Skip to main content

ScopedAllocCounter

Struct ScopedAllocCounter 

Source
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

Source

pub fn new() -> Self

Source

pub fn allocated(&self) -> usize

Bytes allocated by the constructing thread since this counter was created. Always 0 when memory_monitoring is not enabled.

Source

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§

Source§

impl Default for ScopedAllocCounter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> GetTypeRegistration for T

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PayloadDefaultHandlePolicyApply for T
where T: ?Sized,

Source§

impl<T> PayloadDefaultLoggingPolicy for T
where T: ?Sized,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Reflect for T
where T: 'static,

Source§

impl<T> ReflectTypePath for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.