diff options
author | wiggin15 <wiggin15@yahoo.com> | 2017-10-31 11:46:08 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-10-31 10:46:08 +0100 |
commit | 65a52341b55faaab41f68ebc4ed31f18f0929754 (patch) | |
tree | ac934885eb53fc38206f93f62027684a38f5d68a /psutil/_psutil_aix.c | |
parent | 1781c243e590d4dfdb3abff9a658fdc8bbec80b4 (diff) | |
download | psutil-65a52341b55faaab41f68ebc4ed31f18f0929754.tar.gz |
AIX: implement num_ctx_switches (#1164)
* small changes
* AIX: implement num_ctx_switches
Diffstat (limited to 'psutil/_psutil_aix.c')
-rw-r--r-- | psutil/_psutil_aix.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/psutil/_psutil_aix.c b/psutil/_psutil_aix.c index 8ffc8f47..0834726d 100644 --- a/psutil/_psutil_aix.c +++ b/psutil/_psutil_aix.c @@ -4,16 +4,16 @@ * All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. - /* + */ /* * AIX support is experimental at this time. * The following functions and methods are unsupported on the AIX platform: * - psutil.Process.memory_maps - * - psutil.Process.num_ctx_switches * * Known limitations: * - psutil.Process.io_counters read count is always 0 + * - psutil.Process.threads may not be available on older AIX versions * - reading basic process info may fail or return incorrect values when * process is starting (see IBM APAR IV58499 - fixed in newer AIX versions) * - sockets and pipes may not be counted in num_fds (fixed in newer AIX @@ -49,6 +49,7 @@ #include "arch/aix/ifaddrs.h" #include "arch/aix/net_connections.h" +#include "arch/aix/common.h" #include "_psutil_common.h" #include "_psutil_posix.h" @@ -308,6 +309,43 @@ psutil_proc_cred(PyObject *self, PyObject *args) { /* + * Return process voluntary and involuntary context switches as a Python tuple. + */ +static PyObject * +psutil_proc_num_ctx_switches(PyObject *self, PyObject *args) { + PyObject *py_tuple = NULL; + pid32_t requested_pid; + pid32_t pid = 0; + int np = 0; + struct procentry64 *processes = (struct procentry64 *)NULL; + struct procentry64 *p; + + if (! PyArg_ParseTuple(args, "i", &requested_pid)) + return NULL; + + processes = psutil_read_process_table(&np); + if (!processes) + return NULL; + + /* Loop through processes */ + for (p = processes; np > 0; np--, p++) { + pid = p->pi_pid; + if (requested_pid != pid) + continue; + py_tuple = Py_BuildValue("LL", + (long long) p->pi_ru.ru_nvcsw, /* voluntary context switches */ + (long long) p->pi_ru.ru_nivcsw); /* involuntary */ + free(processes); + return py_tuple; + } + + /* finished iteration without finding requested pid */ + free(processes); + return NoSuchProcess(); +} + + +/* * Return users currently connected on the system. */ static PyObject * @@ -833,6 +871,8 @@ PsutilMethods[] = #endif {"proc_io_counters", psutil_proc_io_counters, METH_VARARGS, "Get process I/O counters."}, + {"proc_num_ctx_switches", psutil_proc_num_ctx_switches, METH_VARARGS, + "Get process I/O counters."}, // --- system-related functions {"users", psutil_users, METH_VARARGS, |