Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Why are the indicators collected by psutil too large? #2384

Open
RLYRLY opened this issue Mar 20, 2024 · 5 comments
Open

[Windows] Why are the indicators collected by psutil too large? #2384

RLYRLY opened this issue Mar 20, 2024 · 5 comments

Comments

@RLYRLY
Copy link

RLYRLY commented Mar 20, 2024

Summary

When collecting the CPU utilization of the same process within the same time range, it is found that the value collected by psutil will be larger, and the task manager that comes with Windows will be much less.

@RLYRLY RLYRLY added the bug label Mar 20, 2024
@RLYRLY
Copy link
Author

RLYRLY commented Mar 21, 2024

After reading the latest psutil source code, the CPU utilization uses the GetSystemTimes API, but the calculation of the CPU utilization in the task manager after win10 has changed. The GetSystemTimes API has been a long time ago, and now it is replaced by a "performance counter", so there are inconsistencies.
The performance counter module under WMI obtains the process CPU utilization, which should be the same as what is displayed in the task manager.
https://learn.microsoft.com/en-us/windows/win32/perfctrs/performance-counters-portal
https://learn.microsoft.com/en-us/windows/win32/wmisdk/monitoring-performance-data

@RLYRLY
Copy link
Author

RLYRLY commented Mar 21, 2024

After doing a benchmark test, the CPU utilization output by psutil was 55%, and the result using a PowerShell script combined with Windows Performance Counters was 6%. The difference is nearly 10 times.

@RLYRLY
Copy link
Author

RLYRLY commented Apr 8, 2024

@giampaolo Hello, can you help me take a look?

@giampaolo
Copy link
Owner

Do you have any idea in what Windows version GetSystemTimes() was "obsoleted" by performance counters? Or put it in another way, any idea when Windows task manager started using PC? I'm fine with using PC on newer Windows versions and GetSystemTimes() for older ones. Feel free to make a PR if you know how to do this.

@RLYRLY
Copy link
Author

RLYRLY commented Apr 22, 2024

First of all, thank you for your answer. After reading the psutil documentation, I found that there is no problem in calculating the CPU utilization of a process in Windows. It was my misunderstanding.
Thanks again for your answer.
ps: I am currently testing on macOS and found that there is a problem with the calculation of CPU utilization, and I did not find a relevant explanation in the documentation. For details, see: #2411
@giampaolo

@giampaolo giampaolo changed the title [Windows]Why are the indicators collected by psuntil too large? [Windows] Why are the indicators collected by psutil too large? Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants