From: Josef 'Jeff' Sipek Date: Thu, 20 Feb 2020 19:18:32 +0000 (-0500) Subject: stats: Move event field stats distribution update into a helper function X-Git-Tag: 2.3.11.2~539 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0d6187d381c174cc3644ac3d6a8aa28ad7e6a06;p=thirdparty%2Fdovecot%2Fcore.git stats: Move event field stats distribution update into a helper function --- diff --git a/src/stats/stats-metrics.c b/src/stats/stats-metrics.c index 03b4a4168c..fe0fd4fa72 100644 --- a/src/stats/stats-metrics.c +++ b/src/stats/stats-metrics.c @@ -424,6 +424,31 @@ stats_metric_group_by(struct metric *metric, struct event *event, pool_t pool) stats_metric_event(sub_metric, event, pool); } +static void +stats_metric_event_field(struct event *event, const char *fieldname, + struct stats_dist *stats) +{ + const struct event_field *field = event_find_field(event, fieldname); + intmax_t num = 0; + + if (field == NULL) + return; + + switch (field->value_type) { + case EVENT_FIELD_VALUE_TYPE_STR: + break; + case EVENT_FIELD_VALUE_TYPE_INTMAX: + num = field->value.intmax; + break; + case EVENT_FIELD_VALUE_TYPE_TIMEVAL: + num = field->value.timeval.tv_sec * 1000000ULL + + field->value.timeval.tv_usec; + break; + } + + stats_dist_add(stats, num); +} + static void stats_metric_event(struct metric *metric, struct event *event, pool_t pool) { @@ -432,26 +457,11 @@ stats_metric_event(struct metric *metric, struct event *event, pool_t pool) event_get_last_duration(event, &duration); stats_dist_add(metric->duration_stats, duration); - for (unsigned int i = 0; i < metric->fields_count; i++) { - const struct event_field *field = - event_find_field(event, metric->fields[i].field_key); - if (field == NULL) - continue; - intmax_t num = 0; - switch (field->value_type) { - case EVENT_FIELD_VALUE_TYPE_STR: - break; - case EVENT_FIELD_VALUE_TYPE_INTMAX: - num = field->value.intmax; - break; - case EVENT_FIELD_VALUE_TYPE_TIMEVAL: - num = field->value.timeval.tv_sec * 1000000ULL + - field->value.timeval.tv_usec; - break; - } - stats_dist_add(metric->fields[i].stats, num); - } + for (unsigned int i = 0; i < metric->fields_count; i++) + stats_metric_event_field(event, + metric->fields[i].field_key, + metric->fields[i].stats); if (metric->group_by != NULL) stats_metric_group_by(metric, event, pool);