Fix: Mismatch of field name between ust and tools
[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
fceb65df
MD
149static
150const char *filter_string(int value)
151{
152 switch (value) {
153 case 1: return " [with filter]";
154 default: return "";
155 }
156}
157
8005f29a
MD
158static const char *loglevel_string(int value)
159{
160 switch (value) {
255a5dab
MD
161 case -1:
162 return "";
163 case LTTNG_LOGLEVEL_EMERG:
164 return "TRACE_EMERG";
165 case LTTNG_LOGLEVEL_ALERT:
166 return "TRACE_ALERT";
167 case LTTNG_LOGLEVEL_CRIT:
168 return "TRACE_CRIT";
169 case LTTNG_LOGLEVEL_ERR:
170 return "TRACE_ERR";
171 case LTTNG_LOGLEVEL_WARNING:
172 return "TRACE_WARNING";
173 case LTTNG_LOGLEVEL_NOTICE:
174 return "TRACE_NOTICE";
175 case LTTNG_LOGLEVEL_INFO:
176 return "TRACE_INFO";
177 case LTTNG_LOGLEVEL_DEBUG_SYSTEM:
178 return "TRACE_DEBUG_SYSTEM";
179 case LTTNG_LOGLEVEL_DEBUG_PROGRAM:
180 return "TRACE_DEBUG_PROGRAM";
181 case LTTNG_LOGLEVEL_DEBUG_PROCESS:
182 return "TRACE_DEBUG_PROCESS";
183 case LTTNG_LOGLEVEL_DEBUG_MODULE:
184 return "TRACE_DEBUG_MODULE";
185 case LTTNG_LOGLEVEL_DEBUG_UNIT:
186 return "TRACE_DEBUG_UNIT";
187 case LTTNG_LOGLEVEL_DEBUG_FUNCTION:
188 return "TRACE_DEBUG_FUNCTION";
189 case LTTNG_LOGLEVEL_DEBUG_LINE:
190 return "TRACE_DEBUG_LINE";
191 case LTTNG_LOGLEVEL_DEBUG:
192 return "TRACE_DEBUG";
193 default:
194 return "<<UNKNOWN>>";
8005f29a
MD
195 }
196}
197
b551a063
DG
198/*
199 * Pretty print single event.
200 */
201static void print_events(struct lttng_event *event)
202{
203 switch (event->type) {
204 case LTTNG_EVENT_TRACEPOINT:
e4baff1e 205 {
8b703175 206 if (event->loglevel != -1) {
fceb65df 207 MSG("%s%s (loglevel: %s (%d)) (type: tracepoint)%s%s",
8b703175 208 indent6,
81afa345 209 event->name,
8005f29a 210 loglevel_string(event->loglevel),
8b703175 211 event->loglevel,
fceb65df
MD
212 enabled_string(event->enabled),
213 filter_string(event->filter));
8b703175 214 } else {
fceb65df 215 MSG("%s%s (type: tracepoint)%s%s",
8b703175
MD
216 indent6,
217 event->name,
fceb65df
MD
218 enabled_string(event->enabled),
219 filter_string(event->filter));
8b703175 220 }
b551a063 221 break;
e4baff1e 222 }
b551a063 223 case LTTNG_EVENT_PROBE:
fceb65df
MD
224 MSG("%s%s (type: probe)%s%s", indent6,
225 event->name, enabled_string(event->enabled),
226 filter_string(event->filter));
b551a063
DG
227 if (event->attr.probe.addr != 0) {
228 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
229 } else {
230 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
231 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
232 }
233 break;
234 case LTTNG_EVENT_FUNCTION:
235 case LTTNG_EVENT_FUNCTION_ENTRY:
fceb65df
MD
236 MSG("%s%s (type: function)%s%s", indent6,
237 event->name, enabled_string(event->enabled),
238 filter_string(event->filter));
b551a063
DG
239 MSG("%ssymbol: \"%s\"", indent8, event->attr.ftrace.symbol_name);
240 break;
241 case LTTNG_EVENT_SYSCALL:
fceb65df
MD
242 MSG("%ssyscalls (type: syscall)%s%s", indent6,
243 enabled_string(event->enabled),
244 filter_string(event->filter));
b551a063
DG
245 break;
246 case LTTNG_EVENT_NOOP:
fceb65df
MD
247 MSG("%s (type: noop)%s%s", indent6,
248 enabled_string(event->enabled),
249 filter_string(event->filter));
b551a063
DG
250 break;
251 case LTTNG_EVENT_ALL:
252 /* We should never have "all" events in list. */
253 assert(0);
254 break;
255 }
256}
257
f37d259d
MD
258static const char *field_type(struct lttng_event_field *field)
259{
260 switch(field->type) {
261 case LTTNG_EVENT_FIELD_INTEGER:
262 return "integer";
263 case LTTNG_EVENT_FIELD_ENUM:
264 return "enum";
265 case LTTNG_EVENT_FIELD_FLOAT:
266 return "float";
267 case LTTNG_EVENT_FIELD_STRING:
268 return "string";
269 case LTTNG_EVENT_FIELD_OTHER:
270 default: /* fall-through */
271 return "unknown";
272 }
273}
274
275/*
276 * Pretty print single event fields.
277 */
278static void print_event_field(struct lttng_event_field *field)
279{
280 if (!field->field_name[0]) {
281 return;
282 }
d8fbe2a9 283 MSG("%sfield: %s (%s)%s", indent8, field->field_name,
590b9e3c 284 field_type(field), field->nowrite ? "" : " [no write]");
f37d259d
MD
285}
286
b551a063
DG
287/*
288 * Ask session daemon for all user space tracepoints available.
289 */
290static int list_ust_events(void)
291{
292 int i, size;
293 struct lttng_domain domain;
294 struct lttng_handle *handle;
295 struct lttng_event *event_list;
296 pid_t cur_pid = 0;
297
441c16a7
MD
298 memset(&domain, 0, sizeof(domain));
299
b551a063
DG
300 DBG("Getting UST tracing events");
301
302 domain.type = LTTNG_DOMAIN_UST;
303
304 handle = lttng_create_handle(NULL, &domain);
305 if (handle == NULL) {
306 goto error;
307 }
308
309 size = lttng_list_tracepoints(handle, &event_list);
310 if (size < 0) {
311 ERR("Unable to list UST events");
ef021732 312 lttng_destroy_handle(handle);
b551a063
DG
313 return size;
314 }
315
316 MSG("UST events:\n-------------");
317
318 if (size == 0) {
319 MSG("None");
320 }
321
322 for (i = 0; i < size; i++) {
323 if (cur_pid != event_list[i].pid) {
324 cur_pid = event_list[i].pid;
325 MSG("\nPID: %d - Name: %s", cur_pid, get_cmdline_by_pid(cur_pid));
326 }
327 print_events(&event_list[i]);
328 }
329
330 MSG("");
331
332 free(event_list);
ef021732 333 lttng_destroy_handle(handle);
b551a063
DG
334
335 return CMD_SUCCESS;
336
337error:
ef021732 338 lttng_destroy_handle(handle);
b551a063
DG
339 return -1;
340}
f3ed775e 341
f37d259d
MD
342/*
343 * Ask session daemon for all user space tracepoint fields available.
344 */
345static int list_ust_event_fields(void)
346{
347 int i, size;
348 struct lttng_domain domain;
349 struct lttng_handle *handle;
350 struct lttng_event_field *event_field_list;
351 pid_t cur_pid = 0;
352 struct lttng_event cur_event;
353
354 memset(&domain, 0, sizeof(domain));
355 memset(&cur_event, 0, sizeof(cur_event));
356
357 DBG("Getting UST tracing event fields");
358
359 domain.type = LTTNG_DOMAIN_UST;
360
361 handle = lttng_create_handle(NULL, &domain);
362 if (handle == NULL) {
363 goto error;
364 }
365
366 size = lttng_list_tracepoint_fields(handle, &event_field_list);
367 if (size < 0) {
368 ERR("Unable to list UST event fields");
369 lttng_destroy_handle(handle);
370 return size;
371 }
372
373 MSG("UST events:\n-------------");
374
375 if (size == 0) {
376 MSG("None");
377 }
378
379 for (i = 0; i < size; i++) {
380 if (cur_pid != event_field_list[i].event.pid) {
381 cur_pid = event_field_list[i].event.pid;
382 MSG("\nPID: %d - Name: %s", cur_pid, get_cmdline_by_pid(cur_pid));
383 }
384 if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
385 print_events(&event_field_list[i].event);
386 memcpy(&cur_event, &event_field_list[i].event,
387 sizeof(cur_event));
388 }
389 print_event_field(&event_field_list[i]);
390 }
391
392 MSG("");
393
394 free(event_field_list);
395 lttng_destroy_handle(handle);
396
397 return CMD_SUCCESS;
398
399error:
400 lttng_destroy_handle(handle);
401 return -1;
402}
403
f3ed775e 404/*
9f19cc17 405 * Ask for all trace events in the kernel and pretty print them.
f3ed775e 406 */
9f19cc17 407static int list_kernel_events(void)
f3ed775e 408{
9f19cc17 409 int i, size;
b551a063
DG
410 struct lttng_domain domain;
411 struct lttng_handle *handle;
9f19cc17 412 struct lttng_event *event_list;
f3ed775e 413
441c16a7
MD
414 memset(&domain, 0, sizeof(domain));
415
b551a063
DG
416 DBG("Getting kernel tracing events");
417
418 domain.type = LTTNG_DOMAIN_KERNEL;
419
420 handle = lttng_create_handle(NULL, &domain);
421 if (handle == NULL) {
422 goto error;
423 }
f3ed775e 424
cd80958d 425 size = lttng_list_tracepoints(handle, &event_list);
9f19cc17
DG
426 if (size < 0) {
427 ERR("Unable to list kernel events");
ef021732 428 lttng_destroy_handle(handle);
9f19cc17 429 return size;
f3ed775e
DG
430 }
431
9f19cc17 432 MSG("Kernel events:\n-------------");
f3ed775e 433
9f19cc17 434 for (i = 0; i < size; i++) {
b551a063 435 print_events(&event_list[i]);
f3ed775e
DG
436 }
437
b551a063
DG
438 MSG("");
439
f3ed775e
DG
440 free(event_list);
441
ef021732 442 lttng_destroy_handle(handle);
f3ed775e 443 return CMD_SUCCESS;
b551a063
DG
444
445error:
ef021732 446 lttng_destroy_handle(handle);
b551a063 447 return -1;
f3ed775e
DG
448}
449
450/*
9f19cc17 451 * List events of channel of session and domain.
f3ed775e 452 */
cd80958d 453static int list_events(const char *channel_name)
f3ed775e
DG
454{
455 int ret, count, i;
9f19cc17 456 struct lttng_event *events = NULL;
f3ed775e 457
cd80958d 458 count = lttng_list_events(handle, channel_name, &events);
f3ed775e
DG
459 if (count < 0) {
460 ret = count;
461 goto error;
462 }
463
9f19cc17
DG
464 MSG("\n%sEvents:", indent4);
465 if (count == 0) {
5edd7e09 466 MSG("%sNone\n", indent6);
9f19cc17
DG
467 goto end;
468 }
469
f3ed775e 470 for (i = 0; i < count; i++) {
b551a063 471 print_events(&events[i]);
f3ed775e
DG
472 }
473
9f19cc17 474 MSG("");
f3ed775e 475
9f19cc17
DG
476end:
477 if (events) {
478 free(events);
479 }
480 ret = CMD_SUCCESS;
f3ed775e
DG
481
482error:
483 return ret;
484}
485
486/*
9f19cc17
DG
487 * Pretty print channel
488 */
489static void print_channel(struct lttng_channel *channel)
490{
464dd62d 491 MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
9f19cc17
DG
492
493 MSG("%sAttributes:", indent4);
494 MSG("%soverwrite mode: %d", indent6, channel->attr.overwrite);
495 MSG("%ssubbufers size: %" PRIu64, indent6, channel->attr.subbuf_size);
496 MSG("%snumber of subbufers: %" PRIu64, indent6, channel->attr.num_subbuf);
497 MSG("%sswitch timer interval: %u", indent6, channel->attr.switch_timer_interval);
498 MSG("%sread timer interval: %u", indent6, channel->attr.read_timer_interval);
499 switch (channel->attr.output) {
500 case LTTNG_EVENT_SPLICE:
501 MSG("%soutput: splice()", indent6);
502 break;
503 case LTTNG_EVENT_MMAP:
504 MSG("%soutput: mmap()", indent6);
505 break;
506 }
507}
508
509/*
510 * List channel(s) of session and domain.
f3ed775e 511 *
9f19cc17 512 * If channel_name is NULL, all channels are listed.
f3ed775e 513 */
cd80958d 514static int list_channels(const char *channel_name)
f3ed775e 515{
9f19cc17
DG
516 int count, i, ret = CMD_SUCCESS;
517 unsigned int chan_found = 0;
518 struct lttng_channel *channels = NULL;
f3ed775e 519
3e25cb20 520 DBG("Listing channel(s) (%s)", channel_name ? : "<all>");
9f19cc17 521
cd80958d 522 count = lttng_list_channels(handle, &channels);
f3ed775e
DG
523 if (count < 0) {
524 ret = count;
ae856491 525 goto error_channels;
9f19cc17 526 } else if (count == 0) {
ae856491
DG
527 ERR("Channel %s not found", channel_name);
528 goto error;
f3ed775e
DG
529 }
530
9f19cc17
DG
531 if (channel_name == NULL) {
532 MSG("Channels:\n-------------");
533 }
534
535 for (i = 0; i < count; i++) {
536 if (channel_name != NULL) {
537 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
538 chan_found = 1;
539 } else {
540 continue;
541 }
542 }
543 print_channel(&channels[i]);
544
545 /* Listing events per channel */
cd80958d 546 ret = list_events(channels[i].name);
9f19cc17 547 if (ret < 0) {
9a745bc7 548 MSG("%s", lttng_strerror(ret));
9f19cc17
DG
549 }
550
551 if (chan_found) {
552 break;
f3ed775e 553 }
f3ed775e
DG
554 }
555
9f19cc17 556 if (!chan_found && channel_name != NULL) {
ae856491
DG
557 ERR("Channel %s not found", channel_name);
558 goto error;
9f19cc17 559 }
f3ed775e 560
9f19cc17 561 ret = CMD_SUCCESS;
f3ed775e
DG
562
563error:
ae856491
DG
564 free(channels);
565
566error_channels:
f3ed775e
DG
567 return ret;
568}
569
570/*
9f19cc17 571 * List available tracing session. List only basic information.
f3ed775e 572 *
9f19cc17 573 * If session_name is NULL, all sessions are listed.
f3ed775e 574 */
9f19cc17 575static int list_sessions(const char *session_name)
f3ed775e 576{
9f19cc17
DG
577 int ret, count, i;
578 unsigned int session_found = 0;
579 struct lttng_session *sessions;
580
581 count = lttng_list_sessions(&sessions);
582 DBG("Session count %d", count);
583 if (count < 0) {
584 ret = count;
585 goto error;
d32fb093
DG
586 } else if (count == 0) {
587 MSG("Currently no available tracing session");
588 goto end;
9f19cc17
DG
589 }
590
591 if (session_name == NULL) {
592 MSG("Available tracing sessions:");
593 }
594
595 for (i = 0; i < count; i++) {
596 if (session_name != NULL) {
597 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
598 session_found = 1;
464dd62d 599 MSG("Tracing session %s:%s", session_name, active_string(sessions[i].enabled));
9f19cc17
DG
600 MSG("%sTrace path: %s\n", indent4, sessions[i].path);
601 break;
602 }
cd80958d 603 continue;
9f19cc17
DG
604 }
605
b6913340
DG
606 MSG(" %d) %s (%s)%s", i + 1, sessions[i].name, sessions[i].path,
607 active_string(sessions[i].enabled));
9f19cc17
DG
608
609 if (session_found) {
610 break;
611 }
612 }
613
614 free(sessions);
615
616 if (!session_found && session_name != NULL) {
b6913340
DG
617 ERR("Session '%s' not found", session_name);
618 ret = CMD_ERROR;
619 goto error;
9f19cc17
DG
620 }
621
622 if (session_name == NULL) {
6e0de39b 623 MSG("\nUse lttng list <session_name> for more details");
9f19cc17 624 }
f3ed775e 625
d32fb093 626end:
f3ed775e
DG
627 return CMD_SUCCESS;
628
629error:
630 return ret;
631}
f3ed775e
DG
632
633/*
9f19cc17 634 * List available domain(s) for a session.
f3ed775e 635 */
330be774 636static int list_domains(const char *session_name)
f3ed775e 637{
9f19cc17
DG
638 int i, count, ret = CMD_SUCCESS;
639 struct lttng_domain *domains = NULL;
640
641 MSG("Domains:\n-------------");
642
330be774 643 count = lttng_list_domains(session_name, &domains);
9f19cc17
DG
644 if (count < 0) {
645 ret = count;
646 goto error;
647 } else if (count == 0) {
648 MSG(" None");
649 goto end;
650 }
651
652 for (i = 0; i < count; i++) {
653 switch (domains[i].type) {
654 case LTTNG_DOMAIN_KERNEL:
655 MSG(" - Kernel");
b551a063
DG
656 break;
657 case LTTNG_DOMAIN_UST:
658 MSG(" - UST global");
659 break;
9f19cc17
DG
660 default:
661 break;
662 }
663 }
664
665end:
666 free(domains);
667
668error:
669 return ret;
f3ed775e 670}
f3ed775e
DG
671
672/*
9f19cc17 673 * The 'list <options>' first level command
f3ed775e
DG
674 */
675int cmd_list(int argc, const char **argv)
676{
9f19cc17 677 int opt, i, ret = CMD_SUCCESS;
c3919711 678 int nb_domain;
9f19cc17 679 const char *session_name;
f3ed775e 680 static poptContext pc;
9f19cc17
DG
681 struct lttng_domain domain;
682 struct lttng_domain *domains = NULL;
f3ed775e 683
441c16a7
MD
684 memset(&domain, 0, sizeof(domain));
685
9f19cc17 686 if (argc < 1) {
f3ed775e 687 usage(stderr);
ca1c3607 688 ret = CMD_ERROR;
f3ed775e
DG
689 goto end;
690 }
691
692 pc = poptGetContext(NULL, argc, argv, long_options, 0);
693 poptReadDefaultConfig(pc, 0);
694
695 while ((opt = poptGetNextOpt(pc)) != -1) {
696 switch (opt) {
697 case OPT_HELP:
ca1c3607 698 usage(stdout);
f3ed775e 699 goto end;
eeac7d46
MD
700 case OPT_USERSPACE:
701 opt_userspace = 1;
eeac7d46 702 break;
679b4943
SM
703 case OPT_LIST_OPTIONS:
704 list_cmd_options(stdout, long_options);
679b4943 705 goto end;
f3ed775e
DG
706 default:
707 usage(stderr);
708 ret = CMD_UNDEFINED;
709 goto end;
710 }
711 }
712
9f19cc17
DG
713 /* Get session name (trailing argument) */
714 session_name = poptGetArg(pc);
b551a063 715 DBG2("Session name: %s", session_name);
9f19cc17 716
cd80958d
DG
717 if (opt_kernel) {
718 domain.type = LTTNG_DOMAIN_KERNEL;
b551a063
DG
719 } else if (opt_userspace) {
720 DBG2("Listing userspace global domain");
721 domain.type = LTTNG_DOMAIN_UST;
cd80958d
DG
722 }
723
aa5de748
MD
724 if (opt_kernel || opt_userspace) {
725 handle = lttng_create_handle(session_name, &domain);
726 if (handle == NULL) {
727 ret = CMD_FATAL;
728 goto end;
729 }
cd80958d
DG
730 }
731
9f19cc17 732 if (session_name == NULL) {
b551a063
DG
733 if (!opt_kernel && !opt_userspace) {
734 ret = list_sessions(NULL);
b6913340 735 if (ret != 0) {
b551a063
DG
736 goto end;
737 }
738 }
9f19cc17
DG
739 if (opt_kernel) {
740 ret = list_kernel_events();
741 if (ret < 0) {
742 goto end;
743 }
b551a063
DG
744 }
745 if (opt_userspace) {
f37d259d
MD
746 if (opt_fields) {
747 ret = list_ust_event_fields();
748 } else {
749 ret = list_ust_events();
750 }
9f19cc17
DG
751 if (ret < 0) {
752 goto end;
753 }
754 }
755 } else {
756 /* List session attributes */
757 ret = list_sessions(session_name);
b6913340 758 if (ret != 0) {
9f19cc17
DG
759 goto end;
760 }
761
762 /* Domain listing */
763 if (opt_domain) {
330be774 764 ret = list_domains(session_name);
9f19cc17
DG
765 goto end;
766 }
767
768 if (opt_kernel) {
9f19cc17 769 /* Channel listing */
cd80958d 770 ret = list_channels(opt_channel);
9f19cc17
DG
771 if (ret < 0) {
772 goto end;
773 }
9f19cc17
DG
774 } else {
775 /* We want all domain(s) */
330be774 776 nb_domain = lttng_list_domains(session_name, &domains);
b551a063 777 if (nb_domain < 0) {
67635185 778 ret = nb_domain;
9f19cc17
DG
779 goto end;
780 }
781
b551a063 782 for (i = 0; i < nb_domain; i++) {
9f19cc17
DG
783 switch (domains[i].type) {
784 case LTTNG_DOMAIN_KERNEL:
785 MSG("=== Domain: Kernel ===\n");
786 break;
b551a063
DG
787 case LTTNG_DOMAIN_UST:
788 MSG("=== Domain: UST global ===\n");
789 break;
9f19cc17
DG
790 default:
791 MSG("=== Domain: Unimplemented ===\n");
792 break;
793 }
794
cd80958d 795 /* Clean handle before creating a new one */
aa5de748
MD
796 if (handle) {
797 lttng_destroy_handle(handle);
798 }
cd80958d
DG
799
800 handle = lttng_create_handle(session_name, &domains[i]);
801 if (handle == NULL) {
ca1c3607 802 ret = CMD_FATAL;
cd80958d
DG
803 goto end;
804 }
805
806 ret = list_channels(opt_channel);
9f19cc17
DG
807 if (ret < 0) {
808 goto end;
809 }
810 }
811 }
f3ed775e
DG
812 }
813
814end:
9f19cc17
DG
815 if (domains) {
816 free(domains);
817 }
aa5de748
MD
818 if (handle) {
819 lttng_destroy_handle(handle);
820 }
cd80958d 821
ca1c3607 822 poptFreeContext(pc);
f3ed775e
DG
823 return ret;
824}
This page took 0.109699 seconds and 4 git commands to generate.