2 * Copyright (C) 2014 EfficiOS Inc.
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: LGPL-2.1-only
9 #include "lttng/tracker.h"
11 #include "mi-lttng.hpp"
13 #include <common/config/session-config.hpp>
14 #include <common/defaults.hpp>
15 #include <common/tracker.hpp>
17 #include <lttng/channel.h>
18 #include <lttng/snapshot-internal.hpp>
20 #define MI_SCHEMA_MAJOR_VERSION 4
21 #define MI_SCHEMA_MINOR_VERSION 1
23 /* Machine interface namespace URI */
24 const char *const mi_lttng_xmlns
= "xmlns";
25 const char *const mi_lttng_xmlns_xsi
= "xmlns:xsi";
26 const char *const mi_lttng_w3_schema_uri
= "http://www.w3.org/2001/XMLSchema-instance";
27 const char *const mi_lttng_schema_location
= "xsi:schemaLocation";
28 const char *const mi_lttng_schema_location_uri
= DEFAULT_LTTNG_MI_NAMESPACE
30 "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION
) "/lttng-mi-" XSTR(
31 MI_SCHEMA_MAJOR_VERSION
) "." XSTR(MI_SCHEMA_MINOR_VERSION
) ".xsd";
32 const char *const mi_lttng_schema_version
= "schemaVersion";
33 const char *const mi_lttng_schema_version_value
=
34 XSTR(MI_SCHEMA_MAJOR_VERSION
) "." XSTR(MI_SCHEMA_MINOR_VERSION
);
36 /* Strings related to command */
37 const char *const mi_lttng_element_command
= "command";
38 const char *const mi_lttng_element_command_action
= "snapshot_action";
39 const char *const mi_lttng_element_command_add_context
= "add-context";
40 const char *const mi_lttng_element_command_add_trigger
= "add-trigger";
41 const char *const mi_lttng_element_command_create
= "create";
42 const char *const mi_lttng_element_command_destroy
= "destroy";
43 const char *const mi_lttng_element_command_disable_channel
= "disable-channel";
44 const char *const mi_lttng_element_command_disable_event
= "disable-event";
45 const char *const mi_lttng_element_command_enable_channels
= "enable-channel";
46 const char *const mi_lttng_element_command_enable_event
= "enable-event";
47 const char *const mi_lttng_element_command_list
= "list";
48 const char *const mi_lttng_element_command_list_trigger
= "list-trigger";
49 const char *const mi_lttng_element_command_load
= "load";
50 const char *const mi_lttng_element_command_metadata
= "metadata";
51 const char *const mi_lttng_element_command_metadata_action
= "metadata_action";
52 const char *const mi_lttng_element_command_regenerate
= "regenerate";
53 const char *const mi_lttng_element_command_regenerate_action
= "regenerate_action";
54 const char *const mi_lttng_element_command_name
= "name";
55 const char *const mi_lttng_element_command_output
= "output";
56 const char *const mi_lttng_element_command_remove_trigger
= "remove-trigger";
57 const char *const mi_lttng_element_command_save
= "save";
58 const char *const mi_lttng_element_command_set_session
= "set-session";
59 const char *const mi_lttng_element_command_snapshot
= "snapshot";
60 const char *const mi_lttng_element_command_snapshot_add
= "add_snapshot";
61 const char *const mi_lttng_element_command_snapshot_del
= "del_snapshot";
62 const char *const mi_lttng_element_command_snapshot_list
= "list_snapshot";
63 const char *const mi_lttng_element_command_snapshot_record
= "record_snapshot";
64 const char *const mi_lttng_element_command_start
= "start";
65 const char *const mi_lttng_element_command_stop
= "stop";
66 const char *const mi_lttng_element_command_success
= "success";
67 const char *const mi_lttng_element_command_track
= "track";
68 const char *const mi_lttng_element_command_untrack
= "untrack";
69 const char *const mi_lttng_element_command_version
= "version";
70 const char *const mi_lttng_element_command_rotate
= "rotate";
71 const char *const mi_lttng_element_command_enable_rotation
= "enable-rotation";
72 const char *const mi_lttng_element_command_disable_rotation
= "disable-rotation";
73 const char *const mi_lttng_element_command_clear
= "clear";
75 /* Strings related to version command */
76 const char *const mi_lttng_element_version
= "version";
77 const char *const mi_lttng_element_version_commit
= "commit";
78 const char *const mi_lttng_element_version_description
= "description";
79 const char *const mi_lttng_element_version_license
= "license";
80 const char *const mi_lttng_element_version_major
= "major";
81 const char *const mi_lttng_element_version_minor
= "minor";
82 const char *const mi_lttng_element_version_patch_level
= "patchLevel";
83 const char *const mi_lttng_element_version_str
= "string";
84 const char *const mi_lttng_element_version_web
= "url";
86 /* String related to a lttng_event_field */
87 const char *const mi_lttng_element_event_field
= "event_field";
88 const char *const mi_lttng_element_event_fields
= "event_fields";
90 /* String related to lttng_event_perf_counter_ctx */
91 const char *const mi_lttng_element_perf_counter_context
= "perf";
93 /* Strings related to pid */
94 const char *const mi_lttng_element_pid_id
= "id";
96 /* Strings related to save command */
97 const char *const mi_lttng_element_save
= "save";
99 /* Strings related to load command */
100 const char *const mi_lttng_element_load
= "load";
101 const char *const mi_lttng_element_load_overrides
= "overrides";
102 const char *const mi_lttng_element_load_override_url
= "url";
104 /* General elements of mi_lttng */
105 const char *const mi_lttng_element_empty
= "";
106 const char *const mi_lttng_element_id
= "id";
107 const char *const mi_lttng_element_nowrite
= "nowrite";
108 const char *const mi_lttng_element_success
= "success";
109 const char *const mi_lttng_element_type_enum
= "ENUM";
110 const char *const mi_lttng_element_type_float
= "FLOAT";
111 const char *const mi_lttng_element_type_integer
= "INTEGER";
112 const char *const mi_lttng_element_type_other
= "OTHER";
113 const char *const mi_lttng_element_type_string
= "STRING";
115 /* String related to loglevel */
116 const char *const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
117 const char *const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
118 const char *const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
119 const char *const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
120 const char *const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
121 const char *const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
122 const char *const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
123 const char *const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
124 const char *const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
125 const char *const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
126 const char *const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
127 const char *const mi_lttng_loglevel_str_err
= "TRACE_ERR";
128 const char *const mi_lttng_loglevel_str_info
= "TRACE_INFO";
129 const char *const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
130 const char *const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
131 const char *const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
133 /* String related to loglevel JUL */
134 const char *const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
135 const char *const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
136 const char *const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
137 const char *const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
138 const char *const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
139 const char *const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
140 const char *const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
141 const char *const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
142 const char *const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
144 /* String related to loglevel LOG4J */
145 const char *const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
146 const char *const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
147 const char *const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
148 const char *const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
149 const char *const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
150 const char *const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
151 const char *const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
152 const char *const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
154 /* String related to loglevel Python */
155 const char *const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
156 const char *const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
157 const char *const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
158 const char *const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
159 const char *const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
160 const char *const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
162 /* String related to loglevel type */
163 const char *const mi_lttng_loglevel_type_all
= "ALL";
164 const char *const mi_lttng_loglevel_type_range
= "RANGE";
165 const char *const mi_lttng_loglevel_type_single
= "SINGLE";
166 const char *const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
168 /* String related to a lttng_snapshot_output */
169 const char *const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
170 const char *const mi_lttng_element_snapshot_data_url
= "data_url";
171 const char *const mi_lttng_element_snapshot_max_size
= "max_size";
172 const char *const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
173 const char *const mi_lttng_element_snapshot_session_name
= "session_name";
174 const char *const mi_lttng_element_snapshots
= "snapshots";
176 /* String related to track/untrack command */
177 const char *const mi_lttng_element_track_untrack_all_wildcard
= "*";
179 const char *const mi_lttng_element_session_name
= "session_name";
181 /* String related to rotate command */
182 const char *const mi_lttng_element_rotation
= "rotation";
183 const char *const mi_lttng_element_rotate_status
= "status";
184 const char *const mi_lttng_element_rotation_schedule
= "rotation_schedule";
185 const char *const mi_lttng_element_rotation_schedules
= "rotation_schedules";
186 const char *const mi_lttng_element_rotation_schedule_result
= "rotation_schedule_result";
187 const char *const mi_lttng_element_rotation_schedule_results
= "rotation_schedule_results";
188 const char *const mi_lttng_element_rotation_schedule_periodic
= "periodic";
189 const char *const mi_lttng_element_rotation_schedule_periodic_time_us
= "time_us";
190 const char *const mi_lttng_element_rotation_schedule_size_threshold
= "size_threshold";
191 const char *const mi_lttng_element_rotation_schedule_size_threshold_bytes
= "bytes";
192 const char *const mi_lttng_element_rotation_state
= "state";
193 const char *const mi_lttng_element_rotation_location
= "location";
194 const char *const mi_lttng_element_rotation_location_local
= "local";
195 const char *const mi_lttng_element_rotation_location_local_absolute_path
= "absolute_path";
196 const char *const mi_lttng_element_rotation_location_relay
= "relay";
197 const char *const mi_lttng_element_rotation_location_relay_host
= "host";
198 const char *const mi_lttng_element_rotation_location_relay_control_port
= "control_port";
199 const char *const mi_lttng_element_rotation_location_relay_data_port
= "data_port";
200 const char *const mi_lttng_element_rotation_location_relay_protocol
= "protocol";
201 const char *const mi_lttng_element_rotation_location_relay_relative_path
= "relative_path";
203 /* String related to enum lttng_rotation_state */
204 const char *const mi_lttng_rotation_state_str_ongoing
= "ONGOING";
205 const char *const mi_lttng_rotation_state_str_completed
= "COMPLETED";
206 const char *const mi_lttng_rotation_state_str_expired
= "EXPIRED";
207 const char *const mi_lttng_rotation_state_str_error
= "ERROR";
209 /* String related to enum lttng_trace_archive_location_relay_protocol_type */
210 const char *const mi_lttng_rotation_location_relay_protocol_str_tcp
= "TCP";
212 /* String related to rate_policy elements */
213 const char *const mi_lttng_element_rate_policy
= "rate_policy";
214 const char *const mi_lttng_element_rate_policy_every_n
= "rate_policy_every_n";
215 const char *const mi_lttng_element_rate_policy_once_after_n
= "rate_policy_once_after_n";
217 const char *const mi_lttng_element_rate_policy_every_n_interval
= "interval";
218 const char *const mi_lttng_element_rate_policy_once_after_n_threshold
= "threshold";
220 /* String related to action elements */
221 const char *const mi_lttng_element_action
= "action";
222 const char *const mi_lttng_element_action_list
= "action_list";
223 const char *const mi_lttng_element_action_notify
= "action_notify";
224 const char *const mi_lttng_element_action_start_session
= "action_start_session";
225 const char *const mi_lttng_element_action_stop_session
= "action_stop_session";
226 const char *const mi_lttng_element_action_rotate_session
= "action_rotate_session";
227 const char *const mi_lttng_element_action_snapshot_session
= "action_snapshot_session";
228 const char *const mi_lttng_element_action_snapshot_session_output
= "output";
230 /* String related to condition */
231 const char *const mi_lttng_element_condition
= "condition";
232 const char *const mi_lttng_element_condition_buffer_usage_high
= "condition_buffer_usage_high";
233 const char *const mi_lttng_element_condition_buffer_usage_low
= "condition_buffer_usage_low";
234 const char *const mi_lttng_element_condition_event_rule_matches
= "condition_event_rule_matches";
235 const char *const mi_lttng_element_condition_session_consumed_size
=
236 "condition_session_consumed_size";
237 const char *const mi_lttng_element_condition_session_rotation
= "condition_session_rotation";
238 const char *const mi_lttng_element_condition_session_rotation_completed
=
239 "condition_session_rotation_completed";
240 const char *const mi_lttng_element_condition_session_rotation_ongoing
=
241 "condition_session_rotation_ongoing";
243 const char *const mi_lttng_element_condition_channel_name
= "channel_name";
244 const char *const mi_lttng_element_condition_threshold_bytes
= "threshold_bytes";
245 const char *const mi_lttng_element_condition_threshold_ratio
= "threshold_ratio";
247 /* String related to capture descriptor */
248 const char *const mi_lttng_element_capture_descriptor
= "capture_descriptor";
249 const char *const mi_lttng_element_capture_descriptors
= "capture_descriptors";
251 /* String related to event expression */
252 const char *const mi_lttng_element_event_expr
= "event_expr";
253 const char *const mi_lttng_element_event_expr_payload_field
= "event_expr_payload_field";
254 const char *const mi_lttng_element_event_expr_channel_context_field
=
255 "event_expr_channel_context_field";
256 const char *const mi_lttng_element_event_expr_app_specific_context_field
=
257 "event_expr_app_specific_context_field";
258 const char *const mi_lttng_element_event_expr_array_field_element
=
259 "event_expr_array_field_element";
260 const char *const mi_lttng_element_event_expr_provider_name
= "provider_name";
261 const char *const mi_lttng_element_event_expr_type_name
= "type_name";
262 const char *const mi_lttng_element_event_expr_index
= "index";
264 /* String related to event rule */
265 const char *const mi_lttng_element_event_rule
= "event_rule";
267 /* String related to lttng_event_rule_type */
268 const char *const mi_lttng_element_event_rule_event_name
= "event_name";
269 const char *const mi_lttng_element_event_rule_name_pattern
= "name_pattern";
270 const char *const mi_lttng_element_event_rule_filter_expression
= "filter_expression";
272 const char *const mi_lttng_element_event_rule_jul_logging
= "event_rule_jul_logging";
273 const char *const mi_lttng_element_event_rule_kernel_kprobe
= "event_rule_kernel_kprobe";
274 const char *const mi_lttng_element_event_rule_kernel_syscall
= "event_rule_kernel_syscall";
275 const char *const mi_lttng_element_event_rule_kernel_tracepoint
= "event_rule_kernel_tracepoint";
276 const char *const mi_lttng_element_event_rule_kernel_uprobe
= "event_rule_kernel_uprobe";
277 const char *const mi_lttng_element_event_rule_log4j_logging
= "event_rule_log4j_logging";
278 const char *const mi_lttng_element_event_rule_python_logging
= "event_rule_python_logging";
279 const char *const mi_lttng_element_event_rule_user_tracepoint
= "event_rule_user_tracepoint";
281 /* String related to lttng_event_rule_kernel_syscall. */
282 const char *const mi_lttng_element_event_rule_kernel_syscall_emission_site
= "emission_site";
284 /* String related to enum lttng_event_rule_kernel_syscall_emission_site. */
285 const char *const mi_lttng_event_rule_kernel_syscall_emission_site_entry_exit
= "entry+exit";
286 const char *const mi_lttng_event_rule_kernel_syscall_emission_site_entry
= "entry";
287 const char *const mi_lttng_event_rule_kernel_syscall_emission_site_exit
= "exit";
289 /* String related to lttng_event_rule_user_tracepoint */
290 const char *const mi_lttng_element_event_rule_user_tracepoint_name_pattern_exclusions
=
291 "name_pattern_exclusions";
292 const char *const mi_lttng_element_event_rule_user_tracepoint_name_pattern_exclusion
=
293 "name_pattern_exclusion";
295 /* String related to log level rule. */
296 const char *const mi_lttng_element_log_level_rule
= "log_level_rule";
297 const char *const mi_lttng_element_log_level_rule_exactly
= "log_level_rule_exactly";
298 const char *const mi_lttng_element_log_level_rule_at_least_as_severe_as
=
299 "log_level_rule_at_least_as_severe_as";
300 const char *const mi_lttng_element_log_level_rule_level
= "level";
302 /* String related to kernel probe location. */
303 const char *const mi_lttng_element_kernel_probe_location
= "kernel_probe_location";
304 const char *const mi_lttng_element_kernel_probe_location_symbol_offset
=
305 "kernel_probe_location_symbol_offset";
306 const char *const mi_lttng_element_kernel_probe_location_symbol_offset_name
= "name";
307 const char *const mi_lttng_element_kernel_probe_location_symbol_offset_offset
= "offset";
309 const char *const mi_lttng_element_kernel_probe_location_address
= "kernel_probe_location_address";
310 const char *const mi_lttng_element_kernel_probe_location_address_address
= "address";
312 /* String related to userspace probe location. */
313 const char *const mi_lttng_element_userspace_probe_location
= "userspace_probe_location";
314 const char *const mi_lttng_element_userspace_probe_location_binary_path
= "binary_path";
315 const char *const mi_lttng_element_userspace_probe_location_function
=
316 "userspace_probe_location_function";
317 const char *const mi_lttng_element_userspace_probe_location_function_name
= "name";
318 const char *const mi_lttng_element_userspace_probe_location_lookup_method
=
319 "userspace_probe_location_lookup_method";
320 const char *const mi_lttng_element_userspace_probe_location_lookup_method_function_default
=
321 "userspace_probe_location_lookup_method_function_default";
322 const char *const mi_lttng_element_userspace_probe_location_lookup_method_function_elf
=
323 "userspace_probe_location_lookup_method_function_elf";
324 const char *const mi_lttng_element_userspace_probe_location_lookup_method_tracepoint_sdt
=
325 "userspace_probe_location_lookup_method_tracepoint_sdt";
326 const char *const mi_lttng_element_userspace_probe_location_tracepoint
=
327 "userspace_probe_location_tracepoint";
328 const char *const mi_lttng_element_userspace_probe_location_tracepoint_probe_name
= "probe_name";
329 const char *const mi_lttng_element_userspace_probe_location_tracepoint_provider_name
=
332 /* String related to enum
333 * lttng_userspace_probe_location_function_instrumentation_type */
334 const char *const mi_lttng_element_userspace_probe_location_function_instrumentation_type
=
335 "instrumentation_type";
336 const char *const mi_lttng_userspace_probe_location_function_instrumentation_type_entry
= "ENTRY";
338 /* String related to trigger */
339 const char *const mi_lttng_element_triggers
= "triggers";
340 const char *const mi_lttng_element_trigger
= "trigger";
341 const char *const mi_lttng_element_trigger_owner_uid
= "owner_uid";
343 /* String related to error_query. */
344 const char *const mi_lttng_element_error_query_result
= "error_query_result";
345 const char *const mi_lttng_element_error_query_result_counter
= "error_query_result_counter";
346 const char *const mi_lttng_element_error_query_result_counter_value
= "value";
347 const char *const mi_lttng_element_error_query_result_description
= "description";
348 const char *const mi_lttng_element_error_query_result_name
= "name";
349 const char *const mi_lttng_element_error_query_result_type
= "type";
350 const char *const mi_lttng_element_error_query_results
= "error_query_results";
352 /* String related to add-context command */
353 const char *const mi_lttng_element_context_symbol
= "symbol";
355 /* Deprecated symbols preserved for ABI compatibility. */
356 LTTNG_EXPORT
const char *mi_lttng_context_type_perf_counter
;
357 LTTNG_EXPORT
const char *mi_lttng_context_type_perf_cpu_counter
;
358 LTTNG_EXPORT
const char *mi_lttng_context_type_perf_thread_counter
;
359 LTTNG_EXPORT
const char *mi_lttng_element_track_untrack_pid_target
;
360 LTTNG_EXPORT
const char *mi_lttng_element_track_untrack_targets
;
361 LTTNG_EXPORT
const char *mi_lttng_element_calibrate
;
362 LTTNG_EXPORT
const char *mi_lttng_element_calibrate_function
;
363 LTTNG_EXPORT
const char *mi_lttng_element_command_calibrate
;
365 /* This is a merge of jul loglevel and regular loglevel
366 * Those should never overlap by definition
367 * (see struct lttng_event loglevel)
369 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
372 case LTTNG_DOMAIN_KERNEL
:
373 case LTTNG_DOMAIN_UST
:
376 return mi_lttng_element_empty
;
377 case LTTNG_LOGLEVEL_EMERG
:
378 return mi_lttng_loglevel_str_emerg
;
379 case LTTNG_LOGLEVEL_ALERT
:
380 return mi_lttng_loglevel_str_alert
;
381 case LTTNG_LOGLEVEL_CRIT
:
382 return mi_lttng_loglevel_str_crit
;
383 case LTTNG_LOGLEVEL_ERR
:
384 return mi_lttng_loglevel_str_err
;
385 case LTTNG_LOGLEVEL_WARNING
:
386 return mi_lttng_loglevel_str_warning
;
387 case LTTNG_LOGLEVEL_NOTICE
:
388 return mi_lttng_loglevel_str_notice
;
389 case LTTNG_LOGLEVEL_INFO
:
390 return mi_lttng_loglevel_str_info
;
391 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
392 return mi_lttng_loglevel_str_debug_system
;
393 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
394 return mi_lttng_loglevel_str_debug_program
;
395 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
396 return mi_lttng_loglevel_str_debug_process
;
397 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
398 return mi_lttng_loglevel_str_debug_module
;
399 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
400 return mi_lttng_loglevel_str_debug_unit
;
401 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
402 return mi_lttng_loglevel_str_debug_function
;
403 case LTTNG_LOGLEVEL_DEBUG_LINE
:
404 return mi_lttng_loglevel_str_debug_line
;
405 case LTTNG_LOGLEVEL_DEBUG
:
406 return mi_lttng_loglevel_str_debug
;
408 return mi_lttng_loglevel_str_unknown
;
411 case LTTNG_DOMAIN_LOG4J
:
414 return mi_lttng_element_empty
;
415 case LTTNG_LOGLEVEL_LOG4J_OFF
:
416 return mi_lttng_loglevel_str_log4j_off
;
417 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
418 return mi_lttng_loglevel_str_log4j_fatal
;
419 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
420 return mi_lttng_loglevel_str_log4j_error
;
421 case LTTNG_LOGLEVEL_LOG4J_WARN
:
422 return mi_lttng_loglevel_str_log4j_warn
;
423 case LTTNG_LOGLEVEL_LOG4J_INFO
:
424 return mi_lttng_loglevel_str_log4j_info
;
425 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
426 return mi_lttng_loglevel_str_log4j_debug
;
427 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
428 return mi_lttng_loglevel_str_log4j_trace
;
429 case LTTNG_LOGLEVEL_LOG4J_ALL
:
430 return mi_lttng_loglevel_str_log4j_all
;
432 return mi_lttng_loglevel_str_unknown
;
435 case LTTNG_DOMAIN_JUL
:
438 return mi_lttng_element_empty
;
439 case LTTNG_LOGLEVEL_JUL_OFF
:
440 return mi_lttng_loglevel_str_jul_off
;
441 case LTTNG_LOGLEVEL_JUL_SEVERE
:
442 return mi_lttng_loglevel_str_jul_severe
;
443 case LTTNG_LOGLEVEL_JUL_WARNING
:
444 return mi_lttng_loglevel_str_jul_warning
;
445 case LTTNG_LOGLEVEL_JUL_INFO
:
446 return mi_lttng_loglevel_str_jul_info
;
447 case LTTNG_LOGLEVEL_JUL_CONFIG
:
448 return mi_lttng_loglevel_str_jul_config
;
449 case LTTNG_LOGLEVEL_JUL_FINE
:
450 return mi_lttng_loglevel_str_jul_fine
;
451 case LTTNG_LOGLEVEL_JUL_FINER
:
452 return mi_lttng_loglevel_str_jul_finer
;
453 case LTTNG_LOGLEVEL_JUL_FINEST
:
454 return mi_lttng_loglevel_str_jul_finest
;
455 case LTTNG_LOGLEVEL_JUL_ALL
:
456 return mi_lttng_loglevel_str_jul_all
;
458 return mi_lttng_loglevel_str_unknown
;
461 case LTTNG_DOMAIN_PYTHON
:
463 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
464 return mi_lttng_loglevel_str_python_critical
;
465 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
466 return mi_lttng_loglevel_str_python_error
;
467 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
468 return mi_lttng_loglevel_str_python_warning
;
469 case LTTNG_LOGLEVEL_PYTHON_INFO
:
470 return mi_lttng_loglevel_str_python_info
;
471 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
472 return mi_lttng_loglevel_str_python_debug
;
473 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
474 return mi_lttng_loglevel_str_python_notset
;
476 return mi_lttng_loglevel_str_unknown
;
480 return mi_lttng_loglevel_str_unknown
;
484 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
487 case LTTNG_EVENT_LOGLEVEL_ALL
:
488 return mi_lttng_loglevel_type_all
;
489 case LTTNG_EVENT_LOGLEVEL_RANGE
:
490 return mi_lttng_loglevel_type_range
;
491 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
492 return mi_lttng_loglevel_type_single
;
494 return mi_lttng_loglevel_type_unknown
;
498 static const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
501 case LTTNG_EVENT_ALL
:
502 return config_event_type_all
;
503 case LTTNG_EVENT_TRACEPOINT
:
504 return config_event_type_tracepoint
;
505 case LTTNG_EVENT_PROBE
:
506 return config_event_type_probe
;
507 case LTTNG_EVENT_USERSPACE_PROBE
:
508 return config_event_type_userspace_probe
;
509 case LTTNG_EVENT_FUNCTION
:
510 return config_event_type_function
;
511 case LTTNG_EVENT_FUNCTION_ENTRY
:
512 return config_event_type_function_entry
;
513 case LTTNG_EVENT_SYSCALL
:
514 return config_event_type_syscall
;
515 case LTTNG_EVENT_NOOP
:
516 return config_event_type_noop
;
518 return mi_lttng_element_empty
;
522 static const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
525 case LTTNG_EVENT_CONTEXT_PID
:
526 return config_event_context_pid
;
527 case LTTNG_EVENT_CONTEXT_PROCNAME
:
528 return config_event_context_procname
;
529 case LTTNG_EVENT_CONTEXT_PRIO
:
530 return config_event_context_prio
;
531 case LTTNG_EVENT_CONTEXT_NICE
:
532 return config_event_context_nice
;
533 case LTTNG_EVENT_CONTEXT_VPID
:
534 return config_event_context_vpid
;
535 case LTTNG_EVENT_CONTEXT_TID
:
536 return config_event_context_tid
;
537 case LTTNG_EVENT_CONTEXT_VTID
:
538 return config_event_context_vtid
;
539 case LTTNG_EVENT_CONTEXT_PPID
:
540 return config_event_context_ppid
;
541 case LTTNG_EVENT_CONTEXT_VPPID
:
542 return config_event_context_vppid
;
543 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
544 return config_event_context_pthread_id
;
545 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
546 return config_event_context_hostname
;
547 case LTTNG_EVENT_CONTEXT_IP
:
548 return config_event_context_ip
;
549 case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
:
550 return config_event_context_interruptible
;
551 case LTTNG_EVENT_CONTEXT_PREEMPTIBLE
:
552 return config_event_context_preemptible
;
553 case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
:
554 return config_event_context_need_reschedule
;
555 case LTTNG_EVENT_CONTEXT_MIGRATABLE
:
556 return config_event_context_migratable
;
557 case LTTNG_EVENT_CONTEXT_CALLSTACK_USER
:
558 return config_event_context_callstack_user
;
559 case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
:
560 return config_event_context_callstack_kernel
;
561 case LTTNG_EVENT_CONTEXT_CGROUP_NS
:
562 return config_event_context_cgroup_ns
;
563 case LTTNG_EVENT_CONTEXT_IPC_NS
:
564 return config_event_context_ipc_ns
;
565 case LTTNG_EVENT_CONTEXT_MNT_NS
:
566 return config_event_context_mnt_ns
;
567 case LTTNG_EVENT_CONTEXT_NET_NS
:
568 return config_event_context_net_ns
;
569 case LTTNG_EVENT_CONTEXT_PID_NS
:
570 return config_event_context_pid_ns
;
571 case LTTNG_EVENT_CONTEXT_TIME_NS
:
572 return config_event_context_time_ns
;
573 case LTTNG_EVENT_CONTEXT_USER_NS
:
574 return config_event_context_user_ns
;
575 case LTTNG_EVENT_CONTEXT_UTS_NS
:
576 return config_event_context_uts_ns
;
577 case LTTNG_EVENT_CONTEXT_UID
:
578 return config_event_context_uid
;
579 case LTTNG_EVENT_CONTEXT_EUID
:
580 return config_event_context_euid
;
581 case LTTNG_EVENT_CONTEXT_SUID
:
582 return config_event_context_suid
;
583 case LTTNG_EVENT_CONTEXT_GID
:
584 return config_event_context_gid
;
585 case LTTNG_EVENT_CONTEXT_EGID
:
586 return config_event_context_egid
;
587 case LTTNG_EVENT_CONTEXT_SGID
:
588 return config_event_context_sgid
;
589 case LTTNG_EVENT_CONTEXT_VUID
:
590 return config_event_context_vuid
;
591 case LTTNG_EVENT_CONTEXT_VEUID
:
592 return config_event_context_veuid
;
593 case LTTNG_EVENT_CONTEXT_VSUID
:
594 return config_event_context_vsuid
;
595 case LTTNG_EVENT_CONTEXT_VGID
:
596 return config_event_context_vgid
;
597 case LTTNG_EVENT_CONTEXT_VEGID
:
598 return config_event_context_vegid
;
599 case LTTNG_EVENT_CONTEXT_VSGID
:
600 return config_event_context_vsgid
;
606 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
609 case (LTTNG_EVENT_FIELD_INTEGER
):
610 return mi_lttng_element_type_integer
;
611 case (LTTNG_EVENT_FIELD_ENUM
):
612 return mi_lttng_element_type_enum
;
613 case (LTTNG_EVENT_FIELD_FLOAT
):
614 return mi_lttng_element_type_float
;
615 case (LTTNG_EVENT_FIELD_STRING
):
616 return mi_lttng_element_type_string
;
618 return mi_lttng_element_type_other
;
622 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
625 case LTTNG_DOMAIN_KERNEL
:
626 return config_domain_type_kernel
;
627 case LTTNG_DOMAIN_UST
:
628 return config_domain_type_ust
;
629 case LTTNG_DOMAIN_JUL
:
630 return config_domain_type_jul
;
631 case LTTNG_DOMAIN_LOG4J
:
632 return config_domain_type_log4j
;
633 case LTTNG_DOMAIN_PYTHON
:
634 return config_domain_type_python
;
636 /* Should not have an unknown domain */
642 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
645 case LTTNG_BUFFER_PER_PID
:
646 return config_buffer_type_per_pid
;
647 case LTTNG_BUFFER_PER_UID
:
648 return config_buffer_type_per_uid
;
649 case LTTNG_BUFFER_GLOBAL
:
650 return config_buffer_type_global
;
652 /* Should not have an unknow buffer type */
658 const char *mi_lttng_rotation_state_string(enum lttng_rotation_state value
)
661 case LTTNG_ROTATION_STATE_ONGOING
:
662 return mi_lttng_rotation_state_str_ongoing
;
663 case LTTNG_ROTATION_STATE_COMPLETED
:
664 return mi_lttng_rotation_state_str_completed
;
665 case LTTNG_ROTATION_STATE_EXPIRED
:
666 return mi_lttng_rotation_state_str_expired
;
667 case LTTNG_ROTATION_STATE_ERROR
:
668 return mi_lttng_rotation_state_str_error
;
670 /* Should not have an unknow rotation state. */
676 const char *mi_lttng_trace_archive_location_relay_protocol_type_string(
677 enum lttng_trace_archive_location_relay_protocol_type value
)
680 case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP
:
681 return mi_lttng_rotation_location_relay_protocol_str_tcp
;
683 /* Should not have an unknown relay protocol. */
689 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
691 struct mi_writer
*mi_writer
;
693 mi_writer
= zmalloc
<struct mi_writer
>();
695 PERROR("zmalloc mi_writer_create");
698 if (mi_output_type
== LTTNG_MI_XML
) {
699 mi_writer
->writer
= config_writer_create(fd_output
, 0);
700 if (!mi_writer
->writer
) {
703 mi_writer
->type
= LTTNG_MI_XML
;
716 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
725 ret
= config_writer_destroy(writer
->writer
);
735 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
740 * A command is always the MI's root node, it must declare the current
741 * namespace and schema URIs and the schema's version.
743 ret
= config_writer_open_element(writer
->writer
, mi_lttng_element_command
);
748 ret
= config_writer_write_attribute(
749 writer
->writer
, mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
754 ret
= config_writer_write_attribute(
755 writer
->writer
, mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
760 ret
= config_writer_write_attribute(
761 writer
->writer
, mi_lttng_schema_location
, mi_lttng_schema_location_uri
);
766 ret
= config_writer_write_attribute(
767 writer
->writer
, mi_lttng_schema_version
, mi_lttng_schema_version_value
);
772 ret
= mi_lttng_writer_write_element_string(writer
, mi_lttng_element_command_name
, command
);
777 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
779 return mi_lttng_writer_close_element(writer
);
782 int mi_lttng_writer_open_element(struct mi_writer
*writer
, const char *element_name
)
784 return config_writer_open_element(writer
->writer
, element_name
);
787 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
789 return config_writer_close_element(writer
->writer
);
792 int mi_lttng_close_multi_element(struct mi_writer
*writer
, unsigned int nb_element
)
796 if (nb_element
< 1) {
800 for (i
= 0; i
< nb_element
; i
++) {
801 ret
= mi_lttng_writer_close_element(writer
);
810 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
811 const char *element_name
,
814 return config_writer_write_element_unsigned_int(writer
->writer
, element_name
, value
);
817 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
818 const char *element_name
,
821 return config_writer_write_element_signed_int(writer
->writer
, element_name
, value
);
824 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
825 const char *element_name
,
828 return config_writer_write_element_bool(writer
->writer
, element_name
, value
);
831 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
832 const char *element_name
,
835 return config_writer_write_element_string(writer
->writer
, element_name
, value
);
838 int mi_lttng_writer_write_element_double(struct mi_writer
*writer
,
839 const char *element_name
,
842 return config_writer_write_element_double(writer
->writer
, element_name
, value
);
845 int mi_lttng_version(struct mi_writer
*writer
,
846 struct mi_lttng_version_data
*version
,
847 const char *lttng_description
,
848 const char *lttng_license
)
853 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
858 /* Version string (contain info like rc etc.) */
859 ret
= mi_lttng_writer_write_element_string(
860 writer
, mi_lttng_element_version_str
, version
->version
);
865 /* Major version number */
866 ret
= mi_lttng_writer_write_element_unsigned_int(
867 writer
, mi_lttng_element_version_major
, version
->version_major
);
872 /* Minor version number */
873 ret
= mi_lttng_writer_write_element_unsigned_int(
874 writer
, mi_lttng_element_version_minor
, version
->version_minor
);
879 /* Commit version number */
880 ret
= mi_lttng_writer_write_element_string(
881 writer
, mi_lttng_element_version_commit
, version
->version_commit
);
887 ret
= mi_lttng_writer_write_element_unsigned_int(
888 writer
, mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
893 /* Name of the version */
894 ret
= mi_lttng_writer_write_element_string(
895 writer
, config_element_name
, version
->version_name
);
900 /* Description mostly related to beer... */
901 ret
= mi_lttng_writer_write_element_string(
902 writer
, mi_lttng_element_version_description
, lttng_description
);
908 ret
= mi_lttng_writer_write_element_string(
909 writer
, mi_lttng_element_version_web
, version
->package_url
);
914 /* License: free as in free beer...no...*speech* */
915 ret
= mi_lttng_writer_write_element_string(
916 writer
, mi_lttng_element_version_license
, lttng_license
);
921 /* Close version element */
922 ret
= mi_lttng_writer_close_element(writer
);
928 int mi_lttng_sessions_open(struct mi_writer
*writer
)
930 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
933 int mi_lttng_session(struct mi_writer
*writer
, const struct lttng_session
*session
, int is_open
)
937 LTTNG_ASSERT(session
);
939 /* Open sessions element */
940 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
945 /* Name of the session */
946 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, session
->name
);
952 ret
= mi_lttng_writer_write_element_string(writer
, config_element_path
, session
->path
);
958 ret
= mi_lttng_writer_write_element_bool(writer
, config_element_enabled
, session
->enabled
);
964 ret
= mi_lttng_writer_write_element_unsigned_int(
965 writer
, config_element_snapshot_mode
, session
->snapshot_mode
);
970 /* Live timer interval in usec */
971 ret
= mi_lttng_writer_write_element_unsigned_int(
972 writer
, config_element_live_timer_interval
, session
->live_timer_interval
);
978 /* Closing session element */
979 ret
= mi_lttng_writer_close_element(writer
);
985 int mi_lttng_domains_open(struct mi_writer
*writer
)
987 return mi_lttng_writer_open_element(writer
, config_element_domains
);
990 int mi_lttng_domain(struct mi_writer
*writer
, struct lttng_domain
*domain
, int is_open
)
993 const char *str_domain
;
994 const char *str_buffer
;
996 LTTNG_ASSERT(domain
);
998 /* Open domain element */
999 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
1005 str_domain
= mi_lttng_domaintype_string(domain
->type
);
1006 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
, str_domain
);
1012 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
1013 ret
= mi_lttng_writer_write_element_string(writer
, config_element_buffer_type
, str_buffer
);
1019 * This union is not currently used and was added for
1020 * future ust domain support.
1025 /* Closing domain element */
1026 ret
= mi_lttng_writer_close_element(writer
);
1033 int mi_lttng_channels_open(struct mi_writer
*writer
)
1035 return mi_lttng_writer_open_element(writer
, config_element_channels
);
1038 int mi_lttng_channel(struct mi_writer
*writer
, struct lttng_channel
*channel
, int is_open
)
1042 LTTNG_ASSERT(channel
);
1044 /* Opening channel element */
1045 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
1051 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, channel
->name
);
1057 ret
= mi_lttng_writer_write_element_bool(writer
, config_element_enabled
, channel
->enabled
);
1063 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
1069 /* Closing channel element */
1070 ret
= mi_lttng_writer_close_element(writer
);
1079 int mi_lttng_channel_attr(struct mi_writer
*writer
, struct lttng_channel_attr
*attr
)
1082 struct lttng_channel
*chan
= caa_container_of(attr
, struct lttng_channel
, attr
);
1083 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1084 int64_t blocking_timeout
;
1088 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
1093 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
1098 ret
= lttng_channel_get_monitor_timer_interval(chan
, &monitor_timer_interval
);
1103 ret
= lttng_channel_get_blocking_timeout(chan
, &blocking_timeout
);
1108 /* Opening Attributes */
1109 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1115 ret
= mi_lttng_writer_write_element_string(
1117 config_element_overwrite_mode
,
1118 attr
->overwrite
? config_overwrite_mode_overwrite
: config_overwrite_mode_discard
);
1123 /* Sub buffer size in byte */
1124 ret
= mi_lttng_writer_write_element_unsigned_int(
1125 writer
, config_element_subbuf_size
, attr
->subbuf_size
);
1130 /* Number of subbuffer (power of two) */
1131 ret
= mi_lttng_writer_write_element_unsigned_int(
1132 writer
, config_element_num_subbuf
, attr
->num_subbuf
);
1137 /* Switch timer interval in usec */
1138 ret
= mi_lttng_writer_write_element_unsigned_int(
1139 writer
, config_element_switch_timer_interval
, attr
->switch_timer_interval
);
1144 /* Read timer interval in usec */
1145 ret
= mi_lttng_writer_write_element_unsigned_int(
1146 writer
, config_element_read_timer_interval
, attr
->read_timer_interval
);
1151 /* Monitor timer interval in usec */
1152 ret
= mi_lttng_writer_write_element_unsigned_int(
1153 writer
, config_element_monitor_timer_interval
, monitor_timer_interval
);
1158 /* Retry timeout in usec */
1159 ret
= mi_lttng_writer_write_element_signed_int(
1160 writer
, config_element_blocking_timeout
, blocking_timeout
);
1166 ret
= mi_lttng_writer_write_element_string(writer
,
1167 config_element_output_type
,
1168 attr
->output
== LTTNG_EVENT_SPLICE
?
1169 config_output_type_splice
:
1170 config_output_type_mmap
);
1175 /* Tracefile size in bytes */
1176 ret
= mi_lttng_writer_write_element_unsigned_int(
1177 writer
, config_element_tracefile_size
, attr
->tracefile_size
);
1182 /* Count of tracefiles */
1183 ret
= mi_lttng_writer_write_element_unsigned_int(
1184 writer
, config_element_tracefile_count
, attr
->tracefile_count
);
1189 /* Live timer interval in usec*/
1190 ret
= mi_lttng_writer_write_element_unsigned_int(
1191 writer
, config_element_live_timer_interval
, attr
->live_timer_interval
);
1196 /* Discarded events */
1197 ret
= mi_lttng_writer_write_element_unsigned_int(
1198 writer
, config_element_discarded_events
, discarded_events
);
1204 ret
= mi_lttng_writer_write_element_unsigned_int(
1205 writer
, config_element_lost_packets
, lost_packets
);
1210 /* Closing attributes */
1211 ret
= mi_lttng_writer_close_element(writer
);
1219 int mi_lttng_event_common_attributes(struct mi_writer
*writer
, struct lttng_event
*event
)
1222 const char *filter_expression
;
1224 /* Open event element */
1225 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
1231 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, event
->name
);
1237 ret
= mi_lttng_writer_write_element_string(
1238 writer
, config_element_type
, mi_lttng_eventtype_string(event
->type
));
1243 /* Is event enabled */
1244 ret
= mi_lttng_writer_write_element_bool(writer
, config_element_enabled
, event
->enabled
);
1249 /* Event filter expression */
1250 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1255 if (filter_expression
) {
1256 ret
= mi_lttng_writer_write_element_string(
1257 writer
, config_element_filter_expression
, filter_expression
);
1267 static int write_event_exclusions(struct mi_writer
*writer
, struct lttng_event
*event
)
1271 int exclusion_count
;
1273 /* Open event exclusions */
1274 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1279 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1280 if (exclusion_count
< 0) {
1281 ret
= exclusion_count
;
1285 for (i
= 0; i
< exclusion_count
; i
++) {
1288 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1290 /* Close exclusions */
1291 mi_lttng_writer_close_element(writer
);
1295 ret
= mi_lttng_writer_write_element_string(writer
, config_element_exclusion
, name
);
1297 /* Close exclusions */
1298 mi_lttng_writer_close_element(writer
);
1303 /* Close exclusions */
1304 ret
= mi_lttng_writer_close_element(writer
);
1310 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1311 struct lttng_event
*event
,
1312 enum lttng_domain_type domain
)
1316 /* Event loglevel */
1317 ret
= mi_lttng_writer_write_element_string(
1318 writer
, config_element_loglevel
, mi_lttng_loglevel_string(event
->loglevel
, domain
));
1323 /* Log level type */
1324 ret
= mi_lttng_writer_write_element_string(
1326 config_element_loglevel_type
,
1327 mi_lttng_logleveltype_string(event
->loglevel_type
));
1332 /* Event exclusions */
1333 ret
= write_event_exclusions(writer
, event
);
1339 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
, struct lttng_event
*event
)
1341 /* event exclusion filter */
1342 return write_event_exclusions(writer
, event
);
1345 int mi_lttng_event_function_probe(struct mi_writer
*writer
, struct lttng_event
*event
)
1349 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1354 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1359 if (event
->attr
.probe
.addr
!= 0) {
1360 /* event probe address */
1361 ret
= mi_lttng_writer_write_element_unsigned_int(
1362 writer
, config_element_address
, event
->attr
.probe
.addr
);
1367 /* event probe offset */
1368 ret
= mi_lttng_writer_write_element_unsigned_int(
1369 writer
, config_element_offset
, event
->attr
.probe
.offset
);
1374 /* event probe symbol_name */
1375 ret
= mi_lttng_writer_write_element_string(
1376 writer
, config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1382 /* Close probe_attributes and attributes */
1383 ret
= mi_lttng_close_multi_element(writer
, 2);
1388 static int mi_lttng_event_userspace_probe(struct mi_writer
*writer
, struct lttng_event
*event
)
1391 const struct lttng_userspace_probe_location
*location
;
1392 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
1393 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
1395 location
= lttng_event_get_userspace_probe_location(event
);
1397 ret
= -LTTNG_ERR_INVALID
;
1401 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
1402 if (!lookup_method
) {
1403 ret
= -LTTNG_ERR_INVALID
;
1407 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
1409 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1414 switch (lttng_userspace_probe_location_get_type(location
)) {
1415 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1417 const char *function_name
;
1418 const char *binary_path
;
1420 ret
= mi_lttng_writer_open_element(
1421 writer
, config_element_userspace_probe_function_attributes
);
1426 switch (lookup_type
) {
1427 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
1428 ret
= mi_lttng_writer_write_element_string(
1430 config_element_userspace_probe_lookup
,
1431 config_element_userspace_probe_lookup_function_elf
);
1436 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
1437 ret
= mi_lttng_writer_write_element_string(
1439 config_element_userspace_probe_lookup
,
1440 config_element_userspace_probe_lookup_function_default
);
1449 binary_path
= lttng_userspace_probe_location_function_get_binary_path(location
);
1450 ret
= mi_lttng_writer_write_element_string(
1451 writer
, config_element_userspace_probe_location_binary_path
, binary_path
);
1456 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
1457 ret
= mi_lttng_writer_write_element_string(
1459 config_element_userspace_probe_function_location_function_name
,
1467 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1469 const char *probe_name
, *provider_name
;
1470 const char *binary_path
;
1472 ret
= mi_lttng_writer_open_element(
1473 writer
, config_element_userspace_probe_function_attributes
);
1478 switch (lookup_type
) {
1479 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
1480 ret
= mi_lttng_writer_write_element_string(
1482 config_element_userspace_probe_lookup
,
1483 config_element_userspace_probe_lookup_tracepoint_sdt
);
1492 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(location
);
1493 ret
= mi_lttng_writer_write_element_string(
1494 writer
, config_element_userspace_probe_location_binary_path
, binary_path
);
1500 lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
1501 ret
= mi_lttng_writer_write_element_string(
1503 config_element_userspace_probe_tracepoint_location_provider_name
,
1509 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
1510 ret
= mi_lttng_writer_write_element_string(
1512 config_element_userspace_probe_tracepoint_location_probe_name
,
1520 ERR("Invalid probe type encountered");
1522 /* Close probe_attributes and attributes */
1523 ret
= mi_lttng_close_multi_element(writer
, 2);
1528 int mi_lttng_event_function_entry(struct mi_writer
*writer
, struct lttng_event
*event
)
1532 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1537 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1542 /* event probe symbol_name */
1543 ret
= mi_lttng_writer_write_element_string(
1544 writer
, config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1549 /* Close function_attributes and attributes */
1550 ret
= mi_lttng_close_multi_element(writer
, 2);
1555 int mi_lttng_events_open(struct mi_writer
*writer
)
1557 return mi_lttng_writer_open_element(writer
, config_element_events
);
1560 int mi_lttng_event(struct mi_writer
*writer
,
1561 struct lttng_event
*event
,
1563 enum lttng_domain_type domain
)
1567 ret
= mi_lttng_event_common_attributes(writer
, event
);
1572 switch (event
->type
) {
1573 case LTTNG_EVENT_TRACEPOINT
:
1575 if (event
->loglevel
!= -1) {
1576 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1578 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1582 case LTTNG_EVENT_FUNCTION
:
1584 case LTTNG_EVENT_PROBE
:
1585 ret
= mi_lttng_event_function_probe(writer
, event
);
1587 case LTTNG_EVENT_FUNCTION_ENTRY
:
1588 ret
= mi_lttng_event_function_entry(writer
, event
);
1590 case LTTNG_EVENT_USERSPACE_PROBE
:
1591 ret
= mi_lttng_event_userspace_probe(writer
, event
);
1593 case LTTNG_EVENT_ALL
:
1604 ret
= mi_lttng_writer_close_element(writer
);
1611 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1613 return mi_lttng_writer_open_element(writer
, config_element_process_attr_trackers
);
1616 static int get_tracker_elements(enum lttng_process_attr process_attr
,
1617 const char **element_process_attr_tracker
,
1618 const char **element_process_attr_value
)
1622 switch (process_attr
) {
1623 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1624 *element_process_attr_tracker
= config_element_process_attr_tracker_pid
;
1625 *element_process_attr_value
= config_element_process_attr_pid_value
;
1627 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1628 *element_process_attr_tracker
= config_element_process_attr_tracker_vpid
;
1629 *element_process_attr_value
= config_element_process_attr_vpid_value
;
1631 case LTTNG_PROCESS_ATTR_USER_ID
:
1632 *element_process_attr_tracker
= config_element_process_attr_tracker_uid
;
1633 *element_process_attr_value
= config_element_process_attr_uid_value
;
1635 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1636 *element_process_attr_tracker
= config_element_process_attr_tracker_vuid
;
1637 *element_process_attr_value
= config_element_process_attr_vuid_value
;
1639 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1640 *element_process_attr_tracker
= config_element_process_attr_tracker_gid
;
1641 *element_process_attr_value
= config_element_process_attr_gid_value
;
1643 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1644 *element_process_attr_tracker
= config_element_process_attr_tracker_vgid
;
1645 *element_process_attr_value
= config_element_process_attr_vgid_value
;
1648 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1653 int mi_lttng_process_attribute_tracker_open(struct mi_writer
*writer
,
1654 enum lttng_process_attr process_attr
)
1657 const char *element_tracker
, *element_value
;
1659 ret
= get_tracker_elements(process_attr
, &element_tracker
, &element_value
);
1664 /* Open process attribute tracker element */
1665 ret
= mi_lttng_writer_open_element(writer
, element_tracker
);
1670 /* Open values element */
1671 ret
= mi_lttng_process_attr_values_open(writer
);
1676 int mi_lttng_pids_open(struct mi_writer
*writer
)
1678 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1682 * TODO: move the listing of pid for user agent to process semantic on
1683 * mi api bump. The use of process element break the mi api.
1685 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *name
, int is_open
)
1689 /* Open pid process */
1690 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1695 /* Writing pid number */
1696 ret
= mi_lttng_writer_write_element_signed_int(writer
, mi_lttng_element_pid_id
, (int) pid
);
1701 /* Writing name of the process */
1703 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, name
);
1711 ret
= mi_lttng_writer_close_element(writer
);
1718 int mi_lttng_process_attr_values_open(struct mi_writer
*writer
)
1720 return mi_lttng_writer_open_element(writer
, config_element_process_attr_values
);
1723 int mi_lttng_all_process_attribute_value(struct mi_writer
*writer
,
1724 enum lttng_process_attr process_attr
,
1728 const char *element_id_tracker
, *element_target_id
;
1730 ret
= get_tracker_elements(process_attr
, &element_id_tracker
, &element_target_id
);
1735 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1740 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1745 ret
= mi_lttng_writer_write_element_bool(writer
, config_element_all
, 1);
1750 ret
= mi_lttng_writer_close_element(writer
);
1756 ret
= mi_lttng_writer_close_element(writer
);
1765 int mi_lttng_integral_process_attribute_value(struct mi_writer
*writer
,
1766 enum lttng_process_attr process_attr
,
1771 const char *element_id_tracker
, *element_target_id
;
1773 ret
= get_tracker_elements(process_attr
, &element_id_tracker
, &element_target_id
);
1778 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1783 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1788 ret
= mi_lttng_writer_write_element_signed_int(
1789 writer
, config_element_process_attr_id
, value
);
1794 ret
= mi_lttng_writer_close_element(writer
);
1800 ret
= mi_lttng_writer_close_element(writer
);
1810 int mi_lttng_string_process_attribute_value(struct mi_writer
*writer
,
1811 enum lttng_process_attr process_attr
,
1817 const char *element_id_tracker
, *element_target_id
;
1819 ret
= get_tracker_elements(process_attr
, &element_id_tracker
, &element_target_id
);
1824 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1829 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1834 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, value
);
1839 ret
= mi_lttng_writer_close_element(writer
);
1845 ret
= mi_lttng_writer_close_element(writer
);
1855 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1857 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1860 int mi_lttng_event_field(struct mi_writer
*writer
, struct lttng_event_field
*field
)
1864 if (!field
->field_name
[0]) {
1870 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1875 if (!field
->field_name
[0]) {
1880 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, field
->field_name
);
1886 ret
= mi_lttng_writer_write_element_string(
1887 writer
, config_element_type
, mi_lttng_eventfieldtype_string(field
->type
));
1893 ret
= mi_lttng_writer_write_element_signed_int(
1894 writer
, mi_lttng_element_nowrite
, field
->nowrite
);
1900 /* Close field element */
1901 ret
= mi_lttng_writer_close_element(writer
);
1907 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1908 struct lttng_event_perf_counter_ctx
*perf_context
)
1912 /* Open perf_counter_context */
1913 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_perf_counter_context
);
1919 ret
= mi_lttng_writer_write_element_unsigned_int(
1920 writer
, config_element_type
, perf_context
->type
);
1926 ret
= mi_lttng_writer_write_element_unsigned_int(
1927 writer
, config_element_config
, perf_context
->config
);
1932 /* Name of the perf counter */
1933 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, perf_context
->name
);
1938 /* Close perf_counter_context */
1939 ret
= mi_lttng_writer_close_element(writer
);
1945 mi_lttng_app_context(struct mi_writer
*writer
, const char *provider_name
, const char *ctx_name
)
1950 ret
= mi_lttng_writer_open_element(writer
, config_element_context_app
);
1956 ret
= mi_lttng_writer_write_element_string(
1957 writer
, config_element_context_app_provider_name
, provider_name
);
1963 ret
= mi_lttng_writer_write_element_string(
1964 writer
, config_element_context_app_ctx_name
, ctx_name
);
1970 ret
= mi_lttng_writer_close_element(writer
);
1975 int mi_lttng_context(struct mi_writer
*writer
, struct lttng_event_context
*context
, int is_open
)
1980 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1985 /* Special case for PERF_*_COUNTER
1986 * print the lttng_event_perf_counter_ctx*/
1987 switch (context
->ctx
) {
1988 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1989 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1990 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1992 struct lttng_event_perf_counter_ctx
*perf_context
= &context
->u
.perf_counter
;
1993 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1999 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
2001 ret
= mi_lttng_app_context(
2002 writer
, context
->u
.app_ctx
.provider_name
, context
->u
.app_ctx
.ctx_name
);
2010 const char *type_string
= mi_lttng_event_contexttype_string(context
->ctx
);
2012 ret
= -LTTNG_ERR_INVALID
;
2016 /* Print context type */
2017 ret
= mi_lttng_writer_write_element_string(
2018 writer
, config_element_type
, type_string
);
2025 ret
= mi_lttng_writer_close_element(writer
);
2032 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
, const char *session_name
)
2036 /* Open session element */
2037 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
2042 /* Snapshot output list for current session name */
2043 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, session_name
);
2048 /* Open element snapshots (sequence one snapshot) */
2049 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
2058 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
2059 const struct lttng_snapshot_output
*output
)
2063 /* Open element snapshot output */
2064 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_command_snapshot
);
2069 /* ID of the snapshot output */
2070 ret
= mi_lttng_writer_write_element_unsigned_int(writer
, mi_lttng_element_id
, output
->id
);
2075 /* Name of the output */
2076 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, output
->name
);
2081 /* Destination of the output (ctrl_url)*/
2082 ret
= mi_lttng_writer_write_element_string(
2083 writer
, mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2088 /* Destination of the output (data_url) */
2089 ret
= mi_lttng_writer_write_element_string(
2090 writer
, mi_lttng_element_snapshot_data_url
, output
->data_url
);
2095 /* total size of all stream combined */
2096 ret
= mi_lttng_writer_write_element_unsigned_int(
2097 writer
, mi_lttng_element_snapshot_max_size
, output
->max_size
);
2102 /* Close snapshot output element */
2103 ret
= mi_lttng_writer_close_element(writer
);
2109 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
,
2112 const char *current_session_name
)
2116 /* Open element del_snapshot */
2117 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_command_snapshot
);
2122 if (id
!= UINT32_MAX
) {
2123 /* "Snapshot output "id" successfully deleted
2124 * for "current_session_name"
2125 * ID of the snapshot output
2127 ret
= mi_lttng_writer_write_element_unsigned_int(writer
, mi_lttng_element_id
, id
);
2132 /* "Snapshot output "name" successfully deleted
2133 * for session "current_session_name"
2134 * Name of the output
2136 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, name
);
2142 /* Snapshot was deleted for session "current_session_name"*/
2143 ret
= mi_lttng_writer_write_element_string(
2144 writer
, mi_lttng_element_snapshot_session_name
, current_session_name
);
2149 /* Close snapshot element */
2150 ret
= mi_lttng_writer_close_element(writer
);
2156 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
2157 const char *current_session_name
,
2159 struct lttng_snapshot_output
*output
)
2163 /* Open element snapshot */
2164 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_command_snapshot
);
2169 /* Snapshot output id */
2170 ret
= mi_lttng_writer_write_element_unsigned_int(writer
, mi_lttng_element_id
, output
->id
);
2175 /* Snapshot output names */
2176 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
, n_ptr
);
2181 /* Destination of the output (ctrl_url)*/
2182 ret
= mi_lttng_writer_write_element_string(
2183 writer
, mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2188 /* Snapshot added for session "current_session_name"*/
2189 ret
= mi_lttng_writer_write_element_string(
2190 writer
, mi_lttng_element_snapshot_session_name
, current_session_name
);
2195 /* total size of all stream combined */
2196 ret
= mi_lttng_writer_write_element_unsigned_int(
2197 writer
, mi_lttng_element_snapshot_max_size
, output
->max_size
);
2202 /* Close snapshot element */
2203 ret
= mi_lttng_writer_close_element(writer
);
2209 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
2211 const char *cmdline_ctrl_url
,
2212 const char *cmdline_data_url
)
2216 /* Open element snapshot */
2217 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_command_snapshot
);
2223 * If a valid an URL was given, serialize it,
2224 * else take the command line data and ctrl urls*/
2226 /* Destination of the output (ctrl_url)*/
2227 ret
= mi_lttng_writer_write_element_string(
2228 writer
, mi_lttng_element_snapshot_ctrl_url
, url
);
2232 } else if (cmdline_ctrl_url
) {
2233 /* Destination of the output (ctrl_url)*/
2234 ret
= mi_lttng_writer_write_element_string(
2235 writer
, mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
2240 /* Destination of the output (data_url) */
2241 ret
= mi_lttng_writer_write_element_string(
2242 writer
, mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
2248 /* Close record_snapshot element */
2249 ret
= mi_lttng_writer_close_element(writer
);
2255 int mi_lttng_rotation_schedule(struct mi_writer
*writer
,
2256 const struct lttng_rotation_schedule
*schedule
)
2259 enum lttng_rotation_status status
;
2261 const char *element_name
;
2262 const char *value_name
;
2263 bool empty_schedule
= false;
2265 switch (lttng_rotation_schedule_get_type(schedule
)) {
2266 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2267 status
= lttng_rotation_schedule_periodic_get_period(schedule
, &value
);
2268 element_name
= mi_lttng_element_rotation_schedule_periodic
;
2269 value_name
= mi_lttng_element_rotation_schedule_periodic_time_us
;
2271 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2272 status
= lttng_rotation_schedule_size_threshold_get_threshold(schedule
, &value
);
2273 element_name
= mi_lttng_element_rotation_schedule_size_threshold
;
2274 value_name
= mi_lttng_element_rotation_schedule_size_threshold_bytes
;
2281 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2282 if (status
== LTTNG_ROTATION_STATUS_UNAVAILABLE
) {
2283 empty_schedule
= true;
2290 ret
= mi_lttng_writer_open_element(writer
, element_name
);
2295 if (!empty_schedule
) {
2296 ret
= mi_lttng_writer_write_element_unsigned_int(writer
, value_name
, value
);
2302 /* Close schedule descriptor element. */
2303 ret
= mi_lttng_writer_close_element(writer
);
2311 int mi_lttng_rotation_schedule_result(struct mi_writer
*writer
,
2312 const struct lttng_rotation_schedule
*schedule
,
2317 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_rotation_schedule_result
);
2322 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_rotation_schedule
);
2327 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
2332 /* Close rotation_schedule element */
2333 ret
= mi_lttng_writer_close_element(writer
);
2338 ret
= mi_lttng_writer_write_element_bool(writer
, mi_lttng_element_command_success
, success
);
2343 /* Close rotation_schedule_result element */
2344 ret
= mi_lttng_writer_close_element(writer
);
2352 static int mi_lttng_location(struct mi_writer
*writer
,
2353 const struct lttng_trace_archive_location
*location
)
2356 enum lttng_trace_archive_location_type location_type
;
2357 enum lttng_trace_archive_location_status status
;
2359 location_type
= lttng_trace_archive_location_get_type(location
);
2361 switch (location_type
) {
2362 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
:
2364 const char *absolute_path
;
2366 status
= lttng_trace_archive_location_local_get_absolute_path(location
,
2368 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2373 ret
= mi_lttng_writer_open_element(writer
,
2374 mi_lttng_element_rotation_location_local
);
2379 ret
= mi_lttng_writer_write_element_string(
2381 mi_lttng_element_rotation_location_local_absolute_path
,
2387 /* Close local element */
2388 ret
= mi_lttng_writer_close_element(writer
);
2394 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
:
2396 uint16_t control_port
, data_port
;
2397 const char *host
, *relative_path
;
2398 enum lttng_trace_archive_location_relay_protocol_type protocol
;
2400 /* Fetch all relay location parameters. */
2401 status
= lttng_trace_archive_location_relay_get_protocol_type(location
, &protocol
);
2402 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2407 status
= lttng_trace_archive_location_relay_get_host(location
, &host
);
2408 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2413 status
= lttng_trace_archive_location_relay_get_control_port(location
,
2415 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2420 status
= lttng_trace_archive_location_relay_get_data_port(location
, &data_port
);
2421 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2426 status
= lttng_trace_archive_location_relay_get_relative_path(location
,
2428 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2433 ret
= mi_lttng_writer_open_element(writer
,
2434 mi_lttng_element_rotation_location_relay
);
2439 ret
= mi_lttng_writer_write_element_string(
2440 writer
, mi_lttng_element_rotation_location_relay_host
, host
);
2445 ret
= mi_lttng_writer_write_element_unsigned_int(
2447 mi_lttng_element_rotation_location_relay_control_port
,
2453 ret
= mi_lttng_writer_write_element_unsigned_int(
2454 writer
, mi_lttng_element_rotation_location_relay_data_port
, data_port
);
2459 ret
= mi_lttng_writer_write_element_string(
2461 mi_lttng_element_rotation_location_relay_protocol
,
2462 mi_lttng_trace_archive_location_relay_protocol_type_string(protocol
));
2467 ret
= mi_lttng_writer_write_element_string(
2469 mi_lttng_element_rotation_location_relay_relative_path
,
2475 /* Close relay element */
2476 ret
= mi_lttng_writer_close_element(writer
);
2489 int mi_lttng_rotate(struct mi_writer
*writer
,
2490 const char *session_name
,
2491 enum lttng_rotation_state rotation_state
,
2492 const struct lttng_trace_archive_location
*location
)
2496 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_rotation
);
2501 ret
= mi_lttng_writer_write_element_string(
2502 writer
, mi_lttng_element_session_name
, session_name
);
2507 ret
= mi_lttng_writer_write_element_string(writer
,
2508 mi_lttng_element_rotation_state
,
2509 mi_lttng_rotation_state_string(rotation_state
));
2515 /* Not a serialization error. */
2516 goto close_rotation
;
2519 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_rotation_location
);
2524 ret
= mi_lttng_location(writer
, location
);
2526 goto close_location
;
2530 /* Close location element */
2531 ret
= mi_lttng_writer_close_element(writer
);
2537 /* Close rotation element */
2538 ret
= mi_lttng_writer_close_element(writer
);