]> git.itanic.dy.fi Git - scan-pagemap/blobdiff - analyze.c
Reverse list printing order
[scan-pagemap] / 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");
 }