Closed vthib closed 1 month ago
For this kind of operations, you likely want to use refresh_pids_specifics. Although, in this case it should still work.
Indeed, I didn't know about this API, and it fixes the issue. I'm leaving this issue open since there is still a bug afaict, but i'm no longer blocked by it, I let you decide what to do with it. Thanks!
It definitely needs to be fixed. Gonna try to take a look in the next days.
I have a piece of code that looks like this:
With this code, the cpu for process A seems to be valid, but the one for process B is way too high, it can even get higher than the max value.
Looking at the code, I see that the function
compute_cpu_usage
uses atime_interval
variable. This value seems to be right on the first call to refresh (for pid A), but not on the second call (for pid B). I suppose this value is reset after each call to "refresh_process", leading to the second call computing a CPU load with a time interval that is way too small.Here is a reproducer:
Reversing the two PIDs reverses the one that is reported with a very high CPU usage, showing the bug.
This was reproduced on 0.30.12 on macos x64.