Commit | Line | Data |
---|---|---|
f3ed775e DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
d14d33bf AM |
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. | |
f3ed775e DG |
7 | * |
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. | |
12 | * | |
d14d33bf AM |
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. | |
f3ed775e DG |
16 | */ |
17 | ||
6c1c0768 | 18 | #define _LGPL_SOURCE |
9f19cc17 | 19 | #include <inttypes.h> |
f3ed775e DG |
20 | #include <popt.h> |
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
23 | #include <string.h> | |
7a3d1328 | 24 | #include <assert.h> |
f3ed775e | 25 | |
fb14d0d8 | 26 | #include <common/mi-lttng.h> |
fae9a062 | 27 | #include <lttng/constant.h> |
fb14d0d8 | 28 | |
c399183f | 29 | #include "../command.h" |
f3ed775e | 30 | |
9f19cc17 DG |
31 | static int opt_userspace; |
32 | static int opt_kernel; | |
3c6a091f | 33 | static int opt_jul; |
5cdb6027 | 34 | static int opt_log4j; |
0e115563 | 35 | static int opt_python; |
9f19cc17 DG |
36 | static char *opt_channel; |
37 | static int opt_domain; | |
f37d259d | 38 | static int opt_fields; |
834978fd | 39 | static int opt_syscall; |
9f19cc17 DG |
40 | |
41 | const char *indent4 = " "; | |
42 | const char *indent6 = " "; | |
43 | const char *indent8 = " "; | |
f3ed775e | 44 | |
4fc83d94 PP |
45 | #ifdef LTTNG_EMBED_HELP |
46 | static const char help_msg[] = | |
47 | #include <lttng-list.1.h> | |
48 | ; | |
49 | #endif | |
50 | ||
f3ed775e DG |
51 | enum { |
52 | OPT_HELP = 1, | |
eeac7d46 | 53 | OPT_USERSPACE, |
679b4943 | 54 | OPT_LIST_OPTIONS, |
f3ed775e DG |
55 | }; |
56 | ||
cd80958d | 57 | static struct lttng_handle *handle; |
fb14d0d8 | 58 | static struct mi_writer *writer; |
cd80958d | 59 | |
e50e81d3 JG |
60 | /* Only set when listing a single session. */ |
61 | static struct lttng_session listed_session; | |
62 | ||
f3ed775e DG |
63 | static struct poptOption long_options[] = { |
64 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
2fa605f7 JG |
65 | {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, |
66 | {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, | |
67 | {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0}, | |
68 | {"log4j", 'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0}, | |
69 | {"python", 'p', POPT_ARG_VAL, &opt_python, 1, 0, 0}, | |
70 | {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, | |
71 | {"channel", 'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0}, | |
72 | {"domain", 'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0}, | |
73 | {"fields", 'f', POPT_ARG_VAL, &opt_fields, 1, 0, 0}, | |
74 | {"syscall", 'S', POPT_ARG_VAL, &opt_syscall, 1, 0, 0}, | |
679b4943 | 75 | {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, |
f3ed775e DG |
76 | {0, 0, 0, 0, 0, 0, 0} |
77 | }; | |
78 | ||
f3ed775e | 79 | /* |
9f19cc17 | 80 | * Get command line from /proc for a specific pid. |
f3ed775e | 81 | * |
9f19cc17 DG |
82 | * On success, return an allocated string pointer to the proc cmdline. |
83 | * On error, return NULL. | |
f3ed775e DG |
84 | */ |
85 | static char *get_cmdline_by_pid(pid_t pid) | |
86 | { | |
87 | int ret; | |
1ad31aec | 88 | FILE *fp = NULL; |
f3ed775e | 89 | char *cmdline = NULL; |
fae9a062 JG |
90 | /* Can't go bigger than /proc/LTTNG_MAX_PID/cmdline */ |
91 | char path[sizeof("/proc//cmdline") + sizeof(LTTNG_MAX_PID_STR) - 1]; | |
f3ed775e DG |
92 | |
93 | snprintf(path, sizeof(path), "/proc/%d/cmdline", pid); | |
94 | fp = fopen(path, "r"); | |
95 | if (fp == NULL) { | |
96 | goto end; | |
97 | } | |
98 | ||
99 | /* Caller must free() *cmdline */ | |
63a2c1bd | 100 | cmdline = zmalloc(PATH_MAX); |
f6962219 | 101 | if (!cmdline) { |
6f04ed72 | 102 | PERROR("malloc cmdline"); |
f6962219 JG |
103 | goto end; |
104 | } | |
f3ed775e | 105 | ret = fread(cmdline, 1, PATH_MAX, fp); |
f40799e8 | 106 | if (ret < 0) { |
6f04ed72 | 107 | PERROR("fread proc list"); |
f40799e8 | 108 | } |
f3ed775e DG |
109 | |
110 | end: | |
1ad31aec DG |
111 | if (fp) { |
112 | fclose(fp); | |
113 | } | |
f3ed775e DG |
114 | return cmdline; |
115 | } | |
b551a063 | 116 | |
464dd62d MD |
117 | static |
118 | const char *active_string(int value) | |
119 | { | |
120 | switch (value) { | |
2cbf8fed DG |
121 | case 0: return "inactive"; |
122 | case 1: return "active"; | |
464dd62d MD |
123 | case -1: return ""; |
124 | default: return NULL; | |
125 | } | |
126 | } | |
127 | ||
2cbf8fed DG |
128 | static const char *snapshot_string(int value) |
129 | { | |
130 | switch (value) { | |
131 | case 1: | |
132 | return " snapshot"; | |
133 | default: | |
134 | return ""; | |
135 | } | |
136 | } | |
137 | ||
464dd62d MD |
138 | static |
139 | const char *enabled_string(int value) | |
140 | { | |
141 | switch (value) { | |
b09f0429 MD |
142 | case 0: return " [disabled]"; |
143 | case 1: return " [enabled]"; | |
464dd62d MD |
144 | case -1: return ""; |
145 | default: return NULL; | |
146 | } | |
147 | } | |
148 | ||
fceb65df | 149 | static |
7b4a95b1 | 150 | const char *safe_string(const char *str) |
fceb65df | 151 | { |
7b4a95b1 | 152 | return str ? str : ""; |
4634f12e JI |
153 | } |
154 | ||
1f0e17de DG |
155 | static const char *logleveltype_string(enum lttng_loglevel_type value) |
156 | { | |
157 | switch (value) { | |
af6bce80 DG |
158 | case LTTNG_EVENT_LOGLEVEL_ALL: |
159 | return ":"; | |
1f0e17de | 160 | case LTTNG_EVENT_LOGLEVEL_RANGE: |
af6bce80 | 161 | return " <="; |
1f0e17de | 162 | case LTTNG_EVENT_LOGLEVEL_SINGLE: |
af6bce80 | 163 | return " =="; |
1f0e17de | 164 | default: |
af6bce80 | 165 | return " <<TYPE UNKN>>"; |
1f0e17de DG |
166 | } |
167 | } | |
168 | ||
834978fd DG |
169 | static const char *bitness_event(enum lttng_event_flag flags) |
170 | { | |
171 | if (flags & LTTNG_EVENT_FLAG_SYSCALL_32) { | |
172 | if (flags & LTTNG_EVENT_FLAG_SYSCALL_64) { | |
173 | return " [32/64-bit]"; | |
174 | } else { | |
175 | return " [32-bit]"; | |
176 | } | |
177 | } else if (flags & LTTNG_EVENT_FLAG_SYSCALL_64) { | |
178 | return " [64-bit]"; | |
179 | } else { | |
180 | return ""; | |
181 | } | |
182 | } | |
183 | ||
7b4a95b1 PP |
184 | /* |
185 | * Get exclusion names message for a single event. | |
186 | * | |
187 | * Returned pointer must be freed by caller. Returns NULL on error. | |
188 | */ | |
189 | static char *get_exclusion_names_msg(struct lttng_event *event) | |
190 | { | |
191 | int ret; | |
192 | int exclusion_count; | |
193 | char *exclusion_msg = NULL; | |
194 | char *at; | |
7b4a95b1 PP |
195 | size_t i; |
196 | const char * const exclusion_fmt = " [exclusions: "; | |
19ed7632 | 197 | const size_t exclusion_fmt_len = strlen(exclusion_fmt); |
7b4a95b1 PP |
198 | |
199 | exclusion_count = lttng_event_get_exclusion_name_count(event); | |
200 | if (exclusion_count < 0) { | |
201 | goto end; | |
202 | } else if (exclusion_count == 0) { | |
203 | /* | |
204 | * No exclusions: return copy of empty string so that | |
205 | * it can be freed by caller. | |
206 | */ | |
207 | exclusion_msg = strdup(""); | |
208 | goto end; | |
209 | } | |
210 | ||
211 | /* | |
212 | * exclusion_msg's size is bounded by the exclusion_fmt string, | |
213 | * a comma per entry, the entry count (fixed-size), a closing | |
214 | * bracket, and a trailing \0. | |
215 | */ | |
216 | exclusion_msg = malloc(exclusion_count + | |
217 | exclusion_count * LTTNG_SYMBOL_NAME_LEN + | |
19ed7632 | 218 | exclusion_fmt_len + 1); |
7b4a95b1 PP |
219 | if (!exclusion_msg) { |
220 | goto end; | |
221 | } | |
222 | ||
19ed7632 | 223 | at = strcpy(exclusion_msg, exclusion_fmt) + exclusion_fmt_len; |
7b4a95b1 PP |
224 | for (i = 0; i < exclusion_count; ++i) { |
225 | const char *name; | |
226 | ||
227 | /* Append comma between exclusion names */ | |
228 | if (i > 0) { | |
229 | *at = ','; | |
230 | at++; | |
231 | } | |
232 | ||
233 | ret = lttng_event_get_exclusion_name(event, i, &name); | |
234 | if (ret) { | |
235 | /* Prints '?' on local error; should never happen */ | |
236 | *at = '?'; | |
237 | at++; | |
238 | continue; | |
239 | } | |
240 | ||
241 | /* Append exclusion name */ | |
31e40170 | 242 | at += sprintf(at, "%s", name); |
7b4a95b1 PP |
243 | } |
244 | ||
245 | /* This also puts a final '\0' at the end of exclusion_msg */ | |
19ed7632 | 246 | strcpy(at, "]"); |
7b4a95b1 PP |
247 | |
248 | end: | |
249 | return exclusion_msg; | |
250 | } | |
251 | ||
b955b4d4 FD |
252 | static void print_userspace_probe_location(struct lttng_event *event) |
253 | { | |
254 | struct lttng_userspace_probe_location *location; | |
255 | struct lttng_userspace_probe_location_lookup_method *lookup_method; | |
256 | enum lttng_userspace_probe_location_lookup_method_type lookup_type; | |
257 | ||
258 | location = lttng_event_get_userspace_probe_location(event); | |
259 | if (!location) { | |
260 | MSG("Event has no userspace probe location"); | |
261 | return; | |
262 | } | |
263 | ||
264 | lookup_method = lttng_userspace_probe_location_get_lookup_method(location); | |
265 | if (!lookup_method) { | |
266 | MSG("Event has no userspace probe location lookup method"); | |
267 | return; | |
268 | } | |
269 | ||
270 | MSG("%s%s (type: userspace-probe)%s", indent6, event->name, enabled_string(event->enabled)); | |
271 | ||
272 | lookup_type = lttng_userspace_probe_location_lookup_method_get_type(lookup_method); | |
273 | ||
274 | switch (lttng_userspace_probe_location_get_type(location)) { | |
275 | case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN: | |
276 | MSG("%sType: Unknown", indent8); | |
277 | break; | |
278 | case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION: | |
279 | { | |
280 | const char *function_name; | |
281 | const char *binary_path; | |
282 | ||
283 | MSG("%sType: Function", indent8); | |
284 | function_name = lttng_userspace_probe_location_function_get_function_name(location); | |
285 | binary_path = realpath(lttng_userspace_probe_location_function_get_binary_path(location), NULL); | |
286 | ||
287 | MSG("%sBinary path: %s", indent8, binary_path ? binary_path : "NULL"); | |
288 | MSG("%sFunction: %s()", indent8, function_name ? function_name : "NULL"); | |
289 | switch (lookup_type) { | |
290 | case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF: | |
291 | MSG("%sLookup method: ELF", indent8); | |
292 | break; | |
293 | case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT: | |
294 | MSG("%sLookup method: default", indent8); | |
295 | break; | |
296 | default: | |
297 | MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8); | |
298 | break; | |
299 | } | |
300 | break; | |
301 | } | |
302 | case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT: | |
303 | { | |
304 | const char *probe_name, *provider_name; | |
305 | const char *binary_path; | |
306 | ||
307 | MSG("%sType: Tracepoint", indent8); | |
308 | probe_name = lttng_userspace_probe_location_tracepoint_get_probe_name(location); | |
309 | provider_name = lttng_userspace_probe_location_tracepoint_get_provider_name(location); | |
310 | binary_path = realpath(lttng_userspace_probe_location_tracepoint_get_binary_path(location), NULL); | |
311 | MSG("%sBinary path: %s", indent8, binary_path ? binary_path : "NULL"); | |
312 | MSG("%sTracepoint: %s:%s", indent8, provider_name ? provider_name : "NULL", probe_name ? probe_name : "NULL"); | |
313 | switch (lookup_type) { | |
314 | case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT: | |
315 | MSG("%sLookup method: SDT", indent8); | |
316 | break; | |
317 | default: | |
318 | MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8); | |
319 | break; | |
320 | } | |
321 | break; | |
322 | } | |
323 | default: | |
324 | ERR("Invalid probe type encountered"); | |
325 | } | |
326 | } | |
327 | ||
b551a063 DG |
328 | /* |
329 | * Pretty print single event. | |
330 | */ | |
331 | static void print_events(struct lttng_event *event) | |
332 | { | |
4adbcc72 PP |
333 | int ret; |
334 | const char *filter_str; | |
335 | char *filter_msg = NULL; | |
7b4a95b1 | 336 | char *exclusion_msg = NULL; |
4adbcc72 | 337 | |
134e72ed | 338 | ret = lttng_event_get_filter_expression(event, &filter_str); |
4adbcc72 PP |
339 | |
340 | if (ret) { | |
341 | filter_msg = strdup(" [failed to retrieve filter]"); | |
342 | } else if (filter_str) { | |
343 | const char * const filter_fmt = " [filter: '%s']"; | |
344 | ||
345 | filter_msg = malloc(strlen(filter_str) + | |
346 | strlen(filter_fmt) + 1); | |
347 | if (filter_msg) { | |
348 | sprintf(filter_msg, filter_fmt, | |
349 | filter_str); | |
350 | } | |
351 | } | |
352 | ||
7b4a95b1 PP |
353 | exclusion_msg = get_exclusion_names_msg(event); |
354 | if (!exclusion_msg) { | |
355 | exclusion_msg = strdup(" [failed to retrieve exclusions]"); | |
356 | } | |
357 | ||
b551a063 DG |
358 | switch (event->type) { |
359 | case LTTNG_EVENT_TRACEPOINT: | |
e4baff1e | 360 | { |
8b703175 | 361 | if (event->loglevel != -1) { |
af6bce80 | 362 | MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s", |
8b703175 | 363 | indent6, |
81afa345 | 364 | event->name, |
1f0e17de | 365 | logleveltype_string(event->loglevel_type), |
970d848b | 366 | mi_lttng_loglevel_string(event->loglevel, handle->domain.type), |
8b703175 | 367 | event->loglevel, |
fceb65df | 368 | enabled_string(event->enabled), |
7b4a95b1 PP |
369 | safe_string(exclusion_msg), |
370 | safe_string(filter_msg)); | |
8b703175 | 371 | } else { |
4634f12e | 372 | MSG("%s%s (type: tracepoint)%s%s%s", |
8b703175 MD |
373 | indent6, |
374 | event->name, | |
fceb65df | 375 | enabled_string(event->enabled), |
7b4a95b1 PP |
376 | safe_string(exclusion_msg), |
377 | safe_string(filter_msg)); | |
8b703175 | 378 | } |
b551a063 | 379 | break; |
e4baff1e | 380 | } |
1896972b DG |
381 | case LTTNG_EVENT_FUNCTION: |
382 | MSG("%s%s (type: function)%s%s", indent6, | |
383 | event->name, enabled_string(event->enabled), | |
7b4a95b1 | 384 | safe_string(filter_msg)); |
1896972b DG |
385 | if (event->attr.probe.addr != 0) { |
386 | MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr); | |
387 | } else { | |
388 | MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset); | |
389 | MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name); | |
390 | } | |
391 | break; | |
b551a063 | 392 | case LTTNG_EVENT_PROBE: |
fceb65df MD |
393 | MSG("%s%s (type: probe)%s%s", indent6, |
394 | event->name, enabled_string(event->enabled), | |
7b4a95b1 | 395 | safe_string(filter_msg)); |
b551a063 DG |
396 | if (event->attr.probe.addr != 0) { |
397 | MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr); | |
398 | } else { | |
399 | MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset); | |
400 | MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name); | |
401 | } | |
402 | break; | |
b955b4d4 FD |
403 | case LTTNG_EVENT_USERSPACE_PROBE: |
404 | print_userspace_probe_location(event); | |
405 | break; | |
b551a063 | 406 | case LTTNG_EVENT_FUNCTION_ENTRY: |
fceb65df MD |
407 | MSG("%s%s (type: function)%s%s", indent6, |
408 | event->name, enabled_string(event->enabled), | |
7b4a95b1 | 409 | safe_string(filter_msg)); |
b551a063 DG |
410 | MSG("%ssymbol: \"%s\"", indent8, event->attr.ftrace.symbol_name); |
411 | break; | |
412 | case LTTNG_EVENT_SYSCALL: | |
2199ad66 | 413 | MSG("%s%s%s%s%s%s", indent6, event->name, |
834978fd | 414 | (opt_syscall ? "" : " (type:syscall)"), |
fceb65df | 415 | enabled_string(event->enabled), |
2199ad66 JG |
416 | bitness_event(event->flags), |
417 | safe_string(filter_msg)); | |
b551a063 DG |
418 | break; |
419 | case LTTNG_EVENT_NOOP: | |
fceb65df MD |
420 | MSG("%s (type: noop)%s%s", indent6, |
421 | enabled_string(event->enabled), | |
7b4a95b1 | 422 | safe_string(filter_msg)); |
b551a063 DG |
423 | break; |
424 | case LTTNG_EVENT_ALL: | |
410b78a0 FD |
425 | /* Fall-through. */ |
426 | default: | |
b551a063 DG |
427 | /* We should never have "all" events in list. */ |
428 | assert(0); | |
429 | break; | |
430 | } | |
4adbcc72 PP |
431 | |
432 | free(filter_msg); | |
7b4a95b1 | 433 | free(exclusion_msg); |
b551a063 DG |
434 | } |
435 | ||
f37d259d MD |
436 | static const char *field_type(struct lttng_event_field *field) |
437 | { | |
438 | switch(field->type) { | |
439 | case LTTNG_EVENT_FIELD_INTEGER: | |
440 | return "integer"; | |
441 | case LTTNG_EVENT_FIELD_ENUM: | |
442 | return "enum"; | |
443 | case LTTNG_EVENT_FIELD_FLOAT: | |
444 | return "float"; | |
445 | case LTTNG_EVENT_FIELD_STRING: | |
446 | return "string"; | |
447 | case LTTNG_EVENT_FIELD_OTHER: | |
448 | default: /* fall-through */ | |
449 | return "unknown"; | |
450 | } | |
451 | } | |
452 | ||
453 | /* | |
454 | * Pretty print single event fields. | |
455 | */ | |
456 | static void print_event_field(struct lttng_event_field *field) | |
457 | { | |
458 | if (!field->field_name[0]) { | |
459 | return; | |
460 | } | |
d8fbe2a9 | 461 | MSG("%sfield: %s (%s)%s", indent8, field->field_name, |
45a32634 | 462 | field_type(field), field->nowrite ? " [no write]" : ""); |
f37d259d MD |
463 | } |
464 | ||
fb14d0d8 JR |
465 | /* |
466 | * Machine interface | |
467 | * Jul and ust event listing | |
468 | */ | |
5cdb6027 | 469 | static int mi_list_agent_ust_events(struct lttng_event *events, int count, |
fb14d0d8 JR |
470 | struct lttng_domain *domain) |
471 | { | |
472 | int ret, i; | |
473 | pid_t cur_pid = 0; | |
474 | char *cmdline = NULL; | |
475 | int pid_element_open = 0; | |
476 | ||
477 | /* Open domains element */ | |
478 | ret = mi_lttng_domains_open(writer); | |
479 | if (ret) { | |
480 | goto end; | |
481 | } | |
482 | ||
483 | /* Write domain */ | |
484 | ret = mi_lttng_domain(writer, domain, 1); | |
485 | if (ret) { | |
486 | goto end; | |
487 | } | |
488 | ||
bf239d4c JR |
489 | /* Open pids element element */ |
490 | ret = mi_lttng_pids_open(writer); | |
fb14d0d8 JR |
491 | if (ret) { |
492 | goto end; | |
493 | } | |
494 | ||
495 | for (i = 0; i < count; i++) { | |
496 | if (cur_pid != events[i].pid) { | |
497 | if (pid_element_open) { | |
2e9aecb9 | 498 | /* Close the previous events and pid element */ |
fb14d0d8 JR |
499 | ret = mi_lttng_close_multi_element(writer, 2); |
500 | if (ret) { | |
501 | goto end; | |
502 | } | |
503 | pid_element_open = 0; | |
504 | } | |
505 | ||
506 | cur_pid = events[i].pid; | |
507 | cmdline = get_cmdline_by_pid(cur_pid); | |
508 | if (!cmdline) { | |
509 | ret = CMD_ERROR; | |
510 | goto end; | |
511 | } | |
512 | ||
513 | if (!pid_element_open) { | |
514 | /* Open and write a pid element */ | |
bf239d4c | 515 | ret = mi_lttng_pid(writer, cur_pid, cmdline, 1); |
fb14d0d8 JR |
516 | if (ret) { |
517 | goto error; | |
518 | } | |
519 | ||
520 | /* Open events element */ | |
521 | ret = mi_lttng_events_open(writer); | |
522 | if (ret) { | |
523 | goto error; | |
524 | } | |
525 | ||
526 | pid_element_open = 1; | |
527 | } | |
528 | free(cmdline); | |
529 | } | |
530 | ||
531 | /* Write an event */ | |
970d848b | 532 | ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type); |
fb14d0d8 JR |
533 | if (ret) { |
534 | goto end; | |
535 | } | |
536 | } | |
537 | ||
bf239d4c | 538 | /* Close pids */ |
fb14d0d8 JR |
539 | ret = mi_lttng_writer_close_element(writer); |
540 | if (ret) { | |
541 | goto end; | |
542 | } | |
543 | ||
544 | /* Close domain, domains */ | |
545 | ret = mi_lttng_close_multi_element(writer, 2); | |
546 | end: | |
547 | return ret; | |
548 | error: | |
549 | free(cmdline); | |
550 | return ret; | |
551 | } | |
552 | ||
5cdb6027 | 553 | static int list_agent_events(void) |
3c6a091f | 554 | { |
fb14d0d8 | 555 | int i, size, ret = CMD_SUCCESS; |
3c6a091f | 556 | struct lttng_domain domain; |
26c610c9 | 557 | struct lttng_handle *handle = NULL; |
469b972b | 558 | struct lttng_event *event_list = NULL; |
3c6a091f DG |
559 | pid_t cur_pid = 0; |
560 | char *cmdline = NULL; | |
5cdb6027 | 561 | const char *agent_domain_str; |
3c6a091f DG |
562 | |
563 | memset(&domain, 0, sizeof(domain)); | |
5cdb6027 DG |
564 | if (opt_jul) { |
565 | domain.type = LTTNG_DOMAIN_JUL; | |
566 | } else if (opt_log4j) { | |
567 | domain.type = LTTNG_DOMAIN_LOG4J; | |
0e115563 DG |
568 | } else if (opt_python) { |
569 | domain.type = LTTNG_DOMAIN_PYTHON; | |
26c610c9 JG |
570 | } else { |
571 | ERR("Invalid agent domain selected."); | |
572 | ret = CMD_ERROR; | |
573 | goto error; | |
5cdb6027 DG |
574 | } |
575 | ||
576 | agent_domain_str = get_domain_str(domain.type); | |
577 | ||
578 | DBG("Getting %s tracing events", agent_domain_str); | |
3c6a091f DG |
579 | |
580 | handle = lttng_create_handle(NULL, &domain); | |
581 | if (handle == NULL) { | |
fb14d0d8 JR |
582 | ret = CMD_ERROR; |
583 | goto end; | |
3c6a091f DG |
584 | } |
585 | ||
586 | size = lttng_list_tracepoints(handle, &event_list); | |
587 | if (size < 0) { | |
5cdb6027 DG |
588 | ERR("Unable to list %s events: %s", agent_domain_str, |
589 | lttng_strerror(size)); | |
fb14d0d8 JR |
590 | ret = CMD_ERROR; |
591 | goto end; | |
3c6a091f DG |
592 | } |
593 | ||
fb14d0d8 JR |
594 | if (lttng_opt_mi) { |
595 | /* Mi print */ | |
5cdb6027 | 596 | ret = mi_list_agent_ust_events(event_list, size, &domain); |
fb14d0d8 JR |
597 | if (ret) { |
598 | ret = CMD_ERROR; | |
599 | goto error; | |
3c6a091f | 600 | } |
fb14d0d8 JR |
601 | } else { |
602 | /* Pretty print */ | |
5cdb6027 DG |
603 | MSG("%s events (Logger name):\n-------------------------", |
604 | agent_domain_str); | |
3c6a091f | 605 | |
fb14d0d8 JR |
606 | if (size == 0) { |
607 | MSG("None"); | |
608 | } | |
3c6a091f | 609 | |
fb14d0d8 JR |
610 | for (i = 0; i < size; i++) { |
611 | if (cur_pid != event_list[i].pid) { | |
612 | cur_pid = event_list[i].pid; | |
613 | cmdline = get_cmdline_by_pid(cur_pid); | |
614 | if (cmdline == NULL) { | |
615 | ret = CMD_ERROR; | |
616 | goto error; | |
617 | } | |
618 | MSG("\nPID: %d - Name: %s", cur_pid, cmdline); | |
619 | free(cmdline); | |
620 | } | |
621 | MSG("%s- %s", indent6, event_list[i].name); | |
622 | } | |
3c6a091f | 623 | |
fb14d0d8 JR |
624 | MSG(""); |
625 | } | |
3c6a091f DG |
626 | |
627 | error: | |
fb14d0d8 JR |
628 | free(event_list); |
629 | end: | |
3c6a091f | 630 | lttng_destroy_handle(handle); |
fb14d0d8 | 631 | return ret; |
3c6a091f DG |
632 | } |
633 | ||
b551a063 DG |
634 | /* |
635 | * Ask session daemon for all user space tracepoints available. | |
636 | */ | |
637 | static int list_ust_events(void) | |
638 | { | |
fb14d0d8 | 639 | int i, size, ret = CMD_SUCCESS; |
b551a063 DG |
640 | struct lttng_domain domain; |
641 | struct lttng_handle *handle; | |
bec97646 | 642 | struct lttng_event *event_list = NULL; |
b551a063 | 643 | pid_t cur_pid = 0; |
ea5cbc00 | 644 | char *cmdline = NULL; |
b551a063 | 645 | |
441c16a7 MD |
646 | memset(&domain, 0, sizeof(domain)); |
647 | ||
b551a063 DG |
648 | DBG("Getting UST tracing events"); |
649 | ||
650 | domain.type = LTTNG_DOMAIN_UST; | |
651 | ||
652 | handle = lttng_create_handle(NULL, &domain); | |
653 | if (handle == NULL) { | |
fb14d0d8 JR |
654 | ret = CMD_ERROR; |
655 | goto end; | |
b551a063 DG |
656 | } |
657 | ||
658 | size = lttng_list_tracepoints(handle, &event_list); | |
659 | if (size < 0) { | |
60e835ca | 660 | ERR("Unable to list UST events: %s", lttng_strerror(size)); |
fb14d0d8 JR |
661 | ret = CMD_ERROR; |
662 | goto error; | |
b551a063 DG |
663 | } |
664 | ||
fb14d0d8 JR |
665 | if (lttng_opt_mi) { |
666 | /* Mi print */ | |
5cdb6027 | 667 | ret = mi_list_agent_ust_events(event_list, size, &domain); |
fb14d0d8 JR |
668 | } else { |
669 | /* Pretty print */ | |
670 | MSG("UST events:\n-------------"); | |
671 | ||
672 | if (size == 0) { | |
673 | MSG("None"); | |
674 | } | |
675 | ||
676 | for (i = 0; i < size; i++) { | |
677 | if (cur_pid != event_list[i].pid) { | |
678 | cur_pid = event_list[i].pid; | |
679 | cmdline = get_cmdline_by_pid(cur_pid); | |
680 | if (cmdline == NULL) { | |
681 | ret = CMD_ERROR; | |
682 | goto error; | |
683 | } | |
684 | MSG("\nPID: %d - Name: %s", cur_pid, cmdline); | |
685 | free(cmdline); | |
686 | } | |
687 | print_events(&event_list[i]); | |
688 | } | |
b551a063 | 689 | |
fb14d0d8 | 690 | MSG(""); |
b551a063 DG |
691 | } |
692 | ||
fb14d0d8 JR |
693 | error: |
694 | free(event_list); | |
695 | end: | |
696 | lttng_destroy_handle(handle); | |
697 | return ret; | |
698 | } | |
699 | ||
700 | /* | |
701 | * Machine interface | |
702 | * List all ust event with their fields | |
703 | */ | |
704 | static int mi_list_ust_event_fields(struct lttng_event_field *fields, int count, | |
705 | struct lttng_domain *domain) | |
706 | { | |
707 | int ret, i; | |
708 | pid_t cur_pid = 0; | |
709 | char *cmdline = NULL; | |
710 | int pid_element_open = 0; | |
711 | int event_element_open = 0; | |
712 | struct lttng_event cur_event; | |
713 | ||
d113fbc8 JR |
714 | memset(&cur_event, 0, sizeof(cur_event)); |
715 | ||
fb14d0d8 JR |
716 | /* Open domains element */ |
717 | ret = mi_lttng_domains_open(writer); | |
718 | if (ret) { | |
719 | goto end; | |
720 | } | |
721 | ||
722 | /* Write domain */ | |
723 | ret = mi_lttng_domain(writer, domain, 1); | |
724 | if (ret) { | |
725 | goto end; | |
726 | } | |
727 | ||
bf239d4c JR |
728 | /* Open pids element */ |
729 | ret = mi_lttng_pids_open(writer); | |
fb14d0d8 JR |
730 | if (ret) { |
731 | goto end; | |
732 | } | |
733 | ||
734 | for (i = 0; i < count; i++) { | |
735 | if (cur_pid != fields[i].event.pid) { | |
736 | if (pid_element_open) { | |
737 | if (event_element_open) { | |
485ca16f | 738 | /* Close the previous field element and event. */ |
fb14d0d8 JR |
739 | ret = mi_lttng_close_multi_element(writer, 2); |
740 | if (ret) { | |
741 | goto end; | |
742 | } | |
743 | event_element_open = 0; | |
744 | } | |
745 | /* Close the previous events, pid element */ | |
746 | ret = mi_lttng_close_multi_element(writer, 2); | |
747 | if (ret) { | |
748 | goto end; | |
749 | } | |
750 | pid_element_open = 0; | |
751 | } | |
752 | ||
753 | cur_pid = fields[i].event.pid; | |
ea5cbc00 | 754 | cmdline = get_cmdline_by_pid(cur_pid); |
fb14d0d8 | 755 | if (!pid_element_open) { |
bf239d4c JR |
756 | /* Open and write a pid element */ |
757 | ret = mi_lttng_pid(writer, cur_pid, cmdline, 1); | |
fb14d0d8 JR |
758 | if (ret) { |
759 | goto error; | |
760 | } | |
761 | ||
762 | /* Open events element */ | |
763 | ret = mi_lttng_events_open(writer); | |
764 | if (ret) { | |
765 | goto error; | |
766 | } | |
767 | pid_element_open = 1; | |
768 | } | |
ea5cbc00 | 769 | free(cmdline); |
fb14d0d8 JR |
770 | /* Wipe current event since we are about to print a new PID. */ |
771 | memset(&cur_event, 0, sizeof(cur_event)); | |
b551a063 | 772 | } |
b551a063 | 773 | |
fb14d0d8 JR |
774 | if (strcmp(cur_event.name, fields[i].event.name) != 0) { |
775 | if (event_element_open) { | |
776 | /* Close the previous fields element and the previous event */ | |
777 | ret = mi_lttng_close_multi_element(writer, 2); | |
778 | if (ret) { | |
779 | goto end; | |
780 | } | |
781 | event_element_open = 0; | |
782 | } | |
783 | ||
784 | memcpy(&cur_event, &fields[i].event, | |
785 | sizeof(cur_event)); | |
b551a063 | 786 | |
fb14d0d8 JR |
787 | if (!event_element_open) { |
788 | /* Open and write the event */ | |
970d848b DG |
789 | ret = mi_lttng_event(writer, &cur_event, 1, |
790 | handle->domain.type); | |
fb14d0d8 JR |
791 | if (ret) { |
792 | goto end; | |
793 | } | |
794 | ||
795 | /* Open a fields element */ | |
796 | ret = mi_lttng_event_fields_open(writer); | |
797 | if (ret) { | |
798 | goto end; | |
799 | } | |
800 | event_element_open = 1; | |
801 | } | |
802 | } | |
b551a063 | 803 | |
fb14d0d8 JR |
804 | /* Print the event_field */ |
805 | ret = mi_lttng_event_field(writer, &fields[i]); | |
806 | if (ret) { | |
807 | goto end; | |
808 | } | |
809 | } | |
b551a063 | 810 | |
bf239d4c | 811 | /* Close pid, domain, domains */ |
fb14d0d8 JR |
812 | ret = mi_lttng_close_multi_element(writer, 3); |
813 | end: | |
814 | return ret; | |
b551a063 | 815 | error: |
fb14d0d8 JR |
816 | free(cmdline); |
817 | return ret; | |
b551a063 | 818 | } |
f3ed775e | 819 | |
f37d259d MD |
820 | /* |
821 | * Ask session daemon for all user space tracepoint fields available. | |
822 | */ | |
823 | static int list_ust_event_fields(void) | |
824 | { | |
fb14d0d8 | 825 | int i, size, ret = CMD_SUCCESS; |
f37d259d MD |
826 | struct lttng_domain domain; |
827 | struct lttng_handle *handle; | |
828 | struct lttng_event_field *event_field_list; | |
829 | pid_t cur_pid = 0; | |
ea5cbc00 CB |
830 | char *cmdline = NULL; |
831 | ||
f37d259d MD |
832 | struct lttng_event cur_event; |
833 | ||
834 | memset(&domain, 0, sizeof(domain)); | |
835 | memset(&cur_event, 0, sizeof(cur_event)); | |
836 | ||
837 | DBG("Getting UST tracing event fields"); | |
838 | ||
839 | domain.type = LTTNG_DOMAIN_UST; | |
840 | ||
841 | handle = lttng_create_handle(NULL, &domain); | |
842 | if (handle == NULL) { | |
fb14d0d8 JR |
843 | ret = CMD_ERROR; |
844 | goto end; | |
f37d259d MD |
845 | } |
846 | ||
847 | size = lttng_list_tracepoint_fields(handle, &event_field_list); | |
848 | if (size < 0) { | |
60e835ca | 849 | ERR("Unable to list UST event fields: %s", lttng_strerror(size)); |
fb14d0d8 JR |
850 | ret = CMD_ERROR; |
851 | goto end; | |
f37d259d MD |
852 | } |
853 | ||
fb14d0d8 JR |
854 | if (lttng_opt_mi) { |
855 | /* Mi print */ | |
856 | ret = mi_list_ust_event_fields(event_field_list, size, &domain); | |
857 | if (ret) { | |
858 | ret = CMD_ERROR; | |
859 | goto error; | |
860 | } | |
861 | } else { | |
862 | /* Pretty print */ | |
863 | MSG("UST events:\n-------------"); | |
f37d259d | 864 | |
fb14d0d8 JR |
865 | if (size == 0) { |
866 | MSG("None"); | |
f37d259d | 867 | } |
fb14d0d8 JR |
868 | |
869 | for (i = 0; i < size; i++) { | |
870 | if (cur_pid != event_field_list[i].event.pid) { | |
871 | cur_pid = event_field_list[i].event.pid; | |
872 | cmdline = get_cmdline_by_pid(cur_pid); | |
873 | if (cmdline == NULL) { | |
874 | ret = CMD_ERROR; | |
875 | goto error; | |
876 | } | |
877 | MSG("\nPID: %d - Name: %s", cur_pid, cmdline); | |
878 | free(cmdline); | |
879 | /* Wipe current event since we are about to print a new PID. */ | |
880 | memset(&cur_event, 0, sizeof(cur_event)); | |
881 | } | |
882 | if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) { | |
883 | print_events(&event_field_list[i].event); | |
884 | memcpy(&cur_event, &event_field_list[i].event, | |
885 | sizeof(cur_event)); | |
886 | } | |
887 | print_event_field(&event_field_list[i]); | |
f37d259d | 888 | } |
f37d259d | 889 | |
fb14d0d8 JR |
890 | MSG(""); |
891 | } | |
f37d259d | 892 | |
fb14d0d8 | 893 | error: |
f37d259d | 894 | free(event_field_list); |
fb14d0d8 | 895 | end: |
f37d259d | 896 | lttng_destroy_handle(handle); |
fb14d0d8 JR |
897 | return ret; |
898 | } | |
f37d259d | 899 | |
fb14d0d8 JR |
900 | /* |
901 | * Machine interface | |
902 | * Print a list of kernel events | |
903 | */ | |
904 | static int mi_list_kernel_events(struct lttng_event *events, int count, | |
905 | struct lttng_domain *domain) | |
906 | { | |
907 | int ret, i; | |
f37d259d | 908 | |
fb14d0d8 JR |
909 | /* Open domains element */ |
910 | ret = mi_lttng_domains_open(writer); | |
911 | if (ret) { | |
912 | goto end; | |
913 | } | |
914 | ||
915 | /* Write domain */ | |
916 | ret = mi_lttng_domain(writer, domain, 1); | |
917 | if (ret) { | |
918 | goto end; | |
919 | } | |
920 | ||
921 | /* Open events */ | |
922 | ret = mi_lttng_events_open(writer); | |
923 | if (ret) { | |
924 | goto end; | |
925 | } | |
926 | ||
927 | for (i = 0; i < count; i++) { | |
970d848b | 928 | ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type); |
fb14d0d8 JR |
929 | if (ret) { |
930 | goto end; | |
931 | } | |
932 | } | |
933 | ||
934 | /* close events, domain and domains */ | |
935 | ret = mi_lttng_close_multi_element(writer, 3); | |
936 | if (ret) { | |
937 | goto end; | |
938 | } | |
939 | ||
940 | end: | |
941 | return ret; | |
f37d259d MD |
942 | } |
943 | ||
f3ed775e | 944 | /* |
fb14d0d8 | 945 | * Ask for all trace events in the kernel |
f3ed775e | 946 | */ |
9f19cc17 | 947 | static int list_kernel_events(void) |
f3ed775e | 948 | { |
fb14d0d8 | 949 | int i, size, ret = CMD_SUCCESS; |
b551a063 DG |
950 | struct lttng_domain domain; |
951 | struct lttng_handle *handle; | |
9f19cc17 | 952 | struct lttng_event *event_list; |
f3ed775e | 953 | |
441c16a7 MD |
954 | memset(&domain, 0, sizeof(domain)); |
955 | ||
b551a063 DG |
956 | DBG("Getting kernel tracing events"); |
957 | ||
958 | domain.type = LTTNG_DOMAIN_KERNEL; | |
959 | ||
960 | handle = lttng_create_handle(NULL, &domain); | |
961 | if (handle == NULL) { | |
fb14d0d8 | 962 | ret = CMD_ERROR; |
b551a063 DG |
963 | goto error; |
964 | } | |
f3ed775e | 965 | |
cd80958d | 966 | size = lttng_list_tracepoints(handle, &event_list); |
9f19cc17 | 967 | if (size < 0) { |
60e835ca | 968 | ERR("Unable to list kernel events: %s", lttng_strerror(size)); |
ef021732 | 969 | lttng_destroy_handle(handle); |
fb14d0d8 | 970 | return CMD_ERROR; |
f3ed775e DG |
971 | } |
972 | ||
fb14d0d8 JR |
973 | if (lttng_opt_mi) { |
974 | /* Mi print */ | |
975 | ret = mi_list_kernel_events(event_list, size, &domain); | |
976 | if (ret) { | |
977 | ret = CMD_ERROR; | |
978 | goto end; | |
979 | } | |
980 | } else { | |
981 | MSG("Kernel events:\n-------------"); | |
f3ed775e | 982 | |
fb14d0d8 JR |
983 | for (i = 0; i < size; i++) { |
984 | print_events(&event_list[i]); | |
985 | } | |
f3ed775e | 986 | |
fb14d0d8 JR |
987 | MSG(""); |
988 | } | |
b551a063 | 989 | |
fb14d0d8 | 990 | end: |
f3ed775e DG |
991 | free(event_list); |
992 | ||
ef021732 | 993 | lttng_destroy_handle(handle); |
fb14d0d8 | 994 | return ret; |
b551a063 DG |
995 | |
996 | error: | |
ef021732 | 997 | lttng_destroy_handle(handle); |
fb14d0d8 JR |
998 | return ret; |
999 | } | |
1000 | ||
834978fd DG |
1001 | /* |
1002 | * Machine interface | |
1003 | * Print a list of system calls. | |
1004 | */ | |
1005 | static int mi_list_syscalls(struct lttng_event *events, int count) | |
1006 | { | |
1007 | int ret, i; | |
1008 | ||
1009 | /* Open events */ | |
1010 | ret = mi_lttng_events_open(writer); | |
1011 | if (ret) { | |
1012 | goto end; | |
1013 | } | |
1014 | ||
1015 | for (i = 0; i < count; i++) { | |
970d848b | 1016 | ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type); |
834978fd DG |
1017 | if (ret) { |
1018 | goto end; | |
1019 | } | |
1020 | } | |
1021 | ||
1022 | /* Close events. */ | |
1023 | ret = mi_lttng_writer_close_element(writer); | |
1024 | if (ret) { | |
1025 | goto end; | |
1026 | } | |
1027 | ||
1028 | end: | |
1029 | return ret; | |
1030 | } | |
1031 | ||
1032 | /* | |
1033 | * Ask for kernel system calls. | |
1034 | */ | |
1035 | static int list_syscalls(void) | |
1036 | { | |
1037 | int i, size, ret = CMD_SUCCESS; | |
1038 | struct lttng_event *event_list; | |
1039 | ||
1040 | DBG("Getting kernel system call events"); | |
1041 | ||
1042 | size = lttng_list_syscalls(&event_list); | |
1043 | if (size < 0) { | |
1044 | ERR("Unable to list system calls: %s", lttng_strerror(size)); | |
1045 | ret = CMD_ERROR; | |
1046 | goto error; | |
1047 | } | |
1048 | ||
1049 | if (lttng_opt_mi) { | |
1050 | /* Mi print */ | |
1051 | ret = mi_list_syscalls(event_list, size); | |
1052 | if (ret) { | |
1053 | ret = CMD_ERROR; | |
1054 | goto end; | |
1055 | } | |
1056 | } else { | |
1057 | MSG("System calls:\n-------------"); | |
1058 | ||
1059 | for (i = 0; i < size; i++) { | |
1060 | print_events(&event_list[i]); | |
1061 | } | |
1062 | ||
1063 | MSG(""); | |
1064 | } | |
1065 | ||
1066 | end: | |
1067 | free(event_list); | |
1068 | return ret; | |
1069 | ||
1070 | error: | |
1071 | return ret; | |
1072 | } | |
1073 | ||
fb14d0d8 JR |
1074 | /* |
1075 | * Machine Interface | |
5cdb6027 | 1076 | * Print a list of agent events |
fb14d0d8 | 1077 | */ |
5cdb6027 | 1078 | static int mi_list_session_agent_events(struct lttng_event *events, int count) |
fb14d0d8 JR |
1079 | { |
1080 | int ret, i; | |
1081 | ||
1082 | /* Open events element */ | |
1083 | ret = mi_lttng_events_open(writer); | |
1084 | if (ret) { | |
1085 | goto end; | |
1086 | } | |
1087 | ||
1088 | for (i = 0; i < count; i++) { | |
970d848b | 1089 | ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type); |
fb14d0d8 JR |
1090 | if (ret) { |
1091 | goto end; | |
1092 | } | |
1093 | } | |
1094 | ||
1095 | /* Close events element */ | |
1096 | ret = mi_lttng_writer_close_element(writer); | |
1097 | ||
1098 | end: | |
1099 | return ret; | |
f3ed775e DG |
1100 | } |
1101 | ||
3c6a091f | 1102 | /* |
5cdb6027 | 1103 | * List agent events for a specific session using the handle. |
3c6a091f DG |
1104 | * |
1105 | * Return CMD_SUCCESS on success else a negative value. | |
1106 | */ | |
5cdb6027 | 1107 | static int list_session_agent_events(void) |
3c6a091f | 1108 | { |
fb14d0d8 | 1109 | int ret = CMD_SUCCESS, count, i; |
3c6a091f DG |
1110 | struct lttng_event *events = NULL; |
1111 | ||
1112 | count = lttng_list_events(handle, "", &events); | |
1113 | if (count < 0) { | |
fb14d0d8 JR |
1114 | ret = CMD_ERROR; |
1115 | ERR("%s", lttng_strerror(count)); | |
3c6a091f DG |
1116 | goto error; |
1117 | } | |
1118 | ||
fb14d0d8 JR |
1119 | if (lttng_opt_mi) { |
1120 | /* Mi print */ | |
5cdb6027 | 1121 | ret = mi_list_session_agent_events(events, count); |
fb14d0d8 JR |
1122 | if (ret) { |
1123 | ret = CMD_ERROR; | |
1124 | goto end; | |
1125 | } | |
1126 | } else { | |
1127 | /* Pretty print */ | |
1128 | MSG("Events (Logger name):\n---------------------"); | |
1129 | if (count == 0) { | |
1130 | MSG("%sNone\n", indent6); | |
1131 | goto end; | |
1132 | } | |
1133 | ||
1134 | for (i = 0; i < count; i++) { | |
9a890ce8 JG |
1135 | const char *filter_str; |
1136 | char *filter_msg = NULL; | |
1137 | struct lttng_event *event = &events[i]; | |
1138 | ||
134e72ed JG |
1139 | ret = lttng_event_get_filter_expression(event, |
1140 | &filter_str); | |
9a890ce8 JG |
1141 | if (ret) { |
1142 | filter_msg = strdup(" [failed to retrieve filter]"); | |
1143 | } else if (filter_str) { | |
1144 | const char * const filter_fmt = | |
1145 | " [filter: '%s']"; | |
1146 | ||
1147 | filter_msg = malloc(strlen(filter_str) + | |
1148 | strlen(filter_fmt) + 1); | |
1149 | if (filter_msg) { | |
00505bae JG |
1150 | sprintf(filter_msg, filter_fmt, |
1151 | filter_str); | |
9a890ce8 JG |
1152 | } |
1153 | } | |
1154 | ||
1155 | if (event->loglevel_type != | |
755066c2 | 1156 | LTTNG_EVENT_LOGLEVEL_ALL) { |
9a890ce8 JG |
1157 | MSG("%s- %s%s (loglevel%s %s)%s", indent4, |
1158 | event->name, | |
1159 | enabled_string(event->enabled), | |
755066c2 | 1160 | logleveltype_string( |
9a890ce8 | 1161 | event->loglevel_type), |
755066c2 | 1162 | mi_lttng_loglevel_string( |
9a890ce8 JG |
1163 | event->loglevel, |
1164 | handle->domain.type), | |
7b4a95b1 | 1165 | safe_string(filter_msg)); |
755066c2 | 1166 | } else { |
9a890ce8 JG |
1167 | MSG("%s- %s%s%s", indent4, event->name, |
1168 | enabled_string(event->enabled), | |
7b4a95b1 | 1169 | safe_string(filter_msg)); |
755066c2 | 1170 | } |
9a890ce8 | 1171 | free(filter_msg); |
fb14d0d8 JR |
1172 | } |
1173 | ||
1174 | MSG(""); | |
1175 | } | |
1176 | ||
1177 | end: | |
1178 | free(events); | |
1179 | error: | |
1180 | return ret; | |
1181 | } | |
1182 | ||
1183 | /* | |
1184 | * Machine interface | |
1185 | * print a list of event | |
1186 | */ | |
1187 | static int mi_list_events(struct lttng_event *events, int count) | |
1188 | { | |
1189 | int ret, i; | |
1190 | ||
1191 | /* Open events element */ | |
1192 | ret = mi_lttng_events_open(writer); | |
1193 | if (ret) { | |
3c6a091f DG |
1194 | goto end; |
1195 | } | |
1196 | ||
1197 | for (i = 0; i < count; i++) { | |
970d848b | 1198 | ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type); |
fb14d0d8 JR |
1199 | if (ret) { |
1200 | goto end; | |
1201 | } | |
3c6a091f DG |
1202 | } |
1203 | ||
fb14d0d8 JR |
1204 | /* Close events element */ |
1205 | ret = mi_lttng_writer_close_element(writer); | |
3c6a091f DG |
1206 | |
1207 | end: | |
3c6a091f DG |
1208 | return ret; |
1209 | } | |
1210 | ||
f3ed775e | 1211 | /* |
9f19cc17 | 1212 | * List events of channel of session and domain. |
f3ed775e | 1213 | */ |
cd80958d | 1214 | static int list_events(const char *channel_name) |
f3ed775e | 1215 | { |
fb14d0d8 | 1216 | int ret = CMD_SUCCESS, count, i; |
9f19cc17 | 1217 | struct lttng_event *events = NULL; |
f3ed775e | 1218 | |
cd80958d | 1219 | count = lttng_list_events(handle, channel_name, &events); |
f3ed775e | 1220 | if (count < 0) { |
fb14d0d8 JR |
1221 | ret = CMD_ERROR; |
1222 | ERR("%s", lttng_strerror(count)); | |
f3ed775e DG |
1223 | goto error; |
1224 | } | |
1225 | ||
fb14d0d8 JR |
1226 | if (lttng_opt_mi) { |
1227 | /* Mi print */ | |
1228 | ret = mi_list_events(events, count); | |
1229 | if (ret) { | |
1230 | ret = CMD_ERROR; | |
1231 | goto end; | |
1232 | } | |
1233 | } else { | |
1234 | /* Pretty print */ | |
f3b3a67b | 1235 | MSG("\n%sEvent rules:", indent4); |
fb14d0d8 JR |
1236 | if (count == 0) { |
1237 | MSG("%sNone\n", indent6); | |
1238 | goto end; | |
1239 | } | |
f3ed775e | 1240 | |
fb14d0d8 JR |
1241 | for (i = 0; i < count; i++) { |
1242 | print_events(&events[i]); | |
1243 | } | |
f3ed775e | 1244 | |
fb14d0d8 JR |
1245 | MSG(""); |
1246 | } | |
9f19cc17 | 1247 | end: |
0e428499 | 1248 | free(events); |
f3ed775e DG |
1249 | error: |
1250 | return ret; | |
1251 | } | |
1252 | ||
f3b3a67b JG |
1253 | static |
1254 | void print_timer(const char *timer_name, uint32_t space_count, int64_t value) | |
1255 | { | |
1256 | uint32_t i; | |
1257 | ||
1258 | _MSG("%s%s:", indent6, timer_name); | |
1259 | for (i = 0; i < space_count; i++) { | |
1260 | _MSG(" "); | |
1261 | } | |
1262 | ||
1263 | if (value) { | |
1264 | MSG("%" PRId64 " µs", value); | |
1265 | } else { | |
1266 | MSG("inactive"); | |
1267 | } | |
1268 | } | |
1269 | ||
f3ed775e | 1270 | /* |
9f19cc17 DG |
1271 | * Pretty print channel |
1272 | */ | |
1273 | static void print_channel(struct lttng_channel *channel) | |
1274 | { | |
fb83fe64 | 1275 | int ret; |
cf0bcb51 | 1276 | uint64_t discarded_events, lost_packets, monitor_timer_interval; |
491d1539 | 1277 | int64_t blocking_timeout; |
fb83fe64 JD |
1278 | |
1279 | ret = lttng_channel_get_discarded_event_count(channel, | |
1280 | &discarded_events); | |
1281 | if (ret) { | |
1282 | ERR("Failed to retrieve discarded event count of channel"); | |
1283 | return; | |
1284 | } | |
1285 | ||
1286 | ret = lttng_channel_get_lost_packet_count(channel, | |
1287 | &lost_packets); | |
1288 | if (ret) { | |
1289 | ERR("Failed to retrieve lost packet count of channel"); | |
1290 | return; | |
1291 | } | |
1292 | ||
cf0bcb51 JG |
1293 | ret = lttng_channel_get_monitor_timer_interval(channel, |
1294 | &monitor_timer_interval); | |
1295 | if (ret) { | |
1296 | ERR("Failed to retrieve monitor interval of channel"); | |
1297 | return; | |
1298 | } | |
1299 | ||
491d1539 MD |
1300 | ret = lttng_channel_get_blocking_timeout(channel, |
1301 | &blocking_timeout); | |
1302 | if (ret) { | |
1303 | ERR("Failed to retrieve blocking timeout of channel"); | |
1304 | return; | |
1305 | } | |
1306 | ||
464dd62d | 1307 | MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled)); |
9f19cc17 | 1308 | MSG("%sAttributes:", indent4); |
f3b3a67b JG |
1309 | MSG("%sEvent-loss mode: %s", indent6, channel->attr.overwrite ? "overwrite" : "discard"); |
1310 | MSG("%sSub-buffer size: %" PRIu64 " bytes", indent6, channel->attr.subbuf_size); | |
1311 | MSG("%sSub-buffer count: %" PRIu64, indent6, channel->attr.num_subbuf); | |
1312 | ||
1313 | print_timer("Switch timer", 5, channel->attr.switch_timer_interval); | |
1314 | print_timer("Read timer", 7, channel->attr.read_timer_interval); | |
1315 | print_timer("Monitor timer", 4, monitor_timer_interval); | |
1316 | ||
1317 | if (!channel->attr.overwrite) { | |
1318 | if (blocking_timeout == -1) { | |
1319 | MSG("%sBlocking timeout: infinite", indent6); | |
1320 | } else { | |
1321 | MSG("%sBlocking timeout: %" PRId64 " µs", indent6, blocking_timeout); | |
1322 | } | |
1323 | } | |
1324 | ||
1325 | MSG("%sTrace file count: %" PRIu64 " per stream", indent6, | |
1326 | channel->attr.tracefile_count == 0 ? | |
1327 | 1 : channel->attr.tracefile_count); | |
1328 | if (channel->attr.tracefile_size != 0 ) { | |
1329 | MSG("%sTrace file size: %" PRIu64 " bytes", indent6, | |
1330 | channel->attr.tracefile_size); | |
1331 | } else { | |
1332 | MSG("%sTrace file size: %s", indent6, "unlimited"); | |
1333 | } | |
9f19cc17 DG |
1334 | switch (channel->attr.output) { |
1335 | case LTTNG_EVENT_SPLICE: | |
f3b3a67b | 1336 | MSG("%sOutput mode: splice", indent6); |
9f19cc17 DG |
1337 | break; |
1338 | case LTTNG_EVENT_MMAP: | |
f3b3a67b | 1339 | MSG("%sOutput mode: mmap", indent6); |
9f19cc17 DG |
1340 | break; |
1341 | } | |
e50e81d3 | 1342 | |
f3b3a67b JG |
1343 | MSG("\n%sStatistics:", indent4); |
1344 | if (listed_session.snapshot_mode) { | |
e50e81d3 JG |
1345 | /* |
1346 | * The lost packet count is omitted for sessions in snapshot | |
1347 | * mode as it is misleading: it would indicate the number of | |
1348 | * packets that the consumer could not extract during the | |
1349 | * course of recording the snapshot. It does not have the | |
1350 | * same meaning as the "regular" lost packet count that | |
1351 | * would result from the consumer not keeping up with | |
1352 | * event production in an overwrite-mode channel. | |
1353 | * | |
1354 | * A more interesting statistic would be the number of | |
1355 | * packets lost between the first and last extracted | |
1356 | * packets of a given snapshot (which prevents most analyses). | |
1357 | */ | |
f3b3a67b | 1358 | MSG("%sNone", indent6); |
e50e81d3 JG |
1359 | goto skip_stats_printing; |
1360 | } | |
1361 | ||
1362 | if (!channel->attr.overwrite) { | |
f3b3a67b | 1363 | MSG("%sDiscarded events: %" PRIu64, indent6, discarded_events); |
e50e81d3 | 1364 | } else { |
f3b3a67b | 1365 | MSG("%sLost packets: %" PRIu64, indent6, lost_packets); |
e50e81d3 JG |
1366 | } |
1367 | skip_stats_printing: | |
1368 | return; | |
9f19cc17 DG |
1369 | } |
1370 | ||
fb14d0d8 JR |
1371 | /* |
1372 | * Machine interface | |
1373 | * Print a list of channel | |
1374 | * | |
1375 | */ | |
1376 | static int mi_list_channels(struct lttng_channel *channels, int count, | |
1377 | const char *channel_name) | |
1378 | { | |
1379 | int i, ret; | |
1380 | unsigned int chan_found = 0; | |
1381 | ||
1382 | /* Open channels element */ | |
1383 | ret = mi_lttng_channels_open(writer); | |
1384 | if (ret) { | |
1385 | goto error; | |
1386 | } | |
1387 | ||
1388 | for (i = 0; i < count; i++) { | |
1389 | if (channel_name != NULL) { | |
1390 | if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) { | |
1391 | chan_found = 1; | |
1392 | } else { | |
1393 | continue; | |
1394 | } | |
1395 | } | |
1396 | ||
1397 | /* Write channel element and leave it open */ | |
1398 | ret = mi_lttng_channel(writer, &channels[i], 1); | |
1399 | if (ret) { | |
1400 | goto error; | |
1401 | } | |
1402 | ||
1403 | /* Listing events per channel */ | |
1404 | ret = list_events(channels[i].name); | |
1405 | if (ret) { | |
1406 | goto error; | |
1407 | } | |
1408 | ||
1409 | /* Closing the channel element we opened earlier */ | |
1410 | ret = mi_lttng_writer_close_element(writer); | |
1411 | if (ret) { | |
1412 | goto error; | |
1413 | } | |
1414 | ||
1415 | if (chan_found) { | |
1416 | break; | |
1417 | } | |
1418 | } | |
1419 | ||
1420 | /* Close channels element */ | |
1421 | ret = mi_lttng_writer_close_element(writer); | |
1422 | if (ret) { | |
1423 | goto error; | |
1424 | } | |
1425 | ||
1426 | error: | |
1427 | return ret; | |
1428 | } | |
1429 | ||
9f19cc17 DG |
1430 | /* |
1431 | * List channel(s) of session and domain. | |
f3ed775e | 1432 | * |
9f19cc17 | 1433 | * If channel_name is NULL, all channels are listed. |
f3ed775e | 1434 | */ |
cd80958d | 1435 | static int list_channels(const char *channel_name) |
f3ed775e | 1436 | { |
9f19cc17 DG |
1437 | int count, i, ret = CMD_SUCCESS; |
1438 | unsigned int chan_found = 0; | |
1439 | struct lttng_channel *channels = NULL; | |
f3ed775e | 1440 | |
3e25cb20 | 1441 | DBG("Listing channel(s) (%s)", channel_name ? : "<all>"); |
9f19cc17 | 1442 | |
cd80958d | 1443 | count = lttng_list_channels(handle, &channels); |
f3ed775e | 1444 | if (count < 0) { |
c7d620a2 DG |
1445 | switch (-count) { |
1446 | case LTTNG_ERR_KERN_CHAN_NOT_FOUND: | |
fb14d0d8 JR |
1447 | if (lttng_opt_mi) { |
1448 | /* When printing mi this is not an error | |
1449 | * but an empty channels element */ | |
1450 | count = 0; | |
1451 | } else { | |
1452 | ret = CMD_SUCCESS; | |
1453 | WARN("No kernel channel"); | |
1454 | goto error_channels; | |
1455 | } | |
c7d620a2 DG |
1456 | break; |
1457 | default: | |
1458 | /* We had a real error */ | |
fb14d0d8 JR |
1459 | ret = CMD_ERROR; |
1460 | ERR("%s", lttng_strerror(count)); | |
1461 | goto error_channels; | |
60e835ca | 1462 | break; |
c7d620a2 | 1463 | } |
f3ed775e DG |
1464 | } |
1465 | ||
fb14d0d8 JR |
1466 | if (lttng_opt_mi) { |
1467 | /* Mi print */ | |
1468 | ret = mi_list_channels(channels, count, channel_name); | |
1469 | if (ret) { | |
1470 | ret = CMD_ERROR; | |
1471 | goto error; | |
1472 | } | |
1473 | } else { | |
1474 | /* Pretty print */ | |
ade7ce52 | 1475 | if (count) { |
fb14d0d8 JR |
1476 | MSG("Channels:\n-------------"); |
1477 | } | |
9f19cc17 | 1478 | |
fb14d0d8 JR |
1479 | for (i = 0; i < count; i++) { |
1480 | if (channel_name != NULL) { | |
1481 | if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) { | |
1482 | chan_found = 1; | |
1483 | } else { | |
1484 | continue; | |
1485 | } | |
1486 | } | |
1487 | print_channel(&channels[i]); | |
1488 | ||
1489 | /* Listing events per channel */ | |
1490 | ret = list_events(channels[i].name); | |
1491 | if (ret) { | |
1492 | goto error; | |
1493 | } | |
1494 | ||
1495 | if (chan_found) { | |
1496 | break; | |
9f19cc17 DG |
1497 | } |
1498 | } | |
9f19cc17 | 1499 | |
fb14d0d8 JR |
1500 | if (!chan_found && channel_name != NULL) { |
1501 | ret = CMD_ERROR; | |
1502 | ERR("Channel %s not found", channel_name); | |
1503 | goto error; | |
9f19cc17 | 1504 | } |
fb14d0d8 JR |
1505 | } |
1506 | error: | |
1507 | free(channels); | |
9f19cc17 | 1508 | |
fb14d0d8 JR |
1509 | error_channels: |
1510 | return ret; | |
1511 | } | |
1512 | ||
a5dfbb9d MD |
1513 | /* |
1514 | * List tracker PID(s) of session and domain. | |
1515 | */ | |
1516 | static int list_tracker_pids(void) | |
1517 | { | |
ebbf5ab7 JR |
1518 | int ret = 0; |
1519 | int enabled; | |
a5dfbb9d | 1520 | int *pids = NULL; |
6223570f | 1521 | size_t nr_pids; |
a5dfbb9d MD |
1522 | |
1523 | ret = lttng_list_tracker_pids(handle, | |
1524 | &enabled, &pids, &nr_pids); | |
1525 | if (ret) { | |
1526 | return ret; | |
1527 | } | |
a5dfbb9d | 1528 | if (enabled) { |
6223570f JG |
1529 | int i; |
1530 | _MSG("PID tracker: ["); | |
a5dfbb9d | 1531 | |
ebbf5ab7 JR |
1532 | /* Mi tracker_pid element*/ |
1533 | if (writer) { | |
1534 | /* Open tracker_pid and targets elements */ | |
1535 | ret = mi_lttng_pid_tracker_open(writer); | |
1536 | if (ret) { | |
1537 | goto end; | |
1538 | } | |
1539 | } | |
1540 | ||
a5dfbb9d MD |
1541 | for (i = 0; i < nr_pids; i++) { |
1542 | if (i) { | |
1543 | _MSG(","); | |
1544 | } | |
1545 | _MSG(" %d", pids[i]); | |
ebbf5ab7 JR |
1546 | |
1547 | /* Mi */ | |
1548 | if (writer) { | |
1549 | ret = mi_lttng_pid_target(writer, pids[i], 0); | |
1550 | if (ret) { | |
1551 | goto end; | |
1552 | } | |
1553 | } | |
a5dfbb9d | 1554 | } |
6223570f | 1555 | _MSG(" ]\n\n"); |
ebbf5ab7 JR |
1556 | |
1557 | /* Mi close tracker_pid and targets */ | |
1558 | if (writer) { | |
1559 | ret = mi_lttng_close_multi_element(writer,2); | |
1560 | if (ret) { | |
1561 | goto end; | |
1562 | } | |
1563 | } | |
a5dfbb9d | 1564 | } |
ebbf5ab7 | 1565 | end: |
a5dfbb9d | 1566 | free(pids); |
ebbf5ab7 JR |
1567 | return ret; |
1568 | ||
1569 | } | |
1570 | ||
1571 | /* | |
1572 | * List all tracker of a domain | |
1573 | */ | |
1574 | static int list_trackers(void) | |
1575 | { | |
1576 | int ret; | |
1577 | ||
1578 | /* Trackers listing */ | |
1579 | if (lttng_opt_mi) { | |
1580 | ret = mi_lttng_trackers_open(writer); | |
1581 | if (ret) { | |
1582 | goto end; | |
1583 | } | |
1584 | } | |
1585 | ||
1586 | /* pid tracker */ | |
1587 | ret = list_tracker_pids(); | |
1588 | if (ret) { | |
1589 | goto end; | |
1590 | } | |
1591 | ||
1592 | if (lttng_opt_mi) { | |
1593 | /* Close trackers element */ | |
1594 | ret = mi_lttng_writer_close_element(writer); | |
1595 | if (ret) { | |
1596 | goto end; | |
1597 | } | |
1598 | } | |
1599 | ||
1600 | end: | |
1601 | return ret; | |
a5dfbb9d MD |
1602 | } |
1603 | ||
66ea93b1 JG |
1604 | static enum cmd_error_code print_periodic_rotation_schedule( |
1605 | const struct lttng_rotation_schedule *schedule) | |
1606 | { | |
1607 | enum cmd_error_code ret; | |
1608 | enum lttng_rotation_status status; | |
1609 | uint64_t value; | |
1610 | ||
1611 | status = lttng_rotation_schedule_periodic_get_period(schedule, | |
1612 | &value); | |
1613 | if (status != LTTNG_ROTATION_STATUS_OK) { | |
1614 | ERR("Failed to retrieve period parameter from periodic rotation schedule."); | |
1615 | ret = CMD_ERROR; | |
1616 | goto end; | |
1617 | } | |
1618 | ||
1619 | MSG(" timer period: %" PRIu64" µs", value); | |
66ea93b1 JG |
1620 | ret = CMD_SUCCESS; |
1621 | end: | |
1622 | return ret; | |
1623 | } | |
1624 | ||
1625 | static enum cmd_error_code print_size_threshold_rotation_schedule( | |
1626 | const struct lttng_rotation_schedule *schedule) | |
1627 | { | |
1628 | enum cmd_error_code ret; | |
1629 | enum lttng_rotation_status status; | |
1630 | uint64_t value; | |
1631 | ||
1632 | status = lttng_rotation_schedule_size_threshold_get_threshold(schedule, | |
1633 | &value); | |
1634 | if (status != LTTNG_ROTATION_STATUS_OK) { | |
1635 | ERR("Failed to retrieve size parameter from size-based rotation schedule."); | |
1636 | ret = CMD_ERROR; | |
1637 | goto end; | |
1638 | } | |
1639 | ||
1640 | MSG(" size threshold: %" PRIu64" bytes", value); | |
66ea93b1 JG |
1641 | ret = CMD_SUCCESS; |
1642 | end: | |
1643 | return ret; | |
1644 | } | |
1645 | ||
1646 | static enum cmd_error_code print_rotation_schedule( | |
1647 | const struct lttng_rotation_schedule *schedule) | |
1648 | { | |
1649 | enum cmd_error_code ret; | |
1650 | ||
1651 | switch (lttng_rotation_schedule_get_type(schedule)) { | |
1652 | case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD: | |
1653 | ret = print_size_threshold_rotation_schedule(schedule); | |
1654 | break; | |
1655 | case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC: | |
1656 | ret = print_periodic_rotation_schedule(schedule); | |
1657 | break; | |
1658 | default: | |
1659 | ret = CMD_ERROR; | |
1660 | } | |
1661 | return ret; | |
1662 | } | |
1663 | ||
329f3443 | 1664 | /* |
66ea93b1 | 1665 | * List the automatic rotation settings. |
329f3443 | 1666 | */ |
66ea93b1 | 1667 | static enum cmd_error_code list_rotate_settings(const char *session_name) |
329f3443 JD |
1668 | { |
1669 | int ret; | |
66ea93b1 JG |
1670 | enum cmd_error_code cmd_ret = CMD_SUCCESS; |
1671 | unsigned int count, i; | |
1672 | struct lttng_rotation_schedules *schedules = NULL; | |
1673 | enum lttng_rotation_status status; | |
1674 | ||
1675 | ret = lttng_session_list_rotation_schedules(session_name, &schedules); | |
1676 | if (ret != LTTNG_OK) { | |
1677 | ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret)); | |
1678 | cmd_ret = CMD_ERROR; | |
329f3443 JD |
1679 | goto end; |
1680 | } | |
1681 | ||
66ea93b1 JG |
1682 | status = lttng_rotation_schedules_get_count(schedules, &count); |
1683 | if (status != LTTNG_ROTATION_STATUS_OK) { | |
1684 | ERR("Failed to retrieve the number of session rotation schedules."); | |
1685 | cmd_ret = CMD_ERROR; | |
329f3443 JD |
1686 | goto end; |
1687 | } | |
1688 | ||
66ea93b1 JG |
1689 | if (count == 0) { |
1690 | cmd_ret = CMD_SUCCESS; | |
329f3443 JD |
1691 | goto end; |
1692 | } | |
1693 | ||
66ea93b1 JG |
1694 | MSG("Automatic rotation schedules:"); |
1695 | if (lttng_opt_mi) { | |
1696 | ret = mi_lttng_writer_open_element(writer, | |
1697 | mi_lttng_element_rotation_schedules); | |
1698 | if (ret) { | |
1699 | cmd_ret = CMD_ERROR; | |
1700 | goto end; | |
329f3443 JD |
1701 | } |
1702 | } | |
66ea93b1 JG |
1703 | |
1704 | for (i = 0; i < count; i++) { | |
1705 | enum cmd_error_code tmp_ret = CMD_SUCCESS; | |
1706 | const struct lttng_rotation_schedule *schedule; | |
1707 | ||
1708 | schedule = lttng_rotation_schedules_get_at_index(schedules, i); | |
1709 | if (!schedule) { | |
1710 | ERR("Failed to retrieve session rotation schedule."); | |
1711 | cmd_ret = CMD_ERROR; | |
1712 | goto end; | |
1713 | } | |
1714 | ||
329f3443 | 1715 | if (lttng_opt_mi) { |
66ea93b1 | 1716 | ret = mi_lttng_rotation_schedule(writer, schedule); |
329f3443 | 1717 | if (ret) { |
66ea93b1 | 1718 | tmp_ret = CMD_ERROR; |
329f3443 | 1719 | } |
66ea93b1 JG |
1720 | } else { |
1721 | tmp_ret = print_rotation_schedule(schedule); | |
329f3443 | 1722 | } |
66ea93b1 JG |
1723 | |
1724 | /* | |
1725 | * Report an error if the serialization of any of the | |
1726 | * descriptors failed. | |
1727 | */ | |
1728 | cmd_ret = cmd_ret ? cmd_ret : tmp_ret; | |
329f3443 | 1729 | } |
329f3443 | 1730 | |
66ea93b1 JG |
1731 | _MSG("\n"); |
1732 | if (lttng_opt_mi) { | |
1733 | /* Close the rotation_schedules element. */ | |
1734 | ret = mi_lttng_writer_close_element(writer); | |
1735 | if (ret) { | |
1736 | cmd_ret = CMD_ERROR; | |
1737 | goto end; | |
1738 | } | |
1739 | } | |
329f3443 | 1740 | end: |
66ea93b1 JG |
1741 | lttng_rotation_schedules_destroy(schedules); |
1742 | return cmd_ret; | |
329f3443 JD |
1743 | } |
1744 | ||
fb14d0d8 JR |
1745 | /* |
1746 | * Machine interface | |
1747 | * Find the session with session_name as name | |
1748 | * and print his informations. | |
1749 | */ | |
1750 | static int mi_list_session(const char *session_name, | |
1751 | struct lttng_session *sessions, int count) | |
1752 | { | |
1753 | int ret, i; | |
1754 | unsigned int session_found = 0; | |
1755 | ||
1756 | if (session_name == NULL) { | |
1757 | ret = -LTTNG_ERR_SESS_NOT_FOUND; | |
1758 | goto end; | |
1759 | } | |
1760 | ||
1761 | for (i = 0; i < count; i++) { | |
1762 | if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) { | |
1763 | /* We need to leave it open to append other informations | |
1764 | * like domain, channel, events etc.*/ | |
1765 | session_found = 1; | |
1766 | ret = mi_lttng_session(writer, &sessions[i], 1); | |
1767 | if (ret) { | |
1768 | goto end; | |
1769 | } | |
9f19cc17 | 1770 | break; |
f3ed775e | 1771 | } |
f3ed775e DG |
1772 | } |
1773 | ||
fb14d0d8 JR |
1774 | if (!session_found) { |
1775 | ERR("Session '%s' not found", session_name); | |
1776 | ret = -LTTNG_ERR_SESS_NOT_FOUND; | |
1777 | goto end; | |
9f19cc17 | 1778 | } |
f3ed775e | 1779 | |
fb14d0d8 JR |
1780 | end: |
1781 | return ret; | |
1782 | } | |
f3ed775e | 1783 | |
fb14d0d8 JR |
1784 | /* |
1785 | * Machine interface | |
1786 | * List all availables session | |
1787 | */ | |
1788 | static int mi_list_sessions(struct lttng_session *sessions, int count) | |
1789 | { | |
1790 | int ret, i; | |
ae856491 | 1791 | |
fb14d0d8 JR |
1792 | /* Opening sessions element */ |
1793 | ret = mi_lttng_sessions_open(writer); | |
1794 | if (ret) { | |
1795 | goto end; | |
1796 | } | |
1797 | ||
1798 | /* Listing sessions */ | |
1799 | for (i = 0; i < count; i++) { | |
1800 | ret = mi_lttng_session(writer, &sessions[i], 0); | |
1801 | if (ret) { | |
1802 | goto end; | |
1803 | } | |
1804 | } | |
1805 | ||
1806 | /* Closing sessions element */ | |
1807 | ret = mi_lttng_writer_close_element(writer); | |
1808 | if (ret) { | |
1809 | goto end; | |
1810 | } | |
1811 | ||
1812 | end: | |
f3ed775e DG |
1813 | return ret; |
1814 | } | |
1815 | ||
1816 | /* | |
9f19cc17 | 1817 | * List available tracing session. List only basic information. |
f3ed775e | 1818 | * |
9f19cc17 | 1819 | * If session_name is NULL, all sessions are listed. |
f3ed775e | 1820 | */ |
9f19cc17 | 1821 | static int list_sessions(const char *session_name) |
f3ed775e | 1822 | { |
fb14d0d8 JR |
1823 | int ret = CMD_SUCCESS; |
1824 | int count, i; | |
9f19cc17 DG |
1825 | unsigned int session_found = 0; |
1826 | struct lttng_session *sessions; | |
1827 | ||
1828 | count = lttng_list_sessions(&sessions); | |
1829 | DBG("Session count %d", count); | |
1830 | if (count < 0) { | |
fb14d0d8 JR |
1831 | ret = CMD_ERROR; |
1832 | ERR("%s", lttng_strerror(count)); | |
d32fb093 | 1833 | goto end; |
9f19cc17 DG |
1834 | } |
1835 | ||
fb14d0d8 JR |
1836 | if (lttng_opt_mi) { |
1837 | /* Mi */ | |
1838 | if (session_name == NULL) { | |
1839 | /* List all session */ | |
1840 | ret = mi_list_sessions(sessions, count); | |
1841 | } else { | |
1842 | /* Note : this return an open session element */ | |
1843 | ret = mi_list_session(session_name, sessions, count); | |
1844 | } | |
1845 | if (ret) { | |
1846 | ret = CMD_ERROR; | |
1847 | goto error; | |
1848 | } | |
1849 | } else { | |
1850 | /* Pretty print */ | |
1851 | if (count == 0) { | |
1852 | MSG("Currently no available tracing session"); | |
fb14d0d8 JR |
1853 | goto end; |
1854 | } | |
9f19cc17 | 1855 | |
fb14d0d8 JR |
1856 | if (session_name == NULL) { |
1857 | MSG("Available tracing sessions:"); | |
1858 | } | |
1859 | ||
1860 | ||
1861 | for (i = 0; i < count; i++) { | |
1862 | if (session_name != NULL) { | |
1863 | if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) { | |
1864 | session_found = 1; | |
1865 | MSG("Tracing session %s: [%s%s]", session_name, | |
1866 | active_string(sessions[i].enabled), | |
1867 | snapshot_string(sessions[i].snapshot_mode)); | |
1868 | MSG("%sTrace path: %s\n", indent4, sessions[i].path); | |
e50e81d3 JG |
1869 | memcpy(&listed_session, &sessions[i], |
1870 | sizeof(listed_session)); | |
fb14d0d8 JR |
1871 | break; |
1872 | } | |
1873 | } else { | |
1874 | MSG(" %d) %s (%s) [%s%s]", i + 1, | |
1875 | sessions[i].name, sessions[i].path, | |
2cbf8fed DG |
1876 | active_string(sessions[i].enabled), |
1877 | snapshot_string(sessions[i].snapshot_mode)); | |
2f785fe7 | 1878 | MSG("%sTrace path: %s", indent4, sessions[i].path); |
fcbc96a2 | 1879 | if (sessions[i].live_timer_interval != 0) { |
e50e81d3 | 1880 | MSG("%sLive timer interval: %u µs", indent4, |
fcbc96a2 JG |
1881 | sessions[i].live_timer_interval); |
1882 | } | |
1883 | MSG(""); | |
9f19cc17 | 1884 | } |
fb14d0d8 JR |
1885 | } |
1886 | ||
1887 | if (!session_found && session_name != NULL) { | |
1888 | ERR("Session '%s' not found", session_name); | |
1889 | ret = CMD_ERROR; | |
1890 | goto error; | |
1891 | } | |
1892 | ||
1893 | if (session_name == NULL) { | |
1894 | MSG("\nUse lttng list <session_name> for more details"); | |
9f19cc17 DG |
1895 | } |
1896 | } | |
1897 | ||
fb14d0d8 | 1898 | error: |
9f19cc17 | 1899 | free(sessions); |
fb14d0d8 JR |
1900 | end: |
1901 | return ret; | |
1902 | } | |
9f19cc17 | 1903 | |
fb14d0d8 JR |
1904 | |
1905 | /* | |
1906 | * Machine Interface | |
1907 | * list available domain(s) for a session. | |
1908 | */ | |
1909 | static int mi_list_domains(struct lttng_domain *domains, int count) | |
1910 | { | |
1911 | int i, ret; | |
1912 | /* Open domains element */ | |
1913 | ret = mi_lttng_domains_open(writer); | |
1914 | if (ret) { | |
1915 | goto end; | |
9f19cc17 DG |
1916 | } |
1917 | ||
fb14d0d8 JR |
1918 | for (i = 0; i < count; i++) { |
1919 | ret = mi_lttng_domain(writer, &domains[i] , 0); | |
1920 | if (ret) { | |
1921 | goto end; | |
1922 | } | |
9f19cc17 | 1923 | } |
f3ed775e | 1924 | |
fb14d0d8 JR |
1925 | /* Closing domains element */ |
1926 | ret = mi_lttng_writer_close_element(writer); | |
1927 | if (ret) { | |
1928 | goto end; | |
1929 | } | |
d32fb093 | 1930 | end: |
f3ed775e DG |
1931 | return ret; |
1932 | } | |
f3ed775e DG |
1933 | |
1934 | /* | |
9f19cc17 | 1935 | * List available domain(s) for a session. |
f3ed775e | 1936 | */ |
330be774 | 1937 | static int list_domains(const char *session_name) |
f3ed775e | 1938 | { |
9f19cc17 DG |
1939 | int i, count, ret = CMD_SUCCESS; |
1940 | struct lttng_domain *domains = NULL; | |
1941 | ||
9f19cc17 | 1942 | |
330be774 | 1943 | count = lttng_list_domains(session_name, &domains); |
9f19cc17 | 1944 | if (count < 0) { |
fb14d0d8 JR |
1945 | ret = CMD_ERROR; |
1946 | ERR("%s", lttng_strerror(count)); | |
9f19cc17 DG |
1947 | goto end; |
1948 | } | |
1949 | ||
fb14d0d8 JR |
1950 | if (lttng_opt_mi) { |
1951 | /* Mi output */ | |
1952 | ret = mi_list_domains(domains, count); | |
1953 | if (ret) { | |
1954 | ret = CMD_ERROR; | |
1955 | goto error; | |
1956 | } | |
1957 | } else { | |
1958 | /* Pretty print */ | |
1959 | MSG("Domains:\n-------------"); | |
1960 | if (count == 0) { | |
1961 | MSG(" None"); | |
1962 | goto end; | |
1963 | } | |
1964 | ||
1965 | for (i = 0; i < count; i++) { | |
1966 | switch (domains[i].type) { | |
1967 | case LTTNG_DOMAIN_KERNEL: | |
1968 | MSG(" - Kernel"); | |
1969 | break; | |
1970 | case LTTNG_DOMAIN_UST: | |
1971 | MSG(" - UST global"); | |
1972 | break; | |
1973 | case LTTNG_DOMAIN_JUL: | |
1974 | MSG(" - JUL (Java Util Logging)"); | |
1975 | break; | |
5cdb6027 DG |
1976 | case LTTNG_DOMAIN_LOG4J: |
1977 | MSG(" - LOG4j (Logging for Java)"); | |
1978 | break; | |
0e115563 DG |
1979 | case LTTNG_DOMAIN_PYTHON: |
1980 | MSG(" - Python (logging)"); | |
1981 | break; | |
fb14d0d8 JR |
1982 | default: |
1983 | break; | |
1984 | } | |
9f19cc17 DG |
1985 | } |
1986 | } | |
1987 | ||
fb14d0d8 | 1988 | error: |
9f19cc17 DG |
1989 | free(domains); |
1990 | ||
fb14d0d8 | 1991 | end: |
9f19cc17 | 1992 | return ret; |
f3ed775e | 1993 | } |
f3ed775e DG |
1994 | |
1995 | /* | |
9f19cc17 | 1996 | * The 'list <options>' first level command |
f3ed775e DG |
1997 | */ |
1998 | int cmd_list(int argc, const char **argv) | |
1999 | { | |
c617c0c6 | 2000 | int opt, ret = CMD_SUCCESS; |
68c7f6e5 | 2001 | const char *session_name, *leftover = NULL; |
f3ed775e | 2002 | static poptContext pc; |
9f19cc17 DG |
2003 | struct lttng_domain domain; |
2004 | struct lttng_domain *domains = NULL; | |
f3ed775e | 2005 | |
441c16a7 MD |
2006 | memset(&domain, 0, sizeof(domain)); |
2007 | ||
9f19cc17 | 2008 | if (argc < 1) { |
ca1c3607 | 2009 | ret = CMD_ERROR; |
f3ed775e DG |
2010 | goto end; |
2011 | } | |
2012 | ||
2013 | pc = poptGetContext(NULL, argc, argv, long_options, 0); | |
2014 | poptReadDefaultConfig(pc, 0); | |
2015 | ||
2016 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
2017 | switch (opt) { | |
2018 | case OPT_HELP: | |
4ba92f18 | 2019 | SHOW_HELP(); |
f3ed775e | 2020 | goto end; |
eeac7d46 MD |
2021 | case OPT_USERSPACE: |
2022 | opt_userspace = 1; | |
eeac7d46 | 2023 | break; |
679b4943 SM |
2024 | case OPT_LIST_OPTIONS: |
2025 | list_cmd_options(stdout, long_options); | |
679b4943 | 2026 | goto end; |
f3ed775e | 2027 | default: |
f3ed775e DG |
2028 | ret = CMD_UNDEFINED; |
2029 | goto end; | |
2030 | } | |
2031 | } | |
2032 | ||
fb14d0d8 JR |
2033 | /* Mi check */ |
2034 | if (lttng_opt_mi) { | |
2035 | writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); | |
2036 | if (!writer) { | |
2037 | ret = CMD_ERROR; | |
2038 | goto end; | |
2039 | } | |
2040 | ||
2041 | /* Open command element */ | |
2042 | ret = mi_lttng_writer_command_open(writer, | |
2043 | mi_lttng_element_command_list); | |
2044 | if (ret) { | |
2045 | ret = CMD_ERROR; | |
2046 | goto end; | |
2047 | } | |
2048 | ||
2049 | /* Open output element */ | |
2050 | ret = mi_lttng_writer_open_element(writer, | |
2051 | mi_lttng_element_command_output); | |
2052 | if (ret) { | |
2053 | ret = CMD_ERROR; | |
2054 | goto end; | |
2055 | } | |
2056 | } | |
2057 | ||
9f19cc17 DG |
2058 | /* Get session name (trailing argument) */ |
2059 | session_name = poptGetArg(pc); | |
b551a063 | 2060 | DBG2("Session name: %s", session_name); |
9f19cc17 | 2061 | |
68c7f6e5 JD |
2062 | leftover = poptGetArg(pc); |
2063 | if (leftover) { | |
2064 | ERR("Unknown argument: %s", leftover); | |
2065 | ret = CMD_ERROR; | |
2066 | goto end; | |
2067 | } | |
2068 | ||
cd80958d DG |
2069 | if (opt_kernel) { |
2070 | domain.type = LTTNG_DOMAIN_KERNEL; | |
b551a063 DG |
2071 | } else if (opt_userspace) { |
2072 | DBG2("Listing userspace global domain"); | |
2073 | domain.type = LTTNG_DOMAIN_UST; | |
3c6a091f DG |
2074 | } else if (opt_jul) { |
2075 | DBG2("Listing JUL domain"); | |
2076 | domain.type = LTTNG_DOMAIN_JUL; | |
edf60534 | 2077 | } else if (opt_log4j) { |
5cdb6027 | 2078 | domain.type = LTTNG_DOMAIN_LOG4J; |
0e115563 DG |
2079 | } else if (opt_python) { |
2080 | domain.type = LTTNG_DOMAIN_PYTHON; | |
cd80958d DG |
2081 | } |
2082 | ||
834978fd DG |
2083 | if (!opt_kernel && opt_syscall) { |
2084 | WARN("--syscall will only work with the Kernel domain (-k)"); | |
2085 | ret = CMD_ERROR; | |
2086 | goto end; | |
2087 | } | |
2088 | ||
0e115563 | 2089 | if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) { |
aa5de748 MD |
2090 | handle = lttng_create_handle(session_name, &domain); |
2091 | if (handle == NULL) { | |
2092 | ret = CMD_FATAL; | |
2093 | goto end; | |
2094 | } | |
cd80958d DG |
2095 | } |
2096 | ||
9f19cc17 | 2097 | if (session_name == NULL) { |
0e115563 DG |
2098 | if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j |
2099 | && !opt_python) { | |
b551a063 | 2100 | ret = list_sessions(NULL); |
fb14d0d8 | 2101 | if (ret) { |
b551a063 DG |
2102 | goto end; |
2103 | } | |
2104 | } | |
9f19cc17 | 2105 | if (opt_kernel) { |
834978fd DG |
2106 | if (opt_syscall) { |
2107 | ret = list_syscalls(); | |
2108 | if (ret) { | |
2109 | goto end; | |
2110 | } | |
2111 | } else { | |
2112 | ret = list_kernel_events(); | |
2113 | if (ret) { | |
2114 | goto end; | |
2115 | } | |
9f19cc17 | 2116 | } |
b551a063 DG |
2117 | } |
2118 | if (opt_userspace) { | |
f37d259d MD |
2119 | if (opt_fields) { |
2120 | ret = list_ust_event_fields(); | |
2121 | } else { | |
2122 | ret = list_ust_events(); | |
2123 | } | |
fb14d0d8 | 2124 | if (ret) { |
9f19cc17 DG |
2125 | goto end; |
2126 | } | |
2127 | } | |
0e115563 | 2128 | if (opt_jul || opt_log4j || opt_python) { |
5cdb6027 | 2129 | ret = list_agent_events(); |
fb14d0d8 | 2130 | if (ret) { |
3c6a091f DG |
2131 | goto end; |
2132 | } | |
2133 | } | |
9f19cc17 DG |
2134 | } else { |
2135 | /* List session attributes */ | |
fb14d0d8 JR |
2136 | if (lttng_opt_mi) { |
2137 | /* Open element sessions | |
2138 | * Present for xml consistency */ | |
2139 | ret = mi_lttng_sessions_open(writer); | |
2140 | if (ret) { | |
2141 | goto end; | |
2142 | } | |
2143 | } | |
2144 | /* MI: the ouptut of list_sessions is an unclosed session element */ | |
9f19cc17 | 2145 | ret = list_sessions(session_name); |
fb14d0d8 | 2146 | if (ret) { |
9f19cc17 DG |
2147 | goto end; |
2148 | } | |
2149 | ||
329f3443 JD |
2150 | ret = list_rotate_settings(session_name); |
2151 | if (ret) { | |
2152 | goto end; | |
2153 | } | |
2154 | ||
9f19cc17 DG |
2155 | /* Domain listing */ |
2156 | if (opt_domain) { | |
330be774 | 2157 | ret = list_domains(session_name); |
9f19cc17 DG |
2158 | goto end; |
2159 | } | |
2160 | ||
fb14d0d8 | 2161 | /* Channel listing */ |
1c3de747 | 2162 | if (opt_kernel || opt_userspace) { |
fb14d0d8 JR |
2163 | if (lttng_opt_mi) { |
2164 | /* Add of domains and domain element for xml | |
2165 | * consistency and validation | |
2166 | */ | |
2167 | ret = mi_lttng_domains_open(writer); | |
2168 | if (ret) { | |
2169 | goto end; | |
2170 | } | |
2171 | ||
2172 | /* Open domain and leave it open for | |
2173 | * nested channels printing */ | |
2174 | ret = mi_lttng_domain(writer, &domain, 1); | |
2175 | if (ret) { | |
2176 | goto end; | |
2177 | } | |
2178 | ||
2179 | } | |
2180 | ||
ebbf5ab7 JR |
2181 | |
2182 | /* Trackers */ | |
2183 | ret = list_trackers(); | |
a5dfbb9d MD |
2184 | if (ret) { |
2185 | goto end; | |
2186 | } | |
2187 | ||
ebbf5ab7 | 2188 | /* Channels */ |
cd80958d | 2189 | ret = list_channels(opt_channel); |
fb14d0d8 JR |
2190 | if (ret) { |
2191 | goto end; | |
2192 | } | |
2193 | ||
2194 | if (lttng_opt_mi) { | |
2195 | /* Close domain and domain element */ | |
2196 | ret = mi_lttng_close_multi_element(writer, 2); | |
2197 | } | |
2198 | if (ret) { | |
9f19cc17 DG |
2199 | goto end; |
2200 | } | |
fb14d0d8 JR |
2201 | |
2202 | ||
9f19cc17 | 2203 | } else { |
c617c0c6 MD |
2204 | int i, nb_domain; |
2205 | ||
9f19cc17 | 2206 | /* We want all domain(s) */ |
330be774 | 2207 | nb_domain = lttng_list_domains(session_name, &domains); |
b551a063 | 2208 | if (nb_domain < 0) { |
fb14d0d8 JR |
2209 | ret = CMD_ERROR; |
2210 | ERR("%s", lttng_strerror(nb_domain)); | |
9f19cc17 DG |
2211 | goto end; |
2212 | } | |
2213 | ||
fb14d0d8 JR |
2214 | if (lttng_opt_mi) { |
2215 | ret = mi_lttng_domains_open(writer); | |
2216 | if (ret) { | |
2217 | ret = CMD_ERROR; | |
2218 | goto end; | |
2219 | } | |
2220 | } | |
2221 | ||
b551a063 | 2222 | for (i = 0; i < nb_domain; i++) { |
9f19cc17 DG |
2223 | switch (domains[i].type) { |
2224 | case LTTNG_DOMAIN_KERNEL: | |
2225 | MSG("=== Domain: Kernel ===\n"); | |
2226 | break; | |
b551a063 DG |
2227 | case LTTNG_DOMAIN_UST: |
2228 | MSG("=== Domain: UST global ===\n"); | |
88c5f0d8 DG |
2229 | MSG("Buffer type: %s\n", |
2230 | domains[i].buf_type == | |
2231 | LTTNG_BUFFER_PER_PID ? "per PID" : "per UID"); | |
b551a063 | 2232 | break; |
3c6a091f DG |
2233 | case LTTNG_DOMAIN_JUL: |
2234 | MSG("=== Domain: JUL (Java Util Logging) ===\n"); | |
2235 | break; | |
5cdb6027 DG |
2236 | case LTTNG_DOMAIN_LOG4J: |
2237 | MSG("=== Domain: LOG4j (Logging for Java) ===\n"); | |
2238 | break; | |
0e115563 DG |
2239 | case LTTNG_DOMAIN_PYTHON: |
2240 | MSG("=== Domain: Python (logging) ===\n"); | |
2241 | break; | |
9f19cc17 DG |
2242 | default: |
2243 | MSG("=== Domain: Unimplemented ===\n"); | |
2244 | break; | |
2245 | } | |
2246 | ||
fb14d0d8 JR |
2247 | if (lttng_opt_mi) { |
2248 | ret = mi_lttng_domain(writer, &domains[i], 1); | |
2249 | if (ret) { | |
2250 | ret = CMD_ERROR; | |
2251 | goto end; | |
2252 | } | |
2253 | } | |
2254 | ||
cd80958d | 2255 | /* Clean handle before creating a new one */ |
aa5de748 MD |
2256 | if (handle) { |
2257 | lttng_destroy_handle(handle); | |
2258 | } | |
cd80958d DG |
2259 | |
2260 | handle = lttng_create_handle(session_name, &domains[i]); | |
2261 | if (handle == NULL) { | |
ca1c3607 | 2262 | ret = CMD_FATAL; |
cd80958d DG |
2263 | goto end; |
2264 | } | |
2265 | ||
5cdb6027 | 2266 | if (domains[i].type == LTTNG_DOMAIN_JUL || |
0e115563 DG |
2267 | domains[i].type == LTTNG_DOMAIN_LOG4J || |
2268 | domains[i].type == LTTNG_DOMAIN_PYTHON) { | |
5cdb6027 | 2269 | ret = list_session_agent_events(); |
fb14d0d8 | 2270 | if (ret) { |
3c6a091f DG |
2271 | goto end; |
2272 | } | |
cd7b2927 PP |
2273 | |
2274 | goto next_domain; | |
3c6a091f | 2275 | } |
a5dfbb9d MD |
2276 | |
2277 | switch (domains[i].type) { | |
2278 | case LTTNG_DOMAIN_KERNEL: | |
2279 | case LTTNG_DOMAIN_UST: | |
ebbf5ab7 | 2280 | ret = list_trackers(); |
a5dfbb9d MD |
2281 | if (ret) { |
2282 | goto end; | |
2283 | } | |
2284 | break; | |
2285 | default: | |
2286 | break; | |
2287 | } | |
3c6a091f | 2288 | |
cd80958d | 2289 | ret = list_channels(opt_channel); |
fb14d0d8 JR |
2290 | if (ret) { |
2291 | goto end; | |
2292 | } | |
2293 | ||
cd7b2927 | 2294 | next_domain: |
fb14d0d8 JR |
2295 | if (lttng_opt_mi) { |
2296 | /* Close domain element */ | |
2297 | ret = mi_lttng_writer_close_element(writer); | |
2298 | if (ret) { | |
2299 | ret = CMD_ERROR; | |
2300 | goto end; | |
2301 | } | |
2302 | } | |
2303 | ||
2304 | } | |
2305 | if (lttng_opt_mi) { | |
2306 | /* Close the domains, session and sessions element */ | |
2307 | ret = mi_lttng_close_multi_element(writer, 3); | |
2308 | if (ret) { | |
2309 | ret = CMD_ERROR; | |
9f19cc17 DG |
2310 | goto end; |
2311 | } | |
2312 | } | |
2313 | } | |
f3ed775e DG |
2314 | } |
2315 | ||
fb14d0d8 JR |
2316 | /* Mi closing */ |
2317 | if (lttng_opt_mi) { | |
2318 | /* Close output element */ | |
2319 | ret = mi_lttng_writer_close_element(writer); | |
2320 | if (ret) { | |
2321 | ret = CMD_ERROR; | |
2322 | goto end; | |
2323 | } | |
2324 | ||
2325 | /* Command element close */ | |
2326 | ret = mi_lttng_writer_command_close(writer); | |
2327 | if (ret) { | |
2328 | ret = CMD_ERROR; | |
2329 | goto end; | |
2330 | } | |
2331 | } | |
f3ed775e | 2332 | end: |
fb14d0d8 JR |
2333 | /* Mi clean-up */ |
2334 | if (writer && mi_lttng_writer_destroy(writer)) { | |
2335 | /* Preserve original error code */ | |
2336 | ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL; | |
2337 | } | |
2338 | ||
0e428499 | 2339 | free(domains); |
aa5de748 MD |
2340 | if (handle) { |
2341 | lttng_destroy_handle(handle); | |
2342 | } | |
cd80958d | 2343 | |
ca1c3607 | 2344 | poptFreeContext(pc); |
f3ed775e DG |
2345 | return ret; |
2346 | } |