GuillaumeGomez / sysinfo

Cross-platform library to fetch system information
MIT License
2.11k stars 315 forks source link

Windows CPU frequency does not refresh #1390

Open Huntragon opened 2 hours ago

Huntragon commented 2 hours ago

Describe the bug When retrieving the frequency in windows, it only retrieves it once and then never again refreshes it, even if the refresh flag is used. Looking through the code, there is a boolean that is used to retrieve the frequency just once (not sure the reason for this):

pub fn get_frequencies(&mut self) {
    if self.got_cpu_frequency {
        return;
    }
    let frequencies = get_frequencies(self.cpus.len());

    for (cpu, frequency) in self.cpus.iter_mut().zip(frequencies) {
        cpu.inner.set_frequency(frequency);
    }
    self.got_cpu_frequency = true;
}

I can do a PR and fix this if it's a bug.

To Reproduce

fn main() {
    let mut sys = sysinfo::System::new_all();
    loop {
        sys.refresh_cpu_frequency();
        dbg!(sys
            .cpus()
            .iter()
            .map(|el| el.frequency())
            .collect::<Vec<_>>());
        std::thread::sleep(std::time::Duration::from_secs(1));
    }
}
GuillaumeGomez commented 2 hours ago

It definitely sounds like a bug so a PR is very welcome.