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; | |
a72332c3 JR |
378 | case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE: |
379 | return config_event_context_interruptible; | |
380 | case LTTNG_EVENT_CONTEXT_PREEMPTIBLE: | |
381 | return config_event_context_preemptible; | |
382 | case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE: | |
383 | return config_event_context_need_reschedule; | |
384 | case LTTNG_EVENT_CONTEXT_MIGRATABLE: | |
385 | return config_event_context_migratable; | |
89b72577 JRJ |
386 | default: |
387 | return NULL; | |
388 | } | |
389 | } | |
390 | ||
ea75976a | 391 | LTTNG_HIDDEN |
5e18ec73 JR |
392 | const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val) |
393 | { | |
394 | switch (val) { | |
395 | case(LTTNG_EVENT_FIELD_INTEGER): | |
396 | return mi_lttng_element_type_integer; | |
397 | case(LTTNG_EVENT_FIELD_ENUM): | |
398 | return mi_lttng_element_type_enum; | |
399 | case(LTTNG_EVENT_FIELD_FLOAT): | |
400 | return mi_lttng_element_type_float; | |
401 | case(LTTNG_EVENT_FIELD_STRING): | |
402 | return mi_lttng_element_type_string; | |
403 | default: | |
404 | return mi_lttng_element_type_other; | |
405 | } | |
406 | } | |
407 | ||
ea75976a | 408 | LTTNG_HIDDEN |
5e18ec73 JR |
409 | const char *mi_lttng_domaintype_string(enum lttng_domain_type value) |
410 | { | |
411 | /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */ | |
412 | switch (value) { | |
413 | case LTTNG_DOMAIN_KERNEL: | |
414 | return config_domain_type_kernel; | |
415 | case LTTNG_DOMAIN_UST: | |
416 | return config_domain_type_ust; | |
417 | case LTTNG_DOMAIN_JUL: | |
418 | return config_domain_type_jul; | |
5cdb6027 DG |
419 | case LTTNG_DOMAIN_LOG4J: |
420 | return config_domain_type_log4j; | |
b789735e PP |
421 | case LTTNG_DOMAIN_PYTHON: |
422 | return config_domain_type_python; | |
5e18ec73 JR |
423 | default: |
424 | /* Should not have an unknown domain */ | |
425 | assert(0); | |
2855532e | 426 | return NULL; |
5e18ec73 JR |
427 | } |
428 | } | |
429 | ||
ea75976a | 430 | LTTNG_HIDDEN |
5e18ec73 JR |
431 | const char *mi_lttng_buffertype_string(enum lttng_buffer_type value) |
432 | { | |
433 | switch (value) { | |
434 | case LTTNG_BUFFER_PER_PID: | |
435 | return config_buffer_type_per_pid; | |
436 | case LTTNG_BUFFER_PER_UID: | |
437 | return config_buffer_type_per_uid; | |
438 | case LTTNG_BUFFER_GLOBAL: | |
439 | return config_buffer_type_global; | |
440 | default: | |
441 | /* Should not have an unknow buffer type */ | |
442 | assert(0); | |
2855532e | 443 | return NULL; |
5e18ec73 JR |
444 | } |
445 | } | |
446 | ||
c7e35b03 JR |
447 | LTTNG_HIDDEN |
448 | struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type) | |
449 | { | |
450 | struct mi_writer *mi_writer; | |
451 | ||
452 | mi_writer = zmalloc(sizeof(struct mi_writer)); | |
453 | if (!mi_writer) { | |
454 | PERROR("zmalloc mi_writer_create"); | |
455 | goto end; | |
456 | } | |
457 | if (mi_output_type == LTTNG_MI_XML) { | |
705bb62f | 458 | mi_writer->writer = config_writer_create(fd_output, 0); |
c7e35b03 JR |
459 | if (!mi_writer->writer) { |
460 | goto err_destroy; | |
461 | } | |
462 | mi_writer->type = LTTNG_MI_XML; | |
463 | } else { | |
464 | goto err_destroy; | |
465 | } | |
466 | ||
467 | end: | |
468 | return mi_writer; | |
469 | ||
470 | err_destroy: | |
471 | free(mi_writer); | |
472 | return NULL; | |
473 | } | |
474 | ||
475 | LTTNG_HIDDEN | |
476 | int mi_lttng_writer_destroy(struct mi_writer *writer) | |
477 | { | |
478 | int ret; | |
479 | ||
480 | if (!writer) { | |
481 | ret = -EINVAL; | |
482 | goto end; | |
483 | } | |
484 | ||
485 | ret = config_writer_destroy(writer->writer); | |
486 | if (ret < 0) { | |
487 | goto end; | |
488 | } | |
489 | ||
490 | free(writer); | |
491 | end: | |
492 | return ret; | |
493 | } | |
494 | ||
495 | LTTNG_HIDDEN | |
496 | int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command) | |
497 | { | |
498 | int ret; | |
499 | ||
e10b6a1c JG |
500 | /* |
501 | * A command is always the MI's root node, it must declare the current | |
502 | * namespace and schema URIs and the schema's version. | |
503 | */ | |
504 | ret = config_writer_open_element(writer->writer, | |
505 | mi_lttng_element_command); | |
506 | if (ret) { | |
507 | goto end; | |
508 | } | |
509 | ||
510 | ret = config_writer_write_attribute(writer->writer, | |
41af1adf | 511 | mi_lttng_xmlns, DEFAULT_LTTNG_MI_NAMESPACE); |
e10b6a1c JG |
512 | if (ret) { |
513 | goto end; | |
514 | } | |
515 | ||
516 | ret = config_writer_write_attribute(writer->writer, | |
517 | mi_lttng_xmlns_xsi, mi_lttng_w3_schema_uri); | |
c7e35b03 JR |
518 | if (ret) { |
519 | goto end; | |
520 | } | |
e10b6a1c JG |
521 | |
522 | ret = config_writer_write_attribute(writer->writer, | |
523 | mi_lttng_schema_location, | |
524 | mi_lttng_schema_location_uri); | |
525 | if (ret) { | |
526 | goto end; | |
527 | } | |
528 | ||
529 | ret = config_writer_write_attribute(writer->writer, | |
530 | mi_lttng_schema_version, | |
531 | mi_lttng_schema_version_value); | |
532 | if (ret) { | |
533 | goto end; | |
534 | } | |
535 | ||
c7e35b03 JR |
536 | ret = mi_lttng_writer_write_element_string(writer, |
537 | mi_lttng_element_command_name, command); | |
538 | end: | |
539 | return ret; | |
540 | } | |
541 | ||
542 | LTTNG_HIDDEN | |
543 | int mi_lttng_writer_command_close(struct mi_writer *writer) | |
544 | { | |
545 | return mi_lttng_writer_close_element(writer); | |
546 | } | |
547 | ||
548 | LTTNG_HIDDEN | |
549 | int mi_lttng_writer_open_element(struct mi_writer *writer, | |
550 | const char *element_name) | |
551 | { | |
552 | return config_writer_open_element(writer->writer, element_name); | |
553 | } | |
554 | ||
555 | LTTNG_HIDDEN | |
556 | int mi_lttng_writer_close_element(struct mi_writer *writer) | |
557 | { | |
558 | return config_writer_close_element(writer->writer); | |
559 | } | |
560 | ||
5e18ec73 JR |
561 | LTTNG_HIDDEN |
562 | int mi_lttng_close_multi_element(struct mi_writer *writer, | |
563 | unsigned int nb_element) | |
564 | { | |
565 | int ret, i; | |
566 | ||
567 | if (nb_element < 1) { | |
568 | ret = 0; | |
569 | goto end; | |
570 | } | |
571 | for (i = 0; i < nb_element; i++) { | |
572 | ret = mi_lttng_writer_close_element(writer); | |
573 | if (ret) { | |
574 | goto end; | |
575 | } | |
576 | } | |
577 | end: | |
578 | return ret; | |
579 | } | |
580 | ||
c7e35b03 JR |
581 | LTTNG_HIDDEN |
582 | int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer, | |
583 | const char *element_name, uint64_t value) | |
584 | { | |
585 | return config_writer_write_element_unsigned_int(writer->writer, | |
586 | element_name, value); | |
587 | } | |
588 | ||
589 | LTTNG_HIDDEN | |
590 | int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer, | |
591 | const char *element_name, int64_t value) | |
592 | { | |
593 | return config_writer_write_element_signed_int(writer->writer, | |
594 | element_name, value); | |
595 | } | |
596 | ||
597 | LTTNG_HIDDEN | |
598 | int mi_lttng_writer_write_element_bool(struct mi_writer *writer, | |
599 | const char *element_name, int value) | |
600 | { | |
601 | return config_writer_write_element_bool(writer->writer, | |
602 | element_name, value); | |
603 | } | |
604 | ||
605 | LTTNG_HIDDEN | |
606 | int mi_lttng_writer_write_element_string(struct mi_writer *writer, | |
607 | const char *element_name, const char *value) | |
608 | { | |
609 | return config_writer_write_element_string(writer->writer, | |
610 | element_name, value); | |
611 | } | |
612 | ||
613 | LTTNG_HIDDEN | |
614 | int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version, | |
615 | const char *lttng_description, const char *lttng_license) | |
616 | { | |
617 | int ret; | |
618 | ||
619 | /* Open version */ | |
620 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_version); | |
621 | if (ret) { | |
622 | goto end; | |
623 | } | |
624 | ||
625 | /* Version string (contain info like rc etc.) */ | |
626 | ret = mi_lttng_writer_write_element_string(writer, | |
782f3c61 | 627 | mi_lttng_element_version_str, version->version); |
c7e35b03 JR |
628 | if (ret) { |
629 | goto end; | |
630 | } | |
631 | ||
632 | /* Major version number */ | |
633 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
634 | mi_lttng_element_version_major, version->version_major); | |
635 | if (ret) { | |
636 | goto end; | |
637 | } | |
638 | ||
639 | /* Minor version number */ | |
640 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
641 | mi_lttng_element_version_minor, version->version_minor); | |
642 | if (ret) { | |
643 | goto end; | |
644 | } | |
645 | ||
314d5222 JRJ |
646 | /* Commit version number */ |
647 | ret = mi_lttng_writer_write_element_string(writer, | |
648 | mi_lttng_element_version_commit, version->version_commit); | |
649 | if (ret) { | |
650 | goto end; | |
651 | } | |
652 | ||
c7e35b03 JR |
653 | /* Patch number */ |
654 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
655 | mi_lttng_element_version_patch_level, version->version_patchlevel); | |
656 | if (ret) { | |
657 | goto end; | |
658 | } | |
659 | ||
660 | /* Name of the version */ | |
661 | ret = mi_lttng_writer_write_element_string(writer, | |
662 | config_element_name, version->version_name); | |
663 | if (ret) { | |
664 | goto end; | |
665 | } | |
666 | ||
667 | /* Description mostly related to beer... */ | |
668 | ret = mi_lttng_writer_write_element_string(writer, | |
669 | mi_lttng_element_version_description, lttng_description); | |
670 | if (ret) { | |
671 | goto end; | |
672 | } | |
673 | ||
674 | /* url */ | |
675 | ret = mi_lttng_writer_write_element_string(writer, | |
676 | mi_lttng_element_version_web, version->package_url); | |
677 | if (ret) { | |
678 | goto end; | |
679 | } | |
680 | ||
681 | /* License: free as in free beer...no...*speech* */ | |
682 | ret = mi_lttng_writer_write_element_string(writer, | |
683 | mi_lttng_element_version_license, lttng_license); | |
684 | if (ret) { | |
685 | goto end; | |
686 | } | |
687 | ||
688 | /* Close version element */ | |
689 | ret = mi_lttng_writer_close_element(writer); | |
690 | ||
691 | end: | |
692 | return ret; | |
693 | } | |
694 | ||
5e18ec73 JR |
695 | LTTNG_HIDDEN |
696 | int mi_lttng_sessions_open(struct mi_writer *writer) | |
697 | { | |
698 | return mi_lttng_writer_open_element(writer, config_element_sessions); | |
699 | } | |
700 | ||
c7e35b03 JR |
701 | LTTNG_HIDDEN |
702 | int mi_lttng_session(struct mi_writer *writer, | |
703 | struct lttng_session *session, int is_open) | |
704 | { | |
705 | int ret; | |
706 | ||
5e18ec73 JR |
707 | assert(session); |
708 | ||
709 | /* Open sessions element */ | |
c7e35b03 JR |
710 | ret = mi_lttng_writer_open_element(writer, |
711 | config_element_session); | |
712 | if (ret) { | |
713 | goto end; | |
714 | } | |
715 | ||
716 | /* Name of the session */ | |
717 | ret = mi_lttng_writer_write_element_string(writer, | |
718 | config_element_name, session->name); | |
719 | if (ret) { | |
720 | goto end; | |
721 | } | |
722 | ||
5e18ec73 | 723 | /* Path */ |
c7e35b03 JR |
724 | ret = mi_lttng_writer_write_element_string(writer, |
725 | config_element_path, session->path); | |
726 | if (ret) { | |
727 | goto end; | |
728 | } | |
729 | ||
5e18ec73 JR |
730 | /* Enabled ? */ |
731 | ret = mi_lttng_writer_write_element_bool(writer, | |
c7e35b03 JR |
732 | config_element_enabled, session->enabled); |
733 | if (ret) { | |
734 | goto end; | |
735 | } | |
736 | ||
5e18ec73 | 737 | /* Snapshot mode */ |
c7e35b03 JR |
738 | ret = mi_lttng_writer_write_element_unsigned_int(writer, |
739 | config_element_snapshot_mode, session->snapshot_mode); | |
740 | if (ret) { | |
741 | goto end; | |
742 | } | |
743 | ||
5e18ec73 | 744 | /* Live timer interval in usec */ |
c7e35b03 JR |
745 | ret = mi_lttng_writer_write_element_unsigned_int(writer, |
746 | config_element_live_timer_interval, | |
747 | session->live_timer_interval); | |
748 | if (ret) { | |
749 | goto end; | |
750 | } | |
751 | ||
752 | if (!is_open) { | |
753 | /* Closing session element */ | |
754 | ret = mi_lttng_writer_close_element(writer); | |
755 | } | |
756 | end: | |
757 | return ret; | |
758 | ||
759 | } | |
5e18ec73 JR |
760 | |
761 | LTTNG_HIDDEN | |
762 | int mi_lttng_domains_open(struct mi_writer *writer) | |
763 | { | |
764 | return mi_lttng_writer_open_element(writer, config_element_domains); | |
765 | } | |
766 | ||
767 | LTTNG_HIDDEN | |
768 | int mi_lttng_domain(struct mi_writer *writer, | |
769 | struct lttng_domain *domain, int is_open) | |
770 | { | |
771 | int ret = 0; | |
772 | const char *str_domain; | |
773 | const char *str_buffer; | |
774 | ||
775 | assert(domain); | |
776 | ||
777 | /* Open domain element */ | |
778 | ret = mi_lttng_writer_open_element(writer, config_element_domain); | |
779 | if (ret) { | |
780 | goto end; | |
781 | } | |
782 | ||
783 | /* Domain Type */ | |
784 | str_domain = mi_lttng_domaintype_string(domain->type); | |
785 | ret = mi_lttng_writer_write_element_string(writer, config_element_type, | |
786 | str_domain); | |
787 | if (ret) { | |
788 | goto end; | |
789 | } | |
790 | ||
791 | /* Buffer Type */ | |
792 | str_buffer= mi_lttng_buffertype_string(domain->buf_type); | |
793 | ret = mi_lttng_writer_write_element_string(writer, | |
794 | config_element_buffer_type, str_buffer); | |
795 | if (ret) { | |
796 | goto end; | |
797 | } | |
798 | ||
d813f89b JRJ |
799 | /* TODO: union attr |
800 | * This union is not currently used and was added for | |
801 | * future ust domain support. | |
802 | * Date: 25-06-2014 | |
803 | * */ | |
5e18ec73 JR |
804 | |
805 | if (!is_open) { | |
806 | /* Closing domain element */ | |
807 | ret = mi_lttng_writer_close_element(writer); | |
808 | } | |
809 | ||
810 | end: | |
811 | return ret; | |
812 | ||
813 | } | |
814 | ||
815 | LTTNG_HIDDEN | |
816 | int mi_lttng_channels_open(struct mi_writer *writer) | |
817 | { | |
818 | return mi_lttng_writer_open_element(writer, config_element_channels); | |
819 | } | |
820 | ||
821 | LTTNG_HIDDEN | |
822 | int mi_lttng_channel(struct mi_writer *writer, | |
823 | struct lttng_channel *channel, int is_open) | |
824 | { | |
825 | int ret = 0; | |
826 | ||
827 | assert(channel); | |
828 | ||
829 | /* Opening channel element */ | |
830 | ret = mi_lttng_writer_open_element(writer, config_element_channel); | |
831 | if (ret) { | |
832 | goto end; | |
833 | } | |
834 | ||
835 | /* Name */ | |
836 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
837 | channel->name); | |
838 | if (ret) { | |
839 | goto end; | |
840 | } | |
841 | ||
842 | /* Enabled ? */ | |
843 | ret = mi_lttng_writer_write_element_bool(writer, | |
844 | config_element_enabled, channel->enabled); | |
845 | if (ret) { | |
846 | goto end; | |
847 | } | |
848 | ||
849 | /* Attribute */ | |
850 | ret = mi_lttng_channel_attr(writer, &channel->attr); | |
851 | if (ret) { | |
852 | goto end; | |
853 | } | |
854 | ||
855 | if (!is_open) { | |
856 | /* Closing channel element */ | |
857 | ret = mi_lttng_writer_close_element(writer); | |
858 | if (ret) { | |
859 | goto end; | |
860 | } | |
861 | } | |
862 | end: | |
863 | return ret; | |
864 | } | |
865 | ||
866 | LTTNG_HIDDEN | |
867 | int mi_lttng_channel_attr(struct mi_writer *writer, | |
868 | struct lttng_channel_attr *attr) | |
869 | { | |
870 | int ret = 0; | |
fb83fe64 JD |
871 | struct lttng_channel *chan = caa_container_of(attr, |
872 | struct lttng_channel, attr); | |
cf0bcb51 | 873 | uint64_t discarded_events, lost_packets, monitor_timer_interval; |
491d1539 | 874 | int64_t blocking_timeout; |
5e18ec73 JR |
875 | |
876 | assert(attr); | |
877 | ||
fb83fe64 JD |
878 | ret = lttng_channel_get_discarded_event_count(chan, &discarded_events); |
879 | if (ret) { | |
880 | goto end; | |
881 | } | |
882 | ||
883 | ret = lttng_channel_get_lost_packet_count(chan, &lost_packets); | |
884 | if (ret) { | |
885 | goto end; | |
886 | } | |
887 | ||
cf0bcb51 JG |
888 | ret = lttng_channel_get_monitor_timer_interval(chan, |
889 | &monitor_timer_interval); | |
890 | if (ret) { | |
891 | goto end; | |
892 | } | |
893 | ||
491d1539 MD |
894 | ret = lttng_channel_get_blocking_timeout(chan, |
895 | &blocking_timeout); | |
896 | if (ret) { | |
897 | goto end; | |
898 | } | |
899 | ||
5e18ec73 JR |
900 | /* Opening Attributes */ |
901 | ret = mi_lttng_writer_open_element(writer, config_element_attributes); | |
902 | if (ret) { | |
903 | goto end; | |
904 | } | |
905 | ||
906 | /* Overwrite */ | |
907 | ret = mi_lttng_writer_write_element_string(writer, | |
908 | config_element_overwrite_mode, | |
909 | attr->overwrite ? config_overwrite_mode_overwrite : | |
910 | config_overwrite_mode_discard); | |
911 | if (ret) { | |
912 | goto end; | |
913 | } | |
914 | ||
915 | /* Sub buffer size in byte */ | |
916 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
917 | config_element_subbuf_size, attr->subbuf_size); | |
918 | if (ret) { | |
919 | goto end; | |
920 | } | |
921 | ||
922 | /* Number of subbuffer (power of two) */ | |
923 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
924 | config_element_num_subbuf, | |
925 | attr->num_subbuf); | |
926 | if (ret) { | |
927 | goto end; | |
928 | } | |
929 | ||
930 | /* Switch timer interval in usec */ | |
931 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
932 | config_element_switch_timer_interval, | |
933 | attr->switch_timer_interval); | |
934 | if (ret) { | |
935 | goto end; | |
936 | } | |
937 | ||
938 | /* Read timer interval in usec */ | |
939 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
940 | config_element_read_timer_interval, | |
941 | attr->read_timer_interval); | |
942 | if (ret) { | |
943 | goto end; | |
944 | } | |
945 | ||
cf0bcb51 JG |
946 | /* Monitor timer interval in usec */ |
947 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
948 | config_element_monitor_timer_interval, | |
949 | monitor_timer_interval); | |
950 | if (ret) { | |
951 | goto end; | |
952 | } | |
953 | ||
491d1539 MD |
954 | /* Retry timeout in usec */ |
955 | ret = mi_lttng_writer_write_element_signed_int(writer, | |
956 | config_element_blocking_timeout, | |
957 | blocking_timeout); | |
958 | if (ret) { | |
959 | goto end; | |
960 | } | |
961 | ||
5e18ec73 JR |
962 | /* Event output */ |
963 | ret = mi_lttng_writer_write_element_string(writer, | |
964 | config_element_output_type, | |
965 | attr->output == LTTNG_EVENT_SPLICE ? | |
966 | config_output_type_splice : config_output_type_mmap); | |
967 | if (ret) { | |
968 | goto end; | |
969 | } | |
970 | ||
971 | /* Tracefile size in bytes */ | |
972 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
973 | config_element_tracefile_size, attr->tracefile_size); | |
974 | if (ret) { | |
975 | goto end; | |
976 | } | |
977 | ||
978 | /* Count of tracefiles */ | |
979 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
980 | config_element_tracefile_count, | |
981 | attr->tracefile_count); | |
982 | if (ret) { | |
983 | goto end; | |
984 | } | |
985 | ||
986 | /* Live timer interval in usec*/ | |
987 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
988 | config_element_live_timer_interval, | |
989 | attr->live_timer_interval); | |
990 | if (ret) { | |
fb83fe64 JD |
991 | goto end; |
992 | } | |
993 | ||
994 | /* Discarded events */ | |
995 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
996 | config_element_discarded_events, | |
997 | discarded_events); | |
998 | if (ret) { | |
999 | goto end; | |
1000 | } | |
1001 | ||
1002 | /* Lost packets */ | |
1003 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1004 | config_element_lost_packets, | |
1005 | lost_packets); | |
1006 | if (ret) { | |
5e18ec73 JR |
1007 | goto end; |
1008 | } | |
1009 | ||
1010 | /* Closing attributes */ | |
1011 | ret = mi_lttng_writer_close_element(writer); | |
1012 | if (ret) { | |
1013 | goto end; | |
1014 | } | |
1015 | end: | |
1016 | return ret; | |
1017 | ||
1018 | } | |
1019 | ||
1020 | LTTNG_HIDDEN | |
1021 | int mi_lttng_event_common_attributes(struct mi_writer *writer, | |
1022 | struct lttng_event *event) | |
1023 | { | |
1024 | int ret; | |
7b4aa11d | 1025 | const char *filter_expression; |
5e18ec73 JR |
1026 | |
1027 | /* Open event element */ | |
1028 | ret = mi_lttng_writer_open_element(writer, config_element_event); | |
1029 | if (ret) { | |
1030 | goto end; | |
1031 | } | |
1032 | ||
f4a088f7 | 1033 | /* Event name */ |
5e18ec73 JR |
1034 | ret = mi_lttng_writer_write_element_string(writer, |
1035 | config_element_name, event->name); | |
1036 | if (ret) { | |
1037 | goto end; | |
1038 | } | |
1039 | ||
f4a088f7 | 1040 | /* Event type */ |
5e18ec73 JR |
1041 | ret = mi_lttng_writer_write_element_string(writer, |
1042 | config_element_type, mi_lttng_eventtype_string(event->type)); | |
1043 | if (ret) { | |
1044 | goto end; | |
1045 | } | |
1046 | ||
f4a088f7 | 1047 | /* Is event enabled */ |
5e18ec73 JR |
1048 | ret = mi_lttng_writer_write_element_bool(writer, |
1049 | config_element_enabled, event->enabled); | |
1050 | if (ret) { | |
1051 | goto end; | |
1052 | } | |
1053 | ||
7b4aa11d | 1054 | /* Event filter expression */ |
134e72ed | 1055 | ret = lttng_event_get_filter_expression(event, &filter_expression); |
7b4aa11d PP |
1056 | if (ret) { |
1057 | goto end; | |
1058 | } | |
1059 | ||
1060 | if (filter_expression) { | |
1061 | ret = mi_lttng_writer_write_element_string(writer, | |
654f9f5e JG |
1062 | config_element_filter_expression, |
1063 | filter_expression); | |
7b4aa11d PP |
1064 | if (ret) { |
1065 | goto end; | |
1066 | } | |
1067 | } | |
1068 | ||
5e18ec73 JR |
1069 | end: |
1070 | return ret; | |
1071 | } | |
1072 | ||
eecb9438 PP |
1073 | static int write_event_exclusions(struct mi_writer *writer, |
1074 | struct lttng_event *event) | |
1075 | { | |
1076 | int i; | |
1077 | int ret; | |
1078 | int exclusion_count; | |
1079 | ||
eecb9438 PP |
1080 | /* Open event exclusions */ |
1081 | ret = mi_lttng_writer_open_element(writer, config_element_exclusions); | |
1082 | if (ret) { | |
1083 | goto end; | |
1084 | } | |
1085 | ||
1086 | exclusion_count = lttng_event_get_exclusion_name_count(event); | |
1087 | if (exclusion_count < 0) { | |
1088 | ret = exclusion_count; | |
1089 | goto end; | |
1090 | } | |
1091 | ||
1092 | for (i = 0; i < exclusion_count; i++) { | |
1093 | const char *name; | |
1094 | ||
1095 | ret = lttng_event_get_exclusion_name(event, i, &name); | |
1096 | if (ret) { | |
1097 | /* Close exclusions */ | |
1098 | mi_lttng_writer_close_element(writer); | |
1099 | goto end; | |
1100 | } | |
1101 | ||
1102 | ret = mi_lttng_writer_write_element_string(writer, | |
1103 | config_element_exclusion, name); | |
1104 | if (ret) { | |
1105 | /* Close exclusions */ | |
1106 | mi_lttng_writer_close_element(writer); | |
1107 | goto end; | |
1108 | } | |
1109 | } | |
1110 | ||
1111 | /* Close exclusions */ | |
1112 | ret = mi_lttng_writer_close_element(writer); | |
1113 | ||
1114 | end: | |
1115 | return ret; | |
1116 | } | |
1117 | ||
5e18ec73 JR |
1118 | LTTNG_HIDDEN |
1119 | int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer, | |
970d848b | 1120 | struct lttng_event *event, enum lttng_domain_type domain) |
5e18ec73 JR |
1121 | { |
1122 | int ret; | |
1123 | ||
f4a088f7 | 1124 | /* Event loglevel */ |
5e18ec73 | 1125 | ret = mi_lttng_writer_write_element_string(writer, |
970d848b DG |
1126 | config_element_loglevel, |
1127 | mi_lttng_loglevel_string(event->loglevel, domain)); | |
5e18ec73 JR |
1128 | if (ret) { |
1129 | goto end; | |
1130 | } | |
1131 | ||
f4a088f7 | 1132 | /* Log level type */ |
5e18ec73 JR |
1133 | ret = mi_lttng_writer_write_element_string(writer, |
1134 | config_element_loglevel_type, | |
1135 | mi_lttng_logleveltype_string(event->loglevel_type)); | |
1136 | if (ret) { | |
1137 | goto end; | |
1138 | } | |
1139 | ||
eecb9438 PP |
1140 | /* Event exclusions */ |
1141 | ret = write_event_exclusions(writer, event); | |
5e18ec73 JR |
1142 | |
1143 | end: | |
1144 | return ret; | |
1145 | } | |
1146 | ||
1147 | LTTNG_HIDDEN | |
1148 | int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer *writer, | |
1149 | struct lttng_event *event) | |
1150 | { | |
1151 | /* event exclusion filter */ | |
eecb9438 | 1152 | return write_event_exclusions(writer, event); |
5e18ec73 JR |
1153 | } |
1154 | ||
1155 | LTTNG_HIDDEN | |
1156 | int mi_lttng_event_function_probe(struct mi_writer *writer, | |
1157 | struct lttng_event *event) | |
1158 | { | |
1159 | int ret; | |
1160 | ||
3b4a6e40 JRJ |
1161 | ret = mi_lttng_writer_open_element(writer, config_element_attributes); |
1162 | if (ret) { | |
1163 | goto end; | |
1164 | } | |
1165 | ||
1166 | ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes); | |
1167 | if (ret) { | |
1168 | goto end; | |
1169 | } | |
1170 | ||
5e18ec73 JR |
1171 | if (event->attr.probe.addr != 0) { |
1172 | /* event probe address */ | |
1173 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1174 | config_element_address, event->attr.probe.addr); | |
1175 | if (ret) { | |
1176 | goto end; | |
1177 | } | |
1178 | } else { | |
1179 | /* event probe offset */ | |
1180 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1181 | config_element_offset, event->attr.probe.offset); | |
1182 | if (ret) { | |
1183 | goto end; | |
1184 | } | |
1185 | ||
1186 | /* event probe symbol_name */ | |
1187 | ret = mi_lttng_writer_write_element_string(writer, | |
1188 | config_element_symbol_name, event->attr.probe.symbol_name); | |
1189 | if (ret) { | |
1190 | goto end; | |
1191 | } | |
1192 | } | |
3b4a6e40 JRJ |
1193 | |
1194 | /* Close probe_attributes and attributes */ | |
1195 | ret = mi_lttng_close_multi_element(writer, 2); | |
5e18ec73 JR |
1196 | end: |
1197 | return ret; | |
1198 | } | |
1199 | ||
1200 | LTTNG_HIDDEN | |
1201 | int mi_lttng_event_function_entry(struct mi_writer *writer, | |
1202 | struct lttng_event *event) | |
1203 | { | |
3b4a6e40 JRJ |
1204 | int ret; |
1205 | ||
1206 | ret = mi_lttng_writer_open_element(writer, config_element_attributes); | |
1207 | if (ret) { | |
1208 | goto end; | |
1209 | } | |
1210 | ||
1211 | ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes); | |
1212 | if (ret) { | |
1213 | goto end; | |
1214 | } | |
1215 | ||
5e18ec73 | 1216 | /* event probe symbol_name */ |
3b4a6e40 | 1217 | ret = mi_lttng_writer_write_element_string(writer, |
5e18ec73 | 1218 | config_element_symbol_name, event->attr.ftrace.symbol_name); |
3b4a6e40 JRJ |
1219 | if (ret) { |
1220 | goto end; | |
1221 | } | |
1222 | ||
1223 | /* Close function_attributes and attributes */ | |
1224 | ret = mi_lttng_close_multi_element(writer, 2); | |
1225 | end: | |
1226 | return ret; | |
5e18ec73 JR |
1227 | } |
1228 | ||
1229 | LTTNG_HIDDEN | |
1230 | int mi_lttng_events_open(struct mi_writer *writer) | |
1231 | { | |
1232 | return mi_lttng_writer_open_element(writer, config_element_events); | |
1233 | } | |
1234 | ||
1235 | LTTNG_HIDDEN | |
1236 | int mi_lttng_event(struct mi_writer *writer, | |
970d848b | 1237 | struct lttng_event *event, int is_open, enum lttng_domain_type domain) |
5e18ec73 JR |
1238 | { |
1239 | int ret; | |
1240 | ||
1241 | ret = mi_lttng_event_common_attributes(writer, event); | |
1242 | if (ret) { | |
1243 | goto end; | |
1244 | } | |
1245 | ||
1246 | switch (event->type) { | |
5e18ec73 JR |
1247 | case LTTNG_EVENT_TRACEPOINT: |
1248 | { | |
1249 | if (event->loglevel != -1) { | |
970d848b | 1250 | ret = mi_lttng_event_tracepoint_loglevel(writer, event, domain); |
5e18ec73 JR |
1251 | } else { |
1252 | ret = mi_lttng_event_tracepoint_no_loglevel(writer, event); | |
1253 | } | |
1254 | break; | |
1255 | } | |
3b4a6e40 JRJ |
1256 | case LTTNG_EVENT_FUNCTION: |
1257 | /* Fallthrough */ | |
5e18ec73 JR |
1258 | case LTTNG_EVENT_PROBE: |
1259 | ret = mi_lttng_event_function_probe(writer, event); | |
1260 | break; | |
1261 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
1262 | ret = mi_lttng_event_function_entry(writer, event); | |
1263 | break; | |
89476427 JRJ |
1264 | case LTTNG_EVENT_ALL: |
1265 | /* Fallthrough */ | |
5e18ec73 JR |
1266 | default: |
1267 | break; | |
1268 | } | |
1269 | ||
1270 | if (!is_open) { | |
1271 | ret = mi_lttng_writer_close_element(writer); | |
1272 | } | |
1273 | ||
1274 | end: | |
1275 | return ret; | |
1276 | } | |
1277 | ||
ebbf5ab7 JR |
1278 | LTTNG_HIDDEN |
1279 | int mi_lttng_trackers_open(struct mi_writer *writer) | |
1280 | { | |
1281 | return mi_lttng_writer_open_element(writer, config_element_trackers); | |
1282 | } | |
1283 | ||
1284 | LTTNG_HIDDEN | |
1285 | int mi_lttng_pid_tracker_open(struct mi_writer *writer) | |
1286 | { | |
1287 | int ret; | |
1288 | ||
1289 | /* Open element pid_tracker */ | |
1290 | ret = mi_lttng_writer_open_element(writer, config_element_pid_tracker); | |
1291 | if (ret) { | |
1292 | goto end; | |
1293 | } | |
1294 | ||
1295 | /* Open targets element */ | |
1296 | ret = mi_lttng_targets_open(writer); | |
1297 | end: | |
1298 | return ret; | |
1299 | } | |
1300 | ||
5e18ec73 JR |
1301 | LTTNG_HIDDEN |
1302 | int mi_lttng_pids_open(struct mi_writer *writer) | |
1303 | { | |
ebbf5ab7 JR |
1304 | return mi_lttng_writer_open_element(writer, config_element_pids); |
1305 | } | |
1306 | ||
bf239d4c JR |
1307 | /* |
1308 | * TODO: move the listing of pid for user agent to process semantic on | |
1309 | * mi api bump. The use of process element break the mi api. | |
1310 | */ | |
ebbf5ab7 | 1311 | LTTNG_HIDDEN |
bf239d4c | 1312 | int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *name, |
5e18ec73 JR |
1313 | int is_open) |
1314 | { | |
1315 | int ret; | |
1316 | ||
bf239d4c JR |
1317 | /* Open pid process */ |
1318 | ret = mi_lttng_writer_open_element(writer, config_element_pid); | |
5e18ec73 JR |
1319 | if (ret) { |
1320 | goto end; | |
1321 | } | |
1322 | ||
1323 | /* Writing pid number */ | |
1324 | ret = mi_lttng_writer_write_element_signed_int(writer, | |
bf239d4c | 1325 | mi_lttng_element_pid_id, (int)pid); |
5e18ec73 JR |
1326 | if (ret) { |
1327 | goto end; | |
1328 | } | |
1329 | ||
1330 | /* Writing name of the process */ | |
ebbf5ab7 JR |
1331 | if (name) { |
1332 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
1333 | name); | |
1334 | if (ret) { | |
1335 | goto end; | |
1336 | } | |
1337 | } | |
1338 | ||
1339 | if (!is_open) { | |
1340 | /* Closing Pid */ | |
1341 | ret = mi_lttng_writer_close_element(writer); | |
1342 | } | |
1343 | ||
1344 | end: | |
1345 | return ret; | |
1346 | } | |
1347 | ||
1348 | LTTNG_HIDDEN | |
1349 | int mi_lttng_targets_open(struct mi_writer *writer) | |
1350 | { | |
1351 | return mi_lttng_writer_open_element(writer, | |
f95771e8 | 1352 | config_element_targets); |
ebbf5ab7 JR |
1353 | } |
1354 | ||
1355 | LTTNG_HIDDEN | |
1356 | int mi_lttng_pid_target(struct mi_writer *writer, pid_t pid, int is_open) | |
1357 | { | |
1358 | int ret; | |
1359 | ||
1360 | ret = mi_lttng_writer_open_element(writer, | |
f95771e8 | 1361 | config_element_target_pid); |
ebbf5ab7 JR |
1362 | if (ret) { |
1363 | goto end; | |
1364 | } | |
1365 | ||
1366 | /* Writing pid number | |
1367 | * Special case for element all on track untrack command | |
1368 | * All pid is represented as wildcard * | |
1369 | */ | |
1370 | if ((int) pid == -1) { | |
1371 | ret = mi_lttng_writer_write_element_string(writer, | |
1372 | config_element_pid, | |
1373 | mi_lttng_element_track_untrack_all_wildcard); | |
1374 | } else { | |
1375 | ret = mi_lttng_writer_write_element_signed_int(writer, | |
1376 | config_element_pid, (int) pid); | |
1377 | } | |
5e18ec73 JR |
1378 | if (ret) { |
1379 | goto end; | |
1380 | } | |
1381 | ||
1382 | if (!is_open) { | |
5e18ec73 | 1383 | ret = mi_lttng_writer_close_element(writer); |
ebbf5ab7 JR |
1384 | if (ret) { |
1385 | goto end; | |
1386 | } | |
5e18ec73 JR |
1387 | } |
1388 | ||
1389 | end: | |
1390 | return ret; | |
1391 | } | |
1392 | ||
1393 | LTTNG_HIDDEN | |
1394 | int mi_lttng_event_fields_open(struct mi_writer *writer) | |
1395 | { | |
1396 | return mi_lttng_writer_open_element(writer, mi_lttng_element_event_fields); | |
1397 | } | |
1398 | ||
1399 | LTTNG_HIDDEN | |
1400 | int mi_lttng_event_field(struct mi_writer *writer, | |
1401 | struct lttng_event_field *field) | |
1402 | { | |
1403 | int ret; | |
1404 | ||
1405 | if (!field->field_name[0]) { | |
5e18ec73 JR |
1406 | ret = 0; |
1407 | goto end; | |
1408 | } | |
1409 | ||
1410 | /* Open field */ | |
1411 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_event_field); | |
1412 | if (ret) { | |
1413 | goto end; | |
1414 | } | |
1415 | ||
1416 | if (!field->field_name[0]) { | |
1417 | goto close; | |
1418 | } | |
1419 | ||
1420 | /* Name */ | |
1421 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
1422 | field->field_name); | |
1423 | if (ret) { | |
1424 | goto end; | |
1425 | } | |
1426 | ||
1427 | /* Type */ | |
1428 | ret = mi_lttng_writer_write_element_string(writer, config_element_type, | |
1429 | mi_lttng_eventfieldtype_string(field->type)); | |
1430 | if (ret) { | |
1431 | goto end; | |
1432 | } | |
1433 | ||
1434 | /* nowrite */ | |
1435 | ret = mi_lttng_writer_write_element_signed_int(writer, | |
1436 | mi_lttng_element_nowrite, field->nowrite); | |
1437 | if (ret) { | |
1438 | goto end; | |
1439 | } | |
1440 | ||
1441 | close: | |
1442 | /* Close field element */ | |
1443 | ret = mi_lttng_writer_close_element(writer); | |
1444 | ||
1445 | end: | |
1446 | return ret; | |
1447 | } | |
7e66b1b0 | 1448 | |
89b72577 | 1449 | LTTNG_HIDDEN |
a23cb78a JG |
1450 | int mi_lttng_perf_counter_context(struct mi_writer *writer, |
1451 | struct lttng_event_perf_counter_ctx *perf_context) | |
89b72577 JRJ |
1452 | { |
1453 | int ret; | |
a23cb78a JG |
1454 | |
1455 | /* Open perf_counter_context */ | |
1456 | ret = mi_lttng_writer_open_element(writer, | |
1457 | mi_lttng_element_perf_counter_context); | |
89b72577 JRJ |
1458 | if (ret) { |
1459 | goto end; | |
1460 | } | |
1461 | ||
a23cb78a JG |
1462 | /* Type */ |
1463 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1464 | config_element_type, perf_context->type); | |
1465 | if (ret) { | |
89b72577 JRJ |
1466 | goto end; |
1467 | } | |
1468 | ||
a23cb78a JG |
1469 | /* Config */ |
1470 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1471 | config_element_config, perf_context->config); | |
1472 | if (ret) { | |
1473 | goto end; | |
89b72577 JRJ |
1474 | } |
1475 | ||
a23cb78a JG |
1476 | /* Name of the perf counter */ |
1477 | ret = mi_lttng_writer_write_element_string(writer, | |
1478 | config_element_name, perf_context->name); | |
1479 | if (ret) { | |
1480 | goto end; | |
89b72577 JRJ |
1481 | } |
1482 | ||
a23cb78a JG |
1483 | /* Close perf_counter_context */ |
1484 | ret = mi_lttng_writer_close_element(writer); | |
89b72577 JRJ |
1485 | end: |
1486 | return ret; | |
1487 | } | |
1488 | ||
a23cb78a JG |
1489 | static |
1490 | int mi_lttng_app_context(struct mi_writer *writer, | |
1491 | const char *provider_name, const char *ctx_name) | |
89b72577 JRJ |
1492 | { |
1493 | int ret; | |
1494 | ||
a23cb78a | 1495 | /* Open app */ |
89b72577 | 1496 | ret = mi_lttng_writer_open_element(writer, |
a23cb78a | 1497 | config_element_context_app); |
89b72577 JRJ |
1498 | if (ret) { |
1499 | goto end; | |
1500 | } | |
1501 | ||
a23cb78a JG |
1502 | /* provider_name */ |
1503 | ret = mi_lttng_writer_write_element_string(writer, | |
1504 | config_element_context_app_provider_name, | |
1505 | provider_name); | |
89b72577 JRJ |
1506 | if (ret) { |
1507 | goto end; | |
1508 | } | |
1509 | ||
a23cb78a JG |
1510 | /* ctx_name */ |
1511 | ret = mi_lttng_writer_write_element_string(writer, | |
1512 | config_element_context_app_ctx_name, ctx_name); | |
89b72577 JRJ |
1513 | if (ret) { |
1514 | goto end; | |
1515 | } | |
1516 | ||
a23cb78a JG |
1517 | /* Close app */ |
1518 | ret = mi_lttng_writer_close_element(writer); | |
1519 | end: | |
1520 | return ret; | |
1521 | } | |
1522 | ||
1523 | LTTNG_HIDDEN | |
1524 | int mi_lttng_context(struct mi_writer *writer, | |
1525 | struct lttng_event_context *context, int is_open) | |
1526 | { | |
1527 | int ret; | |
1528 | ||
1529 | /* Open context */ | |
1530 | ret = mi_lttng_writer_open_element(writer , config_element_context); | |
89b72577 JRJ |
1531 | if (ret) { |
1532 | goto end; | |
1533 | } | |
1534 | ||
a23cb78a JG |
1535 | /* Special case for PERF_*_COUNTER |
1536 | * print the lttng_event_perf_counter_ctx*/ | |
1537 | switch (context->ctx) { | |
1538 | case LTTNG_EVENT_CONTEXT_PERF_COUNTER: | |
1539 | case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER: | |
1540 | case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER: | |
1541 | { | |
1542 | struct lttng_event_perf_counter_ctx *perf_context = | |
1543 | &context->u.perf_counter; | |
1544 | ret = mi_lttng_perf_counter_context(writer, perf_context); | |
1545 | if (ret) { | |
1546 | goto end; | |
1547 | } | |
1548 | break; | |
1549 | } | |
1550 | case LTTNG_EVENT_CONTEXT_APP_CONTEXT: | |
1551 | { | |
1552 | ret = mi_lttng_app_context(writer, | |
1553 | context->u.app_ctx.provider_name, | |
1554 | context->u.app_ctx.ctx_name); | |
1555 | if (ret) { | |
1556 | goto end; | |
1557 | } | |
1558 | break; | |
1559 | } | |
1560 | default: | |
1561 | { | |
1562 | const char *type_string = mi_lttng_event_contexttype_string( | |
1563 | context->ctx); | |
1564 | if (!type_string) { | |
1565 | ret = -LTTNG_ERR_INVALID; | |
1566 | goto end; | |
1567 | } | |
1568 | ||
1569 | /* Print context type */ | |
1570 | ret = mi_lttng_writer_write_element_string(writer, | |
1571 | config_element_type, type_string); | |
1572 | break; | |
1573 | } | |
1574 | } | |
1575 | ||
1576 | /* Close context */ | |
1577 | if (!is_open) { | |
1578 | ret = mi_lttng_writer_close_element(writer); | |
1579 | } | |
1580 | ||
89b72577 JRJ |
1581 | end: |
1582 | return ret; | |
1583 | } | |
50534d6f JRJ |
1584 | |
1585 | LTTNG_HIDDEN | |
1586 | int mi_lttng_snapshot_output_session_name(struct mi_writer *writer, | |
1587 | const char *session_name) | |
1588 | { | |
1589 | int ret; | |
1590 | ||
1591 | /* Open session element */ | |
1592 | ret = mi_lttng_writer_open_element(writer, config_element_session); | |
1593 | if (ret) { | |
1594 | goto end; | |
1595 | } | |
1596 | ||
1597 | /* Snapshot output list for current session name */ | |
1598 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
1599 | session_name); | |
01defc26 JR |
1600 | if (ret) { |
1601 | goto end; | |
1602 | } | |
50534d6f JRJ |
1603 | |
1604 | /* Open element snapshots (sequence one snapshot) */ | |
1605 | ret = mi_lttng_writer_open_element(writer, mi_lttng_element_snapshots); | |
1606 | if (ret) { | |
1607 | goto end; | |
1608 | } | |
1609 | ||
1610 | end: | |
1611 | return ret; | |
1612 | } | |
1613 | ||
1614 | LTTNG_HIDDEN | |
1615 | int mi_lttng_snapshot_list_output(struct mi_writer *writer, | |
1616 | struct lttng_snapshot_output *output) | |
1617 | { | |
1618 | int ret; | |
1619 | ||
1620 | /* Open element snapshot output */ | |
1621 | ret = mi_lttng_writer_open_element(writer, | |
1622 | mi_lttng_element_command_snapshot); | |
1623 | if (ret) { | |
1624 | goto end; | |
1625 | } | |
1626 | ||
1627 | /* ID of the snapshot output */ | |
1628 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1629 | mi_lttng_element_id, output->id); | |
1630 | if (ret) { | |
1631 | goto end; | |
1632 | } | |
1633 | ||
1634 | /* Name of the output */ | |
1635 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
1636 | output->name); | |
1637 | if (ret) { | |
1638 | goto end; | |
1639 | } | |
1640 | ||
1641 | /* Destination of the output (ctrl_url)*/ | |
1642 | ret = mi_lttng_writer_write_element_string(writer, | |
1643 | mi_lttng_element_snapshot_ctrl_url, output->ctrl_url); | |
1644 | if (ret) { | |
1645 | goto end; | |
1646 | } | |
1647 | ||
1648 | /* Destination of the output (data_url) */ | |
1649 | ret = mi_lttng_writer_write_element_string(writer, | |
1650 | mi_lttng_element_snapshot_data_url, output->data_url); | |
1651 | if (ret) { | |
1652 | goto end; | |
1653 | } | |
1654 | ||
1655 | /* total size of all stream combined */ | |
1656 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1657 | mi_lttng_element_snapshot_max_size, output->max_size); | |
1658 | if (ret) { | |
1659 | goto end; | |
1660 | } | |
1661 | ||
1662 | /* Close snapshot output element */ | |
1663 | ret = mi_lttng_writer_close_element(writer); | |
1664 | ||
1665 | end: | |
1666 | return ret; | |
1667 | } | |
1668 | ||
1669 | LTTNG_HIDDEN | |
1670 | int mi_lttng_snapshot_del_output(struct mi_writer *writer, int id, | |
1671 | const char *name, const char *current_session_name) | |
1672 | { | |
1673 | int ret; | |
1674 | ||
1675 | /* Open element del_snapshot */ | |
1676 | ret = mi_lttng_writer_open_element(writer, | |
1677 | mi_lttng_element_command_snapshot); | |
1678 | if (ret) { | |
1679 | goto end; | |
1680 | } | |
1681 | ||
1682 | ||
1683 | if (id != UINT32_MAX) { | |
1684 | /* "Snapshot output "id" successfully deleted | |
1685 | * for "current_session_name" | |
1686 | * ID of the snapshot output | |
1687 | */ | |
1688 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1689 | mi_lttng_element_id, id); | |
1690 | if (ret) { | |
1691 | goto end; | |
1692 | } | |
1693 | } else { | |
1694 | /* "Snapshot output "name" successfully deleted | |
1695 | * for session "current_session_name" | |
1696 | * Name of the output | |
1697 | */ | |
1698 | ret = mi_lttng_writer_write_element_string(writer, config_element_name, | |
1699 | name); | |
1700 | if (ret) { | |
1701 | goto end; | |
1702 | } | |
1703 | } | |
1704 | ||
1705 | /* Snapshot was deleted for session "current_session_name"*/ | |
1706 | ret = mi_lttng_writer_write_element_string(writer, | |
1707 | mi_lttng_element_snapshot_session_name, | |
1708 | current_session_name); | |
1709 | if (ret) { | |
1710 | goto end; | |
1711 | } | |
1712 | ||
1713 | /* Close snapshot element */ | |
1714 | ret = mi_lttng_writer_close_element(writer); | |
1715 | ||
1716 | end: | |
1717 | return ret; | |
1718 | } | |
1719 | ||
1720 | LTTNG_HIDDEN | |
1721 | int mi_lttng_snapshot_add_output(struct mi_writer *writer, | |
1722 | const char *current_session_name, const char *n_ptr, | |
1723 | struct lttng_snapshot_output *output) | |
1724 | { | |
1725 | int ret; | |
1726 | ||
1727 | /* Open element snapshot */ | |
1728 | ret = mi_lttng_writer_open_element(writer, | |
1729 | mi_lttng_element_command_snapshot); | |
1730 | if (ret) { | |
1731 | goto end; | |
1732 | } | |
1733 | ||
1734 | /* Snapshot output id */ | |
1735 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1736 | mi_lttng_element_id, output->id); | |
1737 | if (ret) { | |
1738 | goto end; | |
1739 | } | |
1740 | ||
1741 | /* Snapshot output names */ | |
1742 | ret = mi_lttng_writer_write_element_string(writer, | |
1743 | config_element_name, n_ptr); | |
1744 | if (ret) { | |
1745 | goto end; | |
1746 | } | |
1747 | ||
1748 | /* Destination of the output (ctrl_url)*/ | |
1749 | ret = mi_lttng_writer_write_element_string(writer, | |
1750 | mi_lttng_element_snapshot_ctrl_url, output->ctrl_url); | |
1751 | if (ret) { | |
1752 | goto end; | |
1753 | } | |
1754 | ||
1755 | /* Snapshot added for session "current_session_name"*/ | |
1756 | ret = mi_lttng_writer_write_element_string(writer, | |
1757 | mi_lttng_element_snapshot_session_name, current_session_name); | |
1758 | if (ret) { | |
1759 | goto end; | |
1760 | } | |
1761 | ||
1762 | /* total size of all stream combined */ | |
1763 | ret = mi_lttng_writer_write_element_unsigned_int(writer, | |
1764 | mi_lttng_element_snapshot_max_size, output->max_size); | |
1765 | if (ret) { | |
1766 | goto end; | |
1767 | } | |
1768 | ||
1769 | /* Close snapshot element */ | |
1770 | ret = mi_lttng_writer_close_element(writer); | |
1771 | ||
1772 | end: | |
1773 | return ret; | |
1774 | } | |
1775 | ||
1776 | LTTNG_HIDDEN | |
1777 | int mi_lttng_snapshot_record(struct mi_writer *writer, | |
1778 | const char *current_session_name, const char *url, | |
1779 | const char *cmdline_ctrl_url, const char *cmdline_data_url) | |
1780 | { | |
1781 | int ret; | |
1782 | ||
1783 | /* Open element snapshot */ | |
1784 | ret = mi_lttng_writer_open_element(writer, | |
1785 | mi_lttng_element_command_snapshot); | |
1786 | if (ret) { | |
1787 | goto end; | |
1788 | } | |
1789 | ||
1790 | /* | |
1791 | * If a valid an URL was given, serialize it, | |
1792 | * else take the command line data and ctrl urls*/ | |
1793 | if (url) { | |
1794 | /* Destination of the output (ctrl_url)*/ | |
1795 | ret = mi_lttng_writer_write_element_string(writer, | |
1796 | mi_lttng_element_snapshot_ctrl_url, url); | |
1797 | if (ret) { | |
1798 | goto end; | |
1799 | } | |
1800 | } else if (cmdline_ctrl_url) { | |
1801 | /* Destination of the output (ctrl_url)*/ | |
1802 | ret = mi_lttng_writer_write_element_string(writer, | |
1803 | mi_lttng_element_snapshot_ctrl_url, cmdline_ctrl_url); | |
1804 | if (ret) { | |
1805 | goto end; | |
1806 | } | |
1807 | ||
1808 | /* Destination of the output (data_url) */ | |
1809 | ret = mi_lttng_writer_write_element_string(writer, | |
1810 | mi_lttng_element_snapshot_data_url, cmdline_data_url); | |
1811 | if (ret) { | |
1812 | goto end; | |
1813 | } | |
1814 | } | |
1815 | ||
1816 | /* Close record_snapshot element */ | |
1817 | ret = mi_lttng_writer_close_element(writer); | |
1818 | ||
1819 | end: | |
1820 | return ret; | |
1821 | } |