summaryrefslogtreecommitdiffstats
path: root/DiskIOMeter.c
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2023-11-01 19:20:58 +0800
committerBenBE <BenBE@geshi.org>2023-11-24 09:51:25 +0100
commitf7f6aca39d371a02482a6eb722510360377488f9 (patch)
treeecdd67fc0b0243a2b395296a440102a4d9909720 /DiskIOMeter.c
parent9352e26218c8a445bd3b5f28ac508f88ff4cbdc5 (diff)
Always update 'values' member of DiskIOMeter
Always update the `values` member during the call of DiskIOMeter_updateValues(). This makes the values of every instance of DiskIOMeter consistent. The user might see non-zero bars (or graph) during the "stale" status of the meter after this commit. The side effect is not a bug. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Diffstat (limited to 'DiskIOMeter.c')
-rw-r--r--DiskIOMeter.c81
1 files changed, 44 insertions, 37 deletions
diff --git a/DiskIOMeter.c b/DiskIOMeter.c
index b69fb40b..6662918b 100644
--- a/DiskIOMeter.c
+++ b/DiskIOMeter.c
@@ -36,16 +36,13 @@ static void DiskIOMeter_updateValues(Meter* this) {
static uint64_t cached_last_update;
uint64_t passedTimeInMs = host->realtimeMs - cached_last_update;
+ bool hasNewData = false;
+ DiskIOData data;
/* update only every 500ms to have a sane span for rate calculation */
if (passedTimeInMs > 500) {
- static uint64_t cached_read_total;
- static uint64_t cached_write_total;
- static uint64_t cached_msTimeSpend_total;
- uint64_t diff;
-
- DiskIOData data;
- if (!Platform_getDiskIO(&data)) {
+ hasNewData = Platform_getDiskIO(&data);
+ if (!hasNewData) {
status = RATESTATUS_NODATA;
} else if (cached_last_update == 0) {
status = RATESTATUS_INIT;
@@ -56,42 +53,54 @@ static void DiskIOMeter_updateValues(Meter* this) {
}
cached_last_update = host->realtimeMs;
+ }
- if (status == RATESTATUS_NODATA) {
- xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "no data");
- return;
- }
+ if (hasNewData) {
+ static uint64_t cached_read_total;
+ static uint64_t cached_write_total;
+ static uint64_t cached_msTimeSpend_total;
- if (data.totalBytesRead > cached_read_total) {
- diff = data.totalBytesRead - cached_read_total;
- diff = (1000 * diff) / passedTimeInMs; /* convert to B/s */
- diff /= ONE_K; /* convert to KiB/s */
- cached_read_diff = (uint32_t)diff;
- } else {
- cached_read_diff = 0;
+ if (status != RATESTATUS_INIT) {
+ uint64_t diff;
+
+ if (data.totalBytesRead > cached_read_total) {
+ diff = data.totalBytesRead - cached_read_total;
+ diff = (1000 * diff) / passedTimeInMs; /* convert to B/s */
+ diff /= ONE_K; /* convert to KiB/s */
+ cached_read_diff = (uint32_t)diff;
+ } else {
+ cached_read_diff = 0;
+ }
+
+ if (data.totalBytesWritten > cached_write_total) {
+ diff = data.totalBytesWritten - cached_write_total;
+ diff = (1000 * diff) / passedTimeInMs; /* convert to B/s */
+ diff /= ONE_K; /* convert to KiB/s */
+ cached_write_diff = (uint32_t)diff;
+ } else {
+ cached_write_diff = 0;
+ }
+
+ if (data.totalMsTimeSpend > cached_msTimeSpend_total) {
+ diff = data.totalMsTimeSpend - cached_msTimeSpend_total;
+ cached_utilisation_diff = 100.0 * (double)diff / passedTimeInMs;
+ cached_utilisation_diff = MINIMUM(cached_utilisation_diff, 100.0);
+ } else {
+ cached_utilisation_diff = 0.0;
+ }
}
- cached_read_total = data.totalBytesRead;
- if (data.totalBytesWritten > cached_write_total) {
- diff = data.totalBytesWritten - cached_write_total;
- diff = (1000 * diff) / passedTimeInMs; /* convert to B/s */
- diff /= ONE_K; /* convert to KiB/s */
- cached_write_diff = (uint32_t)diff;
- } else {
- cached_write_diff = 0;
- }
+ cached_read_total = data.totalBytesRead;
cached_write_total = data.totalBytesWritten;
-
- if (data.totalMsTimeSpend > cached_msTimeSpend_total) {
- diff = data.totalMsTimeSpend - cached_msTimeSpend_total;
- cached_utilisation_diff = 100.0 * (double)diff / passedTimeInMs;
- cached_utilisation_diff = MINIMUM(cached_utilisation_diff, 100.0);
- } else {
- cached_utilisation_diff = 0.0;
- }
cached_msTimeSpend_total = data.totalMsTimeSpend;
}
+ this->values[0] = cached_utilisation_diff;
+
+ if (status == RATESTATUS_NODATA) {
+ xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "no data");
+ return;
+ }
if (status == RATESTATUS_INIT) {
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "init");
return;
@@ -101,8 +110,6 @@ static void DiskIOMeter_updateValues(Meter* this) {
return;
}
- this->values[0] = cached_utilisation_diff;
-
char bufferRead[12], bufferWrite[12];
Meter_humanUnit(bufferRead, cached_read_diff, sizeof(bufferRead));
Meter_humanUnit(bufferWrite, cached_write_diff, sizeof(bufferWrite));

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