From c33d46d29c33a9fe675cc333199098a4e3c51513 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 5 Sep 2023 10:59:59 -0400 Subject: [PATCH] lib: add bt_clock_class_has_same_identity function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add the bt_clock_class_has_same_identity utility function, which tells if two clock classes have the same identify. The criteria for whether two clock classes have the same identity are the same as in CTF 2: Two clock classes which satisfy all the following conditions are said to have the same identity: - Both share the same namespace property value, or both don’t have any namespace property. - Both have a name property and share the same value. - Both have a uid property and share the same value. Philippe updated the documentation. Change-Id: I55e4e13274d413a15873099045f14690feab09c4 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/10749 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12726 --- include/babeltrace2/trace-ir/clock-class.h | 39 ++++++++++++++++++++++ src/lib/trace-ir/clock-class.c | 30 +++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/include/babeltrace2/trace-ir/clock-class.h b/include/babeltrace2/trace-ir/clock-class.h index a510ab62..14b44fac 100644 --- a/include/babeltrace2/trace-ir/clock-class.h +++ b/include/babeltrace2/trace-ir/clock-class.h @@ -105,6 +105,9 @@ A clock's origin is one of, depending on its class: All stream clocks with a Unix epoch origin, whatever their \link api-tir-clock-cls-prop-iden identity\endlink, have a correlation. + + Check whether or not two clock classes share the same identity + with bt_clock_class_has_same_identity().
@@ -123,6 +126,9 @@ A clock's origin is one of, depending on its class: All stream clocks with the same custom origin, whatever their \link api-tir-clock-cls-prop-iden identity\endlink, have a correlation. + + Check whether or not two clock classes share the same identity + with bt_clock_class_has_same_identity(). @@ -1235,6 +1241,39 @@ If \bt_p{clock_class} has no UID, this function returns \c NULL. extern const char * bt_clock_class_get_uid(const bt_clock_class *clock_class) __BT_NOEXCEPT; +/*! +@brief + Returns whether or not the clock classes \bt_p{clock_class_a} + and \bt_p{clock_class_b} share the same identity. + +See the \ref api-tir-clock-cls-prop-iden "identity" property. + +Two clock classes share the same identity when all the following are +true: + +- They both have a name and a UID. + +- The values of their namespace, name, and UID property tuples + are the same. + +@param[in] clock_class_a + Clock class A. +@param[in] clock_class_b + Clock class B. + +@returns + #BT_TRUE if \bt_p{clock_class_a} and \bt_p{clock_class_b} share + the same identity + +@bt_pre_not_null{clock_class_a} +@bt_pre_clock_cls_with_mip{clock_class_a, 1} +@bt_pre_not_null{clock_class_b} +@bt_pre_clock_cls_with_mip{clock_class_b, 1} +*/ +extern bt_bool bt_clock_class_has_same_identity( + const bt_clock_class *clock_class_a, + const bt_clock_class *clock_class_b) __BT_NOEXCEPT; + /*! @brief Status codes for bt_clock_class_set_description(). diff --git a/src/lib/trace-ir/clock-class.c b/src/lib/trace-ir/clock-class.c index 5f00e5e4..fea35c8d 100644 --- a/src/lib/trace-ir/clock-class.c +++ b/src/lib/trace-ir/clock-class.c @@ -555,6 +555,36 @@ bt_clock_class_cycles_to_ns_from_origin( return ret; } +BT_EXPORT +bt_bool bt_clock_class_has_same_identity( + const bt_clock_class *cc_a, + const bt_clock_class *cc_b) +{ + BT_ASSERT_PRE_DEV_CLK_CLS_NON_NULL(cc_a); + BT_ASSERT_PRE_DEV_CLK_CLS_NON_NULL(cc_b); + BT_ASSERT_PRE_CC_MIP_VERSION_GE(cc_a, 1); + BT_ASSERT_PRE_CC_MIP_VERSION_GE(cc_b, 1); + + bt_bool is_same = BT_FALSE; + + if (g_strcmp0(cc_a->ns, cc_b->ns) != 0) { + goto end; + } + + if (!cc_a->name || !cc_b->name || strcmp(cc_a->name, cc_b->name) != 0) { + goto end; + } + + if (!cc_a->uid || !cc_b->uid || strcmp(cc_a->uid, cc_b->uid) != 0) { + goto end; + } + + is_same = BT_TRUE; + +end: + return is_same; +} + BT_EXPORT const struct bt_value *bt_clock_class_borrow_user_attributes_const( const struct bt_clock_class *clock_class) -- 2.34.1