#!/usr/bin/env python3 """Count bounded-sweep candidates, outside-volume rejects, and cache lookups.""" 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/l99/sweep-counts" DATA = ROOT / "Standalone/data/owner_world.json" HEADLESS = ROOT / "Saved/Linux/l99/bin/VoxelForgeCoreHeadless-l99-clang" CAMERAS = { "SW": (8.0, 16.0, -372.2626953125), "FI": (25.8369140625, 3.19921875, -737.0), "TN": (19.166015625, -14.2001953125, -753.3740234375), "VS": (-20.0625, -5.068359375, -900.353515625), } LINE = re.compile(r"^\[PassageComposerTile\] key=\([^,]+,[^,]+,[^,]+,lod(\d+)\) (.*)$", re.M) FIELDS = re.compile(r"([a-zA-Z0-9_]+)=([^ ]+)") COUNT_KEYS = ( "route_candidates", "sweep_segments", "sweep_pairs", "sweep_outside_pairs", "sweep_min_updates", "sweep_base_samples", "sweep_detail_samples", "sweep_grid_samples", "sweep_no_influence_samples", "sweep_lookups", "sweep_cache_hits", "sweep_base_hits", "sweep_outside_hits", "sweep_missing", ) def run(strate: str) -> dict: OUT.mkdir(parents=True, exist_ok=True) log = OUT / f"profile-sweep-{strate.lower()}.log" camera = ",".join(f"{value:.12f}" for value in CAMERAS[strate]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(HEADLESS), 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-passage-composer", ] start = time.monotonic() with log.open("w", encoding="utf-8") as stream: result = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1740) output = log.read_text(encoding="utf-8", errors="replace") if result.returncode != 0: raise RuntimeError(f"sweep count run failed: exit={result.returncode} {log}") rows = [] for level_text, tail in LINE.findall(output): level = int(level_text) if level > 2: continue fields = dict(FIELDS.findall(tail)) rows.append({"lod": level, **{key: int(fields.get(key, 0)) for key in COUNT_KEYS}}) if not rows: raise RuntimeError(f"no profiled near-set passage tiles: {log}") totals = {key: sum(row[key] for row in rows) for key in COUNT_KEYS} row = { "strate": strate, "workers": 8, "near_profiled_tiles": len(rows), "near_tiles_by_lod": {str(level): sum(1 for item in rows if item["lod"] == level) for level in range(3)}, "counters": totals, "wall_s": round(time.monotonic() - start, 3), "log": str(log.relative_to(ROOT)), } print("[L99SweepCounts] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: rows = [run(strate) for strate in CAMERAS] (OUT / "summary.json").write_text(json.dumps({"runs": rows}, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())