2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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.
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.
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.
24 #include <sys/types.h>
29 #include "../command.h"
30 #include <src/common/sessiond-comm/sessiond-comm.h>
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
;
40 static int opt_enable_all
;
41 static char *opt_probe
;
42 static char *opt_function
;
43 static char *opt_function_entry_symbol
;
44 static char *opt_channel_name
;
45 static char *opt_filter
;
46 static char *opt_exclude
;
48 /* Not implemented yet */
49 static char *opt_cmd_name
;
68 static struct lttng_handle
*handle
;
70 static struct poptOption long_options
[] = {
71 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
72 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
73 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
74 {"all", 'a', POPT_ARG_VAL
, &opt_enable_all
, 1, 0, 0},
75 {"channel", 'c', POPT_ARG_STRING
, &opt_channel_name
, 0, 0, 0},
76 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
77 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
78 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
79 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
80 {"probe", 0, POPT_ARG_STRING
, &opt_probe
, OPT_PROBE
, 0, 0},
81 {"function", 0, POPT_ARG_STRING
, &opt_function
, OPT_FUNCTION
, 0, 0},
84 * Currently removed from lttng kernel tracer. Removed from
85 * lttng UI to discourage its use.
87 {"function:entry", 0, POPT_ARG_STRING
, &opt_function_entry_symbol
, OPT_FUNCTION_ENTRY
, 0, 0},
89 {"syscall", 0, POPT_ARG_NONE
, 0, OPT_SYSCALL
, 0, 0},
90 {"loglevel", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL
, 0, 0},
91 {"loglevel-only", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL_ONLY
, 0, 0},
92 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
93 {"filter", 'f', POPT_ARG_STRING
, &opt_filter
, OPT_FILTER
, 0, 0},
94 {"exclude", 'x', POPT_ARG_STRING
, &opt_exclude
, OPT_EXCLUDE
, 0, 0},
101 static void usage(FILE *ofp
)
103 fprintf(ofp
, "usage: lttng enable-event NAME[,NAME2,...] [-k|-u] [OPTIONS] \n");
105 fprintf(ofp
, "Options:\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 NAME Apply to session name\n");
109 fprintf(ofp
, " -c, --channel NAME 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 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
113 fprintf(ofp
, " -j, --jul Apply for Java application using JUL\n");
115 fprintf(ofp
, "Event options:\n");
116 fprintf(ofp
, " --tracepoint Tracepoint event (default)\n");
117 fprintf(ofp
, " - userspace tracer supports wildcards at end of string.\n");
118 fprintf(ofp
, " Don't forget to quote to deal with bash expansion.\n");
119 fprintf(ofp
, " e.g.:\n");
120 fprintf(ofp
, " \"*\"\n");
121 fprintf(ofp
, " \"app_component:na*\"\n");
122 fprintf(ofp
, " --probe (addr | symbol | symbol+offset)\n");
123 fprintf(ofp
, " Dynamic probe.\n");
124 fprintf(ofp
, " Addr and offset can be octal (0NNN...),\n");
125 fprintf(ofp
, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
126 fprintf(ofp
, " --function (addr | symbol | symbol+offset)\n");
127 fprintf(ofp
, " Dynamic function entry/return probe.\n");
128 fprintf(ofp
, " Addr and offset can be octal (0NNN...),\n");
129 fprintf(ofp
, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
131 fprintf(ofp
, " --function:entry symbol\n");
132 fprintf(ofp
, " Function tracer event\n");
134 fprintf(ofp
, " --syscall System call event\n");
136 fprintf(ofp
, " --loglevel name\n");
137 fprintf(ofp
, " Tracepoint loglevel range from 0 to loglevel\n");
138 fprintf(ofp
, " --loglevel-only name\n");
139 fprintf(ofp
, " Tracepoint loglevel (only this loglevel)\n");
141 fprintf(ofp
, " The loglevel or loglevel-only options should be\n");
142 fprintf(ofp
, " combined with a tracepoint name or tracepoint\n");
143 fprintf(ofp
, " wildcard.\n");
144 fprintf(ofp
, " Available loglevels:\n");
145 fprintf(ofp
, " (higher value is more verbose)\n");
146 fprintf(ofp
, " TRACE_EMERG = 0\n");
147 fprintf(ofp
, " TRACE_ALERT = 1\n");
148 fprintf(ofp
, " TRACE_CRIT = 2\n");
149 fprintf(ofp
, " TRACE_ERR = 3\n");
150 fprintf(ofp
, " TRACE_WARNING = 4\n");
151 fprintf(ofp
, " TRACE_NOTICE = 5\n");
152 fprintf(ofp
, " TRACE_INFO = 6\n");
153 fprintf(ofp
, " TRACE_DEBUG_SYSTEM = 7\n");
154 fprintf(ofp
, " TRACE_DEBUG_PROGRAM = 8\n");
155 fprintf(ofp
, " TRACE_DEBUG_PROCESS = 9\n");
156 fprintf(ofp
, " TRACE_DEBUG_MODULE = 10\n");
157 fprintf(ofp
, " TRACE_DEBUG_UNIT = 11\n");
158 fprintf(ofp
, " TRACE_DEBUG_FUNCTION = 12\n");
159 fprintf(ofp
, " TRACE_DEBUG_LINE = 13\n");
160 fprintf(ofp
, " TRACE_DEBUG = 14\n");
161 fprintf(ofp
, " (shortcuts such as \"system\" are allowed)\n");
162 fprintf(ofp
, " -f, --filter \'expression\'\n");
163 fprintf(ofp
, " Filter expression on event fields and context.\n");
164 fprintf(ofp
, " Event recording depends on evaluation.\n");
165 fprintf(ofp
, " Only specify on first activation of\n");
166 fprintf(ofp
, " a given event within a session.\n");
167 fprintf(ofp
, " Filter only allowed when enabling\n");
168 fprintf(ofp
, " events within a session before tracing\n");
169 fprintf(ofp
, " is started. If the filter fails to link\n");
170 fprintf(ofp
, " with the event within the traced domain,\n");
171 fprintf(ofp
, " the event will be discarded. Currently,\n");
172 fprintf(ofp
, " filter is only implemented for the user-space\n");
173 fprintf(ofp
, " tracer.\n");
174 fprintf(ofp
, " Expression examples:.\n");
176 fprintf(ofp
, " 'intfield > 500 && intfield < 503'\n");
177 fprintf(ofp
, " '(strfield == \"test\" || intfield != 10) && intfield > 33'\n");
178 fprintf(ofp
, " 'doublefield > 1.1 && intfield < 5.3'\n");
180 fprintf(ofp
, " Wildcards are allowed at the end of strings:\n");
181 fprintf(ofp
, " 'seqfield1 == \"te*\"'\n");
182 fprintf(ofp
, " In string literals, the escape character is '\\'.\n");
183 fprintf(ofp
, " Use '\\*' for the '*' character, and '\\\\' for\n");
184 fprintf(ofp
, " the '\\' character. Wildcard match any sequence of,\n");
185 fprintf(ofp
, " characters including an empty sub-string (match 0 or\n");
186 fprintf(ofp
, " more characters).\n");
188 fprintf(ofp
, " Context information can be used for filtering. The\n");
189 fprintf(ofp
, " examples below show usage of context filtering on\n");
190 fprintf(ofp
, " process name (with a wildcard), process ID range, and\n");
191 fprintf(ofp
, " unique thread ID for filtering. The process and\n");
192 fprintf(ofp
, " thread ID of running applications can be found under\n");
193 fprintf(ofp
, " columns \"PID\" and \"LWP\" of the \"ps -eLf\" command.\n");
195 fprintf(ofp
, " '$ctx.procname == \"demo*\"'\n");
196 fprintf(ofp
, " '$ctx.vpid >= 4433 && $ctx.vpid < 4455'\n");
197 fprintf(ofp
, " '$ctx.vtid == 1234'\n");
198 fprintf(ofp
, " -x, --exclude LIST\n");
199 fprintf(ofp
, " Add exclusions to UST tracepoints:\n");
200 fprintf(ofp
, " Events that match any of the items\n");
201 fprintf(ofp
, " in the comma-separated LIST are not\n");
202 fprintf(ofp
, " enabled, even if they match a wildcard\n");
203 fprintf(ofp
, " definition of the event.\n");
208 * Parse probe options.
210 static int parse_probe_opts(struct lttng_event
*ev
, char *opt
)
214 char name
[LTTNG_SYMBOL_NAME_LEN
];
221 /* Check for symbol+offset */
222 ret
= sscanf(opt
, "%[^'+']+%s", name
, s_hex
);
224 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
225 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
226 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
227 if (*s_hex
== '\0') {
228 ERR("Invalid probe offset %s", s_hex
);
232 ev
->attr
.probe
.offset
= strtoul(s_hex
, NULL
, 0);
233 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
234 ev
->attr
.probe
.addr
= 0;
238 /* Check for symbol */
239 if (isalpha(name
[0])) {
240 ret
= sscanf(opt
, "%s", name
);
242 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
243 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
244 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
245 ev
->attr
.probe
.offset
= 0;
246 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
247 ev
->attr
.probe
.addr
= 0;
252 /* Check for address */
253 ret
= sscanf(opt
, "%s", s_hex
);
255 if (*s_hex
== '\0') {
256 ERR("Invalid probe address %s", s_hex
);
260 ev
->attr
.probe
.addr
= strtoul(s_hex
, NULL
, 0);
261 DBG("probe addr %" PRIu64
, ev
->attr
.probe
.addr
);
262 ev
->attr
.probe
.offset
= 0;
263 memset(ev
->attr
.probe
.symbol_name
, 0, LTTNG_SYMBOL_NAME_LEN
);
275 * Maps loglevel from string to value
278 int loglevel_str_to_value(const char *inputstr
)
281 char str
[LTTNG_SYMBOL_NAME_LEN
];
284 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
285 * added at the end of the loop so a the upper bound we avoid the overflow.
287 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
288 str
[i
] = toupper(inputstr
[i
]);
292 if (!strcmp(str
, "TRACE_EMERG") || !strcmp(str
, "EMERG")) {
293 return LTTNG_LOGLEVEL_EMERG
;
294 } else if (!strcmp(str
, "TRACE_ALERT") || !strcmp(str
, "ALERT")) {
295 return LTTNG_LOGLEVEL_ALERT
;
296 } else if (!strcmp(str
, "TRACE_CRIT") || !strcmp(str
, "CRIT")) {
297 return LTTNG_LOGLEVEL_CRIT
;
298 } else if (!strcmp(str
, "TRACE_ERR") || !strcmp(str
, "ERR")) {
299 return LTTNG_LOGLEVEL_ERR
;
300 } else if (!strcmp(str
, "TRACE_WARNING") || !strcmp(str
, "WARNING")) {
301 return LTTNG_LOGLEVEL_WARNING
;
302 } else if (!strcmp(str
, "TRACE_NOTICE") || !strcmp(str
, "NOTICE")) {
303 return LTTNG_LOGLEVEL_NOTICE
;
304 } else if (!strcmp(str
, "TRACE_INFO") || !strcmp(str
, "INFO")) {
305 return LTTNG_LOGLEVEL_INFO
;
306 } else if (!strcmp(str
, "TRACE_DEBUG_SYSTEM") || !strcmp(str
, "DEBUG_SYSTEM") || !strcmp(str
, "SYSTEM")) {
307 return LTTNG_LOGLEVEL_DEBUG_SYSTEM
;
308 } else if (!strcmp(str
, "TRACE_DEBUG_PROGRAM") || !strcmp(str
, "DEBUG_PROGRAM") || !strcmp(str
, "PROGRAM")) {
309 return LTTNG_LOGLEVEL_DEBUG_PROGRAM
;
310 } else if (!strcmp(str
, "TRACE_DEBUG_PROCESS") || !strcmp(str
, "DEBUG_PROCESS") || !strcmp(str
, "PROCESS")) {
311 return LTTNG_LOGLEVEL_DEBUG_PROCESS
;
312 } else if (!strcmp(str
, "TRACE_DEBUG_MODULE") || !strcmp(str
, "DEBUG_MODULE") || !strcmp(str
, "MODULE")) {
313 return LTTNG_LOGLEVEL_DEBUG_MODULE
;
314 } else if (!strcmp(str
, "TRACE_DEBUG_UNIT") || !strcmp(str
, "DEBUG_UNIT") || !strcmp(str
, "UNIT")) {
315 return LTTNG_LOGLEVEL_DEBUG_UNIT
;
316 } else if (!strcmp(str
, "TRACE_DEBUG_FUNCTION") || !strcmp(str
, "DEBUG_FUNCTION") || !strcmp(str
, "FUNCTION")) {
317 return LTTNG_LOGLEVEL_DEBUG_FUNCTION
;
318 } else if (!strcmp(str
, "TRACE_DEBUG_LINE") || !strcmp(str
, "DEBUG_LINE") || !strcmp(str
, "LINE")) {
319 return LTTNG_LOGLEVEL_DEBUG_LINE
;
320 } else if (!strcmp(str
, "TRACE_DEBUG") || !strcmp(str
, "DEBUG")) {
321 return LTTNG_LOGLEVEL_DEBUG
;
328 const char *print_channel_name(const char *name
)
330 return name
? : DEFAULT_CHANNEL_NAME
;
334 const char *print_raw_channel_name(const char *name
)
336 return name
? : "<default>";
340 * Return allocated string for pretty-printing exclusion names.
343 char *print_exclusions(int count
, char **names
)
347 const char *preamble
= " excluding ";
354 /* calculate total required length */
355 for (i
= 0; i
< count
; i
++) {
356 length
+= strlen(names
[i
]) + 1;
359 /* add length of preamble + one for NUL - one for last (missing) comma */
360 length
+= strlen(preamble
);
361 ret
= malloc(length
);
362 strncpy(ret
, preamble
, length
);
363 for (i
= 0; i
< count
; i
++) {
364 strcat(ret
, names
[i
]);
365 if (i
!= count
- 1) {
373 * Compare list of exclusions against an event name.
374 * Return a list of legal exclusion names.
375 * Produce an error or a warning about others (depending on the situation)
378 int check_exclusion_subsets(const char *event_name
,
379 const char *exclusions
,
380 int *exclusion_count_ptr
,
381 char ***exclusion_list_ptr
)
383 const char *excluder_ptr
;
384 const char *event_ptr
;
385 const char *next_excluder
;
387 int exclusion_count
= 0;
388 char **exclusion_list
= NULL
;
389 int ret
= CMD_SUCCESS
;
391 if (event_name
[strlen(event_name
) - 1] != '*') {
392 ERR("Event %s: Excluders can only be used with wildcarded events", event_name
);
396 next_excluder
= exclusions
;
397 while (*next_excluder
!= 0) {
398 event_ptr
= event_name
;
399 excluder_ptr
= next_excluder
;
400 excluder_length
= strcspn(next_excluder
, ",");
402 /* Scan both the excluder and the event letter by letter */
410 /* Event is a subset of the excluder */
411 ERR("Event %s: %.*s excludes all events from %s",
419 /* Excluder is a proper subset of event */
421 exclusion_list
= realloc(exclusion_list
, sizeof(char **) * exclusion_count
);
422 exclusion_list
[exclusion_count
- 1] = strndup(next_excluder
, excluder_length
);
427 /* Excluder and event sets have no common elements */
428 WARN("Event %s: %.*s does not exclude any events from %s",
439 next_excluder
+= excluder_length
;
440 if (*next_excluder
== ',') {
446 while (exclusion_count
--) {
447 free(exclusion_list
[exclusion_count
]);
449 if (exclusion_list
!= NULL
) {
450 free(exclusion_list
);
452 exclusion_list
= NULL
;
456 *exclusion_count_ptr
= exclusion_count
;
457 *exclusion_list_ptr
= exclusion_list
;
461 * Enabling event using the lttng API.
463 static int enable_events(char *session_name
)
465 int ret
= CMD_SUCCESS
, warn
= 0;
466 char *event_name
, *channel_name
= NULL
;
467 struct lttng_event ev
;
468 struct lttng_domain dom
;
469 int exclusion_count
= 0;
470 char **exclusion_list
= NULL
;
472 memset(&ev
, 0, sizeof(ev
));
473 memset(&dom
, 0, sizeof(dom
));
477 ERR("Filter not implement for kernel tracing yet");
482 WARN("Kernel loglevels are not supported.");
486 /* Create lttng domain */
488 dom
.type
= LTTNG_DOMAIN_KERNEL
;
489 dom
.buf_type
= LTTNG_BUFFER_GLOBAL
;
490 } else if (opt_userspace
) {
491 dom
.type
= LTTNG_DOMAIN_UST
;
493 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
494 } else if (opt_jul
) {
495 dom
.type
= LTTNG_DOMAIN_JUL
;
497 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
499 print_missing_domain();
504 if (opt_kernel
&& opt_exclude
) {
505 ERR("Event name exclusions are not yet implemented for kernel events");
510 channel_name
= opt_channel_name
;
512 handle
= lttng_create_handle(session_name
, &dom
);
513 if (handle
== NULL
) {
518 if (opt_enable_all
) {
519 /* Default setup for enable all */
521 ev
.type
= opt_event_type
;
523 /* kernel loglevels not implemented */
524 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
526 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
527 strcpy(ev
.name
, "*");
528 ev
.loglevel_type
= opt_loglevel_type
;
530 ev
.loglevel
= loglevel_str_to_value(opt_loglevel
);
531 if (ev
.loglevel
== -1) {
532 ERR("Unknown loglevel %s", opt_loglevel
);
533 ret
= -LTTNG_ERR_INVALID
;
542 ret
= check_exclusion_subsets("*", opt_exclude
,
543 &exclusion_count
, &exclusion_list
);
544 if (ret
== CMD_ERROR
) {
549 ret
= lttng_enable_event_with_exclusions(handle
,
552 exclusion_count
, exclusion_list
);
555 case LTTNG_ERR_KERN_EVENT_EXIST
:
556 WARN("Kernel events already enabled (channel %s, session %s)",
557 print_channel_name(channel_name
), session_name
);
560 ERR("Events: %s (channel %s, session %s)",
562 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
563 ? print_raw_channel_name(channel_name
)
564 : print_channel_name(channel_name
),
571 switch (opt_event_type
) {
572 case LTTNG_EVENT_TRACEPOINT
:
573 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
574 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
575 MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
576 get_domain_str(dom
.type
),
578 print_channel_name(channel_name
),
580 free(exclusion_string
);
582 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
583 MSG("All %s tracepoints%s are enabled in channel %s",
584 get_domain_str(dom
.type
),
586 print_channel_name(channel_name
));
587 free(exclusion_string
);
590 case LTTNG_EVENT_SYSCALL
:
592 MSG("All kernel system calls are enabled in channel %s",
593 print_channel_name(channel_name
));
596 case LTTNG_EVENT_ALL
:
597 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
598 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
599 MSG("All %s events%s are enabled in channel %s for loglevel %s",
600 get_domain_str(dom
.type
),
602 print_channel_name(channel_name
),
604 free(exclusion_string
);
606 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
607 MSG("All %s events%s are enabled in channel %s",
608 get_domain_str(dom
.type
),
610 print_channel_name(channel_name
));
611 free(exclusion_string
);
616 * We should not be here since lttng_enable_event should have
617 * failed on the event type.
623 ret
= lttng_enable_event_with_exclusions(handle
, &ev
, channel_name
,
624 opt_filter
, exclusion_count
, exclusion_list
);
627 case LTTNG_ERR_FILTER_EXIST
:
628 WARN("Filter on all events is already enabled"
629 " (channel %s, session %s)",
630 print_channel_name(channel_name
), session_name
);
633 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
635 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
636 ? print_raw_channel_name(channel_name
)
637 : print_channel_name(channel_name
),
638 session_name
, opt_filter
);
643 MSG("Filter '%s' successfully set", opt_filter
);
649 /* Strip event list */
650 event_name
= strtok(opt_event_list
, ",");
651 while (event_name
!= NULL
) {
652 /* Copy name and type of the event */
653 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
654 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
655 ev
.type
= opt_event_type
;
657 /* Kernel tracer action */
659 DBG("Enabling kernel event %s for channel %s",
661 print_channel_name(channel_name
));
663 switch (opt_event_type
) {
664 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
665 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
667 case LTTNG_EVENT_TRACEPOINT
:
669 case LTTNG_EVENT_PROBE
:
670 ret
= parse_probe_opts(&ev
, opt_probe
);
672 ERR("Unable to parse probe options");
677 case LTTNG_EVENT_FUNCTION
:
678 ret
= parse_probe_opts(&ev
, opt_function
);
680 ERR("Unable to parse function probe options");
685 case LTTNG_EVENT_FUNCTION_ENTRY
:
686 strncpy(ev
.attr
.ftrace
.symbol_name
, opt_function_entry_symbol
,
687 LTTNG_SYMBOL_NAME_LEN
);
688 ev
.attr
.ftrace
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
690 case LTTNG_EVENT_SYSCALL
:
691 MSG("per-syscall selection not supported yet. Use \"-a\" "
692 "for all syscalls.");
698 /* kernel loglevels not implemented */
699 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
700 } else if (opt_userspace
) { /* User-space tracer action */
702 if (opt_cmd_name
!= NULL
|| opt_pid
) {
703 MSG("Only supporting tracing all UST processes (-u) for now.");
709 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name
,
710 print_channel_name(channel_name
), opt_loglevel
? : "<all>");
712 switch (opt_event_type
) {
713 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
715 case LTTNG_EVENT_TRACEPOINT
:
716 /* Copy name and type of the event */
717 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
718 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
719 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
721 case LTTNG_EVENT_PROBE
:
722 case LTTNG_EVENT_FUNCTION
:
723 case LTTNG_EVENT_FUNCTION_ENTRY
:
724 case LTTNG_EVENT_SYSCALL
:
726 ERR("Event type not available for user-space tracing");
727 ret
= CMD_UNSUPPORTED
;
732 if (opt_event_type
!= LTTNG_EVENT_ALL
&& opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
733 ERR("Exclusion option can only be used with tracepoint events");
737 /* Free previously allocated items */
738 if (exclusion_list
!= NULL
) {
739 while (exclusion_count
--) {
740 free(exclusion_list
[exclusion_count
]);
742 free(exclusion_list
);
743 exclusion_list
= NULL
;
745 /* Check for proper subsets */
746 ret
= check_exclusion_subsets(event_name
, opt_exclude
,
747 &exclusion_count
, &exclusion_list
);
748 if (ret
== CMD_ERROR
) {
753 ev
.loglevel_type
= opt_loglevel_type
;
755 ev
.loglevel
= loglevel_str_to_value(opt_loglevel
);
756 if (ev
.loglevel
== -1) {
757 ERR("Unknown loglevel %s", opt_loglevel
);
758 ret
= -LTTNG_ERR_INVALID
;
764 } else if (opt_jul
) {
765 if (opt_event_type
!= LTTNG_EVENT_ALL
&&
766 opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
767 ERR("Event type not supported for JUL domain.");
768 ret
= CMD_UNSUPPORTED
;
771 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
772 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
773 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
775 print_missing_domain();
781 char *exclusion_string
;
783 ret
= lttng_enable_event_with_exclusions(handle
,
785 NULL
, exclusion_count
, exclusion_list
);
786 exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
788 /* Turn ret to positive value to handle the positive error code */
790 case LTTNG_ERR_KERN_EVENT_EXIST
:
791 WARN("Kernel event %s%s already enabled (channel %s, session %s)",
794 print_channel_name(channel_name
), session_name
);
797 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
800 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
801 ? print_raw_channel_name(channel_name
)
802 : print_channel_name(channel_name
),
808 MSG("%s event %s%s created in channel %s",
809 get_domain_str(dom
.type
), event_name
,
811 print_channel_name(channel_name
));
813 free(exclusion_string
);
817 char *exclusion_string
;
819 ret
= lttng_enable_event_with_exclusions(handle
, &ev
, channel_name
,
820 opt_filter
, exclusion_count
, exclusion_list
);
821 exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
825 case LTTNG_ERR_FILTER_EXIST
:
826 WARN("Filter on event %s%s is already enabled"
827 " (channel %s, session %s)",
830 print_channel_name(channel_name
), session_name
);
833 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
.name
,
836 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
837 ? print_raw_channel_name(channel_name
)
838 : print_channel_name(channel_name
),
839 session_name
, opt_filter
);
842 free(exclusion_string
);
845 MSG("Event %s%s: Filter '%s' successfully set",
846 event_name
, exclusion_string
,
849 free(exclusion_string
);
853 event_name
= strtok(NULL
, ",");
861 lttng_destroy_handle(handle
);
863 if (exclusion_list
!= NULL
) {
864 while (exclusion_count
--) {
865 free(exclusion_list
[exclusion_count
]);
867 free(exclusion_list
);
874 * Add event to trace session
876 int cmd_enable_events(int argc
, const char **argv
)
878 int opt
, ret
= CMD_SUCCESS
;
879 static poptContext pc
;
880 char *session_name
= NULL
;
883 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
884 poptReadDefaultConfig(pc
, 0);
886 /* Default event type */
887 opt_event_type
= LTTNG_EVENT_ALL
;
889 while ((opt
= poptGetNextOpt(pc
)) != -1) {
895 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
898 opt_event_type
= LTTNG_EVENT_PROBE
;
901 opt_event_type
= LTTNG_EVENT_FUNCTION
;
903 case OPT_FUNCTION_ENTRY
:
904 opt_event_type
= LTTNG_EVENT_FUNCTION_ENTRY
;
907 opt_event_type
= LTTNG_EVENT_SYSCALL
;
913 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
914 opt_loglevel
= poptGetOptArg(pc
);
916 case OPT_LOGLEVEL_ONLY
:
917 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
918 opt_loglevel
= poptGetOptArg(pc
);
920 case OPT_LIST_OPTIONS
:
921 list_cmd_options(stdout
, long_options
);
933 /* Validate event type. Multiple event type are not supported. */
934 if (event_type
== -1) {
935 event_type
= opt_event_type
;
937 if (event_type
!= opt_event_type
) {
938 ERR("Multiple event type not supported.");
945 opt_event_list
= (char*) poptGetArg(pc
);
946 if (opt_event_list
== NULL
&& opt_enable_all
== 0) {
947 ERR("Missing event name(s).\n");
953 if (!opt_session_name
) {
954 session_name
= get_session_name();
955 if (session_name
== NULL
) {
960 session_name
= opt_session_name
;
963 ret
= enable_events(session_name
);
966 if (opt_session_name
== NULL
) {