Skip to content

Instrumented profiler: FLING_PROFILE_SCOPE and --profile - #256

Merged
BenjaFriend merged 3 commits into
mainfrom
perf/profiler
Nov 17, 2026
Merged

BenjaFriend merged 3 commits into
mainfrom
perf/profiler

Conversation

@BenjaFriend

Copy link
Copy Markdown
Member

What

A small instrumented profiler, so a run can say where its time goes.

  • FLING_PROFILE_SCOPE("Name") (Profiler.h, Core) times a block on any thread. Scopes with one name add up, with a call count, a total, an average and the slowest call.
  • --profile turns it on and prints a table at exit. It works with --null-render, --offscreen and a window.
  • Off, a scope costs one relaxed atomic load. On, it costs two clock reads and three stores into the thread's own table (no lock, no allocation after the first call on a thread). Shipping builds remove it.
  • Scopes so far: the main loop (input, world update, present), Graphics.PublishSnapshot, the G-buffer pass steps, the pass recording and the wait for the GPU.

Example (Sandbox --offscreen --unattended --profile --frames 300):

scope                          calls      total        avg        max   wall%
Frame                            301    1252.00     4.1595   623.7692   54.0%
Vk.WaitForGpu                    301     535.61     1.7794     2.3843   23.1%
Graphics.PublishSnapshot         301      35.61     0.1183     0.3323    1.5%

Why

Linux perf is often blocked (perf_event_paranoid), and it cannot see the engine's own phases. This found the slowdown that the next PR fixes.

Tests

  • ProfilerTests (new): scopes count only while on, and add up across threads.
  • ctest: 685/685 pass.

Notes

  • In a window, use --play: without it the Sandbox starts the editor, which runs no ticks.
  • Measure in the build mode you care about. Debug is much slower than RelWithDebInfo for per-entity work.

🤖 Generated with Claude Code

https://claude.ai/code/session_017NN37Q2jpV81xZaX3ocojK

BenjaFriend and others added 3 commits November 17, 2026 11:01
A scope times a block on any thread. Scopes with one name add up, with a call
count and the slowest call. --profile turns it on and prints a table at exit
(works with --null-render, --offscreen and a window). Off, a scope costs one
atomic load; shipping builds remove it.

Scopes added: the main loop (input, world update, present), the snapshot
system, the G-buffer pass steps, the pass recording and the wait for the GPU.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017NN37Q2jpV81xZaX3ocojK
-DFLING_PROFILER=AUTO|ON|OFF (default AUTO: on unless DEFINE_SHIPPING). It
sets WITH_PROFILER (0 or 1, PUBLIC on Core). With 0 there is no Profiler
class, FLING_PROFILE_SCOPE is nothing, and --profile exits with code 3. ON
profiles a shipping build locally; OFF removes it from a dev build.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017NN37Q2jpV81xZaX3ocojK
Keep both the profiler scopes/option and main's occlusion culling.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@BenjaFriend
BenjaFriend merged commit a654f79 into main Nov 17, 2026
14 checks passed
@BenjaFriend
BenjaFriend deleted the perf/profiler branch November 17, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant