From 06994c7113d1a2fb4019b5db624f49f21d8aa089 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 5 Jun 2017 17:25:11 -0400 Subject: [PATCH] lttng-live: populate trace name MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- plugins/ctf/lttng-live/lttng-live-internal.h | 8 +++++++- plugins/ctf/lttng-live/lttng-live.c | 15 +++++++++++++-- plugins/ctf/lttng-live/metadata.c | 11 ++++++++--- plugins/ctf/lttng-live/metadata.h | 4 ++-- plugins/ctf/lttng-live/viewer-connection.c | 10 ++++++++-- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/plugins/ctf/lttng-live/lttng-live-internal.h b/plugins/ctf/lttng-live/lttng-live-internal.h index 115ac76b..9aec9f7b 100644 --- a/plugins/ctf/lttng-live/lttng-live-internal.h +++ b/plugins/ctf/lttng-live/lttng-live-internal.h @@ -157,6 +157,9 @@ struct lttng_live_session { struct lttng_live_component *lttng_live; + GString *hostname; + GString *session_name; + uint64_t id; /* List of struct lttng_live_trace */ @@ -237,7 +240,10 @@ int lttng_live_detach_session(struct lttng_live_session *session); enum bt_ctf_lttng_live_iterator_status lttng_live_get_new_streams( struct lttng_live_session *session); -int lttng_live_add_session(struct lttng_live_component *lttng_live, uint64_t session_id); +int lttng_live_add_session(struct lttng_live_component *lttng_live, + uint64_t session_id, + const char *hostname, + const char *session_name); ssize_t lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp); diff --git a/plugins/ctf/lttng-live/lttng-live.c b/plugins/ctf/lttng-live/lttng-live.c index 33cd94a0..4954a3c9 100644 --- a/plugins/ctf/lttng-live/lttng-live.c +++ b/plugins/ctf/lttng-live/lttng-live.c @@ -233,7 +233,9 @@ void lttng_live_close_trace_streams(struct lttng_live_trace *trace) } BT_HIDDEN -int lttng_live_add_session(struct lttng_live_component *lttng_live, uint64_t session_id) +int lttng_live_add_session(struct lttng_live_component *lttng_live, + uint64_t session_id, const char *hostname, + const char *session_name) { int ret = 0; struct lttng_live_session *s; @@ -247,8 +249,11 @@ int lttng_live_add_session(struct lttng_live_component *lttng_live, uint64_t ses BT_INIT_LIST_HEAD(&s->traces); s->lttng_live = lttng_live; s->new_streams_needed = true; + s->hostname = g_string_new(hostname); + s->session_name = g_string_new(session_name); - BT_LOGI("Reading from session %" PRIu64, s->id); + BT_LOGI("Reading from session: %" PRIu64 " hostname: %s session_name: %s", + s->id, hostname, session_name); bt_list_add(&s->node, <tng_live->sessions); goto end; error: @@ -279,6 +284,12 @@ void lttng_live_destroy_session(struct lttng_live_session *session) lttng_live_close_trace_streams(trace); } bt_list_del(&session->node); + if (session->hostname) { + g_string_free(session->hostname, TRUE); + } + if (session->session_name) { + g_string_free(session->session_name, TRUE); + } g_free(session); } diff --git a/plugins/ctf/lttng-live/metadata.c b/plugins/ctf/lttng-live/metadata.c index b71a42a5..fcdb247e 100644 --- a/plugins/ctf/lttng-live/metadata.c +++ b/plugins/ctf/lttng-live/metadata.c @@ -229,10 +229,12 @@ end: BT_HIDDEN int lttng_live_metadata_create_stream(struct lttng_live_session *session, uint64_t ctf_trace_id, - uint64_t stream_id) + uint64_t stream_id, + const char *trace_name) { struct lttng_live_metadata *metadata = NULL; struct lttng_live_trace *trace; + const char *match; metadata = g_new0(struct lttng_live_metadata, 1); if (!metadata) { @@ -240,9 +242,12 @@ int lttng_live_metadata_create_stream(struct lttng_live_session *session, } metadata->stream_id = stream_id; //TODO: add clock offset option - //TODO: add (preferably unique) trace's name + match = strstr(trace_name, session->session_name->str); + if (!match) { + goto error; + } metadata->decoder = ctf_metadata_decoder_create(stderr, 0, - "lttng-live"); + match); if (!metadata->decoder) { goto error; } diff --git a/plugins/ctf/lttng-live/metadata.h b/plugins/ctf/lttng-live/metadata.h index 3d9f7b86..47e4fbb2 100644 --- a/plugins/ctf/lttng-live/metadata.h +++ b/plugins/ctf/lttng-live/metadata.h @@ -30,8 +30,8 @@ #include "lttng-live-internal.h" int lttng_live_metadata_create_stream(struct lttng_live_session *session, - uint64_t ctf_trace_id, - uint64_t stream_id); + uint64_t ctf_trace_id, uint64_t stream_id, + const char *trace_name); enum bt_ctf_lttng_live_iterator_status lttng_live_metadata_update( struct lttng_live_trace *trace); diff --git a/plugins/ctf/lttng-live/viewer-connection.c b/plugins/ctf/lttng-live/viewer-connection.c index 9f61f160..81f043fa 100644 --- a/plugins/ctf/lttng-live/viewer-connection.c +++ b/plugins/ctf/lttng-live/viewer-connection.c @@ -671,12 +671,17 @@ int lttng_live_query_session_ids(struct lttng_live_component *lttng_live) lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0'; session_id = be64toh(lsession.id); + BT_LOGD("Adding session %" PRIu64 " hostname: %s session_name: %s", + session_id, lsession.hostname, lsession.session_name); + if ((strncmp(lsession.session_name, viewer_connection->session_name->str, MAXNAMLEN) == 0) && (strncmp(lsession.hostname, viewer_connection->target_hostname->str, MAXNAMLEN) == 0)) { - if (lttng_live_add_session(lttng_live, session_id)) { + if (lttng_live_add_session(lttng_live, session_id, + lsession.hostname, + lsession.session_name)) { goto error; } } @@ -771,7 +776,8 @@ int receive_streams(struct lttng_live_session *session, stream_id, stream.path_name, stream.channel_name); if (lttng_live_metadata_create_stream(session, - ctf_trace_id, stream_id)) { + ctf_trace_id, stream_id, + stream.path_name)) { BT_LOGE("Error creating metadata stream"); goto error; -- 2.34.1