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