Add load command to the lttng client
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 10 Feb 2014 16:47:14 +0000 (11:47 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 10 Mar 2014 19:09:49 +0000 (15:09 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng/Makefile.am
src/bin/lttng/command.h
src/bin/lttng/commands/load.c [new file with mode: 0644]
src/bin/lttng/lttng.c

index ac4063b7a3ea5d7c3528a05a172bcecd449a6f6d..5a1eb6aedea18d28935856473fb7fcf009656fc2 100644 (file)
@@ -15,7 +15,9 @@ lttng_SOURCES = command.h conf.c conf.h commands/start.c \
                                commands/enable_consumer.c commands/disable_consumer.c \
                                commands/snapshot.c \
                                commands/save.c \
                                commands/enable_consumer.c commands/disable_consumer.c \
                                commands/snapshot.c \
                                commands/save.c \
+                               commands/load.c \
                                utils.c utils.h lttng.c
 
 lttng_LDADD = $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \
                                utils.c utils.h lttng.c
 
 lttng_LDADD = $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \
-                         $(top_builddir)/src/common/libcommon.la
+                       $(top_builddir)/src/common/libcommon.la \
+                       $(top_builddir)/src/common/config/libconfig.la
index fc3c394c1aa05d41d16300928cc67cf63b872e2b..3d4bbf8ebe37aa3ed64082bee9d37076cc9b46f9 100644 (file)
@@ -57,5 +57,6 @@ extern int cmd_enable_consumer(int argc, const char **argv);
 extern int cmd_disable_consumer(int argc, const char **argv);
 extern int cmd_snapshot(int argc, const char **argv);
 extern int cmd_save(int argc, const char **argv);
 extern int cmd_disable_consumer(int argc, const char **argv);
 extern int cmd_snapshot(int argc, const char **argv);
 extern int cmd_save(int argc, const char **argv);
+extern int cmd_load(int argc, const char **argv);
 
 #endif /* _LTTNG_CMD_H */
 
 #endif /* _LTTNG_CMD_H */
diff --git a/src/bin/lttng/commands/load.c b/src/bin/lttng/commands/load.c
new file mode 100644 (file)
index 0000000..3f92654
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2014 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _GNU_SOURCE
+#include <inttypes.h>
+#include <popt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <common/config/config.h>
+#include "../command.h"
+
+static char *opt_input_path;
+static char *opt_session_name;
+static int opt_force;
+static int opt_load_all;
+
+enum {
+       OPT_HELP = 1,
+       OPT_ALL,
+       OPT_FORCE,
+};
+
+static struct poptOption load_opts[] = {
+       /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+       {"help",        'h',  POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+       {"all",         'a',  POPT_ARG_NONE, 0, OPT_ALL, 0, 0},
+       {"session",     's',  POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
+       {"input-path",  'i',  POPT_ARG_STRING, &opt_input_path, 0, 0, 0},
+       {"force",       'f',  POPT_ARG_NONE, 0, OPT_FORCE, 0, 0},
+       {0, 0, 0, 0, 0, 0, 0}
+};
+
+/*
+ * usage
+ */
+static void usage(FILE *ofp)
+{
+       fprintf(ofp, "usage: lttng load [OPTIONS]\n");
+       fprintf(ofp, "\n");
+       fprintf(ofp, "Options:\n");
+       fprintf(ofp, "  -h, --help           Show this help\n");
+       fprintf(ofp, "  -a, --all            Load all sessions (default)\n");
+       fprintf(ofp, "  -s, --session        Load a specific session\n");
+       fprintf(ofp, "  -i, --input-path     Input path of the session configuration(s)\n");
+       fprintf(ofp, "  -f, --force          Override existing session configuration(s)\n");
+}
+
+/*
+ * The 'load <options>' first level command
+ */
+int cmd_load(int argc, const char **argv)
+{
+       int ret = CMD_SUCCESS;
+       int opt;
+       poptContext pc;
+
+       pc = poptGetContext(NULL, argc, argv, load_opts, 0);
+       poptReadDefaultConfig(pc, 0);
+
+       while ((opt = poptGetNextOpt(pc)) != -1) {
+               switch (opt) {
+               case OPT_HELP:
+                       usage(stdout);
+                       goto end;
+               case OPT_ALL:
+                       opt_load_all = 1;
+                       break;
+               case OPT_FORCE:
+                       opt_force = 1;
+                       break;
+               default:
+                       usage(stderr);
+                       ret = CMD_UNDEFINED;
+                       goto end;
+               }
+       }
+
+       if (opt_session_name && opt_load_all) {
+               WARN("Conflicting session options, loading session %s",
+                       opt_session_name);
+       }
+
+       ret = config_load_session(opt_input_path, opt_session_name, opt_force);
+       if (ret) {
+               ret = CMD_ERROR;
+       }
+end:
+       poptFreeContext(pc);
+       return ret;
+}
index c4443e7fb22c8e60d285bcb10dc1952f6e82c1a1..bc7577d77db148d508614e2a3d2929e1bdfeddb1 100644 (file)
@@ -81,6 +81,7 @@ static struct cmd_struct commands[] =  {
        { "view", cmd_view},
        { "snapshot", cmd_snapshot},
        { "save", cmd_save},
        { "view", cmd_view},
        { "snapshot", cmd_snapshot},
        { "save", cmd_save},
+       { "load", cmd_load},
        { "enable-consumer", cmd_enable_consumer}, /* OBSOLETE */
        { "disable-consumer", cmd_disable_consumer}, /* OBSOLETE */
        { NULL, NULL}   /* Array closure */
        { "enable-consumer", cmd_enable_consumer}, /* OBSOLETE */
        { "disable-consumer", cmd_disable_consumer}, /* OBSOLETE */
        { NULL, NULL}   /* Array closure */
@@ -120,6 +121,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "    version           Show version information\n");
        fprintf(ofp, "    view              Start trace viewer\n");
        fprintf(ofp, "    save              Save session configuration\n");
        fprintf(ofp, "    version           Show version information\n");
        fprintf(ofp, "    view              Start trace viewer\n");
        fprintf(ofp, "    save              Save session configuration\n");
+       fprintf(ofp, "    load              Load session configuration\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "Each command also has its own -h, --help option.\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "Each command also has its own -h, --help option.\n");
        fprintf(ofp, "\n");
This page took 0.030084 seconds and 5 git commands to generate.