Skip to content

Commit

Permalink
filterx: add expression eval metrics
Browse files Browse the repository at this point in the history
Signed-off-by: László Várady <laszlo.varady@anno.io>
  • Loading branch information
MrAnno committed Nov 28, 2024
1 parent 0d3340e commit 2791e9b
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/filterx/expr-compound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdarg.h>

Expand All @@ -35,6 +37,7 @@ typedef struct _FilterXCompoundExpr
/* whether this is a statement expression */
gboolean return_value_of_last_expr;
GPtrArray *exprs;

} FilterXCompoundExpr;

static gboolean
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions lib/filterx/expr-condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions lib/filterx/expr-function.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions lib/filterx/expr-function.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

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

Expand All @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions lib/filterx/expr-getattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down
14 changes: 14 additions & 0 deletions lib/filterx/expr-set-subscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions lib/filterx/expr-setattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

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

0 comments on commit 2791e9b

Please sign in to comment.