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 | |
| 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 kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 45 | lat, lat_dev = med_dev(results['lat']) |
| 46 | dev = bw_dev / float(bw) |
koder aka kdanilov | 209e85d | 2015-04-27 23:11:05 +0300 | [diff] [blame^] | 47 | data[name] = PerfInfo(name, bw, iops, dev, lat, lat_dev, results, |
| 48 | pre_result['__test_meta__']) |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 49 | return data |
| 50 | |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 51 | |
| 52 | def parse_output(out_err): |
koder aka kdanilov | 46d4f39 | 2015-04-24 11:35:00 +0300 | [diff] [blame] | 53 | 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 kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 61 | 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 | |
| 76 | def 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 kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame] | 91 | def 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 kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 106 | # def load_data(raw_data): |
| 107 | # data = list(parse_output(raw_data))[0] |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 108 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 109 | # for key, val in data['res'].items(): |
| 110 | # val['blocksize_b'] = ssize_to_b(val['blocksize']) |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 111 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 112 | # 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 kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 116 | |
| 117 | |
koder aka kdanilov | 63ad206 | 2015-04-27 13:11:40 +0300 | [diff] [blame] | 118 | # def load_files(*fnames): |
| 119 | # for fname in fnames: |
| 120 | # for i in load_data(open(fname).read()): |
| 121 | # yield i |