|
6 | 6 | parser = argparse.ArgumentParser(description="Analyze benchmark JSON data.") |
7 | 7 | parser.add_argument("--json", type=Path, default=Path("client_ivc_bench.json"), help="Benchmark JSON file name.") |
8 | 8 | parser.add_argument("--benchmark", type=str, default="ClientIVCBench/Full/6", help="Benchmark name to analyze.") |
9 | | -parser.add_argument("--prefix", type=Path, default=Path("build-op-count-time"), help="Prefix path for benchmark files.") |
| 9 | +parser.add_argument("--prefix", type=Path, default=Path("build"), help="Prefix path for benchmark files.") |
10 | 10 | args = parser.parse_args() |
11 | 11 |
|
12 | 12 | IVC_BENCH_JSON = args.json |
|
30 | 30 |
|
31 | 31 | with open(PREFIX / IVC_BENCH_JSON, "r") as read_file: |
32 | 32 | read_result = json.load(read_file) |
33 | | - for _bench in read_result["benchmarks"]: |
34 | | - if _bench["name"] == BENCHMARK or BENCHMARK == "": |
| 33 | + for _bench in read_result.get("benchmarks", [read_result]): |
| 34 | + if BENCHMARK == "" or _bench["name"] == BENCHMARK: |
35 | 35 | bench = _bench |
36 | 36 |
|
37 | 37 | bench_components = dict(filter(lambda x: x[0] in to_keep, bench.items())) |
|
51 | 51 | time_ms = bench[key] / 1e6 |
52 | 52 | print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}") |
53 | 53 |
|
54 | | -# Validate that kept times account for most of the total measured time. |
55 | | -total_time_ms = bench["real_time"] |
56 | | -totals = '\nTotal time accounted for: {:.0f}ms/{:.0f}ms = {:.2%}' |
57 | | -totals = totals.format( |
58 | | - sum_of_kept_times_ms, total_time_ms, sum_of_kept_times_ms/total_time_ms) |
59 | | -print(totals) |
| 54 | +# There may not be "real_time" if this is from bb cli. |
| 55 | +if "real_time" in bench: |
| 56 | + # Validate that kept times account for most of the total measured time. |
| 57 | + total_time_ms = bench["real_time"] |
| 58 | + totals = '\nTotal time accounted for: {:.0f}ms/{:.0f}ms = {:.2%}' |
| 59 | + totals = totals.format( |
| 60 | + sum_of_kept_times_ms, total_time_ms, sum_of_kept_times_ms/total_time_ms) |
| 61 | + print(totals) |
60 | 62 |
|
61 | 63 | print("\nMajor contributors:") |
62 | 64 | print( |
@@ -91,7 +93,7 @@ def print_contributions(prefix, ivc_bench_json, bench_name, components): |
91 | 93 | try: |
92 | 94 | with open(prefix / ivc_bench_json, "r") as read_file: |
93 | 95 | read_result = json.load(read_file) |
94 | | - bench = next((_bench for _bench in read_result["benchmarks"] if _bench["name"] == bench_name or bench_name == ""), None) |
| 96 | + bench = next((_bench for _bench in read_result.get("benchmarks", [read_result]) if bench_name == "" or _bench["name"] == bench_name), None) |
95 | 97 | if not bench: |
96 | 98 | raise ValueError(f"Benchmark '{bench_name}' not found in the JSON file.") |
97 | 99 | except FileNotFoundError: |
|
0 commit comments