1
Fork 0
mirror of https://github.com/RGBCube/superfreq synced 2025-07-27 17:07:44 +00:00

daemon: more logs

This commit is contained in:
RGBCube 2025-06-12 00:29:36 +03:00
parent 1ba5a1da6c
commit f7f738caa9
Signed by: RGBCube
SSH key fingerprint: SHA256:CzqbPcfwt+GxFYNnFVCqoN5Itn4YFrshg1TrnACpA5M
2 changed files with 36 additions and 22 deletions

View file

@ -36,6 +36,7 @@ fn idle_multiplier(idle_for: Duration) -> f64 {
(1.0 + factor).clamp(1.0, 5.0) (1.0 + factor).clamp(1.0, 5.0)
} }
#[derive(Debug)]
struct Daemon { struct Daemon {
/// Last time when there was user activity. /// Last time when there was user activity.
last_user_activity: Instant, last_user_activity: Instant,
@ -55,14 +56,19 @@ struct Daemon {
impl Daemon { impl Daemon {
fn rescan(&mut self) -> anyhow::Result<()> { fn rescan(&mut self) -> anyhow::Result<()> {
log::debug!("rescanning daemon view of system hardware...");
self.system.rescan()?; self.system.rescan()?;
while self.cpu_log.len() > 99 { let at = Instant::now();
while self.cpu_log.len() > 100 {
log::debug!("daemon CPU log was too long, popping element");
self.cpu_log.pop_front(); self.cpu_log.pop_front();
} }
self.cpu_log.push_back(CpuLog { let cpu_log = CpuLog {
at: Instant::now(), at,
usage: self usage: self
.system .system
@ -74,35 +80,40 @@ impl Daemon {
temperature: self.system.cpu_temperatures.values().sum::<f64>() temperature: self.system.cpu_temperatures.values().sum::<f64>()
/ self.system.cpu_temperatures.len() as f64, / self.system.cpu_temperatures.len() as f64,
}); };
log::debug!("appending CPU log item: {cpu_log:?}");
self.cpu_log.push_back(cpu_log);
let at = Instant::now(); while self.power_supply_log.len() > 100 {
log::debug!("daemon power supply log was too long, popping element");
self.power_supply_log.pop_front();
}
let (charge_sum, charge_nr) = let power_supply_log = PowerSupplyLog {
self.system at,
.power_supplies charge: {
.iter() let (charge_sum, charge_nr) = self.system.power_supplies.iter().fold(
.fold((0.0, 0u32), |(sum, count), power_supply| { (0.0, 0u32),
|(sum, count), power_supply| {
if let Some(charge_percent) = power_supply.charge_percent { if let Some(charge_percent) = power_supply.charge_percent {
(sum + charge_percent, count + 1) (sum + charge_percent, count + 1)
} else { } else {
(sum, count) (sum, count)
} }
}); },
);
while self.power_supply_log.len() > 99 { charge_sum / charge_nr as f64
self.power_supply_log.pop_front(); },
} };
log::debug!("appending power supply log item: {power_supply_log:?}");
self.power_supply_log.push_back(PowerSupplyLog { self.power_supply_log.push_back(power_supply_log);
at,
charge: charge_sum / charge_nr as f64,
});
Ok(()) Ok(())
} }
} }
#[derive(Debug)]
struct CpuLog { struct CpuLog {
at: Instant, at: Instant,
@ -113,6 +124,7 @@ struct CpuLog {
temperature: f64, temperature: f64,
} }
#[derive(Debug)]
struct CpuVolatility { struct CpuVolatility {
usage: f64, usage: f64,
@ -184,6 +196,7 @@ impl Daemon {
} }
} }
#[derive(Debug)]
struct PowerSupplyLog { struct PowerSupplyLog {
at: Instant, at: Instant,

View file

@ -4,6 +4,7 @@ use anyhow::{Context, bail};
use crate::{cpu, fs, power_supply}; use crate::{cpu, fs, power_supply};
#[derive(Debug)]
pub struct System { pub struct System {
pub is_ac: bool, pub is_ac: bool,