diff options
author | Daniel Lange <DLange@git.local> | 2016-04-11 13:01:07 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:01:07 +0200 |
commit | ff9409b1737627857eb47f64f536a3f66b6a09a4 (patch) | |
tree | 61b631ba551e68a4f656b8b76ff7bd0d9955fc64 /MemoryMeter.c | |
parent | f75ab6d2c11e8a8e18191b087564aedebbeb96c5 (diff) | |
download | debian_htop-ff9409b1737627857eb47f64f536a3f66b6a09a4.tar.gz debian_htop-ff9409b1737627857eb47f64f536a3f66b6a09a4.tar.bz2 debian_htop-ff9409b1737627857eb47f64f536a3f66b6a09a4.zip |
Imported Upstream version 2.0.0upstream/2.0.0
Diffstat (limited to 'MemoryMeter.c')
-rw-r--r-- | MemoryMeter.c | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/MemoryMeter.c b/MemoryMeter.c index 0151625..dae56b5 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -8,7 +8,7 @@ in the source distribution for its full text. #include "MemoryMeter.h" #include "CRT.h" -#include "ProcessList.h" +#include "Platform.h" #include <stdlib.h> #include <string.h> @@ -25,36 +25,32 @@ int MemoryMeter_attributes[] = { }; static void MemoryMeter_setValues(Meter* this, char* buffer, int size) { - long int usedMem = this->pl->usedMem; - long int buffersMem = this->pl->buffersMem; - long int cachedMem = this->pl->cachedMem; - usedMem -= buffersMem + cachedMem; - this->total = this->pl->totalMem; - this->values[0] = usedMem; - this->values[1] = buffersMem; - this->values[2] = cachedMem; - snprintf(buffer, size, "%ld/%ldMB", (long int) usedMem / 1024, (long int) this->total / 1024); + int written; + Platform_setMemoryValues(this); + + written = Meter_humanUnit(buffer, this->values[0], size); + buffer += written; + if ((size -= written) > 0) { + *buffer++ = '/'; + size--; + Meter_humanUnit(buffer, this->total, size); + } } static void MemoryMeter_display(Object* cast, RichString* out) { char buffer[50]; Meter* this = (Meter*)cast; - int k = 1024; const char* format = "%ldM "; - long int totalMem = this->total / k; - long int usedMem = this->values[0] / k; - long int buffersMem = this->values[1] / k; - long int cachedMem = this->values[2] / k; RichString_write(out, CRT_colors[METER_TEXT], ":"); - sprintf(buffer, format, totalMem); + Meter_humanUnit(buffer, this->total, 50); RichString_append(out, CRT_colors[METER_VALUE], buffer); - sprintf(buffer, format, usedMem); - RichString_append(out, CRT_colors[METER_TEXT], "used:"); + Meter_humanUnit(buffer, this->values[0], 50); + RichString_append(out, CRT_colors[METER_TEXT], " used:"); RichString_append(out, CRT_colors[MEMORY_USED], buffer); - sprintf(buffer, format, buffersMem); - RichString_append(out, CRT_colors[METER_TEXT], "buffers:"); + Meter_humanUnit(buffer, this->values[1], 50); + RichString_append(out, CRT_colors[METER_TEXT], " buffers:"); RichString_append(out, CRT_colors[MEMORY_BUFFERS_TEXT], buffer); - sprintf(buffer, format, cachedMem); - RichString_append(out, CRT_colors[METER_TEXT], "cache:"); + Meter_humanUnit(buffer, this->values[2], 50); + RichString_append(out, CRT_colors[METER_TEXT], " cache:"); RichString_append(out, CRT_colors[MEMORY_CACHE], buffer); } @@ -69,7 +65,7 @@ MeterClass MemoryMeter_class = { .maxItems = 3, .total = 100.0, .attributes = MemoryMeter_attributes, - "Memory", - "Memory", - "Mem" + .name = "Memory", + .uiName = "Memory", + .caption = "Mem" }; |