Permalink
Browse files

runner: add support to meassure cpu usage

Signed-off-by: Felipe Contreras <felipe.contreras@nokia.com>
  • Loading branch information...
1 parent 5f06e71 commit f4d81cea85e4fd1dee4f0a651d3684e0409c1cb8 Felipe Contreras committed May 22, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 runner
View
18 runner
@@ -114,6 +114,16 @@ def respawn():
def get_date():
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+def get_time(pid):
+ cpu_values = file("/proc/stat", "r").readline().split()[1:]
+ total_time = sum(map(int, cpu_values))
+
+ pid_values = file("/proc/%s/stat" % (pid), "r").readline().split()
+ utime, stime = map(int, pid_values[13:15])
+ process_time = utime + stime
+
+ return total_time, process_time
+
def run_test(t):
global pid
@@ -123,6 +133,8 @@ def run_test(t):
n['in'] = t
n['env'] = t.pop('env', None)
+ time_before = get_time(pid)
+
p2.dump(n)
data = p1.load()
if not data:
@@ -143,6 +155,12 @@ def run_test(t):
if data['in'].get('expected_failure', False):
r = 100.0 - r
+ time_after = get_time(pid)
+
+ total_time, process_time = [b - a for a, b in zip(time_before, time_after)]
+
+ data['cpu_usage'] = 100 * (float(process_time) / float(total_time))
+
data['result'] = r
data['date'] = get_date()
return data

0 comments on commit f4d81ce

Please sign in to comment.