From b77fee4af2fe9d9e39cb446a80cc2727f62252f6 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 12 Feb 2018 20:10:50 +0100 Subject: [PATCH] [modules/memory] Fix "percentage used" calculation For some reason, using "used/total" is more accurate than "(total - free)/total". Probably there's some missing gap of what is counted as used vs. what is counted as free. fixes #229 --- bumblebee/modules/memory.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bumblebee/modules/memory.py b/bumblebee/modules/memory.py index 752a8a0..9df990f 100644 --- a/bumblebee/modules/memory.py +++ b/bumblebee/modules/memory.py @@ -50,12 +50,13 @@ class Module(bumblebee.engine.Module): if tmp[2] == "mB": value = value*1024*1024 if tmp[2] == "gB": value = value*1024*1024*1024 data[tmp[0]] = value + used = data["MemTotal"] - data["MemFree"] - data["Buffers"] - data["Cached"] - data["Slab"] self._mem = { "total": bumblebee.util.bytefmt(data["MemTotal"]), "available": bumblebee.util.bytefmt(data["MemAvailable"]), "free": bumblebee.util.bytefmt(data["MemFree"]), - "used": bumblebee.util.bytefmt(data["MemTotal"] - data["MemFree"] - data["Buffers"] - data["Cached"] - data["Slab"]), - "percent": (float(data["MemTotal"] - data["MemAvailable"])/data["MemTotal"])*100 + "used": bumblebee.util.bytefmt(used), + "percent": float(used)/float(data["MemTotal"])*100.0 } def state(self, widget):