]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
Reverse list printing order
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 29 Dec 2018 15:06:11 +0000 (17:06 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 29 Dec 2018 15:06:11 +0000 (17:06 +0200)
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 <timo.t.kokkonen@iki.fi>
analyze.c

index 29752b1a9a46f9025e52094fdad90be4dc4430fa..af00a48af46043d0da84367e0e1004739c7608c5 100644 (file)
--- 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");
 }