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
impl Report
Sourcepub fn merge(a: &Self, b: &Self) -> Self
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);Sourcepub fn print_to_stdout(&self)
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.
Sourcepub fn operations(&self) -> impl Iterator<Item = (&str, &ReportOperation)>
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());
}