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
;
282 const char *binary_path
;
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
);
303 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
305 const char *probe_name
, *provider_name
;
306 const char *binary_path
;
308 MSG("%sType: Tracepoint", indent8
);
309 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
310 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
311 binary_path
= realpath(lttng_userspace_probe_location_tracepoint_get_binary_path(location
), NULL
);
312 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
313 MSG("%sTracepoint: %s:%s", indent8
, provider_name
? provider_name
: "NULL", probe_name
? probe_name
: "NULL");
314 switch (lookup_type
) {
315 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
316 MSG("%sLookup method: SDT", indent8
);
319 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
325 ERR("Invalid probe type encountered");
330 * Pretty print single event.
332 static void print_events(struct lttng_event
*event
)
335 const char *filter_str
;
336 char *filter_msg
= NULL
;
337 char *exclusion_msg
= NULL
;
339 ret
= lttng_event_get_filter_expression(event
, &filter_str
);
342 filter_msg
= strdup(" [failed to retrieve filter]");
343 } else if (filter_str
) {
344 const char * const filter_fmt
= " [filter: '%s']";
346 filter_msg
= malloc(strlen(filter_str
) +
347 strlen(filter_fmt
) + 1);
349 sprintf(filter_msg
, filter_fmt
,
354 exclusion_msg
= get_exclusion_names_msg(event
);
355 if (!exclusion_msg
) {
356 exclusion_msg
= strdup(" [failed to retrieve exclusions]");
359 switch (event
->type
) {
360 case LTTNG_EVENT_TRACEPOINT
:
362 if (event
->loglevel
!= -1) {
363 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
366 logleveltype_string(event
->loglevel_type
),
367 mi_lttng_loglevel_string(event
->loglevel
, handle
->domain
.type
),
369 enabled_string(event
->enabled
),
370 safe_string(exclusion_msg
),
371 safe_string(filter_msg
));
373 MSG("%s%s (type: tracepoint)%s%s%s",
376 enabled_string(event
->enabled
),
377 safe_string(exclusion_msg
),
378 safe_string(filter_msg
));
382 case LTTNG_EVENT_FUNCTION
:
383 MSG("%s%s (type: function)%s%s", indent6
,
384 event
->name
, enabled_string(event
->enabled
),
385 safe_string(filter_msg
));
386 if (event
->attr
.probe
.addr
!= 0) {
387 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
389 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
390 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
393 case LTTNG_EVENT_PROBE
:
394 MSG("%s%s (type: probe)%s%s", indent6
,
395 event
->name
, enabled_string(event
->enabled
),
396 safe_string(filter_msg
));
397 if (event
->attr
.probe
.addr
!= 0) {
398 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
400 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
401 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
404 case LTTNG_EVENT_USERSPACE_PROBE
:
405 print_userspace_probe_location(event
);
407 case LTTNG_EVENT_FUNCTION_ENTRY
:
408 MSG("%s%s (type: function)%s%s", indent6
,
409 event
->name
, enabled_string(event
->enabled
),
410 safe_string(filter_msg
));
411 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
413 case LTTNG_EVENT_SYSCALL
:
414 MSG("%s%s%s%s%s%s", indent6
, event
->name
,
415 (opt_syscall
? "" : " (type:syscall)"),
416 enabled_string(event
->enabled
),
417 bitness_event(event
->flags
),
418 safe_string(filter_msg
));
420 case LTTNG_EVENT_NOOP
:
421 MSG("%s (type: noop)%s%s", indent6
,
422 enabled_string(event
->enabled
),
423 safe_string(filter_msg
));
425 case LTTNG_EVENT_ALL
:
428 /* We should never have "all" events in list. */
437 static const char *field_type(struct lttng_event_field
*field
)
439 switch(field
->type
) {
440 case LTTNG_EVENT_FIELD_INTEGER
:
442 case LTTNG_EVENT_FIELD_ENUM
:
444 case LTTNG_EVENT_FIELD_FLOAT
:
446 case LTTNG_EVENT_FIELD_STRING
:
448 case LTTNG_EVENT_FIELD_OTHER
:
449 default: /* fall-through */
455 * Pretty print single event fields.
457 static void print_event_field(struct lttng_event_field
*field
)
459 if (!field
->field_name
[0]) {
462 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
463 field_type(field
), field
->nowrite
? " [no write]" : "");
468 * Jul and ust event listing
470 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
471 struct lttng_domain
*domain
)
475 char *cmdline
= NULL
;
476 int pid_element_open
= 0;
478 /* Open domains element */
479 ret
= mi_lttng_domains_open(writer
);
485 ret
= mi_lttng_domain(writer
, domain
, 1);
490 /* Open pids element element */
491 ret
= mi_lttng_pids_open(writer
);
496 for (i
= 0; i
< count
; i
++) {
497 if (cur_pid
!= events
[i
].pid
) {
498 if (pid_element_open
) {
499 /* Close the previous events and pid element */
500 ret
= mi_lttng_close_multi_element(writer
, 2);
504 pid_element_open
= 0;
507 cur_pid
= events
[i
].pid
;
508 cmdline
= get_cmdline_by_pid(cur_pid
);
514 if (!pid_element_open
) {
515 /* Open and write a pid element */
516 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
521 /* Open events element */
522 ret
= mi_lttng_events_open(writer
);
527 pid_element_open
= 1;
533 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
540 ret
= mi_lttng_writer_close_element(writer
);
545 /* Close domain, domains */
546 ret
= mi_lttng_close_multi_element(writer
, 2);
554 static int list_agent_events(void)
556 int i
, size
, ret
= CMD_SUCCESS
;
557 struct lttng_domain domain
;
558 struct lttng_handle
*handle
= NULL
;
559 struct lttng_event
*event_list
= NULL
;
561 char *cmdline
= NULL
;
562 const char *agent_domain_str
;
564 memset(&domain
, 0, sizeof(domain
));
566 domain
.type
= LTTNG_DOMAIN_JUL
;
567 } else if (opt_log4j
) {
568 domain
.type
= LTTNG_DOMAIN_LOG4J
;
569 } else if (opt_python
) {
570 domain
.type
= LTTNG_DOMAIN_PYTHON
;
572 ERR("Invalid agent domain selected.");
577 agent_domain_str
= get_domain_str(domain
.type
);
579 DBG("Getting %s tracing events", agent_domain_str
);
581 handle
= lttng_create_handle(NULL
, &domain
);
582 if (handle
== NULL
) {
587 size
= lttng_list_tracepoints(handle
, &event_list
);
589 ERR("Unable to list %s events: %s", agent_domain_str
,
590 lttng_strerror(size
));
597 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
604 MSG("%s events (Logger name):\n-------------------------",
611 for (i
= 0; i
< size
; i
++) {
612 if (cur_pid
!= event_list
[i
].pid
) {
613 cur_pid
= event_list
[i
].pid
;
614 cmdline
= get_cmdline_by_pid(cur_pid
);
615 if (cmdline
== NULL
) {
619 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
622 MSG("%s- %s", indent6
, event_list
[i
].name
);
631 lttng_destroy_handle(handle
);
636 * Ask session daemon for all user space tracepoints available.
638 static int list_ust_events(void)
640 int i
, size
, ret
= CMD_SUCCESS
;
641 struct lttng_domain domain
;
642 struct lttng_handle
*handle
;
643 struct lttng_event
*event_list
= NULL
;
645 char *cmdline
= NULL
;
647 memset(&domain
, 0, sizeof(domain
));
649 DBG("Getting UST tracing events");
651 domain
.type
= LTTNG_DOMAIN_UST
;
653 handle
= lttng_create_handle(NULL
, &domain
);
654 if (handle
== NULL
) {
659 size
= lttng_list_tracepoints(handle
, &event_list
);
661 ERR("Unable to list UST events: %s", lttng_strerror(size
));
668 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
671 MSG("UST events:\n-------------");
677 for (i
= 0; i
< size
; i
++) {
678 if (cur_pid
!= event_list
[i
].pid
) {
679 cur_pid
= event_list
[i
].pid
;
680 cmdline
= get_cmdline_by_pid(cur_pid
);
681 if (cmdline
== NULL
) {
685 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
688 print_events(&event_list
[i
]);
697 lttng_destroy_handle(handle
);
703 * List all ust event with their fields
705 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
706 struct lttng_domain
*domain
)
710 char *cmdline
= NULL
;
711 int pid_element_open
= 0;
712 int event_element_open
= 0;
713 struct lttng_event cur_event
;
715 memset(&cur_event
, 0, sizeof(cur_event
));
717 /* Open domains element */
718 ret
= mi_lttng_domains_open(writer
);
724 ret
= mi_lttng_domain(writer
, domain
, 1);
729 /* Open pids element */
730 ret
= mi_lttng_pids_open(writer
);
735 for (i
= 0; i
< count
; i
++) {
736 if (cur_pid
!= fields
[i
].event
.pid
) {
737 if (pid_element_open
) {
738 if (event_element_open
) {
739 /* Close the previous field element and event. */
740 ret
= mi_lttng_close_multi_element(writer
, 2);
744 event_element_open
= 0;
746 /* Close the previous events, pid element */
747 ret
= mi_lttng_close_multi_element(writer
, 2);
751 pid_element_open
= 0;
754 cur_pid
= fields
[i
].event
.pid
;
755 cmdline
= get_cmdline_by_pid(cur_pid
);
756 if (!pid_element_open
) {
757 /* Open and write a pid element */
758 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
763 /* Open events element */
764 ret
= mi_lttng_events_open(writer
);
768 pid_element_open
= 1;
771 /* Wipe current event since we are about to print a new PID. */
772 memset(&cur_event
, 0, sizeof(cur_event
));
775 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
776 if (event_element_open
) {
777 /* Close the previous fields element and the previous event */
778 ret
= mi_lttng_close_multi_element(writer
, 2);
782 event_element_open
= 0;
785 memcpy(&cur_event
, &fields
[i
].event
,
788 if (!event_element_open
) {
789 /* Open and write the event */
790 ret
= mi_lttng_event(writer
, &cur_event
, 1,
791 handle
->domain
.type
);
796 /* Open a fields element */
797 ret
= mi_lttng_event_fields_open(writer
);
801 event_element_open
= 1;
805 /* Print the event_field */
806 ret
= mi_lttng_event_field(writer
, &fields
[i
]);
812 /* Close pid, domain, domains */
813 ret
= mi_lttng_close_multi_element(writer
, 3);
822 * Ask session daemon for all user space tracepoint fields available.
824 static int list_ust_event_fields(void)
826 int i
, size
, ret
= CMD_SUCCESS
;
827 struct lttng_domain domain
;
828 struct lttng_handle
*handle
;
829 struct lttng_event_field
*event_field_list
;
831 char *cmdline
= NULL
;
833 struct lttng_event cur_event
;
835 memset(&domain
, 0, sizeof(domain
));
836 memset(&cur_event
, 0, sizeof(cur_event
));
838 DBG("Getting UST tracing event fields");
840 domain
.type
= LTTNG_DOMAIN_UST
;
842 handle
= lttng_create_handle(NULL
, &domain
);
843 if (handle
== NULL
) {
848 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
850 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
857 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
864 MSG("UST events:\n-------------");
870 for (i
= 0; i
< size
; i
++) {
871 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
872 cur_pid
= event_field_list
[i
].event
.pid
;
873 cmdline
= get_cmdline_by_pid(cur_pid
);
874 if (cmdline
== NULL
) {
878 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
880 /* Wipe current event since we are about to print a new PID. */
881 memset(&cur_event
, 0, sizeof(cur_event
));
883 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
884 print_events(&event_field_list
[i
].event
);
885 memcpy(&cur_event
, &event_field_list
[i
].event
,
888 print_event_field(&event_field_list
[i
]);
895 free(event_field_list
);
897 lttng_destroy_handle(handle
);
903 * Print a list of kernel events
905 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
906 struct lttng_domain
*domain
)
910 /* Open domains element */
911 ret
= mi_lttng_domains_open(writer
);
917 ret
= mi_lttng_domain(writer
, domain
, 1);
923 ret
= mi_lttng_events_open(writer
);
928 for (i
= 0; i
< count
; i
++) {
929 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
935 /* close events, domain and domains */
936 ret
= mi_lttng_close_multi_element(writer
, 3);
946 * Ask for all trace events in the kernel
948 static int list_kernel_events(void)
950 int i
, size
, ret
= CMD_SUCCESS
;
951 struct lttng_domain domain
;
952 struct lttng_handle
*handle
;
953 struct lttng_event
*event_list
;
955 memset(&domain
, 0, sizeof(domain
));
957 DBG("Getting kernel tracing events");
959 domain
.type
= LTTNG_DOMAIN_KERNEL
;
961 handle
= lttng_create_handle(NULL
, &domain
);
962 if (handle
== NULL
) {
967 size
= lttng_list_tracepoints(handle
, &event_list
);
969 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
970 lttng_destroy_handle(handle
);
976 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
982 MSG("Kernel events:\n-------------");
984 for (i
= 0; i
< size
; i
++) {
985 print_events(&event_list
[i
]);
994 lttng_destroy_handle(handle
);
998 lttng_destroy_handle(handle
);
1004 * Print a list of system calls.
1006 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1011 ret
= mi_lttng_events_open(writer
);
1016 for (i
= 0; i
< count
; i
++) {
1017 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1024 ret
= mi_lttng_writer_close_element(writer
);
1034 * Ask for kernel system calls.
1036 static int list_syscalls(void)
1038 int i
, size
, ret
= CMD_SUCCESS
;
1039 struct lttng_event
*event_list
;
1041 DBG("Getting kernel system call events");
1043 size
= lttng_list_syscalls(&event_list
);
1045 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1052 ret
= mi_list_syscalls(event_list
, size
);
1058 MSG("System calls:\n-------------");
1060 for (i
= 0; i
< size
; i
++) {
1061 print_events(&event_list
[i
]);
1077 * Print a list of agent events
1079 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1083 /* Open events element */
1084 ret
= mi_lttng_events_open(writer
);
1089 for (i
= 0; i
< count
; i
++) {
1090 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1096 /* Close events element */
1097 ret
= mi_lttng_writer_close_element(writer
);
1104 * List agent events for a specific session using the handle.
1106 * Return CMD_SUCCESS on success else a negative value.
1108 static int list_session_agent_events(void)
1110 int ret
= CMD_SUCCESS
, count
, i
;
1111 struct lttng_event
*events
= NULL
;
1113 count
= lttng_list_events(handle
, "", &events
);
1116 ERR("%s", lttng_strerror(count
));
1122 ret
= mi_list_session_agent_events(events
, count
);
1129 MSG("Events (Logger name):\n---------------------");
1131 MSG("%sNone\n", indent6
);
1135 for (i
= 0; i
< count
; i
++) {
1136 const char *filter_str
;
1137 char *filter_msg
= NULL
;
1138 struct lttng_event
*event
= &events
[i
];
1140 ret
= lttng_event_get_filter_expression(event
,
1143 filter_msg
= strdup(" [failed to retrieve filter]");
1144 } else if (filter_str
) {
1145 const char * const filter_fmt
=
1148 filter_msg
= malloc(strlen(filter_str
) +
1149 strlen(filter_fmt
) + 1);
1151 sprintf(filter_msg
, filter_fmt
,
1156 if (event
->loglevel_type
!=
1157 LTTNG_EVENT_LOGLEVEL_ALL
) {
1158 MSG("%s- %s%s (loglevel%s %s)%s", indent4
,
1160 enabled_string(event
->enabled
),
1161 logleveltype_string(
1162 event
->loglevel_type
),
1163 mi_lttng_loglevel_string(
1165 handle
->domain
.type
),
1166 safe_string(filter_msg
));
1168 MSG("%s- %s%s%s", indent4
, event
->name
,
1169 enabled_string(event
->enabled
),
1170 safe_string(filter_msg
));
1186 * print a list of event
1188 static int mi_list_events(struct lttng_event
*events
, int count
)
1192 /* Open events element */
1193 ret
= mi_lttng_events_open(writer
);
1198 for (i
= 0; i
< count
; i
++) {
1199 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1205 /* Close events element */
1206 ret
= mi_lttng_writer_close_element(writer
);
1213 * List events of channel of session and domain.
1215 static int list_events(const char *channel_name
)
1217 int ret
= CMD_SUCCESS
, count
, i
;
1218 struct lttng_event
*events
= NULL
;
1220 count
= lttng_list_events(handle
, channel_name
, &events
);
1223 ERR("%s", lttng_strerror(count
));
1229 ret
= mi_list_events(events
, count
);
1236 MSG("\n%sEvent rules:", indent4
);
1238 MSG("%sNone\n", indent6
);
1242 for (i
= 0; i
< count
; i
++) {
1243 print_events(&events
[i
]);
1255 void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1259 _MSG("%s%s:", indent6
, timer_name
);
1260 for (i
= 0; i
< space_count
; i
++) {
1265 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1272 * Pretty print channel
1274 static void print_channel(struct lttng_channel
*channel
)
1277 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1278 int64_t blocking_timeout
;
1280 ret
= lttng_channel_get_discarded_event_count(channel
,
1283 ERR("Failed to retrieve discarded event count of channel");
1287 ret
= lttng_channel_get_lost_packet_count(channel
,
1290 ERR("Failed to retrieve lost packet count of channel");
1294 ret
= lttng_channel_get_monitor_timer_interval(channel
,
1295 &monitor_timer_interval
);
1297 ERR("Failed to retrieve monitor interval of channel");
1301 ret
= lttng_channel_get_blocking_timeout(channel
,
1304 ERR("Failed to retrieve blocking timeout of channel");
1308 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1309 MSG("%sAttributes:", indent4
);
1310 MSG("%sEvent-loss mode: %s", indent6
, channel
->attr
.overwrite
? "overwrite" : "discard");
1311 MSG("%sSub-buffer size: %" PRIu64
" bytes", indent6
, channel
->attr
.subbuf_size
);
1312 MSG("%sSub-buffer count: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1314 print_timer("Switch timer", 5, channel
->attr
.switch_timer_interval
);
1315 print_timer("Read timer", 7, channel
->attr
.read_timer_interval
);
1316 print_timer("Monitor timer", 4, monitor_timer_interval
);
1318 if (!channel
->attr
.overwrite
) {
1319 if (blocking_timeout
== -1) {
1320 MSG("%sBlocking timeout: infinite", indent6
);
1322 MSG("%sBlocking timeout: %" PRId64
" %s", indent6
,
1323 blocking_timeout
, USEC_UNIT
);
1327 MSG("%sTrace file count: %" PRIu64
" per stream", indent6
,
1328 channel
->attr
.tracefile_count
== 0 ?
1329 1 : channel
->attr
.tracefile_count
);
1330 if (channel
->attr
.tracefile_size
!= 0 ) {
1331 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
,
1332 channel
->attr
.tracefile_size
);
1334 MSG("%sTrace file size: %s", indent6
, "unlimited");
1336 switch (channel
->attr
.output
) {
1337 case LTTNG_EVENT_SPLICE
:
1338 MSG("%sOutput mode: splice", indent6
);
1340 case LTTNG_EVENT_MMAP
:
1341 MSG("%sOutput mode: mmap", indent6
);
1345 MSG("\n%sStatistics:", indent4
);
1346 if (listed_session
.snapshot_mode
) {
1348 * The lost packet count is omitted for sessions in snapshot
1349 * mode as it is misleading: it would indicate the number of
1350 * packets that the consumer could not extract during the
1351 * course of recording the snapshot. It does not have the
1352 * same meaning as the "regular" lost packet count that
1353 * would result from the consumer not keeping up with
1354 * event production in an overwrite-mode channel.
1356 * A more interesting statistic would be the number of
1357 * packets lost between the first and last extracted
1358 * packets of a given snapshot (which prevents most analyses).
1360 MSG("%sNone", indent6
);
1361 goto skip_stats_printing
;
1364 if (!channel
->attr
.overwrite
) {
1365 MSG("%sDiscarded events: %" PRIu64
, indent6
, discarded_events
);
1367 MSG("%sLost packets: %" PRIu64
, indent6
, lost_packets
);
1369 skip_stats_printing
:
1375 * Print a list of channel
1378 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1379 const char *channel_name
)
1382 unsigned int chan_found
= 0;
1384 /* Open channels element */
1385 ret
= mi_lttng_channels_open(writer
);
1390 for (i
= 0; i
< count
; i
++) {
1391 if (channel_name
!= NULL
) {
1392 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1399 /* Write channel element and leave it open */
1400 ret
= mi_lttng_channel(writer
, &channels
[i
], 1);
1405 /* Listing events per channel */
1406 ret
= list_events(channels
[i
].name
);
1411 /* Closing the channel element we opened earlier */
1412 ret
= mi_lttng_writer_close_element(writer
);
1422 /* Close channels element */
1423 ret
= mi_lttng_writer_close_element(writer
);
1433 * List channel(s) of session and domain.
1435 * If channel_name is NULL, all channels are listed.
1437 static int list_channels(const char *channel_name
)
1439 int count
, i
, ret
= CMD_SUCCESS
;
1440 unsigned int chan_found
= 0;
1441 struct lttng_channel
*channels
= NULL
;
1443 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1445 count
= lttng_list_channels(handle
, &channels
);
1448 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1450 /* When printing mi this is not an error
1451 * but an empty channels element */
1455 WARN("No kernel channel");
1456 goto error_channels
;
1460 /* We had a real error */
1462 ERR("%s", lttng_strerror(count
));
1463 goto error_channels
;
1470 ret
= mi_list_channels(channels
, count
, channel_name
);
1478 MSG("Channels:\n-------------");
1481 for (i
= 0; i
< count
; i
++) {
1482 if (channel_name
!= NULL
) {
1483 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1489 print_channel(&channels
[i
]);
1491 /* Listing events per channel */
1492 ret
= list_events(channels
[i
].name
);
1502 if (!chan_found
&& channel_name
!= NULL
) {
1504 ERR("Channel %s not found", channel_name
);
1516 * List tracker PID(s) of session and domain.
1518 static int list_tracker_pids(void)
1525 ret
= lttng_list_tracker_pids(handle
,
1526 &enabled
, &pids
, &nr_pids
);
1532 _MSG("PID tracker: [");
1534 /* Mi tracker_pid element*/
1536 /* Open tracker_pid and targets elements */
1537 ret
= mi_lttng_pid_tracker_open(writer
);
1543 for (i
= 0; i
< nr_pids
; i
++) {
1547 _MSG(" %d", pids
[i
]);
1551 ret
= mi_lttng_pid_target(writer
, pids
[i
], 0);
1559 /* Mi close tracker_pid and targets */
1561 ret
= mi_lttng_close_multi_element(writer
,2);
1574 * List all tracker of a domain
1576 static int list_trackers(void)
1580 /* Trackers listing */
1582 ret
= mi_lttng_trackers_open(writer
);
1589 ret
= list_tracker_pids();
1595 /* Close trackers element */
1596 ret
= mi_lttng_writer_close_element(writer
);
1606 static enum cmd_error_code
print_periodic_rotation_schedule(
1607 const struct lttng_rotation_schedule
*schedule
)
1609 enum cmd_error_code ret
;
1610 enum lttng_rotation_status status
;
1613 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1615 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1616 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1621 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
1627 static enum cmd_error_code
print_size_threshold_rotation_schedule(
1628 const struct lttng_rotation_schedule
*schedule
)
1630 enum cmd_error_code ret
;
1631 enum lttng_rotation_status status
;
1634 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
1636 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1637 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1642 MSG(" size threshold: %" PRIu64
" bytes", value
);
1648 static enum cmd_error_code
print_rotation_schedule(
1649 const struct lttng_rotation_schedule
*schedule
)
1651 enum cmd_error_code ret
;
1653 switch (lttng_rotation_schedule_get_type(schedule
)) {
1654 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1655 ret
= print_size_threshold_rotation_schedule(schedule
);
1657 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1658 ret
= print_periodic_rotation_schedule(schedule
);
1667 * List the automatic rotation settings.
1669 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1672 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1673 unsigned int count
, i
;
1674 struct lttng_rotation_schedules
*schedules
= NULL
;
1675 enum lttng_rotation_status status
;
1677 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1678 if (ret
!= LTTNG_OK
) {
1679 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1680 cmd_ret
= CMD_ERROR
;
1684 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1685 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1686 ERR("Failed to retrieve the number of session rotation schedules.");
1687 cmd_ret
= CMD_ERROR
;
1692 cmd_ret
= CMD_SUCCESS
;
1696 MSG("Automatic rotation schedules:");
1698 ret
= mi_lttng_writer_open_element(writer
,
1699 mi_lttng_element_rotation_schedules
);
1701 cmd_ret
= CMD_ERROR
;
1706 for (i
= 0; i
< count
; i
++) {
1707 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1708 const struct lttng_rotation_schedule
*schedule
;
1710 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1712 ERR("Failed to retrieve session rotation schedule.");
1713 cmd_ret
= CMD_ERROR
;
1718 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
1720 tmp_ret
= CMD_ERROR
;
1723 tmp_ret
= print_rotation_schedule(schedule
);
1727 * Report an error if the serialization of any of the
1728 * descriptors failed.
1730 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
1735 /* Close the rotation_schedules element. */
1736 ret
= mi_lttng_writer_close_element(writer
);
1738 cmd_ret
= CMD_ERROR
;
1743 lttng_rotation_schedules_destroy(schedules
);
1749 * Find the session with session_name as name
1750 * and print his informations.
1752 static int mi_list_session(const char *session_name
,
1753 struct lttng_session
*sessions
, int count
)
1756 unsigned int session_found
= 0;
1758 if (session_name
== NULL
) {
1759 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1763 for (i
= 0; i
< count
; i
++) {
1764 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1765 /* We need to leave it open to append other informations
1766 * like domain, channel, events etc.*/
1768 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
1776 if (!session_found
) {
1777 ERR("Session '%s' not found", session_name
);
1778 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1788 * List all availables session
1790 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
1794 /* Opening sessions element */
1795 ret
= mi_lttng_sessions_open(writer
);
1800 /* Listing sessions */
1801 for (i
= 0; i
< count
; i
++) {
1802 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
1808 /* Closing sessions element */
1809 ret
= mi_lttng_writer_close_element(writer
);
1819 * List available tracing session. List only basic information.
1821 * If session_name is NULL, all sessions are listed.
1823 static int list_sessions(const char *session_name
)
1825 int ret
= CMD_SUCCESS
;
1827 unsigned int session_found
= 0;
1828 struct lttng_session
*sessions
;
1830 count
= lttng_list_sessions(&sessions
);
1831 DBG("Session count %d", count
);
1834 ERR("%s", lttng_strerror(count
));
1840 if (session_name
== NULL
) {
1841 /* List all session */
1842 ret
= mi_list_sessions(sessions
, count
);
1844 /* Note : this return an open session element */
1845 ret
= mi_list_session(session_name
, sessions
, count
);
1854 MSG("Currently no available tracing session");
1858 if (session_name
== NULL
) {
1859 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 if (*sessions
[i
].path
) {
1870 MSG("%sTrace output: %s\n", indent4
, sessions
[i
].path
);
1872 memcpy(&listed_session
, &sessions
[i
],
1873 sizeof(listed_session
));
1877 MSG(" %d) %s [%s%s]", i
+ 1,
1879 active_string(sessions
[i
].enabled
),
1880 snapshot_string(sessions
[i
].snapshot_mode
));
1881 if (*sessions
[i
].path
) {
1882 MSG("%sTrace output: %s", indent4
, sessions
[i
].path
);
1884 if (sessions
[i
].live_timer_interval
!= 0) {
1885 MSG("%sLive timer interval: %u %s", indent4
,
1886 sessions
[i
].live_timer_interval
,
1893 if (!session_found
&& session_name
!= NULL
) {
1894 ERR("Session '%s' not found", session_name
);
1899 if (session_name
== NULL
) {
1900 MSG("\nUse lttng list <session_name> for more details");
1913 * list available domain(s) for a session.
1915 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
1918 /* Open domains element */
1919 ret
= mi_lttng_domains_open(writer
);
1924 for (i
= 0; i
< count
; i
++) {
1925 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
1931 /* Closing domains element */
1932 ret
= mi_lttng_writer_close_element(writer
);
1941 * List available domain(s) for a session.
1943 static int list_domains(const char *session_name
)
1945 int i
, count
, ret
= CMD_SUCCESS
;
1946 struct lttng_domain
*domains
= NULL
;
1949 count
= lttng_list_domains(session_name
, &domains
);
1952 ERR("%s", lttng_strerror(count
));
1958 ret
= mi_list_domains(domains
, count
);
1965 MSG("Domains:\n-------------");
1971 for (i
= 0; i
< count
; i
++) {
1972 switch (domains
[i
].type
) {
1973 case LTTNG_DOMAIN_KERNEL
:
1976 case LTTNG_DOMAIN_UST
:
1977 MSG(" - UST global");
1979 case LTTNG_DOMAIN_JUL
:
1980 MSG(" - JUL (Java Util Logging)");
1982 case LTTNG_DOMAIN_LOG4J
:
1983 MSG(" - LOG4j (Logging for Java)");
1985 case LTTNG_DOMAIN_PYTHON
:
1986 MSG(" - Python (logging)");
2002 * The 'list <options>' first level command
2004 int cmd_list(int argc
, const char **argv
)
2006 int opt
, ret
= CMD_SUCCESS
;
2007 const char *session_name
, *leftover
= NULL
;
2008 static poptContext pc
;
2009 struct lttng_domain domain
;
2010 struct lttng_domain
*domains
= NULL
;
2012 memset(&domain
, 0, sizeof(domain
));
2019 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2020 poptReadDefaultConfig(pc
, 0);
2022 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2030 case OPT_LIST_OPTIONS
:
2031 list_cmd_options(stdout
, long_options
);
2034 ret
= CMD_UNDEFINED
;
2041 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
2047 /* Open command element */
2048 ret
= mi_lttng_writer_command_open(writer
,
2049 mi_lttng_element_command_list
);
2055 /* Open output element */
2056 ret
= mi_lttng_writer_open_element(writer
,
2057 mi_lttng_element_command_output
);
2064 /* Get session name (trailing argument) */
2065 session_name
= poptGetArg(pc
);
2066 DBG2("Session name: %s", session_name
);
2068 leftover
= poptGetArg(pc
);
2070 ERR("Unknown argument: %s", leftover
);
2076 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2077 } else if (opt_userspace
) {
2078 DBG2("Listing userspace global domain");
2079 domain
.type
= LTTNG_DOMAIN_UST
;
2080 } else if (opt_jul
) {
2081 DBG2("Listing JUL domain");
2082 domain
.type
= LTTNG_DOMAIN_JUL
;
2083 } else if (opt_log4j
) {
2084 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2085 } else if (opt_python
) {
2086 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2089 if (!opt_kernel
&& opt_syscall
) {
2090 WARN("--syscall will only work with the Kernel domain (-k)");
2095 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2096 handle
= lttng_create_handle(session_name
, &domain
);
2097 if (handle
== NULL
) {
2103 if (session_name
== NULL
) {
2104 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2106 ret
= list_sessions(NULL
);
2113 ret
= list_syscalls();
2118 ret
= list_kernel_events();
2124 if (opt_userspace
) {
2126 ret
= list_ust_event_fields();
2128 ret
= list_ust_events();
2134 if (opt_jul
|| opt_log4j
|| opt_python
) {
2135 ret
= list_agent_events();
2141 /* List session attributes */
2143 /* Open element sessions
2144 * Present for xml consistency */
2145 ret
= mi_lttng_sessions_open(writer
);
2150 /* MI: the ouptut of list_sessions is an unclosed session element */
2151 ret
= list_sessions(session_name
);
2156 ret
= list_rotate_settings(session_name
);
2161 /* Domain listing */
2163 ret
= list_domains(session_name
);
2167 /* Channel listing */
2168 if (opt_kernel
|| opt_userspace
) {
2170 /* Add of domains and domain element for xml
2171 * consistency and validation
2173 ret
= mi_lttng_domains_open(writer
);
2178 /* Open domain and leave it open for
2179 * nested channels printing */
2180 ret
= mi_lttng_domain(writer
, &domain
, 1);
2189 ret
= list_trackers();
2195 ret
= list_channels(opt_channel
);
2201 /* Close domain and domain element */
2202 ret
= mi_lttng_close_multi_element(writer
, 2);
2212 /* We want all domain(s) */
2213 nb_domain
= lttng_list_domains(session_name
, &domains
);
2214 if (nb_domain
< 0) {
2216 ERR("%s", lttng_strerror(nb_domain
));
2221 ret
= mi_lttng_domains_open(writer
);
2228 for (i
= 0; i
< nb_domain
; i
++) {
2229 switch (domains
[i
].type
) {
2230 case LTTNG_DOMAIN_KERNEL
:
2231 MSG("=== Domain: Kernel ===\n");
2233 case LTTNG_DOMAIN_UST
:
2234 MSG("=== Domain: UST global ===\n");
2235 MSG("Buffer type: %s\n",
2236 domains
[i
].buf_type
==
2237 LTTNG_BUFFER_PER_PID
? "per PID" : "per UID");
2239 case LTTNG_DOMAIN_JUL
:
2240 MSG("=== Domain: JUL (Java Util Logging) ===\n");
2242 case LTTNG_DOMAIN_LOG4J
:
2243 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
2245 case LTTNG_DOMAIN_PYTHON
:
2246 MSG("=== Domain: Python (logging) ===\n");
2249 MSG("=== Domain: Unimplemented ===\n");
2254 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
2261 /* Clean handle before creating a new one */
2263 lttng_destroy_handle(handle
);
2266 handle
= lttng_create_handle(session_name
, &domains
[i
]);
2267 if (handle
== NULL
) {
2272 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2273 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2274 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2275 ret
= list_session_agent_events();
2283 switch (domains
[i
].type
) {
2284 case LTTNG_DOMAIN_KERNEL
:
2285 case LTTNG_DOMAIN_UST
:
2286 ret
= list_trackers();
2295 ret
= list_channels(opt_channel
);
2302 /* Close domain element */
2303 ret
= mi_lttng_writer_close_element(writer
);
2312 /* Close the domains, session and sessions element */
2313 ret
= mi_lttng_close_multi_element(writer
, 3);
2324 /* Close output element */
2325 ret
= mi_lttng_writer_close_element(writer
);
2331 /* Command element close */
2332 ret
= mi_lttng_writer_command_close(writer
);
2340 if (writer
&& mi_lttng_writer_destroy(writer
)) {
2341 /* Preserve original error code */
2342 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2347 lttng_destroy_handle(handle
);
2350 poptFreeContext(pc
);