From 2791e9b169ab64a1eb7e7c8c987247ff937d75fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20V=C3=A1rady?= Date: Thu, 28 Nov 2024 12:19:04 +0100 Subject: [PATCH] filterx: add expression eval metrics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: László Várady --- lib/filterx/expr-compound.c | 15 +++++++++++++++ lib/filterx/expr-condition.c | 14 ++++++++++++++ lib/filterx/expr-function.c | 15 +++++++++++++++ lib/filterx/expr-function.h | 1 + lib/filterx/expr-get-subscript.c | 14 ++++++++++++++ lib/filterx/expr-getattr.c | 14 ++++++++++++++ lib/filterx/expr-set-subscript.c | 14 ++++++++++++++ lib/filterx/expr-setattr.c | 14 ++++++++++++++ lib/filterx/expr-template.c | 32 ++++++++++++++++++++++++++++++++ lib/filterx/expr-variable.c | 32 ++++++++++++++++++++++++++++++++ 10 files changed, 165 insertions(+) diff --git a/lib/filterx/expr-compound.c b/lib/filterx/expr-compound.c index b324894c6e..35f6d7d83a 100644 --- a/lib/filterx/expr-compound.c +++ b/lib/filterx/expr-compound.c @@ -26,6 +26,8 @@ #include "filterx/filterx-eval.h" #include "filterx/object-primitive.h" #include "scratch-buffers.h" +#include "stats/stats-registry.h" +#include "stats/stats-cluster-single.h" #include @@ -35,6 +37,7 @@ typedef struct _FilterXCompoundExpr /* whether this is a statement expression */ gboolean return_value_of_last_expr; GPtrArray *exprs; + } FilterXCompoundExpr; static gboolean @@ -148,6 +151,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg) } } + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_compound_evals_total", NULL, 0); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + return filterx_expr_init_method(s, cfg); } @@ -156,6 +165,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg) { FilterXCompoundExpr *self = (FilterXCompoundExpr *) s; + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_compound_evals_total", NULL, 0); + stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + for (gint i = 0; i < self->exprs->len; i++) { FilterXExpr *expr = g_ptr_array_index(self->exprs, i); diff --git a/lib/filterx/expr-condition.c b/lib/filterx/expr-condition.c index 75011631d6..95494fe345 100644 --- a/lib/filterx/expr-condition.c +++ b/lib/filterx/expr-condition.c @@ -25,6 +25,8 @@ #include "filterx/expr-literal.h" #include "filterx/object-primitive.h" #include "scratch-buffers.h" +#include "stats/stats-registry.h" +#include "stats/stats-cluster-single.h" typedef struct _FilterXConditional FilterXConditional; @@ -57,6 +59,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg) return FALSE; } + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_condition_evals_total", NULL, 0); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + return filterx_expr_init_method(s, cfg); } @@ -66,6 +74,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg) { FilterXConditional *self = (FilterXConditional *) s; + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_condition_evals_total", NULL, 0); + stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + filterx_expr_deinit(self->condition, cfg); filterx_expr_deinit(self->true_branch, cfg); filterx_expr_deinit(self->false_branch, cfg); diff --git a/lib/filterx/expr-function.c b/lib/filterx/expr-function.c index 408051995c..013bcf7e07 100644 --- a/lib/filterx/expr-function.c +++ b/lib/filterx/expr-function.c @@ -35,6 +35,7 @@ #include "plugin.h" #include "cfg.h" #include "mainloop.h" +#include "stats/stats-cluster-single.h" GQuark filterx_function_error_quark(void) @@ -227,12 +228,26 @@ filterx_simple_function_new(const gchar *function_name, FilterXFunctionArgs *arg gboolean filterx_function_init_method(FilterXFunction *s, GlobalConfig *cfg) { + stats_lock(); + StatsClusterKey sc_key; + StatsClusterLabel labels[] = { stats_cluster_label("name", s->function_name) }; + stats_cluster_single_key_set(&sc_key, "fx_func_evals_total", labels, G_N_ELEMENTS(labels)); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &s->super.eval_count); + stats_unlock(); + return filterx_expr_init_method(&s->super, cfg); } void filterx_function_deinit_method(FilterXFunction *s, GlobalConfig *cfg) { + stats_lock(); + StatsClusterKey sc_key; + StatsClusterLabel labels[] = { stats_cluster_label("name", s->function_name) }; + stats_cluster_single_key_set(&sc_key, "fx_func_evals_total", labels, G_N_ELEMENTS(labels)); + stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &s->super.eval_count); + stats_unlock(); + filterx_expr_deinit_method(&s->super, cfg); } diff --git a/lib/filterx/expr-function.h b/lib/filterx/expr-function.h index 819e0b736e..0c1085f2a1 100644 --- a/lib/filterx/expr-function.h +++ b/lib/filterx/expr-function.h @@ -29,6 +29,7 @@ #include "filterx/filterx-expr.h" #include "filterx/filterx-object.h" #include "filterx/expr-generator.h" +#include "stats/stats-registry.h" #include "generic-number.h" #include "plugin.h" diff --git a/lib/filterx/expr-get-subscript.c b/lib/filterx/expr-get-subscript.c index 6ccee3c26a..32a1d51ce4 100644 --- a/lib/filterx/expr-get-subscript.c +++ b/lib/filterx/expr-get-subscript.c @@ -22,6 +22,8 @@ */ #include "filterx/expr-get-subscript.h" #include "filterx/filterx-eval.h" +#include "stats/stats-registry.h" +#include "stats/stats-cluster-single.h" typedef struct _FilterXGetSubscript { @@ -117,6 +119,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg) return FALSE; } + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_get_subscript_evals_total", NULL, 0); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + return filterx_expr_init_method(s, cfg); } @@ -125,6 +133,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg) { FilterXGetSubscript *self = (FilterXGetSubscript *) s; + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_get_subscript_evals_total", NULL, 0); + stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + filterx_expr_deinit(self->operand, cfg); filterx_expr_deinit(self->key, cfg); filterx_expr_deinit_method(s, cfg); diff --git a/lib/filterx/expr-getattr.c b/lib/filterx/expr-getattr.c index 781e64cfc5..f85bf15859 100644 --- a/lib/filterx/expr-getattr.c +++ b/lib/filterx/expr-getattr.c @@ -23,6 +23,8 @@ #include "filterx/expr-getattr.h" #include "filterx/object-string.h" #include "filterx/filterx-eval.h" +#include "stats/stats-registry.h" +#include "stats/stats-cluster-single.h" typedef struct _FilterXGetAttr { @@ -98,6 +100,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg) if (!filterx_expr_init(self->operand, cfg)) return FALSE; + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_getattr_evals_total", NULL, 0); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + return filterx_expr_init_method(s, cfg); } @@ -106,6 +114,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg) { FilterXGetAttr *self = (FilterXGetAttr *) s; + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_getattr_evals_total", NULL, 0); + stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + filterx_expr_deinit(self->operand, cfg); filterx_expr_deinit_method(s, cfg); } diff --git a/lib/filterx/expr-set-subscript.c b/lib/filterx/expr-set-subscript.c index 341c63c7ce..cfb5c100ae 100644 --- a/lib/filterx/expr-set-subscript.c +++ b/lib/filterx/expr-set-subscript.c @@ -29,6 +29,8 @@ #include "filterx/object-null.h" #include "filterx/object-message-value.h" #include "scratch-buffers.h" +#include "stats/stats-registry.h" +#include "stats/stats-cluster-single.h" typedef struct _FilterXSetSubscript { @@ -167,6 +169,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg) return FALSE; } + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_set_subscript_evals_total", NULL, 0); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + return filterx_expr_init_method(s, cfg); } @@ -175,6 +183,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg) { FilterXSetSubscript *self = (FilterXSetSubscript *) s; + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_set_subscript_evals_total", NULL, 0); + stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + filterx_expr_deinit(self->object, cfg); filterx_expr_deinit(self->new_value, cfg); filterx_expr_deinit(self->key, cfg); diff --git a/lib/filterx/expr-setattr.c b/lib/filterx/expr-setattr.c index 2741619415..3151a7ed4f 100644 --- a/lib/filterx/expr-setattr.c +++ b/lib/filterx/expr-setattr.c @@ -30,6 +30,8 @@ #include "filterx/object-null.h" #include "filterx/object-message-value.h" #include "scratch-buffers.h" +#include "stats/stats-registry.h" +#include "stats/stats-cluster-single.h" typedef struct _FilterXSetAttr { @@ -143,6 +145,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg) return FALSE; } + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_setattr_evals_total", NULL, 0); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + return filterx_expr_init_method(s, cfg); } @@ -151,6 +159,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg) { FilterXSetAttr *self = (FilterXSetAttr *) s; + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_setattr_evals_total", NULL, 0); + stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + filterx_expr_deinit(self->object, cfg); filterx_expr_deinit(self->new_value, cfg); filterx_expr_deinit_method(s, cfg); diff --git a/lib/filterx/expr-template.c b/lib/filterx/expr-template.c index ea0f572652..f94716ad34 100644 --- a/lib/filterx/expr-template.c +++ b/lib/filterx/expr-template.c @@ -25,6 +25,8 @@ #include "filterx/filterx-eval.h" #include "template/templates.h" #include "scratch-buffers.h" +#include "stats/stats-registry.h" +#include "stats/stats-cluster-single.h" typedef struct _FilterXTemplate { @@ -63,6 +65,34 @@ _free(FilterXExpr *s) filterx_expr_free_method(s); } +static gboolean +_template_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXTemplate *self = (FilterXTemplate *) s; + + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_template_evals_total", NULL, 0); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + + return filterx_expr_init_method(s, cfg); +} + +static void +_template_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXTemplate *self = (FilterXTemplate *) s; + + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_template_evals_total", NULL, 0); + stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + + filterx_expr_deinit_method(s, cfg); +} + /* NOTE: takes the object reference */ FilterXExpr * filterx_template_new(LogTemplate *template) @@ -70,6 +100,8 @@ filterx_template_new(LogTemplate *template) FilterXTemplate *self = g_new0(FilterXTemplate, 1); filterx_expr_init_instance(&self->super); + self->super.init = _template_init; + self->super.deinit = _template_deinit; self->super.eval = _eval; self->super.free_fn = _free; self->template = template; diff --git a/lib/filterx/expr-variable.c b/lib/filterx/expr-variable.c index fba8621490..5ed2e51ff5 100644 --- a/lib/filterx/expr-variable.c +++ b/lib/filterx/expr-variable.c @@ -27,6 +27,8 @@ #include "filterx/filterx-eval.h" #include "filterx/filterx-variable.h" #include "logmsg/logmsg.h" +#include "stats/stats-registry.h" +#include "stats/stats-cluster-single.h" typedef struct _FilterXVariableExpr @@ -173,6 +175,34 @@ _free(FilterXExpr *s) filterx_expr_free_method(s); } +static gboolean +_init(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXVariableExpr *self = (FilterXVariableExpr *) s; + + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_variable_evals_total", NULL, 0); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + + return filterx_expr_init_method(s, cfg); +} + +static void +_deinit(FilterXExpr *s, GlobalConfig *cfg) +{ + FilterXVariableExpr *self = (FilterXVariableExpr *) s; + + stats_lock(); + StatsClusterKey sc_key; + stats_cluster_single_key_set(&sc_key, "fx_variable_evals_total", NULL, 0); + stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + + return filterx_expr_deinit_method(s, cfg); +} + static FilterXExpr * filterx_variable_expr_new(FilterXString *name, FilterXVariableType type) { @@ -180,6 +210,8 @@ filterx_variable_expr_new(FilterXString *name, FilterXVariableType type) filterx_expr_init_instance(&self->super); self->super.free_fn = _free; + self->super.init = _init; + self->super.deinit = _deinit; self->super.eval = _eval; self->super._update_repr = _update_repr; self->super.assign = _assign;