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