lib: make packets and packet messages optional, disabled by default
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 8 Jul 2019 16:33:30 +0000 (12:33 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 9 Jul 2019 17:20:05 +0000 (13:20 -0400)
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 <eeppeliteloop@gmail.com>
Change-Id: I79a8063b4a85140004789d024364cf37ef076c45
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1656
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
46 files changed:
include/babeltrace2/graph/message-event.h
include/babeltrace2/trace-ir/stream-class-const.h
include/babeltrace2/trace-ir/stream-class.h
src/bindings/python/bt2/bt2/__init__.py.in
src/bindings/python/bt2/bt2/event.py
src/bindings/python/bt2/bt2/message.py
src/bindings/python/bt2/bt2/message_iterator.py
src/bindings/python/bt2/bt2/stream.py
src/bindings/python/bt2/bt2/stream_class.py
src/bindings/python/bt2/bt2/trace_class.py
src/lib/graph/message/event.c
src/lib/graph/message/packet.c
src/lib/lib-logging.c
src/lib/trace-ir/event.c
src/lib/trace-ir/event.h
src/lib/trace-ir/packet-context-field.c
src/lib/trace-ir/packet.c
src/lib/trace-ir/stream-class.c
src/lib/trace-ir/stream-class.h
src/plugins/ctf/common/metadata/ctf-meta-translate.c
src/plugins/ctf/common/msg-iter/msg-iter.c
src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h
src/plugins/ctf/fs-sink/fs-sink-stream.c
src/plugins/ctf/fs-sink/fs-sink-stream.h
src/plugins/ctf/fs-sink/fs-sink.c
src/plugins/lttng-utils/debug-info/debug-info.c
src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c
src/plugins/text/details/write.c
src/plugins/text/dmesg/dmesg.c
src/plugins/text/pretty/print.c
src/plugins/utils/trimmer/trimmer.c
tests/bindings/python/bt2/test_clock_class.py
tests/bindings/python/bt2/test_event.py
tests/bindings/python/bt2/test_field.py
tests/bindings/python/bt2/test_field_class.py
tests/bindings/python/bt2/test_graph.py
tests/bindings/python/bt2/test_message.py
tests/bindings/python/bt2/test_message_iterator.py
tests/bindings/python/bt2/test_packet.py
tests/bindings/python/bt2/test_stream_class.py
tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py
tests/data/plugins/sink.ctf.fs/succeed/trace-double.expect
tests/data/plugins/sink.ctf.fs/succeed/trace-float.expect
tests/data/plugins/src.ctf.fs/succeed/trace-simple.expect
tests/data/plugins/src.ctf.fs/succeed/trace-smalltrace.expect
tests/lib/test_trace_ir_ref.c

index 13a2f57cc1b0ac50d2aa10d53bb96f9d24b0a6e9..dea9a5ae6590b93ead048a7c57b95d24dbd069c0 100644 (file)
@@ -27,7 +27,7 @@
 #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>
@@ -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);
index 8687c9852273a61dae66e49dd93edfa8a8a264fa..ccc99a078cd2d15cc525c19628073d5abb86b745 100644 (file)
@@ -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);
 
index c7cab857b20b6f83b6043fe6a793333fddf2952a..bf3fced913efabc627a5d6873885d2cffdfa55d4 100644 (file)
@@ -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,
index b8639978ccd0b69cdf5a3c78d54dd0846ce2b7da..37c7e4bee1119cc2468c891a1e214ce92a0770a6 100644 (file)
@@ -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
index 4ff398b7565d291154c82c58b4d06ff71a1c0732..8864b1dfda33c5a5c21acf3968e3f8d5d7c2e0dc 100644 (file)
@@ -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
index e461019141e7a241a1a7dcf4674c017cb56c266e..a2e885b8208bdd8dfc994d5359bbe7bc5f83cf07 100644 (file)
@@ -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
index ebf0619c4d79aa0db0e348533f1f2b109cc533e1..eb22dfb4edec32c4afd14612d744cb618248319d 100644 (file)
@@ -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')
index 5accfcd0751cfdf271121587b1b6b0d8c73a1ab1..eb780b0ee6ab02c9d0c78ff6502f0037a9593597 100644 (file)
@@ -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:
index c22e05a584c6cec260da0fda4634fc039e50ad59..cf34cf4c05f285808619724aed60f2d43f89394d 100644 (file)
@@ -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,
index 76becf56c7effffefee7c08a49c359b4889a3977..9c8258429c55e2066c3ee5aa1a1fe918ee8f5228 100644 (file)
@@ -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,
index 95b39605ca30bb74880815da5e0a7a20fbb8ed29..5f3c90d4912a83bb6a9d67e8e0f6d77e211afcd0 100644 (file)
@@ -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
index 63471f6040c1e17fc62c634db45048fa1ced2d69..b00f2dfc0b7026c540affb5787f21d7c79377387 100644 (file)
@@ -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 {
index b48c5db7b4274de39f04905cbad53bf2e9452aa1..c9c8249b39af6ed07d5f7321495e6c56e6f98e8c 100644 (file)
@@ -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);
                }
index ffe3080e315e12552b4af0f23b765f1750079b56..15b40c8c3fb27d4e1ea4a52fc8c6589dfc8c2895 100644 (file)
@@ -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);
 }
 
index 002278ce88e1bb090e2e3e01ae6d23f9166f7b18..71318f95b626b3b8e11b8db83f3e603d2f00d9f9 100644 (file)
@@ -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:
index 388c20f307cc83ec01c19c0f224c9f2ada610792..9f648e24a221404caa37ed9dc70b745063841a70 100644 (file)
@@ -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);
index cd81ca46aeeb9b0bda7ce840062bf17eb8a707bd..8f8625b6123b7f7b9ea8b2f46b62dd4200f80126 100644 (file)
@@ -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(
index fe0d8259125d438351751237301c6ebe7546ae48..edeccbecc730391c62857f6c371839da5c9bccbb 100644 (file)
@@ -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)
index 7610b9029a0b1bfd422368705b5d2afea53d1d65..fe423d7683d99e66855f5fd5503e4c1e1e1651ee 100644 (file)
@@ -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;
index c9a720309cf64e51ef9218bd3c09ef87deb9a247..af788824754c92fc968db9f34072e4793933f5a2 100644 (file)
@@ -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;
 
index d71d00e9b23a88d6dac33ea4e9603115e248096d..27d51779251e049a5c90d3f27035d5ff97f9df80 100644 (file)
@@ -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);
        }
 
index 0d26a32e0efe5efbbc7af5123da59880102b26ce..72d47d4aaf53313925039d66b85546f048e9603f 100644 (file)
@@ -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);
index a6f39a376b53a76a13ed84381fd3687da966e715..4ca9ce1059bd5545fd2481d5a7dbf35dadafcdc7 100644 (file)
@@ -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,
index e3d7ba5eb1f02a86dbc8399f95ee24710e3d9a5b..205cac03f494ae1e1a36c2a3b19be700a4a16f62 100644 (file)
@@ -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;
 
index 3a08c71e56b19939fadd491d65618bf0b84c731a..239e7ad10ed3ffc087ade96dd152218b35a9269e 100644 (file)
@@ -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\"",
index c994b264d009fb81b4795dd62c87c4d7103b88f4..75e1a6fe2b0381ebd5fb8c6903482ff9c58d6da4 100644 (file)
@@ -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) {
index ce76cce52d5262df463b9368a4d7e8ba363118ab..60ef68bcee2395b3f076805179b684681020e65d 100644 (file)
@@ -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(
index 0ccad6226de0e93b195f086c5891a095f821a28c..1606599c28fec3a9c751fadf1de30d01b120df16 100644 (file)
@@ -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));
index f08f83d27c9b85a0c8c0a63d0f8398deaebbbdcc..7243bbb5d777dfdb28c416118f0b9a37ae6df297 100644 (file)
@@ -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);
index 9645827e15bd6b7d912e5bcdb98d57cae52db3ae..cdb15e231387e5e1eb77c07f0b47a5fb7a061521 100644 (file)
@@ -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);
index 763c898660d3ff3263528ef7f89403c29a8a083a..c1c0f6921458cf963f814e41a80f31c4f9e94284 100644 (file)
@@ -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)) {
index 1f3959127208b274f23b0a3615ee05ac9f436631..53487c655370a9695064eba568894489f33832ac 100644 (file)
@@ -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
 
index a2727130a82c36ad7f83b41f52febd9cb4e1fce9..eedc9688b306ae7ec799866dc83b28c6a483495d 100644 (file)
@@ -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
index ed3661ebbc13004b481bd94ad6d039f4b66b1e1d..db6404455cfc26609384341e35828b1fe031bbb5 100644 (file)
@@ -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
index 012545af11411b3353c7033558eaaaf7ab957768..bb73da48c03c41646faacdca9daa3f1ea4a1e766 100644 (file)
@@ -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
 
index 073db5d7fd3959262c7a4a099422fc87386b98ff..852e3f01ce23e24c55f57fe15f64234fe9a6fa8d 100644 (file)
@@ -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()
index c98edea77848edf513afc22627a74aed5c8d9284..6e1999de47e501437e34a28ab2cdff7331dcc074 100644 (file)
@@ -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,
index a716ce0195da83b262af2a2c00488181336328f6..bd0a52eefc9860d3cbd9fbbf2d335a0006c4b953 100644 (file)
@@ -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)
index ff763dfc182c36726af80563838970a7e988f601..2945f49b56f2e300f7e8ebb51a27198d2ee5d197 100644 (file)
@@ -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()
index 56dcf9203e1a120ecef6902b7fd321585ed44bdd..55cdb3109304a0158a1121e31f4aedae14d8bbbe 100644 (file)
@@ -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()
index 140dd54c50752c411e0cfc2a500790b9b38abf81..e1db25edb3239686795557e2c8886f455b3533f0 100644 (file)
@@ -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')
index 41384961561a421d5269294f77aaf39fc7cdeb67..57f0dc830923bfb3a4922873175fbaa062d5cff7 100644 (file)
@@ -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
index 17c915db6d0521fb33ba0f8855b32a53e3b115af..a0780df3b759909b4c0b06795a81e8dcdeb7d69c 100644 (file)
@@ -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
index 6f62034b632f035986feb8d34386ff11e0b43570..05cf63db6875429133ab80b2ba3916c7a5834f89 100644 (file)
@@ -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
index 39a740f6832a503edb0acdef44a055840bac8d85..e5c47e7fded9c51584e0ba6d0fd24d68cb5a53b3 100644 (file)
@@ -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
index 5051fa6d1d00aa9550ef3f7f7a6ee669816d3019..90cff9cddbeae57737a6bfcd2374e28b0d951638 100644 (file)
@@ -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");
This page took 0.056122 seconds and 4 git commands to generate.