1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/usr/bin/python3
import sys
f = sys.argv[1]
if len(sys.argv) < 2:
print("Usage "+sys.argv[0]+" <filename> --inf-precision")
res = {}
mem_res = {}
memw_res = {}
samples = {}
max_res = {}
with open(f) as fp:
for line in fp:
s = line.split()
if s[0] not in res:
# print(s[0])
res[s[0]] = list([int(s[5])])#)int(s[5])
mem_res[s[0]] = int(s[8])
memw_res[s[0]] = int(s[9])
samples[s[0]] = int(s[4])
max_res[s[0]] = int(s[5])
else:
res[s[0]].append(int(s[5]))
mem_res[s[0]] += int(s[8])
memw_res[s[0]] += int(s[9])
max_res[s[0]] = max(int(s[5]), max_res[s[0]])
## {{{ http://code.activestate.com/recipes/511478/ (r1)
import math
import functools
def percentile(N, percent, key=lambda x:x):
"""
Find the percentile of a list of values.
@parameter N - is a list of values. Note N MUST BE already sorted.
@parameter percent - a float value from 0.0 to 1.0.
@parameter key - optional key function to compute value from each element of N.
@return - the percentile of the values
"""
if not N:
return None
k = (len(N)-1) * percent
f = math.floor(k)
c = math.ceil(k)
if f == c:
return key(N[int(k)])
d0 = key(N[int(f)]) * (c-k)
d1 = key(N[int(c)]) * (k-f)
return d0+d1
## end of http://code.activestate.com/recipes/511478/ }}}
def memstring(memr, memw, samples):
if memr or memw:
return "\t{:>12.f}\t{:>12.f}".format(memr/samples, memw/samples)
else:
return ""
avg_max = 0
avg_99th = 0
avg_avg = 0
# Only include memory info in the header if relevant
if mem_res[s[0]] == 0:
print("Name\t\tAverage\t\tMax\t\t99th %")
else:
print("Name\t\tAverage\t\tMax\t\t99th %\t\tAvg Mem Read\tAvg Mem Write\t")
for r in sorted(res.keys()):
# print(r + "\t\t" + str(res[r]/samples[r]) + "\t\t" + str(max_res[r]))
avg_avg += sum(res[r])/len(res[r])
avg_max += max(res[r])
avg_99th += percentile(sorted(res[r]), 0.99)
if len(sys.argv) > 2 and sys.argv[2] == "--inf-precision":
print("{:12}\t{:>12.0f}\t{:>12.0f}\t{:>12.0f}".format(r, sum(res[r])/len(res[r]), max(res[r]), percentile(sorted(res[r]), 0.99)) + memstring(mem_res[r], memw_res[r], samples[r]))
else:
print("{:12.12}\t{:>12.0f}\t{:>12.0f}\t{:>12.0f}".format(r, sum(res[r])/len(res[r]), max(res[r]), percentile(sorted(res[r]), 0.99)) + memstring(mem_res[r], memw_res[r], samples[r]))
print("Average average:", avg_avg/len(res.keys()))
print("Average max:", avg_max/len(res.keys()))
print("Average 99th:", avg_99th/len(res.keys()))
|