summaryrefslogtreecommitdiff
path: root/psutil/_psbsd.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2022-01-16 20:06:14 +0100
committerGitHub <noreply@github.com>2022-01-16 20:06:14 +0100
commit98b49486f81f085bceda60b01b0a8f69a7008290 (patch)
tree23aead2f5fa0e6ae789f7f167100d493f045031e /psutil/_psbsd.py
parent01f5f1ecb1b3470c1df2a120f0f6dca7f58088fb (diff)
downloadpsutil-98b49486f81f085bceda60b01b0a8f69a7008290.tar.gz
OpenBSD: add support for CPU frequency (#2057)
Diffstat (limited to 'psutil/_psbsd.py')
-rw-r--r--psutil/_psbsd.py54
1 files changed, 30 insertions, 24 deletions
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 52885065..c4200cce 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -310,6 +310,36 @@ def cpu_stats():
return _common.scpustats(ctxsw, intrs, soft_intrs, syscalls)
+if FREEBSD:
+ def cpu_freq():
+ """Return frequency metrics for CPUs. As of Dec 2018 only
+ CPU 0 appears to be supported by FreeBSD and all other cores
+ match the frequency of CPU 0.
+ """
+ ret = []
+ num_cpus = cpu_count_logical()
+ for cpu in range(num_cpus):
+ try:
+ current, available_freq = cext.cpu_freq(cpu)
+ except NotImplementedError:
+ continue
+ if available_freq:
+ try:
+ min_freq = int(available_freq.split(" ")[-1].split("/")[0])
+ except(IndexError, ValueError):
+ min_freq = None
+ try:
+ max_freq = int(available_freq.split(" ")[0].split("/")[0])
+ except(IndexError, ValueError):
+ max_freq = None
+ ret.append(_common.scpufreq(current, min_freq, max_freq))
+ return ret
+elif OPENBSD:
+ def cpu_freq():
+ curr = float(cext.cpu_freq())
+ return [_common.scpufreq(curr, 0.0, 0.0)]
+
+
# =====================================================================
# --- disks
# =====================================================================
@@ -439,30 +469,6 @@ if FREEBSD:
return ret
- def cpu_freq():
- """Return frequency metrics for CPUs. As of Dec 2018 only
- CPU 0 appears to be supported by FreeBSD and all other cores
- match the frequency of CPU 0.
- """
- ret = []
- num_cpus = cpu_count_logical()
- for cpu in range(num_cpus):
- try:
- current, available_freq = cext.cpu_frequency(cpu)
- except NotImplementedError:
- continue
- if available_freq:
- try:
- min_freq = int(available_freq.split(" ")[-1].split("/")[0])
- except(IndexError, ValueError):
- min_freq = None
- try:
- max_freq = int(available_freq.split(" ")[0].split("/")[0])
- except(IndexError, ValueError):
- max_freq = None
- ret.append(_common.scpufreq(current, min_freq, max_freq))
- return ret
-
# =====================================================================
# --- other system functions