Skip to main content

measure

Attribute Macro measure 

Source
#[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-meta feature) — bytes allocated and allocation count

§Parameters

  • log - If true, logs the return value on each call (requires Debug on return type)
  • future - If true, 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 system
  • measure_all - Bulk instrumentation for modules and impl blocks
  • measure_block! - Instruments code blocks