diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-03-01 15:58:31 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-03-01 15:58:31 +0100 |
commit | 168e8c95aac8815900d0011fca6d525c831801f4 (patch) | |
tree | 043701a4cd5d135c343255f1f082bfe4dbd59037 | |
parent | f2a1a605eb9e43e6e6d7a8d911eb3df73ec791ec (diff) | |
download | psutil-168e8c95aac8815900d0011fca6d525c831801f4.tar.gz |
osx / bsd: set children user/sys time to 0
-rw-r--r-- | docs/index.rst | 12 | ||||
-rw-r--r-- | psutil/_common.py | 3 | ||||
-rw-r--r-- | psutil/_psbsd.py | 2 | ||||
-rw-r--r-- | psutil/_pslinux.py | 5 | ||||
-rw-r--r-- | psutil/_psosx.py | 3 | ||||
-rw-r--r-- | psutil/_pssunos.py | 3 | ||||
-rw-r--r-- | psutil/_pswindows.py | 7 | ||||
-rw-r--r-- | psutil/tests/test_process.py | 5 |
8 files changed, 20 insertions, 20 deletions
diff --git a/docs/index.rst b/docs/index.rst index 0a0674d4..3c7fb6e4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -915,17 +915,17 @@ Process class .. method:: cpu_times() - Return a (user, system) namedtuple representing the accumulated process - time, in seconds (see + Return a `(user, system, children_user, children_system)` namedtuple + representing the accumulated process time, in seconds (see `explanation <http://stackoverflow.com/questions/556405/>`__). - On Linux, BSD and SunOS the namedtuple also includes `children_user` times - and `children_system` times. + On Windows and OSX only *user* and *system* are filled, the others are + set to ``0``. This is similar to `os.times() <http://docs.python.org//library/os.html#os.times>`__ but can be used for any process PID. - .. versionchanged:: 4.1.0 return two extra fields on Linux, BSD and SunOS: - *children_user* and *children_system*. + .. versionchanged:: 4.1.0 return two extra fields: *children_user* and + *children_system*. .. method:: cpu_percent(interval=None) diff --git a/psutil/_common.py b/psutil/_common.py index 51cc1a2c..b146c736 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -311,7 +311,8 @@ snicstats = namedtuple('snicstats', ['isup', 'duplex', 'speed', 'mtu']) # --- namedtuples for psutil.Process methods # psutil.Process.cpu_times() -pcputimes = namedtuple('pcputimes', ['user', 'system']) +pcputimes = namedtuple('pcputimes', + ['user', 'system', 'children_user', 'children_system']) # psutil.Process.open_files() popenfile = namedtuple('popenfile', ['path', 'fd']) # psutil.Process.threads() diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index c47f480c..d628f3f7 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -438,7 +438,7 @@ class Process(object): @wrap_exceptions def cpu_times(self): - return pcputimes(*cext.proc_cpu_times(self.pid)) + return _common.pcputimes(*cext.proc_cpu_times(self.pid)) @wrap_exceptions def memory_info(self): diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 9abbb876..50da9b53 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -251,9 +251,6 @@ popenfile = namedtuple('popenfile', ['path', 'fd', 'position', 'mode', 'flags']) pmem = namedtuple('pmem', 'rss vms shared text lib data dirty') pfullmem = namedtuple('pfullmem', pmem._fields + ('uss', 'pss', 'swap')) -pcputimes = namedtuple('pcputimes', - ['user', 'system', 'children_user', 'children_system']) - pmmap_grouped = namedtuple( 'pmmap_grouped', ['path', 'rss', 'size', 'pss', 'shared_clean', 'shared_dirty', 'private_clean', 'private_dirty', @@ -993,7 +990,7 @@ class Process(object): stime = float(values[12]) / CLOCK_TICKS children_utime = float(values[13]) / CLOCK_TICKS children_stime = float(values[14]) / CLOCK_TICKS - return pcputimes(utime, stime, children_utime, children_stime) + return _common.pcputimes(utime, stime, children_utime, children_stime) @wrap_exceptions def wait(self, timeout=None): diff --git a/psutil/_psosx.py b/psutil/_psosx.py index 5f39589c..b8066775 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -282,7 +282,8 @@ class Process(object): @wrap_exceptions def cpu_times(self): user, system = cext.proc_cpu_times(self.pid) - return _common.pcputimes(user, system) + # Children user/system times are not retrievable (set to 0). + return _common.pcputimes(user, system, 0, 0) @wrap_exceptions def create_time(self): diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py index f5ea5878..8779c425 100644 --- a/psutil/_pssunos.py +++ b/psutil/_pssunos.py @@ -365,7 +365,8 @@ class Process(object): @wrap_exceptions def cpu_times(self): - return pcputimes(*cext.proc_cpu_times(self.pid, self._procfs_path)) + times = cext.proc_cpu_times(self.pid, self._procfs_path) + return _common.pcputimes(*times) @wrap_exceptions def terminal(self): diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index 92472576..25ed2a59 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -448,14 +448,15 @@ class Process(object): @wrap_exceptions def cpu_times(self): try: - ret = cext.proc_cpu_times(self.pid) + user, system = cext.proc_cpu_times(self.pid) except OSError as err: if err.errno in ACCESS_DENIED_SET: nt = ntpinfo(*cext.proc_info(self.pid)) - ret = (nt.user_time, nt.kernel_time) + user, system = (nt.user_time, nt.kernel_time) else: raise - return _common.pcputimes(*ret) + # Children user/system times are not retrievable (set to 0). + return _common.pcputimes(user, system, 0, 0) @wrap_exceptions def suspend(self): diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 8a557f60..477c412c 100644 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -267,9 +267,8 @@ class TestProcess(unittest.TestCase): def test_cpu_times(self): times = psutil.Process().cpu_times() assert (times.user > 0.0) or (times.system > 0.0), times - if LINUX or BSD or SUNOS: - assert (times.children_user >= 0.0), times - assert (times.children_system >= 0.0), times + assert (times.children_user >= 0.0), times + assert (times.children_system >= 0.0), times # make sure returned values can be pretty printed with strftime for name in times._fields: time.strftime("%H:%M:%S", time.localtime(getattr(times, name))) |