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