summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2023-08-29 13:02:50 +0200
committercgzones <cgzones@googlemail.com>2024-03-27 19:49:23 +0100
commitb61685779cdf696ba4135a97ce66075c337c7562 (patch)
tree03cde66b2157eb5da9b0bc64fa46bff01ea96767
parent484f029d8b0e0dbb5df37e3aff0dbf059fd857a1 (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.c10
-rw-r--r--Machine.h1
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;

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