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/tracker-internal.h>
25 #include <lttng/channel.h>
30 #define MI_SCHEMA_MAJOR_VERSION 3
31 #define MI_SCHEMA_MINOR_VERSION 0
33 /* Machine interface namespace URI */
34 LTTNG_HIDDEN
const char * const mi_lttng_xmlns
= "xmlns";
35 LTTNG_HIDDEN
const char * const mi_lttng_xmlns_xsi
= "xmlns:xsi";
36 LTTNG_HIDDEN
const char * const mi_lttng_w3_schema_uri
= "http://www.w3.org/2001/XMLSchema-instance";
37 LTTNG_HIDDEN
const char * const mi_lttng_schema_location
= "xsi:schemaLocation";
38 LTTNG_HIDDEN
const char * const mi_lttng_schema_location_uri
=
39 DEFAULT_LTTNG_MI_NAMESPACE
" "
40 "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION
)
41 "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION
) "."
42 XSTR(MI_SCHEMA_MINOR_VERSION
) ".xsd";
43 LTTNG_HIDDEN
const char * const mi_lttng_schema_version
= "schemaVersion";
44 LTTNG_HIDDEN
const char * const mi_lttng_schema_version_value
= XSTR(MI_SCHEMA_MAJOR_VERSION
)
45 "." XSTR(MI_SCHEMA_MINOR_VERSION
);
47 /* Strings related to command */
48 const char * const mi_lttng_element_command
= "command";
49 const char * const mi_lttng_element_command_action
= "snapshot_action";
50 const char * const mi_lttng_element_command_add_context
= "add-context";
51 const char * const mi_lttng_element_command_create
= "create";
52 const char * const mi_lttng_element_command_destroy
= "destroy";
53 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
54 const char * const mi_lttng_element_command_disable_event
= "disable-event";
55 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
56 const char * const mi_lttng_element_command_enable_event
= "enable-event";
57 const char * const mi_lttng_element_command_list
= "list";
58 const char * const mi_lttng_element_command_load
= "load";
59 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata
= "metadata";
60 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata_action
= "metadata_action";
61 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate
= "regenerate";
62 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate_action
= "regenerate_action";
63 const char * const mi_lttng_element_command_name
= "name";
64 const char * const mi_lttng_element_command_output
= "output";
65 const char * const mi_lttng_element_command_save
= "save";
66 const char * const mi_lttng_element_command_set_session
= "set-session";
67 const char * const mi_lttng_element_command_snapshot
= "snapshot";
68 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
69 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
70 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
71 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
72 const char * const mi_lttng_element_command_start
= "start";
73 const char * const mi_lttng_element_command_stop
= "stop";
74 const char * const mi_lttng_element_command_success
= "success";
75 const char * const mi_lttng_element_command_track
= "track";
76 const char * const mi_lttng_element_command_untrack
= "untrack";
77 const char * const mi_lttng_element_command_version
= "version";
78 LTTNG_HIDDEN
const char * const mi_lttng_element_command_rotate
= "rotate";
79 LTTNG_HIDDEN
const char * const mi_lttng_element_command_enable_rotation
= "enable-rotation";
80 LTTNG_HIDDEN
const char * const mi_lttng_element_command_disable_rotation
= "disable-rotation";
81 LTTNG_HIDDEN
const char * const mi_lttng_element_command_clear
= "clear";
83 /* Strings related to version command */
84 const char * const mi_lttng_element_version
= "version";
85 const char * const mi_lttng_element_version_commit
= "commit";
86 const char * const mi_lttng_element_version_description
= "description";
87 const char * const mi_lttng_element_version_license
= "license";
88 const char * const mi_lttng_element_version_major
= "major";
89 const char * const mi_lttng_element_version_minor
= "minor";
90 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
91 const char * const mi_lttng_element_version_str
= "string";
92 const char * const mi_lttng_element_version_web
= "url";
94 /* String related to a lttng_event_field */
95 const char * const mi_lttng_element_event_field
= "event_field";
96 const char * const mi_lttng_element_event_fields
= "event_fields";
98 /* String related to lttng_event_perf_counter_ctx */
99 const char * const mi_lttng_element_perf_counter_context
= "perf";
101 /* Strings related to pid */
102 const char * const mi_lttng_element_pid_id
= "id";
104 /* Strings related to save command */
105 const char * const mi_lttng_element_save
= "save";
107 /* Strings related to load command */
108 const char * const mi_lttng_element_load
= "load";
109 LTTNG_HIDDEN
const char * const mi_lttng_element_load_overrides
= "overrides";
110 LTTNG_HIDDEN
const char * const mi_lttng_element_load_override_url
= "url";
112 /* General elements of mi_lttng */
113 const char * const mi_lttng_element_empty
= "";
114 const char * const mi_lttng_element_id
= "id";
115 const char * const mi_lttng_element_nowrite
= "nowrite";
116 const char * const mi_lttng_element_success
= "success";
117 const char * const mi_lttng_element_type_enum
= "ENUM";
118 const char * const mi_lttng_element_type_float
= "FLOAT";
119 const char * const mi_lttng_element_type_integer
= "INTEGER";
120 const char * const mi_lttng_element_type_other
= "OTHER";
121 const char * const mi_lttng_element_type_string
= "STRING";
123 /* String related to loglevel */
124 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
125 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
126 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
127 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
128 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
129 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
130 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
131 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
132 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
133 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
134 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
135 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
136 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
137 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
138 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
139 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
141 /* String related to loglevel JUL */
142 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
143 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
144 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
145 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
146 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
147 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
148 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
149 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
150 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
152 /* String related to loglevel LOG4J */
153 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
154 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
155 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
156 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
157 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
158 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
159 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
160 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
162 /* String related to loglevel Python */
163 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
164 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
165 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
166 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
167 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
168 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
170 /* String related to loglevel type */
171 const char * const mi_lttng_loglevel_type_all
= "ALL";
172 const char * const mi_lttng_loglevel_type_range
= "RANGE";
173 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
174 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
176 /* String related to a lttng_snapshot_output */
177 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
178 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
179 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
180 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
181 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
182 const char * const mi_lttng_element_snapshots
= "snapshots";
184 /* String related to track/untrack command */
185 const char * const mi_lttng_element_track_untrack_all_wildcard
= "*";
187 LTTNG_HIDDEN
const char * const mi_lttng_element_session_name
= "session_name";
189 /* String related to rotate command */
190 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation
= "rotation";
191 LTTNG_HIDDEN
const char * const mi_lttng_element_rotate_status
= "status";
192 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule
= "rotation_schedule";
193 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedules
= "rotation_schedules";
194 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_result
= "rotation_schedule_result";
195 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_results
= "rotation_schedule_results";
196 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_periodic
= "periodic";
197 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_periodic_time_us
= "time_us";
198 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_size_threshold
= "size_threshold";
199 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_size_threshold_bytes
= "bytes";
200 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_state
= "state";
201 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location
= "location";
202 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_local
= "local";
203 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_local_absolute_path
= "absolute_path";
204 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay
= "relay";
205 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_host
= "host";
206 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_control_port
= "control_port";
207 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_data_port
= "data_port";
208 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_protocol
= "protocol";
209 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_relative_path
= "relative_path";
211 /* String related to enum lttng_rotation_state */
212 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_ongoing
= "ONGOING";
213 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_completed
= "COMPLETED";
214 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_expired
= "EXPIRED";
215 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_error
= "ERROR";
217 /* String related to enum lttng_trace_archive_location_relay_protocol_type */
218 LTTNG_HIDDEN
const char * const mi_lttng_rotation_location_relay_protocol_str_tcp
= "TCP";
220 /* String related to add-context command */
221 LTTNG_HIDDEN
const char * const mi_lttng_element_context_symbol
= "symbol";
223 /* Deprecated symbols preserved for ABI compatibility. */
224 const char * const mi_lttng_context_type_perf_counter
;
225 const char * const mi_lttng_context_type_perf_cpu_counter
;
226 const char * const mi_lttng_context_type_perf_thread_counter
;
227 const char * const mi_lttng_element_track_untrack_pid_target
;
228 const char * const mi_lttng_element_track_untrack_targets
;
229 const char * const mi_lttng_element_calibrate
;
230 const char * const mi_lttng_element_calibrate_function
;
231 const char * const mi_lttng_element_command_calibrate
;
233 /* This is a merge of jul loglevel and regular loglevel
234 * Those should never overlap by definition
235 * (see struct lttng_event loglevel)
238 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
241 case LTTNG_DOMAIN_KERNEL
:
242 case LTTNG_DOMAIN_UST
:
245 return mi_lttng_element_empty
;
246 case LTTNG_LOGLEVEL_EMERG
:
247 return mi_lttng_loglevel_str_emerg
;
248 case LTTNG_LOGLEVEL_ALERT
:
249 return mi_lttng_loglevel_str_alert
;
250 case LTTNG_LOGLEVEL_CRIT
:
251 return mi_lttng_loglevel_str_crit
;
252 case LTTNG_LOGLEVEL_ERR
:
253 return mi_lttng_loglevel_str_err
;
254 case LTTNG_LOGLEVEL_WARNING
:
255 return mi_lttng_loglevel_str_warning
;
256 case LTTNG_LOGLEVEL_NOTICE
:
257 return mi_lttng_loglevel_str_notice
;
258 case LTTNG_LOGLEVEL_INFO
:
259 return mi_lttng_loglevel_str_info
;
260 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
261 return mi_lttng_loglevel_str_debug_system
;
262 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
263 return mi_lttng_loglevel_str_debug_program
;
264 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
265 return mi_lttng_loglevel_str_debug_process
;
266 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
267 return mi_lttng_loglevel_str_debug_module
;
268 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
269 return mi_lttng_loglevel_str_debug_unit
;
270 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
271 return mi_lttng_loglevel_str_debug_function
;
272 case LTTNG_LOGLEVEL_DEBUG_LINE
:
273 return mi_lttng_loglevel_str_debug_line
;
274 case LTTNG_LOGLEVEL_DEBUG
:
275 return mi_lttng_loglevel_str_debug
;
277 return mi_lttng_loglevel_str_unknown
;
280 case LTTNG_DOMAIN_LOG4J
:
283 return mi_lttng_element_empty
;
284 case LTTNG_LOGLEVEL_LOG4J_OFF
:
285 return mi_lttng_loglevel_str_log4j_off
;
286 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
287 return mi_lttng_loglevel_str_log4j_fatal
;
288 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
289 return mi_lttng_loglevel_str_log4j_error
;
290 case LTTNG_LOGLEVEL_LOG4J_WARN
:
291 return mi_lttng_loglevel_str_log4j_warn
;
292 case LTTNG_LOGLEVEL_LOG4J_INFO
:
293 return mi_lttng_loglevel_str_log4j_info
;
294 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
295 return mi_lttng_loglevel_str_log4j_debug
;
296 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
297 return mi_lttng_loglevel_str_log4j_trace
;
298 case LTTNG_LOGLEVEL_LOG4J_ALL
:
299 return mi_lttng_loglevel_str_log4j_all
;
301 return mi_lttng_loglevel_str_unknown
;
304 case LTTNG_DOMAIN_JUL
:
307 return mi_lttng_element_empty
;
308 case LTTNG_LOGLEVEL_JUL_OFF
:
309 return mi_lttng_loglevel_str_jul_off
;
310 case LTTNG_LOGLEVEL_JUL_SEVERE
:
311 return mi_lttng_loglevel_str_jul_severe
;
312 case LTTNG_LOGLEVEL_JUL_WARNING
:
313 return mi_lttng_loglevel_str_jul_warning
;
314 case LTTNG_LOGLEVEL_JUL_INFO
:
315 return mi_lttng_loglevel_str_jul_info
;
316 case LTTNG_LOGLEVEL_JUL_CONFIG
:
317 return mi_lttng_loglevel_str_jul_config
;
318 case LTTNG_LOGLEVEL_JUL_FINE
:
319 return mi_lttng_loglevel_str_jul_fine
;
320 case LTTNG_LOGLEVEL_JUL_FINER
:
321 return mi_lttng_loglevel_str_jul_finer
;
322 case LTTNG_LOGLEVEL_JUL_FINEST
:
323 return mi_lttng_loglevel_str_jul_finest
;
324 case LTTNG_LOGLEVEL_JUL_ALL
:
325 return mi_lttng_loglevel_str_jul_all
;
327 return mi_lttng_loglevel_str_unknown
;
330 case LTTNG_DOMAIN_PYTHON
:
332 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
333 return mi_lttng_loglevel_str_python_critical
;
334 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
335 return mi_lttng_loglevel_str_python_error
;
336 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
337 return mi_lttng_loglevel_str_python_warning
;
338 case LTTNG_LOGLEVEL_PYTHON_INFO
:
339 return mi_lttng_loglevel_str_python_info
;
340 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
341 return mi_lttng_loglevel_str_python_debug
;
342 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
343 return mi_lttng_loglevel_str_python_notset
;
345 return mi_lttng_loglevel_str_unknown
;
349 return mi_lttng_loglevel_str_unknown
;
354 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
357 case LTTNG_EVENT_LOGLEVEL_ALL
:
358 return mi_lttng_loglevel_type_all
;
359 case LTTNG_EVENT_LOGLEVEL_RANGE
:
360 return mi_lttng_loglevel_type_range
;
361 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
362 return mi_lttng_loglevel_type_single
;
364 return mi_lttng_loglevel_type_unknown
;
369 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
372 case LTTNG_EVENT_ALL
:
373 return config_event_type_all
;
374 case LTTNG_EVENT_TRACEPOINT
:
375 return config_event_type_tracepoint
;
376 case LTTNG_EVENT_PROBE
:
377 return config_event_type_probe
;
378 case LTTNG_EVENT_USERSPACE_PROBE
:
379 return config_event_type_userspace_probe
;
380 case LTTNG_EVENT_FUNCTION
:
381 return config_event_type_function
;
382 case LTTNG_EVENT_FUNCTION_ENTRY
:
383 return config_event_type_function_entry
;
384 case LTTNG_EVENT_SYSCALL
:
385 return config_event_type_syscall
;
386 case LTTNG_EVENT_NOOP
:
387 return config_event_type_noop
;
389 return mi_lttng_element_empty
;
394 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
397 case LTTNG_EVENT_CONTEXT_PID
:
398 return config_event_context_pid
;
399 case LTTNG_EVENT_CONTEXT_PROCNAME
:
400 return config_event_context_procname
;
401 case LTTNG_EVENT_CONTEXT_PRIO
:
402 return config_event_context_prio
;
403 case LTTNG_EVENT_CONTEXT_NICE
:
404 return config_event_context_nice
;
405 case LTTNG_EVENT_CONTEXT_VPID
:
406 return config_event_context_vpid
;
407 case LTTNG_EVENT_CONTEXT_TID
:
408 return config_event_context_tid
;
409 case LTTNG_EVENT_CONTEXT_VTID
:
410 return config_event_context_vtid
;
411 case LTTNG_EVENT_CONTEXT_PPID
:
412 return config_event_context_ppid
;
413 case LTTNG_EVENT_CONTEXT_VPPID
:
414 return config_event_context_vppid
;
415 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
416 return config_event_context_pthread_id
;
417 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
418 return config_event_context_hostname
;
419 case LTTNG_EVENT_CONTEXT_IP
:
420 return config_event_context_ip
;
421 case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
:
422 return config_event_context_interruptible
;
423 case LTTNG_EVENT_CONTEXT_PREEMPTIBLE
:
424 return config_event_context_preemptible
;
425 case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
:
426 return config_event_context_need_reschedule
;
427 case LTTNG_EVENT_CONTEXT_MIGRATABLE
:
428 return config_event_context_migratable
;
429 case LTTNG_EVENT_CONTEXT_CALLSTACK_USER
:
430 return config_event_context_callstack_user
;
431 case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
:
432 return config_event_context_callstack_kernel
;
433 case LTTNG_EVENT_CONTEXT_CGROUP_NS
:
434 return config_event_context_cgroup_ns
;
435 case LTTNG_EVENT_CONTEXT_IPC_NS
:
436 return config_event_context_ipc_ns
;
437 case LTTNG_EVENT_CONTEXT_MNT_NS
:
438 return config_event_context_mnt_ns
;
439 case LTTNG_EVENT_CONTEXT_NET_NS
:
440 return config_event_context_net_ns
;
441 case LTTNG_EVENT_CONTEXT_PID_NS
:
442 return config_event_context_pid_ns
;
443 case LTTNG_EVENT_CONTEXT_USER_NS
:
444 return config_event_context_user_ns
;
445 case LTTNG_EVENT_CONTEXT_UTS_NS
:
446 return config_event_context_uts_ns
;
447 case LTTNG_EVENT_CONTEXT_UID
:
448 return config_event_context_uid
;
449 case LTTNG_EVENT_CONTEXT_EUID
:
450 return config_event_context_euid
;
451 case LTTNG_EVENT_CONTEXT_SUID
:
452 return config_event_context_suid
;
453 case LTTNG_EVENT_CONTEXT_GID
:
454 return config_event_context_gid
;
455 case LTTNG_EVENT_CONTEXT_EGID
:
456 return config_event_context_egid
;
457 case LTTNG_EVENT_CONTEXT_SGID
:
458 return config_event_context_sgid
;
459 case LTTNG_EVENT_CONTEXT_VUID
:
460 return config_event_context_vuid
;
461 case LTTNG_EVENT_CONTEXT_VEUID
:
462 return config_event_context_veuid
;
463 case LTTNG_EVENT_CONTEXT_VSUID
:
464 return config_event_context_vsuid
;
465 case LTTNG_EVENT_CONTEXT_VGID
:
466 return config_event_context_vgid
;
467 case LTTNG_EVENT_CONTEXT_VEGID
:
468 return config_event_context_vegid
;
469 case LTTNG_EVENT_CONTEXT_VSGID
:
470 return config_event_context_vsgid
;
477 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
480 case(LTTNG_EVENT_FIELD_INTEGER
):
481 return mi_lttng_element_type_integer
;
482 case(LTTNG_EVENT_FIELD_ENUM
):
483 return mi_lttng_element_type_enum
;
484 case(LTTNG_EVENT_FIELD_FLOAT
):
485 return mi_lttng_element_type_float
;
486 case(LTTNG_EVENT_FIELD_STRING
):
487 return mi_lttng_element_type_string
;
489 return mi_lttng_element_type_other
;
494 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
496 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
498 case LTTNG_DOMAIN_KERNEL
:
499 return config_domain_type_kernel
;
500 case LTTNG_DOMAIN_UST
:
501 return config_domain_type_ust
;
502 case LTTNG_DOMAIN_JUL
:
503 return config_domain_type_jul
;
504 case LTTNG_DOMAIN_LOG4J
:
505 return config_domain_type_log4j
;
506 case LTTNG_DOMAIN_PYTHON
:
507 return config_domain_type_python
;
509 /* Should not have an unknown domain */
516 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
519 case LTTNG_BUFFER_PER_PID
:
520 return config_buffer_type_per_pid
;
521 case LTTNG_BUFFER_PER_UID
:
522 return config_buffer_type_per_uid
;
523 case LTTNG_BUFFER_GLOBAL
:
524 return config_buffer_type_global
;
526 /* Should not have an unknow buffer type */
533 const char *mi_lttng_rotation_state_string(enum lttng_rotation_state value
)
536 case LTTNG_ROTATION_STATE_ONGOING
:
537 return mi_lttng_rotation_state_str_ongoing
;
538 case LTTNG_ROTATION_STATE_COMPLETED
:
539 return mi_lttng_rotation_state_str_completed
;
540 case LTTNG_ROTATION_STATE_EXPIRED
:
541 return mi_lttng_rotation_state_str_expired
;
542 case LTTNG_ROTATION_STATE_ERROR
:
543 return mi_lttng_rotation_state_str_error
;
545 /* Should not have an unknow rotation state. */
552 const char *mi_lttng_trace_archive_location_relay_protocol_type_string(
553 enum lttng_trace_archive_location_relay_protocol_type value
)
556 case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP
:
557 return mi_lttng_rotation_location_relay_protocol_str_tcp
;
559 /* Should not have an unknow relay protocol. */
566 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
568 struct mi_writer
*mi_writer
;
570 mi_writer
= zmalloc(sizeof(struct mi_writer
));
572 PERROR("zmalloc mi_writer_create");
575 if (mi_output_type
== LTTNG_MI_XML
) {
576 mi_writer
->writer
= config_writer_create(fd_output
, 0);
577 if (!mi_writer
->writer
) {
580 mi_writer
->type
= LTTNG_MI_XML
;
594 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
603 ret
= config_writer_destroy(writer
->writer
);
614 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
619 * A command is always the MI's root node, it must declare the current
620 * namespace and schema URIs and the schema's version.
622 ret
= config_writer_open_element(writer
->writer
,
623 mi_lttng_element_command
);
628 ret
= config_writer_write_attribute(writer
->writer
,
629 mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
634 ret
= config_writer_write_attribute(writer
->writer
,
635 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
640 ret
= config_writer_write_attribute(writer
->writer
,
641 mi_lttng_schema_location
,
642 mi_lttng_schema_location_uri
);
647 ret
= config_writer_write_attribute(writer
->writer
,
648 mi_lttng_schema_version
,
649 mi_lttng_schema_version_value
);
654 ret
= mi_lttng_writer_write_element_string(writer
,
655 mi_lttng_element_command_name
, command
);
661 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
663 return mi_lttng_writer_close_element(writer
);
667 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
668 const char *element_name
)
670 return config_writer_open_element(writer
->writer
, element_name
);
674 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
676 return config_writer_close_element(writer
->writer
);
680 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
681 unsigned int nb_element
)
685 if (nb_element
< 1) {
689 for (i
= 0; i
< nb_element
; i
++) {
690 ret
= mi_lttng_writer_close_element(writer
);
700 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
701 const char *element_name
, uint64_t value
)
703 return config_writer_write_element_unsigned_int(writer
->writer
,
704 element_name
, value
);
708 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
709 const char *element_name
, int64_t value
)
711 return config_writer_write_element_signed_int(writer
->writer
,
712 element_name
, value
);
716 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
717 const char *element_name
, int value
)
719 return config_writer_write_element_bool(writer
->writer
,
720 element_name
, value
);
724 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
725 const char *element_name
, const char *value
)
727 return config_writer_write_element_string(writer
->writer
,
728 element_name
, value
);
732 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
733 const char *lttng_description
, const char *lttng_license
)
738 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
743 /* Version string (contain info like rc etc.) */
744 ret
= mi_lttng_writer_write_element_string(writer
,
745 mi_lttng_element_version_str
, version
->version
);
750 /* Major version number */
751 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
752 mi_lttng_element_version_major
, version
->version_major
);
757 /* Minor version number */
758 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
759 mi_lttng_element_version_minor
, version
->version_minor
);
764 /* Commit version number */
765 ret
= mi_lttng_writer_write_element_string(writer
,
766 mi_lttng_element_version_commit
, version
->version_commit
);
772 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
773 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
778 /* Name of the version */
779 ret
= mi_lttng_writer_write_element_string(writer
,
780 config_element_name
, version
->version_name
);
785 /* Description mostly related to beer... */
786 ret
= mi_lttng_writer_write_element_string(writer
,
787 mi_lttng_element_version_description
, lttng_description
);
793 ret
= mi_lttng_writer_write_element_string(writer
,
794 mi_lttng_element_version_web
, version
->package_url
);
799 /* License: free as in free beer...no...*speech* */
800 ret
= mi_lttng_writer_write_element_string(writer
,
801 mi_lttng_element_version_license
, lttng_license
);
806 /* Close version element */
807 ret
= mi_lttng_writer_close_element(writer
);
814 int mi_lttng_sessions_open(struct mi_writer
*writer
)
816 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
820 int mi_lttng_session(struct mi_writer
*writer
,
821 struct lttng_session
*session
, int is_open
)
827 /* Open sessions element */
828 ret
= mi_lttng_writer_open_element(writer
,
829 config_element_session
);
834 /* Name of the session */
835 ret
= mi_lttng_writer_write_element_string(writer
,
836 config_element_name
, session
->name
);
842 ret
= mi_lttng_writer_write_element_string(writer
,
843 config_element_path
, session
->path
);
849 ret
= mi_lttng_writer_write_element_bool(writer
,
850 config_element_enabled
, session
->enabled
);
856 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
857 config_element_snapshot_mode
, session
->snapshot_mode
);
862 /* Live timer interval in usec */
863 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
864 config_element_live_timer_interval
,
865 session
->live_timer_interval
);
871 /* Closing session element */
872 ret
= mi_lttng_writer_close_element(writer
);
880 int mi_lttng_domains_open(struct mi_writer
*writer
)
882 return mi_lttng_writer_open_element(writer
, config_element_domains
);
886 int mi_lttng_domain(struct mi_writer
*writer
,
887 struct lttng_domain
*domain
, int is_open
)
890 const char *str_domain
;
891 const char *str_buffer
;
895 /* Open domain element */
896 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
902 str_domain
= mi_lttng_domaintype_string(domain
->type
);
903 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
910 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
911 ret
= mi_lttng_writer_write_element_string(writer
,
912 config_element_buffer_type
, str_buffer
);
918 * This union is not currently used and was added for
919 * future ust domain support.
924 /* Closing domain element */
925 ret
= mi_lttng_writer_close_element(writer
);
934 int mi_lttng_channels_open(struct mi_writer
*writer
)
936 return mi_lttng_writer_open_element(writer
, config_element_channels
);
940 int mi_lttng_channel(struct mi_writer
*writer
,
941 struct lttng_channel
*channel
, int is_open
)
947 /* Opening channel element */
948 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
954 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
961 ret
= mi_lttng_writer_write_element_bool(writer
,
962 config_element_enabled
, channel
->enabled
);
968 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
974 /* Closing channel element */
975 ret
= mi_lttng_writer_close_element(writer
);
985 int mi_lttng_channel_attr(struct mi_writer
*writer
,
986 struct lttng_channel_attr
*attr
)
989 struct lttng_channel
*chan
= caa_container_of(attr
,
990 struct lttng_channel
, attr
);
991 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
992 int64_t blocking_timeout
;
996 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
1001 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
1006 ret
= lttng_channel_get_monitor_timer_interval(chan
,
1007 &monitor_timer_interval
);
1012 ret
= lttng_channel_get_blocking_timeout(chan
,
1018 /* Opening Attributes */
1019 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1025 ret
= mi_lttng_writer_write_element_string(writer
,
1026 config_element_overwrite_mode
,
1027 attr
->overwrite
? config_overwrite_mode_overwrite
:
1028 config_overwrite_mode_discard
);
1033 /* Sub buffer size in byte */
1034 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1035 config_element_subbuf_size
, attr
->subbuf_size
);
1040 /* Number of subbuffer (power of two) */
1041 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1042 config_element_num_subbuf
,
1048 /* Switch timer interval in usec */
1049 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1050 config_element_switch_timer_interval
,
1051 attr
->switch_timer_interval
);
1056 /* Read timer interval in usec */
1057 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1058 config_element_read_timer_interval
,
1059 attr
->read_timer_interval
);
1064 /* Monitor timer interval in usec */
1065 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1066 config_element_monitor_timer_interval
,
1067 monitor_timer_interval
);
1072 /* Retry timeout in usec */
1073 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1074 config_element_blocking_timeout
,
1081 ret
= mi_lttng_writer_write_element_string(writer
,
1082 config_element_output_type
,
1083 attr
->output
== LTTNG_EVENT_SPLICE
?
1084 config_output_type_splice
: config_output_type_mmap
);
1089 /* Tracefile size in bytes */
1090 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1091 config_element_tracefile_size
, attr
->tracefile_size
);
1096 /* Count of tracefiles */
1097 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1098 config_element_tracefile_count
,
1099 attr
->tracefile_count
);
1104 /* Live timer interval in usec*/
1105 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1106 config_element_live_timer_interval
,
1107 attr
->live_timer_interval
);
1112 /* Discarded events */
1113 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1114 config_element_discarded_events
,
1121 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1122 config_element_lost_packets
,
1128 /* Closing attributes */
1129 ret
= mi_lttng_writer_close_element(writer
);
1139 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
1140 struct lttng_event
*event
)
1143 const char *filter_expression
;
1145 /* Open event element */
1146 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
1152 ret
= mi_lttng_writer_write_element_string(writer
,
1153 config_element_name
, event
->name
);
1159 ret
= mi_lttng_writer_write_element_string(writer
,
1160 config_element_type
, mi_lttng_eventtype_string(event
->type
));
1165 /* Is event enabled */
1166 ret
= mi_lttng_writer_write_element_bool(writer
,
1167 config_element_enabled
, event
->enabled
);
1172 /* Event filter expression */
1173 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1178 if (filter_expression
) {
1179 ret
= mi_lttng_writer_write_element_string(writer
,
1180 config_element_filter_expression
,
1191 static int write_event_exclusions(struct mi_writer
*writer
,
1192 struct lttng_event
*event
)
1196 int exclusion_count
;
1198 /* Open event exclusions */
1199 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1204 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1205 if (exclusion_count
< 0) {
1206 ret
= exclusion_count
;
1210 for (i
= 0; i
< exclusion_count
; i
++) {
1213 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1215 /* Close exclusions */
1216 mi_lttng_writer_close_element(writer
);
1220 ret
= mi_lttng_writer_write_element_string(writer
,
1221 config_element_exclusion
, name
);
1223 /* Close exclusions */
1224 mi_lttng_writer_close_element(writer
);
1229 /* Close exclusions */
1230 ret
= mi_lttng_writer_close_element(writer
);
1237 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1238 struct lttng_event
*event
, enum lttng_domain_type domain
)
1242 /* Event loglevel */
1243 ret
= mi_lttng_writer_write_element_string(writer
,
1244 config_element_loglevel
,
1245 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1250 /* Log level type */
1251 ret
= mi_lttng_writer_write_element_string(writer
,
1252 config_element_loglevel_type
,
1253 mi_lttng_logleveltype_string(event
->loglevel_type
));
1258 /* Event exclusions */
1259 ret
= write_event_exclusions(writer
, event
);
1266 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1267 struct lttng_event
*event
)
1269 /* event exclusion filter */
1270 return write_event_exclusions(writer
, event
);
1274 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1275 struct lttng_event
*event
)
1279 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1284 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1289 if (event
->attr
.probe
.addr
!= 0) {
1290 /* event probe address */
1291 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1292 config_element_address
, event
->attr
.probe
.addr
);
1297 /* event probe offset */
1298 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1299 config_element_offset
, event
->attr
.probe
.offset
);
1304 /* event probe symbol_name */
1305 ret
= mi_lttng_writer_write_element_string(writer
,
1306 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1312 /* Close probe_attributes and attributes */
1313 ret
= mi_lttng_close_multi_element(writer
, 2);
1319 int mi_lttng_event_userspace_probe(struct mi_writer
*writer
,
1320 struct lttng_event
*event
)
1323 const struct lttng_userspace_probe_location
*location
;
1324 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
1325 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
1327 location
= lttng_event_get_userspace_probe_location(event
);
1329 ret
= -LTTNG_ERR_INVALID
;
1333 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
1334 if (!lookup_method
) {
1335 ret
= -LTTNG_ERR_INVALID
;
1339 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
1341 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1346 switch (lttng_userspace_probe_location_get_type(location
)) {
1347 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1349 const char *function_name
;
1350 const char *binary_path
;
1352 ret
= mi_lttng_writer_open_element(writer
,
1353 config_element_userspace_probe_function_attributes
);
1358 switch (lookup_type
) {
1359 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
1360 ret
= mi_lttng_writer_write_element_string(writer
,
1361 config_element_userspace_probe_lookup
,
1362 config_element_userspace_probe_lookup_function_elf
);
1367 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
1368 ret
= mi_lttng_writer_write_element_string(writer
,
1369 config_element_userspace_probe_lookup
,
1370 config_element_userspace_probe_lookup_function_default
);
1379 binary_path
= lttng_userspace_probe_location_function_get_binary_path(location
);
1380 ret
= mi_lttng_writer_write_element_string(writer
,
1381 config_element_userspace_probe_location_binary_path
, binary_path
);
1386 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
1387 ret
= mi_lttng_writer_write_element_string(writer
,
1388 config_element_userspace_probe_function_location_function_name
,
1396 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1398 const char *probe_name
, *provider_name
;
1399 const char *binary_path
;
1401 ret
= mi_lttng_writer_open_element(writer
,
1402 config_element_userspace_probe_function_attributes
);
1407 switch (lookup_type
) {
1408 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
1409 ret
= mi_lttng_writer_write_element_string(writer
,
1410 config_element_userspace_probe_lookup
,
1411 config_element_userspace_probe_lookup_tracepoint_sdt
);
1420 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(location
);
1421 ret
= mi_lttng_writer_write_element_string(writer
,
1422 config_element_userspace_probe_location_binary_path
,
1428 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
1429 ret
= mi_lttng_writer_write_element_string(writer
,
1430 config_element_userspace_probe_tracepoint_location_provider_name
,
1436 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
1437 ret
= mi_lttng_writer_write_element_string(writer
,
1438 config_element_userspace_probe_tracepoint_location_probe_name
, probe_name
);
1445 ERR("Invalid probe type encountered");
1447 /* Close probe_attributes and attributes */
1448 ret
= mi_lttng_close_multi_element(writer
, 2);
1454 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1455 struct lttng_event
*event
)
1459 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1464 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1469 /* event probe symbol_name */
1470 ret
= mi_lttng_writer_write_element_string(writer
,
1471 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1476 /* Close function_attributes and attributes */
1477 ret
= mi_lttng_close_multi_element(writer
, 2);
1483 int mi_lttng_events_open(struct mi_writer
*writer
)
1485 return mi_lttng_writer_open_element(writer
, config_element_events
);
1489 int mi_lttng_event(struct mi_writer
*writer
,
1490 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1494 ret
= mi_lttng_event_common_attributes(writer
, event
);
1499 switch (event
->type
) {
1500 case LTTNG_EVENT_TRACEPOINT
:
1502 if (event
->loglevel
!= -1) {
1503 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1505 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1509 case LTTNG_EVENT_FUNCTION
:
1511 case LTTNG_EVENT_PROBE
:
1512 ret
= mi_lttng_event_function_probe(writer
, event
);
1514 case LTTNG_EVENT_FUNCTION_ENTRY
:
1515 ret
= mi_lttng_event_function_entry(writer
, event
);
1517 case LTTNG_EVENT_USERSPACE_PROBE
:
1518 ret
= mi_lttng_event_userspace_probe(writer
, event
);
1520 case LTTNG_EVENT_ALL
:
1531 ret
= mi_lttng_writer_close_element(writer
);
1539 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1541 return mi_lttng_writer_open_element(writer
, config_element_trackers
);
1544 static int get_tracker_elements(enum lttng_tracker_type tracker_type
,
1545 const char **element_id_tracker
,
1546 const char **element_target_id
)
1550 switch (tracker_type
) {
1551 case LTTNG_TRACKER_PID
:
1552 *element_id_tracker
= config_element_pid_tracker
;
1553 *element_target_id
= config_element_target_pid
;
1555 case LTTNG_TRACKER_VPID
:
1556 *element_id_tracker
= config_element_vpid_tracker
;
1557 *element_target_id
= config_element_target_vpid
;
1559 case LTTNG_TRACKER_UID
:
1560 *element_id_tracker
= config_element_uid_tracker
;
1561 *element_target_id
= config_element_target_uid
;
1563 case LTTNG_TRACKER_VUID
:
1564 *element_id_tracker
= config_element_vuid_tracker
;
1565 *element_target_id
= config_element_target_vuid
;
1567 case LTTNG_TRACKER_GID
:
1568 *element_id_tracker
= config_element_gid_tracker
;
1569 *element_target_id
= config_element_target_gid
;
1571 case LTTNG_TRACKER_VGID
:
1572 *element_id_tracker
= config_element_vgid_tracker
;
1573 *element_target_id
= config_element_target_vgid
;
1576 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1582 int mi_lttng_id_tracker_open(
1583 struct mi_writer
*writer
, enum lttng_tracker_type tracker_type
)
1586 const char *element_id_tracker
, *element_target_id
;
1588 ret
= get_tracker_elements(
1589 tracker_type
, &element_id_tracker
, &element_target_id
);
1594 /* Open element $id_tracker */
1595 ret
= mi_lttng_writer_open_element(writer
, element_id_tracker
);
1600 /* Open targets element */
1601 ret
= mi_lttng_targets_open(writer
);
1607 int mi_lttng_pids_open(struct mi_writer
*writer
)
1609 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1613 * TODO: move the listing of pid for user agent to process semantic on
1614 * mi api bump. The use of process element break the mi api.
1617 int mi_lttng_pid(struct mi_writer
*writer
,
1624 /* Open pid process */
1625 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1630 /* Writing pid number */
1631 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1632 mi_lttng_element_pid_id
, (int)pid
);
1637 /* Writing name of the process */
1639 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1648 ret
= mi_lttng_writer_close_element(writer
);
1656 int mi_lttng_targets_open(struct mi_writer
*writer
)
1658 return mi_lttng_writer_open_element(writer
,
1659 config_element_targets
);
1663 int mi_lttng_id_target(struct mi_writer
*writer
,
1664 enum lttng_tracker_type tracker_type
,
1665 const struct lttng_tracker_id
*id
,
1669 const char *element_id_tracker
, *element_target_id
;
1670 enum lttng_tracker_id_status status
;
1674 ret
= get_tracker_elements(
1675 tracker_type
, &element_id_tracker
, &element_target_id
);
1680 switch (lttng_tracker_id_get_type(id
)) {
1682 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1686 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1690 ret
= mi_lttng_writer_write_element_bool(
1691 writer
, config_element_all
, 1);
1695 ret
= mi_lttng_writer_close_element(writer
);
1700 case LTTNG_ID_VALUE
:
1701 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1705 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1710 status
= lttng_tracker_id_get_value(id
, &value
);
1711 if (status
!= LTTNG_TRACKER_ID_STATUS_OK
) {
1716 ret
= mi_lttng_writer_write_element_signed_int(
1717 writer
, config_element_id
, value
);
1721 ret
= mi_lttng_writer_close_element(writer
);
1726 case LTTNG_ID_STRING
:
1727 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1731 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1736 status
= lttng_tracker_id_get_string(id
, &string
);
1737 if (status
!= LTTNG_TRACKER_ID_STATUS_OK
) {
1742 ret
= mi_lttng_writer_write_element_string(
1743 writer
, config_element_name
, string
);
1747 ret
= mi_lttng_writer_close_element(writer
);
1752 case LTTNG_ID_UNKNOWN
:
1753 ret
= -LTTNG_ERR_INVALID
;
1761 ret
= mi_lttng_writer_close_element(writer
);
1772 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1774 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1778 int mi_lttng_event_field(struct mi_writer
*writer
,
1779 struct lttng_event_field
*field
)
1783 if (!field
->field_name
[0]) {
1789 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1794 if (!field
->field_name
[0]) {
1799 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1806 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1807 mi_lttng_eventfieldtype_string(field
->type
));
1813 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1814 mi_lttng_element_nowrite
, field
->nowrite
);
1820 /* Close field element */
1821 ret
= mi_lttng_writer_close_element(writer
);
1828 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1829 struct lttng_event_perf_counter_ctx
*perf_context
)
1833 /* Open perf_counter_context */
1834 ret
= mi_lttng_writer_open_element(writer
,
1835 mi_lttng_element_perf_counter_context
);
1841 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1842 config_element_type
, perf_context
->type
);
1848 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1849 config_element_config
, perf_context
->config
);
1854 /* Name of the perf counter */
1855 ret
= mi_lttng_writer_write_element_string(writer
,
1856 config_element_name
, perf_context
->name
);
1861 /* Close perf_counter_context */
1862 ret
= mi_lttng_writer_close_element(writer
);
1868 int mi_lttng_app_context(struct mi_writer
*writer
,
1869 const char *provider_name
, const char *ctx_name
)
1874 ret
= mi_lttng_writer_open_element(writer
,
1875 config_element_context_app
);
1881 ret
= mi_lttng_writer_write_element_string(writer
,
1882 config_element_context_app_provider_name
,
1889 ret
= mi_lttng_writer_write_element_string(writer
,
1890 config_element_context_app_ctx_name
, ctx_name
);
1896 ret
= mi_lttng_writer_close_element(writer
);
1902 int mi_lttng_context(struct mi_writer
*writer
,
1903 struct lttng_event_context
*context
, int is_open
)
1908 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1913 /* Special case for PERF_*_COUNTER
1914 * print the lttng_event_perf_counter_ctx*/
1915 switch (context
->ctx
) {
1916 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1917 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1918 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1920 struct lttng_event_perf_counter_ctx
*perf_context
=
1921 &context
->u
.perf_counter
;
1922 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1928 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
1930 ret
= mi_lttng_app_context(writer
,
1931 context
->u
.app_ctx
.provider_name
,
1932 context
->u
.app_ctx
.ctx_name
);
1940 const char *type_string
= mi_lttng_event_contexttype_string(
1943 ret
= -LTTNG_ERR_INVALID
;
1947 /* Print context type */
1948 ret
= mi_lttng_writer_write_element_string(writer
,
1949 config_element_type
, type_string
);
1956 ret
= mi_lttng_writer_close_element(writer
);
1964 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1965 const char *session_name
)
1969 /* Open session element */
1970 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1975 /* Snapshot output list for current session name */
1976 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1982 /* Open element snapshots (sequence one snapshot) */
1983 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1993 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1994 struct lttng_snapshot_output
*output
)
1998 /* Open element snapshot output */
1999 ret
= mi_lttng_writer_open_element(writer
,
2000 mi_lttng_element_command_snapshot
);
2005 /* ID of the snapshot output */
2006 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2007 mi_lttng_element_id
, output
->id
);
2012 /* Name of the output */
2013 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2019 /* Destination of the output (ctrl_url)*/
2020 ret
= mi_lttng_writer_write_element_string(writer
,
2021 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2026 /* Destination of the output (data_url) */
2027 ret
= mi_lttng_writer_write_element_string(writer
,
2028 mi_lttng_element_snapshot_data_url
, output
->data_url
);
2033 /* total size of all stream combined */
2034 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2035 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2040 /* Close snapshot output element */
2041 ret
= mi_lttng_writer_close_element(writer
);
2048 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
2049 const char *name
, const char *current_session_name
)
2053 /* Open element del_snapshot */
2054 ret
= mi_lttng_writer_open_element(writer
,
2055 mi_lttng_element_command_snapshot
);
2061 if (id
!= UINT32_MAX
) {
2062 /* "Snapshot output "id" successfully deleted
2063 * for "current_session_name"
2064 * ID of the snapshot output
2066 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2067 mi_lttng_element_id
, id
);
2072 /* "Snapshot output "name" successfully deleted
2073 * for session "current_session_name"
2074 * Name of the output
2076 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2083 /* Snapshot was deleted for session "current_session_name"*/
2084 ret
= mi_lttng_writer_write_element_string(writer
,
2085 mi_lttng_element_snapshot_session_name
,
2086 current_session_name
);
2091 /* Close snapshot element */
2092 ret
= mi_lttng_writer_close_element(writer
);
2099 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
2100 const char *current_session_name
, const char *n_ptr
,
2101 struct lttng_snapshot_output
*output
)
2105 /* Open element snapshot */
2106 ret
= mi_lttng_writer_open_element(writer
,
2107 mi_lttng_element_command_snapshot
);
2112 /* Snapshot output id */
2113 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2114 mi_lttng_element_id
, output
->id
);
2119 /* Snapshot output names */
2120 ret
= mi_lttng_writer_write_element_string(writer
,
2121 config_element_name
, n_ptr
);
2126 /* Destination of the output (ctrl_url)*/
2127 ret
= mi_lttng_writer_write_element_string(writer
,
2128 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2133 /* Snapshot added for session "current_session_name"*/
2134 ret
= mi_lttng_writer_write_element_string(writer
,
2135 mi_lttng_element_snapshot_session_name
, current_session_name
);
2140 /* total size of all stream combined */
2141 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2142 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2147 /* Close snapshot element */
2148 ret
= mi_lttng_writer_close_element(writer
);
2155 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
2156 const char *current_session_name
, const char *url
,
2157 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
2161 /* Open element snapshot */
2162 ret
= mi_lttng_writer_open_element(writer
,
2163 mi_lttng_element_command_snapshot
);
2169 * If a valid an URL was given, serialize it,
2170 * else take the command line data and ctrl urls*/
2172 /* Destination of the output (ctrl_url)*/
2173 ret
= mi_lttng_writer_write_element_string(writer
,
2174 mi_lttng_element_snapshot_ctrl_url
, url
);
2178 } else if (cmdline_ctrl_url
) {
2179 /* Destination of the output (ctrl_url)*/
2180 ret
= mi_lttng_writer_write_element_string(writer
,
2181 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
2186 /* Destination of the output (data_url) */
2187 ret
= mi_lttng_writer_write_element_string(writer
,
2188 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
2194 /* Close record_snapshot element */
2195 ret
= mi_lttng_writer_close_element(writer
);
2202 int mi_lttng_rotation_schedule(struct mi_writer
*writer
,
2203 const struct lttng_rotation_schedule
*schedule
)
2206 enum lttng_rotation_status status
;
2208 const char *element_name
;
2209 const char *value_name
;
2210 bool empty_schedule
= false;
2212 switch (lttng_rotation_schedule_get_type(schedule
)) {
2213 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2214 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
2216 element_name
= mi_lttng_element_rotation_schedule_periodic
;
2217 value_name
= mi_lttng_element_rotation_schedule_periodic_time_us
;
2219 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2220 status
= lttng_rotation_schedule_size_threshold_get_threshold(
2222 element_name
= mi_lttng_element_rotation_schedule_size_threshold
;
2223 value_name
= mi_lttng_element_rotation_schedule_size_threshold_bytes
;
2230 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2231 if (status
== LTTNG_ROTATION_STATUS_UNAVAILABLE
) {
2232 empty_schedule
= true;
2239 ret
= mi_lttng_writer_open_element(writer
, element_name
);
2244 if (!empty_schedule
) {
2245 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2252 /* Close schedule descriptor element. */
2253 ret
= mi_lttng_writer_close_element(writer
);
2262 int mi_lttng_rotation_schedule_result(struct mi_writer
*writer
,
2263 const struct lttng_rotation_schedule
*schedule
,
2268 ret
= mi_lttng_writer_open_element(writer
,
2269 mi_lttng_element_rotation_schedule_result
);
2274 ret
= mi_lttng_writer_open_element(writer
,
2275 mi_lttng_element_rotation_schedule
);
2280 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
2285 /* Close rotation_schedule element */
2286 ret
= mi_lttng_writer_close_element(writer
);
2291 ret
= mi_lttng_writer_write_element_bool(writer
,
2292 mi_lttng_element_command_success
, success
);
2297 /* Close rotation_schedule_result element */
2298 ret
= mi_lttng_writer_close_element(writer
);
2307 int mi_lttng_location(struct mi_writer
*writer
,
2308 const struct lttng_trace_archive_location
*location
)
2311 enum lttng_trace_archive_location_type location_type
;
2312 enum lttng_trace_archive_location_status status
;
2314 location_type
= lttng_trace_archive_location_get_type(location
);
2316 switch (location_type
) {
2317 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
:
2319 const char *absolute_path
;
2321 status
= lttng_trace_archive_location_local_get_absolute_path(
2322 location
, &absolute_path
);
2323 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2328 ret
= mi_lttng_writer_open_element(writer
,
2329 mi_lttng_element_rotation_location_local
);
2335 ret
= mi_lttng_writer_write_element_string(writer
,
2336 mi_lttng_element_rotation_location_local_absolute_path
,
2342 /* Close local element */
2343 ret
= mi_lttng_writer_close_element(writer
);
2349 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
:
2351 uint16_t control_port
, data_port
;
2352 const char *host
, *relative_path
;
2353 enum lttng_trace_archive_location_relay_protocol_type protocol
;
2355 /* Fetch all relay location parameters. */
2356 status
= lttng_trace_archive_location_relay_get_protocol_type(
2357 location
, &protocol
);
2358 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2363 status
= lttng_trace_archive_location_relay_get_host(
2365 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2370 status
= lttng_trace_archive_location_relay_get_control_port(
2371 location
, &control_port
);
2372 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2377 status
= lttng_trace_archive_location_relay_get_data_port(
2378 location
, &data_port
);
2379 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2384 status
= lttng_trace_archive_location_relay_get_relative_path(
2385 location
, &relative_path
);
2386 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2391 ret
= mi_lttng_writer_open_element(writer
,
2392 mi_lttng_element_rotation_location_relay
);
2397 ret
= mi_lttng_writer_write_element_string(writer
,
2398 mi_lttng_element_rotation_location_relay_host
,
2404 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2405 mi_lttng_element_rotation_location_relay_control_port
,
2411 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2412 mi_lttng_element_rotation_location_relay_data_port
,
2418 ret
= mi_lttng_writer_write_element_string(writer
,
2419 mi_lttng_element_rotation_location_relay_protocol
,
2420 mi_lttng_trace_archive_location_relay_protocol_type_string(protocol
));
2425 ret
= mi_lttng_writer_write_element_string(writer
,
2426 mi_lttng_element_rotation_location_relay_relative_path
,
2432 /* Close relay element */
2433 ret
= mi_lttng_writer_close_element(writer
);
2447 int mi_lttng_rotate(struct mi_writer
*writer
,
2448 const char *session_name
,
2449 enum lttng_rotation_state rotation_state
,
2450 const struct lttng_trace_archive_location
*location
)
2454 ret
= mi_lttng_writer_open_element(writer
,
2455 mi_lttng_element_rotation
);
2460 ret
= mi_lttng_writer_write_element_string(writer
,
2461 mi_lttng_element_session_name
,
2467 ret
= mi_lttng_writer_write_element_string(writer
,
2468 mi_lttng_element_rotation_state
,
2469 mi_lttng_rotation_state_string(rotation_state
));
2475 /* Not a serialization error. */
2476 goto close_rotation
;
2479 ret
= mi_lttng_writer_open_element(writer
,
2480 mi_lttng_element_rotation_location
);
2485 ret
= mi_lttng_location(writer
, location
);
2487 goto close_location
;
2491 /* Close location element */
2492 ret
= mi_lttng_writer_close_element(writer
);
2498 /* Close rotation element */
2499 ret
= mi_lttng_writer_close_element(writer
);