added --enable_cache_memory flag, disabled cache memory collection by default

This commit is contained in:
Twan Stok 2023-03-13 22:49:30 +01:00
parent 69e1783bfb
commit e6fc69b1df
5 changed files with 32 additions and 1 deletions

View File

@ -60,6 +60,7 @@ pub struct AppConfigFields {
pub table_gap: u16,
pub disable_click: bool,
pub enable_gpu_memory: bool,
pub enable_cache_memory: bool,
pub show_table_scroll_position: bool,
pub is_advanced_kill: bool,
// TODO: Remove these, move network details state-side.

View File

@ -401,10 +401,12 @@ impl DataCollector {
fn update_memory_usage(&mut self) {
if self.widgets_to_harvest.use_mem {
self.data.memory = memory::get_ram_usage(&self.sys);
#[cfg(not(target_os = "windows"))]
{
if self.widgets_to_harvest.use_cache {
self.data.cache = memory::get_cache_usage(&self.sys);
}
self.data.swap = memory::get_swap_usage(
#[cfg(not(target_os = "windows"))]
&self.sys,

View File

@ -997,6 +997,7 @@ Supported widget names:
pub struct UsedWidgets {
pub use_cpu: bool,
pub use_mem: bool,
pub use_cache: bool,
pub use_gpu: bool,
pub use_net: bool,
pub use_proc: bool,

View File

@ -441,6 +441,14 @@ use CPU (3) as the default instead.
app = app.arg(enable_gpu_memory);
}
#[cfg(not(target_os = "windows"))]
{
let cache = Arg::new("enable_cache_memory")
.long("enable_cache_memory")
.help("Enable collecting and displaying cache and buffer memory.");
app = app.arg(cache);
}
app
}

View File

@ -80,6 +80,7 @@ pub struct ConfigFlags {
pub network_use_log: Option<bool>,
pub network_use_binary_prefix: Option<bool>,
pub enable_gpu_memory: Option<bool>,
pub enable_cache_memory: Option<bool>,
#[serde(with = "humantime_serde")]
#[serde(default)]
pub retention: Option<Duration>,
@ -236,6 +237,7 @@ pub fn build_app(
table_gap: u16::from(!(is_flag_enabled!(hide_table_gap, matches, config))),
disable_click: is_flag_enabled!(disable_click, matches, config),
enable_gpu_memory: get_enable_gpu_memory(matches, config),
enable_cache_memory: get_enable_cache_memory(matches, config),
show_table_scroll_position: is_flag_enabled!(show_table_scroll_position, matches, config),
is_advanced_kill,
network_scale_type,
@ -383,6 +385,7 @@ pub fn build_app(
let used_widgets = UsedWidgets {
use_cpu: used_widget_set.get(&Cpu).is_some() || used_widget_set.get(&BasicCpu).is_some(),
use_mem,
use_cache: use_mem && get_enable_cache_memory(matches, config),
use_gpu: use_mem && get_enable_gpu_memory(matches, config),
use_net: used_widget_set.get(&Net).is_some() || used_widget_set.get(&BasicNet).is_some(),
use_proc: used_widget_set.get(&Proc).is_some(),
@ -713,6 +716,22 @@ fn get_enable_gpu_memory(matches: &ArgMatches, config: &Config) -> bool {
false
}
#[allow(unused_variables)]
fn get_enable_cache_memory(matches: &ArgMatches, config: &Config) -> bool {
#[cfg(not(target_os = "windows"))]
{
if matches.contains_id("enable_cache_memory") {
return true;
} else if let Some(flags) = &config.flags {
if let Some(enable_cache_memory) = flags.enable_cache_memory {
return enable_cache_memory;
}
}
}
false
}
fn get_ignore_list(ignore_list: &Option<IgnoreList>) -> error::Result<Option<Filter>> {
if let Some(ignore_list) = ignore_list {
let list: Result<Vec<_>, _> = ignore_list