From: David Goulet Date: Wed, 29 Jun 2011 18:47:18 +0000 (-0400) Subject: Add disable kernel channel support X-Git-Tag: v2.0-pre1~69 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=26cc6b4e17dc888cd894ef1f42a83c59d7f8a95f Add disable kernel channel support Signed-off-by: David Goulet --- diff --git a/liblttngctl/liblttngctl.c b/liblttngctl/liblttngctl.c index 7ddbc3099..cad4d735e 100644 --- a/liblttngctl/liblttngctl.c +++ b/liblttngctl/liblttngctl.c @@ -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); } diff --git a/liblttsessiondcomm/liblttsessiondcomm.c b/liblttsessiondcomm/liblttsessiondcomm.c index 6f39388c7..ea5b68f9f 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.c +++ b/liblttsessiondcomm/liblttsessiondcomm.c @@ -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", diff --git a/liblttsessiondcomm/liblttsessiondcomm.h b/liblttsessiondcomm/liblttsessiondcomm.h index df3cc6179..2fb6de069 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.h +++ b/liblttsessiondcomm/liblttsessiondcomm.h @@ -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 */ diff --git a/ltt-sessiond/kernel-ctl.c b/ltt-sessiond/kernel-ctl.c index bc92ffca9..e42ab872e 100644 --- a/ltt-sessiond/kernel-ctl.c +++ b/ltt-sessiond/kernel-ctl.c @@ -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 * diff --git a/ltt-sessiond/kernel-ctl.h b/ltt-sessiond/kernel-ctl.h index 82b680bd7..1f8993707 100644 --- a/ltt-sessiond/kernel-ctl.h +++ b/ltt-sessiond/kernel-ctl.h @@ -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); diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 4fba6a2cf..01e75cbb2 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -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; diff --git a/lttng/Makefile.am b/lttng/Makefile.am index ef2ddc1e0..c02506419 100644 --- a/lttng/Makefile.am +++ b/lttng/Makefile.am @@ -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 diff --git a/lttng/cmd.h b/lttng/cmd.h index 7f54bafda..201bad9ee 100644 --- a/lttng/cmd.h +++ b/lttng/cmd.h @@ -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 index 000000000..ad2f0bf08 --- /dev/null +++ b/lttng/commands/disable_channels.c @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2011 - David Goulet + * + * 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 +#include +#include +#include +#include +#include +#include + +#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; +} diff --git a/lttng/lttng.c b/lttng/lttng.c index e4578c70a..48d834491 100644 --- a/lttng/lttng.c +++ b/lttng/lttng.c @@ -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");