Commit | Line | Data |
---|---|---|
c7e35b03 JR |
1 | /* |
2 | * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com> | |
3 | * - Olivier Cotte <olivier.cotte@polymtl.ca> | |
e10b6a1c | 4 | * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com> |
c7e35b03 JR |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License, version 2 only, as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along with | |
16 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
17 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
19 | ||
6c1c0768 | 20 | #define _LGPL_SOURCE |
f40ef1d5 | 21 | #include <common/config/session-config.h> |
41af1adf | 22 | #include <common/defaults.h> |
50534d6f | 23 | #include <lttng/snapshot-internal.h> |
fb83fe64 | 24 | #include <lttng/channel.h> |
c7e35b03 JR |
25 | #include "mi-lttng.h" |
26 | ||
5e18ec73 JR |
27 | #include <assert.h> |
28 | ||
e10b6a1c JG |
29 | #define MI_SCHEMA_MAJOR_VERSION 3 |
30 | #define MI_SCHEMA_MINOR_VERSION 0 | |
31 | ||
32 | /* Machine interface namespace URI */ | |
c8ecdbb0 JG |
33 | LTTNG_HIDDEN const char * const mi_lttng_xmlns = "xmlns"; |
34 | LTTNG_HIDDEN const char * const mi_lttng_xmlns_xsi = "xmlns:xsi"; | |
35 | LTTNG_HIDDEN const char * const mi_lttng_w3_schema_uri = "http://www.w3.org/2001/XMLSchema-instance"; | |
36 | LTTNG_HIDDEN const char * const mi_lttng_schema_location = "xsi:schemaLocation"; | |
37 | LTTNG_HIDDEN const char * const mi_lttng_schema_location_uri = | |
41af1adf | 38 | DEFAULT_LTTNG_MI_NAMESPACE " " |
e10b6a1c JG |
39 | "http://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION) |
40 | "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION) "." | |
41 | XSTR(MI_SCHEMA_MINOR_VERSION) ".xsd"; | |
c8ecdbb0 JG |
42 | LTTNG_HIDDEN const char * const mi_lttng_schema_version = "schemaVersion"; |
43 | LTTNG_HIDDEN const char * const mi_lttng_schema_version_value = XSTR(MI_SCHEMA_MAJOR_VERSION) | |
e10b6a1c JG |
44 | "." XSTR(MI_SCHEMA_MINOR_VERSION); |
45 | ||
c7e35b03 JR |
46 | /* Strings related to command */ |
47 | const char * const mi_lttng_element_command = "command"; | |
f4a088f7 JRJ |
48 | const char * const mi_lttng_element_command_action = "snapshot_action"; |
49 | const char * const mi_lttng_element_command_add_context = "add-context"; | |
f4a088f7 JRJ |
50 | const char * const mi_lttng_element_command_create = "create"; |
51 | const char * const mi_lttng_element_command_destroy = "destroy"; | |
52 | const char * const mi_lttng_element_command_disable_channel = "disable-channel"; | |
53 | const char * const mi_lttng_element_command_disable_event = "disable-event"; | |
54 | const char * const mi_lttng_element_command_enable_channels = "enable-channel"; | |
89476427 | 55 | const char * const mi_lttng_element_command_enable_event = "enable-event"; |
c7e35b03 | 56 | const char * const mi_lttng_element_command_list = "list"; |
1734c658 | 57 | const char * const mi_lttng_element_command_load = "load"; |
c8ecdbb0 JG |
58 | LTTNG_HIDDEN const char * const mi_lttng_element_command_metadata = "metadata"; |
59 | LTTNG_HIDDEN const char * const mi_lttng_element_command_metadata_action = "metadata_action"; | |
eded6438 JD |
60 | LTTNG_HIDDEN const char * const mi_lttng_element_command_regenerate = "regenerate"; |
61 | LTTNG_HIDDEN const char * const mi_lttng_element_command_regenerate_action = "regenerate_action"; | |
f4a088f7 JRJ |
62 | const char * const mi_lttng_element_command_name = "name"; |
63 | const char * const mi_lttng_element_command_output = "output"; | |
64 | const char * const mi_lttng_element_command_save = "save"; | |
65 | const char * const mi_lttng_element_command_set_session = "set-session"; | |
66 | const char * const mi_lttng_element_command_snapshot = "snapshot"; | |
67 | const char * const mi_lttng_element_command_snapshot_add = "add_snapshot"; | |
68 | const char * const mi_lttng_element_command_snapshot_del = "del_snapshot"; | |
69 | const char * const mi_lttng_element_command_snapshot_list = "list_snapshot"; | |
70 | const char * const mi_lttng_element_command_snapshot_record = "record_snapshot"; | |
1cfc0bc8 | 71 | const char * const mi_lttng_element_command_start = "start"; |
e5b83100 | 72 | const char * const mi_lttng_element_command_stop = "stop"; |
1734c658 | 73 | const char * const mi_lttng_element_command_success = "success"; |
ccf10263 MD |
74 | const char * const mi_lttng_element_command_track = "track"; |
75 | const char * const mi_lttng_element_command_untrack = "untrack"; | |
f4a088f7 | 76 | const char * const mi_lttng_element_command_version = "version"; |
c7e35b03 | 77 | |
1734c658 | 78 | /* Strings related to version command */ |
c7e35b03 | 79 | const char * const mi_lttng_element_version = "version"; |
314d5222 | 80 | const char * const mi_lttng_element_version_commit = "commit"; |
f4a088f7 | 81 | const char * const mi_lttng_element_version_description = "description"; |
c7e35b03 | 82 | const char * const mi_lttng_element_version_license = "license"; |
f4a088f7 JRJ |
83 | const char * const mi_lttng_element_version_major = "major"; |
84 | const char * const mi_lttng_element_version_minor = "minor"; | |
c7e35b03 | 85 | const char * const mi_lttng_element_version_patch_level = "patchLevel"; |
f4a088f7 JRJ |
86 | const char * const mi_lttng_element_version_str = "string"; |
87 | const char * const mi_lttng_element_version_web = "url"; | |
1734c658 | 88 | |
5e18ec73 JR |
89 | /* String related to a lttng_event_field */ |
90 | const char * const mi_lttng_element_event_field = "event_field"; | |
91 | const char * const mi_lttng_element_event_fields = "event_fields"; | |
92 | ||
89b72577 | 93 | /* String related to lttng_event_perf_counter_ctx */ |
a23cb78a | 94 | const char * const mi_lttng_element_perf_counter_context = "perf"; |
89b72577 | 95 | |
f4a088f7 | 96 | /* Strings related to pid */ |
bf239d4c | 97 | const char * const mi_lttng_element_pid_id = "id"; |
f4a088f7 JRJ |
98 | |
99 | /* Strings related to save command */ | |
100 | const char * const mi_lttng_element_save = "save"; | |
101 | ||
102 | /* Strings related to load command */ | |
103 | const char * const mi_lttng_element_load = "load"; | |
23cb2d55 JR |
104 | LTTNG_HIDDEN const char * const mi_lttng_element_load_overrides = "overrides"; |
105 | LTTNG_HIDDEN const char * const mi_lttng_element_load_override_url = "url"; | |
f4a088f7 | 106 | |
5e18ec73 | 107 | /* General elements of mi_lttng */ |
f4a088f7 JRJ |
108 | const char * const mi_lttng_element_empty = ""; |
109 | const char * const mi_lttng_element_id = "id"; | |
110 | const char * const mi_lttng_element_nowrite = "nowrite"; | |
111 | const char * const mi_lttng_element_success = "success"; | |
5e18ec73 JR |
112 | const char * const mi_lttng_element_type_enum = "ENUM"; |
113 | const char * const mi_lttng_element_type_float = "FLOAT"; | |
f4a088f7 JRJ |
114 | const char * const mi_lttng_element_type_integer = "INTEGER"; |
115 | const char * const mi_lttng_element_type_other = "OTHER"; | |
5e18ec73 | 116 | const char * const mi_lttng_element_type_string = "STRING"; |
5e18ec73 JR |
117 | |
118 | /* String related to loglevel */ | |
119 | const char * const mi_lttng_loglevel_str_alert = "TRACE_ALERT"; | |
120 | const char * const mi_lttng_loglevel_str_crit = "TRACE_CRIT"; | |
121 | const char * const mi_lttng_loglevel_str_debug = "TRACE_DEBUG"; | |
122 | const char * const mi_lttng_loglevel_str_debug_function = "TRACE_DEBUG_FUNCTION"; | |
123 | const char * const mi_lttng_loglevel_str_debug_line = "TRACE_DEBUG_LINE"; | |
124 | const char * const mi_lttng_loglevel_str_debug_module = "TRACE_DEBUG_MODULE"; | |
125 | const char * const mi_lttng_loglevel_str_debug_process = "TRACE_DEBUG_PROCESS"; | |
126 | const char * const mi_lttng_loglevel_str_debug_program = "TRACE_DEBUG_PROGRAM"; | |
127 | const char * const mi_lttng_loglevel_str_debug_system = "TRACE_DEBUG_SYSTEM"; | |
128 | const char * const mi_lttng_loglevel_str_debug_unit = "TRACE_DEBUG_UNIT"; | |
129 | const char * const mi_lttng_loglevel_str_emerg = "TRACE_EMERG"; | |
130 | const char * const mi_lttng_loglevel_str_err = "TRACE_ERR"; | |
131 | const char * const mi_lttng_loglevel_str_info = "TRACE_INFO"; | |
132 | const char * const mi_lttng_loglevel_str_notice = "TRACE_NOTICE"; | |
133 | const char * const mi_lttng_loglevel_str_unknown = "UNKNOWN"; | |
134 | const char * const mi_lttng_loglevel_str_warning = "TRACE_WARNING"; | |
135 | ||
136f2f81 JRJ |
136 | /* String related to loglevel JUL */ |
137 | const char * const mi_lttng_loglevel_str_jul_all = "JUL_ALL"; | |
138 | const char * const mi_lttng_loglevel_str_jul_config = "JUL_CONFIG"; | |
139 | const char * const mi_lttng_loglevel_str_jul_fine = "JUL_FINE"; | |
140 | const char * const mi_lttng_loglevel_str_jul_finer = "JUL_FINER"; | |
141 | const char * const mi_lttng_loglevel_str_jul_finest = "JUL_FINEST"; | |
142 | const char * const mi_lttng_loglevel_str_jul_info = "JUL_INFO"; | |
143 | const char * const mi_lttng_loglevel_str_jul_off = "JUL_OFF"; | |
144 | const char * const mi_lttng_loglevel_str_jul_severe = "JUL_SEVERE"; | |
145 | const char * const mi_lttng_loglevel_str_jul_warning = "JUL_WARNING"; | |
146 | ||
970d848b DG |
147 | /* String related to loglevel LOG4J */ |
148 | const char * const mi_lttng_loglevel_str_log4j_off = "LOG4J_OFF"; | |
149 | const char * const mi_lttng_loglevel_str_log4j_fatal = "LOG4J_FATAL"; | |
150 | const char * const mi_lttng_loglevel_str_log4j_error = "LOG4J_ERROR"; | |
151 | const char * const mi_lttng_loglevel_str_log4j_warn = "LOG4J_WARN"; | |
152 | const char * const mi_lttng_loglevel_str_log4j_info = "LOG4J_INFO"; | |
153 | const char * const mi_lttng_loglevel_str_log4j_debug = "LOG4J_DEBUG"; | |
154 | const char * const mi_lttng_loglevel_str_log4j_trace = "LOG4J_TRACE"; | |
155 | const char * const mi_lttng_loglevel_str_log4j_all = "LOG4J_ALL"; | |
156 | ||
0e115563 DG |
157 | /* String related to loglevel Python */ |
158 | const char * const mi_lttng_loglevel_str_python_critical = "PYTHON_CRITICAL"; | |
159 | const char * const mi_lttng_loglevel_str_python_error = "PYTHON_ERROR"; | |
160 | const char * const mi_lttng_loglevel_str_python_warning = "PYTHON_WARNING"; | |
161 | const char * const mi_lttng_loglevel_str_python_info = "PYTHON_INFO"; | |
162 | const char * const mi_lttng_loglevel_str_python_debug = "PYTHON_DEBUG"; | |
163 | const char * const mi_lttng_loglevel_str_python_notset = "PYTHON_NOTSET"; | |
164 | ||
1734c658 | 165 | /* String related to loglevel type */ |
5e18ec73 JR |
166 | const char * const mi_lttng_loglevel_type_all = "ALL"; |
167 | const char * const mi_lttng_loglevel_type_range = "RANGE"; | |
168 | const char * const mi_lttng_loglevel_type_single = "SINGLE"; | |
169 | const char * const mi_lttng_loglevel_type_unknown = "UNKNOWN"; | |
170 | ||
50534d6f | 171 | /* String related to a lttng_snapshot_output */ |
50534d6f | 172 | const char * const mi_lttng_element_snapshot_ctrl_url = "ctrl_url"; |
f4a088f7 | 173 | const char * const mi_lttng_element_snapshot_data_url = "data_url"; |
50534d6f | 174 | const char * const mi_lttng_element_snapshot_max_size = "max_size"; |
f4a088f7 JRJ |
175 | const char * const mi_lttng_element_snapshot_n_ptr = "n_ptr"; |
176 | const char * const mi_lttng_element_snapshot_session_name = "session_name"; | |
177 | const char * const mi_lttng_element_snapshots = "snapshots"; | |
5e18ec73 | 178 | |
ebbf5ab7 | 179 | /* String related to track/untrack command */ |
ebbf5ab7 JR |
180 | const char * const mi_lttng_element_track_untrack_all_wildcard = "*"; |
181 | ||
ae8c46e0 JG |
182 | /* Deprecated symbols preserved for ABI compatibility. */ |
183 | const char * const mi_lttng_context_type_perf_counter; | |
184 | const char * const mi_lttng_context_type_perf_cpu_counter; | |
185 | const char * const mi_lttng_context_type_perf_thread_counter; | |
186 | const char * const mi_lttng_element_track_untrack_pid_target; | |
187 | const char * const mi_lttng_element_track_untrack_targets; | |
95057847 PP |
188 | const char * const mi_lttng_element_calibrate; |
189 | const char * const mi_lttng_element_calibrate_function; | |
190 | const char * const mi_lttng_element_command_calibrate; | |
ebbf5ab7 | 191 | |
136f2f81 JRJ |
192 | /* This is a merge of jul loglevel and regular loglevel |
193 | * Those should never overlap by definition | |
194 | * (see struct lttng_event loglevel) | |
195 | */ | |
ea75976a | 196 | LTTNG_HIDDEN |
970d848b | 197 | const char *mi_lttng_loglevel_string(int value, enum lttng_domain_type domain) |
5e18ec73 | 198 | { |
970d848b DG |
199 | switch (domain) { |
200 | case LTTNG_DOMAIN_KERNEL: | |
201 | case LTTNG_DOMAIN_UST: | |
202 | switch (value) { | |
203 | case -1: | |
204 | return mi_lttng_element_empty; | |
205 | case LTTNG_LOGLEVEL_EMERG: | |
206 | return mi_lttng_loglevel_str_emerg; | |
207 | case LTTNG_LOGLEVEL_ALERT: | |
208 | return mi_lttng_loglevel_str_alert; | |
209 | case LTTNG_LOGLEVEL_CRIT: | |
210 | return mi_lttng_loglevel_str_crit; | |
211 | case LTTNG_LOGLEVEL_ERR: | |
212 | return mi_lttng_loglevel_str_err; | |
213 | case LTTNG_LOGLEVEL_WARNING: | |
214 | return mi_lttng_loglevel_str_warning; | |
215 | case LTTNG_LOGLEVEL_NOTICE: | |
216 | return mi_lttng_loglevel_str_notice; | |
217 | case LTTNG_LOGLEVEL_INFO: | |
218 | return mi_lttng_loglevel_str_info; | |
219 | case LTTNG_LOGLEVEL_DEBUG_SYSTEM: | |
220 | return mi_lttng_loglevel_str_debug_system; | |
221 | case LTTNG_LOGLEVEL_DEBUG_PROGRAM: | |
222 | return mi_lttng_loglevel_str_debug_program; | |
223 | case LTTNG_LOGLEVEL_DEBUG_PROCESS: | |
224 | return mi_lttng_loglevel_str_debug_process; | |
225 | case LTTNG_LOGLEVEL_DEBUG_MODULE: | |
226 | return mi_lttng_loglevel_str_debug_module; | |
227 | case LTTNG_LOGLEVEL_DEBUG_UNIT: | |
228 | return mi_lttng_loglevel_str_debug_unit; | |
229 | case LTTNG_LOGLEVEL_DEBUG_FUNCTION: | |
230 | return mi_lttng_loglevel_str_debug_function; | |
231 | case LTTNG_LOGLEVEL_DEBUG_LINE: | |
232 | return mi_lttng_loglevel_str_debug_line; | |
233 | case LTTNG_LOGLEVEL_DEBUG: | |
234 | return mi_lttng_loglevel_str_debug; | |
235 | default: | |
236 | return mi_lttng_loglevel_str_unknown; | |
237 | } | |
238 | break; | |
239 | case LTTNG_DOMAIN_LOG4J: | |
240 | switch (value) { | |
241 | case -1: | |
242 | return mi_lttng_element_empty; | |
243 | case LTTNG_LOGLEVEL_LOG4J_OFF: | |
244 | return mi_lttng_loglevel_str_log4j_off; | |
245 | case LTTNG_LOGLEVEL_LOG4J_FATAL: | |
246 | return mi_lttng_loglevel_str_log4j_fatal; | |
247 | case LTTNG_LOGLEVEL_LOG4J_ERROR: | |
248 | return mi_lttng_loglevel_str_log4j_error; | |
249 | case LTTNG_LOGLEVEL_LOG4J_WARN: | |
250 | return mi_lttng_loglevel_str_log4j_warn; | |
251 | case LTTNG_LOGLEVEL_LOG4J_INFO: | |
252 | return mi_lttng_loglevel_str_log4j_info; | |
253 | case LTTNG_LOGLEVEL_LOG4J_DEBUG: | |
254 | return mi_lttng_loglevel_str_log4j_debug; | |
255 | case LTTNG_LOGLEVEL_LOG4J_TRACE: | |
256 | return mi_lttng_loglevel_str_log4j_trace; | |
257 | case LTTNG_LOGLEVEL_LOG4J_ALL: | |
258 | return mi_lttng_loglevel_str_log4j_all; | |
259 | default: | |
260 | return mi_lttng_loglevel_str_unknown; | |
261 | } | |
262 | break; | |
263 | case LTTNG_DOMAIN_JUL: | |
264 | switch (value) { | |
265 | case -1: | |
266 | return mi_lttng_element_empty; | |
267 | case LTTNG_LOGLEVEL_JUL_OFF: | |
268 | return mi_lttng_loglevel_str_jul_off; | |
269 | case LTTNG_LOGLEVEL_JUL_SEVERE: | |
270 | return mi_lttng_loglevel_str_jul_severe; | |
271 | case LTTNG_LOGLEVEL_JUL_WARNING: | |
272 | return mi_lttng_loglevel_str_jul_warning; | |
273 | case LTTNG_LOGLEVEL_JUL_INFO: | |
274 | return mi_lttng_loglevel_str_jul_info; | |
275 | case LTTNG_LOGLEVEL_JUL_CONFIG: | |
276 | return mi_lttng_loglevel_str_jul_config; | |
277 | case LTTNG_LOGLEVEL_JUL_FINE: | |
278 | return mi_lttng_loglevel_str_jul_fine; | |
279 | case LTTNG_LOGLEVEL_JUL_FINER: | |
280 | return mi_lttng_loglevel_str_jul_finer; | |
281 | case LTTNG_LOGLEVEL_JUL_FINEST: | |
282 | return mi_lttng_loglevel_str_jul_finest; | |
283 | case LTTNG_LOGLEVEL_JUL_ALL: | |
284 | return mi_lttng_loglevel_str_jul_all; | |
285 | default: | |
286 | return mi_lttng_loglevel_str_unknown; | |
287 | } | |
288 | break; | |
0e115563 DG |
289 | case LTTNG_DOMAIN_PYTHON: |
290 | switch (value) { | |
291 | case LTTNG_LOGLEVEL_PYTHON_CRITICAL: | |
292 | return mi_lttng_loglevel_str_python_critical; | |
293 | case LTTNG_LOGLEVEL_PYTHON_ERROR: | |
294 | return mi_lttng_loglevel_str_python_error; | |
295 | case LTTNG_LOGLEVEL_PYTHON_WARNING: | |
296 | return mi_lttng_loglevel_str_python_warning; | |
297 | case LTTNG_LOGLEVEL_PYTHON_INFO: | |
298 | return mi_lttng_loglevel_str_python_info; | |
299 | case LTTNG_LOGLEVEL_PYTHON_DEBUG: | |
300 | return mi_lttng_loglevel_str_python_debug; | |
301 | case LTTNG_LOGLEVEL_PYTHON_NOTSET: | |
302 | return mi_lttng_loglevel_str_python_notset; | |
303 | default: | |
304 | return mi_lttng_loglevel_str_unknown; | |
305 | } | |
306 | break; | |
bc2718d1 JG |
307 | default: |
308 | return mi_lttng_loglevel_str_unknown; | |
5e18ec73 JR |
309 | } |
310 | } | |
311 | ||
ea75976a | 312 | LTTNG_HIDDEN |
5e18ec73 JR |
313 | const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value) |
314 | { | |
315 | switch (value) { | |
316 | case LTTNG_EVENT_LOGLEVEL_ALL: | |
317 | return mi_lttng_loglevel_type_all; | |
318 | case LTTNG_EVENT_LOGLEVEL_RANGE: | |
319 | return mi_lttng_loglevel_type_range; | |
320 | case LTTNG_EVENT_LOGLEVEL_SINGLE: | |
321 | return mi_lttng_loglevel_type_single; | |
322 | default: | |
323 | return mi_lttng_loglevel_type_unknown; | |
324 | } | |
325 | } | |
326 | ||
ea75976a | 327 | LTTNG_HIDDEN |
5e18ec73 JR |
328 | const char *mi_lttng_eventtype_string(enum lttng_event_type value) |
329 | { | |
330 | switch (value) { | |
331 | case LTTNG_EVENT_ALL: | |
332 | return config_event_type_all; | |
333 | case LTTNG_EVENT_TRACEPOINT: | |
334 | return config_event_type_tracepoint; | |
335 | case LTTNG_EVENT_PROBE: | |
336 | return config_event_type_probe; | |
337 | case LTTNG_EVENT_FUNCTION: | |
338 | return config_event_type_function; | |
339 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
340 | return config_event_type_function_entry; | |
341 | case LTTNG_EVENT_SYSCALL: | |
342 | return config_event_type_syscall; | |
343 | case LTTNG_EVENT_NOOP: | |
344 | return config_event_type_noop; | |
345 | default: | |
346 | return mi_lttng_element_empty; | |
347 | } | |
348 | } | |
349 | ||
a23cb78a | 350 | static |
89b72577 JRJ |
351 | const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val) |
352 | { | |
353 | switch (val) { | |
354 | case LTTNG_EVENT_CONTEXT_PID: | |
355 | return config_event_context_pid; | |
89b72577 JRJ |
356 | case LTTNG_EVENT_CONTEXT_PROCNAME: |
357 | return config_event_context_procname; | |
358 | case LTTNG_EVENT_CONTEXT_PRIO: | |
359 | return config_event_context_prio; | |
360 | case LTTNG_EVENT_CONTEXT_NICE: | |
361 | return config_event_context_nice; | |
362 | case LTTNG_EVENT_CONTEXT_VPID: | |
363 | return config_event_context_vpid; | |
364 | case LTTNG_EVENT_CONTEXT_TID: | |
365 | return config_event_context_tid; | |
366 | case LTTNG_EVENT_CONTEXT_VTID: | |
367 | return config_event_context_vtid; | |
368 | case LTTNG_EVENT_CONTEXT_PPID: | |
369 | return config_event_context_ppid; | |
370 | case LTTNG_EVENT_CONTEXT_VPPID: | |
371 | return config_event_context_vppid; | |
372 | case LTTNG_EVENT_CONTEXT_PTHREAD_ID: | |
373 | return config_event_context_pthread_id; | |
374 | case LTTNG_EVENT_CONTEXT_HOSTNAME: | |
375 | return config_event_context_hostname; | |
376 | case LTTNG_EVENT_CONTEXT_IP: | |
377 | return config_event_context_ip; | |
378 | default: | |
379 | return NULL; | |
380 | } | |
381 | } | |
382 | ||
ea75976a | 383 | LTTNG_HIDDEN |
5e18ec73 JR |
384 | const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val) |
385 | { | |
386 | switch (val) { | |
387 | case(LTTNG_EVENT_FIELD_INTEGER): | |
388 | return mi_lttng_element_type_integer; | |
389 | case(LTTNG_EVENT_FIELD_ENUM): | |
390 | return mi_lttng_element_type_enum; | |
391 | case(LTTNG_EVENT_FIELD_FLOAT): | |
392 | return mi_lttng_element_type_float; | |
393 | case(LTTNG_EVENT_FIELD_STRING): | |
394 | return mi_lttng_element_type_string; | |
395 | default: | |
396 | return mi_lttng_element_type_other; | |
397 | } | |
398 | } | |
399 | ||
ea75976a | 400 | LTTNG_HIDDEN |
5e18ec73 JR |
401 | const char *mi_lttng_domaintype_string(enum lttng_domain_type value) |
402 | { | |
403 | /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */ | |
404 | switch (value) { | |
405 | case LTTNG_DOMAIN_KERNEL: | |
406 | return config_domain_type_kernel; | |
407 | case LTTNG_DOMAIN_UST: | |
408 | return config_domain_type_ust; | |
409 | case LTTNG_DOMAIN_JUL: | |
410 | return config_domain_type_jul; | |
5cdb6027 DG |
411 | case LTTNG_DOMAIN_LOG4J: |
412 | return config_domain_type_log4j; | |
b789735e PP |
413 | case LTTNG_DOMAIN_PYTHON: |
414 | return config_domain_type_python; | |
5e18ec73 JR |
415 | default: |
416 | /* Should not have an unknown domain */ | |
417 | assert(0); | |
2855532e | 418 | return NULL; |
5e18ec73 JR |
419 | } |
420 | } | |
421 | ||
ea75976a | 422 | LTTNG_HIDDEN |
5e18ec73 JR |
423 | const char *mi_lttng_buffertype_string(enum lttng_buffer_type value) |
424 | { | |
425 | switch (value) { | |
426 | case LTTNG_BUFFER_PER_PID: | |
427 | return config_buffer_type_per_pid; | |
428 | case LTTNG_BUFFER_PER_UID: | |
429 | return config_buffer_type_per_uid; | |
430 | case LTTNG_BUFFER_GLOBAL: | |
431 | return config_buffer_type_global; | |
432 | default: | |
433 | /* Should not have an unknow buffer type */ | |
434 | assert(0); | |
2855532e | 435 | return NULL; |
5e18ec73 JR |
436 | } |
437 | } | |
438 | ||
c7e35b03 JR |
439 | LTTNG_HIDDEN |
440 | struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type) | |
441 | { | |
442 | struct mi_writer *mi_writer; | |
443 | ||
444 | mi_writer = zmalloc(sizeof(struct mi_writer)); | |
445 | if (!mi_writer) { | |
446 | PERROR("zmalloc mi_writer_create"); | |
447 | goto end; | |
448 | } | |
449 | if (mi_output_type == LTTNG_MI_XML) { | |
705bb62f | 450 | mi_writer->writer = config_writer_create(fd_output, 0); |
c7e35b03 JR |
451 | if (!mi_writer->writer) { |
452 | goto err_destroy; | |
453 | } | |
454 | mi_writer->type = LTTNG_MI_XML; | |
455 | } else { | |
456 | goto err_destroy; | |
457 | } | |
458 | ||
459 | end: | |
460 | return mi_writer; | |
461 | ||
462 | err_destroy: | |
463 | free(mi_writer); | |
464 | return NULL; | |
465 | } | |
466 | ||
467 | LTTNG_HIDDEN | |
468 | int mi_lttng_writer_destroy(struct mi_writer *writer) | |
469 | { | |
470 | int ret; | |
471 | ||
472 | if (!writer) { | |
473 | ret = -EINVAL; | |
474 | goto end; | |
475 | } | |
476 | ||
477 | ret = config_writer_destroy(writer->writer); | |
478 | if (ret < 0) { | |
479 | goto end; | |
480 | } | |
481 | ||
482 | free(writer); | |
483 | end: | |
484 | return ret; | |
485 | } | |
486 | ||
487 | LTTNG_HIDDEN | |
488 | int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command) | |
489 | { | |
490 | int ret; | |
491 | ||
e10b6a1c JG |
492 | /* |
493 | * A command is always the MI's root node, it must declare the current | |
494 | * namespace and schema URIs and the schema's version. | |
495 | */ | |
496 | ret = config_writer_open_element(writer->writer, | |
497 | mi_lttng_element_command); | |
498 | if (ret) { | |
499 | goto end; | |
500 | } | |
501 | ||
502 | ret = config_writer_write_attribute(writer->writer, | |
41af1adf | 503 | mi_lttng_xmlns, DEFAULT_LTTNG_MI_NAMESPACE); |
e10b6a1c JG |
504 | if (ret) { |
505 | goto end; | |
506 | } | |
507 | ||
508 | ret = config_writer_write_attribute(writer->writer, | |
509 | mi_lttng_xmlns_xsi, mi_lttng_w3_schema_uri); | |
c7e35b03 JR |
510 | if (ret) { |
511 | goto end; | |
512 | } | |
e10b6a1c JG |
513 | |
514 | ret = config_writer_write_attribute(writer->writer, | |
515 | mi_lttng_schema_location, | |
516 | mi_lttng_schema_location_uri); | |
517 | if (ret) { | |
518 | goto end; | |
519 | } | |
520 | ||
521 | ret = config_writer_write_attribute(writer->writer, | |
522 | mi_lttng_schema_version, | |
523 | mi_lttng_schema_version_value); | |
524 | if (ret) { | |
525 | goto end; | |
526 | } | |
527 | ||
c7e35b03 JR |
528 | ret = mi_lttng_writer_write_element_string(writer, |
529 | mi_lttng_element_command_name, command); | |
530 | end: | |
531 | return ret; | |
532 | } | |
533 | ||
534 | LTTNG_HIDDEN | |
535 | int mi_lttng_writer_command_close(struct mi_writer *writer) | |
536 | { | |
537 | return mi_lttng_writer_close_element(writer); | |
538 | } | |
539 | ||
540 | LTTNG_HIDDEN | |
541 | int mi_lttng_writer_open_element(struct mi_writer *writer, | |
542 | const char *element_name) | |
543 | { | |
544 | return config_writer_open_element(writer->writer, element_name); | |
545 | } | |
546 | ||
547 | LTTNG_HIDDEN | |
548 | int mi_lttng_writer_close_element(struct mi_writer *writer) | |
549 | { | |
550 | return config_writer_close_element(writer->writer); | |
551 | } | |
552 | ||
5e18ec73 JR |
553 | LTTNG_HIDDEN |
554 | int mi_lttng_close_multi_element(struct mi_writer *writer, | |
555 | unsigned int nb_element) | |
556 | { | |
557 | int ret, i; | |
558 | ||
559 | if (nb_element < 1) { | |
560 | ret = 0; | |
561 | goto end; | |
562 | } | |
563 | for (i = 0; i < nb_element; i++) { | |
564 | ret = mi_lttng_writer_close_element(writer); | |
565 | if (ret) { | |
566 | goto end; | |
567 | } | |
568 | } | |
569 | end: | |
570 | return ret; | |
571 | } | |
572 | ||
c7e35b03 JR |
573 | LTTNG_HIDDEN |
574 | int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer, | |
575 | const char *element_name, uint64_t value) | |
576 | { | |
577 | return config_writer_write_element_unsigned_int(writer->writer, | |
578 | element_name, value); | |
579 | } | |
580 | ||
581 | LTTNG_HIDDEN | |
582 | int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer, | |
583 | const char *element_name, int64_t value) | |
584 | { | |
585 | return config_writer_write_element_signed_int(writer->writer, | |
586 | element_name, value); | |
587 | } | |
588 | ||
589 | LTTNG_HIDDEN | |
590 | int mi_lttng_writer_write_element_bool(struct mi_writer *writer, | |
591 | const char *element_name, int value) | |
592 | { | |
593 | return config_writer_write_element_bool(writer->writer, | |
594 | element_name, value); | |
595 | } | |
596 | ||
597 | LTTNG_HIDDEN | |
598 | int mi_lttng_writer_write_element_string(struct mi_writer *writer, | |
599 | const char *element_name, const char *value) | |
600 | { | |
601 | return config_writer_write_element_string(writer->writer, | |
602 | element_name, value); | |
603 | } | |
604 | ||
605 | LTTNG_HIDDEN | |
606 | int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version, | |
607 | const char *lttng_description, const char *lttng_license) | |
608 | { | |
609 | int ret; | |
610 | ||
611 | /* Open version */ | |
612 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_version); | |
613 | if (ret) { | |
614 | goto end; | |
615 | } | |
616 | ||
617 | /* Version string (contain info like rc etc.) */ | |
618 | ret = mi_lttng_writer_write_element_string(writer, | |
782f3c61 | 619 | mi_lttng_element_version_str, version->version); |
c7e35b03 JR |
620 | if (ret) { |
621 | goto end; | |
622 | } | |
623 | ||
624 | /* Major version number */ | |
625 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
626 | mi_lttng_element_version_major, version->version_major); | |
627 | if (ret) { | |
628 | goto end; | |
629 | } | |
630 | ||
631 | /* Minor version number */ | |
632 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
633 | mi_lttng_element_version_minor, version->version_minor); | |
634 | if (ret) { | |
635 | goto end; | |
636 | } | |
637 | ||
314d5222 JRJ |
638 | /* Commit version number */ |
639 | ret = mi_lttng_writer_write_element_string(writer, | |
640 | mi_lttng_element_version_commit, version->version_commit); | |
641 | if (ret) { | |
642 | goto end; | |
643 | } | |
644 | ||
c7e35b03 JR |
645 | /* Patch number */ |
646 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
647 | mi_lttng_element_version_patch_level, version->version_patchlevel); | |
648 | if (ret) { | |
649 | goto end; | |
650 | } | |
651 | ||
652 | /* Name of the version */ | |
653 | ret = mi_lttng_writer_write_element_string(writer, | |
654 | config_element_name, version->version_name); | |
655 | if (ret) { | |
656 | goto end; | |
657 | } | |
658 | ||
659 | /* Description mostly related to beer... */ | |
660 | ret = mi_lttng_writer_write_element_string(writer, | |
661 | mi_lttng_element_version_description, lttng_description); | |
662 | if (ret) { | |
663 | goto end; | |
664 | } | |
665 | ||
666 | /* url */ | |
667 | ret = mi_lttng_writer_write_element_string(writer, | |
668 | mi_lttng_element_version_web, version->package_url); | |
669 | if (ret) { | |
670 | goto end; | |
671 | } | |
672 | ||
673 | /* License: free as in free beer...no...*speech* */ | |
674 | ret = mi_lttng_writer_write_element_string(writer, | |
675 | mi_lttng_element_version_license, lttng_license); | |
676 | if (ret) { | |
677 | goto end; | |
678 | } | |
679 | ||
680 | /* Close version element */ | |
681 | ret = mi_lttng_writer_close_element(writer); | |
682 | ||
683 | end: | |
684 | return ret; | |
685 | } | |
686 | ||
5e18ec73 JR |
687 | LTTNG_HIDDEN |
688 | int mi_lttng_sessions_open(struct mi_writer *writer) | |
689 | { | |
690 | return mi_lttng_writer_open_element(writer, config_element_sessions); | |
691 | } | |
692 | ||
c7e35b03 JR |
693 | LTTNG_HIDDEN |
694 | int mi_lttng_session(struct mi_writer *writer, | |
695 | struct lttng_session *session, int is_open) | |
696 | { | |
697 | int ret; | |
698 | ||
5e18ec73 JR |
699 | assert(session); |
700 | ||
701 | /* Open sessions element */ | |
c7e35b03 JR |
702 | ret = mi_lttng_writer_open_element(writer, |
703 | config_element_session); | |
704 | if (ret) { | |
705 | goto end; | |
706 | } | |
707 | ||
708 | /* Name of the session */ | |
709 | ret = mi_lttng_writer_write_element_string(writer, | |
710 | config_element_name, session->name); | |
711 | if (ret) { | |
712 | goto end; | |
713 | } | |
714 | ||
5e18ec73 | 715 | /* Path */ |
c7e35b03 JR |
716 | ret = mi_lttng_writer_write_element_string(writer, |
717 | config_element_path, session->path); | |
718 | if (ret) { | |
719 | goto end; | |
720 | } | |
721 | ||
5e18ec73 JR |
722 | /* Enabled ? */ |
723 | ret = mi_lttng_writer_write_element_bool(writer, | |
c7e35b03 JR |
724 | config_element_enabled, session->enabled); |
725 | if (ret) { | |
726 | goto end; | |
727 | } | |
728 | ||
5e18ec73 | 729 | /* Snapshot mode */ |
c7e35b03 JR |
730 | ret = mi_lttng_writer_write_element_unsigned_int(writer, |
731 | config_element_snapshot_mode, session->snapshot_mode); | |
732 | if (ret) { | |
733 | goto end; | |
734 | } | |
735 | ||
5e18ec73 | 736 | /* Live timer interval in usec */ |
c7e35b03 JR |
737 | ret = mi_lttng_writer_write_element_unsigned_int(writer, |
738 | config_element_live_timer_interval, | |
739 | session->live_timer_interval); | |
740 | if (ret) { | |
741 | goto end; | |
742 | } | |
743 | ||
744 | if (!is_open) { | |
745 | /* Closing session element */ | |
746 | ret = mi_lttng_writer_close_element(writer); | |
747 | } | |
748 | end: | |
749 | return ret; | |
750 | ||
751 | } | |
5e18ec73 JR |
752 | |
753 | LTTNG_HIDDEN | |
754 | int mi_lttng_domains_open(struct mi_writer *writer) | |
755 | { | |
756 | return mi_lttng_writer_open_element(writer, config_element_domains); | |
757 | } | |
758 | ||
759 | LTTNG_HIDDEN | |
760 | int mi_lttng_domain(struct mi_writer *writer, | |
761 | struct lttng_domain *domain, int is_open) | |
762 | { | |
763 | int ret = 0; | |
764 | const char *str_domain; | |
765 | const char *str_buffer; | |
766 | ||
767 | assert(domain); | |
768 | ||
769 | /* Open domain element */ | |
770 | ret = mi_lttng_writer_open_element(writer, config_element_domain); | |
771 | if (ret) { | |
772 | goto end; | |
773 | } | |
774 | ||
775 | /* Domain Type */ | |
776 | str_domain = mi_lttng_domaintype_string(domain->type); | |
777 | ret = mi_lttng_writer_write_element_string(writer, config_element_type, | |
778 | str_domain); | |
779 | if (ret) { | |
780 | goto end; | |
781 | } | |
782 | ||
783 | /* Buffer Type */ | |
784 | str_buffer= mi_lttng_buffertype_string(domain->buf_type); | |
785 | ret = mi_lttng_writer_write_element_string(writer, | |
786 | config_element_buffer_type, str_buffer); | |
787 | if (ret) { | |
788 | goto end; | |
789 | } | |
790 | ||
d813f89b JRJ |
791 | /* TODO: union attr |
792 | * This union is not currently used and was added for | |
793 | * future ust domain support. | |
794 | * Date: 25-06-2014 | |
795 | * */ | |
5e18ec73 JR |
796 | |
797 | if (!is_open) { | |
798 | /* Closing domain element */ | |
799 | ret = mi_lttng_writer_close_element(writer); | |
800 | } | |
801 | ||
802 | end: | |
803 | return ret; | |
804 | ||
805 | } | |
806 | ||
807 | LTTNG_HIDDEN | |
808 | int mi_lttng_channels_open(struct mi_writer *writer) | |
809 | { | |
810 | return mi_lttng_writer_open_element(writer, config_element_channels); | |
811 | } | |
812 | ||
813 | LTTNG_HIDDEN | |
814 | int mi_lttng_channel(struct mi_writer *writer, | |
815 | struct lttng_channel *channel, int is_open) | |
816 | { | |
817 | int ret = 0; | |
818 | ||
819 | assert(channel); | |
820 | ||
821 | /* Opening channel element */ | |
822 | ret = mi_lttng_writer_open_element(writer, config_element_channel); | |
823 | if (ret) { | |
824 | goto end; | |
825 | } | |
826 | ||
827 | /* Name */ | |
828 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
829 | channel->name); | |
830 | if (ret) { | |
831 | goto end; | |
832 | } | |
833 | ||
834 | /* Enabled ? */ | |
835 | ret = mi_lttng_writer_write_element_bool(writer, | |
836 | config_element_enabled, channel->enabled); | |
837 | if (ret) { | |
838 | goto end; | |
839 | } | |
840 | ||
841 | /* Attribute */ | |
842 | ret = mi_lttng_channel_attr(writer, &channel->attr); | |
843 | if (ret) { | |
844 | goto end; | |
845 | } | |
846 | ||
847 | if (!is_open) { | |
848 | /* Closing channel element */ | |
849 | ret = mi_lttng_writer_close_element(writer); | |
850 | if (ret) { | |
851 | goto end; | |
852 | } | |
853 | } | |
854 | end: | |
855 | return ret; | |
856 | } | |
857 | ||
858 | LTTNG_HIDDEN | |
859 | int mi_lttng_channel_attr(struct mi_writer *writer, | |
860 | struct lttng_channel_attr *attr) | |
861 | { | |
862 | int ret = 0; | |
fb83fe64 JD |
863 | struct lttng_channel *chan = caa_container_of(attr, |
864 | struct lttng_channel, attr); | |
cf0bcb51 | 865 | uint64_t discarded_events, lost_packets, monitor_timer_interval; |
f515d318 | 866 | int64_t blocking_timeout; |
5e18ec73 JR |
867 | |
868 | assert(attr); | |
869 | ||
fb83fe64 JD |
870 | ret = lttng_channel_get_discarded_event_count(chan, &discarded_events); |
871 | if (ret) { | |
872 | goto end; | |
873 | } | |
874 | ||
875 | ret = lttng_channel_get_lost_packet_count(chan, &lost_packets); | |
876 | if (ret) { | |
877 | goto end; | |
878 | } | |
879 | ||
cf0bcb51 JG |
880 | ret = lttng_channel_get_monitor_timer_interval(chan, |
881 | &monitor_timer_interval); | |
882 | if (ret) { | |
883 | goto end; | |
884 | } | |
885 | ||
f515d318 MD |
886 | ret = lttng_channel_get_blocking_timeout(chan, |
887 | &blocking_timeout); | |
888 | if (ret) { | |
889 | goto end; | |
890 | } | |
891 | ||
5e18ec73 JR |
892 | /* Opening Attributes */ |
893 | ret = mi_lttng_writer_open_element(writer, config_element_attributes); | |
894 | if (ret) { | |
895 | goto end; | |
896 | } | |
897 | ||
898 | /* Overwrite */ | |
899 | ret = mi_lttng_writer_write_element_string(writer, | |
900 | config_element_overwrite_mode, | |
901 | attr->overwrite ? config_overwrite_mode_overwrite : | |
902 | config_overwrite_mode_discard); | |
903 | if (ret) { | |
904 | goto end; | |
905 | } | |
906 | ||
907 | /* Sub buffer size in byte */ | |
908 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
909 | config_element_subbuf_size, attr->subbuf_size); | |
910 | if (ret) { | |
911 | goto end; | |
912 | } | |
913 | ||
914 | /* Number of subbuffer (power of two) */ | |
915 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
916 | config_element_num_subbuf, | |
917 | attr->num_subbuf); | |
918 | if (ret) { | |
919 | goto end; | |
920 | } | |
921 | ||
922 | /* Switch timer interval in usec */ | |
923 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
924 | config_element_switch_timer_interval, | |
925 | attr->switch_timer_interval); | |
926 | if (ret) { | |
927 | goto end; | |
928 | } | |
929 | ||
930 | /* Read timer interval in usec */ | |
931 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
932 | config_element_read_timer_interval, | |
933 | attr->read_timer_interval); | |
934 | if (ret) { | |
935 | goto end; | |
936 | } | |
937 | ||
cf0bcb51 JG |
938 | /* Monitor timer interval in usec */ |
939 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
940 | config_element_monitor_timer_interval, | |
941 | monitor_timer_interval); | |
942 | if (ret) { | |
943 | goto end; | |
944 | } | |
945 | ||
f515d318 MD |
946 | /* Retry timeout in usec */ |
947 | ret = mi_lttng_writer_write_element_signed_int(writer, | |
948 | config_element_blocking_timeout, | |
949 | blocking_timeout); | |
950 | if (ret) { | |
951 | goto end; | |
952 | } | |
953 | ||
5e18ec73 JR |
954 | /* Event output */ |
955 | ret = mi_lttng_writer_write_element_string(writer, | |
956 | config_element_output_type, | |
957 | attr->output == LTTNG_EVENT_SPLICE ? | |
958 | config_output_type_splice : config_output_type_mmap); | |
959 | if (ret) { | |
960 | goto end; | |
961 | } | |
962 | ||
963 | /* Tracefile size in bytes */ | |
964 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
965 | config_element_tracefile_size, attr->tracefile_size); | |
966 | if (ret) { | |
967 | goto end; | |
968 | } | |
969 | ||
970 | /* Count of tracefiles */ | |
971 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
972 | config_element_tracefile_count, | |
973 | attr->tracefile_count); | |
974 | if (ret) { | |
975 | goto end; | |
976 | } | |
977 | ||
978 | /* Live timer interval in usec*/ | |
979 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
980 | config_element_live_timer_interval, | |
981 | attr->live_timer_interval); | |
982 | if (ret) { | |
fb83fe64 JD |
983 | goto end; |
984 | } | |
985 | ||
986 | /* Discarded events */ | |
987 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
988 | config_element_discarded_events, | |
989 | discarded_events); | |
990 | if (ret) { | |
991 | goto end; | |
992 | } | |
993 | ||
994 | /* Lost packets */ | |
995 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
996 | config_element_lost_packets, | |
997 | lost_packets); | |
998 | if (ret) { | |
5e18ec73 JR |
999 | goto end; |
1000 | } | |
1001 | ||
1002 | /* Closing attributes */ | |
1003 | ret = mi_lttng_writer_close_element(writer); | |
1004 | if (ret) { | |
1005 | goto end; | |
1006 | } | |
1007 | end: | |
1008 | return ret; | |
1009 | ||
1010 | } | |
1011 | ||
1012 | LTTNG_HIDDEN | |
1013 | int mi_lttng_event_common_attributes(struct mi_writer *writer, | |
1014 | struct lttng_event *event) | |
1015 | { | |
1016 | int ret; | |
7b4aa11d | 1017 | const char *filter_expression; |
5e18ec73 JR |
1018 | |
1019 | /* Open event element */ | |
1020 | ret = mi_lttng_writer_open_element(writer, config_element_event); | |
1021 | if (ret) { | |
1022 | goto end; | |
1023 | } | |
1024 | ||
f4a088f7 | 1025 | /* Event name */ |
5e18ec73 JR |
1026 | ret = mi_lttng_writer_write_element_string(writer, |
1027 | config_element_name, event->name); | |
1028 | if (ret) { | |
1029 | goto end; | |
1030 | } | |
1031 | ||
f4a088f7 | 1032 | /* Event type */ |
5e18ec73 JR |
1033 | ret = mi_lttng_writer_write_element_string(writer, |
1034 | config_element_type, mi_lttng_eventtype_string(event->type)); | |
1035 | if (ret) { | |
1036 | goto end; | |
1037 | } | |
1038 | ||
f4a088f7 | 1039 | /* Is event enabled */ |
5e18ec73 JR |
1040 | ret = mi_lttng_writer_write_element_bool(writer, |
1041 | config_element_enabled, event->enabled); | |
1042 | if (ret) { | |
1043 | goto end; | |
1044 | } | |
1045 | ||
7b4aa11d | 1046 | /* Event filter expression */ |
134e72ed | 1047 | ret = lttng_event_get_filter_expression(event, &filter_expression); |
7b4aa11d PP |
1048 | if (ret) { |
1049 | goto end; | |
1050 | } | |
1051 | ||
1052 | if (filter_expression) { | |
1053 | ret = mi_lttng_writer_write_element_string(writer, | |
654f9f5e JG |
1054 | config_element_filter_expression, |
1055 | filter_expression); | |
7b4aa11d PP |
1056 | if (ret) { |
1057 | goto end; | |
1058 | } | |
1059 | } | |
1060 | ||
5e18ec73 JR |
1061 | end: |
1062 | return ret; | |
1063 | } | |
1064 | ||
eecb9438 PP |
1065 | static int write_event_exclusions(struct mi_writer *writer, |
1066 | struct lttng_event *event) | |
1067 | { | |
1068 | int i; | |
1069 | int ret; | |
1070 | int exclusion_count; | |
1071 | ||
eecb9438 PP |
1072 | /* Open event exclusions */ |
1073 | ret = mi_lttng_writer_open_element(writer, config_element_exclusions); | |
1074 | if (ret) { | |
1075 | goto end; | |
1076 | } | |
1077 | ||
1078 | exclusion_count = lttng_event_get_exclusion_name_count(event); | |
1079 | if (exclusion_count < 0) { | |
1080 | ret = exclusion_count; | |
1081 | goto end; | |
1082 | } | |
1083 | ||
1084 | for (i = 0; i < exclusion_count; i++) { | |
1085 | const char *name; | |
1086 | ||
1087 | ret = lttng_event_get_exclusion_name(event, i, &name); | |
1088 | if (ret) { | |
1089 | /* Close exclusions */ | |
1090 | mi_lttng_writer_close_element(writer); | |
1091 | goto end; | |
1092 | } | |
1093 | ||
1094 | ret = mi_lttng_writer_write_element_string(writer, | |
1095 | config_element_exclusion, name); | |
1096 | if (ret) { | |
1097 | /* Close exclusions */ | |
1098 | mi_lttng_writer_close_element(writer); | |
1099 | goto end; | |
1100 | } | |
1101 | } | |
1102 | ||
1103 | /* Close exclusions */ | |
1104 | ret = mi_lttng_writer_close_element(writer); | |
1105 | ||
1106 | end: | |
1107 | return ret; | |
1108 | } | |
1109 | ||
5e18ec73 JR |
1110 | LTTNG_HIDDEN |
1111 | int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer, | |
970d848b | 1112 | struct lttng_event *event, enum lttng_domain_type domain) |
5e18ec73 JR |
1113 | { |
1114 | int ret; | |
1115 | ||
f4a088f7 | 1116 | /* Event loglevel */ |
5e18ec73 | 1117 | ret = mi_lttng_writer_write_element_string(writer, |
970d848b DG |
1118 | config_element_loglevel, |
1119 | mi_lttng_loglevel_string(event->loglevel, domain)); | |
5e18ec73 JR |
1120 | if (ret) { |
1121 | goto end; | |
1122 | } | |
1123 | ||
f4a088f7 | 1124 | /* Log level type */ |
5e18ec73 JR |
1125 | ret = mi_lttng_writer_write_element_string(writer, |
1126 | config_element_loglevel_type, | |
1127 | mi_lttng_logleveltype_string(event->loglevel_type)); | |
1128 | if (ret) { | |
1129 | goto end; | |
1130 | } | |
1131 | ||
eecb9438 PP |
1132 | /* Event exclusions */ |
1133 | ret = write_event_exclusions(writer, event); | |
5e18ec73 JR |
1134 | |
1135 | end: | |
1136 | return ret; | |
1137 | } | |
1138 | ||
1139 | LTTNG_HIDDEN | |
1140 | int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer *writer, | |
1141 | struct lttng_event *event) | |
1142 | { | |
1143 | /* event exclusion filter */ | |
eecb9438 | 1144 | return write_event_exclusions(writer, event); |
5e18ec73 JR |
1145 | } |
1146 | ||
1147 | LTTNG_HIDDEN | |
1148 | int mi_lttng_event_function_probe(struct mi_writer *writer, | |
1149 | struct lttng_event *event) | |
1150 | { | |
1151 | int ret; | |
1152 | ||
3b4a6e40 JRJ |
1153 | ret = mi_lttng_writer_open_element(writer, config_element_attributes); |
1154 | if (ret) { | |
1155 | goto end; | |
1156 | } | |
1157 | ||
1158 | ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes); | |
1159 | if (ret) { | |
1160 | goto end; | |
1161 | } | |
1162 | ||
5e18ec73 JR |
1163 | if (event->attr.probe.addr != 0) { |
1164 | /* event probe address */ | |
1165 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1166 | config_element_address, event->attr.probe.addr); | |
1167 | if (ret) { | |
1168 | goto end; | |
1169 | } | |
1170 | } else { | |
1171 | /* event probe offset */ | |
1172 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1173 | config_element_offset, event->attr.probe.offset); | |
1174 | if (ret) { | |
1175 | goto end; | |
1176 | } | |
1177 | ||
1178 | /* event probe symbol_name */ | |
1179 | ret = mi_lttng_writer_write_element_string(writer, | |
1180 | config_element_symbol_name, event->attr.probe.symbol_name); | |
1181 | if (ret) { | |
1182 | goto end; | |
1183 | } | |
1184 | } | |
3b4a6e40 JRJ |
1185 | |
1186 | /* Close probe_attributes and attributes */ | |
1187 | ret = mi_lttng_close_multi_element(writer, 2); | |
5e18ec73 JR |
1188 | end: |
1189 | return ret; | |
1190 | } | |
1191 | ||
1192 | LTTNG_HIDDEN | |
1193 | int mi_lttng_event_function_entry(struct mi_writer *writer, | |
1194 | struct lttng_event *event) | |
1195 | { | |
3b4a6e40 JRJ |
1196 | int ret; |
1197 | ||
1198 | ret = mi_lttng_writer_open_element(writer, config_element_attributes); | |
1199 | if (ret) { | |
1200 | goto end; | |
1201 | } | |
1202 | ||
1203 | ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes); | |
1204 | if (ret) { | |
1205 | goto end; | |
1206 | } | |
1207 | ||
5e18ec73 | 1208 | /* event probe symbol_name */ |
3b4a6e40 | 1209 | ret = mi_lttng_writer_write_element_string(writer, |
5e18ec73 | 1210 | config_element_symbol_name, event->attr.ftrace.symbol_name); |
3b4a6e40 JRJ |
1211 | if (ret) { |
1212 | goto end; | |
1213 | } | |
1214 | ||
1215 | /* Close function_attributes and attributes */ | |
1216 | ret = mi_lttng_close_multi_element(writer, 2); | |
1217 | end: | |
1218 | return ret; | |
5e18ec73 JR |
1219 | } |
1220 | ||
1221 | LTTNG_HIDDEN | |
1222 | int mi_lttng_events_open(struct mi_writer *writer) | |
1223 | { | |
1224 | return mi_lttng_writer_open_element(writer, config_element_events); | |
1225 | } | |
1226 | ||
1227 | LTTNG_HIDDEN | |
1228 | int mi_lttng_event(struct mi_writer *writer, | |
970d848b | 1229 | struct lttng_event *event, int is_open, enum lttng_domain_type domain) |
5e18ec73 JR |
1230 | { |
1231 | int ret; | |
1232 | ||
1233 | ret = mi_lttng_event_common_attributes(writer, event); | |
1234 | if (ret) { | |
1235 | goto end; | |
1236 | } | |
1237 | ||
1238 | switch (event->type) { | |
5e18ec73 JR |
1239 | case LTTNG_EVENT_TRACEPOINT: |
1240 | { | |
1241 | if (event->loglevel != -1) { | |
970d848b | 1242 | ret = mi_lttng_event_tracepoint_loglevel(writer, event, domain); |
5e18ec73 JR |
1243 | } else { |
1244 | ret = mi_lttng_event_tracepoint_no_loglevel(writer, event); | |
1245 | } | |
1246 | break; | |
1247 | } | |
3b4a6e40 JRJ |
1248 | case LTTNG_EVENT_FUNCTION: |
1249 | /* Fallthrough */ | |
5e18ec73 JR |
1250 | case LTTNG_EVENT_PROBE: |
1251 | ret = mi_lttng_event_function_probe(writer, event); | |
1252 | break; | |
1253 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
1254 | ret = mi_lttng_event_function_entry(writer, event); | |
1255 | break; | |
89476427 JRJ |
1256 | case LTTNG_EVENT_ALL: |
1257 | /* Fallthrough */ | |
5e18ec73 JR |
1258 | default: |
1259 | break; | |
1260 | } | |
1261 | ||
1262 | if (!is_open) { | |
1263 | ret = mi_lttng_writer_close_element(writer); | |
1264 | } | |
1265 | ||
1266 | end: | |
1267 | return ret; | |
1268 | } | |
1269 | ||
ebbf5ab7 JR |
1270 | LTTNG_HIDDEN |
1271 | int mi_lttng_trackers_open(struct mi_writer *writer) | |
1272 | { | |
1273 | return mi_lttng_writer_open_element(writer, config_element_trackers); | |
1274 | } | |
1275 | ||
1276 | LTTNG_HIDDEN | |
1277 | int mi_lttng_pid_tracker_open(struct mi_writer *writer) | |
1278 | { | |
1279 | int ret; | |
1280 | ||
1281 | /* Open element pid_tracker */ | |
1282 | ret = mi_lttng_writer_open_element(writer, config_element_pid_tracker); | |
1283 | if (ret) { | |
1284 | goto end; | |
1285 | } | |
1286 | ||
1287 | /* Open targets element */ | |
1288 | ret = mi_lttng_targets_open(writer); | |
1289 | end: | |
1290 | return ret; | |
1291 | } | |
1292 | ||
5e18ec73 JR |
1293 | LTTNG_HIDDEN |
1294 | int mi_lttng_pids_open(struct mi_writer *writer) | |
1295 | { | |
ebbf5ab7 JR |
1296 | return mi_lttng_writer_open_element(writer, config_element_pids); |
1297 | } | |
1298 | ||
bf239d4c JR |
1299 | /* |
1300 | * TODO: move the listing of pid for user agent to process semantic on | |
1301 | * mi api bump. The use of process element break the mi api. | |
1302 | */ | |
ebbf5ab7 | 1303 | LTTNG_HIDDEN |
bf239d4c | 1304 | int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *name, |
5e18ec73 JR |
1305 | int is_open) |
1306 | { | |
1307 | int ret; | |
1308 | ||
bf239d4c JR |
1309 | /* Open pid process */ |
1310 | ret = mi_lttng_writer_open_element(writer, config_element_pid); | |
5e18ec73 JR |
1311 | if (ret) { |
1312 | goto end; | |
1313 | } | |
1314 | ||
1315 | /* Writing pid number */ | |
1316 | ret = mi_lttng_writer_write_element_signed_int(writer, | |
bf239d4c | 1317 | mi_lttng_element_pid_id, (int)pid); |
5e18ec73 JR |
1318 | if (ret) { |
1319 | goto end; | |
1320 | } | |
1321 | ||
1322 | /* Writing name of the process */ | |
ebbf5ab7 JR |
1323 | if (name) { |
1324 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
1325 | name); | |
1326 | if (ret) { | |
1327 | goto end; | |
1328 | } | |
1329 | } | |
1330 | ||
1331 | if (!is_open) { | |
1332 | /* Closing Pid */ | |
1333 | ret = mi_lttng_writer_close_element(writer); | |
1334 | } | |
1335 | ||
1336 | end: | |
1337 | return ret; | |
1338 | } | |
1339 | ||
1340 | LTTNG_HIDDEN | |
1341 | int mi_lttng_targets_open(struct mi_writer *writer) | |
1342 | { | |
1343 | return mi_lttng_writer_open_element(writer, | |
f95771e8 | 1344 | config_element_targets); |
ebbf5ab7 JR |
1345 | } |
1346 | ||
1347 | LTTNG_HIDDEN | |
1348 | int mi_lttng_pid_target(struct mi_writer *writer, pid_t pid, int is_open) | |
1349 | { | |
1350 | int ret; | |
1351 | ||
1352 | ret = mi_lttng_writer_open_element(writer, | |
f95771e8 | 1353 | config_element_target_pid); |
ebbf5ab7 JR |
1354 | if (ret) { |
1355 | goto end; | |
1356 | } | |
1357 | ||
1358 | /* Writing pid number | |
1359 | * Special case for element all on track untrack command | |
1360 | * All pid is represented as wildcard * | |
1361 | */ | |
1362 | if ((int) pid == -1) { | |
1363 | ret = mi_lttng_writer_write_element_string(writer, | |
1364 | config_element_pid, | |
1365 | mi_lttng_element_track_untrack_all_wildcard); | |
1366 | } else { | |
1367 | ret = mi_lttng_writer_write_element_signed_int(writer, | |
1368 | config_element_pid, (int) pid); | |
1369 | } | |
5e18ec73 JR |
1370 | if (ret) { |
1371 | goto end; | |
1372 | } | |
1373 | ||
1374 | if (!is_open) { | |
5e18ec73 | 1375 | ret = mi_lttng_writer_close_element(writer); |
ebbf5ab7 JR |
1376 | if (ret) { |
1377 | goto end; | |
1378 | } | |
5e18ec73 JR |
1379 | } |
1380 | ||
1381 | end: | |
1382 | return ret; | |
1383 | } | |
1384 | ||
1385 | LTTNG_HIDDEN | |
1386 | int mi_lttng_event_fields_open(struct mi_writer *writer) | |
1387 | { | |
1388 | return mi_lttng_writer_open_element(writer, mi_lttng_element_event_fields); | |
1389 | } | |
1390 | ||
1391 | LTTNG_HIDDEN | |
1392 | int mi_lttng_event_field(struct mi_writer *writer, | |
1393 | struct lttng_event_field *field) | |
1394 | { | |
1395 | int ret; | |
1396 | ||
1397 | if (!field->field_name[0]) { | |
5e18ec73 JR |
1398 | ret = 0; |
1399 | goto end; | |
1400 | } | |
1401 | ||
1402 | /* Open field */ | |
1403 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_event_field); | |
1404 | if (ret) { | |
1405 | goto end; | |
1406 | } | |
1407 | ||
1408 | if (!field->field_name[0]) { | |
1409 | goto close; | |
1410 | } | |
1411 | ||
1412 | /* Name */ | |
1413 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
1414 | field->field_name); | |
1415 | if (ret) { | |
1416 | goto end; | |
1417 | } | |
1418 | ||
1419 | /* Type */ | |
1420 | ret = mi_lttng_writer_write_element_string(writer, config_element_type, | |
1421 | mi_lttng_eventfieldtype_string(field->type)); | |
1422 | if (ret) { | |
1423 | goto end; | |
1424 | } | |
1425 | ||
1426 | /* nowrite */ | |
1427 | ret = mi_lttng_writer_write_element_signed_int(writer, | |
1428 | mi_lttng_element_nowrite, field->nowrite); | |
1429 | if (ret) { | |
1430 | goto end; | |
1431 | } | |
1432 | ||
1433 | close: | |
1434 | /* Close field element */ | |
1435 | ret = mi_lttng_writer_close_element(writer); | |
1436 | ||
1437 | end: | |
1438 | return ret; | |
1439 | } | |
7e66b1b0 | 1440 | |
89b72577 | 1441 | LTTNG_HIDDEN |
a23cb78a JG |
1442 | int mi_lttng_perf_counter_context(struct mi_writer *writer, |
1443 | struct lttng_event_perf_counter_ctx *perf_context) | |
89b72577 JRJ |
1444 | { |
1445 | int ret; | |
a23cb78a JG |
1446 | |
1447 | /* Open perf_counter_context */ | |
1448 | ret = mi_lttng_writer_open_element(writer, | |
1449 | mi_lttng_element_perf_counter_context); | |
89b72577 JRJ |
1450 | if (ret) { |
1451 | goto end; | |
1452 | } | |
1453 | ||
a23cb78a JG |
1454 | /* Type */ |
1455 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1456 | config_element_type, perf_context->type); | |
1457 | if (ret) { | |
89b72577 JRJ |
1458 | goto end; |
1459 | } | |
1460 | ||
a23cb78a JG |
1461 | /* Config */ |
1462 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1463 | config_element_config, perf_context->config); | |
1464 | if (ret) { | |
1465 | goto end; | |
89b72577 JRJ |
1466 | } |
1467 | ||
a23cb78a JG |
1468 | /* Name of the perf counter */ |
1469 | ret = mi_lttng_writer_write_element_string(writer, | |
1470 | config_element_name, perf_context->name); | |
1471 | if (ret) { | |
1472 | goto end; | |
89b72577 JRJ |
1473 | } |
1474 | ||
a23cb78a JG |
1475 | /* Close perf_counter_context */ |
1476 | ret = mi_lttng_writer_close_element(writer); | |
89b72577 JRJ |
1477 | end: |
1478 | return ret; | |
1479 | } | |
1480 | ||
a23cb78a JG |
1481 | static |
1482 | int mi_lttng_app_context(struct mi_writer *writer, | |
1483 | const char *provider_name, const char *ctx_name) | |
89b72577 JRJ |
1484 | { |
1485 | int ret; | |
1486 | ||
a23cb78a | 1487 | /* Open app */ |
89b72577 | 1488 | ret = mi_lttng_writer_open_element(writer, |
a23cb78a | 1489 | config_element_context_app); |
89b72577 JRJ |
1490 | if (ret) { |
1491 | goto end; | |
1492 | } | |
1493 | ||
a23cb78a JG |
1494 | /* provider_name */ |
1495 | ret = mi_lttng_writer_write_element_string(writer, | |
1496 | config_element_context_app_provider_name, | |
1497 | provider_name); | |
89b72577 JRJ |
1498 | if (ret) { |
1499 | goto end; | |
1500 | } | |
1501 | ||
a23cb78a JG |
1502 | /* ctx_name */ |
1503 | ret = mi_lttng_writer_write_element_string(writer, | |
1504 | config_element_context_app_ctx_name, ctx_name); | |
89b72577 JRJ |
1505 | if (ret) { |
1506 | goto end; | |
1507 | } | |
1508 | ||
a23cb78a JG |
1509 | /* Close app */ |
1510 | ret = mi_lttng_writer_close_element(writer); | |
1511 | end: | |
1512 | return ret; | |
1513 | } | |
1514 | ||
1515 | LTTNG_HIDDEN | |
1516 | int mi_lttng_context(struct mi_writer *writer, | |
1517 | struct lttng_event_context *context, int is_open) | |
1518 | { | |
1519 | int ret; | |
1520 | ||
1521 | /* Open context */ | |
1522 | ret = mi_lttng_writer_open_element(writer , config_element_context); | |
89b72577 JRJ |
1523 | if (ret) { |
1524 | goto end; | |
1525 | } | |
1526 | ||
a23cb78a JG |
1527 | /* Special case for PERF_*_COUNTER |
1528 | * print the lttng_event_perf_counter_ctx*/ | |
1529 | switch (context->ctx) { | |
1530 | case LTTNG_EVENT_CONTEXT_PERF_COUNTER: | |
1531 | case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER: | |
1532 | case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER: | |
1533 | { | |
1534 | struct lttng_event_perf_counter_ctx *perf_context = | |
1535 | &context->u.perf_counter; | |
1536 | ret = mi_lttng_perf_counter_context(writer, perf_context); | |
1537 | if (ret) { | |
1538 | goto end; | |
1539 | } | |
1540 | break; | |
1541 | } | |
1542 | case LTTNG_EVENT_CONTEXT_APP_CONTEXT: | |
1543 | { | |
1544 | ret = mi_lttng_app_context(writer, | |
1545 | context->u.app_ctx.provider_name, | |
1546 | context->u.app_ctx.ctx_name); | |
1547 | if (ret) { | |
1548 | goto end; | |
1549 | } | |
1550 | break; | |
1551 | } | |
1552 | default: | |
1553 | { | |
1554 | const char *type_string = mi_lttng_event_contexttype_string( | |
1555 | context->ctx); | |
1556 | if (!type_string) { | |
1557 | ret = -LTTNG_ERR_INVALID; | |
1558 | goto end; | |
1559 | } | |
1560 | ||
1561 | /* Print context type */ | |
1562 | ret = mi_lttng_writer_write_element_string(writer, | |
1563 | config_element_type, type_string); | |
1564 | break; | |
1565 | } | |
1566 | } | |
1567 | ||
1568 | /* Close context */ | |
1569 | if (!is_open) { | |
1570 | ret = mi_lttng_writer_close_element(writer); | |
1571 | } | |
1572 | ||
89b72577 JRJ |
1573 | end: |
1574 | return ret; | |
1575 | } | |
50534d6f JRJ |
1576 | |
1577 | LTTNG_HIDDEN | |
1578 | int mi_lttng_snapshot_output_session_name(struct mi_writer *writer, | |
1579 | const char *session_name) | |
1580 | { | |
1581 | int ret; | |
1582 | ||
1583 | /* Open session element */ | |
1584 | ret = mi_lttng_writer_open_element(writer, config_element_session); | |
1585 | if (ret) { | |
1586 | goto end; | |
1587 | } | |
1588 | ||
1589 | /* Snapshot output list for current session name */ | |
1590 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
1591 | session_name); | |
01defc26 JR |
1592 | if (ret) { |
1593 | goto end; | |
1594 | } | |
50534d6f JRJ |
1595 | |
1596 | /* Open element snapshots (sequence one snapshot) */ | |
1597 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_snapshots); | |
1598 | if (ret) { | |
1599 | goto end; | |
1600 | } | |
1601 | ||
1602 | end: | |
1603 | return ret; | |
1604 | } | |
1605 | ||
1606 | LTTNG_HIDDEN | |
1607 | int mi_lttng_snapshot_list_output(struct mi_writer *writer, | |
1608 | struct lttng_snapshot_output *output) | |
1609 | { | |
1610 | int ret; | |
1611 | ||
1612 | /* Open element snapshot output */ | |
1613 | ret = mi_lttng_writer_open_element(writer, | |
1614 | mi_lttng_element_command_snapshot); | |
1615 | if (ret) { | |
1616 | goto end; | |
1617 | } | |
1618 | ||
1619 | /* ID of the snapshot output */ | |
1620 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1621 | mi_lttng_element_id, output->id); | |
1622 | if (ret) { | |
1623 | goto end; | |
1624 | } | |
1625 | ||
1626 | /* Name of the output */ | |
1627 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
1628 | output->name); | |
1629 | if (ret) { | |
1630 | goto end; | |
1631 | } | |
1632 | ||
1633 | /* Destination of the output (ctrl_url)*/ | |
1634 | ret = mi_lttng_writer_write_element_string(writer, | |
1635 | mi_lttng_element_snapshot_ctrl_url, output->ctrl_url); | |
1636 | if (ret) { | |
1637 | goto end; | |
1638 | } | |
1639 | ||
1640 | /* Destination of the output (data_url) */ | |
1641 | ret = mi_lttng_writer_write_element_string(writer, | |
1642 | mi_lttng_element_snapshot_data_url, output->data_url); | |
1643 | if (ret) { | |
1644 | goto end; | |
1645 | } | |
1646 | ||
1647 | /* total size of all stream combined */ | |
1648 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1649 | mi_lttng_element_snapshot_max_size, output->max_size); | |
1650 | if (ret) { | |
1651 | goto end; | |
1652 | } | |
1653 | ||
1654 | /* Close snapshot output element */ | |
1655 | ret = mi_lttng_writer_close_element(writer); | |
1656 | ||
1657 | end: | |
1658 | return ret; | |
1659 | } | |
1660 | ||
1661 | LTTNG_HIDDEN | |
1662 | int mi_lttng_snapshot_del_output(struct mi_writer *writer, int id, | |
1663 | const char *name, const char *current_session_name) | |
1664 | { | |
1665 | int ret; | |
1666 | ||
1667 | /* Open element del_snapshot */ | |
1668 | ret = mi_lttng_writer_open_element(writer, | |
1669 | mi_lttng_element_command_snapshot); | |
1670 | if (ret) { | |
1671 | goto end; | |
1672 | } | |
1673 | ||
1674 | ||
1675 | if (id != UINT32_MAX) { | |
1676 | /* "Snapshot output "id" successfully deleted | |
1677 | * for "current_session_name" | |
1678 | * ID of the snapshot output | |
1679 | */ | |
1680 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1681 | mi_lttng_element_id, id); | |
1682 | if (ret) { | |
1683 | goto end; | |
1684 | } | |
1685 | } else { | |
1686 | /* "Snapshot output "name" successfully deleted | |
1687 | * for session "current_session_name" | |
1688 | * Name of the output | |
1689 | */ | |
1690 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
1691 | name); | |
1692 | if (ret) { | |
1693 | goto end; | |
1694 | } | |
1695 | } | |
1696 | ||
1697 | /* Snapshot was deleted for session "current_session_name"*/ | |
1698 | ret = mi_lttng_writer_write_element_string(writer, | |
1699 | mi_lttng_element_snapshot_session_name, | |
1700 | current_session_name); | |
1701 | if (ret) { | |
1702 | goto end; | |
1703 | } | |
1704 | ||
1705 | /* Close snapshot element */ | |
1706 | ret = mi_lttng_writer_close_element(writer); | |
1707 | ||
1708 | end: | |
1709 | return ret; | |
1710 | } | |
1711 | ||
1712 | LTTNG_HIDDEN | |
1713 | int mi_lttng_snapshot_add_output(struct mi_writer *writer, | |
1714 | const char *current_session_name, const char *n_ptr, | |
1715 | struct lttng_snapshot_output *output) | |
1716 | { | |
1717 | int ret; | |
1718 | ||
1719 | /* Open element snapshot */ | |
1720 | ret = mi_lttng_writer_open_element(writer, | |
1721 | mi_lttng_element_command_snapshot); | |
1722 | if (ret) { | |
1723 | goto end; | |
1724 | } | |
1725 | ||
1726 | /* Snapshot output id */ | |
1727 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1728 | mi_lttng_element_id, output->id); | |
1729 | if (ret) { | |
1730 | goto end; | |
1731 | } | |
1732 | ||
1733 | /* Snapshot output names */ | |
1734 | ret = mi_lttng_writer_write_element_string(writer, | |
1735 | config_element_name, n_ptr); | |
1736 | if (ret) { | |
1737 | goto end; | |
1738 | } | |
1739 | ||
1740 | /* Destination of the output (ctrl_url)*/ | |
1741 | ret = mi_lttng_writer_write_element_string(writer, | |
1742 | mi_lttng_element_snapshot_ctrl_url, output->ctrl_url); | |
1743 | if (ret) { | |
1744 | goto end; | |
1745 | } | |
1746 | ||
1747 | /* Snapshot added for session "current_session_name"*/ | |
1748 | ret = mi_lttng_writer_write_element_string(writer, | |
1749 | mi_lttng_element_snapshot_session_name, current_session_name); | |
1750 | if (ret) { | |
1751 | goto end; | |
1752 | } | |
1753 | ||
1754 | /* total size of all stream combined */ | |
1755 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1756 | mi_lttng_element_snapshot_max_size, output->max_size); | |
1757 | if (ret) { | |
1758 | goto end; | |
1759 | } | |
1760 | ||
1761 | /* Close snapshot element */ | |
1762 | ret = mi_lttng_writer_close_element(writer); | |
1763 | ||
1764 | end: | |
1765 | return ret; | |
1766 | } | |
1767 | ||
1768 | LTTNG_HIDDEN | |
1769 | int mi_lttng_snapshot_record(struct mi_writer *writer, | |
1770 | const char *current_session_name, const char *url, | |
1771 | const char *cmdline_ctrl_url, const char *cmdline_data_url) | |
1772 | { | |
1773 | int ret; | |
1774 | ||
1775 | /* Open element snapshot */ | |
1776 | ret = mi_lttng_writer_open_element(writer, | |
1777 | mi_lttng_element_command_snapshot); | |
1778 | if (ret) { | |
1779 | goto end; | |
1780 | } | |
1781 | ||
1782 | /* | |
1783 | * If a valid an URL was given, serialize it, | |
1784 | * else take the command line data and ctrl urls*/ | |
1785 | if (url) { | |
1786 | /* Destination of the output (ctrl_url)*/ | |
1787 | ret = mi_lttng_writer_write_element_string(writer, | |
1788 | mi_lttng_element_snapshot_ctrl_url, url); | |
1789 | if (ret) { | |
1790 | goto end; | |
1791 | } | |
1792 | } else if (cmdline_ctrl_url) { | |
1793 | /* Destination of the output (ctrl_url)*/ | |
1794 | ret = mi_lttng_writer_write_element_string(writer, | |
1795 | mi_lttng_element_snapshot_ctrl_url, cmdline_ctrl_url); | |
1796 | if (ret) { | |
1797 | goto end; | |
1798 | } | |
1799 | ||
1800 | /* Destination of the output (data_url) */ | |
1801 | ret = mi_lttng_writer_write_element_string(writer, | |
1802 | mi_lttng_element_snapshot_data_url, cmdline_data_url); | |
1803 | if (ret) { | |
1804 | goto end; | |
1805 | } | |
1806 | } | |
1807 | ||
1808 | /* Close record_snapshot element */ | |
1809 | ret = mi_lttng_writer_close_element(writer); | |
1810 | ||
1811 | end: | |
1812 | return ret; | |
1813 | } |