lib: add trace namespace property
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 7 May 2024 20:22:04 +0000 (16:22 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10695
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12721

include/babeltrace2/trace-ir/trace.h
src/lib/assert-cond.h
src/lib/lib-logging.c
src/lib/trace-ir/trace.c
src/lib/trace-ir/trace.h

index 33c05f8c02d63ea7280bf210467b3c676b7d09be..93a58db891e45320a449c8aa3058630fcad95588 100644 (file)
@@ -75,6 +75,20 @@ bt_trace_remove_destruction_listener().
 A trace has the following properties:
 
 <dl>
+  <dt>
+    \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&nbsp;1)
+  </dt>
+  <dd>
+    Namespace of the trace.
+
+    Use bt_trace_set_namespace() and
+    bt_trace_get_namespace().
+  </dd>
+
   <dt>
     \anchor api-tir-trace-prop-name
     \bt_dt_opt Name
@@ -190,6 +204,9 @@ On success, the returned trace has the following property values:
   <tr>
     <th>Property
     <th>Value
+  <tr>
+    <td>\bt_mip version&nbsp;1: \ref api-tir-trace-prop-ns "Namespace"
+    <td>\em None
   <tr>
     <td>\ref api-tir-trace-prop-name "Name"
     <td>\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() &mdash;
+    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() &mdash;
+    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().
index bdeee5d49f1fea71a536df45d15bc28b17da6bed..f73cfb97ebd5592a4506d287607ba014e9feebd4 100644 (file)
 #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`.
index 30cf4736661d42b76f51498ca0d9707339f75c39..e49b5e735ab4e8eadd473a1af6f77e34d0c10d39 100644 (file)
@@ -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));
        }
index f6f973ad7e96c4de3010136247f5bf097815bf2e..1420ad07a1a01916bb9b3ad93fae5f28789e01e6 100644 (file)
@@ -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)
 {
index febf824d0696cd04219f021eb487f8ce84fbed88..090bb395a2cf0c345e05f4c854f6a107b74fed9e 100644 (file)
@@ -31,6 +31,7 @@ struct bt_trace {
        /* Owned by this */
        struct bt_trace_class *class;
 
+       gchar *ns;
        gchar *name;
 
        union {
This page took 0.027401 seconds and 4 git commands to generate.