]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: event-exporter-fmt - Use the new event category iterator API for event_export_...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sat, 19 Aug 2023 17:48:15 +0000 (19:48 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Sat, 18 Nov 2023 18:58:04 +0000 (18:58 +0000)
src/stats/event-exporter-fmt-json.c
src/stats/event-exporter-fmt-tab-text.c
src/stats/event-exporter-fmt.c
src/stats/event-exporter.h

index 1c563ecbece186669c730e5c17fb3eb2d749825a..b93a900e8f98c2fd6b27b857c9d54d498beec5b3 100644 (file)
@@ -146,18 +146,13 @@ static void json_export_timestamps(string_t *dest, struct event *event,
 static void json_export_categories(string_t *dest, struct event *event,
                                   const struct metric_export_info *info)
 {
-       struct event_category *const *cats;
-       unsigned int count;
-
        if ((info->include & EVENT_EXPORTER_INCL_CATEGORIES) == 0)
                return;
 
        append_str(dest, "categories");
        str_append(dest, ":[");
 
-       cats = event_get_categories(event, &count);
-       event_export_helper_fmt_categories(dest, cats, count,
-                                          append_str, ",");
+       event_export_helper_fmt_categories(dest, event, append_str, ",");
 
        str_append(dest, "],");
 }
index a68f10a3c6904596473cb925fd36dce0510726f2..40575541c561b8a1ba17ab440985a46d150d6f65 100644 (file)
@@ -133,15 +133,10 @@ static void append_category(string_t *dest, const char *cat)
 static void tabtext_export_categories(string_t *dest, struct event *event,
                                      const struct metric_export_info *info)
 {
-       struct event_category *const *cats;
-       unsigned int count;
-
        if ((info->include & EVENT_EXPORTER_INCL_CATEGORIES) == 0)
                return;
 
-       cats = event_get_categories(event, &count);
-       event_export_helper_fmt_categories(dest, cats, count,
-                                          append_category, "\t");
+       event_export_helper_fmt_categories(dest, event, append_category, "\t");
 
        str_append_c(dest, '\t'); /* extra \t to have something to remove later */
 }
index 73467950b492c5e59c53a2ae6d145629c3e4d393..07db4e8328b4f7774fb6a913084f9120c8af5d49 100644 (file)
@@ -2,7 +2,6 @@
 
 #include "lib.h"
 #include "str.h"
-#include "hash.h"
 #include "ioloop.h"
 #include "event-exporter.h"
 
@@ -26,45 +25,17 @@ void event_export_helper_fmt_rfc3339_time(string_t *dest,
                    (unsigned int) time->tv_usec);
 }
 
-HASH_TABLE_DEFINE_TYPE(category_set, void *, const struct event_category *);
-
-static void insert_category(HASH_TABLE_TYPE(category_set) hash,
-                           const struct event_category * const cat)
-{
-       /* insert this category (key == the unique internal pointer) */
-       hash_table_update(hash, cat->internal, cat);
-
-       /* insert parent's categories */
-       if (cat->parent != NULL)
-               insert_category(hash, cat->parent);
-}
-
 void event_export_helper_fmt_categories(string_t *dest,
-                                       struct event_category * const *cats,
-                                       unsigned int count,
+                                       const struct event *event,
                                        void (*append)(string_t *, const char *),
                                        const char *separator)
 {
-       HASH_TABLE_TYPE(category_set) hash;
-       struct hash_iterate_context *iter;
+       struct event_category_iterator *iter;
        const struct event_category *cat;
-       void *key ATTR_UNUSED;
-       unsigned int i;
        bool first = TRUE;
 
-       if (count == 0)
-               return;
-
-       hash_table_create_direct(&hash, pool_datastack_create(),
-                                3 * count /* estimate */);
-
-       /* insert all the categories into the hash table */
-       for (i = 0; i < count; i++)
-               insert_category(hash, cats[i]);
-
-       /* output each category from hash table */
-       iter = hash_table_iterate_init(hash);
-       while (hash_table_iterate(iter, hash, &key, &cat)) {
+       iter = event_categories_iterate_init(event);
+       while (event_categories_iterate(iter, &cat)) {
                if (!first)
                        str_append(dest, separator);
 
@@ -72,7 +43,5 @@ void event_export_helper_fmt_categories(string_t *dest,
 
                first = FALSE;
        }
-       hash_table_iterate_deinit(&iter);
-
-       hash_table_destroy(&hash);
+       event_categories_iterate_deinit(&iter);
 }
index c093eff9b39e61f1e24ed32e9718e8ccf06a1706..704f0bffa62ec28c3c2a65124862eb52778a0d73 100644 (file)
@@ -27,8 +27,7 @@ void event_export_helper_fmt_unix_time(string_t *dest, const struct timeval *tim
    The result has no duplicates regardless of if the array has any or if any
    of the categories' ancestors are implictly or explicitly duplicated. */
 void event_export_helper_fmt_categories(string_t *dest,
-                                       struct event_category *const *cats,
-                                       unsigned int count,
+                                       const struct event *event,
                                        void (*append)(string_t *, const char *),
                                        const char *separator);