summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-01-08 15:13:49 +0000
committerGiampaolo Rodola <g.rodola@gmail.com>2016-01-08 15:13:49 +0000
commit116fc6a3436704abb71743a8dd2ef747666af6b8 (patch)
treeec86fb5de2de3a706333cf17ed8e250abef17bd0
parentb8cb12aa2526e7490958439b453dc3a5c8b33948 (diff)
downloadpsutil-116fc6a3436704abb71743a8dd2ef747666af6b8.tar.gz
#557 (NetBSD): add swapin/swapout to swap mem stats
-rw-r--r--docs/index.rst2
-rw-r--r--psutil/arch/bsd/netbsd.c28
2 files changed, 22 insertions, 8 deletions
diff --git a/docs/index.rst b/docs/index.rst
index d71b1193..68e3e5d0 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -207,7 +207,7 @@ Memory
* **sout**: the number of bytes the system has swapped out from disk
(cumulative)
- **sin** and **sout** on Windows, OpenBSD and NetBSD are always set to ``0``.
+ **sin** and **sout** on Windows and OpenBSD are always set to ``0``.
See `examples/meminfo.py <https://github.com/giampaolo/psutil/blob/master/examples/meminfo.py>`__
script providing an example on how to convert bytes in a human readable form.
diff --git a/psutil/arch/bsd/netbsd.c b/psutil/arch/bsd/netbsd.c
index 542c6998..a8c0364c 100644
--- a/psutil/arch/bsd/netbsd.c
+++ b/psutil/arch/bsd/netbsd.c
@@ -424,7 +424,7 @@ error:
PyObject *
psutil_virtual_mem(PyObject *self, PyObject *args) {
- unsigned int total, active, inactive, wired, cached, free;
+ unsigned int total;
size_t size = sizeof(total);
struct uvmexp_sysctl uv;
int mib[] = {CTL_VM, VM_UVMEXP2};
@@ -432,7 +432,6 @@ psutil_virtual_mem(PyObject *self, PyObject *args) {
size = sizeof(uv);
if (sysctl(mib, 2, &uv, &size, NULL, 0) < 0) {
- warn("failed to get vm.uvmexp");
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
@@ -472,9 +471,8 @@ psutil_swap_mem(PyObject *self, PyObject *args) {
}
if (swapctl(SWAP_STATS, swdev, nswap) == -1) {
- free(swdev);
PyErr_SetFromErrno(PyExc_OSError);
- return NULL;
+ goto error;
}
// Total things up.
@@ -486,12 +484,28 @@ psutil_swap_mem(PyObject *self, PyObject *args) {
}
}
free(swdev);
- return Py_BuildValue("(LLLII)",
+
+ // Get swap in/out
+ unsigned int total;
+ size_t size = sizeof(total);
+ struct uvmexp_sysctl uv;
+ int mib[] = {CTL_VM, VM_UVMEXP2};
+ long pagesize = getpagesize();
+ size = sizeof(uv);
+ if (sysctl(mib, 2, &uv, &size, NULL, 0) < 0) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ goto error;
+ }
+
+ return Py_BuildValue("(LLLll)",
swap_total * DEV_BSIZE,
(swap_total - swap_free) * DEV_BSIZE,
swap_free * DEV_BSIZE,
- 0, // XXX swap in
- 0); // XXX swap out
+ (long) uv.pgswapin * pagesize, // swap in
+ (long) uv.pgswapout * pagesize); // swap out
+
+error:
+ free(swdev);
}