X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Ftrace-kernel.c;h=f38cf3d8d0a6f96a48250cafd58b96a8f53feb36;hp=48f6eea7d60e6db4b2e79766c11ac1b6f3a1f12a;hb=5922e6c21e0ad1a5050b2440bcc14f15abd9c5f4;hpb=d14d33bf091e72b23b1f90ea18a0a01bed098b76 diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index 48f6eea7d..f38cf3d8d 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.c @@ -24,6 +24,7 @@ #include #include +#include "consumer.h" #include "trace-kernel.h" /* @@ -84,14 +85,13 @@ error: */ struct ltt_kernel_session *trace_kernel_create_session(char *path) { - int ret; - struct ltt_kernel_session *lks; + struct ltt_kernel_session *lks = NULL; /* Allocate a new ltt kernel session */ lks = zmalloc(sizeof(struct ltt_kernel_session)); if (lks == NULL) { PERROR("create kernel session zmalloc"); - goto error; + goto alloc_error; } /* Init data structure */ @@ -100,19 +100,46 @@ struct ltt_kernel_session *trace_kernel_create_session(char *path) lks->channel_count = 0; lks->stream_count_global = 0; lks->metadata = NULL; - lks->consumer_fd = -1; CDS_INIT_LIST_HEAD(&lks->channel_list.head); - /* Set session path */ - ret = asprintf(&lks->trace_path, "%s/kernel", path); - if (ret < 0) { - PERROR("asprintf kernel traces path"); + lks->consumer = consumer_create_output(CONSUMER_DST_LOCAL); + if (lks->consumer == NULL) { 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; + + if (path && strlen(path) > 0) { + int ret; + + /* Use the default consumer output which is the tracing session path. */ + ret = snprintf(lks->consumer->dst.trace_path, PATH_MAX, + "%s" DEFAULT_KERNEL_TRACE_DIR, path); + if (ret < 0) { + PERROR("snprintf consumer trace path"); + goto error; + } + + /* Set session path */ + ret = asprintf(&lks->trace_path, "%s" DEFAULT_KERNEL_TRACE_DIR, path); + if (ret < 0) { + PERROR("asprintf kernel traces path"); + goto error; + } + } + return lks; error: + free(lks); + +alloc_error: return NULL; } @@ -121,9 +148,9 @@ error: * * Return pointer to structure or NULL. */ -struct ltt_kernel_channel *trace_kernel_create_channel(struct lttng_channel *chan, char *path) +struct ltt_kernel_channel *trace_kernel_create_channel( + struct lttng_channel *chan, char *path) { - int ret; struct ltt_kernel_channel *lkc; lkc = zmalloc(sizeof(struct ltt_kernel_channel)); @@ -147,12 +174,6 @@ struct ltt_kernel_channel *trace_kernel_create_channel(struct lttng_channel *cha /* Init linked list */ CDS_INIT_LIST_HEAD(&lkc->events_list.head); CDS_INIT_LIST_HEAD(&lkc->stream_list.head); - /* Set default trace output path */ - ret = asprintf(&lkc->pathname, "%s", path); - if (ret < 0) { - PERROR("asprintf kernel create channel"); - goto error; - } return lkc; @@ -223,11 +244,12 @@ struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev) lke->fd = -1; lke->event = attr; lke->enabled = 1; - lke->ctx = NULL; return lke; error: + free(lke); + free(attr); return NULL; } @@ -236,9 +258,8 @@ error: * * Return pointer to structure or NULL. */ -struct ltt_kernel_metadata *trace_kernel_create_metadata(char *path) +struct ltt_kernel_metadata *trace_kernel_create_metadata(void) { - int ret; struct ltt_kernel_metadata *lkm; struct lttng_channel *chan; @@ -251,7 +272,7 @@ struct ltt_kernel_metadata *trace_kernel_create_metadata(char *path) /* Set default attributes */ chan->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE; - chan->attr.subbuf_size = DEFAULT_METADATA_SUBBUF_SIZE; + chan->attr.subbuf_size = default_get_metadata_subbuf_size(); chan->attr.num_subbuf = DEFAULT_METADATA_SUBBUF_NUM; chan->attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER; chan->attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER; @@ -260,16 +281,12 @@ struct ltt_kernel_metadata *trace_kernel_create_metadata(char *path) /* Init metadata */ lkm->fd = -1; lkm->conf = chan; - /* Set default metadata path */ - ret = asprintf(&lkm->pathname, "%s/metadata", path); - if (ret < 0) { - PERROR("asprintf kernel metadata"); - goto error; - } return lkm; error: + free(lkm); + free(chan); return NULL; } @@ -279,8 +296,10 @@ error: * * Return pointer to structure or NULL. */ -struct ltt_kernel_stream *trace_kernel_create_stream(void) +struct ltt_kernel_stream *trace_kernel_create_stream(const char *name, + unsigned int count) { + int ret; struct ltt_kernel_stream *lks; lks = zmalloc(sizeof(struct ltt_kernel_stream)); @@ -289,9 +308,16 @@ struct ltt_kernel_stream *trace_kernel_create_stream(void) goto error; } + /* Set name */ + ret = snprintf(lks->name, sizeof(lks->name), "%s_%d", name, count); + if (ret < 0) { + PERROR("snprintf stream name"); + goto error; + } + lks->name[sizeof(lks->name) - 1] = '\0'; + /* Init stream */ lks->fd = -1; - lks->pathname = NULL; lks->state = 0; return lks; @@ -305,11 +331,11 @@ error: */ void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream) { - int ret; - DBG("[trace] Closing stream fd %d", stream->fd); /* Close kernel fd */ if (stream->fd >= 0) { + int ret; + ret = close(stream->fd); if (ret) { PERROR("close"); @@ -318,7 +344,6 @@ void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream) /* Remove from stream list */ cds_list_del(&stream->list); - free(stream->pathname); free(stream); } @@ -327,9 +352,9 @@ void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream) */ void trace_kernel_destroy_event(struct ltt_kernel_event *event) { - int ret; - if (event->fd >= 0) { + int ret; + DBG("[trace] Closing event fd %d", event->fd); /* Close kernel fd */ ret = close(event->fd); @@ -344,7 +369,6 @@ void trace_kernel_destroy_event(struct ltt_kernel_event *event) cds_list_del(&event->list); free(event->event); - free(event->ctx); free(event); } @@ -379,7 +403,6 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel) /* Remove from channel list */ cds_list_del(&channel->list); - free(channel->pathname); free(channel->channel); free(channel->ctx); free(channel); @@ -390,11 +413,11 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel) */ void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata) { - int ret; - DBG("[trace] Closing metadata fd %d", metadata->fd); /* Close kernel fd */ if (metadata->fd >= 0) { + int ret; + ret = close(metadata->fd); if (ret) { PERROR("close"); @@ -402,7 +425,6 @@ void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata) } free(metadata->conf); - free(metadata->pathname); free(metadata); } @@ -439,6 +461,10 @@ void trace_kernel_destroy_session(struct ltt_kernel_session *session) trace_kernel_destroy_channel(channel); } + /* Wipe consumer output object */ + consumer_destroy_output(session->consumer); + consumer_destroy_output(session->tmp_consumer); + free(session->trace_path); free(session); }