From: Simon Marchi Date: Tue, 7 May 2024 20:41:55 +0000 (-0400) Subject: lib: add stream class UID property X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=adb764122455c86448e810c5b2ddd7c0591eb49f;p=babeltrace.git lib: add stream class UID property Add a UID property to stream class objects. This is needed to support CTF 2. Philippe updated the documentation. Change-Id: Iac6f88ada28f0e97cf3082fd753df0867cb772d0 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/10696 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12722 --- diff --git a/include/babeltrace2/trace-ir/stream-class.h b/include/babeltrace2/trace-ir/stream-class.h index 251f220d..30a147eb 100644 --- a/include/babeltrace2/trace-ir/stream-class.h +++ b/include/babeltrace2/trace-ir/stream-class.h @@ -198,6 +198,21 @@ A stream class has the following properties: Use bt_stream_class_set_name() and bt_stream_class_get_name(). +
+ \anchor api-tir-stream-cls-prop-uid + \bt_dt_opt UID + (only available when the parent \bt_trace_cls was created + from a \bt_comp which belongs to a trace processing \bt_graph + with the effective \bt_mip version 1) +
+
+ Unique identifier + (UID) of the stream class. + + Use bt_stream_class_set_uid() and + bt_stream_class_get_uid(). +
+
\anchor api-tir-stream-cls-prop-def-clock-cls \bt_dt_opt Default clock class @@ -519,6 +534,9 @@ On success, the returned stream class has the following property values: \ref api-tir-stream-cls-prop-name "Name" \em None + + \bt_mip version 1: \ref api-tir-stream-cls-prop-uid "UID" + \em None \ref api-tir-stream-cls-prop-def-clock-cls "Default clock class" \em None @@ -613,6 +631,9 @@ On success, the returned stream class has the following property values: \ref api-tir-stream-cls-prop-name "Name" \em None + + \bt_mip version 1: \ref api-tir-stream-cls-prop-uid "UID" + \em None \ref api-tir-stream-cls-prop-def-clock-cls "Default clock class" \em None @@ -1004,6 +1025,82 @@ If \bt_p{stream_class} has no name, this function returns \c NULL. extern const char *bt_stream_class_get_name( const bt_stream_class *stream_class) __BT_NOEXCEPT; +/*! +@brief + Status codes for bt_stream_class_set_uid(). +*/ +typedef enum bt_stream_class_set_uid_status { + /*! + @brief + Success. + */ + BT_STREAM_CLASS_SET_UID_STATUS_OK = __BT_FUNC_STATUS_OK, + + /*! + @brief + Out of memory. + */ + BT_STREAM_CLASS_SET_UID_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, +} bt_stream_class_set_uid_status; + +/*! +@brief + Sets the + unique identifier (UID) + of the stream class \bt_p{stream_class} to + a copy of \bt_p{uid}. + +See the \ref api-tir-stream-cls-prop-uid "UID" property. + +@param[in] stream_class + Stream class of which to set the UID to \bt_p{uid}. +@param[in] name + New UID of \bt_p{stream_class} (copied). + +@retval #BT_STREAM_CLASS_SET_UID_STATUS_OK + Success. +@retval #BT_STREAM_CLASS_SET_UID_STATUS_MEMORY_ERROR + Out of memory. + +@bt_pre_not_null{stream_class} +@bt_pre_hot{stream_class} +@bt_pre_stream_cls_with_mip{stream_class, 1} +@bt_pre_not_null{uid} + +@sa bt_stream_class_get_uid() — + Returns the UID of a stream class. +*/ +extern bt_stream_class_set_uid_status bt_stream_class_set_uid( + bt_stream_class *stream_class, const char *uid) __BT_NOEXCEPT; + +/*! +@brief + Returns the UID of the stream class \bt_p{stream_class}. + +See the \ref api-tir-stream-cls-prop-uid "UID" property. + +If \bt_p{stream_class} has no UID, this function returns \c NULL. + +@param[in] stream_class + Stream class of which to get the UID. + +@returns + @parblock + UID of \bt_p{stream_class}, or \c NULL if none. + + The returned pointer remains valid as long as \bt_p{stream_class} + is not modified. + @endparblock + +@bt_pre_not_null{stream_class} +@bt_pre_stream_cls_with_mip{stream_class, 1} + +@sa bt_stream_class_set_uid() — + Sets the UID of a stream class. +*/ +extern const char *bt_stream_class_get_uid( + const bt_stream_class *stream_class) __BT_NOEXCEPT; + /*! @brief Status codes for bt_stream_class_set_default_clock_class(). diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index e49b5e73..04867569 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -647,6 +647,10 @@ static inline void format_stream_class(char **buf_ch, bool extended, BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class->name)); } + if (stream_class->uid) { + BUF_APPEND(", %suid=\"%s\"", PRFIELD(stream_class->uid)); + } + if (!extended) { return; } diff --git a/src/lib/trace-ir/stream-class.c b/src/lib/trace-ir/stream-class.c index 152ae909..9f1d2dd5 100644 --- a/src/lib/trace-ir/stream-class.c +++ b/src/lib/trace-ir/stream-class.c @@ -49,6 +49,7 @@ void destroy_stream_class(struct bt_object *obj) g_free(stream_class->ns); g_free(stream_class->name); + g_free(stream_class->uid); BT_LOGD_STR("Putting packet context field class."); BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc); BT_LOGD_STR("Putting event common context field class."); @@ -236,6 +237,30 @@ enum bt_stream_class_set_name_status bt_stream_class_set_name( return BT_FUNC_STATUS_OK; } +BT_EXPORT +const char *bt_stream_class_get_uid(const struct bt_stream_class *stream_class) +{ + BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); + BT_ASSERT_PRE_SC_MIP_VERSION_GE(stream_class, 1); + return stream_class->uid; +} + +BT_EXPORT +enum bt_stream_class_set_uid_status bt_stream_class_set_uid( + struct bt_stream_class *stream_class, + const char *uid) +{ + BT_ASSERT_PRE_NO_ERROR(); + BT_ASSERT_PRE_SC_NON_NULL(stream_class); + BT_ASSERT_PRE_NAME_NON_NULL(uid); + BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); + BT_ASSERT_PRE_SC_MIP_VERSION_GE(stream_class, 1); + g_free(stream_class->uid); + stream_class->uid = g_strdup(uid); + BT_LIB_LOGD("Set stream class's UID: %!+S", stream_class); + return BT_FUNC_STATUS_OK; +} + BT_EXPORT uint64_t bt_stream_class_get_id(const struct bt_stream_class *stream_class) { diff --git a/src/lib/trace-ir/stream-class.h b/src/lib/trace-ir/stream-class.h index c44c121b..17aa48a0 100644 --- a/src/lib/trace-ir/stream-class.h +++ b/src/lib/trace-ir/stream-class.h @@ -25,6 +25,7 @@ struct bt_stream_class { gchar *ns; gchar *name; + gchar *uid; uint64_t id; bool assigns_automatic_event_class_id;