diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-01-24 18:59:48 +0000 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-01-24 18:59:48 +0000 |
commit | fbda723ad0ad96d5f28753605adeffe63a618dcf (patch) | |
tree | afea682bac499325e50c0cb1e3480e81691c49dc | |
parent | a991494e4502e1235ebc62b5ba450287d0dedec0 (diff) | |
download | psutil-792-cpu-stats.tar.gz |
add netbsd tests792-cpu-stats
-rw-r--r-- | psutil/_psbsd.py | 12 | ||||
-rw-r--r-- | psutil/arch/bsd/netbsd.c | 2 | ||||
-rw-r--r-- | psutil/tests/test_bsd.py | 23 |
3 files changed, 35 insertions, 2 deletions
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index ad98b4f9..89bbf7c6 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -234,11 +234,21 @@ def cpu_stats(): return scpustats( ctx_switches, interrupts, soft_interrupts, syscalls, traps) elif NETBSD: + # XXX + # Note about interrupts: the C extension returns 0. interrupts + # can be determined via /proc/stat; it has the same value as + # soft_interrupts thought so the kernel is faking it (?). + # + # Note about syscalls: the C extension always sets it to 0 (?). + # # Note: the C ext is returning two metrics we are not returning: # faults and forks. - # XXX - syscalls and intrs are always 0 (?). (ctx_switches, interrupts, soft_interrupts, syscalls, traps, faults, forks) = cext.cpu_stats() + with open('/proc/stat', 'rb') as f: + for line in f: + if line.startswith(b'intr'): + interrupts = int(line.split()[1]) return scpustats( ctx_switches, interrupts, soft_interrupts, syscalls, traps) diff --git a/psutil/arch/bsd/netbsd.c b/psutil/arch/bsd/netbsd.c index be9b2fdb..11552340 100644 --- a/psutil/arch/bsd/netbsd.c +++ b/psutil/arch/bsd/netbsd.c @@ -690,7 +690,7 @@ psutil_cpu_stats(PyObject *self, PyObject *args) { return Py_BuildValue( "IIIIIII", uv.swtch, // ctx switches - uv.intrs, // interrupts - XXX always 0 + uv.intrs, // interrupts - XXX always 0, will be determined via /proc uv.softs, // soft interrupts uv.syscalls, // syscalls - XXX always 0 uv.traps, // traps diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py index 53682c61..e1cc9cf4 100644 --- a/psutil/tests/test_bsd.py +++ b/psutil/tests/test_bsd.py @@ -356,5 +356,28 @@ class NetBSDSpecificTestCase(unittest.TestCase): self.assertEqual( psutil.swap_memory().free, self.parse_meminfo("SwapFree:")) + def test_cpu_stats_interrupts(self): + with open('/proc/stat', 'rb') as f: + for line in f: + if line.startswith(b'intr'): + interrupts = int(line.split()[1]) + break + else: + raise ValueError("couldn't find line") + self.assertAlmostEqual( + psutil.cpu_stats().interrupts, interrupts, delta=1000) + + def test_cpu_stats_ctx_switches(self): + with open('/proc/stat', 'rb') as f: + for line in f: + if line.startswith(b'ctxt'): + ctx_switches = int(line.split()[1]) + break + else: + raise ValueError("couldn't find line") + self.assertAlmostEqual( + psutil.cpu_stats().ctx_switches, ctx_switches, delta=1000) + + if __name__ == '__main__': run_test_module_by_name(__file__) |