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