From 26fc5aedf48df3f1654fe4d0b6ada1a10cd804f2 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 8 Jul 2019 12:33:30 -0400 Subject: [PATCH] lib: make packets and packet messages optional, disabled by default This patch makes it optional for the streams of a given stream class to support the concept of packets, much like the support for discarded events and discarded packets is already optional. Packets exist to support trace formats which group events into packets, all the packet's events sharing the same packet context information. CTF is currently the single input format which needs the packet concept. Other, more simple sources (existing and future) which do not need the packet concept need, before this patch, to create at least one and, for each stream, to emit the packet beginning and packet end messages at the right locations within the message flow. This makes this part of the API cumbersome and unnecessary. With this patch, a message iterator can simply emit: 1. Stream beginning message 2. Event messages 3. Stream end message API changes =========== When you create a stream class with bt_stream_class_create() or bt_stream_class_create_with_id(), the created stream class does NOT support packets by default. This is to make the initial stream class's configuration as simple as possible. This means that: * You cannot create packet objects from the instances of this stream class (bt_packet_create()). * You cannot create packet beginning and packet end messages for the instances of this stream class because you don't have any packet object (bt_message_packet_beginning_create(), bt_message_packet_beginning_create_with_default_clock_snapshot(), bt_message_packet_end_create(), and bt_message_packet_end_create_with_default_clock_snapshot()). * The stream class cannot support discarded packets (bt_stream_class_set_supports_discarded_packets()). * The stream class cannot have a packet context field class (bt_stream_class_set_packet_context_field_class()). * You cannot create a detached packet context field from this stream class (bt_packet_context_field_create()). * You cannot create an event message with a packet object (bt_message_event_create() and bt_message_event_create_with_default_clock_snapshot(); more about this below). To make a stream class support packets, you need to call bt_stream_class_set_supports_packets(). This is also where you specify whether or not the stream class's stream packets have a beginning and/or an end default clock snapshot from now on. You can use bt_stream_class_supports_packets() to know if a given stream class supports packets. The functions bt_message_event_create() and bt_message_event_create_with_default_clock_snapshot() are renamed to bt_message_event_create_with_packet() and bt_message_event_create_with_packet_and_default_clock_snapshot(). The functions bt_message_event_create() and bt_message_event_create_with_default_clock_snapshot() now accept a `const bt_stream *` parameter to associate the event to a stream. You can borrow the stream to which an event is associated with bt_event_borrow_stream_const(), however it was created. bt_event_borrow_packet_const() returns `NULL` if the event's stream class does not support packets. When a stream class supports packets, it is required that you emit the packet beginning and packet end messages at the correct locations within an iterator's message flow for a given instance of this stream class. When a stream class does not support packets, it is required that you do not create packet beginning and packet end messages for the instances of this stream class. Plugin changes ============== `src.ctf.fs` and `src.ctf.lttng-live`: The message iterators always create stream classes supporting packets. `sink.ctf.fs`: The component requires that packets are supported if a stream class also supports discarded events. This is because the way to indicate discarded events in CTF 1.8 is with packet contexts. When packets are not supported for a given stream, the component creates "artificial" packets. I chose to make it create packets of about 4 MiB. This could become configurable in the future. `flt.lttng-utils.debug-info`: The message iterator copies whether or not the stream class supports packets. `src.text.dmesg`: The message iterator does not emit packet beginning and end messages anymore. `sink.text.details`: The component prints whether or not a given stream class supports packets. The component only prints the "packets have beginning default clock snapshot" and "packets have end default clock snapshot" stream class properties if packets are supported to reduce textual noise. Signed-off-by: Philippe Proulx Change-Id: I79a8063b4a85140004789d024364cf37ef076c45 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1656 Reviewed-by: Simon Marchi Tested-by: jenkins --- include/babeltrace2/graph/message-event.h | 14 ++- .../babeltrace2/trace-ir/stream-class-const.h | 3 + include/babeltrace2/trace-ir/stream-class.h | 11 +- src/bindings/python/bt2/bt2/__init__.py.in | 1 + src/bindings/python/bt2/bt2/event.py | 5 +- src/bindings/python/bt2/bt2/message.py | 2 +- .../python/bt2/bt2/message_iterator.py | 26 +++-- src/bindings/python/bt2/bt2/stream.py | 3 + src/bindings/python/bt2/bt2/stream_class.py | 32 ++++-- src/bindings/python/bt2/bt2/trace_class.py | 20 +++- src/lib/graph/message/event.c | 43 ++++++-- src/lib/graph/message/packet.c | 6 ++ src/lib/lib-logging.c | 33 +++--- src/lib/trace-ir/event.c | 11 +- src/lib/trace-ir/event.h | 45 ++++++-- src/lib/trace-ir/packet-context-field.c | 3 + src/lib/trace-ir/packet.c | 3 + src/lib/trace-ir/stream-class.c | 102 +++++++++++------- src/lib/trace-ir/stream-class.h | 1 + .../ctf/common/metadata/ctf-meta-translate.c | 33 +++--- src/plugins/ctf/common/msg-iter/msg-iter.c | 4 +- src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h | 2 + src/plugins/ctf/fs-sink/fs-sink-stream.c | 7 +- src/plugins/ctf/fs-sink/fs-sink-stream.h | 5 +- src/plugins/ctf/fs-sink/fs-sink.c | 70 ++++++++++++ .../lttng-utils/debug-info/debug-info.c | 39 +++++-- .../debug-info/trace-ir-metadata-copy.c | 7 +- src/plugins/text/details/write.c | 16 ++- src/plugins/text/dmesg/dmesg.c | 65 ++--------- src/plugins/text/pretty/print.c | 5 +- src/plugins/utils/trimmer/trimmer.c | 1 - tests/bindings/python/bt2/test_clock_class.py | 18 +--- tests/bindings/python/bt2/test_event.py | 78 +++++++++----- tests/bindings/python/bt2/test_field.py | 3 +- tests/bindings/python/bt2/test_field_class.py | 5 +- tests/bindings/python/bt2/test_graph.py | 2 +- tests/bindings/python/bt2/test_message.py | 1 + .../python/bt2/test_message_iterator.py | 6 +- tests/bindings/python/bt2/test_packet.py | 3 +- .../bindings/python/bt2/test_stream_class.py | 80 +++++++++++--- .../bt_plugin_trimmer_test.py | 1 + .../sink.ctf.fs/succeed/trace-double.expect | 1 + .../sink.ctf.fs/succeed/trace-float.expect | 1 + .../src.ctf.fs/succeed/trace-simple.expect | 1 + .../succeed/trace-smalltrace.expect | 1 + tests/lib/test_trace_ir_ref.c | 33 ------ 46 files changed, 554 insertions(+), 298 deletions(-) diff --git a/include/babeltrace2/graph/message-event.h b/include/babeltrace2/graph/message-event.h index 13a2f57c..dea9a5ae 100644 --- a/include/babeltrace2/graph/message-event.h +++ b/include/babeltrace2/graph/message-event.h @@ -27,7 +27,7 @@ #include /* - * 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 @@ -38,12 +38,24 @@ extern "C" { 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); diff --git a/include/babeltrace2/trace-ir/stream-class-const.h b/include/babeltrace2/trace-ir/stream-class-const.h index 8687c985..ccc99a07 100644 --- a/include/babeltrace2/trace-ir/stream-class-const.h +++ b/include/babeltrace2/trace-ir/stream-class-const.h @@ -51,6 +51,9 @@ extern bt_bool bt_stream_class_assigns_automatic_event_class_id( 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); diff --git a/include/babeltrace2/trace-ir/stream-class.h b/include/babeltrace2/trace-ir/stream-class.h index c7cab857..bf3fced9 100644 --- a/include/babeltrace2/trace-ir/stream-class.h +++ b/include/babeltrace2/trace-ir/stream-class.h @@ -67,12 +67,6 @@ extern void bt_stream_class_set_assigns_automatic_event_class_id( 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, @@ -88,6 +82,11 @@ typedef enum bt_stream_class_set_field_class_status { 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, diff --git a/src/bindings/python/bt2/bt2/__init__.py.in b/src/bindings/python/bt2/bt2/__init__.py.in index b8639978..37c7e4be 100644 --- a/src/bindings/python/bt2/bt2/__init__.py.in +++ b/src/bindings/python/bt2/bt2/__init__.py.in @@ -47,6 +47,7 @@ from bt2.logging import * 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 diff --git a/src/bindings/python/bt2/bt2/event.py b/src/bindings/python/bt2/bt2/event.py index 4ff398b7..8864b1df 100644 --- a/src/bindings/python/bt2/bt2/event.py +++ b/src/bindings/python/bt2/bt2/event.py @@ -48,7 +48,10 @@ class _Event(object._UniqueObject): @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 diff --git a/src/bindings/python/bt2/bt2/message.py b/src/bindings/python/bt2/bt2/message.py index e4610191..a2e885b8 100644 --- a/src/bindings/python/bt2/bt2/message.py +++ b/src/bindings/python/bt2/bt2/message.py @@ -60,7 +60,7 @@ class _EventMessage(_Message, _MessageWithDefaultClockSnapshot): @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 diff --git a/src/bindings/python/bt2/bt2/message_iterator.py b/src/bindings/python/bt2/bt2/message_iterator.py index ebf0619c..eb22dfb4 100644 --- a/src/bindings/python/bt2/bt2/message_iterator.py +++ b/src/bindings/python/bt2/bt2/message_iterator.py @@ -165,23 +165,37 @@ class _UserMessageIterator(_MessageIterator): 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') diff --git a/src/bindings/python/bt2/bt2/stream.py b/src/bindings/python/bt2/bt2/stream.py index 5accfcd0..eb780b0e 100644 --- a/src/bindings/python/bt2/bt2/stream.py +++ b/src/bindings/python/bt2/bt2/stream.py @@ -52,6 +52,9 @@ class _Stream(bt2.object._SharedObject): 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: diff --git a/src/bindings/python/bt2/bt2/stream_class.py b/src/bindings/python/bt2/bt2/stream_class.py index c22e05a5..cf34cf4c 100644 --- a/src/bindings/python/bt2/bt2/stream_class.py +++ b/src/bindings/python/bt2/bt2/stream_class.py @@ -129,25 +129,30 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): _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): @@ -174,6 +179,9 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): 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') @@ -211,6 +219,10 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): 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, diff --git a/src/bindings/python/bt2/bt2/trace_class.py b/src/bindings/python/bt2/bt2/trace_class.py index 76becf56..9c825842 100644 --- a/src/bindings/python/bt2/bt2/trace_class.py +++ b/src/bindings/python/bt2/bt2/trace_class.py @@ -115,6 +115,7 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): 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, @@ -139,19 +140,28 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): 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, diff --git a/src/lib/graph/message/event.c b/src/lib/graph/message/event.c index 95b39605..5f3c90d4 100644 --- a/src/lib/graph/message/event.c +++ b/src/lib/graph/message/event.c @@ -82,7 +82,8 @@ static inline 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 = @@ -91,11 +92,12 @@ struct bt_message *create_event_message( 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); @@ -109,7 +111,7 @@ struct bt_message *create_event_message( "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: " @@ -152,7 +154,12 @@ struct bt_message *create_event_message( 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); @@ -167,21 +174,45 @@ end: } 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 diff --git a/src/lib/graph/message/packet.c b/src/lib/graph/message/packet.c index 63471f60..b00f2dfc 100644 --- a/src/lib/graph/message/packet.c +++ b/src/lib/graph/message/packet.c @@ -99,6 +99,12 @@ struct bt_message *create_packet_message( 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 { diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index b48c5db7..c9c8249b 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -518,14 +518,16 @@ static inline void format_stream_class(char **buf_ch, bool extended, } 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), @@ -674,8 +676,6 @@ static inline void format_packet(char **buf_ch, bool extended, 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]; @@ -718,22 +718,17 @@ static inline void format_event(char **buf_ch, bool extended, } } - 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, @@ -953,13 +948,13 @@ static inline void format_message(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); } diff --git a/src/lib/trace-ir/event.c b/src/lib/trace-ir/event.c index ffe3080e..15b40c8c 100644 --- a/src/lib/trace-ir/event.c +++ b/src/lib/trace-ir/event.c @@ -72,8 +72,11 @@ void _bt_event_set_is_frozen(const struct bt_event *event, bool is_frozen) } ((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 @@ -147,7 +150,7 @@ const struct bt_event_class *bt_event_borrow_class_const( 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( @@ -223,6 +226,8 @@ void bt_event_destroy(struct bt_event *event) 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); } diff --git a/src/lib/trace-ir/event.h b/src/lib/trace-ir/event.h index 002278ce..71318f95 100644 --- a/src/lib/trace-ir/event.h +++ b/src/lib/trace-ir/event.h @@ -56,9 +56,12 @@ struct bt_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; @@ -118,8 +121,13 @@ void bt_event_reset(struct bt_event *event) 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 @@ -170,7 +178,7 @@ void bt_event_set_packet(struct bt_event *event, struct bt_packet *packet) 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); @@ -178,13 +186,31 @@ void bt_event_set_packet(struct bt_event *event, struct bt_packet *packet) 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( @@ -198,8 +224,13 @@ struct bt_event *bt_event_create(struct bt_event_class *event_class, 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: diff --git a/src/lib/trace-ir/packet-context-field.c b/src/lib/trace-ir/packet-context-field.c index 388c20f3..9f648e24 100644 --- a/src/lib/trace-ir/packet-context-field.c +++ b/src/lib/trace-ir/packet-context-field.c @@ -63,6 +63,9 @@ struct bt_packet_context_field *bt_packet_context_field_create( 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); diff --git a/src/lib/trace-ir/packet.c b/src/lib/trace-ir/packet.c index cd81ca46..8f8625b6 100644 --- a/src/lib/trace-ir/packet.c +++ b/src/lib/trace-ir/packet.c @@ -222,6 +222,9 @@ struct bt_packet *bt_packet_create(const struct bt_stream *c_stream) 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( diff --git a/src/lib/trace-ir/stream-class.c b/src/lib/trace-ir/stream-class.c index fe0d8259..edeccbec 100644 --- a/src/lib/trace-ir/stream-class.c +++ b/src/lib/trace-ir/stream-class.c @@ -310,6 +310,9 @@ bt_stream_class_set_packet_context_field_class( }; 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) == @@ -457,46 +460,6 @@ void bt_stream_class_set_assigns_automatic_event_class_id( "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) { @@ -547,6 +510,10 @@ void bt_stream_class_set_supports_discarded_packets( { 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 " @@ -576,6 +543,61 @@ bt_bool bt_stream_class_discarded_packets_have_default_clock_snapshots( 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) diff --git a/src/lib/trace-ir/stream-class.h b/src/lib/trace-ir/stream-class.h index 7610b902..fe423d76 100644 --- a/src/lib/trace-ir/stream-class.h +++ b/src/lib/trace-ir/stream-class.h @@ -49,6 +49,7 @@ struct bt_stream_class { 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; diff --git a/src/plugins/ctf/common/metadata/ctf-meta-translate.c b/src/plugins/ctf/common/metadata/ctf-meta-translate.c index c9a72030..af788824 100644 --- a/src/plugins/ctf/common/metadata/ctf-meta-translate.c +++ b/src/plugins/ctf/common/metadata/ctf-meta-translate.c @@ -455,6 +455,22 @@ void ctf_stream_class_to_ir(struct ctx *ctx) 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) { @@ -477,23 +493,6 @@ void ctf_stream_class_to_ir(struct ctx *ctx) 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; diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.c b/src/plugins/ctf/common/msg-iter/msg-iter.c index d71d00e9..27d51779 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.c +++ b/src/plugins/ctf/common/msg-iter/msg-iter.c @@ -1197,11 +1197,11 @@ enum bt_msg_iter_status set_current_event_message( 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); } diff --git a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h index 0d26a32e..72d47d4a 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h +++ b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h @@ -133,6 +133,7 @@ struct fs_sink_ctf_stream_class { 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; @@ -739,6 +740,7 @@ struct fs_sink_ctf_stream_class *fs_sink_ctf_stream_class_create( 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); diff --git a/src/plugins/ctf/fs-sink/fs-sink-stream.c b/src/plugins/ctf/fs-sink/fs-sink-stream.c index a6f39a37..4ca9ce10 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-stream.c +++ b/src/plugins/ctf/fs-sink/fs-sink-stream.c @@ -517,10 +517,11 @@ int write_packet_context(struct fs_sink_stream *stream) /* 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, diff --git a/src/plugins/ctf/fs-sink/fs-sink-stream.h b/src/plugins/ctf/fs-sink/fs-sink-stream.h index e3d7ba5e..205cac03 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-stream.h +++ b/src/plugins/ctf/fs-sink/fs-sink-stream.h @@ -95,7 +95,10 @@ struct fs_sink_stream { */ 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; diff --git a/src/plugins/ctf/fs-sink/fs-sink.c b/src/plugins/ctf/fs-sink/fs-sink.c index 3a08c71e..239e7ad1 100644 --- a/src/plugins/ctf/fs-sink/fs-sink.c +++ b/src/plugins/ctf/fs-sink/fs-sink.c @@ -313,6 +313,42 @@ bt_component_class_sink_consume_method_status handle_event_msg( 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; @@ -616,6 +652,29 @@ bt_component_class_sink_consume_method_status handle_stream_beginning_msg( 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. @@ -688,6 +747,17 @@ bt_component_class_sink_consume_method_status handle_stream_end_msg( 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\"", diff --git a/src/plugins/lttng-utils/debug-info/debug-info.c b/src/plugins/lttng-utils/debug-info/debug-info.c index c994b264..75e1a6fe 100644 --- a/src/plugins/lttng-utils/debug-info/debug-info.c +++ b/src/plugins/lttng-utils/debug-info/debug-info.c @@ -1261,8 +1261,10 @@ bt_message *handle_event_message(struct debug_info_msg_iter *debug_it, 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; @@ -1285,10 +1287,19 @@ bt_message *handle_event_message(struct debug_info_msg_iter *debug_it, } 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)); @@ -1298,13 +1309,29 @@ bt_message *handle_event_message(struct debug_info_msg_iter *debug_it, 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) { diff --git a/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c b/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c index ce76cce5..60ef68bc 100644 --- a/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c +++ b/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c @@ -204,12 +204,11 @@ int copy_stream_class_content(struct trace_ir_maps *ir_maps, } - 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( diff --git a/src/plugins/text/details/write.c b/src/plugins/text/details/write.c index 0ccad622..1606599c 100644 --- a/src/plugins/text/details/write.c +++ b/src/plugins/text/details/write.c @@ -1025,11 +1025,17 @@ void write_stream_class(struct details_write_ctx *ctx, /* 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)); diff --git a/src/plugins/text/dmesg/dmesg.c b/src/plugins/text/dmesg/dmesg.c index f08f83d2..7243bbb5 100644 --- a/src/plugins/text/dmesg/dmesg.c +++ b/src/plugins/text/dmesg/dmesg.c @@ -55,9 +55,7 @@ struct dmesg_msg_iter { enum { STATE_EMIT_STREAM_BEGINNING, - STATE_EMIT_PACKET_BEGINNING, STATE_EMIT_EVENT, - STATE_EMIT_PACKET_END, STATE_EMIT_STREAM_END, STATE_DONE, } state; @@ -79,7 +77,6 @@ struct dmesg_component { bt_event_class *event_class; bt_trace *trace; bt_stream *stream; - bt_packet *packet; bt_clock_class *clock_class; }; @@ -161,11 +158,6 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) 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( @@ -258,7 +250,7 @@ end: } 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; @@ -298,12 +290,6 @@ int create_packet_and_stream_and_trace(struct dmesg_component *dmesg_comp) 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: @@ -318,8 +304,7 @@ end: } 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; @@ -335,9 +320,9 @@ int try_create_meta_stream_packet(struct dmesg_component *dmesg_comp, 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; } @@ -362,7 +347,6 @@ void destroy_dmesg_component(struct dmesg_component *dmesg_comp) 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); @@ -539,22 +523,22 @@ skip_ts: /* * 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) { @@ -747,7 +731,6 @@ bt_component_class_message_iterator_next_method_status dmesg_msg_iter_next_one( } 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; } @@ -769,9 +752,9 @@ bt_component_class_message_iterator_next_method_status dmesg_msg_iter_next_one( 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; } } @@ -811,20 +794,6 @@ 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: @@ -832,18 +801,6 @@ handle_state: *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); diff --git a/src/plugins/text/pretty/print.c b/src/plugins/text/pretty/print.c index 9645827e..cdb15e23 100644 --- a/src/plugins/text/pretty/print.c +++ b/src/plugins/text/pretty/print.c @@ -296,7 +296,6 @@ int print_event_header(struct pretty_component *pretty, 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); @@ -305,8 +304,7 @@ int print_event_header(struct pretty_component *pretty, 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) { @@ -1038,7 +1036,6 @@ int print_stream_packet_context(struct pretty_component *pretty, packet = bt_event_borrow_packet_const(event); if (!packet) { - ret = -1; goto end; } main_field = bt_packet_borrow_context_field_const(packet); diff --git a/src/plugins/utils/trimmer/trimmer.c b/src/plugins/utils/trimmer/trimmer.c index 763c8986..c1c0f692 100644 --- a/src/plugins/utils/trimmer/trimmer.c +++ b/src/plugins/utils/trimmer/trimmer.c @@ -1349,7 +1349,6 @@ handle_message_with_stream( * 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)) { diff --git a/tests/bindings/python/bt2/test_clock_class.py b/tests/bindings/python/bt2/test_clock_class.py index 1f395912..53487c65 100644 --- a/tests/bindings/python/bt2/test_clock_class.py +++ b/tests/bindings/python/bt2/test_clock_class.py @@ -207,13 +207,9 @@ class ClockSnapshotTestCase(unittest.TestCase): _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 @@ -226,14 +222,10 @@ class ClockSnapshotTestCase(unittest.TestCase): 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 @@ -251,9 +243,9 @@ class ClockSnapshotTestCase(unittest.TestCase): 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 diff --git a/tests/bindings/python/bt2/test_event.py b/tests/bindings/python/bt2/test_event.py index a2727130..eedc9688 100644 --- a/tests/bindings/python/bt2/test_event.py +++ b/tests/bindings/python/bt2/test_event.py @@ -26,31 +26,45 @@ class EventTestCase(unittest.TestCase): 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 @@ -73,15 +87,19 @@ class EventTestCase(unittest.TestCase): )) # 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 @@ -108,12 +126,17 @@ class EventTestCase(unittest.TestCase): 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 @@ -122,8 +145,8 @@ class EventTestCase(unittest.TestCase): 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): @@ -211,7 +234,8 @@ class EventTestCase(unittest.TestCase): 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 diff --git a/tests/bindings/python/bt2/test_field.py b/tests/bindings/python/bt2/test_field.py index ed3661eb..db640445 100644 --- a/tests/bindings/python/bt2/test_field.py +++ b/tests/bindings/python/bt2/test_field.py @@ -44,7 +44,8 @@ def _create_stream(tc, ctx_field_classes): 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 diff --git a/tests/bindings/python/bt2/test_field_class.py b/tests/bindings/python/bt2/test_field_class.py index 012545af..bb73da48 100644 --- a/tests/bindings/python/bt2/test_field_class.py +++ b/tests/bindings/python/bt2/test_field_class.py @@ -451,7 +451,7 @@ class VariantFieldClassTestCase(_TestFieldContainer, unittest.TestCase): # 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 @@ -545,7 +545,8 @@ class DynamicArrayFieldClassTestCase(unittest.TestCase): # 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 diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index 073db5d7..852e3f01 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -31,7 +31,7 @@ class _MyIter(bt2._UserMessageIterator): 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() diff --git a/tests/bindings/python/bt2/test_message.py b/tests/bindings/python/bt2/test_message.py index c98edea7..6e1999de 100644 --- a/tests/bindings/python/bt2/test_message.py +++ b/tests/bindings/python/bt2/test_message.py @@ -88,6 +88,7 @@ class AllMessagesTestCase(unittest.TestCase): 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, diff --git a/tests/bindings/python/bt2/test_message_iterator.py b/tests/bindings/python/bt2/test_message_iterator.py index a716ce01..bd0a52ee 100644 --- a/tests/bindings/python/bt2/test_message_iterator.py +++ b/tests/bindings/python/bt2/test_message_iterator.py @@ -145,7 +145,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): 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)) @@ -205,7 +205,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): 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)) @@ -339,7 +339,7 @@ class OutputPortMessageIteratorTestCase(unittest.TestCase): 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) diff --git a/tests/bindings/python/bt2/test_packet.py b/tests/bindings/python/bt2/test_packet.py index ff763dfc..2945f49b 100644 --- a/tests/bindings/python/bt2/test_packet.py +++ b/tests/bindings/python/bt2/test_packet.py @@ -52,7 +52,8 @@ class PacketTestCase(unittest.TestCase): # 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() diff --git a/tests/bindings/python/bt2/test_stream_class.py b/tests/bindings/python/bt2/test_stream_class.py index 56dcf920..55cdb310 100644 --- a/tests/bindings/python/bt2/test_stream_class.py +++ b/tests/bindings/python/bt2/test_stream_class.py @@ -40,6 +40,7 @@ class StreamClassTestCase(unittest.TestCase): 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) @@ -57,13 +58,20 @@ class StreamClassTestCase(unittest.TestCase): 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) @@ -137,21 +145,53 @@ class StreamClassTestCase(unittest.TestCase): 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, @@ -183,31 +223,41 @@ class StreamClassTestCase(unittest.TestCase): 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() diff --git a/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py b/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py index 140dd54c..e1db25ed 100644 --- a/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py +++ b/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py @@ -55,6 +55,7 @@ class TheSourceOfAllEvil(bt2._UserSourceComponent, # 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') diff --git a/tests/data/plugins/sink.ctf.fs/succeed/trace-double.expect b/tests/data/plugins/sink.ctf.fs/succeed/trace-double.expect index 41384961..57f0dc83 100644 --- a/tests/data/plugins/sink.ctf.fs/succeed/trace-double.expect +++ b/tests/data/plugins/sink.ctf.fs/succeed/trace-double.expect @@ -1,5 +1,6 @@ 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 diff --git a/tests/data/plugins/sink.ctf.fs/succeed/trace-float.expect b/tests/data/plugins/sink.ctf.fs/succeed/trace-float.expect index 17c915db..a0780df3 100644 --- a/tests/data/plugins/sink.ctf.fs/succeed/trace-float.expect +++ b/tests/data/plugins/sink.ctf.fs/succeed/trace-float.expect @@ -1,5 +1,6 @@ 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 diff --git a/tests/data/plugins/src.ctf.fs/succeed/trace-simple.expect b/tests/data/plugins/src.ctf.fs/succeed/trace-simple.expect index 6f62034b..05cf63db 100644 --- a/tests/data/plugins/src.ctf.fs/succeed/trace-simple.expect +++ b/tests/data/plugins/src.ctf.fs/succeed/trace-simple.expect @@ -1,5 +1,6 @@ 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 diff --git a/tests/data/plugins/src.ctf.fs/succeed/trace-smalltrace.expect b/tests/data/plugins/src.ctf.fs/succeed/trace-smalltrace.expect index 39a740f6..e5c47e7f 100644 --- a/tests/data/plugins/src.ctf.fs/succeed/trace-smalltrace.expect +++ b/tests/data/plugins/src.ctf.fs/succeed/trace-smalltrace.expect @@ -1,5 +1,6 @@ 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 diff --git a/tests/lib/test_trace_ir_ref.c b/tests/lib/test_trace_ir_ref.c index 5051fa6d..90cff9cd 100644 --- a/tests/lib/test_trace_ir_ref.c +++ b/tests/lib/test_trace_ir_ref.c @@ -197,37 +197,6 @@ static bt_event_class *create_complex_event(bt_stream_class *sc, 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; @@ -238,7 +207,6 @@ static void create_sc1(bt_trace_class *trace_class) 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"); @@ -262,7 +230,6 @@ static void create_sc2(bt_trace_class *trace_class) 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"); -- 2.34.1