From 46d678c8e9d0dd4c07e2efe1cda2eab3c7ad5779 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Fri, 23 Jul 2010 19:37:02 +0300 Subject: [PATCH] analyzer: Add support for dumping process page maps 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 --- analyze.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- analyze.h | 1 + 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/analyze.c b/analyze.c index 67acb2f..dda98bb 100644 --- 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); + } +} diff --git a/analyze.h b/analyze.h index 5ec2914..2d5010c 100644 --- 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 -- 2.45.0