From: Philippe Proulx Date: Tue, 19 Feb 2019 14:14:55 +0000 (-0500) Subject: lib: have default clock snapshot in event message X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=aae879910975c03ade18c1330935cd9bd9dd8b33;p=deliverable%2Fbabeltrace.git lib: have default clock snapshot in event message The event message is the only message not having a default clock snapshot property (it's in an event object). Since an event object is unique and belongs solely to an event message, make it more consistent and move the default clock snapshot property to the message instead. Signed-off-by: Philippe Proulx --- diff --git a/include/babeltrace/graph/message-event-const.h b/include/babeltrace/graph/message-event-const.h index 8d0d6fc1a..3de48c485 100644 --- a/include/babeltrace/graph/message-event-const.h +++ b/include/babeltrace/graph/message-event-const.h @@ -27,6 +27,9 @@ /* For bt_message, bt_event */ #include +/* For bt_clock_snapshot_state */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -34,6 +37,10 @@ extern "C" { extern const bt_event *bt_message_event_borrow_event_const( const bt_message *message); +extern bt_clock_snapshot_state +bt_message_event_borrow_default_clock_snapshot_const( + const bt_message *msg, const bt_clock_snapshot **snapshot); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/message-event-internal.h b/include/babeltrace/graph/message-event-internal.h index 5727df298..f0d827b94 100644 --- a/include/babeltrace/graph/message-event-internal.h +++ b/include/babeltrace/graph/message-event-internal.h @@ -37,6 +37,7 @@ extern "C" { struct bt_message_event { struct bt_message parent; struct bt_event *event; + struct bt_clock_snapshot *default_cs; }; BT_HIDDEN diff --git a/include/babeltrace/graph/message-event.h b/include/babeltrace/graph/message-event.h index 733d91ad5..942a1d84c 100644 --- a/include/babeltrace/graph/message-event.h +++ b/include/babeltrace/graph/message-event.h @@ -24,6 +24,8 @@ * SOFTWARE. */ +#include + /* * For bt_self_message_iterator, bt_event, bt_packet, * bt_event_class, bt_message @@ -40,6 +42,12 @@ bt_message *bt_message_event_create( 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_packet *packet, uint64_t raw_clock_value); + extern bt_event *bt_message_event_borrow_event( bt_message *message); diff --git a/include/babeltrace/trace-ir/event-const.h b/include/babeltrace/trace-ir/event-const.h index 1199c40a7..00dff6581 100644 --- a/include/babeltrace/trace-ir/event-const.h +++ b/include/babeltrace/trace-ir/event-const.h @@ -27,10 +27,7 @@ * http://www.efficios.com/ctf */ -/* For bt_clock_snapshot_state */ -#include - -/* For bt_event, bt_clock_snapshot, bt_event_class, bt_field, bt_packet */ +/* For bt_event, bt_event_class, bt_field, bt_packet */ #include #ifdef __cplusplus @@ -60,10 +57,6 @@ extern const bt_field *bt_event_borrow_specific_context_field_const( extern const bt_field *bt_event_borrow_payload_field_const( const bt_event *event); -extern bt_clock_snapshot_state bt_event_borrow_default_clock_snapshot_const( - const bt_event *event, - const bt_clock_snapshot **clock_snapshot); - #ifdef __cplusplus } #endif diff --git a/include/babeltrace/trace-ir/event-internal.h b/include/babeltrace/trace-ir/event-internal.h index cfc30ee1b..71356bc38 100644 --- a/include/babeltrace/trace-ir/event-internal.h +++ b/include/babeltrace/trace-ir/event-internal.h @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -62,7 +61,6 @@ struct bt_event { struct bt_field *common_context_field; struct bt_field *specific_context_field; struct bt_field *payload_field; - struct bt_clock_snapshot *default_cs; bool frozen; }; @@ -119,11 +117,6 @@ 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); - - if (event->default_cs) { - bt_clock_snapshot_reset(event->default_cs); - } - bt_object_put_no_null_check(&event->packet->base); event->packet = NULL; } diff --git a/include/babeltrace/trace-ir/event.h b/include/babeltrace/trace-ir/event.h index e394583ba..e7c797ca5 100644 --- a/include/babeltrace/trace-ir/event.h +++ b/include/babeltrace/trace-ir/event.h @@ -51,9 +51,6 @@ bt_event_borrow_specific_context_field(bt_event *event); extern bt_field *bt_event_borrow_payload_field(bt_event *event); -extern void bt_event_set_default_clock_snapshot(bt_event *event, - uint64_t value_cycles); - #ifdef __cplusplus } #endif diff --git a/lib/graph/iterator.c b/lib/graph/iterator.c index bc8faf85a..094447b6f 100644 --- a/lib/graph/iterator.c +++ b/lib/graph/iterator.c @@ -985,7 +985,7 @@ int get_message_ns_from_origin(const struct bt_message *msg, const struct bt_message_event *event_msg = (const void *) msg; - clk_snapshot = event_msg->event->default_cs; + clk_snapshot = event_msg->default_cs; BT_ASSERT_PRE(clk_snapshot, "Event has no default clock snapshot: %!+e", event_msg->event); diff --git a/lib/graph/message/event.c b/lib/graph/message/event.c index 2b4b4ba8d..e79eb3de9 100644 --- a/lib/graph/message/event.c +++ b/lib/graph/message/event.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -74,15 +75,18 @@ end: return (void *) message; } -struct bt_message *bt_message_event_create( +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) + const struct bt_packet *c_packet, bool with_cs, + uint64_t raw_value) { struct bt_self_component_port_input_message_iterator *msg_iter = (void *) self_msg_iter; struct bt_message_event *message = NULL; 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_event *event; @@ -91,8 +95,17 @@ struct bt_message *bt_message_event_create( 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); - BT_LIB_LOGD("Creating event message object: %![ec-]+E", - event_class); + stream_class = bt_event_class_borrow_stream_class_inline(event_class); + BT_ASSERT(stream_class); + BT_ASSERT_PRE((with_cs && stream_class->default_clock_class) || + (!with_cs && !stream_class->default_clock_class), + "Creating an event message with a default clock snapshot, but without " + "a default clock class, or without a default clock snapshot, " + "but with a default clock class: ", + "%![ec-]+E, %![sc-]+S, with-cs=%d, " + "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); if (unlikely(!event)) { BT_LIB_LOGE("Cannot create event from event class: " @@ -122,6 +135,17 @@ struct bt_message *bt_message_event_create( goto error; } + if (with_cs) { + BT_ASSERT(stream_class->default_clock_class); + message->default_cs = bt_clock_snapshot_create( + stream_class->default_clock_class); + if (!message->default_cs) { + goto error; + } + + bt_clock_snapshot_set_raw_value(message->default_cs, raw_value); + } + BT_ASSERT(!message->event); message->event = event; bt_packet_set_is_frozen(packet, true); @@ -138,6 +162,24 @@ end: return (void *) message; } +struct bt_message *bt_message_event_create( + 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); +} + +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_packet *packet, + uint64_t raw_value) +{ + return create_event_message(msg_iter, event_class, packet, + true, raw_value); +} + BT_HIDDEN void bt_message_event_destroy(struct bt_message *msg) { @@ -151,6 +193,11 @@ void bt_message_event_destroy(struct bt_message *msg) event_msg->event = NULL; } + if (event_msg->default_cs) { + bt_clock_snapshot_recycle(event_msg->default_cs); + event_msg->default_cs = NULL; + } + g_free(msg); } @@ -173,6 +220,12 @@ void bt_message_event_recycle(struct bt_message *msg) BT_ASSERT(event_msg->event); bt_event_recycle(event_msg->event); event_msg->event = NULL; + + if (event_msg->default_cs) { + bt_clock_snapshot_recycle(event_msg->default_cs); + event_msg->default_cs = NULL; + } + graph = msg->graph; msg->graph = NULL; bt_object_pool_recycle_object(&graph->event_msg_pool, msg); @@ -201,3 +254,25 @@ const struct bt_event *bt_message_event_borrow_event_const( { return borrow_event((void *) message); } + +enum bt_clock_snapshot_state +bt_message_event_borrow_default_clock_snapshot_const( + const struct bt_message *msg, + const struct bt_clock_snapshot **snapshot) +{ + struct bt_message_event *event_msg = (void *) msg; + struct bt_stream_class *stream_class; + + BT_ASSERT_PRE_NON_NULL(msg, "Message"); + BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_EVENT); + BT_ASSERT(msg); + stream_class = bt_event_class_borrow_stream_class( + event_msg->event->class); + BT_ASSERT(stream_class); + BT_ASSERT_PRE(stream_class->default_clock_class, + "Message's stream's class has no default clock class: " + "%![msg-]+n, %![sc-]+S", msg, stream_class); + BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)"); + *snapshot = event_msg->default_cs; + return BT_CLOCK_SNAPSHOT_STATE_KNOWN; +} diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 0872cc26b..ecf217ff1 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -712,12 +712,6 @@ static inline void format_event(char **buf_ch, bool extended, } } - if (event->default_cs) { - SET_TMP_PREFIX("default-cs-"); - format_clock_snapshot(buf_ch, true, tmp_prefix, - event->default_cs); - } - packet = bt_event_borrow_packet_const(event); if (!packet) { return; diff --git a/lib/trace-ir/event.c b/lib/trace-ir/event.c index 1badd83a3..ec2a7e243 100644 --- a/lib/trace-ir/event.c +++ b/lib/trace-ir/event.c @@ -27,10 +27,6 @@ #include #include #include -#include -#include -#include -#include #include #include #include @@ -123,15 +119,6 @@ struct bt_event *bt_event_new(struct bt_event_class *event_class) } } - if (stream_class->default_clock_class) { - event->default_cs = bt_clock_snapshot_create( - stream_class->default_clock_class); - if (!event->default_cs) { - /* bt_clock_snapshot_create() logs errors */ - goto error; - } - } - goto end; error: @@ -233,45 +220,11 @@ void bt_event_destroy(struct bt_event *event) BT_LOGD_STR("Putting event's class."); bt_object_put_ref(event->class); - - if (event->default_cs) { - bt_clock_snapshot_recycle(event->default_cs); - event->default_cs = NULL; - } - BT_LOGD_STR("Putting event's packet."); BT_OBJECT_PUT_REF_AND_RESET(event->packet); g_free(event); } -void bt_event_set_default_clock_snapshot(struct bt_event *event, - uint64_t value_cycles) -{ - struct bt_stream_class *sc; - - BT_ASSERT_PRE_NON_NULL(event, "Event"); - BT_ASSERT_PRE_EVENT_HOT(event); - sc = bt_event_class_borrow_stream_class_inline(event->class); - BT_ASSERT(sc); - BT_ASSERT_PRE(sc->default_clock_class, - "Event's stream class has no default clock class: " - "%![ev-]+e, %![sc-]+S", event, sc); - BT_ASSERT(event->default_cs); - bt_clock_snapshot_set_raw_value(event->default_cs, value_cycles); - BT_LIB_LOGV("Set event's default clock snapshot: %![event-]+e, " - "value=%" PRIu64, event, value_cycles); -} - -enum bt_clock_snapshot_state bt_event_borrow_default_clock_snapshot_const( - const struct bt_event *event, - const struct bt_clock_snapshot **clock_snapshot) -{ - BT_ASSERT_PRE_NON_NULL(event, "Event"); - BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot (output)"); - *clock_snapshot = event->default_cs; - return BT_CLOCK_SNAPSHOT_STATE_KNOWN; -} - struct bt_packet *bt_event_borrow_packet(struct bt_event *event) { BT_ASSERT_PRE_NON_NULL(event, "Event"); diff --git a/plugins/ctf/common/msg-iter/msg-iter.c b/plugins/ctf/common/msg-iter/msg-iter.c index 3800d07a3..d7cb7f37a 100644 --- a/plugins/ctf/common/msg-iter/msg-iter.c +++ b/plugins/ctf/common/msg-iter/msg-iter.c @@ -1183,8 +1183,17 @@ enum bt_msg_iter_status set_current_event_message( notit->meta.ec->name->str, notit->packet); BT_ASSERT(notit->msg_iter); - msg = bt_message_event_create(notit->msg_iter, - notit->meta.ec->ir_ec, notit->packet); + 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( + notit->msg_iter, notit->meta.ec->ir_ec, + notit->packet, notit->default_clock_snapshot); + } else { + msg = bt_message_event_create(notit->msg_iter, + notit->meta.ec->ir_ec, notit->packet); + } + if (!msg) { BT_LOGE("Cannot create event message: " "notit-addr=%p, ec-addr=%p, ec-name=\"%s\", " @@ -2369,20 +2378,6 @@ end: return ret_fc; } -static -void set_event_default_clock_snapshot(struct bt_msg_iter *notit) -{ - bt_event *event = bt_message_event_borrow_event(notit->event_msg); - bt_stream_class *sc = notit->meta.sc->ir_sc; - - BT_ASSERT(event); - - if (bt_stream_class_borrow_default_clock_class(sc)) { - bt_event_set_default_clock_snapshot(event, - notit->default_clock_snapshot); - } -} - static void create_msg_stream_beginning(struct bt_msg_iter *notit, bt_message **message) @@ -2778,7 +2773,6 @@ enum bt_msg_iter_status bt_msg_iter_get_next_message( switch (notit->state) { case STATE_EMIT_MSG_EVENT: BT_ASSERT(notit->event_msg); - set_event_default_clock_snapshot(notit); *message = notit->event_msg; notit->event_msg = NULL; goto end; diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index d73d2abe6..aac38c23e 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -516,8 +516,16 @@ skip_ts: goto error; } - msg = bt_message_event_create(msg_iter->pc_msg_iter, - dmesg_comp->event_class, dmesg_comp->packet); + 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); + msg_iter->last_clock_value = ts; + } else { + msg = bt_message_event_create(msg_iter->pc_msg_iter, + dmesg_comp->event_class, dmesg_comp->packet); + } + if (!msg) { BT_LOGE_STR("Cannot create event message."); goto error; @@ -525,12 +533,6 @@ skip_ts: event = bt_message_event_borrow_event(msg); BT_ASSERT(event); - - if (dmesg_comp->clock_class) { - bt_event_set_default_clock_snapshot(event, ts); - msg_iter->last_clock_value = ts; - } - goto end; error: diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index b3afd5738..be9b13e9b 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -78,17 +78,9 @@ void print_field_name_equal(struct pretty_component *pretty, const char *name) static void print_timestamp_cycles(struct pretty_component *pretty, - const bt_event *event) + const bt_clock_snapshot *clock_snapshot) { - const bt_clock_snapshot *clock_snapshot; uint64_t cycles; - bt_clock_snapshot_state cs_state; - - cs_state = bt_event_borrow_default_clock_snapshot_const(event, &clock_snapshot); - if (cs_state != BT_CLOCK_SNAPSHOT_STATE_KNOWN || !clock_snapshot) { - g_string_append(pretty->string, "????????????????????"); - return; - } cycles = bt_clock_snapshot_get_value(clock_snapshot); g_string_append_printf(pretty->string, "%020" PRIu64, cycles); @@ -96,6 +88,7 @@ void print_timestamp_cycles(struct pretty_component *pretty, if (pretty->last_cycles_timestamp != -1ULL) { pretty->delta_cycles = cycles - pretty->last_cycles_timestamp; } + pretty->last_cycles_timestamp = cycles; } @@ -216,30 +209,25 @@ end: static int print_event_timestamp(struct pretty_component *pretty, - const bt_event *event, bool *start_line) + const bt_message *event_msg, bool *start_line) { bool print_names = pretty->options.print_header_field_names; int ret = 0; const bt_stream *stream = NULL; const bt_stream_class *stream_class = NULL; const bt_clock_snapshot *clock_snapshot = NULL; - bt_clock_snapshot_state cs_state; + const bt_event *event = bt_message_event_borrow_event_const(event_msg); stream = bt_event_borrow_stream_const(event); - if (!stream) { - ret = -1; - goto end; - } - stream_class = bt_stream_borrow_class_const(stream); - if (!stream_class) { - ret = -1; + + if (!bt_stream_class_borrow_default_clock_class_const(stream_class)) { + /* No default clock class: skip the timestamp without an error */ goto end; } - cs_state = bt_event_borrow_default_clock_snapshot_const(event, - &clock_snapshot); - if (cs_state != BT_CLOCK_SNAPSHOT_STATE_KNOWN || !clock_snapshot) { + if (bt_message_event_borrow_default_clock_snapshot_const(event_msg, + &clock_snapshot) != BT_CLOCK_SNAPSHOT_STATE_KNOWN) { /* No default clock value: skip the timestamp without an error */ goto end; } @@ -253,11 +241,8 @@ int print_event_timestamp(struct pretty_component *pretty, g_string_append(pretty->string, COLOR_TIMESTAMP); } if (pretty->options.print_timestamp_cycles) { - print_timestamp_cycles(pretty, event); + print_timestamp_cycles(pretty, clock_snapshot); } else { - clock_snapshot = NULL; - cs_state = bt_event_borrow_default_clock_snapshot_const(event, - &clock_snapshot); print_timestamp_wall(pretty, clock_snapshot); } if (pretty->use_colors) { @@ -308,7 +293,7 @@ end: static int print_event_header(struct pretty_component *pretty, - const bt_event *event) + const bt_message *event_msg) { bool print_names = pretty->options.print_header_field_names; int ret = 0; @@ -318,6 +303,7 @@ int print_event_header(struct pretty_component *pretty, 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); int dom_print = 0; bt_property_availability prop_avail; @@ -327,7 +313,7 @@ int print_event_header(struct pretty_component *pretty, packet = bt_event_borrow_packet_const(event); stream = bt_packet_borrow_stream_const(packet); trace = bt_stream_borrow_trace_const(stream); - ret = print_event_timestamp(pretty, event, &pretty->start_line); + ret = print_event_timestamp(pretty, event_msg, &pretty->start_line); if (ret) { goto end; } @@ -1180,7 +1166,7 @@ int pretty_print_event(struct pretty_component *pretty, BT_ASSERT(event); pretty->start_line = true; g_string_assign(pretty->string, ""); - ret = print_event_header(pretty, event); + ret = print_event_header(pretty, event_msg); if (ret != 0) { goto end; } diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index 032fef41b..700789520 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -610,7 +610,6 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp, { const bt_clock_class *clock_class = NULL; const bt_clock_snapshot *clock_snapshot = NULL; - const bt_event *event = NULL; int ret = 0; const unsigned char *cc_uuid; const char *cc_name; @@ -626,10 +625,8 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp, switch (bt_message_get_type(msg)) { case BT_MESSAGE_TYPE_EVENT: - event = bt_message_event_borrow_event_const(msg); - BT_ASSERT(event); - cs_state = bt_event_borrow_default_clock_snapshot_const(event, - &clock_snapshot); + cs_state = bt_message_event_borrow_default_clock_snapshot_const( + msg, &clock_snapshot); break; case BT_MESSAGE_TYPE_INACTIVITY: