summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-09-20 15:17:16 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-09-20 15:17:16 +0200
commit340d5bc2e3fe85d46602c7b12695bcf9eb0a2427 (patch)
treecd71c0b11689adf37fc48743f3ef6737b85a0397
parent8504d930cb68e1e079e03df55112312505ed260f (diff)
parent1e707020f116627d5e3d060164c32b56257a1938 (diff)
downloadpsutil-340d5bc2e3fe85d46602c7b12695bcf9eb0a2427.tar.gz
merge
-rw-r--r--HISTORY.rst5
-rw-r--r--docs/index.rst8
-rw-r--r--psutil/__init__.py2
-rw-r--r--psutil/tests/test_linux.py60
4 files changed, 26 insertions, 49 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 34a34165..b5775bfd 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,7 +1,7 @@
Bug tracker at https://github.com/giampaolo/psutil/issues
-4.4.0 - XXXX-XX-XX
+4.3.2 - XXXX-XX-XX
==================
**Bug fixes**
@@ -10,9 +10,6 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
- #880: [Windows] Handle race condition inside psutil_net_connections.
- #885: ValueError is raised if a negative integer is passed to cpu_percent()
functions.
-- #887: [Linux] free, available and used fields are more precise and match
- "free" cmdline utility. It also takes into account LCX containers preventing
- "avail" to overflow "total".
4.3.1 - 2016-09-01
diff --git a/docs/index.rst b/docs/index.rst
index 675c028b..e0d145b9 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -172,8 +172,7 @@ Memory
.. function:: virtual_memory()
Return statistics about system memory usage as a namedtuple including the
- following fields, expressed in bytes.
- Main metrics:
+ following fields, expressed in bytes. Main metrics:
- **total**: total physical memory.
- **available**: the memory that can be given instantly to processes without
@@ -181,8 +180,6 @@ Memory
This is calculated by summing different memory values depending on the
platform and it is supposed to be used to monitor actual memory usage in a
cross platform fashion.
- - **percent**: the percentage usage calculated as
- ``(total - available) / total * 100``.
Other metrics:
@@ -224,9 +221,6 @@ Memory
.. versionchanged:: 4.2.0 added *shared* metrics on Linux.
- .. versionchanged:: 4.4.0 on Linux, *free*, *available* and *used* fields
- are more precise and match "free" cmdline utility.
-
.. function:: swap_memory()
Return system swap memory statistics as a namedtuple including the following
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 020a0bdd..0a6f3ec6 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -187,7 +187,7 @@ __all__ = [
]
__all__.extend(_psplatform.__extra__all__)
__author__ = "Giampaolo Rodola'"
-__version__ = "4.4.0"
+__version__ = "4.3.2"
version_info = tuple([int(num) for num in __version__.split('.')])
AF_LINK = _psplatform.AF_LINK
_TOTAL_PHYMEM = None
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index a6b5d3f3..9f7c25fb 100644
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -117,9 +117,8 @@ def free_physmem():
if line.startswith('Mem'):
total, used, free, shared = \
[int(x) for x in line.split()[1:5]]
- nt = collections.namedtuple(
- 'free', 'total used free shared output')
- return nt(total, used, free, shared, out)
+ nt = collections.namedtuple('free', 'total used free shared')
+ return nt(total, used, free, shared)
raise ValueError(
"can't find 'Mem' in 'free' output:\n%s" % '\n'.join(lines))
@@ -133,11 +132,6 @@ def vmstat(stat):
raise ValueError("can't find %r in 'vmstat' output" % stat)
-def get_free_version_info():
- out = sh("free -V").strip()
- return tuple(map(int, out.split()[-1].split('.')))
-
-
# =====================================================================
# system virtual memory
# =====================================================================
@@ -154,20 +148,12 @@ class TestSystemVirtualMemory(unittest.TestCase):
psutil_value = psutil.virtual_memory().total
self.assertAlmostEqual(vmstat_value, psutil_value)
- # Older versions of procps used slab memory to calculate used memory.
- # This got changed in:
- # https://gitlab.com/procps-ng/procps/commit/
- # 05d751c4f076a2f0118b914c5e51cfbb4762ad8e
- @unittest.skipUnless(
- LINUX and get_free_version_info() >= (3, 3, 12), "old free version")
@retry_before_failing()
def test_used(self):
- free = free_physmem()
- free_value = free.used
+ free_value = free_physmem().used
psutil_value = psutil.virtual_memory().used
self.assertAlmostEqual(
- free_value, psutil_value, delta=MEMORY_TOLERANCE,
- msg='%s %s \n%s' % (free_value, psutil_value, free.output))
+ free_value, psutil_value, delta=MEMORY_TOLERANCE)
@retry_before_failing()
def test_free(self):
@@ -202,30 +188,31 @@ class TestSystemVirtualMemory(unittest.TestCase):
vmstat_value, psutil_value, delta=MEMORY_TOLERANCE)
@retry_before_failing()
+ @unittest.skipIf(TRAVIS, "fails on travis")
def test_shared(self):
- free = free_physmem()
- free_value = free.shared
+ free_value = free_physmem().shared
if free_value == 0:
raise unittest.SkipTest("free does not support 'shared' column")
psutil_value = psutil.virtual_memory().shared
self.assertAlmostEqual(
- free_value, psutil_value, delta=MEMORY_TOLERANCE,
- msg='%s %s \n%s' % (free_value, psutil_value, free.output))
+ free_value, psutil_value, delta=MEMORY_TOLERANCE)
- @retry_before_failing()
- def test_available(self):
- # "free" output format has changed at some point:
- # https://github.com/giampaolo/psutil/issues/538#issuecomment-147192098
- out = sh("free -b")
- lines = out.split('\n')
- if 'available' not in lines[0]:
- raise unittest.SkipTest("free does not support 'available' column")
- else:
- free_value = int(lines[1].split()[-1])
- psutil_value = psutil.virtual_memory().available
- self.assertAlmostEqual(
- free_value, psutil_value, delta=MEMORY_TOLERANCE,
- msg='%s %s \n%s' % (free_value, psutil_value, out))
+ # --- mocked tests
+
+ def test_warnings_mocked(self):
+ with mock.patch('psutil._pslinux.open', create=True) as m:
+ with warnings.catch_warnings(record=True) as ws:
+ warnings.simplefilter("always")
+ ret = psutil._pslinux.virtual_memory()
+ assert m.called
+ self.assertEqual(len(ws), 1)
+ w = ws[0]
+ self.assertTrue(w.filename.endswith('psutil/_pslinux.py'))
+ self.assertIn(
+ "memory stats couldn't be determined", str(w.message))
+ self.assertEqual(ret.cached, 0)
+ self.assertEqual(ret.active, 0)
+ self.assertEqual(ret.inactive, 0)
# =====================================================================
@@ -383,7 +370,6 @@ class TestSystemCPU(unittest.TestCase):
@unittest.skipUnless(LINUX, "not a Linux system")
class TestSystemCPUStats(unittest.TestCase):
- @unittest.skipIf(TRAVIS, "fails on Travis")
def test_ctx_switches(self):
vmstat_value = vmstat("context switches")
psutil_value = psutil.cpu_stats().ctx_switches