From 2341f81f296cdc770238174970a59af071fc8eb5 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 7 May 2024 15:51:03 -0400 Subject: [PATCH] lib: add namespace property to stream classes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add the namespace property to stream classes, with the intent to support namespace properties on data stream 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: Ibdfc9c924fc6347f5020c5ba06f14a7737cbf76b Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/7380 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12688 --- doc/api/libbabeltrace2/Doxyfile.in | 1 + include/babeltrace2/trace-ir/stream-class.h | 94 +++++++++++++++++++++ src/lib/assert-cond.h | 17 +++- src/lib/lib-logging.c | 7 +- src/lib/trace-ir/stream-class.c | 26 ++++++ src/lib/trace-ir/stream-class.h | 1 + 6 files changed, 141 insertions(+), 5 deletions(-) diff --git a/doc/api/libbabeltrace2/Doxyfile.in b/doc/api/libbabeltrace2/Doxyfile.in index 64a4e89b..a18353a1 100644 --- a/doc/api/libbabeltrace2/Doxyfile.in +++ b/doc/api/libbabeltrace2/Doxyfile.in @@ -132,6 +132,7 @@ ALIASES += bt_pre_fc_with_mip{2}="@pre \bt_p{\1} was created from ALIASES += bt_pre_field_with_mip{2}="@pre The class of \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_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: field class object types: singular ALIASES += bt_fc="\link api-tir-fc field class\endlink" diff --git a/include/babeltrace2/trace-ir/stream-class.h b/include/babeltrace2/trace-ir/stream-class.h index e74d3cc3..251f220d 100644 --- a/include/babeltrace2/trace-ir/stream-class.h +++ b/include/babeltrace2/trace-ir/stream-class.h @@ -177,6 +177,20 @@ A stream class has the following properties: Get a stream class's numeric ID with bt_stream_class_get_id(). +
+ \anchor api-tir-stream-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 stream class. + + Use bt_stream_class_set_namespace() and + bt_stream_class_get_namespace(). +
+
\anchor api-tir-stream-cls-prop-name \bt_dt_opt Name
Name of the stream class. @@ -499,6 +513,9 @@ On success, the returned stream class has the following property values: \ref api-tir-stream-cls-prop-id "Numeric ID" Automatically assigned by \bt_p{trace_class} + + \bt_mip version 1: \ref api-tir-stream-cls-prop-ns "namespace" + \em None \ref api-tir-stream-cls-prop-name "Name" \em None @@ -590,6 +607,9 @@ On success, the returned stream class has the following property values: \ref api-tir-stream-cls-prop-id "Numeric ID" \bt_p{id} + + \bt_mip version 1: \ref api-tir-stream-cls-prop-ns "namespace" + \em None \ref api-tir-stream-cls-prop-name "Name" \em None @@ -838,6 +858,80 @@ See the \ref api-tir-stream-cls-prop-id "numeric ID" property. extern uint64_t bt_stream_class_get_id( const bt_stream_class *stream_class) __BT_NOEXCEPT; +/*! +@brief + Status codes for bt_stream_class_set_namespace(). +*/ +typedef enum bt_stream_class_set_namespace_status { + /*! + @brief + Success. + */ + BT_STREAM_CLASS_SET_NAMESPACE_STATUS_OK = __BT_FUNC_STATUS_OK, + + /*! + @brief + Out of memory. + */ + BT_STREAM_CLASS_SET_NAMESPACE_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, +} bt_stream_class_set_namespace_status; + +/*! +@brief + Sets the namespace of the stream class \bt_p{stream_class} to + a copy of \bt_p{ns}. + +See the \ref api-tir-stream-cls-prop-ns "namespace" property. + +@param[in] stream_class + Stream class of which to set the namespace to \bt_p{ns}. +@param[in] name + New namespace of \bt_p{stream_class} (copied). + +@retval #BT_STREAM_CLASS_SET_NAMESPACE_STATUS_OK + Success. +@retval #BT_STREAM_CLASS_SET_NAMESPACE_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{ns} + +@sa bt_stream_class_get_namespace() — + Returns the namespace of a stream class. +*/ +extern bt_stream_class_set_namespace_status bt_stream_class_set_namespace( + bt_stream_class *stream_class, const char *ns) __BT_NOEXCEPT; + +/*! +@brief + Returns the namespace of the stream class \bt_p{stream_class}. + +See the \ref api-tir-stream-cls-prop-ns "namespace" property. + +If \bt_p{stream_class} has no namespace, this function returns \c NULL. + +@param[in] stream_class + Stream class of which to get the namespace. + +@returns + @parblock + Namespace 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_namespace() — + Sets the namespace of a stream class. +*/ +extern const char *bt_stream_class_get_namespace( + const bt_stream_class *stream_class) __BT_NOEXCEPT; + /*! @brief Status codes for bt_stream_class_set_name(). diff --git a/src/lib/assert-cond.h b/src/lib/assert-cond.h index 368164dd..a666c52a 100644 --- a/src/lib/assert-cond.h +++ b/src/lib/assert-cond.h @@ -1063,13 +1063,24 @@ #define BT_ASSERT_PRE_TC_MIP_VERSION_GE(_trace_class, _val) \ BT_ASSERT_PRE_MIP_VERSION_GE((_trace_class)->mip_version, _val) +/* + * Asserts that the effective MIP version for `_stream_class` is greater than or + * equal to `_val`. + */ +#define BT_ASSERT_PRE_SC_MIP_VERSION_GE(_stream_class, _val) \ + BT_ASSERT_PRE_TC_MIP_VERSION_GE( \ + bt_stream_class_borrow_trace_class_inline(_stream_class), \ + _val) + /* * Asserts that the effective MIP version for `_field_class` is equal to `_val`. */ #define BT_ASSERT_PRE_FC_MIP_VERSION_EQ(_field_class, _val) \ BT_ASSERT_PRE_MIP_VERSION_EQ((_field_class)->mip_version, _val) -/* Asserts that the effective MIP version for `_field_class` is equal to `_val`. */ +/* + * Asserts that the effective MIP version for `_field_class` is equal to `_val`. + */ #define BT_ASSERT_PRE_DEV_FC_MIP_VERSION_EQ(_field_class, _val) \ BT_ASSERT_PRE_DEV_MIP_VERSION_EQ((_field_class)->mip_version, _val) @@ -1377,8 +1388,8 @@ #define _BT_ASSERT_PRE_NAMESPACE_NAME "Namespace" #define _BT_ASSERT_PRE_NAMESPACE_ID "namespace" -#define BT_ASSERT_PRE_NAMESPACE_NON_NULL(_name) \ - BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_NAMESPACE_ID, (_name), \ +#define BT_ASSERT_PRE_NAMESPACE_NON_NULL(_namespace) \ + BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_NAMESPACE_ID, (_namespace), \ _BT_ASSERT_PRE_NAMESPACE_NAME) #define _BT_ASSERT_PRE_DESCR_NAME "Description" diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index 91286458..3342b739 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -635,9 +635,12 @@ static inline void format_stream_class(char **buf_ch, bool extended, BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream_class->id)); + if (stream_class->ns) { + BUF_APPEND(", %snamespace=\"%s\"", PRFIELD(stream_class->ns)); + } + if (stream_class->name) { - BUF_APPEND(", %sname=\"%s\"", - PRFIELD(stream_class->name)); + BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class->name)); } if (!extended) { diff --git a/src/lib/trace-ir/stream-class.c b/src/lib/trace-ir/stream-class.c index 47e5e155..152ae909 100644 --- a/src/lib/trace-ir/stream-class.c +++ b/src/lib/trace-ir/stream-class.c @@ -47,6 +47,7 @@ void destroy_stream_class(struct bt_object *obj) stream_class->event_classes = NULL; } + g_free(stream_class->ns); g_free(stream_class->name); BT_LOGD_STR("Putting packet context field class."); BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc); @@ -188,6 +189,31 @@ const struct bt_trace_class *bt_stream_class_borrow_trace_class_const( return bt_stream_class_borrow_trace_class((void *) stream_class); } +BT_EXPORT +const char *bt_stream_class_get_namespace( + 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->ns; +} + +BT_EXPORT +enum bt_stream_class_set_namespace_status bt_stream_class_set_namespace( + struct bt_stream_class *stream_class, + const char *ns) +{ + BT_ASSERT_PRE_NO_ERROR(); + BT_ASSERT_PRE_SC_NON_NULL(stream_class); + BT_ASSERT_PRE_SC_MIP_VERSION_GE(stream_class, 1); + BT_ASSERT_PRE_NAMESPACE_NON_NULL(ns); + BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); + g_free(stream_class->ns); + stream_class->ns = g_strdup(ns); + BT_LIB_LOGD("Set stream class's namespace: %!+S", stream_class); + return BT_FUNC_STATUS_OK; +} + BT_EXPORT const char *bt_stream_class_get_name(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 7ebb1d02..c44c121b 100644 --- a/src/lib/trace-ir/stream-class.h +++ b/src/lib/trace-ir/stream-class.h @@ -23,6 +23,7 @@ struct bt_stream_class { /* Owned by this */ struct bt_value *user_attributes; + gchar *ns; gchar *name; uint64_t id; -- 2.34.1