virt.virt_test_utils: run_autotest - 'tar' needs relative paths to strip the leading '/'
[autotest-zwu.git] / client / tools / avgtime
blobb5a1ed77179307f29e0655347a0728ce9194f669
1 #!/usr/bin/python
2 import sys, os, re
4 def avg_deviation(values):
5 sum = 0
6 count = 0
8 if not values:
9 return (0, 0)
10 for x in values:
11 sum += x
12 count += 1
13 average = sum / count
14 sum_sq_dev = 0
15 for x in values:
16 sum_sq_dev += (x - average) ** 2
17 std_dev = (sum_sq_dev / count)**0.5
18 return (average, 100 * std_dev / average)
21 list = []
22 for line in sys.stdin.readlines():
23 (user, system, elapsed, cpu) = line.split()[0:4]
24 user = float(re.match(r'([\d\.]+)', user).group(0))
25 system = float(re.match(r'([\d\.]+)', system).group(0))
26 m = re.match(r'(\d+):([\d\.]+)', elapsed)
27 elapsed = 60*int(m.group(1)) + float(m.group(2))
28 cpu = int(re.match(r'(\d+)', cpu).group(0))
30 list.append((user, system, elapsed, cpu))
32 print " user: %0.2fs (%0.2f%%)" % avg_deviation([x[0] for x in list])
33 print " system: %0.2fs (%0.2f%%)" % avg_deviation([x[1] for x in list])
34 print "elapsed: %0.2fs (%0.2f%%)" % avg_deviation([x[2] for x in list])
35 print " cpu: %d%% (%0.2f%%)" % avg_deviation([x[3] for x in list])