Report

Struct Report 

Source
pub struct Report { /* private fields */ }
Expand description

Thread-safe memory allocation tracking report.

A Report contains the captured memory allocation statistics from a Session and can be safely sent to other threads for processing. Reports can be merged together and processed independently.

§Examples

use alloc_tracker::{Allocator, Session};

#[global_allocator]
static ALLOCATOR: Allocator<std::alloc::System> = Allocator::system();

let session = Session::new();
{
    let operation = session.operation("test_work");
    let _span = operation.measure_process();
    let _data = vec![1, 2, 3, 4, 5]; // This allocates memory
}

let report = session.to_report();
report.print_to_stdout();

§Merging reports

use alloc_tracker::{Allocator, Report, Session};

#[global_allocator]
static ALLOCATOR: Allocator<std::alloc::System> = Allocator::system();

// Create two separate sessions
let session1 = Session::new();
let session2 = Session::new();

// Record some work in each
{
    let op1 = session1.operation("work");
    let _span1 = op1.measure_process();
    let _data1 = vec![1, 2, 3]; // This allocates memory
}

{
    let op2 = session2.operation("work");
    let _span2 = op2.measure_process();
    let _data2 = vec![4, 5, 6, 7]; // This allocates more memory
}

// Convert to reports and merge
let report1 = session1.to_report();
let report2 = session2.to_report();
let merged = Report::merge(&report1, &report2);

merged.print_to_stdout();

Implementations§

Source§

impl Report

Source

pub fn merge(a: &Self, b: &Self) -> Self

Merges two reports into a new report.

The resulting report contains the combined statistics from both input reports. Operations with the same name have their statistics combined as if all spans had been recorded through a single session.

§Examples
use alloc_tracker::{Allocator, Report, Session};

#[global_allocator]
static ALLOCATOR: Allocator<std::alloc::System> = Allocator::system();

let session1 = Session::new();
let session2 = Session::new();

// Both sessions record the same operation name
{
    let op1 = session1.operation("common_work");
    let _span1 = op1.measure_process();
    let _data1 = vec![1, 2, 3]; // 3 elements
}

{
    let op2 = session2.operation("common_work");
    let _span2 = op2.measure_process();
    let _data2 = vec![4, 5]; // 2 elements
}

let report1 = session1.to_report();
let report2 = session2.to_report();

// Merged report shows combined statistics (2 total iterations)
let merged = Report::merge(&report1, &report2);
Source

pub fn print_to_stdout(&self)

Prints the memory allocation statistics to stdout.

Prints nothing if no operations were captured. This may indicate that the session was part of a “list available benchmarks” probe run instead of some real activity, in which case printing anything might violate the output protocol the tool is speaking.

Source

pub fn is_empty(&self) -> bool

Whether there is any recorded activity in this report.

Source

pub fn operations(&self) -> impl Iterator<Item = (&str, &ReportOperation)>

Returns an iterator over the operation names and their statistics.

This allows programmatic access to the same data that would be printed by print_to_stdout().

§Examples
use alloc_tracker::{Allocator, Session};

#[global_allocator]
static ALLOCATOR: Allocator<std::alloc::System> = Allocator::system();

let session = Session::new();
{
    let operation = session.operation("test_work");
    let _span = operation.measure_process();
    let _data = vec![1, 2, 3, 4, 5]; // This allocates memory
}

let report = session.to_report();
for (name, op) in report.operations() {
    println!(
        "Operation '{}' had {} iterations",
        name,
        op.total_iterations()
    );
    println!("Mean bytes per iteration: {}", op.mean());
    println!("Total bytes: {}", op.total_bytes_allocated());
}

Trait Implementations§

Source§

impl Clone for Report

Source§

fn clone(&self) -> Report

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Report

Source§

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

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

impl Default for Report

Source§

fn default() -> Report

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

impl Display for Report

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Report

§

impl RefUnwindSafe for Report

§

impl Send for Report

§

impl Sync for Report

§

impl Unpin for Report

§

impl UnwindSafe for Report

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.