From c6bf9e374cbaf6c3bdb9cc86cc05cec843c319c0 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sat, 29 Dec 2018 17:06:11 +0200 Subject: [PATCH] Reverse list printing order The process and mapping lists are often very long and rarely fit entirely on the screen. Usually we are most interested in the largest entries, the ones that now get printed in the beginning of the list. This is cumbersome as it therefore requires quite a bit of scrolling to see what you really want. Reverse the list printing order so that the tool becomes more friendly to the end user. Signed-off-by: Timo Kokkonen --- analyze.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/analyze.c b/analyze.c index 29752b1..af00a48 100644 --- a/analyze.c +++ b/analyze.c @@ -228,7 +228,7 @@ void print_pid_stats(struct rb_root *root, struct process *process_list, struct process *ps; struct pageframe *pf; long int swapped, present, unique, total; - long int biggest = 0, second_biggest; + long int biggest = 0, smallest = 0, second_smallest; int count, processes = 0; /* @@ -256,20 +256,18 @@ void print_pid_stats(struct rb_root *root, struct process *process_list, printf(" name\n"); restart: - second_biggest = 0; + second_smallest = biggest; count = 0; list_for_each_entry(ps, &process_list->list, list) { - present = ps->pages_present; swapped = ps->pages_swapped; unique = ps->pages_unique; total = present + swapped; - second_biggest = (total < biggest) && - (second_biggest < total) ? - total : second_biggest; + if (total > smallest) + second_smallest = MIN(second_smallest, total); - if (total != biggest) + if (total != smallest) continue; if (total == 0) @@ -293,11 +291,15 @@ restart: processes++; } - if (count > 0) { - biggest = second_biggest; + if (smallest != second_smallest) { + smallest = second_smallest; goto restart; } + printf(" RSS swapped USS total pid"); + if (opts->with_threads) + printf(" tid"); + printf(" name\n"); printf("Total %d processes\n", processes); } @@ -306,7 +308,7 @@ static void _dump_process_maps(struct rb_root *root, struct process *ps, { struct maps *map; long int swapped, present, total; - long int biggest = 0, second_biggest; + long int biggest = 0, smallest = 0, second_smallest; int count, processes = 0, pids = 0; if (is_parse_option(opts, PARSE_SHARED_MAPPING)) { @@ -335,19 +337,17 @@ static void _dump_process_maps(struct rb_root *root, struct process *ps, printf("process: [%d] %s\n", ps->pid, ps->name); printf(" size RSS swapped total name\n"); restart: - second_biggest = 0; + second_smallest = biggest; 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 > smallest) + second_smallest = MIN(second_smallest, total); - if (total != biggest) + if (total != smallest) continue; /* @@ -368,10 +368,11 @@ restart: processes++; } - if (count > 0 && biggest > 0) { - biggest = second_biggest; + if (smallest != second_smallest) { + smallest = second_smallest; goto restart; } + printf(" size RSS swapped total name\n"); printf("\n"); } -- 2.45.0