fix(scripts): profile_report.py on Windows counts waits as running time and leaves the renderer's names mangled #1337

Open
opened 2026-11-17 03:54:23 +00:00 by dyst · 1 comment
Member

What happens

scripts/profile_report.py misreads a Windows profile from the profiling mode (#1279, HOS_PROFILE=1) in two ways. Found on the first Windows run of the mode (main @ 8e9cfc3a, Windows 11, Ryzen 9 3900X, RTX 3080 / NVIDIA 621.14, --maps <game folder>):

  1. Waits count as running time. prof.waiting (scripts/prof.py) calls a sample a wait when its innermost frame of Longshot's ends with one of WAIT_FRAMES. On Windows:

    • a thread sleeping in ntdll under sleep_away (host/hos_thread.c) is not in the list;
    • the renderer's frames are Itanium-mangled (longshot_vk:_ZN5mkwvk12_GLOBAL__N_14waitEyy), so endswith never matches a wait there.

    So the report's "hottest" on each thread leads with waiting: sead::MainThread "running 49 %", hottest mkwvk::(anonymous)::wait 6.7 % and sleep_away 5.7 %; the Presentation Thread's hottest is __libcpp_condvar_timedwait, 7.8 %. Stutter attribution ("running far more in stutters") is skewed the same way.

  2. The renderer's names stay mangled (_ZN5mkwvk12guarded_copyEPvPKvy): prof.demangle reads MSVC's ?name@ns@@ names only, and llvm-mingw's longshot_vk.map holds Itanium ones.

Suggested fix

  • In prof.waiting: on a Windows sample, a leaf in the system's own modules (ntdll.dll, KERNELBASE.dll, KERNEL32.DLL, win32u.dll) under a frame of Longshot's is a wait (a system call: sleeping, waiting, yielding), unless a known running frame says otherwise; and add sleep_away.
  • In prof.load_symbols: demangle the Itanium names of a Windows map once at load, with the toolchain's llvm-cxxfilt when it is there (the Linux path already gets nm -C's names).

A tools-only fix; the game is untouched. A PR follows. The game's crash on the same run is #383 (the sampler's unguarded stack walk).

🤖 Generated with Claude Code

## What happens `scripts/profile_report.py` misreads a Windows profile from the profiling mode (#1279, `HOS_PROFILE=1`) in two ways. Found on the first Windows run of the mode (main @ 8e9cfc3a, Windows 11, Ryzen 9 3900X, RTX 3080 / NVIDIA 621.14, `--maps <game folder>`): 1. **Waits count as running time.** `prof.waiting` (`scripts/prof.py`) calls a sample a wait when its innermost frame of Longshot's ends with one of `WAIT_FRAMES`. On Windows: - a thread sleeping in `ntdll` under `sleep_away` (`host/hos_thread.c`) is not in the list; - the renderer's frames are Itanium-mangled (`longshot_vk:_ZN5mkwvk12_GLOBAL__N_14waitEyy`), so `endswith` never matches a wait there. So the report's "hottest" on each thread leads with waiting: `sead::MainThread` "running 49 %", hottest `mkwvk::(anonymous)::wait` 6.7 % and `sleep_away` 5.7 %; the Presentation Thread's hottest is `__libcpp_condvar_timedwait`, 7.8 %. Stutter attribution ("running far more in stutters") is skewed the same way. 2. **The renderer's names stay mangled** (`_ZN5mkwvk12guarded_copyEPvPKvy`): `prof.demangle` reads MSVC's `?name@ns@@` names only, and llvm-mingw's `longshot_vk.map` holds Itanium ones. ## Suggested fix - In `prof.waiting`: on a Windows sample, a leaf in the system's own modules (`ntdll.dll`, `KERNELBASE.dll`, `KERNEL32.DLL`, `win32u.dll`) under a frame of Longshot's is a wait (a system call: sleeping, waiting, yielding), unless a known running frame says otherwise; and add `sleep_away`. - In `prof.load_symbols`: demangle the Itanium names of a Windows map once at load, with the toolchain's `llvm-cxxfilt` when it is there (the Linux path already gets `nm -C`'s names). A tools-only fix; the game is untouched. A PR follows. The game's crash on the same run is #383 (the sampler's unguarded stack walk). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Collaborator

Possibly related, for context:

  • PR #1321 fix(profiling): a Windows profile names its C++ code, counts its waits as waits, and gives a thread one row — Open fix for Windows profile wait attribution and demangling
  • issue #383 fix(host): HOS_SAMPLE_ALL can crash the game: the sampler's stack walk (RtlVirtualUnwind) is unguarded — Related Windows profiling sampler crash mentioned by reporter
Possibly related, for context: - PR #1321 fix(profiling): a Windows profile names its C++ code, counts its waits as waits, and gives a thread one row — Open fix for Windows profile wait attribution and demangling - issue #383 fix(host): HOS_SAMPLE_ALL can crash the game: the sampler's stack walk (RtlVirtualUnwind) is unguarded — Related Windows profiling sampler crash mentioned by reporter
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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
MagicBeanDev/Longshot#1337
No description provided.