summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-02-04 21:46:15 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2016-02-04 21:46:15 +0100
commitc8a5ef085a0e7c9b22b440cf9dab31e66f4b3a47 (patch)
treef80b0824ec0dfe6929a1acc4b1bf67c557a792d8
parent4761cfee48b780684af48b59745b302a96ad7b8b (diff)
downloadpsutil-c8a5ef085a0e7c9b22b440cf9dab31e66f4b3a47.tar.gz
linux / memory_addrspace_info(): also provide 'swap' metrics
-rw-r--r--README.rst2
-rw-r--r--docs/index.rst8
-rw-r--r--psutil/_pslinux.py8
-rw-r--r--test/_linux.py2
4 files changed, 13 insertions, 7 deletions
diff --git a/README.rst b/README.rst
index 0742414b..017a0d66 100644
--- a/README.rst
+++ b/README.rst
@@ -240,7 +240,7 @@ Process management
pmem(rss=10915840, vms=67608576, shared=3313664, text=2310144, lib=0, data=7262208, dirty=0)
>>>
>>> p.memory_addrspace_info() # "real" memory usage (Linux, OSX, Win only)
- paddrspmem(uss=9830400, pss=1216512)
+ paddrspmem(uss=9830400, pss=1216512, swap=0)
>>>
>>> p.memory_maps()
[pmmap_grouped(path='/lib/x8664-linux-gnu/libutil-2.15.so', rss=32768, size=2125824, pss=32768, shared_clean=0, shared_dirty=0, private_clean=20480, private_dirty=12288, referenced=32768, anonymous=12288, swap=0),
diff --git a/docs/index.rst b/docs/index.rst
index 9449b4e2..4a7816c7 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1065,8 +1065,8 @@ Process class
This method passes through the whole process address space in order to
calculate highly reliable metrics about "real" process memory consumption.
- It usually requires higher privileges and is considerably
- slower than :meth:`memory_info`.
+ It usually requires higher privileges and is considerably slower than
+ :meth:`memory_info`.
- **uss**: (Linux, Windows, OSX) aka "Unique Set Size", this is the memory
which is unique to a process and which would be freed if the process was terminated right now.
@@ -1077,6 +1077,8 @@ Process class
I.e. if a process has 10 MBs all to itself, and 10 MBs shared with
another process, its PSS will be 15 MBs.
+ - **swap**: (Linux) memory that has been swapped out to disk.
+
.. note::
`uss` is probably the most representative metric for determining how
much memory is being used by a process.
@@ -1088,7 +1090,7 @@ Process class
>>> import psutil
>>> p = psutil.Process()
>>> p.memory_addrspace_info()
- paddrspmem(uss=7421952, pss=7681024)
+ paddrspmem(uss=7421952, pss=7681024, swap=0)
>>>
.. versionadded:: 3.5.0
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 8f54dfeb..11e21fd7 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -219,7 +219,7 @@ svmem = namedtuple(
'active', 'inactive', 'buffers', 'cached'])
pmem = namedtuple('pmem', 'rss vms shared text lib data dirty')
-paddrspmem = namedtuple('paddrspmem', ['uss', 'pss'])
+paddrspmem = namedtuple('paddrspmem', ['uss', 'pss', 'swap'])
pmmap_grouped = namedtuple(
'pmmap_grouped', ['path', 'rss', 'size', 'pss', 'shared_clean',
@@ -976,7 +976,8 @@ class Process(object):
def memory_addrspace_info(
self,
_private_re=re.compile(b"Private.*:\s+(\d+)"),
- _pss_re=re.compile(b"Pss.*:\s+(\d+)")):
+ _pss_re=re.compile(b"Pss.*:\s+(\d+)"),
+ _swap_re=re.compile(b"Swap.*:\s+(\d+)")):
# Note: using two regexes is faster than reading the file
# line by line.
# XXX: on Python 3 the 2 regexes are 30% slower than on
@@ -986,7 +987,8 @@ class Process(object):
smaps_data = f.read()
uss = sum(map(int, _private_re.findall(smaps_data))) * 1024
pss = sum(map(int, _pss_re.findall(smaps_data))) * 1024
- return paddrspmem(uss, pss)
+ swap = sum(map(int, _swap_re.findall(smaps_data))) * 1024
+ return paddrspmem(uss, pss, swap)
@wrap_exceptions
def memory_maps(self):
diff --git a/test/_linux.py b/test/_linux.py
index cebd21a4..7baa7d00 100644
--- a/test/_linux.py
+++ b/test/_linux.py
@@ -616,6 +616,8 @@ class LinuxSpecificTestCase(unittest.TestCase):
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]))
def main():