3f304a0902ad398bfddacc76ba97ca6595836685
[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, "\n");
172 }
173
174 /*
175 * Parse probe options.
176 */
177 static int parse_probe_opts(struct lttng_event *ev, char *opt)
178 {
179 int ret;
180 char s_hex[19];
181 char name[LTTNG_SYMBOL_NAME_LEN];
182
183 if (opt == NULL) {
184 ret = -1;
185 goto end;
186 }
187
188 /* Check for symbol+offset */
189 ret = sscanf(opt, "%[^'+']+%s", name, s_hex);
190 if (ret == 2) {
191 strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
192 ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
193 DBG("probe symbol %s", ev->attr.probe.symbol_name);
194 if (strlen(s_hex) == 0) {
195 ERR("Invalid probe offset %s", s_hex);
196 ret = -1;
197 goto end;
198 }
199 ev->attr.probe.offset = strtoul(s_hex, NULL, 0);
200 DBG("probe offset %" PRIu64, ev->attr.probe.offset);
201 ev->attr.probe.addr = 0;
202 goto end;
203 }
204
205 /* Check for symbol */
206 if (isalpha(name[0])) {
207 ret = sscanf(opt, "%s", name);
208 if (ret == 1) {
209 strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
210 ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
211 DBG("probe symbol %s", ev->attr.probe.symbol_name);
212 ev->attr.probe.offset = 0;
213 DBG("probe offset %" PRIu64, ev->attr.probe.offset);
214 ev->attr.probe.addr = 0;
215 goto end;
216 }
217 }
218
219 /* Check for address */
220 ret = sscanf(opt, "%s", s_hex);
221 if (ret > 0) {
222 if (strlen(s_hex) == 0) {
223 ERR("Invalid probe address %s", s_hex);
224 ret = -1;
225 goto end;
226 }
227 ev->attr.probe.addr = strtoul(s_hex, NULL, 0);
228 DBG("probe addr %" PRIu64, ev->attr.probe.addr);
229 ev->attr.probe.offset = 0;
230 memset(ev->attr.probe.symbol_name, 0, LTTNG_SYMBOL_NAME_LEN);
231 goto end;
232 }
233
234 /* No match */
235 ret = -1;
236
237 end:
238 return ret;
239 }
240
241 /*
242 * Maps loglevel from string to value
243 */
244 static
245 int loglevel_str_to_value(const char *inputstr)
246 {
247 int i = 0;
248 char str[LTTNG_SYMBOL_NAME_LEN];
249
250 while (inputstr[i] != '\0' && i < LTTNG_SYMBOL_NAME_LEN) {
251 str[i] = toupper(inputstr[i]);
252 i++;
253 }
254 str[i] = '\0';
255 if (!strcmp(str, "TRACE_EMERG") || !strcmp(str, "EMERG")) {
256 return LTTNG_LOGLEVEL_EMERG;
257 } else if (!strcmp(str, "TRACE_ALERT") || !strcmp(str, "ALERT")) {
258 return LTTNG_LOGLEVEL_ALERT;
259 } else if (!strcmp(str, "TRACE_CRIT") || !strcmp(str, "CRIT")) {
260 return LTTNG_LOGLEVEL_CRIT;
261 } else if (!strcmp(str, "TRACE_ERR") || !strcmp(str, "ERR")) {
262 return LTTNG_LOGLEVEL_ERR;
263 } else if (!strcmp(str, "TRACE_WARNING") || !strcmp(str, "WARNING")) {
264 return LTTNG_LOGLEVEL_WARNING;
265 } else if (!strcmp(str, "TRACE_NOTICE") || !strcmp(str, "NOTICE")) {
266 return LTTNG_LOGLEVEL_NOTICE;
267 } else if (!strcmp(str, "TRACE_INFO") || !strcmp(str, "INFO")) {
268 return LTTNG_LOGLEVEL_INFO;
269 } else if (!strcmp(str, "TRACE_DEBUG_SYSTEM") || !strcmp(str, "DEBUG_SYSTEM") || !strcmp(str, "SYSTEM")) {
270 return LTTNG_LOGLEVEL_DEBUG_SYSTEM;
271 } else if (!strcmp(str, "TRACE_DEBUG_PROGRAM") || !strcmp(str, "DEBUG_PROGRAM") || !strcmp(str, "PROGRAM")) {
272 return LTTNG_LOGLEVEL_DEBUG_PROGRAM;
273 } else if (!strcmp(str, "TRACE_DEBUG_PROCESS") || !strcmp(str, "DEBUG_PROCESS") || !strcmp(str, "PROCESS")) {
274 return LTTNG_LOGLEVEL_DEBUG_PROCESS;
275 } else if (!strcmp(str, "TRACE_DEBUG_MODULE") || !strcmp(str, "DEBUG_MODULE") || !strcmp(str, "MODULE")) {
276 return LTTNG_LOGLEVEL_DEBUG_MODULE;
277 } else if (!strcmp(str, "TRACE_DEBUG_UNIT") || !strcmp(str, "DEBUG_UNIT") || !strcmp(str, "UNIT")) {
278 return LTTNG_LOGLEVEL_DEBUG_UNIT;
279 } else if (!strcmp(str, "TRACE_DEBUG_FUNCTION") || !strcmp(str, "DEBUG_FUNCTION") || !strcmp(str, "FUNCTION")) {
280 return LTTNG_LOGLEVEL_DEBUG_FUNCTION;
281 } else if (!strcmp(str, "TRACE_DEBUG_LINE") || !strcmp(str, "DEBUG_LINE") || !strcmp(str, "LINE")) {
282 return LTTNG_LOGLEVEL_DEBUG_LINE;
283 } else if (!strcmp(str, "TRACE_DEBUG") || !strcmp(str, "DEBUG")) {
284 return LTTNG_LOGLEVEL_DEBUG;
285 } else {
286 return -1;
287 }
288 }
289
290 /*
291 * Enabling event using the lttng API.
292 */
293 static int enable_events(char *session_name)
294 {
295 int err, ret = CMD_SUCCESS, warn = 0;
296 char *event_name, *channel_name = NULL;
297 struct lttng_event ev;
298 struct lttng_domain dom;
299
300 memset(&ev, 0, sizeof(ev));
301 memset(&dom, 0, sizeof(dom));
302
303 if (opt_kernel) {
304 if (opt_filter) {
305 ERR("Filter not implement for kernel tracing yet");
306 ret = CMD_ERROR;
307 goto error;
308 }
309 }
310
311 /* Create lttng domain */
312 if (opt_kernel) {
313 dom.type = LTTNG_DOMAIN_KERNEL;
314 } else if (opt_userspace) {
315 dom.type = LTTNG_DOMAIN_UST;
316 } else {
317 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
318 ret = CMD_ERROR;
319 goto error;
320 }
321
322 if (opt_channel_name == NULL) {
323 err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
324 if (err < 0) {
325 ret = CMD_FATAL;
326 goto error;
327 }
328 } else {
329 channel_name = opt_channel_name;
330 }
331
332 handle = lttng_create_handle(session_name, &dom);
333 if (handle == NULL) {
334 ret = -1;
335 goto error;
336 }
337
338 if (opt_enable_all) {
339 /* Default setup for enable all */
340 if (opt_kernel) {
341 ev.type = opt_event_type;
342 ev.name[0] = '\0';
343 /* kernel loglevels not implemented */
344 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
345 } else {
346 ev.type = LTTNG_EVENT_TRACEPOINT;
347 strcpy(ev.name, "*");
348 ev.loglevel_type = opt_loglevel_type;
349 if (opt_loglevel) {
350 ev.loglevel = loglevel_str_to_value(opt_loglevel);
351 if (ev.loglevel == -1) {
352 ERR("Unknown loglevel %s", opt_loglevel);
353 ret = -1;
354 goto error;
355 }
356 } else {
357 ev.loglevel = -1;
358 }
359 }
360
361 ret = lttng_enable_event(handle, &ev, channel_name);
362 if (ret < 0) {
363 switch (-ret) {
364 case LTTCOMM_KERN_EVENT_EXIST:
365 WARN("Kernel events already enabled (channel %s, session %s)",
366 channel_name, session_name);
367 break;
368 default:
369 ERR("Events: %s (channel %s, session %s)",
370 lttng_strerror(ret), channel_name, session_name);
371 break;
372 }
373 goto end;
374 }
375 if (opt_filter) {
376 ret = lttng_set_event_filter(handle, ev.name, channel_name,
377 opt_filter);
378 if (ret < 0) {
379 ERR("Error setting filter");
380 ret = -1;
381 goto error;
382 }
383 }
384
385 switch (opt_event_type) {
386 case LTTNG_EVENT_TRACEPOINT:
387 if (opt_loglevel) {
388 MSG("All %s tracepoints are enabled in channel %s for loglevel %s",
389 opt_kernel ? "kernel" : "UST", channel_name,
390 opt_loglevel);
391 } else {
392 MSG("All %s tracepoints are enabled in channel %s",
393 opt_kernel ? "kernel" : "UST", channel_name);
394
395 }
396 break;
397 case LTTNG_EVENT_SYSCALL:
398 if (opt_kernel) {
399 MSG("All kernel system calls are enabled in channel %s",
400 channel_name);
401 }
402 break;
403 case LTTNG_EVENT_ALL:
404 if (opt_loglevel) {
405 MSG("All %s events are enabled in channel %s for loglevel %s",
406 opt_kernel ? "kernel" : "UST", channel_name,
407 opt_loglevel);
408 } else {
409 MSG("All %s events are enabled in channel %s",
410 opt_kernel ? "kernel" : "UST", channel_name);
411 }
412 break;
413 default:
414 /*
415 * We should not be here since lttng_enable_event should have
416 * failed on the event type.
417 */
418 goto error;
419 }
420 goto end;
421 }
422
423 /* Strip event list */
424 event_name = strtok(opt_event_list, ",");
425 while (event_name != NULL) {
426 /* Copy name and type of the event */
427 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
428 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
429 ev.type = opt_event_type;
430
431 /* Kernel tracer action */
432 if (opt_kernel) {
433 DBG("Enabling kernel event %s for channel %s",
434 event_name, channel_name);
435
436 switch (opt_event_type) {
437 case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */
438 ev.type = LTTNG_EVENT_TRACEPOINT;
439 /* Fall-through */
440 case LTTNG_EVENT_TRACEPOINT:
441 break;
442 case LTTNG_EVENT_PROBE:
443 ret = parse_probe_opts(&ev, opt_probe);
444 if (ret < 0) {
445 ERR("Unable to parse probe options");
446 ret = 0;
447 goto error;
448 }
449 break;
450 case LTTNG_EVENT_FUNCTION:
451 ret = parse_probe_opts(&ev, opt_function);
452 if (ret < 0) {
453 ERR("Unable to parse function probe options");
454 ret = 0;
455 goto error;
456 }
457 break;
458 case LTTNG_EVENT_FUNCTION_ENTRY:
459 strncpy(ev.attr.ftrace.symbol_name, opt_function_entry_symbol,
460 LTTNG_SYMBOL_NAME_LEN);
461 ev.attr.ftrace.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
462 break;
463 case LTTNG_EVENT_SYSCALL:
464 MSG("per-syscall selection not supported yet. Use \"-a\" "
465 "for all syscalls.");
466 default:
467 ret = CMD_UNDEFINED;
468 goto error;
469 }
470
471 if (opt_loglevel) {
472 MSG("Kernel loglevels are not supported.");
473 ret = CMD_UNDEFINED;
474 goto error;
475 }
476
477 /* kernel loglevels not implemented */
478 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
479 } else if (opt_userspace) { /* User-space tracer action */
480 #if 0
481 if (opt_cmd_name != NULL || opt_pid) {
482 MSG("Only supporting tracing all UST processes (-u) for now.");
483 ret = CMD_UNDEFINED;
484 goto error;
485 }
486 #endif
487
488 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name,
489 channel_name, opt_loglevel ? : "<all>");
490
491 switch (opt_event_type) {
492 case LTTNG_EVENT_ALL: /* Default behavior is tracepoint */
493 /* Fall-through */
494 case LTTNG_EVENT_TRACEPOINT:
495 /* Copy name and type of the event */
496 ev.type = LTTNG_EVENT_TRACEPOINT;
497 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
498 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
499 break;
500 case LTTNG_EVENT_PROBE:
501 case LTTNG_EVENT_FUNCTION:
502 case LTTNG_EVENT_FUNCTION_ENTRY:
503 case LTTNG_EVENT_SYSCALL:
504 default:
505 ERR("Event type not available for user-space tracing");
506 ret = CMD_UNDEFINED;
507 goto error;
508 }
509
510 ev.loglevel_type = opt_loglevel_type;
511 if (opt_loglevel) {
512 ev.loglevel = loglevel_str_to_value(opt_loglevel);
513 if (ev.loglevel == -1) {
514 ERR("Unknown loglevel %s", opt_loglevel);
515 ret = -1;
516 goto error;
517 }
518 } else {
519 ev.loglevel = -1;
520 }
521 } else {
522 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
523 ret = CMD_ERROR;
524 goto error;
525 }
526
527 ret = lttng_enable_event(handle, &ev, channel_name);
528 if (ret < 0) {
529 /* Turn ret to positive value to handle the positive error code */
530 switch (-ret) {
531 case LTTCOMM_KERN_EVENT_EXIST:
532 WARN("Kernel event %s already enabled (channel %s, session %s)",
533 event_name, channel_name, session_name);
534 break;
535 default:
536 ERR("Event %s: %s (channel %s, session %s)", event_name,
537 lttng_strerror(ret), channel_name, session_name);
538 break;
539 }
540 warn = 1;
541 } else {
542 MSG("%s event %s created in channel %s",
543 opt_kernel ? "kernel": "UST", event_name, channel_name);
544 }
545 if (opt_filter) {
546 ret = lttng_set_event_filter(handle, ev.name,
547 channel_name, opt_filter);
548 if (ret < 0) {
549 ERR("Error setting filter");
550 ret = -1;
551 goto error;
552 }
553 }
554
555 /* Next event */
556 event_name = strtok(NULL, ",");
557 }
558
559 end:
560 error:
561 if (warn) {
562 ret = CMD_WARNING;
563 }
564 if (opt_channel_name == NULL) {
565 free(channel_name);
566 }
567 lttng_destroy_handle(handle);
568
569 return ret;
570 }
571
572 /*
573 * Add event to trace session
574 */
575 int cmd_enable_events(int argc, const char **argv)
576 {
577 int opt, ret = CMD_SUCCESS;
578 static poptContext pc;
579 char *session_name = NULL;
580
581 pc = poptGetContext(NULL, argc, argv, long_options, 0);
582 poptReadDefaultConfig(pc, 0);
583
584 /* Default event type */
585 opt_event_type = LTTNG_EVENT_ALL;
586
587 while ((opt = poptGetNextOpt(pc)) != -1) {
588 switch (opt) {
589 case OPT_HELP:
590 usage(stdout);
591 goto end;
592 case OPT_TRACEPOINT:
593 opt_event_type = LTTNG_EVENT_TRACEPOINT;
594 break;
595 case OPT_PROBE:
596 opt_event_type = LTTNG_EVENT_PROBE;
597 break;
598 case OPT_FUNCTION:
599 opt_event_type = LTTNG_EVENT_FUNCTION;
600 break;
601 case OPT_FUNCTION_ENTRY:
602 opt_event_type = LTTNG_EVENT_FUNCTION_ENTRY;
603 break;
604 case OPT_SYSCALL:
605 opt_event_type = LTTNG_EVENT_SYSCALL;
606 break;
607 case OPT_USERSPACE:
608 opt_userspace = 1;
609 break;
610 case OPT_LOGLEVEL:
611 opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE;
612 opt_loglevel = poptGetOptArg(pc);
613 break;
614 case OPT_LOGLEVEL_ONLY:
615 opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE;
616 opt_loglevel = poptGetOptArg(pc);
617 break;
618 case OPT_LIST_OPTIONS:
619 list_cmd_options(stdout, long_options);
620 goto end;
621 case OPT_FILTER:
622 break;
623 default:
624 usage(stderr);
625 ret = CMD_UNDEFINED;
626 goto end;
627 }
628 }
629
630 opt_event_list = (char*) poptGetArg(pc);
631 if (opt_event_list == NULL && opt_enable_all == 0) {
632 ERR("Missing event name(s).\n");
633 usage(stderr);
634 ret = CMD_ERROR;
635 goto end;
636 }
637
638 if (!opt_session_name) {
639 session_name = get_session_name();
640 if (session_name == NULL) {
641 ret = CMD_ERROR;
642 goto end;
643 }
644 } else {
645 session_name = opt_session_name;
646 }
647
648 ret = enable_events(session_name);
649
650 end:
651 if (opt_session_name == NULL) {
652 free(session_name);
653 }
654
655 poptFreeContext(pc);
656 return ret;
657 }
This page took 0.0435 seconds and 4 git commands to generate.