1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! 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();
//! # }
//! ```
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;