Add live timer and tracefile count/size to list
[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 static const char *logleveltype_string(enum lttng_loglevel_type value)
221 {
222 switch (value) {
223 case LTTNG_EVENT_LOGLEVEL_ALL:
224 return ":";
225 case LTTNG_EVENT_LOGLEVEL_RANGE:
226 return " <=";
227 case LTTNG_EVENT_LOGLEVEL_SINGLE:
228 return " ==";
229 default:
230 return " <<TYPE UNKN>>";
231 }
232 }
233
234 /*
235 * Pretty print single event.
236 */
237 static void print_events(struct lttng_event *event)
238 {
239 switch (event->type) {
240 case LTTNG_EVENT_TRACEPOINT:
241 {
242 if (event->loglevel != -1) {
243 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
244 indent6,
245 event->name,
246 logleveltype_string(event->loglevel_type),
247 loglevel_string(event->loglevel),
248 event->loglevel,
249 enabled_string(event->enabled),
250 exclusion_string(event->exclusion),
251 filter_string(event->filter));
252 } else {
253 MSG("%s%s (type: tracepoint)%s%s%s",
254 indent6,
255 event->name,
256 enabled_string(event->enabled),
257 exclusion_string(event->exclusion),
258 filter_string(event->filter));
259 }
260 break;
261 }
262 case LTTNG_EVENT_FUNCTION:
263 MSG("%s%s (type: function)%s%s", indent6,
264 event->name, enabled_string(event->enabled),
265 filter_string(event->filter));
266 if (event->attr.probe.addr != 0) {
267 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
268 } else {
269 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
270 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
271 }
272 break;
273 case LTTNG_EVENT_PROBE:
274 MSG("%s%s (type: probe)%s%s", indent6,
275 event->name, enabled_string(event->enabled),
276 filter_string(event->filter));
277 if (event->attr.probe.addr != 0) {
278 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
279 } else {
280 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
281 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
282 }
283 break;
284 case LTTNG_EVENT_FUNCTION_ENTRY:
285 MSG("%s%s (type: function)%s%s", indent6,
286 event->name, enabled_string(event->enabled),
287 filter_string(event->filter));
288 MSG("%ssymbol: \"%s\"", indent8, event->attr.ftrace.symbol_name);
289 break;
290 case LTTNG_EVENT_SYSCALL:
291 MSG("%ssyscalls (type: syscall)%s%s", indent6,
292 enabled_string(event->enabled),
293 filter_string(event->filter));
294 break;
295 case LTTNG_EVENT_NOOP:
296 MSG("%s (type: noop)%s%s", indent6,
297 enabled_string(event->enabled),
298 filter_string(event->filter));
299 break;
300 case LTTNG_EVENT_ALL:
301 /* We should never have "all" events in list. */
302 assert(0);
303 break;
304 }
305 }
306
307 static const char *field_type(struct lttng_event_field *field)
308 {
309 switch(field->type) {
310 case LTTNG_EVENT_FIELD_INTEGER:
311 return "integer";
312 case LTTNG_EVENT_FIELD_ENUM:
313 return "enum";
314 case LTTNG_EVENT_FIELD_FLOAT:
315 return "float";
316 case LTTNG_EVENT_FIELD_STRING:
317 return "string";
318 case LTTNG_EVENT_FIELD_OTHER:
319 default: /* fall-through */
320 return "unknown";
321 }
322 }
323
324 /*
325 * Pretty print single event fields.
326 */
327 static void print_event_field(struct lttng_event_field *field)
328 {
329 if (!field->field_name[0]) {
330 return;
331 }
332 MSG("%sfield: %s (%s)%s", indent8, field->field_name,
333 field_type(field), field->nowrite ? " [no write]" : "");
334 }
335
336 static int list_jul_events(void)
337 {
338 int i, size;
339 struct lttng_domain domain;
340 struct lttng_handle *handle;
341 struct lttng_event *event_list;
342 pid_t cur_pid = 0;
343 char *cmdline = NULL;
344
345 DBG("Getting JUL tracing events");
346
347 memset(&domain, 0, sizeof(domain));
348 domain.type = LTTNG_DOMAIN_JUL;
349
350 handle = lttng_create_handle(NULL, &domain);
351 if (handle == NULL) {
352 goto error;
353 }
354
355 size = lttng_list_tracepoints(handle, &event_list);
356 if (size < 0) {
357 ERR("Unable to list JUL events: %s", lttng_strerror(size));
358 lttng_destroy_handle(handle);
359 return size;
360 }
361
362 MSG("JUL events (Logger name):\n-------------------------");
363
364 if (size == 0) {
365 MSG("None");
366 }
367
368 for (i = 0; i < size; i++) {
369 if (cur_pid != event_list[i].pid) {
370 cur_pid = event_list[i].pid;
371 cmdline = get_cmdline_by_pid(cur_pid);
372 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
373 free(cmdline);
374 }
375 MSG("%s- %s", indent6, event_list[i].name);
376 }
377
378 MSG("");
379
380 free(event_list);
381 lttng_destroy_handle(handle);
382
383 return CMD_SUCCESS;
384
385 error:
386 lttng_destroy_handle(handle);
387 return -1;
388 }
389
390 /*
391 * Ask session daemon for all user space tracepoints available.
392 */
393 static int list_ust_events(void)
394 {
395 int i, size;
396 struct lttng_domain domain;
397 struct lttng_handle *handle;
398 struct lttng_event *event_list;
399 pid_t cur_pid = 0;
400 char *cmdline = NULL;
401
402 memset(&domain, 0, sizeof(domain));
403
404 DBG("Getting UST tracing events");
405
406 domain.type = LTTNG_DOMAIN_UST;
407
408 handle = lttng_create_handle(NULL, &domain);
409 if (handle == NULL) {
410 goto error;
411 }
412
413 size = lttng_list_tracepoints(handle, &event_list);
414 if (size < 0) {
415 ERR("Unable to list UST events: %s", lttng_strerror(size));
416 lttng_destroy_handle(handle);
417 return size;
418 }
419
420 MSG("UST events:\n-------------");
421
422 if (size == 0) {
423 MSG("None");
424 }
425
426 for (i = 0; i < size; i++) {
427 if (cur_pid != event_list[i].pid) {
428 cur_pid = event_list[i].pid;
429 cmdline = get_cmdline_by_pid(cur_pid);
430 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
431 free(cmdline);
432 }
433 print_events(&event_list[i]);
434 }
435
436 MSG("");
437
438 free(event_list);
439 lttng_destroy_handle(handle);
440
441 return CMD_SUCCESS;
442
443 error:
444 lttng_destroy_handle(handle);
445 return -1;
446 }
447
448 /*
449 * Ask session daemon for all user space tracepoint fields available.
450 */
451 static int list_ust_event_fields(void)
452 {
453 int i, size;
454 struct lttng_domain domain;
455 struct lttng_handle *handle;
456 struct lttng_event_field *event_field_list;
457 pid_t cur_pid = 0;
458 char *cmdline = NULL;
459
460 struct lttng_event cur_event;
461
462 memset(&domain, 0, sizeof(domain));
463 memset(&cur_event, 0, sizeof(cur_event));
464
465 DBG("Getting UST tracing event fields");
466
467 domain.type = LTTNG_DOMAIN_UST;
468
469 handle = lttng_create_handle(NULL, &domain);
470 if (handle == NULL) {
471 goto error;
472 }
473
474 size = lttng_list_tracepoint_fields(handle, &event_field_list);
475 if (size < 0) {
476 ERR("Unable to list UST event fields: %s", lttng_strerror(size));
477 lttng_destroy_handle(handle);
478 return size;
479 }
480
481 MSG("UST events:\n-------------");
482
483 if (size == 0) {
484 MSG("None");
485 }
486
487 for (i = 0; i < size; i++) {
488 if (cur_pid != event_field_list[i].event.pid) {
489 cur_pid = event_field_list[i].event.pid;
490 cmdline = get_cmdline_by_pid(cur_pid);
491 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
492 free(cmdline);
493 /* Wipe current event since we are about to print a new PID. */
494 memset(&cur_event, 0, sizeof(cur_event));
495 }
496 if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
497 print_events(&event_field_list[i].event);
498 memcpy(&cur_event, &event_field_list[i].event,
499 sizeof(cur_event));
500 }
501 print_event_field(&event_field_list[i]);
502 }
503
504 MSG("");
505
506 free(event_field_list);
507 lttng_destroy_handle(handle);
508
509 return CMD_SUCCESS;
510
511 error:
512 lttng_destroy_handle(handle);
513 return -1;
514 }
515
516 /*
517 * Ask for all trace events in the kernel and pretty print them.
518 */
519 static int list_kernel_events(void)
520 {
521 int i, size;
522 struct lttng_domain domain;
523 struct lttng_handle *handle;
524 struct lttng_event *event_list;
525
526 memset(&domain, 0, sizeof(domain));
527
528 DBG("Getting kernel tracing events");
529
530 domain.type = LTTNG_DOMAIN_KERNEL;
531
532 handle = lttng_create_handle(NULL, &domain);
533 if (handle == NULL) {
534 goto error;
535 }
536
537 size = lttng_list_tracepoints(handle, &event_list);
538 if (size < 0) {
539 ERR("Unable to list kernel events: %s", lttng_strerror(size));
540 lttng_destroy_handle(handle);
541 return size;
542 }
543
544 MSG("Kernel events:\n-------------");
545
546 for (i = 0; i < size; i++) {
547 print_events(&event_list[i]);
548 }
549
550 MSG("");
551
552 free(event_list);
553
554 lttng_destroy_handle(handle);
555 return CMD_SUCCESS;
556
557 error:
558 lttng_destroy_handle(handle);
559 return -1;
560 }
561
562 /*
563 * List JUL events for a specific session using the handle.
564 *
565 * Return CMD_SUCCESS on success else a negative value.
566 */
567 static int list_session_jul_events(void)
568 {
569 int ret, count, i;
570 struct lttng_event *events = NULL;
571
572 count = lttng_list_events(handle, "", &events);
573 if (count < 0) {
574 ret = count;
575 ERR("%s", lttng_strerror(ret));
576 goto error;
577 }
578
579 MSG("Events (Logger name):\n---------------------");
580 if (count == 0) {
581 MSG("%sNone\n", indent6);
582 goto end;
583 }
584
585 for (i = 0; i < count; i++) {
586 MSG("%s- %s%s", indent4, events[i].name,
587 enabled_string(events[i].enabled));
588 }
589
590 MSG("");
591
592 end:
593 free(events);
594 ret = CMD_SUCCESS;
595
596 error:
597 return ret;
598 }
599
600 /*
601 * List events of channel of session and domain.
602 */
603 static int list_events(const char *channel_name)
604 {
605 int ret, count, i;
606 struct lttng_event *events = NULL;
607
608 count = lttng_list_events(handle, channel_name, &events);
609 if (count < 0) {
610 ret = count;
611 ERR("%s", lttng_strerror(ret));
612 goto error;
613 }
614
615 MSG("\n%sEvents:", indent4);
616 if (count == 0) {
617 MSG("%sNone\n", indent6);
618 goto end;
619 }
620
621 for (i = 0; i < count; i++) {
622 print_events(&events[i]);
623 }
624
625 MSG("");
626
627 end:
628 free(events);
629 ret = CMD_SUCCESS;
630
631 error:
632 return ret;
633 }
634
635 /*
636 * Pretty print channel
637 */
638 static void print_channel(struct lttng_channel *channel)
639 {
640 MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
641
642 MSG("%sAttributes:", indent4);
643 MSG("%soverwrite mode: %d", indent6, channel->attr.overwrite);
644 MSG("%ssubbufers size: %" PRIu64, indent6, channel->attr.subbuf_size);
645 MSG("%snumber of subbufers: %" PRIu64, indent6, channel->attr.num_subbuf);
646 MSG("%sswitch timer interval: %u", indent6, channel->attr.switch_timer_interval);
647 MSG("%sread timer interval: %u", indent6, channel->attr.read_timer_interval);
648 MSG("%strace file count: %" PRIu64, indent6, channel->attr.tracefile_count);
649 MSG("%strace file size (bytes): %" PRIu64, indent6, channel->attr.tracefile_size);
650 switch (channel->attr.output) {
651 case LTTNG_EVENT_SPLICE:
652 MSG("%soutput: splice()", indent6);
653 break;
654 case LTTNG_EVENT_MMAP:
655 MSG("%soutput: mmap()", indent6);
656 break;
657 }
658 }
659
660 /*
661 * List channel(s) of session and domain.
662 *
663 * If channel_name is NULL, all channels are listed.
664 */
665 static int list_channels(const char *channel_name)
666 {
667 int count, i, ret = CMD_SUCCESS;
668 unsigned int chan_found = 0;
669 struct lttng_channel *channels = NULL;
670
671 DBG("Listing channel(s) (%s)", channel_name ? : "<all>");
672
673 count = lttng_list_channels(handle, &channels);
674 if (count < 0) {
675 switch (-count) {
676 case LTTNG_ERR_KERN_CHAN_NOT_FOUND:
677 ret = CMD_SUCCESS;
678 WARN("No kernel channel");
679 break;
680 default:
681 /* We had a real error */
682 ret = count;
683 ERR("%s", lttng_strerror(ret));
684 break;
685 }
686 goto error_channels;
687 }
688
689 if (channel_name == NULL) {
690 MSG("Channels:\n-------------");
691 }
692
693 for (i = 0; i < count; i++) {
694 if (channel_name != NULL) {
695 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
696 chan_found = 1;
697 } else {
698 continue;
699 }
700 }
701 print_channel(&channels[i]);
702
703 /* Listing events per channel */
704 ret = list_events(channels[i].name);
705 if (ret < 0) {
706 ERR("%s", lttng_strerror(ret));
707 }
708
709 if (chan_found) {
710 break;
711 }
712 }
713
714 if (!chan_found && channel_name != NULL) {
715 ERR("Channel %s not found", channel_name);
716 goto error;
717 }
718
719 ret = CMD_SUCCESS;
720
721 error:
722 free(channels);
723
724 error_channels:
725 return ret;
726 }
727
728 /*
729 * List available tracing session. List only basic information.
730 *
731 * If session_name is NULL, all sessions are listed.
732 */
733 static int list_sessions(const char *session_name)
734 {
735 int ret, count, i;
736 unsigned int session_found = 0;
737 struct lttng_session *sessions;
738
739 count = lttng_list_sessions(&sessions);
740 DBG("Session count %d", count);
741 if (count < 0) {
742 ret = count;
743 ERR("%s", lttng_strerror(ret));
744 goto error;
745 } else if (count == 0) {
746 MSG("Currently no available tracing session");
747 goto end;
748 }
749
750 if (session_name == NULL) {
751 MSG("Available tracing sessions:");
752 }
753
754 for (i = 0; i < count; i++) {
755 if (session_name != NULL) {
756 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
757 session_found = 1;
758 MSG("Tracing session %s: [%s%s]", session_name,
759 active_string(sessions[i].enabled),
760 snapshot_string(sessions[i].snapshot_mode));
761 MSG("%sTrace path: %s", indent4, sessions[i].path);
762 MSG("%sLive timer interval (usec): %u\n", indent4,
763 sessions[i].live_timer_interval);
764 break;
765 }
766 } else {
767 MSG(" %d) %s (%s) [%s%s]", i + 1, sessions[i].name, sessions[i].path,
768 active_string(sessions[i].enabled),
769 snapshot_string(sessions[i].snapshot_mode));
770 }
771 }
772
773 free(sessions);
774
775 if (!session_found && session_name != NULL) {
776 ERR("Session '%s' not found", session_name);
777 ret = CMD_ERROR;
778 goto error;
779 }
780
781 if (session_name == NULL) {
782 MSG("\nUse lttng list <session_name> for more details");
783 }
784
785 end:
786 return CMD_SUCCESS;
787
788 error:
789 return ret;
790 }
791
792 /*
793 * List available domain(s) for a session.
794 */
795 static int list_domains(const char *session_name)
796 {
797 int i, count, ret = CMD_SUCCESS;
798 struct lttng_domain *domains = NULL;
799
800 MSG("Domains:\n-------------");
801
802 count = lttng_list_domains(session_name, &domains);
803 if (count < 0) {
804 ret = count;
805 ERR("%s", lttng_strerror(ret));
806 goto error;
807 } else if (count == 0) {
808 MSG(" None");
809 goto end;
810 }
811
812 for (i = 0; i < count; i++) {
813 switch (domains[i].type) {
814 case LTTNG_DOMAIN_KERNEL:
815 MSG(" - Kernel");
816 break;
817 case LTTNG_DOMAIN_UST:
818 MSG(" - UST global");
819 break;
820 case LTTNG_DOMAIN_JUL:
821 MSG(" - JUL (Java Util Logging)");
822 break;
823 default:
824 break;
825 }
826 }
827
828 end:
829 free(domains);
830
831 error:
832 return ret;
833 }
834
835 /*
836 * The 'list <options>' first level command
837 */
838 int cmd_list(int argc, const char **argv)
839 {
840 int opt, ret = CMD_SUCCESS;
841 const char *session_name;
842 static poptContext pc;
843 struct lttng_domain domain;
844 struct lttng_domain *domains = NULL;
845
846 memset(&domain, 0, sizeof(domain));
847
848 if (argc < 1) {
849 usage(stderr);
850 ret = CMD_ERROR;
851 goto end;
852 }
853
854 pc = poptGetContext(NULL, argc, argv, long_options, 0);
855 poptReadDefaultConfig(pc, 0);
856
857 while ((opt = poptGetNextOpt(pc)) != -1) {
858 switch (opt) {
859 case OPT_HELP:
860 usage(stdout);
861 goto end;
862 case OPT_USERSPACE:
863 opt_userspace = 1;
864 break;
865 case OPT_LIST_OPTIONS:
866 list_cmd_options(stdout, long_options);
867 goto end;
868 default:
869 usage(stderr);
870 ret = CMD_UNDEFINED;
871 goto end;
872 }
873 }
874
875 /* Get session name (trailing argument) */
876 session_name = poptGetArg(pc);
877 DBG2("Session name: %s", session_name);
878
879 if (opt_kernel) {
880 domain.type = LTTNG_DOMAIN_KERNEL;
881 } else if (opt_userspace) {
882 DBG2("Listing userspace global domain");
883 domain.type = LTTNG_DOMAIN_UST;
884 } else if (opt_jul) {
885 DBG2("Listing JUL domain");
886 domain.type = LTTNG_DOMAIN_JUL;
887 }
888
889 if (opt_kernel || opt_userspace || opt_jul) {
890 handle = lttng_create_handle(session_name, &domain);
891 if (handle == NULL) {
892 ret = CMD_FATAL;
893 goto end;
894 }
895 }
896
897 if (session_name == NULL) {
898 if (!opt_kernel && !opt_userspace && !opt_jul) {
899 ret = list_sessions(NULL);
900 if (ret != 0) {
901 goto end;
902 }
903 }
904 if (opt_kernel) {
905 ret = list_kernel_events();
906 if (ret < 0) {
907 ret = CMD_ERROR;
908 goto end;
909 }
910 }
911 if (opt_userspace) {
912 if (opt_fields) {
913 ret = list_ust_event_fields();
914 } else {
915 ret = list_ust_events();
916 }
917 if (ret < 0) {
918 ret = CMD_ERROR;
919 goto end;
920 }
921 }
922 if (opt_jul) {
923 ret = list_jul_events();
924 if (ret < 0) {
925 ret = CMD_ERROR;
926 goto end;
927 }
928 }
929 } else {
930 /* List session attributes */
931 ret = list_sessions(session_name);
932 if (ret != 0) {
933 goto end;
934 }
935
936 /* Domain listing */
937 if (opt_domain) {
938 ret = list_domains(session_name);
939 goto end;
940 }
941
942 if (opt_kernel || opt_userspace) {
943 /* Channel listing */
944 ret = list_channels(opt_channel);
945 if (ret < 0) {
946 goto end;
947 }
948 } else {
949 int i, nb_domain;
950
951 /* We want all domain(s) */
952 nb_domain = lttng_list_domains(session_name, &domains);
953 if (nb_domain < 0) {
954 ret = nb_domain;
955 ERR("%s", lttng_strerror(ret));
956 goto end;
957 }
958
959 for (i = 0; i < nb_domain; i++) {
960 switch (domains[i].type) {
961 case LTTNG_DOMAIN_KERNEL:
962 MSG("=== Domain: Kernel ===\n");
963 break;
964 case LTTNG_DOMAIN_UST:
965 MSG("=== Domain: UST global ===\n");
966 MSG("Buffer type: %s\n",
967 domains[i].buf_type ==
968 LTTNG_BUFFER_PER_PID ? "per PID" : "per UID");
969 break;
970 case LTTNG_DOMAIN_JUL:
971 MSG("=== Domain: JUL (Java Util Logging) ===\n");
972 break;
973 default:
974 MSG("=== Domain: Unimplemented ===\n");
975 break;
976 }
977
978 /* Clean handle before creating a new one */
979 if (handle) {
980 lttng_destroy_handle(handle);
981 }
982
983 handle = lttng_create_handle(session_name, &domains[i]);
984 if (handle == NULL) {
985 ret = CMD_FATAL;
986 goto end;
987 }
988
989 if (domains[i].type == LTTNG_DOMAIN_JUL) {
990 ret = list_session_jul_events();
991 if (ret < 0) {
992 goto end;
993 }
994 continue;
995 }
996
997 ret = list_channels(opt_channel);
998 if (ret < 0) {
999 goto end;
1000 }
1001 }
1002 }
1003 }
1004
1005 end:
1006 free(domains);
1007 if (handle) {
1008 lttng_destroy_handle(handle);
1009 }
1010
1011 poptFreeContext(pc);
1012 return ret;
1013 }
This page took 0.049699 seconds and 5 git commands to generate.