Check kernel version for tests
[lttng-tools.git] / src / bin / lttng / commands / disable_events.c
CommitLineData
e953ef25
DG
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
82a3637f
DG
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
e953ef25
DG
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
c399183f 28#include "../command.h"
e953ef25
DG
29
30static char *opt_event_list;
9730260e 31static int opt_kernel;
e953ef25 32static char *opt_channel_name;
5440dc42 33static char *opt_session_name;
e953ef25
DG
34static int opt_userspace;
35static int opt_disable_all;
d78d6610
DG
36#if 0
37/* Not implemented yet */
38static char *opt_cmd_name;
e953ef25 39static pid_t opt_pid;
d78d6610 40#endif
e953ef25
DG
41
42enum {
43 OPT_HELP = 1,
44 OPT_USERSPACE,
45};
46
cd80958d
DG
47static struct lttng_handle *handle;
48
e953ef25
DG
49static struct poptOption long_options[] = {
50 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
51 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
5440dc42 52 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
e953ef25
DG
53 {"all-events", 'a', POPT_ARG_VAL, &opt_disable_all, 1, 0, 0},
54 {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0},
55 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
d78d6610
DG
56#if 0
57 /* Not implemented yet */
6caa2bcc 58 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
e953ef25 59 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
d78d6610
DG
60#else
61 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
62#endif
e953ef25
DG
63 {0, 0, 0, 0, 0, 0, 0}
64};
65
66/*
67 * usage
68 */
69static void usage(FILE *ofp)
70{
71 fprintf(ofp, "usage: lttng disable-event NAME[,NAME2,...] [options]\n");
72 fprintf(ofp, "\n");
73 fprintf(ofp, " -h, --help Show this help\n");
5440dc42 74 fprintf(ofp, " -s, --session Apply on session name\n");
e953ef25 75 fprintf(ofp, " -c, --channel Apply on this channel\n");
9730260e 76 fprintf(ofp, " -a, --all-events Disable all tracepoints\n");
e953ef25 77 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
d78d6610 78#if 0
e953ef25 79 fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n");
e14f64a8
DG
80 fprintf(ofp, " If no CMD, the domain used is UST global\n");
81 fprintf(ofp, " or else the domain is UST EXEC_NAME\n");
82 fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
d78d6610
DG
83#else
84 fprintf(ofp, " -u, --userspace Apply for the user-space tracer\n");
85#endif
e953ef25
DG
86 fprintf(ofp, "\n");
87}
88
89/*
90 * disable_events
91 *
92 * Disabling event using the lttng API.
93 */
cd80958d 94static int disable_events(char *session_name)
e953ef25
DG
95{
96 int err, ret = CMD_SUCCESS;
b73d0b29 97 char *event_name, *channel_name = NULL;
7d29a247 98 struct lttng_domain dom;
e953ef25 99
e953ef25
DG
100 if (opt_channel_name == NULL) {
101 err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
102 if (err < 0) {
103 ret = CMD_FATAL;
104 goto error;
105 }
106 } else {
107 channel_name = opt_channel_name;
108 }
109
e14f64a8
DG
110 if (opt_kernel && opt_userspace) {
111 ERR("Can't use -k/--kernel and -u/--userspace together");
112 ret = CMD_FATAL;
113 goto error;
114 }
115
d78d6610 116 /* Create lttng domain */
7d29a247
DG
117 if (opt_kernel) {
118 dom.type = LTTNG_DOMAIN_KERNEL;
d78d6610 119 } else if (opt_userspace) {
9730260e 120 dom.type = LTTNG_DOMAIN_UST;
9730260e 121 } else {
e14f64a8 122 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
1ab1ea0b 123 ret = CMD_UNDEFINED;
9730260e 124 goto error;
7d29a247
DG
125 }
126
cd80958d
DG
127 handle = lttng_create_handle(session_name, &dom);
128 if (handle == NULL) {
129 ret = -1;
130 goto error;
131 }
132
e953ef25 133 if (opt_disable_all) {
9730260e
DG
134 ret = lttng_disable_event(handle, NULL, channel_name);
135 if (ret < 0) {
e953ef25
DG
136 goto error;
137 }
138
9730260e
DG
139 MSG("All %s events are disabled in channel %s",
140 opt_kernel ? "kernel" : "UST", channel_name);
141 goto end;
e953ef25
DG
142 }
143
144 /* Strip event list */
145 event_name = strtok(opt_event_list, ",");
146 while (event_name != NULL) {
147 /* Kernel tracer action */
148 if (opt_kernel) {
9730260e 149 DBG("Disabling kernel event %s in channel %s",
e953ef25 150 event_name, channel_name);
e953ef25 151 } else if (opt_userspace) { /* User-space tracer action */
d78d6610 152#if 0
e14f64a8
DG
153 if (opt_cmd_name != NULL || opt_pid) {
154 MSG("Only supporting tracing all UST processes (-u) for now.");
1ab1ea0b 155 ret = CMD_UNDEFINED;
9730260e 156 goto error;
e953ef25 157 }
d78d6610 158#endif
9730260e
DG
159 DBG("Disabling UST event %s in channel %s",
160 event_name, channel_name);
e953ef25 161 } else {
e14f64a8 162 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
e953ef25
DG
163 goto error;
164 }
165
9730260e
DG
166 ret = lttng_disable_event(handle, event_name, channel_name);
167 if (ret < 0) {
168 MSG("Unable to disable %s event %s in channel %s",
169 opt_kernel ? "kernel" : "UST", event_name,
170 channel_name);
171 } else {
172 MSG("%s event %s disabled in channel %s",
173 opt_kernel ? "kernel" : "UST", event_name,
174 channel_name);
175 }
176
e953ef25
DG
177 /* Next event */
178 event_name = strtok(NULL, ",");
179 }
180
9730260e 181end:
e953ef25 182error:
b73d0b29
MD
183 if (opt_channel_name == NULL) {
184 free(channel_name);
185 }
cd80958d
DG
186 lttng_destroy_handle(handle);
187
e953ef25
DG
188 return ret;
189}
190
191/*
192 * cmd_disable_events
193 *
194 * Disable event to trace session
195 */
196int cmd_disable_events(int argc, const char **argv)
197{
198 int opt, ret;
199 static poptContext pc;
cd80958d 200 char *session_name = NULL;
e953ef25
DG
201
202 pc = poptGetContext(NULL, argc, argv, long_options, 0);
203 poptReadDefaultConfig(pc, 0);
204
205 while ((opt = poptGetNextOpt(pc)) != -1) {
206 switch (opt) {
207 case OPT_HELP:
208 usage(stderr);
209 ret = CMD_SUCCESS;
210 goto end;
211 case OPT_USERSPACE:
212 opt_userspace = 1;
e953ef25
DG
213 break;
214 default:
215 usage(stderr);
216 ret = CMD_UNDEFINED;
217 goto end;
218 }
219 }
220
221 opt_event_list = (char*) poptGetArg(pc);
222 if (opt_event_list == NULL && opt_disable_all == 0) {
223 ERR("Missing event name(s).\n");
224 usage(stderr);
225 ret = CMD_SUCCESS;
226 goto end;
227 }
228
cd80958d
DG
229 if (!opt_session_name) {
230 session_name = get_session_name();
231 if (session_name == NULL) {
232 ret = -1;
233 goto end;
234 }
235 } else {
236 session_name = opt_session_name;
237 }
238
239 ret = disable_events(session_name);
e953ef25
DG
240
241end:
242 return ret;
243}
This page took 0.035467 seconds and 4 git commands to generate.