From 24626e8bc3516dd3b075489b42576c9045070b4a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 21 Nov 2016 18:07:03 -0500 Subject: [PATCH] Allow ctf-writer to use new time-keeping facilities MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/clock.c | 15 ++++++ formats/ctf/ir/event.c | 58 ++++++++++++++-------- formats/ctf/ir/fields.c | 2 +- formats/ctf/ir/stream-class.c | 2 +- include/babeltrace/ctf-ir/clock-internal.h | 3 ++ lib/plugin-system/notification/event.c | 5 ++ 6 files changed, 63 insertions(+), 22 deletions(-) diff --git a/formats/ctf/ir/clock.c b/formats/ctf/ir/clock.c index 4eed39c7..e24b864b 100644 --- a/formats/ctf/ir/clock.c +++ b/formats/ctf/ir/clock.c @@ -434,6 +434,21 @@ void bt_ctf_clock_serialize(struct bt_ctf_clock *clock, g_string_append(context->string, "};\n\n"); } +BT_HIDDEN +int bt_ctf_clock_get_value(struct bt_ctf_clock *clock, uint64_t *value) +{ + int ret = 0; + + if (!clock || !value) { + ret = -1; + goto end; + } + + *value = clock->value; +end: + return ret; +} + static void bt_ctf_clock_destroy(struct bt_object *obj) { diff --git a/formats/ctf/ir/event.c b/formats/ctf/ir/event.c index 4c1d2402..01468650 100644 --- a/formats/ctf/ir/event.c +++ b/formats/ctf/ir/event.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -612,11 +613,6 @@ int set_integer_field_value(struct bt_ctf_field* field, uint64_t value) goto end; } - if (!bt_ctf_field_validate(field)) { - /* Payload already set, skip! (not an error) */ - goto end; - } - field_type = bt_ctf_field_get_type(field); assert(field_type); @@ -714,6 +710,7 @@ int bt_ctf_event_populate_event_header(struct bt_ctf_event *event) { int ret = 0; struct bt_ctf_field *id_field = NULL, *timestamp_field = NULL; + struct bt_ctf_clock *mapped_clock = NULL; if (!event || event->frozen) { ret = -1; @@ -721,40 +718,60 @@ int bt_ctf_event_populate_event_header(struct bt_ctf_event *event) } id_field = bt_ctf_field_structure_get_field(event->event_header, "id"); - if (id_field) { + if (id_field && !bt_ctf_field_is_set(id_field)) { ret = set_integer_field_value(id_field, (uint64_t) bt_ctf_event_class_get_id( - event->event_class)); + event->event_class)); if (ret) { goto end; } } timestamp_field = bt_ctf_field_structure_get_field(event->event_header, - "timestamp"); - if (timestamp_field) { + "timestamp"); + if (timestamp_field && !bt_ctf_field_is_set(timestamp_field)) { struct bt_ctf_field_type *timestamp_field_type = bt_ctf_field_get_type(timestamp_field); - struct bt_ctf_clock *mapped_clock; assert(timestamp_field_type); mapped_clock = bt_ctf_field_type_integer_get_mapped_clock( - timestamp_field_type); + timestamp_field_type); bt_put(timestamp_field_type); if (mapped_clock) { - int64_t timestamp = 0; - - // FIXME - Clock refactoring /* - ret = bt_ctf_clock_get_time(mapped_clock, ×tamp); - bt_put(mapped_clock); - if (ret) { - goto end; + * Babeltrace 2.0 introduced a notion of per-event clock + * values which can be queried using a "clock" instance. + * + * However, the original CTF-Writer (BT 1.x) had a + * notion of per-stream clock which is sampled on + * a call to append an event to a stream. + * + * If the event has a clock value associated with the + * mapped clock, we ignore the pre-2.0 behaviour and + * populate the timestamp field using the clock value. + */ + uint64_t timestamp = 0; + struct bt_ctf_clock_value *clock_value; + + clock_value = bt_ctf_event_get_clock_value(event, + mapped_clock); + if (clock_value) { + ret = bt_ctf_clock_value_get_value(clock_value, + ×tamp); + bt_put(clock_value); + if (ret) { + goto end; + } + } else { + ret = bt_ctf_clock_get_value(mapped_clock, + ×tamp); + if (ret) { + goto end; + } } - */ ret = set_integer_field_value(timestamp_field, - timestamp); + timestamp); if (ret) { goto end; } @@ -763,6 +780,7 @@ int bt_ctf_event_populate_event_header(struct bt_ctf_event *event) end: bt_put(id_field); bt_put(timestamp_field); + bt_put(mapped_clock); return ret; } diff --git a/formats/ctf/ir/fields.c b/formats/ctf/ir/fields.c index 84b8c078..1a2a2c7f 100644 --- a/formats/ctf/ir/fields.c +++ b/formats/ctf/ir/fields.c @@ -2523,7 +2523,7 @@ bool bt_ctf_field_array_is_set(struct bt_ctf_field *field) array = container_of(field, struct bt_ctf_field_array, parent); for (i = 0; i < array->elements->len; i++) { - is_set = bt_ctf_field_validate(array->elements->pdata[i]); + is_set = bt_ctf_field_is_set(array->elements->pdata[i]); if (!is_set) { goto end; } diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index d1cac621..f5b89233 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -421,7 +421,7 @@ int bt_ctf_stream_class_add_event_class( /* Only set an event ID if none was explicitly set before */ *event_id = bt_ctf_event_class_get_id(event_class); - if (event_id < 0) { + if (*event_id < 0) { if (bt_ctf_event_class_set_id(event_class, stream_class->next_event_id++)) { ret = -1; diff --git a/include/babeltrace/ctf-ir/clock-internal.h b/include/babeltrace/ctf-ir/clock-internal.h index 0ed43ae9..38b0fcf1 100644 --- a/include/babeltrace/ctf-ir/clock-internal.h +++ b/include/babeltrace/ctf-ir/clock-internal.h @@ -79,4 +79,7 @@ void bt_ctf_clock_serialize(struct bt_ctf_clock *clock, BT_HIDDEN bool bt_ctf_clock_is_valid(struct bt_ctf_clock *clock); +BT_HIDDEN +int bt_ctf_clock_get_value(struct bt_ctf_clock *clock, uint64_t *value); + #endif /* BABELTRACE_CTF_IR_CLOCK_INTERNAL_H */ diff --git a/lib/plugin-system/notification/event.c b/lib/plugin-system/notification/event.c index 9d99a0d6..eb570909 100644 --- a/lib/plugin-system/notification/event.c +++ b/lib/plugin-system/notification/event.c @@ -45,7 +45,12 @@ struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event) goto error; } + // FIXME - Validate that the event is associated to a packet + // and freeze the event. notification = g_new0(struct bt_notification_event, 1); + if (!notification) { + goto error; + } bt_notification_init(¬ification->parent, BT_NOTIFICATION_TYPE_EVENT, bt_notification_event_destroy); -- 2.34.1