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

Open
Jesper-Andersson wants to merge 1 commit from upstream-pr/452 into main
Jesper-Andersson commented 2026-11-27 10:30:30 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by Jesper-Andersson on 2026-11-27T10:30:30Z.


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).

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:5525098975 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/452). Originally posted by [Jesper-Andersson](https://github.com/Jesper-Andersson) on 2026-11-27T10:30:30Z. --- 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).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/452:upstream-pr/452'
git switch 'upstream-pr/452'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/452'
git switch 'upstream-pr/452'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/452'
git switch 'upstream-pr/452'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/452'
git switch 'main'
git merge --squash 'upstream-pr/452'
git switch 'main'
git merge --ff-only 'upstream-pr/452'
git switch 'main'
git merge 'upstream-pr/452'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
avatarmanz/VIctory-7900XTX!452
No description provided.