From a02a2754427b007b99a15549f87a1202a67eaeeb Mon Sep 17 00:00:00 2001
From: Laura Abbott <lauraa@codeaurora.org>
Date: Mon, 3 Mar 2014 11:16:23 -0800
Subject: [PATCH] linux-ramdump-parser-v2: Make the page print outs more useful

The pagetype info gives useful data but it's helpful to see the data
in other formats that often involve having to do math. Make the parser
do the math of calculating the total number of pages per migrate type
and the total number of pages per order. Additionally, print out the
total number of ram pages with vmstat to make it easier to determine
just how low a system may be on memory.

Change-Id: I812288fe4c25de06c7017fb0b6515e514f799134
---
 .../parsers/pagetypeinfo.py                    | 18 ++++++++++++++----
 linux-ramdump-parser-v2/parsers/vmstat.py      |  3 ++-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/linux-ramdump-parser-v2/parsers/pagetypeinfo.py b/linux-ramdump-parser-v2/parsers/pagetypeinfo.py
index 2a633f0..5ccb6bc 100644
--- a/linux-ramdump-parser-v2/parsers/pagetypeinfo.py
+++ b/linux-ramdump-parser-v2/parsers/pagetypeinfo.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
+# Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2 and
@@ -28,6 +28,9 @@ class Pagetypeinfo(RamParser):
         zname = ramdump.read_cstring(zname_addr, 12)
         is_corrupt = False
         total_bytes = 0
+        total_pages = 0
+        total_orders = [0]*11
+        total_orders_str = 'Total pages:                    '
 
         for mtype in range(0, migrate_types):
             mname_addr = ramdump.read_word(migratetype_names + mtype * 4)
@@ -35,6 +38,7 @@ class Pagetypeinfo(RamParser):
             pageinfo = ('zone {0:8} type {1:12} '.format(zname, mname))
             nums = ''
             total_type_bytes = 0
+            total_type_pages = 0
             for order in range(0, 11):
 
                 area = zone + free_area_offset + order * free_area_size
@@ -57,12 +61,18 @@ class Pagetypeinfo(RamParser):
                 nums = nums + ('{0:6}'.format(pg_count))
                 total_type_bytes = total_type_bytes + \
                     pg_count * 4096 * (2 ** order)
+                total_type_pages = total_type_pages + pg_count * (2 ** order)
+                total_orders[order] += pg_count
             print_out_str(pageinfo + nums +
-                          ' = {0} MB'.format(total_type_bytes / (1024 * 1024)))
+                          ' = {0} MB {1} pages'.format(total_type_bytes / (1024 * 1024), total_type_pages))
             total_bytes = total_bytes + total_type_bytes
+            total_pages = total_pages + total_type_pages
+        for order in range(0, 11):
+            total_orders_str += '{0:6}'.format(total_orders[order])
+        print_out_str(total_orders_str)
 
-        print_out_str('Approximate total for zone {0}: {1} MB\n'.format(
-            zname, total_bytes / (1024 * 1024)))
+        print_out_str('Approximate total for zone {0}: {1} MB, {2} pages\n'.format(
+            zname, total_bytes / (1024 * 1024), total_pages))
         if is_corrupt:
             print_out_str(
                 '!!! Numbers may not be accurate due to list corruption!')
diff --git a/linux-ramdump-parser-v2/parsers/vmstat.py b/linux-ramdump-parser-v2/parsers/vmstat.py
index 49cf501..568bd48 100644
--- a/linux-ramdump-parser-v2/parsers/vmstat.py
+++ b/linux-ramdump-parser-v2/parsers/vmstat.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2013, The Linux Foundation. All rights reserved.
+# Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2 and
@@ -66,3 +66,4 @@ class ZoneInfo(RamParser):
         for i in xrange(0, max_zone_stats):
             print_out_str('{0:30}: {1:8}'.format(vmstat_names[i], self.ramdump.read_word(
                 self.ramdump.array_index(vmstats_addr, 'atomic_long_t', i))))
+        print_out_str('Total system pages: {0}'.format(self.ramdump.read_word(self.ramdump.addr_lookup('totalram_pages'))))
-- 
GitLab