diff --git a/src/app.rs b/src/app.rs index a5e5c108..a78a20d2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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, - - #[builder(default, setter(strip_option))] pub dot_marker: Option, - - #[builder(default, setter(strip_option))] pub temperature_type: Option, - - #[builder(default, setter(strip_option))] pub rate: Option, - - #[builder(default, setter(strip_option))] pub left_legend: Option, - - #[builder(default, setter(strip_option))] pub current_usage: Option, - - #[builder(default, setter(strip_option))] pub group_processes: Option, - - #[builder(default, setter(strip_option))] pub case_sensitive: Option, - - #[builder(default, setter(strip_option))] pub whole_word: Option, - - #[builder(default, setter(strip_option))] pub regex: Option, - - #[builder(default, setter(strip_option))] pub basic: Option, - - #[builder(default, setter(strip_option))] pub default_time_value: Option, - - #[builder(default, setter(strip_option))] pub time_delta: Option, - - #[builder(default, setter(strip_option))] pub autohide_time: Option, - - #[builder(default, setter(strip_option))] pub hide_time: Option, - - #[builder(default, setter(strip_option))] pub default_widget_type: Option, - - #[builder(default, setter(strip_option))] pub default_widget_count: Option, - - #[builder(default, setter(strip_option))] pub use_old_network_legend: Option, - - #[builder(default, setter(strip_option))] pub hide_table_gap: Option, - - #[builder(default, setter(strip_option))] pub battery: Option, - - #[builder(default, setter(strip_option))] pub disable_click: Option, - - #[builder(default, setter(strip_option))] pub no_write: Option, - // For built-in colour palettes. - #[builder(default, setter(strip_option))] pub color: Option, - - // 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>, - - #[builder(default, setter(strip_option))] - pub search_case_enabled_widgets: Option>, - - #[builder(default, setter(strip_option))] - #[serde(skip)] - pub search_whole_word_enabled_widgets_map: Option>, - - #[builder(default, setter(strip_option))] - pub search_whole_word_enabled_widgets: Option>, - - #[builder(default, setter(strip_option))] - #[serde(skip)] - pub search_regex_enabled_widgets_map: Option>, - - #[builder(default, setter(strip_option))] - pub search_regex_enabled_widgets: Option>, - - // End hack - #[builder(default, setter(strip_option))] pub mem_as_value: Option, - - #[builder(default, setter(strip_option))] pub tree: Option, - - #[builder(default, setter(strip_option))] show_table_scroll_position: Option, - - #[builder(default, setter(strip_option))] pub process_command: Option, - - #[builder(default, setter(strip_option))] pub disable_advanced_kill: Option, - - #[builder(default, setter(strip_option))] pub network_use_bytes: Option, - - #[builder(default, setter(strip_option))] pub network_use_log: Option, - - #[builder(default, setter(strip_option))] pub network_use_binary_prefix: Option, + pub enable_gpu_memory: Option, } #[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") {