-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathgenerate_benchmark_report.py
More file actions
executable file
·184 lines (150 loc) · 5.74 KB
/
generate_benchmark_report.py
File metadata and controls
executable file
·184 lines (150 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python3
"""Generate benchmark report for GitHub Actions summary from JSON summaries."""
import argparse
import json
import urllib.parse
from pathlib import Path
from typing import Dict, List, Any
def find_latest_benchmark_results_file(search_dir: Path = None) -> Path:
"""Find the latest benchmark-results JSON file."""
if search_dir is None:
search_dir = Path("benchmark_summaries")
if not search_dir.exists():
raise FileNotFoundError(f"Directory not found: {search_dir}")
all_summaries = list(search_dir.glob("benchmark-results-*.json"))
if not all_summaries:
raise FileNotFoundError(f"No benchmark-results-*.json files found in {search_dir}")
# Sort by modification time, newest first
return max(all_summaries, key=lambda p: p.stat().st_mtime)
def generate_report_from_json(
json_file: Path,
branch_path: str = "",
perfetto_host: str = "https://perfetto.irreducible.com",
) -> str:
"""Generate complete benchmark report from a JSON summary file."""
output = []
if not json_file.exists():
output.append(f"JSON file not found: {json_file}")
return "\n".join(output)
with open(json_file) as f:
data = json.load(f)
if not data:
output.append("No data in summary file.")
return "\n".join(output)
# Auto-detect machine name from the data
machine = data[0].get("machine", "") if data else ""
if machine:
output.append(f"# Benchmark Report for {machine}")
output.append("")
# Generate metrics table
output.append("## 📈 Benchmark Metrics")
output.append("")
# Group by circuit
circuits: Dict[str, List[Dict[str, Any]]] = {}
for entry in data:
circuit = entry.get("circuit", "unknown")
if circuit not in circuits:
circuits[circuit] = []
circuits[circuit].append(entry)
for circuit in sorted(circuits.keys()):
output.append(f"### {circuit}")
# Show parameters if available
if params := circuits[circuit][0].get("parameters"):
output.append(f"**Parameters:** {params}")
output.append("")
output.append(
"| Config | Witness (ms) | Prove (ms) | Verify (ms) | Proof Size (bytes) | Traces |"
)
output.append(
"|--------|--------------|------------|-------------|-------------------|---------|"
)
# Sort for consistent display
entries = sorted(
circuits[circuit],
key=lambda x: (x.get("threading", "single"), not x.get("fusion", False)),
)
for entry in entries:
config = entry.get("threading", "single")
if entry.get("fusion"):
config += "-fusion"
witness = entry.get("avg_witness_ms", 0)
prove = entry.get("avg_prove_ms", 0)
verify = entry.get("avg_verify_ms", 0)
proof_size = entry.get("avg_proof_size_bytes", 0)
# Generate trace links for this entry
trace_files = entry.get("trace_files", [])
trace_links = []
if trace_files:
for i, trace_path in enumerate(trace_files, 1):
# Generate Perfetto URLs with provided branch path
s3_key = f"traces/binius64/{branch_path}/{trace_path}"
trace_url = f"{perfetto_host}/{s3_key}"
encoded_url = urllib.parse.quote_plus(trace_url)
perfetto_ui_url = f"{perfetto_host}/#!/?url={encoded_url}"
trace_links.append(f"[{i}]({perfetto_ui_url})")
trace_links_str = " ".join(trace_links) if trace_links else "—"
output.append(
f"| {config} | {witness:.2f} | {prove:.2f} | {verify:.2f} | {proof_size:.0f} | {trace_links_str} |"
)
output.append("")
return "\n".join(output)
def main():
parser = argparse.ArgumentParser(
description="Generate benchmark report from JSON summary file"
)
parser.add_argument(
"--json-file",
type=Path,
default=None,
help="Path to benchmark-results JSON file (auto-detects latest if not provided)",
)
parser.add_argument(
"--summaries-dir",
type=Path,
default=Path("benchmark_summaries"),
help="Directory to search for benchmark-results JSON files (default: benchmark_summaries)",
)
parser.add_argument(
"--branch-path",
type=str,
required=True,
help="S3 branch path for Perfetto links (e.g., 'main' or 'branch-feature')",
)
parser.add_argument(
"--perfetto-host",
type=str,
default="https://perfetto.irreducible.com",
help="Perfetto host URL",
)
parser.add_argument(
"--output", type=Path, default=None, help="Output file (default: stdout)"
)
args = parser.parse_args()
# Determine which JSON file to use
if args.json_file:
json_file = args.json_file
print(f"DEBUG: Using specified JSON file: {json_file}")
else:
try:
json_file = find_latest_benchmark_results_file(args.summaries_dir)
print(f"DEBUG: Auto-detected JSON file: {json_file}")
except FileNotFoundError as e:
print(f"DEBUG: Error finding JSON file: {e}")
return 1
# Generate the report
try:
report = generate_report_from_json(
json_file, args.branch_path, args.perfetto_host
)
except Exception as e:
print(f"Error generating report: {e}")
return 1
# Output the report
if args.output:
args.output.write_text(report)
print(f"Report written to {args.output}")
else:
print(report)
return 0
if __name__ == "__main__":
main()