summaryrefslogtreecommitdiffstats
path: root/NetworkIOMeter.c
diff options
context:
space:
mode:
authorSohaib <sohaib.amhmd@gmail.com>2021-03-23 08:27:05 +0200
committerSohaib <sohaib.amhmd@gmail.com>2021-04-05 23:40:41 +0200
commit421bdeec603b4fb1a4edec0e802c437fbe47fca0 (patch)
tree8be7cfd1cb7b0c3d1720d75978b27318fbc43253 /NetworkIOMeter.c
parentf16aa483dd36cfdb39e9d6d4238687178f2981e8 (diff)
Merging all the points related to calculating time in one place
The end goal is to consolidate all the points in htop that can only work in live-only mode today, so that will be able to inject PCP archive mode and have a chance at it working. The biggest problem we've got at this moment is all the places that are independently asking the kernel to 'give me the time right now'. Each of those needs to be audited and ultimately changed to allow platforms to manage their own idea of time. So, all the calls to gettimeofday(2) and time(2) are potential problems. Ultimately I want to get these down to just one or two. Related to https://github.com/htop-dev/htop/pull/574
Diffstat (limited to 'NetworkIOMeter.c')
-rw-r--r--NetworkIOMeter.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c
index c0e1b06f..bfcb3c0e 100644
--- a/NetworkIOMeter.c
+++ b/NetworkIOMeter.c
@@ -25,12 +25,10 @@ static uint32_t cached_txb_diff;
static uint32_t cached_txp_diff;
static void NetworkIOMeter_updateValues(Meter* this) {
+ const ProcessList* pl = this->pl;
static uint64_t cached_last_update = 0;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- uint64_t timeInMilliSeconds = (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000;
- uint64_t passedTimeInMs = timeInMilliSeconds - cached_last_update;
+ uint64_t passedTimeInMs = pl->timestampMs - cached_last_update;
/* update only every 500ms */
if (passedTimeInMs > 500) {
@@ -40,7 +38,7 @@ static void NetworkIOMeter_updateValues(Meter* this) {
static uint64_t cached_txp_total;
uint64_t diff;
- cached_last_update = timeInMilliSeconds;
+ cached_last_update = pl->timestampMs;
NetworkIOData data;
hasData = Platform_getNetworkIO(&data);

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