From bdafcd92b882d1723feb423788e8342b82a3dc6e Mon Sep 17 00:00:00 2001 From: Shinyeong Hyun Date: Sat, 3 May 2025 03:07:43 +0900 Subject: [PATCH] Implemented storage update interval at the UI side (#1706) * Minor refactoring for #1699 * Implemented storage update interval for the UI * Revert "Implemented storage update interval for the UI" This reverts commit 977ff2f5518d420e35cadad17054f4e69c260df1. * Revert "Minor refactoring for #1699" This reverts commit 923f6d6f636a2a10ff44b8c23f84e8985ccbf667. * Made update interval configurable for storage devices * Changed label text m to min for consistency * Revised 8e6c669 as requested * ATA Update interval defaults to 1s in the UI * Simplified storage update interval menu --- LibreHardwareMonitor/UI/MainForm.Designer.cs | 12 +++++++++- LibreHardwareMonitor/UI/MainForm.cs | 17 ++++++++++++++ .../Hardware/Storage/ATAStorage.cs | 23 ++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/LibreHardwareMonitor/UI/MainForm.Designer.cs b/LibreHardwareMonitor/UI/MainForm.Designer.cs index e7785cd..7dc9831 100644 --- a/LibreHardwareMonitor/UI/MainForm.Designer.cs +++ b/LibreHardwareMonitor/UI/MainForm.Designer.cs @@ -123,6 +123,7 @@ namespace LibreHardwareMonitor.UI this.updateInterval2sMenuItem = new LibreHardwareMonitor.UI.ToolStripRadioButtonMenuItem(); this.updateInterval5sMenuItem = new LibreHardwareMonitor.UI.ToolStripRadioButtonMenuItem(); this.updateInterval10sMenuItem = new LibreHardwareMonitor.UI.ToolStripRadioButtonMenuItem(); + this.throttleAtaUpdateMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sensorValuesTimeWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.timeWindow30sMenuItem = new LibreHardwareMonitor.UI.ToolStripRadioButtonMenuItem(); this.timeWindow1minMenuItem = new LibreHardwareMonitor.UI.ToolStripRadioButtonMenuItem(); @@ -787,7 +788,8 @@ namespace LibreHardwareMonitor.UI this.updateInterval1sMenuItem, this.updateInterval2sMenuItem, this.updateInterval5sMenuItem, - this.updateInterval10sMenuItem}); + this.updateInterval10sMenuItem, + this.throttleAtaUpdateMenuItem}); this.updateIntervalMenuItem.Name = "updateIntervalMenuItem"; this.updateIntervalMenuItem.Size = new System.Drawing.Size(221, 22); this.updateIntervalMenuItem.Text = "Update Interval"; @@ -834,6 +836,13 @@ namespace LibreHardwareMonitor.UI this.updateInterval10sMenuItem.Size = new System.Drawing.Size(107, 22); this.updateInterval10sMenuItem.Text = "10s"; // + // throttleATAUpdateMenuItem + // + this.throttleAtaUpdateMenuItem.CheckOnClick = true; + this.throttleAtaUpdateMenuItem.Name = "throttleATAUpdateMenuItem"; + this.throttleAtaUpdateMenuItem.Size = new System.Drawing.Size(107, 22); + this.throttleAtaUpdateMenuItem.Text = "Throttle ATA Storage"; + // // sensorValuesTimeWindowMenuItem // this.sensorValuesTimeWindowMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -1171,6 +1180,7 @@ namespace LibreHardwareMonitor.UI private ToolStripRadioButtonMenuItem updateInterval2sMenuItem; private ToolStripRadioButtonMenuItem updateInterval5sMenuItem; private ToolStripRadioButtonMenuItem updateInterval10sMenuItem; + private System.Windows.Forms.ToolStripMenuItem throttleAtaUpdateMenuItem; private System.Windows.Forms.ToolStripMenuItem nicMenuItem; private System.Windows.Forms.ToolStripMenuItem sensorValuesTimeWindowMenuItem; private ToolStripRadioButtonMenuItem timeWindow30sMenuItem; diff --git a/LibreHardwareMonitor/UI/MainForm.cs b/LibreHardwareMonitor/UI/MainForm.cs index 6864bef..6273d77 100644 --- a/LibreHardwareMonitor/UI/MainForm.cs +++ b/LibreHardwareMonitor/UI/MainForm.cs @@ -15,6 +15,7 @@ using System.Windows.Forms; using Aga.Controls.Tree; using Aga.Controls.Tree.NodeControls; using LibreHardwareMonitor.Hardware; +using LibreHardwareMonitor.Hardware.Storage; using LibreHardwareMonitor.UI.Themes; using LibreHardwareMonitor.Utilities; using LibreHardwareMonitor.Wmi; @@ -30,6 +31,7 @@ public sealed partial class MainForm : Form private readonly Logger _logger; private readonly UserRadioGroup _loggingInterval; private readonly UserRadioGroup _updateInterval; + private readonly UserOption _throttleAtaUpdate; private readonly UserOption _logSensors; private readonly UserOption _minimizeOnClose; private readonly UserOption _minimizeToTray; @@ -374,6 +376,21 @@ public sealed partial class MainForm : Form } }; + _throttleAtaUpdate = new UserOption("throttleAtaUpdateMenuItem", false, throttleAtaUpdateMenuItem, _settings); + _throttleAtaUpdate.Changed += (sender, e) => + { + switch (_throttleAtaUpdate.Value) + { + case true: + AtaStorage.ThrottleInterval = TimeSpan.FromSeconds(30); + break; + + case false: + AtaStorage.ThrottleInterval = TimeSpan.Zero; + break; + } + }; + _sensorValuesTimeWindow = new UserRadioGroup("sensorValuesTimeWindow", 10, new[] diff --git a/LibreHardwareMonitorLib/Hardware/Storage/ATAStorage.cs b/LibreHardwareMonitorLib/Hardware/Storage/ATAStorage.cs index 2d6c08f..b0ea05f 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/ATAStorage.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/ATAStorage.cs @@ -22,6 +22,9 @@ public abstract class AtaStorage : AbstractStorage private IDictionary _sensors; + private static TimeSpan _throttleInterval = TimeSpan.Zero; + private DateTime _lastUpdate = DateTime.MinValue; + /// /// Gets the SMART data. /// @@ -187,10 +190,28 @@ public abstract class AtaStorage : AbstractStorage base.CreateSensors(); } + public static TimeSpan ThrottleInterval + { + get + { + return _throttleInterval; + } + set + { + _throttleInterval = value; + } + } + protected virtual void UpdateAdditionalSensors(Kernel32.SMART_ATTRIBUTE[] values) { } protected override void UpdateSensors() { + if (DateTime.UtcNow - _lastUpdate < ThrottleInterval) + { + return; + } + _lastUpdate = DateTime.UtcNow; + if (Smart.IsValid) { Kernel32.SMART_ATTRIBUTE[] smartAttributes = Smart.ReadSmartData(); @@ -289,4 +310,4 @@ public abstract class AtaStorage : AbstractStorage Smart.Close(); base.Close(); } -} \ No newline at end of file +}