giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.31k stars 1.39k forks source link

[Win11] psutil.cpu_percent get different result with task manager #2327

Open Peng-wei-Yu opened 1 year ago

Peng-wei-Yu commented 1 year ago

Summary

Description

import psutil psutil.cpu_percent(None) 1.2 (here is manually wait 2 seconds around) psutil.cpu_percent(None) 1.3 (here is manually wait 10 seconds around) psutil.cpu_percent(None) 1.1 from task manager cpu usage around 7-9%

moyu284 commented 1 year ago

I also found the same problem

RLYRLY commented 7 months ago

Please see this:https://psutil.readthedocs.io/en/latest/#psutil.Process.cpu_percent , it may answer your question.In general, the value calculated on the Windows system needs to be divided by the number of CPU logical cores to be consistent with the value of the task manager.

kazmorebig commented 4 months ago

Actually this can be reproduced on Intel i7-12700K as well. @RLYRLY This relates to cpu_present call for a process. If you call this as psutil.cpu_percent (link) value should be close to task manager. However this does not work for Win 11. Anyhow the cpu load reported by psutil should not be lower than the value in task manager, unlike we see here.

ChiangMark commented 3 months ago

I also encountered this issue with Xeon CPU on Win 11 platform.