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: u16Logical 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
impl CpuSnapshot
Sourcepub fn effective_cores(&self) -> f32
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.
Sourcepub fn is_cpu_limited(&self) -> bool
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.
Sourcepub const fn warming_up(logical_count: u16) -> Self
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
impl Clone for CpuSnapshot
Source§fn clone(&self) -> CpuSnapshot
fn clone(&self) -> CpuSnapshot
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more