2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
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.
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
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.
20 #include <include/config.h>
21 #include <common/config/config.h>
26 /* Strings related to command */
27 const char * const mi_lttng_element_command
= "command";
28 const char * const mi_lttng_element_command_name
= "name";
29 const char * const mi_lttng_element_command_version
= "version";
30 const char * const mi_lttng_element_command_list
= "list";
31 const char * const mi_lttng_element_command_save
= "save";
32 const char * const mi_lttng_element_command_load
= "load";
33 const char * const mi_lttng_element_command_start
= "start";
34 const char * const mi_lttng_element_command_stop
= "stop";
35 const char * const mi_lttng_element_command_create
= "create";
36 const char * const mi_lttng_element_command_destroy
= "destroy";
37 const char * const mi_lttng_element_command_calibrate
= "calibrate";
38 const char * const mi_lttng_element_command_add_context
= "add-context";
39 const char * const mi_lttng_element_command_output
= "output";
40 const char * const mi_lttng_element_command_success
= "success";
42 /* Strings related to version command */
43 const char * const mi_lttng_element_version
= "version";
44 const char * const mi_lttng_element_version_str
= "string";
45 const char * const mi_lttng_element_version_web
= "url";
46 const char * const mi_lttng_element_version_major
= "major";
47 const char * const mi_lttng_element_version_minor
= "minor";
48 const char * const mi_lttng_element_version_commit
= "commit";
49 const char * const mi_lttng_element_version_license
= "license";
50 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
51 const char * const mi_lttng_element_version_description
= "description";
53 /* Strings related to pid */
54 const char * const mi_lttng_element_pids
= "pids";
55 const char * const mi_lttng_element_pid
= "pid";
56 const char * const mi_lttng_element_pid_id
= "id";
58 /* Strings related to save command */
59 const char * const mi_lttng_element_save
= "save";
61 /* Strings related to load command */
62 const char * const mi_lttng_element_load
= "load";
64 /* String related to a lttng_event_field */
65 const char * const mi_lttng_element_event_field
= "event_field";
66 const char * const mi_lttng_element_event_fields
= "event_fields";
68 /* String related to lttng_event_context */
69 const char * const mi_lttng_context_type_perf_counter
= "PERF_COUNTER";
70 const char * const mi_lttng_context_type_perf_cpu_counter
= "PERF_CPU_COUNTER";
71 const char * const mi_lttng_context_type_perf_thread_counter
= "PERF_THREAD_COUNTER";
73 /* String related to lttng_event_perf_counter_ctx */
74 const char * const mi_lttng_element_perf_counter_context
= "perf_counter_context";
76 /* General elements of mi_lttng */
77 const char * const mi_lttng_element_type_other
= "OTHER";
78 const char * const mi_lttng_element_type_integer
= "INTEGER";
79 const char * const mi_lttng_element_type_enum
= "ENUM";
80 const char * const mi_lttng_element_type_float
= "FLOAT";
81 const char * const mi_lttng_element_type_string
= "STRING";
82 const char * const mi_lttng_element_nowrite
= "nowrite";
83 const char * const mi_lttng_element_success
= "success";
85 /* String related to loglevel */
86 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
87 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
88 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
89 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
90 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
91 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
92 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
93 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
94 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
95 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
96 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
97 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
98 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
99 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
100 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
101 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
103 /* String related to loglevel type */
104 const char * const mi_lttng_loglevel_type_all
= "ALL";
105 const char * const mi_lttng_loglevel_type_range
= "RANGE";
106 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
107 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
109 /* String related to lttng_calibrate */
110 const char * const mi_lttng_element_calibrate
= "calibrate";
111 const char * const mi_lttng_element_calibrate_function
= "FUNCTION";
113 const char * const mi_lttng_element_empty
= "";
115 const char *mi_lttng_loglevel_string(int value
)
119 return mi_lttng_element_empty
;
120 case LTTNG_LOGLEVEL_EMERG
:
121 return mi_lttng_loglevel_str_emerg
;
122 case LTTNG_LOGLEVEL_ALERT
:
123 return mi_lttng_loglevel_str_alert
;
124 case LTTNG_LOGLEVEL_CRIT
:
125 return mi_lttng_loglevel_str_crit
;
126 case LTTNG_LOGLEVEL_ERR
:
127 return mi_lttng_loglevel_str_err
;
128 case LTTNG_LOGLEVEL_WARNING
:
129 return mi_lttng_loglevel_str_warning
;
130 case LTTNG_LOGLEVEL_NOTICE
:
131 return mi_lttng_loglevel_str_notice
;
132 case LTTNG_LOGLEVEL_INFO
:
133 return mi_lttng_loglevel_str_info
;
134 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
135 return mi_lttng_loglevel_str_debug_system
;
136 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
137 return mi_lttng_loglevel_str_debug_program
;
138 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
139 return mi_lttng_loglevel_str_debug_process
;
140 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
141 return mi_lttng_loglevel_str_debug_module
;
142 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
143 return mi_lttng_loglevel_str_debug_unit
;
144 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
145 return mi_lttng_loglevel_str_debug_function
;
146 case LTTNG_LOGLEVEL_DEBUG_LINE
:
147 return mi_lttng_loglevel_str_debug_line
;
148 case LTTNG_LOGLEVEL_DEBUG
:
149 return mi_lttng_loglevel_str_debug
;
151 return mi_lttng_loglevel_str_unknown
;
155 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
158 case LTTNG_EVENT_LOGLEVEL_ALL
:
159 return mi_lttng_loglevel_type_all
;
160 case LTTNG_EVENT_LOGLEVEL_RANGE
:
161 return mi_lttng_loglevel_type_range
;
162 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
163 return mi_lttng_loglevel_type_single
;
165 return mi_lttng_loglevel_type_unknown
;
169 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
172 case LTTNG_EVENT_ALL
:
173 return config_event_type_all
;
174 case LTTNG_EVENT_TRACEPOINT
:
175 return config_event_type_tracepoint
;
176 case LTTNG_EVENT_PROBE
:
177 return config_event_type_probe
;
178 case LTTNG_EVENT_FUNCTION
:
179 return config_event_type_function
;
180 case LTTNG_EVENT_FUNCTION_ENTRY
:
181 return config_event_type_function_entry
;
182 case LTTNG_EVENT_SYSCALL
:
183 return config_event_type_syscall
;
184 case LTTNG_EVENT_NOOP
:
185 return config_event_type_noop
;
187 return mi_lttng_element_empty
;
191 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
194 case LTTNG_EVENT_CONTEXT_PID
:
195 return config_event_context_pid
;
196 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
197 return mi_lttng_context_type_perf_counter
;
198 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
199 return mi_lttng_context_type_perf_thread_counter
;
200 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
201 return mi_lttng_context_type_perf_cpu_counter
;
202 case LTTNG_EVENT_CONTEXT_PROCNAME
:
203 return config_event_context_procname
;
204 case LTTNG_EVENT_CONTEXT_PRIO
:
205 return config_event_context_prio
;
206 case LTTNG_EVENT_CONTEXT_NICE
:
207 return config_event_context_nice
;
208 case LTTNG_EVENT_CONTEXT_VPID
:
209 return config_event_context_vpid
;
210 case LTTNG_EVENT_CONTEXT_TID
:
211 return config_event_context_tid
;
212 case LTTNG_EVENT_CONTEXT_VTID
:
213 return config_event_context_vtid
;
214 case LTTNG_EVENT_CONTEXT_PPID
:
215 return config_event_context_ppid
;
216 case LTTNG_EVENT_CONTEXT_VPPID
:
217 return config_event_context_vppid
;
218 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
219 return config_event_context_pthread_id
;
220 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
221 return config_event_context_hostname
;
222 case LTTNG_EVENT_CONTEXT_IP
:
223 return config_event_context_ip
;
229 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
232 case(LTTNG_EVENT_FIELD_INTEGER
):
233 return mi_lttng_element_type_integer
;
234 case(LTTNG_EVENT_FIELD_ENUM
):
235 return mi_lttng_element_type_enum
;
236 case(LTTNG_EVENT_FIELD_FLOAT
):
237 return mi_lttng_element_type_float
;
238 case(LTTNG_EVENT_FIELD_STRING
):
239 return mi_lttng_element_type_string
;
241 return mi_lttng_element_type_other
;
245 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
247 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
249 case LTTNG_DOMAIN_KERNEL
:
250 return config_domain_type_kernel
;
251 case LTTNG_DOMAIN_UST
:
252 return config_domain_type_ust
;
253 case LTTNG_DOMAIN_JUL
:
254 return config_domain_type_jul
;
256 /* Should not have an unknown domain */
261 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
264 case LTTNG_BUFFER_PER_PID
:
265 return config_buffer_type_per_pid
;
266 case LTTNG_BUFFER_PER_UID
:
267 return config_buffer_type_per_uid
;
268 case LTTNG_BUFFER_GLOBAL
:
269 return config_buffer_type_global
;
271 /* Should not have an unknow buffer type */
276 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
)
281 case LTTNG_CALIBRATE_FUNCTION
:
282 ret
= mi_lttng_element_calibrate_function
;
285 ret
= mi_lttng_element_empty
;
292 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
294 struct mi_writer
*mi_writer
;
296 mi_writer
= zmalloc(sizeof(struct mi_writer
));
298 PERROR("zmalloc mi_writer_create");
301 if (mi_output_type
== LTTNG_MI_XML
) {
302 mi_writer
->writer
= config_writer_create(fd_output
);
303 if (!mi_writer
->writer
) {
306 mi_writer
->type
= LTTNG_MI_XML
;
320 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
329 ret
= config_writer_destroy(writer
->writer
);
340 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
344 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_command
);
348 ret
= mi_lttng_writer_write_element_string(writer
,
349 mi_lttng_element_command_name
, command
);
355 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
357 return mi_lttng_writer_close_element(writer
);
361 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
362 const char *element_name
)
364 return config_writer_open_element(writer
->writer
, element_name
);
368 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
370 return config_writer_close_element(writer
->writer
);
374 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
375 unsigned int nb_element
)
379 if (nb_element
< 1) {
383 for (i
= 0; i
< nb_element
; i
++) {
384 ret
= mi_lttng_writer_close_element(writer
);
394 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
395 const char *element_name
, uint64_t value
)
397 return config_writer_write_element_unsigned_int(writer
->writer
,
398 element_name
, value
);
402 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
403 const char *element_name
, int64_t value
)
405 return config_writer_write_element_signed_int(writer
->writer
,
406 element_name
, value
);
410 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
411 const char *element_name
, int value
)
413 return config_writer_write_element_bool(writer
->writer
,
414 element_name
, value
);
418 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
419 const char *element_name
, const char *value
)
421 return config_writer_write_element_string(writer
->writer
,
422 element_name
, value
);
426 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
427 const char *lttng_description
, const char *lttng_license
)
432 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
437 /* Version string (contain info like rc etc.) */
438 ret
= mi_lttng_writer_write_element_string(writer
,
439 mi_lttng_element_version_str
, VERSION
);
444 /* Major version number */
445 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
446 mi_lttng_element_version_major
, version
->version_major
);
451 /* Minor version number */
452 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
453 mi_lttng_element_version_minor
, version
->version_minor
);
458 /* Commit version number */
459 ret
= mi_lttng_writer_write_element_string(writer
,
460 mi_lttng_element_version_commit
, version
->version_commit
);
466 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
467 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
472 /* Name of the version */
473 ret
= mi_lttng_writer_write_element_string(writer
,
474 config_element_name
, version
->version_name
);
479 /* Description mostly related to beer... */
480 ret
= mi_lttng_writer_write_element_string(writer
,
481 mi_lttng_element_version_description
, lttng_description
);
487 ret
= mi_lttng_writer_write_element_string(writer
,
488 mi_lttng_element_version_web
, version
->package_url
);
493 /* License: free as in free beer...no...*speech* */
494 ret
= mi_lttng_writer_write_element_string(writer
,
495 mi_lttng_element_version_license
, lttng_license
);
500 /* Close version element */
501 ret
= mi_lttng_writer_close_element(writer
);
508 int mi_lttng_sessions_open(struct mi_writer
*writer
)
510 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
514 int mi_lttng_session(struct mi_writer
*writer
,
515 struct lttng_session
*session
, int is_open
)
521 /* Open sessions element */
522 ret
= mi_lttng_writer_open_element(writer
,
523 config_element_session
);
528 /* Name of the session */
529 ret
= mi_lttng_writer_write_element_string(writer
,
530 config_element_name
, session
->name
);
536 ret
= mi_lttng_writer_write_element_string(writer
,
537 config_element_path
, session
->path
);
543 ret
= mi_lttng_writer_write_element_bool(writer
,
544 config_element_enabled
, session
->enabled
);
550 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
551 config_element_snapshot_mode
, session
->snapshot_mode
);
556 /* Live timer interval in usec */
557 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
558 config_element_live_timer_interval
,
559 session
->live_timer_interval
);
565 /* Closing session element */
566 ret
= mi_lttng_writer_close_element(writer
);
574 int mi_lttng_domains_open(struct mi_writer
*writer
)
576 return mi_lttng_writer_open_element(writer
, config_element_domains
);
580 int mi_lttng_domain(struct mi_writer
*writer
,
581 struct lttng_domain
*domain
, int is_open
)
584 const char *str_domain
;
585 const char *str_buffer
;
589 /* Open domain element */
590 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
596 str_domain
= mi_lttng_domaintype_string(domain
->type
);
597 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
604 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
605 ret
= mi_lttng_writer_write_element_string(writer
,
606 config_element_buffer_type
, str_buffer
);
611 /* TODO: attr... not sure how to use the union.... */
614 /* Closing domain element */
615 ret
= mi_lttng_writer_close_element(writer
);
624 int mi_lttng_channels_open(struct mi_writer
*writer
)
626 return mi_lttng_writer_open_element(writer
, config_element_channels
);
630 int mi_lttng_channel(struct mi_writer
*writer
,
631 struct lttng_channel
*channel
, int is_open
)
637 /* Opening channel element */
638 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
644 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
651 ret
= mi_lttng_writer_write_element_bool(writer
,
652 config_element_enabled
, channel
->enabled
);
658 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
664 /* Closing channel element */
665 ret
= mi_lttng_writer_close_element(writer
);
675 int mi_lttng_channel_attr(struct mi_writer
*writer
,
676 struct lttng_channel_attr
*attr
)
682 /* Opening Attributes */
683 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
689 ret
= mi_lttng_writer_write_element_string(writer
,
690 config_element_overwrite_mode
,
691 attr
->overwrite
? config_overwrite_mode_overwrite
:
692 config_overwrite_mode_discard
);
697 /* Sub buffer size in byte */
698 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
699 config_element_subbuf_size
, attr
->subbuf_size
);
704 /* Number of subbuffer (power of two) */
705 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
706 config_element_num_subbuf
,
712 /* Switch timer interval in usec */
713 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
714 config_element_switch_timer_interval
,
715 attr
->switch_timer_interval
);
720 /* Read timer interval in usec */
721 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
722 config_element_read_timer_interval
,
723 attr
->read_timer_interval
);
729 ret
= mi_lttng_writer_write_element_string(writer
,
730 config_element_output_type
,
731 attr
->output
== LTTNG_EVENT_SPLICE
?
732 config_output_type_splice
: config_output_type_mmap
);
737 /* Tracefile size in bytes */
738 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
739 config_element_tracefile_size
, attr
->tracefile_size
);
744 /* Count of tracefiles */
745 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
746 config_element_tracefile_count
,
747 attr
->tracefile_count
);
752 /* Live timer interval in usec*/
753 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
754 config_element_live_timer_interval
,
755 attr
->live_timer_interval
);
760 /* Closing attributes */
761 ret
= mi_lttng_writer_close_element(writer
);
771 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
772 struct lttng_event
*event
)
776 /* Open event element */
777 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
783 ret
= mi_lttng_writer_write_element_string(writer
,
784 config_element_name
, event
->name
);
790 ret
= mi_lttng_writer_write_element_string(writer
,
791 config_element_type
, mi_lttng_eventtype_string(event
->type
));
796 /* is event enabled */
797 ret
= mi_lttng_writer_write_element_bool(writer
,
798 config_element_enabled
, event
->enabled
);
803 /* event filter enabled? */
804 ret
= mi_lttng_writer_write_element_bool(writer
,
805 config_element_filter
, event
->filter
);
812 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
813 struct lttng_event
*event
)
818 ret
= mi_lttng_writer_write_element_string(writer
,
819 config_element_loglevel
, mi_lttng_loglevel_string(event
->loglevel
));
824 ret
= mi_lttng_writer_write_element_string(writer
,
825 config_element_loglevel_type
,
826 mi_lttng_logleveltype_string(event
->loglevel_type
));
831 /* event exclusion filter */
832 ret
= mi_lttng_writer_write_element_bool(writer
,
833 config_element_exclusion
, event
->exclusion
);
843 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
844 struct lttng_event
*event
)
846 /* event exclusion filter */
847 return mi_lttng_writer_write_element_bool(writer
,
848 config_element_exclusion
, event
->exclusion
);
852 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
853 struct lttng_event
*event
)
857 if (event
->attr
.probe
.addr
!= 0) {
858 /* event probe address */
859 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
860 config_element_address
, event
->attr
.probe
.addr
);
865 /* event probe offset */
866 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
867 config_element_offset
, event
->attr
.probe
.offset
);
872 /* event probe symbol_name */
873 ret
= mi_lttng_writer_write_element_string(writer
,
874 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
884 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
885 struct lttng_event
*event
)
887 /* event probe symbol_name */
888 return mi_lttng_writer_write_element_string(writer
,
889 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
893 int mi_lttng_events_open(struct mi_writer
*writer
)
895 return mi_lttng_writer_open_element(writer
, config_element_events
);
899 int mi_lttng_event(struct mi_writer
*writer
,
900 struct lttng_event
*event
, int is_open
)
904 ret
= mi_lttng_event_common_attributes(writer
, event
);
909 switch (event
->type
) {
910 case LTTNG_EVENT_ALL
:
911 /* We should never have "all" events in list. */
914 case LTTNG_EVENT_TRACEPOINT
:
916 if (event
->loglevel
!= -1) {
917 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
);
919 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
923 case LTTNG_EVENT_PROBE
:
924 ret
= mi_lttng_event_function_probe(writer
, event
);
926 case LTTNG_EVENT_FUNCTION_ENTRY
:
927 ret
= mi_lttng_event_function_entry(writer
, event
);
934 ret
= mi_lttng_writer_close_element(writer
);
942 int mi_lttng_pids_open(struct mi_writer
*writer
)
944 return mi_lttng_writer_open_element(writer
, mi_lttng_element_pids
);
948 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
953 /* Open element pid */
954 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_pid
);
959 /* Writing pid number */
960 ret
= mi_lttng_writer_write_element_signed_int(writer
,
961 mi_lttng_element_pid_id
, (int)pid
);
966 /* Writing name of the process */
967 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
975 ret
= mi_lttng_writer_close_element(writer
);
983 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
985 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
989 int mi_lttng_event_field(struct mi_writer
*writer
,
990 struct lttng_event_field
*field
)
994 if (!field
->field_name
[0]) {
995 /* To Review: not sure if legal david ?
996 * how should this be handle ?
1003 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1008 if (!field
->field_name
[0]) {
1013 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1020 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1021 mi_lttng_eventfieldtype_string(field
->type
));
1027 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1028 mi_lttng_element_nowrite
, field
->nowrite
);
1034 /* Close field element */
1035 ret
= mi_lttng_writer_close_element(writer
);
1042 int mi_lttng_calibrate(struct mi_writer
*writer
,
1043 struct lttng_calibrate
*calibrate
)
1047 /* Open calibrate element */
1048 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1053 /* Calibration type */
1054 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1055 mi_lttng_calibratetype_string(calibrate
->type
));
1060 /* Closing calibrate element */
1061 ret
= mi_lttng_writer_close_element(writer
);
1066 int mi_lttng_context(struct mi_writer
*writer
,
1067 struct lttng_event_context
*context
, int is_open
)
1070 const char *type_string
;
1071 struct lttng_event_perf_counter_ctx
*perf_context
;
1073 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1078 type_string
= mi_lttng_event_contexttype_string(context
->ctx
);
1080 ret
= -LTTNG_ERR_INVALID
;
1084 /* Print context type */
1085 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1088 /* Special case for PERF_*_COUNTER
1089 * print the lttng_event_perf_counter_ctx*/
1090 switch (context
->ctx
) {
1091 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1092 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1093 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1094 perf_context
= &context
->u
.perf_counter
;
1095 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1106 ret
= mi_lttng_writer_close_element(writer
);
1114 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1115 struct lttng_event_perf_counter_ctx
*perf_context
)
1119 /* Open perf_counter_context */
1120 ret
= mi_lttng_writer_open_element(writer
,
1121 mi_lttng_element_perf_counter_context
);
1127 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1128 config_element_type
, perf_context
->type
);
1134 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1135 config_element_config
, perf_context
->config
);
1140 /* Name of the perf counter */
1141 ret
= mi_lttng_writer_write_element_string(writer
,
1142 config_element_name
, perf_context
->name
);
1147 /* Close perf_counter_context */
1148 ret
= mi_lttng_writer_close_element(writer
);