Skip to main content

Module system_monitor

Module system_monitor 

Source

Structs§

CgroupCpuStat
Subset of cgroup v2 cpu.stat that is useful for spotting CPU throttling.

Functions§

cgroup_cpu_stat_path
Resolves this process’s own cgroup cpu.stat from the contents of /proc/self/cgroup. Without a cgroup namespace the root file would report host-wide usage, so the 0::<path> line is followed; the root file is the fallback when there is no v2 line.
emit_cgroup_cpu_stats
Emits the cgroup’s cumulative CPU counters. Emits nothing when the file is missing (non-Linux, cgroup v1, no cgroup).
emit_jemalloc_stats
Emits jemalloc’s own runtime accounting (stats.allocated/resident/ mapped/retained). Only meaningful when jemalloc is this process’s global allocator, hence the feature + platform gate.
emit_process_memory_stats
Emits this process’s own RSS/virtual memory size. Allocator-agnostic (reads from the OS via sysinfo), so this runs for every consumer of spawn_system_monitor, including non-jemalloc binaries.
parse_cpu_stat
Parses the body of a cgroup v2 cpu.stat file. usage_usec is required; the throttling counters are absent when the cpu controller has no limit.
send_system_metrics_forever
Continuously sends system-wide CPU and memory usage metrics.
should_sample_slow
True once at least SLOW_SAMPLE_INTERVAL has elapsed since the last slow sample. Extracted as a pure function (mirroring saturation_monitor.rs’s sample_once extraction) so the gating decision itself is directly testable with plain Duration values, rather than only reachable from inside the infinite loop below.
spawn_system_monitor
Spawns a new thread to run the send_system_metrics_forever function.
usec_to_ticks
Converts microseconds to ticks at frequency ticks per second. Widens to u128 because a cumulative counter times a multi-GHz frequency overflows u64 within days.