#[cfg(any(target_os = "linux", target_os = "macos"))]
pub(crate) fn os_peak_bytes() -> Result<u64, String> {
use nix::sys::resource::{UsageWho, getrusage};
let usage = getrusage(UsageWho::RUSAGE_SELF).map_err(|error| error.to_string())?;
let max_rss = u64::try_from(usage.max_rss()).map_err(|error| error.to_string())?;
match cfg!(target_os = "macos") {
true => Ok(max_rss),
false => Ok(max_rss.saturating_mul(crate::peak_memory::constants::KIB)),
}
}
#[cfg(windows)]
pub(crate) fn os_peak_bytes() -> Result<u64, String> {
crate::peak_memory::_helpers::windows::peak_working_set()
}
#[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
pub(crate) fn os_peak_bytes() -> Result<u64, String> {
Err(crate::peak_memory::constants::NO_PEAK_MEMORY.to_owned())
}