Add disable kernel channel support
authorDavid Goulet <david.goulet@polymtl.ca>
Wed, 29 Jun 2011 18:47:18 +0000 (14:47 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Wed, 29 Jun 2011 18:51:21 +0000 (14:51 -0400)
Signed-off-by: David Goulet <david.goulet@polymtl.ca>
liblttngctl/liblttngctl.c
liblttsessiondcomm/liblttsessiondcomm.c
liblttsessiondcomm/liblttsessiondcomm.h
ltt-sessiond/kernel-ctl.c
ltt-sessiond/kernel-ctl.h
ltt-sessiond/main.c
lttng/Makefile.am
lttng/cmd.h
lttng/commands/disable_channels.c [new file with mode: 0644]
lttng/lttng.c

index 7ddbc3099d102de20d83e87f0990c5ab65e830c5..cad4d735eed17aff794aa5aae95892f505198ef0 100644 (file)
@@ -317,6 +317,7 @@ int lttng_kernel_enable_channel(char *name)
  */
 int lttng_kernel_disable_channel(char *name)
 {
+       strncpy(lsm.u.disable.channel_name, name, NAME_MAX);
        return ask_sessiond(LTTNG_KERNEL_DISABLE_CHANNEL, NULL);
 }
 
index 6f39388c78c70eb424c71058c3902eef7a2fbb1c..ea5b68f9f5d208e2b5201301ca49394ec666131e 100644 (file)
@@ -52,6 +52,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_SESS_FAIL) ] = "Kernel create session failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_FAIL) ] = "Kernel create channel failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_NOT_FOUND) ] = "Kernel channel not found",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_DISABLE_FAIL) ] = "Disable kernel channel failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_ENABLE_FAIL) ] = "Enable kernel channel failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_ENABLE_FAIL) ] = "Enable kernel event failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_DISABLE_FAIL) ] = "Disable kernel event failed",
index df3cc6179d53042388ba14695d37289262b24fd8..2fb6de069fb58e096903468580e3fa0a794549ea 100644 (file)
@@ -87,6 +87,7 @@ enum lttcomm_return_code {
        LTTCOMM_KERN_SESS_FAIL,                 /* Kernel create session failed */
        LTTCOMM_KERN_CHAN_FAIL,                 /* Kernel create channel failed */
        LTTCOMM_KERN_CHAN_NOT_FOUND,    /* Kernel channel not found */
+       LTTCOMM_KERN_CHAN_DISABLE_FAIL, /* Kernel disable channel failed */
        LTTCOMM_KERN_CHAN_ENABLE_FAIL,  /* Kernel enable channel failed */
        LTTCOMM_KERN_ENABLE_FAIL,               /* Kernel enable event failed */
        LTTCOMM_KERN_DISABLE_FAIL,              /* Kernel disable event failed */
index bc92ffca918cb07b524aa8b9a6865308e455761b..e42ab872e487890b8c01072aa1784bb10b9ffb19 100644 (file)
@@ -159,6 +159,31 @@ error:
        return -1;
 }
 
+/*
+ *  kernel_disable_channel
+ *
+ *  Disable a kernel channel.
+ */
+int kernel_disable_channel(struct ltt_kernel_channel *chan)
+{
+       int ret;
+
+       ret = kernctl_disable(chan->fd);
+       if (ret < 0) {
+               perror("disable chan ioctl");
+               ret = errno;
+               goto error;
+       }
+
+       chan->enabled = 0;
+       DBG("Kernel channel %s disabled (fd: %d)", chan->channel->name, chan->fd);
+
+       return 0;
+
+error:
+       return ret;
+}
+
 /*
  *  kernel_enable_channel
  *
index 82b680bd759908f73efad5a5fb66014ef847950b..1f899370706f197cd78a7d93e0f702df1a8a010a 100644 (file)
@@ -33,6 +33,7 @@
 int kernel_create_session(struct ltt_session *session, int tracer_fd);
 int kernel_create_channel(struct ltt_kernel_session *session, struct lttng_channel *chan);
 int kernel_create_event(struct lttng_event *ev, struct ltt_kernel_channel *channel);
+int kernel_disable_channel(struct ltt_kernel_channel *chan);
 int kernel_disable_event(struct ltt_kernel_event *event);
 int kernel_enable_event(struct ltt_kernel_event *event);
 int kernel_enable_channel(struct ltt_kernel_channel *chan);
index 4fba6a2cf53a701054601e88df4478f35b658342..01e75cbb26488f0cd68aff386d5e76da98a85223 100644 (file)
@@ -873,6 +873,35 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                ret = LTTCOMM_OK;
                break;
        }
+       case LTTNG_KERNEL_DISABLE_CHANNEL:
+       {
+               struct ltt_kernel_channel *chan;
+
+               /* Setup lttng message with no payload */
+               ret = setup_lttng_msg(cmd_ctx, 0);
+               if (ret < 0) {
+                       goto setup_error;
+               }
+
+               chan = get_kernel_channel_by_name(cmd_ctx->lsm->u.disable.channel_name,
+                               cmd_ctx->session->kernel_session);
+               if (chan == NULL) {
+                       ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
+                       goto error;
+               } else if (chan->enabled == 1) {
+                       ret = kernel_disable_channel(chan);
+                       if (ret < 0) {
+                               if (ret != EEXIST) {
+                                       ret = LTTCOMM_KERN_CHAN_DISABLE_FAIL;
+                               }
+                               goto error;
+                       }
+               }
+
+               kernel_wait_quiescent(kernel_tracer_fd);
+               ret = LTTCOMM_OK;
+               break;
+       }
        case LTTNG_KERNEL_DISABLE_EVENT:
        {
                struct ltt_kernel_channel *chan;
index ef2ddc1e01a8488eca16c45bdc4b6e0830e841e4..c0250641950450abef0008663c7df9612f07220f 100644 (file)
@@ -6,7 +6,7 @@ lttng_SOURCES = conf.c commands/start.c commands/add_channel.c \
                                commands/list.c commands/create.c commands/destroy.c \
                                commands/stop.c commands/enable_events.c \
                                commands/disable_events.c commands/enable_channels.c \
-                               utils.c lttng.c
+                               commands/disable_channels.c utils.c lttng.c
 
 lttng_LDADD = \
                $(top_builddir)/liblttngctl/liblttngctl.la
index 7f54bafdafa1b70c63c505e6470bef4e64507f23..201bad9eece46616823a11fa069a2de5d5e4227b 100644 (file)
@@ -46,5 +46,6 @@ extern int cmd_stop(int argc, const char **argv);
 extern int cmd_enable_events(int argc, const char **argv);
 extern int cmd_disable_events(int argc, const char **argv);
 extern int cmd_enable_channels(int argc, const char **argv);
+extern int cmd_disable_channels(int argc, const char **argv);
 
 #endif /* _LTTNG_CMD_H */
diff --git a/lttng/commands/disable_channels.c b/lttng/commands/disable_channels.c
new file mode 100644 (file)
index 0000000..ad2f0bf
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#define _GNU_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 "cmd.h"
+#include "conf.h"
+#include "utils.h"
+
+static char *opt_channels;
+static char *opt_kernel;
+static int opt_pid_all;
+static int opt_userspace;
+static pid_t opt_pid;
+
+enum {
+       OPT_HELP = 1,
+       OPT_USERSPACE,
+};
+
+static struct poptOption long_options[] = {
+       /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+       {"help",           'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+       {"kernel",         'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
+       {"userspace",      'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
+       {"all",            0,   POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
+       {"pid",            'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
+       {0, 0, 0, 0, 0, 0, 0}
+};
+
+/*
+ * usage
+ */
+static void usage(FILE *ofp)
+{
+       fprintf(ofp, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n");
+       fprintf(ofp, "\n");
+       fprintf(ofp, "  -h, --help            Show this help\n");
+       fprintf(ofp, "  -k, --kernel          Apply for the kernel tracer\n");
+       fprintf(ofp, "  -u, --userspace       Apply for the user-space tracer\n");
+       fprintf(ofp, "      --all             If -u, apply on all traceable apps\n");
+       fprintf(ofp, "  -p, --pid PID         If -u, apply on a specific PID\n");
+       fprintf(ofp, "\n");
+}
+
+/*
+ *  disable_channels
+ *
+ *  Disabling channel using the lttng API.
+ */
+static int disable_channels(void)
+{
+       int ret = CMD_SUCCESS;
+       char *channel_name;
+
+       if (set_session_name() < 0) {
+               ret = CMD_ERROR;
+               goto error;
+       }
+
+       /* Strip channel list */
+       channel_name = strtok(opt_channels, ",");
+       while (channel_name != NULL) {
+               /* Kernel tracer action */
+               if (opt_kernel) {
+                       DBG("Disabling kernel channel %s", channel_name);
+                       ret = lttng_kernel_disable_channel(channel_name);
+                       if (ret < 0) {
+                               goto error;
+                       } else {
+                               MSG("Kernel channel disabled %s", channel_name);
+                       }
+               } else if (opt_userspace) {             /* User-space tracer action */
+                       /*
+                        * TODO: Waiting on lttng UST 2.0
+                        */
+                       if (opt_pid_all) {
+                       } else if (opt_pid != 0) {
+                       }
+                       ret = CMD_NOT_IMPLEMENTED;
+                       goto error;
+               } else {
+                       ERR("Please specify a tracer (kernel or user-space)");
+                       goto error;
+               }
+
+               /* Next channel */
+               channel_name = strtok(NULL, ",");
+       }
+
+error:
+       return ret;
+}
+
+/*
+ *  cmd_disable_channels
+ *
+ *  Disable channel to trace session
+ */
+int cmd_disable_channels(int argc, const char **argv)
+{
+       int opt, ret;
+       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(stderr);
+                       ret = CMD_SUCCESS;
+                       goto end;
+               case OPT_USERSPACE:
+                       opt_userspace = 1;
+                       break;
+               default:
+                       usage(stderr);
+                       ret = CMD_UNDEFINED;
+                       goto end;
+               }
+       }
+
+       opt_channels = (char*) poptGetArg(pc);
+       if (opt_channels == NULL) {
+               ERR("Missing channel name(s).\n");
+               usage(stderr);
+               ret = CMD_SUCCESS;
+               goto end;
+       }
+
+       ret = disable_channels();
+
+end:
+       return ret;
+}
index e4578c70a3a60ad8eb8a2a2cdf510a5458e5e82b..48d83449152bc7b4316a3698a6c4aa7b60e5728a 100644 (file)
@@ -65,6 +65,7 @@ static struct cmd_struct commands[] =  {
        { "enable-event", cmd_enable_events},
        { "disable-event", cmd_disable_events},
        { "enable-channel", cmd_enable_channels},
+       { "disable-channel", cmd_disable_channels},
        { NULL, NULL}   /* Array closure */
 };
 
@@ -85,8 +86,9 @@ static void usage(FILE *ofp)
        fprintf(ofp, "    add-channel     Add channel to tracer\n");
        fprintf(ofp, "    create          Create tracing session\n");
        fprintf(ofp, "    destroy         Teardown tracing session\n");
-       fprintf(ofp, "    enable-event    Enable tracing event\n");
        fprintf(ofp, "    enable-channel  Enable tracing channel\n");
+       fprintf(ofp, "    enable-event    Enable tracing event\n");
+       fprintf(ofp, "    disable-channel Disable tracing channel\n");
        fprintf(ofp, "    disable-event   Disable tracing event\n");
        fprintf(ofp, "    list            List possible tracing options\n");
        fprintf(ofp, "    start           Start tracing\n");
This page took 0.030811 seconds and 4 git commands to generate.