Don't rely on explicit context for filtering
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 26 Mar 2013 15:02:54 +0000 (11:02 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 27 Mar 2013 17:32:20 +0000 (13:32 -0400)
Now $ctx can be used without having the contexts explicitly enabled on
the channel.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/ust-events.h
liblttng-ust/lttng-context.c
liblttng-ust/lttng-filter-interpreter.c
liblttng-ust/lttng-filter.c
liblttng-ust/lttng-ust-comm.c

index c79bbed62174c920efcc0b891b94bb3479295cbe..d370251783d8e9778fb8878f8aceba95a5cbbf40 100644 (file)
@@ -516,6 +516,9 @@ int lttng_enabler_attach_context(struct lttng_enabler *enabler,
 
 int lttng_attach_context(struct lttng_ust_context *context_param,
                struct lttng_ctx **ctx, struct lttng_session *session);
+void lttng_context_init(void);
+void lttng_context_exit(void);
+struct lttng_ctx *lttng_static_ctx;    /* Used by filtering */
 
 void lttng_transport_register(struct lttng_transport *transport);
 void lttng_transport_unregister(struct lttng_transport *transport);
index fc2ab4f570b8182ef69f44a8e3375e5adcde1630..ecee23445787bce42397e96c200537b1385017ef 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
+#include <usterr-signal-safe.h>
 #include <helper.h>
 #include <string.h>
 #include <assert.h>
  * same context performed by the same thread return the same result.
  */
 
+/*
+ * Static array of contexts, for $ctx filters.
+ */
+struct lttng_ctx *lttng_static_ctx;
+
 int lttng_find_context(struct lttng_ctx *ctx, const char *name)
 {
        unsigned int i;
@@ -120,3 +126,31 @@ void lttng_destroy_context(struct lttng_ctx *ctx)
        free(ctx->fields);
        free(ctx);
 }
+
+void lttng_context_init(void)
+{
+       int ret;
+
+       ret = lttng_add_pthread_id_to_ctx(&lttng_static_ctx);
+       if (ret) {
+               WARN("Cannot add context lttng_add_pthread_id_to_ctx");
+       }
+       ret = lttng_add_vtid_to_ctx(&lttng_static_ctx);
+       if (ret) {
+               WARN("Cannot add context lttng_add_vtid_to_ctx");
+       }
+       ret = lttng_add_vpid_to_ctx(&lttng_static_ctx);
+       if (ret) {
+               WARN("Cannot add context lttng_add_vpid_to_ctx");
+       }
+       ret = lttng_add_procname_to_ctx(&lttng_static_ctx);
+       if (ret) {
+               WARN("Cannot add context lttng_add_procname_to_ctx");
+       }
+}
+
+void lttng_context_exit(void)
+{
+       lttng_destroy_context(lttng_static_ctx);
+       lttng_static_ctx = NULL;
+}
index 1f43decee2e32414cb71b3f06e2cd2e9d3afbbaf..29bcaeffa0656cacea08f59f5c6b782bb23c1af7 100644 (file)
@@ -176,7 +176,6 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data,
                const char *filter_stack_data)
 {
        struct bytecode_runtime *bytecode = filter_data;
-       struct lttng_ctx *ctx = bytecode->p.bc->enabler->chan->ctx;
        void *pc, *next_pc, *start_pc;
        int ret = -EINVAL;
        uint64_t retval = 0;
@@ -864,7 +863,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data,
 
                        dbg_printf("get context ref offset %u type string\n",
                                ref->offset);
-                       ctx_field = &ctx->fields[ref->offset];
+                       ctx_field = &lttng_static_ctx->fields[ref->offset];
                        ctx_field->get_value(ctx_field, &v);
                        estack_push(stack, top, ax, bx);
                        estack_ax(stack, top)->u.s.str = v.str;
@@ -889,7 +888,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data,
 
                        dbg_printf("get context ref offset %u type s64\n",
                                ref->offset);
-                       ctx_field = &ctx->fields[ref->offset];
+                       ctx_field = &lttng_static_ctx->fields[ref->offset];
                        ctx_field->get_value(ctx_field, &v);
                        estack_push(stack, top, ax, bx);
                        estack_ax_v = v.s64;
@@ -907,7 +906,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data,
 
                        dbg_printf("get context ref offset %u type double\n",
                                ref->offset);
-                       ctx_field = &ctx->fields[ref->offset];
+                       ctx_field = &lttng_static_ctx->fields[ref->offset];
                        ctx_field->get_value(ctx_field, &v);
                        estack_push(stack, top, ax, bx);
                        memcpy(&estack_ax(stack, top)->u.d, &v.d, sizeof(struct literal_double));
index 4bb7d4dc87f0793705a11804d7fe91fefab5a427..d71485d166b30bc839b0b71dbd53307aae265def 100644 (file)
@@ -232,7 +232,7 @@ int apply_context_reloc(struct lttng_event *event,
        dbg_printf("Apply context reloc: %u %s\n", reloc_offset, context_name);
 
        /* Get context index */
-       idx = lttng_get_context_index(event->chan->ctx, context_name);
+       idx = lttng_get_context_index(lttng_static_ctx, context_name);
        if (idx < 0)
                return -ENOENT;
 
@@ -241,7 +241,7 @@ int apply_context_reloc(struct lttng_event *event,
                return -EINVAL;
 
        /* Get context return type */
-       ctx_field = &event->chan->ctx->fields[idx];
+       ctx_field = &lttng_static_ctx->fields[idx];
        op = (struct load_op *) &runtime->data[reloc_offset];
        field_ref = (struct field_ref *) op->data;
        switch (ctx_field->event_field.type.atype) {
index 18763c45fd3a9c0e499f50ddf657b2b3996c0f29..86af682b110024c5b1c6f73bb4b34d4ccc29d648 100644 (file)
@@ -1123,6 +1123,7 @@ void __attribute__((constructor)) lttng_ust_init(void)
        lttng_ring_buffer_client_overwrite_rt_init();
        lttng_ring_buffer_client_discard_init();
        lttng_ring_buffer_client_discard_rt_init();
+       lttng_context_init();
 
        timeout_mode = get_constructor_timeout(&constructor_timeout);
 
@@ -1225,6 +1226,7 @@ void lttng_ust_cleanup(int exiting)
         */
        lttng_ust_abi_exit();
        lttng_ust_events_exit();
+       lttng_context_exit();
        lttng_ring_buffer_client_discard_rt_exit();
        lttng_ring_buffer_client_discard_exit();
        lttng_ring_buffer_client_overwrite_rt_exit();
This page took 0.028148 seconds and 4 git commands to generate.