#define BT_LOG_TAG "PLUGIN-CTF-FS-SINK"
#include "logging.h"
-#include <babeltrace/babeltrace.h>
+#include <babeltrace2/babeltrace.h>
#include <stdio.h>
#include <stdbool.h>
#include <glib.h>
-#include <babeltrace/assert-internal.h>
-#include <babeltrace/ctfser-internal.h>
+#include <babeltrace2/assert-internal.h>
+#include <babeltrace2/ctfser-internal.h>
#include "fs-sink.h"
#include "fs-sink-trace.h"
BT_ASSERT(cs);
}
+ /*
+ * If we previously received a discarded events message with
+ * a time range, make sure that its beginning time matches what's
+ * expected for CTF 1.8, that is:
+ *
+ * * Its beginning time is the previous packet's end
+ * time (or the current packet's beginning time if
+ * this is the first packet).
+ *
+ * We check this here instead of in handle_packet_end_msg()
+ * because we want to catch any incompatible message as early as
+ * possible to report the error.
+ *
+ * Validation of the discarded events message's end time is
+ * performed in handle_packet_end_msg().
+ */
if (stream->discarded_events_state.in_range) {
uint64_t expected_cs;
+ /*
+ * `stream->discarded_events_state.in_range` is only set
+ * when the stream class's discarded events have a time
+ * range.
+ *
+ * It is required that the packet beginning and end
+ * messages for this stream class have times when
+ * discarded events have a time range.
+ */
BT_ASSERT(stream->sc->discarded_events_has_ts);
BT_ASSERT(stream->sc->packets_have_ts_begin);
BT_ASSERT(stream->sc->packets_have_ts_end);
- /*
- * Make sure that the current discarded events range's
- * beginning time matches what's expected for CTF 1.8.
- */
if (stream->prev_packet_state.end_cs == UINT64_C(-1)) {
/* We're opening the first packet */
expected_cs = bt_clock_snapshot_get_value(cs);
}
}
+ /*
+ * If we previously received a discarded packets message with a
+ * time range, make sure that its beginning and end times match
+ * what's expected for CTF 1.8, that is:
+ *
+ * * Its beginning time is the previous packet's end time.
+ *
+ * * Its end time is the current packet's beginning time.
+ */
if (stream->discarded_packets_state.in_range) {
uint64_t expected_end_cs;
+ /*
+ * `stream->discarded_packets_state.in_range` is only
+ * set when the stream class's discarded packets have a
+ * time range.
+ *
+ * It is required that the packet beginning and end
+ * messages for this stream class have times when
+ * discarded packets have a time range.
+ */
BT_ASSERT(stream->sc->discarded_packets_has_ts);
BT_ASSERT(stream->sc->packets_have_ts_begin);
BT_ASSERT(stream->sc->packets_have_ts_end);
/*
- * Make sure that the current discarded packets range's
- * beginning and end times match what's expected for CTF
- * 1.8.
+ * It is not supported to have a discarded packets
+ * message _before_ the first packet: we cannot validate
+ * that its beginning time is compatible with CTF 1.8 in
+ * this case.
*/
if (stream->prev_packet_state.end_cs == UINT64_C(-1)) {
BT_LOGE("Incompatible discarded packets message "
}
}
- if (stream->sc->discarded_packets_has_ts) {
- stream->discarded_packets_state.in_range = false;
- }
+ /*
+ * We're not in a discarded packets time range anymore since we
+ * require that the discarded packets time ranges go from one
+ * packet's end time to the next packet's beginning time, and
+ * we're handling a packet beginning message here.
+ */
+ stream->discarded_packets_state.in_range = false;
ret = fs_sink_stream_open_packet(stream, cs, ir_packet);
if (ret) {
BT_ASSERT(cs);
}
+ /*
+ * If we previously received a discarded events message with
+ * a time range, make sure that its end time matches what's
+ * expected for CTF 1.8, that is:
+ *
+ * * Its end time is the current packet's end time.
+ *
+ * Validation of the discarded events message's beginning time
+ * is performed in handle_packet_beginning_msg().
+ */
if (stream->discarded_events_state.in_range) {
uint64_t expected_cs;
+ /*
+ * `stream->discarded_events_state.in_range` is only set
+ * when the stream class's discarded events have a time
+ * range.
+ *
+ * It is required that the packet beginning and end
+ * messages for this stream class have times when
+ * discarded events have a time range.
+ */
BT_ASSERT(stream->sc->discarded_events_has_ts);
BT_ASSERT(stream->sc->packets_have_ts_begin);
BT_ASSERT(stream->sc->packets_have_ts_end);
- /*
- * Make sure that the current discarded events range's
- * end time matches what's expected for CTF 1.8.
- */
expected_cs = bt_clock_snapshot_get_value(cs);
if (stream->discarded_events_state.end_cs != expected_cs) {
goto end;
}
- if (stream->sc->discarded_events_has_ts) {
- stream->discarded_events_state.in_range = false;
- }
+ /*
+ * We're not in a discarded events time range anymore since we
+ * require that the discarded events time ranges go from one
+ * packet's end time to the next packet's end time, and we're
+ * handling a packet end message here.
+ */
+ stream->discarded_events_state.in_range = false;
end:
return status;
bt_stream_borrow_class_const(ir_stream);
struct fs_sink_stream *stream;
bool packets_have_beginning_end_cs =
- bt_stream_class_packets_have_default_beginning_clock_snapshot(ir_sc) &&
- bt_stream_class_packets_have_default_end_clock_snapshot(ir_sc);
+ bt_stream_class_packets_have_beginning_default_clock_snapshot(ir_sc) &&
+ bt_stream_class_packets_have_end_default_clock_snapshot(ir_sc);
/*
* Not supported: discarded events with default clock snapshots,
goto end;
}
+ /*
+ * If we're currently in an opened packet (got a packet
+ * beginning message, but no packet end message yet), we do not
+ * support having a discarded events message with a time range
+ * because we require that the discarded events message's time
+ * range go from a packet's end time to the next packet's end
+ * time.
+ */
if (stream->packet_state.is_open &&
stream->sc->discarded_events_has_ts) {
BT_LOGE("Unsupported discarded events message with "
}
if (stream->sc->discarded_events_has_ts) {
+ /*
+ * Make the stream's state be in the time range of a
+ * discarded events message since we have the message's
+ * time range (`stream->sc->discarded_events_has_ts`).
+ */
stream->discarded_events_state.in_range = true;
/*
* The clock snapshot values will be validated when
- * handling the next "packet beginning" message.
+ * handling the next packet beginning and end messages
+ * (next calls to handle_packet_beginning_msg() and
+ * handle_packet_end_msg()).
*/
- cs = bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
+ cs = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
msg);
BT_ASSERT(cs);
stream->discarded_events_state.beginning_cs =
bt_clock_snapshot_get_value(cs);
- cs = bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
+ cs = bt_message_discarded_events_borrow_end_default_clock_snapshot_const(
msg);
BT_ASSERT(cs);
stream->discarded_events_state.end_cs = bt_clock_snapshot_get_value(cs);
avail = bt_message_discarded_events_get_count(msg, &count);
if (avail != BT_PROPERTY_AVAILABILITY_AVAILABLE) {
+ /*
+ * There's no specific count of discarded events: set it
+ * to 1 so that we know that we at least discarded
+ * something.
+ */
count = 1;
}
goto end;
}
+ /*
+ * Discarded packets messages are guaranteed to occur between
+ * packets.
+ */
BT_ASSERT(!stream->packet_state.is_open);
if (stream->sc->discarded_packets_has_ts) {
+ /*
+ * Make the stream's state be in the time range of a
+ * discarded packets message since we have the message's
+ * time range (`stream->sc->discarded_packets_has_ts`).
+ */
stream->discarded_packets_state.in_range = true;
/*
* The clock snapshot values will be validated when
- * handling the next "packet beginning" message.
+ * handling the next packet beginning message (next call
+ * to handle_packet_beginning_msg()).
*/
- cs = bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
+ cs = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
msg);
BT_ASSERT(cs);
stream->discarded_packets_state.beginning_cs =
bt_clock_snapshot_get_value(cs);
- cs = bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
+ cs = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
msg);
BT_ASSERT(cs);
stream->discarded_packets_state.end_cs =
avail = bt_message_discarded_packets_get_count(msg, &count);
if (avail != BT_PROPERTY_AVAILABILITY_AVAILABLE) {
+ /*
+ * There's no specific count of discarded packets: set
+ * it to 1 so that we know that we at least discarded
+ * something.
+ */
count = 1;
}