aboutsummaryrefslogtreecommitdiffstats
path: root/DiskIOMeter.c
diff options
context:
space:
mode:
Diffstat (limited to 'DiskIOMeter.c')
-rw-r--r--DiskIOMeter.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/DiskIOMeter.c b/DiskIOMeter.c
index 04ca5a7..67122a1 100644
--- a/DiskIOMeter.c
+++ b/DiskIOMeter.c
@@ -9,12 +9,12 @@ in the source distribution for its full text.
#include <stdbool.h>
#include <stdio.h>
-#include <sys/time.h>
#include "CRT.h"
#include "Macros.h"
#include "Object.h"
#include "Platform.h"
+#include "ProcessList.h"
#include "RichString.h"
#include "XUtils.h"
@@ -26,51 +26,55 @@ static const int DiskIOMeter_attributes[] = {
};
static bool hasData = false;
-static unsigned long int cached_read_diff = 0;
-static unsigned long int cached_write_diff = 0;
-static double cached_utilisation_diff = 0.0;
+static uint32_t cached_read_diff;
+static uint32_t cached_write_diff;
+static double cached_utilisation_diff;
-static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
- static unsigned long long int cached_last_update = 0;
+static void DiskIOMeter_updateValues(Meter* this) {
+ const ProcessList* pl = this->pl;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- unsigned long long int timeInMilliSeconds = (unsigned long long int)tv.tv_sec * 1000 + (unsigned long long int)tv.tv_usec / 1000;
- unsigned long long int passedTimeInMs = timeInMilliSeconds - cached_last_update;
+ static uint64_t cached_last_update;
+ uint64_t passedTimeInMs = pl->realtimeMs - cached_last_update;
/* update only every 500ms */
if (passedTimeInMs > 500) {
- static unsigned long int cached_read_total = 0;
- static unsigned long int cached_write_total = 0;
- static unsigned long int cached_msTimeSpend_total = 0;
+ static uint64_t cached_read_total;
+ static uint64_t cached_write_total;
+ static uint64_t cached_msTimeSpend_total;
+ uint64_t diff;
- cached_last_update = timeInMilliSeconds;
+ cached_last_update = pl->realtimeMs;
DiskIOData data;
hasData = Platform_getDiskIO(&data);
if (!hasData) {
this->values[0] = 0;
- xSnprintf(buffer, len, "no data");
+ xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "no data");
return;
}
if (data.totalBytesRead > cached_read_total) {
- cached_read_diff = (data.totalBytesRead - cached_read_total) / 1024; /* Meter_humanUnit() expects unit in kilo */
+ diff = data.totalBytesRead - cached_read_total;
+ diff /= 1024; /* Meter_humanUnit() expects unit in kilo */
+ cached_read_diff = (uint32_t)diff;
} else {
cached_read_diff = 0;
}
cached_read_total = data.totalBytesRead;
if (data.totalBytesWritten > cached_write_total) {
- cached_write_diff = (data.totalBytesWritten - cached_write_total) / 1024; /* Meter_humanUnit() expects unit in kilo */
+ diff = data.totalBytesWritten - cached_write_total;
+ diff /= 1024; /* Meter_humanUnit() expects unit in kilo */
+ cached_write_diff = (uint32_t)diff;
} else {
cached_write_diff = 0;
}
cached_write_total = data.totalBytesWritten;
if (data.totalMsTimeSpend > cached_msTimeSpend_total) {
- cached_utilisation_diff = 100 * (double)(data.totalMsTimeSpend - cached_msTimeSpend_total) / passedTimeInMs;
+ diff = data.totalMsTimeSpend - cached_msTimeSpend_total;
+ cached_utilisation_diff = 100.0 * (double)diff / passedTimeInMs;
} else {
cached_utilisation_diff = 0.0;
}
@@ -83,20 +87,21 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
char bufferRead[12], bufferWrite[12];
Meter_humanUnit(bufferRead, cached_read_diff, sizeof(bufferRead));
Meter_humanUnit(bufferWrite, cached_write_diff, sizeof(bufferWrite));
- snprintf(buffer, len, "%sB %sB %.1f%%", bufferRead, bufferWrite, cached_utilisation_diff);
+ snprintf(this->txtBuffer, sizeof(this->txtBuffer), "%sB %sB %.1f%%", bufferRead, bufferWrite, cached_utilisation_diff);
}
-static void DIskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
+static void DiskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
if (!hasData) {
RichString_writeAscii(out, CRT_colors[METER_VALUE_ERROR], "no data");
return;
}
char buffer[16];
+ int len;
int color = cached_utilisation_diff > 40.0 ? METER_VALUE_NOTICE : METER_VALUE;
- xSnprintf(buffer, sizeof(buffer), "%.1f%%", cached_utilisation_diff);
- RichString_writeAscii(out, CRT_colors[color], buffer);
+ len = xSnprintf(buffer, sizeof(buffer), "%.1f%%", cached_utilisation_diff);
+ RichString_appendnAscii(out, CRT_colors[color], buffer, len);
RichString_appendAscii(out, CRT_colors[METER_TEXT], " read: ");
Meter_humanUnit(buffer, cached_read_diff, sizeof(buffer));
@@ -111,7 +116,7 @@ const MeterClass DiskIOMeter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete,
- .display = DIskIOMeter_display
+ .display = DiskIOMeter_display
},
.updateValues = DiskIOMeter_updateValues,
.defaultMode = TEXT_METERMODE,

© 2014-2024 Faster IT GmbH | imprint | privacy policy