summaryrefslogtreecommitdiffstats
path: root/DiskIOMeter.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2021-03-01 12:10:18 +1100
committerNathan Scott <nathans@redhat.com>2021-03-01 12:10:18 +1100
commit00339087b0ec7ab951eb65b03a2d1d66d97517f0 (patch)
tree5a2319e2d95c208ab2d99b66ec83eb035d567d00 /DiskIOMeter.c
parent379421d3b2a5a1cf718b555663ec873ef7ea90d8 (diff)
Fix integer sizing issues in the DiskIO Meter
On Linux kernels the size of the values exported for block device bytes has used a 64 bit integer for quite some time (2.6+ IIRC). Make the procfs value extraction use correct types and change internal types used to rate convert these counters (within the DiskIO Meter) 64 bit integers, where appropriate.
Diffstat (limited to 'DiskIOMeter.c')
-rw-r--r--DiskIOMeter.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/DiskIOMeter.c b/DiskIOMeter.c
index 52b14611..1c0c2ba4 100644
--- a/DiskIOMeter.c
+++ b/DiskIOMeter.c
@@ -26,12 +26,12 @@ 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 unsigned long int cached_read_diff;
+static unsigned long int 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 unsigned long long int cached_last_update;
struct timeval tv;
gettimeofday(&tv, NULL);
@@ -40,9 +40,10 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
/* 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 unsigned long long int cached_read_total;
+ static unsigned long long int cached_write_total;
+ static unsigned long long int cached_msTimeSpend_total;
+ unsigned long long int diff;
cached_last_update = timeInMilliSeconds;
@@ -56,21 +57,26 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
}
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 = (unsigned int)diff;
} else {
- cached_read_diff = 0;
+ cached_read_diff = 0UL;
}
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 = (unsigned int)diff;
} else {
- cached_write_diff = 0;
+ cached_write_diff = 0UL;
}
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;
}

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