Skip to content

Commit

Permalink
filterx: add operator eval metrics
Browse files Browse the repository at this point in the history
Signed-off-by: László Várady <[email protected]>
  • Loading branch information
MrAnno committed Nov 28, 2024
1 parent 0a279de commit e2574ba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/filterx/filterx-expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -181,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);
}

Expand All @@ -189,6 +212,13 @@ 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);
Expand Down
5 changes: 5 additions & 0 deletions lib/filterx/filterx-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "filterx-object.h"
#include "cfg-lexer.h"
#include "stats/stats-counter.h"

struct _FilterXExpr
{
Expand All @@ -35,6 +36,8 @@ struct _FilterXExpr
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
Expand Down Expand Up @@ -76,6 +79,8 @@ struct _FilterXExpr
static inline FilterXObject *
filterx_expr_eval(FilterXExpr *self)
{
stats_counter_inc(self->eval_count);

return self->eval(self);
}

Expand Down

0 comments on commit e2574ba

Please sign in to comment.