Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 1 | import argparse |
| 2 | from collections import OrderedDict |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 3 | import itertools |
| 4 | import math |
| 5 | import re |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 6 | |
Yulia Portnova | 5c9c6dd | 2015-02-11 13:29:04 +0200 | [diff] [blame] | 7 | from chart import charts |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 8 | import formatters |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 9 | from utils import ssize_to_b |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 10 | |
| 11 | |
Yulia Portnova | 7b3b1d4 | 2015-02-13 14:08:35 +0200 | [diff] [blame] | 12 | OPERATIONS = (('async', ('randwrite asynchronous', 'randread asynchronous', |
| 13 | 'write asynchronous', 'read asynchronous')), |
| 14 | ('sync', ('randwrite synchronous', 'randread synchronous', |
| 15 | 'write synchronous', 'read synchronous'))) |
| 16 | |
| 17 | sync_async_view = {'s': 'synchronous', |
| 18 | 'a': 'asynchronous'} |
Yulia Portnova | 042344d | 2015-02-10 17:38:33 +0200 | [diff] [blame] | 19 | |
| 20 | |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 21 | def parse_args(argv): |
| 22 | parser = argparse.ArgumentParser() |
| 23 | parser.add_argument('-s', '--storage', help='storage location', dest="url") |
| 24 | parser.add_argument('-e', '--email', help='user email', |
| 25 | default="aaa@gmail.com") |
| 26 | parser.add_argument('-p', '--password', help='user password', |
| 27 | default="1234") |
| 28 | return parser.parse_args(argv) |
| 29 | |
| 30 | |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 31 | def pgbench_chart_data(results): |
| 32 | """ |
| 33 | Format pgbench results for chart |
| 34 | """ |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 35 | data = {} |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 36 | charts_url = [] |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 37 | |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 38 | formatted_res = formatters.format_pgbench_stat(results) |
| 39 | for key, value in formatted_res.items(): |
| 40 | num_cl, num_tr = key.split(' ') |
| 41 | data.setdefault(num_cl, {}).setdefault(build, {}) |
| 42 | data[keys[z]][build][ |
| 43 | ' '.join(keys)] = value |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 44 | |
| 45 | for name, value in data.items(): |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 46 | title = name |
| 47 | legend = [] |
| 48 | dataset = [] |
Yulia Portnova | e440802 | 2015-02-10 15:39:25 +0200 | [diff] [blame] | 49 | |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 50 | scale_x = [] |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 51 | |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 52 | for build_id, build_results in value.items(): |
| 53 | vals = [] |
| 54 | OD = OrderedDict |
| 55 | ordered_build_results = OD(sorted(build_results.items(), |
| 56 | key=lambda t: t[0])) |
| 57 | scale_x = ordered_build_results.keys() |
| 58 | for key in scale_x: |
| 59 | res = build_results.get(key) |
| 60 | if res: |
| 61 | vals.append(res) |
| 62 | if vals: |
| 63 | dataset.append(vals) |
| 64 | legend.append(build_id) |
Yulia Portnova | e440802 | 2015-02-10 15:39:25 +0200 | [diff] [blame] | 65 | |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 66 | if dataset: |
| 67 | charts_url.append(str(charts.render_vertical_bar |
| 68 | (title, legend, dataset, scale_x=scale_x))) |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 69 | return charts_url |
| 70 | |
| 71 | |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 72 | def build_vertical_bar(results, z=0): |
| 73 | data = {} |
| 74 | charts_url = [] |
| 75 | for build, res in results: |
| 76 | formatted_res = formatters.get_formatter(build)(res) |
| 77 | for key, value in formatted_res.items(): |
| 78 | keys = key.split(' ') |
| 79 | data.setdefault(keys[z], {}).setdefault(build, {}) |
| 80 | data[keys[z]][build][ |
| 81 | ' '.join(keys)] = value |
| 82 | |
| 83 | for name, value in data.items(): |
| 84 | title = name |
| 85 | legend = [] |
| 86 | dataset = [] |
| 87 | |
| 88 | scale_x = [] |
| 89 | |
| 90 | for build_id, build_results in value.items(): |
| 91 | vals = [] |
| 92 | OD = OrderedDict |
| 93 | ordered_build_results = OD(sorted(build_results.items(), |
| 94 | key=lambda t: t[0])) |
| 95 | scale_x = ordered_build_results.keys() |
| 96 | for key in scale_x: |
| 97 | res = build_results.get(key) |
| 98 | if res: |
| 99 | vals.append(res) |
| 100 | if vals: |
| 101 | dataset.append(vals) |
| 102 | legend.append(build_id) |
| 103 | |
| 104 | if dataset: |
| 105 | charts_url.append(str(charts.render_vertical_bar |
| 106 | (title, legend, dataset, scale_x=scale_x))) |
| 107 | return charts_url |
| 108 | |
| 109 | |
| 110 | def build_lines_chart(results, z=0): |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 111 | data = {} |
| 112 | charts_url = [] |
| 113 | |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 114 | for build, res in results: |
| 115 | formatted_res = formatters.get_formatter(build)(res) |
| 116 | for key, value in formatted_res.items(): |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 117 | keys = key.split(' ') |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 118 | data.setdefault(key[z], {}) |
| 119 | data[key[z]].setdefault(build, {})[keys[1]] = value |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 120 | |
| 121 | for name, value in data.items(): |
| 122 | title = name |
| 123 | legend = [] |
| 124 | dataset = [] |
| 125 | scale_x = [] |
| 126 | for build_id, build_results in value.items(): |
| 127 | legend.append(build_id) |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 128 | |
| 129 | OD = OrderedDict |
| 130 | ordered_build_results = OD(sorted(build_results.items(), |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 131 | key=lambda t: ssize_to_b(t[0]))) |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 132 | |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 133 | if not scale_x: |
| 134 | scale_x = ordered_build_results.keys() |
| 135 | dataset.append(zip(*ordered_build_results.values())[0]) |
| 136 | |
| 137 | chart = charts.render_lines(title, legend, dataset, scale_x) |
| 138 | charts_url.append(str(chart)) |
| 139 | |
| 140 | return charts_url |
| 141 | |
| 142 | |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 143 | def render_html(charts_urls, dest): |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 144 | templ = open("report.html", 'r').read() |
| 145 | body = "<div><ol>%s</ol></div>" |
| 146 | li = "<li><img src='%s'></li>" |
| 147 | ol = [] |
| 148 | for chart in charts_urls: |
| 149 | ol.append(li % chart) |
| 150 | html = templ % {'body': body % '\n'.join(ol)} |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 151 | open(dest, 'w').write(html) |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 152 | |
| 153 | |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 154 | def build_io_chart(res): |
| 155 | pass |
| 156 | |
| 157 | |
| 158 | def render_html_results(ctx, dest): |
| 159 | charts = [] |
| 160 | import ipdb;ipdb.set_trace() |
| 161 | for res in ctx.results: |
| 162 | if res[0] == "io": |
| 163 | charts.append(build_io_chart(res)) |
| 164 | |
| 165 | bars = build_vertical_bar(ctx.results) |
| 166 | lines = build_lines_chart(ctx.results) |
| 167 | |
| 168 | render_html(bars + lines, dest) |
| 169 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 170 | # def report(url, email=None, password=None): |
| 171 | # results = storage.recent_builds() |
| 172 | # bars = build_vertical_bar(results) |
| 173 | # lines = build_lines_chart(results) |
| 174 | # |
| 175 | # render_html(bars + lines) |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 176 | # |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 177 | |
Yulia Portnova | 407ca95 | 2015-04-10 10:38:15 +0300 | [diff] [blame^] | 178 | |
| 179 | def calc_dev(l): |
| 180 | sum_res = sum(l) |
| 181 | mean = sum_res/len(l) |
| 182 | sum_sq = sum([(r - mean) ** 2 for r in l]) |
| 183 | if len(l) > 1: |
| 184 | return math.sqrt(sum_sq / (len(l) - 1)) |
| 185 | else: |
| 186 | return 0 |
| 187 | |
| 188 | |
| 189 | def main(): |
| 190 | from tests.disk_test_agent import parse_output |
| 191 | out = parse_output( |
| 192 | open("results/io_scenario_check_th_count.txt").read()).next() |
| 193 | results = out['res'] |
| 194 | |
| 195 | charts_url = [] |
| 196 | charts_data = {} |
| 197 | for test_name, test_res in results.items(): |
| 198 | blocksize = test_res['blocksize'] |
| 199 | op_type = "sync" if test_res['sync'] else "direct" |
| 200 | chart_name = "Block size: %s %s" % (blocksize, op_type) |
| 201 | lat = sum(test_res['lat']) / len(test_res['lat']) / 1000 |
| 202 | lat_dev = calc_dev(test_res['lat']) |
| 203 | iops = sum(test_res['iops']) / len(test_res['iops']) |
| 204 | iops_dev = calc_dev(test_res['iops']) |
| 205 | bw = sum(test_res['bw_mean']) / len(test_res['bw_mean']) |
| 206 | bw_dev = calc_dev(test_res['bw_mean']) |
| 207 | conc = test_res['concurence'] |
| 208 | vals = ((lat, lat_dev), (iops, iops_dev), (bw, bw_dev)) |
| 209 | charts_data.setdefault(chart_name, {})[conc] = vals |
| 210 | |
| 211 | for chart_name, chart_data in charts_data.items(): |
| 212 | legend = ["bw"] |
| 213 | ordered_data = OrderedDict(sorted(chart_data.items(), |
| 214 | key=lambda t: t[0])) |
| 215 | |
| 216 | lat_d, iops_d, bw_d = zip(*ordered_data.values()) |
| 217 | bw_sum = [vals[2][0] * conc for conc, vals in ordered_data.items()] |
| 218 | |
| 219 | chart_url = str(charts.render_vertical_bar( |
| 220 | chart_name, legend, [bw_d], label_x="KBps", |
| 221 | scale_x=ordered_data.keys(), |
| 222 | lines=[(zip(*lat_d)[0], 'msec', 'rr', 'lat'), (bw_sum, None, None, 'bw_sum')])) |
| 223 | charts_url.append(chart_url) |
| 224 | render_html(charts_url, "results.html") |
| 225 | return 0 |
| 226 | |
| 227 | |
| 228 | if __name__ == '__main__': |
| 229 | exit(main()) |