#include <stdint.h>
/*
- * For bt_self_message_iterator, bt_event, bt_packet,
+ * For bt_self_message_iterator, bt_event, bt_packet, bt_stream,
* bt_event_class, bt_message
*/
#include <babeltrace2/types.h>
extern
bt_message *bt_message_event_create(
+ bt_self_message_iterator *message_iterator,
+ const bt_event_class *event_class,
+ const bt_stream *stream);
+
+extern
+bt_message *bt_message_event_create_with_packet(
bt_self_message_iterator *message_iterator,
const bt_event_class *event_class,
const bt_packet *packet);
extern
bt_message *bt_message_event_create_with_default_clock_snapshot(
+ bt_self_message_iterator *message_iterator,
+ const bt_event_class *event_class,
+ const bt_stream *stream, uint64_t raw_clock_value);
+
+extern
+bt_message *bt_message_event_create_with_packet_and_default_clock_snapshot(
bt_self_message_iterator *message_iterator,
const bt_event_class *event_class,
const bt_packet *packet, uint64_t raw_clock_value);
extern bt_bool bt_stream_class_assigns_automatic_stream_id(
const bt_stream_class *stream_class);
+extern bt_bool bt_stream_class_supports_packets(
+ const bt_stream_class *stream_class);
+
extern bt_bool bt_stream_class_packets_have_beginning_default_clock_snapshot(
const bt_stream_class *stream_class);
extern void bt_stream_class_set_assigns_automatic_stream_id(
bt_stream_class *stream_class, bt_bool value);
-extern void bt_stream_class_set_packets_have_beginning_default_clock_snapshot(
- bt_stream_class *stream_class, bt_bool value);
-
-extern void bt_stream_class_set_packets_have_end_default_clock_snapshot(
- bt_stream_class *stream_class, bt_bool value);
-
extern void bt_stream_class_set_supports_discarded_events(
bt_stream_class *stream_class,
bt_bool supports_discarded_events,
BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK = __BT_FUNC_STATUS_OK,
} bt_stream_class_set_field_class_status;
+extern void bt_stream_class_set_supports_packets(
+ bt_stream_class *stream_class, bt_bool supports_packets,
+ bt_bool with_beginning_default_clock_snapshot,
+ bt_bool with_end_default_clock_snapshot);
+
extern bt_stream_class_set_field_class_status
bt_stream_class_set_packet_context_field_class(
bt_stream_class *stream_class,
from bt2.message import *
from bt2.message import _DiscardedEventsMessage
from bt2.message import _DiscardedPacketsMessage
+from bt2.message import _EventMessage
from bt2.message_iterator import *
from bt2.message_iterator import _UserMessageIterator
from bt2.packet import _Packet
@property
def packet(self):
packet_ptr = native_bt.event_borrow_packet(self._ptr)
- assert packet_ptr is not None
+
+ if packet_ptr is None:
+ return
+
return bt2.packet._Packet._create_from_ptr_and_get_ref(packet_ptr)
@property
@property
def default_clock_snapshot(self):
- self._check_has_default_clock_class(self.event.packet.stream.cls.default_clock_class)
+ self._check_has_default_clock_class(self.event.stream.cls.default_clock_class)
return self._get_default_clock_snapshot(self._borrow_default_clock_snapshot_ptr)
@property
def _bt_seek_beginning_from_native(self):
self._seek_beginning()
- def _create_event_message(self, event_class, packet, default_clock_snapshot=None):
+ def _create_event_message(self, event_class, parent=None,
+ default_clock_snapshot=None):
utils._check_type(event_class, bt2.event_class._EventClass)
- utils._check_type(packet, bt2.packet._Packet)
+
+ if event_class.stream_class.supports_packets:
+ utils._check_type(parent, bt2.packet._Packet)
+ else:
+ utils._check_type(parent, bt2.stream._Stream)
if default_clock_snapshot is not None:
if event_class.stream_class.default_clock_class is None:
raise ValueError('event messages in this stream must not have a default clock snapshot')
utils._check_uint64(default_clock_snapshot)
- ptr = native_bt.message_event_create_with_default_clock_snapshot(
- self._bt_ptr, event_class._ptr, packet._ptr, default_clock_snapshot)
+
+ if event_class.stream_class.supports_packets:
+ ptr = native_bt.message_event_create_with_packet_and_default_clock_snapshot(
+ self._bt_ptr, event_class._ptr, parent._ptr, default_clock_snapshot)
+ else:
+ ptr = native_bt.message_event_create_with_default_clock_snapshot(
+ self._bt_ptr, event_class._ptr, parent._ptr, default_clock_snapshot)
else:
if event_class.stream_class.default_clock_class is not None:
raise ValueError('event messages in this stream must have a default clock snapshot')
- ptr = native_bt.message_event_create(
- self._bt_ptr, event_class._ptr, packet._ptr)
+ if event_class.stream_class.supports_packets:
+ ptr = native_bt.message_event_create_with_packet(
+ self._bt_ptr, event_class._ptr, parent._ptr)
+ else:
+ ptr = native_bt.message_event_create(
+ self._bt_ptr, event_class._ptr, parent._ptr)
if ptr is None:
raise bt2.CreationError('cannot create event message object')
return id if id >= 0 else None
def create_packet(self):
+ if not self.cls.supports_packets:
+ raise bt2.Error('cannot create packet: stream class does not support packets')
+
packet_ptr = native_bt.packet_create(self._ptr)
if packet_ptr is None:
_assigns_automatic_stream_id = property(fset=_assigns_automatic_stream_id)
+ @property
+ def supports_packets(self):
+ return native_bt.stream_class_supports_packets(self._ptr)
+
@property
def packets_have_beginning_default_clock_snapshot(self):
return native_bt.stream_class_packets_have_beginning_default_clock_snapshot(self._ptr)
- def _packets_have_beginning_default_clock_snapshot(self, value):
- utils._check_bool(value)
- native_bt.stream_class_set_packets_have_beginning_default_clock_snapshot(self._ptr, value)
-
- _packets_have_beginning_default_clock_snapshot = property(fset=_packets_have_beginning_default_clock_snapshot)
-
@property
def packets_have_end_default_clock_snapshot(self):
return native_bt.stream_class_packets_have_end_default_clock_snapshot(self._ptr)
- def _packets_have_end_default_clock_snapshot(self, value):
- utils._check_bool(value)
- native_bt.stream_class_set_packets_have_end_default_clock_snapshot(self._ptr, value)
+ def _set_supports_packets(self, supports, with_begin_cs=False, with_end_cs=False):
+ utils._check_bool(supports)
+ utils._check_bool(with_begin_cs)
+ utils._check_bool(with_end_cs)
+
+ if not supports and (with_begin_cs or with_end_cs):
+ raise ValueError('cannot not support packets, but have default clock snapshots')
+
+ if not supports and self.packet_context_field_class is not None:
+ raise ValueError('stream class already has a packet context field class')
- _packets_have_end_default_clock_snapshot = property(fset=_packets_have_end_default_clock_snapshot)
+ native_bt.stream_class_set_supports_packets(self._ptr, supports, with_begin_cs, with_end_cs)
@property
def supports_discarded_events(self):
utils._check_bool(supports)
utils._check_bool(with_cs)
+ if supports and not self.supports_packets:
+ raise ValueError('cannot support discarded packets, but not support packets')
+
if not supports and with_cs:
raise ValueError('cannot not support discarded packets, but have default clock snapshots')
if packet_context_field_class is not None:
utils._check_type(packet_context_field_class,
bt2.field_class._StructureFieldClass)
+
+ if not self.supports_packets:
+ raise ValueError('stream class does not support packets')
+
status = native_bt.stream_class_set_packet_context_field_class(self._ptr,
packet_context_field_class._ptr)
utils._handle_func_status(status,
default_clock_class=None,
assigns_automatic_event_class_id=True,
assigns_automatic_stream_id=True,
+ supports_packets=False,
packets_have_beginning_default_clock_snapshot=False,
packets_have_end_default_clock_snapshot=False,
supports_discarded_events=False,
if name is not None:
sc._name = name
- if packet_context_field_class is not None:
- sc._packet_context_field_class = packet_context_field_class
-
if event_common_context_field_class is not None:
sc._event_common_context_field_class = event_common_context_field_class
if default_clock_class is not None:
sc._default_clock_class = default_clock_class
+ # call after `sc._default_clock_class` because, if
+ # `packets_have_beginning_default_clock_snapshot` or
+ # `packets_have_end_default_clock_snapshot` is true, then this
+ # stream class needs a default clock class already.
+ sc._set_supports_packets(supports_packets,
+ packets_have_beginning_default_clock_snapshot,
+ packets_have_end_default_clock_snapshot)
+
+ # call after sc._set_supports_packets() because, if
+ # `packet_context_field_class` is not `None`, then this stream
+ # class needs to support packets already.
+ if packet_context_field_class is not None:
+ sc._packet_context_field_class = packet_context_field_class
+
sc._assigns_automatic_event_class_id = assigns_automatic_event_class_id
sc._assigns_automatic_stream_id = assigns_automatic_stream_id
- sc._packets_have_beginning_default_clock_snapshot = packets_have_beginning_default_clock_snapshot
- sc._packets_have_end_default_clock_snapshot = packets_have_end_default_clock_snapshot
sc._set_supports_discarded_events(supports_discarded_events,
discarded_events_have_default_clock_snapshots)
sc._set_supports_discarded_packets(supports_discarded_packets,
struct bt_message *create_event_message(
struct bt_self_message_iterator *self_msg_iter,
const struct bt_event_class *c_event_class,
- const struct bt_packet *c_packet, bool with_cs,
+ const struct bt_packet *c_packet,
+ const struct bt_stream *c_stream, bool with_cs,
uint64_t raw_value)
{
struct bt_self_component_port_input_message_iterator *msg_iter =
struct bt_event_class *event_class = (void *) c_event_class;
struct bt_stream_class *stream_class;
struct bt_packet *packet = (void *) c_packet;
+ struct bt_stream *stream = (void *) c_stream;
struct bt_event *event;
+ BT_ASSERT(stream);
BT_ASSERT_PRE_NON_NULL(msg_iter, "Message iterator");
BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
- BT_ASSERT_PRE_NON_NULL(packet, "Packet");
BT_ASSERT_PRE(event_class_has_trace(event_class),
"Event class is not part of a trace: %!+E", event_class);
stream_class = bt_event_class_borrow_stream_class_inline(event_class);
"cs-val=%" PRIu64,
event_class, stream_class, with_cs, raw_value);
BT_LIB_LOGD("Creating event message object: %![ec-]+E", event_class);
- event = bt_event_create(event_class, packet);
+ event = bt_event_create(event_class, packet, stream);
if (G_UNLIKELY(!event)) {
BT_LIB_LOGE_APPEND_CAUSE(
"Cannot create event from event class: "
BT_ASSERT(!message->event);
message->event = event;
- bt_packet_set_is_frozen(packet, true);
+
+ if (packet) {
+ bt_packet_set_is_frozen(packet, true);
+ }
+
+ bt_stream_freeze(stream);
bt_event_class_freeze(event_class);
BT_LIB_LOGD("Created event message object: "
"%![msg-]+n, %![event-]+e", message, event);
}
struct bt_message *bt_message_event_create(
+ struct bt_self_message_iterator *msg_iter,
+ const struct bt_event_class *event_class,
+ const struct bt_stream *stream)
+{
+ BT_ASSERT_PRE_NON_NULL(stream, "Stream");
+ return create_event_message(msg_iter, event_class, NULL, stream, false, 0);
+}
+
+struct bt_message *bt_message_event_create_with_packet(
struct bt_self_message_iterator *msg_iter,
const struct bt_event_class *event_class,
const struct bt_packet *packet)
{
- return create_event_message(msg_iter, event_class, packet, false, 0);
+ BT_ASSERT_PRE_NON_NULL(packet, "Packet");
+ return create_event_message(msg_iter, event_class, packet,
+ packet->stream, false, 0);
}
struct bt_message *bt_message_event_create_with_default_clock_snapshot(
+ struct bt_self_message_iterator *msg_iter,
+ const struct bt_event_class *event_class,
+ const struct bt_stream *stream,
+ uint64_t raw_value)
+{
+ BT_ASSERT_PRE_NON_NULL(stream, "Stream");
+ return create_event_message(msg_iter, event_class, NULL, stream,
+ true, raw_value);
+}
+
+struct bt_message *
+bt_message_event_create_with_packet_and_default_clock_snapshot(
struct bt_self_message_iterator *msg_iter,
const struct bt_event_class *event_class,
const struct bt_packet *packet,
uint64_t raw_value)
{
+ BT_ASSERT_PRE_NON_NULL(packet, "Packet");
return create_event_message(msg_iter, event_class, packet,
- true, raw_value);
+ packet->stream, true, raw_value);
}
BT_HIDDEN
stream_class = bt_stream_borrow_class(stream);
BT_ASSERT(stream_class);
+ /*
+ * It's not possible to create a packet from a stream of which
+ * the class indicates that packets are not supported.
+ */
+ BT_ASSERT(stream_class->supports_packets);
+
if (pool == &msg_iter->graph->packet_begin_msg_pool) {
need_cs = stream_class->packets_have_beginning_default_clock_snapshot;
} else {
}
BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
- "%spackets-have-default-beginning-cs=%d, "
- "%spackets-have-default-end-cs=%d, "
+ "%ssupports-packets=%d, "
+ "%spackets-have-begin-default-cs=%d, "
+ "%spackets-have-end-default-cs=%d, "
"%ssupports-discarded-events=%d, "
"%sdiscarded-events-have-default-cs=%d, "
"%ssupports-discarded-packets=%d, "
"%sdiscarded-packets-have-default-cs=%d",
PRFIELD(stream_class->assigns_automatic_event_class_id),
PRFIELD(stream_class->assigns_automatic_stream_id),
+ PRFIELD(stream_class->supports_packets),
PRFIELD(stream_class->packets_have_beginning_default_clock_snapshot),
PRFIELD(stream_class->packets_have_end_default_clock_snapshot),
PRFIELD(stream_class->supports_discarded_events),
static inline void format_event(char **buf_ch, bool extended,
const char *prefix, const struct bt_event *event)
{
- const struct bt_packet *packet;
- const struct bt_stream *stream;
const struct bt_trace_class *trace_class;
const struct bt_stream_class *stream_class;
char tmp_prefix[TMP_PREFIX_LEN];
}
}
- packet = bt_event_borrow_packet_const(event);
- if (!packet) {
- return;
+ if (event->stream) {
+ BUF_APPEND(", %sstream-addr=%p", PRFIELD(event->stream));
+ SET_TMP_PREFIX("stream-");
+ format_stream(buf_ch, false, tmp_prefix, event->stream);
}
- BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet));
- SET_TMP_PREFIX("packet-");
- format_packet(buf_ch, false, tmp_prefix, packet);
- stream = bt_packet_borrow_stream_const(packet);
- if (!stream) {
- return;
+ if (event->packet) {
+ BUF_APPEND(", %spacket-addr=%p", PRFIELD(event->packet));
+ SET_TMP_PREFIX("packet-");
+ format_packet(buf_ch, false, tmp_prefix, event->packet);
}
-
- BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream));
- SET_TMP_PREFIX("stream-");
- format_stream(buf_ch, false, tmp_prefix, stream);
}
static inline void format_clock_class(char **buf_ch, bool extended,
}
if (msg_disc_items->default_begin_cs) {
- SET_TMP_PREFIX("default-begin-cs-");
+ SET_TMP_PREFIX("begin-default-cs-");
format_clock_snapshot(buf_ch, true, tmp_prefix,
msg_disc_items->default_begin_cs);
}
if (msg_disc_items->default_end_cs) {
- SET_TMP_PREFIX("default-end-cs-");
+ SET_TMP_PREFIX("end-default-cs-");
format_clock_snapshot(buf_ch, true, tmp_prefix,
msg_disc_items->default_end_cs);
}
}
((struct bt_event *) event)->frozen = is_frozen;
- BT_LOGD_STR("Setting event's packet's frozen state.");
- bt_packet_set_is_frozen(event->packet, is_frozen);
+
+ if (event->packet) {
+ BT_LOGD_STR("Setting event's packet's frozen state.");
+ bt_packet_set_is_frozen(event->packet, is_frozen);
+ }
}
BT_HIDDEN
struct bt_stream *bt_event_borrow_stream(struct bt_event *event)
{
BT_ASSERT_PRE_NON_NULL(event, "Event");
- return event->packet ? event->packet->stream : NULL;
+ return event->stream;
}
const struct bt_stream *bt_event_borrow_stream_const(
bt_object_put_ref(event->class);
BT_LOGD_STR("Putting event's packet.");
BT_OBJECT_PUT_REF_AND_RESET(event->packet);
+ BT_LOGD_STR("Putting event's stream.");
+ BT_OBJECT_PUT_REF_AND_RESET(event->stream);
g_free(event);
}
/* Owned by this */
struct bt_event_class *class;
- /* Owned by this */
+ /* Owned by this (can be `NULL`) */
struct bt_packet *packet;
+ /* Owned by this */
+ struct bt_stream *stream;
+
struct bt_field *common_context_field;
struct bt_field *specific_context_field;
struct bt_field *payload_field;
BT_ASSERT(event);
BT_LIB_LOGD("Resetting event: %!+e", event);
bt_event_set_is_frozen(event, false);
- bt_object_put_no_null_check(&event->packet->base);
- event->packet = NULL;
+ bt_object_put_no_null_check(&event->stream->base);
+ event->stream = NULL;
+
+ if (event->packet) {
+ bt_object_put_no_null_check(&event->packet->base);
+ event->packet = NULL;
+ }
}
static inline
event->class) == packet->stream->class,
"Packet's stream class and event's stream class differ: "
"%![event-]+e, %![packet-]+a", event, packet);
-
+ BT_ASSERT(event->stream->class->supports_packets);
BT_ASSERT(!event->packet);
event->packet = packet;
bt_object_get_no_null_check_no_parent_check(&event->packet->base);
event, packet);
}
+static inline
+void bt_event_set_stream(struct bt_event *event, struct bt_stream *stream)
+{
+ BT_ASSERT_PRE_NON_NULL(event, "Event");
+ BT_ASSERT_PRE_NON_NULL(stream, "Stream");
+ BT_ASSERT_PRE_EVENT_HOT(event);
+ BT_ASSERT_PRE(bt_event_class_borrow_stream_class(
+ event->class) == stream->class,
+ "Stream's class and event's stream class differ: "
+ "%![event-]+e, %![stream-]+s", event, stream);
+ BT_ASSERT(!event->stream);
+ event->stream = stream;
+ bt_object_get_no_null_check_no_parent_check(&event->stream->base);
+ BT_LIB_LOGD("Set event's stream: %![event-]+e, %![stream-]+s",
+ event, stream);
+}
+
static inline
struct bt_event *bt_event_create(struct bt_event_class *event_class,
- struct bt_packet *packet)
+ struct bt_packet *packet, struct bt_stream *stream)
{
struct bt_event *event = NULL;
BT_ASSERT(event_class);
+ BT_ASSERT(stream);
event = bt_object_pool_create_object(&event_class->event_pool);
if (G_UNLIKELY(!event)) {
BT_LIB_LOGE_APPEND_CAUSE(
bt_object_get_no_null_check(&event_class->base);
}
- BT_ASSERT(packet);
- bt_event_set_packet(event, packet);
+ bt_event_set_stream(event, stream);
+
+ if (packet) {
+ BT_ASSERT(packet);
+ bt_event_set_packet(event, packet);
+ }
+
goto end;
end:
struct bt_field_wrapper *field_wrapper;
BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE(stream_class->supports_packets,
+ "Stream class does not support packets: %![sc-]+S",
+ stream_class);
BT_ASSERT_PRE(stream_class->packet_context_fc,
"Stream class has no packet context field class: %!+S",
stream_class);
struct bt_stream *stream = (void *) c_stream;
BT_ASSERT_PRE_NON_NULL(stream, "Stream");
+ BT_ASSERT_PRE(stream->class->supports_packets,
+ "Stream class does not support packets: %![sc-]+S",
+ stream->class);
packet = bt_object_pool_create_object(&stream->packet_pool);
if (G_UNLIKELY(!packet)) {
BT_LIB_LOGE_APPEND_CAUSE(
};
BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE(stream_class->supports_packets,
+ "Stream class does not support packets: %![sc-]+S",
+ stream_class);
BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
"assignment property: %!+S", stream_class);
}
-bt_bool bt_stream_class_packets_have_beginning_default_clock_snapshot(
- const struct bt_stream_class *stream_class)
-{
- BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
- return (bt_bool) stream_class->packets_have_beginning_default_clock_snapshot;
-}
-
-void bt_stream_class_set_packets_have_beginning_default_clock_snapshot(
- struct bt_stream_class *stream_class, bt_bool value)
-{
- BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
- BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
- BT_ASSERT_PRE(!value || stream_class->default_clock_class,
- "Stream class has no default clock class: %!+S", stream_class);
- stream_class->packets_have_beginning_default_clock_snapshot =
- (bool) value;
- BT_LIB_LOGD("Set stream class's \"packets have default beginning "
- "clock snapshot\" property: %!+S", stream_class);
-}
-
-bt_bool bt_stream_class_packets_have_end_default_clock_snapshot(
- const struct bt_stream_class *stream_class)
-{
- BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
- return (bt_bool) stream_class->packets_have_end_default_clock_snapshot;
-}
-
-void bt_stream_class_set_packets_have_end_default_clock_snapshot(
- struct bt_stream_class *stream_class, bt_bool value)
-{
- BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
- BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
- BT_ASSERT_PRE(!value || stream_class->default_clock_class,
- "Stream class has no default clock class: %!+S", stream_class);
- stream_class->packets_have_end_default_clock_snapshot =
- (bool) value;
- BT_LIB_LOGD("Set stream class's \"packets have default end "
- "clock snapshot\" property: %!+S", stream_class);
-}
-
bt_bool bt_stream_class_assigns_automatic_stream_id(
const struct bt_stream_class *stream_class)
{
{
BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ BT_ASSERT_PRE(!supports_discarded_packets ||
+ stream_class->supports_packets,
+ "Stream class does not support packets: %!+S",
+ stream_class);
BT_ASSERT_PRE(supports_discarded_packets ||
!with_default_clock_snapshots,
"Discarded packets cannot have default clock snapshots when "
return (bt_bool) stream_class->discarded_packets_have_default_clock_snapshots;
}
+void bt_stream_class_set_supports_packets(
+ struct bt_stream_class *stream_class,
+ bt_bool supports_packets,
+ bt_bool with_beginning_default_clock_snapshot,
+ bt_bool with_end_default_clock_snapshot)
+{
+ bt_bool with_default_clock_snapshot =
+ with_beginning_default_clock_snapshot ||
+ with_end_default_clock_snapshot;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ BT_ASSERT_PRE(supports_packets ||
+ !with_default_clock_snapshot,
+ "Packets cannot have default clock snapshots when "
+ "not supported: %!+S", stream_class);
+ BT_ASSERT_PRE(!with_default_clock_snapshot ||
+ stream_class->default_clock_class,
+ "Stream class has no default clock class: %!+S", stream_class);
+ BT_ASSERT_PRE(supports_packets || !stream_class->packet_context_fc,
+ "Stream class already has a packet context field class: %!+S",
+ stream_class);
+ BT_ASSERT_PRE(supports_packets ||
+ !stream_class->supports_discarded_packets,
+ "Stream class already supports discarded packets: %!+S",
+ stream_class);
+ stream_class->supports_packets = (bool) supports_packets;
+ stream_class->packets_have_beginning_default_clock_snapshot =
+ (bool) with_beginning_default_clock_snapshot;
+ stream_class->packets_have_end_default_clock_snapshot =
+ (bool) with_end_default_clock_snapshot;
+ BT_LIB_LOGD("Set stream class's packets support property: %!+S",
+ stream_class);
+}
+
+bt_bool bt_stream_class_supports_packets(
+ const struct bt_stream_class *stream_class)
+{
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return (bt_bool) stream_class->supports_packets;
+}
+
+bt_bool bt_stream_class_packets_have_beginning_default_clock_snapshot(
+ const struct bt_stream_class *stream_class)
+{
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return (bt_bool) stream_class->packets_have_beginning_default_clock_snapshot;
+}
+
+bt_bool bt_stream_class_packets_have_end_default_clock_snapshot(
+ const struct bt_stream_class *stream_class)
+{
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return (bt_bool) stream_class->packets_have_end_default_clock_snapshot;
+}
+
void bt_stream_class_set_assigns_automatic_stream_id(
struct bt_stream_class *stream_class,
bt_bool value)
uint64_t id;
bool assigns_automatic_event_class_id;
bool assigns_automatic_stream_id;
+ bool supports_packets;
bool packets_have_beginning_default_clock_snapshot;
bool packets_have_end_default_clock_snapshot;
bool supports_discarded_events;
ctx->ir_sc = bt_stream_class_create_with_id(ctx->ir_tc, ctx->sc->id);
BT_ASSERT(ctx->ir_sc);
bt_stream_class_put_ref(ctx->ir_sc);
+
+ if (ctx->sc->default_clock_class) {
+ BT_ASSERT(ctx->sc->default_clock_class->ir_cc);
+ 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_supports_packets(ctx->ir_sc, BT_TRUE,
+ ctx->sc->packets_have_ts_begin, 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->scope = CTF_SCOPE_PACKET_CONTEXT;
ir_fc = scope_ctf_field_class_to_ir(ctx);
if (ir_fc) {
BT_FALSE);
bt_stream_class_set_assigns_automatic_stream_id(ctx->ir_sc, BT_FALSE);
- if (ctx->sc->default_clock_class) {
- BT_ASSERT(ctx->sc->default_clock_class->ir_cc);
- 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_beginning_default_clock_snapshot(
- ctx->ir_sc, ctx->sc->packets_have_ts_begin);
- bt_stream_class_set_packets_have_end_default_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;
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(
+ msg = bt_message_event_create_with_packet_and_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,
+ msg = bt_message_event_create_with_packet(notit->msg_iter,
notit->meta.ec->ir_ec, notit->packet);
}
const bt_clock_class *default_clock_class;
GString *default_clock_class_name;
+ bool has_packets;
bool packets_have_ts_begin;
bool packets_have_ts_end;
bool has_discarded_events;
sc->event_classes_from_ir = g_hash_table_new(g_direct_hash,
g_direct_equal);
BT_ASSERT(sc->event_classes_from_ir);
+ sc->has_packets = bt_stream_class_supports_packets(ir_sc);
sc->packets_have_ts_begin =
bt_stream_class_packets_have_beginning_default_clock_snapshot(
ir_sc);
/* Other members */
if (stream->sc->packet_context_fc) {
- const bt_field *packet_context_field =
- bt_packet_borrow_context_field_const(
- stream->packet_state.packet);
+ const bt_field *packet_context_field;
+ BT_ASSERT(stream->packet_state.packet);
+ packet_context_field = bt_packet_borrow_context_field_const(
+ stream->packet_state.packet);
BT_ASSERT(packet_context_field);
ret = write_struct_field(stream,
(void *) stream->sc->packet_context_fc,
*/
uint64_t context_offset_bits;
- /* Owned by this */
+ /*
+ * Owned by this; `NULL` if the current packet is closed
+ * or if the trace IR stream does not support packets.
+ */
const bt_packet *packet;
} packet_state;
msg);
}
+ /*
+ * If this event's stream does not support packets, then we
+ * lazily create artificial packets.
+ *
+ * The size of an artificial packet is arbitrarily at least
+ * 4 MiB (it usually is greater because we close it when
+ * comes the time to write a new event and the packet's content
+ * size is >= 4 MiB), except the last one which can be smaller.
+ */
+ if (G_UNLIKELY(!stream->sc->has_packets)) {
+ if (stream->packet_state.is_open &&
+ bt_ctfser_get_offset_in_current_packet_bits(&stream->ctfser) / 8 >=
+ 4 * 1024 * 1024) {
+ /*
+ * Stream's current packet is larger than 4 MiB:
+ * close it. A new packet will be opened just
+ * below.
+ */
+ ret = fs_sink_stream_close_packet(stream, NULL);
+ if (ret) {
+ status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+ goto end;
+ }
+ }
+
+ if (!stream->packet_state.is_open) {
+ /* Stream's packet is not currently opened: open it */
+ ret = fs_sink_stream_open_packet(stream, NULL, NULL);
+ if (ret) {
+ status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+ goto end;
+ }
+ }
+ }
+
+ BT_ASSERT(stream->packet_state.is_open);
ret = fs_sink_stream_write_event(stream, cs, ir_event, ec);
if (G_UNLIKELY(ret)) {
status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
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 or discarded packets support
+ * without packets support. Packets are the way to know where
+ * discarded events/packets occured in CTF 1.8.
+ */
+ if (!bt_stream_class_supports_packets(ir_sc)) {
+ BT_ASSERT(!bt_stream_class_supports_discarded_packets(ir_sc));
+
+ if (!fs_sink->ignore_discarded_events &&
+ bt_stream_class_supports_discarded_events(ir_sc)) {
+ BT_COMP_LOGE("Unsupported stream: "
+ "stream does not support packets, "
+ "but supports discarded events: "
+ "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_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+ goto end;
+ }
+ }
+
/*
* Not supported: discarded events with default clock snapshots,
* but packet beginning/end without default clock snapshot.
goto end;
}
+ if (G_UNLIKELY(!stream->sc->has_packets &&
+ stream->packet_state.is_open)) {
+ /* Close stream's current artificial packet */
+ int ret = fs_sink_stream_close_packet(stream, NULL);
+
+ if (ret) {
+ status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+ goto end;
+ }
+ }
+
BT_COMP_LOGI("Closing stream file: "
"stream-id=%" PRIu64 ", stream-name=\"%s\", "
"trace-name=\"%s\", path=\"%s/%s\"",
const bt_clock_snapshot *cs;
const bt_clock_class *default_cc;
const bt_packet *in_packet;
+ const bt_stream *in_stream;
+ const bt_stream *out_stream;
bt_event_class *out_event_class;
- bt_packet *out_packet;
+ bt_packet *out_packet = NULL;
bt_event *out_event;
bt_logging_level log_level = debug_it->log_level;
bt_self_component *self_comp = debug_it->self_comp;
}
BT_ASSERT(out_event_class);
+ /* Borrow the input stream. */
+ in_stream = bt_event_borrow_stream_const(in_event);
+ BT_ASSERT(in_stream);
+ out_stream = trace_ir_mapping_borrow_mapped_stream(debug_it->ir_maps,
+ in_stream);
+ BT_ASSERT(in_stream);
+
/* Borrow the input and output packets. */
in_packet = bt_event_borrow_packet_const(in_event);
- out_packet = trace_ir_mapping_borrow_mapped_packet(debug_it->ir_maps,
- in_packet);
+ if (in_packet) {
+ out_packet = trace_ir_mapping_borrow_mapped_packet(
+ debug_it->ir_maps, in_packet);
+ }
default_cc = bt_stream_class_borrow_default_clock_class_const(
bt_event_class_borrow_stream_class_const(in_event_class));
in_message);
/* Create an output event message. */
- out_message = bt_message_event_create_with_default_clock_snapshot(
+ if (out_packet) {
+ out_message =
+ bt_message_event_create_with_packet_and_default_clock_snapshot(
debug_it->input_iterator,
out_event_class, out_packet,
bt_clock_snapshot_get_value(cs));
+ } else {
+ out_message =
+ bt_message_event_create_with_default_clock_snapshot(
+ debug_it->input_iterator,
+ out_event_class, out_stream,
+ bt_clock_snapshot_get_value(cs));
+ }
} else {
- out_message = bt_message_event_create(debug_it->input_iterator,
- out_event_class, out_packet);
+ if (out_packet) {
+ out_message = bt_message_event_create_with_packet(
+ debug_it->input_iterator, out_event_class,
+ out_packet);
+ } else {
+ out_message = bt_message_event_create(
+ debug_it->input_iterator, out_event_class,
+ out_stream);
+ }
}
if (!out_message) {
}
- bt_stream_class_set_packets_have_beginning_default_clock_snapshot(
+ bt_stream_class_set_supports_packets(
out_stream_class,
+ bt_stream_class_supports_packets(in_stream_class),
bt_stream_class_packets_have_beginning_default_clock_snapshot(
- in_stream_class));
- bt_stream_class_set_packets_have_end_default_clock_snapshot(
- out_stream_class,
+ in_stream_class),
bt_stream_class_packets_have_end_default_clock_snapshot(
in_stream_class));
bt_stream_class_set_supports_discarded_events(
/* Write configuration */
write_bool_prop_line(ctx,
- "Packets have beginning default clock snapshot",
- bt_stream_class_packets_have_beginning_default_clock_snapshot(sc));
- write_bool_prop_line(ctx,
- "Packets have end default clock snapshot",
- bt_stream_class_packets_have_end_default_clock_snapshot(sc));
+ "Supports packets", bt_stream_class_supports_packets(sc));
+
+ if (bt_stream_class_supports_packets(sc)) {
+ write_bool_prop_line(ctx,
+ "Packets have beginning default clock snapshot",
+ bt_stream_class_packets_have_beginning_default_clock_snapshot(sc));
+ write_bool_prop_line(ctx,
+ "Packets have end default clock snapshot",
+ bt_stream_class_packets_have_end_default_clock_snapshot(sc));
+ }
+
write_bool_prop_line(ctx,
"Supports discarded events",
bt_stream_class_supports_discarded_events(sc));
enum {
STATE_EMIT_STREAM_BEGINNING,
- STATE_EMIT_PACKET_BEGINNING,
STATE_EMIT_EVENT,
- STATE_EMIT_PACKET_END,
STATE_EMIT_STREAM_END,
STATE_DONE,
} state;
bt_event_class *event_class;
bt_trace *trace;
bt_stream *stream;
- bt_packet *packet;
bt_clock_class *clock_class;
};
BT_COMP_LOGE_STR("Cannot set stream class's default clock class.");
goto error;
}
-
- bt_stream_class_set_packets_have_beginning_default_clock_snapshot(
- dmesg_comp->stream_class, BT_TRUE);
- bt_stream_class_set_packets_have_end_default_clock_snapshot(
- dmesg_comp->stream_class, BT_TRUE);
}
dmesg_comp->event_class = bt_event_class_create(
}
static
-int create_packet_and_stream_and_trace(struct dmesg_component *dmesg_comp)
+int create_stream_and_trace(struct dmesg_component *dmesg_comp)
{
int ret = 0;
const char *trace_name = NULL;
goto error;
}
- dmesg_comp->packet = bt_packet_create(dmesg_comp->stream);
- if (!dmesg_comp->packet) {
- BT_COMP_LOGE_STR("Cannot create packet object.");
- goto error;
- }
-
goto end;
error:
}
static
-int try_create_meta_stream_packet(struct dmesg_component *dmesg_comp,
- bool has_ts)
+int try_create_meta_stream(struct dmesg_component *dmesg_comp, bool has_ts)
{
int ret = 0;
goto error;
}
- ret = create_packet_and_stream_and_trace(dmesg_comp);
+ ret = create_stream_and_trace(dmesg_comp);
if (ret) {
- BT_COMP_LOGE("Cannot create packet and stream objects: "
+ BT_COMP_LOGE("Cannot create stream object: "
"dmesg-comp-addr=%p", dmesg_comp);
goto error;
}
g_string_free(dmesg_comp->params.path, TRUE);
}
- bt_packet_put_ref(dmesg_comp->packet);
bt_trace_put_ref(dmesg_comp->trace);
bt_stream_class_put_ref(dmesg_comp->stream_class);
bt_event_class_put_ref(dmesg_comp->event_class);
/*
* At this point, we know if the stream class's event header
* field class should have a timestamp or not, so we can lazily
- * create the metadata, stream, and packet objects.
+ * create the metadata and stream objects.
*/
- ret = try_create_meta_stream_packet(dmesg_comp, has_timestamp);
+ ret = try_create_meta_stream(dmesg_comp, has_timestamp);
if (ret) {
- /* try_create_meta_stream_packet() logs errors */
+ /* try_create_meta_stream() logs errors */
goto error;
}
if (dmesg_comp->clock_class) {
msg = bt_message_event_create_with_default_clock_snapshot(
msg_iter->pc_msg_iter,
- dmesg_comp->event_class, dmesg_comp->packet, ts);
+ dmesg_comp->event_class, dmesg_comp->stream, ts);
msg_iter->last_clock_value = ts;
} else {
msg = bt_message_event_create(msg_iter->pc_msg_iter,
- dmesg_comp->event_class, dmesg_comp->packet);
+ dmesg_comp->event_class, dmesg_comp->stream);
}
if (!msg) {
}
if (dmesg_msg_iter->tmp_event_msg ||
- dmesg_msg_iter->state == STATE_EMIT_PACKET_END ||
dmesg_msg_iter->state == STATE_EMIT_STREAM_END) {
goto handle_state;
}
status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END;
goto end;
} else {
- /* End current packet now */
+ /* End stream now */
dmesg_msg_iter->state =
- STATE_EMIT_PACKET_END;
+ STATE_EMIT_STREAM_END;
goto handle_state;
}
}
BT_ASSERT(dmesg_msg_iter->tmp_event_msg);
*msg = bt_message_stream_beginning_create(
dmesg_msg_iter->pc_msg_iter, dmesg_comp->stream);
- dmesg_msg_iter->state = STATE_EMIT_PACKET_BEGINNING;
- break;
- case STATE_EMIT_PACKET_BEGINNING:
- BT_ASSERT(dmesg_msg_iter->tmp_event_msg);
-
- if (dmesg_comp->clock_class) {
- *msg = bt_message_packet_beginning_create_with_default_clock_snapshot(
- dmesg_msg_iter->pc_msg_iter, dmesg_comp->packet,
- dmesg_msg_iter->last_clock_value);
- } else {
- *msg = bt_message_packet_beginning_create(
- dmesg_msg_iter->pc_msg_iter, dmesg_comp->packet);
- }
-
dmesg_msg_iter->state = STATE_EMIT_EVENT;
break;
case STATE_EMIT_EVENT:
*msg = dmesg_msg_iter->tmp_event_msg;
dmesg_msg_iter->tmp_event_msg = NULL;
break;
- case STATE_EMIT_PACKET_END:
- if (dmesg_comp->clock_class) {
- *msg = bt_message_packet_end_create_with_default_clock_snapshot(
- dmesg_msg_iter->pc_msg_iter, dmesg_comp->packet,
- dmesg_msg_iter->last_clock_value);
- } else {
- *msg = bt_message_packet_end_create(
- dmesg_msg_iter->pc_msg_iter, dmesg_comp->packet);
- }
-
- dmesg_msg_iter->state = STATE_EMIT_STREAM_END;
- break;
case STATE_EMIT_STREAM_END:
*msg = bt_message_stream_end_create(
dmesg_msg_iter->pc_msg_iter, dmesg_comp->stream);
bool print_names = pretty->options.print_header_field_names;
int ret = 0;
const bt_event_class *event_class = NULL;
- const bt_packet *packet = NULL;
const bt_stream *stream = NULL;
const bt_trace *trace = NULL;
const bt_event *event = bt_message_event_borrow_event_const(event_msg);
bt_property_availability prop_avail;
event_class = bt_event_borrow_class_const(event);
- packet = bt_event_borrow_packet_const(event);
- stream = bt_packet_borrow_stream_const(packet);
+ stream = bt_event_borrow_stream_const(event);
trace = bt_stream_borrow_trace_const(stream);
ret = print_event_timestamp(pretty, event_msg, &pretty->start_line);
if (ret) {
packet = bt_event_borrow_packet_const(event);
if (!packet) {
- ret = -1;
goto end;
}
main_field = bt_packet_borrow_context_field_const(packet);
* couldn't be using the trimmer component.
*/
BT_ASSERT(ns_from_origin);
- BT_ASSERT(sstate->cur_packet);
if (G_UNLIKELY(!trimmer_it->end.is_infinite &&
*ns_from_origin > trimmer_it->end.ns_from_origin)) {
_cc, _tc = run_in_component_init(f)
_trace = _tc()
- _sc = _tc.create_stream_class(default_clock_class=_cc,
- packets_have_beginning_default_clock_snapshot=True,
- packets_have_end_default_clock_snapshot=True)
+ _sc = _tc.create_stream_class(default_clock_class=_cc)
_ec = _sc.create_event_class(name='salut')
_stream = _trace.create_stream(_sc)
- _packet = _stream.create_packet()
- self._packet = _packet
self._stream = _stream
self._ec = _ec
self._cc = _cc
if self._at == 0:
notif = self._create_stream_beginning_message(_stream)
elif self._at == 1:
- notif = self._create_packet_beginning_message(_packet, 100)
+ notif = self._create_event_message(_ec, _stream, 123)
elif self._at == 2:
- notif = self._create_event_message(_ec, _packet, 123)
+ notif = self._create_event_message(_ec, _stream, 2**63)
elif self._at == 3:
- notif = self._create_event_message(_ec, _packet, 2**63)
- elif self._at == 4:
- notif = self._create_packet_end_message(_packet)
- elif self._at == 5:
notif = self._create_stream_end_message(_stream)
else:
raise bt2.Stop
self._src_comp.output_ports['out'])
for i, msg in enumerate(self._msg_iter):
- if i == 2:
+ if i == 1:
self._msg = msg
- elif i == 3:
+ elif i == 2:
self._msg_clock_overflow = msg
break
event_fields_config=None,
with_clockclass=False,
with_cc=False, with_sc=False,
- with_ep=False):
+ with_ep=False, with_packet=False):
class MyIter(bt2._UserMessageIterator):
def __init__(self, self_output_port):
self._at = 0
+ self._msgs = [
+ self._create_stream_beginning_message(test_obj.stream),
+ ]
- def __next__(self):
- if self._at == 0:
- msg = self._create_stream_beginning_message(test_obj.stream)
- elif self._at == 1:
+ if with_packet:
assert test_obj.packet
- msg = self._create_packet_beginning_message(test_obj.packet)
- elif self._at == 2:
- default_clock_snapshot = 789 if with_clockclass else None
+ self._msgs.append(self._create_packet_beginning_message(test_obj.packet))
+
+ default_clock_snapshot = 789 if with_clockclass else None
+
+ if with_packet:
assert test_obj.packet
- msg = self._create_event_message(test_obj.event_class, test_obj.packet, default_clock_snapshot)
- if event_fields_config is not None:
- event_fields_config(msg.event)
- elif self._at == 3:
- msg = self._create_packet_end_message(test_obj.packet)
- elif self._at == 4:
- msg = self._create_stream_end_message(test_obj.stream)
- elif self._at >= 5:
+ ev_parent = test_obj.packet
+ else:
+ assert test_obj.stream
+ ev_parent = test_obj.stream
+
+ msg = self._create_event_message(test_obj.event_class, ev_parent, default_clock_snapshot)
+
+ if event_fields_config is not None:
+ event_fields_config(msg.event)
+
+ self._msgs.append(msg)
+
+ if with_packet:
+ self._msgs.append(self._create_packet_end_message(test_obj.packet))
+
+ self._msgs.append(self._create_stream_end_message(test_obj.stream))
+
+ def __next__(self):
+ if self._at == len(self._msgs):
raise bt2.Stop
+ msg = self._msgs[self._at]
self._at += 1
return msg
))
# packet context (stream-class-defined)
- pc = tc.create_structure_field_class()
- pc += OrderedDict((
- ('something', tc.create_unsigned_integer_field_class(8)),
- ('something_else', tc.create_real_field_class()),
- ))
+ pc = None
+
+ if with_packet:
+ pc = tc.create_structure_field_class()
+ pc += OrderedDict((
+ ('something', tc.create_unsigned_integer_field_class(8)),
+ ('something_else', tc.create_real_field_class()),
+ ))
stream_class = tc.create_stream_class(default_clock_class=clock_class,
event_common_context_field_class=cc,
- packet_context_field_class=pc)
+ packet_context_field_class=pc,
+ supports_packets=with_packet)
# specific context (event-class-defined)
sc = None
trace = tc()
stream = trace.create_stream(stream_class)
- packet = stream.create_packet()
+
+ if with_packet:
+ packet = stream.create_packet()
if packet_fields_config is not None:
+ assert packet
packet_fields_config(packet)
- test_obj.packet = packet
+ if with_packet:
+ test_obj.packet = packet
+
test_obj.stream = stream
test_obj.event_class = event_class
self._src_comp = self._graph.add_component(MySrc, 'my_source')
self._msg_iter = self._graph.create_output_port_message_iterator(self._src_comp.output_ports['out'])
- for i, msg in enumerate(self._msg_iter):
- if i == 2:
+ for msg in self._msg_iter:
+ if type(msg) is bt2._EventMessage:
return msg
def test_attr_event_class(self):
msg = self._create_test_event_message(packet_fields_config=packet_fields_config,
event_fields_config=event_fields_config,
- with_cc=True, with_sc=True, with_ep=True)
+ with_cc=True, with_sc=True, with_ep=True,
+ with_packet=True)
ev = msg.event
# Test event fields
packet_context_fc.append_member(name, fc)
trace = tc()
- stream_class = tc.create_stream_class(packet_context_field_class=packet_context_fc)
+ stream_class = tc.create_stream_class(packet_context_field_class=packet_context_fc,
+ supports_packets=True)
stream = trace.create_stream(stream_class)
return stream
# The path to the selector field is resolved when the sequence is
# actually used, for example in a packet context.
- self._tc.create_stream_class(packet_context_field_class=outer_struct_fc)
+ self._tc.create_stream_class(supports_packets=True, packet_context_field_class=outer_struct_fc)
return fc
# The path to the length field is resolved when the sequence is
# actually used, for example in a packet context.
- self._tc.create_stream_class(packet_context_field_class=outer_struct_fc)
+ self._tc.create_stream_class(packet_context_field_class=outer_struct_fc,
+ supports_packets=True)
return fc
def _build_meta(self):
self._tc = self._component._create_trace_class()
self._t = self._tc()
- self._sc = self._tc.create_stream_class()
+ self._sc = self._tc.create_stream_class(supports_packets=True)
self._ec = self._sc.create_event_class(name='salut')
self._my_int_ft = self._tc.create_signed_integer_field_class(32)
payload_ft = self._tc.create_structure_field_class()
cc = None
sc = tc.create_stream_class(default_clock_class=cc,
+ supports_packets=True,
packets_have_beginning_default_clock_snapshot=with_cc,
packets_have_end_default_clock_snapshot=with_cc,
supports_discarded_events=True,
class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
def __init__(self, params):
tc = self._create_trace_class()
- sc = tc.create_stream_class()
+ sc = tc.create_stream_class(supports_packets=True)
ec = sc.create_event_class()
self._add_output_port('out', (tc, sc, ec))
message_iterator_class=MySourceIter):
def __init__(self, params):
tc = self._create_trace_class()
- sc = tc.create_stream_class()
+ sc = tc.create_stream_class(supports_packets=True)
ec = sc.create_event_class()
self._add_output_port('out', (tc, sc, ec))
self._add_output_port('out')
trace_class = self._create_trace_class()
- stream_class = trace_class.create_stream_class()
+ stream_class = trace_class.create_stream_class(supports_packets=True)
# Create payload field class
my_int_ft = trace_class.create_signed_integer_field_class(32)
# stream class
sc = tc.create_stream_class(default_clock_class=clock_class,
event_common_context_field_class=sec,
- packet_context_field_class=pc)
+ packet_context_field_class=pc,
+ supports_packets=True)
# event context
ec = tc.create_structure_field_class()
self.assertIsNone(sc.default_clock_class)
self.assertTrue(sc.assigns_automatic_event_class_id)
self.assertTrue(sc.assigns_automatic_stream_id)
+ self.assertFalse(sc.supports_packets)
self.assertFalse(sc.packets_have_beginning_default_clock_snapshot)
self.assertFalse(sc.packets_have_end_default_clock_snapshot)
self.assertFalse(sc.supports_discarded_events)
def test_create_packet_context_field_class(self):
fc = self._tc.create_structure_field_class()
- sc = self._tc.create_stream_class(packet_context_field_class=fc)
+ sc = self._tc.create_stream_class(packet_context_field_class=fc,
+ supports_packets=True)
self.assertEqual(sc.packet_context_field_class, fc)
def test_create_invalid_packet_context_field_class(self):
with self.assertRaises(TypeError):
self._tc.create_stream_class(packet_context_field_class=22)
+ def test_create_invalid_packet_context_field_class_no_packets(self):
+ fc = self._tc.create_structure_field_class()
+
+ with self.assertRaises(ValueError):
+ self._tc.create_stream_class(packet_context_field_class=fc)
+
def test_create_event_common_context_field_class(self):
fc = self._tc.create_structure_field_class()
sc = self._tc.create_stream_class(event_common_context_field_class=fc)
with self.assertRaises(ValueError):
sc.create_event_class()
- def test_packets_have_beginning_default_clock_snapshot(self):
- sc = self._tc.create_stream_class(default_clock_class=self._cc, packets_have_beginning_default_clock_snapshot=True)
+ def test_supports_packets_without_cs(self):
+ sc = self._tc.create_stream_class(default_clock_class=self._cc,
+ supports_packets=True)
+ self.assertTrue(sc.supports_packets)
+ self.assertFalse(sc.packets_have_beginning_default_clock_snapshot)
+ self.assertFalse(sc.packets_have_end_default_clock_snapshot)
+
+ def test_supports_packets_with_begin_cs(self):
+ sc = self._tc.create_stream_class(default_clock_class=self._cc,
+ supports_packets=True,
+ packets_have_beginning_default_clock_snapshot=True)
+ self.assertTrue(sc.supports_packets)
self.assertTrue(sc.packets_have_beginning_default_clock_snapshot)
+ self.assertFalse(sc.packets_have_end_default_clock_snapshot)
- def test_packets_have_beginning_default_clock_snapshot_raises(self):
+ def test_supports_packets_with_end_cs(self):
+ sc = self._tc.create_stream_class(default_clock_class=self._cc,
+ supports_packets=True,
+ packets_have_end_default_clock_snapshot=True)
+ self.assertTrue(sc.supports_packets)
+ self.assertFalse(sc.packets_have_beginning_default_clock_snapshot)
+ self.assertTrue(sc.packets_have_end_default_clock_snapshot)
+
+ def test_supports_packets_raises_type_error(self):
with self.assertRaises(TypeError):
- sc = self._tc.create_stream_class(packets_have_beginning_default_clock_snapshot="something")
+ sc = self._tc.create_stream_class(default_clock_class=self._cc,
+ supports_packets=23)
- def test_packets_have_end_default_clock_snapshot(self):
- sc = self._tc.create_stream_class(default_clock_class=self._cc, packets_have_end_default_clock_snapshot=True)
- self.assertTrue(sc.packets_have_end_default_clock_snapshot)
+ def test_packets_have_begin_default_cs_raises_type_error(self):
+ with self.assertRaises(TypeError):
+ sc = self._tc.create_stream_class(default_clock_class=self._cc,
+ packets_have_beginning_default_clock_snapshot=23)
- def test_packets_have_end_default_clock_snapshot_raises(self):
+ def test_packets_have_end_default_cs_raises_type_error(self):
with self.assertRaises(TypeError):
- sc = self._tc.create_stream_class(packets_have_end_default_clock_snapshot="something")
+ sc = self._tc.create_stream_class(default_clock_class=self._cc,
+ packets_have_end_default_clock_snapshot=23)
+
+ def test_does_not_support_packets_raises_with_begin_cs(self):
+ with self.assertRaises(ValueError):
+ sc = self._tc.create_stream_class(default_clock_class=self._cc,
+ packets_have_beginning_default_clock_snapshot=True)
+
+ def test_does_not_support_packets_raises_with_end_cs(self):
+ with self.assertRaises(ValueError):
+ sc = self._tc.create_stream_class(default_clock_class=self._cc,
+ packets_have_end_default_clock_snapshot=True)
def test_supports_discarded_events_without_cs(self):
sc = self._tc.create_stream_class(default_clock_class=self._cc,
def test_supports_discarded_packets_without_cs(self):
sc = self._tc.create_stream_class(default_clock_class=self._cc,
- supports_discarded_packets=True)
+ supports_discarded_packets=True,
+ supports_packets=True)
self.assertTrue(sc.supports_discarded_packets)
self.assertFalse(sc.discarded_packets_have_default_clock_snapshots)
def test_supports_discarded_packets_with_cs(self):
sc = self._tc.create_stream_class(default_clock_class=self._cc,
supports_discarded_packets=True,
- discarded_packets_have_default_clock_snapshots=True)
+ discarded_packets_have_default_clock_snapshots=True,
+ supports_packets=True)
self.assertTrue(sc.supports_discarded_packets)
self.assertTrue(sc.discarded_packets_have_default_clock_snapshots)
+ def test_supports_discarded_packets_raises_without_packet_support(self):
+ with self.assertRaises(ValueError):
+ sc = self._tc.create_stream_class(default_clock_class=self._cc,
+ supports_discarded_packets=True)
+
def test_supports_discarded_packets_raises_type_error(self):
with self.assertRaises(TypeError):
sc = self._tc.create_stream_class(default_clock_class=self._cc,
- supports_discarded_packets=23)
+ supports_discarded_packets=23,
+ supports_packets=True)
def test_discarded_packets_have_default_cs_raises_type_error(self):
with self.assertRaises(TypeError):
sc = self._tc.create_stream_class(default_clock_class=self._cc,
- discarded_packets_have_default_clock_snapshots=23)
+ discarded_packets_have_default_clock_snapshots=23,
+ supports_packets=True)
def test_does_not_support_discarded_packets_raises_with_cs(self):
with self.assertRaises(ValueError):
sc = self._tc.create_stream_class(default_clock_class=self._cc,
- discarded_packets_have_default_clock_snapshots=True)
+ discarded_packets_have_default_clock_snapshots=True,
+ supports_packets=True)
def test_trace_class(self):
sc = self._tc.create_stream_class()
# possible to represent with this clock class).
cc = self._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(10000))
sc = tc.create_stream_class(default_clock_class=cc,
+ supports_packets=True,
packets_have_beginning_default_clock_snapshot=True,
packets_have_end_default_clock_snapshot=True)
ec1 = sc.create_event_class(name='event 1')
Trace class:
Stream class (ID 0):
+ Supports packets: Yes
Packets have beginning default clock snapshot: Yes
Packets have end default clock snapshot: Yes
Supports discarded events: Yes
Trace class:
Stream class (ID 0):
+ Supports packets: Yes
Packets have beginning default clock snapshot: Yes
Packets have end default clock snapshot: Yes
Supports discarded events: Yes
Trace class:
Stream class (ID 0):
+ Supports packets: Yes
Packets have beginning default clock snapshot: Yes
Packets have end default clock snapshot: Yes
Supports discarded events: Yes
Trace class:
Stream class (ID 0):
+ Supports packets: Yes
Packets have beginning default clock snapshot: No
Packets have end default clock snapshot: No
Supports discarded events: No
return event;
}
-static void set_stream_class_field_classes(
- bt_stream_class *stream_class)
-{
- bt_trace_class *trace_class =
- bt_stream_class_borrow_trace_class(stream_class);
- bt_field_class *packet_context_type;
- bt_field_class *fc;
- int ret;
-
- packet_context_type = bt_field_class_structure_create(trace_class);
- BT_ASSERT(packet_context_type);
- fc = bt_field_class_unsigned_integer_create(trace_class);
- BT_ASSERT(fc);
- bt_field_class_integer_set_field_value_range(fc, 32);
- ret = bt_field_class_structure_append_member(packet_context_type,
- "packet_size", fc);
- BT_ASSERT(ret == 0);
- bt_field_class_put_ref(fc);
- fc = bt_field_class_unsigned_integer_create(trace_class);
- BT_ASSERT(fc);
- bt_field_class_integer_set_field_value_range(fc, 32);
- ret = bt_field_class_structure_append_member(packet_context_type,
- "content_size", fc);
- BT_ASSERT(ret == 0);
- bt_field_class_put_ref(fc);
- ret = bt_stream_class_set_packet_context_field_class(
- stream_class, packet_context_type);
- BT_ASSERT(ret == 0);
- bt_field_class_put_ref(packet_context_type);
-}
-
static void create_sc1(bt_trace_class *trace_class)
{
int ret;
BT_ASSERT(sc1);
ret = bt_stream_class_set_name(sc1, "sc1");
BT_ASSERT(ret == 0);
- set_stream_class_field_classes(sc1);
ec1 = create_complex_event(sc1, "ec1");
BT_ASSERT(ec1);
ec2 = create_simple_event(sc1, "ec2");
BT_ASSERT(sc2);
ret = bt_stream_class_set_name(sc2, "sc2");
BT_ASSERT(ret == 0);
- set_stream_class_field_classes(sc2);
ec3 = create_simple_event(sc2, "ec3");
ret_stream = bt_event_class_borrow_stream_class(ec3);
ok(ret_stream == sc2, "Borrow parent stream SC2 from EC3");