use crate::support::impl_get_set::impl_get_set;
use super::Pid;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum UpdateKind {
#[default]
Never,
Always,
OnlyIfNotSet,
}
impl UpdateKind {
#[allow(dead_code)] pub(crate) fn needs_update(self, f: impl Fn() -> bool) -> bool {
match self {
Self::Never => false,
Self::Always => true,
Self::OnlyIfNotSet => f(),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ProcessesToUpdate<'a> {
All,
Some(&'a [Pid]),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ProcessRefreshKind {
cpu: bool,
disk_usage: bool,
memory: bool,
user: UpdateKind,
cwd: UpdateKind,
root: UpdateKind,
environ: UpdateKind,
cmd: UpdateKind,
exe: UpdateKind,
tasks: bool,
gpu_usage: bool,
gpu_memory: bool,
}
impl Default for ProcessRefreshKind {
fn default() -> Self {
Self {
cpu: false,
disk_usage: false,
memory: false,
user: UpdateKind::default(),
cwd: UpdateKind::default(),
root: UpdateKind::default(),
environ: UpdateKind::default(),
cmd: UpdateKind::default(),
exe: UpdateKind::default(),
tasks: false,
gpu_usage: false,
gpu_memory: false,
}
}
}
impl ProcessRefreshKind {
pub fn nothing() -> Self {
Self::default()
}
pub fn everything() -> Self {
Self {
cpu: true,
disk_usage: true,
memory: true,
user: UpdateKind::OnlyIfNotSet,
cwd: UpdateKind::OnlyIfNotSet,
root: UpdateKind::OnlyIfNotSet,
environ: UpdateKind::OnlyIfNotSet,
cmd: UpdateKind::OnlyIfNotSet,
exe: UpdateKind::OnlyIfNotSet,
tasks: false,
gpu_usage: true,
gpu_memory: true,
}
}
impl_get_set!(
ProcessRefreshKind,
cpu,
with_cpu,
without_cpu,
"\
It will retrieve both CPU usage and CPU accumulated time,"
);
impl_get_set!(
ProcessRefreshKind,
disk_usage,
with_disk_usage,
without_disk_usage
);
impl_get_set!(
ProcessRefreshKind,
user,
with_user,
without_user,
UpdateKind,
"\
It will retrieve the following information:
* user ID
* user effective ID (if available on the platform)
* user group ID (if available on the platform)
* user effective ID (if available on the platform)"
);
impl_get_set!(ProcessRefreshKind, memory, with_memory, without_memory);
impl_get_set!(ProcessRefreshKind, cwd, with_cwd, without_cwd, UpdateKind);
impl_get_set!(
ProcessRefreshKind,
root,
with_root,
without_root,
UpdateKind
);
impl_get_set!(
ProcessRefreshKind,
environ,
with_environ,
without_environ,
UpdateKind
);
impl_get_set!(ProcessRefreshKind, cmd, with_cmd, without_cmd, UpdateKind);
impl_get_set!(ProcessRefreshKind, exe, with_exe, without_exe, UpdateKind);
impl_get_set!(ProcessRefreshKind, tasks, with_tasks, without_tasks);
impl_get_set!(
ProcessRefreshKind,
gpu_usage,
with_gpu_usage,
without_gpu_usage
);
impl_get_set!(
ProcessRefreshKind,
gpu_memory,
with_gpu_memory,
without_gpu_memory
);
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct CpuRefreshKind {
usage: bool,
frequency: bool,
}
impl CpuRefreshKind {
pub fn nothing() -> Self {
Self::default()
}
pub fn everything() -> Self {
Self {
usage: true,
frequency: true,
}
}
impl_get_set!(CpuRefreshKind, usage, with_usage, without_usage);
impl_get_set!(CpuRefreshKind, frequency, with_frequency, without_frequency);
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct MemoryRefreshKind {
ram: bool,
swap: bool,
}
impl MemoryRefreshKind {
pub fn nothing() -> Self {
Self::default()
}
pub fn everything() -> Self {
Self {
ram: true,
swap: true,
}
}
impl_get_set!(MemoryRefreshKind, ram, with_ram, without_ram);
impl_get_set!(MemoryRefreshKind, swap, with_swap, without_swap);
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[doc = include_str!("../../docs/snippets/refresh.md")]
pub struct RefreshKind {
processes: Option<ProcessRefreshKind>,
memory: Option<MemoryRefreshKind>,
cpu: Option<CpuRefreshKind>,
}
impl RefreshKind {
pub fn nothing() -> Self {
Self::default()
}
pub fn everything() -> Self {
Self {
processes: Some(ProcessRefreshKind::everything()),
memory: Some(MemoryRefreshKind::everything()),
cpu: Some(CpuRefreshKind::everything()),
}
}
impl_get_set!(
RefreshKind,
processes,
with_processes,
without_processes,
ProcessRefreshKind
);
impl_get_set!(
RefreshKind,
memory,
with_memory,
without_memory,
MemoryRefreshKind
);
impl_get_set!(RefreshKind, cpu, with_cpu, without_cpu, CpuRefreshKind);
}