mirror of https://github.com/xzeldon/htop.git
Switch DiskIO Meter to using uint32_t and uint64_t
From review via @BenBE, this is now a whole lot cleaner.
This commit is contained in:
parent
00339087b0
commit
b4736228dc
|
@ -26,24 +26,24 @@ static const int DiskIOMeter_attributes[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool hasData = false;
|
static bool hasData = false;
|
||||||
static unsigned long int cached_read_diff;
|
static uint32_t cached_read_diff;
|
||||||
static unsigned long int cached_write_diff;
|
static uint32_t cached_write_diff;
|
||||||
static double cached_utilisation_diff;
|
static double cached_utilisation_diff;
|
||||||
|
|
||||||
static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
|
static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
|
||||||
static unsigned long long int cached_last_update;
|
static uint64_t cached_last_update;
|
||||||
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
unsigned long long int timeInMilliSeconds = (unsigned long long int)tv.tv_sec * 1000 + (unsigned long long int)tv.tv_usec / 1000;
|
uint64_t timeInMilliSeconds = (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000;
|
||||||
unsigned long long int passedTimeInMs = timeInMilliSeconds - cached_last_update;
|
uint64_t passedTimeInMs = timeInMilliSeconds - cached_last_update;
|
||||||
|
|
||||||
/* update only every 500ms */
|
/* update only every 500ms */
|
||||||
if (passedTimeInMs > 500) {
|
if (passedTimeInMs > 500) {
|
||||||
static unsigned long long int cached_read_total;
|
static uint64_t cached_read_total;
|
||||||
static unsigned long long int cached_write_total;
|
static uint64_t cached_write_total;
|
||||||
static unsigned long long int cached_msTimeSpend_total;
|
static uint64_t cached_msTimeSpend_total;
|
||||||
unsigned long long int diff;
|
uint64_t diff;
|
||||||
|
|
||||||
cached_last_update = timeInMilliSeconds;
|
cached_last_update = timeInMilliSeconds;
|
||||||
|
|
||||||
|
@ -59,18 +59,18 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
|
||||||
if (data.totalBytesRead > cached_read_total) {
|
if (data.totalBytesRead > cached_read_total) {
|
||||||
diff = data.totalBytesRead - cached_read_total;
|
diff = data.totalBytesRead - cached_read_total;
|
||||||
diff /= 1024; /* Meter_humanUnit() expects unit in kilo */
|
diff /= 1024; /* Meter_humanUnit() expects unit in kilo */
|
||||||
cached_read_diff = (unsigned int)diff;
|
cached_read_diff = (uint32_t)diff;
|
||||||
} else {
|
} else {
|
||||||
cached_read_diff = 0UL;
|
cached_read_diff = 0;
|
||||||
}
|
}
|
||||||
cached_read_total = data.totalBytesRead;
|
cached_read_total = data.totalBytesRead;
|
||||||
|
|
||||||
if (data.totalBytesWritten > cached_write_total) {
|
if (data.totalBytesWritten > cached_write_total) {
|
||||||
diff = data.totalBytesWritten - cached_write_total;
|
diff = data.totalBytesWritten - cached_write_total;
|
||||||
diff /= 1024; /* Meter_humanUnit() expects unit in kilo */
|
diff /= 1024; /* Meter_humanUnit() expects unit in kilo */
|
||||||
cached_write_diff = (unsigned int)diff;
|
cached_write_diff = (uint32_t)diff;
|
||||||
} else {
|
} else {
|
||||||
cached_write_diff = 0UL;
|
cached_write_diff = 0;
|
||||||
}
|
}
|
||||||
cached_write_total = data.totalBytesWritten;
|
cached_write_total = data.totalBytesWritten;
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@ in the source distribution for its full text.
|
||||||
#include "Meter.h"
|
#include "Meter.h"
|
||||||
|
|
||||||
typedef struct DiskIOData_ {
|
typedef struct DiskIOData_ {
|
||||||
unsigned long long int totalBytesRead;
|
uint64_t totalBytesRead;
|
||||||
unsigned long long int totalBytesWritten;
|
uint64_t totalBytesWritten;
|
||||||
unsigned long long int totalMsTimeSpend;
|
uint64_t totalMsTimeSpend;
|
||||||
} DiskIOData;
|
} DiskIOData;
|
||||||
|
|
||||||
extern const MeterClass DiskIOMeter_class;
|
extern const MeterClass DiskIOMeter_class;
|
||||||
|
|
Loading…
Reference in New Issue