2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
4 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License, version 2 only, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <common/config/session-config.h>
22 #include <common/defaults.h>
23 #include <lttng/snapshot-internal.h>
24 #include <lttng/channel.h>
29 #define MI_SCHEMA_MAJOR_VERSION 3
30 #define MI_SCHEMA_MINOR_VERSION 0
32 /* Machine interface namespace URI */
33 LTTNG_HIDDEN
const char * const mi_lttng_xmlns
= "xmlns";
34 LTTNG_HIDDEN
const char * const mi_lttng_xmlns_xsi
= "xmlns:xsi";
35 LTTNG_HIDDEN
const char * const mi_lttng_w3_schema_uri
= "http://www.w3.org/2001/XMLSchema-instance";
36 LTTNG_HIDDEN
const char * const mi_lttng_schema_location
= "xsi:schemaLocation";
37 LTTNG_HIDDEN
const char * const mi_lttng_schema_location_uri
=
38 DEFAULT_LTTNG_MI_NAMESPACE
" "
39 "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION
)
40 "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION
) "."
41 XSTR(MI_SCHEMA_MINOR_VERSION
) ".xsd";
42 LTTNG_HIDDEN
const char * const mi_lttng_schema_version
= "schemaVersion";
43 LTTNG_HIDDEN
const char * const mi_lttng_schema_version_value
= XSTR(MI_SCHEMA_MAJOR_VERSION
)
44 "." XSTR(MI_SCHEMA_MINOR_VERSION
);
46 /* Strings related to command */
47 const char * const mi_lttng_element_command
= "command";
48 const char * const mi_lttng_element_command_action
= "snapshot_action";
49 const char * const mi_lttng_element_command_add_context
= "add-context";
50 const char * const mi_lttng_element_command_create
= "create";
51 const char * const mi_lttng_element_command_destroy
= "destroy";
52 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
53 const char * const mi_lttng_element_command_disable_event
= "disable-event";
54 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
55 const char * const mi_lttng_element_command_enable_event
= "enable-event";
56 const char * const mi_lttng_element_command_list
= "list";
57 const char * const mi_lttng_element_command_load
= "load";
58 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata
= "metadata";
59 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata_action
= "metadata_action";
60 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate
= "regenerate";
61 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate_action
= "regenerate_action";
62 const char * const mi_lttng_element_command_name
= "name";
63 const char * const mi_lttng_element_command_output
= "output";
64 const char * const mi_lttng_element_command_save
= "save";
65 const char * const mi_lttng_element_command_set_session
= "set-session";
66 const char * const mi_lttng_element_command_snapshot
= "snapshot";
67 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
68 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
69 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
70 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
71 const char * const mi_lttng_element_command_start
= "start";
72 const char * const mi_lttng_element_command_stop
= "stop";
73 const char * const mi_lttng_element_command_success
= "success";
74 const char * const mi_lttng_element_command_track
= "track";
75 const char * const mi_lttng_element_command_untrack
= "untrack";
76 const char * const mi_lttng_element_command_version
= "version";
77 LTTNG_HIDDEN
const char * const mi_lttng_element_command_rotate
= "rotate";
78 LTTNG_HIDDEN
const char * const mi_lttng_element_command_enable_rotation
= "enable-rotation";
79 LTTNG_HIDDEN
const char * const mi_lttng_element_command_disable_rotation
= "disable-rotation";
81 /* Strings related to version command */
82 const char * const mi_lttng_element_version
= "version";
83 const char * const mi_lttng_element_version_commit
= "commit";
84 const char * const mi_lttng_element_version_description
= "description";
85 const char * const mi_lttng_element_version_license
= "license";
86 const char * const mi_lttng_element_version_major
= "major";
87 const char * const mi_lttng_element_version_minor
= "minor";
88 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
89 const char * const mi_lttng_element_version_str
= "string";
90 const char * const mi_lttng_element_version_web
= "url";
92 /* String related to a lttng_event_field */
93 const char * const mi_lttng_element_event_field
= "event_field";
94 const char * const mi_lttng_element_event_fields
= "event_fields";
96 /* String related to lttng_event_perf_counter_ctx */
97 const char * const mi_lttng_element_perf_counter_context
= "perf";
99 /* Strings related to pid */
100 const char * const mi_lttng_element_pid_id
= "id";
102 /* Strings related to save command */
103 const char * const mi_lttng_element_save
= "save";
105 /* Strings related to load command */
106 const char * const mi_lttng_element_load
= "load";
107 LTTNG_HIDDEN
const char * const mi_lttng_element_load_overrides
= "overrides";
108 LTTNG_HIDDEN
const char * const mi_lttng_element_load_override_url
= "url";
110 /* General elements of mi_lttng */
111 const char * const mi_lttng_element_empty
= "";
112 const char * const mi_lttng_element_id
= "id";
113 const char * const mi_lttng_element_nowrite
= "nowrite";
114 const char * const mi_lttng_element_success
= "success";
115 const char * const mi_lttng_element_type_enum
= "ENUM";
116 const char * const mi_lttng_element_type_float
= "FLOAT";
117 const char * const mi_lttng_element_type_integer
= "INTEGER";
118 const char * const mi_lttng_element_type_other
= "OTHER";
119 const char * const mi_lttng_element_type_string
= "STRING";
121 /* String related to loglevel */
122 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
123 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
124 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
125 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
126 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
127 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
128 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
129 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
130 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
131 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
132 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
133 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
134 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
135 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
136 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
137 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
139 /* String related to loglevel JUL */
140 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
141 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
142 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
143 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
144 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
145 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
146 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
147 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
148 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
150 /* String related to loglevel LOG4J */
151 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
152 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
153 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
154 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
155 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
156 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
157 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
158 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
160 /* String related to loglevel Python */
161 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
162 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
163 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
164 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
165 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
166 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
168 /* String related to loglevel type */
169 const char * const mi_lttng_loglevel_type_all
= "ALL";
170 const char * const mi_lttng_loglevel_type_range
= "RANGE";
171 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
172 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
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
= "*";
185 LTTNG_HIDDEN
const char * const mi_lttng_element_session_name
= "session_name";
187 /* String related to rotate command */
188 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation
= "rotation";
189 LTTNG_HIDDEN
const char * const mi_lttng_element_rotate_status
= "status";
190 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule
= "rotation_schedule";
191 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedules
= "rotation_schedules";
192 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_result
= "rotation_schedule_result";
193 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_results
= "rotation_schedule_results";
194 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_periodic
= "periodic";
195 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_periodic_time_us
= "time_us";
196 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_size_threshold
= "size_threshold";
197 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_size_threshold_bytes
= "bytes";
198 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_state
= "state";
199 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location
= "location";
200 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_local
= "local";
201 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_local_absolute_path
= "absolute_path";
202 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay
= "relay";
203 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_host
= "host";
204 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_control_port
= "control_port";
205 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_data_port
= "data_port";
206 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_protocol
= "protocol";
207 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_relative_path
= "relative_path";
209 /* String related to enum lttng_rotation_state */
210 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_ongoing
= "ONGOING";
211 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_completed
= "COMPLETED";
212 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_expired
= "EXPIRED";
213 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_error
= "ERROR";
215 /* String related to enum lttng_trace_archive_location_relay_protocol_type */
216 LTTNG_HIDDEN
const char * const mi_lttng_rotation_location_relay_protocol_str_tcp
= "TCP";
218 /* String related to add-context command */
219 LTTNG_HIDDEN
const char * const mi_lttng_element_context_symbol
= "symbol";
221 /* Deprecated symbols preserved for ABI compatibility. */
222 const char * const mi_lttng_context_type_perf_counter
;
223 const char * const mi_lttng_context_type_perf_cpu_counter
;
224 const char * const mi_lttng_context_type_perf_thread_counter
;
225 const char * const mi_lttng_element_track_untrack_pid_target
;
226 const char * const mi_lttng_element_track_untrack_targets
;
227 const char * const mi_lttng_element_calibrate
;
228 const char * const mi_lttng_element_calibrate_function
;
229 const char * const mi_lttng_element_command_calibrate
;
231 /* This is a merge of jul loglevel and regular loglevel
232 * Those should never overlap by definition
233 * (see struct lttng_event loglevel)
236 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
239 case LTTNG_DOMAIN_KERNEL
:
240 case LTTNG_DOMAIN_UST
:
243 return mi_lttng_element_empty
;
244 case LTTNG_LOGLEVEL_EMERG
:
245 return mi_lttng_loglevel_str_emerg
;
246 case LTTNG_LOGLEVEL_ALERT
:
247 return mi_lttng_loglevel_str_alert
;
248 case LTTNG_LOGLEVEL_CRIT
:
249 return mi_lttng_loglevel_str_crit
;
250 case LTTNG_LOGLEVEL_ERR
:
251 return mi_lttng_loglevel_str_err
;
252 case LTTNG_LOGLEVEL_WARNING
:
253 return mi_lttng_loglevel_str_warning
;
254 case LTTNG_LOGLEVEL_NOTICE
:
255 return mi_lttng_loglevel_str_notice
;
256 case LTTNG_LOGLEVEL_INFO
:
257 return mi_lttng_loglevel_str_info
;
258 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
259 return mi_lttng_loglevel_str_debug_system
;
260 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
261 return mi_lttng_loglevel_str_debug_program
;
262 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
263 return mi_lttng_loglevel_str_debug_process
;
264 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
265 return mi_lttng_loglevel_str_debug_module
;
266 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
267 return mi_lttng_loglevel_str_debug_unit
;
268 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
269 return mi_lttng_loglevel_str_debug_function
;
270 case LTTNG_LOGLEVEL_DEBUG_LINE
:
271 return mi_lttng_loglevel_str_debug_line
;
272 case LTTNG_LOGLEVEL_DEBUG
:
273 return mi_lttng_loglevel_str_debug
;
275 return mi_lttng_loglevel_str_unknown
;
278 case LTTNG_DOMAIN_LOG4J
:
281 return mi_lttng_element_empty
;
282 case LTTNG_LOGLEVEL_LOG4J_OFF
:
283 return mi_lttng_loglevel_str_log4j_off
;
284 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
285 return mi_lttng_loglevel_str_log4j_fatal
;
286 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
287 return mi_lttng_loglevel_str_log4j_error
;
288 case LTTNG_LOGLEVEL_LOG4J_WARN
:
289 return mi_lttng_loglevel_str_log4j_warn
;
290 case LTTNG_LOGLEVEL_LOG4J_INFO
:
291 return mi_lttng_loglevel_str_log4j_info
;
292 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
293 return mi_lttng_loglevel_str_log4j_debug
;
294 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
295 return mi_lttng_loglevel_str_log4j_trace
;
296 case LTTNG_LOGLEVEL_LOG4J_ALL
:
297 return mi_lttng_loglevel_str_log4j_all
;
299 return mi_lttng_loglevel_str_unknown
;
302 case LTTNG_DOMAIN_JUL
:
305 return mi_lttng_element_empty
;
306 case LTTNG_LOGLEVEL_JUL_OFF
:
307 return mi_lttng_loglevel_str_jul_off
;
308 case LTTNG_LOGLEVEL_JUL_SEVERE
:
309 return mi_lttng_loglevel_str_jul_severe
;
310 case LTTNG_LOGLEVEL_JUL_WARNING
:
311 return mi_lttng_loglevel_str_jul_warning
;
312 case LTTNG_LOGLEVEL_JUL_INFO
:
313 return mi_lttng_loglevel_str_jul_info
;
314 case LTTNG_LOGLEVEL_JUL_CONFIG
:
315 return mi_lttng_loglevel_str_jul_config
;
316 case LTTNG_LOGLEVEL_JUL_FINE
:
317 return mi_lttng_loglevel_str_jul_fine
;
318 case LTTNG_LOGLEVEL_JUL_FINER
:
319 return mi_lttng_loglevel_str_jul_finer
;
320 case LTTNG_LOGLEVEL_JUL_FINEST
:
321 return mi_lttng_loglevel_str_jul_finest
;
322 case LTTNG_LOGLEVEL_JUL_ALL
:
323 return mi_lttng_loglevel_str_jul_all
;
325 return mi_lttng_loglevel_str_unknown
;
328 case LTTNG_DOMAIN_PYTHON
:
330 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
331 return mi_lttng_loglevel_str_python_critical
;
332 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
333 return mi_lttng_loglevel_str_python_error
;
334 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
335 return mi_lttng_loglevel_str_python_warning
;
336 case LTTNG_LOGLEVEL_PYTHON_INFO
:
337 return mi_lttng_loglevel_str_python_info
;
338 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
339 return mi_lttng_loglevel_str_python_debug
;
340 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
341 return mi_lttng_loglevel_str_python_notset
;
343 return mi_lttng_loglevel_str_unknown
;
347 return mi_lttng_loglevel_str_unknown
;
352 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
355 case LTTNG_EVENT_LOGLEVEL_ALL
:
356 return mi_lttng_loglevel_type_all
;
357 case LTTNG_EVENT_LOGLEVEL_RANGE
:
358 return mi_lttng_loglevel_type_range
;
359 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
360 return mi_lttng_loglevel_type_single
;
362 return mi_lttng_loglevel_type_unknown
;
367 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
370 case LTTNG_EVENT_ALL
:
371 return config_event_type_all
;
372 case LTTNG_EVENT_TRACEPOINT
:
373 return config_event_type_tracepoint
;
374 case LTTNG_EVENT_PROBE
:
375 return config_event_type_probe
;
376 case LTTNG_EVENT_USERSPACE_PROBE
:
377 return config_event_type_userspace_probe
;
378 case LTTNG_EVENT_FUNCTION
:
379 return config_event_type_function
;
380 case LTTNG_EVENT_FUNCTION_ENTRY
:
381 return config_event_type_function_entry
;
382 case LTTNG_EVENT_SYSCALL
:
383 return config_event_type_syscall
;
384 case LTTNG_EVENT_NOOP
:
385 return config_event_type_noop
;
387 return mi_lttng_element_empty
;
392 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
395 case LTTNG_EVENT_CONTEXT_PID
:
396 return config_event_context_pid
;
397 case LTTNG_EVENT_CONTEXT_PROCNAME
:
398 return config_event_context_procname
;
399 case LTTNG_EVENT_CONTEXT_PRIO
:
400 return config_event_context_prio
;
401 case LTTNG_EVENT_CONTEXT_NICE
:
402 return config_event_context_nice
;
403 case LTTNG_EVENT_CONTEXT_VPID
:
404 return config_event_context_vpid
;
405 case LTTNG_EVENT_CONTEXT_TID
:
406 return config_event_context_tid
;
407 case LTTNG_EVENT_CONTEXT_VTID
:
408 return config_event_context_vtid
;
409 case LTTNG_EVENT_CONTEXT_PPID
:
410 return config_event_context_ppid
;
411 case LTTNG_EVENT_CONTEXT_VPPID
:
412 return config_event_context_vppid
;
413 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
414 return config_event_context_pthread_id
;
415 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
416 return config_event_context_hostname
;
417 case LTTNG_EVENT_CONTEXT_IP
:
418 return config_event_context_ip
;
419 case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
:
420 return config_event_context_interruptible
;
421 case LTTNG_EVENT_CONTEXT_PREEMPTIBLE
:
422 return config_event_context_preemptible
;
423 case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
:
424 return config_event_context_need_reschedule
;
425 case LTTNG_EVENT_CONTEXT_MIGRATABLE
:
426 return config_event_context_migratable
;
427 case LTTNG_EVENT_CONTEXT_CALLSTACK_USER
:
428 return config_event_context_callstack_user
;
429 case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
:
430 return config_event_context_callstack_kernel
;
431 case LTTNG_EVENT_CONTEXT_CGROUP_NS
:
432 return config_event_context_cgroup_ns
;
433 case LTTNG_EVENT_CONTEXT_IPC_NS
:
434 return config_event_context_ipc_ns
;
435 case LTTNG_EVENT_CONTEXT_MNT_NS
:
436 return config_event_context_mnt_ns
;
437 case LTTNG_EVENT_CONTEXT_NET_NS
:
438 return config_event_context_net_ns
;
439 case LTTNG_EVENT_CONTEXT_PID_NS
:
440 return config_event_context_pid_ns
;
441 case LTTNG_EVENT_CONTEXT_USER_NS
:
442 return config_event_context_user_ns
;
443 case LTTNG_EVENT_CONTEXT_UTS_NS
:
444 return config_event_context_uts_ns
;
445 case LTTNG_EVENT_CONTEXT_UID
:
446 return config_event_context_uid
;
447 case LTTNG_EVENT_CONTEXT_EUID
:
448 return config_event_context_euid
;
449 case LTTNG_EVENT_CONTEXT_SUID
:
450 return config_event_context_suid
;
451 case LTTNG_EVENT_CONTEXT_GID
:
452 return config_event_context_gid
;
453 case LTTNG_EVENT_CONTEXT_EGID
:
454 return config_event_context_egid
;
455 case LTTNG_EVENT_CONTEXT_SGID
:
456 return config_event_context_sgid
;
457 case LTTNG_EVENT_CONTEXT_VUID
:
458 return config_event_context_vuid
;
459 case LTTNG_EVENT_CONTEXT_VEUID
:
460 return config_event_context_veuid
;
461 case LTTNG_EVENT_CONTEXT_VSUID
:
462 return config_event_context_vsuid
;
463 case LTTNG_EVENT_CONTEXT_VGID
:
464 return config_event_context_vgid
;
465 case LTTNG_EVENT_CONTEXT_VEGID
:
466 return config_event_context_vegid
;
467 case LTTNG_EVENT_CONTEXT_VSGID
:
468 return config_event_context_vsgid
;
475 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
478 case(LTTNG_EVENT_FIELD_INTEGER
):
479 return mi_lttng_element_type_integer
;
480 case(LTTNG_EVENT_FIELD_ENUM
):
481 return mi_lttng_element_type_enum
;
482 case(LTTNG_EVENT_FIELD_FLOAT
):
483 return mi_lttng_element_type_float
;
484 case(LTTNG_EVENT_FIELD_STRING
):
485 return mi_lttng_element_type_string
;
487 return mi_lttng_element_type_other
;
492 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
494 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
496 case LTTNG_DOMAIN_KERNEL
:
497 return config_domain_type_kernel
;
498 case LTTNG_DOMAIN_UST
:
499 return config_domain_type_ust
;
500 case LTTNG_DOMAIN_JUL
:
501 return config_domain_type_jul
;
502 case LTTNG_DOMAIN_LOG4J
:
503 return config_domain_type_log4j
;
504 case LTTNG_DOMAIN_PYTHON
:
505 return config_domain_type_python
;
507 /* Should not have an unknown domain */
514 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
517 case LTTNG_BUFFER_PER_PID
:
518 return config_buffer_type_per_pid
;
519 case LTTNG_BUFFER_PER_UID
:
520 return config_buffer_type_per_uid
;
521 case LTTNG_BUFFER_GLOBAL
:
522 return config_buffer_type_global
;
524 /* Should not have an unknow buffer type */
531 const char *mi_lttng_rotation_state_string(enum lttng_rotation_state value
)
534 case LTTNG_ROTATION_STATE_ONGOING
:
535 return mi_lttng_rotation_state_str_ongoing
;
536 case LTTNG_ROTATION_STATE_COMPLETED
:
537 return mi_lttng_rotation_state_str_completed
;
538 case LTTNG_ROTATION_STATE_EXPIRED
:
539 return mi_lttng_rotation_state_str_expired
;
540 case LTTNG_ROTATION_STATE_ERROR
:
541 return mi_lttng_rotation_state_str_error
;
543 /* Should not have an unknow rotation state. */
550 const char *mi_lttng_trace_archive_location_relay_protocol_type_string(
551 enum lttng_trace_archive_location_relay_protocol_type value
)
554 case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP
:
555 return mi_lttng_rotation_location_relay_protocol_str_tcp
;
557 /* Should not have an unknow relay protocol. */
564 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
566 struct mi_writer
*mi_writer
;
568 mi_writer
= zmalloc(sizeof(struct mi_writer
));
570 PERROR("zmalloc mi_writer_create");
573 if (mi_output_type
== LTTNG_MI_XML
) {
574 mi_writer
->writer
= config_writer_create(fd_output
, 0);
575 if (!mi_writer
->writer
) {
578 mi_writer
->type
= LTTNG_MI_XML
;
592 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
601 ret
= config_writer_destroy(writer
->writer
);
612 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
617 * A command is always the MI's root node, it must declare the current
618 * namespace and schema URIs and the schema's version.
620 ret
= config_writer_open_element(writer
->writer
,
621 mi_lttng_element_command
);
626 ret
= config_writer_write_attribute(writer
->writer
,
627 mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
632 ret
= config_writer_write_attribute(writer
->writer
,
633 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
638 ret
= config_writer_write_attribute(writer
->writer
,
639 mi_lttng_schema_location
,
640 mi_lttng_schema_location_uri
);
645 ret
= config_writer_write_attribute(writer
->writer
,
646 mi_lttng_schema_version
,
647 mi_lttng_schema_version_value
);
652 ret
= mi_lttng_writer_write_element_string(writer
,
653 mi_lttng_element_command_name
, command
);
659 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
661 return mi_lttng_writer_close_element(writer
);
665 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
666 const char *element_name
)
668 return config_writer_open_element(writer
->writer
, element_name
);
672 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
674 return config_writer_close_element(writer
->writer
);
678 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
679 unsigned int nb_element
)
683 if (nb_element
< 1) {
687 for (i
= 0; i
< nb_element
; i
++) {
688 ret
= mi_lttng_writer_close_element(writer
);
698 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
699 const char *element_name
, uint64_t value
)
701 return config_writer_write_element_unsigned_int(writer
->writer
,
702 element_name
, value
);
706 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
707 const char *element_name
, int64_t value
)
709 return config_writer_write_element_signed_int(writer
->writer
,
710 element_name
, value
);
714 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
715 const char *element_name
, int value
)
717 return config_writer_write_element_bool(writer
->writer
,
718 element_name
, value
);
722 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
723 const char *element_name
, const char *value
)
725 return config_writer_write_element_string(writer
->writer
,
726 element_name
, value
);
730 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
731 const char *lttng_description
, const char *lttng_license
)
736 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
741 /* Version string (contain info like rc etc.) */
742 ret
= mi_lttng_writer_write_element_string(writer
,
743 mi_lttng_element_version_str
, version
->version
);
748 /* Major version number */
749 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
750 mi_lttng_element_version_major
, version
->version_major
);
755 /* Minor version number */
756 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
757 mi_lttng_element_version_minor
, version
->version_minor
);
762 /* Commit version number */
763 ret
= mi_lttng_writer_write_element_string(writer
,
764 mi_lttng_element_version_commit
, version
->version_commit
);
770 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
771 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
776 /* Name of the version */
777 ret
= mi_lttng_writer_write_element_string(writer
,
778 config_element_name
, version
->version_name
);
783 /* Description mostly related to beer... */
784 ret
= mi_lttng_writer_write_element_string(writer
,
785 mi_lttng_element_version_description
, lttng_description
);
791 ret
= mi_lttng_writer_write_element_string(writer
,
792 mi_lttng_element_version_web
, version
->package_url
);
797 /* License: free as in free beer...no...*speech* */
798 ret
= mi_lttng_writer_write_element_string(writer
,
799 mi_lttng_element_version_license
, lttng_license
);
804 /* Close version element */
805 ret
= mi_lttng_writer_close_element(writer
);
812 int mi_lttng_sessions_open(struct mi_writer
*writer
)
814 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
818 int mi_lttng_session(struct mi_writer
*writer
,
819 struct lttng_session
*session
, int is_open
)
825 /* Open sessions element */
826 ret
= mi_lttng_writer_open_element(writer
,
827 config_element_session
);
832 /* Name of the session */
833 ret
= mi_lttng_writer_write_element_string(writer
,
834 config_element_name
, session
->name
);
840 ret
= mi_lttng_writer_write_element_string(writer
,
841 config_element_path
, session
->path
);
847 ret
= mi_lttng_writer_write_element_bool(writer
,
848 config_element_enabled
, session
->enabled
);
854 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
855 config_element_snapshot_mode
, session
->snapshot_mode
);
860 /* Live timer interval in usec */
861 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
862 config_element_live_timer_interval
,
863 session
->live_timer_interval
);
869 /* Closing session element */
870 ret
= mi_lttng_writer_close_element(writer
);
878 int mi_lttng_domains_open(struct mi_writer
*writer
)
880 return mi_lttng_writer_open_element(writer
, config_element_domains
);
884 int mi_lttng_domain(struct mi_writer
*writer
,
885 struct lttng_domain
*domain
, int is_open
)
888 const char *str_domain
;
889 const char *str_buffer
;
893 /* Open domain element */
894 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
900 str_domain
= mi_lttng_domaintype_string(domain
->type
);
901 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
908 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
909 ret
= mi_lttng_writer_write_element_string(writer
,
910 config_element_buffer_type
, str_buffer
);
916 * This union is not currently used and was added for
917 * future ust domain support.
922 /* Closing domain element */
923 ret
= mi_lttng_writer_close_element(writer
);
932 int mi_lttng_channels_open(struct mi_writer
*writer
)
934 return mi_lttng_writer_open_element(writer
, config_element_channels
);
938 int mi_lttng_channel(struct mi_writer
*writer
,
939 struct lttng_channel
*channel
, int is_open
)
945 /* Opening channel element */
946 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
952 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
959 ret
= mi_lttng_writer_write_element_bool(writer
,
960 config_element_enabled
, channel
->enabled
);
966 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
972 /* Closing channel element */
973 ret
= mi_lttng_writer_close_element(writer
);
983 int mi_lttng_channel_attr(struct mi_writer
*writer
,
984 struct lttng_channel_attr
*attr
)
987 struct lttng_channel
*chan
= caa_container_of(attr
,
988 struct lttng_channel
, attr
);
989 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
990 int64_t blocking_timeout
;
994 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
999 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
1004 ret
= lttng_channel_get_monitor_timer_interval(chan
,
1005 &monitor_timer_interval
);
1010 ret
= lttng_channel_get_blocking_timeout(chan
,
1016 /* Opening Attributes */
1017 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1023 ret
= mi_lttng_writer_write_element_string(writer
,
1024 config_element_overwrite_mode
,
1025 attr
->overwrite
? config_overwrite_mode_overwrite
:
1026 config_overwrite_mode_discard
);
1031 /* Sub buffer size in byte */
1032 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1033 config_element_subbuf_size
, attr
->subbuf_size
);
1038 /* Number of subbuffer (power of two) */
1039 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1040 config_element_num_subbuf
,
1046 /* Switch timer interval in usec */
1047 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1048 config_element_switch_timer_interval
,
1049 attr
->switch_timer_interval
);
1054 /* Read timer interval in usec */
1055 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1056 config_element_read_timer_interval
,
1057 attr
->read_timer_interval
);
1062 /* Monitor timer interval in usec */
1063 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1064 config_element_monitor_timer_interval
,
1065 monitor_timer_interval
);
1070 /* Retry timeout in usec */
1071 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1072 config_element_blocking_timeout
,
1079 ret
= mi_lttng_writer_write_element_string(writer
,
1080 config_element_output_type
,
1081 attr
->output
== LTTNG_EVENT_SPLICE
?
1082 config_output_type_splice
: config_output_type_mmap
);
1087 /* Tracefile size in bytes */
1088 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1089 config_element_tracefile_size
, attr
->tracefile_size
);
1094 /* Count of tracefiles */
1095 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1096 config_element_tracefile_count
,
1097 attr
->tracefile_count
);
1102 /* Live timer interval in usec*/
1103 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1104 config_element_live_timer_interval
,
1105 attr
->live_timer_interval
);
1110 /* Discarded events */
1111 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1112 config_element_discarded_events
,
1119 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1120 config_element_lost_packets
,
1126 /* Closing attributes */
1127 ret
= mi_lttng_writer_close_element(writer
);
1137 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
1138 struct lttng_event
*event
)
1141 const char *filter_expression
;
1143 /* Open event element */
1144 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
1150 ret
= mi_lttng_writer_write_element_string(writer
,
1151 config_element_name
, event
->name
);
1157 ret
= mi_lttng_writer_write_element_string(writer
,
1158 config_element_type
, mi_lttng_eventtype_string(event
->type
));
1163 /* Is event enabled */
1164 ret
= mi_lttng_writer_write_element_bool(writer
,
1165 config_element_enabled
, event
->enabled
);
1170 /* Event filter expression */
1171 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1176 if (filter_expression
) {
1177 ret
= mi_lttng_writer_write_element_string(writer
,
1178 config_element_filter_expression
,
1189 static int write_event_exclusions(struct mi_writer
*writer
,
1190 struct lttng_event
*event
)
1194 int exclusion_count
;
1196 /* Open event exclusions */
1197 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1202 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1203 if (exclusion_count
< 0) {
1204 ret
= exclusion_count
;
1208 for (i
= 0; i
< exclusion_count
; i
++) {
1211 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1213 /* Close exclusions */
1214 mi_lttng_writer_close_element(writer
);
1218 ret
= mi_lttng_writer_write_element_string(writer
,
1219 config_element_exclusion
, name
);
1221 /* Close exclusions */
1222 mi_lttng_writer_close_element(writer
);
1227 /* Close exclusions */
1228 ret
= mi_lttng_writer_close_element(writer
);
1235 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1236 struct lttng_event
*event
, enum lttng_domain_type domain
)
1240 /* Event loglevel */
1241 ret
= mi_lttng_writer_write_element_string(writer
,
1242 config_element_loglevel
,
1243 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1248 /* Log level type */
1249 ret
= mi_lttng_writer_write_element_string(writer
,
1250 config_element_loglevel_type
,
1251 mi_lttng_logleveltype_string(event
->loglevel_type
));
1256 /* Event exclusions */
1257 ret
= write_event_exclusions(writer
, event
);
1264 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1265 struct lttng_event
*event
)
1267 /* event exclusion filter */
1268 return write_event_exclusions(writer
, event
);
1272 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1273 struct lttng_event
*event
)
1277 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1282 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1287 if (event
->attr
.probe
.addr
!= 0) {
1288 /* event probe address */
1289 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1290 config_element_address
, event
->attr
.probe
.addr
);
1295 /* event probe offset */
1296 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1297 config_element_offset
, event
->attr
.probe
.offset
);
1302 /* event probe symbol_name */
1303 ret
= mi_lttng_writer_write_element_string(writer
,
1304 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1310 /* Close probe_attributes and attributes */
1311 ret
= mi_lttng_close_multi_element(writer
, 2);
1317 int mi_lttng_event_userspace_probe(struct mi_writer
*writer
,
1318 struct lttng_event
*event
)
1321 const struct lttng_userspace_probe_location
*location
;
1322 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
1323 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
1325 location
= lttng_event_get_userspace_probe_location(event
);
1327 ret
= -LTTNG_ERR_INVALID
;
1331 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
1332 if (!lookup_method
) {
1333 ret
= -LTTNG_ERR_INVALID
;
1337 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
1339 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1344 switch (lttng_userspace_probe_location_get_type(location
)) {
1345 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1347 const char *function_name
;
1348 const char *binary_path
;
1350 ret
= mi_lttng_writer_open_element(writer
,
1351 config_element_userspace_probe_function_attributes
);
1356 switch (lookup_type
) {
1357 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
1358 ret
= mi_lttng_writer_write_element_string(writer
,
1359 config_element_userspace_probe_lookup
,
1360 config_element_userspace_probe_lookup_function_elf
);
1365 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
1366 ret
= mi_lttng_writer_write_element_string(writer
,
1367 config_element_userspace_probe_lookup
,
1368 config_element_userspace_probe_lookup_function_default
);
1377 binary_path
= lttng_userspace_probe_location_function_get_binary_path(location
);
1378 ret
= mi_lttng_writer_write_element_string(writer
,
1379 config_element_userspace_probe_location_binary_path
, binary_path
);
1384 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
1385 ret
= mi_lttng_writer_write_element_string(writer
,
1386 config_element_userspace_probe_function_location_function_name
,
1394 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1396 const char *probe_name
, *provider_name
;
1397 const char *binary_path
;
1399 ret
= mi_lttng_writer_open_element(writer
,
1400 config_element_userspace_probe_function_attributes
);
1405 switch (lookup_type
) {
1406 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
1407 ret
= mi_lttng_writer_write_element_string(writer
,
1408 config_element_userspace_probe_lookup
,
1409 config_element_userspace_probe_lookup_tracepoint_sdt
);
1418 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(location
);
1419 ret
= mi_lttng_writer_write_element_string(writer
,
1420 config_element_userspace_probe_location_binary_path
,
1426 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
1427 ret
= mi_lttng_writer_write_element_string(writer
,
1428 config_element_userspace_probe_tracepoint_location_provider_name
,
1434 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
1435 ret
= mi_lttng_writer_write_element_string(writer
,
1436 config_element_userspace_probe_tracepoint_location_probe_name
, probe_name
);
1443 ERR("Invalid probe type encountered");
1445 /* Close probe_attributes and attributes */
1446 ret
= mi_lttng_close_multi_element(writer
, 2);
1452 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1453 struct lttng_event
*event
)
1457 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1462 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1467 /* event probe symbol_name */
1468 ret
= mi_lttng_writer_write_element_string(writer
,
1469 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1474 /* Close function_attributes and attributes */
1475 ret
= mi_lttng_close_multi_element(writer
, 2);
1481 int mi_lttng_events_open(struct mi_writer
*writer
)
1483 return mi_lttng_writer_open_element(writer
, config_element_events
);
1487 int mi_lttng_event(struct mi_writer
*writer
,
1488 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1492 ret
= mi_lttng_event_common_attributes(writer
, event
);
1497 switch (event
->type
) {
1498 case LTTNG_EVENT_TRACEPOINT
:
1500 if (event
->loglevel
!= -1) {
1501 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1503 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1507 case LTTNG_EVENT_FUNCTION
:
1509 case LTTNG_EVENT_PROBE
:
1510 ret
= mi_lttng_event_function_probe(writer
, event
);
1512 case LTTNG_EVENT_FUNCTION_ENTRY
:
1513 ret
= mi_lttng_event_function_entry(writer
, event
);
1515 case LTTNG_EVENT_USERSPACE_PROBE
:
1516 ret
= mi_lttng_event_userspace_probe(writer
, event
);
1518 case LTTNG_EVENT_ALL
:
1529 ret
= mi_lttng_writer_close_element(writer
);
1537 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1539 return mi_lttng_writer_open_element(writer
, config_element_trackers
);
1543 int mi_lttng_pid_tracker_open(struct mi_writer
*writer
)
1547 /* Open element pid_tracker */
1548 ret
= mi_lttng_writer_open_element(writer
, config_element_pid_tracker
);
1553 /* Open targets element */
1554 ret
= mi_lttng_targets_open(writer
);
1560 int mi_lttng_pids_open(struct mi_writer
*writer
)
1562 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1566 * TODO: move the listing of pid for user agent to process semantic on
1567 * mi api bump. The use of process element break the mi api.
1570 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *name
,
1575 /* Open pid process */
1576 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1581 /* Writing pid number */
1582 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1583 mi_lttng_element_pid_id
, (int)pid
);
1588 /* Writing name of the process */
1590 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1599 ret
= mi_lttng_writer_close_element(writer
);
1607 int mi_lttng_targets_open(struct mi_writer
*writer
)
1609 return mi_lttng_writer_open_element(writer
,
1610 config_element_targets
);
1614 int mi_lttng_pid_target(struct mi_writer
*writer
, pid_t pid
, int is_open
)
1618 ret
= mi_lttng_writer_open_element(writer
,
1619 config_element_target_pid
);
1624 /* Writing pid number
1625 * Special case for element all on track untrack command
1626 * All pid is represented as wildcard *
1628 if ((int) pid
== -1) {
1629 ret
= mi_lttng_writer_write_element_string(writer
,
1631 mi_lttng_element_track_untrack_all_wildcard
);
1633 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1634 config_element_pid
, (int) pid
);
1641 ret
= mi_lttng_writer_close_element(writer
);
1652 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1654 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1658 int mi_lttng_event_field(struct mi_writer
*writer
,
1659 struct lttng_event_field
*field
)
1663 if (!field
->field_name
[0]) {
1669 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1674 if (!field
->field_name
[0]) {
1679 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1686 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1687 mi_lttng_eventfieldtype_string(field
->type
));
1693 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1694 mi_lttng_element_nowrite
, field
->nowrite
);
1700 /* Close field element */
1701 ret
= mi_lttng_writer_close_element(writer
);
1708 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1709 struct lttng_event_perf_counter_ctx
*perf_context
)
1713 /* Open perf_counter_context */
1714 ret
= mi_lttng_writer_open_element(writer
,
1715 mi_lttng_element_perf_counter_context
);
1721 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1722 config_element_type
, perf_context
->type
);
1728 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1729 config_element_config
, perf_context
->config
);
1734 /* Name of the perf counter */
1735 ret
= mi_lttng_writer_write_element_string(writer
,
1736 config_element_name
, perf_context
->name
);
1741 /* Close perf_counter_context */
1742 ret
= mi_lttng_writer_close_element(writer
);
1748 int mi_lttng_app_context(struct mi_writer
*writer
,
1749 const char *provider_name
, const char *ctx_name
)
1754 ret
= mi_lttng_writer_open_element(writer
,
1755 config_element_context_app
);
1761 ret
= mi_lttng_writer_write_element_string(writer
,
1762 config_element_context_app_provider_name
,
1769 ret
= mi_lttng_writer_write_element_string(writer
,
1770 config_element_context_app_ctx_name
, ctx_name
);
1776 ret
= mi_lttng_writer_close_element(writer
);
1782 int mi_lttng_context(struct mi_writer
*writer
,
1783 struct lttng_event_context
*context
, int is_open
)
1788 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1793 /* Special case for PERF_*_COUNTER
1794 * print the lttng_event_perf_counter_ctx*/
1795 switch (context
->ctx
) {
1796 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1797 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1798 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1800 struct lttng_event_perf_counter_ctx
*perf_context
=
1801 &context
->u
.perf_counter
;
1802 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1808 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
1810 ret
= mi_lttng_app_context(writer
,
1811 context
->u
.app_ctx
.provider_name
,
1812 context
->u
.app_ctx
.ctx_name
);
1820 const char *type_string
= mi_lttng_event_contexttype_string(
1823 ret
= -LTTNG_ERR_INVALID
;
1827 /* Print context type */
1828 ret
= mi_lttng_writer_write_element_string(writer
,
1829 config_element_type
, type_string
);
1836 ret
= mi_lttng_writer_close_element(writer
);
1844 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1845 const char *session_name
)
1849 /* Open session element */
1850 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1855 /* Snapshot output list for current session name */
1856 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1862 /* Open element snapshots (sequence one snapshot) */
1863 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1873 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1874 struct lttng_snapshot_output
*output
)
1878 /* Open element snapshot output */
1879 ret
= mi_lttng_writer_open_element(writer
,
1880 mi_lttng_element_command_snapshot
);
1885 /* ID of the snapshot output */
1886 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1887 mi_lttng_element_id
, output
->id
);
1892 /* Name of the output */
1893 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1899 /* Destination of the output (ctrl_url)*/
1900 ret
= mi_lttng_writer_write_element_string(writer
,
1901 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1906 /* Destination of the output (data_url) */
1907 ret
= mi_lttng_writer_write_element_string(writer
,
1908 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1913 /* total size of all stream combined */
1914 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1915 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1920 /* Close snapshot output element */
1921 ret
= mi_lttng_writer_close_element(writer
);
1928 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1929 const char *name
, const char *current_session_name
)
1933 /* Open element del_snapshot */
1934 ret
= mi_lttng_writer_open_element(writer
,
1935 mi_lttng_element_command_snapshot
);
1941 if (id
!= UINT32_MAX
) {
1942 /* "Snapshot output "id" successfully deleted
1943 * for "current_session_name"
1944 * ID of the snapshot output
1946 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1947 mi_lttng_element_id
, id
);
1952 /* "Snapshot output "name" successfully deleted
1953 * for session "current_session_name"
1954 * Name of the output
1956 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1963 /* Snapshot was deleted for session "current_session_name"*/
1964 ret
= mi_lttng_writer_write_element_string(writer
,
1965 mi_lttng_element_snapshot_session_name
,
1966 current_session_name
);
1971 /* Close snapshot element */
1972 ret
= mi_lttng_writer_close_element(writer
);
1979 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1980 const char *current_session_name
, const char *n_ptr
,
1981 struct lttng_snapshot_output
*output
)
1985 /* Open element snapshot */
1986 ret
= mi_lttng_writer_open_element(writer
,
1987 mi_lttng_element_command_snapshot
);
1992 /* Snapshot output id */
1993 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1994 mi_lttng_element_id
, output
->id
);
1999 /* Snapshot output names */
2000 ret
= mi_lttng_writer_write_element_string(writer
,
2001 config_element_name
, n_ptr
);
2006 /* Destination of the output (ctrl_url)*/
2007 ret
= mi_lttng_writer_write_element_string(writer
,
2008 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2013 /* Snapshot added for session "current_session_name"*/
2014 ret
= mi_lttng_writer_write_element_string(writer
,
2015 mi_lttng_element_snapshot_session_name
, current_session_name
);
2020 /* total size of all stream combined */
2021 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2022 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2027 /* Close snapshot element */
2028 ret
= mi_lttng_writer_close_element(writer
);
2035 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
2036 const char *current_session_name
, const char *url
,
2037 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
2041 /* Open element snapshot */
2042 ret
= mi_lttng_writer_open_element(writer
,
2043 mi_lttng_element_command_snapshot
);
2049 * If a valid an URL was given, serialize it,
2050 * else take the command line data and ctrl urls*/
2052 /* Destination of the output (ctrl_url)*/
2053 ret
= mi_lttng_writer_write_element_string(writer
,
2054 mi_lttng_element_snapshot_ctrl_url
, url
);
2058 } else if (cmdline_ctrl_url
) {
2059 /* Destination of the output (ctrl_url)*/
2060 ret
= mi_lttng_writer_write_element_string(writer
,
2061 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
2066 /* Destination of the output (data_url) */
2067 ret
= mi_lttng_writer_write_element_string(writer
,
2068 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
2074 /* Close record_snapshot element */
2075 ret
= mi_lttng_writer_close_element(writer
);
2082 int mi_lttng_rotation_schedule(struct mi_writer
*writer
,
2083 const struct lttng_rotation_schedule
*schedule
)
2086 enum lttng_rotation_status status
;
2088 const char *element_name
;
2089 const char *value_name
;
2090 bool empty_schedule
= false;
2092 switch (lttng_rotation_schedule_get_type(schedule
)) {
2093 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2094 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
2096 element_name
= mi_lttng_element_rotation_schedule_periodic
;
2097 value_name
= mi_lttng_element_rotation_schedule_periodic_time_us
;
2099 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2100 status
= lttng_rotation_schedule_size_threshold_get_threshold(
2102 element_name
= mi_lttng_element_rotation_schedule_size_threshold
;
2103 value_name
= mi_lttng_element_rotation_schedule_size_threshold_bytes
;
2110 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2111 if (status
== LTTNG_ROTATION_STATUS_UNAVAILABLE
) {
2112 empty_schedule
= true;
2119 ret
= mi_lttng_writer_open_element(writer
, element_name
);
2124 if (!empty_schedule
) {
2125 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2132 /* Close schedule descriptor element. */
2133 ret
= mi_lttng_writer_close_element(writer
);
2142 int mi_lttng_rotation_schedule_result(struct mi_writer
*writer
,
2143 const struct lttng_rotation_schedule
*schedule
,
2148 ret
= mi_lttng_writer_open_element(writer
,
2149 mi_lttng_element_rotation_schedule_result
);
2154 ret
= mi_lttng_writer_open_element(writer
,
2155 mi_lttng_element_rotation_schedule
);
2160 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
2165 /* Close rotation_schedule element */
2166 ret
= mi_lttng_writer_close_element(writer
);
2171 ret
= mi_lttng_writer_write_element_bool(writer
,
2172 mi_lttng_element_command_success
, success
);
2177 /* Close rotation_schedule_result element */
2178 ret
= mi_lttng_writer_close_element(writer
);
2187 int mi_lttng_location(struct mi_writer
*writer
,
2188 const struct lttng_trace_archive_location
*location
)
2191 enum lttng_trace_archive_location_type location_type
;
2192 enum lttng_trace_archive_location_status status
;
2194 location_type
= lttng_trace_archive_location_get_type(location
);
2196 switch (location_type
) {
2197 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
:
2199 const char *absolute_path
;
2201 status
= lttng_trace_archive_location_local_get_absolute_path(
2202 location
, &absolute_path
);
2203 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2208 ret
= mi_lttng_writer_open_element(writer
,
2209 mi_lttng_element_rotation_location_local
);
2215 ret
= mi_lttng_writer_write_element_string(writer
,
2216 mi_lttng_element_rotation_location_local_absolute_path
,
2222 /* Close local element */
2223 ret
= mi_lttng_writer_close_element(writer
);
2229 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
:
2231 uint16_t control_port
, data_port
;
2232 const char *host
, *relative_path
;
2233 enum lttng_trace_archive_location_relay_protocol_type protocol
;
2235 /* Fetch all relay location parameters. */
2236 status
= lttng_trace_archive_location_relay_get_protocol_type(
2237 location
, &protocol
);
2238 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2243 status
= lttng_trace_archive_location_relay_get_host(
2245 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2250 status
= lttng_trace_archive_location_relay_get_control_port(
2251 location
, &control_port
);
2252 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2257 status
= lttng_trace_archive_location_relay_get_data_port(
2258 location
, &data_port
);
2259 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2264 status
= lttng_trace_archive_location_relay_get_relative_path(
2265 location
, &relative_path
);
2266 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2271 ret
= mi_lttng_writer_open_element(writer
,
2272 mi_lttng_element_rotation_location_relay
);
2277 ret
= mi_lttng_writer_write_element_string(writer
,
2278 mi_lttng_element_rotation_location_relay_host
,
2284 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2285 mi_lttng_element_rotation_location_relay_control_port
,
2291 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2292 mi_lttng_element_rotation_location_relay_data_port
,
2298 ret
= mi_lttng_writer_write_element_string(writer
,
2299 mi_lttng_element_rotation_location_relay_protocol
,
2300 mi_lttng_trace_archive_location_relay_protocol_type_string(protocol
));
2305 ret
= mi_lttng_writer_write_element_string(writer
,
2306 mi_lttng_element_rotation_location_relay_relative_path
,
2312 /* Close relay element */
2313 ret
= mi_lttng_writer_close_element(writer
);
2327 int mi_lttng_rotate(struct mi_writer
*writer
,
2328 const char *session_name
,
2329 enum lttng_rotation_state rotation_state
,
2330 const struct lttng_trace_archive_location
*location
)
2334 ret
= mi_lttng_writer_open_element(writer
,
2335 mi_lttng_element_rotation
);
2340 ret
= mi_lttng_writer_write_element_string(writer
,
2341 mi_lttng_element_session_name
,
2347 ret
= mi_lttng_writer_write_element_string(writer
,
2348 mi_lttng_element_rotation_state
,
2349 mi_lttng_rotation_state_string(rotation_state
));
2355 /* Not a serialization error. */
2356 goto close_rotation
;
2359 ret
= mi_lttng_writer_open_element(writer
,
2360 mi_lttng_element_rotation_location
);
2365 ret
= mi_lttng_location(writer
, location
);
2367 goto close_location
;
2371 /* Close location element */
2372 ret
= mi_lttng_writer_close_element(writer
);
2378 /* Close rotation element */
2379 ret
= mi_lttng_writer_close_element(writer
);