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>
29 #include <lttng/tracker.h>
31 #include "../command.h"
33 static int opt_userspace
;
34 static int opt_kernel
;
37 static int opt_python
;
38 static char *opt_channel
;
39 static int opt_domain
;
40 static int opt_fields
;
41 static int opt_syscall
;
43 const char *indent4
= " ";
44 const char *indent6
= " ";
45 const char *indent8
= " ";
47 #ifdef LTTNG_EMBED_HELP
48 static const char help_msg
[] =
49 #include <lttng-list.1.h>
59 static struct lttng_handle
*handle
;
60 static struct mi_writer
*writer
;
62 /* Only set when listing a single session. */
63 static struct lttng_session listed_session
;
65 static struct poptOption long_options
[] = {
66 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
67 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
68 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
69 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
70 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
71 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
72 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
73 {"channel", 'c', POPT_ARG_STRING
, &opt_channel
, 0, 0, 0},
74 {"domain", 'd', POPT_ARG_VAL
, &opt_domain
, 1, 0, 0},
75 {"fields", 'f', POPT_ARG_VAL
, &opt_fields
, 1, 0, 0},
76 {"syscall", 'S', POPT_ARG_VAL
, &opt_syscall
, 1, 0, 0},
77 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
82 * Get command line from /proc for a specific pid.
84 * On success, return an allocated string pointer to the proc cmdline.
85 * On error, return NULL.
87 static char *get_cmdline_by_pid(pid_t pid
)
92 /* Can't go bigger than /proc/LTTNG_MAX_PID/cmdline */
93 char path
[sizeof("/proc//cmdline") + sizeof(LTTNG_MAX_PID_STR
) - 1];
95 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pid
);
96 fp
= fopen(path
, "r");
101 /* Caller must free() *cmdline */
102 cmdline
= zmalloc(PATH_MAX
);
104 PERROR("malloc cmdline");
107 ret
= fread(cmdline
, 1, PATH_MAX
, fp
);
109 PERROR("fread proc list");
120 const char *active_string(int value
)
123 case 0: return "inactive";
124 case 1: return "active";
126 default: return NULL
;
130 static const char *snapshot_string(int value
)
141 const char *enabled_string(int value
)
144 case 0: return " [disabled]";
145 case 1: return " [enabled]";
147 default: return NULL
;
152 const char *safe_string(const char *str
)
154 return str
? str
: "";
157 static const char *logleveltype_string(enum lttng_loglevel_type value
)
160 case LTTNG_EVENT_LOGLEVEL_ALL
:
162 case LTTNG_EVENT_LOGLEVEL_RANGE
:
164 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
167 return " <<TYPE UNKN>>";
171 static const char *bitness_event(enum lttng_event_flag flags
)
173 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_32
) {
174 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
175 return " [32/64-bit]";
179 } else if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
187 * Get exclusion names message for a single event.
189 * Returned pointer must be freed by caller. Returns NULL on error.
191 static char *get_exclusion_names_msg(struct lttng_event
*event
)
195 char *exclusion_msg
= NULL
;
198 const char * const exclusion_fmt
= " [exclusions: ";
199 const size_t exclusion_fmt_len
= strlen(exclusion_fmt
);
201 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
202 if (exclusion_count
< 0) {
204 } else if (exclusion_count
== 0) {
206 * No exclusions: return copy of empty string so that
207 * it can be freed by caller.
209 exclusion_msg
= strdup("");
214 * exclusion_msg's size is bounded by the exclusion_fmt string,
215 * a comma per entry, the entry count (fixed-size), a closing
216 * bracket, and a trailing \0.
218 exclusion_msg
= malloc(exclusion_count
+
219 exclusion_count
* LTTNG_SYMBOL_NAME_LEN
+
220 exclusion_fmt_len
+ 1);
221 if (!exclusion_msg
) {
225 at
= strcpy(exclusion_msg
, exclusion_fmt
) + exclusion_fmt_len
;
226 for (i
= 0; i
< exclusion_count
; ++i
) {
229 /* Append comma between exclusion names */
235 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
237 /* Prints '?' on local error; should never happen */
243 /* Append exclusion name */
244 at
+= sprintf(at
, "%s", name
);
247 /* This also puts a final '\0' at the end of exclusion_msg */
251 return exclusion_msg
;
254 static void print_userspace_probe_location(struct lttng_event
*event
)
256 const struct lttng_userspace_probe_location
*location
;
257 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
258 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
260 location
= lttng_event_get_userspace_probe_location(event
);
262 MSG("Event has no userspace probe location");
266 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
267 if (!lookup_method
) {
268 MSG("Event has no userspace probe location lookup method");
272 MSG("%s%s (type: userspace-probe)%s", indent6
, event
->name
, enabled_string(event
->enabled
));
274 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
276 switch (lttng_userspace_probe_location_get_type(location
)) {
277 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
:
278 MSG("%sType: Unknown", indent8
);
280 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
282 const char *function_name
;
283 const char *binary_path
;
285 MSG("%sType: Function", indent8
);
286 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
287 binary_path
= realpath(lttng_userspace_probe_location_function_get_binary_path(location
), NULL
);
289 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
290 MSG("%sFunction: %s()", indent8
, function_name
? function_name
: "NULL");
291 switch (lookup_type
) {
292 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
293 MSG("%sLookup method: ELF", indent8
);
295 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
296 MSG("%sLookup method: default", indent8
);
299 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
304 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
306 const char *probe_name
, *provider_name
;
307 const char *binary_path
;
309 MSG("%sType: Tracepoint", indent8
);
310 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
311 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
312 binary_path
= realpath(lttng_userspace_probe_location_tracepoint_get_binary_path(location
), NULL
);
313 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
314 MSG("%sTracepoint: %s:%s", indent8
, provider_name
? provider_name
: "NULL", probe_name
? probe_name
: "NULL");
315 switch (lookup_type
) {
316 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
317 MSG("%sLookup method: SDT", indent8
);
320 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
326 ERR("Invalid probe type encountered");
331 * Pretty print single event.
333 static void print_events(struct lttng_event
*event
)
336 const char *filter_str
;
337 char *filter_msg
= NULL
;
338 char *exclusion_msg
= NULL
;
340 ret
= lttng_event_get_filter_expression(event
, &filter_str
);
343 filter_msg
= strdup(" [failed to retrieve filter]");
344 } else if (filter_str
) {
345 const char * const filter_fmt
= " [filter: '%s']";
347 filter_msg
= malloc(strlen(filter_str
) +
348 strlen(filter_fmt
) + 1);
350 sprintf(filter_msg
, filter_fmt
,
355 exclusion_msg
= get_exclusion_names_msg(event
);
356 if (!exclusion_msg
) {
357 exclusion_msg
= strdup(" [failed to retrieve exclusions]");
360 switch (event
->type
) {
361 case LTTNG_EVENT_TRACEPOINT
:
363 if (event
->loglevel
!= -1) {
364 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
367 logleveltype_string(event
->loglevel_type
),
368 mi_lttng_loglevel_string(event
->loglevel
, handle
->domain
.type
),
370 enabled_string(event
->enabled
),
371 safe_string(exclusion_msg
),
372 safe_string(filter_msg
));
374 MSG("%s%s (type: tracepoint)%s%s%s",
377 enabled_string(event
->enabled
),
378 safe_string(exclusion_msg
),
379 safe_string(filter_msg
));
383 case LTTNG_EVENT_FUNCTION
:
384 MSG("%s%s (type: function)%s%s", indent6
,
385 event
->name
, enabled_string(event
->enabled
),
386 safe_string(filter_msg
));
387 if (event
->attr
.probe
.addr
!= 0) {
388 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
390 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
391 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
394 case LTTNG_EVENT_PROBE
:
395 MSG("%s%s (type: probe)%s%s", indent6
,
396 event
->name
, enabled_string(event
->enabled
),
397 safe_string(filter_msg
));
398 if (event
->attr
.probe
.addr
!= 0) {
399 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
401 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
402 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
405 case LTTNG_EVENT_USERSPACE_PROBE
:
406 print_userspace_probe_location(event
);
408 case LTTNG_EVENT_FUNCTION_ENTRY
:
409 MSG("%s%s (type: function)%s%s", indent6
,
410 event
->name
, enabled_string(event
->enabled
),
411 safe_string(filter_msg
));
412 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
414 case LTTNG_EVENT_SYSCALL
:
415 MSG("%s%s%s%s%s%s", indent6
, event
->name
,
416 (opt_syscall
? "" : " (type:syscall)"),
417 enabled_string(event
->enabled
),
418 bitness_event(event
->flags
),
419 safe_string(filter_msg
));
421 case LTTNG_EVENT_NOOP
:
422 MSG("%s (type: noop)%s%s", indent6
,
423 enabled_string(event
->enabled
),
424 safe_string(filter_msg
));
426 case LTTNG_EVENT_ALL
:
429 /* We should never have "all" events in list. */
438 static const char *field_type(struct lttng_event_field
*field
)
440 switch(field
->type
) {
441 case LTTNG_EVENT_FIELD_INTEGER
:
443 case LTTNG_EVENT_FIELD_ENUM
:
445 case LTTNG_EVENT_FIELD_FLOAT
:
447 case LTTNG_EVENT_FIELD_STRING
:
449 case LTTNG_EVENT_FIELD_OTHER
:
450 default: /* fall-through */
456 * Pretty print single event fields.
458 static void print_event_field(struct lttng_event_field
*field
)
460 if (!field
->field_name
[0]) {
463 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
464 field_type(field
), field
->nowrite
? " [no write]" : "");
469 * Jul and ust event listing
471 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
472 struct lttng_domain
*domain
)
476 char *cmdline
= NULL
;
477 int pid_element_open
= 0;
479 /* Open domains element */
480 ret
= mi_lttng_domains_open(writer
);
486 ret
= mi_lttng_domain(writer
, domain
, 1);
491 /* Open pids element element */
492 ret
= mi_lttng_pids_open(writer
);
497 for (i
= 0; i
< count
; i
++) {
498 if (cur_pid
!= events
[i
].pid
) {
499 if (pid_element_open
) {
500 /* Close the previous events and pid element */
501 ret
= mi_lttng_close_multi_element(writer
, 2);
505 pid_element_open
= 0;
508 cur_pid
= events
[i
].pid
;
509 cmdline
= get_cmdline_by_pid(cur_pid
);
515 if (!pid_element_open
) {
516 /* Open and write a pid element */
517 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
522 /* Open events element */
523 ret
= mi_lttng_events_open(writer
);
528 pid_element_open
= 1;
534 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
541 ret
= mi_lttng_writer_close_element(writer
);
546 /* Close domain, domains */
547 ret
= mi_lttng_close_multi_element(writer
, 2);
555 static int list_agent_events(void)
557 int i
, size
, ret
= CMD_SUCCESS
;
558 struct lttng_domain domain
;
559 struct lttng_handle
*handle
= NULL
;
560 struct lttng_event
*event_list
= NULL
;
562 char *cmdline
= NULL
;
563 const char *agent_domain_str
;
565 memset(&domain
, 0, sizeof(domain
));
567 domain
.type
= LTTNG_DOMAIN_JUL
;
568 } else if (opt_log4j
) {
569 domain
.type
= LTTNG_DOMAIN_LOG4J
;
570 } else if (opt_python
) {
571 domain
.type
= LTTNG_DOMAIN_PYTHON
;
573 ERR("Invalid agent domain selected.");
578 agent_domain_str
= get_domain_str(domain
.type
);
580 DBG("Getting %s tracing events", agent_domain_str
);
582 handle
= lttng_create_handle(NULL
, &domain
);
583 if (handle
== NULL
) {
588 size
= lttng_list_tracepoints(handle
, &event_list
);
590 ERR("Unable to list %s events: %s", agent_domain_str
,
591 lttng_strerror(size
));
598 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
605 MSG("%s events (Logger name):\n-------------------------",
612 for (i
= 0; i
< size
; i
++) {
613 if (cur_pid
!= event_list
[i
].pid
) {
614 cur_pid
= event_list
[i
].pid
;
615 cmdline
= get_cmdline_by_pid(cur_pid
);
616 if (cmdline
== NULL
) {
620 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
623 MSG("%s- %s", indent6
, event_list
[i
].name
);
632 lttng_destroy_handle(handle
);
637 * Ask session daemon for all user space tracepoints available.
639 static int list_ust_events(void)
641 int i
, size
, ret
= CMD_SUCCESS
;
642 struct lttng_domain domain
;
643 struct lttng_handle
*handle
;
644 struct lttng_event
*event_list
= NULL
;
646 char *cmdline
= NULL
;
648 memset(&domain
, 0, sizeof(domain
));
650 DBG("Getting UST tracing events");
652 domain
.type
= LTTNG_DOMAIN_UST
;
654 handle
= lttng_create_handle(NULL
, &domain
);
655 if (handle
== NULL
) {
660 size
= lttng_list_tracepoints(handle
, &event_list
);
662 ERR("Unable to list UST events: %s", lttng_strerror(size
));
669 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
672 MSG("UST events:\n-------------");
678 for (i
= 0; i
< size
; i
++) {
679 if (cur_pid
!= event_list
[i
].pid
) {
680 cur_pid
= event_list
[i
].pid
;
681 cmdline
= get_cmdline_by_pid(cur_pid
);
682 if (cmdline
== NULL
) {
686 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
689 print_events(&event_list
[i
]);
698 lttng_destroy_handle(handle
);
704 * List all ust event with their fields
706 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
707 struct lttng_domain
*domain
)
711 char *cmdline
= NULL
;
712 int pid_element_open
= 0;
713 int event_element_open
= 0;
714 struct lttng_event cur_event
;
716 memset(&cur_event
, 0, sizeof(cur_event
));
718 /* Open domains element */
719 ret
= mi_lttng_domains_open(writer
);
725 ret
= mi_lttng_domain(writer
, domain
, 1);
730 /* Open pids element */
731 ret
= mi_lttng_pids_open(writer
);
736 for (i
= 0; i
< count
; i
++) {
737 if (cur_pid
!= fields
[i
].event
.pid
) {
738 if (pid_element_open
) {
739 if (event_element_open
) {
740 /* Close the previous field element and event. */
741 ret
= mi_lttng_close_multi_element(writer
, 2);
745 event_element_open
= 0;
747 /* Close the previous events, pid element */
748 ret
= mi_lttng_close_multi_element(writer
, 2);
752 pid_element_open
= 0;
755 cur_pid
= fields
[i
].event
.pid
;
756 cmdline
= get_cmdline_by_pid(cur_pid
);
757 if (!pid_element_open
) {
758 /* Open and write a pid element */
759 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
764 /* Open events element */
765 ret
= mi_lttng_events_open(writer
);
769 pid_element_open
= 1;
772 /* Wipe current event since we are about to print a new PID. */
773 memset(&cur_event
, 0, sizeof(cur_event
));
776 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
777 if (event_element_open
) {
778 /* Close the previous fields element and the previous event */
779 ret
= mi_lttng_close_multi_element(writer
, 2);
783 event_element_open
= 0;
786 memcpy(&cur_event
, &fields
[i
].event
,
789 if (!event_element_open
) {
790 /* Open and write the event */
791 ret
= mi_lttng_event(writer
, &cur_event
, 1,
792 handle
->domain
.type
);
797 /* Open a fields element */
798 ret
= mi_lttng_event_fields_open(writer
);
802 event_element_open
= 1;
806 /* Print the event_field */
807 ret
= mi_lttng_event_field(writer
, &fields
[i
]);
813 /* Close pids, domain, domains */
814 ret
= mi_lttng_close_multi_element(writer
, 3);
823 * Ask session daemon for all user space tracepoint fields available.
825 static int list_ust_event_fields(void)
827 int i
, size
, ret
= CMD_SUCCESS
;
828 struct lttng_domain domain
;
829 struct lttng_handle
*handle
;
830 struct lttng_event_field
*event_field_list
;
832 char *cmdline
= NULL
;
834 struct lttng_event cur_event
;
836 memset(&domain
, 0, sizeof(domain
));
837 memset(&cur_event
, 0, sizeof(cur_event
));
839 DBG("Getting UST tracing event fields");
841 domain
.type
= LTTNG_DOMAIN_UST
;
843 handle
= lttng_create_handle(NULL
, &domain
);
844 if (handle
== NULL
) {
849 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
851 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
858 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
865 MSG("UST events:\n-------------");
871 for (i
= 0; i
< size
; i
++) {
872 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
873 cur_pid
= event_field_list
[i
].event
.pid
;
874 cmdline
= get_cmdline_by_pid(cur_pid
);
875 if (cmdline
== NULL
) {
879 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
881 /* Wipe current event since we are about to print a new PID. */
882 memset(&cur_event
, 0, sizeof(cur_event
));
884 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
885 print_events(&event_field_list
[i
].event
);
886 memcpy(&cur_event
, &event_field_list
[i
].event
,
889 print_event_field(&event_field_list
[i
]);
896 free(event_field_list
);
898 lttng_destroy_handle(handle
);
904 * Print a list of kernel events
906 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
907 struct lttng_domain
*domain
)
911 /* Open domains element */
912 ret
= mi_lttng_domains_open(writer
);
918 ret
= mi_lttng_domain(writer
, domain
, 1);
924 ret
= mi_lttng_events_open(writer
);
929 for (i
= 0; i
< count
; i
++) {
930 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
936 /* close events, domain and domains */
937 ret
= mi_lttng_close_multi_element(writer
, 3);
947 * Ask for all trace events in the kernel
949 static int list_kernel_events(void)
951 int i
, size
, ret
= CMD_SUCCESS
;
952 struct lttng_domain domain
;
953 struct lttng_handle
*handle
;
954 struct lttng_event
*event_list
;
956 memset(&domain
, 0, sizeof(domain
));
958 DBG("Getting kernel tracing events");
960 domain
.type
= LTTNG_DOMAIN_KERNEL
;
962 handle
= lttng_create_handle(NULL
, &domain
);
963 if (handle
== NULL
) {
968 size
= lttng_list_tracepoints(handle
, &event_list
);
970 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
971 lttng_destroy_handle(handle
);
977 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
983 MSG("Kernel events:\n-------------");
985 for (i
= 0; i
< size
; i
++) {
986 print_events(&event_list
[i
]);
995 lttng_destroy_handle(handle
);
999 lttng_destroy_handle(handle
);
1005 * Print a list of system calls.
1007 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1012 ret
= mi_lttng_events_open(writer
);
1017 for (i
= 0; i
< count
; i
++) {
1018 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1025 ret
= mi_lttng_writer_close_element(writer
);
1035 * Ask for kernel system calls.
1037 static int list_syscalls(void)
1039 int i
, size
, ret
= CMD_SUCCESS
;
1040 struct lttng_event
*event_list
;
1042 DBG("Getting kernel system call events");
1044 size
= lttng_list_syscalls(&event_list
);
1046 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1053 ret
= mi_list_syscalls(event_list
, size
);
1059 MSG("System calls:\n-------------");
1061 for (i
= 0; i
< size
; i
++) {
1062 print_events(&event_list
[i
]);
1078 * Print a list of agent events
1080 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1084 /* Open events element */
1085 ret
= mi_lttng_events_open(writer
);
1090 for (i
= 0; i
< count
; i
++) {
1091 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1097 /* Close events element */
1098 ret
= mi_lttng_writer_close_element(writer
);
1105 * List agent events for a specific session using the handle.
1107 * Return CMD_SUCCESS on success else a negative value.
1109 static int list_session_agent_events(void)
1111 int ret
= CMD_SUCCESS
, count
, i
;
1112 struct lttng_event
*events
= NULL
;
1114 count
= lttng_list_events(handle
, "", &events
);
1117 ERR("%s", lttng_strerror(count
));
1123 ret
= mi_list_session_agent_events(events
, count
);
1130 MSG("Events (Logger name):\n---------------------");
1132 MSG("%sNone\n", indent6
);
1136 for (i
= 0; i
< count
; i
++) {
1137 const char *filter_str
;
1138 char *filter_msg
= NULL
;
1139 struct lttng_event
*event
= &events
[i
];
1141 ret
= lttng_event_get_filter_expression(event
,
1144 filter_msg
= strdup(" [failed to retrieve filter]");
1145 } else if (filter_str
) {
1146 const char * const filter_fmt
=
1149 filter_msg
= malloc(strlen(filter_str
) +
1150 strlen(filter_fmt
) + 1);
1152 sprintf(filter_msg
, filter_fmt
,
1157 if (event
->loglevel_type
!=
1158 LTTNG_EVENT_LOGLEVEL_ALL
) {
1159 MSG("%s- %s%s (loglevel%s %s)%s", indent4
,
1161 enabled_string(event
->enabled
),
1162 logleveltype_string(
1163 event
->loglevel_type
),
1164 mi_lttng_loglevel_string(
1166 handle
->domain
.type
),
1167 safe_string(filter_msg
));
1169 MSG("%s- %s%s%s", indent4
, event
->name
,
1170 enabled_string(event
->enabled
),
1171 safe_string(filter_msg
));
1187 * print a list of event
1189 static int mi_list_events(struct lttng_event
*events
, int count
)
1193 /* Open events element */
1194 ret
= mi_lttng_events_open(writer
);
1199 for (i
= 0; i
< count
; i
++) {
1200 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1206 /* Close events element */
1207 ret
= mi_lttng_writer_close_element(writer
);
1214 * List events of channel of session and domain.
1216 static int list_events(const char *channel_name
)
1218 int ret
= CMD_SUCCESS
, count
, i
;
1219 struct lttng_event
*events
= NULL
;
1221 count
= lttng_list_events(handle
, channel_name
, &events
);
1224 ERR("%s", lttng_strerror(count
));
1230 ret
= mi_list_events(events
, count
);
1237 MSG("\n%sEvent rules:", indent4
);
1239 MSG("%sNone\n", indent6
);
1243 for (i
= 0; i
< count
; i
++) {
1244 print_events(&events
[i
]);
1256 void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1260 _MSG("%s%s:", indent6
, timer_name
);
1261 for (i
= 0; i
< space_count
; i
++) {
1266 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1273 * Pretty print channel
1275 static void print_channel(struct lttng_channel
*channel
)
1278 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1279 int64_t blocking_timeout
;
1281 ret
= lttng_channel_get_discarded_event_count(channel
,
1284 ERR("Failed to retrieve discarded event count of channel");
1288 ret
= lttng_channel_get_lost_packet_count(channel
,
1291 ERR("Failed to retrieve lost packet count of channel");
1295 ret
= lttng_channel_get_monitor_timer_interval(channel
,
1296 &monitor_timer_interval
);
1298 ERR("Failed to retrieve monitor interval of channel");
1302 ret
= lttng_channel_get_blocking_timeout(channel
,
1305 ERR("Failed to retrieve blocking timeout of channel");
1309 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1310 MSG("%sAttributes:", indent4
);
1311 MSG("%sEvent-loss mode: %s", indent6
, channel
->attr
.overwrite
? "overwrite" : "discard");
1312 MSG("%sSub-buffer size: %" PRIu64
" bytes", indent6
, channel
->attr
.subbuf_size
);
1313 MSG("%sSub-buffer count: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1315 print_timer("Switch timer", 5, channel
->attr
.switch_timer_interval
);
1316 print_timer("Read timer", 7, channel
->attr
.read_timer_interval
);
1317 print_timer("Monitor timer", 4, monitor_timer_interval
);
1319 if (!channel
->attr
.overwrite
) {
1320 if (blocking_timeout
== -1) {
1321 MSG("%sBlocking timeout: infinite", indent6
);
1323 MSG("%sBlocking timeout: %" PRId64
" %s", indent6
,
1324 blocking_timeout
, USEC_UNIT
);
1328 MSG("%sTrace file count: %" PRIu64
" per stream", indent6
,
1329 channel
->attr
.tracefile_count
== 0 ?
1330 1 : channel
->attr
.tracefile_count
);
1331 if (channel
->attr
.tracefile_size
!= 0 ) {
1332 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
,
1333 channel
->attr
.tracefile_size
);
1335 MSG("%sTrace file size: %s", indent6
, "unlimited");
1337 switch (channel
->attr
.output
) {
1338 case LTTNG_EVENT_SPLICE
:
1339 MSG("%sOutput mode: splice", indent6
);
1341 case LTTNG_EVENT_MMAP
:
1342 MSG("%sOutput mode: mmap", indent6
);
1346 MSG("\n%sStatistics:", indent4
);
1347 if (listed_session
.snapshot_mode
) {
1349 * The lost packet count is omitted for sessions in snapshot
1350 * mode as it is misleading: it would indicate the number of
1351 * packets that the consumer could not extract during the
1352 * course of recording the snapshot. It does not have the
1353 * same meaning as the "regular" lost packet count that
1354 * would result from the consumer not keeping up with
1355 * event production in an overwrite-mode channel.
1357 * A more interesting statistic would be the number of
1358 * packets lost between the first and last extracted
1359 * packets of a given snapshot (which prevents most analyses).
1361 MSG("%sNone", indent6
);
1362 goto skip_stats_printing
;
1365 if (!channel
->attr
.overwrite
) {
1366 MSG("%sDiscarded events: %" PRIu64
, indent6
, discarded_events
);
1368 MSG("%sLost packets: %" PRIu64
, indent6
, lost_packets
);
1370 skip_stats_printing
:
1376 * Print a list of channel
1379 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1380 const char *channel_name
)
1383 unsigned int chan_found
= 0;
1385 /* Open channels element */
1386 ret
= mi_lttng_channels_open(writer
);
1391 for (i
= 0; i
< count
; i
++) {
1392 if (channel_name
!= NULL
) {
1393 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1400 /* Write channel element and leave it open */
1401 ret
= mi_lttng_channel(writer
, &channels
[i
], 1);
1406 /* Listing events per channel */
1407 ret
= list_events(channels
[i
].name
);
1412 /* Closing the channel element we opened earlier */
1413 ret
= mi_lttng_writer_close_element(writer
);
1423 /* Close channels element */
1424 ret
= mi_lttng_writer_close_element(writer
);
1434 * List channel(s) of session and domain.
1436 * If channel_name is NULL, all channels are listed.
1438 static int list_channels(const char *channel_name
)
1440 int count
, i
, ret
= CMD_SUCCESS
;
1441 unsigned int chan_found
= 0;
1442 struct lttng_channel
*channels
= NULL
;
1444 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1446 count
= lttng_list_channels(handle
, &channels
);
1449 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1451 /* When printing mi this is not an error
1452 * but an empty channels element */
1456 WARN("No kernel channel");
1457 goto error_channels
;
1461 /* We had a real error */
1463 ERR("%s", lttng_strerror(count
));
1464 goto error_channels
;
1471 ret
= mi_list_channels(channels
, count
, channel_name
);
1479 MSG("Channels:\n-------------");
1482 for (i
= 0; i
< count
; i
++) {
1483 if (channel_name
!= NULL
) {
1484 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1490 print_channel(&channels
[i
]);
1492 /* Listing events per channel */
1493 ret
= list_events(channels
[i
].name
);
1503 if (!chan_found
&& channel_name
!= NULL
) {
1505 ERR("Channel %s not found", channel_name
);
1516 static const char *get_tracker_str(enum lttng_tracker_type tracker_type
)
1518 switch (tracker_type
) {
1519 case LTTNG_TRACKER_PID
:
1521 case LTTNG_TRACKER_VPID
:
1523 case LTTNG_TRACKER_UID
:
1525 case LTTNG_TRACKER_VUID
:
1527 case LTTNG_TRACKER_GID
:
1529 case LTTNG_TRACKER_VGID
:
1536 * List tracker ID(s) of session and domain.
1538 static int list_tracker_ids(enum lttng_tracker_type tracker_type
)
1542 struct lttng_tracker_ids
*ids
= NULL
;
1543 unsigned int nr_ids
, i
;
1544 const struct lttng_tracker_id
*id
;
1545 enum lttng_tracker_id_status status
;
1547 ret
= lttng_list_tracker_ids(handle
, tracker_type
, &ids
);
1552 status
= lttng_tracker_ids_get_count(ids
, &nr_ids
);
1553 if (status
!= LTTNG_TRACKER_ID_STATUS_OK
) {
1559 id
= lttng_tracker_ids_get_at_index(ids
, 0);
1560 if (id
&& lttng_tracker_id_get_type(id
) == LTTNG_ID_ALL
) {
1566 _MSG("%s tracker: [", get_tracker_str(tracker_type
));
1568 /* Mi tracker_id element */
1570 /* Open tracker_id and targets elements */
1571 ret
= mi_lttng_id_tracker_open(writer
, tracker_type
);
1577 for (i
= 0; i
< nr_ids
; i
++) {
1578 enum lttng_tracker_id_status status
=
1579 LTTNG_TRACKER_ID_STATUS_OK
;
1581 const char *value_string
;
1583 id
= lttng_tracker_ids_get_at_index(ids
, i
);
1589 switch (lttng_tracker_id_get_type(id
)) {
1592 case LTTNG_ID_VALUE
:
1593 status
= lttng_tracker_id_get_value(id
, &value
);
1595 case LTTNG_ID_STRING
:
1596 status
= lttng_tracker_id_get_string(
1599 case LTTNG_ID_UNKNOWN
:
1604 if (status
!= LTTNG_TRACKER_ID_STATUS_OK
) {
1605 ERR("Invalid state for tracker id");
1613 switch (lttng_tracker_id_get_type(id
)) {
1617 case LTTNG_ID_VALUE
:
1620 case LTTNG_ID_STRING
:
1621 _MSG(" %s", value_string
);
1623 case LTTNG_ID_UNKNOWN
:
1624 ERR("Invalid state for tracker id");
1631 ret
= mi_lttng_id_target(
1632 writer
, tracker_type
, id
, 0);
1640 /* Mi close tracker_id and targets */
1642 ret
= mi_lttng_close_multi_element(writer
, 2);
1649 lttng_tracker_ids_destroy(ids
);
1654 * List all trackers of a domain
1656 static int list_trackers(const struct lttng_domain
*domain
)
1660 /* Trackers listing */
1662 ret
= mi_lttng_trackers_open(writer
);
1668 switch (domain
->type
) {
1669 case LTTNG_DOMAIN_KERNEL
:
1671 ret
= list_tracker_ids(LTTNG_TRACKER_PID
);
1676 ret
= list_tracker_ids(LTTNG_TRACKER_VPID
);
1681 ret
= list_tracker_ids(LTTNG_TRACKER_UID
);
1686 ret
= list_tracker_ids(LTTNG_TRACKER_VUID
);
1691 ret
= list_tracker_ids(LTTNG_TRACKER_GID
);
1696 ret
= list_tracker_ids(LTTNG_TRACKER_VGID
);
1701 case LTTNG_DOMAIN_UST
:
1703 ret
= list_tracker_ids(LTTNG_TRACKER_VPID
);
1708 ret
= list_tracker_ids(LTTNG_TRACKER_VUID
);
1713 ret
= list_tracker_ids(LTTNG_TRACKER_VGID
);
1722 /* Close trackers element */
1723 ret
= mi_lttng_writer_close_element(writer
);
1733 static enum cmd_error_code
print_periodic_rotation_schedule(
1734 const struct lttng_rotation_schedule
*schedule
)
1736 enum cmd_error_code ret
;
1737 enum lttng_rotation_status status
;
1740 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1742 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1743 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1748 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
1754 static enum cmd_error_code
print_size_threshold_rotation_schedule(
1755 const struct lttng_rotation_schedule
*schedule
)
1757 enum cmd_error_code ret
;
1758 enum lttng_rotation_status status
;
1761 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
1763 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1764 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1769 MSG(" size threshold: %" PRIu64
" bytes", value
);
1775 static enum cmd_error_code
print_rotation_schedule(
1776 const struct lttng_rotation_schedule
*schedule
)
1778 enum cmd_error_code ret
;
1780 switch (lttng_rotation_schedule_get_type(schedule
)) {
1781 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1782 ret
= print_size_threshold_rotation_schedule(schedule
);
1784 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1785 ret
= print_periodic_rotation_schedule(schedule
);
1794 * List the automatic rotation settings.
1796 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1799 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1800 unsigned int count
, i
;
1801 struct lttng_rotation_schedules
*schedules
= NULL
;
1802 enum lttng_rotation_status status
;
1804 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1805 if (ret
!= LTTNG_OK
) {
1806 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1807 cmd_ret
= CMD_ERROR
;
1811 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1812 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1813 ERR("Failed to retrieve the number of session rotation schedules.");
1814 cmd_ret
= CMD_ERROR
;
1819 cmd_ret
= CMD_SUCCESS
;
1823 MSG("Automatic rotation schedules:");
1825 ret
= mi_lttng_writer_open_element(writer
,
1826 mi_lttng_element_rotation_schedules
);
1828 cmd_ret
= CMD_ERROR
;
1833 for (i
= 0; i
< count
; i
++) {
1834 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1835 const struct lttng_rotation_schedule
*schedule
;
1837 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1839 ERR("Failed to retrieve session rotation schedule.");
1840 cmd_ret
= CMD_ERROR
;
1845 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
1847 tmp_ret
= CMD_ERROR
;
1850 tmp_ret
= print_rotation_schedule(schedule
);
1854 * Report an error if the serialization of any of the
1855 * descriptors failed.
1857 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
1862 /* Close the rotation_schedules element. */
1863 ret
= mi_lttng_writer_close_element(writer
);
1865 cmd_ret
= CMD_ERROR
;
1870 lttng_rotation_schedules_destroy(schedules
);
1876 * Find the session with session_name as name
1877 * and print his informations.
1879 static int mi_list_session(const char *session_name
,
1880 struct lttng_session
*sessions
, int count
)
1883 unsigned int session_found
= 0;
1885 if (session_name
== NULL
) {
1886 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1890 for (i
= 0; i
< count
; i
++) {
1891 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1892 /* We need to leave it open to append other informations
1893 * like domain, channel, events etc.*/
1895 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
1903 if (!session_found
) {
1904 ERR("Session '%s' not found", session_name
);
1905 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1915 * List all availables session
1917 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
1921 /* Opening sessions element */
1922 ret
= mi_lttng_sessions_open(writer
);
1927 /* Listing sessions */
1928 for (i
= 0; i
< count
; i
++) {
1929 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
1935 /* Closing sessions element */
1936 ret
= mi_lttng_writer_close_element(writer
);
1946 * List available tracing session. List only basic information.
1948 * If session_name is NULL, all sessions are listed.
1950 static int list_sessions(const char *session_name
)
1952 int ret
= CMD_SUCCESS
;
1954 unsigned int session_found
= 0;
1955 struct lttng_session
*sessions
= NULL
;
1957 count
= lttng_list_sessions(&sessions
);
1958 DBG("Session count %d", count
);
1961 ERR("%s", lttng_strerror(count
));
1967 if (session_name
== NULL
) {
1968 /* List all sessions */
1969 ret
= mi_list_sessions(sessions
, count
);
1971 /* Note : this return an open session element */
1972 ret
= mi_list_session(session_name
, sessions
, count
);
1981 MSG("Currently no available tracing session");
1985 if (session_name
== NULL
) {
1986 MSG("Available tracing sessions:");
1989 for (i
= 0; i
< count
; i
++) {
1990 if (session_name
!= NULL
) {
1991 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1993 MSG("Tracing session %s: [%s%s]", session_name
,
1994 active_string(sessions
[i
].enabled
),
1995 snapshot_string(sessions
[i
].snapshot_mode
));
1996 if (*sessions
[i
].path
) {
1997 MSG("%sTrace output: %s\n", indent4
, sessions
[i
].path
);
1999 memcpy(&listed_session
, &sessions
[i
],
2000 sizeof(listed_session
));
2004 MSG(" %d) %s [%s%s]", i
+ 1,
2006 active_string(sessions
[i
].enabled
),
2007 snapshot_string(sessions
[i
].snapshot_mode
));
2008 if (*sessions
[i
].path
) {
2009 MSG("%sTrace output: %s", indent4
, sessions
[i
].path
);
2011 if (sessions
[i
].live_timer_interval
!= 0) {
2012 MSG("%sLive timer interval: %u %s", indent4
,
2013 sessions
[i
].live_timer_interval
,
2020 if (!session_found
&& session_name
!= NULL
) {
2021 ERR("Session '%s' not found", session_name
);
2026 if (session_name
== NULL
) {
2027 MSG("\nUse lttng list <session_name> for more details");
2039 * list available domain(s) for a session.
2041 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
2044 /* Open domains element */
2045 ret
= mi_lttng_domains_open(writer
);
2050 for (i
= 0; i
< count
; i
++) {
2051 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
2057 /* Closing domains element */
2058 ret
= mi_lttng_writer_close_element(writer
);
2067 * List available domain(s) for a session.
2069 static int list_domains(const char *session_name
)
2071 int i
, count
, ret
= CMD_SUCCESS
;
2072 struct lttng_domain
*domains
= NULL
;
2075 count
= lttng_list_domains(session_name
, &domains
);
2078 ERR("%s", lttng_strerror(count
));
2084 ret
= mi_list_domains(domains
, count
);
2091 MSG("Domains:\n-------------");
2097 for (i
= 0; i
< count
; i
++) {
2098 switch (domains
[i
].type
) {
2099 case LTTNG_DOMAIN_KERNEL
:
2102 case LTTNG_DOMAIN_UST
:
2103 MSG(" - UST global");
2105 case LTTNG_DOMAIN_JUL
:
2106 MSG(" - JUL (Java Util Logging)");
2108 case LTTNG_DOMAIN_LOG4J
:
2109 MSG(" - LOG4j (Logging for Java)");
2111 case LTTNG_DOMAIN_PYTHON
:
2112 MSG(" - Python (logging)");
2128 * The 'list <options>' first level command
2130 int cmd_list(int argc
, const char **argv
)
2132 int opt
, ret
= CMD_SUCCESS
;
2133 const char *session_name
, *leftover
= NULL
;
2134 static poptContext pc
;
2135 struct lttng_domain domain
;
2136 struct lttng_domain
*domains
= NULL
;
2138 memset(&domain
, 0, sizeof(domain
));
2145 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2146 poptReadDefaultConfig(pc
, 0);
2148 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2156 case OPT_LIST_OPTIONS
:
2157 list_cmd_options(stdout
, long_options
);
2160 ret
= CMD_UNDEFINED
;
2167 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
2173 /* Open command element */
2174 ret
= mi_lttng_writer_command_open(writer
,
2175 mi_lttng_element_command_list
);
2181 /* Open output element */
2182 ret
= mi_lttng_writer_open_element(writer
,
2183 mi_lttng_element_command_output
);
2190 /* Get session name (trailing argument) */
2191 session_name
= poptGetArg(pc
);
2192 DBG2("Session name: %s", session_name
);
2194 leftover
= poptGetArg(pc
);
2196 ERR("Unknown argument: %s", leftover
);
2202 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2203 } else if (opt_userspace
) {
2204 DBG2("Listing userspace global domain");
2205 domain
.type
= LTTNG_DOMAIN_UST
;
2206 } else if (opt_jul
) {
2207 DBG2("Listing JUL domain");
2208 domain
.type
= LTTNG_DOMAIN_JUL
;
2209 } else if (opt_log4j
) {
2210 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2211 } else if (opt_python
) {
2212 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2215 if (!opt_kernel
&& opt_syscall
) {
2216 WARN("--syscall will only work with the Kernel domain (-k)");
2221 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2222 handle
= lttng_create_handle(session_name
, &domain
);
2223 if (handle
== NULL
) {
2229 if (session_name
== NULL
) {
2230 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2232 ret
= list_sessions(NULL
);
2239 ret
= list_syscalls();
2244 ret
= list_kernel_events();
2250 if (opt_userspace
) {
2252 ret
= list_ust_event_fields();
2254 ret
= list_ust_events();
2260 if (opt_jul
|| opt_log4j
|| opt_python
) {
2261 ret
= list_agent_events();
2267 /* List session attributes */
2269 /* Open element sessions
2270 * Present for xml consistency */
2271 ret
= mi_lttng_sessions_open(writer
);
2276 /* MI: the ouptut of list_sessions is an unclosed session element */
2277 ret
= list_sessions(session_name
);
2282 ret
= list_rotate_settings(session_name
);
2287 /* Domain listing */
2289 ret
= list_domains(session_name
);
2293 /* Channel listing */
2294 if (opt_kernel
|| opt_userspace
) {
2296 /* Add of domains and domain element for xml
2297 * consistency and validation
2299 ret
= mi_lttng_domains_open(writer
);
2304 /* Open domain and leave it open for
2305 * nested channels printing */
2306 ret
= mi_lttng_domain(writer
, &domain
, 1);
2315 ret
= list_trackers(&domain
);
2321 ret
= list_channels(opt_channel
);
2327 /* Close domain and domain element */
2328 ret
= mi_lttng_close_multi_element(writer
, 2);
2338 /* We want all domain(s) */
2339 nb_domain
= lttng_list_domains(session_name
, &domains
);
2340 if (nb_domain
< 0) {
2342 ERR("%s", lttng_strerror(nb_domain
));
2347 ret
= mi_lttng_domains_open(writer
);
2354 for (i
= 0; i
< nb_domain
; i
++) {
2355 switch (domains
[i
].type
) {
2356 case LTTNG_DOMAIN_KERNEL
:
2357 MSG("=== Domain: Kernel ===\n");
2359 case LTTNG_DOMAIN_UST
:
2360 MSG("=== Domain: UST global ===\n");
2361 MSG("Buffer type: %s\n",
2362 domains
[i
].buf_type
==
2363 LTTNG_BUFFER_PER_PID
? "per PID" : "per UID");
2365 case LTTNG_DOMAIN_JUL
:
2366 MSG("=== Domain: JUL (Java Util Logging) ===\n");
2368 case LTTNG_DOMAIN_LOG4J
:
2369 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
2371 case LTTNG_DOMAIN_PYTHON
:
2372 MSG("=== Domain: Python (logging) ===\n");
2375 MSG("=== Domain: Unimplemented ===\n");
2380 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
2387 /* Clean handle before creating a new one */
2389 lttng_destroy_handle(handle
);
2392 handle
= lttng_create_handle(session_name
, &domains
[i
]);
2393 if (handle
== NULL
) {
2398 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2399 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2400 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2401 ret
= list_session_agent_events();
2409 switch (domains
[i
].type
) {
2410 case LTTNG_DOMAIN_KERNEL
:
2411 case LTTNG_DOMAIN_UST
:
2412 ret
= list_trackers(&domains
[i
]);
2421 ret
= list_channels(opt_channel
);
2428 /* Close domain element */
2429 ret
= mi_lttng_writer_close_element(writer
);
2438 /* Close the domains, session and sessions element */
2439 ret
= mi_lttng_close_multi_element(writer
, 3);
2450 /* Close output element */
2451 ret
= mi_lttng_writer_close_element(writer
);
2457 /* Command element close */
2458 ret
= mi_lttng_writer_command_close(writer
);
2466 if (writer
&& mi_lttng_writer_destroy(writer
)) {
2467 /* Preserve original error code */
2468 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2473 lttng_destroy_handle(handle
);
2476 poptFreeContext(pc
);