Skip to content

rust: Port the profiler snapshot accessors to obs-util - #88

Merged
zackees merged 3 commits into
obs-rust:masterfrom
b7216309-jpg:port/profiler-snapshot
Oct 10, 2026
Merged

zackees merged 3 commits into
obs-rust:masterfrom
b7216309-jpg:port/profiler-snapshot

Conversation

@b7216309-jpg

Copy link
Copy Markdown
Contributor

Description

First slice of the profiler.c port (#44): the snapshot accessors and profile_snapshot_free, 16 exported functions.

Commit 1, C only, behavior-neutral (testing policy, "Extracting a function before porting it"). These move verbatim out of profiler.c:

  • struct profiler_snapshot and struct profiler_snapshot_entry go into a new private header, util/profiler-snapshot.h. It is not installed, and profiler.c includes it because it still builds snapshots.
  • free_snapshot_entry, profile_snapshot_free and profiler_snapshot_num_roots … profiler_snapshot_entry_overall_between_calls_count (the end of the file) go into util/profiler-snapshot.c.

Signatures and public headers do not change. Both files compile cleanly with MSVC, with no implicit declarations.

Commits 2–3, RED then GREEN: the Rust port (obs-util::profiler_snapshot).

  • profiler.c stays C and still builds snapshots with bmalloc and DARRAY. The shims read and free them in place through #[repr(C)] mirrors of profiler-snapshot.h, using the same bfree, da_free and da_erase steps (the existing ffi::darray helpers).
  • The safe core holds the two loops, generic over a small EntryList trait so they run over the C darray and over a Vec:
    • enumerate stops when the callback returns false;
    • filter removes a marked entry before honoring a stop, and only advances past entries that stay.
  • Intentional differences, where C would crash: a NULL snap to profiler_snapshot_filter_roots, and a NULL callback with entries to visit, do nothing.

Motivation and Context

#44 lists profiler.c, and nobody has claimed it (#76, #77, #78 and #87 cover other Phase 4 files). The rest of profiler.c (the call tracking, the times hash map, printing and CSV dumps) can follow in later slices on top of this one.

Refs #44

How Has This Been Tested?

Windows 11, MSVC 14.44, soldr 0.9.31.

  • test/cmocka/test_profiler.c is unchanged. Its lifecycle test enumerates, reads every getter, filters out a root and frees snapshots that profiler.c built, so with ON, Tier 2 runs C-built snapshots through the Rust accessors.
  • Tier 1: the loops on Vec, including removing the entry the callback stops on and removing consecutive entries.
  • Tier 2: layout of profiler_snapshot, every field of profiler_snapshot_entry, and profiler_time_entry, against the oracle.
  • Tier 3 (512 cases): the same random snapshot (roots and children up to depth 2, time arrays, spare capacity) is built in bmalloc memory for both sides. The test compares the root and child enumeration with early stops, every getter (the times getters must return the entry's own darray), and filter_roots driven by a scripted series of answers, where a callback sometimes leaves *remove untouched. It then checks the remaining roots, num and capacity, and frees both. NULL inputs are compared too.
  • Mutation check, all 8 caught: filter always advances, stop before removing, enumerate ignores false, min_time reads max_time, remove initialized to true (caught after adding the leave-*remove-alone answers), the between-calls getter returns times, num_roots returns capacity, erase at the wrong index. Freeing is exercised but not counted.
  • soldr cargo test --workspace (38 binaries), python ci/local_gate.py --lane lint, and cargo clippy -p obs-util -p libobs-rust --lib -- -D warnings for x86_64/aarch64 Linux and aarch64 macOS.

Types of changes

  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

🤖 Generated with Claude Code

@zackees
zackees force-pushed the port/profiler-snapshot branch 2 times, most recently from c50ae21 to 25404e4 Compare October 10, 2026 16:47
@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Maintainer update: rebased onto current master (resolved README / obs-c-oracle conflicts with vec3, obs-nal, video-fourcc by keeping both sides; no logic changes). RED commit verified: 6 Tier 1 tests panic on todo!(). GREEN: full workspace cargo test passes; local gate (lint, rust-test, tier2-linux OFF/ON) passed and stamped.

@zackees
zackees force-pushed the port/profiler-snapshot branch 2 times, most recently from d07b908 to bf571d0 Compare October 10, 2026 17:43
b7216309-jpg and others added 3 commits October 10, 2026 10:55
Behavior-neutral move ahead of the Rust port of the snapshot accessors
(docs/rust-port/testing-policy.md, "Extracting a function before
porting it"). Moved verbatim from profiler.c:

- struct profiler_snapshot and struct profiler_snapshot_entry, into the
  new private header profiler-snapshot.h, which profiler.c includes
  because it still builds snapshots;
- free_snapshot_entry and profile_snapshot_free;
- profiler_snapshot_num_roots through
  profiler_snapshot_entry_overall_between_calls_count, the end of the
  file.

No signature, public header or behavior changes. profiler-snapshot.h is
not installed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
C ABI shims for the 16 exports of libobs/util/profiler-snapshot.c
(profile_snapshot_free and the profiler_snapshot_* accessors), with
rust-exports.txt entries, and Tier 1, Tier 2 layout and Tier 3 tests.

The enumerate and filter loops in the safe core are todo!(): Tier 1
fails 0/6, the parity binary aborts on its first call, and the layout
tests pass 3/3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The snapshot accessors and profile_snapshot_free move to Rust. With
ENABLE_RUST_LIBOBS=ON libobs builds without util/profiler-snapshot.c.
profiler.c still builds snapshots in C, so the shims read and free them
in place through mirrors of profiler-snapshot.h, with the same bfree,
da_free and da_erase steps.

The core keeps the C loop rules: enumeration stops when the callback
returns false; filtering removes a marked entry before honoring a stop,
and only advances past entries that stay.

Intentional differences, where C would crash: a NULL snap to
profiler_snapshot_filter_roots, and a NULL callback with entries to
visit, do nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=6e7735eec51936f713dfc5be229d9e529bb898ed secs=18 lanes=lint:reused@b5c506257d92,rust-test:reused@237544c5f4e4,tier2-linux:run
Ci-Attestation: {"at":1791654979,"gate":"rust/all/fmt","host":"linux-x86_64","key":"b5c506257d92bfd3ce6ec00fb127611cb53cafaf428514f21d7d52997b30e275","lane":"lint","parents":["1dd28aa00d66da1a4cbc808c0a8073f44c38fbcc"],"secs":null,"stamp":"0362130a62c2c8ef4f0e86b9f30e7e8d","tree":"6e7735eec51936f713dfc5be229d9e529bb898ed","v":1,"via":"reused"}
Ci-Attestation: {"at":1791654979,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"b5c506257d92bfd3ce6ec00fb127611cb53cafaf428514f21d7d52997b30e275","lane":"lint","parents":["1dd28aa00d66da1a4cbc808c0a8073f44c38fbcc"],"secs":null,"stamp":"50c8321dd10d48c44c1026958c9c2e64","tree":"6e7735eec51936f713dfc5be229d9e529bb898ed","v":1,"via":"reused"}
Ci-Attestation: {"at":1791654979,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"237544c5f4e4da9573b02de2c615267365099bd974860b770aeebbeb7516608e","lane":"rust-test","parents":["1dd28aa00d66da1a4cbc808c0a8073f44c38fbcc"],"secs":null,"stamp":"94b98382f147795ac02d662ccdeb48db","tree":"6e7735eec51936f713dfc5be229d9e529bb898ed","v":1,"via":"reused"}
Ci-Attestation: {"at":1791655236,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"ebdc46f8a8f1313f5a8a7598543c59a5fd5215cd8f7e5a82bfa270fc2ec20328","lane":"tier2-linux","parents":["1dd28aa00d66da1a4cbc808c0a8073f44c38fbcc"],"secs":18,"stamp":"aef558127baf860704a81ce802aa05cf","tree":"6e7735eec51936f713dfc5be229d9e529bb898ed","v":1,"via":"run"}
@zackees
zackees force-pushed the port/profiler-snapshot branch from bf571d0 to 4ea0b96 Compare October 10, 2026 18:00
@zackees
zackees merged commit 2c7ae54 into obs-rust:master Oct 10, 2026
22 checks passed
zackees added a commit that referenced this pull request Oct 10, 2026
…43)

Phase 3 ports of libobs/util into the obs-util crate, each with a safe
core, a C ABI shim, Tier 1 tests, a layout test where a struct crosses
the ABI, and a proptest parity suite against the original C built as an
oracle. ENABLE_RUST_LIBOBS=ON drops the matching C sources from libobs.

- utf8: hidden and non-Windows only (Windows keeps the C utf8.c).
- lexer.c: follows master's C, including the #48 strref ordering.
- text-lookup: no longer crashes on an opening quote at end of line;
  the shim returns false for a NULL lookup.
- dstr: follows master's #46/#47 fixes; strlist_split takes a NUL
  separator. Wide-char and printf helpers stay in dstr-libc.c.
- bmem: Windows _aligned_* branch and the allocation counter.

The oracle vendors uthash 2.3.0 (BSD-1-Clause) for text-lookup.c, since
the Rust test runners have no uthash package.

Refs #43

Rebased onto master after #61 (base), #66 (file-serializer) and #85 (real
utf8.c in the oracle): the oracle's utf8.c/platform_conv_host.c now use
oracle_* utf8 names so they no longer clash with the Rust shims; the
dstr-conversion oracle test moved to obs-util and calls oracle_dstr_*;
duplicate bcrash/os_fopen/bmemdup/os_*_ptr stand-ins were dropped in favour
of master's base-variadic.c, file_serializer_host.c and
platform_conv_host.c; utf8 shims are listed in rust-hidden.txt; the
vendored uthash is excluded from clang-format.

Rebased again onto master after #82/#83/#87/#97/#89/#98/#88: oracle build.rs keeps
video_fourcc.c/task.c and drops the direct util/utf8.c (oracle/utf8.c already
compiles it under oracle_* names, which platform_conv_host.c and #82's
file_serializer_host.c use).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=44ac22e2f9bf9093f2a87bc1c0860393942c7f05 secs=31 lanes=lint:reused@9b0282a9e1c3,rust-test:reused@e3680ff66806,tier2-linux:run
Ci-Attestation: {"at":1791656844,"gate":"rust/all/fmt","host":"linux-x86_64","key":"9b0282a9e1c35c80eae0d4f0c7540b1c3b1c9f193daad522570bc7b20e609cdc","lane":"lint","parents":["07223a5abc85d40d9b7c016092ce37a672aca501"],"secs":null,"stamp":"ed3cee40895adfa7780a781e7ead1f4d","tree":"44ac22e2f9bf9093f2a87bc1c0860393942c7f05","v":1,"via":"reused"}
Ci-Attestation: {"at":1791656844,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"9b0282a9e1c35c80eae0d4f0c7540b1c3b1c9f193daad522570bc7b20e609cdc","lane":"lint","parents":["07223a5abc85d40d9b7c016092ce37a672aca501"],"secs":null,"stamp":"9bde047cbb6c054fa18fa8143826c0c7","tree":"44ac22e2f9bf9093f2a87bc1c0860393942c7f05","v":1,"via":"reused"}
Ci-Attestation: {"at":1791656844,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"e3680ff66806191a1385606c7996530d1becc162ef5a3444eeefce614a7d0c02","lane":"rust-test","parents":["07223a5abc85d40d9b7c016092ce37a672aca501"],"secs":null,"stamp":"46cf777b2d672af2f62536e2d4132bf2","tree":"44ac22e2f9bf9093f2a87bc1c0860393942c7f05","v":1,"via":"reused"}
Ci-Attestation: {"at":1791657116,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"99939507781ddefb1aa7855e1a0c9b4af9092524f38999d7db36a74a20f1ccce","lane":"tier2-linux","parents":["07223a5abc85d40d9b7c016092ce37a672aca501"],"secs":31,"stamp":"8164638665d4208fabc4b0a768fbc870","tree":"44ac22e2f9bf9093f2a87bc1c0860393942c7f05","v":1,"via":"run"}
zackees added a commit that referenced this pull request Oct 10, 2026
…43)

Phase 3 ports of libobs/util into the obs-util crate, each with a safe
core, a C ABI shim, Tier 1 tests, a layout test where a struct crosses
the ABI, and a proptest parity suite against the original C built as an
oracle. ENABLE_RUST_LIBOBS=ON drops the matching C sources from libobs.

- utf8: hidden and non-Windows only (Windows keeps the C utf8.c).
- lexer.c: follows master's C, including the #48 strref ordering.
- text-lookup: no longer crashes on an opening quote at end of line;
  the shim returns false for a NULL lookup.
- dstr: follows master's #46/#47 fixes; strlist_split takes a NUL
  separator. Wide-char and printf helpers stay in dstr-libc.c.
- bmem: Windows _aligned_* branch and the allocation counter.

The oracle vendors uthash 2.3.0 (BSD-1-Clause) for text-lookup.c, since
the Rust test runners have no uthash package.

Refs #43

Rebased onto master after #61 (base), #66 (file-serializer) and #85 (real
utf8.c in the oracle): the oracle's utf8.c/platform_conv_host.c now use
oracle_* utf8 names so they no longer clash with the Rust shims; the
dstr-conversion oracle test moved to obs-util and calls oracle_dstr_*;
duplicate bcrash/os_fopen/bmemdup/os_*_ptr stand-ins were dropped in favour
of master's base-variadic.c, file_serializer_host.c and
platform_conv_host.c; utf8 shims are listed in rust-hidden.txt; the
vendored uthash is excluded from clang-format.

Rebased again onto master after #82/#83/#87/#97/#89/#98/#88/#105: oracle build.rs keeps
video_fourcc.c/task.c and drops the direct util/utf8.c (oracle/utf8.c already
compiles it under oracle_* names, which platform_conv_host.c and #82's
file_serializer_host.c use).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=58f2156a689831720a1e6ad9004041e400917579 secs=135 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791658556,"gate":"rust/all/fmt","host":"linux-x86_64","key":"e533312cff231c50944045005e90c2b48ce1920b317c9037a705bfda5b49ef4c","lane":"lint","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":17,"stamp":"a33efc3cd6c98f3fbd2fa57e9a61a281","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"}
Ci-Attestation: {"at":1791658556,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"e533312cff231c50944045005e90c2b48ce1920b317c9037a705bfda5b49ef4c","lane":"lint","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":17,"stamp":"fb2d0a58bcefb05085a4b512fc916740","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"}
Ci-Attestation: {"at":1791658556,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"1a00cb7a8eb7b67b33a108e748711133d604e544b254813435cc1ca5ea24cd26","lane":"rust-test","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":22,"stamp":"d80b75173a27c995da2676193fa36904","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"}
Ci-Attestation: {"at":1791658556,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a950373231b455174e5c031fe578e1e48c61e04f0387195a7ddc0e265e371e15","lane":"tier2-linux","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":96,"stamp":"f1c2d81609277e26492a5a3f3553cd9c","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"}
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.

2 participants