From dc68f16da7c8a96930d36f50489d6697c852b733 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Sat, 8 Dec 2018 14:47:56 -0500 Subject: [PATCH] Clock snapshot API: use status `enum bt_clock_snapshot_status` is renamed to `enum bt_clock_snapshot_state` (known or unknown), while `enum bt_clock_snapshot_status` is the API status enumeration like with other APIs. Signed-off-by: Philippe Proulx --- .../graph/message-inactivity-const.h | 7 ++++-- include/babeltrace/graph/message-inactivity.h | 4 ++-- .../babeltrace/graph/message-stream-const.h | 11 +++++---- .../trace-ir/clock-snapshot-const.h | 11 ++++++--- include/babeltrace/trace-ir/event-const.h | 4 ++-- include/babeltrace/trace-ir/packet-const.h | 7 +++--- lib/graph/message/inactivity.c | 8 ++++--- lib/graph/message/stream.c | 23 ++++++++++++------- lib/trace-ir/clock-snapshot.c | 9 +++++--- lib/trace-ir/event.c | 4 ++-- lib/trace-ir/packet.c | 8 +++---- lib/trace-ir/stream-class.c | 2 +- plugins/text/pretty/print.c | 14 +++++------ plugins/utils/muxer/muxer.c | 10 ++++---- 14 files changed, 73 insertions(+), 49 deletions(-) diff --git a/include/babeltrace/graph/message-inactivity-const.h b/include/babeltrace/graph/message-inactivity-const.h index 9c1a825b..0642c409 100644 --- a/include/babeltrace/graph/message-inactivity-const.h +++ b/include/babeltrace/graph/message-inactivity-const.h @@ -26,13 +26,16 @@ /* For bt_message, bt_clock_snapshot */ #include +/* For enum bt_clock_snapshot_state */ +#include + #ifdef __cplusplus extern "C" { #endif -extern const bt_clock_snapshot * +extern enum bt_clock_snapshot_state bt_message_inactivity_borrow_default_clock_snapshot_const( - const bt_message *msg); + const bt_message *msg, const bt_clock_snapshot **snapshot); #ifdef __cplusplus } diff --git a/include/babeltrace/graph/message-inactivity.h b/include/babeltrace/graph/message-inactivity.h index f958eb66..2549815d 100644 --- a/include/babeltrace/graph/message-inactivity.h +++ b/include/babeltrace/graph/message-inactivity.h @@ -23,11 +23,11 @@ * SOFTWARE. */ +#include + /* For bt_self_message_iterator, bt_message, bt_clock_class */ #include -#include - #ifdef __cplusplus extern "C" { #endif diff --git a/include/babeltrace/graph/message-stream-const.h b/include/babeltrace/graph/message-stream-const.h index f1c2c2ec..7b902f07 100644 --- a/include/babeltrace/graph/message-stream-const.h +++ b/include/babeltrace/graph/message-stream-const.h @@ -27,6 +27,9 @@ /* For bt_message, bt_clock_snapshot, bt_stream */ #include +/* For enum bt_clock_snapshot_state */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -34,16 +37,16 @@ extern "C" { extern const bt_stream *bt_message_stream_beginning_borrow_stream_const( const bt_message *message); -extern const bt_clock_snapshot * +extern enum bt_clock_snapshot_state bt_message_stream_beginning_borrow_default_clock_snapshot_const( - const bt_message *msg); + const bt_message *msg, const bt_clock_snapshot **snapshot); extern const bt_stream *bt_message_stream_end_borrow_stream_const( const bt_message *message); -extern const bt_clock_snapshot * +extern enum bt_clock_snapshot_state bt_message_stream_end_borrow_default_clock_snapshot_const( - const bt_message *msg); + const bt_message *msg, const bt_clock_snapshot **snapshot); #ifdef __cplusplus } diff --git a/include/babeltrace/trace-ir/clock-snapshot-const.h b/include/babeltrace/trace-ir/clock-snapshot-const.h index e0b0e392..e0f5f05f 100644 --- a/include/babeltrace/trace-ir/clock-snapshot-const.h +++ b/include/babeltrace/trace-ir/clock-snapshot-const.h @@ -36,9 +36,14 @@ extern "C" { #endif +enum bt_clock_snapshot_state { + BT_CLOCK_SNAPSHOT_STATE_KNOWN, + BT_CLOCK_SNAPSHOT_STATE_UNKNOWN, +}; + enum bt_clock_snapshot_status { - BT_CLOCK_SNAPSHOT_STATUS_KNOWN, - BT_CLOCK_SNAPSHOT_STATUS_UNKNOWN, + BT_CLOCK_SNAPSHOT_STATUS_OK = 0, + BT_CLOCK_SNAPSHOT_STATUS_OVERFLOW = -75, }; extern const bt_clock_class *bt_clock_snapshot_borrow_clock_class_const( @@ -47,7 +52,7 @@ extern const bt_clock_class *bt_clock_snapshot_borrow_clock_class_const( extern uint64_t bt_clock_snapshot_get_value( const bt_clock_snapshot *clock_snapshot); -extern int bt_clock_snapshot_get_ns_from_origin( +extern enum bt_clock_snapshot_status bt_clock_snapshot_get_ns_from_origin( const bt_clock_snapshot *clock_snapshot, int64_t *ns_from_origin); diff --git a/include/babeltrace/trace-ir/event-const.h b/include/babeltrace/trace-ir/event-const.h index 9aa4e692..00b58cab 100644 --- a/include/babeltrace/trace-ir/event-const.h +++ b/include/babeltrace/trace-ir/event-const.h @@ -27,7 +27,7 @@ * http://www.efficios.com/ctf */ -/* For enum bt_clock_snapshot_status */ +/* For enum bt_clock_snapshot_state */ #include /* For bt_event, bt_clock_snapshot, bt_event_class, bt_field, bt_packet */ @@ -58,7 +58,7 @@ 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 enum bt_clock_snapshot_status bt_event_borrow_default_clock_snapshot_const( +extern enum bt_clock_snapshot_state bt_event_borrow_default_clock_snapshot_const( const bt_event *event, const bt_clock_snapshot **clock_snapshot); diff --git a/include/babeltrace/trace-ir/packet-const.h b/include/babeltrace/trace-ir/packet-const.h index 877def81..52a0b305 100644 --- a/include/babeltrace/trace-ir/packet-const.h +++ b/include/babeltrace/trace-ir/packet-const.h @@ -31,7 +31,7 @@ /* For enum bt_property_availability */ #include -/* For enum bt_clock_snapshot_status */ +/* For enum bt_clock_snapshot_state */ #include /* @@ -56,12 +56,13 @@ const bt_field *bt_packet_borrow_context_field_const( const bt_packet *packet); extern -enum bt_clock_snapshot_status bt_packet_borrow_default_beginning_clock_snapshot_const( +enum bt_clock_snapshot_state +bt_packet_borrow_default_beginning_clock_snapshot_const( const bt_packet *packet, const bt_clock_snapshot **clock_snapshot); extern -enum bt_clock_snapshot_status bt_packet_borrow_default_end_clock_valeu_const( +enum bt_clock_snapshot_state bt_packet_borrow_default_end_clock_snapshot_const( const bt_packet *packet, const bt_clock_snapshot **clock_snapshot); diff --git a/lib/graph/message/inactivity.c b/lib/graph/message/inactivity.c index f61f1fdc..7a766677 100644 --- a/lib/graph/message/inactivity.c +++ b/lib/graph/message/inactivity.c @@ -99,13 +99,15 @@ void bt_message_inactivity_set_default_clock_snapshot( "%![msg-]+n, value=%" PRIu64, msg, value_cycles); } -const struct bt_clock_snapshot * +extern enum bt_clock_snapshot_state bt_message_inactivity_borrow_default_clock_snapshot_const( - const struct bt_message *msg) + const bt_message *msg, const bt_clock_snapshot **snapshot) { struct bt_message_inactivity *inactivity = (void *) msg; BT_ASSERT_PRE_NON_NULL(msg, "Message"); + BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)"); BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_INACTIVITY); - return inactivity->default_cs; + *snapshot = inactivity->default_cs; + return BT_CLOCK_SNAPSHOT_STATE_KNOWN; } diff --git a/lib/graph/message/stream.c b/lib/graph/message/stream.c index d2483b4b..fe35f1f6 100644 --- a/lib/graph/message/stream.c +++ b/lib/graph/message/stream.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -127,14 +128,17 @@ void bt_message_stream_end_set_default_clock_snapshot( "value=%" PRIu64, value_cycles); } -struct bt_clock_snapshot *bt_message_stream_end_borrow_default_clock_snapshot( - struct bt_message *msg) +enum bt_clock_snapshot_state +bt_message_stream_end_borrow_default_clock_snapshot_const( + const bt_message *msg, const bt_clock_snapshot **snapshot) { struct bt_message_stream_end *stream_end = (void *) msg; BT_ASSERT_PRE_NON_NULL(msg, "Message"); + BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)"); BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_END); - return stream_end->default_cs; + *snapshot = stream_end->default_cs; + return BT_CLOCK_SNAPSHOT_STATE_KNOWN; } static @@ -229,12 +233,15 @@ void bt_message_stream_beginning_set_default_clock_snapshot( "value=%" PRIu64, value_cycles); } -struct bt_clock_snapshot *bt_message_stream_beginning_borrow_default_clock_snapshot( - struct bt_message *msg) +enum bt_clock_snapshot_state +bt_message_stream_beginning_borrow_default_clock_snapshot_const( + const bt_message *msg, const bt_clock_snapshot **snapshot) { - struct bt_message_stream_beginning *stream_begin = (void *) msg; + struct bt_message_stream_beginning *stream_beginning = (void *) msg; BT_ASSERT_PRE_NON_NULL(msg, "Message"); - BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_BEGINNING); - return stream_begin->default_cs; + BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)"); + BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_END); + *snapshot = stream_beginning->default_cs; + return BT_CLOCK_SNAPSHOT_STATE_KNOWN; } diff --git a/lib/trace-ir/clock-snapshot.c b/lib/trace-ir/clock-snapshot.c index 7dcf2893..792b3fc0 100644 --- a/lib/trace-ir/clock-snapshot.c +++ b/lib/trace-ir/clock-snapshot.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -142,10 +143,12 @@ uint64_t bt_clock_snapshot_get_value(const struct bt_clock_snapshot *clock_snaps return clock_snapshot->value_cycles; } -int bt_clock_snapshot_get_ns_from_origin(const struct bt_clock_snapshot *clock_snapshot, +enum bt_clock_snapshot_status bt_clock_snapshot_get_ns_from_origin( + const struct bt_clock_snapshot *clock_snapshot, int64_t *ret_value_ns) { - int ret = 0; + int ret = BT_CLOCK_SNAPSHOT_STATUS_OK; + BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot"); BT_ASSERT_PRE_NON_NULL(ret_value_ns, "Value (ns) (output)"); BT_ASSERT_PRE(clock_snapshot->is_set, @@ -155,7 +158,7 @@ int bt_clock_snapshot_get_ns_from_origin(const struct bt_clock_snapshot *clock_s BT_LIB_LOGD("Clock snapshot, once converted to nanoseconds from origin, " "overflows the signed 64-bit integer range: " "%![cs-]+k", clock_snapshot); - ret = -1; + ret = BT_CLOCK_SNAPSHOT_STATUS_OVERFLOW; goto end; } diff --git a/lib/trace-ir/event.c b/lib/trace-ir/event.c index 1b3a085f..8bbb1fca 100644 --- a/lib/trace-ir/event.c +++ b/lib/trace-ir/event.c @@ -349,14 +349,14 @@ void bt_event_set_default_clock_snapshot(struct bt_event *event, "value=%" PRIu64, event, value_cycles); } -enum bt_clock_snapshot_status bt_event_borrow_default_clock_snapshot_const( +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_STATUS_KNOWN; + return BT_CLOCK_SNAPSHOT_STATE_KNOWN; } struct bt_packet *bt_event_borrow_packet(struct bt_event *event) diff --git a/lib/trace-ir/packet.c b/lib/trace-ir/packet.c index 41bd4119..501a8249 100644 --- a/lib/trace-ir/packet.c +++ b/lib/trace-ir/packet.c @@ -424,14 +424,14 @@ void bt_packet_set_default_beginning_clock_snapshot(struct bt_packet *packet, "%![packet-]+a, value=%" PRIu64, packet, value_cycles); } -enum bt_clock_snapshot_status bt_packet_borrow_default_beginning_clock_snapshot( +enum bt_clock_snapshot_state bt_packet_borrow_default_beginning_clock_snapshot( const struct bt_packet *packet, const struct bt_clock_snapshot **clock_snapshot) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot (output)"); *clock_snapshot = packet->default_beginning_cs; - return BT_CLOCK_SNAPSHOT_STATUS_KNOWN; + return BT_CLOCK_SNAPSHOT_STATE_KNOWN; } void bt_packet_set_default_end_clock_snapshot(struct bt_packet *packet, @@ -456,14 +456,14 @@ void bt_packet_set_default_end_clock_snapshot(struct bt_packet *packet, "%![packet-]+a, value=%" PRIu64, packet, value_cycles); } -enum bt_clock_snapshot_status bt_packet_borrow_default_end_clock_snapshot( +enum bt_clock_snapshot_state bt_packet_borrow_default_end_clock_snapshot( const struct bt_packet *packet, const struct bt_clock_snapshot **clock_snapshot) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot (output)"); *clock_snapshot = packet->default_end_cs; - return BT_CLOCK_SNAPSHOT_STATUS_KNOWN; + return BT_CLOCK_SNAPSHOT_STATE_KNOWN; } enum bt_property_availability bt_packet_get_discarded_event_counter_snapshot( diff --git a/lib/trace-ir/stream-class.c b/lib/trace-ir/stream-class.c index 9b3dd621..f8dd5999 100644 --- a/lib/trace-ir/stream-class.c +++ b/lib/trace-ir/stream-class.c @@ -597,7 +597,7 @@ void bt_stream_class_set_packets_have_default_end_clock_snapshot( bt_bool bt_stream_class_default_clock_is_always_known( const struct bt_stream_class *stream_class) { - /* BT_CLOCK_SNAPSHOT_STATUS_UNKNOWN is not supported as of 2.0 */ + /* BT_CLOCK_SNAPSHOT_STATE_UNKNOWN is not supported as of 2.0 */ return BT_TRUE; } diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index cdbbc1b6..3661a64a 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -82,10 +82,10 @@ void print_timestamp_cycles(struct pretty_component *pretty, { const bt_clock_snapshot *clock_snapshot; uint64_t cycles; - enum bt_clock_snapshot_status cv_status; + enum bt_clock_snapshot_state cs_state; - cv_status = bt_event_borrow_default_clock_snapshot_const(event, &clock_snapshot); - if (cv_status != BT_CLOCK_SNAPSHOT_STATUS_KNOWN || !clock_snapshot) { + 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; } @@ -223,7 +223,7 @@ int print_event_timestamp(struct pretty_component *pretty, const bt_stream *stream = NULL; const bt_stream_class *stream_class = NULL; const bt_clock_snapshot *clock_snapshot = NULL; - enum bt_clock_snapshot_status cv_status; + enum bt_clock_snapshot_state cs_state; stream = bt_event_borrow_stream_const(event); if (!stream) { @@ -237,9 +237,9 @@ int print_event_timestamp(struct pretty_component *pretty, goto end; } - cv_status = bt_event_borrow_default_clock_snapshot_const(event, + cs_state = bt_event_borrow_default_clock_snapshot_const(event, &clock_snapshot); - if (cv_status != BT_CLOCK_SNAPSHOT_STATUS_KNOWN || !clock_snapshot) { + if (cs_state != BT_CLOCK_SNAPSHOT_STATE_KNOWN || !clock_snapshot) { /* No default clock value: skip the timestamp without an error */ goto end; } @@ -256,7 +256,7 @@ int print_event_timestamp(struct pretty_component *pretty, print_timestamp_cycles(pretty, event); } else { clock_snapshot = NULL; - cv_status = bt_event_borrow_default_clock_snapshot_const(event, + cs_state = bt_event_borrow_default_clock_snapshot_const(event, &clock_snapshot); print_timestamp_wall(pretty, clock_snapshot); } diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index 077a8f8d..82344b72 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -608,7 +608,7 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp, int ret = 0; const unsigned char *cc_uuid; const char *cc_name; - enum bt_clock_snapshot_status cv_status = BT_CLOCK_SNAPSHOT_STATUS_KNOWN; + enum bt_clock_snapshot_state cs_state = BT_CLOCK_SNAPSHOT_STATE_KNOWN; BT_ASSERT(msg); BT_ASSERT(ts_ns); @@ -622,14 +622,14 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp, case BT_MESSAGE_TYPE_EVENT: event = bt_message_event_borrow_event_const(msg); BT_ASSERT(event); - cv_status = bt_event_borrow_default_clock_snapshot_const(event, + cs_state = bt_event_borrow_default_clock_snapshot_const(event, &clock_snapshot); break; case BT_MESSAGE_TYPE_INACTIVITY: - clock_snapshot = + cs_state = bt_message_inactivity_borrow_default_clock_snapshot_const( - msg); + msg, &clock_snapshot); break; default: /* All the other messages have a higher priority */ @@ -638,7 +638,7 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp, goto end; } - if (cv_status != BT_CLOCK_SNAPSHOT_STATUS_KNOWN) { + if (cs_state != BT_CLOCK_SNAPSHOT_STATE_KNOWN) { BT_LOGE_STR("Unsupported unknown clock snapshot."); ret = -1; goto end; -- 2.34.1