From 851de941fc0cdea645b905098fb8f2a61dfdd161 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 2 Nov 2019 22:09:50 -0400 Subject: [PATCH] ctf: save self_msg_iter in ctf_msg_iter when creating it I find it strange that we assign ctf_msg_iter::self_msg_iter in ctf_msg_iter_get_next_message. The self_msg_iter associated to the ctf_msg_iter is the same throughout its lifetime, and known at creation time, so we can assign it once at creation time. This patch adds a self_msg_iter to ctf_msg_iter_create to do that. It also removes the self_msg_iter parameter from ctf_msg_iter_get_next_message, since it is not needed anymore. Some ctf_msg_iter instances are created not in the context of a bt_self_message_iterator (e.g. when we create a src.ctf.fs component and we need to build an index). For those cases, we pass NULL. Change-Id: I0890dd2504097cf038fd40ec6a1ce1dc099008b2 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2323 Tested-by: jenkins --- src/plugins/ctf/common/msg-iter/msg-iter.c | 11 +++++++---- src/plugins/ctf/common/msg-iter/msg-iter.h | 13 ++++++++----- src/plugins/ctf/fs-src/data-stream-file.c | 2 +- src/plugins/ctf/fs-src/fs.c | 6 +++--- src/plugins/ctf/lttng-live/data-stream.c | 10 ++++++---- src/plugins/ctf/lttng-live/data-stream.h | 6 ++++-- src/plugins/ctf/lttng-live/lttng-live.c | 16 +++++++++------- src/plugins/ctf/lttng-live/lttng-live.h | 6 ++++-- src/plugins/ctf/lttng-live/viewer-connection.c | 15 +++++++++------ 9 files changed, 51 insertions(+), 34 deletions(-) diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.c b/src/plugins/ctf/common/msg-iter/msg-iter.c index 8f0d663c..5c99aed1 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.c +++ b/src/plugins/ctf/common/msg-iter/msg-iter.c @@ -2808,10 +2808,13 @@ end: } BT_HIDDEN -struct ctf_msg_iter *ctf_msg_iter_create(struct ctf_trace_class *tc, +struct ctf_msg_iter *ctf_msg_iter_create( + struct ctf_trace_class *tc, size_t max_request_sz, struct ctf_msg_iter_medium_ops medops, void *data, - bt_logging_level log_level, bt_self_component *self_comp) + bt_logging_level log_level, + bt_self_component *self_comp, + bt_self_message_iterator *self_msg_iter) { struct ctf_msg_iter *msg_it = NULL; struct bt_bfcr_cbs cbs = { @@ -2846,6 +2849,7 @@ struct ctf_msg_iter *ctf_msg_iter_create(struct ctf_trace_class *tc, goto end; } msg_it->self_comp = self_comp; + msg_it->self_msg_iter = self_msg_iter; msg_it->log_level = log_level; msg_it->meta.tc = tc; msg_it->medium.medops = medops; @@ -2912,14 +2916,13 @@ void ctf_msg_iter_destroy(struct ctf_msg_iter *msg_it) enum ctf_msg_iter_status ctf_msg_iter_get_next_message( struct ctf_msg_iter *msg_it, - bt_self_message_iterator *self_msg_iter, bt_message **message) + bt_message **message) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; bt_self_component *self_comp = msg_it->self_comp; BT_ASSERT_DBG(msg_it); BT_ASSERT_DBG(message); - msg_it->self_msg_iter = self_msg_iter; msg_it->set_stream = true; BT_COMP_LOGD("Getting next message: msg-it-addr=%p", msg_it); diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.h b/src/plugins/ctf/common/msg-iter/msg-iter.h index 3bd55a61..a5969f44 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.h +++ b/src/plugins/ctf/common/msg-iter/msg-iter.h @@ -252,10 +252,14 @@ struct ctf_msg_iter; * success, or \c NULL on error */ BT_HIDDEN -struct ctf_msg_iter *ctf_msg_iter_create(struct ctf_trace_class *tc, - size_t max_request_sz, struct ctf_msg_iter_medium_ops medops, - void *medops_data, bt_logging_level log_level, - bt_self_component *self_comp); +struct ctf_msg_iter *ctf_msg_iter_create( + struct ctf_trace_class *tc, + size_t max_request_sz, + struct ctf_msg_iter_medium_ops medops, + void *medops_data, + bt_logging_level log_level, + bt_self_component *self_comp, + bt_self_message_iterator *self_msg_iter); /** * Destroys a CTF message iterator, freeing all internal resources. @@ -287,7 +291,6 @@ void ctf_msg_iter_destroy(struct ctf_msg_iter *msg_iter); BT_HIDDEN enum ctf_msg_iter_status ctf_msg_iter_get_next_message( struct ctf_msg_iter *msg_it, - bt_self_message_iterator *msg_iter, bt_message **message); struct ctf_msg_iter_packet_properties { diff --git a/src/plugins/ctf/fs-src/data-stream-file.c b/src/plugins/ctf/fs-src/data-stream-file.c index 64f7f2be..b9c3ae9e 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.c +++ b/src/plugins/ctf/fs-src/data-stream-file.c @@ -755,7 +755,7 @@ bt_component_class_message_iterator_next_method_status ctf_fs_ds_file_next( bt_component_class_message_iterator_next_method_status status; msg_iter_status = ctf_msg_iter_get_next_message( - ds_file->msg_iter, ds_file->self_msg_iter, msg); + ds_file->msg_iter, msg); switch (msg_iter_status) { case CTF_MSG_ITER_STATUS_EOF: diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c index 28b728ae..43b131fa 100644 --- a/src/plugins/ctf/fs-src/fs.c +++ b/src/plugins/ctf/fs-src/fs.c @@ -281,7 +281,7 @@ bt_component_class_message_iterator_initialize_method_status ctf_fs_iterator_ini port_data->ds_file_group->ctf_fs_trace->metadata->tc, bt_common_get_page_size(msg_iter_data->log_level) * 8, ctf_fs_ds_file_medops, NULL, msg_iter_data->log_level, - self_comp); + self_comp, self_msg_iter); if (!msg_iter_data->msg_iter) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot create a CTF message iterator."); ret = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; @@ -738,7 +738,7 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, msg_iter = ctf_msg_iter_create(ctf_fs_trace->metadata->tc, bt_common_get_page_size(log_level) * 8, - ctf_fs_ds_file_medops, NULL, log_level, self_comp); + ctf_fs_ds_file_medops, NULL, log_level, self_comp, NULL); if (!msg_iter) { BT_COMP_LOGE_STR("Cannot create a CTF message iterator."); goto error; @@ -1442,7 +1442,7 @@ int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace, msg_iter = ctf_msg_iter_create(ctf_fs_trace->metadata->tc, bt_common_get_page_size(log_level) * 8, ctf_fs_ds_file_medops, - NULL, log_level, self_comp); + NULL, log_level, self_comp, NULL); if (!msg_iter) { /* ctf_msg_iter_create() logs errors. */ ret = -1; diff --git a/src/plugins/ctf/lttng-live/data-stream.c b/src/plugins/ctf/lttng-live/data-stream.c index b7083ab6..36a34eba 100644 --- a/src/plugins/ctf/lttng-live/data-stream.c +++ b/src/plugins/ctf/lttng-live/data-stream.c @@ -138,7 +138,8 @@ static struct ctf_msg_iter_medium_ops medops = { BT_HIDDEN enum lttng_live_iterator_status lttng_live_lazy_msg_init( - struct lttng_live_session *session) + struct lttng_live_session *session, + bt_self_message_iterator *self_msg_iter) { struct lttng_live_component *lttng_live = session->lttng_live_msg_iter->lttng_live_comp; @@ -169,7 +170,7 @@ enum lttng_live_iterator_status lttng_live_lazy_msg_init( trace->metadata->decoder); stream_iter->msg_iter = ctf_msg_iter_create(ctf_tc, lttng_live->max_query_size, medops, stream_iter, - log_level, self_comp); + log_level, self_comp, self_msg_iter); if (!stream_iter->msg_iter) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create CTF message iterator"); @@ -195,7 +196,8 @@ BT_HIDDEN struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( struct lttng_live_session *session, uint64_t ctf_trace_id, - uint64_t stream_id) + uint64_t stream_id, + bt_self_message_iterator *self_msg_iter) { struct lttng_live_stream_iterator *stream_iter; struct lttng_live_component *lttng_live; @@ -240,7 +242,7 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( BT_ASSERT(!stream_iter->msg_iter); stream_iter->msg_iter = ctf_msg_iter_create(ctf_tc, lttng_live->max_query_size, medops, stream_iter, - log_level, self_comp); + log_level, self_comp, self_msg_iter); if (!stream_iter->msg_iter) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create CTF message iterator"); diff --git a/src/plugins/ctf/lttng-live/data-stream.h b/src/plugins/ctf/lttng-live/data-stream.h index 1fcaced3..da3fbe72 100644 --- a/src/plugins/ctf/lttng-live/data-stream.h +++ b/src/plugins/ctf/lttng-live/data-stream.h @@ -32,12 +32,14 @@ #include "lttng-live.h" enum lttng_live_iterator_status lttng_live_lazy_msg_init( - struct lttng_live_session *session); + struct lttng_live_session *session, + bt_self_message_iterator *self_msg_iter); struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( struct lttng_live_session *session, uint64_t ctf_trace_id, - uint64_t stream_id); + uint64_t stream_id, + bt_self_message_iterator *self_msg_iter); void lttng_live_stream_iterator_destroy( struct lttng_live_stream_iterator *stream); diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index aeb9e80f..d2a92f3d 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -449,7 +449,8 @@ enum lttng_live_iterator_status lttng_live_get_session( if (!session->attached) { enum lttng_live_attach_session_status attach_status = - lttng_live_attach_session(session); + lttng_live_attach_session(session, + lttng_live_msg_iter->self_msg_iter); if (attach_status != LTTNG_LIVE_ATTACH_SESSION_STATUS_OK) { if (lttng_live_graph_is_canceled(lttng_live_msg_iter)) { /* @@ -469,7 +470,8 @@ enum lttng_live_iterator_status lttng_live_get_session( } } - status = lttng_live_get_new_streams(session); + status = lttng_live_get_new_streams(session, + lttng_live_msg_iter->self_msg_iter); if (status != LTTNG_LIVE_ITERATOR_STATUS_OK && status != LTTNG_LIVE_ITERATOR_STATUS_END) { goto end; @@ -501,7 +503,8 @@ enum lttng_live_iterator_status lttng_live_get_session( goto end; } } - status = lttng_live_lazy_msg_init(session); + status = lttng_live_lazy_msg_init(session, + lttng_live_msg_iter->self_msg_iter); end: return status; @@ -798,8 +801,8 @@ enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_active_data_ goto end; } - status = ctf_msg_iter_get_next_message(lttng_live_stream->msg_iter, - lttng_live_msg_iter->self_msg_iter, message); + status = ctf_msg_iter_get_next_message( + lttng_live_stream->msg_iter, message); switch (status) { case CTF_MSG_ITER_STATUS_EOF: ret = LTTNG_LIVE_ITERATOR_STATUS_END; @@ -846,8 +849,7 @@ enum lttng_live_iterator_status lttng_live_iterator_close_stream( * stream properly by emitting the necessary stream end message. */ enum ctf_msg_iter_status status = ctf_msg_iter_get_next_message( - stream_iter->msg_iter, lttng_live_msg_iter->self_msg_iter, - curr_msg); + stream_iter->msg_iter, curr_msg); if (status == CTF_MSG_ITER_STATUS_ERROR) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, diff --git a/src/plugins/ctf/lttng-live/lttng-live.h b/src/plugins/ctf/lttng-live/lttng-live.h index 533c3213..bb1c760e 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.h +++ b/src/plugins/ctf/lttng-live/lttng-live.h @@ -293,11 +293,13 @@ enum lttng_live_attach_session_status { }; enum lttng_live_attach_session_status lttng_live_attach_session( - struct lttng_live_session *session); + struct lttng_live_session *session, + bt_self_message_iterator *self_msg_iter); int lttng_live_detach_session(struct lttng_live_session *session); enum lttng_live_iterator_status lttng_live_get_new_streams( - struct lttng_live_session *session); + struct lttng_live_session *session, + bt_self_message_iterator *self_msg_iter); int lttng_live_add_session(struct lttng_live_msg_iter *lttng_live_msg_iter, uint64_t session_id, diff --git a/src/plugins/ctf/lttng-live/viewer-connection.c b/src/plugins/ctf/lttng-live/viewer-connection.c index 62918034..b1f37f04 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.c +++ b/src/plugins/ctf/lttng-live/viewer-connection.c @@ -812,7 +812,8 @@ error: static int receive_streams(struct lttng_live_session *session, - uint32_t stream_count) + uint32_t stream_count, + bt_self_message_iterator *self_msg_iter) { ssize_t ret_len; uint32_t i; @@ -862,7 +863,7 @@ int receive_streams(struct lttng_live_session *session, BT_COMP_LOGI(" stream %" PRIu64 " : %s/%s", stream_id, stream.path_name, stream.channel_name); live_stream = lttng_live_stream_iterator_create(session, - ctf_trace_id, stream_id); + ctf_trace_id, stream_id, self_msg_iter); if (!live_stream) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error creating stream"); @@ -878,7 +879,8 @@ error: BT_HIDDEN enum lttng_live_attach_session_status lttng_live_attach_session( - struct lttng_live_session *session) + struct lttng_live_session *session, + bt_self_message_iterator *self_msg_iter) { struct lttng_viewer_cmd cmd; enum lttng_live_attach_session_status attach_status; @@ -960,7 +962,7 @@ enum lttng_live_attach_session_status lttng_live_attach_session( } /* We receive the initial list of streams. */ - if (receive_streams(session, streams_count)) { + if (receive_streams(session, streams_count, self_msg_iter)) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error receiving streams"); goto error; } @@ -1481,7 +1483,8 @@ error: */ BT_HIDDEN enum lttng_live_iterator_status lttng_live_get_new_streams( - struct lttng_live_session *session) + struct lttng_live_session *session, + bt_self_message_iterator *self_msg_iter) { enum lttng_live_iterator_status status = LTTNG_LIVE_ITERATOR_STATUS_OK; @@ -1562,7 +1565,7 @@ enum lttng_live_iterator_status lttng_live_get_new_streams( goto error; } - if (receive_streams(session, streams_count)) { + if (receive_streams(session, streams_count, self_msg_iter)) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error receiving streams"); goto error; } -- 2.34.1