mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-13 04:34: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
@ -16,6 +16,7 @@ static const int NetworkIOMeter_attributes[] = {
|
||||
METER_VALUE_IOWRITE,
|
||||
};
|
||||
|
||||
static bool hasData = false;
|
||||
static unsigned long int cached_rxb_diff = 0;
|
||||
static unsigned long int cached_rxp_diff = 0;
|
||||
static unsigned long int cached_txb_diff = 0;
|
||||
@ -35,9 +36,15 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i
|
||||
|
||||
/* update only every 500ms */
|
||||
if (passedTimeInMs > 500) {
|
||||
cached_last_update = timeInMilliSeconds;
|
||||
|
||||
unsigned long int bytesReceived, packetsReceived, bytesTransmitted, packetsTransmitted;
|
||||
|
||||
Platform_getNetworkIO(&bytesReceived, &packetsReceived, &bytesTransmitted, &packetsTransmitted);
|
||||
hasData = Platform_getNetworkIO(&bytesReceived, &packetsReceived, &bytesTransmitted, &packetsTransmitted);
|
||||
if (!hasData) {
|
||||
xSnprintf(buffer, len, "no data");
|
||||
return;
|
||||
}
|
||||
|
||||
cached_rxb_diff = (bytesReceived - cached_rxb_total) / 1024; /* Meter_humanUnit() expects unit in kilo */
|
||||
cached_rxb_diff = 1000.0 * cached_rxb_diff / passedTimeInMs; /* convert to per second */
|
||||
@ -52,8 +59,6 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i
|
||||
|
||||
cached_txp_diff = packetsTransmitted - cached_txp_total;
|
||||
cached_txp_total = packetsTransmitted;
|
||||
|
||||
cached_last_update = timeInMilliSeconds;
|
||||
}
|
||||
|
||||
char bufferBytesReceived[12], bufferBytesTransmitted[12];
|
||||
@ -63,6 +68,11 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, i
|
||||
}
|
||||
|
||||
static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
|
||||
if (!hasData) {
|
||||
RichString_write(out, CRT_colors[METER_VALUE_ERROR], "no data");
|
||||
return;
|
||||
}
|
||||
|
||||
char buffer[64];
|
||||
|
||||
RichString_write(out, CRT_colors[METER_TEXT], "rx: ");
|
||||
|
Reference in New Issue
Block a user