summaryrefslogtreecommitdiffstats
path: root/DiskIOMeter.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-20 21:40:51 +0200
committercgzones <cgzones@googlemail.com>2020-10-26 19:17:14 +0100
commitf757810f489b12d2a98dcb09751003f4ed002538 (patch)
tree4558520309803981d20d8c0aa6ab100211d9bd48 /DiskIOMeter.c
parent167adc0a2b4a940cae6c9eb71f3185b5d2d3b4fa (diff)
Improve handling of no data in Disk and Network IO Meters
Diffstat (limited to 'DiskIOMeter.c')
-rw-r--r--DiskIOMeter.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/DiskIOMeter.c b/DiskIOMeter.c
index 432ba6f0..9f311653 100644
--- a/DiskIOMeter.c
+++ b/DiskIOMeter.c
@@ -24,6 +24,7 @@ static const int DiskIOMeter_attributes[] = {
METER_VALUE_IOWRITE,
};
+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;
@@ -37,12 +38,20 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) {
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;
/* update only every 500ms */
- if (timeInMilliSeconds - cached_last_update > 500) {
+ if (passedTimeInMs > 500) {
+ cached_last_update = timeInMilliSeconds;
+
unsigned long int bytesRead, bytesWrite, msTimeSpend;
- Platform_getDiskIO(&bytesRead, &bytesWrite, &msTimeSpend);
+ hasData = Platform_getDiskIO(&bytesRead, &bytesWrite, &msTimeSpend);
+ if (!hasData) {
+ this->values[0] = 0;
+ xSnprintf(buffer, len, "no data");
+ return;
+ }
cached_read_diff = (bytesRead - cached_read_total) / 1024; /* Meter_humanUnit() expects unit in kilo */
cached_read_total = bytesRead;
@@ -50,8 +59,7 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) {
cached_write_diff = (bytesWrite - cached_write_total) / 1024; /* Meter_humanUnit() expects unit in kilo */
cached_write_total = bytesWrite;
- cached_utilisation_diff = 100 * (double)(msTimeSpend - cached_msTimeSpend_total) / (timeInMilliSeconds - cached_last_update);
- cached_last_update = timeInMilliSeconds;
+ cached_utilisation_diff = 100 * (double)(msTimeSpend - cached_msTimeSpend_total) / passedTimeInMs;
cached_msTimeSpend_total = msTimeSpend;
}
@@ -65,6 +73,11 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) {
}
static void DIskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
+ if (!hasData) {
+ RichString_write(out, CRT_colors[METER_VALUE_ERROR], "no data");
+ return;
+ }
+
char buffer[16];
int color = cached_utilisation_diff > 40.0 ? METER_VALUE_NOTICE : METER_VALUE;

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