X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Flttng-live%2Fdata-stream.c;h=d7fdf34635cdc5bcbe6ce68889ca88bc131541f2;hp=1c89a87ae1a524c5baebb0a6b45b1b3a51a61764;hb=a043c3621976126dfaaaf8ffa2ee7fd5d98ea33b;hpb=d9c39b0a4ad9517178899334c0ca89fd20901609 diff --git a/src/plugins/ctf/lttng-live/data-stream.c b/src/plugins/ctf/lttng-live/data-stream.c index 1c89a87a..d7fdf346 100644 --- a/src/plugins/ctf/lttng-live/data-stream.c +++ b/src/plugins/ctf/lttng-live/data-stream.c @@ -1,26 +1,10 @@ /* - * Copyright 2019 Francis Deslauriers - * Copyright 2016 - Philippe Proulx - * Copyright 2016 - Jérémie Galarneau - * Copyright 2010-2011 - EfficiOS Inc. and Linux Foundation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * SPDX-License-Identifier: MIT * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Copyright 2019 Francis Deslauriers + * Copyright 2016 Philippe Proulx + * Copyright 2016 Jérémie Galarneau + * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation */ #define BT_COMP_LOG_SELF_COMP self_comp @@ -28,28 +12,28 @@ #define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/DS" #include "logging/comp-logging.h" +#include #include -#include #include -#include + #include -#include -#include "compat/mman.h" + #include + #include "../common/msg-iter/msg-iter.h" #include "common/assert.h" - +#include "compat/mman.h" #include "data-stream.h" #define STREAM_NAME_PREFIX "stream-" static -enum bt_msg_iter_medium_status medop_request_bytes( +enum ctf_msg_iter_medium_status medop_request_bytes( size_t request_sz, uint8_t **buffer_addr, size_t *buffer_sz, void *data) { - enum bt_msg_iter_medium_status status = - BT_MSG_ITER_MEDIUM_STATUS_OK; + enum ctf_msg_iter_medium_status status = + CTF_MSG_ITER_MEDIUM_STATUS_OK; struct lttng_live_stream_iterator *stream = data; struct lttng_live_trace *trace = stream->trace; struct lttng_live_session *session = trace->session; @@ -58,12 +42,21 @@ enum bt_msg_iter_medium_status medop_request_bytes( uint64_t len_left; uint64_t read_len; + BT_ASSERT(request_sz); + + if (stream->has_stream_hung_up) { + status = CTF_MSG_ITER_MEDIUM_STATUS_EOF; + goto end; + } + len_left = stream->base_offset + stream->len - stream->offset; if (!len_left) { - stream->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA; - status = BT_MSG_ITER_MEDIUM_STATUS_AGAIN; - return status; + lttng_live_stream_iterator_set_state(stream, + LTTNG_LIVE_STREAM_ACTIVE_NO_DATA); + status = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN; + goto end; } + read_len = MIN(request_sz, stream->buflen); read_len = MIN(read_len, len_left); status = lttng_live_get_stream_bytes(live_msg_iter, @@ -72,6 +65,7 @@ enum bt_msg_iter_medium_status medop_request_bytes( *buffer_addr = stream->buf; *buffer_sz = recv_len; stream->offset += recv_len; +end: return status; } @@ -107,7 +101,8 @@ bt_stream *medop_borrow_stream(bt_stream_class *stream_class, } if (!lttng_live_stream->stream) { - BT_COMP_LOGE("Cannot create stream %s (stream class ID " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot create stream %s (stream class ID " "%" PRId64 ", stream ID %" PRIu64 ")", lttng_live_stream->name->str, stream_class_id, stream_id); @@ -122,7 +117,7 @@ end: return lttng_live_stream->stream; } -static struct bt_msg_iter_medium_ops medops = { +static struct ctf_msg_iter_medium_ops medops = { .request_bytes = medop_request_bytes, .seek = NULL, .borrow_stream = medop_borrow_stream, @@ -130,7 +125,8 @@ static struct bt_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; @@ -142,6 +138,10 @@ enum lttng_live_iterator_status lttng_live_lazy_msg_init( return LTTNG_LIVE_ITERATOR_STATUS_OK; } + BT_COMP_LOGD("Lazily initializing self message iterator for live session: " + "session-id=%"PRIu64", self-msg-iter-addr=%p", session->id, + self_msg_iter); + for (trace_idx = 0; trace_idx < session->traces->len; trace_idx++) { struct lttng_live_trace *trace = g_ptr_array_index(session->traces, trace_idx); @@ -152,17 +152,23 @@ enum lttng_live_iterator_status lttng_live_lazy_msg_init( struct ctf_trace_class *ctf_tc; struct lttng_live_stream_iterator *stream_iter = g_ptr_array_index(trace->stream_iterators, - stream_iter_idx); + stream_iter_idx); if (stream_iter->msg_iter) { continue; } ctf_tc = ctf_metadata_decoder_borrow_ctf_trace_class( - trace->metadata->decoder); - stream_iter->msg_iter = bt_msg_iter_create(ctf_tc, - lttng_live->max_query_size, medops, - stream_iter, log_level, self_comp); + trace->metadata->decoder); + BT_COMP_LOGD("Creating CTF message iterator: " + "session-id=%"PRIu64", ctf-tc-addr=%p, " + "stream-iter-name=%s, self-msg-iter-addr=%p", + session->id, ctf_tc, stream_iter->name->str, self_msg_iter); + stream_iter->msg_iter = ctf_msg_iter_create(ctf_tc, + lttng_live->max_query_size, medops, stream_iter, + 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"); goto error; } } @@ -180,7 +186,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; @@ -198,13 +205,17 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( stream_iter = g_new0(struct lttng_live_stream_iterator, 1); if (!stream_iter) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to allocate struct lttng_live_stream_iterator"); goto error; } stream_iter->log_level = log_level; stream_iter->self_comp = self_comp; - trace = lttng_live_borrow_trace(session, ctf_trace_id); + trace = lttng_live_session_borrow_or_create_trace_by_id(session, ctf_trace_id); if (!trace) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to borrow CTF trace."); goto error; } @@ -212,33 +223,40 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( stream_iter->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA; stream_iter->viewer_stream_id = stream_id; stream_iter->ctf_stream_class_id = -1ULL; - stream_iter->last_inactivity_ts = INT64_MIN; + stream_iter->last_inactivity_ts.is_set = false; + stream_iter->last_inactivity_ts.value = 0; if (trace->trace) { struct ctf_trace_class *ctf_tc = ctf_metadata_decoder_borrow_ctf_trace_class( - trace->metadata->decoder); + trace->metadata->decoder); BT_ASSERT(!stream_iter->msg_iter); - stream_iter->msg_iter = bt_msg_iter_create(ctf_tc, - lttng_live->max_query_size, medops, - stream_iter, log_level, self_comp); + stream_iter->msg_iter = ctf_msg_iter_create(ctf_tc, + lttng_live->max_query_size, medops, stream_iter, + 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"); goto error; } } stream_iter->buf = g_new0(uint8_t, lttng_live->max_query_size); if (!stream_iter->buf) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to allocate live stream iterator buffer"); goto error; } stream_iter->buflen = lttng_live->max_query_size; stream_iter->name = g_string_new(NULL); if (!stream_iter->name) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to allocate live stream iterator name buffer"); goto error; } g_string_printf(stream_iter->name, STREAM_NAME_PREFIX "%" PRIu64, - stream_iter->viewer_stream_id); + stream_iter->viewer_stream_id); g_ptr_array_add(trace->stream_iterators, stream_iter); /* Track the number of active stream iterator. */ @@ -265,7 +283,7 @@ void lttng_live_stream_iterator_destroy( } if (stream_iter->msg_iter) { - bt_msg_iter_destroy(stream_iter->msg_iter); + ctf_msg_iter_destroy(stream_iter->msg_iter); } g_free(stream_iter->buf); if (stream_iter->name) { @@ -277,10 +295,5 @@ void lttng_live_stream_iterator_destroy( /* Track the number of active stream iterator. */ stream_iter->trace->session->lttng_live_msg_iter->active_stream_iter--; - /* - * Ensure we poke the trace metadata in the future, which is - * required to release the metadata reference on the trace. - */ - stream_iter->trace->new_metadata_needed = true; g_free(stream_iter); }