Skip to content

Commit

Permalink
#779 / proc cpu times: sunos impl
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Feb 2, 2016
1 parent e3e575b commit 350eeb1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions psutil/_pssunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
}

scputimes = namedtuple('scputimes', ['user', 'system', 'idle', 'iowait'])
pcputimes = namedtuple('pcputimes',
['user', 'system', 'children_user', 'children_system'])
svmem = namedtuple('svmem', ['total', 'available', 'percent', 'used', 'free'])
pmem = namedtuple('pmem', ['rss', 'vms'])
pmmap_grouped = namedtuple('pmmap_grouped',
Expand Down Expand Up @@ -363,8 +365,7 @@ def gids(self):

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

@wrap_exceptions
def terminal(self):
Expand Down
10 changes: 7 additions & 3 deletions psutil/_psutil_sunos.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ psutil_proc_cpu_times(PyObject *self, PyObject *args) {
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
// results are more precise than os.times()
return Py_BuildValue("dd",
PSUTIL_TV2DOUBLE(info.pr_utime),
PSUTIL_TV2DOUBLE(info.pr_stime));
return Py_BuildValue(
"(dddd)",
PSUTIL_TV2DOUBLE(info.pr_utime),
PSUTIL_TV2DOUBLE(info.pr_stime),
PSUTIL_TV2DOUBLE(info.pr_cutime),
PSUTIL_TV2DOUBLE(info.pr_cstime)
);
}


Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_cpu_percent(self):
def test_cpu_times(self):
times = psutil.Process().cpu_times()
assert (times.user > 0.0) or (times.system > 0.0), times
if LINUX:
if LINUX or BSD or SUNOS:
assert (times.children_user >= 0.0), times
assert (times.children_system >= 0.0), times
# make sure returned values can be pretty printed with strftime
Expand Down

0 comments on commit 350eeb1

Please sign in to comment.