-
Hi I am unfamiliar with the Thanks in advance! use heim_process::processes;
...
async fn get_procs_cpu_usage() -> Vec<f32> {
let mut usages = Vec::new();
let mut processes = processes();
while let Some(process) = processes.next().await {
if let Ok(proc) = process {
let measurement_1 = proc.cpu_usage().await.expect("Failed to get CPU usage for process");
// CpuUsage struct represents instantaneous CPU usage and
// does not represent any reasonable value by itself
sleep(Duration::from_secs(1)).await;
let measurement_2 = proc.cpu_usage().await.expect("Failed to get CPU usage for process");
let usage = (measurement_2 - measurement_1).get::<ratio>();
usages.push(usage);
}
}
usages
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Depending on your use-case you might want to use one of the While I prefer not to spend time on writing more newcomers-friendly documentation here (it is mostly out of scope and I do not have enough free time to do that), any PRs with more examples are more then welcomed! |
Beta Was this translation helpful? Give feedback.
Depending on your use-case you might want to use one of the
TryStreamExt
trait methods, namelytry_for_each_concurrent
ortry_buffer_unordered
, for example.While I prefer not to spend time on writing more newcomers-friendly documentation here (it is mostly out of scope and I do not have enough free time to do that), any PRs with more examples are more then welcomed!