Expand description
Read data from /proc/stat into the struct ProcStat.
The Documentation for /proc/stat is found here: https://www.kernel.org/doc/Documentation/filesystems/proc.txt.
Please mind that the description of “steal” time in the kernel source describes ‘involuntary wait time’. This is true, but involuntary waiting means virtualization makes the kernel (virtual machine) wait. This is implemented for PowerPC, S390 and X86, and for X86 for paravirtualization.
The stat module converts the jiffies from /proc/stat from the cpu_total and cpu_individual CpuStat
structs into milliseconds. It does that by taking the CLK-TCK (clock tick) sysconf variable set by
CONFIG_HZ, and calculate the time in milliseconds from the cpu state jiffies value in the following way:
(CPUSTATE_JIFFIES * 1000) / CLK_TCK
convert seconds to milliseconds divide by ticks per secondExample usage of stat:
use proc_sys_parser::{stat, stat::{ProcStat, CpuStat}};
let proc_stat = stat::read();Example output:
ProcStat {
cpu_total: CpuStat { name: "cpu", user: 8570, nice: 0, system: 7530, idle: 1710040, iowait: 2780, irq: 0, softirq: 150, steal: 0, guest: 0, guest_nice: 0 },
cpu_individual: [CpuStat { name: "cpu0", user: 1800, nice: 0, system: 1450, idle: 283400, iowait: 460, irq: 0, softirq: 120, steal: 0, guest: 0, guest_nice: 0 },
CpuStat { name: "cpu1", user: 1720, nice: 0, system: 1320, idle: 284780, iowait: 580, irq: 0, softirq: 0, steal: 0, guest: 0, guest_nice: 0 },
CpuStat { name: "cpu2", user: 1060, nice: 0, system: 1220, idle: 285410, iowait: 510, irq: 0, softirq: 0, steal: 0, guest: 0, guest_nice: 0 },
CpuStat { name: "cpu3", user: 890, nice: 0, system: 990, idle: 286130, iowait: 450, irq: 0, softirq: 0, steal: 0, guest: 0, guest_nice: 0 },
CpuStat { name: "cpu4", user: 1400, nice: 0, system: 1280, idle: 285260, iowait: 310, irq: 0, softirq: 30, steal: 0, guest: 0, guest_nice: 0 },
CpuStat { name: "cpu5", user: 1680, nice: 0, system: 1250, idle: 285020, iowait: 450, irq: 0, softirq: 0, steal: 0, guest: 0, guest_nice: 0 }],
interrupts: [184655, 0, 4500, 60546, 0, 0, 0, 2, 0, 0, 0, 70138, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 548, 0, 0, 0, 0, 0, 2, 0, 3410, 2927, 4739, 5542, 1595, 1913, 0, 0, 0, 79, 154, 208, 282, 43, 52, 0, 14842, 11679, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 1437, 0, 0, 0, 0, 0, 0],
context_switches: 275716,
boot_time: 1702127060,
processes: 3472,
processes_running: 1,
processes_blocked: 0,
softirq: [99012, 30, 8368, 2, 24666, 11, 0, 208, 15031, 0, 50696]
}(edited for readability)
If you want to change the path and/or file that is read for ProcStat, which is /proc/stat, by
default, use:
use proc_sys_parser::{stat, stat::{ProcStat, CpuStat, Builder}};
let proc_stat = Builder::new().path("/myproc").read();Structs§
- Builder
- Builder pattern for
ProcStat - CpuStat
- Struct for holding cpu times in milliseconds
- Proc
Stat - Struct for holding
/proc/statstatistics