7364c5d82ce8a6a9b85acf9ee771a0c6210ff488
[lttng-tools.git] / src / common / mi-lttng.c
1 /*
2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19
20 #include <include/config.h>
21 #include <common/config/config.h>
22 #include "mi-lttng.h"
23
24 #include <assert.h>
25
26 /* Strings related to command */
27 const char * const mi_lttng_element_command = "command";
28 const char * const mi_lttng_element_command_version = "version";
29 const char * const mi_lttng_element_command_list = "list";
30 const char * const mi_lttng_element_command_name = "name";
31 const char * const mi_lttng_element_command_output = "output";
32
33 /* Strings related to command: version */
34 const char * const mi_lttng_element_version = "version";
35 const char * const mi_lttng_element_version_str = "string";
36 const char * const mi_lttng_element_version_web = "url";
37 const char * const mi_lttng_element_version_major = "major";
38 const char * const mi_lttng_element_version_minor = "minor";
39 const char * const mi_lttng_element_version_commit = "commit";
40 const char * const mi_lttng_element_version_license = "license";
41 const char * const mi_lttng_element_version_patch_level = "patchLevel";
42 const char * const mi_lttng_element_version_description = "description";
43
44 /* Strings related to pid */
45 const char * const mi_lttng_element_pids = "pids";
46 const char * const mi_lttng_element_pid = "pid";
47 const char * const mi_lttng_element_pid_id = "id";
48
49 /* String related to a lttng_event_field */
50 const char * const mi_lttng_element_event_field = "event_field";
51 const char * const mi_lttng_element_event_fields = "event_fields";
52
53 /* General elements of mi_lttng */
54 const char * const mi_lttng_element_type_other = "OTHER";
55 const char * const mi_lttng_element_type_integer = "INTEGER";
56 const char * const mi_lttng_element_type_enum = "ENUM";
57 const char * const mi_lttng_element_type_float = "FLOAT";
58 const char * const mi_lttng_element_type_string = "STRING";
59 const char * const mi_lttng_element_nowrite = "nowrite";
60
61 /* String related to loglevel */
62 const char * const mi_lttng_loglevel_str_alert = "TRACE_ALERT";
63 const char * const mi_lttng_loglevel_str_crit = "TRACE_CRIT";
64 const char * const mi_lttng_loglevel_str_debug = "TRACE_DEBUG";
65 const char * const mi_lttng_loglevel_str_debug_function = "TRACE_DEBUG_FUNCTION";
66 const char * const mi_lttng_loglevel_str_debug_line = "TRACE_DEBUG_LINE";
67 const char * const mi_lttng_loglevel_str_debug_module = "TRACE_DEBUG_MODULE";
68 const char * const mi_lttng_loglevel_str_debug_process = "TRACE_DEBUG_PROCESS";
69 const char * const mi_lttng_loglevel_str_debug_program = "TRACE_DEBUG_PROGRAM";
70 const char * const mi_lttng_loglevel_str_debug_system = "TRACE_DEBUG_SYSTEM";
71 const char * const mi_lttng_loglevel_str_debug_unit = "TRACE_DEBUG_UNIT";
72 const char * const mi_lttng_loglevel_str_emerg = "TRACE_EMERG";
73 const char * const mi_lttng_loglevel_str_err = "TRACE_ERR";
74 const char * const mi_lttng_loglevel_str_info = "TRACE_INFO";
75 const char * const mi_lttng_loglevel_str_notice = "TRACE_NOTICE";
76 const char * const mi_lttng_loglevel_str_unknown = "UNKNOWN";
77 const char * const mi_lttng_loglevel_str_warning = "TRACE_WARNING";
78
79 const char * const mi_lttng_loglevel_type_all = "ALL";
80 const char * const mi_lttng_loglevel_type_range = "RANGE";
81 const char * const mi_lttng_loglevel_type_single = "SINGLE";
82 const char * const mi_lttng_loglevel_type_unknown = "UNKNOWN";
83
84 const char * const mi_lttng_element_empty = "";
85
86 const char *mi_lttng_loglevel_string(int value)
87 {
88 switch (value) {
89 case -1:
90 return mi_lttng_element_empty;
91 case LTTNG_LOGLEVEL_EMERG:
92 return mi_lttng_loglevel_str_emerg;
93 case LTTNG_LOGLEVEL_ALERT:
94 return mi_lttng_loglevel_str_alert;
95 case LTTNG_LOGLEVEL_CRIT:
96 return mi_lttng_loglevel_str_crit;
97 case LTTNG_LOGLEVEL_ERR:
98 return mi_lttng_loglevel_str_err;
99 case LTTNG_LOGLEVEL_WARNING:
100 return mi_lttng_loglevel_str_warning;
101 case LTTNG_LOGLEVEL_NOTICE:
102 return mi_lttng_loglevel_str_notice;
103 case LTTNG_LOGLEVEL_INFO:
104 return mi_lttng_loglevel_str_info;
105 case LTTNG_LOGLEVEL_DEBUG_SYSTEM:
106 return mi_lttng_loglevel_str_debug_system;
107 case LTTNG_LOGLEVEL_DEBUG_PROGRAM:
108 return mi_lttng_loglevel_str_debug_program;
109 case LTTNG_LOGLEVEL_DEBUG_PROCESS:
110 return mi_lttng_loglevel_str_debug_process;
111 case LTTNG_LOGLEVEL_DEBUG_MODULE:
112 return mi_lttng_loglevel_str_debug_module;
113 case LTTNG_LOGLEVEL_DEBUG_UNIT:
114 return mi_lttng_loglevel_str_debug_unit;
115 case LTTNG_LOGLEVEL_DEBUG_FUNCTION:
116 return mi_lttng_loglevel_str_debug_function;
117 case LTTNG_LOGLEVEL_DEBUG_LINE:
118 return mi_lttng_loglevel_str_debug_line;
119 case LTTNG_LOGLEVEL_DEBUG:
120 return mi_lttng_loglevel_str_debug;
121 default:
122 return mi_lttng_loglevel_str_unknown;
123 }
124 }
125
126 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value)
127 {
128 switch (value) {
129 case LTTNG_EVENT_LOGLEVEL_ALL:
130 return mi_lttng_loglevel_type_all;
131 case LTTNG_EVENT_LOGLEVEL_RANGE:
132 return mi_lttng_loglevel_type_range;
133 case LTTNG_EVENT_LOGLEVEL_SINGLE:
134 return mi_lttng_loglevel_type_single;
135 default:
136 return mi_lttng_loglevel_type_unknown;
137 }
138 }
139
140 const char *mi_lttng_eventtype_string(enum lttng_event_type value)
141 {
142 switch (value) {
143 case LTTNG_EVENT_ALL:
144 return config_event_type_all;
145 case LTTNG_EVENT_TRACEPOINT:
146 return config_event_type_tracepoint;
147 case LTTNG_EVENT_PROBE:
148 return config_event_type_probe;
149 case LTTNG_EVENT_FUNCTION:
150 return config_event_type_function;
151 case LTTNG_EVENT_FUNCTION_ENTRY:
152 return config_event_type_function_entry;
153 case LTTNG_EVENT_SYSCALL:
154 return config_event_type_syscall;
155 case LTTNG_EVENT_NOOP:
156 return config_event_type_noop;
157 default:
158 return mi_lttng_element_empty;
159 }
160 }
161
162 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val)
163 {
164 switch (val) {
165 case(LTTNG_EVENT_FIELD_INTEGER):
166 return mi_lttng_element_type_integer;
167 case(LTTNG_EVENT_FIELD_ENUM):
168 return mi_lttng_element_type_enum;
169 case(LTTNG_EVENT_FIELD_FLOAT):
170 return mi_lttng_element_type_float;
171 case(LTTNG_EVENT_FIELD_STRING):
172 return mi_lttng_element_type_string;
173 default:
174 return mi_lttng_element_type_other;
175 }
176 }
177
178 const char *mi_lttng_domaintype_string(enum lttng_domain_type value)
179 {
180 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
181 switch (value) {
182 case LTTNG_DOMAIN_KERNEL:
183 return config_domain_type_kernel;
184 case LTTNG_DOMAIN_UST:
185 return config_domain_type_ust;
186 case LTTNG_DOMAIN_JUL:
187 return config_domain_type_jul;
188 default:
189 /* Should not have an unknown domain */
190 assert(0);
191 }
192 }
193
194 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value)
195 {
196 switch (value) {
197 case LTTNG_BUFFER_PER_PID:
198 return config_buffer_type_per_pid;
199 case LTTNG_BUFFER_PER_UID:
200 return config_buffer_type_per_uid;
201 case LTTNG_BUFFER_GLOBAL:
202 return config_buffer_type_global;
203 default:
204 /* Should not have an unknow buffer type */
205 assert(0);
206 }
207 }
208
209 LTTNG_HIDDEN
210 struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type)
211 {
212 struct mi_writer *mi_writer;
213
214 mi_writer = zmalloc(sizeof(struct mi_writer));
215 if (!mi_writer) {
216 PERROR("zmalloc mi_writer_create");
217 goto end;
218 }
219 if (mi_output_type == LTTNG_MI_XML) {
220 mi_writer->writer = config_writer_create(fd_output);
221 if (!mi_writer->writer) {
222 goto err_destroy;
223 }
224 mi_writer->type = LTTNG_MI_XML;
225 } else {
226 goto err_destroy;
227 }
228
229 end:
230 return mi_writer;
231
232 err_destroy:
233 free(mi_writer);
234 return NULL;
235 }
236
237 LTTNG_HIDDEN
238 int mi_lttng_writer_destroy(struct mi_writer *writer)
239 {
240 int ret;
241
242 if (!writer) {
243 ret = -EINVAL;
244 goto end;
245 }
246
247 ret = config_writer_destroy(writer->writer);
248 if (ret < 0) {
249 goto end;
250 }
251
252 free(writer);
253 end:
254 return ret;
255 }
256
257 LTTNG_HIDDEN
258 int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command)
259 {
260 int ret;
261
262 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command);
263 if (ret) {
264 goto end;
265 }
266 ret = mi_lttng_writer_write_element_string(writer,
267 mi_lttng_element_command_name, command);
268 end:
269 return ret;
270 }
271
272 LTTNG_HIDDEN
273 int mi_lttng_writer_command_close(struct mi_writer *writer)
274 {
275 return mi_lttng_writer_close_element(writer);
276 }
277
278 LTTNG_HIDDEN
279 int mi_lttng_writer_open_element(struct mi_writer *writer,
280 const char *element_name)
281 {
282 return config_writer_open_element(writer->writer, element_name);
283 }
284
285 LTTNG_HIDDEN
286 int mi_lttng_writer_close_element(struct mi_writer *writer)
287 {
288 return config_writer_close_element(writer->writer);
289 }
290
291 LTTNG_HIDDEN
292 int mi_lttng_close_multi_element(struct mi_writer *writer,
293 unsigned int nb_element)
294 {
295 int ret, i;
296
297 if (nb_element < 1) {
298 ret = 0;
299 goto end;
300 }
301 for (i = 0; i < nb_element; i++) {
302 ret = mi_lttng_writer_close_element(writer);
303 if (ret) {
304 goto end;
305 }
306 }
307 end:
308 return ret;
309 }
310
311 LTTNG_HIDDEN
312 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer,
313 const char *element_name, uint64_t value)
314 {
315 return config_writer_write_element_unsigned_int(writer->writer,
316 element_name, value);
317 }
318
319 LTTNG_HIDDEN
320 int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer,
321 const char *element_name, int64_t value)
322 {
323 return config_writer_write_element_signed_int(writer->writer,
324 element_name, value);
325 }
326
327 LTTNG_HIDDEN
328 int mi_lttng_writer_write_element_bool(struct mi_writer *writer,
329 const char *element_name, int value)
330 {
331 return config_writer_write_element_bool(writer->writer,
332 element_name, value);
333 }
334
335 LTTNG_HIDDEN
336 int mi_lttng_writer_write_element_string(struct mi_writer *writer,
337 const char *element_name, const char *value)
338 {
339 return config_writer_write_element_string(writer->writer,
340 element_name, value);
341 }
342
343 LTTNG_HIDDEN
344 int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version,
345 const char *lttng_description, const char *lttng_license)
346 {
347 int ret;
348
349 /* Open version */
350 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_version);
351 if (ret) {
352 goto end;
353 }
354
355 /* Version string (contain info like rc etc.) */
356 ret = mi_lttng_writer_write_element_string(writer,
357 mi_lttng_element_version_str, VERSION);
358 if (ret) {
359 goto end;
360 }
361
362 /* Major version number */
363 ret = mi_lttng_writer_write_element_unsigned_int(writer,
364 mi_lttng_element_version_major, version->version_major);
365 if (ret) {
366 goto end;
367 }
368
369 /* Minor version number */
370 ret = mi_lttng_writer_write_element_unsigned_int(writer,
371 mi_lttng_element_version_minor, version->version_minor);
372 if (ret) {
373 goto end;
374 }
375
376 /* Commit version number */
377 ret = mi_lttng_writer_write_element_string(writer,
378 mi_lttng_element_version_commit, version->version_commit);
379 if (ret) {
380 goto end;
381 }
382
383 /* Patch number */
384 ret = mi_lttng_writer_write_element_unsigned_int(writer,
385 mi_lttng_element_version_patch_level, version->version_patchlevel);
386 if (ret) {
387 goto end;
388 }
389
390 /* Name of the version */
391 ret = mi_lttng_writer_write_element_string(writer,
392 config_element_name, version->version_name);
393 if (ret) {
394 goto end;
395 }
396
397 /* Description mostly related to beer... */
398 ret = mi_lttng_writer_write_element_string(writer,
399 mi_lttng_element_version_description, lttng_description);
400 if (ret) {
401 goto end;
402 }
403
404 /* url */
405 ret = mi_lttng_writer_write_element_string(writer,
406 mi_lttng_element_version_web, version->package_url);
407 if (ret) {
408 goto end;
409 }
410
411 /* License: free as in free beer...no...*speech* */
412 ret = mi_lttng_writer_write_element_string(writer,
413 mi_lttng_element_version_license, lttng_license);
414 if (ret) {
415 goto end;
416 }
417
418 /* Close version element */
419 ret = mi_lttng_writer_close_element(writer);
420
421 end:
422 return ret;
423 }
424
425 LTTNG_HIDDEN
426 int mi_lttng_sessions_open(struct mi_writer *writer)
427 {
428 return mi_lttng_writer_open_element(writer, config_element_sessions);
429 }
430
431 LTTNG_HIDDEN
432 int mi_lttng_session(struct mi_writer *writer,
433 struct lttng_session *session, int is_open)
434 {
435 int ret;
436
437 assert(session);
438
439 /* Open sessions element */
440 ret = mi_lttng_writer_open_element(writer,
441 config_element_session);
442 if (ret) {
443 goto end;
444 }
445
446 /* Name of the session */
447 ret = mi_lttng_writer_write_element_string(writer,
448 config_element_name, session->name);
449 if (ret) {
450 goto end;
451 }
452
453 /* Path */
454 ret = mi_lttng_writer_write_element_string(writer,
455 config_element_path, session->path);
456 if (ret) {
457 goto end;
458 }
459
460 /* Enabled ? */
461 ret = mi_lttng_writer_write_element_bool(writer,
462 config_element_enabled, session->enabled);
463 if (ret) {
464 goto end;
465 }
466
467 /* Snapshot mode */
468 ret = mi_lttng_writer_write_element_unsigned_int(writer,
469 config_element_snapshot_mode, session->snapshot_mode);
470 if (ret) {
471 goto end;
472 }
473
474 /* Live timer interval in usec */
475 ret = mi_lttng_writer_write_element_unsigned_int(writer,
476 config_element_live_timer_interval,
477 session->live_timer_interval);
478 if (ret) {
479 goto end;
480 }
481
482 if (!is_open) {
483 /* Closing session element */
484 ret = mi_lttng_writer_close_element(writer);
485 }
486 end:
487 return ret;
488
489 }
490
491 LTTNG_HIDDEN
492 int mi_lttng_domains_open(struct mi_writer *writer)
493 {
494 return mi_lttng_writer_open_element(writer, config_element_domains);
495 }
496
497 LTTNG_HIDDEN
498 int mi_lttng_domain(struct mi_writer *writer,
499 struct lttng_domain *domain, int is_open)
500 {
501 int ret = 0;
502 const char *str_domain;
503 const char *str_buffer;
504
505 assert(domain);
506
507 /* Open domain element */
508 ret = mi_lttng_writer_open_element(writer, config_element_domain);
509 if (ret) {
510 goto end;
511 }
512
513 /* Domain Type */
514 str_domain = mi_lttng_domaintype_string(domain->type);
515 ret = mi_lttng_writer_write_element_string(writer, config_element_type,
516 str_domain);
517 if (ret) {
518 goto end;
519 }
520
521 /* Buffer Type */
522 str_buffer= mi_lttng_buffertype_string(domain->buf_type);
523 ret = mi_lttng_writer_write_element_string(writer,
524 config_element_buffer_type, str_buffer);
525 if (ret) {
526 goto end;
527 }
528
529 /* TODO: attr... not sure how to use the union.... */
530
531 if (!is_open) {
532 /* Closing domain element */
533 ret = mi_lttng_writer_close_element(writer);
534 }
535
536 end:
537 return ret;
538
539 }
540
541 LTTNG_HIDDEN
542 int mi_lttng_channels_open(struct mi_writer *writer)
543 {
544 return mi_lttng_writer_open_element(writer, config_element_channels);
545 }
546
547 LTTNG_HIDDEN
548 int mi_lttng_channel(struct mi_writer *writer,
549 struct lttng_channel *channel, int is_open)
550 {
551 int ret = 0;
552
553 assert(channel);
554
555 /* Opening channel element */
556 ret = mi_lttng_writer_open_element(writer, config_element_channel);
557 if (ret) {
558 goto end;
559 }
560
561 /* Name */
562 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
563 channel->name);
564 if (ret) {
565 goto end;
566 }
567
568 /* Enabled ? */
569 ret = mi_lttng_writer_write_element_bool(writer,
570 config_element_enabled, channel->enabled);
571 if (ret) {
572 goto end;
573 }
574
575 /* Attribute */
576 ret = mi_lttng_channel_attr(writer, &channel->attr);
577 if (ret) {
578 goto end;
579 }
580
581 if (!is_open) {
582 /* Closing channel element */
583 ret = mi_lttng_writer_close_element(writer);
584 if (ret) {
585 goto end;
586 }
587 }
588 end:
589 return ret;
590 }
591
592 LTTNG_HIDDEN
593 int mi_lttng_channel_attr(struct mi_writer *writer,
594 struct lttng_channel_attr *attr)
595 {
596 int ret = 0;
597
598 assert(attr);
599
600 /* Opening Attributes */
601 ret = mi_lttng_writer_open_element(writer, config_element_attributes);
602 if (ret) {
603 goto end;
604 }
605
606 /* Overwrite */
607 ret = mi_lttng_writer_write_element_string(writer,
608 config_element_overwrite_mode,
609 attr->overwrite ? config_overwrite_mode_overwrite :
610 config_overwrite_mode_discard);
611 if (ret) {
612 goto end;
613 }
614
615 /* Sub buffer size in byte */
616 ret = mi_lttng_writer_write_element_unsigned_int(writer,
617 config_element_subbuf_size, attr->subbuf_size);
618 if (ret) {
619 goto end;
620 }
621
622 /* Number of subbuffer (power of two) */
623 ret = mi_lttng_writer_write_element_unsigned_int(writer,
624 config_element_num_subbuf,
625 attr->num_subbuf);
626 if (ret) {
627 goto end;
628 }
629
630 /* Switch timer interval in usec */
631 ret = mi_lttng_writer_write_element_unsigned_int(writer,
632 config_element_switch_timer_interval,
633 attr->switch_timer_interval);
634 if (ret) {
635 goto end;
636 }
637
638 /* Read timer interval in usec */
639 ret = mi_lttng_writer_write_element_unsigned_int(writer,
640 config_element_read_timer_interval,
641 attr->read_timer_interval);
642 if (ret) {
643 goto end;
644 }
645
646 /* Event output */
647 ret = mi_lttng_writer_write_element_string(writer,
648 config_element_output_type,
649 attr->output == LTTNG_EVENT_SPLICE ?
650 config_output_type_splice : config_output_type_mmap);
651 if (ret) {
652 goto end;
653 }
654
655 /* Tracefile size in bytes */
656 ret = mi_lttng_writer_write_element_unsigned_int(writer,
657 config_element_tracefile_size, attr->tracefile_size);
658 if (ret) {
659 goto end;
660 }
661
662 /* Count of tracefiles */
663 ret = mi_lttng_writer_write_element_unsigned_int(writer,
664 config_element_tracefile_count,
665 attr->tracefile_count);
666 if (ret) {
667 goto end;
668 }
669
670 /* Live timer interval in usec*/
671 ret = mi_lttng_writer_write_element_unsigned_int(writer,
672 config_element_live_timer_interval,
673 attr->live_timer_interval);
674 if (ret) {
675 goto end;
676 }
677
678 /* Closing attributes */
679 ret = mi_lttng_writer_close_element(writer);
680 if (ret) {
681 goto end;
682 }
683 end:
684 return ret;
685
686 }
687
688 LTTNG_HIDDEN
689 int mi_lttng_event_common_attributes(struct mi_writer *writer,
690 struct lttng_event *event)
691 {
692 int ret;
693
694 /* Open event element */
695 ret = mi_lttng_writer_open_element(writer, config_element_event);
696 if (ret) {
697 goto end;
698 }
699
700 /* event name */
701 ret = mi_lttng_writer_write_element_string(writer,
702 config_element_name, event->name);
703 if (ret) {
704 goto end;
705 }
706
707 /* event type */
708 ret = mi_lttng_writer_write_element_string(writer,
709 config_element_type, mi_lttng_eventtype_string(event->type));
710 if (ret) {
711 goto end;
712 }
713
714 /* is event enabled */
715 ret = mi_lttng_writer_write_element_bool(writer,
716 config_element_enabled, event->enabled);
717 if (ret) {
718 goto end;
719 }
720
721 /* event filter enabled? */
722 ret = mi_lttng_writer_write_element_bool(writer,
723 config_element_filter, event->filter);
724
725 end:
726 return ret;
727 }
728
729 LTTNG_HIDDEN
730 int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer,
731 struct lttng_event *event)
732 {
733 int ret;
734
735 /* event loglevel */
736 ret = mi_lttng_writer_write_element_string(writer,
737 config_element_loglevel, mi_lttng_loglevel_string(event->loglevel));
738 if (ret) {
739 goto end;
740 }
741
742 ret = mi_lttng_writer_write_element_string(writer,
743 config_element_loglevel_type,
744 mi_lttng_logleveltype_string(event->loglevel_type));
745 if (ret) {
746 goto end;
747 }
748
749 /* event exclusion filter */
750 ret = mi_lttng_writer_write_element_bool(writer,
751 config_element_exclusion, event->exclusion);
752 if (ret) {
753 goto end;
754 }
755
756 end:
757 return ret;
758 }
759
760 LTTNG_HIDDEN
761 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer *writer,
762 struct lttng_event *event)
763 {
764 /* event exclusion filter */
765 return mi_lttng_writer_write_element_bool(writer,
766 config_element_exclusion, event->exclusion);
767 }
768
769 LTTNG_HIDDEN
770 int mi_lttng_event_function_probe(struct mi_writer *writer,
771 struct lttng_event *event)
772 {
773 int ret;
774
775 if (event->attr.probe.addr != 0) {
776 /* event probe address */
777 ret = mi_lttng_writer_write_element_unsigned_int(writer,
778 config_element_address, event->attr.probe.addr);
779 if (ret) {
780 goto end;
781 }
782 } else {
783 /* event probe offset */
784 ret = mi_lttng_writer_write_element_unsigned_int(writer,
785 config_element_offset, event->attr.probe.offset);
786 if (ret) {
787 goto end;
788 }
789
790 /* event probe symbol_name */
791 ret = mi_lttng_writer_write_element_string(writer,
792 config_element_symbol_name, event->attr.probe.symbol_name);
793 if (ret) {
794 goto end;
795 }
796 }
797 end:
798 return ret;
799 }
800
801 LTTNG_HIDDEN
802 int mi_lttng_event_function_entry(struct mi_writer *writer,
803 struct lttng_event *event)
804 {
805 /* event probe symbol_name */
806 return mi_lttng_writer_write_element_string(writer,
807 config_element_symbol_name, event->attr.ftrace.symbol_name);
808 }
809
810 LTTNG_HIDDEN
811 int mi_lttng_events_open(struct mi_writer *writer)
812 {
813 return mi_lttng_writer_open_element(writer, config_element_events);
814 }
815
816 LTTNG_HIDDEN
817 int mi_lttng_event(struct mi_writer *writer,
818 struct lttng_event *event, int is_open)
819 {
820 int ret;
821
822 ret = mi_lttng_event_common_attributes(writer, event);
823 if (ret) {
824 goto end;
825 }
826
827 switch (event->type) {
828 case LTTNG_EVENT_ALL:
829 /* We should never have "all" events in list. */
830 assert(0);
831 break;
832 case LTTNG_EVENT_TRACEPOINT:
833 {
834 if (event->loglevel != -1) {
835 ret = mi_lttng_event_tracepoint_loglevel(writer, event);
836 } else {
837 ret = mi_lttng_event_tracepoint_no_loglevel(writer, event);
838 }
839 break;
840 }
841 case LTTNG_EVENT_PROBE:
842 ret = mi_lttng_event_function_probe(writer, event);
843 break;
844 case LTTNG_EVENT_FUNCTION_ENTRY:
845 ret = mi_lttng_event_function_entry(writer, event);
846 break;
847 default:
848 break;
849 }
850
851 if (!is_open) {
852 ret = mi_lttng_writer_close_element(writer);
853 }
854
855 end:
856 return ret;
857 }
858
859 LTTNG_HIDDEN
860 int mi_lttng_pids_open(struct mi_writer *writer)
861 {
862 return mi_lttng_writer_open_element(writer, mi_lttng_element_pids);
863 }
864
865 LTTNG_HIDDEN
866 int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *cmdline,
867 int is_open)
868 {
869 int ret;
870
871 /* Open element pid */
872 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_pid);
873 if (ret) {
874 goto end;
875 }
876
877 /* Writing pid number */
878 ret = mi_lttng_writer_write_element_signed_int(writer,
879 mi_lttng_element_pid_id, (int)pid);
880 if (ret) {
881 goto end;
882 }
883
884 /* Writing name of the process */
885 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
886 cmdline);
887 if (ret) {
888 goto end;
889 }
890
891 if (!is_open) {
892 /* Closing Pid */
893 ret = mi_lttng_writer_close_element(writer);
894 }
895
896 end:
897 return ret;
898 }
899
900 LTTNG_HIDDEN
901 int mi_lttng_event_fields_open(struct mi_writer *writer)
902 {
903 return mi_lttng_writer_open_element(writer, mi_lttng_element_event_fields);
904 }
905
906 LTTNG_HIDDEN
907 int mi_lttng_event_field(struct mi_writer *writer,
908 struct lttng_event_field *field)
909 {
910 int ret;
911
912 if (!field->field_name[0]) {
913 /* To Review: not sure if legal david ?
914 * how should this be handle ?
915 */
916 ret = 0;
917 goto end;
918 }
919
920 /* Open field */
921 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_event_field);
922 if (ret) {
923 goto end;
924 }
925
926 if (!field->field_name[0]) {
927 goto close;
928 }
929
930 /* Name */
931 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
932 field->field_name);
933 if (ret) {
934 goto end;
935 }
936
937 /* Type */
938 ret = mi_lttng_writer_write_element_string(writer, config_element_type,
939 mi_lttng_eventfieldtype_string(field->type));
940 if (ret) {
941 goto end;
942 }
943
944 /* nowrite */
945 ret = mi_lttng_writer_write_element_signed_int(writer,
946 mi_lttng_element_nowrite, field->nowrite);
947 if (ret) {
948 goto end;
949 }
950
951 close:
952 /* Close field element */
953 ret = mi_lttng_writer_close_element(writer);
954
955 end:
956 return ret;
957 }
This page took 0.078205 seconds and 3 git commands to generate.