pub struct ScopedAllocCounter {}Expand description
Scoped helper that captures the calling thread’s allocation counters on construction and exposes the delta accumulated by the time you query it.
Per-thread accounting matters under parallel-rt: multiple worker threads
run monitored steps concurrently, and a delta computed from the
process-wide counters would attribute every other thread’s allocations to
the local step. The counters this type snapshots are thread-local, so
allocated() only reflects allocations performed on the same thread that
constructed the counter.
When the runtime is built without feature = "memory_monitoring", this
becomes a zero-sized no-op: allocated()/deallocated() return 0, the
constructor performs no TLS load, and the type is fully eliminated by the
optimizer. This lets the runtime macro emit the same code in both builds.
ScopedAllocCounter is intentionally pinned to the constructing thread —
the macro always uses it as a stack-local within a single step, so this
matches the only realistic usage pattern.
§Example
use cu29_runtime::monitoring::ScopedAllocCounter;
let counter = ScopedAllocCounter::new();
let _vec = vec![0u8; 1024];
// With `memory_monitoring`: `counter.allocated() >= 1024`.
// Without: `counter.allocated() == 0`.
let _ = counter.allocated();Implementations§
Source§impl ScopedAllocCounter
impl ScopedAllocCounter
pub fn new() -> Self
Sourcepub fn allocated(&self) -> usize
pub fn allocated(&self) -> usize
Bytes allocated by the constructing thread since this counter was
created. Always 0 when memory_monitoring is not enabled.
Sourcepub fn deallocated(&self) -> usize
pub fn deallocated(&self) -> usize
Bytes deallocated by the constructing thread since this counter was
created. Always 0 when memory_monitoring is not enabled.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ScopedAllocCounter
impl RefUnwindSafe for ScopedAllocCounter
impl Send for ScopedAllocCounter
impl Sync for ScopedAllocCounter
impl Unpin for ScopedAllocCounter
impl UnsafeUnpin for ScopedAllocCounter
impl UnwindSafe for ScopedAllocCounter
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
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