blob: 62489f1b062de78492c6582b34119c5356f24d78 [file] [log] [blame]
koder aka kdanilov652cd802015-04-13 12:21:07 +03001import sys
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02002from collections import OrderedDict
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02003
koder aka kdanilov652cd802015-04-13 12:21:07 +03004import matplotlib.pyplot as plt
koder aka kdanilov66839a92015-04-11 13:22:31 +03005
Yulia Portnova407ca952015-04-10 10:38:15 +03006import formatters
koder aka kdanilov66839a92015-04-11 13:22:31 +03007from chart import charts
koder aka kdanilov2c473092015-03-29 17:12:13 +03008from utils import ssize_to_b
koder aka kdanilov652cd802015-04-13 12:21:07 +03009from statistic import med_dev, approximate_curve
10
11from disk_perf_test_tool.tests.io_results_loader import (load_files,
12 filter_data)
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020013
14
Yulia Portnova7b3b1d42015-02-13 14:08:35 +020015OPERATIONS = (('async', ('randwrite asynchronous', 'randread asynchronous',
16 'write asynchronous', 'read asynchronous')),
17 ('sync', ('randwrite synchronous', 'randread synchronous',
koder aka kdanilov652cd802015-04-13 12:21:07 +030018 'write synchronous', 'read synchronous')),
19 ('direct', ('randwrite direct', 'randread direct',
20 'write direct', 'read direct')))
Yulia Portnova7b3b1d42015-02-13 14:08:35 +020021
22sync_async_view = {'s': 'synchronous',
koder aka kdanilov652cd802015-04-13 12:21:07 +030023 'a': 'asynchronous',
24 'd': 'direct'}
Yulia Portnova042344d2015-02-10 17:38:33 +020025
26
koder aka kdanilov652cd802015-04-13 12:21:07 +030027# def pgbench_chart_data(results):
28# """
29# Format pgbench results for chart
30# """
31# data = {}
32# charts_url = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020033
koder aka kdanilov652cd802015-04-13 12:21:07 +030034# formatted_res = formatters.format_pgbench_stat(results)
35# for key, value in formatted_res.items():
36# num_cl, num_tr = key.split(' ')
37# data.setdefault(num_cl, {}).setdefault(build, {})
38# data[keys[z]][build][
39# ' '.join(keys)] = value
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020040
koder aka kdanilov652cd802015-04-13 12:21:07 +030041# for name, value in data.items():
42# title = name
43# legend = []
44# dataset = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020045
koder aka kdanilov652cd802015-04-13 12:21:07 +030046# scale_x = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020047
koder aka kdanilov652cd802015-04-13 12:21:07 +030048# for build_id, build_results in value.items():
49# vals = []
50# OD = OrderedDict
51# ordered_build_results = OD(sorted(build_results.items(),
52# key=lambda t: t[0]))
53# scale_x = ordered_build_results.keys()
54# for key in scale_x:
55# res = build_results.get(key)
56# if res:
57# vals.append(res)
58# if vals:
59# dataset.append(vals)
60# legend.append(build_id)
Yulia Portnovae4408022015-02-10 15:39:25 +020061
koder aka kdanilov652cd802015-04-13 12:21:07 +030062# if dataset:
63# charts_url.append(str(charts.render_vertical_bar
64# (title, legend, dataset, scale_x=scale_x)))
65# return charts_url
Yulia Portnova919f3be2015-02-06 12:49:22 +020066
67
Yulia Portnova407ca952015-04-10 10:38:15 +030068def build_vertical_bar(results, z=0):
69 data = {}
70 charts_url = []
71 for build, res in results:
72 formatted_res = formatters.get_formatter(build)(res)
73 for key, value in formatted_res.items():
74 keys = key.split(' ')
75 data.setdefault(keys[z], {}).setdefault(build, {})
76 data[keys[z]][build][
77 ' '.join(keys)] = value
78
79 for name, value in data.items():
80 title = name
81 legend = []
82 dataset = []
83
84 scale_x = []
85
86 for build_id, build_results in value.items():
87 vals = []
88 OD = OrderedDict
89 ordered_build_results = OD(sorted(build_results.items(),
90 key=lambda t: t[0]))
91 scale_x = ordered_build_results.keys()
92 for key in scale_x:
93 res = build_results.get(key)
94 if res:
95 vals.append(res)
96 if vals:
97 dataset.append(vals)
98 legend.append(build_id)
99
100 if dataset:
101 charts_url.append(str(charts.render_vertical_bar
102 (title, legend, dataset, scale_x=scale_x)))
103 return charts_url
104
105
106def build_lines_chart(results, z=0):
Yulia Portnova919f3be2015-02-06 12:49:22 +0200107 data = {}
108 charts_url = []
109
Yulia Portnova407ca952015-04-10 10:38:15 +0300110 for build, res in results:
111 formatted_res = formatters.get_formatter(build)(res)
112 for key, value in formatted_res.items():
Yulia Portnova919f3be2015-02-06 12:49:22 +0200113 keys = key.split(' ')
Yulia Portnova407ca952015-04-10 10:38:15 +0300114 data.setdefault(key[z], {})
115 data[key[z]].setdefault(build, {})[keys[1]] = value
Yulia Portnova919f3be2015-02-06 12:49:22 +0200116
117 for name, value in data.items():
118 title = name
119 legend = []
120 dataset = []
121 scale_x = []
122 for build_id, build_results in value.items():
123 legend.append(build_id)
koder aka kdanilove21d7472015-02-14 19:02:04 -0800124
125 OD = OrderedDict
126 ordered_build_results = OD(sorted(build_results.items(),
koder aka kdanilov2c473092015-03-29 17:12:13 +0300127 key=lambda t: ssize_to_b(t[0])))
koder aka kdanilove21d7472015-02-14 19:02:04 -0800128
Yulia Portnova919f3be2015-02-06 12:49:22 +0200129 if not scale_x:
130 scale_x = ordered_build_results.keys()
131 dataset.append(zip(*ordered_build_results.values())[0])
132
133 chart = charts.render_lines(title, legend, dataset, scale_x)
134 charts_url.append(str(chart))
135
136 return charts_url
137
138
Yulia Portnova407ca952015-04-10 10:38:15 +0300139def render_html(charts_urls, dest):
Yulia Portnova919f3be2015-02-06 12:49:22 +0200140 templ = open("report.html", 'r').read()
141 body = "<div><ol>%s</ol></div>"
142 li = "<li><img src='%s'></li>"
143 ol = []
144 for chart in charts_urls:
145 ol.append(li % chart)
146 html = templ % {'body': body % '\n'.join(ol)}
Yulia Portnova407ca952015-04-10 10:38:15 +0300147 open(dest, 'w').write(html)
Yulia Portnova919f3be2015-02-06 12:49:22 +0200148
149
Yulia Portnova407ca952015-04-10 10:38:15 +0300150def build_io_chart(res):
151 pass
152
153
koder aka kdanilov652cd802015-04-13 12:21:07 +0300154# def render_html_results(ctx):
155# charts = []
156# for res in ctx.results:
157# if res[0] == "io":
158# charts.append(build_io_chart(res))
Yulia Portnova407ca952015-04-10 10:38:15 +0300159
koder aka kdanilov652cd802015-04-13 12:21:07 +0300160# bars = build_vertical_bar(ctx.results)
161# lines = build_lines_chart(ctx.results)
Yulia Portnova407ca952015-04-10 10:38:15 +0300162
koder aka kdanilov652cd802015-04-13 12:21:07 +0300163 # render_html(bars + lines, dest)
Yulia Portnova407ca952015-04-10 10:38:15 +0300164
Yulia Portnova407ca952015-04-10 10:38:15 +0300165
koder aka kdanilov652cd802015-04-13 12:21:07 +0300166def make_io_report(results):
167 for suite_type, test_suite_data in results:
168 if suite_type != 'io':
169 continue
Yulia Portnova407ca952015-04-10 10:38:15 +0300170
koder aka kdanilov652cd802015-04-13 12:21:07 +0300171 io_test_suite_res = test_suite_data['res']
koder aka kdanilov66839a92015-04-11 13:22:31 +0300172
koder aka kdanilov652cd802015-04-13 12:21:07 +0300173 charts_url = []
koder aka kdanilov66839a92015-04-11 13:22:31 +0300174
koder aka kdanilov652cd802015-04-13 12:21:07 +0300175 name_filters = [
176 #('hdd_test_rws4k', ('concurence', 'lat', 'iops')),
177 #('hdd_test_rrs4k', ('concurence', 'lat', 'iops')),
178 ('hdd_test_rrd4k', ('concurence', 'lat', 'iops')),
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300179 ('hdd_test_swd1m', ('concurence', 'lat', 'bw')),
koder aka kdanilov652cd802015-04-13 12:21:07 +0300180 ]
koder aka kdanilov66839a92015-04-11 13:22:31 +0300181
koder aka kdanilov652cd802015-04-13 12:21:07 +0300182 for name_filter, fields in name_filters:
183 th_filter = filter_data(name_filter, fields)
koder aka kdanilov66839a92015-04-11 13:22:31 +0300184
koder aka kdanilov652cd802015-04-13 12:21:07 +0300185 data_iter = sorted(th_filter(io_test_suite_res.values()))
Yulia Portnova407ca952015-04-10 10:38:15 +0300186
koder aka kdanilov652cd802015-04-13 12:21:07 +0300187 concurence, latv, iops_or_bw_v = zip(*data_iter)
188 iops_or_bw_v, iops_or_bw_dev_v = zip(*map(med_dev, iops_or_bw_v))
Yulia Portnova407ca952015-04-10 10:38:15 +0300189
koder aka kdanilov652cd802015-04-13 12:21:07 +0300190 _, ax1 = plt.subplots()
Yulia Portnova407ca952015-04-10 10:38:15 +0300191
koder aka kdanilov652cd802015-04-13 12:21:07 +0300192 ax1.plot(concurence, iops_or_bw_v)
193 ax1.errorbar(concurence, iops_or_bw_v, iops_or_bw_dev_v,
194 linestyle='None',
195 label="iops_or_bw_v",
196 marker="*")
197
198 # ynew = approximate_line(ax, ay, ax, True)
199
200 ax2 = ax1.twinx()
201
202 ax2.errorbar(concurence,
203 [med_dev(lat)[0] / 1000 for lat in latv],
204 [med_dev(lat)[1] / 1000 for lat in latv],
205 linestyle='None',
206 label="iops_or_bw_v",
207 marker="*")
208 ax2.plot(concurence, [med_dev(lat)[0] / 1000 for lat in latv])
209 plt.show()
210 exit(0)
211
212 # bw_only = []
213
214 # for conc, _, _, (bw, _) in data:
215 # bw_only.append(bw)
216 # bw_d_per_th.append((bw / conc, 0))
217
218 # lines = [(zip(*lat_d)[0], 'msec', 'rr', 'lat'), (bw_sum, None, None, 'bw_sum')]
219
220 # chart_url = charts.render_vertical_bar(
221 # chart_name, ["bw"], [bw_d_per_th], label_x="KBps",
222 # scale_x=ordered_data.keys(),
223 # lines=lines)
224
225 # charts_url.append(str(chart_url))
226
Yulia Portnova407ca952015-04-10 10:38:15 +0300227 render_html(charts_url, "results.html")
koder aka kdanilov652cd802015-04-13 12:21:07 +0300228
229
230def main(args):
231 make_io_report('/tmp/report', load_files(args[1:]))
Yulia Portnova407ca952015-04-10 10:38:15 +0300232 return 0
233
234
235if __name__ == '__main__':
koder aka kdanilov652cd802015-04-13 12:21:07 +0300236 exit(main(sys.argv))