pub struct MemoryProfiler { /* private fields */ }Expand description
Simple memory profiler that tracks peak RSS usage over its lifetime.
Designed to be shared via Arc<MemoryProfiler> across threads.
All mutable state is stored in atomics, so no locking is required.
§Example
use oxibonsai_runtime::memory::MemoryProfiler;
let profiler = MemoryProfiler::new();
// Sample at some point during processing
let snap = profiler.sample();
println!("current RSS: {} bytes", snap.rss_bytes);
// Peak may differ from current if memory was freed
println!("peak RSS: {} bytes", profiler.peak_rss_bytes());
println!("delta: {} bytes", profiler.delta_bytes());Implementations§
Source§impl MemoryProfiler
impl MemoryProfiler
Sourcepub fn sample(&self) -> MemorySnapshot
pub fn sample(&self) -> MemorySnapshot
Take a memory snapshot, updating the peak if necessary.
Lock-free and safe to call from any thread.
Sourcepub fn peak_rss_bytes(&self) -> u64
pub fn peak_rss_bytes(&self) -> u64
Highest RSS observed across all sample() calls and at creation.
Sourcepub fn start_rss_bytes(&self) -> u64
pub fn start_rss_bytes(&self) -> u64
RSS at the time this profiler was created.
Sourcepub fn delta_bytes(&self) -> i64
pub fn delta_bytes(&self) -> i64
Signed difference: peak_rss − start_rss.
Positive means memory grew; negative (rare) means the OS reclaimed pages between profiler creation and the peak sample.
Sourcepub fn sample_count(&self) -> u64
pub fn sample_count(&self) -> u64
Total number of sample() calls made on this profiler.
Sourcepub fn take_snapshot(&self) -> MemorySnapshot
pub fn take_snapshot(&self) -> MemorySnapshot
Take a memory snapshot, updating the peak if necessary.
Alias for sample using the name required by the task specification.
Sourcepub fn current_rss_bytes(&self) -> Option<u64>
pub fn current_rss_bytes(&self) -> Option<u64>
Current RSS in bytes as Option<u64>.
Returns None on platforms where RSS reading is unsupported (WASM, etc.).
On Linux and macOS this always returns Some(value), where value may be
0 only in the extremely unlikely case that the OS returns an error.
Trait Implementations§
Source§impl Debug for MemoryProfiler
impl Debug for MemoryProfiler
Auto Trait Implementations§
impl !Freeze for MemoryProfiler
impl RefUnwindSafe for MemoryProfiler
impl Send for MemoryProfiler
impl Sync for MemoryProfiler
impl Unpin for MemoryProfiler
impl UnsafeUnpin for MemoryProfiler
impl UnwindSafe for MemoryProfiler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more