X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Fcommon%2Fmsg-iter%2Fmsg-iter.c;h=de80263923e57573169c6ff83f379161b7d86eeb;hb=6a0b47baa475071e293285f5633bb577a2a34700;hp=2adf68f71dcd4849b5d82ec57b8ab55ec4cb79ef;hpb=bc0ae3643695e12c77a976103fcaff3e11bd7a94;p=babeltrace.git diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.c b/src/plugins/ctf/common/msg-iter/msg-iter.c index 2adf68f7..de802639 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.c +++ b/src/plugins/ctf/common/msg-iter/msg-iter.c @@ -1,26 +1,10 @@ /* - * Babeltrace - CTF message iterator + * SPDX-License-Identifier: MIT * * Copyright (c) 2015-2018 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015-2018 Philippe Proulx * - * 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. - * - * 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. + * Babeltrace - CTF message iterator */ #define BT_COMP_LOG_SELF_COMP (msg_it->self_comp) @@ -108,6 +92,7 @@ enum state { STATE_EMIT_MSG_PACKET_END_MULTI, STATE_EMIT_MSG_PACKET_END_SINGLE, STATE_EMIT_QUEUED_MSG_PACKET_END, + STATE_CHECK_EMIT_MSG_STREAM_END, STATE_EMIT_MSG_STREAM_END, STATE_DONE, }; @@ -181,6 +166,14 @@ struct ctf_msg_iter { */ bool emit_stream_beginning_message; + /* + * True if we need to emit a stream end message at the end of the + * current stream. A live stream may never receive any data and thus + * never send a stream beginning message which removes the need to emit + * a stream end message. + */ + bool emit_stream_end_message; + /* Database of current dynamic scopes */ struct { bt_field *stream_packet_context; @@ -282,6 +275,10 @@ const char *state_string(enum state state) return "AFTER_STREAM_PACKET_CONTEXT"; case STATE_EMIT_MSG_STREAM_BEGINNING: return "EMIT_MSG_STREAM_BEGINNING"; + case STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS: + return "CHECK_EMIT_MSG_DISCARDED_EVENTS"; + case STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS: + return "CHECK_EMIT_MSG_DISCARDED_PACKETS"; case STATE_EMIT_MSG_PACKET_BEGINNING: return "EMIT_MSG_PACKET_BEGINNING"; case STATE_EMIT_MSG_DISCARDED_EVENTS: @@ -318,13 +315,15 @@ const char *state_string(enum state state) return "EMIT_MSG_PACKET_END_SINGLE"; case STATE_EMIT_QUEUED_MSG_PACKET_END: return "EMIT_QUEUED_MSG_PACKET_END"; + case STATE_CHECK_EMIT_MSG_STREAM_END: + return "CHECK_EMIT_MSG_STREAM_END"; case STATE_EMIT_MSG_STREAM_END: return "EMIT_MSG_STREAM_END"; case STATE_DONE: return "DONE"; - default: - return "(unknown)"; } + + bt_common_abort(); } static @@ -512,7 +511,7 @@ enum ctf_msg_iter_status request_medium_bytes( "packet-offset=%zu, cur=%zu, size=%zu, addr=%p", msg_it->buf.packet_offset, msg_it->buf.at, msg_it->buf.sz, msg_it->buf.addr); - BT_COMP_LOGD_MEM(buffer_addr, buffer_sz, "Returned bytes at %p:", + BT_COMP_LOGT_MEM(buffer_addr, buffer_sz, "Returned bytes at %p:", buffer_addr); } else if (m_status == CTF_MSG_ITER_MEDIUM_STATUS_EOF) { /* @@ -725,7 +724,7 @@ enum ctf_msg_iter_status switch_packet_state(struct ctf_msg_iter *msg_it) medium_status = msg_it->medium.medops.switch_packet(msg_it->medium.data); if (medium_status == CTF_MSG_ITER_MEDIUM_STATUS_EOF) { /* No more packets. */ - msg_it->state = STATE_EMIT_MSG_STREAM_END; + msg_it->state = STATE_CHECK_EMIT_MSG_STREAM_END; status = CTF_MSG_ITER_STATUS_OK; goto end; } else if (medium_status != CTF_MSG_ITER_MEDIUM_STATUS_OK) { @@ -803,7 +802,7 @@ enum ctf_msg_iter_status read_packet_header_begin_state( break; case CTF_MSG_ITER_STATUS_EOF: status = CTF_MSG_ITER_STATUS_OK; - msg_it->state = STATE_EMIT_MSG_STREAM_END; + msg_it->state = STATE_CHECK_EMIT_MSG_STREAM_END; goto end; default: goto end; @@ -1657,6 +1656,20 @@ end: return CTF_MSG_ITER_STATUS_OK; } +static inline +enum state check_emit_msg_stream_end(struct ctf_msg_iter *msg_it) +{ + enum state next_state; + + if (msg_it->emit_stream_end_message) { + next_state = STATE_EMIT_MSG_STREAM_END; + } else { + next_state = STATE_DONE; + } + + return next_state; +} + static inline enum ctf_msg_iter_status handle_state(struct ctf_msg_iter *msg_it) { @@ -1755,6 +1768,9 @@ enum ctf_msg_iter_status handle_state(struct ctf_msg_iter *msg_it) case STATE_EMIT_QUEUED_MSG_PACKET_END: msg_it->state = STATE_EMIT_MSG_PACKET_END_SINGLE; break; + case STATE_CHECK_EMIT_MSG_STREAM_END: + msg_it->state = check_emit_msg_stream_end(msg_it); + break; case STATE_EMIT_MSG_STREAM_END: msg_it->state = STATE_DONE; break; @@ -1817,6 +1833,7 @@ void ctf_msg_iter_reset(struct ctf_msg_iter *msg_it) msg_it->prev_packet_snapshots.beginning_clock = UINT64_C(-1); msg_it->prev_packet_snapshots.end_clock = UINT64_C(-1); msg_it->emit_stream_beginning_message = true; + msg_it->emit_stream_end_message = false; } static @@ -2423,7 +2440,7 @@ struct ctf_field_class *bfcr_borrow_variant_selected_field_class_cb( if (selected_option->fc->in_ir && !msg_it->dry_run) { bt_field *var_field = stack_top(msg_it->stack)->base; - ret = bt_field_variant_select_option_field_by_index( + ret = bt_field_variant_select_option_by_index( var_field, option_index); if (ret) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, @@ -2947,6 +2964,7 @@ enum ctf_msg_iter_status ctf_msg_iter_get_next_message( /* create_msg_stream_beginning() logs errors */ *message = create_msg_stream_beginning(msg_it); msg_it->emit_stream_beginning_message = false; + msg_it->emit_stream_end_message = true; if (!*message) { status = CTF_MSG_ITER_STATUS_ERROR; @@ -2956,6 +2974,7 @@ enum ctf_msg_iter_status ctf_msg_iter_get_next_message( case STATE_EMIT_MSG_STREAM_END: /* create_msg_stream_end() logs errors */ *message = create_msg_stream_end(msg_it); + msg_it->emit_stream_end_message = false; if (!*message) { status = CTF_MSG_ITER_STATUS_ERROR;