Fix uninitialized ret value
[lttng-tools.git] / src / bin / lttng / commands / enable_events.c
CommitLineData
f3ed775e
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.
f3ed775e
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>
5a0de755 27#include <inttypes.h>
8f0d098b 28#include <ctype.h>
f3ed775e 29
c399183f 30#include "../command.h"
f3ed775e
DG
31
32static char *opt_event_list;
33static int opt_event_type;
0cda4f28
MD
34static const char *opt_loglevel;
35static int opt_loglevel_type;
6181537c 36static int opt_kernel;
5440dc42 37static char *opt_session_name;
f3ed775e
DG
38static int opt_userspace;
39static int opt_enable_all;
cf0e5467 40static char *opt_probe;
8f0d098b
MD
41static char *opt_function;
42static char *opt_function_entry_symbol;
f3ed775e 43static char *opt_channel_name;
d78d6610
DG
44#if 0
45/* Not implemented yet */
46static char *opt_cmd_name;
47static pid_t opt_pid;
48#endif
f3ed775e
DG
49
50enum {
51 OPT_HELP = 1,
f3ed775e 52 OPT_TRACEPOINT,
cf0e5467 53 OPT_PROBE,
f3ed775e 54 OPT_FUNCTION,
8f0d098b 55 OPT_FUNCTION_ENTRY,
a54bd42d 56 OPT_SYSCALL,
eeac7d46 57 OPT_USERSPACE,
0cda4f28
MD
58 OPT_LOGLEVEL,
59 OPT_LOGLEVEL_ONLY,
679b4943 60 OPT_LIST_OPTIONS,
f3ed775e
DG
61};
62
cd80958d
DG
63static struct lttng_handle *handle;
64
f3ed775e
DG
65static struct poptOption long_options[] = {
66 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
67 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
5440dc42 68 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
e14f64a8 69 {"all", 'a', POPT_ARG_VAL, &opt_enable_all, 1, 0, 0},
f3ed775e
DG
70 {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0},
71 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
d78d6610
DG
72#if 0
73 /* Not implemented yet */
40e9d5d3 74 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
f3ed775e 75 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
d78d6610
DG
76#else
77 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
78#endif
f3ed775e 79 {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0},
7ebae521 80 {"probe", 0, POPT_ARG_STRING, &opt_probe, OPT_PROBE, 0, 0},
40e9d5d3 81 {"function", 0, POPT_ARG_STRING, &opt_function, OPT_FUNCTION, 0, 0},
b213d387
MD
82#if 0
83 /*
84 * Currently removed from lttng kernel tracer. Removed from
85 * lttng UI to discourage its use.
86 */
40e9d5d3 87 {"function:entry", 0, POPT_ARG_STRING, &opt_function_entry_symbol, OPT_FUNCTION_ENTRY, 0, 0},
b213d387 88#endif
7ebae521 89 {"syscall", 0, POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0},
0cda4f28
MD
90 {"loglevel", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL, 0, 0},
91 {"loglevel-only", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL_ONLY, 0, 0},
679b4943 92 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
f3ed775e
DG
93 {0, 0, 0, 0, 0, 0, 0}
94};
95
96/*
97 * usage
98 */
99static void usage(FILE *ofp)
100{
101 fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] [options] [event_options]\n");
102 fprintf(ofp, "\n");
103 fprintf(ofp, " -h, --help Show this help\n");
679b4943 104 fprintf(ofp, " --list-options Simple listing of options\n");
27221701
DG
105 fprintf(ofp, " -s, --session Apply to session name\n");
106 fprintf(ofp, " -c, --channel Apply to this channel\n");
e14f64a8 107 fprintf(ofp, " -a, --all Enable all tracepoints\n");
f3ed775e 108 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
d78d6610 109#if 0
27221701 110 fprintf(ofp, " -u, --userspace [CMD] Apply to the user-space tracer\n");
e14f64a8
DG
111 fprintf(ofp, " If no CMD, the domain used is UST global\n");
112 fprintf(ofp, " or else the domain is UST EXEC_NAME\n");
113 fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
d78d6610 114#else
27221701 115 fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
d78d6610 116#endif
f3ed775e
DG
117 fprintf(ofp, "\n");
118 fprintf(ofp, "Event options:\n");
119 fprintf(ofp, " --tracepoint Tracepoint event (default)\n");
be49af1e
MD
120 fprintf(ofp, " - userspace tracer supports wildcards at end of string.\n");
121 fprintf(ofp, " Don't forget to quote to deal with bash expansion.\n");
122 fprintf(ofp, " e.g.:\n");
123 fprintf(ofp, " \"*\"\n");
124 fprintf(ofp, " \"app_component:na*\"\n");
8f0d098b 125 fprintf(ofp, " --probe [addr | symbol | symbol+offset]\n");
cf0e5467
MD
126 fprintf(ofp, " Dynamic probe.\n");
127 fprintf(ofp, " Addr and offset can be octal (0NNN...),\n");
128 fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
8f0d098b
MD
129 fprintf(ofp, " --function [addr | symbol | symbol+offset]\n");
130 fprintf(ofp, " Dynamic function entry/return probe.\n");
131 fprintf(ofp, " Addr and offset can be octal (0NNN...),\n");
132 fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
b213d387 133#if 0
8f0d098b
MD
134 fprintf(ofp, " --function:entry symbol\n");
135 fprintf(ofp, " Function tracer event\n");
b213d387 136#endif
a54bd42d 137 fprintf(ofp, " --syscall System call event\n");
f3ed775e 138 fprintf(ofp, "\n");
300b8fd5
MD
139 fprintf(ofp, " --loglevel name\n");
140 fprintf(ofp, " Tracepoint loglevel range from 0 to loglevel\n");
141 fprintf(ofp, " --loglevel-only name\n");
142 fprintf(ofp, " Tracepoint loglevel (only this loglevel)\n");
143 fprintf(ofp, "\n");
0c8477c8
MD
144 fprintf(ofp, " The loglevel or loglevel-only options should be\n");
145 fprintf(ofp, " combined with a tracepoint name or tracepoint\n");
146 fprintf(ofp, " wildcard.\n");
147 fprintf(ofp, " Available loglevels:\n");
148 fprintf(ofp, " (higher value is more verbose)\n");
300b8fd5
MD
149 fprintf(ofp, " TRACE_EMERG = 0\n");
150 fprintf(ofp, " TRACE_ALERT = 1\n");
151 fprintf(ofp, " TRACE_CRIT = 2\n");
152 fprintf(ofp, " TRACE_ERR = 3\n");
153 fprintf(ofp, " TRACE_WARNING = 4\n");
154 fprintf(ofp, " TRACE_NOTICE = 5\n");
155 fprintf(ofp, " TRACE_INFO = 6\n");
156 fprintf(ofp, " TRACE_SYSTEM = 7\n");
0c8477c8
MD
157 fprintf(ofp, " TRACE_PROGRAM = 8\n");
158 fprintf(ofp, " TRACE_PROCESS = 9\n");
159 fprintf(ofp, " TRACE_MODULE = 10\n");
160 fprintf(ofp, " TRACE_UNIT = 11\n");
161 fprintf(ofp, " TRACE_FUNCTION = 12\n");
162 fprintf(ofp, " TRACE_DEFAULT = 13\n");
163 fprintf(ofp, " TRACE_VERBOSE = 14\n");
300b8fd5
MD
164 fprintf(ofp, " TRACE_DEBUG = 15\n");
165 fprintf(ofp, "\n");
f3ed775e
DG
166}
167
0d63dd19 168/*
6181537c 169 * Parse probe options.
0d63dd19 170 */
cf0e5467 171static int parse_probe_opts(struct lttng_event *ev, char *opt)
0d63dd19
DG
172{
173 int ret;
8ff0bbd0 174 char s_hex[19];
0d63dd19
DG
175 char name[LTTNG_SYMBOL_NAME_LEN];
176
177 if (opt == NULL) {
178 ret = -1;
8f0d098b 179 goto end;
0d63dd19
DG
180 }
181
182 /* Check for symbol+offset */
8ff0bbd0 183 ret = sscanf(opt, "%[^'+']+%s", name, s_hex);
0d63dd19 184 if (ret == 2) {
7d29a247 185 strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
99497cd0 186 ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
cf0e5467 187 DBG("probe symbol %s", ev->attr.probe.symbol_name);
8ff0bbd0
DG
188 if (strlen(s_hex) == 0) {
189 ERR("Invalid probe offset %s", s_hex);
0d63dd19 190 ret = -1;
8f0d098b 191 goto end;
0d63dd19 192 }
8ff0bbd0 193 ev->attr.probe.offset = strtoul(s_hex, NULL, 0);
cf0e5467 194 DBG("probe offset %" PRIu64, ev->attr.probe.offset);
3000dc78 195 ev->attr.probe.addr = 0;
8f0d098b
MD
196 goto end;
197 }
198
199 /* Check for symbol */
200 if (isalpha(name[0])) {
201 ret = sscanf(opt, "%s", name);
202 if (ret == 1) {
203 strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
99497cd0 204 ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
8f0d098b
MD
205 DBG("probe symbol %s", ev->attr.probe.symbol_name);
206 ev->attr.probe.offset = 0;
207 DBG("probe offset %" PRIu64, ev->attr.probe.offset);
208 ev->attr.probe.addr = 0;
209 goto end;
210 }
0d63dd19
DG
211 }
212
213 /* Check for address */
8ff0bbd0 214 ret = sscanf(opt, "%s", s_hex);
0d63dd19 215 if (ret > 0) {
8ff0bbd0
DG
216 if (strlen(s_hex) == 0) {
217 ERR("Invalid probe address %s", s_hex);
0d63dd19 218 ret = -1;
8f0d098b 219 goto end;
0d63dd19 220 }
8ff0bbd0 221 ev->attr.probe.addr = strtoul(s_hex, NULL, 0);
cf0e5467 222 DBG("probe addr %" PRIu64, ev->attr.probe.addr);
3000dc78
DG
223 ev->attr.probe.offset = 0;
224 memset(ev->attr.probe.symbol_name, 0, LTTNG_SYMBOL_NAME_LEN);
8f0d098b 225 goto end;
0d63dd19
DG
226 }
227
228 /* No match */
229 ret = -1;
230
8f0d098b 231end:
0d63dd19
DG
232 return ret;
233}
234
8005f29a 235/*
0c8477c8 236 * Maps loglevel from string to value
8005f29a
MD
237 */
238static
239int loglevel_str_to_value(const char *str)
240{
241 if (!strcmp(str, "TRACE_EMERG")) {
242 return 0;
243 } else if (!strcmp(str, "TRACE_ALERT")) {
244 return 1;
245 } else if (!strcmp(str, "TRACE_CRIT")) {
246 return 2;
247 } else if (!strcmp(str, "TRACE_ERR")) {
248 return 3;
249 } else if (!strcmp(str, "TRACE_WARNING")) {
250 return 4;
251 } else if (!strcmp(str, "TRACE_NOTICE")) {
252 return 5;
253 } else if (!strcmp(str, "TRACE_INFO")) {
254 return 6;
255 } else if (!strcmp(str, "TRACE_SYSTEM")) {
256 return 7;
0c8477c8 257 } else if (!strcmp(str, "TRACE_PROGRAM")) {
8005f29a 258 return 8;
0c8477c8 259 } else if (!strcmp(str, "TRACE_PROCESS")) {
8005f29a 260 return 9;
0c8477c8 261 } else if (!strcmp(str, "TRACE_MODULE")) {
8005f29a 262 return 10;
0c8477c8 263 } else if (!strcmp(str, "TRACE_UNIT")) {
8005f29a 264 return 11;
8005f29a 265 } else if (!strcmp(str, "TRACE_FUNCTION")) {
0c8477c8
MD
266 return 12;
267 } else if (!strcmp(str, "TRACE_DEFAULT")) {
8005f29a 268 return 13;
0c8477c8 269 } else if (!strcmp(str, "TRACE_VERBOSE")) {
8005f29a
MD
270 return 14;
271 } else if (!strcmp(str, "TRACE_DEBUG")) {
272 return 15;
273 } else {
274 return -1;
275 }
276}
277
f3ed775e 278/*
6181537c 279 * Enabling event using the lttng API.
f3ed775e 280 */
cd80958d 281static int enable_events(char *session_name)
f3ed775e 282{
ae856491 283 int err, ret = CMD_SUCCESS, warn = 0;
b73d0b29 284 char *event_name, *channel_name = NULL;
f3ed775e 285 struct lttng_event ev;
7d29a247 286 struct lttng_domain dom;
f3ed775e 287
441c16a7
MD
288 memset(&ev, 0, sizeof(ev));
289 memset(&dom, 0, sizeof(dom));
290
7d29a247
DG
291 /* Create lttng domain */
292 if (opt_kernel) {
293 dom.type = LTTNG_DOMAIN_KERNEL;
d78d6610 294 } else if (opt_userspace) {
2bdd86d4 295 dom.type = LTTNG_DOMAIN_UST;
6181537c 296 } else {
e14f64a8 297 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
d16c1a4c 298 ret = CMD_ERROR;
6181537c 299 goto error;
2bdd86d4 300 }
7d29a247 301
ae856491
DG
302 if (opt_channel_name == NULL) {
303 err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
304 if (err < 0) {
305 ret = CMD_FATAL;
306 goto error;
307 }
308 } else {
309 channel_name = opt_channel_name;
310 }
311
cd80958d
DG
312 handle = lttng_create_handle(session_name, &dom);
313 if (handle == NULL) {
314 ret = -1;
315 goto error;
316 }
1aef21b6 317
cd80958d 318 if (opt_enable_all) {
8c9ae521 319 /* Default setup for enable all */
75e8c5ab
MD
320 if (opt_kernel) {
321 ev.type = opt_event_type;
322 ev.name[0] = '\0';
300b8fd5
MD
323 /* kernel loglevels not implemented */
324 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
75e8c5ab
MD
325 } else {
326 ev.type = LTTNG_EVENT_TRACEPOINT;
327 strcpy(ev.name, "*");
300b8fd5
MD
328 ev.loglevel_type = opt_loglevel_type;
329 if (opt_loglevel) {
330 ev.loglevel = loglevel_str_to_value(opt_loglevel);
331 if (ev.loglevel == -1) {
332 ERR("Unknown loglevel %s", opt_loglevel);
333 ret = -1;
334 goto error;
335 }
22e25b71
MD
336 } else {
337 ev.loglevel = -1;
300b8fd5 338 }
75e8c5ab 339 }
8c9ae521
DG
340
341 ret = lttng_enable_event(handle, &ev, channel_name);
342 if (ret < 0) {
343 goto error;
344 }
345
0133c199
MD
346 switch (opt_event_type) {
347 case LTTNG_EVENT_TRACEPOINT:
300b8fd5
MD
348 MSG("All %s tracepoints are enabled in channel %s for loglevel %s",
349 opt_kernel ? "kernel" : "UST", channel_name,
350 opt_loglevel ? : "<all>");
0133c199 351 break;
a54bd42d 352 case LTTNG_EVENT_SYSCALL:
0133c199 353 if (opt_kernel) {
8c9ae521
DG
354 MSG("All kernel system calls are enabled in channel %s",
355 channel_name);
c93d9daf 356 }
0133c199 357 break;
7a3d1328 358 case LTTNG_EVENT_ALL:
300b8fd5
MD
359 MSG("All %s events are enabled in channel %s for loglevel %s",
360 opt_kernel ? "kernel" : "UST", channel_name,
361 opt_loglevel ? : "<all>");
7a3d1328 362 break;
0133c199 363 default:
8c9ae521 364 /*
6181537c
DG
365 * We should not be here since lttng_enable_event should have
366 * failed on the event type.
8c9ae521 367 */
f3ed775e
DG
368 goto error;
369 }
8c9ae521 370 goto end;
f3ed775e
DG
371 }
372
373 /* Strip event list */
374 event_name = strtok(opt_event_list, ",");
375 while (event_name != NULL) {
6181537c
DG
376 /* Copy name and type of the event */
377 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
378 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
379 ev.type = opt_event_type;
380
f3ed775e
DG
381 /* Kernel tracer action */
382 if (opt_kernel) {
383 DBG("Enabling kernel event %s for channel %s",
384 event_name, channel_name);
f3ed775e
DG
385
386 switch (opt_event_type) {
7a3d1328
MD
387 case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */
388 ev.type = LTTNG_EVENT_TRACEPOINT;
389 /* Fall-through */
e6ddca71 390 case LTTNG_EVENT_TRACEPOINT:
f3ed775e 391 break;
7d29a247 392 case LTTNG_EVENT_PROBE:
cf0e5467 393 ret = parse_probe_opts(&ev, opt_probe);
0d63dd19 394 if (ret < 0) {
cf0e5467 395 ERR("Unable to parse probe options");
0d63dd19
DG
396 ret = 0;
397 goto error;
398 }
f3ed775e
DG
399 break;
400 case LTTNG_EVENT_FUNCTION:
8f0d098b
MD
401 ret = parse_probe_opts(&ev, opt_function);
402 if (ret < 0) {
403 ERR("Unable to parse function probe options");
404 ret = 0;
405 goto error;
406 }
407 break;
408 case LTTNG_EVENT_FUNCTION_ENTRY:
6181537c
DG
409 strncpy(ev.attr.ftrace.symbol_name, opt_function_entry_symbol,
410 LTTNG_SYMBOL_NAME_LEN);
99497cd0 411 ev.attr.ftrace.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
f3ed775e 412 break;
a54bd42d 413 case LTTNG_EVENT_SYSCALL:
6181537c
DG
414 MSG("per-syscall selection not supported yet. Use \"-a\" "
415 "for all syscalls.");
f3ed775e 416 default:
1ab1ea0b 417 ret = CMD_UNDEFINED;
f3ed775e
DG
418 goto error;
419 }
0cda4f28 420
ed7f4083 421 if (opt_loglevel) {
0cda4f28
MD
422 MSG("Kernel loglevels are not supported.");
423 ret = CMD_UNDEFINED;
424 goto error;
425 }
426
427 /* kernel loglevels not implemented */
8005f29a 428 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
f3ed775e 429 } else if (opt_userspace) { /* User-space tracer action */
d78d6610 430#if 0
e14f64a8
DG
431 if (opt_cmd_name != NULL || opt_pid) {
432 MSG("Only supporting tracing all UST processes (-u) for now.");
1ab1ea0b 433 ret = CMD_UNDEFINED;
2bdd86d4
MD
434 goto error;
435 }
d78d6610 436#endif
6181537c 437
300b8fd5
MD
438 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name,
439 channel_name, opt_loglevel ? : "<all>");
2bdd86d4
MD
440
441 switch (opt_event_type) {
442 case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */
2bdd86d4
MD
443 /* Fall-through */
444 case LTTNG_EVENT_TRACEPOINT:
e4baff1e
MD
445 /* Copy name and type of the event */
446 ev.type = LTTNG_EVENT_TRACEPOINT;
447 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
448 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
2bdd86d4
MD
449 break;
450 case LTTNG_EVENT_PROBE:
451 case LTTNG_EVENT_FUNCTION:
452 case LTTNG_EVENT_FUNCTION_ENTRY:
453 case LTTNG_EVENT_SYSCALL:
454 default:
cc62c0c0 455 ERR("Event type not available for user-space tracing");
1ab1ea0b 456 ret = CMD_UNDEFINED;
2bdd86d4
MD
457 goto error;
458 }
0cda4f28
MD
459
460 ev.loglevel_type = opt_loglevel_type;
ed7f4083 461 if (opt_loglevel) {
8005f29a
MD
462 ev.loglevel = loglevel_str_to_value(opt_loglevel);
463 if (ev.loglevel == -1) {
464 ERR("Unknown loglevel %s", opt_loglevel);
300b8fd5 465 ret = -1;
8005f29a
MD
466 goto error;
467 }
22e25b71
MD
468 } else {
469 ev.loglevel = -1;
ed7f4083 470 }
f3ed775e 471 } else {
e14f64a8 472 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
300b8fd5 473 ret = CMD_ERROR;
f3ed775e
DG
474 goto error;
475 }
476
6181537c 477 ret = lttng_enable_event(handle, &ev, channel_name);
ae856491
DG
478 if (ret < 0) {
479 ERR("Event %s: %s (channel %s, session %s)", event_name,
480 lttng_strerror(ret), channel_name, session_name);
481 warn = 1;
482 } else {
6181537c
DG
483 MSG("%s event %s created in channel %s",
484 opt_kernel ? "kernel": "UST", event_name, channel_name);
485 }
486
f3ed775e
DG
487 /* Next event */
488 event_name = strtok(NULL, ",");
489 }
490
8c9ae521 491end:
f3ed775e 492error:
ae856491
DG
493 if (warn) {
494 ret = CMD_WARNING;
495 }
b73d0b29
MD
496 if (opt_channel_name == NULL) {
497 free(channel_name);
498 }
cd80958d
DG
499 lttng_destroy_handle(handle);
500
f3ed775e
DG
501 return ret;
502}
503
504/*
6181537c 505 * Add event to trace session
f3ed775e
DG
506 */
507int cmd_enable_events(int argc, const char **argv)
508{
ca1c3607 509 int opt, ret = CMD_SUCCESS;
f3ed775e 510 static poptContext pc;
cd80958d 511 char *session_name = NULL;
f3ed775e
DG
512
513 pc = poptGetContext(NULL, argc, argv, long_options, 0);
514 poptReadDefaultConfig(pc, 0);
515
516 /* Default event type */
7a3d1328 517 opt_event_type = LTTNG_EVENT_ALL;
f3ed775e
DG
518
519 while ((opt = poptGetNextOpt(pc)) != -1) {
520 switch (opt) {
521 case OPT_HELP:
ca1c3607 522 usage(stdout);
f3ed775e 523 goto end;
f3ed775e 524 case OPT_TRACEPOINT:
e6ddca71 525 opt_event_type = LTTNG_EVENT_TRACEPOINT;
f3ed775e 526 break;
cf0e5467 527 case OPT_PROBE:
7d29a247 528 opt_event_type = LTTNG_EVENT_PROBE;
f3ed775e
DG
529 break;
530 case OPT_FUNCTION:
531 opt_event_type = LTTNG_EVENT_FUNCTION;
8f0d098b
MD
532 break;
533 case OPT_FUNCTION_ENTRY:
534 opt_event_type = LTTNG_EVENT_FUNCTION_ENTRY;
f3ed775e 535 break;
a54bd42d
MD
536 case OPT_SYSCALL:
537 opt_event_type = LTTNG_EVENT_SYSCALL;
0133c199 538 break;
eeac7d46
MD
539 case OPT_USERSPACE:
540 opt_userspace = 1;
eeac7d46 541 break;
0cda4f28 542 case OPT_LOGLEVEL:
8005f29a 543 opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE;
0cda4f28
MD
544 opt_loglevel = poptGetOptArg(pc);
545 break;
546 case OPT_LOGLEVEL_ONLY:
8005f29a 547 opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE;
0cda4f28 548 opt_loglevel = poptGetOptArg(pc);
13dce3b7 549 break;
679b4943
SM
550 case OPT_LIST_OPTIONS:
551 list_cmd_options(stdout, long_options);
679b4943 552 goto end;
f3ed775e
DG
553 default:
554 usage(stderr);
555 ret = CMD_UNDEFINED;
556 goto end;
557 }
558 }
559
560 opt_event_list = (char*) poptGetArg(pc);
561 if (opt_event_list == NULL && opt_enable_all == 0) {
562 ERR("Missing event name(s).\n");
563 usage(stderr);
ca1c3607 564 ret = CMD_ERROR;
f3ed775e
DG
565 goto end;
566 }
567
cd80958d
DG
568 if (!opt_session_name) {
569 session_name = get_session_name();
570 if (session_name == NULL) {
ca1c3607 571 ret = CMD_ERROR;
cd80958d
DG
572 goto end;
573 }
574 } else {
575 session_name = opt_session_name;
576 }
577
578 ret = enable_events(session_name);
f3ed775e
DG
579
580end:
cd80958d
DG
581 if (opt_session_name == NULL) {
582 free(session_name);
583 }
584
ca1c3607 585 poptFreeContext(pc);
f3ed775e
DG
586 return ret;
587}
This page took 0.08997 seconds and 4 git commands to generate.