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