]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: event_get_last_duration() - Change it to return uintmax_t
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 18 Feb 2021 16:58:29 +0000 (18:58 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 19 Feb 2021 13:27:44 +0000 (13:27 +0000)
It can't be negative, so unsigned return value makes more sense.
Also clarify the function comment and parameter name.

src/lib/lib-event.c
src/lib/lib-event.h
src/lib/test-event-log.c
src/stats/stats-metrics.c

index b9b2e2f5b0af42404ca69aa8ad6e2ca65a7bb940..5ead7f6e2e81757f70cbf968bb9294d044445673 100644 (file)
@@ -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 *
index 5bcbd3639b5f47be590d8cf3b30925af34605850..0c601370614b72caf2c3c70911c1946928c2829e 100644 (file)
@@ -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 *
index dc2e3dc0232855a39d5f4275de87fcf84af6ce26..99c9b6a94123e00e8841e9cf979fa7f958586a04 100644 (file)
@@ -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);
index 3dc8b7717de5badd6e46253e0630de1df20b9459..66f6ecd26dce843a7059bffc6573a15d45c3ce6e 100644 (file)
@@ -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