Crate all_the_time

Source
Expand description

Processor time tracking utilities for benchmarks and performance analysis.

This package provides utilities to track processor time during code execution, enabling analysis of processor usage patterns in benchmarks and performance tests.

The core functionality includes:

  • Session - Configures processor time tracking and provides access to tracking data
  • ThreadSpan - Tracks thread processor time over a time period
  • ProcessSpan - Tracks process processor time over a time period
  • Operation - Calculates mean processor time per operation
  • SpanBuilder - Builder for creating spans with explicit iteration counts

This package is not meant for use in production, serving only as a development tool.

§Example

use all_the_time::Session;

let mut session = Session::new();

{
    let batch_op = session.operation("batch_work");
    let _span = batch_op.iterations(1000).measure_thread();
    for _ in 0..1000 {
        // Fast operation - measured once and divided by 1000
        std::hint::black_box(42 * 2);
    }
}

// Output statistics of all operations to console
session.print_to_stdout();

§Thread vs Process Processor Time

You can choose between tracking thread processor time or process processor time:

use all_the_time::Session;

let mut session = Session::new();

// Track thread processor time
{
    let op = session.operation("thread_work");
    let _span = op.iterations(1).measure_thread();
    // Work done here is measured for the current thread only
}

// Track process processor time (all threads)
{
    let op = session.operation("process_work");
    let _span = op.iterations(1).measure_process();
    // Work done here is measured for the entire process
}

§Overhead

Capturing a single measurement by calling measure_xyz() incurs an overhead of approximately 500 nanoseconds on an arbitrary sample machine. You are recommended to measure multiple consecutive iterations to minimize the impact of overhead on your benchmarks: operation.iterations(12345).measure_xyz().

§Session management

Multiple Session instances can be used concurrently as they track processor time independently. Each session maintains its own set of operations and statistics.

Structs§

Operation
Calculates mean processor time per operation across multiple iterations.
ProcessSpan
A span of code for which we track process processor time between creation and drop.
Session
Manages processor time tracking session state and contains operations.
SpanBuilder
Builder for creating processor time tracking spans with explicit iteration counts.
ThreadSpan
A tracked span of code that tracks thread processor time between creation and drop.