#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
-#include <babeltrace/assert-internal.h>
+#include <babeltrace2/assert-internal.h>
#include <string.h>
-#include <babeltrace/babeltrace.h>
-#include <babeltrace/common-internal.h>
+#include <babeltrace2/babeltrace.h>
+#include <babeltrace2/common-internal.h>
#include <glib.h>
#include <stdlib.h>
if (notit->cur_exp_packet_total_size == -1) {
if (notit->cur_exp_packet_content_size != -1) {
- BT_LOGW("Content size is set, but packet size is not: "
- "notit-addr=%p, packet-context-field-addr=%p, "
- "packet-size=%" PRId64 ", content-size=%" PRId64,
- notit, notit->dscopes.stream_packet_context,
- notit->cur_exp_packet_total_size,
- notit->cur_exp_packet_content_size);
- status = BT_MSG_ITER_STATUS_ERROR;
- goto end;
+ notit->cur_exp_packet_total_size =
+ notit->cur_exp_packet_content_size;
}
} else {
if (notit->cur_exp_packet_content_size == -1) {
}
}
+ BT_ASSERT((notit->cur_exp_packet_total_size >= 0 &&
+ notit->cur_exp_packet_content_size >= 0) ||
+ (notit->cur_exp_packet_total_size < 0 &&
+ notit->cur_exp_packet_content_size < 0));
+
if (notit->cur_exp_packet_content_size >
notit->cur_exp_packet_total_size) {
BT_LOGW("Invalid packet or content size: "
notit->meta.ec->name->str,
notit->packet);
BT_ASSERT(notit->msg_iter);
- msg = bt_message_event_create(notit->msg_iter,
- notit->meta.ec->ir_ec, notit->packet);
+ BT_ASSERT(notit->meta.sc);
+
+ if (bt_stream_class_borrow_default_clock_class(notit->meta.sc->ir_sc)) {
+ msg = bt_message_event_create_with_default_clock_snapshot(
+ notit->msg_iter, notit->meta.ec->ir_ec,
+ notit->packet, notit->default_clock_snapshot);
+ } else {
+ msg = bt_message_event_create(notit->msg_iter,
+ notit->meta.ec->ir_ec, notit->packet);
+ }
+
if (!msg) {
BT_LOGE("Cannot create event message: "
"notit-addr=%p, ec-addr=%p, ec-name=\"%s\", "
{
notit->state = STATE_EMIT_MSG_DISCARDED_EVENTS;
+ if (!notit->meta.sc->has_discarded_events) {
+ notit->state = STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS;
+ goto end;
+ }
+
if (notit->prev_packet_snapshots.discarded_events == UINT64_C(-1)) {
if (notit->snapshots.discarded_events == 0 ||
notit->snapshots.discarded_events == UINT64_C(-1)) {
}
}
+end:
return BT_MSG_ITER_STATUS_OK;
}
{
notit->state = STATE_EMIT_MSG_DISCARDED_PACKETS;
+ if (!notit->meta.sc->has_discarded_packets) {
+ notit->state = STATE_EMIT_MSG_PACKET_BEGINNING;
+ goto end;
+ }
+
if (notit->prev_packet_snapshots.packets == UINT64_C(-1)) {
/*
* Stream's first packet or no information about
}
}
+end:
return BT_MSG_ITER_STATUS_OK;
}
seq_fc->stored_length_index);
seq_field = stack_top(notit->stack)->base;
BT_ASSERT(seq_field);
- ret = bt_field_dynamic_array_set_length(seq_field, (uint64_t) length);
- if (ret) {
- BT_LOGE("Cannot set dynamic array field's length field: "
- "notit-addr=%p, field-addr=%p, "
- "length=%" PRIu64, notit, seq_field, length);
+
+ /*
+ * bfcr_get_sequence_length_cb() also gets called back for a
+ * text sequence, but the destination field is a string field.
+ * Only set the field's sequence length if the destination field
+ * is a sequence field.
+ */
+ if (!seq_fc->base.is_text) {
+ BT_ASSERT(bt_field_get_class_type(seq_field) ==
+ BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY);
+ ret = bt_field_dynamic_array_set_length(seq_field,
+ (uint64_t) length);
+ if (ret) {
+ BT_LOGE("Cannot set dynamic array field's length field: "
+ "notit-addr=%p, field-addr=%p, "
+ "length=%" PRIu64, notit, seq_field, length);
+ }
}
return length;
return ret_fc;
}
-static
-void set_event_default_clock_snapshot(struct bt_msg_iter *notit)
-{
- bt_event *event = bt_message_event_borrow_event(notit->event_msg);
- bt_stream_class *sc = notit->meta.sc->ir_sc;
-
- BT_ASSERT(event);
-
- if (bt_stream_class_borrow_default_clock_class(sc)) {
- bt_event_set_default_clock_snapshot(event,
- notit->default_clock_snapshot);
- }
-}
-
static
void create_msg_stream_beginning(struct bt_msg_iter *notit,
bt_message **message)
sc = notit->meta.sc->ir_sc;
BT_ASSERT(sc);
- if (bt_stream_class_packets_have_discarded_event_counter_snapshot(sc)) {
- BT_ASSERT(notit->snapshots.discarded_events != UINT64_C(-1));
- bt_packet_set_discarded_event_counter_snapshot(
- notit->packet, notit->snapshots.discarded_events);
- }
-
- if (bt_stream_class_packets_have_packet_counter_snapshot(sc)) {
- BT_ASSERT(notit->snapshots.packets != UINT64_C(-1));
- bt_packet_set_packet_counter_snapshot(
- notit->packet, notit->snapshots.packets);
- }
-
- if (bt_stream_class_packets_have_default_beginning_clock_snapshot(sc)) {
- BT_ASSERT(notit->snapshots.beginning_clock != UINT64_C(-1));
- bt_packet_set_default_beginning_clock_snapshot(
- notit->packet, notit->snapshots.beginning_clock);
- }
-
- if (bt_stream_class_packets_have_default_end_clock_snapshot(sc)) {
- BT_ASSERT(notit->snapshots.end_clock != UINT64_C(-1));
- bt_packet_set_default_end_clock_snapshot(
- notit->packet, notit->snapshots.end_clock);
- }
-
if (notit->packet_context_field) {
ret = bt_packet_move_context_field(
notit->packet, notit->packet_context_field);
}
BT_ASSERT(notit->msg_iter);
- msg = bt_message_packet_beginning_create(notit->msg_iter,
- notit->packet);
+
+ if (notit->meta.sc->packets_have_ts_begin) {
+ BT_ASSERT(notit->snapshots.beginning_clock != UINT64_C(-1));
+ msg = bt_message_packet_beginning_create_with_default_clock_snapshot(
+ notit->msg_iter, notit->packet,
+ notit->snapshots.beginning_clock);
+ } else {
+ msg = bt_message_packet_beginning_create(notit->msg_iter,
+ notit->packet);
+ }
+
if (!msg) {
BT_LOGE("Cannot create packet beginning message: "
"notit-addr=%p, packet-addr=%p",
}
BT_ASSERT(notit->msg_iter);
- msg = bt_message_packet_end_create(notit->msg_iter,
- notit->packet);
+
+ if (notit->meta.sc->packets_have_ts_end) {
+ BT_ASSERT(notit->snapshots.end_clock != UINT64_C(-1));
+ msg = bt_message_packet_end_create_with_default_clock_snapshot(
+ notit->msg_iter, notit->packet,
+ notit->snapshots.end_clock);
+ } else {
+ msg = bt_message_packet_end_create(notit->msg_iter,
+ notit->packet);
+ }
+
if (!msg) {
BT_LOGE("Cannot create packet end message: "
"notit-addr=%p, packet-addr=%p",
bt_message *msg;
uint64_t beginning_raw_value = UINT64_C(-1);
uint64_t end_raw_value = UINT64_C(-1);
- uint64_t count = UINT64_C(-1);
BT_ASSERT(notit->msg_iter);
BT_ASSERT(notit->stream);
+ BT_ASSERT(notit->meta.sc->has_discarded_events);
- if (notit->prev_packet_snapshots.discarded_events == UINT64_C(-1)) {
- /*
- * We discarded events, but before (and possibly
- * including) the current packet: use this packet's time
- * range, and do not have a specific count.
- */
- beginning_raw_value = notit->snapshots.beginning_clock;
- end_raw_value = notit->snapshots.end_clock;
- } else {
- count = notit->snapshots.discarded_events -
- notit->prev_packet_snapshots.discarded_events;
- BT_ASSERT(count > 0);
- beginning_raw_value = notit->prev_packet_snapshots.end_clock;
- end_raw_value = notit->snapshots.end_clock;
- }
+ if (notit->meta.sc->discarded_events_have_default_cs) {
+ if (notit->prev_packet_snapshots.discarded_events == UINT64_C(-1)) {
+ /*
+ * We discarded events, but before (and possibly
+ * including) the current packet: use this packet's time
+ * range, and do not have a specific count.
+ */
+ beginning_raw_value = notit->snapshots.beginning_clock;
+ end_raw_value = notit->snapshots.end_clock;
+ } else {
+ beginning_raw_value = notit->prev_packet_snapshots.end_clock;
+ end_raw_value = notit->snapshots.end_clock;
+ }
- if (beginning_raw_value != UINT64_C(-1) &&
- end_raw_value != UINT64_C(-1)) {
+ BT_ASSERT(beginning_raw_value != UINT64_C(-1));
+ BT_ASSERT(end_raw_value != UINT64_C(-1));
msg = bt_message_discarded_events_create_with_default_clock_snapshots(
notit->msg_iter, notit->stream, beginning_raw_value,
end_raw_value);
return;
}
- if (count != UINT64_C(-1)) {
- bt_message_discarded_events_set_count(msg, count);
+ if (notit->prev_packet_snapshots.discarded_events != UINT64_C(-1)) {
+ bt_message_discarded_events_set_count(msg,
+ notit->snapshots.discarded_events -
+ notit->prev_packet_snapshots.discarded_events);
}
*message = msg;
BT_ASSERT(notit->msg_iter);
BT_ASSERT(notit->stream);
+ BT_ASSERT(notit->meta.sc->has_discarded_packets);
BT_ASSERT(notit->prev_packet_snapshots.packets !=
UINT64_C(-1));
- if (notit->prev_packet_snapshots.end_clock != UINT64_C(-1) &&
- notit->snapshots.beginning_clock != UINT64_C(-1)) {
+ if (notit->meta.sc->discarded_packets_have_default_cs) {
+ BT_ASSERT(notit->prev_packet_snapshots.end_clock != UINT64_C(-1));
+ BT_ASSERT(notit->snapshots.beginning_clock != UINT64_C(-1));
msg = bt_message_discarded_packets_create_with_default_clock_snapshots(
notit->msg_iter, notit->stream,
notit->prev_packet_snapshots.end_clock,
switch (notit->state) {
case STATE_EMIT_MSG_EVENT:
BT_ASSERT(notit->event_msg);
- set_event_default_clock_snapshot(notit);
*message = notit->event_msg;
notit->event_msg = NULL;
goto end;
ret = set_current_packet_content_sizes(notit);
if (ret) {
status = BT_MSG_ITER_STATUS_ERROR;
- goto end;
}
return status;
props->exp_packet_total_size = notit->cur_exp_packet_total_size;
props->exp_packet_content_size = notit->cur_exp_packet_content_size;
- BT_ASSERT(props->stream_class_id >= 0);
props->stream_class_id = (uint64_t) notit->cur_stream_class_id;
props->data_stream_id = notit->cur_data_stream_id;
props->snapshots.discarded_events = notit->snapshots.discarded_events;