2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <common/mi-lttng.h>
28 #include "../command.h"
30 static int opt_userspace
;
31 static int opt_kernel
;
34 static char *opt_channel
;
35 static int opt_domain
;
36 static int opt_fields
;
37 static int opt_syscall
;
39 /* Not implemented yet */
40 static char *opt_cmd_name
;
44 const char *indent4
= " ";
45 const char *indent6
= " ";
46 const char *indent8
= " ";
54 static struct lttng_handle
*handle
;
55 static struct mi_writer
*writer
;
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},
64 /* Not implemented yet */
65 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
66 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
68 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
70 {"channel", 'c', POPT_ARG_STRING
, &opt_channel
, 0, 0, 0},
71 {"domain", 'd', POPT_ARG_VAL
, &opt_domain
, 1, 0, 0},
72 {"fields", 'f', POPT_ARG_VAL
, &opt_fields
, 1, 0, 0},
73 {"syscall", 'S', POPT_ARG_VAL
, &opt_syscall
, 1, 0, 0},
74 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
81 static void usage(FILE *ofp
)
83 fprintf(ofp
, "usage: lttng list [OPTIONS] [SESSION [SESSION OPTIONS]]\n");
85 fprintf(ofp
, "With no arguments, list available tracing session(s)\n");
87 fprintf(ofp
, "Without a session, -k lists available kernel events\n");
88 fprintf(ofp
, "Without a session, -u lists available userspace events\n");
90 fprintf(ofp
, " -h, --help Show this help\n");
91 fprintf(ofp
, " --list-options Simple listing of options\n");
92 fprintf(ofp
, " -k, --kernel Select kernel domain\n");
93 fprintf(ofp
, " -u, --userspace Select user-space domain.\n");
94 fprintf(ofp
, " -j, --jul Apply for Java application using JUL\n");
95 fprintf(ofp
, " -f, --fields List event fields.\n");
96 fprintf(ofp
, " --syscall List available system calls.\n");
98 fprintf(ofp
, " -p, --pid PID List user-space events by PID\n");
101 fprintf(ofp
, "Session Options:\n");
102 fprintf(ofp
, " -c, --channel NAME List details of a channel\n");
103 fprintf(ofp
, " -d, --domain List available domain(s)\n");
108 * Get command line from /proc for a specific pid.
110 * On success, return an allocated string pointer to the proc cmdline.
111 * On error, return NULL.
113 static char *get_cmdline_by_pid(pid_t pid
)
117 char *cmdline
= NULL
;
118 char path
[20]; /* Can't go bigger than /proc/65535/cmdline */
120 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pid
);
121 fp
= fopen(path
, "r");
126 /* Caller must free() *cmdline */
127 cmdline
= malloc(PATH_MAX
);
129 perror("malloc cmdline");
132 ret
= fread(cmdline
, 1, PATH_MAX
, fp
);
134 perror("fread proc list");
145 const char *active_string(int value
)
148 case 0: return "inactive";
149 case 1: return "active";
151 default: return NULL
;
155 static const char *snapshot_string(int value
)
166 const char *enabled_string(int value
)
169 case 0: return " [disabled]";
170 case 1: return " [enabled]";
172 default: return NULL
;
177 const char *filter_string(int value
)
180 case 1: return " [with filter]";
186 const char *exclusion_string(int value
)
189 case 1: return " [has exclusions]";
194 static const char *logleveltype_string(enum lttng_loglevel_type value
)
197 case LTTNG_EVENT_LOGLEVEL_ALL
:
199 case LTTNG_EVENT_LOGLEVEL_RANGE
:
201 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
204 return " <<TYPE UNKN>>";
208 static const char *bitness_event(enum lttng_event_flag flags
)
210 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_32
) {
211 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
212 return " [32/64-bit]";
216 } else if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
224 * Pretty print single event.
226 static void print_events(struct lttng_event
*event
)
228 switch (event
->type
) {
229 case LTTNG_EVENT_TRACEPOINT
:
231 if (event
->loglevel
!= -1) {
232 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
235 logleveltype_string(event
->loglevel_type
),
236 mi_lttng_loglevel_string(event
->loglevel
),
238 enabled_string(event
->enabled
),
239 exclusion_string(event
->exclusion
),
240 filter_string(event
->filter
));
242 MSG("%s%s (type: tracepoint)%s%s%s",
245 enabled_string(event
->enabled
),
246 exclusion_string(event
->exclusion
),
247 filter_string(event
->filter
));
251 case LTTNG_EVENT_FUNCTION
:
252 MSG("%s%s (type: function)%s%s", indent6
,
253 event
->name
, enabled_string(event
->enabled
),
254 filter_string(event
->filter
));
255 if (event
->attr
.probe
.addr
!= 0) {
256 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
258 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
259 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
262 case LTTNG_EVENT_PROBE
:
263 MSG("%s%s (type: probe)%s%s", indent6
,
264 event
->name
, enabled_string(event
->enabled
),
265 filter_string(event
->filter
));
266 if (event
->attr
.probe
.addr
!= 0) {
267 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
269 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
270 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
273 case LTTNG_EVENT_FUNCTION_ENTRY
:
274 MSG("%s%s (type: function)%s%s", indent6
,
275 event
->name
, enabled_string(event
->enabled
),
276 filter_string(event
->filter
));
277 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
279 case LTTNG_EVENT_SYSCALL
:
280 MSG("%s%s%s%s%s", indent6
, event
->name
,
281 (opt_syscall
? "" : " (type:syscall)"),
282 enabled_string(event
->enabled
),
283 bitness_event(event
->flags
));
285 case LTTNG_EVENT_NOOP
:
286 MSG("%s (type: noop)%s%s", indent6
,
287 enabled_string(event
->enabled
),
288 filter_string(event
->filter
));
290 case LTTNG_EVENT_ALL
:
291 /* We should never have "all" events in list. */
297 static const char *field_type(struct lttng_event_field
*field
)
299 switch(field
->type
) {
300 case LTTNG_EVENT_FIELD_INTEGER
:
302 case LTTNG_EVENT_FIELD_ENUM
:
304 case LTTNG_EVENT_FIELD_FLOAT
:
306 case LTTNG_EVENT_FIELD_STRING
:
308 case LTTNG_EVENT_FIELD_OTHER
:
309 default: /* fall-through */
315 * Pretty print single event fields.
317 static void print_event_field(struct lttng_event_field
*field
)
319 if (!field
->field_name
[0]) {
322 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
323 field_type(field
), field
->nowrite
? " [no write]" : "");
328 * Jul and ust event listing
330 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
331 struct lttng_domain
*domain
)
335 char *cmdline
= NULL
;
336 int pid_element_open
= 0;
338 /* Open domains element */
339 ret
= mi_lttng_domains_open(writer
);
345 ret
= mi_lttng_domain(writer
, domain
, 1);
350 /* Open pids element */
351 ret
= mi_lttng_pids_open(writer
);
356 for (i
= 0; i
< count
; i
++) {
357 if (cur_pid
!= events
[i
].pid
) {
358 if (pid_element_open
) {
359 /* Close the previous events and pid element */
360 ret
= mi_lttng_close_multi_element(writer
, 2);
364 pid_element_open
= 0;
367 cur_pid
= events
[i
].pid
;
368 cmdline
= get_cmdline_by_pid(cur_pid
);
374 if (!pid_element_open
) {
375 /* Open and write a pid element */
376 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
381 /* Open events element */
382 ret
= mi_lttng_events_open(writer
);
387 pid_element_open
= 1;
393 ret
= mi_lttng_event(writer
, &events
[i
], 0);
400 ret
= mi_lttng_writer_close_element(writer
);
405 /* Close domain, domains */
406 ret
= mi_lttng_close_multi_element(writer
, 2);
414 static int list_agent_events(void)
416 int i
, size
, ret
= CMD_SUCCESS
;
417 struct lttng_domain domain
;
418 struct lttng_handle
*handle
;
419 struct lttng_event
*event_list
;
421 char *cmdline
= NULL
;
422 const char *agent_domain_str
;
424 memset(&domain
, 0, sizeof(domain
));
426 domain
.type
= LTTNG_DOMAIN_JUL
;
427 } else if (opt_log4j
) {
428 domain
.type
= LTTNG_DOMAIN_LOG4J
;
431 agent_domain_str
= get_domain_str(domain
.type
);
433 DBG("Getting %s tracing events", agent_domain_str
);
435 handle
= lttng_create_handle(NULL
, &domain
);
436 if (handle
== NULL
) {
441 size
= lttng_list_tracepoints(handle
, &event_list
);
443 ERR("Unable to list %s events: %s", agent_domain_str
,
444 lttng_strerror(size
));
451 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
458 MSG("%s events (Logger name):\n-------------------------",
465 for (i
= 0; i
< size
; i
++) {
466 if (cur_pid
!= event_list
[i
].pid
) {
467 cur_pid
= event_list
[i
].pid
;
468 cmdline
= get_cmdline_by_pid(cur_pid
);
469 if (cmdline
== NULL
) {
473 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
476 MSG("%s- %s", indent6
, event_list
[i
].name
);
485 lttng_destroy_handle(handle
);
490 * Ask session daemon for all user space tracepoints available.
492 static int list_ust_events(void)
494 int i
, size
, ret
= CMD_SUCCESS
;
495 struct lttng_domain domain
;
496 struct lttng_handle
*handle
;
497 struct lttng_event
*event_list
;
499 char *cmdline
= NULL
;
501 memset(&domain
, 0, sizeof(domain
));
503 DBG("Getting UST tracing events");
505 domain
.type
= LTTNG_DOMAIN_UST
;
507 handle
= lttng_create_handle(NULL
, &domain
);
508 if (handle
== NULL
) {
513 size
= lttng_list_tracepoints(handle
, &event_list
);
515 ERR("Unable to list UST events: %s", lttng_strerror(size
));
522 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
525 MSG("UST events:\n-------------");
531 for (i
= 0; i
< size
; i
++) {
532 if (cur_pid
!= event_list
[i
].pid
) {
533 cur_pid
= event_list
[i
].pid
;
534 cmdline
= get_cmdline_by_pid(cur_pid
);
535 if (cmdline
== NULL
) {
539 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
542 print_events(&event_list
[i
]);
551 lttng_destroy_handle(handle
);
557 * List all ust event with their fields
559 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
560 struct lttng_domain
*domain
)
564 char *cmdline
= NULL
;
565 int pid_element_open
= 0;
566 int event_element_open
= 0;
567 struct lttng_event cur_event
;
569 /* Open domains element */
570 ret
= mi_lttng_domains_open(writer
);
576 ret
= mi_lttng_domain(writer
, domain
, 1);
581 /* Open pids element */
582 ret
= mi_lttng_pids_open(writer
);
587 for (i
= 0; i
< count
; i
++) {
588 if (cur_pid
!= fields
[i
].event
.pid
) {
589 if (pid_element_open
) {
590 if (event_element_open
) {
592 /* Close the previous field element and event. */
593 ret
= mi_lttng_close_multi_element(writer
, 2);
597 event_element_open
= 0;
599 /* Close the previous events, pid element */
600 ret
= mi_lttng_close_multi_element(writer
, 2);
604 pid_element_open
= 0;
607 cur_pid
= fields
[i
].event
.pid
;
608 cmdline
= get_cmdline_by_pid(cur_pid
);
609 if (!pid_element_open
) {
610 /* Open and write a pid element */
611 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
616 /* Open events element */
617 ret
= mi_lttng_events_open(writer
);
621 pid_element_open
= 1;
624 /* Wipe current event since we are about to print a new PID. */
625 memset(&cur_event
, 0, sizeof(cur_event
));
628 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
629 if (event_element_open
) {
630 /* Close the previous fields element and the previous event */
631 ret
= mi_lttng_close_multi_element(writer
, 2);
635 event_element_open
= 0;
638 memcpy(&cur_event
, &fields
[i
].event
,
641 if (!event_element_open
) {
642 /* Open and write the event */
643 ret
= mi_lttng_event(writer
, &cur_event
, 1);
648 /* Open a fields element */
649 ret
= mi_lttng_event_fields_open(writer
);
653 event_element_open
= 1;
657 /* Print the event_field */
658 ret
= mi_lttng_event_field(writer
, &fields
[i
]);
664 /* Close pids, domain, domains */
665 ret
= mi_lttng_close_multi_element(writer
, 3);
674 * Ask session daemon for all user space tracepoint fields available.
676 static int list_ust_event_fields(void)
678 int i
, size
, ret
= CMD_SUCCESS
;
679 struct lttng_domain domain
;
680 struct lttng_handle
*handle
;
681 struct lttng_event_field
*event_field_list
;
683 char *cmdline
= NULL
;
685 struct lttng_event cur_event
;
687 memset(&domain
, 0, sizeof(domain
));
688 memset(&cur_event
, 0, sizeof(cur_event
));
690 DBG("Getting UST tracing event fields");
692 domain
.type
= LTTNG_DOMAIN_UST
;
694 handle
= lttng_create_handle(NULL
, &domain
);
695 if (handle
== NULL
) {
700 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
702 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
709 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
716 MSG("UST events:\n-------------");
722 for (i
= 0; i
< size
; i
++) {
723 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
724 cur_pid
= event_field_list
[i
].event
.pid
;
725 cmdline
= get_cmdline_by_pid(cur_pid
);
726 if (cmdline
== NULL
) {
730 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
732 /* Wipe current event since we are about to print a new PID. */
733 memset(&cur_event
, 0, sizeof(cur_event
));
735 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
736 print_events(&event_field_list
[i
].event
);
737 memcpy(&cur_event
, &event_field_list
[i
].event
,
740 print_event_field(&event_field_list
[i
]);
747 free(event_field_list
);
749 lttng_destroy_handle(handle
);
755 * Print a list of kernel events
757 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
758 struct lttng_domain
*domain
)
762 /* Open domains element */
763 ret
= mi_lttng_domains_open(writer
);
769 ret
= mi_lttng_domain(writer
, domain
, 1);
775 ret
= mi_lttng_events_open(writer
);
780 for (i
= 0; i
< count
; i
++) {
781 ret
= mi_lttng_event(writer
, &events
[i
], 0);
787 /* close events, domain and domains */
788 ret
= mi_lttng_close_multi_element(writer
, 3);
798 * Ask for all trace events in the kernel
800 static int list_kernel_events(void)
802 int i
, size
, ret
= CMD_SUCCESS
;
803 struct lttng_domain domain
;
804 struct lttng_handle
*handle
;
805 struct lttng_event
*event_list
;
807 memset(&domain
, 0, sizeof(domain
));
809 DBG("Getting kernel tracing events");
811 domain
.type
= LTTNG_DOMAIN_KERNEL
;
813 handle
= lttng_create_handle(NULL
, &domain
);
814 if (handle
== NULL
) {
819 size
= lttng_list_tracepoints(handle
, &event_list
);
821 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
822 lttng_destroy_handle(handle
);
828 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
834 MSG("Kernel events:\n-------------");
836 for (i
= 0; i
< size
; i
++) {
837 print_events(&event_list
[i
]);
846 lttng_destroy_handle(handle
);
850 lttng_destroy_handle(handle
);
856 * Print a list of system calls.
858 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
863 ret
= mi_lttng_events_open(writer
);
868 for (i
= 0; i
< count
; i
++) {
869 ret
= mi_lttng_event(writer
, &events
[i
], 0);
876 ret
= mi_lttng_writer_close_element(writer
);
886 * Ask for kernel system calls.
888 static int list_syscalls(void)
890 int i
, size
, ret
= CMD_SUCCESS
;
891 struct lttng_event
*event_list
;
893 DBG("Getting kernel system call events");
895 size
= lttng_list_syscalls(&event_list
);
897 ERR("Unable to list system calls: %s", lttng_strerror(size
));
904 ret
= mi_list_syscalls(event_list
, size
);
910 MSG("System calls:\n-------------");
912 for (i
= 0; i
< size
; i
++) {
913 print_events(&event_list
[i
]);
929 * Print a list of agent events
931 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
935 /* Open events element */
936 ret
= mi_lttng_events_open(writer
);
941 for (i
= 0; i
< count
; i
++) {
942 ret
= mi_lttng_event(writer
, &events
[i
], 0);
948 /* Close events element */
949 ret
= mi_lttng_writer_close_element(writer
);
956 * List agent events for a specific session using the handle.
958 * Return CMD_SUCCESS on success else a negative value.
960 static int list_session_agent_events(void)
962 int ret
= CMD_SUCCESS
, count
, i
;
963 struct lttng_event
*events
= NULL
;
965 count
= lttng_list_events(handle
, "", &events
);
968 ERR("%s", lttng_strerror(count
));
974 ret
= mi_list_session_agent_events(events
, count
);
981 MSG("Events (Logger name):\n---------------------");
983 MSG("%sNone\n", indent6
);
987 for (i
= 0; i
< count
; i
++) {
988 MSG("%s- %s%s (loglevel%s %s)", indent4
, events
[i
].name
,
989 enabled_string(events
[i
].enabled
),
990 logleveltype_string(events
[i
].loglevel_type
),
991 mi_lttng_loglevel_string(events
[i
].loglevel
));
1005 * print a list of event
1007 static int mi_list_events(struct lttng_event
*events
, int count
)
1011 /* Open events element */
1012 ret
= mi_lttng_events_open(writer
);
1017 for (i
= 0; i
< count
; i
++) {
1018 ret
= mi_lttng_event(writer
, &events
[i
], 0);
1024 /* Close events element */
1025 ret
= mi_lttng_writer_close_element(writer
);
1032 * List events of channel of session and domain.
1034 static int list_events(const char *channel_name
)
1036 int ret
= CMD_SUCCESS
, count
, i
;
1037 struct lttng_event
*events
= NULL
;
1039 count
= lttng_list_events(handle
, channel_name
, &events
);
1042 ERR("%s", lttng_strerror(count
));
1048 ret
= mi_list_events(events
, count
);
1055 MSG("\n%sEvents:", indent4
);
1057 MSG("%sNone\n", indent6
);
1061 for (i
= 0; i
< count
; i
++) {
1062 print_events(&events
[i
]);
1074 * Pretty print channel
1076 static void print_channel(struct lttng_channel
*channel
)
1078 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1080 MSG("%sAttributes:", indent4
);
1081 MSG("%soverwrite mode: %d", indent6
, channel
->attr
.overwrite
);
1082 MSG("%ssubbufers size: %" PRIu64
, indent6
, channel
->attr
.subbuf_size
);
1083 MSG("%snumber of subbufers: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1084 MSG("%sswitch timer interval: %u", indent6
, channel
->attr
.switch_timer_interval
);
1085 MSG("%sread timer interval: %u", indent6
, channel
->attr
.read_timer_interval
);
1086 MSG("%strace file count: %" PRIu64
, indent6
, channel
->attr
.tracefile_count
);
1087 MSG("%strace file size (bytes): %" PRIu64
, indent6
, channel
->attr
.tracefile_size
);
1088 switch (channel
->attr
.output
) {
1089 case LTTNG_EVENT_SPLICE
:
1090 MSG("%soutput: splice()", indent6
);
1092 case LTTNG_EVENT_MMAP
:
1093 MSG("%soutput: mmap()", indent6
);
1100 * Print a list of channel
1103 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1104 const char *channel_name
)
1107 unsigned int chan_found
= 0;
1109 /* Open channels element */
1110 ret
= mi_lttng_channels_open(writer
);
1115 for (i
= 0; i
< count
; i
++) {
1116 if (channel_name
!= NULL
) {
1117 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1124 /* Write channel element and leave it open */
1125 ret
= mi_lttng_channel(writer
, &channels
[i
], 1);
1130 /* Listing events per channel */
1131 ret
= list_events(channels
[i
].name
);
1136 /* Closing the channel element we opened earlier */
1137 ret
= mi_lttng_writer_close_element(writer
);
1147 /* Close channels element */
1148 ret
= mi_lttng_writer_close_element(writer
);
1158 * List channel(s) of session and domain.
1160 * If channel_name is NULL, all channels are listed.
1162 static int list_channels(const char *channel_name
)
1164 int count
, i
, ret
= CMD_SUCCESS
;
1165 unsigned int chan_found
= 0;
1166 struct lttng_channel
*channels
= NULL
;
1168 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1170 count
= lttng_list_channels(handle
, &channels
);
1173 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1175 /* When printing mi this is not an error
1176 * but an empty channels element */
1180 WARN("No kernel channel");
1181 goto error_channels
;
1185 /* We had a real error */
1187 ERR("%s", lttng_strerror(count
));
1188 goto error_channels
;
1195 ret
= mi_list_channels(channels
, count
, channel_name
);
1202 if (channel_name
== NULL
) {
1203 MSG("Channels:\n-------------");
1206 for (i
= 0; i
< count
; i
++) {
1207 if (channel_name
!= NULL
) {
1208 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1214 print_channel(&channels
[i
]);
1216 /* Listing events per channel */
1217 ret
= list_events(channels
[i
].name
);
1227 if (!chan_found
&& channel_name
!= NULL
) {
1229 ERR("Channel %s not found", channel_name
);
1242 * Find the session with session_name as name
1243 * and print his informations.
1245 static int mi_list_session(const char *session_name
,
1246 struct lttng_session
*sessions
, int count
)
1249 unsigned int session_found
= 0;
1251 if (session_name
== NULL
) {
1252 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1256 for (i
= 0; i
< count
; i
++) {
1257 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1258 /* We need to leave it open to append other informations
1259 * like domain, channel, events etc.*/
1261 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
1269 if (!session_found
) {
1270 ERR("Session '%s' not found", session_name
);
1271 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1281 * List all availables session
1283 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
1287 /* Opening sessions element */
1288 ret
= mi_lttng_sessions_open(writer
);
1293 /* Listing sessions */
1294 for (i
= 0; i
< count
; i
++) {
1295 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
1301 /* Closing sessions element */
1302 ret
= mi_lttng_writer_close_element(writer
);
1312 * List available tracing session. List only basic information.
1314 * If session_name is NULL, all sessions are listed.
1316 static int list_sessions(const char *session_name
)
1318 int ret
= CMD_SUCCESS
;
1320 unsigned int session_found
= 0;
1321 struct lttng_session
*sessions
;
1323 count
= lttng_list_sessions(&sessions
);
1324 DBG("Session count %d", count
);
1327 ERR("%s", lttng_strerror(count
));
1333 if (session_name
== NULL
) {
1334 /* List all session */
1335 ret
= mi_list_sessions(sessions
, count
);
1337 /* Note : this return an open session element */
1338 ret
= mi_list_session(session_name
, sessions
, count
);
1347 MSG("Currently no available tracing session");
1351 if (session_name
== NULL
) {
1352 MSG("Available tracing sessions:");
1356 for (i
= 0; i
< count
; i
++) {
1357 if (session_name
!= NULL
) {
1358 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1360 MSG("Tracing session %s: [%s%s]", session_name
,
1361 active_string(sessions
[i
].enabled
),
1362 snapshot_string(sessions
[i
].snapshot_mode
));
1363 MSG("%sTrace path: %s\n", indent4
, sessions
[i
].path
);
1367 MSG(" %d) %s (%s) [%s%s]", i
+ 1,
1368 sessions
[i
].name
, sessions
[i
].path
,
1369 active_string(sessions
[i
].enabled
),
1370 snapshot_string(sessions
[i
].snapshot_mode
));
1371 MSG("%sTrace path: %s", indent4
, sessions
[i
].path
);
1372 MSG("%sLive timer interval (usec): %u\n", indent4
,
1373 sessions
[i
].live_timer_interval
);
1377 if (!session_found
&& session_name
!= NULL
) {
1378 ERR("Session '%s' not found", session_name
);
1383 if (session_name
== NULL
) {
1384 MSG("\nUse lttng list <session_name> for more details");
1397 * list available domain(s) for a session.
1399 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
1402 /* Open domains element */
1403 ret
= mi_lttng_domains_open(writer
);
1408 for (i
= 0; i
< count
; i
++) {
1409 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
1415 /* Closing domains element */
1416 ret
= mi_lttng_writer_close_element(writer
);
1425 * List available domain(s) for a session.
1427 static int list_domains(const char *session_name
)
1429 int i
, count
, ret
= CMD_SUCCESS
;
1430 struct lttng_domain
*domains
= NULL
;
1433 count
= lttng_list_domains(session_name
, &domains
);
1436 ERR("%s", lttng_strerror(count
));
1442 ret
= mi_list_domains(domains
, count
);
1449 MSG("Domains:\n-------------");
1455 for (i
= 0; i
< count
; i
++) {
1456 switch (domains
[i
].type
) {
1457 case LTTNG_DOMAIN_KERNEL
:
1460 case LTTNG_DOMAIN_UST
:
1461 MSG(" - UST global");
1463 case LTTNG_DOMAIN_JUL
:
1464 MSG(" - JUL (Java Util Logging)");
1466 case LTTNG_DOMAIN_LOG4J
:
1467 MSG(" - LOG4j (Logging for Java)");
1483 * The 'list <options>' first level command
1485 int cmd_list(int argc
, const char **argv
)
1487 int opt
, ret
= CMD_SUCCESS
;
1488 const char *session_name
;
1489 static poptContext pc
;
1490 struct lttng_domain domain
;
1491 struct lttng_domain
*domains
= NULL
;
1493 memset(&domain
, 0, sizeof(domain
));
1501 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
1502 poptReadDefaultConfig(pc
, 0);
1504 while ((opt
= poptGetNextOpt(pc
)) != -1) {
1512 case OPT_LIST_OPTIONS
:
1513 list_cmd_options(stdout
, long_options
);
1517 ret
= CMD_UNDEFINED
;
1524 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
1530 /* Open command element */
1531 ret
= mi_lttng_writer_command_open(writer
,
1532 mi_lttng_element_command_list
);
1538 /* Open output element */
1539 ret
= mi_lttng_writer_open_element(writer
,
1540 mi_lttng_element_command_output
);
1547 /* Get session name (trailing argument) */
1548 session_name
= poptGetArg(pc
);
1549 DBG2("Session name: %s", session_name
);
1552 domain
.type
= LTTNG_DOMAIN_KERNEL
;
1553 } else if (opt_userspace
) {
1554 DBG2("Listing userspace global domain");
1555 domain
.type
= LTTNG_DOMAIN_UST
;
1556 } else if (opt_jul
) {
1557 DBG2("Listing JUL domain");
1558 domain
.type
= LTTNG_DOMAIN_JUL
;
1559 } else if (opt_log4j
) {
1560 domain
.type
= LTTNG_DOMAIN_LOG4J
;
1563 if (!opt_kernel
&& opt_syscall
) {
1564 WARN("--syscall will only work with the Kernel domain (-k)");
1569 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
) {
1570 handle
= lttng_create_handle(session_name
, &domain
);
1571 if (handle
== NULL
) {
1577 if (session_name
== NULL
) {
1578 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
) {
1579 ret
= list_sessions(NULL
);
1586 ret
= list_syscalls();
1591 ret
= list_kernel_events();
1597 if (opt_userspace
) {
1599 ret
= list_ust_event_fields();
1601 ret
= list_ust_events();
1607 if (opt_jul
|| opt_log4j
) {
1608 ret
= list_agent_events();
1614 /* List session attributes */
1616 /* Open element sessions
1617 * Present for xml consistency */
1618 ret
= mi_lttng_sessions_open(writer
);
1623 /* MI: the ouptut of list_sessions is an unclosed session element */
1624 ret
= list_sessions(session_name
);
1629 /* Domain listing */
1631 ret
= list_domains(session_name
);
1635 /* Channel listing */
1636 if (opt_kernel
|| opt_userspace
) {
1638 /* Add of domains and domain element for xml
1639 * consistency and validation
1641 ret
= mi_lttng_domains_open(writer
);
1646 /* Open domain and leave it open for
1647 * nested channels printing */
1648 ret
= mi_lttng_domain(writer
, &domain
, 1);
1655 ret
= list_channels(opt_channel
);
1661 /* Close domain and domain element */
1662 ret
= mi_lttng_close_multi_element(writer
, 2);
1672 /* We want all domain(s) */
1673 nb_domain
= lttng_list_domains(session_name
, &domains
);
1674 if (nb_domain
< 0) {
1676 ERR("%s", lttng_strerror(nb_domain
));
1681 ret
= mi_lttng_domains_open(writer
);
1688 for (i
= 0; i
< nb_domain
; i
++) {
1689 switch (domains
[i
].type
) {
1690 case LTTNG_DOMAIN_KERNEL
:
1691 MSG("=== Domain: Kernel ===\n");
1693 case LTTNG_DOMAIN_UST
:
1694 MSG("=== Domain: UST global ===\n");
1695 MSG("Buffer type: %s\n",
1696 domains
[i
].buf_type
==
1697 LTTNG_BUFFER_PER_PID
? "per PID" : "per UID");
1699 case LTTNG_DOMAIN_JUL
:
1700 MSG("=== Domain: JUL (Java Util Logging) ===\n");
1702 case LTTNG_DOMAIN_LOG4J
:
1703 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
1706 MSG("=== Domain: Unimplemented ===\n");
1711 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
1718 /* Clean handle before creating a new one */
1720 lttng_destroy_handle(handle
);
1723 handle
= lttng_create_handle(session_name
, &domains
[i
]);
1724 if (handle
== NULL
) {
1729 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
1730 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
) {
1731 ret
= list_session_agent_events();
1738 ret
= list_channels(opt_channel
);
1744 /* Close domain element */
1745 ret
= mi_lttng_writer_close_element(writer
);
1754 /* Close the domains, session and sessions element */
1755 ret
= mi_lttng_close_multi_element(writer
, 3);
1766 /* Close output element */
1767 ret
= mi_lttng_writer_close_element(writer
);
1773 /* Command element close */
1774 ret
= mi_lttng_writer_command_close(writer
);
1782 if (writer
&& mi_lttng_writer_destroy(writer
)) {
1783 /* Preserve original error code */
1784 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
1789 lttng_destroy_handle(handle
);
1792 poptFreeContext(pc
);