ctf: logging: missing comma and space between fields
[babeltrace.git] / src / plugins / ctf / common / msg-iter / msg-iter.c
index fc617f3d366ccee0f8a9b8815a23b3222c432602..b56cf0c1de8c680a5392e9527a0f2c028661977c 100644 (file)
@@ -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 <pproulx@efficios.com>
  *
- * 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;
@@ -819,7 +818,7 @@ enum ctf_msg_iter_status read_packet_header_begin_state(
        msg_it->cur_stream_class_id = -1;
        msg_it->cur_event_class_id = -1;
        msg_it->cur_data_stream_id = -1;
-       BT_COMP_LOGD("Decoding packet header field:"
+       BT_COMP_LOGD("Decoding packet header field: "
                "msg-it-addr=%p, trace-class-addr=%p, fc-addr=%p",
                msg_it, msg_it->meta.tc, packet_header_fc);
        status = read_dscope_begin_state(msg_it, packet_header_fc,
@@ -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
@@ -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;
This page took 0.025946 seconds and 4 git commands to generate.