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
11 #include "../command.hpp"
13 #include <common/mi-lttng.hpp>
14 #include <common/time.hpp>
15 #include <common/tracker.hpp>
17 #include <lttng/domain-internal.hpp>
18 #include <lttng/lttng.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
*the_handle
;
53 static struct mi_writer
*the_writer
;
55 /* Only set when listing a single session. */
56 static struct lttng_session the_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
},
71 { 0, 0, 0, 0, 0, 0, 0 }
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
<char>(PATH_MAX
);
97 PERROR("malloc cmdline");
101 ret
= fread(cmdline
, 1, PATH_MAX
, fp
);
103 PERROR("fread proc list");
113 static const char *active_string(int value
)
127 static const char *snapshot_string(int value
)
137 static const char *enabled_string(int value
)
141 return " [disabled]";
151 static const char *safe_string(const char *str
)
153 return str
? str
: "";
156 static const char *logleveltype_string(enum lttng_loglevel_type value
)
159 case LTTNG_EVENT_LOGLEVEL_ALL
:
161 case LTTNG_EVENT_LOGLEVEL_RANGE
:
163 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
166 return " <<TYPE UNKN>>";
170 static const char *bitness_event(enum lttng_event_flag flags
)
172 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_32
) {
173 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
174 return " [32/64-bit]";
178 } else if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
186 * Get exclusion names message for a single event.
188 * Returned pointer must be freed by caller. Returns NULL on error.
190 static char *get_exclusion_names_msg(struct lttng_event
*event
)
194 char *exclusion_msg
= NULL
;
197 const char *const exclusion_fmt
= " [exclusions: ";
198 const size_t exclusion_fmt_len
= strlen(exclusion_fmt
);
200 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
201 if (exclusion_count
< 0) {
203 } else if (exclusion_count
== 0) {
205 * No exclusions: return copy of empty string so that
206 * it can be freed by caller.
208 exclusion_msg
= strdup("");
213 * exclusion_msg's size is bounded by the exclusion_fmt string,
214 * a comma per entry, the entry count (fixed-size), a closing
215 * bracket, and a trailing \0.
217 exclusion_msg
= (char *) malloc(exclusion_count
+ exclusion_count
* LTTNG_SYMBOL_NAME_LEN
+
218 exclusion_fmt_len
+ 1);
219 if (!exclusion_msg
) {
223 at
= strcpy(exclusion_msg
, exclusion_fmt
) + exclusion_fmt_len
;
224 for (i
= 0; i
< exclusion_count
; ++i
) {
227 /* Append comma between exclusion names */
233 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
235 /* Prints '?' on local error; should never happen */
241 /* Append exclusion name */
242 at
+= sprintf(at
, "%s", name
);
245 /* This also puts a final '\0' at the end of exclusion_msg */
249 return exclusion_msg
;
252 static void print_userspace_probe_location(struct lttng_event
*event
)
254 const struct lttng_userspace_probe_location
*location
;
255 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
256 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
258 location
= lttng_event_get_userspace_probe_location(event
);
260 MSG("Event has no userspace probe location");
264 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
265 if (!lookup_method
) {
266 MSG("Event has no userspace probe location lookup method");
270 MSG("%s%s (type: userspace-probe)%s", indent6
, event
->name
, enabled_string(event
->enabled
));
272 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
274 switch (lttng_userspace_probe_location_get_type(location
)) {
275 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
:
276 MSG("%sType: Unknown", indent8
);
278 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
280 const char *function_name
;
283 MSG("%sType: Function", indent8
);
284 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
285 binary_path
= realpath(
286 lttng_userspace_probe_location_function_get_binary_path(location
), NULL
);
288 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
289 MSG("%sFunction: %s()", indent8
, function_name
? function_name
: "NULL");
290 switch (lookup_type
) {
291 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
292 MSG("%sLookup method: ELF", indent8
);
294 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
295 MSG("%sLookup method: default", indent8
);
298 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
305 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
307 const char *probe_name
, *provider_name
;
310 MSG("%sType: Tracepoint", indent8
);
311 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
313 lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
314 binary_path
= realpath(
315 lttng_userspace_probe_location_tracepoint_get_binary_path(location
), NULL
);
316 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
317 MSG("%sTracepoint: %s:%s",
319 provider_name
? provider_name
: "NULL",
320 probe_name
? probe_name
: "NULL");
321 switch (lookup_type
) {
322 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
323 MSG("%sLookup method: SDT", indent8
);
326 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
334 ERR("Invalid probe type encountered");
339 * Pretty print single event.
341 static void print_events(struct lttng_event
*event
)
344 const char *filter_str
;
345 char *filter_msg
= NULL
;
346 char *exclusion_msg
= NULL
;
348 ret
= lttng_event_get_filter_expression(event
, &filter_str
);
351 filter_msg
= strdup(" [failed to retrieve filter]");
352 } else if (filter_str
) {
353 if (asprintf(&filter_msg
, " [filter: '%s']", filter_str
) == -1) {
358 exclusion_msg
= get_exclusion_names_msg(event
);
359 if (!exclusion_msg
) {
360 exclusion_msg
= strdup(" [failed to retrieve exclusions]");
363 switch (event
->type
) {
364 case LTTNG_EVENT_TRACEPOINT
:
366 if (event
->loglevel
!= -1) {
367 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
370 logleveltype_string(event
->loglevel_type
),
371 mi_lttng_loglevel_string(event
->loglevel
, the_handle
->domain
.type
),
373 enabled_string(event
->enabled
),
374 safe_string(exclusion_msg
),
375 safe_string(filter_msg
));
377 MSG("%s%s (type: tracepoint)%s%s%s",
380 enabled_string(event
->enabled
),
381 safe_string(exclusion_msg
),
382 safe_string(filter_msg
));
386 case LTTNG_EVENT_FUNCTION
:
387 MSG("%s%s (type: function)%s%s",
390 enabled_string(event
->enabled
),
391 safe_string(filter_msg
));
392 if (event
->attr
.probe
.addr
!= 0) {
393 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
395 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
396 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
399 case LTTNG_EVENT_PROBE
:
400 MSG("%s%s (type: probe)%s%s",
403 enabled_string(event
->enabled
),
404 safe_string(filter_msg
));
405 if (event
->attr
.probe
.addr
!= 0) {
406 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
408 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
409 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
412 case LTTNG_EVENT_USERSPACE_PROBE
:
413 print_userspace_probe_location(event
);
415 case LTTNG_EVENT_FUNCTION_ENTRY
:
416 MSG("%s%s (type: function)%s%s",
419 enabled_string(event
->enabled
),
420 safe_string(filter_msg
));
421 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
423 case LTTNG_EVENT_SYSCALL
:
427 (opt_syscall
? "" : " (type:syscall)"),
428 enabled_string(event
->enabled
),
429 bitness_event(event
->flags
),
430 safe_string(filter_msg
));
432 case LTTNG_EVENT_NOOP
:
433 MSG("%s (type: noop)%s%s",
435 enabled_string(event
->enabled
),
436 safe_string(filter_msg
));
438 case LTTNG_EVENT_ALL
:
441 /* We should never have "all" events in list. */
450 static const char *field_type(struct lttng_event_field
*field
)
452 switch (field
->type
) {
453 case LTTNG_EVENT_FIELD_INTEGER
:
455 case LTTNG_EVENT_FIELD_ENUM
:
457 case LTTNG_EVENT_FIELD_FLOAT
:
459 case LTTNG_EVENT_FIELD_STRING
:
461 case LTTNG_EVENT_FIELD_OTHER
:
462 default: /* fall-through */
468 * Pretty print single event fields.
470 static void print_event_field(struct lttng_event_field
*field
)
472 if (!field
->field_name
[0]) {
475 MSG("%sfield: %s (%s)%s",
479 field
->nowrite
? " [no write]" : "");
484 * Jul and ust event listing
487 mi_list_agent_ust_events(struct lttng_event
*events
, int count
, struct lttng_domain
*domain
)
491 char *cmdline
= NULL
;
492 int pid_element_open
= 0;
494 /* Open domains element */
495 ret
= mi_lttng_domains_open(the_writer
);
501 ret
= mi_lttng_domain(the_writer
, domain
, 1);
506 /* Open pids element element */
507 ret
= mi_lttng_pids_open(the_writer
);
512 for (i
= 0; i
< count
; i
++) {
513 if (cur_pid
!= events
[i
].pid
) {
514 if (pid_element_open
) {
515 /* Close the previous events and pid element */
516 ret
= mi_lttng_close_multi_element(the_writer
, 2);
520 pid_element_open
= 0;
523 cur_pid
= events
[i
].pid
;
524 cmdline
= get_cmdline_by_pid(cur_pid
);
530 if (!pid_element_open
) {
531 /* Open and write a pid element */
532 ret
= mi_lttng_pid(the_writer
, cur_pid
, cmdline
, 1);
537 /* Open events element */
538 ret
= mi_lttng_events_open(the_writer
);
543 pid_element_open
= 1;
549 ret
= mi_lttng_event(the_writer
, &events
[i
], 0, the_handle
->domain
.type
);
556 ret
= mi_lttng_writer_close_element(the_writer
);
561 /* Close domain, domains */
562 ret
= mi_lttng_close_multi_element(the_writer
, 2);
570 static int list_agent_events(void)
572 int i
, size
, ret
= CMD_SUCCESS
;
573 struct lttng_domain domain
;
574 struct lttng_handle
*handle
= NULL
;
575 struct lttng_event
*event_list
= NULL
;
577 char *cmdline
= NULL
;
578 const char *agent_domain_str
;
580 memset(&domain
, 0, sizeof(domain
));
582 domain
.type
= LTTNG_DOMAIN_JUL
;
583 } else if (opt_log4j
) {
584 domain
.type
= LTTNG_DOMAIN_LOG4J
;
585 } else if (opt_python
) {
586 domain
.type
= LTTNG_DOMAIN_PYTHON
;
588 ERR("Invalid agent domain selected.");
593 agent_domain_str
= lttng_domain_type_str(domain
.type
);
595 DBG("Getting %s tracing events", agent_domain_str
);
597 handle
= lttng_create_handle(NULL
, &domain
);
598 if (handle
== NULL
) {
603 size
= lttng_list_tracepoints(handle
, &event_list
);
605 ERR("Unable to list %s events: %s", agent_domain_str
, lttng_strerror(size
));
612 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
619 MSG("%s events (Logger name):\n-------------------------", agent_domain_str
);
625 for (i
= 0; i
< size
; i
++) {
626 if (cur_pid
!= event_list
[i
].pid
) {
627 cur_pid
= event_list
[i
].pid
;
628 cmdline
= get_cmdline_by_pid(cur_pid
);
629 if (cmdline
== NULL
) {
633 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
636 MSG("%s- %s", indent6
, event_list
[i
].name
);
645 lttng_destroy_handle(handle
);
650 * Ask session daemon for all user space tracepoints available.
652 static int list_ust_events(void)
654 int i
, size
, ret
= CMD_SUCCESS
;
655 struct lttng_domain domain
;
656 struct lttng_handle
*handle
;
657 struct lttng_event
*event_list
= NULL
;
659 char *cmdline
= NULL
;
661 memset(&domain
, 0, sizeof(domain
));
663 DBG("Getting UST tracing events");
665 domain
.type
= LTTNG_DOMAIN_UST
;
667 handle
= lttng_create_handle(NULL
, &domain
);
668 if (handle
== NULL
) {
673 size
= lttng_list_tracepoints(handle
, &event_list
);
675 ERR("Unable to list UST events: %s", lttng_strerror(size
));
682 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
685 MSG("UST events:\n-------------");
691 for (i
= 0; i
< size
; i
++) {
692 if (cur_pid
!= event_list
[i
].pid
) {
693 cur_pid
= event_list
[i
].pid
;
694 cmdline
= get_cmdline_by_pid(cur_pid
);
695 if (cmdline
== NULL
) {
699 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
702 print_events(&event_list
[i
]);
711 lttng_destroy_handle(handle
);
717 * List all ust event with their fields
720 mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
, struct lttng_domain
*domain
)
724 char *cmdline
= NULL
;
725 int pid_element_open
= 0;
726 int event_element_open
= 0;
727 struct lttng_event cur_event
;
729 memset(&cur_event
, 0, sizeof(cur_event
));
731 /* Open domains element */
732 ret
= mi_lttng_domains_open(the_writer
);
738 ret
= mi_lttng_domain(the_writer
, domain
, 1);
743 /* Open pids element */
744 ret
= mi_lttng_pids_open(the_writer
);
749 for (i
= 0; i
< count
; i
++) {
750 if (cur_pid
!= fields
[i
].event
.pid
) {
751 if (pid_element_open
) {
752 if (event_element_open
) {
753 /* Close the previous field element and event. */
754 ret
= mi_lttng_close_multi_element(the_writer
, 2);
758 event_element_open
= 0;
760 /* Close the previous events, pid element */
761 ret
= mi_lttng_close_multi_element(the_writer
, 2);
765 pid_element_open
= 0;
768 cur_pid
= fields
[i
].event
.pid
;
769 cmdline
= get_cmdline_by_pid(cur_pid
);
770 if (!pid_element_open
) {
771 /* Open and write a pid element */
772 ret
= mi_lttng_pid(the_writer
, cur_pid
, cmdline
, 1);
777 /* Open events element */
778 ret
= mi_lttng_events_open(the_writer
);
782 pid_element_open
= 1;
785 /* Wipe current event since we are about to print a new PID. */
786 memset(&cur_event
, 0, sizeof(cur_event
));
789 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
790 if (event_element_open
) {
791 /* Close the previous fields element and the previous event */
792 ret
= mi_lttng_close_multi_element(the_writer
, 2);
796 event_element_open
= 0;
799 memcpy(&cur_event
, &fields
[i
].event
, sizeof(cur_event
));
801 if (!event_element_open
) {
802 /* Open and write the event */
803 ret
= mi_lttng_event(
804 the_writer
, &cur_event
, 1, the_handle
->domain
.type
);
809 /* Open a fields element */
810 ret
= mi_lttng_event_fields_open(the_writer
);
814 event_element_open
= 1;
818 /* Print the event_field */
819 ret
= mi_lttng_event_field(the_writer
, &fields
[i
]);
825 /* Close pids, domain, domains */
826 ret
= mi_lttng_close_multi_element(the_writer
, 3);
835 * Ask session daemon for all user space tracepoint fields available.
837 static int list_ust_event_fields(void)
839 int i
, size
, ret
= CMD_SUCCESS
;
840 struct lttng_domain domain
;
841 struct lttng_handle
*handle
;
842 struct lttng_event_field
*event_field_list
;
844 char *cmdline
= NULL
;
846 struct lttng_event cur_event
;
848 memset(&domain
, 0, sizeof(domain
));
849 memset(&cur_event
, 0, sizeof(cur_event
));
851 DBG("Getting UST tracing event fields");
853 domain
.type
= LTTNG_DOMAIN_UST
;
855 handle
= lttng_create_handle(NULL
, &domain
);
856 if (handle
== NULL
) {
861 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
863 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
870 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
877 MSG("UST events:\n-------------");
883 for (i
= 0; i
< size
; i
++) {
884 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
885 cur_pid
= event_field_list
[i
].event
.pid
;
886 cmdline
= get_cmdline_by_pid(cur_pid
);
887 if (cmdline
== NULL
) {
891 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
893 /* Wipe current event since we are about to print a new PID. */
894 memset(&cur_event
, 0, sizeof(cur_event
));
896 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
897 print_events(&event_field_list
[i
].event
);
898 memcpy(&cur_event
, &event_field_list
[i
].event
, sizeof(cur_event
));
900 print_event_field(&event_field_list
[i
]);
907 free(event_field_list
);
909 lttng_destroy_handle(handle
);
915 * Print a list of kernel events
917 static int mi_list_kernel_events(struct lttng_event
*events
, int count
, struct lttng_domain
*domain
)
921 /* Open domains element */
922 ret
= mi_lttng_domains_open(the_writer
);
928 ret
= mi_lttng_domain(the_writer
, domain
, 1);
934 ret
= mi_lttng_events_open(the_writer
);
939 for (i
= 0; i
< count
; i
++) {
940 ret
= mi_lttng_event(the_writer
, &events
[i
], 0, the_handle
->domain
.type
);
946 /* close events, domain and domains */
947 ret
= mi_lttng_close_multi_element(the_writer
, 3);
957 * Ask for all trace events in the kernel
959 static int list_kernel_events(void)
961 int i
, size
, ret
= CMD_SUCCESS
;
962 struct lttng_domain domain
;
963 struct lttng_handle
*handle
;
964 struct lttng_event
*event_list
;
966 memset(&domain
, 0, sizeof(domain
));
968 DBG("Getting kernel tracing events");
970 domain
.type
= LTTNG_DOMAIN_KERNEL
;
972 handle
= lttng_create_handle(NULL
, &domain
);
973 if (handle
== NULL
) {
978 size
= lttng_list_tracepoints(handle
, &event_list
);
980 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
981 lttng_destroy_handle(handle
);
987 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
993 MSG("Kernel events:\n-------------");
995 for (i
= 0; i
< size
; i
++) {
996 print_events(&event_list
[i
]);
1005 lttng_destroy_handle(handle
);
1009 lttng_destroy_handle(handle
);
1015 * Print a list of system calls.
1017 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1022 ret
= mi_lttng_events_open(the_writer
);
1027 for (i
= 0; i
< count
; i
++) {
1028 ret
= mi_lttng_event(the_writer
, &events
[i
], 0, the_handle
->domain
.type
);
1035 ret
= mi_lttng_writer_close_element(the_writer
);
1045 * Ask for kernel system calls.
1047 static int list_syscalls(void)
1049 int i
, size
, ret
= CMD_SUCCESS
;
1050 struct lttng_event
*event_list
;
1052 DBG("Getting kernel system call events");
1054 size
= lttng_list_syscalls(&event_list
);
1056 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1063 ret
= mi_list_syscalls(event_list
, size
);
1069 MSG("System calls:\n-------------");
1071 for (i
= 0; i
< size
; i
++) {
1072 print_events(&event_list
[i
]);
1088 * Print a list of agent events
1090 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1094 /* Open events element */
1095 ret
= mi_lttng_events_open(the_writer
);
1100 for (i
= 0; i
< count
; i
++) {
1101 ret
= mi_lttng_event(the_writer
, &events
[i
], 0, the_handle
->domain
.type
);
1107 /* Close events element */
1108 ret
= mi_lttng_writer_close_element(the_writer
);
1115 * List agent events for a specific session using the handle.
1117 * Return CMD_SUCCESS on success else a negative value.
1119 static int list_session_agent_events(void)
1121 int ret
= CMD_SUCCESS
, count
, i
;
1122 struct lttng_event
*events
= NULL
;
1124 count
= lttng_list_events(the_handle
, "", &events
);
1127 ERR("%s", lttng_strerror(count
));
1133 ret
= mi_list_session_agent_events(events
, count
);
1140 MSG("Events (Logger name):\n---------------------");
1142 MSG("%sNone\n", indent6
);
1146 for (i
= 0; i
< count
; i
++) {
1147 const char *filter_str
;
1148 char *filter_msg
= NULL
;
1149 struct lttng_event
*event
= &events
[i
];
1151 ret
= lttng_event_get_filter_expression(event
, &filter_str
);
1153 filter_msg
= strdup(" [failed to retrieve filter]");
1154 } else if (filter_str
) {
1155 if (asprintf(&filter_msg
, " [filter: '%s']", filter_str
) == -1) {
1160 if (event
->loglevel_type
!= LTTNG_EVENT_LOGLEVEL_ALL
) {
1161 MSG("%s- %s%s (loglevel%s %s)%s",
1164 enabled_string(event
->enabled
),
1165 logleveltype_string(event
->loglevel_type
),
1166 mi_lttng_loglevel_string(event
->loglevel
,
1167 the_handle
->domain
.type
),
1168 safe_string(filter_msg
));
1173 enabled_string(event
->enabled
),
1174 safe_string(filter_msg
));
1190 * print a list of event
1192 static int mi_list_events(struct lttng_event
*events
, int count
)
1196 /* Open events element */
1197 ret
= mi_lttng_events_open(the_writer
);
1202 for (i
= 0; i
< count
; i
++) {
1203 ret
= mi_lttng_event(the_writer
, &events
[i
], 0, the_handle
->domain
.type
);
1209 /* Close events element */
1210 ret
= mi_lttng_writer_close_element(the_writer
);
1217 * List events of channel of session and domain.
1219 static int list_events(const char *channel_name
)
1221 int ret
= CMD_SUCCESS
, count
, i
;
1222 struct lttng_event
*events
= NULL
;
1224 count
= lttng_list_events(the_handle
, channel_name
, &events
);
1227 ERR("%s", lttng_strerror(count
));
1233 ret
= mi_list_events(events
, count
);
1240 MSG("\n%sRecording event rules:", indent4
);
1242 MSG("%sNone\n", indent6
);
1246 for (i
= 0; i
< count
; i
++) {
1247 print_events(&events
[i
]);
1258 static void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1262 _MSG("%s%s:", indent6
, timer_name
);
1263 for (i
= 0; i
< space_count
; i
++) {
1268 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1275 * Pretty print channel
1277 static void print_channel(struct lttng_channel
*channel
)
1280 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1281 int64_t blocking_timeout
;
1283 ret
= lttng_channel_get_discarded_event_count(channel
, &discarded_events
);
1285 ERR("Failed to retrieve discarded event count of channel");
1289 ret
= lttng_channel_get_lost_packet_count(channel
, &lost_packets
);
1291 ERR("Failed to retrieve lost packet count of channel");
1295 ret
= lttng_channel_get_monitor_timer_interval(channel
, &monitor_timer_interval
);
1297 ERR("Failed to retrieve monitor interval of channel");
1301 ret
= lttng_channel_get_blocking_timeout(channel
, &blocking_timeout
);
1303 ERR("Failed to retrieve blocking timeout of channel");
1307 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1308 MSG("%sAttributes:", indent4
);
1309 MSG("%sEvent-loss mode: %s", indent6
, channel
->attr
.overwrite
? "overwrite" : "discard");
1310 MSG("%sSub-buffer size: %" PRIu64
" bytes", indent6
, channel
->attr
.subbuf_size
);
1311 MSG("%sSub-buffer count: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1313 print_timer("Switch timer", 5, channel
->attr
.switch_timer_interval
);
1314 print_timer("Read timer", 7, channel
->attr
.read_timer_interval
);
1315 print_timer("Monitor timer", 4, monitor_timer_interval
);
1317 if (!channel
->attr
.overwrite
) {
1318 if (blocking_timeout
== -1) {
1319 MSG("%sBlocking timeout: infinite", indent6
);
1321 MSG("%sBlocking timeout: %" PRId64
" %s",
1328 MSG("%sTrace file count: %" PRIu64
" per stream",
1330 channel
->attr
.tracefile_count
== 0 ? 1 : channel
->attr
.tracefile_count
);
1331 if (channel
->attr
.tracefile_size
!= 0) {
1332 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
, 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
, const char *channel_name
)
1381 unsigned int chan_found
= 0;
1383 /* Open channels element */
1384 ret
= mi_lttng_channels_open(the_writer
);
1389 for (i
= 0; i
< count
; i
++) {
1390 if (channel_name
!= NULL
) {
1391 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1398 /* Write channel element and leave it open */
1399 ret
= mi_lttng_channel(the_writer
, &channels
[i
], 1);
1404 /* Listing events per channel */
1405 ret
= list_events(channels
[i
].name
);
1410 /* Closing the channel element we opened earlier */
1411 ret
= mi_lttng_writer_close_element(the_writer
);
1421 /* Close channels element */
1422 ret
= mi_lttng_writer_close_element(the_writer
);
1432 * List channel(s) of session and domain.
1434 * If channel_name is NULL, all channels are listed.
1436 static int list_channels(const char *channel_name
)
1438 int count
, i
, ret
= CMD_SUCCESS
;
1439 unsigned int chan_found
= 0;
1440 struct lttng_channel
*channels
= NULL
;
1442 DBG("Listing channel(s) (%s)", channel_name
?: "<all>");
1444 count
= lttng_list_channels(the_handle
, &channels
);
1447 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1449 /* When printing mi this is not an error
1450 * but an empty channels element */
1454 goto error_channels
;
1458 /* We had a real error */
1460 ERR("%s", lttng_strerror(count
));
1461 goto error_channels
;
1468 ret
= mi_list_channels(channels
, count
, channel_name
);
1476 MSG("Channels:\n-------------");
1479 for (i
= 0; i
< count
; i
++) {
1480 if (channel_name
!= NULL
) {
1481 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1487 print_channel(&channels
[i
]);
1489 /* Listing events per channel */
1490 ret
= list_events(channels
[i
].name
);
1500 if (!chan_found
&& channel_name
!= NULL
) {
1502 ERR("Channel %s not found", channel_name
);
1513 static const char *get_capitalized_process_attr_str(enum lttng_process_attr process_attr
)
1515 switch (process_attr
) {
1516 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1517 return "Process ID";
1518 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1519 return "Virtual process ID";
1520 case LTTNG_PROCESS_ATTR_USER_ID
:
1522 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1523 return "Virtual user ID";
1524 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1526 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1527 return "Virtual group ID";
1534 static int handle_process_attr_status(enum lttng_process_attr process_attr
,
1535 enum lttng_process_attr_tracker_handle_status status
)
1537 int ret
= CMD_SUCCESS
;
1540 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID_TRACKING_POLICY
:
1541 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
1544 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
1545 ERR("Communication occurred while fetching %s tracker",
1546 lttng_process_attr_to_string(process_attr
));
1549 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_SESSION_DOES_NOT_EXIST
:
1550 ERR("Failed to get the inclusion set of the %s tracker: session `%s` no longer exists",
1551 lttng_process_attr_to_string(process_attr
),
1552 the_handle
->session_name
);
1556 ERR("Unknown error occurred while fetching the inclusion set of the %s tracker",
1557 lttng_process_attr_to_string(process_attr
));
1565 static int mi_output_empty_tracker(enum lttng_process_attr process_attr
)
1569 ret
= mi_lttng_process_attribute_tracker_open(the_writer
, process_attr
);
1574 ret
= mi_lttng_close_multi_element(the_writer
, 2);
1579 static inline bool is_value_type_name(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(
1600 the_handle
->session_name
, the_handle
->domain
.type
, process_attr
, &tracker_handle
);
1601 if (ret_code
!= LTTNG_OK
) {
1602 ERR("Failed to get process attribute tracker handle: %s", lttng_strerror(ret_code
));
1608 lttng_process_attr_tracker_handle_get_inclusion_set(tracker_handle
, &values
);
1609 ret
= handle_process_attr_status(process_attr
, handle_status
);
1610 if (ret
!= CMD_SUCCESS
) {
1615 lttng_process_attr_tracker_handle_get_tracking_policy(tracker_handle
, &policy
);
1616 ret
= handle_process_attr_status(process_attr
, handle_status
);
1617 if (ret
!= CMD_SUCCESS
) {
1622 char *process_attr_name
;
1623 const int print_ret
= asprintf(
1624 &process_attr_name
, "%ss:", get_capitalized_process_attr_str(process_attr
));
1626 if (print_ret
== -1) {
1630 _MSG(" %-22s", process_attr_name
);
1631 free(process_attr_name
);
1634 case LTTNG_TRACKING_POLICY_INCLUDE_SET
:
1636 case LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
1638 mi_output_empty_tracker(process_attr
);
1643 case LTTNG_TRACKING_POLICY_INCLUDE_ALL
:
1648 ERR("Unknown tracking policy encoutered while listing the %s process attribute tracker of session `%s`",
1649 lttng_process_attr_to_string(process_attr
),
1650 the_handle
->session_name
);
1655 values_status
= lttng_process_attr_values_get_count(values
, &count
);
1656 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1657 ERR("Failed to get the count of values in the inclusion set of the %s process attribute tracker of session `%s`",
1658 lttng_process_attr_to_string(process_attr
),
1659 the_handle
->session_name
);
1665 /* Functionally equivalent to the 'exclude all' policy. */
1667 mi_output_empty_tracker(process_attr
);
1674 /* Mi tracker_id element */
1676 /* Open tracker_id and targets elements */
1677 ret
= mi_lttng_process_attribute_tracker_open(the_writer
, process_attr
);
1683 for (i
= 0; i
< count
; i
++) {
1684 const enum lttng_process_attr_value_type value_type
=
1685 lttng_process_attr_values_get_type_at_index(values
, i
);
1686 int64_t integral_value
= INT64_MAX
;
1687 const char *name
= "error";
1692 switch (value_type
) {
1693 case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID
:
1697 values_status
= lttng_process_attr_values_get_pid_at_index(values
, i
, &pid
);
1698 integral_value
= (int64_t) pid
;
1701 case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID
:
1705 values_status
= lttng_process_attr_values_get_uid_at_index(values
, i
, &uid
);
1706 integral_value
= (int64_t) uid
;
1709 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID
:
1713 values_status
= lttng_process_attr_values_get_gid_at_index(values
, i
, &gid
);
1714 integral_value
= (int64_t) gid
;
1717 case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
:
1719 lttng_process_attr_values_get_user_name_at_index(values
, i
, &name
);
1721 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
:
1723 lttng_process_attr_values_get_group_name_at_index(values
, i
, &name
);
1730 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1732 * Not possible given the current liblttng-ctl
1735 ERR("Unknown error occurred while fetching process attribute value in inclusion list");
1740 if (is_value_type_name(value_type
)) {
1743 _MSG("%" PRIi64
, integral_value
);
1748 ret
= is_value_type_name(value_type
) ?
1749 mi_lttng_string_process_attribute_value(
1750 the_writer
, process_attr
, name
, false) :
1751 mi_lttng_integral_process_attribute_value(
1752 the_writer
, process_attr
, integral_value
, false);
1760 /* Mi close tracker_id and targets */
1762 ret
= mi_lttng_close_multi_element(the_writer
, 2);
1768 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
1773 * List all trackers of a domain
1775 static int list_trackers(const struct lttng_domain
*domain
)
1779 MSG("Tracked process attributes");
1780 /* Trackers listing */
1782 ret
= mi_lttng_trackers_open(the_writer
);
1788 switch (domain
->type
) {
1789 case LTTNG_DOMAIN_KERNEL
:
1791 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_PROCESS_ID
);
1796 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1801 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_USER_ID
);
1806 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1811 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_GROUP_ID
);
1816 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1821 case LTTNG_DOMAIN_UST
:
1823 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1828 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1833 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1843 /* Close trackers element */
1844 ret
= mi_lttng_writer_close_element(the_writer
);
1854 static enum cmd_error_code
1855 print_periodic_rotation_schedule(const struct lttng_rotation_schedule
*schedule
)
1857 enum cmd_error_code ret
;
1858 enum lttng_rotation_status status
;
1861 status
= lttng_rotation_schedule_periodic_get_period(schedule
, &value
);
1862 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1863 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1868 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
1874 static enum cmd_error_code
1875 print_size_threshold_rotation_schedule(const struct lttng_rotation_schedule
*schedule
)
1877 enum cmd_error_code ret
;
1878 enum lttng_rotation_status status
;
1881 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
, &value
);
1882 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1883 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1888 MSG(" size threshold: %" PRIu64
" bytes", value
);
1894 static enum cmd_error_code
print_rotation_schedule(const struct lttng_rotation_schedule
*schedule
)
1896 enum cmd_error_code ret
;
1898 switch (lttng_rotation_schedule_get_type(schedule
)) {
1899 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1900 ret
= print_size_threshold_rotation_schedule(schedule
);
1902 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1903 ret
= print_periodic_rotation_schedule(schedule
);
1912 * List the automatic rotation settings.
1914 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1917 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1918 unsigned int count
, i
;
1919 struct lttng_rotation_schedules
*schedules
= NULL
;
1920 enum lttng_rotation_status status
;
1922 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1923 if (ret
!= LTTNG_OK
) {
1924 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1925 cmd_ret
= CMD_ERROR
;
1929 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1930 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1931 ERR("Failed to retrieve the number of session rotation schedules.");
1932 cmd_ret
= CMD_ERROR
;
1937 cmd_ret
= CMD_SUCCESS
;
1941 MSG("Automatic rotation schedules:");
1943 ret
= mi_lttng_writer_open_element(the_writer
, mi_lttng_element_rotation_schedules
);
1945 cmd_ret
= CMD_ERROR
;
1950 for (i
= 0; i
< count
; i
++) {
1951 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1952 const struct lttng_rotation_schedule
*schedule
;
1954 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1956 ERR("Failed to retrieve session rotation schedule.");
1957 cmd_ret
= CMD_ERROR
;
1962 ret
= mi_lttng_rotation_schedule(the_writer
, schedule
);
1964 tmp_ret
= CMD_ERROR
;
1967 tmp_ret
= print_rotation_schedule(schedule
);
1971 * Report an error if the serialization of any of the
1972 * descriptors failed.
1974 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
1979 /* Close the rotation_schedules element. */
1980 ret
= mi_lttng_writer_close_element(the_writer
);
1982 cmd_ret
= CMD_ERROR
;
1987 lttng_rotation_schedules_destroy(schedules
);
1993 * Find the session with session_name as name
1994 * and print his informations.
1996 static int mi_list_session(const char *session_name
, struct lttng_session
*sessions
, int count
)
1999 unsigned int session_found
= 0;
2001 if (session_name
== NULL
) {
2002 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2006 for (i
= 0; i
< count
; i
++) {
2007 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2008 /* We need to leave it open to append other informations
2009 * like domain, channel, events etc.*/
2011 ret
= mi_lttng_session(the_writer
, &sessions
[i
], 1);
2019 if (!session_found
) {
2020 ERR("Session '%s' not found", session_name
);
2021 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2031 * List all availables session
2033 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
2037 /* Opening sessions element */
2038 ret
= mi_lttng_sessions_open(the_writer
);
2043 /* Listing sessions */
2044 for (i
= 0; i
< count
; i
++) {
2045 ret
= mi_lttng_session(the_writer
, &sessions
[i
], 0);
2051 /* Closing sessions element */
2052 ret
= mi_lttng_writer_close_element(the_writer
);
2062 * List available tracing session. List only basic information.
2064 * If session_name is NULL, all sessions are listed.
2066 static int list_sessions(const char *session_name
)
2068 int ret
= CMD_SUCCESS
;
2070 unsigned int session_found
= 0;
2071 struct lttng_session
*sessions
= NULL
;
2073 count
= lttng_list_sessions(&sessions
);
2074 DBG("Session count %d", count
);
2077 ERR("%s", lttng_strerror(count
));
2083 if (session_name
== NULL
) {
2084 /* List all sessions */
2085 ret
= mi_list_sessions(sessions
, count
);
2087 /* Note : this return an open session element */
2088 ret
= mi_list_session(session_name
, sessions
, count
);
2097 MSG("Currently no available recording session");
2101 if (session_name
== NULL
) {
2102 MSG("Available recording sessions:");
2105 for (i
= 0; i
< count
; i
++) {
2106 if (session_name
!= NULL
) {
2107 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2109 MSG("Recording session %s: [%s%s]",
2111 active_string(sessions
[i
].enabled
),
2112 snapshot_string(sessions
[i
].snapshot_mode
));
2113 if (*sessions
[i
].path
) {
2114 MSG("%sTrace output: %s\n",
2118 memcpy(&the_listed_session
,
2120 sizeof(the_listed_session
));
2124 MSG(" %d) %s [%s%s]",
2127 active_string(sessions
[i
].enabled
),
2128 snapshot_string(sessions
[i
].snapshot_mode
));
2129 if (*sessions
[i
].path
) {
2130 MSG("%sTrace output: %s", indent4
, sessions
[i
].path
);
2132 if (sessions
[i
].live_timer_interval
!= 0) {
2133 MSG("%sLive timer interval: %u %s",
2135 sessions
[i
].live_timer_interval
,
2142 if (!session_found
&& session_name
!= NULL
) {
2143 ERR("Session '%s' not found", session_name
);
2148 if (session_name
== NULL
) {
2149 MSG("\nUse lttng list <session_name> for more details");
2160 * list available domain(s) for a session.
2162 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
2165 /* Open domains element */
2166 ret
= mi_lttng_domains_open(the_writer
);
2171 for (i
= 0; i
< count
; i
++) {
2172 ret
= mi_lttng_domain(the_writer
, &domains
[i
], 0);
2178 /* Closing domains element */
2179 ret
= mi_lttng_writer_close_element(the_writer
);
2188 * List available domain(s) for a session.
2190 static int list_domains(const char *session_name
)
2192 int i
, count
, ret
= CMD_SUCCESS
;
2193 struct lttng_domain
*domains
= NULL
;
2195 count
= lttng_list_domains(session_name
, &domains
);
2198 ERR("%s", lttng_strerror(count
));
2204 ret
= mi_list_domains(domains
, count
);
2211 MSG("Domains:\n-------------");
2217 for (i
= 0; i
< count
; i
++) {
2218 switch (domains
[i
].type
) {
2219 case LTTNG_DOMAIN_KERNEL
:
2222 case LTTNG_DOMAIN_UST
:
2223 MSG(" - UST global");
2225 case LTTNG_DOMAIN_JUL
:
2226 MSG(" - JUL (Java Util Logging)");
2228 case LTTNG_DOMAIN_LOG4J
:
2229 MSG(" - LOG4j (Logging for Java)");
2231 case LTTNG_DOMAIN_PYTHON
:
2232 MSG(" - Python (logging)");
2248 * The 'list <options>' first level command
2250 int cmd_list(int argc
, const char **argv
)
2252 int opt
, ret
= CMD_SUCCESS
;
2253 const char *arg_session_name
, *leftover
= NULL
;
2254 static poptContext pc
;
2255 struct lttng_domain domain
;
2256 struct lttng_domain
*domains
= NULL
;
2258 memset(&domain
, 0, sizeof(domain
));
2265 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2266 poptReadDefaultConfig(pc
, 0);
2268 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2276 case OPT_LIST_OPTIONS
:
2277 list_cmd_options(stdout
, long_options
);
2280 ret
= CMD_UNDEFINED
;
2287 the_writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
2293 /* Open command element */
2294 ret
= mi_lttng_writer_command_open(the_writer
, mi_lttng_element_command_list
);
2300 /* Open output element */
2301 ret
= mi_lttng_writer_open_element(the_writer
, mi_lttng_element_command_output
);
2308 /* Get session name (trailing argument) */
2309 arg_session_name
= poptGetArg(pc
);
2310 DBG2("Session name: %s", arg_session_name
);
2312 leftover
= poptGetArg(pc
);
2314 ERR("Unknown argument: %s", leftover
);
2320 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2321 } else if (opt_userspace
) {
2322 DBG2("Listing userspace global domain");
2323 domain
.type
= LTTNG_DOMAIN_UST
;
2324 } else if (opt_jul
) {
2325 DBG2("Listing JUL domain");
2326 domain
.type
= LTTNG_DOMAIN_JUL
;
2327 } else if (opt_log4j
) {
2328 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2329 } else if (opt_python
) {
2330 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2333 if (!opt_kernel
&& opt_syscall
) {
2334 WARN("--syscall will only work with the Kernel domain (-k)");
2339 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2340 the_handle
= lttng_create_handle(arg_session_name
, &domain
);
2341 if (the_handle
== NULL
) {
2347 if (arg_session_name
== NULL
) {
2348 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
&& !opt_python
) {
2349 ret
= list_sessions(NULL
);
2356 ret
= list_syscalls();
2361 ret
= list_kernel_events();
2367 if (opt_userspace
) {
2369 ret
= list_ust_event_fields();
2371 ret
= list_ust_events();
2377 if (opt_jul
|| opt_log4j
|| opt_python
) {
2378 ret
= list_agent_events();
2384 /* List session attributes */
2386 /* Open element sessions
2387 * Present for xml consistency */
2388 ret
= mi_lttng_sessions_open(the_writer
);
2393 /* MI: the ouptut of list_sessions is an unclosed session element */
2394 ret
= list_sessions(arg_session_name
);
2399 ret
= list_rotate_settings(arg_session_name
);
2404 /* Domain listing */
2406 ret
= list_domains(arg_session_name
);
2410 /* Channel listing */
2411 if (opt_kernel
|| opt_userspace
) {
2413 /* Add of domains and domain element for xml
2414 * consistency and validation
2416 ret
= mi_lttng_domains_open(the_writer
);
2421 /* Open domain and leave it open for
2422 * nested channels printing */
2423 ret
= mi_lttng_domain(the_writer
, &domain
, 1);
2430 ret
= list_trackers(&domain
);
2436 ret
= list_channels(opt_channel
);
2442 /* Close domain and domain element */
2443 ret
= mi_lttng_close_multi_element(the_writer
, 2);
2452 /* We want all domain(s) */
2453 nb_domain
= lttng_list_domains(arg_session_name
, &domains
);
2454 if (nb_domain
< 0) {
2456 ERR("%s", lttng_strerror(nb_domain
));
2461 ret
= mi_lttng_domains_open(the_writer
);
2468 for (i
= 0; i
< nb_domain
; i
++) {
2469 switch (domains
[i
].type
) {
2470 case LTTNG_DOMAIN_KERNEL
:
2471 MSG("=== Domain: Linux kernel ===\n");
2473 case LTTNG_DOMAIN_UST
:
2474 MSG("=== Domain: User space ===\n");
2475 MSG("Buffering scheme: %s\n",
2476 domains
[i
].buf_type
== LTTNG_BUFFER_PER_PID
?
2480 case LTTNG_DOMAIN_JUL
:
2481 MSG("=== Domain: java.util.logging (JUL) ===\n");
2483 case LTTNG_DOMAIN_LOG4J
:
2484 MSG("=== Domain: log4j ===\n");
2486 case LTTNG_DOMAIN_PYTHON
:
2487 MSG("=== Domain: Python logging ===\n");
2490 MSG("=== Domain: Unimplemented ===\n");
2495 ret
= mi_lttng_domain(the_writer
, &domains
[i
], 1);
2502 /* Clean handle before creating a new one */
2504 lttng_destroy_handle(the_handle
);
2507 the_handle
= lttng_create_handle(arg_session_name
, &domains
[i
]);
2508 if (the_handle
== NULL
) {
2513 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2514 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2515 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2516 ret
= list_session_agent_events();
2524 switch (domains
[i
].type
) {
2525 case LTTNG_DOMAIN_KERNEL
:
2526 case LTTNG_DOMAIN_UST
:
2527 ret
= list_trackers(&domains
[i
]);
2536 ret
= list_channels(opt_channel
);
2543 /* Close domain element */
2544 ret
= mi_lttng_writer_close_element(the_writer
);
2552 /* Close the domains, session and sessions element */
2553 ret
= mi_lttng_close_multi_element(the_writer
, 3);
2564 /* Close output element */
2565 ret
= mi_lttng_writer_close_element(the_writer
);
2571 /* Command element close */
2572 ret
= mi_lttng_writer_command_close(the_writer
);
2580 if (the_writer
&& mi_lttng_writer_destroy(the_writer
)) {
2581 /* Preserve original error code */
2582 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2587 lttng_destroy_handle(the_handle
);
2590 poptFreeContext(pc
);