| Index: third_party/psutil/psutil/_psutil_bsd.c
|
| diff --git a/third_party/psutil/psutil/_psutil_bsd.c b/third_party/psutil/psutil/_psutil_bsd.c
|
| index 7586d9f1f54f5763aaad96dc270914186adb1310..d937cbf4c1efcc47bbca100c344f3f89497a7747 100644
|
| --- a/third_party/psutil/psutil/_psutil_bsd.c
|
| +++ b/third_party/psutil/psutil/_psutil_bsd.c
|
| @@ -1,5 +1,9 @@
|
| /*
|
| - * $Id: _psutil_bsd.c 780 2010-11-10 18:42:47Z jloden $
|
| + * $Id: _psutil_bsd.c 1142 2011-10-05 18:45:49Z g.rodola $
|
| + *
|
| + * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| *
|
| * FreeBSD platform-specific module methods for _psutil_bsd
|
| */
|
| @@ -16,127 +20,19 @@
|
| #include <sys/user.h>
|
| #include <sys/proc.h>
|
| #include <sys/vmmeter.h> /* needed for vmtotal struct */
|
| +#include <sys/mount.h>
|
| +// network-related stuff
|
| +#include <net/if.h>
|
| +#include <net/if_dl.h>
|
| +#include <net/route.h>
|
|
|
| #include "_psutil_bsd.h"
|
| +#include "_psutil_common.h"
|
| #include "arch/bsd/process_info.h"
|
|
|
| -/*
|
| - * define the psutil C module methods and initialize the module.
|
| - */
|
| -static PyMethodDef
|
| -PsutilMethods[] =
|
| -{
|
| - // --- per-process functions
|
| -
|
| - {"get_process_name", get_process_name, METH_VARARGS,
|
| - "Return process name"},
|
| - {"get_process_cmdline", get_process_cmdline, METH_VARARGS,
|
| - "Return process cmdline as a list of cmdline arguments"},
|
| - {"get_process_ppid", get_process_ppid, METH_VARARGS,
|
| - "Return process ppid as an integer"},
|
| - {"get_process_uid", get_process_uid, METH_VARARGS,
|
| - "Return process real user id as an integer"},
|
| - {"get_process_gid", get_process_gid, METH_VARARGS,
|
| - "Return process real group id as an integer"},
|
| - {"get_cpu_times", get_cpu_times, METH_VARARGS,
|
| - "Return tuple of user/kern time for the given PID"},
|
| - {"get_process_create_time", get_process_create_time, METH_VARARGS,
|
| - "Return a float indicating the process create time expressed in "
|
| - "seconds since the epoch"},
|
| - {"get_memory_info", get_memory_info, METH_VARARGS,
|
| - "Return a tuple of RSS/VMS memory information"},
|
| - {"get_process_num_threads", get_process_num_threads, METH_VARARGS,
|
| - "Return number of threads used by process"},
|
| -
|
| -
|
| - // --- system-related functions
|
| -
|
| - {"get_pid_list", get_pid_list, METH_VARARGS,
|
| - "Returns a list of PIDs currently running on the system"},
|
| - {"get_num_cpus", get_num_cpus, METH_VARARGS,
|
| - "Return number of CPUs on the system"},
|
| - {"get_total_phymem", get_total_phymem, METH_VARARGS,
|
| - "Return the total amount of physical memory, in bytes"},
|
| - {"get_avail_phymem", get_avail_phymem, METH_VARARGS,
|
| - "Return the amount of available physical memory, in bytes"},
|
| - {"get_total_virtmem", get_total_virtmem, METH_VARARGS,
|
| - "Return the total amount of virtual memory, in bytes"},
|
| - {"get_avail_virtmem", get_avail_virtmem, METH_VARARGS,
|
| - "Return the amount of available virtual memory, in bytes"},
|
| - {"get_system_cpu_times", get_system_cpu_times, METH_VARARGS,
|
| - "Return system cpu times as a tuple (user, system, nice, idle, irc)"},
|
| -
|
| - {NULL, NULL, 0, NULL}
|
| -};
|
| -
|
| -struct module_state {
|
| - PyObject *error;
|
| -};
|
| -
|
| -#if PY_MAJOR_VERSION >= 3
|
| -#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
|
| -#else
|
| -#define GETSTATE(m) (&_state)
|
| -static struct module_state _state;
|
| -#endif
|
| -
|
| -#if PY_MAJOR_VERSION >= 3
|
| -
|
| -static int
|
| -psutil_bsd_traverse(PyObject *m, visitproc visit, void *arg) {
|
| - Py_VISIT(GETSTATE(m)->error);
|
| - return 0;
|
| -}
|
|
|
| -static int
|
| -psutil_bsd_clear(PyObject *m) {
|
| - Py_CLEAR(GETSTATE(m)->error);
|
| - return 0;
|
| -}
|
| -
|
| -static struct PyModuleDef
|
| -moduledef = {
|
| - PyModuleDef_HEAD_INIT,
|
| - "psutil_bsd",
|
| - NULL,
|
| - sizeof(struct module_state),
|
| - PsutilMethods,
|
| - NULL,
|
| - psutil_bsd_traverse,
|
| - psutil_bsd_clear,
|
| - NULL
|
| -};
|
| -
|
| -#define INITERROR return NULL
|
| -
|
| -PyObject *
|
| -PyInit__psutil_bsd(void)
|
| -
|
| -#else
|
| -#define INITERROR return
|
| -
|
| -void init_psutil_bsd(void)
|
| -#endif
|
| -{
|
| -#if PY_MAJOR_VERSION >= 3
|
| - PyObject *module = PyModule_Create(&moduledef);
|
| -#else
|
| - PyObject *module = Py_InitModule("_psutil_bsd", PsutilMethods);
|
| -#endif
|
| - if (module == NULL) {
|
| - INITERROR;
|
| - }
|
| - struct module_state *st = GETSTATE(module);
|
| -
|
| - st->error = PyErr_NewException("_psutil_bsd.Error", NULL, NULL);
|
| - if (st->error == NULL) {
|
| - Py_DECREF(module);
|
| - INITERROR;
|
| - }
|
| -#if PY_MAJOR_VERSION >= 3
|
| - return module;
|
| -#endif
|
| -}
|
| +// convert a timeval struct to a double
|
| +#define TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0)
|
|
|
|
|
| /*
|
| @@ -161,11 +57,9 @@ get_kinfo_proc(const pid_t pid, struct kinfo_proc *proc)
|
|
|
| /*
|
| * sysctl stores 0 in the size if we can't find the process information.
|
| - * Set errno to ESRCH which will be translated in NoSuchProcess later on.
|
| */
|
| if (size == 0) {
|
| - errno = ESRCH;
|
| - PyErr_SetFromErrno(PyExc_OSError);
|
| + NoSuchProcess();
|
| return -1;
|
| }
|
| return 0;
|
| @@ -207,6 +101,28 @@ get_pid_list(PyObject* self, PyObject* args)
|
|
|
|
|
| /*
|
| + * Return a Python float indicating the system boot time expressed in
|
| + * seconds since the epoch.
|
| + */
|
| +static PyObject*
|
| +get_system_boot_time(PyObject* self, PyObject* args)
|
| +{
|
| + /* fetch sysctl "kern.boottime" */
|
| + static int request[2] = { CTL_KERN, KERN_BOOTTIME };
|
| + struct timeval result;
|
| + size_t result_len = sizeof result;
|
| + time_t boot_time = 0;
|
| +
|
| + if (sysctl(request, 2, &result, &result_len, NULL, 0) == -1) {
|
| + PyErr_SetFromErrno(0);
|
| + return NULL;
|
| + }
|
| + boot_time = result.tv_sec;
|
| + return Py_BuildValue("f", (float)boot_time);
|
| +}
|
| +
|
| +
|
| +/*
|
| * Return process name from kinfo_proc as a Python string.
|
| */
|
| static PyObject*
|
| @@ -225,6 +141,47 @@ get_process_name(PyObject* self, PyObject* args)
|
|
|
|
|
| /*
|
| + * Return process pathname executable.
|
| + * Thanks to Robert N. M. Watson:
|
| + * http://fxr.googlebit.com/source/usr.bin/procstat/procstat_bin.c?v=8-CURRENT
|
| + */
|
| +static PyObject*
|
| +get_process_exe(PyObject* self, PyObject* args)
|
| +{
|
| + long pid;
|
| + char pathname[PATH_MAX];
|
| + int error;
|
| + int mib[4];
|
| + size_t size;
|
| +
|
| + if (! PyArg_ParseTuple(args, "l", &pid)) {
|
| + return NULL;
|
| + }
|
| +
|
| + mib[0] = CTL_KERN;
|
| + mib[1] = KERN_PROC;
|
| + mib[2] = KERN_PROC_PATHNAME;
|
| + mib[3] = pid;
|
| +
|
| + size = sizeof(pathname);
|
| + error = sysctl(mib, 4, pathname, &size, NULL, 0);
|
| + if (error == -1) {
|
| + PyErr_SetFromErrno(PyExc_OSError);
|
| + return NULL;
|
| + }
|
| + if (size == 0 || strlen(pathname) == 0) {
|
| + if (pid_exists(pid) == 0) {
|
| + return NoSuchProcess();
|
| + }
|
| + else {
|
| + strcpy(pathname, "");
|
| + }
|
| + }
|
| + return Py_BuildValue("s", pathname);
|
| +}
|
| +
|
| +
|
| +/*
|
| * Return process cmdline as a Python list of cmdline arguments.
|
| */
|
| static PyObject*
|
| @@ -268,10 +225,29 @@ get_process_ppid(PyObject* self, PyObject* args)
|
|
|
|
|
| /*
|
| - * Return process real uid from kinfo_proc as a Python integer.
|
| + * Return process status as a Python integer.
|
| + */
|
| +static PyObject*
|
| +get_process_status(PyObject* self, PyObject* args)
|
| +{
|
| + long pid;
|
| + struct kinfo_proc kp;
|
| + if (! PyArg_ParseTuple(args, "l", &pid)) {
|
| + return NULL;
|
| + }
|
| + if (get_kinfo_proc(pid, &kp) == -1) {
|
| + return NULL;
|
| + }
|
| + return Py_BuildValue("i", (int)kp.ki_stat);
|
| +}
|
| +
|
| +
|
| +/*
|
| + * Return process real, effective and saved user ids from kinfo_proc
|
| + * as a Python tuple.
|
| */
|
| static PyObject*
|
| -get_process_uid(PyObject* self, PyObject* args)
|
| +get_process_uids(PyObject* self, PyObject* args)
|
| {
|
| long pid;
|
| struct kinfo_proc kp;
|
| @@ -281,15 +257,18 @@ get_process_uid(PyObject* self, PyObject* args)
|
| if (get_kinfo_proc(pid, &kp) == -1) {
|
| return NULL;
|
| }
|
| - return Py_BuildValue("l", (long)kp.ki_ruid);
|
| + return Py_BuildValue("lll", (long)kp.ki_ruid,
|
| + (long)kp.ki_uid,
|
| + (long)kp.ki_svuid);
|
| }
|
|
|
|
|
| /*
|
| - * Return process real group id from ki_comm as a Python integer.
|
| + * Return process real, effective and saved group ids from kinfo_proc
|
| + * as a Python tuple.
|
| */
|
| static PyObject*
|
| -get_process_gid(PyObject* self, PyObject* args)
|
| +get_process_gids(PyObject* self, PyObject* args)
|
| {
|
| long pid;
|
| struct kinfo_proc kp;
|
| @@ -299,7 +278,28 @@ get_process_gid(PyObject* self, PyObject* args)
|
| if (get_kinfo_proc(pid, &kp) == -1) {
|
| return NULL;
|
| }
|
| - return Py_BuildValue("l", (long)kp.ki_rgid);
|
| + return Py_BuildValue("lll", (long)kp.ki_rgid,
|
| + (long)kp.ki_groups[0],
|
| + (long)kp.ki_svuid);
|
| +}
|
| +
|
| +
|
| +/*
|
| + * Return process real, effective and saved group ids from kinfo_proc
|
| + * as a Python tuple.
|
| + */
|
| +static PyObject*
|
| +get_process_tty_nr(PyObject* self, PyObject* args)
|
| +{
|
| + long pid;
|
| + struct kinfo_proc kp;
|
| + if (! PyArg_ParseTuple(args, "l", &pid)) {
|
| + return NULL;
|
| + }
|
| + if (get_kinfo_proc(pid, &kp) == -1) {
|
| + return NULL;
|
| + }
|
| + return Py_BuildValue("i", kp.ki_tdev);
|
| }
|
|
|
|
|
| @@ -321,9 +321,74 @@ get_process_num_threads(PyObject* self, PyObject* args)
|
| }
|
|
|
|
|
| +/*
|
| + * Retrieves all threads used by process returning a list of tuples
|
| + * including thread id, user time and system time.
|
| + * Thanks to Robert N. M. Watson:
|
| + * http://fxr.googlebit.com/source/usr.bin/procstat/procstat_threads.c?v=8-CURRENT
|
| + */
|
| +static PyObject*
|
| +get_process_threads(PyObject* self, PyObject* args)
|
| +{
|
| + long pid;
|
| + int mib[4];
|
| + struct kinfo_proc *kip;
|
| + struct kinfo_proc *kipp;
|
| + int error;
|
| + unsigned int i;
|
| + size_t size;
|
| + PyObject* retList = PyList_New(0);
|
| + PyObject* pyTuple = NULL;
|
|
|
| -// convert a timeval struct to a double
|
| -#define TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0)
|
| + if (! PyArg_ParseTuple(args, "l", &pid)) {
|
| + return NULL;
|
| + }
|
| +
|
| + /*
|
| + * We need to re-query for thread information, so don't use *kipp.
|
| + */
|
| + mib[0] = CTL_KERN;
|
| + mib[1] = KERN_PROC;
|
| + mib[2] = KERN_PROC_PID | KERN_PROC_INC_THREAD;
|
| + mib[3] = pid;
|
| +
|
| + size = 0;
|
| + error = sysctl(mib, 4, NULL, &size, NULL, 0);
|
| + if (error == -1) {
|
| + PyErr_SetFromErrno(PyExc_OSError);
|
| + return NULL;
|
| + }
|
| + if (size == 0) {
|
| + return NoSuchProcess();
|
| + }
|
| +
|
| + kip = malloc(size);
|
| + if (kip == NULL) {
|
| + PyErr_SetFromErrno(PyExc_OSError);
|
| + return NULL;
|
| + }
|
| +
|
| + error = sysctl(mib, 4, kip, &size, NULL, 0);
|
| + if (error == -1) {
|
| + PyErr_SetFromErrno(PyExc_OSError);
|
| + return NULL;
|
| + }
|
| + if (size == 0) {
|
| + return NoSuchProcess();
|
| + }
|
| +
|
| + for (i = 0; i < size / sizeof(*kipp); i++) {
|
| + kipp = &kip[i];
|
| + pyTuple = Py_BuildValue("Idd", kipp->ki_tid,
|
| + TV2DOUBLE(kipp->ki_rusage.ru_utime),
|
| + TV2DOUBLE(kipp->ki_rusage.ru_stime)
|
| + );
|
| + PyList_Append(retList, pyTuple);
|
| + Py_XDECREF(pyTuple);
|
| + }
|
| + free(kip);
|
| + return retList;
|
| +}
|
|
|
|
|
| /*
|
| @@ -391,6 +456,29 @@ get_process_create_time(PyObject* self, PyObject* args)
|
|
|
|
|
| /*
|
| + * Return a Python float indicating the process create time expressed in
|
| + * seconds since the epoch.
|
| + */
|
| +static PyObject*
|
| +get_process_io_counters(PyObject* self, PyObject* args)
|
| +{
|
| + long pid;
|
| + struct kinfo_proc kp;
|
| + if (! PyArg_ParseTuple(args, "l", &pid)) {
|
| + return NULL;
|
| + }
|
| + if (get_kinfo_proc(pid, &kp) == -1) {
|
| + return NULL;
|
| + }
|
| + // there's apparently no way to determine bytes count, hence return -1.
|
| + return Py_BuildValue("(llll)", kp.ki_rusage.ru_inblock,
|
| + kp.ki_rusage.ru_oublock,
|
| + -1, -1);
|
| +}
|
| +
|
| +
|
| +
|
| +/*
|
| * Return the RSS and VMS as a Python tuple.
|
| */
|
| static PyObject*
|
| @@ -546,15 +634,6 @@ get_system_cpu_times(PyObject* self, PyObject* args)
|
| return NULL;
|
| }
|
|
|
| - /*
|
| - #define CP_USER 0
|
| - #define CP_NICE 1
|
| - #define CP_SYS 2
|
| - #define CP_INTR 3
|
| - #define CP_IDLE 4
|
| - #define CPUSTATES 5
|
| - */
|
| - //user, nice, system, idle, iowait, irqm, softirq
|
| return Py_BuildValue("(ddddd)",
|
| (double)cpu_time[CP_USER] / CLOCKS_PER_SEC,
|
| (double)cpu_time[CP_NICE] / CLOCKS_PER_SEC,
|
| @@ -564,3 +643,317 @@ get_system_cpu_times(PyObject* self, PyObject* args)
|
| );
|
| }
|
|
|
| +
|
| +/*
|
| + * Return a Python list of tuple representing per-cpu times
|
| + */
|
| +static PyObject*
|
| +get_system_per_cpu_times(PyObject* self, PyObject* args)
|
| +{
|
| + static int maxcpus;
|
| + int mib[2];
|
| + int ncpu;
|
| + size_t len;
|
| + size_t size;
|
| + int i;
|
| + PyObject* py_retlist = PyList_New(0);
|
| + PyObject* py_cputime;
|
| +
|
| + // retrieve maxcpus value
|
| + size = sizeof(maxcpus);
|
| + if (sysctlbyname("kern.smp.maxcpus", &maxcpus, &size, NULL, 0) < 0) {
|
| + PyErr_SetFromErrno(0);
|
| + return NULL;
|
| + }
|
| + long cpu_time[maxcpus][CPUSTATES];
|
| +
|
| + // retrieve the number of cpus
|
| + mib[0] = CTL_HW;
|
| + mib[1] = HW_NCPU;
|
| + len = sizeof(ncpu);
|
| + if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == -1) {
|
| + PyErr_SetFromErrno(0);
|
| + return NULL;
|
| + }
|
| +
|
| + // per-cpu info
|
| + size = sizeof(cpu_time);
|
| + if (sysctlbyname("kern.cp_times", &cpu_time, &size, NULL, 0) == -1) {
|
| + PyErr_SetFromErrno(0);
|
| + return NULL;
|
| + }
|
| +
|
| + for (i = 0; i < ncpu; i++) {
|
| + py_cputime = Py_BuildValue("(ddddd)",
|
| + (double)cpu_time[i][CP_USER] / CLOCKS_PER_SEC,
|
| + (double)cpu_time[i][CP_NICE] / CLOCKS_PER_SEC,
|
| + (double)cpu_time[i][CP_SYS] / CLOCKS_PER_SEC,
|
| + (double)cpu_time[i][CP_IDLE] / CLOCKS_PER_SEC,
|
| + (double)cpu_time[i][CP_INTR] / CLOCKS_PER_SEC
|
| + );
|
| + PyList_Append(py_retlist, py_cputime);
|
| + Py_XDECREF(py_cputime);
|
| + }
|
| +
|
| + return py_retlist;
|
| +}
|
| +
|
| +
|
| +/*
|
| + * Return a list of tuples including device, mount point and fs type
|
| + * for all partitions mounted on the system.
|
| + */
|
| +static PyObject*
|
| +get_disk_partitions(PyObject* self, PyObject* args)
|
| +{
|
| + int num;
|
| + int i;
|
| + long len;
|
| + struct statfs *fs;
|
| + PyObject* py_retlist = PyList_New(0);
|
| + PyObject* py_tuple;
|
| +
|
| + // get the number of mount points
|
| + Py_BEGIN_ALLOW_THREADS
|
| + num = getfsstat(NULL, 0, MNT_NOWAIT);
|
| + Py_END_ALLOW_THREADS
|
| + if (num == -1) {
|
| + PyErr_SetFromErrno(0);
|
| + return NULL;
|
| + }
|
| +
|
| + len = sizeof(*fs) * num;
|
| + fs = malloc(len);
|
| +
|
| + Py_BEGIN_ALLOW_THREADS
|
| + num = getfsstat(fs, len, MNT_NOWAIT);
|
| + Py_END_ALLOW_THREADS
|
| + if (num == -1) {
|
| + free(fs);
|
| + PyErr_SetFromErrno(0);
|
| + return NULL;
|
| + }
|
| +
|
| + for (i = 0; i < num; i++) {
|
| + py_tuple = Py_BuildValue("(sss)", fs[i].f_mntfromname, // device
|
| + fs[i].f_mntonname, // mount point
|
| + fs[i].f_fstypename); // fs type
|
| + PyList_Append(py_retlist, py_tuple);
|
| + Py_XDECREF(py_tuple);
|
| + }
|
| +
|
| + free(fs);
|
| + return py_retlist;
|
| +}
|
| +
|
| +
|
| +/*
|
| + * Return a Python list of named tuples with overall network I/O information
|
| + */
|
| +static PyObject*
|
| +get_network_io_counters(PyObject* self, PyObject* args)
|
| +{
|
| + PyObject* py_retdict = PyDict_New();
|
| + PyObject* py_ifc_info;
|
| +
|
| + char *buf = NULL, *lim, *next;
|
| + struct if_msghdr *ifm;
|
| + int mib[6];
|
| + size_t len;
|
| +
|
| + mib[0] = CTL_NET; // networking subsystem
|
| + mib[1] = PF_ROUTE; // type of information
|
| + mib[2] = 0; // protocol (IPPROTO_xxx)
|
| + mib[3] = 0; // address family
|
| + mib[4] = NET_RT_IFLIST; // operation
|
| + mib[5] = 0;
|
| +
|
| + if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
|
| + Py_DECREF(py_retdict);
|
| + PyErr_SetFromErrno(0);
|
| + return NULL;
|
| + }
|
| +
|
| +
|
| + buf = malloc(len);
|
| +
|
| + if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
|
| + if (buf) {
|
| + free(buf);
|
| + }
|
| + Py_DECREF(py_retdict);
|
| + PyErr_SetFromErrno(0);
|
| + return NULL;
|
| + }
|
| +
|
| + lim = buf + len;
|
| +
|
| + for (next = buf; next < lim; ) {
|
| + ifm = (struct if_msghdr *)next;
|
| + next += ifm->ifm_msglen;
|
| +
|
| + if (ifm->ifm_type == RTM_IFINFO) {
|
| + struct if_msghdr *if2m = (struct if_msghdr *)ifm;
|
| + struct sockaddr_dl *sdl = (struct sockaddr_dl *)(if2m + 1);
|
| + char ifc_name[32];
|
| +
|
| + strncpy(ifc_name, sdl->sdl_data, sdl->sdl_nlen);
|
| + ifc_name[sdl->sdl_nlen] = 0;
|
| +
|
| + py_ifc_info = Py_BuildValue("(KKKK)",
|
| + if2m->ifm_data.ifi_obytes,
|
| + if2m->ifm_data.ifi_ibytes,
|
| + if2m->ifm_data.ifi_opackets,
|
| + if2m->ifm_data.ifi_ipackets);
|
| + PyDict_SetItemString(py_retdict, ifc_name, py_ifc_info);
|
| + Py_XDECREF(py_ifc_info);
|
| + }
|
| + else {
|
| + continue;
|
| + }
|
| + }
|
| +
|
| + return py_retdict;
|
| +}
|
| +
|
| +
|
| +
|
| +
|
| +/*
|
| + * define the psutil C module methods and initialize the module.
|
| + */
|
| +static PyMethodDef
|
| +PsutilMethods[] =
|
| +{
|
| + // --- per-process functions
|
| +
|
| + {"get_process_name", get_process_name, METH_VARARGS,
|
| + "Return process name"},
|
| + {"get_process_exe", get_process_exe, METH_VARARGS,
|
| + "Return process pathname executable"},
|
| + {"get_process_cmdline", get_process_cmdline, METH_VARARGS,
|
| + "Return process cmdline as a list of cmdline arguments"},
|
| + {"get_process_ppid", get_process_ppid, METH_VARARGS,
|
| + "Return process ppid as an integer"},
|
| + {"get_process_uids", get_process_uids, METH_VARARGS,
|
| + "Return process real effective and saved user ids as a Python tuple"},
|
| + {"get_process_gids", get_process_gids, METH_VARARGS,
|
| + "Return process real effective and saved group ids as a Python tuple"},
|
| + {"get_cpu_times", get_cpu_times, METH_VARARGS,
|
| + "Return tuple of user/kern time for the given PID"},
|
| + {"get_process_create_time", get_process_create_time, METH_VARARGS,
|
| + "Return a float indicating the process create time expressed in "
|
| + "seconds since the epoch"},
|
| + {"get_memory_info", get_memory_info, METH_VARARGS,
|
| + "Return a tuple of RSS/VMS memory information"},
|
| + {"get_process_num_threads", get_process_num_threads, METH_VARARGS,
|
| + "Return number of threads used by process"},
|
| + {"get_process_threads", get_process_threads, METH_VARARGS,
|
| + "Return process threads"},
|
| + {"get_process_status", get_process_status, METH_VARARGS,
|
| + "Return process status as an integer"},
|
| + {"get_process_io_counters", get_process_io_counters, METH_VARARGS,
|
| + "Return process IO counters"},
|
| + {"get_process_tty_nr", get_process_tty_nr, METH_VARARGS,
|
| + "Return process tty (terminal) number"},
|
| +
|
| +
|
| + // --- system-related functions
|
| +
|
| + {"get_pid_list", get_pid_list, METH_VARARGS,
|
| + "Returns a list of PIDs currently running on the system"},
|
| + {"get_num_cpus", get_num_cpus, METH_VARARGS,
|
| + "Return number of CPUs on the system"},
|
| + {"get_total_phymem", get_total_phymem, METH_VARARGS,
|
| + "Return the total amount of physical memory, in bytes"},
|
| + {"get_avail_phymem", get_avail_phymem, METH_VARARGS,
|
| + "Return the amount of available physical memory, in bytes"},
|
| + {"get_total_virtmem", get_total_virtmem, METH_VARARGS,
|
| + "Return the total amount of virtual memory, in bytes"},
|
| + {"get_avail_virtmem", get_avail_virtmem, METH_VARARGS,
|
| + "Return the amount of available virtual memory, in bytes"},
|
| + {"get_system_cpu_times", get_system_cpu_times, METH_VARARGS,
|
| + "Return system cpu times as a tuple (user, system, nice, idle, irc)"},
|
| + {"get_system_per_cpu_times", get_system_per_cpu_times, METH_VARARGS,
|
| + "Return system per-cpu times as a list of tuples"},
|
| + {"get_system_boot_time", get_system_boot_time, METH_VARARGS,
|
| + "Return a float indicating the system boot time expressed in "
|
| + "seconds since the epoch"},
|
| + {"get_disk_partitions", get_disk_partitions, METH_VARARGS,
|
| + "Return a list of tuples including device, mount point and "
|
| + "fs type for all partitions mounted on the system."},
|
| + {"get_network_io_counters", get_network_io_counters, METH_VARARGS,
|
| + "Return dict of tuples of networks I/O information."},
|
| +
|
| + {NULL, NULL, 0, NULL}
|
| +};
|
| +
|
| +struct module_state {
|
| + PyObject *error;
|
| +};
|
| +
|
| +#if PY_MAJOR_VERSION >= 3
|
| +#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
|
| +#else
|
| +#define GETSTATE(m) (&_state)
|
| +#endif
|
| +
|
| +#if PY_MAJOR_VERSION >= 3
|
| +
|
| +static int
|
| +psutil_bsd_traverse(PyObject *m, visitproc visit, void *arg) {
|
| + Py_VISIT(GETSTATE(m)->error);
|
| + return 0;
|
| +}
|
| +
|
| +static int
|
| +psutil_bsd_clear(PyObject *m) {
|
| + Py_CLEAR(GETSTATE(m)->error);
|
| + return 0;
|
| +}
|
| +
|
| +static struct PyModuleDef
|
| +moduledef = {
|
| + PyModuleDef_HEAD_INIT,
|
| + "psutil_bsd",
|
| + NULL,
|
| + sizeof(struct module_state),
|
| + PsutilMethods,
|
| + NULL,
|
| + psutil_bsd_traverse,
|
| + psutil_bsd_clear,
|
| + NULL
|
| +};
|
| +
|
| +#define INITERROR return NULL
|
| +
|
| +PyObject *
|
| +PyInit__psutil_bsd(void)
|
| +
|
| +#else
|
| +#define INITERROR return
|
| +
|
| +void init_psutil_bsd(void)
|
| +#endif
|
| +{
|
| +#if PY_MAJOR_VERSION >= 3
|
| + PyObject *module = PyModule_Create(&moduledef);
|
| +#else
|
| + PyObject *module = Py_InitModule("_psutil_bsd", PsutilMethods);
|
| +#endif
|
| + PyModule_AddIntConstant(module, "SSTOP", SSTOP);
|
| + PyModule_AddIntConstant(module, "SSLEEP", SSLEEP);
|
| + PyModule_AddIntConstant(module, "SRUN", SRUN);
|
| + PyModule_AddIntConstant(module, "SIDL", SIDL);
|
| + PyModule_AddIntConstant(module, "SWAIT", SWAIT);
|
| + PyModule_AddIntConstant(module, "SLOCK", SLOCK);
|
| + PyModule_AddIntConstant(module, "SZOMB", SZOMB);
|
| +
|
| + if (module == NULL) {
|
| + INITERROR;
|
| + }
|
| +#if PY_MAJOR_VERSION >= 3
|
| + return module;
|
| +#endif
|
| +}
|
| +
|
|
|