koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 1 | import re |
| 2 | import json |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 3 | import collections |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 4 | |
| 5 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame^] | 6 | # from wally.utils import ssize_to_b |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 7 | from wally.statistic import med_dev |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 8 | |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 9 | PerfInfo = collections.namedtuple('PerfInfo', |
| 10 | ('name', |
| 11 | 'bw', 'iops', 'dev', |
| 12 | 'lat', 'lat_dev', 'raw')) |
| 13 | |
| 14 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame^] | 15 | def 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 kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 26 | def process_disk_info(test_output): |
| 27 | data = {} |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 28 | for tp, pre_result in test_output: |
koder aka kdanilov | e2de58c | 2015-04-24 22:59:36 +0300 | [diff] [blame] | 29 | if tp != 'io' or pre_result is None: |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 30 | pass |
| 31 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame^] | 32 | vm_count = pre_result['__test_meta__']['testnodes_count'] |
| 33 | |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 34 | for name, results in pre_result['res'].items(): |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame^] | 35 | 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 kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 37 | 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 kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 42 | |
| 43 | def parse_output(out_err): |
koder aka kdanilov | 46d4f39 | 2015-04-24 11:35:00 +0300 | [diff] [blame] | 44 | 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 kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 52 | 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 | |
| 67 | def 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 kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 82 | def 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 kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame^] | 97 | # def load_data(raw_data): |
| 98 | # data = list(parse_output(raw_data))[0] |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 99 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame^] | 100 | # for key, val in data['res'].items(): |
| 101 | # val['blocksize_b'] = ssize_to_b(val['blocksize']) |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 102 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame^] | 103 | # 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 kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 107 | |
| 108 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame^] | 109 | # def load_files(*fnames): |
| 110 | # for fname in fnames: |
| 111 | # for i in load_data(open(fname).read()): |
| 112 | # yield i |