From: Jonathan Rajotte Date: Tue, 13 Aug 2019 18:14:24 +0000 (-0400) Subject: Add metadata env fields X-Git-Tag: v2.12.0-pre~34 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3eb95be4200bdde975385f3acd00943ec3b78cc2;p=lttng-modules.git Add metadata env fields 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 Signed-off-by: Jonathan Rajotte Signed-off-by: Mathieu Desnoyers --- diff --git a/lttng-events.c b/lttng-events.c index a4570b7b..2e7670b8 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",