#!/usr/bin/env python3 """Measure same-binary timing spread for one L80 owner view and worker count.""" from __future__ import annotations import json import re import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l175/timing/aa-control" DATA = ROOT / "Standalone/data/owner_world.json" BINARY = ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-l175-final-clang" CAMERA = "8.000000000000,16.000000000000,-372.262695312500,0,0" PIPELINE_RE = re.compile(r"^\[StreamPipeline\] (.*)$", re.M) FIELDS_RE = re.compile(r"([a-zA-Z0-9_]+)=([^ ]+)") NEAR_RE = re.compile( r"^\[WorldAssemblerNearLODReady\] lods=0-2 tiles=(\d+)/(\d+) " r"cold_ready_s=([0-9.]+)$", re.M) def run(label: str, phase: str, replicate: int) -> dict: log = OUT / f"{label}-{phase}{replicate}.log" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BINARY), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--seed=0", "--workers=8", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={CAMERA}", "--profile-lod-work", "--stream-scheduler-policy=3", ] started = time.monotonic() with log.open("w", encoding="utf-8") as output: result = subprocess.run(command, cwd=ROOT, stdout=output, stderr=subprocess.STDOUT, check=False, timeout=1740) content = log.read_text(encoding="utf-8", errors="replace") pipeline, near = PIPELINE_RE.search(content), NEAR_RE.search(content) if result.returncode or pipeline is None or near is None: raise RuntimeError(f"A/A timing run failed: {log}; exit={result.returncode}") fields = dict(FIELDS_RE.findall(pipeline.group(1))) row = { "label": label, "phase": phase, "replicate": replicate, "lod02_ready_s": float(near.group(3)), "whole_view_ready_s": float(fields["whole_view_ready"].removesuffix("s")), "wall_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT)), } print("[L175TimingAA] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: if not DATA.is_file() or not BINARY.is_file(): raise SystemExit("missing owner input or final Clang binary") OUT.mkdir(parents=True, exist_ok=True) rows = [run("warmup", "warmup", 0)] for replicate in range(1, 11): rows.append(run("same-binary", "measured", replicate)) (OUT / "runs-partial.json").write_text( json.dumps(rows, indent=2) + "\n", encoding="utf-8") summary = {} for key in ("lod02_ready_s", "whole_view_ready_s"): values = [row[key] for row in rows if row["phase"] == "measured"] summary[key] = {"values": values, "min": min(values), "max": max(values)} (OUT / "summary.json").write_text( json.dumps({"runs": rows, "summary": summary}, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())