summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2018-12-01 19:28:02 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2018-12-01 19:28:02 +0100
commitfd0b6d76a6c3319119f9ae932a965ac06c5855c4 (patch)
tree75c15035b5bf0ec48bbf47826e134c233380fefd
parentb560cad6ebcef0d0708cb2322a6c8020a1a6dd2f (diff)
downloadpsutil-fd0b6d76a6c3319119f9ae932a965ac06c5855c4.tar.gz
give CREDITS to @amanusk for #1369 / #1352 and update doc
-rw-r--r--CREDITS2
-rw-r--r--HISTORY.rst7
-rw-r--r--docs/index.rst3
-rw-r--r--psutil/__init__.py2
-rw-r--r--psutil/_psbsd.py12
-rw-r--r--psutil/arch/freebsd/specific.c10
-rwxr-xr-xpsutil/tests/test_bsd.py5
7 files changed, 25 insertions, 16 deletions
diff --git a/CREDITS b/CREDITS
index ee06df0d..30d9006f 100644
--- a/CREDITS
+++ b/CREDITS
@@ -546,7 +546,7 @@ I: 1278
N: Alex Manuskin
W: https://github.com/amanusk
-I: 1284, 1345, 1350
+I: 1284, 1345, 1350, 1352
N: Sylvain Duchesne
W: https://github.com/sylvainduchesne
diff --git a/HISTORY.rst b/HISTORY.rst
index 56d33296..7cfe0f19 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,5 +1,12 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*
+5.5.1
+=====
+
+**Enhancements**
+
+- 1352_: [FreeBSD] added support for CPU frequency. (patch by Alex Manuskin)
+
5.5.0
=====
diff --git a/docs/index.rst b/docs/index.rst
index d54129c2..85506a28 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -235,10 +235,11 @@ CPU
scpufreq(current=1703.609, min=800.0, max=3500.0),
scpufreq(current=1754.289, min=800.0, max=3500.0)]
- Availability: Linux, macOS, Windows
+ Availability: Linux, macOS, Windows, FreeBSD
.. versionadded:: 5.1.0
+ .. versionchanged:: 5.5.1 added FreeBSD support.
Memory
------
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 5a5720d7..3548cdcc 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -220,7 +220,7 @@ __all__ = [
]
__all__.extend(_psplatform.__extra__all__)
__author__ = "Giampaolo Rodola'"
-__version__ = "5.5.0"
+__version__ = "5.5.1"
version_info = tuple([int(num) for num in __version__.split('.')])
AF_LINK = _psplatform.AF_LINK
POWER_TIME_UNLIMITED = _common.POWER_TIME_UNLIMITED
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index d3ce7b5c..1dc72312 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -456,9 +456,9 @@ if FREEBSD:
return ret
def cpu_freq():
- """
- Return frequency metrics for CPUs. Currently, only CPU 0 is supported
- by FreeBSD, all other cores match the frequency of CPU 0.
+ """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()
@@ -467,17 +467,15 @@ if FREEBSD:
current, available_freq = cext.cpu_frequency(cpu)
except NotImplementedError:
continue
- min_freq = None
- max_freq = None
if available_freq:
try:
min_freq = int(available_freq.split(" ")[-1].split("/")[0])
except(IndexError, ValueError):
- pass
+ min_freq = None
try:
max_freq = int(available_freq.split(" ")[0].split("/")[0])
except(IndexError, ValueError):
- pass
+ max_freq = None
ret.append(_common.scpufreq(current, min_freq, max_freq))
return ret
diff --git a/psutil/arch/freebsd/specific.c b/psutil/arch/freebsd/specific.c
index 70dc7f2c..93bf51ff 100644
--- a/psutil/arch/freebsd/specific.c
+++ b/psutil/arch/freebsd/specific.c
@@ -1049,7 +1049,9 @@ error:
/*
- * Return frequency information of a given CPU
+ * Return frequency information of a given CPU.
+ * As of Dec 2018 only CPU 0 appears to be supported and all other
+ * cores match the frequency of CPU 0.
*/
PyObject *
psutil_cpu_freq(PyObject *self, PyObject *args) {
@@ -1061,12 +1063,14 @@ psutil_cpu_freq(PyObject *self, PyObject *args) {
if (! PyArg_ParseTuple(args, "i", &core))
return NULL;
+ // https://www.unix.com/man-page/FreeBSD/4/cpufreq/
sprintf(sensor, "dev.cpu.%d.freq", core);
if (sysctlbyname(sensor, &current, &size, NULL, 0))
goto error;
size = sizeof(available_freq_levels);
- // In case of failure, an empty string is returned
+ // https://www.unix.com/man-page/FreeBSD/4/cpufreq/
+ // In case of failure, an empty string is returned.
sprintf(sensor, "dev.cpu.%d.freq_levels", core);
sysctlbyname(sensor, &available_freq_levels, &size, NULL, 0);
@@ -1074,7 +1078,7 @@ psutil_cpu_freq(PyObject *self, PyObject *args) {
error:
if (errno == ENOENT)
- PyErr_SetString(PyExc_NotImplementedError, "Unable to read frequency");
+ PyErr_SetString(PyExc_NotImplementedError, "unable to read frequency");
else
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py
index 87feb147..34b66ca6 100755
--- a/psutil/tests/test_bsd.py
+++ b/psutil/tests/test_bsd.py
@@ -250,10 +250,9 @@ class FreeBSDSpecificTestCase(unittest.TestCase):
if len(tested) != 2:
raise RuntimeError("couldn't find lines match in procstat out")
- # --- cpu_freq(); tests against sysctl
def test_cpu_frequency_against_sysctl(self):
# Currently only cpu 0 is frequency is supported in FreeBSD
- # All other cores use the same frequency
+ # All other cores use the same frequency.
sensor = "dev.cpu.0.freq"
sysctl_result = int(sysctl(sensor))
self.assertEqual(psutil.cpu_freq().current, sysctl_result)
@@ -262,7 +261,7 @@ class FreeBSDSpecificTestCase(unittest.TestCase):
sysctl_result = sysctl(sensor)
# sysctl returns a string of the format:
# <freq_level_1>/<voltage_level_1> <freq_level_2>/<voltage_level_2>...
- # Ordered highest available to lowest available
+ # Ordered highest available to lowest available.
max_freq = int(sysctl_result.split()[0].split("/")[0])
min_freq = int(sysctl_result.split()[-1].split("/")[0])
self.assertEqual(psutil.cpu_freq().max, max_freq)