Skip to main content

Module cpu

Module cpu 

Source

Structsยง

CfsQuota ๐Ÿ”’
Effective CPU limit from CFS quota (None = unlimited).
CpuCollector
Snapshot ๐Ÿ”’

Enumsยง

CpuSource ๐Ÿ”’
Which CPU accounting source is available for system-level utilization.

Functionsยง

aggregate_util_cores ๐Ÿ”’
Aggregate utilization expressed as fractional cores in use (0.0..n_cores). Not clamped: kernel rounding can produce values very slightly above n_cores.
core_util_pct ๐Ÿ”’
Per-core utilization percentage (0.0โ€“100.0, clamped).
cpu_idle ๐Ÿ”’
cpu_total ๐Ÿ”’
detect_cfs_quota ๐Ÿ”’
Read the CFS quota to determine effective core limit.
detect_cpu_source ๐Ÿ”’
Detect the best available CPU accounting source. Preference: cgroupv2 > cgroupv1 > /proc/stat
process_tree_io ๐Ÿ”’
Per-process cumulative disk I/O bytes from /proc/pid/io. Returns { pid -> (read_bytes, write_bytes) }. PIDs whose /proc/pid/io is unreadable (e.g. different UID without ptrace) are silently omitted โ€“ the delta for those PIDs will be 0.
process_tree_memory_mib ๐Ÿ”’
Sum of PSS and VmRSS across all given PIDs, each converted to MiB. One Process::open per PID reads both sources. PSS matches Python memory_mib; RSS is retained for consumers that need resident set size.
process_tree_ticks ๐Ÿ”’
Returns a map of { pid to (utime, stime) } for every process in the tree rooted at root_pid (root included). Processes that have already exited are silently skipped: this is a TOCTOU race we accept.
read_cgroup_usage_secs ๐Ÿ”’
Read cgroup CPU usage as fractional seconds (cumulative). Returns None if the detected source is ProcStat or reads fail.
read_cgroupv1_usage_ns ๐Ÿ”’
Read cgroupv1 cpuacct.usage (nanoseconds, cumulative).
read_cgroupv2_usage_usec ๐Ÿ”’
Read cgroupv2 cpu.stat usage_usec (microseconds, cumulative).
util_pct_from_ticks ๐Ÿ”’
Pure math: percentage of non-idle ticks between two snapshots (0.0โ€“100.0 before any clamping). Takes raw pre-computed totals/idles so it can be unit-tested without constructing a CpuTime (which has private fields).

Type Aliasesยง

Result ๐Ÿ”’