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 <src/common/sessiond-comm/sessiond-comm.h>
33 #include <common/mi-lttng.h>
35 #include "../command.h"
37 #if (LTTNG_SYMBOL_NAME_LEN == 256)
38 #define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255"
41 static char *opt_event_list
;
42 static int opt_event_type
;
43 static const char *opt_loglevel
;
44 static int opt_loglevel_type
;
45 static int opt_kernel
;
46 static char *opt_session_name
;
47 static int opt_userspace
;
50 static int opt_python
;
51 static int opt_enable_all
;
52 static char *opt_probe
;
53 static char *opt_function
;
54 static char *opt_function_entry_symbol
;
55 static char *opt_channel_name
;
56 static char *opt_filter
;
57 static char *opt_exclude
;
59 /* Not implemented yet */
60 static char *opt_cmd_name
;
79 static struct lttng_handle
*handle
;
80 static struct mi_writer
*writer
;
82 static struct poptOption long_options
[] = {
83 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
84 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
85 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
86 {"all", 'a', POPT_ARG_VAL
, &opt_enable_all
, 1, 0, 0},
87 {"channel", 'c', POPT_ARG_STRING
, &opt_channel_name
, 0, 0, 0},
88 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
89 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
90 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
91 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
92 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
93 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
94 {"probe", 0, POPT_ARG_STRING
, &opt_probe
, OPT_PROBE
, 0, 0},
95 {"function", 0, POPT_ARG_STRING
, &opt_function
, OPT_FUNCTION
, 0, 0},
98 * Currently removed from lttng kernel tracer. Removed from
99 * lttng UI to discourage its use.
101 {"function:entry", 0, POPT_ARG_STRING
, &opt_function_entry_symbol
, OPT_FUNCTION_ENTRY
, 0, 0},
103 {"syscall", 0, POPT_ARG_NONE
, 0, OPT_SYSCALL
, 0, 0},
104 {"loglevel", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL
, 0, 0},
105 {"loglevel-only", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL_ONLY
, 0, 0},
106 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
107 {"filter", 'f', POPT_ARG_STRING
, &opt_filter
, OPT_FILTER
, 0, 0},
108 {"exclude", 'x', POPT_ARG_STRING
, &opt_exclude
, OPT_EXCLUDE
, 0, 0},
109 {0, 0, 0, 0, 0, 0, 0}
115 static void usage(FILE *ofp
)
117 fprintf(ofp
, "usage: lttng enable-event NAME[,NAME2,...] [-k|-u] [OPTIONS] \n");
119 fprintf(ofp
, "Options:\n");
120 fprintf(ofp
, " -h, --help Show this help\n");
121 fprintf(ofp
, " --list-options Simple listing of options\n");
122 fprintf(ofp
, " -s, --session NAME Apply to session name\n");
123 fprintf(ofp
, " -c, --channel NAME Apply to this channel\n");
124 fprintf(ofp
, " -a, --all Enable all tracepoints and syscalls\n");
125 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
126 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
127 fprintf(ofp
, " -j, --jul Apply for Java application using JUL\n");
128 fprintf(ofp
, " -l, --log4j Apply for Java application using LOG4j\n");
129 fprintf(ofp
, " -p, --python Apply for Java application using LOG4j\n");
131 fprintf(ofp
, "Event options:\n");
132 fprintf(ofp
, " --tracepoint Tracepoint event (default)\n");
133 fprintf(ofp
, " - userspace tracer supports wildcards at end of string.\n");
134 fprintf(ofp
, " Don't forget to quote to deal with bash expansion.\n");
135 fprintf(ofp
, " e.g.:\n");
136 fprintf(ofp
, " \"*\"\n");
137 fprintf(ofp
, " \"app_component:na*\"\n");
138 fprintf(ofp
, " --probe (addr | symbol | symbol+offset)\n");
139 fprintf(ofp
, " Dynamic probe.\n");
140 fprintf(ofp
, " Addr and offset can be octal (0NNN...),\n");
141 fprintf(ofp
, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
142 fprintf(ofp
, " --function (addr | symbol | symbol+offset)\n");
143 fprintf(ofp
, " Dynamic function entry/return probe.\n");
144 fprintf(ofp
, " Addr and offset can be octal (0NNN...),\n");
145 fprintf(ofp
, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
147 fprintf(ofp
, " --function:entry symbol\n");
148 fprintf(ofp
, " Function tracer event\n");
150 fprintf(ofp
, " --syscall System call event\n");
152 fprintf(ofp
, " --loglevel name\n");
153 fprintf(ofp
, " Tracepoint loglevel range from 0 to loglevel.\n");
154 fprintf(ofp
, " For JUL/LOG4j domain, see the table below for the range values.\n");
155 fprintf(ofp
, " --loglevel-only name\n");
156 fprintf(ofp
, " Tracepoint loglevel (only this loglevel)\n");
158 fprintf(ofp
, " The loglevel or loglevel-only options should be\n");
159 fprintf(ofp
, " combined with a tracepoint name or tracepoint\n");
160 fprintf(ofp
, " wildcard.\n");
161 fprintf(ofp
, " Available loglevels:\n");
162 fprintf(ofp
, " (higher value is more verbose)\n");
163 fprintf(ofp
, " TRACE_EMERG = 0\n");
164 fprintf(ofp
, " TRACE_ALERT = 1\n");
165 fprintf(ofp
, " TRACE_CRIT = 2\n");
166 fprintf(ofp
, " TRACE_ERR = 3\n");
167 fprintf(ofp
, " TRACE_WARNING = 4\n");
168 fprintf(ofp
, " TRACE_NOTICE = 5\n");
169 fprintf(ofp
, " TRACE_INFO = 6\n");
170 fprintf(ofp
, " TRACE_DEBUG_SYSTEM = 7\n");
171 fprintf(ofp
, " TRACE_DEBUG_PROGRAM = 8\n");
172 fprintf(ofp
, " TRACE_DEBUG_PROCESS = 9\n");
173 fprintf(ofp
, " TRACE_DEBUG_MODULE = 10\n");
174 fprintf(ofp
, " TRACE_DEBUG_UNIT = 11\n");
175 fprintf(ofp
, " TRACE_DEBUG_FUNCTION = 12\n");
176 fprintf(ofp
, " TRACE_DEBUG_LINE = 13\n");
177 fprintf(ofp
, " TRACE_DEBUG = 14\n");
178 fprintf(ofp
, " (shortcuts such as \"system\" are allowed)\n");
180 fprintf(ofp
, " Available JUL domain loglevels:\n");
181 fprintf(ofp
, " JUL_OFF = INT32_MAX\n");
182 fprintf(ofp
, " JUL_SEVERE = %d\n", LTTNG_LOGLEVEL_JUL_SEVERE
);
183 fprintf(ofp
, " JUL_WARNING = %d\n", LTTNG_LOGLEVEL_JUL_WARNING
);
184 fprintf(ofp
, " JUL_INFO = %d\n", LTTNG_LOGLEVEL_JUL_INFO
);
185 fprintf(ofp
, " JUL_CONFIG = %d\n", LTTNG_LOGLEVEL_JUL_CONFIG
);
186 fprintf(ofp
, " JUL_FINE = %d\n", LTTNG_LOGLEVEL_JUL_FINE
);
187 fprintf(ofp
, " JUL_FINER = %d\n", LTTNG_LOGLEVEL_JUL_FINER
);
188 fprintf(ofp
, " JUL_FINEST = %d\n", LTTNG_LOGLEVEL_JUL_FINEST
);
189 fprintf(ofp
, " JUL_ALL = INT32_MIN\n");
190 fprintf(ofp
, " (shortcuts such as \"severe\" are allowed)\n");
192 fprintf(ofp
, " Available LOG4j domain loglevels:\n");
193 fprintf(ofp
, " LOG4J_OFF = INT32_MAX\n");
194 fprintf(ofp
, " LOG4J_FATAL = %d\n", LTTNG_LOGLEVEL_LOG4J_FATAL
);
195 fprintf(ofp
, " LOG4J_ERROR = %d\n", LTTNG_LOGLEVEL_LOG4J_ERROR
);
196 fprintf(ofp
, " LOG4J_WARN = %d\n", LTTNG_LOGLEVEL_LOG4J_WARN
);
197 fprintf(ofp
, " LOG4J_INFO = %d\n", LTTNG_LOGLEVEL_LOG4J_INFO
);
198 fprintf(ofp
, " LOG4J_DEBUG = %d\n", LTTNG_LOGLEVEL_LOG4J_DEBUG
);
199 fprintf(ofp
, " LOG4J_TRACE = %d\n", LTTNG_LOGLEVEL_LOG4J_TRACE
);
200 fprintf(ofp
, " LOG4J_ALL = INT32_MIN\n");
201 fprintf(ofp
, " (shortcuts such as \"severe\" are allowed)\n");
203 fprintf(ofp
, " Available Python domain loglevels:\n");
204 fprintf(ofp
, " PYTHON_CRITICAL = %d\n", LTTNG_LOGLEVEL_PYTHON_CRITICAL
);
205 fprintf(ofp
, " PYTHON_ERROR = %d\n", LTTNG_LOGLEVEL_PYTHON_ERROR
);
206 fprintf(ofp
, " PYTHON_WARNING = %d\n", LTTNG_LOGLEVEL_PYTHON_WARNING
);
207 fprintf(ofp
, " PYTHON_INFO = %d\n", LTTNG_LOGLEVEL_PYTHON_INFO
);
208 fprintf(ofp
, " PYTHON_DEBUG = %d\n", LTTNG_LOGLEVEL_PYTHON_DEBUG
);
209 fprintf(ofp
, " PYTHON_NOTSET = %d\n", LTTNG_LOGLEVEL_PYTHON_NOTSET
);
210 fprintf(ofp
, " (shortcuts such as \"critical\" are allowed)\n");
212 fprintf(ofp
, " -f, --filter \'expression\'\n");
213 fprintf(ofp
, " Filter expression on event fields and context.\n");
214 fprintf(ofp
, " Event recording depends on evaluation.\n");
215 fprintf(ofp
, " Only specify on first activation of\n");
216 fprintf(ofp
, " a given event within a session.\n");
217 fprintf(ofp
, " Filter only allowed when enabling\n");
218 fprintf(ofp
, " events within a session before tracing\n");
219 fprintf(ofp
, " is started. If the filter fails to link\n");
220 fprintf(ofp
, " with the event within the traced domain,\n");
221 fprintf(ofp
, " the event will be discarded. Currently,\n");
222 fprintf(ofp
, " filter is only implemented for the user-space\n");
223 fprintf(ofp
, " tracer.\n");
224 fprintf(ofp
, " Expression examples:.\n");
226 fprintf(ofp
, " 'intfield > 500 && intfield < 503'\n");
227 fprintf(ofp
, " '(strfield == \"test\" || intfield != 10) && intfield > 33'\n");
228 fprintf(ofp
, " 'doublefield > 1.1 && intfield < 5.3'\n");
230 fprintf(ofp
, " Wildcards are allowed at the end of strings:\n");
231 fprintf(ofp
, " 'seqfield1 == \"te*\"'\n");
232 fprintf(ofp
, " In string literals, the escape character is '\\'.\n");
233 fprintf(ofp
, " Use '\\*' for the '*' character, and '\\\\' for\n");
234 fprintf(ofp
, " the '\\' character. Wildcard match any sequence of,\n");
235 fprintf(ofp
, " characters including an empty sub-string (match 0 or\n");
236 fprintf(ofp
, " more characters).\n");
238 fprintf(ofp
, " Context information can be used for filtering. The\n");
239 fprintf(ofp
, " examples below show usage of context filtering on\n");
240 fprintf(ofp
, " process name (with a wildcard), process ID range, and\n");
241 fprintf(ofp
, " unique thread ID for filtering. The process and\n");
242 fprintf(ofp
, " thread ID of running applications can be found under\n");
243 fprintf(ofp
, " columns \"PID\" and \"LWP\" of the \"ps -eLf\" command.\n");
245 fprintf(ofp
, " '$ctx.procname == \"demo*\"'\n");
246 fprintf(ofp
, " '$ctx.vpid >= 4433 && $ctx.vpid < 4455'\n");
247 fprintf(ofp
, " '$ctx.vtid == 1234'\n");
248 fprintf(ofp
, " -x, --exclude LIST\n");
249 fprintf(ofp
, " Add exclusions to UST tracepoints:\n");
250 fprintf(ofp
, " Events that match any of the items\n");
251 fprintf(ofp
, " in the comma-separated LIST are not\n");
252 fprintf(ofp
, " enabled, even if they match a wildcard\n");
253 fprintf(ofp
, " definition of the event.\n");
258 * Parse probe options.
260 static int parse_probe_opts(struct lttng_event
*ev
, char *opt
)
262 int ret
= CMD_SUCCESS
;
265 #define S_HEX_LEN_SCANF_IS_A_BROKEN_API "18" /* 18 is (19 - 1) (\0 is extra) */
266 char name
[LTTNG_SYMBOL_NAME_LEN
];
273 /* Check for symbol+offset */
274 match
= sscanf(opt
, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
275 "[^'+']+%" S_HEX_LEN_SCANF_IS_A_BROKEN_API
"s", name
, s_hex
);
277 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
278 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
279 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
280 if (*s_hex
== '\0') {
281 ERR("Invalid probe offset %s", s_hex
);
285 ev
->attr
.probe
.offset
= strtoul(s_hex
, NULL
, 0);
286 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
287 ev
->attr
.probe
.addr
= 0;
291 /* Check for symbol */
292 if (isalpha(name
[0])) {
293 match
= sscanf(opt
, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
"s",
296 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
297 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
298 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
299 ev
->attr
.probe
.offset
= 0;
300 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
301 ev
->attr
.probe
.addr
= 0;
306 /* Check for address */
307 match
= sscanf(opt
, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API
"s", s_hex
);
309 if (*s_hex
== '\0') {
310 ERR("Invalid probe address %s", s_hex
);
314 ev
->attr
.probe
.addr
= strtoul(s_hex
, NULL
, 0);
315 DBG("probe addr %" PRIu64
, ev
->attr
.probe
.addr
);
316 ev
->attr
.probe
.offset
= 0;
317 memset(ev
->attr
.probe
.symbol_name
, 0, LTTNG_SYMBOL_NAME_LEN
);
329 * Maps LOG4j loglevel from string to value
331 static int loglevel_log4j_str_to_value(const char *inputstr
)
334 char str
[LTTNG_SYMBOL_NAME_LEN
];
337 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
338 * added at the end of the loop so a the upper bound we avoid the overflow.
340 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
341 str
[i
] = toupper(inputstr
[i
]);
346 if (!strcmp(str
, "LOG4J_OFF") || !strcmp(str
, "OFF")) {
347 return LTTNG_LOGLEVEL_LOG4J_OFF
;
348 } else if (!strcmp(str
, "LOG4J_FATAL") || !strcmp(str
, "FATAL")) {
349 return LTTNG_LOGLEVEL_LOG4J_FATAL
;
350 } else if (!strcmp(str
, "LOG4J_ERROR") || !strcmp(str
, "ERROR")) {
351 return LTTNG_LOGLEVEL_LOG4J_ERROR
;
352 } else if (!strcmp(str
, "LOG4J_WARN") || !strcmp(str
, "WARN")) {
353 return LTTNG_LOGLEVEL_LOG4J_WARN
;
354 } else if (!strcmp(str
, "LOG4J_INFO") || !strcmp(str
, "INFO")) {
355 return LTTNG_LOGLEVEL_LOG4J_INFO
;
356 } else if (!strcmp(str
, "LOG4J_DEBUG") || !strcmp(str
, "DEBUG")) {
357 return LTTNG_LOGLEVEL_LOG4J_DEBUG
;
358 } else if (!strcmp(str
, "LOG4J_TRACE") || !strcmp(str
, "TRACE")) {
359 return LTTNG_LOGLEVEL_LOG4J_TRACE
;
360 } else if (!strcmp(str
, "LOG4J_ALL") || !strcmp(str
, "ALL")) {
361 return LTTNG_LOGLEVEL_LOG4J_ALL
;
368 * Maps JUL loglevel from string to value
370 static int loglevel_jul_str_to_value(const char *inputstr
)
373 char str
[LTTNG_SYMBOL_NAME_LEN
];
376 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
377 * added at the end of the loop so a the upper bound we avoid the overflow.
379 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
380 str
[i
] = toupper(inputstr
[i
]);
385 if (!strcmp(str
, "JUL_OFF") || !strcmp(str
, "OFF")) {
386 return LTTNG_LOGLEVEL_JUL_OFF
;
387 } else if (!strcmp(str
, "JUL_SEVERE") || !strcmp(str
, "SEVERE")) {
388 return LTTNG_LOGLEVEL_JUL_SEVERE
;
389 } else if (!strcmp(str
, "JUL_WARNING") || !strcmp(str
, "WARNING")) {
390 return LTTNG_LOGLEVEL_JUL_WARNING
;
391 } else if (!strcmp(str
, "JUL_INFO") || !strcmp(str
, "INFO")) {
392 return LTTNG_LOGLEVEL_JUL_INFO
;
393 } else if (!strcmp(str
, "JUL_CONFIG") || !strcmp(str
, "CONFIG")) {
394 return LTTNG_LOGLEVEL_JUL_CONFIG
;
395 } else if (!strcmp(str
, "JUL_FINE") || !strcmp(str
, "FINE")) {
396 return LTTNG_LOGLEVEL_JUL_FINE
;
397 } else if (!strcmp(str
, "JUL_FINER") || !strcmp(str
, "FINER")) {
398 return LTTNG_LOGLEVEL_JUL_FINER
;
399 } else if (!strcmp(str
, "JUL_FINEST") || !strcmp(str
, "FINEST")) {
400 return LTTNG_LOGLEVEL_JUL_FINEST
;
401 } else if (!strcmp(str
, "JUL_ALL") || !strcmp(str
, "ALL")) {
402 return LTTNG_LOGLEVEL_JUL_ALL
;
409 * Maps Python loglevel from string to value
411 static int loglevel_python_str_to_value(const char *inputstr
)
414 char str
[LTTNG_SYMBOL_NAME_LEN
];
417 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
418 * added at the end of the loop so a the upper bound we avoid the overflow.
420 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
421 str
[i
] = toupper(inputstr
[i
]);
426 if (!strcmp(str
, "PYTHON_CRITICAL") || !strcmp(str
, "CRITICAL")) {
427 return LTTNG_LOGLEVEL_PYTHON_CRITICAL
;
428 } else if (!strcmp(str
, "PYTHON_ERROR") || !strcmp(str
, "ERROR")) {
429 return LTTNG_LOGLEVEL_PYTHON_ERROR
;
430 } else if (!strcmp(str
, "PYTHON_WARNING") || !strcmp(str
, "WARNING")) {
431 return LTTNG_LOGLEVEL_PYTHON_WARNING
;
432 } else if (!strcmp(str
, "PYTHON_INFO") || !strcmp(str
, "INFO")) {
433 return LTTNG_LOGLEVEL_PYTHON_INFO
;
434 } else if (!strcmp(str
, "PYTNON_DEBUG") || !strcmp(str
, "DEBUG")) {
435 return LTTNG_LOGLEVEL_PYTHON_DEBUG
;
436 } else if (!strcmp(str
, "PYTHON_NOTSET") || !strcmp(str
, "NOTSET")) {
437 return LTTNG_LOGLEVEL_PYTHON_NOTSET
;
444 * Maps loglevel from string to value
447 int loglevel_str_to_value(const char *inputstr
)
450 char str
[LTTNG_SYMBOL_NAME_LEN
];
453 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
454 * added at the end of the loop so a the upper bound we avoid the overflow.
456 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
457 str
[i
] = toupper(inputstr
[i
]);
461 if (!strcmp(str
, "TRACE_EMERG") || !strcmp(str
, "EMERG")) {
462 return LTTNG_LOGLEVEL_EMERG
;
463 } else if (!strcmp(str
, "TRACE_ALERT") || !strcmp(str
, "ALERT")) {
464 return LTTNG_LOGLEVEL_ALERT
;
465 } else if (!strcmp(str
, "TRACE_CRIT") || !strcmp(str
, "CRIT")) {
466 return LTTNG_LOGLEVEL_CRIT
;
467 } else if (!strcmp(str
, "TRACE_ERR") || !strcmp(str
, "ERR")) {
468 return LTTNG_LOGLEVEL_ERR
;
469 } else if (!strcmp(str
, "TRACE_WARNING") || !strcmp(str
, "WARNING")) {
470 return LTTNG_LOGLEVEL_WARNING
;
471 } else if (!strcmp(str
, "TRACE_NOTICE") || !strcmp(str
, "NOTICE")) {
472 return LTTNG_LOGLEVEL_NOTICE
;
473 } else if (!strcmp(str
, "TRACE_INFO") || !strcmp(str
, "INFO")) {
474 return LTTNG_LOGLEVEL_INFO
;
475 } else if (!strcmp(str
, "TRACE_DEBUG_SYSTEM") || !strcmp(str
, "DEBUG_SYSTEM") || !strcmp(str
, "SYSTEM")) {
476 return LTTNG_LOGLEVEL_DEBUG_SYSTEM
;
477 } else if (!strcmp(str
, "TRACE_DEBUG_PROGRAM") || !strcmp(str
, "DEBUG_PROGRAM") || !strcmp(str
, "PROGRAM")) {
478 return LTTNG_LOGLEVEL_DEBUG_PROGRAM
;
479 } else if (!strcmp(str
, "TRACE_DEBUG_PROCESS") || !strcmp(str
, "DEBUG_PROCESS") || !strcmp(str
, "PROCESS")) {
480 return LTTNG_LOGLEVEL_DEBUG_PROCESS
;
481 } else if (!strcmp(str
, "TRACE_DEBUG_MODULE") || !strcmp(str
, "DEBUG_MODULE") || !strcmp(str
, "MODULE")) {
482 return LTTNG_LOGLEVEL_DEBUG_MODULE
;
483 } else if (!strcmp(str
, "TRACE_DEBUG_UNIT") || !strcmp(str
, "DEBUG_UNIT") || !strcmp(str
, "UNIT")) {
484 return LTTNG_LOGLEVEL_DEBUG_UNIT
;
485 } else if (!strcmp(str
, "TRACE_DEBUG_FUNCTION") || !strcmp(str
, "DEBUG_FUNCTION") || !strcmp(str
, "FUNCTION")) {
486 return LTTNG_LOGLEVEL_DEBUG_FUNCTION
;
487 } else if (!strcmp(str
, "TRACE_DEBUG_LINE") || !strcmp(str
, "DEBUG_LINE") || !strcmp(str
, "LINE")) {
488 return LTTNG_LOGLEVEL_DEBUG_LINE
;
489 } else if (!strcmp(str
, "TRACE_DEBUG") || !strcmp(str
, "DEBUG")) {
490 return LTTNG_LOGLEVEL_DEBUG
;
497 const char *print_channel_name(const char *name
)
499 return name
? : DEFAULT_CHANNEL_NAME
;
503 const char *print_raw_channel_name(const char *name
)
505 return name
? : "<default>";
509 * Mi print exlcusion list
512 int mi_print_exclusion(int count
, char **names
)
522 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
527 for (i
= 0; i
< count
; i
++) {
528 ret
= mi_lttng_writer_write_element_string(writer
,
529 config_element_exclusion
, names
[i
]);
535 /* Close exclusions element */
536 ret
= mi_lttng_writer_close_element(writer
);
543 * Return allocated string for pretty-printing exclusion names.
546 char *print_exclusions(int count
, char **names
)
550 const char *preamble
= " excluding ";
557 /* calculate total required length */
558 for (i
= 0; i
< count
; i
++) {
559 length
+= strlen(names
[i
]) + 1;
562 /* add length of preamble + one for NUL - one for last (missing) comma */
563 length
+= strlen(preamble
);
564 ret
= malloc(length
);
565 strncpy(ret
, preamble
, length
);
566 for (i
= 0; i
< count
; i
++) {
567 strcat(ret
, names
[i
]);
568 if (i
!= count
- 1) {
577 * Compare list of exclusions against an event name.
578 * Return a list of legal exclusion names.
579 * Produce an error or a warning about others (depending on the situation)
582 int check_exclusion_subsets(const char *event_name
,
583 const char *exclusions
,
584 int *exclusion_count_ptr
,
585 char ***exclusion_list_ptr
)
587 const char *excluder_ptr
;
588 const char *event_ptr
;
589 const char *next_excluder
;
591 int exclusion_count
= 0;
592 char **exclusion_list
= NULL
;
593 int ret
= CMD_SUCCESS
;
595 if (event_name
[strlen(event_name
) - 1] != '*') {
596 ERR("Event %s: Excluders can only be used with wildcarded events", event_name
);
600 next_excluder
= exclusions
;
601 while (*next_excluder
!= 0) {
602 event_ptr
= event_name
;
603 excluder_ptr
= next_excluder
;
604 excluder_length
= strcspn(next_excluder
, ",");
606 /* Scan both the excluder and the event letter by letter */
614 /* Event is a subset of the excluder */
615 ERR("Event %s: %.*s excludes all events from %s",
623 /* Excluder is a proper subset of event */
625 exclusion_list
= realloc(exclusion_list
, sizeof(char **) * exclusion_count
);
626 exclusion_list
[exclusion_count
- 1] = strndup(next_excluder
, excluder_length
);
631 /* Excluder and event sets have no common elements */
632 WARN("Event %s: %.*s does not exclude any events from %s",
643 next_excluder
+= excluder_length
;
644 if (*next_excluder
== ',') {
650 while (exclusion_count
--) {
651 free(exclusion_list
[exclusion_count
]);
653 if (exclusion_list
!= NULL
) {
654 free(exclusion_list
);
656 exclusion_list
= NULL
;
660 *exclusion_count_ptr
= exclusion_count
;
661 *exclusion_list_ptr
= exclusion_list
;
665 * Enabling event using the lttng API.
666 * Note: in case of error only the last error code will be return.
668 static int enable_events(char *session_name
)
670 int ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
;
671 int error_holder
= CMD_SUCCESS
, warn
= 0, error
= 0, success
= 1;
672 char *event_name
, *channel_name
= NULL
;
673 struct lttng_event ev
;
674 struct lttng_domain dom
;
675 int exclusion_count
= 0;
676 char **exclusion_list
= NULL
;
678 memset(&ev
, 0, sizeof(ev
));
679 memset(&dom
, 0, sizeof(dom
));
683 ERR("Filter not implement for kernel tracing yet");
688 WARN("Kernel loglevels are not supported.");
692 /* Create lttng domain */
694 dom
.type
= LTTNG_DOMAIN_KERNEL
;
695 dom
.buf_type
= LTTNG_BUFFER_GLOBAL
;
696 } else if (opt_userspace
) {
697 dom
.type
= LTTNG_DOMAIN_UST
;
699 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
700 } else if (opt_jul
) {
701 dom
.type
= LTTNG_DOMAIN_JUL
;
703 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
704 } else if (opt_log4j
) {
705 dom
.type
= LTTNG_DOMAIN_LOG4J
;
707 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
708 } else if (opt_python
) {
709 dom
.type
= LTTNG_DOMAIN_PYTHON
;
711 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
713 print_missing_domain();
718 if (opt_kernel
&& opt_exclude
) {
719 ERR("Event name exclusions are not yet implemented for kernel events");
724 channel_name
= opt_channel_name
;
726 handle
= lttng_create_handle(session_name
, &dom
);
727 if (handle
== NULL
) {
734 /* Open a events element */
735 ret
= mi_lttng_writer_open_element(writer
, config_element_events
);
742 if (opt_enable_all
) {
743 /* Default setup for enable all */
745 ev
.type
= opt_event_type
;
747 /* kernel loglevels not implemented */
748 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
750 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
751 strcpy(ev
.name
, "*");
752 ev
.loglevel_type
= opt_loglevel_type
;
754 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
756 ev
.loglevel
= loglevel_str_to_value(opt_loglevel
);
757 } else if (opt_jul
) {
758 ev
.loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
759 } else if (opt_log4j
) {
760 ev
.loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
761 } else if (opt_python
) {
762 ev
.loglevel
= loglevel_python_str_to_value(opt_loglevel
);
764 if (ev
.loglevel
== -1) {
765 ERR("Unknown loglevel %s", opt_loglevel
);
766 ret
= -LTTNG_ERR_INVALID
;
770 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
773 } else if (opt_jul
|| opt_log4j
) {
774 ev
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
775 } else if (opt_python
) {
776 ev
.loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
782 ret
= check_exclusion_subsets("*", opt_exclude
,
783 &exclusion_count
, &exclusion_list
);
784 if (ret
== CMD_ERROR
) {
790 ret
= lttng_enable_event_with_exclusions(handle
,
793 exclusion_count
, exclusion_list
);
796 case LTTNG_ERR_KERN_EVENT_EXIST
:
797 WARN("Kernel events already enabled (channel %s, session %s)",
798 print_channel_name(channel_name
), session_name
);
801 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
803 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
804 ERR("Events: %s (channel %s, session %s)",
806 print_channel_name(channel_name
),
812 ERR("Events: %s (channel %s, session %s)",
814 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
815 ? print_raw_channel_name(channel_name
)
816 : print_channel_name(channel_name
),
824 switch (opt_event_type
) {
825 case LTTNG_EVENT_TRACEPOINT
:
826 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
827 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
828 MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
829 get_domain_str(dom
.type
),
831 print_channel_name(channel_name
),
833 free(exclusion_string
);
835 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
836 MSG("All %s tracepoints%s are enabled in channel %s",
837 get_domain_str(dom
.type
),
839 print_channel_name(channel_name
));
840 free(exclusion_string
);
843 case LTTNG_EVENT_SYSCALL
:
845 MSG("All %s system calls are enabled in channel %s",
846 get_domain_str(dom
.type
),
847 print_channel_name(channel_name
));
850 case LTTNG_EVENT_ALL
:
851 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
852 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
853 MSG("All %s events%s are enabled in channel %s for loglevel %s",
854 get_domain_str(dom
.type
),
856 print_channel_name(channel_name
),
858 free(exclusion_string
);
860 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
861 MSG("All %s events%s are enabled in channel %s",
862 get_domain_str(dom
.type
),
864 print_channel_name(channel_name
));
865 free(exclusion_string
);
870 * We should not be here since lttng_enable_event should have
871 * failed on the event type.
878 command_ret
= lttng_enable_event_with_exclusions(handle
, &ev
, channel_name
,
879 opt_filter
, exclusion_count
, exclusion_list
);
880 if (command_ret
< 0) {
881 switch (-command_ret
) {
882 case LTTNG_ERR_FILTER_EXIST
:
883 WARN("Filter on all events is already enabled"
884 " (channel %s, session %s)",
885 print_channel_name(channel_name
), session_name
);
888 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
890 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
891 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
893 print_channel_name(channel_name
),
894 session_name
, opt_filter
);
899 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
900 lttng_strerror(command_ret
),
901 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
902 ? print_raw_channel_name(channel_name
)
903 : print_channel_name(channel_name
),
904 session_name
, opt_filter
);
908 error_holder
= command_ret
;
911 MSG("Filter '%s' successfully set", opt_filter
);
916 /* The wildcard * is used for kernel and ust domain to
917 * represent ALL. We copy * in event name to force the wildcard use
920 * Note: this is strictly for semantic and printing while in
921 * machine interface mode.
923 strcpy(ev
.name
, "*");
925 /* If we reach here the events are enabled */
926 if (!error
&& !warn
) {
932 ret
= mi_lttng_event(writer
, &ev
, 1, handle
->domain
.type
);
938 /* print exclusion */
939 ret
= mi_print_exclusion(exclusion_count
, exclusion_list
);
946 ret
= mi_lttng_writer_write_element_bool(writer
,
947 mi_lttng_element_command_success
, success
);
953 /* Close event element */
954 ret
= mi_lttng_writer_close_element(writer
);
964 /* Strip event list */
965 event_name
= strtok(opt_event_list
, ",");
966 while (event_name
!= NULL
) {
967 /* Copy name and type of the event */
968 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
969 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
970 ev
.type
= opt_event_type
;
972 /* Kernel tracer action */
974 DBG("Enabling kernel event %s for channel %s",
976 print_channel_name(channel_name
));
978 switch (opt_event_type
) {
979 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
980 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
982 case LTTNG_EVENT_TRACEPOINT
:
984 case LTTNG_EVENT_PROBE
:
985 ret
= parse_probe_opts(&ev
, opt_probe
);
987 ERR("Unable to parse probe options");
992 case LTTNG_EVENT_FUNCTION
:
993 ret
= parse_probe_opts(&ev
, opt_function
);
995 ERR("Unable to parse function probe options");
1000 case LTTNG_EVENT_FUNCTION_ENTRY
:
1001 strncpy(ev
.attr
.ftrace
.symbol_name
, opt_function_entry_symbol
,
1002 LTTNG_SYMBOL_NAME_LEN
);
1003 ev
.attr
.ftrace
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1005 case LTTNG_EVENT_SYSCALL
:
1006 ev
.type
= LTTNG_EVENT_SYSCALL
;
1009 ret
= CMD_UNDEFINED
;
1013 /* kernel loglevels not implemented */
1014 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
1015 } else if (opt_userspace
) { /* User-space tracer action */
1017 if (opt_cmd_name
!= NULL
|| opt_pid
) {
1018 MSG("Only supporting tracing all UST processes (-u) for now.");
1019 ret
= CMD_UNDEFINED
;
1024 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name
,
1025 print_channel_name(channel_name
), opt_loglevel
? : "<all>");
1027 switch (opt_event_type
) {
1028 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
1030 case LTTNG_EVENT_TRACEPOINT
:
1031 /* Copy name and type of the event */
1032 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
1033 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1034 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1036 case LTTNG_EVENT_PROBE
:
1037 case LTTNG_EVENT_FUNCTION
:
1038 case LTTNG_EVENT_FUNCTION_ENTRY
:
1039 case LTTNG_EVENT_SYSCALL
:
1041 ERR("Event type not available for user-space tracing");
1042 ret
= CMD_UNSUPPORTED
;
1048 if (opt_event_type
!= LTTNG_EVENT_ALL
&& opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1049 ERR("Exclusion option can only be used with tracepoint events");
1053 /* Free previously allocated items */
1054 if (exclusion_list
!= NULL
) {
1055 while (exclusion_count
--) {
1056 free(exclusion_list
[exclusion_count
]);
1058 free(exclusion_list
);
1059 exclusion_list
= NULL
;
1061 /* Check for proper subsets */
1062 ret
= check_exclusion_subsets(event_name
, opt_exclude
,
1063 &exclusion_count
, &exclusion_list
);
1064 if (ret
== CMD_ERROR
) {
1069 ev
.loglevel_type
= opt_loglevel_type
;
1071 ev
.loglevel
= loglevel_str_to_value(opt_loglevel
);
1072 if (ev
.loglevel
== -1) {
1073 ERR("Unknown loglevel %s", opt_loglevel
);
1074 ret
= -LTTNG_ERR_INVALID
;
1080 } else if (opt_jul
|| opt_log4j
|| opt_python
) {
1081 if (opt_event_type
!= LTTNG_EVENT_ALL
&&
1082 opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1083 ERR("Event type not supported for domain.");
1084 ret
= CMD_UNSUPPORTED
;
1088 ev
.loglevel_type
= opt_loglevel_type
;
1091 ev
.loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
1092 } else if (opt_log4j
) {
1093 ev
.loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
1094 } else if (opt_python
) {
1095 ev
.loglevel
= loglevel_python_str_to_value(opt_loglevel
);
1097 if (ev
.loglevel
== -1) {
1098 ERR("Unknown loglevel %s", opt_loglevel
);
1099 ret
= -LTTNG_ERR_INVALID
;
1104 ev
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1105 } else if (opt_log4j
) {
1106 ev
.loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1107 } else if (opt_python
) {
1108 ev
.loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1111 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
1112 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1113 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1115 print_missing_domain();
1121 char *exclusion_string
;
1123 command_ret
= lttng_enable_event_with_exclusions(handle
,
1125 NULL
, exclusion_count
, exclusion_list
);
1126 exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
1127 if (command_ret
< 0) {
1128 /* Turn ret to positive value to handle the positive error code */
1129 switch (-command_ret
) {
1130 case LTTNG_ERR_KERN_EVENT_EXIST
:
1131 WARN("Kernel event %s%s already enabled (channel %s, session %s)",
1134 print_channel_name(channel_name
), session_name
);
1137 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1139 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1140 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1143 print_channel_name(channel_name
),
1149 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1151 lttng_strerror(command_ret
),
1152 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1153 ? print_raw_channel_name(channel_name
)
1154 : print_channel_name(channel_name
),
1159 error_holder
= command_ret
;
1161 /* So we don't print the default channel name for agent domain. */
1162 if (dom
.type
== LTTNG_DOMAIN_JUL
||
1163 dom
.type
== LTTNG_DOMAIN_LOG4J
) {
1164 MSG("%s event %s%s enabled.",
1165 get_domain_str(dom
.type
), event_name
,
1168 MSG("%s event %s%s created in channel %s",
1169 get_domain_str(dom
.type
), event_name
,
1171 print_channel_name(channel_name
));
1174 free(exclusion_string
);
1178 char *exclusion_string
;
1180 /* Filter present */
1183 command_ret
= lttng_enable_event_with_exclusions(handle
, &ev
, channel_name
,
1184 opt_filter
, exclusion_count
, exclusion_list
);
1185 exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
1187 if (command_ret
< 0) {
1188 switch (-command_ret
) {
1189 case LTTNG_ERR_FILTER_EXIST
:
1190 WARN("Filter on event %s%s is already enabled"
1191 " (channel %s, session %s)",
1194 print_channel_name(channel_name
), session_name
);
1197 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1199 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1200 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
.name
,
1203 print_channel_name(channel_name
),
1204 session_name
, opt_filter
);
1209 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
.name
,
1211 lttng_strerror(command_ret
),
1212 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1213 ? print_raw_channel_name(channel_name
)
1214 : print_channel_name(channel_name
),
1215 session_name
, opt_filter
);
1219 error_holder
= command_ret
;
1222 MSG("Event %s%s: Filter '%s' successfully set",
1223 event_name
, exclusion_string
,
1226 free(exclusion_string
);
1237 ret
= mi_lttng_event(writer
, &ev
, 1, handle
->domain
.type
);
1243 /* print exclusion */
1244 ret
= mi_print_exclusion(exclusion_count
, exclusion_list
);
1251 ret
= mi_lttng_writer_write_element_bool(writer
,
1252 mi_lttng_element_command_success
, success
);
1258 /* Close event element */
1259 ret
= mi_lttng_writer_close_element(writer
);
1267 event_name
= strtok(NULL
, ",");
1268 /* Reset warn, error and success */
1275 /* Close events element */
1276 ret
= mi_lttng_writer_close_element(writer
);
1289 lttng_destroy_handle(handle
);
1291 if (exclusion_list
!= NULL
) {
1292 while (exclusion_count
--) {
1293 free(exclusion_list
[exclusion_count
]);
1295 free(exclusion_list
);
1298 /* Overwrite ret with error_holder if there was an actual error with
1299 * enabling an event.
1301 ret
= error_holder
? error_holder
: ret
;
1307 * Add event to trace session
1309 int cmd_enable_events(int argc
, const char **argv
)
1311 int opt
, ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
, success
= 1;
1312 static poptContext pc
;
1313 char *session_name
= NULL
;
1314 int event_type
= -1;
1316 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
1317 poptReadDefaultConfig(pc
, 0);
1319 /* Default event type */
1320 opt_event_type
= LTTNG_EVENT_ALL
;
1322 while ((opt
= poptGetNextOpt(pc
)) != -1) {
1327 case OPT_TRACEPOINT
:
1328 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
1331 opt_event_type
= LTTNG_EVENT_PROBE
;
1334 opt_event_type
= LTTNG_EVENT_FUNCTION
;
1336 case OPT_FUNCTION_ENTRY
:
1337 opt_event_type
= LTTNG_EVENT_FUNCTION_ENTRY
;
1340 opt_event_type
= LTTNG_EVENT_SYSCALL
;
1346 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1347 opt_loglevel
= poptGetOptArg(pc
);
1349 case OPT_LOGLEVEL_ONLY
:
1350 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1351 opt_loglevel
= poptGetOptArg(pc
);
1353 case OPT_LIST_OPTIONS
:
1354 list_cmd_options(stdout
, long_options
);
1362 ret
= CMD_UNDEFINED
;
1366 /* Validate event type. Multiple event type are not supported. */
1367 if (event_type
== -1) {
1368 event_type
= opt_event_type
;
1370 if (event_type
!= opt_event_type
) {
1371 ERR("Multiple event type not supported.");
1380 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
1382 ret
= -LTTNG_ERR_NOMEM
;
1386 /* Open command element */
1387 ret
= mi_lttng_writer_command_open(writer
,
1388 mi_lttng_element_command_enable_event
);
1394 /* Open output element */
1395 ret
= mi_lttng_writer_open_element(writer
,
1396 mi_lttng_element_command_output
);
1403 opt_event_list
= (char*) poptGetArg(pc
);
1404 if (opt_event_list
== NULL
&& opt_enable_all
== 0) {
1405 ERR("Missing event name(s).\n");
1411 if (!opt_session_name
) {
1412 session_name
= get_session_name();
1413 if (session_name
== NULL
) {
1414 command_ret
= CMD_ERROR
;
1419 session_name
= opt_session_name
;
1422 command_ret
= enable_events(session_name
);
1431 /* Close output element */
1432 ret
= mi_lttng_writer_close_element(writer
);
1438 ret
= mi_lttng_writer_write_element_bool(writer
,
1439 mi_lttng_element_command_success
, success
);
1445 /* Command element close */
1446 ret
= mi_lttng_writer_command_close(writer
);
1455 if (writer
&& mi_lttng_writer_destroy(writer
)) {
1456 /* Preserve original error code */
1457 ret
= ret
? ret
: LTTNG_ERR_MI_IO_FAIL
;
1460 if (opt_session_name
== NULL
) {
1464 /* Overwrite ret if an error occurred in enable_events */
1465 ret
= command_ret
? command_ret
: ret
;
1467 poptFreeContext(pc
);