diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-02-15 17:48:29 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-02-15 17:48:29 +0100 |
commit | 50fd31a4eaca3e24905b96d587fd08bcf313fc6b (patch) | |
tree | 87e33b156ec7263e516e5535aa4b4c5c34bf79ba | |
parent | a99bbba73e03d5961b1fcbc38996a2e580b11faf (diff) | |
download | psutil-50fd31a4eaca3e24905b96d587fd08bcf313fc6b.tar.gz |
#685 / linux / mem funcs: return original C types and use the multiplier in python in order to avoid C typing issues
-rw-r--r-- | psutil/_pslinux.py | 12 | ||||
-rw-r--r-- | psutil/_psutil_linux.c | 16 |
2 files changed, 19 insertions, 9 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index d82cb680..d48dd5ed 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -252,7 +252,12 @@ pmmap_ext = namedtuple( # --- system memory def virtual_memory(): - total, free, buffers, shared, _, _ = cext.linux_sysinfo() + total, free, buffers, shared, _, _, unit_multiplier = cext.linux_sysinfo() + total *= unit_multiplier + free *= unit_multiplier + buffers *= unit_multiplier + shared *= unit_multiplier + cached = active = inactive = None with open_binary('%s/meminfo' % get_procfs_path()) as f: for line in f: @@ -273,6 +278,7 @@ def virtual_memory(): "be determined and were set to 0" warnings.warn(msg, RuntimeWarning) cached = active = inactive = 0 + avail = free + buffers + cached used = total - free percent = usage_percent((total - avail), total, _round=1) @@ -281,7 +287,9 @@ def virtual_memory(): def swap_memory(): - _, _, _, _, total, free = cext.linux_sysinfo() + _, _, _, _, total, free, unit_multiplier = cext.linux_sysinfo() + total *= unit_multiplier + free *= unit_multiplier used = total - free percent = usage_percent(used, total, _round=1) # get pgin/pgouts diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index 0e90304e..2cf2a7db 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -247,13 +247,15 @@ psutil_linux_sysinfo(PyObject *self, PyObject *args) { return PyErr_SetFromErrno(PyExc_OSError); // note: boot time might also be determined from here return Py_BuildValue( - "(KKKKKK)", - (unsigned long long)info.totalram * info.mem_unit, // total - (unsigned long long)info.freeram * info.mem_unit, // free - (unsigned long long)info.bufferram * info.mem_unit, // buffer - (unsigned long long)info.sharedram * info.mem_unit, // shared - (unsigned long long)info.totalswap * info.mem_unit, // swap tot - (unsigned long long)info.freeswap * info.mem_unit); // swap free + "(kkkkkkI)", + info.totalram, // total + info.freeram, // free + info.bufferram, // buffer + info.sharedram, // shared + info.totalswap, // swap tot + info.freeswap, // swap free + info.mem_unit // multiplier + ); } |