]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
Analyzer: Print detailed kpageflag statistics
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 29 Aug 2010 10:30:33 +0000 (13:30 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 29 Aug 2010 10:30:33 +0000 (13:30 +0300)
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 <kaapeli@itanic.dy.fi>
analyze.c

index 1625a24c9cbdabaa7167cb78d0b226b4456d8378..2c5eddd087411034df23fe06afa8b0ac28b756fe 100644 (file)
--- 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"