You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I call System::refresh_processes_specifics(ProcessesToUpdate::Some(&[pid], ProcessRefreshKind::new().with_cpu().with_memory()) the cpu usage of provided process is not updated. Calling Process::cpu_usage() always returns the same value.
Expected behavious
CPU usage is updated and can be read from Process struct.
Actuall result
Only memory gets updated, CPU value always stays the same.
What is interesting, when I replaced ProcessesToUpdate::Some(...) with ProcessesToUpdate::All, all of a sudden it is updating correctly.
Code to reproduce issue
use std::{thread, time::Duration};use sysinfo::{get_current_pid,ProcessRefreshKind,System};fnmain(){letmut system = System::new_all();loop{
thread::sleep(Duration::from_secs(1));let pid = get_current_pid().unwrap();
system.refresh_processes_specifics(
sysinfo::ProcessesToUpdate::Some(&[pid]),ProcessRefreshKind::everything());let process = system.process(pid).unwrap();println!("cpu={}, mem={}", process.cpu_usage(), process.memory());}}
top -p <pid> returns CPU usage from 0.0 to 0.3, to the value should fluctuate a bit, but it always remains zero.
The text was updated successfully, but these errors were encountered:
I even added some shitty fibbonaci function to make sure that CPU is heavily loaded - even when top returns 90% CPU utilization, I still get 0 printed to the console :(
use std::{thread, time::Duration};use sysinfo::{get_current_pid,ProcessRefreshKind,System};fnfib(n:u64) -> u64{if n == 0 || n == 1{return1;}returnfib(n - 1) + fib(n - 2);}fnmain(){
thread::spawn(|| {let calculation = fib(100);println!("{calculation}");});letmut system = System::new_all();loop{
thread::sleep(Duration::from_secs(1));let pid = get_current_pid().unwrap();
system.refresh_processes_specifics(
sysinfo::ProcessesToUpdate::Some(&[pid]),ProcessRefreshKind::everything());let process = system.process(pid).unwrap();println!("cpu={}, mem={}", process.cpu_usage(), process.memory());}}
I'll try to take a look in the next days. Could be interesting if you checked what path the code is entering into on your side as I don't have your setup.
My setup
OS: WSL, Ubuntu 24.04 LTS
Architecture: x86_64
Rust: 1.81.0
Sysinfo: 0.31.4
Issue
When I call
System::refresh_processes_specifics(ProcessesToUpdate::Some(&[pid], ProcessRefreshKind::new().with_cpu().with_memory())
the cpu usage of provided process is not updated. CallingProcess::cpu_usage()
always returns the same value.Expected behavious
CPU usage is updated and can be read from
Process
struct.Actuall result
Only memory gets updated, CPU value always stays the same.
What is interesting, when I replaced
ProcessesToUpdate::Some(...)
withProcessesToUpdate::All
, all of a sudden it is updating correctly.Code to reproduce issue
top -p <pid>
returns CPU usage from 0.0 to 0.3, to the value should fluctuate a bit, but it always remains zero.The text was updated successfully, but these errors were encountered: