From: Jérémie Galarneau Date: Wed, 22 Jan 2014 17:04:49 +0000 (-0500) Subject: Add a save command based on the save API to the lttng client X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;ds=sidebyside;h=c864d6d788c58de94111911a9e10d221ec8bc398;p=lttng-tools.git Add a save command based on the save API to the lttng client Signed-off-by: Jérémie Galarneau Signed-off-by: David Goulet --- diff --git a/src/bin/lttng/Makefile.am b/src/bin/lttng/Makefile.am index c3a43fa2f..ac4063b7a 100644 --- a/src/bin/lttng/Makefile.am +++ b/src/bin/lttng/Makefile.am @@ -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 \ diff --git a/src/bin/lttng/command.h b/src/bin/lttng/command.h index 7965f55ce..fc3c394c1 100644 --- a/src/bin/lttng/command.h +++ b/src/bin/lttng/command.h @@ -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 index 000000000..e7c3caeef --- /dev/null +++ b/src/bin/lttng/commands/save.c @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2013 - Jérémie Galarneau + * + * 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 +#include +#include +#include +#include +#include + +#include "../command.h" +#include + +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 ' 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; +} diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 6b926954d..c4443e7fb 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -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");