Skip to content

obs-media-io: register the audio thread as a profiler root with its tick period (Fixes #5769) - #5774

Merged
vpacher merged 4 commits into
masterfrom
fix/5769-audio-thread-profiler-root
Nov 26, 2026
Merged

vpacher merged 4 commits into
masterfrom
fix/5769-audio-thread-profiler-root

Conversation

@vpacher

@vpacher vpacher commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #5769. Part of #5768 (thread priority on Linux and macOS, discussion #5458).

Change

The audio thread now registers its profiler name as a root, with the tick period as the expected time between calls (audio_frames_to_ns(rate, AUDIO_OUTPUT_FRAMES), 21.333 ms at 48 kHz). The graphics thread already does this with its frame interval. Result: the profiler output at quit shows how regularly the audio thread mixes, in a normal OBS log on every platform. The other sub-issues of #5768 use this line to measure their effect.

The mixing itself does not change: the thread makes one more profiler call before its loop.

RED → GREEN

  • RED 3affc97: audio_thread_registers_profiler_root_with_tick_period (media-io library harness, tests/audio/audio_io.rs). The test starts obs-util's profiler, opens an audio output at 48 kHz and at 44.1 kHz, waits for a tick, and looks for a profiler root that expects the tick period. Before the change it failed:
    48000 Hz: no profiler root expects 21333 us between calls (roots: [0]).
    In the test binary the oracle's name store is NULL, so the test finds the root by its expected time, not by its name.
  • GREEN b6e5936: one profile_register_root(audio_thread_name, period) call after the name is stored. All 403 tests of the media-io harness pass. Clippy and rustfmt are clean.

Tiers:

  • Tier 1: the new test.
  • Tier 2: no C test covers the profiler output of the audio thread. The cmocka audio-io tests do not change.
  • Tier 3: the C original has no such call. The existing audio_io_parity cases (mixed output against the C oracle) pass unchanged.

Real app

macOS build (RelWithDebInfo, M1 Max), OBS run for 40 s, then quit. Profiler output before this change: no audio_thread line in "Time Between Calls". After:

audio_thread(Audio): min=0.004 ms, median=0.041 ms, max=5.241 ms, 99th percentile=4.791 ms, 100% below 21.333 ms
...
== Profiler Time Between Calls ==================
audio_thread(Audio): min=16.339 ms, median=21.309 ms, max=26.324 ms, 16.9751% within ±2% of 21.333 ms (42.3585% lower, 40.6663% higher)
obs_graphics_thread(33.3333 ms): min=32.313 ms, median=33.334 ms, max=34.349 ms, 72.629% within ±2% of 33.333 ms (13.5607% lower, 13.8103% higher)

At idle on macOS, only about 17 % of the audio ticks are within ±2 % of the period. That agrees with the lateness measured in #5458 for a default-priority thread, and it is the baseline for #5771.

Not run on Linux in the real app. The code path is the same on all platforms (no platform code).

Test cost

New test: longest 0.10 s, peak RSS 8.8 MB over 25 runs. It starts no threads of its own; each audio_output_open starts the audio thread, one at a time.

The test runs in its own child process (f269d34), as obs-util's isolated() does. In the test binary every audio thread registers the same NULL-named root, so the audio output of a parallel test overwrote the expected time on Windows (run 45793492596: 44100 Hz: no profiler root expects 23220 us between calls (roots: [21333])). The child adds one process start, about 0.1 s.

Ledger

docs/features.md, Performance: "Audio thread regularity in the log".

🤖 Generated with Claude Code

@vpacher
vpacher requested a review from zackees as a code owner November 26, 2026 09:35
@vpacher
vpacher enabled auto-merge November 26, 2026 09:43
Every audio thread in the test binary registers the same NULL-named
profiler root, so an audio output of a parallel test overwrote the
expected time between the 48 kHz and 44.1 kHz checks (Windows Rust Tests,
run 45793492596: 44100 Hz roots [21333]). The test now re-runs itself
alone with --exact --test-threads=1, as obs-util's isolated() does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zackees
zackees disabled auto-merge November 26, 2026 10:02
@vpacher
vpacher added this pull request to the merge queue Nov 26, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this to In merge queue in obs-rust Multiview Nov 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 26, 2026
@vpacher
vpacher added this pull request to the merge queue Nov 26, 2026
Merged via the queue into master with commit 6333e3a Nov 26, 2026
90 of 92 checks passed
@vpacher
vpacher deleted the fix/5769-audio-thread-profiler-root branch November 26, 2026 12:49
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In merge queue to Done in obs-rust Multiview Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

perf: obs-media-io: register the audio thread as a profiler root

1 participant