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 struct lttng_userspace_probe_location
*location
;
255 struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
256 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
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
);
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
, blocking_timeout
);
1325 MSG("%sTrace file count: %" PRIu64
" per stream", indent6
,
1326 channel
->attr
.tracefile_count
== 0 ?
1327 1 : channel
->attr
.tracefile_count
);
1328 if (channel
->attr
.tracefile_size
!= 0 ) {
1329 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
,
1330 channel
->attr
.tracefile_size
);
1332 MSG("%sTrace file size: %s", indent6
, "unlimited");
1334 switch (channel
->attr
.output
) {
1335 case LTTNG_EVENT_SPLICE
:
1336 MSG("%sOutput mode: splice", indent6
);
1338 case LTTNG_EVENT_MMAP
:
1339 MSG("%sOutput mode: mmap", indent6
);
1343 MSG("\n%sStatistics:", indent4
);
1344 if (listed_session
.snapshot_mode
) {
1346 * The lost packet count is omitted for sessions in snapshot
1347 * mode as it is misleading: it would indicate the number of
1348 * packets that the consumer could not extract during the
1349 * course of recording the snapshot. It does not have the
1350 * same meaning as the "regular" lost packet count that
1351 * would result from the consumer not keeping up with
1352 * event production in an overwrite-mode channel.
1354 * A more interesting statistic would be the number of
1355 * packets lost between the first and last extracted
1356 * packets of a given snapshot (which prevents most analyses).
1358 MSG("%sNone", indent6
);
1359 goto skip_stats_printing
;
1362 if (!channel
->attr
.overwrite
) {
1363 MSG("%sDiscarded events: %" PRIu64
, indent6
, discarded_events
);
1365 MSG("%sLost packets: %" PRIu64
, indent6
, lost_packets
);
1367 skip_stats_printing
:
1373 * Print a list of channel
1376 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1377 const char *channel_name
)
1380 unsigned int chan_found
= 0;
1382 /* Open channels element */
1383 ret
= mi_lttng_channels_open(writer
);
1388 for (i
= 0; i
< count
; i
++) {
1389 if (channel_name
!= NULL
) {
1390 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1397 /* Write channel element and leave it open */
1398 ret
= mi_lttng_channel(writer
, &channels
[i
], 1);
1403 /* Listing events per channel */
1404 ret
= list_events(channels
[i
].name
);
1409 /* Closing the channel element we opened earlier */
1410 ret
= mi_lttng_writer_close_element(writer
);
1420 /* Close channels element */
1421 ret
= mi_lttng_writer_close_element(writer
);
1431 * List channel(s) of session and domain.
1433 * If channel_name is NULL, all channels are listed.
1435 static int list_channels(const char *channel_name
)
1437 int count
, i
, ret
= CMD_SUCCESS
;
1438 unsigned int chan_found
= 0;
1439 struct lttng_channel
*channels
= NULL
;
1441 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1443 count
= lttng_list_channels(handle
, &channels
);
1446 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1448 /* When printing mi this is not an error
1449 * but an empty channels element */
1453 WARN("No kernel channel");
1454 goto error_channels
;
1458 /* We had a real error */
1460 ERR("%s", lttng_strerror(count
));
1461 goto error_channels
;
1468 ret
= mi_list_channels(channels
, count
, channel_name
);
1476 MSG("Channels:\n-------------");
1479 for (i
= 0; i
< count
; i
++) {
1480 if (channel_name
!= NULL
) {
1481 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1487 print_channel(&channels
[i
]);
1489 /* Listing events per channel */
1490 ret
= list_events(channels
[i
].name
);
1500 if (!chan_found
&& channel_name
!= NULL
) {
1502 ERR("Channel %s not found", channel_name
);
1514 * List tracker PID(s) of session and domain.
1516 static int list_tracker_pids(void)
1523 ret
= lttng_list_tracker_pids(handle
,
1524 &enabled
, &pids
, &nr_pids
);
1530 _MSG("PID tracker: [");
1532 /* Mi tracker_pid element*/
1534 /* Open tracker_pid and targets elements */
1535 ret
= mi_lttng_pid_tracker_open(writer
);
1541 for (i
= 0; i
< nr_pids
; i
++) {
1545 _MSG(" %d", pids
[i
]);
1549 ret
= mi_lttng_pid_target(writer
, pids
[i
], 0);
1557 /* Mi close tracker_pid and targets */
1559 ret
= mi_lttng_close_multi_element(writer
,2);
1572 * List all tracker of a domain
1574 static int list_trackers(void)
1578 /* Trackers listing */
1580 ret
= mi_lttng_trackers_open(writer
);
1587 ret
= list_tracker_pids();
1593 /* Close trackers element */
1594 ret
= mi_lttng_writer_close_element(writer
);
1604 static enum cmd_error_code
print_periodic_rotation_schedule(
1605 const struct lttng_rotation_schedule
*schedule
)
1607 enum cmd_error_code ret
;
1608 enum lttng_rotation_status status
;
1611 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1613 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1614 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1619 MSG(" timer period: %" PRIu64
" µs", value
);
1625 static enum cmd_error_code
print_size_threshold_rotation_schedule(
1626 const struct lttng_rotation_schedule
*schedule
)
1628 enum cmd_error_code ret
;
1629 enum lttng_rotation_status status
;
1632 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
1634 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1635 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1640 MSG(" size threshold: %" PRIu64
" bytes", value
);
1646 static enum cmd_error_code
print_rotation_schedule(
1647 const struct lttng_rotation_schedule
*schedule
)
1649 enum cmd_error_code ret
;
1651 switch (lttng_rotation_schedule_get_type(schedule
)) {
1652 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1653 ret
= print_size_threshold_rotation_schedule(schedule
);
1655 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1656 ret
= print_periodic_rotation_schedule(schedule
);
1665 * List the automatic rotation settings.
1667 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1670 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1671 unsigned int count
, i
;
1672 struct lttng_rotation_schedules
*schedules
= NULL
;
1673 enum lttng_rotation_status status
;
1675 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1676 if (ret
!= LTTNG_OK
) {
1677 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1678 cmd_ret
= CMD_ERROR
;
1682 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1683 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1684 ERR("Failed to retrieve the number of session rotation schedules.");
1685 cmd_ret
= CMD_ERROR
;
1690 cmd_ret
= CMD_SUCCESS
;
1694 MSG("Automatic rotation schedules:");
1696 ret
= mi_lttng_writer_open_element(writer
,
1697 mi_lttng_element_rotation_schedules
);
1699 cmd_ret
= CMD_ERROR
;
1704 for (i
= 0; i
< count
; i
++) {
1705 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1706 const struct lttng_rotation_schedule
*schedule
;
1708 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1710 ERR("Failed to retrieve session rotation schedule.");
1711 cmd_ret
= CMD_ERROR
;
1716 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
1718 tmp_ret
= CMD_ERROR
;
1721 tmp_ret
= print_rotation_schedule(schedule
);
1725 * Report an error if the serialization of any of the
1726 * descriptors failed.
1728 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
1733 /* Close the rotation_schedules element. */
1734 ret
= mi_lttng_writer_close_element(writer
);
1736 cmd_ret
= CMD_ERROR
;
1741 lttng_rotation_schedules_destroy(schedules
);
1747 * Find the session with session_name as name
1748 * and print his informations.
1750 static int mi_list_session(const char *session_name
,
1751 struct lttng_session
*sessions
, int count
)
1754 unsigned int session_found
= 0;
1756 if (session_name
== NULL
) {
1757 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1761 for (i
= 0; i
< count
; i
++) {
1762 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1763 /* We need to leave it open to append other informations
1764 * like domain, channel, events etc.*/
1766 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
1774 if (!session_found
) {
1775 ERR("Session '%s' not found", session_name
);
1776 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1786 * List all availables session
1788 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
1792 /* Opening sessions element */
1793 ret
= mi_lttng_sessions_open(writer
);
1798 /* Listing sessions */
1799 for (i
= 0; i
< count
; i
++) {
1800 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
1806 /* Closing sessions element */
1807 ret
= mi_lttng_writer_close_element(writer
);
1817 * List available tracing session. List only basic information.
1819 * If session_name is NULL, all sessions are listed.
1821 static int list_sessions(const char *session_name
)
1823 int ret
= CMD_SUCCESS
;
1825 unsigned int session_found
= 0;
1826 struct lttng_session
*sessions
;
1828 count
= lttng_list_sessions(&sessions
);
1829 DBG("Session count %d", count
);
1832 ERR("%s", lttng_strerror(count
));
1838 if (session_name
== NULL
) {
1839 /* List all session */
1840 ret
= mi_list_sessions(sessions
, count
);
1842 /* Note : this return an open session element */
1843 ret
= mi_list_session(session_name
, sessions
, count
);
1852 MSG("Currently no available tracing session");
1856 if (session_name
== NULL
) {
1857 MSG("Available tracing sessions:");
1861 for (i
= 0; i
< count
; i
++) {
1862 if (session_name
!= NULL
) {
1863 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1865 MSG("Tracing session %s: [%s%s]", session_name
,
1866 active_string(sessions
[i
].enabled
),
1867 snapshot_string(sessions
[i
].snapshot_mode
));
1868 MSG("%sTrace path: %s\n", indent4
, sessions
[i
].path
);
1869 memcpy(&listed_session
, &sessions
[i
],
1870 sizeof(listed_session
));
1874 MSG(" %d) %s (%s) [%s%s]", i
+ 1,
1875 sessions
[i
].name
, sessions
[i
].path
,
1876 active_string(sessions
[i
].enabled
),
1877 snapshot_string(sessions
[i
].snapshot_mode
));
1878 MSG("%sTrace path: %s", indent4
, sessions
[i
].path
);
1879 if (sessions
[i
].live_timer_interval
!= 0) {
1880 MSG("%sLive timer interval: %u µs", indent4
,
1881 sessions
[i
].live_timer_interval
);
1887 if (!session_found
&& session_name
!= NULL
) {
1888 ERR("Session '%s' not found", session_name
);
1893 if (session_name
== NULL
) {
1894 MSG("\nUse lttng list <session_name> for more details");
1907 * list available domain(s) for a session.
1909 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
1912 /* Open domains element */
1913 ret
= mi_lttng_domains_open(writer
);
1918 for (i
= 0; i
< count
; i
++) {
1919 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
1925 /* Closing domains element */
1926 ret
= mi_lttng_writer_close_element(writer
);
1935 * List available domain(s) for a session.
1937 static int list_domains(const char *session_name
)
1939 int i
, count
, ret
= CMD_SUCCESS
;
1940 struct lttng_domain
*domains
= NULL
;
1943 count
= lttng_list_domains(session_name
, &domains
);
1946 ERR("%s", lttng_strerror(count
));
1952 ret
= mi_list_domains(domains
, count
);
1959 MSG("Domains:\n-------------");
1965 for (i
= 0; i
< count
; i
++) {
1966 switch (domains
[i
].type
) {
1967 case LTTNG_DOMAIN_KERNEL
:
1970 case LTTNG_DOMAIN_UST
:
1971 MSG(" - UST global");
1973 case LTTNG_DOMAIN_JUL
:
1974 MSG(" - JUL (Java Util Logging)");
1976 case LTTNG_DOMAIN_LOG4J
:
1977 MSG(" - LOG4j (Logging for Java)");
1979 case LTTNG_DOMAIN_PYTHON
:
1980 MSG(" - Python (logging)");
1996 * The 'list <options>' first level command
1998 int cmd_list(int argc
, const char **argv
)
2000 int opt
, ret
= CMD_SUCCESS
;
2001 const char *session_name
, *leftover
= NULL
;
2002 static poptContext pc
;
2003 struct lttng_domain domain
;
2004 struct lttng_domain
*domains
= NULL
;
2006 memset(&domain
, 0, sizeof(domain
));
2013 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2014 poptReadDefaultConfig(pc
, 0);
2016 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2024 case OPT_LIST_OPTIONS
:
2025 list_cmd_options(stdout
, long_options
);
2028 ret
= CMD_UNDEFINED
;
2035 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
2041 /* Open command element */
2042 ret
= mi_lttng_writer_command_open(writer
,
2043 mi_lttng_element_command_list
);
2049 /* Open output element */
2050 ret
= mi_lttng_writer_open_element(writer
,
2051 mi_lttng_element_command_output
);
2058 /* Get session name (trailing argument) */
2059 session_name
= poptGetArg(pc
);
2060 DBG2("Session name: %s", session_name
);
2062 leftover
= poptGetArg(pc
);
2064 ERR("Unknown argument: %s", leftover
);
2070 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2071 } else if (opt_userspace
) {
2072 DBG2("Listing userspace global domain");
2073 domain
.type
= LTTNG_DOMAIN_UST
;
2074 } else if (opt_jul
) {
2075 DBG2("Listing JUL domain");
2076 domain
.type
= LTTNG_DOMAIN_JUL
;
2077 } else if (opt_log4j
) {
2078 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2079 } else if (opt_python
) {
2080 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2083 if (!opt_kernel
&& opt_syscall
) {
2084 WARN("--syscall will only work with the Kernel domain (-k)");
2089 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2090 handle
= lttng_create_handle(session_name
, &domain
);
2091 if (handle
== NULL
) {
2097 if (session_name
== NULL
) {
2098 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2100 ret
= list_sessions(NULL
);
2107 ret
= list_syscalls();
2112 ret
= list_kernel_events();
2118 if (opt_userspace
) {
2120 ret
= list_ust_event_fields();
2122 ret
= list_ust_events();
2128 if (opt_jul
|| opt_log4j
|| opt_python
) {
2129 ret
= list_agent_events();
2135 /* List session attributes */
2137 /* Open element sessions
2138 * Present for xml consistency */
2139 ret
= mi_lttng_sessions_open(writer
);
2144 /* MI: the ouptut of list_sessions is an unclosed session element */
2145 ret
= list_sessions(session_name
);
2150 ret
= list_rotate_settings(session_name
);
2155 /* Domain listing */
2157 ret
= list_domains(session_name
);
2161 /* Channel listing */
2162 if (opt_kernel
|| opt_userspace
) {
2164 /* Add of domains and domain element for xml
2165 * consistency and validation
2167 ret
= mi_lttng_domains_open(writer
);
2172 /* Open domain and leave it open for
2173 * nested channels printing */
2174 ret
= mi_lttng_domain(writer
, &domain
, 1);
2183 ret
= list_trackers();
2189 ret
= list_channels(opt_channel
);
2195 /* Close domain and domain element */
2196 ret
= mi_lttng_close_multi_element(writer
, 2);
2206 /* We want all domain(s) */
2207 nb_domain
= lttng_list_domains(session_name
, &domains
);
2208 if (nb_domain
< 0) {
2210 ERR("%s", lttng_strerror(nb_domain
));
2215 ret
= mi_lttng_domains_open(writer
);
2222 for (i
= 0; i
< nb_domain
; i
++) {
2223 switch (domains
[i
].type
) {
2224 case LTTNG_DOMAIN_KERNEL
:
2225 MSG("=== Domain: Kernel ===\n");
2227 case LTTNG_DOMAIN_UST
:
2228 MSG("=== Domain: UST global ===\n");
2229 MSG("Buffer type: %s\n",
2230 domains
[i
].buf_type
==
2231 LTTNG_BUFFER_PER_PID
? "per PID" : "per UID");
2233 case LTTNG_DOMAIN_JUL
:
2234 MSG("=== Domain: JUL (Java Util Logging) ===\n");
2236 case LTTNG_DOMAIN_LOG4J
:
2237 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
2239 case LTTNG_DOMAIN_PYTHON
:
2240 MSG("=== Domain: Python (logging) ===\n");
2243 MSG("=== Domain: Unimplemented ===\n");
2248 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
2255 /* Clean handle before creating a new one */
2257 lttng_destroy_handle(handle
);
2260 handle
= lttng_create_handle(session_name
, &domains
[i
]);
2261 if (handle
== NULL
) {
2266 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2267 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2268 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2269 ret
= list_session_agent_events();
2277 switch (domains
[i
].type
) {
2278 case LTTNG_DOMAIN_KERNEL
:
2279 case LTTNG_DOMAIN_UST
:
2280 ret
= list_trackers();
2289 ret
= list_channels(opt_channel
);
2296 /* Close domain element */
2297 ret
= mi_lttng_writer_close_element(writer
);
2306 /* Close the domains, session and sessions element */
2307 ret
= mi_lttng_close_multi_element(writer
, 3);
2318 /* Close output element */
2319 ret
= mi_lttng_writer_close_element(writer
);
2325 /* Command element close */
2326 ret
= mi_lttng_writer_command_close(writer
);
2334 if (writer
&& mi_lttng_writer_destroy(writer
)) {
2335 /* Preserve original error code */
2336 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2341 lttng_destroy_handle(handle
);
2344 poptFreeContext(pc
);