]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
analyzer: Pretty print output
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 4 Jul 2010 07:23:28 +0000 (10:23 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 4 Jul 2010 07:38:08 +0000 (10:38 +0300)
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
analyze.c

index 0cc630bfdf84f79a7b35526980275537f1c82605..8baa33016637b6246506bfd080210b9068185817 100644 (file)
--- a/analyze.c
+++ b/analyze.c
@@ -5,6 +5,23 @@
 #include "utils.h"
 #include "bintree.h"
 
+#define SI_k   1024ll
+#define SI_M   (1024 * 1024ll)
+#define SI_G   (1025 * 1024 * 1024ll)
+
+#define NICE_DIV(a)                                                    \
+       ((a) < SI_k ? (a) :                                             \
+               (a < SI_M ? ((a) / SI_k) :                              \
+                       (a < SI_G ? ((a) / SI_M) : ((a) / SI_G))))
+
+#define NICE_UNIT(a)                                   \
+       ((a) < SI_k ? "" :                              \
+               ((a) < SI_M ? "k" :                     \
+                       ((a) < SI_G ? "M" : "G")))
+
+#define PAGE_TO_NICE(a)                NICE_DIV((long long)a * PAGE_SIZE)
+#define PAGE_TO_NICE_UNIT(a)   NICE_UNIT((long long)a * PAGE_SIZE)
+
 struct analyze_frames {
        struct bintree_ops ops;
        long int present_pages;
@@ -35,18 +52,26 @@ static void count_pages(struct bintree *b, struct bintree_ops *ops)
 void print_page_stats(struct pageframe *pf)
 {
        struct analyze_frames af;
-       int count;
+       long count;
        memset(&af, 0, sizeof(af));
 
        af.ops.callback = count_pages;
 
        count = bintree_walk(&pf->tree, &af.ops);
-       printf("present pages: %ld\n"
-               "Swapped pages: %ld\n"
-               "Unused pages: %ld\n"
-               "Total %d physical pages\n",
+       printf("present pages: %ld, %lld %sB\n"
+               "Swapped pages: %ld, %lld %sB\n"
+               "Unused pages: %ld, %lld %sB\n"
+               "Total %ld physical pages, %lld %sB\n",
                af.present_pages,
+               PAGE_TO_NICE(af.present_pages),
+               PAGE_TO_NICE_UNIT(af.present_pages),
                af.swapped_pages,
+               PAGE_TO_NICE(af.swapped_pages),
+               PAGE_TO_NICE_UNIT(af.swapped_pages),
                af.unused_pages,
-               count);
+               PAGE_TO_NICE(af.unused_pages),
+               PAGE_TO_NICE_UNIT(af.unused_pages),
+               count,
+               PAGE_TO_NICE(count),
+               PAGE_TO_NICE_UNIT(count));
 }