diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2022-10-15 16:50:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-15 16:50:21 -0400 |
commit | a949740c942d69fba51b3cf3b5f1fd9dfc3a9c24 (patch) | |
tree | 54b1ef00831dbdbf0db7aef7780bee5b2bfcc200 /src | |
parent | bd35bbdc9c539e035bc4bf91c799d85e566a6921 (diff) |
other: make gpu memory collection configurable (#835)
Follow-up to #794, this makes GPU memory collection toggleable.
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 2 | ||||
-rw-r--r-- | src/app/data_harvester.rs | 11 | ||||
-rw-r--r-- | src/app/data_harvester/memory/general/heim.rs | 8 | ||||
-rw-r--r-- | src/app/data_harvester/memory/general/sysinfo.rs | 8 | ||||
-rw-r--r-- | src/app/layout_manager.rs | 1 | ||||
-rw-r--r-- | src/canvas/widgets/mem_basic.rs | 5 | ||||
-rw-r--r-- | src/clap.rs | 21 | ||||
-rw-r--r-- | src/options.rs | 153 |
8 files changed, 64 insertions, 145 deletions
@@ -67,7 +67,7 @@ pub struct AppConfigFields { pub use_old_network_legend: bool, pub table_gap: u16, pub disable_click: bool, - pub no_write: bool, + pub enable_gpu_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 4f163755..f289f41f 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester.rs @@ -405,11 +405,18 @@ impl DataCollector { let mem_data_fut = { #[cfg(not(target_os = "freebsd"))] { - memory::get_mem_data(self.widgets_to_harvest.use_mem) + memory::get_mem_data( + self.widgets_to_harvest.use_mem, + self.widgets_to_harvest.use_gpu, + ) } #[cfg(target_os = "freebsd")] { - memory::get_mem_data(&self.sys, self.widgets_to_harvest.use_mem) + memory::get_mem_data( + &self.sys, + self.widgets_to_harvest.use_mem, + self.widgets_to_harvest.use_gpu, + ) } }; let disk_data_fut = disks::get_disk_usage( diff --git a/src/app/data_harvester/memory/general/heim.rs b/src/app/data_harvester/memory/general/heim.rs index 83f78ae4..eb596ea7 100644 --- a/src/app/data_harvester/memory/general/heim.rs +++ b/src/app/data_harvester/memory/general/heim.rs @@ -2,7 +2,7 @@ use crate::data_harvester::memory::{MemCollect, MemHarvest}; -pub async fn get_mem_data(actually_get: bool) -> MemCollect { +pub async fn get_mem_data(actually_get: bool, _get_gpu: bool) -> MemCollect { if !actually_get { MemCollect { ram: Ok(None), @@ -19,7 +19,11 @@ pub async fn get_mem_data(actually_get: bool) -> MemCollect { #[cfg(feature = "zfs")] arc: get_arc_data().await, #[cfg(feature = "gpu")] - gpus: get_gpu_data().await, + gpus: if _get_gpu { + get_gpu_data().await + } else { + Ok(None) + }, } } } diff --git a/src/app/data_harvester/memory/general/sysinfo.rs b/src/app/data_harvester/memory/general/sysinfo.rs index cf80c206..93130e96 100644 --- a/src/app/data_harvester/memory/general/sysinfo.rs +++ b/src/app/data_harvester/memory/general/sysinfo.rs @@ -3,7 +3,7 @@ use crate::data_harvester::memory::{MemCollect, MemHarvest}; use sysinfo::{System, SystemExt}; -pub async fn get_mem_data(sys: &System, actually_get: bool) -> MemCollect { +pub async fn get_mem_data(sys: &System, actually_get: bool, _get_gpu: bool) -> MemCollect { if !actually_get { MemCollect { ram: Ok(None), @@ -20,7 +20,11 @@ pub async fn get_mem_data(sys: &System, actually_get: bool) -> MemCollect { #[cfg(feature = "zfs")] arc: get_arc_data().await, #[cfg(feature = "gpu")] - gpus: get_gpu_data().await, + gpus: if _get_gpu { + get_gpu_data().await + } else { + Ok(None) + }, } } } diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs index cf23efda..9148ab5b 100644 --- a/src/app/layout_manager.rs +++ b/src/app/layout_manager.rs @@ -1001,6 +1001,7 @@ Supported widget names: pub struct UsedWidgets { pub use_cpu: bool, pub use_mem: bool, + pub use_gpu: bool, pub use_net: bool, pub use_proc: bool, pub use_disk: bool, diff --git a/src/canvas/widgets/mem_basic.rs b/src/canvas/widgets/mem_basic.rs index 8f372eff..5e3d3d91 100644 --- a/src/canvas/widgets/mem_basic.rs +++ b/src/canvas/widgets/mem_basic.rs @@ -104,9 +104,10 @@ impl Painter { #[cfg(feature = "gpu")] { - let gpu_styles = &self.colours.gpu_colour_styles; - let mut color_index = 0; if let Some(gpu_data) = &app_state.converted_data.gpu_data { + let gpu_styles = &self.colours.gpu_colour_styles; + let mut color_index = 0; + gpu_data.iter().for_each(|gpu_data_vec| { let gpu_data = gpu_data_vec.points.as_slice(); let gpu_percentage = if let Some(gpu) = gpu_data.last() { diff --git a/src/clap.rs b/src/clap.rs index a882d932..c24498f3 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -348,7 +348,8 @@ use CPU (3) as the default instead. "Displays the network widget with binary prefixes (i.e. kibibits, mebibits) rather than a decimal prefix (i.e. kilobits, megabits). Defaults to decimal prefixes.", ); - let app = Command::new(crate_name!()) + #[allow(unused_mut)] + let mut app = Command::new(crate_name!()) .version(crate_version!()) .author(crate_authors!()) .about(crate_description!()) @@ -392,19 +393,27 @@ use CPU (3) as the default instead. .arg(use_old_network_legend) .arg(whole_word); - if cfg!(feature = "battery") { + #[cfg(feature = "battery")] + { let battery = Arg::new("battery") .long("battery") .help("Shows the battery widget.") .long_help( "Shows the battery widget in default or basic mode. No effect on custom layouts.", ); - app.arg(battery) - } else { - app + app = app.arg(battery); + } + + #[cfg(feature = "gpu")] + { + let enable_gpu_memory = Arg::new("enable_gpu_memory") + .long("enable_gpu_memory") + .help("Enable collecting and displaying GPU memory usage."); + app = app.arg(enable_gpu_memory); } -} + app +} #[cfg(test)] mod test { use super::*; diff --git a/src/options.rs b/src/options.rs index d85632c9..c2bac1c9 100644 --- a/src/options.rs +++ b/src/options.rs @@ -53,123 +53,39 @@ impl Config { #[derive(Clone, Debug, Default, Deserialize, Serialize, TypedBuilder)] pub struct ConfigFlags { - #[builder(default, setter(strip_option))] pub hide_avg_cpu: Option<bool>, - - #[builder(default, setter(strip_option))] pub dot_marker: Option<bool>, - - #[builder(default, setter(strip_option))] pub temperature_type: Option<String>, - - #[builder(default, setter(strip_option))] pub rate: Option<u64>, - - #[builder(default, setter(strip_option))] pub left_legend: Option<bool>, - - #[builder(default, setter(strip_option))] pub current_usage: Option<bool>, - - #[builder(default, setter(strip_option))] pub group_processes: Option<bool>, - - #[builder(default, setter(strip_option))] pub case_sensitive: Option<bool>, - - #[builder(default, setter(strip_option))] pub whole_word: Option<bool>, - - #[builder(default, setter(strip_option))] pub regex: Option<bool>, - - #[builder(default, setter(strip_option))] pub basic: Option<bool>, - - #[builder(default, setter(strip_option))] pub default_time_value: Option<u64>, - - #[builder(default, setter(strip_option))] pub time_delta: Option<u64>, - - #[builder(default, setter(strip_option))] pub autohide_time: Option<bool>, - - #[builder(default, setter(strip_option))] pub hide_time: Option<bool>, - - #[builder(default, setter(strip_option))] pub default_widget_type: Option<String>, - - #[builder(default, setter(strip_option))] pub default_widget_count: Option<u64>, - - #[builder(default, setter(strip_option))] pub use_old_network_legend: Option<bool>, - - #[builder(default, setter(strip_option))] pub hide_table_gap: Option<bool>, - - #[builder(default, setter(strip_option))] pub battery: Option<bool>, - - #[builder(default, setter(strip_option))] pub disable_click: Option<bool>, - - #[builder(default, setter(strip_option))] pub no_write: Option<bool>, - // For built-in colour palettes. - #[builder(default, setter(strip_option))] pub color: Option<String>, - - // This is a huge hack to enable hashmap functionality WITHOUT being able to serializing the field. - // Basically, keep a hashmap in the struct, and convert to a vector every time. - #[builder(default, setter(strip_option))] - #[serde(skip)] - pub search_case_enabled_widgets_map: Option<HashMap<u64, bool>>, - - #[builder(default, setter(strip_option))] - pub search_case_enabled_widgets: Option<Vec<WidgetIdEnabled>>, - - #[builder(default, setter(strip_option))] - #[serde(skip)] - pub search_whole_word_enabled_widgets_map: Option<HashMap<u64, bool>>, - - #[builder(default, setter(strip_option))] - pub search_whole_word_enabled_widgets: Option<Vec<WidgetIdEnabled>>, - - #[builder(default, setter(strip_option))] - #[serde(skip)] - pub search_regex_enabled_widgets_map: Option<HashMap<u64, bool>>, - - #[builder(default, setter(strip_option))] - pub search_regex_enabled_widgets: Option<Vec<WidgetIdEnabled>>, - - // End hack - #[builder(default, setter(strip_option))] pub mem_as_value: Option<bool>, - - #[builder(default, setter(strip_option))] pub tree: Option<bool>, - - #[builder(default, setter(strip_option))] show_table_scroll_position: Option<bool>, - - #[builder(default, setter(strip_option))] pub process_command: Option<bool>, - - #[builder(default, setter(strip_option))] pub disable_advanced_kill: Option<bool>, - - #[builder(default, setter(strip_option))] pub network_use_bytes: Option<bool>, - - #[builder(default, setter(strip_option))] pub network_use_log: Option<bool>, - - #[builder(default, setter(strip_option))] pub network_use_binary_prefix: Option<bool>, + pub enable_gpu_memory: Option<bool>, } #[derive(Clone, Default, Debug, Deserialize, Serialize)] @@ -317,8 +233,7 @@ pub fn build_app( 1 }, disable_click: get_disable_click(matches, config), - // no_write: get_no_write(matches, config), - no_write: false, + enable_gpu_memory: get_enable_gpu_memory(matches, config), show_table_scroll_position: get_show_table_scroll_position(matches, config), is_advanced_kill, network_scale_type, @@ -461,9 +376,16 @@ pub fn build_app( None }; + let use_mem = used_widget_set.get(&Mem).is_some() || used_widget_set.get(&BasicMem).is_some(); let used_widgets = UsedWidgets { use_cpu: used_widget_set.get(&Cpu).is_some() || used_widget_set.get(&BasicCpu).is_some(), - use_mem: used_widget_set.get(&Mem).is_some() || used_widget_set.get(&BasicMem).is_some(), + use_mem, + use_gpu: use_mem + && config + .flags + .as_ref() + .and_then(|f| f.enable_gpu_memory) + .unwrap_or(false), 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(), use_disk: used_widget_set.get(&Disk).is_some(), @@ -480,48 +402,6 @@ pub fn build_app( let net_filter = get_ignore_list(&config.net_filter).context("Update 'net_filter' in your config file")?; - // One more thing - we have to update the search settings of our proc_state_map, and create the hashmaps if needed! - // Note that if you change your layout, this might not actually match properly... not sure if/where we should deal with that... - if let Some(flags) = &mut config.flags { - if flags.case_sensitive.is_none() && !matches.is_present("case_sensitive") { - if let Some(search_case_enabled_widgets) = &flags.search_case_enabled_widgets { - let mapping = HashMap::new(); - for widget in search_case_enabled_widgets { - if let Some(proc_widget) = proc_state_map.get_mut(&widget.id) { - proc_widget.proc_search.is_ignoring_case = !widget.enabled; - } - } - flags.search_case_enabled_widgets_map = Some(mapping); - } - } - - if flags.whole_word.is_none() && !matches.is_present("whole_word") { - if let Some(search_whole_word_enabled_widgets) = - &flags.search_whole_word_enabled_widgets - { - let mapping = HashMap::new(); - for widget in search_whole_word_enabled_widgets { - if let Some(proc_widget) = proc_state_map.get_mut(&widget.id) { - proc_widget.proc_search.is_searching_whole_word = widget.enabled; - } - } - flags.search_whole_word_enabled_widgets_map = Some(mapping); - } - } - - if flags.regex.is_none() && !matches.is_present("regex") { - if let Some(search_regex_enabled_widgets) = &flags.search_regex_enabled_widgets { - let mapping = HashMap::new(); - for widget in search_regex_enabled_widgets { - if let Some(proc_widget) = proc_state_map.get_mut(&widget.id) { - proc_widget.proc_search.is_searching_with_regex = widget.enabled; - } - } - flags.search_regex_enabled_widgets_map = Some(mapping); - } - } - } - Ok(App::builder() .app_config_fields(app_config_fields) .cpu_state(CpuState::init(cpu_state_map)) @@ -948,6 +828,19 @@ fn get_use_battery(matches: &clap::ArgMatches, config: &Config) -> bool { false } +fn get_enable_gpu_memory(matches: &clap::ArgMatches, config: &Config) -> bool { + if cfg!(feature = "gpu") { + if matches.is_present("enable_gpu_memory") { + return true; + } else if let Some(flags) = &config.flags { + if let Some(enable_gpu_memory) = flags.enable_gpu_memory { + return enable_gpu_memory; + } + } + } + false +} + #[allow(dead_code)] fn get_no_write(matches: &clap::ArgMatches, config: &Config) -> bool { if matches.is_present("no_write") { |