CLI: Add `--trace-format` option to `create` command
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 14 Apr 2022 21:50:02 +0000 (17:50 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 19 Aug 2022 16:05:11 +0000 (12:05 -0400)
TODO: doc

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Change-Id: Ifcb37b7289e3b8a30a3f76fb515029fa46aa6905

src/bin/lttng/commands/create.cpp

index 64cf2b37ca37f46b70b5e5dc2bb0e699024ed779..68a1020a892ef53cdb8379fc5266fcccc8b60b2a 100644 (file)
@@ -7,17 +7,19 @@
  */
 
 #define _LGPL_SOURCE
+#include <common/compat/time.hpp>
 #include <ctype.h>
+#include <functional>
 #include <popt.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <common/compat/time.hpp>
-#include <unistd.h>
-#include <signal.h>
 #include <sys/wait.h>
+#include <unistd.h>
+#include <unordered_map>
 
 #include <common/mi-lttng.hpp>
 
@@ -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<std::string,
+                               std::function<struct lttng_trace_format_descriptor *()>>
+                               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;
 }
 
 /*
This page took 0.028265 seconds and 5 git commands to generate.