#!/usr/bin/env python3 """Run interleaved L77/L78 cold readiness pairs for the four owner strates.""" from __future__ import annotations import json import re import statistics import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l78/timing" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "before": ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-l77-clang", "after": ROOT / "Saved/Linux/l78/bin/VoxelForgeCoreHeadless-l78-clang-profile", } CAMERAS = { 0: (8.0, 16.0, -372.2626953125), 1: (25.8369140625, 3.19921875, -737.0), 2: (19.166015625, -14.2001953125, -753.3740234375), 3: (-20.0625, -5.068359375, -900.353515625), } PIPELINE = re.compile(r"^\[StreamPipeline\] (.*)$", re.M) FIELDS = re.compile(r"([a-zA-Z0-9_]+)=([^ ]+)") LOD_READY = re.compile( r"^\[WorldAssemblerL77LODReady\] lod=(\d+) tiles=(\d+) cold_ready_s=([0-9.]+)$", re.M, ) STAMP = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=(\S+)$", re.M) ORDERS = (("before", "after"), ("after", "before"), ("before", "after")) def run(strate: int, pair: int, mode: str) -> dict: OUT.mkdir(parents=True, exist_ok=True) log = OUT / f"strate{strate}-pair{pair}-{mode}.log" camera = ",".join(f"{value:.12f}" for value in CAMERAS[strate]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BINARIES[mode]), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--workers=8", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera}", "--profile-lod-work", "--linux77-profile", ] 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_match = PIPELINE.search(content) ready = {int(lod): {"tiles": int(tiles), "seconds": float(seconds)} for lod, tiles, seconds in LOD_READY.findall(content)} if result.returncode != 0 or pipeline_match is None or any(lod not in ready for lod in (0, 1, 2)): raise SystemExit(f"readiness run failed or LOD0-2 data missing: {log}; exit={result.returncode}") pipeline = dict(FIELDS.findall(pipeline_match.group(1))) row = { "strate": strate, "pair": pair, "mode": mode, "exit_code": result.returncode, "wall_s": round(time.monotonic() - started, 3), "lod02_ready_s": max(ready[lod]["seconds"] for lod in (0, 1, 2)), "lod_ready_s": {str(lod): ready[lod]["seconds"] for lod in sorted(ready)}, "whole_view_ready_s": float(pipeline["whole_view_ready"].removesuffix("s")), "whole_tiles": int(pipeline["whole_tiles"].split("/")[0]), "sampler": next((line for line in content.splitlines() if line.startswith("[L77Sampler] action=stop")), None), "source_stamp": STAMP.search(content).group(1) if STAMP.search(content) else None, "log": str(log.relative_to(ROOT)), } print("[L78TimingRun] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: missing = [str(path) for path in (DATA, *BINARIES.values()) if not path.is_file()] if missing: raise SystemExit("missing input: " + ", ".join(missing)) rows = [] for strate in range(4): for pair, order in enumerate(ORDERS, 1): paired = {} for mode in order: row = run(strate, pair, mode) rows.append(row) paired[mode] = row (OUT / "runs-partial.json").write_text( json.dumps(rows, indent=2) + "\n", encoding="utf-8") summary_row = { "strate": strate, "pair": pair, "before_lod02_s": paired["before"]["lod02_ready_s"], "after_lod02_s": paired["after"]["lod02_ready_s"], "before_whole_s": paired["before"]["whole_view_ready_s"], "after_whole_s": paired["after"]["whole_view_ready_s"], } print("[L78TimingPair] " + json.dumps(summary_row, sort_keys=True), flush=True) summary = [] for strate in range(4): group = [row for row in rows if row["strate"] == strate] before_near = [row["lod02_ready_s"] for row in group if row["mode"] == "before"] after_near = [row["lod02_ready_s"] for row in group if row["mode"] == "after"] before_whole = [row["whole_view_ready_s"] for row in group if row["mode"] == "before"] after_whole = [row["whole_view_ready_s"] for row in group if row["mode"] == "after"] summary.append({ "strate": strate, "pairs": len(before_near), "before_lod02_s": before_near, "after_lod02_s": after_near, "before_lod02_median_s": statistics.median(before_near), "after_lod02_median_s": statistics.median(after_near), "before_whole_s": before_whole, "after_whole_s": after_whole, "before_whole_median_s": statistics.median(before_whole), "after_whole_median_s": statistics.median(after_whole), }) result = {"runs": rows, "summary": summary} (OUT / "summary.json").write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())