#!/usr/bin/env python3 """Find active LOD0/1 passage tiles in each owner stratum.""" 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/l80/passage-census" DATA = ROOT / "Standalone/data/owner_world.json" BINARY = ROOT / "Saved/Linux/l79/bin/VoxelForgeCoreHeadless-l79-final" 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), } TILE = re.compile(r"^\[PassageComposerTile\] (.*)$", re.M) FIELD = re.compile(r"([a-zA-Z0-9_]+)=([^ ]+)") KEY = re.compile(r"key=\((-?\d+),(-?\d+),(-?\d+),lod(\d+)\)") def run(strate: int, camera: tuple[float, float, float]) -> dict: log = OUT / f"strate{strate}.log" camera_arg = ",".join(f"{v:.12f}" for v in camera) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BINARY), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--workers=8", "--clip-radius=3", "--max-clip-level=8", "--max-level=1", f"--camera={camera_arg}", "--profile-lod-work", "--profile-passage-composer", ] start = time.monotonic() with log.open("w", encoding="utf-8") as out: proc = subprocess.run(command, cwd=ROOT, stdout=out, stderr=subprocess.STDOUT, check=False, timeout=1740) text = log.read_text(encoding="utf-8", errors="replace") rows = [] for match in TILE.finditer(text): row = dict(FIELD.findall(match.group(1))) for name, value in tuple(row.items()): try: row[name] = int(value) if name not in {"worker_ms"} else float(value) except ValueError: pass key = KEY.search(match.group(1)) if key: row["coord"] = [int(key.group(i)) for i in range(1, 4)] row["lod"] = int(key.group(4)) row["strate"] = strate rows.append(row) summary = next((line for line in text.splitlines() if line.startswith("[StreamPipeline] ")), None) result = {"strate": strate, "exit_code": proc.returncode, "wall_s": round(time.monotonic() - start, 3), "profiled_tiles": len(rows), "log": str(log.relative_to(ROOT)), "summary": summary, "tiles": rows} print("[L80PassageCensus] " + json.dumps( {k: v for k, v in result.items() if k != "tiles"}, sort_keys=True), flush=True) if proc.returncode or not rows: raise SystemExit(f"census failed or emitted no tile rows: {log} exit={proc.returncode}") return result def main() -> int: OUT.mkdir(parents=True, exist_ok=True) runs = [run(i, CAMERAS[i]) for i in range(4)] tiles = [tile for result in runs for tile in result["tiles"]] categories = { "mouth": "mouth_route_segment_checks", "route_body": "carve_segment_visits", "support": "support_segment_visits", } leaders = {} for strate in range(4): for lod in (0, 1): for category, metric in categories.items(): candidates = [tile for tile in tiles if tile["strate"] == strate and tile["lod"] == lod and tile.get(metric, 0) > 0] candidates.sort(key=lambda x: (x.get(metric, 0), x.get("worker_ms", 0)), reverse=True) leaders[f"s{strate}-l{lod}-{category}"] = candidates[:2] payload = {"runs": [{k: v for k, v in r.items() if k != "tiles"} for r in runs], "profiled_tile_count": len(tiles), "tiles": tiles, "leaders": leaders} (OUT / "summary.json").write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())