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_function_entry_symbol
;
56 static char *opt_channel_name
;
57 static char *opt_filter
;
58 static char *opt_exclude
;
60 /* Not implemented yet */
61 static char *opt_cmd_name
;
80 static struct lttng_handle
*handle
;
81 static struct mi_writer
*writer
;
83 static struct poptOption long_options
[] = {
84 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
85 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
86 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
87 {"all", 'a', POPT_ARG_VAL
, &opt_enable_all
, 1, 0, 0},
88 {"channel", 'c', POPT_ARG_STRING
, &opt_channel_name
, 0, 0, 0},
89 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
90 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
91 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
92 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
93 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
94 {"tracepoint", 0, POPT_ARG_NONE
, 0, OPT_TRACEPOINT
, 0, 0},
95 {"probe", 0, POPT_ARG_STRING
, &opt_probe
, OPT_PROBE
, 0, 0},
96 {"function", 0, POPT_ARG_STRING
, &opt_function
, OPT_FUNCTION
, 0, 0},
99 * Currently removed from lttng kernel tracer. Removed from
100 * lttng UI to discourage its use.
102 {"function:entry", 0, POPT_ARG_STRING
, &opt_function_entry_symbol
, OPT_FUNCTION_ENTRY
, 0, 0},
104 {"syscall", 0, POPT_ARG_NONE
, 0, OPT_SYSCALL
, 0, 0},
105 {"loglevel", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL
, 0, 0},
106 {"loglevel-only", 0, POPT_ARG_STRING
, 0, OPT_LOGLEVEL_ONLY
, 0, 0},
107 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
108 {"filter", 'f', POPT_ARG_STRING
, &opt_filter
, OPT_FILTER
, 0, 0},
109 {"exclude", 'x', POPT_ARG_STRING
, &opt_exclude
, OPT_EXCLUDE
, 0, 0},
110 {0, 0, 0, 0, 0, 0, 0}
116 static void usage(FILE *ofp
)
118 fprintf(ofp
, "usage: lttng enable-event NAME[,NAME2,...] [-k|-u] [OPTIONS] \n");
120 fprintf(ofp
, "Options:\n");
121 fprintf(ofp
, " -h, --help Show this help\n");
122 fprintf(ofp
, " --list-options Simple listing of options\n");
123 fprintf(ofp
, " -s, --session NAME Apply to session name\n");
124 fprintf(ofp
, " -c, --channel NAME Apply to this channel\n");
125 fprintf(ofp
, " -a, --all Enable all tracepoints and syscalls\n");
126 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
127 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
128 fprintf(ofp
, " -j, --jul Apply for Java application using JUL\n");
129 fprintf(ofp
, " -l, --log4j Apply for Java application using LOG4j\n");
130 fprintf(ofp
, " -p, --python Apply for Java application using LOG4j\n");
132 fprintf(ofp
, "Event options:\n");
133 fprintf(ofp
, " --tracepoint Tracepoint event (default)\n");
134 fprintf(ofp
, " - userspace tracer supports wildcards at end of string.\n");
135 fprintf(ofp
, " Don't forget to quote to deal with bash expansion.\n");
136 fprintf(ofp
, " e.g.:\n");
137 fprintf(ofp
, " \"*\"\n");
138 fprintf(ofp
, " \"app_component:na*\"\n");
139 fprintf(ofp
, " --probe (addr | symbol | symbol+offset)\n");
140 fprintf(ofp
, " Dynamic probe.\n");
141 fprintf(ofp
, " Addr and offset can be octal (0NNN...),\n");
142 fprintf(ofp
, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
143 fprintf(ofp
, " --function (addr | symbol | symbol+offset)\n");
144 fprintf(ofp
, " Dynamic function entry/return probe.\n");
145 fprintf(ofp
, " Addr and offset can be octal (0NNN...),\n");
146 fprintf(ofp
, " decimal (NNN...) or hexadecimal (0xNNN...)\n");
148 fprintf(ofp
, " --function:entry symbol\n");
149 fprintf(ofp
, " Function tracer event\n");
151 fprintf(ofp
, " --syscall System call event\n");
153 fprintf(ofp
, " --loglevel name\n");
154 fprintf(ofp
, " Tracepoint loglevel range from 0 to loglevel.\n");
155 fprintf(ofp
, " For JUL/LOG4j domain, see the table below for the range values.\n");
156 fprintf(ofp
, " --loglevel-only name\n");
157 fprintf(ofp
, " Tracepoint loglevel (only this loglevel)\n");
159 fprintf(ofp
, " The loglevel or loglevel-only options should be\n");
160 fprintf(ofp
, " combined with a tracepoint name or tracepoint\n");
161 fprintf(ofp
, " wildcard.\n");
162 fprintf(ofp
, " Available loglevels:\n");
163 fprintf(ofp
, " (higher value is more verbose)\n");
164 fprintf(ofp
, " TRACE_EMERG = 0\n");
165 fprintf(ofp
, " TRACE_ALERT = 1\n");
166 fprintf(ofp
, " TRACE_CRIT = 2\n");
167 fprintf(ofp
, " TRACE_ERR = 3\n");
168 fprintf(ofp
, " TRACE_WARNING = 4\n");
169 fprintf(ofp
, " TRACE_NOTICE = 5\n");
170 fprintf(ofp
, " TRACE_INFO = 6\n");
171 fprintf(ofp
, " TRACE_DEBUG_SYSTEM = 7\n");
172 fprintf(ofp
, " TRACE_DEBUG_PROGRAM = 8\n");
173 fprintf(ofp
, " TRACE_DEBUG_PROCESS = 9\n");
174 fprintf(ofp
, " TRACE_DEBUG_MODULE = 10\n");
175 fprintf(ofp
, " TRACE_DEBUG_UNIT = 11\n");
176 fprintf(ofp
, " TRACE_DEBUG_FUNCTION = 12\n");
177 fprintf(ofp
, " TRACE_DEBUG_LINE = 13\n");
178 fprintf(ofp
, " TRACE_DEBUG = 14\n");
179 fprintf(ofp
, " (shortcuts such as \"system\" are allowed)\n");
181 fprintf(ofp
, " Available JUL domain loglevels:\n");
182 fprintf(ofp
, " JUL_OFF = INT32_MAX\n");
183 fprintf(ofp
, " JUL_SEVERE = %d\n", LTTNG_LOGLEVEL_JUL_SEVERE
);
184 fprintf(ofp
, " JUL_WARNING = %d\n", LTTNG_LOGLEVEL_JUL_WARNING
);
185 fprintf(ofp
, " JUL_INFO = %d\n", LTTNG_LOGLEVEL_JUL_INFO
);
186 fprintf(ofp
, " JUL_CONFIG = %d\n", LTTNG_LOGLEVEL_JUL_CONFIG
);
187 fprintf(ofp
, " JUL_FINE = %d\n", LTTNG_LOGLEVEL_JUL_FINE
);
188 fprintf(ofp
, " JUL_FINER = %d\n", LTTNG_LOGLEVEL_JUL_FINER
);
189 fprintf(ofp
, " JUL_FINEST = %d\n", LTTNG_LOGLEVEL_JUL_FINEST
);
190 fprintf(ofp
, " JUL_ALL = INT32_MIN\n");
191 fprintf(ofp
, " (shortcuts such as \"severe\" are allowed)\n");
193 fprintf(ofp
, " Available LOG4j domain loglevels:\n");
194 fprintf(ofp
, " LOG4J_OFF = INT32_MAX\n");
195 fprintf(ofp
, " LOG4J_FATAL = %d\n", LTTNG_LOGLEVEL_LOG4J_FATAL
);
196 fprintf(ofp
, " LOG4J_ERROR = %d\n", LTTNG_LOGLEVEL_LOG4J_ERROR
);
197 fprintf(ofp
, " LOG4J_WARN = %d\n", LTTNG_LOGLEVEL_LOG4J_WARN
);
198 fprintf(ofp
, " LOG4J_INFO = %d\n", LTTNG_LOGLEVEL_LOG4J_INFO
);
199 fprintf(ofp
, " LOG4J_DEBUG = %d\n", LTTNG_LOGLEVEL_LOG4J_DEBUG
);
200 fprintf(ofp
, " LOG4J_TRACE = %d\n", LTTNG_LOGLEVEL_LOG4J_TRACE
);
201 fprintf(ofp
, " LOG4J_ALL = INT32_MIN\n");
202 fprintf(ofp
, " (shortcuts such as \"severe\" are allowed)\n");
204 fprintf(ofp
, " Available Python domain loglevels:\n");
205 fprintf(ofp
, " PYTHON_CRITICAL = %d\n", LTTNG_LOGLEVEL_PYTHON_CRITICAL
);
206 fprintf(ofp
, " PYTHON_ERROR = %d\n", LTTNG_LOGLEVEL_PYTHON_ERROR
);
207 fprintf(ofp
, " PYTHON_WARNING = %d\n", LTTNG_LOGLEVEL_PYTHON_WARNING
);
208 fprintf(ofp
, " PYTHON_INFO = %d\n", LTTNG_LOGLEVEL_PYTHON_INFO
);
209 fprintf(ofp
, " PYTHON_DEBUG = %d\n", LTTNG_LOGLEVEL_PYTHON_DEBUG
);
210 fprintf(ofp
, " PYTHON_NOTSET = %d\n", LTTNG_LOGLEVEL_PYTHON_NOTSET
);
211 fprintf(ofp
, " (shortcuts such as \"critical\" are allowed)\n");
213 fprintf(ofp
, " -f, --filter \'expression\'\n");
214 fprintf(ofp
, " Filter expression on event fields and context.\n");
215 fprintf(ofp
, " Event recording depends on evaluation.\n");
216 fprintf(ofp
, " Only specify on first activation of\n");
217 fprintf(ofp
, " a given event within a session.\n");
218 fprintf(ofp
, " Filter only allowed when enabling\n");
219 fprintf(ofp
, " events within a session before tracing\n");
220 fprintf(ofp
, " is started. If the filter fails to link\n");
221 fprintf(ofp
, " with the event within the traced domain,\n");
222 fprintf(ofp
, " the event will be discarded. Currently,\n");
223 fprintf(ofp
, " filter is only implemented for the user-space\n");
224 fprintf(ofp
, " tracer.\n");
225 fprintf(ofp
, " Expression examples:.\n");
227 fprintf(ofp
, " 'intfield > 500 && intfield < 503'\n");
228 fprintf(ofp
, " '(strfield == \"test\" || intfield != 10) && intfield > 33'\n");
229 fprintf(ofp
, " 'doublefield > 1.1 && intfield < 5.3'\n");
231 fprintf(ofp
, " Wildcards are allowed at the end of strings:\n");
232 fprintf(ofp
, " 'seqfield1 == \"te*\"'\n");
233 fprintf(ofp
, " In string literals, the escape character is '\\'.\n");
234 fprintf(ofp
, " Use '\\*' for the '*' character, and '\\\\' for\n");
235 fprintf(ofp
, " the '\\' character. Wildcard match any sequence of,\n");
236 fprintf(ofp
, " characters including an empty sub-string (match 0 or\n");
237 fprintf(ofp
, " more characters).\n");
239 fprintf(ofp
, " Context information can be used for filtering. The\n");
240 fprintf(ofp
, " examples below show usage of context filtering on\n");
241 fprintf(ofp
, " process name (with a wildcard), process ID range, and\n");
242 fprintf(ofp
, " unique thread ID for filtering. The process and\n");
243 fprintf(ofp
, " thread ID of running applications can be found under\n");
244 fprintf(ofp
, " columns \"PID\" and \"LWP\" of the \"ps -eLf\" command.\n");
246 fprintf(ofp
, " '$ctx.procname == \"demo*\"'\n");
247 fprintf(ofp
, " '$ctx.vpid >= 4433 && $ctx.vpid < 4455'\n");
248 fprintf(ofp
, " '$ctx.vtid == 1234'\n");
249 fprintf(ofp
, " -x, --exclude LIST\n");
250 fprintf(ofp
, " Add exclusions to UST tracepoints:\n");
251 fprintf(ofp
, " Events that match any of the items\n");
252 fprintf(ofp
, " in the comma-separated LIST are not\n");
253 fprintf(ofp
, " enabled, even if they match a wildcard\n");
254 fprintf(ofp
, " definition of the event.\n");
259 * Parse probe options.
261 static int parse_probe_opts(struct lttng_event
*ev
, char *opt
)
263 int ret
= CMD_SUCCESS
;
266 #define S_HEX_LEN_SCANF_IS_A_BROKEN_API "18" /* 18 is (19 - 1) (\0 is extra) */
267 char name
[LTTNG_SYMBOL_NAME_LEN
];
274 /* Check for symbol+offset */
275 match
= sscanf(opt
, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
276 "[^'+']+%" S_HEX_LEN_SCANF_IS_A_BROKEN_API
"s", name
, s_hex
);
278 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
279 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
280 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
281 if (*s_hex
== '\0') {
282 ERR("Invalid probe offset %s", s_hex
);
286 ev
->attr
.probe
.offset
= strtoul(s_hex
, NULL
, 0);
287 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
288 ev
->attr
.probe
.addr
= 0;
292 /* Check for symbol */
293 if (isalpha(name
[0])) {
294 match
= sscanf(opt
, "%" LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API
"s",
297 strncpy(ev
->attr
.probe
.symbol_name
, name
, LTTNG_SYMBOL_NAME_LEN
);
298 ev
->attr
.probe
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
299 DBG("probe symbol %s", ev
->attr
.probe
.symbol_name
);
300 ev
->attr
.probe
.offset
= 0;
301 DBG("probe offset %" PRIu64
, ev
->attr
.probe
.offset
);
302 ev
->attr
.probe
.addr
= 0;
307 /* Check for address */
308 match
= sscanf(opt
, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API
"s", s_hex
);
310 if (*s_hex
== '\0') {
311 ERR("Invalid probe address %s", s_hex
);
315 ev
->attr
.probe
.addr
= strtoul(s_hex
, NULL
, 0);
316 DBG("probe addr %" PRIu64
, ev
->attr
.probe
.addr
);
317 ev
->attr
.probe
.offset
= 0;
318 memset(ev
->attr
.probe
.symbol_name
, 0, LTTNG_SYMBOL_NAME_LEN
);
330 * Maps LOG4j loglevel from string to value
332 static int loglevel_log4j_str_to_value(const char *inputstr
)
335 char str
[LTTNG_SYMBOL_NAME_LEN
];
338 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
339 * added at the end of the loop so a the upper bound we avoid the overflow.
341 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
342 str
[i
] = toupper(inputstr
[i
]);
347 if (!strcmp(str
, "LOG4J_OFF") || !strcmp(str
, "OFF")) {
348 return LTTNG_LOGLEVEL_LOG4J_OFF
;
349 } else if (!strcmp(str
, "LOG4J_FATAL") || !strcmp(str
, "FATAL")) {
350 return LTTNG_LOGLEVEL_LOG4J_FATAL
;
351 } else if (!strcmp(str
, "LOG4J_ERROR") || !strcmp(str
, "ERROR")) {
352 return LTTNG_LOGLEVEL_LOG4J_ERROR
;
353 } else if (!strcmp(str
, "LOG4J_WARN") || !strcmp(str
, "WARN")) {
354 return LTTNG_LOGLEVEL_LOG4J_WARN
;
355 } else if (!strcmp(str
, "LOG4J_INFO") || !strcmp(str
, "INFO")) {
356 return LTTNG_LOGLEVEL_LOG4J_INFO
;
357 } else if (!strcmp(str
, "LOG4J_DEBUG") || !strcmp(str
, "DEBUG")) {
358 return LTTNG_LOGLEVEL_LOG4J_DEBUG
;
359 } else if (!strcmp(str
, "LOG4J_TRACE") || !strcmp(str
, "TRACE")) {
360 return LTTNG_LOGLEVEL_LOG4J_TRACE
;
361 } else if (!strcmp(str
, "LOG4J_ALL") || !strcmp(str
, "ALL")) {
362 return LTTNG_LOGLEVEL_LOG4J_ALL
;
369 * Maps JUL loglevel from string to value
371 static int loglevel_jul_str_to_value(const char *inputstr
)
374 char str
[LTTNG_SYMBOL_NAME_LEN
];
377 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
378 * added at the end of the loop so a the upper bound we avoid the overflow.
380 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
381 str
[i
] = toupper(inputstr
[i
]);
386 if (!strcmp(str
, "JUL_OFF") || !strcmp(str
, "OFF")) {
387 return LTTNG_LOGLEVEL_JUL_OFF
;
388 } else if (!strcmp(str
, "JUL_SEVERE") || !strcmp(str
, "SEVERE")) {
389 return LTTNG_LOGLEVEL_JUL_SEVERE
;
390 } else if (!strcmp(str
, "JUL_WARNING") || !strcmp(str
, "WARNING")) {
391 return LTTNG_LOGLEVEL_JUL_WARNING
;
392 } else if (!strcmp(str
, "JUL_INFO") || !strcmp(str
, "INFO")) {
393 return LTTNG_LOGLEVEL_JUL_INFO
;
394 } else if (!strcmp(str
, "JUL_CONFIG") || !strcmp(str
, "CONFIG")) {
395 return LTTNG_LOGLEVEL_JUL_CONFIG
;
396 } else if (!strcmp(str
, "JUL_FINE") || !strcmp(str
, "FINE")) {
397 return LTTNG_LOGLEVEL_JUL_FINE
;
398 } else if (!strcmp(str
, "JUL_FINER") || !strcmp(str
, "FINER")) {
399 return LTTNG_LOGLEVEL_JUL_FINER
;
400 } else if (!strcmp(str
, "JUL_FINEST") || !strcmp(str
, "FINEST")) {
401 return LTTNG_LOGLEVEL_JUL_FINEST
;
402 } else if (!strcmp(str
, "JUL_ALL") || !strcmp(str
, "ALL")) {
403 return LTTNG_LOGLEVEL_JUL_ALL
;
410 * Maps Python loglevel from string to value
412 static int loglevel_python_str_to_value(const char *inputstr
)
415 char str
[LTTNG_SYMBOL_NAME_LEN
];
418 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
419 * added at the end of the loop so a the upper bound we avoid the overflow.
421 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
422 str
[i
] = toupper(inputstr
[i
]);
427 if (!strcmp(str
, "PYTHON_CRITICAL") || !strcmp(str
, "CRITICAL")) {
428 return LTTNG_LOGLEVEL_PYTHON_CRITICAL
;
429 } else if (!strcmp(str
, "PYTHON_ERROR") || !strcmp(str
, "ERROR")) {
430 return LTTNG_LOGLEVEL_PYTHON_ERROR
;
431 } else if (!strcmp(str
, "PYTHON_WARNING") || !strcmp(str
, "WARNING")) {
432 return LTTNG_LOGLEVEL_PYTHON_WARNING
;
433 } else if (!strcmp(str
, "PYTHON_INFO") || !strcmp(str
, "INFO")) {
434 return LTTNG_LOGLEVEL_PYTHON_INFO
;
435 } else if (!strcmp(str
, "PYTNON_DEBUG") || !strcmp(str
, "DEBUG")) {
436 return LTTNG_LOGLEVEL_PYTHON_DEBUG
;
437 } else if (!strcmp(str
, "PYTHON_NOTSET") || !strcmp(str
, "NOTSET")) {
438 return LTTNG_LOGLEVEL_PYTHON_NOTSET
;
445 * Maps loglevel from string to value
448 int loglevel_str_to_value(const char *inputstr
)
451 char str
[LTTNG_SYMBOL_NAME_LEN
];
454 * Loop up to LTTNG_SYMBOL_NAME_LEN minus one because the NULL bytes is
455 * added at the end of the loop so a the upper bound we avoid the overflow.
457 while (i
< (LTTNG_SYMBOL_NAME_LEN
- 1) && inputstr
[i
] != '\0') {
458 str
[i
] = toupper(inputstr
[i
]);
462 if (!strcmp(str
, "TRACE_EMERG") || !strcmp(str
, "EMERG")) {
463 return LTTNG_LOGLEVEL_EMERG
;
464 } else if (!strcmp(str
, "TRACE_ALERT") || !strcmp(str
, "ALERT")) {
465 return LTTNG_LOGLEVEL_ALERT
;
466 } else if (!strcmp(str
, "TRACE_CRIT") || !strcmp(str
, "CRIT")) {
467 return LTTNG_LOGLEVEL_CRIT
;
468 } else if (!strcmp(str
, "TRACE_ERR") || !strcmp(str
, "ERR")) {
469 return LTTNG_LOGLEVEL_ERR
;
470 } else if (!strcmp(str
, "TRACE_WARNING") || !strcmp(str
, "WARNING")) {
471 return LTTNG_LOGLEVEL_WARNING
;
472 } else if (!strcmp(str
, "TRACE_NOTICE") || !strcmp(str
, "NOTICE")) {
473 return LTTNG_LOGLEVEL_NOTICE
;
474 } else if (!strcmp(str
, "TRACE_INFO") || !strcmp(str
, "INFO")) {
475 return LTTNG_LOGLEVEL_INFO
;
476 } else if (!strcmp(str
, "TRACE_DEBUG_SYSTEM") || !strcmp(str
, "DEBUG_SYSTEM") || !strcmp(str
, "SYSTEM")) {
477 return LTTNG_LOGLEVEL_DEBUG_SYSTEM
;
478 } else if (!strcmp(str
, "TRACE_DEBUG_PROGRAM") || !strcmp(str
, "DEBUG_PROGRAM") || !strcmp(str
, "PROGRAM")) {
479 return LTTNG_LOGLEVEL_DEBUG_PROGRAM
;
480 } else if (!strcmp(str
, "TRACE_DEBUG_PROCESS") || !strcmp(str
, "DEBUG_PROCESS") || !strcmp(str
, "PROCESS")) {
481 return LTTNG_LOGLEVEL_DEBUG_PROCESS
;
482 } else if (!strcmp(str
, "TRACE_DEBUG_MODULE") || !strcmp(str
, "DEBUG_MODULE") || !strcmp(str
, "MODULE")) {
483 return LTTNG_LOGLEVEL_DEBUG_MODULE
;
484 } else if (!strcmp(str
, "TRACE_DEBUG_UNIT") || !strcmp(str
, "DEBUG_UNIT") || !strcmp(str
, "UNIT")) {
485 return LTTNG_LOGLEVEL_DEBUG_UNIT
;
486 } else if (!strcmp(str
, "TRACE_DEBUG_FUNCTION") || !strcmp(str
, "DEBUG_FUNCTION") || !strcmp(str
, "FUNCTION")) {
487 return LTTNG_LOGLEVEL_DEBUG_FUNCTION
;
488 } else if (!strcmp(str
, "TRACE_DEBUG_LINE") || !strcmp(str
, "DEBUG_LINE") || !strcmp(str
, "LINE")) {
489 return LTTNG_LOGLEVEL_DEBUG_LINE
;
490 } else if (!strcmp(str
, "TRACE_DEBUG") || !strcmp(str
, "DEBUG")) {
491 return LTTNG_LOGLEVEL_DEBUG
;
498 const char *print_channel_name(const char *name
)
500 return name
? : DEFAULT_CHANNEL_NAME
;
504 const char *print_raw_channel_name(const char *name
)
506 return name
? : "<default>";
510 * Mi print exlcusion list
513 int mi_print_exclusion(int count
, char **names
)
523 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
528 for (i
= 0; i
< count
; i
++) {
529 ret
= mi_lttng_writer_write_element_string(writer
,
530 config_element_exclusion
, names
[i
]);
536 /* Close exclusions element */
537 ret
= mi_lttng_writer_close_element(writer
);
544 * Return allocated string for pretty-printing exclusion names.
547 char *print_exclusions(int count
, char **names
)
551 const char *preamble
= " excluding ";
558 /* calculate total required length */
559 for (i
= 0; i
< count
; i
++) {
560 length
+= strlen(names
[i
]) + 1;
563 /* add length of preamble + one for NUL - one for last (missing) comma */
564 length
+= strlen(preamble
);
565 ret
= zmalloc(length
);
569 strncpy(ret
, preamble
, length
);
570 for (i
= 0; i
< count
; i
++) {
571 strcat(ret
, names
[i
]);
572 if (i
!= count
- 1) {
581 * Compare list of exclusions against an event name.
582 * Return a list of legal exclusion names.
583 * Produce an error or a warning about others (depending on the situation)
586 int check_exclusion_subsets(const char *event_name
,
587 const char *exclusions
,
588 int *exclusion_count_ptr
,
589 char ***exclusion_list_ptr
)
591 const char *excluder_ptr
;
592 const char *event_ptr
;
593 const char *next_excluder
;
595 int exclusion_count
= 0;
596 char **exclusion_list
= NULL
;
597 int ret
= CMD_SUCCESS
;
599 if (event_name
[strlen(event_name
) - 1] != '*') {
600 ERR("Event %s: Excluders can only be used with wildcarded events", event_name
);
604 next_excluder
= exclusions
;
605 while (*next_excluder
!= 0) {
606 event_ptr
= event_name
;
607 excluder_ptr
= next_excluder
;
608 excluder_length
= strcspn(next_excluder
, ",");
610 /* Scan both the excluder and the event letter by letter */
618 /* Event is a subset of the excluder */
619 ERR("Event %s: %.*s excludes all events from %s",
627 /* Excluder is a proper subset of event */
629 exclusion_list
= realloc(exclusion_list
, sizeof(char **) * exclusion_count
);
630 exclusion_list
[exclusion_count
- 1] = strndup(next_excluder
, excluder_length
);
635 /* Excluder and event sets have no common elements */
636 WARN("Event %s: %.*s does not exclude any events from %s",
647 next_excluder
+= excluder_length
;
648 if (*next_excluder
== ',') {
654 while (exclusion_count
--) {
655 free(exclusion_list
[exclusion_count
]);
657 if (exclusion_list
!= NULL
) {
658 free(exclusion_list
);
660 exclusion_list
= NULL
;
664 *exclusion_count_ptr
= exclusion_count
;
665 *exclusion_list_ptr
= exclusion_list
;
669 * Enabling event using the lttng API.
670 * Note: in case of error only the last error code will be return.
672 static int enable_events(char *session_name
)
674 int ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
;
675 int error_holder
= CMD_SUCCESS
, warn
= 0, error
= 0, success
= 1;
676 char *event_name
, *channel_name
= NULL
;
677 struct lttng_event ev
;
678 struct lttng_domain dom
;
679 int exclusion_count
= 0;
680 char **exclusion_list
= NULL
;
682 memset(&ev
, 0, sizeof(ev
));
683 memset(&dom
, 0, sizeof(dom
));
687 ERR("Filter not implement for kernel tracing yet");
692 WARN("Kernel loglevels are not supported.");
696 /* Create lttng domain */
698 dom
.type
= LTTNG_DOMAIN_KERNEL
;
699 dom
.buf_type
= LTTNG_BUFFER_GLOBAL
;
700 } else if (opt_userspace
) {
701 dom
.type
= LTTNG_DOMAIN_UST
;
703 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
704 } else if (opt_jul
) {
705 dom
.type
= LTTNG_DOMAIN_JUL
;
707 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
708 } else if (opt_log4j
) {
709 dom
.type
= LTTNG_DOMAIN_LOG4J
;
711 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
712 } else if (opt_python
) {
713 dom
.type
= LTTNG_DOMAIN_PYTHON
;
715 dom
.buf_type
= LTTNG_BUFFER_PER_UID
;
717 print_missing_domain();
722 if (opt_kernel
&& opt_exclude
) {
723 ERR("Event name exclusions are not yet implemented for kernel events");
728 channel_name
= opt_channel_name
;
730 handle
= lttng_create_handle(session_name
, &dom
);
731 if (handle
== NULL
) {
738 /* Open a events element */
739 ret
= mi_lttng_writer_open_element(writer
, config_element_events
);
746 if (opt_enable_all
) {
747 /* Default setup for enable all */
749 ev
.type
= opt_event_type
;
751 /* kernel loglevels not implemented */
752 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
754 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
755 strcpy(ev
.name
, "*");
756 ev
.loglevel_type
= opt_loglevel_type
;
758 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
760 ev
.loglevel
= loglevel_str_to_value(opt_loglevel
);
761 } else if (opt_jul
) {
762 ev
.loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
763 } else if (opt_log4j
) {
764 ev
.loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
765 } else if (opt_python
) {
766 ev
.loglevel
= loglevel_python_str_to_value(opt_loglevel
);
768 if (ev
.loglevel
== -1) {
769 ERR("Unknown loglevel %s", opt_loglevel
);
770 ret
= -LTTNG_ERR_INVALID
;
774 assert(opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
);
777 } else if (opt_jul
|| opt_log4j
) {
778 ev
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
779 } else if (opt_python
) {
780 ev
.loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
786 ret
= check_exclusion_subsets("*", opt_exclude
,
787 &exclusion_count
, &exclusion_list
);
788 if (ret
== CMD_ERROR
) {
794 ret
= lttng_enable_event_with_exclusions(handle
,
797 exclusion_count
, exclusion_list
);
800 case LTTNG_ERR_KERN_EVENT_EXIST
:
801 WARN("Kernel events already enabled (channel %s, session %s)",
802 print_channel_name(channel_name
), session_name
);
805 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
807 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
808 ERR("Events: %s (channel %s, session %s)",
810 print_channel_name(channel_name
),
816 ERR("Events: %s (channel %s, session %s)",
818 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
819 ? print_raw_channel_name(channel_name
)
820 : print_channel_name(channel_name
),
828 switch (opt_event_type
) {
829 case LTTNG_EVENT_TRACEPOINT
:
830 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
831 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
832 MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s",
833 get_domain_str(dom
.type
),
835 print_channel_name(channel_name
),
837 free(exclusion_string
);
839 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
840 MSG("All %s tracepoints%s are enabled in channel %s",
841 get_domain_str(dom
.type
),
843 print_channel_name(channel_name
));
844 free(exclusion_string
);
847 case LTTNG_EVENT_SYSCALL
:
849 MSG("All %s system calls are enabled in channel %s",
850 get_domain_str(dom
.type
),
851 print_channel_name(channel_name
));
854 case LTTNG_EVENT_ALL
:
855 if (opt_loglevel
&& dom
.type
!= LTTNG_DOMAIN_KERNEL
) {
856 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
857 MSG("All %s events%s are enabled in channel %s for loglevel %s",
858 get_domain_str(dom
.type
),
860 print_channel_name(channel_name
),
862 free(exclusion_string
);
864 char *exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
865 MSG("All %s events%s are enabled in channel %s",
866 get_domain_str(dom
.type
),
868 print_channel_name(channel_name
));
869 free(exclusion_string
);
874 * We should not be here since lttng_enable_event should have
875 * failed on the event type.
882 command_ret
= lttng_enable_event_with_exclusions(handle
, &ev
, channel_name
,
883 opt_filter
, exclusion_count
, exclusion_list
);
884 if (command_ret
< 0) {
885 switch (-command_ret
) {
886 case LTTNG_ERR_FILTER_EXIST
:
887 WARN("Filter on all events is already enabled"
888 " (channel %s, session %s)",
889 print_channel_name(channel_name
), session_name
);
892 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
894 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
895 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
897 print_channel_name(channel_name
),
898 session_name
, opt_filter
);
903 ERR("All events: %s (channel %s, session %s, filter \'%s\')",
904 lttng_strerror(command_ret
),
905 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
906 ? print_raw_channel_name(channel_name
)
907 : print_channel_name(channel_name
),
908 session_name
, opt_filter
);
912 error_holder
= command_ret
;
915 MSG("Filter '%s' successfully set", opt_filter
);
920 /* The wildcard * is used for kernel and ust domain to
921 * represent ALL. We copy * in event name to force the wildcard use
924 * Note: this is strictly for semantic and printing while in
925 * machine interface mode.
927 strcpy(ev
.name
, "*");
929 /* If we reach here the events are enabled */
930 if (!error
&& !warn
) {
936 ret
= mi_lttng_event(writer
, &ev
, 1, handle
->domain
.type
);
942 /* print exclusion */
943 ret
= mi_print_exclusion(exclusion_count
, exclusion_list
);
950 ret
= mi_lttng_writer_write_element_bool(writer
,
951 mi_lttng_element_command_success
, success
);
957 /* Close event element */
958 ret
= mi_lttng_writer_close_element(writer
);
968 /* Strip event list */
969 event_name
= strtok(opt_event_list
, ",");
970 while (event_name
!= NULL
) {
971 /* Copy name and type of the event */
972 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
973 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
974 ev
.type
= opt_event_type
;
976 /* Kernel tracer action */
978 DBG("Enabling kernel event %s for channel %s",
980 print_channel_name(channel_name
));
982 switch (opt_event_type
) {
983 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
984 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
986 case LTTNG_EVENT_TRACEPOINT
:
988 case LTTNG_EVENT_PROBE
:
989 ret
= parse_probe_opts(&ev
, opt_probe
);
991 ERR("Unable to parse probe options");
996 case LTTNG_EVENT_FUNCTION
:
997 ret
= parse_probe_opts(&ev
, opt_function
);
999 ERR("Unable to parse function probe options");
1004 case LTTNG_EVENT_FUNCTION_ENTRY
:
1005 strncpy(ev
.attr
.ftrace
.symbol_name
, opt_function_entry_symbol
,
1006 LTTNG_SYMBOL_NAME_LEN
);
1007 ev
.attr
.ftrace
.symbol_name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1009 case LTTNG_EVENT_SYSCALL
:
1010 ev
.type
= LTTNG_EVENT_SYSCALL
;
1013 ret
= CMD_UNDEFINED
;
1017 /* kernel loglevels not implemented */
1018 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
1019 } else if (opt_userspace
) { /* User-space tracer action */
1021 if (opt_cmd_name
!= NULL
|| opt_pid
) {
1022 MSG("Only supporting tracing all UST processes (-u) for now.");
1023 ret
= CMD_UNDEFINED
;
1028 DBG("Enabling UST event %s for channel %s, loglevel %s", event_name
,
1029 print_channel_name(channel_name
), opt_loglevel
? : "<all>");
1031 switch (opt_event_type
) {
1032 case LTTNG_EVENT_ALL
: /* Default behavior is tracepoint */
1034 case LTTNG_EVENT_TRACEPOINT
:
1035 /* Copy name and type of the event */
1036 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
1037 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1038 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1040 case LTTNG_EVENT_PROBE
:
1041 case LTTNG_EVENT_FUNCTION
:
1042 case LTTNG_EVENT_FUNCTION_ENTRY
:
1043 case LTTNG_EVENT_SYSCALL
:
1045 ERR("Event type not available for user-space tracing");
1046 ret
= CMD_UNSUPPORTED
;
1052 if (opt_event_type
!= LTTNG_EVENT_ALL
&& opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1053 ERR("Exclusion option can only be used with tracepoint events");
1057 /* Free previously allocated items */
1058 if (exclusion_list
!= NULL
) {
1059 while (exclusion_count
--) {
1060 free(exclusion_list
[exclusion_count
]);
1062 free(exclusion_list
);
1063 exclusion_list
= NULL
;
1065 /* Check for proper subsets */
1066 ret
= check_exclusion_subsets(event_name
, opt_exclude
,
1067 &exclusion_count
, &exclusion_list
);
1068 if (ret
== CMD_ERROR
) {
1073 ev
.loglevel_type
= opt_loglevel_type
;
1075 ev
.loglevel
= loglevel_str_to_value(opt_loglevel
);
1076 if (ev
.loglevel
== -1) {
1077 ERR("Unknown loglevel %s", opt_loglevel
);
1078 ret
= -LTTNG_ERR_INVALID
;
1084 } else if (opt_jul
|| opt_log4j
|| opt_python
) {
1085 if (opt_event_type
!= LTTNG_EVENT_ALL
&&
1086 opt_event_type
!= LTTNG_EVENT_TRACEPOINT
) {
1087 ERR("Event type not supported for domain.");
1088 ret
= CMD_UNSUPPORTED
;
1092 ev
.loglevel_type
= opt_loglevel_type
;
1095 ev
.loglevel
= loglevel_jul_str_to_value(opt_loglevel
);
1096 } else if (opt_log4j
) {
1097 ev
.loglevel
= loglevel_log4j_str_to_value(opt_loglevel
);
1098 } else if (opt_python
) {
1099 ev
.loglevel
= loglevel_python_str_to_value(opt_loglevel
);
1101 if (ev
.loglevel
== -1) {
1102 ERR("Unknown loglevel %s", opt_loglevel
);
1103 ret
= -LTTNG_ERR_INVALID
;
1108 ev
.loglevel
= LTTNG_LOGLEVEL_JUL_ALL
;
1109 } else if (opt_log4j
) {
1110 ev
.loglevel
= LTTNG_LOGLEVEL_LOG4J_ALL
;
1111 } else if (opt_python
) {
1112 ev
.loglevel
= LTTNG_LOGLEVEL_PYTHON_DEBUG
;
1115 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
1116 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
1117 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1119 print_missing_domain();
1125 char *exclusion_string
;
1127 command_ret
= lttng_enable_event_with_exclusions(handle
,
1129 NULL
, exclusion_count
, exclusion_list
);
1130 exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
1131 if (command_ret
< 0) {
1132 /* Turn ret to positive value to handle the positive error code */
1133 switch (-command_ret
) {
1134 case LTTNG_ERR_KERN_EVENT_EXIST
:
1135 WARN("Kernel event %s%s already enabled (channel %s, session %s)",
1138 print_channel_name(channel_name
), session_name
);
1141 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1143 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1144 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1147 print_channel_name(channel_name
),
1153 ERR("Event %s%s: %s (channel %s, session %s)", event_name
,
1155 lttng_strerror(command_ret
),
1156 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1157 ? print_raw_channel_name(channel_name
)
1158 : print_channel_name(channel_name
),
1163 error_holder
= command_ret
;
1165 /* So we don't print the default channel name for agent domain. */
1166 if (dom
.type
== LTTNG_DOMAIN_JUL
||
1167 dom
.type
== LTTNG_DOMAIN_LOG4J
) {
1168 MSG("%s event %s%s enabled.",
1169 get_domain_str(dom
.type
), event_name
,
1172 MSG("%s event %s%s created in channel %s",
1173 get_domain_str(dom
.type
), event_name
,
1175 print_channel_name(channel_name
));
1178 free(exclusion_string
);
1182 char *exclusion_string
;
1184 /* Filter present */
1187 command_ret
= lttng_enable_event_with_exclusions(handle
, &ev
, channel_name
,
1188 opt_filter
, exclusion_count
, exclusion_list
);
1189 exclusion_string
= print_exclusions(exclusion_count
, exclusion_list
);
1191 if (command_ret
< 0) {
1192 switch (-command_ret
) {
1193 case LTTNG_ERR_FILTER_EXIST
:
1194 WARN("Filter on event %s%s is already enabled"
1195 " (channel %s, session %s)",
1198 print_channel_name(channel_name
), session_name
);
1201 case LTTNG_ERR_TRACE_ALREADY_STARTED
:
1203 const char *msg
= "The command tried to enable an event in a new domain for a session that has already been started once.";
1204 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
.name
,
1207 print_channel_name(channel_name
),
1208 session_name
, opt_filter
);
1213 ERR("Event %s%s: %s (channel %s, session %s, filter \'%s\')", ev
.name
,
1215 lttng_strerror(command_ret
),
1216 command_ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
1217 ? print_raw_channel_name(channel_name
)
1218 : print_channel_name(channel_name
),
1219 session_name
, opt_filter
);
1223 error_holder
= command_ret
;
1226 MSG("Event %s%s: Filter '%s' successfully set",
1227 event_name
, exclusion_string
,
1230 free(exclusion_string
);
1241 ret
= mi_lttng_event(writer
, &ev
, 1, handle
->domain
.type
);
1247 /* print exclusion */
1248 ret
= mi_print_exclusion(exclusion_count
, exclusion_list
);
1255 ret
= mi_lttng_writer_write_element_bool(writer
,
1256 mi_lttng_element_command_success
, success
);
1262 /* Close event element */
1263 ret
= mi_lttng_writer_close_element(writer
);
1271 event_name
= strtok(NULL
, ",");
1272 /* Reset warn, error and success */
1279 /* Close events element */
1280 ret
= mi_lttng_writer_close_element(writer
);
1293 lttng_destroy_handle(handle
);
1295 if (exclusion_list
!= NULL
) {
1296 while (exclusion_count
--) {
1297 free(exclusion_list
[exclusion_count
]);
1299 free(exclusion_list
);
1302 /* Overwrite ret with error_holder if there was an actual error with
1303 * enabling an event.
1305 ret
= error_holder
? error_holder
: ret
;
1311 * Add event to trace session
1313 int cmd_enable_events(int argc
, const char **argv
)
1315 int opt
, ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
, success
= 1;
1316 static poptContext pc
;
1317 char *session_name
= NULL
;
1318 int event_type
= -1;
1320 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
1321 poptReadDefaultConfig(pc
, 0);
1323 /* Default event type */
1324 opt_event_type
= LTTNG_EVENT_ALL
;
1326 while ((opt
= poptGetNextOpt(pc
)) != -1) {
1331 case OPT_TRACEPOINT
:
1332 opt_event_type
= LTTNG_EVENT_TRACEPOINT
;
1335 opt_event_type
= LTTNG_EVENT_PROBE
;
1338 opt_event_type
= LTTNG_EVENT_FUNCTION
;
1340 case OPT_FUNCTION_ENTRY
:
1341 opt_event_type
= LTTNG_EVENT_FUNCTION_ENTRY
;
1344 opt_event_type
= LTTNG_EVENT_SYSCALL
;
1350 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_RANGE
;
1351 opt_loglevel
= poptGetOptArg(pc
);
1353 case OPT_LOGLEVEL_ONLY
:
1354 opt_loglevel_type
= LTTNG_EVENT_LOGLEVEL_SINGLE
;
1355 opt_loglevel
= poptGetOptArg(pc
);
1357 case OPT_LIST_OPTIONS
:
1358 list_cmd_options(stdout
, long_options
);
1366 ret
= CMD_UNDEFINED
;
1370 /* Validate event type. Multiple event type are not supported. */
1371 if (event_type
== -1) {
1372 event_type
= opt_event_type
;
1374 if (event_type
!= opt_event_type
) {
1375 ERR("Multiple event type not supported.");
1384 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
1386 ret
= -LTTNG_ERR_NOMEM
;
1390 /* Open command element */
1391 ret
= mi_lttng_writer_command_open(writer
,
1392 mi_lttng_element_command_enable_event
);
1398 /* Open output element */
1399 ret
= mi_lttng_writer_open_element(writer
,
1400 mi_lttng_element_command_output
);
1407 opt_event_list
= (char*) poptGetArg(pc
);
1408 if (opt_event_list
== NULL
&& opt_enable_all
== 0) {
1409 ERR("Missing event name(s).\n");
1415 if (!opt_session_name
) {
1416 session_name
= get_session_name();
1417 if (session_name
== NULL
) {
1418 command_ret
= CMD_ERROR
;
1423 session_name
= opt_session_name
;
1426 command_ret
= enable_events(session_name
);
1435 /* Close output element */
1436 ret
= mi_lttng_writer_close_element(writer
);
1442 ret
= mi_lttng_writer_write_element_bool(writer
,
1443 mi_lttng_element_command_success
, success
);
1449 /* Command element close */
1450 ret
= mi_lttng_writer_command_close(writer
);
1459 if (writer
&& mi_lttng_writer_destroy(writer
)) {
1460 /* Preserve original error code */
1461 ret
= ret
? ret
: LTTNG_ERR_MI_IO_FAIL
;
1464 if (opt_session_name
== NULL
) {
1468 /* Overwrite ret if an error occurred in enable_events */
1469 ret
= command_ret
? command_ret
: ret
;
1471 poptFreeContext(pc
);