pub struct LocalAllocCounter;Expand description
Thread-local allocation counter suitable for #[global_allocator] in tests.
Install once per test binary and wrap measured blocks with
count_thread_allocations or count_thread_allocations_with_bytes.
use ferravex_core::telemetry::count_thread_allocations;
// Without LocalAllocCounter installed as #[global_allocator], counts stay 0.
let (sum, calls) = count_thread_allocations(|| 2 + 2);
assert_eq!((sum, calls), (4, 0));Trait Implementations§
Source§impl GlobalAlloc for LocalAllocCounter
impl GlobalAlloc for LocalAllocCounter
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocates memory as described by the given
layout. Read moreSource§unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
Behaves like
alloc, but also ensures that the contents
are set to zero before being returned. Read moreAuto Trait Implementations§
impl Freeze for LocalAllocCounter
impl RefUnwindSafe for LocalAllocCounter
impl Send for LocalAllocCounter
impl Sync for LocalAllocCounter
impl Unpin for LocalAllocCounter
impl UnwindSafe for LocalAllocCounter
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
Mutably borrows from an owned value. Read more