Phase 4.6: Viewer round-trip tests (inferno SVG render + speedscope folded import) - #16
Merged
Merged
Conversation
…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.
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.
Summary
Tests-only addition validating
write_flamegraphoutput is consumable by real viewers. No public API changes.inferno::flamegraph::from_reader, asserts<svg+ at least one<gelement^([^\s]+) (\d+)$regex (without pullingregexcrate), asserts ≥95% of folded lines matchAdded
inferno = "0.11"as dev-dependency (pinned for MSRV alignment).Test plan