pub struct CpuTracker { /* private fields */ }Expand description
Tracks per-PID CPU time across ticks to turn the kernel’s cumulative counter into an
instantaneous rate. A single /proc/<pid>/stat read only gives total ticks consumed since
the process started; the rate is the delta between two reads over the wall time between them.
Implementations§
Source§impl CpuTracker
impl CpuTracker
pub fn new() -> Self
Sourcepub fn sample(&mut self, pid: u32) -> Option<f32>
pub fn sample(&mut self, pid: u32) -> Option<f32>
CPU % (relative to one core) for pid, or None. The first sighting only establishes
a baseline — there is no prior point to difference against — so it returns None by
design rather than fabricating a since-boot average. Later sightings return the rate.
A missing/unreadable stat (PID exited, foreign user) is a normal None.
Trait Implementations§
Source§impl Default for CpuTracker
impl Default for CpuTracker
Source§fn default() -> CpuTracker
fn default() -> CpuTracker
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CpuTracker
impl RefUnwindSafe for CpuTracker
impl Send for CpuTracker
impl Sync for CpuTracker
impl Unpin for CpuTracker
impl UnsafeUnpin for CpuTracker
impl UnwindSafe for CpuTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more