From 2fc2de475df32f1a90dc9ad571c1f35b921c3816 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 7 May 2024 16:18:47 -0400 Subject: [PATCH] lib: add clock class namespace and UID properties Add the namespace and UID properties to clock class objects. This is needed to support CTF 2. Philippe updated the documentation. Change-Id: I9b6ee8f78581ca8ebfa8b1ceca0d1fe50178c1b3 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/10677 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12720 --- include/babeltrace2/trace-ir/clock-class.h | 149 +++++++++++++++++++++ src/lib/lib-logging.c | 8 ++ src/lib/trace-ir/clock-class.c | 50 +++++++ src/lib/trace-ir/clock-class.h | 2 + 4 files changed, 209 insertions(+) diff --git a/include/babeltrace2/trace-ir/clock-class.h b/include/babeltrace2/trace-ir/clock-class.h index c7f25fdb..1222547b 100644 --- a/include/babeltrace2/trace-ir/clock-class.h +++ b/include/babeltrace2/trace-ir/clock-class.h @@ -876,6 +876,80 @@ See the \ref api-tir-clock-cls-prop-origin "origin" property. extern const char *bt_clock_class_get_origin_uid( const bt_clock_class *clock_class) __BT_NOEXCEPT; +/*! +@brief + Status codes for bt_clock_class_set_namespace(). +*/ +typedef enum bt_clock_class_set_namespace_status { + /*! + @brief + Success. + */ + BT_CLOCK_CLASS_SET_NAMESPACE_STATUS_OK = __BT_FUNC_STATUS_OK, + + /*! + @brief + Out of memory. + */ + BT_CLOCK_CLASS_SET_NAMESPACE_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, +} bt_clock_class_set_namespace_status; + +/*! +@brief + Sets the namespace of the clock class \bt_p{clock_class} to + a copy of \bt_p{ns}. + +See the \ref api-tir-clock-cls-prop-iden "identity" property. + +@param[in] clock_class + Clock class of which to set the namespace to \bt_p{ns}. +@param[in] namespace + New namespace of \bt_p{clock_class} (copied). + +@retval #BT_CLOCK_CLASS_SET_NAMESPACE_STATUS_OK + Success. +@retval #BT_CLOCK_CLASS_SET_NAMESPACE_STATUS_MEMORY_ERROR + Out of memory. + +@bt_pre_not_null{clock_class} +@bt_pre_hot{clock_class} +@bt_pre_clock_cls_with_mip{clock_class, 1} +@bt_pre_not_null{namespace} + +@sa bt_clock_class_get_namespace() — + Returns the namespace of a clock class. +*/ +extern bt_clock_class_set_namespace_status bt_clock_class_set_namespace( + bt_clock_class *clock_class, const char *ns) __BT_NOEXCEPT; + +/*! +@brief + Returns the namespace of the clock class \bt_p{clock_class}. + +See the \ref api-tir-clock-cls-prop-iden "identity" property. + +If \bt_p{clock_class} has no namespace, this function returns \c NULL. + +@param[in] clock_class + Clock class of which to get the namespace. + +@returns + @parblock + Namespace of \bt_p{clock_class}, or \c NULL if none. + + The returned pointer remains valid as long as \bt_p{clock_class} + is not modified. + @endparblock + +@bt_pre_not_null{clock_class} +@bt_pre_clock_cls_with_mip{clock_class, 1} + +@sa bt_clock_class_set_namespace() — + Sets the namespace of a clock class. +*/ +extern const char *bt_clock_class_get_namespace( + const bt_clock_class *clock_class) __BT_NOEXCEPT; + /*! @brief Status codes for bt_clock_class_set_name(). @@ -948,6 +1022,81 @@ If \bt_p{clock_class} has no name, this function returns \c NULL. extern const char *bt_clock_class_get_name( const bt_clock_class *clock_class) __BT_NOEXCEPT; +/*! +@brief + Status codes for bt_clock_class_set_uid(). +*/ +typedef enum bt_clock_class_set_uid_status { + /*! + @brief + Success. + */ + BT_CLOCK_CLASS_SET_UID_STATUS_OK = __BT_FUNC_STATUS_OK, + + /*! + @brief + Out of memory. + */ + BT_CLOCK_CLASS_SET_UID_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, +} bt_clock_class_set_uid_status; + +/*! +@brief + Sets the + unique identifier + (UID) of the clock class \bt_p{clock_class} to a copy of \bt_p{uid}. + +See the \ref api-tir-clock-cls-prop-iden "identity" property. + +@param[in] clock_class + Clock class of which to set the UID to \bt_p{uid}. +@param[in] UID + New UID of \bt_p{clock_class} (copied). + +@retval #BT_CLOCK_CLASS_SET_UID_STATUS_OK + Success. +@retval #BT_CLOCK_CLASS_SET_UID_STATUS_MEMORY_ERROR + Out of memory. + +@bt_pre_not_null{clock_class} +@bt_pre_hot{clock_class} +@bt_pre_clock_cls_with_mip{clock_class, 1} +@bt_pre_not_null{uid} + +@sa bt_clock_class_get_uid() — + Returns the UID of a clock class. +*/ +extern bt_clock_class_set_uid_status bt_clock_class_set_uid( + bt_clock_class *clock_class, const char *uid) __BT_NOEXCEPT; + +/*! +@brief + Returns the UID of the clock class \bt_p{clock_class}. + +See the \ref api-tir-clock-cls-prop-iden "identity" property. + +If \bt_p{clock_class} has no UID, this function returns \c NULL. + +@param[in] clock_class + Clock class of which to get the UID. + +@returns + @parblock + UID of \bt_p{clock_class}, or \c NULL if none. + + The returned pointer remains valid as long as \bt_p{clock_class} + is not modified. + @endparblock + +@bt_pre_not_null{clock_class} +@bt_pre_clock_cls_with_mip{clock_class, 1} + +@sa bt_clock_class_set_uid() — + Sets the UID of a clock class. +*/ +extern const char * +bt_clock_class_get_uid(const bt_clock_class *clock_class) __BT_NOEXCEPT; + /*! @brief Status codes for bt_clock_class_set_description(). diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index f87a748f..30cf4736 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -884,10 +884,18 @@ static inline void format_clock_class(char **buf_ch, bool extended, { char tmp_prefix[TMP_PREFIX_LEN]; + if (clock_class->ns) { + BUF_APPEND(", %snamepace=\"%s\"", PRFIELD(clock_class->ns)); + } + if (clock_class->name) { BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name)); } + if (clock_class->uid) { + BUF_APPEND(", %suid=\"%s\"", PRFIELD(clock_class->uid)); + } + BUF_APPEND(", %sfreq=%" PRIu64, PRFIELD(clock_class->frequency)); if (!extended) { diff --git a/src/lib/trace-ir/clock-class.c b/src/lib/trace-ir/clock-class.c index 2939b5a8..bb75fb9c 100644 --- a/src/lib/trace-ir/clock-class.c +++ b/src/lib/trace-ir/clock-class.c @@ -69,7 +69,9 @@ void destroy_clock_class(struct bt_object *obj) BT_LIB_LOGD("Destroying clock class: %!+K", clock_class); BT_OBJECT_PUT_REF_AND_RESET(clock_class->user_attributes); + g_free(clock_class->ns); g_free(clock_class->name); + g_free(clock_class->uid); g_free(clock_class->description); free_clock_class_origin_data(clock_class); bt_object_pool_finalize(&clock_class->cs_pool); @@ -164,6 +166,30 @@ end: return clock_class; } +BT_EXPORT +const char *bt_clock_class_get_namespace( + const struct bt_clock_class *clock_class) +{ + BT_ASSERT_PRE_DEV_CLK_CLS_NON_NULL(clock_class); + BT_ASSERT_PRE_CC_MIP_VERSION_GE(clock_class, 1); + return clock_class->ns; +} + +BT_EXPORT +enum bt_clock_class_set_namespace_status bt_clock_class_set_namespace( + struct bt_clock_class *clock_class, const char *ns) +{ + BT_ASSERT_PRE_NO_ERROR(); + BT_ASSERT_PRE_CLK_CLS_NON_NULL(clock_class); + BT_ASSERT_PRE_NAME_NON_NULL(ns); + BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(clock_class); + BT_ASSERT_PRE_CC_MIP_VERSION_GE(clock_class, 1); + g_free(clock_class->ns); + clock_class->ns = g_strdup(ns); + BT_LIB_LOGD("Set clock class's namespace: %!+K", clock_class); + return BT_FUNC_STATUS_OK; +} + BT_EXPORT const char *bt_clock_class_get_name(const struct bt_clock_class *clock_class) { @@ -185,6 +211,30 @@ enum bt_clock_class_set_name_status bt_clock_class_set_name( return BT_FUNC_STATUS_OK; } +BT_EXPORT +const char *bt_clock_class_get_uid(const struct bt_clock_class *clock_class) +{ + BT_ASSERT_PRE_NO_ERROR(); + BT_ASSERT_PRE_DEV_CLK_CLS_NON_NULL(clock_class); + BT_ASSERT_PRE_CC_MIP_VERSION_GE(clock_class, 1); + return clock_class->uid; +} + +BT_EXPORT +enum bt_clock_class_set_uid_status bt_clock_class_set_uid( + struct bt_clock_class *clock_class, const char *uid) +{ + BT_ASSERT_PRE_NO_ERROR(); + BT_ASSERT_PRE_CLK_CLS_NON_NULL(clock_class); + BT_ASSERT_PRE_NAME_NON_NULL(uid); + BT_ASSERT_PRE_DEV_CLOCK_CLASS_HOT(clock_class); + BT_ASSERT_PRE_CC_MIP_VERSION_GE(clock_class, 1); + g_free(clock_class->uid); + clock_class->uid = g_strdup(uid); + BT_LIB_LOGD("Set clock class's UID: %!+K", clock_class); + return BT_FUNC_STATUS_OK; +} + BT_EXPORT const char *bt_clock_class_get_description( const struct bt_clock_class *clock_class) diff --git a/src/lib/trace-ir/clock-class.h b/src/lib/trace-ir/clock-class.h index bca58088..e4b88a1f 100644 --- a/src/lib/trace-ir/clock-class.h +++ b/src/lib/trace-ir/clock-class.h @@ -30,7 +30,9 @@ struct bt_clock_class { /* Owned by this */ struct bt_value *user_attributes; + gchar *ns; gchar *name; + gchar *uid; gchar *description; uint64_t frequency; -- 2.34.1