blob: 102fe4c86d195e2afea32457f8eff75da6b0f12b [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 kdanilov63ad2062015-04-27 13:11:40 +03006# from wally.utils import ssize_to_b
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03007from 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',
koder aka kdanilov209e85d2015-04-27 23:11:05 +030012 'lat', 'lat_dev', 'raw',
13 'meta'))
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030014
15
koder aka kdanilov209e85d2015-04-27 23:11:05 +030016def split_and_add(data, block_size):
17 assert len(data) % block_size == 0
18 res = [0] * block_size
koder aka kdanilov63ad2062015-04-27 13:11:40 +030019
koder aka kdanilov209e85d2015-04-27 23:11:05 +030020 for idx, val in enumerate(data):
21 res[idx % block_size] += val
koder aka kdanilov63ad2062015-04-27 13:11:40 +030022
23 return res
24
25
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030026def process_disk_info(test_output):
27 data = {}
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030028 for tp, pre_result in test_output:
koder aka kdanilove2de58c2015-04-24 22:59:36 +030029 if tp != 'io' or pre_result is None:
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030030 pass
31
koder aka kdanilov63ad2062015-04-27 13:11:40 +030032 vm_count = pre_result['__test_meta__']['testnodes_count']
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030033 for name, results in pre_result['res'].items():
koder aka kdanilov209e85d2015-04-27 23:11:05 +030034 assert len(results['bw']) % vm_count == 0
35 block_count = len(results['bw']) // vm_count
36
37 # print
38 # print name, block_count
39 # print results['bw']
40 # print split_and_add(results['bw'], block_count)
41
42 bw, bw_dev = med_dev(split_and_add(results['bw'], block_count))
43 iops, iops_dev = med_dev(split_and_add(results['iops'],
44 block_count))
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030045 lat, lat_dev = med_dev(results['lat'])
46 dev = bw_dev / float(bw)
koder aka kdanilov209e85d2015-04-27 23:11:05 +030047 data[name] = PerfInfo(name, bw, iops, dev, lat, lat_dev, results,
48 pre_result['__test_meta__'])
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030049 return data
50
koder aka kdanilov6c491062015-04-09 22:33:13 +030051
52def parse_output(out_err):
koder aka kdanilov46d4f392015-04-24 11:35:00 +030053 err_start_patt = r"(?ims)=+\s+ERROR\s+=+"
54 err_end_patt = r"(?ims)=+\s+END OF ERROR\s+=+"
55
56 for block in re.split(err_start_patt, out_err)[1:]:
57 tb, garbage = re.split(err_end_patt, block)
58 msg = "Test fails with error:\n" + tb.strip() + "\n"
59 raise OSError(msg)
60
koder aka kdanilov6c491062015-04-09 22:33:13 +030061 start_patt = r"(?ims)=+\s+RESULTS\(format=json\)\s+=+"
62 end_patt = r"(?ims)=+\s+END OF RESULTS\s+=+"
63
64 for block in re.split(start_patt, out_err)[1:]:
65 data, garbage = re.split(end_patt, block)
66 yield json.loads(data.strip())
67
68 start_patt = r"(?ims)=+\s+RESULTS\(format=eval\)\s+=+"
69 end_patt = r"(?ims)=+\s+END OF RESULTS\s+=+"
70
71 for block in re.split(start_patt, out_err)[1:]:
72 data, garbage = re.split(end_patt, block)
73 yield eval(data.strip())
74
75
76def filter_data(name_prefix, fields_to_select, **filters):
77 def closure(data):
78 for result in data:
79 if name_prefix is not None:
80 if not result['jobname'].startswith(name_prefix):
81 continue
82
83 for k, v in filters.items():
84 if result.get(k) != v:
85 break
86 else:
87 yield map(result.get, fields_to_select)
88 return closure
89
90
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030091def filter_processed_data(name_prefix, fields_to_select, **filters):
92 def closure(data):
93 for name, result in data.items():
94 if name_prefix is not None:
95 if not name.startswith(name_prefix):
96 continue
97
98 for k, v in filters.items():
99 if result.raw.get(k) != v:
100 break
101 else:
102 yield map(result.raw.get, fields_to_select)
103 return closure
104
105
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300106# def load_data(raw_data):
107# data = list(parse_output(raw_data))[0]
koder aka kdanilov6c491062015-04-09 22:33:13 +0300108
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300109# for key, val in data['res'].items():
110# val['blocksize_b'] = ssize_to_b(val['blocksize'])
koder aka kdanilov6c491062015-04-09 22:33:13 +0300111
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300112# val['iops_mediana'], val['iops_stddev'] = med_dev(val['iops'])
113# val['bw_mediana'], val['bw_stddev'] = med_dev(val['bw'])
114# val['lat_mediana'], val['lat_stddev'] = med_dev(val['lat'])
115# yield val
koder aka kdanilov6c491062015-04-09 22:33:13 +0300116
117
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300118# def load_files(*fnames):
119# for fname in fnames:
120# for i in load_data(open(fname).read()):
121# yield i