2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
18 #include <common/mi-lttng.h>
19 #include <common/time.h>
20 #include <common/tracker.h>
21 #include <lttng/lttng.h>
23 #include "../command.h"
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
*handle
;
52 static struct mi_writer
*writer
;
54 /* Only set when listing a single session. */
55 static struct lttng_session 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
= 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
= 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 const char * const filter_fmt
= " [filter: '%s']";
343 filter_msg
= malloc(strlen(filter_str
) +
344 strlen(filter_fmt
) + 1);
346 sprintf(filter_msg
, filter_fmt
,
351 exclusion_msg
= get_exclusion_names_msg(event
);
352 if (!exclusion_msg
) {
353 exclusion_msg
= strdup(" [failed to retrieve exclusions]");
356 switch (event
->type
) {
357 case LTTNG_EVENT_TRACEPOINT
:
359 if (event
->loglevel
!= -1) {
360 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
363 logleveltype_string(event
->loglevel_type
),
364 mi_lttng_loglevel_string(event
->loglevel
, handle
->domain
.type
),
366 enabled_string(event
->enabled
),
367 safe_string(exclusion_msg
),
368 safe_string(filter_msg
));
370 MSG("%s%s (type: tracepoint)%s%s%s",
373 enabled_string(event
->enabled
),
374 safe_string(exclusion_msg
),
375 safe_string(filter_msg
));
379 case LTTNG_EVENT_FUNCTION
:
380 MSG("%s%s (type: function)%s%s", indent6
,
381 event
->name
, enabled_string(event
->enabled
),
382 safe_string(filter_msg
));
383 if (event
->attr
.probe
.addr
!= 0) {
384 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
386 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
387 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
390 case LTTNG_EVENT_PROBE
:
391 MSG("%s%s (type: probe)%s%s", indent6
,
392 event
->name
, enabled_string(event
->enabled
),
393 safe_string(filter_msg
));
394 if (event
->attr
.probe
.addr
!= 0) {
395 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
397 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
398 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
401 case LTTNG_EVENT_USERSPACE_PROBE
:
402 print_userspace_probe_location(event
);
404 case LTTNG_EVENT_FUNCTION_ENTRY
:
405 MSG("%s%s (type: function)%s%s", indent6
,
406 event
->name
, enabled_string(event
->enabled
),
407 safe_string(filter_msg
));
408 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
410 case LTTNG_EVENT_SYSCALL
:
411 MSG("%s%s%s%s%s%s", indent6
, event
->name
,
412 (opt_syscall
? "" : " (type:syscall)"),
413 enabled_string(event
->enabled
),
414 bitness_event(event
->flags
),
415 safe_string(filter_msg
));
417 case LTTNG_EVENT_NOOP
:
418 MSG("%s (type: noop)%s%s", indent6
,
419 enabled_string(event
->enabled
),
420 safe_string(filter_msg
));
422 case LTTNG_EVENT_ALL
:
425 /* We should never have "all" events in list. */
434 static const char *field_type(struct lttng_event_field
*field
)
436 switch(field
->type
) {
437 case LTTNG_EVENT_FIELD_INTEGER
:
439 case LTTNG_EVENT_FIELD_ENUM
:
441 case LTTNG_EVENT_FIELD_FLOAT
:
443 case LTTNG_EVENT_FIELD_STRING
:
445 case LTTNG_EVENT_FIELD_OTHER
:
446 default: /* fall-through */
452 * Pretty print single event fields.
454 static void print_event_field(struct lttng_event_field
*field
)
456 if (!field
->field_name
[0]) {
459 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
460 field_type(field
), field
->nowrite
? " [no write]" : "");
465 * Jul and ust event listing
467 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
468 struct lttng_domain
*domain
)
472 char *cmdline
= NULL
;
473 int pid_element_open
= 0;
475 /* Open domains element */
476 ret
= mi_lttng_domains_open(writer
);
482 ret
= mi_lttng_domain(writer
, domain
, 1);
487 /* Open pids element element */
488 ret
= mi_lttng_pids_open(writer
);
493 for (i
= 0; i
< count
; i
++) {
494 if (cur_pid
!= events
[i
].pid
) {
495 if (pid_element_open
) {
496 /* Close the previous events and pid element */
497 ret
= mi_lttng_close_multi_element(writer
, 2);
501 pid_element_open
= 0;
504 cur_pid
= events
[i
].pid
;
505 cmdline
= get_cmdline_by_pid(cur_pid
);
511 if (!pid_element_open
) {
512 /* Open and write a pid element */
513 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
518 /* Open events element */
519 ret
= mi_lttng_events_open(writer
);
524 pid_element_open
= 1;
530 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
537 ret
= mi_lttng_writer_close_element(writer
);
542 /* Close domain, domains */
543 ret
= mi_lttng_close_multi_element(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
= get_domain_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(writer
);
721 ret
= mi_lttng_domain(writer
, domain
, 1);
726 /* Open pids element */
727 ret
= mi_lttng_pids_open(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(writer
, 2);
741 event_element_open
= 0;
743 /* Close the previous events, pid element */
744 ret
= mi_lttng_close_multi_element(writer
, 2);
748 pid_element_open
= 0;
751 cur_pid
= fields
[i
].event
.pid
;
752 cmdline
= get_cmdline_by_pid(cur_pid
);
753 if (!pid_element_open
) {
754 /* Open and write a pid element */
755 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
760 /* Open events element */
761 ret
= mi_lttng_events_open(writer
);
765 pid_element_open
= 1;
768 /* Wipe current event since we are about to print a new PID. */
769 memset(&cur_event
, 0, sizeof(cur_event
));
772 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
773 if (event_element_open
) {
774 /* Close the previous fields element and the previous event */
775 ret
= mi_lttng_close_multi_element(writer
, 2);
779 event_element_open
= 0;
782 memcpy(&cur_event
, &fields
[i
].event
,
785 if (!event_element_open
) {
786 /* Open and write the event */
787 ret
= mi_lttng_event(writer
, &cur_event
, 1,
788 handle
->domain
.type
);
793 /* Open a fields element */
794 ret
= mi_lttng_event_fields_open(writer
);
798 event_element_open
= 1;
802 /* Print the event_field */
803 ret
= mi_lttng_event_field(writer
, &fields
[i
]);
809 /* Close pids, domain, domains */
810 ret
= mi_lttng_close_multi_element(writer
, 3);
819 * Ask session daemon for all user space tracepoint fields available.
821 static int list_ust_event_fields(void)
823 int i
, size
, ret
= CMD_SUCCESS
;
824 struct lttng_domain domain
;
825 struct lttng_handle
*handle
;
826 struct lttng_event_field
*event_field_list
;
828 char *cmdline
= NULL
;
830 struct lttng_event cur_event
;
832 memset(&domain
, 0, sizeof(domain
));
833 memset(&cur_event
, 0, sizeof(cur_event
));
835 DBG("Getting UST tracing event fields");
837 domain
.type
= LTTNG_DOMAIN_UST
;
839 handle
= lttng_create_handle(NULL
, &domain
);
840 if (handle
== NULL
) {
845 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
847 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
854 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
861 MSG("UST events:\n-------------");
867 for (i
= 0; i
< size
; i
++) {
868 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
869 cur_pid
= event_field_list
[i
].event
.pid
;
870 cmdline
= get_cmdline_by_pid(cur_pid
);
871 if (cmdline
== NULL
) {
875 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
877 /* Wipe current event since we are about to print a new PID. */
878 memset(&cur_event
, 0, sizeof(cur_event
));
880 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
881 print_events(&event_field_list
[i
].event
);
882 memcpy(&cur_event
, &event_field_list
[i
].event
,
885 print_event_field(&event_field_list
[i
]);
892 free(event_field_list
);
894 lttng_destroy_handle(handle
);
900 * Print a list of kernel events
902 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
903 struct lttng_domain
*domain
)
907 /* Open domains element */
908 ret
= mi_lttng_domains_open(writer
);
914 ret
= mi_lttng_domain(writer
, domain
, 1);
920 ret
= mi_lttng_events_open(writer
);
925 for (i
= 0; i
< count
; i
++) {
926 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
932 /* close events, domain and domains */
933 ret
= mi_lttng_close_multi_element(writer
, 3);
943 * Ask for all trace events in the kernel
945 static int list_kernel_events(void)
947 int i
, size
, ret
= CMD_SUCCESS
;
948 struct lttng_domain domain
;
949 struct lttng_handle
*handle
;
950 struct lttng_event
*event_list
;
952 memset(&domain
, 0, sizeof(domain
));
954 DBG("Getting kernel tracing events");
956 domain
.type
= LTTNG_DOMAIN_KERNEL
;
958 handle
= lttng_create_handle(NULL
, &domain
);
959 if (handle
== NULL
) {
964 size
= lttng_list_tracepoints(handle
, &event_list
);
966 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
967 lttng_destroy_handle(handle
);
973 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
979 MSG("Kernel events:\n-------------");
981 for (i
= 0; i
< size
; i
++) {
982 print_events(&event_list
[i
]);
991 lttng_destroy_handle(handle
);
995 lttng_destroy_handle(handle
);
1001 * Print a list of system calls.
1003 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1008 ret
= mi_lttng_events_open(writer
);
1013 for (i
= 0; i
< count
; i
++) {
1014 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1021 ret
= mi_lttng_writer_close_element(writer
);
1031 * Ask for kernel system calls.
1033 static int list_syscalls(void)
1035 int i
, size
, ret
= CMD_SUCCESS
;
1036 struct lttng_event
*event_list
;
1038 DBG("Getting kernel system call events");
1040 size
= lttng_list_syscalls(&event_list
);
1042 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1049 ret
= mi_list_syscalls(event_list
, size
);
1055 MSG("System calls:\n-------------");
1057 for (i
= 0; i
< size
; i
++) {
1058 print_events(&event_list
[i
]);
1074 * Print a list of agent events
1076 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1080 /* Open events element */
1081 ret
= mi_lttng_events_open(writer
);
1086 for (i
= 0; i
< count
; i
++) {
1087 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1093 /* Close events element */
1094 ret
= mi_lttng_writer_close_element(writer
);
1101 * List agent events for a specific session using the handle.
1103 * Return CMD_SUCCESS on success else a negative value.
1105 static int list_session_agent_events(void)
1107 int ret
= CMD_SUCCESS
, count
, i
;
1108 struct lttng_event
*events
= NULL
;
1110 count
= lttng_list_events(handle
, "", &events
);
1113 ERR("%s", lttng_strerror(count
));
1119 ret
= mi_list_session_agent_events(events
, count
);
1126 MSG("Events (Logger name):\n---------------------");
1128 MSG("%sNone\n", indent6
);
1132 for (i
= 0; i
< count
; i
++) {
1133 const char *filter_str
;
1134 char *filter_msg
= NULL
;
1135 struct lttng_event
*event
= &events
[i
];
1137 ret
= lttng_event_get_filter_expression(event
,
1140 filter_msg
= strdup(" [failed to retrieve filter]");
1141 } else if (filter_str
) {
1142 const char * const filter_fmt
=
1145 filter_msg
= malloc(strlen(filter_str
) +
1146 strlen(filter_fmt
) + 1);
1148 sprintf(filter_msg
, filter_fmt
,
1153 if (event
->loglevel_type
!=
1154 LTTNG_EVENT_LOGLEVEL_ALL
) {
1155 MSG("%s- %s%s (loglevel%s %s)%s", indent4
,
1157 enabled_string(event
->enabled
),
1158 logleveltype_string(
1159 event
->loglevel_type
),
1160 mi_lttng_loglevel_string(
1162 handle
->domain
.type
),
1163 safe_string(filter_msg
));
1165 MSG("%s- %s%s%s", indent4
, event
->name
,
1166 enabled_string(event
->enabled
),
1167 safe_string(filter_msg
));
1183 * print a list of event
1185 static int mi_list_events(struct lttng_event
*events
, int count
)
1189 /* Open events element */
1190 ret
= mi_lttng_events_open(writer
);
1195 for (i
= 0; i
< count
; i
++) {
1196 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1202 /* Close events element */
1203 ret
= mi_lttng_writer_close_element(writer
);
1210 * List events of channel of session and domain.
1212 static int list_events(const char *channel_name
)
1214 int ret
= CMD_SUCCESS
, count
, i
;
1215 struct lttng_event
*events
= NULL
;
1217 count
= lttng_list_events(handle
, channel_name
, &events
);
1220 ERR("%s", lttng_strerror(count
));
1226 ret
= mi_list_events(events
, count
);
1233 MSG("\n%sEvent rules:", indent4
);
1235 MSG("%sNone\n", indent6
);
1239 for (i
= 0; i
< count
; i
++) {
1240 print_events(&events
[i
]);
1252 void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1256 _MSG("%s%s:", indent6
, timer_name
);
1257 for (i
= 0; i
< space_count
; i
++) {
1262 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1269 * Pretty print channel
1271 static void print_channel(struct lttng_channel
*channel
)
1274 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1275 int64_t blocking_timeout
;
1277 ret
= lttng_channel_get_discarded_event_count(channel
,
1280 ERR("Failed to retrieve discarded event count of channel");
1284 ret
= lttng_channel_get_lost_packet_count(channel
,
1287 ERR("Failed to retrieve lost packet count of channel");
1291 ret
= lttng_channel_get_monitor_timer_interval(channel
,
1292 &monitor_timer_interval
);
1294 ERR("Failed to retrieve monitor interval of channel");
1298 ret
= lttng_channel_get_blocking_timeout(channel
,
1301 ERR("Failed to retrieve blocking timeout of channel");
1305 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1306 MSG("%sAttributes:", indent4
);
1307 MSG("%sEvent-loss mode: %s", indent6
, channel
->attr
.overwrite
? "overwrite" : "discard");
1308 MSG("%sSub-buffer size: %" PRIu64
" bytes", indent6
, channel
->attr
.subbuf_size
);
1309 MSG("%sSub-buffer count: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1311 print_timer("Switch timer", 5, channel
->attr
.switch_timer_interval
);
1312 print_timer("Read timer", 7, channel
->attr
.read_timer_interval
);
1313 print_timer("Monitor timer", 4, monitor_timer_interval
);
1315 if (!channel
->attr
.overwrite
) {
1316 if (blocking_timeout
== -1) {
1317 MSG("%sBlocking timeout: infinite", indent6
);
1319 MSG("%sBlocking timeout: %" PRId64
" %s", indent6
,
1320 blocking_timeout
, USEC_UNIT
);
1324 MSG("%sTrace file count: %" PRIu64
" per stream", indent6
,
1325 channel
->attr
.tracefile_count
== 0 ?
1326 1 : channel
->attr
.tracefile_count
);
1327 if (channel
->attr
.tracefile_size
!= 0 ) {
1328 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
,
1329 channel
->attr
.tracefile_size
);
1331 MSG("%sTrace file size: %s", indent6
, "unlimited");
1333 switch (channel
->attr
.output
) {
1334 case LTTNG_EVENT_SPLICE
:
1335 MSG("%sOutput mode: splice", indent6
);
1337 case LTTNG_EVENT_MMAP
:
1338 MSG("%sOutput mode: mmap", indent6
);
1342 MSG("\n%sStatistics:", indent4
);
1343 if (listed_session
.snapshot_mode
) {
1345 * The lost packet count is omitted for sessions in snapshot
1346 * mode as it is misleading: it would indicate the number of
1347 * packets that the consumer could not extract during the
1348 * course of recording the snapshot. It does not have the
1349 * same meaning as the "regular" lost packet count that
1350 * would result from the consumer not keeping up with
1351 * event production in an overwrite-mode channel.
1353 * A more interesting statistic would be the number of
1354 * packets lost between the first and last extracted
1355 * packets of a given snapshot (which prevents most analyses).
1357 MSG("%sNone", indent6
);
1358 goto skip_stats_printing
;
1361 if (!channel
->attr
.overwrite
) {
1362 MSG("%sDiscarded events: %" PRIu64
, indent6
, discarded_events
);
1364 MSG("%sLost packets: %" PRIu64
, indent6
, lost_packets
);
1366 skip_stats_printing
:
1372 * Print a list of channel
1375 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1376 const char *channel_name
)
1379 unsigned int chan_found
= 0;
1381 /* Open channels element */
1382 ret
= mi_lttng_channels_open(writer
);
1387 for (i
= 0; i
< count
; i
++) {
1388 if (channel_name
!= NULL
) {
1389 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1396 /* Write channel element and leave it open */
1397 ret
= mi_lttng_channel(writer
, &channels
[i
], 1);
1402 /* Listing events per channel */
1403 ret
= list_events(channels
[i
].name
);
1408 /* Closing the channel element we opened earlier */
1409 ret
= mi_lttng_writer_close_element(writer
);
1419 /* Close channels element */
1420 ret
= mi_lttng_writer_close_element(writer
);
1430 * List channel(s) of session and domain.
1432 * If channel_name is NULL, all channels are listed.
1434 static int list_channels(const char *channel_name
)
1436 int count
, i
, ret
= CMD_SUCCESS
;
1437 unsigned int chan_found
= 0;
1438 struct lttng_channel
*channels
= NULL
;
1440 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1442 count
= lttng_list_channels(handle
, &channels
);
1445 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1447 /* When printing mi this is not an error
1448 * but an empty channels element */
1452 goto error_channels
;
1456 /* We had a real error */
1458 ERR("%s", lttng_strerror(count
));
1459 goto error_channels
;
1466 ret
= mi_list_channels(channels
, count
, channel_name
);
1474 MSG("Channels:\n-------------");
1477 for (i
= 0; i
< count
; i
++) {
1478 if (channel_name
!= NULL
) {
1479 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1485 print_channel(&channels
[i
]);
1487 /* Listing events per channel */
1488 ret
= list_events(channels
[i
].name
);
1498 if (!chan_found
&& channel_name
!= NULL
) {
1500 ERR("Channel %s not found", channel_name
);
1511 static const char *get_capitalized_process_attr_str(enum lttng_process_attr process_attr
)
1513 switch (process_attr
) {
1514 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1515 return "Process ID";
1516 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1517 return "Virtual process ID";
1518 case LTTNG_PROCESS_ATTR_USER_ID
:
1520 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1521 return "Virtual user ID";
1522 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1524 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1525 return "Virtual group ID";
1532 static int handle_process_attr_status(enum lttng_process_attr process_attr
,
1533 enum lttng_process_attr_tracker_handle_status status
)
1535 int ret
= CMD_SUCCESS
;
1538 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID_TRACKING_POLICY
:
1539 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
1542 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
1543 ERR("Communication occurred while fetching %s tracker",
1544 lttng_process_attr_to_string(process_attr
));
1547 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_SESSION_DOES_NOT_EXIST
:
1548 ERR("Failed to get the inclusion set of the %s tracker: session `%s` no longer exists",
1549 lttng_process_attr_to_string(process_attr
),
1550 handle
->session_name
);
1554 ERR("Unknown error occurred while fetching the inclusion set of the %s tracker",
1555 lttng_process_attr_to_string(process_attr
));
1563 static int mi_output_empty_tracker(enum lttng_process_attr process_attr
)
1567 ret
= mi_lttng_process_attribute_tracker_open(writer
, process_attr
);
1572 ret
= mi_lttng_close_multi_element(writer
, 2);
1577 static inline bool is_value_type_name(
1578 enum lttng_process_attr_value_type value_type
)
1580 return value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
||
1581 value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
;
1585 * List a process attribute tracker for a session and domain tuple.
1587 static int list_process_attr_tracker(enum lttng_process_attr process_attr
)
1590 unsigned int count
, i
;
1591 enum lttng_tracking_policy policy
;
1592 enum lttng_error_code ret_code
;
1593 enum lttng_process_attr_tracker_handle_status handle_status
;
1594 enum lttng_process_attr_values_status values_status
;
1595 const struct lttng_process_attr_values
*values
;
1596 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
1598 ret_code
= lttng_session_get_tracker_handle(handle
->session_name
,
1599 handle
->domain
.type
, process_attr
, &tracker_handle
);
1600 if (ret_code
!= LTTNG_OK
) {
1601 ERR("Failed to get process attribute tracker handle: %s",
1602 lttng_strerror(ret_code
));
1607 handle_status
= lttng_process_attr_tracker_handle_get_inclusion_set(
1608 tracker_handle
, &values
);
1609 ret
= handle_process_attr_status(process_attr
, handle_status
);
1610 if (ret
!= CMD_SUCCESS
) {
1614 handle_status
= lttng_process_attr_tracker_handle_get_tracking_policy(
1615 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(&process_attr_name
, "%ss:",
1624 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 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 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(
1678 writer
, process_attr
);
1684 for (i
= 0; i
< count
; i
++) {
1685 const enum lttng_process_attr_value_type value_type
=
1686 lttng_process_attr_values_get_type_at_index(
1688 int64_t integral_value
= INT64_MAX
;
1689 const char *name
= "error";
1694 switch (value_type
) {
1695 case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID
:
1699 values_status
= lttng_process_attr_values_get_pid_at_index(
1701 integral_value
= (int64_t) pid
;
1704 case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID
:
1708 values_status
= lttng_process_attr_values_get_uid_at_index(
1710 integral_value
= (int64_t) uid
;
1713 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID
:
1717 values_status
= lttng_process_attr_values_get_gid_at_index(
1719 integral_value
= (int64_t) gid
;
1722 case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
:
1723 values_status
= lttng_process_attr_values_get_user_name_at_index(
1726 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
:
1727 values_status
= lttng_process_attr_values_get_group_name_at_index(
1735 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1737 * Not possible given the current liblttng-ctl
1740 ERR("Unknown error occurred while fetching process attribute value in inclusion list");
1745 if (is_value_type_name(value_type
)) {
1748 _MSG("%" PRIi64
, integral_value
);
1753 ret
= is_value_type_name(value_type
) ?
1754 mi_lttng_string_process_attribute_value(
1758 mi_lttng_integral_process_attribute_value(
1770 /* Mi close tracker_id and targets */
1772 ret
= mi_lttng_close_multi_element(writer
, 2);
1778 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
1783 * List all trackers of a domain
1785 static int list_trackers(const struct lttng_domain
*domain
)
1789 MSG("Tracked process attributes");
1790 /* Trackers listing */
1792 ret
= mi_lttng_trackers_open(writer
);
1798 switch (domain
->type
) {
1799 case LTTNG_DOMAIN_KERNEL
:
1801 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_PROCESS_ID
);
1806 ret
= list_process_attr_tracker(
1807 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1812 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_USER_ID
);
1817 ret
= list_process_attr_tracker(
1818 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1823 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_GROUP_ID
);
1828 ret
= list_process_attr_tracker(
1829 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1834 case LTTNG_DOMAIN_UST
:
1836 ret
= list_process_attr_tracker(
1837 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1842 ret
= list_process_attr_tracker(
1843 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1848 ret
= list_process_attr_tracker(
1849 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1859 /* Close trackers element */
1860 ret
= mi_lttng_writer_close_element(writer
);
1870 static enum cmd_error_code
print_periodic_rotation_schedule(
1871 const struct lttng_rotation_schedule
*schedule
)
1873 enum cmd_error_code ret
;
1874 enum lttng_rotation_status status
;
1877 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1879 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1880 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1885 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
1891 static enum cmd_error_code
print_size_threshold_rotation_schedule(
1892 const struct lttng_rotation_schedule
*schedule
)
1894 enum cmd_error_code ret
;
1895 enum lttng_rotation_status status
;
1898 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
1900 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1901 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1906 MSG(" size threshold: %" PRIu64
" bytes", value
);
1912 static enum cmd_error_code
print_rotation_schedule(
1913 const struct lttng_rotation_schedule
*schedule
)
1915 enum cmd_error_code ret
;
1917 switch (lttng_rotation_schedule_get_type(schedule
)) {
1918 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1919 ret
= print_size_threshold_rotation_schedule(schedule
);
1921 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1922 ret
= print_periodic_rotation_schedule(schedule
);
1931 * List the automatic rotation settings.
1933 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1936 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1937 unsigned int count
, i
;
1938 struct lttng_rotation_schedules
*schedules
= NULL
;
1939 enum lttng_rotation_status status
;
1941 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1942 if (ret
!= LTTNG_OK
) {
1943 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1944 cmd_ret
= CMD_ERROR
;
1948 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1949 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1950 ERR("Failed to retrieve the number of session rotation schedules.");
1951 cmd_ret
= CMD_ERROR
;
1956 cmd_ret
= CMD_SUCCESS
;
1960 MSG("Automatic rotation schedules:");
1962 ret
= mi_lttng_writer_open_element(writer
,
1963 mi_lttng_element_rotation_schedules
);
1965 cmd_ret
= CMD_ERROR
;
1970 for (i
= 0; i
< count
; i
++) {
1971 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1972 const struct lttng_rotation_schedule
*schedule
;
1974 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1976 ERR("Failed to retrieve session rotation schedule.");
1977 cmd_ret
= CMD_ERROR
;
1982 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
1984 tmp_ret
= CMD_ERROR
;
1987 tmp_ret
= print_rotation_schedule(schedule
);
1991 * Report an error if the serialization of any of the
1992 * descriptors failed.
1994 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
1999 /* Close the rotation_schedules element. */
2000 ret
= mi_lttng_writer_close_element(writer
);
2002 cmd_ret
= CMD_ERROR
;
2007 lttng_rotation_schedules_destroy(schedules
);
2013 * Find the session with session_name as name
2014 * and print his informations.
2016 static int mi_list_session(const char *session_name
,
2017 struct lttng_session
*sessions
, int count
)
2020 unsigned int session_found
= 0;
2022 if (session_name
== NULL
) {
2023 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2027 for (i
= 0; i
< count
; i
++) {
2028 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2029 /* We need to leave it open to append other informations
2030 * like domain, channel, events etc.*/
2032 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
2040 if (!session_found
) {
2041 ERR("Session '%s' not found", session_name
);
2042 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2052 * List all availables session
2054 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
2058 /* Opening sessions element */
2059 ret
= mi_lttng_sessions_open(writer
);
2064 /* Listing sessions */
2065 for (i
= 0; i
< count
; i
++) {
2066 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
2072 /* Closing sessions element */
2073 ret
= mi_lttng_writer_close_element(writer
);
2083 * List available tracing session. List only basic information.
2085 * If session_name is NULL, all sessions are listed.
2087 static int list_sessions(const char *session_name
)
2089 int ret
= CMD_SUCCESS
;
2091 unsigned int session_found
= 0;
2092 struct lttng_session
*sessions
= NULL
;
2094 count
= lttng_list_sessions(&sessions
);
2095 DBG("Session count %d", count
);
2098 ERR("%s", lttng_strerror(count
));
2104 if (session_name
== NULL
) {
2105 /* List all sessions */
2106 ret
= mi_list_sessions(sessions
, count
);
2108 /* Note : this return an open session element */
2109 ret
= mi_list_session(session_name
, sessions
, count
);
2118 MSG("Currently no available tracing session");
2122 if (session_name
== NULL
) {
2123 MSG("Available tracing sessions:");
2126 for (i
= 0; i
< count
; i
++) {
2127 if (session_name
!= NULL
) {
2128 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2130 MSG("Tracing session %s: [%s%s]", session_name
,
2131 active_string(sessions
[i
].enabled
),
2132 snapshot_string(sessions
[i
].snapshot_mode
));
2133 if (*sessions
[i
].path
) {
2134 MSG("%sTrace output: %s\n", indent4
, sessions
[i
].path
);
2136 memcpy(&listed_session
, &sessions
[i
],
2137 sizeof(listed_session
));
2141 MSG(" %d) %s [%s%s]", i
+ 1,
2143 active_string(sessions
[i
].enabled
),
2144 snapshot_string(sessions
[i
].snapshot_mode
));
2145 if (*sessions
[i
].path
) {
2146 MSG("%sTrace output: %s", indent4
, sessions
[i
].path
);
2148 if (sessions
[i
].live_timer_interval
!= 0) {
2149 MSG("%sLive timer interval: %u %s", indent4
,
2150 sessions
[i
].live_timer_interval
,
2157 if (!session_found
&& session_name
!= NULL
) {
2158 ERR("Session '%s' not found", session_name
);
2163 if (session_name
== NULL
) {
2164 MSG("\nUse lttng list <session_name> for more details");
2176 * list available domain(s) for a session.
2178 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
2181 /* Open domains element */
2182 ret
= mi_lttng_domains_open(writer
);
2187 for (i
= 0; i
< count
; i
++) {
2188 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
2194 /* Closing domains element */
2195 ret
= mi_lttng_writer_close_element(writer
);
2204 * List available domain(s) for a session.
2206 static int list_domains(const char *session_name
)
2208 int i
, count
, ret
= CMD_SUCCESS
;
2209 struct lttng_domain
*domains
= NULL
;
2212 count
= lttng_list_domains(session_name
, &domains
);
2215 ERR("%s", lttng_strerror(count
));
2221 ret
= mi_list_domains(domains
, count
);
2228 MSG("Domains:\n-------------");
2234 for (i
= 0; i
< count
; i
++) {
2235 switch (domains
[i
].type
) {
2236 case LTTNG_DOMAIN_KERNEL
:
2239 case LTTNG_DOMAIN_UST
:
2240 MSG(" - UST global");
2242 case LTTNG_DOMAIN_JUL
:
2243 MSG(" - JUL (Java Util Logging)");
2245 case LTTNG_DOMAIN_LOG4J
:
2246 MSG(" - LOG4j (Logging for Java)");
2248 case LTTNG_DOMAIN_PYTHON
:
2249 MSG(" - Python (logging)");
2265 * The 'list <options>' first level command
2267 int cmd_list(int argc
, const char **argv
)
2269 int opt
, ret
= CMD_SUCCESS
;
2270 const char *session_name
, *leftover
= NULL
;
2271 static poptContext pc
;
2272 struct lttng_domain domain
;
2273 struct lttng_domain
*domains
= NULL
;
2275 memset(&domain
, 0, sizeof(domain
));
2282 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2283 poptReadDefaultConfig(pc
, 0);
2285 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2293 case OPT_LIST_OPTIONS
:
2294 list_cmd_options(stdout
, long_options
);
2297 ret
= CMD_UNDEFINED
;
2304 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
2310 /* Open command element */
2311 ret
= mi_lttng_writer_command_open(writer
,
2312 mi_lttng_element_command_list
);
2318 /* Open output element */
2319 ret
= mi_lttng_writer_open_element(writer
,
2320 mi_lttng_element_command_output
);
2327 /* Get session name (trailing argument) */
2328 session_name
= poptGetArg(pc
);
2329 DBG2("Session name: %s", session_name
);
2331 leftover
= poptGetArg(pc
);
2333 ERR("Unknown argument: %s", leftover
);
2339 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2340 } else if (opt_userspace
) {
2341 DBG2("Listing userspace global domain");
2342 domain
.type
= LTTNG_DOMAIN_UST
;
2343 } else if (opt_jul
) {
2344 DBG2("Listing JUL domain");
2345 domain
.type
= LTTNG_DOMAIN_JUL
;
2346 } else if (opt_log4j
) {
2347 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2348 } else if (opt_python
) {
2349 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2352 if (!opt_kernel
&& opt_syscall
) {
2353 WARN("--syscall will only work with the Kernel domain (-k)");
2358 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2359 handle
= lttng_create_handle(session_name
, &domain
);
2360 if (handle
== NULL
) {
2366 if (session_name
== NULL
) {
2367 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2369 ret
= list_sessions(NULL
);
2376 ret
= list_syscalls();
2381 ret
= list_kernel_events();
2387 if (opt_userspace
) {
2389 ret
= list_ust_event_fields();
2391 ret
= list_ust_events();
2397 if (opt_jul
|| opt_log4j
|| opt_python
) {
2398 ret
= list_agent_events();
2404 /* List session attributes */
2406 /* Open element sessions
2407 * Present for xml consistency */
2408 ret
= mi_lttng_sessions_open(writer
);
2413 /* MI: the ouptut of list_sessions is an unclosed session element */
2414 ret
= list_sessions(session_name
);
2419 ret
= list_rotate_settings(session_name
);
2424 /* Domain listing */
2426 ret
= list_domains(session_name
);
2430 /* Channel listing */
2431 if (opt_kernel
|| opt_userspace
) {
2433 /* Add of domains and domain element for xml
2434 * consistency and validation
2436 ret
= mi_lttng_domains_open(writer
);
2441 /* Open domain and leave it open for
2442 * nested channels printing */
2443 ret
= mi_lttng_domain(writer
, &domain
, 1);
2452 ret
= list_trackers(&domain
);
2458 ret
= list_channels(opt_channel
);
2464 /* Close domain and domain element */
2465 ret
= mi_lttng_close_multi_element(writer
, 2);
2475 /* We want all domain(s) */
2476 nb_domain
= lttng_list_domains(session_name
, &domains
);
2477 if (nb_domain
< 0) {
2479 ERR("%s", lttng_strerror(nb_domain
));
2484 ret
= mi_lttng_domains_open(writer
);
2491 for (i
= 0; i
< nb_domain
; i
++) {
2492 switch (domains
[i
].type
) {
2493 case LTTNG_DOMAIN_KERNEL
:
2494 MSG("=== Domain: Linux kernel ===\n");
2496 case LTTNG_DOMAIN_UST
:
2497 MSG("=== Domain: User space ===\n");
2498 MSG("Buffering scheme: %s\n",
2499 domains
[i
].buf_type
==
2500 LTTNG_BUFFER_PER_PID
? "per-process" : "per-user");
2502 case LTTNG_DOMAIN_JUL
:
2503 MSG("=== Domain: java.util.logging (JUL) ===\n");
2505 case LTTNG_DOMAIN_LOG4J
:
2506 MSG("=== Domain: log4j ===\n");
2508 case LTTNG_DOMAIN_PYTHON
:
2509 MSG("=== Domain: Python logging ===\n");
2512 MSG("=== Domain: Unimplemented ===\n");
2517 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
2524 /* Clean handle before creating a new one */
2526 lttng_destroy_handle(handle
);
2529 handle
= lttng_create_handle(session_name
, &domains
[i
]);
2530 if (handle
== NULL
) {
2535 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2536 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2537 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2538 ret
= list_session_agent_events();
2546 switch (domains
[i
].type
) {
2547 case LTTNG_DOMAIN_KERNEL
:
2548 case LTTNG_DOMAIN_UST
:
2549 ret
= list_trackers(&domains
[i
]);
2558 ret
= list_channels(opt_channel
);
2565 /* Close domain element */
2566 ret
= mi_lttng_writer_close_element(writer
);
2575 /* Close the domains, session and sessions element */
2576 ret
= mi_lttng_close_multi_element(writer
, 3);
2587 /* Close output element */
2588 ret
= mi_lttng_writer_close_element(writer
);
2594 /* Command element close */
2595 ret
= mi_lttng_writer_command_close(writer
);
2603 if (writer
&& mi_lttng_writer_destroy(writer
)) {
2604 /* Preserve original error code */
2605 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2610 lttng_destroy_handle(handle
);
2613 poptFreeContext(pc
);