Skip to content

util: Port profiler-io to obs-util - #1875

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

zackees merged 4 commits into
masterfrom
port/profiler-io

Conversation

@zackees

@zackees zackees commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #1870
Refs #1846
Refs #874

Unit 3 of #1846: libobs/util/profiler-io.c.h → obs-util::profiler_io, as one PR.

Commits

  • 5adf312 characterization: test/cmocka/test_profiler_io.c (every print line for a hand-built snapshot, NULL snapshots, exact CSV bytes, truncation, empty snapshot, gzip magic, failure paths), registered in the native test graph.
  • 75266c5 RED: safe core with todo!(), C ABI shim, export fragment, hidden profile_print_func, new ported group libobs.ported-profiler-io with its own PCH (zlib leaves libobs.pch.h), oracle wrapper over a pass-through <zlib.h> stand-in. All 9 Tier 1 cases in tests::profiling::profiler_io fail on todo!("profiler-io port").
  • 283e295 GREEN: the port. Tier 1 9/9 pass; Tier 3 proptest parity (log lines of both reports, CSV and decompressed CSV.gz bytes, address columns mapped to walk order) passes; full obs-util --lib 800/800 pass locally. ./lint clean.

Mutation check: 0.98 → 0.97 in print_entry_expected fails print_parity on its first case.

port_comparison (profiler_snapshot_dump_csv, 8 roots × 8 children, 64 rows each): Rust 5.05 ms, C 8.77 ms.

Design: %g/%p go through the C runtime's snprintf (platform::stdio, as os_dtostr does), so output is byte-identical per host. gzip uses flate2 (miniz_oxide), so neither libobs-rust nor the Rust test runners need zlib. The file is opened through platform::path_from_bytes, so the Rust side has no _WIN32 split (#874's two profiler-io conditionals stay only in the C reference copy).

Intentional differences (rust/README.md, test files, #1870): gzip compressed bytes / header OS byte differ (CSV inside identical); NULL snapshot, file name, or entry name (C dereferences); expected time above u64::MAX / 1.02 saturates the ±2% bound (C conversion undefined; excluded from parity inputs).

Tier 2: test_profiler and test_profiler_io run against hybrid and C reference in PR CI (local Tier 2 was occupied by another run). Tier 4: n/a.

@zackees
zackees marked this pull request as ready for review October 23, 2026 04:20
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 23, 2026
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 23, 2026
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@zackees

zackees commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Coordinator: this was ejected from the queue twice. The cause is on master, not in this PR: native_test_graph_replaces_legacy_utility_definitions already fails on master with 141 vs 139, because #1879 and #1883 added core tests without bumping the count. #1896 fixes master. After it lands, this PR's count must be 142, not 140. I'll rebase it and make that change then.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 23, 2026
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
zackees added a commit that referenced this pull request Oct 23, 2026
Master's test graph gained two core tests while this PR was queued, so
the core partition now holds 142 tests (#1875 adds test_profiler_io).
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
@zackees
zackees enabled auto-merge October 23, 2026 05:42
@zackees

zackees commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Coordinator: #1896 landed. I rebased this PR onto it and set the core count to 142 (141 on master, plus this PR's test_profiler_io). native_test_graph_replaces_legacy_utility_definitions passes locally. Auto-merge is on.

test_profiler_io pins what libobs/util/profiler-io.c does today, which
test_profiler only touches through the CSV header line. It builds a
snapshot by hand through the private profiler-snapshot.h layout, so every
time and count is fixed, and checks:

- profiler_print: every log line, with the tree pipes, the min == max
  form, the expected-time percentage and calls per parent call;
- profiler_print_time_between_calls: the within/lower/higher split, the
  all-within and all-higher shortcuts, and that entries without an
  expected time print nothing (nor do their children);
- profiler_print(NULL) and _time_between_calls(NULL) on a profiler that
  never ran: intro and footer only;
- profiler_snapshot_dump_csv: the exact bytes (pointer columns spelled by
  the same C runtime's %p), truncation of an existing file, an empty
  snapshot, and failure on a missing directory;
- profiler_snapshot_dump_csv_gz: a gzip stream, and failure on a missing
  directory.

Two quirks are characterized, not endorsed: a median that lands on the
boundary between two time entries prints as 0 ms, and a calls-per-parent
ratio that rounds to 1.0 is not printed. Registered in the native test
graph like test_profiler.

Refs #1846
rust/obs-util/src/profiler_io.rs holds the safe core with todo!() bodies:
the indent string, gather_stats / gather_stats_between, the two report
printers over any Entry tree, the CSV walk and the CSV / CSV.gz file
writers. %g and %p go through the C runtime's snprintf
(platform::snprintf_double, new platform::snprintf_ptr); gzip is flate2
over miniz_oxide, so neither libobs-rust nor the test runners need zlib.

ffi/profiler_io.rs is the C ABI shim: profiler_print,
profiler_print_time_between_calls, profiler_snapshot_dump_csv and
_csv_gz (rust-exports.d/obs-util-profiler_io.txt), and profile_print_func,
which the C never exports, hidden in rust-hidden.txt, rust-exports.map and
rust-unexports-macos.txt. Lines go to blog(LOG_INFO, "%s", line).

profiler-io.c.h moves to its own ported group, libobs.ported-profiler-io,
with libobs-ported-profiler-io.pch.h (zlib leaves libobs.pch.h). The
oracle compiles it as oracle_* (oracle/profiler_io.c) over a
pass-through <zlib.h> stand-in (oracle/zlib-shim).

Tier 1 (tests/profiler/profiler_io.rs) ports test_profiler_io.c and adds
stats, rounding and pipe edge cases: all 9 fail on
todo!("profiler-io port").

Refs #1870
Refs #1846
The core follows profiler-io.c step for step over any Entry tree: the
indent pipes (with the C's int-shift mask for the last child),
gather_stats and gather_stats_between in the same double arithmetic, the
two report printers, and the CSV walk (times rows, then between-call
rows, then children). %g and %p are the C runtime's snprintf, so every
line and CSV byte is the C's on the same host. The CSV file is created or
truncated and write errors are ignored, as the C ignores fwrite; the gz
file is gzip level 6 through flate2.

- Tier 1 (tests/profiler/profiler_io.rs): all 9 cases pass.
- Tier 3 (profiler_io_parity.rs): proptest against the oracle on random
  snapshot trees (depth 4, repeated names, zero and u64-sized times and
  counts, so nan/inf and e-notation occur): every logged line of both
  reports, and the CSV and CSV.gz bytes with the address columns mapped
  to walk order; profile_print_func's printer calls; missing-directory
  failures. A thread-owned log capture in oracle/profiler_io.c keeps
  other tests' lines out, and a shared LOG_HANDLER_LOCK (tests/common)
  serializes it with base_parity.rs.
- Mutation check: 0.98 -> 0.97 in print_entry_expected fails
  print_parity on its first case.
- port_comparison: profiler_snapshot_dump_csv (8 roots x 8 children,
  32 + 32 rows each), Rust 5.05 ms vs C 8.77 ms.

Intentional differences (rust/README.md, test files): gzip bytes differ
(miniz_oxide, not zlib; the CSV inside is identical); NULL snapshot,
file name or entry name, which the C dereferences; an expected time
above u64::MAX / 1.02 saturates the +-2% bound where the C conversion is
undefined (excluded from the parity inputs).

Fixes #1870
Refs #1846
Refs #874
Clang (macOS Rust Tests) rejects the vsnprintf in
oracle_profiler_io_log_capture under -Wformat-nonliteral; GCC's -Wformat
pragma already covered it. Reproduced locally with CC=clang.

Refs #1870
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
Merged via the queue into master with commit c3f0c7e Oct 23, 2026
32 checks passed
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 23, 2026
…rust#1899) (obs-rust#1901)

* test: characterize the obs-service capability and connect-info getters (obs-rust#1899)

* test: run the service getter cases on one libobs and fail instead of skipping with a display (obs-rust#1899)

* test: count test_service_getters on top of obs-rust#1875's core test (obs-rust#1899)
@zackees
zackees deleted the port/profiler-io 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/profiler-io.c to obs-util

1 participant