ThreadSpan

Struct ThreadSpan 

Source
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 here

Implementations§

Source§

impl ThreadSpan

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for ThreadSpan

Source§

fn drop(&mut self)

Executes the destructor for this 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, 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, 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.