| From 3570b3e9ba367f10718b56336ce32d5254f66575 Mon Sep 17 00:00:00 2001 |
| From: Tom Gundersen <teg@jklm.no> |
| Date: Thu, 9 May 2019 13:00:37 +0200 |
| Subject: [PATCH] metrics: change the constant used for invalid timestamps |
| |
| Use (uint64_t)-1 rather than 0 to indicate an invalid timestamp. It |
| should not be possible for the kernel to return 0 from |
| clock_gettime(), but we have received some reports of our asserts |
| triggering, so avoid the issue entirely by using -1 instead (which |
| really can never be returned). |
| |
| See https://retrace.fedoraproject.org/faf/reports/2539484/ |
| |
| Signed-off-by: Tom Gundersen <teg@jklm.no> |
| Upstream-Status: dbus-broker@3570b3e9ba367f10718b56336ce32d5254f66575 |
| --- |
| src/util/metrics.c | 8 ++++---- |
| src/util/metrics.h | 9 ++++++--- |
| 2 files changed, 10 insertions(+), 7 deletions(-) |
| |
| diff --git a/src/util/metrics.c b/src/util/metrics.c |
| index b5a7182..eef94eb 100644 |
| --- a/src/util/metrics.c |
| +++ b/src/util/metrics.c |
| @@ -26,7 +26,7 @@ void metrics_init(Metrics *metrics, clockid_t id) { |
| } |
| |
| void metrics_deinit(Metrics *metrics) { |
| - c_assert(!metrics->timestamp); |
| + c_assert(metrics->timestamp == METRICS_TIMESTAMP_INVALID); |
| metrics_init(metrics, metrics->id); |
| } |
| |
| @@ -82,7 +82,7 @@ void metrics_sample_add(Metrics *metrics, uint64_t timestamp) { |
| * a sample is not currently running. |
| */ |
| void metrics_sample_start(Metrics *metrics) { |
| - c_assert(!metrics->timestamp); |
| + c_assert(metrics->timestamp == METRICS_TIMESTAMP_INVALID); |
| metrics->timestamp = metrics_get_time(metrics); |
| } |
| |
| @@ -93,11 +93,11 @@ void metrics_sample_start(Metrics *metrics) { |
| * End a currently running sample, and update the internal state. |
| */ |
| void metrics_sample_end(Metrics *metrics) { |
| - c_assert(metrics->timestamp); |
| + c_assert(metrics->timestamp != METRICS_TIMESTAMP_INVALID); |
| |
| metrics_sample_add(metrics, metrics->timestamp); |
| |
| - metrics->timestamp = 0; |
| + metrics->timestamp = METRICS_TIMESTAMP_INVALID; |
| } |
| |
| /** |
| diff --git a/src/util/metrics.h b/src/util/metrics.h |
| index a8ee915..b00dee6 100644 |
| --- a/src/util/metrics.h |
| +++ b/src/util/metrics.h |
| @@ -8,6 +8,8 @@ |
| #include <stdlib.h> |
| #include <time.h> |
| |
| +#define METRICS_TIMESTAMP_INVALID ((uint64_t) -1) |
| + |
| typedef struct Metrics Metrics; |
| |
| struct Metrics { |
| @@ -23,9 +25,10 @@ struct Metrics { |
| uint64_t sum_of_squares; |
| }; |
| |
| -#define METRICS_INIT(_id) { \ |
| - .minimum = (uint64_t) -1, \ |
| - .id = (_id), \ |
| +#define METRICS_INIT(_id) { \ |
| + .minimum = (uint64_t) -1, \ |
| + .id = (_id), \ |
| + .timestamp = METRICS_TIMESTAMP_INVALID, \ |
| } |
| |
| void metrics_init(Metrics *metrics, clockid_t id); |
| -- |
| 2.21.0 |
| |