2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
4 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License, version 2 only, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <common/config/session-config.h>
22 #include <common/defaults.h>
23 #include <lttng/snapshot-internal.h>
24 #include <lttng/channel.h>
29 #define MI_SCHEMA_MAJOR_VERSION 3
30 #define MI_SCHEMA_MINOR_VERSION 0
32 /* Machine interface namespace URI */
33 LTTNG_HIDDEN
const char * const mi_lttng_xmlns
= "xmlns";
34 LTTNG_HIDDEN
const char * const mi_lttng_xmlns_xsi
= "xmlns:xsi";
35 LTTNG_HIDDEN
const char * const mi_lttng_w3_schema_uri
= "http://www.w3.org/2001/XMLSchema-instance";
36 LTTNG_HIDDEN
const char * const mi_lttng_schema_location
= "xsi:schemaLocation";
37 LTTNG_HIDDEN
const char * const mi_lttng_schema_location_uri
=
38 DEFAULT_LTTNG_MI_NAMESPACE
" "
39 "http://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION
)
40 "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION
) "."
41 XSTR(MI_SCHEMA_MINOR_VERSION
) ".xsd";
42 LTTNG_HIDDEN
const char * const mi_lttng_schema_version
= "schemaVersion";
43 LTTNG_HIDDEN
const char * const mi_lttng_schema_version_value
= XSTR(MI_SCHEMA_MAJOR_VERSION
)
44 "." XSTR(MI_SCHEMA_MINOR_VERSION
);
46 /* Strings related to command */
47 const char * const mi_lttng_element_command
= "command";
48 const char * const mi_lttng_element_command_action
= "snapshot_action";
49 const char * const mi_lttng_element_command_add_context
= "add-context";
50 const char * const mi_lttng_element_command_create
= "create";
51 const char * const mi_lttng_element_command_destroy
= "destroy";
52 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
53 const char * const mi_lttng_element_command_disable_event
= "disable-event";
54 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
55 const char * const mi_lttng_element_command_enable_event
= "enable-event";
56 const char * const mi_lttng_element_command_list
= "list";
57 const char * const mi_lttng_element_command_load
= "load";
58 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata
= "metadata";
59 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata_action
= "metadata_action";
60 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate
= "regenerate";
61 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate_action
= "regenerate_action";
62 const char * const mi_lttng_element_command_name
= "name";
63 const char * const mi_lttng_element_command_output
= "output";
64 const char * const mi_lttng_element_command_save
= "save";
65 const char * const mi_lttng_element_command_set_session
= "set-session";
66 const char * const mi_lttng_element_command_snapshot
= "snapshot";
67 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
68 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
69 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
70 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
71 const char * const mi_lttng_element_command_start
= "start";
72 const char * const mi_lttng_element_command_stop
= "stop";
73 const char * const mi_lttng_element_command_success
= "success";
74 const char * const mi_lttng_element_command_track
= "track";
75 const char * const mi_lttng_element_command_untrack
= "untrack";
76 const char * const mi_lttng_element_command_version
= "version";
78 /* Strings related to version command */
79 const char * const mi_lttng_element_version
= "version";
80 const char * const mi_lttng_element_version_commit
= "commit";
81 const char * const mi_lttng_element_version_description
= "description";
82 const char * const mi_lttng_element_version_license
= "license";
83 const char * const mi_lttng_element_version_major
= "major";
84 const char * const mi_lttng_element_version_minor
= "minor";
85 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
86 const char * const mi_lttng_element_version_str
= "string";
87 const char * const mi_lttng_element_version_web
= "url";
89 /* String related to a lttng_event_field */
90 const char * const mi_lttng_element_event_field
= "event_field";
91 const char * const mi_lttng_element_event_fields
= "event_fields";
93 /* String related to lttng_event_perf_counter_ctx */
94 const char * const mi_lttng_element_perf_counter_context
= "perf";
96 /* Strings related to pid */
97 const char * const mi_lttng_element_pid_id
= "id";
99 /* Strings related to save command */
100 const char * const mi_lttng_element_save
= "save";
102 /* Strings related to load command */
103 const char * const mi_lttng_element_load
= "load";
104 LTTNG_HIDDEN
const char * const mi_lttng_element_load_overrides
= "overrides";
105 LTTNG_HIDDEN
const char * const mi_lttng_element_load_override_url
= "url";
107 /* General elements of mi_lttng */
108 const char * const mi_lttng_element_empty
= "";
109 const char * const mi_lttng_element_id
= "id";
110 const char * const mi_lttng_element_nowrite
= "nowrite";
111 const char * const mi_lttng_element_success
= "success";
112 const char * const mi_lttng_element_type_enum
= "ENUM";
113 const char * const mi_lttng_element_type_float
= "FLOAT";
114 const char * const mi_lttng_element_type_integer
= "INTEGER";
115 const char * const mi_lttng_element_type_other
= "OTHER";
116 const char * const mi_lttng_element_type_string
= "STRING";
118 /* String related to loglevel */
119 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
120 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
121 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
122 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
123 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
124 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
125 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
126 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
127 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
128 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
129 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
130 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
131 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
132 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
133 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
134 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
136 /* String related to loglevel JUL */
137 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
138 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
139 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
140 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
141 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
142 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
143 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
144 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
145 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
147 /* String related to loglevel LOG4J */
148 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
149 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
150 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
151 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
152 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
153 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
154 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
155 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
157 /* String related to loglevel Python */
158 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
159 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
160 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
161 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
162 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
163 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
165 /* String related to loglevel type */
166 const char * const mi_lttng_loglevel_type_all
= "ALL";
167 const char * const mi_lttng_loglevel_type_range
= "RANGE";
168 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
169 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
171 /* String related to a lttng_snapshot_output */
172 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
173 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
174 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
175 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
176 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
177 const char * const mi_lttng_element_snapshots
= "snapshots";
179 /* String related to track/untrack command */
180 const char * const mi_lttng_element_track_untrack_all_wildcard
= "*";
182 /* Deprecated symbols preserved for ABI compatibility. */
183 const char * const mi_lttng_context_type_perf_counter
;
184 const char * const mi_lttng_context_type_perf_cpu_counter
;
185 const char * const mi_lttng_context_type_perf_thread_counter
;
186 const char * const mi_lttng_element_track_untrack_pid_target
;
187 const char * const mi_lttng_element_track_untrack_targets
;
188 const char * const mi_lttng_element_calibrate
;
189 const char * const mi_lttng_element_calibrate_function
;
190 const char * const mi_lttng_element_command_calibrate
;
192 /* This is a merge of jul loglevel and regular loglevel
193 * Those should never overlap by definition
194 * (see struct lttng_event loglevel)
197 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
200 case LTTNG_DOMAIN_KERNEL
:
201 case LTTNG_DOMAIN_UST
:
204 return mi_lttng_element_empty
;
205 case LTTNG_LOGLEVEL_EMERG
:
206 return mi_lttng_loglevel_str_emerg
;
207 case LTTNG_LOGLEVEL_ALERT
:
208 return mi_lttng_loglevel_str_alert
;
209 case LTTNG_LOGLEVEL_CRIT
:
210 return mi_lttng_loglevel_str_crit
;
211 case LTTNG_LOGLEVEL_ERR
:
212 return mi_lttng_loglevel_str_err
;
213 case LTTNG_LOGLEVEL_WARNING
:
214 return mi_lttng_loglevel_str_warning
;
215 case LTTNG_LOGLEVEL_NOTICE
:
216 return mi_lttng_loglevel_str_notice
;
217 case LTTNG_LOGLEVEL_INFO
:
218 return mi_lttng_loglevel_str_info
;
219 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
220 return mi_lttng_loglevel_str_debug_system
;
221 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
222 return mi_lttng_loglevel_str_debug_program
;
223 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
224 return mi_lttng_loglevel_str_debug_process
;
225 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
226 return mi_lttng_loglevel_str_debug_module
;
227 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
228 return mi_lttng_loglevel_str_debug_unit
;
229 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
230 return mi_lttng_loglevel_str_debug_function
;
231 case LTTNG_LOGLEVEL_DEBUG_LINE
:
232 return mi_lttng_loglevel_str_debug_line
;
233 case LTTNG_LOGLEVEL_DEBUG
:
234 return mi_lttng_loglevel_str_debug
;
236 return mi_lttng_loglevel_str_unknown
;
239 case LTTNG_DOMAIN_LOG4J
:
242 return mi_lttng_element_empty
;
243 case LTTNG_LOGLEVEL_LOG4J_OFF
:
244 return mi_lttng_loglevel_str_log4j_off
;
245 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
246 return mi_lttng_loglevel_str_log4j_fatal
;
247 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
248 return mi_lttng_loglevel_str_log4j_error
;
249 case LTTNG_LOGLEVEL_LOG4J_WARN
:
250 return mi_lttng_loglevel_str_log4j_warn
;
251 case LTTNG_LOGLEVEL_LOG4J_INFO
:
252 return mi_lttng_loglevel_str_log4j_info
;
253 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
254 return mi_lttng_loglevel_str_log4j_debug
;
255 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
256 return mi_lttng_loglevel_str_log4j_trace
;
257 case LTTNG_LOGLEVEL_LOG4J_ALL
:
258 return mi_lttng_loglevel_str_log4j_all
;
260 return mi_lttng_loglevel_str_unknown
;
263 case LTTNG_DOMAIN_JUL
:
266 return mi_lttng_element_empty
;
267 case LTTNG_LOGLEVEL_JUL_OFF
:
268 return mi_lttng_loglevel_str_jul_off
;
269 case LTTNG_LOGLEVEL_JUL_SEVERE
:
270 return mi_lttng_loglevel_str_jul_severe
;
271 case LTTNG_LOGLEVEL_JUL_WARNING
:
272 return mi_lttng_loglevel_str_jul_warning
;
273 case LTTNG_LOGLEVEL_JUL_INFO
:
274 return mi_lttng_loglevel_str_jul_info
;
275 case LTTNG_LOGLEVEL_JUL_CONFIG
:
276 return mi_lttng_loglevel_str_jul_config
;
277 case LTTNG_LOGLEVEL_JUL_FINE
:
278 return mi_lttng_loglevel_str_jul_fine
;
279 case LTTNG_LOGLEVEL_JUL_FINER
:
280 return mi_lttng_loglevel_str_jul_finer
;
281 case LTTNG_LOGLEVEL_JUL_FINEST
:
282 return mi_lttng_loglevel_str_jul_finest
;
283 case LTTNG_LOGLEVEL_JUL_ALL
:
284 return mi_lttng_loglevel_str_jul_all
;
286 return mi_lttng_loglevel_str_unknown
;
289 case LTTNG_DOMAIN_PYTHON
:
291 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
292 return mi_lttng_loglevel_str_python_critical
;
293 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
294 return mi_lttng_loglevel_str_python_error
;
295 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
296 return mi_lttng_loglevel_str_python_warning
;
297 case LTTNG_LOGLEVEL_PYTHON_INFO
:
298 return mi_lttng_loglevel_str_python_info
;
299 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
300 return mi_lttng_loglevel_str_python_debug
;
301 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
302 return mi_lttng_loglevel_str_python_notset
;
304 return mi_lttng_loglevel_str_unknown
;
308 return mi_lttng_loglevel_str_unknown
;
313 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
316 case LTTNG_EVENT_LOGLEVEL_ALL
:
317 return mi_lttng_loglevel_type_all
;
318 case LTTNG_EVENT_LOGLEVEL_RANGE
:
319 return mi_lttng_loglevel_type_range
;
320 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
321 return mi_lttng_loglevel_type_single
;
323 return mi_lttng_loglevel_type_unknown
;
328 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
331 case LTTNG_EVENT_ALL
:
332 return config_event_type_all
;
333 case LTTNG_EVENT_TRACEPOINT
:
334 return config_event_type_tracepoint
;
335 case LTTNG_EVENT_PROBE
:
336 return config_event_type_probe
;
337 case LTTNG_EVENT_FUNCTION
:
338 return config_event_type_function
;
339 case LTTNG_EVENT_FUNCTION_ENTRY
:
340 return config_event_type_function_entry
;
341 case LTTNG_EVENT_SYSCALL
:
342 return config_event_type_syscall
;
343 case LTTNG_EVENT_NOOP
:
344 return config_event_type_noop
;
346 return mi_lttng_element_empty
;
351 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
354 case LTTNG_EVENT_CONTEXT_PID
:
355 return config_event_context_pid
;
356 case LTTNG_EVENT_CONTEXT_PROCNAME
:
357 return config_event_context_procname
;
358 case LTTNG_EVENT_CONTEXT_PRIO
:
359 return config_event_context_prio
;
360 case LTTNG_EVENT_CONTEXT_NICE
:
361 return config_event_context_nice
;
362 case LTTNG_EVENT_CONTEXT_VPID
:
363 return config_event_context_vpid
;
364 case LTTNG_EVENT_CONTEXT_TID
:
365 return config_event_context_tid
;
366 case LTTNG_EVENT_CONTEXT_VTID
:
367 return config_event_context_vtid
;
368 case LTTNG_EVENT_CONTEXT_PPID
:
369 return config_event_context_ppid
;
370 case LTTNG_EVENT_CONTEXT_VPPID
:
371 return config_event_context_vppid
;
372 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
373 return config_event_context_pthread_id
;
374 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
375 return config_event_context_hostname
;
376 case LTTNG_EVENT_CONTEXT_IP
:
377 return config_event_context_ip
;
384 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
387 case(LTTNG_EVENT_FIELD_INTEGER
):
388 return mi_lttng_element_type_integer
;
389 case(LTTNG_EVENT_FIELD_ENUM
):
390 return mi_lttng_element_type_enum
;
391 case(LTTNG_EVENT_FIELD_FLOAT
):
392 return mi_lttng_element_type_float
;
393 case(LTTNG_EVENT_FIELD_STRING
):
394 return mi_lttng_element_type_string
;
396 return mi_lttng_element_type_other
;
401 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
403 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
405 case LTTNG_DOMAIN_KERNEL
:
406 return config_domain_type_kernel
;
407 case LTTNG_DOMAIN_UST
:
408 return config_domain_type_ust
;
409 case LTTNG_DOMAIN_JUL
:
410 return config_domain_type_jul
;
411 case LTTNG_DOMAIN_LOG4J
:
412 return config_domain_type_log4j
;
413 case LTTNG_DOMAIN_PYTHON
:
414 return config_domain_type_python
;
416 /* Should not have an unknown domain */
423 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
426 case LTTNG_BUFFER_PER_PID
:
427 return config_buffer_type_per_pid
;
428 case LTTNG_BUFFER_PER_UID
:
429 return config_buffer_type_per_uid
;
430 case LTTNG_BUFFER_GLOBAL
:
431 return config_buffer_type_global
;
433 /* Should not have an unknow buffer type */
440 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
442 struct mi_writer
*mi_writer
;
444 mi_writer
= zmalloc(sizeof(struct mi_writer
));
446 PERROR("zmalloc mi_writer_create");
449 if (mi_output_type
== LTTNG_MI_XML
) {
450 mi_writer
->writer
= config_writer_create(fd_output
, 0);
451 if (!mi_writer
->writer
) {
454 mi_writer
->type
= LTTNG_MI_XML
;
468 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
477 ret
= config_writer_destroy(writer
->writer
);
488 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
493 * A command is always the MI's root node, it must declare the current
494 * namespace and schema URIs and the schema's version.
496 ret
= config_writer_open_element(writer
->writer
,
497 mi_lttng_element_command
);
502 ret
= config_writer_write_attribute(writer
->writer
,
503 mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
508 ret
= config_writer_write_attribute(writer
->writer
,
509 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
514 ret
= config_writer_write_attribute(writer
->writer
,
515 mi_lttng_schema_location
,
516 mi_lttng_schema_location_uri
);
521 ret
= config_writer_write_attribute(writer
->writer
,
522 mi_lttng_schema_version
,
523 mi_lttng_schema_version_value
);
528 ret
= mi_lttng_writer_write_element_string(writer
,
529 mi_lttng_element_command_name
, command
);
535 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
537 return mi_lttng_writer_close_element(writer
);
541 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
542 const char *element_name
)
544 return config_writer_open_element(writer
->writer
, element_name
);
548 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
550 return config_writer_close_element(writer
->writer
);
554 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
555 unsigned int nb_element
)
559 if (nb_element
< 1) {
563 for (i
= 0; i
< nb_element
; i
++) {
564 ret
= mi_lttng_writer_close_element(writer
);
574 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
575 const char *element_name
, uint64_t value
)
577 return config_writer_write_element_unsigned_int(writer
->writer
,
578 element_name
, value
);
582 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
583 const char *element_name
, int64_t value
)
585 return config_writer_write_element_signed_int(writer
->writer
,
586 element_name
, value
);
590 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
591 const char *element_name
, int value
)
593 return config_writer_write_element_bool(writer
->writer
,
594 element_name
, value
);
598 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
599 const char *element_name
, const char *value
)
601 return config_writer_write_element_string(writer
->writer
,
602 element_name
, value
);
606 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
607 const char *lttng_description
, const char *lttng_license
)
612 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
617 /* Version string (contain info like rc etc.) */
618 ret
= mi_lttng_writer_write_element_string(writer
,
619 mi_lttng_element_version_str
, version
->version
);
624 /* Major version number */
625 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
626 mi_lttng_element_version_major
, version
->version_major
);
631 /* Minor version number */
632 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
633 mi_lttng_element_version_minor
, version
->version_minor
);
638 /* Commit version number */
639 ret
= mi_lttng_writer_write_element_string(writer
,
640 mi_lttng_element_version_commit
, version
->version_commit
);
646 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
647 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
652 /* Name of the version */
653 ret
= mi_lttng_writer_write_element_string(writer
,
654 config_element_name
, version
->version_name
);
659 /* Description mostly related to beer... */
660 ret
= mi_lttng_writer_write_element_string(writer
,
661 mi_lttng_element_version_description
, lttng_description
);
667 ret
= mi_lttng_writer_write_element_string(writer
,
668 mi_lttng_element_version_web
, version
->package_url
);
673 /* License: free as in free beer...no...*speech* */
674 ret
= mi_lttng_writer_write_element_string(writer
,
675 mi_lttng_element_version_license
, lttng_license
);
680 /* Close version element */
681 ret
= mi_lttng_writer_close_element(writer
);
688 int mi_lttng_sessions_open(struct mi_writer
*writer
)
690 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
694 int mi_lttng_session(struct mi_writer
*writer
,
695 struct lttng_session
*session
, int is_open
)
701 /* Open sessions element */
702 ret
= mi_lttng_writer_open_element(writer
,
703 config_element_session
);
708 /* Name of the session */
709 ret
= mi_lttng_writer_write_element_string(writer
,
710 config_element_name
, session
->name
);
716 ret
= mi_lttng_writer_write_element_string(writer
,
717 config_element_path
, session
->path
);
723 ret
= mi_lttng_writer_write_element_bool(writer
,
724 config_element_enabled
, session
->enabled
);
730 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
731 config_element_snapshot_mode
, session
->snapshot_mode
);
736 /* Live timer interval in usec */
737 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
738 config_element_live_timer_interval
,
739 session
->live_timer_interval
);
745 /* Closing session element */
746 ret
= mi_lttng_writer_close_element(writer
);
754 int mi_lttng_domains_open(struct mi_writer
*writer
)
756 return mi_lttng_writer_open_element(writer
, config_element_domains
);
760 int mi_lttng_domain(struct mi_writer
*writer
,
761 struct lttng_domain
*domain
, int is_open
)
764 const char *str_domain
;
765 const char *str_buffer
;
769 /* Open domain element */
770 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
776 str_domain
= mi_lttng_domaintype_string(domain
->type
);
777 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
784 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
785 ret
= mi_lttng_writer_write_element_string(writer
,
786 config_element_buffer_type
, str_buffer
);
792 * This union is not currently used and was added for
793 * future ust domain support.
798 /* Closing domain element */
799 ret
= mi_lttng_writer_close_element(writer
);
808 int mi_lttng_channels_open(struct mi_writer
*writer
)
810 return mi_lttng_writer_open_element(writer
, config_element_channels
);
814 int mi_lttng_channel(struct mi_writer
*writer
,
815 struct lttng_channel
*channel
, int is_open
)
821 /* Opening channel element */
822 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
828 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
835 ret
= mi_lttng_writer_write_element_bool(writer
,
836 config_element_enabled
, channel
->enabled
);
842 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
848 /* Closing channel element */
849 ret
= mi_lttng_writer_close_element(writer
);
859 int mi_lttng_channel_attr(struct mi_writer
*writer
,
860 struct lttng_channel_attr
*attr
)
863 struct lttng_channel
*chan
= caa_container_of(attr
,
864 struct lttng_channel
, attr
);
865 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
869 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
874 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
879 ret
= lttng_channel_get_monitor_timer_interval(chan
,
880 &monitor_timer_interval
);
885 /* Opening Attributes */
886 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
892 ret
= mi_lttng_writer_write_element_string(writer
,
893 config_element_overwrite_mode
,
894 attr
->overwrite
? config_overwrite_mode_overwrite
:
895 config_overwrite_mode_discard
);
900 /* Sub buffer size in byte */
901 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
902 config_element_subbuf_size
, attr
->subbuf_size
);
907 /* Number of subbuffer (power of two) */
908 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
909 config_element_num_subbuf
,
915 /* Switch timer interval in usec */
916 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
917 config_element_switch_timer_interval
,
918 attr
->switch_timer_interval
);
923 /* Read timer interval in usec */
924 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
925 config_element_read_timer_interval
,
926 attr
->read_timer_interval
);
931 /* Monitor timer interval in usec */
932 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
933 config_element_monitor_timer_interval
,
934 monitor_timer_interval
);
940 ret
= mi_lttng_writer_write_element_string(writer
,
941 config_element_output_type
,
942 attr
->output
== LTTNG_EVENT_SPLICE
?
943 config_output_type_splice
: config_output_type_mmap
);
948 /* Tracefile size in bytes */
949 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
950 config_element_tracefile_size
, attr
->tracefile_size
);
955 /* Count of tracefiles */
956 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
957 config_element_tracefile_count
,
958 attr
->tracefile_count
);
963 /* Live timer interval in usec*/
964 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
965 config_element_live_timer_interval
,
966 attr
->live_timer_interval
);
971 /* Discarded events */
972 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
973 config_element_discarded_events
,
980 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
981 config_element_lost_packets
,
987 /* Closing attributes */
988 ret
= mi_lttng_writer_close_element(writer
);
998 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
999 struct lttng_event
*event
)
1002 const char *filter_expression
;
1004 /* Open event element */
1005 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
1011 ret
= mi_lttng_writer_write_element_string(writer
,
1012 config_element_name
, event
->name
);
1018 ret
= mi_lttng_writer_write_element_string(writer
,
1019 config_element_type
, mi_lttng_eventtype_string(event
->type
));
1024 /* Is event enabled */
1025 ret
= mi_lttng_writer_write_element_bool(writer
,
1026 config_element_enabled
, event
->enabled
);
1031 /* Event filter expression */
1032 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1037 if (filter_expression
) {
1038 ret
= mi_lttng_writer_write_element_string(writer
,
1039 config_element_filter_expression
,
1050 static int write_event_exclusions(struct mi_writer
*writer
,
1051 struct lttng_event
*event
)
1055 int exclusion_count
;
1057 /* Open event exclusions */
1058 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1063 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1064 if (exclusion_count
< 0) {
1065 ret
= exclusion_count
;
1069 for (i
= 0; i
< exclusion_count
; i
++) {
1072 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1074 /* Close exclusions */
1075 mi_lttng_writer_close_element(writer
);
1079 ret
= mi_lttng_writer_write_element_string(writer
,
1080 config_element_exclusion
, name
);
1082 /* Close exclusions */
1083 mi_lttng_writer_close_element(writer
);
1088 /* Close exclusions */
1089 ret
= mi_lttng_writer_close_element(writer
);
1096 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1097 struct lttng_event
*event
, enum lttng_domain_type domain
)
1101 /* Event loglevel */
1102 ret
= mi_lttng_writer_write_element_string(writer
,
1103 config_element_loglevel
,
1104 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1109 /* Log level type */
1110 ret
= mi_lttng_writer_write_element_string(writer
,
1111 config_element_loglevel_type
,
1112 mi_lttng_logleveltype_string(event
->loglevel_type
));
1117 /* Event exclusions */
1118 ret
= write_event_exclusions(writer
, event
);
1125 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1126 struct lttng_event
*event
)
1128 /* event exclusion filter */
1129 return write_event_exclusions(writer
, event
);
1133 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1134 struct lttng_event
*event
)
1138 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1143 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1148 if (event
->attr
.probe
.addr
!= 0) {
1149 /* event probe address */
1150 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1151 config_element_address
, event
->attr
.probe
.addr
);
1156 /* event probe offset */
1157 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1158 config_element_offset
, event
->attr
.probe
.offset
);
1163 /* event probe symbol_name */
1164 ret
= mi_lttng_writer_write_element_string(writer
,
1165 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1171 /* Close probe_attributes and attributes */
1172 ret
= mi_lttng_close_multi_element(writer
, 2);
1178 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1179 struct lttng_event
*event
)
1183 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1188 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1193 /* event probe symbol_name */
1194 ret
= mi_lttng_writer_write_element_string(writer
,
1195 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1200 /* Close function_attributes and attributes */
1201 ret
= mi_lttng_close_multi_element(writer
, 2);
1207 int mi_lttng_events_open(struct mi_writer
*writer
)
1209 return mi_lttng_writer_open_element(writer
, config_element_events
);
1213 int mi_lttng_event(struct mi_writer
*writer
,
1214 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1218 ret
= mi_lttng_event_common_attributes(writer
, event
);
1223 switch (event
->type
) {
1224 case LTTNG_EVENT_TRACEPOINT
:
1226 if (event
->loglevel
!= -1) {
1227 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1229 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1233 case LTTNG_EVENT_FUNCTION
:
1235 case LTTNG_EVENT_PROBE
:
1236 ret
= mi_lttng_event_function_probe(writer
, event
);
1238 case LTTNG_EVENT_FUNCTION_ENTRY
:
1239 ret
= mi_lttng_event_function_entry(writer
, event
);
1241 case LTTNG_EVENT_ALL
:
1248 ret
= mi_lttng_writer_close_element(writer
);
1256 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1258 return mi_lttng_writer_open_element(writer
, config_element_trackers
);
1262 int mi_lttng_pid_tracker_open(struct mi_writer
*writer
)
1266 /* Open element pid_tracker */
1267 ret
= mi_lttng_writer_open_element(writer
, config_element_pid_tracker
);
1272 /* Open targets element */
1273 ret
= mi_lttng_targets_open(writer
);
1279 int mi_lttng_pids_open(struct mi_writer
*writer
)
1281 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1285 * TODO: move the listing of pid for user agent to process semantic on
1286 * mi api bump. The use of process element break the mi api.
1289 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *name
,
1294 /* Open pid process */
1295 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1300 /* Writing pid number */
1301 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1302 mi_lttng_element_pid_id
, (int)pid
);
1307 /* Writing name of the process */
1309 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1318 ret
= mi_lttng_writer_close_element(writer
);
1326 int mi_lttng_targets_open(struct mi_writer
*writer
)
1328 return mi_lttng_writer_open_element(writer
,
1329 config_element_targets
);
1333 int mi_lttng_pid_target(struct mi_writer
*writer
, pid_t pid
, int is_open
)
1337 ret
= mi_lttng_writer_open_element(writer
,
1338 config_element_target_pid
);
1343 /* Writing pid number
1344 * Special case for element all on track untrack command
1345 * All pid is represented as wildcard *
1347 if ((int) pid
== -1) {
1348 ret
= mi_lttng_writer_write_element_string(writer
,
1350 mi_lttng_element_track_untrack_all_wildcard
);
1352 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1353 config_element_pid
, (int) pid
);
1360 ret
= mi_lttng_writer_close_element(writer
);
1371 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1373 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1377 int mi_lttng_event_field(struct mi_writer
*writer
,
1378 struct lttng_event_field
*field
)
1382 if (!field
->field_name
[0]) {
1388 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1393 if (!field
->field_name
[0]) {
1398 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1405 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1406 mi_lttng_eventfieldtype_string(field
->type
));
1412 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1413 mi_lttng_element_nowrite
, field
->nowrite
);
1419 /* Close field element */
1420 ret
= mi_lttng_writer_close_element(writer
);
1427 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1428 struct lttng_event_perf_counter_ctx
*perf_context
)
1432 /* Open perf_counter_context */
1433 ret
= mi_lttng_writer_open_element(writer
,
1434 mi_lttng_element_perf_counter_context
);
1440 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1441 config_element_type
, perf_context
->type
);
1447 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1448 config_element_config
, perf_context
->config
);
1453 /* Name of the perf counter */
1454 ret
= mi_lttng_writer_write_element_string(writer
,
1455 config_element_name
, perf_context
->name
);
1460 /* Close perf_counter_context */
1461 ret
= mi_lttng_writer_close_element(writer
);
1467 int mi_lttng_app_context(struct mi_writer
*writer
,
1468 const char *provider_name
, const char *ctx_name
)
1473 ret
= mi_lttng_writer_open_element(writer
,
1474 config_element_context_app
);
1480 ret
= mi_lttng_writer_write_element_string(writer
,
1481 config_element_context_app_provider_name
,
1488 ret
= mi_lttng_writer_write_element_string(writer
,
1489 config_element_context_app_ctx_name
, ctx_name
);
1495 ret
= mi_lttng_writer_close_element(writer
);
1501 int mi_lttng_context(struct mi_writer
*writer
,
1502 struct lttng_event_context
*context
, int is_open
)
1507 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1512 /* Special case for PERF_*_COUNTER
1513 * print the lttng_event_perf_counter_ctx*/
1514 switch (context
->ctx
) {
1515 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1516 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1517 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1519 struct lttng_event_perf_counter_ctx
*perf_context
=
1520 &context
->u
.perf_counter
;
1521 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1527 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
1529 ret
= mi_lttng_app_context(writer
,
1530 context
->u
.app_ctx
.provider_name
,
1531 context
->u
.app_ctx
.ctx_name
);
1539 const char *type_string
= mi_lttng_event_contexttype_string(
1542 ret
= -LTTNG_ERR_INVALID
;
1546 /* Print context type */
1547 ret
= mi_lttng_writer_write_element_string(writer
,
1548 config_element_type
, type_string
);
1555 ret
= mi_lttng_writer_close_element(writer
);
1563 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1564 const char *session_name
)
1568 /* Open session element */
1569 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1574 /* Snapshot output list for current session name */
1575 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1581 /* Open element snapshots (sequence one snapshot) */
1582 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1592 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1593 struct lttng_snapshot_output
*output
)
1597 /* Open element snapshot output */
1598 ret
= mi_lttng_writer_open_element(writer
,
1599 mi_lttng_element_command_snapshot
);
1604 /* ID of the snapshot output */
1605 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1606 mi_lttng_element_id
, output
->id
);
1611 /* Name of the output */
1612 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1618 /* Destination of the output (ctrl_url)*/
1619 ret
= mi_lttng_writer_write_element_string(writer
,
1620 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1625 /* Destination of the output (data_url) */
1626 ret
= mi_lttng_writer_write_element_string(writer
,
1627 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1632 /* total size of all stream combined */
1633 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1634 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1639 /* Close snapshot output element */
1640 ret
= mi_lttng_writer_close_element(writer
);
1647 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1648 const char *name
, const char *current_session_name
)
1652 /* Open element del_snapshot */
1653 ret
= mi_lttng_writer_open_element(writer
,
1654 mi_lttng_element_command_snapshot
);
1660 if (id
!= UINT32_MAX
) {
1661 /* "Snapshot output "id" successfully deleted
1662 * for "current_session_name"
1663 * ID of the snapshot output
1665 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1666 mi_lttng_element_id
, id
);
1671 /* "Snapshot output "name" successfully deleted
1672 * for session "current_session_name"
1673 * Name of the output
1675 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1682 /* Snapshot was deleted for session "current_session_name"*/
1683 ret
= mi_lttng_writer_write_element_string(writer
,
1684 mi_lttng_element_snapshot_session_name
,
1685 current_session_name
);
1690 /* Close snapshot element */
1691 ret
= mi_lttng_writer_close_element(writer
);
1698 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1699 const char *current_session_name
, const char *n_ptr
,
1700 struct lttng_snapshot_output
*output
)
1704 /* Open element snapshot */
1705 ret
= mi_lttng_writer_open_element(writer
,
1706 mi_lttng_element_command_snapshot
);
1711 /* Snapshot output id */
1712 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1713 mi_lttng_element_id
, output
->id
);
1718 /* Snapshot output names */
1719 ret
= mi_lttng_writer_write_element_string(writer
,
1720 config_element_name
, n_ptr
);
1725 /* Destination of the output (ctrl_url)*/
1726 ret
= mi_lttng_writer_write_element_string(writer
,
1727 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1732 /* Snapshot added for session "current_session_name"*/
1733 ret
= mi_lttng_writer_write_element_string(writer
,
1734 mi_lttng_element_snapshot_session_name
, current_session_name
);
1739 /* total size of all stream combined */
1740 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1741 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1746 /* Close snapshot element */
1747 ret
= mi_lttng_writer_close_element(writer
);
1754 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1755 const char *current_session_name
, const char *url
,
1756 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1760 /* Open element snapshot */
1761 ret
= mi_lttng_writer_open_element(writer
,
1762 mi_lttng_element_command_snapshot
);
1768 * If a valid an URL was given, serialize it,
1769 * else take the command line data and ctrl urls*/
1771 /* Destination of the output (ctrl_url)*/
1772 ret
= mi_lttng_writer_write_element_string(writer
,
1773 mi_lttng_element_snapshot_ctrl_url
, url
);
1777 } else if (cmdline_ctrl_url
) {
1778 /* Destination of the output (ctrl_url)*/
1779 ret
= mi_lttng_writer_write_element_string(writer
,
1780 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1785 /* Destination of the output (data_url) */
1786 ret
= mi_lttng_writer_write_element_string(writer
,
1787 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1793 /* Close record_snapshot element */
1794 ret
= mi_lttng_writer_close_element(writer
);