Before you profile

What a recompiled game is to a profiler

A profiler sees an ordinary native process. Knowing its parts saves most of the confusion:

PartWhere it isWhat a profiler names it
The runtime (HLE kernel, services, NVN to Vulkan, audio, input)recompiled/<id>/<id>[.exe], a copy of scarletnx the driver put beside the gameits own symbols (C functions: buf_get, stage_set, svc_*, ...)
The game's recompiled code (AOT)recompiled/<id>/<id>_code.{so,dll}F_<guest address in hex>, from the module's .symtab (ir_codegen.c's snx_ir_guest_function)
Code the JIT compiled for functions the module missedanonymous executable memory in the JIT loader's arenanothing: [unknown], //anon, a bare address (The JIT)
The game's code under NCE (AArch64 Linux/Android, nce=1)the guest's own pages, at the guest's own addresses (g_mem is 0)nothing; the address is the guest address
The GPU driver, the Vulkan loader, libc, SDLshared librariestheir exports; a stripped driver stays addresses

Things that follow from this:

A build to profile with

BuildWhat it is for
The normal release build (cmake --preset default, or your build/rel)Throughput numbers, A/B timing, flat CPU profiles
cmake --preset tracy -B build/tracy && cmake --build build/tracyTracy, and any sampling profiler that needs call stacks: SNX_TRACY=ON adds -fno-omit-frame-pointer to the runtime (CMakeLists.txt), which -O2 otherwise drops
A build with -DCMAKE_BUILD_TYPE=RelWithDebInfoperf annotate and source lines in the runtime's code

A scene that repeats

A profile is only as good as its scene. Make the same work happen in every run:

games="${XDG_DATA_HOME:-$HOME/.local/share}/scarletnx/recompiled"
g="$games/<id>/<id>"
"$g" --state-load=2000:1 --input-replay=1 --frames=1800 --fps-limit=0 --vsync=0

tools/run_game.py runs the same thing unattended and prints the average FPS of the run; options it does not know go to the runtime:

python3 tools/run_game.py <id> --script "" --seconds 60 --fps-limit=0 --vsync=0 --out work/prof/base

Which tool for which question

The questionStart with
How fast is it, and is it smooth?the stats box (F12), --seconds' average FPS, tools/run_game.py
Which thread, and what is it doing frame by frame?Tracy
Which functions burn the CPU?perf, pmcstat, profile_cpu.py, Tracy's sampler
Is the frame rate bound by the CPU or the GPU?CPU-bound or GPU-bound
Which render pass costs the GPU?vk_gpu_profile=1, Tracy's GPU track
Which draw of that pass, and why?the GPU track's draw zones in a connected Tracy run, then RenderDoc and a vendor profiler
Is this shader translation faster than that one?snx-shaderperf
Did my change make the game faster?tools/bench_nvn_game.py

Made from docs/dev/profiling.md at 69237645142c. GPL-3.0-or-later.