pub struct ThreadSpan { /* private fields */ }Expand description
A tracked span of code that tracks allocations on this thread between creation and drop.
This span tracks allocations made by the current thread only.
§Examples
use alloc_tracker::{Allocator, Operation, Session};
#[global_allocator]
static ALLOCATOR: Allocator<std::alloc::System> = Allocator::system();
let session = Session::new();
let mean_calc = session.operation("test");
{
let _span = mean_calc.measure_thread();
// Perform some operation that allocates memory
let _data = String::from("Hello, world!");
} // Thread allocation is automatically tracked and recorded hereImplementations§
Source§impl ThreadSpan
impl ThreadSpan
Sourcepub fn iterations(self, iterations: u64) -> Self
pub fn iterations(self, iterations: u64) -> Self
Sets the number of iterations for this span.
This allows you to specify how many iterations this span represents, which is used to calculate the mean allocation per iteration when the span is dropped.
§Examples
use alloc_tracker::{Allocator, Session};
#[global_allocator]
static ALLOCATOR: Allocator<std::alloc::System> = Allocator::system();
let session = Session::new();
let operation = session.operation("batch_work");
{
let _span = operation.measure_thread().iterations(1000);
for _ in 0..1000 {
// Perform the same operation 1000 times
let _data = vec![42];
}
} // Total allocation is measured once and divided by 1000§Panics
Panics if iterations is zero.
Trait Implementations§
Source§impl Debug for ThreadSpan
impl Debug for ThreadSpan
Auto Trait Implementations§
impl Freeze for ThreadSpan
impl RefUnwindSafe for ThreadSpan
impl !Send for ThreadSpan
impl !Sync for ThreadSpan
impl Unpin for ThreadSpan
impl UnwindSafe for ThreadSpan
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