Skip to content

rust: Port util/profiler-io.c to obs-util #1870

Closed

Description

@zackees

Unit

libobs/util/profiler-io.c.h (363 lines) into rust/obs-util. It is the print and CSV half of util/profiler.c, left C when the profiler (#152) and the snapshot accessors were ported:

  • profiler_print, profiler_print_time_between_calls (log lines through blog)
  • profiler_snapshot_dump_csv, profiler_snapshot_dump_csv_gz (file output; gzip through zlib)
  • profile_print_func: non-static but not EXPORT; nothing else calls it. Ported as a hidden shim (rust-hidden.txt), so the exported symbol sets stay identical.
  • statics: make_indent_string, gather_stats, gather_stats_between, profile_print_entry, profile_print_entry_expected, entry_dump_csv, profiler_snapshot_dump, dump_csv_fwrite, dump_csv_gzwrite

Phase and position

Unit 3 of #1846. The recording engine (obs-util::profiler) and the snapshot accessors (obs-util::profiler_snapshot) are Rust; this removes the last C of the profiler except its variadic profile_store_name (profiler-variadic.c.h). It also takes the two _WIN32 conditionals of this file listed in #874 (gzopen_w/gzclose_w): Rust opens the file through platform::path_from_bytes, so the host split leaves the C.

Dependencies and existing tests

  • Snapshots: read in place through the existing #[repr(C)] mirrors in ffi::profiler_snapshot; NULL takes and frees a snapshot through the ported profile_snapshot_create / profile_snapshot_free.
  • Number and pointer spelling: %g and %p go through the C runtime's snprintf in platform::stdio (as os_dtostr and config_set_default_double already do), so nan/inf and pointer spellings match the host C exactly.
  • gzip: zlib is replaced by flate2 (pure-Rust miniz_oxide backend), so neither libobs-rust nor the Rust test runners need zlib (the Windows runners have none). The oracle compiles profiler-io.c.h with a pass-through stand-in for the four zlib calls, so Tier 3 compares the decompressed Rust output with the C's uncompressed bytes.
  • Logging: the shim calls blog(LOG_INFO, "%s", line) like the C.
  • test_profiler only checks the CSV header. A characterization test test/cmocka/test_profiler_io.c lands first: every print line for a hand-built snapshot, NULL snapshots, exact CSV bytes, truncation, empty snapshot, gzip magic, failure paths.

Characterized, not endorsed: a median on the boundary of two time entries prints as 0 ms; a calls-per-parent ratio that rounds to 1.0 is not printed.

Intentional differences:

  • The .csv.gz stream is deflated by miniz_oxide, not zlib: the compressed bytes (and the gzip header's OS byte) differ, the decompressed CSV is identical.
  • A snapshot entry with a NULL name (never produced by the profiler; C passes NULL to %s, undefined behavior) prints an empty name.

Plan

One PR:

  1. Characterization: test/cmocka/test_profiler_io.c, registered in test/cmocka/build/test-graph.json.
  2. RED: obs-util::profiler_io safe core and ffi::profiler_io shim with todo!(); Tier 1 tests in tests/profiler/profiler_io.rs; export fragment rust-exports.d/obs-util-profiler_io.txt.
  3. GREEN: the port; profiler-io.c.h moves to a ported group; Tier 3 proptest parity against the oracle (log lines and CSV / decompressed CSV.gz bytes for random snapshot trees); Tier 2 runs test_profiler and test_profiler_io against hybrid and C reference; port_comparison bench.
  4. Tier 4 does not apply.

Refs #1846, #874

Activity

  1. zackees commented on Oct 23, 2026

    @zackees
    MemberAuthor

    Claiming: profiler-io port (unit 3 of #1846), one PR, branch port/profiler-io.

    1. Characterization test test/cmocka/test_profiler_io.c (done locally).
    2. RED: safe core + C ABI shim with todo!(), Tier 1 tests in obs-util's profiler harness; draft PR today.
    3. GREEN: port, ported group, export fragment, Tier 3 parity vs the oracle, port_comparison numbers.
    4. Lint, focused tests, PR CI, queue.
  2. added
    claimed
    on Oct 23, 2026
  3. zackees commented on Oct 23, 2026

    @zackees
    MemberAuthor

    Draft PR #1875 (RED 75266c5, GREEN 283e295). One more intentional difference found by Tier 3: an expected time above u64::MAX / 1.02 saturates the ±2% bound in Rust, where the C's (uint64_t) conversion is undefined; excluded from the parity inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions