X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fcommon%2Fmuxing%2Fmuxing.c;h=5e52c4f497cdf77f17bf5e47b11c7c1aafcef5cb;hb=0ea4aa9f8de0535273540aeaeacec74421cfb6b8;hp=cd97798acc0309a3b77a0a0fc028119e8bd883a5;hpb=60d02328261d37044d37a7d77b3d3847db5c72bf;p=babeltrace.git diff --git a/src/plugins/common/muxing/muxing.c b/src/plugins/common/muxing/muxing.c index cd97798a..5e52c4f4 100644 --- a/src/plugins/common/muxing/muxing.c +++ b/src/plugins/common/muxing/muxing.c @@ -1,23 +1,7 @@ /* - * Copyright 2019 Francis Deslauriers - * - * 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 */ #include @@ -82,10 +66,10 @@ int message_type_weight(const bt_message_type msg_type) } /* - * Compare 2 messages to order them in a determinitic way based on their + * Compare 2 messages to order them in a deterministic way based on their * types. - * Returns -1 is left mesage must go first - * Returns 1 is right mesage must go first + * Returns -1 is left message must go first + * Returns 1 is right message must go first */ static int compare_messages_by_type(struct messages_to_compare *msgs) @@ -177,6 +161,78 @@ end: return ret; } + +static +int compare_clock_classes(const bt_clock_class *left_cc, + const bt_clock_class *right_cc) +{ + int ret; + const char *left_clock_class_name, *right_clock_class_name; + bt_uuid left_clock_class_uuid, right_clock_class_uuid; + uint64_t left_freq, right_freq, left_prec, right_prec; + bool left_origin_is_unix, right_origin_is_unix; + + left_clock_class_uuid = bt_clock_class_get_uuid(left_cc); + right_clock_class_uuid = bt_clock_class_get_uuid(right_cc); + + if (left_clock_class_uuid && !right_clock_class_uuid) { + ret = -1; + goto end; + } else if (!left_clock_class_uuid && right_clock_class_uuid) { + ret = 1; + goto end; + } else if (left_clock_class_uuid && right_clock_class_uuid) { + ret = bt_uuid_compare(left_clock_class_uuid, + right_clock_class_uuid); + if (ret != 0) { + goto end; + } + } + + left_origin_is_unix = bt_clock_class_origin_is_unix_epoch(left_cc); + right_origin_is_unix = bt_clock_class_origin_is_unix_epoch(right_cc); + + if (left_origin_is_unix != right_origin_is_unix) { + ret = left_origin_is_unix - right_origin_is_unix; + goto end; + } + + left_clock_class_name = bt_clock_class_get_name(left_cc); + right_clock_class_name = bt_clock_class_get_name(right_cc); + + if (left_clock_class_name && !right_clock_class_name) { + ret = -1; + goto end; + } else if (!left_clock_class_name && right_clock_class_name) { + ret = 1; + goto end; + } else if (left_clock_class_name && right_clock_class_name) { + ret = strcmp(left_clock_class_name, right_clock_class_name); + if (ret != 0) { + goto end; + } + } + + left_freq = bt_clock_class_get_frequency(left_cc); + right_freq = bt_clock_class_get_frequency(right_cc); + + ret = right_freq - left_freq; + if (ret != 0) { + goto end; + } + + left_prec = bt_clock_class_get_precision(left_cc); + right_prec = bt_clock_class_get_precision(right_cc); + + ret = right_prec - left_prec; + if (ret != 0) { + goto end; + } + +end: + return ret; +} + static int compare_streams(const bt_stream *left_stream, const bt_stream *right_stream) { @@ -184,12 +240,13 @@ int compare_streams(const bt_stream *left_stream, const bt_stream *right_stream) const char *left_stream_name, *right_stream_name, *left_stream_class_name, *right_stream_class_name; const bt_stream_class *left_stream_class, *right_stream_class; + const bt_clock_class *left_cc, *right_cc; /* * No need to compare stream id as it was checked earlier and if we are * here it means they are identical or both absent. */ - BT_ASSERT(bt_stream_get_id(left_stream) == + BT_ASSERT_DBG(bt_stream_get_id(left_stream) == bt_stream_get_id(right_stream)); /* Compare stream name. */ @@ -216,7 +273,7 @@ int compare_streams(const bt_stream *left_stream, const bt_stream *right_stream) * No need to compare stream class id as it was checked earlier and if * we are here it means they are identical. */ - BT_ASSERT(bt_stream_class_get_id(left_stream_class) == + BT_ASSERT_DBG(bt_stream_class_get_id(left_stream_class) == bt_stream_class_get_id(right_stream_class)); /* Compare stream class name. */ @@ -291,133 +348,73 @@ int compare_streams(const bt_stream *left_stream, const bt_stream *right_stream) goto end; } - if (!bt_stream_class_supports_packets(left_stream_class)) { - /* Skip all packet related checks. */ - goto end; - } - - /* - * Compare stream class presence of discarded packets beginning default - * clock snapshot. - */ - if (bt_stream_class_packets_have_beginning_default_clock_snapshot(left_stream_class) && - !bt_stream_class_packets_have_beginning_default_clock_snapshot(right_stream_class)) { - ret = 1; - goto end; - } else if (!bt_stream_class_packets_have_beginning_default_clock_snapshot(left_stream_class) && - bt_stream_class_packets_have_beginning_default_clock_snapshot(right_stream_class)) { - ret = -1; - goto end; - } - - /* - * Compare stream class presence of discarded packets end default clock - * snapshot. - */ - if (bt_stream_class_packets_have_end_default_clock_snapshot(left_stream_class) && - !bt_stream_class_packets_have_end_default_clock_snapshot(right_stream_class)) { - ret = 1; - goto end; - } else if (!bt_stream_class_packets_have_end_default_clock_snapshot(left_stream_class) && - bt_stream_class_packets_have_end_default_clock_snapshot(right_stream_class)) { - ret = -1; - goto end; - } - - /* Compare stream class support of discarded packets. */ - if (bt_stream_class_supports_discarded_packets(left_stream_class) && - !bt_stream_class_supports_discarded_packets(right_stream_class)) { - ret = 1; - goto end; - } else if (!bt_stream_class_supports_discarded_packets(left_stream_class) && - bt_stream_class_supports_discarded_packets(right_stream_class)) { - ret = -1; - goto end; - } - - /* Compare stream class discarded packets default clock snapshot. */ - if (bt_stream_class_discarded_packets_have_default_clock_snapshots(left_stream_class) && - !bt_stream_class_discarded_packets_have_default_clock_snapshots(right_stream_class)) { - ret = 1; - goto end; - } else if (!bt_stream_class_discarded_packets_have_default_clock_snapshots(left_stream_class) && - bt_stream_class_discarded_packets_have_default_clock_snapshots(right_stream_class)) { - ret = -1; - goto end; - } - -end: - return ret; -} - -static -int compare_clock_snapshots_and_clock_classes(const bt_clock_snapshot *left_cs, - const bt_clock_snapshot *right_cs) -{ - int ret; - uint64_t left_freq, right_freq, left_prec, right_prec; - uint64_t left_cs_value, right_cs_value; - const bt_clock_class *left_clock_class, *right_clock_class; - const char *left_clock_class_name, *right_clock_class_name; - left_cs_value = bt_clock_snapshot_get_value(left_cs); - right_cs_value = bt_clock_snapshot_get_value(right_cs); - bt_uuid left_clock_class_uuid, right_clock_class_uuid; - - ret = left_cs_value - right_cs_value; - if (ret != 0) { - goto end; - } + if (bt_stream_class_supports_packets(left_stream_class)) { + /* + * Compare stream class presence of discarded packets beginning default + * clock snapshot. + */ + if (bt_stream_class_packets_have_beginning_default_clock_snapshot(left_stream_class) && + !bt_stream_class_packets_have_beginning_default_clock_snapshot(right_stream_class)) { + ret = 1; + goto end; + } else if (!bt_stream_class_packets_have_beginning_default_clock_snapshot(left_stream_class) && + bt_stream_class_packets_have_beginning_default_clock_snapshot(right_stream_class)) { + ret = -1; + goto end; + } - left_clock_class = bt_clock_snapshot_borrow_clock_class_const(left_cs); - right_clock_class = bt_clock_snapshot_borrow_clock_class_const(right_cs); + /* + * Compare stream class presence of discarded packets end default clock + * snapshot. + */ + if (bt_stream_class_packets_have_end_default_clock_snapshot(left_stream_class) && + !bt_stream_class_packets_have_end_default_clock_snapshot(right_stream_class)) { + ret = 1; + goto end; + } else if (!bt_stream_class_packets_have_end_default_clock_snapshot(left_stream_class) && + bt_stream_class_packets_have_end_default_clock_snapshot(right_stream_class)) { + ret = -1; + goto end; + } - left_clock_class_uuid = bt_clock_class_get_uuid(left_clock_class); - right_clock_class_uuid = bt_clock_class_get_uuid(right_clock_class); + /* Compare stream class support of discarded packets. */ + if (bt_stream_class_supports_discarded_packets(left_stream_class) && + !bt_stream_class_supports_discarded_packets(right_stream_class)) { + ret = 1; + goto end; + } else if (!bt_stream_class_supports_discarded_packets(left_stream_class) && + bt_stream_class_supports_discarded_packets(right_stream_class)) { + ret = -1; + goto end; + } - if (left_clock_class_uuid && !right_clock_class_uuid) { - ret = -1; - goto end; - } else if (!left_clock_class_uuid && right_clock_class_uuid) { - ret = 1; - goto end; - } else if (left_clock_class_uuid && right_clock_class_uuid) { - ret = bt_uuid_compare(left_clock_class_uuid, - right_clock_class_uuid); - if (ret != 0) { + /* Compare stream class discarded packets default clock snapshot. */ + if (bt_stream_class_discarded_packets_have_default_clock_snapshots(left_stream_class) && + !bt_stream_class_discarded_packets_have_default_clock_snapshots(right_stream_class)) { + ret = 1; + goto end; + } else if (!bt_stream_class_discarded_packets_have_default_clock_snapshots(left_stream_class) && + bt_stream_class_discarded_packets_have_default_clock_snapshots(right_stream_class)) { + ret = -1; goto end; } } + /* Compare the clock classes associated to the stream classes. */ + left_cc = bt_stream_class_borrow_default_clock_class_const(left_stream_class); + right_cc = bt_stream_class_borrow_default_clock_class_const(right_stream_class); - left_clock_class_name = bt_clock_class_get_name(left_clock_class); - right_clock_class_name = bt_clock_class_get_name(right_clock_class); + if (!left_cc && !right_cc) { + ret = compare_clock_classes(left_cc, right_cc); - if (left_clock_class_name && !right_clock_class_name) { - ret = -1; - goto end; - } else if (!left_clock_class_name && right_clock_class_name) { - ret = 1; - goto end; - } else if (left_clock_class_name && right_clock_class_name) { - ret = strcmp(left_clock_class_name, right_clock_class_name); if (ret != 0) { goto end; } - } - - left_freq = bt_clock_class_get_frequency(left_clock_class); - right_freq = bt_clock_class_get_frequency(right_clock_class); - - ret = right_freq - left_freq; - if (ret != 0) { + } else if (left_cc && !right_cc) { + ret = -1; goto end; - } - - left_prec = bt_clock_class_get_precision(left_clock_class); - right_prec = bt_clock_class_get_precision(right_clock_class); - - ret = right_prec - left_prec; - if (ret != 0) { + } else if (!left_cc && right_cc) { + ret = 1; goto end; } @@ -425,6 +422,16 @@ end: return ret; } +static +int compare_clock_snapshots(const bt_clock_snapshot *left_cs, + const bt_clock_snapshot *right_cs) +{ + uint64_t left_cs_value = bt_clock_snapshot_get_value(left_cs); + uint64_t right_cs_value = bt_clock_snapshot_get_value(right_cs); + + return left_cs_value - right_cs_value; +} + static const bt_stream *borrow_stream(const bt_message *msg) { @@ -649,10 +656,10 @@ int compare_messages_same_type(struct messages_to_compare *msgs) int ret = 0; /* - * Both messages are of the same type, we must compare characterics of + * Both messages are of the same type, we must compare characteristics of * the messages such as the attributes of the event in a event message. */ - BT_ASSERT(bt_message_get_type(msgs->left.msg) == + BT_ASSERT_DBG(bt_message_get_type(msgs->left.msg) == bt_message_get_type(msgs->right.msg)); switch (bt_message_get_type(msgs->left.msg)) { @@ -715,17 +722,22 @@ int compare_messages_same_type(struct messages_to_compare *msgs) const bt_clock_snapshot *right_end_cs = bt_message_discarded_events_borrow_end_default_clock_snapshot_const(msgs->right.msg); - ret = compare_clock_snapshots_and_clock_classes( - left_beg_cs, right_beg_cs); + ret = compare_clock_snapshots(left_beg_cs, right_beg_cs); if (ret) { goto end; } - ret = compare_clock_snapshots_and_clock_classes( - left_end_cs, right_end_cs); + ret = compare_clock_snapshots(left_end_cs, right_end_cs); if (ret) { goto end; } + + ret = compare_clock_classes( + bt_clock_snapshot_borrow_clock_class_const(left_beg_cs), + bt_clock_snapshot_borrow_clock_class_const(right_beg_cs)); + if (ret != 0) { + goto end; + } } left_event_count_avail = @@ -782,17 +794,22 @@ int compare_messages_same_type(struct messages_to_compare *msgs) const bt_clock_snapshot *right_end_cs = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(msgs->right.msg); - ret = compare_clock_snapshots_and_clock_classes( - left_beg_cs, right_beg_cs); + ret = compare_clock_snapshots(left_beg_cs, right_beg_cs); if (ret) { goto end; } - ret = compare_clock_snapshots_and_clock_classes( - left_end_cs, right_end_cs); + ret = compare_clock_snapshots(left_end_cs, right_end_cs); if (ret) { goto end; } + + ret = compare_clock_classes( + bt_clock_snapshot_borrow_clock_class_const(left_beg_cs), + bt_clock_snapshot_borrow_clock_class_const(right_beg_cs)); + if (ret != 0) { + goto end; + } } left_packet_count_avail = bt_message_discarded_packets_get_count( @@ -824,8 +841,14 @@ int compare_messages_same_type(struct messages_to_compare *msgs) const bt_clock_snapshot *right_cs = bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(msgs->right.msg); - ret = compare_clock_snapshots_and_clock_classes( - left_cs, right_cs); + ret = compare_clock_snapshots(left_cs, right_cs); + if (ret != 0) { + goto end; + } + + ret = compare_clock_classes( + bt_clock_snapshot_borrow_clock_class_const(left_cs), + bt_clock_snapshot_borrow_clock_class_const(right_cs)); if (ret != 0) { goto end; } @@ -840,14 +863,13 @@ end: return ret; } -BT_HIDDEN int common_muxing_compare_messages(const bt_message *left_msg, const bt_message *right_msg) { int ret = 0; struct messages_to_compare msgs; - BT_ASSERT(left_msg != right_msg); + BT_ASSERT_DBG(left_msg != right_msg); msgs.left.msg = left_msg; msgs.left.trace = borrow_trace(left_msg);