Skip to content

Commit

Permalink
Merge pull request #741 from landryb/visa
Browse files Browse the repository at this point in the history
Get system page size via sysconf()
  • Loading branch information
giampaolo committed Jan 26, 2016
2 parents caf49c3 + 6abfa22 commit 4ceb5ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,7 @@ I: 730
N: Frank Benkstein
W: https://github.com/fbenkstein
I: 732, 733

N: Visa Hankala
E: visa@openbsd.org
I: 741
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
name(), cwd(), exe(), cmdline() and open_files() methods resulting in
UnicodeDecodeError exceptions. 'surrogateescape' error handler is now
used as a workaround for replacing the corrupted data.
- #741: [OpenBSD] fix compilation on mips64.


3.4.2 - 2016-01-20
Expand Down
30 changes: 12 additions & 18 deletions psutil/_psutil_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@
#include <utmpx.h>
#include <sys/vnode.h> // for VREG
#include <sys/sched.h> // for CPUSTATES & CP_*
#include <machine/vmparam.h> // for PAGE_SHIFT
#define _KERNEL
#include <uvm/uvm_extern.h>
#undef _KERNEL
#endif


Expand Down Expand Up @@ -454,15 +450,12 @@ psutil_proc_io_counters(PyObject *self, PyObject *args) {
}


#if defined(__OpenBSD__) || defined(__NetBSD__)
#define ptoa(x) ((paddr_t)(x) << PAGE_SHIFT)
#endif

/*
* Return extended memory info for a process as a Python tuple.
*/
static PyObject *
psutil_proc_memory_info(PyObject *self, PyObject *args) {
long pagesize = sysconf(_SC_PAGESIZE);
long pid;
kinfo_proc kp;
if (! PyArg_ParseTuple(args, "l", &pid))
Expand All @@ -473,26 +466,27 @@ psutil_proc_memory_info(PyObject *self, PyObject *args) {
return Py_BuildValue(
"(lllll)",
#ifdef __FreeBSD__
(long) ptoa(kp.ki_rssize), // rss
(long) kp.ki_rssize * pagesize, // rss
(long) kp.ki_size, // vms
(long) ptoa(kp.ki_tsize), // text
(long) ptoa(kp.ki_dsize), // data
(long) ptoa(kp.ki_ssize) // stack
(long) kp.ki_tsize * pagesize, // text
(long) kp.ki_dsize * pagesize, // data
(long) kp.ki_ssize * pagesize // stack
#else
(long) ptoa(kp.p_vm_rssize), // rss
(long) kp.p_vm_rssize * pagesize, // rss
#ifdef __OpenBSD__
// VMS, this is how ps determines it on OpenBSD:
// http://anoncvs.spacehopper.org/openbsd-src/tree/bin/ps/print.c#n461
(long) ptoa(kp.p_vm_dsize + kp.p_vm_ssize + kp.p_vm_tsize), // vms
// vms
(long) (kp.p_vm_dsize + kp.p_vm_ssize + kp.p_vm_tsize) * pagesize,
#elif __NetBSD__
// VMS, this is how top determines it on NetBSD:
// ftp://ftp.iij.ad.jp/pub/NetBSD/NetBSD-release-6/src/external/bsd/
// top/dist/machine/m_netbsd.c
(long) ptoa(kp.p_vm_msize), // vms
(long) kp.p_vm_msize * pagesize, // vms
#endif
(long) ptoa(kp.p_vm_tsize), // text
(long) ptoa(kp.p_vm_dsize), // data
(long) ptoa(kp.p_vm_ssize) // stack
(long) kp.p_vm_tsize * pagesize, // text
(long) kp.p_vm_dsize * pagesize, // data
(long) kp.p_vm_ssize * pagesize // stack
#endif
);
}
Expand Down

0 comments on commit 4ceb5ec

Please sign in to comment.