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