Skip to content

engine: execution profiler with per-node render and GPU timings - #2420

Open
jcelerier wants to merge 2 commits into
masterfrom
split/profiler
Open

jcelerier wants to merge 2 commits into
masterfrom
split/profiler

Conversation

@jcelerier

Copy link
Copy Markdown
Member

The Benchmark setting only measured each node's run() in the audio graph, once every 50 ticks, and showed one percentage in the process header. A gfx process's audio node only queues messages for the render thread, so the real cost of graphics never showed up anywhere. This adds a profiler that covers both the audio graph and the render thread, including GPU time, with a panel and a script API.

Graphics side (Gfx/Graph/NodeProfiler):

  • Each GfxContext owns a NodeProfiler. Its render lists fill it while profiling is on: one FrameTiming per frame and output, with, for every node, the render-thread time of its update and command recording, its GPU time, and the bytes of the render targets the list allocates for its inputs.
  • GPU time comes from timestamps written between passes (Vulkan timestamp query pools, desktop GL timer queries; other backends report CPU time only). Each stamp closes the span since the previous one and gives it to the nodes passed. The shared pass of a sink input is split evenly between the sources drawing into it, and such a time is flagged gpu_shared. Results are read four frames later without waiting. Frames whose GPU results are not ready are reported with CPU times only. Preview outputs are not profiled.

Engine side (Execution/Profiler):

  • Execution::Profiler, owned by the execution document plug-in, keeps, per process: audio time per tick and its share of the tick, render-thread and GPU time per frame (nodes mapped to processes through their gfx_exec_node ids), render-target memory, and averages and maxima over the last 64 samples. It also keeps the audio load and frame times over time, plus the ticks and frames over a threshold, with their slowest nodes.
  • The benchmark tick now measures every tick, accumulates per node, and reports every 50 ticks. Load is computed against the ticks' actual durations.
  • Process headers show the dominant cost through a new benchmarkLabel signal: GPU ms for gfx nodes, % of the tick for audio nodes. A "~" marks a GPU time that includes a shared pass. The old benchmark(double) signal is removed.
  • A Profiler panel (Ctrl+Alt+P): Benchmark toggle, spike thresholds, timelines, a sortable per-process tree grouped by interval with subtotals and bars, click to select, "selected only", the kept spikes, and JSON export.
  • Scripts: Score.profile(), clearProfile(), profiling() / setProfiling() (the saved Benchmark setting) and setProfileSpikes().

The audio thread never allocates for this. Three reports circulate between it and the GUI through preallocated queues (AudioBenchChannel), the per-node map keeps its capacity, and a report keeps at most 16 spikes of its 8 slowest nodes in fixed arrays.

Commits

  • 66ca39cacb gfx: per-node render timings. A render list creates its profiler once profiling is on, after it has rebuilt itself for the frame (an output resize releases it). It releases the profiler, with its query pools, when profiling goes off.
  • 0ea473eeb6 engine: execution profiler for audio and render nodes. profile() first pulls the measures still queued, because a script driving renderFrames() blocks the timers that would otherwise collect them.

Tests

  • New test_unit_profiler: series keep their last values, render frames feed nodes and totals, frames over the threshold are kept with their slowest nodes, audio load is computed over the report's whole duration, per-kind spike caps, spike generation past the cap, and audio reports circulating between the audio thread and the GUI.
  • New test_unit_gfx_node_profiler: without GPU timestamps a frame is submitted with its CPU times.
  • New test_gfx_profiler_rebuild: profiling survives an output rebuild and being turned off and on.
  • The whole series was built and tested with ctest on Linux (Xvfb, lavapipe Vulkan and Mesa OpenGL). Nothing failed beyond master's own known failures (test_gfx_shader_corpus_targets, test_gfx_window_layout, test_threedim_ply_fingerprint, test_unit_miniaudio_alsa and the few others master's run lists).

Notes for review

  • Removing Process::ProcessModel::benchmark(double) is an API change for plug-ins that connected to it.
  • GPU time splitting between sources that share a pass is an approximation, because passes can overlap on the GPU. The gpu_shared flag and the "~" in headers say so.
  • The render list's existing frame GPU timing stored lastCompletedGpuTime() (seconds) as milliseconds. That is fixed later in the series, in the multi-window output PR (bdbf376952), not here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KdPgujQFUTMVZBdH6Hv7Vj

jcelerier and others added 2 commits November 25, 2026 10:28
Each GfxContext now owns a NodeProfiler that its render lists fill while
it is enabled: one FrameTiming per frame and output, with, for every
node, the render-thread time of its update and command recording, its GPU
time, and the bytes of the render targets the list allocates for its
inputs.

GPU time comes from timestamps written between passes (Vulkan timestamp
query pools, desktop GL timer queries; other backends report CPU time
only). Each stamp closes the span since the previous one and gives it to
the nodes passed: a source's initial passes to that source, the shared
pass of a sink input split evenly between the sources drawing into it,
preview taps to no one. Passes can overlap on the GPU, so the split is
per node rather than exact, and a node whose time includes such a split
says so (gpu_shared). Results are read four frames later, without
waiting: a frame whose GPU results are not ready is reported with its CPU
times only, and one whose slot was not revisited four frames later is
dropped. Preview outputs are not profiled.

The profiler of a render list is created once profiling is on, after the
list rebuilt itself for the frame (an output resized releases it), and
released when profiling goes off, with its query pools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgufk1W2MBbpcjraruZq
The Benchmark setting only ever measured each node's run() in the audio
graph, once every 50 ticks, and showed one percentage in the process
header. A gfx process's audio node only queues messages for the render
thread, so its real cost never appeared.

Execution::Profiler, owned by the execution document plug-in, now keeps
per process: audio time per tick and its share of the ticks' duration,
render-thread and GPU time per frame (fed by the graphics plug-in from the
render lists' NodeProfiler, nodes mapped to processes through their
gfx_exec_node ids), render-target memory, and averages and maxima over the
last 64 samples; plus the audio load and frame times over time, and the
ticks and frames over a threshold with their slowest nodes.

- The benchmark tick measures every tick, accumulates per node, and
  reports every 50 ticks; load is computed against the ticks' actual
  durations.
- Process headers show the dominant cost (GPU ms for gfx nodes, % of the
  tick for audio ones) through a new benchmarkLabel signal.
- A Profiler panel (Ctrl+Alt+P): Benchmark toggle, spike thresholds,
  timelines, a sortable per-process tree grouped by interval with
  subtotals and bars, click to select, "selected only", the kept spikes,
  JSON export.
- Score.profile(), clearProfile(), profiling() / setProfiling() (the
  Benchmark setting, which is saved) and setProfileSpikes() in scripts.
  profile() first pulls the measures still queued, as a script driving
  renderFrames() blocks the timers that would otherwise.

The audio thread never allocates for this: three reports go round between
it and the GUI through preallocated queues (AudioBenchChannel), the
per-node map keeps its capacity, and a report keeps at most 16 spikes of
its 8 slowest nodes in fixed arrays. The GUI takes the reports with the
edit commands, and profile() takes them alone. A header shows its label
only when it changes, a GPU time that includes a shared pass with a "~",
and the labels go when Benchmark is turned off. The old benchmark(double)
signal goes: headers clear through benchmarkLabel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPgufk1W2MBbpcjraruZq

This branch is waiting to be deployed

1 waiting deployment
full-ci — 0ea473ee Waiting Nov 25, 2026 by jcelerier via Approve full PR suite #9
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