systemstat/platform/
bsd.rs

1use libc::c_int;
2use crate::data::*;
3
4lazy_static! {
5    pub static ref PAGESHIFT: c_int = {
6        let mut pagesize = unsafe { getpagesize() };
7        let mut pageshift = 0;
8        while pagesize > 1 {
9            pageshift += 1;
10            pagesize >>= 1;
11        }
12        pageshift - 10 // LOG1024
13    };
14}
15
16#[repr(C)]
17#[derive(Debug, Clone, Copy)]
18pub struct sysctl_cpu {
19    user: usize,
20    nice: usize,
21    system: usize,
22    interrupt: usize,
23    idle: usize,
24}
25
26impl From<sysctl_cpu> for CpuTime {
27    fn from(cpu: sysctl_cpu) -> CpuTime {
28        CpuTime {
29            user: cpu.user,
30            nice: cpu.nice,
31            system: cpu.system,
32            interrupt: cpu.interrupt,
33            idle: cpu.idle,
34            other: 0,
35        }
36    }
37}
38
39#[link(name = "c")]
40extern "C" {
41    fn getpagesize() -> c_int;
42}