2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
18 #include <common/mi-lttng.h>
19 #include <common/time.h>
20 #include <common/tracker.h>
21 #include <lttng/constant.h>
22 #include <lttng/tracker.h>
24 #include "../command.h"
26 static int opt_userspace
;
27 static int opt_kernel
;
30 static int opt_python
;
31 static char *opt_channel
;
32 static int opt_domain
;
33 static int opt_fields
;
34 static int opt_syscall
;
36 const char *indent4
= " ";
37 const char *indent6
= " ";
38 const char *indent8
= " ";
40 #ifdef LTTNG_EMBED_HELP
41 static const char help_msg
[] =
42 #include <lttng-list.1.h>
52 static struct lttng_handle
*handle
;
53 static struct mi_writer
*writer
;
55 /* Only set when listing a single session. */
56 static struct lttng_session listed_session
;
58 static struct poptOption long_options
[] = {
59 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
60 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
61 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
62 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
63 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
64 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
65 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
66 {"channel", 'c', POPT_ARG_STRING
, &opt_channel
, 0, 0, 0},
67 {"domain", 'd', POPT_ARG_VAL
, &opt_domain
, 1, 0, 0},
68 {"fields", 'f', POPT_ARG_VAL
, &opt_fields
, 1, 0, 0},
69 {"syscall", 'S', POPT_ARG_VAL
, &opt_syscall
, 1, 0, 0},
70 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
75 * Get command line from /proc for a specific pid.
77 * On success, return an allocated string pointer to the proc cmdline.
78 * On error, return NULL.
80 static char *get_cmdline_by_pid(pid_t pid
)
85 /* Can't go bigger than /proc/LTTNG_MAX_PID/cmdline */
86 char path
[sizeof("/proc//cmdline") + sizeof(LTTNG_MAX_PID_STR
) - 1];
88 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pid
);
89 fp
= fopen(path
, "r");
94 /* Caller must free() *cmdline */
95 cmdline
= zmalloc(PATH_MAX
);
97 PERROR("malloc cmdline");
100 ret
= fread(cmdline
, 1, PATH_MAX
, fp
);
102 PERROR("fread proc list");
113 const char *active_string(int value
)
116 case 0: return "inactive";
117 case 1: return "active";
119 default: return NULL
;
123 static const char *snapshot_string(int value
)
134 const char *enabled_string(int value
)
137 case 0: return " [disabled]";
138 case 1: return " [enabled]";
140 default: return NULL
;
145 const char *safe_string(const char *str
)
147 return str
? str
: "";
150 static const char *logleveltype_string(enum lttng_loglevel_type value
)
153 case LTTNG_EVENT_LOGLEVEL_ALL
:
155 case LTTNG_EVENT_LOGLEVEL_RANGE
:
157 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
160 return " <<TYPE UNKN>>";
164 static const char *bitness_event(enum lttng_event_flag flags
)
166 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_32
) {
167 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
168 return " [32/64-bit]";
172 } else if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
180 * Get exclusion names message for a single event.
182 * Returned pointer must be freed by caller. Returns NULL on error.
184 static char *get_exclusion_names_msg(struct lttng_event
*event
)
188 char *exclusion_msg
= NULL
;
191 const char * const exclusion_fmt
= " [exclusions: ";
192 const size_t exclusion_fmt_len
= strlen(exclusion_fmt
);
194 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
195 if (exclusion_count
< 0) {
197 } else if (exclusion_count
== 0) {
199 * No exclusions: return copy of empty string so that
200 * it can be freed by caller.
202 exclusion_msg
= strdup("");
207 * exclusion_msg's size is bounded by the exclusion_fmt string,
208 * a comma per entry, the entry count (fixed-size), a closing
209 * bracket, and a trailing \0.
211 exclusion_msg
= malloc(exclusion_count
+
212 exclusion_count
* LTTNG_SYMBOL_NAME_LEN
+
213 exclusion_fmt_len
+ 1);
214 if (!exclusion_msg
) {
218 at
= strcpy(exclusion_msg
, exclusion_fmt
) + exclusion_fmt_len
;
219 for (i
= 0; i
< exclusion_count
; ++i
) {
222 /* Append comma between exclusion names */
228 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
230 /* Prints '?' on local error; should never happen */
236 /* Append exclusion name */
237 at
+= sprintf(at
, "%s", name
);
240 /* This also puts a final '\0' at the end of exclusion_msg */
244 return exclusion_msg
;
247 static void print_userspace_probe_location(struct lttng_event
*event
)
249 const struct lttng_userspace_probe_location
*location
;
250 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
251 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
253 location
= lttng_event_get_userspace_probe_location(event
);
255 MSG("Event has no userspace probe location");
259 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
260 if (!lookup_method
) {
261 MSG("Event has no userspace probe location lookup method");
265 MSG("%s%s (type: userspace-probe)%s", indent6
, event
->name
, enabled_string(event
->enabled
));
267 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
269 switch (lttng_userspace_probe_location_get_type(location
)) {
270 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
:
271 MSG("%sType: Unknown", indent8
);
273 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
275 const char *function_name
;
276 const char *binary_path
;
278 MSG("%sType: Function", indent8
);
279 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
280 binary_path
= realpath(lttng_userspace_probe_location_function_get_binary_path(location
), NULL
);
282 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
283 MSG("%sFunction: %s()", indent8
, function_name
? function_name
: "NULL");
284 switch (lookup_type
) {
285 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
286 MSG("%sLookup method: ELF", indent8
);
288 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
289 MSG("%sLookup method: default", indent8
);
292 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
297 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
299 const char *probe_name
, *provider_name
;
300 const char *binary_path
;
302 MSG("%sType: Tracepoint", indent8
);
303 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
304 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
305 binary_path
= realpath(lttng_userspace_probe_location_tracepoint_get_binary_path(location
), NULL
);
306 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
307 MSG("%sTracepoint: %s:%s", indent8
, provider_name
? provider_name
: "NULL", probe_name
? probe_name
: "NULL");
308 switch (lookup_type
) {
309 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
310 MSG("%sLookup method: SDT", indent8
);
313 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
319 ERR("Invalid probe type encountered");
324 * Pretty print single event.
326 static void print_events(struct lttng_event
*event
)
329 const char *filter_str
;
330 char *filter_msg
= NULL
;
331 char *exclusion_msg
= NULL
;
333 ret
= lttng_event_get_filter_expression(event
, &filter_str
);
336 filter_msg
= strdup(" [failed to retrieve filter]");
337 } else if (filter_str
) {
338 const char * const filter_fmt
= " [filter: '%s']";
340 filter_msg
= malloc(strlen(filter_str
) +
341 strlen(filter_fmt
) + 1);
343 sprintf(filter_msg
, filter_fmt
,
348 exclusion_msg
= get_exclusion_names_msg(event
);
349 if (!exclusion_msg
) {
350 exclusion_msg
= strdup(" [failed to retrieve exclusions]");
353 switch (event
->type
) {
354 case LTTNG_EVENT_TRACEPOINT
:
356 if (event
->loglevel
!= -1) {
357 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
360 logleveltype_string(event
->loglevel_type
),
361 mi_lttng_loglevel_string(event
->loglevel
, handle
->domain
.type
),
363 enabled_string(event
->enabled
),
364 safe_string(exclusion_msg
),
365 safe_string(filter_msg
));
367 MSG("%s%s (type: tracepoint)%s%s%s",
370 enabled_string(event
->enabled
),
371 safe_string(exclusion_msg
),
372 safe_string(filter_msg
));
376 case LTTNG_EVENT_FUNCTION
:
377 MSG("%s%s (type: function)%s%s", indent6
,
378 event
->name
, enabled_string(event
->enabled
),
379 safe_string(filter_msg
));
380 if (event
->attr
.probe
.addr
!= 0) {
381 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
383 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
384 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
387 case LTTNG_EVENT_PROBE
:
388 MSG("%s%s (type: probe)%s%s", indent6
,
389 event
->name
, enabled_string(event
->enabled
),
390 safe_string(filter_msg
));
391 if (event
->attr
.probe
.addr
!= 0) {
392 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
394 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
395 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
398 case LTTNG_EVENT_USERSPACE_PROBE
:
399 print_userspace_probe_location(event
);
401 case LTTNG_EVENT_FUNCTION_ENTRY
:
402 MSG("%s%s (type: function)%s%s", indent6
,
403 event
->name
, enabled_string(event
->enabled
),
404 safe_string(filter_msg
));
405 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
407 case LTTNG_EVENT_SYSCALL
:
408 MSG("%s%s%s%s%s%s", indent6
, event
->name
,
409 (opt_syscall
? "" : " (type:syscall)"),
410 enabled_string(event
->enabled
),
411 bitness_event(event
->flags
),
412 safe_string(filter_msg
));
414 case LTTNG_EVENT_NOOP
:
415 MSG("%s (type: noop)%s%s", indent6
,
416 enabled_string(event
->enabled
),
417 safe_string(filter_msg
));
419 case LTTNG_EVENT_ALL
:
422 /* We should never have "all" events in list. */
431 static const char *field_type(struct lttng_event_field
*field
)
433 switch(field
->type
) {
434 case LTTNG_EVENT_FIELD_INTEGER
:
436 case LTTNG_EVENT_FIELD_ENUM
:
438 case LTTNG_EVENT_FIELD_FLOAT
:
440 case LTTNG_EVENT_FIELD_STRING
:
442 case LTTNG_EVENT_FIELD_OTHER
:
443 default: /* fall-through */
449 * Pretty print single event fields.
451 static void print_event_field(struct lttng_event_field
*field
)
453 if (!field
->field_name
[0]) {
456 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
457 field_type(field
), field
->nowrite
? " [no write]" : "");
462 * Jul and ust event listing
464 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
465 struct lttng_domain
*domain
)
469 char *cmdline
= NULL
;
470 int pid_element_open
= 0;
472 /* Open domains element */
473 ret
= mi_lttng_domains_open(writer
);
479 ret
= mi_lttng_domain(writer
, domain
, 1);
484 /* Open pids element element */
485 ret
= mi_lttng_pids_open(writer
);
490 for (i
= 0; i
< count
; i
++) {
491 if (cur_pid
!= events
[i
].pid
) {
492 if (pid_element_open
) {
493 /* Close the previous events and pid element */
494 ret
= mi_lttng_close_multi_element(writer
, 2);
498 pid_element_open
= 0;
501 cur_pid
= events
[i
].pid
;
502 cmdline
= get_cmdline_by_pid(cur_pid
);
508 if (!pid_element_open
) {
509 /* Open and write a pid element */
510 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
515 /* Open events element */
516 ret
= mi_lttng_events_open(writer
);
521 pid_element_open
= 1;
527 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
534 ret
= mi_lttng_writer_close_element(writer
);
539 /* Close domain, domains */
540 ret
= mi_lttng_close_multi_element(writer
, 2);
548 static int list_agent_events(void)
550 int i
, size
, ret
= CMD_SUCCESS
;
551 struct lttng_domain domain
;
552 struct lttng_handle
*handle
= NULL
;
553 struct lttng_event
*event_list
= NULL
;
555 char *cmdline
= NULL
;
556 const char *agent_domain_str
;
558 memset(&domain
, 0, sizeof(domain
));
560 domain
.type
= LTTNG_DOMAIN_JUL
;
561 } else if (opt_log4j
) {
562 domain
.type
= LTTNG_DOMAIN_LOG4J
;
563 } else if (opt_python
) {
564 domain
.type
= LTTNG_DOMAIN_PYTHON
;
566 ERR("Invalid agent domain selected.");
571 agent_domain_str
= get_domain_str(domain
.type
);
573 DBG("Getting %s tracing events", agent_domain_str
);
575 handle
= lttng_create_handle(NULL
, &domain
);
576 if (handle
== NULL
) {
581 size
= lttng_list_tracepoints(handle
, &event_list
);
583 ERR("Unable to list %s events: %s", agent_domain_str
,
584 lttng_strerror(size
));
591 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
598 MSG("%s events (Logger name):\n-------------------------",
605 for (i
= 0; i
< size
; i
++) {
606 if (cur_pid
!= event_list
[i
].pid
) {
607 cur_pid
= event_list
[i
].pid
;
608 cmdline
= get_cmdline_by_pid(cur_pid
);
609 if (cmdline
== NULL
) {
613 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
616 MSG("%s- %s", indent6
, event_list
[i
].name
);
625 lttng_destroy_handle(handle
);
630 * Ask session daemon for all user space tracepoints available.
632 static int list_ust_events(void)
634 int i
, size
, ret
= CMD_SUCCESS
;
635 struct lttng_domain domain
;
636 struct lttng_handle
*handle
;
637 struct lttng_event
*event_list
= NULL
;
639 char *cmdline
= NULL
;
641 memset(&domain
, 0, sizeof(domain
));
643 DBG("Getting UST tracing events");
645 domain
.type
= LTTNG_DOMAIN_UST
;
647 handle
= lttng_create_handle(NULL
, &domain
);
648 if (handle
== NULL
) {
653 size
= lttng_list_tracepoints(handle
, &event_list
);
655 ERR("Unable to list UST events: %s", lttng_strerror(size
));
662 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
665 MSG("UST events:\n-------------");
671 for (i
= 0; i
< size
; i
++) {
672 if (cur_pid
!= event_list
[i
].pid
) {
673 cur_pid
= event_list
[i
].pid
;
674 cmdline
= get_cmdline_by_pid(cur_pid
);
675 if (cmdline
== NULL
) {
679 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
682 print_events(&event_list
[i
]);
691 lttng_destroy_handle(handle
);
697 * List all ust event with their fields
699 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
700 struct lttng_domain
*domain
)
704 char *cmdline
= NULL
;
705 int pid_element_open
= 0;
706 int event_element_open
= 0;
707 struct lttng_event cur_event
;
709 memset(&cur_event
, 0, sizeof(cur_event
));
711 /* Open domains element */
712 ret
= mi_lttng_domains_open(writer
);
718 ret
= mi_lttng_domain(writer
, domain
, 1);
723 /* Open pids element */
724 ret
= mi_lttng_pids_open(writer
);
729 for (i
= 0; i
< count
; i
++) {
730 if (cur_pid
!= fields
[i
].event
.pid
) {
731 if (pid_element_open
) {
732 if (event_element_open
) {
733 /* Close the previous field element and event. */
734 ret
= mi_lttng_close_multi_element(writer
, 2);
738 event_element_open
= 0;
740 /* Close the previous events, pid element */
741 ret
= mi_lttng_close_multi_element(writer
, 2);
745 pid_element_open
= 0;
748 cur_pid
= fields
[i
].event
.pid
;
749 cmdline
= get_cmdline_by_pid(cur_pid
);
750 if (!pid_element_open
) {
751 /* Open and write a pid element */
752 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
757 /* Open events element */
758 ret
= mi_lttng_events_open(writer
);
762 pid_element_open
= 1;
765 /* Wipe current event since we are about to print a new PID. */
766 memset(&cur_event
, 0, sizeof(cur_event
));
769 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
770 if (event_element_open
) {
771 /* Close the previous fields element and the previous event */
772 ret
= mi_lttng_close_multi_element(writer
, 2);
776 event_element_open
= 0;
779 memcpy(&cur_event
, &fields
[i
].event
,
782 if (!event_element_open
) {
783 /* Open and write the event */
784 ret
= mi_lttng_event(writer
, &cur_event
, 1,
785 handle
->domain
.type
);
790 /* Open a fields element */
791 ret
= mi_lttng_event_fields_open(writer
);
795 event_element_open
= 1;
799 /* Print the event_field */
800 ret
= mi_lttng_event_field(writer
, &fields
[i
]);
806 /* Close pids, domain, domains */
807 ret
= mi_lttng_close_multi_element(writer
, 3);
816 * Ask session daemon for all user space tracepoint fields available.
818 static int list_ust_event_fields(void)
820 int i
, size
, ret
= CMD_SUCCESS
;
821 struct lttng_domain domain
;
822 struct lttng_handle
*handle
;
823 struct lttng_event_field
*event_field_list
;
825 char *cmdline
= NULL
;
827 struct lttng_event cur_event
;
829 memset(&domain
, 0, sizeof(domain
));
830 memset(&cur_event
, 0, sizeof(cur_event
));
832 DBG("Getting UST tracing event fields");
834 domain
.type
= LTTNG_DOMAIN_UST
;
836 handle
= lttng_create_handle(NULL
, &domain
);
837 if (handle
== NULL
) {
842 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
844 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
851 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
858 MSG("UST events:\n-------------");
864 for (i
= 0; i
< size
; i
++) {
865 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
866 cur_pid
= event_field_list
[i
].event
.pid
;
867 cmdline
= get_cmdline_by_pid(cur_pid
);
868 if (cmdline
== NULL
) {
872 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
874 /* Wipe current event since we are about to print a new PID. */
875 memset(&cur_event
, 0, sizeof(cur_event
));
877 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
878 print_events(&event_field_list
[i
].event
);
879 memcpy(&cur_event
, &event_field_list
[i
].event
,
882 print_event_field(&event_field_list
[i
]);
889 free(event_field_list
);
891 lttng_destroy_handle(handle
);
897 * Print a list of kernel events
899 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
900 struct lttng_domain
*domain
)
904 /* Open domains element */
905 ret
= mi_lttng_domains_open(writer
);
911 ret
= mi_lttng_domain(writer
, domain
, 1);
917 ret
= mi_lttng_events_open(writer
);
922 for (i
= 0; i
< count
; i
++) {
923 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
929 /* close events, domain and domains */
930 ret
= mi_lttng_close_multi_element(writer
, 3);
940 * Ask for all trace events in the kernel
942 static int list_kernel_events(void)
944 int i
, size
, ret
= CMD_SUCCESS
;
945 struct lttng_domain domain
;
946 struct lttng_handle
*handle
;
947 struct lttng_event
*event_list
;
949 memset(&domain
, 0, sizeof(domain
));
951 DBG("Getting kernel tracing events");
953 domain
.type
= LTTNG_DOMAIN_KERNEL
;
955 handle
= lttng_create_handle(NULL
, &domain
);
956 if (handle
== NULL
) {
961 size
= lttng_list_tracepoints(handle
, &event_list
);
963 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
964 lttng_destroy_handle(handle
);
970 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
976 MSG("Kernel events:\n-------------");
978 for (i
= 0; i
< size
; i
++) {
979 print_events(&event_list
[i
]);
988 lttng_destroy_handle(handle
);
992 lttng_destroy_handle(handle
);
998 * Print a list of system calls.
1000 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1005 ret
= mi_lttng_events_open(writer
);
1010 for (i
= 0; i
< count
; i
++) {
1011 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1018 ret
= mi_lttng_writer_close_element(writer
);
1028 * Ask for kernel system calls.
1030 static int list_syscalls(void)
1032 int i
, size
, ret
= CMD_SUCCESS
;
1033 struct lttng_event
*event_list
;
1035 DBG("Getting kernel system call events");
1037 size
= lttng_list_syscalls(&event_list
);
1039 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1046 ret
= mi_list_syscalls(event_list
, size
);
1052 MSG("System calls:\n-------------");
1054 for (i
= 0; i
< size
; i
++) {
1055 print_events(&event_list
[i
]);
1071 * Print a list of agent events
1073 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1077 /* Open events element */
1078 ret
= mi_lttng_events_open(writer
);
1083 for (i
= 0; i
< count
; i
++) {
1084 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1090 /* Close events element */
1091 ret
= mi_lttng_writer_close_element(writer
);
1098 * List agent events for a specific session using the handle.
1100 * Return CMD_SUCCESS on success else a negative value.
1102 static int list_session_agent_events(void)
1104 int ret
= CMD_SUCCESS
, count
, i
;
1105 struct lttng_event
*events
= NULL
;
1107 count
= lttng_list_events(handle
, "", &events
);
1110 ERR("%s", lttng_strerror(count
));
1116 ret
= mi_list_session_agent_events(events
, count
);
1123 MSG("Events (Logger name):\n---------------------");
1125 MSG("%sNone\n", indent6
);
1129 for (i
= 0; i
< count
; i
++) {
1130 const char *filter_str
;
1131 char *filter_msg
= NULL
;
1132 struct lttng_event
*event
= &events
[i
];
1134 ret
= lttng_event_get_filter_expression(event
,
1137 filter_msg
= strdup(" [failed to retrieve filter]");
1138 } else if (filter_str
) {
1139 const char * const filter_fmt
=
1142 filter_msg
= malloc(strlen(filter_str
) +
1143 strlen(filter_fmt
) + 1);
1145 sprintf(filter_msg
, filter_fmt
,
1150 if (event
->loglevel_type
!=
1151 LTTNG_EVENT_LOGLEVEL_ALL
) {
1152 MSG("%s- %s%s (loglevel%s %s)%s", indent4
,
1154 enabled_string(event
->enabled
),
1155 logleveltype_string(
1156 event
->loglevel_type
),
1157 mi_lttng_loglevel_string(
1159 handle
->domain
.type
),
1160 safe_string(filter_msg
));
1162 MSG("%s- %s%s%s", indent4
, event
->name
,
1163 enabled_string(event
->enabled
),
1164 safe_string(filter_msg
));
1180 * print a list of event
1182 static int mi_list_events(struct lttng_event
*events
, int count
)
1186 /* Open events element */
1187 ret
= mi_lttng_events_open(writer
);
1192 for (i
= 0; i
< count
; i
++) {
1193 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1199 /* Close events element */
1200 ret
= mi_lttng_writer_close_element(writer
);
1207 * List events of channel of session and domain.
1209 static int list_events(const char *channel_name
)
1211 int ret
= CMD_SUCCESS
, count
, i
;
1212 struct lttng_event
*events
= NULL
;
1214 count
= lttng_list_events(handle
, channel_name
, &events
);
1217 ERR("%s", lttng_strerror(count
));
1223 ret
= mi_list_events(events
, count
);
1230 MSG("\n%sEvent rules:", indent4
);
1232 MSG("%sNone\n", indent6
);
1236 for (i
= 0; i
< count
; i
++) {
1237 print_events(&events
[i
]);
1249 void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1253 _MSG("%s%s:", indent6
, timer_name
);
1254 for (i
= 0; i
< space_count
; i
++) {
1259 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1266 * Pretty print channel
1268 static void print_channel(struct lttng_channel
*channel
)
1271 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1272 int64_t blocking_timeout
;
1274 ret
= lttng_channel_get_discarded_event_count(channel
,
1277 ERR("Failed to retrieve discarded event count of channel");
1281 ret
= lttng_channel_get_lost_packet_count(channel
,
1284 ERR("Failed to retrieve lost packet count of channel");
1288 ret
= lttng_channel_get_monitor_timer_interval(channel
,
1289 &monitor_timer_interval
);
1291 ERR("Failed to retrieve monitor interval of channel");
1295 ret
= lttng_channel_get_blocking_timeout(channel
,
1298 ERR("Failed to retrieve blocking timeout of channel");
1302 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1303 MSG("%sAttributes:", indent4
);
1304 MSG("%sEvent-loss mode: %s", indent6
, channel
->attr
.overwrite
? "overwrite" : "discard");
1305 MSG("%sSub-buffer size: %" PRIu64
" bytes", indent6
, channel
->attr
.subbuf_size
);
1306 MSG("%sSub-buffer count: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1308 print_timer("Switch timer", 5, channel
->attr
.switch_timer_interval
);
1309 print_timer("Read timer", 7, channel
->attr
.read_timer_interval
);
1310 print_timer("Monitor timer", 4, monitor_timer_interval
);
1312 if (!channel
->attr
.overwrite
) {
1313 if (blocking_timeout
== -1) {
1314 MSG("%sBlocking timeout: infinite", indent6
);
1316 MSG("%sBlocking timeout: %" PRId64
" %s", indent6
,
1317 blocking_timeout
, USEC_UNIT
);
1321 MSG("%sTrace file count: %" PRIu64
" per stream", indent6
,
1322 channel
->attr
.tracefile_count
== 0 ?
1323 1 : channel
->attr
.tracefile_count
);
1324 if (channel
->attr
.tracefile_size
!= 0 ) {
1325 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
,
1326 channel
->attr
.tracefile_size
);
1328 MSG("%sTrace file size: %s", indent6
, "unlimited");
1330 switch (channel
->attr
.output
) {
1331 case LTTNG_EVENT_SPLICE
:
1332 MSG("%sOutput mode: splice", indent6
);
1334 case LTTNG_EVENT_MMAP
:
1335 MSG("%sOutput mode: mmap", indent6
);
1339 MSG("\n%sStatistics:", indent4
);
1340 if (listed_session
.snapshot_mode
) {
1342 * The lost packet count is omitted for sessions in snapshot
1343 * mode as it is misleading: it would indicate the number of
1344 * packets that the consumer could not extract during the
1345 * course of recording the snapshot. It does not have the
1346 * same meaning as the "regular" lost packet count that
1347 * would result from the consumer not keeping up with
1348 * event production in an overwrite-mode channel.
1350 * A more interesting statistic would be the number of
1351 * packets lost between the first and last extracted
1352 * packets of a given snapshot (which prevents most analyses).
1354 MSG("%sNone", indent6
);
1355 goto skip_stats_printing
;
1358 if (!channel
->attr
.overwrite
) {
1359 MSG("%sDiscarded events: %" PRIu64
, indent6
, discarded_events
);
1361 MSG("%sLost packets: %" PRIu64
, indent6
, lost_packets
);
1363 skip_stats_printing
:
1369 * Print a list of channel
1372 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1373 const char *channel_name
)
1376 unsigned int chan_found
= 0;
1378 /* Open channels element */
1379 ret
= mi_lttng_channels_open(writer
);
1384 for (i
= 0; i
< count
; i
++) {
1385 if (channel_name
!= NULL
) {
1386 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1393 /* Write channel element and leave it open */
1394 ret
= mi_lttng_channel(writer
, &channels
[i
], 1);
1399 /* Listing events per channel */
1400 ret
= list_events(channels
[i
].name
);
1405 /* Closing the channel element we opened earlier */
1406 ret
= mi_lttng_writer_close_element(writer
);
1416 /* Close channels element */
1417 ret
= mi_lttng_writer_close_element(writer
);
1427 * List channel(s) of session and domain.
1429 * If channel_name is NULL, all channels are listed.
1431 static int list_channels(const char *channel_name
)
1433 int count
, i
, ret
= CMD_SUCCESS
;
1434 unsigned int chan_found
= 0;
1435 struct lttng_channel
*channels
= NULL
;
1437 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1439 count
= lttng_list_channels(handle
, &channels
);
1442 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1444 /* When printing mi this is not an error
1445 * but an empty channels element */
1449 goto error_channels
;
1453 /* We had a real error */
1455 ERR("%s", lttng_strerror(count
));
1456 goto error_channels
;
1463 ret
= mi_list_channels(channels
, count
, channel_name
);
1471 MSG("Channels:\n-------------");
1474 for (i
= 0; i
< count
; i
++) {
1475 if (channel_name
!= NULL
) {
1476 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1482 print_channel(&channels
[i
]);
1484 /* Listing events per channel */
1485 ret
= list_events(channels
[i
].name
);
1495 if (!chan_found
&& channel_name
!= NULL
) {
1497 ERR("Channel %s not found", channel_name
);
1508 static const char *get_capitalized_process_attr_str(enum lttng_process_attr process_attr
)
1510 switch (process_attr
) {
1511 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1512 return "Process ID";
1513 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1514 return "Virtual process ID";
1515 case LTTNG_PROCESS_ATTR_USER_ID
:
1517 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1518 return "Virtual user ID";
1519 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1521 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1522 return "Virtual group ID";
1529 static int handle_process_attr_status(enum lttng_process_attr process_attr
,
1530 enum lttng_process_attr_tracker_handle_status status
)
1532 int ret
= CMD_SUCCESS
;
1535 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID_TRACKING_POLICY
:
1536 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
1539 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
1540 ERR("Communication occurred while fetching %s tracker",
1541 lttng_process_attr_to_string(process_attr
));
1544 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_SESSION_DOES_NOT_EXIST
:
1545 ERR("Failed to get the inclusion set of the %s tracker: session `%s` no longer exists",
1546 lttng_process_attr_to_string(process_attr
),
1547 handle
->session_name
);
1551 ERR("Unknown error occurred while fetching the inclusion set of the %s tracker",
1552 lttng_process_attr_to_string(process_attr
));
1560 static int mi_output_empty_tracker(enum lttng_process_attr process_attr
)
1564 ret
= mi_lttng_process_attribute_tracker_open(writer
, process_attr
);
1569 ret
= mi_lttng_close_multi_element(writer
, 2);
1574 static inline bool is_value_type_name(
1575 enum lttng_process_attr_value_type value_type
)
1577 return value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
||
1578 value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
;
1582 * List a process attribute tracker for a session and domain tuple.
1584 static int list_process_attr_tracker(enum lttng_process_attr process_attr
)
1587 unsigned int count
, i
;
1588 enum lttng_tracking_policy policy
;
1589 enum lttng_error_code ret_code
;
1590 enum lttng_process_attr_tracker_handle_status handle_status
;
1591 enum lttng_process_attr_values_status values_status
;
1592 const struct lttng_process_attr_values
*values
;
1593 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
1595 ret_code
= lttng_session_get_tracker_handle(handle
->session_name
,
1596 handle
->domain
.type
, process_attr
, &tracker_handle
);
1597 if (ret_code
!= LTTNG_OK
) {
1598 ERR("Failed to get process attribute tracker handle: %s",
1599 lttng_strerror(ret_code
));
1604 handle_status
= lttng_process_attr_tracker_handle_get_inclusion_set(
1605 tracker_handle
, &values
);
1606 ret
= handle_process_attr_status(process_attr
, handle_status
);
1607 if (ret
!= CMD_SUCCESS
) {
1611 handle_status
= lttng_process_attr_tracker_handle_get_tracking_policy(
1612 tracker_handle
, &policy
);
1613 ret
= handle_process_attr_status(process_attr
, handle_status
);
1614 if (ret
!= CMD_SUCCESS
) {
1619 char *process_attr_name
;
1620 const int print_ret
= asprintf(&process_attr_name
, "%ss:",
1621 get_capitalized_process_attr_str(process_attr
));
1623 if (print_ret
== -1) {
1627 _MSG(" %-22s", process_attr_name
);
1628 free(process_attr_name
);
1631 case LTTNG_TRACKING_POLICY_INCLUDE_SET
:
1633 case LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
1635 mi_output_empty_tracker(process_attr
);
1640 case LTTNG_TRACKING_POLICY_INCLUDE_ALL
:
1645 ERR("Unknown tracking policy encoutered while listing the %s process attribute tracker of session `%s`",
1646 lttng_process_attr_to_string(process_attr
),
1647 handle
->session_name
);
1652 values_status
= lttng_process_attr_values_get_count(values
, &count
);
1653 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1654 ERR("Failed to get the count of values in the inclusion set of the %s process attribute tracker of session `%s`",
1655 lttng_process_attr_to_string(process_attr
),
1656 handle
->session_name
);
1662 /* Functionally equivalent to the 'exclude all' policy. */
1664 mi_output_empty_tracker(process_attr
);
1671 /* Mi tracker_id element */
1673 /* Open tracker_id and targets elements */
1674 ret
= mi_lttng_process_attribute_tracker_open(
1675 writer
, process_attr
);
1681 for (i
= 0; i
< count
; i
++) {
1682 const enum lttng_process_attr_value_type value_type
=
1683 lttng_process_attr_values_get_type_at_index(
1685 int64_t integral_value
= INT64_MAX
;
1686 const char *name
= "error";
1691 switch (value_type
) {
1692 case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID
:
1696 values_status
= lttng_process_attr_values_get_pid_at_index(
1698 integral_value
= (int64_t) pid
;
1701 case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID
:
1705 values_status
= lttng_process_attr_values_get_uid_at_index(
1707 integral_value
= (int64_t) uid
;
1710 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID
:
1714 values_status
= lttng_process_attr_values_get_gid_at_index(
1716 integral_value
= (int64_t) gid
;
1719 case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
:
1720 values_status
= lttng_process_attr_values_get_user_name_at_index(
1723 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
:
1724 values_status
= lttng_process_attr_values_get_group_name_at_index(
1732 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1734 * Not possible given the current liblttng-ctl
1737 ERR("Unknown error occurred while fetching process attribute value in inclusion list");
1742 if (is_value_type_name(value_type
)) {
1745 _MSG("%" PRIi64
, integral_value
);
1750 ret
= is_value_type_name(value_type
) ?
1751 mi_lttng_string_process_attribute_value(
1755 mi_lttng_integral_process_attribute_value(
1767 /* Mi close tracker_id and targets */
1769 ret
= mi_lttng_close_multi_element(writer
, 2);
1775 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
1780 * List all trackers of a domain
1782 static int list_trackers(const struct lttng_domain
*domain
)
1786 MSG("Tracked process attributes");
1787 /* Trackers listing */
1789 ret
= mi_lttng_trackers_open(writer
);
1795 switch (domain
->type
) {
1796 case LTTNG_DOMAIN_KERNEL
:
1798 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_PROCESS_ID
);
1803 ret
= list_process_attr_tracker(
1804 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1809 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_USER_ID
);
1814 ret
= list_process_attr_tracker(
1815 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1820 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_GROUP_ID
);
1825 ret
= list_process_attr_tracker(
1826 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1831 case LTTNG_DOMAIN_UST
:
1833 ret
= list_process_attr_tracker(
1834 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1839 ret
= list_process_attr_tracker(
1840 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1845 ret
= list_process_attr_tracker(
1846 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1856 /* Close trackers element */
1857 ret
= mi_lttng_writer_close_element(writer
);
1867 static enum cmd_error_code
print_periodic_rotation_schedule(
1868 const struct lttng_rotation_schedule
*schedule
)
1870 enum cmd_error_code ret
;
1871 enum lttng_rotation_status status
;
1874 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1876 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1877 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1882 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
1888 static enum cmd_error_code
print_size_threshold_rotation_schedule(
1889 const struct lttng_rotation_schedule
*schedule
)
1891 enum cmd_error_code ret
;
1892 enum lttng_rotation_status status
;
1895 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
1897 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1898 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1903 MSG(" size threshold: %" PRIu64
" bytes", value
);
1909 static enum cmd_error_code
print_rotation_schedule(
1910 const struct lttng_rotation_schedule
*schedule
)
1912 enum cmd_error_code ret
;
1914 switch (lttng_rotation_schedule_get_type(schedule
)) {
1915 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1916 ret
= print_size_threshold_rotation_schedule(schedule
);
1918 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1919 ret
= print_periodic_rotation_schedule(schedule
);
1928 * List the automatic rotation settings.
1930 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1933 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1934 unsigned int count
, i
;
1935 struct lttng_rotation_schedules
*schedules
= NULL
;
1936 enum lttng_rotation_status status
;
1938 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1939 if (ret
!= LTTNG_OK
) {
1940 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1941 cmd_ret
= CMD_ERROR
;
1945 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1946 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1947 ERR("Failed to retrieve the number of session rotation schedules.");
1948 cmd_ret
= CMD_ERROR
;
1953 cmd_ret
= CMD_SUCCESS
;
1957 MSG("Automatic rotation schedules:");
1959 ret
= mi_lttng_writer_open_element(writer
,
1960 mi_lttng_element_rotation_schedules
);
1962 cmd_ret
= CMD_ERROR
;
1967 for (i
= 0; i
< count
; i
++) {
1968 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1969 const struct lttng_rotation_schedule
*schedule
;
1971 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1973 ERR("Failed to retrieve session rotation schedule.");
1974 cmd_ret
= CMD_ERROR
;
1979 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
1981 tmp_ret
= CMD_ERROR
;
1984 tmp_ret
= print_rotation_schedule(schedule
);
1988 * Report an error if the serialization of any of the
1989 * descriptors failed.
1991 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
1996 /* Close the rotation_schedules element. */
1997 ret
= mi_lttng_writer_close_element(writer
);
1999 cmd_ret
= CMD_ERROR
;
2004 lttng_rotation_schedules_destroy(schedules
);
2010 * Find the session with session_name as name
2011 * and print his informations.
2013 static int mi_list_session(const char *session_name
,
2014 struct lttng_session
*sessions
, int count
)
2017 unsigned int session_found
= 0;
2019 if (session_name
== NULL
) {
2020 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2024 for (i
= 0; i
< count
; i
++) {
2025 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2026 /* We need to leave it open to append other informations
2027 * like domain, channel, events etc.*/
2029 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
2037 if (!session_found
) {
2038 ERR("Session '%s' not found", session_name
);
2039 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2049 * List all availables session
2051 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
2055 /* Opening sessions element */
2056 ret
= mi_lttng_sessions_open(writer
);
2061 /* Listing sessions */
2062 for (i
= 0; i
< count
; i
++) {
2063 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
2069 /* Closing sessions element */
2070 ret
= mi_lttng_writer_close_element(writer
);
2080 * List available tracing session. List only basic information.
2082 * If session_name is NULL, all sessions are listed.
2084 static int list_sessions(const char *session_name
)
2086 int ret
= CMD_SUCCESS
;
2088 unsigned int session_found
= 0;
2089 struct lttng_session
*sessions
= NULL
;
2091 count
= lttng_list_sessions(&sessions
);
2092 DBG("Session count %d", count
);
2095 ERR("%s", lttng_strerror(count
));
2101 if (session_name
== NULL
) {
2102 /* List all sessions */
2103 ret
= mi_list_sessions(sessions
, count
);
2105 /* Note : this return an open session element */
2106 ret
= mi_list_session(session_name
, sessions
, count
);
2115 MSG("Currently no available tracing session");
2119 if (session_name
== NULL
) {
2120 MSG("Available tracing sessions:");
2123 for (i
= 0; i
< count
; i
++) {
2124 if (session_name
!= NULL
) {
2125 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2127 MSG("Tracing session %s: [%s%s]", session_name
,
2128 active_string(sessions
[i
].enabled
),
2129 snapshot_string(sessions
[i
].snapshot_mode
));
2130 if (*sessions
[i
].path
) {
2131 MSG("%sTrace output: %s\n", indent4
, sessions
[i
].path
);
2133 memcpy(&listed_session
, &sessions
[i
],
2134 sizeof(listed_session
));
2138 MSG(" %d) %s [%s%s]", i
+ 1,
2140 active_string(sessions
[i
].enabled
),
2141 snapshot_string(sessions
[i
].snapshot_mode
));
2142 if (*sessions
[i
].path
) {
2143 MSG("%sTrace output: %s", indent4
, sessions
[i
].path
);
2145 if (sessions
[i
].live_timer_interval
!= 0) {
2146 MSG("%sLive timer interval: %u %s", indent4
,
2147 sessions
[i
].live_timer_interval
,
2154 if (!session_found
&& session_name
!= NULL
) {
2155 ERR("Session '%s' not found", session_name
);
2160 if (session_name
== NULL
) {
2161 MSG("\nUse lttng list <session_name> for more details");
2173 * list available domain(s) for a session.
2175 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
2178 /* Open domains element */
2179 ret
= mi_lttng_domains_open(writer
);
2184 for (i
= 0; i
< count
; i
++) {
2185 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
2191 /* Closing domains element */
2192 ret
= mi_lttng_writer_close_element(writer
);
2201 * List available domain(s) for a session.
2203 static int list_domains(const char *session_name
)
2205 int i
, count
, ret
= CMD_SUCCESS
;
2206 struct lttng_domain
*domains
= NULL
;
2209 count
= lttng_list_domains(session_name
, &domains
);
2212 ERR("%s", lttng_strerror(count
));
2218 ret
= mi_list_domains(domains
, count
);
2225 MSG("Domains:\n-------------");
2231 for (i
= 0; i
< count
; i
++) {
2232 switch (domains
[i
].type
) {
2233 case LTTNG_DOMAIN_KERNEL
:
2236 case LTTNG_DOMAIN_UST
:
2237 MSG(" - UST global");
2239 case LTTNG_DOMAIN_JUL
:
2240 MSG(" - JUL (Java Util Logging)");
2242 case LTTNG_DOMAIN_LOG4J
:
2243 MSG(" - LOG4j (Logging for Java)");
2245 case LTTNG_DOMAIN_PYTHON
:
2246 MSG(" - Python (logging)");
2262 * The 'list <options>' first level command
2264 int cmd_list(int argc
, const char **argv
)
2266 int opt
, ret
= CMD_SUCCESS
;
2267 const char *session_name
, *leftover
= NULL
;
2268 static poptContext pc
;
2269 struct lttng_domain domain
;
2270 struct lttng_domain
*domains
= NULL
;
2272 memset(&domain
, 0, sizeof(domain
));
2279 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2280 poptReadDefaultConfig(pc
, 0);
2282 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2290 case OPT_LIST_OPTIONS
:
2291 list_cmd_options(stdout
, long_options
);
2294 ret
= CMD_UNDEFINED
;
2301 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
2307 /* Open command element */
2308 ret
= mi_lttng_writer_command_open(writer
,
2309 mi_lttng_element_command_list
);
2315 /* Open output element */
2316 ret
= mi_lttng_writer_open_element(writer
,
2317 mi_lttng_element_command_output
);
2324 /* Get session name (trailing argument) */
2325 session_name
= poptGetArg(pc
);
2326 DBG2("Session name: %s", session_name
);
2328 leftover
= poptGetArg(pc
);
2330 ERR("Unknown argument: %s", leftover
);
2336 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2337 } else if (opt_userspace
) {
2338 DBG2("Listing userspace global domain");
2339 domain
.type
= LTTNG_DOMAIN_UST
;
2340 } else if (opt_jul
) {
2341 DBG2("Listing JUL domain");
2342 domain
.type
= LTTNG_DOMAIN_JUL
;
2343 } else if (opt_log4j
) {
2344 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2345 } else if (opt_python
) {
2346 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2349 if (!opt_kernel
&& opt_syscall
) {
2350 WARN("--syscall will only work with the Kernel domain (-k)");
2355 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2356 handle
= lttng_create_handle(session_name
, &domain
);
2357 if (handle
== NULL
) {
2363 if (session_name
== NULL
) {
2364 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2366 ret
= list_sessions(NULL
);
2373 ret
= list_syscalls();
2378 ret
= list_kernel_events();
2384 if (opt_userspace
) {
2386 ret
= list_ust_event_fields();
2388 ret
= list_ust_events();
2394 if (opt_jul
|| opt_log4j
|| opt_python
) {
2395 ret
= list_agent_events();
2401 /* List session attributes */
2403 /* Open element sessions
2404 * Present for xml consistency */
2405 ret
= mi_lttng_sessions_open(writer
);
2410 /* MI: the ouptut of list_sessions is an unclosed session element */
2411 ret
= list_sessions(session_name
);
2416 ret
= list_rotate_settings(session_name
);
2421 /* Domain listing */
2423 ret
= list_domains(session_name
);
2427 /* Channel listing */
2428 if (opt_kernel
|| opt_userspace
) {
2430 /* Add of domains and domain element for xml
2431 * consistency and validation
2433 ret
= mi_lttng_domains_open(writer
);
2438 /* Open domain and leave it open for
2439 * nested channels printing */
2440 ret
= mi_lttng_domain(writer
, &domain
, 1);
2449 ret
= list_trackers(&domain
);
2455 ret
= list_channels(opt_channel
);
2461 /* Close domain and domain element */
2462 ret
= mi_lttng_close_multi_element(writer
, 2);
2472 /* We want all domain(s) */
2473 nb_domain
= lttng_list_domains(session_name
, &domains
);
2474 if (nb_domain
< 0) {
2476 ERR("%s", lttng_strerror(nb_domain
));
2481 ret
= mi_lttng_domains_open(writer
);
2488 for (i
= 0; i
< nb_domain
; i
++) {
2489 switch (domains
[i
].type
) {
2490 case LTTNG_DOMAIN_KERNEL
:
2491 MSG("=== Domain: Linux kernel ===\n");
2493 case LTTNG_DOMAIN_UST
:
2494 MSG("=== Domain: User space ===\n");
2495 MSG("Buffering scheme: %s\n",
2496 domains
[i
].buf_type
==
2497 LTTNG_BUFFER_PER_PID
? "per-process" : "per-user");
2499 case LTTNG_DOMAIN_JUL
:
2500 MSG("=== Domain: java.util.logging (JUL) ===\n");
2502 case LTTNG_DOMAIN_LOG4J
:
2503 MSG("=== Domain: log4j ===\n");
2505 case LTTNG_DOMAIN_PYTHON
:
2506 MSG("=== Domain: Python logging ===\n");
2509 MSG("=== Domain: Unimplemented ===\n");
2514 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
2521 /* Clean handle before creating a new one */
2523 lttng_destroy_handle(handle
);
2526 handle
= lttng_create_handle(session_name
, &domains
[i
]);
2527 if (handle
== NULL
) {
2532 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2533 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2534 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2535 ret
= list_session_agent_events();
2543 switch (domains
[i
].type
) {
2544 case LTTNG_DOMAIN_KERNEL
:
2545 case LTTNG_DOMAIN_UST
:
2546 ret
= list_trackers(&domains
[i
]);
2555 ret
= list_channels(opt_channel
);
2562 /* Close domain element */
2563 ret
= mi_lttng_writer_close_element(writer
);
2572 /* Close the domains, session and sessions element */
2573 ret
= mi_lttng_close_multi_element(writer
, 3);
2584 /* Close output element */
2585 ret
= mi_lttng_writer_close_element(writer
);
2591 /* Command element close */
2592 ret
= mi_lttng_writer_command_close(writer
);
2600 if (writer
&& mi_lttng_writer_destroy(writer
)) {
2601 /* Preserve original error code */
2602 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2607 lttng_destroy_handle(handle
);
2610 poptFreeContext(pc
);