blob: eeffefc0c10b5c60a59dbcfb20677465e6cb3b55 [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 kdanilov63ad2062015-04-27 13:11:40 +030013from wally.utils import parse_creds, ssize_to_b
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +030014from wally.statistic import round_3_digit, round_deviation
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 kdanilov7e0f7cf2015-05-01 17:24:35 +0300119 data = info.__dict__.copy()
120 for k, v in data.items():
121 if v is None:
122 data[k] = "-"
123
124 report = templ.format(lab_info=lab_description, **data)
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300125 open(dest, 'w').write(report)
126
127
128def render_ceph_html(dest, info, lab_description):
129 very_root_dir = os.path.dirname(os.path.dirname(wally.__file__))
130 templ_dir = os.path.join(very_root_dir, 'report_templates')
131 templ_file = os.path.join(templ_dir, "report_ceph.html")
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300132 templ = open(templ_file, 'r').read()
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300133
134 for name, val in info.__dict__.items():
135 if not name.startswith('__') and isinstance(val, (int, long, float)):
136 setattr(info, name, round_3_digit(val))
137
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300138 data = info.__dict__.copy()
139 for k, v in data.items():
140 if v is None:
141 data[k] = "-"
142
143 report = templ.format(lab_info=lab_description, **data)
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300144 open(dest, 'w').write(report)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300145
146
147def io_chart(title, concurence, latv, iops_or_bw, iops_or_bw_dev,
148 legend, fname):
149 bar_data, bar_dev = iops_or_bw, iops_or_bw_dev
150 legend = [legend]
151
152 iops_or_bw_per_vm = []
153 for i in range(len(concurence)):
154 iops_or_bw_per_vm.append(iops_or_bw[i] / concurence[i])
155
156 bar_dev_bottom = []
157 bar_dev_top = []
158 for i in range(len(bar_data)):
159 bar_dev_top.append(bar_data[i] + bar_dev[i])
160 bar_dev_bottom.append(bar_data[i] - bar_dev[i])
161
162 latv = [lat / 1000 for lat in latv]
163 ch = charts.render_vertical_bar(title, legend, [bar_data], [bar_dev_top],
164 [bar_dev_bottom], file_name=fname,
Yulia Portnova0d1b45f2015-04-28 16:51:11 +0300165 scale_x=concurence, label_x="clients",
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300166 label_y=legend[0],
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300167 lines=[
168 (latv, "msec", "rr", "lat"),
169 (iops_or_bw_per_vm, None, None,
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300170 legend[0] + " per client")
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300171 ])
172 return str(ch)
173
174
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300175def make_hdd_plots(processed_results, path):
176 plots = [
177 ('hdd_test_rrd4k', 'rand_read_4k', 'Random read 4k direct IOPS'),
koder aka kdanilovea7eac72015-04-21 21:37:27 +0300178 ('hdd_test_rws4k', 'rand_write_4k', 'Random write 4k sync IOPS')
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300179 ]
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300180 make_plots(processed_results, path, plots)
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300181
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300182
183def make_ceph_plots(processed_results, path):
184 plots = [
185 ('ceph_test_rrd4k', 'rand_read_4k', 'Random read 4k direct IOPS'),
186 ('ceph_test_rws4k', 'rand_write_4k', 'Random write 4k sync IOPS'),
187 ('ceph_test_rrd16m', 'rand_read_16m', 'Random read 16m direct MiBps'),
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300188 ('ceph_test_rwd16m', 'rand_write_16m',
189 'Random write 16m direct MiBps'),
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300190 ]
191 make_plots(processed_results, path, plots)
192
193
194def make_plots(processed_results, path, plots):
195 for name_pref, fname, desc in plots:
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300196 chart_data = []
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300197
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300198 for res in processed_results.values():
199 if res.name.startswith(name_pref):
200 chart_data.append(res)
201
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300202 if len(chart_data) == 0:
203 raise ValueError("Can't found any date for " + name_pref)
204
205 use_bw = ssize_to_b(chart_data[0].raw['blocksize']) > 16 * 1024
206
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300207 chart_data.sort(key=lambda x: x.raw['concurence'])
208
209 lat = [x.lat for x in chart_data]
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300210 vm_count = x.meta['testnodes_count']
211 concurence = [x.raw['concurence'] * vm_count for x in chart_data]
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300212
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300213 if use_bw:
214 data = [x.bw for x in chart_data]
215 data_dev = [x.bw * x.dev for x in chart_data]
216 name = "BW"
217 else:
218 data = [x.iops for x in chart_data]
219 data_dev = [x.iops * x.dev for x in chart_data]
220 name = "IOPS"
221
222 io_chart(desc, concurence, lat, data, data_dev, name, fname)
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300223
224
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300225def find_max_where(processed_results, sync_mode, blocksize, rw, iops=True):
226 result = [0, 0]
227 attr = 'iops' if iops else 'bw'
228 for measurement in processed_results.values():
229 ok = measurement.raw['sync_mode'] == sync_mode
230 ok = ok and (measurement.raw['blocksize'] == blocksize)
231 ok = ok and (measurement.raw['rw'] == rw)
232
233 if ok:
234 if getattr(measurement, attr) > result[0]:
235 result = [getattr(measurement, attr), measurement.dev]
236 return result
237
238
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300239def get_disk_info(processed_results):
240 di = DiskInfo()
241 rws4k_iops_lat_th = []
242
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300243 di.direct_iops_w_max = find_max_where(processed_results,
244 'd', '4k', 'randwrite')
245 di.direct_iops_r_max = find_max_where(processed_results,
246 'd', '4k', 'randread')
247 di.bw_write_max = find_max_where(processed_results,
248 'd', '16m', 'randwrite', False)
249 di.bw_read_max = find_max_where(processed_results,
250 'd', '16m', 'randread', False)
251
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300252 for res in processed_results.values():
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300253 if res.raw['sync_mode'] == 's' and res.raw['blocksize'] == '4k':
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300254 if res.raw['rw'] != 'randwrite':
255 continue
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300256 rws4k_iops_lat_th.append((res.iops, res.lat,
257 res.raw['concurence']))
258
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300259 di.bw_write_max[0] /= 1000
260 di.bw_read_max[0] /= 1000
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300261
262 rws4k_iops_lat_th.sort(key=lambda (_1, _2, conc): conc)
263
264 latv = [lat for _, lat, _ in rws4k_iops_lat_th]
265
266 for tlatv_ms in [10, 30, 100]:
267 tlat = tlatv_ms * 1000
268 pos = bisect.bisect_left(latv, tlat)
269 if 0 == pos:
270 iops3 = 0
271 elif pos == len(latv):
272 iops3 = latv[-1]
273 else:
274 lat1 = latv[pos - 1]
275 lat2 = latv[pos]
276
277 th1 = rws4k_iops_lat_th[pos - 1][2]
278 th2 = rws4k_iops_lat_th[pos][2]
279
280 iops1 = rws4k_iops_lat_th[pos - 1][0]
281 iops2 = rws4k_iops_lat_th[pos][0]
282
283 th_lat_coef = (th2 - th1) / (lat2 - lat1)
284 th3 = th_lat_coef * (tlat - lat1) + th1
285
286 th_iops_coef = (iops2 - iops1) / (th2 - th1)
287 iops3 = th_iops_coef * (th3 - th1) + iops1
288 setattr(di, 'rws4k_{}ms'.format(tlatv_ms), int(iops3))
289
290 hdi = DiskInfo()
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300291
292 def pp(x):
293 med, dev = round_deviation((x[0], x[1] * x[0]))
294 # 3 sigma in %
295 dev = int(float(dev) / med * 100)
296 return (med, dev)
297
298 hdi.direct_iops_r_max = pp(di.direct_iops_r_max)
299 hdi.direct_iops_w_max = pp(di.direct_iops_w_max)
300 hdi.bw_write_max = pp(di.bw_write_max)
301 hdi.bw_read_max = pp(di.bw_read_max)
302
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300303 hdi.rws4k_10ms = di.rws4k_10ms if 0 != di.rws4k_10ms else None
304 hdi.rws4k_30ms = di.rws4k_30ms if 0 != di.rws4k_30ms else None
305 hdi.rws4k_100ms = di.rws4k_100ms if 0 != di.rws4k_100ms else None
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300306 return hdi
307
308
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300309@report('HDD', 'hdd_test_rrd4k,hdd_test_rws4k')
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300310def make_hdd_report(processed_results, path, lab_info):
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300311 make_hdd_plots(processed_results, path)
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300312 di = get_disk_info(processed_results)
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300313 render_hdd_html(path, di, lab_info)
314
315
316@report('Ceph', 'ceph_test')
317def make_ceph_report(processed_results, path, lab_info):
318 make_ceph_plots(processed_results, path)
319 di = get_disk_info(processed_results)
320 render_ceph_html(path, di, lab_info)
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300321
322
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300323def make_io_report(results, path, lab_url=None, creds=None):
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300324 lab_info = None
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300325
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300326 # if lab_url is not None:
327 # username, password, tenant_name = parse_creds(creds)
328 # creds = {'username': username,
329 # 'password': password,
330 # "tenant_name": tenant_name}
331 # try:
332 # data = collect_lab_data(lab_url, creds)
333 # lab_info = total_lab_info(data)
334 # except Exception as exc:
335 # logger.warning("Can't collect lab data: {0!s}".format(exc))
336
337 if lab_info is None:
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300338 lab_info = {
339 "total_disk": "None",
340 "total_memory": "None",
341 "nodes_count": "None",
342 "processor_count": "None"
343 }
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300344
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300345 try:
346 processed_results = process_disk_info(results)
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300347 res_fields = sorted(processed_results.keys())
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300348 for fields, name, func in report_funcs:
koder aka kdanilovafd98742015-04-24 01:27:22 +0300349 for field in fields:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300350 pos = bisect.bisect_left(res_fields, field)
351
352 if pos == len(res_fields):
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300353 break
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300354
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300355 if not res_fields[pos].startswith(field):
koder aka kdanilovafd98742015-04-24 01:27:22 +0300356 break
357 else:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300358 hpath = path.format(name)
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300359 logger.debug("Generatins report " + name + " into " + hpath)
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300360 func(processed_results, hpath, lab_info)
koder aka kdanilovafd98742015-04-24 01:27:22 +0300361 break
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300362 else:
363 logger.warning("No report generator found for this load")
koder aka kdanilovafd98742015-04-24 01:27:22 +0300364
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300365 except Exception as exc:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300366 import traceback
367 traceback.print_exc()
koder aka kdanilovec1b9732015-04-23 20:43:29 +0300368 logger.error("Failed to generate html report:" + str(exc))