2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
17 #include <common/mi-lttng.hpp>
18 #include <common/time.hpp>
19 #include <common/tracker.hpp>
20 #include <lttng/domain-internal.hpp>
21 #include <lttng/lttng.h>
23 #include "../command.hpp"
25 static int opt_userspace
;
26 static int opt_kernel
;
29 static int opt_python
;
30 static char *opt_channel
;
31 static int opt_domain
;
32 static int opt_fields
;
33 static int opt_syscall
;
35 const char *indent4
= " ";
36 const char *indent6
= " ";
37 const char *indent8
= " ";
39 #ifdef LTTNG_EMBED_HELP
40 static const char help_msg
[] =
41 #include <lttng-list.1.h>
51 static struct lttng_handle
*the_handle
;
52 static struct mi_writer
*the_writer
;
54 /* Only set when listing a single session. */
55 static struct lttng_session the_listed_session
;
57 static struct poptOption long_options
[] = {
58 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
59 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
60 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
61 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
62 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
63 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
64 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
65 {"channel", 'c', POPT_ARG_STRING
, &opt_channel
, 0, 0, 0},
66 {"domain", 'd', POPT_ARG_VAL
, &opt_domain
, 1, 0, 0},
67 {"fields", 'f', POPT_ARG_VAL
, &opt_fields
, 1, 0, 0},
68 {"syscall", 'S', POPT_ARG_VAL
, &opt_syscall
, 1, 0, 0},
69 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
74 * Get command line from /proc for a specific pid.
76 * On success, return an allocated string pointer to the proc cmdline.
77 * On error, return NULL.
79 static char *get_cmdline_by_pid(pid_t pid
)
84 /* Can't go bigger than /proc/LTTNG_MAX_PID/cmdline */
85 char path
[sizeof("/proc//cmdline") + sizeof(LTTNG_MAX_PID_STR
) - 1];
87 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pid
);
88 fp
= fopen(path
, "r");
93 /* Caller must free() *cmdline */
94 cmdline
= (char *) zmalloc(PATH_MAX
);
96 PERROR("malloc cmdline");
99 ret
= fread(cmdline
, 1, PATH_MAX
, fp
);
101 PERROR("fread proc list");
112 const char *active_string(int value
)
115 case 0: return "inactive";
116 case 1: return "active";
118 default: return NULL
;
122 static const char *snapshot_string(int value
)
133 const char *enabled_string(int value
)
136 case 0: return " [disabled]";
137 case 1: return " [enabled]";
139 default: return NULL
;
144 const char *safe_string(const char *str
)
146 return str
? str
: "";
149 static const char *logleveltype_string(enum lttng_loglevel_type value
)
152 case LTTNG_EVENT_LOGLEVEL_ALL
:
154 case LTTNG_EVENT_LOGLEVEL_RANGE
:
156 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
159 return " <<TYPE UNKN>>";
163 static const char *bitness_event(enum lttng_event_flag flags
)
165 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_32
) {
166 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
167 return " [32/64-bit]";
171 } else if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
179 * Get exclusion names message for a single event.
181 * Returned pointer must be freed by caller. Returns NULL on error.
183 static char *get_exclusion_names_msg(struct lttng_event
*event
)
187 char *exclusion_msg
= NULL
;
190 const char * const exclusion_fmt
= " [exclusions: ";
191 const size_t exclusion_fmt_len
= strlen(exclusion_fmt
);
193 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
194 if (exclusion_count
< 0) {
196 } else if (exclusion_count
== 0) {
198 * No exclusions: return copy of empty string so that
199 * it can be freed by caller.
201 exclusion_msg
= strdup("");
206 * exclusion_msg's size is bounded by the exclusion_fmt string,
207 * a comma per entry, the entry count (fixed-size), a closing
208 * bracket, and a trailing \0.
210 exclusion_msg
= (char *) malloc(exclusion_count
+
211 exclusion_count
* LTTNG_SYMBOL_NAME_LEN
+
212 exclusion_fmt_len
+ 1);
213 if (!exclusion_msg
) {
217 at
= strcpy(exclusion_msg
, exclusion_fmt
) + exclusion_fmt_len
;
218 for (i
= 0; i
< exclusion_count
; ++i
) {
221 /* Append comma between exclusion names */
227 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
229 /* Prints '?' on local error; should never happen */
235 /* Append exclusion name */
236 at
+= sprintf(at
, "%s", name
);
239 /* This also puts a final '\0' at the end of exclusion_msg */
243 return exclusion_msg
;
246 static void print_userspace_probe_location(struct lttng_event
*event
)
248 const struct lttng_userspace_probe_location
*location
;
249 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
250 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
252 location
= lttng_event_get_userspace_probe_location(event
);
254 MSG("Event has no userspace probe location");
258 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
259 if (!lookup_method
) {
260 MSG("Event has no userspace probe location lookup method");
264 MSG("%s%s (type: userspace-probe)%s", indent6
, event
->name
, enabled_string(event
->enabled
));
266 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
268 switch (lttng_userspace_probe_location_get_type(location
)) {
269 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
:
270 MSG("%sType: Unknown", indent8
);
272 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
274 const char *function_name
;
277 MSG("%sType: Function", indent8
);
278 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
279 binary_path
= realpath(lttng_userspace_probe_location_function_get_binary_path(location
), NULL
);
281 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
282 MSG("%sFunction: %s()", indent8
, function_name
? function_name
: "NULL");
283 switch (lookup_type
) {
284 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
285 MSG("%sLookup method: ELF", indent8
);
287 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
288 MSG("%sLookup method: default", indent8
);
291 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
298 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
300 const char *probe_name
, *provider_name
;
303 MSG("%sType: Tracepoint", indent8
);
304 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
305 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
306 binary_path
= realpath(lttng_userspace_probe_location_tracepoint_get_binary_path(location
), NULL
);
307 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
308 MSG("%sTracepoint: %s:%s", indent8
, provider_name
? provider_name
: "NULL", probe_name
? probe_name
: "NULL");
309 switch (lookup_type
) {
310 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
311 MSG("%sLookup method: SDT", indent8
);
314 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
322 ERR("Invalid probe type encountered");
327 * Pretty print single event.
329 static void print_events(struct lttng_event
*event
)
332 const char *filter_str
;
333 char *filter_msg
= NULL
;
334 char *exclusion_msg
= NULL
;
336 ret
= lttng_event_get_filter_expression(event
, &filter_str
);
339 filter_msg
= strdup(" [failed to retrieve filter]");
340 } else if (filter_str
) {
341 if (asprintf(&filter_msg
, " [filter: '%s']", filter_str
) == -1) {
346 exclusion_msg
= get_exclusion_names_msg(event
);
347 if (!exclusion_msg
) {
348 exclusion_msg
= strdup(" [failed to retrieve exclusions]");
351 switch (event
->type
) {
352 case LTTNG_EVENT_TRACEPOINT
:
354 if (event
->loglevel
!= -1) {
355 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
356 indent6
, event
->name
,
358 event
->loglevel_type
),
359 mi_lttng_loglevel_string(
361 the_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(the_writer
);
479 ret
= mi_lttng_domain(the_writer
, domain
, 1);
484 /* Open pids element element */
485 ret
= mi_lttng_pids_open(the_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(
499 pid_element_open
= 0;
502 cur_pid
= events
[i
].pid
;
503 cmdline
= get_cmdline_by_pid(cur_pid
);
509 if (!pid_element_open
) {
510 /* Open and write a pid element */
511 ret
= mi_lttng_pid(the_writer
, cur_pid
, cmdline
,
517 /* Open events element */
518 ret
= mi_lttng_events_open(the_writer
);
523 pid_element_open
= 1;
529 ret
= mi_lttng_event(the_writer
, &events
[i
], 0,
530 the_handle
->domain
.type
);
537 ret
= mi_lttng_writer_close_element(the_writer
);
542 /* Close domain, domains */
543 ret
= mi_lttng_close_multi_element(the_writer
, 2);
551 static int list_agent_events(void)
553 int i
, size
, ret
= CMD_SUCCESS
;
554 struct lttng_domain domain
;
555 struct lttng_handle
*handle
= NULL
;
556 struct lttng_event
*event_list
= NULL
;
558 char *cmdline
= NULL
;
559 const char *agent_domain_str
;
561 memset(&domain
, 0, sizeof(domain
));
563 domain
.type
= LTTNG_DOMAIN_JUL
;
564 } else if (opt_log4j
) {
565 domain
.type
= LTTNG_DOMAIN_LOG4J
;
566 } else if (opt_python
) {
567 domain
.type
= LTTNG_DOMAIN_PYTHON
;
569 ERR("Invalid agent domain selected.");
574 agent_domain_str
= lttng_domain_type_str(domain
.type
);
576 DBG("Getting %s tracing events", agent_domain_str
);
578 handle
= lttng_create_handle(NULL
, &domain
);
579 if (handle
== NULL
) {
584 size
= lttng_list_tracepoints(handle
, &event_list
);
586 ERR("Unable to list %s events: %s", agent_domain_str
,
587 lttng_strerror(size
));
594 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
601 MSG("%s events (Logger name):\n-------------------------",
608 for (i
= 0; i
< size
; i
++) {
609 if (cur_pid
!= event_list
[i
].pid
) {
610 cur_pid
= event_list
[i
].pid
;
611 cmdline
= get_cmdline_by_pid(cur_pid
);
612 if (cmdline
== NULL
) {
616 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
619 MSG("%s- %s", indent6
, event_list
[i
].name
);
628 lttng_destroy_handle(handle
);
633 * Ask session daemon for all user space tracepoints available.
635 static int list_ust_events(void)
637 int i
, size
, ret
= CMD_SUCCESS
;
638 struct lttng_domain domain
;
639 struct lttng_handle
*handle
;
640 struct lttng_event
*event_list
= NULL
;
642 char *cmdline
= NULL
;
644 memset(&domain
, 0, sizeof(domain
));
646 DBG("Getting UST tracing events");
648 domain
.type
= LTTNG_DOMAIN_UST
;
650 handle
= lttng_create_handle(NULL
, &domain
);
651 if (handle
== NULL
) {
656 size
= lttng_list_tracepoints(handle
, &event_list
);
658 ERR("Unable to list UST events: %s", lttng_strerror(size
));
665 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
668 MSG("UST events:\n-------------");
674 for (i
= 0; i
< size
; i
++) {
675 if (cur_pid
!= event_list
[i
].pid
) {
676 cur_pid
= event_list
[i
].pid
;
677 cmdline
= get_cmdline_by_pid(cur_pid
);
678 if (cmdline
== NULL
) {
682 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
685 print_events(&event_list
[i
]);
694 lttng_destroy_handle(handle
);
700 * List all ust event with their fields
702 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
703 struct lttng_domain
*domain
)
707 char *cmdline
= NULL
;
708 int pid_element_open
= 0;
709 int event_element_open
= 0;
710 struct lttng_event cur_event
;
712 memset(&cur_event
, 0, sizeof(cur_event
));
714 /* Open domains element */
715 ret
= mi_lttng_domains_open(the_writer
);
721 ret
= mi_lttng_domain(the_writer
, domain
, 1);
726 /* Open pids element */
727 ret
= mi_lttng_pids_open(the_writer
);
732 for (i
= 0; i
< count
; i
++) {
733 if (cur_pid
!= fields
[i
].event
.pid
) {
734 if (pid_element_open
) {
735 if (event_element_open
) {
736 /* Close the previous field element and event. */
737 ret
= mi_lttng_close_multi_element(
742 event_element_open
= 0;
744 /* Close the previous events, pid element */
745 ret
= mi_lttng_close_multi_element(
750 pid_element_open
= 0;
753 cur_pid
= fields
[i
].event
.pid
;
754 cmdline
= get_cmdline_by_pid(cur_pid
);
755 if (!pid_element_open
) {
756 /* Open and write a pid element */
757 ret
= mi_lttng_pid(the_writer
, cur_pid
, cmdline
,
763 /* Open events element */
764 ret
= mi_lttng_events_open(the_writer
);
768 pid_element_open
= 1;
771 /* Wipe current event since we are about to print a new PID. */
772 memset(&cur_event
, 0, sizeof(cur_event
));
775 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
776 if (event_element_open
) {
777 /* Close the previous fields element and the previous event */
778 ret
= mi_lttng_close_multi_element(
783 event_element_open
= 0;
786 memcpy(&cur_event
, &fields
[i
].event
,
789 if (!event_element_open
) {
790 /* Open and write the event */
791 ret
= mi_lttng_event(the_writer
, &cur_event
, 1,
792 the_handle
->domain
.type
);
797 /* Open a fields element */
798 ret
= mi_lttng_event_fields_open(the_writer
);
802 event_element_open
= 1;
806 /* Print the event_field */
807 ret
= mi_lttng_event_field(the_writer
, &fields
[i
]);
813 /* Close pids, domain, domains */
814 ret
= mi_lttng_close_multi_element(the_writer
, 3);
823 * Ask session daemon for all user space tracepoint fields available.
825 static int list_ust_event_fields(void)
827 int i
, size
, ret
= CMD_SUCCESS
;
828 struct lttng_domain domain
;
829 struct lttng_handle
*handle
;
830 struct lttng_event_field
*event_field_list
;
832 char *cmdline
= NULL
;
834 struct lttng_event cur_event
;
836 memset(&domain
, 0, sizeof(domain
));
837 memset(&cur_event
, 0, sizeof(cur_event
));
839 DBG("Getting UST tracing event fields");
841 domain
.type
= LTTNG_DOMAIN_UST
;
843 handle
= lttng_create_handle(NULL
, &domain
);
844 if (handle
== NULL
) {
849 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
851 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
858 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
865 MSG("UST events:\n-------------");
871 for (i
= 0; i
< size
; i
++) {
872 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
873 cur_pid
= event_field_list
[i
].event
.pid
;
874 cmdline
= get_cmdline_by_pid(cur_pid
);
875 if (cmdline
== NULL
) {
879 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
881 /* Wipe current event since we are about to print a new PID. */
882 memset(&cur_event
, 0, sizeof(cur_event
));
884 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
885 print_events(&event_field_list
[i
].event
);
886 memcpy(&cur_event
, &event_field_list
[i
].event
,
889 print_event_field(&event_field_list
[i
]);
896 free(event_field_list
);
898 lttng_destroy_handle(handle
);
904 * Print a list of kernel events
906 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
907 struct lttng_domain
*domain
)
911 /* Open domains element */
912 ret
= mi_lttng_domains_open(the_writer
);
918 ret
= mi_lttng_domain(the_writer
, domain
, 1);
924 ret
= mi_lttng_events_open(the_writer
);
929 for (i
= 0; i
< count
; i
++) {
930 ret
= mi_lttng_event(the_writer
, &events
[i
], 0,
931 the_handle
->domain
.type
);
937 /* close events, domain and domains */
938 ret
= mi_lttng_close_multi_element(the_writer
, 3);
948 * Ask for all trace events in the kernel
950 static int list_kernel_events(void)
952 int i
, size
, ret
= CMD_SUCCESS
;
953 struct lttng_domain domain
;
954 struct lttng_handle
*handle
;
955 struct lttng_event
*event_list
;
957 memset(&domain
, 0, sizeof(domain
));
959 DBG("Getting kernel tracing events");
961 domain
.type
= LTTNG_DOMAIN_KERNEL
;
963 handle
= lttng_create_handle(NULL
, &domain
);
964 if (handle
== NULL
) {
969 size
= lttng_list_tracepoints(handle
, &event_list
);
971 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
972 lttng_destroy_handle(handle
);
978 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
984 MSG("Kernel events:\n-------------");
986 for (i
= 0; i
< size
; i
++) {
987 print_events(&event_list
[i
]);
996 lttng_destroy_handle(handle
);
1000 lttng_destroy_handle(handle
);
1006 * Print a list of system calls.
1008 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1013 ret
= mi_lttng_events_open(the_writer
);
1018 for (i
= 0; i
< count
; i
++) {
1019 ret
= mi_lttng_event(the_writer
, &events
[i
], 0,
1020 the_handle
->domain
.type
);
1027 ret
= mi_lttng_writer_close_element(the_writer
);
1037 * Ask for kernel system calls.
1039 static int list_syscalls(void)
1041 int i
, size
, ret
= CMD_SUCCESS
;
1042 struct lttng_event
*event_list
;
1044 DBG("Getting kernel system call events");
1046 size
= lttng_list_syscalls(&event_list
);
1048 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1055 ret
= mi_list_syscalls(event_list
, size
);
1061 MSG("System calls:\n-------------");
1063 for (i
= 0; i
< size
; i
++) {
1064 print_events(&event_list
[i
]);
1080 * Print a list of agent events
1082 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1086 /* Open events element */
1087 ret
= mi_lttng_events_open(the_writer
);
1092 for (i
= 0; i
< count
; i
++) {
1093 ret
= mi_lttng_event(the_writer
, &events
[i
], 0,
1094 the_handle
->domain
.type
);
1100 /* Close events element */
1101 ret
= mi_lttng_writer_close_element(the_writer
);
1108 * List agent events for a specific session using the handle.
1110 * Return CMD_SUCCESS on success else a negative value.
1112 static int list_session_agent_events(void)
1114 int ret
= CMD_SUCCESS
, count
, i
;
1115 struct lttng_event
*events
= NULL
;
1117 count
= lttng_list_events(the_handle
, "", &events
);
1120 ERR("%s", lttng_strerror(count
));
1126 ret
= mi_list_session_agent_events(events
, count
);
1133 MSG("Events (Logger name):\n---------------------");
1135 MSG("%sNone\n", indent6
);
1139 for (i
= 0; i
< count
; i
++) {
1140 const char *filter_str
;
1141 char *filter_msg
= NULL
;
1142 struct lttng_event
*event
= &events
[i
];
1144 ret
= lttng_event_get_filter_expression(event
,
1147 filter_msg
= strdup(" [failed to retrieve filter]");
1148 } else if (filter_str
) {
1149 if (asprintf(&filter_msg
, " [filter: '%s']", filter_str
) == -1) {
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(
1165 safe_string(filter_msg
));
1167 MSG("%s- %s%s%s", indent4
, event
->name
,
1168 enabled_string(event
->enabled
),
1169 safe_string(filter_msg
));
1185 * print a list of event
1187 static int mi_list_events(struct lttng_event
*events
, int count
)
1191 /* Open events element */
1192 ret
= mi_lttng_events_open(the_writer
);
1197 for (i
= 0; i
< count
; i
++) {
1198 ret
= mi_lttng_event(the_writer
, &events
[i
], 0,
1199 the_handle
->domain
.type
);
1205 /* Close events element */
1206 ret
= mi_lttng_writer_close_element(the_writer
);
1213 * List events of channel of session and domain.
1215 static int list_events(const char *channel_name
)
1217 int ret
= CMD_SUCCESS
, count
, i
;
1218 struct lttng_event
*events
= NULL
;
1220 count
= lttng_list_events(the_handle
, channel_name
, &events
);
1223 ERR("%s", lttng_strerror(count
));
1229 ret
= mi_list_events(events
, count
);
1236 MSG("\n%sRecording event rules:", indent4
);
1238 MSG("%sNone\n", indent6
);
1242 for (i
= 0; i
< count
; i
++) {
1243 print_events(&events
[i
]);
1255 void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1259 _MSG("%s%s:", indent6
, timer_name
);
1260 for (i
= 0; i
< space_count
; i
++) {
1265 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1272 * Pretty print channel
1274 static void print_channel(struct lttng_channel
*channel
)
1277 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1278 int64_t blocking_timeout
;
1280 ret
= lttng_channel_get_discarded_event_count(channel
,
1283 ERR("Failed to retrieve discarded event count of channel");
1287 ret
= lttng_channel_get_lost_packet_count(channel
,
1290 ERR("Failed to retrieve lost packet count of channel");
1294 ret
= lttng_channel_get_monitor_timer_interval(channel
,
1295 &monitor_timer_interval
);
1297 ERR("Failed to retrieve monitor interval of channel");
1301 ret
= lttng_channel_get_blocking_timeout(channel
,
1304 ERR("Failed to retrieve blocking timeout of channel");
1308 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1309 MSG("%sAttributes:", indent4
);
1310 MSG("%sEvent-loss mode: %s", indent6
, channel
->attr
.overwrite
? "overwrite" : "discard");
1311 MSG("%sSub-buffer size: %" PRIu64
" bytes", indent6
, channel
->attr
.subbuf_size
);
1312 MSG("%sSub-buffer count: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1314 print_timer("Switch timer", 5, channel
->attr
.switch_timer_interval
);
1315 print_timer("Read timer", 7, channel
->attr
.read_timer_interval
);
1316 print_timer("Monitor timer", 4, monitor_timer_interval
);
1318 if (!channel
->attr
.overwrite
) {
1319 if (blocking_timeout
== -1) {
1320 MSG("%sBlocking timeout: infinite", indent6
);
1322 MSG("%sBlocking timeout: %" PRId64
" %s", indent6
,
1323 blocking_timeout
, USEC_UNIT
);
1327 MSG("%sTrace file count: %" PRIu64
" per stream", indent6
,
1328 channel
->attr
.tracefile_count
== 0 ?
1329 1 : channel
->attr
.tracefile_count
);
1330 if (channel
->attr
.tracefile_size
!= 0 ) {
1331 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
,
1332 channel
->attr
.tracefile_size
);
1334 MSG("%sTrace file size: %s", indent6
, "unlimited");
1336 switch (channel
->attr
.output
) {
1337 case LTTNG_EVENT_SPLICE
:
1338 MSG("%sOutput mode: splice", indent6
);
1340 case LTTNG_EVENT_MMAP
:
1341 MSG("%sOutput mode: mmap", indent6
);
1345 MSG("\n%sStatistics:", indent4
);
1346 if (the_listed_session
.snapshot_mode
) {
1348 * The lost packet count is omitted for sessions in snapshot
1349 * mode as it is misleading: it would indicate the number of
1350 * packets that the consumer could not extract during the
1351 * course of recording the snapshot. It does not have the
1352 * same meaning as the "regular" lost packet count that
1353 * would result from the consumer not keeping up with
1354 * event production in an overwrite-mode channel.
1356 * A more interesting statistic would be the number of
1357 * packets lost between the first and last extracted
1358 * packets of a given snapshot (which prevents most analyses).
1360 MSG("%sNone", indent6
);
1361 goto skip_stats_printing
;
1364 if (!channel
->attr
.overwrite
) {
1365 MSG("%sDiscarded events: %" PRIu64
, indent6
, discarded_events
);
1367 MSG("%sLost packets: %" PRIu64
, indent6
, lost_packets
);
1369 skip_stats_printing
:
1375 * Print a list of channel
1378 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1379 const char *channel_name
)
1382 unsigned int chan_found
= 0;
1384 /* Open channels element */
1385 ret
= mi_lttng_channels_open(the_writer
);
1390 for (i
= 0; i
< count
; i
++) {
1391 if (channel_name
!= NULL
) {
1392 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1399 /* Write channel element and leave it open */
1400 ret
= mi_lttng_channel(the_writer
, &channels
[i
], 1);
1405 /* Listing events per channel */
1406 ret
= list_events(channels
[i
].name
);
1411 /* Closing the channel element we opened earlier */
1412 ret
= mi_lttng_writer_close_element(the_writer
);
1422 /* Close channels element */
1423 ret
= mi_lttng_writer_close_element(the_writer
);
1433 * List channel(s) of session and domain.
1435 * If channel_name is NULL, all channels are listed.
1437 static int list_channels(const char *channel_name
)
1439 int count
, i
, ret
= CMD_SUCCESS
;
1440 unsigned int chan_found
= 0;
1441 struct lttng_channel
*channels
= NULL
;
1443 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1445 count
= lttng_list_channels(the_handle
, &channels
);
1448 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1450 /* When printing mi this is not an error
1451 * but an empty channels element */
1455 goto error_channels
;
1459 /* We had a real error */
1461 ERR("%s", lttng_strerror(count
));
1462 goto error_channels
;
1469 ret
= mi_list_channels(channels
, count
, channel_name
);
1477 MSG("Channels:\n-------------");
1480 for (i
= 0; i
< count
; i
++) {
1481 if (channel_name
!= NULL
) {
1482 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1488 print_channel(&channels
[i
]);
1490 /* Listing events per channel */
1491 ret
= list_events(channels
[i
].name
);
1501 if (!chan_found
&& channel_name
!= NULL
) {
1503 ERR("Channel %s not found", channel_name
);
1514 static const char *get_capitalized_process_attr_str(enum lttng_process_attr process_attr
)
1516 switch (process_attr
) {
1517 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1518 return "Process ID";
1519 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1520 return "Virtual process ID";
1521 case LTTNG_PROCESS_ATTR_USER_ID
:
1523 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1524 return "Virtual user ID";
1525 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1527 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1528 return "Virtual group ID";
1535 static int handle_process_attr_status(enum lttng_process_attr process_attr
,
1536 enum lttng_process_attr_tracker_handle_status status
)
1538 int ret
= CMD_SUCCESS
;
1541 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID_TRACKING_POLICY
:
1542 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
1545 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
1546 ERR("Communication occurred while fetching %s tracker",
1547 lttng_process_attr_to_string(process_attr
));
1550 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_SESSION_DOES_NOT_EXIST
:
1551 ERR("Failed to get the inclusion set of the %s tracker: session `%s` no longer exists",
1552 lttng_process_attr_to_string(process_attr
),
1553 the_handle
->session_name
);
1557 ERR("Unknown error occurred while fetching the inclusion set of the %s tracker",
1558 lttng_process_attr_to_string(process_attr
));
1566 static int mi_output_empty_tracker(enum lttng_process_attr process_attr
)
1570 ret
= mi_lttng_process_attribute_tracker_open(the_writer
, process_attr
);
1575 ret
= mi_lttng_close_multi_element(the_writer
, 2);
1580 static inline bool is_value_type_name(
1581 enum lttng_process_attr_value_type value_type
)
1583 return value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
||
1584 value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
;
1588 * List a process attribute tracker for a session and domain tuple.
1590 static int list_process_attr_tracker(enum lttng_process_attr process_attr
)
1593 unsigned int count
, i
;
1594 enum lttng_tracking_policy policy
;
1595 enum lttng_error_code ret_code
;
1596 enum lttng_process_attr_tracker_handle_status handle_status
;
1597 enum lttng_process_attr_values_status values_status
;
1598 const struct lttng_process_attr_values
*values
;
1599 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
1601 ret_code
= lttng_session_get_tracker_handle(the_handle
->session_name
,
1602 the_handle
->domain
.type
, process_attr
, &tracker_handle
);
1603 if (ret_code
!= LTTNG_OK
) {
1604 ERR("Failed to get process attribute tracker handle: %s",
1605 lttng_strerror(ret_code
));
1610 handle_status
= lttng_process_attr_tracker_handle_get_inclusion_set(
1611 tracker_handle
, &values
);
1612 ret
= handle_process_attr_status(process_attr
, handle_status
);
1613 if (ret
!= CMD_SUCCESS
) {
1617 handle_status
= lttng_process_attr_tracker_handle_get_tracking_policy(
1618 tracker_handle
, &policy
);
1619 ret
= handle_process_attr_status(process_attr
, handle_status
);
1620 if (ret
!= CMD_SUCCESS
) {
1625 char *process_attr_name
;
1626 const int print_ret
= asprintf(&process_attr_name
, "%ss:",
1627 get_capitalized_process_attr_str(process_attr
));
1629 if (print_ret
== -1) {
1633 _MSG(" %-22s", process_attr_name
);
1634 free(process_attr_name
);
1637 case LTTNG_TRACKING_POLICY_INCLUDE_SET
:
1639 case LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
1641 mi_output_empty_tracker(process_attr
);
1646 case LTTNG_TRACKING_POLICY_INCLUDE_ALL
:
1651 ERR("Unknown tracking policy encoutered while listing the %s process attribute tracker of session `%s`",
1652 lttng_process_attr_to_string(process_attr
),
1653 the_handle
->session_name
);
1658 values_status
= lttng_process_attr_values_get_count(values
, &count
);
1659 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1660 ERR("Failed to get the count of values in the inclusion set of the %s process attribute tracker of session `%s`",
1661 lttng_process_attr_to_string(process_attr
),
1662 the_handle
->session_name
);
1668 /* Functionally equivalent to the 'exclude all' policy. */
1670 mi_output_empty_tracker(process_attr
);
1677 /* Mi tracker_id element */
1679 /* Open tracker_id and targets elements */
1680 ret
= mi_lttng_process_attribute_tracker_open(
1681 the_writer
, process_attr
);
1687 for (i
= 0; i
< count
; i
++) {
1688 const enum lttng_process_attr_value_type value_type
=
1689 lttng_process_attr_values_get_type_at_index(
1691 int64_t integral_value
= INT64_MAX
;
1692 const char *name
= "error";
1697 switch (value_type
) {
1698 case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID
:
1702 values_status
= lttng_process_attr_values_get_pid_at_index(
1704 integral_value
= (int64_t) pid
;
1707 case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID
:
1711 values_status
= lttng_process_attr_values_get_uid_at_index(
1713 integral_value
= (int64_t) uid
;
1716 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID
:
1720 values_status
= lttng_process_attr_values_get_gid_at_index(
1722 integral_value
= (int64_t) gid
;
1725 case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
:
1726 values_status
= lttng_process_attr_values_get_user_name_at_index(
1729 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
:
1730 values_status
= lttng_process_attr_values_get_group_name_at_index(
1738 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1740 * Not possible given the current liblttng-ctl
1743 ERR("Unknown error occurred while fetching process attribute value in inclusion list");
1748 if (is_value_type_name(value_type
)) {
1751 _MSG("%" PRIi64
, integral_value
);
1756 ret
= is_value_type_name(value_type
) ?
1757 mi_lttng_string_process_attribute_value(
1761 mi_lttng_integral_process_attribute_value(
1764 integral_value
, false);
1772 /* Mi close tracker_id and targets */
1774 ret
= mi_lttng_close_multi_element(the_writer
, 2);
1780 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
1785 * List all trackers of a domain
1787 static int list_trackers(const struct lttng_domain
*domain
)
1791 MSG("Tracked process attributes");
1792 /* Trackers listing */
1794 ret
= mi_lttng_trackers_open(the_writer
);
1800 switch (domain
->type
) {
1801 case LTTNG_DOMAIN_KERNEL
:
1803 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_PROCESS_ID
);
1808 ret
= list_process_attr_tracker(
1809 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1814 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_USER_ID
);
1819 ret
= list_process_attr_tracker(
1820 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1825 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_GROUP_ID
);
1830 ret
= list_process_attr_tracker(
1831 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1836 case LTTNG_DOMAIN_UST
:
1838 ret
= list_process_attr_tracker(
1839 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1844 ret
= list_process_attr_tracker(
1845 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1850 ret
= list_process_attr_tracker(
1851 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1861 /* Close trackers element */
1862 ret
= mi_lttng_writer_close_element(the_writer
);
1872 static enum cmd_error_code
print_periodic_rotation_schedule(
1873 const struct lttng_rotation_schedule
*schedule
)
1875 enum cmd_error_code ret
;
1876 enum lttng_rotation_status status
;
1879 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1881 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1882 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1887 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
1893 static enum cmd_error_code
print_size_threshold_rotation_schedule(
1894 const struct lttng_rotation_schedule
*schedule
)
1896 enum cmd_error_code ret
;
1897 enum lttng_rotation_status status
;
1900 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
1902 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1903 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1908 MSG(" size threshold: %" PRIu64
" bytes", value
);
1914 static enum cmd_error_code
print_rotation_schedule(
1915 const struct lttng_rotation_schedule
*schedule
)
1917 enum cmd_error_code ret
;
1919 switch (lttng_rotation_schedule_get_type(schedule
)) {
1920 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1921 ret
= print_size_threshold_rotation_schedule(schedule
);
1923 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1924 ret
= print_periodic_rotation_schedule(schedule
);
1933 * List the automatic rotation settings.
1935 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1938 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1939 unsigned int count
, i
;
1940 struct lttng_rotation_schedules
*schedules
= NULL
;
1941 enum lttng_rotation_status status
;
1943 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1944 if (ret
!= LTTNG_OK
) {
1945 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1946 cmd_ret
= CMD_ERROR
;
1950 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1951 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1952 ERR("Failed to retrieve the number of session rotation schedules.");
1953 cmd_ret
= CMD_ERROR
;
1958 cmd_ret
= CMD_SUCCESS
;
1962 MSG("Automatic rotation schedules:");
1964 ret
= mi_lttng_writer_open_element(the_writer
,
1965 mi_lttng_element_rotation_schedules
);
1967 cmd_ret
= CMD_ERROR
;
1972 for (i
= 0; i
< count
; i
++) {
1973 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1974 const struct lttng_rotation_schedule
*schedule
;
1976 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1978 ERR("Failed to retrieve session rotation schedule.");
1979 cmd_ret
= CMD_ERROR
;
1984 ret
= mi_lttng_rotation_schedule(the_writer
, schedule
);
1986 tmp_ret
= CMD_ERROR
;
1989 tmp_ret
= print_rotation_schedule(schedule
);
1993 * Report an error if the serialization of any of the
1994 * descriptors failed.
1996 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
2001 /* Close the rotation_schedules element. */
2002 ret
= mi_lttng_writer_close_element(the_writer
);
2004 cmd_ret
= CMD_ERROR
;
2009 lttng_rotation_schedules_destroy(schedules
);
2015 * Find the session with session_name as name
2016 * and print his informations.
2018 static int mi_list_session(const char *session_name
,
2019 struct lttng_session
*sessions
, int count
)
2022 unsigned int session_found
= 0;
2024 if (session_name
== NULL
) {
2025 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2029 for (i
= 0; i
< count
; i
++) {
2030 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2031 /* We need to leave it open to append other informations
2032 * like domain, channel, events etc.*/
2034 ret
= mi_lttng_session(the_writer
, &sessions
[i
], 1);
2042 if (!session_found
) {
2043 ERR("Session '%s' not found", session_name
);
2044 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2054 * List all availables session
2056 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
2060 /* Opening sessions element */
2061 ret
= mi_lttng_sessions_open(the_writer
);
2066 /* Listing sessions */
2067 for (i
= 0; i
< count
; i
++) {
2068 ret
= mi_lttng_session(the_writer
, &sessions
[i
], 0);
2074 /* Closing sessions element */
2075 ret
= mi_lttng_writer_close_element(the_writer
);
2085 * List available tracing session. List only basic information.
2087 * If session_name is NULL, all sessions are listed.
2089 static int list_sessions(const char *session_name
)
2091 int ret
= CMD_SUCCESS
;
2093 unsigned int session_found
= 0;
2094 struct lttng_session
*sessions
= NULL
;
2096 count
= lttng_list_sessions(&sessions
);
2097 DBG("Session count %d", count
);
2100 ERR("%s", lttng_strerror(count
));
2106 if (session_name
== NULL
) {
2107 /* List all sessions */
2108 ret
= mi_list_sessions(sessions
, count
);
2110 /* Note : this return an open session element */
2111 ret
= mi_list_session(session_name
, sessions
, count
);
2120 MSG("Currently no available recording session");
2124 if (session_name
== NULL
) {
2125 MSG("Available recording sessions:");
2128 for (i
= 0; i
< count
; i
++) {
2129 if (session_name
!= NULL
) {
2130 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2132 MSG("Recording session %s: [%s%s]", session_name
,
2133 active_string(sessions
[i
].enabled
),
2134 snapshot_string(sessions
[i
].snapshot_mode
));
2135 if (*sessions
[i
].path
) {
2136 MSG("%sTrace output: %s\n", indent4
, sessions
[i
].path
);
2138 memcpy(&the_listed_session
,
2140 sizeof(the_listed_session
));
2144 MSG(" %d) %s [%s%s]", i
+ 1,
2146 active_string(sessions
[i
].enabled
),
2147 snapshot_string(sessions
[i
].snapshot_mode
));
2148 if (*sessions
[i
].path
) {
2149 MSG("%sTrace output: %s", indent4
, sessions
[i
].path
);
2151 if (sessions
[i
].live_timer_interval
!= 0) {
2152 MSG("%sLive timer interval: %u %s", indent4
,
2153 sessions
[i
].live_timer_interval
,
2160 if (!session_found
&& session_name
!= NULL
) {
2161 ERR("Session '%s' not found", session_name
);
2166 if (session_name
== NULL
) {
2167 MSG("\nUse lttng list <session_name> for more details");
2179 * list available domain(s) for a session.
2181 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
2184 /* Open domains element */
2185 ret
= mi_lttng_domains_open(the_writer
);
2190 for (i
= 0; i
< count
; i
++) {
2191 ret
= mi_lttng_domain(the_writer
, &domains
[i
], 0);
2197 /* Closing domains element */
2198 ret
= mi_lttng_writer_close_element(the_writer
);
2207 * List available domain(s) for a session.
2209 static int list_domains(const char *session_name
)
2211 int i
, count
, ret
= CMD_SUCCESS
;
2212 struct lttng_domain
*domains
= NULL
;
2215 count
= lttng_list_domains(session_name
, &domains
);
2218 ERR("%s", lttng_strerror(count
));
2224 ret
= mi_list_domains(domains
, count
);
2231 MSG("Domains:\n-------------");
2237 for (i
= 0; i
< count
; i
++) {
2238 switch (domains
[i
].type
) {
2239 case LTTNG_DOMAIN_KERNEL
:
2242 case LTTNG_DOMAIN_UST
:
2243 MSG(" - UST global");
2245 case LTTNG_DOMAIN_JUL
:
2246 MSG(" - JUL (Java Util Logging)");
2248 case LTTNG_DOMAIN_LOG4J
:
2249 MSG(" - LOG4j (Logging for Java)");
2251 case LTTNG_DOMAIN_PYTHON
:
2252 MSG(" - Python (logging)");
2268 * The 'list <options>' first level command
2270 int cmd_list(int argc
, const char **argv
)
2272 int opt
, ret
= CMD_SUCCESS
;
2273 const char *session_name
, *leftover
= NULL
;
2274 static poptContext pc
;
2275 struct lttng_domain domain
;
2276 struct lttng_domain
*domains
= NULL
;
2278 memset(&domain
, 0, sizeof(domain
));
2285 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2286 poptReadDefaultConfig(pc
, 0);
2288 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2296 case OPT_LIST_OPTIONS
:
2297 list_cmd_options(stdout
, long_options
);
2300 ret
= CMD_UNDEFINED
;
2307 the_writer
= mi_lttng_writer_create(
2308 fileno(stdout
), lttng_opt_mi
);
2314 /* Open command element */
2315 ret
= mi_lttng_writer_command_open(
2316 the_writer
, mi_lttng_element_command_list
);
2322 /* Open output element */
2323 ret
= mi_lttng_writer_open_element(
2324 the_writer
, mi_lttng_element_command_output
);
2331 /* Get session name (trailing argument) */
2332 session_name
= poptGetArg(pc
);
2333 DBG2("Session name: %s", session_name
);
2335 leftover
= poptGetArg(pc
);
2337 ERR("Unknown argument: %s", leftover
);
2343 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2344 } else if (opt_userspace
) {
2345 DBG2("Listing userspace global domain");
2346 domain
.type
= LTTNG_DOMAIN_UST
;
2347 } else if (opt_jul
) {
2348 DBG2("Listing JUL domain");
2349 domain
.type
= LTTNG_DOMAIN_JUL
;
2350 } else if (opt_log4j
) {
2351 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2352 } else if (opt_python
) {
2353 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2356 if (!opt_kernel
&& opt_syscall
) {
2357 WARN("--syscall will only work with the Kernel domain (-k)");
2362 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2363 the_handle
= lttng_create_handle(session_name
, &domain
);
2364 if (the_handle
== NULL
) {
2370 if (session_name
== NULL
) {
2371 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2373 ret
= list_sessions(NULL
);
2380 ret
= list_syscalls();
2385 ret
= list_kernel_events();
2391 if (opt_userspace
) {
2393 ret
= list_ust_event_fields();
2395 ret
= list_ust_events();
2401 if (opt_jul
|| opt_log4j
|| opt_python
) {
2402 ret
= list_agent_events();
2408 /* List session attributes */
2410 /* Open element sessions
2411 * Present for xml consistency */
2412 ret
= mi_lttng_sessions_open(the_writer
);
2417 /* MI: the ouptut of list_sessions is an unclosed session element */
2418 ret
= list_sessions(session_name
);
2423 ret
= list_rotate_settings(session_name
);
2428 /* Domain listing */
2430 ret
= list_domains(session_name
);
2434 /* Channel listing */
2435 if (opt_kernel
|| opt_userspace
) {
2437 /* Add of domains and domain element for xml
2438 * consistency and validation
2440 ret
= mi_lttng_domains_open(the_writer
);
2445 /* Open domain and leave it open for
2446 * nested channels printing */
2447 ret
= mi_lttng_domain(the_writer
, &domain
, 1);
2456 ret
= list_trackers(&domain
);
2462 ret
= list_channels(opt_channel
);
2468 /* Close domain and domain element */
2469 ret
= mi_lttng_close_multi_element(
2480 /* We want all domain(s) */
2481 nb_domain
= lttng_list_domains(session_name
, &domains
);
2482 if (nb_domain
< 0) {
2484 ERR("%s", lttng_strerror(nb_domain
));
2489 ret
= mi_lttng_domains_open(the_writer
);
2496 for (i
= 0; i
< nb_domain
; i
++) {
2497 switch (domains
[i
].type
) {
2498 case LTTNG_DOMAIN_KERNEL
:
2499 MSG("=== Domain: Linux kernel ===\n");
2501 case LTTNG_DOMAIN_UST
:
2502 MSG("=== Domain: User space ===\n");
2503 MSG("Buffering scheme: %s\n",
2504 domains
[i
].buf_type
==
2505 LTTNG_BUFFER_PER_PID
? "per-process" : "per-user");
2507 case LTTNG_DOMAIN_JUL
:
2508 MSG("=== Domain: java.util.logging (JUL) ===\n");
2510 case LTTNG_DOMAIN_LOG4J
:
2511 MSG("=== Domain: log4j ===\n");
2513 case LTTNG_DOMAIN_PYTHON
:
2514 MSG("=== Domain: Python logging ===\n");
2517 MSG("=== Domain: Unimplemented ===\n");
2522 ret
= mi_lttng_domain(the_writer
,
2530 /* Clean handle before creating a new one */
2532 lttng_destroy_handle(the_handle
);
2535 the_handle
= lttng_create_handle(
2536 session_name
, &domains
[i
]);
2537 if (the_handle
== NULL
) {
2542 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2543 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2544 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2545 ret
= list_session_agent_events();
2553 switch (domains
[i
].type
) {
2554 case LTTNG_DOMAIN_KERNEL
:
2555 case LTTNG_DOMAIN_UST
:
2556 ret
= list_trackers(&domains
[i
]);
2565 ret
= list_channels(opt_channel
);
2572 /* Close domain element */
2573 ret
= mi_lttng_writer_close_element(
2583 /* Close the domains, session and sessions element */
2584 ret
= mi_lttng_close_multi_element(
2596 /* Close output element */
2597 ret
= mi_lttng_writer_close_element(the_writer
);
2603 /* Command element close */
2604 ret
= mi_lttng_writer_command_close(the_writer
);
2612 if (the_writer
&& mi_lttng_writer_destroy(the_writer
)) {
2613 /* Preserve original error code */
2614 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2619 lttng_destroy_handle(the_handle
);
2622 poptFreeContext(pc
);