blob: e21665da1c91e6d48bd8ed310e1e68e0b58a7cc0 [file] [log] [blame]
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02001import argparse
2from collections import OrderedDict
Yulia Portnova407ca952015-04-10 10:38:15 +03003import itertools
4import math
5import re
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02006
Yulia Portnova5c9c6dd2015-02-11 13:29:04 +02007from chart import charts
Yulia Portnova407ca952015-04-10 10:38:15 +03008import formatters
koder aka kdanilov2c473092015-03-29 17:12:13 +03009from utils import ssize_to_b
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020010
11
Yulia Portnova7b3b1d42015-02-13 14:08:35 +020012OPERATIONS = (('async', ('randwrite asynchronous', 'randread asynchronous',
13 'write asynchronous', 'read asynchronous')),
14 ('sync', ('randwrite synchronous', 'randread synchronous',
15 'write synchronous', 'read synchronous')))
16
17sync_async_view = {'s': 'synchronous',
18 'a': 'asynchronous'}
Yulia Portnova042344d2015-02-10 17:38:33 +020019
20
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020021def 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 Portnova407ca952015-04-10 10:38:15 +030031def pgbench_chart_data(results):
32 """
33 Format pgbench results for chart
34 """
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020035 data = {}
Yulia Portnova919f3be2015-02-06 12:49:22 +020036 charts_url = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020037
Yulia Portnova407ca952015-04-10 10:38:15 +030038 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 Portnova6d72d7f2015-02-04 16:48:50 +020044
45 for name, value in data.items():
Yulia Portnova407ca952015-04-10 10:38:15 +030046 title = name
47 legend = []
48 dataset = []
Yulia Portnovae4408022015-02-10 15:39:25 +020049
Yulia Portnova407ca952015-04-10 10:38:15 +030050 scale_x = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020051
Yulia Portnova407ca952015-04-10 10:38:15 +030052 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 Portnovae4408022015-02-10 15:39:25 +020065
Yulia Portnova407ca952015-04-10 10:38:15 +030066 if dataset:
67 charts_url.append(str(charts.render_vertical_bar
68 (title, legend, dataset, scale_x=scale_x)))
Yulia Portnova919f3be2015-02-06 12:49:22 +020069 return charts_url
70
71
Yulia Portnova407ca952015-04-10 10:38:15 +030072def 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
110def build_lines_chart(results, z=0):
Yulia Portnova919f3be2015-02-06 12:49:22 +0200111 data = {}
112 charts_url = []
113
Yulia Portnova407ca952015-04-10 10:38:15 +0300114 for build, res in results:
115 formatted_res = formatters.get_formatter(build)(res)
116 for key, value in formatted_res.items():
Yulia Portnova919f3be2015-02-06 12:49:22 +0200117 keys = key.split(' ')
Yulia Portnova407ca952015-04-10 10:38:15 +0300118 data.setdefault(key[z], {})
119 data[key[z]].setdefault(build, {})[keys[1]] = value
Yulia Portnova919f3be2015-02-06 12:49:22 +0200120
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 kdanilove21d7472015-02-14 19:02:04 -0800128
129 OD = OrderedDict
130 ordered_build_results = OD(sorted(build_results.items(),
koder aka kdanilov2c473092015-03-29 17:12:13 +0300131 key=lambda t: ssize_to_b(t[0])))
koder aka kdanilove21d7472015-02-14 19:02:04 -0800132
Yulia Portnova919f3be2015-02-06 12:49:22 +0200133 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 Portnova407ca952015-04-10 10:38:15 +0300143def render_html(charts_urls, dest):
Yulia Portnova919f3be2015-02-06 12:49:22 +0200144 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 Portnova407ca952015-04-10 10:38:15 +0300151 open(dest, 'w').write(html)
Yulia Portnova919f3be2015-02-06 12:49:22 +0200152
153
Yulia Portnova407ca952015-04-10 10:38:15 +0300154def build_io_chart(res):
155 pass
156
157
158def 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
gstepanovec9048c2015-02-16 19:17:09 +0200170# 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 Portnova407ca952015-04-10 10:38:15 +0300176#
Yulia Portnova919f3be2015-02-06 12:49:22 +0200177
Yulia Portnova407ca952015-04-10 10:38:15 +0300178
179def 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
189def 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
228if __name__ == '__main__':
229 exit(main())