From: Timo Kokkonen Date: Sun, 29 Aug 2010 10:30:33 +0000 (+0300) Subject: Analyzer: Print detailed kpageflag statistics X-Git-Url: http://git.itanic.dy.fi/?p=scan-pagemap;a=commitdiff_plain;h=62bf88c85726994e287a41257474e856167ef382 Analyzer: Print detailed kpageflag statistics The print_page_statst() function is modified so that it will count how many pages are found with each of the kpageflag bit set. The collected stats are then printed so that count for every non-zero kpageflag is shown. Since there are so many kpageflag flags (22 at the moment), zero number counts are alwaysy omitted. Since root priviledges are required to read the /proc/kpageflag interface, all of the kpageflag counts are zero if user does not have root priviledges. Signed-off-by: Timo Kokkonen --- diff --git a/analyze.c b/analyze.c index 1625a24..2c5eddd 100644 --- a/analyze.c +++ b/analyze.c @@ -58,9 +58,13 @@ struct analyze_frames { struct maps *map; int pids; + /* General counters */ long int pages_present; long int pages_swapped; long int pages_unique; + + /* kpageflag stats counters */ + long int kpageflag[KPAGEFLAGS_NUM]; }; #define bintree_ops_to_af(bintree_ops) \ @@ -71,6 +75,7 @@ static void count_pages(struct bintree *b, struct bintree_ops *ops) struct pageframe *pf = tree_to_pageframe(b); struct analyze_frames *af = bintree_ops_to_af(ops); struct maps_list *ml; + int i; if (af->pid) { /* Find pages which reference at least once a pid */ @@ -137,6 +142,10 @@ get_stats: af->pages_swapped++; if (pf->kpagecount == 1) af->pages_unique++; + + for (i = 0; i < KPAGEFLAGS_NUM; i++) + if (kpageflag_is_set(pf, i)) + af->kpageflag[i]++; } /* @@ -146,11 +155,24 @@ void print_page_stats(struct pageframe *pf) { struct analyze_frames af; long count; + int i; memset(&af, 0, sizeof(af)); af.ops.callback = count_pages; count = bintree_walk(&pf->tree, &af.ops); + + for (i = 0; i < KPAGEFLAGS_NUM; i++) { + if (!af.kpageflag[i]) + continue; + + printf("%13s pages: %6ld, %5lld %s\n", + kpageflag_to_str(i), + af.kpageflag[i], + PAGE_TO_NICE(af.kpageflag[i]), + PAGE_TO_NICE_UNIT(af.kpageflag[i])); + } + printf(" present pages: %6ld, %5lld %sB\n" " swapped pages: %6ld, %5lld %sB\n" " unique pages: %6ld, %5lld %sB\n"