Diagnostics: long frames one by one, with where each one's time went (VICTORY_LONG_FRAMES=<ms>) #452

Open
github-bot wants to merge 1 commit from github-bot/gh-452 into main AGit
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-27 10:30 UTC · original
Jesper-Andersson:long-frames → main · +357 −1 · 4 files · 1 commits · open

The frame-rate line and the 5 s copies per frame / recording per frame lines average every frame since the last line, so one 1.5 s frame among fifty of 95 ms hardly moves them: they show which stretches stutter, not what held any one frame. This adds a line for each long frame on its own, with where that frame's time went.

Change

  • VICTORY_LONG_FRAMES=<ms> (diagnostics builds only, off by default; 1/on = 250 ms, a number is clamped to at least 50 ms so a steady slow frame rate doesn't log every frame). At each present (copystat::presented) that comes at least that long after the one before, one line:
    • present to the title's first list call and to its first submission, and its last submission to this present (the first of these is time the title spent on its own side);
    • list calls (all recording threads), waits for pipelines being made, the title's frame waits;
    • title copies (time and bytes), refreshes (how many, the lengths of the ranges they name, what the write watch checked and found changed, what was copied whole), our steps on the host, texture uploads;
    • the card waited for, what shaders wrote put back, waits for new memory to be resident and mapped (VICTORY_WAIT_RESIDENT, #371);
    • the process's page faults and user/kernel time (all threads);
    • and, as they are at the present: the PC's free RAM and the pipelines being made.
  • Every field is that one frame's: copystat's counters get running totals (CARRIED keeps what the 5 s line has taken, total() adds what is there now), and a present diffs them with the totals at the present before (longframe::Sample::since). The 5 s line's taking and a present's reading share a lock (TAKING), so a total is never read between a counter's taking and its carrying. Without the lock that frame would come out short and the next one would get the whole 5 s line's worth.
  • The refreshes' MB is the sum of the lengths of the ranges named for refreshing, the same counter as the 5 s line's "refreshes N MB" (about 18 GB a frame in the world here). It is not bytes copied: most of a named range is found unchanged. The line says so and puts the write watch's checked/changed bytes and the bytes copied whole beside it.
  • New counter C::CopyUs: the time of the title copies that C::CopyBytes counts (the 5 s line had that time only in host.rs's PREPARING). New host::residency_waits_us() reads the resident/mapped wait totals, which are never reset.
  • New module crates/victory-gpu/src/longframe.rs (threshold parsing, the sample and the line, tests); hooks in copystat.rs, host.rs, lib.rs.

Where it does nothing

  • Release builds and diagnostics builds without the switch: presented() checks a OnceLock and returns. The extra work on the 5 s line is one fetch_add per counter and an uncontended lock.

Measured

I haven't timed what the line itself costs: with the switch on, a present makes three syscalls and sums about 20 counters over 32 banks. Here is what it showed from a local branch (main plus about 50 PRs, not main), on an RTX 2070 SUPER 8 GB (driver 621.14), Ryzen 7 5800X, 32 GB, Windows 11, diag build, Series S + DLSS, VICTORY_LONG_FRAMES=250:

  • In the first minute in the world, almost all long frames are spent "after the present before it until the title's first list call". They show 9,000-85,000 page faults in that frame and 7-8 s of process CPU in a frame of about 1 s. One example: a 1,523 ms frame had 1,488.9 ms until the first list call, 21.8 ms of list calls, 63,239 page faults, 9,625 ms user + 1,125 ms kernel, and no residency waits. So the title's own side stalls under paging. That led to VICTORY_KEEP_PAGES (#447).
  • Other long frames are a different kind: most of the time goes to list calls (hundreds of ms across threads), waits for pipelines and residency waits, while hundreds of pipelines are being made.

Checks

  • cargo test -p victory-gpu --lib --locked longframe: 4 passed (4 new: the_switch_reads_as_a_threshold, a_frame_is_the_difference_of_its_presents_and_never_negative, every_field_of_a_frame_is_that_frame_alone, only_frames_past_the_threshold_make_a_line)
  • cargo clippy -p victory-gpu --all-targets --locked --features diagnostics: no warnings in changed code (6 warnings already on main: texture.rs, host/panel.rs, host/place.rs, host/rtstamps.rs x2, watch.rs)
  • cargo xtask policy: 4 files ok
  • In game: the original commit (before the per-frame fixes here) ran on the local branch above. This port onto main has not been run in game.

Not checked

  • AMD cards, Linux/Proton.
  • This exact port in game. The most useful check: a diag run with VICTORY_LONG_FRAMES=1, comparing a long frame's fields with the 5 s line around it.
  • Marvisak/VIctory#2721 is a slow-frame report and partly overlaps. This one adds the parts needed to tell paging stalls apart: page faults, user/kernel time, residency and mapping waits, free RAM, and the split of the frame around the title's first list call and submission.
  • #272 (open) logs a percentile summary of frame times every 5 s (median, p95, p99, longest, counts over 50/100 ms). It has no per-frame breakdown. The two fit together: #272 says how many frames were long, this says what held each one.
  • #429 (open, VICTORY_CRITICAL_PATH=1) logs one line every frame with the submitting, recording and relay chains. It has no threshold and no paging or residency fields.
  • #432 (open) splits residency and mapping waits by allocation kind. This line uses only their totals.
  • #447 (VICTORY_KEEP_PAGES) is the fix these lines led to.

This change was made with AI assistance (Claude Code).

**@⁠Jesper-Andersson** on GitHub · 2026-11-27 10:30 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/452) `Jesper-Andersson:long-frames` → `main` · +357 −1 · 4 files · 1 commits · open The frame-rate line and the 5 s `copies per frame` / `recording per frame` lines average every frame since the last line, so one 1.5 s frame among fifty of 95 ms hardly moves them: they show which stretches stutter, not what held any one frame. This adds a line for each long frame on its own, with where that frame's time went. ## Change - `VICTORY_LONG_FRAMES=<ms>` (diagnostics builds only, off by default; `1`/`on` = 250 ms, a number is clamped to at least 50 ms so a steady slow frame rate doesn't log every frame). At each present (`copystat::presented`) that comes at least that long after the one before, one line: - present to the title's first list call and to its first submission, and its last submission to this present (the first of these is time the title spent on its own side); - list calls (all recording threads), waits for pipelines being made, the title's frame waits; - title copies (time and bytes), refreshes (how many, the lengths of the ranges they name, what the write watch checked and found changed, what was copied whole), our steps on the host, texture uploads; - the card waited for, what shaders wrote put back, waits for new memory to be resident and mapped (`VICTORY_WAIT_RESIDENT`, #371); - the process's page faults and user/kernel time (all threads); - and, as they are at the present: the PC's free RAM and the pipelines being made. - Every field is that one frame's: `copystat`'s counters get running totals (`CARRIED` keeps what the 5 s line has taken, `total()` adds what is there now), and a present diffs them with the totals at the present before (`longframe::Sample::since`). The 5 s line's taking and a present's reading share a lock (`TAKING`), so a total is never read between a counter's taking and its carrying. Without the lock that frame would come out short and the next one would get the whole 5 s line's worth. - The refreshes' MB is the sum of the lengths of the ranges named for refreshing, the same counter as the 5 s line's "refreshes N MB" (about 18 GB a frame in the world here). It is not bytes copied: most of a named range is found unchanged. The line says so and puts the write watch's checked/changed bytes and the bytes copied whole beside it. - New counter `C::CopyUs`: the time of the title copies that `C::CopyBytes` counts (the 5 s line had that time only in `host.rs`'s `PREPARING`). New `host::residency_waits_us()` reads the `resident`/`mapped` wait totals, which are never reset. - New module `crates/victory-gpu/src/longframe.rs` (threshold parsing, the sample and the line, tests); hooks in `copystat.rs`, `host.rs`, `lib.rs`. ## Where it does nothing - Release builds and diagnostics builds without the switch: `presented()` checks a `OnceLock` and returns. The extra work on the 5 s line is one `fetch_add` per counter and an uncontended lock. ## Measured I haven't timed what the line itself costs: with the switch on, a present makes three syscalls and sums about 20 counters over 32 banks. Here is what it showed from a local branch (main plus about 50 PRs, not `main`), on an RTX 2070 SUPER 8 GB (driver 621.14), Ryzen 7 5800X, 32 GB, Windows 11, diag build, Series S + DLSS, `VICTORY_LONG_FRAMES=250`: - In the first minute in the world, almost all long frames are spent "after the present before it until the title's first list call". They show 9,000-85,000 page faults in that frame and 7-8 s of process CPU in a frame of about 1 s. One example: a 1,523 ms frame had 1,488.9 ms until the first list call, 21.8 ms of list calls, 63,239 page faults, 9,625 ms user + 1,125 ms kernel, and no residency waits. So the title's own side stalls under paging. That led to `VICTORY_KEEP_PAGES` (#447). - Other long frames are a different kind: most of the time goes to list calls (hundreds of ms across threads), waits for pipelines and residency waits, while hundreds of pipelines are being made. ## Checks - `cargo test -p victory-gpu --lib --locked longframe`: 4 passed (4 new: `the_switch_reads_as_a_threshold`, `a_frame_is_the_difference_of_its_presents_and_never_negative`, `every_field_of_a_frame_is_that_frame_alone`, `only_frames_past_the_threshold_make_a_line`) - `cargo clippy -p victory-gpu --all-targets --locked --features diagnostics`: no warnings in changed code (6 warnings already on main: `texture.rs`, `host/panel.rs`, `host/place.rs`, `host/rtstamps.rs` x2, `watch.rs`) - `cargo xtask policy`: 4 files ok - In game: the original commit (before the per-frame fixes here) ran on the local branch above. This port onto main has not been run in game. ## Not checked - AMD cards, Linux/Proton. - This exact port in game. The most useful check: a diag run with `VICTORY_LONG_FRAMES=1`, comparing a long frame's fields with the 5 s line around it. ## Related - Marvisak/VIctory#2721 is a slow-frame report and partly overlaps. This one adds the parts needed to tell paging stalls apart: page faults, user/kernel time, residency and mapping waits, free RAM, and the split of the frame around the title's first list call and submission. - #272 (open) logs a percentile summary of frame times every 5 s (median, p95, p99, longest, counts over 50/100 ms). It has no per-frame breakdown. The two fit together: #272 says how many frames were long, this says what held each one. - #429 (open, `VICTORY_CRITICAL_PATH=1`) logs one line every frame with the submitting, recording and relay chains. It has no threshold and no paging or residency fields. - #432 (open) splits residency and mapping waits by allocation kind. This line uses only their totals. - #447 (`VICTORY_KEEP_PAGES`) is the fix these lines led to. This change was made with AI assistance (Claude Code).
A line for every present that came at least that long after the one
before (1/on: 250 ms; at least 50), saying where that one frame went:
present to the title's first list call and first submission, last
submission to present, list calls, pipeline waits, frame waits, title
copies (time and bytes), refreshes (how many, the lengths of the ranges
they name, what the write watch checked and found changed, what was
copied whole), our steps on the host, texture uploads, card waits,
copy-back, the waits for new memory to be resident and mapped
(VICTORY_WAIT_RESIDENT, #371), the process's page faults and user/kernel
time; and, as they are at the present, free RAM and the pipelines being
made. The 5 s lines average many frames: they tell which stretches
stuttered, not what held a frame.

Every field is that frame's alone: copystat's counters keep running
totals beside the 5 s lines' takings, and a present diffs them with the
one before. The 5 s line's taking and a present's reading share a lock,
so a total is never read between a counter's taking and its carrying
(it would be short by a whole line's worth, and the next frame would get
it). New counter C::CopyUs: the time of the title copies counted in
CopyBytes, which the line needs and the 5 s line had only in host.rs.

The refreshes' MB is the lengths of the ranges named for refreshing, as
on the 5 s "copies per frame" line (about 18 GB a frame in the world
here), not bytes copied: most of a named range is found unchanged. The
line says so and gives the watch's checked and changed bytes beside it.

Diagnostics builds only; off, a present asks nothing more. Overlaps
Marvisak/VIctory#2721 (a slow-frame report), which lacks the paging,
residency and kernel-time parts this needs.

This change was made with AI assistance (Claude Code).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 10:39:00 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/452/head:github-bot/gh-452'
git switch 'github-bot/gh-452'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-452'
git switch 'github-bot/gh-452'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-452'
git switch 'github-bot/gh-452'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-452'
git switch 'main'
git merge --squash 'github-bot/gh-452'
git switch 'main'
git merge --ff-only 'github-bot/gh-452'
git switch 'main'
git merge 'github-bot/gh-452'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.