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.
26 #include <sys/types.h>
31 #include <src/common/sessiond-comm/sessiond-comm.h>
34 #include <common/mi-lttng.h>
36 #include "../command.h"
38 #if (LTTNG_SYMBOL_NAME_LEN == 256)
39 #define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255"
42 static char *opt_event_list
;
43 static int opt_event_type
;
44 static const char *opt_loglevel
;
45 static int opt_loglevel_type
;
46 static int opt_kernel
;
47 static char *opt_session_name
;
48 static int opt_userspace
;
51 static int opt_python
;
52 static int opt_enable_all
;
53 static char *opt_probe
;
54 static char *opt_function
;
55 static char *opt_channel_name
;
56 static char *opt_filter
;
57 static char *opt_exclude
;
73 static struct lttng_handle
*handle
;
74 static struct mi_writer
*writer
;
76 static struct poptOption long_options
[] = {
77 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
78 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
79 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
80 {"all", 'a', POPT_ARG_VAL
, &opt_enable_all
, 1, 0, 0},
81 {"channel", 'c', POPT_ARG_STRING
, &opt_channel_name
, 0, 0, 0},
82 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
83 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
84 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
85 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
86 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
87 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
88 {"probe", 0, POPT_ARG_STRING
, &opt_probe
, OPT_PROBE
, 0, 0},
89 {"function", 0, POPT_ARG_STRING
, &opt_function
, OPT_FUNCTION
, 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 | -j | -l | -p) [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 to the kernel tracer\n");
113 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
114 fprintf(ofp
, " -j, --jul Apply to Java application using JUL\n");
115 fprintf(ofp
, " -l, --log4j Apply for Java application using LOG4j\n");
116 fprintf(ofp
, " -p, --python Apply for Python application\n");
118 fprintf(ofp
, "Event options:\n");
119 fprintf(ofp
, " --tracepoint Tracepoint event (default)\n");
120 fprintf(ofp
, " - userspace tracer supports wildcards at end of string.\n");
121 fprintf(ofp
, " Don't forget to quote to deal with bash expansion.\n");
122 fprintf(ofp
, " e.g.:\n");
123 fprintf(ofp
, " \"*\"\n");
124 fprintf(ofp
, " \"app_component:na*\"\n");
125 fprintf(ofp
, " --probe (addr | symbol | symbol+offset)\n");
126 fprintf(ofp
, " Dynamic probe.\n");
127 fprintf(ofp
, " Addr and offset can be octal (0NNN...),\n");
128 fprintf(ofp
, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
129 fprintf(ofp
, " --function (addr | symbol | symbol+offset)\n");
130 fprintf(ofp
, " Dynamic function entry/return probe.\n");
131 fprintf(ofp
, " Addr and offset can be octal (0NNN...),\n");
132 fprintf(ofp
, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
133 fprintf(ofp
, " --syscall System call event\n");
135 fprintf(ofp
, " --loglevel name\n");
136 fprintf(ofp
, " Tracepoint loglevel range from 0 to loglevel.\n");
137 fprintf(ofp
, " For JUL/LOG4j/Python domains, see the table below for the range values.\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");
163 fprintf(ofp
, " Available JUL domain loglevels:\n");
164 fprintf(ofp
, " JUL_OFF = INT32_MAX\n");
165 fprintf(ofp
, " JUL_SEVERE = %d\n", LTTNG_LOGLEVEL_JUL_SEVERE
);
166 fprintf(ofp
, " JUL_WARNING = %d\n", LTTNG_LOGLEVEL_JUL_WARNING
);
167 fprintf(ofp
, " JUL_INFO = %d\n", LTTNG_LOGLEVEL_JUL_INFO
);
168 fprintf(ofp
, " JUL_CONFIG = %d\n", LTTNG_LOGLEVEL_JUL_CONFIG
);
169 fprintf(ofp
, " JUL_FINE = %d\n", LTTNG_LOGLEVEL_JUL_FINE
);
170 fprintf(ofp
, " JUL_FINER = %d\n", LTTNG_LOGLEVEL_JUL_FINER
);
171 fprintf(ofp
, " JUL_FINEST = %d\n", LTTNG_LOGLEVEL_JUL_FINEST
);
172 fprintf(ofp
, " JUL_ALL = INT32_MIN\n");
173 fprintf(ofp
, " (shortcuts such as \"severe\" are allowed)\n");
175 fprintf(ofp
, " Available LOG4j domain loglevels:\n");
176 fprintf(ofp
, " LOG4J_OFF = INT32_MAX\n");
177 fprintf(ofp
, " LOG4J_FATAL = %d\n", LTTNG_LOGLEVEL_LOG4J_FATAL
);
178 fprintf(ofp
, " LOG4J_ERROR = %d\n", LTTNG_LOGLEVEL_LOG4J_ERROR
);
179 fprintf(ofp
, " LOG4J_WARN = %d\n", LTTNG_LOGLEVEL_LOG4J_WARN
);
180 fprintf(ofp
, " LOG4J_INFO = %d\n", LTTNG_LOGLEVEL_LOG4J_INFO
);
181 fprintf(ofp
, " LOG4J_DEBUG = %d\n", LTTNG_LOGLEVEL_LOG4J_DEBUG
);
182 fprintf(ofp
, " LOG4J_TRACE = %d\n", LTTNG_LOGLEVEL_LOG4J_TRACE
);
183 fprintf(ofp
, " LOG4J_ALL = INT32_MIN\n");
184 fprintf(ofp
, " (shortcuts such as \"severe\" are allowed)\n");
186 fprintf(ofp
, " Available Python domain loglevels:\n");
187 fprintf(ofp
, " PYTHON_CRITICAL = %d\n", LTTNG_LOGLEVEL_PYTHON_CRITICAL
);
188 fprintf(ofp
, " PYTHON_ERROR = %d\n", LTTNG_LOGLEVEL_PYTHON_ERROR
);
189 fprintf(ofp
, " PYTHON_WARNING = %d\n", LTTNG_LOGLEVEL_PYTHON_WARNING
);
190 fprintf(ofp
, " PYTHON_INFO = %d\n", LTTNG_LOGLEVEL_PYTHON_INFO
);
191 fprintf(ofp
, " PYTHON_DEBUG = %d\n", LTTNG_LOGLEVEL_PYTHON_DEBUG
);
192 fprintf(ofp
, " PYTHON_NOTSET = %d\n", LTTNG_LOGLEVEL_PYTHON_NOTSET
);
193 fprintf(ofp
, " (shortcuts such as \"critical\" are allowed)\n");
195 fprintf(ofp
, " -f, --filter \'expression\'\n");
196 fprintf(ofp
, " Filter expression on event fields and context.\n");
197 fprintf(ofp
, " Event recording depends on evaluation.\n");
198 fprintf(ofp
, " Only specify on first activation of\n");
199 fprintf(ofp
, " a given event within a session.\n");
200 fprintf(ofp
, " Filter only allowed when enabling\n");
201 fprintf(ofp
, " events within a session before tracing\n");
202 fprintf(ofp
, " is started. If the filter fails to link\n");
203 fprintf(ofp
, " with the event within the traced domain,\n");
204 fprintf(ofp
, " the event will be discarded. Currently,\n");
205 fprintf(ofp
, " filter is only implemented for the user-space\n");
206 fprintf(ofp
, " tracer.\n");
207 fprintf(ofp
, " Expression examples:.\n");
209 fprintf(ofp
, " 'intfield > 500 && intfield < 503'\n");
210 fprintf(ofp
, " '(strfield == \"test\" || intfield != 10) && intfield > 33'\n");
211 fprintf(ofp
, " 'doublefield > 1.1 && intfield < 5.3'\n");
213 fprintf(ofp
, " Wildcards are allowed at the end of strings:\n");
214 fprintf(ofp
, " 'seqfield1 == \"te*\"'\n");
215 fprintf(ofp
, " In string literals, the escape character is '\\'.\n");
216 fprintf(ofp
, " Use '\\*' for the '*' character, and '\\\\' for\n");
217 fprintf(ofp
, " the '\\' character. Wildcard match any sequence of,\n");
218 fprintf(ofp
, " characters including an empty sub-string (match 0 or\n");
219 fprintf(ofp
, " more characters).\n");
221 fprintf(ofp
, " Context information can be used for filtering. The\n");
222 fprintf(ofp
, " examples below show usage of context filtering on\n");
223 fprintf(ofp
, " process name (with a wildcard), process ID range, and\n");
224 fprintf(ofp
, " unique thread ID for filtering. The process and\n");
225 fprintf(ofp
, " thread ID of running applications can be found under\n");
226 fprintf(ofp
, " columns \"PID\" and \"LWP\" of the \"ps -eLf\" command.\n");
228 fprintf(ofp
, " '$ctx.procname == \"demo*\"'\n");
229 fprintf(ofp
, " '$ctx.vpid >= 4433 && $ctx.vpid < 4455'\n");
230 fprintf(ofp
, " '$ctx.vtid == 1234'\n");
231 fprintf(ofp
, " -x, --exclude LIST\n");
232 fprintf(ofp
, " Add exclusions to UST tracepoints:\n");
233 fprintf(ofp
, " Events that match any of the items\n");
234 fprintf(ofp
, " in the comma-separated LIST are not\n");
235 fprintf(ofp
, " enabled, even if they match a wildcard\n");
236 fprintf(ofp
, " definition of the event.\n");
241 * Parse probe options.
243 static int parse_probe_opts(struct lttng_event
*ev
, char *opt
)
245 int ret
= CMD_SUCCESS
;
248 #define S_HEX_LEN_SCANF_IS_A_BROKEN_API "18" /* 18 is (19 - 1) (\0 is extra) */
249 char name
[LTTNG_SYMBOL_NAME_LEN
];
256 /* Check for symbol+offset */
257 match
= sscanf(opt
, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
258 "[^'+']+%" S_HEX_LEN_SCANF_IS_A_BROKEN_API
"s", name
, s_hex
);
260 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
261 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
262 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
263 if (*s_hex
== '\0') {
264 ERR("Invalid probe offset %s", s_hex
);
268 ev
->attr
.probe
.offset
= strtoul(s_hex
, NULL
, 0);
269 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
270 ev
->attr
.probe
.addr
= 0;
274 /* Check for symbol */
275 if (isalpha(name
[0])) {
276 match
= sscanf(opt
, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
"s",
279 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
280 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
281 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
282 ev
->attr
.probe
.offset
= 0;
283 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
284 ev
->attr
.probe
.addr
= 0;
289 /* Check for address */
290 match
= sscanf(opt
, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API
"s", s_hex
);
292 if (*s_hex
== '\0') {
293 ERR("Invalid probe address %s", s_hex
);
297 ev
->attr
.probe
.addr
= strtoul(s_hex
, NULL
, 0);
298 DBG("probe addr %" PRIu64
, ev
->attr
.probe
.addr
);
299 ev
->attr
.probe
.offset
= 0;
300 memset(ev
->attr
.probe
.symbol_name
, 0, LTTNG_SYMBOL_NAME_LEN
);
312 * Maps LOG4j loglevel from string to value
314 static int loglevel_log4j_str_to_value(const char *inputstr
)
317 char str
[LTTNG_SYMBOL_NAME_LEN
];
319 if (!inputstr
|| strlen(inputstr
) == 0) {
324 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
325 * added at the end of the loop so a the upper bound we avoid the overflow.
327 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
328 str
[i
] = toupper(inputstr
[i
]);
333 if (!strcmp(str
, "LOG4J_OFF") || !strcmp(str
, "OFF")) {
334 return LTTNG_LOGLEVEL_LOG4J_OFF
;
335 } else if (!strcmp(str
, "LOG4J_FATAL") || !strcmp(str
, "FATAL")) {
336 return LTTNG_LOGLEVEL_LOG4J_FATAL
;
337 } else if (!strcmp(str
, "LOG4J_ERROR") || !strcmp(str
, "ERROR")) {
338 return LTTNG_LOGLEVEL_LOG4J_ERROR
;
339 } else if (!strcmp(str
, "LOG4J_WARN") || !strcmp(str
, "WARN")) {
340 return LTTNG_LOGLEVEL_LOG4J_WARN
;
341 } else if (!strcmp(str
, "LOG4J_INFO") || !strcmp(str
, "INFO")) {
342 return LTTNG_LOGLEVEL_LOG4J_INFO
;
343 } else if (!strcmp(str
, "LOG4J_DEBUG") || !strcmp(str
, "DEBUG")) {
344 return LTTNG_LOGLEVEL_LOG4J_DEBUG
;
345 } else if (!strcmp(str
, "LOG4J_TRACE") || !strcmp(str
, "TRACE")) {
346 return LTTNG_LOGLEVEL_LOG4J_TRACE
;
347 } else if (!strcmp(str
, "LOG4J_ALL") || !strcmp(str
, "ALL")) {
348 return LTTNG_LOGLEVEL_LOG4J_ALL
;
355 * Maps JUL loglevel from string to value
357 static int loglevel_jul_str_to_value(const char *inputstr
)
360 char str
[LTTNG_SYMBOL_NAME_LEN
];
362 if (!inputstr
|| strlen(inputstr
) == 0) {
367 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
368 * added at the end of the loop so a the upper bound we avoid the overflow.
370 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
371 str
[i
] = toupper(inputstr
[i
]);
376 if (!strcmp(str
, "JUL_OFF") || !strcmp(str
, "OFF")) {
377 return LTTNG_LOGLEVEL_JUL_OFF
;
378 } else if (!strcmp(str
, "JUL_SEVERE") || !strcmp(str
, "SEVERE")) {
379 return LTTNG_LOGLEVEL_JUL_SEVERE
;
380 } else if (!strcmp(str
, "JUL_WARNING") || !strcmp(str
, "WARNING")) {
381 return LTTNG_LOGLEVEL_JUL_WARNING
;
382 } else if (!strcmp(str
, "JUL_INFO") || !strcmp(str
, "INFO")) {
383 return LTTNG_LOGLEVEL_JUL_INFO
;
384 } else if (!strcmp(str
, "JUL_CONFIG") || !strcmp(str
, "CONFIG")) {
385 return LTTNG_LOGLEVEL_JUL_CONFIG
;
386 } else if (!strcmp(str
, "JUL_FINE") || !strcmp(str
, "FINE")) {
387 return LTTNG_LOGLEVEL_JUL_FINE
;
388 } else if (!strcmp(str
, "JUL_FINER") || !strcmp(str
, "FINER")) {
389 return LTTNG_LOGLEVEL_JUL_FINER
;
390 } else if (!strcmp(str
, "JUL_FINEST") || !strcmp(str
, "FINEST")) {
391 return LTTNG_LOGLEVEL_JUL_FINEST
;
392 } else if (!strcmp(str
, "JUL_ALL") || !strcmp(str
, "ALL")) {
393 return LTTNG_LOGLEVEL_JUL_ALL
;
400 * Maps Python loglevel from string to value
402 static int loglevel_python_str_to_value(const char *inputstr
)
405 char str
[LTTNG_SYMBOL_NAME_LEN
];
407 if (!inputstr
|| strlen(inputstr
) == 0) {
412 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
413 * added at the end of the loop so a the upper bound we avoid the overflow.
415 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
416 str
[i
] = toupper(inputstr
[i
]);
421 if (!strcmp(str
, "PYTHON_CRITICAL") || !strcmp(str
, "CRITICAL")) {
422 return LTTNG_LOGLEVEL_PYTHON_CRITICAL
;
423 } else if (!strcmp(str
, "PYTHON_ERROR") || !strcmp(str
, "ERROR")) {
424 return LTTNG_LOGLEVEL_PYTHON_ERROR
;
425 } else if (!strcmp(str
, "PYTHON_WARNING") || !strcmp(str
, "WARNING")) {
426 return LTTNG_LOGLEVEL_PYTHON_WARNING
;
427 } else if (!strcmp(str
, "PYTHON_INFO") || !strcmp(str
, "INFO")) {
428 return LTTNG_LOGLEVEL_PYTHON_INFO
;
429 } else if (!strcmp(str
, "PYTNON_DEBUG") || !strcmp(str
, "DEBUG")) {
430 return LTTNG_LOGLEVEL_PYTHON_DEBUG
;
431 } else if (!strcmp(str
, "PYTHON_NOTSET") || !strcmp(str
, "NOTSET")) {
432 return LTTNG_LOGLEVEL_PYTHON_NOTSET
;
439 * Maps loglevel from string to value
442 int loglevel_str_to_value(const char *inputstr
)
445 char str
[LTTNG_SYMBOL_NAME_LEN
];
447 if (!inputstr
|| strlen(inputstr
) == 0) {
452 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
453 * added at the end of the loop so a the upper bound we avoid the overflow.
455 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
456 str
[i
] = toupper(inputstr
[i
]);
460 if (!strcmp(str
, "TRACE_EMERG") || !strcmp(str
, "EMERG")) {
461 return LTTNG_LOGLEVEL_EMERG
;
462 } else if (!strcmp(str
, "TRACE_ALERT") || !strcmp(str
, "ALERT")) {
463 return LTTNG_LOGLEVEL_ALERT
;
464 } else if (!strcmp(str
, "TRACE_CRIT") || !strcmp(str
, "CRIT")) {
465 return LTTNG_LOGLEVEL_CRIT
;
466 } else if (!strcmp(str
, "TRACE_ERR") || !strcmp(str
, "ERR")) {
467 return LTTNG_LOGLEVEL_ERR
;
468 } else if (!strcmp(str
, "TRACE_WARNING") || !strcmp(str
, "WARNING")) {
469 return LTTNG_LOGLEVEL_WARNING
;
470 } else if (!strcmp(str
, "TRACE_NOTICE") || !strcmp(str
, "NOTICE")) {
471 return LTTNG_LOGLEVEL_NOTICE
;
472 } else if (!strcmp(str
, "TRACE_INFO") || !strcmp(str
, "INFO")) {
473 return LTTNG_LOGLEVEL_INFO
;
474 } else if (!strcmp(str
, "TRACE_DEBUG_SYSTEM") || !strcmp(str
, "DEBUG_SYSTEM") || !strcmp(str
, "SYSTEM")) {
475 return LTTNG_LOGLEVEL_DEBUG_SYSTEM
;
476 } else if (!strcmp(str
, "TRACE_DEBUG_PROGRAM") || !strcmp(str
, "DEBUG_PROGRAM") || !strcmp(str
, "PROGRAM")) {
477 return LTTNG_LOGLEVEL_DEBUG_PROGRAM
;
478 } else if (!strcmp(str
, "TRACE_DEBUG_PROCESS") || !strcmp(str
, "DEBUG_PROCESS") || !strcmp(str
, "PROCESS")) {
479 return LTTNG_LOGLEVEL_DEBUG_PROCESS
;
480 } else if (!strcmp(str
, "TRACE_DEBUG_MODULE") || !strcmp(str
, "DEBUG_MODULE") || !strcmp(str
, "MODULE")) {
481 return LTTNG_LOGLEVEL_DEBUG_MODULE
;
482 } else if (!strcmp(str
, "TRACE_DEBUG_UNIT") || !strcmp(str
, "DEBUG_UNIT") || !strcmp(str
, "UNIT")) {
483 return LTTNG_LOGLEVEL_DEBUG_UNIT
;
484 } else if (!strcmp(str
, "TRACE_DEBUG_FUNCTION") || !strcmp(str
, "DEBUG_FUNCTION") || !strcmp(str
, "FUNCTION")) {
485 return LTTNG_LOGLEVEL_DEBUG_FUNCTION
;
486 } else if (!strcmp(str
, "TRACE_DEBUG_LINE") || !strcmp(str
, "DEBUG_LINE") || !strcmp(str
, "LINE")) {
487 return LTTNG_LOGLEVEL_DEBUG_LINE
;
488 } else if (!strcmp(str
, "TRACE_DEBUG") || !strcmp(str
, "DEBUG")) {
489 return LTTNG_LOGLEVEL_DEBUG
;
496 const char *print_channel_name(const char *name
)
498 return name
? : DEFAULT_CHANNEL_NAME
;
502 const char *print_raw_channel_name(const char *name
)
504 return name
? : "<default>";
508 * Mi print exlcusion list
511 int mi_print_exclusion(int count
, char **names
)
521 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
526 for (i
= 0; i
< count
; i
++) {
527 ret
= mi_lttng_writer_write_element_string(writer
,
528 config_element_exclusion
, names
[i
]);
534 /* Close exclusions element */
535 ret
= mi_lttng_writer_close_element(writer
);
542 * Return allocated string for pretty-printing exclusion names.
545 char *print_exclusions(int count
, char **names
)
549 const char *preamble
= " excluding ";
556 /* calculate total required length */
557 for (i
= 0; i
< count
; i
++) {
558 length
+= strlen(names
[i
]) + 1;
561 /* add length of preamble + one for NUL - one for last (missing) comma */
562 length
+= strlen(preamble
);
563 ret
= zmalloc(length
);
567 strncpy(ret
, preamble
, length
);
568 for (i
= 0; i
< count
; i
++) {
569 strcat(ret
, names
[i
]);
570 if (i
!= count
- 1) {
579 * Compare list of exclusions against an event name.
580 * Return a list of legal exclusion names.
581 * Produce an error or a warning about others (depending on the situation)
584 int check_exclusion_subsets(const char *event_name
,
585 const char *exclusions
,
586 int *exclusion_count_ptr
,
587 char ***exclusion_list_ptr
)
589 const char *excluder_ptr
;
590 const char *event_ptr
;
591 const char *next_excluder
;
593 int exclusion_count
= 0;
594 char **exclusion_list
= NULL
;
595 int ret
= CMD_SUCCESS
;
597 if (event_name
[strlen(event_name
) - 1] != '*') {
598 ERR("Event %s: Excluders can only be used with wildcarded events", event_name
);
602 next_excluder
= exclusions
;
603 while (*next_excluder
!= 0) {
604 event_ptr
= event_name
;
605 excluder_ptr
= next_excluder
;
606 excluder_length
= strcspn(next_excluder
, ",");
608 /* Scan both the excluder and the event letter by letter */
616 /* Event is a subset of the excluder */
617 ERR("Event %s: %.*s excludes all events from %s",
626 char **new_exclusion_list
;
628 /* Excluder is a proper subset of event */
629 string
= strndup(next_excluder
, excluder_length
);
631 PERROR("strndup error");
634 new_exclusion_list
= realloc(exclusion_list
,
635 sizeof(char *) * (exclusion_count
+ 1));
636 if (!new_exclusion_list
) {
641 exclusion_list
= new_exclusion_list
;
643 exclusion_list
[exclusion_count
- 1] = string
;
647 /* Excluder and event sets have no common elements */
648 WARN("Event %s: %.*s does not exclude any events from %s",
659 next_excluder
+= excluder_length
;
660 if (*next_excluder
== ',') {
666 while (exclusion_count
--) {
667 free(exclusion_list
[exclusion_count
]);
669 if (exclusion_list
!= NULL
) {
670 free(exclusion_list
);
672 exclusion_list
= NULL
;
676 *exclusion_count_ptr
= exclusion_count
;
677 *exclusion_list_ptr
= exclusion_list
;
681 * Enabling event using the lttng API.
682 * Note: in case of error only the last error code will be return.
684 static int enable_events(char *session_name
)
686 int ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
;
687 int error_holder
= CMD_SUCCESS
, warn
= 0, error
= 0, success
= 1;
688 char *event_name
, *channel_name
= NULL
;
689 struct lttng_event ev
;
690 struct lttng_domain dom
;
691 int exclusion_count
= 0;
692 char **exclusion_list
= NULL
;
694 memset(&ev
, 0, sizeof(ev
));
695 memset(&dom
, 0, sizeof(dom
));
699 WARN("Kernel loglevels are not supported.");
703 /* Create lttng domain */
705 dom
.type
= LTTNG_DOMAIN_KERNEL
;
706 dom
.buf_type
= LTTNG_BUFFER_GLOBAL
;
707 } else if (opt_userspace
) {
708 dom
.type
= LTTNG_DOMAIN_UST
;
710 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
711 } else if (opt_jul
) {
712 dom
.type
= LTTNG_DOMAIN_JUL
;
714 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
715 } else if (opt_log4j
) {
716 dom
.type
= LTTNG_DOMAIN_LOG4J
;
718 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
719 } else if (opt_python
) {
720 dom
.type
= LTTNG_DOMAIN_PYTHON
;
722 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
724 /* Checked by the caller. */
730 case LTTNG_DOMAIN_KERNEL
:
731 case LTTNG_DOMAIN_JUL
:
732 case LTTNG_DOMAIN_LOG4J
:
733 case LTTNG_DOMAIN_PYTHON
:
734 ERR("Event name exclusions are not yet implemented for %s events",
735 get_domain_str(dom
.type
));
738 case LTTNG_DOMAIN_UST
:
739 /* Exclusions supported */
746 channel_name
= opt_channel_name
;
748 handle
= lttng_create_handle(session_name
, &dom
);
749 if (handle
== NULL
) {
756 /* Open a events element */
757 ret
= mi_lttng_writer_open_element(writer
, config_element_events
);
764 if (opt_enable_all
) {
765 /* Default setup for enable all */
767 ev
.type
= opt_event_type
;
768 strcpy(ev
.name
, "*");
769 /* kernel loglevels not implemented */
770 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
772 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
773 strcpy(ev
.name
, "*");
774 ev
.loglevel_type
= opt_loglevel_type
;
776 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
778 ev
.loglevel
= loglevel_str_to_value(opt_loglevel
);
779 } else if (opt_jul
) {
780 ev
.loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
781 } else if (opt_log4j
) {
782 ev
.loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
783 } else if (opt_python
) {
784 ev
.loglevel
= loglevel_python_str_to_value(opt_loglevel
);
786 if (ev
.loglevel
== -1) {
787 ERR("Unknown loglevel %s", opt_loglevel
);
788 ret
= -LTTNG_ERR_INVALID
;
792 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
795 } else if (opt_jul
) {
796 ev
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
797 } else if (opt_log4j
) {
798 ev
.loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
799 } else if (opt_python
) {
800 ev
.loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
806 ret
= check_exclusion_subsets("*", opt_exclude
,
807 &exclusion_count
, &exclusion_list
);
808 if (ret
== CMD_ERROR
) {
814 ret
= lttng_enable_event_with_exclusions(handle
,
817 exclusion_count
, exclusion_list
);
820 case LTTNG_ERR_KERN_EVENT_EXIST
:
821 WARN("Kernel events already enabled (channel %s, session %s)",
822 print_channel_name(channel_name
), session_name
);
825 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
827 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
828 ERR("Events: %s (channel %s, session %s)",
830 print_channel_name(channel_name
),
836 ERR("Events: %s (channel %s, session %s)",
838 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
839 ? print_raw_channel_name(channel_name
)
840 : print_channel_name(channel_name
),
848 switch (opt_event_type
) {
849 case LTTNG_EVENT_TRACEPOINT
:
850 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
851 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
853 if (!exclusion_string
) {
854 PERROR("Cannot allocate exclusion_string");
858 MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
859 get_domain_str(dom
.type
),
861 print_channel_name(channel_name
),
863 free(exclusion_string
);
865 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
867 if (!exclusion_string
) {
868 PERROR("Cannot allocate exclusion_string");
872 MSG("All %s tracepoints%s are enabled in channel %s",
873 get_domain_str(dom
.type
),
875 print_channel_name(channel_name
));
876 free(exclusion_string
);
879 case LTTNG_EVENT_SYSCALL
:
881 MSG("All %s system calls are enabled in channel %s",
882 get_domain_str(dom
.type
),
883 print_channel_name(channel_name
));
886 case LTTNG_EVENT_ALL
:
887 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
888 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
890 if (!exclusion_string
) {
891 PERROR("Cannot allocate exclusion_string");
895 MSG("All %s events%s are enabled in channel %s for loglevel %s",
896 get_domain_str(dom
.type
),
898 print_channel_name(channel_name
),
900 free(exclusion_string
);
902 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
904 if (!exclusion_string
) {
905 PERROR("Cannot allocate exclusion_string");
909 MSG("All %s events%s are enabled in channel %s",
910 get_domain_str(dom
.type
),
912 print_channel_name(channel_name
));
913 free(exclusion_string
);
918 * We should not be here since lttng_enable_event should have
919 * failed on the event type.
926 command_ret
= lttng_enable_event_with_exclusions(handle
, &ev
, channel_name
,
927 opt_filter
, exclusion_count
, exclusion_list
);
928 if (command_ret
< 0) {
929 switch (-command_ret
) {
930 case LTTNG_ERR_FILTER_EXIST
:
931 WARN("Filter on all events is already enabled"
932 " (channel %s, session %s)",
933 print_channel_name(channel_name
), session_name
);
936 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
938 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
939 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
941 print_channel_name(channel_name
),
942 session_name
, opt_filter
);
947 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
948 lttng_strerror(command_ret
),
949 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
950 ? print_raw_channel_name(channel_name
)
951 : print_channel_name(channel_name
),
952 session_name
, opt_filter
);
956 error_holder
= command_ret
;
959 MSG("Filter '%s' successfully set", opt_filter
);
964 /* The wildcard * is used for kernel and ust domain to
965 * represent ALL. We copy * in event name to force the wildcard use
968 * Note: this is strictly for semantic and printing while in
969 * machine interface mode.
971 strcpy(ev
.name
, "*");
973 /* If we reach here the events are enabled */
974 if (!error
&& !warn
) {
980 ret
= mi_lttng_event(writer
, &ev
, 1, handle
->domain
.type
);
986 /* print exclusion */
987 ret
= mi_print_exclusion(exclusion_count
, exclusion_list
);
994 ret
= mi_lttng_writer_write_element_bool(writer
,
995 mi_lttng_element_command_success
, success
);
1001 /* Close event element */
1002 ret
= mi_lttng_writer_close_element(writer
);
1012 /* Strip event list */
1013 event_name
= strtok(opt_event_list
, ",");
1014 while (event_name
!= NULL
) {
1015 /* Copy name and type of the event */
1016 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1017 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1018 ev
.type
= opt_event_type
;
1020 /* Kernel tracer action */
1022 DBG("Enabling kernel event %s for channel %s",
1024 print_channel_name(channel_name
));
1026 switch (opt_event_type
) {
1027 case LTTNG_EVENT_ALL
: /* Enable tracepoints and syscalls */
1028 /* If event name differs from *, select tracepoint. */
1029 if (strcmp(ev
.name
, "*")) {
1030 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
1033 case LTTNG_EVENT_TRACEPOINT
:
1035 case LTTNG_EVENT_PROBE
:
1036 ret
= parse_probe_opts(&ev
, opt_probe
);
1038 ERR("Unable to parse probe options");
1043 case LTTNG_EVENT_FUNCTION
:
1044 ret
= parse_probe_opts(&ev
, opt_function
);
1046 ERR("Unable to parse function probe options");
1051 case LTTNG_EVENT_SYSCALL
:
1052 ev
.type
= LTTNG_EVENT_SYSCALL
;
1055 ret
= CMD_UNDEFINED
;
1059 /* kernel loglevels not implemented */
1060 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
1061 } else if (opt_userspace
) { /* User-space tracer action */
1062 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name
,
1063 print_channel_name(channel_name
), opt_loglevel
? : "<all>");
1065 switch (opt_event_type
) {
1066 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
1068 case LTTNG_EVENT_TRACEPOINT
:
1069 /* Copy name and type of the event */
1070 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
1071 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1072 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1074 case LTTNG_EVENT_PROBE
:
1075 case LTTNG_EVENT_FUNCTION
:
1076 case LTTNG_EVENT_SYSCALL
:
1078 ERR("Event type not available for user-space tracing");
1079 ret
= CMD_UNSUPPORTED
;
1085 if (opt_event_type
!= LTTNG_EVENT_ALL
&& opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1086 ERR("Exclusion option can only be used with tracepoint events");
1090 /* Free previously allocated items */
1091 if (exclusion_list
!= NULL
) {
1092 while (exclusion_count
--) {
1093 free(exclusion_list
[exclusion_count
]);
1095 free(exclusion_list
);
1096 exclusion_list
= NULL
;
1098 /* Check for proper subsets */
1099 ret
= check_exclusion_subsets(event_name
, opt_exclude
,
1100 &exclusion_count
, &exclusion_list
);
1101 if (ret
== CMD_ERROR
) {
1106 ev
.loglevel_type
= opt_loglevel_type
;
1108 ev
.loglevel
= loglevel_str_to_value(opt_loglevel
);
1109 if (ev
.loglevel
== -1) {
1110 ERR("Unknown loglevel %s", opt_loglevel
);
1111 ret
= -LTTNG_ERR_INVALID
;
1117 } else if (opt_jul
|| opt_log4j
|| opt_python
) {
1118 if (opt_event_type
!= LTTNG_EVENT_ALL
&&
1119 opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1120 ERR("Event type not supported for domain.");
1121 ret
= CMD_UNSUPPORTED
;
1125 ev
.loglevel_type
= opt_loglevel_type
;
1128 ev
.loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
1129 } else if (opt_log4j
) {
1130 ev
.loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
1131 } else if (opt_python
) {
1132 ev
.loglevel
= loglevel_python_str_to_value(opt_loglevel
);
1134 if (ev
.loglevel
== -1) {
1135 ERR("Unknown loglevel %s", opt_loglevel
);
1136 ret
= -LTTNG_ERR_INVALID
;
1141 ev
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1142 } else if (opt_log4j
) {
1143 ev
.loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1144 } else if (opt_python
) {
1145 ev
.loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1148 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
1149 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1150 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1156 char *exclusion_string
;
1158 command_ret
= lttng_enable_event_with_exclusions(handle
,
1160 NULL
, exclusion_count
, exclusion_list
);
1161 exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
1162 if (!exclusion_string
) {
1163 PERROR("Cannot allocate exclusion_string");
1167 if (command_ret
< 0) {
1168 /* Turn ret to positive value to handle the positive error code */
1169 switch (-command_ret
) {
1170 case LTTNG_ERR_KERN_EVENT_EXIST
:
1171 WARN("Kernel event %s%s already enabled (channel %s, session %s)",
1174 print_channel_name(channel_name
), session_name
);
1177 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1179 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1180 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1183 print_channel_name(channel_name
),
1189 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1191 lttng_strerror(command_ret
),
1192 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1193 ? print_raw_channel_name(channel_name
)
1194 : print_channel_name(channel_name
),
1199 error_holder
= command_ret
;
1202 case LTTNG_DOMAIN_KERNEL
:
1203 case LTTNG_DOMAIN_UST
:
1204 MSG("%s event %s%s created in channel %s",
1205 get_domain_str(dom
.type
),
1208 print_channel_name(channel_name
));
1210 case LTTNG_DOMAIN_JUL
:
1211 case LTTNG_DOMAIN_LOG4J
:
1212 case LTTNG_DOMAIN_PYTHON
:
1214 * Don't print the default channel
1215 * name for agent domains.
1217 MSG("%s event %s%s enabled",
1218 get_domain_str(dom
.type
),
1226 free(exclusion_string
);
1230 char *exclusion_string
;
1232 /* Filter present */
1235 command_ret
= lttng_enable_event_with_exclusions(handle
, &ev
, channel_name
,
1236 opt_filter
, exclusion_count
, exclusion_list
);
1237 exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
1238 if (!exclusion_string
) {
1239 PERROR("Cannot allocate exclusion_string");
1243 if (command_ret
< 0) {
1244 switch (-command_ret
) {
1245 case LTTNG_ERR_FILTER_EXIST
:
1246 WARN("Filter on event %s%s is already enabled"
1247 " (channel %s, session %s)",
1250 print_channel_name(channel_name
), session_name
);
1253 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1255 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1256 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
.name
,
1259 print_channel_name(channel_name
),
1260 session_name
, opt_filter
);
1265 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
.name
,
1267 lttng_strerror(command_ret
),
1268 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1269 ? print_raw_channel_name(channel_name
)
1270 : print_channel_name(channel_name
),
1271 session_name
, opt_filter
);
1275 error_holder
= command_ret
;
1278 MSG("Event %s%s: Filter '%s' successfully set",
1279 event_name
, exclusion_string
,
1282 free(exclusion_string
);
1293 ret
= mi_lttng_event(writer
, &ev
, 1, handle
->domain
.type
);
1299 /* print exclusion */
1300 ret
= mi_print_exclusion(exclusion_count
, exclusion_list
);
1307 ret
= mi_lttng_writer_write_element_bool(writer
,
1308 mi_lttng_element_command_success
, success
);
1314 /* Close event element */
1315 ret
= mi_lttng_writer_close_element(writer
);
1323 event_name
= strtok(NULL
, ",");
1324 /* Reset warn, error and success */
1331 /* Close events element */
1332 ret
= mi_lttng_writer_close_element(writer
);
1345 lttng_destroy_handle(handle
);
1347 if (exclusion_list
!= NULL
) {
1348 while (exclusion_count
--) {
1349 free(exclusion_list
[exclusion_count
]);
1351 free(exclusion_list
);
1354 /* Overwrite ret with error_holder if there was an actual error with
1355 * enabling an event.
1357 ret
= error_holder
? error_holder
: ret
;
1363 * Add event to trace session
1365 int cmd_enable_events(int argc
, const char **argv
)
1367 int opt
, ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
, success
= 1;
1368 static poptContext pc
;
1369 char *session_name
= NULL
;
1370 int event_type
= -1;
1372 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
1373 poptReadDefaultConfig(pc
, 0);
1375 /* Default event type */
1376 opt_event_type
= LTTNG_EVENT_ALL
;
1378 while ((opt
= poptGetNextOpt(pc
)) != -1) {
1383 case OPT_TRACEPOINT
:
1384 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
1387 opt_event_type
= LTTNG_EVENT_PROBE
;
1390 opt_event_type
= LTTNG_EVENT_FUNCTION
;
1393 opt_event_type
= LTTNG_EVENT_SYSCALL
;
1399 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1400 opt_loglevel
= poptGetOptArg(pc
);
1402 case OPT_LOGLEVEL_ONLY
:
1403 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1404 opt_loglevel
= poptGetOptArg(pc
);
1406 case OPT_LIST_OPTIONS
:
1407 list_cmd_options(stdout
, long_options
);
1415 ret
= CMD_UNDEFINED
;
1419 /* Validate event type. Multiple event type are not supported. */
1420 if (event_type
== -1) {
1421 event_type
= opt_event_type
;
1423 if (event_type
!= opt_event_type
) {
1424 ERR("Multiple event type not supported.");
1431 ret
= print_missing_or_multiple_domains(
1432 opt_kernel
+ opt_userspace
+ opt_jul
+ opt_log4j
+ opt_python
);
1440 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
1442 ret
= -LTTNG_ERR_NOMEM
;
1446 /* Open command element */
1447 ret
= mi_lttng_writer_command_open(writer
,
1448 mi_lttng_element_command_enable_event
);
1454 /* Open output element */
1455 ret
= mi_lttng_writer_open_element(writer
,
1456 mi_lttng_element_command_output
);
1463 opt_event_list
= (char*) poptGetArg(pc
);
1464 if (opt_event_list
== NULL
&& opt_enable_all
== 0) {
1465 ERR("Missing event name(s).\n");
1471 if (!opt_session_name
) {
1472 session_name
= get_session_name();
1473 if (session_name
== NULL
) {
1474 command_ret
= CMD_ERROR
;
1479 session_name
= opt_session_name
;
1482 command_ret
= enable_events(session_name
);
1491 /* Close output element */
1492 ret
= mi_lttng_writer_close_element(writer
);
1498 ret
= mi_lttng_writer_write_element_bool(writer
,
1499 mi_lttng_element_command_success
, success
);
1505 /* Command element close */
1506 ret
= mi_lttng_writer_command_close(writer
);
1515 if (writer
&& mi_lttng_writer_destroy(writer
)) {
1516 /* Preserve original error code */
1517 ret
= ret
? ret
: LTTNG_ERR_MI_IO_FAIL
;
1520 if (opt_session_name
== NULL
) {
1524 /* Overwrite ret if an error occurred in enable_events */
1525 ret
= command_ret
? command_ret
: ret
;
1527 poptFreeContext(pc
);