Expand description
Best-effort system-resource samplers (CPU, RSS, total RAM).
Per the library-purity principle this module does no terminal I/O and
reads no $HOME/config/environment for behavior: it queries live
system state via a few libc syscalls (CPU time, resident set size,
physical RAM) so a higher-level controller can make adaptive decisions
(e.g. a concurrency/throughput guardrail in the stores lane). It is purely
advisory runtime telemetry and is never consulted by the walk, the
manifest builder, or any snapshot computation — a walk samples identically
whether or not anything reads these numbers.
Everything here is strictly best-effort: every platform read that fails
yields None rather than panicking. Each unsafe block performs exactly
one syscall into a plain-old-data struct and checks the return code before
trusting the result; no unwrap/expect is used on any syscall path.
The CpuSampler mirrors the renderer’s sampler in
snapdir-cli’s progress module, and resident_set_bytes mirrors its
sample_rss; total_ram_bytes is new (the controller needs a
memory-budget denominator that the CLI renderer never sampled).
Structs§
- CpuSampler
- 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.
Functions§
- resident_
set_ bytes - Returns the current process resident set size (RSS) in bytes, best-effort.
- total_
ram_ bytes - Returns the total physical RAM of the machine in bytes, best-effort.