pub struct ProcessCpuTracker { /* private fields */ }Expand description
Per-process CPU utilization from cumulative per-process CPU time (§8.3).
ProcessCpuTracker::observe returns the core-normalized value: one fully
used core is 100%, so a process saturating four cores reads 400% and a
single-threaded process on a 64-CPU machine still reads 100%. The other
convention is applied on top by ProcessCpuTracker::observe_normalized,
which delegates to the frozen CpuNormalization::apply rather than
re-deriving the arithmetic.
§Monotonic time
Unlike SystemCpuTracker, this divides by the elapsed interval, so the
interval’s accuracy is the percentage’s accuracy. Callers must pass the
snapshot’s monotonic captured_at; a wall-clock jump would otherwise scale
every process on screen (§8.1). The interval is derived with
Instant::saturating_duration_since, so it can never be negative.
§Identity
One tracker follows one process. Callers must key trackers on
crate::model::ProcessIdentity and not on a bare PID: a reused PID must
start a fresh baseline rather than inherit the dead process’s CPU time (§26).
super::KeyedProcessCpuTrackers encodes that.
Implementations§
Source§impl ProcessCpuTracker
impl ProcessCpuTracker
Sourcepub const fn is_warming_up(&self) -> bool
pub const fn is_warming_up(&self) -> bool
Whether the next reading will be the first, and so warming up (§8.3).
Sourcepub const fn last_observed_at(&self) -> Option<Instant>
pub const fn last_observed_at(&self) -> Option<Instant>
When the last reading was accepted, or None while warming up.
Sourcepub fn forget_baseline(&mut self)
pub fn forget_baseline(&mut self)
Drops the baseline so the next reading warms up again.
Sourcepub fn observe(
&mut self,
cpu_time: Duration,
at: Instant,
) -> MetricState<Percent>
pub fn observe( &mut self, cpu_time: Duration, at: Instant, ) -> MetricState<Percent>
Folds one cumulative process CPU time in and publishes core-normalized usage: one core = 100%, so the result may exceed 100% (§8.3).
Sourcepub fn observe_normalized(
&mut self,
cpu_time: Duration,
at: Instant,
normalization: CpuNormalization,
logical_cpus: u16,
) -> MetricState<Percent>
pub fn observe_normalized( &mut self, cpu_time: Duration, at: Instant, normalization: CpuNormalization, logical_cpus: u16, ) -> MetricState<Percent>
Folds one reading in and publishes usage in the requested convention.
logical_cpus is only consulted for CpuNormalization::Machine. A zero
CPU count leaves machine normalization undefined, and §4 forbids
substituting a number for an undefined value, so that case reports
UnavailableReason::ReadFailed — the CPU count is what failed to read.
Trait Implementations§
Source§impl Clone for ProcessCpuTracker
impl Clone for ProcessCpuTracker
Source§fn clone(&self) -> ProcessCpuTracker
fn clone(&self) -> ProcessCpuTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ProcessCpuTracker
Source§impl Debug for ProcessCpuTracker
impl Debug for ProcessCpuTracker
Source§impl Default for ProcessCpuTracker
impl Default for ProcessCpuTracker
Source§fn default() -> ProcessCpuTracker
fn default() -> ProcessCpuTracker
Source§impl DeltaTracker for ProcessCpuTracker
impl DeltaTracker for ProcessCpuTracker
Source§fn with_config(_config: Self::Config) -> Self
fn with_config(_config: Self::Config) -> Self
Source§fn observe_reading(
&mut self,
reading: Self::Reading,
at: Instant,
) -> MetricState<Self::Value>
fn observe_reading( &mut self, reading: Self::Reading, at: Instant, ) -> MetricState<Self::Value>
at.Source§fn last_observed_at(&self) -> Option<Instant>
fn last_observed_at(&self) -> Option<Instant>
None while warming up.