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