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 <common/time.h>
28 #include <lttng/constant.h>
30 #include "../command.h"
32 static int opt_userspace
;
33 static int opt_kernel
;
36 static int opt_python
;
37 static char *opt_channel
;
38 static int opt_domain
;
39 static int opt_fields
;
40 static int opt_syscall
;
42 const char *indent4
= " ";
43 const char *indent6
= " ";
44 const char *indent8
= " ";
46 #ifdef LTTNG_EMBED_HELP
47 static const char help_msg
[] =
48 #include <lttng-list.1.h>
58 static struct lttng_handle
*handle
;
59 static struct mi_writer
*writer
;
61 /* Only set when listing a single session. */
62 static struct lttng_session listed_session
;
64 static struct poptOption long_options
[] = {
65 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
66 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
67 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
68 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
69 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
70 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
71 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
72 {"channel", 'c', POPT_ARG_STRING
, &opt_channel
, 0, 0, 0},
73 {"domain", 'd', POPT_ARG_VAL
, &opt_domain
, 1, 0, 0},
74 {"fields", 'f', POPT_ARG_VAL
, &opt_fields
, 1, 0, 0},
75 {"syscall", 'S', POPT_ARG_VAL
, &opt_syscall
, 1, 0, 0},
76 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
81 * Get command line from /proc for a specific pid.
83 * On success, return an allocated string pointer to the proc cmdline.
84 * On error, return NULL.
86 static char *get_cmdline_by_pid(pid_t pid
)
91 /* Can't go bigger than /proc/LTTNG_MAX_PID/cmdline */
92 char path
[sizeof("/proc//cmdline") + sizeof(LTTNG_MAX_PID_STR
) - 1];
94 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pid
);
95 fp
= fopen(path
, "r");
100 /* Caller must free() *cmdline */
101 cmdline
= zmalloc(PATH_MAX
);
103 PERROR("malloc cmdline");
106 ret
= fread(cmdline
, 1, PATH_MAX
, fp
);
108 PERROR("fread proc list");
119 const char *active_string(int value
)
122 case 0: return "inactive";
123 case 1: return "active";
125 default: return NULL
;
129 static const char *snapshot_string(int value
)
140 const char *enabled_string(int value
)
143 case 0: return " [disabled]";
144 case 1: return " [enabled]";
146 default: return NULL
;
151 const char *safe_string(const char *str
)
153 return str
? str
: "";
156 static const char *logleveltype_string(enum lttng_loglevel_type value
)
159 case LTTNG_EVENT_LOGLEVEL_ALL
:
161 case LTTNG_EVENT_LOGLEVEL_RANGE
:
163 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
166 return " <<TYPE UNKN>>";
170 static const char *bitness_event(enum lttng_event_flag flags
)
172 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_32
) {
173 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
174 return " [32/64-bit]";
178 } else if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
186 * Get exclusion names message for a single event.
188 * Returned pointer must be freed by caller. Returns NULL on error.
190 static char *get_exclusion_names_msg(struct lttng_event
*event
)
194 char *exclusion_msg
= NULL
;
197 const char * const exclusion_fmt
= " [exclusions: ";
198 const size_t exclusion_fmt_len
= strlen(exclusion_fmt
);
200 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
201 if (exclusion_count
< 0) {
203 } else if (exclusion_count
== 0) {
205 * No exclusions: return copy of empty string so that
206 * it can be freed by caller.
208 exclusion_msg
= strdup("");
213 * exclusion_msg's size is bounded by the exclusion_fmt string,
214 * a comma per entry, the entry count (fixed-size), a closing
215 * bracket, and a trailing \0.
217 exclusion_msg
= malloc(exclusion_count
+
218 exclusion_count
* LTTNG_SYMBOL_NAME_LEN
+
219 exclusion_fmt_len
+ 1);
220 if (!exclusion_msg
) {
224 at
= strcpy(exclusion_msg
, exclusion_fmt
) + exclusion_fmt_len
;
225 for (i
= 0; i
< exclusion_count
; ++i
) {
228 /* Append comma between exclusion names */
234 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
236 /* Prints '?' on local error; should never happen */
242 /* Append exclusion name */
243 at
+= sprintf(at
, "%s", name
);
246 /* This also puts a final '\0' at the end of exclusion_msg */
250 return exclusion_msg
;
253 static void print_userspace_probe_location(struct lttng_event
*event
)
255 const struct lttng_userspace_probe_location
*location
;
256 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
257 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
259 location
= lttng_event_get_userspace_probe_location(event
);
261 MSG("Event has no userspace probe location");
265 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
266 if (!lookup_method
) {
267 MSG("Event has no userspace probe location lookup method");
271 MSG("%s%s (type: userspace-probe)%s", indent6
, event
->name
, enabled_string(event
->enabled
));
273 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
275 switch (lttng_userspace_probe_location_get_type(location
)) {
276 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
:
277 MSG("%sType: Unknown", indent8
);
279 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
281 const char *function_name
;
284 MSG("%sType: Function", indent8
);
285 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
286 binary_path
= realpath(lttng_userspace_probe_location_function_get_binary_path(location
), NULL
);
288 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
289 MSG("%sFunction: %s()", indent8
, function_name
? function_name
: "NULL");
290 switch (lookup_type
) {
291 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
292 MSG("%sLookup method: ELF", indent8
);
294 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
295 MSG("%sLookup method: default", indent8
);
298 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
305 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
307 const char *probe_name
, *provider_name
;
310 MSG("%sType: Tracepoint", indent8
);
311 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
312 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
313 binary_path
= realpath(lttng_userspace_probe_location_tracepoint_get_binary_path(location
), NULL
);
314 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
315 MSG("%sTracepoint: %s:%s", indent8
, provider_name
? provider_name
: "NULL", probe_name
? probe_name
: "NULL");
316 switch (lookup_type
) {
317 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
318 MSG("%sLookup method: SDT", indent8
);
321 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
329 ERR("Invalid probe type encountered");
334 * Pretty print single event.
336 static void print_events(struct lttng_event
*event
)
339 const char *filter_str
;
340 char *filter_msg
= NULL
;
341 char *exclusion_msg
= NULL
;
343 ret
= lttng_event_get_filter_expression(event
, &filter_str
);
346 filter_msg
= strdup(" [failed to retrieve filter]");
347 } else if (filter_str
) {
348 const char * const filter_fmt
= " [filter: '%s']";
350 filter_msg
= malloc(strlen(filter_str
) +
351 strlen(filter_fmt
) + 1);
353 sprintf(filter_msg
, filter_fmt
,
358 exclusion_msg
= get_exclusion_names_msg(event
);
359 if (!exclusion_msg
) {
360 exclusion_msg
= strdup(" [failed to retrieve exclusions]");
363 switch (event
->type
) {
364 case LTTNG_EVENT_TRACEPOINT
:
366 if (event
->loglevel
!= -1) {
367 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
370 logleveltype_string(event
->loglevel_type
),
371 mi_lttng_loglevel_string(event
->loglevel
, handle
->domain
.type
),
373 enabled_string(event
->enabled
),
374 safe_string(exclusion_msg
),
375 safe_string(filter_msg
));
377 MSG("%s%s (type: tracepoint)%s%s%s",
380 enabled_string(event
->enabled
),
381 safe_string(exclusion_msg
),
382 safe_string(filter_msg
));
386 case LTTNG_EVENT_FUNCTION
:
387 MSG("%s%s (type: function)%s%s", indent6
,
388 event
->name
, enabled_string(event
->enabled
),
389 safe_string(filter_msg
));
390 if (event
->attr
.probe
.addr
!= 0) {
391 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
393 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
394 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
397 case LTTNG_EVENT_PROBE
:
398 MSG("%s%s (type: probe)%s%s", indent6
,
399 event
->name
, enabled_string(event
->enabled
),
400 safe_string(filter_msg
));
401 if (event
->attr
.probe
.addr
!= 0) {
402 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
404 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
405 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
408 case LTTNG_EVENT_USERSPACE_PROBE
:
409 print_userspace_probe_location(event
);
411 case LTTNG_EVENT_FUNCTION_ENTRY
:
412 MSG("%s%s (type: function)%s%s", indent6
,
413 event
->name
, enabled_string(event
->enabled
),
414 safe_string(filter_msg
));
415 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
417 case LTTNG_EVENT_SYSCALL
:
418 MSG("%s%s%s%s%s%s", indent6
, event
->name
,
419 (opt_syscall
? "" : " (type:syscall)"),
420 enabled_string(event
->enabled
),
421 bitness_event(event
->flags
),
422 safe_string(filter_msg
));
424 case LTTNG_EVENT_NOOP
:
425 MSG("%s (type: noop)%s%s", indent6
,
426 enabled_string(event
->enabled
),
427 safe_string(filter_msg
));
429 case LTTNG_EVENT_ALL
:
432 /* We should never have "all" events in list. */
441 static const char *field_type(struct lttng_event_field
*field
)
443 switch(field
->type
) {
444 case LTTNG_EVENT_FIELD_INTEGER
:
446 case LTTNG_EVENT_FIELD_ENUM
:
448 case LTTNG_EVENT_FIELD_FLOAT
:
450 case LTTNG_EVENT_FIELD_STRING
:
452 case LTTNG_EVENT_FIELD_OTHER
:
453 default: /* fall-through */
459 * Pretty print single event fields.
461 static void print_event_field(struct lttng_event_field
*field
)
463 if (!field
->field_name
[0]) {
466 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
467 field_type(field
), field
->nowrite
? " [no write]" : "");
472 * Jul and ust event listing
474 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
475 struct lttng_domain
*domain
)
479 char *cmdline
= NULL
;
480 int pid_element_open
= 0;
482 /* Open domains element */
483 ret
= mi_lttng_domains_open(writer
);
489 ret
= mi_lttng_domain(writer
, domain
, 1);
494 /* Open pids element element */
495 ret
= mi_lttng_pids_open(writer
);
500 for (i
= 0; i
< count
; i
++) {
501 if (cur_pid
!= events
[i
].pid
) {
502 if (pid_element_open
) {
503 /* Close the previous events and pid element */
504 ret
= mi_lttng_close_multi_element(writer
, 2);
508 pid_element_open
= 0;
511 cur_pid
= events
[i
].pid
;
512 cmdline
= get_cmdline_by_pid(cur_pid
);
518 if (!pid_element_open
) {
519 /* Open and write a pid element */
520 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
525 /* Open events element */
526 ret
= mi_lttng_events_open(writer
);
531 pid_element_open
= 1;
537 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
544 ret
= mi_lttng_writer_close_element(writer
);
549 /* Close domain, domains */
550 ret
= mi_lttng_close_multi_element(writer
, 2);
558 static int list_agent_events(void)
560 int i
, size
, ret
= CMD_SUCCESS
;
561 struct lttng_domain domain
;
562 struct lttng_handle
*handle
= NULL
;
563 struct lttng_event
*event_list
= NULL
;
565 char *cmdline
= NULL
;
566 const char *agent_domain_str
;
568 memset(&domain
, 0, sizeof(domain
));
570 domain
.type
= LTTNG_DOMAIN_JUL
;
571 } else if (opt_log4j
) {
572 domain
.type
= LTTNG_DOMAIN_LOG4J
;
573 } else if (opt_python
) {
574 domain
.type
= LTTNG_DOMAIN_PYTHON
;
576 ERR("Invalid agent domain selected.");
581 agent_domain_str
= get_domain_str(domain
.type
);
583 DBG("Getting %s tracing events", agent_domain_str
);
585 handle
= lttng_create_handle(NULL
, &domain
);
586 if (handle
== NULL
) {
591 size
= lttng_list_tracepoints(handle
, &event_list
);
593 ERR("Unable to list %s events: %s", agent_domain_str
,
594 lttng_strerror(size
));
601 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
608 MSG("%s events (Logger name):\n-------------------------",
615 for (i
= 0; i
< size
; i
++) {
616 if (cur_pid
!= event_list
[i
].pid
) {
617 cur_pid
= event_list
[i
].pid
;
618 cmdline
= get_cmdline_by_pid(cur_pid
);
619 if (cmdline
== NULL
) {
623 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
626 MSG("%s- %s", indent6
, event_list
[i
].name
);
635 lttng_destroy_handle(handle
);
640 * Ask session daemon for all user space tracepoints available.
642 static int list_ust_events(void)
644 int i
, size
, ret
= CMD_SUCCESS
;
645 struct lttng_domain domain
;
646 struct lttng_handle
*handle
;
647 struct lttng_event
*event_list
= NULL
;
649 char *cmdline
= NULL
;
651 memset(&domain
, 0, sizeof(domain
));
653 DBG("Getting UST tracing events");
655 domain
.type
= LTTNG_DOMAIN_UST
;
657 handle
= lttng_create_handle(NULL
, &domain
);
658 if (handle
== NULL
) {
663 size
= lttng_list_tracepoints(handle
, &event_list
);
665 ERR("Unable to list UST events: %s", lttng_strerror(size
));
672 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
675 MSG("UST events:\n-------------");
681 for (i
= 0; i
< size
; i
++) {
682 if (cur_pid
!= event_list
[i
].pid
) {
683 cur_pid
= event_list
[i
].pid
;
684 cmdline
= get_cmdline_by_pid(cur_pid
);
685 if (cmdline
== NULL
) {
689 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
692 print_events(&event_list
[i
]);
701 lttng_destroy_handle(handle
);
707 * List all ust event with their fields
709 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
710 struct lttng_domain
*domain
)
714 char *cmdline
= NULL
;
715 int pid_element_open
= 0;
716 int event_element_open
= 0;
717 struct lttng_event cur_event
;
719 memset(&cur_event
, 0, sizeof(cur_event
));
721 /* Open domains element */
722 ret
= mi_lttng_domains_open(writer
);
728 ret
= mi_lttng_domain(writer
, domain
, 1);
733 /* Open pids element */
734 ret
= mi_lttng_pids_open(writer
);
739 for (i
= 0; i
< count
; i
++) {
740 if (cur_pid
!= fields
[i
].event
.pid
) {
741 if (pid_element_open
) {
742 if (event_element_open
) {
743 /* Close the previous field element and event. */
744 ret
= mi_lttng_close_multi_element(writer
, 2);
748 event_element_open
= 0;
750 /* Close the previous events, pid element */
751 ret
= mi_lttng_close_multi_element(writer
, 2);
755 pid_element_open
= 0;
758 cur_pid
= fields
[i
].event
.pid
;
759 cmdline
= get_cmdline_by_pid(cur_pid
);
760 if (!pid_element_open
) {
761 /* Open and write a pid element */
762 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
767 /* Open events element */
768 ret
= mi_lttng_events_open(writer
);
772 pid_element_open
= 1;
775 /* Wipe current event since we are about to print a new PID. */
776 memset(&cur_event
, 0, sizeof(cur_event
));
779 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
780 if (event_element_open
) {
781 /* Close the previous fields element and the previous event */
782 ret
= mi_lttng_close_multi_element(writer
, 2);
786 event_element_open
= 0;
789 memcpy(&cur_event
, &fields
[i
].event
,
792 if (!event_element_open
) {
793 /* Open and write the event */
794 ret
= mi_lttng_event(writer
, &cur_event
, 1,
795 handle
->domain
.type
);
800 /* Open a fields element */
801 ret
= mi_lttng_event_fields_open(writer
);
805 event_element_open
= 1;
809 /* Print the event_field */
810 ret
= mi_lttng_event_field(writer
, &fields
[i
]);
816 /* Close pid, domain, domains */
817 ret
= mi_lttng_close_multi_element(writer
, 3);
826 * Ask session daemon for all user space tracepoint fields available.
828 static int list_ust_event_fields(void)
830 int i
, size
, ret
= CMD_SUCCESS
;
831 struct lttng_domain domain
;
832 struct lttng_handle
*handle
;
833 struct lttng_event_field
*event_field_list
;
835 char *cmdline
= NULL
;
837 struct lttng_event cur_event
;
839 memset(&domain
, 0, sizeof(domain
));
840 memset(&cur_event
, 0, sizeof(cur_event
));
842 DBG("Getting UST tracing event fields");
844 domain
.type
= LTTNG_DOMAIN_UST
;
846 handle
= lttng_create_handle(NULL
, &domain
);
847 if (handle
== NULL
) {
852 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
854 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
861 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
868 MSG("UST events:\n-------------");
874 for (i
= 0; i
< size
; i
++) {
875 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
876 cur_pid
= event_field_list
[i
].event
.pid
;
877 cmdline
= get_cmdline_by_pid(cur_pid
);
878 if (cmdline
== NULL
) {
882 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
884 /* Wipe current event since we are about to print a new PID. */
885 memset(&cur_event
, 0, sizeof(cur_event
));
887 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
888 print_events(&event_field_list
[i
].event
);
889 memcpy(&cur_event
, &event_field_list
[i
].event
,
892 print_event_field(&event_field_list
[i
]);
899 free(event_field_list
);
901 lttng_destroy_handle(handle
);
907 * Print a list of kernel events
909 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
910 struct lttng_domain
*domain
)
914 /* Open domains element */
915 ret
= mi_lttng_domains_open(writer
);
921 ret
= mi_lttng_domain(writer
, domain
, 1);
927 ret
= mi_lttng_events_open(writer
);
932 for (i
= 0; i
< count
; i
++) {
933 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
939 /* close events, domain and domains */
940 ret
= mi_lttng_close_multi_element(writer
, 3);
950 * Ask for all trace events in the kernel
952 static int list_kernel_events(void)
954 int i
, size
, ret
= CMD_SUCCESS
;
955 struct lttng_domain domain
;
956 struct lttng_handle
*handle
;
957 struct lttng_event
*event_list
;
959 memset(&domain
, 0, sizeof(domain
));
961 DBG("Getting kernel tracing events");
963 domain
.type
= LTTNG_DOMAIN_KERNEL
;
965 handle
= lttng_create_handle(NULL
, &domain
);
966 if (handle
== NULL
) {
971 size
= lttng_list_tracepoints(handle
, &event_list
);
973 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
974 lttng_destroy_handle(handle
);
980 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
986 MSG("Kernel events:\n-------------");
988 for (i
= 0; i
< size
; i
++) {
989 print_events(&event_list
[i
]);
998 lttng_destroy_handle(handle
);
1002 lttng_destroy_handle(handle
);
1008 * Print a list of system calls.
1010 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1015 ret
= mi_lttng_events_open(writer
);
1020 for (i
= 0; i
< count
; i
++) {
1021 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1028 ret
= mi_lttng_writer_close_element(writer
);
1038 * Ask for kernel system calls.
1040 static int list_syscalls(void)
1042 int i
, size
, ret
= CMD_SUCCESS
;
1043 struct lttng_event
*event_list
;
1045 DBG("Getting kernel system call events");
1047 size
= lttng_list_syscalls(&event_list
);
1049 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1056 ret
= mi_list_syscalls(event_list
, size
);
1062 MSG("System calls:\n-------------");
1064 for (i
= 0; i
< size
; i
++) {
1065 print_events(&event_list
[i
]);
1081 * Print a list of agent events
1083 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1087 /* Open events element */
1088 ret
= mi_lttng_events_open(writer
);
1093 for (i
= 0; i
< count
; i
++) {
1094 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1100 /* Close events element */
1101 ret
= mi_lttng_writer_close_element(writer
);
1108 * List agent events for a specific session using the handle.
1110 * Return CMD_SUCCESS on success else a negative value.
1112 static int list_session_agent_events(void)
1114 int ret
= CMD_SUCCESS
, count
, i
;
1115 struct lttng_event
*events
= NULL
;
1117 count
= lttng_list_events(handle
, "", &events
);
1120 ERR("%s", lttng_strerror(count
));
1126 ret
= mi_list_session_agent_events(events
, count
);
1133 MSG("Events (Logger name):\n---------------------");
1135 MSG("%sNone\n", indent6
);
1139 for (i
= 0; i
< count
; i
++) {
1140 const char *filter_str
;
1141 char *filter_msg
= NULL
;
1142 struct lttng_event
*event
= &events
[i
];
1144 ret
= lttng_event_get_filter_expression(event
,
1147 filter_msg
= strdup(" [failed to retrieve filter]");
1148 } else if (filter_str
) {
1149 const char * const filter_fmt
=
1152 filter_msg
= malloc(strlen(filter_str
) +
1153 strlen(filter_fmt
) + 1);
1155 sprintf(filter_msg
, filter_fmt
,
1160 if (event
->loglevel_type
!=
1161 LTTNG_EVENT_LOGLEVEL_ALL
) {
1162 MSG("%s- %s%s (loglevel%s %s)%s", indent4
,
1164 enabled_string(event
->enabled
),
1165 logleveltype_string(
1166 event
->loglevel_type
),
1167 mi_lttng_loglevel_string(
1169 handle
->domain
.type
),
1170 safe_string(filter_msg
));
1172 MSG("%s- %s%s%s", indent4
, event
->name
,
1173 enabled_string(event
->enabled
),
1174 safe_string(filter_msg
));
1190 * print a list of event
1192 static int mi_list_events(struct lttng_event
*events
, int count
)
1196 /* Open events element */
1197 ret
= mi_lttng_events_open(writer
);
1202 for (i
= 0; i
< count
; i
++) {
1203 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1209 /* Close events element */
1210 ret
= mi_lttng_writer_close_element(writer
);
1217 * List events of channel of session and domain.
1219 static int list_events(const char *channel_name
)
1221 int ret
= CMD_SUCCESS
, count
, i
;
1222 struct lttng_event
*events
= NULL
;
1224 count
= lttng_list_events(handle
, channel_name
, &events
);
1227 ERR("%s", lttng_strerror(count
));
1233 ret
= mi_list_events(events
, count
);
1240 MSG("\n%sEvent rules:", indent4
);
1242 MSG("%sNone\n", indent6
);
1246 for (i
= 0; i
< count
; i
++) {
1247 print_events(&events
[i
]);
1259 void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1263 _MSG("%s%s:", indent6
, timer_name
);
1264 for (i
= 0; i
< space_count
; i
++) {
1269 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1276 * Pretty print channel
1278 static void print_channel(struct lttng_channel
*channel
)
1281 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1282 int64_t blocking_timeout
;
1284 ret
= lttng_channel_get_discarded_event_count(channel
,
1287 ERR("Failed to retrieve discarded event count of channel");
1291 ret
= lttng_channel_get_lost_packet_count(channel
,
1294 ERR("Failed to retrieve lost packet count of channel");
1298 ret
= lttng_channel_get_monitor_timer_interval(channel
,
1299 &monitor_timer_interval
);
1301 ERR("Failed to retrieve monitor interval of channel");
1305 ret
= lttng_channel_get_blocking_timeout(channel
,
1308 ERR("Failed to retrieve blocking timeout of channel");
1312 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1313 MSG("%sAttributes:", indent4
);
1314 MSG("%sEvent-loss mode: %s", indent6
, channel
->attr
.overwrite
? "overwrite" : "discard");
1315 MSG("%sSub-buffer size: %" PRIu64
" bytes", indent6
, channel
->attr
.subbuf_size
);
1316 MSG("%sSub-buffer count: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1318 print_timer("Switch timer", 5, channel
->attr
.switch_timer_interval
);
1319 print_timer("Read timer", 7, channel
->attr
.read_timer_interval
);
1320 print_timer("Monitor timer", 4, monitor_timer_interval
);
1322 if (!channel
->attr
.overwrite
) {
1323 if (blocking_timeout
== -1) {
1324 MSG("%sBlocking timeout: infinite", indent6
);
1326 MSG("%sBlocking timeout: %" PRId64
" %s", indent6
,
1327 blocking_timeout
, USEC_UNIT
);
1331 MSG("%sTrace file count: %" PRIu64
" per stream", indent6
,
1332 channel
->attr
.tracefile_count
== 0 ?
1333 1 : channel
->attr
.tracefile_count
);
1334 if (channel
->attr
.tracefile_size
!= 0 ) {
1335 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
,
1336 channel
->attr
.tracefile_size
);
1338 MSG("%sTrace file size: %s", indent6
, "unlimited");
1340 switch (channel
->attr
.output
) {
1341 case LTTNG_EVENT_SPLICE
:
1342 MSG("%sOutput mode: splice", indent6
);
1344 case LTTNG_EVENT_MMAP
:
1345 MSG("%sOutput mode: mmap", indent6
);
1349 MSG("\n%sStatistics:", indent4
);
1350 if (listed_session
.snapshot_mode
) {
1352 * The lost packet count is omitted for sessions in snapshot
1353 * mode as it is misleading: it would indicate the number of
1354 * packets that the consumer could not extract during the
1355 * course of recording the snapshot. It does not have the
1356 * same meaning as the "regular" lost packet count that
1357 * would result from the consumer not keeping up with
1358 * event production in an overwrite-mode channel.
1360 * A more interesting statistic would be the number of
1361 * packets lost between the first and last extracted
1362 * packets of a given snapshot (which prevents most analyses).
1364 MSG("%sNone", indent6
);
1365 goto skip_stats_printing
;
1368 if (!channel
->attr
.overwrite
) {
1369 MSG("%sDiscarded events: %" PRIu64
, indent6
, discarded_events
);
1371 MSG("%sLost packets: %" PRIu64
, indent6
, lost_packets
);
1373 skip_stats_printing
:
1379 * Print a list of channel
1382 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1383 const char *channel_name
)
1386 unsigned int chan_found
= 0;
1388 /* Open channels element */
1389 ret
= mi_lttng_channels_open(writer
);
1394 for (i
= 0; i
< count
; i
++) {
1395 if (channel_name
!= NULL
) {
1396 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1403 /* Write channel element and leave it open */
1404 ret
= mi_lttng_channel(writer
, &channels
[i
], 1);
1409 /* Listing events per channel */
1410 ret
= list_events(channels
[i
].name
);
1415 /* Closing the channel element we opened earlier */
1416 ret
= mi_lttng_writer_close_element(writer
);
1426 /* Close channels element */
1427 ret
= mi_lttng_writer_close_element(writer
);
1437 * List channel(s) of session and domain.
1439 * If channel_name is NULL, all channels are listed.
1441 static int list_channels(const char *channel_name
)
1443 int count
, i
, ret
= CMD_SUCCESS
;
1444 unsigned int chan_found
= 0;
1445 struct lttng_channel
*channels
= NULL
;
1447 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1449 count
= lttng_list_channels(handle
, &channels
);
1452 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1454 /* When printing mi this is not an error
1455 * but an empty channels element */
1459 goto error_channels
;
1463 /* We had a real error */
1465 ERR("%s", lttng_strerror(count
));
1466 goto error_channels
;
1473 ret
= mi_list_channels(channels
, count
, channel_name
);
1481 MSG("Channels:\n-------------");
1484 for (i
= 0; i
< count
; i
++) {
1485 if (channel_name
!= NULL
) {
1486 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1492 print_channel(&channels
[i
]);
1494 /* Listing events per channel */
1495 ret
= list_events(channels
[i
].name
);
1505 if (!chan_found
&& channel_name
!= NULL
) {
1507 ERR("Channel %s not found", channel_name
);
1519 * List tracker PID(s) of session and domain.
1521 static int list_tracker_pids(void)
1528 ret
= lttng_list_tracker_pids(handle
,
1529 &enabled
, &pids
, &nr_pids
);
1535 _MSG("PID tracker: [");
1537 /* Mi tracker_pid element*/
1539 /* Open tracker_pid and targets elements */
1540 ret
= mi_lttng_pid_tracker_open(writer
);
1546 for (i
= 0; i
< nr_pids
; i
++) {
1550 _MSG(" %d", pids
[i
]);
1554 ret
= mi_lttng_pid_target(writer
, pids
[i
], 0);
1562 /* Mi close tracker_pid and targets */
1564 ret
= mi_lttng_close_multi_element(writer
,2);
1577 * List all tracker of a domain
1579 static int list_trackers(void)
1583 /* Trackers listing */
1585 ret
= mi_lttng_trackers_open(writer
);
1592 ret
= list_tracker_pids();
1598 /* Close trackers element */
1599 ret
= mi_lttng_writer_close_element(writer
);
1609 static enum cmd_error_code
print_periodic_rotation_schedule(
1610 const struct lttng_rotation_schedule
*schedule
)
1612 enum cmd_error_code ret
;
1613 enum lttng_rotation_status status
;
1616 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1618 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1619 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1624 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
1630 static enum cmd_error_code
print_size_threshold_rotation_schedule(
1631 const struct lttng_rotation_schedule
*schedule
)
1633 enum cmd_error_code ret
;
1634 enum lttng_rotation_status status
;
1637 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
1639 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1640 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1645 MSG(" size threshold: %" PRIu64
" bytes", value
);
1651 static enum cmd_error_code
print_rotation_schedule(
1652 const struct lttng_rotation_schedule
*schedule
)
1654 enum cmd_error_code ret
;
1656 switch (lttng_rotation_schedule_get_type(schedule
)) {
1657 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1658 ret
= print_size_threshold_rotation_schedule(schedule
);
1660 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1661 ret
= print_periodic_rotation_schedule(schedule
);
1670 * List the automatic rotation settings.
1672 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1675 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1676 unsigned int count
, i
;
1677 struct lttng_rotation_schedules
*schedules
= NULL
;
1678 enum lttng_rotation_status status
;
1680 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1681 if (ret
!= LTTNG_OK
) {
1682 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1683 cmd_ret
= CMD_ERROR
;
1687 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1688 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1689 ERR("Failed to retrieve the number of session rotation schedules.");
1690 cmd_ret
= CMD_ERROR
;
1695 cmd_ret
= CMD_SUCCESS
;
1699 MSG("Automatic rotation schedules:");
1701 ret
= mi_lttng_writer_open_element(writer
,
1702 mi_lttng_element_rotation_schedules
);
1704 cmd_ret
= CMD_ERROR
;
1709 for (i
= 0; i
< count
; i
++) {
1710 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1711 const struct lttng_rotation_schedule
*schedule
;
1713 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1715 ERR("Failed to retrieve session rotation schedule.");
1716 cmd_ret
= CMD_ERROR
;
1721 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
1723 tmp_ret
= CMD_ERROR
;
1726 tmp_ret
= print_rotation_schedule(schedule
);
1730 * Report an error if the serialization of any of the
1731 * descriptors failed.
1733 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
1738 /* Close the rotation_schedules element. */
1739 ret
= mi_lttng_writer_close_element(writer
);
1741 cmd_ret
= CMD_ERROR
;
1746 lttng_rotation_schedules_destroy(schedules
);
1752 * Find the session with session_name as name
1753 * and print his informations.
1755 static int mi_list_session(const char *session_name
,
1756 struct lttng_session
*sessions
, int count
)
1759 unsigned int session_found
= 0;
1761 if (session_name
== NULL
) {
1762 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1766 for (i
= 0; i
< count
; i
++) {
1767 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1768 /* We need to leave it open to append other informations
1769 * like domain, channel, events etc.*/
1771 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
1779 if (!session_found
) {
1780 ERR("Session '%s' not found", session_name
);
1781 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1791 * List all availables session
1793 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
1797 /* Opening sessions element */
1798 ret
= mi_lttng_sessions_open(writer
);
1803 /* Listing sessions */
1804 for (i
= 0; i
< count
; i
++) {
1805 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
1811 /* Closing sessions element */
1812 ret
= mi_lttng_writer_close_element(writer
);
1822 * List available tracing session. List only basic information.
1824 * If session_name is NULL, all sessions are listed.
1826 static int list_sessions(const char *session_name
)
1828 int ret
= CMD_SUCCESS
;
1830 unsigned int session_found
= 0;
1831 struct lttng_session
*sessions
= NULL
;
1833 count
= lttng_list_sessions(&sessions
);
1834 DBG("Session count %d", count
);
1837 ERR("%s", lttng_strerror(count
));
1843 if (session_name
== NULL
) {
1844 /* List all sessions */
1845 ret
= mi_list_sessions(sessions
, count
);
1847 /* Note : this return an open session element */
1848 ret
= mi_list_session(session_name
, sessions
, count
);
1857 MSG("Currently no available tracing session");
1861 if (session_name
== NULL
) {
1862 MSG("Available tracing sessions:");
1865 for (i
= 0; i
< count
; i
++) {
1866 if (session_name
!= NULL
) {
1867 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1869 MSG("Tracing session %s: [%s%s]", session_name
,
1870 active_string(sessions
[i
].enabled
),
1871 snapshot_string(sessions
[i
].snapshot_mode
));
1872 if (*sessions
[i
].path
) {
1873 MSG("%sTrace output: %s\n", indent4
, sessions
[i
].path
);
1875 memcpy(&listed_session
, &sessions
[i
],
1876 sizeof(listed_session
));
1880 MSG(" %d) %s [%s%s]", i
+ 1,
1882 active_string(sessions
[i
].enabled
),
1883 snapshot_string(sessions
[i
].snapshot_mode
));
1884 if (*sessions
[i
].path
) {
1885 MSG("%sTrace output: %s", indent4
, sessions
[i
].path
);
1887 if (sessions
[i
].live_timer_interval
!= 0) {
1888 MSG("%sLive timer interval: %u %s", indent4
,
1889 sessions
[i
].live_timer_interval
,
1896 if (!session_found
&& session_name
!= NULL
) {
1897 ERR("Session '%s' not found", session_name
);
1902 if (session_name
== NULL
) {
1903 MSG("\nUse lttng list <session_name> for more details");
1915 * list available domain(s) for a session.
1917 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
1920 /* Open domains element */
1921 ret
= mi_lttng_domains_open(writer
);
1926 for (i
= 0; i
< count
; i
++) {
1927 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
1933 /* Closing domains element */
1934 ret
= mi_lttng_writer_close_element(writer
);
1943 * List available domain(s) for a session.
1945 static int list_domains(const char *session_name
)
1947 int i
, count
, ret
= CMD_SUCCESS
;
1948 struct lttng_domain
*domains
= NULL
;
1951 count
= lttng_list_domains(session_name
, &domains
);
1954 ERR("%s", lttng_strerror(count
));
1960 ret
= mi_list_domains(domains
, count
);
1967 MSG("Domains:\n-------------");
1973 for (i
= 0; i
< count
; i
++) {
1974 switch (domains
[i
].type
) {
1975 case LTTNG_DOMAIN_KERNEL
:
1978 case LTTNG_DOMAIN_UST
:
1979 MSG(" - UST global");
1981 case LTTNG_DOMAIN_JUL
:
1982 MSG(" - JUL (Java Util Logging)");
1984 case LTTNG_DOMAIN_LOG4J
:
1985 MSG(" - LOG4j (Logging for Java)");
1987 case LTTNG_DOMAIN_PYTHON
:
1988 MSG(" - Python (logging)");
2004 * The 'list <options>' first level command
2006 int cmd_list(int argc
, const char **argv
)
2008 int opt
, ret
= CMD_SUCCESS
;
2009 const char *session_name
, *leftover
= NULL
;
2010 static poptContext pc
;
2011 struct lttng_domain domain
;
2012 struct lttng_domain
*domains
= NULL
;
2014 memset(&domain
, 0, sizeof(domain
));
2021 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2022 poptReadDefaultConfig(pc
, 0);
2024 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2032 case OPT_LIST_OPTIONS
:
2033 list_cmd_options(stdout
, long_options
);
2036 ret
= CMD_UNDEFINED
;
2043 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
2049 /* Open command element */
2050 ret
= mi_lttng_writer_command_open(writer
,
2051 mi_lttng_element_command_list
);
2057 /* Open output element */
2058 ret
= mi_lttng_writer_open_element(writer
,
2059 mi_lttng_element_command_output
);
2066 /* Get session name (trailing argument) */
2067 session_name
= poptGetArg(pc
);
2068 DBG2("Session name: %s", session_name
);
2070 leftover
= poptGetArg(pc
);
2072 ERR("Unknown argument: %s", leftover
);
2078 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2079 } else if (opt_userspace
) {
2080 DBG2("Listing userspace global domain");
2081 domain
.type
= LTTNG_DOMAIN_UST
;
2082 } else if (opt_jul
) {
2083 DBG2("Listing JUL domain");
2084 domain
.type
= LTTNG_DOMAIN_JUL
;
2085 } else if (opt_log4j
) {
2086 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2087 } else if (opt_python
) {
2088 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2091 if (!opt_kernel
&& opt_syscall
) {
2092 WARN("--syscall will only work with the Kernel domain (-k)");
2097 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2098 handle
= lttng_create_handle(session_name
, &domain
);
2099 if (handle
== NULL
) {
2105 if (session_name
== NULL
) {
2106 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2108 ret
= list_sessions(NULL
);
2115 ret
= list_syscalls();
2120 ret
= list_kernel_events();
2126 if (opt_userspace
) {
2128 ret
= list_ust_event_fields();
2130 ret
= list_ust_events();
2136 if (opt_jul
|| opt_log4j
|| opt_python
) {
2137 ret
= list_agent_events();
2143 /* List session attributes */
2145 /* Open element sessions
2146 * Present for xml consistency */
2147 ret
= mi_lttng_sessions_open(writer
);
2152 /* MI: the ouptut of list_sessions is an unclosed session element */
2153 ret
= list_sessions(session_name
);
2158 ret
= list_rotate_settings(session_name
);
2163 /* Domain listing */
2165 ret
= list_domains(session_name
);
2169 /* Channel listing */
2170 if (opt_kernel
|| opt_userspace
) {
2172 /* Add of domains and domain element for xml
2173 * consistency and validation
2175 ret
= mi_lttng_domains_open(writer
);
2180 /* Open domain and leave it open for
2181 * nested channels printing */
2182 ret
= mi_lttng_domain(writer
, &domain
, 1);
2191 ret
= list_trackers();
2197 ret
= list_channels(opt_channel
);
2203 /* Close domain and domain element */
2204 ret
= mi_lttng_close_multi_element(writer
, 2);
2214 /* We want all domain(s) */
2215 nb_domain
= lttng_list_domains(session_name
, &domains
);
2216 if (nb_domain
< 0) {
2218 ERR("%s", lttng_strerror(nb_domain
));
2223 ret
= mi_lttng_domains_open(writer
);
2230 for (i
= 0; i
< nb_domain
; i
++) {
2231 switch (domains
[i
].type
) {
2232 case LTTNG_DOMAIN_KERNEL
:
2233 MSG("=== Domain: Kernel ===\n");
2235 case LTTNG_DOMAIN_UST
:
2236 MSG("=== Domain: UST global ===\n");
2237 MSG("Buffer type: %s\n",
2238 domains
[i
].buf_type
==
2239 LTTNG_BUFFER_PER_PID
? "per PID" : "per UID");
2241 case LTTNG_DOMAIN_JUL
:
2242 MSG("=== Domain: JUL (Java Util Logging) ===\n");
2244 case LTTNG_DOMAIN_LOG4J
:
2245 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
2247 case LTTNG_DOMAIN_PYTHON
:
2248 MSG("=== Domain: Python (logging) ===\n");
2251 MSG("=== Domain: Unimplemented ===\n");
2256 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
2263 /* Clean handle before creating a new one */
2265 lttng_destroy_handle(handle
);
2268 handle
= lttng_create_handle(session_name
, &domains
[i
]);
2269 if (handle
== NULL
) {
2274 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2275 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2276 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2277 ret
= list_session_agent_events();
2285 switch (domains
[i
].type
) {
2286 case LTTNG_DOMAIN_KERNEL
:
2287 case LTTNG_DOMAIN_UST
:
2288 ret
= list_trackers();
2297 ret
= list_channels(opt_channel
);
2304 /* Close domain element */
2305 ret
= mi_lttng_writer_close_element(writer
);
2314 /* Close the domains, session and sessions element */
2315 ret
= mi_lttng_close_multi_element(writer
, 3);
2326 /* Close output element */
2327 ret
= mi_lttng_writer_close_element(writer
);
2333 /* Command element close */
2334 ret
= mi_lttng_writer_command_close(writer
);
2342 if (writer
&& mi_lttng_writer_destroy(writer
)) {
2343 /* Preserve original error code */
2344 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2349 lttng_destroy_handle(handle
);
2352 poptFreeContext(pc
);