diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-01-24 17:53:38 +0000 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-01-24 17:53:38 +0000 |
commit | 52396c8008ce0d7ad6f8e83952b215ccad81ea8f (patch) | |
tree | cd1adc6ca47ff067b4e64420406e447521068635 | |
parent | 0e79c6370c19e93330a74e843cc93844f841964a (diff) | |
download | psutil-52396c8008ce0d7ad6f8e83952b215ccad81ea8f.tar.gz |
fix #788: [NetBSD] virtual_memory()'s buffers and shared values were set to 0.
-rw-r--r-- | HISTORY.rst | 1 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | psutil/_psbsd.py | 9 | ||||
-rw-r--r-- | psutil/tests/test_bsd.py | 24 |
4 files changed, 34 insertions, 2 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index 84faf32b..b8bdec10 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -18,6 +18,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues (patch by wxwright) - #780: [OSX] psutil does not compile with some gcc versions. - #786: net_if_addrs() may report incomplete MAC addresses. +- #788: [NetBSD] virtual_memory()'s buffers and shared values were set to 0. 4.0.0 - 2016-02-17 @@ -82,7 +82,7 @@ test-by-name: install # Run specific platform tests only. test-platform: install - $(PYTHON) psutil/tests/test_`$(PYTHON) -c 'import psutil; print([x.lower() for x in ("FREEBSD", "LINUX", "NETBSD", "OPENBSD", "OSX", "SUNOS", "WINDOWS") if getattr(psutil, x)][0])'`.py + $(PYTHON) psutil/tests/test_`$(PYTHON) -c 'import psutil; print([x.lower() for x in ("LINUX", "BSD", "OSX", "SUNOS", "WINDOWS") if getattr(psutil, x)][0])'`.py # Same as above but for test_memory_leaks.py script. test-memleaks-by-name: install diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index d628f3f7..4af3bc8e 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -126,6 +126,15 @@ def virtual_memory(): """System virtual memory as a namedtuple.""" mem = cext.virtual_mem() total, free, active, inactive, wired, cached, buffers, shared = mem + if NETBSD: + # On NetBSD buffers and shared mem is determined via /proc. + # The C ext set them to 0. + with open('/proc/meminfo', 'rb') as f: + for line in f: + if line.startswith("Buffers:"): + buffers = int(line.split()[1]) * 1024 + elif line.startswith("MemShared:"): + shared = int(line.split()[1]) * 1024 avail = inactive + cached + free used = active + wired + cached percent = usage_percent((total - avail), total, _round=1) diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py index b77640cf..fd330b4d 100644 --- a/psutil/tests/test_bsd.py +++ b/psutil/tests/test_bsd.py @@ -286,7 +286,6 @@ class FreeBSDSpecificTestCase(unittest.TestCase): # --- OpenBSD # ===================================================================== - @unittest.skipUnless(OPENBSD, "not an OpenBSD system") class OpenBSDSpecificTestCase(unittest.TestCase): @@ -297,5 +296,28 @@ class OpenBSDSpecificTestCase(unittest.TestCase): self.assertEqual(sys_bt, psutil_bt) +# ===================================================================== +# --- NetBSD +# ===================================================================== + +@unittest.skipUnless(NETBSD, "not a NetBSD system") +class NetBSDSpecificTestCase(unittest.TestCase): + + def parse_meminfo(self, look_for): + with open('/proc/meminfo', 'rb') as f: + for line in f: + if line.startswith(look_for): + return int(line.split()[1]) * 1024 + raise ValueError("can't find %s" % look_for) + + def test_vmem_buffers(self): + self.assertEqual( + psutil.virtual_memory().buffers, self.parse_meminfo("Buffers:")) + + def test_vmem_shared(self): + self.assertEqual( + psutil.virtual_memory().shared, self.parse_meminfo("MemShared:")) + + if __name__ == '__main__': run_test_module_by_name(__file__) |