Clean-up: Remove ifdef-ed out lttng list options
[lttng-tools.git] / src / bin / lttng / commands / list.c
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
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.
7 *
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.
12 *
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.
16 */
17
18 #define _GNU_SOURCE
19 #define _LGPL_SOURCE
20 #include <inttypes.h>
21 #include <popt.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <assert.h>
26
27 #include <common/mi-lttng.h>
28
29 #include "../command.h"
30
31 static int opt_userspace;
32 static int opt_kernel;
33 static int opt_jul;
34 static int opt_log4j;
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;
40
41 const char *indent4 = " ";
42 const char *indent6 = " ";
43 const char *indent8 = " ";
44
45 enum {
46 OPT_HELP = 1,
47 OPT_USERSPACE,
48 OPT_LIST_OPTIONS,
49 };
50
51 static struct lttng_handle *handle;
52 static struct mi_writer *writer;
53
54 static struct poptOption long_options[] = {
55 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
56 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
57 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
58 {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
59 {"log4j", 'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0},
60 {"python", 'p', POPT_ARG_VAL, &opt_python, 1, 0, 0},
61 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
62 {"channel", 'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0},
63 {"domain", 'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
64 {"fields", 'f', POPT_ARG_VAL, &opt_fields, 1, 0, 0},
65 {"syscall", 'S', POPT_ARG_VAL, &opt_syscall, 1, 0, 0},
66 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
67 {0, 0, 0, 0, 0, 0, 0}
68 };
69
70 /*
71 * usage
72 */
73 static void usage(FILE *ofp)
74 {
75 fprintf(ofp, "usage: lttng list [OPTIONS] [SESSION [SESSION OPTIONS]]\n");
76 fprintf(ofp, "\n");
77 fprintf(ofp, "With no arguments, list available tracing session(s)\n");
78 fprintf(ofp, "\n");
79 fprintf(ofp, "Without a session, -k lists available kernel events\n");
80 fprintf(ofp, "Without a session, -u lists available userspace events\n");
81 fprintf(ofp, "\n");
82 fprintf(ofp, " -h, --help Show this help\n");
83 fprintf(ofp, " --list-options Simple listing of options\n");
84 fprintf(ofp, " -k, --kernel Select kernel domain\n");
85 fprintf(ofp, " -u, --userspace Select user-space domain.\n");
86 fprintf(ofp, " -j, --jul Apply for Java application using JUL\n");
87 fprintf(ofp, " -l, --log4j Apply for Java application using LOG4J\n");
88 fprintf(ofp, " -p, --python Apply for Python application using logging\n");
89 fprintf(ofp, " -f, --fields List event fields.\n");
90 fprintf(ofp, " --syscall List available system calls.\n");
91 fprintf(ofp, "\n");
92 fprintf(ofp, "Session Options:\n");
93 fprintf(ofp, " -c, --channel NAME List details of a channel\n");
94 fprintf(ofp, " -d, --domain List available domain(s)\n");
95 fprintf(ofp, "\n");
96 }
97
98 /*
99 * Get command line from /proc for a specific pid.
100 *
101 * On success, return an allocated string pointer to the proc cmdline.
102 * On error, return NULL.
103 */
104 static char *get_cmdline_by_pid(pid_t pid)
105 {
106 int ret;
107 FILE *fp = NULL;
108 char *cmdline = NULL;
109 char path[20]; /* Can't go bigger than /proc/65535/cmdline */
110
111 snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
112 fp = fopen(path, "r");
113 if (fp == NULL) {
114 goto end;
115 }
116
117 /* Caller must free() *cmdline */
118 cmdline = zmalloc(PATH_MAX);
119 if (!cmdline) {
120 PERROR("malloc cmdline");
121 goto end;
122 }
123 ret = fread(cmdline, 1, PATH_MAX, fp);
124 if (ret < 0) {
125 PERROR("fread proc list");
126 }
127
128 end:
129 if (fp) {
130 fclose(fp);
131 }
132 return cmdline;
133 }
134
135 static
136 const char *active_string(int value)
137 {
138 switch (value) {
139 case 0: return "inactive";
140 case 1: return "active";
141 case -1: return "";
142 default: return NULL;
143 }
144 }
145
146 static const char *snapshot_string(int value)
147 {
148 switch (value) {
149 case 1:
150 return " snapshot";
151 default:
152 return "";
153 }
154 }
155
156 static
157 const char *enabled_string(int value)
158 {
159 switch (value) {
160 case 0: return " [disabled]";
161 case 1: return " [enabled]";
162 case -1: return "";
163 default: return NULL;
164 }
165 }
166
167 static
168 const char *filter_string(int value)
169 {
170 switch (value) {
171 case 1: return " [with filter]";
172 default: return "";
173 }
174 }
175
176 static
177 const char *exclusion_string(int value)
178 {
179 switch (value) {
180 case 1: return " [has exclusions]";
181 default: return "";
182 }
183 }
184
185 static const char *logleveltype_string(enum lttng_loglevel_type value)
186 {
187 switch (value) {
188 case LTTNG_EVENT_LOGLEVEL_ALL:
189 return ":";
190 case LTTNG_EVENT_LOGLEVEL_RANGE:
191 return " <=";
192 case LTTNG_EVENT_LOGLEVEL_SINGLE:
193 return " ==";
194 default:
195 return " <<TYPE UNKN>>";
196 }
197 }
198
199 static const char *bitness_event(enum lttng_event_flag flags)
200 {
201 if (flags & LTTNG_EVENT_FLAG_SYSCALL_32) {
202 if (flags & LTTNG_EVENT_FLAG_SYSCALL_64) {
203 return " [32/64-bit]";
204 } else {
205 return " [32-bit]";
206 }
207 } else if (flags & LTTNG_EVENT_FLAG_SYSCALL_64) {
208 return " [64-bit]";
209 } else {
210 return "";
211 }
212 }
213
214 /*
215 * Pretty print single event.
216 */
217 static void print_events(struct lttng_event *event)
218 {
219 switch (event->type) {
220 case LTTNG_EVENT_TRACEPOINT:
221 {
222 if (event->loglevel != -1) {
223 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
224 indent6,
225 event->name,
226 logleveltype_string(event->loglevel_type),
227 mi_lttng_loglevel_string(event->loglevel, handle->domain.type),
228 event->loglevel,
229 enabled_string(event->enabled),
230 exclusion_string(event->exclusion),
231 filter_string(event->filter));
232 } else {
233 MSG("%s%s (type: tracepoint)%s%s%s",
234 indent6,
235 event->name,
236 enabled_string(event->enabled),
237 exclusion_string(event->exclusion),
238 filter_string(event->filter));
239 }
240 break;
241 }
242 case LTTNG_EVENT_FUNCTION:
243 MSG("%s%s (type: function)%s%s", indent6,
244 event->name, enabled_string(event->enabled),
245 filter_string(event->filter));
246 if (event->attr.probe.addr != 0) {
247 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
248 } else {
249 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
250 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
251 }
252 break;
253 case LTTNG_EVENT_PROBE:
254 MSG("%s%s (type: probe)%s%s", indent6,
255 event->name, enabled_string(event->enabled),
256 filter_string(event->filter));
257 if (event->attr.probe.addr != 0) {
258 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
259 } else {
260 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
261 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
262 }
263 break;
264 case LTTNG_EVENT_FUNCTION_ENTRY:
265 MSG("%s%s (type: function)%s%s", indent6,
266 event->name, enabled_string(event->enabled),
267 filter_string(event->filter));
268 MSG("%ssymbol: \"%s\"", indent8, event->attr.ftrace.symbol_name);
269 break;
270 case LTTNG_EVENT_SYSCALL:
271 MSG("%s%s%s%s%s", indent6, event->name,
272 (opt_syscall ? "" : " (type:syscall)"),
273 enabled_string(event->enabled),
274 bitness_event(event->flags));
275 break;
276 case LTTNG_EVENT_NOOP:
277 MSG("%s (type: noop)%s%s", indent6,
278 enabled_string(event->enabled),
279 filter_string(event->filter));
280 break;
281 case LTTNG_EVENT_ALL:
282 /* We should never have "all" events in list. */
283 assert(0);
284 break;
285 }
286 }
287
288 static const char *field_type(struct lttng_event_field *field)
289 {
290 switch(field->type) {
291 case LTTNG_EVENT_FIELD_INTEGER:
292 return "integer";
293 case LTTNG_EVENT_FIELD_ENUM:
294 return "enum";
295 case LTTNG_EVENT_FIELD_FLOAT:
296 return "float";
297 case LTTNG_EVENT_FIELD_STRING:
298 return "string";
299 case LTTNG_EVENT_FIELD_OTHER:
300 default: /* fall-through */
301 return "unknown";
302 }
303 }
304
305 /*
306 * Pretty print single event fields.
307 */
308 static void print_event_field(struct lttng_event_field *field)
309 {
310 if (!field->field_name[0]) {
311 return;
312 }
313 MSG("%sfield: %s (%s)%s", indent8, field->field_name,
314 field_type(field), field->nowrite ? " [no write]" : "");
315 }
316
317 /*
318 * Machine interface
319 * Jul and ust event listing
320 */
321 static int mi_list_agent_ust_events(struct lttng_event *events, int count,
322 struct lttng_domain *domain)
323 {
324 int ret, i;
325 pid_t cur_pid = 0;
326 char *cmdline = NULL;
327 int pid_element_open = 0;
328
329 /* Open domains element */
330 ret = mi_lttng_domains_open(writer);
331 if (ret) {
332 goto end;
333 }
334
335 /* Write domain */
336 ret = mi_lttng_domain(writer, domain, 1);
337 if (ret) {
338 goto end;
339 }
340
341 /* Open pids element */
342 ret = mi_lttng_pids_open(writer);
343 if (ret) {
344 goto end;
345 }
346
347 for (i = 0; i < count; i++) {
348 if (cur_pid != events[i].pid) {
349 if (pid_element_open) {
350 /* Close the previous events and pid element */
351 ret = mi_lttng_close_multi_element(writer, 2);
352 if (ret) {
353 goto end;
354 }
355 pid_element_open = 0;
356 }
357
358 cur_pid = events[i].pid;
359 cmdline = get_cmdline_by_pid(cur_pid);
360 if (!cmdline) {
361 ret = CMD_ERROR;
362 goto end;
363 }
364
365 if (!pid_element_open) {
366 /* Open and write a pid element */
367 ret = mi_lttng_pid(writer, cur_pid, cmdline, 1);
368 if (ret) {
369 goto error;
370 }
371
372 /* Open events element */
373 ret = mi_lttng_events_open(writer);
374 if (ret) {
375 goto error;
376 }
377
378 pid_element_open = 1;
379 }
380 free(cmdline);
381 }
382
383 /* Write an event */
384 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
385 if (ret) {
386 goto end;
387 }
388 }
389
390 /* Close pids */
391 ret = mi_lttng_writer_close_element(writer);
392 if (ret) {
393 goto end;
394 }
395
396 /* Close domain, domains */
397 ret = mi_lttng_close_multi_element(writer, 2);
398 end:
399 return ret;
400 error:
401 free(cmdline);
402 return ret;
403 }
404
405 static int list_agent_events(void)
406 {
407 int i, size, ret = CMD_SUCCESS;
408 struct lttng_domain domain;
409 struct lttng_handle *handle;
410 struct lttng_event *event_list;
411 pid_t cur_pid = 0;
412 char *cmdline = NULL;
413 const char *agent_domain_str;
414
415 memset(&domain, 0, sizeof(domain));
416 if (opt_jul) {
417 domain.type = LTTNG_DOMAIN_JUL;
418 } else if (opt_log4j) {
419 domain.type = LTTNG_DOMAIN_LOG4J;
420 } else if (opt_python) {
421 domain.type = LTTNG_DOMAIN_PYTHON;
422 }
423
424 agent_domain_str = get_domain_str(domain.type);
425
426 DBG("Getting %s tracing events", agent_domain_str);
427
428 handle = lttng_create_handle(NULL, &domain);
429 if (handle == NULL) {
430 ret = CMD_ERROR;
431 goto end;
432 }
433
434 size = lttng_list_tracepoints(handle, &event_list);
435 if (size < 0) {
436 ERR("Unable to list %s events: %s", agent_domain_str,
437 lttng_strerror(size));
438 ret = CMD_ERROR;
439 goto end;
440 }
441
442 if (lttng_opt_mi) {
443 /* Mi print */
444 ret = mi_list_agent_ust_events(event_list, size, &domain);
445 if (ret) {
446 ret = CMD_ERROR;
447 goto error;
448 }
449 } else {
450 /* Pretty print */
451 MSG("%s events (Logger name):\n-------------------------",
452 agent_domain_str);
453
454 if (size == 0) {
455 MSG("None");
456 }
457
458 for (i = 0; i < size; i++) {
459 if (cur_pid != event_list[i].pid) {
460 cur_pid = event_list[i].pid;
461 cmdline = get_cmdline_by_pid(cur_pid);
462 if (cmdline == NULL) {
463 ret = CMD_ERROR;
464 goto error;
465 }
466 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
467 free(cmdline);
468 }
469 MSG("%s- %s", indent6, event_list[i].name);
470 }
471
472 MSG("");
473 }
474
475 error:
476 free(event_list);
477 end:
478 lttng_destroy_handle(handle);
479 return ret;
480 }
481
482 /*
483 * Ask session daemon for all user space tracepoints available.
484 */
485 static int list_ust_events(void)
486 {
487 int i, size, ret = CMD_SUCCESS;
488 struct lttng_domain domain;
489 struct lttng_handle *handle;
490 struct lttng_event *event_list;
491 pid_t cur_pid = 0;
492 char *cmdline = NULL;
493
494 memset(&domain, 0, sizeof(domain));
495
496 DBG("Getting UST tracing events");
497
498 domain.type = LTTNG_DOMAIN_UST;
499
500 handle = lttng_create_handle(NULL, &domain);
501 if (handle == NULL) {
502 ret = CMD_ERROR;
503 goto end;
504 }
505
506 size = lttng_list_tracepoints(handle, &event_list);
507 if (size < 0) {
508 ERR("Unable to list UST events: %s", lttng_strerror(size));
509 ret = CMD_ERROR;
510 goto error;
511 }
512
513 if (lttng_opt_mi) {
514 /* Mi print */
515 ret = mi_list_agent_ust_events(event_list, size, &domain);
516 } else {
517 /* Pretty print */
518 MSG("UST events:\n-------------");
519
520 if (size == 0) {
521 MSG("None");
522 }
523
524 for (i = 0; i < size; i++) {
525 if (cur_pid != event_list[i].pid) {
526 cur_pid = event_list[i].pid;
527 cmdline = get_cmdline_by_pid(cur_pid);
528 if (cmdline == NULL) {
529 ret = CMD_ERROR;
530 goto error;
531 }
532 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
533 free(cmdline);
534 }
535 print_events(&event_list[i]);
536 }
537
538 MSG("");
539 }
540
541 error:
542 free(event_list);
543 end:
544 lttng_destroy_handle(handle);
545 return ret;
546 }
547
548 /*
549 * Machine interface
550 * List all ust event with their fields
551 */
552 static int mi_list_ust_event_fields(struct lttng_event_field *fields, int count,
553 struct lttng_domain *domain)
554 {
555 int ret, i;
556 pid_t cur_pid = 0;
557 char *cmdline = NULL;
558 int pid_element_open = 0;
559 int event_element_open = 0;
560 struct lttng_event cur_event;
561
562 /* Open domains element */
563 ret = mi_lttng_domains_open(writer);
564 if (ret) {
565 goto end;
566 }
567
568 /* Write domain */
569 ret = mi_lttng_domain(writer, domain, 1);
570 if (ret) {
571 goto end;
572 }
573
574 /* Open pids element */
575 ret = mi_lttng_pids_open(writer);
576 if (ret) {
577 goto end;
578 }
579
580 for (i = 0; i < count; i++) {
581 if (cur_pid != fields[i].event.pid) {
582 if (pid_element_open) {
583 if (event_element_open) {
584
585 /* Close the previous field element and event. */
586 ret = mi_lttng_close_multi_element(writer, 2);
587 if (ret) {
588 goto end;
589 }
590 event_element_open = 0;
591 }
592 /* Close the previous events, pid element */
593 ret = mi_lttng_close_multi_element(writer, 2);
594 if (ret) {
595 goto end;
596 }
597 pid_element_open = 0;
598 }
599
600 cur_pid = fields[i].event.pid;
601 cmdline = get_cmdline_by_pid(cur_pid);
602 if (!pid_element_open) {
603 /* Open and write a pid element */
604 ret = mi_lttng_pid(writer, cur_pid, cmdline, 1);
605 if (ret) {
606 goto error;
607 }
608
609 /* Open events element */
610 ret = mi_lttng_events_open(writer);
611 if (ret) {
612 goto error;
613 }
614 pid_element_open = 1;
615 }
616 free(cmdline);
617 /* Wipe current event since we are about to print a new PID. */
618 memset(&cur_event, 0, sizeof(cur_event));
619 }
620
621 if (strcmp(cur_event.name, fields[i].event.name) != 0) {
622 if (event_element_open) {
623 /* Close the previous fields element and the previous event */
624 ret = mi_lttng_close_multi_element(writer, 2);
625 if (ret) {
626 goto end;
627 }
628 event_element_open = 0;
629 }
630
631 memcpy(&cur_event, &fields[i].event,
632 sizeof(cur_event));
633
634 if (!event_element_open) {
635 /* Open and write the event */
636 ret = mi_lttng_event(writer, &cur_event, 1,
637 handle->domain.type);
638 if (ret) {
639 goto end;
640 }
641
642 /* Open a fields element */
643 ret = mi_lttng_event_fields_open(writer);
644 if (ret) {
645 goto end;
646 }
647 event_element_open = 1;
648 }
649 }
650
651 /* Print the event_field */
652 ret = mi_lttng_event_field(writer, &fields[i]);
653 if (ret) {
654 goto end;
655 }
656 }
657
658 /* Close pids, domain, domains */
659 ret = mi_lttng_close_multi_element(writer, 3);
660 end:
661 return ret;
662 error:
663 free(cmdline);
664 return ret;
665 }
666
667 /*
668 * Ask session daemon for all user space tracepoint fields available.
669 */
670 static int list_ust_event_fields(void)
671 {
672 int i, size, ret = CMD_SUCCESS;
673 struct lttng_domain domain;
674 struct lttng_handle *handle;
675 struct lttng_event_field *event_field_list;
676 pid_t cur_pid = 0;
677 char *cmdline = NULL;
678
679 struct lttng_event cur_event;
680
681 memset(&domain, 0, sizeof(domain));
682 memset(&cur_event, 0, sizeof(cur_event));
683
684 DBG("Getting UST tracing event fields");
685
686 domain.type = LTTNG_DOMAIN_UST;
687
688 handle = lttng_create_handle(NULL, &domain);
689 if (handle == NULL) {
690 ret = CMD_ERROR;
691 goto end;
692 }
693
694 size = lttng_list_tracepoint_fields(handle, &event_field_list);
695 if (size < 0) {
696 ERR("Unable to list UST event fields: %s", lttng_strerror(size));
697 ret = CMD_ERROR;
698 goto end;
699 }
700
701 if (lttng_opt_mi) {
702 /* Mi print */
703 ret = mi_list_ust_event_fields(event_field_list, size, &domain);
704 if (ret) {
705 ret = CMD_ERROR;
706 goto error;
707 }
708 } else {
709 /* Pretty print */
710 MSG("UST events:\n-------------");
711
712 if (size == 0) {
713 MSG("None");
714 }
715
716 for (i = 0; i < size; i++) {
717 if (cur_pid != event_field_list[i].event.pid) {
718 cur_pid = event_field_list[i].event.pid;
719 cmdline = get_cmdline_by_pid(cur_pid);
720 if (cmdline == NULL) {
721 ret = CMD_ERROR;
722 goto error;
723 }
724 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
725 free(cmdline);
726 /* Wipe current event since we are about to print a new PID. */
727 memset(&cur_event, 0, sizeof(cur_event));
728 }
729 if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
730 print_events(&event_field_list[i].event);
731 memcpy(&cur_event, &event_field_list[i].event,
732 sizeof(cur_event));
733 }
734 print_event_field(&event_field_list[i]);
735 }
736
737 MSG("");
738 }
739
740 error:
741 free(event_field_list);
742 end:
743 lttng_destroy_handle(handle);
744 return ret;
745 }
746
747 /*
748 * Machine interface
749 * Print a list of kernel events
750 */
751 static int mi_list_kernel_events(struct lttng_event *events, int count,
752 struct lttng_domain *domain)
753 {
754 int ret, i;
755
756 /* Open domains element */
757 ret = mi_lttng_domains_open(writer);
758 if (ret) {
759 goto end;
760 }
761
762 /* Write domain */
763 ret = mi_lttng_domain(writer, domain, 1);
764 if (ret) {
765 goto end;
766 }
767
768 /* Open events */
769 ret = mi_lttng_events_open(writer);
770 if (ret) {
771 goto end;
772 }
773
774 for (i = 0; i < count; i++) {
775 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
776 if (ret) {
777 goto end;
778 }
779 }
780
781 /* close events, domain and domains */
782 ret = mi_lttng_close_multi_element(writer, 3);
783 if (ret) {
784 goto end;
785 }
786
787 end:
788 return ret;
789 }
790
791 /*
792 * Ask for all trace events in the kernel
793 */
794 static int list_kernel_events(void)
795 {
796 int i, size, ret = CMD_SUCCESS;
797 struct lttng_domain domain;
798 struct lttng_handle *handle;
799 struct lttng_event *event_list;
800
801 memset(&domain, 0, sizeof(domain));
802
803 DBG("Getting kernel tracing events");
804
805 domain.type = LTTNG_DOMAIN_KERNEL;
806
807 handle = lttng_create_handle(NULL, &domain);
808 if (handle == NULL) {
809 ret = CMD_ERROR;
810 goto error;
811 }
812
813 size = lttng_list_tracepoints(handle, &event_list);
814 if (size < 0) {
815 ERR("Unable to list kernel events: %s", lttng_strerror(size));
816 lttng_destroy_handle(handle);
817 return CMD_ERROR;
818 }
819
820 if (lttng_opt_mi) {
821 /* Mi print */
822 ret = mi_list_kernel_events(event_list, size, &domain);
823 if (ret) {
824 ret = CMD_ERROR;
825 goto end;
826 }
827 } else {
828 MSG("Kernel events:\n-------------");
829
830 for (i = 0; i < size; i++) {
831 print_events(&event_list[i]);
832 }
833
834 MSG("");
835 }
836
837 end:
838 free(event_list);
839
840 lttng_destroy_handle(handle);
841 return ret;
842
843 error:
844 lttng_destroy_handle(handle);
845 return ret;
846 }
847
848 /*
849 * Machine interface
850 * Print a list of system calls.
851 */
852 static int mi_list_syscalls(struct lttng_event *events, int count)
853 {
854 int ret, i;
855
856 /* Open events */
857 ret = mi_lttng_events_open(writer);
858 if (ret) {
859 goto end;
860 }
861
862 for (i = 0; i < count; i++) {
863 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
864 if (ret) {
865 goto end;
866 }
867 }
868
869 /* Close events. */
870 ret = mi_lttng_writer_close_element(writer);
871 if (ret) {
872 goto end;
873 }
874
875 end:
876 return ret;
877 }
878
879 /*
880 * Ask for kernel system calls.
881 */
882 static int list_syscalls(void)
883 {
884 int i, size, ret = CMD_SUCCESS;
885 struct lttng_event *event_list;
886
887 DBG("Getting kernel system call events");
888
889 size = lttng_list_syscalls(&event_list);
890 if (size < 0) {
891 ERR("Unable to list system calls: %s", lttng_strerror(size));
892 ret = CMD_ERROR;
893 goto error;
894 }
895
896 if (lttng_opt_mi) {
897 /* Mi print */
898 ret = mi_list_syscalls(event_list, size);
899 if (ret) {
900 ret = CMD_ERROR;
901 goto end;
902 }
903 } else {
904 MSG("System calls:\n-------------");
905
906 for (i = 0; i < size; i++) {
907 print_events(&event_list[i]);
908 }
909
910 MSG("");
911 }
912
913 end:
914 free(event_list);
915 return ret;
916
917 error:
918 return ret;
919 }
920
921 /*
922 * Machine Interface
923 * Print a list of agent events
924 */
925 static int mi_list_session_agent_events(struct lttng_event *events, int count)
926 {
927 int ret, i;
928
929 /* Open events element */
930 ret = mi_lttng_events_open(writer);
931 if (ret) {
932 goto end;
933 }
934
935 for (i = 0; i < count; i++) {
936 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
937 if (ret) {
938 goto end;
939 }
940 }
941
942 /* Close events element */
943 ret = mi_lttng_writer_close_element(writer);
944
945 end:
946 return ret;
947 }
948
949 /*
950 * List agent events for a specific session using the handle.
951 *
952 * Return CMD_SUCCESS on success else a negative value.
953 */
954 static int list_session_agent_events(void)
955 {
956 int ret = CMD_SUCCESS, count, i;
957 struct lttng_event *events = NULL;
958
959 count = lttng_list_events(handle, "", &events);
960 if (count < 0) {
961 ret = CMD_ERROR;
962 ERR("%s", lttng_strerror(count));
963 goto error;
964 }
965
966 if (lttng_opt_mi) {
967 /* Mi print */
968 ret = mi_list_session_agent_events(events, count);
969 if (ret) {
970 ret = CMD_ERROR;
971 goto end;
972 }
973 } else {
974 /* Pretty print */
975 MSG("Events (Logger name):\n---------------------");
976 if (count == 0) {
977 MSG("%sNone\n", indent6);
978 goto end;
979 }
980
981 for (i = 0; i < count; i++) {
982 MSG("%s- %s%s (loglevel%s %s)", indent4, events[i].name,
983 enabled_string(events[i].enabled),
984 logleveltype_string(events[i].loglevel_type),
985 mi_lttng_loglevel_string(events[i].loglevel,
986 handle->domain.type));
987 }
988
989 MSG("");
990 }
991
992 end:
993 free(events);
994 error:
995 return ret;
996 }
997
998 /*
999 * Machine interface
1000 * print a list of event
1001 */
1002 static int mi_list_events(struct lttng_event *events, int count)
1003 {
1004 int ret, i;
1005
1006 /* Open events element */
1007 ret = mi_lttng_events_open(writer);
1008 if (ret) {
1009 goto end;
1010 }
1011
1012 for (i = 0; i < count; i++) {
1013 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
1014 if (ret) {
1015 goto end;
1016 }
1017 }
1018
1019 /* Close events element */
1020 ret = mi_lttng_writer_close_element(writer);
1021
1022 end:
1023 return ret;
1024 }
1025
1026 /*
1027 * List events of channel of session and domain.
1028 */
1029 static int list_events(const char *channel_name)
1030 {
1031 int ret = CMD_SUCCESS, count, i;
1032 struct lttng_event *events = NULL;
1033
1034 count = lttng_list_events(handle, channel_name, &events);
1035 if (count < 0) {
1036 ret = CMD_ERROR;
1037 ERR("%s", lttng_strerror(count));
1038 goto error;
1039 }
1040
1041 if (lttng_opt_mi) {
1042 /* Mi print */
1043 ret = mi_list_events(events, count);
1044 if (ret) {
1045 ret = CMD_ERROR;
1046 goto end;
1047 }
1048 } else {
1049 /* Pretty print */
1050 MSG("\n%sEvents:", indent4);
1051 if (count == 0) {
1052 MSG("%sNone\n", indent6);
1053 goto end;
1054 }
1055
1056 for (i = 0; i < count; i++) {
1057 print_events(&events[i]);
1058 }
1059
1060 MSG("");
1061 }
1062 end:
1063 free(events);
1064 error:
1065 return ret;
1066 }
1067
1068 /*
1069 * Pretty print channel
1070 */
1071 static void print_channel(struct lttng_channel *channel)
1072 {
1073 MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
1074
1075 MSG("%sAttributes:", indent4);
1076 MSG("%soverwrite mode: %d", indent6, channel->attr.overwrite);
1077 MSG("%ssubbufers size: %" PRIu64, indent6, channel->attr.subbuf_size);
1078 MSG("%snumber of subbufers: %" PRIu64, indent6, channel->attr.num_subbuf);
1079 MSG("%sswitch timer interval: %u", indent6, channel->attr.switch_timer_interval);
1080 MSG("%sread timer interval: %u", indent6, channel->attr.read_timer_interval);
1081 MSG("%strace file count: %" PRIu64, indent6, channel->attr.tracefile_count);
1082 MSG("%strace file size (bytes): %" PRIu64, indent6, channel->attr.tracefile_size);
1083 switch (channel->attr.output) {
1084 case LTTNG_EVENT_SPLICE:
1085 MSG("%soutput: splice()", indent6);
1086 break;
1087 case LTTNG_EVENT_MMAP:
1088 MSG("%soutput: mmap()", indent6);
1089 break;
1090 }
1091 }
1092
1093 /*
1094 * Machine interface
1095 * Print a list of channel
1096 *
1097 */
1098 static int mi_list_channels(struct lttng_channel *channels, int count,
1099 const char *channel_name)
1100 {
1101 int i, ret;
1102 unsigned int chan_found = 0;
1103
1104 /* Open channels element */
1105 ret = mi_lttng_channels_open(writer);
1106 if (ret) {
1107 goto error;
1108 }
1109
1110 for (i = 0; i < count; i++) {
1111 if (channel_name != NULL) {
1112 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
1113 chan_found = 1;
1114 } else {
1115 continue;
1116 }
1117 }
1118
1119 /* Write channel element and leave it open */
1120 ret = mi_lttng_channel(writer, &channels[i], 1);
1121 if (ret) {
1122 goto error;
1123 }
1124
1125 /* Listing events per channel */
1126 ret = list_events(channels[i].name);
1127 if (ret) {
1128 goto error;
1129 }
1130
1131 /* Closing the channel element we opened earlier */
1132 ret = mi_lttng_writer_close_element(writer);
1133 if (ret) {
1134 goto error;
1135 }
1136
1137 if (chan_found) {
1138 break;
1139 }
1140 }
1141
1142 /* Close channels element */
1143 ret = mi_lttng_writer_close_element(writer);
1144 if (ret) {
1145 goto error;
1146 }
1147
1148 error:
1149 return ret;
1150 }
1151
1152 /*
1153 * List channel(s) of session and domain.
1154 *
1155 * If channel_name is NULL, all channels are listed.
1156 */
1157 static int list_channels(const char *channel_name)
1158 {
1159 int count, i, ret = CMD_SUCCESS;
1160 unsigned int chan_found = 0;
1161 struct lttng_channel *channels = NULL;
1162
1163 DBG("Listing channel(s) (%s)", channel_name ? : "<all>");
1164
1165 count = lttng_list_channels(handle, &channels);
1166 if (count < 0) {
1167 switch (-count) {
1168 case LTTNG_ERR_KERN_CHAN_NOT_FOUND:
1169 if (lttng_opt_mi) {
1170 /* When printing mi this is not an error
1171 * but an empty channels element */
1172 count = 0;
1173 } else {
1174 ret = CMD_SUCCESS;
1175 WARN("No kernel channel");
1176 goto error_channels;
1177 }
1178 break;
1179 default:
1180 /* We had a real error */
1181 ret = CMD_ERROR;
1182 ERR("%s", lttng_strerror(count));
1183 goto error_channels;
1184 break;
1185 }
1186 }
1187
1188 if (lttng_opt_mi) {
1189 /* Mi print */
1190 ret = mi_list_channels(channels, count, channel_name);
1191 if (ret) {
1192 ret = CMD_ERROR;
1193 goto error;
1194 }
1195 } else {
1196 /* Pretty print */
1197 if (count) {
1198 MSG("Channels:\n-------------");
1199 }
1200
1201 for (i = 0; i < count; i++) {
1202 if (channel_name != NULL) {
1203 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
1204 chan_found = 1;
1205 } else {
1206 continue;
1207 }
1208 }
1209 print_channel(&channels[i]);
1210
1211 /* Listing events per channel */
1212 ret = list_events(channels[i].name);
1213 if (ret) {
1214 goto error;
1215 }
1216
1217 if (chan_found) {
1218 break;
1219 }
1220 }
1221
1222 if (!chan_found && channel_name != NULL) {
1223 ret = CMD_ERROR;
1224 ERR("Channel %s not found", channel_name);
1225 goto error;
1226 }
1227 }
1228 error:
1229 free(channels);
1230
1231 error_channels:
1232 return ret;
1233 }
1234
1235 /*
1236 * List tracker PID(s) of session and domain.
1237 */
1238 static int list_tracker_pids(void)
1239 {
1240 int enabled, ret;
1241 int *pids = NULL;
1242 size_t nr_pids;
1243
1244 ret = lttng_list_tracker_pids(handle,
1245 &enabled, &pids, &nr_pids);
1246 if (ret) {
1247 return ret;
1248 }
1249 if (enabled) {
1250 int i;
1251 _MSG("PID tracker: [");
1252
1253 for (i = 0; i < nr_pids; i++) {
1254 if (i) {
1255 _MSG(",");
1256 }
1257 _MSG(" %d", pids[i]);
1258 }
1259 _MSG(" ]\n\n");
1260 }
1261 free(pids);
1262 return 0;
1263 }
1264
1265 /*
1266 * Machine interface
1267 * Find the session with session_name as name
1268 * and print his informations.
1269 */
1270 static int mi_list_session(const char *session_name,
1271 struct lttng_session *sessions, int count)
1272 {
1273 int ret, i;
1274 unsigned int session_found = 0;
1275
1276 if (session_name == NULL) {
1277 ret = -LTTNG_ERR_SESS_NOT_FOUND;
1278 goto end;
1279 }
1280
1281 for (i = 0; i < count; i++) {
1282 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
1283 /* We need to leave it open to append other informations
1284 * like domain, channel, events etc.*/
1285 session_found = 1;
1286 ret = mi_lttng_session(writer, &sessions[i], 1);
1287 if (ret) {
1288 goto end;
1289 }
1290 break;
1291 }
1292 }
1293
1294 if (!session_found) {
1295 ERR("Session '%s' not found", session_name);
1296 ret = -LTTNG_ERR_SESS_NOT_FOUND;
1297 goto end;
1298 }
1299
1300 end:
1301 return ret;
1302 }
1303
1304 /*
1305 * Machine interface
1306 * List all availables session
1307 */
1308 static int mi_list_sessions(struct lttng_session *sessions, int count)
1309 {
1310 int ret, i;
1311
1312 /* Opening sessions element */
1313 ret = mi_lttng_sessions_open(writer);
1314 if (ret) {
1315 goto end;
1316 }
1317
1318 /* Listing sessions */
1319 for (i = 0; i < count; i++) {
1320 ret = mi_lttng_session(writer, &sessions[i], 0);
1321 if (ret) {
1322 goto end;
1323 }
1324 }
1325
1326 /* Closing sessions element */
1327 ret = mi_lttng_writer_close_element(writer);
1328 if (ret) {
1329 goto end;
1330 }
1331
1332 end:
1333 return ret;
1334 }
1335
1336 /*
1337 * List available tracing session. List only basic information.
1338 *
1339 * If session_name is NULL, all sessions are listed.
1340 */
1341 static int list_sessions(const char *session_name)
1342 {
1343 int ret = CMD_SUCCESS;
1344 int count, i;
1345 unsigned int session_found = 0;
1346 struct lttng_session *sessions;
1347
1348 count = lttng_list_sessions(&sessions);
1349 DBG("Session count %d", count);
1350 if (count < 0) {
1351 ret = CMD_ERROR;
1352 ERR("%s", lttng_strerror(count));
1353 goto end;
1354 }
1355
1356 if (lttng_opt_mi) {
1357 /* Mi */
1358 if (session_name == NULL) {
1359 /* List all session */
1360 ret = mi_list_sessions(sessions, count);
1361 } else {
1362 /* Note : this return an open session element */
1363 ret = mi_list_session(session_name, sessions, count);
1364 }
1365 if (ret) {
1366 ret = CMD_ERROR;
1367 goto error;
1368 }
1369 } else {
1370 /* Pretty print */
1371 if (count == 0) {
1372 MSG("Currently no available tracing session");
1373 goto end;
1374 }
1375
1376 if (session_name == NULL) {
1377 MSG("Available tracing sessions:");
1378 }
1379
1380
1381 for (i = 0; i < count; i++) {
1382 if (session_name != NULL) {
1383 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
1384 session_found = 1;
1385 MSG("Tracing session %s: [%s%s]", session_name,
1386 active_string(sessions[i].enabled),
1387 snapshot_string(sessions[i].snapshot_mode));
1388 MSG("%sTrace path: %s\n", indent4, sessions[i].path);
1389 break;
1390 }
1391 } else {
1392 MSG(" %d) %s (%s) [%s%s]", i + 1,
1393 sessions[i].name, sessions[i].path,
1394 active_string(sessions[i].enabled),
1395 snapshot_string(sessions[i].snapshot_mode));
1396 MSG("%sTrace path: %s", indent4, sessions[i].path);
1397 if (sessions[i].live_timer_interval != 0) {
1398 MSG("%sLive timer interval (usec): %u", indent4,
1399 sessions[i].live_timer_interval);
1400 }
1401 MSG("");
1402 }
1403 }
1404
1405 if (!session_found && session_name != NULL) {
1406 ERR("Session '%s' not found", session_name);
1407 ret = CMD_ERROR;
1408 goto error;
1409 }
1410
1411 if (session_name == NULL) {
1412 MSG("\nUse lttng list <session_name> for more details");
1413 }
1414 }
1415
1416 error:
1417 free(sessions);
1418 end:
1419 return ret;
1420 }
1421
1422
1423 /*
1424 * Machine Interface
1425 * list available domain(s) for a session.
1426 */
1427 static int mi_list_domains(struct lttng_domain *domains, int count)
1428 {
1429 int i, ret;
1430 /* Open domains element */
1431 ret = mi_lttng_domains_open(writer);
1432 if (ret) {
1433 goto end;
1434 }
1435
1436 for (i = 0; i < count; i++) {
1437 ret = mi_lttng_domain(writer, &domains[i] , 0);
1438 if (ret) {
1439 goto end;
1440 }
1441 }
1442
1443 /* Closing domains element */
1444 ret = mi_lttng_writer_close_element(writer);
1445 if (ret) {
1446 goto end;
1447 }
1448 end:
1449 return ret;
1450 }
1451
1452 /*
1453 * List available domain(s) for a session.
1454 */
1455 static int list_domains(const char *session_name)
1456 {
1457 int i, count, ret = CMD_SUCCESS;
1458 struct lttng_domain *domains = NULL;
1459
1460
1461 count = lttng_list_domains(session_name, &domains);
1462 if (count < 0) {
1463 ret = CMD_ERROR;
1464 ERR("%s", lttng_strerror(count));
1465 goto end;
1466 }
1467
1468 if (lttng_opt_mi) {
1469 /* Mi output */
1470 ret = mi_list_domains(domains, count);
1471 if (ret) {
1472 ret = CMD_ERROR;
1473 goto error;
1474 }
1475 } else {
1476 /* Pretty print */
1477 MSG("Domains:\n-------------");
1478 if (count == 0) {
1479 MSG(" None");
1480 goto end;
1481 }
1482
1483 for (i = 0; i < count; i++) {
1484 switch (domains[i].type) {
1485 case LTTNG_DOMAIN_KERNEL:
1486 MSG(" - Kernel");
1487 break;
1488 case LTTNG_DOMAIN_UST:
1489 MSG(" - UST global");
1490 break;
1491 case LTTNG_DOMAIN_JUL:
1492 MSG(" - JUL (Java Util Logging)");
1493 break;
1494 case LTTNG_DOMAIN_LOG4J:
1495 MSG(" - LOG4j (Logging for Java)");
1496 break;
1497 case LTTNG_DOMAIN_PYTHON:
1498 MSG(" - Python (logging)");
1499 break;
1500 default:
1501 break;
1502 }
1503 }
1504 }
1505
1506 error:
1507 free(domains);
1508
1509 end:
1510 return ret;
1511 }
1512
1513 /*
1514 * The 'list <options>' first level command
1515 */
1516 int cmd_list(int argc, const char **argv)
1517 {
1518 int opt, ret = CMD_SUCCESS;
1519 const char *session_name;
1520 static poptContext pc;
1521 struct lttng_domain domain;
1522 struct lttng_domain *domains = NULL;
1523
1524 memset(&domain, 0, sizeof(domain));
1525
1526 if (argc < 1) {
1527 usage(stderr);
1528 ret = CMD_ERROR;
1529 goto end;
1530 }
1531
1532 pc = poptGetContext(NULL, argc, argv, long_options, 0);
1533 poptReadDefaultConfig(pc, 0);
1534
1535 while ((opt = poptGetNextOpt(pc)) != -1) {
1536 switch (opt) {
1537 case OPT_HELP:
1538 usage(stdout);
1539 goto end;
1540 case OPT_USERSPACE:
1541 opt_userspace = 1;
1542 break;
1543 case OPT_LIST_OPTIONS:
1544 list_cmd_options(stdout, long_options);
1545 goto end;
1546 default:
1547 usage(stderr);
1548 ret = CMD_UNDEFINED;
1549 goto end;
1550 }
1551 }
1552
1553 /* Mi check */
1554 if (lttng_opt_mi) {
1555 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
1556 if (!writer) {
1557 ret = CMD_ERROR;
1558 goto end;
1559 }
1560
1561 /* Open command element */
1562 ret = mi_lttng_writer_command_open(writer,
1563 mi_lttng_element_command_list);
1564 if (ret) {
1565 ret = CMD_ERROR;
1566 goto end;
1567 }
1568
1569 /* Open output element */
1570 ret = mi_lttng_writer_open_element(writer,
1571 mi_lttng_element_command_output);
1572 if (ret) {
1573 ret = CMD_ERROR;
1574 goto end;
1575 }
1576 }
1577
1578 /* Get session name (trailing argument) */
1579 session_name = poptGetArg(pc);
1580 DBG2("Session name: %s", session_name);
1581
1582 if (opt_kernel) {
1583 domain.type = LTTNG_DOMAIN_KERNEL;
1584 } else if (opt_userspace) {
1585 DBG2("Listing userspace global domain");
1586 domain.type = LTTNG_DOMAIN_UST;
1587 } else if (opt_jul) {
1588 DBG2("Listing JUL domain");
1589 domain.type = LTTNG_DOMAIN_JUL;
1590 } else if (opt_log4j) {
1591 domain.type = LTTNG_DOMAIN_LOG4J;
1592 } else if (opt_python) {
1593 domain.type = LTTNG_DOMAIN_PYTHON;
1594 }
1595
1596 if (!opt_kernel && opt_syscall) {
1597 WARN("--syscall will only work with the Kernel domain (-k)");
1598 ret = CMD_ERROR;
1599 goto end;
1600 }
1601
1602 if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) {
1603 handle = lttng_create_handle(session_name, &domain);
1604 if (handle == NULL) {
1605 ret = CMD_FATAL;
1606 goto end;
1607 }
1608 }
1609
1610 if (session_name == NULL) {
1611 if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j
1612 && !opt_python) {
1613 ret = list_sessions(NULL);
1614 if (ret) {
1615 goto end;
1616 }
1617 }
1618 if (opt_kernel) {
1619 if (opt_syscall) {
1620 ret = list_syscalls();
1621 if (ret) {
1622 goto end;
1623 }
1624 } else {
1625 ret = list_kernel_events();
1626 if (ret) {
1627 goto end;
1628 }
1629 }
1630 }
1631 if (opt_userspace) {
1632 if (opt_fields) {
1633 ret = list_ust_event_fields();
1634 } else {
1635 ret = list_ust_events();
1636 }
1637 if (ret) {
1638 goto end;
1639 }
1640 }
1641 if (opt_jul || opt_log4j || opt_python) {
1642 ret = list_agent_events();
1643 if (ret) {
1644 goto end;
1645 }
1646 }
1647 } else {
1648 /* List session attributes */
1649 if (lttng_opt_mi) {
1650 /* Open element sessions
1651 * Present for xml consistency */
1652 ret = mi_lttng_sessions_open(writer);
1653 if (ret) {
1654 goto end;
1655 }
1656 }
1657 /* MI: the ouptut of list_sessions is an unclosed session element */
1658 ret = list_sessions(session_name);
1659 if (ret) {
1660 goto end;
1661 }
1662
1663 /* Domain listing */
1664 if (opt_domain) {
1665 ret = list_domains(session_name);
1666 goto end;
1667 }
1668
1669 /* Channel listing */
1670 if (opt_kernel || opt_userspace) {
1671 if (lttng_opt_mi) {
1672 /* Add of domains and domain element for xml
1673 * consistency and validation
1674 */
1675 ret = mi_lttng_domains_open(writer);
1676 if (ret) {
1677 goto end;
1678 }
1679
1680 /* Open domain and leave it open for
1681 * nested channels printing */
1682 ret = mi_lttng_domain(writer, &domain, 1);
1683 if (ret) {
1684 goto end;
1685 }
1686
1687 }
1688
1689 ret = list_tracker_pids();
1690 if (ret) {
1691 goto end;
1692 }
1693
1694 ret = list_channels(opt_channel);
1695 if (ret) {
1696 goto end;
1697 }
1698
1699 if (lttng_opt_mi) {
1700 /* Close domain and domain element */
1701 ret = mi_lttng_close_multi_element(writer, 2);
1702 }
1703 if (ret) {
1704 goto end;
1705 }
1706
1707
1708 } else {
1709 int i, nb_domain;
1710
1711 /* We want all domain(s) */
1712 nb_domain = lttng_list_domains(session_name, &domains);
1713 if (nb_domain < 0) {
1714 ret = CMD_ERROR;
1715 ERR("%s", lttng_strerror(nb_domain));
1716 goto end;
1717 }
1718
1719 if (lttng_opt_mi) {
1720 ret = mi_lttng_domains_open(writer);
1721 if (ret) {
1722 ret = CMD_ERROR;
1723 goto end;
1724 }
1725 }
1726
1727 for (i = 0; i < nb_domain; i++) {
1728 switch (domains[i].type) {
1729 case LTTNG_DOMAIN_KERNEL:
1730 MSG("=== Domain: Kernel ===\n");
1731 break;
1732 case LTTNG_DOMAIN_UST:
1733 MSG("=== Domain: UST global ===\n");
1734 MSG("Buffer type: %s\n",
1735 domains[i].buf_type ==
1736 LTTNG_BUFFER_PER_PID ? "per PID" : "per UID");
1737 break;
1738 case LTTNG_DOMAIN_JUL:
1739 MSG("=== Domain: JUL (Java Util Logging) ===\n");
1740 break;
1741 case LTTNG_DOMAIN_LOG4J:
1742 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
1743 break;
1744 case LTTNG_DOMAIN_PYTHON:
1745 MSG("=== Domain: Python (logging) ===\n");
1746 break;
1747 default:
1748 MSG("=== Domain: Unimplemented ===\n");
1749 break;
1750 }
1751
1752 if (lttng_opt_mi) {
1753 ret = mi_lttng_domain(writer, &domains[i], 1);
1754 if (ret) {
1755 ret = CMD_ERROR;
1756 goto end;
1757 }
1758 }
1759
1760 /* Clean handle before creating a new one */
1761 if (handle) {
1762 lttng_destroy_handle(handle);
1763 }
1764
1765 handle = lttng_create_handle(session_name, &domains[i]);
1766 if (handle == NULL) {
1767 ret = CMD_FATAL;
1768 goto end;
1769 }
1770
1771 if (domains[i].type == LTTNG_DOMAIN_JUL ||
1772 domains[i].type == LTTNG_DOMAIN_LOG4J ||
1773 domains[i].type == LTTNG_DOMAIN_PYTHON) {
1774 ret = list_session_agent_events();
1775 if (ret) {
1776 goto end;
1777 }
1778 continue;
1779 }
1780
1781 switch (domains[i].type) {
1782 case LTTNG_DOMAIN_KERNEL:
1783 case LTTNG_DOMAIN_UST:
1784 ret = list_tracker_pids();
1785 if (ret) {
1786 goto end;
1787 }
1788 break;
1789 default:
1790 break;
1791 }
1792
1793 ret = list_channels(opt_channel);
1794 if (ret) {
1795 goto end;
1796 }
1797
1798 if (lttng_opt_mi) {
1799 /* Close domain element */
1800 ret = mi_lttng_writer_close_element(writer);
1801 if (ret) {
1802 ret = CMD_ERROR;
1803 goto end;
1804 }
1805 }
1806
1807 }
1808 if (lttng_opt_mi) {
1809 /* Close the domains, session and sessions element */
1810 ret = mi_lttng_close_multi_element(writer, 3);
1811 if (ret) {
1812 ret = CMD_ERROR;
1813 goto end;
1814 }
1815 }
1816 }
1817 }
1818
1819 /* Mi closing */
1820 if (lttng_opt_mi) {
1821 /* Close output element */
1822 ret = mi_lttng_writer_close_element(writer);
1823 if (ret) {
1824 ret = CMD_ERROR;
1825 goto end;
1826 }
1827
1828 /* Command element close */
1829 ret = mi_lttng_writer_command_close(writer);
1830 if (ret) {
1831 ret = CMD_ERROR;
1832 goto end;
1833 }
1834 }
1835 end:
1836 /* Mi clean-up */
1837 if (writer && mi_lttng_writer_destroy(writer)) {
1838 /* Preserve original error code */
1839 ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
1840 }
1841
1842 free(domains);
1843 if (handle) {
1844 lttng_destroy_handle(handle);
1845 }
1846
1847 poptFreeContext(pc);
1848 return ret;
1849 }
This page took 0.115117 seconds and 4 git commands to generate.