From: David Goulet Date: Fri, 27 May 2011 18:29:12 +0000 (-0400) Subject: Add kernel trace destroy functions X-Git-Tag: v2.0-pre1~107 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c363b55d55c5b1d0f43d7d8c2938b5bea842d6eb;p=lttng-tools.git Add kernel trace destroy functions Adds clean trace data structure cleanup using trace_destroy_kernel_* functions. Signed-off-by: David Goulet --- diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index eb5d47f62..722402311 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -90,50 +90,6 @@ static sem_t kconsumerd_sem; static pthread_mutex_t kconsumerd_pid_mutex; /* Mutex to control kconsumerd pid assignation */ -/* - * free_kernel_session - * - * Free all data structure inside a kernel session and the session pointer. - */ -static void free_kernel_session(struct ltt_kernel_session *session) -{ - struct ltt_kernel_channel *chan; - struct ltt_kernel_stream *stream; - struct ltt_kernel_event *event; - - /* Clean metadata */ - close(session->metadata_stream_fd); - close(session->metadata->fd); - free(session->metadata->conf); - free(session->metadata); - - cds_list_for_each_entry(chan, &session->channel_list.head, list) { - /* Clean all event(s) */ - cds_list_for_each_entry(event, &chan->events_list.head, list) { - close(event->fd); - free(event->event); - free(event); - } - - /* Clean streams */ - cds_list_for_each_entry(stream, &chan->stream_list.head, list) { - close(stream->fd); - free(stream->pathname); - free(stream); - } - /* Clean channel */ - close(chan->fd); - free(chan->channel); - free(chan->pathname); - free(chan); - } - - close(session->fd); - free(session); - - DBG("All kernel session data structures freed"); -} - /* * teardown_kernel_session * @@ -144,7 +100,7 @@ static void teardown_kernel_session(struct ltt_session *session) { if (session->kernel_session != NULL) { DBG("Tearing down kernel session"); - free_kernel_session(session->kernel_session); + trace_destroy_kernel_session(session->kernel_session); /* Extra precaution */ session->kernel_session = NULL; /* Decrement session count */ diff --git a/ltt-sessiond/trace.c b/ltt-sessiond/trace.c index 8b1d15e10..5214cddfc 100644 --- a/ltt-sessiond/trace.c +++ b/ltt-sessiond/trace.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "ltt-sessiond.h" @@ -207,3 +208,79 @@ struct ltt_kernel_stream *trace_create_kernel_stream(void) error: return NULL; } + +void trace_destroy_kernel_stream(struct ltt_kernel_stream *stream) +{ + /* Close kernel fd */ + close(stream->fd); + free(stream->pathname); + + /* Remove from stream list */ + cds_list_del(&stream->list); + free(stream); +} + +void trace_destroy_kernel_event(struct ltt_kernel_event *event) +{ + /* Close kernel fd */ + close(event->fd); + /* Free attributes */ + free(event->event); + + /* Remove from event list */ + cds_list_del(&event->list); + free(event); +} + +void trace_destroy_kernel_channel(struct ltt_kernel_channel *channel) +{ + struct ltt_kernel_stream *stream; + struct ltt_kernel_event *event; + + /* Close kernel fd */ + close(channel->fd); + free(channel->pathname); + /* Free attributes structure */ + free(channel->channel); + + /* For each stream in the channel list */ + cds_list_for_each_entry(stream, &channel->stream_list.head, list) { + trace_destroy_kernel_stream(stream); + } + + /* For each event in the channel list */ + cds_list_for_each_entry(event, &channel->events_list.head, list) { + trace_destroy_kernel_event(event); + } + + /* Remove from channel list */ + cds_list_del(&channel->list); + free(channel); +} + +void trace_destroy_kernel_metadata(struct ltt_kernel_metadata *metadata) +{ + /* Close kernel fd */ + close(metadata->fd); + /* Free attributes */ + free(metadata->conf); + + free(metadata); +} + +void trace_destroy_kernel_session(struct ltt_kernel_session *session) +{ + struct ltt_kernel_channel *channel; + + /* Close kernel fds */ + close(session->fd); + close(session->metadata_stream_fd); + + trace_destroy_kernel_metadata(session->metadata); + + cds_list_for_each_entry(channel, &session->channel_list.head, list) { + trace_destroy_kernel_channel(channel); + } + + free(session); +} diff --git a/ltt-sessiond/trace.h b/ltt-sessiond/trace.h index 488fd757d..444126ba0 100644 --- a/ltt-sessiond/trace.h +++ b/ltt-sessiond/trace.h @@ -104,23 +104,23 @@ struct ltt_ust_marker { }; /* - * Function prototype + * Create functions malloc() the data structure. */ - -/* Kernel session */ struct ltt_kernel_session *trace_create_kernel_session(void); - -/* Kernel channel */ struct ltt_kernel_channel *trace_create_kernel_channel(void); - -/* Kernel event */ struct ltt_kernel_event *trace_create_kernel_event(char *name, enum lttng_kernel_instrumentation type); - -/* Kernel metadata */ struct ltt_kernel_metadata *trace_create_kernel_metadata(void); - -/* Kernel stream */ struct ltt_kernel_stream *trace_create_kernel_stream(void); +/* + * Destroy functions free() the data structure and remove from linked list if + * it's applies. + */ +void trace_destroy_kernel_session(struct ltt_kernel_session *session); +void trace_destroy_kernel_metadata(struct ltt_kernel_metadata *metadata); +void trace_destroy_kernel_channel(struct ltt_kernel_channel *channel); +void trace_destroy_kernel_event(struct ltt_kernel_event *event); +void trace_destroy_kernel_stream(struct ltt_kernel_stream *stream); + #endif /* _LTT_TRACE_H */