sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
#[cfg(feature = "gpu")]
use super::ProcessInner;

#[cfg(feature = "gpu")]
impl ProcessInner {
    pub(crate) fn compute_gpu_usage(&mut self, new_gpu_time: u64, new_instant: std::time::Instant) {
        let old_gpu_time = std::mem::replace(&mut self.gpu_time, new_gpu_time);
        if let Some(instant) = self.gpu_instant {
            let diff = self.gpu_time.saturating_sub(old_gpu_time) as f64;
            let time_diff = new_instant.duration_since(instant).as_nanos();
            if time_diff != 0 {
                self.gpu_usage = Some((diff as f64 / time_diff as f64) as f32 * 100.);
            } else {
                self.gpu_usage = Some(0.);
            }
        }
        self.gpu_instant = Some(new_instant);
    }
}

#[cfg(feature = "gpu")]
impl ProcessInner {
    #[cfg(feature = "gpu")]
    pub(crate) fn gpu_usage(&self) -> Option<f32> {
        self.gpu_usage
    }

    #[cfg(feature = "gpu")]
    pub fn gpu_memory(&self) -> Option<u64> {
        // Not supported on macOS.
        None
    }
}