From b61685779cdf696ba4135a97ce66075c337c7562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 29 Aug 2023 13:02:50 +0200 Subject: 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. --- Machine.c | 10 +++++++--- Machine.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Machine.c b/Machine.c index 44aa27c8..6beb47b4 100644 --- a/Machine.c +++ b/Machine.c @@ -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(); diff --git a/Machine.h b/Machine.h index 419911c3..f7f82afa 100644 --- a/Machine.h +++ b/Machine.h @@ -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; -- cgit v1.2.3