Profiler: works under Wine (no thread cycle counter, unnamed system functions, inlined calls without their path) #959

Open
UwUCammie wants to merge 1 commit from upstream-pr/960 into main
UwUCammie commented 2026-11-25 13:49:51 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by UwUCammie on 2026-11-25T13:49:51Z.


What was wrong

Under Wine VICTORY_PROFILE=1 wrote a report with every number at zero: 328,651 looks, all of them counted as failed, no stack taken and an empty .folded file. Three things in Wine's libraries differ from Windows:

  1. QueryThreadCycleTime is a stub that fails for every thread. A look took the failure for "the thread ended" and returned before taking the stack.
  2. Wine's dbghelp names nothing in ntdll, kernelbase and the other system modules when their debug files are not installed. Every innermost frame was ntdll.dll+0x..., so no wait was recognised as one.
  3. It names an inlined call by its last part alone (lock, wait, wait_on_address), where Windows gives the whole path. The language's runtime was then taken for code of ours, and a wait was given to wait_on_address instead of the function that waited.

What the change does

  • Whether the counter answers is asked once, on the sampler's own thread. Without it every look takes the stack, the busy threads are found by their processor time (GetThreadTimes) from one scan to the next, and the report says in its header that "on cpu" is not known.
  • A function that starts at an export is named from the module's own export table when the symbol library has no name for it (exports_of: a bounded read of the loaded image's export directory, forwarders left out).
  • An inlined call whose name has no path gets it back from the source file of the call: library/std/src/sync/mutex.rs is std::sync::mutex, crates/victory-gpu/src/draw.rs is victory_gpu::draw. Files anywhere else are left as they are.

Where the counter answers and the names come with their paths, as on Windows, none of the three paths is taken.

How it was tested

RX 7900 XT, RADV (Mesa 26.3.1), Wine 11.22 with vkd3d-proton from GE-Proton11-14.

  • cargo test -p victory-gpu --features diagnostics --locked profile:: under Wine: 10 passed, 1 ignored (the measurement). Before the change time_goes_to_the_function_that_spent_it and the_sampler_finds_threads_and_writes_its_files failed there. One assertion of the first is now made only where the counter exists (a waiting thread is not suspended again): without the counter nothing says a thread has not run. a_source_file_says_whose_inlined_code_it_is is new.
  • cargo clippy -p victory-gpu --features diagnostics --all-targets --locked: the same 5 warnings with and without the change, none in profile.rs.
  • In the title, with the first two parts of the change (the third came after and is covered by the unit tests only), VICTORY_PROFILE_HZ=250:
sampled 270.0 s in 64715 looks (250 asked a second, 4.17 ms between looks, 1038 late); 876 frames presented meanwhile (308.2 ms a frame)
21 threads followed (21 still running); a thread looked at stood still under 41 us half the times, under 1049 us 99 in 100, [...] 1349697 times; 256203 call sites kept
the system does not count a thread's cycles here (QueryThreadCycleTime fails, as it does under Wine): every look took the thread's stack, and "on cpu" is not known and reads 0

and the tables name the waits (ntdll!NtWaitForSingleObject, ntdll!NtWaitForAlertByThreadId) and the system calls (ntdll!NtReadVirtualMemory, ntdll!NtWriteVirtualMemory, ntdll!NtProtectVirtualMemory).

A look costs more under Wine (suspending a thread and reading its registers are requests to the wineserver, about 78 us on average here), so 250 looks a second is a better rate there than the default 1,000.

Not tested: native Windows. I have no Windows machine; a run of the profiler tests there by someone who has would be welcome.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6605996047 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/960). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-25T13:49:51Z. --- ## What was wrong Under Wine `VICTORY_PROFILE=1` wrote a report with every number at zero: 328,651 looks, all of them counted as failed, no stack taken and an empty `.folded` file. Three things in Wine's libraries differ from Windows: 1. **`QueryThreadCycleTime` is a stub that fails for every thread.** A look took the failure for "the thread ended" and returned before taking the stack. 2. **Wine's dbghelp names nothing in ntdll, kernelbase and the other system modules** when their debug files are not installed. Every innermost frame was `ntdll.dll+0x...`, so no wait was recognised as one. 3. **It names an inlined call by its last part alone** (`lock`, `wait`, `wait_on_address`), where Windows gives the whole path. The language's runtime was then taken for code of ours, and a wait was given to `wait_on_address` instead of the function that waited. ## What the change does - Whether the counter answers is asked once, on the sampler's own thread. Without it every look takes the stack, the busy threads are found by their processor time (`GetThreadTimes`) from one scan to the next, and the report says in its header that "on cpu" is not known. - A function that starts at an export is named from the module's own export table when the symbol library has no name for it (`exports_of`: a bounded read of the loaded image's export directory, forwarders left out). - An inlined call whose name has no path gets it back from the source file of the call: `library/std/src/sync/mutex.rs` is `std::sync::mutex`, `crates/victory-gpu/src/draw.rs` is `victory_gpu::draw`. Files anywhere else are left as they are. Where the counter answers and the names come with their paths, as on Windows, none of the three paths is taken. ## How it was tested RX 7900 XT, RADV (Mesa 26.3.1), Wine 11.22 with vkd3d-proton from GE-Proton11-14. - `cargo test -p victory-gpu --features diagnostics --locked profile::` under Wine: 10 passed, 1 ignored (the measurement). Before the change `time_goes_to_the_function_that_spent_it` and `the_sampler_finds_threads_and_writes_its_files` failed there. One assertion of the first is now made only where the counter exists (a waiting thread is not suspended again): without the counter nothing says a thread has not run. `a_source_file_says_whose_inlined_code_it_is` is new. - `cargo clippy -p victory-gpu --features diagnostics --all-targets --locked`: the same 5 warnings with and without the change, none in `profile.rs`. - In the title, with the first two parts of the change (the third came after and is covered by the unit tests only), `VICTORY_PROFILE_HZ=250`: ``` sampled 270.0 s in 64715 looks (250 asked a second, 4.17 ms between looks, 1038 late); 876 frames presented meanwhile (308.2 ms a frame) 21 threads followed (21 still running); a thread looked at stood still under 41 us half the times, under 1049 us 99 in 100, [...] 1349697 times; 256203 call sites kept the system does not count a thread's cycles here (QueryThreadCycleTime fails, as it does under Wine): every look took the thread's stack, and "on cpu" is not known and reads 0 ``` and the tables name the waits (`ntdll!NtWaitForSingleObject`, `ntdll!NtWaitForAlertByThreadId`) and the system calls (`ntdll!NtReadVirtualMemory`, `ntdll!NtWriteVirtualMemory`, `ntdll!NtProtectVirtualMemory`). A look costs more under Wine (suspending a thread and reading its registers are requests to the wineserver, about 78 us on average here), so 250 looks a second is a better rate there than the default 1,000. **Not tested:** native Windows. I have no Windows machine; a run of the profiler tests there by someone who has would be welcome.
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/960:upstream-pr/960'
git switch 'upstream-pr/960'

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/960'
git switch 'upstream-pr/960'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/960'
git switch 'upstream-pr/960'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/960'
git switch 'main'
git merge --squash 'upstream-pr/960'
git switch 'main'
git merge --ff-only 'upstream-pr/960'
git switch 'main'
git merge 'upstream-pr/960'
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
fxceless/victory-fork!959
No description provided.