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.
27 #include <common/mi-lttng.h>
29 #include "../command.h"
31 static int opt_userspace
;
32 static int opt_kernel
;
35 static int opt_python
;
36 static char *opt_channel
;
37 static int opt_domain
;
38 static int opt_fields
;
39 static int opt_syscall
;
41 /* Not implemented yet */
42 static char *opt_cmd_name
;
46 const char *indent4
= " ";
47 const char *indent6
= " ";
48 const char *indent8
= " ";
56 static struct lttng_handle
*handle
;
57 static struct mi_writer
*writer
;
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},
67 /* Not implemented yet */
68 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
69 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
71 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
73 {"channel", 'c', POPT_ARG_STRING
, &opt_channel
, 0, 0, 0},
74 {"domain", 'd', POPT_ARG_VAL
, &opt_domain
, 1, 0, 0},
75 {"fields", 'f', POPT_ARG_VAL
, &opt_fields
, 1, 0, 0},
76 {"syscall", 'S', POPT_ARG_VAL
, &opt_syscall
, 1, 0, 0},
77 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
84 static void usage(FILE *ofp
)
86 fprintf(ofp
, "usage: lttng list [OPTIONS] [SESSION [SESSION OPTIONS]]\n");
88 fprintf(ofp
, "With no arguments, list available tracing session(s)\n");
90 fprintf(ofp
, "Without a session, -k lists available kernel events\n");
91 fprintf(ofp
, "Without a session, -u lists available userspace events\n");
93 fprintf(ofp
, " -h, --help Show this help\n");
94 fprintf(ofp
, " --list-options Simple listing of options\n");
95 fprintf(ofp
, " -k, --kernel Select kernel domain\n");
96 fprintf(ofp
, " -u, --userspace Select user-space domain.\n");
97 fprintf(ofp
, " -j, --jul Apply for Java application using JUL\n");
98 fprintf(ofp
, " -l, --log4j Apply for Java application using LOG4J\n");
99 fprintf(ofp
, " -p, --python Apply for Python application using logging\n");
100 fprintf(ofp
, " -f, --fields List event fields.\n");
101 fprintf(ofp
, " --syscall List available system calls.\n");
103 fprintf(ofp
, " -p, --pid PID List user-space events by PID\n");
106 fprintf(ofp
, "Session Options:\n");
107 fprintf(ofp
, " -c, --channel NAME List details of a channel\n");
108 fprintf(ofp
, " -d, --domain List available domain(s)\n");
113 * Get command line from /proc for a specific pid.
115 * On success, return an allocated string pointer to the proc cmdline.
116 * On error, return NULL.
118 static char *get_cmdline_by_pid(pid_t pid
)
122 char *cmdline
= NULL
;
123 char path
[20]; /* Can't go bigger than /proc/65535/cmdline */
125 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pid
);
126 fp
= fopen(path
, "r");
131 /* Caller must free() *cmdline */
132 cmdline
= malloc(PATH_MAX
);
134 perror("malloc cmdline");
137 ret
= fread(cmdline
, 1, PATH_MAX
, fp
);
139 perror("fread proc list");
150 const char *active_string(int value
)
153 case 0: return "inactive";
154 case 1: return "active";
156 default: return NULL
;
160 static const char *snapshot_string(int value
)
171 const char *enabled_string(int value
)
174 case 0: return " [disabled]";
175 case 1: return " [enabled]";
177 default: return NULL
;
182 const char *filter_string(int value
)
185 case 1: return " [with filter]";
191 const char *exclusion_string(int value
)
194 case 1: return " [has exclusions]";
199 static const char *logleveltype_string(enum lttng_loglevel_type value
)
202 case LTTNG_EVENT_LOGLEVEL_ALL
:
204 case LTTNG_EVENT_LOGLEVEL_RANGE
:
206 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
209 return " <<TYPE UNKN>>";
213 static const char *bitness_event(enum lttng_event_flag flags
)
215 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_32
) {
216 if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
217 return " [32/64-bit]";
221 } else if (flags
& LTTNG_EVENT_FLAG_SYSCALL_64
) {
229 * Pretty print single event.
231 static void print_events(struct lttng_event
*event
)
233 switch (event
->type
) {
234 case LTTNG_EVENT_TRACEPOINT
:
236 if (event
->loglevel
!= -1) {
237 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
240 logleveltype_string(event
->loglevel_type
),
241 mi_lttng_loglevel_string(event
->loglevel
, handle
->domain
.type
),
243 enabled_string(event
->enabled
),
244 exclusion_string(event
->exclusion
),
245 filter_string(event
->filter
));
247 MSG("%s%s (type: tracepoint)%s%s%s",
250 enabled_string(event
->enabled
),
251 exclusion_string(event
->exclusion
),
252 filter_string(event
->filter
));
256 case LTTNG_EVENT_FUNCTION
:
257 MSG("%s%s (type: function)%s%s", indent6
,
258 event
->name
, enabled_string(event
->enabled
),
259 filter_string(event
->filter
));
260 if (event
->attr
.probe
.addr
!= 0) {
261 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
263 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
264 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
267 case LTTNG_EVENT_PROBE
:
268 MSG("%s%s (type: probe)%s%s", indent6
,
269 event
->name
, enabled_string(event
->enabled
),
270 filter_string(event
->filter
));
271 if (event
->attr
.probe
.addr
!= 0) {
272 MSG("%saddr: 0x%" PRIx64
, indent8
, event
->attr
.probe
.addr
);
274 MSG("%soffset: 0x%" PRIx64
, indent8
, event
->attr
.probe
.offset
);
275 MSG("%ssymbol: %s", indent8
, event
->attr
.probe
.symbol_name
);
278 case LTTNG_EVENT_FUNCTION_ENTRY
:
279 MSG("%s%s (type: function)%s%s", indent6
,
280 event
->name
, enabled_string(event
->enabled
),
281 filter_string(event
->filter
));
282 MSG("%ssymbol: \"%s\"", indent8
, event
->attr
.ftrace
.symbol_name
);
284 case LTTNG_EVENT_SYSCALL
:
285 MSG("%s%s%s%s%s", indent6
, event
->name
,
286 (opt_syscall
? "" : " (type:syscall)"),
287 enabled_string(event
->enabled
),
288 bitness_event(event
->flags
));
290 case LTTNG_EVENT_NOOP
:
291 MSG("%s (type: noop)%s%s", indent6
,
292 enabled_string(event
->enabled
),
293 filter_string(event
->filter
));
295 case LTTNG_EVENT_ALL
:
296 /* We should never have "all" events in list. */
302 static const char *field_type(struct lttng_event_field
*field
)
304 switch(field
->type
) {
305 case LTTNG_EVENT_FIELD_INTEGER
:
307 case LTTNG_EVENT_FIELD_ENUM
:
309 case LTTNG_EVENT_FIELD_FLOAT
:
311 case LTTNG_EVENT_FIELD_STRING
:
313 case LTTNG_EVENT_FIELD_OTHER
:
314 default: /* fall-through */
320 * Pretty print single event fields.
322 static void print_event_field(struct lttng_event_field
*field
)
324 if (!field
->field_name
[0]) {
327 MSG("%sfield: %s (%s)%s", indent8
, field
->field_name
,
328 field_type(field
), field
->nowrite
? " [no write]" : "");
333 * Jul and ust event listing
335 static int mi_list_agent_ust_events(struct lttng_event
*events
, int count
,
336 struct lttng_domain
*domain
)
340 char *cmdline
= NULL
;
341 int pid_element_open
= 0;
343 /* Open domains element */
344 ret
= mi_lttng_domains_open(writer
);
350 ret
= mi_lttng_domain(writer
, domain
, 1);
355 /* Open pids element */
356 ret
= mi_lttng_pids_open(writer
);
361 for (i
= 0; i
< count
; i
++) {
362 if (cur_pid
!= events
[i
].pid
) {
363 if (pid_element_open
) {
364 /* Close the previous events and pid element */
365 ret
= mi_lttng_close_multi_element(writer
, 2);
369 pid_element_open
= 0;
372 cur_pid
= events
[i
].pid
;
373 cmdline
= get_cmdline_by_pid(cur_pid
);
379 if (!pid_element_open
) {
380 /* Open and write a pid element */
381 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
386 /* Open events element */
387 ret
= mi_lttng_events_open(writer
);
392 pid_element_open
= 1;
398 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
405 ret
= mi_lttng_writer_close_element(writer
);
410 /* Close domain, domains */
411 ret
= mi_lttng_close_multi_element(writer
, 2);
419 static int list_agent_events(void)
421 int i
, size
, ret
= CMD_SUCCESS
;
422 struct lttng_domain domain
;
423 struct lttng_handle
*handle
;
424 struct lttng_event
*event_list
;
426 char *cmdline
= NULL
;
427 const char *agent_domain_str
;
429 memset(&domain
, 0, sizeof(domain
));
431 domain
.type
= LTTNG_DOMAIN_JUL
;
432 } else if (opt_log4j
) {
433 domain
.type
= LTTNG_DOMAIN_LOG4J
;
434 } else if (opt_python
) {
435 domain
.type
= LTTNG_DOMAIN_PYTHON
;
438 agent_domain_str
= get_domain_str(domain
.type
);
440 DBG("Getting %s tracing events", agent_domain_str
);
442 handle
= lttng_create_handle(NULL
, &domain
);
443 if (handle
== NULL
) {
448 size
= lttng_list_tracepoints(handle
, &event_list
);
450 ERR("Unable to list %s events: %s", agent_domain_str
,
451 lttng_strerror(size
));
458 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
465 MSG("%s events (Logger name):\n-------------------------",
472 for (i
= 0; i
< size
; i
++) {
473 if (cur_pid
!= event_list
[i
].pid
) {
474 cur_pid
= event_list
[i
].pid
;
475 cmdline
= get_cmdline_by_pid(cur_pid
);
476 if (cmdline
== NULL
) {
480 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
483 MSG("%s- %s", indent6
, event_list
[i
].name
);
492 lttng_destroy_handle(handle
);
497 * Ask session daemon for all user space tracepoints available.
499 static int list_ust_events(void)
501 int i
, size
, ret
= CMD_SUCCESS
;
502 struct lttng_domain domain
;
503 struct lttng_handle
*handle
;
504 struct lttng_event
*event_list
;
506 char *cmdline
= NULL
;
508 memset(&domain
, 0, sizeof(domain
));
510 DBG("Getting UST tracing events");
512 domain
.type
= LTTNG_DOMAIN_UST
;
514 handle
= lttng_create_handle(NULL
, &domain
);
515 if (handle
== NULL
) {
520 size
= lttng_list_tracepoints(handle
, &event_list
);
522 ERR("Unable to list UST events: %s", lttng_strerror(size
));
529 ret
= mi_list_agent_ust_events(event_list
, size
, &domain
);
532 MSG("UST events:\n-------------");
538 for (i
= 0; i
< size
; i
++) {
539 if (cur_pid
!= event_list
[i
].pid
) {
540 cur_pid
= event_list
[i
].pid
;
541 cmdline
= get_cmdline_by_pid(cur_pid
);
542 if (cmdline
== NULL
) {
546 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
549 print_events(&event_list
[i
]);
558 lttng_destroy_handle(handle
);
564 * List all ust event with their fields
566 static int mi_list_ust_event_fields(struct lttng_event_field
*fields
, int count
,
567 struct lttng_domain
*domain
)
571 char *cmdline
= NULL
;
572 int pid_element_open
= 0;
573 int event_element_open
= 0;
574 struct lttng_event cur_event
;
576 /* Open domains element */
577 ret
= mi_lttng_domains_open(writer
);
583 ret
= mi_lttng_domain(writer
, domain
, 1);
588 /* Open pids element */
589 ret
= mi_lttng_pids_open(writer
);
594 for (i
= 0; i
< count
; i
++) {
595 if (cur_pid
!= fields
[i
].event
.pid
) {
596 if (pid_element_open
) {
597 if (event_element_open
) {
599 /* Close the previous field element and event. */
600 ret
= mi_lttng_close_multi_element(writer
, 2);
604 event_element_open
= 0;
606 /* Close the previous events, pid element */
607 ret
= mi_lttng_close_multi_element(writer
, 2);
611 pid_element_open
= 0;
614 cur_pid
= fields
[i
].event
.pid
;
615 cmdline
= get_cmdline_by_pid(cur_pid
);
616 if (!pid_element_open
) {
617 /* Open and write a pid element */
618 ret
= mi_lttng_pid(writer
, cur_pid
, cmdline
, 1);
623 /* Open events element */
624 ret
= mi_lttng_events_open(writer
);
628 pid_element_open
= 1;
631 /* Wipe current event since we are about to print a new PID. */
632 memset(&cur_event
, 0, sizeof(cur_event
));
635 if (strcmp(cur_event
.name
, fields
[i
].event
.name
) != 0) {
636 if (event_element_open
) {
637 /* Close the previous fields element and the previous event */
638 ret
= mi_lttng_close_multi_element(writer
, 2);
642 event_element_open
= 0;
645 memcpy(&cur_event
, &fields
[i
].event
,
648 if (!event_element_open
) {
649 /* Open and write the event */
650 ret
= mi_lttng_event(writer
, &cur_event
, 1,
651 handle
->domain
.type
);
656 /* Open a fields element */
657 ret
= mi_lttng_event_fields_open(writer
);
661 event_element_open
= 1;
665 /* Print the event_field */
666 ret
= mi_lttng_event_field(writer
, &fields
[i
]);
672 /* Close pids, domain, domains */
673 ret
= mi_lttng_close_multi_element(writer
, 3);
682 * Ask session daemon for all user space tracepoint fields available.
684 static int list_ust_event_fields(void)
686 int i
, size
, ret
= CMD_SUCCESS
;
687 struct lttng_domain domain
;
688 struct lttng_handle
*handle
;
689 struct lttng_event_field
*event_field_list
;
691 char *cmdline
= NULL
;
693 struct lttng_event cur_event
;
695 memset(&domain
, 0, sizeof(domain
));
696 memset(&cur_event
, 0, sizeof(cur_event
));
698 DBG("Getting UST tracing event fields");
700 domain
.type
= LTTNG_DOMAIN_UST
;
702 handle
= lttng_create_handle(NULL
, &domain
);
703 if (handle
== NULL
) {
708 size
= lttng_list_tracepoint_fields(handle
, &event_field_list
);
710 ERR("Unable to list UST event fields: %s", lttng_strerror(size
));
717 ret
= mi_list_ust_event_fields(event_field_list
, size
, &domain
);
724 MSG("UST events:\n-------------");
730 for (i
= 0; i
< size
; i
++) {
731 if (cur_pid
!= event_field_list
[i
].event
.pid
) {
732 cur_pid
= event_field_list
[i
].event
.pid
;
733 cmdline
= get_cmdline_by_pid(cur_pid
);
734 if (cmdline
== NULL
) {
738 MSG("\nPID: %d - Name: %s", cur_pid
, cmdline
);
740 /* Wipe current event since we are about to print a new PID. */
741 memset(&cur_event
, 0, sizeof(cur_event
));
743 if (strcmp(cur_event
.name
, event_field_list
[i
].event
.name
) != 0) {
744 print_events(&event_field_list
[i
].event
);
745 memcpy(&cur_event
, &event_field_list
[i
].event
,
748 print_event_field(&event_field_list
[i
]);
755 free(event_field_list
);
757 lttng_destroy_handle(handle
);
763 * Print a list of kernel events
765 static int mi_list_kernel_events(struct lttng_event
*events
, int count
,
766 struct lttng_domain
*domain
)
770 /* Open domains element */
771 ret
= mi_lttng_domains_open(writer
);
777 ret
= mi_lttng_domain(writer
, domain
, 1);
783 ret
= mi_lttng_events_open(writer
);
788 for (i
= 0; i
< count
; i
++) {
789 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
795 /* close events, domain and domains */
796 ret
= mi_lttng_close_multi_element(writer
, 3);
806 * Ask for all trace events in the kernel
808 static int list_kernel_events(void)
810 int i
, size
, ret
= CMD_SUCCESS
;
811 struct lttng_domain domain
;
812 struct lttng_handle
*handle
;
813 struct lttng_event
*event_list
;
815 memset(&domain
, 0, sizeof(domain
));
817 DBG("Getting kernel tracing events");
819 domain
.type
= LTTNG_DOMAIN_KERNEL
;
821 handle
= lttng_create_handle(NULL
, &domain
);
822 if (handle
== NULL
) {
827 size
= lttng_list_tracepoints(handle
, &event_list
);
829 ERR("Unable to list kernel events: %s", lttng_strerror(size
));
830 lttng_destroy_handle(handle
);
836 ret
= mi_list_kernel_events(event_list
, size
, &domain
);
842 MSG("Kernel events:\n-------------");
844 for (i
= 0; i
< size
; i
++) {
845 print_events(&event_list
[i
]);
854 lttng_destroy_handle(handle
);
858 lttng_destroy_handle(handle
);
864 * Print a list of system calls.
866 static int mi_list_syscalls(struct lttng_event
*events
, int count
)
871 ret
= mi_lttng_events_open(writer
);
876 for (i
= 0; i
< count
; i
++) {
877 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
884 ret
= mi_lttng_writer_close_element(writer
);
894 * Ask for kernel system calls.
896 static int list_syscalls(void)
898 int i
, size
, ret
= CMD_SUCCESS
;
899 struct lttng_event
*event_list
;
901 DBG("Getting kernel system call events");
903 size
= lttng_list_syscalls(&event_list
);
905 ERR("Unable to list system calls: %s", lttng_strerror(size
));
912 ret
= mi_list_syscalls(event_list
, size
);
918 MSG("System calls:\n-------------");
920 for (i
= 0; i
< size
; i
++) {
921 print_events(&event_list
[i
]);
937 * Print a list of agent events
939 static int mi_list_session_agent_events(struct lttng_event
*events
, int count
)
943 /* Open events element */
944 ret
= mi_lttng_events_open(writer
);
949 for (i
= 0; i
< count
; i
++) {
950 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
956 /* Close events element */
957 ret
= mi_lttng_writer_close_element(writer
);
964 * List agent events for a specific session using the handle.
966 * Return CMD_SUCCESS on success else a negative value.
968 static int list_session_agent_events(void)
970 int ret
= CMD_SUCCESS
, count
, i
;
971 struct lttng_event
*events
= NULL
;
973 count
= lttng_list_events(handle
, "", &events
);
976 ERR("%s", lttng_strerror(count
));
982 ret
= mi_list_session_agent_events(events
, count
);
989 MSG("Events (Logger name):\n---------------------");
991 MSG("%sNone\n", indent6
);
995 for (i
= 0; i
< count
; i
++) {
996 MSG("%s- %s%s (loglevel%s %s)", indent4
, events
[i
].name
,
997 enabled_string(events
[i
].enabled
),
998 logleveltype_string(events
[i
].loglevel_type
),
999 mi_lttng_loglevel_string(events
[i
].loglevel
,
1000 handle
->domain
.type
));
1014 * print a list of event
1016 static int mi_list_events(struct lttng_event
*events
, int count
)
1020 /* Open events element */
1021 ret
= mi_lttng_events_open(writer
);
1026 for (i
= 0; i
< count
; i
++) {
1027 ret
= mi_lttng_event(writer
, &events
[i
], 0, handle
->domain
.type
);
1033 /* Close events element */
1034 ret
= mi_lttng_writer_close_element(writer
);
1041 * List events of channel of session and domain.
1043 static int list_events(const char *channel_name
)
1045 int ret
= CMD_SUCCESS
, count
, i
;
1046 struct lttng_event
*events
= NULL
;
1048 count
= lttng_list_events(handle
, channel_name
, &events
);
1051 ERR("%s", lttng_strerror(count
));
1057 ret
= mi_list_events(events
, count
);
1064 MSG("\n%sEvents:", indent4
);
1066 MSG("%sNone\n", indent6
);
1070 for (i
= 0; i
< count
; i
++) {
1071 print_events(&events
[i
]);
1083 * Pretty print channel
1085 static void print_channel(struct lttng_channel
*channel
)
1087 MSG("- %s:%s\n", channel
->name
, enabled_string(channel
->enabled
));
1089 MSG("%sAttributes:", indent4
);
1090 MSG("%soverwrite mode: %d", indent6
, channel
->attr
.overwrite
);
1091 MSG("%ssubbufers size: %" PRIu64
, indent6
, channel
->attr
.subbuf_size
);
1092 MSG("%snumber of subbufers: %" PRIu64
, indent6
, channel
->attr
.num_subbuf
);
1093 MSG("%sswitch timer interval: %u", indent6
, channel
->attr
.switch_timer_interval
);
1094 MSG("%sread timer interval: %u", indent6
, channel
->attr
.read_timer_interval
);
1095 MSG("%strace file count: %" PRIu64
, indent6
, channel
->attr
.tracefile_count
);
1096 MSG("%strace file size (bytes): %" PRIu64
, indent6
, channel
->attr
.tracefile_size
);
1097 switch (channel
->attr
.output
) {
1098 case LTTNG_EVENT_SPLICE
:
1099 MSG("%soutput: splice()", indent6
);
1101 case LTTNG_EVENT_MMAP
:
1102 MSG("%soutput: mmap()", indent6
);
1109 * Print a list of channel
1112 static int mi_list_channels(struct lttng_channel
*channels
, int count
,
1113 const char *channel_name
)
1116 unsigned int chan_found
= 0;
1118 /* Open channels element */
1119 ret
= mi_lttng_channels_open(writer
);
1124 for (i
= 0; i
< count
; i
++) {
1125 if (channel_name
!= NULL
) {
1126 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1133 /* Write channel element and leave it open */
1134 ret
= mi_lttng_channel(writer
, &channels
[i
], 1);
1139 /* Listing events per channel */
1140 ret
= list_events(channels
[i
].name
);
1145 /* Closing the channel element we opened earlier */
1146 ret
= mi_lttng_writer_close_element(writer
);
1156 /* Close channels element */
1157 ret
= mi_lttng_writer_close_element(writer
);
1167 * List channel(s) of session and domain.
1169 * If channel_name is NULL, all channels are listed.
1171 static int list_channels(const char *channel_name
)
1173 int count
, i
, ret
= CMD_SUCCESS
;
1174 unsigned int chan_found
= 0;
1175 struct lttng_channel
*channels
= NULL
;
1177 DBG("Listing channel(s) (%s)", channel_name
? : "<all>");
1179 count
= lttng_list_channels(handle
, &channels
);
1182 case LTTNG_ERR_KERN_CHAN_NOT_FOUND
:
1184 /* When printing mi this is not an error
1185 * but an empty channels element */
1189 WARN("No kernel channel");
1190 goto error_channels
;
1194 /* We had a real error */
1196 ERR("%s", lttng_strerror(count
));
1197 goto error_channels
;
1204 ret
= mi_list_channels(channels
, count
, channel_name
);
1212 MSG("Channels:\n-------------");
1215 for (i
= 0; i
< count
; i
++) {
1216 if (channel_name
!= NULL
) {
1217 if (strncmp(channels
[i
].name
, channel_name
, NAME_MAX
) == 0) {
1223 print_channel(&channels
[i
]);
1225 /* Listing events per channel */
1226 ret
= list_events(channels
[i
].name
);
1236 if (!chan_found
&& channel_name
!= NULL
) {
1238 ERR("Channel %s not found", channel_name
);
1251 * Find the session with session_name as name
1252 * and print his informations.
1254 static int mi_list_session(const char *session_name
,
1255 struct lttng_session
*sessions
, int count
)
1258 unsigned int session_found
= 0;
1260 if (session_name
== NULL
) {
1261 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1265 for (i
= 0; i
< count
; i
++) {
1266 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1267 /* We need to leave it open to append other informations
1268 * like domain, channel, events etc.*/
1270 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
1278 if (!session_found
) {
1279 ERR("Session '%s' not found", session_name
);
1280 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1290 * List all availables session
1292 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
1296 /* Opening sessions element */
1297 ret
= mi_lttng_sessions_open(writer
);
1302 /* Listing sessions */
1303 for (i
= 0; i
< count
; i
++) {
1304 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
1310 /* Closing sessions element */
1311 ret
= mi_lttng_writer_close_element(writer
);
1321 * List available tracing session. List only basic information.
1323 * If session_name is NULL, all sessions are listed.
1325 static int list_sessions(const char *session_name
)
1327 int ret
= CMD_SUCCESS
;
1329 unsigned int session_found
= 0;
1330 struct lttng_session
*sessions
;
1332 count
= lttng_list_sessions(&sessions
);
1333 DBG("Session count %d", count
);
1336 ERR("%s", lttng_strerror(count
));
1342 if (session_name
== NULL
) {
1343 /* List all session */
1344 ret
= mi_list_sessions(sessions
, count
);
1346 /* Note : this return an open session element */
1347 ret
= mi_list_session(session_name
, sessions
, count
);
1356 MSG("Currently no available tracing session");
1360 if (session_name
== NULL
) {
1361 MSG("Available tracing sessions:");
1365 for (i
= 0; i
< count
; i
++) {
1366 if (session_name
!= NULL
) {
1367 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1369 MSG("Tracing session %s: [%s%s]", session_name
,
1370 active_string(sessions
[i
].enabled
),
1371 snapshot_string(sessions
[i
].snapshot_mode
));
1372 MSG("%sTrace path: %s\n", indent4
, sessions
[i
].path
);
1376 MSG(" %d) %s (%s) [%s%s]", i
+ 1,
1377 sessions
[i
].name
, sessions
[i
].path
,
1378 active_string(sessions
[i
].enabled
),
1379 snapshot_string(sessions
[i
].snapshot_mode
));
1380 MSG("%sTrace path: %s", indent4
, sessions
[i
].path
);
1381 MSG("%sLive timer interval (usec): %u\n", indent4
,
1382 sessions
[i
].live_timer_interval
);
1386 if (!session_found
&& session_name
!= NULL
) {
1387 ERR("Session '%s' not found", session_name
);
1392 if (session_name
== NULL
) {
1393 MSG("\nUse lttng list <session_name> for more details");
1406 * list available domain(s) for a session.
1408 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
1411 /* Open domains element */
1412 ret
= mi_lttng_domains_open(writer
);
1417 for (i
= 0; i
< count
; i
++) {
1418 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
1424 /* Closing domains element */
1425 ret
= mi_lttng_writer_close_element(writer
);
1434 * List available domain(s) for a session.
1436 static int list_domains(const char *session_name
)
1438 int i
, count
, ret
= CMD_SUCCESS
;
1439 struct lttng_domain
*domains
= NULL
;
1442 count
= lttng_list_domains(session_name
, &domains
);
1445 ERR("%s", lttng_strerror(count
));
1451 ret
= mi_list_domains(domains
, count
);
1458 MSG("Domains:\n-------------");
1464 for (i
= 0; i
< count
; i
++) {
1465 switch (domains
[i
].type
) {
1466 case LTTNG_DOMAIN_KERNEL
:
1469 case LTTNG_DOMAIN_UST
:
1470 MSG(" - UST global");
1472 case LTTNG_DOMAIN_JUL
:
1473 MSG(" - JUL (Java Util Logging)");
1475 case LTTNG_DOMAIN_LOG4J
:
1476 MSG(" - LOG4j (Logging for Java)");
1478 case LTTNG_DOMAIN_PYTHON
:
1479 MSG(" - Python (logging)");
1495 * The 'list <options>' first level command
1497 int cmd_list(int argc
, const char **argv
)
1499 int opt
, ret
= CMD_SUCCESS
;
1500 const char *session_name
;
1501 static poptContext pc
;
1502 struct lttng_domain domain
;
1503 struct lttng_domain
*domains
= NULL
;
1505 memset(&domain
, 0, sizeof(domain
));
1513 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
1514 poptReadDefaultConfig(pc
, 0);
1516 while ((opt
= poptGetNextOpt(pc
)) != -1) {
1524 case OPT_LIST_OPTIONS
:
1525 list_cmd_options(stdout
, long_options
);
1529 ret
= CMD_UNDEFINED
;
1536 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
1542 /* Open command element */
1543 ret
= mi_lttng_writer_command_open(writer
,
1544 mi_lttng_element_command_list
);
1550 /* Open output element */
1551 ret
= mi_lttng_writer_open_element(writer
,
1552 mi_lttng_element_command_output
);
1559 /* Get session name (trailing argument) */
1560 session_name
= poptGetArg(pc
);
1561 DBG2("Session name: %s", session_name
);
1564 domain
.type
= LTTNG_DOMAIN_KERNEL
;
1565 } else if (opt_userspace
) {
1566 DBG2("Listing userspace global domain");
1567 domain
.type
= LTTNG_DOMAIN_UST
;
1568 } else if (opt_jul
) {
1569 DBG2("Listing JUL domain");
1570 domain
.type
= LTTNG_DOMAIN_JUL
;
1571 } else if (opt_log4j
) {
1572 domain
.type
= LTTNG_DOMAIN_LOG4J
;
1573 } else if (opt_python
) {
1574 domain
.type
= LTTNG_DOMAIN_PYTHON
;
1577 if (!opt_kernel
&& opt_syscall
) {
1578 WARN("--syscall will only work with the Kernel domain (-k)");
1583 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
1584 handle
= lttng_create_handle(session_name
, &domain
);
1585 if (handle
== NULL
) {
1591 if (session_name
== NULL
) {
1592 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
1594 ret
= list_sessions(NULL
);
1601 ret
= list_syscalls();
1606 ret
= list_kernel_events();
1612 if (opt_userspace
) {
1614 ret
= list_ust_event_fields();
1616 ret
= list_ust_events();
1622 if (opt_jul
|| opt_log4j
|| opt_python
) {
1623 ret
= list_agent_events();
1629 /* List session attributes */
1631 /* Open element sessions
1632 * Present for xml consistency */
1633 ret
= mi_lttng_sessions_open(writer
);
1638 /* MI: the ouptut of list_sessions is an unclosed session element */
1639 ret
= list_sessions(session_name
);
1644 /* Domain listing */
1646 ret
= list_domains(session_name
);
1650 /* Channel listing */
1651 if (opt_kernel
|| opt_userspace
) {
1653 /* Add of domains and domain element for xml
1654 * consistency and validation
1656 ret
= mi_lttng_domains_open(writer
);
1661 /* Open domain and leave it open for
1662 * nested channels printing */
1663 ret
= mi_lttng_domain(writer
, &domain
, 1);
1670 ret
= list_channels(opt_channel
);
1676 /* Close domain and domain element */
1677 ret
= mi_lttng_close_multi_element(writer
, 2);
1687 /* We want all domain(s) */
1688 nb_domain
= lttng_list_domains(session_name
, &domains
);
1689 if (nb_domain
< 0) {
1691 ERR("%s", lttng_strerror(nb_domain
));
1696 ret
= mi_lttng_domains_open(writer
);
1703 for (i
= 0; i
< nb_domain
; i
++) {
1704 switch (domains
[i
].type
) {
1705 case LTTNG_DOMAIN_KERNEL
:
1706 MSG("=== Domain: Kernel ===\n");
1708 case LTTNG_DOMAIN_UST
:
1709 MSG("=== Domain: UST global ===\n");
1710 MSG("Buffer type: %s\n",
1711 domains
[i
].buf_type
==
1712 LTTNG_BUFFER_PER_PID
? "per PID" : "per UID");
1714 case LTTNG_DOMAIN_JUL
:
1715 MSG("=== Domain: JUL (Java Util Logging) ===\n");
1717 case LTTNG_DOMAIN_LOG4J
:
1718 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
1720 case LTTNG_DOMAIN_PYTHON
:
1721 MSG("=== Domain: Python (logging) ===\n");
1724 MSG("=== Domain: Unimplemented ===\n");
1729 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
1736 /* Clean handle before creating a new one */
1738 lttng_destroy_handle(handle
);
1741 handle
= lttng_create_handle(session_name
, &domains
[i
]);
1742 if (handle
== NULL
) {
1747 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
1748 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
1749 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
1750 ret
= list_session_agent_events();
1757 ret
= list_channels(opt_channel
);
1763 /* Close domain element */
1764 ret
= mi_lttng_writer_close_element(writer
);
1773 /* Close the domains, session and sessions element */
1774 ret
= mi_lttng_close_multi_element(writer
, 3);
1785 /* Close output element */
1786 ret
= mi_lttng_writer_close_element(writer
);
1792 /* Command element close */
1793 ret
= mi_lttng_writer_command_close(writer
);
1801 if (writer
&& mi_lttng_writer_destroy(writer
)) {
1802 /* Preserve original error code */
1803 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
1808 lttng_destroy_handle(handle
);
1811 poptFreeContext(pc
);