Add getrusage suite to sys.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -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
|
||||
|
||||
25
src/core/utils/sys/usage.rs
Normal file
25
src/core/utils/sys/usage.rs
Normal 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()) }
|
||||
Reference in New Issue
Block a user