When listing events, show exclusions if they exist
[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 #include <inttypes.h>
20 #include <popt.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <assert.h>
25
26 #include "../command.h"
27
28 static int opt_userspace;
29 static int opt_kernel;
30 static int opt_jul;
31 static char *opt_channel;
32 static int opt_domain;
33 static int opt_fields;
34 #if 0
35 /* Not implemented yet */
36 static char *opt_cmd_name;
37 static pid_t opt_pid;
38 #endif
39
40 const char *indent4 = " ";
41 const char *indent6 = " ";
42 const char *indent8 = " ";
43
44 enum {
45 OPT_HELP = 1,
46 OPT_USERSPACE,
47 OPT_LIST_OPTIONS,
48 };
49
50 static struct lttng_handle *handle;
51
52 static struct poptOption long_options[] = {
53 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
54 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
55 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
56 {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
57 #if 0
58 /* Not implemented yet */
59 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
60 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
61 #else
62 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
63 #endif
64 {"channel", 'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0},
65 {"domain", 'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
66 {"fields", 'f', POPT_ARG_VAL, &opt_fields, 1, 0, 0},
67 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
68 {0, 0, 0, 0, 0, 0, 0}
69 };
70
71 /*
72 * usage
73 */
74 static void usage(FILE *ofp)
75 {
76 fprintf(ofp, "usage: lttng list [OPTIONS] [SESSION [SESSION OPTIONS]]\n");
77 fprintf(ofp, "\n");
78 fprintf(ofp, "With no arguments, list available tracing session(s)\n");
79 fprintf(ofp, "\n");
80 fprintf(ofp, "Without a session, -k lists available kernel events\n");
81 fprintf(ofp, "Without a session, -u lists available userspace events\n");
82 fprintf(ofp, "\n");
83 fprintf(ofp, " -h, --help Show this help\n");
84 fprintf(ofp, " --list-options Simple listing of options\n");
85 fprintf(ofp, " -k, --kernel Select kernel domain\n");
86 fprintf(ofp, " -u, --userspace Select user-space domain.\n");
87 fprintf(ofp, " -j, --jul Apply for Java application using JUL\n");
88 fprintf(ofp, " -f, --fields List event fields.\n");
89 #if 0
90 fprintf(ofp, " -p, --pid PID List user-space events by PID\n");
91 #endif
92 fprintf(ofp, "\n");
93 fprintf(ofp, "Session Options:\n");
94 fprintf(ofp, " -c, --channel NAME List details of a channel\n");
95 fprintf(ofp, " -d, --domain List available domain(s)\n");
96 fprintf(ofp, "\n");
97 }
98
99 /*
100 * Get command line from /proc for a specific pid.
101 *
102 * On success, return an allocated string pointer to the proc cmdline.
103 * On error, return NULL.
104 */
105 static char *get_cmdline_by_pid(pid_t pid)
106 {
107 int ret;
108 FILE *fp;
109 char *cmdline = NULL;
110 char path[24]; /* Can't go bigger than /proc/65535/cmdline */
111
112 snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
113 fp = fopen(path, "r");
114 if (fp == NULL) {
115 goto end;
116 }
117
118 /* Caller must free() *cmdline */
119 cmdline = malloc(PATH_MAX);
120 ret = fread(cmdline, 1, PATH_MAX, fp);
121 if (ret < 0) {
122 perror("fread proc list");
123 }
124 fclose(fp);
125
126 end:
127 return cmdline;
128 }
129
130 static
131 const char *active_string(int value)
132 {
133 switch (value) {
134 case 0: return "inactive";
135 case 1: return "active";
136 case -1: return "";
137 default: return NULL;
138 }
139 }
140
141 static const char *snapshot_string(int value)
142 {
143 switch (value) {
144 case 1:
145 return " snapshot";
146 default:
147 return "";
148 }
149 }
150
151 static
152 const char *enabled_string(int value)
153 {
154 switch (value) {
155 case 0: return " [disabled]";
156 case 1: return " [enabled]";
157 case -1: return "";
158 default: return NULL;
159 }
160 }
161
162 static
163 const char *filter_string(int value)
164 {
165 switch (value) {
166 case 1: return " [with filter]";
167 default: return "";
168 }
169 }
170
171 static
172 const char *exclusion_string(int value)
173 {
174 switch (value) {
175 case 1: return " [has exclusions]";
176 default: return "";
177 }
178 }
179
180 static const char *loglevel_string(int value)
181 {
182 switch (value) {
183 case -1:
184 return "";
185 case LTTNG_LOGLEVEL_EMERG:
186 return "TRACE_EMERG";
187 case LTTNG_LOGLEVEL_ALERT:
188 return "TRACE_ALERT";
189 case LTTNG_LOGLEVEL_CRIT:
190 return "TRACE_CRIT";
191 case LTTNG_LOGLEVEL_ERR:
192 return "TRACE_ERR";
193 case LTTNG_LOGLEVEL_WARNING:
194 return "TRACE_WARNING";
195 case LTTNG_LOGLEVEL_NOTICE:
196 return "TRACE_NOTICE";
197 case LTTNG_LOGLEVEL_INFO:
198 return "TRACE_INFO";
199 case LTTNG_LOGLEVEL_DEBUG_SYSTEM:
200 return "TRACE_DEBUG_SYSTEM";
201 case LTTNG_LOGLEVEL_DEBUG_PROGRAM:
202 return "TRACE_DEBUG_PROGRAM";
203 case LTTNG_LOGLEVEL_DEBUG_PROCESS:
204 return "TRACE_DEBUG_PROCESS";
205 case LTTNG_LOGLEVEL_DEBUG_MODULE:
206 return "TRACE_DEBUG_MODULE";
207 case LTTNG_LOGLEVEL_DEBUG_UNIT:
208 return "TRACE_DEBUG_UNIT";
209 case LTTNG_LOGLEVEL_DEBUG_FUNCTION:
210 return "TRACE_DEBUG_FUNCTION";
211 case LTTNG_LOGLEVEL_DEBUG_LINE:
212 return "TRACE_DEBUG_LINE";
213 case LTTNG_LOGLEVEL_DEBUG:
214 return "TRACE_DEBUG";
215 default:
216 return "<<UNKNOWN>>";
217 }
218 }
219
220 /*
221 * Pretty print single event.
222 */
223 static void print_events(struct lttng_event *event)
224 {
225 switch (event->type) {
226 case LTTNG_EVENT_TRACEPOINT:
227 {
228 if (event->loglevel != -1) {
229 MSG("%s%s (loglevel: %s (%d)) (type: tracepoint)%s%s%s",
230 indent6,
231 event->name,
232 loglevel_string(event->loglevel),
233 event->loglevel,
234 enabled_string(event->enabled),
235 exclusion_string(event->exclusion),
236 filter_string(event->filter));
237 } else {
238 MSG("%s%s (type: tracepoint)%s%s%s",
239 indent6,
240 event->name,
241 enabled_string(event->enabled),
242 exclusion_string(event->exclusion),
243 filter_string(event->filter));
244 }
245 break;
246 }
247 case LTTNG_EVENT_FUNCTION:
248 MSG("%s%s (type: function)%s%s", indent6,
249 event->name, enabled_string(event->enabled),
250 filter_string(event->filter));
251 if (event->attr.probe.addr != 0) {
252 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
253 } else {
254 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
255 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
256 }
257 break;
258 case LTTNG_EVENT_PROBE:
259 MSG("%s%s (type: probe)%s%s", indent6,
260 event->name, enabled_string(event->enabled),
261 filter_string(event->filter));
262 if (event->attr.probe.addr != 0) {
263 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
264 } else {
265 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
266 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
267 }
268 break;
269 case LTTNG_EVENT_FUNCTION_ENTRY:
270 MSG("%s%s (type: function)%s%s", indent6,
271 event->name, enabled_string(event->enabled),
272 filter_string(event->filter));
273 MSG("%ssymbol: \"%s\"", indent8, event->attr.ftrace.symbol_name);
274 break;
275 case LTTNG_EVENT_SYSCALL:
276 MSG("%ssyscalls (type: syscall)%s%s", indent6,
277 enabled_string(event->enabled),
278 filter_string(event->filter));
279 break;
280 case LTTNG_EVENT_NOOP:
281 MSG("%s (type: noop)%s%s", indent6,
282 enabled_string(event->enabled),
283 filter_string(event->filter));
284 break;
285 case LTTNG_EVENT_ALL:
286 /* We should never have "all" events in list. */
287 assert(0);
288 break;
289 }
290 }
291
292 static const char *field_type(struct lttng_event_field *field)
293 {
294 switch(field->type) {
295 case LTTNG_EVENT_FIELD_INTEGER:
296 return "integer";
297 case LTTNG_EVENT_FIELD_ENUM:
298 return "enum";
299 case LTTNG_EVENT_FIELD_FLOAT:
300 return "float";
301 case LTTNG_EVENT_FIELD_STRING:
302 return "string";
303 case LTTNG_EVENT_FIELD_OTHER:
304 default: /* fall-through */
305 return "unknown";
306 }
307 }
308
309 /*
310 * Pretty print single event fields.
311 */
312 static void print_event_field(struct lttng_event_field *field)
313 {
314 if (!field->field_name[0]) {
315 return;
316 }
317 MSG("%sfield: %s (%s)%s", indent8, field->field_name,
318 field_type(field), field->nowrite ? " [no write]" : "");
319 }
320
321 static int list_jul_events(void)
322 {
323 int i, size;
324 struct lttng_domain domain;
325 struct lttng_handle *handle;
326 struct lttng_event *event_list;
327 pid_t cur_pid = 0;
328 char *cmdline = NULL;
329
330 DBG("Getting JUL tracing events");
331
332 memset(&domain, 0, sizeof(domain));
333 domain.type = LTTNG_DOMAIN_JUL;
334
335 handle = lttng_create_handle(NULL, &domain);
336 if (handle == NULL) {
337 goto error;
338 }
339
340 size = lttng_list_tracepoints(handle, &event_list);
341 if (size < 0) {
342 ERR("Unable to list JUL events: %s", lttng_strerror(size));
343 lttng_destroy_handle(handle);
344 return size;
345 }
346
347 MSG("JUL events (Logger name):\n-------------------------");
348
349 if (size == 0) {
350 MSG("None");
351 }
352
353 for (i = 0; i < size; i++) {
354 if (cur_pid != event_list[i].pid) {
355 cur_pid = event_list[i].pid;
356 cmdline = get_cmdline_by_pid(cur_pid);
357 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
358 free(cmdline);
359 }
360 MSG("%s- %s", indent6, event_list[i].name);
361 }
362
363 MSG("");
364
365 free(event_list);
366 lttng_destroy_handle(handle);
367
368 return CMD_SUCCESS;
369
370 error:
371 lttng_destroy_handle(handle);
372 return -1;
373 }
374
375 /*
376 * Ask session daemon for all user space tracepoints available.
377 */
378 static int list_ust_events(void)
379 {
380 int i, size;
381 struct lttng_domain domain;
382 struct lttng_handle *handle;
383 struct lttng_event *event_list;
384 pid_t cur_pid = 0;
385 char *cmdline = NULL;
386
387 memset(&domain, 0, sizeof(domain));
388
389 DBG("Getting UST tracing events");
390
391 domain.type = LTTNG_DOMAIN_UST;
392
393 handle = lttng_create_handle(NULL, &domain);
394 if (handle == NULL) {
395 goto error;
396 }
397
398 size = lttng_list_tracepoints(handle, &event_list);
399 if (size < 0) {
400 ERR("Unable to list UST events: %s", lttng_strerror(size));
401 lttng_destroy_handle(handle);
402 return size;
403 }
404
405 MSG("UST events:\n-------------");
406
407 if (size == 0) {
408 MSG("None");
409 }
410
411 for (i = 0; i < size; i++) {
412 if (cur_pid != event_list[i].pid) {
413 cur_pid = event_list[i].pid;
414 cmdline = get_cmdline_by_pid(cur_pid);
415 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
416 free(cmdline);
417 }
418 print_events(&event_list[i]);
419 }
420
421 MSG("");
422
423 free(event_list);
424 lttng_destroy_handle(handle);
425
426 return CMD_SUCCESS;
427
428 error:
429 lttng_destroy_handle(handle);
430 return -1;
431 }
432
433 /*
434 * Ask session daemon for all user space tracepoint fields available.
435 */
436 static int list_ust_event_fields(void)
437 {
438 int i, size;
439 struct lttng_domain domain;
440 struct lttng_handle *handle;
441 struct lttng_event_field *event_field_list;
442 pid_t cur_pid = 0;
443 char *cmdline = NULL;
444
445 struct lttng_event cur_event;
446
447 memset(&domain, 0, sizeof(domain));
448 memset(&cur_event, 0, sizeof(cur_event));
449
450 DBG("Getting UST tracing event fields");
451
452 domain.type = LTTNG_DOMAIN_UST;
453
454 handle = lttng_create_handle(NULL, &domain);
455 if (handle == NULL) {
456 goto error;
457 }
458
459 size = lttng_list_tracepoint_fields(handle, &event_field_list);
460 if (size < 0) {
461 ERR("Unable to list UST event fields: %s", lttng_strerror(size));
462 lttng_destroy_handle(handle);
463 return size;
464 }
465
466 MSG("UST events:\n-------------");
467
468 if (size == 0) {
469 MSG("None");
470 }
471
472 for (i = 0; i < size; i++) {
473 if (cur_pid != event_field_list[i].event.pid) {
474 cur_pid = event_field_list[i].event.pid;
475 cmdline = get_cmdline_by_pid(cur_pid);
476 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
477 free(cmdline);
478 }
479 if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
480 print_events(&event_field_list[i].event);
481 memcpy(&cur_event, &event_field_list[i].event,
482 sizeof(cur_event));
483 }
484 print_event_field(&event_field_list[i]);
485 }
486
487 MSG("");
488
489 free(event_field_list);
490 lttng_destroy_handle(handle);
491
492 return CMD_SUCCESS;
493
494 error:
495 lttng_destroy_handle(handle);
496 return -1;
497 }
498
499 /*
500 * Ask for all trace events in the kernel and pretty print them.
501 */
502 static int list_kernel_events(void)
503 {
504 int i, size;
505 struct lttng_domain domain;
506 struct lttng_handle *handle;
507 struct lttng_event *event_list;
508
509 memset(&domain, 0, sizeof(domain));
510
511 DBG("Getting kernel tracing events");
512
513 domain.type = LTTNG_DOMAIN_KERNEL;
514
515 handle = lttng_create_handle(NULL, &domain);
516 if (handle == NULL) {
517 goto error;
518 }
519
520 size = lttng_list_tracepoints(handle, &event_list);
521 if (size < 0) {
522 ERR("Unable to list kernel events: %s", lttng_strerror(size));
523 lttng_destroy_handle(handle);
524 return size;
525 }
526
527 MSG("Kernel events:\n-------------");
528
529 for (i = 0; i < size; i++) {
530 print_events(&event_list[i]);
531 }
532
533 MSG("");
534
535 free(event_list);
536
537 lttng_destroy_handle(handle);
538 return CMD_SUCCESS;
539
540 error:
541 lttng_destroy_handle(handle);
542 return -1;
543 }
544
545 /*
546 * List JUL events for a specific session using the handle.
547 *
548 * Return CMD_SUCCESS on success else a negative value.
549 */
550 static int list_session_jul_events(void)
551 {
552 int ret, count, i;
553 struct lttng_event *events = NULL;
554
555 count = lttng_list_events(handle, "", &events);
556 if (count < 0) {
557 ret = count;
558 ERR("%s", lttng_strerror(ret));
559 goto error;
560 }
561
562 MSG("Events (Logger name):\n---------------------");
563 if (count == 0) {
564 MSG("%sNone\n", indent6);
565 goto end;
566 }
567
568 for (i = 0; i < count; i++) {
569 MSG("%s- %s%s", indent4, events[i].name,
570 enabled_string(events[i].enabled));
571 }
572
573 MSG("");
574
575 end:
576 free(events);
577 ret = CMD_SUCCESS;
578
579 error:
580 return ret;
581 }
582
583 /*
584 * List events of channel of session and domain.
585 */
586 static int list_events(const char *channel_name)
587 {
588 int ret, count, i;
589 struct lttng_event *events = NULL;
590
591 count = lttng_list_events(handle, channel_name, &events);
592 if (count < 0) {
593 ret = count;
594 ERR("%s", lttng_strerror(ret));
595 goto error;
596 }
597
598 MSG("\n%sEvents:", indent4);
599 if (count == 0) {
600 MSG("%sNone\n", indent6);
601 goto end;
602 }
603
604 for (i = 0; i < count; i++) {
605 print_events(&events[i]);
606 }
607
608 MSG("");
609
610 end:
611 free(events);
612 ret = CMD_SUCCESS;
613
614 error:
615 return ret;
616 }
617
618 /*
619 * Pretty print channel
620 */
621 static void print_channel(struct lttng_channel *channel)
622 {
623 MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
624
625 MSG("%sAttributes:", indent4);
626 MSG("%soverwrite mode: %d", indent6, channel->attr.overwrite);
627 MSG("%ssubbufers size: %" PRIu64, indent6, channel->attr.subbuf_size);
628 MSG("%snumber of subbufers: %" PRIu64, indent6, channel->attr.num_subbuf);
629 MSG("%sswitch timer interval: %u", indent6, channel->attr.switch_timer_interval);
630 MSG("%sread timer interval: %u", indent6, channel->attr.read_timer_interval);
631 switch (channel->attr.output) {
632 case LTTNG_EVENT_SPLICE:
633 MSG("%soutput: splice()", indent6);
634 break;
635 case LTTNG_EVENT_MMAP:
636 MSG("%soutput: mmap()", indent6);
637 break;
638 }
639 }
640
641 /*
642 * List channel(s) of session and domain.
643 *
644 * If channel_name is NULL, all channels are listed.
645 */
646 static int list_channels(const char *channel_name)
647 {
648 int count, i, ret = CMD_SUCCESS;
649 unsigned int chan_found = 0;
650 struct lttng_channel *channels = NULL;
651
652 DBG("Listing channel(s) (%s)", channel_name ? : "<all>");
653
654 count = lttng_list_channels(handle, &channels);
655 if (count < 0) {
656 switch (-count) {
657 case LTTNG_ERR_KERN_CHAN_NOT_FOUND:
658 ret = CMD_SUCCESS;
659 WARN("No kernel channel");
660 break;
661 default:
662 /* We had a real error */
663 ret = count;
664 ERR("%s", lttng_strerror(ret));
665 break;
666 }
667 goto error_channels;
668 }
669
670 if (channel_name == NULL) {
671 MSG("Channels:\n-------------");
672 }
673
674 for (i = 0; i < count; i++) {
675 if (channel_name != NULL) {
676 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
677 chan_found = 1;
678 } else {
679 continue;
680 }
681 }
682 print_channel(&channels[i]);
683
684 /* Listing events per channel */
685 ret = list_events(channels[i].name);
686 if (ret < 0) {
687 ERR("%s", lttng_strerror(ret));
688 }
689
690 if (chan_found) {
691 break;
692 }
693 }
694
695 if (!chan_found && channel_name != NULL) {
696 ERR("Channel %s not found", channel_name);
697 goto error;
698 }
699
700 ret = CMD_SUCCESS;
701
702 error:
703 free(channels);
704
705 error_channels:
706 return ret;
707 }
708
709 /*
710 * List available tracing session. List only basic information.
711 *
712 * If session_name is NULL, all sessions are listed.
713 */
714 static int list_sessions(const char *session_name)
715 {
716 int ret, count, i;
717 unsigned int session_found = 0;
718 struct lttng_session *sessions;
719
720 count = lttng_list_sessions(&sessions);
721 DBG("Session count %d", count);
722 if (count < 0) {
723 ret = count;
724 ERR("%s", lttng_strerror(ret));
725 goto error;
726 } else if (count == 0) {
727 MSG("Currently no available tracing session");
728 goto end;
729 }
730
731 if (session_name == NULL) {
732 MSG("Available tracing sessions:");
733 }
734
735 for (i = 0; i < count; i++) {
736 if (session_name != NULL) {
737 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
738 session_found = 1;
739 MSG("Tracing session %s: [%s%s]", session_name,
740 active_string(sessions[i].enabled),
741 snapshot_string(sessions[i].snapshot_mode));
742 MSG("%sTrace path: %s\n", indent4, sessions[i].path);
743 break;
744 }
745 } else {
746 MSG(" %d) %s (%s) [%s%s]", i + 1, sessions[i].name, sessions[i].path,
747 active_string(sessions[i].enabled),
748 snapshot_string(sessions[i].snapshot_mode));
749 }
750 }
751
752 free(sessions);
753
754 if (!session_found && session_name != NULL) {
755 ERR("Session '%s' not found", session_name);
756 ret = CMD_ERROR;
757 goto error;
758 }
759
760 if (session_name == NULL) {
761 MSG("\nUse lttng list <session_name> for more details");
762 }
763
764 end:
765 return CMD_SUCCESS;
766
767 error:
768 return ret;
769 }
770
771 /*
772 * List available domain(s) for a session.
773 */
774 static int list_domains(const char *session_name)
775 {
776 int i, count, ret = CMD_SUCCESS;
777 struct lttng_domain *domains = NULL;
778
779 MSG("Domains:\n-------------");
780
781 count = lttng_list_domains(session_name, &domains);
782 if (count < 0) {
783 ret = count;
784 ERR("%s", lttng_strerror(ret));
785 goto error;
786 } else if (count == 0) {
787 MSG(" None");
788 goto end;
789 }
790
791 for (i = 0; i < count; i++) {
792 switch (domains[i].type) {
793 case LTTNG_DOMAIN_KERNEL:
794 MSG(" - Kernel");
795 break;
796 case LTTNG_DOMAIN_UST:
797 MSG(" - UST global");
798 break;
799 case LTTNG_DOMAIN_JUL:
800 MSG(" - JUL (Java Util Logging)");
801 break;
802 default:
803 break;
804 }
805 }
806
807 end:
808 free(domains);
809
810 error:
811 return ret;
812 }
813
814 /*
815 * The 'list <options>' first level command
816 */
817 int cmd_list(int argc, const char **argv)
818 {
819 int opt, ret = CMD_SUCCESS;
820 const char *session_name;
821 static poptContext pc;
822 struct lttng_domain domain;
823 struct lttng_domain *domains = NULL;
824
825 memset(&domain, 0, sizeof(domain));
826
827 if (argc < 1) {
828 usage(stderr);
829 ret = CMD_ERROR;
830 goto end;
831 }
832
833 pc = poptGetContext(NULL, argc, argv, long_options, 0);
834 poptReadDefaultConfig(pc, 0);
835
836 while ((opt = poptGetNextOpt(pc)) != -1) {
837 switch (opt) {
838 case OPT_HELP:
839 usage(stdout);
840 goto end;
841 case OPT_USERSPACE:
842 opt_userspace = 1;
843 break;
844 case OPT_LIST_OPTIONS:
845 list_cmd_options(stdout, long_options);
846 goto end;
847 default:
848 usage(stderr);
849 ret = CMD_UNDEFINED;
850 goto end;
851 }
852 }
853
854 /* Get session name (trailing argument) */
855 session_name = poptGetArg(pc);
856 DBG2("Session name: %s", session_name);
857
858 if (opt_kernel) {
859 domain.type = LTTNG_DOMAIN_KERNEL;
860 } else if (opt_userspace) {
861 DBG2("Listing userspace global domain");
862 domain.type = LTTNG_DOMAIN_UST;
863 } else if (opt_jul) {
864 DBG2("Listing JUL domain");
865 domain.type = LTTNG_DOMAIN_JUL;
866 }
867
868 if (opt_kernel || opt_userspace || opt_jul) {
869 handle = lttng_create_handle(session_name, &domain);
870 if (handle == NULL) {
871 ret = CMD_FATAL;
872 goto end;
873 }
874 }
875
876 if (session_name == NULL) {
877 if (!opt_kernel && !opt_userspace && !opt_jul) {
878 ret = list_sessions(NULL);
879 if (ret != 0) {
880 goto end;
881 }
882 }
883 if (opt_kernel) {
884 ret = list_kernel_events();
885 if (ret < 0) {
886 ret = CMD_ERROR;
887 goto end;
888 }
889 }
890 if (opt_userspace) {
891 if (opt_fields) {
892 ret = list_ust_event_fields();
893 } else {
894 ret = list_ust_events();
895 }
896 if (ret < 0) {
897 ret = CMD_ERROR;
898 goto end;
899 }
900 }
901 if (opt_jul) {
902 ret = list_jul_events();
903 if (ret < 0) {
904 ret = CMD_ERROR;
905 goto end;
906 }
907 }
908 } else {
909 /* List session attributes */
910 ret = list_sessions(session_name);
911 if (ret != 0) {
912 goto end;
913 }
914
915 /* Domain listing */
916 if (opt_domain) {
917 ret = list_domains(session_name);
918 goto end;
919 }
920
921 if (opt_kernel) {
922 /* Channel listing */
923 ret = list_channels(opt_channel);
924 if (ret < 0) {
925 goto end;
926 }
927 } else {
928 int i, nb_domain;
929
930 /* We want all domain(s) */
931 nb_domain = lttng_list_domains(session_name, &domains);
932 if (nb_domain < 0) {
933 ret = nb_domain;
934 ERR("%s", lttng_strerror(ret));
935 goto end;
936 }
937
938 for (i = 0; i < nb_domain; i++) {
939 switch (domains[i].type) {
940 case LTTNG_DOMAIN_KERNEL:
941 MSG("=== Domain: Kernel ===\n");
942 break;
943 case LTTNG_DOMAIN_UST:
944 MSG("=== Domain: UST global ===\n");
945 MSG("Buffer type: %s\n",
946 domains[i].buf_type ==
947 LTTNG_BUFFER_PER_PID ? "per PID" : "per UID");
948 break;
949 case LTTNG_DOMAIN_JUL:
950 MSG("=== Domain: JUL (Java Util Logging) ===\n");
951 break;
952 default:
953 MSG("=== Domain: Unimplemented ===\n");
954 break;
955 }
956
957 /* Clean handle before creating a new one */
958 if (handle) {
959 lttng_destroy_handle(handle);
960 }
961
962 handle = lttng_create_handle(session_name, &domains[i]);
963 if (handle == NULL) {
964 ret = CMD_FATAL;
965 goto end;
966 }
967
968 if (domains[i].type == LTTNG_DOMAIN_JUL) {
969 ret = list_session_jul_events();
970 if (ret < 0) {
971 goto end;
972 }
973 continue;
974 }
975
976 ret = list_channels(opt_channel);
977 if (ret < 0) {
978 goto end;
979 }
980 }
981 }
982 }
983
984 end:
985 free(domains);
986 if (handle) {
987 lttng_destroy_handle(handle);
988 }
989
990 poptFreeContext(pc);
991 return ret;
992 }
This page took 0.085172 seconds and 5 git commands to generate.