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
= zmalloc(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
);
1250 * List tracker PID(s) of session and domain.
1252 static int list_tracker_pids(void)
1258 ret
= lttng_list_tracker_pids(handle
,
1259 &enabled
, &pids
, &nr_pids
);
1263 _MSG("PID tracker: [%s]", enabled
? "enabled" : "disabled");
1267 for (i
= 0; i
< nr_pids
; i
++) {
1271 _MSG(" %d", pids
[i
]);
1282 * Find the session with session_name as name
1283 * and print his informations.
1285 static int mi_list_session(const char *session_name
,
1286 struct lttng_session
*sessions
, int count
)
1289 unsigned int session_found
= 0;
1291 if (session_name
== NULL
) {
1292 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1296 for (i
= 0; i
< count
; i
++) {
1297 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1298 /* We need to leave it open to append other informations
1299 * like domain, channel, events etc.*/
1301 ret
= mi_lttng_session(writer
, &sessions
[i
], 1);
1309 if (!session_found
) {
1310 ERR("Session '%s' not found", session_name
);
1311 ret
= -LTTNG_ERR_SESS_NOT_FOUND
;
1321 * List all availables session
1323 static int mi_list_sessions(struct lttng_session
*sessions
, int count
)
1327 /* Opening sessions element */
1328 ret
= mi_lttng_sessions_open(writer
);
1333 /* Listing sessions */
1334 for (i
= 0; i
< count
; i
++) {
1335 ret
= mi_lttng_session(writer
, &sessions
[i
], 0);
1341 /* Closing sessions element */
1342 ret
= mi_lttng_writer_close_element(writer
);
1352 * List available tracing session. List only basic information.
1354 * If session_name is NULL, all sessions are listed.
1356 static int list_sessions(const char *session_name
)
1358 int ret
= CMD_SUCCESS
;
1360 unsigned int session_found
= 0;
1361 struct lttng_session
*sessions
;
1363 count
= lttng_list_sessions(&sessions
);
1364 DBG("Session count %d", count
);
1367 ERR("%s", lttng_strerror(count
));
1373 if (session_name
== NULL
) {
1374 /* List all session */
1375 ret
= mi_list_sessions(sessions
, count
);
1377 /* Note : this return an open session element */
1378 ret
= mi_list_session(session_name
, sessions
, count
);
1387 MSG("Currently no available tracing session");
1391 if (session_name
== NULL
) {
1392 MSG("Available tracing sessions:");
1396 for (i
= 0; i
< count
; i
++) {
1397 if (session_name
!= NULL
) {
1398 if (strncmp(sessions
[i
].name
, session_name
, NAME_MAX
) == 0) {
1400 MSG("Tracing session %s: [%s%s]", session_name
,
1401 active_string(sessions
[i
].enabled
),
1402 snapshot_string(sessions
[i
].snapshot_mode
));
1403 MSG("%sTrace path: %s\n", indent4
, sessions
[i
].path
);
1407 MSG(" %d) %s (%s) [%s%s]", i
+ 1,
1408 sessions
[i
].name
, sessions
[i
].path
,
1409 active_string(sessions
[i
].enabled
),
1410 snapshot_string(sessions
[i
].snapshot_mode
));
1411 MSG("%sTrace path: %s", indent4
, sessions
[i
].path
);
1412 MSG("%sLive timer interval (usec): %u\n", indent4
,
1413 sessions
[i
].live_timer_interval
);
1417 if (!session_found
&& session_name
!= NULL
) {
1418 ERR("Session '%s' not found", session_name
);
1423 if (session_name
== NULL
) {
1424 MSG("\nUse lttng list <session_name> for more details");
1437 * list available domain(s) for a session.
1439 static int mi_list_domains(struct lttng_domain
*domains
, int count
)
1442 /* Open domains element */
1443 ret
= mi_lttng_domains_open(writer
);
1448 for (i
= 0; i
< count
; i
++) {
1449 ret
= mi_lttng_domain(writer
, &domains
[i
] , 0);
1455 /* Closing domains element */
1456 ret
= mi_lttng_writer_close_element(writer
);
1465 * List available domain(s) for a session.
1467 static int list_domains(const char *session_name
)
1469 int i
, count
, ret
= CMD_SUCCESS
;
1470 struct lttng_domain
*domains
= NULL
;
1473 count
= lttng_list_domains(session_name
, &domains
);
1476 ERR("%s", lttng_strerror(count
));
1482 ret
= mi_list_domains(domains
, count
);
1489 MSG("Domains:\n-------------");
1495 for (i
= 0; i
< count
; i
++) {
1496 switch (domains
[i
].type
) {
1497 case LTTNG_DOMAIN_KERNEL
:
1500 case LTTNG_DOMAIN_UST
:
1501 MSG(" - UST global");
1503 case LTTNG_DOMAIN_JUL
:
1504 MSG(" - JUL (Java Util Logging)");
1506 case LTTNG_DOMAIN_LOG4J
:
1507 MSG(" - LOG4j (Logging for Java)");
1509 case LTTNG_DOMAIN_PYTHON
:
1510 MSG(" - Python (logging)");
1526 * The 'list <options>' first level command
1528 int cmd_list(int argc
, const char **argv
)
1530 int opt
, ret
= CMD_SUCCESS
;
1531 const char *session_name
;
1532 static poptContext pc
;
1533 struct lttng_domain domain
;
1534 struct lttng_domain
*domains
= NULL
;
1536 memset(&domain
, 0, sizeof(domain
));
1544 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
1545 poptReadDefaultConfig(pc
, 0);
1547 while ((opt
= poptGetNextOpt(pc
)) != -1) {
1555 case OPT_LIST_OPTIONS
:
1556 list_cmd_options(stdout
, long_options
);
1560 ret
= CMD_UNDEFINED
;
1567 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
1573 /* Open command element */
1574 ret
= mi_lttng_writer_command_open(writer
,
1575 mi_lttng_element_command_list
);
1581 /* Open output element */
1582 ret
= mi_lttng_writer_open_element(writer
,
1583 mi_lttng_element_command_output
);
1590 /* Get session name (trailing argument) */
1591 session_name
= poptGetArg(pc
);
1592 DBG2("Session name: %s", session_name
);
1595 domain
.type
= LTTNG_DOMAIN_KERNEL
;
1596 } else if (opt_userspace
) {
1597 DBG2("Listing userspace global domain");
1598 domain
.type
= LTTNG_DOMAIN_UST
;
1599 } else if (opt_jul
) {
1600 DBG2("Listing JUL domain");
1601 domain
.type
= LTTNG_DOMAIN_JUL
;
1602 } else if (opt_log4j
) {
1603 domain
.type
= LTTNG_DOMAIN_LOG4J
;
1604 } else if (opt_python
) {
1605 domain
.type
= LTTNG_DOMAIN_PYTHON
;
1608 if (!opt_kernel
&& opt_syscall
) {
1609 WARN("--syscall will only work with the Kernel domain (-k)");
1614 if (opt_kernel
|| opt_userspace
|| opt_jul
|| opt_log4j
|| opt_python
) {
1615 handle
= lttng_create_handle(session_name
, &domain
);
1616 if (handle
== NULL
) {
1622 if (session_name
== NULL
) {
1623 if (!opt_kernel
&& !opt_userspace
&& !opt_jul
&& !opt_log4j
1625 ret
= list_sessions(NULL
);
1632 ret
= list_syscalls();
1637 ret
= list_kernel_events();
1643 if (opt_userspace
) {
1645 ret
= list_ust_event_fields();
1647 ret
= list_ust_events();
1653 if (opt_jul
|| opt_log4j
|| opt_python
) {
1654 ret
= list_agent_events();
1660 /* List session attributes */
1662 /* Open element sessions
1663 * Present for xml consistency */
1664 ret
= mi_lttng_sessions_open(writer
);
1669 /* MI: the ouptut of list_sessions is an unclosed session element */
1670 ret
= list_sessions(session_name
);
1675 /* Domain listing */
1677 ret
= list_domains(session_name
);
1681 /* Channel listing */
1682 if (opt_kernel
|| opt_userspace
) {
1684 /* Add of domains and domain element for xml
1685 * consistency and validation
1687 ret
= mi_lttng_domains_open(writer
);
1692 /* Open domain and leave it open for
1693 * nested channels printing */
1694 ret
= mi_lttng_domain(writer
, &domain
, 1);
1701 ret
= list_tracker_pids();
1706 ret
= list_channels(opt_channel
);
1712 /* Close domain and domain element */
1713 ret
= mi_lttng_close_multi_element(writer
, 2);
1723 /* We want all domain(s) */
1724 nb_domain
= lttng_list_domains(session_name
, &domains
);
1725 if (nb_domain
< 0) {
1727 ERR("%s", lttng_strerror(nb_domain
));
1732 ret
= mi_lttng_domains_open(writer
);
1739 for (i
= 0; i
< nb_domain
; i
++) {
1740 switch (domains
[i
].type
) {
1741 case LTTNG_DOMAIN_KERNEL
:
1742 MSG("=== Domain: Kernel ===\n");
1744 case LTTNG_DOMAIN_UST
:
1745 MSG("=== Domain: UST global ===\n");
1746 MSG("Buffer type: %s\n",
1747 domains
[i
].buf_type
==
1748 LTTNG_BUFFER_PER_PID
? "per PID" : "per UID");
1750 case LTTNG_DOMAIN_JUL
:
1751 MSG("=== Domain: JUL (Java Util Logging) ===\n");
1753 case LTTNG_DOMAIN_LOG4J
:
1754 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
1756 case LTTNG_DOMAIN_PYTHON
:
1757 MSG("=== Domain: Python (logging) ===\n");
1760 MSG("=== Domain: Unimplemented ===\n");
1765 ret
= mi_lttng_domain(writer
, &domains
[i
], 1);
1772 /* Clean handle before creating a new one */
1774 lttng_destroy_handle(handle
);
1777 handle
= lttng_create_handle(session_name
, &domains
[i
]);
1778 if (handle
== NULL
) {
1783 if (domains
[i
].type
== LTTNG_DOMAIN_JUL
||
1784 domains
[i
].type
== LTTNG_DOMAIN_LOG4J
||
1785 domains
[i
].type
== LTTNG_DOMAIN_PYTHON
) {
1786 ret
= list_session_agent_events();
1793 switch (domains
[i
].type
) {
1794 case LTTNG_DOMAIN_KERNEL
:
1795 case LTTNG_DOMAIN_UST
:
1796 ret
= list_tracker_pids();
1805 ret
= list_channels(opt_channel
);
1811 /* Close domain element */
1812 ret
= mi_lttng_writer_close_element(writer
);
1821 /* Close the domains, session and sessions element */
1822 ret
= mi_lttng_close_multi_element(writer
, 3);
1833 /* Close output element */
1834 ret
= mi_lttng_writer_close_element(writer
);
1840 /* Command element close */
1841 ret
= mi_lttng_writer_command_close(writer
);
1849 if (writer
&& mi_lttng_writer_destroy(writer
)) {
1850 /* Preserve original error code */
1851 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
1856 lttng_destroy_handle(handle
);
1859 poptFreeContext(pc
);