From 07c465ea11e26b26af7e0c8baec2bfd05ece5946 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 7 May 2024 16:01:42 -0400 Subject: [PATCH] lib: add namespace property to event classes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add the namespace property to event classes, with the intent to support namespace properties on event record classes in CTF2‑SPEC‑2.0 [1]. Copy everything from the existing name property, and rename it to "namespace." Both new public functions have a `MIP >= 1` pre-condition check. Philippe updated the documentation. [1] https://diamon.org/ctf/CTF2-SPEC-2.0.html Change-Id: I644446087b6071f2ccc70027b079615f3a33a2a7 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/7381 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12689 --- doc/api/libbabeltrace2/Doxyfile.in | 1 + include/babeltrace2/trace-ir/event-class.h | 94 ++++++++++++++++++++++ src/lib/assert-cond.h | 10 +++ src/lib/lib-logging.c | 7 +- src/lib/trace-ir/event-class.c | 24 ++++++ src/lib/trace-ir/event-class.h | 1 + 6 files changed, 135 insertions(+), 2 deletions(-) diff --git a/doc/api/libbabeltrace2/Doxyfile.in b/doc/api/libbabeltrace2/Doxyfile.in index a18353a1..5fb8ad29 100644 --- a/doc/api/libbabeltrace2/Doxyfile.in +++ b/doc/api/libbabeltrace2/Doxyfile.in @@ -133,6 +133,7 @@ ALIASES += bt_pre_field_with_mip{2}="@pre The class of \bt_p{\1} ALIASES += bt_pre_trace_with_mip{2}="@pre The \link api-tir-trace-cls class\endlink of \bt_p{\1} was created from a \bt_comp which belongs to a trace processing \bt_graph with the effective \bt_mip version \2." ALIASES += bt_pre_clock_cls_with_mip{2}="@pre \bt_p{\1} was created from a \bt_comp which belongs to a trace processing \bt_graph with the effective \bt_mip version \2." ALIASES += bt_pre_stream_cls_with_mip{2}="@pre \bt_p{\1} was created from a \bt_trace_cls which was created from a \bt_comp which belongs to a trace processing \bt_graph with the effective \bt_mip version \2." +ALIASES += bt_pre_ev_cls_with_mip{2}="@pre The parent \bt_trace_cls of \bt_p{\1} was created from a \bt_comp which belongs to a trace processing \bt_graph with the effective \bt_mip version \2." # Aliases: field class object types: singular ALIASES += bt_fc="\link api-tir-fc field class\endlink" diff --git a/include/babeltrace2/trace-ir/event-class.h b/include/babeltrace2/trace-ir/event-class.h index f4e815d5..c00ba9ac 100644 --- a/include/babeltrace2/trace-ir/event-class.h +++ b/include/babeltrace2/trace-ir/event-class.h @@ -99,6 +99,20 @@ An event class has the following properties: Get an event class's numeric ID with bt_event_class_get_id(). +
+ \anchor api-tir-ev-cls-prop-ns + \bt_dt_opt Namespace + (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) +
+
+ Namespace of the event class. + + Use bt_event_class_set_namespace() and + bt_event_class_get_namespace(). +
+
\anchor api-tir-ev-cls-prop-name \bt_dt_opt Name
Name of the event class. @@ -221,6 +235,9 @@ On success, the returned event class has the following property values: \ref api-tir-ev-cls-prop-id "Numeric ID" Automatically assigned by \bt_p{stream_class} + + \bt_mip version 1: \ref api-tir-ev-cls-prop-ns "namespace" + \em None \ref api-tir-ev-cls-prop-name "Name" \em None @@ -288,6 +305,9 @@ On success, the returned event class has the following property values: \ref api-tir-ev-cls-prop-id "Numeric ID" \bt_p{id} + + \bt_mip version 1: \ref api-tir-ev-cls-prop-ns "namespace" + \em None \ref api-tir-ev-cls-prop-name "Name" \em None @@ -398,6 +418,80 @@ See the \ref api-tir-ev-cls-prop-id "numeric ID" property. extern uint64_t bt_event_class_get_id( const bt_event_class *event_class) __BT_NOEXCEPT; +/*! +@brief + Status codes for bt_event_class_set_namespace(). +*/ +typedef enum bt_event_class_set_namespace_status { + /*! + @brief + Success. + */ + BT_EVENT_CLASS_SET_NAMESPACE_STATUS_OK = __BT_FUNC_STATUS_OK, + + /*! + @brief + Out of memory. + */ + BT_EVENT_CLASS_SET_NAMESPACE_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, +} bt_event_class_set_namespace_status; + +/*! +@brief + Sets the namespace of the event class \bt_p{event_class} to + a copy of \bt_p{ns}. + +See the \ref api-tir-ev-cls-prop-ns "namespace" property. + +@param[in] event_class + Event class of which to set the namespace to \bt_p{ns}. +@param[in] name + New namespace of \bt_p{event_class} (copied). + +@retval #BT_EVENT_CLASS_SET_NAMESPACE_STATUS_OK + Success. +@retval #BT_EVENT_CLASS_SET_NAMESPACE_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{ns} + +@sa bt_event_class_get_namespace() — + Returns the namespace of an event class. +*/ +extern bt_event_class_set_namespace_status bt_event_class_set_namespace( + bt_event_class *event_class, const char *ns) __BT_NOEXCEPT; + +/*! +@brief + Returns the namespace of the event class \bt_p{event_class}. + +See the \ref api-tir-ev-cls-prop-ns "namespace" property. + +If \bt_p{event_class} has no namespace, this function returns \c NULL. + +@param[in] event_class + Event class of which to get the namespace. + +@returns + @parblock + Namespace 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_namespace() — + Sets the namespace of a event class. +*/ +extern const char * +bt_event_class_get_namespace(const bt_event_class *event_class) __BT_NOEXCEPT; + /*! @brief Status codes for bt_event_class_set_name(). diff --git a/src/lib/assert-cond.h b/src/lib/assert-cond.h index a666c52a..bdeee5d4 100644 --- a/src/lib/assert-cond.h +++ b/src/lib/assert-cond.h @@ -9,6 +9,7 @@ #define BABELTRACE_LIB_ASSERT_COND_H #include "assert-cond-base.h" +#include "trace-ir/trace-class.h" /* IWYU pragma: keep */ #include @@ -1072,6 +1073,15 @@ bt_stream_class_borrow_trace_class_inline(_stream_class), \ _val) +/* + * Asserts that the effective MIP version for `_event_class` is greater than or + * equal to `_val`. + */ +#define BT_ASSERT_PRE_EC_MIP_VERSION_GE(_event_class, _val) \ + BT_ASSERT_PRE_SC_MIP_VERSION_GE( \ + bt_event_class_borrow_stream_class_inline(_event_class), \ + _val) + /* * Asserts that the effective MIP version for `_field_class` is equal to `_val`. */ diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index 3342b739..f87a748f 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -697,9 +697,12 @@ static inline void format_event_class(char **buf_ch, bool extended, BUF_APPEND(", %sid=%" PRIu64, PRFIELD(event_class->id)); + if (event_class->ns) { + BUF_APPEND(", %snamespace=\"%s\"", PRFIELD(event_class->ns)); + } + if (event_class->name) { - BUF_APPEND(", %sname=\"%s\"", - PRFIELD(event_class->name)); + BUF_APPEND(", %sname=\"%s\"", PRFIELD(event_class->name)); } if (!extended) { diff --git a/src/lib/trace-ir/event-class.c b/src/lib/trace-ir/event-class.c index 12bb1120..48f39fef 100644 --- a/src/lib/trace-ir/event-class.c +++ b/src/lib/trace-ir/event-class.c @@ -41,6 +41,7 @@ void destroy_event_class(struct bt_object *obj) BT_LIB_LOGD("Destroying event class: %!+E", event_class); BT_OBJECT_PUT_REF_AND_RESET(event_class->user_attributes); + g_free(event_class->ns); g_free(event_class->name); g_free(event_class->emf_uri); BT_LOGD_STR("Putting context field class."); @@ -164,6 +165,29 @@ struct bt_event_class *bt_event_class_create_with_id( return create_event_class_with_id(stream_class, id); } +BT_EXPORT +const char *bt_event_class_get_namespace(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->ns; +} + +BT_EXPORT +enum bt_event_class_set_namespace_status bt_event_class_set_namespace( + struct bt_event_class *event_class, const char *ns) +{ + 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_NAMESPACE_NON_NULL(ns); + BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(event_class); + g_free(event_class->ns); + event_class->ns = g_strdup(ns); + BT_LIB_LOGD("Set event class's namespace: %!+E", event_class); + return BT_FUNC_STATUS_OK; +} + BT_EXPORT const char *bt_event_class_get_name(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 5e1d5071..815a607d 100644 --- a/src/lib/trace-ir/event-class.h +++ b/src/lib/trace-ir/event-class.h @@ -29,6 +29,7 @@ struct bt_event_class { /* Owned by this */ struct bt_value *user_attributes; + gchar *ns; gchar *name; uint64_t id; -- 2.34.1