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