lttng: add status command
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 5 Sep 2015 18:50:46 +0000 (14:50 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 11 Nov 2015 23:13:26 +0000 (18:13 -0500)
The status command is the equivalent of:
    lttng [general-options] list <current-session-name>

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/Makefile.am
src/bin/lttng/command.h
src/bin/lttng/commands/status.c [new file with mode: 0644]
src/bin/lttng/lttng.c

index 9f00caeae0199ef2d74aa04e84cc16046a5b0ad8..7cf329ee24c03d59808dadffe6b9fb642fcb53e6 100644 (file)
@@ -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 \
index 9d6bc093b718b8b3675917fd40d063bcfc0e83cb..fc6f01c1c6db6e891aaa6e8cc5a425f192341683 100644 (file)
@@ -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 (file)
index 0000000..b3555c9
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2015 - Philippe Proulx <pproulx@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
+#define _LGPL_SOURCE
+#include <popt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "../command.h"
+#include "../utils.h"
+#include <config.h>
+
+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 <options>' 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;
+}
index 25665b3695db85ceb27a17db5032035237e8b0f0..d4dbe2697a8d2a591ed1c045267a559cee69420f 100644 (file)
@@ -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");
This page took 0.027549 seconds and 4 git commands to generate.