koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 1 | import re |
| 2 | import sys |
| 3 | import json |
| 4 | |
| 5 | splitter_rr = "(?ms)=====+\n" |
| 6 | |
| 7 | |
| 8 | def get_data_from_output(fname): |
| 9 | results = {} |
| 10 | fc = open(fname).read() |
| 11 | |
| 12 | for block in re.split(splitter_rr, fc): |
| 13 | block = block.strip() |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame^] | 14 | |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 15 | if not block.startswith("[{u'__meta__':"): |
| 16 | continue |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame^] | 17 | |
| 18 | print |
| 19 | print |
| 20 | print block |
| 21 | print |
| 22 | print |
| 23 | |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 24 | for val in eval(block): |
| 25 | meta = val['__meta__'] |
| 26 | meta['sync'] = 's' if meta['sync'] else 'a' |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 27 | key = "{action} {sync} {blocksize}k {concurence}".format(**meta) |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 28 | results.setdefault(key, []).append(val['bw_mean']) |
| 29 | |
| 30 | processed_res = {} |
| 31 | |
| 32 | for k, v in results.items(): |
| 33 | v.sort() |
| 34 | med = float(sum(v)) / len(v) |
| 35 | ran = sum(abs(x - med) for x in v) / len(v) |
| 36 | processed_res[k] = (int(med), int(ran)) |
| 37 | |
| 38 | return meta, processed_res |
| 39 | |
| 40 | |
| 41 | def ksort(x): |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 42 | op, sync, sz, conc = x.split(" ") |
| 43 | return (op, sync, int(sz[:-1]), int(conc)) |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 44 | |
| 45 | |
| 46 | def create_json_results(meta, file_data): |
| 47 | row = {"build_id": "", |
| 48 | "type": "", |
| 49 | "iso_md5": ""} |
| 50 | row.update(file_data) |
| 51 | return json.dumps(row) |
| 52 | |
| 53 | |
| 54 | def show_data(*pathes): |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 55 | begin = "| {:>10} {:>5} {:>5} {:>3}" |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 56 | first_file_templ = " | {:>6} ~ {:>5} {:>2}% {:>5}" |
| 57 | other_file_templ = " | {:>6} ~ {:>5} {:>2}% {:>5} ---- {:>6}%" |
| 58 | |
| 59 | line_templ = begin + first_file_templ + \ |
| 60 | other_file_templ * (len(pathes) - 1) + " |" |
| 61 | |
| 62 | header_ln = line_templ.replace("<", "^").replace(">", "^") |
| 63 | |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 64 | params = ["Oper", "Sync", "BSZ", "CC", "BW1", "DEV1", "%", "IOPS1"] |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 65 | for pos in range(1, len(pathes)): |
| 66 | params += "BW{0}+DEV{0}+%+IOPS{0}+DIFF %".format(pos).split("+") |
| 67 | |
| 68 | header_ln = header_ln.format(*params) |
| 69 | |
| 70 | sep = '-' * len(header_ln) |
| 71 | |
| 72 | results = [get_data_from_output(path)[1] for path in pathes] |
| 73 | |
| 74 | print sep |
| 75 | print header_ln |
| 76 | print sep |
| 77 | |
| 78 | prev_tp = None |
| 79 | |
| 80 | common_keys = set(results[0].keys()) |
| 81 | for result in results[1:]: |
| 82 | common_keys &= set(result.keys()) |
| 83 | |
| 84 | for k in sorted(common_keys, key=ksort): |
| 85 | tp = k.rsplit(" ", 1)[0] |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 86 | op, s, sz, conc = k.split(" ") |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 87 | s = 'sync' if s == 's' else 'async' |
| 88 | |
| 89 | if tp != prev_tp and prev_tp is not None: |
| 90 | print sep |
| 91 | |
| 92 | prev_tp = tp |
| 93 | |
| 94 | results0 = results[0] |
| 95 | m0, d0 = results0[k] |
| 96 | iops0 = m0 / int(sz[:-1]) |
| 97 | perc0 = int(d0 * 100.0 / m0 + 0.5) |
| 98 | |
koder aka kdanilov | 3f35626 | 2015-02-13 08:06:14 -0800 | [diff] [blame] | 99 | data = [op, s, sz, conc, m0, d0, perc0, iops0] |
koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 100 | |
| 101 | for result in results[1:]: |
| 102 | m, d = result[k] |
| 103 | iops = m / int(sz[:-1]) |
| 104 | perc = int(d * 100.0 / m + 0.5) |
| 105 | avg_diff = int(((m - m0) * 100.) / m + 0.5) |
| 106 | data.extend([m, d, perc, iops, avg_diff]) |
| 107 | |
| 108 | print line_templ.format(*data) |
| 109 | |
| 110 | print sep |
| 111 | |
| 112 | |
| 113 | def main(argv): |
| 114 | path1 = argv[0] |
| 115 | if path1 == '--json': |
| 116 | print create_json_results(*get_data_from_output(argv[1])) |
| 117 | else: |
| 118 | show_data(*argv) |
| 119 | return 0 |
| 120 | |
| 121 | if __name__ == "__main__": |
| 122 | exit(main(sys.argv[1:])) |
| 123 | # print " ", results[k] |