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
*the_handle
;
52 static struct mi_writer
*the_writer
;
54 /* Only set when listing a single session. */
55 static struct lttng_session the_listed_session
;
57 static struct poptOption long_options
[] = {
58 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
59 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
60 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
61 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
62 {"log4j", 'l', POPT_ARG_VAL
, &opt_log4j
, 1, 0, 0},
63 {"python", 'p', POPT_ARG_VAL
, &opt_python
, 1, 0, 0},
64 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
65 {"channel", 'c', POPT_ARG_STRING
, &opt_channel
, 0, 0, 0},
66 {"domain", 'd', POPT_ARG_VAL
, &opt_domain
, 1, 0, 0},
67 {"fields", 'f', POPT_ARG_VAL
, &opt_fields
, 1, 0, 0},
68 {"syscall", 'S', POPT_ARG_VAL
, &opt_syscall
, 1, 0, 0},
69 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
74 * Get command line from /proc for a specific pid.
76 * On success, return an allocated string pointer to the proc cmdline.
77 * On error, return NULL.
79 static char *get_cmdline_by_pid(pid_t pid
)
84 /* Can't go bigger than /proc/LTTNG_MAX_PID/cmdline */
85 char path
[sizeof("/proc//cmdline") + sizeof(LTTNG_MAX_PID_STR
) - 1];
87 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pid
);
88 fp
= fopen(path
, "r");
93 /* Caller must free() *cmdline */
94 cmdline
= 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",
361 indent6
, event
->name
,
363 event
->loglevel_type
),
364 mi_lttng_loglevel_string(
366 the_handle
->domain
.type
),
368 enabled_string(event
->enabled
),
369 safe_string(exclusion_msg
),
370 safe_string(filter_msg
));
372 MSG("%s%s (type: tracepoint)%s%s%s",
375 enabled_string(event
->enabled
),
376 safe_string(exclusion_msg
),
377 safe_string(filter_msg
));
381 case LTTNG_EVENT_FUNCTION
:
382 MSG("%s%s (type: function)%s%s", indent6
,
383 event
->name
, enabled_string(event
->enabled
),
384 safe_string(filter_msg
));
385 if (event
->attr
.probe
.addr
!= 0) {
386 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
388 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
389 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
392 case LTTNG_EVENT_PROBE
:
393 MSG("%s%s (type: probe)%s%s", indent6
,
394 event
->name
, enabled_string(event
->enabled
),
395 safe_string(filter_msg
));
396 if (event
->attr
.probe
.addr
!= 0) {
397 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
399 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
400 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
403 case LTTNG_EVENT_USERSPACE_PROBE
:
404 print_userspace_probe_location(event
);
406 case LTTNG_EVENT_FUNCTION_ENTRY
:
407 MSG("%s%s (type: function)%s%s", indent6
,
408 event
->name
, enabled_string(event
->enabled
),
409 safe_string(filter_msg
));
410 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
412 case LTTNG_EVENT_SYSCALL
:
413 MSG("%s%s%s%s%s%s", indent6
, event
->name
,
414 (opt_syscall
? "" : " (type:syscall)"),
415 enabled_string(event
->enabled
),
416 bitness_event(event
->flags
),
417 safe_string(filter_msg
));
419 case LTTNG_EVENT_NOOP
:
420 MSG("%s (type: noop)%s%s", indent6
,
421 enabled_string(event
->enabled
),
422 safe_string(filter_msg
));
424 case LTTNG_EVENT_ALL
:
427 /* We should never have "all" events in list. */
436 static const char *field_type(struct lttng_event_field
*field
)
438 switch(field
->type
) {
439 case LTTNG_EVENT_FIELD_INTEGER
:
441 case LTTNG_EVENT_FIELD_ENUM
:
443 case LTTNG_EVENT_FIELD_FLOAT
:
445 case LTTNG_EVENT_FIELD_STRING
:
447 case LTTNG_EVENT_FIELD_OTHER
:
448 default: /* fall-through */
454 * Pretty print single event fields.
456 static void print_event_field(struct lttng_event_field
*field
)
458 if (!field
->field_name
[0]) {
461 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
462 field_type(field
), field
->nowrite
? " [no write]" : "");
467 * Jul and ust event listing
469 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
470 struct lttng_domain
*domain
)
474 char *cmdline
= NULL
;
475 int pid_element_open
= 0;
477 /* Open domains element */
478 ret
= mi_lttng_domains_open(the_writer
);
484 ret
= mi_lttng_domain(the_writer
, domain
, 1);
489 /* Open pids element element */
490 ret
= mi_lttng_pids_open(the_writer
);
495 for (i
= 0; i
< count
; i
++) {
496 if (cur_pid
!= events
[i
].pid
) {
497 if (pid_element_open
) {
498 /* Close the previous events and pid element */
499 ret
= mi_lttng_close_multi_element(
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(the_writer
, cur_pid
, cmdline
,
522 /* Open events element */
523 ret
= mi_lttng_events_open(the_writer
);
528 pid_element_open
= 1;
534 ret
= mi_lttng_event(the_writer
, &events
[i
], 0,
535 the_handle
->domain
.type
);
542 ret
= mi_lttng_writer_close_element(the_writer
);
547 /* Close domain, domains */
548 ret
= mi_lttng_close_multi_element(the_writer
, 2);
556 static int list_agent_events(void)
558 int i
, size
, ret
= CMD_SUCCESS
;
559 struct lttng_domain domain
;
560 struct lttng_handle
*handle
= NULL
;
561 struct lttng_event
*event_list
= NULL
;
563 char *cmdline
= NULL
;
564 const char *agent_domain_str
;
566 memset(&domain
, 0, sizeof(domain
));
568 domain
.type
= LTTNG_DOMAIN_JUL
;
569 } else if (opt_log4j
) {
570 domain
.type
= LTTNG_DOMAIN_LOG4J
;
571 } else if (opt_python
) {
572 domain
.type
= LTTNG_DOMAIN_PYTHON
;
574 ERR("Invalid agent domain selected.");
579 agent_domain_str
= get_domain_str(domain
.type
);
581 DBG("Getting %s tracing events", agent_domain_str
);
583 handle
= lttng_create_handle(NULL
, &domain
);
584 if (handle
== NULL
) {
589 size
= lttng_list_tracepoints(handle
, &event_list
);
591 ERR("Unable to list %s events: %s", agent_domain_str
,
592 lttng_strerror(size
));
599 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
606 MSG("%s events (Logger name):\n-------------------------",
613 for (i
= 0; i
< size
; i
++) {
614 if (cur_pid
!= event_list
[i
].pid
) {
615 cur_pid
= event_list
[i
].pid
;
616 cmdline
= get_cmdline_by_pid(cur_pid
);
617 if (cmdline
== NULL
) {
621 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
624 MSG("%s- %s", indent6
, event_list
[i
].name
);
633 lttng_destroy_handle(handle
);
638 * Ask session daemon for all user space tracepoints available.
640 static int list_ust_events(void)
642 int i
, size
, ret
= CMD_SUCCESS
;
643 struct lttng_domain domain
;
644 struct lttng_handle
*handle
;
645 struct lttng_event
*event_list
= NULL
;
647 char *cmdline
= NULL
;
649 memset(&domain
, 0, sizeof(domain
));
651 DBG("Getting UST tracing events");
653 domain
.type
= LTTNG_DOMAIN_UST
;
655 handle
= lttng_create_handle(NULL
, &domain
);
656 if (handle
== NULL
) {
661 size
= lttng_list_tracepoints(handle
, &event_list
);
663 ERR("Unable to list UST events: %s", lttng_strerror(size
));
670 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
673 MSG("UST events:\n-------------");
679 for (i
= 0; i
< size
; i
++) {
680 if (cur_pid
!= event_list
[i
].pid
) {
681 cur_pid
= event_list
[i
].pid
;
682 cmdline
= get_cmdline_by_pid(cur_pid
);
683 if (cmdline
== NULL
) {
687 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
690 print_events(&event_list
[i
]);
699 lttng_destroy_handle(handle
);
705 * List all ust event with their fields
707 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
708 struct lttng_domain
*domain
)
712 char *cmdline
= NULL
;
713 int pid_element_open
= 0;
714 int event_element_open
= 0;
715 struct lttng_event cur_event
;
717 memset(&cur_event
, 0, sizeof(cur_event
));
719 /* Open domains element */
720 ret
= mi_lttng_domains_open(the_writer
);
726 ret
= mi_lttng_domain(the_writer
, domain
, 1);
731 /* Open pids element */
732 ret
= mi_lttng_pids_open(the_writer
);
737 for (i
= 0; i
< count
; i
++) {
738 if (cur_pid
!= fields
[i
].event
.pid
) {
739 if (pid_element_open
) {
740 if (event_element_open
) {
741 /* Close the previous field element and event. */
742 ret
= mi_lttng_close_multi_element(
747 event_element_open
= 0;
749 /* Close the previous events, pid element */
750 ret
= mi_lttng_close_multi_element(
755 pid_element_open
= 0;
758 cur_pid
= fields
[i
].event
.pid
;
759 cmdline
= get_cmdline_by_pid(cur_pid
);
760 if (!pid_element_open
) {
761 /* Open and write a pid element */
762 ret
= mi_lttng_pid(the_writer
, cur_pid
, cmdline
,
768 /* Open events element */
769 ret
= mi_lttng_events_open(the_writer
);
773 pid_element_open
= 1;
776 /* Wipe current event since we are about to print a new PID. */
777 memset(&cur_event
, 0, sizeof(cur_event
));
780 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
781 if (event_element_open
) {
782 /* Close the previous fields element and the previous event */
783 ret
= mi_lttng_close_multi_element(
788 event_element_open
= 0;
791 memcpy(&cur_event
, &fields
[i
].event
,
794 if (!event_element_open
) {
795 /* Open and write the event */
796 ret
= mi_lttng_event(the_writer
, &cur_event
, 1,
797 the_handle
->domain
.type
);
802 /* Open a fields element */
803 ret
= mi_lttng_event_fields_open(the_writer
);
807 event_element_open
= 1;
811 /* Print the event_field */
812 ret
= mi_lttng_event_field(the_writer
, &fields
[i
]);
818 /* Close pids, domain, domains */
819 ret
= mi_lttng_close_multi_element(the_writer
, 3);
828 * Ask session daemon for all user space tracepoint fields available.
830 static int list_ust_event_fields(void)
832 int i
, size
, ret
= CMD_SUCCESS
;
833 struct lttng_domain domain
;
834 struct lttng_handle
*handle
;
835 struct lttng_event_field
*event_field_list
;
837 char *cmdline
= NULL
;
839 struct lttng_event cur_event
;
841 memset(&domain
, 0, sizeof(domain
));
842 memset(&cur_event
, 0, sizeof(cur_event
));
844 DBG("Getting UST tracing event fields");
846 domain
.type
= LTTNG_DOMAIN_UST
;
848 handle
= lttng_create_handle(NULL
, &domain
);
849 if (handle
== NULL
) {
854 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
856 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
863 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
870 MSG("UST events:\n-------------");
876 for (i
= 0; i
< size
; i
++) {
877 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
878 cur_pid
= event_field_list
[i
].event
.pid
;
879 cmdline
= get_cmdline_by_pid(cur_pid
);
880 if (cmdline
== NULL
) {
884 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
886 /* Wipe current event since we are about to print a new PID. */
887 memset(&cur_event
, 0, sizeof(cur_event
));
889 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
890 print_events(&event_field_list
[i
].event
);
891 memcpy(&cur_event
, &event_field_list
[i
].event
,
894 print_event_field(&event_field_list
[i
]);
901 free(event_field_list
);
903 lttng_destroy_handle(handle
);
909 * Print a list of kernel events
911 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
912 struct lttng_domain
*domain
)
916 /* Open domains element */
917 ret
= mi_lttng_domains_open(the_writer
);
923 ret
= mi_lttng_domain(the_writer
, domain
, 1);
929 ret
= mi_lttng_events_open(the_writer
);
934 for (i
= 0; i
< count
; i
++) {
935 ret
= mi_lttng_event(the_writer
, &events
[i
], 0,
936 the_handle
->domain
.type
);
942 /* close events, domain and domains */
943 ret
= mi_lttng_close_multi_element(the_writer
, 3);
953 * Ask for all trace events in the kernel
955 static int list_kernel_events(void)
957 int i
, size
, ret
= CMD_SUCCESS
;
958 struct lttng_domain domain
;
959 struct lttng_handle
*handle
;
960 struct lttng_event
*event_list
;
962 memset(&domain
, 0, sizeof(domain
));
964 DBG("Getting kernel tracing events");
966 domain
.type
= LTTNG_DOMAIN_KERNEL
;
968 handle
= lttng_create_handle(NULL
, &domain
);
969 if (handle
== NULL
) {
974 size
= lttng_list_tracepoints(handle
, &event_list
);
976 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
977 lttng_destroy_handle(handle
);
983 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
989 MSG("Kernel events:\n-------------");
991 for (i
= 0; i
< size
; i
++) {
992 print_events(&event_list
[i
]);
1001 lttng_destroy_handle(handle
);
1005 lttng_destroy_handle(handle
);
1011 * Print a list of system calls.
1013 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
1018 ret
= mi_lttng_events_open(the_writer
);
1023 for (i
= 0; i
< count
; i
++) {
1024 ret
= mi_lttng_event(the_writer
, &events
[i
], 0,
1025 the_handle
->domain
.type
);
1032 ret
= mi_lttng_writer_close_element(the_writer
);
1042 * Ask for kernel system calls.
1044 static int list_syscalls(void)
1046 int i
, size
, ret
= CMD_SUCCESS
;
1047 struct lttng_event
*event_list
;
1049 DBG("Getting kernel system call events");
1051 size
= lttng_list_syscalls(&event_list
);
1053 ERR("Unable to list system calls: %s", lttng_strerror(size
));
1060 ret
= mi_list_syscalls(event_list
, size
);
1066 MSG("System calls:\n-------------");
1068 for (i
= 0; i
< size
; i
++) {
1069 print_events(&event_list
[i
]);
1085 * Print a list of agent events
1087 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
1091 /* Open events element */
1092 ret
= mi_lttng_events_open(the_writer
);
1097 for (i
= 0; i
< count
; i
++) {
1098 ret
= mi_lttng_event(the_writer
, &events
[i
], 0,
1099 the_handle
->domain
.type
);
1105 /* Close events element */
1106 ret
= mi_lttng_writer_close_element(the_writer
);
1113 * List agent events for a specific session using the handle.
1115 * Return CMD_SUCCESS on success else a negative value.
1117 static int list_session_agent_events(void)
1119 int ret
= CMD_SUCCESS
, count
, i
;
1120 struct lttng_event
*events
= NULL
;
1122 count
= lttng_list_events(the_handle
, "", &events
);
1125 ERR("%s", lttng_strerror(count
));
1131 ret
= mi_list_session_agent_events(events
, count
);
1138 MSG("Events (Logger name):\n---------------------");
1140 MSG("%sNone\n", indent6
);
1144 for (i
= 0; i
< count
; i
++) {
1145 const char *filter_str
;
1146 char *filter_msg
= NULL
;
1147 struct lttng_event
*event
= &events
[i
];
1149 ret
= lttng_event_get_filter_expression(event
,
1152 filter_msg
= strdup(" [failed to retrieve filter]");
1153 } else if (filter_str
) {
1154 const char * const filter_fmt
=
1157 filter_msg
= malloc(strlen(filter_str
) +
1158 strlen(filter_fmt
) + 1);
1160 sprintf(filter_msg
, filter_fmt
,
1165 if (event
->loglevel_type
!=
1166 LTTNG_EVENT_LOGLEVEL_ALL
) {
1167 MSG("%s- %s%s (loglevel%s %s)%s", indent4
,
1169 enabled_string(event
->enabled
),
1170 logleveltype_string(
1171 event
->loglevel_type
),
1172 mi_lttng_loglevel_string(
1176 safe_string(filter_msg
));
1178 MSG("%s- %s%s%s", indent4
, event
->name
,
1179 enabled_string(event
->enabled
),
1180 safe_string(filter_msg
));
1196 * print a list of event
1198 static int mi_list_events(struct lttng_event
*events
, int count
)
1202 /* Open events element */
1203 ret
= mi_lttng_events_open(the_writer
);
1208 for (i
= 0; i
< count
; i
++) {
1209 ret
= mi_lttng_event(the_writer
, &events
[i
], 0,
1210 the_handle
->domain
.type
);
1216 /* Close events element */
1217 ret
= mi_lttng_writer_close_element(the_writer
);
1224 * List events of channel of session and domain.
1226 static int list_events(const char *channel_name
)
1228 int ret
= CMD_SUCCESS
, count
, i
;
1229 struct lttng_event
*events
= NULL
;
1231 count
= lttng_list_events(the_handle
, channel_name
, &events
);
1234 ERR("%s", lttng_strerror(count
));
1240 ret
= mi_list_events(events
, count
);
1247 MSG("\n%sRecording event rules:", indent4
);
1249 MSG("%sNone\n", indent6
);
1253 for (i
= 0; i
< count
; i
++) {
1254 print_events(&events
[i
]);
1266 void print_timer(const char *timer_name
, uint32_t space_count
, int64_t value
)
1270 _MSG("%s%s:", indent6
, timer_name
);
1271 for (i
= 0; i
< space_count
; i
++) {
1276 MSG("%" PRId64
" %s", value
, USEC_UNIT
);
1283 * Pretty print channel
1285 static void print_channel(struct lttng_channel
*channel
)
1288 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1289 int64_t blocking_timeout
;
1291 ret
= lttng_channel_get_discarded_event_count(channel
,
1294 ERR("Failed to retrieve discarded event count of channel");
1298 ret
= lttng_channel_get_lost_packet_count(channel
,
1301 ERR("Failed to retrieve lost packet count of channel");
1305 ret
= lttng_channel_get_monitor_timer_interval(channel
,
1306 &monitor_timer_interval
);
1308 ERR("Failed to retrieve monitor interval of channel");
1312 ret
= lttng_channel_get_blocking_timeout(channel
,
1315 ERR("Failed to retrieve blocking timeout of channel");
1319 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1320 MSG("%sAttributes:", indent4
);
1321 MSG("%sEvent-loss mode: %s", indent6
, channel
->attr
.overwrite
? "overwrite" : "discard");
1322 MSG("%sSub-buffer size: %" PRIu64
" bytes", indent6
, channel
->attr
.subbuf_size
);
1323 MSG("%sSub-buffer count: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1325 print_timer("Switch timer", 5, channel
->attr
.switch_timer_interval
);
1326 print_timer("Read timer", 7, channel
->attr
.read_timer_interval
);
1327 print_timer("Monitor timer", 4, monitor_timer_interval
);
1329 if (!channel
->attr
.overwrite
) {
1330 if (blocking_timeout
== -1) {
1331 MSG("%sBlocking timeout: infinite", indent6
);
1333 MSG("%sBlocking timeout: %" PRId64
" %s", indent6
,
1334 blocking_timeout
, USEC_UNIT
);
1338 MSG("%sTrace file count: %" PRIu64
" per stream", indent6
,
1339 channel
->attr
.tracefile_count
== 0 ?
1340 1 : channel
->attr
.tracefile_count
);
1341 if (channel
->attr
.tracefile_size
!= 0 ) {
1342 MSG("%sTrace file size: %" PRIu64
" bytes", indent6
,
1343 channel
->attr
.tracefile_size
);
1345 MSG("%sTrace file size: %s", indent6
, "unlimited");
1347 switch (channel
->attr
.output
) {
1348 case LTTNG_EVENT_SPLICE
:
1349 MSG("%sOutput mode: splice", indent6
);
1351 case LTTNG_EVENT_MMAP
:
1352 MSG("%sOutput mode: mmap", indent6
);
1356 MSG("\n%sStatistics:", indent4
);
1357 if (the_listed_session
.snapshot_mode
) {
1359 * The lost packet count is omitted for sessions in snapshot
1360 * mode as it is misleading: it would indicate the number of
1361 * packets that the consumer could not extract during the
1362 * course of recording the snapshot. It does not have the
1363 * same meaning as the "regular" lost packet count that
1364 * would result from the consumer not keeping up with
1365 * event production in an overwrite-mode channel.
1367 * A more interesting statistic would be the number of
1368 * packets lost between the first and last extracted
1369 * packets of a given snapshot (which prevents most analyses).
1371 MSG("%sNone", indent6
);
1372 goto skip_stats_printing
;
1375 if (!channel
->attr
.overwrite
) {
1376 MSG("%sDiscarded events: %" PRIu64
, indent6
, discarded_events
);
1378 MSG("%sLost packets: %" PRIu64
, indent6
, lost_packets
);
1380 skip_stats_printing
:
1386 * Print a list of channel
1389 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1390 const char *channel_name
)
1393 unsigned int chan_found
= 0;
1395 /* Open channels element */
1396 ret
= mi_lttng_channels_open(the_writer
);
1401 for (i
= 0; i
< count
; i
++) {
1402 if (channel_name
!= NULL
) {
1403 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1410 /* Write channel element and leave it open */
1411 ret
= mi_lttng_channel(the_writer
, &channels
[i
], 1);
1416 /* Listing events per channel */
1417 ret
= list_events(channels
[i
].name
);
1422 /* Closing the channel element we opened earlier */
1423 ret
= mi_lttng_writer_close_element(the_writer
);
1433 /* Close channels element */
1434 ret
= mi_lttng_writer_close_element(the_writer
);
1444 * List channel(s) of session and domain.
1446 * If channel_name is NULL, all channels are listed.
1448 static int list_channels(const char *channel_name
)
1450 int count
, i
, ret
= CMD_SUCCESS
;
1451 unsigned int chan_found
= 0;
1452 struct lttng_channel
*channels
= NULL
;
1454 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1456 count
= lttng_list_channels(the_handle
, &channels
);
1459 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1461 /* When printing mi this is not an error
1462 * but an empty channels element */
1466 goto error_channels
;
1470 /* We had a real error */
1472 ERR("%s", lttng_strerror(count
));
1473 goto error_channels
;
1480 ret
= mi_list_channels(channels
, count
, channel_name
);
1488 MSG("Channels:\n-------------");
1491 for (i
= 0; i
< count
; i
++) {
1492 if (channel_name
!= NULL
) {
1493 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1499 print_channel(&channels
[i
]);
1501 /* Listing events per channel */
1502 ret
= list_events(channels
[i
].name
);
1512 if (!chan_found
&& channel_name
!= NULL
) {
1514 ERR("Channel %s not found", channel_name
);
1525 static const char *get_capitalized_process_attr_str(enum lttng_process_attr process_attr
)
1527 switch (process_attr
) {
1528 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1529 return "Process ID";
1530 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1531 return "Virtual process ID";
1532 case LTTNG_PROCESS_ATTR_USER_ID
:
1534 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1535 return "Virtual user ID";
1536 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1538 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1539 return "Virtual group ID";
1546 static int handle_process_attr_status(enum lttng_process_attr process_attr
,
1547 enum lttng_process_attr_tracker_handle_status status
)
1549 int ret
= CMD_SUCCESS
;
1552 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID_TRACKING_POLICY
:
1553 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK
:
1556 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR
:
1557 ERR("Communication occurred while fetching %s tracker",
1558 lttng_process_attr_to_string(process_attr
));
1561 case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_SESSION_DOES_NOT_EXIST
:
1562 ERR("Failed to get the inclusion set of the %s tracker: session `%s` no longer exists",
1563 lttng_process_attr_to_string(process_attr
),
1564 the_handle
->session_name
);
1568 ERR("Unknown error occurred while fetching the inclusion set of the %s tracker",
1569 lttng_process_attr_to_string(process_attr
));
1577 static int mi_output_empty_tracker(enum lttng_process_attr process_attr
)
1581 ret
= mi_lttng_process_attribute_tracker_open(the_writer
, process_attr
);
1586 ret
= mi_lttng_close_multi_element(the_writer
, 2);
1591 static inline bool is_value_type_name(
1592 enum lttng_process_attr_value_type value_type
)
1594 return value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
||
1595 value_type
== LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
;
1599 * List a process attribute tracker for a session and domain tuple.
1601 static int list_process_attr_tracker(enum lttng_process_attr process_attr
)
1604 unsigned int count
, i
;
1605 enum lttng_tracking_policy policy
;
1606 enum lttng_error_code ret_code
;
1607 enum lttng_process_attr_tracker_handle_status handle_status
;
1608 enum lttng_process_attr_values_status values_status
;
1609 const struct lttng_process_attr_values
*values
;
1610 struct lttng_process_attr_tracker_handle
*tracker_handle
= NULL
;
1612 ret_code
= lttng_session_get_tracker_handle(the_handle
->session_name
,
1613 the_handle
->domain
.type
, process_attr
, &tracker_handle
);
1614 if (ret_code
!= LTTNG_OK
) {
1615 ERR("Failed to get process attribute tracker handle: %s",
1616 lttng_strerror(ret_code
));
1621 handle_status
= lttng_process_attr_tracker_handle_get_inclusion_set(
1622 tracker_handle
, &values
);
1623 ret
= handle_process_attr_status(process_attr
, handle_status
);
1624 if (ret
!= CMD_SUCCESS
) {
1628 handle_status
= lttng_process_attr_tracker_handle_get_tracking_policy(
1629 tracker_handle
, &policy
);
1630 ret
= handle_process_attr_status(process_attr
, handle_status
);
1631 if (ret
!= CMD_SUCCESS
) {
1636 char *process_attr_name
;
1637 const int print_ret
= asprintf(&process_attr_name
, "%ss:",
1638 get_capitalized_process_attr_str(process_attr
));
1640 if (print_ret
== -1) {
1644 _MSG(" %-22s", process_attr_name
);
1645 free(process_attr_name
);
1648 case LTTNG_TRACKING_POLICY_INCLUDE_SET
:
1650 case LTTNG_TRACKING_POLICY_EXCLUDE_ALL
:
1652 mi_output_empty_tracker(process_attr
);
1657 case LTTNG_TRACKING_POLICY_INCLUDE_ALL
:
1662 ERR("Unknown tracking policy encoutered while listing the %s process attribute tracker of session `%s`",
1663 lttng_process_attr_to_string(process_attr
),
1664 the_handle
->session_name
);
1669 values_status
= lttng_process_attr_values_get_count(values
, &count
);
1670 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1671 ERR("Failed to get the count of values in the inclusion set of the %s process attribute tracker of session `%s`",
1672 lttng_process_attr_to_string(process_attr
),
1673 the_handle
->session_name
);
1679 /* Functionally equivalent to the 'exclude all' policy. */
1681 mi_output_empty_tracker(process_attr
);
1688 /* Mi tracker_id element */
1690 /* Open tracker_id and targets elements */
1691 ret
= mi_lttng_process_attribute_tracker_open(
1692 the_writer
, process_attr
);
1698 for (i
= 0; i
< count
; i
++) {
1699 const enum lttng_process_attr_value_type value_type
=
1700 lttng_process_attr_values_get_type_at_index(
1702 int64_t integral_value
= INT64_MAX
;
1703 const char *name
= "error";
1708 switch (value_type
) {
1709 case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID
:
1713 values_status
= lttng_process_attr_values_get_pid_at_index(
1715 integral_value
= (int64_t) pid
;
1718 case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID
:
1722 values_status
= lttng_process_attr_values_get_uid_at_index(
1724 integral_value
= (int64_t) uid
;
1727 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID
:
1731 values_status
= lttng_process_attr_values_get_gid_at_index(
1733 integral_value
= (int64_t) gid
;
1736 case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME
:
1737 values_status
= lttng_process_attr_values_get_user_name_at_index(
1740 case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME
:
1741 values_status
= lttng_process_attr_values_get_group_name_at_index(
1749 if (values_status
!= LTTNG_PROCESS_ATTR_VALUES_STATUS_OK
) {
1751 * Not possible given the current liblttng-ctl
1754 ERR("Unknown error occurred while fetching process attribute value in inclusion list");
1759 if (is_value_type_name(value_type
)) {
1762 _MSG("%" PRIi64
, integral_value
);
1767 ret
= is_value_type_name(value_type
) ?
1768 mi_lttng_string_process_attribute_value(
1772 mi_lttng_integral_process_attribute_value(
1775 integral_value
, false);
1783 /* Mi close tracker_id and targets */
1785 ret
= mi_lttng_close_multi_element(the_writer
, 2);
1791 lttng_process_attr_tracker_handle_destroy(tracker_handle
);
1796 * List all trackers of a domain
1798 static int list_trackers(const struct lttng_domain
*domain
)
1802 MSG("Tracked process attributes");
1803 /* Trackers listing */
1805 ret
= mi_lttng_trackers_open(the_writer
);
1811 switch (domain
->type
) {
1812 case LTTNG_DOMAIN_KERNEL
:
1814 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_PROCESS_ID
);
1819 ret
= list_process_attr_tracker(
1820 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1825 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_USER_ID
);
1830 ret
= list_process_attr_tracker(
1831 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1836 ret
= list_process_attr_tracker(LTTNG_PROCESS_ATTR_GROUP_ID
);
1841 ret
= list_process_attr_tracker(
1842 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1847 case LTTNG_DOMAIN_UST
:
1849 ret
= list_process_attr_tracker(
1850 LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
);
1855 ret
= list_process_attr_tracker(
1856 LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
);
1861 ret
= list_process_attr_tracker(
1862 LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
);
1872 /* Close trackers element */
1873 ret
= mi_lttng_writer_close_element(the_writer
);
1883 static enum cmd_error_code
print_periodic_rotation_schedule(
1884 const struct lttng_rotation_schedule
*schedule
)
1886 enum cmd_error_code ret
;
1887 enum lttng_rotation_status status
;
1890 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
1892 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1893 ERR("Failed to retrieve period parameter from periodic rotation schedule.");
1898 MSG(" timer period: %" PRIu64
" %s", value
, USEC_UNIT
);
1904 static enum cmd_error_code
print_size_threshold_rotation_schedule(
1905 const struct lttng_rotation_schedule
*schedule
)
1907 enum cmd_error_code ret
;
1908 enum lttng_rotation_status status
;
1911 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
,
1913 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1914 ERR("Failed to retrieve size parameter from size-based rotation schedule.");
1919 MSG(" size threshold: %" PRIu64
" bytes", value
);
1925 static enum cmd_error_code
print_rotation_schedule(
1926 const struct lttng_rotation_schedule
*schedule
)
1928 enum cmd_error_code ret
;
1930 switch (lttng_rotation_schedule_get_type(schedule
)) {
1931 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
1932 ret
= print_size_threshold_rotation_schedule(schedule
);
1934 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
1935 ret
= print_periodic_rotation_schedule(schedule
);
1944 * List the automatic rotation settings.
1946 static enum cmd_error_code
list_rotate_settings(const char *session_name
)
1949 enum cmd_error_code cmd_ret
= CMD_SUCCESS
;
1950 unsigned int count
, i
;
1951 struct lttng_rotation_schedules
*schedules
= NULL
;
1952 enum lttng_rotation_status status
;
1954 ret
= lttng_session_list_rotation_schedules(session_name
, &schedules
);
1955 if (ret
!= LTTNG_OK
) {
1956 ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret
));
1957 cmd_ret
= CMD_ERROR
;
1961 status
= lttng_rotation_schedules_get_count(schedules
, &count
);
1962 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
1963 ERR("Failed to retrieve the number of session rotation schedules.");
1964 cmd_ret
= CMD_ERROR
;
1969 cmd_ret
= CMD_SUCCESS
;
1973 MSG("Automatic rotation schedules:");
1975 ret
= mi_lttng_writer_open_element(the_writer
,
1976 mi_lttng_element_rotation_schedules
);
1978 cmd_ret
= CMD_ERROR
;
1983 for (i
= 0; i
< count
; i
++) {
1984 enum cmd_error_code tmp_ret
= CMD_SUCCESS
;
1985 const struct lttng_rotation_schedule
*schedule
;
1987 schedule
= lttng_rotation_schedules_get_at_index(schedules
, i
);
1989 ERR("Failed to retrieve session rotation schedule.");
1990 cmd_ret
= CMD_ERROR
;
1995 ret
= mi_lttng_rotation_schedule(the_writer
, schedule
);
1997 tmp_ret
= CMD_ERROR
;
2000 tmp_ret
= print_rotation_schedule(schedule
);
2004 * Report an error if the serialization of any of the
2005 * descriptors failed.
2007 cmd_ret
= cmd_ret
? cmd_ret
: tmp_ret
;
2012 /* Close the rotation_schedules element. */
2013 ret
= mi_lttng_writer_close_element(the_writer
);
2015 cmd_ret
= CMD_ERROR
;
2020 lttng_rotation_schedules_destroy(schedules
);
2026 * Find the session with session_name as name
2027 * and print his informations.
2029 static int mi_list_session(const char *session_name
,
2030 struct lttng_session
*sessions
, int count
)
2033 unsigned int session_found
= 0;
2035 if (session_name
== NULL
) {
2036 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2040 for (i
= 0; i
< count
; i
++) {
2041 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2042 /* We need to leave it open to append other informations
2043 * like domain, channel, events etc.*/
2045 ret
= mi_lttng_session(the_writer
, &sessions
[i
], 1);
2053 if (!session_found
) {
2054 ERR("Session '%s' not found", session_name
);
2055 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
2065 * List all availables session
2067 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
2071 /* Opening sessions element */
2072 ret
= mi_lttng_sessions_open(the_writer
);
2077 /* Listing sessions */
2078 for (i
= 0; i
< count
; i
++) {
2079 ret
= mi_lttng_session(the_writer
, &sessions
[i
], 0);
2085 /* Closing sessions element */
2086 ret
= mi_lttng_writer_close_element(the_writer
);
2096 * List available tracing session. List only basic information.
2098 * If session_name is NULL, all sessions are listed.
2100 static int list_sessions(const char *session_name
)
2102 int ret
= CMD_SUCCESS
;
2104 unsigned int session_found
= 0;
2105 struct lttng_session
*sessions
= NULL
;
2107 count
= lttng_list_sessions(&sessions
);
2108 DBG("Session count %d", count
);
2111 ERR("%s", lttng_strerror(count
));
2117 if (session_name
== NULL
) {
2118 /* List all sessions */
2119 ret
= mi_list_sessions(sessions
, count
);
2121 /* Note : this return an open session element */
2122 ret
= mi_list_session(session_name
, sessions
, count
);
2131 MSG("Currently no available tracing session");
2135 if (session_name
== NULL
) {
2136 MSG("Available tracing sessions:");
2139 for (i
= 0; i
< count
; i
++) {
2140 if (session_name
!= NULL
) {
2141 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
2143 MSG("Tracing session %s: [%s%s]", session_name
,
2144 active_string(sessions
[i
].enabled
),
2145 snapshot_string(sessions
[i
].snapshot_mode
));
2146 if (*sessions
[i
].path
) {
2147 MSG("%sTrace output: %s\n", indent4
, sessions
[i
].path
);
2149 memcpy(&the_listed_session
,
2151 sizeof(the_listed_session
));
2155 MSG(" %d) %s [%s%s]", i
+ 1,
2157 active_string(sessions
[i
].enabled
),
2158 snapshot_string(sessions
[i
].snapshot_mode
));
2159 if (*sessions
[i
].path
) {
2160 MSG("%sTrace output: %s", indent4
, sessions
[i
].path
);
2162 if (sessions
[i
].live_timer_interval
!= 0) {
2163 MSG("%sLive timer interval: %u %s", indent4
,
2164 sessions
[i
].live_timer_interval
,
2171 if (!session_found
&& session_name
!= NULL
) {
2172 ERR("Session '%s' not found", session_name
);
2177 if (session_name
== NULL
) {
2178 MSG("\nUse lttng list <session_name> for more details");
2190 * list available domain(s) for a session.
2192 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
2195 /* Open domains element */
2196 ret
= mi_lttng_domains_open(the_writer
);
2201 for (i
= 0; i
< count
; i
++) {
2202 ret
= mi_lttng_domain(the_writer
, &domains
[i
], 0);
2208 /* Closing domains element */
2209 ret
= mi_lttng_writer_close_element(the_writer
);
2218 * List available domain(s) for a session.
2220 static int list_domains(const char *session_name
)
2222 int i
, count
, ret
= CMD_SUCCESS
;
2223 struct lttng_domain
*domains
= NULL
;
2226 count
= lttng_list_domains(session_name
, &domains
);
2229 ERR("%s", lttng_strerror(count
));
2235 ret
= mi_list_domains(domains
, count
);
2242 MSG("Domains:\n-------------");
2248 for (i
= 0; i
< count
; i
++) {
2249 switch (domains
[i
].type
) {
2250 case LTTNG_DOMAIN_KERNEL
:
2253 case LTTNG_DOMAIN_UST
:
2254 MSG(" - UST global");
2256 case LTTNG_DOMAIN_JUL
:
2257 MSG(" - JUL (Java Util Logging)");
2259 case LTTNG_DOMAIN_LOG4J
:
2260 MSG(" - LOG4j (Logging for Java)");
2262 case LTTNG_DOMAIN_PYTHON
:
2263 MSG(" - Python (logging)");
2279 * The 'list <options>' first level command
2281 int cmd_list(int argc
, const char **argv
)
2283 int opt
, ret
= CMD_SUCCESS
;
2284 const char *session_name
, *leftover
= NULL
;
2285 static poptContext pc
;
2286 struct lttng_domain domain
;
2287 struct lttng_domain
*domains
= NULL
;
2289 memset(&domain
, 0, sizeof(domain
));
2296 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
2297 poptReadDefaultConfig(pc
, 0);
2299 while ((opt
= poptGetNextOpt(pc
)) != -1) {
2307 case OPT_LIST_OPTIONS
:
2308 list_cmd_options(stdout
, long_options
);
2311 ret
= CMD_UNDEFINED
;
2318 the_writer
= mi_lttng_writer_create(
2319 fileno(stdout
), lttng_opt_mi
);
2325 /* Open command element */
2326 ret
= mi_lttng_writer_command_open(
2327 the_writer
, mi_lttng_element_command_list
);
2333 /* Open output element */
2334 ret
= mi_lttng_writer_open_element(
2335 the_writer
, mi_lttng_element_command_output
);
2342 /* Get session name (trailing argument) */
2343 session_name
= poptGetArg(pc
);
2344 DBG2("Session name: %s", session_name
);
2346 leftover
= poptGetArg(pc
);
2348 ERR("Unknown argument: %s", leftover
);
2354 domain
.type
= LTTNG_DOMAIN_KERNEL
;
2355 } else if (opt_userspace
) {
2356 DBG2("Listing userspace global domain");
2357 domain
.type
= LTTNG_DOMAIN_UST
;
2358 } else if (opt_jul
) {
2359 DBG2("Listing JUL domain");
2360 domain
.type
= LTTNG_DOMAIN_JUL
;
2361 } else if (opt_log4j
) {
2362 domain
.type
= LTTNG_DOMAIN_LOG4J
;
2363 } else if (opt_python
) {
2364 domain
.type
= LTTNG_DOMAIN_PYTHON
;
2367 if (!opt_kernel
&& opt_syscall
) {
2368 WARN("--syscall will only work with the Kernel domain (-k)");
2373 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
2374 the_handle
= lttng_create_handle(session_name
, &domain
);
2375 if (the_handle
== NULL
) {
2381 if (session_name
== NULL
) {
2382 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
2384 ret
= list_sessions(NULL
);
2391 ret
= list_syscalls();
2396 ret
= list_kernel_events();
2402 if (opt_userspace
) {
2404 ret
= list_ust_event_fields();
2406 ret
= list_ust_events();
2412 if (opt_jul
|| opt_log4j
|| opt_python
) {
2413 ret
= list_agent_events();
2419 /* List session attributes */
2421 /* Open element sessions
2422 * Present for xml consistency */
2423 ret
= mi_lttng_sessions_open(the_writer
);
2428 /* MI: the ouptut of list_sessions is an unclosed session element */
2429 ret
= list_sessions(session_name
);
2434 ret
= list_rotate_settings(session_name
);
2439 /* Domain listing */
2441 ret
= list_domains(session_name
);
2445 /* Channel listing */
2446 if (opt_kernel
|| opt_userspace
) {
2448 /* Add of domains and domain element for xml
2449 * consistency and validation
2451 ret
= mi_lttng_domains_open(the_writer
);
2456 /* Open domain and leave it open for
2457 * nested channels printing */
2458 ret
= mi_lttng_domain(the_writer
, &domain
, 1);
2467 ret
= list_trackers(&domain
);
2473 ret
= list_channels(opt_channel
);
2479 /* Close domain and domain element */
2480 ret
= mi_lttng_close_multi_element(
2491 /* We want all domain(s) */
2492 nb_domain
= lttng_list_domains(session_name
, &domains
);
2493 if (nb_domain
< 0) {
2495 ERR("%s", lttng_strerror(nb_domain
));
2500 ret
= mi_lttng_domains_open(the_writer
);
2507 for (i
= 0; i
< nb_domain
; i
++) {
2508 switch (domains
[i
].type
) {
2509 case LTTNG_DOMAIN_KERNEL
:
2510 MSG("=== Domain: Linux kernel ===\n");
2512 case LTTNG_DOMAIN_UST
:
2513 MSG("=== Domain: User space ===\n");
2514 MSG("Buffering scheme: %s\n",
2515 domains
[i
].buf_type
==
2516 LTTNG_BUFFER_PER_PID
? "per-process" : "per-user");
2518 case LTTNG_DOMAIN_JUL
:
2519 MSG("=== Domain: java.util.logging (JUL) ===\n");
2521 case LTTNG_DOMAIN_LOG4J
:
2522 MSG("=== Domain: log4j ===\n");
2524 case LTTNG_DOMAIN_PYTHON
:
2525 MSG("=== Domain: Python logging ===\n");
2528 MSG("=== Domain: Unimplemented ===\n");
2533 ret
= mi_lttng_domain(the_writer
,
2541 /* Clean handle before creating a new one */
2543 lttng_destroy_handle(the_handle
);
2546 the_handle
= lttng_create_handle(
2547 session_name
, &domains
[i
]);
2548 if (the_handle
== NULL
) {
2553 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
2554 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
2555 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
2556 ret
= list_session_agent_events();
2564 switch (domains
[i
].type
) {
2565 case LTTNG_DOMAIN_KERNEL
:
2566 case LTTNG_DOMAIN_UST
:
2567 ret
= list_trackers(&domains
[i
]);
2576 ret
= list_channels(opt_channel
);
2583 /* Close domain element */
2584 ret
= mi_lttng_writer_close_element(
2594 /* Close the domains, session and sessions element */
2595 ret
= mi_lttng_close_multi_element(
2607 /* Close output element */
2608 ret
= mi_lttng_writer_close_element(the_writer
);
2614 /* Command element close */
2615 ret
= mi_lttng_writer_command_close(the_writer
);
2623 if (the_writer
&& mi_lttng_writer_destroy(the_writer
)) {
2624 /* Preserve original error code */
2625 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
2630 lttng_destroy_handle(the_handle
);
2633 poptFreeContext(pc
);