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