From: Philippe Proulx Date: Sat, 5 Sep 2015 18:50:46 +0000 (-0400) Subject: lttng: add status command X-Git-Tag: v2.8.0-rc1~218 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=54a0adbf3cf5cd691d57b9ebaef083cad30273e1;p=lttng-tools.git lttng: add status command The status command is the equivalent of: lttng [general-options] list Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/Makefile.am b/src/bin/lttng/Makefile.am index 9f00caeae..7cf329ee2 100644 --- a/src/bin/lttng/Makefile.am +++ b/src/bin/lttng/Makefile.am @@ -16,6 +16,7 @@ lttng_SOURCES = command.h conf.c conf.h commands/start.c \ commands/save.c \ commands/load.c \ commands/track-untrack.c \ + commands/status.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 9d6bc093b..fc6f01c1c 100644 --- a/src/bin/lttng/command.h +++ b/src/bin/lttng/command.h @@ -43,6 +43,7 @@ struct cmd_struct { }; DECL_COMMAND(list); +DECL_COMMAND(status); DECL_COMMAND(create); DECL_COMMAND(destroy); DECL_COMMAND(start); diff --git a/src/bin/lttng/commands/status.c b/src/bin/lttng/commands/status.c new file mode 100644 index 000000000..b3555c984 --- /dev/null +++ b/src/bin/lttng/commands/status.c @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2015 - Philippe Proulx + * + * 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 +#define _LGPL_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "../command.h" +#include "../utils.h" +#include + +enum { + OPT_HELP = 1, + OPT_LIST_OPTIONS, +}; + +static struct poptOption long_options[] = { + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ + {"help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL}, + {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, + {0, 0, 0, 0, 0, 0, 0} +}; + +static void usage(FILE *ofp) +{ + fprintf(ofp, "Usage: lttng status [options]\n"); + fprintf(ofp, "\n"); + fprintf(ofp, "Options:\n"); + fprintf(ofp, " -h, --help Show this help\n"); + fprintf(ofp, " --list-options List options\n"); +} + +static int status(void) +{ + const char *argv[2]; + int ret = CMD_SUCCESS; + char *session_name = NULL; + + session_name = get_session_name(); + if (!session_name) { + ret = CMD_ERROR; + goto end; + } + + argv[0] = "list"; + argv[1] = session_name; + ret = cmd_list(2, argv); +end: + free(session_name); + return ret; +} + +/* + * The 'status ' first level command + */ +int cmd_status(int argc, const char **argv) +{ + int opt, ret = CMD_SUCCESS; + static poptContext pc; + + pc = poptGetContext(NULL, argc, argv, long_options, 0); + poptReadDefaultConfig(pc, 0); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case OPT_HELP: + usage(stdout); + goto end; + case OPT_LIST_OPTIONS: + list_cmd_options(stdout, long_options); + goto end; + default: + usage(stderr); + ret = CMD_UNDEFINED; + goto end; + } + } + + if (poptPeekArg(pc) != NULL) { + ERR("This command does not accept positional arguments.\n"); + usage(stderr); + ret = CMD_UNDEFINED; + goto end; + } + + ret = status(); +end: + poptFreeContext(pc); + return ret; +} diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 25665b369..d4dbe2697 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -65,6 +65,7 @@ static struct option long_options[] = { /* First level command */ static struct cmd_struct commands[] = { { "list", cmd_list}, + { "status", cmd_status}, { "create", cmd_create}, { "destroy", cmd_destroy}, { "start", cmd_start}, @@ -119,6 +120,7 @@ static void usage(FILE *ofp) fprintf(ofp, " set-session Set current session name\n"); fprintf(ofp, " snapshot Snapshot buffers of current session name\n"); fprintf(ofp, " start Start tracing\n"); + fprintf(ofp, " status Show current session's details\n"); fprintf(ofp, " stop Stop tracing\n"); fprintf(ofp, " version Show version information\n"); fprintf(ofp, " view Start trace viewer\n");