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>
22 #include <lttng/snapshot-internal.h>
27 /* Strings related to command */
28 const char * const mi_lttng_element_command
= "command";
29 const char * const mi_lttng_element_command_action
= "snapshot_action";
30 const char * const mi_lttng_element_command_add_context
= "add-context";
31 const char * const mi_lttng_element_command_calibrate
= "calibrate";
32 const char * const mi_lttng_element_command_create
= "create";
33 const char * const mi_lttng_element_command_destroy
= "destroy";
34 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
35 const char * const mi_lttng_element_command_disable_event
= "disable-event";
36 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
37 const char * const mi_lttng_element_command_enable_event
= "enable-event";
38 const char * const mi_lttng_element_command_list
= "list";
39 const char * const mi_lttng_element_command_load
= "load";
40 const char * const mi_lttng_element_command_name
= "name";
41 const char * const mi_lttng_element_command_output
= "output";
42 const char * const mi_lttng_element_command_save
= "save";
43 const char * const mi_lttng_element_command_set_session
= "set-session";
44 const char * const mi_lttng_element_command_snapshot
= "snapshot";
45 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
46 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
47 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
48 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
49 const char * const mi_lttng_element_command_start
= "start";
50 const char * const mi_lttng_element_command_stop
= "stop";
51 const char * const mi_lttng_element_command_success
= "success";
52 const char * const mi_lttng_element_command_version
= "version";
54 /* Strings related to version command */
55 const char * const mi_lttng_element_version
= "version";
56 const char * const mi_lttng_element_version_commit
= "commit";
57 const char * const mi_lttng_element_version_description
= "description";
58 const char * const mi_lttng_element_version_license
= "license";
59 const char * const mi_lttng_element_version_major
= "major";
60 const char * const mi_lttng_element_version_minor
= "minor";
61 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
62 const char * const mi_lttng_element_version_str
= "string";
63 const char * const mi_lttng_element_version_web
= "url";
65 /* String related to a lttng_event_field */
66 const char * const mi_lttng_element_event_field
= "event_field";
67 const char * const mi_lttng_element_event_fields
= "event_fields";
69 /* String related to lttng_event_context */
70 const char * const mi_lttng_context_type_perf_counter
= "PERF_COUNTER";
71 const char * const mi_lttng_context_type_perf_cpu_counter
= "PERF_CPU_COUNTER";
72 const char * const mi_lttng_context_type_perf_thread_counter
= "PERF_THREAD_COUNTER";
74 /* String related to lttng_event_perf_counter_ctx */
75 const char * const mi_lttng_element_perf_counter_context
= "perf_counter_context";
77 /* Strings related to pid */
78 const char * const mi_lttng_element_pids
= "pids";
79 const char * const mi_lttng_element_pid
= "pid";
80 const char * const mi_lttng_element_pid_id
= "id";
82 /* Strings related to save command */
83 const char * const mi_lttng_element_save
= "save";
85 /* Strings related to load command */
86 const char * const mi_lttng_element_load
= "load";
88 /* General elements of mi_lttng */
89 const char * const mi_lttng_element_empty
= "";
90 const char * const mi_lttng_element_id
= "id";
91 const char * const mi_lttng_element_nowrite
= "nowrite";
92 const char * const mi_lttng_element_success
= "success";
93 const char * const mi_lttng_element_type_enum
= "ENUM";
94 const char * const mi_lttng_element_type_float
= "FLOAT";
95 const char * const mi_lttng_element_type_integer
= "INTEGER";
96 const char * const mi_lttng_element_type_other
= "OTHER";
97 const char * const mi_lttng_element_type_string
= "STRING";
99 /* String related to loglevel */
100 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
101 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
102 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
103 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
104 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
105 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
106 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
107 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
108 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
109 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
110 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
111 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
112 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
113 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
114 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
115 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
117 /* String related to loglevel JUL */
118 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
119 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
120 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
121 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
122 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
123 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
124 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
125 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
126 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
128 /* String related to loglevel type */
129 const char * const mi_lttng_loglevel_type_all
= "ALL";
130 const char * const mi_lttng_loglevel_type_range
= "RANGE";
131 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
132 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
134 /* String related to lttng_calibrate */
135 const char * const mi_lttng_element_calibrate
= "calibrate";
136 const char * const mi_lttng_element_calibrate_function
= "FUNCTION";
138 /* String related to a lttng_snapshot_output */
139 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
140 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
141 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
142 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
143 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
144 const char * const mi_lttng_element_snapshots
= "snapshots";
146 /* This is a merge of jul loglevel and regular loglevel
147 * Those should never overlap by definition
148 * (see struct lttng_event loglevel)
151 const char *mi_lttng_loglevel_string(int value
)
155 return mi_lttng_element_empty
;
156 case LTTNG_LOGLEVEL_EMERG
:
157 return mi_lttng_loglevel_str_emerg
;
158 case LTTNG_LOGLEVEL_ALERT
:
159 return mi_lttng_loglevel_str_alert
;
160 case LTTNG_LOGLEVEL_CRIT
:
161 return mi_lttng_loglevel_str_crit
;
162 case LTTNG_LOGLEVEL_ERR
:
163 return mi_lttng_loglevel_str_err
;
164 case LTTNG_LOGLEVEL_WARNING
:
165 return mi_lttng_loglevel_str_warning
;
166 case LTTNG_LOGLEVEL_NOTICE
:
167 return mi_lttng_loglevel_str_notice
;
168 case LTTNG_LOGLEVEL_INFO
:
169 return mi_lttng_loglevel_str_info
;
170 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
171 return mi_lttng_loglevel_str_debug_system
;
172 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
173 return mi_lttng_loglevel_str_debug_program
;
174 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
175 return mi_lttng_loglevel_str_debug_process
;
176 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
177 return mi_lttng_loglevel_str_debug_module
;
178 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
179 return mi_lttng_loglevel_str_debug_unit
;
180 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
181 return mi_lttng_loglevel_str_debug_function
;
182 case LTTNG_LOGLEVEL_DEBUG_LINE
:
183 return mi_lttng_loglevel_str_debug_line
;
184 case LTTNG_LOGLEVEL_DEBUG
:
185 return mi_lttng_loglevel_str_debug
;
186 case LTTNG_LOGLEVEL_JUL_OFF
:
187 return mi_lttng_loglevel_str_jul_off
;
188 case LTTNG_LOGLEVEL_JUL_SEVERE
:
189 return mi_lttng_loglevel_str_jul_severe
;
190 case LTTNG_LOGLEVEL_JUL_WARNING
:
191 return mi_lttng_loglevel_str_jul_warning
;
192 case LTTNG_LOGLEVEL_JUL_INFO
:
193 return mi_lttng_loglevel_str_jul_info
;
194 case LTTNG_LOGLEVEL_JUL_CONFIG
:
195 return mi_lttng_loglevel_str_jul_config
;
196 case LTTNG_LOGLEVEL_JUL_FINE
:
197 return mi_lttng_loglevel_str_jul_fine
;
198 case LTTNG_LOGLEVEL_JUL_FINER
:
199 return mi_lttng_loglevel_str_jul_finer
;
200 case LTTNG_LOGLEVEL_JUL_FINEST
:
201 return mi_lttng_loglevel_str_jul_finest
;
202 case LTTNG_LOGLEVEL_JUL_ALL
:
203 return mi_lttng_loglevel_str_jul_all
;
205 return mi_lttng_loglevel_str_unknown
;
210 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
213 case LTTNG_EVENT_LOGLEVEL_ALL
:
214 return mi_lttng_loglevel_type_all
;
215 case LTTNG_EVENT_LOGLEVEL_RANGE
:
216 return mi_lttng_loglevel_type_range
;
217 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
218 return mi_lttng_loglevel_type_single
;
220 return mi_lttng_loglevel_type_unknown
;
225 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
228 case LTTNG_EVENT_ALL
:
229 return config_event_type_all
;
230 case LTTNG_EVENT_TRACEPOINT
:
231 return config_event_type_tracepoint
;
232 case LTTNG_EVENT_PROBE
:
233 return config_event_type_probe
;
234 case LTTNG_EVENT_FUNCTION
:
235 return config_event_type_function
;
236 case LTTNG_EVENT_FUNCTION_ENTRY
:
237 return config_event_type_function_entry
;
238 case LTTNG_EVENT_SYSCALL
:
239 return config_event_type_syscall
;
240 case LTTNG_EVENT_NOOP
:
241 return config_event_type_noop
;
243 return mi_lttng_element_empty
;
248 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
251 case LTTNG_EVENT_CONTEXT_PID
:
252 return config_event_context_pid
;
253 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
254 return mi_lttng_context_type_perf_counter
;
255 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
256 return mi_lttng_context_type_perf_thread_counter
;
257 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
258 return mi_lttng_context_type_perf_cpu_counter
;
259 case LTTNG_EVENT_CONTEXT_PROCNAME
:
260 return config_event_context_procname
;
261 case LTTNG_EVENT_CONTEXT_PRIO
:
262 return config_event_context_prio
;
263 case LTTNG_EVENT_CONTEXT_NICE
:
264 return config_event_context_nice
;
265 case LTTNG_EVENT_CONTEXT_VPID
:
266 return config_event_context_vpid
;
267 case LTTNG_EVENT_CONTEXT_TID
:
268 return config_event_context_tid
;
269 case LTTNG_EVENT_CONTEXT_VTID
:
270 return config_event_context_vtid
;
271 case LTTNG_EVENT_CONTEXT_PPID
:
272 return config_event_context_ppid
;
273 case LTTNG_EVENT_CONTEXT_VPPID
:
274 return config_event_context_vppid
;
275 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
276 return config_event_context_pthread_id
;
277 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
278 return config_event_context_hostname
;
279 case LTTNG_EVENT_CONTEXT_IP
:
280 return config_event_context_ip
;
287 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
290 case(LTTNG_EVENT_FIELD_INTEGER
):
291 return mi_lttng_element_type_integer
;
292 case(LTTNG_EVENT_FIELD_ENUM
):
293 return mi_lttng_element_type_enum
;
294 case(LTTNG_EVENT_FIELD_FLOAT
):
295 return mi_lttng_element_type_float
;
296 case(LTTNG_EVENT_FIELD_STRING
):
297 return mi_lttng_element_type_string
;
299 return mi_lttng_element_type_other
;
304 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
306 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
308 case LTTNG_DOMAIN_KERNEL
:
309 return config_domain_type_kernel
;
310 case LTTNG_DOMAIN_UST
:
311 return config_domain_type_ust
;
312 case LTTNG_DOMAIN_JUL
:
313 return config_domain_type_jul
;
314 case LTTNG_DOMAIN_LOG4J
:
315 return config_domain_type_log4j
;
317 /* Should not have an unknown domain */
323 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
326 case LTTNG_BUFFER_PER_PID
:
327 return config_buffer_type_per_pid
;
328 case LTTNG_BUFFER_PER_UID
:
329 return config_buffer_type_per_uid
;
330 case LTTNG_BUFFER_GLOBAL
:
331 return config_buffer_type_global
;
333 /* Should not have an unknow buffer type */
339 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
)
344 case LTTNG_CALIBRATE_FUNCTION
:
345 ret
= mi_lttng_element_calibrate_function
;
348 ret
= mi_lttng_element_empty
;
355 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
357 struct mi_writer
*mi_writer
;
359 mi_writer
= zmalloc(sizeof(struct mi_writer
));
361 PERROR("zmalloc mi_writer_create");
364 if (mi_output_type
== LTTNG_MI_XML
) {
365 mi_writer
->writer
= config_writer_create(fd_output
, 0);
366 if (!mi_writer
->writer
) {
369 mi_writer
->type
= LTTNG_MI_XML
;
383 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
392 ret
= config_writer_destroy(writer
->writer
);
403 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
407 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_command
);
411 ret
= mi_lttng_writer_write_element_string(writer
,
412 mi_lttng_element_command_name
, command
);
418 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
420 return mi_lttng_writer_close_element(writer
);
424 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
425 const char *element_name
)
427 return config_writer_open_element(writer
->writer
, element_name
);
431 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
433 return config_writer_close_element(writer
->writer
);
437 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
438 unsigned int nb_element
)
442 if (nb_element
< 1) {
446 for (i
= 0; i
< nb_element
; i
++) {
447 ret
= mi_lttng_writer_close_element(writer
);
457 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
458 const char *element_name
, uint64_t value
)
460 return config_writer_write_element_unsigned_int(writer
->writer
,
461 element_name
, value
);
465 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
466 const char *element_name
, int64_t value
)
468 return config_writer_write_element_signed_int(writer
->writer
,
469 element_name
, value
);
473 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
474 const char *element_name
, int value
)
476 return config_writer_write_element_bool(writer
->writer
,
477 element_name
, value
);
481 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
482 const char *element_name
, const char *value
)
484 return config_writer_write_element_string(writer
->writer
,
485 element_name
, value
);
489 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
490 const char *lttng_description
, const char *lttng_license
)
495 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
500 /* Version string (contain info like rc etc.) */
501 ret
= mi_lttng_writer_write_element_string(writer
,
502 mi_lttng_element_version_str
, version
->version
);
507 /* Major version number */
508 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
509 mi_lttng_element_version_major
, version
->version_major
);
514 /* Minor version number */
515 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
516 mi_lttng_element_version_minor
, version
->version_minor
);
521 /* Commit version number */
522 ret
= mi_lttng_writer_write_element_string(writer
,
523 mi_lttng_element_version_commit
, version
->version_commit
);
529 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
530 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
535 /* Name of the version */
536 ret
= mi_lttng_writer_write_element_string(writer
,
537 config_element_name
, version
->version_name
);
542 /* Description mostly related to beer... */
543 ret
= mi_lttng_writer_write_element_string(writer
,
544 mi_lttng_element_version_description
, lttng_description
);
550 ret
= mi_lttng_writer_write_element_string(writer
,
551 mi_lttng_element_version_web
, version
->package_url
);
556 /* License: free as in free beer...no...*speech* */
557 ret
= mi_lttng_writer_write_element_string(writer
,
558 mi_lttng_element_version_license
, lttng_license
);
563 /* Close version element */
564 ret
= mi_lttng_writer_close_element(writer
);
571 int mi_lttng_sessions_open(struct mi_writer
*writer
)
573 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
577 int mi_lttng_session(struct mi_writer
*writer
,
578 struct lttng_session
*session
, int is_open
)
584 /* Open sessions element */
585 ret
= mi_lttng_writer_open_element(writer
,
586 config_element_session
);
591 /* Name of the session */
592 ret
= mi_lttng_writer_write_element_string(writer
,
593 config_element_name
, session
->name
);
599 ret
= mi_lttng_writer_write_element_string(writer
,
600 config_element_path
, session
->path
);
606 ret
= mi_lttng_writer_write_element_bool(writer
,
607 config_element_enabled
, session
->enabled
);
613 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
614 config_element_snapshot_mode
, session
->snapshot_mode
);
619 /* Live timer interval in usec */
620 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
621 config_element_live_timer_interval
,
622 session
->live_timer_interval
);
628 /* Closing session element */
629 ret
= mi_lttng_writer_close_element(writer
);
637 int mi_lttng_domains_open(struct mi_writer
*writer
)
639 return mi_lttng_writer_open_element(writer
, config_element_domains
);
643 int mi_lttng_domain(struct mi_writer
*writer
,
644 struct lttng_domain
*domain
, int is_open
)
647 const char *str_domain
;
648 const char *str_buffer
;
652 /* Open domain element */
653 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
659 str_domain
= mi_lttng_domaintype_string(domain
->type
);
660 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
667 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
668 ret
= mi_lttng_writer_write_element_string(writer
,
669 config_element_buffer_type
, str_buffer
);
675 * This union is not currently used and was added for
676 * future ust domain support.
681 /* Closing domain element */
682 ret
= mi_lttng_writer_close_element(writer
);
691 int mi_lttng_channels_open(struct mi_writer
*writer
)
693 return mi_lttng_writer_open_element(writer
, config_element_channels
);
697 int mi_lttng_channel(struct mi_writer
*writer
,
698 struct lttng_channel
*channel
, int is_open
)
704 /* Opening channel element */
705 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
711 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
718 ret
= mi_lttng_writer_write_element_bool(writer
,
719 config_element_enabled
, channel
->enabled
);
725 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
731 /* Closing channel element */
732 ret
= mi_lttng_writer_close_element(writer
);
742 int mi_lttng_channel_attr(struct mi_writer
*writer
,
743 struct lttng_channel_attr
*attr
)
749 /* Opening Attributes */
750 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
756 ret
= mi_lttng_writer_write_element_string(writer
,
757 config_element_overwrite_mode
,
758 attr
->overwrite
? config_overwrite_mode_overwrite
:
759 config_overwrite_mode_discard
);
764 /* Sub buffer size in byte */
765 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
766 config_element_subbuf_size
, attr
->subbuf_size
);
771 /* Number of subbuffer (power of two) */
772 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
773 config_element_num_subbuf
,
779 /* Switch timer interval in usec */
780 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
781 config_element_switch_timer_interval
,
782 attr
->switch_timer_interval
);
787 /* Read timer interval in usec */
788 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
789 config_element_read_timer_interval
,
790 attr
->read_timer_interval
);
796 ret
= mi_lttng_writer_write_element_string(writer
,
797 config_element_output_type
,
798 attr
->output
== LTTNG_EVENT_SPLICE
?
799 config_output_type_splice
: config_output_type_mmap
);
804 /* Tracefile size in bytes */
805 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
806 config_element_tracefile_size
, attr
->tracefile_size
);
811 /* Count of tracefiles */
812 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
813 config_element_tracefile_count
,
814 attr
->tracefile_count
);
819 /* Live timer interval in usec*/
820 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
821 config_element_live_timer_interval
,
822 attr
->live_timer_interval
);
827 /* Closing attributes */
828 ret
= mi_lttng_writer_close_element(writer
);
838 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
839 struct lttng_event
*event
)
843 /* Open event element */
844 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
850 ret
= mi_lttng_writer_write_element_string(writer
,
851 config_element_name
, event
->name
);
857 ret
= mi_lttng_writer_write_element_string(writer
,
858 config_element_type
, mi_lttng_eventtype_string(event
->type
));
863 /* Is event enabled */
864 ret
= mi_lttng_writer_write_element_bool(writer
,
865 config_element_enabled
, event
->enabled
);
870 /* Event filter enabled? */
871 ret
= mi_lttng_writer_write_element_bool(writer
,
872 config_element_filter
, event
->filter
);
879 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
880 struct lttng_event
*event
)
885 ret
= mi_lttng_writer_write_element_string(writer
,
886 config_element_loglevel
, mi_lttng_loglevel_string(event
->loglevel
));
892 ret
= mi_lttng_writer_write_element_string(writer
,
893 config_element_loglevel_type
,
894 mi_lttng_logleveltype_string(event
->loglevel_type
));
899 /* event exclusion filter */
900 ret
= mi_lttng_writer_write_element_bool(writer
,
901 config_element_exclusion
, event
->exclusion
);
911 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
912 struct lttng_event
*event
)
914 /* event exclusion filter */
915 return mi_lttng_writer_write_element_bool(writer
,
916 config_element_exclusion
, event
->exclusion
);
920 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
921 struct lttng_event
*event
)
925 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
930 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
935 if (event
->attr
.probe
.addr
!= 0) {
936 /* event probe address */
937 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
938 config_element_address
, event
->attr
.probe
.addr
);
943 /* event probe offset */
944 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
945 config_element_offset
, event
->attr
.probe
.offset
);
950 /* event probe symbol_name */
951 ret
= mi_lttng_writer_write_element_string(writer
,
952 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
958 /* Close probe_attributes and attributes */
959 ret
= mi_lttng_close_multi_element(writer
, 2);
965 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
966 struct lttng_event
*event
)
970 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
975 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
980 /* event probe symbol_name */
981 ret
= mi_lttng_writer_write_element_string(writer
,
982 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
987 /* Close function_attributes and attributes */
988 ret
= mi_lttng_close_multi_element(writer
, 2);
994 int mi_lttng_events_open(struct mi_writer
*writer
)
996 return mi_lttng_writer_open_element(writer
, config_element_events
);
1000 int mi_lttng_event(struct mi_writer
*writer
,
1001 struct lttng_event
*event
, int is_open
)
1005 ret
= mi_lttng_event_common_attributes(writer
, event
);
1010 switch (event
->type
) {
1011 case LTTNG_EVENT_TRACEPOINT
:
1013 if (event
->loglevel
!= -1) {
1014 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
);
1016 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1020 case LTTNG_EVENT_FUNCTION
:
1022 case LTTNG_EVENT_PROBE
:
1023 ret
= mi_lttng_event_function_probe(writer
, event
);
1025 case LTTNG_EVENT_FUNCTION_ENTRY
:
1026 ret
= mi_lttng_event_function_entry(writer
, event
);
1028 case LTTNG_EVENT_ALL
:
1035 ret
= mi_lttng_writer_close_element(writer
);
1043 int mi_lttng_pids_open(struct mi_writer
*writer
)
1045 return mi_lttng_writer_open_element(writer
, mi_lttng_element_pids
);
1049 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
1054 /* Open element pid */
1055 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_pid
);
1060 /* Writing pid number */
1061 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1062 mi_lttng_element_pid_id
, (int)pid
);
1067 /* Writing name of the process */
1068 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1076 ret
= mi_lttng_writer_close_element(writer
);
1084 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1086 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1090 int mi_lttng_event_field(struct mi_writer
*writer
,
1091 struct lttng_event_field
*field
)
1095 if (!field
->field_name
[0]) {
1101 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1106 if (!field
->field_name
[0]) {
1111 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1118 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1119 mi_lttng_eventfieldtype_string(field
->type
));
1125 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1126 mi_lttng_element_nowrite
, field
->nowrite
);
1132 /* Close field element */
1133 ret
= mi_lttng_writer_close_element(writer
);
1140 int mi_lttng_calibrate(struct mi_writer
*writer
,
1141 struct lttng_calibrate
*calibrate
)
1145 /* Open calibrate element */
1146 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1151 /* Calibration type */
1152 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1153 mi_lttng_calibratetype_string(calibrate
->type
));
1158 /* Closing calibrate element */
1159 ret
= mi_lttng_writer_close_element(writer
);
1164 int mi_lttng_context(struct mi_writer
*writer
,
1165 struct lttng_event_context
*context
, int is_open
)
1168 const char *type_string
;
1169 struct lttng_event_perf_counter_ctx
*perf_context
;
1171 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1176 type_string
= mi_lttng_event_contexttype_string(context
->ctx
);
1178 ret
= -LTTNG_ERR_INVALID
;
1182 /* Print context type */
1183 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1186 /* Special case for PERF_*_COUNTER
1187 * print the lttng_event_perf_counter_ctx*/
1188 switch (context
->ctx
) {
1189 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1190 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1191 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1192 perf_context
= &context
->u
.perf_counter
;
1193 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1204 ret
= mi_lttng_writer_close_element(writer
);
1212 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1213 struct lttng_event_perf_counter_ctx
*perf_context
)
1217 /* Open perf_counter_context */
1218 ret
= mi_lttng_writer_open_element(writer
,
1219 mi_lttng_element_perf_counter_context
);
1225 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1226 config_element_type
, perf_context
->type
);
1232 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1233 config_element_config
, perf_context
->config
);
1238 /* Name of the perf counter */
1239 ret
= mi_lttng_writer_write_element_string(writer
,
1240 config_element_name
, perf_context
->name
);
1245 /* Close perf_counter_context */
1246 ret
= mi_lttng_writer_close_element(writer
);
1252 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1253 const char *session_name
)
1257 /* Open session element */
1258 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1263 /* Snapshot output list for current session name */
1264 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1267 /* Open element snapshots (sequence one snapshot) */
1268 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1278 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1279 struct lttng_snapshot_output
*output
)
1283 /* Open element snapshot output */
1284 ret
= mi_lttng_writer_open_element(writer
,
1285 mi_lttng_element_command_snapshot
);
1290 /* ID of the snapshot output */
1291 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1292 mi_lttng_element_id
, output
->id
);
1297 /* Name of the output */
1298 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1304 /* Destination of the output (ctrl_url)*/
1305 ret
= mi_lttng_writer_write_element_string(writer
,
1306 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1311 /* Destination of the output (data_url) */
1312 ret
= mi_lttng_writer_write_element_string(writer
,
1313 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1318 /* total size of all stream combined */
1319 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1320 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1325 /* Close snapshot output element */
1326 ret
= mi_lttng_writer_close_element(writer
);
1333 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1334 const char *name
, const char *current_session_name
)
1338 /* Open element del_snapshot */
1339 ret
= mi_lttng_writer_open_element(writer
,
1340 mi_lttng_element_command_snapshot
);
1346 if (id
!= UINT32_MAX
) {
1347 /* "Snapshot output "id" successfully deleted
1348 * for "current_session_name"
1349 * ID of the snapshot output
1351 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1352 mi_lttng_element_id
, id
);
1357 /* "Snapshot output "name" successfully deleted
1358 * for session "current_session_name"
1359 * Name of the output
1361 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1368 /* Snapshot was deleted for session "current_session_name"*/
1369 ret
= mi_lttng_writer_write_element_string(writer
,
1370 mi_lttng_element_snapshot_session_name
,
1371 current_session_name
);
1376 /* Close snapshot element */
1377 ret
= mi_lttng_writer_close_element(writer
);
1384 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1385 const char *current_session_name
, const char *n_ptr
,
1386 struct lttng_snapshot_output
*output
)
1390 /* Open element snapshot */
1391 ret
= mi_lttng_writer_open_element(writer
,
1392 mi_lttng_element_command_snapshot
);
1397 /* Snapshot output id */
1398 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1399 mi_lttng_element_id
, output
->id
);
1404 /* Snapshot output names */
1405 ret
= mi_lttng_writer_write_element_string(writer
,
1406 config_element_name
, n_ptr
);
1411 /* Destination of the output (ctrl_url)*/
1412 ret
= mi_lttng_writer_write_element_string(writer
,
1413 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1418 /* Snapshot added for session "current_session_name"*/
1419 ret
= mi_lttng_writer_write_element_string(writer
,
1420 mi_lttng_element_snapshot_session_name
, current_session_name
);
1425 /* total size of all stream combined */
1426 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1427 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1432 /* Close snapshot element */
1433 ret
= mi_lttng_writer_close_element(writer
);
1440 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1441 const char *current_session_name
, const char *url
,
1442 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1446 /* Open element snapshot */
1447 ret
= mi_lttng_writer_open_element(writer
,
1448 mi_lttng_element_command_snapshot
);
1454 * If a valid an URL was given, serialize it,
1455 * else take the command line data and ctrl urls*/
1457 /* Destination of the output (ctrl_url)*/
1458 ret
= mi_lttng_writer_write_element_string(writer
,
1459 mi_lttng_element_snapshot_ctrl_url
, url
);
1463 } else if (cmdline_ctrl_url
) {
1464 /* Destination of the output (ctrl_url)*/
1465 ret
= mi_lttng_writer_write_element_string(writer
,
1466 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1471 /* Destination of the output (data_url) */
1472 ret
= mi_lttng_writer_write_element_string(writer
,
1473 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1479 /* Close record_snapshot element */
1480 ret
= mi_lttng_writer_close_element(writer
);