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>
22 #include <lttng/map/map.h>
24 #include "../command.h"
26 static int opt_userspace
;
27 static int opt_kernel
;
30 static int opt_python
;
31 static char *opt_channel
;
33 static int opt_domain
;
34 static int opt_fields
;
35 static int opt_syscall
;
37 const char *indent4
= " ";
38 const char *indent6
= " ";
39 const char *indent8
= " ";
41 #ifdef LTTNG_EMBED_HELP
42 static const char help_msg
[] =
43 #include <lttng-list.1.h>
53 static struct lttng_handle
*handle
;
54 static struct mi_writer
*writer
;
56 /* Only set when listing a single session. */
57 static struct lttng_session listed_session
;
59 static struct poptOption long_options
[] = {
60 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
61 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
62 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
63 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
64 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
65 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
66 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
67 {"channel", 'c', POPT_ARG_STRING
, &opt_channel
, 0, 0, 0},
68 {"map", 'm', POPT_ARG_STRING
, &opt_map
, 0, 0, 0},
69 {"domain", 'd', POPT_ARG_VAL
, &opt_domain
, 1, 0, 0},
70 {"fields", 'f', POPT_ARG_VAL
, &opt_fields
, 1, 0, 0},
71 {"syscall", 'S', POPT_ARG_VAL
, &opt_syscall
, 1, 0, 0},
72 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
77 * Get command line from /proc for a specific pid.
79 * On success, return an allocated string pointer to the proc cmdline.
80 * On error, return NULL.
82 static char *get_cmdline_by_pid(pid_t pid
)
87 /* Can't go bigger than /proc/LTTNG_MAX_PID/cmdline */
88 char path
[sizeof("/proc//cmdline") + sizeof(LTTNG_MAX_PID_STR
) - 1];
90 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pid
);
91 fp
= fopen(path
, "r");
96 /* Caller must free() *cmdline */
97 cmdline
= zmalloc(PATH_MAX
);
99 PERROR("malloc cmdline");
102 ret
= fread(cmdline
, 1, PATH_MAX
, fp
);
104 PERROR("fread proc list");
115 const char *active_string(int value
)
118 case 0: return "inactive";
119 case 1: return "active";
121 default: return NULL
;
125 static const char *snapshot_string(int value
)
136 const char *enabled_string(int value
)
139 case 0: return " [disabled]";
140 case 1: return " [enabled]";
142 default: return NULL
;
147 const char *safe_string(const char *str
)
149 return str
? str
: "";
152 static const char *logleveltype_string(enum lttng_loglevel_type value
)
155 case LTTNG_EVENT_LOGLEVEL_ALL
:
157 case LTTNG_EVENT_LOGLEVEL_RANGE
:
159 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
162 return " <<TYPE UNKN>>";
166 static const char *bitness_event(enum lttng_event_flag flags
)
168 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_32
) {
169 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
170 return " [32/64-bit]";
174 } else if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
182 * Get exclusion names message for a single event.
184 * Returned pointer must be freed by caller. Returns NULL on error.
186 static char *get_exclusion_names_msg(struct lttng_event
*event
)
190 char *exclusion_msg
= NULL
;
193 const char * const exclusion_fmt
= " [exclusions: ";
194 const size_t exclusion_fmt_len
= strlen(exclusion_fmt
);
196 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
197 if (exclusion_count
< 0) {
199 } else if (exclusion_count
== 0) {
201 * No exclusions: return copy of empty string so that
202 * it can be freed by caller.
204 exclusion_msg
= strdup("");
209 * exclusion_msg's size is bounded by the exclusion_fmt string,
210 * a comma per entry, the entry count (fixed-size), a closing
211 * bracket, and a trailing \0.
213 exclusion_msg
= malloc(exclusion_count
+
214 exclusion_count
* LTTNG_SYMBOL_NAME_LEN
+
215 exclusion_fmt_len
+ 1);
216 if (!exclusion_msg
) {
220 at
= strcpy(exclusion_msg
, exclusion_fmt
) + exclusion_fmt_len
;
221 for (i
= 0; i
< exclusion_count
; ++i
) {
224 /* Append comma between exclusion names */
230 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
232 /* Prints '?' on local error; should never happen */
238 /* Append exclusion name */
239 at
+= sprintf(at
, "%s", name
);
242 /* This also puts a final '\0' at the end of exclusion_msg */
246 return exclusion_msg
;
249 static void print_userspace_probe_location(struct lttng_event
*event
)
251 const struct lttng_userspace_probe_location
*location
;
252 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
253 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
255 location
= lttng_event_get_userspace_probe_location(event
);
257 MSG("Event has no userspace probe location");
261 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
262 if (!lookup_method
) {
263 MSG("Event has no userspace probe location lookup method");
267 MSG("%s%s (type: userspace-probe)%s", indent6
, event
->name
, enabled_string(event
->enabled
));
269 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
271 switch (lttng_userspace_probe_location_get_type(location
)) {
272 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
:
273 MSG("%sType: Unknown", indent8
);
275 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
277 const char *function_name
;
280 MSG("%sType: Function", indent8
);
281 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
282 binary_path
= realpath(lttng_userspace_probe_location_function_get_binary_path(location
), NULL
);
284 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
285 MSG("%sFunction: %s()", indent8
, function_name
? function_name
: "NULL");
286 switch (lookup_type
) {
287 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
288 MSG("%sLookup method: ELF", indent8
);
290 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
291 MSG("%sLookup method: default", indent8
);
294 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
301 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
303 const char *probe_name
, *provider_name
;
306 MSG("%sType: Tracepoint", indent8
);
307 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
308 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
309 binary_path
= realpath(lttng_userspace_probe_location_tracepoint_get_binary_path(location
), NULL
);
310 MSG("%sBinary path: %s", indent8
, binary_path
? binary_path
: "NULL");
311 MSG("%sTracepoint: %s:%s", indent8
, provider_name
? provider_name
: "NULL", probe_name
? probe_name
: "NULL");
312 switch (lookup_type
) {
313 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
314 MSG("%sLookup method: SDT", indent8
);
317 MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8
);
325 ERR("Invalid probe type encountered");
330 * Pretty print single event.
332 static void print_events(struct lttng_event
*event
)
335 const char *filter_str
;
336 char *filter_msg
= NULL
;
337 char *exclusion_msg
= NULL
;
339 ret
= lttng_event_get_filter_expression(event
, &filter_str
);
342 filter_msg
= strdup(" [failed to retrieve filter]");
343 } else if (filter_str
) {
344 const char * const filter_fmt
= " [filter: '%s']";
346 filter_msg
= malloc(strlen(filter_str
) +
347 strlen(filter_fmt
) + 1);
349 sprintf(filter_msg
, filter_fmt
,
354 exclusion_msg
= get_exclusion_names_msg(event
);
355 if (!exclusion_msg
) {
356 exclusion_msg
= strdup(" [failed to retrieve exclusions]");
359 switch (event
->type
) {
360 case LTTNG_EVENT_TRACEPOINT
:
362 if (event
->loglevel
!= -1) {
363 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
366 logleveltype_string(event
->loglevel_type
),
367 mi_lttng_loglevel_string(event
->loglevel
, handle
->domain
.type
),
369 enabled_string(event
->enabled
),
370 safe_string(exclusion_msg
),
371 safe_string(filter_msg
));
373 MSG("%s%s (type: tracepoint)%s%s%s",
376 enabled_string(event
->enabled
),
377 safe_string(exclusion_msg
),
378 safe_string(filter_msg
));
382 case LTTNG_EVENT_FUNCTION
:
383 MSG("%s%s (type: function)%s%s", indent6
,
384 event
->name
, enabled_string(event
->enabled
),
385 safe_string(filter_msg
));
386 if (event
->attr
.probe
.addr
!= 0) {
387 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
389 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
390 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
393 case LTTNG_EVENT_PROBE
:
394 MSG("%s%s (type: probe)%s%s", indent6
,
395 event
->name
, enabled_string(event
->enabled
),
396 safe_string(filter_msg
));
397 if (event
->attr
.probe
.addr
!= 0) {
398 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
400 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
401 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
404 case LTTNG_EVENT_USERSPACE_PROBE
:
405 print_userspace_probe_location(event
);
407 case LTTNG_EVENT_FUNCTION_ENTRY
:
408 MSG("%s%s (type: function)%s%s", indent6
,
409 event
->name
, enabled_string(event
->enabled
),
410 safe_string(filter_msg
));
411 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
413 case LTTNG_EVENT_SYSCALL
:
414 MSG("%s%s%s%s%s%s", indent6
, event
->name
,
415 (opt_syscall
? "" : " (type:syscall)"),
416 enabled_string(event
->enabled
),
417 bitness_event(event
->flags
),
418 safe_string(filter_msg
));
420 case LTTNG_EVENT_NOOP
:
421 MSG("%s (type: noop)%s%s", indent6
,
422 enabled_string(event
->enabled
),
423 safe_string(filter_msg
));
425 case LTTNG_EVENT_ALL
:
428 /* We should never have "all" events in list. */
437 static const char *field_type(struct lttng_event_field
*field
)
439 switch(field
->type
) {
440 case LTTNG_EVENT_FIELD_INTEGER
:
442 case LTTNG_EVENT_FIELD_ENUM
:
444 case LTTNG_EVENT_FIELD_FLOAT
:
446 case LTTNG_EVENT_FIELD_STRING
:
448 case LTTNG_EVENT_FIELD_OTHER
:
449 default: /* fall-through */
455 * Pretty print single event fields.
457 static void print_event_field(struct lttng_event_field
*field
)
459 if (!field
->field_name
[0]) {
462 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
463 field_type(field
), field
->nowrite
? " [no write]" : "");
468 * Jul and ust event listing
470 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
471 struct lttng_domain
*domain
)
475 char *cmdline
= NULL
;
476 int pid_element_open
= 0;
478 /* Open domains element */
479 ret
= mi_lttng_domains_open(writer
);
485 ret
= mi_lttng_domain(writer
, domain
, 1);
490 /* Open pids element element */
491 ret
= mi_lttng_pids_open(writer
);
496 for (i
= 0; i
< count
; i
++) {
497 if (cur_pid
!= events
[i
].pid
) {
498 if (pid_element_open
) {
499 /* Close the previous events and pid element */
500 ret
= mi_lttng_close_multi_element(writer
, 2);
504 pid_element_open
= 0;
507 cur_pid
= events
[i
].pid
;
508 cmdline
= get_cmdline_by_pid(cur_pid
);
514 if (!pid_element_open
) {
515 /* Open and write a pid element */
516 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
521 /* Open events element */
522 ret
= mi_lttng_events_open(writer
);
527 pid_element_open
= 1;
533 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
540 ret
= mi_lttng_writer_close_element(writer
);
545 /* Close domain, domains */
546 ret
= mi_lttng_close_multi_element(writer
, 2);
554 static int list_agent_events(void)
556 int i
, size
, ret
= CMD_SUCCESS
;
557 struct lttng_domain domain
;
558 struct lttng_handle
*handle
= NULL
;
559 struct lttng_event
*event_list
= NULL
;
561 char *cmdline
= NULL
;
562 const char *agent_domain_str
;
564 memset(&domain
, 0, sizeof(domain
));
566 domain
.type
= LTTNG_DOMAIN_JUL
;
567 } else if (opt_log4j
) {
568 domain
.type
= LTTNG_DOMAIN_LOG4J
;
569 } else if (opt_python
) {
570 domain
.type
= LTTNG_DOMAIN_PYTHON
;
572 ERR("Invalid agent domain selected.");
577 agent_domain_str
= get_domain_str(domain
.type
);
579 DBG("Getting %s tracing events", agent_domain_str
);
581 handle
= lttng_create_handle(NULL
, &domain
);
582 if (handle
== NULL
) {
587 size
= lttng_list_tracepoints(handle
, &event_list
);
589 ERR("Unable to list %s events: %s", agent_domain_str
,
590 lttng_strerror(size
));
597 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
604 MSG("%s events (Logger name):\n-------------------------",
611 for (i
= 0; i
< size
; i
++) {
612 if (cur_pid
!= event_list
[i
].pid
) {
613 cur_pid
= event_list
[i
].pid
;
614 cmdline
= get_cmdline_by_pid(cur_pid
);
615 if (cmdline
== NULL
) {
619 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
622 MSG("%s- %s", indent6
, event_list
[i
].name
);
631 lttng_destroy_handle(handle
);
636 * Ask session daemon for all user space tracepoints available.
638 static int list_ust_events(void)
640 int i
, size
, ret
= CMD_SUCCESS
;
641 struct lttng_domain domain
;
642 struct lttng_handle
*handle
;
643 struct lttng_event
*event_list
= NULL
;
645 char *cmdline
= NULL
;
647 memset(&domain
, 0, sizeof(domain
));
649 DBG("Getting UST tracing events");
651 domain
.type
= LTTNG_DOMAIN_UST
;
653 handle
= lttng_create_handle(NULL
, &domain
);
654 if (handle
== NULL
) {
659 size
= lttng_list_tracepoints(handle
, &event_list
);
661 ERR("Unable to list UST events: %s", lttng_strerror(size
));
668 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
671 MSG("UST events:\n-------------");
677 for (i
= 0; i
< size
; i
++) {
678 if (cur_pid
!= event_list
[i
].pid
) {
679 cur_pid
= event_list
[i
].pid
;
680 cmdline
= get_cmdline_by_pid(cur_pid
);
681 if (cmdline
== NULL
) {
685 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
688 print_events(&event_list
[i
]);
697 lttng_destroy_handle(handle
);
703 * List all ust event with their fields
705 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
706 struct lttng_domain
*domain
)
710 char *cmdline
= NULL
;
711 int pid_element_open
= 0;
712 int event_element_open
= 0;
713 struct lttng_event cur_event
;
715 memset(&cur_event
, 0, sizeof(cur_event
));
717 /* Open domains element */
718 ret
= mi_lttng_domains_open(writer
);
724 ret
= mi_lttng_domain(writer
, domain
, 1);
729 /* Open pids element */
730 ret
= mi_lttng_pids_open(writer
);
735 for (i
= 0; i
< count
; i
++) {
736 if (cur_pid
!= fields
[i
].event
.pid
) {
737 if (pid_element_open
) {
738 if (event_element_open
) {
739 /* Close the previous field element and event. */
740 ret
= mi_lttng_close_multi_element(writer
, 2);
744 event_element_open
= 0;
746 /* Close the previous events, pid element */
747 ret
= mi_lttng_close_multi_element(writer
, 2);
751 pid_element_open
= 0;
754 cur_pid
= fields
[i
].event
.pid
;
755 cmdline
= get_cmdline_by_pid(cur_pid
);
756 if (!pid_element_open
) {
757 /* Open and write a pid element */
758 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
763 /* Open events element */
764 ret
= mi_lttng_events_open(writer
);
768 pid_element_open
= 1;
771 /* Wipe current event since we are about to print a new PID. */
772 memset(&cur_event
, 0, sizeof(cur_event
));
775 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
776 if (event_element_open
) {
777 /* Close the previous fields element and the previous event */
778 ret
= mi_lttng_close_multi_element(writer
, 2);
782 event_element_open
= 0;
785 memcpy(&cur_event
, &fields
[i
].event
,
788 if (!event_element_open
) {
789 /* Open and write the event */
790 ret
= mi_lttng_event(writer
, &cur_event
, 1,
791 handle
->domain
.type
);
796 /* Open a fields element */
797 ret
= mi_lttng_event_fields_open(writer
);
801 event_element_open
= 1;
805 /* Print the event_field */
806 ret
= mi_lttng_event_field(writer
, &fields
[i
]);
812 /* Close pids, domain, domains */
813 ret
= mi_lttng_close_multi_element(writer
, 3);
822 * Ask session daemon for all user space tracepoint fields available.
824 static int list_ust_event_fields(void)
826 int i
, size
, ret
= CMD_SUCCESS
;
827 struct lttng_domain domain
;
828 struct lttng_handle
*handle
;
829 struct lttng_event_field
*event_field_list
;
831 char *cmdline
= NULL
;
833 struct lttng_event cur_event
;
835 memset(&domain
, 0, sizeof(domain
));
836 memset(&cur_event
, 0, sizeof(cur_event
));
838 DBG("Getting UST tracing event fields");
840 domain
.type
= LTTNG_DOMAIN_UST
;
842 handle
= lttng_create_handle(NULL
, &domain
);
843 if (handle
== NULL
) {
848 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
850 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
857 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
864 MSG("UST events:\n-------------");
870 for (i
= 0; i
< size
; i
++) {
871 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
872 cur_pid
= event_field_list
[i
].event
.pid
;
873 cmdline
= get_cmdline_by_pid(cur_pid
);
874 if (cmdline
== NULL
) {
878 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
880 /* Wipe current event since we are about to print a new PID. */
881 memset(&cur_event
, 0, sizeof(cur_event
));
883 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
884 print_events(&event_field_list
[i
].event
);
885 memcpy(&cur_event
, &event_field_list
[i
].event
,
888 print_event_field(&event_field_list
[i
]);
895 free(event_field_list
);
897 lttng_destroy_handle(handle
);
903 * Print a list of kernel events
905 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
906 struct lttng_domain
*domain
)
910 /* Open domains element */
911 ret
= mi_lttng_domains_open(writer
);
917 ret
= mi_lttng_domain(writer
, domain
, 1);
923 ret
= mi_lttng_events_open(writer
);
928 for (i
= 0; i
< count
; i
++) {
929 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
935 /* close events, domain and domains */
936 ret
= mi_lttng_close_multi_element(writer
, 3);
946 * Ask for all trace events in the kernel
948 static int list_kernel_events(void)
950 int i
, size
, ret
= CMD_SUCCESS
;
951 struct lttng_domain domain
;
952 struct lttng_handle
*handle
;
953 struct lttng_event
*event_list
;
955 memset(&domain
, 0, sizeof(domain
));
957 DBG("Getting kernel tracing events");
959 domain
.type
= LTTNG_DOMAIN_KERNEL
;
961 handle
= lttng_create_handle(NULL
, &domain
);
962 if (handle
== NULL
) {
967 size
= lttng_list_tracepoints(handle
, &event_list
);
969 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
970 lttng_destroy_handle(handle
);
976 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
982 MSG("Kernel events:\n-------------");
984 for (i
= 0; i
< size
; i
++) {
985 print_events(&event_list
[i
]);
994 lttng_destroy_handle(handle
);
998 lttng_destroy_handle(handle
);
1004 * Print a list of system calls.
1006 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1011 ret
= mi_lttng_events_open(writer
);
1016 for (i
= 0; i
< count
; i
++) {
1017 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1024 ret
= mi_lttng_writer_close_element(writer
);
1034 * Ask for kernel system calls.
1036 static int list_syscalls(void)
1038 int i
, size
, ret
= CMD_SUCCESS
;
1039 struct lttng_event
*event_list
;
1041 DBG("Getting kernel system call events");
1043 size
= lttng_list_syscalls(&event_list
);
1045 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1052 ret
= mi_list_syscalls(event_list
, size
);
1058 MSG("System calls:\n-------------");
1060 for (i
= 0; i
< size
; i
++) {
1061 print_events(&event_list
[i
]);
1077 * Print a list of agent events
1079 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1083 /* Open events element */
1084 ret
= mi_lttng_events_open(writer
);
1089 for (i
= 0; i
< count
; i
++) {
1090 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1096 /* Close events element */
1097 ret
= mi_lttng_writer_close_element(writer
);
1104 * List agent events for a specific session using the handle.
1106 * Return CMD_SUCCESS on success else a negative value.
1108 static int list_session_agent_events(void)
1110 int ret
= CMD_SUCCESS
, count
, i
;
1111 struct lttng_event
*events
= NULL
;
1113 count
= lttng_list_events(handle
, "", &events
);
1116 ERR("%s", lttng_strerror(count
));
1122 ret
= mi_list_session_agent_events(events
, count
);
1129 MSG("Events (Logger name):\n---------------------");
1131 MSG("%sNone\n", indent6
);
1135 for (i
= 0; i
< count
; i
++) {
1136 const char *filter_str
;
1137 char *filter_msg
= NULL
;
1138 struct lttng_event
*event
= &events
[i
];
1140 ret
= lttng_event_get_filter_expression(event
,
1143 filter_msg
= strdup(" [failed to retrieve filter]");
1144 } else if (filter_str
) {
1145 const char * const filter_fmt
=
1148 filter_msg
= malloc(strlen(filter_str
) +
1149 strlen(filter_fmt
) + 1);
1151 sprintf(filter_msg
, filter_fmt
,
1156 if (event
->loglevel_type
!=
1157 LTTNG_EVENT_LOGLEVEL_ALL
) {
1158 MSG("%s- %s%s (loglevel%s %s)%s", indent4
,
1160 enabled_string(event
->enabled
),
1161 logleveltype_string(
1162 event
->loglevel_type
),
1163 mi_lttng_loglevel_string(
1165 handle
->domain
.type
),
1166 safe_string(filter_msg
));
1168 MSG("%s- %s%s%s", indent4
, event
->name
,
1169 enabled_string(event
->enabled
),
1170 safe_string(filter_msg
));
1186 * print a list of event
1188 static int mi_list_events(struct lttng_event
*events
, int count
)
1192 /* Open events element */
1193 ret
= mi_lttng_events_open(writer
);
1198 for (i
= 0; i
< count
; i
++) {
1199 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1205 /* Close events element */
1206 ret
= mi_lttng_writer_close_element(writer
);
1213 * List events of channel of session and domain.
1215 static int list_events(const char *channel_name
)
1217 int ret
= CMD_SUCCESS
, count
, i
;
1218 struct lttng_event
*events
= NULL
;
1220 count
= lttng_list_events(handle
, channel_name
, &events
);
1223 ERR("%s", lttng_strerror(count
));
1229 ret
= mi_list_events(events
, count
);
1236 MSG("\n%sEvent rules:", indent4
);
1238 MSG("%sNone\n", indent6
);
1242 for (i
= 0; i
< count
; i
++) {
1243 print_events(&events
[i
]);
1255 void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1259 _MSG("%s%s:", indent6
, timer_name
);
1260 for (i
= 0; i
< space_count
; i
++) {
1265 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1272 * Pretty print channel
1274 static void print_channel(struct lttng_channel
*channel
)
1277 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1278 int64_t blocking_timeout
;
1280 ret
= lttng_channel_get_discarded_event_count(channel
,
1283 ERR("Failed to retrieve discarded event count of channel");
1287 ret
= lttng_channel_get_lost_packet_count(channel
,
1290 ERR("Failed to retrieve lost packet count of channel");
1294 ret
= lttng_channel_get_monitor_timer_interval(channel
,
1295 &monitor_timer_interval
);
1297 ERR("Failed to retrieve monitor interval of channel");
1301 ret
= lttng_channel_get_blocking_timeout(channel
,
1304 ERR("Failed to retrieve blocking timeout of channel");
1308 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1309 MSG("%sAttributes:", indent4
);
1310 MSG("%sEvent-loss mode: %s", indent6
, channel
->attr
.overwrite
? "overwrite" : "discard");
1311 MSG("%sSub-buffer size: %" PRIu64
" bytes", indent6
, channel
->attr
.subbuf_size
);
1312 MSG("%sSub-buffer count: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1314 print_timer("Switch timer", 5, channel
->attr
.switch_timer_interval
);
1315 print_timer("Read timer", 7, channel
->attr
.read_timer_interval
);
1316 print_timer("Monitor timer", 4, monitor_timer_interval
);
1318 if (!channel
->attr
.overwrite
) {
1319 if (blocking_timeout
== -1) {
1320 MSG("%sBlocking timeout: infinite", indent6
);
1322 MSG("%sBlocking timeout: %" PRId64
" %s", indent6
,
1323 blocking_timeout
, USEC_UNIT
);
1327 MSG("%sTrace file count: %" PRIu64
" per stream", indent6
,
1328 channel
->attr
.tracefile_count
== 0 ?
1329 1 : channel
->attr
.tracefile_count
);
1330 if (channel
->attr
.tracefile_size
!= 0 ) {
1331 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
,
1332 channel
->attr
.tracefile_size
);
1334 MSG("%sTrace file size: %s", indent6
, "unlimited");
1336 switch (channel
->attr
.output
) {
1337 case LTTNG_EVENT_SPLICE
:
1338 MSG("%sOutput mode: splice", indent6
);
1340 case LTTNG_EVENT_MMAP
:
1341 MSG("%sOutput mode: mmap", indent6
);
1345 MSG("\n%sStatistics:", indent4
);
1346 if (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
:
1373 static void print_map(const struct lttng_map
*map
)
1375 const char *map_name
;
1376 enum lttng_map_status map_status
;
1377 enum lttng_buffer_type buffer_type
;
1378 enum lttng_map_bitness bitness
;
1379 enum lttng_map_boundary_policy boundary_policy
;
1380 uint64_t bucket_count
;
1383 bitness
= lttng_map_get_bitness(map
);
1384 is_enabled
= lttng_map_get_is_enabled(map
);
1385 buffer_type
= lttng_map_get_buffer_type(map
);
1387 boundary_policy
= lttng_map_get_boundary_policy(map
);
1389 map_status
= lttng_map_get_name(map
, &map_name
);
1390 if (map_status
!= LTTNG_MAP_STATUS_OK
) {
1391 ERR("Failed to get map name");
1395 map_status
= lttng_map_get_dimension_length(map
, 0, &bucket_count
);
1396 if (map_status
!= LTTNG_MAP_STATUS_OK
) {
1397 ERR("Failed to bucket count");
1401 MSG("- %s (%s)", map_name
, is_enabled
? "enabled": "disabled");
1402 MSG("%sAttributes:", indent4
);
1403 MSG("%sBitness: %s", indent6
, bitness
== LTTNG_MAP_BITNESS_32BITS
? "32" : "64");
1404 _MSG("%sCounter type: ", indent6
);
1405 switch (buffer_type
) {
1406 case LTTNG_BUFFER_PER_PID
:
1409 case LTTNG_BUFFER_PER_UID
:
1412 case LTTNG_BUFFER_GLOBAL
:
1418 MSG("%sBoundary policy: %s", indent6
,
1419 boundary_policy
== LTTNG_MAP_BOUNDARY_POLICY_OVERFLOW
? "OVERFLOW" : "<unknown>");
1420 MSG("%sBucket count: %"PRIu64
, indent6
, bucket_count
);
1427 * Print a list of channel
1430 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1431 const char *channel_name
)
1434 unsigned int chan_found
= 0;
1436 /* Open channels element */
1437 ret
= mi_lttng_channels_open(writer
);
1442 for (i
= 0; i
< count
; i
++) {
1443 if (channel_name
!= NULL
) {
1444 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1451 /* Write channel element and leave it open */
1452 ret
= mi_lttng_channel(writer
, &channels
[i
], 1);
1457 /* Listing events per channel */
1458 ret
= list_events(channels
[i
].name
);
1463 /* Closing the channel element we opened earlier */
1464 ret
= mi_lttng_writer_close_element(writer
);
1474 /* Close channels element */
1475 ret
= mi_lttng_writer_close_element(writer
);
1485 * List channel(s) of session and domain.
1487 * If channel_name is NULL, all channels are listed.
1489 static int list_channels(const char *channel_name
)
1491 int count
, i
, ret
= CMD_SUCCESS
;
1492 unsigned int chan_found
= 0;
1493 struct lttng_channel
*channels
= NULL
;
1495 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1497 count
= lttng_list_channels(handle
, &channels
);
1500 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1502 /* When printing mi this is not an error
1503 * but an empty channels element */
1507 goto error_channels
;
1511 /* We had a real error */
1513 ERR("%s", lttng_strerror(count
));
1514 goto error_channels
;
1521 ret
= mi_list_channels(channels
, count
, channel_name
);
1529 MSG("Channels:\n-------------");
1532 for (i
= 0; i
< count
; i
++) {
1533 if (channel_name
!= NULL
) {
1534 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1540 print_channel(&channels
[i
]);
1542 /* Listing events per channel */
1543 ret
= list_events(channels
[i
].name
);
1553 if (!chan_found
&& channel_name
!= NULL
) {
1555 ERR("Channel %s not found", channel_name
);
1567 * List map(s) of session and domain.
1569 * If map_name is NULL, all maps are listed.
1571 static int list_maps(const char *desired_map_name
)
1573 struct lttng_map_list
*map_list
= NULL
;
1574 enum lttng_map_status map_status
;
1575 enum lttng_error_code ret_code
;
1576 unsigned int i
, map_count
;
1577 int ret
= CMD_SUCCESS
;
1579 DBG("Listing map(s) (%s)", desired_map_name
? : "<all>");
1581 ret_code
= lttng_list_maps(handle
, &map_list
);
1582 if (ret_code
!= LTTNG_OK
) {
1583 ERR("Error getting map list");
1588 map_status
= lttng_map_list_get_count(map_list
, &map_count
);
1589 if (map_status
!= LTTNG_MAP_STATUS_OK
) {
1590 ERR("Error getting map list element count");
1595 MSG("Maps:\n-------------");
1596 for (i
= 0; i
< map_count
; i
++) {
1597 const struct lttng_map
*map
= NULL
;
1598 const char *map_name
= NULL
;
1599 map
= lttng_map_list_get_at_index(map_list
, i
);
1602 ERR("Error getting map from list: index = %u", i
);
1606 map_status
= lttng_map_get_name(map
, &map_name
);
1607 if (map_status
!= LTTNG_MAP_STATUS_OK
) {
1608 ERR("Error getting map name");
1613 if (desired_map_name
!= NULL
) {
1614 if (strncmp(map_name
, desired_map_name
, NAME_MAX
) == 0) {
1623 // Should be in its own patch.
1624 lttng_map_list_destroy(map_list
);
1628 static const char *get_capitalized_process_attr_str(enum lttng_process_attr process_attr
)
1630 switch (process_attr
) {
1631 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1632 return "Process ID";
1633 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1634 return "Virtual process ID";
1635 case LTTNG_PROCESS_ATTR_USER_ID
:
1637 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1638 return "Virtual user ID";
1639 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1641 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1642 return "Virtual group ID";
1649 static int handle_process_attr_status(enum lttng_process_attr process_attr
,
1650 enum lttng_process_attr_tracker_handle_status status
)
1652 int ret
= CMD_SUCCESS
;
1655 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID_TRACKING_POLICY
:
1656 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
1659 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
1660 ERR("Communication occurred while fetching %s tracker",
1661 lttng_process_attr_to_string(process_attr
));
1664 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_SESSION_DOES_NOT_EXIST
:
1665 ERR("Failed to get the inclusion set of the %s tracker: session `%s` no longer exists",
1666 lttng_process_attr_to_string(process_attr
),
1667 handle
->session_name
);
1671 ERR("Unknown error occurred while fetching the inclusion set of the %s tracker",
1672 lttng_process_attr_to_string(process_attr
));
1680 static int mi_output_empty_tracker(enum lttng_process_attr process_attr
)
1684 ret
= mi_lttng_process_attribute_tracker_open(writer
, process_attr
);
1689 ret
= mi_lttng_close_multi_element(writer
, 2);
1694 static inline bool is_value_type_name(
1695 enum lttng_process_attr_value_type value_type
)
1697 return value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
||
1698 value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
;
1702 * List a process attribute tracker for a session and domain tuple.
1704 static int list_process_attr_tracker(enum lttng_process_attr process_attr
)
1707 unsigned int count
, i
;
1708 enum lttng_tracking_policy policy
;
1709 enum lttng_error_code ret_code
;
1710 enum lttng_process_attr_tracker_handle_status handle_status
;
1711 enum lttng_process_attr_values_status values_status
;
1712 const struct lttng_process_attr_values
*values
;
1713 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
1715 ret_code
= lttng_session_get_tracker_handle(handle
->session_name
,
1716 handle
->domain
.type
, process_attr
, &tracker_handle
);
1717 if (ret_code
!= LTTNG_OK
) {
1718 ERR("Failed to get process attribute tracker handle: %s",
1719 lttng_strerror(ret_code
));
1724 handle_status
= lttng_process_attr_tracker_handle_get_inclusion_set(
1725 tracker_handle
, &values
);
1726 ret
= handle_process_attr_status(process_attr
, handle_status
);
1727 if (ret
!= CMD_SUCCESS
) {
1731 handle_status
= lttng_process_attr_tracker_handle_get_tracking_policy(
1732 tracker_handle
, &policy
);
1733 ret
= handle_process_attr_status(process_attr
, handle_status
);
1734 if (ret
!= CMD_SUCCESS
) {
1739 char *process_attr_name
;
1740 const int print_ret
= asprintf(&process_attr_name
, "%ss:",
1741 get_capitalized_process_attr_str(process_attr
));
1743 if (print_ret
== -1) {
1747 _MSG(" %-22s", process_attr_name
);
1748 free(process_attr_name
);
1751 case LTTNG_TRACKING_POLICY_INCLUDE_SET
:
1753 case LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
1755 mi_output_empty_tracker(process_attr
);
1760 case LTTNG_TRACKING_POLICY_INCLUDE_ALL
:
1765 ERR("Unknown tracking policy encoutered while listing the %s process attribute tracker of session `%s`",
1766 lttng_process_attr_to_string(process_attr
),
1767 handle
->session_name
);
1772 values_status
= lttng_process_attr_values_get_count(values
, &count
);
1773 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1774 ERR("Failed to get the count of values in the inclusion set of the %s process attribute tracker of session `%s`",
1775 lttng_process_attr_to_string(process_attr
),
1776 handle
->session_name
);
1782 /* Functionally equivalent to the 'exclude all' policy. */
1784 mi_output_empty_tracker(process_attr
);
1791 /* Mi tracker_id element */
1793 /* Open tracker_id and targets elements */
1794 ret
= mi_lttng_process_attribute_tracker_open(
1795 writer
, process_attr
);
1801 for (i
= 0; i
< count
; i
++) {
1802 const enum lttng_process_attr_value_type value_type
=
1803 lttng_process_attr_values_get_type_at_index(
1805 int64_t integral_value
= INT64_MAX
;
1806 const char *name
= "error";
1811 switch (value_type
) {
1812 case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID
:
1816 values_status
= lttng_process_attr_values_get_pid_at_index(
1818 integral_value
= (int64_t) pid
;
1821 case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID
:
1825 values_status
= lttng_process_attr_values_get_uid_at_index(
1827 integral_value
= (int64_t) uid
;
1830 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID
:
1834 values_status
= lttng_process_attr_values_get_gid_at_index(
1836 integral_value
= (int64_t) gid
;
1839 case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
:
1840 values_status
= lttng_process_attr_values_get_user_name_at_index(
1843 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
:
1844 values_status
= lttng_process_attr_values_get_group_name_at_index(
1852 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1854 * Not possible given the current liblttng-ctl
1857 ERR("Unknown error occurred while fetching process attribute value in inclusion list");
1862 if (is_value_type_name(value_type
)) {
1865 _MSG("%" PRIi64
, integral_value
);
1870 ret
= is_value_type_name(value_type
) ?
1871 mi_lttng_string_process_attribute_value(
1875 mi_lttng_integral_process_attribute_value(
1887 /* Mi close tracker_id and targets */
1889 ret
= mi_lttng_close_multi_element(writer
, 2);
1895 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
1900 * List all trackers of a domain
1902 static int list_trackers(const struct lttng_domain
*domain
)
1906 MSG("Tracked process attributes");
1907 /* Trackers listing */
1909 ret
= mi_lttng_trackers_open(writer
);
1915 switch (domain
->type
) {
1916 case LTTNG_DOMAIN_KERNEL
:
1918 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_PROCESS_ID
);
1923 ret
= list_process_attr_tracker(
1924 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1929 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_USER_ID
);
1934 ret
= list_process_attr_tracker(
1935 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1940 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_GROUP_ID
);
1945 ret
= list_process_attr_tracker(
1946 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1951 case LTTNG_DOMAIN_UST
:
1953 ret
= list_process_attr_tracker(
1954 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1959 ret
= list_process_attr_tracker(
1960 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1965 ret
= list_process_attr_tracker(
1966 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1976 /* Close trackers element */
1977 ret
= mi_lttng_writer_close_element(writer
);
1987 static enum cmd_error_code
print_periodic_rotation_schedule(
1988 const struct lttng_rotation_schedule
*schedule
)
1990 enum cmd_error_code ret
;
1991 enum lttng_rotation_status status
;
1994 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1996 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1997 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
2002 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
2008 static enum cmd_error_code
print_size_threshold_rotation_schedule(
2009 const struct lttng_rotation_schedule
*schedule
)
2011 enum cmd_error_code ret
;
2012 enum lttng_rotation_status status
;
2015 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
2017 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2018 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
2023 MSG(" size threshold: %" PRIu64
" bytes", value
);
2029 static enum cmd_error_code
print_rotation_schedule(
2030 const struct lttng_rotation_schedule
*schedule
)
2032 enum cmd_error_code ret
;
2034 switch (lttng_rotation_schedule_get_type(schedule
)) {
2035 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2036 ret
= print_size_threshold_rotation_schedule(schedule
);
2038 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2039 ret
= print_periodic_rotation_schedule(schedule
);
2048 * List the automatic rotation settings.
2050 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
2053 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
2054 unsigned int count
, i
;
2055 struct lttng_rotation_schedules
*schedules
= NULL
;
2056 enum lttng_rotation_status status
;
2058 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
2059 if (ret
!= LTTNG_OK
) {
2060 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
2061 cmd_ret
= CMD_ERROR
;
2065 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
2066 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2067 ERR("Failed to retrieve the number of session rotation schedules.");
2068 cmd_ret
= CMD_ERROR
;
2073 cmd_ret
= CMD_SUCCESS
;
2077 MSG("Automatic rotation schedules:");
2079 ret
= mi_lttng_writer_open_element(writer
,
2080 mi_lttng_element_rotation_schedules
);
2082 cmd_ret
= CMD_ERROR
;
2087 for (i
= 0; i
< count
; i
++) {
2088 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
2089 const struct lttng_rotation_schedule
*schedule
;
2091 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
2093 ERR("Failed to retrieve session rotation schedule.");
2094 cmd_ret
= CMD_ERROR
;
2099 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
2101 tmp_ret
= CMD_ERROR
;
2104 tmp_ret
= print_rotation_schedule(schedule
);
2108 * Report an error if the serialization of any of the
2109 * descriptors failed.
2111 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
2116 /* Close the rotation_schedules element. */
2117 ret
= mi_lttng_writer_close_element(writer
);
2119 cmd_ret
= CMD_ERROR
;
2124 lttng_rotation_schedules_destroy(schedules
);
2130 * Find the session with session_name as name
2131 * and print his informations.
2133 static int mi_list_session(const char *session_name
,
2134 struct lttng_session
*sessions
, int count
)
2137 unsigned int session_found
= 0;
2139 if (session_name
== NULL
) {
2140 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2144 for (i
= 0; i
< count
; i
++) {
2145 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2146 /* We need to leave it open to append other informations
2147 * like domain, channel, events etc.*/
2149 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
2157 if (!session_found
) {
2158 ERR("Session '%s' not found", session_name
);
2159 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2169 * List all availables session
2171 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
2175 /* Opening sessions element */
2176 ret
= mi_lttng_sessions_open(writer
);
2181 /* Listing sessions */
2182 for (i
= 0; i
< count
; i
++) {
2183 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
2189 /* Closing sessions element */
2190 ret
= mi_lttng_writer_close_element(writer
);
2200 * List available tracing session. List only basic information.
2202 * If session_name is NULL, all sessions are listed.
2204 static int list_sessions(const char *session_name
)
2206 int ret
= CMD_SUCCESS
;
2208 unsigned int session_found
= 0;
2209 struct lttng_session
*sessions
= NULL
;
2211 count
= lttng_list_sessions(&sessions
);
2212 DBG("Session count %d", count
);
2215 ERR("%s", lttng_strerror(count
));
2221 if (session_name
== NULL
) {
2222 /* List all sessions */
2223 ret
= mi_list_sessions(sessions
, count
);
2225 /* Note : this return an open session element */
2226 ret
= mi_list_session(session_name
, sessions
, count
);
2235 MSG("Currently no available tracing session");
2239 if (session_name
== NULL
) {
2240 MSG("Available tracing sessions:");
2243 for (i
= 0; i
< count
; i
++) {
2244 if (session_name
!= NULL
) {
2245 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2247 MSG("Tracing session %s: [%s%s]", session_name
,
2248 active_string(sessions
[i
].enabled
),
2249 snapshot_string(sessions
[i
].snapshot_mode
));
2250 if (*sessions
[i
].path
) {
2251 MSG("%sTrace output: %s\n", indent4
, sessions
[i
].path
);
2253 memcpy(&listed_session
, &sessions
[i
],
2254 sizeof(listed_session
));
2258 MSG(" %d) %s [%s%s]", i
+ 1,
2260 active_string(sessions
[i
].enabled
),
2261 snapshot_string(sessions
[i
].snapshot_mode
));
2262 if (*sessions
[i
].path
) {
2263 MSG("%sTrace output: %s", indent4
, sessions
[i
].path
);
2265 if (sessions
[i
].live_timer_interval
!= 0) {
2266 MSG("%sLive timer interval: %u %s", indent4
,
2267 sessions
[i
].live_timer_interval
,
2274 if (!session_found
&& session_name
!= NULL
) {
2275 ERR("Session '%s' not found", session_name
);
2280 if (session_name
== NULL
) {
2281 MSG("\nUse lttng list <session_name> for more details");
2293 * list available domain(s) for a session.
2295 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
2298 /* Open domains element */
2299 ret
= mi_lttng_domains_open(writer
);
2304 for (i
= 0; i
< count
; i
++) {
2305 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
2311 /* Closing domains element */
2312 ret
= mi_lttng_writer_close_element(writer
);
2321 * List available domain(s) for a session.
2323 static int list_domains(const char *session_name
)
2325 int i
, count
, ret
= CMD_SUCCESS
;
2326 struct lttng_domain
*domains
= NULL
;
2329 count
= lttng_list_domains(session_name
, &domains
);
2332 ERR("%s", lttng_strerror(count
));
2338 ret
= mi_list_domains(domains
, count
);
2345 MSG("Domains:\n-------------");
2351 for (i
= 0; i
< count
; i
++) {
2352 switch (domains
[i
].type
) {
2353 case LTTNG_DOMAIN_KERNEL
:
2356 case LTTNG_DOMAIN_UST
:
2357 MSG(" - UST global");
2359 case LTTNG_DOMAIN_JUL
:
2360 MSG(" - JUL (Java Util Logging)");
2362 case LTTNG_DOMAIN_LOG4J
:
2363 MSG(" - LOG4j (Logging for Java)");
2365 case LTTNG_DOMAIN_PYTHON
:
2366 MSG(" - Python (logging)");
2382 * The 'list <options>' first level command
2384 int cmd_list(int argc
, const char **argv
)
2386 int opt
, ret
= CMD_SUCCESS
;
2387 const char *session_name
, *leftover
= NULL
;
2388 static poptContext pc
;
2389 struct lttng_domain domain
;
2390 struct lttng_domain
*domains
= NULL
;
2392 memset(&domain
, 0, sizeof(domain
));
2399 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2400 poptReadDefaultConfig(pc
, 0);
2402 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2410 case OPT_LIST_OPTIONS
:
2411 list_cmd_options(stdout
, long_options
);
2414 ret
= CMD_UNDEFINED
;
2421 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
2427 /* Open command element */
2428 ret
= mi_lttng_writer_command_open(writer
,
2429 mi_lttng_element_command_list
);
2435 /* Open output element */
2436 ret
= mi_lttng_writer_open_element(writer
,
2437 mi_lttng_element_command_output
);
2444 /* Get session name (trailing argument) */
2445 session_name
= poptGetArg(pc
);
2446 DBG2("Session name: %s", session_name
);
2448 leftover
= poptGetArg(pc
);
2450 ERR("Unknown argument: %s", leftover
);
2456 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2457 } else if (opt_userspace
) {
2458 DBG2("Listing userspace global domain");
2459 domain
.type
= LTTNG_DOMAIN_UST
;
2460 } else if (opt_jul
) {
2461 DBG2("Listing JUL domain");
2462 domain
.type
= LTTNG_DOMAIN_JUL
;
2463 } else if (opt_log4j
) {
2464 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2465 } else if (opt_python
) {
2466 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2469 if (!opt_kernel
&& opt_syscall
) {
2470 WARN("--syscall will only work with the Kernel domain (-k)");
2475 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2476 handle
= lttng_create_handle(session_name
, &domain
);
2477 if (handle
== NULL
) {
2483 if (session_name
== NULL
) {
2484 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2486 ret
= list_sessions(NULL
);
2493 ret
= list_syscalls();
2498 ret
= list_kernel_events();
2504 if (opt_userspace
) {
2506 ret
= list_ust_event_fields();
2508 ret
= list_ust_events();
2514 if (opt_jul
|| opt_log4j
|| opt_python
) {
2515 ret
= list_agent_events();
2521 /* List session attributes */
2523 /* Open element sessions
2524 * Present for xml consistency */
2525 ret
= mi_lttng_sessions_open(writer
);
2530 /* MI: the ouptut of list_sessions is an unclosed session element */
2531 ret
= list_sessions(session_name
);
2536 ret
= list_rotate_settings(session_name
);
2541 /* Domain listing */
2543 ret
= list_domains(session_name
);
2547 /* Channel listing */
2548 if (opt_kernel
|| opt_userspace
) {
2550 /* Add of domains and domain element for xml
2551 * consistency and validation
2553 ret
= mi_lttng_domains_open(writer
);
2558 /* Open domain and leave it open for
2559 * nested channels printing */
2560 ret
= mi_lttng_domain(writer
, &domain
, 1);
2569 ret
= list_trackers(&domain
);
2575 ret
= list_channels(opt_channel
);
2580 ret
= list_maps(opt_map
);
2586 /* Close domain and domain element */
2587 ret
= mi_lttng_close_multi_element(writer
, 2);
2597 /* We want all domain(s) */
2598 nb_domain
= lttng_list_domains(session_name
, &domains
);
2599 if (nb_domain
< 0) {
2601 ERR("%s", lttng_strerror(nb_domain
));
2606 ret
= mi_lttng_domains_open(writer
);
2613 for (i
= 0; i
< nb_domain
; i
++) {
2614 switch (domains
[i
].type
) {
2615 case LTTNG_DOMAIN_KERNEL
:
2616 MSG("=== Domain: Linux kernel ===\n");
2618 case LTTNG_DOMAIN_UST
:
2619 MSG("=== Domain: User space ===\n");
2620 MSG("Buffering scheme: %s\n",
2621 domains
[i
].buf_type
==
2622 LTTNG_BUFFER_PER_PID
? "per-process" : "per-user");
2624 case LTTNG_DOMAIN_JUL
:
2625 MSG("=== Domain: java.util.logging (JUL) ===\n");
2627 case LTTNG_DOMAIN_LOG4J
:
2628 MSG("=== Domain: log4j ===\n");
2630 case LTTNG_DOMAIN_PYTHON
:
2631 MSG("=== Domain: Python logging ===\n");
2634 MSG("=== Domain: Unimplemented ===\n");
2639 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
2646 /* Clean handle before creating a new one */
2648 lttng_destroy_handle(handle
);
2651 handle
= lttng_create_handle(session_name
, &domains
[i
]);
2652 if (handle
== NULL
) {
2657 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2658 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2659 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2660 ret
= list_session_agent_events();
2668 switch (domains
[i
].type
) {
2669 case LTTNG_DOMAIN_KERNEL
:
2670 case LTTNG_DOMAIN_UST
:
2671 ret
= list_trackers(&domains
[i
]);
2680 ret
= list_channels(opt_channel
);
2685 ret
= list_maps(opt_map
);
2692 /* Close domain element */
2693 ret
= mi_lttng_writer_close_element(writer
);
2702 /* Close the domains, session and sessions element */
2703 ret
= mi_lttng_close_multi_element(writer
, 3);
2714 /* Close output element */
2715 ret
= mi_lttng_writer_close_element(writer
);
2721 /* Command element close */
2722 ret
= mi_lttng_writer_command_close(writer
);
2730 if (writer
&& mi_lttng_writer_destroy(writer
)) {
2731 /* Preserve original error code */
2732 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2737 lttng_destroy_handle(handle
);
2740 poptFreeContext(pc
);