ctf: notif-iter: pass current stream ID to get_stream() medop
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 5 Jul 2017 16:14:47 +0000 (12:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 6 Jul 2017 21:23:19 +0000 (17:23 -0400)
Make the notif iter's get_stream() medop receive the current stream
(instance) ID as a parameter, if any, so that the callee can create a
stream with bt_ctf_stream_create_with_id(), if this is needed, with the
appropriate stream ID which is only known dynamically after decoding the
first packet header.

In the case of src.ctf.fs, the streams are already created with the
appropriate stream IDs because the component deals with data stream file
groups and must mark the trace as static at creation time, so the new
parameter is ignored. In the case of src.ctf.lttng-live, we cannot read
the first packet header and then rewind (or it is rather complicated to
do so), so the stream object is created the first time get_stream() is
called with the received ID.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/ctf/common/notif-iter/notif-iter.c
plugins/ctf/common/notif-iter/notif-iter.h
plugins/ctf/fs-src/data-stream-file.c
plugins/ctf/lttng-live/data-stream.c

index e6b85753b48e7d1c56cba8cd4c4009013de7d656..b8af7e15a13dfe603f4599b104cbedbee8a52f13 100644 (file)
@@ -2667,6 +2667,35 @@ end:
        return event;
 }
 
+static
+uint64_t get_cur_stream_instance_id(struct bt_ctf_notif_iter *notit)
+{
+       struct bt_ctf_field *stream_instance_id_field = NULL;
+       uint64_t stream_instance_id = -1ULL;
+       int ret;
+
+       if (!notit->dscopes.trace_packet_header) {
+               goto end;
+       }
+
+       stream_instance_id_field = bt_ctf_field_structure_get_field_by_name(
+               notit->dscopes.trace_packet_header, "stream_instance_id");
+       if (!stream_instance_id_field) {
+               goto end;
+       }
+
+       ret = bt_ctf_field_unsigned_integer_get_value(stream_instance_id_field,
+               &stream_instance_id);
+       if (ret) {
+               stream_instance_id = -1ULL;
+               goto end;
+       }
+
+end:
+       bt_put(stream_instance_id_field);
+       return stream_instance_id;
+}
+
 static
 int set_stream(struct bt_ctf_notif_iter *notit)
 {
@@ -2680,7 +2709,8 @@ int set_stream(struct bt_ctf_notif_iter *notit)
                bt_ctf_stream_class_get_name(notit->meta.stream_class),
                bt_ctf_stream_class_get_id(notit->meta.stream_class));
        stream = bt_get(notit->medium.medops.get_stream(
-               notit->meta.stream_class, notit->medium.data));
+               notit->meta.stream_class, get_cur_stream_instance_id(notit),
+               notit->medium.data));
        BT_LOGV("User function returned: stream-addr=%p", stream);
        if (!stream) {
                BT_LOGW_STR("User function failed to return a stream object for the given stream class.");
index 428dd2eca2332644fdd5c7224d60b58db711761a..c14146e3e297d794d3d62ee5a3738d90468feafa 100644 (file)
@@ -189,13 +189,16 @@ struct bt_ctf_notif_iter_medium_ops {
         * corresponding stream class is found by the notification
         * iterator.
         *
-        * @param stream_class  Stream class associated to the stream
+        * @param stream_class  Stream class of the stream to get
+        * @param stream_id     Stream (instance) ID of the stream
+        *                      to get (-1ULL if not available)
         * @param data          User data
         * @returns             Stream instance (weak reference) or
         *                      \c NULL on error
         */
        struct bt_ctf_stream * (* get_stream)(
-                       struct bt_ctf_stream_class *stream_class, void *data);
+                       struct bt_ctf_stream_class *stream_class,
+                       uint64_t stream_id, void *data);
 };
 
 /** CTF notification iterator. */
@@ -240,7 +243,6 @@ struct bt_ctf_notif_iter_notif_event {
  *                             at a time
  * @param medops               Medium operations
  * @param medops_data          User data (passed to medium operations)
- * @param err_stream           Error stream (can be \c NULL to disable)
  * @returns                    New CTF notification iterator on
  *                             success, or \c NULL on error
  */
index 0ca01a61606f67c5d831c7568bc42bc2dbf58916..76b58da90d5aa527827b90b366d47cc4f3934bcd 100644 (file)
@@ -176,7 +176,8 @@ end:
 
 static
 struct bt_ctf_stream *medop_get_stream(
-               struct bt_ctf_stream_class *stream_class, void *data)
+               struct bt_ctf_stream_class *stream_class, uint64_t stream_id,
+               void *data)
 {
        struct ctf_fs_ds_file *ds_file = data;
        struct bt_ctf_stream_class *ds_file_stream_class;
index d70891089be92776486957f3b3ebb3ccda72c254..f6832cab967443e71b5a15e5cdbb1364b936760d 100644 (file)
@@ -73,20 +73,32 @@ enum bt_ctf_notif_iter_medium_status medop_request_bytes(
 
 static
 struct bt_ctf_stream *medop_get_stream(
-               struct bt_ctf_stream_class *stream_class, void *data)
+               struct bt_ctf_stream_class *stream_class,
+               uint64_t stream_id, void *data)
 {
        struct lttng_live_stream_iterator *lttng_live_stream = data;
 
        if (!lttng_live_stream->stream) {
-               int64_t id = bt_ctf_stream_class_get_id(stream_class);
+               int64_t stream_class_id =
+                       bt_ctf_stream_class_get_id(stream_class);
+
+               BT_LOGD("Creating stream %s (ID: %" PRIu64 ") out of stream class %" PRId64,
+                       lttng_live_stream->name, stream_id, stream_class_id);
+
+               if (stream_id == -1ULL) {
+                       /* No stream ID */
+                       lttng_live_stream->stream = bt_ctf_stream_create(
+                               stream_class, lttng_live_stream->name);
+               } else {
+                       lttng_live_stream->stream =
+                               bt_ctf_stream_create_with_id(stream_class,
+                                       lttng_live_stream->name, stream_id);
+               }
 
-               BT_LOGD("Creating stream %s out of stream class %" PRId64,
-                       lttng_live_stream->name, id);
-               lttng_live_stream->stream = bt_ctf_stream_create(stream_class,
-                               lttng_live_stream->name);
                if (!lttng_live_stream->stream) {
-                       BT_LOGE("Cannot create stream %s (stream class %" PRId64 ")",
-                                       lttng_live_stream->name, id);
+                       BT_LOGE("Cannot create stream %s (stream class %" PRId64 ", stream ID %" PRIu64 ")",
+                                       lttng_live_stream->name,
+                                       stream_class_id, stream_id);
                }
        }
 
This page took 0.027499 seconds and 4 git commands to generate.