From e6fc69b1df7c11b2f5969e02a1fcd3cfef013c68 Mon Sep 17 00:00:00 2001 From: Twan Stok Date: Mon, 13 Mar 2023 22:49:30 +0100 Subject: [PATCH] added --enable_cache_memory flag, disabled cache memory collection by default --- src/app.rs | 1 + src/app/data_harvester.rs | 4 +++- src/app/layout_manager.rs | 1 + src/clap.rs | 8 ++++++++ src/options.rs | 19 +++++++++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 9c3a37fd..03c73fb4 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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. diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs index 06d627f1..d3b8eeb6 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester.rs @@ -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, diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs index abc60899..032ccf98 100644 --- a/src/app/layout_manager.rs +++ b/src/app/layout_manager.rs @@ -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, diff --git a/src/clap.rs b/src/clap.rs index b7610583..82e94716 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -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 } diff --git a/src/options.rs b/src/options.rs index 0a620129..2931f4aa 100644 --- a/src/options.rs +++ b/src/options.rs @@ -80,6 +80,7 @@ pub struct ConfigFlags { pub network_use_log: Option, pub network_use_binary_prefix: Option, pub enable_gpu_memory: Option, + pub enable_cache_memory: Option, #[serde(with = "humantime_serde")] #[serde(default)] pub retention: Option, @@ -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) -> error::Result> { if let Some(ignore_list) = ignore_list { let list: Result, _> = ignore_list