fix(profiling): a Windows profile names its C++ code, counts its waits as waits, and gives a thread one row #1321
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1321
Loading…
Reference in a new issue
No description provided.
Delete branch "madebyjordan/Longshot:fix/profile-report-names"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: fix · Risk: low · Tested on: Windows 11, RX 6700 XT · Needs: none
Why
On Windows, the profiling mode's report (#1279,
HOS_PROFILE=1) mixes two kinds of names, and that puts wrong numbers in three places (found testing #1279 on Windows, #1279 (comment)):prof.demangleonly knew MSVC's. The report's hot code showed_ZN5mkwvk12_GLOBAL__N_14waitEyywhere the Linux report showsmkwvk::(anonymous namespace)::wait(...).WAIT_FRAMES. Mangled names never matched, and on either system a C++ name with its parameters (...condition_variable::wait(std::__1::unique_lock<...>&), asnm -Cgives it) didn't either. The host's sleeps now block insleep_away, which wasn't in the list. So threads asleep all run long came out running 99-100 % of the time (the renderer's replay and recorder threads, the vibration thread), and the main thread 63 %.prof: threads innames (mkw_vk replay) against the samplers' (mkw_vk_replay). Each thread with a space in its name got one row with its CPU % and another with its samples.How to reproduce
Seen on: Windows 11, RX 6700 XT, main @
8e9cfc3a(#1279's merge commit).Steps: run the game with
HOS_PROFILE=1(a minute is enough), thenpython -I scripts/profile_report.py <game folder>/logs/profile-<date>-<time> --no-trace.Expected: the C++ frames named as on Linux (
mkwvk::...), a thread asleep in a wait not counted as running, one Threads row a thread.Actual:
_ZN...names; the renderer's replay and recorder threads running 99-100 % of their samples while the log gives them ~30-35 % of a core;mkw_vk replayandmkw_vk_replayon two rows.What changed
The report now names a Windows build's C++ code the way the Linux report does, so its waits are recognised and a sleeping thread no longer counts as busy. Each thread also gets a single row in the Threads table.
scripts/prof.py:load_mapdemangles a map's Itanium names (_Z...) asnm -Cdoes on Linux (demangle_all). The demangler isllvm-cxxfiltorc++filt(demangler()): from the PATH,LONGSHOT_MINGW, or the llvm-mingw of a build tools folder on the PC (scripts/dev_build.py's, the Longshot Launcher's). A name that isn't Itanium (C, MSVC's, a lifted import'simp__ZN..., whichscripts/cpu_report.pyreads) stays as it is, and so does every name when there is no demangler.crit.py,hotlist.py,vkprof.pyandchain.pyread maps through it too.waiting()compares a frame's name without its parameter list (bare()).WAIT_FRAMESgainssleep_away(host/hos_thread.c: wherehos_sleep_nsand the guest's sleeps block), libc++'s__libcpp_condvar_wait/__libcpp_condvar_timedwait, and the renderer's wait for a GPU fence (mkwvk::(anonymous namespace)::wait, vk_replay.cpp).scripts/profile_report.py: the log's thread names are written as the samplers write them (spaces and|made_), so a thread has one row.tests/test_profile_report_names.py(new; the first commit, failing on main for each of the three): a made-up Windows map's names, the waits, and a made-up profile folder's Threads table. Without a demangler on the PC, the demangling part says so and is skipped.Measurements
Verdict: the report's running shares now agree with the measured CPU.
Hardware: Windows 11, Ryzen 5 5600 (6 cores), 16 GB, RX 6700 XT, AMD 26.10.1
Scene: the menu after the start, headless,
HOS_PROFILE=1, ~11 minutes (a game built from main @8e9cfc3a)Method: one profile folder read by
scripts/profile_report.pyon each side (the report is deterministic: one run each); the log's CPU is itsprof: threads in 5 slines in playHow to reproduce:
python -I scripts/profile_report.py <profile folder> --no-traceon main and on this PR, then the report's Threads table and its At a glance lines6d72ca935506d389longshot:sleep_away27.6 %,_ZN5mkwvk12_GLOBAL__N_14waitEyy5.9 %longshot:spin_until_set3.2 %,mkwvk::guarded_copy(void*, void const*, unsigned long long)3.0 %Flags and settings
None new. To find a demangler,
scripts/profile_report.pyalso readsLONGSHOT_MINGW, which already exists (docs/development.md, the llvm-mingw to build with); nothing sets or changes it.Testing
Tested:
tests/test_profile_report_names.pyfails on main for each of its three parts (demangling, withllvm-cxxfilton the PATH; the waits; the Threads rows) and passes here, with a demangler and without one (LOCALAPPDATAhidden: the demangling part skipped).tests/test_prof_symbols.pyandtests/test_profile_stream.pypass.python -I -B tests/run_all.pyon Windows: 589 passed, 42 failed, 90 skipped; main @6d72ca93on the same PC at thesame time: 588 passed and the same 42 failed (
test_auto_handheld,test_bug_report,test_bug_report_defaults,test_cpu_report,test_crash_dialog,test_crash_groups,test_crt_options,test_damage_debug_menu,test_display_startup_failure,test_dlss_feature_size,test_failed_compile_keeps_objects,test_framegen_preset,test_guest_imported,test_hardware_report,test_hud_layout_row,test_invalidate_vcore,test_job_queue,test_linux_preflight,test_linux_pressure,test_mirror_budget,test_missing_nup,test_pads_after_menu,test_pending_guest_import,test_perf_report,test_pipeline_play_cache,test_portable_builder_home,test_portable_builder_startup,test_present_thread,test_profiling_mode,test_readback_timeout_source,test_rumble_menu,test_run_all_changed,test_slow_frames,test_switch_table,test_target_image_pool,test_tested_configurations,test_upscaler_round_trip,test_upscaler_rows,test_vcore_escape,test_vk_occlusion_queries,test_vk_swapchain_compat,test_walk_key).Not tested: Linux, where
nm -Cnames the frames already. The waits now match there too, so a Linux report's running shares drop the same way; that's the intent ofWAIT_FRAMES. TrashPanda asked for that Linux read (review on5506d389): the same profile folder read on main and on this PR, with the waits out of the running shares and one row a thread. It's still to do.Must be tested:
python -I scripts/profile_report.py <a HOS_PROFILE=1 folder> --no-traceon main and on this PR, expecting the C++ waits (std::...::condition_variable::wait,sleep_away) out of the running shares and one Threads row a threadRisks
What could break: a script that matched a mangled
_Z...name read throughprof.load_map(none in the repository:cpu_report.pyhas its own map reader and matchesimp__ZN...). Running shares in reports go down where threads were asleep.Turning it off: revert the commit.
Compatibility: scripts only; no game, cache or file format change.
Issues
Found testing #1279 on Windows (its "Must be tested"). Prior work: none open (searched
demangle,profile_report,GetThreadTimes,thread names).Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.🤖 Generated with Claude Code
tests/test_profile_report_names.py: a made-up Windows linker map's Itanium names (llvm-mingw) come out of prof.load_map as nm -C gives them on Linux, a plain C name and a lifted import's name unchanged; a sample asleep in a wait with a C++ name's parameters (std::condition_variable::wait, libc++'s timed wait, the renderer's GPU wait) or in host/hos_thread.c's sleep_away counts as waiting; and profile_report.py's Threads table puts the log's CPU % ("mkw_vk replay") on the samples' row ("mkw_vk_replay"). Fails on main for each of the three. Co-Authored-By: Claude Opus 5.5 <[email protected]>A Windows profile names its C++ code, counts a wait as a wait, and gives each thread one row. I read head
5506d389. It applies onto current main, and this stays a comment.A map's Itanium names (
_Z...) are demangled the way Linux already names them. A name that is not Itanium is left as it is, and so is every name when there is no demangler. A wait is matched without the parameter list, and the list now includessleep_away, libc++'s condition waits, and the renderer's fence wait. The log's thread names lose spaces and|the same way the sampler writes them (host/mkw_glue.c). On Windows, an RX 6700 XT, the replay thread's running share goes from 99 % on its own row to 41 % on the row that also has its CPU time, against about 35 % of a core in the log.The Linux read this asks for is still open: the same profile folder on main and on this branch, with those waits out of the running shares and one row a thread.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.