blob: dfe97a26877fc825f492791a2adb3184af591521 [file] [log] [blame]
koder aka kdanilov4643fd62015-02-10 16:20:13 -08001import re
2import sys
3import json
4
5splitter_rr = "(?ms)=====+\n"
6
7
8def get_data_from_output(fname):
9 results = {}
10 fc = open(fname).read()
11
12 for block in re.split(splitter_rr, fc):
13 block = block.strip()
14 if not block.startswith("[{u'__meta__':"):
15 continue
16 for val in eval(block):
17 meta = val['__meta__']
18 meta['sync'] = 's' if meta['sync'] else 'a'
19 key = "{action} {sync} {blocksize}k".format(**meta)
20 results.setdefault(key, []).append(val['bw_mean'])
21
22 processed_res = {}
23
24 for k, v in results.items():
25 v.sort()
26 med = float(sum(v)) / len(v)
27 ran = sum(abs(x - med) for x in v) / len(v)
28 processed_res[k] = (int(med), int(ran))
29
30 return meta, processed_res
31
32
33def ksort(x):
34 op, sync, sz = x.split(" ")
35 return (op, sync, int(sz[:-1]))
36
37
38def create_json_results(meta, file_data):
39 row = {"build_id": "",
40 "type": "",
41 "iso_md5": ""}
42 row.update(file_data)
43 return json.dumps(row)
44
45
46def show_data(*pathes):
47 begin = "| {:>10} {:>5} {:>5}"
48 first_file_templ = " | {:>6} ~ {:>5} {:>2}% {:>5}"
49 other_file_templ = " | {:>6} ~ {:>5} {:>2}% {:>5} ---- {:>6}%"
50
51 line_templ = begin + first_file_templ + \
52 other_file_templ * (len(pathes) - 1) + " |"
53
54 header_ln = line_templ.replace("<", "^").replace(">", "^")
55
56 params = ["Oper", "Sync", "BSZ", "BW1", "DEV1", "%", "IOPS1"]
57 for pos in range(1, len(pathes)):
58 params += "BW{0}+DEV{0}+%+IOPS{0}+DIFF %".format(pos).split("+")
59
60 header_ln = header_ln.format(*params)
61
62 sep = '-' * len(header_ln)
63
64 results = [get_data_from_output(path)[1] for path in pathes]
65
66 print sep
67 print header_ln
68 print sep
69
70 prev_tp = None
71
72 common_keys = set(results[0].keys())
73 for result in results[1:]:
74 common_keys &= set(result.keys())
75
76 for k in sorted(common_keys, key=ksort):
77 tp = k.rsplit(" ", 1)[0]
78 op, s, sz = k.split(" ")
79 s = 'sync' if s == 's' else 'async'
80
81 if tp != prev_tp and prev_tp is not None:
82 print sep
83
84 prev_tp = tp
85
86 results0 = results[0]
87 m0, d0 = results0[k]
88 iops0 = m0 / int(sz[:-1])
89 perc0 = int(d0 * 100.0 / m0 + 0.5)
90
91 data = [op, s, sz, m0, d0, perc0, iops0]
92
93 for result in results[1:]:
94 m, d = result[k]
95 iops = m / int(sz[:-1])
96 perc = int(d * 100.0 / m + 0.5)
97 avg_diff = int(((m - m0) * 100.) / m + 0.5)
98 data.extend([m, d, perc, iops, avg_diff])
99
100 print line_templ.format(*data)
101
102 print sep
103
104
105def main(argv):
106 path1 = argv[0]
107 if path1 == '--json':
108 print create_json_results(*get_data_from_output(argv[1]))
109 else:
110 show_data(*argv)
111 return 0
112
113if __name__ == "__main__":
114 exit(main(sys.argv[1:]))
115# print " ", results[k]