From 8a30271a574f095d9d6a7978f3745e568c019f7b Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 5 May 2021 10:07:56 -0400 Subject: [PATCH] trimmer: don't get clock snapshots from messages that don't have them When using a trace with packets that don't have beginning clock snapshots [1] with a trimmer component, we hit: $ ./src/cli/babeltrace2 nvctf --timerange="05:50:53,05:50:55" ... Condition ID: `pre:message-packet-beginning-borrow-default-clock-snapshot-const:msg-stream-class-packets-have-beginning-default-clock-snapshot`. Function: bt_message_packet_beginning_borrow_default_clock_snapshot_const(). ------------------------------------------------------------------------ Error is: Message's stream class packets don't have beginning default clock snapshot. The problem is with the trimmer's get_msg_ns_from_origin function assuming that that packet begnning messages have a clock snapshot if the stream class has a clock class (which I suppose was true in early development stages). Fix that by making get_msg_ns_from_origin skip over messages that don't have clock snapshots. In addition to packet beginning messages, I found (just by inspection, not tested) that packet end, discarded events and discarded packets messages are in the same situation. Note that the trimmer component currently requires packet messages to have clock snapshots in order to work. However, the check for this happens later, during the TRIM state. get_msg_ns_from_origin is called early, during the SET_BOUNDS_NS_FROM_ORIGIN state. So in get_msg_ns_from_origin, we can't assume that messages we encounter have them. [1] Like the trace from https://lists.lttng.org/pipermail/lttng-dev/2021-May/029955.html Change-Id: Ie56b3250829197eadb823b7ac5d23efc46d12b3c Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/5689 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/plugins/utils/trimmer/trimmer.c | 50 +++++++++++++++++------------ 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/plugins/utils/trimmer/trimmer.c b/src/plugins/utils/trimmer/trimmer.c index 5b3a6c35..a65b2ecc 100644 --- a/src/plugins/utils/trimmer/trimmer.c +++ b/src/plugins/utils/trimmer/trimmer.c @@ -784,27 +784,33 @@ int get_msg_ns_from_origin(const bt_message *msg, int64_t *ns_from_origin, msg); break; case BT_MESSAGE_TYPE_PACKET_BEGINNING: - clock_class = - bt_message_packet_beginning_borrow_stream_class_default_clock_class_const( - msg); - if (G_UNLIKELY(!clock_class)) { - goto error; + { + const bt_packet *packet = bt_message_packet_beginning_borrow_packet_const(msg); + const bt_stream *stream = bt_packet_borrow_stream_const(packet); + const bt_stream_class *stream_class = bt_stream_borrow_class_const(stream); + + if (!bt_stream_class_packets_have_beginning_default_clock_snapshot(stream_class)) { + goto no_clock_snapshot; } clock_snapshot = bt_message_packet_beginning_borrow_default_clock_snapshot_const( msg); break; + } case BT_MESSAGE_TYPE_PACKET_END: - clock_class = - bt_message_packet_end_borrow_stream_class_default_clock_class_const( - msg); - if (G_UNLIKELY(!clock_class)) { - goto error; + { + const bt_packet *packet = bt_message_packet_end_borrow_packet_const(msg); + const bt_stream *stream = bt_packet_borrow_stream_const(packet); + const bt_stream_class *stream_class = bt_stream_borrow_class_const(stream); + + if (!bt_stream_class_packets_have_end_default_clock_snapshot(stream_class)) { + goto no_clock_snapshot; } clock_snapshot = bt_message_packet_end_borrow_default_clock_snapshot_const( msg); break; + } case BT_MESSAGE_TYPE_STREAM_BEGINNING: { enum bt_message_stream_clock_snapshot_state cs_state; @@ -840,27 +846,31 @@ int get_msg_ns_from_origin(const bt_message *msg, int64_t *ns_from_origin, break; } case BT_MESSAGE_TYPE_DISCARDED_EVENTS: - clock_class = - bt_message_discarded_events_borrow_stream_class_default_clock_class_const( - msg); - if (G_UNLIKELY(!clock_class)) { - goto error; + { + const bt_stream *stream = bt_message_discarded_events_borrow_stream_const(msg); + const bt_stream_class *stream_class = bt_stream_borrow_class_const(stream); + + if (!bt_stream_class_discarded_events_have_default_clock_snapshots(stream_class)) { + goto no_clock_snapshot; } clock_snapshot = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const( msg); break; + } case BT_MESSAGE_TYPE_DISCARDED_PACKETS: - clock_class = - bt_message_discarded_packets_borrow_stream_class_default_clock_class_const( - msg); - if (G_UNLIKELY(!clock_class)) { - goto error; + { + const bt_stream *stream = bt_message_discarded_packets_borrow_stream_const(msg); + const bt_stream_class *stream_class = bt_stream_borrow_class_const(stream); + + if (!bt_stream_class_discarded_packets_have_default_clock_snapshots(stream_class)) { + goto no_clock_snapshot; } clock_snapshot = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const( msg); break; + } case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY: clock_snapshot = bt_message_message_iterator_inactivity_borrow_clock_snapshot_const( -- 2.34.1