#!/usr/bin/env python3 """Capture five 30 m/s UE runs with admission-reason tracing enabled.""" from __future__ import annotations import json import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] HOST = Path("/home/jahni/VFHost") EDITOR = Path("/home/jahni/UnrealEngine/Engine/Binaries/Linux/UnrealEditor-Cmd") OUT = ROOT / "Saved/Linux/l122/diagnostic/unreal" HOST_OUT = HOST / "Plugins/VoxelForge/Saved/Linux/l122/diagnostic" HOST_SAVED = HOST / "Saved/Linux/l122" SPAWN_M = (19.166015625, -14.2001953125, -753.3740234375) def run(repetition: int) -> dict: trace = OUT / f"fast-r{repetition}.trace.jsonl" abslog = OUT / f"fast-r{repetition}.log" stdout = OUT / f"fast-r{repetition}.stdout.log" export = HOST_OUT / f"fast-r{repetition}" userdir = HOST_SAVED / "user" / f"fast-r{repetition}" zendata = HOST_SAVED / "zen" / f"fast-r{repetition}" ddc = HOST_SAVED / "DDC" for path in (export, userdir, zendata, ddc): path.mkdir(parents=True, exist_ok=True) spawn_cm = ",".join(f"{value * 100.0:.3f}" for value in SPAWN_M) command = [ str(EDITOR), str(HOST / "VFHost.uproject"), "-nullrhi", "-unattended", "-nop4", "-nosplash", "-NoSound", "-corelimit=12", "-NoZenAutoLaunch", "-notraceserver", "-nocrashreports", "-DisablePlugins=AndroidFileServer", "-ddc=NoZenLocalFallback", f"-userdir={userdir}", f"-ZenDataPath={zendata}", f"-LocalDataCachePath={ddc}", "-run=VoxelForgeExplore", "-seed=0", "-archetype=TunnelNetwork", "-slot=0", "-modes=export", "-gameconfig=1", "-coreworldtest=1", "-ownerfourstrateplan=1", "-corevoxelsizecm=25", "-coreislandtest=0", "-corefallbacktest=0", "-coreofftest=0", "-coreplantest=0", "-settingsref=/Game/VoxelForge/DA_Settings.DA_Settings", "-corehybridmesher=0", f"-out={export}", "-voxel.StreamingCoarseFirst=1", "-voxel.StreamingDynamicNearReserve=1", "-voxel.StreamingLegacyPendingResultCap=0", "-voxel.CoreRegionConcurrentAdmission=1", "-voxel.StreamingResultBacklogCap=256", "-voxel.StreamingReadyQueueDepth=8", "-voxel.StreamingBackgroundWorkerCap=1", "-voxel.CoreColumnCacheDirectMapped=0", "-voxel.StreamingFarApplySupplement=1", "-voxel.CoreMCGradientMemoization=1", "-voxel.StreamingCollisionLookahead=1", "-voxel.TestMove=1", "-voxel.TestMoveSpeedCmPerSecond=3000.0", "-voxel.TestMoveStartSeconds=6.0", "-voxel.TestMoveDurationSeconds=12.0", "-voxel.TestExitSeconds=23.0", "-voxel.TestMoveDirection=1,0,0", "-voxel.StreamingSchedulerPolicy=3", "-voxel.TestExitOnSteady=0", "-coreworldstreamtrace=1", f"-voxel.StartupTraceSpawnCm={spawn_cm}", "-voxel.StartupTraceUntilEndPlay=1", "-voxel.StartupTraceThroughCrossing=1", "-voxel.StartupTraceMaxTiles=16384", f"-voxel.StartupTraceFile={trace}", f"-abslog={abslog}", ] OUT.mkdir(parents=True, exist_ok=True) wrapped = ["taskset", "-c", "0-11", "timeout", "1740s", *command] started = time.monotonic() with stdout.open("w", encoding="utf-8") as stream: result = subprocess.run(wrapped, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1740) events = [] if trace.is_file(): for line in trace.read_text(encoding="utf-8", errors="replace").splitlines(): if line.startswith("{"): try: events.append(json.loads(line)) except json.JSONDecodeError: continue moving = [event for event in events if event.get("type") == "streaming_sample" and float(event.get("speed_cm_s", 0.0)) >= 50.0] dwell = [event for event in events if event.get("type") == "streaming_sample" and float(event.get("speed_cm_s", 0.0)) < 50.0 and float(event.get("t_s", 0.0)) >= 18.0] backend = next((event for event in events if event.get("type") == "worker_backend_config"), {}) cap = next((event for event in events if event.get("type") == "streaming_worker_cap_readback"), {}) if result.returncode or len(moving) < 40 or len(dwell) < 16: raise RuntimeError(f"incomplete Unreal run {repetition}: exit={result.returncode}, " f"move={len(moving)}, dwell={len(dwell)}, trace={trace}") if (int(backend.get("streaming_far_apply_supplement", -1)) != 1 or int(cap.get("streaming_background_worker_cap", -1)) != 1 or int(backend.get("effective_tile_slots", -1)) != 8): raise RuntimeError(f"configuration readback mismatch: {backend}; {cap}") if not any(event.get("type") == "scheduler_admission" and "region_compile_declines_by_lod" in event for event in events): raise RuntimeError(f"admission diagnostics missing from {trace}") row = { "platform": "unreal", "phase": "diagnostic_baseline", "repetition": repetition, "exit_code": result.returncode, "wall_s": round(time.monotonic() - started, 3), "moving_samples": len(moving), "dwell_samples": len(dwell), "trace": str(trace.relative_to(ROOT)), "log": str(abslog.relative_to(ROOT)), } with (OUT / "runs.jsonl").open("a", encoding="utf-8") as stream: stream.write(json.dumps(row, sort_keys=True) + "\n") print("[L122Admission] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: if not (ROOT / "Standalone/data/owner_world.json").is_file() or not EDITOR.is_file(): raise SystemExit("missing owner world data or Unreal editor") OUT.mkdir(parents=True, exist_ok=True) runs = [run(repetition) for repetition in range(1, 6)] (OUT / "summary.json").write_text(json.dumps({"runs": runs}, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())