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.
25 #include <sys/types.h>
30 #include "../command.h"
31 #include <src/common/sessiond-comm/sessiond-comm.h>
33 static char *opt_event_list
;
34 static int opt_event_type
;
35 static const char *opt_loglevel
;
36 static int opt_loglevel_type
;
37 static int opt_kernel
;
38 static char *opt_session_name
;
39 static int opt_userspace
;
41 static int opt_enable_all
;
42 static char *opt_probe
;
43 static char *opt_function
;
44 static char *opt_function_entry_symbol
;
45 static char *opt_channel_name
;
46 static char *opt_filter
;
47 static char *opt_exclude
;
49 /* Not implemented yet */
50 static char *opt_cmd_name
;
69 static struct lttng_handle
*handle
;
71 static struct poptOption long_options
[] = {
72 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
73 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
74 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
75 {"all", 'a', POPT_ARG_VAL
, &opt_enable_all
, 1, 0, 0},
76 {"channel", 'c', POPT_ARG_STRING
, &opt_channel_name
, 0, 0, 0},
77 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
78 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
79 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
80 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
81 {"probe", 0, POPT_ARG_STRING
, &opt_probe
, OPT_PROBE
, 0, 0},
82 {"function", 0, POPT_ARG_STRING
, &opt_function
, OPT_FUNCTION
, 0, 0},
85 * Currently removed from lttng kernel tracer. Removed from
86 * lttng UI to discourage its use.
88 {"function:entry", 0, POPT_ARG_STRING
, &opt_function_entry_symbol
, OPT_FUNCTION_ENTRY
, 0, 0},
90 {"syscall", 0, POPT_ARG_NONE
, 0, OPT_SYSCALL
, 0, 0},
91 {"loglevel", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL
, 0, 0},
92 {"loglevel-only", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL_ONLY
, 0, 0},
93 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
94 {"filter", 'f', POPT_ARG_STRING
, &opt_filter
, OPT_FILTER
, 0, 0},
95 {"exclude", 'x', POPT_ARG_STRING
, &opt_exclude
, OPT_EXCLUDE
, 0, 0},
102 static void usage(FILE *ofp
)
104 fprintf(ofp
, "usage: lttng enable-event NAME[,NAME2,...] [-k|-u] [OPTIONS] \n");
106 fprintf(ofp
, "Options:\n");
107 fprintf(ofp
, " -h, --help Show this help\n");
108 fprintf(ofp
, " --list-options Simple listing of options\n");
109 fprintf(ofp
, " -s, --session NAME Apply to session name\n");
110 fprintf(ofp
, " -c, --channel NAME Apply to this channel\n");
111 fprintf(ofp
, " -a, --all Enable all tracepoints and syscalls\n");
112 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
113 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
114 fprintf(ofp
, " -j, --jul Apply for Java application using JUL\n");
116 fprintf(ofp
, "Event options:\n");
117 fprintf(ofp
, " --tracepoint Tracepoint event (default)\n");
118 fprintf(ofp
, " - userspace tracer supports wildcards at end of string.\n");
119 fprintf(ofp
, " Don't forget to quote to deal with bash expansion.\n");
120 fprintf(ofp
, " e.g.:\n");
121 fprintf(ofp
, " \"*\"\n");
122 fprintf(ofp
, " \"app_component:na*\"\n");
123 fprintf(ofp
, " --probe (addr | symbol | symbol+offset)\n");
124 fprintf(ofp
, " Dynamic probe.\n");
125 fprintf(ofp
, " Addr and offset can be octal (0NNN...),\n");
126 fprintf(ofp
, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
127 fprintf(ofp
, " --function (addr | symbol | symbol+offset)\n");
128 fprintf(ofp
, " Dynamic function entry/return probe.\n");
129 fprintf(ofp
, " Addr and offset can be octal (0NNN...),\n");
130 fprintf(ofp
, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
132 fprintf(ofp
, " --function:entry symbol\n");
133 fprintf(ofp
, " Function tracer event\n");
135 fprintf(ofp
, " --syscall System call event\n");
137 fprintf(ofp
, " --loglevel name\n");
138 fprintf(ofp
, " Tracepoint loglevel range from 0 to loglevel\n");
139 fprintf(ofp
, " --loglevel-only name\n");
140 fprintf(ofp
, " Tracepoint loglevel (only this loglevel)\n");
142 fprintf(ofp
, " The loglevel or loglevel-only options should be\n");
143 fprintf(ofp
, " combined with a tracepoint name or tracepoint\n");
144 fprintf(ofp
, " wildcard.\n");
145 fprintf(ofp
, " Available loglevels:\n");
146 fprintf(ofp
, " (higher value is more verbose)\n");
147 fprintf(ofp
, " TRACE_EMERG = 0\n");
148 fprintf(ofp
, " TRACE_ALERT = 1\n");
149 fprintf(ofp
, " TRACE_CRIT = 2\n");
150 fprintf(ofp
, " TRACE_ERR = 3\n");
151 fprintf(ofp
, " TRACE_WARNING = 4\n");
152 fprintf(ofp
, " TRACE_NOTICE = 5\n");
153 fprintf(ofp
, " TRACE_INFO = 6\n");
154 fprintf(ofp
, " TRACE_DEBUG_SYSTEM = 7\n");
155 fprintf(ofp
, " TRACE_DEBUG_PROGRAM = 8\n");
156 fprintf(ofp
, " TRACE_DEBUG_PROCESS = 9\n");
157 fprintf(ofp
, " TRACE_DEBUG_MODULE = 10\n");
158 fprintf(ofp
, " TRACE_DEBUG_UNIT = 11\n");
159 fprintf(ofp
, " TRACE_DEBUG_FUNCTION = 12\n");
160 fprintf(ofp
, " TRACE_DEBUG_LINE = 13\n");
161 fprintf(ofp
, " TRACE_DEBUG = 14\n");
162 fprintf(ofp
, " (shortcuts such as \"system\" are allowed)\n");
164 fprintf(ofp
, " Available JUL domain loglevels:\n");
165 fprintf(ofp
, " JUL_OFF = INT32_MAX\n");
166 fprintf(ofp
, " JUL_SEVERE = %d\n", LTTNG_LOGLEVEL_JUL_SEVERE
);
167 fprintf(ofp
, " JUL_WARNING = %d\n", LTTNG_LOGLEVEL_JUL_WARNING
);
168 fprintf(ofp
, " JUL_INFO = %d\n", LTTNG_LOGLEVEL_JUL_INFO
);
169 fprintf(ofp
, " JUL_CONFIG = %d\n", LTTNG_LOGLEVEL_JUL_CONFIG
);
170 fprintf(ofp
, " JUL_FINE = %d\n", LTTNG_LOGLEVEL_JUL_FINE
);
171 fprintf(ofp
, " JUL_FINER = %d\n", LTTNG_LOGLEVEL_JUL_FINER
);
172 fprintf(ofp
, " JUL_FINEST = %d\n", LTTNG_LOGLEVEL_JUL_FINEST
);
173 fprintf(ofp
, " JUL_ALL = INT32_MIN\n");
174 fprintf(ofp
, " (shortcuts such as \"severe\" are allowed)\n");
176 fprintf(ofp
, " -f, --filter \'expression\'\n");
177 fprintf(ofp
, " Filter expression on event fields and context.\n");
178 fprintf(ofp
, " Event recording depends on evaluation.\n");
179 fprintf(ofp
, " Only specify on first activation of\n");
180 fprintf(ofp
, " a given event within a session.\n");
181 fprintf(ofp
, " Filter only allowed when enabling\n");
182 fprintf(ofp
, " events within a session before tracing\n");
183 fprintf(ofp
, " is started. If the filter fails to link\n");
184 fprintf(ofp
, " with the event within the traced domain,\n");
185 fprintf(ofp
, " the event will be discarded. Currently,\n");
186 fprintf(ofp
, " filter is only implemented for the user-space\n");
187 fprintf(ofp
, " tracer.\n");
188 fprintf(ofp
, " Expression examples:.\n");
190 fprintf(ofp
, " 'intfield > 500 && intfield < 503'\n");
191 fprintf(ofp
, " '(strfield == \"test\" || intfield != 10) && intfield > 33'\n");
192 fprintf(ofp
, " 'doublefield > 1.1 && intfield < 5.3'\n");
194 fprintf(ofp
, " Wildcards are allowed at the end of strings:\n");
195 fprintf(ofp
, " 'seqfield1 == \"te*\"'\n");
196 fprintf(ofp
, " In string literals, the escape character is '\\'.\n");
197 fprintf(ofp
, " Use '\\*' for the '*' character, and '\\\\' for\n");
198 fprintf(ofp
, " the '\\' character. Wildcard match any sequence of,\n");
199 fprintf(ofp
, " characters including an empty sub-string (match 0 or\n");
200 fprintf(ofp
, " more characters).\n");
202 fprintf(ofp
, " Context information can be used for filtering. The\n");
203 fprintf(ofp
, " examples below show usage of context filtering on\n");
204 fprintf(ofp
, " process name (with a wildcard), process ID range, and\n");
205 fprintf(ofp
, " unique thread ID for filtering. The process and\n");
206 fprintf(ofp
, " thread ID of running applications can be found under\n");
207 fprintf(ofp
, " columns \"PID\" and \"LWP\" of the \"ps -eLf\" command.\n");
209 fprintf(ofp
, " '$ctx.procname == \"demo*\"'\n");
210 fprintf(ofp
, " '$ctx.vpid >= 4433 && $ctx.vpid < 4455'\n");
211 fprintf(ofp
, " '$ctx.vtid == 1234'\n");
212 fprintf(ofp
, " -x, --exclude LIST\n");
213 fprintf(ofp
, " Add exclusions to UST tracepoints:\n");
214 fprintf(ofp
, " Events that match any of the items\n");
215 fprintf(ofp
, " in the comma-separated LIST are not\n");
216 fprintf(ofp
, " enabled, even if they match a wildcard\n");
217 fprintf(ofp
, " definition of the event.\n");
222 * Parse probe options.
224 static int parse_probe_opts(struct lttng_event
*ev
, char *opt
)
228 char name
[LTTNG_SYMBOL_NAME_LEN
];
235 /* Check for symbol+offset */
236 ret
= sscanf(opt
, "%[^'+']+%s", name
, s_hex
);
238 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
239 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
240 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
241 if (*s_hex
== '\0') {
242 ERR("Invalid probe offset %s", s_hex
);
246 ev
->attr
.probe
.offset
= strtoul(s_hex
, NULL
, 0);
247 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
248 ev
->attr
.probe
.addr
= 0;
252 /* Check for symbol */
253 if (isalpha(name
[0])) {
254 ret
= sscanf(opt
, "%s", name
);
256 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
257 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
258 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
259 ev
->attr
.probe
.offset
= 0;
260 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
261 ev
->attr
.probe
.addr
= 0;
266 /* Check for address */
267 ret
= sscanf(opt
, "%s", s_hex
);
269 if (*s_hex
== '\0') {
270 ERR("Invalid probe address %s", s_hex
);
274 ev
->attr
.probe
.addr
= strtoul(s_hex
, NULL
, 0);
275 DBG("probe addr %" PRIu64
, ev
->attr
.probe
.addr
);
276 ev
->attr
.probe
.offset
= 0;
277 memset(ev
->attr
.probe
.symbol_name
, 0, LTTNG_SYMBOL_NAME_LEN
);
289 * Maps JUL loglevel from string to value
291 static int loglevel_jul_str_to_value(const char *inputstr
)
294 char str
[LTTNG_SYMBOL_NAME_LEN
];
297 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
298 * added at the end of the loop so a the upper bound we avoid the overflow.
300 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
301 str
[i
] = toupper(inputstr
[i
]);
306 if (!strcmp(str
, "JUL_OFF") || !strcmp(str
, "OFF")) {
307 return LTTNG_LOGLEVEL_JUL_OFF
;
308 } else if (!strcmp(str
, "JUL_SEVERE") || !strcmp(str
, "SEVERE")) {
309 return LTTNG_LOGLEVEL_JUL_SEVERE
;
310 } else if (!strcmp(str
, "JUL_WARNING") || !strcmp(str
, "WARNING")) {
311 return LTTNG_LOGLEVEL_JUL_WARNING
;
312 } else if (!strcmp(str
, "JUL_INFO") || !strcmp(str
, "INFO")) {
313 return LTTNG_LOGLEVEL_JUL_INFO
;
314 } else if (!strcmp(str
, "JUL_CONFIG") || !strcmp(str
, "CONFIG")) {
315 return LTTNG_LOGLEVEL_JUL_CONFIG
;
316 } else if (!strcmp(str
, "JUL_FINE") || !strcmp(str
, "FINE")) {
317 return LTTNG_LOGLEVEL_JUL_FINE
;
318 } else if (!strcmp(str
, "JUL_FINER") || !strcmp(str
, "FINER")) {
319 return LTTNG_LOGLEVEL_JUL_FINER
;
320 } else if (!strcmp(str
, "JUL_FINEST") || !strcmp(str
, "FINEST")) {
321 return LTTNG_LOGLEVEL_JUL_FINEST
;
322 } else if (!strcmp(str
, "JUL_ALL") || !strcmp(str
, "ALL")) {
323 return LTTNG_LOGLEVEL_JUL_ALL
;
330 * Maps loglevel from string to value
333 int loglevel_str_to_value(const char *inputstr
)
336 char str
[LTTNG_SYMBOL_NAME_LEN
];
339 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
340 * added at the end of the loop so a the upper bound we avoid the overflow.
342 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
343 str
[i
] = toupper(inputstr
[i
]);
347 if (!strcmp(str
, "TRACE_EMERG") || !strcmp(str
, "EMERG")) {
348 return LTTNG_LOGLEVEL_EMERG
;
349 } else if (!strcmp(str
, "TRACE_ALERT") || !strcmp(str
, "ALERT")) {
350 return LTTNG_LOGLEVEL_ALERT
;
351 } else if (!strcmp(str
, "TRACE_CRIT") || !strcmp(str
, "CRIT")) {
352 return LTTNG_LOGLEVEL_CRIT
;
353 } else if (!strcmp(str
, "TRACE_ERR") || !strcmp(str
, "ERR")) {
354 return LTTNG_LOGLEVEL_ERR
;
355 } else if (!strcmp(str
, "TRACE_WARNING") || !strcmp(str
, "WARNING")) {
356 return LTTNG_LOGLEVEL_WARNING
;
357 } else if (!strcmp(str
, "TRACE_NOTICE") || !strcmp(str
, "NOTICE")) {
358 return LTTNG_LOGLEVEL_NOTICE
;
359 } else if (!strcmp(str
, "TRACE_INFO") || !strcmp(str
, "INFO")) {
360 return LTTNG_LOGLEVEL_INFO
;
361 } else if (!strcmp(str
, "TRACE_DEBUG_SYSTEM") || !strcmp(str
, "DEBUG_SYSTEM") || !strcmp(str
, "SYSTEM")) {
362 return LTTNG_LOGLEVEL_DEBUG_SYSTEM
;
363 } else if (!strcmp(str
, "TRACE_DEBUG_PROGRAM") || !strcmp(str
, "DEBUG_PROGRAM") || !strcmp(str
, "PROGRAM")) {
364 return LTTNG_LOGLEVEL_DEBUG_PROGRAM
;
365 } else if (!strcmp(str
, "TRACE_DEBUG_PROCESS") || !strcmp(str
, "DEBUG_PROCESS") || !strcmp(str
, "PROCESS")) {
366 return LTTNG_LOGLEVEL_DEBUG_PROCESS
;
367 } else if (!strcmp(str
, "TRACE_DEBUG_MODULE") || !strcmp(str
, "DEBUG_MODULE") || !strcmp(str
, "MODULE")) {
368 return LTTNG_LOGLEVEL_DEBUG_MODULE
;
369 } else if (!strcmp(str
, "TRACE_DEBUG_UNIT") || !strcmp(str
, "DEBUG_UNIT") || !strcmp(str
, "UNIT")) {
370 return LTTNG_LOGLEVEL_DEBUG_UNIT
;
371 } else if (!strcmp(str
, "TRACE_DEBUG_FUNCTION") || !strcmp(str
, "DEBUG_FUNCTION") || !strcmp(str
, "FUNCTION")) {
372 return LTTNG_LOGLEVEL_DEBUG_FUNCTION
;
373 } else if (!strcmp(str
, "TRACE_DEBUG_LINE") || !strcmp(str
, "DEBUG_LINE") || !strcmp(str
, "LINE")) {
374 return LTTNG_LOGLEVEL_DEBUG_LINE
;
375 } else if (!strcmp(str
, "TRACE_DEBUG") || !strcmp(str
, "DEBUG")) {
376 return LTTNG_LOGLEVEL_DEBUG
;
383 const char *print_channel_name(const char *name
)
385 return name
? : DEFAULT_CHANNEL_NAME
;
389 const char *print_raw_channel_name(const char *name
)
391 return name
? : "<default>";
395 * Return allocated string for pretty-printing exclusion names.
398 char *print_exclusions(int count
, char **names
)
402 const char *preamble
= " excluding ";
409 /* calculate total required length */
410 for (i
= 0; i
< count
; i
++) {
411 length
+= strlen(names
[i
]) + 1;
414 /* add length of preamble + one for NUL - one for last (missing) comma */
415 length
+= strlen(preamble
);
416 ret
= malloc(length
);
417 strncpy(ret
, preamble
, length
);
418 for (i
= 0; i
< count
; i
++) {
419 strcat(ret
, names
[i
]);
420 if (i
!= count
- 1) {
428 * Compare list of exclusions against an event name.
429 * Return a list of legal exclusion names.
430 * Produce an error or a warning about others (depending on the situation)
433 int check_exclusion_subsets(const char *event_name
,
434 const char *exclusions
,
435 int *exclusion_count_ptr
,
436 char ***exclusion_list_ptr
)
438 const char *excluder_ptr
;
439 const char *event_ptr
;
440 const char *next_excluder
;
442 int exclusion_count
= 0;
443 char **exclusion_list
= NULL
;
444 int ret
= CMD_SUCCESS
;
446 if (event_name
[strlen(event_name
) - 1] != '*') {
447 ERR("Event %s: Excluders can only be used with wildcarded events", event_name
);
451 next_excluder
= exclusions
;
452 while (*next_excluder
!= 0) {
453 event_ptr
= event_name
;
454 excluder_ptr
= next_excluder
;
455 excluder_length
= strcspn(next_excluder
, ",");
457 /* Scan both the excluder and the event letter by letter */
465 /* Event is a subset of the excluder */
466 ERR("Event %s: %.*s excludes all events from %s",
474 /* Excluder is a proper subset of event */
476 exclusion_list
= realloc(exclusion_list
, sizeof(char **) * exclusion_count
);
477 exclusion_list
[exclusion_count
- 1] = strndup(next_excluder
, excluder_length
);
482 /* Excluder and event sets have no common elements */
483 WARN("Event %s: %.*s does not exclude any events from %s",
494 next_excluder
+= excluder_length
;
495 if (*next_excluder
== ',') {
501 while (exclusion_count
--) {
502 free(exclusion_list
[exclusion_count
]);
504 if (exclusion_list
!= NULL
) {
505 free(exclusion_list
);
507 exclusion_list
= NULL
;
511 *exclusion_count_ptr
= exclusion_count
;
512 *exclusion_list_ptr
= exclusion_list
;
516 * Enabling event using the lttng API.
518 static int enable_events(char *session_name
)
520 int ret
= CMD_SUCCESS
, warn
= 0;
521 char *event_name
, *channel_name
= NULL
;
522 struct lttng_event ev
;
523 struct lttng_domain dom
;
524 int exclusion_count
= 0;
525 char **exclusion_list
= NULL
;
527 memset(&ev
, 0, sizeof(ev
));
528 memset(&dom
, 0, sizeof(dom
));
532 ERR("Filter not implement for kernel tracing yet");
537 WARN("Kernel loglevels are not supported.");
541 /* Create lttng domain */
543 dom
.type
= LTTNG_DOMAIN_KERNEL
;
544 dom
.buf_type
= LTTNG_BUFFER_GLOBAL
;
545 } else if (opt_userspace
) {
546 dom
.type
= LTTNG_DOMAIN_UST
;
548 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
549 } else if (opt_jul
) {
550 dom
.type
= LTTNG_DOMAIN_JUL
;
552 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
554 print_missing_domain();
559 if (opt_kernel
&& opt_exclude
) {
560 ERR("Event name exclusions are not yet implemented for kernel events");
565 channel_name
= opt_channel_name
;
567 handle
= lttng_create_handle(session_name
, &dom
);
568 if (handle
== NULL
) {
573 if (opt_enable_all
) {
574 /* Default setup for enable all */
576 ev
.type
= opt_event_type
;
578 /* kernel loglevels not implemented */
579 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
581 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
582 strcpy(ev
.name
, "*");
583 ev
.loglevel_type
= opt_loglevel_type
;
585 assert(opt_userspace
|| opt_jul
);
587 ev
.loglevel
= loglevel_str_to_value(opt_loglevel
);
588 } else if (opt_jul
) {
589 ev
.loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
591 if (ev
.loglevel
== -1) {
592 ERR("Unknown loglevel %s", opt_loglevel
);
593 ret
= -LTTNG_ERR_INVALID
;
597 assert(opt_userspace
|| opt_jul
);
600 } else if (opt_jul
) {
601 ev
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
607 ret
= check_exclusion_subsets("*", opt_exclude
,
608 &exclusion_count
, &exclusion_list
);
609 if (ret
== CMD_ERROR
) {
614 ret
= lttng_enable_event_with_exclusions(handle
,
617 exclusion_count
, exclusion_list
);
620 case LTTNG_ERR_KERN_EVENT_EXIST
:
621 WARN("Kernel events already enabled (channel %s, session %s)",
622 print_channel_name(channel_name
), session_name
);
625 ERR("Events: %s (channel %s, session %s)",
627 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
628 ? print_raw_channel_name(channel_name
)
629 : print_channel_name(channel_name
),
636 switch (opt_event_type
) {
637 case LTTNG_EVENT_TRACEPOINT
:
638 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
639 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
640 MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
641 get_domain_str(dom
.type
),
643 print_channel_name(channel_name
),
645 free(exclusion_string
);
647 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
648 MSG("All %s tracepoints%s are enabled in channel %s",
649 get_domain_str(dom
.type
),
651 print_channel_name(channel_name
));
652 free(exclusion_string
);
655 case LTTNG_EVENT_SYSCALL
:
657 MSG("All kernel system calls are enabled in channel %s",
658 print_channel_name(channel_name
));
661 case LTTNG_EVENT_ALL
:
662 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
663 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
664 MSG("All %s events%s are enabled in channel %s for loglevel %s",
665 get_domain_str(dom
.type
),
667 print_channel_name(channel_name
),
669 free(exclusion_string
);
671 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
672 MSG("All %s events%s are enabled in channel %s",
673 get_domain_str(dom
.type
),
675 print_channel_name(channel_name
));
676 free(exclusion_string
);
681 * We should not be here since lttng_enable_event should have
682 * failed on the event type.
688 ret
= lttng_enable_event_with_exclusions(handle
, &ev
, channel_name
,
689 opt_filter
, exclusion_count
, exclusion_list
);
692 case LTTNG_ERR_FILTER_EXIST
:
693 WARN("Filter on all events is already enabled"
694 " (channel %s, session %s)",
695 print_channel_name(channel_name
), session_name
);
698 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
700 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
701 ? print_raw_channel_name(channel_name
)
702 : print_channel_name(channel_name
),
703 session_name
, opt_filter
);
708 MSG("Filter '%s' successfully set", opt_filter
);
714 /* Strip event list */
715 event_name
= strtok(opt_event_list
, ",");
716 while (event_name
!= NULL
) {
717 /* Copy name and type of the event */
718 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
719 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
720 ev
.type
= opt_event_type
;
722 /* Kernel tracer action */
724 DBG("Enabling kernel event %s for channel %s",
726 print_channel_name(channel_name
));
728 switch (opt_event_type
) {
729 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
730 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
732 case LTTNG_EVENT_TRACEPOINT
:
734 case LTTNG_EVENT_PROBE
:
735 ret
= parse_probe_opts(&ev
, opt_probe
);
737 ERR("Unable to parse probe options");
742 case LTTNG_EVENT_FUNCTION
:
743 ret
= parse_probe_opts(&ev
, opt_function
);
745 ERR("Unable to parse function probe options");
750 case LTTNG_EVENT_FUNCTION_ENTRY
:
751 strncpy(ev
.attr
.ftrace
.symbol_name
, opt_function_entry_symbol
,
752 LTTNG_SYMBOL_NAME_LEN
);
753 ev
.attr
.ftrace
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
755 case LTTNG_EVENT_SYSCALL
:
756 MSG("per-syscall selection not supported yet. Use \"-a\" "
757 "for all syscalls.");
763 /* kernel loglevels not implemented */
764 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
765 } else if (opt_userspace
) { /* User-space tracer action */
767 if (opt_cmd_name
!= NULL
|| opt_pid
) {
768 MSG("Only supporting tracing all UST processes (-u) for now.");
774 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name
,
775 print_channel_name(channel_name
), opt_loglevel
? : "<all>");
777 switch (opt_event_type
) {
778 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
780 case LTTNG_EVENT_TRACEPOINT
:
781 /* Copy name and type of the event */
782 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
783 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
784 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
786 case LTTNG_EVENT_PROBE
:
787 case LTTNG_EVENT_FUNCTION
:
788 case LTTNG_EVENT_FUNCTION_ENTRY
:
789 case LTTNG_EVENT_SYSCALL
:
791 ERR("Event type not available for user-space tracing");
792 ret
= CMD_UNSUPPORTED
;
797 if (opt_event_type
!= LTTNG_EVENT_ALL
&& opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
798 ERR("Exclusion option can only be used with tracepoint events");
802 /* Free previously allocated items */
803 if (exclusion_list
!= NULL
) {
804 while (exclusion_count
--) {
805 free(exclusion_list
[exclusion_count
]);
807 free(exclusion_list
);
808 exclusion_list
= NULL
;
810 /* Check for proper subsets */
811 ret
= check_exclusion_subsets(event_name
, opt_exclude
,
812 &exclusion_count
, &exclusion_list
);
813 if (ret
== CMD_ERROR
) {
818 ev
.loglevel_type
= opt_loglevel_type
;
820 ev
.loglevel
= loglevel_str_to_value(opt_loglevel
);
821 if (ev
.loglevel
== -1) {
822 ERR("Unknown loglevel %s", opt_loglevel
);
823 ret
= -LTTNG_ERR_INVALID
;
829 } else if (opt_jul
) {
830 if (opt_event_type
!= LTTNG_EVENT_ALL
&&
831 opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
832 ERR("Event type not supported for JUL domain.");
833 ret
= CMD_UNSUPPORTED
;
837 ev
.loglevel_type
= opt_loglevel_type
;
839 ev
.loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
840 if (ev
.loglevel
== -1) {
841 ERR("Unknown loglevel %s", opt_loglevel
);
842 ret
= -LTTNG_ERR_INVALID
;
846 ev
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
848 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
849 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
850 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
852 print_missing_domain();
858 char *exclusion_string
;
860 ret
= lttng_enable_event_with_exclusions(handle
,
862 NULL
, exclusion_count
, exclusion_list
);
863 exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
865 /* Turn ret to positive value to handle the positive error code */
867 case LTTNG_ERR_KERN_EVENT_EXIST
:
868 WARN("Kernel event %s%s already enabled (channel %s, session %s)",
871 print_channel_name(channel_name
), session_name
);
874 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
877 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
878 ? print_raw_channel_name(channel_name
)
879 : print_channel_name(channel_name
),
885 MSG("%s event %s%s created in channel %s",
886 get_domain_str(dom
.type
), event_name
,
888 print_channel_name(channel_name
));
890 free(exclusion_string
);
894 char *exclusion_string
;
896 ret
= lttng_enable_event_with_exclusions(handle
, &ev
, channel_name
,
897 opt_filter
, exclusion_count
, exclusion_list
);
898 exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
902 case LTTNG_ERR_FILTER_EXIST
:
903 WARN("Filter on event %s%s is already enabled"
904 " (channel %s, session %s)",
907 print_channel_name(channel_name
), session_name
);
910 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
.name
,
913 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
914 ? print_raw_channel_name(channel_name
)
915 : print_channel_name(channel_name
),
916 session_name
, opt_filter
);
919 free(exclusion_string
);
922 MSG("Event %s%s: Filter '%s' successfully set",
923 event_name
, exclusion_string
,
926 free(exclusion_string
);
930 event_name
= strtok(NULL
, ",");
938 lttng_destroy_handle(handle
);
940 if (exclusion_list
!= NULL
) {
941 while (exclusion_count
--) {
942 free(exclusion_list
[exclusion_count
]);
944 free(exclusion_list
);
951 * Add event to trace session
953 int cmd_enable_events(int argc
, const char **argv
)
955 int opt
, ret
= CMD_SUCCESS
;
956 static poptContext pc
;
957 char *session_name
= NULL
;
960 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
961 poptReadDefaultConfig(pc
, 0);
963 /* Default event type */
964 opt_event_type
= LTTNG_EVENT_ALL
;
966 while ((opt
= poptGetNextOpt(pc
)) != -1) {
972 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
975 opt_event_type
= LTTNG_EVENT_PROBE
;
978 opt_event_type
= LTTNG_EVENT_FUNCTION
;
980 case OPT_FUNCTION_ENTRY
:
981 opt_event_type
= LTTNG_EVENT_FUNCTION_ENTRY
;
984 opt_event_type
= LTTNG_EVENT_SYSCALL
;
990 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
991 opt_loglevel
= poptGetOptArg(pc
);
993 case OPT_LOGLEVEL_ONLY
:
994 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
995 opt_loglevel
= poptGetOptArg(pc
);
997 case OPT_LIST_OPTIONS
:
998 list_cmd_options(stdout
, long_options
);
1006 ret
= CMD_UNDEFINED
;
1010 /* Validate event type. Multiple event type are not supported. */
1011 if (event_type
== -1) {
1012 event_type
= opt_event_type
;
1014 if (event_type
!= opt_event_type
) {
1015 ERR("Multiple event type not supported.");
1022 opt_event_list
= (char*) poptGetArg(pc
);
1023 if (opt_event_list
== NULL
&& opt_enable_all
== 0) {
1024 ERR("Missing event name(s).\n");
1030 if (!opt_session_name
) {
1031 session_name
= get_session_name();
1032 if (session_name
== NULL
) {
1037 session_name
= opt_session_name
;
1040 ret
= enable_events(session_name
);
1043 if (opt_session_name
== NULL
) {
1047 poptFreeContext(pc
);