Sampling profiler: VICTORY_PROFILE=1 counts named threads' stacks, folded and top-60 files beside the log #4342

Closed
github-bot wants to merge 11 commits from github-bot/gh-4341 into main AGit
Owner

@⁠IRennie74 on GitHub · 2026-11-30 19:05 UTC · original
IRennie74:pr/sampling-profiler → main · +1871 −825 · 39 files · 11 commits · closed without merging

What it changes

The stage timers in copystat are placed by hand and say which stage is long, not which functions inside it. On a Ryzen 5 5600X with an RTX 3060 the frame was about 53 ms, about 47 ms of it set by victory-submit, with the list translators (victory-list-{i}) taking 131-215 ms of processor time a frame over four threads (figures from the new module's documentation). This adds a statistical profiler that counts whole stacks instead. Diagnostics builds only; a plain build is unchanged.

  • crates/victory-loader/src/sampler.rs (new): with VICTORY_PROFILE=1, a thread of its own (victory-sampler) takes each chosen thread VICTORY_PROFILE_HZ times a second (1 to 10 000, default 1000), suspends it, reads its registers and copies its stack, resumes it, and only then unwinds the copy. Nothing allocates and no lock is taken while the thread is suspended. VICTORY_PROFILE_THREADS takes name prefixes (default victory-submit,victory-list,victory-relay); the word title adds every title thread. Threads are listed again every second, so later threads and later names are seen. Every 20 s and at exit the addresses are named with dbghelp (ours by the pdb, the system's by exports, the title's by module and function start) and written beside VICTORY_LOG_FILE (else <cache>/logs) as profile-<group>.folded (folded stacks for flamegraph.pl or speedscope) and profile-top.txt (the 60 functions with the most samples of their own and the 60 with the most inside them, per group, with what the sampling cost).
  • crash::unwind_copy takes a frame limit: the stack dump keeps MAX_FRAMES (40), the sampler 48. It is now built for any(test, feature = "diagnostics") (main gated it on diagnostics alone in ea97b1af), because the sampler's tests are built without the feature as well.
  • threads::title_image_at tells a title thread and a title frame from ours; threads::detach_all calls sampler::finish() first, so the last files are written (waiting up to 3 s) before the other threads are ended.
  • apps/victory/src/run.rs: diagnostics() starts the sampler with the log's directory.
  • VICTORY_PROFILE with a schedule (<from>,<to>,<ms>,<file>) is still the older profiler in profile.rs, which writes addresses only; its module documentation now says that 1 is the new one. A value of 1 parses to no schedule there and starts nothing.

Ported from a working branch; against current main the only conflict was the unwind_copy gate above. The test a_busy_thread_is_found_at_the_top also now waits for its busy thread to have started before listing threads: std names a thread from inside it, and under the parallel test harness the list found it unnamed in one run of six.

How it was tested

  • GPU and profile: RTX 3060 12 GB, Ryzen 5 5600X, 32 GB; Series S profile, 960x540 internal, DLSS performance, frame generation off, ray tracing default.
  • Before / after: not measured in game on this branch. The profiler only runs with VICTORY_PROFILE=1 in a diagnostics build, so frame times without it are unchanged by construction; its own cost per sample is written into profile-top.txt when it runs.
  • cargo build --locked --profile diag -p victory --features diagnostics: builds.
  • cargo test --locked -p victory-loader --lib: passes (83 tests), with and without --features diagnostics (86 with it; twelve runs in a row green after the test fix above). The sampler's tests cover the switches' parsing, thread grouping, folding and the top list, and sample a busy thread of the test program itself, which must be found in at least 90% of samples (skipped when dbghelp or the test's pdb is missing).
  • cargo clippy --locked -p victory-loader --all-targets -- -D warnings, with and without --features diagnostics: clean.
  • cargo xtask policy --staged: clean.
  • cargo test passed for the crates it touches: yes

Checked for overlap

  • I searched the open and merged pull requests for profiler, sampler, VICTORY_PROFILE, sampling and stack sampling. Related: #1224 (merged; made the older profiler unwind a copy of the stack, which this builds on), #4203 (open; makes the older VICTORY_PROFILE schedule profiler available in release builds, a different profiler; it also removes the unwind_copy gate in crash.rs and touches lib.rs and run.rs, so whichever lands second needs a small rebase), #2019 (open; also changes the unwind_copy gate in crash.rs), #1575 (open; list-thread stacks for the GPU timeline, VICTORY_TIMELINE_LISTS, a separate sampler in victory-gpu). None adds this sampler.
**@⁠IRennie74** on GitHub · 2026-11-30 19:05 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4341) `IRennie74:pr/sampling-profiler` → `main` · +1871 −825 · 39 files · 11 commits · closed without merging ## What it changes The stage timers in `copystat` are placed by hand and say which stage is long, not which functions inside it. On a Ryzen 5 5600X with an RTX 3060 the frame was about 53 ms, about 47 ms of it set by `victory-submit`, with the list translators (`victory-list-{i}`) taking 131-215 ms of processor time a frame over four threads (figures from the new module's documentation). This adds a statistical profiler that counts whole stacks instead. Diagnostics builds only; a plain build is unchanged. - `crates/victory-loader/src/sampler.rs` (new): with `VICTORY_PROFILE=1`, a thread of its own (`victory-sampler`) takes each chosen thread `VICTORY_PROFILE_HZ` times a second (1 to 10 000, default 1000), suspends it, reads its registers and copies its stack, resumes it, and only then unwinds the copy. Nothing allocates and no lock is taken while the thread is suspended. `VICTORY_PROFILE_THREADS` takes name prefixes (default `victory-submit,victory-list,victory-relay`); the word `title` adds every title thread. Threads are listed again every second, so later threads and later names are seen. Every 20 s and at exit the addresses are named with dbghelp (ours by the pdb, the system's by exports, the title's by module and function start) and written beside `VICTORY_LOG_FILE` (else `<cache>/logs`) as `profile-<group>.folded` (folded stacks for `flamegraph.pl` or speedscope) and `profile-top.txt` (the 60 functions with the most samples of their own and the 60 with the most inside them, per group, with what the sampling cost). - `crash::unwind_copy` takes a frame limit: the stack dump keeps `MAX_FRAMES` (40), the sampler 48. It is now built for `any(test, feature = "diagnostics")` (main gated it on `diagnostics` alone in ea97b1af), because the sampler's tests are built without the feature as well. - `threads::title_image_at` tells a title thread and a title frame from ours; `threads::detach_all` calls `sampler::finish()` first, so the last files are written (waiting up to 3 s) before the other threads are ended. - `apps/victory/src/run.rs`: `diagnostics()` starts the sampler with the log's directory. - `VICTORY_PROFILE` with a schedule (`<from>,<to>,<ms>,<file>`) is still the older profiler in `profile.rs`, which writes addresses only; its module documentation now says that `1` is the new one. A value of `1` parses to no schedule there and starts nothing. Ported from a working branch; against current main the only conflict was the `unwind_copy` gate above. The test `a_busy_thread_is_found_at_the_top` also now waits for its busy thread to have started before listing threads: std names a thread from inside it, and under the parallel test harness the list found it unnamed in one run of six. ## How it was tested - GPU and profile: RTX 3060 12 GB, Ryzen 5 5600X, 32 GB; Series S profile, 960x540 internal, DLSS performance, frame generation off, ray tracing default. - Before / after: not measured in game on this branch. The profiler only runs with `VICTORY_PROFILE=1` in a diagnostics build, so frame times without it are unchanged by construction; its own cost per sample is written into `profile-top.txt` when it runs. - `cargo build --locked --profile diag -p victory --features diagnostics`: builds. - `cargo test --locked -p victory-loader --lib`: passes (83 tests), with and without `--features diagnostics` (86 with it; twelve runs in a row green after the test fix above). The sampler's tests cover the switches' parsing, thread grouping, folding and the top list, and sample a busy thread of the test program itself, which must be found in at least 90% of samples (skipped when dbghelp or the test's pdb is missing). - `cargo clippy --locked -p victory-loader --all-targets -- -D warnings`, with and without `--features diagnostics`: clean. - `cargo xtask policy --staged`: clean. - `cargo test` passed for the crates it touches: yes ## Checked for overlap - [x] I searched the open and merged pull requests for `profiler`, `sampler`, `VICTORY_PROFILE`, `sampling` and `stack sampling`. Related: #1224 (merged; made the older profiler unwind a copy of the stack, which this builds on), #4203 (open; makes the older `VICTORY_PROFILE` schedule profiler available in release builds, a different profiler; it also removes the `unwind_copy` gate in `crash.rs` and touches `lib.rs` and `run.rs`, so whichever lands second needs a small rebase), #2019 (open; also changes the `unwind_copy` gate in `crash.rs`), #1575 (open; list-thread stacks for the GPU timeline, `VICTORY_TIMELINE_LISTS`, a separate sampler in `victory-gpu`). None adds this sampler.
A diagnostics-only sampler thread suspends each chosen thread (victory-submit,
victory-list, victory-relay by default; VICTORY_PROFILE_THREADS prefixes, 'title'
for title threads) VICTORY_PROFILE_HZ times a second, copies its stack, resumes
it and unwinds the copy (unwind_copy, 48 frames). Every 20 s and at exit the
stacks are named with dbghelp and written as profile-<group>.folded and
profile-top.txt beside VICTORY_LOG_FILE (else <cache>/logs).

unwind_copy takes its frame limit and is built for tests as well as for
diagnostics (main gated it on diagnostics alone in ea97b1af; the sampler's
tests build without the feature). The busy-thread test waits for its thread
to have started before listing: std names a thread from inside it, and under
the parallel harness the list found it unnamed one run in six.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 19:09:29 +00:00
github-bot force-pushed github-bot/gh-4341 from 62103bfb40 to 56a5724f5e 2026-11-30 19:16:24 +00:00 Compare
github-bot force-pushed github-bot/gh-4341 from 56a5724f5e to 8c1b80d539 2026-11-30 19:28:58 +00:00 Compare
github-bot closed this pull request 2026-12-01 18:43:49 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:42 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:42 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4341#issuecomment-7321381931) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

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!4342
No description provided.