diff --git a/lib/filterx/expr-assign.c b/lib/filterx/expr-assign.c index e2a5d23bc..0f4ff3baa 100644 --- a/lib/filterx/expr-assign.c +++ b/lib/filterx/expr-assign.c @@ -96,7 +96,7 @@ filterx_nullv_assign_new(FilterXExpr *lhs, FilterXExpr *rhs) { FilterXBinaryOp *self = g_new0(FilterXBinaryOp, 1); - filterx_binary_op_init_instance(self, lhs, rhs); + filterx_binary_op_init_instance(self, "nullv_assign", lhs, rhs); self->super.eval = _nullv_assign_eval; self->super.ignore_falsy_result = TRUE; return &self->super; @@ -108,7 +108,7 @@ filterx_assign_new(FilterXExpr *lhs, FilterXExpr *rhs) { FilterXBinaryOp *self = g_new0(FilterXBinaryOp, 1); - filterx_binary_op_init_instance(self, lhs, rhs); + filterx_binary_op_init_instance(self, "assign", lhs, rhs); self->super.eval = _assign_eval; self->super.ignore_falsy_result = TRUE; return &self->super; diff --git a/lib/filterx/expr-boolalg.c b/lib/filterx/expr-boolalg.c index 4fd3c903d..f4a9760a2 100644 --- a/lib/filterx/expr-boolalg.c +++ b/lib/filterx/expr-boolalg.c @@ -62,7 +62,7 @@ filterx_unary_not_new(FilterXExpr *operand) FilterXUnaryOp *self = g_new0(FilterXUnaryOp, 1); - filterx_unary_op_init_instance(self, operand); + filterx_unary_op_init_instance(self, "not", operand); self->super.eval = _eval_not; return &self->super; } @@ -115,7 +115,7 @@ filterx_binary_and_new(FilterXExpr *lhs, FilterXExpr *rhs) FilterXBinaryOp *self = g_new0(FilterXBinaryOp, 1); - filterx_binary_op_init_instance(self, lhs, rhs); + filterx_binary_op_init_instance(self, "and", lhs, rhs); if (filterx_expr_is_literal(lhs)) self->lhs = NULL; @@ -171,7 +171,7 @@ filterx_binary_or_new(FilterXExpr *lhs, FilterXExpr *rhs) FilterXBinaryOp *self = g_new0(FilterXBinaryOp, 1); - filterx_binary_op_init_instance(self, lhs, rhs); + filterx_binary_op_init_instance(self, "or", lhs, rhs); if (filterx_expr_is_literal(lhs)) self->lhs = NULL; diff --git a/lib/filterx/expr-comparison.c b/lib/filterx/expr-comparison.c index b40802b6d..8220b6770 100644 --- a/lib/filterx/expr-comparison.c +++ b/lib/filterx/expr-comparison.c @@ -253,7 +253,7 @@ filterx_comparison_new(FilterXExpr *lhs, FilterXExpr *rhs, gint operator) { FilterXComparison *self = g_new0(FilterXComparison, 1); - filterx_binary_op_init_instance(&self->super, lhs, rhs); + filterx_binary_op_init_instance(&self->super, "comparison", lhs, rhs); self->super.super.eval = _eval; self->super.super.free_fn = _filterx_comparison_free; self->operator = operator; diff --git a/lib/filterx/expr-compound.c b/lib/filterx/expr-compound.c index b324894c6..35f6d7d83 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 75011631d..95494fe34 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 408051995..013bcf7e0 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 819e0b736..0c1085f2a 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 6ccee3c26..32a1d51ce 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 781e64cfc..f85bf1585 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-isset.c b/lib/filterx/expr-isset.c index 56717f7ee..65989afad 100644 --- a/lib/filterx/expr-isset.c +++ b/lib/filterx/expr-isset.c @@ -36,7 +36,7 @@ FilterXExpr * filterx_isset_new(FilterXExpr *expr) { FilterXUnaryOp *self = g_new0(FilterXUnaryOp, 1); - filterx_unary_op_init_instance(self, expr); + filterx_unary_op_init_instance(self, "isset", expr); self->super.eval = _eval; return &self->super; } diff --git a/lib/filterx/expr-null-coalesce.c b/lib/filterx/expr-null-coalesce.c index e1cdf3b95..019ef8b14 100644 --- a/lib/filterx/expr-null-coalesce.c +++ b/lib/filterx/expr-null-coalesce.c @@ -76,7 +76,7 @@ filterx_null_coalesce_new(FilterXExpr *lhs, FilterXExpr *rhs) } FilterXNullCoalesce *self = g_new0(FilterXNullCoalesce, 1); - filterx_binary_op_init_instance(&self->super, lhs, rhs); + filterx_binary_op_init_instance(&self->super, "null_coalesce", lhs, rhs); self->super.super.eval = _eval; return &self->super.super; } diff --git a/lib/filterx/expr-plus.c b/lib/filterx/expr-plus.c index 2eb349c0a..f5e562f4a 100644 --- a/lib/filterx/expr-plus.c +++ b/lib/filterx/expr-plus.c @@ -71,7 +71,7 @@ FilterXExpr * filterx_operator_plus_new(FilterXExpr *lhs, FilterXExpr *rhs) { FilterXOperatorPlus *self = g_new0(FilterXOperatorPlus, 1); - filterx_binary_op_init_instance(&self->super, lhs, rhs); + filterx_binary_op_init_instance(&self->super, "plus", lhs, rhs); self->super.super.eval = _eval; self->super.super.free_fn = _filterx_operator_plus_free; diff --git a/lib/filterx/expr-set-subscript.c b/lib/filterx/expr-set-subscript.c index 341c63c7c..cfb5c100a 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 274161941..3151a7ed4 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 ea0f57265..f94716ad3 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 fba862149..5ed2e51ff 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; diff --git a/lib/filterx/filterx-expr.c b/lib/filterx/filterx-expr.c index de7280921..61af438c2 100644 --- a/lib/filterx/filterx-expr.c +++ b/lib/filterx/filterx-expr.c @@ -26,6 +26,8 @@ #include "cfg-source.h" #include "messages.h" #include "mainloop.h" +#include "stats/stats-registry.h" +#include "stats/stats-cluster-single.h" void filterx_expr_set_location_with_text(FilterXExpr *self, CfgLexer *lexer, CFG_LTYPE *lloc, const gchar *text) @@ -127,6 +129,13 @@ filterx_unary_op_init_method(FilterXExpr *s, GlobalConfig *cfg) if (!filterx_expr_init(self->operand, cfg)) return FALSE; + stats_lock(); + StatsClusterKey sc_key; + StatsClusterLabel labels[] = { stats_cluster_label("name", self->name) }; + stats_cluster_single_key_set(&sc_key, "fx_op_evals_total", labels, G_N_ELEMENTS(labels)); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + return filterx_expr_init_method(s, cfg); } @@ -135,6 +144,13 @@ filterx_unary_op_deinit_method(FilterXExpr *s, GlobalConfig *cfg) { FilterXUnaryOp *self = (FilterXUnaryOp *) s; + stats_lock(); + StatsClusterKey sc_key; + StatsClusterLabel labels[] = { stats_cluster_label("name", self->name) }; + stats_cluster_single_key_set(&sc_key, "fx_op_evals_total", labels, G_N_ELEMENTS(labels)); + 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); } @@ -149,13 +165,15 @@ filterx_unary_op_free_method(FilterXExpr *s) } void -filterx_unary_op_init_instance(FilterXUnaryOp *self, FilterXExpr *operand) +filterx_unary_op_init_instance(FilterXUnaryOp *self, const gchar *name, FilterXExpr *operand) { filterx_expr_init_instance(&self->super); self->super.init = filterx_unary_op_init_method; self->super.deinit = filterx_unary_op_deinit_method; self->super.free_fn = filterx_unary_op_free_method; self->operand = operand; + + self->name = name; } void @@ -179,6 +197,13 @@ filterx_binary_op_init_method(FilterXExpr *s, GlobalConfig *cfg) if (!filterx_expr_init(self->rhs, cfg)) return FALSE; + stats_lock(); + StatsClusterKey sc_key; + StatsClusterLabel labels[] = { stats_cluster_label("name", self->name) }; + stats_cluster_single_key_set(&sc_key, "fx_op_evals_total", labels, G_N_ELEMENTS(labels)); + stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + return filterx_expr_init_method(s, cfg); } @@ -187,13 +212,20 @@ filterx_binary_op_deinit_method(FilterXExpr *s, GlobalConfig *cfg) { FilterXBinaryOp *self = (FilterXBinaryOp *) s; + stats_lock(); + StatsClusterKey sc_key; + StatsClusterLabel labels[] = { stats_cluster_label("name", self->name) }; + stats_cluster_single_key_set(&sc_key, "fx_op_evals_total", labels, G_N_ELEMENTS(labels)); + stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count); + stats_unlock(); + filterx_expr_deinit(self->lhs, cfg); filterx_expr_deinit(self->rhs, cfg); filterx_expr_deinit_method(s, cfg); } void -filterx_binary_op_init_instance(FilterXBinaryOp *self, FilterXExpr *lhs, FilterXExpr *rhs) +filterx_binary_op_init_instance(FilterXBinaryOp *self, const gchar *name, FilterXExpr *lhs, FilterXExpr *rhs) { filterx_expr_init_instance(&self->super); self->super.init = filterx_binary_op_init_method; @@ -203,4 +235,6 @@ filterx_binary_op_init_instance(FilterXBinaryOp *self, FilterXExpr *lhs, FilterX g_assert(rhs); self->lhs = lhs; self->rhs = rhs; + + self->name = name; } diff --git a/lib/filterx/filterx-expr.h b/lib/filterx/filterx-expr.h index d889c0aaa..f67227fd8 100644 --- a/lib/filterx/filterx-expr.h +++ b/lib/filterx/filterx-expr.h @@ -27,14 +27,17 @@ #include "filterx-object.h" #include "cfg-lexer.h" +#include "stats/stats-counter.h" struct _FilterXExpr { - /* not thread-safe*/ + /* not thread-safe */ guint32 ref_cnt; const gchar *type; guint32 ignore_falsy_result:1, suppress_from_trace:1; + StatsCounterItem *eval_count; + /* evaluate expression */ FilterXObject *(*eval)(FilterXExpr *self); /* not to be used except for FilterXMessageRef, replace any cached values @@ -76,6 +79,8 @@ struct _FilterXExpr static inline FilterXObject * filterx_expr_eval(FilterXExpr *self) { + stats_counter_inc(self->eval_count); + return self->eval(self); } @@ -185,22 +190,24 @@ typedef struct _FilterXUnaryOp { FilterXExpr super; FilterXExpr *operand; + const gchar *name; } FilterXUnaryOp; gboolean filterx_unary_op_init_method(FilterXExpr *s, GlobalConfig *cfg); void filterx_unary_op_deinit_method(FilterXExpr *s, GlobalConfig *cfg); void filterx_unary_op_free_method(FilterXExpr *s); -void filterx_unary_op_init_instance(FilterXUnaryOp *self, FilterXExpr *operand); +void filterx_unary_op_init_instance(FilterXUnaryOp *self, const gchar *name, FilterXExpr *operand); typedef struct _FilterXBinaryOp { FilterXExpr super; FilterXExpr *lhs, *rhs; + const gchar *name; } FilterXBinaryOp; gboolean filterx_binary_op_init_method(FilterXExpr *s, GlobalConfig *cfg); void filterx_binary_op_deinit_method(FilterXExpr *s, GlobalConfig *cfg); void filterx_binary_op_free_method(FilterXExpr *s); -void filterx_binary_op_init_instance(FilterXBinaryOp *self, FilterXExpr *lhs, FilterXExpr *rhs); +void filterx_binary_op_init_instance(FilterXBinaryOp *self, const gchar *name, FilterXExpr *lhs, FilterXExpr *rhs); #endif diff --git a/news/fx-feature-398.md b/news/fx-feature-398.md new file mode 100644 index 000000000..6f6a49a32 --- /dev/null +++ b/news/fx-feature-398.md @@ -0,0 +1,5 @@ +Metrics for FilterX expression execution + +Metrics `syslogng_fx_*_evals_total` are available on `stats(level(3))`. +They can be used to gain insight on how FilterX expressions are executed on +different messages and paths and to find potential bottlenecks.