Add a save command based on the save API to the lttng client
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 22 Jan 2014 17:04:49 +0000 (12:04 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 10 Mar 2014 16:33:44 +0000 (12:33 -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/save.c [new file with mode: 0644]
src/bin/lttng/lttng.c

index c3a43fa2f2182b45d4d371dcf79d405a8e60fffe..ac4063b7a3ea5d7c3528a05a172bcecd449a6f6d 100644 (file)
@@ -14,6 +14,7 @@ lttng_SOURCES = command.h conf.c conf.h commands/start.c \
                                commands/calibrate.c commands/view.c \
                                commands/enable_consumer.c commands/disable_consumer.c \
                                commands/snapshot.c \
+                               commands/save.c \
                                utils.c utils.h lttng.c
 
 lttng_LDADD = $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \
index 7965f55cee5063475aaa0fe78a6eed371b379ebe..fc3c394c1aa05d41d16300928cc67cf63b872e2b 100644 (file)
@@ -56,5 +56,6 @@ extern int cmd_view(int argc, const char **argv);
 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);
 
 #endif /* _LTTNG_CMD_H */
diff --git a/src/bin/lttng/commands/save.c b/src/bin/lttng/commands/save.c
new file mode 100644 (file)
index 0000000..e7c3cae
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2013 - 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 "../command.h"
+#include <lttng/save.h>
+
+static char *opt_output_path;
+static int opt_force;
+static int opt_save_all;
+
+enum {
+       OPT_HELP = 1,
+       OPT_ALL,
+       OPT_FORCE,
+};
+
+static struct poptOption save_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},
+       {"output-path", 'o', POPT_ARG_STRING, &opt_output_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 save [OPTIONS] [SESSION]\n");
+       fprintf(ofp, "\n");
+       fprintf(ofp, "Options:\n");
+       fprintf(ofp, "  -h, --help           Show this help\n");
+       fprintf(ofp, "  -a, --all            Save all sessions (default)\n");
+       fprintf(ofp, "  -o, --output-path    Output path of the session configuration(s)\n");
+       fprintf(ofp, "  -f, --force          Overwrite existing session configuration(s)\n");
+}
+
+/*
+ * The 'save <options>' first level command
+ */
+int cmd_save(int argc, const char **argv)
+{
+       int ret = CMD_SUCCESS;
+       int opt;
+       const char *session_name = NULL;
+       poptContext pc;
+       struct lttng_save_session_attr *attr;
+
+       pc = poptGetContext(NULL, argc, argv, save_opts, 0);
+       poptReadDefaultConfig(pc, 0);
+
+       while ((opt = poptGetNextOpt(pc)) != -1) {
+               switch (opt) {
+               case OPT_HELP:
+                       usage(stdout);
+                       goto end;
+               case OPT_ALL:
+                       opt_save_all = 1;
+                       break;
+               case OPT_FORCE:
+                       opt_force = 1;
+                       break;
+               default:
+                       usage(stderr);
+                       ret = CMD_UNDEFINED;
+                       goto end;
+               }
+       }
+
+       if (!opt_save_all) {
+               session_name = poptGetArg(pc);
+               if (!session_name) {
+                       ERR("A session name must be provided if the \"all\" option is not used.");
+                       ret = CMD_ERROR;
+                       goto end;
+               }
+               DBG2("Session name: %s", session_name);
+       }
+
+       attr = lttng_save_session_attr_create();
+       if (!attr) {
+               ret = CMD_FATAL;
+               goto end_destroy;
+       }
+
+       if (lttng_save_session_attr_set_session_name(attr, session_name)) {
+               ret = CMD_ERROR;
+               goto end_destroy;
+       }
+
+       if (lttng_save_session_attr_set_overwrite(attr, opt_force)) {
+               ret = CMD_ERROR;
+               goto end_destroy;
+       }
+
+       if (lttng_save_session_attr_set_output_url(attr,
+               opt_output_path)) {
+               ret = CMD_ERROR;
+               goto end_destroy;
+       }
+
+       ret = lttng_save_session(attr);
+       if (ret) {
+               if (ret == -LTTNG_ERR_SESS_NOT_FOUND) {
+                       ERR("Session '%s' not found", session_name);
+               }
+               ret = CMD_ERROR;
+       }
+end_destroy:
+       lttng_save_session_attr_destroy(attr);
+end:
+       poptFreeContext(pc);
+       return ret;
+}
index 6b926954da8c29a53f36f0eea7a1fbea79752d38..c4443e7fb22c8e60d285bcb10dc1952f6e82c1a1 100644 (file)
@@ -80,6 +80,7 @@ static struct cmd_struct commands[] =  {
        { "calibrate", cmd_calibrate},
        { "view", cmd_view},
        { "snapshot", cmd_snapshot},
+       { "save", cmd_save},
        { "enable-consumer", cmd_enable_consumer}, /* OBSOLETE */
        { "disable-consumer", cmd_disable_consumer}, /* OBSOLETE */
        { NULL, NULL}   /* Array closure */
@@ -118,6 +119,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "    stop              Stop tracing\n");
        fprintf(ofp, "    version           Show version information\n");
        fprintf(ofp, "    view              Start trace viewer\n");
+       fprintf(ofp, "    save              Save session configuration\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "Each command also has its own -h, --help option.\n");
        fprintf(ofp, "\n");
This page took 0.029762 seconds and 5 git commands to generate.