Testing
This commit is contained in:
parent
b226217ba4
commit
53cb6510d0
@ -390,6 +390,28 @@ impl ServiceCollector {
|
||||
}
|
||||
|
||||
async fn get_cpu_frequency_mhz(&self) -> Option<f32> {
|
||||
// Prioritize /proc/cpuinfo for actual current frequencies, then calculate average
|
||||
if let Ok(content) = fs::read_to_string("/proc/cpuinfo").await {
|
||||
let mut frequencies = Vec::new();
|
||||
for line in content.lines() {
|
||||
if let Some(rest) = line.strip_prefix("cpu MHz") {
|
||||
if let Some(value) = rest.split(':').nth(1) {
|
||||
if let Ok(mhz) = value.trim().parse::<f32>() {
|
||||
if mhz > 0.0 {
|
||||
frequencies.push(mhz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !frequencies.is_empty() {
|
||||
let avg_freq = frequencies.iter().sum::<f32>() / frequencies.len() as f32;
|
||||
return Some(avg_freq);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to scaling frequency if cpuinfo is not available
|
||||
let candidates = [
|
||||
"/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq",
|
||||
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq",
|
||||
@ -405,20 +427,6 @@ impl ServiceCollector {
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(content) = fs::read_to_string("/proc/cpuinfo").await {
|
||||
for line in content.lines() {
|
||||
if let Some(rest) = line.strip_prefix("cpu MHz") {
|
||||
if let Some(value) = rest.split(':').nth(1) {
|
||||
if let Ok(mhz) = value.trim().parse::<f32>() {
|
||||
if mhz > 0.0 {
|
||||
return Some(mhz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user