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

CPU frequency #941

Closed
giampaolo opened this issue Nov 26, 2016 · 1 comment
Closed

CPU frequency #941

giampaolo opened this issue Nov 26, 2016 · 1 comment

Comments

@giampaolo
Copy link
Owner

giampaolo commented Nov 26, 2016

It's unlikely this can be done on all platforms and all the times as this kind of info is typically not standardized and varies depending on the hardware. Anyway, it may be nice to have a psutil.cpu_freq() function returning a list of named tuples for each CPU including current and nominal (max) frequency.

API

>>> psutil.cpu_freq()
[scpufreq(curr=899.945, min=800.0, max=3500.0),
 scpufreq(curr=900.046, min=800.0, max=3500.0),
 scpufreq(curr=900.046, min=800.0, max=3500.0),
 scpufreq(curr=899.945, min=800.0, max=3500.0),
 scpufreq(curr=899.742, min=800.0, max=3500.0),
 scpufreq(curr=900.046, min=800.0, max=3500.0),
 scpufreq(curr=899.945, min=800.0, max=3500.0),
 scpufreq(curr=899.945, min=800.0, max=3500.0)]

The returned list should be consistent with psutil.cpu_count() and psutil.cpu_percent(percpu=True) both in length and indexing.

If added, the API should be marked as provisional, stating it can change or be removed entirely in case it shows to be unreliable.

Linux

$ cat /proc/cpuinfo  | grep MHz
cpu MHz		: 899.640
cpu MHz		: 949.507
cpu MHz		: 900.046
cpu MHz		: 899.640
cpu MHz		: 933.867
cpu MHz		: 896.695
cpu MHz		: 900.046
cpu MHz		: 899.945

min and max freqs are in /sys/devices/system/cpu/cpu (see doc)

OSX

Note: does not provide per-cpu info.

$ sysctl -a | grep freq
hw.busfrequency: 100000000
hw.busfrequency_min: 100000000
hw.busfrequency_max: 100000000
hw.cpufrequency: 2590000000
hw.cpufrequency_min: 2590000000
hw.cpufrequency_max: 2590000000
hw.tbfrequency: 1000000000
machdep.tsc.frequency: 2591998000

BSD

TODO

Windows

Looks like it's possible to get only nominal frequency:
http://stackoverflow.com/a/7544085
http://stackoverflow.com/questions/8351944/finding-out-the-cpu-clock-frequency-per-core-per-processor

SunOS

http://www.oracle.com/technetwork/articles/servers-storage-admin/script-clockrate-1980818.html

Other links

https://www.google.cz/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=python%20cpu%20frequency
https://github.com/workhorsy/py-cpuinfo

@giampaolo
Copy link
Owner Author

Merged in #952.

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

1 participant