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_metadata
= "metadata";
60 const char * const mi_lttng_element_command_metadata_action
= "metadata_action";
61 const char * const mi_lttng_element_command_name
= "name";
62 const char * const mi_lttng_element_command_output
= "output";
63 const char * const mi_lttng_element_command_save
= "save";
64 const char * const mi_lttng_element_command_set_session
= "set-session";
65 const char * const mi_lttng_element_command_snapshot
= "snapshot";
66 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
67 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
68 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
69 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
70 const char * const mi_lttng_element_command_start
= "start";
71 const char * const mi_lttng_element_command_stop
= "stop";
72 const char * const mi_lttng_element_command_success
= "success";
73 const char * const mi_lttng_element_command_track
= "track";
74 const char * const mi_lttng_element_command_untrack
= "untrack";
75 const char * const mi_lttng_element_command_version
= "version";
77 /* Strings related to version command */
78 const char * const mi_lttng_element_version
= "version";
79 const char * const mi_lttng_element_version_commit
= "commit";
80 const char * const mi_lttng_element_version_description
= "description";
81 const char * const mi_lttng_element_version_license
= "license";
82 const char * const mi_lttng_element_version_major
= "major";
83 const char * const mi_lttng_element_version_minor
= "minor";
84 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
85 const char * const mi_lttng_element_version_str
= "string";
86 const char * const mi_lttng_element_version_web
= "url";
88 /* String related to a lttng_event_field */
89 const char * const mi_lttng_element_event_field
= "event_field";
90 const char * const mi_lttng_element_event_fields
= "event_fields";
92 /* String related to lttng_event_perf_counter_ctx */
93 const char * const mi_lttng_element_perf_counter_context
= "perf";
95 /* Strings related to pid */
96 const char * const mi_lttng_element_pid_id
= "id";
98 /* Strings related to save command */
99 const char * const mi_lttng_element_save
= "save";
101 /* Strings related to load command */
102 const char * const mi_lttng_element_load
= "load";
104 /* General elements of mi_lttng */
105 const char * const mi_lttng_element_empty
= "";
106 const char * const mi_lttng_element_id
= "id";
107 const char * const mi_lttng_element_nowrite
= "nowrite";
108 const char * const mi_lttng_element_success
= "success";
109 const char * const mi_lttng_element_type_enum
= "ENUM";
110 const char * const mi_lttng_element_type_float
= "FLOAT";
111 const char * const mi_lttng_element_type_integer
= "INTEGER";
112 const char * const mi_lttng_element_type_other
= "OTHER";
113 const char * const mi_lttng_element_type_string
= "STRING";
115 /* String related to loglevel */
116 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
117 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
118 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
119 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
120 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
121 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
122 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
123 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
124 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
125 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
126 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
127 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
128 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
129 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
130 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
131 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
133 /* String related to loglevel JUL */
134 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
135 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
136 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
137 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
138 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
139 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
140 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
141 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
142 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
144 /* String related to loglevel LOG4J */
145 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
146 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
147 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
148 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
149 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
150 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
151 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
152 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
154 /* String related to loglevel Python */
155 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
156 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
157 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
158 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
159 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
160 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
162 /* String related to loglevel type */
163 const char * const mi_lttng_loglevel_type_all
= "ALL";
164 const char * const mi_lttng_loglevel_type_range
= "RANGE";
165 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
166 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
168 /* String related to lttng_calibrate */
169 const char * const mi_lttng_element_calibrate
= "calibrate";
170 const char * const mi_lttng_element_calibrate_function
= "FUNCTION";
172 /* String related to a lttng_snapshot_output */
173 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
174 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
175 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
176 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
177 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
178 const char * const mi_lttng_element_snapshots
= "snapshots";
180 /* String related to track/untrack command */
181 const char * const mi_lttng_element_track_untrack_all_wildcard
= "*";
184 /* This is a merge of jul loglevel and regular loglevel
185 * Those should never overlap by definition
186 * (see struct lttng_event loglevel)
189 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
192 case LTTNG_DOMAIN_KERNEL
:
193 case LTTNG_DOMAIN_UST
:
196 return mi_lttng_element_empty
;
197 case LTTNG_LOGLEVEL_EMERG
:
198 return mi_lttng_loglevel_str_emerg
;
199 case LTTNG_LOGLEVEL_ALERT
:
200 return mi_lttng_loglevel_str_alert
;
201 case LTTNG_LOGLEVEL_CRIT
:
202 return mi_lttng_loglevel_str_crit
;
203 case LTTNG_LOGLEVEL_ERR
:
204 return mi_lttng_loglevel_str_err
;
205 case LTTNG_LOGLEVEL_WARNING
:
206 return mi_lttng_loglevel_str_warning
;
207 case LTTNG_LOGLEVEL_NOTICE
:
208 return mi_lttng_loglevel_str_notice
;
209 case LTTNG_LOGLEVEL_INFO
:
210 return mi_lttng_loglevel_str_info
;
211 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
212 return mi_lttng_loglevel_str_debug_system
;
213 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
214 return mi_lttng_loglevel_str_debug_program
;
215 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
216 return mi_lttng_loglevel_str_debug_process
;
217 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
218 return mi_lttng_loglevel_str_debug_module
;
219 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
220 return mi_lttng_loglevel_str_debug_unit
;
221 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
222 return mi_lttng_loglevel_str_debug_function
;
223 case LTTNG_LOGLEVEL_DEBUG_LINE
:
224 return mi_lttng_loglevel_str_debug_line
;
225 case LTTNG_LOGLEVEL_DEBUG
:
226 return mi_lttng_loglevel_str_debug
;
228 return mi_lttng_loglevel_str_unknown
;
231 case LTTNG_DOMAIN_LOG4J
:
234 return mi_lttng_element_empty
;
235 case LTTNG_LOGLEVEL_LOG4J_OFF
:
236 return mi_lttng_loglevel_str_log4j_off
;
237 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
238 return mi_lttng_loglevel_str_log4j_fatal
;
239 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
240 return mi_lttng_loglevel_str_log4j_error
;
241 case LTTNG_LOGLEVEL_LOG4J_WARN
:
242 return mi_lttng_loglevel_str_log4j_warn
;
243 case LTTNG_LOGLEVEL_LOG4J_INFO
:
244 return mi_lttng_loglevel_str_log4j_info
;
245 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
246 return mi_lttng_loglevel_str_log4j_debug
;
247 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
248 return mi_lttng_loglevel_str_log4j_trace
;
249 case LTTNG_LOGLEVEL_LOG4J_ALL
:
250 return mi_lttng_loglevel_str_log4j_all
;
252 return mi_lttng_loglevel_str_unknown
;
255 case LTTNG_DOMAIN_JUL
:
258 return mi_lttng_element_empty
;
259 case LTTNG_LOGLEVEL_JUL_OFF
:
260 return mi_lttng_loglevel_str_jul_off
;
261 case LTTNG_LOGLEVEL_JUL_SEVERE
:
262 return mi_lttng_loglevel_str_jul_severe
;
263 case LTTNG_LOGLEVEL_JUL_WARNING
:
264 return mi_lttng_loglevel_str_jul_warning
;
265 case LTTNG_LOGLEVEL_JUL_INFO
:
266 return mi_lttng_loglevel_str_jul_info
;
267 case LTTNG_LOGLEVEL_JUL_CONFIG
:
268 return mi_lttng_loglevel_str_jul_config
;
269 case LTTNG_LOGLEVEL_JUL_FINE
:
270 return mi_lttng_loglevel_str_jul_fine
;
271 case LTTNG_LOGLEVEL_JUL_FINER
:
272 return mi_lttng_loglevel_str_jul_finer
;
273 case LTTNG_LOGLEVEL_JUL_FINEST
:
274 return mi_lttng_loglevel_str_jul_finest
;
275 case LTTNG_LOGLEVEL_JUL_ALL
:
276 return mi_lttng_loglevel_str_jul_all
;
278 return mi_lttng_loglevel_str_unknown
;
281 case LTTNG_DOMAIN_PYTHON
:
283 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
284 return mi_lttng_loglevel_str_python_critical
;
285 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
286 return mi_lttng_loglevel_str_python_error
;
287 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
288 return mi_lttng_loglevel_str_python_warning
;
289 case LTTNG_LOGLEVEL_PYTHON_INFO
:
290 return mi_lttng_loglevel_str_python_info
;
291 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
292 return mi_lttng_loglevel_str_python_debug
;
293 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
294 return mi_lttng_loglevel_str_python_notset
;
296 return mi_lttng_loglevel_str_unknown
;
301 /* Reaching this means the domain is unknown. */
302 return mi_lttng_loglevel_str_unknown
;
306 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
309 case LTTNG_EVENT_LOGLEVEL_ALL
:
310 return mi_lttng_loglevel_type_all
;
311 case LTTNG_EVENT_LOGLEVEL_RANGE
:
312 return mi_lttng_loglevel_type_range
;
313 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
314 return mi_lttng_loglevel_type_single
;
316 return mi_lttng_loglevel_type_unknown
;
321 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
324 case LTTNG_EVENT_ALL
:
325 return config_event_type_all
;
326 case LTTNG_EVENT_TRACEPOINT
:
327 return config_event_type_tracepoint
;
328 case LTTNG_EVENT_PROBE
:
329 return config_event_type_probe
;
330 case LTTNG_EVENT_FUNCTION
:
331 return config_event_type_function
;
332 case LTTNG_EVENT_FUNCTION_ENTRY
:
333 return config_event_type_function_entry
;
334 case LTTNG_EVENT_SYSCALL
:
335 return config_event_type_syscall
;
336 case LTTNG_EVENT_NOOP
:
337 return config_event_type_noop
;
339 return mi_lttng_element_empty
;
344 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
347 case LTTNG_EVENT_CONTEXT_PID
:
348 return config_event_context_pid
;
349 case LTTNG_EVENT_CONTEXT_PROCNAME
:
350 return config_event_context_procname
;
351 case LTTNG_EVENT_CONTEXT_PRIO
:
352 return config_event_context_prio
;
353 case LTTNG_EVENT_CONTEXT_NICE
:
354 return config_event_context_nice
;
355 case LTTNG_EVENT_CONTEXT_VPID
:
356 return config_event_context_vpid
;
357 case LTTNG_EVENT_CONTEXT_TID
:
358 return config_event_context_tid
;
359 case LTTNG_EVENT_CONTEXT_VTID
:
360 return config_event_context_vtid
;
361 case LTTNG_EVENT_CONTEXT_PPID
:
362 return config_event_context_ppid
;
363 case LTTNG_EVENT_CONTEXT_VPPID
:
364 return config_event_context_vppid
;
365 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
366 return config_event_context_pthread_id
;
367 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
368 return config_event_context_hostname
;
369 case LTTNG_EVENT_CONTEXT_IP
:
370 return config_event_context_ip
;
377 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
380 case(LTTNG_EVENT_FIELD_INTEGER
):
381 return mi_lttng_element_type_integer
;
382 case(LTTNG_EVENT_FIELD_ENUM
):
383 return mi_lttng_element_type_enum
;
384 case(LTTNG_EVENT_FIELD_FLOAT
):
385 return mi_lttng_element_type_float
;
386 case(LTTNG_EVENT_FIELD_STRING
):
387 return mi_lttng_element_type_string
;
389 return mi_lttng_element_type_other
;
394 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
396 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
398 case LTTNG_DOMAIN_KERNEL
:
399 return config_domain_type_kernel
;
400 case LTTNG_DOMAIN_UST
:
401 return config_domain_type_ust
;
402 case LTTNG_DOMAIN_JUL
:
403 return config_domain_type_jul
;
404 case LTTNG_DOMAIN_LOG4J
:
405 return config_domain_type_log4j
;
406 case LTTNG_DOMAIN_PYTHON
:
407 return config_domain_type_python
;
409 /* Should not have an unknown domain */
416 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
419 case LTTNG_BUFFER_PER_PID
:
420 return config_buffer_type_per_pid
;
421 case LTTNG_BUFFER_PER_UID
:
422 return config_buffer_type_per_uid
;
423 case LTTNG_BUFFER_GLOBAL
:
424 return config_buffer_type_global
;
426 /* Should not have an unknow buffer type */
433 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
)
438 case LTTNG_CALIBRATE_FUNCTION
:
439 ret
= mi_lttng_element_calibrate_function
;
442 ret
= mi_lttng_element_empty
;
449 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
451 struct mi_writer
*mi_writer
;
453 mi_writer
= zmalloc(sizeof(struct mi_writer
));
455 PERROR("zmalloc mi_writer_create");
458 if (mi_output_type
== LTTNG_MI_XML
) {
459 mi_writer
->writer
= config_writer_create(fd_output
, 0);
460 if (!mi_writer
->writer
) {
463 mi_writer
->type
= LTTNG_MI_XML
;
477 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
486 ret
= config_writer_destroy(writer
->writer
);
497 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
502 * A command is always the MI's root node, it must declare the current
503 * namespace and schema URIs and the schema's version.
505 ret
= config_writer_open_element(writer
->writer
,
506 mi_lttng_element_command
);
511 ret
= config_writer_write_attribute(writer
->writer
,
512 mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
517 ret
= config_writer_write_attribute(writer
->writer
,
518 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
523 ret
= config_writer_write_attribute(writer
->writer
,
524 mi_lttng_schema_location
,
525 mi_lttng_schema_location_uri
);
530 ret
= config_writer_write_attribute(writer
->writer
,
531 mi_lttng_schema_version
,
532 mi_lttng_schema_version_value
);
537 ret
= mi_lttng_writer_write_element_string(writer
,
538 mi_lttng_element_command_name
, command
);
544 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
546 return mi_lttng_writer_close_element(writer
);
550 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
551 const char *element_name
)
553 return config_writer_open_element(writer
->writer
, element_name
);
557 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
559 return config_writer_close_element(writer
->writer
);
563 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
564 unsigned int nb_element
)
568 if (nb_element
< 1) {
572 for (i
= 0; i
< nb_element
; i
++) {
573 ret
= mi_lttng_writer_close_element(writer
);
583 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
584 const char *element_name
, uint64_t value
)
586 return config_writer_write_element_unsigned_int(writer
->writer
,
587 element_name
, value
);
591 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
592 const char *element_name
, int64_t value
)
594 return config_writer_write_element_signed_int(writer
->writer
,
595 element_name
, value
);
599 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
600 const char *element_name
, int value
)
602 return config_writer_write_element_bool(writer
->writer
,
603 element_name
, value
);
607 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
608 const char *element_name
, const char *value
)
610 return config_writer_write_element_string(writer
->writer
,
611 element_name
, value
);
615 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
616 const char *lttng_description
, const char *lttng_license
)
621 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
626 /* Version string (contain info like rc etc.) */
627 ret
= mi_lttng_writer_write_element_string(writer
,
628 mi_lttng_element_version_str
, version
->version
);
633 /* Major version number */
634 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
635 mi_lttng_element_version_major
, version
->version_major
);
640 /* Minor version number */
641 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
642 mi_lttng_element_version_minor
, version
->version_minor
);
647 /* Commit version number */
648 ret
= mi_lttng_writer_write_element_string(writer
,
649 mi_lttng_element_version_commit
, version
->version_commit
);
655 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
656 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
661 /* Name of the version */
662 ret
= mi_lttng_writer_write_element_string(writer
,
663 config_element_name
, version
->version_name
);
668 /* Description mostly related to beer... */
669 ret
= mi_lttng_writer_write_element_string(writer
,
670 mi_lttng_element_version_description
, lttng_description
);
676 ret
= mi_lttng_writer_write_element_string(writer
,
677 mi_lttng_element_version_web
, version
->package_url
);
682 /* License: free as in free beer...no...*speech* */
683 ret
= mi_lttng_writer_write_element_string(writer
,
684 mi_lttng_element_version_license
, lttng_license
);
689 /* Close version element */
690 ret
= mi_lttng_writer_close_element(writer
);
697 int mi_lttng_sessions_open(struct mi_writer
*writer
)
699 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
703 int mi_lttng_session(struct mi_writer
*writer
,
704 struct lttng_session
*session
, int is_open
)
710 /* Open sessions element */
711 ret
= mi_lttng_writer_open_element(writer
,
712 config_element_session
);
717 /* Name of the session */
718 ret
= mi_lttng_writer_write_element_string(writer
,
719 config_element_name
, session
->name
);
725 ret
= mi_lttng_writer_write_element_string(writer
,
726 config_element_path
, session
->path
);
732 ret
= mi_lttng_writer_write_element_bool(writer
,
733 config_element_enabled
, session
->enabled
);
739 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
740 config_element_snapshot_mode
, session
->snapshot_mode
);
745 /* Live timer interval in usec */
746 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
747 config_element_live_timer_interval
,
748 session
->live_timer_interval
);
754 /* Closing session element */
755 ret
= mi_lttng_writer_close_element(writer
);
763 int mi_lttng_domains_open(struct mi_writer
*writer
)
765 return mi_lttng_writer_open_element(writer
, config_element_domains
);
769 int mi_lttng_domain(struct mi_writer
*writer
,
770 struct lttng_domain
*domain
, int is_open
)
773 const char *str_domain
;
774 const char *str_buffer
;
778 /* Open domain element */
779 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
785 str_domain
= mi_lttng_domaintype_string(domain
->type
);
786 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
793 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
794 ret
= mi_lttng_writer_write_element_string(writer
,
795 config_element_buffer_type
, str_buffer
);
801 * This union is not currently used and was added for
802 * future ust domain support.
807 /* Closing domain element */
808 ret
= mi_lttng_writer_close_element(writer
);
817 int mi_lttng_channels_open(struct mi_writer
*writer
)
819 return mi_lttng_writer_open_element(writer
, config_element_channels
);
823 int mi_lttng_channel(struct mi_writer
*writer
,
824 struct lttng_channel
*channel
, int is_open
)
830 /* Opening channel element */
831 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
837 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
844 ret
= mi_lttng_writer_write_element_bool(writer
,
845 config_element_enabled
, channel
->enabled
);
851 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
857 /* Closing channel element */
858 ret
= mi_lttng_writer_close_element(writer
);
868 int mi_lttng_channel_attr(struct mi_writer
*writer
,
869 struct lttng_channel_attr
*attr
)
872 struct lttng_channel
*chan
= caa_container_of(attr
,
873 struct lttng_channel
, attr
);
874 uint64_t discarded_events
, lost_packets
;
878 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
883 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
888 /* Opening Attributes */
889 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
895 ret
= mi_lttng_writer_write_element_string(writer
,
896 config_element_overwrite_mode
,
897 attr
->overwrite
? config_overwrite_mode_overwrite
:
898 config_overwrite_mode_discard
);
903 /* Sub buffer size in byte */
904 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
905 config_element_subbuf_size
, attr
->subbuf_size
);
910 /* Number of subbuffer (power of two) */
911 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
912 config_element_num_subbuf
,
918 /* Switch timer interval in usec */
919 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
920 config_element_switch_timer_interval
,
921 attr
->switch_timer_interval
);
926 /* Read timer interval in usec */
927 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
928 config_element_read_timer_interval
,
929 attr
->read_timer_interval
);
935 ret
= mi_lttng_writer_write_element_string(writer
,
936 config_element_output_type
,
937 attr
->output
== LTTNG_EVENT_SPLICE
?
938 config_output_type_splice
: config_output_type_mmap
);
943 /* Tracefile size in bytes */
944 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
945 config_element_tracefile_size
, attr
->tracefile_size
);
950 /* Count of tracefiles */
951 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
952 config_element_tracefile_count
,
953 attr
->tracefile_count
);
958 /* Live timer interval in usec*/
959 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
960 config_element_live_timer_interval
,
961 attr
->live_timer_interval
);
966 /* Discarded events */
967 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
968 config_element_discarded_events
,
975 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
976 config_element_lost_packets
,
982 /* Closing attributes */
983 ret
= mi_lttng_writer_close_element(writer
);
993 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
994 struct lttng_event
*event
)
997 const char *filter_expression
;
999 /* Open event element */
1000 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
1006 ret
= mi_lttng_writer_write_element_string(writer
,
1007 config_element_name
, event
->name
);
1013 ret
= mi_lttng_writer_write_element_string(writer
,
1014 config_element_type
, mi_lttng_eventtype_string(event
->type
));
1019 /* Is event enabled */
1020 ret
= mi_lttng_writer_write_element_bool(writer
,
1021 config_element_enabled
, event
->enabled
);
1026 /* Event filter expression */
1027 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1032 if (filter_expression
) {
1033 ret
= mi_lttng_writer_write_element_string(writer
,
1034 config_element_filter_expression
,
1045 static int write_event_exclusions(struct mi_writer
*writer
,
1046 struct lttng_event
*event
)
1050 int exclusion_count
;
1052 /* Open event exclusions */
1053 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1058 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1059 if (exclusion_count
< 0) {
1060 ret
= exclusion_count
;
1064 for (i
= 0; i
< exclusion_count
; i
++) {
1067 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1069 /* Close exclusions */
1070 mi_lttng_writer_close_element(writer
);
1074 ret
= mi_lttng_writer_write_element_string(writer
,
1075 config_element_exclusion
, name
);
1077 /* Close exclusions */
1078 mi_lttng_writer_close_element(writer
);
1083 /* Close exclusions */
1084 ret
= mi_lttng_writer_close_element(writer
);
1091 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1092 struct lttng_event
*event
, enum lttng_domain_type domain
)
1096 /* Event loglevel */
1097 ret
= mi_lttng_writer_write_element_string(writer
,
1098 config_element_loglevel
,
1099 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1104 /* Log level type */
1105 ret
= mi_lttng_writer_write_element_string(writer
,
1106 config_element_loglevel_type
,
1107 mi_lttng_logleveltype_string(event
->loglevel_type
));
1112 /* Event exclusions */
1113 ret
= write_event_exclusions(writer
, event
);
1120 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1121 struct lttng_event
*event
)
1123 /* event exclusion filter */
1124 return write_event_exclusions(writer
, event
);
1128 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1129 struct lttng_event
*event
)
1133 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1138 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1143 if (event
->attr
.probe
.addr
!= 0) {
1144 /* event probe address */
1145 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1146 config_element_address
, event
->attr
.probe
.addr
);
1151 /* event probe offset */
1152 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1153 config_element_offset
, event
->attr
.probe
.offset
);
1158 /* event probe symbol_name */
1159 ret
= mi_lttng_writer_write_element_string(writer
,
1160 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1166 /* Close probe_attributes and attributes */
1167 ret
= mi_lttng_close_multi_element(writer
, 2);
1173 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1174 struct lttng_event
*event
)
1178 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1183 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1188 /* event probe symbol_name */
1189 ret
= mi_lttng_writer_write_element_string(writer
,
1190 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1195 /* Close function_attributes and attributes */
1196 ret
= mi_lttng_close_multi_element(writer
, 2);
1202 int mi_lttng_events_open(struct mi_writer
*writer
)
1204 return mi_lttng_writer_open_element(writer
, config_element_events
);
1208 int mi_lttng_event(struct mi_writer
*writer
,
1209 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1213 ret
= mi_lttng_event_common_attributes(writer
, event
);
1218 switch (event
->type
) {
1219 case LTTNG_EVENT_TRACEPOINT
:
1221 if (event
->loglevel
!= -1) {
1222 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1224 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1228 case LTTNG_EVENT_FUNCTION
:
1230 case LTTNG_EVENT_PROBE
:
1231 ret
= mi_lttng_event_function_probe(writer
, event
);
1233 case LTTNG_EVENT_FUNCTION_ENTRY
:
1234 ret
= mi_lttng_event_function_entry(writer
, event
);
1236 case LTTNG_EVENT_ALL
:
1243 ret
= mi_lttng_writer_close_element(writer
);
1251 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1253 return mi_lttng_writer_open_element(writer
, config_element_trackers
);
1257 int mi_lttng_pid_tracker_open(struct mi_writer
*writer
)
1261 /* Open element pid_tracker */
1262 ret
= mi_lttng_writer_open_element(writer
, config_element_pid_tracker
);
1267 /* Open targets element */
1268 ret
= mi_lttng_targets_open(writer
);
1274 int mi_lttng_pids_open(struct mi_writer
*writer
)
1276 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1280 * TODO: move the listing of pid for user agent to process semantic on
1281 * mi api bump. The use of process element break the mi api.
1284 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *name
,
1289 /* Open pid process */
1290 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1295 /* Writing pid number */
1296 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1297 mi_lttng_element_pid_id
, (int)pid
);
1302 /* Writing name of the process */
1304 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1313 ret
= mi_lttng_writer_close_element(writer
);
1321 int mi_lttng_targets_open(struct mi_writer
*writer
)
1323 return mi_lttng_writer_open_element(writer
,
1324 config_element_targets
);
1328 int mi_lttng_pid_target(struct mi_writer
*writer
, pid_t pid
, int is_open
)
1332 ret
= mi_lttng_writer_open_element(writer
,
1333 config_element_target_pid
);
1338 /* Writing pid number
1339 * Special case for element all on track untrack command
1340 * All pid is represented as wildcard *
1342 if ((int) pid
== -1) {
1343 ret
= mi_lttng_writer_write_element_string(writer
,
1345 mi_lttng_element_track_untrack_all_wildcard
);
1347 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1348 config_element_pid
, (int) pid
);
1355 ret
= mi_lttng_writer_close_element(writer
);
1366 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1368 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1372 int mi_lttng_event_field(struct mi_writer
*writer
,
1373 struct lttng_event_field
*field
)
1377 if (!field
->field_name
[0]) {
1383 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1388 if (!field
->field_name
[0]) {
1393 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1400 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1401 mi_lttng_eventfieldtype_string(field
->type
));
1407 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1408 mi_lttng_element_nowrite
, field
->nowrite
);
1414 /* Close field element */
1415 ret
= mi_lttng_writer_close_element(writer
);
1422 int mi_lttng_calibrate(struct mi_writer
*writer
,
1423 struct lttng_calibrate
*calibrate
)
1427 /* Open calibrate element */
1428 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1433 /* Calibration type */
1434 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1435 mi_lttng_calibratetype_string(calibrate
->type
));
1440 /* Closing calibrate element */
1441 ret
= mi_lttng_writer_close_element(writer
);
1447 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1448 struct lttng_event_perf_counter_ctx
*perf_context
)
1452 /* Open perf_counter_context */
1453 ret
= mi_lttng_writer_open_element(writer
,
1454 mi_lttng_element_perf_counter_context
);
1460 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1461 config_element_type
, perf_context
->type
);
1467 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1468 config_element_config
, perf_context
->config
);
1473 /* Name of the perf counter */
1474 ret
= mi_lttng_writer_write_element_string(writer
,
1475 config_element_name
, perf_context
->name
);
1480 /* Close perf_counter_context */
1481 ret
= mi_lttng_writer_close_element(writer
);
1487 int mi_lttng_app_context(struct mi_writer
*writer
,
1488 const char *provider_name
, const char *ctx_name
)
1493 ret
= mi_lttng_writer_open_element(writer
,
1494 config_element_context_app
);
1500 ret
= mi_lttng_writer_write_element_string(writer
,
1501 config_element_context_app_provider_name
,
1508 ret
= mi_lttng_writer_write_element_string(writer
,
1509 config_element_context_app_ctx_name
, ctx_name
);
1515 ret
= mi_lttng_writer_close_element(writer
);
1521 int mi_lttng_context(struct mi_writer
*writer
,
1522 struct lttng_event_context
*context
, int is_open
)
1527 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1532 /* Special case for PERF_*_COUNTER
1533 * print the lttng_event_perf_counter_ctx*/
1534 switch (context
->ctx
) {
1535 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1536 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1537 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1539 struct lttng_event_perf_counter_ctx
*perf_context
=
1540 &context
->u
.perf_counter
;
1541 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1547 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
1549 ret
= mi_lttng_app_context(writer
,
1550 context
->u
.app_ctx
.provider_name
,
1551 context
->u
.app_ctx
.ctx_name
);
1559 const char *type_string
= mi_lttng_event_contexttype_string(
1562 ret
= -LTTNG_ERR_INVALID
;
1566 /* Print context type */
1567 ret
= mi_lttng_writer_write_element_string(writer
,
1568 config_element_type
, type_string
);
1575 ret
= mi_lttng_writer_close_element(writer
);
1583 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1584 const char *session_name
)
1588 /* Open session element */
1589 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1594 /* Snapshot output list for current session name */
1595 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1601 /* Open element snapshots (sequence one snapshot) */
1602 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1612 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1613 struct lttng_snapshot_output
*output
)
1617 /* Open element snapshot output */
1618 ret
= mi_lttng_writer_open_element(writer
,
1619 mi_lttng_element_command_snapshot
);
1624 /* ID of the snapshot output */
1625 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1626 mi_lttng_element_id
, output
->id
);
1631 /* Name of the output */
1632 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1638 /* Destination of the output (ctrl_url)*/
1639 ret
= mi_lttng_writer_write_element_string(writer
,
1640 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1645 /* Destination of the output (data_url) */
1646 ret
= mi_lttng_writer_write_element_string(writer
,
1647 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1652 /* total size of all stream combined */
1653 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1654 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1659 /* Close snapshot output element */
1660 ret
= mi_lttng_writer_close_element(writer
);
1667 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1668 const char *name
, const char *current_session_name
)
1672 /* Open element del_snapshot */
1673 ret
= mi_lttng_writer_open_element(writer
,
1674 mi_lttng_element_command_snapshot
);
1680 if (id
!= UINT32_MAX
) {
1681 /* "Snapshot output "id" successfully deleted
1682 * for "current_session_name"
1683 * ID of the snapshot output
1685 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1686 mi_lttng_element_id
, id
);
1691 /* "Snapshot output "name" successfully deleted
1692 * for session "current_session_name"
1693 * Name of the output
1695 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1702 /* Snapshot was deleted for session "current_session_name"*/
1703 ret
= mi_lttng_writer_write_element_string(writer
,
1704 mi_lttng_element_snapshot_session_name
,
1705 current_session_name
);
1710 /* Close snapshot element */
1711 ret
= mi_lttng_writer_close_element(writer
);
1718 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1719 const char *current_session_name
, const char *n_ptr
,
1720 struct lttng_snapshot_output
*output
)
1724 /* Open element snapshot */
1725 ret
= mi_lttng_writer_open_element(writer
,
1726 mi_lttng_element_command_snapshot
);
1731 /* Snapshot output id */
1732 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1733 mi_lttng_element_id
, output
->id
);
1738 /* Snapshot output names */
1739 ret
= mi_lttng_writer_write_element_string(writer
,
1740 config_element_name
, n_ptr
);
1745 /* Destination of the output (ctrl_url)*/
1746 ret
= mi_lttng_writer_write_element_string(writer
,
1747 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1752 /* Snapshot added for session "current_session_name"*/
1753 ret
= mi_lttng_writer_write_element_string(writer
,
1754 mi_lttng_element_snapshot_session_name
, current_session_name
);
1759 /* total size of all stream combined */
1760 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1761 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1766 /* Close snapshot element */
1767 ret
= mi_lttng_writer_close_element(writer
);
1774 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1775 const char *current_session_name
, const char *url
,
1776 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1780 /* Open element snapshot */
1781 ret
= mi_lttng_writer_open_element(writer
,
1782 mi_lttng_element_command_snapshot
);
1788 * If a valid an URL was given, serialize it,
1789 * else take the command line data and ctrl urls*/
1791 /* Destination of the output (ctrl_url)*/
1792 ret
= mi_lttng_writer_write_element_string(writer
,
1793 mi_lttng_element_snapshot_ctrl_url
, url
);
1797 } else if (cmdline_ctrl_url
) {
1798 /* Destination of the output (ctrl_url)*/
1799 ret
= mi_lttng_writer_write_element_string(writer
,
1800 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1805 /* Destination of the output (data_url) */
1806 ret
= mi_lttng_writer_write_element_string(writer
,
1807 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1813 /* Close record_snapshot element */
1814 ret
= mi_lttng_writer_close_element(writer
);