bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen#include "lib.h"
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen#include "stats-event-category.h"
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstatic pool_t categories_pool;
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenvoid stats_event_category_register(const char *name,
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen struct event_category *parent)
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen{
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen struct event_category *category =
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen p_new(categories_pool, struct event_category, 1);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen category->parent = parent;
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen category->name = p_strdup(categories_pool, name);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen /* Create a temporary event to register the category. A bit slower
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen than necessary, but this code won't be called often. */
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen struct event *event = event_create(NULL);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen struct event_category *categories[] = { category, NULL };
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen event_add_categories(event, categories);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen event_unref(&event);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen}
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenvoid stats_event_categories_init(void)
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen{
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen categories_pool = pool_alloconly_create("categories", 1024);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen}
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenvoid stats_event_categories_deinit(void)
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen{
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen pool_unref(&categories_pool);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen}