rotation-api: pass session name explicitly
[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
6c1c0768 18#define _LGPL_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
fb14d0d8 26#include <common/mi-lttng.h>
fae9a062 27#include <lttng/constant.h>
fb14d0d8 28
c399183f 29#include "../command.h"
f3ed775e 30
9f19cc17
DG
31static int opt_userspace;
32static int opt_kernel;
3c6a091f 33static int opt_jul;
5cdb6027 34static int opt_log4j;
0e115563 35static int opt_python;
9f19cc17
DG
36static char *opt_channel;
37static int opt_domain;
f37d259d 38static int opt_fields;
834978fd 39static int opt_syscall;
9f19cc17
DG
40
41const char *indent4 = " ";
42const char *indent6 = " ";
43const char *indent8 = " ";
f3ed775e 44
4fc83d94
PP
45#ifdef LTTNG_EMBED_HELP
46static const char help_msg[] =
47#include <lttng-list.1.h>
48;
49#endif
50
f3ed775e
DG
51enum {
52 OPT_HELP = 1,
eeac7d46 53 OPT_USERSPACE,
679b4943 54 OPT_LIST_OPTIONS,
f3ed775e
DG
55};
56
cd80958d 57static struct lttng_handle *handle;
fb14d0d8 58static struct mi_writer *writer;
cd80958d 59
e50e81d3
JG
60/* Only set when listing a single session. */
61static struct lttng_session listed_session;
62
f3ed775e
DG
63static struct poptOption long_options[] = {
64 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2fa605f7
JG
65 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
66 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
67 {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
68 {"log4j", 'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0},
69 {"python", 'p', POPT_ARG_VAL, &opt_python, 1, 0, 0},
70 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
71 {"channel", 'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0},
72 {"domain", 'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
73 {"fields", 'f', POPT_ARG_VAL, &opt_fields, 1, 0, 0},
74 {"syscall", 'S', POPT_ARG_VAL, &opt_syscall, 1, 0, 0},
679b4943 75 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
f3ed775e
DG
76 {0, 0, 0, 0, 0, 0, 0}
77};
78
f3ed775e 79/*
9f19cc17 80 * Get command line from /proc for a specific pid.
f3ed775e 81 *
9f19cc17
DG
82 * On success, return an allocated string pointer to the proc cmdline.
83 * On error, return NULL.
f3ed775e
DG
84 */
85static char *get_cmdline_by_pid(pid_t pid)
86{
87 int ret;
1ad31aec 88 FILE *fp = NULL;
f3ed775e 89 char *cmdline = NULL;
fae9a062
JG
90 /* Can't go bigger than /proc/LTTNG_MAX_PID/cmdline */
91 char path[sizeof("/proc//cmdline") + sizeof(LTTNG_MAX_PID_STR) - 1];
f3ed775e
DG
92
93 snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
94 fp = fopen(path, "r");
95 if (fp == NULL) {
96 goto end;
97 }
98
99 /* Caller must free() *cmdline */
63a2c1bd 100 cmdline = zmalloc(PATH_MAX);
f6962219 101 if (!cmdline) {
6f04ed72 102 PERROR("malloc cmdline");
f6962219
JG
103 goto end;
104 }
f3ed775e 105 ret = fread(cmdline, 1, PATH_MAX, fp);
f40799e8 106 if (ret < 0) {
6f04ed72 107 PERROR("fread proc list");
f40799e8 108 }
f3ed775e
DG
109
110end:
1ad31aec
DG
111 if (fp) {
112 fclose(fp);
113 }
f3ed775e
DG
114 return cmdline;
115}
b551a063 116
464dd62d
MD
117static
118const char *active_string(int value)
119{
120 switch (value) {
2cbf8fed
DG
121 case 0: return "inactive";
122 case 1: return "active";
464dd62d
MD
123 case -1: return "";
124 default: return NULL;
125 }
126}
127
2cbf8fed
DG
128static const char *snapshot_string(int value)
129{
130 switch (value) {
131 case 1:
132 return " snapshot";
133 default:
134 return "";
135 }
136}
137
464dd62d
MD
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 149static
7b4a95b1 150const char *safe_string(const char *str)
fceb65df 151{
7b4a95b1 152 return str ? str : "";
4634f12e
JI
153}
154
1f0e17de
DG
155static const char *logleveltype_string(enum lttng_loglevel_type value)
156{
157 switch (value) {
af6bce80
DG
158 case LTTNG_EVENT_LOGLEVEL_ALL:
159 return ":";
1f0e17de 160 case LTTNG_EVENT_LOGLEVEL_RANGE:
af6bce80 161 return " <=";
1f0e17de 162 case LTTNG_EVENT_LOGLEVEL_SINGLE:
af6bce80 163 return " ==";
1f0e17de 164 default:
af6bce80 165 return " <<TYPE UNKN>>";
1f0e17de
DG
166 }
167}
168
834978fd
DG
169static const char *bitness_event(enum lttng_event_flag flags)
170{
171 if (flags & LTTNG_EVENT_FLAG_SYSCALL_32) {
172 if (flags & LTTNG_EVENT_FLAG_SYSCALL_64) {
173 return " [32/64-bit]";
174 } else {
175 return " [32-bit]";
176 }
177 } else if (flags & LTTNG_EVENT_FLAG_SYSCALL_64) {
178 return " [64-bit]";
179 } else {
180 return "";
181 }
182}
183
7b4a95b1
PP
184/*
185 * Get exclusion names message for a single event.
186 *
187 * Returned pointer must be freed by caller. Returns NULL on error.
188 */
189static char *get_exclusion_names_msg(struct lttng_event *event)
190{
191 int ret;
192 int exclusion_count;
193 char *exclusion_msg = NULL;
194 char *at;
7b4a95b1
PP
195 size_t i;
196 const char * const exclusion_fmt = " [exclusions: ";
19ed7632 197 const size_t exclusion_fmt_len = strlen(exclusion_fmt);
7b4a95b1
PP
198
199 exclusion_count = lttng_event_get_exclusion_name_count(event);
200 if (exclusion_count < 0) {
201 goto end;
202 } else if (exclusion_count == 0) {
203 /*
204 * No exclusions: return copy of empty string so that
205 * it can be freed by caller.
206 */
207 exclusion_msg = strdup("");
208 goto end;
209 }
210
211 /*
212 * exclusion_msg's size is bounded by the exclusion_fmt string,
213 * a comma per entry, the entry count (fixed-size), a closing
214 * bracket, and a trailing \0.
215 */
216 exclusion_msg = malloc(exclusion_count +
217 exclusion_count * LTTNG_SYMBOL_NAME_LEN +
19ed7632 218 exclusion_fmt_len + 1);
7b4a95b1
PP
219 if (!exclusion_msg) {
220 goto end;
221 }
222
19ed7632 223 at = strcpy(exclusion_msg, exclusion_fmt) + exclusion_fmt_len;
7b4a95b1
PP
224 for (i = 0; i < exclusion_count; ++i) {
225 const char *name;
226
227 /* Append comma between exclusion names */
228 if (i > 0) {
229 *at = ',';
230 at++;
231 }
232
233 ret = lttng_event_get_exclusion_name(event, i, &name);
234 if (ret) {
235 /* Prints '?' on local error; should never happen */
236 *at = '?';
237 at++;
238 continue;
239 }
240
241 /* Append exclusion name */
31e40170 242 at += sprintf(at, "%s", name);
7b4a95b1
PP
243 }
244
245 /* This also puts a final '\0' at the end of exclusion_msg */
19ed7632 246 strcpy(at, "]");
7b4a95b1
PP
247
248end:
249 return exclusion_msg;
250}
251
b551a063
DG
252/*
253 * Pretty print single event.
254 */
255static void print_events(struct lttng_event *event)
256{
4adbcc72
PP
257 int ret;
258 const char *filter_str;
259 char *filter_msg = NULL;
7b4a95b1 260 char *exclusion_msg = NULL;
4adbcc72 261
134e72ed 262 ret = lttng_event_get_filter_expression(event, &filter_str);
4adbcc72
PP
263
264 if (ret) {
265 filter_msg = strdup(" [failed to retrieve filter]");
266 } else if (filter_str) {
267 const char * const filter_fmt = " [filter: '%s']";
268
269 filter_msg = malloc(strlen(filter_str) +
270 strlen(filter_fmt) + 1);
271 if (filter_msg) {
272 sprintf(filter_msg, filter_fmt,
273 filter_str);
274 }
275 }
276
7b4a95b1
PP
277 exclusion_msg = get_exclusion_names_msg(event);
278 if (!exclusion_msg) {
279 exclusion_msg = strdup(" [failed to retrieve exclusions]");
280 }
281
b551a063
DG
282 switch (event->type) {
283 case LTTNG_EVENT_TRACEPOINT:
e4baff1e 284 {
8b703175 285 if (event->loglevel != -1) {
af6bce80 286 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
8b703175 287 indent6,
81afa345 288 event->name,
1f0e17de 289 logleveltype_string(event->loglevel_type),
970d848b 290 mi_lttng_loglevel_string(event->loglevel, handle->domain.type),
8b703175 291 event->loglevel,
fceb65df 292 enabled_string(event->enabled),
7b4a95b1
PP
293 safe_string(exclusion_msg),
294 safe_string(filter_msg));
8b703175 295 } else {
4634f12e 296 MSG("%s%s (type: tracepoint)%s%s%s",
8b703175
MD
297 indent6,
298 event->name,
fceb65df 299 enabled_string(event->enabled),
7b4a95b1
PP
300 safe_string(exclusion_msg),
301 safe_string(filter_msg));
8b703175 302 }
b551a063 303 break;
e4baff1e 304 }
1896972b
DG
305 case LTTNG_EVENT_FUNCTION:
306 MSG("%s%s (type: function)%s%s", indent6,
307 event->name, enabled_string(event->enabled),
7b4a95b1 308 safe_string(filter_msg));
1896972b
DG
309 if (event->attr.probe.addr != 0) {
310 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
311 } else {
312 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
313 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
314 }
315 break;
b551a063 316 case LTTNG_EVENT_PROBE:
fceb65df
MD
317 MSG("%s%s (type: probe)%s%s", indent6,
318 event->name, enabled_string(event->enabled),
7b4a95b1 319 safe_string(filter_msg));
b551a063
DG
320 if (event->attr.probe.addr != 0) {
321 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
322 } else {
323 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
324 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
325 }
326 break;
b551a063 327 case LTTNG_EVENT_FUNCTION_ENTRY:
fceb65df
MD
328 MSG("%s%s (type: function)%s%s", indent6,
329 event->name, enabled_string(event->enabled),
7b4a95b1 330 safe_string(filter_msg));
b551a063
DG
331 MSG("%ssymbol: \"%s\"", indent8, event->attr.ftrace.symbol_name);
332 break;
333 case LTTNG_EVENT_SYSCALL:
2199ad66 334 MSG("%s%s%s%s%s%s", indent6, event->name,
834978fd 335 (opt_syscall ? "" : " (type:syscall)"),
fceb65df 336 enabled_string(event->enabled),
2199ad66
JG
337 bitness_event(event->flags),
338 safe_string(filter_msg));
b551a063
DG
339 break;
340 case LTTNG_EVENT_NOOP:
fceb65df
MD
341 MSG("%s (type: noop)%s%s", indent6,
342 enabled_string(event->enabled),
7b4a95b1 343 safe_string(filter_msg));
b551a063
DG
344 break;
345 case LTTNG_EVENT_ALL:
346 /* We should never have "all" events in list. */
347 assert(0);
348 break;
349 }
4adbcc72
PP
350
351 free(filter_msg);
7b4a95b1 352 free(exclusion_msg);
b551a063
DG
353}
354
f37d259d
MD
355static const char *field_type(struct lttng_event_field *field)
356{
357 switch(field->type) {
358 case LTTNG_EVENT_FIELD_INTEGER:
359 return "integer";
360 case LTTNG_EVENT_FIELD_ENUM:
361 return "enum";
362 case LTTNG_EVENT_FIELD_FLOAT:
363 return "float";
364 case LTTNG_EVENT_FIELD_STRING:
365 return "string";
366 case LTTNG_EVENT_FIELD_OTHER:
367 default: /* fall-through */
368 return "unknown";
369 }
370}
371
372/*
373 * Pretty print single event fields.
374 */
375static void print_event_field(struct lttng_event_field *field)
376{
377 if (!field->field_name[0]) {
378 return;
379 }
d8fbe2a9 380 MSG("%sfield: %s (%s)%s", indent8, field->field_name,
45a32634 381 field_type(field), field->nowrite ? " [no write]" : "");
f37d259d
MD
382}
383
fb14d0d8
JR
384/*
385 * Machine interface
386 * Jul and ust event listing
387 */
5cdb6027 388static int mi_list_agent_ust_events(struct lttng_event *events, int count,
fb14d0d8
JR
389 struct lttng_domain *domain)
390{
391 int ret, i;
392 pid_t cur_pid = 0;
393 char *cmdline = NULL;
394 int pid_element_open = 0;
395
396 /* Open domains element */
397 ret = mi_lttng_domains_open(writer);
398 if (ret) {
399 goto end;
400 }
401
402 /* Write domain */
403 ret = mi_lttng_domain(writer, domain, 1);
404 if (ret) {
405 goto end;
406 }
407
bf239d4c
JR
408 /* Open pids element element */
409 ret = mi_lttng_pids_open(writer);
fb14d0d8
JR
410 if (ret) {
411 goto end;
412 }
413
414 for (i = 0; i < count; i++) {
415 if (cur_pid != events[i].pid) {
416 if (pid_element_open) {
2e9aecb9 417 /* Close the previous events and pid element */
fb14d0d8
JR
418 ret = mi_lttng_close_multi_element(writer, 2);
419 if (ret) {
420 goto end;
421 }
422 pid_element_open = 0;
423 }
424
425 cur_pid = events[i].pid;
426 cmdline = get_cmdline_by_pid(cur_pid);
427 if (!cmdline) {
428 ret = CMD_ERROR;
429 goto end;
430 }
431
432 if (!pid_element_open) {
433 /* Open and write a pid element */
bf239d4c 434 ret = mi_lttng_pid(writer, cur_pid, cmdline, 1);
fb14d0d8
JR
435 if (ret) {
436 goto error;
437 }
438
439 /* Open events element */
440 ret = mi_lttng_events_open(writer);
441 if (ret) {
442 goto error;
443 }
444
445 pid_element_open = 1;
446 }
447 free(cmdline);
448 }
449
450 /* Write an event */
970d848b 451 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
fb14d0d8
JR
452 if (ret) {
453 goto end;
454 }
455 }
456
bf239d4c 457 /* Close pids */
fb14d0d8
JR
458 ret = mi_lttng_writer_close_element(writer);
459 if (ret) {
460 goto end;
461 }
462
463 /* Close domain, domains */
464 ret = mi_lttng_close_multi_element(writer, 2);
465end:
466 return ret;
467error:
468 free(cmdline);
469 return ret;
470}
471
5cdb6027 472static int list_agent_events(void)
3c6a091f 473{
fb14d0d8 474 int i, size, ret = CMD_SUCCESS;
3c6a091f 475 struct lttng_domain domain;
26c610c9 476 struct lttng_handle *handle = NULL;
469b972b 477 struct lttng_event *event_list = NULL;
3c6a091f
DG
478 pid_t cur_pid = 0;
479 char *cmdline = NULL;
5cdb6027 480 const char *agent_domain_str;
3c6a091f
DG
481
482 memset(&domain, 0, sizeof(domain));
5cdb6027
DG
483 if (opt_jul) {
484 domain.type = LTTNG_DOMAIN_JUL;
485 } else if (opt_log4j) {
486 domain.type = LTTNG_DOMAIN_LOG4J;
0e115563
DG
487 } else if (opt_python) {
488 domain.type = LTTNG_DOMAIN_PYTHON;
26c610c9
JG
489 } else {
490 ERR("Invalid agent domain selected.");
491 ret = CMD_ERROR;
492 goto error;
5cdb6027
DG
493 }
494
495 agent_domain_str = get_domain_str(domain.type);
496
497 DBG("Getting %s tracing events", agent_domain_str);
3c6a091f
DG
498
499 handle = lttng_create_handle(NULL, &domain);
500 if (handle == NULL) {
fb14d0d8
JR
501 ret = CMD_ERROR;
502 goto end;
3c6a091f
DG
503 }
504
505 size = lttng_list_tracepoints(handle, &event_list);
506 if (size < 0) {
5cdb6027
DG
507 ERR("Unable to list %s events: %s", agent_domain_str,
508 lttng_strerror(size));
fb14d0d8
JR
509 ret = CMD_ERROR;
510 goto end;
3c6a091f
DG
511 }
512
fb14d0d8
JR
513 if (lttng_opt_mi) {
514 /* Mi print */
5cdb6027 515 ret = mi_list_agent_ust_events(event_list, size, &domain);
fb14d0d8
JR
516 if (ret) {
517 ret = CMD_ERROR;
518 goto error;
3c6a091f 519 }
fb14d0d8
JR
520 } else {
521 /* Pretty print */
5cdb6027
DG
522 MSG("%s events (Logger name):\n-------------------------",
523 agent_domain_str);
3c6a091f 524
fb14d0d8
JR
525 if (size == 0) {
526 MSG("None");
527 }
3c6a091f 528
fb14d0d8
JR
529 for (i = 0; i < size; i++) {
530 if (cur_pid != event_list[i].pid) {
531 cur_pid = event_list[i].pid;
532 cmdline = get_cmdline_by_pid(cur_pid);
533 if (cmdline == NULL) {
534 ret = CMD_ERROR;
535 goto error;
536 }
537 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
538 free(cmdline);
539 }
540 MSG("%s- %s", indent6, event_list[i].name);
541 }
3c6a091f 542
fb14d0d8
JR
543 MSG("");
544 }
3c6a091f
DG
545
546error:
fb14d0d8
JR
547 free(event_list);
548end:
3c6a091f 549 lttng_destroy_handle(handle);
fb14d0d8 550 return ret;
3c6a091f
DG
551}
552
b551a063
DG
553/*
554 * Ask session daemon for all user space tracepoints available.
555 */
556static int list_ust_events(void)
557{
fb14d0d8 558 int i, size, ret = CMD_SUCCESS;
b551a063
DG
559 struct lttng_domain domain;
560 struct lttng_handle *handle;
bec97646 561 struct lttng_event *event_list = NULL;
b551a063 562 pid_t cur_pid = 0;
ea5cbc00 563 char *cmdline = NULL;
b551a063 564
441c16a7
MD
565 memset(&domain, 0, sizeof(domain));
566
b551a063
DG
567 DBG("Getting UST tracing events");
568
569 domain.type = LTTNG_DOMAIN_UST;
570
571 handle = lttng_create_handle(NULL, &domain);
572 if (handle == NULL) {
fb14d0d8
JR
573 ret = CMD_ERROR;
574 goto end;
b551a063
DG
575 }
576
577 size = lttng_list_tracepoints(handle, &event_list);
578 if (size < 0) {
60e835ca 579 ERR("Unable to list UST events: %s", lttng_strerror(size));
fb14d0d8
JR
580 ret = CMD_ERROR;
581 goto error;
b551a063
DG
582 }
583
fb14d0d8
JR
584 if (lttng_opt_mi) {
585 /* Mi print */
5cdb6027 586 ret = mi_list_agent_ust_events(event_list, size, &domain);
fb14d0d8
JR
587 } else {
588 /* Pretty print */
589 MSG("UST events:\n-------------");
590
591 if (size == 0) {
592 MSG("None");
593 }
594
595 for (i = 0; i < size; i++) {
596 if (cur_pid != event_list[i].pid) {
597 cur_pid = event_list[i].pid;
598 cmdline = get_cmdline_by_pid(cur_pid);
599 if (cmdline == NULL) {
600 ret = CMD_ERROR;
601 goto error;
602 }
603 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
604 free(cmdline);
605 }
606 print_events(&event_list[i]);
607 }
b551a063 608
fb14d0d8 609 MSG("");
b551a063
DG
610 }
611
fb14d0d8
JR
612error:
613 free(event_list);
614end:
615 lttng_destroy_handle(handle);
616 return ret;
617}
618
619/*
620 * Machine interface
621 * List all ust event with their fields
622 */
623static int mi_list_ust_event_fields(struct lttng_event_field *fields, int count,
624 struct lttng_domain *domain)
625{
626 int ret, i;
627 pid_t cur_pid = 0;
628 char *cmdline = NULL;
629 int pid_element_open = 0;
630 int event_element_open = 0;
631 struct lttng_event cur_event;
632
d113fbc8
JR
633 memset(&cur_event, 0, sizeof(cur_event));
634
fb14d0d8
JR
635 /* Open domains element */
636 ret = mi_lttng_domains_open(writer);
637 if (ret) {
638 goto end;
639 }
640
641 /* Write domain */
642 ret = mi_lttng_domain(writer, domain, 1);
643 if (ret) {
644 goto end;
645 }
646
bf239d4c
JR
647 /* Open pids element */
648 ret = mi_lttng_pids_open(writer);
fb14d0d8
JR
649 if (ret) {
650 goto end;
651 }
652
653 for (i = 0; i < count; i++) {
654 if (cur_pid != fields[i].event.pid) {
655 if (pid_element_open) {
656 if (event_element_open) {
485ca16f 657 /* Close the previous field element and event. */
fb14d0d8
JR
658 ret = mi_lttng_close_multi_element(writer, 2);
659 if (ret) {
660 goto end;
661 }
662 event_element_open = 0;
663 }
664 /* Close the previous events, pid element */
665 ret = mi_lttng_close_multi_element(writer, 2);
666 if (ret) {
667 goto end;
668 }
669 pid_element_open = 0;
670 }
671
672 cur_pid = fields[i].event.pid;
ea5cbc00 673 cmdline = get_cmdline_by_pid(cur_pid);
fb14d0d8 674 if (!pid_element_open) {
bf239d4c
JR
675 /* Open and write a pid element */
676 ret = mi_lttng_pid(writer, cur_pid, cmdline, 1);
fb14d0d8
JR
677 if (ret) {
678 goto error;
679 }
680
681 /* Open events element */
682 ret = mi_lttng_events_open(writer);
683 if (ret) {
684 goto error;
685 }
686 pid_element_open = 1;
687 }
ea5cbc00 688 free(cmdline);
fb14d0d8
JR
689 /* Wipe current event since we are about to print a new PID. */
690 memset(&cur_event, 0, sizeof(cur_event));
b551a063 691 }
b551a063 692
fb14d0d8
JR
693 if (strcmp(cur_event.name, fields[i].event.name) != 0) {
694 if (event_element_open) {
695 /* Close the previous fields element and the previous event */
696 ret = mi_lttng_close_multi_element(writer, 2);
697 if (ret) {
698 goto end;
699 }
700 event_element_open = 0;
701 }
702
703 memcpy(&cur_event, &fields[i].event,
704 sizeof(cur_event));
b551a063 705
fb14d0d8
JR
706 if (!event_element_open) {
707 /* Open and write the event */
970d848b
DG
708 ret = mi_lttng_event(writer, &cur_event, 1,
709 handle->domain.type);
fb14d0d8
JR
710 if (ret) {
711 goto end;
712 }
713
714 /* Open a fields element */
715 ret = mi_lttng_event_fields_open(writer);
716 if (ret) {
717 goto end;
718 }
719 event_element_open = 1;
720 }
721 }
b551a063 722
fb14d0d8
JR
723 /* Print the event_field */
724 ret = mi_lttng_event_field(writer, &fields[i]);
725 if (ret) {
726 goto end;
727 }
728 }
b551a063 729
bf239d4c 730 /* Close pid, domain, domains */
fb14d0d8
JR
731 ret = mi_lttng_close_multi_element(writer, 3);
732end:
733 return ret;
b551a063 734error:
fb14d0d8
JR
735 free(cmdline);
736 return ret;
b551a063 737}
f3ed775e 738
f37d259d
MD
739/*
740 * Ask session daemon for all user space tracepoint fields available.
741 */
742static int list_ust_event_fields(void)
743{
fb14d0d8 744 int i, size, ret = CMD_SUCCESS;
f37d259d
MD
745 struct lttng_domain domain;
746 struct lttng_handle *handle;
747 struct lttng_event_field *event_field_list;
748 pid_t cur_pid = 0;
ea5cbc00
CB
749 char *cmdline = NULL;
750
f37d259d
MD
751 struct lttng_event cur_event;
752
753 memset(&domain, 0, sizeof(domain));
754 memset(&cur_event, 0, sizeof(cur_event));
755
756 DBG("Getting UST tracing event fields");
757
758 domain.type = LTTNG_DOMAIN_UST;
759
760 handle = lttng_create_handle(NULL, &domain);
761 if (handle == NULL) {
fb14d0d8
JR
762 ret = CMD_ERROR;
763 goto end;
f37d259d
MD
764 }
765
766 size = lttng_list_tracepoint_fields(handle, &event_field_list);
767 if (size < 0) {
60e835ca 768 ERR("Unable to list UST event fields: %s", lttng_strerror(size));
fb14d0d8
JR
769 ret = CMD_ERROR;
770 goto end;
f37d259d
MD
771 }
772
fb14d0d8
JR
773 if (lttng_opt_mi) {
774 /* Mi print */
775 ret = mi_list_ust_event_fields(event_field_list, size, &domain);
776 if (ret) {
777 ret = CMD_ERROR;
778 goto error;
779 }
780 } else {
781 /* Pretty print */
782 MSG("UST events:\n-------------");
f37d259d 783
fb14d0d8
JR
784 if (size == 0) {
785 MSG("None");
f37d259d 786 }
fb14d0d8
JR
787
788 for (i = 0; i < size; i++) {
789 if (cur_pid != event_field_list[i].event.pid) {
790 cur_pid = event_field_list[i].event.pid;
791 cmdline = get_cmdline_by_pid(cur_pid);
792 if (cmdline == NULL) {
793 ret = CMD_ERROR;
794 goto error;
795 }
796 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
797 free(cmdline);
798 /* Wipe current event since we are about to print a new PID. */
799 memset(&cur_event, 0, sizeof(cur_event));
800 }
801 if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
802 print_events(&event_field_list[i].event);
803 memcpy(&cur_event, &event_field_list[i].event,
804 sizeof(cur_event));
805 }
806 print_event_field(&event_field_list[i]);
f37d259d 807 }
f37d259d 808
fb14d0d8
JR
809 MSG("");
810 }
f37d259d 811
fb14d0d8 812error:
f37d259d 813 free(event_field_list);
fb14d0d8 814end:
f37d259d 815 lttng_destroy_handle(handle);
fb14d0d8
JR
816 return ret;
817}
f37d259d 818
fb14d0d8
JR
819/*
820 * Machine interface
821 * Print a list of kernel events
822 */
823static int mi_list_kernel_events(struct lttng_event *events, int count,
824 struct lttng_domain *domain)
825{
826 int ret, i;
f37d259d 827
fb14d0d8
JR
828 /* Open domains element */
829 ret = mi_lttng_domains_open(writer);
830 if (ret) {
831 goto end;
832 }
833
834 /* Write domain */
835 ret = mi_lttng_domain(writer, domain, 1);
836 if (ret) {
837 goto end;
838 }
839
840 /* Open events */
841 ret = mi_lttng_events_open(writer);
842 if (ret) {
843 goto end;
844 }
845
846 for (i = 0; i < count; i++) {
970d848b 847 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
fb14d0d8
JR
848 if (ret) {
849 goto end;
850 }
851 }
852
853 /* close events, domain and domains */
854 ret = mi_lttng_close_multi_element(writer, 3);
855 if (ret) {
856 goto end;
857 }
858
859end:
860 return ret;
f37d259d
MD
861}
862
f3ed775e 863/*
fb14d0d8 864 * Ask for all trace events in the kernel
f3ed775e 865 */
9f19cc17 866static int list_kernel_events(void)
f3ed775e 867{
fb14d0d8 868 int i, size, ret = CMD_SUCCESS;
b551a063
DG
869 struct lttng_domain domain;
870 struct lttng_handle *handle;
9f19cc17 871 struct lttng_event *event_list;
f3ed775e 872
441c16a7
MD
873 memset(&domain, 0, sizeof(domain));
874
b551a063
DG
875 DBG("Getting kernel tracing events");
876
877 domain.type = LTTNG_DOMAIN_KERNEL;
878
879 handle = lttng_create_handle(NULL, &domain);
880 if (handle == NULL) {
fb14d0d8 881 ret = CMD_ERROR;
b551a063
DG
882 goto error;
883 }
f3ed775e 884
cd80958d 885 size = lttng_list_tracepoints(handle, &event_list);
9f19cc17 886 if (size < 0) {
60e835ca 887 ERR("Unable to list kernel events: %s", lttng_strerror(size));
ef021732 888 lttng_destroy_handle(handle);
fb14d0d8 889 return CMD_ERROR;
f3ed775e
DG
890 }
891
fb14d0d8
JR
892 if (lttng_opt_mi) {
893 /* Mi print */
894 ret = mi_list_kernel_events(event_list, size, &domain);
895 if (ret) {
896 ret = CMD_ERROR;
897 goto end;
898 }
899 } else {
900 MSG("Kernel events:\n-------------");
f3ed775e 901
fb14d0d8
JR
902 for (i = 0; i < size; i++) {
903 print_events(&event_list[i]);
904 }
f3ed775e 905
fb14d0d8
JR
906 MSG("");
907 }
b551a063 908
fb14d0d8 909end:
f3ed775e
DG
910 free(event_list);
911
ef021732 912 lttng_destroy_handle(handle);
fb14d0d8 913 return ret;
b551a063
DG
914
915error:
ef021732 916 lttng_destroy_handle(handle);
fb14d0d8
JR
917 return ret;
918}
919
834978fd
DG
920/*
921 * Machine interface
922 * Print a list of system calls.
923 */
924static int mi_list_syscalls(struct lttng_event *events, int count)
925{
926 int ret, i;
927
928 /* Open events */
929 ret = mi_lttng_events_open(writer);
930 if (ret) {
931 goto end;
932 }
933
934 for (i = 0; i < count; i++) {
970d848b 935 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
834978fd
DG
936 if (ret) {
937 goto end;
938 }
939 }
940
941 /* Close events. */
942 ret = mi_lttng_writer_close_element(writer);
943 if (ret) {
944 goto end;
945 }
946
947end:
948 return ret;
949}
950
951/*
952 * Ask for kernel system calls.
953 */
954static int list_syscalls(void)
955{
956 int i, size, ret = CMD_SUCCESS;
957 struct lttng_event *event_list;
958
959 DBG("Getting kernel system call events");
960
961 size = lttng_list_syscalls(&event_list);
962 if (size < 0) {
963 ERR("Unable to list system calls: %s", lttng_strerror(size));
964 ret = CMD_ERROR;
965 goto error;
966 }
967
968 if (lttng_opt_mi) {
969 /* Mi print */
970 ret = mi_list_syscalls(event_list, size);
971 if (ret) {
972 ret = CMD_ERROR;
973 goto end;
974 }
975 } else {
976 MSG("System calls:\n-------------");
977
978 for (i = 0; i < size; i++) {
979 print_events(&event_list[i]);
980 }
981
982 MSG("");
983 }
984
985end:
986 free(event_list);
987 return ret;
988
989error:
990 return ret;
991}
992
fb14d0d8
JR
993/*
994 * Machine Interface
5cdb6027 995 * Print a list of agent events
fb14d0d8 996 */
5cdb6027 997static int mi_list_session_agent_events(struct lttng_event *events, int count)
fb14d0d8
JR
998{
999 int ret, i;
1000
1001 /* Open events element */
1002 ret = mi_lttng_events_open(writer);
1003 if (ret) {
1004 goto end;
1005 }
1006
1007 for (i = 0; i < count; i++) {
970d848b 1008 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
fb14d0d8
JR
1009 if (ret) {
1010 goto end;
1011 }
1012 }
1013
1014 /* Close events element */
1015 ret = mi_lttng_writer_close_element(writer);
1016
1017end:
1018 return ret;
f3ed775e
DG
1019}
1020
3c6a091f 1021/*
5cdb6027 1022 * List agent events for a specific session using the handle.
3c6a091f
DG
1023 *
1024 * Return CMD_SUCCESS on success else a negative value.
1025 */
5cdb6027 1026static int list_session_agent_events(void)
3c6a091f 1027{
fb14d0d8 1028 int ret = CMD_SUCCESS, count, i;
3c6a091f
DG
1029 struct lttng_event *events = NULL;
1030
1031 count = lttng_list_events(handle, "", &events);
1032 if (count < 0) {
fb14d0d8
JR
1033 ret = CMD_ERROR;
1034 ERR("%s", lttng_strerror(count));
3c6a091f
DG
1035 goto error;
1036 }
1037
fb14d0d8
JR
1038 if (lttng_opt_mi) {
1039 /* Mi print */
5cdb6027 1040 ret = mi_list_session_agent_events(events, count);
fb14d0d8
JR
1041 if (ret) {
1042 ret = CMD_ERROR;
1043 goto end;
1044 }
1045 } else {
1046 /* Pretty print */
1047 MSG("Events (Logger name):\n---------------------");
1048 if (count == 0) {
1049 MSG("%sNone\n", indent6);
1050 goto end;
1051 }
1052
1053 for (i = 0; i < count; i++) {
9a890ce8
JG
1054 const char *filter_str;
1055 char *filter_msg = NULL;
1056 struct lttng_event *event = &events[i];
1057
134e72ed
JG
1058 ret = lttng_event_get_filter_expression(event,
1059 &filter_str);
9a890ce8
JG
1060 if (ret) {
1061 filter_msg = strdup(" [failed to retrieve filter]");
1062 } else if (filter_str) {
1063 const char * const filter_fmt =
1064 " [filter: '%s']";
1065
1066 filter_msg = malloc(strlen(filter_str) +
1067 strlen(filter_fmt) + 1);
1068 if (filter_msg) {
00505bae
JG
1069 sprintf(filter_msg, filter_fmt,
1070 filter_str);
9a890ce8
JG
1071 }
1072 }
1073
1074 if (event->loglevel_type !=
755066c2 1075 LTTNG_EVENT_LOGLEVEL_ALL) {
9a890ce8
JG
1076 MSG("%s- %s%s (loglevel%s %s)%s", indent4,
1077 event->name,
1078 enabled_string(event->enabled),
755066c2 1079 logleveltype_string(
9a890ce8 1080 event->loglevel_type),
755066c2 1081 mi_lttng_loglevel_string(
9a890ce8
JG
1082 event->loglevel,
1083 handle->domain.type),
7b4a95b1 1084 safe_string(filter_msg));
755066c2 1085 } else {
9a890ce8
JG
1086 MSG("%s- %s%s%s", indent4, event->name,
1087 enabled_string(event->enabled),
7b4a95b1 1088 safe_string(filter_msg));
755066c2 1089 }
9a890ce8 1090 free(filter_msg);
fb14d0d8
JR
1091 }
1092
1093 MSG("");
1094 }
1095
1096end:
1097 free(events);
1098error:
1099 return ret;
1100}
1101
1102/*
1103 * Machine interface
1104 * print a list of event
1105 */
1106static int mi_list_events(struct lttng_event *events, int count)
1107{
1108 int ret, i;
1109
1110 /* Open events element */
1111 ret = mi_lttng_events_open(writer);
1112 if (ret) {
3c6a091f
DG
1113 goto end;
1114 }
1115
1116 for (i = 0; i < count; i++) {
970d848b 1117 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
fb14d0d8
JR
1118 if (ret) {
1119 goto end;
1120 }
3c6a091f
DG
1121 }
1122
fb14d0d8
JR
1123 /* Close events element */
1124 ret = mi_lttng_writer_close_element(writer);
3c6a091f
DG
1125
1126end:
3c6a091f
DG
1127 return ret;
1128}
1129
f3ed775e 1130/*
9f19cc17 1131 * List events of channel of session and domain.
f3ed775e 1132 */
cd80958d 1133static int list_events(const char *channel_name)
f3ed775e 1134{
fb14d0d8 1135 int ret = CMD_SUCCESS, count, i;
9f19cc17 1136 struct lttng_event *events = NULL;
f3ed775e 1137
cd80958d 1138 count = lttng_list_events(handle, channel_name, &events);
f3ed775e 1139 if (count < 0) {
fb14d0d8
JR
1140 ret = CMD_ERROR;
1141 ERR("%s", lttng_strerror(count));
f3ed775e
DG
1142 goto error;
1143 }
1144
fb14d0d8
JR
1145 if (lttng_opt_mi) {
1146 /* Mi print */
1147 ret = mi_list_events(events, count);
1148 if (ret) {
1149 ret = CMD_ERROR;
1150 goto end;
1151 }
1152 } else {
1153 /* Pretty print */
f3b3a67b 1154 MSG("\n%sEvent rules:", indent4);
fb14d0d8
JR
1155 if (count == 0) {
1156 MSG("%sNone\n", indent6);
1157 goto end;
1158 }
f3ed775e 1159
fb14d0d8
JR
1160 for (i = 0; i < count; i++) {
1161 print_events(&events[i]);
1162 }
f3ed775e 1163
fb14d0d8
JR
1164 MSG("");
1165 }
9f19cc17 1166end:
0e428499 1167 free(events);
f3ed775e
DG
1168error:
1169 return ret;
1170}
1171
f3b3a67b
JG
1172static
1173void print_timer(const char *timer_name, uint32_t space_count, int64_t value)
1174{
1175 uint32_t i;
1176
1177 _MSG("%s%s:", indent6, timer_name);
1178 for (i = 0; i < space_count; i++) {
1179 _MSG(" ");
1180 }
1181
1182 if (value) {
1183 MSG("%" PRId64 " µs", value);
1184 } else {
1185 MSG("inactive");
1186 }
1187}
1188
f3ed775e 1189/*
9f19cc17
DG
1190 * Pretty print channel
1191 */
1192static void print_channel(struct lttng_channel *channel)
1193{
fb83fe64 1194 int ret;
cf0bcb51 1195 uint64_t discarded_events, lost_packets, monitor_timer_interval;
491d1539 1196 int64_t blocking_timeout;
fb83fe64
JD
1197
1198 ret = lttng_channel_get_discarded_event_count(channel,
1199 &discarded_events);
1200 if (ret) {
1201 ERR("Failed to retrieve discarded event count of channel");
1202 return;
1203 }
1204
1205 ret = lttng_channel_get_lost_packet_count(channel,
1206 &lost_packets);
1207 if (ret) {
1208 ERR("Failed to retrieve lost packet count of channel");
1209 return;
1210 }
1211
cf0bcb51
JG
1212 ret = lttng_channel_get_monitor_timer_interval(channel,
1213 &monitor_timer_interval);
1214 if (ret) {
1215 ERR("Failed to retrieve monitor interval of channel");
1216 return;
1217 }
1218
491d1539
MD
1219 ret = lttng_channel_get_blocking_timeout(channel,
1220 &blocking_timeout);
1221 if (ret) {
1222 ERR("Failed to retrieve blocking timeout of channel");
1223 return;
1224 }
1225
464dd62d 1226 MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
9f19cc17 1227 MSG("%sAttributes:", indent4);
f3b3a67b
JG
1228 MSG("%sEvent-loss mode: %s", indent6, channel->attr.overwrite ? "overwrite" : "discard");
1229 MSG("%sSub-buffer size: %" PRIu64 " bytes", indent6, channel->attr.subbuf_size);
1230 MSG("%sSub-buffer count: %" PRIu64, indent6, channel->attr.num_subbuf);
1231
1232 print_timer("Switch timer", 5, channel->attr.switch_timer_interval);
1233 print_timer("Read timer", 7, channel->attr.read_timer_interval);
1234 print_timer("Monitor timer", 4, monitor_timer_interval);
1235
1236 if (!channel->attr.overwrite) {
1237 if (blocking_timeout == -1) {
1238 MSG("%sBlocking timeout: infinite", indent6);
1239 } else {
1240 MSG("%sBlocking timeout: %" PRId64 " µs", indent6, blocking_timeout);
1241 }
1242 }
1243
1244 MSG("%sTrace file count: %" PRIu64 " per stream", indent6,
1245 channel->attr.tracefile_count == 0 ?
1246 1 : channel->attr.tracefile_count);
1247 if (channel->attr.tracefile_size != 0 ) {
1248 MSG("%sTrace file size: %" PRIu64 " bytes", indent6,
1249 channel->attr.tracefile_size);
1250 } else {
1251 MSG("%sTrace file size: %s", indent6, "unlimited");
1252 }
9f19cc17
DG
1253 switch (channel->attr.output) {
1254 case LTTNG_EVENT_SPLICE:
f3b3a67b 1255 MSG("%sOutput mode: splice", indent6);
9f19cc17
DG
1256 break;
1257 case LTTNG_EVENT_MMAP:
f3b3a67b 1258 MSG("%sOutput mode: mmap", indent6);
9f19cc17
DG
1259 break;
1260 }
e50e81d3 1261
f3b3a67b
JG
1262 MSG("\n%sStatistics:", indent4);
1263 if (listed_session.snapshot_mode) {
e50e81d3
JG
1264 /*
1265 * The lost packet count is omitted for sessions in snapshot
1266 * mode as it is misleading: it would indicate the number of
1267 * packets that the consumer could not extract during the
1268 * course of recording the snapshot. It does not have the
1269 * same meaning as the "regular" lost packet count that
1270 * would result from the consumer not keeping up with
1271 * event production in an overwrite-mode channel.
1272 *
1273 * A more interesting statistic would be the number of
1274 * packets lost between the first and last extracted
1275 * packets of a given snapshot (which prevents most analyses).
1276 */
f3b3a67b 1277 MSG("%sNone", indent6);
e50e81d3
JG
1278 goto skip_stats_printing;
1279 }
1280
1281 if (!channel->attr.overwrite) {
f3b3a67b 1282 MSG("%sDiscarded events: %" PRIu64, indent6, discarded_events);
e50e81d3 1283 } else {
f3b3a67b 1284 MSG("%sLost packets: %" PRIu64, indent6, lost_packets);
e50e81d3
JG
1285 }
1286skip_stats_printing:
1287 return;
9f19cc17
DG
1288}
1289
fb14d0d8
JR
1290/*
1291 * Machine interface
1292 * Print a list of channel
1293 *
1294 */
1295static int mi_list_channels(struct lttng_channel *channels, int count,
1296 const char *channel_name)
1297{
1298 int i, ret;
1299 unsigned int chan_found = 0;
1300
1301 /* Open channels element */
1302 ret = mi_lttng_channels_open(writer);
1303 if (ret) {
1304 goto error;
1305 }
1306
1307 for (i = 0; i < count; i++) {
1308 if (channel_name != NULL) {
1309 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
1310 chan_found = 1;
1311 } else {
1312 continue;
1313 }
1314 }
1315
1316 /* Write channel element and leave it open */
1317 ret = mi_lttng_channel(writer, &channels[i], 1);
1318 if (ret) {
1319 goto error;
1320 }
1321
1322 /* Listing events per channel */
1323 ret = list_events(channels[i].name);
1324 if (ret) {
1325 goto error;
1326 }
1327
1328 /* Closing the channel element we opened earlier */
1329 ret = mi_lttng_writer_close_element(writer);
1330 if (ret) {
1331 goto error;
1332 }
1333
1334 if (chan_found) {
1335 break;
1336 }
1337 }
1338
1339 /* Close channels element */
1340 ret = mi_lttng_writer_close_element(writer);
1341 if (ret) {
1342 goto error;
1343 }
1344
1345error:
1346 return ret;
1347}
1348
9f19cc17
DG
1349/*
1350 * List channel(s) of session and domain.
f3ed775e 1351 *
9f19cc17 1352 * If channel_name is NULL, all channels are listed.
f3ed775e 1353 */
cd80958d 1354static int list_channels(const char *channel_name)
f3ed775e 1355{
9f19cc17
DG
1356 int count, i, ret = CMD_SUCCESS;
1357 unsigned int chan_found = 0;
1358 struct lttng_channel *channels = NULL;
f3ed775e 1359
3e25cb20 1360 DBG("Listing channel(s) (%s)", channel_name ? : "<all>");
9f19cc17 1361
cd80958d 1362 count = lttng_list_channels(handle, &channels);
f3ed775e 1363 if (count < 0) {
c7d620a2
DG
1364 switch (-count) {
1365 case LTTNG_ERR_KERN_CHAN_NOT_FOUND:
fb14d0d8
JR
1366 if (lttng_opt_mi) {
1367 /* When printing mi this is not an error
1368 * but an empty channels element */
1369 count = 0;
1370 } else {
1371 ret = CMD_SUCCESS;
1372 WARN("No kernel channel");
1373 goto error_channels;
1374 }
c7d620a2
DG
1375 break;
1376 default:
1377 /* We had a real error */
fb14d0d8
JR
1378 ret = CMD_ERROR;
1379 ERR("%s", lttng_strerror(count));
1380 goto error_channels;
60e835ca 1381 break;
c7d620a2 1382 }
f3ed775e
DG
1383 }
1384
fb14d0d8
JR
1385 if (lttng_opt_mi) {
1386 /* Mi print */
1387 ret = mi_list_channels(channels, count, channel_name);
1388 if (ret) {
1389 ret = CMD_ERROR;
1390 goto error;
1391 }
1392 } else {
1393 /* Pretty print */
ade7ce52 1394 if (count) {
fb14d0d8
JR
1395 MSG("Channels:\n-------------");
1396 }
9f19cc17 1397
fb14d0d8
JR
1398 for (i = 0; i < count; i++) {
1399 if (channel_name != NULL) {
1400 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
1401 chan_found = 1;
1402 } else {
1403 continue;
1404 }
1405 }
1406 print_channel(&channels[i]);
1407
1408 /* Listing events per channel */
1409 ret = list_events(channels[i].name);
1410 if (ret) {
1411 goto error;
1412 }
1413
1414 if (chan_found) {
1415 break;
9f19cc17
DG
1416 }
1417 }
9f19cc17 1418
fb14d0d8
JR
1419 if (!chan_found && channel_name != NULL) {
1420 ret = CMD_ERROR;
1421 ERR("Channel %s not found", channel_name);
1422 goto error;
9f19cc17 1423 }
fb14d0d8
JR
1424 }
1425error:
1426 free(channels);
9f19cc17 1427
fb14d0d8
JR
1428error_channels:
1429 return ret;
1430}
1431
a5dfbb9d
MD
1432/*
1433 * List tracker PID(s) of session and domain.
1434 */
1435static int list_tracker_pids(void)
1436{
ebbf5ab7
JR
1437 int ret = 0;
1438 int enabled;
a5dfbb9d 1439 int *pids = NULL;
6223570f 1440 size_t nr_pids;
a5dfbb9d
MD
1441
1442 ret = lttng_list_tracker_pids(handle,
1443 &enabled, &pids, &nr_pids);
1444 if (ret) {
1445 return ret;
1446 }
a5dfbb9d 1447 if (enabled) {
6223570f
JG
1448 int i;
1449 _MSG("PID tracker: [");
a5dfbb9d 1450
ebbf5ab7
JR
1451 /* Mi tracker_pid element*/
1452 if (writer) {
1453 /* Open tracker_pid and targets elements */
1454 ret = mi_lttng_pid_tracker_open(writer);
1455 if (ret) {
1456 goto end;
1457 }
1458 }
1459
a5dfbb9d
MD
1460 for (i = 0; i < nr_pids; i++) {
1461 if (i) {
1462 _MSG(",");
1463 }
1464 _MSG(" %d", pids[i]);
ebbf5ab7
JR
1465
1466 /* Mi */
1467 if (writer) {
1468 ret = mi_lttng_pid_target(writer, pids[i], 0);
1469 if (ret) {
1470 goto end;
1471 }
1472 }
a5dfbb9d 1473 }
6223570f 1474 _MSG(" ]\n\n");
ebbf5ab7
JR
1475
1476 /* Mi close tracker_pid and targets */
1477 if (writer) {
1478 ret = mi_lttng_close_multi_element(writer,2);
1479 if (ret) {
1480 goto end;
1481 }
1482 }
a5dfbb9d 1483 }
ebbf5ab7 1484end:
a5dfbb9d 1485 free(pids);
ebbf5ab7
JR
1486 return ret;
1487
1488}
1489
1490/*
1491 * List all tracker of a domain
1492 */
1493static int list_trackers(void)
1494{
1495 int ret;
1496
1497 /* Trackers listing */
1498 if (lttng_opt_mi) {
1499 ret = mi_lttng_trackers_open(writer);
1500 if (ret) {
1501 goto end;
1502 }
1503 }
1504
1505 /* pid tracker */
1506 ret = list_tracker_pids();
1507 if (ret) {
1508 goto end;
1509 }
1510
1511 if (lttng_opt_mi) {
1512 /* Close trackers element */
1513 ret = mi_lttng_writer_close_element(writer);
1514 if (ret) {
1515 goto end;
1516 }
1517 }
1518
1519end:
1520 return ret;
a5dfbb9d
MD
1521}
1522
329f3443
JD
1523/*
1524 * List the rotate settings (timer/size if any).
1525 */
1526static int list_rotate_settings(const char *session_name)
1527{
1528 int ret;
1529 uint64_t size, timer;
1530
1531 ret = lttng_rotation_schedule_get_timer_period(session_name, &timer);
1532 if (ret) {
1533 goto end;
1534 }
1535
1536 ret = lttng_rotation_schedule_get_size(session_name, &size);
1537 if (ret) {
1538 goto end;
1539 }
1540
1541 if (!timer && !size) {
1542 ret = 0;
1543 goto end;
1544 }
1545
1546 _MSG("Automatic rotation schedule settings:\n");
1547
1548 if (timer) {
1549 _MSG(" timer period: %" PRIu64" µs\n", timer);
1550 if (lttng_opt_mi) {
1551 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1552 config_element_rotation_timer_interval, timer);
1553 if (ret) {
1554 goto end;
1555 }
1556 }
1557 }
1558 if (size) {
1559 _MSG(" size threshold: %" PRIu64" bytes\n", size);
1560 if (lttng_opt_mi) {
1561 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1562 config_element_rotation_size, size);
1563 if (ret) {
1564 goto end;
1565 }
1566 }
1567 }
1568 _MSG("\n");
1569
1570end:
1571 return ret;
1572}
1573
fb14d0d8
JR
1574/*
1575 * Machine interface
1576 * Find the session with session_name as name
1577 * and print his informations.
1578 */
1579static int mi_list_session(const char *session_name,
1580 struct lttng_session *sessions, int count)
1581{
1582 int ret, i;
1583 unsigned int session_found = 0;
1584
1585 if (session_name == NULL) {
1586 ret = -LTTNG_ERR_SESS_NOT_FOUND;
1587 goto end;
1588 }
1589
1590 for (i = 0; i < count; i++) {
1591 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
1592 /* We need to leave it open to append other informations
1593 * like domain, channel, events etc.*/
1594 session_found = 1;
1595 ret = mi_lttng_session(writer, &sessions[i], 1);
1596 if (ret) {
1597 goto end;
1598 }
9f19cc17 1599 break;
f3ed775e 1600 }
f3ed775e
DG
1601 }
1602
fb14d0d8
JR
1603 if (!session_found) {
1604 ERR("Session '%s' not found", session_name);
1605 ret = -LTTNG_ERR_SESS_NOT_FOUND;
1606 goto end;
9f19cc17 1607 }
f3ed775e 1608
fb14d0d8
JR
1609end:
1610 return ret;
1611}
f3ed775e 1612
fb14d0d8
JR
1613/*
1614 * Machine interface
1615 * List all availables session
1616 */
1617static int mi_list_sessions(struct lttng_session *sessions, int count)
1618{
1619 int ret, i;
ae856491 1620
fb14d0d8
JR
1621 /* Opening sessions element */
1622 ret = mi_lttng_sessions_open(writer);
1623 if (ret) {
1624 goto end;
1625 }
1626
1627 /* Listing sessions */
1628 for (i = 0; i < count; i++) {
1629 ret = mi_lttng_session(writer, &sessions[i], 0);
1630 if (ret) {
1631 goto end;
1632 }
1633 }
1634
1635 /* Closing sessions element */
1636 ret = mi_lttng_writer_close_element(writer);
1637 if (ret) {
1638 goto end;
1639 }
1640
1641end:
f3ed775e
DG
1642 return ret;
1643}
1644
1645/*
9f19cc17 1646 * List available tracing session. List only basic information.
f3ed775e 1647 *
9f19cc17 1648 * If session_name is NULL, all sessions are listed.
f3ed775e 1649 */
9f19cc17 1650static int list_sessions(const char *session_name)
f3ed775e 1651{
fb14d0d8
JR
1652 int ret = CMD_SUCCESS;
1653 int count, i;
9f19cc17
DG
1654 unsigned int session_found = 0;
1655 struct lttng_session *sessions;
1656
1657 count = lttng_list_sessions(&sessions);
1658 DBG("Session count %d", count);
1659 if (count < 0) {
fb14d0d8
JR
1660 ret = CMD_ERROR;
1661 ERR("%s", lttng_strerror(count));
d32fb093 1662 goto end;
9f19cc17
DG
1663 }
1664
fb14d0d8
JR
1665 if (lttng_opt_mi) {
1666 /* Mi */
1667 if (session_name == NULL) {
1668 /* List all session */
1669 ret = mi_list_sessions(sessions, count);
1670 } else {
1671 /* Note : this return an open session element */
1672 ret = mi_list_session(session_name, sessions, count);
1673 }
1674 if (ret) {
1675 ret = CMD_ERROR;
1676 goto error;
1677 }
1678 } else {
1679 /* Pretty print */
1680 if (count == 0) {
1681 MSG("Currently no available tracing session");
fb14d0d8
JR
1682 goto end;
1683 }
9f19cc17 1684
fb14d0d8
JR
1685 if (session_name == NULL) {
1686 MSG("Available tracing sessions:");
1687 }
1688
1689
1690 for (i = 0; i < count; i++) {
1691 if (session_name != NULL) {
1692 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
1693 session_found = 1;
1694 MSG("Tracing session %s: [%s%s]", session_name,
1695 active_string(sessions[i].enabled),
1696 snapshot_string(sessions[i].snapshot_mode));
1697 MSG("%sTrace path: %s\n", indent4, sessions[i].path);
e50e81d3
JG
1698 memcpy(&listed_session, &sessions[i],
1699 sizeof(listed_session));
fb14d0d8
JR
1700 break;
1701 }
1702 } else {
1703 MSG(" %d) %s (%s) [%s%s]", i + 1,
1704 sessions[i].name, sessions[i].path,
2cbf8fed
DG
1705 active_string(sessions[i].enabled),
1706 snapshot_string(sessions[i].snapshot_mode));
2f785fe7 1707 MSG("%sTrace path: %s", indent4, sessions[i].path);
fcbc96a2 1708 if (sessions[i].live_timer_interval != 0) {
e50e81d3 1709 MSG("%sLive timer interval: %u µs", indent4,
fcbc96a2
JG
1710 sessions[i].live_timer_interval);
1711 }
1712 MSG("");
9f19cc17 1713 }
fb14d0d8
JR
1714 }
1715
1716 if (!session_found && session_name != NULL) {
1717 ERR("Session '%s' not found", session_name);
1718 ret = CMD_ERROR;
1719 goto error;
1720 }
1721
1722 if (session_name == NULL) {
1723 MSG("\nUse lttng list <session_name> for more details");
9f19cc17
DG
1724 }
1725 }
1726
fb14d0d8 1727error:
9f19cc17 1728 free(sessions);
fb14d0d8
JR
1729end:
1730 return ret;
1731}
9f19cc17 1732
fb14d0d8
JR
1733
1734/*
1735 * Machine Interface
1736 * list available domain(s) for a session.
1737 */
1738static int mi_list_domains(struct lttng_domain *domains, int count)
1739{
1740 int i, ret;
1741 /* Open domains element */
1742 ret = mi_lttng_domains_open(writer);
1743 if (ret) {
1744 goto end;
9f19cc17
DG
1745 }
1746
fb14d0d8
JR
1747 for (i = 0; i < count; i++) {
1748 ret = mi_lttng_domain(writer, &domains[i] , 0);
1749 if (ret) {
1750 goto end;
1751 }
9f19cc17 1752 }
f3ed775e 1753
fb14d0d8
JR
1754 /* Closing domains element */
1755 ret = mi_lttng_writer_close_element(writer);
1756 if (ret) {
1757 goto end;
1758 }
d32fb093 1759end:
f3ed775e
DG
1760 return ret;
1761}
f3ed775e
DG
1762
1763/*
9f19cc17 1764 * List available domain(s) for a session.
f3ed775e 1765 */
330be774 1766static int list_domains(const char *session_name)
f3ed775e 1767{
9f19cc17
DG
1768 int i, count, ret = CMD_SUCCESS;
1769 struct lttng_domain *domains = NULL;
1770
9f19cc17 1771
330be774 1772 count = lttng_list_domains(session_name, &domains);
9f19cc17 1773 if (count < 0) {
fb14d0d8
JR
1774 ret = CMD_ERROR;
1775 ERR("%s", lttng_strerror(count));
9f19cc17
DG
1776 goto end;
1777 }
1778
fb14d0d8
JR
1779 if (lttng_opt_mi) {
1780 /* Mi output */
1781 ret = mi_list_domains(domains, count);
1782 if (ret) {
1783 ret = CMD_ERROR;
1784 goto error;
1785 }
1786 } else {
1787 /* Pretty print */
1788 MSG("Domains:\n-------------");
1789 if (count == 0) {
1790 MSG(" None");
1791 goto end;
1792 }
1793
1794 for (i = 0; i < count; i++) {
1795 switch (domains[i].type) {
1796 case LTTNG_DOMAIN_KERNEL:
1797 MSG(" - Kernel");
1798 break;
1799 case LTTNG_DOMAIN_UST:
1800 MSG(" - UST global");
1801 break;
1802 case LTTNG_DOMAIN_JUL:
1803 MSG(" - JUL (Java Util Logging)");
1804 break;
5cdb6027
DG
1805 case LTTNG_DOMAIN_LOG4J:
1806 MSG(" - LOG4j (Logging for Java)");
1807 break;
0e115563
DG
1808 case LTTNG_DOMAIN_PYTHON:
1809 MSG(" - Python (logging)");
1810 break;
fb14d0d8
JR
1811 default:
1812 break;
1813 }
9f19cc17
DG
1814 }
1815 }
1816
fb14d0d8 1817error:
9f19cc17
DG
1818 free(domains);
1819
fb14d0d8 1820end:
9f19cc17 1821 return ret;
f3ed775e 1822}
f3ed775e
DG
1823
1824/*
9f19cc17 1825 * The 'list <options>' first level command
f3ed775e
DG
1826 */
1827int cmd_list(int argc, const char **argv)
1828{
c617c0c6 1829 int opt, ret = CMD_SUCCESS;
68c7f6e5 1830 const char *session_name, *leftover = NULL;
f3ed775e 1831 static poptContext pc;
9f19cc17
DG
1832 struct lttng_domain domain;
1833 struct lttng_domain *domains = NULL;
f3ed775e 1834
441c16a7
MD
1835 memset(&domain, 0, sizeof(domain));
1836
9f19cc17 1837 if (argc < 1) {
ca1c3607 1838 ret = CMD_ERROR;
f3ed775e
DG
1839 goto end;
1840 }
1841
1842 pc = poptGetContext(NULL, argc, argv, long_options, 0);
1843 poptReadDefaultConfig(pc, 0);
1844
1845 while ((opt = poptGetNextOpt(pc)) != -1) {
1846 switch (opt) {
1847 case OPT_HELP:
4ba92f18 1848 SHOW_HELP();
f3ed775e 1849 goto end;
eeac7d46
MD
1850 case OPT_USERSPACE:
1851 opt_userspace = 1;
eeac7d46 1852 break;
679b4943
SM
1853 case OPT_LIST_OPTIONS:
1854 list_cmd_options(stdout, long_options);
679b4943 1855 goto end;
f3ed775e 1856 default:
f3ed775e
DG
1857 ret = CMD_UNDEFINED;
1858 goto end;
1859 }
1860 }
1861
fb14d0d8
JR
1862 /* Mi check */
1863 if (lttng_opt_mi) {
1864 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
1865 if (!writer) {
1866 ret = CMD_ERROR;
1867 goto end;
1868 }
1869
1870 /* Open command element */
1871 ret = mi_lttng_writer_command_open(writer,
1872 mi_lttng_element_command_list);
1873 if (ret) {
1874 ret = CMD_ERROR;
1875 goto end;
1876 }
1877
1878 /* Open output element */
1879 ret = mi_lttng_writer_open_element(writer,
1880 mi_lttng_element_command_output);
1881 if (ret) {
1882 ret = CMD_ERROR;
1883 goto end;
1884 }
1885 }
1886
9f19cc17
DG
1887 /* Get session name (trailing argument) */
1888 session_name = poptGetArg(pc);
b551a063 1889 DBG2("Session name: %s", session_name);
9f19cc17 1890
68c7f6e5
JD
1891 leftover = poptGetArg(pc);
1892 if (leftover) {
1893 ERR("Unknown argument: %s", leftover);
1894 ret = CMD_ERROR;
1895 goto end;
1896 }
1897
cd80958d
DG
1898 if (opt_kernel) {
1899 domain.type = LTTNG_DOMAIN_KERNEL;
b551a063
DG
1900 } else if (opt_userspace) {
1901 DBG2("Listing userspace global domain");
1902 domain.type = LTTNG_DOMAIN_UST;
3c6a091f
DG
1903 } else if (opt_jul) {
1904 DBG2("Listing JUL domain");
1905 domain.type = LTTNG_DOMAIN_JUL;
edf60534 1906 } else if (opt_log4j) {
5cdb6027 1907 domain.type = LTTNG_DOMAIN_LOG4J;
0e115563
DG
1908 } else if (opt_python) {
1909 domain.type = LTTNG_DOMAIN_PYTHON;
cd80958d
DG
1910 }
1911
834978fd
DG
1912 if (!opt_kernel && opt_syscall) {
1913 WARN("--syscall will only work with the Kernel domain (-k)");
1914 ret = CMD_ERROR;
1915 goto end;
1916 }
1917
0e115563 1918 if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) {
aa5de748
MD
1919 handle = lttng_create_handle(session_name, &domain);
1920 if (handle == NULL) {
1921 ret = CMD_FATAL;
1922 goto end;
1923 }
cd80958d
DG
1924 }
1925
9f19cc17 1926 if (session_name == NULL) {
0e115563
DG
1927 if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j
1928 && !opt_python) {
b551a063 1929 ret = list_sessions(NULL);
fb14d0d8 1930 if (ret) {
b551a063
DG
1931 goto end;
1932 }
1933 }
9f19cc17 1934 if (opt_kernel) {
834978fd
DG
1935 if (opt_syscall) {
1936 ret = list_syscalls();
1937 if (ret) {
1938 goto end;
1939 }
1940 } else {
1941 ret = list_kernel_events();
1942 if (ret) {
1943 goto end;
1944 }
9f19cc17 1945 }
b551a063
DG
1946 }
1947 if (opt_userspace) {
f37d259d
MD
1948 if (opt_fields) {
1949 ret = list_ust_event_fields();
1950 } else {
1951 ret = list_ust_events();
1952 }
fb14d0d8 1953 if (ret) {
9f19cc17
DG
1954 goto end;
1955 }
1956 }
0e115563 1957 if (opt_jul || opt_log4j || opt_python) {
5cdb6027 1958 ret = list_agent_events();
fb14d0d8 1959 if (ret) {
3c6a091f
DG
1960 goto end;
1961 }
1962 }
9f19cc17
DG
1963 } else {
1964 /* List session attributes */
fb14d0d8
JR
1965 if (lttng_opt_mi) {
1966 /* Open element sessions
1967 * Present for xml consistency */
1968 ret = mi_lttng_sessions_open(writer);
1969 if (ret) {
1970 goto end;
1971 }
1972 }
1973 /* MI: the ouptut of list_sessions is an unclosed session element */
9f19cc17 1974 ret = list_sessions(session_name);
fb14d0d8 1975 if (ret) {
9f19cc17
DG
1976 goto end;
1977 }
1978
329f3443
JD
1979 ret = list_rotate_settings(session_name);
1980 if (ret) {
1981 goto end;
1982 }
1983
9f19cc17
DG
1984 /* Domain listing */
1985 if (opt_domain) {
330be774 1986 ret = list_domains(session_name);
9f19cc17
DG
1987 goto end;
1988 }
1989
fb14d0d8 1990 /* Channel listing */
1c3de747 1991 if (opt_kernel || opt_userspace) {
fb14d0d8
JR
1992 if (lttng_opt_mi) {
1993 /* Add of domains and domain element for xml
1994 * consistency and validation
1995 */
1996 ret = mi_lttng_domains_open(writer);
1997 if (ret) {
1998 goto end;
1999 }
2000
2001 /* Open domain and leave it open for
2002 * nested channels printing */
2003 ret = mi_lttng_domain(writer, &domain, 1);
2004 if (ret) {
2005 goto end;
2006 }
2007
2008 }
2009
ebbf5ab7
JR
2010
2011 /* Trackers */
2012 ret = list_trackers();
a5dfbb9d
MD
2013 if (ret) {
2014 goto end;
2015 }
2016
ebbf5ab7 2017 /* Channels */
cd80958d 2018 ret = list_channels(opt_channel);
fb14d0d8
JR
2019 if (ret) {
2020 goto end;
2021 }
2022
2023 if (lttng_opt_mi) {
2024 /* Close domain and domain element */
2025 ret = mi_lttng_close_multi_element(writer, 2);
2026 }
2027 if (ret) {
9f19cc17
DG
2028 goto end;
2029 }
fb14d0d8
JR
2030
2031
9f19cc17 2032 } else {
c617c0c6
MD
2033 int i, nb_domain;
2034
9f19cc17 2035 /* We want all domain(s) */
330be774 2036 nb_domain = lttng_list_domains(session_name, &domains);
b551a063 2037 if (nb_domain < 0) {
fb14d0d8
JR
2038 ret = CMD_ERROR;
2039 ERR("%s", lttng_strerror(nb_domain));
9f19cc17
DG
2040 goto end;
2041 }
2042
fb14d0d8
JR
2043 if (lttng_opt_mi) {
2044 ret = mi_lttng_domains_open(writer);
2045 if (ret) {
2046 ret = CMD_ERROR;
2047 goto end;
2048 }
2049 }
2050
b551a063 2051 for (i = 0; i < nb_domain; i++) {
9f19cc17
DG
2052 switch (domains[i].type) {
2053 case LTTNG_DOMAIN_KERNEL:
2054 MSG("=== Domain: Kernel ===\n");
2055 break;
b551a063
DG
2056 case LTTNG_DOMAIN_UST:
2057 MSG("=== Domain: UST global ===\n");
88c5f0d8
DG
2058 MSG("Buffer type: %s\n",
2059 domains[i].buf_type ==
2060 LTTNG_BUFFER_PER_PID ? "per PID" : "per UID");
b551a063 2061 break;
3c6a091f
DG
2062 case LTTNG_DOMAIN_JUL:
2063 MSG("=== Domain: JUL (Java Util Logging) ===\n");
2064 break;
5cdb6027
DG
2065 case LTTNG_DOMAIN_LOG4J:
2066 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
2067 break;
0e115563
DG
2068 case LTTNG_DOMAIN_PYTHON:
2069 MSG("=== Domain: Python (logging) ===\n");
2070 break;
9f19cc17
DG
2071 default:
2072 MSG("=== Domain: Unimplemented ===\n");
2073 break;
2074 }
2075
fb14d0d8
JR
2076 if (lttng_opt_mi) {
2077 ret = mi_lttng_domain(writer, &domains[i], 1);
2078 if (ret) {
2079 ret = CMD_ERROR;
2080 goto end;
2081 }
2082 }
2083
cd80958d 2084 /* Clean handle before creating a new one */
aa5de748
MD
2085 if (handle) {
2086 lttng_destroy_handle(handle);
2087 }
cd80958d
DG
2088
2089 handle = lttng_create_handle(session_name, &domains[i]);
2090 if (handle == NULL) {
ca1c3607 2091 ret = CMD_FATAL;
cd80958d
DG
2092 goto end;
2093 }
2094
5cdb6027 2095 if (domains[i].type == LTTNG_DOMAIN_JUL ||
0e115563
DG
2096 domains[i].type == LTTNG_DOMAIN_LOG4J ||
2097 domains[i].type == LTTNG_DOMAIN_PYTHON) {
5cdb6027 2098 ret = list_session_agent_events();
fb14d0d8 2099 if (ret) {
3c6a091f
DG
2100 goto end;
2101 }
cd7b2927
PP
2102
2103 goto next_domain;
3c6a091f 2104 }
a5dfbb9d
MD
2105
2106 switch (domains[i].type) {
2107 case LTTNG_DOMAIN_KERNEL:
2108 case LTTNG_DOMAIN_UST:
ebbf5ab7 2109 ret = list_trackers();
a5dfbb9d
MD
2110 if (ret) {
2111 goto end;
2112 }
2113 break;
2114 default:
2115 break;
2116 }
3c6a091f 2117
cd80958d 2118 ret = list_channels(opt_channel);
fb14d0d8
JR
2119 if (ret) {
2120 goto end;
2121 }
2122
cd7b2927 2123next_domain:
fb14d0d8
JR
2124 if (lttng_opt_mi) {
2125 /* Close domain element */
2126 ret = mi_lttng_writer_close_element(writer);
2127 if (ret) {
2128 ret = CMD_ERROR;
2129 goto end;
2130 }
2131 }
2132
2133 }
2134 if (lttng_opt_mi) {
2135 /* Close the domains, session and sessions element */
2136 ret = mi_lttng_close_multi_element(writer, 3);
2137 if (ret) {
2138 ret = CMD_ERROR;
9f19cc17
DG
2139 goto end;
2140 }
2141 }
2142 }
f3ed775e
DG
2143 }
2144
fb14d0d8
JR
2145 /* Mi closing */
2146 if (lttng_opt_mi) {
2147 /* Close output element */
2148 ret = mi_lttng_writer_close_element(writer);
2149 if (ret) {
2150 ret = CMD_ERROR;
2151 goto end;
2152 }
2153
2154 /* Command element close */
2155 ret = mi_lttng_writer_command_close(writer);
2156 if (ret) {
2157 ret = CMD_ERROR;
2158 goto end;
2159 }
2160 }
f3ed775e 2161end:
fb14d0d8
JR
2162 /* Mi clean-up */
2163 if (writer && mi_lttng_writer_destroy(writer)) {
2164 /* Preserve original error code */
2165 ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
2166 }
2167
0e428499 2168 free(domains);
aa5de748
MD
2169 if (handle) {
2170 lttng_destroy_handle(handle);
2171 }
cd80958d 2172
ca1c3607 2173 poptFreeContext(pc);
f3ed775e
DG
2174 return ret;
2175}
This page took 0.258372 seconds and 4 git commands to generate.