mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
daemon: refactor SystemHistory
init; derive Default
for SystemState
This commit is contained in:
parent
4aea53e060
commit
59602b0e3e
1 changed files with 11 additions and 7 deletions
|
@ -131,6 +131,7 @@ fn compute_new(params: &IntervalParams) -> u64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tracks historical system data for "advanced" adaptive polling
|
/// Tracks historical system data for "advanced" adaptive polling
|
||||||
|
#[derive(Debug)]
|
||||||
struct SystemHistory {
|
struct SystemHistory {
|
||||||
/// Last several CPU usage measurements
|
/// Last several CPU usage measurements
|
||||||
cpu_usage_history: VecDeque<f32>,
|
cpu_usage_history: VecDeque<f32>,
|
||||||
|
@ -152,21 +153,23 @@ struct SystemHistory {
|
||||||
current_state: SystemState,
|
current_state: SystemState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemHistory {
|
impl Default for SystemHistory {
|
||||||
fn new() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
cpu_usage_history: VecDeque::with_capacity(5),
|
cpu_usage_history: VecDeque::new(),
|
||||||
temperature_history: VecDeque::with_capacity(5),
|
temperature_history: VecDeque::new(),
|
||||||
last_user_activity: Instant::now(),
|
last_user_activity: Instant::now(),
|
||||||
last_battery_percentage: None,
|
last_battery_percentage: None,
|
||||||
last_battery_timestamp: None,
|
last_battery_timestamp: None,
|
||||||
battery_discharge_rate: None,
|
battery_discharge_rate: None,
|
||||||
state_durations: std::collections::HashMap::new(),
|
state_durations: std::collections::HashMap::new(),
|
||||||
last_state_change: Instant::now(),
|
last_state_change: Instant::now(),
|
||||||
current_state: SystemState::Unknown,
|
current_state: SystemState::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SystemHistory {
|
||||||
/// Update system history with new report data
|
/// Update system history with new report data
|
||||||
fn update(&mut self, report: &SystemReport) {
|
fn update(&mut self, report: &SystemReport) {
|
||||||
// Update CPU usage history
|
// Update CPU usage history
|
||||||
|
@ -422,7 +425,7 @@ pub fn run_daemon(mut config: AppConfig, verbose: bool) -> Result<(), Box<dyn st
|
||||||
|
|
||||||
// Variables for adaptive polling
|
// Variables for adaptive polling
|
||||||
let mut current_poll_interval = config.daemon.poll_interval_sec;
|
let mut current_poll_interval = config.daemon.poll_interval_sec;
|
||||||
let mut system_history = SystemHistory::new();
|
let mut system_history = SystemHistory::default();
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while running.load(Ordering::SeqCst) {
|
while running.load(Ordering::SeqCst) {
|
||||||
|
@ -574,8 +577,9 @@ fn write_stats_file(path: &str, report: &SystemReport) -> Result<(), std::io::Er
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Simplified system state used for determining when to adjust polling interval
|
/// Simplified system state used for determining when to adjust polling interval
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
#[derive(Debug, PartialEq, Eq, Clone, Hash, Default)]
|
||||||
enum SystemState {
|
enum SystemState {
|
||||||
|
#[default]
|
||||||
Unknown,
|
Unknown,
|
||||||
OnAC,
|
OnAC,
|
||||||
OnBattery,
|
OnBattery,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue