]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
analyzer: Sort processes based on both swapped and present size
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 14 Jul 2010 19:10:28 +0000 (22:10 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 14 Jul 2010 19:17:11 +0000 (22:17 +0300)
Sorting by only the present size will cause the logic to get in an
infinite loop, since the exit criteria for the print loop is that the
sum of the swapped and present size needs to be zero.

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

index 4d07988f1b97b4e0433912175af504406cc45ccf..77ef1da87fc057b0f3a8012bbeeeb25c6adc41bd 100644 (file)
--- a/analyze.c
+++ b/analyze.c
@@ -93,7 +93,7 @@ void print_pid_stats(struct pageframe *pf, struct process *process_list)
 {
        struct analyze_frames af;
        struct process *ps;
-       long int swapped, present;
+       long int swapped, present, total;
        long int biggest = 0, second_biggest;
        int count;
 
@@ -109,7 +109,7 @@ void print_pid_stats(struct pageframe *pf, struct process *process_list)
                bintree_walk(&pf->tree, &af.ops);
                ps->pages_present = af.pages_present;
                ps->pages_swapped = af.pages_swapped;
-               biggest = MAX(biggest, ps->pages_present);
+               biggest = MAX(biggest, ps->pages_present + ps->pages_swapped);
        }
 
        printf("   in ram   swapped   pid name\n");
@@ -121,15 +121,16 @@ restart:
 
                present = ps->pages_present;
                swapped = ps->pages_swapped;
+               total = present + swapped;
 
-               second_biggest = ps->pages_present < biggest &&
-                       second_biggest < ps->pages_present ?
-                       ps->pages_present : second_biggest;
+               second_biggest = (total < biggest) &&
+                       (second_biggest < total) ?
+                       total : second_biggest;
 
-               if (ps->pages_present != biggest)
+               if (total != biggest)
                        continue;
 
-               if ((swapped + present) == 0)
+               if (total == 0)
                        continue;
 
                printf("%6lld %sB %6lld %sB %5d %s\n",