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 <common/mi-lttng.h>
27 #include <lttng/constant.h>
29 #include "../command.h"
31 static int opt_userspace
;
32 static int opt_kernel
;
35 static int opt_python
;
36 static char *opt_channel
;
37 static int opt_domain
;
38 static int opt_fields
;
39 static int opt_syscall
;
41 const char *indent4
= " ";
42 const char *indent6
= " ";
43 const char *indent8
= " ";
45 #ifdef LTTNG_EMBED_HELP
46 static const char help_msg
[] =
47 #include <lttng-list.1.h>
57 static struct lttng_handle
*handle
;
58 static struct mi_writer
*writer
;
60 /* Only set when listing a single session. */
61 static struct lttng_session listed_session
;
63 static struct poptOption long_options
[] = {
64 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
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},
75 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
80 * Get command line from /proc for a specific pid.
82 * On success, return an allocated string pointer to the proc cmdline.
83 * On error, return NULL.
85 static char *get_cmdline_by_pid(pid_t pid
)
90 /* Can't go bigger than /proc/LTTNG_MAX_PID/cmdline */
91 char path
[sizeof("/proc//cmdline") + sizeof(LTTNG_MAX_PID_STR
) - 1];
93 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pid
);
94 fp
= fopen(path
, "r");
99 /* Caller must free() *cmdline */
100 cmdline
= zmalloc(PATH_MAX
);
102 PERROR("malloc cmdline");
105 ret
= fread(cmdline
, 1, PATH_MAX
, fp
);
107 PERROR("fread proc list");
118 const char *active_string(int value
)
121 case 0: return "inactive";
122 case 1: return "active";
124 default: return NULL
;
128 static const char *snapshot_string(int value
)
139 const char *enabled_string(int value
)
142 case 0: return " [disabled]";
143 case 1: return " [enabled]";
145 default: return NULL
;
150 const char *safe_string(const char *str
)
152 return str
? str
: "";
155 static const char *logleveltype_string(enum lttng_loglevel_type value
)
158 case LTTNG_EVENT_LOGLEVEL_ALL
:
160 case LTTNG_EVENT_LOGLEVEL_RANGE
:
162 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
165 return " <<TYPE UNKN>>";
169 static const char *bitness_event(enum lttng_event_flag flags
)
171 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_32
) {
172 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
173 return " [32/64-bit]";
177 } else if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
185 * Get exclusion names message for a single event.
187 * Returned pointer must be freed by caller. Returns NULL on error.
189 static char *get_exclusion_names_msg(struct lttng_event
*event
)
193 char *exclusion_msg
= NULL
;
196 const char * const exclusion_fmt
= " [exclusions: ";
197 const size_t exclusion_fmt_len
= strlen(exclusion_fmt
);
199 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
200 if (exclusion_count
< 0) {
202 } else if (exclusion_count
== 0) {
204 * No exclusions: return copy of empty string so that
205 * it can be freed by caller.
207 exclusion_msg
= strdup("");
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.
216 exclusion_msg
= malloc(exclusion_count
+
217 exclusion_count
* LTTNG_SYMBOL_NAME_LEN
+
218 exclusion_fmt_len
+ 1);
219 if (!exclusion_msg
) {
223 at
= strcpy(exclusion_msg
, exclusion_fmt
) + exclusion_fmt_len
;
224 for (i
= 0; i
< exclusion_count
; ++i
) {
227 /* Append comma between exclusion names */
233 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
235 /* Prints '?' on local error; should never happen */
241 /* Append exclusion name */
242 at
+= sprintf(at
, "%s", name
);
245 /* This also puts a final '\0' at the end of exclusion_msg */
249 return exclusion_msg
;
252 static void print_userspace_probe_location(struct lttng_event
*event
)
254 const struct lttng_userspace_probe_location
*location
;
255 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
256 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
258 location
= lttng_event_get_userspace_probe_location(event
);
260 MSG("Event has no userspace probe location");
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");
270 MSG("%s%s (type: userspace-probe)%s", indent6
, event
->name
, enabled_string(event
->enabled
));
272 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
274 switch (lttng_userspace_probe_location_get_type(location
)) {
275 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
:
276 MSG("%sType: Unknown", indent8
);
278 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
280 const char *function_name
;
281 const char *binary_path
;
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
);
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
);
293 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
294 MSG("%sLookup method: default", indent8
);
297 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
302 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
304 const char *probe_name
, *provider_name
;
305 const char *binary_path
;
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
);
318 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
324 ERR("Invalid probe type encountered");
329 * Pretty print single event.
331 static void print_events(struct lttng_event
*event
)
334 const char *filter_str
;
335 char *filter_msg
= NULL
;
336 char *exclusion_msg
= NULL
;
338 ret
= lttng_event_get_filter_expression(event
, &filter_str
);
341 filter_msg
= strdup(" [failed to retrieve filter]");
342 } else if (filter_str
) {
343 const char * const filter_fmt
= " [filter: '%s']";
345 filter_msg
= malloc(strlen(filter_str
) +
346 strlen(filter_fmt
) + 1);
348 sprintf(filter_msg
, filter_fmt
,
353 exclusion_msg
= get_exclusion_names_msg(event
);
354 if (!exclusion_msg
) {
355 exclusion_msg
= strdup(" [failed to retrieve exclusions]");
358 switch (event
->type
) {
359 case LTTNG_EVENT_TRACEPOINT
:
361 if (event
->loglevel
!= -1) {
362 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
365 logleveltype_string(event
->loglevel_type
),
366 mi_lttng_loglevel_string(event
->loglevel
, handle
->domain
.type
),
368 enabled_string(event
->enabled
),
369 safe_string(exclusion_msg
),
370 safe_string(filter_msg
));
372 MSG("%s%s (type: tracepoint)%s%s%s",
375 enabled_string(event
->enabled
),
376 safe_string(exclusion_msg
),
377 safe_string(filter_msg
));
381 case LTTNG_EVENT_FUNCTION
:
382 MSG("%s%s (type: function)%s%s", indent6
,
383 event
->name
, enabled_string(event
->enabled
),
384 safe_string(filter_msg
));
385 if (event
->attr
.probe
.addr
!= 0) {
386 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
388 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
389 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
392 case LTTNG_EVENT_PROBE
:
393 MSG("%s%s (type: probe)%s%s", indent6
,
394 event
->name
, enabled_string(event
->enabled
),
395 safe_string(filter_msg
));
396 if (event
->attr
.probe
.addr
!= 0) {
397 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
399 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
400 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
403 case LTTNG_EVENT_USERSPACE_PROBE
:
404 print_userspace_probe_location(event
);
406 case LTTNG_EVENT_FUNCTION_ENTRY
:
407 MSG("%s%s (type: function)%s%s", indent6
,
408 event
->name
, enabled_string(event
->enabled
),
409 safe_string(filter_msg
));
410 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
412 case LTTNG_EVENT_SYSCALL
:
413 MSG("%s%s%s%s%s%s", indent6
, event
->name
,
414 (opt_syscall
? "" : " (type:syscall)"),
415 enabled_string(event
->enabled
),
416 bitness_event(event
->flags
),
417 safe_string(filter_msg
));
419 case LTTNG_EVENT_NOOP
:
420 MSG("%s (type: noop)%s%s", indent6
,
421 enabled_string(event
->enabled
),
422 safe_string(filter_msg
));
424 case LTTNG_EVENT_ALL
:
427 /* We should never have "all" events in list. */
436 static const char *field_type(struct lttng_event_field
*field
)
438 switch(field
->type
) {
439 case LTTNG_EVENT_FIELD_INTEGER
:
441 case LTTNG_EVENT_FIELD_ENUM
:
443 case LTTNG_EVENT_FIELD_FLOAT
:
445 case LTTNG_EVENT_FIELD_STRING
:
447 case LTTNG_EVENT_FIELD_OTHER
:
448 default: /* fall-through */
454 * Pretty print single event fields.
456 static void print_event_field(struct lttng_event_field
*field
)
458 if (!field
->field_name
[0]) {
461 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
462 field_type(field
), field
->nowrite
? " [no write]" : "");
467 * Jul and ust event listing
469 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
470 struct lttng_domain
*domain
)
474 char *cmdline
= NULL
;
475 int pid_element_open
= 0;
477 /* Open domains element */
478 ret
= mi_lttng_domains_open(writer
);
484 ret
= mi_lttng_domain(writer
, domain
, 1);
489 /* Open pids element element */
490 ret
= mi_lttng_pids_open(writer
);
495 for (i
= 0; i
< count
; i
++) {
496 if (cur_pid
!= events
[i
].pid
) {
497 if (pid_element_open
) {
498 /* Close the previous events and pid element */
499 ret
= mi_lttng_close_multi_element(writer
, 2);
503 pid_element_open
= 0;
506 cur_pid
= events
[i
].pid
;
507 cmdline
= get_cmdline_by_pid(cur_pid
);
513 if (!pid_element_open
) {
514 /* Open and write a pid element */
515 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
520 /* Open events element */
521 ret
= mi_lttng_events_open(writer
);
526 pid_element_open
= 1;
532 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
539 ret
= mi_lttng_writer_close_element(writer
);
544 /* Close domain, domains */
545 ret
= mi_lttng_close_multi_element(writer
, 2);
553 static int list_agent_events(void)
555 int i
, size
, ret
= CMD_SUCCESS
;
556 struct lttng_domain domain
;
557 struct lttng_handle
*handle
= NULL
;
558 struct lttng_event
*event_list
= NULL
;
560 char *cmdline
= NULL
;
561 const char *agent_domain_str
;
563 memset(&domain
, 0, sizeof(domain
));
565 domain
.type
= LTTNG_DOMAIN_JUL
;
566 } else if (opt_log4j
) {
567 domain
.type
= LTTNG_DOMAIN_LOG4J
;
568 } else if (opt_python
) {
569 domain
.type
= LTTNG_DOMAIN_PYTHON
;
571 ERR("Invalid agent domain selected.");
576 agent_domain_str
= get_domain_str(domain
.type
);
578 DBG("Getting %s tracing events", agent_domain_str
);
580 handle
= lttng_create_handle(NULL
, &domain
);
581 if (handle
== NULL
) {
586 size
= lttng_list_tracepoints(handle
, &event_list
);
588 ERR("Unable to list %s events: %s", agent_domain_str
,
589 lttng_strerror(size
));
596 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
603 MSG("%s events (Logger name):\n-------------------------",
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
) {
618 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
621 MSG("%s- %s", indent6
, event_list
[i
].name
);
630 lttng_destroy_handle(handle
);
635 * Ask session daemon for all user space tracepoints available.
637 static int list_ust_events(void)
639 int i
, size
, ret
= CMD_SUCCESS
;
640 struct lttng_domain domain
;
641 struct lttng_handle
*handle
;
642 struct lttng_event
*event_list
= NULL
;
644 char *cmdline
= NULL
;
646 memset(&domain
, 0, sizeof(domain
));
648 DBG("Getting UST tracing events");
650 domain
.type
= LTTNG_DOMAIN_UST
;
652 handle
= lttng_create_handle(NULL
, &domain
);
653 if (handle
== NULL
) {
658 size
= lttng_list_tracepoints(handle
, &event_list
);
660 ERR("Unable to list UST events: %s", lttng_strerror(size
));
667 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
670 MSG("UST events:\n-------------");
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
) {
684 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
687 print_events(&event_list
[i
]);
696 lttng_destroy_handle(handle
);
702 * List all ust event with their fields
704 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
705 struct lttng_domain
*domain
)
709 char *cmdline
= NULL
;
710 int pid_element_open
= 0;
711 int event_element_open
= 0;
712 struct lttng_event cur_event
;
714 memset(&cur_event
, 0, sizeof(cur_event
));
716 /* Open domains element */
717 ret
= mi_lttng_domains_open(writer
);
723 ret
= mi_lttng_domain(writer
, domain
, 1);
728 /* Open pids element */
729 ret
= mi_lttng_pids_open(writer
);
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
) {
738 /* Close the previous field element and event. */
739 ret
= mi_lttng_close_multi_element(writer
, 2);
743 event_element_open
= 0;
745 /* Close the previous events, pid element */
746 ret
= mi_lttng_close_multi_element(writer
, 2);
750 pid_element_open
= 0;
753 cur_pid
= fields
[i
].event
.pid
;
754 cmdline
= get_cmdline_by_pid(cur_pid
);
755 if (!pid_element_open
) {
756 /* Open and write a pid element */
757 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
762 /* Open events element */
763 ret
= mi_lttng_events_open(writer
);
767 pid_element_open
= 1;
770 /* Wipe current event since we are about to print a new PID. */
771 memset(&cur_event
, 0, sizeof(cur_event
));
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);
781 event_element_open
= 0;
784 memcpy(&cur_event
, &fields
[i
].event
,
787 if (!event_element_open
) {
788 /* Open and write the event */
789 ret
= mi_lttng_event(writer
, &cur_event
, 1,
790 handle
->domain
.type
);
795 /* Open a fields element */
796 ret
= mi_lttng_event_fields_open(writer
);
800 event_element_open
= 1;
804 /* Print the event_field */
805 ret
= mi_lttng_event_field(writer
, &fields
[i
]);
811 /* Close pid, domain, domains */
812 ret
= mi_lttng_close_multi_element(writer
, 3);
821 * Ask session daemon for all user space tracepoint fields available.
823 static int list_ust_event_fields(void)
825 int i
, size
, ret
= CMD_SUCCESS
;
826 struct lttng_domain domain
;
827 struct lttng_handle
*handle
;
828 struct lttng_event_field
*event_field_list
;
830 char *cmdline
= NULL
;
832 struct lttng_event cur_event
;
834 memset(&domain
, 0, sizeof(domain
));
835 memset(&cur_event
, 0, sizeof(cur_event
));
837 DBG("Getting UST tracing event fields");
839 domain
.type
= LTTNG_DOMAIN_UST
;
841 handle
= lttng_create_handle(NULL
, &domain
);
842 if (handle
== NULL
) {
847 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
849 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
856 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
863 MSG("UST events:\n-------------");
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
) {
877 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
879 /* Wipe current event since we are about to print a new PID. */
880 memset(&cur_event
, 0, sizeof(cur_event
));
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
,
887 print_event_field(&event_field_list
[i
]);
894 free(event_field_list
);
896 lttng_destroy_handle(handle
);
902 * Print a list of kernel events
904 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
905 struct lttng_domain
*domain
)
909 /* Open domains element */
910 ret
= mi_lttng_domains_open(writer
);
916 ret
= mi_lttng_domain(writer
, domain
, 1);
922 ret
= mi_lttng_events_open(writer
);
927 for (i
= 0; i
< count
; i
++) {
928 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
934 /* close events, domain and domains */
935 ret
= mi_lttng_close_multi_element(writer
, 3);
945 * Ask for all trace events in the kernel
947 static int list_kernel_events(void)
949 int i
, size
, ret
= CMD_SUCCESS
;
950 struct lttng_domain domain
;
951 struct lttng_handle
*handle
;
952 struct lttng_event
*event_list
;
954 memset(&domain
, 0, sizeof(domain
));
956 DBG("Getting kernel tracing events");
958 domain
.type
= LTTNG_DOMAIN_KERNEL
;
960 handle
= lttng_create_handle(NULL
, &domain
);
961 if (handle
== NULL
) {
966 size
= lttng_list_tracepoints(handle
, &event_list
);
968 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
969 lttng_destroy_handle(handle
);
975 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
981 MSG("Kernel events:\n-------------");
983 for (i
= 0; i
< size
; i
++) {
984 print_events(&event_list
[i
]);
993 lttng_destroy_handle(handle
);
997 lttng_destroy_handle(handle
);
1003 * Print a list of system calls.
1005 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1010 ret
= mi_lttng_events_open(writer
);
1015 for (i
= 0; i
< count
; i
++) {
1016 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1023 ret
= mi_lttng_writer_close_element(writer
);
1033 * Ask for kernel system calls.
1035 static int list_syscalls(void)
1037 int i
, size
, ret
= CMD_SUCCESS
;
1038 struct lttng_event
*event_list
;
1040 DBG("Getting kernel system call events");
1042 size
= lttng_list_syscalls(&event_list
);
1044 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1051 ret
= mi_list_syscalls(event_list
, size
);
1057 MSG("System calls:\n-------------");
1059 for (i
= 0; i
< size
; i
++) {
1060 print_events(&event_list
[i
]);
1076 * Print a list of agent events
1078 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1082 /* Open events element */
1083 ret
= mi_lttng_events_open(writer
);
1088 for (i
= 0; i
< count
; i
++) {
1089 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1095 /* Close events element */
1096 ret
= mi_lttng_writer_close_element(writer
);
1103 * List agent events for a specific session using the handle.
1105 * Return CMD_SUCCESS on success else a negative value.
1107 static int list_session_agent_events(void)
1109 int ret
= CMD_SUCCESS
, count
, i
;
1110 struct lttng_event
*events
= NULL
;
1112 count
= lttng_list_events(handle
, "", &events
);
1115 ERR("%s", lttng_strerror(count
));
1121 ret
= mi_list_session_agent_events(events
, count
);
1128 MSG("Events (Logger name):\n---------------------");
1130 MSG("%sNone\n", indent6
);
1134 for (i
= 0; i
< count
; i
++) {
1135 const char *filter_str
;
1136 char *filter_msg
= NULL
;
1137 struct lttng_event
*event
= &events
[i
];
1139 ret
= lttng_event_get_filter_expression(event
,
1142 filter_msg
= strdup(" [failed to retrieve filter]");
1143 } else if (filter_str
) {
1144 const char * const filter_fmt
=
1147 filter_msg
= malloc(strlen(filter_str
) +
1148 strlen(filter_fmt
) + 1);
1150 sprintf(filter_msg
, filter_fmt
,
1155 if (event
->loglevel_type
!=
1156 LTTNG_EVENT_LOGLEVEL_ALL
) {
1157 MSG("%s- %s%s (loglevel%s %s)%s", indent4
,
1159 enabled_string(event
->enabled
),
1160 logleveltype_string(
1161 event
->loglevel_type
),
1162 mi_lttng_loglevel_string(
1164 handle
->domain
.type
),
1165 safe_string(filter_msg
));
1167 MSG("%s- %s%s%s", indent4
, event
->name
,
1168 enabled_string(event
->enabled
),
1169 safe_string(filter_msg
));
1185 * print a list of event
1187 static int mi_list_events(struct lttng_event
*events
, int count
)
1191 /* Open events element */
1192 ret
= mi_lttng_events_open(writer
);
1197 for (i
= 0; i
< count
; i
++) {
1198 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1204 /* Close events element */
1205 ret
= mi_lttng_writer_close_element(writer
);
1212 * List events of channel of session and domain.
1214 static int list_events(const char *channel_name
)
1216 int ret
= CMD_SUCCESS
, count
, i
;
1217 struct lttng_event
*events
= NULL
;
1219 count
= lttng_list_events(handle
, channel_name
, &events
);
1222 ERR("%s", lttng_strerror(count
));
1228 ret
= mi_list_events(events
, count
);
1235 MSG("\n%sEvent rules:", indent4
);
1237 MSG("%sNone\n", indent6
);
1241 for (i
= 0; i
< count
; i
++) {
1242 print_events(&events
[i
]);
1254 void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1258 _MSG("%s%s:", indent6
, timer_name
);
1259 for (i
= 0; i
< space_count
; i
++) {
1264 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1271 * Pretty print channel
1273 static void print_channel(struct lttng_channel
*channel
)
1276 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1277 int64_t blocking_timeout
;
1279 ret
= lttng_channel_get_discarded_event_count(channel
,
1282 ERR("Failed to retrieve discarded event count of channel");
1286 ret
= lttng_channel_get_lost_packet_count(channel
,
1289 ERR("Failed to retrieve lost packet count of channel");
1293 ret
= lttng_channel_get_monitor_timer_interval(channel
,
1294 &monitor_timer_interval
);
1296 ERR("Failed to retrieve monitor interval of channel");
1300 ret
= lttng_channel_get_blocking_timeout(channel
,
1303 ERR("Failed to retrieve blocking timeout of channel");
1307 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1308 MSG("%sAttributes:", indent4
);
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
);
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
);
1317 if (!channel
->attr
.overwrite
) {
1318 if (blocking_timeout
== -1) {
1319 MSG("%sBlocking timeout: infinite", indent6
);
1321 MSG("%sBlocking timeout: %" PRId64
" %s", indent6
,
1322 blocking_timeout
, USEC_UNIT
);
1326 MSG("%sTrace file count: %" PRIu64
" per stream", indent6
,
1327 channel
->attr
.tracefile_count
== 0 ?
1328 1 : channel
->attr
.tracefile_count
);
1329 if (channel
->attr
.tracefile_size
!= 0 ) {
1330 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
,
1331 channel
->attr
.tracefile_size
);
1333 MSG("%sTrace file size: %s", indent6
, "unlimited");
1335 switch (channel
->attr
.output
) {
1336 case LTTNG_EVENT_SPLICE
:
1337 MSG("%sOutput mode: splice", indent6
);
1339 case LTTNG_EVENT_MMAP
:
1340 MSG("%sOutput mode: mmap", indent6
);
1344 MSG("\n%sStatistics:", indent4
);
1345 if (listed_session
.snapshot_mode
) {
1347 * The lost packet count is omitted for sessions in snapshot
1348 * mode as it is misleading: it would indicate the number of
1349 * packets that the consumer could not extract during the
1350 * course of recording the snapshot. It does not have the
1351 * same meaning as the "regular" lost packet count that
1352 * would result from the consumer not keeping up with
1353 * event production in an overwrite-mode channel.
1355 * A more interesting statistic would be the number of
1356 * packets lost between the first and last extracted
1357 * packets of a given snapshot (which prevents most analyses).
1359 MSG("%sNone", indent6
);
1360 goto skip_stats_printing
;
1363 if (!channel
->attr
.overwrite
) {
1364 MSG("%sDiscarded events: %" PRIu64
, indent6
, discarded_events
);
1366 MSG("%sLost packets: %" PRIu64
, indent6
, lost_packets
);
1368 skip_stats_printing
:
1374 * Print a list of channel
1377 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1378 const char *channel_name
)
1381 unsigned int chan_found
= 0;
1383 /* Open channels element */
1384 ret
= mi_lttng_channels_open(writer
);
1389 for (i
= 0; i
< count
; i
++) {
1390 if (channel_name
!= NULL
) {
1391 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1398 /* Write channel element and leave it open */
1399 ret
= mi_lttng_channel(writer
, &channels
[i
], 1);
1404 /* Listing events per channel */
1405 ret
= list_events(channels
[i
].name
);
1410 /* Closing the channel element we opened earlier */
1411 ret
= mi_lttng_writer_close_element(writer
);
1421 /* Close channels element */
1422 ret
= mi_lttng_writer_close_element(writer
);
1432 * List channel(s) of session and domain.
1434 * If channel_name is NULL, all channels are listed.
1436 static int list_channels(const char *channel_name
)
1438 int count
, i
, ret
= CMD_SUCCESS
;
1439 unsigned int chan_found
= 0;
1440 struct lttng_channel
*channels
= NULL
;
1442 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1444 count
= lttng_list_channels(handle
, &channels
);
1447 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1449 /* When printing mi this is not an error
1450 * but an empty channels element */
1454 WARN("No kernel channel");
1455 goto error_channels
;
1459 /* We had a real error */
1461 ERR("%s", lttng_strerror(count
));
1462 goto error_channels
;
1469 ret
= mi_list_channels(channels
, count
, channel_name
);
1477 MSG("Channels:\n-------------");
1480 for (i
= 0; i
< count
; i
++) {
1481 if (channel_name
!= NULL
) {
1482 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1488 print_channel(&channels
[i
]);
1490 /* Listing events per channel */
1491 ret
= list_events(channels
[i
].name
);
1501 if (!chan_found
&& channel_name
!= NULL
) {
1503 ERR("Channel %s not found", channel_name
);
1515 * List tracker PID(s) of session and domain.
1517 static int list_tracker_pids(void)
1524 ret
= lttng_list_tracker_pids(handle
,
1525 &enabled
, &pids
, &nr_pids
);
1531 _MSG("PID tracker: [");
1533 /* Mi tracker_pid element*/
1535 /* Open tracker_pid and targets elements */
1536 ret
= mi_lttng_pid_tracker_open(writer
);
1542 for (i
= 0; i
< nr_pids
; i
++) {
1546 _MSG(" %d", pids
[i
]);
1550 ret
= mi_lttng_pid_target(writer
, pids
[i
], 0);
1558 /* Mi close tracker_pid and targets */
1560 ret
= mi_lttng_close_multi_element(writer
,2);
1573 * List all tracker of a domain
1575 static int list_trackers(void)
1579 /* Trackers listing */
1581 ret
= mi_lttng_trackers_open(writer
);
1588 ret
= list_tracker_pids();
1594 /* Close trackers element */
1595 ret
= mi_lttng_writer_close_element(writer
);
1605 static enum cmd_error_code
print_periodic_rotation_schedule(
1606 const struct lttng_rotation_schedule
*schedule
)
1608 enum cmd_error_code ret
;
1609 enum lttng_rotation_status status
;
1612 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1614 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1615 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1620 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
1626 static enum cmd_error_code
print_size_threshold_rotation_schedule(
1627 const struct lttng_rotation_schedule
*schedule
)
1629 enum cmd_error_code ret
;
1630 enum lttng_rotation_status status
;
1633 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
1635 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1636 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1641 MSG(" size threshold: %" PRIu64
" bytes", value
);
1647 static enum cmd_error_code
print_rotation_schedule(
1648 const struct lttng_rotation_schedule
*schedule
)
1650 enum cmd_error_code ret
;
1652 switch (lttng_rotation_schedule_get_type(schedule
)) {
1653 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1654 ret
= print_size_threshold_rotation_schedule(schedule
);
1656 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1657 ret
= print_periodic_rotation_schedule(schedule
);
1666 * List the automatic rotation settings.
1668 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1671 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1672 unsigned int count
, i
;
1673 struct lttng_rotation_schedules
*schedules
= NULL
;
1674 enum lttng_rotation_status status
;
1676 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1677 if (ret
!= LTTNG_OK
) {
1678 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1679 cmd_ret
= CMD_ERROR
;
1683 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1684 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1685 ERR("Failed to retrieve the number of session rotation schedules.");
1686 cmd_ret
= CMD_ERROR
;
1691 cmd_ret
= CMD_SUCCESS
;
1695 MSG("Automatic rotation schedules:");
1697 ret
= mi_lttng_writer_open_element(writer
,
1698 mi_lttng_element_rotation_schedules
);
1700 cmd_ret
= CMD_ERROR
;
1705 for (i
= 0; i
< count
; i
++) {
1706 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1707 const struct lttng_rotation_schedule
*schedule
;
1709 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1711 ERR("Failed to retrieve session rotation schedule.");
1712 cmd_ret
= CMD_ERROR
;
1717 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
1719 tmp_ret
= CMD_ERROR
;
1722 tmp_ret
= print_rotation_schedule(schedule
);
1726 * Report an error if the serialization of any of the
1727 * descriptors failed.
1729 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
1734 /* Close the rotation_schedules element. */
1735 ret
= mi_lttng_writer_close_element(writer
);
1737 cmd_ret
= CMD_ERROR
;
1742 lttng_rotation_schedules_destroy(schedules
);
1748 * Find the session with session_name as name
1749 * and print his informations.
1751 static int mi_list_session(const char *session_name
,
1752 struct lttng_session
*sessions
, int count
)
1755 unsigned int session_found
= 0;
1757 if (session_name
== NULL
) {
1758 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1762 for (i
= 0; i
< count
; i
++) {
1763 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1764 /* We need to leave it open to append other informations
1765 * like domain, channel, events etc.*/
1767 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
1775 if (!session_found
) {
1776 ERR("Session '%s' not found", session_name
);
1777 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1787 * List all availables session
1789 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
1793 /* Opening sessions element */
1794 ret
= mi_lttng_sessions_open(writer
);
1799 /* Listing sessions */
1800 for (i
= 0; i
< count
; i
++) {
1801 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
1807 /* Closing sessions element */
1808 ret
= mi_lttng_writer_close_element(writer
);
1818 * List available tracing session. List only basic information.
1820 * If session_name is NULL, all sessions are listed.
1822 static int list_sessions(const char *session_name
)
1824 int ret
= CMD_SUCCESS
;
1826 unsigned int session_found
= 0;
1827 struct lttng_session
*sessions
;
1829 count
= lttng_list_sessions(&sessions
);
1830 DBG("Session count %d", count
);
1833 ERR("%s", lttng_strerror(count
));
1839 if (session_name
== NULL
) {
1840 /* List all session */
1841 ret
= mi_list_sessions(sessions
, count
);
1843 /* Note : this return an open session element */
1844 ret
= mi_list_session(session_name
, sessions
, count
);
1853 MSG("Currently no available tracing session");
1857 if (session_name
== NULL
) {
1858 MSG("Available tracing sessions:");
1862 for (i
= 0; i
< count
; i
++) {
1863 if (session_name
!= NULL
) {
1864 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1866 MSG("Tracing session %s: [%s%s]", session_name
,
1867 active_string(sessions
[i
].enabled
),
1868 snapshot_string(sessions
[i
].snapshot_mode
));
1869 MSG("%sTrace path: %s\n", indent4
, sessions
[i
].path
);
1870 memcpy(&listed_session
, &sessions
[i
],
1871 sizeof(listed_session
));
1875 MSG(" %d) %s (%s) [%s%s]", i
+ 1,
1876 sessions
[i
].name
, sessions
[i
].path
,
1877 active_string(sessions
[i
].enabled
),
1878 snapshot_string(sessions
[i
].snapshot_mode
));
1879 MSG("%sTrace path: %s", indent4
, sessions
[i
].path
);
1880 if (sessions
[i
].live_timer_interval
!= 0) {
1881 MSG("%sLive timer interval: %u µs", indent4
,
1882 sessions
[i
].live_timer_interval
);
1888 if (!session_found
&& session_name
!= NULL
) {
1889 ERR("Session '%s' not found", session_name
);
1894 if (session_name
== NULL
) {
1895 MSG("\nUse lttng list <session_name> for more details");
1908 * list available domain(s) for a session.
1910 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
1913 /* Open domains element */
1914 ret
= mi_lttng_domains_open(writer
);
1919 for (i
= 0; i
< count
; i
++) {
1920 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
1926 /* Closing domains element */
1927 ret
= mi_lttng_writer_close_element(writer
);
1936 * List available domain(s) for a session.
1938 static int list_domains(const char *session_name
)
1940 int i
, count
, ret
= CMD_SUCCESS
;
1941 struct lttng_domain
*domains
= NULL
;
1944 count
= lttng_list_domains(session_name
, &domains
);
1947 ERR("%s", lttng_strerror(count
));
1953 ret
= mi_list_domains(domains
, count
);
1960 MSG("Domains:\n-------------");
1966 for (i
= 0; i
< count
; i
++) {
1967 switch (domains
[i
].type
) {
1968 case LTTNG_DOMAIN_KERNEL
:
1971 case LTTNG_DOMAIN_UST
:
1972 MSG(" - UST global");
1974 case LTTNG_DOMAIN_JUL
:
1975 MSG(" - JUL (Java Util Logging)");
1977 case LTTNG_DOMAIN_LOG4J
:
1978 MSG(" - LOG4j (Logging for Java)");
1980 case LTTNG_DOMAIN_PYTHON
:
1981 MSG(" - Python (logging)");
1997 * The 'list <options>' first level command
1999 int cmd_list(int argc
, const char **argv
)
2001 int opt
, ret
= CMD_SUCCESS
;
2002 const char *session_name
, *leftover
= NULL
;
2003 static poptContext pc
;
2004 struct lttng_domain domain
;
2005 struct lttng_domain
*domains
= NULL
;
2007 memset(&domain
, 0, sizeof(domain
));
2014 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2015 poptReadDefaultConfig(pc
, 0);
2017 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2025 case OPT_LIST_OPTIONS
:
2026 list_cmd_options(stdout
, long_options
);
2029 ret
= CMD_UNDEFINED
;
2036 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
2042 /* Open command element */
2043 ret
= mi_lttng_writer_command_open(writer
,
2044 mi_lttng_element_command_list
);
2050 /* Open output element */
2051 ret
= mi_lttng_writer_open_element(writer
,
2052 mi_lttng_element_command_output
);
2059 /* Get session name (trailing argument) */
2060 session_name
= poptGetArg(pc
);
2061 DBG2("Session name: %s", session_name
);
2063 leftover
= poptGetArg(pc
);
2065 ERR("Unknown argument: %s", leftover
);
2071 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2072 } else if (opt_userspace
) {
2073 DBG2("Listing userspace global domain");
2074 domain
.type
= LTTNG_DOMAIN_UST
;
2075 } else if (opt_jul
) {
2076 DBG2("Listing JUL domain");
2077 domain
.type
= LTTNG_DOMAIN_JUL
;
2078 } else if (opt_log4j
) {
2079 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2080 } else if (opt_python
) {
2081 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2084 if (!opt_kernel
&& opt_syscall
) {
2085 WARN("--syscall will only work with the Kernel domain (-k)");
2090 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2091 handle
= lttng_create_handle(session_name
, &domain
);
2092 if (handle
== NULL
) {
2098 if (session_name
== NULL
) {
2099 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2101 ret
= list_sessions(NULL
);
2108 ret
= list_syscalls();
2113 ret
= list_kernel_events();
2119 if (opt_userspace
) {
2121 ret
= list_ust_event_fields();
2123 ret
= list_ust_events();
2129 if (opt_jul
|| opt_log4j
|| opt_python
) {
2130 ret
= list_agent_events();
2136 /* List session attributes */
2138 /* Open element sessions
2139 * Present for xml consistency */
2140 ret
= mi_lttng_sessions_open(writer
);
2145 /* MI: the ouptut of list_sessions is an unclosed session element */
2146 ret
= list_sessions(session_name
);
2151 ret
= list_rotate_settings(session_name
);
2156 /* Domain listing */
2158 ret
= list_domains(session_name
);
2162 /* Channel listing */
2163 if (opt_kernel
|| opt_userspace
) {
2165 /* Add of domains and domain element for xml
2166 * consistency and validation
2168 ret
= mi_lttng_domains_open(writer
);
2173 /* Open domain and leave it open for
2174 * nested channels printing */
2175 ret
= mi_lttng_domain(writer
, &domain
, 1);
2184 ret
= list_trackers();
2190 ret
= list_channels(opt_channel
);
2196 /* Close domain and domain element */
2197 ret
= mi_lttng_close_multi_element(writer
, 2);
2207 /* We want all domain(s) */
2208 nb_domain
= lttng_list_domains(session_name
, &domains
);
2209 if (nb_domain
< 0) {
2211 ERR("%s", lttng_strerror(nb_domain
));
2216 ret
= mi_lttng_domains_open(writer
);
2223 for (i
= 0; i
< nb_domain
; i
++) {
2224 switch (domains
[i
].type
) {
2225 case LTTNG_DOMAIN_KERNEL
:
2226 MSG("=== Domain: Kernel ===\n");
2228 case LTTNG_DOMAIN_UST
:
2229 MSG("=== Domain: UST global ===\n");
2230 MSG("Buffer type: %s\n",
2231 domains
[i
].buf_type
==
2232 LTTNG_BUFFER_PER_PID
? "per PID" : "per UID");
2234 case LTTNG_DOMAIN_JUL
:
2235 MSG("=== Domain: JUL (Java Util Logging) ===\n");
2237 case LTTNG_DOMAIN_LOG4J
:
2238 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
2240 case LTTNG_DOMAIN_PYTHON
:
2241 MSG("=== Domain: Python (logging) ===\n");
2244 MSG("=== Domain: Unimplemented ===\n");
2249 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
2256 /* Clean handle before creating a new one */
2258 lttng_destroy_handle(handle
);
2261 handle
= lttng_create_handle(session_name
, &domains
[i
]);
2262 if (handle
== NULL
) {
2267 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2268 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2269 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2270 ret
= list_session_agent_events();
2278 switch (domains
[i
].type
) {
2279 case LTTNG_DOMAIN_KERNEL
:
2280 case LTTNG_DOMAIN_UST
:
2281 ret
= list_trackers();
2290 ret
= list_channels(opt_channel
);
2297 /* Close domain element */
2298 ret
= mi_lttng_writer_close_element(writer
);
2307 /* Close the domains, session and sessions element */
2308 ret
= mi_lttng_close_multi_element(writer
, 3);
2319 /* Close output element */
2320 ret
= mi_lttng_writer_close_element(writer
);
2326 /* Command element close */
2327 ret
= mi_lttng_writer_command_close(writer
);
2335 if (writer
&& mi_lttng_writer_destroy(writer
)) {
2336 /* Preserve original error code */
2337 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2342 lttng_destroy_handle(handle
);
2345 poptFreeContext(pc
);