2 * Copyright (C) 2014 Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * Copyright (C) 2014 Olivier Cotte <olivier.cotte@polymtl.ca>
4 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * SPDX-License-Identifier: GPL-2.0-only
10 #include "lttng/tracker.h"
13 #include <common/config/session-config.h>
14 #include <common/defaults.h>
15 #include <common/tracker.h>
16 #include <lttng/channel.h>
17 #include <lttng/snapshot-internal.h>
21 #define MI_SCHEMA_MAJOR_VERSION 4
22 #define MI_SCHEMA_MINOR_VERSION 0
24 /* Machine interface namespace URI */
25 LTTNG_HIDDEN
const char * const mi_lttng_xmlns
= "xmlns";
26 LTTNG_HIDDEN
const char * const mi_lttng_xmlns_xsi
= "xmlns:xsi";
27 LTTNG_HIDDEN
const char * const mi_lttng_w3_schema_uri
= "http://www.w3.org/2001/XMLSchema-instance";
28 LTTNG_HIDDEN
const char * const mi_lttng_schema_location
= "xsi:schemaLocation";
29 LTTNG_HIDDEN
const char * const mi_lttng_schema_location_uri
=
30 DEFAULT_LTTNG_MI_NAMESPACE
" "
31 "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION
)
32 "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION
) "."
33 XSTR(MI_SCHEMA_MINOR_VERSION
) ".xsd";
34 LTTNG_HIDDEN
const char * const mi_lttng_schema_version
= "schemaVersion";
35 LTTNG_HIDDEN
const char * const mi_lttng_schema_version_value
= XSTR(MI_SCHEMA_MAJOR_VERSION
)
36 "." XSTR(MI_SCHEMA_MINOR_VERSION
);
38 /* Strings related to command */
39 const char * const mi_lttng_element_command
= "command";
40 const char * const mi_lttng_element_command_action
= "snapshot_action";
41 const char * const mi_lttng_element_command_add_context
= "add-context";
42 const char * const mi_lttng_element_command_create
= "create";
43 const char * const mi_lttng_element_command_destroy
= "destroy";
44 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
45 const char * const mi_lttng_element_command_disable_event
= "disable-event";
46 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
47 const char * const mi_lttng_element_command_enable_event
= "enable-event";
48 const char * const mi_lttng_element_command_list
= "list";
49 const char * const mi_lttng_element_command_load
= "load";
50 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata
= "metadata";
51 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata_action
= "metadata_action";
52 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate
= "regenerate";
53 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate_action
= "regenerate_action";
54 const char * const mi_lttng_element_command_name
= "name";
55 const char * const mi_lttng_element_command_output
= "output";
56 const char * const mi_lttng_element_command_save
= "save";
57 const char * const mi_lttng_element_command_set_session
= "set-session";
58 const char * const mi_lttng_element_command_snapshot
= "snapshot";
59 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
60 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
61 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
62 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
63 const char * const mi_lttng_element_command_start
= "start";
64 const char * const mi_lttng_element_command_stop
= "stop";
65 const char * const mi_lttng_element_command_success
= "success";
66 const char * const mi_lttng_element_command_track
= "track";
67 const char * const mi_lttng_element_command_untrack
= "untrack";
68 const char * const mi_lttng_element_command_version
= "version";
69 LTTNG_HIDDEN
const char * const mi_lttng_element_command_rotate
= "rotate";
70 LTTNG_HIDDEN
const char * const mi_lttng_element_command_enable_rotation
= "enable-rotation";
71 LTTNG_HIDDEN
const char * const mi_lttng_element_command_disable_rotation
= "disable-rotation";
72 LTTNG_HIDDEN
const char * const mi_lttng_element_command_clear
= "clear";
74 /* Strings related to version command */
75 const char * const mi_lttng_element_version
= "version";
76 const char * const mi_lttng_element_version_commit
= "commit";
77 const char * const mi_lttng_element_version_description
= "description";
78 const char * const mi_lttng_element_version_license
= "license";
79 const char * const mi_lttng_element_version_major
= "major";
80 const char * const mi_lttng_element_version_minor
= "minor";
81 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
82 const char * const mi_lttng_element_version_str
= "string";
83 const char * const mi_lttng_element_version_web
= "url";
85 /* String related to a lttng_event_field */
86 const char * const mi_lttng_element_event_field
= "event_field";
87 const char * const mi_lttng_element_event_fields
= "event_fields";
89 /* String related to lttng_event_perf_counter_ctx */
90 const char * const mi_lttng_element_perf_counter_context
= "perf";
92 /* Strings related to pid */
93 const char * const mi_lttng_element_pid_id
= "id";
95 /* Strings related to save command */
96 const char * const mi_lttng_element_save
= "save";
98 /* Strings related to load command */
99 const char * const mi_lttng_element_load
= "load";
100 LTTNG_HIDDEN
const char * const mi_lttng_element_load_overrides
= "overrides";
101 LTTNG_HIDDEN
const char * const mi_lttng_element_load_override_url
= "url";
103 /* General elements of mi_lttng */
104 const char * const mi_lttng_element_empty
= "";
105 const char * const mi_lttng_element_id
= "id";
106 const char * const mi_lttng_element_nowrite
= "nowrite";
107 const char * const mi_lttng_element_success
= "success";
108 const char * const mi_lttng_element_type_enum
= "ENUM";
109 const char * const mi_lttng_element_type_float
= "FLOAT";
110 const char * const mi_lttng_element_type_integer
= "INTEGER";
111 const char * const mi_lttng_element_type_other
= "OTHER";
112 const char * const mi_lttng_element_type_string
= "STRING";
114 /* String related to loglevel */
115 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
116 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
117 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
118 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
119 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
120 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
121 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
122 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
123 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
124 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
125 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
126 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
127 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
128 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
129 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
130 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
132 /* String related to loglevel JUL */
133 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
134 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
135 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
136 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
137 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
138 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
139 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
140 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
141 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
143 /* String related to loglevel LOG4J */
144 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
145 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
146 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
147 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
148 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
149 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
150 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
151 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
153 /* String related to loglevel Python */
154 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
155 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
156 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
157 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
158 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
159 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
161 /* String related to loglevel type */
162 const char * const mi_lttng_loglevel_type_all
= "ALL";
163 const char * const mi_lttng_loglevel_type_range
= "RANGE";
164 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
165 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
167 /* String related to a lttng_snapshot_output */
168 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
169 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
170 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
171 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
172 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
173 const char * const mi_lttng_element_snapshots
= "snapshots";
175 /* String related to track/untrack command */
176 const char * const mi_lttng_element_track_untrack_all_wildcard
= "*";
178 LTTNG_HIDDEN
const char * const mi_lttng_element_session_name
= "session_name";
180 /* String related to rotate command */
181 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation
= "rotation";
182 LTTNG_HIDDEN
const char * const mi_lttng_element_rotate_status
= "status";
183 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule
= "rotation_schedule";
184 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedules
= "rotation_schedules";
185 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_result
= "rotation_schedule_result";
186 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_results
= "rotation_schedule_results";
187 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_periodic
= "periodic";
188 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_periodic_time_us
= "time_us";
189 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_size_threshold
= "size_threshold";
190 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_size_threshold_bytes
= "bytes";
191 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_state
= "state";
192 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location
= "location";
193 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_local
= "local";
194 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_local_absolute_path
= "absolute_path";
195 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay
= "relay";
196 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_host
= "host";
197 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_control_port
= "control_port";
198 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_data_port
= "data_port";
199 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_protocol
= "protocol";
200 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_relative_path
= "relative_path";
202 /* String related to enum lttng_rotation_state */
203 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_ongoing
= "ONGOING";
204 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_completed
= "COMPLETED";
205 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_expired
= "EXPIRED";
206 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_error
= "ERROR";
208 /* String related to enum lttng_trace_archive_location_relay_protocol_type */
209 LTTNG_HIDDEN
const char * const mi_lttng_rotation_location_relay_protocol_str_tcp
= "TCP";
211 /* String related to add-context command */
212 LTTNG_HIDDEN
const char * const mi_lttng_element_context_symbol
= "symbol";
214 /* Deprecated symbols preserved for ABI compatibility. */
215 const char * const mi_lttng_context_type_perf_counter
;
216 const char * const mi_lttng_context_type_perf_cpu_counter
;
217 const char * const mi_lttng_context_type_perf_thread_counter
;
218 const char * const mi_lttng_element_track_untrack_pid_target
;
219 const char * const mi_lttng_element_track_untrack_targets
;
220 const char * const mi_lttng_element_calibrate
;
221 const char * const mi_lttng_element_calibrate_function
;
222 const char * const mi_lttng_element_command_calibrate
;
224 /* This is a merge of jul loglevel and regular loglevel
225 * Those should never overlap by definition
226 * (see struct lttng_event loglevel)
229 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
232 case LTTNG_DOMAIN_KERNEL
:
233 case LTTNG_DOMAIN_UST
:
236 return mi_lttng_element_empty
;
237 case LTTNG_LOGLEVEL_EMERG
:
238 return mi_lttng_loglevel_str_emerg
;
239 case LTTNG_LOGLEVEL_ALERT
:
240 return mi_lttng_loglevel_str_alert
;
241 case LTTNG_LOGLEVEL_CRIT
:
242 return mi_lttng_loglevel_str_crit
;
243 case LTTNG_LOGLEVEL_ERR
:
244 return mi_lttng_loglevel_str_err
;
245 case LTTNG_LOGLEVEL_WARNING
:
246 return mi_lttng_loglevel_str_warning
;
247 case LTTNG_LOGLEVEL_NOTICE
:
248 return mi_lttng_loglevel_str_notice
;
249 case LTTNG_LOGLEVEL_INFO
:
250 return mi_lttng_loglevel_str_info
;
251 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
252 return mi_lttng_loglevel_str_debug_system
;
253 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
254 return mi_lttng_loglevel_str_debug_program
;
255 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
256 return mi_lttng_loglevel_str_debug_process
;
257 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
258 return mi_lttng_loglevel_str_debug_module
;
259 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
260 return mi_lttng_loglevel_str_debug_unit
;
261 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
262 return mi_lttng_loglevel_str_debug_function
;
263 case LTTNG_LOGLEVEL_DEBUG_LINE
:
264 return mi_lttng_loglevel_str_debug_line
;
265 case LTTNG_LOGLEVEL_DEBUG
:
266 return mi_lttng_loglevel_str_debug
;
268 return mi_lttng_loglevel_str_unknown
;
271 case LTTNG_DOMAIN_LOG4J
:
274 return mi_lttng_element_empty
;
275 case LTTNG_LOGLEVEL_LOG4J_OFF
:
276 return mi_lttng_loglevel_str_log4j_off
;
277 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
278 return mi_lttng_loglevel_str_log4j_fatal
;
279 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
280 return mi_lttng_loglevel_str_log4j_error
;
281 case LTTNG_LOGLEVEL_LOG4J_WARN
:
282 return mi_lttng_loglevel_str_log4j_warn
;
283 case LTTNG_LOGLEVEL_LOG4J_INFO
:
284 return mi_lttng_loglevel_str_log4j_info
;
285 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
286 return mi_lttng_loglevel_str_log4j_debug
;
287 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
288 return mi_lttng_loglevel_str_log4j_trace
;
289 case LTTNG_LOGLEVEL_LOG4J_ALL
:
290 return mi_lttng_loglevel_str_log4j_all
;
292 return mi_lttng_loglevel_str_unknown
;
295 case LTTNG_DOMAIN_JUL
:
298 return mi_lttng_element_empty
;
299 case LTTNG_LOGLEVEL_JUL_OFF
:
300 return mi_lttng_loglevel_str_jul_off
;
301 case LTTNG_LOGLEVEL_JUL_SEVERE
:
302 return mi_lttng_loglevel_str_jul_severe
;
303 case LTTNG_LOGLEVEL_JUL_WARNING
:
304 return mi_lttng_loglevel_str_jul_warning
;
305 case LTTNG_LOGLEVEL_JUL_INFO
:
306 return mi_lttng_loglevel_str_jul_info
;
307 case LTTNG_LOGLEVEL_JUL_CONFIG
:
308 return mi_lttng_loglevel_str_jul_config
;
309 case LTTNG_LOGLEVEL_JUL_FINE
:
310 return mi_lttng_loglevel_str_jul_fine
;
311 case LTTNG_LOGLEVEL_JUL_FINER
:
312 return mi_lttng_loglevel_str_jul_finer
;
313 case LTTNG_LOGLEVEL_JUL_FINEST
:
314 return mi_lttng_loglevel_str_jul_finest
;
315 case LTTNG_LOGLEVEL_JUL_ALL
:
316 return mi_lttng_loglevel_str_jul_all
;
318 return mi_lttng_loglevel_str_unknown
;
321 case LTTNG_DOMAIN_PYTHON
:
323 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
324 return mi_lttng_loglevel_str_python_critical
;
325 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
326 return mi_lttng_loglevel_str_python_error
;
327 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
328 return mi_lttng_loglevel_str_python_warning
;
329 case LTTNG_LOGLEVEL_PYTHON_INFO
:
330 return mi_lttng_loglevel_str_python_info
;
331 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
332 return mi_lttng_loglevel_str_python_debug
;
333 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
334 return mi_lttng_loglevel_str_python_notset
;
336 return mi_lttng_loglevel_str_unknown
;
340 return mi_lttng_loglevel_str_unknown
;
345 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
348 case LTTNG_EVENT_LOGLEVEL_ALL
:
349 return mi_lttng_loglevel_type_all
;
350 case LTTNG_EVENT_LOGLEVEL_RANGE
:
351 return mi_lttng_loglevel_type_range
;
352 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
353 return mi_lttng_loglevel_type_single
;
355 return mi_lttng_loglevel_type_unknown
;
360 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
363 case LTTNG_EVENT_ALL
:
364 return config_event_type_all
;
365 case LTTNG_EVENT_TRACEPOINT
:
366 return config_event_type_tracepoint
;
367 case LTTNG_EVENT_PROBE
:
368 return config_event_type_probe
;
369 case LTTNG_EVENT_USERSPACE_PROBE
:
370 return config_event_type_userspace_probe
;
371 case LTTNG_EVENT_FUNCTION
:
372 return config_event_type_function
;
373 case LTTNG_EVENT_FUNCTION_ENTRY
:
374 return config_event_type_function_entry
;
375 case LTTNG_EVENT_SYSCALL
:
376 return config_event_type_syscall
;
377 case LTTNG_EVENT_NOOP
:
378 return config_event_type_noop
;
380 return mi_lttng_element_empty
;
385 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
388 case LTTNG_EVENT_CONTEXT_PID
:
389 return config_event_context_pid
;
390 case LTTNG_EVENT_CONTEXT_PROCNAME
:
391 return config_event_context_procname
;
392 case LTTNG_EVENT_CONTEXT_PRIO
:
393 return config_event_context_prio
;
394 case LTTNG_EVENT_CONTEXT_NICE
:
395 return config_event_context_nice
;
396 case LTTNG_EVENT_CONTEXT_VPID
:
397 return config_event_context_vpid
;
398 case LTTNG_EVENT_CONTEXT_TID
:
399 return config_event_context_tid
;
400 case LTTNG_EVENT_CONTEXT_VTID
:
401 return config_event_context_vtid
;
402 case LTTNG_EVENT_CONTEXT_PPID
:
403 return config_event_context_ppid
;
404 case LTTNG_EVENT_CONTEXT_VPPID
:
405 return config_event_context_vppid
;
406 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
407 return config_event_context_pthread_id
;
408 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
409 return config_event_context_hostname
;
410 case LTTNG_EVENT_CONTEXT_IP
:
411 return config_event_context_ip
;
412 case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
:
413 return config_event_context_interruptible
;
414 case LTTNG_EVENT_CONTEXT_PREEMPTIBLE
:
415 return config_event_context_preemptible
;
416 case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
:
417 return config_event_context_need_reschedule
;
418 case LTTNG_EVENT_CONTEXT_MIGRATABLE
:
419 return config_event_context_migratable
;
420 case LTTNG_EVENT_CONTEXT_CALLSTACK_USER
:
421 return config_event_context_callstack_user
;
422 case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
:
423 return config_event_context_callstack_kernel
;
424 case LTTNG_EVENT_CONTEXT_CGROUP_NS
:
425 return config_event_context_cgroup_ns
;
426 case LTTNG_EVENT_CONTEXT_IPC_NS
:
427 return config_event_context_ipc_ns
;
428 case LTTNG_EVENT_CONTEXT_MNT_NS
:
429 return config_event_context_mnt_ns
;
430 case LTTNG_EVENT_CONTEXT_NET_NS
:
431 return config_event_context_net_ns
;
432 case LTTNG_EVENT_CONTEXT_PID_NS
:
433 return config_event_context_pid_ns
;
434 case LTTNG_EVENT_CONTEXT_TIME_NS
:
435 return config_event_context_time_ns
;
436 case LTTNG_EVENT_CONTEXT_USER_NS
:
437 return config_event_context_user_ns
;
438 case LTTNG_EVENT_CONTEXT_UTS_NS
:
439 return config_event_context_uts_ns
;
440 case LTTNG_EVENT_CONTEXT_UID
:
441 return config_event_context_uid
;
442 case LTTNG_EVENT_CONTEXT_EUID
:
443 return config_event_context_euid
;
444 case LTTNG_EVENT_CONTEXT_SUID
:
445 return config_event_context_suid
;
446 case LTTNG_EVENT_CONTEXT_GID
:
447 return config_event_context_gid
;
448 case LTTNG_EVENT_CONTEXT_EGID
:
449 return config_event_context_egid
;
450 case LTTNG_EVENT_CONTEXT_SGID
:
451 return config_event_context_sgid
;
452 case LTTNG_EVENT_CONTEXT_VUID
:
453 return config_event_context_vuid
;
454 case LTTNG_EVENT_CONTEXT_VEUID
:
455 return config_event_context_veuid
;
456 case LTTNG_EVENT_CONTEXT_VSUID
:
457 return config_event_context_vsuid
;
458 case LTTNG_EVENT_CONTEXT_VGID
:
459 return config_event_context_vgid
;
460 case LTTNG_EVENT_CONTEXT_VEGID
:
461 return config_event_context_vegid
;
462 case LTTNG_EVENT_CONTEXT_VSGID
:
463 return config_event_context_vsgid
;
470 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
473 case(LTTNG_EVENT_FIELD_INTEGER
):
474 return mi_lttng_element_type_integer
;
475 case(LTTNG_EVENT_FIELD_ENUM
):
476 return mi_lttng_element_type_enum
;
477 case(LTTNG_EVENT_FIELD_FLOAT
):
478 return mi_lttng_element_type_float
;
479 case(LTTNG_EVENT_FIELD_STRING
):
480 return mi_lttng_element_type_string
;
482 return mi_lttng_element_type_other
;
487 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
489 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
491 case LTTNG_DOMAIN_KERNEL
:
492 return config_domain_type_kernel
;
493 case LTTNG_DOMAIN_UST
:
494 return config_domain_type_ust
;
495 case LTTNG_DOMAIN_JUL
:
496 return config_domain_type_jul
;
497 case LTTNG_DOMAIN_LOG4J
:
498 return config_domain_type_log4j
;
499 case LTTNG_DOMAIN_PYTHON
:
500 return config_domain_type_python
;
502 /* Should not have an unknown domain */
509 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
512 case LTTNG_BUFFER_PER_PID
:
513 return config_buffer_type_per_pid
;
514 case LTTNG_BUFFER_PER_UID
:
515 return config_buffer_type_per_uid
;
516 case LTTNG_BUFFER_GLOBAL
:
517 return config_buffer_type_global
;
519 /* Should not have an unknow buffer type */
526 const char *mi_lttng_rotation_state_string(enum lttng_rotation_state value
)
529 case LTTNG_ROTATION_STATE_ONGOING
:
530 return mi_lttng_rotation_state_str_ongoing
;
531 case LTTNG_ROTATION_STATE_COMPLETED
:
532 return mi_lttng_rotation_state_str_completed
;
533 case LTTNG_ROTATION_STATE_EXPIRED
:
534 return mi_lttng_rotation_state_str_expired
;
535 case LTTNG_ROTATION_STATE_ERROR
:
536 return mi_lttng_rotation_state_str_error
;
538 /* Should not have an unknow rotation state. */
545 const char *mi_lttng_trace_archive_location_relay_protocol_type_string(
546 enum lttng_trace_archive_location_relay_protocol_type value
)
549 case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP
:
550 return mi_lttng_rotation_location_relay_protocol_str_tcp
;
552 /* Should not have an unknow relay protocol. */
559 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
561 struct mi_writer
*mi_writer
;
563 mi_writer
= zmalloc(sizeof(struct mi_writer
));
565 PERROR("zmalloc mi_writer_create");
568 if (mi_output_type
== LTTNG_MI_XML
) {
569 mi_writer
->writer
= config_writer_create(fd_output
, 0);
570 if (!mi_writer
->writer
) {
573 mi_writer
->type
= LTTNG_MI_XML
;
587 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
596 ret
= config_writer_destroy(writer
->writer
);
607 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
612 * A command is always the MI's root node, it must declare the current
613 * namespace and schema URIs and the schema's version.
615 ret
= config_writer_open_element(writer
->writer
,
616 mi_lttng_element_command
);
621 ret
= config_writer_write_attribute(writer
->writer
,
622 mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
627 ret
= config_writer_write_attribute(writer
->writer
,
628 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
633 ret
= config_writer_write_attribute(writer
->writer
,
634 mi_lttng_schema_location
,
635 mi_lttng_schema_location_uri
);
640 ret
= config_writer_write_attribute(writer
->writer
,
641 mi_lttng_schema_version
,
642 mi_lttng_schema_version_value
);
647 ret
= mi_lttng_writer_write_element_string(writer
,
648 mi_lttng_element_command_name
, command
);
654 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
656 return mi_lttng_writer_close_element(writer
);
660 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
661 const char *element_name
)
663 return config_writer_open_element(writer
->writer
, element_name
);
667 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
669 return config_writer_close_element(writer
->writer
);
673 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
674 unsigned int nb_element
)
678 if (nb_element
< 1) {
682 for (i
= 0; i
< nb_element
; i
++) {
683 ret
= mi_lttng_writer_close_element(writer
);
693 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
694 const char *element_name
, uint64_t value
)
696 return config_writer_write_element_unsigned_int(writer
->writer
,
697 element_name
, value
);
701 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
702 const char *element_name
, int64_t value
)
704 return config_writer_write_element_signed_int(writer
->writer
,
705 element_name
, value
);
709 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
710 const char *element_name
, int value
)
712 return config_writer_write_element_bool(writer
->writer
,
713 element_name
, value
);
717 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
718 const char *element_name
, const char *value
)
720 return config_writer_write_element_string(writer
->writer
,
721 element_name
, value
);
725 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
726 const char *lttng_description
, const char *lttng_license
)
731 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
736 /* Version string (contain info like rc etc.) */
737 ret
= mi_lttng_writer_write_element_string(writer
,
738 mi_lttng_element_version_str
, version
->version
);
743 /* Major version number */
744 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
745 mi_lttng_element_version_major
, version
->version_major
);
750 /* Minor version number */
751 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
752 mi_lttng_element_version_minor
, version
->version_minor
);
757 /* Commit version number */
758 ret
= mi_lttng_writer_write_element_string(writer
,
759 mi_lttng_element_version_commit
, version
->version_commit
);
765 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
766 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
771 /* Name of the version */
772 ret
= mi_lttng_writer_write_element_string(writer
,
773 config_element_name
, version
->version_name
);
778 /* Description mostly related to beer... */
779 ret
= mi_lttng_writer_write_element_string(writer
,
780 mi_lttng_element_version_description
, lttng_description
);
786 ret
= mi_lttng_writer_write_element_string(writer
,
787 mi_lttng_element_version_web
, version
->package_url
);
792 /* License: free as in free beer...no...*speech* */
793 ret
= mi_lttng_writer_write_element_string(writer
,
794 mi_lttng_element_version_license
, lttng_license
);
799 /* Close version element */
800 ret
= mi_lttng_writer_close_element(writer
);
807 int mi_lttng_sessions_open(struct mi_writer
*writer
)
809 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
813 int mi_lttng_session(struct mi_writer
*writer
,
814 struct lttng_session
*session
, int is_open
)
820 /* Open sessions element */
821 ret
= mi_lttng_writer_open_element(writer
,
822 config_element_session
);
827 /* Name of the session */
828 ret
= mi_lttng_writer_write_element_string(writer
,
829 config_element_name
, session
->name
);
835 ret
= mi_lttng_writer_write_element_string(writer
,
836 config_element_path
, session
->path
);
842 ret
= mi_lttng_writer_write_element_bool(writer
,
843 config_element_enabled
, session
->enabled
);
849 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
850 config_element_snapshot_mode
, session
->snapshot_mode
);
855 /* Live timer interval in usec */
856 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
857 config_element_live_timer_interval
,
858 session
->live_timer_interval
);
864 /* Closing session element */
865 ret
= mi_lttng_writer_close_element(writer
);
873 int mi_lttng_domains_open(struct mi_writer
*writer
)
875 return mi_lttng_writer_open_element(writer
, config_element_domains
);
879 int mi_lttng_domain(struct mi_writer
*writer
,
880 struct lttng_domain
*domain
, int is_open
)
883 const char *str_domain
;
884 const char *str_buffer
;
888 /* Open domain element */
889 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
895 str_domain
= mi_lttng_domaintype_string(domain
->type
);
896 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
903 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
904 ret
= mi_lttng_writer_write_element_string(writer
,
905 config_element_buffer_type
, str_buffer
);
911 * This union is not currently used and was added for
912 * future ust domain support.
917 /* Closing domain element */
918 ret
= mi_lttng_writer_close_element(writer
);
927 int mi_lttng_channels_open(struct mi_writer
*writer
)
929 return mi_lttng_writer_open_element(writer
, config_element_channels
);
933 int mi_lttng_channel(struct mi_writer
*writer
,
934 struct lttng_channel
*channel
, int is_open
)
940 /* Opening channel element */
941 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
947 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
954 ret
= mi_lttng_writer_write_element_bool(writer
,
955 config_element_enabled
, channel
->enabled
);
961 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
967 /* Closing channel element */
968 ret
= mi_lttng_writer_close_element(writer
);
978 int mi_lttng_channel_attr(struct mi_writer
*writer
,
979 struct lttng_channel_attr
*attr
)
982 struct lttng_channel
*chan
= caa_container_of(attr
,
983 struct lttng_channel
, attr
);
984 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
985 int64_t blocking_timeout
;
989 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
994 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
999 ret
= lttng_channel_get_monitor_timer_interval(chan
,
1000 &monitor_timer_interval
);
1005 ret
= lttng_channel_get_blocking_timeout(chan
,
1011 /* Opening Attributes */
1012 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1018 ret
= mi_lttng_writer_write_element_string(writer
,
1019 config_element_overwrite_mode
,
1020 attr
->overwrite
? config_overwrite_mode_overwrite
:
1021 config_overwrite_mode_discard
);
1026 /* Sub buffer size in byte */
1027 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1028 config_element_subbuf_size
, attr
->subbuf_size
);
1033 /* Number of subbuffer (power of two) */
1034 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1035 config_element_num_subbuf
,
1041 /* Switch timer interval in usec */
1042 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1043 config_element_switch_timer_interval
,
1044 attr
->switch_timer_interval
);
1049 /* Read timer interval in usec */
1050 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1051 config_element_read_timer_interval
,
1052 attr
->read_timer_interval
);
1057 /* Monitor timer interval in usec */
1058 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1059 config_element_monitor_timer_interval
,
1060 monitor_timer_interval
);
1065 /* Retry timeout in usec */
1066 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1067 config_element_blocking_timeout
,
1074 ret
= mi_lttng_writer_write_element_string(writer
,
1075 config_element_output_type
,
1076 attr
->output
== LTTNG_EVENT_SPLICE
?
1077 config_output_type_splice
: config_output_type_mmap
);
1082 /* Tracefile size in bytes */
1083 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1084 config_element_tracefile_size
, attr
->tracefile_size
);
1089 /* Count of tracefiles */
1090 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1091 config_element_tracefile_count
,
1092 attr
->tracefile_count
);
1097 /* Live timer interval in usec*/
1098 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1099 config_element_live_timer_interval
,
1100 attr
->live_timer_interval
);
1105 /* Discarded events */
1106 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1107 config_element_discarded_events
,
1114 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1115 config_element_lost_packets
,
1121 /* Closing attributes */
1122 ret
= mi_lttng_writer_close_element(writer
);
1132 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
1133 struct lttng_event
*event
)
1136 const char *filter_expression
;
1138 /* Open event element */
1139 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
1145 ret
= mi_lttng_writer_write_element_string(writer
,
1146 config_element_name
, event
->name
);
1152 ret
= mi_lttng_writer_write_element_string(writer
,
1153 config_element_type
, mi_lttng_eventtype_string(event
->type
));
1158 /* Is event enabled */
1159 ret
= mi_lttng_writer_write_element_bool(writer
,
1160 config_element_enabled
, event
->enabled
);
1165 /* Event filter expression */
1166 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1171 if (filter_expression
) {
1172 ret
= mi_lttng_writer_write_element_string(writer
,
1173 config_element_filter_expression
,
1184 static int write_event_exclusions(struct mi_writer
*writer
,
1185 struct lttng_event
*event
)
1189 int exclusion_count
;
1191 /* Open event exclusions */
1192 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1197 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1198 if (exclusion_count
< 0) {
1199 ret
= exclusion_count
;
1203 for (i
= 0; i
< exclusion_count
; i
++) {
1206 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1208 /* Close exclusions */
1209 mi_lttng_writer_close_element(writer
);
1213 ret
= mi_lttng_writer_write_element_string(writer
,
1214 config_element_exclusion
, name
);
1216 /* Close exclusions */
1217 mi_lttng_writer_close_element(writer
);
1222 /* Close exclusions */
1223 ret
= mi_lttng_writer_close_element(writer
);
1230 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1231 struct lttng_event
*event
, enum lttng_domain_type domain
)
1235 /* Event loglevel */
1236 ret
= mi_lttng_writer_write_element_string(writer
,
1237 config_element_loglevel
,
1238 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1243 /* Log level type */
1244 ret
= mi_lttng_writer_write_element_string(writer
,
1245 config_element_loglevel_type
,
1246 mi_lttng_logleveltype_string(event
->loglevel_type
));
1251 /* Event exclusions */
1252 ret
= write_event_exclusions(writer
, event
);
1259 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1260 struct lttng_event
*event
)
1262 /* event exclusion filter */
1263 return write_event_exclusions(writer
, event
);
1267 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1268 struct lttng_event
*event
)
1272 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1277 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1282 if (event
->attr
.probe
.addr
!= 0) {
1283 /* event probe address */
1284 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1285 config_element_address
, event
->attr
.probe
.addr
);
1290 /* event probe offset */
1291 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1292 config_element_offset
, event
->attr
.probe
.offset
);
1297 /* event probe symbol_name */
1298 ret
= mi_lttng_writer_write_element_string(writer
,
1299 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1305 /* Close probe_attributes and attributes */
1306 ret
= mi_lttng_close_multi_element(writer
, 2);
1312 int mi_lttng_event_userspace_probe(struct mi_writer
*writer
,
1313 struct lttng_event
*event
)
1316 const struct lttng_userspace_probe_location
*location
;
1317 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
1318 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
1320 location
= lttng_event_get_userspace_probe_location(event
);
1322 ret
= -LTTNG_ERR_INVALID
;
1326 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
1327 if (!lookup_method
) {
1328 ret
= -LTTNG_ERR_INVALID
;
1332 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
1334 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1339 switch (lttng_userspace_probe_location_get_type(location
)) {
1340 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1342 const char *function_name
;
1343 const char *binary_path
;
1345 ret
= mi_lttng_writer_open_element(writer
,
1346 config_element_userspace_probe_function_attributes
);
1351 switch (lookup_type
) {
1352 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
1353 ret
= mi_lttng_writer_write_element_string(writer
,
1354 config_element_userspace_probe_lookup
,
1355 config_element_userspace_probe_lookup_function_elf
);
1360 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
1361 ret
= mi_lttng_writer_write_element_string(writer
,
1362 config_element_userspace_probe_lookup
,
1363 config_element_userspace_probe_lookup_function_default
);
1372 binary_path
= lttng_userspace_probe_location_function_get_binary_path(location
);
1373 ret
= mi_lttng_writer_write_element_string(writer
,
1374 config_element_userspace_probe_location_binary_path
, binary_path
);
1379 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
1380 ret
= mi_lttng_writer_write_element_string(writer
,
1381 config_element_userspace_probe_function_location_function_name
,
1389 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1391 const char *probe_name
, *provider_name
;
1392 const char *binary_path
;
1394 ret
= mi_lttng_writer_open_element(writer
,
1395 config_element_userspace_probe_function_attributes
);
1400 switch (lookup_type
) {
1401 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
1402 ret
= mi_lttng_writer_write_element_string(writer
,
1403 config_element_userspace_probe_lookup
,
1404 config_element_userspace_probe_lookup_tracepoint_sdt
);
1413 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(location
);
1414 ret
= mi_lttng_writer_write_element_string(writer
,
1415 config_element_userspace_probe_location_binary_path
,
1421 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
1422 ret
= mi_lttng_writer_write_element_string(writer
,
1423 config_element_userspace_probe_tracepoint_location_provider_name
,
1429 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
1430 ret
= mi_lttng_writer_write_element_string(writer
,
1431 config_element_userspace_probe_tracepoint_location_probe_name
, probe_name
);
1438 ERR("Invalid probe type encountered");
1440 /* Close probe_attributes and attributes */
1441 ret
= mi_lttng_close_multi_element(writer
, 2);
1447 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1448 struct lttng_event
*event
)
1452 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1457 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1462 /* event probe symbol_name */
1463 ret
= mi_lttng_writer_write_element_string(writer
,
1464 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1469 /* Close function_attributes and attributes */
1470 ret
= mi_lttng_close_multi_element(writer
, 2);
1476 int mi_lttng_events_open(struct mi_writer
*writer
)
1478 return mi_lttng_writer_open_element(writer
, config_element_events
);
1482 int mi_lttng_event(struct mi_writer
*writer
,
1483 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1487 ret
= mi_lttng_event_common_attributes(writer
, event
);
1492 switch (event
->type
) {
1493 case LTTNG_EVENT_TRACEPOINT
:
1495 if (event
->loglevel
!= -1) {
1496 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1498 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1502 case LTTNG_EVENT_FUNCTION
:
1504 case LTTNG_EVENT_PROBE
:
1505 ret
= mi_lttng_event_function_probe(writer
, event
);
1507 case LTTNG_EVENT_FUNCTION_ENTRY
:
1508 ret
= mi_lttng_event_function_entry(writer
, event
);
1510 case LTTNG_EVENT_USERSPACE_PROBE
:
1511 ret
= mi_lttng_event_userspace_probe(writer
, event
);
1513 case LTTNG_EVENT_ALL
:
1524 ret
= mi_lttng_writer_close_element(writer
);
1532 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1534 return mi_lttng_writer_open_element(
1535 writer
, config_element_process_attr_trackers
);
1538 static int get_tracker_elements(enum lttng_process_attr process_attr
,
1539 const char **element_process_attr_tracker
,
1540 const char **element_process_attr_value
)
1544 switch (process_attr
) {
1545 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1546 *element_process_attr_tracker
=
1547 config_element_process_attr_tracker_pid
;
1548 *element_process_attr_value
=
1549 config_element_process_attr_pid_value
;
1551 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1552 *element_process_attr_tracker
=
1553 config_element_process_attr_tracker_vpid
;
1554 *element_process_attr_value
=
1555 config_element_process_attr_vpid_value
;
1557 case LTTNG_PROCESS_ATTR_USER_ID
:
1558 *element_process_attr_tracker
=
1559 config_element_process_attr_tracker_uid
;
1560 *element_process_attr_value
=
1561 config_element_process_attr_uid_value
;
1563 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1564 *element_process_attr_tracker
=
1565 config_element_process_attr_tracker_vuid
;
1566 *element_process_attr_value
=
1567 config_element_process_attr_vuid_value
;
1569 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1570 *element_process_attr_tracker
=
1571 config_element_process_attr_tracker_gid
;
1572 *element_process_attr_value
=
1573 config_element_process_attr_gid_value
;
1575 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1576 *element_process_attr_tracker
=
1577 config_element_process_attr_tracker_vgid
;
1578 *element_process_attr_value
=
1579 config_element_process_attr_vgid_value
;
1582 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1588 int mi_lttng_process_attribute_tracker_open(
1589 struct mi_writer
*writer
, enum lttng_process_attr process_attr
)
1592 const char *element_tracker
, *element_value
;
1594 ret
= get_tracker_elements(
1595 process_attr
, &element_tracker
, &element_value
);
1600 /* Open process attribute tracker element */
1601 ret
= mi_lttng_writer_open_element(writer
, element_tracker
);
1606 /* Open values element */
1607 ret
= mi_lttng_process_attr_values_open(writer
);
1613 int mi_lttng_pids_open(struct mi_writer
*writer
)
1615 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1619 * TODO: move the listing of pid for user agent to process semantic on
1620 * mi api bump. The use of process element break the mi api.
1623 int mi_lttng_pid(struct mi_writer
*writer
,
1630 /* Open pid process */
1631 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1636 /* Writing pid number */
1637 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1638 mi_lttng_element_pid_id
, (int)pid
);
1643 /* Writing name of the process */
1645 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1654 ret
= mi_lttng_writer_close_element(writer
);
1662 int mi_lttng_process_attr_values_open(struct mi_writer
*writer
)
1664 return mi_lttng_writer_open_element(
1665 writer
, config_element_process_attr_values
);
1669 int mi_lttng_all_process_attribute_value(struct mi_writer
*writer
,
1670 enum lttng_process_attr process_attr
,
1674 const char *element_id_tracker
, *element_target_id
;
1676 ret
= get_tracker_elements(
1677 process_attr
, &element_id_tracker
, &element_target_id
);
1682 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1687 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1692 ret
= mi_lttng_writer_write_element_bool(writer
, config_element_all
, 1);
1697 ret
= mi_lttng_writer_close_element(writer
);
1703 ret
= mi_lttng_writer_close_element(writer
);
1713 int mi_lttng_integral_process_attribute_value(struct mi_writer
*writer
,
1714 enum lttng_process_attr process_attr
,
1719 const char *element_id_tracker
, *element_target_id
;
1721 ret
= get_tracker_elements(
1722 process_attr
, &element_id_tracker
, &element_target_id
);
1727 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1732 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1737 ret
= mi_lttng_writer_write_element_signed_int(
1738 writer
, config_element_process_attr_id
, value
);
1743 ret
= mi_lttng_writer_close_element(writer
);
1749 ret
= mi_lttng_writer_close_element(writer
);
1760 int mi_lttng_string_process_attribute_value(struct mi_writer
*writer
,
1761 enum lttng_process_attr process_attr
,
1767 const char *element_id_tracker
, *element_target_id
;
1769 ret
= get_tracker_elements(
1770 process_attr
, &element_id_tracker
, &element_target_id
);
1775 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1780 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1785 ret
= mi_lttng_writer_write_element_string(
1786 writer
, config_element_name
, value
);
1791 ret
= mi_lttng_writer_close_element(writer
);
1797 ret
= mi_lttng_writer_close_element(writer
);
1808 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1810 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1814 int mi_lttng_event_field(struct mi_writer
*writer
,
1815 struct lttng_event_field
*field
)
1819 if (!field
->field_name
[0]) {
1825 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1830 if (!field
->field_name
[0]) {
1835 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1842 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1843 mi_lttng_eventfieldtype_string(field
->type
));
1849 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1850 mi_lttng_element_nowrite
, field
->nowrite
);
1856 /* Close field element */
1857 ret
= mi_lttng_writer_close_element(writer
);
1864 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1865 struct lttng_event_perf_counter_ctx
*perf_context
)
1869 /* Open perf_counter_context */
1870 ret
= mi_lttng_writer_open_element(writer
,
1871 mi_lttng_element_perf_counter_context
);
1877 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1878 config_element_type
, perf_context
->type
);
1884 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1885 config_element_config
, perf_context
->config
);
1890 /* Name of the perf counter */
1891 ret
= mi_lttng_writer_write_element_string(writer
,
1892 config_element_name
, perf_context
->name
);
1897 /* Close perf_counter_context */
1898 ret
= mi_lttng_writer_close_element(writer
);
1904 int mi_lttng_app_context(struct mi_writer
*writer
,
1905 const char *provider_name
, const char *ctx_name
)
1910 ret
= mi_lttng_writer_open_element(writer
,
1911 config_element_context_app
);
1917 ret
= mi_lttng_writer_write_element_string(writer
,
1918 config_element_context_app_provider_name
,
1925 ret
= mi_lttng_writer_write_element_string(writer
,
1926 config_element_context_app_ctx_name
, ctx_name
);
1932 ret
= mi_lttng_writer_close_element(writer
);
1938 int mi_lttng_context(struct mi_writer
*writer
,
1939 struct lttng_event_context
*context
, int is_open
)
1944 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1949 /* Special case for PERF_*_COUNTER
1950 * print the lttng_event_perf_counter_ctx*/
1951 switch (context
->ctx
) {
1952 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1953 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1954 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1956 struct lttng_event_perf_counter_ctx
*perf_context
=
1957 &context
->u
.perf_counter
;
1958 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1964 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
1966 ret
= mi_lttng_app_context(writer
,
1967 context
->u
.app_ctx
.provider_name
,
1968 context
->u
.app_ctx
.ctx_name
);
1976 const char *type_string
= mi_lttng_event_contexttype_string(
1979 ret
= -LTTNG_ERR_INVALID
;
1983 /* Print context type */
1984 ret
= mi_lttng_writer_write_element_string(writer
,
1985 config_element_type
, type_string
);
1992 ret
= mi_lttng_writer_close_element(writer
);
2000 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
2001 const char *session_name
)
2005 /* Open session element */
2006 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
2011 /* Snapshot output list for current session name */
2012 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2018 /* Open element snapshots (sequence one snapshot) */
2019 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
2029 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
2030 struct lttng_snapshot_output
*output
)
2034 /* Open element snapshot output */
2035 ret
= mi_lttng_writer_open_element(writer
,
2036 mi_lttng_element_command_snapshot
);
2041 /* ID of the snapshot output */
2042 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2043 mi_lttng_element_id
, output
->id
);
2048 /* Name of the output */
2049 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2055 /* Destination of the output (ctrl_url)*/
2056 ret
= mi_lttng_writer_write_element_string(writer
,
2057 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2062 /* Destination of the output (data_url) */
2063 ret
= mi_lttng_writer_write_element_string(writer
,
2064 mi_lttng_element_snapshot_data_url
, output
->data_url
);
2069 /* total size of all stream combined */
2070 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2071 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2076 /* Close snapshot output element */
2077 ret
= mi_lttng_writer_close_element(writer
);
2084 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
2085 const char *name
, const char *current_session_name
)
2089 /* Open element del_snapshot */
2090 ret
= mi_lttng_writer_open_element(writer
,
2091 mi_lttng_element_command_snapshot
);
2097 if (id
!= UINT32_MAX
) {
2098 /* "Snapshot output "id" successfully deleted
2099 * for "current_session_name"
2100 * ID of the snapshot output
2102 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2103 mi_lttng_element_id
, id
);
2108 /* "Snapshot output "name" successfully deleted
2109 * for session "current_session_name"
2110 * Name of the output
2112 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2119 /* Snapshot was deleted for session "current_session_name"*/
2120 ret
= mi_lttng_writer_write_element_string(writer
,
2121 mi_lttng_element_snapshot_session_name
,
2122 current_session_name
);
2127 /* Close snapshot element */
2128 ret
= mi_lttng_writer_close_element(writer
);
2135 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
2136 const char *current_session_name
, const char *n_ptr
,
2137 struct lttng_snapshot_output
*output
)
2141 /* Open element snapshot */
2142 ret
= mi_lttng_writer_open_element(writer
,
2143 mi_lttng_element_command_snapshot
);
2148 /* Snapshot output id */
2149 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2150 mi_lttng_element_id
, output
->id
);
2155 /* Snapshot output names */
2156 ret
= mi_lttng_writer_write_element_string(writer
,
2157 config_element_name
, n_ptr
);
2162 /* Destination of the output (ctrl_url)*/
2163 ret
= mi_lttng_writer_write_element_string(writer
,
2164 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2169 /* Snapshot added for session "current_session_name"*/
2170 ret
= mi_lttng_writer_write_element_string(writer
,
2171 mi_lttng_element_snapshot_session_name
, current_session_name
);
2176 /* total size of all stream combined */
2177 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2178 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2183 /* Close snapshot element */
2184 ret
= mi_lttng_writer_close_element(writer
);
2191 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
2192 const char *current_session_name
, const char *url
,
2193 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
2197 /* Open element snapshot */
2198 ret
= mi_lttng_writer_open_element(writer
,
2199 mi_lttng_element_command_snapshot
);
2205 * If a valid an URL was given, serialize it,
2206 * else take the command line data and ctrl urls*/
2208 /* Destination of the output (ctrl_url)*/
2209 ret
= mi_lttng_writer_write_element_string(writer
,
2210 mi_lttng_element_snapshot_ctrl_url
, url
);
2214 } else if (cmdline_ctrl_url
) {
2215 /* Destination of the output (ctrl_url)*/
2216 ret
= mi_lttng_writer_write_element_string(writer
,
2217 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
2222 /* Destination of the output (data_url) */
2223 ret
= mi_lttng_writer_write_element_string(writer
,
2224 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
2230 /* Close record_snapshot element */
2231 ret
= mi_lttng_writer_close_element(writer
);
2238 int mi_lttng_rotation_schedule(struct mi_writer
*writer
,
2239 const struct lttng_rotation_schedule
*schedule
)
2242 enum lttng_rotation_status status
;
2244 const char *element_name
;
2245 const char *value_name
;
2246 bool empty_schedule
= false;
2248 switch (lttng_rotation_schedule_get_type(schedule
)) {
2249 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2250 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
2252 element_name
= mi_lttng_element_rotation_schedule_periodic
;
2253 value_name
= mi_lttng_element_rotation_schedule_periodic_time_us
;
2255 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2256 status
= lttng_rotation_schedule_size_threshold_get_threshold(
2258 element_name
= mi_lttng_element_rotation_schedule_size_threshold
;
2259 value_name
= mi_lttng_element_rotation_schedule_size_threshold_bytes
;
2266 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2267 if (status
== LTTNG_ROTATION_STATUS_UNAVAILABLE
) {
2268 empty_schedule
= true;
2275 ret
= mi_lttng_writer_open_element(writer
, element_name
);
2280 if (!empty_schedule
) {
2281 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2288 /* Close schedule descriptor element. */
2289 ret
= mi_lttng_writer_close_element(writer
);
2298 int mi_lttng_rotation_schedule_result(struct mi_writer
*writer
,
2299 const struct lttng_rotation_schedule
*schedule
,
2304 ret
= mi_lttng_writer_open_element(writer
,
2305 mi_lttng_element_rotation_schedule_result
);
2310 ret
= mi_lttng_writer_open_element(writer
,
2311 mi_lttng_element_rotation_schedule
);
2316 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
2321 /* Close rotation_schedule element */
2322 ret
= mi_lttng_writer_close_element(writer
);
2327 ret
= mi_lttng_writer_write_element_bool(writer
,
2328 mi_lttng_element_command_success
, success
);
2333 /* Close rotation_schedule_result element */
2334 ret
= mi_lttng_writer_close_element(writer
);
2343 int mi_lttng_location(struct mi_writer
*writer
,
2344 const struct lttng_trace_archive_location
*location
)
2347 enum lttng_trace_archive_location_type location_type
;
2348 enum lttng_trace_archive_location_status status
;
2350 location_type
= lttng_trace_archive_location_get_type(location
);
2352 switch (location_type
) {
2353 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
:
2355 const char *absolute_path
;
2357 status
= lttng_trace_archive_location_local_get_absolute_path(
2358 location
, &absolute_path
);
2359 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2364 ret
= mi_lttng_writer_open_element(writer
,
2365 mi_lttng_element_rotation_location_local
);
2371 ret
= mi_lttng_writer_write_element_string(writer
,
2372 mi_lttng_element_rotation_location_local_absolute_path
,
2378 /* Close local element */
2379 ret
= mi_lttng_writer_close_element(writer
);
2385 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
:
2387 uint16_t control_port
, data_port
;
2388 const char *host
, *relative_path
;
2389 enum lttng_trace_archive_location_relay_protocol_type protocol
;
2391 /* Fetch all relay location parameters. */
2392 status
= lttng_trace_archive_location_relay_get_protocol_type(
2393 location
, &protocol
);
2394 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2399 status
= lttng_trace_archive_location_relay_get_host(
2401 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2406 status
= lttng_trace_archive_location_relay_get_control_port(
2407 location
, &control_port
);
2408 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2413 status
= lttng_trace_archive_location_relay_get_data_port(
2414 location
, &data_port
);
2415 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2420 status
= lttng_trace_archive_location_relay_get_relative_path(
2421 location
, &relative_path
);
2422 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2427 ret
= mi_lttng_writer_open_element(writer
,
2428 mi_lttng_element_rotation_location_relay
);
2433 ret
= mi_lttng_writer_write_element_string(writer
,
2434 mi_lttng_element_rotation_location_relay_host
,
2440 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2441 mi_lttng_element_rotation_location_relay_control_port
,
2447 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2448 mi_lttng_element_rotation_location_relay_data_port
,
2454 ret
= mi_lttng_writer_write_element_string(writer
,
2455 mi_lttng_element_rotation_location_relay_protocol
,
2456 mi_lttng_trace_archive_location_relay_protocol_type_string(protocol
));
2461 ret
= mi_lttng_writer_write_element_string(writer
,
2462 mi_lttng_element_rotation_location_relay_relative_path
,
2468 /* Close relay element */
2469 ret
= mi_lttng_writer_close_element(writer
);
2483 int mi_lttng_rotate(struct mi_writer
*writer
,
2484 const char *session_name
,
2485 enum lttng_rotation_state rotation_state
,
2486 const struct lttng_trace_archive_location
*location
)
2490 ret
= mi_lttng_writer_open_element(writer
,
2491 mi_lttng_element_rotation
);
2496 ret
= mi_lttng_writer_write_element_string(writer
,
2497 mi_lttng_element_session_name
,
2503 ret
= mi_lttng_writer_write_element_string(writer
,
2504 mi_lttng_element_rotation_state
,
2505 mi_lttng_rotation_state_string(rotation_state
));
2511 /* Not a serialization error. */
2512 goto close_rotation
;
2515 ret
= mi_lttng_writer_open_element(writer
,
2516 mi_lttng_element_rotation_location
);
2521 ret
= mi_lttng_location(writer
, location
);
2523 goto close_location
;
2527 /* Close location element */
2528 ret
= mi_lttng_writer_close_element(writer
);
2534 /* Close rotation element */
2535 ret
= mi_lttng_writer_close_element(writer
);