Event notification: pass CC priority map on creation
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 31 Mar 2017 05:12:08 +0000 (01:12 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:39 +0000 (12:57 -0400)
An event notification must have an associated clock class priority map
to indicate the ranks of its event's clock values.

As of this patch, a ctf.fs source component always set the priority of
all the parsed clock classes to 0.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/graph/notification-event-internal.h
include/babeltrace/graph/notification-event.h
lib/component/notification/event.c
plugins/ctf/common/notif-iter/notif-iter.c
plugins/ctf/common/notif-iter/notif-iter.h
plugins/ctf/fs/data-stream.c
plugins/ctf/fs/fs.c
plugins/ctf/fs/fs.h

index 939b77111f610641080704546f2f67a21079fe72..8fffd47ee9b7c1af57b4d42f7439d212a3870d4e 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <babeltrace/ctf-ir/event.h>
 #include <babeltrace/graph/notification-internal.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -37,6 +38,7 @@ extern "C" {
 struct bt_notification_event {
        struct bt_notification parent;
        struct bt_ctf_event *event;
+       struct bt_clock_class_priority_map *cc_prio_map;
 };
 
 #ifdef __cplusplus
index e5947b7ed09b4c8fd04b0016b938c0525696f9e0..f386abb2845c3c13933408453d29df7043037da5 100644 (file)
@@ -33,6 +33,7 @@ extern "C" {
 
 struct bt_notification;
 struct bt_ctf_event;
+struct bt_clock_class_priority_map;
 
 /***BT_NOTIFICATION_TYPE_EVENT ***/
 /**
@@ -44,7 +45,8 @@ struct bt_ctf_event;
  * @see #bt_notification_type
  */
 extern struct bt_notification *bt_notification_event_create(
-               struct bt_ctf_event *event);
+               struct bt_ctf_event *event,
+               struct bt_clock_class_priority_map *clock_class_priority_map);
 
 /**
  * Get an event notification's event.
@@ -57,6 +59,10 @@ extern struct bt_notification *bt_notification_event_create(
 extern struct bt_ctf_event *bt_notification_event_get_event(
                struct bt_notification *notification);
 
+extern struct bt_clock_class_priority_map *
+bt_notification_event_get_clock_class_priority_map(
+               struct bt_notification *notification);
+
 #ifdef __cplusplus
 }
 #endif
index faf9635273f27c3cb349edf4f45e1677908dd3b5..c3c461a1e86fafc9da1f057223b86e9cd1d1333b 100644 (file)
  */
 
 #include <babeltrace/compiler.h>
+#include <babeltrace/ctf-ir/event.h>
+#include <babeltrace/ctf-ir/event-class.h>
+#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace/ctf-ir/trace.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
 #include <babeltrace/graph/notification-event-internal.h>
 
 static
@@ -34,14 +39,64 @@ void bt_notification_event_destroy(struct bt_object *obj)
                        (struct bt_notification_event *) obj;
 
        BT_PUT(notification->event);
+       BT_PUT(notification->cc_prio_map);
        g_free(notification);
 }
 
-struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event)
+static
+bool validate_clock_classes(struct bt_notification_event *notif)
+{
+       /*
+        * For each clock class found in the event's trace, get the
+        * event's clock value for this clock class, and if it exists,
+        * make sure that this clock class has a priority in the
+        * notification's clock class priority map.
+        */
+       bool is_valid = true;
+       int ret;
+       int count;
+       size_t i;
+       struct bt_ctf_event_class *event_class = NULL;
+       struct bt_ctf_stream_class *stream_class = NULL;
+       struct bt_ctf_trace *trace = NULL;
+       uint64_t prio;
+
+       event_class = bt_ctf_event_get_class(notif->event);
+       assert(event_class);
+       stream_class = bt_ctf_event_class_get_stream_class(event_class);
+       assert(stream_class);
+       trace = bt_ctf_stream_class_get_trace(stream_class);
+       assert(trace);
+       count = bt_ctf_trace_get_clock_class_count(trace);
+       assert(count >= 0);
+
+       for (i = 0; i < count; i++) {
+               struct bt_ctf_clock_class *clock_class =
+                       bt_ctf_trace_get_clock_class(trace, i);
+
+               assert(clock_class);
+               ret = bt_clock_class_priority_map_get_clock_class_priority(
+                       notif->cc_prio_map, clock_class, &prio);
+               bt_put(clock_class);
+               if (ret) {
+                       is_valid = false;
+                       goto end;
+               }
+       }
+
+end:
+       bt_put(trace);
+       bt_put(stream_class);
+       bt_put(event_class);
+       return is_valid;
+}
+
+struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event,
+               struct bt_clock_class_priority_map *cc_prio_map)
 {
        struct bt_notification_event *notification;
 
-       if (!event) {
+       if (!event || !cc_prio_map) {
                goto error;
        }
 
@@ -55,6 +110,13 @@ struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event)
                        BT_NOTIFICATION_TYPE_EVENT,
                        bt_notification_event_destroy);
        notification->event = bt_get(event);
+       notification->cc_prio_map = bt_get(cc_prio_map);
+
+       if (!validate_clock_classes(notification)) {
+               bt_put(notification);
+               goto error;
+       }
+
        return &notification->parent;
 error:
        return NULL;
@@ -76,3 +138,22 @@ struct bt_ctf_event *bt_notification_event_get_event(
 end:
        return event;
 }
+
+extern struct bt_clock_class_priority_map *
+bt_notification_event_get_clock_class_priority_map(
+               struct bt_notification *notification)
+{
+       struct bt_clock_class_priority_map *cc_prio_map = NULL;
+       struct bt_notification_event *event_notification;
+
+       if (bt_notification_get_type(notification) !=
+                       BT_NOTIFICATION_TYPE_EVENT) {
+               goto end;
+       }
+
+       event_notification = container_of(notification,
+                       struct bt_notification_event, parent);
+       cc_prio_map = bt_get(event_notification->cc_prio_map);
+end:
+       return cc_prio_map;
+}
index d82c9b85a6fe8bb7ad7d7d8d6f8d9d2cefdd915d..319575df8ff73759b60c5de8d3280933c80ca8f2 100644 (file)
@@ -41,6 +41,7 @@
 #include <babeltrace/graph/notification-packet.h>
 #include <babeltrace/graph/notification-event.h>
 #include <babeltrace/graph/notification-stream.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
 #include <babeltrace/ref.h>
 #include <glib.h>
 
@@ -161,6 +162,9 @@ struct bt_ctf_notif_iter {
                struct bt_ctf_event_class *event_class;
        } meta;
 
+       /* Clock class priority map (owned by this) */
+       struct bt_clock_class_priority_map *cc_prio_map;
+
        /* Current packet (NULL if not created yet) */
        struct bt_ctf_packet *packet;
 
@@ -2195,7 +2199,7 @@ void notify_event(struct bt_ctf_notif_iter *notit,
                goto end;
        }
 
-       ret = bt_notification_event_create(event);
+       ret = bt_notification_event_create(event, notit->cc_prio_map);
        if (!ret) {
                goto end;
        }
@@ -2303,6 +2307,7 @@ end:
 
 BT_HIDDEN
 struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace,
+               struct bt_clock_class_priority_map *cc_prio_map,
                size_t max_request_sz,
                struct bt_ctf_notif_iter_medium_ops medops,
                void *data, FILE *err_stream)
@@ -2327,6 +2332,7 @@ struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace,
        };
 
        assert(trace);
+       assert(cc_prio_map);
        assert(medops.request_bytes);
        assert(medops.get_stream);
        notit = g_new0(struct bt_ctf_notif_iter, 1);
@@ -2345,6 +2351,7 @@ struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace,
                PERR("Failed to initialize stream clock states\n");
                goto error;
        }
+       notit->cc_prio_map = bt_get(cc_prio_map);
        notit->meta.trace = bt_get(trace);
        notit->medium.medops = medops;
        notit->medium.max_request_sz = max_request_sz;
@@ -2388,6 +2395,7 @@ error:
 
 void bt_ctf_notif_iter_destroy(struct bt_ctf_notif_iter *notit)
 {
+       BT_PUT(notit->cc_prio_map);
        BT_PUT(notit->meta.trace);
        BT_PUT(notit->meta.stream_class);
        BT_PUT(notit->meta.event_class);
index fd56575a2cc915411b43f6b017a3d35ce4c3a111..b8b91c5e324ab63578d232123dabac6b6b656524 100644 (file)
@@ -32,6 +32,7 @@
 #include <babeltrace/ctf-ir/trace.h>
 #include <babeltrace/ctf-ir/fields.h>
 #include <babeltrace/ctf-ir/event.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
 #include <babeltrace/babeltrace-internal.h>
 
 /**
@@ -233,6 +234,8 @@ struct bt_ctf_notif_iter_notif_event {
  * incremented.
  *
  * @param trace                        Trace to read
+ * @param cc_prio_map          Clock class priority map to use when
+ *                             creating the event notifications
  * @param max_request_sz       Maximum buffer size, in bytes, to
  *                             request to
  *                             bt_ctf_notif_iter_medium_ops::request_bytes()
@@ -245,6 +248,7 @@ struct bt_ctf_notif_iter_notif_event {
  */
 BT_HIDDEN
 struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace,
+       struct bt_clock_class_priority_map *cc_prio_map,
        size_t max_request_sz, struct bt_ctf_notif_iter_medium_ops medops,
        void *medops_data, FILE *err_stream);
 
index b4bb087a3ae867f4ac85bf19fe154ce8bcab1c7f..70bdf5a8a59adfcb3d6da8968b4247c97620f9dc 100644 (file)
@@ -370,7 +370,8 @@ struct ctf_fs_stream *ctf_fs_stream_create(
        }
 
        stream->notif_iter = bt_ctf_notif_iter_create(ctf_fs->metadata->trace,
-                       ctf_fs->page_size, medops, stream, ctf_fs->error_fp);
+                       ctf_fs->cc_prio_map, ctf_fs->page_size, medops, stream,
+                       ctf_fs->error_fp);
        if (!stream->notif_iter) {
                goto error;
        }
index ea45fbca792bbd9061844281a3054ff2a77ab558..ea33974bde4045609ece5e481b483e538970cbe7 100644 (file)
@@ -34,6 +34,7 @@
 #include <babeltrace/graph/private-notification-iterator.h>
 #include <babeltrace/graph/component.h>
 #include <babeltrace/graph/notification-iterator.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
 #include <plugins-common.h>
 #include <glib.h>
 #include <assert.h>
@@ -140,6 +141,7 @@ void ctf_fs_destroy_data(struct ctf_fs_component *ctf_fs)
                g_free(ctf_fs->metadata);
        }
 
+       bt_put(ctf_fs->cc_prio_map);
        g_free(ctf_fs);
 }
 
@@ -325,6 +327,42 @@ end:
        return ret;
 }
 
+static
+int create_cc_prio_map(struct ctf_fs_component *ctf_fs)
+{
+       int ret = 0;
+       size_t i;
+       int count;
+
+       assert(ctf_fs);
+       ctf_fs->cc_prio_map = bt_clock_class_priority_map_create();
+       if (!ctf_fs->cc_prio_map) {
+               ret = -1;
+               goto end;
+       }
+
+       count = bt_ctf_trace_get_clock_class_count(ctf_fs->metadata->trace);
+       assert(count >= 0);
+
+       for (i = 0; i < count; i++) {
+               struct bt_ctf_clock_class *clock_class =
+                       bt_ctf_trace_get_clock_class(ctf_fs->metadata->trace,
+                               i);
+
+               assert(clock_class);
+               ret = bt_clock_class_priority_map_add_clock_class(
+                       ctf_fs->cc_prio_map, clock_class, 0);
+               BT_PUT(clock_class);
+
+               if (ret) {
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
+}
+
 static
 struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp,
                struct bt_value *params)
@@ -380,6 +418,11 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp,
                goto error;
        }
 
+       ret = create_cc_prio_map(ctf_fs);
+       if (ret) {
+               goto error;
+       }
+
        ret = create_ports(ctf_fs);
        if (ret) {
                goto error;
index 0a34856af8a8000cc08815b36ebec8c6f6f8bbe3..720102987572484766a41a4c89be2f10df7c4954 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/graph/component.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
 #include "data-stream.h"
 
 #define CTF_FS_COMPONENT_DESCRIPTION \
@@ -90,6 +91,7 @@ struct ctf_fs_component {
        size_t page_size;
        struct ctf_fs_component_options options;
        struct ctf_fs_metadata *metadata;
+       struct bt_clock_class_priority_map *cc_prio_map;
 
        /* Array of struct ctf_fs_port_data *, owned by this */
        GPtrArray *port_data;
This page took 0.030387 seconds and 4 git commands to generate.