0

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!

mekki10
  • 33
  • 1
  • 8

2 Answers2

1

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

Lenormju
  • 4,078
  • 2
  • 8
  • 22
0

@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)
Kevin Grimm
  • 131
  • 2
  • 4