Implement UST PID tracker
[lttng-tools.git] / src / bin / lttng / commands / list.c
... / ...
CommitLineData
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
31static int opt_userspace;
32static int opt_kernel;
33static int opt_jul;
34static int opt_log4j;
35static int opt_python;
36static char *opt_channel;
37static int opt_domain;
38static int opt_fields;
39static int opt_syscall;
40#if 0
41/* Not implemented yet */
42static char *opt_cmd_name;
43static pid_t opt_pid;
44#endif
45
46const char *indent4 = " ";
47const char *indent6 = " ";
48const char *indent8 = " ";
49
50enum {
51 OPT_HELP = 1,
52 OPT_USERSPACE,
53 OPT_LIST_OPTIONS,
54};
55
56static struct lttng_handle *handle;
57static struct mi_writer *writer;
58
59static 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 */
84static 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 */
118static 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
142end:
143 if (fp) {
144 fclose(fp);
145 }
146 return cmdline;
147}
148
149static
150const 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
160static const char *snapshot_string(int value)
161{
162 switch (value) {
163 case 1:
164 return " snapshot";
165 default:
166 return "";
167 }
168}
169
170static
171const 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
181static
182const char *filter_string(int value)
183{
184 switch (value) {
185 case 1: return " [with filter]";
186 default: return "";
187 }
188}
189
190static
191const char *exclusion_string(int value)
192{
193 switch (value) {
194 case 1: return " [has exclusions]";
195 default: return "";
196 }
197}
198
199static 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
213static 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 */
231static 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
302static 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 */
322static 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 */
335static 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);
412end:
413 return ret;
414error:
415 free(cmdline);
416 return ret;
417}
418
419static 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
489error:
490 free(event_list);
491end:
492 lttng_destroy_handle(handle);
493 return ret;
494}
495
496/*
497 * Ask session daemon for all user space tracepoints available.
498 */
499static 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
555error:
556 free(event_list);
557end:
558 lttng_destroy_handle(handle);
559 return ret;
560}
561
562/*
563 * Machine interface
564 * List all ust event with their fields
565 */
566static 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);
674end:
675 return ret;
676error:
677 free(cmdline);
678 return ret;
679}
680
681/*
682 * Ask session daemon for all user space tracepoint fields available.
683 */
684static 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
754error:
755 free(event_field_list);
756end:
757 lttng_destroy_handle(handle);
758 return ret;
759}
760
761/*
762 * Machine interface
763 * Print a list of kernel events
764 */
765static 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
801end:
802 return ret;
803}
804
805/*
806 * Ask for all trace events in the kernel
807 */
808static 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
851end:
852 free(event_list);
853
854 lttng_destroy_handle(handle);
855 return ret;
856
857error:
858 lttng_destroy_handle(handle);
859 return ret;
860}
861
862/*
863 * Machine interface
864 * Print a list of system calls.
865 */
866static 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
889end:
890 return ret;
891}
892
893/*
894 * Ask for kernel system calls.
895 */
896static 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
927end:
928 free(event_list);
929 return ret;
930
931error:
932 return ret;
933}
934
935/*
936 * Machine Interface
937 * Print a list of agent events
938 */
939static 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
959end:
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 */
968static 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
1006end:
1007 free(events);
1008error:
1009 return ret;
1010}
1011
1012/*
1013 * Machine interface
1014 * print a list of event
1015 */
1016static 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
1036end:
1037 return ret;
1038}
1039
1040/*
1041 * List events of channel of session and domain.
1042 */
1043static 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 }
1076end:
1077 free(events);
1078error:
1079 return ret;
1080}
1081
1082/*
1083 * Pretty print channel
1084 */
1085static 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 */
1112static 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
1162error:
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 */
1171static 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 }
1242error:
1243 free(channels);
1244
1245error_channels:
1246 return ret;
1247}
1248
1249/*
1250 * Machine interface
1251 * Find the session with session_name as name
1252 * and print his informations.
1253 */
1254static int mi_list_session(const char *session_name,
1255 struct lttng_session *sessions, int count)
1256{
1257 int ret, i;
1258 unsigned int session_found = 0;
1259
1260 if (session_name == NULL) {
1261 ret = -LTTNG_ERR_SESS_NOT_FOUND;
1262 goto end;
1263 }
1264
1265 for (i = 0; i < count; i++) {
1266 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
1267 /* We need to leave it open to append other informations
1268 * like domain, channel, events etc.*/
1269 session_found = 1;
1270 ret = mi_lttng_session(writer, &sessions[i], 1);
1271 if (ret) {
1272 goto end;
1273 }
1274 break;
1275 }
1276 }
1277
1278 if (!session_found) {
1279 ERR("Session '%s' not found", session_name);
1280 ret = -LTTNG_ERR_SESS_NOT_FOUND;
1281 goto end;
1282 }
1283
1284end:
1285 return ret;
1286}
1287
1288/*
1289 * Machine interface
1290 * List all availables session
1291 */
1292static int mi_list_sessions(struct lttng_session *sessions, int count)
1293{
1294 int ret, i;
1295
1296 /* Opening sessions element */
1297 ret = mi_lttng_sessions_open(writer);
1298 if (ret) {
1299 goto end;
1300 }
1301
1302 /* Listing sessions */
1303 for (i = 0; i < count; i++) {
1304 ret = mi_lttng_session(writer, &sessions[i], 0);
1305 if (ret) {
1306 goto end;
1307 }
1308 }
1309
1310 /* Closing sessions element */
1311 ret = mi_lttng_writer_close_element(writer);
1312 if (ret) {
1313 goto end;
1314 }
1315
1316end:
1317 return ret;
1318}
1319
1320/*
1321 * List available tracing session. List only basic information.
1322 *
1323 * If session_name is NULL, all sessions are listed.
1324 */
1325static int list_sessions(const char *session_name)
1326{
1327 int ret = CMD_SUCCESS;
1328 int count, i;
1329 unsigned int session_found = 0;
1330 struct lttng_session *sessions;
1331
1332 count = lttng_list_sessions(&sessions);
1333 DBG("Session count %d", count);
1334 if (count < 0) {
1335 ret = CMD_ERROR;
1336 ERR("%s", lttng_strerror(count));
1337 goto end;
1338 }
1339
1340 if (lttng_opt_mi) {
1341 /* Mi */
1342 if (session_name == NULL) {
1343 /* List all session */
1344 ret = mi_list_sessions(sessions, count);
1345 } else {
1346 /* Note : this return an open session element */
1347 ret = mi_list_session(session_name, sessions, count);
1348 }
1349 if (ret) {
1350 ret = CMD_ERROR;
1351 goto error;
1352 }
1353 } else {
1354 /* Pretty print */
1355 if (count == 0) {
1356 MSG("Currently no available tracing session");
1357 goto end;
1358 }
1359
1360 if (session_name == NULL) {
1361 MSG("Available tracing sessions:");
1362 }
1363
1364
1365 for (i = 0; i < count; i++) {
1366 if (session_name != NULL) {
1367 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
1368 session_found = 1;
1369 MSG("Tracing session %s: [%s%s]", session_name,
1370 active_string(sessions[i].enabled),
1371 snapshot_string(sessions[i].snapshot_mode));
1372 MSG("%sTrace path: %s\n", indent4, sessions[i].path);
1373 break;
1374 }
1375 } else {
1376 MSG(" %d) %s (%s) [%s%s]", i + 1,
1377 sessions[i].name, sessions[i].path,
1378 active_string(sessions[i].enabled),
1379 snapshot_string(sessions[i].snapshot_mode));
1380 MSG("%sTrace path: %s", indent4, sessions[i].path);
1381 MSG("%sLive timer interval (usec): %u\n", indent4,
1382 sessions[i].live_timer_interval);
1383 }
1384 }
1385
1386 if (!session_found && session_name != NULL) {
1387 ERR("Session '%s' not found", session_name);
1388 ret = CMD_ERROR;
1389 goto error;
1390 }
1391
1392 if (session_name == NULL) {
1393 MSG("\nUse lttng list <session_name> for more details");
1394 }
1395 }
1396
1397error:
1398 free(sessions);
1399end:
1400 return ret;
1401}
1402
1403
1404/*
1405 * Machine Interface
1406 * list available domain(s) for a session.
1407 */
1408static int mi_list_domains(struct lttng_domain *domains, int count)
1409{
1410 int i, ret;
1411 /* Open domains element */
1412 ret = mi_lttng_domains_open(writer);
1413 if (ret) {
1414 goto end;
1415 }
1416
1417 for (i = 0; i < count; i++) {
1418 ret = mi_lttng_domain(writer, &domains[i] , 0);
1419 if (ret) {
1420 goto end;
1421 }
1422 }
1423
1424 /* Closing domains element */
1425 ret = mi_lttng_writer_close_element(writer);
1426 if (ret) {
1427 goto end;
1428 }
1429end:
1430 return ret;
1431}
1432
1433/*
1434 * List available domain(s) for a session.
1435 */
1436static int list_domains(const char *session_name)
1437{
1438 int i, count, ret = CMD_SUCCESS;
1439 struct lttng_domain *domains = NULL;
1440
1441
1442 count = lttng_list_domains(session_name, &domains);
1443 if (count < 0) {
1444 ret = CMD_ERROR;
1445 ERR("%s", lttng_strerror(count));
1446 goto end;
1447 }
1448
1449 if (lttng_opt_mi) {
1450 /* Mi output */
1451 ret = mi_list_domains(domains, count);
1452 if (ret) {
1453 ret = CMD_ERROR;
1454 goto error;
1455 }
1456 } else {
1457 /* Pretty print */
1458 MSG("Domains:\n-------------");
1459 if (count == 0) {
1460 MSG(" None");
1461 goto end;
1462 }
1463
1464 for (i = 0; i < count; i++) {
1465 switch (domains[i].type) {
1466 case LTTNG_DOMAIN_KERNEL:
1467 MSG(" - Kernel");
1468 break;
1469 case LTTNG_DOMAIN_UST:
1470 MSG(" - UST global");
1471 break;
1472 case LTTNG_DOMAIN_JUL:
1473 MSG(" - JUL (Java Util Logging)");
1474 break;
1475 case LTTNG_DOMAIN_LOG4J:
1476 MSG(" - LOG4j (Logging for Java)");
1477 break;
1478 case LTTNG_DOMAIN_PYTHON:
1479 MSG(" - Python (logging)");
1480 break;
1481 default:
1482 break;
1483 }
1484 }
1485 }
1486
1487error:
1488 free(domains);
1489
1490end:
1491 return ret;
1492}
1493
1494/*
1495 * The 'list <options>' first level command
1496 */
1497int cmd_list(int argc, const char **argv)
1498{
1499 int opt, ret = CMD_SUCCESS;
1500 const char *session_name;
1501 static poptContext pc;
1502 struct lttng_domain domain;
1503 struct lttng_domain *domains = NULL;
1504
1505 memset(&domain, 0, sizeof(domain));
1506
1507 if (argc < 1) {
1508 usage(stderr);
1509 ret = CMD_ERROR;
1510 goto end;
1511 }
1512
1513 pc = poptGetContext(NULL, argc, argv, long_options, 0);
1514 poptReadDefaultConfig(pc, 0);
1515
1516 while ((opt = poptGetNextOpt(pc)) != -1) {
1517 switch (opt) {
1518 case OPT_HELP:
1519 usage(stdout);
1520 goto end;
1521 case OPT_USERSPACE:
1522 opt_userspace = 1;
1523 break;
1524 case OPT_LIST_OPTIONS:
1525 list_cmd_options(stdout, long_options);
1526 goto end;
1527 default:
1528 usage(stderr);
1529 ret = CMD_UNDEFINED;
1530 goto end;
1531 }
1532 }
1533
1534 /* Mi check */
1535 if (lttng_opt_mi) {
1536 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
1537 if (!writer) {
1538 ret = CMD_ERROR;
1539 goto end;
1540 }
1541
1542 /* Open command element */
1543 ret = mi_lttng_writer_command_open(writer,
1544 mi_lttng_element_command_list);
1545 if (ret) {
1546 ret = CMD_ERROR;
1547 goto end;
1548 }
1549
1550 /* Open output element */
1551 ret = mi_lttng_writer_open_element(writer,
1552 mi_lttng_element_command_output);
1553 if (ret) {
1554 ret = CMD_ERROR;
1555 goto end;
1556 }
1557 }
1558
1559 /* Get session name (trailing argument) */
1560 session_name = poptGetArg(pc);
1561 DBG2("Session name: %s", session_name);
1562
1563 if (opt_kernel) {
1564 domain.type = LTTNG_DOMAIN_KERNEL;
1565 } else if (opt_userspace) {
1566 DBG2("Listing userspace global domain");
1567 domain.type = LTTNG_DOMAIN_UST;
1568 } else if (opt_jul) {
1569 DBG2("Listing JUL domain");
1570 domain.type = LTTNG_DOMAIN_JUL;
1571 } else if (opt_log4j) {
1572 domain.type = LTTNG_DOMAIN_LOG4J;
1573 } else if (opt_python) {
1574 domain.type = LTTNG_DOMAIN_PYTHON;
1575 }
1576
1577 if (!opt_kernel && opt_syscall) {
1578 WARN("--syscall will only work with the Kernel domain (-k)");
1579 ret = CMD_ERROR;
1580 goto end;
1581 }
1582
1583 if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) {
1584 handle = lttng_create_handle(session_name, &domain);
1585 if (handle == NULL) {
1586 ret = CMD_FATAL;
1587 goto end;
1588 }
1589 }
1590
1591 if (session_name == NULL) {
1592 if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j
1593 && !opt_python) {
1594 ret = list_sessions(NULL);
1595 if (ret) {
1596 goto end;
1597 }
1598 }
1599 if (opt_kernel) {
1600 if (opt_syscall) {
1601 ret = list_syscalls();
1602 if (ret) {
1603 goto end;
1604 }
1605 } else {
1606 ret = list_kernel_events();
1607 if (ret) {
1608 goto end;
1609 }
1610 }
1611 }
1612 if (opt_userspace) {
1613 if (opt_fields) {
1614 ret = list_ust_event_fields();
1615 } else {
1616 ret = list_ust_events();
1617 }
1618 if (ret) {
1619 goto end;
1620 }
1621 }
1622 if (opt_jul || opt_log4j || opt_python) {
1623 ret = list_agent_events();
1624 if (ret) {
1625 goto end;
1626 }
1627 }
1628 } else {
1629 /* List session attributes */
1630 if (lttng_opt_mi) {
1631 /* Open element sessions
1632 * Present for xml consistency */
1633 ret = mi_lttng_sessions_open(writer);
1634 if (ret) {
1635 goto end;
1636 }
1637 }
1638 /* MI: the ouptut of list_sessions is an unclosed session element */
1639 ret = list_sessions(session_name);
1640 if (ret) {
1641 goto end;
1642 }
1643
1644 /* Domain listing */
1645 if (opt_domain) {
1646 ret = list_domains(session_name);
1647 goto end;
1648 }
1649
1650 /* Channel listing */
1651 if (opt_kernel || opt_userspace) {
1652 if (lttng_opt_mi) {
1653 /* Add of domains and domain element for xml
1654 * consistency and validation
1655 */
1656 ret = mi_lttng_domains_open(writer);
1657 if (ret) {
1658 goto end;
1659 }
1660
1661 /* Open domain and leave it open for
1662 * nested channels printing */
1663 ret = mi_lttng_domain(writer, &domain, 1);
1664 if (ret) {
1665 goto end;
1666 }
1667
1668 }
1669
1670 ret = list_channels(opt_channel);
1671 if (ret) {
1672 goto end;
1673 }
1674
1675 if (lttng_opt_mi) {
1676 /* Close domain and domain element */
1677 ret = mi_lttng_close_multi_element(writer, 2);
1678 }
1679 if (ret) {
1680 goto end;
1681 }
1682
1683
1684 } else {
1685 int i, nb_domain;
1686
1687 /* We want all domain(s) */
1688 nb_domain = lttng_list_domains(session_name, &domains);
1689 if (nb_domain < 0) {
1690 ret = CMD_ERROR;
1691 ERR("%s", lttng_strerror(nb_domain));
1692 goto end;
1693 }
1694
1695 if (lttng_opt_mi) {
1696 ret = mi_lttng_domains_open(writer);
1697 if (ret) {
1698 ret = CMD_ERROR;
1699 goto end;
1700 }
1701 }
1702
1703 for (i = 0; i < nb_domain; i++) {
1704 switch (domains[i].type) {
1705 case LTTNG_DOMAIN_KERNEL:
1706 MSG("=== Domain: Kernel ===\n");
1707 break;
1708 case LTTNG_DOMAIN_UST:
1709 MSG("=== Domain: UST global ===\n");
1710 MSG("Buffer type: %s\n",
1711 domains[i].buf_type ==
1712 LTTNG_BUFFER_PER_PID ? "per PID" : "per UID");
1713 break;
1714 case LTTNG_DOMAIN_JUL:
1715 MSG("=== Domain: JUL (Java Util Logging) ===\n");
1716 break;
1717 case LTTNG_DOMAIN_LOG4J:
1718 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
1719 break;
1720 case LTTNG_DOMAIN_PYTHON:
1721 MSG("=== Domain: Python (logging) ===\n");
1722 break;
1723 default:
1724 MSG("=== Domain: Unimplemented ===\n");
1725 break;
1726 }
1727
1728 if (lttng_opt_mi) {
1729 ret = mi_lttng_domain(writer, &domains[i], 1);
1730 if (ret) {
1731 ret = CMD_ERROR;
1732 goto end;
1733 }
1734 }
1735
1736 /* Clean handle before creating a new one */
1737 if (handle) {
1738 lttng_destroy_handle(handle);
1739 }
1740
1741 handle = lttng_create_handle(session_name, &domains[i]);
1742 if (handle == NULL) {
1743 ret = CMD_FATAL;
1744 goto end;
1745 }
1746
1747 if (domains[i].type == LTTNG_DOMAIN_JUL ||
1748 domains[i].type == LTTNG_DOMAIN_LOG4J ||
1749 domains[i].type == LTTNG_DOMAIN_PYTHON) {
1750 ret = list_session_agent_events();
1751 if (ret) {
1752 goto end;
1753 }
1754 continue;
1755 }
1756
1757 ret = list_channels(opt_channel);
1758 if (ret) {
1759 goto end;
1760 }
1761
1762 if (lttng_opt_mi) {
1763 /* Close domain element */
1764 ret = mi_lttng_writer_close_element(writer);
1765 if (ret) {
1766 ret = CMD_ERROR;
1767 goto end;
1768 }
1769 }
1770
1771 }
1772 if (lttng_opt_mi) {
1773 /* Close the domains, session and sessions element */
1774 ret = mi_lttng_close_multi_element(writer, 3);
1775 if (ret) {
1776 ret = CMD_ERROR;
1777 goto end;
1778 }
1779 }
1780 }
1781 }
1782
1783 /* Mi closing */
1784 if (lttng_opt_mi) {
1785 /* Close output element */
1786 ret = mi_lttng_writer_close_element(writer);
1787 if (ret) {
1788 ret = CMD_ERROR;
1789 goto end;
1790 }
1791
1792 /* Command element close */
1793 ret = mi_lttng_writer_command_close(writer);
1794 if (ret) {
1795 ret = CMD_ERROR;
1796 goto end;
1797 }
1798 }
1799end:
1800 /* Mi clean-up */
1801 if (writer && mi_lttng_writer_destroy(writer)) {
1802 /* Preserve original error code */
1803 ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
1804 }
1805
1806 free(domains);
1807 if (handle) {
1808 lttng_destroy_handle(handle);
1809 }
1810
1811 poptFreeContext(pc);
1812 return ret;
1813}
This page took 0.047267 seconds and 4 git commands to generate.