2026-03-31 17:26:00 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
import json
|
|
|
|
|
from dataclasses import asdict
|
|
|
|
|
from datetime import date
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
2026-11-27 00:38:00 -08:00
|
|
|
from inire.tests.example_scenarios import capture_scenario_snapshots
|
2026-04-01 21:29:23 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _build_payload(
|
|
|
|
|
selected_scenarios: tuple[str, ...] | None = None,
|
|
|
|
|
*,
|
|
|
|
|
include_performance_only: bool = False,
|
|
|
|
|
) -> dict[str, object]:
|
2026-11-27 00:38:00 -08:00
|
|
|
snapshots = capture_scenario_snapshots(selected_scenarios, include_performance_only=include_performance_only)
|
2026-03-31 17:26:00 -07:00
|
|
|
return {
|
|
|
|
|
"generated_on": date.today().isoformat(),
|
|
|
|
|
"generator": "scripts/record_performance_baseline.py",
|
|
|
|
|
"scenarios": [asdict(snapshot) for snapshot in snapshots],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _render_markdown(payload: dict[str, object]) -> str:
|
|
|
|
|
rows = payload["scenarios"]
|
|
|
|
|
lines = [
|
|
|
|
|
"# Performance Baseline",
|
|
|
|
|
"",
|
|
|
|
|
f"Generated on {payload['generated_on']} by `{payload['generator']}`.",
|
|
|
|
|
"",
|
2026-11-26 21:37:05 -08:00
|
|
|
"The full machine-readable snapshot is in [performance_baseline.json](performance_baseline.json).",
|
2026-03-31 17:41:15 -07:00
|
|
|
"Use `scripts/diff_performance_baseline.py` to compare a fresh run against that snapshot.",
|
2026-03-31 17:26:00 -07:00
|
|
|
"",
|
2026-11-26 19:58:46 -08:00
|
|
|
"| Scenario | Duration (s) | Total | Valid | Reached | Iter | Nets Routed | Nodes | Ray Casts | "
|
2026-11-29 16:37:41 -08:00
|
|
|
"Moves Gen | Moves Added | Dyn Tree | Corner Index Builds | Congestion Checks | Verify Calls |",
|
2026-03-31 17:26:00 -07:00
|
|
|
"| :-- | --: | --: | --: | --: | --: | --: | --: | --: | --: | --: | --: | --: | --: | --: |",
|
|
|
|
|
]
|
|
|
|
|
for row in rows:
|
|
|
|
|
metrics = row["metrics"]
|
|
|
|
|
lines.append(
|
|
|
|
|
"| "
|
|
|
|
|
f"{row['name']} | "
|
|
|
|
|
f"{row['duration_s']:.4f} | "
|
|
|
|
|
f"{row['total_results']} | "
|
|
|
|
|
f"{row['valid_results']} | "
|
|
|
|
|
f"{row['reached_targets']} | "
|
|
|
|
|
f"{metrics['route_iterations']} | "
|
|
|
|
|
f"{metrics['nets_routed']} | "
|
|
|
|
|
f"{metrics['nodes_expanded']} | "
|
|
|
|
|
f"{metrics['ray_cast_calls']} | "
|
|
|
|
|
f"{metrics['moves_generated']} | "
|
|
|
|
|
f"{metrics['moves_added']} | "
|
|
|
|
|
f"{metrics['dynamic_tree_rebuilds']} | "
|
2026-11-29 16:37:41 -08:00
|
|
|
f"{metrics['visibility_corner_index_builds']} | "
|
2026-03-31 17:26:00 -07:00
|
|
|
f"{metrics['congestion_check_calls']} | "
|
|
|
|
|
f"{metrics['verify_path_report_calls']} |"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
lines.extend(
|
|
|
|
|
[
|
|
|
|
|
"",
|
|
|
|
|
"## Full Counter Set",
|
|
|
|
|
"",
|
2026-11-26 21:37:05 -08:00
|
|
|
"Each scenario entry in the JSON records the full `RouteMetrics` snapshot, "
|
2026-11-26 19:58:46 -08:00
|
|
|
"including cache, index, congestion, and verification counters.",
|
2026-03-31 17:41:15 -07:00
|
|
|
"These counters are currently observational only and are not enforced as CI regression gates.",
|
2026-03-31 17:26:00 -07:00
|
|
|
"",
|
|
|
|
|
"Tracked metric keys:",
|
|
|
|
|
"",
|
|
|
|
|
", ".join(rows[0]["metrics"].keys()) if rows else "",
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
return "\n".join(lines) + "\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
|
parser = argparse.ArgumentParser(description="Record the example-scenario performance baseline.")
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--output-dir",
|
|
|
|
|
type=Path,
|
|
|
|
|
default=None,
|
2026-11-26 21:37:05 -08:00
|
|
|
help="Directory to write performance_baseline.json and performance.md into. Defaults to <repo>/archive/routing.",
|
2026-03-31 17:26:00 -07:00
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--scenario",
|
|
|
|
|
action="append",
|
|
|
|
|
dest="scenarios",
|
|
|
|
|
default=[],
|
|
|
|
|
help="Optional scenario name to include. May be passed more than once.",
|
|
|
|
|
)
|
2026-04-01 21:29:23 -07:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--include-performance-only",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Include performance-only snapshot scenarios that are excluded from the default baseline corpus.",
|
|
|
|
|
)
|
2026-03-31 17:26:00 -07:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
repo_root = Path(__file__).resolve().parents[1]
|
2026-11-26 21:37:05 -08:00
|
|
|
output_dir = repo_root / "archive" / "routing" if args.output_dir is None else args.output_dir.resolve()
|
2026-03-31 17:26:00 -07:00
|
|
|
selected = tuple(args.scenarios) if args.scenarios else None
|
2026-12-02 17:16:34 -08:00
|
|
|
try:
|
|
|
|
|
payload = _build_payload(selected, include_performance_only=args.include_performance_only)
|
|
|
|
|
except ValueError as exc:
|
|
|
|
|
parser.error(str(exc))
|
|
|
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
2026-11-26 21:37:05 -08:00
|
|
|
json_path = output_dir / "performance_baseline.json"
|
|
|
|
|
markdown_path = output_dir / "performance.md"
|
2026-03-31 17:26:00 -07:00
|
|
|
|
|
|
|
|
json_path.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n")
|
|
|
|
|
markdown_path.write_text(_render_markdown(payload))
|
|
|
|
|
|
|
|
|
|
if json_path.is_relative_to(repo_root):
|
|
|
|
|
print(f"Wrote {json_path.relative_to(repo_root)}")
|
|
|
|
|
else:
|
|
|
|
|
print(f"Wrote {json_path}")
|
|
|
|
|
if markdown_path.is_relative_to(repo_root):
|
|
|
|
|
print(f"Wrote {markdown_path.relative_to(repo_root)}")
|
|
|
|
|
else:
|
|
|
|
|
print(f"Wrote {markdown_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|