Add disable kernel event support
[lttng-tools.git] / lttng / commands / disable_events.c
... / ...
CommitLineData
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#define _GNU_SOURCE
20#include <popt.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26#include <unistd.h>
27
28#include "cmd.h"
29#include "conf.h"
30#include "utils.h"
31
32static char *opt_event_list;
33static char *opt_kernel;
34static char *opt_cmd_name;
35static char *opt_channel_name;
36static int opt_pid_all;
37static int opt_userspace;
38static int opt_disable_all;
39static pid_t opt_pid;
40
41enum {
42 OPT_HELP = 1,
43 OPT_USERSPACE,
44};
45
46static struct poptOption long_options[] = {
47 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
48 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
49 {"all-events", 'a', POPT_ARG_VAL, &opt_disable_all, 1, 0, 0},
50 {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0},
51 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
52 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_USERSPACE, 0, 0},
53 {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
54 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
55 {0, 0, 0, 0, 0, 0, 0}
56};
57
58/*
59 * usage
60 */
61static void usage(FILE *ofp)
62{
63 fprintf(ofp, "usage: lttng disable-event NAME[,NAME2,...] [options]\n");
64 fprintf(ofp, "\n");
65 fprintf(ofp, " -h, --help Show this help\n");
66 fprintf(ofp, " -c, --channel Apply on this channel\n");
67 fprintf(ofp, " -a, --all-events Enable all tracepoints\n");
68 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
69 fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n");
70 fprintf(ofp, " --all If -u, apply on all traceable apps\n");
71 fprintf(ofp, " -p, --pid PID If -u, apply on a specific PID\n");
72 fprintf(ofp, "\n");
73}
74
75/*
76 * disable_events
77 *
78 * Disabling event using the lttng API.
79 */
80static int disable_events(void)
81{
82 int err, ret = CMD_SUCCESS;
83 char *event_name, *channel_name;
84 struct lttng_event ev;
85
86 if (set_session_name() < 0) {
87 ret = CMD_ERROR;
88 goto error;
89 }
90
91 if (opt_channel_name == NULL) {
92 err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
93 if (err < 0) {
94 ret = CMD_FATAL;
95 goto error;
96 }
97 } else {
98 channel_name = opt_channel_name;
99 }
100
101 if (opt_disable_all) {
102 if (opt_kernel) {
103 ret = lttng_kernel_disable_event(NULL, channel_name);
104 goto error;
105 }
106
107 /* TODO: User-space tracer */
108 }
109
110 /* Strip event list */
111 event_name = strtok(opt_event_list, ",");
112 while (event_name != NULL) {
113 /* Kernel tracer action */
114 if (opt_kernel) {
115 DBG("Disabling kernel event %s for channel %s",
116 event_name, channel_name);
117
118 /* Copy name and type of the event */
119 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
120 ret = lttng_kernel_disable_event(event_name, channel_name);
121 if (ret < 0) {
122 MSG("Unable to disable event %s for channel %s",
123 event_name, channel_name);
124 } else {
125 MSG("Kernel event %s disabled for channel %s",
126 event_name, channel_name);
127 }
128 } else if (opt_userspace) { /* User-space tracer action */
129 /*
130 * TODO: Waiting on lttng UST 2.0
131 */
132 if (opt_pid_all) {
133 } else if (opt_pid != 0) {
134 }
135 ret = CMD_NOT_IMPLEMENTED;
136 goto error;
137 } else {
138 ERR("Please specify a tracer (kernel or user-space)");
139 goto error;
140 }
141
142 /* Next event */
143 event_name = strtok(NULL, ",");
144 }
145
146error:
147 return ret;
148}
149
150/*
151 * cmd_disable_events
152 *
153 * Disable event to trace session
154 */
155int cmd_disable_events(int argc, const char **argv)
156{
157 int opt, ret;
158 static poptContext pc;
159
160 pc = poptGetContext(NULL, argc, argv, long_options, 0);
161 poptReadDefaultConfig(pc, 0);
162
163 while ((opt = poptGetNextOpt(pc)) != -1) {
164 switch (opt) {
165 case OPT_HELP:
166 usage(stderr);
167 ret = CMD_SUCCESS;
168 goto end;
169 case OPT_USERSPACE:
170 opt_userspace = 1;
171 opt_cmd_name = poptGetOptArg(pc);
172 break;
173 default:
174 usage(stderr);
175 ret = CMD_UNDEFINED;
176 goto end;
177 }
178 }
179
180 opt_event_list = (char*) poptGetArg(pc);
181 if (opt_event_list == NULL && opt_disable_all == 0) {
182 ERR("Missing event name(s).\n");
183 usage(stderr);
184 ret = CMD_SUCCESS;
185 goto end;
186 }
187
188 ret = disable_events();
189
190end:
191 return ret;
192}
This page took 0.022735 seconds and 4 git commands to generate.