Phase 5.2: Rust ProfilingSession + safe streaming API - #20
Merged
Merged
Conversation
- Add snmalloc-sys extern "C" decls for sn_rust_profile_streaming_start / sn_rust_profile_streaming_stop, gated on the `profiling` feature. - Introduce `snmalloc-rs::streaming` exposing `ProfilingSession` (RAII handle) plus a borrowed `StreamSample<'_>` view of the raw FFI sample. Single-session-at-a-time semantics enforced through a process-global `Mutex<Option<Handler>>`; second `start()` returns `StreamingError::AlreadyActive`. - Trampoline is a fixed `extern "C"` function that locks the slot, dispatches into the boxed `Fn` and catches panics so unwinds never cross the FFI boundary. Handler bounds are `Send + Sync + 'static`. - Drop unregisters from the C side, then clears the slot so a fresh `ProfilingSession::start` can succeed. - Re-export `ProfilingSession`, `StreamSample`, `StreamingError` from the crate root under `#[cfg(feature = "profiling")]`. - Add `tests/profile_streaming.rs` covering: smoke handler-invocation, double-start AlreadyActive recovery, drop-unregisters guarantee, and thread-safety under a concurrent allocator workload.
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
Safe Rust wrapper over Phase 5.1's
sn_rust_profile_streaming_start/stopC exports.ProfilingSession— RAII handle.start<F: Fn(StreamSample<'_>) + Send + Sync + 'static>(handler) -> Result<Self, StreamingError>;Dropunregisters.StreamSample<'a>— zero-copy view overSnRustProfileRawSample; accessors:alloc_ptr(),requested_size(),allocated_size(),weight(),stack().StreamingError—AlreadyActive|RegistrationFailed.Mutex<Option<Handler>>; secondstart()returnsErr(AlreadyActive).std::panic::catch_unwind(UB to unwind acrossextern \"C\").ProfilingSessionis!Send + !Sync(Drop runs on constructing thread). Handler itself isSend + Sync.start();Dropleaves a poisoned mutex untouched (one-shot bounded leak; recovers next start).Test plan
profile_streaming::smoke_session_receives_samplesprofile_streaming::double_start_errors_then_recoversprofile_streaming::drop_unregisters_handlerprofile_streaming::thread_safety_concurrent_workload