Diagnostics: copystat's per-frame figures divide by the frames of their own 5 s interval (they read 1.5-6x too high) #213

Open
MamaLeVrai wants to merge 1 commit from upstream-pr/213 into main
MamaLeVrai commented 2026-11-25 23:55:49 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-25T23:55:49Z.


In diagnostics builds, the copies per frame: … line (copystat::log) and its copied from … x/frame lines divide counters gathered over about 5 s by the frame count of the last 1 s only.

Where. Meter::frame (crates/victory-gpu/src/host.rs) computes frames for a one-second window and resets it every second. The copystat counters are only swapped to zero inside the if self.logged.elapsed() >= 5 s block, so they hold about 5 s of work, and crate::copystat::log(frames) divides them by that one second's frames. The page-fault count in the same line has the same problem. At 2 to 4 fps the per-frame figures come out about 1.5 to 6 times too high, depending on how many frames the last second had. They are only right when one frame spans the whole interval.

This matters for reports that quote them. #151 cites 21-38 GB "refreshed per frame". In two runs on my machine the same line said up to 23 GB per frame, while the fps line's copies … MB (the bytes actually copied, over the same one-second window as its frame count) said 35-121 MB a frame.

The change. TIMED_FRAMES already counts the frames presented since the last 5 s line; log_gpu_times used it for the same purpose. It is now read once in that block and passed to both log_gpu_times and copystat::log. Diagnostics builds only; release builds are unchanged.

Checked. cargo clippy --release -p victory-gpu --features diagnostics --no-deps builds with no new warning. I have not run the game with it.

AI-assisted (Claude Code); no game data.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5501284131 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/213). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T23:55:49Z. --- In diagnostics builds, the `copies per frame: …` line (`copystat::log`) and its `copied from … x/frame` lines divide counters gathered over about 5 s by the frame count of the last 1 s only. **Where.** `Meter::frame` (`crates/victory-gpu/src/host.rs`) computes `frames` for a one-second window and resets it every second. The copystat counters are only swapped to zero inside the `if self.logged.elapsed() >= 5 s` block, so they hold about 5 s of work, and `crate::copystat::log(frames)` divides them by that one second's frames. The page-fault count in the same line has the same problem. At 2 to 4 fps the per-frame figures come out about 1.5 to 6 times too high, depending on how many frames the last second had. They are only right when one frame spans the whole interval. This matters for reports that quote them. #151 cites 21-38 GB "refreshed per frame". In two runs on my machine the same line said up to 23 GB per frame, while the fps line's `copies … MB` (the bytes actually copied, over the same one-second window as its frame count) said 35-121 MB a frame. **The change.** `TIMED_FRAMES` already counts the frames presented since the last 5 s line; `log_gpu_times` used it for the same purpose. It is now read once in that block and passed to both `log_gpu_times` and `copystat::log`. Diagnostics builds only; release builds are unchanged. **Checked.** `cargo clippy --release -p victory-gpu --features diagnostics --no-deps` builds with no new warning. I have not run the game with it. AI-assisted (Claude Code); no game data. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
copilot-pull-request-reviewer[bot] commented 2026-11-25 23:56:00 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T23:56:00Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6066667570 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/213#pullrequestreview-6066667570). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T23:56:00Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
KernelSmoker commented 2026-11-26 00:25:45 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by KernelSmoker on 2026-11-26T00:25:45Z.


I cross-checked PR #213 with cargo check --target x86_64-pc-windows-gnu -p victory-gpu --features diagnostics (passed; compile check only). Static review found a counter edge case: TIMED_FRAMES.swap runs before log_gpu_times, which returns early when GPU_TIMES is None (usual unless VICTORY_GPU_TIMING populated it). The swap still consumes the frames, so copystat::log(interval_frames) can then use 1 and retain the overcount. Could you move ownership of the swap so copy stats always receive the interval frame count? I recorded the validation at https://github.com/KernelSmoker/VIctory-Belobug-AMD/blob/testreports/2026-11-27/reports/2026-11-27-pr213-windows-compile.md

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7178745373 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/213#issuecomment-7178745373). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-26T00:25:45Z. --- I cross-checked PR #213 with `cargo check --target x86_64-pc-windows-gnu -p victory-gpu --features diagnostics` (passed; compile check only). Static review found a counter edge case: `TIMED_FRAMES.swap` runs before `log_gpu_times`, which returns early when `GPU_TIMES` is `None` (usual unless `VICTORY_GPU_TIMING` populated it). The swap still consumes the frames, so `copystat::log(interval_frames)` can then use 1 and retain the overcount. Could you move ownership of the swap so copy stats always receive the interval frame count? I recorded the validation at https://github.com/KernelSmoker/VIctory-Belobug-AMD/blob/testreports/2026-11-27/reports/2026-11-27-pr213-windows-compile.md
MamaLeVrai commented 2026-11-26 04:59:53 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-26T04:59:53Z.


Thanks for the cross-check under the GNU target. I think the swap already lives where you suggest. The PR takes TIMED_FRAMES.swap(0, …) out of log_gpu_times, which now only takes frames: f64 as an argument. The swap happens once, in Meter::frame's 5 s block, into interval_frames, and that one value is passed to both log_gpu_times(interval_frames) and crate::copystat::log(interval_frames). So when log_gpu_times returns early (no GPU_TIMES), nothing has been consumed on its account, and copystat still gets the interval's frame count. The relevant lines of the diff:

-fn log_gpu_times() {
-    let frames = f64::from(TIMED_FRAMES.swap(0, Ordering::Relaxed).max(1));
+fn log_gpu_times(frames: f64) {
…
+            let interval_frames = f64::from(TIMED_FRAMES.swap(0, Ordering::Relaxed).max(1));
-            log_gpu_times();
+            log_gpu_times(interval_frames);
-                crate::copystat::log(frames);
+                crate::copystat::log(interval_frames);

If I have missed a path, please point me to it.

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7183086158 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/213#issuecomment-7183086158). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-26T04:59:53Z. --- Thanks for the cross-check under the GNU target. I think the swap already lives where you suggest. The PR takes `TIMED_FRAMES.swap(0, …)` out of `log_gpu_times`, which now only takes `frames: f64` as an argument. The swap happens once, in `Meter::frame`'s 5 s block, into `interval_frames`, and that one value is passed to both `log_gpu_times(interval_frames)` and `crate::copystat::log(interval_frames)`. So when `log_gpu_times` returns early (no `GPU_TIMES`), nothing has been consumed on its account, and copystat still gets the interval's frame count. The relevant lines of the diff: ```rust -fn log_gpu_times() { - let frames = f64::from(TIMED_FRAMES.swap(0, Ordering::Relaxed).max(1)); +fn log_gpu_times(frames: f64) { … + let interval_frames = f64::from(TIMED_FRAMES.swap(0, Ordering::Relaxed).max(1)); - log_gpu_times(); + log_gpu_times(interval_frames); - crate::copystat::log(frames); + crate::copystat::log(interval_frames); ``` If I have missed a path, please point me to it. AI-assisted (Claude Code); no game data.
adrianmjim commented 2026-11-26 19:51:53 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T19:51:53Z.


Tested natively on Windows 11 (MSVC toolchain, RX 7900 XT), head ccbf888 against base 4f62c2a.

  • cargo clippy -p victory-gpu --features diagnostics --no-deps --all-targets: same warnings as on base, none new.
  • cargo test -p victory-gpu --lib --features diagnostics: no test reaches Meter::frame, so this only shows the build is fine. The failures I saw were intermittent watch::tests, pipeline::library and queue tests that also fail on base. There was also one query::tests failure, seen once, on the PR side only.
  • To exercise the change I added a local test (not part of this PR). It drives a Meter at 3 fps for about 6.6 s with a null HWND. It adds 1 MB of title copies per frame through copystat::add/copystat::range and reads the logged line.
    • Base: title copies 4.2 to 5.3 MB/frame, copied from 4.2x to 5.3x per frame (4 runs).
    • PR: 1.0 MB/frame and 1.0x/frame (5 runs).

On the edge case raised above: that test ran without VICTORY_GPU_TIMING. So GPU_TIMES was None and log_gpu_times returned early. copystat::log still got the interval's frame count. TIMED_FRAMES is incremented on every present in diagnostics builds, whether or not GPU timing is on.

So the frame count is not lost there.

Not tested: running the game with this build, and the page-fault figure in that line.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7202040535 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/213#issuecomment-7202040535). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-26T19:51:53Z. --- Tested natively on Windows 11 (MSVC toolchain, RX 7900 XT), head ccbf888 against base 4f62c2a. - `cargo clippy -p victory-gpu --features diagnostics --no-deps --all-targets`: same warnings as on base, none new. - `cargo test -p victory-gpu --lib --features diagnostics`: no test reaches `Meter::frame`, so this only shows the build is fine. The failures I saw were intermittent `watch::tests`, `pipeline::library` and `queue` tests that also fail on base. There was also one `query::tests` failure, seen once, on the PR side only. - To exercise the change I added a local test (not part of this PR). It drives a `Meter` at 3 fps for about 6.6 s with a null HWND. It adds 1 MB of title copies per frame through `copystat::add`/`copystat::range` and reads the logged line. - Base: `title copies` 4.2 to 5.3 MB/frame, `copied from` 4.2x to 5.3x per frame (4 runs). - PR: 1.0 MB/frame and 1.0x/frame (5 runs). On the edge case raised above: that test ran without `VICTORY_GPU_TIMING`. So `GPU_TIMES` was `None` and `log_gpu_times` returned early. `copystat::log` still got the interval's frame count. `TIMED_FRAMES` is incremented on every present in diagnostics builds, whether or not GPU timing is on. So the frame count is not lost there. Not tested: running the game with this build, and the page-fault figure in that line.
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/213:upstream-pr/213'
git switch 'upstream-pr/213'

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/213'
git switch 'upstream-pr/213'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/213'
git switch 'upstream-pr/213'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/213'
git switch 'main'
git merge --squash 'upstream-pr/213'
git switch 'main'
git merge --ff-only 'upstream-pr/213'
git switch 'main'
git merge 'upstream-pr/213'
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
Belobug/VIctory-Belobug-AMD!213
No description provided.