lttng: Add --all, --glob options to lttng-start
authorOlivier Dion <odion@efficios.com>
Mon, 6 Feb 2023 21:06:10 +0000 (16:06 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 26 Apr 2023 17:54:58 +0000 (13:54 -0400)
Change-Id: I8ff806c7ea7a51b8fa69206bd427b5e106706073
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
doc/man/lttng-start.1.txt
src/bin/lttng/commands/start.cpp

index b595b2f5ce2f804f605f99ebd350fe910d6ab1a4..f3ee0e785053792c5e11575802b75fb626fc0e22 100644 (file)
@@ -11,7 +11,7 @@ lttng-start - Start an LTTng recording session
 SYNOPSIS
 --------
 [verse]
-*lttng* ['linkgenoptions:(GENERAL OPTIONS)'] *start* ['SESSION']
+*lttng* ['linkgenoptions:(GENERAL OPTIONS)'] *start* [option::--all | option::--glob 'SESSION' | 'SESSION' ]
 
 
 DESCRIPTION
@@ -44,6 +44,11 @@ include::common-lttng-cmd-options-head.txt[]
 
 include::common-lttng-cmd-help-options.txt[]
 
+option:-a, option:--all::
+    Start all sessions.
+
+option:-g, option:--glob::
+    Interpret SESSION as a globbing pattern.
 
 include::common-lttng-cmd-after-options.txt[]
 
@@ -67,6 +72,26 @@ $ lttng start my-session
 ----
 ====
 
+.Start all sessions.
+====
+See the option::--all option.
+
+[role="term"]
+----
+$ lttng start --all
+----
+====
+
+.Start all sessions with the suffix foo.
+====
+See the option::--glob option.
+
+[role="term"]
+----
+$ lttng start --glob '*foo'
+----
+====
+
 
 include::common-footer.txt[]
 
index d8e3569760298a1c7850bf8e29a9dff1ee0c2880..556c1120dddc94b86ccba2b9dd7a18ff59f17bd9 100644 (file)
@@ -7,7 +7,9 @@
 
 #define _LGPL_SOURCE
 #include "../command.hpp"
+#include "../utils.hpp"
 
+#include <common/exception.hpp>
 #include <common/mi-lttng.hpp>
 #include <common/sessiond-comm/sessiond-comm.hpp>
 
@@ -30,16 +32,20 @@ static const char help_msg[] =
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
+       OPT_ENABLE_GLOB,
+       OPT_ALL,
 };
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        { "help", 'h', POPT_ARG_NONE, nullptr, OPT_HELP, nullptr, nullptr },
        { "list-options", 0, POPT_ARG_NONE, nullptr, OPT_LIST_OPTIONS, nullptr, nullptr },
+       { "glob", 'g', POPT_ARG_NONE, nullptr, OPT_ENABLE_GLOB, nullptr, nullptr },
+       { "all", 'a', POPT_ARG_NONE, nullptr, OPT_ALL, nullptr, nullptr },
        { nullptr, 0, 0, nullptr, 0, nullptr, nullptr }
 };
 
-static int mi_print_session(char *session_name, int enabled)
+static int mi_print_session(const char *session_name, int enabled)
 {
        int ret;
 
@@ -72,19 +78,9 @@ end:
  *
  *  Start tracing for all trace of the session.
  */
-static int start_tracing(const char *arg_session_name)
+static int start_tracing(const char *session_name)
 {
        int ret;
-       char *session_name;
-
-       if (arg_session_name == nullptr) {
-               session_name = get_session_name();
-       } else {
-               session_name = strdup(arg_session_name);
-               if (session_name == nullptr) {
-                       PERROR("Failed to copy session name");
-               }
-       }
 
        if (session_name == nullptr) {
                ret = CMD_ERROR;
@@ -103,7 +99,7 @@ static int start_tracing(const char *arg_session_name)
                        ERR("%s", lttng_strerror(ret));
                        break;
                }
-               goto free_name;
+               goto error;
        }
 
        ret = CMD_SUCCESS;
@@ -113,16 +109,46 @@ static int start_tracing(const char *arg_session_name)
                ret = mi_print_session(session_name, 1);
                if (ret) {
                        ret = CMD_ERROR;
-                       goto free_name;
+                       goto error;
                }
        }
 
-free_name:
-       free(session_name);
 error:
        return ret;
 }
 
+static int start_tracing(const struct session_spec& spec)
+{
+       int ret = CMD_SUCCESS;
+       bool had_warning = false;
+
+       try {
+               for (const auto& session : list_sessions(spec)) {
+                       const auto sub_ret = start_tracing(session.name);
+
+                       switch (sub_ret) {
+                       case CMD_WARNING:
+                               had_warning = true;
+                               /* fall-through. */
+                       case CMD_SUCCESS:
+                               continue;
+                       default:
+                               ret = sub_ret;
+                               break;
+                       }
+               }
+       } catch (const std::exception& e) {
+               ERR_FMT("{}", e.what());
+               return CMD_FATAL;
+       }
+
+       if (ret == CMD_SUCCESS && had_warning) {
+               ret = CMD_WARNING;
+       }
+
+       return ret;
+}
+
 /*
  *  cmd_start
  *
@@ -132,8 +158,11 @@ int cmd_start(int argc, const char **argv)
 {
        int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
        static poptContext pc;
-       const char *arg_session_name = nullptr;
        const char *leftover = nullptr;
+       struct session_spec session_spec = {
+               .type = session_spec::NAME,
+               .value = nullptr,
+       };
 
        pc = poptGetContext(nullptr, argc, argv, long_options, 0);
        poptReadDefaultConfig(pc, 0);
@@ -146,13 +175,19 @@ int cmd_start(int argc, const char **argv)
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
                        goto end;
+               case OPT_ENABLE_GLOB:
+                       session_spec.type = session_spec::GLOB_PATTERN;
+                       break;
+               case OPT_ALL:
+                       session_spec.type = session_spec::ALL;
+                       break;
                default:
                        ret = CMD_UNDEFINED;
                        goto end;
                }
        }
 
-       arg_session_name = poptGetArg(pc);
+       session_spec.value = poptGetArg(pc);
 
        leftover = poptGetArg(pc);
        if (leftover) {
@@ -194,7 +229,7 @@ int cmd_start(int argc, const char **argv)
                }
        }
 
-       command_ret = start_tracing(arg_session_name);
+       command_ret = start_tracing(session_spec);
        if (command_ret) {
                success = 0;
        }
This page took 0.028298 seconds and 4 git commands to generate.