Crate all_the_time

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
  • Report - Thread-safe processor time statistics that can be merged and processed independently
  • 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

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

§Example

use all_the_time::Session;

let session = Session::new();

{
    let batch_op = session.operation("batch_work");
    let _span = batch_op.measure_thread().iterations(1000);
    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 session = Session::new();

// Track thread processor time
{
    let op = session.operation("thread_work");
    let _span = op.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.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.measure_xyz().iterations(12345).

§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.

While Session itself is single-threaded, reports from sessions can be converted to thread-safe Report instances and sent to other threads for processing:

use std::thread;

use all_the_time::{Report, Session};

let session = Session::new();
let operation = session.operation("work");
let _span = operation.measure_thread();
// Some work happens here

let report = session.to_report();

// Report can be sent to another thread
thread::spawn(move || {
    report.print_to_stdout();
})
.join()
.unwrap();

Structs§

Operation
Calculates mean processor time per operation across multiple iterations.
ProcessSpan
Use this to track processor times for code that runs on any thread.
Report
Thread-safe processor time tracking report.
ReportOperation
Processor time statistics for a single operation in a report.
Session
Manages processor time tracking session state and contains operations.
ThreadSpan
A tracked span of code that tracks thread processor time between creation and drop.