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', |
koder aka kdanilov | 209e85d | 2015-04-27 23:11:05 +0300 | [diff] [blame] | 12 | 'lat', 'lat_dev', 'raw', |
| 13 | 'meta')) |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 14 | |
| 15 | |
koder aka kdanilov | 209e85d | 2015-04-27 23:11:05 +0300 | [diff] [blame] | 16 | def split_and_add(data, block_size): |
| 17 | assert len(data) % block_size == 0 |
| 18 | res = [0] * block_size |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 19 | |
koder aka kdanilov | 209e85d | 2015-04-27 23:11:05 +0300 | [diff] [blame] | 20 | for idx, val in enumerate(data): |
| 21 | res[idx % block_size] += val |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 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'] |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 33 | for name, results in pre_result['res'].items(): |
koder aka kdanilov | 209e85d | 2015-04-27 23:11:05 +0300 | [diff] [blame] | 34 | assert len(results['bw']) % vm_count == 0 |
| 35 | block_count = len(results['bw']) // vm_count |
| 36 | |
koder aka kdanilov | 209e85d | 2015-04-27 23:11:05 +0300 | [diff] [blame] | 37 | bw, bw_dev = med_dev(split_and_add(results['bw'], block_count)) |
koder aka kdanilov | 63e9c5a | 2015-04-28 23:06:07 +0300 | [diff] [blame] | 38 | iops, _ = med_dev(split_and_add(results['iops'], |
| 39 | block_count)) |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 40 | lat, lat_dev = med_dev(results['lat']) |
| 41 | dev = bw_dev / float(bw) |
koder aka kdanilov | 209e85d | 2015-04-27 23:11:05 +0300 | [diff] [blame] | 42 | data[name] = PerfInfo(name, bw, iops, dev, lat, lat_dev, results, |
| 43 | pre_result['__test_meta__']) |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 44 | return data |
| 45 | |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 46 | |
| 47 | def parse_output(out_err): |
koder aka kdanilov | 46d4f39 | 2015-04-24 11:35:00 +0300 | [diff] [blame] | 48 | 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 kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 56 | 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 | |
| 71 | def 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 kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 86 | def 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 kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 101 | # def load_data(raw_data): |
| 102 | # data = list(parse_output(raw_data))[0] |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 103 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 104 | # for key, val in data['res'].items(): |
| 105 | # val['blocksize_b'] = ssize_to_b(val['blocksize']) |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 106 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 107 | # 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 kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 111 | |
| 112 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 113 | # def load_files(*fnames): |
| 114 | # for fname in fnames: |
| 115 | # for i in load_data(open(fname).read()): |
| 116 | # yield i |