#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"
goto end;
}
- if (stream->sc->default_clock_class) {
+ if (stream->sc->packets_have_ts_begin) {
cs = bt_message_packet_beginning_borrow_default_clock_snapshot_const(
msg);
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;
+
/*
- * Make sure that the current discarded events range's
- * beginning time matches what's expected for CTF 1.8.
+ * `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.
*/
- if (stream->sc->default_clock_class) {
- uint64_t expected_cs;
-
- if (stream->prev_packet_state.end_cs == UINT64_C(-1)) {
- /* We're opening the first packet */
- expected_cs = bt_clock_snapshot_get_value(cs);
- } else {
- expected_cs = stream->prev_packet_state.end_cs;
- }
+ BT_ASSERT(stream->sc->discarded_events_has_ts);
+ BT_ASSERT(stream->sc->packets_have_ts_begin);
+ BT_ASSERT(stream->sc->packets_have_ts_end);
- if (stream->discarded_events_state.beginning_cs !=
- expected_cs) {
- BT_LOGE("Incompatible discarded events message: "
- "unexpected beginning time: "
- "beginning-cs-val=%" PRIu64 ", "
- "expected-beginning-cs-val=%" PRIu64 ", "
- "stream-id=%" PRIu64 ", stream-name=\"%s\", "
- "trace-name=\"%s\", path=\"%s/%s\"",
- stream->discarded_events_state.beginning_cs,
- expected_cs,
- bt_stream_get_id(ir_stream),
- bt_stream_get_name(ir_stream),
- bt_trace_get_name(
- bt_stream_borrow_trace_const(ir_stream)),
- stream->trace->path->str, stream->file_name->str);
- status = BT_SELF_COMPONENT_STATUS_ERROR;
- goto end;
- }
+ if (stream->prev_packet_state.end_cs == UINT64_C(-1)) {
+ /* We're opening the first packet */
+ expected_cs = bt_clock_snapshot_get_value(cs);
+ } else {
+ expected_cs = stream->prev_packet_state.end_cs;
}
- }
+ if (stream->discarded_events_state.beginning_cs !=
+ expected_cs) {
+ BT_LOGE("Incompatible discarded events message: "
+ "unexpected beginning time: "
+ "beginning-cs-val=%" PRIu64 ", "
+ "expected-beginning-cs-val=%" PRIu64 ", "
+ "stream-id=%" PRIu64 ", stream-name=\"%s\", "
+ "trace-name=\"%s\", path=\"%s/%s\"",
+ stream->discarded_events_state.beginning_cs,
+ expected_cs,
+ bt_stream_get_id(ir_stream),
+ bt_stream_get_name(ir_stream),
+ bt_trace_get_name(
+ bt_stream_borrow_trace_const(ir_stream)),
+ stream->trace->path->str, stream->file_name->str);
+ status = BT_SELF_COMPONENT_STATUS_ERROR;
+ goto end;
+ }
+ }
+ /*
+ * 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);
+
+ /*
+ * 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 "
"occuring before the stream's first packet: "
goto end;
}
- /*
- * Make sure that the current discarded packets range's
- * beginning and end times match what's expected for CTF
- * 1.8.
- */
- if (stream->sc->default_clock_class) {
- uint64_t expected_end_cs =
- bt_clock_snapshot_get_value(cs);
-
- if (stream->discarded_packets_state.beginning_cs !=
- stream->prev_packet_state.end_cs) {
- BT_LOGE("Incompatible discarded packets message: "
- "unexpected beginning time: "
- "beginning-cs-val=%" PRIu64 ", "
- "expected-beginning-cs-val=%" PRIu64 ", "
- "stream-id=%" PRIu64 ", stream-name=\"%s\", "
- "trace-name=\"%s\", path=\"%s/%s\"",
- stream->discarded_packets_state.beginning_cs,
- stream->prev_packet_state.end_cs,
- bt_stream_get_id(ir_stream),
- bt_stream_get_name(ir_stream),
- bt_trace_get_name(
- bt_stream_borrow_trace_const(ir_stream)),
- stream->trace->path->str, stream->file_name->str);
- status = BT_SELF_COMPONENT_STATUS_ERROR;
- goto end;
- }
+ if (stream->discarded_packets_state.beginning_cs !=
+ stream->prev_packet_state.end_cs) {
+ BT_LOGE("Incompatible discarded packets message: "
+ "unexpected beginning time: "
+ "beginning-cs-val=%" PRIu64 ", "
+ "expected-beginning-cs-val=%" PRIu64 ", "
+ "stream-id=%" PRIu64 ", stream-name=\"%s\", "
+ "trace-name=\"%s\", path=\"%s/%s\"",
+ stream->discarded_packets_state.beginning_cs,
+ stream->prev_packet_state.end_cs,
+ bt_stream_get_id(ir_stream),
+ bt_stream_get_name(ir_stream),
+ bt_trace_get_name(
+ bt_stream_borrow_trace_const(ir_stream)),
+ stream->trace->path->str, stream->file_name->str);
+ status = BT_SELF_COMPONENT_STATUS_ERROR;
+ goto end;
+ }
- if (stream->discarded_packets_state.end_cs !=
- expected_end_cs) {
- BT_LOGE("Incompatible discarded packets message: "
- "unexpected end time: "
- "end-cs-val=%" PRIu64 ", "
- "expected-end-cs-val=%" PRIu64 ", "
- "stream-id=%" PRIu64 ", stream-name=\"%s\", "
- "trace-name=\"%s\", path=\"%s/%s\"",
- stream->discarded_packets_state.beginning_cs,
- expected_end_cs,
- bt_stream_get_id(ir_stream),
- bt_stream_get_name(ir_stream),
- bt_trace_get_name(
- bt_stream_borrow_trace_const(ir_stream)),
- stream->trace->path->str, stream->file_name->str);
- status = BT_SELF_COMPONENT_STATUS_ERROR;
- goto end;
- }
+ expected_end_cs = bt_clock_snapshot_get_value(cs);
+
+ if (stream->discarded_packets_state.end_cs !=
+ expected_end_cs) {
+ BT_LOGE("Incompatible discarded packets message: "
+ "unexpected end time: "
+ "end-cs-val=%" PRIu64 ", "
+ "expected-end-cs-val=%" PRIu64 ", "
+ "stream-id=%" PRIu64 ", stream-name=\"%s\", "
+ "trace-name=\"%s\", path=\"%s/%s\"",
+ stream->discarded_packets_state.end_cs,
+ expected_end_cs,
+ bt_stream_get_id(ir_stream),
+ bt_stream_get_name(ir_stream),
+ bt_trace_get_name(
+ bt_stream_borrow_trace_const(ir_stream)),
+ stream->trace->path->str, stream->file_name->str);
+ status = BT_SELF_COMPONENT_STATUS_ERROR;
+ goto end;
}
}
+ /*
+ * 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) {
status = BT_SELF_COMPONENT_STATUS_ERROR;
goto end;
}
- if (stream->sc->default_clock_class) {
- cs = bt_message_packet_end_borrow_default_clock_snapshot_const(
- msg);
- BT_ASSERT(cs);
- }
-
- if (stream->sc->default_clock_class) {
+ if (stream->sc->packets_have_ts_end) {
cs = bt_message_packet_end_borrow_default_clock_snapshot_const(
msg);
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;
+
/*
- * Make sure that the current discarded events range's
- * end time matches what's expected for CTF 1.8.
+ * `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.
*/
- if (stream->sc->default_clock_class) {
- uint64_t expected_cs = bt_clock_snapshot_get_value(cs);
-
- if (stream->discarded_events_state.end_cs !=
- expected_cs) {
- BT_LOGE("Incompatible discarded events message: "
- "unexpected end time: "
- "end-cs-val=%" PRIu64 ", "
- "expected-end-cs-val=%" PRIu64 ", "
- "stream-id=%" PRIu64 ", stream-name=\"%s\", "
- "trace-name=\"%s\", path=\"%s/%s\"",
- stream->discarded_events_state.end_cs,
- expected_cs,
- bt_stream_get_id(ir_stream),
- bt_stream_get_name(ir_stream),
- bt_trace_get_name(
- bt_stream_borrow_trace_const(ir_stream)),
- stream->trace->path->str, stream->file_name->str);
- status = BT_SELF_COMPONENT_STATUS_ERROR;
- goto end;
- }
+ BT_ASSERT(stream->sc->discarded_events_has_ts);
+ BT_ASSERT(stream->sc->packets_have_ts_begin);
+ BT_ASSERT(stream->sc->packets_have_ts_end);
+
+ expected_cs = bt_clock_snapshot_get_value(cs);
+
+ if (stream->discarded_events_state.end_cs != expected_cs) {
+ BT_LOGE("Incompatible discarded events message: "
+ "unexpected end time: "
+ "end-cs-val=%" PRIu64 ", "
+ "expected-end-cs-val=%" PRIu64 ", "
+ "stream-id=%" PRIu64 ", stream-name=\"%s\", "
+ "trace-name=\"%s\", path=\"%s/%s\"",
+ stream->discarded_events_state.end_cs,
+ expected_cs,
+ bt_stream_get_id(ir_stream),
+ bt_stream_get_name(ir_stream),
+ bt_trace_get_name(
+ bt_stream_borrow_trace_const(ir_stream)),
+ stream->trace->path->str, stream->file_name->str);
+ status = BT_SELF_COMPONENT_STATUS_ERROR;
+ goto end;
}
}
goto end;
}
+ /*
+ * 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:
bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
const bt_stream *ir_stream =
bt_message_stream_beginning_borrow_stream_const(msg);
+ const bt_stream_class *ir_sc =
+ bt_stream_borrow_class_const(ir_stream);
struct fs_sink_stream *stream;
+ bool packets_have_beginning_end_cs =
+ 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,
+ * but packet beginning/end without default clock snapshot.
+ */
+ if (!fs_sink->ignore_discarded_events &&
+ bt_stream_class_discarded_events_have_default_clock_snapshots(ir_sc) &&
+ !packets_have_beginning_end_cs) {
+ BT_LOGE("Unsupported stream: discarded events have "
+ "default clock snapshots, but packets have no "
+ "beginning and/or end default clock snapshots: "
+ "stream-addr=%p, "
+ "stream-id=%" PRIu64 ", "
+ "stream-name=\"%s\"",
+ ir_stream, bt_stream_get_id(ir_stream),
+ bt_stream_get_name(ir_stream));
+ status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
+ goto end;
+ }
+
+ /*
+ * Not supported: discarded packets with default clock
+ * snapshots, but packet beginning/end without default clock
+ * snapshot.
+ */
+ if (!fs_sink->ignore_discarded_packets &&
+ bt_stream_class_discarded_packets_have_default_clock_snapshots(ir_sc) &&
+ !packets_have_beginning_end_cs) {
+ BT_LOGE("Unsupported stream: discarded packets have "
+ "default clock snapshots, but packets have no "
+ "beginning and/or end default clock snapshots: "
+ "stream-addr=%p, "
+ "stream-id=%" PRIu64 ", "
+ "stream-name=\"%s\"",
+ ir_stream, bt_stream_get_id(ir_stream),
+ bt_stream_get_name(ir_stream));
+ status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
+ goto end;
+ }
stream = borrow_stream(fs_sink, ir_stream);
if (!stream) {
goto end;
}
- if (stream->packet_state.is_open) {
- BT_LOGE("Unsupported discarded events message occuring "
- "within a packet: "
+ /*
+ * 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 "
+ "default clock snapshots occuring within a packet: "
"stream-id=%" PRIu64 ", stream-name=\"%s\", "
"trace-name=\"%s\", path=\"%s/%s\"",
bt_stream_get_id(ir_stream),
goto end;
}
- stream->discarded_events_state.in_range = true;
+ 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;
- if (stream->sc->default_clock_class) {
/*
* 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);
- } else {
- stream->discarded_events_state.beginning_cs = UINT64_C(-1);
- stream->discarded_events_state.end_cs = UINT64_C(-1);
+ 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;
}
- if (stream->packet_state.is_open) {
- BT_LOGE("Unsupported discarded packets message occuring "
- "within a packet: "
- "stream-id=%" PRIu64 ", stream-name=\"%s\", "
- "trace-name=\"%s\", path=\"%s/%s\"",
- bt_stream_get_id(ir_stream),
- bt_stream_get_name(ir_stream),
- bt_trace_get_name(
- bt_stream_borrow_trace_const(ir_stream)),
- stream->trace->path->str, stream->file_name->str);
- status = BT_SELF_COMPONENT_STATUS_ERROR;
- goto end;
- }
+ /*
+ * Discarded packets messages are guaranteed to occur between
+ * packets.
+ */
+ BT_ASSERT(!stream->packet_state.is_open);
- stream->discarded_packets_state.in_range = true;
+ 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;
- if (stream->sc->default_clock_class) {
/*
* 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 =
bt_clock_snapshot_get_value(cs);
- } else {
- stream->discarded_packets_state.beginning_cs = UINT64_C(-1);
- stream->discarded_packets_state.end_cs = UINT64_C(-1);
}
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;
}