I tried to get current frequency of processor with psutil function psutil.cpu_freq(percpu=False). But as is written in docs "On Linux current frequency reports the real-time value, on all other platforms it represents the nominal “fixed” value". Is there a way to get current frequency in Windows? Thank you!
2 Answers
Searching for "python windows get actual frequency" yields a Stack Overflow question : Unable to get current CPU frequency in Powershell or Python. It says :
To find the Current Processor Frequency, you have to use the
% Processor Performance
performance counter
So searching for "python windows get performance counter" yields this PyPI library : winstats. It lets you do :
usage = winstats.get_perf_data(r'\Processor(_Total)\% Processor Time',
fmts='double', delay=100)
print(' CPU Usage: %.02f %%' % usage)
The first parameters to get_perf_data
is named counters
and as the doc says must be Localized Windows PerfMon counter name, or list of.
. Because it MUST be localized names, and I don't have an english Windows at hand, I can't reproduce it, but it would work.
If you want your code to work on any language, there are plenty of Stack Overflow questions about that, here is one looking promising : https://stackoverflow.com/a/16364388/11384184

- 4,078
- 2
- 8
- 22
@Lenormju is right, though I found that the fmt
arg requires an s
. Could be a recent change to the docs, I'm not sure.
This works for me
usage = winstats.get_perf_data(r'\Processor(_Total)\% Processor Time',
fmts='double', delay=100)
print(' CPU Usage: %.02f %%' % usage)

- 131
- 2
- 4
-
indeed, I just checked and you are right. I updated my answer too. – Lenormju Sep 16 '21 at 06:55