From: Jonathan Rajotte Date: Thu, 14 Apr 2022 21:50:02 +0000 (-0400) Subject: CLI: Add `--trace-format` option to `create` command X-Git-Url: https://git.efficios.com/?p=deliverable%2Flttng-tools.git;a=commitdiff_plain;h=0ff3383bd63f627474f999cbc7cdb8f78c61cb59 CLI: Add `--trace-format` option to `create` command TODO: doc Signed-off-by: Jonathan Rajotte Change-Id: Ifcb37b7289e3b8a30a3f76fb515029fa46aa6905 --- diff --git a/src/bin/lttng/commands/create.cpp b/src/bin/lttng/commands/create.cpp index 64cf2b37c..68a1020a8 100644 --- a/src/bin/lttng/commands/create.cpp +++ b/src/bin/lttng/commands/create.cpp @@ -7,17 +7,19 @@ */ #define _LGPL_SOURCE +#include #include +#include #include +#include #include #include #include #include #include -#include -#include -#include #include +#include +#include #include @@ -37,6 +39,7 @@ static char *opt_url; static char *opt_ctrl_url; static char *opt_data_url; static char *opt_shm_path; +static char *opt_trace_format; static int opt_no_consumer; static int opt_no_output; static int opt_snapshot; @@ -75,6 +78,7 @@ static struct poptOption long_options[] = { {"snapshot", 0, POPT_ARG_VAL, &opt_snapshot, 1, 0, 0}, {"live", 0, POPT_ARG_INT | POPT_ARGFLAG_OPTIONAL, 0, OPT_LIVE_TIMER, 0, 0}, {"shm-path", 0, POPT_ARG_STRING, &opt_shm_path, 0, 0, 0}, + {"trace-format", 0, POPT_ARG_STRING, &opt_trace_format, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0} }; @@ -264,14 +268,52 @@ struct lttng_session_descriptor *create_session_descriptor(void) ret = spawn_relayd(pathname, 0); if (ret < 0) { - lttng_session_descriptor_destroy(descriptor); - descriptor = NULL; + goto error; } } } + + if (opt_trace_format) { + std::unordered_map> + factory = { + {"ctf1", lttng_trace_format_ctf_1_descriptor_create}, + {"ctf2", lttng_trace_format_ctf_2_descriptor_create}, + }; + + lttng_session_descriptor_status status; + lttng_trace_format_descriptor *trace_format_descriptor = nullptr; + std::string s_trace_format(opt_trace_format); + + auto it = factory.find(s_trace_format); + + if (it == factory.end()) { + ERR("Unknown trace format"); + goto error; + } + + trace_format_descriptor = it->second(); + if (trace_format_descriptor == nullptr) { + ERR("Failed to create trace format descriptor for trace format %s", + opt_trace_format); + goto error; + } + + status = lttng_session_descriptor_set_trace_format_descriptor( + descriptor, trace_format_descriptor); + lttng_trace_format_descriptor_destroy(trace_format_descriptor); + if (status != LTTNG_SESSION_DESCRIPTOR_STATUS_OK) { + ERR("Failed to set trace format descriptor"); + goto error; + } + } end: free(uris); return descriptor; +error: + lttng_session_descriptor_destroy(descriptor); + descriptor = NULL; + goto end; } /*