lib: add event class UID property
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 7 May 2024 20:42:24 +0000 (16:42 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
Add a UID property to event class objects.  This is needed to
support CTF 2.

Philippe updated the documentation.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Iae20d1d9835de2a04b02493c824e486e6fed7dcf
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10698
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12723

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

index c00ba9aceee99401cebd59607661bc1790d84560..5af0bb2382c77a5a6563a3bcb2803bbb7d04bf39 100644 (file)
@@ -120,6 +120,21 @@ An event class has the following properties:
     Use bt_event_class_set_name() and bt_event_class_get_name().
   </dd>
 
+  <dt>
+    \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&nbsp;1)
+  </dt>
+  <dd>
+    <a href="https://en.wikipedia.org/wiki/Unique_identifier">Unique identifier</a>
+    (UID) of the event class.
+
+    Use bt_event_class_set_uid() and
+    bt_event_class_get_uid().
+  </dd>
+
   <dt>\anchor api-tir-ev-cls-prop-log-lvl \bt_dt_opt Log level</dt>
   <dd>
     Log level of the event class.
@@ -241,6 +256,9 @@ On success, the returned event class has the following property values:
   <tr>
     <td>\ref api-tir-ev-cls-prop-name "Name"
     <td>\em None
+  <tr>
+    <td>\bt_mip version&nbsp;1: \ref api-tir-ev-cls-prop-uid "UID"
+    <td>\em None
   <tr>
     <td>\ref api-tir-ev-cls-prop-log-lvl "Log level"
     <td>\em None
@@ -311,6 +329,9 @@ On success, the returned event class has the following property values:
   <tr>
     <td>\ref api-tir-ev-cls-prop-name "Name"
     <td>\em None
+  <tr>
+    <td>\bt_mip version&nbsp;1: \ref api-tir-ev-cls-prop-uid "UID"
+    <td>\em None
   <tr>
     <td>\ref api-tir-ev-cls-prop-log-lvl "Log level"
     <td>\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
+    <a href="https://en.wikipedia.org/wiki/Unique_identifier">unique identifier</a> (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() &mdash;
+    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() &mdash;
+    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}.
index 0486756989e0f64fa78282322e5c1068b16e87b1..2aafccedb8e9d948c1b795936c2fc6130125a15d 100644 (file)
@@ -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;
        }
index 48f39fef967114912d34dc409e1e6fb674578343..3a8892f9a8f2af75706ed99cd65186a97ad3b8f2 100644 (file)
@@ -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)
 {
index 815a607d8a8ba007e8c0c6b56d70b4b4e6156c08..ad383495656a7c6fac38eea3b990b96cd744d3a1 100644 (file)
@@ -31,6 +31,7 @@ struct bt_event_class {
 
        gchar *ns;
        gchar *name;
+       gchar *uid;
 
        uint64_t id;
        struct bt_property_uint log_level;
This page took 0.027213 seconds and 4 git commands to generate.