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