src.ctf.lttng-live: use `common_muxing_compare_messages()` to break TS ties
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 9 Aug 2019 18:40:23 +0000 (14:40 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 10 Aug 2019 15:02:50 +0000 (11:02 -0400)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I2dc0087d995ea06e7ac9c11e4e5cd54958e932aa
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1848
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/ctf/lttng-live/Makefile.am
src/plugins/ctf/lttng-live/lttng-live.c

index f22e6b702d526d1fc4060478e7a535f3bf4a4655..5eeb641a909d03d14ae1dc93ad7f542e65daeed6 100644 (file)
@@ -9,8 +9,15 @@ libbabeltrace2_plugin_ctf_lttng_live_la_SOURCES = \
                viewer-connection.h \
                lttng-viewer-abi.h
 
+libbabeltrace2_plugin_ctf_lttng_live_la_LIBADD =
+
+if !ENABLE_BUILT_IN_PLUGINS
+libbabeltrace2_plugin_ctf_lttng_live_la_LIBADD += \
+       $(top_builddir)/src/plugins/common/muxing/libbabeltrace2-plugins-common-muxing.la
+endif
+
 if BABELTRACE_BUILD_WITH_MINGW
-libbabeltrace2_plugin_ctf_lttng_live_la_LIBADD = -lws2_32
+libbabeltrace2_plugin_ctf_lttng_live_la_LIBADD += -lws2_32
 endif
 
 noinst_LTLIBRARIES = libbabeltrace2-plugin-ctf-lttng-live.la
index 7760daf650099e25f89d9929396e859bf09531dc..72d3e74ea05b8d98f6bc62e6ac01ac0d9d5bade3 100644 (file)
@@ -42,6 +42,8 @@
 #include "compat/compiler.h"
 #include <babeltrace2/types.h>
 
+#include "plugins/common/muxing/muxing.h"
+
 #include "data-stream.h"
 #include "metadata.h"
 #include "lttng-live.h"
@@ -1162,6 +1164,8 @@ bt_component_class_message_iterator_next_method_status lttng_live_msg_iter_next(
                bt_self_message_iterator_get_data(self_msg_it);
        struct lttng_live_component *lttng_live =
                lttng_live_msg_iter->lttng_live_comp;
+       bt_self_component *self_comp = lttng_live_msg_iter->self_comp;
+       bt_logging_level log_level = lttng_live_msg_iter->log_level;
        enum lttng_live_iterator_status stream_iter_status;
        uint64_t session_idx;
 
@@ -1273,9 +1277,38 @@ bt_component_class_message_iterator_next_method_status lttng_live_msg_iter_next(
                                goto end;
                        }
 
-                       if (candidate_stream_iter->current_msg_ts_ns <= next_msg_ts_ns) {
+                       if (G_UNLIKELY(next_stream_iter == NULL) ||
+                                       candidate_stream_iter->current_msg_ts_ns <= next_msg_ts_ns) {
                                next_msg_ts_ns = candidate_stream_iter->current_msg_ts_ns;
                                next_stream_iter = candidate_stream_iter;
+                       } else if (candidate_stream_iter->current_msg_ts_ns == next_msg_ts_ns) {
+                               /*
+                                * The currently selected message to be sent
+                                * downstream next has the exact same timestamp
+                                * that of the current candidate message. We
+                                * must break the tie in a predictable manner.
+                                */
+                               BT_COMP_LOGD_STR("Two of the next message candidates have the same timestamps, pick one deterministically.");
+                               /*
+                                * Order the messages in an arbitrary but
+                                * determinitic way.
+                                */
+                               int ret = common_muxing_compare_messages(candidate_stream_iter->current_msg,
+                                       next_stream_iter->current_msg);
+                               if (ret < 0) {
+                                       /*
+                                        * The `candidate_stream_iter->current_msg`
+                                        * should go first. Update the next
+                                        * iterator and the current timestamp.
+                                        */
+                                       next_msg_ts_ns = candidate_stream_iter->current_msg_ts_ns;
+                                       next_stream_iter = candidate_stream_iter;
+                               } else if (ret == 0) {
+                                       /* Unable to pick which one should go first. */
+                                       BT_COMP_LOGW("Cannot deterministically pick next live stream message iterator because they have identical next messages: "
+                                               "next-stream-iter-addr=%p" "candidate-stream-iter-addr=%p",
+                                               next_stream_iter, candidate_stream_iter);
+                               }
                        }
 
                        session_idx++;
This page took 0.029243 seconds and 4 git commands to generate.