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