use yash_env::system::resource::{rlim_t, Resource};
pub trait ResourceExt {
#[must_use]
fn option(&self) -> char;
#[must_use]
fn description(&self) -> &'static str;
#[must_use]
fn scale(&self) -> rlim_t;
}
impl ResourceExt for Resource {
fn option(&self) -> char {
match self {
Self::AS => 'v',
Self::CORE => 'c',
Self::CPU => 't',
Self::DATA => 'd',
Self::FSIZE => 'f',
Self::KQUEUES => 'k',
Self::LOCKS => 'x',
Self::MEMLOCK => 'l',
Self::MSGQUEUE => 'q',
Self::NICE => 'e',
Self::NOFILE => 'n',
Self::NPROC => 'u',
Self::RSS => 'm',
Self::RTPRIO => 'r',
Self::RTTIME => 'R',
Self::SBSIZE => 'b',
Self::SIGPENDING => 'i',
Self::STACK => 's',
Self::SWAP => 'w',
_ => '\0',
}
}
fn description(&self) -> &'static str {
match self {
Self::AS => "virtual address space size (KiB)",
Self::CORE => "core dump size (512-byte blocks)",
Self::CPU => "CPU time (seconds)",
Self::DATA => "data segment size (KiB)",
Self::FSIZE => "file size (512-byte blocks)",
Self::KQUEUES => "number of kqueues",
Self::LOCKS => "number of file locks",
Self::MEMLOCK => "locked memory size (KiB)",
Self::MSGQUEUE => "message queue size (bytes)",
Self::NICE => "process priority (20 - nice)",
Self::NOFILE => "number of open files",
Self::NPROC => "number of processes",
Self::RSS => "resident set size (KiB)",
Self::RTPRIO => "real-time priority",
Self::RTTIME => "real-time timeout (microseconds)",
Self::SBSIZE => "socket buffer size (bytes)",
Self::SIGPENDING => "number of pending signals",
Self::STACK => "stack size (KiB)",
Self::SWAP => "swap space size (KiB)",
_ => "unknown resource",
}
}
fn scale(&self) -> rlim_t {
match self {
Self::AS | Self::DATA | Self::MEMLOCK | Self::RSS | Self::STACK | Self::SWAP => 1 << 10,
Self::CORE | Self::FSIZE => 1 << 9,
_ => 1,
}
}
}