#!/usr/bin/env python3 """Cold production-path samples and controls for Linux77.""" from __future__ import annotations import json import re import subprocess import sys import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l77" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "clean": ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-l76-clang", "clean_default": ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-l77-clean-clang", "l77_off": ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-l77-clang", "profile": ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-l77-clang", } CAMERAS = { "FI": (25.8369140625, 3.19921875, -737.0), "TN": (19.166015625, -14.2001953125, -753.3740234375), } KV = re.compile(r"([a-zA-Z0-9_]+)=([^ ]+)") PIPELINE = re.compile(r"^\[StreamPipeline\] (.*)$", re.M) STAMP = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=(\S+)$", re.M) def run(world: str, mode: str, replicate: int = 1) -> dict: camera = ",".join(f"{value:.12f}" for value in CAMERAS[world]) + ",0,0" name = f"{world.lower()}-{mode}-r{replicate}" log = OUT / f"{name}.log" 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", ] if mode == "profile": command.append("--linux77-profile") start = 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") match = PIPELINE.search(content) if result.returncode != 0 or match is None: raise SystemExit(f"run failed or summary missing: {name} exit={result.returncode}; see {log}") pipeline = dict(KV.findall(match.group(1))) row = { "world": world, "mode": mode, "replicate": replicate, "exit_code": result.returncode, "process_wall_s": round(time.monotonic() - start, 3), "whole_view_ready_s": float(pipeline["whole_view_ready"].removesuffix("s")), "stream_wall_s": float(pipeline["stream_wall"].removesuffix("s")), "whole_tiles": int(pipeline["whole_tiles"].split("/")[0]), "source_stamp": STAMP.search(content).group(1) if STAMP.search(content) else None, "sampler_samples": sum(1 for line in content.splitlines() if line.startswith("[L77Sample]")), "sampler_header": next((line for line in content.splitlines() if line.startswith("[L77Sampler] action=stop")), None), "log": str(log.relative_to(ROOT)), } print("[Linux77Run] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: OUT.mkdir(parents=True, exist_ok=True) missing = [str(path) for path in [DATA, *BINARIES.values()] if not path.is_file()] if missing: raise SystemExit("missing input: " + ", ".join(missing)) if len(sys.argv) > 1 and sys.argv[1] == "--clean-control": schedule = [("FI", "clean_default", 14), ("TN", "clean_default", 14), ("FI", "clean_default", 15), ("TN", "clean_default", 15)] output_name = "final-clean-runs2.json" else: schedule = [("FI", "profile", 12), ("TN", "profile", 12), ("FI", "profile", 13), ("TN", "profile", 13)] output_name = "final-runs3.json" rows = [run(*item) for item in schedule] (OUT / output_name).write_text( json.dumps(rows, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())