blob: 777ae5f96be72fa98637cdb88229c9f8990072f2 [file] [log] [blame]
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03001import re
2import time
3import json
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03004import stat
koder aka kdanilov6ab4d432015-06-22 00:26:28 +03005import random
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03006import os.path
7import logging
8import datetime
9import functools
10import subprocess
11import collections
12
13import yaml
14import paramiko
15import texttable
16from paramiko.ssh_exception import SSHException
17from concurrent.futures import ThreadPoolExecutor
18
koder aka kdanilov6ab4d432015-06-22 00:26:28 +030019import wally
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030020from wally.pretty_yaml import dumps
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030021from wally.statistic import round_3_digit, data_property, average
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030022from wally.utils import ssize2b, sec_to_str, StopTestError, Barrier, get_os
23from wally.ssh_utils import (save_to_remote, read_from_remote, BGSSHTask, reconnect)
24
25from .fio_task_parser import (execution_time, fio_cfg_compile,
koder aka kdanilovf236b9c2015-06-24 18:17:22 +030026 get_test_summary, get_test_summary_tuple,
27 get_test_sync_mode, FioJobSection)
28
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030029from ..itest import (TimeSeriesValue, PerfTest, TestResults,
30 run_on_node, TestConfig, MeasurementMatrix)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030031
32logger = logging.getLogger("wally")
33
34
35# Results folder structure
36# results/
37# {loadtype}_{num}/
38# config.yaml
39# ......
40
41
42class NoData(object):
43 pass
44
45
46def cached_prop(func):
47 @property
48 @functools.wraps(func)
49 def closure(self):
50 val = getattr(self, "_" + func.__name__)
51 if val is NoData:
52 val = func(self)
53 setattr(self, "_" + func.__name__, val)
54 return val
55 return closure
56
57
58def load_fio_log_file(fname):
59 with open(fname) as fd:
60 it = [ln.split(',')[:2] for ln in fd]
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030061
62 vals = [(float(off) / 1000, # convert us to ms
63 float(val.strip()) + 0.5) # add 0.5 to compemsate average value
64 # as fio trimm all values in log to integer
65 for off, val in it]
66
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030067 return TimeSeriesValue(vals)
68
69
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +030070def load_test_results(folder, run_num):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030071 res = {}
72 params = None
73
74 fn = os.path.join(folder, str(run_num) + '_params.yaml')
75 params = yaml.load(open(fn).read())
76
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030077 conn_ids_set = set()
78 rr = r"{0}_(?P<conn_id>.*?)_(?P<type>[^_.]*)\.\d+\.log$".format(run_num)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030079 for fname in os.listdir(folder):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030080 rm = re.match(rr, fname)
81 if rm is None:
82 continue
83
84 conn_id_s = rm.group('conn_id')
85 conn_id = conn_id_s.replace('_', ':')
86 ftype = rm.group('type')
87
88 if ftype not in ('iops', 'bw', 'lat'):
89 continue
90
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030091 ts = load_fio_log_file(os.path.join(folder, fname))
92 res.setdefault(ftype, {}).setdefault(conn_id, []).append(ts)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030093
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030094 conn_ids_set.add(conn_id)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +030095
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +030096 mm_res = {}
97
98 for key, data in res.items():
99 conn_ids = sorted(conn_ids_set)
100 matr = [data[conn_id] for conn_id in conn_ids]
101
102 mm_res[key] = MeasurementMatrix(matr, conn_ids)
103
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300104 raw_res = {}
105 for conn_id in conn_ids:
106 fn = os.path.join(folder, "{0}_{1}_rawres.json".format(run_num, conn_id_s))
107
108 # remove message hack
109 fc = "{" + open(fn).read().split('{', 1)[1]
110 raw_res[conn_id] = json.loads(fc)
111
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300112 fio_task = FioJobSection(params['name'])
113 fio_task.vals.update(params['vals'])
114
115 config = TestConfig('io', params, None, params['nodes'], folder, None)
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300116 return FioRunResult(config, fio_task, mm_res, raw_res, params['intervals'], run_num)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300117
118
119class Attrmapper(object):
120 def __init__(self, dct):
121 self.__dct = dct
122
123 def __getattr__(self, name):
124 try:
125 return self.__dct[name]
126 except KeyError:
127 raise AttributeError(name)
128
129
130class DiskPerfInfo(object):
131 def __init__(self, name, summary, params, testnodes_count):
132 self.name = name
133 self.bw = None
134 self.iops = None
135 self.lat = None
136 self.lat_50 = None
137 self.lat_95 = None
koder aka kdanilov170936a2015-06-27 22:51:17 +0300138 self.lat_avg = None
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300139
140 self.raw_bw = []
141 self.raw_iops = []
142 self.raw_lat = []
143
144 self.params = params
145 self.testnodes_count = testnodes_count
146 self.summary = summary
147 self.p = Attrmapper(self.params['vals'])
148
149 self.sync_mode = get_test_sync_mode(self.params['vals'])
150 self.concurence = self.params['vals'].get('numjobs', 1)
151
152
153def get_lat_perc_50_95(lat_mks):
154 curr_perc = 0
155 perc_50 = None
156 perc_95 = None
157 pkey = None
158 for key, val in sorted(lat_mks.items()):
159 if curr_perc + val >= 50 and perc_50 is None:
160 if pkey is None or val < 1.:
161 perc_50 = key
162 else:
163 perc_50 = (50. - curr_perc) / val * (key - pkey) + pkey
164
165 if curr_perc + val >= 95:
166 if pkey is None or val < 1.:
167 perc_95 = key
168 else:
169 perc_95 = (95. - curr_perc) / val * (key - pkey) + pkey
170 break
171
172 pkey = key
173 curr_perc += val
174
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300175 # for k, v in sorted(lat_mks.items()):
176 # if k / 1000 > 0:
177 # print "{0:>4}".format(k / 1000), v
178
179 # print perc_50 / 1000., perc_95 / 1000.
180 # exit(1)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300181 return perc_50 / 1000., perc_95 / 1000.
182
183
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300184class IOTestResults(object):
185 def __init__(self, suite_name, fio_results, log_directory):
186 self.suite_name = suite_name
187 self.fio_results = fio_results
188 self.log_directory = log_directory
189
190 def __iter__(self):
191 return iter(self.fio_results)
192
193 def __len__(self):
194 return len(self.fio_results)
195
196 def get_yamable(self):
197 items = [(fio_res.summary(), fio_res.idx) for fio_res in self]
198 return {self.suite_name: [self.log_directory] + items}
199
200
201class FioRunResult(TestResults):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300202 """
203 Fio run results
204 config: TestConfig
205 fio_task: FioJobSection
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300206 ts_results: {str: MeasurementMatrix[TimeSeriesValue]}
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300207 raw_result: ????
208 run_interval:(float, float) - test tun time, used for sensors
209 """
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300210 def __init__(self, config, fio_task, ts_results, raw_result, run_interval, idx):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300211
koder aka kdanilov170936a2015-06-27 22:51:17 +0300212 self.name = fio_task.name.rsplit("_", 1)[0]
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300213 self.fio_task = fio_task
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300214 self.idx = idx
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300215
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300216 self.bw = ts_results.get('bw')
217 self.lat = ts_results.get('lat')
218 self.iops = ts_results.get('iops')
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300219
220 res = {"bw": self.bw, "lat": self.lat, "iops": self.iops}
221
222 self.sensors_data = None
223 self._pinfo = None
224 TestResults.__init__(self, config, res, raw_result, run_interval)
225
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300226 def get_params_from_fio_report(self):
227 nodes = self.bw.connections_ids
228
229 iops = [self.raw_result[node]['jobs'][0]['mixed']['iops'] for node in nodes]
230 total_ios = [self.raw_result[node]['jobs'][0]['mixed']['total_ios'] for node in nodes]
231 runtime = [self.raw_result[node]['jobs'][0]['mixed']['runtime'] / 1000 for node in nodes]
232 flt_iops = [float(ios) / rtime for ios, rtime in zip(total_ios, runtime)]
233
234 bw = [self.raw_result[node]['jobs'][0]['mixed']['bw'] for node in nodes]
235 total_bytes = [self.raw_result[node]['jobs'][0]['mixed']['io_bytes'] for node in nodes]
236 flt_bw = [float(tbytes) / rtime for tbytes, rtime in zip(total_bytes, runtime)]
237
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300238 return {'iops': iops,
239 'flt_iops': flt_iops,
240 'bw': bw,
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300241 'flt_bw': flt_bw}
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300242
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300243 def summary(self):
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300244 return get_test_summary(self.fio_task, len(self.config.nodes))
245
246 def summary_tpl(self):
247 return get_test_summary_tuple(self.fio_task, len(self.config.nodes))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300248
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300249 def get_lat_perc_50_95_multy(self):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300250 lat_mks = collections.defaultdict(lambda: 0)
251 num_res = 0
252
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300253 for result in self.raw_result.values():
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300254 num_res += len(result['jobs'])
255 for job_info in result['jobs']:
256 for k, v in job_info['latency_ms'].items():
257 if isinstance(k, basestring) and k.startswith('>='):
258 lat_mks[int(k[2:]) * 1000] += v
259 else:
260 lat_mks[int(k) * 1000] += v
261
262 for k, v in job_info['latency_us'].items():
263 lat_mks[int(k)] += v
264
265 for k, v in lat_mks.items():
266 lat_mks[k] = float(v) / num_res
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300267 return get_lat_perc_50_95(lat_mks)
268
269 def disk_perf_info(self, avg_interval=2.0):
270
271 if self._pinfo is not None:
272 return self._pinfo
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300273
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300274 testnodes_count = len(self.config.nodes)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300275
276 pinfo = DiskPerfInfo(self.name,
277 self.summary(),
278 self.params,
279 testnodes_count)
280
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300281 def prepare(data, drop=1):
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300282 if data is None:
283 return data
284
285 res = []
286 for ts_data in data:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300287 if ts_data.average_interval() < avg_interval:
288 ts_data = ts_data.derived(avg_interval)
289
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300290 # drop last value on bounds
291 # as they may contains ranges without activities
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300292 assert len(ts_data.values) >= drop + 1, str(drop) + " " + str(ts_data.values)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300293
294 if drop > 0:
295 res.append(ts_data.values[:-drop])
296 else:
297 res.append(ts_data.values)
298
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300299 return res
300
301 def agg_data(matr):
302 arr = sum(matr, [])
303 min_len = min(map(len, arr))
304 res = []
305 for idx in range(min_len):
306 res.append(sum(dt[idx] for dt in arr))
307 return res
308
koder aka kdanilov170936a2015-06-27 22:51:17 +0300309 pinfo.raw_lat = map(prepare, self.lat.per_vm())
310 num_th = sum(map(len, pinfo.raw_lat))
311 lat_avg = [val / num_th for val in agg_data(pinfo.raw_lat)]
312 pinfo.lat_avg = data_property(lat_avg).average / 1000 # us to ms
313
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300314 pinfo.lat_50, pinfo.lat_95 = self.get_lat_perc_50_95_multy()
315 pinfo.lat = pinfo.lat_50
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300316
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300317 pinfo.raw_bw = map(prepare, self.bw.per_vm())
318 pinfo.raw_iops = map(prepare, self.iops.per_vm())
319
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300320 fparams = self.get_params_from_fio_report()
321 fio_report_bw = sum(fparams['flt_bw'])
322 fio_report_iops = sum(fparams['flt_iops'])
323
324 agg_bw = agg_data(pinfo.raw_bw)
325 agg_iops = agg_data(pinfo.raw_iops)
326
327 log_bw_avg = average(agg_bw)
328 log_iops_avg = average(agg_iops)
329
330 # update values to match average from fio report
331 coef_iops = fio_report_iops / float(log_iops_avg)
332 coef_bw = fio_report_bw / float(log_bw_avg)
333
334 bw_log = data_property([val * coef_bw for val in agg_bw])
335 iops_log = data_property([val * coef_iops for val in agg_iops])
336
337 bw_report = data_property([fio_report_bw])
338 iops_report = data_property([fio_report_iops])
339
340 # When IOPS/BW per thread is too low
341 # data from logs is rounded to match
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300342 iops_per_th = sum(sum(pinfo.raw_iops, []), [])
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300343 if average(iops_per_th) > 10:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300344 pinfo.iops = iops_log
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300345 pinfo.iops2 = iops_report
346 else:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300347 pinfo.iops = iops_report
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300348 pinfo.iops2 = iops_log
349
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300350 bw_per_th = sum(sum(pinfo.raw_bw, []), [])
351 if average(bw_per_th) > 10:
352 pinfo.bw = bw_log
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300353 pinfo.bw2 = bw_report
koder aka kdanilov170936a2015-06-27 22:51:17 +0300354 else:
355 pinfo.bw = bw_report
356 pinfo.bw2 = bw_log
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300357
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300358 self._pinfo = pinfo
359
360 return pinfo
361
362
363class IOPerfTest(PerfTest):
364 tcp_conn_timeout = 30
365 max_pig_timeout = 5
366 soft_runcycle = 5 * 60
367
368 def __init__(self, config):
369 PerfTest.__init__(self, config)
370
371 get = self.config.params.get
372 do_get = self.config.params.__getitem__
373
374 self.config_fname = do_get('cfg')
375
376 if '/' not in self.config_fname and '.' not in self.config_fname:
377 cfgs_dir = os.path.dirname(__file__)
378 self.config_fname = os.path.join(cfgs_dir,
379 self.config_fname + '.cfg')
380
381 self.alive_check_interval = get('alive_check_interval')
382 self.use_system_fio = get('use_system_fio', False)
383
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300384 if get('prefill_files') is not None:
385 logger.warning("prefill_files option is depricated. Use force_prefill instead")
386
387 self.force_prefill = get('force_prefill', False)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300388 self.config_params = get('params', {}).copy()
389
390 self.io_py_remote = self.join_remote("agent.py")
391 self.results_file = self.join_remote("results.json")
392 self.pid_file = self.join_remote("pid")
393 self.task_file = self.join_remote("task.cfg")
394 self.sh_file = self.join_remote("cmd.sh")
395 self.err_out_file = self.join_remote("fio_err_out")
396 self.exit_code_file = self.join_remote("exit_code")
397
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300398 self.max_latency = get("max_lat", None)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300399 self.min_bw_per_thread = get("min_bw", None)
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300400
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300401 self.use_sudo = get("use_sudo", True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300402
403 self.raw_cfg = open(self.config_fname).read()
404 self.fio_configs = fio_cfg_compile(self.raw_cfg,
405 self.config_fname,
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300406 self.config_params)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300407 self.fio_configs = list(self.fio_configs)
408
409 @classmethod
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300410 def load(cls, suite_name, folder):
411 res = []
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300412 for fname in os.listdir(folder):
413 if re.match("\d+_params.yaml$", fname):
414 num = int(fname.split('_')[0])
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300415 res.append(load_test_results(folder, num))
416 return IOTestResults(suite_name, res, folder)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300417
418 def cleanup(self):
419 # delete_file(conn, self.io_py_remote)
420 # Need to remove tempo files, used for testing
421 pass
422
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300423 # size is megabytes
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300424 def check_prefill_required(self, rossh, fname, size, num_blocks=16):
koder aka kdanilov170936a2015-06-27 22:51:17 +0300425 try:
426 with rossh.connection.open_sftp() as sftp:
427 fstats = sftp.stat(fname)
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300428
koder aka kdanilov170936a2015-06-27 22:51:17 +0300429 if stat.S_ISREG(fstats.st_mode) and fstats.st_size < size * 1024 ** 2:
430 return True
431 except EnvironmentError:
koder aka kdanilovf95cfc12015-06-23 03:33:19 +0300432 return True
433
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300434 cmd = 'python -c "' + \
435 "import sys;" + \
436 "fd = open('{0}', 'rb');" + \
437 "fd.seek({1});" + \
438 "data = fd.read(1024); " + \
439 "sys.stdout.write(data + ' ' * ( 1024 - len(data)))\" | md5sum"
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300440
441 if self.use_sudo:
442 cmd = "sudo " + cmd
443
koder aka kdanilovf95cfc12015-06-23 03:33:19 +0300444 zero_md5 = '0f343b0931126a20f133d67c2b018a3b'
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300445 offsets = [random.randrange(size - 1024) for _ in range(num_blocks)]
446 offsets.append(size - 1024)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300447
koder aka kdanilovf95cfc12015-06-23 03:33:19 +0300448 for offset in offsets:
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300449 data = rossh(cmd.format(fname, offset), nolog=True)
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300450
451 md = ""
452 for line in data.split("\n"):
453 if "unable to resolve" not in line:
454 md = line.split()[0].strip()
455 break
koder aka kdanilovf95cfc12015-06-23 03:33:19 +0300456
457 if len(md) != 32:
458 logger.error("File data check is failed - " + data)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300459 return True
koder aka kdanilovf95cfc12015-06-23 03:33:19 +0300460
461 if zero_md5 == md:
462 return True
463
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300464 return False
465
466 def prefill_test_files(self, rossh, files, force=False):
467 if self.use_system_fio:
468 cmd_templ = "fio "
469 else:
470 cmd_templ = "{0}/fio ".format(self.config.remote_dir)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300471
472 if self.use_sudo:
473 cmd_templ = "sudo " + cmd_templ
474
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300475 cmd_templ += "--name=xxx --filename={0} --direct=1" + \
476 " --bs=4m --size={1}m --rw=write"
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300477
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300478 ssize = 0
479
480 if force:
481 logger.info("File prefilling is forced")
482
483 ddtime = 0
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300484 for fname, curr_sz in files.items():
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300485 if not force:
486 if not self.check_prefill_required(rossh, fname, curr_sz):
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300487 logger.debug("prefill is skipped")
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300488 continue
489
490 logger.info("Prefilling file {0}".format(fname))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300491 cmd = cmd_templ.format(fname, curr_sz)
492 ssize += curr_sz
493
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300494 stime = time.time()
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300495 rossh(cmd, timeout=curr_sz)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300496 ddtime += time.time() - stime
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300497
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300498 if ddtime > 1.0:
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300499 fill_bw = int(ssize / ddtime)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300500 mess = "Initiall fio fill bw is {0} MiBps for this vm"
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300501 logger.info(mess.format(fill_bw))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300502
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300503 def install_utils(self, node, rossh, max_retry=3, timeout=5):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300504 need_install = []
505 packs = [('screen', 'screen')]
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300506 os_info = get_os(rossh)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300507
508 if self.use_system_fio:
509 packs.append(('fio', 'fio'))
510 else:
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300511 packs.append(('bzip2', 'bzip2'))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300512
513 for bin_name, package in packs:
514 if bin_name is None:
515 need_install.append(package)
516 continue
517
518 try:
519 rossh('which ' + bin_name, nolog=True)
520 except OSError:
521 need_install.append(package)
522
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300523 if len(need_install) != 0:
524 if 'redhat' == os_info.distro:
525 cmd = "sudo yum -y install " + " ".join(need_install)
526 else:
527 cmd = "sudo apt-get -y install " + " ".join(need_install)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300528
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300529 for _ in range(max_retry):
530 try:
531 rossh(cmd)
532 break
533 except OSError as err:
534 time.sleep(timeout)
535 else:
536 raise OSError("Can't install - " + str(err))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300537
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300538 if not self.use_system_fio:
539 fio_dir = os.path.dirname(os.path.dirname(wally.__file__))
540 fio_dir = os.path.join(os.getcwd(), fio_dir)
541 fio_dir = os.path.join(fio_dir, 'fio_binaries')
542 fname = 'fio_{0.release}_{0.arch}.bz2'.format(os_info)
543 fio_path = os.path.join(fio_dir, fname)
544
545 if not os.path.exists(fio_path):
546 raise RuntimeError("No prebuild fio available for {0}".format(os_info))
547
548 bz_dest = self.join_remote('fio.bz2')
549 with node.connection.open_sftp() as sftp:
550 sftp.put(fio_path, bz_dest)
551
552 rossh("bzip2 --decompress " + bz_dest, nolog=True)
553 rossh("chmod a+x " + self.join_remote("fio"), nolog=True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300554
555 def pre_run(self):
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300556 files = {}
557 for section in self.fio_configs:
558 sz = ssize2b(section.vals['size'])
559 msz = sz / (1024 ** 2)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300560
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300561 if sz % (1024 ** 2) != 0:
562 msz += 1
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300563
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300564 fname = section.vals['filename']
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300565
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300566 # if already has other test with the same file name
567 # take largest size
568 files[fname] = max(files.get(fname, 0), msz)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300569
570 with ThreadPoolExecutor(len(self.config.nodes)) as pool:
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300571 fc = functools.partial(self.pre_run_th,
572 files=files,
573 force=self.force_prefill)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300574 list(pool.map(fc, self.config.nodes))
575
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300576 def pre_run_th(self, node, files, force):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300577 # fill files with pseudo-random data
578 rossh = run_on_node(node)
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300579 rossh.connection = node.connection
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300580
581 try:
582 cmd = 'mkdir -p "{0}"'.format(self.config.remote_dir)
583 if self.use_sudo:
584 cmd = "sudo " + cmd
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300585 cmd += " ; sudo chown {0} {1}".format(node.get_user(),
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300586 self.config.remote_dir)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300587 rossh(cmd, nolog=True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300588
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300589 assert self.config.remote_dir != "" and self.config.remote_dir != "/"
590 rossh("rm -rf {0}/*".format(self.config.remote_dir), nolog=True)
591
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300592 except Exception as exc:
593 msg = "Failed to create folder {0} on remote {1}. Error: {2!s}"
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300594 msg = msg.format(self.config.remote_dir, node.get_conn_id(), exc)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300595 logger.exception(msg)
596 raise StopTestError(msg, exc)
597
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300598 self.install_utils(node, rossh)
599 self.prefill_test_files(rossh, files, force)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300600
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300601 def show_test_execution_time(self):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300602 if len(self.fio_configs) > 1:
603 # +10% - is a rough estimation for additional operations
604 # like sftp, etc
605 exec_time = int(sum(map(execution_time, self.fio_configs)) * 1.1)
606 exec_time_s = sec_to_str(exec_time)
607 now_dt = datetime.datetime.now()
608 end_dt = now_dt + datetime.timedelta(0, exec_time)
609 msg = "Entire test should takes aroud: {0} and finished at {1}"
610 logger.info(msg.format(exec_time_s,
611 end_dt.strftime("%H:%M:%S")))
612
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300613 def run(self):
614 logger.debug("Run preparation")
615 self.pre_run()
616 self.show_test_execution_time()
617
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300618 tname = os.path.basename(self.config_fname)
619 if tname.endswith('.cfg'):
620 tname = tname[:-4]
621
622 barrier = Barrier(len(self.config.nodes))
623 results = []
624
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300625 # set of Operation_Mode_BlockSize str's
626 # which should not be tested anymore, as
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300627 # they already too slow with previous thread count
628 lat_bw_limit_reached = set()
629
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300630 with ThreadPoolExecutor(len(self.config.nodes)) as pool:
631 for pos, fio_cfg in enumerate(self.fio_configs):
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300632 test_descr = get_test_summary(fio_cfg.vals).split("th")[0]
633 if test_descr in lat_bw_limit_reached:
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300634 continue
635 else:
636 logger.info("Will run {0} test".format(fio_cfg.name))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300637
638 templ = "Test should takes about {0}." + \
639 " Should finish at {1}," + \
640 " will wait at most till {2}"
641 exec_time = execution_time(fio_cfg)
642 exec_time_str = sec_to_str(exec_time)
643 timeout = int(exec_time + max(300, exec_time))
644
645 now_dt = datetime.datetime.now()
646 end_dt = now_dt + datetime.timedelta(0, exec_time)
647 wait_till = now_dt + datetime.timedelta(0, timeout)
648
649 logger.info(templ.format(exec_time_str,
650 end_dt.strftime("%H:%M:%S"),
651 wait_till.strftime("%H:%M:%S")))
652
653 func = functools.partial(self.do_run,
654 barrier=barrier,
655 fio_cfg=fio_cfg,
656 pos=pos)
657
658 max_retr = 3
659 for idx in range(max_retr):
660 try:
661 intervals = list(pool.map(func, self.config.nodes))
662 break
663 except (EnvironmentError, SSHException) as exc:
664 logger.exception("During fio run")
665 if idx == max_retr - 1:
666 raise StopTestError("Fio failed", exc)
667
668 logger.info("Sleeping 30s and retrying")
669 time.sleep(30)
670
671 fname = "{0}_task.fio".format(pos)
672 with open(os.path.join(self.config.log_directory, fname), "w") as fd:
673 fd.write(str(fio_cfg))
674
675 params = {'vm_count': len(self.config.nodes)}
676 params['name'] = fio_cfg.name
677 params['vals'] = dict(fio_cfg.vals.items())
678 params['intervals'] = intervals
679 params['nodes'] = [node.get_conn_id() for node in self.config.nodes]
680
681 fname = "{0}_params.yaml".format(pos)
682 with open(os.path.join(self.config.log_directory, fname), "w") as fd:
683 fd.write(dumps(params))
684
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300685 res = load_test_results(self.config.log_directory, pos)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300686 results.append(res)
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300687
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300688 if self.max_latency is not None:
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300689 lat_50, _ = res.get_lat_perc_50_95_multy()
690
691 # conver us to ms
692 if self.max_latency < lat_50:
693 logger.info(("Will skip all subsequent tests of {0} " +
694 "due to lat/bw limits").format(fio_cfg.name))
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300695 lat_bw_limit_reached.add(test_descr)
696
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300697 test_res = res.get_params_from_fio_report()
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300698 if self.min_bw_per_thread is not None:
699 if self.min_bw_per_thread > average(test_res['bw']):
700 lat_bw_limit_reached.add(test_descr)
701
koder aka kdanilov0fdaaee2015-06-30 11:10:48 +0300702 return IOTestResults(self.config.params['cfg'],
703 results, self.config.log_directory)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300704
705 def do_run(self, node, barrier, fio_cfg, pos, nolog=False):
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300706 if self.use_sudo:
707 sudo = "sudo "
708 else:
709 sudo = ""
710
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300711 bash_file = "#!/bin/bash\n" + \
712 "cd {exec_folder}\n" + \
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300713 "{fio_path}fio --output-format=json --output={out_file} " + \
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300714 "--alloc-size=262144 {job_file} " + \
715 " >{err_out_file} 2>&1 \n" + \
716 "echo $? >{res_code_file}\n"
717
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300718 exec_folder = self.config.remote_dir
719
720 if self.use_system_fio:
721 fio_path = ""
722 else:
723 if not exec_folder.endswith("/"):
724 fio_path = exec_folder + "/"
725 else:
726 fio_path = exec_folder
727
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300728 bash_file = bash_file.format(out_file=self.results_file,
729 job_file=self.task_file,
730 err_out_file=self.err_out_file,
731 res_code_file=self.exit_code_file,
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300732 exec_folder=exec_folder,
733 fio_path=fio_path)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300734
735 with node.connection.open_sftp() as sftp:
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300736 save_to_remote(sftp, self.task_file, str(fio_cfg))
737 save_to_remote(sftp, self.sh_file, bash_file)
738
739 exec_time = execution_time(fio_cfg)
740
741 timeout = int(exec_time + max(300, exec_time))
742 soft_tout = exec_time
743
744 begin = time.time()
745
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300746 fnames_before = run_on_node(node)("ls -1 " + exec_folder, nolog=True)
747
748 barrier.wait()
749
koder aka kdanilov5414a992015-06-13 03:07:25 +0300750 task = BGSSHTask(node, self.use_sudo)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300751 task.start(sudo + "bash " + self.sh_file)
752
753 while True:
754 try:
755 task.wait(soft_tout, timeout)
756 break
757 except paramiko.SSHException:
758 pass
759
760 try:
761 node.connection.close()
762 except:
763 pass
764
765 reconnect(node.connection, node.conn_url)
766
767 end = time.time()
768 rossh = run_on_node(node)
769 fnames_after = rossh("ls -1 " + exec_folder, nolog=True)
770
771 conn_id = node.get_conn_id().replace(":", "_")
772 if not nolog:
773 logger.debug("Test on node {0} is finished".format(conn_id))
774
775 log_files_pref = []
776 if 'write_lat_log' in fio_cfg.vals:
777 fname = fio_cfg.vals['write_lat_log']
778 log_files_pref.append(fname + '_clat')
779 log_files_pref.append(fname + '_lat')
780 log_files_pref.append(fname + '_slat')
781
782 if 'write_iops_log' in fio_cfg.vals:
783 fname = fio_cfg.vals['write_iops_log']
784 log_files_pref.append(fname + '_iops')
785
786 if 'write_bw_log' in fio_cfg.vals:
787 fname = fio_cfg.vals['write_bw_log']
788 log_files_pref.append(fname + '_bw')
789
790 files = collections.defaultdict(lambda: [])
791 all_files = [os.path.basename(self.results_file)]
792 new_files = set(fnames_after.split()) - set(fnames_before.split())
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300793
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300794 for fname in new_files:
795 if fname.endswith('.log') and fname.split('.')[0] in log_files_pref:
796 name, _ = os.path.splitext(fname)
797 if fname.count('.') == 1:
798 tp = name.split("_")[-1]
799 cnt = 0
800 else:
801 tp_cnt = name.split("_")[-1]
802 tp, cnt = tp_cnt.split('.')
803 files[tp].append((int(cnt), fname))
804 all_files.append(fname)
805
806 arch_name = self.join_remote('wally_result.tar.gz')
807 tmp_dir = os.path.join(self.config.log_directory, 'tmp_' + conn_id)
808 os.mkdir(tmp_dir)
809 loc_arch_name = os.path.join(tmp_dir, 'wally_result.{0}.tar.gz'.format(conn_id))
810 file_full_names = " ".join(all_files)
811
812 try:
813 os.unlink(loc_arch_name)
814 except:
815 pass
816
817 with node.connection.open_sftp() as sftp:
818 exit_code = read_from_remote(sftp, self.exit_code_file)
819 err_out = read_from_remote(sftp, self.err_out_file)
820 exit_code = exit_code.strip()
821
822 if exit_code != '0':
823 msg = "fio exit with code {0}: {1}".format(exit_code, err_out)
824 logger.critical(msg.strip())
825 raise StopTestError("fio failed")
826
827 rossh("rm -f {0}".format(arch_name), nolog=True)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300828 pack_files_cmd = "cd {0} ; tar zcvf {1} {2}".format(exec_folder, arch_name, file_full_names)
829 rossh(pack_files_cmd, nolog=True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300830 sftp.get(arch_name, loc_arch_name)
831
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300832 unpack_files_cmd = "cd {0} ; tar xvzf {1} >/dev/null".format(tmp_dir, loc_arch_name)
833 subprocess.check_call(unpack_files_cmd, shell=True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300834 os.unlink(loc_arch_name)
835
836 for ftype, fls in files.items():
837 for idx, fname in fls:
838 cname = os.path.join(tmp_dir, fname)
839 loc_fname = "{0}_{1}_{2}.{3}.log".format(pos, conn_id, ftype, idx)
840 loc_path = os.path.join(self.config.log_directory, loc_fname)
841 os.rename(cname, loc_path)
842
843 cname = os.path.join(tmp_dir,
844 os.path.basename(self.results_file))
845 loc_fname = "{0}_{1}_rawres.json".format(pos, conn_id)
846 loc_path = os.path.join(self.config.log_directory, loc_fname)
847 os.rename(cname, loc_path)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300848 os.rmdir(tmp_dir)
koder aka kdanilov6ab4d432015-06-22 00:26:28 +0300849
850 remove_remote_res_files_cmd = "cd {0} ; rm -f {1} {2}".format(exec_folder,
851 arch_name,
852 file_full_names)
853 rossh(remove_remote_res_files_cmd, nolog=True)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300854 return begin, end
855
856 @classmethod
koder aka kdanilov6b872662015-06-23 01:58:36 +0300857 def prepare_data(cls, results):
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300858 """
859 create a table with io performance report
860 for console
861 """
862
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300863 def key_func(data):
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300864 tpl = data.summary_tpl()
koder aka kdanilov170936a2015-06-27 22:51:17 +0300865 return (data.name,
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300866 tpl.oper,
867 tpl.mode,
koder aka kdanilov170936a2015-06-27 22:51:17 +0300868 ssize2b(tpl.bsize),
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300869 int(tpl.th_count) * int(tpl.vm_count))
koder aka kdanilov6b872662015-06-23 01:58:36 +0300870 res = []
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300871
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300872 for item in sorted(results, key=key_func):
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300873 test_dinfo = item.disk_perf_info()
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300874
875 iops, _ = test_dinfo.iops.rounded_average_conf()
876
877 bw, bw_conf = test_dinfo.bw.rounded_average_conf()
878 _, bw_dev = test_dinfo.bw.rounded_average_dev()
879 conf_perc = int(round(bw_conf * 100 / bw))
880 dev_perc = int(round(bw_dev * 100 / bw))
881
koder aka kdanilov6b872662015-06-23 01:58:36 +0300882 lat_50 = round_3_digit(int(test_dinfo.lat_50))
883 lat_95 = round_3_digit(int(test_dinfo.lat_95))
koder aka kdanilov170936a2015-06-27 22:51:17 +0300884 lat_avg = round_3_digit(int(test_dinfo.lat_avg))
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300885
koder aka kdanilovbb6d6cd2015-06-20 02:55:07 +0300886 testnodes_count = len(item.config.nodes)
887 iops_per_vm = round_3_digit(iops / testnodes_count)
888 bw_per_vm = round_3_digit(bw / testnodes_count)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300889
890 iops = round_3_digit(iops)
891 bw = round_3_digit(bw)
892
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300893 summ = "{0.oper}{0.mode} {0.bsize:>4} {0.th_count:>3}th {0.vm_count:>2}vm".format(item.summary_tpl())
894
895 res.append({"name": key_func(item)[0],
896 "key": key_func(item)[:4],
897 "summ": summ,
koder aka kdanilov6b872662015-06-23 01:58:36 +0300898 "iops": int(iops),
899 "bw": int(bw),
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300900 "conf": str(conf_perc),
901 "dev": str(dev_perc),
koder aka kdanilov6b872662015-06-23 01:58:36 +0300902 "iops_per_vm": int(iops_per_vm),
903 "bw_per_vm": int(bw_per_vm),
904 "lat_50": lat_50,
koder aka kdanilov170936a2015-06-27 22:51:17 +0300905 "lat_95": lat_95,
906 "lat_avg": lat_avg})
koder aka kdanilovbc2c8982015-06-13 02:50:43 +0300907
koder aka kdanilov6b872662015-06-23 01:58:36 +0300908 return res
909
910 Field = collections.namedtuple("Field", ("header", "attr", "allign", "size"))
911 fiels_and_header = [
912 Field("Name", "name", "l", 7),
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300913 Field("Description", "summ", "l", 19),
koder aka kdanilov6b872662015-06-23 01:58:36 +0300914 Field("IOPS\ncum", "iops", "r", 3),
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300915 Field("KiBps\ncum", "bw", "r", 6),
916 Field("Cnf %\n95%", "conf", "r", 3),
917 Field("Dev%", "dev", "r", 3),
918 Field("iops\n/vm", "iops_per_vm", "r", 3),
919 Field("KiBps\n/vm", "bw_per_vm", "r", 6),
koder aka kdanilov6b872662015-06-23 01:58:36 +0300920 Field("lat ms\nmedian", "lat_50", "r", 3),
koder aka kdanilov170936a2015-06-27 22:51:17 +0300921 Field("lat ms\n95%", "lat_95", "r", 3),
922 Field("lat\navg", "lat_avg", "r", 3),
koder aka kdanilov6b872662015-06-23 01:58:36 +0300923 ]
924
925 fiels_and_header_dct = dict((item.attr, item) for item in fiels_and_header)
926
927 @classmethod
928 def format_for_console(cls, results):
929 """
930 create a table with io performance report
931 for console
932 """
933
934 tab = texttable.Texttable(max_width=120)
935 tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER)
936 tab.set_cols_align([f.allign for f in cls.fiels_and_header])
937 sep = ["-" * f.size for f in cls.fiels_and_header]
938 tab.header([f.header for f in cls.fiels_and_header])
koder aka kdanilov6b872662015-06-23 01:58:36 +0300939 prev_k = None
940 for item in cls.prepare_data(results):
koder aka kdanilov6b872662015-06-23 01:58:36 +0300941 if prev_k is not None:
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300942 if prev_k != item["key"]:
koder aka kdanilov6b872662015-06-23 01:58:36 +0300943 tab.add_row(sep)
944
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300945 prev_k = item["key"]
koder aka kdanilov6b872662015-06-23 01:58:36 +0300946 tab.add_row([item[f.attr] for f in cls.fiels_and_header])
947
948 return tab.draw()
949
950 @classmethod
951 def format_diff_for_console(cls, list_of_results):
952 """
953 create a table with io performance report
954 for console
955 """
956
957 tab = texttable.Texttable(max_width=200)
958 tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER)
959
960 header = [
961 cls.fiels_and_header_dct["name"].header,
962 cls.fiels_and_header_dct["summ"].header,
963 ]
964 allign = ["l", "l"]
965
966 header.append("IOPS ~ Cnf% ~ Dev%")
967 allign.extend(["r"] * len(list_of_results))
968 header.extend(
969 "IOPS_{0} %".format(i + 2) for i in range(len(list_of_results[1:]))
970 )
971
972 header.append("BW")
973 allign.extend(["r"] * len(list_of_results))
974 header.extend(
975 "BW_{0} %".format(i + 2) for i in range(len(list_of_results[1:]))
976 )
977
978 header.append("LAT")
979 allign.extend(["r"] * len(list_of_results))
980 header.extend(
981 "LAT_{0}".format(i + 2) for i in range(len(list_of_results[1:]))
982 )
983
984 tab.header(header)
985 sep = ["-" * 3] * len(header)
986 processed_results = map(cls.prepare_data, list_of_results)
987
988 key2results = []
989 for res in processed_results:
990 key2results.append(dict(
991 ((item["name"], item["summ"]), item) for item in res
992 ))
993
994 prev_k = None
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300995 iops_frmt = "{0[iops]} ~ {0[conf]:>2} ~ {0[dev]:>2}"
koder aka kdanilov6b872662015-06-23 01:58:36 +0300996 for item in processed_results[0]:
koder aka kdanilov6b872662015-06-23 01:58:36 +0300997 if prev_k is not None:
koder aka kdanilovf236b9c2015-06-24 18:17:22 +0300998 if prev_k != item["key"]:
koder aka kdanilov6b872662015-06-23 01:58:36 +0300999 tab.add_row(sep)
1000
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001001 prev_k = item["key"]
koder aka kdanilov6b872662015-06-23 01:58:36 +03001002
1003 key = (item['name'], item['summ'])
1004 line = list(key)
1005 base = key2results[0][key]
1006
1007 line.append(iops_frmt.format(base))
1008
1009 for test_results in key2results[1:]:
1010 val = test_results.get(key)
1011 if val is None:
1012 line.append("-")
1013 elif base['iops'] == 0:
1014 line.append("Nan")
1015 else:
koder aka kdanilovf236b9c2015-06-24 18:17:22 +03001016 prc_val = {'dev': val['dev'], 'conf': val['conf']}
koder aka kdanilov6b872662015-06-23 01:58:36 +03001017 prc_val['iops'] = int(100 * val['iops'] / base['iops'])
1018 line.append(iops_frmt.format(prc_val))
1019
1020 line.append(base['bw'])
1021
1022 for test_results in key2results[1:]:
1023 val = test_results.get(key)
1024 if val is None:
1025 line.append("-")
1026 elif base['bw'] == 0:
1027 line.append("Nan")
1028 else:
1029 line.append(int(100 * val['bw'] / base['bw']))
1030
1031 for test_results in key2results:
1032 val = test_results.get(key)
1033 if val is None:
1034 line.append("-")
1035 else:
1036 line.append("{0[lat_50]} - {0[lat_95]}".format(val))
1037
1038 tab.add_row(line)
1039
1040 tab.set_cols_align(allign)
koder aka kdanilovbc2c8982015-06-13 02:50:43 +03001041 return tab.draw()