A profiler sees an ordinary native process. Knowing its parts saves most of the confusion:
| Part | Where it is | What 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 game | its 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 missed | anonymous executable memory in the JIT loader's arena | nothing: [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, SDL | shared libraries | their exports; a stripped driver stays addresses |
Things that follow from this:
hle/kernel/thread.c), so per-thread views in every tool are per guest thread too.
The GPU thread, the recording thread, the JIT's threads (jit compile, jit miss), the audio and host1x workers
are host threads with names of their own.F_7100123450 is the guest function at 0x7100123450. Its real (demangled) name comes from the game's own symbol
tables, through tools/symbols.py (Naming the game's code)..symtab but no .eh_frame (link_elf.c writes neither it nor debug info), and its
functions are not compiled to keep frame pointers. Unwinders can name a sample inside the game's code, but a call
stack through it is cut or wrong. Read the game's code by self time; read call stacks for the runtime's code.| Build | What 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/tracy | Tracy, 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=RelWithDebInfo | perf annotate and source lines in the runtime's code |
SNX_DEPLOY off: the profiled runtime is not copied over every game. The driver still
hands a game the runtime it was started with, so the first run through build/tracy/scarletnx puts that runtime
beside the game, and the next run through a normal build puts the normal one back (Build).build/san), or between a Tracy build and a normal one.jit_opt's (2 by default), not CMake's.A profile is only as good as its scene. Make the same work happen in every run:
--state-load=at:slot loads a save state at a fixed time; --input-replay=N
plays a recorded input file (--input-record=N makes one, <game folder>/tas/<id>.<N>.snxtas); --script= presses
buttons at fixed times. See Run / diagnose. native_cond_var and native_os_sync
refuse save states; set them to 0 to take one, and keep them so for the comparison.--seconds=N or --frames=N, counted from the game's start after the shader loading screen.prepare_shaders=2) and makes its pipelines; the first run of a new scene JIT-compiles what the module missed.
Run the scene once, then profile the second run, unless the cold start is what you are measuring.--fps-limit=0 --vsync=0 lets a frame take as long as its work. With the game's pace on, a
fast frame waits, and the wait shows up as idle time rather than as a higher frame rate.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
| The question | Start 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.