summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2021-02-28 18:44:39 +0100
committerDaniel Lange <DLange@git.local>2021-02-28 18:44:39 +0100
commit379421d3b2a5a1cf718b555663ec873ef7ea90d8 (patch)
treec9e44ec42b40f36571e56a58b49669ad89fb675c
parent07a6efcb22c002ad09432e8dbe87eed888821c2c (diff)
parentbb9a60ee8af33da0ae2f763640a2a2da48b27bfa (diff)
Merge branch 'networkiograph' of Nudin/htop
-rw-r--r--Meter.c7
-rw-r--r--NetworkIOMeter.c10
2 files changed, 12 insertions, 5 deletions
diff --git a/Meter.c b/Meter.c
index e42b29b9..e8bfaad0 100644
--- a/Meter.c
+++ b/Meter.c
@@ -334,7 +334,6 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
double value = 0.0;
for (uint8_t i = 0; i < this->curItems; i++)
value += this->values[i];
- value /= this->total;
data->values[nValues - 1] = value;
}
@@ -345,8 +344,10 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
}
for (; i < nValues - 1; i += 2, k++) {
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
- int v1 = CLAMP((int) lround(data->values[i] * pix), 1, pix);
- int v2 = CLAMP((int) lround(data->values[i + 1] * pix), 1, pix);
+ if (this->total < 1)
+ this->total = 1;
+ int v1 = CLAMP((int) lround(data->values[i] / this->total * pix), 1, pix);
+ int v2 = CLAMP((int) lround(data->values[i + 1] / this->total * pix), 1, pix);
int colorIdx = GRAPH_1;
for (int line = 0; line < GRAPH_HEIGHT; line++) {
diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c
index a898b311..b78ac89a 100644
--- a/NetworkIOMeter.c
+++ b/NetworkIOMeter.c
@@ -24,7 +24,7 @@ static unsigned long int cached_rxp_diff = 0;
static unsigned long int cached_txb_diff = 0;
static unsigned long int cached_txp_diff = 0;
-static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t len) {
+static void NetworkIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
static unsigned long long int cached_last_update = 0;
struct timeval tv;
@@ -80,6 +80,12 @@ static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, s
cached_txp_total = packetsTransmitted;
}
+ this->values[0] = cached_rxb_diff;
+ this->values[1] = cached_txb_diff;
+ if (cached_rxb_diff + cached_txb_diff > this->total) {
+ this->total = cached_rxb_diff + cached_txb_diff;
+ }
+
char bufferBytesReceived[12], bufferBytesTransmitted[12];
Meter_humanUnit(bufferBytesReceived, cached_rxb_diff, sizeof(bufferBytesReceived));
Meter_humanUnit(bufferBytesTransmitted, cached_txb_diff, sizeof(bufferBytesTransmitted));
@@ -116,7 +122,7 @@ const MeterClass NetworkIOMeter_class = {
},
.updateValues = NetworkIOMeter_updateValues,
.defaultMode = TEXT_METERMODE,
- .maxItems = 0,
+ .maxItems = 2,
.total = 100.0,
.attributes = NetworkIOMeter_attributes,
.name = "NetworkIO",

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