Cleanup: src.ctf.lttng-live: missing space in debug statement
[babeltrace.git] / src / plugins / ctf / lttng-live / lttng-live.c
index 66e20b73e17d2bd67a76696e0a148854fc507ace..bc8ea07d4d5e841774bc96596862b372d95ec408 100644 (file)
@@ -1,31 +1,11 @@
 /*
- * lttng-live.c
- *
- * Babeltrace CTF LTTng-live Client Component
+ * SPDX-License-Identifier: MIT
  *
  * Copyright 2019 Francis Deslauriers <francis.deslauriers@efficios.com>
  * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * Author: Jérémie Galarneau <jeremie.galarneau@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 LTTng-live Client Component
  */
 
 #define BT_COMP_LOG_SELF_COMP self_comp
@@ -554,7 +534,7 @@ lttng_live_iterator_handle_new_streams_and_metadata(
        enum session_not_found_action sess_not_found_act =
                lttng_live_msg_iter->lttng_live_comp->params.sess_not_found_act;
 
-       BT_COMP_LOGD("Update data and metadata of all sessions"
+       BT_COMP_LOGD("Update data and metadata of all sessions"
                "live-msg-iter-addr=%p", lttng_live_msg_iter);
        /*
         * In a remotely distant future, we could add a "new
@@ -1001,6 +981,77 @@ end:
        return live_status;
 }
 
+static
+bool is_discarded_packet_or_event_message(const bt_message *msg)
+{
+       const enum bt_message_type msg_type = bt_message_get_type(msg);
+
+       return msg_type == BT_MESSAGE_TYPE_DISCARDED_EVENTS ||
+                       msg_type == BT_MESSAGE_TYPE_DISCARDED_PACKETS;
+}
+
+static
+enum lttng_live_iterator_status adjust_discarded_packets_message(
+               bt_self_message_iterator *iter,
+               const bt_stream *stream,
+               const bt_message *msg_in, bt_message **msg_out,
+               uint64_t new_begin_ts)
+{
+       enum lttng_live_iterator_status status = LTTNG_LIVE_ITERATOR_STATUS_OK;
+       enum bt_property_availability availability;
+       const bt_clock_snapshot *clock_snapshot;
+       uint64_t end_ts;
+       uint64_t count;
+
+       clock_snapshot = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(msg_in);
+       end_ts = bt_clock_snapshot_get_value(clock_snapshot);
+
+       availability = bt_message_discarded_packets_get_count(msg_in, &count);
+       BT_ASSERT_DBG(availability == BT_PROPERTY_AVAILABILITY_AVAILABLE);
+
+       *msg_out = bt_message_discarded_packets_create_with_default_clock_snapshots(
+               iter, stream, new_begin_ts, end_ts);
+       if (!*msg_out) {
+               status = LTTNG_LIVE_ITERATOR_STATUS_NOMEM;
+               goto end;
+       }
+
+       bt_message_discarded_packets_set_count(*msg_out, count);
+end:
+       return status;
+}
+
+static
+enum lttng_live_iterator_status adjust_discarded_events_message(
+               bt_self_message_iterator *iter,
+               const bt_stream *stream,
+               const bt_message *msg_in, bt_message **msg_out,
+               uint64_t new_begin_ts)
+{
+       enum lttng_live_iterator_status status = LTTNG_LIVE_ITERATOR_STATUS_OK;
+       enum bt_property_availability availability;
+       const bt_clock_snapshot *clock_snapshot;
+       uint64_t end_ts;
+       uint64_t count;
+
+       clock_snapshot = bt_message_discarded_events_borrow_end_default_clock_snapshot_const(msg_in);
+       end_ts = bt_clock_snapshot_get_value(clock_snapshot);
+
+       availability = bt_message_discarded_events_get_count(msg_in, &count);
+       BT_ASSERT_DBG(availability == BT_PROPERTY_AVAILABILITY_AVAILABLE);
+
+       *msg_out = bt_message_discarded_events_create_with_default_clock_snapshots(
+               iter, stream, new_begin_ts, end_ts);
+       if (!*msg_out) {
+               status = LTTNG_LIVE_ITERATOR_STATUS_NOMEM;
+               goto end;
+       }
+
+       bt_message_discarded_events_set_count(*msg_out, count);
+end:
+       return status;
+}
+
 static
 enum lttng_live_iterator_status next_stream_iterator_for_trace(
                struct lttng_live_msg_iter *lttng_live_msg_iter,
@@ -1033,8 +1084,8 @@ enum lttng_live_iterator_status next_stream_iterator_for_trace(
                                stream_iter_idx);
 
                /*
-                * Find if there is are now current message for this stream
-                * iterator get it.
+                * If there is no current message for this stream, go fetch
+                * one.
                 */
                while (!stream_iter->current_msg) {
                        const bt_message *msg = NULL;
@@ -1072,6 +1123,59 @@ enum lttng_live_iterator_status next_stream_iterator_for_trace(
                        if (curr_msg_ts_ns >= lttng_live_msg_iter->last_msg_ts_ns) {
                                stream_iter->current_msg = msg;
                                stream_iter->current_msg_ts_ns = curr_msg_ts_ns;
+                       } else if (stream_iter->last_inactivity_ts > curr_msg_ts_ns &&
+                                       is_discarded_packet_or_event_message(msg)) {
+                               /*
+                                * The CTF message iterator emits Discarded
+                                * Packets and Events with synthesized begin and
+                                * end timestamps from the bounds of the last
+                                * known packet and the newly decoded packet
+                                * header.
+                                *
+                                * The CTF message iterator is not aware of
+                                * stream inactivity beacons. Hence, we have
+                                * to adjust the begin timestamp of those types
+                                * of messages if a stream signaled its
+                                * inactivity up until _after_ the last known
+                                * packet's begin timestamp.
+                                *
+                                * Otherwise, the monotonicity guarantee would
+                                * not be preserved.
+                                */
+                               const enum bt_message_type msg_type =
+                                       bt_message_get_type(msg);
+                               enum lttng_live_iterator_status adjust_status =
+                                       LTTNG_LIVE_ITERATOR_STATUS_OK;
+                               bt_message *adjusted_message;
+
+                               switch (msg_type) {
+                               case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
+                                       adjust_status = adjust_discarded_events_message(
+                                               lttng_live_msg_iter->self_msg_iter,
+                                               stream_iter->stream,
+                                               msg, &adjusted_message,
+                                               stream_iter->last_inactivity_ts);
+                                       break;
+                               case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
+                                       adjust_status = adjust_discarded_packets_message(
+                                               lttng_live_msg_iter->self_msg_iter,
+                                               stream_iter->stream,
+                                               msg, &adjusted_message,
+                                               stream_iter->last_inactivity_ts);
+                                       break;
+                               default:
+                                       bt_common_abort();
+                               }
+
+                               if (adjust_status != LTTNG_LIVE_ITERATOR_STATUS_OK) {
+                                       stream_iter_status = adjust_status;
+                                       goto end;
+                               }
+
+                               BT_ASSERT_DBG(adjusted_message);
+                               stream_iter->current_msg = adjusted_message;
+                               stream_iter->current_msg_ts_ns =
+                                       stream_iter->last_inactivity_ts;
                        } else {
                                /*
                                 * We received a message in the past. To ensure
This page took 0.036741 seconds and 4 git commands to generate.