diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2021-05-03 13:33:26 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2021-05-03 13:33:26 +0200 |
commit | d5e9ea17e5068d89b741a2f9dc8dd22d24b2545a (patch) | |
tree | 7329623349b0f18b647448819f0ee7ec40bf9533 | |
parent | 4d30272e3de81a0c4244143595284e040cfb070f (diff) | |
parent | ea5b2df02e39816c1f6626dd9d93ae7ede422687 (diff) | |
download | psutil-d5e9ea17e5068d89b741a2f9dc8dd22d24b2545a.tar.gz |
Merge branch 'master' of github.com:giampaolo/psutil
-rw-r--r-- | CREDITS | 4 | ||||
-rw-r--r-- | HISTORY.rst | 1 | ||||
-rw-r--r-- | psutil/_pswindows.py | 12 | ||||
-rwxr-xr-x | psutil/tests/test_linux.py | 3 |
4 files changed, 17 insertions, 3 deletions
@@ -740,3 +740,7 @@ I: 1851 N: guille W: https://github.com/guille I: 1913 + +N: David Knaack +W: https://github.com/davidkna +I: 1921 diff --git a/HISTORY.rst b/HISTORY.rst index b42261ab..c826f47b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -22,6 +22,7 @@ XXXX-XX-XX called after sprintf(). (patch by alxchk) - 1874_: [Solaris] swap output error due to incorrect range. - 1913_: [Linux] wait_procs seemingly ignoring timeout, TimeoutExpired thrown +- 1921_: [Windows] psutil.swap_memory() shows committed memory instead of swap 5.8.0 ===== diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index 0ad60c4a..6b1a34de 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -241,8 +241,16 @@ def virtual_memory(): def swap_memory(): """Swap system memory as a (total, used, free, sin, sout) tuple.""" mem = cext.virtual_mem() - total = mem[2] - free = mem[3] + + total_phys = mem[0] + free_phys = mem[1] + total_system = mem[2] + free_system = mem[3] + + # Despite the name PageFile refers to total system memory here + # thus physical memory values need to be substracted to get swap values + total = total_system - total_phys + free = min(total, free_system - free_phys) used = total - free percent = usage_percent(used, total, round_=1) return _common.sswap(total, used, free, percent, 0, 0) diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index 0c6d498c..f5243c2c 100755 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -243,7 +243,8 @@ class TestSystemVirtualMemory(PsutilTestCase): # self.assertEqual(free_value, psutil_value) vmstat_value = vmstat('total memory') * 1024 psutil_value = psutil.virtual_memory().total - self.assertAlmostEqual(vmstat_value, psutil_value) + self.assertAlmostEqual( + vmstat_value, psutil_value, delta=TOLERANCE_SYS_MEM) @retry_on_failure() def test_used(self): |