Skip to content

Phase 4.6: Viewer round-trip tests (inferno SVG render + speedscope folded import) - #16

Merged
jayakasadev merged 1 commit into
mainfrom
feature/phase-4-6-viewer-roundtrip
Jun 11, 2026
Merged

jayakasadev merged 1 commit into
mainfrom
feature/phase-4-6-viewer-roundtrip

Conversation

@jayakasadev

Copy link
Copy Markdown
Owner

Summary

Tests-only addition validating write_flamegraph output is consumable by real viewers. No public API changes.

  • inferno_roundtrip (profiling): drives a 5000×64B workload, captures snapshot, renders SVG via inferno::flamegraph::from_reader, asserts <svg + at least one <g element
  • speedscope_folded_import (profiling): re-implements speedscope's ^([^\s]+) (\d+)$ regex (without pulling regex crate), asserts ≥95% of folded lines match
  • round_trip_weight_invariance (profiling): regression guard — sum(folded weights) == HeapProfile::total_allocated_bytes
  • empty_snapshot_viewer_safety (both feature configs): empty snapshot → zero bytes, inferno cleanly errors (no panic)

Added inferno = "0.11" as dev-dependency (pinned for MSRV alignment).

Test plan

  • cargo test --features profiling --test profile_viewer_roundtrip (4/4)
  • cargo test --test profile_viewer_roundtrip (1/1 in OFF build)
  • cargo test --all (OFF)
  • cargo test --all --features profiling

…ase 4.6)

- snmalloc-rs/Cargo.toml: add `inferno = "0.11"` as a dev-dependency
  (test-only; never appears in the published crate's transitive deps).
  Version pin documented inline -- 0.11 keeps MSRV aligned with the
  rest of the workspace, while later 0.12.x bumps `rust-version` to
  1.71 and pulls in additional crossbeam transitive deps we don't
  otherwise need.
- snmalloc-rs/tests/profile_viewer_roundtrip.rs: new integration suite
  asserting that the folded-stack output emitted by Phase 4.3's
  `HeapProfile::write_flamegraph` is consumable by two real viewers
  in the Rust profiling ecosystem.  Test-only -- no public API on
  `HeapProfile` / `SnMalloc` is added, and `src/profile.rs` is not
  touched.
  * inferno_roundtrip -- captures a >=50-sample snapshot, writes its
    folded form into a `Vec<u8>`, hands it to `inferno::flamegraph
    ::from_reader` with `Options::default()`, and asserts the
    rendered SVG contains a `<svg` root and at least one `<g`
    stack-frame group node.  Confirms the round-trip from folded
    bytes to SVG works without any post-processing.
  * speedscope_folded_import -- re-implements the regex
    `^([^\s]+) (\d+)$` that speedscope's "Brendan Gregg's collapsed
    stack format" importer uses (per its wiki) and asserts >=95% of
    folded lines match.  speedscope itself runs in a browser/wasm
    context we can't drive in CI, so the conformance check is the
    next best thing.
  * round_trip_weight_invariance -- regression guard for the Phase
    4.3 BTreeMap collapse step: sum of folded weights over a
    real-workload snapshot must equal
    `HeapProfile::total_allocated_bytes` exactly.
  * empty_snapshot_viewer_safety -- runs in both feature
    configurations (no `#[cfg(feature = "profiling")]` gate).
    Confirms `write_flamegraph` on an empty profile writes zero
    bytes and that inferno cleanly returns `Err` rather than
    panicking when handed the resulting empty stream.  Covers the
    OFF-build path where every snapshot is empty by construction.
- Workload calibration: 5_000 x 64-byte allocations at sampling
  rate 512 -> ~625 expected samples (well above the 50-sample floor
  Phase 4.6 requires).  Smaller than the 100k workload in
  profile_accuracy.rs to keep CPU contention low when `cargo test
  --all --features profiling` runs the two test binaries in
  parallel.  Workload-driving helpers live in a
  `#[cfg(feature = "profiling")]` module to avoid dead-code warnings
  on the OFF build.

Verified:
- cargo test --all (profiling OFF): all binaries green, including
  the new profile_viewer_roundtrip binary running just
  empty_snapshot_viewer_safety.
- cargo test --all --features profiling: stable across 5
  back-to-back runs; all 4 new tests pass, all pre-existing tests
  pass.
- cargo test --features profiling --test profile_viewer_roundtrip:
  4 passed, 0 failed.
- No new compiler warnings in either feature configuration.
@jayakasadev
jayakasadev merged commit a4ded83 into main Jun 11, 2026
153 of 202 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant