lib: add bt_clock_class_has_same_identity function
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 5 Sep 2023 14:59:59 +0000 (10:59 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10749
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12726

include/babeltrace2/trace-ir/clock-class.h
src/lib/trace-ir/clock-class.c

index a510ab62c06ea949ad79e3672c854927b694dfdf..14b44fac6c921d78b38ede8e6d4338dfb39daa5d 100644 (file)
@@ -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().
   </dd>
 
   <dt>
@@ -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().
   </dd>
 </dl>
 
@@ -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().
index 5f00e5e4ac5edf22a60ab710f405e52a90adbfac..fea35c8d62dda6b35cd818009d8d913bf176d6b3 100644 (file)
@@ -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)
This page took 0.025793 seconds and 4 git commands to generate.