[lttng-dev] [PATCH 3/5] run-report: Fix CPU usage stats computation

Christian Babeux christian.babeux at efficios.com
Tue Dec 18 16:31:16 EST 2012


The CPU usage statistics are computed by grepping the top command
output. The top output format as since changed so the CPU usage
statistics were not properly computed.

Fix this by adjusting to the new top command output format.

Signed-off-by: Christian Babeux <christian.babeux at efficios.com>
---
 tests/run-report.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tests/run-report.py b/tests/run-report.py
index 6f559c9..b0bdb74 100755
--- a/tests/run-report.py
+++ b/tests/run-report.py
@@ -46,10 +46,12 @@ def cpu_create_usage_dict(top_line):
     top_line = top_line.replace(",","")
     words = top_line.split()[1:]
 
-    for word in words:
-        index = word.find('%')
+
+    for key in top_dict:
+        index = words.index(key)
         # Add the value to the dictionnary
-        top_dict[word[index + 1:]] = float(word[:index])
+        val = words[index-1]
+        top_dict[key] = float(val)
 
     return top_dict
 
@@ -87,7 +89,7 @@ def cpu_sample_usage(pid=None):
     # Spawn top process
     top = subprocess.Popen(args, stdout = subprocess.PIPE)
 
-    grep = subprocess.Popen(["grep", "^Cpu"], stdin = top.stdout,
+    grep = subprocess.Popen(["grep", "Cpu"], stdin = top.stdout,
             stdout = subprocess.PIPE)
     top.stdout.close()
 
-- 
1.8.0.2




More information about the lttng-dev mailing list