diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-09-18 17:47:51 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-09-18 17:47:51 +0200 |
commit | 559270e5d7d36707995e2ddf99e3b9b80fba9f85 (patch) | |
tree | 9425b4c0a8db924e596edc83feeaac9821e52238 | |
parent | 4b4e8282ea60840f48f0fe797da76d7d5598b9da (diff) | |
download | psutil-559270e5d7d36707995e2ddf99e3b9b80fba9f85.tar.gz |
#887: do not use sysinfo() syscall; use /proc/meminfo to calculate all stats
-rw-r--r-- | psutil/_pslinux.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 1a6a6ba0..88e6a939 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -300,20 +300,16 @@ def virtual_memory(): 16.04 and which should report the same numbers. """ missing_fields = [] - total, free, buffers, shared, _, _, unit_multiplier = cext.linux_sysinfo() - total *= unit_multiplier - free *= unit_multiplier - buffers *= unit_multiplier - # Note: this (on my Ubuntu 14.04, kernel 3.13 at least) may be 0. - # If so, it will be determined from /proc/meminfo. - shared *= unit_multiplier - mems = {} with open_binary('%s/meminfo' % get_procfs_path()) as f: for line in f: fields = line.split() mems[fields[0]] = int(fields[1]) * 1024 + # Note: these info are available also as cext.linux_sysinfo(). + total = mems[b'MemTotal:'] + buffers = mems[b'Buffers:'] + free = mems[b'MemFree:'] cached = mems[b"Cached:"] # "free" cmdline utility sums cached + reclamaible: # https://gitlab.com/procps-ng/procps/ @@ -324,17 +320,16 @@ def virtual_memory(): # 05d751c4f076a2f0118b914c5e51cfbb4762ad8e cached += mems.get(b"SReclaimable:", 0) # kernel 2.6.19 - if shared == 0: - # Note: if 0 (e.g. Ubuntu 14.04, kernel 3.13) this can be - # determined from /proc/meminfo. + # Note: if 0 (e.g. Ubuntu 14.04, kernel 3.13) this can be + # determined from /proc/meminfo. + try: + shared = mems[b'Shmem:'] # since kernel 2.6.32 + except KeyError: try: - shared = mems['Shmem:'] # since kernel 2.6.32 + shared = mems[b'MemShared:'] # kernels 2.4 except KeyError: - try: - shared = mems['MemShared:'] # kernels 2.4 - except KeyError: - shared = 0 - missing_fields.append('shared') + shared = 0 + missing_fields.append('shared') try: active = mems[b"Active:"] |