From: Jérémie Galarneau Date: Mon, 10 Feb 2014 16:47:14 +0000 (-0500) Subject: Add load command to the lttng client X-Git-Tag: v2.5.0-rc1~124 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8c42d8454516c418e666aa9f96eaa261bb65b748;p=lttng-tools.git Add load command 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 ac4063b7a..5a1eb6aed 100644 --- a/src/bin/lttng/Makefile.am +++ b/src/bin/lttng/Makefile.am @@ -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/load.c \ 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 diff --git a/src/bin/lttng/command.h b/src/bin/lttng/command.h index fc3c394c1..3d4bbf8eb 100644 --- a/src/bin/lttng/command.h +++ b/src/bin/lttng/command.h @@ -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_load(int argc, const char **argv); #endif /* _LTTNG_CMD_H */ diff --git a/src/bin/lttng/commands/load.c b/src/bin/lttng/commands/load.c new file mode 100644 index 000000000..3f926548a --- /dev/null +++ b/src/bin/lttng/commands/load.c @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2014 - 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 +#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 ' 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; +} diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index c4443e7fb..bc7577d77 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -81,6 +81,7 @@ static struct cmd_struct commands[] = { { "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 */ @@ -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, " load Load session configuration\n"); fprintf(ofp, "\n"); fprintf(ofp, "Each command also has its own -h, --help option.\n"); fprintf(ofp, "\n");