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";
105 /* General elements of mi_lttng */
106 const char * const mi_lttng_element_empty
= "";
107 const char * const mi_lttng_element_id
= "id";
108 const char * const mi_lttng_element_nowrite
= "nowrite";
109 const char * const mi_lttng_element_success
= "success";
110 const char * const mi_lttng_element_type_enum
= "ENUM";
111 const char * const mi_lttng_element_type_float
= "FLOAT";
112 const char * const mi_lttng_element_type_integer
= "INTEGER";
113 const char * const mi_lttng_element_type_other
= "OTHER";
114 const char * const mi_lttng_element_type_string
= "STRING";
116 /* String related to loglevel */
117 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
118 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
119 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
120 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
121 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
122 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
123 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
124 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
125 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
126 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
127 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
128 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
129 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
130 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
131 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
132 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
134 /* String related to loglevel JUL */
135 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
136 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
137 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
138 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
139 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
140 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
141 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
142 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
143 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
145 /* String related to loglevel LOG4J */
146 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
147 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
148 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
149 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
150 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
151 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
152 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
153 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
155 /* String related to loglevel Python */
156 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
157 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
158 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
159 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
160 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
161 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
163 /* String related to loglevel type */
164 const char * const mi_lttng_loglevel_type_all
= "ALL";
165 const char * const mi_lttng_loglevel_type_range
= "RANGE";
166 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
167 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
169 /* String related to a lttng_snapshot_output */
170 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
171 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
172 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
173 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
174 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
175 const char * const mi_lttng_element_snapshots
= "snapshots";
177 /* String related to track/untrack command */
178 const char * const mi_lttng_element_track_untrack_all_wildcard
= "*";
180 /* Deprecated symbols preserved for ABI compatibility. */
181 const char * const mi_lttng_context_type_perf_counter
;
182 const char * const mi_lttng_context_type_perf_cpu_counter
;
183 const char * const mi_lttng_context_type_perf_thread_counter
;
184 const char * const mi_lttng_element_track_untrack_pid_target
;
185 const char * const mi_lttng_element_track_untrack_targets
;
186 const char * const mi_lttng_element_calibrate
;
187 const char * const mi_lttng_element_calibrate_function
;
188 const char * const mi_lttng_element_command_calibrate
;
190 /* This is a merge of jul loglevel and regular loglevel
191 * Those should never overlap by definition
192 * (see struct lttng_event loglevel)
195 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
198 case LTTNG_DOMAIN_KERNEL
:
199 case LTTNG_DOMAIN_UST
:
202 return mi_lttng_element_empty
;
203 case LTTNG_LOGLEVEL_EMERG
:
204 return mi_lttng_loglevel_str_emerg
;
205 case LTTNG_LOGLEVEL_ALERT
:
206 return mi_lttng_loglevel_str_alert
;
207 case LTTNG_LOGLEVEL_CRIT
:
208 return mi_lttng_loglevel_str_crit
;
209 case LTTNG_LOGLEVEL_ERR
:
210 return mi_lttng_loglevel_str_err
;
211 case LTTNG_LOGLEVEL_WARNING
:
212 return mi_lttng_loglevel_str_warning
;
213 case LTTNG_LOGLEVEL_NOTICE
:
214 return mi_lttng_loglevel_str_notice
;
215 case LTTNG_LOGLEVEL_INFO
:
216 return mi_lttng_loglevel_str_info
;
217 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
218 return mi_lttng_loglevel_str_debug_system
;
219 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
220 return mi_lttng_loglevel_str_debug_program
;
221 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
222 return mi_lttng_loglevel_str_debug_process
;
223 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
224 return mi_lttng_loglevel_str_debug_module
;
225 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
226 return mi_lttng_loglevel_str_debug_unit
;
227 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
228 return mi_lttng_loglevel_str_debug_function
;
229 case LTTNG_LOGLEVEL_DEBUG_LINE
:
230 return mi_lttng_loglevel_str_debug_line
;
231 case LTTNG_LOGLEVEL_DEBUG
:
232 return mi_lttng_loglevel_str_debug
;
234 return mi_lttng_loglevel_str_unknown
;
237 case LTTNG_DOMAIN_LOG4J
:
240 return mi_lttng_element_empty
;
241 case LTTNG_LOGLEVEL_LOG4J_OFF
:
242 return mi_lttng_loglevel_str_log4j_off
;
243 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
244 return mi_lttng_loglevel_str_log4j_fatal
;
245 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
246 return mi_lttng_loglevel_str_log4j_error
;
247 case LTTNG_LOGLEVEL_LOG4J_WARN
:
248 return mi_lttng_loglevel_str_log4j_warn
;
249 case LTTNG_LOGLEVEL_LOG4J_INFO
:
250 return mi_lttng_loglevel_str_log4j_info
;
251 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
252 return mi_lttng_loglevel_str_log4j_debug
;
253 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
254 return mi_lttng_loglevel_str_log4j_trace
;
255 case LTTNG_LOGLEVEL_LOG4J_ALL
:
256 return mi_lttng_loglevel_str_log4j_all
;
258 return mi_lttng_loglevel_str_unknown
;
261 case LTTNG_DOMAIN_JUL
:
264 return mi_lttng_element_empty
;
265 case LTTNG_LOGLEVEL_JUL_OFF
:
266 return mi_lttng_loglevel_str_jul_off
;
267 case LTTNG_LOGLEVEL_JUL_SEVERE
:
268 return mi_lttng_loglevel_str_jul_severe
;
269 case LTTNG_LOGLEVEL_JUL_WARNING
:
270 return mi_lttng_loglevel_str_jul_warning
;
271 case LTTNG_LOGLEVEL_JUL_INFO
:
272 return mi_lttng_loglevel_str_jul_info
;
273 case LTTNG_LOGLEVEL_JUL_CONFIG
:
274 return mi_lttng_loglevel_str_jul_config
;
275 case LTTNG_LOGLEVEL_JUL_FINE
:
276 return mi_lttng_loglevel_str_jul_fine
;
277 case LTTNG_LOGLEVEL_JUL_FINER
:
278 return mi_lttng_loglevel_str_jul_finer
;
279 case LTTNG_LOGLEVEL_JUL_FINEST
:
280 return mi_lttng_loglevel_str_jul_finest
;
281 case LTTNG_LOGLEVEL_JUL_ALL
:
282 return mi_lttng_loglevel_str_jul_all
;
284 return mi_lttng_loglevel_str_unknown
;
287 case LTTNG_DOMAIN_PYTHON
:
289 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
290 return mi_lttng_loglevel_str_python_critical
;
291 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
292 return mi_lttng_loglevel_str_python_error
;
293 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
294 return mi_lttng_loglevel_str_python_warning
;
295 case LTTNG_LOGLEVEL_PYTHON_INFO
:
296 return mi_lttng_loglevel_str_python_info
;
297 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
298 return mi_lttng_loglevel_str_python_debug
;
299 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
300 return mi_lttng_loglevel_str_python_notset
;
302 return mi_lttng_loglevel_str_unknown
;
306 return mi_lttng_loglevel_str_unknown
;
311 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
314 case LTTNG_EVENT_LOGLEVEL_ALL
:
315 return mi_lttng_loglevel_type_all
;
316 case LTTNG_EVENT_LOGLEVEL_RANGE
:
317 return mi_lttng_loglevel_type_range
;
318 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
319 return mi_lttng_loglevel_type_single
;
321 return mi_lttng_loglevel_type_unknown
;
326 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
329 case LTTNG_EVENT_ALL
:
330 return config_event_type_all
;
331 case LTTNG_EVENT_TRACEPOINT
:
332 return config_event_type_tracepoint
;
333 case LTTNG_EVENT_PROBE
:
334 return config_event_type_probe
;
335 case LTTNG_EVENT_FUNCTION
:
336 return config_event_type_function
;
337 case LTTNG_EVENT_FUNCTION_ENTRY
:
338 return config_event_type_function_entry
;
339 case LTTNG_EVENT_SYSCALL
:
340 return config_event_type_syscall
;
341 case LTTNG_EVENT_NOOP
:
342 return config_event_type_noop
;
344 return mi_lttng_element_empty
;
349 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
352 case LTTNG_EVENT_CONTEXT_PID
:
353 return config_event_context_pid
;
354 case LTTNG_EVENT_CONTEXT_PROCNAME
:
355 return config_event_context_procname
;
356 case LTTNG_EVENT_CONTEXT_PRIO
:
357 return config_event_context_prio
;
358 case LTTNG_EVENT_CONTEXT_NICE
:
359 return config_event_context_nice
;
360 case LTTNG_EVENT_CONTEXT_VPID
:
361 return config_event_context_vpid
;
362 case LTTNG_EVENT_CONTEXT_TID
:
363 return config_event_context_tid
;
364 case LTTNG_EVENT_CONTEXT_VTID
:
365 return config_event_context_vtid
;
366 case LTTNG_EVENT_CONTEXT_PPID
:
367 return config_event_context_ppid
;
368 case LTTNG_EVENT_CONTEXT_VPPID
:
369 return config_event_context_vppid
;
370 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
371 return config_event_context_pthread_id
;
372 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
373 return config_event_context_hostname
;
374 case LTTNG_EVENT_CONTEXT_IP
:
375 return config_event_context_ip
;
382 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
385 case(LTTNG_EVENT_FIELD_INTEGER
):
386 return mi_lttng_element_type_integer
;
387 case(LTTNG_EVENT_FIELD_ENUM
):
388 return mi_lttng_element_type_enum
;
389 case(LTTNG_EVENT_FIELD_FLOAT
):
390 return mi_lttng_element_type_float
;
391 case(LTTNG_EVENT_FIELD_STRING
):
392 return mi_lttng_element_type_string
;
394 return mi_lttng_element_type_other
;
399 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
401 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
403 case LTTNG_DOMAIN_KERNEL
:
404 return config_domain_type_kernel
;
405 case LTTNG_DOMAIN_UST
:
406 return config_domain_type_ust
;
407 case LTTNG_DOMAIN_JUL
:
408 return config_domain_type_jul
;
409 case LTTNG_DOMAIN_LOG4J
:
410 return config_domain_type_log4j
;
411 case LTTNG_DOMAIN_PYTHON
:
412 return config_domain_type_python
;
414 /* Should not have an unknown domain */
421 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
424 case LTTNG_BUFFER_PER_PID
:
425 return config_buffer_type_per_pid
;
426 case LTTNG_BUFFER_PER_UID
:
427 return config_buffer_type_per_uid
;
428 case LTTNG_BUFFER_GLOBAL
:
429 return config_buffer_type_global
;
431 /* Should not have an unknow buffer type */
438 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
440 struct mi_writer
*mi_writer
;
442 mi_writer
= zmalloc(sizeof(struct mi_writer
));
444 PERROR("zmalloc mi_writer_create");
447 if (mi_output_type
== LTTNG_MI_XML
) {
448 mi_writer
->writer
= config_writer_create(fd_output
, 0);
449 if (!mi_writer
->writer
) {
452 mi_writer
->type
= LTTNG_MI_XML
;
466 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
475 ret
= config_writer_destroy(writer
->writer
);
486 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
491 * A command is always the MI's root node, it must declare the current
492 * namespace and schema URIs and the schema's version.
494 ret
= config_writer_open_element(writer
->writer
,
495 mi_lttng_element_command
);
500 ret
= config_writer_write_attribute(writer
->writer
,
501 mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
506 ret
= config_writer_write_attribute(writer
->writer
,
507 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
512 ret
= config_writer_write_attribute(writer
->writer
,
513 mi_lttng_schema_location
,
514 mi_lttng_schema_location_uri
);
519 ret
= config_writer_write_attribute(writer
->writer
,
520 mi_lttng_schema_version
,
521 mi_lttng_schema_version_value
);
526 ret
= mi_lttng_writer_write_element_string(writer
,
527 mi_lttng_element_command_name
, command
);
533 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
535 return mi_lttng_writer_close_element(writer
);
539 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
540 const char *element_name
)
542 return config_writer_open_element(writer
->writer
, element_name
);
546 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
548 return config_writer_close_element(writer
->writer
);
552 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
553 unsigned int nb_element
)
557 if (nb_element
< 1) {
561 for (i
= 0; i
< nb_element
; i
++) {
562 ret
= mi_lttng_writer_close_element(writer
);
572 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
573 const char *element_name
, uint64_t value
)
575 return config_writer_write_element_unsigned_int(writer
->writer
,
576 element_name
, value
);
580 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
581 const char *element_name
, int64_t value
)
583 return config_writer_write_element_signed_int(writer
->writer
,
584 element_name
, value
);
588 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
589 const char *element_name
, int value
)
591 return config_writer_write_element_bool(writer
->writer
,
592 element_name
, value
);
596 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
597 const char *element_name
, const char *value
)
599 return config_writer_write_element_string(writer
->writer
,
600 element_name
, value
);
604 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
605 const char *lttng_description
, const char *lttng_license
)
610 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
615 /* Version string (contain info like rc etc.) */
616 ret
= mi_lttng_writer_write_element_string(writer
,
617 mi_lttng_element_version_str
, version
->version
);
622 /* Major version number */
623 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
624 mi_lttng_element_version_major
, version
->version_major
);
629 /* Minor version number */
630 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
631 mi_lttng_element_version_minor
, version
->version_minor
);
636 /* Commit version number */
637 ret
= mi_lttng_writer_write_element_string(writer
,
638 mi_lttng_element_version_commit
, version
->version_commit
);
644 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
645 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
650 /* Name of the version */
651 ret
= mi_lttng_writer_write_element_string(writer
,
652 config_element_name
, version
->version_name
);
657 /* Description mostly related to beer... */
658 ret
= mi_lttng_writer_write_element_string(writer
,
659 mi_lttng_element_version_description
, lttng_description
);
665 ret
= mi_lttng_writer_write_element_string(writer
,
666 mi_lttng_element_version_web
, version
->package_url
);
671 /* License: free as in free beer...no...*speech* */
672 ret
= mi_lttng_writer_write_element_string(writer
,
673 mi_lttng_element_version_license
, lttng_license
);
678 /* Close version element */
679 ret
= mi_lttng_writer_close_element(writer
);
686 int mi_lttng_sessions_open(struct mi_writer
*writer
)
688 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
692 int mi_lttng_session(struct mi_writer
*writer
,
693 struct lttng_session
*session
, int is_open
)
699 /* Open sessions element */
700 ret
= mi_lttng_writer_open_element(writer
,
701 config_element_session
);
706 /* Name of the session */
707 ret
= mi_lttng_writer_write_element_string(writer
,
708 config_element_name
, session
->name
);
714 ret
= mi_lttng_writer_write_element_string(writer
,
715 config_element_path
, session
->path
);
721 ret
= mi_lttng_writer_write_element_bool(writer
,
722 config_element_enabled
, session
->enabled
);
728 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
729 config_element_snapshot_mode
, session
->snapshot_mode
);
734 /* Live timer interval in usec */
735 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
736 config_element_live_timer_interval
,
737 session
->live_timer_interval
);
743 /* Closing session element */
744 ret
= mi_lttng_writer_close_element(writer
);
752 int mi_lttng_domains_open(struct mi_writer
*writer
)
754 return mi_lttng_writer_open_element(writer
, config_element_domains
);
758 int mi_lttng_domain(struct mi_writer
*writer
,
759 struct lttng_domain
*domain
, int is_open
)
762 const char *str_domain
;
763 const char *str_buffer
;
767 /* Open domain element */
768 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
774 str_domain
= mi_lttng_domaintype_string(domain
->type
);
775 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
782 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
783 ret
= mi_lttng_writer_write_element_string(writer
,
784 config_element_buffer_type
, str_buffer
);
790 * This union is not currently used and was added for
791 * future ust domain support.
796 /* Closing domain element */
797 ret
= mi_lttng_writer_close_element(writer
);
806 int mi_lttng_channels_open(struct mi_writer
*writer
)
808 return mi_lttng_writer_open_element(writer
, config_element_channels
);
812 int mi_lttng_channel(struct mi_writer
*writer
,
813 struct lttng_channel
*channel
, int is_open
)
819 /* Opening channel element */
820 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
826 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
833 ret
= mi_lttng_writer_write_element_bool(writer
,
834 config_element_enabled
, channel
->enabled
);
840 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
846 /* Closing channel element */
847 ret
= mi_lttng_writer_close_element(writer
);
857 int mi_lttng_channel_attr(struct mi_writer
*writer
,
858 struct lttng_channel_attr
*attr
)
861 struct lttng_channel
*chan
= caa_container_of(attr
,
862 struct lttng_channel
, attr
);
863 uint64_t discarded_events
, lost_packets
;
867 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
872 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
877 /* Opening Attributes */
878 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
884 ret
= mi_lttng_writer_write_element_string(writer
,
885 config_element_overwrite_mode
,
886 attr
->overwrite
? config_overwrite_mode_overwrite
:
887 config_overwrite_mode_discard
);
892 /* Sub buffer size in byte */
893 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
894 config_element_subbuf_size
, attr
->subbuf_size
);
899 /* Number of subbuffer (power of two) */
900 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
901 config_element_num_subbuf
,
907 /* Switch timer interval in usec */
908 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
909 config_element_switch_timer_interval
,
910 attr
->switch_timer_interval
);
915 /* Read timer interval in usec */
916 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
917 config_element_read_timer_interval
,
918 attr
->read_timer_interval
);
924 ret
= mi_lttng_writer_write_element_string(writer
,
925 config_element_output_type
,
926 attr
->output
== LTTNG_EVENT_SPLICE
?
927 config_output_type_splice
: config_output_type_mmap
);
932 /* Tracefile size in bytes */
933 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
934 config_element_tracefile_size
, attr
->tracefile_size
);
939 /* Count of tracefiles */
940 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
941 config_element_tracefile_count
,
942 attr
->tracefile_count
);
947 /* Live timer interval in usec*/
948 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
949 config_element_live_timer_interval
,
950 attr
->live_timer_interval
);
955 /* Discarded events */
956 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
957 config_element_discarded_events
,
964 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
965 config_element_lost_packets
,
971 /* Closing attributes */
972 ret
= mi_lttng_writer_close_element(writer
);
982 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
983 struct lttng_event
*event
)
986 const char *filter_expression
;
988 /* Open event element */
989 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
995 ret
= mi_lttng_writer_write_element_string(writer
,
996 config_element_name
, event
->name
);
1002 ret
= mi_lttng_writer_write_element_string(writer
,
1003 config_element_type
, mi_lttng_eventtype_string(event
->type
));
1008 /* Is event enabled */
1009 ret
= mi_lttng_writer_write_element_bool(writer
,
1010 config_element_enabled
, event
->enabled
);
1015 /* Event filter expression */
1016 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1021 if (filter_expression
) {
1022 ret
= mi_lttng_writer_write_element_string(writer
,
1023 config_element_filter_expression
,
1034 static int write_event_exclusions(struct mi_writer
*writer
,
1035 struct lttng_event
*event
)
1039 int exclusion_count
;
1041 /* Open event exclusions */
1042 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1047 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1048 if (exclusion_count
< 0) {
1049 ret
= exclusion_count
;
1053 for (i
= 0; i
< exclusion_count
; i
++) {
1056 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1058 /* Close exclusions */
1059 mi_lttng_writer_close_element(writer
);
1063 ret
= mi_lttng_writer_write_element_string(writer
,
1064 config_element_exclusion
, name
);
1066 /* Close exclusions */
1067 mi_lttng_writer_close_element(writer
);
1072 /* Close exclusions */
1073 ret
= mi_lttng_writer_close_element(writer
);
1080 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1081 struct lttng_event
*event
, enum lttng_domain_type domain
)
1085 /* Event loglevel */
1086 ret
= mi_lttng_writer_write_element_string(writer
,
1087 config_element_loglevel
,
1088 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1093 /* Log level type */
1094 ret
= mi_lttng_writer_write_element_string(writer
,
1095 config_element_loglevel_type
,
1096 mi_lttng_logleveltype_string(event
->loglevel_type
));
1101 /* Event exclusions */
1102 ret
= write_event_exclusions(writer
, event
);
1109 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1110 struct lttng_event
*event
)
1112 /* event exclusion filter */
1113 return write_event_exclusions(writer
, event
);
1117 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1118 struct lttng_event
*event
)
1122 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1127 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1132 if (event
->attr
.probe
.addr
!= 0) {
1133 /* event probe address */
1134 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1135 config_element_address
, event
->attr
.probe
.addr
);
1140 /* event probe offset */
1141 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1142 config_element_offset
, event
->attr
.probe
.offset
);
1147 /* event probe symbol_name */
1148 ret
= mi_lttng_writer_write_element_string(writer
,
1149 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1155 /* Close probe_attributes and attributes */
1156 ret
= mi_lttng_close_multi_element(writer
, 2);
1162 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1163 struct lttng_event
*event
)
1167 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1172 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1177 /* event probe symbol_name */
1178 ret
= mi_lttng_writer_write_element_string(writer
,
1179 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1184 /* Close function_attributes and attributes */
1185 ret
= mi_lttng_close_multi_element(writer
, 2);
1191 int mi_lttng_events_open(struct mi_writer
*writer
)
1193 return mi_lttng_writer_open_element(writer
, config_element_events
);
1197 int mi_lttng_event(struct mi_writer
*writer
,
1198 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1202 ret
= mi_lttng_event_common_attributes(writer
, event
);
1207 switch (event
->type
) {
1208 case LTTNG_EVENT_TRACEPOINT
:
1210 if (event
->loglevel
!= -1) {
1211 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1213 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1217 case LTTNG_EVENT_FUNCTION
:
1219 case LTTNG_EVENT_PROBE
:
1220 ret
= mi_lttng_event_function_probe(writer
, event
);
1222 case LTTNG_EVENT_FUNCTION_ENTRY
:
1223 ret
= mi_lttng_event_function_entry(writer
, event
);
1225 case LTTNG_EVENT_ALL
:
1232 ret
= mi_lttng_writer_close_element(writer
);
1240 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1242 return mi_lttng_writer_open_element(writer
, config_element_trackers
);
1246 int mi_lttng_pid_tracker_open(struct mi_writer
*writer
)
1250 /* Open element pid_tracker */
1251 ret
= mi_lttng_writer_open_element(writer
, config_element_pid_tracker
);
1256 /* Open targets element */
1257 ret
= mi_lttng_targets_open(writer
);
1263 int mi_lttng_pids_open(struct mi_writer
*writer
)
1265 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1269 * TODO: move the listing of pid for user agent to process semantic on
1270 * mi api bump. The use of process element break the mi api.
1273 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *name
,
1278 /* Open pid process */
1279 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1284 /* Writing pid number */
1285 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1286 mi_lttng_element_pid_id
, (int)pid
);
1291 /* Writing name of the process */
1293 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1302 ret
= mi_lttng_writer_close_element(writer
);
1310 int mi_lttng_targets_open(struct mi_writer
*writer
)
1312 return mi_lttng_writer_open_element(writer
,
1313 config_element_targets
);
1317 int mi_lttng_pid_target(struct mi_writer
*writer
, pid_t pid
, int is_open
)
1321 ret
= mi_lttng_writer_open_element(writer
,
1322 config_element_target_pid
);
1327 /* Writing pid number
1328 * Special case for element all on track untrack command
1329 * All pid is represented as wildcard *
1331 if ((int) pid
== -1) {
1332 ret
= mi_lttng_writer_write_element_string(writer
,
1334 mi_lttng_element_track_untrack_all_wildcard
);
1336 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1337 config_element_pid
, (int) pid
);
1344 ret
= mi_lttng_writer_close_element(writer
);
1355 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1357 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1361 int mi_lttng_event_field(struct mi_writer
*writer
,
1362 struct lttng_event_field
*field
)
1366 if (!field
->field_name
[0]) {
1372 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1377 if (!field
->field_name
[0]) {
1382 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1389 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1390 mi_lttng_eventfieldtype_string(field
->type
));
1396 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1397 mi_lttng_element_nowrite
, field
->nowrite
);
1403 /* Close field element */
1404 ret
= mi_lttng_writer_close_element(writer
);
1411 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1412 struct lttng_event_perf_counter_ctx
*perf_context
)
1416 /* Open perf_counter_context */
1417 ret
= mi_lttng_writer_open_element(writer
,
1418 mi_lttng_element_perf_counter_context
);
1424 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1425 config_element_type
, perf_context
->type
);
1431 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1432 config_element_config
, perf_context
->config
);
1437 /* Name of the perf counter */
1438 ret
= mi_lttng_writer_write_element_string(writer
,
1439 config_element_name
, perf_context
->name
);
1444 /* Close perf_counter_context */
1445 ret
= mi_lttng_writer_close_element(writer
);
1451 int mi_lttng_app_context(struct mi_writer
*writer
,
1452 const char *provider_name
, const char *ctx_name
)
1457 ret
= mi_lttng_writer_open_element(writer
,
1458 config_element_context_app
);
1464 ret
= mi_lttng_writer_write_element_string(writer
,
1465 config_element_context_app_provider_name
,
1472 ret
= mi_lttng_writer_write_element_string(writer
,
1473 config_element_context_app_ctx_name
, ctx_name
);
1479 ret
= mi_lttng_writer_close_element(writer
);
1485 int mi_lttng_context(struct mi_writer
*writer
,
1486 struct lttng_event_context
*context
, int is_open
)
1491 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1496 /* Special case for PERF_*_COUNTER
1497 * print the lttng_event_perf_counter_ctx*/
1498 switch (context
->ctx
) {
1499 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1500 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1501 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1503 struct lttng_event_perf_counter_ctx
*perf_context
=
1504 &context
->u
.perf_counter
;
1505 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1511 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
1513 ret
= mi_lttng_app_context(writer
,
1514 context
->u
.app_ctx
.provider_name
,
1515 context
->u
.app_ctx
.ctx_name
);
1523 const char *type_string
= mi_lttng_event_contexttype_string(
1526 ret
= -LTTNG_ERR_INVALID
;
1530 /* Print context type */
1531 ret
= mi_lttng_writer_write_element_string(writer
,
1532 config_element_type
, type_string
);
1539 ret
= mi_lttng_writer_close_element(writer
);
1547 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1548 const char *session_name
)
1552 /* Open session element */
1553 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1558 /* Snapshot output list for current session name */
1559 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1565 /* Open element snapshots (sequence one snapshot) */
1566 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1576 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1577 struct lttng_snapshot_output
*output
)
1581 /* Open element snapshot output */
1582 ret
= mi_lttng_writer_open_element(writer
,
1583 mi_lttng_element_command_snapshot
);
1588 /* ID of the snapshot output */
1589 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1590 mi_lttng_element_id
, output
->id
);
1595 /* Name of the output */
1596 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1602 /* Destination of the output (ctrl_url)*/
1603 ret
= mi_lttng_writer_write_element_string(writer
,
1604 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1609 /* Destination of the output (data_url) */
1610 ret
= mi_lttng_writer_write_element_string(writer
,
1611 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1616 /* total size of all stream combined */
1617 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1618 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1623 /* Close snapshot output element */
1624 ret
= mi_lttng_writer_close_element(writer
);
1631 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1632 const char *name
, const char *current_session_name
)
1636 /* Open element del_snapshot */
1637 ret
= mi_lttng_writer_open_element(writer
,
1638 mi_lttng_element_command_snapshot
);
1644 if (id
!= UINT32_MAX
) {
1645 /* "Snapshot output "id" successfully deleted
1646 * for "current_session_name"
1647 * ID of the snapshot output
1649 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1650 mi_lttng_element_id
, id
);
1655 /* "Snapshot output "name" successfully deleted
1656 * for session "current_session_name"
1657 * Name of the output
1659 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1666 /* Snapshot was deleted for session "current_session_name"*/
1667 ret
= mi_lttng_writer_write_element_string(writer
,
1668 mi_lttng_element_snapshot_session_name
,
1669 current_session_name
);
1674 /* Close snapshot element */
1675 ret
= mi_lttng_writer_close_element(writer
);
1682 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1683 const char *current_session_name
, const char *n_ptr
,
1684 struct lttng_snapshot_output
*output
)
1688 /* Open element snapshot */
1689 ret
= mi_lttng_writer_open_element(writer
,
1690 mi_lttng_element_command_snapshot
);
1695 /* Snapshot output id */
1696 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1697 mi_lttng_element_id
, output
->id
);
1702 /* Snapshot output names */
1703 ret
= mi_lttng_writer_write_element_string(writer
,
1704 config_element_name
, n_ptr
);
1709 /* Destination of the output (ctrl_url)*/
1710 ret
= mi_lttng_writer_write_element_string(writer
,
1711 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1716 /* Snapshot added for session "current_session_name"*/
1717 ret
= mi_lttng_writer_write_element_string(writer
,
1718 mi_lttng_element_snapshot_session_name
, current_session_name
);
1723 /* total size of all stream combined */
1724 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1725 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1730 /* Close snapshot element */
1731 ret
= mi_lttng_writer_close_element(writer
);
1738 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1739 const char *current_session_name
, const char *url
,
1740 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1744 /* Open element snapshot */
1745 ret
= mi_lttng_writer_open_element(writer
,
1746 mi_lttng_element_command_snapshot
);
1752 * If a valid an URL was given, serialize it,
1753 * else take the command line data and ctrl urls*/
1755 /* Destination of the output (ctrl_url)*/
1756 ret
= mi_lttng_writer_write_element_string(writer
,
1757 mi_lttng_element_snapshot_ctrl_url
, url
);
1761 } else if (cmdline_ctrl_url
) {
1762 /* Destination of the output (ctrl_url)*/
1763 ret
= mi_lttng_writer_write_element_string(writer
,
1764 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1769 /* Destination of the output (data_url) */
1770 ret
= mi_lttng_writer_write_element_string(writer
,
1771 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1777 /* Close record_snapshot element */
1778 ret
= mi_lttng_writer_close_element(writer
);