run-report: Fix CPU usage stats computation
[lttng-tools.git] / tests / run-report.py
index 73645fd420764c29ad9aea183267b3b7c639f5c0..5e8a0cfabe554521053d07fbdfc54ca428baa808 100755 (executable)
@@ -7,7 +7,7 @@ import Queue
 import time
 import shlex
 
-from signal import signal, SIGTERM, SIGINT
+from signal import signal, SIGTERM, SIGINT, SIGPIPE, SIG_DFL
 
 SESSIOND_BIN_NAME = "lttng-sessiond"
 SESSIOND_BIN_PATH = "src/bin/lttng-sessiond/"
@@ -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()
 
@@ -182,7 +184,7 @@ class TestWorker(threading.Thread):
         env = os.environ
         env['TEST_NO_SESSIOND'] = '1'
 
-        test = subprocess.Popen([bin_path_name], env=env)
+        test = subprocess.Popen([bin_path_name], env=env, preexec_fn = lambda: signal(SIGPIPE, SIG_DFL))
         test.wait()
 
         # Send ret value to main thread
This page took 0.022995 seconds and 4 git commands to generate.