diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2023-08-29 13:02:50 +0200 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2024-03-27 19:49:23 +0100 |
commit | b61685779cdf696ba4135a97ce66075c337c7562 (patch) | |
tree | 03cde66b2157eb5da9b0bc64fa46bff01ea96767 | |
parent | 484f029d8b0e0dbb5df37e3aff0dbf059fd857a1 (diff) |
Store time of the previous process scan
The difference of scans is useful for utilization calculations.
To avoid divisions by 0 on first scan set monotonicMs also on first
scan.
-rw-r--r-- | Machine.c | 10 | ||||
-rw-r--r-- | Machine.h | 1 |
2 files changed, 8 insertions, 3 deletions
@@ -99,10 +99,14 @@ void Machine_scanTables(Machine* this) { // set scan timestamp static bool firstScanDone = false; - if (firstScanDone) - Platform_gettime_monotonic(&this->monotonicMs); - else + if (firstScanDone) { + this->prevMonotonicMs = this->monotonicMs; + } else { + this->prevMonotonicMs = 0; firstScanDone = true; + } + Platform_gettime_monotonic(&this->monotonicMs); + assert(this->monotonicMs > this->prevMonotonicMs); this->maxUserId = 0; Row_resetFieldWidths(); @@ -41,6 +41,7 @@ typedef struct Machine_ { struct timeval realtime; /* time of the current sample */ uint64_t realtimeMs; /* current time in milliseconds */ uint64_t monotonicMs; /* same, but from monotonic clock */ + uint64_t prevMonotonicMs; /* time in milliseconds from monotonic clock of previous scan */ int64_t iterationsRemaining; |