Created
October 25, 2022 16:33
-
-
Save kennykerr/aa630879280744062a1e953b94e44013 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use windows::{core::*, Win32::System::Performance::*}; | |
fn main() { | |
unsafe { | |
let mut query = 0; | |
PdhOpenQueryW(None, 0, &mut query); | |
let mut counter = 0; | |
PdhAddCounterW( | |
query, | |
w!("\\Processor(0)\\% Processor Time"), | |
0, | |
&mut counter, | |
); | |
loop { | |
std::thread::sleep(std::time::Duration::new(1, 0)); | |
PdhCollectQueryData(query); | |
let mut value = Default::default(); | |
if 0 == PdhGetFormattedCounterValue(counter, PDH_FMT_DOUBLE, None, &mut value) { | |
println!("{:.2}", value.Anonymous.doubleValue); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment