2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
4 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License, version 2 only, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <common/config/session-config.h>
22 #include <common/defaults.h>
23 #include <lttng/snapshot-internal.h>
24 #include <lttng/channel.h>
29 #define MI_SCHEMA_MAJOR_VERSION 3
30 #define MI_SCHEMA_MINOR_VERSION 0
32 /* Machine interface namespace URI */
33 LTTNG_HIDDEN
const char * const mi_lttng_xmlns
= "xmlns";
34 LTTNG_HIDDEN
const char * const mi_lttng_xmlns_xsi
= "xmlns:xsi";
35 LTTNG_HIDDEN
const char * const mi_lttng_w3_schema_uri
= "http://www.w3.org/2001/XMLSchema-instance";
36 LTTNG_HIDDEN
const char * const mi_lttng_schema_location
= "xsi:schemaLocation";
37 LTTNG_HIDDEN
const char * const mi_lttng_schema_location_uri
=
38 DEFAULT_LTTNG_MI_NAMESPACE
" "
39 "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION
)
40 "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION
) "."
41 XSTR(MI_SCHEMA_MINOR_VERSION
) ".xsd";
42 LTTNG_HIDDEN
const char * const mi_lttng_schema_version
= "schemaVersion";
43 LTTNG_HIDDEN
const char * const mi_lttng_schema_version_value
= XSTR(MI_SCHEMA_MAJOR_VERSION
)
44 "." XSTR(MI_SCHEMA_MINOR_VERSION
);
46 /* Strings related to command */
47 const char * const mi_lttng_element_command
= "command";
48 const char * const mi_lttng_element_command_action
= "snapshot_action";
49 const char * const mi_lttng_element_command_add_context
= "add-context";
50 const char * const mi_lttng_element_command_create
= "create";
51 const char * const mi_lttng_element_command_destroy
= "destroy";
52 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
53 const char * const mi_lttng_element_command_disable_event
= "disable-event";
54 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
55 const char * const mi_lttng_element_command_enable_event
= "enable-event";
56 const char * const mi_lttng_element_command_list
= "list";
57 const char * const mi_lttng_element_command_load
= "load";
58 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata
= "metadata";
59 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata_action
= "metadata_action";
60 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate
= "regenerate";
61 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate_action
= "regenerate_action";
62 const char * const mi_lttng_element_command_name
= "name";
63 const char * const mi_lttng_element_command_output
= "output";
64 const char * const mi_lttng_element_command_save
= "save";
65 const char * const mi_lttng_element_command_set_session
= "set-session";
66 const char * const mi_lttng_element_command_snapshot
= "snapshot";
67 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
68 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
69 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
70 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
71 const char * const mi_lttng_element_command_start
= "start";
72 const char * const mi_lttng_element_command_stop
= "stop";
73 const char * const mi_lttng_element_command_success
= "success";
74 const char * const mi_lttng_element_command_track
= "track";
75 const char * const mi_lttng_element_command_untrack
= "untrack";
76 const char * const mi_lttng_element_command_version
= "version";
77 LTTNG_HIDDEN
const char * const mi_lttng_element_command_rotate
= "rotate";
78 LTTNG_HIDDEN
const char * const mi_lttng_element_command_enable_rotation
= "enable-rotation";
79 LTTNG_HIDDEN
const char * const mi_lttng_element_command_disable_rotation
= "disable-rotation";
80 LTTNG_HIDDEN
const char * const mi_lttng_element_command_clear
= "clear";
82 /* Strings related to version command */
83 const char * const mi_lttng_element_version
= "version";
84 const char * const mi_lttng_element_version_commit
= "commit";
85 const char * const mi_lttng_element_version_description
= "description";
86 const char * const mi_lttng_element_version_license
= "license";
87 const char * const mi_lttng_element_version_major
= "major";
88 const char * const mi_lttng_element_version_minor
= "minor";
89 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
90 const char * const mi_lttng_element_version_str
= "string";
91 const char * const mi_lttng_element_version_web
= "url";
93 /* String related to a lttng_event_field */
94 const char * const mi_lttng_element_event_field
= "event_field";
95 const char * const mi_lttng_element_event_fields
= "event_fields";
97 /* String related to lttng_event_perf_counter_ctx */
98 const char * const mi_lttng_element_perf_counter_context
= "perf";
100 /* Strings related to pid */
101 const char * const mi_lttng_element_pid_id
= "id";
103 /* Strings related to save command */
104 const char * const mi_lttng_element_save
= "save";
106 /* Strings related to load command */
107 const char * const mi_lttng_element_load
= "load";
108 LTTNG_HIDDEN
const char * const mi_lttng_element_load_overrides
= "overrides";
109 LTTNG_HIDDEN
const char * const mi_lttng_element_load_override_url
= "url";
111 /* General elements of mi_lttng */
112 const char * const mi_lttng_element_empty
= "";
113 const char * const mi_lttng_element_id
= "id";
114 const char * const mi_lttng_element_nowrite
= "nowrite";
115 const char * const mi_lttng_element_success
= "success";
116 const char * const mi_lttng_element_type_enum
= "ENUM";
117 const char * const mi_lttng_element_type_float
= "FLOAT";
118 const char * const mi_lttng_element_type_integer
= "INTEGER";
119 const char * const mi_lttng_element_type_other
= "OTHER";
120 const char * const mi_lttng_element_type_string
= "STRING";
122 /* String related to loglevel */
123 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
124 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
125 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
126 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
127 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
128 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
129 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
130 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
131 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
132 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
133 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
134 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
135 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
136 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
137 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
138 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
140 /* String related to loglevel JUL */
141 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
142 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
143 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
144 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
145 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
146 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
147 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
148 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
149 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
151 /* String related to loglevel LOG4J */
152 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
153 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
154 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
155 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
156 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
157 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
158 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
159 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
161 /* String related to loglevel Python */
162 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
163 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
164 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
165 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
166 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
167 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
169 /* String related to loglevel type */
170 const char * const mi_lttng_loglevel_type_all
= "ALL";
171 const char * const mi_lttng_loglevel_type_range
= "RANGE";
172 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
173 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
175 /* String related to a lttng_snapshot_output */
176 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
177 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
178 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
179 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
180 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
181 const char * const mi_lttng_element_snapshots
= "snapshots";
183 /* String related to track/untrack command */
184 const char * const mi_lttng_element_track_untrack_all_wildcard
= "*";
186 LTTNG_HIDDEN
const char * const mi_lttng_element_session_name
= "session_name";
188 /* String related to rotate command */
189 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation
= "rotation";
190 LTTNG_HIDDEN
const char * const mi_lttng_element_rotate_status
= "status";
191 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule
= "rotation_schedule";
192 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedules
= "rotation_schedules";
193 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_result
= "rotation_schedule_result";
194 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_results
= "rotation_schedule_results";
195 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_periodic
= "periodic";
196 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_periodic_time_us
= "time_us";
197 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_size_threshold
= "size_threshold";
198 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_size_threshold_bytes
= "bytes";
199 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_state
= "state";
200 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location
= "location";
201 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_local
= "local";
202 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_local_absolute_path
= "absolute_path";
203 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay
= "relay";
204 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_host
= "host";
205 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_control_port
= "control_port";
206 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_data_port
= "data_port";
207 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_protocol
= "protocol";
208 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_relative_path
= "relative_path";
210 /* String related to enum lttng_rotation_state */
211 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_ongoing
= "ONGOING";
212 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_completed
= "COMPLETED";
213 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_expired
= "EXPIRED";
214 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_error
= "ERROR";
216 /* String related to enum lttng_trace_archive_location_relay_protocol_type */
217 LTTNG_HIDDEN
const char * const mi_lttng_rotation_location_relay_protocol_str_tcp
= "TCP";
219 /* String related to add-context command */
220 LTTNG_HIDDEN
const char * const mi_lttng_element_context_symbol
= "symbol";
222 /* Deprecated symbols preserved for ABI compatibility. */
223 const char * const mi_lttng_context_type_perf_counter
;
224 const char * const mi_lttng_context_type_perf_cpu_counter
;
225 const char * const mi_lttng_context_type_perf_thread_counter
;
226 const char * const mi_lttng_element_track_untrack_pid_target
;
227 const char * const mi_lttng_element_track_untrack_targets
;
228 const char * const mi_lttng_element_calibrate
;
229 const char * const mi_lttng_element_calibrate_function
;
230 const char * const mi_lttng_element_command_calibrate
;
232 /* This is a merge of jul loglevel and regular loglevel
233 * Those should never overlap by definition
234 * (see struct lttng_event loglevel)
237 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
240 case LTTNG_DOMAIN_KERNEL
:
241 case LTTNG_DOMAIN_UST
:
244 return mi_lttng_element_empty
;
245 case LTTNG_LOGLEVEL_EMERG
:
246 return mi_lttng_loglevel_str_emerg
;
247 case LTTNG_LOGLEVEL_ALERT
:
248 return mi_lttng_loglevel_str_alert
;
249 case LTTNG_LOGLEVEL_CRIT
:
250 return mi_lttng_loglevel_str_crit
;
251 case LTTNG_LOGLEVEL_ERR
:
252 return mi_lttng_loglevel_str_err
;
253 case LTTNG_LOGLEVEL_WARNING
:
254 return mi_lttng_loglevel_str_warning
;
255 case LTTNG_LOGLEVEL_NOTICE
:
256 return mi_lttng_loglevel_str_notice
;
257 case LTTNG_LOGLEVEL_INFO
:
258 return mi_lttng_loglevel_str_info
;
259 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
260 return mi_lttng_loglevel_str_debug_system
;
261 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
262 return mi_lttng_loglevel_str_debug_program
;
263 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
264 return mi_lttng_loglevel_str_debug_process
;
265 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
266 return mi_lttng_loglevel_str_debug_module
;
267 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
268 return mi_lttng_loglevel_str_debug_unit
;
269 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
270 return mi_lttng_loglevel_str_debug_function
;
271 case LTTNG_LOGLEVEL_DEBUG_LINE
:
272 return mi_lttng_loglevel_str_debug_line
;
273 case LTTNG_LOGLEVEL_DEBUG
:
274 return mi_lttng_loglevel_str_debug
;
276 return mi_lttng_loglevel_str_unknown
;
279 case LTTNG_DOMAIN_LOG4J
:
282 return mi_lttng_element_empty
;
283 case LTTNG_LOGLEVEL_LOG4J_OFF
:
284 return mi_lttng_loglevel_str_log4j_off
;
285 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
286 return mi_lttng_loglevel_str_log4j_fatal
;
287 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
288 return mi_lttng_loglevel_str_log4j_error
;
289 case LTTNG_LOGLEVEL_LOG4J_WARN
:
290 return mi_lttng_loglevel_str_log4j_warn
;
291 case LTTNG_LOGLEVEL_LOG4J_INFO
:
292 return mi_lttng_loglevel_str_log4j_info
;
293 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
294 return mi_lttng_loglevel_str_log4j_debug
;
295 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
296 return mi_lttng_loglevel_str_log4j_trace
;
297 case LTTNG_LOGLEVEL_LOG4J_ALL
:
298 return mi_lttng_loglevel_str_log4j_all
;
300 return mi_lttng_loglevel_str_unknown
;
303 case LTTNG_DOMAIN_JUL
:
306 return mi_lttng_element_empty
;
307 case LTTNG_LOGLEVEL_JUL_OFF
:
308 return mi_lttng_loglevel_str_jul_off
;
309 case LTTNG_LOGLEVEL_JUL_SEVERE
:
310 return mi_lttng_loglevel_str_jul_severe
;
311 case LTTNG_LOGLEVEL_JUL_WARNING
:
312 return mi_lttng_loglevel_str_jul_warning
;
313 case LTTNG_LOGLEVEL_JUL_INFO
:
314 return mi_lttng_loglevel_str_jul_info
;
315 case LTTNG_LOGLEVEL_JUL_CONFIG
:
316 return mi_lttng_loglevel_str_jul_config
;
317 case LTTNG_LOGLEVEL_JUL_FINE
:
318 return mi_lttng_loglevel_str_jul_fine
;
319 case LTTNG_LOGLEVEL_JUL_FINER
:
320 return mi_lttng_loglevel_str_jul_finer
;
321 case LTTNG_LOGLEVEL_JUL_FINEST
:
322 return mi_lttng_loglevel_str_jul_finest
;
323 case LTTNG_LOGLEVEL_JUL_ALL
:
324 return mi_lttng_loglevel_str_jul_all
;
326 return mi_lttng_loglevel_str_unknown
;
329 case LTTNG_DOMAIN_PYTHON
:
331 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
332 return mi_lttng_loglevel_str_python_critical
;
333 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
334 return mi_lttng_loglevel_str_python_error
;
335 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
336 return mi_lttng_loglevel_str_python_warning
;
337 case LTTNG_LOGLEVEL_PYTHON_INFO
:
338 return mi_lttng_loglevel_str_python_info
;
339 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
340 return mi_lttng_loglevel_str_python_debug
;
341 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
342 return mi_lttng_loglevel_str_python_notset
;
344 return mi_lttng_loglevel_str_unknown
;
348 return mi_lttng_loglevel_str_unknown
;
353 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
356 case LTTNG_EVENT_LOGLEVEL_ALL
:
357 return mi_lttng_loglevel_type_all
;
358 case LTTNG_EVENT_LOGLEVEL_RANGE
:
359 return mi_lttng_loglevel_type_range
;
360 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
361 return mi_lttng_loglevel_type_single
;
363 return mi_lttng_loglevel_type_unknown
;
368 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
371 case LTTNG_EVENT_ALL
:
372 return config_event_type_all
;
373 case LTTNG_EVENT_TRACEPOINT
:
374 return config_event_type_tracepoint
;
375 case LTTNG_EVENT_PROBE
:
376 return config_event_type_probe
;
377 case LTTNG_EVENT_USERSPACE_PROBE
:
378 return config_event_type_userspace_probe
;
379 case LTTNG_EVENT_FUNCTION
:
380 return config_event_type_function
;
381 case LTTNG_EVENT_FUNCTION_ENTRY
:
382 return config_event_type_function_entry
;
383 case LTTNG_EVENT_SYSCALL
:
384 return config_event_type_syscall
;
385 case LTTNG_EVENT_NOOP
:
386 return config_event_type_noop
;
388 return mi_lttng_element_empty
;
393 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
396 case LTTNG_EVENT_CONTEXT_PID
:
397 return config_event_context_pid
;
398 case LTTNG_EVENT_CONTEXT_PROCNAME
:
399 return config_event_context_procname
;
400 case LTTNG_EVENT_CONTEXT_PRIO
:
401 return config_event_context_prio
;
402 case LTTNG_EVENT_CONTEXT_NICE
:
403 return config_event_context_nice
;
404 case LTTNG_EVENT_CONTEXT_VPID
:
405 return config_event_context_vpid
;
406 case LTTNG_EVENT_CONTEXT_TID
:
407 return config_event_context_tid
;
408 case LTTNG_EVENT_CONTEXT_VTID
:
409 return config_event_context_vtid
;
410 case LTTNG_EVENT_CONTEXT_PPID
:
411 return config_event_context_ppid
;
412 case LTTNG_EVENT_CONTEXT_VPPID
:
413 return config_event_context_vppid
;
414 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
415 return config_event_context_pthread_id
;
416 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
417 return config_event_context_hostname
;
418 case LTTNG_EVENT_CONTEXT_IP
:
419 return config_event_context_ip
;
420 case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
:
421 return config_event_context_interruptible
;
422 case LTTNG_EVENT_CONTEXT_PREEMPTIBLE
:
423 return config_event_context_preemptible
;
424 case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
:
425 return config_event_context_need_reschedule
;
426 case LTTNG_EVENT_CONTEXT_MIGRATABLE
:
427 return config_event_context_migratable
;
428 case LTTNG_EVENT_CONTEXT_CALLSTACK_USER
:
429 return config_event_context_callstack_user
;
430 case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
:
431 return config_event_context_callstack_kernel
;
432 case LTTNG_EVENT_CONTEXT_CGROUP_NS
:
433 return config_event_context_cgroup_ns
;
434 case LTTNG_EVENT_CONTEXT_IPC_NS
:
435 return config_event_context_ipc_ns
;
436 case LTTNG_EVENT_CONTEXT_MNT_NS
:
437 return config_event_context_mnt_ns
;
438 case LTTNG_EVENT_CONTEXT_NET_NS
:
439 return config_event_context_net_ns
;
440 case LTTNG_EVENT_CONTEXT_PID_NS
:
441 return config_event_context_pid_ns
;
442 case LTTNG_EVENT_CONTEXT_USER_NS
:
443 return config_event_context_user_ns
;
444 case LTTNG_EVENT_CONTEXT_UTS_NS
:
445 return config_event_context_uts_ns
;
446 case LTTNG_EVENT_CONTEXT_UID
:
447 return config_event_context_uid
;
448 case LTTNG_EVENT_CONTEXT_EUID
:
449 return config_event_context_euid
;
450 case LTTNG_EVENT_CONTEXT_SUID
:
451 return config_event_context_suid
;
452 case LTTNG_EVENT_CONTEXT_GID
:
453 return config_event_context_gid
;
454 case LTTNG_EVENT_CONTEXT_EGID
:
455 return config_event_context_egid
;
456 case LTTNG_EVENT_CONTEXT_SGID
:
457 return config_event_context_sgid
;
458 case LTTNG_EVENT_CONTEXT_VUID
:
459 return config_event_context_vuid
;
460 case LTTNG_EVENT_CONTEXT_VEUID
:
461 return config_event_context_veuid
;
462 case LTTNG_EVENT_CONTEXT_VSUID
:
463 return config_event_context_vsuid
;
464 case LTTNG_EVENT_CONTEXT_VGID
:
465 return config_event_context_vgid
;
466 case LTTNG_EVENT_CONTEXT_VEGID
:
467 return config_event_context_vegid
;
468 case LTTNG_EVENT_CONTEXT_VSGID
:
469 return config_event_context_vsgid
;
476 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
479 case(LTTNG_EVENT_FIELD_INTEGER
):
480 return mi_lttng_element_type_integer
;
481 case(LTTNG_EVENT_FIELD_ENUM
):
482 return mi_lttng_element_type_enum
;
483 case(LTTNG_EVENT_FIELD_FLOAT
):
484 return mi_lttng_element_type_float
;
485 case(LTTNG_EVENT_FIELD_STRING
):
486 return mi_lttng_element_type_string
;
488 return mi_lttng_element_type_other
;
493 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
495 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
497 case LTTNG_DOMAIN_KERNEL
:
498 return config_domain_type_kernel
;
499 case LTTNG_DOMAIN_UST
:
500 return config_domain_type_ust
;
501 case LTTNG_DOMAIN_JUL
:
502 return config_domain_type_jul
;
503 case LTTNG_DOMAIN_LOG4J
:
504 return config_domain_type_log4j
;
505 case LTTNG_DOMAIN_PYTHON
:
506 return config_domain_type_python
;
508 /* Should not have an unknown domain */
515 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
518 case LTTNG_BUFFER_PER_PID
:
519 return config_buffer_type_per_pid
;
520 case LTTNG_BUFFER_PER_UID
:
521 return config_buffer_type_per_uid
;
522 case LTTNG_BUFFER_GLOBAL
:
523 return config_buffer_type_global
;
525 /* Should not have an unknow buffer type */
532 const char *mi_lttng_rotation_state_string(enum lttng_rotation_state value
)
535 case LTTNG_ROTATION_STATE_ONGOING
:
536 return mi_lttng_rotation_state_str_ongoing
;
537 case LTTNG_ROTATION_STATE_COMPLETED
:
538 return mi_lttng_rotation_state_str_completed
;
539 case LTTNG_ROTATION_STATE_EXPIRED
:
540 return mi_lttng_rotation_state_str_expired
;
541 case LTTNG_ROTATION_STATE_ERROR
:
542 return mi_lttng_rotation_state_str_error
;
544 /* Should not have an unknow rotation state. */
551 const char *mi_lttng_trace_archive_location_relay_protocol_type_string(
552 enum lttng_trace_archive_location_relay_protocol_type value
)
555 case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP
:
556 return mi_lttng_rotation_location_relay_protocol_str_tcp
;
558 /* Should not have an unknow relay protocol. */
565 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
567 struct mi_writer
*mi_writer
;
569 mi_writer
= zmalloc(sizeof(struct mi_writer
));
571 PERROR("zmalloc mi_writer_create");
574 if (mi_output_type
== LTTNG_MI_XML
) {
575 mi_writer
->writer
= config_writer_create(fd_output
, 0);
576 if (!mi_writer
->writer
) {
579 mi_writer
->type
= LTTNG_MI_XML
;
593 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
602 ret
= config_writer_destroy(writer
->writer
);
613 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
618 * A command is always the MI's root node, it must declare the current
619 * namespace and schema URIs and the schema's version.
621 ret
= config_writer_open_element(writer
->writer
,
622 mi_lttng_element_command
);
627 ret
= config_writer_write_attribute(writer
->writer
,
628 mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
633 ret
= config_writer_write_attribute(writer
->writer
,
634 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
639 ret
= config_writer_write_attribute(writer
->writer
,
640 mi_lttng_schema_location
,
641 mi_lttng_schema_location_uri
);
646 ret
= config_writer_write_attribute(writer
->writer
,
647 mi_lttng_schema_version
,
648 mi_lttng_schema_version_value
);
653 ret
= mi_lttng_writer_write_element_string(writer
,
654 mi_lttng_element_command_name
, command
);
660 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
662 return mi_lttng_writer_close_element(writer
);
666 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
667 const char *element_name
)
669 return config_writer_open_element(writer
->writer
, element_name
);
673 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
675 return config_writer_close_element(writer
->writer
);
679 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
680 unsigned int nb_element
)
684 if (nb_element
< 1) {
688 for (i
= 0; i
< nb_element
; i
++) {
689 ret
= mi_lttng_writer_close_element(writer
);
699 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
700 const char *element_name
, uint64_t value
)
702 return config_writer_write_element_unsigned_int(writer
->writer
,
703 element_name
, value
);
707 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
708 const char *element_name
, int64_t value
)
710 return config_writer_write_element_signed_int(writer
->writer
,
711 element_name
, value
);
715 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
716 const char *element_name
, int value
)
718 return config_writer_write_element_bool(writer
->writer
,
719 element_name
, value
);
723 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
724 const char *element_name
, const char *value
)
726 return config_writer_write_element_string(writer
->writer
,
727 element_name
, value
);
731 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
732 const char *lttng_description
, const char *lttng_license
)
737 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
742 /* Version string (contain info like rc etc.) */
743 ret
= mi_lttng_writer_write_element_string(writer
,
744 mi_lttng_element_version_str
, version
->version
);
749 /* Major version number */
750 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
751 mi_lttng_element_version_major
, version
->version_major
);
756 /* Minor version number */
757 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
758 mi_lttng_element_version_minor
, version
->version_minor
);
763 /* Commit version number */
764 ret
= mi_lttng_writer_write_element_string(writer
,
765 mi_lttng_element_version_commit
, version
->version_commit
);
771 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
772 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
777 /* Name of the version */
778 ret
= mi_lttng_writer_write_element_string(writer
,
779 config_element_name
, version
->version_name
);
784 /* Description mostly related to beer... */
785 ret
= mi_lttng_writer_write_element_string(writer
,
786 mi_lttng_element_version_description
, lttng_description
);
792 ret
= mi_lttng_writer_write_element_string(writer
,
793 mi_lttng_element_version_web
, version
->package_url
);
798 /* License: free as in free beer...no...*speech* */
799 ret
= mi_lttng_writer_write_element_string(writer
,
800 mi_lttng_element_version_license
, lttng_license
);
805 /* Close version element */
806 ret
= mi_lttng_writer_close_element(writer
);
813 int mi_lttng_sessions_open(struct mi_writer
*writer
)
815 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
819 int mi_lttng_session(struct mi_writer
*writer
,
820 struct lttng_session
*session
, int is_open
)
826 /* Open sessions element */
827 ret
= mi_lttng_writer_open_element(writer
,
828 config_element_session
);
833 /* Name of the session */
834 ret
= mi_lttng_writer_write_element_string(writer
,
835 config_element_name
, session
->name
);
841 ret
= mi_lttng_writer_write_element_string(writer
,
842 config_element_path
, session
->path
);
848 ret
= mi_lttng_writer_write_element_bool(writer
,
849 config_element_enabled
, session
->enabled
);
855 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
856 config_element_snapshot_mode
, session
->snapshot_mode
);
861 /* Live timer interval in usec */
862 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
863 config_element_live_timer_interval
,
864 session
->live_timer_interval
);
870 /* Closing session element */
871 ret
= mi_lttng_writer_close_element(writer
);
879 int mi_lttng_domains_open(struct mi_writer
*writer
)
881 return mi_lttng_writer_open_element(writer
, config_element_domains
);
885 int mi_lttng_domain(struct mi_writer
*writer
,
886 struct lttng_domain
*domain
, int is_open
)
889 const char *str_domain
;
890 const char *str_buffer
;
894 /* Open domain element */
895 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
901 str_domain
= mi_lttng_domaintype_string(domain
->type
);
902 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
909 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
910 ret
= mi_lttng_writer_write_element_string(writer
,
911 config_element_buffer_type
, str_buffer
);
917 * This union is not currently used and was added for
918 * future ust domain support.
923 /* Closing domain element */
924 ret
= mi_lttng_writer_close_element(writer
);
933 int mi_lttng_channels_open(struct mi_writer
*writer
)
935 return mi_lttng_writer_open_element(writer
, config_element_channels
);
939 int mi_lttng_channel(struct mi_writer
*writer
,
940 struct lttng_channel
*channel
, int is_open
)
946 /* Opening channel element */
947 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
953 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
960 ret
= mi_lttng_writer_write_element_bool(writer
,
961 config_element_enabled
, channel
->enabled
);
967 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
973 /* Closing channel element */
974 ret
= mi_lttng_writer_close_element(writer
);
984 int mi_lttng_channel_attr(struct mi_writer
*writer
,
985 struct lttng_channel_attr
*attr
)
988 struct lttng_channel
*chan
= caa_container_of(attr
,
989 struct lttng_channel
, attr
);
990 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
991 int64_t blocking_timeout
;
995 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
1000 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
1005 ret
= lttng_channel_get_monitor_timer_interval(chan
,
1006 &monitor_timer_interval
);
1011 ret
= lttng_channel_get_blocking_timeout(chan
,
1017 /* Opening Attributes */
1018 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1024 ret
= mi_lttng_writer_write_element_string(writer
,
1025 config_element_overwrite_mode
,
1026 attr
->overwrite
? config_overwrite_mode_overwrite
:
1027 config_overwrite_mode_discard
);
1032 /* Sub buffer size in byte */
1033 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1034 config_element_subbuf_size
, attr
->subbuf_size
);
1039 /* Number of subbuffer (power of two) */
1040 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1041 config_element_num_subbuf
,
1047 /* Switch timer interval in usec */
1048 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1049 config_element_switch_timer_interval
,
1050 attr
->switch_timer_interval
);
1055 /* Read timer interval in usec */
1056 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1057 config_element_read_timer_interval
,
1058 attr
->read_timer_interval
);
1063 /* Monitor timer interval in usec */
1064 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1065 config_element_monitor_timer_interval
,
1066 monitor_timer_interval
);
1071 /* Retry timeout in usec */
1072 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1073 config_element_blocking_timeout
,
1080 ret
= mi_lttng_writer_write_element_string(writer
,
1081 config_element_output_type
,
1082 attr
->output
== LTTNG_EVENT_SPLICE
?
1083 config_output_type_splice
: config_output_type_mmap
);
1088 /* Tracefile size in bytes */
1089 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1090 config_element_tracefile_size
, attr
->tracefile_size
);
1095 /* Count of tracefiles */
1096 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1097 config_element_tracefile_count
,
1098 attr
->tracefile_count
);
1103 /* Live timer interval in usec*/
1104 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1105 config_element_live_timer_interval
,
1106 attr
->live_timer_interval
);
1111 /* Discarded events */
1112 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1113 config_element_discarded_events
,
1120 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1121 config_element_lost_packets
,
1127 /* Closing attributes */
1128 ret
= mi_lttng_writer_close_element(writer
);
1138 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
1139 struct lttng_event
*event
)
1142 const char *filter_expression
;
1144 /* Open event element */
1145 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
1151 ret
= mi_lttng_writer_write_element_string(writer
,
1152 config_element_name
, event
->name
);
1158 ret
= mi_lttng_writer_write_element_string(writer
,
1159 config_element_type
, mi_lttng_eventtype_string(event
->type
));
1164 /* Is event enabled */
1165 ret
= mi_lttng_writer_write_element_bool(writer
,
1166 config_element_enabled
, event
->enabled
);
1171 /* Event filter expression */
1172 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1177 if (filter_expression
) {
1178 ret
= mi_lttng_writer_write_element_string(writer
,
1179 config_element_filter_expression
,
1190 static int write_event_exclusions(struct mi_writer
*writer
,
1191 struct lttng_event
*event
)
1195 int exclusion_count
;
1197 /* Open event exclusions */
1198 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1203 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1204 if (exclusion_count
< 0) {
1205 ret
= exclusion_count
;
1209 for (i
= 0; i
< exclusion_count
; i
++) {
1212 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1214 /* Close exclusions */
1215 mi_lttng_writer_close_element(writer
);
1219 ret
= mi_lttng_writer_write_element_string(writer
,
1220 config_element_exclusion
, name
);
1222 /* Close exclusions */
1223 mi_lttng_writer_close_element(writer
);
1228 /* Close exclusions */
1229 ret
= mi_lttng_writer_close_element(writer
);
1236 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1237 struct lttng_event
*event
, enum lttng_domain_type domain
)
1241 /* Event loglevel */
1242 ret
= mi_lttng_writer_write_element_string(writer
,
1243 config_element_loglevel
,
1244 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1249 /* Log level type */
1250 ret
= mi_lttng_writer_write_element_string(writer
,
1251 config_element_loglevel_type
,
1252 mi_lttng_logleveltype_string(event
->loglevel_type
));
1257 /* Event exclusions */
1258 ret
= write_event_exclusions(writer
, event
);
1265 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1266 struct lttng_event
*event
)
1268 /* event exclusion filter */
1269 return write_event_exclusions(writer
, event
);
1273 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1274 struct lttng_event
*event
)
1278 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1283 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1288 if (event
->attr
.probe
.addr
!= 0) {
1289 /* event probe address */
1290 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1291 config_element_address
, event
->attr
.probe
.addr
);
1296 /* event probe offset */
1297 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1298 config_element_offset
, event
->attr
.probe
.offset
);
1303 /* event probe symbol_name */
1304 ret
= mi_lttng_writer_write_element_string(writer
,
1305 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1311 /* Close probe_attributes and attributes */
1312 ret
= mi_lttng_close_multi_element(writer
, 2);
1318 int mi_lttng_event_userspace_probe(struct mi_writer
*writer
,
1319 struct lttng_event
*event
)
1322 const struct lttng_userspace_probe_location
*location
;
1323 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
1324 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
1326 location
= lttng_event_get_userspace_probe_location(event
);
1328 ret
= -LTTNG_ERR_INVALID
;
1332 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
1333 if (!lookup_method
) {
1334 ret
= -LTTNG_ERR_INVALID
;
1338 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
1340 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1345 switch (lttng_userspace_probe_location_get_type(location
)) {
1346 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1348 const char *function_name
;
1349 const char *binary_path
;
1351 ret
= mi_lttng_writer_open_element(writer
,
1352 config_element_userspace_probe_function_attributes
);
1357 switch (lookup_type
) {
1358 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
1359 ret
= mi_lttng_writer_write_element_string(writer
,
1360 config_element_userspace_probe_lookup
,
1361 config_element_userspace_probe_lookup_function_elf
);
1366 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
1367 ret
= mi_lttng_writer_write_element_string(writer
,
1368 config_element_userspace_probe_lookup
,
1369 config_element_userspace_probe_lookup_function_default
);
1378 binary_path
= lttng_userspace_probe_location_function_get_binary_path(location
);
1379 ret
= mi_lttng_writer_write_element_string(writer
,
1380 config_element_userspace_probe_location_binary_path
, binary_path
);
1385 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
1386 ret
= mi_lttng_writer_write_element_string(writer
,
1387 config_element_userspace_probe_function_location_function_name
,
1395 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1397 const char *probe_name
, *provider_name
;
1398 const char *binary_path
;
1400 ret
= mi_lttng_writer_open_element(writer
,
1401 config_element_userspace_probe_function_attributes
);
1406 switch (lookup_type
) {
1407 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
1408 ret
= mi_lttng_writer_write_element_string(writer
,
1409 config_element_userspace_probe_lookup
,
1410 config_element_userspace_probe_lookup_tracepoint_sdt
);
1419 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(location
);
1420 ret
= mi_lttng_writer_write_element_string(writer
,
1421 config_element_userspace_probe_location_binary_path
,
1427 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
1428 ret
= mi_lttng_writer_write_element_string(writer
,
1429 config_element_userspace_probe_tracepoint_location_provider_name
,
1435 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
1436 ret
= mi_lttng_writer_write_element_string(writer
,
1437 config_element_userspace_probe_tracepoint_location_probe_name
, probe_name
);
1444 ERR("Invalid probe type encountered");
1446 /* Close probe_attributes and attributes */
1447 ret
= mi_lttng_close_multi_element(writer
, 2);
1453 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1454 struct lttng_event
*event
)
1458 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1463 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1468 /* event probe symbol_name */
1469 ret
= mi_lttng_writer_write_element_string(writer
,
1470 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1475 /* Close function_attributes and attributes */
1476 ret
= mi_lttng_close_multi_element(writer
, 2);
1482 int mi_lttng_events_open(struct mi_writer
*writer
)
1484 return mi_lttng_writer_open_element(writer
, config_element_events
);
1488 int mi_lttng_event(struct mi_writer
*writer
,
1489 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1493 ret
= mi_lttng_event_common_attributes(writer
, event
);
1498 switch (event
->type
) {
1499 case LTTNG_EVENT_TRACEPOINT
:
1501 if (event
->loglevel
!= -1) {
1502 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1504 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1508 case LTTNG_EVENT_FUNCTION
:
1510 case LTTNG_EVENT_PROBE
:
1511 ret
= mi_lttng_event_function_probe(writer
, event
);
1513 case LTTNG_EVENT_FUNCTION_ENTRY
:
1514 ret
= mi_lttng_event_function_entry(writer
, event
);
1516 case LTTNG_EVENT_USERSPACE_PROBE
:
1517 ret
= mi_lttng_event_userspace_probe(writer
, event
);
1519 case LTTNG_EVENT_ALL
:
1530 ret
= mi_lttng_writer_close_element(writer
);
1538 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1540 return mi_lttng_writer_open_element(writer
, config_element_trackers
);
1543 static int get_tracker_elements(enum lttng_tracker_type tracker_type
,
1544 const char **element_id_tracker
,
1545 const char **element_target_id
)
1549 switch (tracker_type
) {
1550 case LTTNG_TRACKER_PID
:
1551 *element_id_tracker
= config_element_pid_tracker
;
1552 *element_target_id
= config_element_target_pid
;
1554 case LTTNG_TRACKER_VPID
:
1555 *element_id_tracker
= config_element_vpid_tracker
;
1556 *element_target_id
= config_element_target_vpid
;
1558 case LTTNG_TRACKER_UID
:
1559 *element_id_tracker
= config_element_uid_tracker
;
1560 *element_target_id
= config_element_target_uid
;
1562 case LTTNG_TRACKER_VUID
:
1563 *element_id_tracker
= config_element_vuid_tracker
;
1564 *element_target_id
= config_element_target_vuid
;
1566 case LTTNG_TRACKER_GID
:
1567 *element_id_tracker
= config_element_gid_tracker
;
1568 *element_target_id
= config_element_target_gid
;
1570 case LTTNG_TRACKER_VGID
:
1571 *element_id_tracker
= config_element_vgid_tracker
;
1572 *element_target_id
= config_element_target_vgid
;
1575 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1581 int mi_lttng_id_tracker_open(
1582 struct mi_writer
*writer
, enum lttng_tracker_type tracker_type
)
1585 const char *element_id_tracker
, *element_target_id
;
1587 ret
= get_tracker_elements(
1588 tracker_type
, &element_id_tracker
, &element_target_id
);
1593 /* Open element $id_tracker */
1594 ret
= mi_lttng_writer_open_element(writer
, element_id_tracker
);
1599 /* Open targets element */
1600 ret
= mi_lttng_targets_open(writer
);
1606 int mi_lttng_pids_open(struct mi_writer
*writer
)
1608 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1612 * TODO: move the listing of pid for user agent to process semantic on
1613 * mi api bump. The use of process element break the mi api.
1616 int mi_lttng_pid(struct mi_writer
*writer
,
1623 /* Open pid process */
1624 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1629 /* Writing pid number */
1630 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1631 mi_lttng_element_pid_id
, (int)pid
);
1636 /* Writing name of the process */
1638 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1647 ret
= mi_lttng_writer_close_element(writer
);
1655 int mi_lttng_targets_open(struct mi_writer
*writer
)
1657 return mi_lttng_writer_open_element(writer
,
1658 config_element_targets
);
1662 int mi_lttng_id_target(struct mi_writer
*writer
,
1663 enum lttng_tracker_type tracker_type
,
1664 struct lttng_tracker_id
*id
,
1668 const char *element_id_tracker
, *element_target_id
;
1670 ret
= get_tracker_elements(
1671 tracker_type
, &element_id_tracker
, &element_target_id
);
1678 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1682 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1686 ret
= mi_lttng_writer_write_element_bool(
1687 writer
, config_element_all
, 1);
1691 ret
= mi_lttng_writer_close_element(writer
);
1696 case LTTNG_ID_VALUE
:
1697 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1701 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1705 ret
= mi_lttng_writer_write_element_signed_int(
1706 writer
, config_element_id
, id
->value
);
1710 ret
= mi_lttng_writer_close_element(writer
);
1715 case LTTNG_ID_STRING
:
1716 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1720 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1724 ret
= mi_lttng_writer_write_element_string(
1725 writer
, config_element_name
, id
->string
);
1729 ret
= mi_lttng_writer_close_element(writer
);
1734 case LTTNG_ID_UNKNOWN
:
1735 ret
= -LTTNG_ERR_INVALID
;
1743 ret
= mi_lttng_writer_close_element(writer
);
1754 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1756 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1760 int mi_lttng_event_field(struct mi_writer
*writer
,
1761 struct lttng_event_field
*field
)
1765 if (!field
->field_name
[0]) {
1771 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1776 if (!field
->field_name
[0]) {
1781 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1788 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1789 mi_lttng_eventfieldtype_string(field
->type
));
1795 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1796 mi_lttng_element_nowrite
, field
->nowrite
);
1802 /* Close field element */
1803 ret
= mi_lttng_writer_close_element(writer
);
1810 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1811 struct lttng_event_perf_counter_ctx
*perf_context
)
1815 /* Open perf_counter_context */
1816 ret
= mi_lttng_writer_open_element(writer
,
1817 mi_lttng_element_perf_counter_context
);
1823 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1824 config_element_type
, perf_context
->type
);
1830 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1831 config_element_config
, perf_context
->config
);
1836 /* Name of the perf counter */
1837 ret
= mi_lttng_writer_write_element_string(writer
,
1838 config_element_name
, perf_context
->name
);
1843 /* Close perf_counter_context */
1844 ret
= mi_lttng_writer_close_element(writer
);
1850 int mi_lttng_app_context(struct mi_writer
*writer
,
1851 const char *provider_name
, const char *ctx_name
)
1856 ret
= mi_lttng_writer_open_element(writer
,
1857 config_element_context_app
);
1863 ret
= mi_lttng_writer_write_element_string(writer
,
1864 config_element_context_app_provider_name
,
1871 ret
= mi_lttng_writer_write_element_string(writer
,
1872 config_element_context_app_ctx_name
, ctx_name
);
1878 ret
= mi_lttng_writer_close_element(writer
);
1884 int mi_lttng_context(struct mi_writer
*writer
,
1885 struct lttng_event_context
*context
, int is_open
)
1890 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1895 /* Special case for PERF_*_COUNTER
1896 * print the lttng_event_perf_counter_ctx*/
1897 switch (context
->ctx
) {
1898 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1899 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1900 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1902 struct lttng_event_perf_counter_ctx
*perf_context
=
1903 &context
->u
.perf_counter
;
1904 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1910 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
1912 ret
= mi_lttng_app_context(writer
,
1913 context
->u
.app_ctx
.provider_name
,
1914 context
->u
.app_ctx
.ctx_name
);
1922 const char *type_string
= mi_lttng_event_contexttype_string(
1925 ret
= -LTTNG_ERR_INVALID
;
1929 /* Print context type */
1930 ret
= mi_lttng_writer_write_element_string(writer
,
1931 config_element_type
, type_string
);
1938 ret
= mi_lttng_writer_close_element(writer
);
1946 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1947 const char *session_name
)
1951 /* Open session element */
1952 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1957 /* Snapshot output list for current session name */
1958 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1964 /* Open element snapshots (sequence one snapshot) */
1965 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1975 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1976 struct lttng_snapshot_output
*output
)
1980 /* Open element snapshot output */
1981 ret
= mi_lttng_writer_open_element(writer
,
1982 mi_lttng_element_command_snapshot
);
1987 /* ID of the snapshot output */
1988 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1989 mi_lttng_element_id
, output
->id
);
1994 /* Name of the output */
1995 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2001 /* Destination of the output (ctrl_url)*/
2002 ret
= mi_lttng_writer_write_element_string(writer
,
2003 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2008 /* Destination of the output (data_url) */
2009 ret
= mi_lttng_writer_write_element_string(writer
,
2010 mi_lttng_element_snapshot_data_url
, output
->data_url
);
2015 /* total size of all stream combined */
2016 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2017 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2022 /* Close snapshot output element */
2023 ret
= mi_lttng_writer_close_element(writer
);
2030 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
2031 const char *name
, const char *current_session_name
)
2035 /* Open element del_snapshot */
2036 ret
= mi_lttng_writer_open_element(writer
,
2037 mi_lttng_element_command_snapshot
);
2043 if (id
!= UINT32_MAX
) {
2044 /* "Snapshot output "id" successfully deleted
2045 * for "current_session_name"
2046 * ID of the snapshot output
2048 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2049 mi_lttng_element_id
, id
);
2054 /* "Snapshot output "name" successfully deleted
2055 * for session "current_session_name"
2056 * Name of the output
2058 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2065 /* Snapshot was deleted for session "current_session_name"*/
2066 ret
= mi_lttng_writer_write_element_string(writer
,
2067 mi_lttng_element_snapshot_session_name
,
2068 current_session_name
);
2073 /* Close snapshot element */
2074 ret
= mi_lttng_writer_close_element(writer
);
2081 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
2082 const char *current_session_name
, const char *n_ptr
,
2083 struct lttng_snapshot_output
*output
)
2087 /* Open element snapshot */
2088 ret
= mi_lttng_writer_open_element(writer
,
2089 mi_lttng_element_command_snapshot
);
2094 /* Snapshot output id */
2095 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2096 mi_lttng_element_id
, output
->id
);
2101 /* Snapshot output names */
2102 ret
= mi_lttng_writer_write_element_string(writer
,
2103 config_element_name
, n_ptr
);
2108 /* Destination of the output (ctrl_url)*/
2109 ret
= mi_lttng_writer_write_element_string(writer
,
2110 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2115 /* Snapshot added for session "current_session_name"*/
2116 ret
= mi_lttng_writer_write_element_string(writer
,
2117 mi_lttng_element_snapshot_session_name
, current_session_name
);
2122 /* total size of all stream combined */
2123 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2124 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2129 /* Close snapshot element */
2130 ret
= mi_lttng_writer_close_element(writer
);
2137 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
2138 const char *current_session_name
, const char *url
,
2139 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
2143 /* Open element snapshot */
2144 ret
= mi_lttng_writer_open_element(writer
,
2145 mi_lttng_element_command_snapshot
);
2151 * If a valid an URL was given, serialize it,
2152 * else take the command line data and ctrl urls*/
2154 /* Destination of the output (ctrl_url)*/
2155 ret
= mi_lttng_writer_write_element_string(writer
,
2156 mi_lttng_element_snapshot_ctrl_url
, url
);
2160 } else if (cmdline_ctrl_url
) {
2161 /* Destination of the output (ctrl_url)*/
2162 ret
= mi_lttng_writer_write_element_string(writer
,
2163 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
2168 /* Destination of the output (data_url) */
2169 ret
= mi_lttng_writer_write_element_string(writer
,
2170 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
2176 /* Close record_snapshot element */
2177 ret
= mi_lttng_writer_close_element(writer
);
2184 int mi_lttng_rotation_schedule(struct mi_writer
*writer
,
2185 const struct lttng_rotation_schedule
*schedule
)
2188 enum lttng_rotation_status status
;
2190 const char *element_name
;
2191 const char *value_name
;
2192 bool empty_schedule
= false;
2194 switch (lttng_rotation_schedule_get_type(schedule
)) {
2195 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2196 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
2198 element_name
= mi_lttng_element_rotation_schedule_periodic
;
2199 value_name
= mi_lttng_element_rotation_schedule_periodic_time_us
;
2201 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2202 status
= lttng_rotation_schedule_size_threshold_get_threshold(
2204 element_name
= mi_lttng_element_rotation_schedule_size_threshold
;
2205 value_name
= mi_lttng_element_rotation_schedule_size_threshold_bytes
;
2212 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2213 if (status
== LTTNG_ROTATION_STATUS_UNAVAILABLE
) {
2214 empty_schedule
= true;
2221 ret
= mi_lttng_writer_open_element(writer
, element_name
);
2226 if (!empty_schedule
) {
2227 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2234 /* Close schedule descriptor element. */
2235 ret
= mi_lttng_writer_close_element(writer
);
2244 int mi_lttng_rotation_schedule_result(struct mi_writer
*writer
,
2245 const struct lttng_rotation_schedule
*schedule
,
2250 ret
= mi_lttng_writer_open_element(writer
,
2251 mi_lttng_element_rotation_schedule_result
);
2256 ret
= mi_lttng_writer_open_element(writer
,
2257 mi_lttng_element_rotation_schedule
);
2262 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
2267 /* Close rotation_schedule element */
2268 ret
= mi_lttng_writer_close_element(writer
);
2273 ret
= mi_lttng_writer_write_element_bool(writer
,
2274 mi_lttng_element_command_success
, success
);
2279 /* Close rotation_schedule_result element */
2280 ret
= mi_lttng_writer_close_element(writer
);
2289 int mi_lttng_location(struct mi_writer
*writer
,
2290 const struct lttng_trace_archive_location
*location
)
2293 enum lttng_trace_archive_location_type location_type
;
2294 enum lttng_trace_archive_location_status status
;
2296 location_type
= lttng_trace_archive_location_get_type(location
);
2298 switch (location_type
) {
2299 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
:
2301 const char *absolute_path
;
2303 status
= lttng_trace_archive_location_local_get_absolute_path(
2304 location
, &absolute_path
);
2305 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2310 ret
= mi_lttng_writer_open_element(writer
,
2311 mi_lttng_element_rotation_location_local
);
2317 ret
= mi_lttng_writer_write_element_string(writer
,
2318 mi_lttng_element_rotation_location_local_absolute_path
,
2324 /* Close local element */
2325 ret
= mi_lttng_writer_close_element(writer
);
2331 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
:
2333 uint16_t control_port
, data_port
;
2334 const char *host
, *relative_path
;
2335 enum lttng_trace_archive_location_relay_protocol_type protocol
;
2337 /* Fetch all relay location parameters. */
2338 status
= lttng_trace_archive_location_relay_get_protocol_type(
2339 location
, &protocol
);
2340 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2345 status
= lttng_trace_archive_location_relay_get_host(
2347 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2352 status
= lttng_trace_archive_location_relay_get_control_port(
2353 location
, &control_port
);
2354 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2359 status
= lttng_trace_archive_location_relay_get_data_port(
2360 location
, &data_port
);
2361 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2366 status
= lttng_trace_archive_location_relay_get_relative_path(
2367 location
, &relative_path
);
2368 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2373 ret
= mi_lttng_writer_open_element(writer
,
2374 mi_lttng_element_rotation_location_relay
);
2379 ret
= mi_lttng_writer_write_element_string(writer
,
2380 mi_lttng_element_rotation_location_relay_host
,
2386 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2387 mi_lttng_element_rotation_location_relay_control_port
,
2393 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2394 mi_lttng_element_rotation_location_relay_data_port
,
2400 ret
= mi_lttng_writer_write_element_string(writer
,
2401 mi_lttng_element_rotation_location_relay_protocol
,
2402 mi_lttng_trace_archive_location_relay_protocol_type_string(protocol
));
2407 ret
= mi_lttng_writer_write_element_string(writer
,
2408 mi_lttng_element_rotation_location_relay_relative_path
,
2414 /* Close relay element */
2415 ret
= mi_lttng_writer_close_element(writer
);
2429 int mi_lttng_rotate(struct mi_writer
*writer
,
2430 const char *session_name
,
2431 enum lttng_rotation_state rotation_state
,
2432 const struct lttng_trace_archive_location
*location
)
2436 ret
= mi_lttng_writer_open_element(writer
,
2437 mi_lttng_element_rotation
);
2442 ret
= mi_lttng_writer_write_element_string(writer
,
2443 mi_lttng_element_session_name
,
2449 ret
= mi_lttng_writer_write_element_string(writer
,
2450 mi_lttng_element_rotation_state
,
2451 mi_lttng_rotation_state_string(rotation_state
));
2457 /* Not a serialization error. */
2458 goto close_rotation
;
2461 ret
= mi_lttng_writer_open_element(writer
,
2462 mi_lttng_element_rotation_location
);
2467 ret
= mi_lttng_location(writer
, location
);
2469 goto close_location
;
2473 /* Close location element */
2474 ret
= mi_lttng_writer_close_element(writer
);
2480 /* Close rotation element */
2481 ret
= mi_lttng_writer_close_element(writer
);