blob: 5b4c8581afdf1196472bc3a5c2a5de8e66c273a2 [file] [log] [blame]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03001import os
koder aka kdanilov4a510ee2015-04-21 18:50:42 +03002import bisect
koder aka kdanilova047e1b2015-04-21 23:16:59 +03003import logging
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03004
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +03005try:
6 import matplotlib.pyplot as plt
7except ImportError:
8 plt = None
9
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030010import wally
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030011from wally import charts
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030012from wally.utils import ssize2b
13from wally.statistic import round_3_digit, data_property
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030014
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030015
koder aka kdanilova047e1b2015-04-21 23:16:59 +030016logger = logging.getLogger("wally.report")
17
18
koder aka kdanilov209e85d2015-04-27 23:11:05 +030019class DiskInfo(object):
20 def __init__(self):
21 self.direct_iops_r_max = 0
22 self.direct_iops_w_max = 0
23 self.rws4k_10ms = 0
24 self.rws4k_30ms = 0
25 self.rws4k_100ms = 0
26 self.bw_write_max = 0
27 self.bw_read_max = 0
28
29
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030030report_funcs = []
31
32
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030033class PerfInfo(object):
34 def __init__(self, name, raw, meta):
35 self.name = name
36 self.bw = None
37 self.iops = None
38 self.lat = None
39 self.raw = raw
40 self.meta = meta
41
42
43def split_and_add(data, block_size):
44 assert len(data) % block_size == 0
45 res = [0] * block_size
46
47 for idx, val in enumerate(data):
48 res[idx % block_size] += val
49
50 return res
51
52
53def process_disk_info(test_data):
54 data = {}
55 vm_count = test_data['__test_meta__']['testnodes_count']
56 for name, results in test_data['res'].items():
57 assert len(results['bw']) % vm_count == 0
58 block_count = len(results['bw']) // vm_count
59
60 pinfo = PerfInfo(name, results, test_data['__test_meta__'])
61 pinfo.bw = data_property(split_and_add(results['bw'], block_count))
62 pinfo.iops = data_property(split_and_add(results['iops'],
63 block_count))
64
65 pinfo.lat = data_property(results['lat'])
66 data[name] = pinfo
67 return data
68
69
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030070def report(name, required_fields):
71 def closure(func):
72 report_funcs.append((required_fields.split(","), name, func))
73 return func
74 return closure
75
76
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030077def linearity_report(processed_results, path, lab_info):
78 names = {}
79 for tp1 in ('rand', 'seq'):
80 for oper in ('read', 'write'):
81 for sync in ('sync', 'direct', 'async'):
82 sq = (tp1, oper, sync)
83 name = "{0} {1} {2}".format(*sq)
84 names["".join(word[0] for word in sq)] = name
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030085
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030086 colors = ['red', 'green', 'blue', 'cyan',
87 'magenta', 'black', 'yellow', 'burlywood']
88 markers = ['*', '^', 'x', 'o', '+', '.']
89 color = 0
90 marker = 0
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030091
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030092 plot_data = {}
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030093
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030094 name_pref = 'linearity_test_rrd'
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030095
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +030096 for res in processed_results.values():
97 if res.name.startswith(name_pref):
98 iotime = 1000000. / res.iops
99 iotime_max = iotime * (1 + res.dev * 3)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300100 bsize = ssize2b(res.raw['blocksize'])
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300101 plot_data[bsize] = (iotime, iotime_max)
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300102
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300103 min_sz = min(plot_data)
104 min_iotime, _ = plot_data.pop(min_sz)
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300105
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300106 x = []
107 y = []
108 e = []
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300109
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300110 for k, (v, vmax) in sorted(plot_data.items()):
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300111 y.append(v - min_iotime)
112 x.append(k)
113 e.append(y[-1] - (vmax - min_iotime))
114
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300115 tp = 'rrd'
116 plt.errorbar(x, y, e, linestyle='None', label=names[tp],
117 color=colors[color], ecolor="black",
118 marker=markers[marker])
119 plt.yscale('log')
120 plt.xscale('log')
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300121 # plt.show()
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300122
123 # ynew = approximate_line(ax, ay, ax, True)
124 # plt.plot(ax, ynew, color=colors[color])
125 # color += 1
126 # marker += 1
127 # plt.legend(loc=2)
128 # plt.title("Linearity test by %i dots" % (len(vals)))
129
130
131if plt:
132 linearity_report = report('linearity', 'linearity_test')(linearity_report)
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300133
134
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300135def render_all_html(dest, info, lab_description, templ_name):
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300136 very_root_dir = os.path.dirname(os.path.dirname(wally.__file__))
137 templ_dir = os.path.join(very_root_dir, 'report_templates')
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300138 templ_file = os.path.join(templ_dir, templ_name)
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300139 templ = open(templ_file, 'r').read()
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300140
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300141 data = info.__dict__.copy()
142 for name, val in data.items():
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300143 if not name.startswith('__'):
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300144 if val is None:
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300145 data[name] = '-'
146 elif isinstance(val, (int, float, long)):
147 data[name] = round_3_digit(val)
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300148
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300149 data['bw_read_max'] = (data['bw_read_max'][0] // 1024,
150 data['bw_read_max'][1])
151 data['bw_write_max'] = (data['bw_write_max'][0] // 1024,
152 data['bw_write_max'][1])
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300153
154 report = templ.format(lab_info=lab_description, **data)
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300155 open(dest, 'w').write(report)
156
157
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300158def render_hdd_html(dest, info, lab_description):
159 render_all_html(dest, info, lab_description, "report_hdd.html")
160
161
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300162def render_ceph_html(dest, info, lab_description):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300163 render_all_html(dest, info, lab_description, "report_ceph.html")
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300164
165
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300166def io_chart(title, concurence,
167 latv, latv_min, latv_max,
168 iops_or_bw, iops_or_bw_dev,
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300169 legend, fname):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300170 bar_data = iops_or_bw
171 bar_dev = iops_or_bw_dev
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300172 legend = [legend]
173
174 iops_or_bw_per_vm = []
175 for i in range(len(concurence)):
176 iops_or_bw_per_vm.append(iops_or_bw[i] / concurence[i])
177
178 bar_dev_bottom = []
179 bar_dev_top = []
180 for i in range(len(bar_data)):
181 bar_dev_top.append(bar_data[i] + bar_dev[i])
182 bar_dev_bottom.append(bar_data[i] - bar_dev[i])
183
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300184 ch = charts.render_vertical_bar(title, legend, [bar_data], [bar_dev_top],
185 [bar_dev_bottom], file_name=fname,
Yulia Portnova0d1b45f2015-04-28 16:51:11 +0300186 scale_x=concurence, label_x="clients",
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300187 label_y=legend[0],
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300188 lines=[
189 (latv, "msec", "rr", "lat"),
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300190 # (latv_min, None, None, "lat_min"),
191 # (latv_max, None, None, "lat_max"),
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300192 (iops_or_bw_per_vm, None, None,
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300193 legend[0] + " per client")
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300194 ])
195 return str(ch)
196
197
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300198def make_hdd_plots(processed_results, path):
199 plots = [
200 ('hdd_test_rrd4k', 'rand_read_4k', 'Random read 4k direct IOPS'),
koder aka kdanilovea7eac72015-04-21 21:37:27 +0300201 ('hdd_test_rws4k', 'rand_write_4k', 'Random write 4k sync IOPS')
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300202 ]
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300203 make_plots(processed_results, path, plots)
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300204
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300205
206def make_ceph_plots(processed_results, path):
207 plots = [
208 ('ceph_test_rrd4k', 'rand_read_4k', 'Random read 4k direct IOPS'),
209 ('ceph_test_rws4k', 'rand_write_4k', 'Random write 4k sync IOPS'),
210 ('ceph_test_rrd16m', 'rand_read_16m', 'Random read 16m direct MiBps'),
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300211 ('ceph_test_rwd16m', 'rand_write_16m',
212 'Random write 16m direct MiBps'),
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300213 ]
214 make_plots(processed_results, path, plots)
215
216
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300217def make_plots(processed_results, path, plots, max_lat=400000):
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300218 for name_pref, fname, desc in plots:
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300219 chart_data = []
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300220
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300221 for res in processed_results.values():
222 if res.name.startswith(name_pref):
223 chart_data.append(res)
224
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300225 if len(chart_data) == 0:
226 raise ValueError("Can't found any date for " + name_pref)
227
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300228 use_bw = ssize2b(chart_data[0].raw['blocksize']) > 16 * 1024
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300229
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300230 chart_data.sort(key=lambda x: x.raw['concurence'])
231
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300232 # if x.lat.average < max_lat]
233 lat = [x.lat.average / 1000 for x in chart_data]
234
235 lat_min = [x.lat.min / 1000 for x in chart_data if x.lat.min < max_lat]
236 lat_max = [x.lat.max / 1000 for x in chart_data if x.lat.max < max_lat]
237
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300238 vm_count = x.meta['testnodes_count']
239 concurence = [x.raw['concurence'] * vm_count for x in chart_data]
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300240
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300241 if use_bw:
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300242 data = [x.bw.average / 1000 for x in chart_data]
243 data_dev = [x.bw.confidence / 1000 for x in chart_data]
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300244 name = "BW"
245 else:
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300246 data = [x.iops.average for x in chart_data]
247 data_dev = [x.iops.confidence for x in chart_data]
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300248 name = "IOPS"
249
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300250 io_chart(desc, concurence, lat, lat_min, lat_max,
251 data, data_dev, name, fname)
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300252
253
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300254def find_max_where(processed_results, sync_mode, blocksize, rw, iops=True):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300255 result = None
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300256 attr = 'iops' if iops else 'bw'
257 for measurement in processed_results.values():
258 ok = measurement.raw['sync_mode'] == sync_mode
259 ok = ok and (measurement.raw['blocksize'] == blocksize)
260 ok = ok and (measurement.raw['rw'] == rw)
261
262 if ok:
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300263 field = getattr(measurement, attr)
264
265 if result is None:
266 result = field
267 elif field.average > result.average:
268 result = field
269
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300270 return result
271
272
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300273def get_disk_info(processed_results):
274 di = DiskInfo()
275 rws4k_iops_lat_th = []
276
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300277 di.direct_iops_w_max = find_max_where(processed_results,
278 'd', '4k', 'randwrite')
279 di.direct_iops_r_max = find_max_where(processed_results,
280 'd', '4k', 'randread')
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300281
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300282 di.bw_write_max = find_max_where(processed_results,
283 'd', '16m', 'randwrite', False)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300284 if di.bw_write_max is None:
285 di.bw_write_max = find_max_where(processed_results,
286 'd', '1m', 'write', False)
287
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300288 di.bw_read_max = find_max_where(processed_results,
289 'd', '16m', 'randread', False)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300290 if di.bw_read_max is None:
291 di.bw_read_max = find_max_where(processed_results,
292 'd', '1m', 'read', False)
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300293
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300294 for res in processed_results.values():
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300295 if res.raw['sync_mode'] == 's' and res.raw['blocksize'] == '4k':
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300296 if res.raw['rw'] != 'randwrite':
297 continue
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300298 rws4k_iops_lat_th.append((res.iops.average,
299 res.lat.average,
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300300 res.raw['concurence']))
301
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300302 rws4k_iops_lat_th.sort(key=lambda (_1, _2, conc): conc)
303
304 latv = [lat for _, lat, _ in rws4k_iops_lat_th]
305
306 for tlatv_ms in [10, 30, 100]:
307 tlat = tlatv_ms * 1000
308 pos = bisect.bisect_left(latv, tlat)
309 if 0 == pos:
310 iops3 = 0
311 elif pos == len(latv):
312 iops3 = latv[-1]
313 else:
314 lat1 = latv[pos - 1]
315 lat2 = latv[pos]
316
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300317 iops1, _, th1 = rws4k_iops_lat_th[pos - 1]
318 iops2, _, th2 = rws4k_iops_lat_th[pos]
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300319
320 th_lat_coef = (th2 - th1) / (lat2 - lat1)
321 th3 = th_lat_coef * (tlat - lat1) + th1
322
323 th_iops_coef = (iops2 - iops1) / (th2 - th1)
324 iops3 = th_iops_coef * (th3 - th1) + iops1
325 setattr(di, 'rws4k_{}ms'.format(tlatv_ms), int(iops3))
326
327 hdi = DiskInfo()
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300328
329 def pp(x):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300330 med, conf = x.rounded_average_conf()
331 conf_perc = int(float(conf) / med * 100)
332 return (med, conf_perc)
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300333
334 hdi.direct_iops_r_max = pp(di.direct_iops_r_max)
335 hdi.direct_iops_w_max = pp(di.direct_iops_w_max)
336 hdi.bw_write_max = pp(di.bw_write_max)
337 hdi.bw_read_max = pp(di.bw_read_max)
338
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300339 hdi.rws4k_10ms = di.rws4k_10ms if 0 != di.rws4k_10ms else None
340 hdi.rws4k_30ms = di.rws4k_30ms if 0 != di.rws4k_30ms else None
341 hdi.rws4k_100ms = di.rws4k_100ms if 0 != di.rws4k_100ms else None
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300342 return hdi
343
344
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300345@report('HDD', 'hdd_test_rrd4k,hdd_test_rws4k')
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300346def make_hdd_report(processed_results, path, lab_info):
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300347 make_hdd_plots(processed_results, path)
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300348 di = get_disk_info(processed_results)
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300349 render_hdd_html(path, di, lab_info)
350
351
352@report('Ceph', 'ceph_test')
353def make_ceph_report(processed_results, path, lab_info):
354 make_ceph_plots(processed_results, path)
355 di = get_disk_info(processed_results)
356 render_ceph_html(path, di, lab_info)
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300357
358
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300359def make_io_report(dinfo, results, path, lab_info=None):
360 lab_info = {
361 "total_disk": "None",
362 "total_memory": "None",
363 "nodes_count": "None",
364 "processor_count": "None"
365 }
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300366
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300367 try:
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300368 res_fields = sorted(dinfo.keys())
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300369 for fields, name, func in report_funcs:
koder aka kdanilovafd98742015-04-24 01:27:22 +0300370 for field in fields:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300371 pos = bisect.bisect_left(res_fields, field)
372
373 if pos == len(res_fields):
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300374 break
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300375
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300376 if not res_fields[pos].startswith(field):
koder aka kdanilovafd98742015-04-24 01:27:22 +0300377 break
378 else:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300379 hpath = path.format(name)
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300380 logger.debug("Generatins report " + name + " into " + hpath)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300381 func(dinfo, hpath, lab_info)
koder aka kdanilovafd98742015-04-24 01:27:22 +0300382 break
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300383 else:
384 logger.warning("No report generator found for this load")
koder aka kdanilovafd98742015-04-24 01:27:22 +0300385
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300386 except Exception as exc:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300387 import traceback
388 traceback.print_exc()
koder aka kdanilovec1b9732015-04-23 20:43:29 +0300389 logger.error("Failed to generate html report:" + str(exc))