Skip to content

Commit

Permalink
#792 / cpu_stats: netbsd impl
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jan 24, 2016
1 parent fa00dfb commit a991494
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
38 changes: 19 additions & 19 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
10 changes: 9 additions & 1 deletion psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
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'])
Expand Down Expand Up @@ -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():
Expand Down
25 changes: 25 additions & 0 deletions psutil/arch/bsd/netbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,28 @@ psutil_disk_io_counters(PyObject *self, PyObject *args) {
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
);
}
1 change: 1 addition & 0 deletions psutil/arch/bsd/netbsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit a991494

Please sign in to comment.