blob: 3b50bf7e41a391196a6826adb66775c15eb7d89d [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',
12 'lat', 'lat_dev', 'raw'))
13
14
koder aka kdanilov63ad2062015-04-27 13:11:40 +030015def split_and_add(data, block_count):
16 assert len(data) % block_count == 0
17 res = [0] * (len(data) // block_count)
18
19 for i in range(block_count):
20 for idx, val in enumerate(data[i::block_count]):
21 res[idx] += val
22
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']
33
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030034 for name, results in pre_result['res'].items():
koder aka kdanilov63ad2062015-04-27 13:11:40 +030035 bw, bw_dev = med_dev(split_and_add(results['bw'], vm_count))
36 iops, iops_dev = med_dev(split_and_add(results['iops'], vm_count))
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030037 lat, lat_dev = med_dev(results['lat'])
38 dev = bw_dev / float(bw)
39 data[name] = PerfInfo(name, bw, iops, dev, lat, lat_dev, results)
40 return data
41
koder aka kdanilov6c491062015-04-09 22:33:13 +030042
43def parse_output(out_err):
koder aka kdanilov46d4f392015-04-24 11:35:00 +030044 err_start_patt = r"(?ims)=+\s+ERROR\s+=+"
45 err_end_patt = r"(?ims)=+\s+END OF ERROR\s+=+"
46
47 for block in re.split(err_start_patt, out_err)[1:]:
48 tb, garbage = re.split(err_end_patt, block)
49 msg = "Test fails with error:\n" + tb.strip() + "\n"
50 raise OSError(msg)
51
koder aka kdanilov6c491062015-04-09 22:33:13 +030052 start_patt = r"(?ims)=+\s+RESULTS\(format=json\)\s+=+"
53 end_patt = r"(?ims)=+\s+END OF RESULTS\s+=+"
54
55 for block in re.split(start_patt, out_err)[1:]:
56 data, garbage = re.split(end_patt, block)
57 yield json.loads(data.strip())
58
59 start_patt = r"(?ims)=+\s+RESULTS\(format=eval\)\s+=+"
60 end_patt = r"(?ims)=+\s+END OF RESULTS\s+=+"
61
62 for block in re.split(start_patt, out_err)[1:]:
63 data, garbage = re.split(end_patt, block)
64 yield eval(data.strip())
65
66
67def filter_data(name_prefix, fields_to_select, **filters):
68 def closure(data):
69 for result in data:
70 if name_prefix is not None:
71 if not result['jobname'].startswith(name_prefix):
72 continue
73
74 for k, v in filters.items():
75 if result.get(k) != v:
76 break
77 else:
78 yield map(result.get, fields_to_select)
79 return closure
80
81
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030082def filter_processed_data(name_prefix, fields_to_select, **filters):
83 def closure(data):
84 for name, result in data.items():
85 if name_prefix is not None:
86 if not name.startswith(name_prefix):
87 continue
88
89 for k, v in filters.items():
90 if result.raw.get(k) != v:
91 break
92 else:
93 yield map(result.raw.get, fields_to_select)
94 return closure
95
96
koder aka kdanilov63ad2062015-04-27 13:11:40 +030097# def load_data(raw_data):
98# data = list(parse_output(raw_data))[0]
koder aka kdanilov6c491062015-04-09 22:33:13 +030099
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300100# for key, val in data['res'].items():
101# val['blocksize_b'] = ssize_to_b(val['blocksize'])
koder aka kdanilov6c491062015-04-09 22:33:13 +0300102
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300103# val['iops_mediana'], val['iops_stddev'] = med_dev(val['iops'])
104# val['bw_mediana'], val['bw_stddev'] = med_dev(val['bw'])
105# val['lat_mediana'], val['lat_stddev'] = med_dev(val['lat'])
106# yield val
koder aka kdanilov6c491062015-04-09 22:33:13 +0300107
108
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300109# def load_files(*fnames):
110# for fname in fnames:
111# for i in load_data(open(fname).read()):
112# yield i