summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-02-17 17:00:50 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2016-02-17 17:00:50 +0100
commitcc1e74aeb3866f4324904a96fdeb3d4d5c879c51 (patch)
tree17484857418b542b17e8968e3b41dded0f14ceea
parent0291759a750ebc46882d7ee9c75e21661ac5c024 (diff)
downloadpsutil-cc1e74aeb3866f4324904a96fdeb3d4d5c879c51.tar.gz
rename memory_addrspace_info -> memory_full_info
-rw-r--r--README.rst4
-rw-r--r--docs/index.rst28
-rw-r--r--psutil/__init__.py32
-rw-r--r--psutil/_pslinux.py27
-rw-r--r--psutil/_psosx.py7
-rw-r--r--psutil/_pssunos.py2
-rw-r--r--psutil/_pswindows.py7
-rw-r--r--psutil/tests/test_linux.py4
-rw-r--r--psutil/tests/test_memory_leaks.py4
-rw-r--r--psutil/tests/test_misc.py4
-rw-r--r--psutil/tests/test_process.py6
-rwxr-xr-xscripts/procsmem.py15
12 files changed, 77 insertions, 63 deletions
diff --git a/README.rst b/README.rst
index eb0da7a3..64c6ceaf 100644
--- a/README.rst
+++ b/README.rst
@@ -239,8 +239,8 @@ Process management
>>> p.memory_info()
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, swap=0)
+ >>> p.memory_full_info() # "real" USS memory usage (Linux, OSX, Win only)
+ pfullmem(rss=10199040, vms=52133888, shared=3887104, text=2867200, lib=0, data=5967872, dirty=0, uss=6545408, pss=6872064, 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 cbfa1887..9ac4b976 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1091,17 +1091,19 @@ Process class
.. warning:: deprecated in version 4.0.0; use :meth:`memory_info` instead.
- .. method:: memory_addrspace_info()
+ .. method:: memory_full_info()
- This method passes through the whole process address space in order to
- calculate highly reliable metrics about "effective" process memory
- consumption.
- It usually requires higher privileges and is considerably slower than
- :meth:`memory_info`.
+ This method returns the same information as :meth:`memory_info`, plus, on
+ some platform (Linux, OSX, Windows), also provides additional metrics
+ (USS, PSS and swap).
+ The additional metrics provide a better representation of "effective"
+ process memory consumption (in case of USS).
+ It does so by passing through the whole process address.
+ As such it usually requires higher user privileges than
+ :meth:`memory_info` and is considerably slower.
- - **uss**: 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.
+ - **uss**: (Linux, OSX, Windows) 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.
- **pss**: (Linux) aka "Proportional Set Size", is the amount of memory
shared with other processes, accounted in a way that the amount is
@@ -1121,8 +1123,8 @@ Process class
>>> import psutil
>>> p = psutil.Process()
- >>> p.memory_addrspace_info()
- paddrspmem(uss=7421952, pss=7681024, swap=0)
+ >>> p.memory_full_info()
+ pfullmem(rss=10199040, vms=52133888, shared=3887104, text=2867200, lib=0, data=5967872, dirty=0, uss=6545408, pss=6872064, swap=0)
>>>
See also `scripts/procsmem.py <https://github.com/giampaolo/psutil/blob/master/scripts/procsmem.py>`__
@@ -1130,15 +1132,13 @@ Process class
.. versionadded:: 4.0.0
- Availability: Linux, OSX, Windows
-
.. method:: memory_percent(memtype="rss")
Compare process memory to total physical system memory and calculate
process memory utilization as a percentage.
*memtype* argument is a string that dictates what type of process memory
you want to compare against. You can choose between the namedtuple field
- names returned by :meth:`memory_info` and :meth:`memory_addrspace_info`
+ names returned by :meth:`memory_info` and :meth:`memory_full_info`
(defaults to ``"rss"``).
.. versionchanged:: 4.0.0 added `memtype` parameter.
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 297ef5cd..1e3b43f2 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -980,17 +980,21 @@ class Process(object):
def memory_info_ex(self):
return self.memory_info()
- if hasattr(_psplatform.Process, "memory_addrspace_info"):
-
- def memory_addrspace_info(self):
- """This method passes through the whole process address space
- in order to calculate highly reliable metrics about "effective"
- process memory consumption (USS and PSS).
-
- It usually requires higher privileges and is considerably
- slower than memory_info().
- """
- return self._proc.memory_addrspace_info()
+ def memory_full_info(self):
+ """This method returns the same information as memory_info(),
+ plus, on some platform (Linux, OSX, Windows), also provides
+ additional metrics (USS, PSS and swap).
+ The additional metrics provide a better representation of actual
+ process memory usage.
+
+ Namely USS is the memory which is unique to a process and which
+ would be freed if the process was terminated right now.
+
+ It does so by passing through the whole process address.
+ As such it usually requires higher user privileges than
+ memory_info() and is considerably slower.
+ """
+ return self._proc.memory_full_info()
def memory_percent(self, memtype="rss"):
"""Compare process memory to total physical system memory and
@@ -1003,13 +1007,13 @@ class Process(object):
('rss', 'vms', 'shared', 'text', 'lib', 'data', 'dirty', 'uss', 'pss')
"""
if memtype in ('uss', 'pss', 'swap'):
- if not hasattr(self, "memory_addrspace_info"):
+ if not hasattr(self, "memory_full_info"):
fields = _psplatform.pmem._fields
raise ValueError(
"invalid memtype %r; valid types are %r" % (
memtype, fields))
- fun = self.memory_addrspace_info
- fields = _psplatform.paddrspmem._fields
+ fun = self.memory_full_info
+ fields = _psplatform.pfullmem._fields
else:
fields = _psplatform.pmem._fields
fun = self.memory_info
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 5dd57207..882cfac8 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -238,7 +238,7 @@ sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
'busy_time'])
pmem = namedtuple('pmem', 'rss vms shared text lib data dirty')
-paddrspmem = namedtuple('paddrspmem', ['uss', 'pss', 'swap'])
+pfullmem = namedtuple('pfullmem', pmem._fields + ('uss', 'pss', 'swap'))
pmmap_grouped = namedtuple(
'pmmap_grouped', ['path', 'rss', 'size', 'pss', 'shared_clean',
@@ -1024,19 +1024,12 @@ class Process(object):
if HAS_SMAPS:
@wrap_exceptions
- def memory_addrspace_info(
+ def memory_full_info(
self,
_private_re=re.compile(b"Private.*:\s+(\d+)"),
_pss_re=re.compile(b"Pss.*:\s+(\d+)"),
_swap_re=re.compile(b"Swap.*:\s+(\d+)")):
- # You might be tempted to calculate USS by subtracting
- # the "shared" value from the "resident" value in
- # /proc/<pid>/statm. But at least on Linux, statm's "shared"
- # value actually counts pages backed by files, which has
- # little to do with whether the pages are actually shared.
- # /proc/self/smaps on the other hand appears to give us the
- # correct information.
-
+ basic_mem = self.memory_info()
# Note: using 3 regexes is faster than reading the file
# line by line.
# XXX: on Python 3 the 2 regexes are 30% slower than on
@@ -1044,10 +1037,22 @@ class Process(object):
with open_binary("%s/%s/smaps" % (self._procfs_path, self.pid),
buffering=BIGGER_FILE_BUFFERING) as f:
smaps_data = f.read()
+ # You might be tempted to calculate USS by subtracting
+ # the "shared" value from the "resident" value in
+ # /proc/<pid>/statm. But at least on Linux, statm's "shared"
+ # value actually counts pages backed by files, which has
+ # little to do with whether the pages are actually shared.
+ # /proc/self/smaps on the other hand appears to give us the
+ # correct information.
uss = sum(map(int, _private_re.findall(smaps_data))) * 1024
pss = sum(map(int, _pss_re.findall(smaps_data))) * 1024
swap = sum(map(int, _swap_re.findall(smaps_data))) * 1024
- return paddrspmem(uss, pss, swap)
+ return pfullmem(*basic_mem + (uss, pss, swap))
+
+ else:
+ memory_full_info = memory_info
+
+ if HAS_SMAPS:
@wrap_exceptions
def memory_maps(self):
diff --git a/psutil/_psosx.py b/psutil/_psosx.py
index 113d5f32..5f39589c 100644
--- a/psutil/_psosx.py
+++ b/psutil/_psosx.py
@@ -59,7 +59,7 @@ svmem = namedtuple(
'active', 'inactive', 'wired'])
pmem = namedtuple('pmem', ['rss', 'vms', 'pfaults', 'pageins'])
-paddrspmem = namedtuple('paddrspmem', 'uss')
+pfullmem = namedtuple('pfullmem', pmem._fields + ('uss', ))
pmmap_grouped = namedtuple(
'pmmap_grouped',
@@ -274,9 +274,10 @@ class Process(object):
return pmem(rss, vms, pfaults, pageins)
@wrap_exceptions
- def memory_addrspace_info(self):
+ def memory_full_info(self):
+ basic_mem = self.memory_info()
uss = cext.proc_memory_uss(self.pid)
- return paddrspmem(uss)
+ return pfullmem(*basic_mem + (uss, ))
@wrap_exceptions
def cpu_times(self):
diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py
index 41ebdbb8..bcaeb78b 100644
--- a/psutil/_pssunos.py
+++ b/psutil/_pssunos.py
@@ -407,6 +407,8 @@ class Process(object):
rss, vms = ret[1] * 1024, ret[2] * 1024
return _common.pmem(rss, vms)
+ memory_full_info = memory_info
+
@wrap_exceptions
def status(self):
code = cext.proc_basic_info(self.pid, self._procfs_path)[6]
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index fa581c8b..92472576 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -89,7 +89,7 @@ pmem = namedtuple(
'num_page_faults', 'peak_wset', 'wset', 'peak_paged_pool',
'paged_pool', 'peak_nonpaged_pool', 'nonpaged_pool',
'pagefile', 'peak_pagefile', 'private'])
-paddrspmem = namedtuple('paddrspmem', 'uss')
+pfullmem = namedtuple('pfullmem', pmem._fields + ('uss', ))
pmmap_grouped = namedtuple('pmmap_grouped', ['path', 'rss'])
pmmap_ext = namedtuple(
'pmmap_ext', 'addr perms ' + ' '.join(pmmap_grouped._fields))
@@ -372,9 +372,10 @@ class Process(object):
return pmem(*(rss, vms, ) + t)
@wrap_exceptions
- def memory_addrspace_info(self):
+ def memory_full_info(self):
+ basic_mem = self.memory_info()
uss = cext.proc_memory_uss(self.pid)
- return paddrspmem(uss)
+ return pfullmem(*basic_mem + (uss, ))
def memory_maps(self):
try:
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index c14c59e4..44c09862 100644
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -720,7 +720,7 @@ class TestProcess(unittest.TestCase):
# test only rwx chars, ignore 's' and 'p'
self.assertEqual(mode[:3], this.perms[:3])
- def test_memory_addrspace_info(self):
+ def test_memory_full_info(self):
src = textwrap.dedent("""
import time
with open("%s", "w") as f:
@@ -731,7 +731,7 @@ class TestProcess(unittest.TestCase):
call_until(lambda: os.listdir('.'), "'%s' not in ret" % TESTFN)
p = psutil.Process(sproc.pid)
time.sleep(.1)
- mem = p.memory_addrspace_info()
+ 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]))
diff --git a/psutil/tests/test_memory_leaks.py b/psutil/tests/test_memory_leaks.py
index 9167742b..397cc481 100644
--- a/psutil/tests/test_memory_leaks.py
+++ b/psutil/tests/test_memory_leaks.py
@@ -228,8 +228,8 @@ class TestProcessObjectLeaks(Base):
# also available on Linux but it's pure python
@unittest.skipUnless(OSX or WINDOWS,
"not available on this platform")
- def test_memory_addrspace_info(self):
- self.execute('memory_addrspace_info')
+ def test_memory_full_info(self):
+ self.execute('memory_full_info')
@unittest.skipUnless(POSIX, "POSIX only")
@skip_if_linux()
diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py
index 507abf94..1257a1ef 100644
--- a/psutil/tests/test_misc.py
+++ b/psutil/tests/test_misc.py
@@ -392,8 +392,8 @@ class TestScripts(unittest.TestCase):
def test_pmap(self):
self.assert_stdout('pmap.py', args=str(os.getpid()))
- @unittest.skipUnless(hasattr(psutil.Process, "memory_addrspace_info"),
- "memory_addrspace_info() not supported")
+ @unittest.skipUnless(hasattr(psutil.Process, "memory_full_info"),
+ "memory_full_info() not supported")
def test_procsmem(self):
self.assert_stdout('procsmem.py')
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index 42ad59ea..f84dbda5 100644
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -588,8 +588,8 @@ class TestProcess(unittest.TestCase):
@unittest.skipUnless(LINUX or OSX or WINDOWS,
"not available on this platform")
- def test_memory_addrspace_info(self):
- mem = psutil.Process().memory_addrspace_info()
+ def test_memory_full_info(self):
+ mem = psutil.Process().memory_full_info()
self.assertGreater(mem.uss, 0)
if LINUX:
self.assertGreater(mem.pss, 0)
@@ -1669,7 +1669,7 @@ class TestFetchAllProcesses(unittest.TestCase):
assert ret.peak_nonpaged_pool >= ret.nonpaged_pool, ret
assert ret.peak_pagefile >= ret.pagefile, ret
- def memory_addrspace_info(self, ret, proc):
+ def memory_full_info(self, ret, proc):
for name in ret._fields:
self.assertGreaterEqual(getattr(ret, name), 0)
if LINUX:
diff --git a/scripts/procsmem.py b/scripts/procsmem.py
index e6b079ec..5236f4f7 100755
--- a/scripts/procsmem.py
+++ b/scripts/procsmem.py
@@ -41,7 +41,7 @@ import sys
import psutil
-if not hasattr(psutil.Process, "memory_addrspace_info"):
+if not psutil.LINUX or psutil.OSX or psutil.WINDOWS:
sys.exit("platform not supported")
@@ -62,18 +62,19 @@ def main():
procs = []
for p in psutil.process_iter():
try:
- mem_addrspace = p.memory_addrspace_info()
- info = p.as_dict(attrs=["cmdline", "username", "memory_info"])
+ mem = p.memory_full_info()
+ info = p.as_dict(attrs=["cmdline", "username"])
except psutil.AccessDenied:
ad_pids.append(p.pid)
except psutil.NoSuchProcess:
pass
else:
- p._uss = mem_addrspace.uss
+ p._uss = mem.uss
+ p._rss = mem.rss
if not p._uss:
continue
- p._pss = getattr(mem_addrspace, "pss", "")
- p._swap = getattr(mem_addrspace, "swap", "")
+ p._pss = getattr(mem, "pss", "")
+ p._swap = getattr(mem, "swap", "")
p._info = info
procs.append(p)
@@ -89,7 +90,7 @@ def main():
convert_bytes(p._uss),
convert_bytes(p._pss) if p._pss != "" else "",
convert_bytes(p._swap) if p._swap != "" else "",
- convert_bytes(p._info['memory_info'].rss),
+ convert_bytes(p._rss),
)
print(line)
if ad_pids: