summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2018-03-13 19:21:43 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2018-03-13 19:21:43 +0100
commitc08ec74d44e5183dd2e399c96392bcb96d2ea971 (patch)
tree3b2f871121264eec482c7b3dd1ab20a2d48e03aa
parentd67e977cb57e77c6907d3e4c183b8ffedd9e9dcc (diff)
downloadpsutil-c08ec74d44e5183dd2e399c96392bcb96d2ea971.tar.gz
#1222 / linux / memory_full_info: we were erroneously adding "Pss:" and "SwapPss"
-rw-r--r--HISTORY.rst4
-rw-r--r--psutil/_pslinux.py7
-rwxr-xr-xpsutil/tests/test_linux.py40
3 files changed, 46 insertions, 5 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 9667f85f..bb094980 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -14,8 +14,8 @@ XXXX-XX-XX
**Bug fixes**
- 1216_: fix compatibility with python 2.6 on Windows (patch by Dan Vinakovsky)
-- 1222_: [Linux] Process.memory_full_info() was summing both "swap PSS" (swap
- proportional set size) and plain "swap". Not anymore.
+- 1222_: [Linux] Process.memory_full_info() was erroneously summing "Swap:" and
+ "SwapPss:". Same for "Pss:" and "SwapPss". Not anymore.
- 1240_: [Windows] cpu_times() float loses accuracy in a long running system.
(patch by stswandering)
- 1245_: [Linux] sensors_temperatures() may fail with IOError "no such file".
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index e7f6e2c1..c8c10ec9 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1606,9 +1606,10 @@ class Process(object):
@wrap_exceptions
def memory_full_info(
self,
- _private_re=re.compile(br"Private.*:\s+(\d+)"),
- _pss_re=re.compile(br"Pss.*:\s+(\d+)"),
- _swap_re=re.compile(br"Swap:\s+(\d+)")):
+ # Gets Private_Clean, Private_Dirty, Private_Hugetlb.
+ _private_re=re.compile(br"\nPrivate.*:\s+(\d+)"),
+ _pss_re=re.compile(br"\nPss\:\s+(\d+)"),
+ _swap_re=re.compile(br"\nSwap\:\s+(\d+)")):
basic_mem = self.memory_info()
# Note: using 3 regexes is faster than reading the file
# line by line.
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index 6ba17b25..139b32ab 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -1482,6 +1482,46 @@ class TestProcess(unittest.TestCase):
self.assertAlmostEqual(
mem.swap, sum([x.swap for x in maps]), delta=4096)
+ def test_memory_full_info_mocked(self):
+ # See: https://github.com/giampaolo/psutil/issues/1222
+ def open_mock(name, *args, **kwargs):
+ if name == "/proc/%s/smaps" % os.getpid():
+ return io.BytesIO(textwrap.dedent("""\
+ fffff0 r-xp 00000000 00:00 0 [vsyscall]
+ Size: 1 kB
+ Rss: 2 kB
+ Pss: 3 kB
+ Shared_Clean: 4 kB
+ Shared_Dirty: 5 kB
+ Private_Clean: 6 kB
+ Private_Dirty: 7 kB
+ Referenced: 8 kB
+ Anonymous: 9 kB
+ LazyFree: 10 kB
+ AnonHugePages: 11 kB
+ ShmemPmdMapped: 12 kB
+ Shared_Hugetlb: 13 kB
+ Private_Hugetlb: 14 kB
+ Swap: 15 kB
+ SwapPss: 16 kB
+ KernelPageSize: 17 kB
+ MMUPageSize: 18 kB
+ Locked: 19 kB
+ VmFlags: rd ex
+ """).encode())
+ else:
+ return orig_open(name, *args, **kwargs)
+
+ orig_open = open
+ patch_point = 'builtins.open' if PY3 else '__builtin__.open'
+ with mock.patch(patch_point, create=True, side_effect=open_mock) as m:
+ p = psutil.Process()
+ mem = p.memory_full_info()
+ assert m.called
+ self.assertEqual(mem.uss, (6 + 7 + 14) * 1024)
+ self.assertEqual(mem.pss, 3 * 1024)
+ self.assertEqual(mem.swap, 15 * 1024)
+
# On PYPY file descriptors are not closed fast enough.
@unittest.skipIf(PYPY, "unreliable on PYPY")
def test_open_files_mode(self):