#[measure]Expand description
Instruments a function to measure execution time or memory allocations.
Automatically detects sync vs async and inserts the appropriate measurement guard.
Compiles to zero overhead when the hotpath-meta feature is disabled.
§Measurements
- Time profiling (default) — execution duration via high-precision timers
- Allocation profiling (
hotpath-alloc-metafeature) — bytes allocated and allocation count
§Parameters
log- Iftrue, logs the return value on each call (requiresDebugon return type)future- Iftrue, also tracks the future lifecycle (poll count, state transitions, cancellation). Only valid on async functions.
§Examples
#[hotpath_meta::measure]
fn process(data: &[u8]) -> usize {
data.len()
}
#[hotpath_meta::measure(log = true)]
fn compute() -> i32 {
42
}
#[hotpath_meta::measure(future = true)]
async fn fetch_data() -> Vec<u8> {
vec![1, 2, 3]
}§Async Allocation Limitation
Allocation profiling requires current_thread tokio runtime because thread-local
tracking cannot follow tasks across threads. Time profiling works with any runtime.
§See Also
main- Initializes the profiling systemmeasure_all- Bulk instrumentation for modules and impl blocksmeasure_block!- Instruments code blocks