summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-01-24 18:32:53 +0000
committerGiampaolo Rodola <g.rodola@gmail.com>2016-01-24 18:32:53 +0000
commita991494e4502e1235ebc62b5ba450287d0dedec0 (patch)
tree606d69ce6c34ab862dd297e98bb6acf4855a795d
parentfa00dfb961ef63426c7818899340866ced8d2418 (diff)
downloadpsutil-a991494e4502e1235ebc62b5ba450287d0dedec0.tar.gz
#792 / cpu_stats: netbsd impl
-rw-r--r--docs/index.rst38
-rw-r--r--psutil/_psbsd.py10
-rw-r--r--psutil/arch/bsd/netbsd.c25
-rw-r--r--psutil/arch/bsd/netbsd.h1
4 files changed, 54 insertions, 20 deletions
diff --git a/docs/index.rst b/docs/index.rst
index fc062389..b7233863 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -157,25 +157,25 @@ CPU
ctx_switches, interrupts, soft_interrupts, syscalls, traps
- +-----------------+-----------------+--------------+-----------------+-------------+--------------+--------------+
- | Linux | OSX | Windows | FreeBSD | OpenBSD | NetBSD | SunOS |
- +=================+=================+==============+=================+=============+==============+==============+
- | ctx_switches | ctx_switches | | ctx_switches | | | |
- +-----------------+-----------------+--------------+-----------------+-------------+--------------+--------------+
- | interrupts | interrupts | | interrupts | | | |
- +-----------------+-----------------+--------------+-----------------+-------------+--------------+--------------+
- | soft_interrupts | soft_interrupts | | soft_interrupts | | | |
- +-----------------+-----------------+--------------+-----------------+-------------+--------------+--------------+
- | procs_running | syscalls | | syscalls | | | |
- +-----------------+-----------------+--------------+-----------------+-------------+--------------+--------------+
- | procs_blocked | traps | | traps | | | |
- +-----------------+-----------------+--------------+-----------------+-------------+--------------+--------------+
- | | | | | | | |
- +-----------------+-----------------+--------------+-----------------+-------------+--------------+--------------+
- | | | | | | | |
- +-----------------+-----------------+--------------+-----------------+-------------+--------------+--------------+
- | | | | | | | |
- +-----------------+-----------------+--------------+-----------------+-------------+--------------+--------------+
+ +-----------------+-----------------+--------------+-----------------+-------------+-----------------+--------------+
+ | Linux | OSX | Windows | FreeBSD | OpenBSD | NetBSD | SunOS |
+ +=================+=================+==============+=================+=============+=================+==============+
+ | ctx_switches | ctx_switches | | ctx_switches | | ctx_switches | |
+ +-----------------+-----------------+--------------+-----------------+-------------+-----------------+--------------+
+ | interrupts | interrupts | | interrupts | | interrupts | |
+ +-----------------+-----------------+--------------+-----------------+-------------+-----------------+--------------+
+ | soft_interrupts | soft_interrupts | | soft_interrupts | | soft_interrupts | |
+ +-----------------+-----------------+--------------+-----------------+-------------+-----------------+--------------+
+ | procs_running | syscalls | | syscalls | | syscalls | |
+ +-----------------+-----------------+--------------+-----------------+-------------+-----------------+--------------+
+ | procs_blocked | traps | | traps | | traps | |
+ +-----------------+-----------------+--------------+-----------------+-------------+-----------------+--------------+
+ | | | | | | | |
+ +-----------------+-----------------+--------------+-----------------+-------------+-----------------+--------------+
+ | | | | | | | |
+ +-----------------+-----------------+--------------+-----------------+-------------+-----------------+--------------+
+ | | | | | | | |
+ +-----------------+-----------------+--------------+-----------------+-------------+-----------------+--------------+
Example (Linux):
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index d5c3405f..ad98b4f9 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -114,7 +114,7 @@ if FREEBSD:
else:
sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
'read_bytes', 'write_bytes'])
-if FREEBSD:
+if FREEBSD or NETBSD:
scpustats = namedtuple(
'scpustats', ['ctx_switches', 'interrupts', 'soft_interrupts',
'syscalls', 'traps'])
@@ -233,6 +233,14 @@ def cpu_stats():
cext.cpu_stats()
return scpustats(
ctx_switches, interrupts, soft_interrupts, syscalls, traps)
+ elif NETBSD:
+ # 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()
+ return scpustats(
+ ctx_switches, interrupts, soft_interrupts, syscalls, traps)
def boot_time():
diff --git a/psutil/arch/bsd/netbsd.c b/psutil/arch/bsd/netbsd.c
index 5f66449a..be9b2fdb 100644
--- a/psutil/arch/bsd/netbsd.c
+++ b/psutil/arch/bsd/netbsd.c
@@ -673,3 +673,28 @@ error:
free(stats);
return NULL;
}
+
+
+PyObject *
+psutil_cpu_stats(PyObject *self, PyObject *args) {
+ size_t size;
+ struct uvmexp_sysctl uv;
+ int uvmexp_mib[] = {CTL_VM, VM_UVMEXP2};
+
+ size = sizeof(uv);
+ if (sysctl(uvmexp_mib, 2, &uv, &size, NULL, 0) < 0) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
+
+ return Py_BuildValue(
+ "IIIIIII",
+ uv.swtch, // ctx switches
+ uv.intrs, // interrupts - XXX always 0
+ uv.softs, // soft interrupts
+ uv.syscalls, // syscalls - XXX always 0
+ uv.traps, // traps
+ uv.faults, // faults
+ uv.forks // forks
+ );
+}
diff --git a/psutil/arch/bsd/netbsd.h b/psutil/arch/bsd/netbsd.h
index b0b2caaf..2c8edae6 100644
--- a/psutil/arch/bsd/netbsd.h
+++ b/psutil/arch/bsd/netbsd.h
@@ -27,3 +27,4 @@ PyObject *psutil_per_cpu_times(PyObject *self, PyObject *args);
PyObject* psutil_disk_io_counters(PyObject* self, PyObject* args);
PyObject* psutil_proc_exe(PyObject* self, PyObject* args);
PyObject* psutil_proc_num_threads(PyObject* self, PyObject* args);
+PyObject* psutil_cpu_stats(PyObject* self, PyObject* args);