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
github-bot wants to merge 1 commit from github-bot/gh-213 into main AGit
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 23:55 UTC · original
MamaLeVrai:copystat-interval → main · +10 −5 · 1 files · 1 commits · open

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

**@⁠MamaLeVrai** on GitHub · 2026-11-25 23:55 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/213) `MamaLeVrai:copystat-interval` → `main` · +10 −5 · 1 files · 1 commits · open 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:38:04 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-26 00:25 UTC · original

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

**@⁠KernelSmoker** on GitHub · 2026-11-26 00:25 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/213#issuecomment-7178745373) 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
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 23:56 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 23:56 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/213#pullrequestreview-6066667570) · **reviewed** 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.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 04:59 UTC · original

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.

**@⁠MamaLeVrai** on GitHub · 2026-11-26 04:59 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/213#issuecomment-7183086158) 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.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:51 UTC · original

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.

**@⁠adrianmjim** on GitHub · 2026-11-26 19:51 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/213#issuecomment-7202040535) 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 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/213/head:github-bot/gh-213'
git switch 'github-bot/gh-213'

Merge

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