pub struct ProcessSpan { /* private fields */ }Expand description
A measurement of process-wide allocations over the span’s lifetime.
Returned by Operation::measure_process.
It captures the process’s allocation counters at creation and records the delta
when it is dropped, so the measured work should live inside the span’s scope.
Before the span is dropped the caller must state how many iterations the
measured work covers by calling iterations. Dropping a
span without an iteration count panics, because a measurement with no
iteration count is a programming error. If the thread is already unwinding
from a panic when the span drops, it records nothing and does not panic again,
leaving the original panic to propagate.
Reach for this when the threads doing the work cannot be instrumented themselves, or
when several of them collaborate on every iteration so that no single thread’s span
covers a whole one. When each worker can be instrumented and counts iterations of its
own, give each one its own ThreadSpan naming the same operation
instead. The trade-offs a process span accepts are listed under
Operation::measure_process.
§Examples
Work that a library fans out over its own threads:
use std::hint::black_box;
use std::thread;
use alloc_tracker::{Allocator, Session};
#[global_allocator]
static ALLOCATOR: Allocator<std::alloc::System> = Allocator::system();
// Stands in for a library that owns its worker threads. You cannot give them thread
// spans because you never see them, which is what leaves process scope as the option.
fn fan_out(items: usize) {
thread::scope(|scope| {
for item in 0..items {
scope.spawn(move || {
black_box(vec![item as u8; 1024]);
});
}
});
}
let session = Session::new();
let operation = session.operation("fan_out");
const ITEMS: usize = 4;
let span = operation.measure_process();
fan_out(ITEMS);
drop(span.iterations(1));Implementations§
Source§impl ProcessSpan
impl ProcessSpan
Sourcepub fn iterations(self, iterations: u64) -> Self
pub fn iterations(self, iterations: u64) -> Self
Sets how many iterations the measured work covers.
This must be called before the span is dropped. Pass the number of times the
measured region repeats the work, or 1 for a single unit of work.
Passing 0 — for example when a benchmark could not execute its workload —
is permitted; the operation then reports a NaN per-iteration figure to
signal that no valid measurement was produced.