]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
analyzer: Add support for dumping process page maps
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Fri, 23 Jul 2010 16:37:02 +0000 (19:37 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Fri, 23 Jul 2010 16:40:10 +0000 (19:40 +0300)
This code will dump the process page mappings, sorted by the the
actual (ram + swap) size. The size of the mapping address space is
printed as well.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
analyze.c
analyze.h

index 67acb2fd8a017d1b91e26e3ffe85c74de6531899..dda98bb5fd97ce1825355448296e898abcf3a7cc 100644 (file)
--- a/analyze.c
+++ b/analyze.c
@@ -112,7 +112,7 @@ void print_pid_stats(struct pageframe *pf, struct process *process_list,
                biggest = MAX(biggest, ps->pages_present + ps->pages_swapped);
        }
 
-       printf("   in ram   swapped     total   pid");
+       printf("  in ram  swapped    total   pid");
        if (opts->with_threads)
                printf("   tid");
        printf(" name\n");
@@ -136,7 +136,7 @@ restart:
                if (total == 0)
                        continue;
 
-               printf("%6lld %sB %6lld %sB %6lld %sB %5d ",
+               printf("%5lld %sB %5lld %sB %5lld %sB %5d ",
                        PAGE_TO_NICE(present), PAGE_TO_NICE_UNIT(present),
                        PAGE_TO_NICE(swapped), PAGE_TO_NICE_UNIT(swapped),
                        PAGE_TO_NICE(total), PAGE_TO_NICE_UNIT(total),
@@ -158,3 +158,62 @@ restart:
 
        printf("Total %d processes\n", processes);
 }
+
+static void _dump_process_maps(struct process *ps)
+{
+       struct maps *map;
+       long int swapped, present, total;
+       long int biggest = 0, second_biggest;
+       int count, processes = 0;
+
+       list_for_each_entry(map, &ps->maps->list, list) {
+               biggest = MAX(biggest, map->pages_present + map->pages_swapped);
+       }
+
+       printf("process: [%d] %s\n", ps->pid, ps->name);
+       printf("    size   in ram  swapped    total name\n");
+restart:
+       second_biggest = 0;
+       count = 0;
+       list_for_each_entry(map, &ps->maps->list, list) {
+
+               present = map->pages_present;
+               swapped = map->pages_swapped;
+               total = present + swapped;
+
+               second_biggest = (total < biggest) &&
+                       (second_biggest < total) ?
+                       total : second_biggest;
+
+               if (total != biggest)
+                       continue;
+
+               printf("%5lld %sB %5lld %sB %5lld %sB %5lld %sB %s\n",
+                       NICE_DIV(map->size), NICE_UNIT(map->size),
+                       PAGE_TO_NICE(present), PAGE_TO_NICE_UNIT(present),
+                       PAGE_TO_NICE(swapped), PAGE_TO_NICE_UNIT(swapped),
+                       PAGE_TO_NICE(total), PAGE_TO_NICE_UNIT(total),
+                       map->name);
+
+               count++;
+               processes++;
+       }
+
+       if (count > 0 && biggest > 0) {
+               biggest = second_biggest;
+               goto restart;
+       }
+       printf("\n");
+}
+
+void dump_process_maps(struct process *process_list)
+{
+       struct process *ps;
+
+       if (list_empty(&process_list->list))
+               _dump_process_maps(process_list);
+
+       list_for_each_entry(ps, &process_list->list, list) {
+               _dump_process_maps(ps);
+       }
+}
index 5ec291484377e59af9756adaf4e89ec691f88a94..2d5010c83d9506ab3eff8ae8c51fab444ae3589a 100644 (file)
--- a/analyze.h
+++ b/analyze.h
@@ -6,5 +6,6 @@
 void print_page_stats(struct pageframe *pf);
 void print_pid_stats(struct pageframe *pf, struct process *process_list,
                struct parse_opts *opts);
+void dump_process_maps(struct process *process_list);
 
 #endif