X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Ftrace-kernel.c;h=d6ee8e8afb23401b2420e430bdd892dd0acc714d;hp=8e074fd91b0dcbe829f8c053d32ac6e92766d32c;hb=e9404c27e7cc9d841785e6c4292c1add19fbc1cc;hpb=645328ae989e5f50a3a49c1ac34b2fee287a3d7b diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index 8e074fd91..d6ee8e8af 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.c @@ -15,7 +15,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE +#define _LGPL_SOURCE #include #include #include @@ -26,6 +26,8 @@ #include "consumer.h" #include "trace-kernel.h" +#include "lttng-sessiond.h" +#include "notification-thread-commands.h" /* * Find the channel name for the given kernel session. @@ -57,26 +59,79 @@ struct ltt_kernel_channel *trace_kernel_get_channel_by_name( return NULL; } +/* + * Find the event for the given channel. + */ +struct ltt_kernel_event *trace_kernel_find_event( + char *name, struct ltt_kernel_channel *channel, + enum lttng_event_type type, + struct lttng_filter_bytecode *filter) +{ + struct ltt_kernel_event *ev; + int found = 0; + + assert(name); + assert(channel); + + cds_list_for_each_entry(ev, &channel->events_list.head, list) { + if (type != LTTNG_EVENT_ALL && ev->type != type) { + continue; + } + if (strcmp(name, ev->event->name)) { + continue; + } + if ((ev->filter && !filter) || (!ev->filter && filter)) { + continue; + } + if (ev->filter && filter) { + if (ev->filter->len != filter->len || + memcmp(ev->filter->data, filter->data, + filter->len) != 0) { + continue; + } + } + found = 1; + break; + } + if (found) { + DBG("Found event %s for channel %s", name, + channel->channel->name); + return ev; + } else { + return NULL; + } +} + /* * Find the event name for the given channel. */ struct ltt_kernel_event *trace_kernel_get_event_by_name( - char *name, struct ltt_kernel_channel *channel) + char *name, struct ltt_kernel_channel *channel, + enum lttng_event_type type) { struct ltt_kernel_event *ev; + int found = 0; assert(name); assert(channel); cds_list_for_each_entry(ev, &channel->events_list.head, list) { - if (strcmp(name, ev->event->name) == 0) { - DBG("Found event by name %s for channel %s", name, - channel->channel->name); - return ev; + if (type != LTTNG_EVENT_ALL && ev->type != type) { + continue; + } + if (strcmp(name, ev->event->name)) { + continue; } + found = 1; + break; + } + if (found) { + DBG("Found event %s for channel %s", name, + channel->channel->name); + return ev; + } else { + return NULL; } - - return NULL; } /* @@ -108,14 +163,6 @@ struct ltt_kernel_session *trace_kernel_create_session(void) goto error; } - /* - * The tmp_consumer stays NULL until a set_consumer_uri command is - * executed. At this point, the consumer should be nullify until an - * enable_consumer command. This assignment is symbolic since we've zmalloc - * the struct. - */ - lks->tmp_consumer = NULL; - return lks; error: @@ -134,6 +181,7 @@ struct ltt_kernel_channel *trace_kernel_create_channel( struct lttng_channel *chan) { struct ltt_kernel_channel *lkc; + struct lttng_channel_extended *extended; assert(chan); @@ -146,10 +194,18 @@ struct ltt_kernel_channel *trace_kernel_create_channel( lkc->channel = zmalloc(sizeof(struct lttng_channel)); if (lkc->channel == NULL) { PERROR("lttng_channel zmalloc"); - free(lkc); + goto error; + } + + extended = zmalloc(sizeof(struct lttng_channel_extended)); + if (!extended) { + PERROR("lttng_channel_channel zmalloc"); goto error; } memcpy(lkc->channel, chan, sizeof(struct lttng_channel)); + memcpy(extended, chan->attr.extended.ptr, sizeof(struct lttng_channel_extended)); + lkc->channel->attr.extended.ptr = extended; + extended = NULL; /* * If we receive an empty string for channel name, it means the @@ -173,6 +229,11 @@ struct ltt_kernel_channel *trace_kernel_create_channel( return lkc; error: + if (lkc) { + free(lkc->channel); + } + free(extended); + free(lkc); return NULL; } @@ -196,16 +257,20 @@ struct ltt_kernel_context *trace_kernel_create_context( memcpy(&kctx->ctx, ctx, sizeof(kctx->ctx)); } + CDS_INIT_LIST_HEAD(&kctx->list); + error: return kctx; } /* * Allocate and initialize a kernel event. Set name and event type. + * We own filter_expression, and filter. * * Return pointer to structure or NULL. */ -struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev) +struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev, + char *filter_expression, struct lttng_filter_bytecode *filter) { struct ltt_kernel_event *lke; struct lttng_kernel_event *attr; @@ -264,10 +329,14 @@ struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev) lke->fd = -1; lke->event = attr; lke->enabled = 1; + lke->filter_expression = filter_expression; + lke->filter = filter; return lke; error: + free(filter_expression); + free(filter); free(lke); free(attr); return NULL; @@ -395,6 +464,9 @@ void trace_kernel_destroy_event(struct ltt_kernel_event *event) /* Remove from event list */ cds_list_del(&event->list); + free(event->filter_expression); + free(event->filter); + free(event->event); free(event); } @@ -419,6 +491,7 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel) struct ltt_kernel_event *event, *etmp; struct ltt_kernel_context *ctx, *ctmp; int ret; + enum lttng_error_code status; assert(channel); @@ -449,6 +522,11 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel) /* Remove from channel list */ cds_list_del(&channel->list); + status = notification_thread_command_remove_channel( + notification_thread_handle, + channel->fd, LTTNG_DOMAIN_KERNEL); + assert(status == LTTNG_OK); + free(channel->channel->attr.extended.ptr); free(channel->channel); free(channel); } @@ -513,8 +591,7 @@ void trace_kernel_destroy_session(struct ltt_kernel_session *session) } /* Wipe consumer output object */ - consumer_destroy_output(session->consumer); - consumer_destroy_output(session->tmp_consumer); + consumer_output_put(session->consumer); free(session); }