diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/Makefile.in | 18 | ||||
-rw-r--r-- | tests/read_stats.c | 80 |
3 files changed, 97 insertions, 4 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 3927621..5999389 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,13 +2,14 @@ INCLUDES = -I$(top_srcdir)/include LDADD = $(top_srcdir)/src/.libs/libcgroup.la # compile the tests, but do not install them -noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test +noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats libcgrouptest01_SOURCES=libcgrouptest01.c test_functions.c libcgrouptest.h libcg_ba_SOURCES=libcg_ba.cpp setuid_SOURCES=setuid.c pathtest_SOURCES=pathtest.c walk_test_SOURCES=walk_test.c +read_stats_SOURCES=read_stats.c EXTRA_DIST = pathtest.sh runlibcgrouptest.sh diff --git a/tests/Makefile.in b/tests/Makefile.in index dae7a12..704e96f 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -33,7 +33,8 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ noinst_PROGRAMS = libcgrouptest01$(EXEEXT) libcg_ba$(EXEEXT) \ - setuid$(EXEEXT) pathtest$(EXEEXT) walk_test$(EXEEXT) + setuid$(EXEEXT) pathtest$(EXEEXT) walk_test$(EXEEXT) \ + read_stats$(EXEEXT) subdir = tests DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -65,6 +66,10 @@ am_walk_test_OBJECTS = walk_test.$(OBJEXT) walk_test_OBJECTS = $(am_walk_test_OBJECTS) walk_test_LDADD = $(LDADD) walk_test_DEPENDENCIES = $(top_srcdir)/src/.libs/libcgroup.la +am_read_stats_OBJECTS = read_stats.$(OBJEXT) +read_stats_OBJECTS = $(am_read_stats_OBJECTS) +read_stats_LDADD = $(LDADD) +read_stats_DEPENDENCIES = $(top_srcdir)/src/.libs/libcgroup.la DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -87,9 +92,11 @@ CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ SOURCES = $(libcg_ba_SOURCES) $(libcgrouptest01_SOURCES) \ - $(pathtest_SOURCES) $(setuid_SOURCES) $(walk_test_SOURCES) + $(pathtest_SOURCES) $(setuid_SOURCES) $(walk_test_SOURCES) \ + $(read_stats_SOURCES) DIST_SOURCES = $(libcg_ba_SOURCES) $(libcgrouptest01_SOURCES) \ - $(pathtest_SOURCES) $(setuid_SOURCES) $(walk_test_SOURCES) + $(pathtest_SOURCES) $(setuid_SOURCES) $(walk_test_SOURCES) \ + $(read_test_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -214,6 +221,7 @@ libcg_ba_SOURCES = libcg_ba.cpp setuid_SOURCES = setuid.c pathtest_SOURCES = pathtest.c walk_test_SOURCES = walk_test.c +read_stats_SOURCES = read_stats.c EXTRA_DIST = pathtest.sh runlibcgrouptest.sh TESTS = runlibcgrouptest.sh all: all-am @@ -271,6 +279,9 @@ setuid$(EXEEXT): $(setuid_OBJECTS) $(setuid_DEPENDENCIES) walk_test$(EXEEXT): $(walk_test_OBJECTS) $(walk_test_DEPENDENCIES) @rm -f walk_test$(EXEEXT) $(LINK) $(walk_test_OBJECTS) $(walk_test_LDADD) $(LIBS) +read_stats$(EXEEXT): $(read_stats_OBJECTS) $(read_stats_DEPENDENCIES) + @rm -f read_stats$(EXEEXT) + $(LINK) $(read_stats_OBJECTS) $(read_stats_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -284,6 +295,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setuid.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_functions.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/walk_test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/read_stats.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/tests/read_stats.c b/tests/read_stats.c new file mode 100644 index 0000000..6e61b97 --- /dev/null +++ b/tests/read_stats.c @@ -0,0 +1,80 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> +#include <libcgroup.h> + +int read_stats(char *path, char *controller) +{ + int ret; + void *handle; + struct cgroup_stat stat; + + ret = cgroup_read_stats_begin(controller, path, &handle, &stat); + + if (ret != 0) { + fprintf(stderr, "stats read failed\n"); + return -1; + } + + printf("Stats for %s:\n", path); + printf("%s: %s", stat.name, stat.value); + + while ((ret = cgroup_read_stats_next(&handle, &stat)) != + ECGEOF) { + printf("%s: %s", stat.name, stat.value); + } + + cgroup_read_stats_end(&handle); + printf("\n"); + return 0; +} + +int main(int argc, char *argv[]) +{ + int ret; + char *controller; + void *handle; + struct cgroup_file_info info; + int lvl; + char cgroup_path[FILENAME_MAX]; + int root_len; + + if (argc < 2) { + fprintf(stderr, "Usage %s: <controller name>\n", + argv[0]); + exit(EXIT_FAILURE); + } + + controller = argv[1]; + + cgroup_init(); + + ret = cgroup_walk_tree_begin(controller, "/", 0, &handle, &info, &lvl); + + if (ret != 0) { + fprintf(stderr, "Walk failed\n"); + exit(EXIT_FAILURE); + } + + root_len = strlen(info.full_path) - 1; + strncpy(cgroup_path, info.path, FILENAME_MAX); + ret = read_stats(cgroup_path, controller); + if (ret < 0) + exit(EXIT_FAILURE); + + while ((ret = cgroup_walk_tree_next(0, &handle, &info, lvl)) != + ECGEOF) { + if (info.type != CGROUP_FILE_TYPE_DIR) + continue; + strncpy(cgroup_path, info.full_path + root_len, FILENAME_MAX); + strcat(cgroup_path, "/"); + ret = read_stats(cgroup_path, controller); + if (ret < 0) + exit(EXIT_FAILURE); + } + cgroup_walk_tree_end(&handle); + + return EXIT_SUCCESS; +} |