diff --git a/src/mana_plugin_root_histogram.cc b/src/mana_plugin_root_histogram.cc index 11ab4bc..a87bc27 100644 --- a/src/mana_plugin_root_histogram.cc +++ b/src/mana_plugin_root_histogram.cc @@ -20,18 +20,30 @@ struct Context std::vector> rawHistograms; }; +static Context *g_ctx = nullptr; + MANA_DEFINE_PLUGIN_INIT(init) { + if (g_ctx) + { + log_warn("init() called multiple times. This plugin is a singleton!"); + return g_ctx; + } log_set_level(LOG_INFO); - static Context g_ctx; - log_debug("init: ctx=%p", &g_ctx); - return &g_ctx; + log_debug("init"); + return g_ctx = new Context; } MANA_DEFINE_PLUGIN_SHUTDOWN(shutdown) { - (void)context; log_debug("shutdown"); + if (context != g_ctx) + { + log_warn("shutdown() called with invalid context"); + return; + } + delete g_ctx; + g_ctx = nullptr; } struct ObjectPath @@ -145,7 +157,8 @@ inline std::string histo_info(const std::vector> &histos) } } - return fmt::format("histoCount={}, histoMem={} MiB", histoCount, histoMem / (1024.0 * 1024)); + return fmt::format("histoCount={}, histoMem={:.2f} MiB", histoCount, + histoMem / (1024.0 * 1024)); } MANA_DEFINE_PLUGIN_BEGIN_RUN(begin_run)