Skip to content

Commit

Permalink
give CREDITS to @amanusk for #1369 / #1352 and update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Dec 1, 2018
1 parent b560cad commit fd0b6d7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -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
=====

Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand Down
2 changes: 1 addition & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
]
__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
Expand Down
12 changes: 5 additions & 7 deletions psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,9 @@ def sensors_temperatures():
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()
Expand All @@ -467,17 +467,15 @@ def cpu_freq():
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

Expand Down
10 changes: 7 additions & 3 deletions psutil/arch/freebsd/specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,9 @@ psutil_sensors_cpu_temperature(PyObject *self, PyObject *args) {


/*
* 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) {
Expand All @@ -1061,20 +1063,22 @@ 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);

return Py_BuildValue("is", current, available_freq_levels);

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;
Expand Down
5 changes: 2 additions & 3 deletions psutil/tests/test_bsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,9 @@ def test_proc_cpu_times(self):
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)
Expand All @@ -262,7 +261,7 @@ def test_cpu_frequency_against_sysctl(self):
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)
Expand Down

0 comments on commit fd0b6d7

Please sign in to comment.