blob: 16c487d184157103fbdc120572bdd14cc8246afb [file] [log] [blame]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03001import os
koder aka kdanilov88407ff2015-05-26 15:35:57 +03002import csv
koder aka kdanilov4a510ee2015-04-21 18:50:42 +03003import bisect
koder aka kdanilova047e1b2015-04-21 23:16:59 +03004import logging
koder aka kdanilov88407ff2015-05-26 15:35:57 +03005import itertools
koder aka kdanilov416b87a2015-05-12 00:26:04 +03006import collections
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +03007from cStringIO import StringIO
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03008
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +03009try:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030010 import numpy
11 import scipy
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030012 import matplotlib.pyplot as plt
13except ImportError:
14 plt = None
15
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030016import wally
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030017from wally.utils import ssize2b
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030018from wally.statistic import round_3_digit
koder aka kdanilov88407ff2015-05-26 15:35:57 +030019from wally.suits.io.fio_task_parser import (get_test_sync_mode,
20 get_test_summary,
21 parse_all_in_1,
22 abbv_name_to_full)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030023
koder aka kdanilov4a510ee2015-04-21 18:50:42 +030024
koder aka kdanilova047e1b2015-04-21 23:16:59 +030025logger = logging.getLogger("wally.report")
26
27
koder aka kdanilov209e85d2015-04-27 23:11:05 +030028class DiskInfo(object):
29 def __init__(self):
30 self.direct_iops_r_max = 0
31 self.direct_iops_w_max = 0
koder aka kdanilov88407ff2015-05-26 15:35:57 +030032
33 # 64 used instead of 4k to faster feed caches
34 self.direct_iops_w64_max = 0
35
koder aka kdanilov209e85d2015-04-27 23:11:05 +030036 self.rws4k_10ms = 0
37 self.rws4k_30ms = 0
38 self.rws4k_100ms = 0
39 self.bw_write_max = 0
40 self.bw_read_max = 0
41
42
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030043report_funcs = []
44
45
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030046class Attrmapper(object):
47 def __init__(self, dct):
48 self.__dct = dct
49
50 def __getattr__(self, name):
51 try:
52 return self.__dct[name]
53 except KeyError:
54 raise AttributeError(name)
55
56
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030057class PerfInfo(object):
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030058 def __init__(self, name, summary, intervals, params, testnodes_count):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030059 self.name = name
60 self.bw = None
61 self.iops = None
62 self.lat = None
koder aka kdanilov88407ff2015-05-26 15:35:57 +030063 self.lat_50 = None
64 self.lat_95 = None
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030065
66 self.raw_bw = []
67 self.raw_iops = []
68 self.raw_lat = []
69
koder aka kdanilov416b87a2015-05-12 00:26:04 +030070 self.params = params
71 self.intervals = intervals
72 self.testnodes_count = testnodes_count
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030073 self.summary = summary
74 self.p = Attrmapper(self.params.vals)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030075
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030076 self.sync_mode = get_test_sync_mode(self.params)
77 self.concurence = self.params.vals.get('numjobs', 1)
koder aka kdanilovf86d7af2015-05-06 04:01:54 +030078
79
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +030080# disk_info = None
81# base = None
82# linearity = None
83
84
koder aka kdanilov416b87a2015-05-12 00:26:04 +030085def group_by_name(test_data):
86 name_map = collections.defaultdict(lambda: [])
87
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +030088 for data in test_data:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030089 name_map[(data.name, data.summary())].append(data)
koder aka kdanilov416b87a2015-05-12 00:26:04 +030090
91 return name_map
92
93
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +030094def report(name, required_fields):
95 def closure(func):
96 report_funcs.append((required_fields.split(","), name, func))
97 return func
98 return closure
99
100
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300101def get_test_lcheck_params(pinfo):
102 res = [{
103 's': 'sync',
104 'd': 'direct',
105 'a': 'async',
106 'x': 'sync direct'
107 }[pinfo.sync_mode]]
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300108
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300109 res.append(pinfo.p.rw)
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300110
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300111 return " ".join(res)
koder aka kdanilov63e9c5a2015-04-28 23:06:07 +0300112
113
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300114def get_emb_data_svg(plt):
115 sio = StringIO()
116 plt.savefig(sio, format='svg')
117 img_start = "<!-- Created with matplotlib (http://matplotlib.org/) -->"
118 return sio.getvalue().split(img_start, 1)[1]
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300119
120
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300121def get_template(templ_name):
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300122 very_root_dir = os.path.dirname(os.path.dirname(wally.__file__))
123 templ_dir = os.path.join(very_root_dir, 'report_templates')
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300124 templ_file = os.path.join(templ_dir, templ_name)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300125 return open(templ_file, 'r').read()
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300126
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300127
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300128def group_by(data, func):
129 if len(data) < 2:
130 yield data
131 return
132
133 ndata = [(func(dt), dt) for dt in data]
134 ndata.sort(key=func)
135 pkey, dt = ndata[0]
136 curr_list = [dt]
137
138 for key, val in ndata[1:]:
139 if pkey != key:
140 yield curr_list
141 curr_list = [val]
142 else:
143 curr_list.append(val)
144 pkey = key
145
146 yield curr_list
147
148
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300149@report('linearity', 'linearity_test')
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300150def linearity_report(processed_results, lab_info, comment):
151 labels_and_data_mp = collections.defaultdict(lambda: [])
152 vls = {}
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300153
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300154 # plot io_time = func(bsize)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300155 for res in processed_results.values():
156 if res.name.startswith('linearity_test'):
157 iotimes = [1000. / val for val in res.iops.raw]
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300158
159 op_summ = get_test_summary(res.params)[:3]
160
161 labels_and_data_mp[op_summ].append(
162 [res.p.blocksize, res.iops.raw, iotimes])
163
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300164 cvls = res.params.vals.copy()
165 del cvls['blocksize']
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300166 del cvls['rw']
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300167
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300168 cvls.pop('sync', None)
169 cvls.pop('direct', None)
170 cvls.pop('buffered', None)
171
172 if op_summ not in vls:
173 vls[op_summ] = cvls
174 else:
175 assert cvls == vls[op_summ]
176
177 all_labels = None
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300178 _, ax1 = plt.subplots()
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300179 for name, labels_and_data in labels_and_data_mp.items():
180 labels_and_data.sort(key=lambda x: ssize2b(x[0]))
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300181
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300182 labels, _, iotimes = zip(*labels_and_data)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300183
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300184 if all_labels is None:
185 all_labels = labels
186 else:
187 assert all_labels == labels
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300188
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300189 plt.boxplot(iotimes)
190 if len(labels_and_data) > 2 and \
191 ssize2b(labels_and_data[-2][0]) >= 4096:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300192
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300193 xt = range(1, len(labels) + 1)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300194
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300195 def io_time(sz, bw, initial_lat):
196 return sz / bw + initial_lat
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300197
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300198 x = numpy.array(map(ssize2b, labels))
199 y = numpy.array([sum(dt) / len(dt) for dt in iotimes])
200 popt, _ = scipy.optimize.curve_fit(io_time, x, y, p0=(100., 1.))
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300201
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300202 y1 = io_time(x, *popt)
203 plt.plot(xt, y1, linestyle='--',
204 label=name + ' LS linear approx')
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300205
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300206 for idx, (sz, _, _) in enumerate(labels_and_data):
207 if ssize2b(sz) >= 4096:
208 break
209
210 bw = (x[-1] - x[idx]) / (y[-1] - y[idx])
211 lat = y[-1] - x[-1] / bw
212 y2 = io_time(x, bw, lat)
213 plt.plot(xt, y2, linestyle='--',
214 label=abbv_name_to_full(name) +
215 ' (4k & max) linear approx')
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300216
217 plt.setp(ax1, xticklabels=labels)
218
219 plt.xlabel("Block size")
220 plt.ylabel("IO time, ms")
221
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300222 plt.subplots_adjust(top=0.85)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300223 plt.legend(bbox_to_anchor=(0.5, 1.15),
224 loc='upper center',
225 prop={'size': 10}, ncol=2)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300226 plt.grid()
227 iotime_plot = get_emb_data_svg(plt)
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300228 plt.clf()
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300229
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300230 # plot IOPS = func(bsize)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300231 _, ax1 = plt.subplots()
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300232
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300233 for name, labels_and_data in labels_and_data_mp.items():
234 labels_and_data.sort(key=lambda x: ssize2b(x[0]))
235 _, data, _ = zip(*labels_and_data)
236 plt.boxplot(data)
237 avg = [float(sum(arr)) / len(arr) for arr in data]
238 xt = range(1, len(data) + 1)
239 plt.plot(xt, avg, linestyle='--',
240 label=abbv_name_to_full(name) + " avg")
241
242 plt.setp(ax1, xticklabels=labels)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300243 plt.xlabel("Block size")
244 plt.ylabel("IOPS")
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300245 plt.legend(bbox_to_anchor=(0.5, 1.15),
246 loc='upper center',
247 prop={'size': 10}, ncol=2)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300248 plt.grid()
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300249 plt.subplots_adjust(top=0.85)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300250
251 iops_plot = get_emb_data_svg(plt)
252
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300253 res = set(get_test_lcheck_params(res) for res in processed_results.values())
254 ncount = list(set(res.testnodes_count for res in processed_results.values()))
255 conc = list(set(res.concurence for res in processed_results.values()))
256
257 assert len(conc) == 1
258 assert len(ncount) == 1
259
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300260 descr = {
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300261 'vm_count': ncount[0],
262 'concurence': conc[0],
263 'oper_descr': ", ".join(res).capitalize()
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300264 }
265
266 params_map = {'iotime_vs_size': iotime_plot,
267 'iops_vs_size': iops_plot,
268 'descr': descr}
269
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300270 return get_template('report_linearity.html').format(**params_map)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300271
272
273@report('lat_vs_iops', 'lat_vs_iops')
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300274def lat_vs_iops(processed_results, lab_info, comment):
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300275 lat_iops = collections.defaultdict(lambda: [])
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300276 requsted_vs_real = collections.defaultdict(lambda: {})
277
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300278 for res in processed_results.values():
279 if res.name.startswith('lat_vs_iops'):
280 lat_iops[res.concurence].append((res.lat.average / 1000.0,
281 res.lat.deviation / 1000.0,
282 res.iops.average,
283 res.iops.deviation))
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300284 requested_iops = res.p.rate_iops * res.concurence
285 requsted_vs_real[res.concurence][requested_iops] = \
286 (res.iops.average, res.iops.deviation)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300287
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300288 colors = ['red', 'green', 'blue', 'orange', 'magenta', "teal"]
289 colors_it = iter(colors)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300290 for conc, lat_iops in sorted(lat_iops.items()):
291 lat, dev, iops, iops_dev = zip(*lat_iops)
292 plt.errorbar(iops, lat, xerr=iops_dev, yerr=dev, fmt='ro',
293 label=str(conc) + " threads",
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300294 color=next(colors_it))
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300295
296 plt.xlabel("IOPS")
297 plt.ylabel("Latency, ms")
298 plt.grid()
299 plt.legend(loc=0)
koder aka kdanilovfd2cfa52015-05-20 03:17:42 +0300300 plt_iops_vs_lat = get_emb_data_svg(plt)
301 plt.clf()
302
303 colors_it = iter(colors)
304 for conc, req_vs_real in sorted(requsted_vs_real.items()):
305 req, real = zip(*sorted(req_vs_real.items()))
306 iops, dev = zip(*real)
307 plt.errorbar(req, iops, yerr=dev, fmt='ro',
308 label=str(conc) + " threads",
309 color=next(colors_it))
310 plt.xlabel("Requested IOPS")
311 plt.ylabel("Get IOPS")
312 plt.grid()
313 plt.legend(loc=0)
314 plt_iops_vs_requested = get_emb_data_svg(plt)
315
316 res1 = processed_results.values()[0]
317 params_map = {'iops_vs_lat': plt_iops_vs_lat,
318 'iops_vs_requested': plt_iops_vs_requested,
319 'oper_descr': get_test_lcheck_params(res1).capitalize()}
320
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300321 return get_template('report_iops_vs_lat.html').format(**params_map)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300322
323
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300324def render_all_html(comment, info, lab_description, images, templ_name):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300325 data = info.__dict__.copy()
326 for name, val in data.items():
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300327 if not name.startswith('__'):
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300328 if val is None:
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300329 data[name] = '-'
330 elif isinstance(val, (int, float, long)):
331 data[name] = round_3_digit(val)
koder aka kdanilov209e85d2015-04-27 23:11:05 +0300332
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300333 data['bw_read_max'] = (data['bw_read_max'][0] // 1024,
334 data['bw_read_max'][1])
335 data['bw_write_max'] = (data['bw_write_max'][0] // 1024,
336 data['bw_write_max'][1])
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300337
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300338 images.update(data)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300339 return get_template(templ_name).format(lab_info=lab_description,
340 comment=comment,
341 **images)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300342
343
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300344def io_chart(title, concurence,
345 latv, latv_min, latv_max,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300346 iops_or_bw, iops_or_bw_err,
347 legend, log=False,
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300348 boxplots=False,
349 latv_50=None, latv_95=None):
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300350 points = " MiBps" if legend == 'BW' else ""
351 lc = len(concurence)
352 width = 0.35
353 xt = range(1, lc + 1)
354
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300355 op_per_vm = [v / (vm * th) for v, (vm, th) in zip(iops_or_bw, concurence)]
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300356 fig, p1 = plt.subplots()
357 xpos = [i - width / 2 for i in xt]
358
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300359 p1.bar(xpos, iops_or_bw,
360 width=width,
361 yerr=iops_or_bw_err,
362 ecolor='m',
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300363 color='y',
364 label=legend)
365
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300366 p1.grid(True)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300367 p1.plot(xt, op_per_vm, '--', label=legend + "/thread", color='black')
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300368 handles1, labels1 = p1.get_legend_handles_labels()
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300369
370 p2 = p1.twinx()
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300371
372 if latv_50 is None:
373 p2.plot(xt, latv_max, label="lat max")
374 p2.plot(xt, latv, label="lat avg")
375 p2.plot(xt, latv_min, label="lat min")
376 else:
377 p2.plot(xt, latv_50, label="lat med")
378 p2.plot(xt, latv_95, label="lat 95%")
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300379
380 plt.xlim(0.5, lc + 0.5)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300381 plt.xticks(xt, ["{0} * {1}".format(vm, th) for (vm, th) in concurence])
382 p1.set_xlabel("VM Count * Thread per VM")
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300383 p1.set_ylabel(legend + points)
384 p2.set_ylabel("Latency ms")
385 plt.title(title)
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300386 handles2, labels2 = p2.get_legend_handles_labels()
387
388 plt.legend(handles1 + handles2, labels1 + labels2,
389 loc='center left', bbox_to_anchor=(1.1, 0.81))
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300390
391 if log:
392 p1.set_yscale('log')
393 p2.set_yscale('log')
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300394 plt.subplots_adjust(right=0.68)
395
396 return get_emb_data_svg(plt)
koder aka kdanilovd5ed4da2015-05-07 23:33:23 +0300397
398
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300399def make_plots(processed_results, plots):
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300400 """
401 processed_results: [PerfInfo]
402 plots = [(test_name_prefix:str, fname:str, description:str)]
403 """
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300404 files = {}
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300405 for name_pref, fname, desc in plots:
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300406 chart_data = []
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300407
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300408 for res in processed_results:
409 summ = res.name + "_" + res.summary
410 if summ.startswith(name_pref):
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300411 chart_data.append(res)
412
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300413 if len(chart_data) == 0:
414 raise ValueError("Can't found any date for " + name_pref)
415
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300416 use_bw = ssize2b(chart_data[0].p.blocksize) > 16 * 1024
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300417
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300418 chart_data.sort(key=lambda x: x.params['vals']['numjobs'])
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300419
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300420 lat = None
421 lat_min = None
422 lat_max = None
423 lat_50 = [x.lat_50 for x in chart_data]
424 lat_95 = [x.lat_95 for x in chart_data]
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300425
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300426 testnodes_count = x.testnodes_count
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300427 concurence = [(testnodes_count, x.concurence)
koder aka kdanilov416b87a2015-05-12 00:26:04 +0300428 for x in chart_data]
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300429
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300430 if use_bw:
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300431 data = [x.bw.average / 1000 for x in chart_data]
432 data_dev = [x.bw.confidence / 1000 for x in chart_data]
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300433 name = "BW"
434 else:
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300435 data = [x.iops.average for x in chart_data]
436 data_dev = [x.iops.confidence for x in chart_data]
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300437 name = "IOPS"
438
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300439 fc = io_chart(title=desc,
440 concurence=concurence,
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300441
442 latv=lat,
443 latv_min=lat_min,
444 latv_max=lat_max,
445
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300446 iops_or_bw=data,
447 iops_or_bw_err=data_dev,
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300448
449 legend=name,
450
451 latv_50=lat_50,
452 latv_95=lat_95)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300453 files[fname] = fc
454
455 return files
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300456
457
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300458def find_max_where(processed_results, sync_mode, blocksize, rw, iops=True):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300459 result = None
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300460 attr = 'iops' if iops else 'bw'
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300461 for measurement in processed_results:
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300462 ok = measurement.sync_mode == sync_mode
463 ok = ok and (measurement.p.blocksize == blocksize)
464 ok = ok and (measurement.p.rw == rw)
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300465
466 if ok:
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300467 field = getattr(measurement, attr)
468
469 if result is None:
470 result = field
471 elif field.average > result.average:
472 result = field
473
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300474 return result
475
476
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300477def get_disk_info(processed_results):
478 di = DiskInfo()
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300479 di.direct_iops_w_max = find_max_where(processed_results,
480 'd', '4k', 'randwrite')
481 di.direct_iops_r_max = find_max_where(processed_results,
482 'd', '4k', 'randread')
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300483
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300484 di.direct_iops_w64_max = find_max_where(processed_results,
485 'd', '64k', 'randwrite')
486
487 for sz in ('16m', '64m'):
488 di.bw_write_max = find_max_where(processed_results,
489 'd', sz, 'randwrite', False)
490 if di.bw_write_max is not None:
491 break
492
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300493 if di.bw_write_max is None:
494 di.bw_write_max = find_max_where(processed_results,
495 'd', '1m', 'write', False)
496
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300497 for sz in ('16m', '64m'):
498 di.bw_read_max = find_max_where(processed_results,
499 'd', sz, 'randread', False)
500 if di.bw_read_max is not None:
501 break
502
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300503 if di.bw_read_max is None:
504 di.bw_read_max = find_max_where(processed_results,
505 'd', '1m', 'read', False)
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300506
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300507 rws4k_iops_lat_th = []
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300508 for res in processed_results:
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300509 if res.sync_mode in 'xs' and res.p.blocksize == '4k':
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300510 if res.p.rw != 'randwrite':
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300511 continue
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300512 rws4k_iops_lat_th.append((res.iops.average,
513 res.lat.average,
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300514 res.concurence))
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300515
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300516 rws4k_iops_lat_th.sort(key=lambda (_1, _2, conc): conc)
517
518 latv = [lat for _, lat, _ in rws4k_iops_lat_th]
519
520 for tlatv_ms in [10, 30, 100]:
521 tlat = tlatv_ms * 1000
522 pos = bisect.bisect_left(latv, tlat)
523 if 0 == pos:
koder aka kdanilovbb5fe072015-05-21 02:50:23 +0300524 setattr(di, 'rws4k_{}ms'.format(tlatv_ms), 0)
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300525 elif pos == len(latv):
koder aka kdanilovbb5fe072015-05-21 02:50:23 +0300526 iops3, _, _ = rws4k_iops_lat_th[-1]
527 setattr(di, 'rws4k_{}ms'.format(tlatv_ms), ">=" + str(iops3))
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300528 else:
529 lat1 = latv[pos - 1]
530 lat2 = latv[pos]
531
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300532 iops1, _, th1 = rws4k_iops_lat_th[pos - 1]
533 iops2, _, th2 = rws4k_iops_lat_th[pos]
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300534
535 th_lat_coef = (th2 - th1) / (lat2 - lat1)
536 th3 = th_lat_coef * (tlat - lat1) + th1
537
538 th_iops_coef = (iops2 - iops1) / (th2 - th1)
539 iops3 = th_iops_coef * (th3 - th1) + iops1
koder aka kdanilovbb5fe072015-05-21 02:50:23 +0300540 setattr(di, 'rws4k_{}ms'.format(tlatv_ms), int(iops3))
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300541
542 hdi = DiskInfo()
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300543
544 def pp(x):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300545 med, conf = x.rounded_average_conf()
546 conf_perc = int(float(conf) / med * 100)
547 return (med, conf_perc)
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300548
549 hdi.direct_iops_r_max = pp(di.direct_iops_r_max)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300550
551 if di.direct_iops_w_max is not None:
552 hdi.direct_iops_w_max = pp(di.direct_iops_w_max)
553 else:
554 hdi.direct_iops_w_max = None
555
556 if di.direct_iops_w64_max is not None:
557 hdi.direct_iops_w64_max = pp(di.direct_iops_w64_max)
558 else:
559 hdi.direct_iops_w64_max = None
560
koder aka kdanilov7e0f7cf2015-05-01 17:24:35 +0300561 hdi.bw_write_max = pp(di.bw_write_max)
562 hdi.bw_read_max = pp(di.bw_read_max)
563
koder aka kdanilovc368eb62015-04-28 18:22:01 +0300564 hdi.rws4k_10ms = di.rws4k_10ms if 0 != di.rws4k_10ms else None
565 hdi.rws4k_30ms = di.rws4k_30ms if 0 != di.rws4k_30ms else None
566 hdi.rws4k_100ms = di.rws4k_100ms if 0 != di.rws4k_100ms else None
koder aka kdanilov4a510ee2015-04-21 18:50:42 +0300567 return hdi
568
569
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300570@report('hdd', 'hdd')
571def make_hdd_report(processed_results, lab_info, comment):
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300572 plots = [
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300573 ('hdd_rrd4k', 'rand_read_4k', 'Random read 4k direct IOPS'),
574 ('hdd_rwx4k', 'rand_write_4k', 'Random write 4k sync IOPS')
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300575 ]
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300576 perf_infos = [res.disk_perf_info() for res in processed_results]
577 images = make_plots(perf_infos, plots)
578 di = get_disk_info(perf_infos)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300579 return render_all_html(comment, di, lab_info, images, "report_hdd.html")
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300580
581
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300582@report('cinder_iscsi', 'cinder_iscsi')
583def make_cinder_iscsi_report(processed_results, lab_info, comment):
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300584 plots = [
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300585 ('cinder_iscsi_rrd4k', 'rand_read_4k', 'Random read 4k direct IOPS'),
586 ('cinder_iscsi_rwx4k', 'rand_write_4k', 'Random write 4k sync IOPS')
587 ]
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300588 perf_infos = [res.disk_perf_info() for res in processed_results]
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300589 try:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300590 images = make_plots(perf_infos, plots)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300591 except ValueError:
592 plots = [
593 ('cinder_iscsi_rrd4k', 'rand_read_4k', 'Random read 4k direct IOPS'),
594 ('cinder_iscsi_rws4k', 'rand_write_4k', 'Random write 4k sync IOPS')
595 ]
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300596 images = make_plots(perf_infos, plots)
597 di = get_disk_info(perf_infos)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300598 return render_all_html(comment, di, lab_info, images, "report_cinder_iscsi.html")
599
600
601@report('ceph', 'ceph')
602def make_ceph_report(processed_results, lab_info, comment):
603 plots = [
604 ('ceph_rrd4k', 'rand_read_4k', 'Random read 4k direct IOPS'),
605 ('ceph_rws4k', 'rand_write_4k', 'Random write 4k sync IOPS'),
606 ('ceph_rrd16m', 'rand_read_16m', 'Random read 16m direct MiBps'),
607 ('ceph_rwd16m', 'rand_write_16m',
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300608 'Random write 16m direct MiBps'),
609 ]
610
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300611 perf_infos = [res.disk_perf_info() for res in processed_results]
612 images = make_plots(perf_infos, plots)
613 di = get_disk_info(perf_infos)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300614 return render_all_html(comment, di, lab_info, images, "report_ceph.html")
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300615
616
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300617@report('mixed', 'mixed')
618def make_mixed_report(processed_results, lab_info, comment):
619 #
620 # IOPS(X% read) = 100 / ( X / IOPS_W + (100 - X) / IOPS_R )
621 #
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300622
623 perf_infos = [res.disk_perf_info() for res in processed_results]
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300624 mixed = collections.defaultdict(lambda: [])
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300625
626 is_ssd = False
627 for res in perf_infos:
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300628 if res.name.startswith('mixed'):
629 if res.name.startswith('mixed-ssd'):
630 is_ssd = True
631 mixed[res.concurence].append((res.p.rwmixread,
632 res.lat.average / 1000.0,
633 res.lat.deviation / 1000.0,
634 res.iops.average,
635 res.iops.deviation))
636
637 if len(mixed) == 0:
638 raise ValueError("No mixed load found")
639
640 fig, p1 = plt.subplots()
641 p2 = p1.twinx()
642
643 colors = ['red', 'green', 'blue', 'orange', 'magenta', "teal"]
644 colors_it = iter(colors)
645 for conc, mix_lat_iops in sorted(mixed.items()):
646 mix_lat_iops = sorted(mix_lat_iops)
647 read_perc, lat, dev, iops, iops_dev = zip(*mix_lat_iops)
648 p1.errorbar(read_perc, iops, color=next(colors_it),
649 yerr=iops_dev, label=str(conc) + " th")
650
651 p2.errorbar(read_perc, lat, color=next(colors_it),
652 ls='--', yerr=dev, label=str(conc) + " th lat")
653
654 if is_ssd:
655 p1.set_yscale('log')
656 p2.set_yscale('log')
657
658 p1.set_xlim(-5, 105)
659
660 read_perc = set(read_perc)
661 read_perc.add(0)
662 read_perc.add(100)
663 read_perc = sorted(read_perc)
664
665 plt.xticks(read_perc, map(str, read_perc))
666
667 p1.grid(True)
668 p1.set_xlabel("% of reads")
669 p1.set_ylabel("Mixed IOPS")
670 p2.set_ylabel("Latency, ms")
671
672 handles1, labels1 = p1.get_legend_handles_labels()
673 handles2, labels2 = p2.get_legend_handles_labels()
674 plt.subplots_adjust(top=0.85)
675 plt.legend(handles1 + handles2, labels1 + labels2,
676 bbox_to_anchor=(0.5, 1.15),
677 loc='upper center',
678 prop={'size': 12}, ncol=3)
679 plt.show()
680
681
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300682def make_load_report(idx, results_dir, fname):
683 dpath = os.path.join(results_dir, "io_" + str(idx))
684 files = sorted(os.listdir(dpath))
685 gf = lambda x: "_".join(x.rsplit(".", 1)[0].split('_')[:3])
686
687 for key, group in itertools.groupby(files, gf):
688 fname = os.path.join(dpath, key + ".fio")
689
690 cfgs = list(parse_all_in_1(open(fname).read(), fname))
691
692 fname = os.path.join(dpath, key + "_lat.log")
693
694 curr = []
695 arrays = []
696
697 with open(fname) as fd:
698 for offset, lat, _, _ in csv.reader(fd):
699 offset = int(offset)
700 lat = int(lat)
701 if len(curr) > 0 and curr[-1][0] > offset:
702 arrays.append(curr)
703 curr = []
704 curr.append((offset, lat))
705 arrays.append(curr)
706 conc = int(cfgs[0].vals.get('numjobs', 1))
707
708 if conc != 5:
709 continue
710
711 assert len(arrays) == len(cfgs) * conc
712
713 garrays = [[(0, 0)] for _ in range(conc)]
714
715 for offset in range(len(cfgs)):
716 for acc, new_arr in zip(garrays, arrays[offset * conc:(offset + 1) * conc]):
717 last = acc[-1][0]
718 for off, lat in new_arr:
719 acc.append((off / 1000. + last, lat / 1000.))
720
721 for cfg, arr in zip(cfgs, garrays):
722 plt.plot(*zip(*arr[1:]))
723 plt.show()
724 exit(1)
725
726
727def make_io_report(dinfo, comment, path, lab_info=None):
koder aka kdanilovf86d7af2015-05-06 04:01:54 +0300728 lab_info = {
729 "total_disk": "None",
730 "total_memory": "None",
731 "nodes_count": "None",
732 "processor_count": "None"
733 }
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300734
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300735 try:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300736 res_fields = sorted(v.name for v in dinfo)
koder aka kdanilov4af1c1d2015-05-18 15:48:58 +0300737
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300738 found = False
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300739 for fields, name, func in report_funcs:
koder aka kdanilovafd98742015-04-24 01:27:22 +0300740 for field in fields:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300741 pos = bisect.bisect_left(res_fields, field)
742
743 if pos == len(res_fields):
koder aka kdanilov63ad2062015-04-27 13:11:40 +0300744 break
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300745
koder aka kdanilovbe8f89f2015-04-28 14:51:51 +0300746 if not res_fields[pos].startswith(field):
koder aka kdanilovafd98742015-04-24 01:27:22 +0300747 break
748 else:
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300749 found = True
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300750 hpath = path.format(name)
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300751
752 try:
753 report = func(dinfo, lab_info, comment)
754 except:
755 logger.exception("Diring {0} report generation".format(name))
756 continue
757
koder aka kdanilov7248c7b2015-05-31 22:53:03 +0300758 if report is not None:
759 try:
760 with open(hpath, "w") as fd:
761 fd.write(report)
762 except:
763 logger.exception("Diring saving {0} report".format(name))
764 continue
765 logger.info("Report {0} saved into {1}".format(name, hpath))
766 else:
767 logger.warning("No report produced by {0!r}".format(name))
koder aka kdanilov88407ff2015-05-26 15:35:57 +0300768
769 if not found:
koder aka kdanilova4a570f2015-04-23 22:11:40 +0300770 logger.warning("No report generator found for this load")
koder aka kdanilovafd98742015-04-24 01:27:22 +0300771
koder aka kdanilova047e1b2015-04-21 23:16:59 +0300772 except Exception as exc:
koder aka kdanilov57ce4db2015-04-25 21:25:51 +0300773 import traceback
774 traceback.print_exc()
koder aka kdanilovec1b9732015-04-23 20:43:29 +0300775 logger.error("Failed to generate html report:" + str(exc))