pub struct CpuSampler { /* private fields */ }Expand description
Samples process CPU utilization as a percentage of total machine capacity,
normalized by the number of available cores so 100% means “one core fully
busy”. Values can exceed 100% (up to ~100 × cores) when multiple cores are
saturated, and are clamped to that range.
Stateful: each poll measures the CPU consumed since the
previous poll over the elapsed wall-clock window. The first poll only
establishes a baseline and returns None.
Implementations§
Source§impl CpuSampler
impl CpuSampler
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a sampler. cores comes from
std::thread::available_parallelism, falling back to 1 if the count
is unavailable.
Sourcepub fn poll(&mut self) -> Option<f64>
pub fn poll(&mut self) -> Option<f64>
Polls CPU usage. The first call establishes a baseline and returns
None; subsequent calls return Some(pct) over the elapsed window —
(cpu_delta / wall_delta) / cores * 100, clamped to [0, 100 × cores] —
or None if getrusage is unavailable or no wall time has elapsed.