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