2 * Copyright (C) 2014 Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * Copyright (C) 2014 Olivier Cotte <olivier.cotte@polymtl.ca>
4 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * SPDX-License-Identifier: GPL-2.0-only
10 #include "lttng/tracker.h"
13 #include <common/config/session-config.h>
14 #include <common/defaults.h>
15 #include <common/tracker.h>
16 #include <lttng/channel.h>
17 #include <lttng/snapshot-internal.h>
21 #define MI_SCHEMA_MAJOR_VERSION 4
22 #define MI_SCHEMA_MINOR_VERSION 0
24 /* Machine interface namespace URI */
25 LTTNG_HIDDEN
const char * const mi_lttng_xmlns
= "xmlns";
26 LTTNG_HIDDEN
const char * const mi_lttng_xmlns_xsi
= "xmlns:xsi";
27 LTTNG_HIDDEN
const char * const mi_lttng_w3_schema_uri
= "http://www.w3.org/2001/XMLSchema-instance";
28 LTTNG_HIDDEN
const char * const mi_lttng_schema_location
= "xsi:schemaLocation";
29 LTTNG_HIDDEN
const char * const mi_lttng_schema_location_uri
=
30 DEFAULT_LTTNG_MI_NAMESPACE
" "
31 "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION
)
32 "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION
) "."
33 XSTR(MI_SCHEMA_MINOR_VERSION
) ".xsd";
34 LTTNG_HIDDEN
const char * const mi_lttng_schema_version
= "schemaVersion";
35 LTTNG_HIDDEN
const char * const mi_lttng_schema_version_value
= XSTR(MI_SCHEMA_MAJOR_VERSION
)
36 "." XSTR(MI_SCHEMA_MINOR_VERSION
);
38 /* Strings related to command */
39 const char * const mi_lttng_element_command
= "command";
40 const char * const mi_lttng_element_command_action
= "snapshot_action";
41 const char * const mi_lttng_element_command_add_context
= "add-context";
42 const char *const mi_lttng_element_command_add_trigger
= "add-trigger";
43 const char * const mi_lttng_element_command_create
= "create";
44 const char * const mi_lttng_element_command_destroy
= "destroy";
45 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
46 const char * const mi_lttng_element_command_disable_event
= "disable-event";
47 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
48 const char * const mi_lttng_element_command_enable_event
= "enable-event";
49 const char * const mi_lttng_element_command_list
= "list";
50 const char *const mi_lttng_element_command_list_trigger
= "list-trigger";
51 const char * const mi_lttng_element_command_load
= "load";
52 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata
= "metadata";
53 LTTNG_HIDDEN
const char * const mi_lttng_element_command_metadata_action
= "metadata_action";
54 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate
= "regenerate";
55 LTTNG_HIDDEN
const char * const mi_lttng_element_command_regenerate_action
= "regenerate_action";
56 const char * const mi_lttng_element_command_name
= "name";
57 const char * const mi_lttng_element_command_output
= "output";
58 const char *const mi_lttng_element_command_remove_trigger
= "remove-trigger";
59 const char * const mi_lttng_element_command_save
= "save";
60 const char * const mi_lttng_element_command_set_session
= "set-session";
61 const char * const mi_lttng_element_command_snapshot
= "snapshot";
62 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
63 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
64 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
65 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
66 const char * const mi_lttng_element_command_start
= "start";
67 const char * const mi_lttng_element_command_stop
= "stop";
68 const char * const mi_lttng_element_command_success
= "success";
69 const char * const mi_lttng_element_command_track
= "track";
70 const char * const mi_lttng_element_command_untrack
= "untrack";
71 const char * const mi_lttng_element_command_version
= "version";
72 LTTNG_HIDDEN
const char * const mi_lttng_element_command_rotate
= "rotate";
73 LTTNG_HIDDEN
const char * const mi_lttng_element_command_enable_rotation
= "enable-rotation";
74 LTTNG_HIDDEN
const char * const mi_lttng_element_command_disable_rotation
= "disable-rotation";
75 LTTNG_HIDDEN
const char * const mi_lttng_element_command_clear
= "clear";
77 /* Strings related to version command */
78 const char * const mi_lttng_element_version
= "version";
79 const char * const mi_lttng_element_version_commit
= "commit";
80 const char * const mi_lttng_element_version_description
= "description";
81 const char * const mi_lttng_element_version_license
= "license";
82 const char * const mi_lttng_element_version_major
= "major";
83 const char * const mi_lttng_element_version_minor
= "minor";
84 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
85 const char * const mi_lttng_element_version_str
= "string";
86 const char * const mi_lttng_element_version_web
= "url";
88 /* String related to a lttng_event_field */
89 const char * const mi_lttng_element_event_field
= "event_field";
90 const char * const mi_lttng_element_event_fields
= "event_fields";
92 /* String related to lttng_event_perf_counter_ctx */
93 const char * const mi_lttng_element_perf_counter_context
= "perf";
95 /* Strings related to pid */
96 const char * const mi_lttng_element_pid_id
= "id";
98 /* Strings related to save command */
99 const char * const mi_lttng_element_save
= "save";
101 /* Strings related to load command */
102 const char * const mi_lttng_element_load
= "load";
103 LTTNG_HIDDEN
const char * const mi_lttng_element_load_overrides
= "overrides";
104 LTTNG_HIDDEN
const char * const mi_lttng_element_load_override_url
= "url";
106 /* General elements of mi_lttng */
107 const char * const mi_lttng_element_empty
= "";
108 const char * const mi_lttng_element_id
= "id";
109 const char * const mi_lttng_element_nowrite
= "nowrite";
110 const char * const mi_lttng_element_success
= "success";
111 const char * const mi_lttng_element_type_enum
= "ENUM";
112 const char * const mi_lttng_element_type_float
= "FLOAT";
113 const char * const mi_lttng_element_type_integer
= "INTEGER";
114 const char * const mi_lttng_element_type_other
= "OTHER";
115 const char * const mi_lttng_element_type_string
= "STRING";
117 /* String related to loglevel */
118 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
119 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
120 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
121 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
122 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
123 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
124 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
125 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
126 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
127 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
128 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
129 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
130 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
131 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
132 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
133 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
135 /* String related to loglevel JUL */
136 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
137 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
138 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
139 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
140 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
141 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
142 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
143 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
144 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
146 /* String related to loglevel LOG4J */
147 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
148 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
149 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
150 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
151 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
152 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
153 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
154 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
156 /* String related to loglevel Python */
157 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
158 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
159 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
160 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
161 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
162 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
164 /* String related to loglevel type */
165 const char * const mi_lttng_loglevel_type_all
= "ALL";
166 const char * const mi_lttng_loglevel_type_range
= "RANGE";
167 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
168 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
170 /* String related to a lttng_snapshot_output */
171 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
172 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
173 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
174 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
175 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
176 const char * const mi_lttng_element_snapshots
= "snapshots";
178 /* String related to track/untrack command */
179 const char * const mi_lttng_element_track_untrack_all_wildcard
= "*";
181 LTTNG_HIDDEN
const char * const mi_lttng_element_session_name
= "session_name";
183 /* String related to rotate command */
184 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation
= "rotation";
185 LTTNG_HIDDEN
const char * const mi_lttng_element_rotate_status
= "status";
186 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule
= "rotation_schedule";
187 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedules
= "rotation_schedules";
188 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_result
= "rotation_schedule_result";
189 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_results
= "rotation_schedule_results";
190 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_periodic
= "periodic";
191 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_periodic_time_us
= "time_us";
192 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_size_threshold
= "size_threshold";
193 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_schedule_size_threshold_bytes
= "bytes";
194 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_state
= "state";
195 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location
= "location";
196 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_local
= "local";
197 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_local_absolute_path
= "absolute_path";
198 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay
= "relay";
199 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_host
= "host";
200 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_control_port
= "control_port";
201 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_data_port
= "data_port";
202 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_protocol
= "protocol";
203 LTTNG_HIDDEN
const char * const mi_lttng_element_rotation_location_relay_relative_path
= "relative_path";
205 /* String related to enum lttng_rotation_state */
206 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_ongoing
= "ONGOING";
207 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_completed
= "COMPLETED";
208 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_expired
= "EXPIRED";
209 LTTNG_HIDDEN
const char * const mi_lttng_rotation_state_str_error
= "ERROR";
211 /* String related to enum lttng_trace_archive_location_relay_protocol_type */
212 LTTNG_HIDDEN
const char * const mi_lttng_rotation_location_relay_protocol_str_tcp
= "TCP";
214 /* String related to rate_policy elements */
215 LTTNG_HIDDEN
const char *const mi_lttng_element_rate_policy
= "rate_policy";
216 LTTNG_HIDDEN
const char *const mi_lttng_element_rate_policy_every_n
=
217 "rate_policy_every_n";
218 LTTNG_HIDDEN
const char *const mi_lttng_element_rate_policy_once_after_n
=
219 "rate_policy_once_after_n";
221 LTTNG_HIDDEN
const char *const mi_lttng_element_rate_policy_every_n_interval
=
223 LTTNG_HIDDEN
const char
224 *const mi_lttng_element_rate_policy_once_after_n_threshold
=
227 /* String related to action elements */
228 LTTNG_HIDDEN
const char *const mi_lttng_element_action
= "action";
229 LTTNG_HIDDEN
const char *const mi_lttng_element_action_list
= "action_list";
230 LTTNG_HIDDEN
const char *const mi_lttng_element_action_notify
= "action_notify";
231 LTTNG_HIDDEN
const char *const mi_lttng_element_action_start_session
=
232 "action_start_session";
233 LTTNG_HIDDEN
const char *const mi_lttng_element_action_stop_session
=
234 "action_stop_session";
235 LTTNG_HIDDEN
const char *const mi_lttng_element_action_rotate_session
=
236 "action_rotate_session";
237 LTTNG_HIDDEN
const char *const mi_lttng_element_action_snapshot_session
=
238 "action_snapshot_session";
239 LTTNG_HIDDEN
const char *const mi_lttng_element_action_snapshot_session_output
=
242 /* String related to condition */
243 LTTNG_HIDDEN
const char *const mi_lttng_element_condition
= "condition";
244 LTTNG_HIDDEN
const char *const mi_lttng_element_condition_buffer_usage_high
=
245 "condition_buffer_usage_high";
246 LTTNG_HIDDEN
const char *const mi_lttng_element_condition_buffer_usage_low
=
247 "condition_buffer_usage_low";
248 LTTNG_HIDDEN
const char *const mi_lttng_element_condition_event_rule_matches
=
249 "condition_event_rule_matches";
250 LTTNG_HIDDEN
const char *const mi_lttng_element_condition_session_consumed_size
=
251 "condition_session_consumed_size";
252 LTTNG_HIDDEN
const char *const mi_lttng_element_condition_session_rotation
=
253 "condition_session_rotation";
254 LTTNG_HIDDEN
const char
255 *const mi_lttng_element_condition_session_rotation_completed
=
256 "condition_session_rotation_completed";
257 LTTNG_HIDDEN
const char
258 *const mi_lttng_element_condition_session_rotation_ongoing
=
259 "condition_session_rotation_ongoing";
261 LTTNG_HIDDEN
const char *const mi_lttng_element_condition_channel_name
=
263 LTTNG_HIDDEN
const char *const mi_lttng_element_condition_threshold_bytes
=
265 LTTNG_HIDDEN
const char *const mi_lttng_element_condition_threshold_ratio
=
268 /* String related to capture descriptor */
269 LTTNG_HIDDEN
const char *const mi_lttng_element_capture_descriptor
=
270 "capture_descriptor";
271 LTTNG_HIDDEN
const char *const mi_lttng_element_capture_descriptors
=
272 "capture_descriptors";
274 /* String related to event expression */
275 LTTNG_HIDDEN
const char *const mi_lttng_element_event_expr
= "event_expr";
276 LTTNG_HIDDEN
const char *const mi_lttng_element_event_expr_payload_field
=
277 "event_expr_payload_field";
278 LTTNG_HIDDEN
const char *const mi_lttng_element_event_expr_channel_context_field
=
279 "event_expr_channel_context_field";
280 LTTNG_HIDDEN
const char
281 *const mi_lttng_element_event_expr_app_specific_context_field
=
282 "event_expr_app_specific_context_field";
283 LTTNG_HIDDEN
const char *const mi_lttng_element_event_expr_array_field_element
=
284 "event_expr_array_field_element";
285 LTTNG_HIDDEN
const char *const mi_lttng_element_event_expr_provider_name
=
287 LTTNG_HIDDEN
const char *const mi_lttng_element_event_expr_type_name
=
289 LTTNG_HIDDEN
const char *const mi_lttng_element_event_expr_index
= "index";
291 /* String related to event rule */
292 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule
= "event_rule";
294 /* String related to lttng_event_rule_type */
295 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_event_name
=
297 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_name_pattern
=
299 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_filter_expression
=
302 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_jul_logging
=
303 "event_rule_jul_logging";
304 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_kernel_kprobe
=
305 "event_rule_kernel_kprobe";
306 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_kernel_syscall
=
307 "event_rule_kernel_syscall";
308 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_kernel_tracepoint
=
309 "event_rule_kernel_tracepoint";
310 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_kernel_uprobe
=
311 "event_rule_kernel_uprobe";
312 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_log4j_logging
=
313 "event_rule_log4j_logging";
314 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_python_logging
=
315 "event_rule_python_logging";
316 LTTNG_HIDDEN
const char *const mi_lttng_element_event_rule_user_tracepoint
=
317 "event_rule_user_tracepoint";
319 /* String related to lttng_event_rule_kernel_syscall. */
320 LTTNG_HIDDEN
const char *const
321 mi_lttng_element_event_rule_kernel_syscall_emission_site
=
324 /* String related to enum lttng_event_rule_kernel_syscall_emission_site. */
325 LTTNG_HIDDEN
const char *const
326 mi_lttng_event_rule_kernel_syscall_emission_site_entry_exit
=
328 LTTNG_HIDDEN
const char
329 *const mi_lttng_event_rule_kernel_syscall_emission_site_entry
=
331 LTTNG_HIDDEN
const char *const
332 mi_lttng_event_rule_kernel_syscall_emission_site_exit
= "exit";
334 /* String related to lttng_event_rule_user_tracepoint */
335 LTTNG_HIDDEN
const char *const
336 mi_lttng_element_event_rule_user_tracepoint_name_pattern_exclusions
=
337 "name_pattern_exclusions";
338 LTTNG_HIDDEN
const char *const
339 mi_lttng_element_event_rule_user_tracepoint_name_pattern_exclusion
=
340 "name_pattern_exclusion";
342 /* String related to log level rule. */
343 LTTNG_HIDDEN
const char *const mi_lttng_element_log_level_rule
=
345 LTTNG_HIDDEN
const char *const mi_lttng_element_log_level_rule_exactly
=
346 "log_level_rule_exactly";
347 LTTNG_HIDDEN
const char
348 *const mi_lttng_element_log_level_rule_at_least_as_severe_as
=
349 "log_level_rule_at_least_as_severe_as";
350 LTTNG_HIDDEN
const char *const mi_lttng_element_log_level_rule_level
= "level";
352 /* String related to kernel probe location. */
353 LTTNG_HIDDEN
const char *const mi_lttng_element_kernel_probe_location
=
354 "kernel_probe_location";
355 LTTNG_HIDDEN
const char
356 *const mi_lttng_element_kernel_probe_location_symbol_offset
=
357 "kernel_probe_location_symbol_offset";
358 LTTNG_HIDDEN
const char *const
359 mi_lttng_element_kernel_probe_location_symbol_offset_name
=
361 LTTNG_HIDDEN
const char *const
362 mi_lttng_element_kernel_probe_location_symbol_offset_offset
=
365 LTTNG_HIDDEN
const char *const mi_lttng_element_kernel_probe_location_address
=
366 "kernel_probe_location_address";
367 LTTNG_HIDDEN
const char
368 *const mi_lttng_element_kernel_probe_location_address_address
=
371 /* String related to userspace probe location. */
372 LTTNG_HIDDEN
const char *const mi_lttng_element_userspace_probe_location
=
373 "userspace_probe_location";
374 LTTNG_HIDDEN
const char
375 *const mi_lttng_element_userspace_probe_location_binary_path
=
377 LTTNG_HIDDEN
const char
378 *const mi_lttng_element_userspace_probe_location_function
=
379 "userspace_probe_location_function";
380 LTTNG_HIDDEN
const char
381 *const mi_lttng_element_userspace_probe_location_function_name
=
383 LTTNG_HIDDEN
const char
384 *const mi_lttng_element_userspace_probe_location_lookup_method
=
385 "userspace_probe_location_lookup_method";
386 LTTNG_HIDDEN
const char *const
387 mi_lttng_element_userspace_probe_location_lookup_method_function_default
=
388 "userspace_probe_location_lookup_method_function_default";
389 LTTNG_HIDDEN
const char *const
390 mi_lttng_element_userspace_probe_location_lookup_method_function_elf
=
391 "userspace_probe_location_lookup_method_function_elf";
392 LTTNG_HIDDEN
const char *const
393 mi_lttng_element_userspace_probe_location_lookup_method_tracepoint_sdt
=
394 "userspace_probe_location_lookup_method_tracepoint_sdt";
395 LTTNG_HIDDEN
const char
396 *const mi_lttng_element_userspace_probe_location_tracepoint
=
397 "userspace_probe_location_tracepoint";
398 LTTNG_HIDDEN
const char *const
399 mi_lttng_element_userspace_probe_location_tracepoint_probe_name
=
401 LTTNG_HIDDEN
const char *const
402 mi_lttng_element_userspace_probe_location_tracepoint_provider_name
=
405 /* String related to enum
406 * lttng_userspace_probe_location_function_instrumentation_type */
407 LTTNG_HIDDEN
const char *const
408 mi_lttng_element_userspace_probe_location_function_instrumentation_type
=
409 "instrumentation_type";
410 LTTNG_HIDDEN
const char *const
411 mi_lttng_userspace_probe_location_function_instrumentation_type_entry
=
414 /* String related to trigger */
415 LTTNG_HIDDEN
const char *const mi_lttng_element_triggers
= "triggers";
416 LTTNG_HIDDEN
const char *const mi_lttng_element_trigger
= "trigger";
417 LTTNG_HIDDEN
const char *const mi_lttng_element_trigger_owner_uid
= "owner_uid";
419 /* String related to error_query. */
420 LTTNG_HIDDEN
const char *const mi_lttng_element_error_query_result
=
421 "error_query_result";
422 LTTNG_HIDDEN
const char *const mi_lttng_element_error_query_result_counter
=
423 "error_query_result_counter";
424 LTTNG_HIDDEN
const char *const
425 mi_lttng_element_error_query_result_counter_value
= "value";
426 LTTNG_HIDDEN
const char *const mi_lttng_element_error_query_result_description
=
428 LTTNG_HIDDEN
const char *const mi_lttng_element_error_query_result_name
=
430 LTTNG_HIDDEN
const char *const mi_lttng_element_error_query_result_type
=
432 LTTNG_HIDDEN
const char *const mi_lttng_element_error_query_results
=
433 "error_query_results";
435 /* String related to add-context command */
436 LTTNG_HIDDEN
const char * const mi_lttng_element_context_symbol
= "symbol";
438 /* Deprecated symbols preserved for ABI compatibility. */
439 const char * const mi_lttng_context_type_perf_counter
;
440 const char * const mi_lttng_context_type_perf_cpu_counter
;
441 const char * const mi_lttng_context_type_perf_thread_counter
;
442 const char * const mi_lttng_element_track_untrack_pid_target
;
443 const char * const mi_lttng_element_track_untrack_targets
;
444 const char * const mi_lttng_element_calibrate
;
445 const char * const mi_lttng_element_calibrate_function
;
446 const char * const mi_lttng_element_command_calibrate
;
448 /* This is a merge of jul loglevel and regular loglevel
449 * Those should never overlap by definition
450 * (see struct lttng_event loglevel)
453 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
456 case LTTNG_DOMAIN_KERNEL
:
457 case LTTNG_DOMAIN_UST
:
460 return mi_lttng_element_empty
;
461 case LTTNG_LOGLEVEL_EMERG
:
462 return mi_lttng_loglevel_str_emerg
;
463 case LTTNG_LOGLEVEL_ALERT
:
464 return mi_lttng_loglevel_str_alert
;
465 case LTTNG_LOGLEVEL_CRIT
:
466 return mi_lttng_loglevel_str_crit
;
467 case LTTNG_LOGLEVEL_ERR
:
468 return mi_lttng_loglevel_str_err
;
469 case LTTNG_LOGLEVEL_WARNING
:
470 return mi_lttng_loglevel_str_warning
;
471 case LTTNG_LOGLEVEL_NOTICE
:
472 return mi_lttng_loglevel_str_notice
;
473 case LTTNG_LOGLEVEL_INFO
:
474 return mi_lttng_loglevel_str_info
;
475 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
476 return mi_lttng_loglevel_str_debug_system
;
477 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
478 return mi_lttng_loglevel_str_debug_program
;
479 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
480 return mi_lttng_loglevel_str_debug_process
;
481 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
482 return mi_lttng_loglevel_str_debug_module
;
483 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
484 return mi_lttng_loglevel_str_debug_unit
;
485 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
486 return mi_lttng_loglevel_str_debug_function
;
487 case LTTNG_LOGLEVEL_DEBUG_LINE
:
488 return mi_lttng_loglevel_str_debug_line
;
489 case LTTNG_LOGLEVEL_DEBUG
:
490 return mi_lttng_loglevel_str_debug
;
492 return mi_lttng_loglevel_str_unknown
;
495 case LTTNG_DOMAIN_LOG4J
:
498 return mi_lttng_element_empty
;
499 case LTTNG_LOGLEVEL_LOG4J_OFF
:
500 return mi_lttng_loglevel_str_log4j_off
;
501 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
502 return mi_lttng_loglevel_str_log4j_fatal
;
503 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
504 return mi_lttng_loglevel_str_log4j_error
;
505 case LTTNG_LOGLEVEL_LOG4J_WARN
:
506 return mi_lttng_loglevel_str_log4j_warn
;
507 case LTTNG_LOGLEVEL_LOG4J_INFO
:
508 return mi_lttng_loglevel_str_log4j_info
;
509 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
510 return mi_lttng_loglevel_str_log4j_debug
;
511 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
512 return mi_lttng_loglevel_str_log4j_trace
;
513 case LTTNG_LOGLEVEL_LOG4J_ALL
:
514 return mi_lttng_loglevel_str_log4j_all
;
516 return mi_lttng_loglevel_str_unknown
;
519 case LTTNG_DOMAIN_JUL
:
522 return mi_lttng_element_empty
;
523 case LTTNG_LOGLEVEL_JUL_OFF
:
524 return mi_lttng_loglevel_str_jul_off
;
525 case LTTNG_LOGLEVEL_JUL_SEVERE
:
526 return mi_lttng_loglevel_str_jul_severe
;
527 case LTTNG_LOGLEVEL_JUL_WARNING
:
528 return mi_lttng_loglevel_str_jul_warning
;
529 case LTTNG_LOGLEVEL_JUL_INFO
:
530 return mi_lttng_loglevel_str_jul_info
;
531 case LTTNG_LOGLEVEL_JUL_CONFIG
:
532 return mi_lttng_loglevel_str_jul_config
;
533 case LTTNG_LOGLEVEL_JUL_FINE
:
534 return mi_lttng_loglevel_str_jul_fine
;
535 case LTTNG_LOGLEVEL_JUL_FINER
:
536 return mi_lttng_loglevel_str_jul_finer
;
537 case LTTNG_LOGLEVEL_JUL_FINEST
:
538 return mi_lttng_loglevel_str_jul_finest
;
539 case LTTNG_LOGLEVEL_JUL_ALL
:
540 return mi_lttng_loglevel_str_jul_all
;
542 return mi_lttng_loglevel_str_unknown
;
545 case LTTNG_DOMAIN_PYTHON
:
547 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
548 return mi_lttng_loglevel_str_python_critical
;
549 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
550 return mi_lttng_loglevel_str_python_error
;
551 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
552 return mi_lttng_loglevel_str_python_warning
;
553 case LTTNG_LOGLEVEL_PYTHON_INFO
:
554 return mi_lttng_loglevel_str_python_info
;
555 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
556 return mi_lttng_loglevel_str_python_debug
;
557 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
558 return mi_lttng_loglevel_str_python_notset
;
560 return mi_lttng_loglevel_str_unknown
;
564 return mi_lttng_loglevel_str_unknown
;
569 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
572 case LTTNG_EVENT_LOGLEVEL_ALL
:
573 return mi_lttng_loglevel_type_all
;
574 case LTTNG_EVENT_LOGLEVEL_RANGE
:
575 return mi_lttng_loglevel_type_range
;
576 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
577 return mi_lttng_loglevel_type_single
;
579 return mi_lttng_loglevel_type_unknown
;
584 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
587 case LTTNG_EVENT_ALL
:
588 return config_event_type_all
;
589 case LTTNG_EVENT_TRACEPOINT
:
590 return config_event_type_tracepoint
;
591 case LTTNG_EVENT_PROBE
:
592 return config_event_type_probe
;
593 case LTTNG_EVENT_USERSPACE_PROBE
:
594 return config_event_type_userspace_probe
;
595 case LTTNG_EVENT_FUNCTION
:
596 return config_event_type_function
;
597 case LTTNG_EVENT_FUNCTION_ENTRY
:
598 return config_event_type_function_entry
;
599 case LTTNG_EVENT_SYSCALL
:
600 return config_event_type_syscall
;
601 case LTTNG_EVENT_NOOP
:
602 return config_event_type_noop
;
604 return mi_lttng_element_empty
;
609 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
612 case LTTNG_EVENT_CONTEXT_PID
:
613 return config_event_context_pid
;
614 case LTTNG_EVENT_CONTEXT_PROCNAME
:
615 return config_event_context_procname
;
616 case LTTNG_EVENT_CONTEXT_PRIO
:
617 return config_event_context_prio
;
618 case LTTNG_EVENT_CONTEXT_NICE
:
619 return config_event_context_nice
;
620 case LTTNG_EVENT_CONTEXT_VPID
:
621 return config_event_context_vpid
;
622 case LTTNG_EVENT_CONTEXT_TID
:
623 return config_event_context_tid
;
624 case LTTNG_EVENT_CONTEXT_VTID
:
625 return config_event_context_vtid
;
626 case LTTNG_EVENT_CONTEXT_PPID
:
627 return config_event_context_ppid
;
628 case LTTNG_EVENT_CONTEXT_VPPID
:
629 return config_event_context_vppid
;
630 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
631 return config_event_context_pthread_id
;
632 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
633 return config_event_context_hostname
;
634 case LTTNG_EVENT_CONTEXT_IP
:
635 return config_event_context_ip
;
636 case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE
:
637 return config_event_context_interruptible
;
638 case LTTNG_EVENT_CONTEXT_PREEMPTIBLE
:
639 return config_event_context_preemptible
;
640 case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE
:
641 return config_event_context_need_reschedule
;
642 case LTTNG_EVENT_CONTEXT_MIGRATABLE
:
643 return config_event_context_migratable
;
644 case LTTNG_EVENT_CONTEXT_CALLSTACK_USER
:
645 return config_event_context_callstack_user
;
646 case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL
:
647 return config_event_context_callstack_kernel
;
648 case LTTNG_EVENT_CONTEXT_CGROUP_NS
:
649 return config_event_context_cgroup_ns
;
650 case LTTNG_EVENT_CONTEXT_IPC_NS
:
651 return config_event_context_ipc_ns
;
652 case LTTNG_EVENT_CONTEXT_MNT_NS
:
653 return config_event_context_mnt_ns
;
654 case LTTNG_EVENT_CONTEXT_NET_NS
:
655 return config_event_context_net_ns
;
656 case LTTNG_EVENT_CONTEXT_PID_NS
:
657 return config_event_context_pid_ns
;
658 case LTTNG_EVENT_CONTEXT_TIME_NS
:
659 return config_event_context_time_ns
;
660 case LTTNG_EVENT_CONTEXT_USER_NS
:
661 return config_event_context_user_ns
;
662 case LTTNG_EVENT_CONTEXT_UTS_NS
:
663 return config_event_context_uts_ns
;
664 case LTTNG_EVENT_CONTEXT_UID
:
665 return config_event_context_uid
;
666 case LTTNG_EVENT_CONTEXT_EUID
:
667 return config_event_context_euid
;
668 case LTTNG_EVENT_CONTEXT_SUID
:
669 return config_event_context_suid
;
670 case LTTNG_EVENT_CONTEXT_GID
:
671 return config_event_context_gid
;
672 case LTTNG_EVENT_CONTEXT_EGID
:
673 return config_event_context_egid
;
674 case LTTNG_EVENT_CONTEXT_SGID
:
675 return config_event_context_sgid
;
676 case LTTNG_EVENT_CONTEXT_VUID
:
677 return config_event_context_vuid
;
678 case LTTNG_EVENT_CONTEXT_VEUID
:
679 return config_event_context_veuid
;
680 case LTTNG_EVENT_CONTEXT_VSUID
:
681 return config_event_context_vsuid
;
682 case LTTNG_EVENT_CONTEXT_VGID
:
683 return config_event_context_vgid
;
684 case LTTNG_EVENT_CONTEXT_VEGID
:
685 return config_event_context_vegid
;
686 case LTTNG_EVENT_CONTEXT_VSGID
:
687 return config_event_context_vsgid
;
694 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
697 case(LTTNG_EVENT_FIELD_INTEGER
):
698 return mi_lttng_element_type_integer
;
699 case(LTTNG_EVENT_FIELD_ENUM
):
700 return mi_lttng_element_type_enum
;
701 case(LTTNG_EVENT_FIELD_FLOAT
):
702 return mi_lttng_element_type_float
;
703 case(LTTNG_EVENT_FIELD_STRING
):
704 return mi_lttng_element_type_string
;
706 return mi_lttng_element_type_other
;
711 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
713 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
715 case LTTNG_DOMAIN_KERNEL
:
716 return config_domain_type_kernel
;
717 case LTTNG_DOMAIN_UST
:
718 return config_domain_type_ust
;
719 case LTTNG_DOMAIN_JUL
:
720 return config_domain_type_jul
;
721 case LTTNG_DOMAIN_LOG4J
:
722 return config_domain_type_log4j
;
723 case LTTNG_DOMAIN_PYTHON
:
724 return config_domain_type_python
;
726 /* Should not have an unknown domain */
733 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
736 case LTTNG_BUFFER_PER_PID
:
737 return config_buffer_type_per_pid
;
738 case LTTNG_BUFFER_PER_UID
:
739 return config_buffer_type_per_uid
;
740 case LTTNG_BUFFER_GLOBAL
:
741 return config_buffer_type_global
;
743 /* Should not have an unknow buffer type */
750 const char *mi_lttng_rotation_state_string(enum lttng_rotation_state value
)
753 case LTTNG_ROTATION_STATE_ONGOING
:
754 return mi_lttng_rotation_state_str_ongoing
;
755 case LTTNG_ROTATION_STATE_COMPLETED
:
756 return mi_lttng_rotation_state_str_completed
;
757 case LTTNG_ROTATION_STATE_EXPIRED
:
758 return mi_lttng_rotation_state_str_expired
;
759 case LTTNG_ROTATION_STATE_ERROR
:
760 return mi_lttng_rotation_state_str_error
;
762 /* Should not have an unknow rotation state. */
769 const char *mi_lttng_trace_archive_location_relay_protocol_type_string(
770 enum lttng_trace_archive_location_relay_protocol_type value
)
773 case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP
:
774 return mi_lttng_rotation_location_relay_protocol_str_tcp
;
776 /* Should not have an unknown relay protocol. */
783 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
785 struct mi_writer
*mi_writer
;
787 mi_writer
= zmalloc(sizeof(struct mi_writer
));
789 PERROR("zmalloc mi_writer_create");
792 if (mi_output_type
== LTTNG_MI_XML
) {
793 mi_writer
->writer
= config_writer_create(fd_output
, 0);
794 if (!mi_writer
->writer
) {
797 mi_writer
->type
= LTTNG_MI_XML
;
811 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
820 ret
= config_writer_destroy(writer
->writer
);
831 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
836 * A command is always the MI's root node, it must declare the current
837 * namespace and schema URIs and the schema's version.
839 ret
= config_writer_open_element(writer
->writer
,
840 mi_lttng_element_command
);
845 ret
= config_writer_write_attribute(writer
->writer
,
846 mi_lttng_xmlns
, DEFAULT_LTTNG_MI_NAMESPACE
);
851 ret
= config_writer_write_attribute(writer
->writer
,
852 mi_lttng_xmlns_xsi
, mi_lttng_w3_schema_uri
);
857 ret
= config_writer_write_attribute(writer
->writer
,
858 mi_lttng_schema_location
,
859 mi_lttng_schema_location_uri
);
864 ret
= config_writer_write_attribute(writer
->writer
,
865 mi_lttng_schema_version
,
866 mi_lttng_schema_version_value
);
871 ret
= mi_lttng_writer_write_element_string(writer
,
872 mi_lttng_element_command_name
, command
);
878 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
880 return mi_lttng_writer_close_element(writer
);
884 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
885 const char *element_name
)
887 return config_writer_open_element(writer
->writer
, element_name
);
891 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
893 return config_writer_close_element(writer
->writer
);
897 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
898 unsigned int nb_element
)
902 if (nb_element
< 1) {
906 for (i
= 0; i
< nb_element
; i
++) {
907 ret
= mi_lttng_writer_close_element(writer
);
917 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
918 const char *element_name
, uint64_t value
)
920 return config_writer_write_element_unsigned_int(writer
->writer
,
921 element_name
, value
);
925 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
926 const char *element_name
, int64_t value
)
928 return config_writer_write_element_signed_int(writer
->writer
,
929 element_name
, value
);
933 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
934 const char *element_name
, int value
)
936 return config_writer_write_element_bool(writer
->writer
,
937 element_name
, value
);
941 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
942 const char *element_name
, const char *value
)
944 return config_writer_write_element_string(writer
->writer
,
945 element_name
, value
);
949 int mi_lttng_writer_write_element_double(struct mi_writer
*writer
,
950 const char *element_name
,
953 return config_writer_write_element_double(
954 writer
->writer
, element_name
, value
);
958 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
959 const char *lttng_description
, const char *lttng_license
)
964 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
969 /* Version string (contain info like rc etc.) */
970 ret
= mi_lttng_writer_write_element_string(writer
,
971 mi_lttng_element_version_str
, version
->version
);
976 /* Major version number */
977 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
978 mi_lttng_element_version_major
, version
->version_major
);
983 /* Minor version number */
984 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
985 mi_lttng_element_version_minor
, version
->version_minor
);
990 /* Commit version number */
991 ret
= mi_lttng_writer_write_element_string(writer
,
992 mi_lttng_element_version_commit
, version
->version_commit
);
998 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
999 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
1004 /* Name of the version */
1005 ret
= mi_lttng_writer_write_element_string(writer
,
1006 config_element_name
, version
->version_name
);
1011 /* Description mostly related to beer... */
1012 ret
= mi_lttng_writer_write_element_string(writer
,
1013 mi_lttng_element_version_description
, lttng_description
);
1019 ret
= mi_lttng_writer_write_element_string(writer
,
1020 mi_lttng_element_version_web
, version
->package_url
);
1025 /* License: free as in free beer...no...*speech* */
1026 ret
= mi_lttng_writer_write_element_string(writer
,
1027 mi_lttng_element_version_license
, lttng_license
);
1032 /* Close version element */
1033 ret
= mi_lttng_writer_close_element(writer
);
1040 int mi_lttng_sessions_open(struct mi_writer
*writer
)
1042 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
1046 int mi_lttng_session(struct mi_writer
*writer
,
1047 struct lttng_session
*session
, int is_open
)
1053 /* Open sessions element */
1054 ret
= mi_lttng_writer_open_element(writer
,
1055 config_element_session
);
1060 /* Name of the session */
1061 ret
= mi_lttng_writer_write_element_string(writer
,
1062 config_element_name
, session
->name
);
1068 ret
= mi_lttng_writer_write_element_string(writer
,
1069 config_element_path
, session
->path
);
1075 ret
= mi_lttng_writer_write_element_bool(writer
,
1076 config_element_enabled
, session
->enabled
);
1082 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1083 config_element_snapshot_mode
, session
->snapshot_mode
);
1088 /* Live timer interval in usec */
1089 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1090 config_element_live_timer_interval
,
1091 session
->live_timer_interval
);
1097 /* Closing session element */
1098 ret
= mi_lttng_writer_close_element(writer
);
1106 int mi_lttng_domains_open(struct mi_writer
*writer
)
1108 return mi_lttng_writer_open_element(writer
, config_element_domains
);
1112 int mi_lttng_domain(struct mi_writer
*writer
,
1113 struct lttng_domain
*domain
, int is_open
)
1116 const char *str_domain
;
1117 const char *str_buffer
;
1121 /* Open domain element */
1122 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
1128 str_domain
= mi_lttng_domaintype_string(domain
->type
);
1129 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1136 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
1137 ret
= mi_lttng_writer_write_element_string(writer
,
1138 config_element_buffer_type
, str_buffer
);
1144 * This union is not currently used and was added for
1145 * future ust domain support.
1150 /* Closing domain element */
1151 ret
= mi_lttng_writer_close_element(writer
);
1160 int mi_lttng_channels_open(struct mi_writer
*writer
)
1162 return mi_lttng_writer_open_element(writer
, config_element_channels
);
1166 int mi_lttng_channel(struct mi_writer
*writer
,
1167 struct lttng_channel
*channel
, int is_open
)
1173 /* Opening channel element */
1174 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
1180 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1187 ret
= mi_lttng_writer_write_element_bool(writer
,
1188 config_element_enabled
, channel
->enabled
);
1194 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
1200 /* Closing channel element */
1201 ret
= mi_lttng_writer_close_element(writer
);
1211 int mi_lttng_channel_attr(struct mi_writer
*writer
,
1212 struct lttng_channel_attr
*attr
)
1215 struct lttng_channel
*chan
= caa_container_of(attr
,
1216 struct lttng_channel
, attr
);
1217 uint64_t discarded_events
, lost_packets
, monitor_timer_interval
;
1218 int64_t blocking_timeout
;
1222 ret
= lttng_channel_get_discarded_event_count(chan
, &discarded_events
);
1227 ret
= lttng_channel_get_lost_packet_count(chan
, &lost_packets
);
1232 ret
= lttng_channel_get_monitor_timer_interval(chan
,
1233 &monitor_timer_interval
);
1238 ret
= lttng_channel_get_blocking_timeout(chan
,
1244 /* Opening Attributes */
1245 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1251 ret
= mi_lttng_writer_write_element_string(writer
,
1252 config_element_overwrite_mode
,
1253 attr
->overwrite
? config_overwrite_mode_overwrite
:
1254 config_overwrite_mode_discard
);
1259 /* Sub buffer size in byte */
1260 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1261 config_element_subbuf_size
, attr
->subbuf_size
);
1266 /* Number of subbuffer (power of two) */
1267 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1268 config_element_num_subbuf
,
1274 /* Switch timer interval in usec */
1275 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1276 config_element_switch_timer_interval
,
1277 attr
->switch_timer_interval
);
1282 /* Read timer interval in usec */
1283 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1284 config_element_read_timer_interval
,
1285 attr
->read_timer_interval
);
1290 /* Monitor timer interval in usec */
1291 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1292 config_element_monitor_timer_interval
,
1293 monitor_timer_interval
);
1298 /* Retry timeout in usec */
1299 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1300 config_element_blocking_timeout
,
1307 ret
= mi_lttng_writer_write_element_string(writer
,
1308 config_element_output_type
,
1309 attr
->output
== LTTNG_EVENT_SPLICE
?
1310 config_output_type_splice
: config_output_type_mmap
);
1315 /* Tracefile size in bytes */
1316 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1317 config_element_tracefile_size
, attr
->tracefile_size
);
1322 /* Count of tracefiles */
1323 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1324 config_element_tracefile_count
,
1325 attr
->tracefile_count
);
1330 /* Live timer interval in usec*/
1331 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1332 config_element_live_timer_interval
,
1333 attr
->live_timer_interval
);
1338 /* Discarded events */
1339 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1340 config_element_discarded_events
,
1347 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1348 config_element_lost_packets
,
1354 /* Closing attributes */
1355 ret
= mi_lttng_writer_close_element(writer
);
1365 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
1366 struct lttng_event
*event
)
1369 const char *filter_expression
;
1371 /* Open event element */
1372 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
1378 ret
= mi_lttng_writer_write_element_string(writer
,
1379 config_element_name
, event
->name
);
1385 ret
= mi_lttng_writer_write_element_string(writer
,
1386 config_element_type
, mi_lttng_eventtype_string(event
->type
));
1391 /* Is event enabled */
1392 ret
= mi_lttng_writer_write_element_bool(writer
,
1393 config_element_enabled
, event
->enabled
);
1398 /* Event filter expression */
1399 ret
= lttng_event_get_filter_expression(event
, &filter_expression
);
1404 if (filter_expression
) {
1405 ret
= mi_lttng_writer_write_element_string(writer
,
1406 config_element_filter_expression
,
1417 static int write_event_exclusions(struct mi_writer
*writer
,
1418 struct lttng_event
*event
)
1422 int exclusion_count
;
1424 /* Open event exclusions */
1425 ret
= mi_lttng_writer_open_element(writer
, config_element_exclusions
);
1430 exclusion_count
= lttng_event_get_exclusion_name_count(event
);
1431 if (exclusion_count
< 0) {
1432 ret
= exclusion_count
;
1436 for (i
= 0; i
< exclusion_count
; i
++) {
1439 ret
= lttng_event_get_exclusion_name(event
, i
, &name
);
1441 /* Close exclusions */
1442 mi_lttng_writer_close_element(writer
);
1446 ret
= mi_lttng_writer_write_element_string(writer
,
1447 config_element_exclusion
, name
);
1449 /* Close exclusions */
1450 mi_lttng_writer_close_element(writer
);
1455 /* Close exclusions */
1456 ret
= mi_lttng_writer_close_element(writer
);
1463 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
1464 struct lttng_event
*event
, enum lttng_domain_type domain
)
1468 /* Event loglevel */
1469 ret
= mi_lttng_writer_write_element_string(writer
,
1470 config_element_loglevel
,
1471 mi_lttng_loglevel_string(event
->loglevel
, domain
));
1476 /* Log level type */
1477 ret
= mi_lttng_writer_write_element_string(writer
,
1478 config_element_loglevel_type
,
1479 mi_lttng_logleveltype_string(event
->loglevel_type
));
1484 /* Event exclusions */
1485 ret
= write_event_exclusions(writer
, event
);
1492 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1493 struct lttng_event
*event
)
1495 /* event exclusion filter */
1496 return write_event_exclusions(writer
, event
);
1500 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1501 struct lttng_event
*event
)
1505 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1510 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1515 if (event
->attr
.probe
.addr
!= 0) {
1516 /* event probe address */
1517 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1518 config_element_address
, event
->attr
.probe
.addr
);
1523 /* event probe offset */
1524 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1525 config_element_offset
, event
->attr
.probe
.offset
);
1530 /* event probe symbol_name */
1531 ret
= mi_lttng_writer_write_element_string(writer
,
1532 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1538 /* Close probe_attributes and attributes */
1539 ret
= mi_lttng_close_multi_element(writer
, 2);
1545 int mi_lttng_event_userspace_probe(struct mi_writer
*writer
,
1546 struct lttng_event
*event
)
1549 const struct lttng_userspace_probe_location
*location
;
1550 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
1551 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
1553 location
= lttng_event_get_userspace_probe_location(event
);
1555 ret
= -LTTNG_ERR_INVALID
;
1559 lookup_method
= lttng_userspace_probe_location_get_lookup_method(location
);
1560 if (!lookup_method
) {
1561 ret
= -LTTNG_ERR_INVALID
;
1565 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(lookup_method
);
1567 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1572 switch (lttng_userspace_probe_location_get_type(location
)) {
1573 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1575 const char *function_name
;
1576 const char *binary_path
;
1578 ret
= mi_lttng_writer_open_element(writer
,
1579 config_element_userspace_probe_function_attributes
);
1584 switch (lookup_type
) {
1585 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
1586 ret
= mi_lttng_writer_write_element_string(writer
,
1587 config_element_userspace_probe_lookup
,
1588 config_element_userspace_probe_lookup_function_elf
);
1593 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
1594 ret
= mi_lttng_writer_write_element_string(writer
,
1595 config_element_userspace_probe_lookup
,
1596 config_element_userspace_probe_lookup_function_default
);
1605 binary_path
= lttng_userspace_probe_location_function_get_binary_path(location
);
1606 ret
= mi_lttng_writer_write_element_string(writer
,
1607 config_element_userspace_probe_location_binary_path
, binary_path
);
1612 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
1613 ret
= mi_lttng_writer_write_element_string(writer
,
1614 config_element_userspace_probe_function_location_function_name
,
1622 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1624 const char *probe_name
, *provider_name
;
1625 const char *binary_path
;
1627 ret
= mi_lttng_writer_open_element(writer
,
1628 config_element_userspace_probe_function_attributes
);
1633 switch (lookup_type
) {
1634 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
1635 ret
= mi_lttng_writer_write_element_string(writer
,
1636 config_element_userspace_probe_lookup
,
1637 config_element_userspace_probe_lookup_tracepoint_sdt
);
1646 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(location
);
1647 ret
= mi_lttng_writer_write_element_string(writer
,
1648 config_element_userspace_probe_location_binary_path
,
1654 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
1655 ret
= mi_lttng_writer_write_element_string(writer
,
1656 config_element_userspace_probe_tracepoint_location_provider_name
,
1662 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
1663 ret
= mi_lttng_writer_write_element_string(writer
,
1664 config_element_userspace_probe_tracepoint_location_probe_name
, probe_name
);
1671 ERR("Invalid probe type encountered");
1673 /* Close probe_attributes and attributes */
1674 ret
= mi_lttng_close_multi_element(writer
, 2);
1680 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1681 struct lttng_event
*event
)
1685 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1690 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1695 /* event probe symbol_name */
1696 ret
= mi_lttng_writer_write_element_string(writer
,
1697 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1702 /* Close function_attributes and attributes */
1703 ret
= mi_lttng_close_multi_element(writer
, 2);
1709 int mi_lttng_events_open(struct mi_writer
*writer
)
1711 return mi_lttng_writer_open_element(writer
, config_element_events
);
1715 int mi_lttng_event(struct mi_writer
*writer
,
1716 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1720 ret
= mi_lttng_event_common_attributes(writer
, event
);
1725 switch (event
->type
) {
1726 case LTTNG_EVENT_TRACEPOINT
:
1728 if (event
->loglevel
!= -1) {
1729 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1731 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1735 case LTTNG_EVENT_FUNCTION
:
1737 case LTTNG_EVENT_PROBE
:
1738 ret
= mi_lttng_event_function_probe(writer
, event
);
1740 case LTTNG_EVENT_FUNCTION_ENTRY
:
1741 ret
= mi_lttng_event_function_entry(writer
, event
);
1743 case LTTNG_EVENT_USERSPACE_PROBE
:
1744 ret
= mi_lttng_event_userspace_probe(writer
, event
);
1746 case LTTNG_EVENT_ALL
:
1757 ret
= mi_lttng_writer_close_element(writer
);
1765 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1767 return mi_lttng_writer_open_element(
1768 writer
, config_element_process_attr_trackers
);
1771 static int get_tracker_elements(enum lttng_process_attr process_attr
,
1772 const char **element_process_attr_tracker
,
1773 const char **element_process_attr_value
)
1777 switch (process_attr
) {
1778 case LTTNG_PROCESS_ATTR_PROCESS_ID
:
1779 *element_process_attr_tracker
=
1780 config_element_process_attr_tracker_pid
;
1781 *element_process_attr_value
=
1782 config_element_process_attr_pid_value
;
1784 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID
:
1785 *element_process_attr_tracker
=
1786 config_element_process_attr_tracker_vpid
;
1787 *element_process_attr_value
=
1788 config_element_process_attr_vpid_value
;
1790 case LTTNG_PROCESS_ATTR_USER_ID
:
1791 *element_process_attr_tracker
=
1792 config_element_process_attr_tracker_uid
;
1793 *element_process_attr_value
=
1794 config_element_process_attr_uid_value
;
1796 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID
:
1797 *element_process_attr_tracker
=
1798 config_element_process_attr_tracker_vuid
;
1799 *element_process_attr_value
=
1800 config_element_process_attr_vuid_value
;
1802 case LTTNG_PROCESS_ATTR_GROUP_ID
:
1803 *element_process_attr_tracker
=
1804 config_element_process_attr_tracker_gid
;
1805 *element_process_attr_value
=
1806 config_element_process_attr_gid_value
;
1808 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID
:
1809 *element_process_attr_tracker
=
1810 config_element_process_attr_tracker_vgid
;
1811 *element_process_attr_value
=
1812 config_element_process_attr_vgid_value
;
1815 ret
= LTTNG_ERR_SAVE_IO_FAIL
;
1821 int mi_lttng_process_attribute_tracker_open(
1822 struct mi_writer
*writer
, enum lttng_process_attr process_attr
)
1825 const char *element_tracker
, *element_value
;
1827 ret
= get_tracker_elements(
1828 process_attr
, &element_tracker
, &element_value
);
1833 /* Open process attribute tracker element */
1834 ret
= mi_lttng_writer_open_element(writer
, element_tracker
);
1839 /* Open values element */
1840 ret
= mi_lttng_process_attr_values_open(writer
);
1846 int mi_lttng_pids_open(struct mi_writer
*writer
)
1848 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1852 * TODO: move the listing of pid for user agent to process semantic on
1853 * mi api bump. The use of process element break the mi api.
1856 int mi_lttng_pid(struct mi_writer
*writer
,
1863 /* Open pid process */
1864 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1869 /* Writing pid number */
1870 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1871 mi_lttng_element_pid_id
, (int)pid
);
1876 /* Writing name of the process */
1878 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1887 ret
= mi_lttng_writer_close_element(writer
);
1895 int mi_lttng_process_attr_values_open(struct mi_writer
*writer
)
1897 return mi_lttng_writer_open_element(
1898 writer
, config_element_process_attr_values
);
1902 int mi_lttng_all_process_attribute_value(struct mi_writer
*writer
,
1903 enum lttng_process_attr process_attr
,
1907 const char *element_id_tracker
, *element_target_id
;
1909 ret
= get_tracker_elements(
1910 process_attr
, &element_id_tracker
, &element_target_id
);
1915 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1920 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1925 ret
= mi_lttng_writer_write_element_bool(writer
, config_element_all
, 1);
1930 ret
= mi_lttng_writer_close_element(writer
);
1936 ret
= mi_lttng_writer_close_element(writer
);
1946 int mi_lttng_integral_process_attribute_value(struct mi_writer
*writer
,
1947 enum lttng_process_attr process_attr
,
1952 const char *element_id_tracker
, *element_target_id
;
1954 ret
= get_tracker_elements(
1955 process_attr
, &element_id_tracker
, &element_target_id
);
1960 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
1965 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
1970 ret
= mi_lttng_writer_write_element_signed_int(
1971 writer
, config_element_process_attr_id
, value
);
1976 ret
= mi_lttng_writer_close_element(writer
);
1982 ret
= mi_lttng_writer_close_element(writer
);
1993 int mi_lttng_string_process_attribute_value(struct mi_writer
*writer
,
1994 enum lttng_process_attr process_attr
,
2000 const char *element_id_tracker
, *element_target_id
;
2002 ret
= get_tracker_elements(
2003 process_attr
, &element_id_tracker
, &element_target_id
);
2008 ret
= mi_lttng_writer_open_element(writer
, element_target_id
);
2013 ret
= mi_lttng_writer_open_element(writer
, config_element_type
);
2018 ret
= mi_lttng_writer_write_element_string(
2019 writer
, config_element_name
, value
);
2024 ret
= mi_lttng_writer_close_element(writer
);
2030 ret
= mi_lttng_writer_close_element(writer
);
2041 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
2043 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
2047 int mi_lttng_event_field(struct mi_writer
*writer
,
2048 struct lttng_event_field
*field
)
2052 if (!field
->field_name
[0]) {
2058 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
2063 if (!field
->field_name
[0]) {
2068 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2075 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
2076 mi_lttng_eventfieldtype_string(field
->type
));
2082 ret
= mi_lttng_writer_write_element_signed_int(writer
,
2083 mi_lttng_element_nowrite
, field
->nowrite
);
2089 /* Close field element */
2090 ret
= mi_lttng_writer_close_element(writer
);
2097 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
2098 struct lttng_event_perf_counter_ctx
*perf_context
)
2102 /* Open perf_counter_context */
2103 ret
= mi_lttng_writer_open_element(writer
,
2104 mi_lttng_element_perf_counter_context
);
2110 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2111 config_element_type
, perf_context
->type
);
2117 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2118 config_element_config
, perf_context
->config
);
2123 /* Name of the perf counter */
2124 ret
= mi_lttng_writer_write_element_string(writer
,
2125 config_element_name
, perf_context
->name
);
2130 /* Close perf_counter_context */
2131 ret
= mi_lttng_writer_close_element(writer
);
2137 int mi_lttng_app_context(struct mi_writer
*writer
,
2138 const char *provider_name
, const char *ctx_name
)
2143 ret
= mi_lttng_writer_open_element(writer
,
2144 config_element_context_app
);
2150 ret
= mi_lttng_writer_write_element_string(writer
,
2151 config_element_context_app_provider_name
,
2158 ret
= mi_lttng_writer_write_element_string(writer
,
2159 config_element_context_app_ctx_name
, ctx_name
);
2165 ret
= mi_lttng_writer_close_element(writer
);
2171 int mi_lttng_context(struct mi_writer
*writer
,
2172 struct lttng_event_context
*context
, int is_open
)
2177 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
2182 /* Special case for PERF_*_COUNTER
2183 * print the lttng_event_perf_counter_ctx*/
2184 switch (context
->ctx
) {
2185 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
2186 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
2187 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
2189 struct lttng_event_perf_counter_ctx
*perf_context
=
2190 &context
->u
.perf_counter
;
2191 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
2197 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
2199 ret
= mi_lttng_app_context(writer
,
2200 context
->u
.app_ctx
.provider_name
,
2201 context
->u
.app_ctx
.ctx_name
);
2209 const char *type_string
= mi_lttng_event_contexttype_string(
2212 ret
= -LTTNG_ERR_INVALID
;
2216 /* Print context type */
2217 ret
= mi_lttng_writer_write_element_string(writer
,
2218 config_element_type
, type_string
);
2225 ret
= mi_lttng_writer_close_element(writer
);
2233 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
2234 const char *session_name
)
2238 /* Open session element */
2239 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
2244 /* Snapshot output list for current session name */
2245 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2251 /* Open element snapshots (sequence one snapshot) */
2252 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
2262 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
2263 const struct lttng_snapshot_output
*output
)
2267 /* Open element snapshot output */
2268 ret
= mi_lttng_writer_open_element(writer
,
2269 mi_lttng_element_command_snapshot
);
2274 /* ID of the snapshot output */
2275 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2276 mi_lttng_element_id
, output
->id
);
2281 /* Name of the output */
2282 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2288 /* Destination of the output (ctrl_url)*/
2289 ret
= mi_lttng_writer_write_element_string(writer
,
2290 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2295 /* Destination of the output (data_url) */
2296 ret
= mi_lttng_writer_write_element_string(writer
,
2297 mi_lttng_element_snapshot_data_url
, output
->data_url
);
2302 /* total size of all stream combined */
2303 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2304 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2309 /* Close snapshot output element */
2310 ret
= mi_lttng_writer_close_element(writer
);
2317 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
2318 const char *name
, const char *current_session_name
)
2322 /* Open element del_snapshot */
2323 ret
= mi_lttng_writer_open_element(writer
,
2324 mi_lttng_element_command_snapshot
);
2330 if (id
!= UINT32_MAX
) {
2331 /* "Snapshot output "id" successfully deleted
2332 * for "current_session_name"
2333 * ID of the snapshot output
2335 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2336 mi_lttng_element_id
, id
);
2341 /* "Snapshot output "name" successfully deleted
2342 * for session "current_session_name"
2343 * Name of the output
2345 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
2352 /* Snapshot was deleted for session "current_session_name"*/
2353 ret
= mi_lttng_writer_write_element_string(writer
,
2354 mi_lttng_element_snapshot_session_name
,
2355 current_session_name
);
2360 /* Close snapshot element */
2361 ret
= mi_lttng_writer_close_element(writer
);
2368 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
2369 const char *current_session_name
, const char *n_ptr
,
2370 struct lttng_snapshot_output
*output
)
2374 /* Open element snapshot */
2375 ret
= mi_lttng_writer_open_element(writer
,
2376 mi_lttng_element_command_snapshot
);
2381 /* Snapshot output id */
2382 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2383 mi_lttng_element_id
, output
->id
);
2388 /* Snapshot output names */
2389 ret
= mi_lttng_writer_write_element_string(writer
,
2390 config_element_name
, n_ptr
);
2395 /* Destination of the output (ctrl_url)*/
2396 ret
= mi_lttng_writer_write_element_string(writer
,
2397 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
2402 /* Snapshot added for session "current_session_name"*/
2403 ret
= mi_lttng_writer_write_element_string(writer
,
2404 mi_lttng_element_snapshot_session_name
, current_session_name
);
2409 /* total size of all stream combined */
2410 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2411 mi_lttng_element_snapshot_max_size
, output
->max_size
);
2416 /* Close snapshot element */
2417 ret
= mi_lttng_writer_close_element(writer
);
2424 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
2425 const char *current_session_name
, const char *url
,
2426 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
2430 /* Open element snapshot */
2431 ret
= mi_lttng_writer_open_element(writer
,
2432 mi_lttng_element_command_snapshot
);
2438 * If a valid an URL was given, serialize it,
2439 * else take the command line data and ctrl urls*/
2441 /* Destination of the output (ctrl_url)*/
2442 ret
= mi_lttng_writer_write_element_string(writer
,
2443 mi_lttng_element_snapshot_ctrl_url
, url
);
2447 } else if (cmdline_ctrl_url
) {
2448 /* Destination of the output (ctrl_url)*/
2449 ret
= mi_lttng_writer_write_element_string(writer
,
2450 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
2455 /* Destination of the output (data_url) */
2456 ret
= mi_lttng_writer_write_element_string(writer
,
2457 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
2463 /* Close record_snapshot element */
2464 ret
= mi_lttng_writer_close_element(writer
);
2471 int mi_lttng_rotation_schedule(struct mi_writer
*writer
,
2472 const struct lttng_rotation_schedule
*schedule
)
2475 enum lttng_rotation_status status
;
2477 const char *element_name
;
2478 const char *value_name
;
2479 bool empty_schedule
= false;
2481 switch (lttng_rotation_schedule_get_type(schedule
)) {
2482 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC
:
2483 status
= lttng_rotation_schedule_periodic_get_period(schedule
,
2485 element_name
= mi_lttng_element_rotation_schedule_periodic
;
2486 value_name
= mi_lttng_element_rotation_schedule_periodic_time_us
;
2488 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD
:
2489 status
= lttng_rotation_schedule_size_threshold_get_threshold(
2491 element_name
= mi_lttng_element_rotation_schedule_size_threshold
;
2492 value_name
= mi_lttng_element_rotation_schedule_size_threshold_bytes
;
2499 if (status
!= LTTNG_ROTATION_STATUS_OK
) {
2500 if (status
== LTTNG_ROTATION_STATUS_UNAVAILABLE
) {
2501 empty_schedule
= true;
2508 ret
= mi_lttng_writer_open_element(writer
, element_name
);
2513 if (!empty_schedule
) {
2514 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2521 /* Close schedule descriptor element. */
2522 ret
= mi_lttng_writer_close_element(writer
);
2531 int mi_lttng_rotation_schedule_result(struct mi_writer
*writer
,
2532 const struct lttng_rotation_schedule
*schedule
,
2537 ret
= mi_lttng_writer_open_element(writer
,
2538 mi_lttng_element_rotation_schedule_result
);
2543 ret
= mi_lttng_writer_open_element(writer
,
2544 mi_lttng_element_rotation_schedule
);
2549 ret
= mi_lttng_rotation_schedule(writer
, schedule
);
2554 /* Close rotation_schedule element */
2555 ret
= mi_lttng_writer_close_element(writer
);
2560 ret
= mi_lttng_writer_write_element_bool(writer
,
2561 mi_lttng_element_command_success
, success
);
2566 /* Close rotation_schedule_result element */
2567 ret
= mi_lttng_writer_close_element(writer
);
2576 int mi_lttng_location(struct mi_writer
*writer
,
2577 const struct lttng_trace_archive_location
*location
)
2580 enum lttng_trace_archive_location_type location_type
;
2581 enum lttng_trace_archive_location_status status
;
2583 location_type
= lttng_trace_archive_location_get_type(location
);
2585 switch (location_type
) {
2586 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
:
2588 const char *absolute_path
;
2590 status
= lttng_trace_archive_location_local_get_absolute_path(
2591 location
, &absolute_path
);
2592 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2597 ret
= mi_lttng_writer_open_element(writer
,
2598 mi_lttng_element_rotation_location_local
);
2604 ret
= mi_lttng_writer_write_element_string(writer
,
2605 mi_lttng_element_rotation_location_local_absolute_path
,
2611 /* Close local element */
2612 ret
= mi_lttng_writer_close_element(writer
);
2618 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
:
2620 uint16_t control_port
, data_port
;
2621 const char *host
, *relative_path
;
2622 enum lttng_trace_archive_location_relay_protocol_type protocol
;
2624 /* Fetch all relay location parameters. */
2625 status
= lttng_trace_archive_location_relay_get_protocol_type(
2626 location
, &protocol
);
2627 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2632 status
= lttng_trace_archive_location_relay_get_host(
2634 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2639 status
= lttng_trace_archive_location_relay_get_control_port(
2640 location
, &control_port
);
2641 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2646 status
= lttng_trace_archive_location_relay_get_data_port(
2647 location
, &data_port
);
2648 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2653 status
= lttng_trace_archive_location_relay_get_relative_path(
2654 location
, &relative_path
);
2655 if (status
!= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
) {
2660 ret
= mi_lttng_writer_open_element(writer
,
2661 mi_lttng_element_rotation_location_relay
);
2666 ret
= mi_lttng_writer_write_element_string(writer
,
2667 mi_lttng_element_rotation_location_relay_host
,
2673 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2674 mi_lttng_element_rotation_location_relay_control_port
,
2680 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
2681 mi_lttng_element_rotation_location_relay_data_port
,
2687 ret
= mi_lttng_writer_write_element_string(writer
,
2688 mi_lttng_element_rotation_location_relay_protocol
,
2689 mi_lttng_trace_archive_location_relay_protocol_type_string(protocol
));
2694 ret
= mi_lttng_writer_write_element_string(writer
,
2695 mi_lttng_element_rotation_location_relay_relative_path
,
2701 /* Close relay element */
2702 ret
= mi_lttng_writer_close_element(writer
);
2716 int mi_lttng_rotate(struct mi_writer
*writer
,
2717 const char *session_name
,
2718 enum lttng_rotation_state rotation_state
,
2719 const struct lttng_trace_archive_location
*location
)
2723 ret
= mi_lttng_writer_open_element(writer
,
2724 mi_lttng_element_rotation
);
2729 ret
= mi_lttng_writer_write_element_string(writer
,
2730 mi_lttng_element_session_name
,
2736 ret
= mi_lttng_writer_write_element_string(writer
,
2737 mi_lttng_element_rotation_state
,
2738 mi_lttng_rotation_state_string(rotation_state
));
2744 /* Not a serialization error. */
2745 goto close_rotation
;
2748 ret
= mi_lttng_writer_open_element(writer
,
2749 mi_lttng_element_rotation_location
);
2754 ret
= mi_lttng_location(writer
, location
);
2756 goto close_location
;
2760 /* Close location element */
2761 ret
= mi_lttng_writer_close_element(writer
);
2767 /* Close rotation element */
2768 ret
= mi_lttng_writer_close_element(writer
);