#!/usr/bin/env python3 """Count pre-change Floating Islands cache calls from L137 binaries.""" from __future__ import annotations import json import re import subprocess from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l138/prechange/island-cache" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "assembler-world": ( ROOT / "Saved/Linux/l137/profile-bin/VoxelForgeCoreHeadless-l137-profile-base", "4499fb2a8a4ede7d6cbc68d1b794f104658cdaae93ed9cacbc91fe7ff3fc3621"), "l137": ( ROOT / "Saved/Linux/l137/profile-bin/VoxelForgeCoreHeadless-l137-profile-head", "dcf2ffa55fd6d62b3c7faf76229c3b99c635868dc1b694fc6e8f39e738775a4e"), } CAMERAS = { 1: (25.8369140625, 3.19921875, -737.0), } STAMP = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=([0-9a-f]+)$", re.M) TILE = re.compile(r"^\[CpuTileStages\] key=\([^)]*,lod(\d+)\).*", re.M) FIELDS = re.compile(r"([a-zA-Z0-9_]+)=([^ ]+)") CACHE_FIELDS = ( "fi_local_hit", "fi_local_miss", "fi_local_conflicts", "fi_shared_hit", "fi_shared_miss", "fi_shared_computes", "fi_shared_conflicts", ) def main() -> int: OUT.mkdir(parents=True, exist_ok=True) rows = [] for workers in (8, 12): for version, (binary, expected_stamp) in BINARIES.items(): camera = ",".join(f"{value:.12f}" for value in CAMERAS[1]) + ",0,0" log = OUT / f"s1-w{workers}-{version}.log" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(binary), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", f"--workers={workers}", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera}", "--profile-lod-work", "--profile-passage-composer", "--stream-scheduler-policy=3", ] with log.open("w", encoding="utf-8") as output: proc = subprocess.run(command, cwd=ROOT, stdout=output, stderr=subprocess.STDOUT, check=False, timeout=1740) text = log.read_text(encoding="utf-8", errors="replace") stamp = STAMP.search(text) if proc.returncode or not stamp or stamp.group(1) != expected_stamp: raise SystemExit(f"pre-change cache census failed: {log}") tiles = [] for line in text.splitlines(): match = TILE.match(line) if not match or int(match.group(1)) > 2: continue fields = dict(FIELDS.findall(line)) tiles.append({key: int(fields.get(key, "0")) for key in CACHE_FIELDS}) if not tiles: raise SystemExit(f"no LOD0-2 tile-cache counters in {log}") total = {key: sum(tile[key] for tile in tiles) for key in CACHE_FIELDS} row = { "strate": 1, "workers": workers, "version": version, "source_stamp": stamp.group(1), "tiles": len(tiles), "totals": total, "per_tile": {key: value / len(tiles) for key, value in total.items()}, "logs": str(log.relative_to(ROOT)), } rows.append(row) print("[L138PrechangeIslandCache] " + json.dumps(row, sort_keys=True), flush=True) (OUT / "summary.json").write_text(json.dumps(rows, indent=2) + "\n") return 0 if __name__ == "__main__": raise SystemExit(main())