From 33931ab8fa9ae0cb4eb9bfdbbc9acc4d7b53ac17 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 19 Feb 2019 13:56:37 -0500 Subject: [PATCH] lib: message API: add fast default clock class accessors This patch adds a few bt_message_X_borrow_stream_class_default_clock_class() functions to quickly get the default clock class of a message's stream class. It is a library precondition that a message's stream class has a default clock class in order to borrow its default clock snapshot. This is because, sometimes, a default clock snapshot object exists even if it's never used for pooling and allocation reasons. There's no conditional in the clock snapshot borrowing functions for performance reasons, so you can't rely on the clock snapshot output parameter being `NULL` or not. The correct way to know whether or not there's a default clock snapshot to check if the message's stream class has a default clock class, which you can now do in a single call. For example, before: const bt_message *event_msg = ...; const bt_event *event = bt_message_event_borrow_event_const(event_msg); const bt_packet *packet = bt_event_borrow_packet_const(event); const bt_stream *stream = bt_packet_borrow_stream_const(event); const bt_stream_class *stream_class = bt_stream_borrow_class_const(stream); const bt_clock_class *def_clock_class = bt_stream_class_borrow_default_clock_class_const(stream_class); if (def_clock_class) { /* safe to borrow message's default clock snapshot */ } Now: const bt_message *event_msg = ...; const bt_clock_class *def_clock_class = bt_message_event_borrow_stream_class_default_clock_class_const( event_msg); if (def_clock_class) { /* safe to borrow message's default clock snapshot */ } Signed-off-by: Philippe Proulx --- .../graph/message-discarded-events-const.h | 4 +++ .../graph/message-discarded-packets-const.h | 4 +++ .../babeltrace/graph/message-event-const.h | 6 +++- .../graph/message-packet-beginning-const.h | 6 +++- .../graph/message-packet-end-const.h | 6 +++- .../message-stream-activity-beginning-const.h | 6 +++- .../graph/message-stream-activity-end-const.h | 6 +++- lib/graph/message/discarded-items.c | 31 ++++++++++++++++++ lib/graph/message/event.c | 20 ++++++++++-- lib/graph/message/packet.c | 29 +++++++++++++++++ lib/graph/message/stream-activity.c | 32 +++++++++++++++++++ 11 files changed, 142 insertions(+), 8 deletions(-) diff --git a/include/babeltrace/graph/message-discarded-events-const.h b/include/babeltrace/graph/message-discarded-events-const.h index 221667f6..68615526 100644 --- a/include/babeltrace/graph/message-discarded-events-const.h +++ b/include/babeltrace/graph/message-discarded-events-const.h @@ -41,6 +41,10 @@ extern bt_clock_snapshot_state bt_message_discarded_events_borrow_default_end_clock_snapshot_const( const bt_message *msg, const bt_clock_snapshot **snapshot); +extern const bt_clock_class * +bt_message_discarded_events_borrow_stream_class_default_clock_class_const( + const bt_message *msg); + extern const bt_stream * bt_message_discarded_events_borrow_stream_const(const bt_message *message); diff --git a/include/babeltrace/graph/message-discarded-packets-const.h b/include/babeltrace/graph/message-discarded-packets-const.h index ab067d78..77d5d413 100644 --- a/include/babeltrace/graph/message-discarded-packets-const.h +++ b/include/babeltrace/graph/message-discarded-packets-const.h @@ -41,6 +41,10 @@ extern bt_clock_snapshot_state bt_message_discarded_packets_borrow_default_end_clock_snapshot_const( const bt_message *msg, const bt_clock_snapshot **snapshot); +extern const bt_clock_class * +bt_message_discarded_packets_borrow_stream_class_default_clock_class_const( + const bt_message *msg); + extern const bt_stream * bt_message_discarded_packets_borrow_stream_const(const bt_message *message); diff --git a/include/babeltrace/graph/message-event-const.h b/include/babeltrace/graph/message-event-const.h index 3de48c48..4c611925 100644 --- a/include/babeltrace/graph/message-event-const.h +++ b/include/babeltrace/graph/message-event-const.h @@ -24,7 +24,7 @@ * SOFTWARE. */ -/* For bt_message, bt_event */ +/* For bt_bool, bt_message, bt_event. bt_clock_class, bt_clock_snapshot */ #include /* For bt_clock_snapshot_state */ @@ -41,6 +41,10 @@ extern bt_clock_snapshot_state bt_message_event_borrow_default_clock_snapshot_const( const bt_message *msg, const bt_clock_snapshot **snapshot); +extern const bt_clock_class * +bt_message_event_borrow_stream_class_default_clock_class_const( + const bt_message *msg); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/message-packet-beginning-const.h b/include/babeltrace/graph/message-packet-beginning-const.h index 49ebfcbf..a7cc1348 100644 --- a/include/babeltrace/graph/message-packet-beginning-const.h +++ b/include/babeltrace/graph/message-packet-beginning-const.h @@ -24,7 +24,7 @@ * SOFTWARE. */ -/* For bt_message, bt_packet */ +/* For bt_message, bt_packet, bt_clock_snapshot, bt_clock_class */ #include /* For bt_clock_snapshot_state */ @@ -41,6 +41,10 @@ extern bt_clock_snapshot_state bt_message_packet_beginning_borrow_default_clock_snapshot_const( const bt_message *msg, const bt_clock_snapshot **snapshot); +extern const bt_clock_class * +bt_message_packet_beginning_borrow_stream_class_default_clock_class_const( + const bt_message *msg); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/message-packet-end-const.h b/include/babeltrace/graph/message-packet-end-const.h index 44d18535..3a48911e 100644 --- a/include/babeltrace/graph/message-packet-end-const.h +++ b/include/babeltrace/graph/message-packet-end-const.h @@ -24,7 +24,7 @@ * SOFTWARE. */ -/* For bt_message, bt_packet */ +/* For bt_message, bt_packet, bt_clock_snapshot, bt_clock_class */ #include /* For bt_clock_snapshot_state */ @@ -41,6 +41,10 @@ extern bt_clock_snapshot_state bt_message_packet_end_borrow_default_clock_snapshot_const( const bt_message *msg, const bt_clock_snapshot **snapshot); +extern const bt_clock_class * +bt_message_packet_end_borrow_stream_class_default_clock_class_const( + const bt_message *msg); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/message-stream-activity-beginning-const.h b/include/babeltrace/graph/message-stream-activity-beginning-const.h index 919b1185..3e1d7a9d 100644 --- a/include/babeltrace/graph/message-stream-activity-beginning-const.h +++ b/include/babeltrace/graph/message-stream-activity-beginning-const.h @@ -23,7 +23,7 @@ * SOFTWARE. */ -/* For bt_message, bt_clock_snapshot, bt_stream */ +/* For bt_message, bt_clock_snapshot, bt_stream, bt_clock_class */ #include /* For bt_message_stream_activity_clock_snapshot_state */ @@ -37,6 +37,10 @@ extern bt_message_stream_activity_clock_snapshot_state bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const( const bt_message *msg, const bt_clock_snapshot **snapshot); +extern const bt_clock_class * +bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const( + const bt_message *msg); + extern const bt_stream * bt_message_stream_activity_beginning_borrow_stream_const( const bt_message *message); diff --git a/include/babeltrace/graph/message-stream-activity-end-const.h b/include/babeltrace/graph/message-stream-activity-end-const.h index d10540a2..4cf957b3 100644 --- a/include/babeltrace/graph/message-stream-activity-end-const.h +++ b/include/babeltrace/graph/message-stream-activity-end-const.h @@ -23,7 +23,7 @@ * SOFTWARE. */ -/* For bt_message, bt_clock_snapshot, bt_stream */ +/* For bt_message, bt_clock_snapshot, bt_stream, bt_clock_class */ #include /* For bt_message_stream_activity_clock_snapshot_state */ @@ -37,6 +37,10 @@ extern bt_message_stream_activity_clock_snapshot_state bt_message_stream_activity_end_borrow_default_clock_snapshot_const( const bt_message *msg, const bt_clock_snapshot **snapshot); +extern const bt_clock_class * +bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const( + const bt_message *msg); + extern const bt_stream * bt_message_stream_activity_end_borrow_stream_const( const bt_message *message); diff --git a/lib/graph/message/discarded-items.c b/lib/graph/message/discarded-items.c index a4bc9e3b..cd40a3f3 100644 --- a/lib/graph/message/discarded-items.c +++ b/lib/graph/message/discarded-items.c @@ -344,3 +344,34 @@ enum bt_property_availability bt_message_discarded_packets_get_count( BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS); return get_discarded_items_message_count(message, count); } + +static inline +const struct bt_clock_class * +borrow_discarded_items_message_stream_class_default_clock_class( + const struct bt_message *msg) +{ + struct bt_message_discarded_items *disc_items_msg = (void *) msg; + + BT_ASSERT(msg); + return disc_items_msg->stream->class->default_clock_class; +} + +const struct bt_clock_class * +bt_message_discarded_events_borrow_stream_class_default_clock_class_const( + const struct bt_message *msg) +{ + BT_ASSERT_PRE_NON_NULL(msg, "Message"); + BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS); + return borrow_discarded_items_message_stream_class_default_clock_class( + msg); +} + +const struct bt_clock_class * +bt_message_discarded_packets_borrow_stream_class_default_clock_class_const( + const struct bt_message *msg) +{ + BT_ASSERT_PRE_NON_NULL(msg, "Message"); + BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS); + return borrow_discarded_items_message_stream_class_default_clock_class( + msg); +} diff --git a/lib/graph/message/event.c b/lib/graph/message/event.c index e79eb3de..33e423e1 100644 --- a/lib/graph/message/event.c +++ b/lib/graph/message/event.c @@ -47,7 +47,7 @@ static inline bool event_class_has_trace(struct bt_event_class *event_class) { struct bt_stream_class *stream_class; - stream_class = bt_event_class_borrow_stream_class(event_class); + stream_class = bt_event_class_borrow_stream_class_inline(event_class); BT_ASSERT(stream_class); return bt_stream_class_borrow_trace_class(stream_class) != NULL; } @@ -265,8 +265,7 @@ bt_message_event_borrow_default_clock_snapshot_const( 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( + stream_class = bt_event_class_borrow_stream_class_inline( event_msg->event->class); BT_ASSERT(stream_class); BT_ASSERT_PRE(stream_class->default_clock_class, @@ -276,3 +275,18 @@ bt_message_event_borrow_default_clock_snapshot_const( *snapshot = event_msg->default_cs; return BT_CLOCK_SNAPSHOT_STATE_KNOWN; } + +const bt_clock_class * +bt_message_event_borrow_stream_class_default_clock_class_const( + const bt_message *msg) +{ + 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); + stream_class = bt_event_class_borrow_stream_class_inline( + event_msg->event->class); + BT_ASSERT(stream_class); + return stream_class->default_clock_class; +} diff --git a/lib/graph/message/packet.c b/lib/graph/message/packet.c index a61999ae..87c241e0 100644 --- a/lib/graph/message/packet.c +++ b/lib/graph/message/packet.c @@ -323,3 +323,32 @@ bt_message_packet_end_borrow_default_clock_snapshot_const( return borrow_packet_message_default_clock_snapshot_const( msg, snapshot); } + +static inline +const struct bt_clock_class * +borrow_packet_message_stream_class_default_clock_class( + const struct bt_message *msg) +{ + struct bt_message_packet *packet_msg = (void *) msg; + + BT_ASSERT(msg); + return packet_msg->packet->stream->class->default_clock_class; +} + +const struct bt_clock_class * +bt_message_packet_beginning_borrow_stream_class_default_clock_class_const( + const struct bt_message *msg) +{ + BT_ASSERT_PRE_NON_NULL(msg, "Message"); + BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_BEGINNING); + return borrow_packet_message_stream_class_default_clock_class(msg); +} + +const struct bt_clock_class * +bt_message_packet_end_borrow_stream_class_default_clock_class_const( + const struct bt_message *msg) +{ + BT_ASSERT_PRE_NON_NULL(msg, "Message"); + BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_PACKET_END); + return borrow_packet_message_stream_class_default_clock_class(msg); +} diff --git a/lib/graph/message/stream-activity.c b/lib/graph/message/stream-activity.c index ccbe240a..dbf88645 100644 --- a/lib/graph/message/stream-activity.c +++ b/lib/graph/message/stream-activity.c @@ -269,3 +269,35 @@ void bt_message_stream_activity_end_set_default_clock_snapshot_state( BT_MESSAGE_TYPE_STREAM_ACTIVITY_END); set_stream_activity_message_default_clock_snapshot_state(msg, state); } + +static inline +const struct bt_clock_class * +borrow_stream_activity_message_stream_class_default_clock_class( + const struct bt_message *msg) +{ + struct bt_message_stream_activity *stream_act_msg = (void *) msg; + + BT_ASSERT(msg); + return stream_act_msg->stream->class->default_clock_class; +} + +const struct bt_clock_class * +bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const( + const struct bt_message *msg) +{ + BT_ASSERT_PRE_NON_NULL(msg, "Message"); + BT_ASSERT_PRE_MSG_IS_TYPE(msg, + BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING); + return borrow_stream_activity_message_stream_class_default_clock_class( + msg); +} + +const struct bt_clock_class * +bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const( + const struct bt_message *msg) +{ + BT_ASSERT_PRE_NON_NULL(msg, "Message"); + BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_ACTIVITY_END); + return borrow_stream_activity_message_stream_class_default_clock_class( + msg); +} -- 2.34.1