OSDN Git Service

Fix various issues in procrank.
authorSelim Gurun <sgurun@google.com>
Sat, 21 Jan 2012 03:44:54 +0000 (19:44 -0800)
committerSelim Gurun <sgurun@google.com>
Sat, 21 Jan 2012 04:10:22 +0000 (20:10 -0800)
Fixed these problems:
1. Page swapped bit was not extracted correctly.
2. Pages were ignored when page present bit is not set.
3. Bit operations were not correct.
4. There was a compiler warning about unsigned/signed comparision.
5. Line limit was too short for the map file. This was causing procrank
   to generate a warning and remove the related process from results.

Change-Id: Ifed3913a49b15f59010cfa842090a13228074df9

libpagemap/include/pagemap/pagemap.h
libpagemap/pm_map.c
libpagemap/pm_process.c

index 09ff29d..25c6161 100644 (file)
@@ -129,10 +129,10 @@ int pm_process_pagemap_range(pm_process_t *proc,
                              unsigned long low, unsigned long hi,
                              uint64_t **range_out, size_t *len);
 
-#define _BITS(x, offset, bits) (((x) >> offset) & ((1LL << ((bits) + 1)) - 1))
+#define _BITS(x, offset, bits) (((x) >> offset) & ((1LL << (bits)) - 1))
 
 #define PM_PAGEMAP_PRESENT(x)     (_BITS(x, 63, 1))
-#define PM_PAGEMAP_SWAPPED(x)     (!_BITS(x, 62, 1))
+#define PM_PAGEMAP_SWAPPED(x)     (_BITS(x, 62, 1))
 #define PM_PAGEMAP_SHIFT(x)       (_BITS(x, 55, 6))
 #define PM_PAGEMAP_PFN(x)         (_BITS(x, 0, 55))
 #define PM_PAGEMAP_SWAP_OFFSET(x) (_BITS(x, 5, 50))
index f683ba6..2d5c2f9 100644 (file)
@@ -83,10 +83,6 @@ int pm_map_workingset(pm_map_t *map, pm_memusage_t *ws_out) {
     pm_memusage_zero(&ws);
     
     for (i = 0; i < len; i++) {
-        if (!PM_PAGEMAP_PRESENT(pagemap[i]) ||
-            PM_PAGEMAP_SWAPPED(pagemap[i]))
-            continue;
-
         error = pm_kernel_flags(map->proc->ker, PM_PAGEMAP_PFN(pagemap[i]),
                                 &flags);
         if (error) goto out;
@@ -99,6 +95,7 @@ int pm_map_workingset(pm_map_t *map, pm_memusage_t *ws_out) {
         if (error) goto out;
 
         ws.vss += map->proc->ker->pagesize;
+        if( PM_PAGEMAP_SWAPPED(pagemap[i]) ) continue;
         ws.rss += (count >= 1) ? (map->proc->ker->pagesize) : (0);
         ws.pss += (count >= 1) ? (map->proc->ker->pagesize / count) : (0);
         ws.uss += (count == 1) ? (map->proc->ker->pagesize) : (0);
index b3c077e..dddff01 100644 (file)
@@ -122,7 +122,7 @@ int pm_process_pagemap_range(pm_process_t *proc,
         free(range);
         *range_out = NULL;
         return 0;
-    } else if (error < 0 || (error > 0 && error < numpages * sizeof(uint64_t))) {
+    } else if (error < 0 || (error > 0 && error < (int)(numpages * sizeof(uint64_t)))) {
         error = (error < 0) ? errno : -1;
         free(range);
         return error;
@@ -210,7 +210,7 @@ int pm_process_destroy(pm_process_t *proc) {
 }
 
 #define INITIAL_MAPS 10
-#define MAX_LINE 256
+#define MAX_LINE 1024
 #define MAX_PERMS 5
 
 /*