mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-14 13:04:35 +03:00
Improve handling of no data in Disk and Network IO Meters
This commit is contained in:

committed by
cgzones

parent
167adc0a2b
commit
f757810f48
@ -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;
|
||||
|
Reference in New Issue
Block a user