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