Skip to content

Commit

Permalink
filterx: initialize filterx eval metrics in FilterXExpr
Browse files Browse the repository at this point in the history
Instead of coding this individually in all FilterXExpr derivatives.

Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed Jan 4, 2025
1 parent 2ec35d2 commit db11323
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 175 deletions.
12 changes: 0 additions & 12 deletions lib/filterx/expr-compound.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@ _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);
}

Expand All @@ -182,12 +176,6 @@ _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);
Expand Down
12 changes: 0 additions & 12 deletions lib/filterx/expr-condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ _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);
}

Expand All @@ -74,12 +68,6 @@ _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);
Expand Down
17 changes: 2 additions & 15 deletions lib/filterx/expr-function.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,26 +248,12 @@ filterx_function_optimize_method(FilterXFunction *s)
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);
}

Expand Down Expand Up @@ -309,11 +295,12 @@ _function_free(FilterXExpr *s)
void
filterx_function_init_instance(FilterXFunction *s, const gchar *function_name)
{
filterx_expr_init_instance(&s->super, "call");
filterx_expr_init_instance(&s->super, "func");
s->function_name = g_strdup_printf("%s()", function_name);
s->super.optimize = _function_optimize;
s->super.init = _function_init;
s->super.deinit = _function_deinit;
s->super.name = s->function_name;
s->super.free_fn = _function_free;
}

Expand Down
12 changes: 0 additions & 12 deletions lib/filterx/expr-get-subscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ _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);
}

Expand All @@ -143,12 +137,6 @@ _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);
Expand Down
12 changes: 0 additions & 12 deletions lib/filterx/expr-getattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ _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);
}

Expand All @@ -123,12 +117,6 @@ _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);
}
Expand Down
12 changes: 0 additions & 12 deletions lib/filterx/expr-set-subscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ _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);
}

Expand All @@ -194,12 +188,6 @@ _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);
Expand Down
12 changes: 0 additions & 12 deletions lib/filterx/expr-setattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ _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);
}

Expand All @@ -169,12 +163,6 @@ _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);
Expand Down
30 changes: 0 additions & 30 deletions lib/filterx/expr-template.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,43 +65,13 @@ _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)
{
FilterXTemplate *self = g_new0(FilterXTemplate, 1);

filterx_expr_init_instance(&self->super, "template");
self->super.init = _template_init;
self->super.deinit = _template_deinit;
self->super.eval = _eval;
self->super.free_fn = _free;
self->template = template;
Expand Down
30 changes: 0 additions & 30 deletions lib/filterx/expr-variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,43 +175,13 @@ _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)
{
FilterXVariableExpr *self = g_new0(FilterXVariableExpr, 1);

filterx_expr_init_instance(&self->super, "variable");
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;
Expand Down
59 changes: 32 additions & 27 deletions lib/filterx/filterx-expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,47 @@ filterx_expr_optimize(FilterXExpr *self)
return optimized;
}

static void
_init_sc_key_name(FilterXExpr *self, gchar *buf, gsize buf_len)
{
g_snprintf(buf, buf_len, "fx_%s_evals_total", self->type);
}

gboolean
filterx_expr_init_method(FilterXExpr *self, GlobalConfig *cfg)
{
gchar buf[64];

_init_sc_key_name(self, buf, sizeof(buf));
stats_lock();
StatsClusterKey sc_key;
StatsClusterLabel labels[1];
gint labels_len = 0;

if (self->name)
labels[labels_len++] = stats_cluster_label("name", self->name);
stats_cluster_single_key_set(&sc_key, buf, labels, labels_len);
stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->eval_count);
stats_unlock();
return TRUE;
}

void
filterx_expr_deinit_method(FilterXExpr *self, GlobalConfig *cfg)
{
gchar buf[64];

_init_sc_key_name(self, buf, sizeof(buf));
stats_lock();
StatsClusterKey sc_key;
StatsClusterLabel labels[1];
gint labels_len = 0;

if (self->name)
labels[labels_len++] = stats_cluster_label("name", self->name);
stats_cluster_single_key_set(&sc_key, buf, labels, labels_len);
stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->eval_count);
stats_unlock();
}

void
Expand Down Expand Up @@ -179,12 +211,6 @@ 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);
}
Expand All @@ -194,13 +220,6 @@ 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);
}
Expand Down Expand Up @@ -256,13 +275,6 @@ 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->super.type) };
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);
}

Expand All @@ -271,13 +283,6 @@ 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->super.type) };
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);
Expand Down
Loading

0 comments on commit db11323

Please sign in to comment.