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 const char * const mi_lttng_xmlns
= "xmlns";
34 const char * const mi_lttng_xmlns_xsi
= "xmlns:xsi";
35 const char * const mi_lttng_w3_schema_uri
= "http://www.w3.org/2001/XMLSchema-instance";
36 const char * const mi_lttng_schema_location
= "xsi:schemaLocation";
37 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 const char * const mi_lttng_schema_version
= "schemaVersion";
43 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_calibrate
= "calibrate";
51 const char * const mi_lttng_element_command_create
= "create";
52 const char * const mi_lttng_element_command_destroy
= "destroy";
53 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
54 const char * const mi_lttng_element_command_disable_event
= "disable-event";
55 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
56 const char * const mi_lttng_element_command_enable_event
= "enable-event";
57 const char * const mi_lttng_element_command_list
= "list";
58 const char * const mi_lttng_element_command_load
= "load";
59 const char * const mi_lttng_element_command_name
= "name";
60 const char * const mi_lttng_element_command_output
= "output";
61 const char * const mi_lttng_element_command_save
= "save";
62 const char * const mi_lttng_element_command_set_session
= "set-session";
63 const char * const mi_lttng_element_command_snapshot
= "snapshot";
64 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
65 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
66 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
67 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
68 const char * const mi_lttng_element_command_start
= "start";
69 const char * const mi_lttng_element_command_stop
= "stop";
70 const char * const mi_lttng_element_command_success
= "success";
71 const char * const mi_lttng_element_command_track
= "track";
72 const char * const mi_lttng_element_command_untrack
= "untrack";
73 const char * const mi_lttng_element_command_version
= "version";
75 /* Strings related to version command */
76 const char * const mi_lttng_element_version
= "version";
77 const char * const mi_lttng_element_version_commit
= "commit";
78 const char * const mi_lttng_element_version_description
= "description";
79 const char * const mi_lttng_element_version_license
= "license";
80 const char * const mi_lttng_element_version_major
= "major";
81 const char * const mi_lttng_element_version_minor
= "minor";
82 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
83 const char * const mi_lttng_element_version_str
= "string";
84 const char * const mi_lttng_element_version_web
= "url";
86 /* String related to a lttng_event_field */
87 const char * const mi_lttng_element_event_field
= "event_field";
88 const char * const mi_lttng_element_event_fields
= "event_fields";
90 /* String related to lttng_event_perf_counter_ctx */
91 const char * const mi_lttng_element_perf_counter_context
= "perf";
93 /* Strings related to pid */
94 const char * const mi_lttng_element_pid_id
= "id";
96 /* Strings related to save command */
97 const char * const mi_lttng_element_save
= "save";
99 /* Strings related to load command */
100 const char * const mi_lttng_element_load
= "load";
102 /* General elements of mi_lttng */
103 const char * const mi_lttng_element_empty
= "";
104 const char * const mi_lttng_element_id
= "id";
105 const char * const mi_lttng_element_nowrite
= "nowrite";
106 const char * const mi_lttng_element_success
= "success";
107 const char * const mi_lttng_element_type_enum
= "ENUM";
108 const char * const mi_lttng_element_type_float
= "FLOAT";
109 const char * const mi_lttng_element_type_integer
= "INTEGER";
110 const char * const mi_lttng_element_type_other
= "OTHER";
111 const char * const mi_lttng_element_type_string
= "STRING";
113 /* String related to loglevel */
114 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
115 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
116 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
117 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
118 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
119 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
120 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
121 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
122 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
123 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
124 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
125 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
126 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
127 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
128 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
129 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
131 /* String related to loglevel JUL */
132 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
133 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
134 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
135 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
136 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
137 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
138 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
139 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
140 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
142 /* String related to loglevel LOG4J */
143 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
144 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
145 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
146 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
147 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
148 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
149 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
150 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
152 /* String related to loglevel Python */
153 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
154 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
155 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
156 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
157 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
158 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
160 /* String related to loglevel type */
161 const char * const mi_lttng_loglevel_type_all
= "ALL";
162 const char * const mi_lttng_loglevel_type_range
= "RANGE";
163 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
164 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
166 /* String related to lttng_calibrate */
167 const char * const mi_lttng_element_calibrate
= "calibrate";
168 const char * const mi_lttng_element_calibrate_function
= "FUNCTION";
170 /* String related to a lttng_snapshot_output */
171 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
172 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
173 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
174 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
175 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
176 const char * const mi_lttng_element_snapshots
= "snapshots";
178 /* String related to track/untrack command */
179 const char * const mi_lttng_element_track_untrack_all_wildcard
= "*";
182 /* This is a merge of jul loglevel and regular loglevel
183 * Those should never overlap by definition
184 * (see struct lttng_event loglevel)
187 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
190 case LTTNG_DOMAIN_KERNEL
:
191 case LTTNG_DOMAIN_UST
:
194 return mi_lttng_element_empty
;
195 case LTTNG_LOGLEVEL_EMERG
:
196 return mi_lttng_loglevel_str_emerg
;
197 case LTTNG_LOGLEVEL_ALERT
:
198 return mi_lttng_loglevel_str_alert
;
199 case LTTNG_LOGLEVEL_CRIT
:
200 return mi_lttng_loglevel_str_crit
;
201 case LTTNG_LOGLEVEL_ERR
:
202 return mi_lttng_loglevel_str_err
;
203 case LTTNG_LOGLEVEL_WARNING
:
204 return mi_lttng_loglevel_str_warning
;
205 case LTTNG_LOGLEVEL_NOTICE
:
206 return mi_lttng_loglevel_str_notice
;
207 case LTTNG_LOGLEVEL_INFO
:
208 return mi_lttng_loglevel_str_info
;
209 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
210 return mi_lttng_loglevel_str_debug_system
;
211 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
212 return mi_lttng_loglevel_str_debug_program
;
213 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
214 return mi_lttng_loglevel_str_debug_process
;
215 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
216 return mi_lttng_loglevel_str_debug_module
;
217 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
218 return mi_lttng_loglevel_str_debug_unit
;
219 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
220 return mi_lttng_loglevel_str_debug_function
;
221 case LTTNG_LOGLEVEL_DEBUG_LINE
:
222 return mi_lttng_loglevel_str_debug_line
;
223 case LTTNG_LOGLEVEL_DEBUG
:
224 return mi_lttng_loglevel_str_debug
;
226 return mi_lttng_loglevel_str_unknown
;
229 case LTTNG_DOMAIN_LOG4J
:
232 return mi_lttng_element_empty
;
233 case LTTNG_LOGLEVEL_LOG4J_OFF
:
234 return mi_lttng_loglevel_str_log4j_off
;
235 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
236 return mi_lttng_loglevel_str_log4j_fatal
;
237 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
238 return mi_lttng_loglevel_str_log4j_error
;
239 case LTTNG_LOGLEVEL_LOG4J_WARN
:
240 return mi_lttng_loglevel_str_log4j_warn
;
241 case LTTNG_LOGLEVEL_LOG4J_INFO
:
242 return mi_lttng_loglevel_str_log4j_info
;
243 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
244 return mi_lttng_loglevel_str_log4j_debug
;
245 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
246 return mi_lttng_loglevel_str_log4j_trace
;
247 case LTTNG_LOGLEVEL_LOG4J_ALL
:
248 return mi_lttng_loglevel_str_log4j_all
;
250 return mi_lttng_loglevel_str_unknown
;
253 case LTTNG_DOMAIN_JUL
:
256 return mi_lttng_element_empty
;
257 case LTTNG_LOGLEVEL_JUL_OFF
:
258 return mi_lttng_loglevel_str_jul_off
;
259 case LTTNG_LOGLEVEL_JUL_SEVERE
:
260 return mi_lttng_loglevel_str_jul_severe
;
261 case LTTNG_LOGLEVEL_JUL_WARNING
:
262 return mi_lttng_loglevel_str_jul_warning
;
263 case LTTNG_LOGLEVEL_JUL_INFO
:
264 return mi_lttng_loglevel_str_jul_info
;
265 case LTTNG_LOGLEVEL_JUL_CONFIG
:
266 return mi_lttng_loglevel_str_jul_config
;
267 case LTTNG_LOGLEVEL_JUL_FINE
:
268 return mi_lttng_loglevel_str_jul_fine
;
269 case LTTNG_LOGLEVEL_JUL_FINER
:
270 return mi_lttng_loglevel_str_jul_finer
;
271 case LTTNG_LOGLEVEL_JUL_FINEST
:
272 return mi_lttng_loglevel_str_jul_finest
;
273 case LTTNG_LOGLEVEL_JUL_ALL
:
274 return mi_lttng_loglevel_str_jul_all
;
276 return mi_lttng_loglevel_str_unknown
;
279 case LTTNG_DOMAIN_PYTHON
:
281 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
282 return mi_lttng_loglevel_str_python_critical
;
283 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
284 return mi_lttng_loglevel_str_python_error
;
285 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
286 return mi_lttng_loglevel_str_python_warning
;
287 case LTTNG_LOGLEVEL_PYTHON_INFO
:
288 return mi_lttng_loglevel_str_python_info
;
289 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
290 return mi_lttng_loglevel_str_python_debug
;
291 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
292 return mi_lttng_loglevel_str_python_notset
;
294 return mi_lttng_loglevel_str_unknown
;
299 /* Reaching this means the domain is unknown. */
300 return mi_lttng_loglevel_str_unknown
;
304 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
307 case LTTNG_EVENT_LOGLEVEL_ALL
:
308 return mi_lttng_loglevel_type_all
;
309 case LTTNG_EVENT_LOGLEVEL_RANGE
:
310 return mi_lttng_loglevel_type_range
;
311 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
312 return mi_lttng_loglevel_type_single
;
314 return mi_lttng_loglevel_type_unknown
;
319 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
322 case LTTNG_EVENT_ALL
:
323 return config_event_type_all
;
324 case LTTNG_EVENT_TRACEPOINT
:
325 return config_event_type_tracepoint
;
326 case LTTNG_EVENT_PROBE
:
327 return config_event_type_probe
;
328 case LTTNG_EVENT_FUNCTION
:
329 return config_event_type_function
;
330 case LTTNG_EVENT_FUNCTION_ENTRY
:
331 return config_event_type_function_entry
;
332 case LTTNG_EVENT_SYSCALL
:
333 return config_event_type_syscall
;
334 case LTTNG_EVENT_NOOP
:
335 return config_event_type_noop
;
337 return mi_lttng_element_empty
;
342 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
345 case LTTNG_EVENT_CONTEXT_PID
:
346 return config_event_context_pid
;
347 case LTTNG_EVENT_CONTEXT_PROCNAME
:
348 return config_event_context_procname
;
349 case LTTNG_EVENT_CONTEXT_PRIO
:
350 return config_event_context_prio
;
351 case LTTNG_EVENT_CONTEXT_NICE
:
352 return config_event_context_nice
;
353 case LTTNG_EVENT_CONTEXT_VPID
:
354 return config_event_context_vpid
;
355 case LTTNG_EVENT_CONTEXT_TID
:
356 return config_event_context_tid
;
357 case LTTNG_EVENT_CONTEXT_VTID
:
358 return config_event_context_vtid
;
359 case LTTNG_EVENT_CONTEXT_PPID
:
360 return config_event_context_ppid
;
361 case LTTNG_EVENT_CONTEXT_VPPID
:
362 return config_event_context_vppid
;
363 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
364 return config_event_context_pthread_id
;
365 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
366 return config_event_context_hostname
;
367 case LTTNG_EVENT_CONTEXT_IP
:
368 return config_event_context_ip
;
375 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
378 case(LTTNG_EVENT_FIELD_INTEGER
):
379 return mi_lttng_element_type_integer
;
380 case(LTTNG_EVENT_FIELD_ENUM
):
381 return mi_lttng_element_type_enum
;
382 case(LTTNG_EVENT_FIELD_FLOAT
):
383 return mi_lttng_element_type_float
;
384 case(LTTNG_EVENT_FIELD_STRING
):
385 return mi_lttng_element_type_string
;
387 return mi_lttng_element_type_other
;
392 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
394 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
396 case LTTNG_DOMAIN_KERNEL
:
397 return config_domain_type_kernel
;
398 case LTTNG_DOMAIN_UST
:
399 return config_domain_type_ust
;
400 case LTTNG_DOMAIN_JUL
:
401 return config_domain_type_jul
;
402 case LTTNG_DOMAIN_LOG4J
:
403 return config_domain_type_log4j
;
404 case LTTNG_DOMAIN_PYTHON
:
405 return config_domain_type_python
;
407 /* Should not have an unknown domain */
414 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
417 case LTTNG_BUFFER_PER_PID
:
418 return config_buffer_type_per_pid
;
419 case LTTNG_BUFFER_PER_UID
:
420 return config_buffer_type_per_uid
;
421 case LTTNG_BUFFER_GLOBAL
:
422 return config_buffer_type_global
;
424 /* Should not have an unknow buffer type */
431 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
)
436 case LTTNG_CALIBRATE_FUNCTION
:
437 ret
= mi_lttng_element_calibrate_function
;
440 ret
= mi_lttng_element_empty
;
447 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
449 struct mi_writer
*mi_writer
;
451 mi_writer
= zmalloc(sizeof(struct mi_writer
));
453 PERROR("zmalloc mi_writer_create");
456 if (mi_output_type
== LTTNG_MI_XML
) {
457 mi_writer
->writer
= config_writer_create(fd_output
, 0);
458 if (!mi_writer
->writer
) {
461 mi_writer
->type
= LTTNG_MI_XML
;
475 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
484 ret
= config_writer_destroy(writer
->writer
);
495 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
500 * A command is always the MI's root node, it must declare the current
501 * namespace and schema URIs and the schema's version.
503 ret
= config_writer_open_element(writer
->writer
,
504 mi_lttng_element_command
);
509 ret
= config_writer_write_attribute(writer
->writer
,
510 mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
515 ret
= config_writer_write_attribute(writer
->writer
,
516 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
521 ret
= config_writer_write_attribute(writer
->writer
,
522 mi_lttng_schema_location
,
523 mi_lttng_schema_location_uri
);
528 ret
= config_writer_write_attribute(writer
->writer
,
529 mi_lttng_schema_version
,
530 mi_lttng_schema_version_value
);
535 ret
= mi_lttng_writer_write_element_string(writer
,
536 mi_lttng_element_command_name
, command
);
542 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
544 return mi_lttng_writer_close_element(writer
);
548 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
549 const char *element_name
)
551 return config_writer_open_element(writer
->writer
, element_name
);
555 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
557 return config_writer_close_element(writer
->writer
);
561 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
562 unsigned int nb_element
)
566 if (nb_element
< 1) {
570 for (i
= 0; i
< nb_element
; i
++) {
571 ret
= mi_lttng_writer_close_element(writer
);
581 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
582 const char *element_name
, uint64_t value
)
584 return config_writer_write_element_unsigned_int(writer
->writer
,
585 element_name
, value
);
589 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
590 const char *element_name
, int64_t value
)
592 return config_writer_write_element_signed_int(writer
->writer
,
593 element_name
, value
);
597 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
598 const char *element_name
, int value
)
600 return config_writer_write_element_bool(writer
->writer
,
601 element_name
, value
);
605 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
606 const char *element_name
, const char *value
)
608 return config_writer_write_element_string(writer
->writer
,
609 element_name
, value
);
613 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
614 const char *lttng_description
, const char *lttng_license
)
619 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
624 /* Version string (contain info like rc etc.) */
625 ret
= mi_lttng_writer_write_element_string(writer
,
626 mi_lttng_element_version_str
, version
->version
);
631 /* Major version number */
632 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
633 mi_lttng_element_version_major
, version
->version_major
);
638 /* Minor version number */
639 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
640 mi_lttng_element_version_minor
, version
->version_minor
);
645 /* Commit version number */
646 ret
= mi_lttng_writer_write_element_string(writer
,
647 mi_lttng_element_version_commit
, version
->version_commit
);
653 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
654 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
659 /* Name of the version */
660 ret
= mi_lttng_writer_write_element_string(writer
,
661 config_element_name
, version
->version_name
);
666 /* Description mostly related to beer... */
667 ret
= mi_lttng_writer_write_element_string(writer
,
668 mi_lttng_element_version_description
, lttng_description
);
674 ret
= mi_lttng_writer_write_element_string(writer
,
675 mi_lttng_element_version_web
, version
->package_url
);
680 /* License: free as in free beer...no...*speech* */
681 ret
= mi_lttng_writer_write_element_string(writer
,
682 mi_lttng_element_version_license
, lttng_license
);
687 /* Close version element */
688 ret
= mi_lttng_writer_close_element(writer
);
695 int mi_lttng_sessions_open(struct mi_writer
*writer
)
697 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
701 int mi_lttng_session(struct mi_writer
*writer
,
702 struct lttng_session
*session
, int is_open
)
708 /* Open sessions element */
709 ret
= mi_lttng_writer_open_element(writer
,
710 config_element_session
);
715 /* Name of the session */
716 ret
= mi_lttng_writer_write_element_string(writer
,
717 config_element_name
, session
->name
);
723 ret
= mi_lttng_writer_write_element_string(writer
,
724 config_element_path
, session
->path
);
730 ret
= mi_lttng_writer_write_element_bool(writer
,
731 config_element_enabled
, session
->enabled
);
737 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
738 config_element_snapshot_mode
, session
->snapshot_mode
);
743 /* Live timer interval in usec */
744 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
745 config_element_live_timer_interval
,
746 session
->live_timer_interval
);
752 /* Closing session element */
753 ret
= mi_lttng_writer_close_element(writer
);
761 int mi_lttng_domains_open(struct mi_writer
*writer
)
763 return mi_lttng_writer_open_element(writer
, config_element_domains
);
767 int mi_lttng_domain(struct mi_writer
*writer
,
768 struct lttng_domain
*domain
, int is_open
)
771 const char *str_domain
;
772 const char *str_buffer
;
776 /* Open domain element */
777 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
783 str_domain
= mi_lttng_domaintype_string(domain
->type
);
784 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
791 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
792 ret
= mi_lttng_writer_write_element_string(writer
,
793 config_element_buffer_type
, str_buffer
);
799 * This union is not currently used and was added for
800 * future ust domain support.
805 /* Closing domain element */
806 ret
= mi_lttng_writer_close_element(writer
);
815 int mi_lttng_channels_open(struct mi_writer
*writer
)
817 return mi_lttng_writer_open_element(writer
, config_element_channels
);
821 int mi_lttng_channel(struct mi_writer
*writer
,
822 struct lttng_channel
*channel
, int is_open
)
828 /* Opening channel element */
829 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
835 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
842 ret
= mi_lttng_writer_write_element_bool(writer
,
843 config_element_enabled
, channel
->enabled
);
849 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
855 /* Closing channel element */
856 ret
= mi_lttng_writer_close_element(writer
);
866 int mi_lttng_channel_attr(struct mi_writer
*writer
,
867 struct lttng_channel_attr
*attr
)
870 struct lttng_channel
*chan
= caa_container_of(attr
,
871 struct lttng_channel
, attr
);
872 uint64_t discarded_events
, lost_packets
;
876 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
881 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
886 /* Opening Attributes */
887 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
893 ret
= mi_lttng_writer_write_element_string(writer
,
894 config_element_overwrite_mode
,
895 attr
->overwrite
? config_overwrite_mode_overwrite
:
896 config_overwrite_mode_discard
);
901 /* Sub buffer size in byte */
902 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
903 config_element_subbuf_size
, attr
->subbuf_size
);
908 /* Number of subbuffer (power of two) */
909 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
910 config_element_num_subbuf
,
916 /* Switch timer interval in usec */
917 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
918 config_element_switch_timer_interval
,
919 attr
->switch_timer_interval
);
924 /* Read timer interval in usec */
925 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
926 config_element_read_timer_interval
,
927 attr
->read_timer_interval
);
933 ret
= mi_lttng_writer_write_element_string(writer
,
934 config_element_output_type
,
935 attr
->output
== LTTNG_EVENT_SPLICE
?
936 config_output_type_splice
: config_output_type_mmap
);
941 /* Tracefile size in bytes */
942 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
943 config_element_tracefile_size
, attr
->tracefile_size
);
948 /* Count of tracefiles */
949 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
950 config_element_tracefile_count
,
951 attr
->tracefile_count
);
956 /* Live timer interval in usec*/
957 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
958 config_element_live_timer_interval
,
959 attr
->live_timer_interval
);
964 /* Discarded events */
965 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
966 config_element_discarded_events
,
973 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
974 config_element_lost_packets
,
980 /* Closing attributes */
981 ret
= mi_lttng_writer_close_element(writer
);
991 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
992 struct lttng_event
*event
)
995 const char *filter_expression
;
997 /* Open event element */
998 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
1004 ret
= mi_lttng_writer_write_element_string(writer
,
1005 config_element_name
, event
->name
);
1011 ret
= mi_lttng_writer_write_element_string(writer
,
1012 config_element_type
, mi_lttng_eventtype_string(event
->type
));
1017 /* Is event enabled */
1018 ret
= mi_lttng_writer_write_element_bool(writer
,
1019 config_element_enabled
, event
->enabled
);
1024 /* Event filter expression */
1025 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1030 if (filter_expression
) {
1031 ret
= mi_lttng_writer_write_element_string(writer
,
1032 config_element_filter_expression
,
1043 static int write_event_exclusions(struct mi_writer
*writer
,
1044 struct lttng_event
*event
)
1048 int exclusion_count
;
1050 /* Open event exclusions */
1051 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1056 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1057 if (exclusion_count
< 0) {
1058 ret
= exclusion_count
;
1062 for (i
= 0; i
< exclusion_count
; i
++) {
1065 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1067 /* Close exclusions */
1068 mi_lttng_writer_close_element(writer
);
1072 ret
= mi_lttng_writer_write_element_string(writer
,
1073 config_element_exclusion
, name
);
1075 /* Close exclusions */
1076 mi_lttng_writer_close_element(writer
);
1081 /* Close exclusions */
1082 ret
= mi_lttng_writer_close_element(writer
);
1089 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1090 struct lttng_event
*event
, enum lttng_domain_type domain
)
1094 /* Event loglevel */
1095 ret
= mi_lttng_writer_write_element_string(writer
,
1096 config_element_loglevel
,
1097 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1102 /* Log level type */
1103 ret
= mi_lttng_writer_write_element_string(writer
,
1104 config_element_loglevel_type
,
1105 mi_lttng_logleveltype_string(event
->loglevel_type
));
1110 /* Event exclusions */
1111 ret
= write_event_exclusions(writer
, event
);
1118 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1119 struct lttng_event
*event
)
1121 /* event exclusion filter */
1122 return write_event_exclusions(writer
, event
);
1126 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1127 struct lttng_event
*event
)
1131 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1136 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1141 if (event
->attr
.probe
.addr
!= 0) {
1142 /* event probe address */
1143 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1144 config_element_address
, event
->attr
.probe
.addr
);
1149 /* event probe offset */
1150 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1151 config_element_offset
, event
->attr
.probe
.offset
);
1156 /* event probe symbol_name */
1157 ret
= mi_lttng_writer_write_element_string(writer
,
1158 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1164 /* Close probe_attributes and attributes */
1165 ret
= mi_lttng_close_multi_element(writer
, 2);
1171 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1172 struct lttng_event
*event
)
1176 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1181 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1186 /* event probe symbol_name */
1187 ret
= mi_lttng_writer_write_element_string(writer
,
1188 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1193 /* Close function_attributes and attributes */
1194 ret
= mi_lttng_close_multi_element(writer
, 2);
1200 int mi_lttng_events_open(struct mi_writer
*writer
)
1202 return mi_lttng_writer_open_element(writer
, config_element_events
);
1206 int mi_lttng_event(struct mi_writer
*writer
,
1207 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1211 ret
= mi_lttng_event_common_attributes(writer
, event
);
1216 switch (event
->type
) {
1217 case LTTNG_EVENT_TRACEPOINT
:
1219 if (event
->loglevel
!= -1) {
1220 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1222 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1226 case LTTNG_EVENT_FUNCTION
:
1228 case LTTNG_EVENT_PROBE
:
1229 ret
= mi_lttng_event_function_probe(writer
, event
);
1231 case LTTNG_EVENT_FUNCTION_ENTRY
:
1232 ret
= mi_lttng_event_function_entry(writer
, event
);
1234 case LTTNG_EVENT_ALL
:
1241 ret
= mi_lttng_writer_close_element(writer
);
1249 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1251 return mi_lttng_writer_open_element(writer
, config_element_trackers
);
1255 int mi_lttng_pid_tracker_open(struct mi_writer
*writer
)
1259 /* Open element pid_tracker */
1260 ret
= mi_lttng_writer_open_element(writer
, config_element_pid_tracker
);
1265 /* Open targets element */
1266 ret
= mi_lttng_targets_open(writer
);
1272 int mi_lttng_pids_open(struct mi_writer
*writer
)
1274 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1278 * TODO: move the listing of pid for user agent to process semantic on
1279 * mi api bump. The use of process element break the mi api.
1282 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *name
,
1287 /* Open pid process */
1288 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1293 /* Writing pid number */
1294 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1295 mi_lttng_element_pid_id
, (int)pid
);
1300 /* Writing name of the process */
1302 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1311 ret
= mi_lttng_writer_close_element(writer
);
1319 int mi_lttng_targets_open(struct mi_writer
*writer
)
1321 return mi_lttng_writer_open_element(writer
,
1322 config_element_targets
);
1326 int mi_lttng_pid_target(struct mi_writer
*writer
, pid_t pid
, int is_open
)
1330 ret
= mi_lttng_writer_open_element(writer
,
1331 config_element_target_pid
);
1336 /* Writing pid number
1337 * Special case for element all on track untrack command
1338 * All pid is represented as wildcard *
1340 if ((int) pid
== -1) {
1341 ret
= mi_lttng_writer_write_element_string(writer
,
1343 mi_lttng_element_track_untrack_all_wildcard
);
1345 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1346 config_element_pid
, (int) pid
);
1353 ret
= mi_lttng_writer_close_element(writer
);
1364 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1366 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1370 int mi_lttng_event_field(struct mi_writer
*writer
,
1371 struct lttng_event_field
*field
)
1375 if (!field
->field_name
[0]) {
1381 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1386 if (!field
->field_name
[0]) {
1391 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1398 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1399 mi_lttng_eventfieldtype_string(field
->type
));
1405 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1406 mi_lttng_element_nowrite
, field
->nowrite
);
1412 /* Close field element */
1413 ret
= mi_lttng_writer_close_element(writer
);
1420 int mi_lttng_calibrate(struct mi_writer
*writer
,
1421 struct lttng_calibrate
*calibrate
)
1425 /* Open calibrate element */
1426 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1431 /* Calibration type */
1432 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1433 mi_lttng_calibratetype_string(calibrate
->type
));
1438 /* Closing calibrate element */
1439 ret
= mi_lttng_writer_close_element(writer
);
1445 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1446 struct lttng_event_perf_counter_ctx
*perf_context
)
1450 /* Open perf_counter_context */
1451 ret
= mi_lttng_writer_open_element(writer
,
1452 mi_lttng_element_perf_counter_context
);
1458 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1459 config_element_type
, perf_context
->type
);
1465 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1466 config_element_config
, perf_context
->config
);
1471 /* Name of the perf counter */
1472 ret
= mi_lttng_writer_write_element_string(writer
,
1473 config_element_name
, perf_context
->name
);
1478 /* Close perf_counter_context */
1479 ret
= mi_lttng_writer_close_element(writer
);
1485 int mi_lttng_app_context(struct mi_writer
*writer
,
1486 const char *provider_name
, const char *ctx_name
)
1491 ret
= mi_lttng_writer_open_element(writer
,
1492 config_element_context_app
);
1498 ret
= mi_lttng_writer_write_element_string(writer
,
1499 config_element_context_app_provider_name
,
1506 ret
= mi_lttng_writer_write_element_string(writer
,
1507 config_element_context_app_ctx_name
, ctx_name
);
1513 ret
= mi_lttng_writer_close_element(writer
);
1519 int mi_lttng_context(struct mi_writer
*writer
,
1520 struct lttng_event_context
*context
, int is_open
)
1525 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1530 /* Special case for PERF_*_COUNTER
1531 * print the lttng_event_perf_counter_ctx*/
1532 switch (context
->ctx
) {
1533 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1534 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1535 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1537 struct lttng_event_perf_counter_ctx
*perf_context
=
1538 &context
->u
.perf_counter
;
1539 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1545 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
1547 ret
= mi_lttng_app_context(writer
,
1548 context
->u
.app_ctx
.provider_name
,
1549 context
->u
.app_ctx
.ctx_name
);
1557 const char *type_string
= mi_lttng_event_contexttype_string(
1560 ret
= -LTTNG_ERR_INVALID
;
1564 /* Print context type */
1565 ret
= mi_lttng_writer_write_element_string(writer
,
1566 config_element_type
, type_string
);
1573 ret
= mi_lttng_writer_close_element(writer
);
1581 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1582 const char *session_name
)
1586 /* Open session element */
1587 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1592 /* Snapshot output list for current session name */
1593 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1599 /* Open element snapshots (sequence one snapshot) */
1600 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1610 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1611 struct lttng_snapshot_output
*output
)
1615 /* Open element snapshot output */
1616 ret
= mi_lttng_writer_open_element(writer
,
1617 mi_lttng_element_command_snapshot
);
1622 /* ID of the snapshot output */
1623 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1624 mi_lttng_element_id
, output
->id
);
1629 /* Name of the output */
1630 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1636 /* Destination of the output (ctrl_url)*/
1637 ret
= mi_lttng_writer_write_element_string(writer
,
1638 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1643 /* Destination of the output (data_url) */
1644 ret
= mi_lttng_writer_write_element_string(writer
,
1645 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1650 /* total size of all stream combined */
1651 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1652 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1657 /* Close snapshot output element */
1658 ret
= mi_lttng_writer_close_element(writer
);
1665 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1666 const char *name
, const char *current_session_name
)
1670 /* Open element del_snapshot */
1671 ret
= mi_lttng_writer_open_element(writer
,
1672 mi_lttng_element_command_snapshot
);
1678 if (id
!= UINT32_MAX
) {
1679 /* "Snapshot output "id" successfully deleted
1680 * for "current_session_name"
1681 * ID of the snapshot output
1683 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1684 mi_lttng_element_id
, id
);
1689 /* "Snapshot output "name" successfully deleted
1690 * for session "current_session_name"
1691 * Name of the output
1693 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1700 /* Snapshot was deleted for session "current_session_name"*/
1701 ret
= mi_lttng_writer_write_element_string(writer
,
1702 mi_lttng_element_snapshot_session_name
,
1703 current_session_name
);
1708 /* Close snapshot element */
1709 ret
= mi_lttng_writer_close_element(writer
);
1716 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1717 const char *current_session_name
, const char *n_ptr
,
1718 struct lttng_snapshot_output
*output
)
1722 /* Open element snapshot */
1723 ret
= mi_lttng_writer_open_element(writer
,
1724 mi_lttng_element_command_snapshot
);
1729 /* Snapshot output id */
1730 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1731 mi_lttng_element_id
, output
->id
);
1736 /* Snapshot output names */
1737 ret
= mi_lttng_writer_write_element_string(writer
,
1738 config_element_name
, n_ptr
);
1743 /* Destination of the output (ctrl_url)*/
1744 ret
= mi_lttng_writer_write_element_string(writer
,
1745 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1750 /* Snapshot added for session "current_session_name"*/
1751 ret
= mi_lttng_writer_write_element_string(writer
,
1752 mi_lttng_element_snapshot_session_name
, current_session_name
);
1757 /* total size of all stream combined */
1758 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1759 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1764 /* Close snapshot element */
1765 ret
= mi_lttng_writer_close_element(writer
);
1772 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1773 const char *current_session_name
, const char *url
,
1774 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1778 /* Open element snapshot */
1779 ret
= mi_lttng_writer_open_element(writer
,
1780 mi_lttng_element_command_snapshot
);
1786 * If a valid an URL was given, serialize it,
1787 * else take the command line data and ctrl urls*/
1789 /* Destination of the output (ctrl_url)*/
1790 ret
= mi_lttng_writer_write_element_string(writer
,
1791 mi_lttng_element_snapshot_ctrl_url
, url
);
1795 } else if (cmdline_ctrl_url
) {
1796 /* Destination of the output (ctrl_url)*/
1797 ret
= mi_lttng_writer_write_element_string(writer
,
1798 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1803 /* Destination of the output (data_url) */
1804 ret
= mi_lttng_writer_write_element_string(writer
,
1805 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1811 /* Close record_snapshot element */
1812 ret
= mi_lttng_writer_close_element(writer
);