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