Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get system page size via sysconf() #741

Merged
merged 2 commits into from
Jan 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: [email protected]
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