blob: c012950161e965057f57881a63083e76c7f04e51 [file] [log] [blame]
koder aka kdanilovda45e882015-04-06 02:24:42 +03001import sys
2import time
3import json
koder aka kdanilov0c598a12015-04-21 03:01:40 +03004import copy
koder aka kdanilovda45e882015-04-06 02:24:42 +03005import select
6import pprint
7import argparse
8import traceback
9import subprocess
10import itertools
11from collections import OrderedDict
12
13
14SECTION = 0
15SETTING = 1
16
17
koder aka kdanilov0c598a12015-04-21 03:01:40 +030018class FioJobSection(object):
19 def __init__(self, name):
20 self.name = name
21 self.vals = OrderedDict()
22 self.format_params = {}
23
24 def copy(self):
25 return copy.deepcopy(self)
26
27
28def to_bytes(sz):
29 sz = sz.lower()
30 try:
31 return int(sz)
32 except ValueError:
33 if sz[-1] == 'm':
34 return (1024 ** 2) * int(sz[:-1])
35 if sz[-1] == 'k':
36 return 1024 * int(sz[:-1])
37 if sz[-1] == 'g':
38 return (1024 ** 3) * int(sz[:-1])
39 raise
40
41
42def fio_config_lexer(fio_cfg):
43 for lineno, line in enumerate(fio_cfg.split("\n")):
44 try:
45 line = line.strip()
46
47 if line.startswith("#") or line.startswith(";"):
48 continue
49
50 if line == "":
51 continue
52
53 if line.startswith('['):
54 assert line.endswith(']'), "name should ends with ]"
55 yield lineno, SECTION, line[1:-1], None
56 elif '=' in line:
57 opt_name, opt_val = line.split('=', 1)
58 yield lineno, SETTING, opt_name.strip(), opt_val.strip()
59 else:
60 yield lineno, SETTING, line, None
61 except Exception as exc:
62 pref = "During parsing line number {0}\n".format(lineno)
63 raise ValueError(pref + exc.message)
64
65
66def fio_config_parse(lexer_iter, format_params):
67 orig_format_params_keys = set(format_params)
68 format_params = format_params.copy()
69 in_defaults = False
70 curr_section = None
71 defaults = OrderedDict()
72
73 for lineno, tp, name, val in lexer_iter:
74 if tp == SECTION:
75 if curr_section is not None:
76 yield curr_section
77
78 if name == 'defaults':
79 in_defaults = True
80 curr_section = None
81 else:
82 in_defaults = False
83 curr_section = FioJobSection(name)
84 curr_section.format_params = format_params.copy()
85 curr_section.vals = defaults.copy()
86 else:
87 assert tp == SETTING
88 if name == name.upper():
89 msg = "Param not in default section in line " + str(lineno)
90 assert in_defaults, msg
91 if name not in orig_format_params_keys:
92 # don't make parse_value for PARAMS
93 # they would be parsed later
94 # or this would breakes arrays
95 format_params[name] = val
96 elif in_defaults:
97 defaults[name] = parse_value(val)
98 else:
99 msg = "data outside section, line " + str(lineno)
100 assert curr_section is not None, msg
101 curr_section.vals[name] = parse_value(val)
102
103 if curr_section is not None:
104 yield curr_section
105
106
107def parse_value(val):
108 if val is None:
109 return None
110
111 try:
112 return int(val)
113 except ValueError:
114 pass
115
116 try:
117 return float(val)
118 except ValueError:
119 pass
120
121 if val.startswith('{%'):
122 assert val.endswith("%}")
123 content = val[2:-2]
124 vals = list(i.strip() for i in content.split(','))
125 return map(parse_value, vals)
126 return val
127
128
129def process_repeats(sec_iter):
130
131 for sec in sec_iter:
132 if '*' in sec.name:
133 msg = "Only one '*' allowed in section name"
134 assert sec.name.count('*') == 1, msg
135
136 name, count = sec.name.split("*")
137 sec.name = name.strip()
138 count = count.strip()
139
140 try:
141 count = int(count.strip().format(**sec.format_params))
142 except KeyError:
143 raise ValueError("No parameter {0} given".format(count[1:-1]))
144 except ValueError:
145 msg = "Parameter {0} nas non-int value {1!r}"
146 raise ValueError(msg.format(count[1:-1],
147 count.format(**sec.format_params)))
148
149 yield sec
150
151 if 'ramp_time' in sec.vals:
152 sec = sec.copy()
153 sec.vals['_ramp_time'] = sec.vals.pop('ramp_time')
154
155 for _ in range(count - 1):
156 yield sec.copy()
157 else:
158 yield sec
159
160
161def process_cycles(sec_iter):
162 # insert parametrized cycles
163 sec_iter = try_format_params_into_section(sec_iter)
164
165 for sec in sec_iter:
166
167 cycles_var_names = []
168 cycles_var_values = []
169
170 for name, val in sec.vals.items():
171 if isinstance(val, list):
172 cycles_var_names.append(name)
173 cycles_var_values.append(val)
174
175 if len(cycles_var_names) == 0:
176 yield sec
177 else:
178 for combination in itertools.product(*cycles_var_values):
179 new_sec = sec.copy()
180 new_sec.vals.update(zip(cycles_var_names, combination))
181 yield new_sec
182
183
184def try_format_params_into_section(sec_iter):
185 for sec in sec_iter:
186 params = sec.format_params
187 for name, val in sec.vals.items():
188 if isinstance(val, basestring):
189 try:
190 sec.vals[name] = parse_value(val.format(**params))
191 except:
192 pass
193
194 yield sec
195
196
197def format_params_into_section_finall(sec_iter, counter=[0]):
198 group_report_err_msg = "Group reporting should be set if numjobs != 1"
199
200 for sec in sec_iter:
201
202 num_jobs = int(sec.vals.get('numjobs', '1'))
203 if num_jobs != 1:
204 assert 'group_reporting' in sec.vals, group_report_err_msg
205
206 params = sec.format_params
207
208 fsize = to_bytes(sec.vals['size'])
209 params['PER_TH_OFFSET'] = fsize // num_jobs
210
211 for name, val in sec.vals.items():
212 if isinstance(val, basestring):
213 sec.vals[name] = parse_value(val.format(**params))
214 else:
215 assert isinstance(val, (int, float)) or val is None
216
217 params['UNIQ'] = 'UN{0}'.format(counter[0])
218 counter[0] += 1
219 params['TEST_SUMM'] = get_test_summary(sec.vals)
220 sec.name = sec.name.format(**params)
221
222 yield sec
223
224
225def fio_config_to_str(sec_iter):
226 res = ""
227
228 for pos, sec in enumerate(sec_iter):
229 if pos != 0:
230 res += "\n"
231
232 res += "[{0}]\n".format(sec.name)
233
234 for name, val in sec.vals.items():
235 if name.startswith('_'):
236 continue
237
238 if val is None:
239 res += name + "\n"
240 else:
241 res += "{0}={1}\n".format(name, val)
242
243 return res
244
245
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300246def get_test_sync_mode(config):
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300247 try:
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300248 return config['sync_mode']
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300249 except KeyError:
250 pass
251
koder aka kdanilovea22c3d2015-04-21 03:42:22 +0300252 is_sync = str(config.get("sync", "0")) == "1"
253 is_direct = str(config.get("direct", "0")) == "1"
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300254
255 if is_sync and is_direct:
256 return 'x'
257 elif is_sync:
258 return 's'
259 elif is_direct:
260 return 'd'
261 else:
262 return 'a'
263
264
koder aka kdanilovda45e882015-04-06 02:24:42 +0300265def get_test_summary(params):
266 rw = {"randread": "rr",
267 "randwrite": "rw",
268 "read": "sr",
269 "write": "sw"}[params["rw"]]
270
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300271 sync_mode = get_test_sync_mode(params)
272 th_count = params.get('numjobs')
koder aka kdanilovea22c3d2015-04-21 03:42:22 +0300273
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300274 if th_count is None:
koder aka kdanilovea22c3d2015-04-21 03:42:22 +0300275 th_count = params.get('concurence', 1)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300276
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300277 return "{0}{1}{2}th{3}".format(rw,
278 sync_mode,
279 params['blocksize'],
280 th_count)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300281
282
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300283def calculate_execution_time(sec_iter):
koder aka kdanilovda45e882015-04-06 02:24:42 +0300284 time = 0
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300285 for sec in sec_iter:
286 time += sec.vals.get('ramp_time', 0)
287 time += sec.vals.get('runtime', 0)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300288 return time
289
290
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300291def slice_config(sec_iter, runcycle=None, max_jobs=1000):
292 jcount = 0
293 runtime = 0
294 curr_slice = []
koder aka kdanilovda45e882015-04-06 02:24:42 +0300295
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300296 for pos, sec in enumerate(sec_iter):
koder aka kdanilovda45e882015-04-06 02:24:42 +0300297
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300298 jc = sec.vals.get('numjobs', 1)
299 msg = "numjobs should be integer, not {0!r}".format(jc)
300 assert isinstance(jc, int), msg
koder aka kdanilovda45e882015-04-06 02:24:42 +0300301
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300302 curr_task_time = calculate_execution_time([sec])
koder aka kdanilovda45e882015-04-06 02:24:42 +0300303
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300304 if jc > max_jobs:
305 err_templ = "Can't process job {0!r} - too large numjobs"
306 raise ValueError(err_templ.format(sec.name))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300307
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300308 if runcycle is not None and len(curr_slice) != 0:
309 rc_ok = curr_task_time + runtime <= runcycle
koder aka kdanilovda45e882015-04-06 02:24:42 +0300310 else:
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300311 rc_ok = True
koder aka kdanilovda45e882015-04-06 02:24:42 +0300312
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300313 if jc + jcount <= max_jobs and rc_ok:
314 runtime += curr_task_time
315 jcount += jc
316 curr_slice.append(sec)
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300317 continue
318
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300319 assert len(curr_slice) != 0
320 yield curr_slice
koder aka kdanilovda45e882015-04-06 02:24:42 +0300321
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300322 if '_ramp_time' in sec.vals:
323 sec.vals['ramp_time'] = sec.vals.pop('_ramp_time')
324 curr_task_time = calculate_execution_time([sec])
325
326 runtime = curr_task_time
327 jcount = jc
328 curr_slice = [sec]
329
330 if curr_slice != []:
331 yield curr_slice
koder aka kdanilovda45e882015-04-06 02:24:42 +0300332
333
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300334def parse_all_in_1(source, test_params):
335 lexer_it = fio_config_lexer(source)
336 sec_it = fio_config_parse(lexer_it, test_params)
337 sec_it = process_cycles(sec_it)
338 sec_it = process_repeats(sec_it)
339 return format_params_into_section_finall(sec_it)
koder aka kdanilovb896f692015-04-07 14:57:55 +0300340
341
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300342def parse_and_slice_all_in_1(source, test_params, **slice_params):
343 sec_it = parse_all_in_1(source, test_params)
344 return slice_config(sec_it, **slice_params)
koder aka kdanilovb896f692015-04-07 14:57:55 +0300345
346
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300347def compile_all_in_1(source, test_params, **slice_params):
348 slices_it = parse_and_slice_all_in_1(source, test_params, **slice_params)
349 for slices in slices_it:
350 yield fio_config_to_str(slices)
koder aka kdanilovb896f692015-04-07 14:57:55 +0300351
352
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300353def do_run_fio(config_slice):
354 benchmark_config = fio_config_to_str(config_slice)
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300355 cmd = ["fio", "--output-format=json", "--alloc-size=262144", "-"]
koder aka kdanilove87ae652015-04-20 02:14:35 +0300356 p = subprocess.Popen(cmd,
357 stdin=subprocess.PIPE,
koder aka kdanilovda45e882015-04-06 02:24:42 +0300358 stdout=subprocess.PIPE,
koder aka kdanilove87ae652015-04-20 02:14:35 +0300359 stderr=subprocess.PIPE)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300360
361 # set timeout
koder aka kdanilove87ae652015-04-20 02:14:35 +0300362 raw_out, raw_err = p.communicate(benchmark_config)
363
364 if 0 != p.returncode:
365 msg = "Fio failed with code: {0}\nOutput={1}"
366 raise OSError(msg.format(p.returncode, raw_err))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300367
368 try:
369 parsed_out = json.loads(raw_out)["jobs"]
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300370 except KeyError:
371 msg = "Can't parse fio output {0!r}: no 'jobs' found"
372 raw_out = raw_out[:100]
373 raise ValueError(msg.format(raw_out))
374
375 except Exception as exc:
koder aka kdanilovda45e882015-04-06 02:24:42 +0300376 msg = "Can't parse fio output: {0!r}\nError: {1}"
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300377 raw_out = raw_out[:100]
378 raise ValueError(msg.format(raw_out, exc.message))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300379
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300380 return zip(parsed_out, config_slice)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300381
382
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300383def add_job_results(section, job_output, res):
koder aka kdanilovda45e882015-04-06 02:24:42 +0300384 if job_output['write']['iops'] != 0:
385 raw_result = job_output['write']
386 else:
387 raw_result = job_output['read']
388
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300389 vals = section.vals
390 if section.name not in res:
koder aka kdanilovda45e882015-04-06 02:24:42 +0300391 j_res = {}
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300392 j_res["rw"] = vals["rw"]
393 j_res["sync_mode"] = get_test_sync_mode(vals)
394 j_res["concurence"] = int(vals.get("numjobs", 1))
395 j_res["blocksize"] = vals["blocksize"]
koder aka kdanilovda45e882015-04-06 02:24:42 +0300396 j_res["jobname"] = job_output["jobname"]
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300397 j_res["timings"] = [int(vals.get("runtime", 0)),
398 int(vals.get("ramp_time", 0))]
koder aka kdanilovda45e882015-04-06 02:24:42 +0300399 else:
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300400 j_res = res[section.name]
401 assert j_res["rw"] == vals["rw"]
402 assert j_res["rw"] == vals["rw"]
403 assert j_res["sync_mode"] == get_test_sync_mode(vals)
404 assert j_res["concurence"] == int(vals.get("numjobs", 1))
405 assert j_res["blocksize"] == vals["blocksize"]
koder aka kdanilovda45e882015-04-06 02:24:42 +0300406 assert j_res["jobname"] == job_output["jobname"]
koder aka kdanilov652cd802015-04-13 12:21:07 +0300407
408 # ramp part is skipped for all tests, except first
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300409 # assert j_res["timings"] == (vals.get("runtime"),
410 # vals.get("ramp_time"))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300411
412 def j_app(name, x):
413 j_res.setdefault(name, []).append(x)
414
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +0300415 j_app("bw", raw_result["bw"])
koder aka kdanilovda45e882015-04-06 02:24:42 +0300416 j_app("iops", raw_result["iops"])
417 j_app("lat", raw_result["lat"]["mean"])
418 j_app("clat", raw_result["clat"]["mean"])
419 j_app("slat", raw_result["slat"]["mean"])
420
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300421 res[section.name] = j_res
koder aka kdanilovda45e882015-04-06 02:24:42 +0300422
423
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300424def run_fio(sliced_it, raw_results_func=None):
425 sliced_list = list(sliced_it)
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300426 ok = True
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300427
koder aka kdanilovda45e882015-04-06 02:24:42 +0300428 try:
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300429 curr_test_num = 0
430 executed_tests = 0
431 result = {}
koder aka kdanilovb896f692015-04-07 14:57:55 +0300432
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300433 for i, test_slice in enumerate(sliced_list):
434 res_cfg_it = do_run_fio(test_slice)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300435 res_cfg_it = enumerate(res_cfg_it, curr_test_num)
436
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300437 for curr_test_num, (job_output, section) in res_cfg_it:
koder aka kdanilov2e928022015-04-08 13:47:15 +0300438 executed_tests += 1
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300439
koder aka kdanilovda45e882015-04-06 02:24:42 +0300440 if raw_results_func is not None:
koder aka kdanilov2e928022015-04-08 13:47:15 +0300441 raw_results_func(executed_tests,
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300442 [job_output, section])
koder aka kdanilovda45e882015-04-06 02:24:42 +0300443
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300444 msg = "{0} != {1}".format(section.name, job_output["jobname"])
445 assert section.name == job_output["jobname"], msg
koder aka kdanilovda45e882015-04-06 02:24:42 +0300446
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300447 if section.name.startswith('_'):
koder aka kdanilovda45e882015-04-06 02:24:42 +0300448 continue
449
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300450 add_job_results(section, job_output, result)
451
koder aka kdanilove87ae652015-04-20 02:14:35 +0300452 curr_test_num += 1
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300453 msg_template = "Done {0} tests from {1}. ETA: {2}"
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300454
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300455 rest = sliced_list[i:]
456 time_eta = sum(map(calculate_execution_time, rest))
457 test_left = sum(map(len, rest))
458 print msg_template.format(curr_test_num,
459 test_left,
460 sec_to_str(time_eta))
koder aka kdanilov4500a5f2015-04-17 16:55:17 +0300461
koder aka kdanilovda45e882015-04-06 02:24:42 +0300462 except (SystemExit, KeyboardInterrupt):
koder aka kdanilov652cd802015-04-13 12:21:07 +0300463 raise
koder aka kdanilovda45e882015-04-06 02:24:42 +0300464
465 except Exception:
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300466 print "=========== ERROR ============="
koder aka kdanilovda45e882015-04-06 02:24:42 +0300467 traceback.print_exc()
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300468 print "======== END OF ERROR ========="
469 ok = False
koder aka kdanilovda45e882015-04-06 02:24:42 +0300470
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300471 return result, executed_tests, ok
koder aka kdanilovda45e882015-04-06 02:24:42 +0300472
473
474def run_benchmark(binary_tp, *argv, **kwargs):
475 if 'fio' == binary_tp:
476 return run_fio(*argv, **kwargs)
477 raise ValueError("Unknown behcnmark {0}".format(binary_tp))
478
479
koder aka kdanilov652cd802015-04-13 12:21:07 +0300480def read_config(fd, timeout=10):
481 job_cfg = ""
482 etime = time.time() + timeout
483 while True:
484 wtime = etime - time.time()
485 if wtime <= 0:
486 raise IOError("No config provided")
487
488 r, w, x = select.select([fd], [], [], wtime)
489 if len(r) == 0:
490 raise IOError("No config provided")
491
492 char = fd.read(1)
493 if '' == char:
494 return job_cfg
495
496 job_cfg += char
497
498
koder aka kdanilov652cd802015-04-13 12:21:07 +0300499def sec_to_str(seconds):
500 h = seconds // 3600
501 m = (seconds % 3600) // 60
502 s = seconds % 60
503 return "{0}:{1:02d}:{2:02d}".format(h, m, s)
504
505
koder aka kdanilovda45e882015-04-06 02:24:42 +0300506def parse_args(argv):
507 parser = argparse.ArgumentParser(
508 description="Run fio' and return result")
509 parser.add_argument("--type", metavar="BINARY_TYPE",
510 choices=['fio'], default='fio',
511 help=argparse.SUPPRESS)
512 parser.add_argument("--start-at", metavar="START_AT_UTC", type=int,
513 help="Start execution at START_AT_UTC")
514 parser.add_argument("--json", action="store_true", default=False,
515 help="Json output format")
516 parser.add_argument("--output", default='-', metavar="FILE_PATH",
517 help="Store results to FILE_PATH")
518 parser.add_argument("--estimate", action="store_true", default=False,
519 help="Only estimate task execution time")
520 parser.add_argument("--compile", action="store_true", default=False,
521 help="Compile config file to fio config")
522 parser.add_argument("--num-tests", action="store_true", default=False,
523 help="Show total number of tests")
524 parser.add_argument("--runcycle", type=int, default=None,
525 metavar="MAX_CYCLE_SECONDS",
526 help="Max cycle length in seconds")
527 parser.add_argument("--show-raw-results", action='store_true',
528 default=False, help="Output raw input and results")
koder aka kdanilovda45e882015-04-06 02:24:42 +0300529 parser.add_argument("--params", nargs="*", metavar="PARAM=VAL",
530 default=[],
531 help="Provide set of pairs PARAM=VAL to" +
532 "format into job description")
533 parser.add_argument("jobfile")
534 return parser.parse_args(argv)
535
536
koder aka kdanilovda45e882015-04-06 02:24:42 +0300537def main(argv):
538 argv_obj = parse_args(argv)
539
540 if argv_obj.jobfile == '-':
541 job_cfg = read_config(sys.stdin)
542 else:
543 job_cfg = open(argv_obj.jobfile).read()
544
545 if argv_obj.output == '-':
546 out_fd = sys.stdout
547 else:
548 out_fd = open(argv_obj.output, "w")
549
550 params = {}
551 for param_val in argv_obj.params:
552 assert '=' in param_val
553 name, val = param_val.split("=", 1)
554 params[name] = val
555
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300556 slice_params = {
557 'runcycle': argv_obj.runcycle,
558 }
559
560 sliced_it = parse_and_slice_all_in_1(job_cfg, params, **slice_params)
561
koder aka kdanilov652cd802015-04-13 12:21:07 +0300562 if argv_obj.estimate:
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300563 it = map(calculate_execution_time, sliced_it)
564 print sec_to_str(sum(it))
koder aka kdanilov652cd802015-04-13 12:21:07 +0300565 return 0
566
567 if argv_obj.num_tests or argv_obj.compile:
koder aka kdanilovda45e882015-04-06 02:24:42 +0300568 if argv_obj.compile:
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300569 for test_slice in sliced_it:
570 out_fd.write(fio_config_to_str(test_slice))
571 out_fd.write("\n#" + "-" * 70 + "\n\n")
koder aka kdanilovda45e882015-04-06 02:24:42 +0300572
573 if argv_obj.num_tests:
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300574 print len(list(sliced_it))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300575
koder aka kdanilovda45e882015-04-06 02:24:42 +0300576 return 0
577
578 if argv_obj.start_at is not None:
579 ctime = time.time()
580 if argv_obj.start_at >= ctime:
581 time.sleep(ctime - argv_obj.start_at)
582
583 def raw_res_func(test_num, data):
584 pref = "========= RAW_RESULTS({0}) =========\n".format(test_num)
585 out_fd.write(pref)
586 out_fd.write(json.dumps(data))
587 out_fd.write("\n========= END OF RAW_RESULTS =========\n")
588 out_fd.flush()
589
590 rrfunc = raw_res_func if argv_obj.show_raw_results else None
591
592 stime = time.time()
koder aka kdanilov0c598a12015-04-21 03:01:40 +0300593 job_res, num_tests, ok = run_benchmark(argv_obj.type, sliced_it, rrfunc)
koder aka kdanilovda45e882015-04-06 02:24:42 +0300594 etime = time.time()
595
koder aka kdanilov652cd802015-04-13 12:21:07 +0300596 res = {'__meta__': {'raw_cfg': job_cfg, 'params': params}, 'res': job_res}
koder aka kdanilovda45e882015-04-06 02:24:42 +0300597
598 oformat = 'json' if argv_obj.json else 'eval'
koder aka kdanilov652cd802015-04-13 12:21:07 +0300599 out_fd.write("\nRun {0} tests in {1} seconds\n".format(num_tests,
600 int(etime - stime)))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300601 out_fd.write("========= RESULTS(format={0}) =========\n".format(oformat))
602 if argv_obj.json:
603 out_fd.write(json.dumps(res))
604 else:
605 out_fd.write(pprint.pformat(res) + "\n")
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300606 out_fd.write("\n========= END OF RESULTS =========\n")
koder aka kdanilovda45e882015-04-06 02:24:42 +0300607
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300608 return 0 if ok else 1
609
610
611def fake_main(x):
612 import yaml
613 time.sleep(60)
614 out_fd = sys.stdout
615 fname = "/tmp/perf_tests/metempirical_alisha/raw_results.yaml"
616 res = yaml.load(open(fname).read())[0][1]
617 out_fd.write("========= RESULTS(format=json) =========\n")
618 out_fd.write(json.dumps(res))
619 out_fd.write("\n========= END OF RESULTS =========\n")
koder aka kdanilovda45e882015-04-06 02:24:42 +0300620 return 0
621
622
623if __name__ == '__main__':
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +0300624 # exit(fake_main(sys.argv[1:]))
koder aka kdanilovda45e882015-04-06 02:24:42 +0300625 exit(main(sys.argv[1:]))