It can't be negative, so unsigned return value makes more sense.
Also clarify the function comment and parameter name.
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 *
/* 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 *
static void test_event_duration()
{
- intmax_t duration;
+ uintmax_t duration;
test_begin("event duration");
struct event *e = event_create(NULL);
usleep(10);
{
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