Skip to content

Commit

Permalink
#557 (NetBSD): add swapin/swapout to swap mem stats
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jan 8, 2016
1 parent b8cb12a commit 116fc6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
28 changes: 21 additions & 7 deletions psutil/arch/bsd/netbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,14 @@ psutil_get_cmdline(pid_t pid) {

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};
long pagesize = getpagesize();
size = sizeof(uv);

if (sysctl(mib, 2, &uv, &size, NULL, 0) < 0) {
warn("failed to get vm.uvmexp");
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}


Expand Down

0 comments on commit 116fc6a

Please sign in to comment.