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