diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-03-01 16:12:04 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-03-01 16:12:04 +0100 |
commit | 0f35787993e38df5155d8459cd735960a4e4f20e (patch) | |
tree | 6a4dba056ee54dbf62b23c6f8f5470ab47fb7f5f | |
parent | a18641f6908047bba27c61b8ac450f0999c59d25 (diff) | |
parent | 170680a8e50d2af1f031499ebb55b0ce7c223c31 (diff) | |
download | psutil-779-proc-cpu-children-times.tar.gz |
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | HISTORY.rst | 7 | ||||
-rw-r--r-- | IDEAS | 2 | ||||
-rw-r--r-- | docs/index.rst | 18 | ||||
-rw-r--r-- | psutil/_pslinux.py | 10 | ||||
-rw-r--r-- | psutil/_psutil_osx.c | 13 | ||||
-rw-r--r-- | psutil/tests/__init__.py | 1 | ||||
-rw-r--r-- | psutil/tests/test_linux.py | 18 | ||||
-rw-r--r-- | psutil/tests/test_process.py | 6 |
9 files changed, 50 insertions, 26 deletions
diff --git a/.travis.yml b/.travis.yml index 03f19132..17206c58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ matrix: - python: 3.3 - python: 3.4 - python: 3.5 + - "pypy" # XXX - commented because OSX builds are deadly slow # - language: generic # os: osx diff --git a/HISTORY.rst b/HISTORY.rst index 9dfb8d0f..46438783 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,8 +7,8 @@ Bug tracker at https://github.com/giampaolo/psutil/issues - #777: [Linux] Process.open_files() on Linux return 3 new fields: position, mode and flags. -- #779: [Linux, BSD, SunOS]: Process.cpu_times() returns two new fields: - 'children_user' and 'children_system'. +- #779: Process.cpu_times() returns two new fields, 'children_user' and + 'children_system' (always set to 0 on OSX and Windows). **Bug fixes** @@ -16,6 +16,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues provides it. - #776: [Linux] Process.cpu_affinity() may erroneously raise NoSuchProcess. (patch by wxwright) +- #780: [OSX] psutil does not compile with some gcc versions. 4.0.0 - 2016-02-17 @@ -38,6 +39,8 @@ Bug tracker at https://github.com/giampaolo/psutil/issues **Bug fixes** +- #685: [Linux] virtual_memory() provides wrong results on systems with a lot + of physical memory. - #704: [Solaris] psutil does not compile on Solaris sparc. - #734: on Python 3 invalid UTF-8 data is not correctly handled for process name(), cwd(), exe(), cmdline() and open_files() methods resulting in @@ -19,6 +19,8 @@ FEATURES - (UNIX) process root (different from cwd) +- #782: (UNIX) process num of signals received. + - (Linux) locked files via /proc/locks: https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-proc-locks.html diff --git a/docs/index.rst b/docs/index.rst index 3c7fb6e4..c9066493 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -266,16 +266,22 @@ Disks .. function:: disk_io_counters(perdisk=False) Return system-wide disk I/O statistics as a namedtuple including the - following fields. + following fields: + - **read_count**: number of reads - **write_count**: number of writes - **read_bytes**: number of bytes read - **write_bytes**: number of bytes written - - **read_time**: (all except NetBSD and OpenBSD) time spent reading from disk (in milliseconds) - - **write_time**: (all except NetBSD and OpenBSD) time spent writing to disk (in milliseconds) - - **busy_time**: (Linux, FreeBSD) time spent doing actual I/Os (in milliseconds) - - **read_merged_count** (Linux): number of merged reads (see `iostat doc <https://www.kernel.org/doc/Documentation/iostats.txt>`__) - - **write_merged_count** (Linux): number of merged writes (see `iostats doc <https://www.kernel.org/doc/Documentation/iostats.txt>`__) + - **read_time**: (all except NetBSD and OpenBSD) time spent reading from + disk (in milliseconds) + - **write_time**: (all except NetBSD and OpenBSD) time spent writing to disk + (in milliseconds) + - **busy_time**: (Linux, FreeBSD) time spent doing actual I/Os (in + milliseconds) + - **read_merged_count** (Linux): number of merged reads + (see `iostat doc <https://www.kernel.org/doc/Documentation/iostats.txt>`__) + - **write_merged_count** (Linux): number of merged writes + (see `iostats doc <https://www.kernel.org/doc/Documentation/iostats.txt>`__) If *perdisk* is ``True`` return the same information for every physical disk installed on the system as a dictionary with partition names as the keys and diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 50da9b53..0b996e70 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -180,13 +180,13 @@ def readlink(path): def file_flags_to_mode(flags): - md = {os.O_RDONLY: 'r', os.O_WRONLY: 'w', os.O_RDWR: 'w+'} - m = md[flags & (os.O_RDONLY | os.O_WRONLY | os.O_RDWR)] + modes_map = {os.O_RDONLY: 'r', os.O_WRONLY: 'w', os.O_RDWR: 'w+'} + mode = modes_map[flags & (os.O_RDONLY | os.O_WRONLY | os.O_RDWR)] if flags & os.O_APPEND: - m = m.replace('w', 'a', 1) - m = m.replace('w+', 'r+') + mode = mode.replace('w', 'a', 1) + mode = mode.replace('w+', 'r+') # possible values: r, w, a, r+, a+ - return m + return mode def get_sector_size(): diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c index f76ca0e6..e9a898ac 100644 --- a/psutil/_psutil_osx.c +++ b/psutil/_psutil_osx.c @@ -581,11 +581,14 @@ psutil_proc_memory_uss(PyObject *self, PyObject *args) { mach_msg_type_number_t info_count = VM_REGION_TOP_INFO_COUNT; kern_return_t kr; vm_size_t page_size; + mach_vm_address_t addr = MACH_VM_MIN_ADDRESS; + mach_port_t task = MACH_PORT_NULL; + vm_region_top_info_data_t info; + mach_port_t object_name; if (! PyArg_ParseTuple(args, "l", &pid)) return NULL; - mach_port_t task = MACH_PORT_NULL; err = task_for_pid(mach_task_self(), pid, &task); if (err != KERN_SUCCESS) { psutil_raise_ad_or_nsp(pid); @@ -600,10 +603,7 @@ psutil_proc_memory_uss(PyObject *self, PyObject *args) { // Roughly based on libtop_update_vm_regions in // http://www.opensource.apple.com/source/top/top-100.1.2/libtop.c - for (mach_vm_address_t addr = MACH_VM_MIN_ADDRESS; ; addr += size) { - vm_region_top_info_data_t info; - mach_port_t object_name; - + for (addr = 0; ; addr += size) { kr = mach_vm_region( task, &addr, &size, VM_REGION_TOP_INFO, (vm_region_info_t)&info, &info_count, &object_name); @@ -612,7 +612,8 @@ psutil_proc_memory_uss(PyObject *self, PyObject *args) { break; } else if (kr != KERN_SUCCESS) { - return false; + PyErr_Format(PyExc_RuntimeError, "mach_vm_region() failed"); + return NULL; } if (psutil_in_shared_region(addr, cpu_type) && diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 7ff5133f..a3a8f1ba 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -82,6 +82,7 @@ TESTFN = os.path.join(os.getcwd(), "$testfile") TESTFN_UNICODE = TESTFN + "ƒőő" TESTFILE_PREFIX = 'psutil-test-suite-' TOX = os.getenv('TOX') or '' in ('1', 'true') +PYPY = '__pypy__' in sys.builtin_module_names if not PY3: try: TESTFN_UNICODE = unicode(TESTFN_UNICODE, sys.getfilesystemencoding()) diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index a9545991..67da1b54 100644 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -33,6 +33,7 @@ from psutil.tests import call_until from psutil.tests import get_kernel_version from psutil.tests import importlib from psutil.tests import MEMORY_TOLERANCE +from psutil.tests import PYPY from psutil.tests import pyrun from psutil.tests import reap_children from psutil.tests import retry_before_failing @@ -764,13 +765,16 @@ class TestProcess(unittest.TestCase): time.sleep(.1) mem = p.memory_full_info() maps = p.memory_maps(grouped=False) - self.assertEqual( - mem.uss, sum([x.private_dirty + x.private_clean for x in maps])) - self.assertEqual( - mem.pss, sum([x.pss for x in maps])) - self.assertEqual( - mem.swap, sum([x.swap for x in maps])) - + self.assertAlmostEqual( + mem.uss, sum([x.private_dirty + x.private_clean for x in maps]), + delta=4096) + self.assertAlmostEqual( + mem.pss, sum([x.pss for x in maps]), delta=4096) + self.assertAlmostEqual( + mem.swap, sum([x.swap for x in maps]), delta=4096) + + # On PYPY file descriptors are not closed fast enough. + @unittest.skipIf(PYPY, "skipped on PYPY") def test_open_files_mode(self): def get_test_file(): p = psutil.Process() diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 477c412c..79d28b19 100644 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -65,6 +65,7 @@ from psutil.tests import get_test_subprocess from psutil.tests import get_winver from psutil.tests import GLOBAL_TIMEOUT from psutil.tests import pyrun +from psutil.tests import PYPY from psutil.tests import PYTHON from psutil.tests import reap_children from psutil.tests import retry_before_failing @@ -425,6 +426,11 @@ class TestProcess(unittest.TestCase): self.assertGreaterEqual(value, 0) if name in dir(resource): self.assertEqual(value, getattr(resource, name)) + # XXX - On PyPy RLIMIT_INFINITY returned by + # resource.getrlimit() is reported as a very big long + # number instead of -1. It looks like a bug with PyPy. + if PYPY: + continue self.assertEqual(p.rlimit(value), resource.getrlimit(value)) else: ret = p.rlimit(value) |