| 1 | //! Memory data collection. |
| 2 | |
| 3 | use std::num::NonZeroU64; |
| 4 | |
| 5 | pub(crate) use self::sysinfo::get_ram_usage; |
| 6 | |
| 7 | pub mod sysinfo; |
| 8 | |
| 9 | cfg_select! { |
| 10 | target_os = "windows" => { |
| 11 | mod windows; |
| 12 | pub(crate) use self::windows::get_swap_usage; |
| 13 | } |
| 14 | _ => { |
| 15 | pub(crate) use self::sysinfo::{get_cache_usage, get_swap_usage}; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | #[cfg(feature = "zfs")] |
| 20 | pub mod arc; |
| 21 | |
| 22 | #[derive(Debug, Clone)] |
| 23 | pub struct MemData { |
| 24 | pub used_bytes: u64, |
| 25 | pub total_bytes: NonZeroU64, |
| 26 | } |
| 27 | |
| 28 | impl MemData { |
| 29 | /// Return the use percentage. |
| 30 | #[inline] |
| 31 | pub fn percentage(&self) -> f64 { |
| 32 | let used = self.used_bytes as f64; |
| 33 | let total = self.total_bytes.get() as f64; |
| 34 | |
| 35 | used / total * 100.0 |
| 36 | } |
| 37 | } |