Skip to content

obs-core: Port util/source-profiler.c - #1887

Merged
zackees merged 4 commits into
masterfrom
port/source-profiler
Oct 23, 2026
Merged

zackees merged 4 commits into
masterfrom
port/source-profiler

Conversation

@zackees

@zackees zackees commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #1886
Refs #1846
Refs #444

Unit 4 of #1846: libobs/util/source-profiler.c.h → obs_core::source_profiler, as one PR. obs-core rather than obs-util: the shim calls libobs core (gs_timer_*, obs_enter_graphics, obs_queue_task, source accessors).

No seam needed. The C's two private reads already have accessors with the same result: gs_enter_context(obs->video.graphics)/gs_leave_context() → obs_enter_graphics()/obs_leave_graphics() (identical when graphics exists; with NULL graphics the C only logs two LOG_DEBUG lines), and source->info.output_flags → obs_source_get_output_flags() (never asked for NULL). obs_source_get_last_async_ts() is already an internal accessor. No obs-internal.h change.

Commits

  • characterization: test/cmocka/test_source_profiler.c (graphics suite, Linux + OpenGL under xvfb). The frame hooks are hidden, so it runs real video with a scene holding a sync and an async source and waits on the tick event: disabled (false, result untouched), CPU results (relations, GPU/async fields zero, gpu_enable before enable dropped), unknown/NULL source (false, zeroed), async input fps, a destroyed source forgotten (last release run as a graphics task, so the removal runs inline, no UAF window), disable dropping entries.
  • RED: core with todo!(); soldr cargo test -p obs-data --test obs-tests-core obs_core::source_profiler: 1 passed (Send/Sync check), 28 failed on todo!("source-profiler port").
  • GREEN: the port, shim, export fragment obs-core-source_profiler.txt (4 public symbols), 11 hidden hooks (rust-hidden.txt, map, macOS list), new ported group libobs.ported-source-profiler + PCH, oracle, bench, README row.
  • obs-build (2 commits): master's native_test_graph_replaces_legacy_utility_definitions asserts 139 core tests while the graph has 141 (obs-qsv11: Log the Linux adapter probe and replay it in a test #1879 and frontend: Tell the user which source types a scene collection is missing #1883 each added one); count fixed, found because this PR edits the same assertion.

Tests

  • Tier 1: 29 cases (the six cmocka cases with a scripted clock and exact values; ring, tick/render/fps math, one-frame delay, stale ticks, GPU ranges/timers, disjoint frames, video reset, teardown).
  • Tier 2: layout of profiler_result_t and the obs_video_info fps fields vs the oracle; shim run against the cargo-test stand-ins; test_source_profiler against the C reference and hybrid libobs + exported-symbol diff: local rust/tools/linux-validate/run.sh: 379/379 cmocka tests pass OFF and ON (test_source_profiler included), exported symbols IDENTICAL (1766)
  • Tier 3: oracle/source_profiler.c is the unmodified C with clock, timers, context, task queue and log renamed to deterministic stand-ins. Proptest (512 cases, up to 60 ops) compares flags, samples, every ring (values/num/idx/capacity), fill_result for every source and an unknown one, destroyed timers/ranges, warnings and clock readings after each op; plus ucirclebuf and the math alone.
  • Mutation checks: collecting the current frame instead of the previous one fails the three sequence parity tests; counting equal fps timestamps (>= → >) fails parity_calculate.
  • obs-tests-core 823/823, obs-util --lib tests::platform (export list) 264/264, native graph tests 10/10, ./lint clean.
  • Tier 4: n/a.

port_comparison source_profiler_frame (16 sources: tick + 2 render passes each, collect, 16 fill_result): Rust 5.97 µs, C 8.05 µs.

Intentional differences (test files, rust/README.md, #1886): no LOG_DEBUG lines from gs_enter_context(NULL) without graphics; a ring of capacity 0 and a GPU frequency of 0 do not divide by zero (excluded from parity inputs); source removal takes the entry write lock (C mutates under the read lock); timers of dropped samples are destroyed in one graphics context after the sample lock is released (never waiting for the graphics context while holding it); a NULL timer out-pointer is not written.

@zackees
zackees force-pushed the port/source-profiler branch 3 times, most recently from 3eab6c0 to 0e05136 Compare October 23, 2026 05:44
test_source_profiler pins what libobs/util/source-profiler.c reports today
through util/source-profiler.h. The frame hooks are internal, so the cases
run core video with the OpenGL module and a scene holding a synchronous and
an asynchronous source, and wait for the video thread's tick (an event, no
sleeps). GPU timing stays off: gpu_enable while the profiler is disabled is
dropped. Cases: disabled (false, result untouched, NULL get_result), CPU
results (max >= avg, sum >= first pass, GPU and async fields zero), unknown
and NULL sources (false, result zeroed), async input fps from three output
frames, obs_source_remove forgetting the source, and disable dropping every
entry. Registered in the native test graph (graphics suite, Linux + OpenGL).

Refs #1846
obs_core::source_profiler is the safe core of libobs/util/source-profiler.c
with todo!() bodies: the ucirclebuf ring, the tick/render/fps math, per-source
sample bookkeeping over a FRAME_BUFFER_SIZE ring, GPU timers and ranges, and
the enable/disable state machine, over a Host trait for libobs. Tier 1 in
obs-tests-core: the six cases of test_source_profiler.c with a scripted
clock and exact values, plus the ring, the math, the one-frame delay, stale
ticks, GPU timing, disjoint frames, video reset and teardown.

soldr cargo test -p obs-data --test obs-tests-core obs_core::source_profiler:
1 passed (the Send/Sync check), 28 failed on todo!("source-profiler port").

Refs #1886
obs_core::source_profiler is the profiler: the ucirclebuf ring, the
tick/render/fps math, per-source samples collected one frame late, GPU
timers and ranges, the enable/disable state machine, over a Host trait.
The shim (ffi/source_profiler.rs) exports the four EXPORT functions
(rust-exports.d/obs-core-source_profiler.txt) and hides the eleven frame
hooks obs-internal.h declares. No seam: libobs is reached through
obs_enter_graphics/obs_leave_graphics (what gs_enter_context(obs->video.
graphics) does) and obs_source_get_output_flags, plus the existing internal
obs_source_get_last_async_ts. The C include moves to the new ported group
libobs.ported-source-profiler with its own PCH.

Tier 1: 29 cases. Tier 2 layout: profiler_result_t and the obs_video_info
fps fields against the oracle; the shim runs once against the cargo-test
stand-ins (oracle/source_profiler_host.c). Tier 3: oracle/source_profiler.c
is the C file with its clock, timers, context, task queue and log renamed to
deterministic stand-ins; random operation sequences compare flags, samples,
every ring, fill_result, destroyed timers/ranges and clock readings after
each step, plus the ring and the math alone (proptest). Mutation checks:
collecting the current instead of the previous frame fails the sequence
parity; counting equal fps timestamps fails parity_calculate.

port_comparison source_profiler_frame (16 sources, one frame + 16
fill_result): Rust 5.97 us, C 8.05 us.

Intentional differences (rust/README.md, #1886): no LOG_DEBUG lines from
gs_enter_context(NULL) without graphics; no division by zero for a ring of
capacity 0 or a GPU frequency of 0; source removal takes the entry write
lock; dropped samples' timers are destroyed in one graphics context after
the sample lock is released; a NULL timer out-pointer is not written.

Fixes #1886
@zackees
zackees marked this pull request as ready for review October 23, 2026 10:08
@zackees
zackees force-pushed the port/source-profiler branch from 0e05136 to 5ff38e9 Compare October 23, 2026 10:08
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
Merged via the queue into master with commit c9a6cce Oct 23, 2026
33 checks passed
@zackees
zackees deleted the port/source-profiler branch October 26, 2026 15:46
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.

rust: Port util/source-profiler.c to obs-core

1 participant