blob: ea8e9431f5f54025ffe41d98d7713d9a290a65a0 [file] [log] [blame]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03001import os
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +03002import math
koder aka kdanilov4a510ee2015-04-21 18:50:42 +03003import bisect
koder aka kdanilova047e1b2015-04-21 23:16:59 +03004import logging
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03005
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +03006try:
7 import matplotlib.pyplot as plt
8except ImportError:
9 plt = None
10
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030011import wally
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030012from wally import charts
koder aka kdanilov209e85d2015-04-27 23:11:05 +030013from wally.statistic import round_3_digit
koder aka kdanilov63ad2062015-04-27 13:11:40 +030014from wally.utils import parse_creds, ssize_to_b
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030015from wally.suits.io.results_loader import process_disk_info
koder aka kdanilovea7eac72015-04-21 21:37:27 +030016from wally.meta_info import total_lab_info, collect_lab_data
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030017
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030018
koder aka kdanilova047e1b2015-04-21 23:16:59 +030019logger = logging.getLogger("wally.report")
20
21
koder aka kdanilov209e85d2015-04-27 23:11:05 +030022class DiskInfo(object):
23 def __init__(self):
24 self.direct_iops_r_max = 0
25 self.direct_iops_w_max = 0
26 self.rws4k_10ms = 0
27 self.rws4k_30ms = 0
28 self.rws4k_100ms = 0
29 self.bw_write_max = 0
30 self.bw_read_max = 0
31
32
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030033report_funcs = []
34
35
36def report(name, required_fields):
37 def closure(func):
38 report_funcs.append((required_fields.split(","), name, func))
39 return func
40 return closure
41
42
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030043def linearity_report(processed_results, path, lab_info):
44 names = {}
45 for tp1 in ('rand', 'seq'):
46 for oper in ('read', 'write'):
47 for sync in ('sync', 'direct', 'async'):
48 sq = (tp1, oper, sync)
49 name = "{0} {1} {2}".format(*sq)
50 names["".join(word[0] for word in sq)] = name
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030051
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030052 colors = ['red', 'green', 'blue', 'cyan',
53 'magenta', 'black', 'yellow', 'burlywood']
54 markers = ['*', '^', 'x', 'o', '+', '.']
55 color = 0
56 marker = 0
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030057
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030058 plot_data = {}
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030059
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030060 name_pref = 'linearity_test_rrd'
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030061
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030062 for res in processed_results.values():
63 if res.name.startswith(name_pref):
64 iotime = 1000000. / res.iops
65 iotime_max = iotime * (1 + res.dev * 3)
66 bsize = ssize_to_b(res.raw['blocksize'])
67 plot_data[bsize] = (iotime, iotime_max)
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030068
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030069 min_sz = min(plot_data)
70 min_iotime, _ = plot_data.pop(min_sz)
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030071
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030072 x = []
73 y = []
74 e = []
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030075
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030076 for k, (v, vmax) in sorted(plot_data.items()):
77 # y.append(math.log10(v - min_iotime))
78 # x.append(math.log10(k))
79 # e.append(y[-1] - math.log10(vmax - min_iotime))
80 y.append(v - min_iotime)
81 x.append(k)
82 e.append(y[-1] - (vmax - min_iotime))
83
84 print e
85
86 tp = 'rrd'
87 plt.errorbar(x, y, e, linestyle='None', label=names[tp],
88 color=colors[color], ecolor="black",
89 marker=markers[marker])
90 plt.yscale('log')
91 plt.xscale('log')
92 plt.show()
93
94 # ynew = approximate_line(ax, ay, ax, True)
95 # plt.plot(ax, ynew, color=colors[color])
96 # color += 1
97 # marker += 1
98 # plt.legend(loc=2)
99 # plt.title("Linearity test by %i dots" % (len(vals)))
100
101
102if plt:
103 linearity_report = report('linearity', 'linearity_test')(linearity_report)
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300104
105
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300106def render_hdd_html(dest, info, lab_description):
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300107 very_root_dir = os.path.dirname(os.path.dirname(wally.__file__))
108 templ_dir = os.path.join(very_root_dir, 'report_templates')
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300109 templ_file = os.path.join(templ_dir, "report_hdd.html")
110 templ = open(templ_file, 'r').read()
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300111
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300112 for name, val in info.__dict__.items():
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300113 if not name.startswith('__'):
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300114 if val is None:
115 info.__dict__[name] = '-'
116 else:
117 info.__dict__[name] = round_3_digit(val)
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300118
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300119 report = templ.format(lab_info=lab_description, **info.__dict__)
120 open(dest, 'w').write(report)
121
122
123def render_ceph_html(dest, info, lab_description):
124 very_root_dir = os.path.dirname(os.path.dirname(wally.__file__))
125 templ_dir = os.path.join(very_root_dir, 'report_templates')
126 templ_file = os.path.join(templ_dir, "report_ceph.html")
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300127 templ = open(templ_file, 'r').read()
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300128
129 for name, val in info.__dict__.items():
130 if not name.startswith('__') and isinstance(val, (int, long, float)):
131 setattr(info, name, round_3_digit(val))
132
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300133 report = templ.format(lab_info=lab_description, **info.__dict__)
134 open(dest, 'w').write(report)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300135
136
137def io_chart(title, concurence, latv, iops_or_bw, iops_or_bw_dev,
138 legend, fname):
139 bar_data, bar_dev = iops_or_bw, iops_or_bw_dev
140 legend = [legend]
141
142 iops_or_bw_per_vm = []
143 for i in range(len(concurence)):
144 iops_or_bw_per_vm.append(iops_or_bw[i] / concurence[i])
145
146 bar_dev_bottom = []
147 bar_dev_top = []
148 for i in range(len(bar_data)):
149 bar_dev_top.append(bar_data[i] + bar_dev[i])
150 bar_dev_bottom.append(bar_data[i] - bar_dev[i])
151
152 latv = [lat / 1000 for lat in latv]
153 ch = charts.render_vertical_bar(title, legend, [bar_data], [bar_dev_top],
154 [bar_dev_bottom], file_name=fname,
Yulia Portnova0d1b45f2015-04-28 16:51:11 +0300155 scale_x=concurence, label_x="clients",
156 label_y="iops",
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300157 lines=[
158 (latv, "msec", "rr", "lat"),
159 (iops_or_bw_per_vm, None, None,
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300160 legend[0] + " per thread")
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300161 ])
162 return str(ch)
163
164
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300165def make_hdd_plots(processed_results, path):
166 plots = [
167 ('hdd_test_rrd4k', 'rand_read_4k', 'Random read 4k direct IOPS'),
koder aka kdanilovea7eac72015-04-21 21:37:27 +0300168 ('hdd_test_rws4k', 'rand_write_4k', 'Random write 4k sync IOPS')
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300169 ]
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300170 make_plots(processed_results, path, plots)
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300171
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300172
173def make_ceph_plots(processed_results, path):
174 plots = [
175 ('ceph_test_rrd4k', 'rand_read_4k', 'Random read 4k direct IOPS'),
176 ('ceph_test_rws4k', 'rand_write_4k', 'Random write 4k sync IOPS'),
177 ('ceph_test_rrd16m', 'rand_read_16m', 'Random read 16m direct MiBps'),
178 ('ceph_test_swd1m', 'seq_write_1m',
179 'Sequential write 1m direct MiBps'),
180 ]
181 make_plots(processed_results, path, plots)
182
183
184def make_plots(processed_results, path, plots):
185 for name_pref, fname, desc in plots:
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300186 chart_data = []
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300187
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300188 for res in processed_results.values():
189 if res.name.startswith(name_pref):
190 chart_data.append(res)
191
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300192 if len(chart_data) == 0:
193 raise ValueError("Can't found any date for " + name_pref)
194
195 use_bw = ssize_to_b(chart_data[0].raw['blocksize']) > 16 * 1024
196
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300197 chart_data.sort(key=lambda x: x.raw['concurence'])
198
199 lat = [x.lat for x in chart_data]
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300200 vm_count = x.meta['testnodes_count']
201 concurence = [x.raw['concurence'] * vm_count for x in chart_data]
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300202
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300203 if use_bw:
204 data = [x.bw for x in chart_data]
205 data_dev = [x.bw * x.dev for x in chart_data]
206 name = "BW"
207 else:
208 data = [x.iops for x in chart_data]
209 data_dev = [x.iops * x.dev for x in chart_data]
210 name = "IOPS"
211
212 io_chart(desc, concurence, lat, data, data_dev, name, fname)
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300213
214
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300215def get_disk_info(processed_results):
216 di = DiskInfo()
217 rws4k_iops_lat_th = []
218
219 for res in processed_results.values():
220 if res.raw['sync_mode'] == 'd' and res.raw['blocksize'] == '4k':
221 if res.raw['rw'] == 'randwrite':
222 di.direct_iops_w_max = max(di.direct_iops_w_max, res.iops)
223 elif res.raw['rw'] == 'randread':
224 di.direct_iops_r_max = max(di.direct_iops_r_max, res.iops)
225 elif res.raw['sync_mode'] == 's' and res.raw['blocksize'] == '4k':
226 if res.raw['rw'] != 'randwrite':
227 continue
228
229 rws4k_iops_lat_th.append((res.iops, res.lat,
230 res.raw['concurence']))
231
232 elif res.raw['sync_mode'] == 'd' and res.raw['blocksize'] == '1m':
233
234 if res.raw['rw'] == 'write':
235 di.bw_write_max = max(di.bw_write_max, res.bw)
236 elif res.raw['rw'] == 'read':
237 di.bw_read_max = max(di.bw_read_max, res.bw)
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300238 elif res.raw['sync_mode'] == 'd' and res.raw['blocksize'] == '16m':
239 if res.raw['rw'] == 'write' or res.raw['rw'] == 'randwrite':
240 di.bw_write_max = max(di.bw_write_max, res.bw)
241 elif res.raw['rw'] == 'read' or res.raw['rw'] == 'randread':
242 di.bw_read_max = max(di.bw_read_max, res.bw)
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300243
244 di.bw_write_max /= 1000
245 di.bw_read_max /= 1000
246
247 rws4k_iops_lat_th.sort(key=lambda (_1, _2, conc): conc)
248
249 latv = [lat for _, lat, _ in rws4k_iops_lat_th]
250
251 for tlatv_ms in [10, 30, 100]:
252 tlat = tlatv_ms * 1000
253 pos = bisect.bisect_left(latv, tlat)
254 if 0 == pos:
255 iops3 = 0
256 elif pos == len(latv):
257 iops3 = latv[-1]
258 else:
259 lat1 = latv[pos - 1]
260 lat2 = latv[pos]
261
262 th1 = rws4k_iops_lat_th[pos - 1][2]
263 th2 = rws4k_iops_lat_th[pos][2]
264
265 iops1 = rws4k_iops_lat_th[pos - 1][0]
266 iops2 = rws4k_iops_lat_th[pos][0]
267
268 th_lat_coef = (th2 - th1) / (lat2 - lat1)
269 th3 = th_lat_coef * (tlat - lat1) + th1
270
271 th_iops_coef = (iops2 - iops1) / (th2 - th1)
272 iops3 = th_iops_coef * (th3 - th1) + iops1
273 setattr(di, 'rws4k_{}ms'.format(tlatv_ms), int(iops3))
274
275 hdi = DiskInfo()
276 hdi.direct_iops_r_max = di.direct_iops_r_max
277 hdi.direct_iops_w_max = di.direct_iops_w_max
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300278 hdi.rws4k_10ms = di.rws4k_10ms if 0 != di.rws4k_10ms else None
279 hdi.rws4k_30ms = di.rws4k_30ms if 0 != di.rws4k_30ms else None
280 hdi.rws4k_100ms = di.rws4k_100ms if 0 != di.rws4k_100ms else None
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300281 hdi.bw_write_max = di.bw_write_max
282 hdi.bw_read_max = di.bw_read_max
283 return hdi
284
285
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300286@report('HDD', 'hdd_test_rrd4k,hdd_test_rws4k')
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300287def make_hdd_report(processed_results, path, lab_info):
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300288 make_hdd_plots(processed_results, path)
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300289 di = get_disk_info(processed_results)
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300290 render_hdd_html(path, di, lab_info)
291
292
293@report('Ceph', 'ceph_test')
294def make_ceph_report(processed_results, path, lab_info):
295 make_ceph_plots(processed_results, path)
296 di = get_disk_info(processed_results)
297 render_ceph_html(path, di, lab_info)
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300298
299
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300300def make_io_report(results, path, lab_url=None, creds=None):
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300301 lab_info = None
302 # if lab_url is not None:
303 # username, password, tenant_name = parse_creds(creds)
304 # creds = {'username': username,
305 # 'password': password,
306 # "tenant_name": tenant_name}
307 # try:
308 # data = collect_lab_data(lab_url, creds)
309 # lab_info = total_lab_info(data)
310 # except Exception as exc:
311 # logger.warning("Can't collect lab data: {0!s}".format(exc))
312
313 if lab_info is None:
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300314 lab_info = {
315 "total_disk": "None",
316 "total_memory": "None",
317 "nodes_count": "None",
318 "processor_count": "None"
319 }
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300320
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300321 try:
322 processed_results = process_disk_info(results)
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300323 res_fields = sorted(processed_results.keys())
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300324 for fields, name, func in report_funcs:
koder aka kdanilovafd98742015-04-24 01:27:22 +0300325 for field in fields:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300326 pos = bisect.bisect_left(res_fields, field)
327
328 if pos == len(res_fields):
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300329 break
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300330
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300331 if not res_fields[pos].startswith(field):
koder aka kdanilovafd98742015-04-24 01:27:22 +0300332 break
333 else:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300334 hpath = path.format(name)
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300335 logger.debug("Generatins report " + name + " into " + hpath)
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300336 func(processed_results, hpath, lab_info)
koder aka kdanilovafd98742015-04-24 01:27:22 +0300337 break
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300338 else:
339 logger.warning("No report generator found for this load")
koder aka kdanilovafd98742015-04-24 01:27:22 +0300340
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300341 except Exception as exc:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300342 import traceback
343 traceback.print_exc()
koder aka kdanilovec1b9732015-04-23 20:43:29 +0300344 logger.error("Failed to generate html report:" + str(exc))