Commit | Line | Data |
---|---|---|
c7e35b03 | 1 | /* |
4b2b86f2 | 2 | * Copyright (C) 2014 EfficiOS Inc. |
ab5be9fa | 3 | * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
c7e35b03 | 4 | * |
c922647d | 5 | * SPDX-License-Identifier: LGPL-2.1-only |
c7e35b03 | 6 | * |
c7e35b03 JR |
7 | */ |
8 | ||
159b042f | 9 | #include "lttng/tracker.h" |
6c1c0768 | 10 | #define _LGPL_SOURCE |
c9e313bc | 11 | #include "mi-lttng.hpp" |
28ab034a | 12 | |
c9e313bc SM |
13 | #include <common/config/session-config.hpp> |
14 | #include <common/defaults.hpp> | |
15 | #include <common/tracker.hpp> | |
28ab034a | 16 | |
fb83fe64 | 17 | #include <lttng/channel.h> |
c9e313bc | 18 | #include <lttng/snapshot-internal.hpp> |
c7e35b03 | 19 | |
a92b6bcc | 20 | #define MI_SCHEMA_MAJOR_VERSION 4 |
1f1f7e35 | 21 | #define MI_SCHEMA_MINOR_VERSION 1 |
e10b6a1c JG |
22 | |
23 | /* Machine interface namespace URI */ | |
28ab034a JG |
24 | const char *const mi_lttng_xmlns = "xmlns"; |
25 | const char *const mi_lttng_xmlns_xsi = "xmlns:xsi"; | |
26 | const char *const mi_lttng_w3_schema_uri = "http://www.w3.org/2001/XMLSchema-instance"; | |
27 | const char *const mi_lttng_schema_location = "xsi:schemaLocation"; | |
28 | const char *const mi_lttng_schema_location_uri = DEFAULT_LTTNG_MI_NAMESPACE | |
29 | " " | |
30 | "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION) "/lttng-mi-" XSTR( | |
31 | MI_SCHEMA_MAJOR_VERSION) "." XSTR(MI_SCHEMA_MINOR_VERSION) ".xsd"; | |
32 | const char *const mi_lttng_schema_version = "schemaVersion"; | |
33 | const char *const mi_lttng_schema_version_value = | |
34 | XSTR(MI_SCHEMA_MAJOR_VERSION) "." XSTR(MI_SCHEMA_MINOR_VERSION); | |
e10b6a1c | 35 | |
c7e35b03 | 36 | /* Strings related to command */ |
28ab034a JG |
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"; | |
6a751b95 | 40 | const char *const mi_lttng_element_command_add_trigger = "add-trigger"; |
28ab034a JG |
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"; | |
523c4f8c | 48 | const char *const mi_lttng_element_command_list_trigger = "list-trigger"; |
28ab034a JG |
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"; | |
6a751b95 | 56 | const char *const mi_lttng_element_command_remove_trigger = "remove-trigger"; |
28ab034a JG |
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"; | |
c7e35b03 | 74 | |
1734c658 | 75 | /* Strings related to version command */ |
28ab034a JG |
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"; | |
1734c658 | 85 | |
5e18ec73 | 86 | /* String related to a lttng_event_field */ |
28ab034a JG |
87 | const char *const mi_lttng_element_event_field = "event_field"; |
88 | const char *const mi_lttng_element_event_fields = "event_fields"; | |
5e18ec73 | 89 | |
89b72577 | 90 | /* String related to lttng_event_perf_counter_ctx */ |
28ab034a | 91 | const char *const mi_lttng_element_perf_counter_context = "perf"; |
89b72577 | 92 | |
f4a088f7 | 93 | /* Strings related to pid */ |
28ab034a | 94 | const char *const mi_lttng_element_pid_id = "id"; |
f4a088f7 JRJ |
95 | |
96 | /* Strings related to save command */ | |
28ab034a | 97 | const char *const mi_lttng_element_save = "save"; |
f4a088f7 JRJ |
98 | |
99 | /* Strings related to load command */ | |
28ab034a JG |
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"; | |
f4a088f7 | 103 | |
5e18ec73 | 104 | /* General elements of mi_lttng */ |
28ab034a JG |
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"; | |
5e18ec73 JR |
114 | |
115 | /* String related to loglevel */ | |
28ab034a JG |
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"; | |
5e18ec73 | 132 | |
136f2f81 | 133 | /* String related to loglevel JUL */ |
28ab034a JG |
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"; | |
136f2f81 | 143 | |
970d848b | 144 | /* String related to loglevel LOG4J */ |
28ab034a JG |
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"; | |
970d848b | 153 | |
0e115563 | 154 | /* String related to loglevel Python */ |
28ab034a JG |
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"; | |
0e115563 | 161 | |
1734c658 | 162 | /* String related to loglevel type */ |
28ab034a JG |
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"; | |
5e18ec73 | 167 | |
50534d6f | 168 | /* String related to a lttng_snapshot_output */ |
28ab034a JG |
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"; | |
5e18ec73 | 175 | |
ebbf5ab7 | 176 | /* String related to track/untrack command */ |
28ab034a | 177 | const char *const mi_lttng_element_track_untrack_all_wildcard = "*"; |
ebbf5ab7 | 178 | |
28ab034a | 179 | const char *const mi_lttng_element_session_name = "session_name"; |
d68c9a04 JD |
180 | |
181 | /* String related to rotate command */ | |
28ab034a JG |
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"; | |
91c4d516 JG |
202 | |
203 | /* String related to enum lttng_rotation_state */ | |
28ab034a JG |
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"; | |
91c4d516 JG |
208 | |
209 | /* String related to enum lttng_trace_archive_location_relay_protocol_type */ | |
28ab034a | 210 | const char *const mi_lttng_rotation_location_relay_protocol_str_tcp = "TCP"; |
d68c9a04 | 211 | |
6a751b95 | 212 | /* String related to rate_policy elements */ |
ca806b0b | 213 | const char *const mi_lttng_element_rate_policy = "rate_policy"; |
28ab034a JG |
214 | const char *const mi_lttng_element_rate_policy_every_n = "rate_policy_every_n"; |
215 | const char *const mi_lttng_element_rate_policy_once_after_n = "rate_policy_once_after_n"; | |
6a751b95 | 216 | |
28ab034a JG |
217 | const char *const mi_lttng_element_rate_policy_every_n_interval = "interval"; |
218 | const char *const mi_lttng_element_rate_policy_once_after_n_threshold = "threshold"; | |
6a751b95 JR |
219 | |
220 | /* String related to action elements */ | |
ca806b0b SM |
221 | const char *const mi_lttng_element_action = "action"; |
222 | const char *const mi_lttng_element_action_list = "action_list"; | |
223 | const char *const mi_lttng_element_action_notify = "action_notify"; | |
28ab034a JG |
224 | const char *const mi_lttng_element_action_start_session = "action_start_session"; |
225 | const char *const mi_lttng_element_action_stop_session = "action_stop_session"; | |
226 | const char *const mi_lttng_element_action_rotate_session = "action_rotate_session"; | |
227 | const char *const mi_lttng_element_action_snapshot_session = "action_snapshot_session"; | |
228 | const char *const mi_lttng_element_action_snapshot_session_output = "output"; | |
6a751b95 JR |
229 | |
230 | /* String related to condition */ | |
ca806b0b | 231 | const char *const mi_lttng_element_condition = "condition"; |
28ab034a JG |
232 | const char *const mi_lttng_element_condition_buffer_usage_high = "condition_buffer_usage_high"; |
233 | const char *const mi_lttng_element_condition_buffer_usage_low = "condition_buffer_usage_low"; | |
234 | const char *const mi_lttng_element_condition_event_rule_matches = "condition_event_rule_matches"; | |
ca806b0b | 235 | const char *const mi_lttng_element_condition_session_consumed_size = |
28ab034a JG |
236 | "condition_session_consumed_size"; |
237 | const char *const mi_lttng_element_condition_session_rotation = "condition_session_rotation"; | |
238 | const char *const mi_lttng_element_condition_session_rotation_completed = | |
239 | "condition_session_rotation_completed"; | |
240 | const char *const mi_lttng_element_condition_session_rotation_ongoing = | |
241 | "condition_session_rotation_ongoing"; | |
242 | ||
243 | const char *const mi_lttng_element_condition_channel_name = "channel_name"; | |
244 | const char *const mi_lttng_element_condition_threshold_bytes = "threshold_bytes"; | |
245 | const char *const mi_lttng_element_condition_threshold_ratio = "threshold_ratio"; | |
6a751b95 JR |
246 | |
247 | /* String related to capture descriptor */ | |
28ab034a JG |
248 | const char *const mi_lttng_element_capture_descriptor = "capture_descriptor"; |
249 | const char *const mi_lttng_element_capture_descriptors = "capture_descriptors"; | |
6a751b95 JR |
250 | |
251 | /* String related to event expression */ | |
ca806b0b | 252 | const char *const mi_lttng_element_event_expr = "event_expr"; |
28ab034a | 253 | const char *const mi_lttng_element_event_expr_payload_field = "event_expr_payload_field"; |
ca806b0b | 254 | const char *const mi_lttng_element_event_expr_channel_context_field = |
28ab034a JG |
255 | "event_expr_channel_context_field"; |
256 | const char *const mi_lttng_element_event_expr_app_specific_context_field = | |
257 | "event_expr_app_specific_context_field"; | |
ca806b0b | 258 | const char *const mi_lttng_element_event_expr_array_field_element = |
28ab034a JG |
259 | "event_expr_array_field_element"; |
260 | const char *const mi_lttng_element_event_expr_provider_name = "provider_name"; | |
261 | const char *const mi_lttng_element_event_expr_type_name = "type_name"; | |
ca806b0b | 262 | const char *const mi_lttng_element_event_expr_index = "index"; |
6a751b95 JR |
263 | |
264 | /* String related to event rule */ | |
ca806b0b | 265 | const char *const mi_lttng_element_event_rule = "event_rule"; |
6a751b95 JR |
266 | |
267 | /* String related to lttng_event_rule_type */ | |
28ab034a JG |
268 | const char *const mi_lttng_element_event_rule_event_name = "event_name"; |
269 | const char *const mi_lttng_element_event_rule_name_pattern = "name_pattern"; | |
270 | const char *const mi_lttng_element_event_rule_filter_expression = "filter_expression"; | |
271 | ||
272 | const char *const mi_lttng_element_event_rule_jul_logging = "event_rule_jul_logging"; | |
273 | const char *const mi_lttng_element_event_rule_kernel_kprobe = "event_rule_kernel_kprobe"; | |
274 | const char *const mi_lttng_element_event_rule_kernel_syscall = "event_rule_kernel_syscall"; | |
275 | const char *const mi_lttng_element_event_rule_kernel_tracepoint = "event_rule_kernel_tracepoint"; | |
276 | const char *const mi_lttng_element_event_rule_kernel_uprobe = "event_rule_kernel_uprobe"; | |
277 | const char *const mi_lttng_element_event_rule_log4j_logging = "event_rule_log4j_logging"; | |
278 | const char *const mi_lttng_element_event_rule_python_logging = "event_rule_python_logging"; | |
279 | const char *const mi_lttng_element_event_rule_user_tracepoint = "event_rule_user_tracepoint"; | |
6a751b95 JR |
280 | |
281 | /* String related to lttng_event_rule_kernel_syscall. */ | |
28ab034a | 282 | const char *const mi_lttng_element_event_rule_kernel_syscall_emission_site = "emission_site"; |
6a751b95 JR |
283 | |
284 | /* String related to enum lttng_event_rule_kernel_syscall_emission_site. */ | |
28ab034a JG |
285 | const char *const mi_lttng_event_rule_kernel_syscall_emission_site_entry_exit = "entry+exit"; |
286 | const char *const mi_lttng_event_rule_kernel_syscall_emission_site_entry = "entry"; | |
287 | const char *const mi_lttng_event_rule_kernel_syscall_emission_site_exit = "exit"; | |
6a751b95 JR |
288 | |
289 | /* String related to lttng_event_rule_user_tracepoint */ | |
28ab034a JG |
290 | const char *const mi_lttng_element_event_rule_user_tracepoint_name_pattern_exclusions = |
291 | "name_pattern_exclusions"; | |
292 | const char *const mi_lttng_element_event_rule_user_tracepoint_name_pattern_exclusion = | |
293 | "name_pattern_exclusion"; | |
6a751b95 JR |
294 | |
295 | /* String related to log level rule. */ | |
28ab034a JG |
296 | const char *const mi_lttng_element_log_level_rule = "log_level_rule"; |
297 | const char *const mi_lttng_element_log_level_rule_exactly = "log_level_rule_exactly"; | |
298 | const char *const mi_lttng_element_log_level_rule_at_least_as_severe_as = | |
299 | "log_level_rule_at_least_as_severe_as"; | |
ca806b0b | 300 | const char *const mi_lttng_element_log_level_rule_level = "level"; |
6a751b95 JR |
301 | |
302 | /* String related to kernel probe location. */ | |
28ab034a JG |
303 | const char *const mi_lttng_element_kernel_probe_location = "kernel_probe_location"; |
304 | const char *const mi_lttng_element_kernel_probe_location_symbol_offset = | |
305 | "kernel_probe_location_symbol_offset"; | |
306 | const char *const mi_lttng_element_kernel_probe_location_symbol_offset_name = "name"; | |
307 | const char *const mi_lttng_element_kernel_probe_location_symbol_offset_offset = "offset"; | |
308 | ||
309 | const char *const mi_lttng_element_kernel_probe_location_address = "kernel_probe_location_address"; | |
310 | const char *const mi_lttng_element_kernel_probe_location_address_address = "address"; | |
6a751b95 JR |
311 | |
312 | /* String related to userspace probe location. */ | |
28ab034a JG |
313 | const char *const mi_lttng_element_userspace_probe_location = "userspace_probe_location"; |
314 | const char *const mi_lttng_element_userspace_probe_location_binary_path = "binary_path"; | |
315 | const char *const mi_lttng_element_userspace_probe_location_function = | |
316 | "userspace_probe_location_function"; | |
317 | const char *const mi_lttng_element_userspace_probe_location_function_name = "name"; | |
318 | const char *const mi_lttng_element_userspace_probe_location_lookup_method = | |
319 | "userspace_probe_location_lookup_method"; | |
320 | const char *const mi_lttng_element_userspace_probe_location_lookup_method_function_default = | |
321 | "userspace_probe_location_lookup_method_function_default"; | |
322 | const char *const mi_lttng_element_userspace_probe_location_lookup_method_function_elf = | |
323 | "userspace_probe_location_lookup_method_function_elf"; | |
324 | const char *const mi_lttng_element_userspace_probe_location_lookup_method_tracepoint_sdt = | |
325 | "userspace_probe_location_lookup_method_tracepoint_sdt"; | |
326 | const char *const mi_lttng_element_userspace_probe_location_tracepoint = | |
327 | "userspace_probe_location_tracepoint"; | |
328 | const char *const mi_lttng_element_userspace_probe_location_tracepoint_probe_name = "probe_name"; | |
329 | const char *const mi_lttng_element_userspace_probe_location_tracepoint_provider_name = | |
330 | "provider_name"; | |
6a751b95 JR |
331 | |
332 | /* String related to enum | |
333 | * lttng_userspace_probe_location_function_instrumentation_type */ | |
28ab034a JG |
334 | const char *const mi_lttng_element_userspace_probe_location_function_instrumentation_type = |
335 | "instrumentation_type"; | |
336 | const char *const mi_lttng_userspace_probe_location_function_instrumentation_type_entry = "ENTRY"; | |
6a751b95 JR |
337 | |
338 | /* String related to trigger */ | |
ca806b0b SM |
339 | const char *const mi_lttng_element_triggers = "triggers"; |
340 | const char *const mi_lttng_element_trigger = "trigger"; | |
341 | const char *const mi_lttng_element_trigger_owner_uid = "owner_uid"; | |
6a751b95 JR |
342 | |
343 | /* String related to error_query. */ | |
28ab034a JG |
344 | const char *const mi_lttng_element_error_query_result = "error_query_result"; |
345 | const char *const mi_lttng_element_error_query_result_counter = "error_query_result_counter"; | |
346 | const char *const mi_lttng_element_error_query_result_counter_value = "value"; | |
347 | const char *const mi_lttng_element_error_query_result_description = "description"; | |
348 | const char *const mi_lttng_element_error_query_result_name = "name"; | |
349 | const char *const mi_lttng_element_error_query_result_type = "type"; | |
350 | const char *const mi_lttng_element_error_query_results = "error_query_results"; | |
6a751b95 | 351 | |
59deec0c | 352 | /* String related to add-context command */ |
28ab034a | 353 | const char *const mi_lttng_element_context_symbol = "symbol"; |
59deec0c | 354 | |
ae8c46e0 | 355 | /* Deprecated symbols preserved for ABI compatibility. */ |
a6bc4ca9 SM |
356 | LTTNG_EXPORT const char *mi_lttng_context_type_perf_counter; |
357 | LTTNG_EXPORT const char *mi_lttng_context_type_perf_cpu_counter; | |
358 | LTTNG_EXPORT const char *mi_lttng_context_type_perf_thread_counter; | |
359 | LTTNG_EXPORT const char *mi_lttng_element_track_untrack_pid_target; | |
360 | LTTNG_EXPORT const char *mi_lttng_element_track_untrack_targets; | |
361 | LTTNG_EXPORT const char *mi_lttng_element_calibrate; | |
362 | LTTNG_EXPORT const char *mi_lttng_element_calibrate_function; | |
363 | LTTNG_EXPORT const char *mi_lttng_element_command_calibrate; | |
ebbf5ab7 | 364 | |
136f2f81 JRJ |
365 | /* This is a merge of jul loglevel and regular loglevel |
366 | * Those should never overlap by definition | |
367 | * (see struct lttng_event loglevel) | |
368 | */ | |
970d848b | 369 | const char *mi_lttng_loglevel_string(int value, enum lttng_domain_type domain) |
5e18ec73 | 370 | { |
970d848b DG |
371 | switch (domain) { |
372 | case LTTNG_DOMAIN_KERNEL: | |
373 | case LTTNG_DOMAIN_UST: | |
374 | switch (value) { | |
375 | case -1: | |
376 | return mi_lttng_element_empty; | |
377 | case LTTNG_LOGLEVEL_EMERG: | |
378 | return mi_lttng_loglevel_str_emerg; | |
379 | case LTTNG_LOGLEVEL_ALERT: | |
380 | return mi_lttng_loglevel_str_alert; | |
381 | case LTTNG_LOGLEVEL_CRIT: | |
382 | return mi_lttng_loglevel_str_crit; | |
383 | case LTTNG_LOGLEVEL_ERR: | |
384 | return mi_lttng_loglevel_str_err; | |
385 | case LTTNG_LOGLEVEL_WARNING: | |
386 | return mi_lttng_loglevel_str_warning; | |
387 | case LTTNG_LOGLEVEL_NOTICE: | |
388 | return mi_lttng_loglevel_str_notice; | |
389 | case LTTNG_LOGLEVEL_INFO: | |
390 | return mi_lttng_loglevel_str_info; | |
391 | case LTTNG_LOGLEVEL_DEBUG_SYSTEM: | |
392 | return mi_lttng_loglevel_str_debug_system; | |
393 | case LTTNG_LOGLEVEL_DEBUG_PROGRAM: | |
394 | return mi_lttng_loglevel_str_debug_program; | |
395 | case LTTNG_LOGLEVEL_DEBUG_PROCESS: | |
396 | return mi_lttng_loglevel_str_debug_process; | |
397 | case LTTNG_LOGLEVEL_DEBUG_MODULE: | |
398 | return mi_lttng_loglevel_str_debug_module; | |
399 | case LTTNG_LOGLEVEL_DEBUG_UNIT: | |
400 | return mi_lttng_loglevel_str_debug_unit; | |
401 | case LTTNG_LOGLEVEL_DEBUG_FUNCTION: | |
402 | return mi_lttng_loglevel_str_debug_function; | |
403 | case LTTNG_LOGLEVEL_DEBUG_LINE: | |
404 | return mi_lttng_loglevel_str_debug_line; | |
405 | case LTTNG_LOGLEVEL_DEBUG: | |
406 | return mi_lttng_loglevel_str_debug; | |
407 | default: | |
408 | return mi_lttng_loglevel_str_unknown; | |
409 | } | |
410 | break; | |
411 | case LTTNG_DOMAIN_LOG4J: | |
412 | switch (value) { | |
413 | case -1: | |
414 | return mi_lttng_element_empty; | |
415 | case LTTNG_LOGLEVEL_LOG4J_OFF: | |
416 | return mi_lttng_loglevel_str_log4j_off; | |
417 | case LTTNG_LOGLEVEL_LOG4J_FATAL: | |
418 | return mi_lttng_loglevel_str_log4j_fatal; | |
419 | case LTTNG_LOGLEVEL_LOG4J_ERROR: | |
420 | return mi_lttng_loglevel_str_log4j_error; | |
421 | case LTTNG_LOGLEVEL_LOG4J_WARN: | |
422 | return mi_lttng_loglevel_str_log4j_warn; | |
423 | case LTTNG_LOGLEVEL_LOG4J_INFO: | |
424 | return mi_lttng_loglevel_str_log4j_info; | |
425 | case LTTNG_LOGLEVEL_LOG4J_DEBUG: | |
426 | return mi_lttng_loglevel_str_log4j_debug; | |
427 | case LTTNG_LOGLEVEL_LOG4J_TRACE: | |
428 | return mi_lttng_loglevel_str_log4j_trace; | |
429 | case LTTNG_LOGLEVEL_LOG4J_ALL: | |
430 | return mi_lttng_loglevel_str_log4j_all; | |
431 | default: | |
432 | return mi_lttng_loglevel_str_unknown; | |
433 | } | |
434 | break; | |
435 | case LTTNG_DOMAIN_JUL: | |
436 | switch (value) { | |
437 | case -1: | |
438 | return mi_lttng_element_empty; | |
439 | case LTTNG_LOGLEVEL_JUL_OFF: | |
440 | return mi_lttng_loglevel_str_jul_off; | |
441 | case LTTNG_LOGLEVEL_JUL_SEVERE: | |
442 | return mi_lttng_loglevel_str_jul_severe; | |
443 | case LTTNG_LOGLEVEL_JUL_WARNING: | |
444 | return mi_lttng_loglevel_str_jul_warning; | |
445 | case LTTNG_LOGLEVEL_JUL_INFO: | |
446 | return mi_lttng_loglevel_str_jul_info; | |
447 | case LTTNG_LOGLEVEL_JUL_CONFIG: | |
448 | return mi_lttng_loglevel_str_jul_config; | |
449 | case LTTNG_LOGLEVEL_JUL_FINE: | |
450 | return mi_lttng_loglevel_str_jul_fine; | |
451 | case LTTNG_LOGLEVEL_JUL_FINER: | |
452 | return mi_lttng_loglevel_str_jul_finer; | |
453 | case LTTNG_LOGLEVEL_JUL_FINEST: | |
454 | return mi_lttng_loglevel_str_jul_finest; | |
455 | case LTTNG_LOGLEVEL_JUL_ALL: | |
456 | return mi_lttng_loglevel_str_jul_all; | |
457 | default: | |
458 | return mi_lttng_loglevel_str_unknown; | |
459 | } | |
460 | break; | |
0e115563 DG |
461 | case LTTNG_DOMAIN_PYTHON: |
462 | switch (value) { | |
463 | case LTTNG_LOGLEVEL_PYTHON_CRITICAL: | |
464 | return mi_lttng_loglevel_str_python_critical; | |
465 | case LTTNG_LOGLEVEL_PYTHON_ERROR: | |
466 | return mi_lttng_loglevel_str_python_error; | |
467 | case LTTNG_LOGLEVEL_PYTHON_WARNING: | |
468 | return mi_lttng_loglevel_str_python_warning; | |
469 | case LTTNG_LOGLEVEL_PYTHON_INFO: | |
470 | return mi_lttng_loglevel_str_python_info; | |
471 | case LTTNG_LOGLEVEL_PYTHON_DEBUG: | |
472 | return mi_lttng_loglevel_str_python_debug; | |
473 | case LTTNG_LOGLEVEL_PYTHON_NOTSET: | |
474 | return mi_lttng_loglevel_str_python_notset; | |
475 | default: | |
476 | return mi_lttng_loglevel_str_unknown; | |
477 | } | |
478 | break; | |
bc2718d1 JG |
479 | default: |
480 | return mi_lttng_loglevel_str_unknown; | |
5e18ec73 JR |
481 | } |
482 | } | |
483 | ||
484 | const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value) | |
485 | { | |
486 | switch (value) { | |
487 | case LTTNG_EVENT_LOGLEVEL_ALL: | |
488 | return mi_lttng_loglevel_type_all; | |
489 | case LTTNG_EVENT_LOGLEVEL_RANGE: | |
490 | return mi_lttng_loglevel_type_range; | |
491 | case LTTNG_EVENT_LOGLEVEL_SINGLE: | |
492 | return mi_lttng_loglevel_type_single; | |
493 | default: | |
494 | return mi_lttng_loglevel_type_unknown; | |
495 | } | |
496 | } | |
497 | ||
28ab034a | 498 | static const char *mi_lttng_eventtype_string(enum lttng_event_type value) |
5e18ec73 JR |
499 | { |
500 | switch (value) { | |
501 | case LTTNG_EVENT_ALL: | |
502 | return config_event_type_all; | |
503 | case LTTNG_EVENT_TRACEPOINT: | |
504 | return config_event_type_tracepoint; | |
505 | case LTTNG_EVENT_PROBE: | |
506 | return config_event_type_probe; | |
5a1c0a75 FD |
507 | case LTTNG_EVENT_USERSPACE_PROBE: |
508 | return config_event_type_userspace_probe; | |
5e18ec73 JR |
509 | case LTTNG_EVENT_FUNCTION: |
510 | return config_event_type_function; | |
511 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
512 | return config_event_type_function_entry; | |
513 | case LTTNG_EVENT_SYSCALL: | |
514 | return config_event_type_syscall; | |
515 | case LTTNG_EVENT_NOOP: | |
516 | return config_event_type_noop; | |
517 | default: | |
518 | return mi_lttng_element_empty; | |
519 | } | |
520 | } | |
521 | ||
28ab034a | 522 | static const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val) |
89b72577 JRJ |
523 | { |
524 | switch (val) { | |
525 | case LTTNG_EVENT_CONTEXT_PID: | |
526 | return config_event_context_pid; | |
89b72577 JRJ |
527 | case LTTNG_EVENT_CONTEXT_PROCNAME: |
528 | return config_event_context_procname; | |
529 | case LTTNG_EVENT_CONTEXT_PRIO: | |
530 | return config_event_context_prio; | |
531 | case LTTNG_EVENT_CONTEXT_NICE: | |
532 | return config_event_context_nice; | |
533 | case LTTNG_EVENT_CONTEXT_VPID: | |
534 | return config_event_context_vpid; | |
535 | case LTTNG_EVENT_CONTEXT_TID: | |
536 | return config_event_context_tid; | |
537 | case LTTNG_EVENT_CONTEXT_VTID: | |
538 | return config_event_context_vtid; | |
539 | case LTTNG_EVENT_CONTEXT_PPID: | |
540 | return config_event_context_ppid; | |
541 | case LTTNG_EVENT_CONTEXT_VPPID: | |
542 | return config_event_context_vppid; | |
543 | case LTTNG_EVENT_CONTEXT_PTHREAD_ID: | |
544 | return config_event_context_pthread_id; | |
545 | case LTTNG_EVENT_CONTEXT_HOSTNAME: | |
546 | return config_event_context_hostname; | |
547 | case LTTNG_EVENT_CONTEXT_IP: | |
548 | return config_event_context_ip; | |
a72332c3 JR |
549 | case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE: |
550 | return config_event_context_interruptible; | |
551 | case LTTNG_EVENT_CONTEXT_PREEMPTIBLE: | |
552 | return config_event_context_preemptible; | |
553 | case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE: | |
554 | return config_event_context_need_reschedule; | |
555 | case LTTNG_EVENT_CONTEXT_MIGRATABLE: | |
556 | return config_event_context_migratable; | |
16c4c991 FD |
557 | case LTTNG_EVENT_CONTEXT_CALLSTACK_USER: |
558 | return config_event_context_callstack_user; | |
559 | case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL: | |
560 | return config_event_context_callstack_kernel; | |
65ae1ae9 JR |
561 | case LTTNG_EVENT_CONTEXT_CGROUP_NS: |
562 | return config_event_context_cgroup_ns; | |
563 | case LTTNG_EVENT_CONTEXT_IPC_NS: | |
564 | return config_event_context_ipc_ns; | |
565 | case LTTNG_EVENT_CONTEXT_MNT_NS: | |
566 | return config_event_context_mnt_ns; | |
567 | case LTTNG_EVENT_CONTEXT_NET_NS: | |
568 | return config_event_context_net_ns; | |
569 | case LTTNG_EVENT_CONTEXT_PID_NS: | |
570 | return config_event_context_pid_ns; | |
d37ac3cd MJ |
571 | case LTTNG_EVENT_CONTEXT_TIME_NS: |
572 | return config_event_context_time_ns; | |
65ae1ae9 JR |
573 | case LTTNG_EVENT_CONTEXT_USER_NS: |
574 | return config_event_context_user_ns; | |
575 | case LTTNG_EVENT_CONTEXT_UTS_NS: | |
576 | return config_event_context_uts_ns; | |
577 | case LTTNG_EVENT_CONTEXT_UID: | |
578 | return config_event_context_uid; | |
579 | case LTTNG_EVENT_CONTEXT_EUID: | |
580 | return config_event_context_euid; | |
581 | case LTTNG_EVENT_CONTEXT_SUID: | |
582 | return config_event_context_suid; | |
583 | case LTTNG_EVENT_CONTEXT_GID: | |
584 | return config_event_context_gid; | |
585 | case LTTNG_EVENT_CONTEXT_EGID: | |
586 | return config_event_context_egid; | |
587 | case LTTNG_EVENT_CONTEXT_SGID: | |
588 | return config_event_context_sgid; | |
589 | case LTTNG_EVENT_CONTEXT_VUID: | |
590 | return config_event_context_vuid; | |
591 | case LTTNG_EVENT_CONTEXT_VEUID: | |
592 | return config_event_context_veuid; | |
593 | case LTTNG_EVENT_CONTEXT_VSUID: | |
594 | return config_event_context_vsuid; | |
595 | case LTTNG_EVENT_CONTEXT_VGID: | |
596 | return config_event_context_vgid; | |
597 | case LTTNG_EVENT_CONTEXT_VEGID: | |
598 | return config_event_context_vegid; | |
599 | case LTTNG_EVENT_CONTEXT_VSGID: | |
600 | return config_event_context_vsgid; | |
89b72577 | 601 | default: |
cd9adb8b | 602 | return nullptr; |
89b72577 JRJ |
603 | } |
604 | } | |
605 | ||
5e18ec73 JR |
606 | const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val) |
607 | { | |
608 | switch (val) { | |
28ab034a | 609 | case (LTTNG_EVENT_FIELD_INTEGER): |
5e18ec73 | 610 | return mi_lttng_element_type_integer; |
28ab034a | 611 | case (LTTNG_EVENT_FIELD_ENUM): |
5e18ec73 | 612 | return mi_lttng_element_type_enum; |
28ab034a | 613 | case (LTTNG_EVENT_FIELD_FLOAT): |
5e18ec73 | 614 | return mi_lttng_element_type_float; |
28ab034a | 615 | case (LTTNG_EVENT_FIELD_STRING): |
5e18ec73 JR |
616 | return mi_lttng_element_type_string; |
617 | default: | |
618 | return mi_lttng_element_type_other; | |
619 | } | |
620 | } | |
621 | ||
622 | const char *mi_lttng_domaintype_string(enum lttng_domain_type value) | |
623 | { | |
5e18ec73 JR |
624 | switch (value) { |
625 | case LTTNG_DOMAIN_KERNEL: | |
626 | return config_domain_type_kernel; | |
627 | case LTTNG_DOMAIN_UST: | |
628 | return config_domain_type_ust; | |
629 | case LTTNG_DOMAIN_JUL: | |
630 | return config_domain_type_jul; | |
5cdb6027 DG |
631 | case LTTNG_DOMAIN_LOG4J: |
632 | return config_domain_type_log4j; | |
b789735e PP |
633 | case LTTNG_DOMAIN_PYTHON: |
634 | return config_domain_type_python; | |
5e18ec73 JR |
635 | default: |
636 | /* Should not have an unknown domain */ | |
a0377dfe | 637 | abort(); |
cd9adb8b | 638 | return nullptr; |
5e18ec73 JR |
639 | } |
640 | } | |
641 | ||
642 | const char *mi_lttng_buffertype_string(enum lttng_buffer_type value) | |
643 | { | |
644 | switch (value) { | |
645 | case LTTNG_BUFFER_PER_PID: | |
646 | return config_buffer_type_per_pid; | |
647 | case LTTNG_BUFFER_PER_UID: | |
648 | return config_buffer_type_per_uid; | |
649 | case LTTNG_BUFFER_GLOBAL: | |
650 | return config_buffer_type_global; | |
651 | default: | |
652 | /* Should not have an unknow buffer type */ | |
a0377dfe | 653 | abort(); |
cd9adb8b | 654 | return nullptr; |
5e18ec73 JR |
655 | } |
656 | } | |
657 | ||
91c4d516 JG |
658 | const char *mi_lttng_rotation_state_string(enum lttng_rotation_state value) |
659 | { | |
660 | switch (value) { | |
661 | case LTTNG_ROTATION_STATE_ONGOING: | |
662 | return mi_lttng_rotation_state_str_ongoing; | |
663 | case LTTNG_ROTATION_STATE_COMPLETED: | |
664 | return mi_lttng_rotation_state_str_completed; | |
665 | case LTTNG_ROTATION_STATE_EXPIRED: | |
666 | return mi_lttng_rotation_state_str_expired; | |
667 | case LTTNG_ROTATION_STATE_ERROR: | |
668 | return mi_lttng_rotation_state_str_error; | |
669 | default: | |
670 | /* Should not have an unknow rotation state. */ | |
a0377dfe | 671 | abort(); |
cd9adb8b | 672 | return nullptr; |
91c4d516 JG |
673 | } |
674 | } | |
675 | ||
91c4d516 | 676 | const char *mi_lttng_trace_archive_location_relay_protocol_type_string( |
28ab034a | 677 | enum lttng_trace_archive_location_relay_protocol_type value) |
91c4d516 JG |
678 | { |
679 | switch (value) { | |
680 | case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP: | |
681 | return mi_lttng_rotation_location_relay_protocol_str_tcp; | |
682 | default: | |
6a751b95 | 683 | /* Should not have an unknown relay protocol. */ |
a0377dfe | 684 | abort(); |
cd9adb8b | 685 | return nullptr; |
91c4d516 JG |
686 | } |
687 | } | |
688 | ||
c7e35b03 JR |
689 | struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type) |
690 | { | |
691 | struct mi_writer *mi_writer; | |
692 | ||
64803277 | 693 | mi_writer = zmalloc<struct mi_writer>(); |
c7e35b03 JR |
694 | if (!mi_writer) { |
695 | PERROR("zmalloc mi_writer_create"); | |
696 | goto end; | |
697 | } | |
698 | if (mi_output_type == LTTNG_MI_XML) { | |
705bb62f | 699 | mi_writer->writer = config_writer_create(fd_output, 0); |
c7e35b03 JR |
700 | if (!mi_writer->writer) { |
701 | goto err_destroy; | |
702 | } | |
703 | mi_writer->type = LTTNG_MI_XML; | |
704 | } else { | |
705 | goto err_destroy; | |
706 | } | |
707 | ||
708 | end: | |
709 | return mi_writer; | |
710 | ||
711 | err_destroy: | |
712 | free(mi_writer); | |
cd9adb8b | 713 | return nullptr; |
c7e35b03 JR |
714 | } |
715 | ||
c7e35b03 JR |
716 | int mi_lttng_writer_destroy(struct mi_writer *writer) |
717 | { | |
718 | int ret; | |
719 | ||
720 | if (!writer) { | |
721 | ret = -EINVAL; | |
722 | goto end; | |
723 | } | |
724 | ||
725 | ret = config_writer_destroy(writer->writer); | |
726 | if (ret < 0) { | |
727 | goto end; | |
728 | } | |
729 | ||
730 | free(writer); | |
731 | end: | |
732 | return ret; | |
733 | } | |
734 | ||
c7e35b03 JR |
735 | int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command) |
736 | { | |
737 | int ret; | |
738 | ||
e10b6a1c JG |
739 | /* |
740 | * A command is always the MI's root node, it must declare the current | |
741 | * namespace and schema URIs and the schema's version. | |
742 | */ | |
28ab034a | 743 | ret = config_writer_open_element(writer->writer, mi_lttng_element_command); |
e10b6a1c JG |
744 | if (ret) { |
745 | goto end; | |
746 | } | |
747 | ||
28ab034a JG |
748 | ret = config_writer_write_attribute( |
749 | writer->writer, mi_lttng_xmlns, DEFAULT_LTTNG_MI_NAMESPACE); | |
e10b6a1c JG |
750 | if (ret) { |
751 | goto end; | |
752 | } | |
753 | ||
28ab034a JG |
754 | ret = config_writer_write_attribute( |
755 | writer->writer, mi_lttng_xmlns_xsi, mi_lttng_w3_schema_uri); | |
c7e35b03 JR |
756 | if (ret) { |
757 | goto end; | |
758 | } | |
e10b6a1c | 759 | |
28ab034a JG |
760 | ret = config_writer_write_attribute( |
761 | writer->writer, mi_lttng_schema_location, mi_lttng_schema_location_uri); | |
e10b6a1c JG |
762 | if (ret) { |
763 | goto end; | |
764 | } | |
765 | ||
28ab034a JG |
766 | ret = config_writer_write_attribute( |
767 | writer->writer, mi_lttng_schema_version, mi_lttng_schema_version_value); | |
e10b6a1c JG |
768 | if (ret) { |
769 | goto end; | |
770 | } | |
771 | ||
28ab034a | 772 | ret = mi_lttng_writer_write_element_string(writer, mi_lttng_element_command_name, command); |
c7e35b03 JR |
773 | end: |
774 | return ret; | |
775 | } | |
776 | ||
c7e35b03 JR |
777 | int mi_lttng_writer_command_close(struct mi_writer *writer) |
778 | { | |
779 | return mi_lttng_writer_close_element(writer); | |
780 | } | |
781 | ||
28ab034a | 782 | int mi_lttng_writer_open_element(struct mi_writer *writer, const char *element_name) |
c7e35b03 JR |
783 | { |
784 | return config_writer_open_element(writer->writer, element_name); | |
785 | } | |
786 | ||
c7e35b03 JR |
787 | int mi_lttng_writer_close_element(struct mi_writer *writer) |
788 | { | |
789 | return config_writer_close_element(writer->writer); | |
790 | } | |
791 | ||
28ab034a | 792 | int mi_lttng_close_multi_element(struct mi_writer *writer, unsigned int nb_element) |
5e18ec73 JR |
793 | { |
794 | int ret, i; | |
795 | ||
796 | if (nb_element < 1) { | |
797 | ret = 0; | |
798 | goto end; | |
799 | } | |
800 | for (i = 0; i < nb_element; i++) { | |
801 | ret = mi_lttng_writer_close_element(writer); | |
802 | if (ret) { | |
803 | goto end; | |
804 | } | |
805 | } | |
806 | end: | |
807 | return ret; | |
808 | } | |
809 | ||
c7e35b03 | 810 | int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer, |
28ab034a JG |
811 | const char *element_name, |
812 | uint64_t value) | |
c7e35b03 | 813 | { |
28ab034a | 814 | return config_writer_write_element_unsigned_int(writer->writer, element_name, value); |
c7e35b03 JR |
815 | } |
816 | ||
c7e35b03 | 817 | int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer, |
28ab034a JG |
818 | const char *element_name, |
819 | int64_t value) | |
c7e35b03 | 820 | { |
28ab034a | 821 | return config_writer_write_element_signed_int(writer->writer, element_name, value); |
c7e35b03 JR |
822 | } |
823 | ||
c7e35b03 | 824 | int mi_lttng_writer_write_element_bool(struct mi_writer *writer, |
28ab034a JG |
825 | const char *element_name, |
826 | int value) | |
c7e35b03 | 827 | { |
28ab034a | 828 | return config_writer_write_element_bool(writer->writer, element_name, value); |
c7e35b03 JR |
829 | } |
830 | ||
c7e35b03 | 831 | int mi_lttng_writer_write_element_string(struct mi_writer *writer, |
28ab034a JG |
832 | const char *element_name, |
833 | const char *value) | |
c7e35b03 | 834 | { |
28ab034a | 835 | return config_writer_write_element_string(writer->writer, element_name, value); |
c7e35b03 JR |
836 | } |
837 | ||
2b166400 | 838 | int mi_lttng_writer_write_element_double(struct mi_writer *writer, |
28ab034a JG |
839 | const char *element_name, |
840 | double value) | |
2b166400 | 841 | { |
28ab034a | 842 | return config_writer_write_element_double(writer->writer, element_name, value); |
2b166400 JR |
843 | } |
844 | ||
28ab034a JG |
845 | int mi_lttng_version(struct mi_writer *writer, |
846 | struct mi_lttng_version_data *version, | |
847 | const char *lttng_description, | |
848 | const char *lttng_license) | |
c7e35b03 JR |
849 | { |
850 | int ret; | |
851 | ||
852 | /* Open version */ | |
853 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_version); | |
854 | if (ret) { | |
855 | goto end; | |
856 | } | |
857 | ||
858 | /* Version string (contain info like rc etc.) */ | |
28ab034a JG |
859 | ret = mi_lttng_writer_write_element_string( |
860 | writer, mi_lttng_element_version_str, version->version); | |
c7e35b03 JR |
861 | if (ret) { |
862 | goto end; | |
863 | } | |
864 | ||
865 | /* Major version number */ | |
28ab034a JG |
866 | ret = mi_lttng_writer_write_element_unsigned_int( |
867 | writer, mi_lttng_element_version_major, version->version_major); | |
c7e35b03 JR |
868 | if (ret) { |
869 | goto end; | |
870 | } | |
871 | ||
872 | /* Minor version number */ | |
28ab034a JG |
873 | ret = mi_lttng_writer_write_element_unsigned_int( |
874 | writer, mi_lttng_element_version_minor, version->version_minor); | |
c7e35b03 JR |
875 | if (ret) { |
876 | goto end; | |
877 | } | |
878 | ||
314d5222 | 879 | /* Commit version number */ |
28ab034a JG |
880 | ret = mi_lttng_writer_write_element_string( |
881 | writer, mi_lttng_element_version_commit, version->version_commit); | |
314d5222 JRJ |
882 | if (ret) { |
883 | goto end; | |
884 | } | |
885 | ||
c7e35b03 | 886 | /* Patch number */ |
28ab034a JG |
887 | ret = mi_lttng_writer_write_element_unsigned_int( |
888 | writer, mi_lttng_element_version_patch_level, version->version_patchlevel); | |
c7e35b03 JR |
889 | if (ret) { |
890 | goto end; | |
891 | } | |
892 | ||
893 | /* Name of the version */ | |
28ab034a JG |
894 | ret = mi_lttng_writer_write_element_string( |
895 | writer, config_element_name, version->version_name); | |
c7e35b03 JR |
896 | if (ret) { |
897 | goto end; | |
898 | } | |
899 | ||
900 | /* Description mostly related to beer... */ | |
28ab034a JG |
901 | ret = mi_lttng_writer_write_element_string( |
902 | writer, mi_lttng_element_version_description, lttng_description); | |
c7e35b03 JR |
903 | if (ret) { |
904 | goto end; | |
905 | } | |
906 | ||
907 | /* url */ | |
28ab034a JG |
908 | ret = mi_lttng_writer_write_element_string( |
909 | writer, mi_lttng_element_version_web, version->package_url); | |
c7e35b03 JR |
910 | if (ret) { |
911 | goto end; | |
912 | } | |
913 | ||
914 | /* License: free as in free beer...no...*speech* */ | |
28ab034a JG |
915 | ret = mi_lttng_writer_write_element_string( |
916 | writer, mi_lttng_element_version_license, lttng_license); | |
c7e35b03 JR |
917 | if (ret) { |
918 | goto end; | |
919 | } | |
920 | ||
921 | /* Close version element */ | |
922 | ret = mi_lttng_writer_close_element(writer); | |
923 | ||
924 | end: | |
925 | return ret; | |
926 | } | |
927 | ||
5e18ec73 JR |
928 | int mi_lttng_sessions_open(struct mi_writer *writer) |
929 | { | |
930 | return mi_lttng_writer_open_element(writer, config_element_sessions); | |
931 | } | |
932 | ||
7a96a40b | 933 | int mi_lttng_session(struct mi_writer *writer, const struct lttng_session *session, int is_open) |
c7e35b03 JR |
934 | { |
935 | int ret; | |
936 | ||
a0377dfe | 937 | LTTNG_ASSERT(session); |
5e18ec73 JR |
938 | |
939 | /* Open sessions element */ | |
28ab034a | 940 | ret = mi_lttng_writer_open_element(writer, config_element_session); |
c7e35b03 JR |
941 | if (ret) { |
942 | goto end; | |
943 | } | |
944 | ||
945 | /* Name of the session */ | |
28ab034a | 946 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, session->name); |
c7e35b03 JR |
947 | if (ret) { |
948 | goto end; | |
949 | } | |
950 | ||
5e18ec73 | 951 | /* Path */ |
28ab034a | 952 | ret = mi_lttng_writer_write_element_string(writer, config_element_path, session->path); |
c7e35b03 JR |
953 | if (ret) { |
954 | goto end; | |
955 | } | |
956 | ||
5e18ec73 | 957 | /* Enabled ? */ |
28ab034a | 958 | ret = mi_lttng_writer_write_element_bool(writer, config_element_enabled, session->enabled); |
c7e35b03 JR |
959 | if (ret) { |
960 | goto end; | |
961 | } | |
962 | ||
5e18ec73 | 963 | /* Snapshot mode */ |
28ab034a JG |
964 | ret = mi_lttng_writer_write_element_unsigned_int( |
965 | writer, config_element_snapshot_mode, session->snapshot_mode); | |
c7e35b03 JR |
966 | if (ret) { |
967 | goto end; | |
968 | } | |
969 | ||
5e18ec73 | 970 | /* Live timer interval in usec */ |
28ab034a JG |
971 | ret = mi_lttng_writer_write_element_unsigned_int( |
972 | writer, config_element_live_timer_interval, session->live_timer_interval); | |
c7e35b03 JR |
973 | if (ret) { |
974 | goto end; | |
975 | } | |
976 | ||
977 | if (!is_open) { | |
978 | /* Closing session element */ | |
979 | ret = mi_lttng_writer_close_element(writer); | |
980 | } | |
981 | end: | |
982 | return ret; | |
c7e35b03 | 983 | } |
5e18ec73 | 984 | |
5e18ec73 JR |
985 | int mi_lttng_domains_open(struct mi_writer *writer) |
986 | { | |
987 | return mi_lttng_writer_open_element(writer, config_element_domains); | |
988 | } | |
989 | ||
28ab034a | 990 | int mi_lttng_domain(struct mi_writer *writer, struct lttng_domain *domain, int is_open) |
5e18ec73 JR |
991 | { |
992 | int ret = 0; | |
993 | const char *str_domain; | |
994 | const char *str_buffer; | |
995 | ||
a0377dfe | 996 | LTTNG_ASSERT(domain); |
5e18ec73 JR |
997 | |
998 | /* Open domain element */ | |
999 | ret = mi_lttng_writer_open_element(writer, config_element_domain); | |
1000 | if (ret) { | |
1001 | goto end; | |
1002 | } | |
1003 | ||
1004 | /* Domain Type */ | |
1005 | str_domain = mi_lttng_domaintype_string(domain->type); | |
28ab034a | 1006 | ret = mi_lttng_writer_write_element_string(writer, config_element_type, str_domain); |
5e18ec73 JR |
1007 | if (ret) { |
1008 | goto end; | |
1009 | } | |
1010 | ||
1011 | /* Buffer Type */ | |
28ab034a JG |
1012 | str_buffer = mi_lttng_buffertype_string(domain->buf_type); |
1013 | ret = mi_lttng_writer_write_element_string(writer, config_element_buffer_type, str_buffer); | |
5e18ec73 JR |
1014 | if (ret) { |
1015 | goto end; | |
1016 | } | |
1017 | ||
d813f89b JRJ |
1018 | /* TODO: union attr |
1019 | * This union is not currently used and was added for | |
1020 | * future ust domain support. | |
1021 | * Date: 25-06-2014 | |
1022 | * */ | |
5e18ec73 JR |
1023 | |
1024 | if (!is_open) { | |
1025 | /* Closing domain element */ | |
1026 | ret = mi_lttng_writer_close_element(writer); | |
1027 | } | |
1028 | ||
1029 | end: | |
1030 | return ret; | |
5e18ec73 JR |
1031 | } |
1032 | ||
5e18ec73 JR |
1033 | int mi_lttng_channels_open(struct mi_writer *writer) |
1034 | { | |
1035 | return mi_lttng_writer_open_element(writer, config_element_channels); | |
1036 | } | |
1037 | ||
28ab034a | 1038 | int mi_lttng_channel(struct mi_writer *writer, struct lttng_channel *channel, int is_open) |
5e18ec73 JR |
1039 | { |
1040 | int ret = 0; | |
1041 | ||
a0377dfe | 1042 | LTTNG_ASSERT(channel); |
5e18ec73 JR |
1043 | |
1044 | /* Opening channel element */ | |
1045 | ret = mi_lttng_writer_open_element(writer, config_element_channel); | |
1046 | if (ret) { | |
1047 | goto end; | |
1048 | } | |
1049 | ||
1050 | /* Name */ | |
28ab034a | 1051 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, channel->name); |
5e18ec73 JR |
1052 | if (ret) { |
1053 | goto end; | |
1054 | } | |
1055 | ||
1056 | /* Enabled ? */ | |
28ab034a | 1057 | ret = mi_lttng_writer_write_element_bool(writer, config_element_enabled, channel->enabled); |
5e18ec73 JR |
1058 | if (ret) { |
1059 | goto end; | |
1060 | } | |
1061 | ||
1062 | /* Attribute */ | |
1063 | ret = mi_lttng_channel_attr(writer, &channel->attr); | |
1064 | if (ret) { | |
1065 | goto end; | |
1066 | } | |
1067 | ||
1068 | if (!is_open) { | |
1069 | /* Closing channel element */ | |
1070 | ret = mi_lttng_writer_close_element(writer); | |
1071 | if (ret) { | |
1072 | goto end; | |
1073 | } | |
1074 | } | |
1075 | end: | |
1076 | return ret; | |
1077 | } | |
1078 | ||
28ab034a | 1079 | int mi_lttng_channel_attr(struct mi_writer *writer, struct lttng_channel_attr *attr) |
5e18ec73 JR |
1080 | { |
1081 | int ret = 0; | |
28ab034a | 1082 | struct lttng_channel *chan = caa_container_of(attr, struct lttng_channel, attr); |
cf0bcb51 | 1083 | uint64_t discarded_events, lost_packets, monitor_timer_interval; |
491d1539 | 1084 | int64_t blocking_timeout; |
5e18ec73 | 1085 | |
a0377dfe | 1086 | LTTNG_ASSERT(attr); |
5e18ec73 | 1087 | |
fb83fe64 JD |
1088 | ret = lttng_channel_get_discarded_event_count(chan, &discarded_events); |
1089 | if (ret) { | |
1090 | goto end; | |
1091 | } | |
1092 | ||
1093 | ret = lttng_channel_get_lost_packet_count(chan, &lost_packets); | |
1094 | if (ret) { | |
1095 | goto end; | |
1096 | } | |
1097 | ||
28ab034a | 1098 | ret = lttng_channel_get_monitor_timer_interval(chan, &monitor_timer_interval); |
cf0bcb51 JG |
1099 | if (ret) { |
1100 | goto end; | |
1101 | } | |
1102 | ||
28ab034a | 1103 | ret = lttng_channel_get_blocking_timeout(chan, &blocking_timeout); |
491d1539 MD |
1104 | if (ret) { |
1105 | goto end; | |
1106 | } | |
1107 | ||
5e18ec73 JR |
1108 | /* Opening Attributes */ |
1109 | ret = mi_lttng_writer_open_element(writer, config_element_attributes); | |
1110 | if (ret) { | |
1111 | goto end; | |
1112 | } | |
1113 | ||
1114 | /* Overwrite */ | |
28ab034a JG |
1115 | ret = mi_lttng_writer_write_element_string( |
1116 | writer, | |
5e18ec73 | 1117 | config_element_overwrite_mode, |
28ab034a | 1118 | attr->overwrite ? config_overwrite_mode_overwrite : config_overwrite_mode_discard); |
5e18ec73 JR |
1119 | if (ret) { |
1120 | goto end; | |
1121 | } | |
1122 | ||
1123 | /* Sub buffer size in byte */ | |
28ab034a JG |
1124 | ret = mi_lttng_writer_write_element_unsigned_int( |
1125 | writer, config_element_subbuf_size, attr->subbuf_size); | |
5e18ec73 JR |
1126 | if (ret) { |
1127 | goto end; | |
1128 | } | |
1129 | ||
1130 | /* Number of subbuffer (power of two) */ | |
28ab034a JG |
1131 | ret = mi_lttng_writer_write_element_unsigned_int( |
1132 | writer, config_element_num_subbuf, attr->num_subbuf); | |
5e18ec73 JR |
1133 | if (ret) { |
1134 | goto end; | |
1135 | } | |
1136 | ||
1137 | /* Switch timer interval in usec */ | |
28ab034a JG |
1138 | ret = mi_lttng_writer_write_element_unsigned_int( |
1139 | writer, config_element_switch_timer_interval, attr->switch_timer_interval); | |
5e18ec73 JR |
1140 | if (ret) { |
1141 | goto end; | |
1142 | } | |
1143 | ||
1144 | /* Read timer interval in usec */ | |
28ab034a JG |
1145 | ret = mi_lttng_writer_write_element_unsigned_int( |
1146 | writer, config_element_read_timer_interval, attr->read_timer_interval); | |
5e18ec73 JR |
1147 | if (ret) { |
1148 | goto end; | |
1149 | } | |
1150 | ||
cf0bcb51 | 1151 | /* Monitor timer interval in usec */ |
28ab034a JG |
1152 | ret = mi_lttng_writer_write_element_unsigned_int( |
1153 | writer, config_element_monitor_timer_interval, monitor_timer_interval); | |
cf0bcb51 JG |
1154 | if (ret) { |
1155 | goto end; | |
1156 | } | |
1157 | ||
491d1539 | 1158 | /* Retry timeout in usec */ |
28ab034a JG |
1159 | ret = mi_lttng_writer_write_element_signed_int( |
1160 | writer, config_element_blocking_timeout, blocking_timeout); | |
491d1539 MD |
1161 | if (ret) { |
1162 | goto end; | |
1163 | } | |
1164 | ||
5e18ec73 JR |
1165 | /* Event output */ |
1166 | ret = mi_lttng_writer_write_element_string(writer, | |
28ab034a JG |
1167 | config_element_output_type, |
1168 | attr->output == LTTNG_EVENT_SPLICE ? | |
1169 | config_output_type_splice : | |
1170 | config_output_type_mmap); | |
5e18ec73 JR |
1171 | if (ret) { |
1172 | goto end; | |
1173 | } | |
1174 | ||
1175 | /* Tracefile size in bytes */ | |
28ab034a JG |
1176 | ret = mi_lttng_writer_write_element_unsigned_int( |
1177 | writer, config_element_tracefile_size, attr->tracefile_size); | |
5e18ec73 JR |
1178 | if (ret) { |
1179 | goto end; | |
1180 | } | |
1181 | ||
1182 | /* Count of tracefiles */ | |
28ab034a JG |
1183 | ret = mi_lttng_writer_write_element_unsigned_int( |
1184 | writer, config_element_tracefile_count, attr->tracefile_count); | |
5e18ec73 JR |
1185 | if (ret) { |
1186 | goto end; | |
1187 | } | |
1188 | ||
1189 | /* Live timer interval in usec*/ | |
28ab034a JG |
1190 | ret = mi_lttng_writer_write_element_unsigned_int( |
1191 | writer, config_element_live_timer_interval, attr->live_timer_interval); | |
5e18ec73 | 1192 | if (ret) { |
fb83fe64 JD |
1193 | goto end; |
1194 | } | |
1195 | ||
1196 | /* Discarded events */ | |
28ab034a JG |
1197 | ret = mi_lttng_writer_write_element_unsigned_int( |
1198 | writer, config_element_discarded_events, discarded_events); | |
fb83fe64 JD |
1199 | if (ret) { |
1200 | goto end; | |
1201 | } | |
1202 | ||
1203 | /* Lost packets */ | |
28ab034a JG |
1204 | ret = mi_lttng_writer_write_element_unsigned_int( |
1205 | writer, config_element_lost_packets, lost_packets); | |
fb83fe64 | 1206 | if (ret) { |
5e18ec73 JR |
1207 | goto end; |
1208 | } | |
1209 | ||
1210 | /* Closing attributes */ | |
1211 | ret = mi_lttng_writer_close_element(writer); | |
1212 | if (ret) { | |
1213 | goto end; | |
1214 | } | |
1215 | end: | |
1216 | return ret; | |
5e18ec73 JR |
1217 | } |
1218 | ||
28ab034a | 1219 | int mi_lttng_event_common_attributes(struct mi_writer *writer, struct lttng_event *event) |
5e18ec73 JR |
1220 | { |
1221 | int ret; | |
7b4aa11d | 1222 | const char *filter_expression; |
5e18ec73 JR |
1223 | |
1224 | /* Open event element */ | |
1225 | ret = mi_lttng_writer_open_element(writer, config_element_event); | |
1226 | if (ret) { | |
1227 | goto end; | |
1228 | } | |
1229 | ||
f4a088f7 | 1230 | /* Event name */ |
28ab034a | 1231 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, event->name); |
5e18ec73 JR |
1232 | if (ret) { |
1233 | goto end; | |
1234 | } | |
1235 | ||
f4a088f7 | 1236 | /* Event type */ |
28ab034a JG |
1237 | ret = mi_lttng_writer_write_element_string( |
1238 | writer, config_element_type, mi_lttng_eventtype_string(event->type)); | |
5e18ec73 JR |
1239 | if (ret) { |
1240 | goto end; | |
1241 | } | |
1242 | ||
f4a088f7 | 1243 | /* Is event enabled */ |
28ab034a | 1244 | ret = mi_lttng_writer_write_element_bool(writer, config_element_enabled, event->enabled); |
5e18ec73 JR |
1245 | if (ret) { |
1246 | goto end; | |
1247 | } | |
1248 | ||
7b4aa11d | 1249 | /* Event filter expression */ |
134e72ed | 1250 | ret = lttng_event_get_filter_expression(event, &filter_expression); |
7b4aa11d PP |
1251 | if (ret) { |
1252 | goto end; | |
1253 | } | |
1254 | ||
1255 | if (filter_expression) { | |
28ab034a JG |
1256 | ret = mi_lttng_writer_write_element_string( |
1257 | writer, config_element_filter_expression, filter_expression); | |
7b4aa11d PP |
1258 | if (ret) { |
1259 | goto end; | |
1260 | } | |
1261 | } | |
1262 | ||
5e18ec73 JR |
1263 | end: |
1264 | return ret; | |
1265 | } | |
1266 | ||
28ab034a | 1267 | static int write_event_exclusions(struct mi_writer *writer, struct lttng_event *event) |
eecb9438 PP |
1268 | { |
1269 | int i; | |
1270 | int ret; | |
1271 | int exclusion_count; | |
1272 | ||
eecb9438 PP |
1273 | /* Open event exclusions */ |
1274 | ret = mi_lttng_writer_open_element(writer, config_element_exclusions); | |
1275 | if (ret) { | |
1276 | goto end; | |
1277 | } | |
1278 | ||
1279 | exclusion_count = lttng_event_get_exclusion_name_count(event); | |
1280 | if (exclusion_count < 0) { | |
1281 | ret = exclusion_count; | |
1282 | goto end; | |
1283 | } | |
1284 | ||
1285 | for (i = 0; i < exclusion_count; i++) { | |
1286 | const char *name; | |
1287 | ||
1288 | ret = lttng_event_get_exclusion_name(event, i, &name); | |
1289 | if (ret) { | |
1290 | /* Close exclusions */ | |
1291 | mi_lttng_writer_close_element(writer); | |
1292 | goto end; | |
1293 | } | |
1294 | ||
28ab034a | 1295 | ret = mi_lttng_writer_write_element_string(writer, config_element_exclusion, name); |
eecb9438 PP |
1296 | if (ret) { |
1297 | /* Close exclusions */ | |
1298 | mi_lttng_writer_close_element(writer); | |
1299 | goto end; | |
1300 | } | |
1301 | } | |
1302 | ||
1303 | /* Close exclusions */ | |
1304 | ret = mi_lttng_writer_close_element(writer); | |
1305 | ||
1306 | end: | |
1307 | return ret; | |
1308 | } | |
1309 | ||
5e18ec73 | 1310 | int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer, |
28ab034a JG |
1311 | struct lttng_event *event, |
1312 | enum lttng_domain_type domain) | |
5e18ec73 JR |
1313 | { |
1314 | int ret; | |
1315 | ||
f4a088f7 | 1316 | /* Event loglevel */ |
28ab034a JG |
1317 | ret = mi_lttng_writer_write_element_string( |
1318 | writer, config_element_loglevel, mi_lttng_loglevel_string(event->loglevel, domain)); | |
5e18ec73 JR |
1319 | if (ret) { |
1320 | goto end; | |
1321 | } | |
1322 | ||
f4a088f7 | 1323 | /* Log level type */ |
28ab034a JG |
1324 | ret = mi_lttng_writer_write_element_string( |
1325 | writer, | |
1326 | config_element_loglevel_type, | |
1327 | mi_lttng_logleveltype_string(event->loglevel_type)); | |
5e18ec73 JR |
1328 | if (ret) { |
1329 | goto end; | |
1330 | } | |
1331 | ||
eecb9438 PP |
1332 | /* Event exclusions */ |
1333 | ret = write_event_exclusions(writer, event); | |
5e18ec73 JR |
1334 | |
1335 | end: | |
1336 | return ret; | |
1337 | } | |
1338 | ||
28ab034a | 1339 | int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer *writer, struct lttng_event *event) |
5e18ec73 JR |
1340 | { |
1341 | /* event exclusion filter */ | |
eecb9438 | 1342 | return write_event_exclusions(writer, event); |
5e18ec73 JR |
1343 | } |
1344 | ||
28ab034a | 1345 | int mi_lttng_event_function_probe(struct mi_writer *writer, struct lttng_event *event) |
5e18ec73 JR |
1346 | { |
1347 | int ret; | |
1348 | ||
3b4a6e40 JRJ |
1349 | ret = mi_lttng_writer_open_element(writer, config_element_attributes); |
1350 | if (ret) { | |
1351 | goto end; | |
1352 | } | |
1353 | ||
1354 | ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes); | |
1355 | if (ret) { | |
1356 | goto end; | |
1357 | } | |
1358 | ||
5e18ec73 JR |
1359 | if (event->attr.probe.addr != 0) { |
1360 | /* event probe address */ | |
28ab034a JG |
1361 | ret = mi_lttng_writer_write_element_unsigned_int( |
1362 | writer, config_element_address, event->attr.probe.addr); | |
5e18ec73 JR |
1363 | if (ret) { |
1364 | goto end; | |
1365 | } | |
1366 | } else { | |
1367 | /* event probe offset */ | |
28ab034a JG |
1368 | ret = mi_lttng_writer_write_element_unsigned_int( |
1369 | writer, config_element_offset, event->attr.probe.offset); | |
5e18ec73 JR |
1370 | if (ret) { |
1371 | goto end; | |
1372 | } | |
1373 | ||
1374 | /* event probe symbol_name */ | |
28ab034a JG |
1375 | ret = mi_lttng_writer_write_element_string( |
1376 | writer, config_element_symbol_name, event->attr.probe.symbol_name); | |
5e18ec73 JR |
1377 | if (ret) { |
1378 | goto end; | |
1379 | } | |
1380 | } | |
3b4a6e40 JRJ |
1381 | |
1382 | /* Close probe_attributes and attributes */ | |
1383 | ret = mi_lttng_close_multi_element(writer, 2); | |
5e18ec73 JR |
1384 | end: |
1385 | return ret; | |
1386 | } | |
1387 | ||
28ab034a | 1388 | static int mi_lttng_event_userspace_probe(struct mi_writer *writer, struct lttng_event *event) |
5a1c0a75 FD |
1389 | { |
1390 | int ret; | |
87597c2c JG |
1391 | const struct lttng_userspace_probe_location *location; |
1392 | const struct lttng_userspace_probe_location_lookup_method *lookup_method; | |
5a1c0a75 FD |
1393 | enum lttng_userspace_probe_location_lookup_method_type lookup_type; |
1394 | ||
1395 | location = lttng_event_get_userspace_probe_location(event); | |
1396 | if (!location) { | |
1397 | ret = -LTTNG_ERR_INVALID; | |
1398 | goto end; | |
1399 | } | |
1400 | ||
1401 | lookup_method = lttng_userspace_probe_location_get_lookup_method(location); | |
1402 | if (!lookup_method) { | |
1403 | ret = -LTTNG_ERR_INVALID; | |
1404 | goto end; | |
1405 | } | |
1406 | ||
1407 | lookup_type = lttng_userspace_probe_location_lookup_method_get_type(lookup_method); | |
1408 | ||
1409 | ret = mi_lttng_writer_open_element(writer, config_element_attributes); | |
1410 | if (ret) { | |
1411 | goto end; | |
1412 | } | |
1413 | ||
1414 | switch (lttng_userspace_probe_location_get_type(location)) { | |
1415 | case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION: | |
1416 | { | |
1417 | const char *function_name; | |
1418 | const char *binary_path; | |
1419 | ||
28ab034a JG |
1420 | ret = mi_lttng_writer_open_element( |
1421 | writer, config_element_userspace_probe_function_attributes); | |
5a1c0a75 FD |
1422 | if (ret) { |
1423 | goto end; | |
1424 | } | |
1425 | ||
1426 | switch (lookup_type) { | |
1427 | case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF: | |
28ab034a JG |
1428 | ret = mi_lttng_writer_write_element_string( |
1429 | writer, | |
1430 | config_element_userspace_probe_lookup, | |
1431 | config_element_userspace_probe_lookup_function_elf); | |
5a1c0a75 FD |
1432 | if (ret) { |
1433 | goto end; | |
1434 | } | |
1435 | break; | |
1436 | case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT: | |
28ab034a JG |
1437 | ret = mi_lttng_writer_write_element_string( |
1438 | writer, | |
1439 | config_element_userspace_probe_lookup, | |
1440 | config_element_userspace_probe_lookup_function_default); | |
5a1c0a75 FD |
1441 | if (ret) { |
1442 | goto end; | |
1443 | } | |
1444 | break; | |
1445 | default: | |
1446 | goto end; | |
1447 | } | |
1448 | ||
1449 | binary_path = lttng_userspace_probe_location_function_get_binary_path(location); | |
28ab034a JG |
1450 | ret = mi_lttng_writer_write_element_string( |
1451 | writer, config_element_userspace_probe_location_binary_path, binary_path); | |
5a1c0a75 FD |
1452 | if (ret) { |
1453 | goto end; | |
1454 | } | |
1455 | ||
1456 | function_name = lttng_userspace_probe_location_function_get_function_name(location); | |
28ab034a JG |
1457 | ret = mi_lttng_writer_write_element_string( |
1458 | writer, | |
1459 | config_element_userspace_probe_function_location_function_name, | |
1460 | function_name); | |
5a1c0a75 FD |
1461 | if (ret) { |
1462 | goto end; | |
1463 | } | |
1464 | ||
1465 | break; | |
1466 | } | |
1467 | case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT: | |
1468 | { | |
1469 | const char *probe_name, *provider_name; | |
1470 | const char *binary_path; | |
1471 | ||
28ab034a JG |
1472 | ret = mi_lttng_writer_open_element( |
1473 | writer, config_element_userspace_probe_function_attributes); | |
5a1c0a75 FD |
1474 | if (ret) { |
1475 | goto end; | |
1476 | } | |
1477 | ||
1478 | switch (lookup_type) { | |
1479 | case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT: | |
28ab034a JG |
1480 | ret = mi_lttng_writer_write_element_string( |
1481 | writer, | |
1482 | config_element_userspace_probe_lookup, | |
1483 | config_element_userspace_probe_lookup_tracepoint_sdt); | |
5a1c0a75 FD |
1484 | if (ret) { |
1485 | goto end; | |
1486 | } | |
1487 | break; | |
1488 | default: | |
1489 | goto end; | |
1490 | } | |
1491 | ||
1492 | binary_path = lttng_userspace_probe_location_tracepoint_get_binary_path(location); | |
28ab034a JG |
1493 | ret = mi_lttng_writer_write_element_string( |
1494 | writer, config_element_userspace_probe_location_binary_path, binary_path); | |
5a1c0a75 FD |
1495 | if (ret) { |
1496 | goto end; | |
1497 | } | |
1498 | ||
28ab034a JG |
1499 | provider_name = |
1500 | lttng_userspace_probe_location_tracepoint_get_provider_name(location); | |
1501 | ret = mi_lttng_writer_write_element_string( | |
1502 | writer, | |
1503 | config_element_userspace_probe_tracepoint_location_provider_name, | |
1504 | provider_name); | |
5a1c0a75 FD |
1505 | if (ret) { |
1506 | goto end; | |
1507 | } | |
1508 | ||
1509 | probe_name = lttng_userspace_probe_location_tracepoint_get_probe_name(location); | |
28ab034a JG |
1510 | ret = mi_lttng_writer_write_element_string( |
1511 | writer, | |
1512 | config_element_userspace_probe_tracepoint_location_probe_name, | |
1513 | probe_name); | |
5a1c0a75 FD |
1514 | if (ret) { |
1515 | goto end; | |
1516 | } | |
1517 | break; | |
1518 | } | |
1519 | default: | |
1520 | ERR("Invalid probe type encountered"); | |
1521 | } | |
1522 | /* Close probe_attributes and attributes */ | |
1523 | ret = mi_lttng_close_multi_element(writer, 2); | |
1524 | end: | |
1525 | return ret; | |
1526 | } | |
1527 | ||
28ab034a | 1528 | int mi_lttng_event_function_entry(struct mi_writer *writer, struct lttng_event *event) |
5e18ec73 | 1529 | { |
3b4a6e40 JRJ |
1530 | int ret; |
1531 | ||
1532 | ret = mi_lttng_writer_open_element(writer, config_element_attributes); | |
1533 | if (ret) { | |
1534 | goto end; | |
1535 | } | |
1536 | ||
1537 | ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes); | |
1538 | if (ret) { | |
1539 | goto end; | |
1540 | } | |
1541 | ||
5e18ec73 | 1542 | /* event probe symbol_name */ |
28ab034a JG |
1543 | ret = mi_lttng_writer_write_element_string( |
1544 | writer, config_element_symbol_name, event->attr.ftrace.symbol_name); | |
3b4a6e40 JRJ |
1545 | if (ret) { |
1546 | goto end; | |
1547 | } | |
1548 | ||
1549 | /* Close function_attributes and attributes */ | |
1550 | ret = mi_lttng_close_multi_element(writer, 2); | |
1551 | end: | |
1552 | return ret; | |
5e18ec73 JR |
1553 | } |
1554 | ||
5e18ec73 JR |
1555 | int mi_lttng_events_open(struct mi_writer *writer) |
1556 | { | |
1557 | return mi_lttng_writer_open_element(writer, config_element_events); | |
1558 | } | |
1559 | ||
5e18ec73 | 1560 | int mi_lttng_event(struct mi_writer *writer, |
28ab034a JG |
1561 | struct lttng_event *event, |
1562 | int is_open, | |
1563 | enum lttng_domain_type domain) | |
5e18ec73 JR |
1564 | { |
1565 | int ret; | |
1566 | ||
1567 | ret = mi_lttng_event_common_attributes(writer, event); | |
1568 | if (ret) { | |
1569 | goto end; | |
1570 | } | |
1571 | ||
1572 | switch (event->type) { | |
5e18ec73 JR |
1573 | case LTTNG_EVENT_TRACEPOINT: |
1574 | { | |
1575 | if (event->loglevel != -1) { | |
970d848b | 1576 | ret = mi_lttng_event_tracepoint_loglevel(writer, event, domain); |
5e18ec73 JR |
1577 | } else { |
1578 | ret = mi_lttng_event_tracepoint_no_loglevel(writer, event); | |
1579 | } | |
1580 | break; | |
1581 | } | |
3b4a6e40 JRJ |
1582 | case LTTNG_EVENT_FUNCTION: |
1583 | /* Fallthrough */ | |
5e18ec73 JR |
1584 | case LTTNG_EVENT_PROBE: |
1585 | ret = mi_lttng_event_function_probe(writer, event); | |
1586 | break; | |
1587 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
1588 | ret = mi_lttng_event_function_entry(writer, event); | |
1589 | break; | |
5a1c0a75 FD |
1590 | case LTTNG_EVENT_USERSPACE_PROBE: |
1591 | ret = mi_lttng_event_userspace_probe(writer, event); | |
1592 | break; | |
89476427 JRJ |
1593 | case LTTNG_EVENT_ALL: |
1594 | /* Fallthrough */ | |
5e18ec73 JR |
1595 | default: |
1596 | break; | |
1597 | } | |
1598 | ||
5a1c0a75 FD |
1599 | if (ret) { |
1600 | goto end; | |
1601 | } | |
1602 | ||
5e18ec73 JR |
1603 | if (!is_open) { |
1604 | ret = mi_lttng_writer_close_element(writer); | |
1605 | } | |
1606 | ||
1607 | end: | |
1608 | return ret; | |
1609 | } | |
1610 | ||
ebbf5ab7 JR |
1611 | int mi_lttng_trackers_open(struct mi_writer *writer) |
1612 | { | |
28ab034a | 1613 | return mi_lttng_writer_open_element(writer, config_element_process_attr_trackers); |
ebbf5ab7 JR |
1614 | } |
1615 | ||
159b042f | 1616 | static int get_tracker_elements(enum lttng_process_attr process_attr, |
28ab034a JG |
1617 | const char **element_process_attr_tracker, |
1618 | const char **element_process_attr_value) | |
83d6d6c4 JR |
1619 | { |
1620 | int ret = 0; | |
1621 | ||
159b042f JG |
1622 | switch (process_attr) { |
1623 | case LTTNG_PROCESS_ATTR_PROCESS_ID: | |
28ab034a JG |
1624 | *element_process_attr_tracker = config_element_process_attr_tracker_pid; |
1625 | *element_process_attr_value = config_element_process_attr_pid_value; | |
83d6d6c4 | 1626 | break; |
159b042f | 1627 | case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID: |
28ab034a JG |
1628 | *element_process_attr_tracker = config_element_process_attr_tracker_vpid; |
1629 | *element_process_attr_value = config_element_process_attr_vpid_value; | |
83d6d6c4 | 1630 | break; |
159b042f | 1631 | case LTTNG_PROCESS_ATTR_USER_ID: |
28ab034a JG |
1632 | *element_process_attr_tracker = config_element_process_attr_tracker_uid; |
1633 | *element_process_attr_value = config_element_process_attr_uid_value; | |
83d6d6c4 | 1634 | break; |
159b042f | 1635 | case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID: |
28ab034a JG |
1636 | *element_process_attr_tracker = config_element_process_attr_tracker_vuid; |
1637 | *element_process_attr_value = config_element_process_attr_vuid_value; | |
83d6d6c4 | 1638 | break; |
159b042f | 1639 | case LTTNG_PROCESS_ATTR_GROUP_ID: |
28ab034a JG |
1640 | *element_process_attr_tracker = config_element_process_attr_tracker_gid; |
1641 | *element_process_attr_value = config_element_process_attr_gid_value; | |
83d6d6c4 | 1642 | break; |
159b042f | 1643 | case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID: |
28ab034a JG |
1644 | *element_process_attr_tracker = config_element_process_attr_tracker_vgid; |
1645 | *element_process_attr_value = config_element_process_attr_vgid_value; | |
83d6d6c4 JR |
1646 | break; |
1647 | default: | |
1648 | ret = LTTNG_ERR_SAVE_IO_FAIL; | |
1649 | } | |
1650 | return ret; | |
1651 | } | |
1652 | ||
28ab034a JG |
1653 | int mi_lttng_process_attribute_tracker_open(struct mi_writer *writer, |
1654 | enum lttng_process_attr process_attr) | |
ebbf5ab7 JR |
1655 | { |
1656 | int ret; | |
159b042f | 1657 | const char *element_tracker, *element_value; |
83d6d6c4 | 1658 | |
28ab034a | 1659 | ret = get_tracker_elements(process_attr, &element_tracker, &element_value); |
83d6d6c4 JR |
1660 | if (ret) { |
1661 | return ret; | |
1662 | } | |
ebbf5ab7 | 1663 | |
159b042f JG |
1664 | /* Open process attribute tracker element */ |
1665 | ret = mi_lttng_writer_open_element(writer, element_tracker); | |
ebbf5ab7 JR |
1666 | if (ret) { |
1667 | goto end; | |
1668 | } | |
1669 | ||
159b042f JG |
1670 | /* Open values element */ |
1671 | ret = mi_lttng_process_attr_values_open(writer); | |
ebbf5ab7 JR |
1672 | end: |
1673 | return ret; | |
1674 | } | |
1675 | ||
5e18ec73 JR |
1676 | int mi_lttng_pids_open(struct mi_writer *writer) |
1677 | { | |
ebbf5ab7 JR |
1678 | return mi_lttng_writer_open_element(writer, config_element_pids); |
1679 | } | |
1680 | ||
bf239d4c JR |
1681 | /* |
1682 | * TODO: move the listing of pid for user agent to process semantic on | |
1683 | * mi api bump. The use of process element break the mi api. | |
1684 | */ | |
28ab034a | 1685 | int mi_lttng_pid(struct mi_writer *writer, pid_t pid, const char *name, int is_open) |
5e18ec73 JR |
1686 | { |
1687 | int ret; | |
1688 | ||
bf239d4c JR |
1689 | /* Open pid process */ |
1690 | ret = mi_lttng_writer_open_element(writer, config_element_pid); | |
5e18ec73 JR |
1691 | if (ret) { |
1692 | goto end; | |
1693 | } | |
1694 | ||
1695 | /* Writing pid number */ | |
28ab034a | 1696 | ret = mi_lttng_writer_write_element_signed_int(writer, mi_lttng_element_pid_id, (int) pid); |
5e18ec73 JR |
1697 | if (ret) { |
1698 | goto end; | |
1699 | } | |
1700 | ||
1701 | /* Writing name of the process */ | |
ebbf5ab7 | 1702 | if (name) { |
28ab034a | 1703 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, name); |
ebbf5ab7 JR |
1704 | if (ret) { |
1705 | goto end; | |
1706 | } | |
1707 | } | |
1708 | ||
1709 | if (!is_open) { | |
1710 | /* Closing Pid */ | |
1711 | ret = mi_lttng_writer_close_element(writer); | |
1712 | } | |
1713 | ||
1714 | end: | |
1715 | return ret; | |
1716 | } | |
1717 | ||
159b042f | 1718 | int mi_lttng_process_attr_values_open(struct mi_writer *writer) |
ebbf5ab7 | 1719 | { |
28ab034a | 1720 | return mi_lttng_writer_open_element(writer, config_element_process_attr_values); |
ebbf5ab7 JR |
1721 | } |
1722 | ||
159b042f | 1723 | int mi_lttng_all_process_attribute_value(struct mi_writer *writer, |
28ab034a JG |
1724 | enum lttng_process_attr process_attr, |
1725 | bool is_open) | |
ebbf5ab7 JR |
1726 | { |
1727 | int ret; | |
83d6d6c4 | 1728 | const char *element_id_tracker, *element_target_id; |
ebbf5ab7 | 1729 | |
28ab034a | 1730 | ret = get_tracker_elements(process_attr, &element_id_tracker, &element_target_id); |
ebbf5ab7 | 1731 | if (ret) { |
83d6d6c4 | 1732 | return ret; |
ebbf5ab7 JR |
1733 | } |
1734 | ||
159b042f JG |
1735 | ret = mi_lttng_writer_open_element(writer, element_target_id); |
1736 | if (ret) { | |
1737 | goto end; | |
1738 | } | |
2d97a006 | 1739 | |
159b042f JG |
1740 | ret = mi_lttng_writer_open_element(writer, config_element_type); |
1741 | if (ret) { | |
1742 | goto end; | |
1743 | } | |
2d97a006 | 1744 | |
159b042f JG |
1745 | ret = mi_lttng_writer_write_element_bool(writer, config_element_all, 1); |
1746 | if (ret) { | |
1747 | goto end; | |
1748 | } | |
1749 | ||
1750 | ret = mi_lttng_writer_close_element(writer); | |
1751 | if (ret) { | |
1752 | goto end; | |
1753 | } | |
1754 | ||
1755 | if (!is_open) { | |
83d6d6c4 JR |
1756 | ret = mi_lttng_writer_close_element(writer); |
1757 | if (ret) { | |
1758 | goto end; | |
1759 | } | |
159b042f JG |
1760 | } |
1761 | end: | |
1762 | return ret; | |
1763 | } | |
2d97a006 | 1764 | |
159b042f | 1765 | int mi_lttng_integral_process_attribute_value(struct mi_writer *writer, |
28ab034a JG |
1766 | enum lttng_process_attr process_attr, |
1767 | int64_t value, | |
1768 | bool is_open) | |
159b042f JG |
1769 | { |
1770 | int ret; | |
1771 | const char *element_id_tracker, *element_target_id; | |
2d97a006 | 1772 | |
28ab034a | 1773 | ret = get_tracker_elements(process_attr, &element_id_tracker, &element_target_id); |
159b042f JG |
1774 | if (ret) { |
1775 | return ret; | |
1776 | } | |
1777 | ||
1778 | ret = mi_lttng_writer_open_element(writer, element_target_id); | |
1779 | if (ret) { | |
1780 | goto end; | |
1781 | } | |
1782 | ||
1783 | ret = mi_lttng_writer_open_element(writer, config_element_type); | |
1784 | if (ret) { | |
1785 | goto end; | |
1786 | } | |
1787 | ||
1788 | ret = mi_lttng_writer_write_element_signed_int( | |
28ab034a | 1789 | writer, config_element_process_attr_id, value); |
159b042f JG |
1790 | if (ret) { |
1791 | goto end; | |
1792 | } | |
1793 | ||
1794 | ret = mi_lttng_writer_close_element(writer); | |
1795 | if (ret) { | |
1796 | goto end; | |
1797 | } | |
1798 | ||
1799 | if (!is_open) { | |
83d6d6c4 JR |
1800 | ret = mi_lttng_writer_close_element(writer); |
1801 | if (ret) { | |
1802 | goto end; | |
1803 | } | |
159b042f JG |
1804 | } |
1805 | ||
1806 | end: | |
1807 | return ret; | |
1808 | } | |
1809 | ||
159b042f | 1810 | int mi_lttng_string_process_attribute_value(struct mi_writer *writer, |
28ab034a JG |
1811 | enum lttng_process_attr process_attr, |
1812 | const char *value, | |
1813 | bool is_open) | |
159b042f JG |
1814 | |
1815 | { | |
1816 | int ret; | |
1817 | const char *element_id_tracker, *element_target_id; | |
1818 | ||
28ab034a | 1819 | ret = get_tracker_elements(process_attr, &element_id_tracker, &element_target_id); |
159b042f JG |
1820 | if (ret) { |
1821 | return ret; | |
1822 | } | |
1823 | ||
1824 | ret = mi_lttng_writer_open_element(writer, element_target_id); | |
1825 | if (ret) { | |
1826 | goto end; | |
1827 | } | |
1828 | ||
1829 | ret = mi_lttng_writer_open_element(writer, config_element_type); | |
1830 | if (ret) { | |
1831 | goto end; | |
1832 | } | |
1833 | ||
28ab034a | 1834 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, value); |
159b042f JG |
1835 | if (ret) { |
1836 | goto end; | |
1837 | } | |
1838 | ||
1839 | ret = mi_lttng_writer_close_element(writer); | |
1840 | if (ret) { | |
83d6d6c4 | 1841 | goto end; |
ebbf5ab7 | 1842 | } |
5e18ec73 JR |
1843 | |
1844 | if (!is_open) { | |
5e18ec73 | 1845 | ret = mi_lttng_writer_close_element(writer); |
ebbf5ab7 JR |
1846 | if (ret) { |
1847 | goto end; | |
1848 | } | |
5e18ec73 JR |
1849 | } |
1850 | ||
1851 | end: | |
1852 | return ret; | |
1853 | } | |
1854 | ||
5e18ec73 JR |
1855 | int mi_lttng_event_fields_open(struct mi_writer *writer) |
1856 | { | |
1857 | return mi_lttng_writer_open_element(writer, mi_lttng_element_event_fields); | |
1858 | } | |
1859 | ||
28ab034a | 1860 | int mi_lttng_event_field(struct mi_writer *writer, struct lttng_event_field *field) |
5e18ec73 JR |
1861 | { |
1862 | int ret; | |
1863 | ||
1864 | if (!field->field_name[0]) { | |
5e18ec73 JR |
1865 | ret = 0; |
1866 | goto end; | |
1867 | } | |
1868 | ||
1869 | /* Open field */ | |
1870 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_event_field); | |
1871 | if (ret) { | |
1872 | goto end; | |
1873 | } | |
1874 | ||
1875 | if (!field->field_name[0]) { | |
1876 | goto close; | |
1877 | } | |
1878 | ||
1879 | /* Name */ | |
28ab034a | 1880 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, field->field_name); |
5e18ec73 JR |
1881 | if (ret) { |
1882 | goto end; | |
1883 | } | |
1884 | ||
1885 | /* Type */ | |
28ab034a JG |
1886 | ret = mi_lttng_writer_write_element_string( |
1887 | writer, config_element_type, mi_lttng_eventfieldtype_string(field->type)); | |
5e18ec73 JR |
1888 | if (ret) { |
1889 | goto end; | |
1890 | } | |
1891 | ||
1892 | /* nowrite */ | |
28ab034a JG |
1893 | ret = mi_lttng_writer_write_element_signed_int( |
1894 | writer, mi_lttng_element_nowrite, field->nowrite); | |
5e18ec73 JR |
1895 | if (ret) { |
1896 | goto end; | |
1897 | } | |
1898 | ||
1899 | close: | |
1900 | /* Close field element */ | |
1901 | ret = mi_lttng_writer_close_element(writer); | |
1902 | ||
1903 | end: | |
1904 | return ret; | |
1905 | } | |
7e66b1b0 | 1906 | |
a23cb78a | 1907 | int mi_lttng_perf_counter_context(struct mi_writer *writer, |
28ab034a | 1908 | struct lttng_event_perf_counter_ctx *perf_context) |
89b72577 JRJ |
1909 | { |
1910 | int ret; | |
a23cb78a JG |
1911 | |
1912 | /* Open perf_counter_context */ | |
28ab034a | 1913 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_perf_counter_context); |
89b72577 JRJ |
1914 | if (ret) { |
1915 | goto end; | |
1916 | } | |
1917 | ||
a23cb78a | 1918 | /* Type */ |
28ab034a JG |
1919 | ret = mi_lttng_writer_write_element_unsigned_int( |
1920 | writer, config_element_type, perf_context->type); | |
a23cb78a | 1921 | if (ret) { |
89b72577 JRJ |
1922 | goto end; |
1923 | } | |
1924 | ||
a23cb78a | 1925 | /* Config */ |
28ab034a JG |
1926 | ret = mi_lttng_writer_write_element_unsigned_int( |
1927 | writer, config_element_config, perf_context->config); | |
a23cb78a JG |
1928 | if (ret) { |
1929 | goto end; | |
89b72577 JRJ |
1930 | } |
1931 | ||
a23cb78a | 1932 | /* Name of the perf counter */ |
28ab034a | 1933 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, perf_context->name); |
a23cb78a JG |
1934 | if (ret) { |
1935 | goto end; | |
89b72577 JRJ |
1936 | } |
1937 | ||
a23cb78a JG |
1938 | /* Close perf_counter_context */ |
1939 | ret = mi_lttng_writer_close_element(writer); | |
89b72577 JRJ |
1940 | end: |
1941 | return ret; | |
1942 | } | |
1943 | ||
28ab034a JG |
1944 | static int |
1945 | mi_lttng_app_context(struct mi_writer *writer, const char *provider_name, const char *ctx_name) | |
89b72577 JRJ |
1946 | { |
1947 | int ret; | |
1948 | ||
a23cb78a | 1949 | /* Open app */ |
28ab034a | 1950 | ret = mi_lttng_writer_open_element(writer, config_element_context_app); |
89b72577 JRJ |
1951 | if (ret) { |
1952 | goto end; | |
1953 | } | |
1954 | ||
a23cb78a | 1955 | /* provider_name */ |
28ab034a JG |
1956 | ret = mi_lttng_writer_write_element_string( |
1957 | writer, config_element_context_app_provider_name, provider_name); | |
89b72577 JRJ |
1958 | if (ret) { |
1959 | goto end; | |
1960 | } | |
1961 | ||
a23cb78a | 1962 | /* ctx_name */ |
28ab034a JG |
1963 | ret = mi_lttng_writer_write_element_string( |
1964 | writer, config_element_context_app_ctx_name, ctx_name); | |
89b72577 JRJ |
1965 | if (ret) { |
1966 | goto end; | |
1967 | } | |
1968 | ||
a23cb78a JG |
1969 | /* Close app */ |
1970 | ret = mi_lttng_writer_close_element(writer); | |
1971 | end: | |
1972 | return ret; | |
1973 | } | |
1974 | ||
28ab034a | 1975 | int mi_lttng_context(struct mi_writer *writer, struct lttng_event_context *context, int is_open) |
a23cb78a JG |
1976 | { |
1977 | int ret; | |
1978 | ||
1979 | /* Open context */ | |
28ab034a | 1980 | ret = mi_lttng_writer_open_element(writer, config_element_context); |
89b72577 JRJ |
1981 | if (ret) { |
1982 | goto end; | |
1983 | } | |
1984 | ||
a23cb78a JG |
1985 | /* Special case for PERF_*_COUNTER |
1986 | * print the lttng_event_perf_counter_ctx*/ | |
1987 | switch (context->ctx) { | |
1988 | case LTTNG_EVENT_CONTEXT_PERF_COUNTER: | |
1989 | case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER: | |
1990 | case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER: | |
1991 | { | |
28ab034a JG |
1992 | struct lttng_event_perf_counter_ctx *perf_context = &context->u.perf_counter; |
1993 | ret = mi_lttng_perf_counter_context(writer, perf_context); | |
a23cb78a JG |
1994 | if (ret) { |
1995 | goto end; | |
1996 | } | |
1997 | break; | |
1998 | } | |
1999 | case LTTNG_EVENT_CONTEXT_APP_CONTEXT: | |
2000 | { | |
28ab034a JG |
2001 | ret = mi_lttng_app_context( |
2002 | writer, context->u.app_ctx.provider_name, context->u.app_ctx.ctx_name); | |
a23cb78a JG |
2003 | if (ret) { |
2004 | goto end; | |
2005 | } | |
2006 | break; | |
2007 | } | |
2008 | default: | |
2009 | { | |
28ab034a | 2010 | const char *type_string = mi_lttng_event_contexttype_string(context->ctx); |
a23cb78a JG |
2011 | if (!type_string) { |
2012 | ret = -LTTNG_ERR_INVALID; | |
2013 | goto end; | |
2014 | } | |
2015 | ||
2016 | /* Print context type */ | |
28ab034a JG |
2017 | ret = mi_lttng_writer_write_element_string( |
2018 | writer, config_element_type, type_string); | |
a23cb78a JG |
2019 | break; |
2020 | } | |
2021 | } | |
2022 | ||
2023 | /* Close context */ | |
2024 | if (!is_open) { | |
2025 | ret = mi_lttng_writer_close_element(writer); | |
2026 | } | |
2027 | ||
89b72577 JRJ |
2028 | end: |
2029 | return ret; | |
2030 | } | |
50534d6f | 2031 | |
28ab034a | 2032 | int mi_lttng_snapshot_output_session_name(struct mi_writer *writer, const char *session_name) |
50534d6f JRJ |
2033 | { |
2034 | int ret; | |
2035 | ||
2036 | /* Open session element */ | |
2037 | ret = mi_lttng_writer_open_element(writer, config_element_session); | |
2038 | if (ret) { | |
2039 | goto end; | |
2040 | } | |
2041 | ||
2042 | /* Snapshot output list for current session name */ | |
28ab034a | 2043 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, session_name); |
01defc26 JR |
2044 | if (ret) { |
2045 | goto end; | |
2046 | } | |
50534d6f JRJ |
2047 | |
2048 | /* Open element snapshots (sequence one snapshot) */ | |
2049 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_snapshots); | |
2050 | if (ret) { | |
2051 | goto end; | |
2052 | } | |
2053 | ||
2054 | end: | |
2055 | return ret; | |
2056 | } | |
2057 | ||
50534d6f | 2058 | int mi_lttng_snapshot_list_output(struct mi_writer *writer, |
28ab034a | 2059 | const struct lttng_snapshot_output *output) |
50534d6f JRJ |
2060 | { |
2061 | int ret; | |
2062 | ||
2063 | /* Open element snapshot output */ | |
28ab034a | 2064 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_snapshot); |
50534d6f JRJ |
2065 | if (ret) { |
2066 | goto end; | |
2067 | } | |
2068 | ||
2069 | /* ID of the snapshot output */ | |
28ab034a | 2070 | ret = mi_lttng_writer_write_element_unsigned_int(writer, mi_lttng_element_id, output->id); |
50534d6f JRJ |
2071 | if (ret) { |
2072 | goto end; | |
2073 | } | |
2074 | ||
2075 | /* Name of the output */ | |
28ab034a | 2076 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, output->name); |
50534d6f JRJ |
2077 | if (ret) { |
2078 | goto end; | |
2079 | } | |
2080 | ||
2081 | /* Destination of the output (ctrl_url)*/ | |
28ab034a JG |
2082 | ret = mi_lttng_writer_write_element_string( |
2083 | writer, mi_lttng_element_snapshot_ctrl_url, output->ctrl_url); | |
50534d6f JRJ |
2084 | if (ret) { |
2085 | goto end; | |
2086 | } | |
2087 | ||
2088 | /* Destination of the output (data_url) */ | |
28ab034a JG |
2089 | ret = mi_lttng_writer_write_element_string( |
2090 | writer, mi_lttng_element_snapshot_data_url, output->data_url); | |
50534d6f JRJ |
2091 | if (ret) { |
2092 | goto end; | |
2093 | } | |
2094 | ||
2095 | /* total size of all stream combined */ | |
28ab034a JG |
2096 | ret = mi_lttng_writer_write_element_unsigned_int( |
2097 | writer, mi_lttng_element_snapshot_max_size, output->max_size); | |
50534d6f JRJ |
2098 | if (ret) { |
2099 | goto end; | |
2100 | } | |
2101 | ||
2102 | /* Close snapshot output element */ | |
2103 | ret = mi_lttng_writer_close_element(writer); | |
2104 | ||
2105 | end: | |
2106 | return ret; | |
2107 | } | |
2108 | ||
28ab034a JG |
2109 | int mi_lttng_snapshot_del_output(struct mi_writer *writer, |
2110 | int id, | |
2111 | const char *name, | |
2112 | const char *current_session_name) | |
50534d6f JRJ |
2113 | { |
2114 | int ret; | |
2115 | ||
2116 | /* Open element del_snapshot */ | |
28ab034a | 2117 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_snapshot); |
50534d6f JRJ |
2118 | if (ret) { |
2119 | goto end; | |
2120 | } | |
2121 | ||
50534d6f JRJ |
2122 | if (id != UINT32_MAX) { |
2123 | /* "Snapshot output "id" successfully deleted | |
2124 | * for "current_session_name" | |
2125 | * ID of the snapshot output | |
2126 | */ | |
28ab034a | 2127 | ret = mi_lttng_writer_write_element_unsigned_int(writer, mi_lttng_element_id, id); |
50534d6f JRJ |
2128 | if (ret) { |
2129 | goto end; | |
2130 | } | |
2131 | } else { | |
2132 | /* "Snapshot output "name" successfully deleted | |
2133 | * for session "current_session_name" | |
2134 | * Name of the output | |
2135 | */ | |
28ab034a | 2136 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, name); |
50534d6f JRJ |
2137 | if (ret) { |
2138 | goto end; | |
2139 | } | |
2140 | } | |
2141 | ||
2142 | /* Snapshot was deleted for session "current_session_name"*/ | |
28ab034a JG |
2143 | ret = mi_lttng_writer_write_element_string( |
2144 | writer, mi_lttng_element_snapshot_session_name, current_session_name); | |
50534d6f JRJ |
2145 | if (ret) { |
2146 | goto end; | |
2147 | } | |
2148 | ||
2149 | /* Close snapshot element */ | |
2150 | ret = mi_lttng_writer_close_element(writer); | |
2151 | ||
2152 | end: | |
2153 | return ret; | |
2154 | } | |
2155 | ||
50534d6f | 2156 | int mi_lttng_snapshot_add_output(struct mi_writer *writer, |
28ab034a JG |
2157 | const char *current_session_name, |
2158 | const char *n_ptr, | |
2159 | struct lttng_snapshot_output *output) | |
50534d6f JRJ |
2160 | { |
2161 | int ret; | |
2162 | ||
2163 | /* Open element snapshot */ | |
28ab034a | 2164 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_snapshot); |
50534d6f JRJ |
2165 | if (ret) { |
2166 | goto end; | |
2167 | } | |
2168 | ||
2169 | /* Snapshot output id */ | |
28ab034a | 2170 | ret = mi_lttng_writer_write_element_unsigned_int(writer, mi_lttng_element_id, output->id); |
50534d6f JRJ |
2171 | if (ret) { |
2172 | goto end; | |
2173 | } | |
2174 | ||
2175 | /* Snapshot output names */ | |
28ab034a | 2176 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, n_ptr); |
50534d6f JRJ |
2177 | if (ret) { |
2178 | goto end; | |
2179 | } | |
2180 | ||
2181 | /* Destination of the output (ctrl_url)*/ | |
28ab034a JG |
2182 | ret = mi_lttng_writer_write_element_string( |
2183 | writer, mi_lttng_element_snapshot_ctrl_url, output->ctrl_url); | |
50534d6f JRJ |
2184 | if (ret) { |
2185 | goto end; | |
2186 | } | |
2187 | ||
2188 | /* Snapshot added for session "current_session_name"*/ | |
28ab034a JG |
2189 | ret = mi_lttng_writer_write_element_string( |
2190 | writer, mi_lttng_element_snapshot_session_name, current_session_name); | |
50534d6f JRJ |
2191 | if (ret) { |
2192 | goto end; | |
2193 | } | |
2194 | ||
2195 | /* total size of all stream combined */ | |
28ab034a JG |
2196 | ret = mi_lttng_writer_write_element_unsigned_int( |
2197 | writer, mi_lttng_element_snapshot_max_size, output->max_size); | |
50534d6f JRJ |
2198 | if (ret) { |
2199 | goto end; | |
2200 | } | |
2201 | ||
2202 | /* Close snapshot element */ | |
2203 | ret = mi_lttng_writer_close_element(writer); | |
2204 | ||
2205 | end: | |
2206 | return ret; | |
2207 | } | |
2208 | ||
28ab034a JG |
2209 | int mi_lttng_snapshot_record(struct mi_writer *writer, |
2210 | const char *url, | |
2211 | const char *cmdline_ctrl_url, | |
2212 | const char *cmdline_data_url) | |
50534d6f JRJ |
2213 | { |
2214 | int ret; | |
2215 | ||
2216 | /* Open element snapshot */ | |
28ab034a | 2217 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_snapshot); |
50534d6f JRJ |
2218 | if (ret) { |
2219 | goto end; | |
2220 | } | |
2221 | ||
2222 | /* | |
2223 | * If a valid an URL was given, serialize it, | |
2224 | * else take the command line data and ctrl urls*/ | |
2225 | if (url) { | |
2226 | /* Destination of the output (ctrl_url)*/ | |
28ab034a JG |
2227 | ret = mi_lttng_writer_write_element_string( |
2228 | writer, mi_lttng_element_snapshot_ctrl_url, url); | |
50534d6f JRJ |
2229 | if (ret) { |
2230 | goto end; | |
2231 | } | |
2232 | } else if (cmdline_ctrl_url) { | |
2233 | /* Destination of the output (ctrl_url)*/ | |
28ab034a JG |
2234 | ret = mi_lttng_writer_write_element_string( |
2235 | writer, mi_lttng_element_snapshot_ctrl_url, cmdline_ctrl_url); | |
50534d6f JRJ |
2236 | if (ret) { |
2237 | goto end; | |
2238 | } | |
2239 | ||
2240 | /* Destination of the output (data_url) */ | |
28ab034a JG |
2241 | ret = mi_lttng_writer_write_element_string( |
2242 | writer, mi_lttng_element_snapshot_data_url, cmdline_data_url); | |
50534d6f JRJ |
2243 | if (ret) { |
2244 | goto end; | |
2245 | } | |
2246 | } | |
2247 | ||
2248 | /* Close record_snapshot element */ | |
2249 | ret = mi_lttng_writer_close_element(writer); | |
2250 | ||
2251 | end: | |
2252 | return ret; | |
2253 | } | |
66ea93b1 | 2254 | |
66ea93b1 | 2255 | int mi_lttng_rotation_schedule(struct mi_writer *writer, |
28ab034a | 2256 | const struct lttng_rotation_schedule *schedule) |
66ea93b1 JG |
2257 | { |
2258 | int ret = 0; | |
2259 | enum lttng_rotation_status status; | |
2260 | uint64_t value; | |
2261 | const char *element_name; | |
2262 | const char *value_name; | |
2263 | bool empty_schedule = false; | |
2264 | ||
2265 | switch (lttng_rotation_schedule_get_type(schedule)) { | |
2266 | case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC: | |
28ab034a | 2267 | status = lttng_rotation_schedule_periodic_get_period(schedule, &value); |
66ea93b1 | 2268 | element_name = mi_lttng_element_rotation_schedule_periodic; |
3b13cbcc | 2269 | value_name = mi_lttng_element_rotation_schedule_periodic_time_us; |
66ea93b1 JG |
2270 | break; |
2271 | case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD: | |
28ab034a | 2272 | status = lttng_rotation_schedule_size_threshold_get_threshold(schedule, &value); |
66ea93b1 | 2273 | element_name = mi_lttng_element_rotation_schedule_size_threshold; |
3b13cbcc | 2274 | value_name = mi_lttng_element_rotation_schedule_size_threshold_bytes; |
66ea93b1 JG |
2275 | break; |
2276 | default: | |
2277 | ret = -1; | |
2278 | goto end; | |
2279 | } | |
2280 | ||
2281 | if (status != LTTNG_ROTATION_STATUS_OK) { | |
2282 | if (status == LTTNG_ROTATION_STATUS_UNAVAILABLE) { | |
2283 | empty_schedule = true; | |
2284 | } else { | |
2285 | ret = -1; | |
2286 | goto end; | |
2287 | } | |
2288 | } | |
2289 | ||
2290 | ret = mi_lttng_writer_open_element(writer, element_name); | |
2291 | if (ret) { | |
2292 | goto end; | |
2293 | } | |
2294 | ||
2295 | if (!empty_schedule) { | |
28ab034a | 2296 | ret = mi_lttng_writer_write_element_unsigned_int(writer, value_name, value); |
66ea93b1 JG |
2297 | if (ret) { |
2298 | goto end; | |
2299 | } | |
2300 | } | |
2301 | ||
2302 | /* Close schedule descriptor element. */ | |
2303 | ret = mi_lttng_writer_close_element(writer); | |
2304 | if (ret) { | |
2305 | goto end; | |
2306 | } | |
2307 | end: | |
2308 | return ret; | |
2309 | } | |
2310 | ||
66ea93b1 | 2311 | int mi_lttng_rotation_schedule_result(struct mi_writer *writer, |
28ab034a JG |
2312 | const struct lttng_rotation_schedule *schedule, |
2313 | bool success) | |
66ea93b1 JG |
2314 | { |
2315 | int ret = 0; | |
2316 | ||
28ab034a | 2317 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_rotation_schedule_result); |
66ea93b1 JG |
2318 | if (ret) { |
2319 | goto end; | |
2320 | } | |
2321 | ||
28ab034a | 2322 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_rotation_schedule); |
66ea93b1 JG |
2323 | if (ret) { |
2324 | goto end; | |
2325 | } | |
2326 | ||
2327 | ret = mi_lttng_rotation_schedule(writer, schedule); | |
2328 | if (ret) { | |
2329 | goto end; | |
2330 | } | |
2331 | ||
2332 | /* Close rotation_schedule element */ | |
2333 | ret = mi_lttng_writer_close_element(writer); | |
2334 | if (ret) { | |
2335 | goto end; | |
2336 | } | |
2337 | ||
28ab034a | 2338 | ret = mi_lttng_writer_write_element_bool(writer, mi_lttng_element_command_success, success); |
66ea93b1 JG |
2339 | if (ret) { |
2340 | goto end; | |
2341 | } | |
2342 | ||
2343 | /* Close rotation_schedule_result element */ | |
3b13cbcc | 2344 | ret = mi_lttng_writer_close_element(writer); |
66ea93b1 JG |
2345 | if (ret) { |
2346 | goto end; | |
2347 | } | |
2348 | end: | |
2349 | return ret; | |
2350 | } | |
91c4d516 | 2351 | |
28ab034a JG |
2352 | static int mi_lttng_location(struct mi_writer *writer, |
2353 | const struct lttng_trace_archive_location *location) | |
91c4d516 JG |
2354 | { |
2355 | int ret = 0; | |
2356 | enum lttng_trace_archive_location_type location_type; | |
2357 | enum lttng_trace_archive_location_status status; | |
2358 | ||
2359 | location_type = lttng_trace_archive_location_get_type(location); | |
2360 | ||
2361 | switch (location_type) { | |
2362 | case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL: | |
2363 | { | |
2364 | const char *absolute_path; | |
2365 | ||
28ab034a JG |
2366 | status = lttng_trace_archive_location_local_get_absolute_path(location, |
2367 | &absolute_path); | |
91c4d516 JG |
2368 | if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) { |
2369 | ret = -1; | |
2370 | goto end; | |
2371 | } | |
2372 | ||
2373 | ret = mi_lttng_writer_open_element(writer, | |
28ab034a | 2374 | mi_lttng_element_rotation_location_local); |
91c4d516 JG |
2375 | if (ret) { |
2376 | goto end; | |
2377 | } | |
2378 | ||
28ab034a JG |
2379 | ret = mi_lttng_writer_write_element_string( |
2380 | writer, | |
2381 | mi_lttng_element_rotation_location_local_absolute_path, | |
2382 | absolute_path); | |
91c4d516 JG |
2383 | if (ret) { |
2384 | goto end; | |
2385 | } | |
2386 | ||
2387 | /* Close local element */ | |
2388 | ret = mi_lttng_writer_close_element(writer); | |
2389 | if (ret) { | |
2390 | goto end; | |
2391 | } | |
2392 | break; | |
2393 | } | |
2394 | case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY: | |
2395 | { | |
2396 | uint16_t control_port, data_port; | |
2397 | const char *host, *relative_path; | |
2398 | enum lttng_trace_archive_location_relay_protocol_type protocol; | |
2399 | ||
2400 | /* Fetch all relay location parameters. */ | |
28ab034a | 2401 | status = lttng_trace_archive_location_relay_get_protocol_type(location, &protocol); |
91c4d516 JG |
2402 | if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) { |
2403 | ret = -1; | |
2404 | goto end; | |
2405 | } | |
2406 | ||
28ab034a | 2407 | status = lttng_trace_archive_location_relay_get_host(location, &host); |
91c4d516 JG |
2408 | if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) { |
2409 | ret = -1; | |
2410 | goto end; | |
2411 | } | |
2412 | ||
28ab034a JG |
2413 | status = lttng_trace_archive_location_relay_get_control_port(location, |
2414 | &control_port); | |
91c4d516 JG |
2415 | if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) { |
2416 | ret = -1; | |
2417 | goto end; | |
2418 | } | |
2419 | ||
28ab034a | 2420 | status = lttng_trace_archive_location_relay_get_data_port(location, &data_port); |
91c4d516 JG |
2421 | if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) { |
2422 | ret = -1; | |
2423 | goto end; | |
2424 | } | |
2425 | ||
28ab034a JG |
2426 | status = lttng_trace_archive_location_relay_get_relative_path(location, |
2427 | &relative_path); | |
91c4d516 JG |
2428 | if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) { |
2429 | ret = -1; | |
2430 | goto end; | |
2431 | } | |
2432 | ||
2433 | ret = mi_lttng_writer_open_element(writer, | |
28ab034a | 2434 | mi_lttng_element_rotation_location_relay); |
91c4d516 JG |
2435 | if (ret) { |
2436 | goto end; | |
2437 | } | |
2438 | ||
28ab034a JG |
2439 | ret = mi_lttng_writer_write_element_string( |
2440 | writer, mi_lttng_element_rotation_location_relay_host, host); | |
91c4d516 JG |
2441 | if (ret) { |
2442 | goto end; | |
2443 | } | |
2444 | ||
28ab034a JG |
2445 | ret = mi_lttng_writer_write_element_unsigned_int( |
2446 | writer, | |
2447 | mi_lttng_element_rotation_location_relay_control_port, | |
2448 | control_port); | |
91c4d516 JG |
2449 | if (ret) { |
2450 | goto end; | |
2451 | } | |
2452 | ||
28ab034a JG |
2453 | ret = mi_lttng_writer_write_element_unsigned_int( |
2454 | writer, mi_lttng_element_rotation_location_relay_data_port, data_port); | |
91c4d516 JG |
2455 | if (ret) { |
2456 | goto end; | |
2457 | } | |
2458 | ||
28ab034a JG |
2459 | ret = mi_lttng_writer_write_element_string( |
2460 | writer, | |
2461 | mi_lttng_element_rotation_location_relay_protocol, | |
2462 | mi_lttng_trace_archive_location_relay_protocol_type_string(protocol)); | |
91c4d516 JG |
2463 | if (ret) { |
2464 | goto end; | |
2465 | } | |
2466 | ||
28ab034a JG |
2467 | ret = mi_lttng_writer_write_element_string( |
2468 | writer, | |
2469 | mi_lttng_element_rotation_location_relay_relative_path, | |
2470 | relative_path); | |
91c4d516 JG |
2471 | if (ret) { |
2472 | goto end; | |
2473 | } | |
2474 | ||
2475 | /* Close relay element */ | |
2476 | ret = mi_lttng_writer_close_element(writer); | |
2477 | if (ret) { | |
2478 | goto end; | |
2479 | } | |
2480 | break; | |
2481 | } | |
2482 | default: | |
2483 | abort(); | |
2484 | } | |
2485 | end: | |
2486 | return ret; | |
2487 | } | |
2488 | ||
91c4d516 | 2489 | int mi_lttng_rotate(struct mi_writer *writer, |
28ab034a JG |
2490 | const char *session_name, |
2491 | enum lttng_rotation_state rotation_state, | |
2492 | const struct lttng_trace_archive_location *location) | |
91c4d516 JG |
2493 | { |
2494 | int ret; | |
2495 | ||
28ab034a | 2496 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_rotation); |
91c4d516 JG |
2497 | if (ret) { |
2498 | goto end; | |
2499 | } | |
2500 | ||
28ab034a JG |
2501 | ret = mi_lttng_writer_write_element_string( |
2502 | writer, mi_lttng_element_session_name, session_name); | |
91c4d516 JG |
2503 | if (ret) { |
2504 | goto end; | |
2505 | } | |
2506 | ||
2507 | ret = mi_lttng_writer_write_element_string(writer, | |
28ab034a JG |
2508 | mi_lttng_element_rotation_state, |
2509 | mi_lttng_rotation_state_string(rotation_state)); | |
91c4d516 JG |
2510 | if (ret) { |
2511 | goto end; | |
2512 | } | |
2513 | ||
2514 | if (!location) { | |
2515 | /* Not a serialization error. */ | |
2516 | goto close_rotation; | |
2517 | } | |
2518 | ||
28ab034a | 2519 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_rotation_location); |
91c4d516 JG |
2520 | if (ret) { |
2521 | goto end; | |
2522 | } | |
2523 | ||
2524 | ret = mi_lttng_location(writer, location); | |
2525 | if (ret) { | |
2526 | goto close_location; | |
2527 | } | |
2528 | ||
2529 | close_location: | |
2530 | /* Close location element */ | |
2531 | ret = mi_lttng_writer_close_element(writer); | |
2532 | if (ret) { | |
2533 | goto end; | |
2534 | } | |
a6bc4ca9 | 2535 | |
91c4d516 JG |
2536 | close_rotation: |
2537 | /* Close rotation element */ | |
2538 | ret = mi_lttng_writer_close_element(writer); | |
2539 | if (ret) { | |
2540 | goto end; | |
2541 | } | |
2542 | end: | |
2543 | return ret; | |
2544 | } |