Add getrusage suite to sys.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2026-02-25 23:11:43 +00:00
parent 340b05d88e
commit 37818e1a25
2 changed files with 27 additions and 1 deletions

View File

@@ -1,10 +1,11 @@
pub mod compute;
pub mod limits;
pub mod storage;
pub mod usage;
use std::path::PathBuf;
pub use self::{compute::available_parallelism, limits::*};
pub use self::{compute::available_parallelism, limits::*, usage::*};
use crate::{Result, at};
/// Return a possibly corrected std::env::current_exe() even if the path is

View File

@@ -0,0 +1,25 @@
use nix::sys::resource::Usage;
#[cfg(unix)]
use nix::sys::resource::{UsageWho, getrusage};
use crate::Result;
#[cfg(unix)]
pub fn usage() -> Result<Usage> { getrusage(UsageWho::RUSAGE_SELF).map_err(Into::into) }
#[cfg(not(unix))]
pub fn usage() -> Result<Usage> { Ok(Usage::default()) }
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "openbsd"
))]
pub fn thread_usage() -> Result<Usage> { getrusage(UsageWho::RUSAGE_THREAD).map_err(Into::into) }
#[cfg(not(any(
target_os = "linux",
target_os = "freebsd",
target_os = "openbsd"
)))]
pub fn thread_usage() -> Result<Usage> { Ok(Usage::default()) }