blob: 4dff18675dc4cdf84307e6396087183022a6ae62 [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
koder aka kdanilov209e85d2015-04-27 23:11:05 +030037 bw, bw_dev = med_dev(split_and_add(results['bw'], block_count))
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030038 iops, _ = med_dev(split_and_add(results['iops'],
39 block_count))
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030040 lat, lat_dev = med_dev(results['lat'])
41 dev = bw_dev / float(bw)
koder aka kdanilov209e85d2015-04-27 23:11:05 +030042 data[name] = PerfInfo(name, bw, iops, dev, lat, lat_dev, results,
43 pre_result['__test_meta__'])
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030044 return data
45
koder aka kdanilov6c491062015-04-09 22:33:13 +030046
47def parse_output(out_err):
koder aka kdanilov46d4f392015-04-24 11:35:00 +030048 err_start_patt = r"(?ims)=+\s+ERROR\s+=+"
49 err_end_patt = r"(?ims)=+\s+END OF ERROR\s+=+"
50
51 for block in re.split(err_start_patt, out_err)[1:]:
52 tb, garbage = re.split(err_end_patt, block)
53 msg = "Test fails with error:\n" + tb.strip() + "\n"
54 raise OSError(msg)
55
koder aka kdanilov6c491062015-04-09 22:33:13 +030056 start_patt = r"(?ims)=+\s+RESULTS\(format=json\)\s+=+"
57 end_patt = r"(?ims)=+\s+END OF RESULTS\s+=+"
58
59 for block in re.split(start_patt, out_err)[1:]:
60 data, garbage = re.split(end_patt, block)
61 yield json.loads(data.strip())
62
63 start_patt = r"(?ims)=+\s+RESULTS\(format=eval\)\s+=+"
64 end_patt = r"(?ims)=+\s+END OF RESULTS\s+=+"
65
66 for block in re.split(start_patt, out_err)[1:]:
67 data, garbage = re.split(end_patt, block)
68 yield eval(data.strip())
69
70
71def filter_data(name_prefix, fields_to_select, **filters):
72 def closure(data):
73 for result in data:
74 if name_prefix is not None:
75 if not result['jobname'].startswith(name_prefix):
76 continue
77
78 for k, v in filters.items():
79 if result.get(k) != v:
80 break
81 else:
82 yield map(result.get, fields_to_select)
83 return closure
84
85
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030086def filter_processed_data(name_prefix, fields_to_select, **filters):
87 def closure(data):
88 for name, result in data.items():
89 if name_prefix is not None:
90 if not name.startswith(name_prefix):
91 continue
92
93 for k, v in filters.items():
94 if result.raw.get(k) != v:
95 break
96 else:
97 yield map(result.raw.get, fields_to_select)
98 return closure
99
100
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300101# def load_data(raw_data):
102# data = list(parse_output(raw_data))[0]
koder aka kdanilov6c491062015-04-09 22:33:13 +0300103
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300104# for key, val in data['res'].items():
105# val['blocksize_b'] = ssize_to_b(val['blocksize'])
koder aka kdanilov6c491062015-04-09 22:33:13 +0300106
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300107# val['iops_mediana'], val['iops_stddev'] = med_dev(val['iops'])
108# val['bw_mediana'], val['bw_stddev'] = med_dev(val['bw'])
109# val['lat_mediana'], val['lat_stddev'] = med_dev(val['lat'])
110# yield val
koder aka kdanilov6c491062015-04-09 22:33:13 +0300111
112
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300113# def load_files(*fnames):
114# for fname in fnames:
115# for i in load_data(open(fname).read()):
116# yield i