sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
use super::*;

impl SystemInner {
    /// A CPU usage computation can occasionally exceed `"number of CPUs" * 100`.
    fn get_max_process_cpu_usage(&self) -> f32 {
        self.cpus.len() as f32 * 100.
    }

    pub(super) fn update_procs_cpu(&mut self, refresh_kind: ProcessRefreshKind) {
        if !refresh_kind.cpu() {
            return;
        }
        self.cpus
            .refresh_if_needed(true, CpuRefreshKind::nothing().with_usage());

        if self.cpus.is_empty() {
            sinf_debug!("cannot compute processes CPU usage: no CPU found...");
            return;
        }
        let (new, old) = self.cpus.get_global_raw_times();
        let total_time = if old > new { 1 } else { new - old };
        let total_time = total_time as f32 / self.cpus.len() as f32;
        let max_value = self.get_max_process_cpu_usage();

        for proc_ in self.process_list.values_mut() {
            compute_cpu_usage(&mut proc_.inner, total_time, max_value);
        }
    }

    fn refresh_cpus(&mut self, only_update_global_cpu: bool, refresh_kind: CpuRefreshKind) {
        self.cpus.refresh(only_update_global_cpu, refresh_kind);
    }
}

impl SystemInner {
    pub(crate) fn refresh_cpu_specifics(&mut self, refresh_kind: CpuRefreshKind) {
        self.refresh_cpus(false, refresh_kind);
    }

    pub(crate) fn global_cpu_usage(&self) -> f32 {
        self.cpus.global_cpu.usage()
    }

    pub(crate) fn cpus(&self) -> &[Cpu] {
        &self.cpus.cpus
    }
}