From 5af608b5d47c66aa0bc291a5049dc43c08b28f0c Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 7 May 2024 16:22:04 -0400 Subject: [PATCH] lib: add trace namespace property Add a new namespace property for trace objects. This is needed to support CTF 2. Philippe updated the documentation. Change-Id: I9c382879a3181aab2859a4c41cfbb21c4f6928aa Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/10695 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12721 --- include/babeltrace2/trace-ir/trace.h | 89 ++++++++++++++++++++++++++++ src/lib/assert-cond.h | 7 +++ src/lib/lib-logging.c | 4 ++ src/lib/trace-ir/trace.c | 24 ++++++++ src/lib/trace-ir/trace.h | 1 + 5 files changed, 125 insertions(+) diff --git a/include/babeltrace2/trace-ir/trace.h b/include/babeltrace2/trace-ir/trace.h index 33c05f8c..93a58db8 100644 --- a/include/babeltrace2/trace-ir/trace.h +++ b/include/babeltrace2/trace-ir/trace.h @@ -75,6 +75,20 @@ bt_trace_remove_destruction_listener(). A trace has the following properties:
+
+ \anchor api-tir-trace-prop-ns + \bt_dt_opt Namespace + (only available when the class of the trace was created + from a \bt_comp which belongs to a trace processing \bt_graph + with the effective \bt_mip version 1) +
+
+ Namespace of the trace. + + Use bt_trace_set_namespace() and + bt_trace_get_namespace(). +
+
\anchor api-tir-trace-prop-name \bt_dt_opt Name @@ -190,6 +204,9 @@ On success, the returned trace has the following property values: Property Value + + \bt_mip version 1: \ref api-tir-trace-prop-ns "Namespace" + \em None \ref api-tir-trace-prop-name "Name" \em None @@ -365,6 +382,78 @@ extern const bt_stream *bt_trace_borrow_stream_by_id_const( @{ */ +/*! +@brief + Status codes for bt_trace_set_namespace(). +*/ +typedef enum bt_trace_set_namespace_status { + /*! + @brief + Success. + */ + BT_TRACE_SET_NAMESPACE_STATUS_OK = __BT_FUNC_STATUS_OK, + + /*! + @brief + Out of memory. + */ + BT_TRACE_SET_NAMESPACE_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, +} bt_trace_set_namespace_status; + +/*! +@brief + Sets the namespace of the trace \bt_p{trace} to a copy of \bt_p{ns}. + +See the \ref api-tir-trace-prop-ns "namespace" property. + +@param[in] trace + Trace of which to set the namespace to \bt_p{ns}. +@param[in] name + New namespace of \bt_p{trace} (copied). + +@retval #BT_TRACE_SET_NAMESPACE_STATUS_OK + Success. +@retval #BT_TRACE_SET_NAMESPACE_STATUS_MEMORY_ERROR + Out of memory. + +@bt_pre_not_null{trace} +@bt_pre_hot{trace} +@bt_pre_trace_with_mip{trace, 1} +@bt_pre_not_null{ns} + +@sa bt_trace_get_namespace() — + Returns the namespace of a trace. +*/ +extern bt_trace_set_namespace_status bt_trace_set_namespace(bt_trace *trace, + const char *ns) __BT_NOEXCEPT; + +/*! +@brief + Returns the namespace of the trace \bt_p{trace}. + +See the \ref api-tir-trace-prop-ns "namespace" property. + +If \bt_p{trace} has no namespace, this function returns \c NULL. + +@param[in] trace + Trace of which to get the namespace. + +@returns + @parblock + Namespace of \bt_p{trace}, or \c NULL if none. + + The returned pointer remains valid as long as \bt_p{trace} + is not modified. + @endparblock + +@bt_pre_not_null{trace} +@bt_pre_stream_cls_with_mip{trace, 1} + +@sa bt_trace_set_namespace() — + Sets the namespace of a trace. +*/ +extern const char *bt_trace_get_namespace(const bt_trace *trace) __BT_NOEXCEPT; + /*! @brief Status codes for bt_trace_set_name(). diff --git a/src/lib/assert-cond.h b/src/lib/assert-cond.h index bdeee5d4..f73cfb97 100644 --- a/src/lib/assert-cond.h +++ b/src/lib/assert-cond.h @@ -1064,6 +1064,13 @@ #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 `_trace` is greater than or + * equal to `_val`. + */ +#define BT_ASSERT_PRE_TRACE_MIP_VERSION_GE(_trace, _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`. diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index 30cf4736..e49b5e73 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -592,6 +592,10 @@ static inline void format_trace(char **buf_ch, bool extended, { char tmp_prefix[TMP_PREFIX_LEN]; + if (trace->ns) { + BUF_APPEND(", %snamespace=\"%s\"", PRFIELD(trace->ns)); + } + if (trace->name) { BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name)); } diff --git a/src/lib/trace-ir/trace.c b/src/lib/trace-ir/trace.c index f6f973ad..1420ad07 100644 --- a/src/lib/trace-ir/trace.c +++ b/src/lib/trace-ir/trace.c @@ -105,6 +105,7 @@ void destroy_trace(struct bt_object *obj) } } + g_free(trace->ns); g_free(trace->name); if (trace->class->mip_version >= 1) { @@ -196,6 +197,29 @@ end: return trace; } +BT_EXPORT +const char *bt_trace_get_namespace(const struct bt_trace *trace) +{ + BT_ASSERT_PRE_DEV_TRACE_NON_NULL(trace); + BT_ASSERT_PRE_TRACE_MIP_VERSION_GE(trace, 1); + return trace->ns; +} + +BT_EXPORT +enum bt_trace_set_namespace_status bt_trace_set_namespace( + struct bt_trace *trace, const char *ns) +{ + BT_ASSERT_PRE_NO_ERROR(); + BT_ASSERT_PRE_TRACE_NON_NULL(trace); + BT_ASSERT_PRE_NAME_NON_NULL(ns); + BT_ASSERT_PRE_DEV_TRACE_HOT(trace); + BT_ASSERT_PRE_TRACE_MIP_VERSION_GE(trace, 1); + g_free(trace->ns); + trace->ns = g_strdup(ns); + BT_LIB_LOGD("Set trace's namespace: %!+t", trace); + return BT_FUNC_STATUS_OK; +} + BT_EXPORT const char *bt_trace_get_name(const struct bt_trace *trace) { diff --git a/src/lib/trace-ir/trace.h b/src/lib/trace-ir/trace.h index febf824d..090bb395 100644 --- a/src/lib/trace-ir/trace.h +++ b/src/lib/trace-ir/trace.h @@ -31,6 +31,7 @@ struct bt_trace { /* Owned by this */ struct bt_trace_class *class; + gchar *ns; gchar *name; union { -- 2.34.1