koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import re |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 4 | import os |
| 5 | import sys |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 6 | import os.path |
| 7 | import argparse |
| 8 | import itertools |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 9 | from typing import Optional, Iterator, Union, Dict, Iterable, List, Tuple, NamedTuple, Any |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 10 | from collections import OrderedDict |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 11 | |
kdanylov aka koder | 026e5f2 | 2017-05-15 01:04:39 +0300 | [diff] [blame] | 12 | from cephlib.units import ssize2b |
| 13 | from cephlib.common import flatmap, sec_to_str |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 14 | |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 15 | from .fio_job import Var, FioJobConfig |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 16 | |
| 17 | SECTION = 0 |
| 18 | SETTING = 1 |
| 19 | INCLUDE = 2 |
| 20 | |
| 21 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 22 | CfgLine = NamedTuple('CfgLine', |
| 23 | [('fname', str), |
| 24 | ('lineno', int), |
| 25 | ('oline', str), |
| 26 | ('tp', int), |
| 27 | ('name', str), |
| 28 | ('val', Any)]) |
koder aka kdanilov | 7f59d56 | 2016-12-26 01:34:23 +0200 | [diff] [blame] | 29 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 30 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 31 | class ParseError(ValueError): |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 32 | def __init__(self, msg: str, fname: str, lineno: int, line_cont:Optional[str] = "") -> None: |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 33 | ValueError.__init__(self, msg) |
| 34 | self.file_name = fname |
| 35 | self.lineno = lineno |
| 36 | self.line_cont = line_cont |
| 37 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 38 | def __str__(self) -> str: |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 39 | msg = "In {0}:{1} ({2}) : {3}" |
| 40 | return msg.format(self.file_name, |
| 41 | self.lineno, |
| 42 | self.line_cont, |
| 43 | super(ParseError, self).__str__()) |
| 44 | |
| 45 | |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 46 | def is_name(name: str) -> bool: |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 47 | return re.match("[a-zA-Z_][a-zA-Z_0-9]*", name) is not None |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 48 | |
| 49 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 50 | def parse_value(val: str) -> Union[int, str, float, List, Var]: |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 51 | try: |
| 52 | return int(val) |
| 53 | except ValueError: |
| 54 | pass |
| 55 | |
| 56 | try: |
| 57 | return float(val) |
| 58 | except ValueError: |
| 59 | pass |
| 60 | |
| 61 | if val.startswith('{%'): |
| 62 | assert val.endswith("%}") |
| 63 | content = val[2:-2] |
| 64 | vals = list(i.strip() for i in content.split(',')) |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 65 | return list(map(parse_value, vals)) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 66 | |
| 67 | if val.startswith('{'): |
| 68 | assert val.endswith("}") |
| 69 | assert is_name(val[1:-1]) |
| 70 | return Var(val[1:-1]) |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 71 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 72 | return val |
| 73 | |
| 74 | |
koder aka kdanilov | 22d134e | 2016-11-08 11:33:19 +0200 | [diff] [blame] | 75 | def fio_config_lexer(fio_cfg: str, fname: str) -> Iterator[CfgLine]: |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 76 | for lineno, oline in enumerate(fio_cfg.split("\n")): |
| 77 | try: |
| 78 | line = oline.strip() |
| 79 | |
| 80 | if line.startswith("#") or line.startswith(";"): |
| 81 | continue |
| 82 | |
| 83 | if line == "": |
| 84 | continue |
| 85 | |
| 86 | if '#' in line: |
| 87 | raise ParseError("# isn't allowed inside line", |
| 88 | fname, lineno, oline) |
| 89 | |
| 90 | if line.startswith('['): |
kdanylov aka koder | 026e5f2 | 2017-05-15 01:04:39 +0300 | [diff] [blame] | 91 | yield CfgLine(fname, lineno, oline, SECTION, line[1:-1].strip(), None) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 92 | elif '=' in line: |
| 93 | opt_name, opt_val = line.split('=', 1) |
kdanylov aka koder | 026e5f2 | 2017-05-15 01:04:39 +0300 | [diff] [blame] | 94 | yield CfgLine(fname, lineno, oline, SETTING, opt_name.strip(), parse_value(opt_val.strip())) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 95 | elif line.startswith("include "): |
kdanylov aka koder | 026e5f2 | 2017-05-15 01:04:39 +0300 | [diff] [blame] | 96 | yield CfgLine(fname, lineno, oline, INCLUDE, line.split(" ", 1)[1], None) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 97 | else: |
| 98 | yield CfgLine(fname, lineno, oline, SETTING, line, '1') |
| 99 | |
| 100 | except Exception as exc: |
| 101 | raise ParseError(str(exc), fname, lineno, oline) |
| 102 | |
| 103 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 104 | def fio_config_parse(lexer_iter: Iterable[CfgLine]) -> Iterator[FioJobConfig]: |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 105 | in_globals = False |
| 106 | curr_section = None |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 107 | glob_vals = OrderedDict() # type: Dict[str, Any] |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 108 | sections_count = 0 |
| 109 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 110 | lexed_lines = list(lexer_iter) # type: List[CfgLine] |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 111 | one_more = True |
| 112 | includes = {} |
| 113 | |
| 114 | while one_more: |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 115 | new_lines = [] # type: List[CfgLine] |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 116 | one_more = False |
| 117 | for line in lexed_lines: |
| 118 | fname, lineno, oline, tp, name, val = line |
| 119 | |
| 120 | if INCLUDE == tp: |
| 121 | if not os.path.exists(fname): |
| 122 | dirname = '.' |
| 123 | else: |
| 124 | dirname = os.path.dirname(fname) |
| 125 | |
| 126 | new_fname = os.path.join(dirname, name) |
| 127 | includes[new_fname] = (fname, lineno) |
| 128 | |
| 129 | try: |
| 130 | cont = open(new_fname).read() |
| 131 | except IOError as err: |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 132 | raise ParseError("Error while including file {}: {}".format(new_fname, err), fname, lineno, oline) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 133 | |
| 134 | new_lines.extend(fio_config_lexer(cont, new_fname)) |
| 135 | one_more = True |
| 136 | else: |
| 137 | new_lines.append(line) |
| 138 | |
| 139 | lexed_lines = new_lines |
| 140 | |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 141 | suite_section_idx = 0 |
| 142 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 143 | for fname, lineno, oline, tp, name, val in lexed_lines: |
| 144 | if tp == SECTION: |
| 145 | if curr_section is not None: |
| 146 | yield curr_section |
| 147 | curr_section = None |
| 148 | |
| 149 | if name == 'global': |
| 150 | if sections_count != 0: |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 151 | raise ParseError("[global] section should be only one and first", fname, lineno, oline) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 152 | in_globals = True |
| 153 | else: |
| 154 | in_globals = False |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 155 | curr_section = FioJobConfig(name, idx=suite_section_idx) |
| 156 | suite_section_idx += 1 |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 157 | curr_section.vals = glob_vals.copy() |
| 158 | sections_count += 1 |
| 159 | else: |
| 160 | assert tp == SETTING |
| 161 | if in_globals: |
| 162 | glob_vals[name] = val |
| 163 | elif name == name.upper(): |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 164 | raise ParseError("Param {!r} not in [global] section".format(name), fname, lineno, oline) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 165 | elif curr_section is None: |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 166 | raise ParseError("Data outside section", fname, lineno, oline) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 167 | else: |
| 168 | curr_section.vals[name] = val |
| 169 | |
| 170 | if curr_section is not None: |
| 171 | yield curr_section |
| 172 | |
| 173 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 174 | def process_cycles(sec: FioJobConfig) -> Iterator[FioJobConfig]: |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 175 | cycles = OrderedDict() # type: Dict[str, Any] |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 176 | |
| 177 | for name, val in sec.vals.items(): |
| 178 | if isinstance(val, list) and name.upper() != name: |
| 179 | cycles[name] = val |
| 180 | |
| 181 | if len(cycles) == 0: |
| 182 | yield sec |
| 183 | else: |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 184 | # iodepth should changes faster |
| 185 | numjobs = cycles.pop('iodepth', None) |
| 186 | items = list(cycles.items()) |
koder aka kdanilov | 170936a | 2015-06-27 22:51:17 +0300 | [diff] [blame] | 187 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 188 | if items: |
koder aka kdanilov | 170936a | 2015-06-27 22:51:17 +0300 | [diff] [blame] | 189 | keys, vals = zip(*items) |
| 190 | keys = list(keys) |
| 191 | vals = list(vals) |
| 192 | else: |
| 193 | keys = [] |
| 194 | vals = [] |
| 195 | |
| 196 | if numjobs is not None: |
| 197 | vals.append(numjobs) |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 198 | keys.append('iodepth') |
koder aka kdanilov | 170936a | 2015-06-27 22:51:17 +0300 | [diff] [blame] | 199 | |
| 200 | for combination in itertools.product(*vals): |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 201 | new_sec = sec.copy() |
koder aka kdanilov | 170936a | 2015-06-27 22:51:17 +0300 | [diff] [blame] | 202 | new_sec.vals.update(zip(keys, combination)) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 203 | yield new_sec |
| 204 | |
| 205 | |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 206 | FioParamsVal = Union[str, Var] |
| 207 | FioParams = Dict[str, FioParamsVal] |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 208 | |
| 209 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 210 | def apply_params(sec: FioJobConfig, params: FioParams) -> FioJobConfig: |
koder aka kdanilov | 7022706 | 2016-11-26 23:23:21 +0200 | [diff] [blame] | 211 | processed_vals = OrderedDict() # type: Dict[str, Any] |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 212 | processed_vals.update(params) |
kdanylov aka koder | 84de1e4 | 2017-05-22 14:00:07 +0300 | [diff] [blame^] | 213 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 214 | for name, val in sec.vals.items(): |
| 215 | if name in params: |
| 216 | continue |
| 217 | |
| 218 | if isinstance(val, Var): |
| 219 | if val.name in params: |
| 220 | val = params[val.name] |
| 221 | elif val.name in processed_vals: |
| 222 | val = processed_vals[val.name] |
| 223 | processed_vals[name] = val |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 224 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 225 | sec = sec.copy() |
| 226 | sec.vals = processed_vals |
| 227 | return sec |
| 228 | |
| 229 | |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 230 | def abbv_name_to_full(name: str) -> str: |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 231 | assert len(name) == 3 |
| 232 | |
| 233 | smode = { |
| 234 | 'a': 'async', |
| 235 | 's': 'sync', |
| 236 | 'd': 'direct', |
| 237 | 'x': 'sync direct' |
| 238 | } |
| 239 | off_mode = {'s': 'sequential', 'r': 'random'} |
koder aka kdanilov | 7248c7b | 2015-05-31 22:53:03 +0300 | [diff] [blame] | 240 | oper = {'r': 'read', 'w': 'write', 'm': 'mixed'} |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 241 | return smode[name[2]] + " " + \ |
| 242 | off_mode[name[0]] + " " + oper[name[1]] |
| 243 | |
| 244 | |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 245 | MAGIC_OFFSET = 0.1885 |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 246 | |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 247 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 248 | def final_process(sec: FioJobConfig, counter: List[int] = [0]) -> FioJobConfig: |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 249 | sec = sec.copy() |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 250 | |
| 251 | sec.vals['unified_rw_reporting'] = '1' |
| 252 | |
koder aka kdanilov | bb6d6cd | 2015-06-20 02:55:07 +0300 | [diff] [blame] | 253 | if isinstance(sec.vals['size'], Var): |
| 254 | raise ValueError("Variable {0} isn't provided".format( |
| 255 | sec.vals['size'].name)) |
| 256 | |
koder aka kdanilov | 88407ff | 2015-05-26 15:35:57 +0300 | [diff] [blame] | 257 | sz = ssize2b(sec.vals['size']) |
| 258 | offset = sz * ((MAGIC_OFFSET * counter[0]) % 1.0) |
| 259 | offset = int(offset) // 1024 ** 2 |
| 260 | new_vars = {'UNIQ_OFFSET': str(offset) + "m"} |
| 261 | |
| 262 | for name, val in sec.vals.items(): |
| 263 | if isinstance(val, Var): |
| 264 | if val.name in new_vars: |
| 265 | sec.vals[name] = new_vars[val.name] |
| 266 | |
koder aka kdanilov | bb6d6cd | 2015-06-20 02:55:07 +0300 | [diff] [blame] | 267 | for vl in sec.vals.values(): |
| 268 | if isinstance(vl, Var): |
| 269 | raise ValueError("Variable {0} isn't provided".format(vl.name)) |
| 270 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 271 | params = sec.vals.copy() |
| 272 | params['UNIQ'] = 'UN{0}'.format(counter[0]) |
| 273 | params['COUNTER'] = str(counter[0]) |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 274 | params['TEST_SUMM'] = sec.summary |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 275 | sec.name = sec.name.format(**params) |
| 276 | counter[0] += 1 |
| 277 | |
| 278 | return sec |
| 279 | |
| 280 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 281 | def execution_time(sec: FioJobConfig) -> int: |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 282 | return sec.vals.get('ramp_time', 0) + sec.vals.get('runtime', 0) |
| 283 | |
| 284 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 285 | def parse_all_in_1(source:str, fname: str = None) -> Iterator[FioJobConfig]: |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 286 | return fio_config_parse(fio_config_lexer(source, fname)) |
| 287 | |
| 288 | |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 289 | def get_log_files(sec: FioJobConfig, iops: bool = False) -> Iterator[Tuple[str, str, str]]: |
| 290 | res = [] # type: List[Tuple[str, str, str]] |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 291 | |
kdanylov aka koder | 4518318 | 2017-04-30 23:55:40 +0300 | [diff] [blame] | 292 | keys = [('write_bw_log', 'bw', 'KiBps'), |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 293 | ('write_hist_log', 'lat', 'us')] |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 294 | if iops: |
kdanylov aka koder | 4518318 | 2017-04-30 23:55:40 +0300 | [diff] [blame] | 295 | keys.append(('write_iops_log', 'iops', 'IOPS')) |
koder aka kdanilov | 108ac36 | 2017-01-19 20:17:16 +0200 | [diff] [blame] | 296 | |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 297 | for key, name, units in keys: |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 298 | log = sec.vals.get(key) |
| 299 | if log is not None: |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 300 | yield (name, log, units) |
koder aka kdanilov | bbbe1dc | 2016-12-20 01:19:56 +0200 | [diff] [blame] | 301 | |
| 302 | |
koder aka kdanilov | f286517 | 2016-12-30 03:35:11 +0200 | [diff] [blame] | 303 | def fio_cfg_compile(source: str, fname: str, test_params: FioParams) -> Iterator[FioJobConfig]: |
kdanylov aka koder | 84de1e4 | 2017-05-22 14:00:07 +0300 | [diff] [blame^] | 304 | test_params = test_params.copy() |
| 305 | |
| 306 | if 'RAMPTIME' not in test_params and 'RUNTIME' in test_params: |
| 307 | ramp = int(int(test_params['RUNTIME']) * 0.05) |
| 308 | test_params['RAMPTIME'] = min(30, max(5, ramp)) |
| 309 | |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 310 | it = parse_all_in_1(source, fname) |
| 311 | it = (apply_params(sec, test_params) for sec in it) |
| 312 | it = flatmap(process_cycles, it) |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 313 | for sec in map(final_process, it): |
koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 314 | yield sec |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 315 | |
| 316 | |
| 317 | def parse_args(argv): |
| 318 | parser = argparse.ArgumentParser( |
| 319 | description="Run fio' and return result") |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 320 | parser.add_argument("-p", "--params", nargs="*", metavar="PARAM=VAL", |
| 321 | default=[], |
| 322 | help="Provide set of pairs PARAM=VAL to" + |
| 323 | "format into job description") |
| 324 | parser.add_argument("action", choices=['estimate', 'compile', 'num_tests']) |
| 325 | parser.add_argument("jobfile") |
| 326 | return parser.parse_args(argv) |
| 327 | |
| 328 | |
| 329 | def main(argv): |
| 330 | argv_obj = parse_args(argv) |
| 331 | |
| 332 | if argv_obj.jobfile == '-': |
| 333 | job_cfg = sys.stdin.read() |
| 334 | else: |
| 335 | job_cfg = open(argv_obj.jobfile).read() |
| 336 | |
| 337 | params = {} |
| 338 | for param_val in argv_obj.params: |
| 339 | assert '=' in param_val |
| 340 | name, val = param_val.split("=", 1) |
| 341 | params[name] = parse_value(val) |
| 342 | |
koder aka kdanilov | f236b9c | 2015-06-24 18:17:22 +0300 | [diff] [blame] | 343 | sec_it = fio_cfg_compile(job_cfg, argv_obj.jobfile, params) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 344 | |
| 345 | if argv_obj.action == 'estimate': |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 346 | print(sec_to_str(sum(map(execution_time, sec_it)))) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 347 | elif argv_obj.action == 'num_tests': |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 348 | print(sum(map(len, map(list, sec_it)))) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 349 | elif argv_obj.action == 'compile': |
| 350 | splitter = "\n#" + "-" * 70 + "\n\n" |
koder aka kdanilov | 3b4da8b | 2016-10-17 00:17:53 +0300 | [diff] [blame] | 351 | print(splitter.join(map(str, sec_it))) |
koder aka kdanilov | 4af1c1d | 2015-05-18 15:48:58 +0300 | [diff] [blame] | 352 | |
| 353 | return 0 |
| 354 | |
| 355 | |
| 356 | if __name__ == '__main__': |
| 357 | exit(main(sys.argv[1:])) |