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