ret = bt_stream_class_set_default_clock_class(ctx->ir_sc,
ctx->sc->default_clock_class->ir_cc);
BT_ASSERT(ret == 0);
- bt_stream_class_set_packets_have_default_beginning_clock_snapshot(
- ctx->ir_sc, BT_TRUE);
- bt_stream_class_set_packets_have_default_end_clock_snapshot(
- ctx->ir_sc, BT_TRUE);
}
- bt_stream_class_set_supports_discarded_events(ctx->ir_sc, BT_TRUE,
- ctx->sc->default_clock_class != NULL);
- bt_stream_class_set_supports_discarded_packets(ctx->ir_sc, BT_TRUE,
- ctx->sc->default_clock_class != NULL);
+ bt_stream_class_set_packets_have_default_beginning_clock_snapshot(
+ ctx->ir_sc, ctx->sc->packets_have_ts_begin);
+ bt_stream_class_set_packets_have_default_end_clock_snapshot(
+ ctx->ir_sc, ctx->sc->packets_have_ts_end);
+ bt_stream_class_set_supports_discarded_events(ctx->ir_sc,
+ ctx->sc->has_discarded_events,
+ ctx->sc->discarded_events_have_default_cs);
+ bt_stream_class_set_supports_discarded_packets(ctx->ir_sc,
+ ctx->sc->has_discarded_packets,
+ ctx->sc->discarded_packets_have_default_cs);
ctx->sc->is_translated = true;
ctx->sc->ir_sc = ctx->ir_sc;
--- /dev/null
+/*
+ * Copyright 2019 - Philippe Proulx <pproulx@efficios.com>
+ *
+ * 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.
+ */
+
+#define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-UPDATE-SC-CONFIG"
+#include "logging.h"
+
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <glib.h>
+#include <stdint.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "ctf-meta-visitors.h"
+
+BT_HIDDEN
+int ctf_trace_class_update_stream_class_config(struct ctf_trace_class *ctf_tc)
+{
+ struct ctf_field_class_int *int_fc;
+ uint64_t i;
+
+ for (i = 0; i < ctf_tc->stream_classes->len; i++) {
+ struct ctf_stream_class *sc =
+ ctf_tc->stream_classes->pdata[i];
+
+ if (sc->is_translated) {
+ continue;
+ }
+
+ if (!sc->packet_context_fc) {
+ continue;
+ }
+
+ int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
+ (void *) sc->packet_context_fc, "timestamp_begin");
+ if (int_fc && int_fc->meaning ==
+ CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME) {
+ sc->packets_have_ts_begin = true;
+ }
+
+ int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
+ (void *) sc->packet_context_fc, "timestamp_end");
+ if (int_fc && int_fc->meaning ==
+ CTF_FIELD_CLASS_MEANING_PACKET_END_TIME) {
+ sc->packets_have_ts_end = true;
+ }
+
+ int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
+ (void *) sc->packet_context_fc, "events_discarded");
+ if (int_fc && int_fc->meaning ==
+ CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT) {
+ sc->has_discarded_events = true;
+ }
+
+ sc->discarded_events_have_default_cs =
+ sc->has_discarded_events && sc->packets_have_ts_begin &&
+ sc->packets_have_ts_end;
+ int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
+ (void *) sc->packet_context_fc, "packet_seq_num");
+ if (int_fc && int_fc->meaning ==
+ CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT) {
+ sc->has_discarded_packets = true;
+ }
+
+ sc->discarded_packets_have_default_cs =
+ sc->has_discarded_packets &&
+ sc->packets_have_ts_begin && sc->packets_have_ts_end;
+ }
+
+ return 0;
+}
{
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;
}
BT_ASSERT(notit->msg_iter);
- if (bt_stream_class_borrow_default_clock_class(notit->meta.sc->ir_sc)) {
- uint64_t value = 0;
-
- if (notit->snapshots.beginning_clock == UINT64_C(-1)) {
- if (notit->prev_packet_snapshots.end_clock != UINT64_C(-1)) {
- value = notit->prev_packet_snapshots.end_clock;
- }
- } else {
- value = notit->snapshots.beginning_clock;
- }
-
-
+ 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, value);
+ notit->msg_iter, notit->packet,
+ notit->snapshots.beginning_clock);
} else {
msg = bt_message_packet_beginning_create(notit->msg_iter,
notit->packet);
BT_ASSERT(notit->msg_iter);
- if (bt_stream_class_borrow_default_clock_class(notit->meta.sc->ir_sc)) {
- if (notit->snapshots.end_clock == UINT64_C(-1)) {
- notit->snapshots.end_clock =
- notit->default_clock_snapshot;
- }
-
+ 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,
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,