From cd2f3ddd70c0b8cc3533872389bdc7a212fb1e35 Mon Sep 17 00:00:00 2001 From: Ilya Zlobintsev Date: Tue, 2 Mar 2021 15:11:45 +0200 Subject: [PATCH] Show GPU usage and temperature on the OC page --- daemon/src/gpu_controller.rs | 7 +++ gui/src/app/root_stack/oc_page/stats_grid.rs | 46 ++++++++++++++++++-- gui/src/main.rs | 2 + 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/daemon/src/gpu_controller.rs b/daemon/src/gpu_controller.rs index 1f72fba..de40dcb 100644 --- a/daemon/src/gpu_controller.rs +++ b/daemon/src/gpu_controller.rs @@ -104,6 +104,7 @@ pub struct GpuStats { pub fan_speed: Option, pub max_fan_speed: Option, pub voltage: Option, + pub gpu_usage: Option, } #[derive(Serialize, Deserialize, Debug)] @@ -329,6 +330,11 @@ impl GpuController { Ok(a) => Some(a.trim().parse::().unwrap() / 1024 / 1024), Err(_) => None, }; + + let gpu_usage = match fs::read_to_string(self.hw_path.join("gpu_busy_percent")) { + Ok(a) => Some(a.trim().parse::().unwrap()), + Err(_) => None, + }; let ( mem_freq, @@ -367,6 +373,7 @@ impl GpuController { fan_speed, max_fan_speed, voltage, + gpu_usage, }) } diff --git a/gui/src/app/root_stack/oc_page/stats_grid.rs b/gui/src/app/root_stack/oc_page/stats_grid.rs index 0186a8d..0f28b88 100644 --- a/gui/src/app/root_stack/oc_page/stats_grid.rs +++ b/gui/src/app/root_stack/oc_page/stats_grid.rs @@ -10,6 +10,8 @@ pub struct StatsGrid { vram_clock_label: Label, gpu_voltage_label: Label, power_usage_label: Label, + gpu_temperature_label: Label, + gpu_usage_label: Label, } impl StatsGrid { @@ -37,7 +39,7 @@ impl StatsGrid { vram_usage_overlay.add(&vram_usage_bar); vram_usage_overlay.add_overlay(&vram_usage_label); - container.attach(&vram_usage_overlay, 1, 0, 1, 1); + container.attach(&vram_usage_overlay, 1, 0, 2, 1); } let gpu_clock_label = Label::new(None); @@ -81,7 +83,7 @@ impl StatsGrid { gpu_voltage_box.set_halign(Align::Center); - container.attach(&gpu_voltage_box, 0, 2, 1, 1); + container.attach(&gpu_voltage_box, 2, 1, 1, 1); } let power_usage_label = Label::new(None); @@ -96,7 +98,35 @@ impl StatsGrid { power_usage_box.set_halign(Align::Center); - container.attach(&power_usage_box, 1, 2, 1, 1); + container.attach(&power_usage_box, 0, 2, 1, 1); + } + + let gpu_temperature_label = Label::new(None); + { + let gpu_temperature_box = Box::new(Orientation::Horizontal, 5); + + gpu_temperature_box.pack_start(&Label::new(Some("GPU Temperature:")), false, false, 2); + + // gpu_temperature_label.set_markup("0°C"); + + gpu_temperature_box.pack_start(&gpu_temperature_label, false, false, 2); + + gpu_temperature_box.set_halign(Align::Center); + + container.attach(&gpu_temperature_box, 1, 2, 1, 1); + } + + let gpu_usage_label = Label::new(None); + { + let gpu_usage_box = Box::new(Orientation::Horizontal, 5); + + gpu_usage_box.pack_start(&Label::new(Some("GPU Usage:")), false, false, 2); + + gpu_usage_box.pack_start(&gpu_usage_label, false, false, 2); + + gpu_usage_box.set_halign(Align::Center); + + container.attach(&gpu_usage_box, 2, 2, 1, 1); } Self { @@ -107,6 +137,8 @@ impl StatsGrid { vram_clock_label, gpu_voltage_label, power_usage_label, + gpu_temperature_label, + gpu_usage_label, } } @@ -141,5 +173,13 @@ impl StatsGrid { stats.power_avg.unwrap_or_else(|| 0), stats.power_cap.unwrap_or_else(|| 0) )); + self.gpu_temperature_label.set_markup(&format!( + "{}°C", + stats.gpu_temp.unwrap_or_default() + )); + self.gpu_usage_label.set_markup(&format!( + "{}%", + stats.gpu_usage.unwrap_or_default() + )); } } diff --git a/gui/src/main.rs b/gui/src/main.rs index 98c9f6b..015643d 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -25,6 +25,8 @@ fn ask_for_online_update(connection: &DaemonConnection) { let mut config = connection.get_config().unwrap(); if let None = config.allow_online_update { + log::trace!("Online access permission not configured! Showing the dialog"); + let diag = MessageDialog::new( None::<&Window>, DialogFlags::empty(),