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"
12 #include <common/config/session-config.h>
13 #include <common/defaults.h>
14 #include <common/tracker.h>
15 #include <lttng/channel.h>
16 #include <lttng/snapshot-internal.h>
19 #define MI_SCHEMA_MAJOR_VERSION 4
20 #define MI_SCHEMA_MINOR_VERSION 1
22 /* Machine interface namespace URI */
23 const char * const mi_lttng_xmlns
= "xmlns";
24 const char * const mi_lttng_xmlns_xsi
= "xmlns:xsi";
25 const char * const mi_lttng_w3_schema_uri
= "http://www.w3.org/2001/XMLSchema-instance";
26 const char * const mi_lttng_schema_location
= "xsi:schemaLocation";
27 const char * const mi_lttng_schema_location_uri
=
28 DEFAULT_LTTNG_MI_NAMESPACE
" "
29 "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION
)
30 "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION
) "."
31 XSTR(MI_SCHEMA_MINOR_VERSION
) ".xsd";
32 const char * const mi_lttng_schema_version
= "schemaVersion";
33 const char * const mi_lttng_schema_version_value
= XSTR(MI_SCHEMA_MAJOR_VERSION
)
34 "." 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
=
215 "rate_policy_every_n";
216 const char *const mi_lttng_element_rate_policy_once_after_n
=
217 "rate_policy_once_after_n";
219 const char *const mi_lttng_element_rate_policy_every_n_interval
=
222 *const mi_lttng_element_rate_policy_once_after_n_threshold
=
225 /* String related to action elements */
226 const char *const mi_lttng_element_action
= "action";
227 const char *const mi_lttng_element_action_list
= "action_list";
228 const char *const mi_lttng_element_action_notify
= "action_notify";
229 const char *const mi_lttng_element_action_start_session
=
230 "action_start_session";
231 const char *const mi_lttng_element_action_stop_session
=
232 "action_stop_session";
233 const char *const mi_lttng_element_action_rotate_session
=
234 "action_rotate_session";
235 const char *const mi_lttng_element_action_snapshot_session
=
236 "action_snapshot_session";
237 const char *const mi_lttng_element_action_snapshot_session_output
=
240 /* String related to condition */
241 const char *const mi_lttng_element_condition
= "condition";
242 const char *const mi_lttng_element_condition_buffer_usage_high
=
243 "condition_buffer_usage_high";
244 const char *const mi_lttng_element_condition_buffer_usage_low
=
245 "condition_buffer_usage_low";
246 const char *const mi_lttng_element_condition_event_rule_matches
=
247 "condition_event_rule_matches";
248 const char *const mi_lttng_element_condition_session_consumed_size
=
249 "condition_session_consumed_size";
250 const char *const mi_lttng_element_condition_session_rotation
=
251 "condition_session_rotation";
253 *const mi_lttng_element_condition_session_rotation_completed
=
254 "condition_session_rotation_completed";
256 *const mi_lttng_element_condition_session_rotation_ongoing
=
257 "condition_session_rotation_ongoing";
259 const char *const mi_lttng_element_condition_channel_name
=
261 const char *const mi_lttng_element_condition_threshold_bytes
=
263 const char *const mi_lttng_element_condition_threshold_ratio
=
266 /* String related to capture descriptor */
267 const char *const mi_lttng_element_capture_descriptor
=
268 "capture_descriptor";
269 const char *const mi_lttng_element_capture_descriptors
=
270 "capture_descriptors";
272 /* String related to event expression */
273 const char *const mi_lttng_element_event_expr
= "event_expr";
274 const char *const mi_lttng_element_event_expr_payload_field
=
275 "event_expr_payload_field";
276 const char *const mi_lttng_element_event_expr_channel_context_field
=
277 "event_expr_channel_context_field";
279 *const mi_lttng_element_event_expr_app_specific_context_field
=
280 "event_expr_app_specific_context_field";
281 const char *const mi_lttng_element_event_expr_array_field_element
=
282 "event_expr_array_field_element";
283 const char *const mi_lttng_element_event_expr_provider_name
=
285 const char *const mi_lttng_element_event_expr_type_name
=
287 const char *const mi_lttng_element_event_expr_index
= "index";
289 /* String related to event rule */
290 const char *const mi_lttng_element_event_rule
= "event_rule";
292 /* String related to lttng_event_rule_type */
293 const char *const mi_lttng_element_event_rule_event_name
=
295 const char *const mi_lttng_element_event_rule_name_pattern
=
297 const char *const mi_lttng_element_event_rule_filter_expression
=
300 const char *const mi_lttng_element_event_rule_jul_logging
=
301 "event_rule_jul_logging";
302 const char *const mi_lttng_element_event_rule_kernel_kprobe
=
303 "event_rule_kernel_kprobe";
304 const char *const mi_lttng_element_event_rule_kernel_syscall
=
305 "event_rule_kernel_syscall";
306 const char *const mi_lttng_element_event_rule_kernel_tracepoint
=
307 "event_rule_kernel_tracepoint";
308 const char *const mi_lttng_element_event_rule_kernel_uprobe
=
309 "event_rule_kernel_uprobe";
310 const char *const mi_lttng_element_event_rule_log4j_logging
=
311 "event_rule_log4j_logging";
312 const char *const mi_lttng_element_event_rule_python_logging
=
313 "event_rule_python_logging";
314 const char *const mi_lttng_element_event_rule_user_tracepoint
=
315 "event_rule_user_tracepoint";
317 /* String related to lttng_event_rule_kernel_syscall. */
319 mi_lttng_element_event_rule_kernel_syscall_emission_site
=
322 /* String related to enum lttng_event_rule_kernel_syscall_emission_site. */
324 mi_lttng_event_rule_kernel_syscall_emission_site_entry_exit
=
327 *const mi_lttng_event_rule_kernel_syscall_emission_site_entry
=
330 mi_lttng_event_rule_kernel_syscall_emission_site_exit
= "exit";
332 /* String related to lttng_event_rule_user_tracepoint */
334 mi_lttng_element_event_rule_user_tracepoint_name_pattern_exclusions
=
335 "name_pattern_exclusions";
337 mi_lttng_element_event_rule_user_tracepoint_name_pattern_exclusion
=
338 "name_pattern_exclusion";
340 /* String related to log level rule. */
341 const char *const mi_lttng_element_log_level_rule
=
343 const char *const mi_lttng_element_log_level_rule_exactly
=
344 "log_level_rule_exactly";
346 *const mi_lttng_element_log_level_rule_at_least_as_severe_as
=
347 "log_level_rule_at_least_as_severe_as";
348 const char *const mi_lttng_element_log_level_rule_level
= "level";
350 /* String related to kernel probe location. */
351 const char *const mi_lttng_element_kernel_probe_location
=
352 "kernel_probe_location";
354 *const mi_lttng_element_kernel_probe_location_symbol_offset
=
355 "kernel_probe_location_symbol_offset";
357 mi_lttng_element_kernel_probe_location_symbol_offset_name
=
360 mi_lttng_element_kernel_probe_location_symbol_offset_offset
=
363 const char *const mi_lttng_element_kernel_probe_location_address
=
364 "kernel_probe_location_address";
366 *const mi_lttng_element_kernel_probe_location_address_address
=
369 /* String related to userspace probe location. */
370 const char *const mi_lttng_element_userspace_probe_location
=
371 "userspace_probe_location";
373 *const mi_lttng_element_userspace_probe_location_binary_path
=
376 *const mi_lttng_element_userspace_probe_location_function
=
377 "userspace_probe_location_function";
379 *const mi_lttng_element_userspace_probe_location_function_name
=
382 *const mi_lttng_element_userspace_probe_location_lookup_method
=
383 "userspace_probe_location_lookup_method";
385 mi_lttng_element_userspace_probe_location_lookup_method_function_default
=
386 "userspace_probe_location_lookup_method_function_default";
388 mi_lttng_element_userspace_probe_location_lookup_method_function_elf
=
389 "userspace_probe_location_lookup_method_function_elf";
391 mi_lttng_element_userspace_probe_location_lookup_method_tracepoint_sdt
=
392 "userspace_probe_location_lookup_method_tracepoint_sdt";
394 *const mi_lttng_element_userspace_probe_location_tracepoint
=
395 "userspace_probe_location_tracepoint";
397 mi_lttng_element_userspace_probe_location_tracepoint_probe_name
=
400 mi_lttng_element_userspace_probe_location_tracepoint_provider_name
=
403 /* String related to enum
404 * lttng_userspace_probe_location_function_instrumentation_type */
406 mi_lttng_element_userspace_probe_location_function_instrumentation_type
=
407 "instrumentation_type";
409 mi_lttng_userspace_probe_location_function_instrumentation_type_entry
=
412 /* String related to trigger */
413 const char *const mi_lttng_element_triggers
= "triggers";
414 const char *const mi_lttng_element_trigger
= "trigger";
415 const char *const mi_lttng_element_trigger_owner_uid
= "owner_uid";
417 /* String related to error_query. */
418 const char *const mi_lttng_element_error_query_result
=
419 "error_query_result";
420 const char *const mi_lttng_element_error_query_result_counter
=
421 "error_query_result_counter";
423 mi_lttng_element_error_query_result_counter_value
= "value";
424 const char *const mi_lttng_element_error_query_result_description
=
426 const char *const mi_lttng_element_error_query_result_name
=
428 const char *const mi_lttng_element_error_query_result_type
=
430 const char *const mi_lttng_element_error_query_results
=
431 "error_query_results";
433 /* String related to add-context command */
434 const char * const mi_lttng_element_context_symbol
= "symbol";
436 /* Deprecated symbols preserved for ABI compatibility. */
437 LTTNG_EXPORT
const char *mi_lttng_context_type_perf_counter
;
438 LTTNG_EXPORT
const char *mi_lttng_context_type_perf_cpu_counter
;
439 LTTNG_EXPORT
const char *mi_lttng_context_type_perf_thread_counter
;
440 LTTNG_EXPORT
const char *mi_lttng_element_track_untrack_pid_target
;
441 LTTNG_EXPORT
const char *mi_lttng_element_track_untrack_targets
;
442 LTTNG_EXPORT
const char *mi_lttng_element_calibrate
;
443 LTTNG_EXPORT
const char *mi_lttng_element_calibrate_function
;
444 LTTNG_EXPORT
const char *mi_lttng_element_command_calibrate
;
446 /* This is a merge of jul loglevel and regular loglevel
447 * Those should never overlap by definition
448 * (see struct lttng_event loglevel)
450 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
453 case LTTNG_DOMAIN_KERNEL
:
454 case LTTNG_DOMAIN_UST
:
457 return mi_lttng_element_empty
;
458 case LTTNG_LOGLEVEL_EMERG
:
459 return mi_lttng_loglevel_str_emerg
;
460 case LTTNG_LOGLEVEL_ALERT
:
461 return mi_lttng_loglevel_str_alert
;
462 case LTTNG_LOGLEVEL_CRIT
:
463 return mi_lttng_loglevel_str_crit
;
464 case LTTNG_LOGLEVEL_ERR
:
465 return mi_lttng_loglevel_str_err
;
466 case LTTNG_LOGLEVEL_WARNING
:
467 return mi_lttng_loglevel_str_warning
;
468 case LTTNG_LOGLEVEL_NOTICE
:
469 return mi_lttng_loglevel_str_notice
;
470 case LTTNG_LOGLEVEL_INFO
:
471 return mi_lttng_loglevel_str_info
;
472 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
473 return mi_lttng_loglevel_str_debug_system
;
474 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
475 return mi_lttng_loglevel_str_debug_program
;
476 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
477 return mi_lttng_loglevel_str_debug_process
;
478 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
479 return mi_lttng_loglevel_str_debug_module
;
480 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
481 return mi_lttng_loglevel_str_debug_unit
;
482 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
483 return mi_lttng_loglevel_str_debug_function
;
484 case LTTNG_LOGLEVEL_DEBUG_LINE
:
485 return mi_lttng_loglevel_str_debug_line
;
486 case LTTNG_LOGLEVEL_DEBUG
:
487 return mi_lttng_loglevel_str_debug
;
489 return mi_lttng_loglevel_str_unknown
;
492 case LTTNG_DOMAIN_LOG4J
:
495 return mi_lttng_element_empty
;
496 case LTTNG_LOGLEVEL_LOG4J_OFF
:
497 return mi_lttng_loglevel_str_log4j_off
;
498 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
499 return mi_lttng_loglevel_str_log4j_fatal
;
500 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
501 return mi_lttng_loglevel_str_log4j_error
;
502 case LTTNG_LOGLEVEL_LOG4J_WARN
:
503 return mi_lttng_loglevel_str_log4j_warn
;
504 case LTTNG_LOGLEVEL_LOG4J_INFO
:
505 return mi_lttng_loglevel_str_log4j_info
;
506 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
507 return mi_lttng_loglevel_str_log4j_debug
;
508 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
509 return mi_lttng_loglevel_str_log4j_trace
;
510 case LTTNG_LOGLEVEL_LOG4J_ALL
:
511 return mi_lttng_loglevel_str_log4j_all
;
513 return mi_lttng_loglevel_str_unknown
;
516 case LTTNG_DOMAIN_JUL
:
519 return mi_lttng_element_empty
;
520 case LTTNG_LOGLEVEL_JUL_OFF
:
521 return mi_lttng_loglevel_str_jul_off
;
522 case LTTNG_LOGLEVEL_JUL_SEVERE
:
523 return mi_lttng_loglevel_str_jul_severe
;
524 case LTTNG_LOGLEVEL_JUL_WARNING
:
525 return mi_lttng_loglevel_str_jul_warning
;
526 case LTTNG_LOGLEVEL_JUL_INFO
:
527 return mi_lttng_loglevel_str_jul_info
;
528 case LTTNG_LOGLEVEL_JUL_CONFIG
:
529 return mi_lttng_loglevel_str_jul_config
;
530 case LTTNG_LOGLEVEL_JUL_FINE
:
531 return mi_lttng_loglevel_str_jul_fine
;
532 case LTTNG_LOGLEVEL_JUL_FINER
:
533 return mi_lttng_loglevel_str_jul_finer
;
534 case LTTNG_LOGLEVEL_JUL_FINEST
:
535 return mi_lttng_loglevel_str_jul_finest
;
536 case LTTNG_LOGLEVEL_JUL_ALL
:
537 return mi_lttng_loglevel_str_jul_all
;
539 return mi_lttng_loglevel_str_unknown
;
542 case LTTNG_DOMAIN_PYTHON
:
544 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
545 return mi_lttng_loglevel_str_python_critical
;
546 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
547 return mi_lttng_loglevel_str_python_error
;
548 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
549 return mi_lttng_loglevel_str_python_warning
;
550 case LTTNG_LOGLEVEL_PYTHON_INFO
:
551 return mi_lttng_loglevel_str_python_info
;
552 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
553 return mi_lttng_loglevel_str_python_debug
;
554 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
555 return mi_lttng_loglevel_str_python_notset
;
557 return mi_lttng_loglevel_str_unknown
;
561 return mi_lttng_loglevel_str_unknown
;
565 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
568 case LTTNG_EVENT_LOGLEVEL_ALL
:
569 return mi_lttng_loglevel_type_all
;
570 case LTTNG_EVENT_LOGLEVEL_RANGE
:
571 return mi_lttng_loglevel_type_range
;
572 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
573 return mi_lttng_loglevel_type_single
;
575 return mi_lttng_loglevel_type_unknown
;
580 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
583 case LTTNG_EVENT_ALL
:
584 return config_event_type_all
;
585 case LTTNG_EVENT_TRACEPOINT
:
586 return config_event_type_tracepoint
;
587 case LTTNG_EVENT_PROBE
:
588 return config_event_type_probe
;
589 case LTTNG_EVENT_USERSPACE_PROBE
:
590 return config_event_type_userspace_probe
;
591 case LTTNG_EVENT_FUNCTION
:
592 return config_event_type_function
;
593 case LTTNG_EVENT_FUNCTION_ENTRY
:
594 return config_event_type_function_entry
;
595 case LTTNG_EVENT_SYSCALL
:
596 return config_event_type_syscall
;
597 case LTTNG_EVENT_NOOP
:
598 return config_event_type_noop
;
600 return mi_lttng_element_empty
;
605 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
608 case LTTNG_EVENT_CONTEXT_PID
:
609 return config_event_context_pid
;
610 case LTTNG_EVENT_CONTEXT_PROCNAME
:
611 return config_event_context_procname
;
612 case LTTNG_EVENT_CONTEXT_PRIO
:
613 return config_event_context_prio
;
614 case LTTNG_EVENT_CONTEXT_NICE
:
615 return config_event_context_nice
;
616 case LTTNG_EVENT_CONTEXT_VPID
:
617 return config_event_context_vpid
;
618 case LTTNG_EVENT_CONTEXT_TID
:
619 return config_event_context_tid
;
620 case LTTNG_EVENT_CONTEXT_VTID
:
621 return config_event_context_vtid
;
622 case LTTNG_EVENT_CONTEXT_PPID
:
623 return config_event_context_ppid
;
624 case LTTNG_EVENT_CONTEXT_VPPID
:
625 return config_event_context_vppid
;
626 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
627 return config_event_context_pthread_id
;
628 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
629 return config_event_context_hostname
;
630 case LTTNG_EVENT_CONTEXT_IP
:
631 return config_event_context_ip
;
632 case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
:
633 return config_event_context_interruptible
;
634 case LTTNG_EVENT_CONTEXT_PREEMPTIBLE
:
635 return config_event_context_preemptible
;
636 case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
:
637 return config_event_context_need_reschedule
;
638 case LTTNG_EVENT_CONTEXT_MIGRATABLE
:
639 return config_event_context_migratable
;
640 case LTTNG_EVENT_CONTEXT_CALLSTACK_USER
:
641 return config_event_context_callstack_user
;
642 case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
:
643 return config_event_context_callstack_kernel
;
644 case LTTNG_EVENT_CONTEXT_CGROUP_NS
:
645 return config_event_context_cgroup_ns
;
646 case LTTNG_EVENT_CONTEXT_IPC_NS
:
647 return config_event_context_ipc_ns
;
648 case LTTNG_EVENT_CONTEXT_MNT_NS
:
649 return config_event_context_mnt_ns
;
650 case LTTNG_EVENT_CONTEXT_NET_NS
:
651 return config_event_context_net_ns
;
652 case LTTNG_EVENT_CONTEXT_PID_NS
:
653 return config_event_context_pid_ns
;
654 case LTTNG_EVENT_CONTEXT_TIME_NS
:
655 return config_event_context_time_ns
;
656 case LTTNG_EVENT_CONTEXT_USER_NS
:
657 return config_event_context_user_ns
;
658 case LTTNG_EVENT_CONTEXT_UTS_NS
:
659 return config_event_context_uts_ns
;
660 case LTTNG_EVENT_CONTEXT_UID
:
661 return config_event_context_uid
;
662 case LTTNG_EVENT_CONTEXT_EUID
:
663 return config_event_context_euid
;
664 case LTTNG_EVENT_CONTEXT_SUID
:
665 return config_event_context_suid
;
666 case LTTNG_EVENT_CONTEXT_GID
:
667 return config_event_context_gid
;
668 case LTTNG_EVENT_CONTEXT_EGID
:
669 return config_event_context_egid
;
670 case LTTNG_EVENT_CONTEXT_SGID
:
671 return config_event_context_sgid
;
672 case LTTNG_EVENT_CONTEXT_VUID
:
673 return config_event_context_vuid
;
674 case LTTNG_EVENT_CONTEXT_VEUID
:
675 return config_event_context_veuid
;
676 case LTTNG_EVENT_CONTEXT_VSUID
:
677 return config_event_context_vsuid
;
678 case LTTNG_EVENT_CONTEXT_VGID
:
679 return config_event_context_vgid
;
680 case LTTNG_EVENT_CONTEXT_VEGID
:
681 return config_event_context_vegid
;
682 case LTTNG_EVENT_CONTEXT_VSGID
:
683 return config_event_context_vsgid
;
689 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
692 case(LTTNG_EVENT_FIELD_INTEGER
):
693 return mi_lttng_element_type_integer
;
694 case(LTTNG_EVENT_FIELD_ENUM
):
695 return mi_lttng_element_type_enum
;
696 case(LTTNG_EVENT_FIELD_FLOAT
):
697 return mi_lttng_element_type_float
;
698 case(LTTNG_EVENT_FIELD_STRING
):
699 return mi_lttng_element_type_string
;
701 return mi_lttng_element_type_other
;
705 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
708 case LTTNG_DOMAIN_KERNEL
:
709 return config_domain_type_kernel
;
710 case LTTNG_DOMAIN_UST
:
711 return config_domain_type_ust
;
712 case LTTNG_DOMAIN_JUL
:
713 return config_domain_type_jul
;
714 case LTTNG_DOMAIN_LOG4J
:
715 return config_domain_type_log4j
;
716 case LTTNG_DOMAIN_PYTHON
:
717 return config_domain_type_python
;
719 /* Should not have an unknown domain */
725 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
728 case LTTNG_BUFFER_PER_PID
:
729 return config_buffer_type_per_pid
;
730 case LTTNG_BUFFER_PER_UID
:
731 return config_buffer_type_per_uid
;
732 case LTTNG_BUFFER_GLOBAL
:
733 return config_buffer_type_global
;
735 /* Should not have an unknow buffer type */
741 const char *mi_lttng_rotation_state_string(enum lttng_rotation_state value
)
744 case LTTNG_ROTATION_STATE_ONGOING
:
745 return mi_lttng_rotation_state_str_ongoing
;
746 case LTTNG_ROTATION_STATE_COMPLETED
:
747 return mi_lttng_rotation_state_str_completed
;
748 case LTTNG_ROTATION_STATE_EXPIRED
:
749 return mi_lttng_rotation_state_str_expired
;
750 case LTTNG_ROTATION_STATE_ERROR
:
751 return mi_lttng_rotation_state_str_error
;
753 /* Should not have an unknow rotation state. */
759 const char *mi_lttng_trace_archive_location_relay_protocol_type_string(
760 enum lttng_trace_archive_location_relay_protocol_type value
)
763 case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP
:
764 return mi_lttng_rotation_location_relay_protocol_str_tcp
;
766 /* Should not have an unknown relay protocol. */
772 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
774 struct mi_writer
*mi_writer
;
776 mi_writer
= (struct mi_writer
*) zmalloc(sizeof(struct mi_writer
));
778 PERROR("zmalloc mi_writer_create");
781 if (mi_output_type
== LTTNG_MI_XML
) {
782 mi_writer
->writer
= config_writer_create(fd_output
, 0);
783 if (!mi_writer
->writer
) {
786 mi_writer
->type
= LTTNG_MI_XML
;
799 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
808 ret
= config_writer_destroy(writer
->writer
);
818 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
823 * A command is always the MI's root node, it must declare the current
824 * namespace and schema URIs and the schema's version.
826 ret
= config_writer_open_element(writer
->writer
,
827 mi_lttng_element_command
);
832 ret
= config_writer_write_attribute(writer
->writer
,
833 mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
838 ret
= config_writer_write_attribute(writer
->writer
,
839 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
844 ret
= config_writer_write_attribute(writer
->writer
,
845 mi_lttng_schema_location
,
846 mi_lttng_schema_location_uri
);
851 ret
= config_writer_write_attribute(writer
->writer
,
852 mi_lttng_schema_version
,
853 mi_lttng_schema_version_value
);
858 ret
= mi_lttng_writer_write_element_string(writer
,
859 mi_lttng_element_command_name
, command
);
864 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
866 return mi_lttng_writer_close_element(writer
);
869 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
870 const char *element_name
)
872 return config_writer_open_element(writer
->writer
, element_name
);
875 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
877 return config_writer_close_element(writer
->writer
);
880 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
881 unsigned int nb_element
)
885 if (nb_element
< 1) {
889 for (i
= 0; i
< nb_element
; i
++) {
890 ret
= mi_lttng_writer_close_element(writer
);
899 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
900 const char *element_name
, uint64_t value
)
902 return config_writer_write_element_unsigned_int(writer
->writer
,
903 element_name
, value
);
906 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
907 const char *element_name
, int64_t value
)
909 return config_writer_write_element_signed_int(writer
->writer
,
910 element_name
, value
);
913 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
914 const char *element_name
, int value
)
916 return config_writer_write_element_bool(writer
->writer
,
917 element_name
, value
);
920 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
921 const char *element_name
, const char *value
)
923 return config_writer_write_element_string(writer
->writer
,
924 element_name
, value
);
927 int mi_lttng_writer_write_element_double(struct mi_writer
*writer
,
928 const char *element_name
,
931 return config_writer_write_element_double(
932 writer
->writer
, element_name
, value
);
935 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version_data
*version
,
936 const char *lttng_description
, const char *lttng_license
)
941 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
946 /* Version string (contain info like rc etc.) */
947 ret
= mi_lttng_writer_write_element_string(writer
,
948 mi_lttng_element_version_str
, version
->version
);
953 /* Major version number */
954 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
955 mi_lttng_element_version_major
, version
->version_major
);
960 /* Minor version number */
961 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
962 mi_lttng_element_version_minor
, version
->version_minor
);
967 /* Commit version number */
968 ret
= mi_lttng_writer_write_element_string(writer
,
969 mi_lttng_element_version_commit
, version
->version_commit
);
975 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
976 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
981 /* Name of the version */
982 ret
= mi_lttng_writer_write_element_string(writer
,
983 config_element_name
, version
->version_name
);
988 /* Description mostly related to beer... */
989 ret
= mi_lttng_writer_write_element_string(writer
,
990 mi_lttng_element_version_description
, lttng_description
);
996 ret
= mi_lttng_writer_write_element_string(writer
,
997 mi_lttng_element_version_web
, version
->package_url
);
1002 /* License: free as in free beer...no...*speech* */
1003 ret
= mi_lttng_writer_write_element_string(writer
,
1004 mi_lttng_element_version_license
, lttng_license
);
1009 /* Close version element */
1010 ret
= mi_lttng_writer_close_element(writer
);
1016 int mi_lttng_sessions_open(struct mi_writer
*writer
)
1018 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
1021 int mi_lttng_session(struct mi_writer
*writer
,
1022 struct lttng_session
*session
, int is_open
)
1026 LTTNG_ASSERT(session
);
1028 /* Open sessions element */
1029 ret
= mi_lttng_writer_open_element(writer
,
1030 config_element_session
);
1035 /* Name of the session */
1036 ret
= mi_lttng_writer_write_element_string(writer
,
1037 config_element_name
, session
->name
);
1043 ret
= mi_lttng_writer_write_element_string(writer
,
1044 config_element_path
, session
->path
);
1050 ret
= mi_lttng_writer_write_element_bool(writer
,
1051 config_element_enabled
, session
->enabled
);
1057 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1058 config_element_snapshot_mode
, session
->snapshot_mode
);
1063 /* Live timer interval in usec */
1064 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1065 config_element_live_timer_interval
,
1066 session
->live_timer_interval
);
1072 /* Closing session element */
1073 ret
= mi_lttng_writer_close_element(writer
);
1080 int mi_lttng_domains_open(struct mi_writer
*writer
)
1082 return mi_lttng_writer_open_element(writer
, config_element_domains
);
1085 int mi_lttng_domain(struct mi_writer
*writer
,
1086 struct lttng_domain
*domain
, int is_open
)
1089 const char *str_domain
;
1090 const char *str_buffer
;
1092 LTTNG_ASSERT(domain
);
1094 /* Open domain element */
1095 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
1101 str_domain
= mi_lttng_domaintype_string(domain
->type
);
1102 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1109 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
1110 ret
= mi_lttng_writer_write_element_string(writer
,
1111 config_element_buffer_type
, str_buffer
);
1117 * This union is not currently used and was added for
1118 * future ust domain support.
1123 /* Closing domain element */
1124 ret
= mi_lttng_writer_close_element(writer
);
1132 int mi_lttng_channels_open(struct mi_writer
*writer
)
1134 return mi_lttng_writer_open_element(writer
, config_element_channels
);
1137 int mi_lttng_channel(struct mi_writer
*writer
,
1138 struct lttng_channel
*channel
, int is_open
)
1142 LTTNG_ASSERT(channel
);
1144 /* Opening channel element */
1145 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
1151 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1158 ret
= mi_lttng_writer_write_element_bool(writer
,
1159 config_element_enabled
, channel
->enabled
);
1165 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
1171 /* Closing channel element */
1172 ret
= mi_lttng_writer_close_element(writer
);
1181 int mi_lttng_channel_attr(struct mi_writer
*writer
,
1182 struct lttng_channel_attr
*attr
)
1185 struct lttng_channel
*chan
= caa_container_of(attr
,
1186 struct lttng_channel
, attr
);
1187 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1188 int64_t blocking_timeout
;
1192 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
1197 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
1202 ret
= lttng_channel_get_monitor_timer_interval(chan
,
1203 &monitor_timer_interval
);
1208 ret
= lttng_channel_get_blocking_timeout(chan
,
1214 /* Opening Attributes */
1215 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1221 ret
= mi_lttng_writer_write_element_string(writer
,
1222 config_element_overwrite_mode
,
1223 attr
->overwrite
? config_overwrite_mode_overwrite
:
1224 config_overwrite_mode_discard
);
1229 /* Sub buffer size in byte */
1230 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1231 config_element_subbuf_size
, attr
->subbuf_size
);
1236 /* Number of subbuffer (power of two) */
1237 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1238 config_element_num_subbuf
,
1244 /* Switch timer interval in usec */
1245 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1246 config_element_switch_timer_interval
,
1247 attr
->switch_timer_interval
);
1252 /* Read timer interval in usec */
1253 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1254 config_element_read_timer_interval
,
1255 attr
->read_timer_interval
);
1260 /* Monitor timer interval in usec */
1261 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1262 config_element_monitor_timer_interval
,
1263 monitor_timer_interval
);
1268 /* Retry timeout in usec */
1269 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1270 config_element_blocking_timeout
,
1277 ret
= mi_lttng_writer_write_element_string(writer
,
1278 config_element_output_type
,
1279 attr
->output
== LTTNG_EVENT_SPLICE
?
1280 config_output_type_splice
: config_output_type_mmap
);
1285 /* Tracefile size in bytes */
1286 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1287 config_element_tracefile_size
, attr
->tracefile_size
);
1292 /* Count of tracefiles */
1293 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1294 config_element_tracefile_count
,
1295 attr
->tracefile_count
);
1300 /* Live timer interval in usec*/
1301 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1302 config_element_live_timer_interval
,
1303 attr
->live_timer_interval
);
1308 /* Discarded events */
1309 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1310 config_element_discarded_events
,
1317 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1318 config_element_lost_packets
,
1324 /* Closing attributes */
1325 ret
= mi_lttng_writer_close_element(writer
);
1334 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
1335 struct lttng_event
*event
)
1338 const char *filter_expression
;
1340 /* Open event element */
1341 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
1347 ret
= mi_lttng_writer_write_element_string(writer
,
1348 config_element_name
, event
->name
);
1354 ret
= mi_lttng_writer_write_element_string(writer
,
1355 config_element_type
, mi_lttng_eventtype_string(event
->type
));
1360 /* Is event enabled */
1361 ret
= mi_lttng_writer_write_element_bool(writer
,
1362 config_element_enabled
, event
->enabled
);
1367 /* Event filter expression */
1368 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1373 if (filter_expression
) {
1374 ret
= mi_lttng_writer_write_element_string(writer
,
1375 config_element_filter_expression
,
1386 static int write_event_exclusions(struct mi_writer
*writer
,
1387 struct lttng_event
*event
)
1391 int exclusion_count
;
1393 /* Open event exclusions */
1394 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1399 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1400 if (exclusion_count
< 0) {
1401 ret
= exclusion_count
;
1405 for (i
= 0; i
< exclusion_count
; i
++) {
1408 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1410 /* Close exclusions */
1411 mi_lttng_writer_close_element(writer
);
1415 ret
= mi_lttng_writer_write_element_string(writer
,
1416 config_element_exclusion
, name
);
1418 /* Close exclusions */
1419 mi_lttng_writer_close_element(writer
);
1424 /* Close exclusions */
1425 ret
= mi_lttng_writer_close_element(writer
);
1431 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1432 struct lttng_event
*event
, enum lttng_domain_type domain
)
1436 /* Event loglevel */
1437 ret
= mi_lttng_writer_write_element_string(writer
,
1438 config_element_loglevel
,
1439 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1444 /* Log level type */
1445 ret
= mi_lttng_writer_write_element_string(writer
,
1446 config_element_loglevel_type
,
1447 mi_lttng_logleveltype_string(event
->loglevel_type
));
1452 /* Event exclusions */
1453 ret
= write_event_exclusions(writer
, event
);
1459 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1460 struct lttng_event
*event
)
1462 /* event exclusion filter */
1463 return write_event_exclusions(writer
, event
);
1466 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1467 struct lttng_event
*event
)
1471 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1476 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1481 if (event
->attr
.probe
.addr
!= 0) {
1482 /* event probe address */
1483 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1484 config_element_address
, event
->attr
.probe
.addr
);
1489 /* event probe offset */
1490 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1491 config_element_offset
, event
->attr
.probe
.offset
);
1496 /* event probe symbol_name */
1497 ret
= mi_lttng_writer_write_element_string(writer
,
1498 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1504 /* Close probe_attributes and attributes */
1505 ret
= mi_lttng_close_multi_element(writer
, 2);
1511 int mi_lttng_event_userspace_probe(struct mi_writer
*writer
,
1512 struct lttng_event
*event
)
1515 const struct lttng_userspace_probe_location
*location
;
1516 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
1517 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
1519 location
= lttng_event_get_userspace_probe_location(event
);
1521 ret
= -LTTNG_ERR_INVALID
;
1525 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
1526 if (!lookup_method
) {
1527 ret
= -LTTNG_ERR_INVALID
;
1531 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
1533 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1538 switch (lttng_userspace_probe_location_get_type(location
)) {
1539 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1541 const char *function_name
;
1542 const char *binary_path
;
1544 ret
= mi_lttng_writer_open_element(writer
,
1545 config_element_userspace_probe_function_attributes
);
1550 switch (lookup_type
) {
1551 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
1552 ret
= mi_lttng_writer_write_element_string(writer
,
1553 config_element_userspace_probe_lookup
,
1554 config_element_userspace_probe_lookup_function_elf
);
1559 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
1560 ret
= mi_lttng_writer_write_element_string(writer
,
1561 config_element_userspace_probe_lookup
,
1562 config_element_userspace_probe_lookup_function_default
);
1571 binary_path
= lttng_userspace_probe_location_function_get_binary_path(location
);
1572 ret
= mi_lttng_writer_write_element_string(writer
,
1573 config_element_userspace_probe_location_binary_path
, binary_path
);
1578 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
1579 ret
= mi_lttng_writer_write_element_string(writer
,
1580 config_element_userspace_probe_function_location_function_name
,
1588 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1590 const char *probe_name
, *provider_name
;
1591 const char *binary_path
;
1593 ret
= mi_lttng_writer_open_element(writer
,
1594 config_element_userspace_probe_function_attributes
);
1599 switch (lookup_type
) {
1600 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
1601 ret
= mi_lttng_writer_write_element_string(writer
,
1602 config_element_userspace_probe_lookup
,
1603 config_element_userspace_probe_lookup_tracepoint_sdt
);
1612 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(location
);
1613 ret
= mi_lttng_writer_write_element_string(writer
,
1614 config_element_userspace_probe_location_binary_path
,
1620 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
1621 ret
= mi_lttng_writer_write_element_string(writer
,
1622 config_element_userspace_probe_tracepoint_location_provider_name
,
1628 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
1629 ret
= mi_lttng_writer_write_element_string(writer
,
1630 config_element_userspace_probe_tracepoint_location_probe_name
, probe_name
);
1637 ERR("Invalid probe type encountered");
1639 /* Close probe_attributes and attributes */
1640 ret
= mi_lttng_close_multi_element(writer
, 2);
1645 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1646 struct lttng_event
*event
)
1650 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1655 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1660 /* event probe symbol_name */
1661 ret
= mi_lttng_writer_write_element_string(writer
,
1662 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1667 /* Close function_attributes and attributes */
1668 ret
= mi_lttng_close_multi_element(writer
, 2);
1673 int mi_lttng_events_open(struct mi_writer
*writer
)
1675 return mi_lttng_writer_open_element(writer
, config_element_events
);
1678 int mi_lttng_event(struct mi_writer
*writer
,
1679 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1683 ret
= mi_lttng_event_common_attributes(writer
, event
);
1688 switch (event
->type
) {
1689 case LTTNG_EVENT_TRACEPOINT
:
1691 if (event
->loglevel
!= -1) {
1692 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1694 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1698 case LTTNG_EVENT_FUNCTION
:
1700 case LTTNG_EVENT_PROBE
:
1701 ret
= mi_lttng_event_function_probe(writer
, event
);
1703 case LTTNG_EVENT_FUNCTION_ENTRY
:
1704 ret
= mi_lttng_event_function_entry(writer
, event
);
1706 case LTTNG_EVENT_USERSPACE_PROBE
:
1707 ret
= mi_lttng_event_userspace_probe(writer
, event
);
1709 case LTTNG_EVENT_ALL
:
1720 ret
= mi_lttng_writer_close_element(writer
);
1727 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1729 return mi_lttng_writer_open_element(
1730 writer
, config_element_process_attr_trackers
);
1733 static int get_tracker_elements(enum lttng_process_attr process_attr
,
1734 const char **element_process_attr_tracker
,
1735 const char **element_process_attr_value
)
1739 switch (process_attr
) {
1740 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1741 *element_process_attr_tracker
=
1742 config_element_process_attr_tracker_pid
;
1743 *element_process_attr_value
=
1744 config_element_process_attr_pid_value
;
1746 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1747 *element_process_attr_tracker
=
1748 config_element_process_attr_tracker_vpid
;
1749 *element_process_attr_value
=
1750 config_element_process_attr_vpid_value
;
1752 case LTTNG_PROCESS_ATTR_USER_ID
:
1753 *element_process_attr_tracker
=
1754 config_element_process_attr_tracker_uid
;
1755 *element_process_attr_value
=
1756 config_element_process_attr_uid_value
;
1758 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1759 *element_process_attr_tracker
=
1760 config_element_process_attr_tracker_vuid
;
1761 *element_process_attr_value
=
1762 config_element_process_attr_vuid_value
;
1764 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1765 *element_process_attr_tracker
=
1766 config_element_process_attr_tracker_gid
;
1767 *element_process_attr_value
=
1768 config_element_process_attr_gid_value
;
1770 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1771 *element_process_attr_tracker
=
1772 config_element_process_attr_tracker_vgid
;
1773 *element_process_attr_value
=
1774 config_element_process_attr_vgid_value
;
1777 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1782 int mi_lttng_process_attribute_tracker_open(
1783 struct mi_writer
*writer
, enum lttng_process_attr process_attr
)
1786 const char *element_tracker
, *element_value
;
1788 ret
= get_tracker_elements(
1789 process_attr
, &element_tracker
, &element_value
);
1794 /* Open process attribute tracker element */
1795 ret
= mi_lttng_writer_open_element(writer
, element_tracker
);
1800 /* Open values element */
1801 ret
= mi_lttng_process_attr_values_open(writer
);
1806 int mi_lttng_pids_open(struct mi_writer
*writer
)
1808 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1812 * TODO: move the listing of pid for user agent to process semantic on
1813 * mi api bump. The use of process element break the mi api.
1815 int mi_lttng_pid(struct mi_writer
*writer
,
1822 /* Open pid process */
1823 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1828 /* Writing pid number */
1829 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1830 mi_lttng_element_pid_id
, (int)pid
);
1835 /* Writing name of the process */
1837 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1846 ret
= mi_lttng_writer_close_element(writer
);
1853 int mi_lttng_process_attr_values_open(struct mi_writer
*writer
)
1855 return mi_lttng_writer_open_element(
1856 writer
, config_element_process_attr_values
);
1859 int mi_lttng_all_process_attribute_value(struct mi_writer
*writer
,
1860 enum lttng_process_attr process_attr
,
1864 const char *element_id_tracker
, *element_target_id
;
1866 ret
= get_tracker_elements(
1867 process_attr
, &element_id_tracker
, &element_target_id
);
1872 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1877 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1882 ret
= mi_lttng_writer_write_element_bool(writer
, config_element_all
, 1);
1887 ret
= mi_lttng_writer_close_element(writer
);
1893 ret
= mi_lttng_writer_close_element(writer
);
1902 int mi_lttng_integral_process_attribute_value(struct mi_writer
*writer
,
1903 enum lttng_process_attr process_attr
,
1908 const char *element_id_tracker
, *element_target_id
;
1910 ret
= get_tracker_elements(
1911 process_attr
, &element_id_tracker
, &element_target_id
);
1916 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1921 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1926 ret
= mi_lttng_writer_write_element_signed_int(
1927 writer
, config_element_process_attr_id
, value
);
1932 ret
= mi_lttng_writer_close_element(writer
);
1938 ret
= mi_lttng_writer_close_element(writer
);
1948 int mi_lttng_string_process_attribute_value(struct mi_writer
*writer
,
1949 enum lttng_process_attr process_attr
,
1955 const char *element_id_tracker
, *element_target_id
;
1957 ret
= get_tracker_elements(
1958 process_attr
, &element_id_tracker
, &element_target_id
);
1963 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1968 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1973 ret
= mi_lttng_writer_write_element_string(
1974 writer
, config_element_name
, value
);
1979 ret
= mi_lttng_writer_close_element(writer
);
1985 ret
= mi_lttng_writer_close_element(writer
);
1995 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1997 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
2000 int mi_lttng_event_field(struct mi_writer
*writer
,
2001 struct lttng_event_field
*field
)
2005 if (!field
->field_name
[0]) {
2011 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
2016 if (!field
->field_name
[0]) {
2021 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2028 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
2029 mi_lttng_eventfieldtype_string(field
->type
));
2035 ret
= mi_lttng_writer_write_element_signed_int(writer
,
2036 mi_lttng_element_nowrite
, field
->nowrite
);
2042 /* Close field element */
2043 ret
= mi_lttng_writer_close_element(writer
);
2049 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
2050 struct lttng_event_perf_counter_ctx
*perf_context
)
2054 /* Open perf_counter_context */
2055 ret
= mi_lttng_writer_open_element(writer
,
2056 mi_lttng_element_perf_counter_context
);
2062 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2063 config_element_type
, perf_context
->type
);
2069 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2070 config_element_config
, perf_context
->config
);
2075 /* Name of the perf counter */
2076 ret
= mi_lttng_writer_write_element_string(writer
,
2077 config_element_name
, perf_context
->name
);
2082 /* Close perf_counter_context */
2083 ret
= mi_lttng_writer_close_element(writer
);
2089 int mi_lttng_app_context(struct mi_writer
*writer
,
2090 const char *provider_name
, const char *ctx_name
)
2095 ret
= mi_lttng_writer_open_element(writer
,
2096 config_element_context_app
);
2102 ret
= mi_lttng_writer_write_element_string(writer
,
2103 config_element_context_app_provider_name
,
2110 ret
= mi_lttng_writer_write_element_string(writer
,
2111 config_element_context_app_ctx_name
, ctx_name
);
2117 ret
= mi_lttng_writer_close_element(writer
);
2122 int mi_lttng_context(struct mi_writer
*writer
,
2123 struct lttng_event_context
*context
, int is_open
)
2128 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
2133 /* Special case for PERF_*_COUNTER
2134 * print the lttng_event_perf_counter_ctx*/
2135 switch (context
->ctx
) {
2136 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
2137 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
2138 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2140 struct lttng_event_perf_counter_ctx
*perf_context
=
2141 &context
->u
.perf_counter
;
2142 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
2148 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
2150 ret
= mi_lttng_app_context(writer
,
2151 context
->u
.app_ctx
.provider_name
,
2152 context
->u
.app_ctx
.ctx_name
);
2160 const char *type_string
= mi_lttng_event_contexttype_string(
2163 ret
= -LTTNG_ERR_INVALID
;
2167 /* Print context type */
2168 ret
= mi_lttng_writer_write_element_string(writer
,
2169 config_element_type
, type_string
);
2176 ret
= mi_lttng_writer_close_element(writer
);
2183 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
2184 const char *session_name
)
2188 /* Open session element */
2189 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
2194 /* Snapshot output list for current session name */
2195 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2201 /* Open element snapshots (sequence one snapshot) */
2202 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
2211 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
2212 const struct lttng_snapshot_output
*output
)
2216 /* Open element snapshot output */
2217 ret
= mi_lttng_writer_open_element(writer
,
2218 mi_lttng_element_command_snapshot
);
2223 /* ID of the snapshot output */
2224 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2225 mi_lttng_element_id
, output
->id
);
2230 /* Name of the output */
2231 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2237 /* Destination of the output (ctrl_url)*/
2238 ret
= mi_lttng_writer_write_element_string(writer
,
2239 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2244 /* Destination of the output (data_url) */
2245 ret
= mi_lttng_writer_write_element_string(writer
,
2246 mi_lttng_element_snapshot_data_url
, output
->data_url
);
2251 /* total size of all stream combined */
2252 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2253 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2258 /* Close snapshot output element */
2259 ret
= mi_lttng_writer_close_element(writer
);
2265 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
2266 const char *name
, const char *current_session_name
)
2270 /* Open element del_snapshot */
2271 ret
= mi_lttng_writer_open_element(writer
,
2272 mi_lttng_element_command_snapshot
);
2278 if (id
!= UINT32_MAX
) {
2279 /* "Snapshot output "id" successfully deleted
2280 * for "current_session_name"
2281 * ID of the snapshot output
2283 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2284 mi_lttng_element_id
, id
);
2289 /* "Snapshot output "name" successfully deleted
2290 * for session "current_session_name"
2291 * Name of the output
2293 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2300 /* Snapshot was deleted for session "current_session_name"*/
2301 ret
= mi_lttng_writer_write_element_string(writer
,
2302 mi_lttng_element_snapshot_session_name
,
2303 current_session_name
);
2308 /* Close snapshot element */
2309 ret
= mi_lttng_writer_close_element(writer
);
2315 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
2316 const char *current_session_name
, const char *n_ptr
,
2317 struct lttng_snapshot_output
*output
)
2321 /* Open element snapshot */
2322 ret
= mi_lttng_writer_open_element(writer
,
2323 mi_lttng_element_command_snapshot
);
2328 /* Snapshot output id */
2329 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2330 mi_lttng_element_id
, output
->id
);
2335 /* Snapshot output names */
2336 ret
= mi_lttng_writer_write_element_string(writer
,
2337 config_element_name
, n_ptr
);
2342 /* Destination of the output (ctrl_url)*/
2343 ret
= mi_lttng_writer_write_element_string(writer
,
2344 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2349 /* Snapshot added for session "current_session_name"*/
2350 ret
= mi_lttng_writer_write_element_string(writer
,
2351 mi_lttng_element_snapshot_session_name
, current_session_name
);
2356 /* total size of all stream combined */
2357 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2358 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2363 /* Close snapshot element */
2364 ret
= mi_lttng_writer_close_element(writer
);
2370 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
2371 const char *current_session_name
, const char *url
,
2372 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
2376 /* Open element snapshot */
2377 ret
= mi_lttng_writer_open_element(writer
,
2378 mi_lttng_element_command_snapshot
);
2384 * If a valid an URL was given, serialize it,
2385 * else take the command line data and ctrl urls*/
2387 /* Destination of the output (ctrl_url)*/
2388 ret
= mi_lttng_writer_write_element_string(writer
,
2389 mi_lttng_element_snapshot_ctrl_url
, url
);
2393 } else if (cmdline_ctrl_url
) {
2394 /* Destination of the output (ctrl_url)*/
2395 ret
= mi_lttng_writer_write_element_string(writer
,
2396 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
2401 /* Destination of the output (data_url) */
2402 ret
= mi_lttng_writer_write_element_string(writer
,
2403 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
2409 /* Close record_snapshot element */
2410 ret
= mi_lttng_writer_close_element(writer
);
2416 int mi_lttng_rotation_schedule(struct mi_writer
*writer
,
2417 const struct lttng_rotation_schedule
*schedule
)
2420 enum lttng_rotation_status status
;
2422 const char *element_name
;
2423 const char *value_name
;
2424 bool empty_schedule
= false;
2426 switch (lttng_rotation_schedule_get_type(schedule
)) {
2427 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2428 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
2430 element_name
= mi_lttng_element_rotation_schedule_periodic
;
2431 value_name
= mi_lttng_element_rotation_schedule_periodic_time_us
;
2433 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2434 status
= lttng_rotation_schedule_size_threshold_get_threshold(
2436 element_name
= mi_lttng_element_rotation_schedule_size_threshold
;
2437 value_name
= mi_lttng_element_rotation_schedule_size_threshold_bytes
;
2444 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2445 if (status
== LTTNG_ROTATION_STATUS_UNAVAILABLE
) {
2446 empty_schedule
= true;
2453 ret
= mi_lttng_writer_open_element(writer
, element_name
);
2458 if (!empty_schedule
) {
2459 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2466 /* Close schedule descriptor element. */
2467 ret
= mi_lttng_writer_close_element(writer
);
2475 int mi_lttng_rotation_schedule_result(struct mi_writer
*writer
,
2476 const struct lttng_rotation_schedule
*schedule
,
2481 ret
= mi_lttng_writer_open_element(writer
,
2482 mi_lttng_element_rotation_schedule_result
);
2487 ret
= mi_lttng_writer_open_element(writer
,
2488 mi_lttng_element_rotation_schedule
);
2493 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
2498 /* Close rotation_schedule element */
2499 ret
= mi_lttng_writer_close_element(writer
);
2504 ret
= mi_lttng_writer_write_element_bool(writer
,
2505 mi_lttng_element_command_success
, success
);
2510 /* Close rotation_schedule_result element */
2511 ret
= mi_lttng_writer_close_element(writer
);
2520 int mi_lttng_location(struct mi_writer
*writer
,
2521 const struct lttng_trace_archive_location
*location
)
2524 enum lttng_trace_archive_location_type location_type
;
2525 enum lttng_trace_archive_location_status status
;
2527 location_type
= lttng_trace_archive_location_get_type(location
);
2529 switch (location_type
) {
2530 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
:
2532 const char *absolute_path
;
2534 status
= lttng_trace_archive_location_local_get_absolute_path(
2535 location
, &absolute_path
);
2536 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2541 ret
= mi_lttng_writer_open_element(writer
,
2542 mi_lttng_element_rotation_location_local
);
2548 ret
= mi_lttng_writer_write_element_string(writer
,
2549 mi_lttng_element_rotation_location_local_absolute_path
,
2555 /* Close local element */
2556 ret
= mi_lttng_writer_close_element(writer
);
2562 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
:
2564 uint16_t control_port
, data_port
;
2565 const char *host
, *relative_path
;
2566 enum lttng_trace_archive_location_relay_protocol_type protocol
;
2568 /* Fetch all relay location parameters. */
2569 status
= lttng_trace_archive_location_relay_get_protocol_type(
2570 location
, &protocol
);
2571 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2576 status
= lttng_trace_archive_location_relay_get_host(
2578 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2583 status
= lttng_trace_archive_location_relay_get_control_port(
2584 location
, &control_port
);
2585 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2590 status
= lttng_trace_archive_location_relay_get_data_port(
2591 location
, &data_port
);
2592 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2597 status
= lttng_trace_archive_location_relay_get_relative_path(
2598 location
, &relative_path
);
2599 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2604 ret
= mi_lttng_writer_open_element(writer
,
2605 mi_lttng_element_rotation_location_relay
);
2610 ret
= mi_lttng_writer_write_element_string(writer
,
2611 mi_lttng_element_rotation_location_relay_host
,
2617 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2618 mi_lttng_element_rotation_location_relay_control_port
,
2624 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2625 mi_lttng_element_rotation_location_relay_data_port
,
2631 ret
= mi_lttng_writer_write_element_string(writer
,
2632 mi_lttng_element_rotation_location_relay_protocol
,
2633 mi_lttng_trace_archive_location_relay_protocol_type_string(protocol
));
2638 ret
= mi_lttng_writer_write_element_string(writer
,
2639 mi_lttng_element_rotation_location_relay_relative_path
,
2645 /* Close relay element */
2646 ret
= mi_lttng_writer_close_element(writer
);
2659 int mi_lttng_rotate(struct mi_writer
*writer
,
2660 const char *session_name
,
2661 enum lttng_rotation_state rotation_state
,
2662 const struct lttng_trace_archive_location
*location
)
2666 ret
= mi_lttng_writer_open_element(writer
,
2667 mi_lttng_element_rotation
);
2672 ret
= mi_lttng_writer_write_element_string(writer
,
2673 mi_lttng_element_session_name
,
2679 ret
= mi_lttng_writer_write_element_string(writer
,
2680 mi_lttng_element_rotation_state
,
2681 mi_lttng_rotation_state_string(rotation_state
));
2687 /* Not a serialization error. */
2688 goto close_rotation
;
2691 ret
= mi_lttng_writer_open_element(writer
,
2692 mi_lttng_element_rotation_location
);
2697 ret
= mi_lttng_location(writer
, location
);
2699 goto close_location
;
2703 /* Close location element */
2704 ret
= mi_lttng_writer_close_element(writer
);
2710 /* Close rotation element */
2711 ret
= mi_lttng_writer_close_element(writer
);