diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2018-03-29 20:27:01 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2018-03-29 20:27:01 +0200 |
commit | 904252e99a9d3217eda01159ab83e9384db54590 (patch) | |
tree | 75553167529bfc115ad3c6613c1dc9edac9a724d | |
parent | a4c07e9da0f7a3a92b27c856eec09954ccc824ca (diff) | |
download | psutil-904252e99a9d3217eda01159ab83e9384db54590.tar.gz |
#1255 adjust style + give CREDITS to @href
-rw-r--r-- | CREDITS | 4 | ||||
-rw-r--r-- | HISTORY.rst | 2 | ||||
-rw-r--r-- | psutil/arch/freebsd/specific.c | 15 | ||||
-rwxr-xr-x | psutil/tests/test_bsd.py | 30 |
4 files changed, 28 insertions, 23 deletions
@@ -531,3 +531,7 @@ I: 1193, 1194 N: Maxime Mouial W: https://github.com/hush-hush I: 1239 + +N: Denis Krienbühl +W: https://github.com/href +I: 1260 diff --git a/HISTORY.rst b/HISTORY.rst index d0bb4b0a..65cad58e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -35,6 +35,8 @@ XXXX-XX-XX - 1240_: [Windows] cpu_times() float loses accuracy in a long running system. (patch by stswandering) - 1245_: [Linux] sensors_temperatures() may fail with IOError "no such file". +- 1255_: [FreeBSD] swap_memory() stats were erroneously represented in KB. + (patch by Denis Krienbühl) 5.4.3 ===== diff --git a/psutil/arch/freebsd/specific.c b/psutil/arch/freebsd/specific.c index f6d1a67e..cf0b7df2 100644 --- a/psutil/arch/freebsd/specific.c +++ b/psutil/arch/freebsd/specific.c @@ -518,12 +518,15 @@ psutil_swap_mem(PyObject *self, PyObject *args) { int pagesize = getpagesize(); - return Py_BuildValue("(KKKII)", - (unsigned long long) kvmsw[0].ksw_total * pagesize, // total - (unsigned long long) kvmsw[0].ksw_used * pagesize, // used - (unsigned long long) kvmsw[0].ksw_total * pagesize - kvmsw[0].ksw_used * pagesize, // free - swapin + swapout, // swap in - nodein + nodeout); // swap out + return Py_BuildValue( + "(KKKII)", + (unsigned long long)kvmsw[0].ksw_total * pagesize, // total + (unsigned long long)kvmsw[0].ksw_used * pagesize, // used + (unsigned long long)kvmsw[0].ksw_total * pagesize - // free + kvmsw[0].ksw_used * pagesize, + swapin + swapout, // swap in + nodein + nodeout // swap out + ); error: return PyErr_SetFromErrno(PyExc_OSError); diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py index 63cae66a..7846c1ca 100755 --- a/psutil/tests/test_bsd.py +++ b/psutil/tests/test_bsd.py @@ -159,6 +159,19 @@ class FreeBSDSpecificTestCase(unittest.TestCase): def tearDownClass(cls): reap_children() + @staticmethod + def parse_swapinfo(): + # the last line is always the total + output = sh("swapinfo -k").splitlines()[-1] + parts = re.split(r'\s+', output) + + if not parts: + raise ValueError("Can't parse swapinfo: %s" % output) + + # the size is in 1k units, so multiply by 1024 + total, used, free = (int(p) * 1024 for p in parts[1:4]) + return total, used, free + @retry_before_failing() def test_proc_memory_maps(self): out = sh('procstat -v %s' % self.pid) @@ -345,36 +358,19 @@ class FreeBSDSpecificTestCase(unittest.TestCase): # sysctl('vm.stats.sys.v_trap'), delta=1000) # --- swap memory - @staticmethod - def parse_swapinfo(): - - # the last line is always the total - output = sh("swapinfo -k").splitlines()[-1] - parts = re.split(r'\s+', output) - - if not parts: - raise ValueError("Can't parse swapinfo: %s" % output) - - # the size is in 1k units, so multiply by 1024 - total, used, free = (int(p) * 1024 for p in parts[1:4]) - - return total, used, free def test_swapmem_free(self): total, used, free = self.parse_swapinfo() - self.assertAlmostEqual( psutil.swap_memory().free, free, delta=MEMORY_TOLERANCE) def test_swapmem_used(self): total, used, free = self.parse_swapinfo() - self.assertAlmostEqual( psutil.swap_memory().used, used, delta=MEMORY_TOLERANCE) def test_swapmem_total(self): total, used, free = self.parse_swapinfo() - self.assertAlmostEqual( psutil.swap_memory().total, total, delta=MEMORY_TOLERANCE) |