all_the_time 0.4.15

Processor time tracking utilities for benchmarks and performance analysis
Documentation
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
#![cfg_attr(docsrs, feature(doc_cfg))]

//! 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
//!
//! ```rust
//! use all_the_time::Session;
//!
//! # fn main() {
//! 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;
//!
//! # fn main() {
//! 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};
//!
//! # fn main() {
//! 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();
//! # }
//! ```

#![doc(
    html_logo_url = "https://media.githubusercontent.com/media/folo-rs/folo/refs/heads/main/packages/all_the_time/icon.png"
)]
#![doc(
    html_favicon_url = "https://raw.githubusercontent.com/folo-rs/folo/refs/heads/main/packages/all_the_time/icon.ico"
)]

mod constants;
mod operation;
mod operation_metrics;
mod pal;
mod process_span;
mod report;
mod session;
mod thread_span;

pub(crate) use constants::*;
pub use operation::*;
pub(crate) use operation_metrics::*;
pub use process_span::*;
pub use report::*;
pub use session::*;
pub use thread_span::*;