#!/usr/bin/env python3 """Interleave L78/L79 owner-world readiness timings for all four 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/l79/timing" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "L78": ROOT / "Saved/Linux/l78/bin/VoxelForgeCoreHeadless-l78-clang-profile", "L79": ROOT / "Saved/Linux/l79/bin/VoxelForgeCoreHeadless-l79-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, ) NEAR_READY = re.compile( r"^\[WorldAssemblerNearLODReady\] lods=0-2 tiles=(\d+)/(\d+) cold_ready_s=([0-9.]+)$", re.M, ) ORDERS = (("L78", "L79"), ("L79", "L78"), ("L78", "L79")) 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)} near_match = NEAR_READY.search(content) if (result.returncode != 0 or pipeline_match is None or near_match is None or any(lod not in ready for lod in (0, 1, 2))): raise SystemExit(f"readiness run failed or 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": float(near_match.group(3)), "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), "log": str(log.relative_to(ROOT)), } print("[L79TimingRun] " + 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") print("[L79TimingPair] " + json.dumps({ "strate": strate, "pair": pair, "L78_lod02_s": paired["L78"]["lod02_ready_s"], "L79_lod02_s": paired["L79"]["lod02_ready_s"], "L78_whole_s": paired["L78"]["whole_view_ready_s"], "L79_whole_s": paired["L79"]["whole_view_ready_s"], }, sort_keys=True), flush=True) summary = [] for strate in range(4): group = [row for row in rows if row["strate"] == strate] summary.append({ "strate": strate, "pairs": 3, "L78_lod02_s": [row["lod02_ready_s"] for row in group if row["mode"] == "L78"], "L79_lod02_s": [row["lod02_ready_s"] for row in group if row["mode"] == "L79"], "L78_lod02_median_s": statistics.median( row["lod02_ready_s"] for row in group if row["mode"] == "L78"), "L79_lod02_median_s": statistics.median( row["lod02_ready_s"] for row in group if row["mode"] == "L79"), "L78_whole_s": [row["whole_view_ready_s"] for row in group if row["mode"] == "L78"], "L79_whole_s": [row["whole_view_ready_s"] for row in group if row["mode"] == "L79"], "L78_whole_median_s": statistics.median( row["whole_view_ready_s"] for row in group if row["mode"] == "L78"), "L79_whole_median_s": statistics.median( row["whole_view_ready_s"] for row in group if row["mode"] == "L79"), }) (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())