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