summaryrefslogtreecommitdiffstats
path: root/DiskIOMeter.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-11-02 14:46:42 +0100
committerChristian Göttsche <cgzones@googlemail.com>2020-11-02 14:46:42 +0100
commit0c1908832b50886cd1fa4ea296aa2570625bfa15 (patch)
treeb9e97e2a305317292111fa1d43405553e4cadbef /DiskIOMeter.c
parent15652e7b8102e86b3405254405d8ee5d2a239004 (diff)
Handle data wraparounds in IO Meters
If the current data is smaller than the previous one, either by a retrieve error or a device removal or a original data wraparound, sanitize the value to zero. Fixes: #299
Diffstat (limited to 'DiskIOMeter.c')
-rw-r--r--DiskIOMeter.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/DiskIOMeter.c b/DiskIOMeter.c
index 21696a33..e2d02524 100644
--- a/DiskIOMeter.c
+++ b/DiskIOMeter.c
@@ -53,14 +53,25 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) {
return;
}
- cached_read_diff = (data.totalBytesRead - cached_read_total) / 1024; /* Meter_humanUnit() expects unit in kilo */
+ if (data.totalBytesRead > cached_read_total) {
+ cached_read_diff = (data.totalBytesRead - cached_read_total) / 1024; /* Meter_humanUnit() expects unit in kilo */
+ } else {
+ cached_read_diff = 0;
+ }
cached_read_total = data.totalBytesRead;
- cached_write_diff = (data.totalBytesWritten - cached_write_total) / 1024; /* Meter_humanUnit() expects unit in kilo */
+ if (data.totalBytesWritten > cached_write_total) {
+ cached_write_diff = (data.totalBytesWritten - cached_write_total) / 1024; /* Meter_humanUnit() expects unit in kilo */
+ } else {
+ cached_write_diff = 0;
+ }
cached_write_total = data.totalBytesWritten;
- cached_utilisation_diff = 100 * (double)(data.totalMsTimeSpend - cached_msTimeSpend_total) / passedTimeInMs;
-
+ if (data.totalMsTimeSpend > cached_msTimeSpend_total) {
+ cached_utilisation_diff = 100 * (double)(data.totalMsTimeSpend - cached_msTimeSpend_total) / passedTimeInMs;
+ } else {
+ cached_utilisation_diff = 0.0;
+ }
cached_msTimeSpend_total = data.totalMsTimeSpend;
}

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