blob: c67dbe859f68b7af98b1d28e3021f6b4d252888b [file] [log] [blame]
koder aka kdanilov6c491062015-04-09 22:33:13 +03001import re
2import json
koder aka kdanilov4a510ee2015-04-21 18:50:42 +03003import collections
koder aka kdanilov6c491062015-04-09 22:33:13 +03004
5
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03006from wally.utils import ssize_to_b
7from wally.statistic import med_dev
koder aka kdanilov6c491062015-04-09 22:33:13 +03008
koder aka kdanilov4a510ee2015-04-21 18:50:42 +03009PerfInfo = collections.namedtuple('PerfInfo',
10 ('name',
11 'bw', 'iops', 'dev',
12 'lat', 'lat_dev', 'raw'))
13
14
15def process_disk_info(test_output):
16 data = {}
17
18 for tp, pre_result in test_output:
koder aka kdanilove2de58c2015-04-24 22:59:36 +030019 if tp != 'io' or pre_result is None:
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030020 pass
21
22 for name, results in pre_result['res'].items():
23 bw, bw_dev = med_dev(results['bw'])
24 iops, iops_dev = med_dev(results['iops'])
25 lat, lat_dev = med_dev(results['lat'])
26 dev = bw_dev / float(bw)
27 data[name] = PerfInfo(name, bw, iops, dev, lat, lat_dev, results)
28 return data
29
koder aka kdanilov6c491062015-04-09 22:33:13 +030030
31def parse_output(out_err):
koder aka kdanilov46d4f392015-04-24 11:35:00 +030032 err_start_patt = r"(?ims)=+\s+ERROR\s+=+"
33 err_end_patt = r"(?ims)=+\s+END OF ERROR\s+=+"
34
35 for block in re.split(err_start_patt, out_err)[1:]:
36 tb, garbage = re.split(err_end_patt, block)
37 msg = "Test fails with error:\n" + tb.strip() + "\n"
38 raise OSError(msg)
39
koder aka kdanilov6c491062015-04-09 22:33:13 +030040 start_patt = r"(?ims)=+\s+RESULTS\(format=json\)\s+=+"
41 end_patt = r"(?ims)=+\s+END OF RESULTS\s+=+"
42
43 for block in re.split(start_patt, out_err)[1:]:
44 data, garbage = re.split(end_patt, block)
45 yield json.loads(data.strip())
46
47 start_patt = r"(?ims)=+\s+RESULTS\(format=eval\)\s+=+"
48 end_patt = r"(?ims)=+\s+END OF RESULTS\s+=+"
49
50 for block in re.split(start_patt, out_err)[1:]:
51 data, garbage = re.split(end_patt, block)
52 yield eval(data.strip())
53
54
55def filter_data(name_prefix, fields_to_select, **filters):
56 def closure(data):
57 for result in data:
58 if name_prefix is not None:
59 if not result['jobname'].startswith(name_prefix):
60 continue
61
62 for k, v in filters.items():
63 if result.get(k) != v:
64 break
65 else:
66 yield map(result.get, fields_to_select)
67 return closure
68
69
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030070def filter_processed_data(name_prefix, fields_to_select, **filters):
71 def closure(data):
72 for name, result in data.items():
73 if name_prefix is not None:
74 if not name.startswith(name_prefix):
75 continue
76
77 for k, v in filters.items():
78 if result.raw.get(k) != v:
79 break
80 else:
81 yield map(result.raw.get, fields_to_select)
82 return closure
83
84
koder aka kdanilov6c491062015-04-09 22:33:13 +030085def load_data(raw_data):
86 data = list(parse_output(raw_data))[0]
87
88 for key, val in data['res'].items():
koder aka kdanilov6c491062015-04-09 22:33:13 +030089 val['blocksize_b'] = ssize_to_b(val['blocksize'])
90
koder aka kdanilov652cd802015-04-13 12:21:07 +030091 val['iops_mediana'], val['iops_stddev'] = med_dev(val['iops'])
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +030092 val['bw_mediana'], val['bw_stddev'] = med_dev(val['bw'])
koder aka kdanilov652cd802015-04-13 12:21:07 +030093 val['lat_mediana'], val['lat_stddev'] = med_dev(val['lat'])
koder aka kdanilov6c491062015-04-09 22:33:13 +030094 yield val
95
96
97def load_files(*fnames):
98 for fname in fnames:
99 for i in load_data(open(fname).read()):
100 yield i