Skip to main content

CpuSnapshot

Struct CpuSnapshot 

Source
pub struct CpuSnapshot {
    pub logical_count: u16,
    pub physical_count: MetricState<u16>,
    pub total: MetricState<CpuUsage>,
    pub per_core: MetricState<Vec<CpuUsage>>,
    pub frequency_mhz: MetricState<u64>,
    pub cgroup_quota: MetricState<CpuQuota>,
    pub core_classes: Vec<CoreClass>,
}
Expand description

System-wide CPU state.

Fields§

§logical_count: u16

Logical CPU count, including SMT siblings. Always known.

§physical_count: MetricState<u16>

Physical core count, where the platform reports it.

§total: MetricState<CpuUsage>

Aggregate machine utilization, 0..=100 (§8.3).

§per_core: MetricState<Vec<CpuUsage>>

Per-logical-CPU utilization, in stable index order.

§frequency_mhz: MetricState<u64>

Current clock, where reported.

§cgroup_quota: MetricState<CpuQuota>

The CPU ceiling a cgroup imposes, beside the host’s CPU count.

§9.2 requires a container limit to be reported separately from the host total, so logical_count stays the machine’s real CPU count and this is the ceiling that actually applies to the processes in it. A container limited to 1.5 CPUs on a 64-CPU host is not “2% of the machine”; it is a hard wall a process will be throttled against, and a monitor that showed only the 64 would be describing a machine the user does not have.

MetricState::Unsupported where no quota is configured — cpu.max reading max is not a very large number, it is the absence of a limit — and on every platform without cgroups.

§core_classes: Vec<CoreClass>

The machine’s core classes, where the platform names them.

Empty where there is one class or none is reported, which is the honest answer for a homogeneous machine — an empty list is not “unknown”, it is “there is nothing to distinguish”. MetricState is deliberately not used: this is topology, fixed for the life of the machine, and a topology that could be WarmingUp would invite a renderer to wait for it.

Implementations§

Source§

impl CpuSnapshot

Source

pub fn effective_cores(&self) -> f32

The number of CPUs that actually applies to processes here.

The cgroup quota where one is configured and below the host’s CPU count, the host count otherwise. This is the divisor a load average should be read against and the ceiling a per-core view is bounded by — the exact counterpart of MemorySnapshot::effective_limit_bytes, and required by §9.2 for the same reason.

A quota above the host count is ignored rather than reported: a group allowed more CPU than the machine has is a configuration artefact, not a ceiling, and dividing a load average by it would understate the pressure.

A stale reading counts here, which is the one place this crate deliberately breaks MetricState::fresh’s “use fresh values for calculations” rule. A limit is configuration, not a measurement: if the last successful read said 1.5 CPUs and this tick’s read failed, the group is still limited to 1.5 CPUs, and falling back to the host’s 64 would present a machine 42 times larger than the one the process is actually being throttled against. Keeping the retained value is wrong only if the limit changed in the last few seconds, and the row is marked stale either way.

Source

pub fn is_cpu_limited(&self) -> bool

Whether a cgroup quota, rather than the hardware, is the ceiling here.

What a renderer checks before showing the host CPU count unqualified. Stale counts, for the reason Self::effective_cores gives.

Source

pub const fn warming_up(logical_count: u16) -> Self

A snapshot with no measurements yet, for the first frame.

Trait Implementations§

Source§

impl Clone for CpuSnapshot

Source§

fn clone(&self) -> CpuSnapshot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CpuSnapshot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for CpuSnapshot

Source§

fn eq(&self, other: &CpuSnapshot) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CpuSnapshot

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.