feat: configurable stats poll interval (#739)

This commit is contained in:
Ilya Zlobintsev
2025-09-06 11:37:37 +03:00
committed by GitHub
parent 6de194aad6
commit db32b8f315
5 changed files with 102 additions and 78 deletions
+7 -3
View File
@@ -101,7 +101,7 @@ gpu-clock = GPU Core Clock
gpu-clock-avg = GPU Core Clock (Average)
gpu-clock-target = GPU Core Clock (Target)
gpu-voltage = GPU Voltage
gpu-temp = GPU Temperature
gpu-temp = Temperature
gpu-usage = GPU Usage
vram-clock = VRAM Clock
power-usage = Power Usage
@@ -164,8 +164,12 @@ vram-pstates = VRAM Power States
pstates-manual-needed = Note: performance level must be set to 'manual' to toggle power states
enable-pstate-config = Enable power state configuration
show-historical-charts = Show historical charts
show-process-montor = Show process monitor
show-historical-charts = Show Historical Charts
show-process-monitor = Show Process Monitor
generate-debug-snapshot = Generate Debug Snapshot
dump-vbios = Dump VBIOS
reset-all-config = Reset All Configuration
stats-update-interval = Update Interval (ms)
reconnecting-to-daemon = Daemon connection lost, reconnecting...
daemon-connection-lost = Connection Lost
+3 -50
View File
@@ -15,7 +15,7 @@ use crate::{
overdrive_dialog::{OverdriveDialog, OverdriveDialogMsg},
process_monitor::{ProcessMonitorWindow, ProcessMonitorWindowMsg},
},
APP_ID, GUI_VERSION, I18N,
APP_ID, CONFIG, GUI_VERSION, I18N,
};
use anyhow::{anyhow, Context};
use apply_revealer::{ApplyRevealer, ApplyRevealerMsg};
@@ -52,7 +52,6 @@ use pages::{
PageUpdate,
};
use relm4::{
actions::{RelmAction, RelmActionGroup},
binding::BoolBinding,
prelude::{AsyncComponent, AsyncComponentParts},
tokio::{self, time::sleep},
@@ -79,7 +78,6 @@ use tracing::{debug, error, info, trace, warn};
pub(crate) static APP_BROKER: MessageBroker<AppMsg> = MessageBroker::new();
static ERROR_WINDOW_COUNT: AtomicU32 = AtomicU32::new(0);
const STATS_POLL_INTERVAL_MS: u64 = 250;
const PROCESS_POLL_INTERVAL_MS: u64 = 1500;
const NVIDIA_RECOMMENDED_MIN_VERSION: u32 = 560;
@@ -202,8 +200,6 @@ impl AsyncComponent for AppModel {
}
));
register_actions(&sender);
let system_info = daemon_client
.get_system_info()
.await
@@ -1092,10 +1088,10 @@ fn start_stats_update_loop(
sender: AsyncComponentSender<AppModel>,
header_sender: relm4::Sender<HeaderMsg>,
) -> glib::JoinHandle<()> {
debug!("spawning new stats update task with {STATS_POLL_INTERVAL_MS}ms interval");
let duration = Duration::from_millis(STATS_POLL_INTERVAL_MS);
debug!("spawning new stats update task");
relm4::spawn_local(async move {
loop {
let duration = Duration::from_millis(CONFIG.read().stats_poll_interval_ms as u64);
tokio::time::sleep(duration).await;
match daemon_client.get_device_stats(&gpu_id).await {
@@ -1123,49 +1119,6 @@ fn confirmation_text(seconds_left: u64) -> String {
format!("Do you want to keep the new settings? (Reverting in {seconds_left} seconds)")
}
fn register_actions(sender: &AsyncComponentSender<AppModel>) {
let mut group = RelmActionGroup::<AppActionGroup>::new();
macro_rules! actions {
($(($action:ty, $msg:expr),)*) => {
$(
group.add_action(RelmAction::<$action>::new_stateless(clone!(
#[strong]
sender,
move |_| sender.input($msg)
)));
)*
}
}
actions! {
(ShowGraphsWindow, AppMsg::ShowGraphsWindow),
(ShowProcessMonitor, AppMsg::ShowProcessMonitor),
(DumpVBios, AppMsg::DumpVBios),
(DebugSnapshot, AppMsg::DebugSnapshot),
(DisableOverdrive, AppMsg::ShowOverdriveDialog),
(
ResetConfig,
AppMsg::ask_confirmation(
AppMsg::ResetConfig,
fl!(I18N, "reset-config"),
fl!(I18N, "reset-config-description"),
gtk::ButtonsType::YesNo,
)
),
};
group.register_for_main_application();
}
relm4::new_action_group!(AppActionGroup, "app");
relm4::new_stateless_action!(ShowGraphsWindow, AppActionGroup, "show-graphs-window");
relm4::new_stateless_action!(ShowProcessMonitor, AppActionGroup, "show-process-monitor");
relm4::new_stateless_action!(DumpVBios, AppActionGroup, "dump-vbios");
relm4::new_stateless_action!(DebugSnapshot, AppActionGroup, "generate-debug-snapshot");
relm4::new_stateless_action!(DisableOverdrive, AppActionGroup, "disable-overdrive");
relm4::new_stateless_action!(ResetConfig, AppActionGroup, "reset-config");
async fn create_connection() -> anyhow::Result<(DaemonClient, Option<anyhow::Error>)> {
match DaemonClient::connect().await {
Ok(connection) => {
+82 -23
View File
@@ -4,11 +4,9 @@ mod profile_row;
pub mod profile_rule_window;
use crate::{
app::{header::profile_rule_window::ProfileEditParams, ShowProcessMonitor, APP_BROKER},
app::{header::profile_rule_window::ProfileEditParams, msg::AppMsg, APP_BROKER},
CONFIG, I18N,
};
use super::{AppMsg, DebugSnapshot, DisableOverdrive, DumpVBios, ResetConfig, ShowGraphsWindow};
use glib::clone;
use gtk::prelude::*;
use gtk::*;
@@ -69,7 +67,7 @@ impl Component for Header {
set_label: &model.selector_label,
#[wrap(Some)]
set_popover = &gtk::Popover {
set_margin_all: 5,
set_margin_horizontal: 5,
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
@@ -145,27 +143,88 @@ impl Component for Header {
pack_end = &gtk::MenuButton {
set_icon_name: "open-menu-symbolic",
set_menu_model: Some(&app_menu),
#[wrap(Some)]
set_popover = &gtk::Popover {
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 5,
set_margin_all: 5,
gtk::Button {
set_label: &fl!(I18N, "show-historical-charts"),
connect_clicked => move |_| APP_BROKER.send(AppMsg::ShowGraphsWindow),
add_css_class: "flat",
},
gtk::Button {
set_label: &fl!(I18N, "show-process-monitor"),
connect_clicked => move |_| APP_BROKER.send(AppMsg::ShowProcessMonitor),
add_css_class: "flat",
},
gtk::Separator {},
gtk::Button {
set_label: &fl!(I18N, "generate-debug-snapshot"),
connect_clicked => move |_| APP_BROKER.send(AppMsg::DebugSnapshot),
add_css_class: "flat",
},
gtk::Button {
set_label: &fl!(I18N, "dump-vbios"),
connect_clicked => move |_| APP_BROKER.send(AppMsg::DumpVBios),
add_css_class: "flat",
},
gtk::Separator {},
gtk::Button {
set_label: &fl!(I18N, "disable-amd-oc"),
connect_clicked => move |_| APP_BROKER.send(AppMsg::ShowOverdriveDialog),
add_css_class: "flat",
},
gtk::Button {
set_label: &fl!(I18N, "reset-all-config"),
connect_clicked => move |_| {
let msg = AppMsg::ask_confirmation(
AppMsg::ResetConfig,
fl!(I18N, "reset-config"),
fl!(I18N, "reset-config-description"),
gtk::ButtonsType::YesNo,
);
APP_BROKER.send(msg);
},
add_css_class: "flat",
},
gtk::Separator {},
gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
set_spacing: 5,
gtk::Label {
set_markup: &format!("<b>{}</b>", &fl!(I18N, "stats-update-interval")),
},
gtk::SpinButton {
set_range: (250.0, 5000.0),
set_increments: (250.0, 500.0),
set_digits: 0,
set_value: CONFIG.read().stats_poll_interval_ms as f64,
connect_value_changed => move |btn| {
CONFIG.write().edit(|config| {
config.stats_poll_interval_ms = btn.value() as i64;
})
}
},
},
}
},
}
},
}
menu! {
app_menu: {
section! {
"Show historical charts" => ShowGraphsWindow,
"Show process monitor" => ShowProcessMonitor,
},
section! {
"Generate debug snapshot" => DebugSnapshot,
"Dump VBIOS" => DumpVBios,
} ,
section! {
"Disable AMD overclocking support" => DisableOverdrive,
"Reset all configuration" => ResetConfig,
}
}
}
fn init(
@@ -1,8 +1,10 @@
use crate::app::msg::AppMsg;
use crate::app::APP_BROKER;
use crate::app::{
ext::FlowBoxExt, info_row::InfoRow, page_section::PageSection, pages::PageUpdate,
};
use crate::I18N;
use gtk::prelude::{ActionableExt, BoxExt, ButtonExt, OrientableExt, WidgetExt};
use gtk::prelude::{BoxExt, ButtonExt, OrientableExt, WidgetExt};
use i18n_embed_fl::fl;
use lact_schema::{DeviceStats, PowerStats};
use relm4::{ComponentParts, ComponentSender};
@@ -168,7 +170,7 @@ impl relm4::SimpleComponent for GpuStatsSection {
append = &gtk::Button {
set_label: &fl!(I18N, "show-historical-charts"),
set_action_name: Some("app.show-graphs-window"),
connect_clicked => move |_| APP_BROKER.send(AppMsg::ShowGraphsWindow),
},
}
}
+6
View File
@@ -11,6 +11,8 @@ pub struct UiConfig {
pub plots_time_period: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub plots_per_row: Option<u64>,
#[serde(default = "default_stats_poll_interval")]
pub stats_poll_interval_ms: i64,
#[serde(default)]
pub gpus: HashMap<String, UiGpuConfig>,
}
@@ -73,3 +75,7 @@ fn config_path() -> PathBuf {
}));
config_dir.join("lact").join("ui.yaml")
}
fn default_stats_poll_interval() -> i64 {
500
}