From: Timo Sirainen Date: Thu, 18 Feb 2021 16:58:29 +0000 (+0200) Subject: lib: event_get_last_duration() - Change it to return uintmax_t X-Git-Tag: 2.3.15~360 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9d269602cb59b078d35421468900ec72b3859ff8;p=thirdparty%2Fdovecot%2Fcore.git lib: event_get_last_duration() - Change it to return uintmax_t It can't be negative, so unsigned return value makes more sense. Also clarify the function comment and parameter name. --- diff --git a/src/lib/lib-event.c b/src/lib/lib-event.c index b9b2e2f5b0..5ead7f6e2e 100644 --- a/src/lib/lib-event.c +++ b/src/lib/lib-event.c @@ -940,13 +940,17 @@ bool event_get_last_send_time(const struct event *event, struct timeval *tv_r) return tv_r->tv_sec != 0; } -void event_get_last_duration(const struct event *event, intmax_t *duration_r) +void event_get_last_duration(const struct event *event, + uintmax_t *duration_usecs_r) { if (event->tv_last_sent.tv_sec == 0) { - *duration_r = 0; + *duration_usecs_r = 0; return; } - *duration_r = timeval_diff_usecs(&event->tv_last_sent, &event->tv_created); + long long diff = timeval_diff_usecs(&event->tv_last_sent, + &event->tv_created); + i_assert(diff >= 0); + *duration_usecs_r = diff; } const struct event_field * diff --git a/src/lib/lib-event.h b/src/lib/lib-event.h index 5bcbd3639b..0c60137061 100644 --- a/src/lib/lib-event.h +++ b/src/lib/lib-event.h @@ -294,9 +294,10 @@ void event_get_create_time(const struct event *event, struct timeval *tv_r); /* Get the time when the event was last sent. Returns TRUE if time was returned, FALSE if event has never been sent. */ bool event_get_last_send_time(const struct event *event, struct timeval *tv_r); -/* Get the event duration field, calculated after event has been sent. */ +/* Get the event duration field in microseconds. This is calculated from + the event's last sent time. */ void event_get_last_duration(const struct event *event, - intmax_t *duration_msec_r); + uintmax_t *duration_usecs_r); /* Returns field for a given key, or NULL if it doesn't exist. If the key isn't found from the event itself, find it from parent events. */ const struct event_field * diff --git a/src/lib/test-event-log.c b/src/lib/test-event-log.c index dc2e3dc023..99c9b6a941 100644 --- a/src/lib/test-event-log.c +++ b/src/lib/test-event-log.c @@ -2482,7 +2482,7 @@ static void test_event_log_message(void) static void test_event_duration() { - intmax_t duration; + uintmax_t duration; test_begin("event duration"); struct event *e = event_create(NULL); usleep(10); diff --git a/src/stats/stats-metrics.c b/src/stats/stats-metrics.c index 3dc8b7717d..66f6ecd26d 100644 --- a/src/stats/stats-metrics.c +++ b/src/stats/stats-metrics.c @@ -544,7 +544,7 @@ void stats_metrics_event(struct stats_metrics *metrics, struct event *event, { struct event_filter_match_iter *iter; struct metric *metric; - intmax_t duration; + uintmax_t duration; /* Note: Adding the field here means that it will get exported below. This is necessary to allow group-by functions to quantize