mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
daemon: optimize CPU usage averaging in SystemHistory
updates
This commit is contained in:
parent
70a59cec82
commit
ff2f305d9e
1 changed files with 11 additions and 13 deletions
|
@ -163,20 +163,18 @@ impl SystemHistory {
|
||||||
fn update(&mut self, report: &SystemReport) {
|
fn update(&mut self, report: &SystemReport) {
|
||||||
// Update CPU usage history
|
// Update CPU usage history
|
||||||
if !report.cpu_cores.is_empty() {
|
if !report.cpu_cores.is_empty() {
|
||||||
// Get average CPU usage across all cores
|
let mut total_usage: f32 = 0.0;
|
||||||
let total: f32 = report
|
let mut core_count: usize = 0;
|
||||||
.cpu_cores
|
|
||||||
.iter()
|
|
||||||
.filter_map(|core| core.usage_percent)
|
|
||||||
.sum();
|
|
||||||
let count = report
|
|
||||||
.cpu_cores
|
|
||||||
.iter()
|
|
||||||
.filter(|c| c.usage_percent.is_some())
|
|
||||||
.count();
|
|
||||||
|
|
||||||
if count > 0 {
|
for core in &report.cpu_cores {
|
||||||
let avg_usage = total / count as f32;
|
if let Some(usage) = core.usage_percent {
|
||||||
|
total_usage += usage;
|
||||||
|
core_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if core_count > 0 {
|
||||||
|
let avg_usage = total_usage / core_count as f32;
|
||||||
|
|
||||||
// Keep only the last 5 measurements
|
// Keep only the last 5 measurements
|
||||||
if self.cpu_usage_history.len() >= 5 {
|
if self.cpu_usage_history.len() >= 5 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue