mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
daemon: improve polling interval adjustment
Casting float ->→ u64 risks silent truncation & sub-second intervals. We now *round* the computed interval, and ensure a minimum value of 1 to avoid zero or overly-small polling intervals.
This commit is contained in:
parent
4fcfeb073d
commit
6335f139f9
1 changed files with 3 additions and 2 deletions
|
@ -71,7 +71,7 @@ fn compute_new(params: &IntervalParams) -> u64 {
|
||||||
// Adjust for CPU/temperature volatility
|
// Adjust for CPU/temperature volatility
|
||||||
// If either CPU usage or temperature is changing rapidly, decrease interval
|
// If either CPU usage or temperature is changing rapidly, decrease interval
|
||||||
if params.cpu_volatility > 10.0 || params.temp_volatility > 2.0 {
|
if params.cpu_volatility > 10.0 || params.temp_volatility > 2.0 {
|
||||||
adjusted_interval = (adjusted_interval as f32 * 0.5) as u64;
|
adjusted_interval = ((adjusted_interval as f32 * 0.5).round()).max(1.0) as u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure interval stays within configured bounds
|
// Ensure interval stays within configured bounds
|
||||||
|
@ -193,7 +193,8 @@ impl SystemHistory {
|
||||||
let elapsed_hours = last_timestamp.elapsed().as_secs_f32() / 3600.0;
|
let elapsed_hours = last_timestamp.elapsed().as_secs_f32() / 3600.0;
|
||||||
// Only calculate discharge rate if at least 30 seconds have passed
|
// Only calculate discharge rate if at least 30 seconds have passed
|
||||||
// and we're not on AC power
|
// and we're not on AC power
|
||||||
if elapsed_hours > 0.0083 && !battery.ac_connected { // 0.0083 hours = 30 seconds
|
if elapsed_hours > 0.0083 && !battery.ac_connected {
|
||||||
|
// 0.0083 hours = 30 seconds
|
||||||
// Calculate discharge rate in percent per hour
|
// Calculate discharge rate in percent per hour
|
||||||
let percent_change = last_percentage - current_percent;
|
let percent_change = last_percentage - current_percent;
|
||||||
if percent_change > 0.0 {
|
if percent_change > 0.0 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue