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
;
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
);
299 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
301 const char *probe_name
, *provider_name
;
304 MSG("%sType: Tracepoint", indent8
);
305 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
306 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
307 binary_path
= realpath(lttng_userspace_probe_location_tracepoint_get_binary_path(location
), NULL
);
308 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
309 MSG("%sTracepoint: %s:%s", indent8
, provider_name
? provider_name
: "NULL", probe_name
? probe_name
: "NULL");
310 switch (lookup_type
) {
311 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
312 MSG("%sLookup method: SDT", indent8
);
315 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
323 ERR("Invalid probe type encountered");
328 * Pretty print single event.
330 static void print_events(struct lttng_event
*event
)
333 const char *filter_str
;
334 char *filter_msg
= NULL
;
335 char *exclusion_msg
= NULL
;
337 ret
= lttng_event_get_filter_expression(event
, &filter_str
);
340 filter_msg
= strdup(" [failed to retrieve filter]");
341 } else if (filter_str
) {
342 const char * const filter_fmt
= " [filter: '%s']";
344 filter_msg
= malloc(strlen(filter_str
) +
345 strlen(filter_fmt
) + 1);
347 sprintf(filter_msg
, filter_fmt
,
352 exclusion_msg
= get_exclusion_names_msg(event
);
353 if (!exclusion_msg
) {
354 exclusion_msg
= strdup(" [failed to retrieve exclusions]");
357 switch (event
->type
) {
358 case LTTNG_EVENT_TRACEPOINT
:
360 if (event
->loglevel
!= -1) {
361 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
364 logleveltype_string(event
->loglevel_type
),
365 mi_lttng_loglevel_string(event
->loglevel
, handle
->domain
.type
),
367 enabled_string(event
->enabled
),
368 safe_string(exclusion_msg
),
369 safe_string(filter_msg
));
371 MSG("%s%s (type: tracepoint)%s%s%s",
374 enabled_string(event
->enabled
),
375 safe_string(exclusion_msg
),
376 safe_string(filter_msg
));
380 case LTTNG_EVENT_FUNCTION
:
381 MSG("%s%s (type: function)%s%s", indent6
,
382 event
->name
, enabled_string(event
->enabled
),
383 safe_string(filter_msg
));
384 if (event
->attr
.probe
.addr
!= 0) {
385 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
387 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
388 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
391 case LTTNG_EVENT_PROBE
:
392 MSG("%s%s (type: probe)%s%s", indent6
,
393 event
->name
, enabled_string(event
->enabled
),
394 safe_string(filter_msg
));
395 if (event
->attr
.probe
.addr
!= 0) {
396 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
398 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
399 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
402 case LTTNG_EVENT_USERSPACE_PROBE
:
403 print_userspace_probe_location(event
);
405 case LTTNG_EVENT_FUNCTION_ENTRY
:
406 MSG("%s%s (type: function)%s%s", indent6
,
407 event
->name
, enabled_string(event
->enabled
),
408 safe_string(filter_msg
));
409 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
411 case LTTNG_EVENT_SYSCALL
:
412 MSG("%s%s%s%s%s%s", indent6
, event
->name
,
413 (opt_syscall
? "" : " (type:syscall)"),
414 enabled_string(event
->enabled
),
415 bitness_event(event
->flags
),
416 safe_string(filter_msg
));
418 case LTTNG_EVENT_NOOP
:
419 MSG("%s (type: noop)%s%s", indent6
,
420 enabled_string(event
->enabled
),
421 safe_string(filter_msg
));
423 case LTTNG_EVENT_ALL
:
426 /* We should never have "all" events in list. */
435 static const char *field_type(struct lttng_event_field
*field
)
437 switch(field
->type
) {
438 case LTTNG_EVENT_FIELD_INTEGER
:
440 case LTTNG_EVENT_FIELD_ENUM
:
442 case LTTNG_EVENT_FIELD_FLOAT
:
444 case LTTNG_EVENT_FIELD_STRING
:
446 case LTTNG_EVENT_FIELD_OTHER
:
447 default: /* fall-through */
453 * Pretty print single event fields.
455 static void print_event_field(struct lttng_event_field
*field
)
457 if (!field
->field_name
[0]) {
460 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
461 field_type(field
), field
->nowrite
? " [no write]" : "");
466 * Jul and ust event listing
468 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
469 struct lttng_domain
*domain
)
473 char *cmdline
= NULL
;
474 int pid_element_open
= 0;
476 /* Open domains element */
477 ret
= mi_lttng_domains_open(writer
);
483 ret
= mi_lttng_domain(writer
, domain
, 1);
488 /* Open pids element element */
489 ret
= mi_lttng_pids_open(writer
);
494 for (i
= 0; i
< count
; i
++) {
495 if (cur_pid
!= events
[i
].pid
) {
496 if (pid_element_open
) {
497 /* Close the previous events and pid element */
498 ret
= mi_lttng_close_multi_element(writer
, 2);
502 pid_element_open
= 0;
505 cur_pid
= events
[i
].pid
;
506 cmdline
= get_cmdline_by_pid(cur_pid
);
512 if (!pid_element_open
) {
513 /* Open and write a pid element */
514 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
519 /* Open events element */
520 ret
= mi_lttng_events_open(writer
);
525 pid_element_open
= 1;
531 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
538 ret
= mi_lttng_writer_close_element(writer
);
543 /* Close domain, domains */
544 ret
= mi_lttng_close_multi_element(writer
, 2);
552 static int list_agent_events(void)
554 int i
, size
, ret
= CMD_SUCCESS
;
555 struct lttng_domain domain
;
556 struct lttng_handle
*handle
= NULL
;
557 struct lttng_event
*event_list
= NULL
;
559 char *cmdline
= NULL
;
560 const char *agent_domain_str
;
562 memset(&domain
, 0, sizeof(domain
));
564 domain
.type
= LTTNG_DOMAIN_JUL
;
565 } else if (opt_log4j
) {
566 domain
.type
= LTTNG_DOMAIN_LOG4J
;
567 } else if (opt_python
) {
568 domain
.type
= LTTNG_DOMAIN_PYTHON
;
570 ERR("Invalid agent domain selected.");
575 agent_domain_str
= get_domain_str(domain
.type
);
577 DBG("Getting %s tracing events", agent_domain_str
);
579 handle
= lttng_create_handle(NULL
, &domain
);
580 if (handle
== NULL
) {
585 size
= lttng_list_tracepoints(handle
, &event_list
);
587 ERR("Unable to list %s events: %s", agent_domain_str
,
588 lttng_strerror(size
));
595 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
602 MSG("%s events (Logger name):\n-------------------------",
609 for (i
= 0; i
< size
; i
++) {
610 if (cur_pid
!= event_list
[i
].pid
) {
611 cur_pid
= event_list
[i
].pid
;
612 cmdline
= get_cmdline_by_pid(cur_pid
);
613 if (cmdline
== NULL
) {
617 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
620 MSG("%s- %s", indent6
, event_list
[i
].name
);
629 lttng_destroy_handle(handle
);
634 * Ask session daemon for all user space tracepoints available.
636 static int list_ust_events(void)
638 int i
, size
, ret
= CMD_SUCCESS
;
639 struct lttng_domain domain
;
640 struct lttng_handle
*handle
;
641 struct lttng_event
*event_list
= NULL
;
643 char *cmdline
= NULL
;
645 memset(&domain
, 0, sizeof(domain
));
647 DBG("Getting UST tracing events");
649 domain
.type
= LTTNG_DOMAIN_UST
;
651 handle
= lttng_create_handle(NULL
, &domain
);
652 if (handle
== NULL
) {
657 size
= lttng_list_tracepoints(handle
, &event_list
);
659 ERR("Unable to list UST events: %s", lttng_strerror(size
));
666 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
669 MSG("UST events:\n-------------");
675 for (i
= 0; i
< size
; i
++) {
676 if (cur_pid
!= event_list
[i
].pid
) {
677 cur_pid
= event_list
[i
].pid
;
678 cmdline
= get_cmdline_by_pid(cur_pid
);
679 if (cmdline
== NULL
) {
683 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
686 print_events(&event_list
[i
]);
695 lttng_destroy_handle(handle
);
701 * List all ust event with their fields
703 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
704 struct lttng_domain
*domain
)
708 char *cmdline
= NULL
;
709 int pid_element_open
= 0;
710 int event_element_open
= 0;
711 struct lttng_event cur_event
;
713 memset(&cur_event
, 0, sizeof(cur_event
));
715 /* Open domains element */
716 ret
= mi_lttng_domains_open(writer
);
722 ret
= mi_lttng_domain(writer
, domain
, 1);
727 /* Open pids element */
728 ret
= mi_lttng_pids_open(writer
);
733 for (i
= 0; i
< count
; i
++) {
734 if (cur_pid
!= fields
[i
].event
.pid
) {
735 if (pid_element_open
) {
736 if (event_element_open
) {
737 /* Close the previous field element and event. */
738 ret
= mi_lttng_close_multi_element(writer
, 2);
742 event_element_open
= 0;
744 /* Close the previous events, pid element */
745 ret
= mi_lttng_close_multi_element(writer
, 2);
749 pid_element_open
= 0;
752 cur_pid
= fields
[i
].event
.pid
;
753 cmdline
= get_cmdline_by_pid(cur_pid
);
754 if (!pid_element_open
) {
755 /* Open and write a pid element */
756 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
761 /* Open events element */
762 ret
= mi_lttng_events_open(writer
);
766 pid_element_open
= 1;
769 /* Wipe current event since we are about to print a new PID. */
770 memset(&cur_event
, 0, sizeof(cur_event
));
773 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
774 if (event_element_open
) {
775 /* Close the previous fields element and the previous event */
776 ret
= mi_lttng_close_multi_element(writer
, 2);
780 event_element_open
= 0;
783 memcpy(&cur_event
, &fields
[i
].event
,
786 if (!event_element_open
) {
787 /* Open and write the event */
788 ret
= mi_lttng_event(writer
, &cur_event
, 1,
789 handle
->domain
.type
);
794 /* Open a fields element */
795 ret
= mi_lttng_event_fields_open(writer
);
799 event_element_open
= 1;
803 /* Print the event_field */
804 ret
= mi_lttng_event_field(writer
, &fields
[i
]);
810 /* Close pids, domain, domains */
811 ret
= mi_lttng_close_multi_element(writer
, 3);
820 * Ask session daemon for all user space tracepoint fields available.
822 static int list_ust_event_fields(void)
824 int i
, size
, ret
= CMD_SUCCESS
;
825 struct lttng_domain domain
;
826 struct lttng_handle
*handle
;
827 struct lttng_event_field
*event_field_list
;
829 char *cmdline
= NULL
;
831 struct lttng_event cur_event
;
833 memset(&domain
, 0, sizeof(domain
));
834 memset(&cur_event
, 0, sizeof(cur_event
));
836 DBG("Getting UST tracing event fields");
838 domain
.type
= LTTNG_DOMAIN_UST
;
840 handle
= lttng_create_handle(NULL
, &domain
);
841 if (handle
== NULL
) {
846 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
848 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
855 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
862 MSG("UST events:\n-------------");
868 for (i
= 0; i
< size
; i
++) {
869 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
870 cur_pid
= event_field_list
[i
].event
.pid
;
871 cmdline
= get_cmdline_by_pid(cur_pid
);
872 if (cmdline
== NULL
) {
876 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
878 /* Wipe current event since we are about to print a new PID. */
879 memset(&cur_event
, 0, sizeof(cur_event
));
881 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
882 print_events(&event_field_list
[i
].event
);
883 memcpy(&cur_event
, &event_field_list
[i
].event
,
886 print_event_field(&event_field_list
[i
]);
893 free(event_field_list
);
895 lttng_destroy_handle(handle
);
901 * Print a list of kernel events
903 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
904 struct lttng_domain
*domain
)
908 /* Open domains element */
909 ret
= mi_lttng_domains_open(writer
);
915 ret
= mi_lttng_domain(writer
, domain
, 1);
921 ret
= mi_lttng_events_open(writer
);
926 for (i
= 0; i
< count
; i
++) {
927 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
933 /* close events, domain and domains */
934 ret
= mi_lttng_close_multi_element(writer
, 3);
944 * Ask for all trace events in the kernel
946 static int list_kernel_events(void)
948 int i
, size
, ret
= CMD_SUCCESS
;
949 struct lttng_domain domain
;
950 struct lttng_handle
*handle
;
951 struct lttng_event
*event_list
;
953 memset(&domain
, 0, sizeof(domain
));
955 DBG("Getting kernel tracing events");
957 domain
.type
= LTTNG_DOMAIN_KERNEL
;
959 handle
= lttng_create_handle(NULL
, &domain
);
960 if (handle
== NULL
) {
965 size
= lttng_list_tracepoints(handle
, &event_list
);
967 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
968 lttng_destroy_handle(handle
);
974 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
980 MSG("Kernel events:\n-------------");
982 for (i
= 0; i
< size
; i
++) {
983 print_events(&event_list
[i
]);
992 lttng_destroy_handle(handle
);
996 lttng_destroy_handle(handle
);
1002 * Print a list of system calls.
1004 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1009 ret
= mi_lttng_events_open(writer
);
1014 for (i
= 0; i
< count
; i
++) {
1015 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1022 ret
= mi_lttng_writer_close_element(writer
);
1032 * Ask for kernel system calls.
1034 static int list_syscalls(void)
1036 int i
, size
, ret
= CMD_SUCCESS
;
1037 struct lttng_event
*event_list
;
1039 DBG("Getting kernel system call events");
1041 size
= lttng_list_syscalls(&event_list
);
1043 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1050 ret
= mi_list_syscalls(event_list
, size
);
1056 MSG("System calls:\n-------------");
1058 for (i
= 0; i
< size
; i
++) {
1059 print_events(&event_list
[i
]);
1075 * Print a list of agent events
1077 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1081 /* Open events element */
1082 ret
= mi_lttng_events_open(writer
);
1087 for (i
= 0; i
< count
; i
++) {
1088 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1094 /* Close events element */
1095 ret
= mi_lttng_writer_close_element(writer
);
1102 * List agent events for a specific session using the handle.
1104 * Return CMD_SUCCESS on success else a negative value.
1106 static int list_session_agent_events(void)
1108 int ret
= CMD_SUCCESS
, count
, i
;
1109 struct lttng_event
*events
= NULL
;
1111 count
= lttng_list_events(handle
, "", &events
);
1114 ERR("%s", lttng_strerror(count
));
1120 ret
= mi_list_session_agent_events(events
, count
);
1127 MSG("Events (Logger name):\n---------------------");
1129 MSG("%sNone\n", indent6
);
1133 for (i
= 0; i
< count
; i
++) {
1134 const char *filter_str
;
1135 char *filter_msg
= NULL
;
1136 struct lttng_event
*event
= &events
[i
];
1138 ret
= lttng_event_get_filter_expression(event
,
1141 filter_msg
= strdup(" [failed to retrieve filter]");
1142 } else if (filter_str
) {
1143 const char * const filter_fmt
=
1146 filter_msg
= malloc(strlen(filter_str
) +
1147 strlen(filter_fmt
) + 1);
1149 sprintf(filter_msg
, filter_fmt
,
1154 if (event
->loglevel_type
!=
1155 LTTNG_EVENT_LOGLEVEL_ALL
) {
1156 MSG("%s- %s%s (loglevel%s %s)%s", indent4
,
1158 enabled_string(event
->enabled
),
1159 logleveltype_string(
1160 event
->loglevel_type
),
1161 mi_lttng_loglevel_string(
1163 handle
->domain
.type
),
1164 safe_string(filter_msg
));
1166 MSG("%s- %s%s%s", indent4
, event
->name
,
1167 enabled_string(event
->enabled
),
1168 safe_string(filter_msg
));
1184 * print a list of event
1186 static int mi_list_events(struct lttng_event
*events
, int count
)
1190 /* Open events element */
1191 ret
= mi_lttng_events_open(writer
);
1196 for (i
= 0; i
< count
; i
++) {
1197 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1203 /* Close events element */
1204 ret
= mi_lttng_writer_close_element(writer
);
1211 * List events of channel of session and domain.
1213 static int list_events(const char *channel_name
)
1215 int ret
= CMD_SUCCESS
, count
, i
;
1216 struct lttng_event
*events
= NULL
;
1218 count
= lttng_list_events(handle
, channel_name
, &events
);
1221 ERR("%s", lttng_strerror(count
));
1227 ret
= mi_list_events(events
, count
);
1234 MSG("\n%sEvent rules:", indent4
);
1236 MSG("%sNone\n", indent6
);
1240 for (i
= 0; i
< count
; i
++) {
1241 print_events(&events
[i
]);
1253 void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1257 _MSG("%s%s:", indent6
, timer_name
);
1258 for (i
= 0; i
< space_count
; i
++) {
1263 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1270 * Pretty print channel
1272 static void print_channel(struct lttng_channel
*channel
)
1275 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1276 int64_t blocking_timeout
;
1278 ret
= lttng_channel_get_discarded_event_count(channel
,
1281 ERR("Failed to retrieve discarded event count of channel");
1285 ret
= lttng_channel_get_lost_packet_count(channel
,
1288 ERR("Failed to retrieve lost packet count of channel");
1292 ret
= lttng_channel_get_monitor_timer_interval(channel
,
1293 &monitor_timer_interval
);
1295 ERR("Failed to retrieve monitor interval of channel");
1299 ret
= lttng_channel_get_blocking_timeout(channel
,
1302 ERR("Failed to retrieve blocking timeout of channel");
1306 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1307 MSG("%sAttributes:", indent4
);
1308 MSG("%sEvent-loss mode: %s", indent6
, channel
->attr
.overwrite
? "overwrite" : "discard");
1309 MSG("%sSub-buffer size: %" PRIu64
" bytes", indent6
, channel
->attr
.subbuf_size
);
1310 MSG("%sSub-buffer count: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1312 print_timer("Switch timer", 5, channel
->attr
.switch_timer_interval
);
1313 print_timer("Read timer", 7, channel
->attr
.read_timer_interval
);
1314 print_timer("Monitor timer", 4, monitor_timer_interval
);
1316 if (!channel
->attr
.overwrite
) {
1317 if (blocking_timeout
== -1) {
1318 MSG("%sBlocking timeout: infinite", indent6
);
1320 MSG("%sBlocking timeout: %" PRId64
" %s", indent6
,
1321 blocking_timeout
, USEC_UNIT
);
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 goto error_channels
;
1457 /* We had a real error */
1459 ERR("%s", lttng_strerror(count
));
1460 goto error_channels
;
1467 ret
= mi_list_channels(channels
, count
, channel_name
);
1475 MSG("Channels:\n-------------");
1478 for (i
= 0; i
< count
; i
++) {
1479 if (channel_name
!= NULL
) {
1480 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1486 print_channel(&channels
[i
]);
1488 /* Listing events per channel */
1489 ret
= list_events(channels
[i
].name
);
1499 if (!chan_found
&& channel_name
!= NULL
) {
1501 ERR("Channel %s not found", channel_name
);
1512 static const char *get_capitalized_process_attr_str(enum lttng_process_attr process_attr
)
1514 switch (process_attr
) {
1515 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1516 return "Process ID";
1517 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1518 return "Virtual process ID";
1519 case LTTNG_PROCESS_ATTR_USER_ID
:
1521 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1522 return "Virtual user ID";
1523 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1525 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1526 return "Virtual group ID";
1533 static int handle_process_attr_status(enum lttng_process_attr process_attr
,
1534 enum lttng_process_attr_tracker_handle_status status
)
1536 int ret
= CMD_SUCCESS
;
1539 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID_TRACKING_POLICY
:
1540 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
1543 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
1544 ERR("Communication occurred while fetching %s tracker",
1545 lttng_process_attr_to_string(process_attr
));
1548 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_SESSION_DOES_NOT_EXIST
:
1549 ERR("Failed to get the inclusion set of the %s tracker: session `%s` no longer exists",
1550 lttng_process_attr_to_string(process_attr
),
1551 handle
->session_name
);
1555 ERR("Unknown error occurred while fetching the inclusion set of the %s tracker",
1556 lttng_process_attr_to_string(process_attr
));
1564 static int mi_output_empty_tracker(enum lttng_process_attr process_attr
)
1568 ret
= mi_lttng_process_attribute_tracker_open(writer
, process_attr
);
1573 ret
= mi_lttng_close_multi_element(writer
, 2);
1578 static inline bool is_value_type_name(
1579 enum lttng_process_attr_value_type value_type
)
1581 return value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
||
1582 value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
;
1586 * List a process attribute tracker for a session and domain tuple.
1588 static int list_process_attr_tracker(enum lttng_process_attr process_attr
)
1591 unsigned int count
, i
;
1592 enum lttng_tracking_policy policy
;
1593 enum lttng_error_code ret_code
;
1594 enum lttng_process_attr_tracker_handle_status handle_status
;
1595 enum lttng_process_attr_values_status values_status
;
1596 const struct lttng_process_attr_values
*values
;
1597 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
1599 ret_code
= lttng_session_get_tracker_handle(handle
->session_name
,
1600 handle
->domain
.type
, process_attr
, &tracker_handle
);
1601 if (ret_code
!= LTTNG_OK
) {
1602 ERR("Failed to get process attribute tracker handle: %s",
1603 lttng_strerror(ret_code
));
1608 handle_status
= lttng_process_attr_tracker_handle_get_inclusion_set(
1609 tracker_handle
, &values
);
1610 ret
= handle_process_attr_status(process_attr
, handle_status
);
1611 if (ret
!= CMD_SUCCESS
) {
1615 handle_status
= lttng_process_attr_tracker_handle_get_tracking_policy(
1616 tracker_handle
, &policy
);
1617 ret
= handle_process_attr_status(process_attr
, handle_status
);
1618 if (ret
!= CMD_SUCCESS
) {
1623 char *process_attr_name
;
1624 const int print_ret
= asprintf(&process_attr_name
, "%ss:",
1625 get_capitalized_process_attr_str(process_attr
));
1627 if (print_ret
== -1) {
1631 _MSG(" %-22s", process_attr_name
);
1632 free(process_attr_name
);
1635 case LTTNG_TRACKING_POLICY_INCLUDE_SET
:
1637 case LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
1639 mi_output_empty_tracker(process_attr
);
1644 case LTTNG_TRACKING_POLICY_INCLUDE_ALL
:
1649 ERR("Unknown tracking policy encoutered while listing the %s process attribute tracker of session `%s`",
1650 lttng_process_attr_to_string(process_attr
),
1651 handle
->session_name
);
1656 values_status
= lttng_process_attr_values_get_count(values
, &count
);
1657 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1658 ERR("Failed to get the count of values in the inclusion set of the %s process attribute tracker of session `%s`",
1659 lttng_process_attr_to_string(process_attr
),
1660 handle
->session_name
);
1666 /* Functionally equivalent to the 'exclude all' policy. */
1668 mi_output_empty_tracker(process_attr
);
1675 /* Mi tracker_id element */
1677 /* Open tracker_id and targets elements */
1678 ret
= mi_lttng_process_attribute_tracker_open(
1679 writer
, process_attr
);
1685 for (i
= 0; i
< count
; i
++) {
1686 const enum lttng_process_attr_value_type value_type
=
1687 lttng_process_attr_values_get_type_at_index(
1689 int64_t integral_value
= INT64_MAX
;
1690 const char *name
= "error";
1695 switch (value_type
) {
1696 case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID
:
1700 values_status
= lttng_process_attr_values_get_pid_at_index(
1702 integral_value
= (int64_t) pid
;
1705 case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID
:
1709 values_status
= lttng_process_attr_values_get_uid_at_index(
1711 integral_value
= (int64_t) uid
;
1714 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID
:
1718 values_status
= lttng_process_attr_values_get_gid_at_index(
1720 integral_value
= (int64_t) gid
;
1723 case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
:
1724 values_status
= lttng_process_attr_values_get_user_name_at_index(
1727 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
:
1728 values_status
= lttng_process_attr_values_get_group_name_at_index(
1736 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1738 * Not possible given the current liblttng-ctl
1741 ERR("Unknown error occurred while fetching process attribute value in inclusion list");
1746 if (is_value_type_name(value_type
)) {
1749 _MSG("%" PRIi64
, integral_value
);
1754 ret
= is_value_type_name(value_type
) ?
1755 mi_lttng_string_process_attribute_value(
1759 mi_lttng_integral_process_attribute_value(
1771 /* Mi close tracker_id and targets */
1773 ret
= mi_lttng_close_multi_element(writer
, 2);
1779 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
1784 * List all trackers of a domain
1786 static int list_trackers(const struct lttng_domain
*domain
)
1790 MSG("Tracked process attributes");
1791 /* Trackers listing */
1793 ret
= mi_lttng_trackers_open(writer
);
1799 switch (domain
->type
) {
1800 case LTTNG_DOMAIN_KERNEL
:
1802 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_PROCESS_ID
);
1807 ret
= list_process_attr_tracker(
1808 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1813 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_USER_ID
);
1818 ret
= list_process_attr_tracker(
1819 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1824 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_GROUP_ID
);
1829 ret
= list_process_attr_tracker(
1830 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1835 case LTTNG_DOMAIN_UST
:
1837 ret
= list_process_attr_tracker(
1838 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1843 ret
= list_process_attr_tracker(
1844 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1849 ret
= list_process_attr_tracker(
1850 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1860 /* Close trackers element */
1861 ret
= mi_lttng_writer_close_element(writer
);
1871 static enum cmd_error_code
print_periodic_rotation_schedule(
1872 const struct lttng_rotation_schedule
*schedule
)
1874 enum cmd_error_code ret
;
1875 enum lttng_rotation_status status
;
1878 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1880 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1881 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1886 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
1892 static enum cmd_error_code
print_size_threshold_rotation_schedule(
1893 const struct lttng_rotation_schedule
*schedule
)
1895 enum cmd_error_code ret
;
1896 enum lttng_rotation_status status
;
1899 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
1901 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1902 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1907 MSG(" size threshold: %" PRIu64
" bytes", value
);
1913 static enum cmd_error_code
print_rotation_schedule(
1914 const struct lttng_rotation_schedule
*schedule
)
1916 enum cmd_error_code ret
;
1918 switch (lttng_rotation_schedule_get_type(schedule
)) {
1919 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1920 ret
= print_size_threshold_rotation_schedule(schedule
);
1922 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1923 ret
= print_periodic_rotation_schedule(schedule
);
1932 * List the automatic rotation settings.
1934 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1937 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1938 unsigned int count
, i
;
1939 struct lttng_rotation_schedules
*schedules
= NULL
;
1940 enum lttng_rotation_status status
;
1942 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1943 if (ret
!= LTTNG_OK
) {
1944 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1945 cmd_ret
= CMD_ERROR
;
1949 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1950 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1951 ERR("Failed to retrieve the number of session rotation schedules.");
1952 cmd_ret
= CMD_ERROR
;
1957 cmd_ret
= CMD_SUCCESS
;
1961 MSG("Automatic rotation schedules:");
1963 ret
= mi_lttng_writer_open_element(writer
,
1964 mi_lttng_element_rotation_schedules
);
1966 cmd_ret
= CMD_ERROR
;
1971 for (i
= 0; i
< count
; i
++) {
1972 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1973 const struct lttng_rotation_schedule
*schedule
;
1975 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1977 ERR("Failed to retrieve session rotation schedule.");
1978 cmd_ret
= CMD_ERROR
;
1983 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
1985 tmp_ret
= CMD_ERROR
;
1988 tmp_ret
= print_rotation_schedule(schedule
);
1992 * Report an error if the serialization of any of the
1993 * descriptors failed.
1995 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
2000 /* Close the rotation_schedules element. */
2001 ret
= mi_lttng_writer_close_element(writer
);
2003 cmd_ret
= CMD_ERROR
;
2008 lttng_rotation_schedules_destroy(schedules
);
2014 * Find the session with session_name as name
2015 * and print his informations.
2017 static int mi_list_session(const char *session_name
,
2018 struct lttng_session
*sessions
, int count
)
2021 unsigned int session_found
= 0;
2023 if (session_name
== NULL
) {
2024 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2028 for (i
= 0; i
< count
; i
++) {
2029 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2030 /* We need to leave it open to append other informations
2031 * like domain, channel, events etc.*/
2033 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
2041 if (!session_found
) {
2042 ERR("Session '%s' not found", session_name
);
2043 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2053 * List all availables session
2055 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
2059 /* Opening sessions element */
2060 ret
= mi_lttng_sessions_open(writer
);
2065 /* Listing sessions */
2066 for (i
= 0; i
< count
; i
++) {
2067 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
2073 /* Closing sessions element */
2074 ret
= mi_lttng_writer_close_element(writer
);
2084 * List available tracing session. List only basic information.
2086 * If session_name is NULL, all sessions are listed.
2088 static int list_sessions(const char *session_name
)
2090 int ret
= CMD_SUCCESS
;
2092 unsigned int session_found
= 0;
2093 struct lttng_session
*sessions
= NULL
;
2095 count
= lttng_list_sessions(&sessions
);
2096 DBG("Session count %d", count
);
2099 ERR("%s", lttng_strerror(count
));
2105 if (session_name
== NULL
) {
2106 /* List all sessions */
2107 ret
= mi_list_sessions(sessions
, count
);
2109 /* Note : this return an open session element */
2110 ret
= mi_list_session(session_name
, sessions
, count
);
2119 MSG("Currently no available tracing session");
2123 if (session_name
== NULL
) {
2124 MSG("Available tracing sessions:");
2127 for (i
= 0; i
< count
; i
++) {
2128 if (session_name
!= NULL
) {
2129 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2131 MSG("Tracing session %s: [%s%s]", session_name
,
2132 active_string(sessions
[i
].enabled
),
2133 snapshot_string(sessions
[i
].snapshot_mode
));
2134 if (*sessions
[i
].path
) {
2135 MSG("%sTrace output: %s\n", indent4
, sessions
[i
].path
);
2137 memcpy(&listed_session
, &sessions
[i
],
2138 sizeof(listed_session
));
2142 MSG(" %d) %s [%s%s]", i
+ 1,
2144 active_string(sessions
[i
].enabled
),
2145 snapshot_string(sessions
[i
].snapshot_mode
));
2146 if (*sessions
[i
].path
) {
2147 MSG("%sTrace output: %s", indent4
, sessions
[i
].path
);
2149 if (sessions
[i
].live_timer_interval
!= 0) {
2150 MSG("%sLive timer interval: %u %s", indent4
,
2151 sessions
[i
].live_timer_interval
,
2158 if (!session_found
&& session_name
!= NULL
) {
2159 ERR("Session '%s' not found", session_name
);
2164 if (session_name
== NULL
) {
2165 MSG("\nUse lttng list <session_name> for more details");
2177 * list available domain(s) for a session.
2179 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
2182 /* Open domains element */
2183 ret
= mi_lttng_domains_open(writer
);
2188 for (i
= 0; i
< count
; i
++) {
2189 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
2195 /* Closing domains element */
2196 ret
= mi_lttng_writer_close_element(writer
);
2205 * List available domain(s) for a session.
2207 static int list_domains(const char *session_name
)
2209 int i
, count
, ret
= CMD_SUCCESS
;
2210 struct lttng_domain
*domains
= NULL
;
2213 count
= lttng_list_domains(session_name
, &domains
);
2216 ERR("%s", lttng_strerror(count
));
2222 ret
= mi_list_domains(domains
, count
);
2229 MSG("Domains:\n-------------");
2235 for (i
= 0; i
< count
; i
++) {
2236 switch (domains
[i
].type
) {
2237 case LTTNG_DOMAIN_KERNEL
:
2240 case LTTNG_DOMAIN_UST
:
2241 MSG(" - UST global");
2243 case LTTNG_DOMAIN_JUL
:
2244 MSG(" - JUL (Java Util Logging)");
2246 case LTTNG_DOMAIN_LOG4J
:
2247 MSG(" - LOG4j (Logging for Java)");
2249 case LTTNG_DOMAIN_PYTHON
:
2250 MSG(" - Python (logging)");
2266 * The 'list <options>' first level command
2268 int cmd_list(int argc
, const char **argv
)
2270 int opt
, ret
= CMD_SUCCESS
;
2271 const char *session_name
, *leftover
= NULL
;
2272 static poptContext pc
;
2273 struct lttng_domain domain
;
2274 struct lttng_domain
*domains
= NULL
;
2276 memset(&domain
, 0, sizeof(domain
));
2283 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2284 poptReadDefaultConfig(pc
, 0);
2286 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2294 case OPT_LIST_OPTIONS
:
2295 list_cmd_options(stdout
, long_options
);
2298 ret
= CMD_UNDEFINED
;
2305 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
2311 /* Open command element */
2312 ret
= mi_lttng_writer_command_open(writer
,
2313 mi_lttng_element_command_list
);
2319 /* Open output element */
2320 ret
= mi_lttng_writer_open_element(writer
,
2321 mi_lttng_element_command_output
);
2328 /* Get session name (trailing argument) */
2329 session_name
= poptGetArg(pc
);
2330 DBG2("Session name: %s", session_name
);
2332 leftover
= poptGetArg(pc
);
2334 ERR("Unknown argument: %s", leftover
);
2340 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2341 } else if (opt_userspace
) {
2342 DBG2("Listing userspace global domain");
2343 domain
.type
= LTTNG_DOMAIN_UST
;
2344 } else if (opt_jul
) {
2345 DBG2("Listing JUL domain");
2346 domain
.type
= LTTNG_DOMAIN_JUL
;
2347 } else if (opt_log4j
) {
2348 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2349 } else if (opt_python
) {
2350 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2353 if (!opt_kernel
&& opt_syscall
) {
2354 WARN("--syscall will only work with the Kernel domain (-k)");
2359 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2360 handle
= lttng_create_handle(session_name
, &domain
);
2361 if (handle
== NULL
) {
2367 if (session_name
== NULL
) {
2368 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2370 ret
= list_sessions(NULL
);
2377 ret
= list_syscalls();
2382 ret
= list_kernel_events();
2388 if (opt_userspace
) {
2390 ret
= list_ust_event_fields();
2392 ret
= list_ust_events();
2398 if (opt_jul
|| opt_log4j
|| opt_python
) {
2399 ret
= list_agent_events();
2405 /* List session attributes */
2407 /* Open element sessions
2408 * Present for xml consistency */
2409 ret
= mi_lttng_sessions_open(writer
);
2414 /* MI: the ouptut of list_sessions is an unclosed session element */
2415 ret
= list_sessions(session_name
);
2420 ret
= list_rotate_settings(session_name
);
2425 /* Domain listing */
2427 ret
= list_domains(session_name
);
2431 /* Channel listing */
2432 if (opt_kernel
|| opt_userspace
) {
2434 /* Add of domains and domain element for xml
2435 * consistency and validation
2437 ret
= mi_lttng_domains_open(writer
);
2442 /* Open domain and leave it open for
2443 * nested channels printing */
2444 ret
= mi_lttng_domain(writer
, &domain
, 1);
2453 ret
= list_trackers(&domain
);
2459 ret
= list_channels(opt_channel
);
2465 /* Close domain and domain element */
2466 ret
= mi_lttng_close_multi_element(writer
, 2);
2476 /* We want all domain(s) */
2477 nb_domain
= lttng_list_domains(session_name
, &domains
);
2478 if (nb_domain
< 0) {
2480 ERR("%s", lttng_strerror(nb_domain
));
2485 ret
= mi_lttng_domains_open(writer
);
2492 for (i
= 0; i
< nb_domain
; i
++) {
2493 switch (domains
[i
].type
) {
2494 case LTTNG_DOMAIN_KERNEL
:
2495 MSG("=== Domain: Linux kernel ===\n");
2497 case LTTNG_DOMAIN_UST
:
2498 MSG("=== Domain: User space ===\n");
2499 MSG("Buffering scheme: %s\n",
2500 domains
[i
].buf_type
==
2501 LTTNG_BUFFER_PER_PID
? "per-process" : "per-user");
2503 case LTTNG_DOMAIN_JUL
:
2504 MSG("=== Domain: java.util.logging (JUL) ===\n");
2506 case LTTNG_DOMAIN_LOG4J
:
2507 MSG("=== Domain: log4j ===\n");
2509 case LTTNG_DOMAIN_PYTHON
:
2510 MSG("=== Domain: Python logging ===\n");
2513 MSG("=== Domain: Unimplemented ===\n");
2518 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
2525 /* Clean handle before creating a new one */
2527 lttng_destroy_handle(handle
);
2530 handle
= lttng_create_handle(session_name
, &domains
[i
]);
2531 if (handle
== NULL
) {
2536 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2537 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2538 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2539 ret
= list_session_agent_events();
2547 switch (domains
[i
].type
) {
2548 case LTTNG_DOMAIN_KERNEL
:
2549 case LTTNG_DOMAIN_UST
:
2550 ret
= list_trackers(&domains
[i
]);
2559 ret
= list_channels(opt_channel
);
2566 /* Close domain element */
2567 ret
= mi_lttng_writer_close_element(writer
);
2576 /* Close the domains, session and sessions element */
2577 ret
= mi_lttng_close_multi_element(writer
, 3);
2588 /* Close output element */
2589 ret
= mi_lttng_writer_close_element(writer
);
2595 /* Command element close */
2596 ret
= mi_lttng_writer_command_close(writer
);
2604 if (writer
&& mi_lttng_writer_destroy(writer
)) {
2605 /* Preserve original error code */
2606 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2611 lttng_destroy_handle(handle
);
2614 poptFreeContext(pc
);