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