From 40fdb48ce1c51e8d31c44e1bc77e279549c2be7b Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Thu, 11 Apr 2024 16:57:55 +0200 Subject: [PATCH] filterx: add dirty tracking to FilterXScope Signed-off-by: Balazs Scheidler --- lib/filterx/filterx-eval.c | 1 + lib/filterx/filterx-scope.c | 29 +++++++++++++++++++++++++++++ lib/filterx/filterx-scope.h | 2 ++ 3 files changed, 32 insertions(+) diff --git a/lib/filterx/filterx-eval.c b/lib/filterx/filterx-eval.c index 01cef82979b..17e043ac76f 100644 --- a/lib/filterx/filterx-eval.c +++ b/lib/filterx/filterx-eval.c @@ -118,6 +118,7 @@ filterx_eval_exec_statements(FilterXScope *scope, GList *statements, LogMessage /* NOTE: we only store the results into the message if the entire evaluation was successful */ success = TRUE; fail: + filterx_scope_set_dirty(scope); filterx_eval_set_context(NULL); return success; } diff --git a/lib/filterx/filterx-scope.c b/lib/filterx/filterx-scope.c index b0e7b837d96..9fed2310bbf 100644 --- a/lib/filterx/filterx-scope.c +++ b/lib/filterx/filterx-scope.c @@ -102,6 +102,7 @@ struct _FilterXScope GArray *variables; GPtrArray *weak_refs; gboolean write_protected; + gboolean dirty; }; static gboolean @@ -137,6 +138,18 @@ _lookup_variable(FilterXScope *self, FilterXVariableHandle handle, FilterXVariab return FALSE; } +void +filterx_scope_set_dirty(FilterXScope *self) +{ + self->dirty = TRUE; +} + +gboolean +filterx_scope_is_dirty(FilterXScope *self) +{ + return self->dirty; +} + FilterXVariableHandle filterx_scope_map_variable_to_handle(const gchar *name, FilterXVariableType type) { @@ -199,6 +212,14 @@ filterx_scope_store_weak_ref(FilterXScope *self, FilterXObject *object) void filterx_scope_sync(FilterXScope *self, LogMessage *msg) { + + if (!self->dirty) + { + msg_trace("Filterx sync: not syncing as scope is not dirty", + evt_tag_printf("scope", "%p", self)); + return; + } + GString *buffer = scratch_buffers_alloc(); for (gint i = 0; i < self->variables->len; i++) @@ -255,6 +276,7 @@ filterx_scope_sync(FilterXScope *self, LogMessage *msg) evt_tag_str("variable", log_msg_get_value_name(filterx_variable_get_nv_handle(v), NULL))); } } + self->dirty = FALSE; } FilterXScope * @@ -290,6 +312,13 @@ filterx_scope_clone(FilterXScope *other) } } + if (other->variables->len > 0) + self->dirty = other->dirty; + msg_trace("Filterx clone finished", + evt_tag_printf("scope", "%p", self), + evt_tag_printf("other", "%p", other), + evt_tag_int("dirty", self->dirty), + evt_tag_int("write_protected", self->write_protected)); /* NOTE: we don't clone weak references, those only relate to mutable * objects, which we are cloning anyway */ return self; diff --git a/lib/filterx/filterx-scope.h b/lib/filterx/filterx-scope.h index 00ffc0ea6f2..29321913f9f 100644 --- a/lib/filterx/filterx-scope.h +++ b/lib/filterx/filterx-scope.h @@ -56,6 +56,8 @@ void filterx_variable_mark_declared(FilterXVariable *v); */ typedef struct _FilterXScope FilterXScope; +void filterx_scope_set_dirty(FilterXScope *self); +gboolean filterx_scope_is_dirty(FilterXScope *self); void filterx_scope_sync(FilterXScope *self, LogMessage *msg); FilterXVariableHandle filterx_scope_map_variable_to_handle(const gchar *name, FilterXVariableType type);