[lttng-dev] [PATCH lttng-modules 2/3] Add metadata env fields

Jonathan Rajotte jonathan.rajotte-julien at efficios.com
Tue Aug 13 14:14:24 EDT 2019


Add the following fields:

  - tracer_buffering_scheme
      The buffering scheme used by the tracer. lttng-modules sole
      buffering scheme is "global".
  - trace_name
      The name of the trace. Use the session name.

Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
---

This should also be backported to 2.11 allowing Babeltrace 2 to merge
traces from archived data (rotation) and output a trace with similar
lttng tree hierarchy.

---
 lttng-events.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/lttng-events.c b/lttng-events.c
index a4570b7..2e7670b 100644
--- a/lttng-events.c
+++ b/lttng-events.c
@@ -2478,6 +2478,60 @@ int64_t measure_clock_offset(void)
 	return offset;
 }
 
+static
+int print_escaped_ctf_string(struct lttng_session *session, const char *string)
+{
+	int ret;
+	size_t i;
+	char cur;
+
+	i = 0;
+	cur = string[i];
+	while (cur != '\0') {
+		switch (cur) {
+		case '\n':
+			ret = lttng_metadata_printf(session, "%s", "\\n");
+			break;
+		case '\\':
+		case '"':
+			ret = lttng_metadata_printf(session, "%c", '\\');
+			if (ret)
+				goto error;
+			/* We still print the current char */
+			/* Fallthrough */
+		default:
+			ret = lttng_metadata_printf(session, "%c", cur);
+			break;
+		}
+
+		if (ret)
+			goto error;
+
+		cur = string[++i];
+	}
+error:
+	return ret;
+}
+
+static
+int print_metadata_session_name(struct lttng_session *session)
+{
+	int ret;
+
+	ret = lttng_metadata_printf(session, "	trace_name = \"");
+	if (ret)
+		goto error;
+
+	ret = print_escaped_ctf_string(session, session->name);
+	if (ret)
+		goto error;
+
+	ret = lttng_metadata_printf(session, "\";\n");
+
+error:
+	return ret;
+}
+
 /*
  * Output metadata into this session's metadata buffers.
  * Must be called with sessions_mutex held.
@@ -2553,7 +2607,7 @@ int _lttng_session_metadata_statedump(struct lttng_session *session)
 		"	tracer_major = %d;\n"
 		"	tracer_minor = %d;\n"
 		"	tracer_patchlevel = %d;\n"
-		"};\n\n",
+		"	trace_buffering_scheme = \"global\";\n",
 		current->nsproxy->uts_ns->name.nodename,
 		utsname()->sysname,
 		utsname()->release,
@@ -2565,6 +2619,15 @@ int _lttng_session_metadata_statedump(struct lttng_session *session)
 	if (ret)
 		goto end;
 
+	ret = print_metadata_session_name(session);
+	if (ret)
+		goto end;
+
+	/* Close env */
+	ret = lttng_metadata_printf(session, "};\n\n");
+	if (ret)
+		goto end;
+
 	ret = lttng_metadata_printf(session,
 		"clock {\n"
 		"	name = \"%s\";\n",
-- 
2.17.1



More information about the lttng-dev mailing list