From: Simon Marchi Date: Tue, 7 May 2024 20:42:24 +0000 (-0400) Subject: lib: add event class UID property X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=5ffd1fe9b4c1d906abe1e9cb1917f416b52e3ff1;p=babeltrace.git lib: add event class UID property Add a UID property to event class objects. This is needed to support CTF 2. Philippe updated the documentation. Signed-off-by: Simon Marchi Change-Id: Iae20d1d9835de2a04b02493c824e486e6fed7dcf Reviewed-on: https://review.lttng.org/c/babeltrace/+/10698 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12723 --- diff --git a/include/babeltrace2/trace-ir/event-class.h b/include/babeltrace2/trace-ir/event-class.h index c00ba9ac..5af0bb23 100644 --- a/include/babeltrace2/trace-ir/event-class.h +++ b/include/babeltrace2/trace-ir/event-class.h @@ -120,6 +120,21 @@ An event class has the following properties: Use bt_event_class_set_name() and bt_event_class_get_name(). +
+ \anchor api-tir-ev-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 event class. + + Use bt_event_class_set_uid() and + bt_event_class_get_uid(). +
+
\anchor api-tir-ev-cls-prop-log-lvl \bt_dt_opt Log level
Log level of the event class. @@ -241,6 +256,9 @@ On success, the returned event class has the following property values: \ref api-tir-ev-cls-prop-name "Name" \em None + + \bt_mip version 1: \ref api-tir-ev-cls-prop-uid "UID" + \em None \ref api-tir-ev-cls-prop-log-lvl "Log level" \em None @@ -311,6 +329,9 @@ On success, the returned event class has the following property values: \ref api-tir-ev-cls-prop-name "Name" \em None + + \bt_mip version 1: \ref api-tir-ev-cls-prop-uid "UID" + \em None \ref api-tir-ev-cls-prop-log-lvl "Log level" \em None @@ -537,6 +558,82 @@ See the \ref api-tir-ev-cls-prop-name "name" property. extern bt_event_class_set_name_status bt_event_class_set_name( bt_event_class *event_class, const char *name) __BT_NOEXCEPT; +/*! +@brief + Status codes for bt_event_class_set_uid(). +*/ +typedef enum bt_event_class_set_uid_status { + /*! + @brief + Success. + */ + BT_EVENT_CLASS_SET_UID_STATUS_OK = __BT_FUNC_STATUS_OK, + + /*! + @brief + Out of memory. + */ + BT_EVENT_CLASS_SET_UID_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, +} bt_event_class_set_uid_status; + +/*! +@brief + Sets the + unique identifier (UID) + of the stream class \bt_p{event_class} to + a copy of \bt_p{uid}. + +See the \ref api-tir-ev-cls-prop-uid "UID" property. + +@param[in] event_class + Event class of which to set the UID to \bt_p{uid}. +@param[in] name + New UID of \bt_p{event_class} (copied). + +@retval #BT_EVENT_CLASS_SET_UID_STATUS_OK + Success. +@retval #BT_EVENT_CLASS_SET_UID_STATUS_MEMORY_ERROR + Out of memory. + +@bt_pre_not_null{event_class} +@bt_pre_hot{event_class} +@bt_pre_ev_cls_with_mip{event_class, 1} +@bt_pre_not_null{uid} + +@sa bt_event_class_get_uid() — + Returns the UID of an event class. +*/ +extern bt_event_class_set_uid_status bt_event_class_set_uid( + bt_event_class *event_class, const char *uid) __BT_NOEXCEPT; + +/*! +@brief + Returns the UID of the event class \bt_p{event_class}. + +See the \ref api-tir-ev-cls-prop-uid "UID" property. + +If \bt_p{event_class} has no UID, this function returns \c NULL. + +@param[in] event_class + Event class of which to get the UID. + +@returns + @parblock + UID of \bt_p{event_class}, or \c NULL if none. + + The returned pointer remains valid as long as \bt_p{event_class} + is not modified. + @endparblock + +@bt_pre_not_null{event_class} +@bt_pre_ev_cls_with_mip{event_class, 1} + +@sa bt_event_class_set_uid() — + Sets the UID of an event class. +*/ +extern const char * +bt_event_class_get_uid(const bt_event_class *event_class) __BT_NOEXCEPT; + /*! @brief Returns the name of the event class \bt_p{event_class}. diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index 04867569..2aafcced 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -713,6 +713,10 @@ static inline void format_event_class(char **buf_ch, bool extended, BUF_APPEND(", %sname=\"%s\"", PRFIELD(event_class->name)); } + if (event_class->uid) { + BUF_APPEND(", %suid=\"%s\"", PRFIELD(event_class->uid)); + } + if (!extended) { return; } diff --git a/src/lib/trace-ir/event-class.c b/src/lib/trace-ir/event-class.c index 48f39fef..3a8892f9 100644 --- a/src/lib/trace-ir/event-class.c +++ b/src/lib/trace-ir/event-class.c @@ -43,6 +43,7 @@ void destroy_event_class(struct bt_object *obj) g_free(event_class->ns); g_free(event_class->name); + g_free(event_class->uid); g_free(event_class->emf_uri); BT_LOGD_STR("Putting context field class."); BT_OBJECT_PUT_REF_AND_RESET(event_class->specific_context_fc); @@ -209,6 +210,29 @@ enum bt_event_class_set_name_status bt_event_class_set_name( return BT_FUNC_STATUS_OK; } +BT_EXPORT +const char *bt_event_class_get_uid(const struct bt_event_class *event_class) +{ + BT_ASSERT_PRE_DEV_EC_NON_NULL(event_class); + BT_ASSERT_PRE_EC_MIP_VERSION_GE(event_class, 1); + return event_class->uid; +} + +BT_EXPORT +enum bt_event_class_set_uid_status bt_event_class_set_uid( + struct bt_event_class *event_class, const char *uid) +{ + BT_ASSERT_PRE_NO_ERROR(); + BT_ASSERT_PRE_EC_NON_NULL(event_class); + BT_ASSERT_PRE_EC_MIP_VERSION_GE(event_class, 1); + BT_ASSERT_PRE_NAME_NON_NULL(uid); + BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(event_class); + g_free(event_class->uid); + event_class->uid = g_strdup(uid); + BT_LIB_LOGD("Set event class's UID: %!+E", event_class); + return BT_FUNC_STATUS_OK; +} + BT_EXPORT uint64_t bt_event_class_get_id(const struct bt_event_class *event_class) { diff --git a/src/lib/trace-ir/event-class.h b/src/lib/trace-ir/event-class.h index 815a607d..ad383495 100644 --- a/src/lib/trace-ir/event-class.h +++ b/src/lib/trace-ir/event-class.h @@ -31,6 +31,7 @@ struct bt_event_class { gchar *ns; gchar *name; + gchar *uid; uint64_t id; struct bt_property_uint log_level;