de1796ad8ed0e7fa8f6fe06d363c7ad33787e8f0
[lttng-tools.git] / src / bin / lttng / commands / enable_events.c
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #define _GNU_SOURCE
19 #include <popt.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <inttypes.h>
27 #include <ctype.h>
28
29 #include "../command.h"
30 #include <src/common/sessiond-comm/sessiond-comm.h>
31
32 static char *opt_event_list;
33 static int opt_event_type;
34 static const char *opt_loglevel;
35 static int opt_loglevel_type;
36 static int opt_kernel;
37 static char *opt_session_name;
38 static int opt_userspace;
39 static int opt_enable_all;
40 static char *opt_probe;
41 static char *opt_function;
42 static char *opt_function_entry_symbol;
43 static char *opt_channel_name;
44 static char *opt_filter;
45 #if 0
46 /* Not implemented yet */
47 static char *opt_cmd_name;
48 static pid_t opt_pid;
49 #endif
50
51 enum {
52 OPT_HELP = 1,
53 OPT_TRACEPOINT,
54 OPT_PROBE,
55 OPT_FUNCTION,
56 OPT_FUNCTION_ENTRY,
57 OPT_SYSCALL,
58 OPT_USERSPACE,
59 OPT_LOGLEVEL,
60 OPT_LOGLEVEL_ONLY,
61 OPT_LIST_OPTIONS,
62 OPT_FILTER,
63 };
64
65 static struct lttng_handle *handle;
66
67 static struct poptOption long_options[] = {
68 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
69 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
70 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
71 {"all", 'a', POPT_ARG_VAL, &opt_enable_all, 1, 0, 0},
72 {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0},
73 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
74 #if 0
75 /* Not implemented yet */
76 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
77 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
78 #else
79 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
80 #endif
81 {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0},
82 {"probe", 0, POPT_ARG_STRING, &opt_probe, OPT_PROBE, 0, 0},
83 {"function", 0, POPT_ARG_STRING, &opt_function, OPT_FUNCTION, 0, 0},
84 #if 0
85 /*
86 * Currently removed from lttng kernel tracer. Removed from
87 * lttng UI to discourage its use.
88 */
89 {"function:entry", 0, POPT_ARG_STRING, &opt_function_entry_symbol, OPT_FUNCTION_ENTRY, 0, 0},
90 #endif
91 {"syscall", 0, POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0},
92 {"loglevel", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL, 0, 0},
93 {"loglevel-only", 0, POPT_ARG_STRING, 0, OPT_LOGLEVEL_ONLY, 0, 0},
94 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
95 {"filter", 'f', POPT_ARG_STRING, &opt_filter, OPT_FILTER, 0, 0},
96 {0, 0, 0, 0, 0, 0, 0}
97 };
98
99 /*
100 * usage
101 */
102 static void usage(FILE *ofp)
103 {
104 fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] [options] [event_options]\n");
105 fprintf(ofp, "\n");
106 fprintf(ofp, " -h, --help Show this help\n");
107 fprintf(ofp, " --list-options Simple listing of options\n");
108 fprintf(ofp, " -s, --session Apply to session name\n");
109 fprintf(ofp, " -c, --channel Apply to this channel\n");
110 fprintf(ofp, " -a, --all Enable all tracepoints and syscalls\n");
111 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
112 #if 0
113 fprintf(ofp, " -u, --userspace [CMD] Apply to the user-space tracer\n");
114 fprintf(ofp, " If no CMD, the domain used is UST global\n");
115 fprintf(ofp, " or else the domain is UST EXEC_NAME\n");
116 fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
117 #else
118 fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
119 #endif
120 fprintf(ofp, "\n");
121 fprintf(ofp, "Event options:\n");
122 fprintf(ofp, " --tracepoint Tracepoint event (default)\n");
123 fprintf(ofp, " - userspace tracer supports wildcards at end of string.\n");
124 fprintf(ofp, " Don't forget to quote to deal with bash expansion.\n");
125 fprintf(ofp, " e.g.:\n");
126 fprintf(ofp, " \"*\"\n");
127 fprintf(ofp, " \"app_component:na*\"\n");
128 fprintf(ofp, " --probe [addr | symbol | symbol+offset]\n");
129 fprintf(ofp, " Dynamic probe.\n");
130 fprintf(ofp, " Addr and offset can be octal (0NNN...),\n");
131 fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
132 fprintf(ofp, " --function [addr | symbol | symbol+offset]\n");
133 fprintf(ofp, " Dynamic function entry/return probe.\n");
134 fprintf(ofp, " Addr and offset can be octal (0NNN...),\n");
135 fprintf(ofp, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
136 #if 0
137 fprintf(ofp, " --function:entry symbol\n");
138 fprintf(ofp, " Function tracer event\n");
139 #endif
140 fprintf(ofp, " --syscall System call event\n");
141 fprintf(ofp, "\n");
142 fprintf(ofp, " --loglevel name\n");
143 fprintf(ofp, " Tracepoint loglevel range from 0 to loglevel\n");
144 fprintf(ofp, " --loglevel-only name\n");
145 fprintf(ofp, " Tracepoint loglevel (only this loglevel)\n");
146 fprintf(ofp, "\n");
147 fprintf(ofp, " The loglevel or loglevel-only options should be\n");
148 fprintf(ofp, " combined with a tracepoint name or tracepoint\n");
149 fprintf(ofp, " wildcard.\n");
150 fprintf(ofp, " Available loglevels:\n");
151 fprintf(ofp, " (higher value is more verbose)\n");
152 fprintf(ofp, " TRACE_EMERG = 0\n");
153 fprintf(ofp, " TRACE_ALERT = 1\n");
154 fprintf(ofp, " TRACE_CRIT = 2\n");
155 fprintf(ofp, " TRACE_ERR = 3\n");
156 fprintf(ofp, " TRACE_WARNING = 4\n");
157 fprintf(ofp, " TRACE_NOTICE = 5\n");
158 fprintf(ofp, " TRACE_INFO = 6\n");
159 fprintf(ofp, " TRACE_DEBUG_SYSTEM = 7\n");
160 fprintf(ofp, " TRACE_DEBUG_PROGRAM = 8\n");
161 fprintf(ofp, " TRACE_DEBUG_PROCESS = 9\n");
162 fprintf(ofp, " TRACE_DEBUG_MODULE = 10\n");
163 fprintf(ofp, " TRACE_DEBUG_UNIT = 11\n");
164 fprintf(ofp, " TRACE_DEBUG_FUNCTION = 12\n");
165 fprintf(ofp, " TRACE_DEBUG_LINE = 13\n");
166 fprintf(ofp, " TRACE_DEBUG = 14\n");
167 fprintf(ofp, " (shortcuts such as \"system\" are allowed)\n");
168 fprintf(ofp, " --filter \'expression\'\n");
169 fprintf(ofp, " Filter expression on event fields,\n");
170 fprintf(ofp, " event recording depends on evaluation.\n");
171 fprintf(ofp, " Only specify on first activation of\n");
172 fprintf(ofp, " a given event within a session.\n");
173 fprintf(ofp, " Filter only allowed when enabling\n");
174 fprintf(ofp, " events within a session before tracing\n");
175 fprintf(ofp, " is started.\n");
176 fprintf(ofp, "\n");
177 }
178
179 /*
180 * Parse probe options.
181 */
182 static int parse_probe_opts(struct lttng_event *ev, char *opt)
183 {
184 int ret;
185 char s_hex[19];
186 char name[LTTNG_SYMBOL_NAME_LEN];
187
188 if (opt == NULL) {
189 ret = -1;
190 goto end;
191 }
192
193 /* Check for symbol+offset */
194 ret = sscanf(opt, "%[^'+']+%s", name, s_hex);
195 if (ret == 2) {
196 strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
197 ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
198 DBG("probe symbol %s", ev->attr.probe.symbol_name);
199 if (strlen(s_hex) == 0) {
200 ERR("Invalid probe offset %s", s_hex);
201 ret = -1;
202 goto end;
203 }
204 ev->attr.probe.offset = strtoul(s_hex, NULL, 0);
205 DBG("probe offset %" PRIu64, ev->attr.probe.offset);
206 ev->attr.probe.addr = 0;
207 goto end;
208 }
209
210 /* Check for symbol */
211 if (isalpha(name[0])) {
212 ret = sscanf(opt, "%s", name);
213 if (ret == 1) {
214 strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
215 ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
216 DBG("probe symbol %s", ev->attr.probe.symbol_name);
217 ev->attr.probe.offset = 0;
218 DBG("probe offset %" PRIu64, ev->attr.probe.offset);
219 ev->attr.probe.addr = 0;
220 goto end;
221 }
222 }
223
224 /* Check for address */
225 ret = sscanf(opt, "%s", s_hex);
226 if (ret > 0) {
227 if (strlen(s_hex) == 0) {
228 ERR("Invalid probe address %s", s_hex);
229 ret = -1;
230 goto end;
231 }
232 ev->attr.probe.addr = strtoul(s_hex, NULL, 0);
233 DBG("probe addr %" PRIu64, ev->attr.probe.addr);
234 ev->attr.probe.offset = 0;
235 memset(ev->attr.probe.symbol_name, 0, LTTNG_SYMBOL_NAME_LEN);
236 goto end;
237 }
238
239 /* No match */
240 ret = -1;
241
242 end:
243 return ret;
244 }
245
246 /*
247 * Maps loglevel from string to value
248 */
249 static
250 int loglevel_str_to_value(const char *inputstr)
251 {
252 int i = 0;
253 char str[LTTNG_SYMBOL_NAME_LEN];
254
255 while (inputstr[i] != '\0' && i < LTTNG_SYMBOL_NAME_LEN) {
256 str[i] = toupper(inputstr[i]);
257 i++;
258 }
259 str[i] = '\0';
260 if (!strcmp(str, "TRACE_EMERG") || !strcmp(str, "EMERG")) {
261 return LTTNG_LOGLEVEL_EMERG;
262 } else if (!strcmp(str, "TRACE_ALERT") || !strcmp(str, "ALERT")) {
263 return LTTNG_LOGLEVEL_ALERT;
264 } else if (!strcmp(str, "TRACE_CRIT") || !strcmp(str, "CRIT")) {
265 return LTTNG_LOGLEVEL_CRIT;
266 } else if (!strcmp(str, "TRACE_ERR") || !strcmp(str, "ERR")) {
267 return LTTNG_LOGLEVEL_ERR;
268 } else if (!strcmp(str, "TRACE_WARNING") || !strcmp(str, "WARNING")) {
269 return LTTNG_LOGLEVEL_WARNING;
270 } else if (!strcmp(str, "TRACE_NOTICE") || !strcmp(str, "NOTICE")) {
271 return LTTNG_LOGLEVEL_NOTICE;
272 } else if (!strcmp(str, "TRACE_INFO") || !strcmp(str, "INFO")) {
273 return LTTNG_LOGLEVEL_INFO;
274 } else if (!strcmp(str, "TRACE_DEBUG_SYSTEM") || !strcmp(str, "DEBUG_SYSTEM") || !strcmp(str, "SYSTEM")) {
275 return LTTNG_LOGLEVEL_DEBUG_SYSTEM;
276 } else if (!strcmp(str, "TRACE_DEBUG_PROGRAM") || !strcmp(str, "DEBUG_PROGRAM") || !strcmp(str, "PROGRAM")) {
277 return LTTNG_LOGLEVEL_DEBUG_PROGRAM;
278 } else if (!strcmp(str, "TRACE_DEBUG_PROCESS") || !strcmp(str, "DEBUG_PROCESS") || !strcmp(str, "PROCESS")) {
279 return LTTNG_LOGLEVEL_DEBUG_PROCESS;
280 } else if (!strcmp(str, "TRACE_DEBUG_MODULE") || !strcmp(str, "DEBUG_MODULE") || !strcmp(str, "MODULE")) {
281 return LTTNG_LOGLEVEL_DEBUG_MODULE;
282 } else if (!strcmp(str, "TRACE_DEBUG_UNIT") || !strcmp(str, "DEBUG_UNIT") || !strcmp(str, "UNIT")) {
283 return LTTNG_LOGLEVEL_DEBUG_UNIT;
284 } else if (!strcmp(str, "TRACE_DEBUG_FUNCTION") || !strcmp(str, "DEBUG_FUNCTION") || !strcmp(str, "FUNCTION")) {
285 return LTTNG_LOGLEVEL_DEBUG_FUNCTION;
286 } else if (!strcmp(str, "TRACE_DEBUG_LINE") || !strcmp(str, "DEBUG_LINE") || !strcmp(str, "LINE")) {
287 return LTTNG_LOGLEVEL_DEBUG_LINE;
288 } else if (!strcmp(str, "TRACE_DEBUG") || !strcmp(str, "DEBUG")) {
289 return LTTNG_LOGLEVEL_DEBUG;
290 } else {
291 return -1;
292 }
293 }
294
295 /*
296 * Enabling event using the lttng API.
297 */
298 static int enable_events(char *session_name)
299 {
300 int err, ret = CMD_SUCCESS, warn = 0;
301 char *event_name, *channel_name = NULL;
302 struct lttng_event ev;
303 struct lttng_domain dom;
304
305 memset(&ev, 0, sizeof(ev));
306 memset(&dom, 0, sizeof(dom));
307
308 if (opt_kernel) {
309 if (opt_filter) {
310 ERR("Filter not implement for kernel tracing yet");
311 ret = CMD_ERROR;
312 goto error;
313 }
314 }
315
316 /* Create lttng domain */
317 if (opt_kernel) {
318 dom.type = LTTNG_DOMAIN_KERNEL;
319 } else if (opt_userspace) {
320 dom.type = LTTNG_DOMAIN_UST;
321 } else {
322 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
323 ret = CMD_ERROR;
324 goto error;
325 }
326
327 if (opt_channel_name == NULL) {
328 err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
329 if (err < 0) {
330 ret = CMD_FATAL;
331 goto error;
332 }
333 } else {
334 channel_name = opt_channel_name;
335 }
336
337 handle = lttng_create_handle(session_name, &dom);
338 if (handle == NULL) {
339 ret = -1;
340 goto error;
341 }
342
343 if (opt_enable_all) {
344 /* Default setup for enable all */
345 if (opt_kernel) {
346 ev.type = opt_event_type;
347 ev.name[0] = '\0';
348 /* kernel loglevels not implemented */
349 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
350 } else {
351 ev.type = LTTNG_EVENT_TRACEPOINT;
352 strcpy(ev.name, "*");
353 ev.loglevel_type = opt_loglevel_type;
354 if (opt_loglevel) {
355 ev.loglevel = loglevel_str_to_value(opt_loglevel);
356 if (ev.loglevel == -1) {
357 ERR("Unknown loglevel %s", opt_loglevel);
358 ret = -1;
359 goto error;
360 }
361 } else {
362 ev.loglevel = -1;
363 }
364 }
365
366 ret = lttng_enable_event(handle, &ev, channel_name);
367 if (ret < 0) {
368 switch (-ret) {
369 case LTTCOMM_KERN_EVENT_EXIST:
370 WARN("Kernel events already enabled (channel %s, session %s)",
371 channel_name, session_name);
372 break;
373 default:
374 ERR("Events: %s (channel %s, session %s)",
375 lttng_strerror(ret), channel_name, session_name);
376 break;
377 }
378 goto end;
379 }
380 if (opt_filter) {
381 ret = lttng_set_event_filter(handle, ev.name, channel_name,
382 opt_filter);
383 if (ret < 0) {
384 ERR("Error setting filter");
385 ret = -1;
386 goto error;
387 }
388 }
389
390 switch (opt_event_type) {
391 case LTTNG_EVENT_TRACEPOINT:
392 if (opt_loglevel) {
393 MSG("All %s tracepoints are enabled in channel %s for loglevel %s",
394 opt_kernel ? "kernel" : "UST", channel_name,
395 opt_loglevel);
396 } else {
397 MSG("All %s tracepoints are enabled in channel %s",
398 opt_kernel ? "kernel" : "UST", channel_name);
399
400 }
401 break;
402 case LTTNG_EVENT_SYSCALL:
403 if (opt_kernel) {
404 MSG("All kernel system calls are enabled in channel %s",
405 channel_name);
406 }
407 break;
408 case LTTNG_EVENT_ALL:
409 if (opt_loglevel) {
410 MSG("All %s events are enabled in channel %s for loglevel %s",
411 opt_kernel ? "kernel" : "UST", channel_name,
412 opt_loglevel);
413 } else {
414 MSG("All %s events are enabled in channel %s",
415 opt_kernel ? "kernel" : "UST", channel_name);
416 }
417 break;
418 default:
419 /*
420 * We should not be here since lttng_enable_event should have
421 * failed on the event type.
422 */
423 goto error;
424 }
425 goto end;
426 }
427
428 /* Strip event list */
429 event_name = strtok(opt_event_list, ",");
430 while (event_name != NULL) {
431 /* Copy name and type of the event */
432 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
433 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
434 ev.type = opt_event_type;
435
436 /* Kernel tracer action */
437 if (opt_kernel) {
438 DBG("Enabling kernel event %s for channel %s",
439 event_name, channel_name);
440
441 switch (opt_event_type) {
442 case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */
443 ev.type = LTTNG_EVENT_TRACEPOINT;
444 /* Fall-through */
445 case LTTNG_EVENT_TRACEPOINT:
446 break;
447 case LTTNG_EVENT_PROBE:
448 ret = parse_probe_opts(&ev, opt_probe);
449 if (ret < 0) {
450 ERR("Unable to parse probe options");
451 ret = 0;
452 goto error;
453 }
454 break;
455 case LTTNG_EVENT_FUNCTION:
456 ret = parse_probe_opts(&ev, opt_function);
457 if (ret < 0) {
458 ERR("Unable to parse function probe options");
459 ret = 0;
460 goto error;
461 }
462 break;
463 case LTTNG_EVENT_FUNCTION_ENTRY:
464 strncpy(ev.attr.ftrace.symbol_name, opt_function_entry_symbol,
465 LTTNG_SYMBOL_NAME_LEN);
466 ev.attr.ftrace.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
467 break;
468 case LTTNG_EVENT_SYSCALL:
469 MSG("per-syscall selection not supported yet. Use \"-a\" "
470 "for all syscalls.");
471 default:
472 ret = CMD_UNDEFINED;
473 goto error;
474 }
475
476 if (opt_loglevel) {
477 MSG("Kernel loglevels are not supported.");
478 ret = CMD_UNDEFINED;
479 goto error;
480 }
481
482 /* kernel loglevels not implemented */
483 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
484 } else if (opt_userspace) { /* User-space tracer action */
485 #if 0
486 if (opt_cmd_name != NULL || opt_pid) {
487 MSG("Only supporting tracing all UST processes (-u) for now.");
488 ret = CMD_UNDEFINED;
489 goto error;
490 }
491 #endif
492
493 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name,
494 channel_name, opt_loglevel ? : "<all>");
495
496 switch (opt_event_type) {
497 case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */
498 /* Fall-through */
499 case LTTNG_EVENT_TRACEPOINT:
500 /* Copy name and type of the event */
501 ev.type = LTTNG_EVENT_TRACEPOINT;
502 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
503 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
504 break;
505 case LTTNG_EVENT_PROBE:
506 case LTTNG_EVENT_FUNCTION:
507 case LTTNG_EVENT_FUNCTION_ENTRY:
508 case LTTNG_EVENT_SYSCALL:
509 default:
510 ERR("Event type not available for user-space tracing");
511 ret = CMD_UNDEFINED;
512 goto error;
513 }
514
515 ev.loglevel_type = opt_loglevel_type;
516 if (opt_loglevel) {
517 ev.loglevel = loglevel_str_to_value(opt_loglevel);
518 if (ev.loglevel == -1) {
519 ERR("Unknown loglevel %s", opt_loglevel);
520 ret = -1;
521 goto error;
522 }
523 } else {
524 ev.loglevel = -1;
525 }
526 } else {
527 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
528 ret = CMD_ERROR;
529 goto error;
530 }
531
532 ret = lttng_enable_event(handle, &ev, channel_name);
533 if (ret < 0) {
534 /* Turn ret to positive value to handle the positive error code */
535 switch (-ret) {
536 case LTTCOMM_KERN_EVENT_EXIST:
537 WARN("Kernel event %s already enabled (channel %s, session %s)",
538 event_name, channel_name, session_name);
539 break;
540 default:
541 ERR("Event %s: %s (channel %s, session %s)", event_name,
542 lttng_strerror(ret), channel_name, session_name);
543 break;
544 }
545 warn = 1;
546 } else {
547 MSG("%s event %s created in channel %s",
548 opt_kernel ? "kernel": "UST", event_name, channel_name);
549 }
550 if (opt_filter) {
551 ret = lttng_set_event_filter(handle, ev.name,
552 channel_name, opt_filter);
553 if (ret < 0) {
554 ERR("Error setting filter");
555 ret = -1;
556 goto error;
557 }
558 }
559
560 /* Next event */
561 event_name = strtok(NULL, ",");
562 }
563
564 end:
565 error:
566 if (warn) {
567 ret = CMD_WARNING;
568 }
569 if (opt_channel_name == NULL) {
570 free(channel_name);
571 }
572 lttng_destroy_handle(handle);
573
574 return ret;
575 }
576
577 /*
578 * Add event to trace session
579 */
580 int cmd_enable_events(int argc, const char **argv)
581 {
582 int opt, ret = CMD_SUCCESS;
583 static poptContext pc;
584 char *session_name = NULL;
585
586 pc = poptGetContext(NULL, argc, argv, long_options, 0);
587 poptReadDefaultConfig(pc, 0);
588
589 /* Default event type */
590 opt_event_type = LTTNG_EVENT_ALL;
591
592 while ((opt = poptGetNextOpt(pc)) != -1) {
593 switch (opt) {
594 case OPT_HELP:
595 usage(stdout);
596 goto end;
597 case OPT_TRACEPOINT:
598 opt_event_type = LTTNG_EVENT_TRACEPOINT;
599 break;
600 case OPT_PROBE:
601 opt_event_type = LTTNG_EVENT_PROBE;
602 break;
603 case OPT_FUNCTION:
604 opt_event_type = LTTNG_EVENT_FUNCTION;
605 break;
606 case OPT_FUNCTION_ENTRY:
607 opt_event_type = LTTNG_EVENT_FUNCTION_ENTRY;
608 break;
609 case OPT_SYSCALL:
610 opt_event_type = LTTNG_EVENT_SYSCALL;
611 break;
612 case OPT_USERSPACE:
613 opt_userspace = 1;
614 break;
615 case OPT_LOGLEVEL:
616 opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE;
617 opt_loglevel = poptGetOptArg(pc);
618 break;
619 case OPT_LOGLEVEL_ONLY:
620 opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE;
621 opt_loglevel = poptGetOptArg(pc);
622 break;
623 case OPT_LIST_OPTIONS:
624 list_cmd_options(stdout, long_options);
625 goto end;
626 case OPT_FILTER:
627 break;
628 default:
629 usage(stderr);
630 ret = CMD_UNDEFINED;
631 goto end;
632 }
633 }
634
635 opt_event_list = (char*) poptGetArg(pc);
636 if (opt_event_list == NULL && opt_enable_all == 0) {
637 ERR("Missing event name(s).\n");
638 usage(stderr);
639 ret = CMD_ERROR;
640 goto end;
641 }
642
643 if (!opt_session_name) {
644 session_name = get_session_name();
645 if (session_name == NULL) {
646 ret = CMD_ERROR;
647 goto end;
648 }
649 } else {
650 session_name = opt_session_name;
651 }
652
653 ret = enable_events(session_name);
654
655 end:
656 if (opt_session_name == NULL) {
657 free(session_name);
658 }
659
660 poptFreeContext(pc);
661 return ret;
662 }
This page took 0.066086 seconds and 3 git commands to generate.