Loader: flush VICTORY_PROFILE periodically and on crash/GPU failure #4768

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

@⁠dheerajc8073 on GitHub · 2026-12-01 06:34 UTC · original
dheerajc8073:fix/profile-periodic-flush → main · +187 −55 · 2 files · 1 commits · open

Refs #4733

What it changes

VICTORY_PROFILE=<from>,<to>,<ms>,<file> previously wrote <file> only after the sampling window ended, so a GPU failure (host_gpu_failed), unhandled exception, or hang before <to> lost all collected samples.

  • Flushes the active profile snapshot to <file> every 10 seconds via <file>.tmp + rename (with copy+remove fallback), without closing thread handles and while preserving the resolved symbol cache across flushes.
  • Exposes profile::flush() (using try_lock to avoid deadlocks) and calls it from crash::log_crash and crash::report_unhandled when diagnostics is enabled.
  • Adds unit tests in victory-loader::profile::tests covering incremental snapshot writes, symbol-cache reuse, and flush().

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): not run in-game
  • Before: not run
  • After: not run
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): n/a
  • cargo test passed for the crates it touches: yes (victory-loader, default and --all-features, plus cargo clippy --locked -p victory-loader --all-targets with -D warnings under both default and --all-features, and cargo xtask policy — note CI workspace check currently fails on 5 pre-existing victory-gpu Clippy lints on main tracked by #4708)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #4342, #4203
**@⁠dheerajc8073** on GitHub · 2026-12-01 06:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4767) `dheerajc8073:fix/profile-periodic-flush` → `main` · +187 −55 · 2 files · 1 commits · open Refs #4733 ## What it changes `VICTORY_PROFILE=<from>,<to>,<ms>,<file>` previously wrote `<file>` only after the sampling window ended, so a GPU failure (`host_gpu_failed`), unhandled exception, or hang before `<to>` lost all collected samples. - Flushes the active profile snapshot to `<file>` every 10 seconds via `<file>.tmp` + rename (with copy+remove fallback), without closing thread handles and while preserving the resolved symbol cache across flushes. - Exposes `profile::flush()` (using `try_lock` to avoid deadlocks) and calls it from `crash::log_crash` and `crash::report_unhandled` when `diagnostics` is enabled. - Adds unit tests in `victory-loader::profile::tests` covering incremental snapshot writes, symbol-cache reuse, and `flush()`. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): not run in-game - Before: not run - After: not run - For shader changes, the wave sizes tested (32 and/or 64 lanes): n/a - `cargo test` passed for the crates it touches: yes (`victory-loader`, default and `--all-features`, plus `cargo clippy --locked -p victory-loader --all-targets` with `-D warnings` under both default and `--all-features`, and `cargo xtask policy` — note CI workspace `check` currently fails on 5 pre-existing `victory-gpu` Clippy lints on `main` tracked by #4708) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #4342, #4203
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 06:37:26 +00:00
github-bot changed title from Flush VICTORY_PROFILE periodically and on crash/GPU failure to Loader: flush VICTORY_PROFILE periodically and on crash/GPU failure 2026-12-01 08:10:07 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-12-01 09:24 UTC · original

The snapshot copy fallback can overwrite the last complete profile even after the atomic rename fails. That can leave a partial profile at the published path if the process stops during the copy.

I checked the exact replacement code from d272c96 on Windows with a reader holding profile.txt.tmp open. The rename failed with Windows sharing error 32, but the current fallback returned success and changed what an already-open reader of profile.txt saw from rounds 1 to rounds 2 in the same file.

Proposed commit removes the copy fallback. With the same handles open it returns error 32, preserves rounds 1 and leaves the complete rounds 2 snapshot in .tmp. Retrying after the handles close publishes rounds 2. The patch changes only snapshot replacement and is based directly on your PR head.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-12-01 09:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4767#issuecomment-7306651629) The snapshot copy fallback can overwrite the last complete profile even after the atomic rename fails. That can leave a partial profile at the published path if the process stops during the copy. I checked the exact replacement code from `d272c96` on Windows with a reader holding `profile.txt.tmp` open. The rename failed with Windows sharing error 32, but the current fallback returned success and changed what an already-open reader of `profile.txt` saw from `rounds 1` to `rounds 2` in the same file. [Proposed commit](https://github.com/andrewpozdnakov7-jpg/VIctory-NVIDIA/commit/d0d71ebc7f4b4dec1d4b60b25a33bf0f07383d2e) removes the copy fallback. With the same handles open it returns error 32, preserves `rounds 1` and leaves the complete `rounds 2` snapshot in `.tmp`. Retrying after the handles close publishes `rounds 2`. The patch changes only snapshot replacement and is based directly on your PR head. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-12-01 12:06 UTC · original · approved these changes

Reviewed crates/victory-loader/src/crash.rs and crates/victory-loader/src/profile.rs: periodic 10 s snapshots and crash-path profile::flush() via ACTIVE.try_lock() (avoiding deadlock in exception handlers), closing thread handles via Drop on Thread, reusing state.names across snapshots, and writing via .tmp + rename/copy fallback are all clean and well-tested. Verified on Windows: cargo test -p victory-loader --features diagnostics --lib profile::tests -- --test-threads=1 (3 passed, 0 failed) and default-features cargo check -p victory-loader --tests passed cleanly.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-12-01 12:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4767#pullrequestreview-6130937682) · **approved these changes** Reviewed crates/victory-loader/src/crash.rs and crates/victory-loader/src/profile.rs: periodic 10 s snapshots and crash-path profile::flush() via ACTIVE.try_lock() (avoiding deadlock in exception handlers), closing thread handles via Drop on Thread, reusing state.names across snapshots, and writing via .tmp + rename/copy fallback are all clean and well-tested. Verified on Windows: cargo test -p victory-loader --features diagnostics --lib profile::tests -- --test-threads=1 (3 passed, 0 failed) and default-features cargo check -p victory-loader --tests passed cleanly. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/4768/head:github-bot/gh-4767'
git switch 'github-bot/gh-4767'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4767'
git switch 'github-bot/gh-4767'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4767'
git switch 'github-bot/gh-4767'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4767'
git switch 'main'
git merge --squash 'github-bot/gh-4767'
git switch 'main'
git merge --ff-only 'github-bot/gh-4767'
git switch 'main'
git merge 'github-bot/gh-4767'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!4768
No description provided.