Skip to content

Commit

Permalink
#779 / proc cpu times: freebsd impl
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Feb 15, 2016
1 parent 7f46ad3 commit 5aee97f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
'scputimes', ['user', 'nice', 'system', 'idle', 'irq'])
pmem = namedtuple('pmem', ['rss', 'vms', 'text', 'data', 'stack'])
pfullmem = pmem
pcputimes = namedtuple('pcputimes',
['user', 'system', 'children_user', 'children_system'])
pmmap_grouped = namedtuple(
'pmmap_grouped', 'path rss, private, ref_count, shadow_count')
pmmap_ext = namedtuple(
Expand Down Expand Up @@ -436,8 +438,7 @@ def gids(self):

@wrap_exceptions
def cpu_times(self):
user, system = cext.proc_cpu_times(self.pid)
return _common.pcputimes(user, system)
return pcputimes(*cext.proc_cpu_times(self.pid))

@wrap_exceptions
def memory_info(self):
Expand Down
7 changes: 5 additions & 2 deletions psutil/_psutil_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ psutil_proc_num_ctx_switches(PyObject *self, PyObject *args) {
static PyObject *
psutil_proc_cpu_times(PyObject *self, PyObject *args) {
long pid;
double user_t, sys_t;
double user_t, sys_t, children_user_t, children_sys_t;
kinfo_proc kp;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
Expand All @@ -378,11 +378,14 @@ psutil_proc_cpu_times(PyObject *self, PyObject *args) {
#ifdef __FreeBSD__
user_t = PSUTIL_TV2DOUBLE(kp.ki_rusage.ru_utime);
sys_t = PSUTIL_TV2DOUBLE(kp.ki_rusage.ru_stime);
children_user_t = PSUTIL_TV2DOUBLE(kp.ki_rusage_ch.ru_utime);
children_sys_t = PSUTIL_TV2DOUBLE(kp.ki_rusage_ch.ru_stime);
#elif defined(__OpenBSD__) || defined(__NetBSD__)
user_t = PSUTIL_KPT2DOUBLE(kp.p_uutime);
sys_t = PSUTIL_KPT2DOUBLE(kp.p_ustime);
#endif
return Py_BuildValue("(dd)", user_t, sys_t);
return Py_BuildValue("(dddd)",
user_t, sys_t, children_user_t, children_sys_t);
}


Expand Down

0 comments on commit 5aee97f

Please sign in to comment.