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 <lttng/snapshot-internal.h>
27 #define MI_SCHEMA_MAJOR_VERSION 3
28 #define MI_SCHEMA_MINOR_VERSION 0
30 /* Machine interface namespace URI */
31 const char * const mi_lttng_xmlns
= "xmlns";
32 const char * const mi_lttng_ns_uri
= "http://lttng.org/xml/ns/lttng-mi";
33 const char * const mi_lttng_xmlns_xsi
= "xmlns:xsi";
34 const char * const mi_lttng_w3_schema_uri
= "http://www.w3.org/2001/XMLSchema-instance";
35 const char * const mi_lttng_schema_location
= "xsi:schemaLocation";
36 const char * const mi_lttng_schema_location_uri
=
37 "http://lttng.org/xml/ns/lttng-mi" " "
38 "http://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION
)
39 "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION
) "."
40 XSTR(MI_SCHEMA_MINOR_VERSION
) ".xsd";
41 const char * const mi_lttng_schema_version
= "schemaVersion";
42 const char * const mi_lttng_schema_version_value
= XSTR(MI_SCHEMA_MAJOR_VERSION
)
43 "." XSTR(MI_SCHEMA_MINOR_VERSION
);
45 /* Strings related to command */
46 const char * const mi_lttng_element_command
= "command";
47 const char * const mi_lttng_element_command_action
= "snapshot_action";
48 const char * const mi_lttng_element_command_add_context
= "add-context";
49 const char * const mi_lttng_element_command_calibrate
= "calibrate";
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 const char * const mi_lttng_element_command_name
= "name";
59 const char * const mi_lttng_element_command_output
= "output";
60 const char * const mi_lttng_element_command_save
= "save";
61 const char * const mi_lttng_element_command_set_session
= "set-session";
62 const char * const mi_lttng_element_command_snapshot
= "snapshot";
63 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
64 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
65 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
66 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
67 const char * const mi_lttng_element_command_start
= "start";
68 const char * const mi_lttng_element_command_stop
= "stop";
69 const char * const mi_lttng_element_command_success
= "success";
70 const char * const mi_lttng_element_command_track
= "track";
71 const char * const mi_lttng_element_command_untrack
= "untrack";
72 const char * const mi_lttng_element_command_version
= "version";
74 /* Strings related to version command */
75 const char * const mi_lttng_element_version
= "version";
76 const char * const mi_lttng_element_version_commit
= "commit";
77 const char * const mi_lttng_element_version_description
= "description";
78 const char * const mi_lttng_element_version_license
= "license";
79 const char * const mi_lttng_element_version_major
= "major";
80 const char * const mi_lttng_element_version_minor
= "minor";
81 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
82 const char * const mi_lttng_element_version_str
= "string";
83 const char * const mi_lttng_element_version_web
= "url";
85 /* String related to a lttng_event_field */
86 const char * const mi_lttng_element_event_field
= "event_field";
87 const char * const mi_lttng_element_event_fields
= "event_fields";
89 /* String related to lttng_event_context */
90 const char * const mi_lttng_context_type_perf_counter
= "PERF_COUNTER";
91 const char * const mi_lttng_context_type_perf_cpu_counter
= "PERF_CPU_COUNTER";
92 const char * const mi_lttng_context_type_perf_thread_counter
= "PERF_THREAD_COUNTER";
94 /* String related to lttng_event_perf_counter_ctx */
95 const char * const mi_lttng_element_perf_counter_context
= "perf_counter_context";
97 /* Strings related to pid */
98 const char * const mi_lttng_element_pid_id
= "id";
100 /* Strings related to save command */
101 const char * const mi_lttng_element_save
= "save";
103 /* Strings related to load command */
104 const char * const mi_lttng_element_load
= "load";
106 /* General elements of mi_lttng */
107 const char * const mi_lttng_element_empty
= "";
108 const char * const mi_lttng_element_id
= "id";
109 const char * const mi_lttng_element_nowrite
= "nowrite";
110 const char * const mi_lttng_element_success
= "success";
111 const char * const mi_lttng_element_type_enum
= "ENUM";
112 const char * const mi_lttng_element_type_float
= "FLOAT";
113 const char * const mi_lttng_element_type_integer
= "INTEGER";
114 const char * const mi_lttng_element_type_other
= "OTHER";
115 const char * const mi_lttng_element_type_string
= "STRING";
117 /* String related to loglevel */
118 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
119 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
120 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
121 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
122 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
123 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
124 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
125 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
126 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
127 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
128 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
129 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
130 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
131 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
132 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
133 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
135 /* String related to loglevel JUL */
136 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
137 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
138 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
139 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
140 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
141 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
142 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
143 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
144 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
146 /* String related to loglevel LOG4J */
147 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
148 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
149 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
150 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
151 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
152 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
153 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
154 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
156 /* String related to loglevel Python */
157 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
158 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
159 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
160 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
161 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
162 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
164 /* String related to loglevel type */
165 const char * const mi_lttng_loglevel_type_all
= "ALL";
166 const char * const mi_lttng_loglevel_type_range
= "RANGE";
167 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
168 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
170 /* String related to lttng_calibrate */
171 const char * const mi_lttng_element_calibrate
= "calibrate";
172 const char * const mi_lttng_element_calibrate_function
= "FUNCTION";
174 /* String related to a lttng_snapshot_output */
175 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
176 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
177 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
178 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
179 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
180 const char * const mi_lttng_element_snapshots
= "snapshots";
182 /* String related to track/untrack command */
183 const char * const mi_lttng_element_track_untrack_all_wildcard
= "*";
186 /* This is a merge of jul loglevel and regular loglevel
187 * Those should never overlap by definition
188 * (see struct lttng_event loglevel)
191 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
194 case LTTNG_DOMAIN_KERNEL
:
195 case LTTNG_DOMAIN_UST
:
198 return mi_lttng_element_empty
;
199 case LTTNG_LOGLEVEL_EMERG
:
200 return mi_lttng_loglevel_str_emerg
;
201 case LTTNG_LOGLEVEL_ALERT
:
202 return mi_lttng_loglevel_str_alert
;
203 case LTTNG_LOGLEVEL_CRIT
:
204 return mi_lttng_loglevel_str_crit
;
205 case LTTNG_LOGLEVEL_ERR
:
206 return mi_lttng_loglevel_str_err
;
207 case LTTNG_LOGLEVEL_WARNING
:
208 return mi_lttng_loglevel_str_warning
;
209 case LTTNG_LOGLEVEL_NOTICE
:
210 return mi_lttng_loglevel_str_notice
;
211 case LTTNG_LOGLEVEL_INFO
:
212 return mi_lttng_loglevel_str_info
;
213 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
214 return mi_lttng_loglevel_str_debug_system
;
215 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
216 return mi_lttng_loglevel_str_debug_program
;
217 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
218 return mi_lttng_loglevel_str_debug_process
;
219 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
220 return mi_lttng_loglevel_str_debug_module
;
221 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
222 return mi_lttng_loglevel_str_debug_unit
;
223 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
224 return mi_lttng_loglevel_str_debug_function
;
225 case LTTNG_LOGLEVEL_DEBUG_LINE
:
226 return mi_lttng_loglevel_str_debug_line
;
227 case LTTNG_LOGLEVEL_DEBUG
:
228 return mi_lttng_loglevel_str_debug
;
230 return mi_lttng_loglevel_str_unknown
;
233 case LTTNG_DOMAIN_LOG4J
:
236 return mi_lttng_element_empty
;
237 case LTTNG_LOGLEVEL_LOG4J_OFF
:
238 return mi_lttng_loglevel_str_log4j_off
;
239 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
240 return mi_lttng_loglevel_str_log4j_fatal
;
241 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
242 return mi_lttng_loglevel_str_log4j_error
;
243 case LTTNG_LOGLEVEL_LOG4J_WARN
:
244 return mi_lttng_loglevel_str_log4j_warn
;
245 case LTTNG_LOGLEVEL_LOG4J_INFO
:
246 return mi_lttng_loglevel_str_log4j_info
;
247 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
248 return mi_lttng_loglevel_str_log4j_debug
;
249 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
250 return mi_lttng_loglevel_str_log4j_trace
;
251 case LTTNG_LOGLEVEL_LOG4J_ALL
:
252 return mi_lttng_loglevel_str_log4j_all
;
254 return mi_lttng_loglevel_str_unknown
;
257 case LTTNG_DOMAIN_JUL
:
260 return mi_lttng_element_empty
;
261 case LTTNG_LOGLEVEL_JUL_OFF
:
262 return mi_lttng_loglevel_str_jul_off
;
263 case LTTNG_LOGLEVEL_JUL_SEVERE
:
264 return mi_lttng_loglevel_str_jul_severe
;
265 case LTTNG_LOGLEVEL_JUL_WARNING
:
266 return mi_lttng_loglevel_str_jul_warning
;
267 case LTTNG_LOGLEVEL_JUL_INFO
:
268 return mi_lttng_loglevel_str_jul_info
;
269 case LTTNG_LOGLEVEL_JUL_CONFIG
:
270 return mi_lttng_loglevel_str_jul_config
;
271 case LTTNG_LOGLEVEL_JUL_FINE
:
272 return mi_lttng_loglevel_str_jul_fine
;
273 case LTTNG_LOGLEVEL_JUL_FINER
:
274 return mi_lttng_loglevel_str_jul_finer
;
275 case LTTNG_LOGLEVEL_JUL_FINEST
:
276 return mi_lttng_loglevel_str_jul_finest
;
277 case LTTNG_LOGLEVEL_JUL_ALL
:
278 return mi_lttng_loglevel_str_jul_all
;
280 return mi_lttng_loglevel_str_unknown
;
283 case LTTNG_DOMAIN_PYTHON
:
285 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
286 return mi_lttng_loglevel_str_python_critical
;
287 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
288 return mi_lttng_loglevel_str_python_error
;
289 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
290 return mi_lttng_loglevel_str_python_warning
;
291 case LTTNG_LOGLEVEL_PYTHON_INFO
:
292 return mi_lttng_loglevel_str_python_info
;
293 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
294 return mi_lttng_loglevel_str_python_debug
;
295 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
296 return mi_lttng_loglevel_str_python_notset
;
298 return mi_lttng_loglevel_str_unknown
;
303 /* Reaching this means the domain is unknown. */
304 return mi_lttng_loglevel_str_unknown
;
308 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
311 case LTTNG_EVENT_LOGLEVEL_ALL
:
312 return mi_lttng_loglevel_type_all
;
313 case LTTNG_EVENT_LOGLEVEL_RANGE
:
314 return mi_lttng_loglevel_type_range
;
315 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
316 return mi_lttng_loglevel_type_single
;
318 return mi_lttng_loglevel_type_unknown
;
323 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
326 case LTTNG_EVENT_ALL
:
327 return config_event_type_all
;
328 case LTTNG_EVENT_TRACEPOINT
:
329 return config_event_type_tracepoint
;
330 case LTTNG_EVENT_PROBE
:
331 return config_event_type_probe
;
332 case LTTNG_EVENT_FUNCTION
:
333 return config_event_type_function
;
334 case LTTNG_EVENT_FUNCTION_ENTRY
:
335 return config_event_type_function_entry
;
336 case LTTNG_EVENT_SYSCALL
:
337 return config_event_type_syscall
;
338 case LTTNG_EVENT_NOOP
:
339 return config_event_type_noop
;
341 return mi_lttng_element_empty
;
346 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
349 case LTTNG_EVENT_CONTEXT_PID
:
350 return config_event_context_pid
;
351 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
352 return mi_lttng_context_type_perf_counter
;
353 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
354 return mi_lttng_context_type_perf_thread_counter
;
355 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
356 return mi_lttng_context_type_perf_cpu_counter
;
357 case LTTNG_EVENT_CONTEXT_PROCNAME
:
358 return config_event_context_procname
;
359 case LTTNG_EVENT_CONTEXT_PRIO
:
360 return config_event_context_prio
;
361 case LTTNG_EVENT_CONTEXT_NICE
:
362 return config_event_context_nice
;
363 case LTTNG_EVENT_CONTEXT_VPID
:
364 return config_event_context_vpid
;
365 case LTTNG_EVENT_CONTEXT_TID
:
366 return config_event_context_tid
;
367 case LTTNG_EVENT_CONTEXT_VTID
:
368 return config_event_context_vtid
;
369 case LTTNG_EVENT_CONTEXT_PPID
:
370 return config_event_context_ppid
;
371 case LTTNG_EVENT_CONTEXT_VPPID
:
372 return config_event_context_vppid
;
373 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
374 return config_event_context_pthread_id
;
375 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
376 return config_event_context_hostname
;
377 case LTTNG_EVENT_CONTEXT_IP
:
378 return config_event_context_ip
;
385 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
388 case(LTTNG_EVENT_FIELD_INTEGER
):
389 return mi_lttng_element_type_integer
;
390 case(LTTNG_EVENT_FIELD_ENUM
):
391 return mi_lttng_element_type_enum
;
392 case(LTTNG_EVENT_FIELD_FLOAT
):
393 return mi_lttng_element_type_float
;
394 case(LTTNG_EVENT_FIELD_STRING
):
395 return mi_lttng_element_type_string
;
397 return mi_lttng_element_type_other
;
402 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
404 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
406 case LTTNG_DOMAIN_KERNEL
:
407 return config_domain_type_kernel
;
408 case LTTNG_DOMAIN_UST
:
409 return config_domain_type_ust
;
410 case LTTNG_DOMAIN_JUL
:
411 return config_domain_type_jul
;
412 case LTTNG_DOMAIN_LOG4J
:
413 return config_domain_type_log4j
;
414 case LTTNG_DOMAIN_PYTHON
:
415 return config_domain_type_python
;
417 /* Should not have an unknown domain */
424 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
427 case LTTNG_BUFFER_PER_PID
:
428 return config_buffer_type_per_pid
;
429 case LTTNG_BUFFER_PER_UID
:
430 return config_buffer_type_per_uid
;
431 case LTTNG_BUFFER_GLOBAL
:
432 return config_buffer_type_global
;
434 /* Should not have an unknow buffer type */
441 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
)
446 case LTTNG_CALIBRATE_FUNCTION
:
447 ret
= mi_lttng_element_calibrate_function
;
450 ret
= mi_lttng_element_empty
;
457 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
459 struct mi_writer
*mi_writer
;
461 mi_writer
= zmalloc(sizeof(struct mi_writer
));
463 PERROR("zmalloc mi_writer_create");
466 if (mi_output_type
== LTTNG_MI_XML
) {
467 mi_writer
->writer
= config_writer_create(fd_output
, 0);
468 if (!mi_writer
->writer
) {
471 mi_writer
->type
= LTTNG_MI_XML
;
485 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
494 ret
= config_writer_destroy(writer
->writer
);
505 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
510 * A command is always the MI's root node, it must declare the current
511 * namespace and schema URIs and the schema's version.
513 ret
= config_writer_open_element(writer
->writer
,
514 mi_lttng_element_command
);
519 ret
= config_writer_write_attribute(writer
->writer
,
520 mi_lttng_xmlns
, mi_lttng_ns_uri
);
525 ret
= config_writer_write_attribute(writer
->writer
,
526 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
531 ret
= config_writer_write_attribute(writer
->writer
,
532 mi_lttng_schema_location
,
533 mi_lttng_schema_location_uri
);
538 ret
= config_writer_write_attribute(writer
->writer
,
539 mi_lttng_schema_version
,
540 mi_lttng_schema_version_value
);
545 ret
= mi_lttng_writer_write_element_string(writer
,
546 mi_lttng_element_command_name
, command
);
552 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
554 return mi_lttng_writer_close_element(writer
);
558 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
559 const char *element_name
)
561 return config_writer_open_element(writer
->writer
, element_name
);
565 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
567 return config_writer_close_element(writer
->writer
);
571 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
572 unsigned int nb_element
)
576 if (nb_element
< 1) {
580 for (i
= 0; i
< nb_element
; i
++) {
581 ret
= mi_lttng_writer_close_element(writer
);
591 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
592 const char *element_name
, uint64_t value
)
594 return config_writer_write_element_unsigned_int(writer
->writer
,
595 element_name
, value
);
599 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
600 const char *element_name
, int64_t value
)
602 return config_writer_write_element_signed_int(writer
->writer
,
603 element_name
, value
);
607 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
608 const char *element_name
, int value
)
610 return config_writer_write_element_bool(writer
->writer
,
611 element_name
, value
);
615 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
616 const char *element_name
, const char *value
)
618 return config_writer_write_element_string(writer
->writer
,
619 element_name
, value
);
623 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
624 const char *lttng_description
, const char *lttng_license
)
629 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
634 /* Version string (contain info like rc etc.) */
635 ret
= mi_lttng_writer_write_element_string(writer
,
636 mi_lttng_element_version_str
, version
->version
);
641 /* Major version number */
642 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
643 mi_lttng_element_version_major
, version
->version_major
);
648 /* Minor version number */
649 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
650 mi_lttng_element_version_minor
, version
->version_minor
);
655 /* Commit version number */
656 ret
= mi_lttng_writer_write_element_string(writer
,
657 mi_lttng_element_version_commit
, version
->version_commit
);
663 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
664 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
669 /* Name of the version */
670 ret
= mi_lttng_writer_write_element_string(writer
,
671 config_element_name
, version
->version_name
);
676 /* Description mostly related to beer... */
677 ret
= mi_lttng_writer_write_element_string(writer
,
678 mi_lttng_element_version_description
, lttng_description
);
684 ret
= mi_lttng_writer_write_element_string(writer
,
685 mi_lttng_element_version_web
, version
->package_url
);
690 /* License: free as in free beer...no...*speech* */
691 ret
= mi_lttng_writer_write_element_string(writer
,
692 mi_lttng_element_version_license
, lttng_license
);
697 /* Close version element */
698 ret
= mi_lttng_writer_close_element(writer
);
705 int mi_lttng_sessions_open(struct mi_writer
*writer
)
707 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
711 int mi_lttng_session(struct mi_writer
*writer
,
712 struct lttng_session
*session
, int is_open
)
718 /* Open sessions element */
719 ret
= mi_lttng_writer_open_element(writer
,
720 config_element_session
);
725 /* Name of the session */
726 ret
= mi_lttng_writer_write_element_string(writer
,
727 config_element_name
, session
->name
);
733 ret
= mi_lttng_writer_write_element_string(writer
,
734 config_element_path
, session
->path
);
740 ret
= mi_lttng_writer_write_element_bool(writer
,
741 config_element_enabled
, session
->enabled
);
747 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
748 config_element_snapshot_mode
, session
->snapshot_mode
);
753 /* Live timer interval in usec */
754 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
755 config_element_live_timer_interval
,
756 session
->live_timer_interval
);
762 /* Closing session element */
763 ret
= mi_lttng_writer_close_element(writer
);
771 int mi_lttng_domains_open(struct mi_writer
*writer
)
773 return mi_lttng_writer_open_element(writer
, config_element_domains
);
777 int mi_lttng_domain(struct mi_writer
*writer
,
778 struct lttng_domain
*domain
, int is_open
)
781 const char *str_domain
;
782 const char *str_buffer
;
786 /* Open domain element */
787 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
793 str_domain
= mi_lttng_domaintype_string(domain
->type
);
794 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
801 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
802 ret
= mi_lttng_writer_write_element_string(writer
,
803 config_element_buffer_type
, str_buffer
);
809 * This union is not currently used and was added for
810 * future ust domain support.
815 /* Closing domain element */
816 ret
= mi_lttng_writer_close_element(writer
);
825 int mi_lttng_channels_open(struct mi_writer
*writer
)
827 return mi_lttng_writer_open_element(writer
, config_element_channels
);
831 int mi_lttng_channel(struct mi_writer
*writer
,
832 struct lttng_channel
*channel
, int is_open
)
838 /* Opening channel element */
839 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
845 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
852 ret
= mi_lttng_writer_write_element_bool(writer
,
853 config_element_enabled
, channel
->enabled
);
859 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
865 /* Closing channel element */
866 ret
= mi_lttng_writer_close_element(writer
);
876 int mi_lttng_channel_attr(struct mi_writer
*writer
,
877 struct lttng_channel_attr
*attr
)
883 /* Opening Attributes */
884 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
890 ret
= mi_lttng_writer_write_element_string(writer
,
891 config_element_overwrite_mode
,
892 attr
->overwrite
? config_overwrite_mode_overwrite
:
893 config_overwrite_mode_discard
);
898 /* Sub buffer size in byte */
899 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
900 config_element_subbuf_size
, attr
->subbuf_size
);
905 /* Number of subbuffer (power of two) */
906 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
907 config_element_num_subbuf
,
913 /* Switch timer interval in usec */
914 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
915 config_element_switch_timer_interval
,
916 attr
->switch_timer_interval
);
921 /* Read timer interval in usec */
922 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
923 config_element_read_timer_interval
,
924 attr
->read_timer_interval
);
930 ret
= mi_lttng_writer_write_element_string(writer
,
931 config_element_output_type
,
932 attr
->output
== LTTNG_EVENT_SPLICE
?
933 config_output_type_splice
: config_output_type_mmap
);
938 /* Tracefile size in bytes */
939 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
940 config_element_tracefile_size
, attr
->tracefile_size
);
945 /* Count of tracefiles */
946 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
947 config_element_tracefile_count
,
948 attr
->tracefile_count
);
953 /* Live timer interval in usec*/
954 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
955 config_element_live_timer_interval
,
956 attr
->live_timer_interval
);
961 /* Closing attributes */
962 ret
= mi_lttng_writer_close_element(writer
);
972 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
973 struct lttng_event
*event
)
976 const char *filter_expression
;
978 /* Open event element */
979 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
985 ret
= mi_lttng_writer_write_element_string(writer
,
986 config_element_name
, event
->name
);
992 ret
= mi_lttng_writer_write_element_string(writer
,
993 config_element_type
, mi_lttng_eventtype_string(event
->type
));
998 /* Is event enabled */
999 ret
= mi_lttng_writer_write_element_bool(writer
,
1000 config_element_enabled
, event
->enabled
);
1005 /* Event filter expression */
1006 ret
= lttng_event_get_filter_string(event
, &filter_expression
);
1011 if (filter_expression
) {
1012 ret
= mi_lttng_writer_write_element_string(writer
,
1013 config_element_filter_expression
,
1025 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1026 struct lttng_event
*event
, enum lttng_domain_type domain
)
1030 /* Event loglevel */
1031 ret
= mi_lttng_writer_write_element_string(writer
,
1032 config_element_loglevel
,
1033 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1038 /* Log level type */
1039 ret
= mi_lttng_writer_write_element_string(writer
,
1040 config_element_loglevel_type
,
1041 mi_lttng_logleveltype_string(event
->loglevel_type
));
1046 /* event exclusion filter */
1047 ret
= mi_lttng_writer_write_element_bool(writer
,
1048 config_element_exclusion
, event
->exclusion
);
1058 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1059 struct lttng_event
*event
)
1061 /* event exclusion filter */
1062 return mi_lttng_writer_write_element_bool(writer
,
1063 config_element_exclusion
, event
->exclusion
);
1067 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1068 struct lttng_event
*event
)
1072 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1077 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1082 if (event
->attr
.probe
.addr
!= 0) {
1083 /* event probe address */
1084 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1085 config_element_address
, event
->attr
.probe
.addr
);
1090 /* event probe offset */
1091 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1092 config_element_offset
, event
->attr
.probe
.offset
);
1097 /* event probe symbol_name */
1098 ret
= mi_lttng_writer_write_element_string(writer
,
1099 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1105 /* Close probe_attributes and attributes */
1106 ret
= mi_lttng_close_multi_element(writer
, 2);
1112 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1113 struct lttng_event
*event
)
1117 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1122 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1127 /* event probe symbol_name */
1128 ret
= mi_lttng_writer_write_element_string(writer
,
1129 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1134 /* Close function_attributes and attributes */
1135 ret
= mi_lttng_close_multi_element(writer
, 2);
1141 int mi_lttng_events_open(struct mi_writer
*writer
)
1143 return mi_lttng_writer_open_element(writer
, config_element_events
);
1147 int mi_lttng_event(struct mi_writer
*writer
,
1148 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1152 ret
= mi_lttng_event_common_attributes(writer
, event
);
1157 switch (event
->type
) {
1158 case LTTNG_EVENT_TRACEPOINT
:
1160 if (event
->loglevel
!= -1) {
1161 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1163 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1167 case LTTNG_EVENT_FUNCTION
:
1169 case LTTNG_EVENT_PROBE
:
1170 ret
= mi_lttng_event_function_probe(writer
, event
);
1172 case LTTNG_EVENT_FUNCTION_ENTRY
:
1173 ret
= mi_lttng_event_function_entry(writer
, event
);
1175 case LTTNG_EVENT_ALL
:
1182 ret
= mi_lttng_writer_close_element(writer
);
1190 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1192 return mi_lttng_writer_open_element(writer
, config_element_trackers
);
1196 int mi_lttng_pid_tracker_open(struct mi_writer
*writer
)
1200 /* Open element pid_tracker */
1201 ret
= mi_lttng_writer_open_element(writer
, config_element_pid_tracker
);
1206 /* Open targets element */
1207 ret
= mi_lttng_targets_open(writer
);
1213 int mi_lttng_pids_open(struct mi_writer
*writer
)
1215 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1219 * TODO: move the listing of pid for user agent to process semantic on
1220 * mi api bump. The use of process element break the mi api.
1223 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *name
,
1228 /* Open pid process */
1229 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1234 /* Writing pid number */
1235 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1236 mi_lttng_element_pid_id
, (int)pid
);
1241 /* Writing name of the process */
1243 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1252 ret
= mi_lttng_writer_close_element(writer
);
1260 int mi_lttng_targets_open(struct mi_writer
*writer
)
1262 return mi_lttng_writer_open_element(writer
,
1263 config_element_targets
);
1267 int mi_lttng_pid_target(struct mi_writer
*writer
, pid_t pid
, int is_open
)
1271 ret
= mi_lttng_writer_open_element(writer
,
1272 config_element_target_pid
);
1277 /* Writing pid number
1278 * Special case for element all on track untrack command
1279 * All pid is represented as wildcard *
1281 if ((int) pid
== -1) {
1282 ret
= mi_lttng_writer_write_element_string(writer
,
1284 mi_lttng_element_track_untrack_all_wildcard
);
1286 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1287 config_element_pid
, (int) pid
);
1294 ret
= mi_lttng_writer_close_element(writer
);
1305 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1307 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1311 int mi_lttng_event_field(struct mi_writer
*writer
,
1312 struct lttng_event_field
*field
)
1316 if (!field
->field_name
[0]) {
1322 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1327 if (!field
->field_name
[0]) {
1332 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1339 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1340 mi_lttng_eventfieldtype_string(field
->type
));
1346 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1347 mi_lttng_element_nowrite
, field
->nowrite
);
1353 /* Close field element */
1354 ret
= mi_lttng_writer_close_element(writer
);
1361 int mi_lttng_calibrate(struct mi_writer
*writer
,
1362 struct lttng_calibrate
*calibrate
)
1366 /* Open calibrate element */
1367 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1372 /* Calibration type */
1373 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1374 mi_lttng_calibratetype_string(calibrate
->type
));
1379 /* Closing calibrate element */
1380 ret
= mi_lttng_writer_close_element(writer
);
1386 int mi_lttng_context(struct mi_writer
*writer
,
1387 struct lttng_event_context
*context
, int is_open
)
1390 const char *type_string
;
1391 struct lttng_event_perf_counter_ctx
*perf_context
;
1393 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1398 type_string
= mi_lttng_event_contexttype_string(context
->ctx
);
1400 ret
= -LTTNG_ERR_INVALID
;
1404 /* Print context type */
1405 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1408 /* Special case for PERF_*_COUNTER
1409 * print the lttng_event_perf_counter_ctx*/
1410 switch (context
->ctx
) {
1411 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1412 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1413 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1414 perf_context
= &context
->u
.perf_counter
;
1415 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1426 ret
= mi_lttng_writer_close_element(writer
);
1434 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1435 struct lttng_event_perf_counter_ctx
*perf_context
)
1439 /* Open perf_counter_context */
1440 ret
= mi_lttng_writer_open_element(writer
,
1441 mi_lttng_element_perf_counter_context
);
1447 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1448 config_element_type
, perf_context
->type
);
1454 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1455 config_element_config
, perf_context
->config
);
1460 /* Name of the perf counter */
1461 ret
= mi_lttng_writer_write_element_string(writer
,
1462 config_element_name
, perf_context
->name
);
1467 /* Close perf_counter_context */
1468 ret
= mi_lttng_writer_close_element(writer
);
1474 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1475 const char *session_name
)
1479 /* Open session element */
1480 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1485 /* Snapshot output list for current session name */
1486 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1492 /* Open element snapshots (sequence one snapshot) */
1493 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1503 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1504 struct lttng_snapshot_output
*output
)
1508 /* Open element snapshot output */
1509 ret
= mi_lttng_writer_open_element(writer
,
1510 mi_lttng_element_command_snapshot
);
1515 /* ID of the snapshot output */
1516 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1517 mi_lttng_element_id
, output
->id
);
1522 /* Name of the output */
1523 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1529 /* Destination of the output (ctrl_url)*/
1530 ret
= mi_lttng_writer_write_element_string(writer
,
1531 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1536 /* Destination of the output (data_url) */
1537 ret
= mi_lttng_writer_write_element_string(writer
,
1538 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1543 /* total size of all stream combined */
1544 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1545 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1550 /* Close snapshot output element */
1551 ret
= mi_lttng_writer_close_element(writer
);
1558 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1559 const char *name
, const char *current_session_name
)
1563 /* Open element del_snapshot */
1564 ret
= mi_lttng_writer_open_element(writer
,
1565 mi_lttng_element_command_snapshot
);
1571 if (id
!= UINT32_MAX
) {
1572 /* "Snapshot output "id" successfully deleted
1573 * for "current_session_name"
1574 * ID of the snapshot output
1576 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1577 mi_lttng_element_id
, id
);
1582 /* "Snapshot output "name" successfully deleted
1583 * for session "current_session_name"
1584 * Name of the output
1586 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1593 /* Snapshot was deleted for session "current_session_name"*/
1594 ret
= mi_lttng_writer_write_element_string(writer
,
1595 mi_lttng_element_snapshot_session_name
,
1596 current_session_name
);
1601 /* Close snapshot element */
1602 ret
= mi_lttng_writer_close_element(writer
);
1609 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1610 const char *current_session_name
, const char *n_ptr
,
1611 struct lttng_snapshot_output
*output
)
1615 /* Open element snapshot */
1616 ret
= mi_lttng_writer_open_element(writer
,
1617 mi_lttng_element_command_snapshot
);
1622 /* Snapshot output id */
1623 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1624 mi_lttng_element_id
, output
->id
);
1629 /* Snapshot output names */
1630 ret
= mi_lttng_writer_write_element_string(writer
,
1631 config_element_name
, n_ptr
);
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 /* Snapshot added for session "current_session_name"*/
1644 ret
= mi_lttng_writer_write_element_string(writer
,
1645 mi_lttng_element_snapshot_session_name
, current_session_name
);
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 element */
1658 ret
= mi_lttng_writer_close_element(writer
);
1665 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1666 const char *current_session_name
, const char *url
,
1667 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1671 /* Open element snapshot */
1672 ret
= mi_lttng_writer_open_element(writer
,
1673 mi_lttng_element_command_snapshot
);
1679 * If a valid an URL was given, serialize it,
1680 * else take the command line data and ctrl urls*/
1682 /* Destination of the output (ctrl_url)*/
1683 ret
= mi_lttng_writer_write_element_string(writer
,
1684 mi_lttng_element_snapshot_ctrl_url
, url
);
1688 } else if (cmdline_ctrl_url
) {
1689 /* Destination of the output (ctrl_url)*/
1690 ret
= mi_lttng_writer_write_element_string(writer
,
1691 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1696 /* Destination of the output (data_url) */
1697 ret
= mi_lttng_writer_write_element_string(writer
,
1698 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1704 /* Close record_snapshot element */
1705 ret
= mi_lttng_writer_close_element(writer
);