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 | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame] | 6 | from wally.utils import ssize_to_b |
| 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 | |
| 15 | def process_disk_info(test_output): |
| 16 | data = {} |
| 17 | |
| 18 | for tp, pre_result in test_output: |
| 19 | if tp != 'io': |
| 20 | pass |
| 21 | |
| 22 | for name, results in pre_result['res'].items(): |
| 23 | bw, bw_dev = med_dev(results['bw']) |
| 24 | iops, iops_dev = med_dev(results['iops']) |
| 25 | lat, lat_dev = med_dev(results['lat']) |
| 26 | dev = bw_dev / float(bw) |
| 27 | data[name] = PerfInfo(name, bw, iops, dev, lat, lat_dev, results) |
| 28 | return data |
| 29 | |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 30 | |
| 31 | def parse_output(out_err): |
| 32 | start_patt = r"(?ims)=+\s+RESULTS\(format=json\)\s+=+" |
| 33 | end_patt = r"(?ims)=+\s+END OF RESULTS\s+=+" |
| 34 | |
| 35 | for block in re.split(start_patt, out_err)[1:]: |
| 36 | data, garbage = re.split(end_patt, block) |
| 37 | yield json.loads(data.strip()) |
| 38 | |
| 39 | start_patt = r"(?ims)=+\s+RESULTS\(format=eval\)\s+=+" |
| 40 | end_patt = r"(?ims)=+\s+END OF RESULTS\s+=+" |
| 41 | |
| 42 | for block in re.split(start_patt, out_err)[1:]: |
| 43 | data, garbage = re.split(end_patt, block) |
| 44 | yield eval(data.strip()) |
| 45 | |
| 46 | |
| 47 | def filter_data(name_prefix, fields_to_select, **filters): |
| 48 | def closure(data): |
| 49 | for result in data: |
| 50 | if name_prefix is not None: |
| 51 | if not result['jobname'].startswith(name_prefix): |
| 52 | continue |
| 53 | |
| 54 | for k, v in filters.items(): |
| 55 | if result.get(k) != v: |
| 56 | break |
| 57 | else: |
| 58 | yield map(result.get, fields_to_select) |
| 59 | return closure |
| 60 | |
| 61 | |
koder aka kdanilov | 4a510ee | 2015-04-21 18:50:42 +0300 | [diff] [blame^] | 62 | def filter_processed_data(name_prefix, fields_to_select, **filters): |
| 63 | def closure(data): |
| 64 | for name, result in data.items(): |
| 65 | if name_prefix is not None: |
| 66 | if not name.startswith(name_prefix): |
| 67 | continue |
| 68 | |
| 69 | for k, v in filters.items(): |
| 70 | if result.raw.get(k) != v: |
| 71 | break |
| 72 | else: |
| 73 | yield map(result.raw.get, fields_to_select) |
| 74 | return closure |
| 75 | |
| 76 | |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 77 | def load_data(raw_data): |
| 78 | data = list(parse_output(raw_data))[0] |
| 79 | |
| 80 | for key, val in data['res'].items(): |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 81 | val['blocksize_b'] = ssize_to_b(val['blocksize']) |
| 82 | |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 83 | val['iops_mediana'], val['iops_stddev'] = med_dev(val['iops']) |
koder aka kdanilov | 4e9f3ed | 2015-04-14 11:26:12 +0300 | [diff] [blame] | 84 | val['bw_mediana'], val['bw_stddev'] = med_dev(val['bw']) |
koder aka kdanilov | 652cd80 | 2015-04-13 12:21:07 +0300 | [diff] [blame] | 85 | val['lat_mediana'], val['lat_stddev'] = med_dev(val['lat']) |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 86 | yield val |
| 87 | |
| 88 | |
| 89 | def load_files(*fnames): |
| 90 | for fname in fnames: |
| 91 | for i in load_data(open(fname).read()): |
| 92 | yield i |