Repository navigation
obs-core: Port util/source-profiler.c - #1887
Merged
Merged
Conversation
zackees
force-pushed
the
port/source-profiler
branch
3 times, most recently
from
October 23, 2026 05:44
3eab6c0 to
0e05136
Compare
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
marked this pull request as ready for review
October 23, 2026 10:08
zackees
force-pushed
the
port/source-profiler
branch
from
October 23, 2026 10:08
0e05136 to
5ff38e9
Compare
This was referenced Oct 23, 2026
10 tasks done
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1886
Refs #1846
Refs #444
Unit 4 of #1846:
libobs/util/source-profiler.c.h→obs_core::source_profiler, as one PR.obs-corerather thanobs-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 twoLOG_DEBUGlines), andsource->info.output_flags→obs_source_get_output_flags()(never asked for NULL).obs_source_get_last_async_ts()is already an internal accessor. Noobs-internal.hchange.Commits
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_enablebeforeenabledropped), 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.todo!();soldr cargo test -p obs-data --test obs-tests-core obs_core::source_profiler: 1 passed (Send/Sync check), 28 failed ontodo!("source-profiler port").obs-core-source_profiler.txt(4 public symbols), 11 hidden hooks (rust-hidden.txt, map, macOS list), new ported grouplibobs.ported-source-profiler+ PCH, oracle, bench, README row.obs-build(2 commits): master'snative_test_graph_replaces_legacy_utility_definitionsasserts 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
profiler_result_tand theobs_video_infofps fields vs the oracle; shim run against the cargo-test stand-ins;test_source_profileragainst the C reference and hybrid libobs + exported-symbol diff: localrust/tools/linux-validate/run.sh: 379/379 cmocka tests pass OFF and ON (test_source_profilerincluded), exported symbols IDENTICAL (1766)oracle/source_profiler.cis 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_resultfor every source and an unknown one, destroyed timers/ranges, warnings and clock readings after each op; plusucirclebufand the math alone.>=→>) failsparity_calculate.obs-tests-core823/823,obs-util --lib tests::platform(export list) 264/264, native graph tests 10/10,./lintclean.port_comparison
source_profiler_frame(16 sources: tick + 2 render passes each, collect, 16fill_result): Rust 5.97 µs, C 8.05 µs.Intentional differences (test files, rust/README.md, #1886): no
LOG_DEBUGlines fromgs_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 NULLtimerout-pointer is not written.