]> git.itanic.dy.fi Git - scan-pagemap/blobdiff - analyze.c
Analyzer: Print detailed kpageflag statistics
[scan-pagemap] / 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"