Parse C++ mttest output and return total ops/sec.
(filepath: Path)
| 17 | |
| 18 | |
| 19 | def parse_cpp_output(filepath: Path) -> Optional[float]: |
| 20 | """Parse C++ mttest output and return total ops/sec.""" |
| 21 | test_name = filepath.stem |
| 22 | |
| 23 | ops_per_sec_values = [] |
| 24 | puts_per_sec_values = [] |
| 25 | gets_per_sec_values = [] |
| 26 | |
| 27 | with open(filepath, "r") as f: |
| 28 | for line in f: |
| 29 | brace_idx = line.find("{") |
| 30 | if brace_idx == -1: |
| 31 | continue |
| 32 | try: |
| 33 | data = json.loads(line[brace_idx:]) |
| 34 | if data.get("test") != test_name: |
| 35 | continue |
| 36 | if "ops_per_sec" in data: |
| 37 | ops_per_sec_values.append(float(data["ops_per_sec"])) |
| 38 | if "puts_per_sec" in data: |
| 39 | puts_per_sec_values.append(float(data["puts_per_sec"])) |
| 40 | if "gets_per_sec" in data: |
| 41 | gets_per_sec_values.append(float(data["gets_per_sec"])) |
| 42 | except (json.JSONDecodeError, ValueError, KeyError): |
| 43 | continue |
| 44 | |
| 45 | if ops_per_sec_values: |
| 46 | return sum(ops_per_sec_values) |
| 47 | elif puts_per_sec_values: |
| 48 | return sum(puts_per_sec_values) |
| 49 | elif gets_per_sec_values: |
| 50 | return sum(gets_per_sec_values) |
| 51 | return None |
| 52 | |
| 53 | |
| 54 | def parse_rust_output(filepath: Path) -> Optional[float]: |