From f806537a8cfb568c8dcd9dcc806182f9ac0520a5 Mon Sep 17 00:00:00 2001 From: TheGeogeo <57634077+TheGeogeo@users.noreply.github.com> Date: Tue, 1 Dec 2026 01:32:36 +0100 Subject: [PATCH] gate: summary.json gets the run's memory peaks (D3D12-GATE-MEMORY-PEAKS) Testers could not use the gate daily without memory figures, and a memory pile-up took a 3090's Windows down twice. The parser now reads the runtime's memory line and video memory line (every 5 s in builds with diagnostics) and writes a memory block: the private bytes at their most and when, the most of them in physical memory, the least the PC had left to commit and when, the card's video memory in use at its most and when with the budget then, the seconds over that budget, and the most shared memory in use. The video memory is what the system counts for the process, so it works on any card. The five runtime strings it reads join the contract test. --- docs/game_gate.md | 1 + tests/test_game_gate.py | 31 ++++++++++++++++++++++++++++++ tools/game_gate.py | 42 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/docs/game_gate.md b/docs/game_gate.md index 4bb6c372da..2a4f44c379 100644 --- a/docs/game_gate.md +++ b/docs/game_gate.md @@ -57,6 +57,7 @@ Times are seconds since the run started. The summary holds numbers, switch names | `times.world_s` | Seconds from `world_at_s` to the stop request | | `fps` | From the presents, after the first 60 s in the world: frames, median, p5, frame p95 (ms), median of the last 60 s (`end_median`), the first second with fewer than 2 frames, from 60 s in the world on too (`under_2_at_s`), the longest gap with no frame presented from the world on (`longest_present_gap_s`, `longest_gap_at_s`; on purpose from the world on: a freeze on pipeline compiles comes right after arrival, and 10 s with no frame is what a player sees), draws a frame. Without the present lines (a build without diagnostics), the median and p5 come from the frame lines, with a warning | | `pipelines` | Waits that ran out (`missed_waits`), the most pipelines being made at once | +| `memory` | Peaks over the whole run, from the runtime's memory line and video memory line (every 5 s; builds with diagnostics only, otherwise `source` is null): the process's private bytes and when (`private_max_mb`, `private_max_at_s`), the most of them in physical memory, the least the PC had left to commit and when, the card's video memory in use at its most and when, with the budget the system gave then (`vram_in_use_max_mb`, `vram_max_at_s`, `vram_budget_at_max_mb`), the seconds spent over that budget, and the most of the PC's memory shared with the card in use. The video memory is what the system counts for this process, less than a tool like `nvidia-smi` shows for the whole card | | `crash` | `kind` is `none`, `device_lost`, `panic` or `fault`. It also gives the time, the code, the module kind (`runtime`, `title`, `driver`, `system`, `unknown`) and the access (read/write). `title_watchdog` marks a write at address 0 in the title more than 25 s after the last frame line. `count` is the number of crashes | | `exit` | The game's exit code, and its kind: `clean`, `device_lost` (0x887A0005), `killed` or `other` | | `stop` | Why it was stopped (`target`, `stop_file`, `timeout`, `relaunched`), whether it was killed, whether the cache was saved, whether the suspend was in time | diff --git a/tests/test_game_gate.py b/tests/test_game_gate.py index 879419d5da..9da60f265c 100644 --- a/tests/test_game_gate.py +++ b/tests/test_game_gate.py @@ -48,6 +48,16 @@ def frames(self, start, end, fps, draws, making=0, dropped=0, step=1.0, presents self.log.append(f"{stamp(t)} DEBUG leonida_gpu::frame: present token=1") t += gap + def memory(self, t, private, used, budget=8000, left=3000, shared=500): + """The runtime's video memory line and memory line, as a diagnostics build writes them every 5 s.""" + self.log.append(f"{stamp(t)} INFO leonida_gpu::host: video memory as the system counts it, with the memory " + f"line: the card's own: budget {budget} MB, in use {used} MB, 100 MB could still be reserved, " + f"0 MB reserved; the PC's shared with the card: budget 16000 MB, in use {shared} MB, 0 MB could " + f"still be reserved, 0 MB reserved (the layer reserves none)") + self.log.append(f"{stamp(t)} INFO leonida_gpu::copystat: memory: {private} MB private ({private // 2} MB of it " + f"in memory; the PC has 15000 MB free and {left} MB left to commit); host copies of title " + f"memory: 1 alive 1 MB, of them 0 windows outside buffers 0 MB") + def clean_stop(self, t, exit_code=0): self.event(t, "stop_requested", reason="target") self.log.append(f"{stamp(t + 0.1)} INFO leonida_hle::modules::lifecycle: window closed: suspending the title constrained=0 routines=1") @@ -209,6 +219,27 @@ def test_a_dip_on_arrival_is_not_the_first_second_under_2(self): self.assertEqual(s["fps"]["under_2_at_s"], 300.0) self.assertEqual(s["verdict"]["result"], "PASS", s["verdict"]) + def test_memory_peaks_come_from_the_runtimes_memory_lines(self): + f = passing() + for i, t in enumerate(range(70, 390, 5)): + # Private bytes grow, the PC's commit left shrinks, the card goes over its budget from 200 s on. + f.memory(t, 20000 + 10 * i, 7000 if t < 200 else 9000, left=3000 - i, shared=500 + i) + m = f.summarize()["memory"] + self.assertEqual((m["source"], m["lines"]), ("memory lines", 64)) + self.assertEqual((m["private_max_mb"], m["private_max_at_s"]), (20630, 385.0)) + self.assertEqual(m["in_memory_max_mb"], 10315) + self.assertEqual((m["pc_commit_left_min_mb"], m["pc_commit_left_min_at_s"]), (2937, 385.0)) + self.assertEqual((m["vram_in_use_max_mb"], m["vram_max_at_s"], m["vram_budget_at_max_mb"]), (9000, 200.0, 8000)) + self.assertEqual(m["vram_over_budget_s"], 185.0) + self.assertEqual(m["shared_in_use_max_mb"], 563) + + def test_a_build_without_memory_lines_gives_no_memory_peaks(self): + m = passing().summarize()["memory"] + self.assertIsNone(m["source"]) + self.assertEqual(m["lines"], 0) + self.assertIsNone(m["private_max_mb"]) + self.assertIsNone(m["vram_in_use_max_mb"]) + def test_without_present_lines_the_frame_lines_give_the_rate(self): f = Fake() f.event(1, "game", pid=1) diff --git a/tools/game_gate.py b/tools/game_gate.py index d66ab92382..5a69e89952 100644 --- a/tools/game_gate.py +++ b/tools/game_gate.py @@ -44,6 +44,11 @@ PANIC = re.compile(r"(?:^thread '[^']*'(?: \(\d+\))? panicked at|^Leonida: panic on thread)") FAULT = re.compile(r"^Leonida: unhandled exception (0x[0-9a-fA-F]+) at (\S+)(.*)$") ACCESS = re.compile(r"\((read|write|execute)\w* (0x[0-9a-fA-F]+)") +# The memory line and the video memory line (diagnostics builds, every 5 s with the frame line). +MEMORY = re.compile(r"^memory: (\d+) MB private \((\d+) MB of it in memory; the PC has (\d+) MB free and (\d+) MB " + r"left to commit\)") +VIDEO = re.compile(r"^video memory as the system counts it, [^:]*: the card's own: budget (\d+) MB, in use (\d+) MB, " + r".*?; the PC's shared with the card: budget (\d+) MB, in use (\d+) MB") # The runtime's own words this parser reads, and where they are written: tests/test_game_gate.py checks that # each is still there, so a reworded line fails the test, not the next gate. @@ -64,6 +69,13 @@ "shaders in the cache, {} do not translate, {:.0} s": "d3d12/apps/leonida/src/translate.rs", "pipelines known, {} made before ({fingerprint}), {} bad; {} to make": "d3d12/apps/leonida/src/warm.rs", "made in {:.0} s (": "d3d12/apps/leonida/src/warm.rs", + "memory: {:.0} MB private ({:.0} MB of it in memory; the PC has {:.0} MB free and {:.0} MB": + "d3d12/crates/leonida-gpu/src/copystat.rs", + "left to commit); host copies": "d3d12/crates/leonida-gpu/src/copystat.rs", + "video memory as the system counts it, {}: the card's own: budget {} MB, in use {} MB": + "d3d12/crates/leonida-gpu/src/host.rs", + "the PC's shared with the card: budget {} MB, in use {} MB": "d3d12/crates/leonida-gpu/src/host.rs", + 'h.log_video_memory("with the memory line")': "d3d12/crates/leonida-gpu/src/copystat.rs", } @@ -110,6 +122,8 @@ def __init__(self, folder): self.frames = [] # (t, fps, draws, dropped, making) self.presents = [] # t of each present (diagnostics builds, frame debug lines) self.missed = [] # t of each pipeline not made within its wait + self.memory = [] # (t, private MB, in memory MB, PC free MB, PC left to commit MB) + self.video = [] # (t, card budget MB, card in use MB, shared budget MB, shared in use MB) self.settings = None # from the runtime's settings line self.suspend = None self.ended_at = None @@ -137,6 +151,10 @@ def read_log(self, lines): f = FRAME.search(text) if f: self.frames.append((t, float(f.group(1)), float(f.group(3)), float(f.group(4)), int(f.group(5)))) + elif text.startswith("memory: ") and MEMORY.match(text): + self.memory.append((t,) + tuple(int(x) for x in MEMORY.match(text).groups())) + elif text.startswith("video memory as the system counts it") and VIDEO.match(text): + self.video.append((t,) + tuple(int(x) for x in VIDEO.match(text).groups())) elif text.startswith("a pipeline not made within its wait"): self.missed.append(t) elif target == "settings": @@ -316,6 +334,29 @@ def fps_block(run, world, end): return out +def memory_block(run): + """Peaks of the runtime's memory lines over the whole run (none from a build without diagnostics).""" + out = {"source": None, "lines": 0, "private_max_mb": None, "private_max_at_s": None, "in_memory_max_mb": None, + "pc_commit_left_min_mb": None, "pc_commit_left_min_at_s": None, "vram_in_use_max_mb": None, + "vram_max_at_s": None, "vram_budget_at_max_mb": None, "vram_over_budget_s": None, + "shared_in_use_max_mb": None} + if run.memory: + out["source"], out["lines"] = "memory lines", len(run.memory) + t, private = max(((t, p) for t, p, *_ in run.memory), key=lambda x: x[1]) + out["private_max_mb"], out["private_max_at_s"] = private, round(t, 3) + out["in_memory_max_mb"] = max(m[2] for m in run.memory) + t, left = min(((m[0], m[4]) for m in run.memory), key=lambda x: x[1]) + out["pc_commit_left_min_mb"], out["pc_commit_left_min_at_s"] = left, round(t, 3) + if run.video: + t, budget, used = max(((v[0], v[1], v[2]) for v in run.video), key=lambda x: x[2]) + out["vram_in_use_max_mb"], out["vram_max_at_s"], out["vram_budget_at_max_mb"] = used, round(t, 3), budget + # Time over the card's budget: each line counts until the next one. + over = sum(b[0] - a[0] for a, b in zip(run.video, run.video[1:]) if a[2] > a[1]) + out["vram_over_budget_s"] = round(over, 1) + out["shared_in_use_max_mb"] = max(v[4] for v in run.video) + return out + + def summary(run): world = run.world_at() stop = run.stop_at() @@ -395,6 +436,7 @@ def summary(run): }, "fps": fps, "pipelines": {"missed_waits": len(run.missed), "making_max": max((m for *_, m in run.frames), default=0)}, + "memory": memory_block(run), "crash": { "kind": crash_kind, "at_s": round(first["at_s"], 3) if first and first["at_s"] is not None else None,