From a0a3bef9e447a220a36fb7cb4c3f60e4eafdec4d Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 26 Mar 2013 11:02:54 -0400 Subject: [PATCH] Don't rely on explicit context for filtering Now $ctx can be used without having the contexts explicitly enabled on the channel. Signed-off-by: Mathieu Desnoyers --- include/lttng/ust-events.h | 3 +++ liblttng-ust/lttng-context.c | 34 +++++++++++++++++++++++++ liblttng-ust/lttng-filter-interpreter.c | 7 +++-- liblttng-ust/lttng-filter.c | 4 +-- liblttng-ust/lttng-ust-comm.c | 2 ++ 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index c79bbed6..d3702517 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -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); diff --git a/liblttng-ust/lttng-context.c b/liblttng-ust/lttng-context.c index fc2ab4f5..ecee2344 100644 --- a/liblttng-ust/lttng-context.c +++ b/liblttng-ust/lttng-context.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,11 @@ * 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(<tng_static_ctx); + if (ret) { + WARN("Cannot add context lttng_add_pthread_id_to_ctx"); + } + ret = lttng_add_vtid_to_ctx(<tng_static_ctx); + if (ret) { + WARN("Cannot add context lttng_add_vtid_to_ctx"); + } + ret = lttng_add_vpid_to_ctx(<tng_static_ctx); + if (ret) { + WARN("Cannot add context lttng_add_vpid_to_ctx"); + } + ret = lttng_add_procname_to_ctx(<tng_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; +} diff --git a/liblttng-ust/lttng-filter-interpreter.c b/liblttng-ust/lttng-filter-interpreter.c index 1f43dece..29bcaeff 100644 --- a/liblttng-ust/lttng-filter-interpreter.c +++ b/liblttng-ust/lttng-filter-interpreter.c @@ -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 = <tng_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 = <tng_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 = <tng_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)); diff --git a/liblttng-ust/lttng-filter.c b/liblttng-ust/lttng-filter.c index 4bb7d4dc..d71485d1 100644 --- a/liblttng-ust/lttng-filter.c +++ b/liblttng-ust/lttng-filter.c @@ -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 = <tng_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) { diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 18763c45..86af682b 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -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(); -- 2.34.1