Mi disable-event command: support and validation
[lttng-tools.git] / src / common / mi-lttng.c
CommitLineData
c7e35b03
JR
1/*
2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
5e18ec73 19
c7e35b03
JR
20#include <include/config.h>
21#include <common/config/config.h>
c7e35b03
JR
22#include "mi-lttng.h"
23
5e18ec73
JR
24#include <assert.h>
25
c7e35b03
JR
26/* Strings related to command */
27const char * const mi_lttng_element_command = "command";
37d03ff7 28const char * const mi_lttng_element_command_name = "name";
c7e35b03 29const char * const mi_lttng_element_command_version = "version";
89476427 30const char * const mi_lttng_element_command_enable_event = "enable-event";
c7e35b03 31const char * const mi_lttng_element_command_list = "list";
1734c658
JRJ
32const char * const mi_lttng_element_command_save = "save";
33const char * const mi_lttng_element_command_load = "load";
1cfc0bc8 34const char * const mi_lttng_element_command_start = "start";
e5b83100 35const char * const mi_lttng_element_command_stop = "stop";
37d03ff7 36const char * const mi_lttng_element_command_create = "create";
65f25c66 37const char * const mi_lttng_element_command_destroy = "destroy";
7e66b1b0 38const char * const mi_lttng_element_command_calibrate = "calibrate";
89b72577 39const char * const mi_lttng_element_command_add_context = "add-context";
acc09215 40const char * const mi_lttng_element_command_enable_channels = "enable-channel";
ce91cd0b 41const char * const mi_lttng_element_command_set_session = "set-session";
e4d484a5 42const char * const mi_lttng_element_command_disable_event = "disable-event";
c7e35b03 43const char * const mi_lttng_element_command_output = "output";
1734c658 44const char * const mi_lttng_element_command_success = "success";
c7e35b03 45
1734c658 46/* Strings related to version command */
c7e35b03
JR
47const char * const mi_lttng_element_version = "version";
48const char * const mi_lttng_element_version_str = "string";
49const char * const mi_lttng_element_version_web = "url";
50const char * const mi_lttng_element_version_major = "major";
51const char * const mi_lttng_element_version_minor = "minor";
314d5222 52const char * const mi_lttng_element_version_commit = "commit";
c7e35b03
JR
53const char * const mi_lttng_element_version_license = "license";
54const char * const mi_lttng_element_version_patch_level = "patchLevel";
55const char * const mi_lttng_element_version_description = "description";
56
5e18ec73
JR
57/* Strings related to pid */
58const char * const mi_lttng_element_pids = "pids";
59const char * const mi_lttng_element_pid = "pid";
60const char * const mi_lttng_element_pid_id = "id";
61
1734c658
JRJ
62/* Strings related to save command */
63const char * const mi_lttng_element_save = "save";
64
65/* Strings related to load command */
66const char * const mi_lttng_element_load = "load";
67
5e18ec73
JR
68/* String related to a lttng_event_field */
69const char * const mi_lttng_element_event_field = "event_field";
70const char * const mi_lttng_element_event_fields = "event_fields";
71
89b72577
JRJ
72/* String related to lttng_event_context */
73const char * const mi_lttng_context_type_perf_counter = "PERF_COUNTER";
74const char * const mi_lttng_context_type_perf_cpu_counter = "PERF_CPU_COUNTER";
75const char * const mi_lttng_context_type_perf_thread_counter = "PERF_THREAD_COUNTER";
76
77/* String related to lttng_event_perf_counter_ctx */
78const char * const mi_lttng_element_perf_counter_context = "perf_counter_context";
79
5e18ec73
JR
80/* General elements of mi_lttng */
81const char * const mi_lttng_element_type_other = "OTHER";
82const char * const mi_lttng_element_type_integer = "INTEGER";
83const char * const mi_lttng_element_type_enum = "ENUM";
84const char * const mi_lttng_element_type_float = "FLOAT";
85const char * const mi_lttng_element_type_string = "STRING";
86const char * const mi_lttng_element_nowrite = "nowrite";
89b72577 87const char * const mi_lttng_element_success = "success";
5e18ec73
JR
88
89/* String related to loglevel */
90const char * const mi_lttng_loglevel_str_alert = "TRACE_ALERT";
91const char * const mi_lttng_loglevel_str_crit = "TRACE_CRIT";
92const char * const mi_lttng_loglevel_str_debug = "TRACE_DEBUG";
93const char * const mi_lttng_loglevel_str_debug_function = "TRACE_DEBUG_FUNCTION";
94const char * const mi_lttng_loglevel_str_debug_line = "TRACE_DEBUG_LINE";
95const char * const mi_lttng_loglevel_str_debug_module = "TRACE_DEBUG_MODULE";
96const char * const mi_lttng_loglevel_str_debug_process = "TRACE_DEBUG_PROCESS";
97const char * const mi_lttng_loglevel_str_debug_program = "TRACE_DEBUG_PROGRAM";
98const char * const mi_lttng_loglevel_str_debug_system = "TRACE_DEBUG_SYSTEM";
99const char * const mi_lttng_loglevel_str_debug_unit = "TRACE_DEBUG_UNIT";
100const char * const mi_lttng_loglevel_str_emerg = "TRACE_EMERG";
101const char * const mi_lttng_loglevel_str_err = "TRACE_ERR";
102const char * const mi_lttng_loglevel_str_info = "TRACE_INFO";
103const char * const mi_lttng_loglevel_str_notice = "TRACE_NOTICE";
104const char * const mi_lttng_loglevel_str_unknown = "UNKNOWN";
105const char * const mi_lttng_loglevel_str_warning = "TRACE_WARNING";
106
1734c658 107/* String related to loglevel type */
5e18ec73
JR
108const char * const mi_lttng_loglevel_type_all = "ALL";
109const char * const mi_lttng_loglevel_type_range = "RANGE";
110const char * const mi_lttng_loglevel_type_single = "SINGLE";
111const char * const mi_lttng_loglevel_type_unknown = "UNKNOWN";
112
7e66b1b0
JRJ
113/* String related to lttng_calibrate */
114const char * const mi_lttng_element_calibrate = "calibrate";
115const char * const mi_lttng_element_calibrate_function = "FUNCTION";
116
5e18ec73
JR
117const char * const mi_lttng_element_empty = "";
118
119const char *mi_lttng_loglevel_string(int value)
120{
121 switch (value) {
122 case -1:
123 return mi_lttng_element_empty;
124 case LTTNG_LOGLEVEL_EMERG:
125 return mi_lttng_loglevel_str_emerg;
126 case LTTNG_LOGLEVEL_ALERT:
127 return mi_lttng_loglevel_str_alert;
128 case LTTNG_LOGLEVEL_CRIT:
129 return mi_lttng_loglevel_str_crit;
130 case LTTNG_LOGLEVEL_ERR:
131 return mi_lttng_loglevel_str_err;
132 case LTTNG_LOGLEVEL_WARNING:
133 return mi_lttng_loglevel_str_warning;
134 case LTTNG_LOGLEVEL_NOTICE:
135 return mi_lttng_loglevel_str_notice;
136 case LTTNG_LOGLEVEL_INFO:
137 return mi_lttng_loglevel_str_info;
138 case LTTNG_LOGLEVEL_DEBUG_SYSTEM:
139 return mi_lttng_loglevel_str_debug_system;
140 case LTTNG_LOGLEVEL_DEBUG_PROGRAM:
141 return mi_lttng_loglevel_str_debug_program;
142 case LTTNG_LOGLEVEL_DEBUG_PROCESS:
143 return mi_lttng_loglevel_str_debug_process;
144 case LTTNG_LOGLEVEL_DEBUG_MODULE:
145 return mi_lttng_loglevel_str_debug_module;
146 case LTTNG_LOGLEVEL_DEBUG_UNIT:
147 return mi_lttng_loglevel_str_debug_unit;
148 case LTTNG_LOGLEVEL_DEBUG_FUNCTION:
149 return mi_lttng_loglevel_str_debug_function;
150 case LTTNG_LOGLEVEL_DEBUG_LINE:
151 return mi_lttng_loglevel_str_debug_line;
152 case LTTNG_LOGLEVEL_DEBUG:
153 return mi_lttng_loglevel_str_debug;
154 default:
155 return mi_lttng_loglevel_str_unknown;
156 }
157}
158
159const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value)
160{
161 switch (value) {
162 case LTTNG_EVENT_LOGLEVEL_ALL:
163 return mi_lttng_loglevel_type_all;
164 case LTTNG_EVENT_LOGLEVEL_RANGE:
165 return mi_lttng_loglevel_type_range;
166 case LTTNG_EVENT_LOGLEVEL_SINGLE:
167 return mi_lttng_loglevel_type_single;
168 default:
169 return mi_lttng_loglevel_type_unknown;
170 }
171}
172
173const char *mi_lttng_eventtype_string(enum lttng_event_type value)
174{
175 switch (value) {
176 case LTTNG_EVENT_ALL:
177 return config_event_type_all;
178 case LTTNG_EVENT_TRACEPOINT:
179 return config_event_type_tracepoint;
180 case LTTNG_EVENT_PROBE:
181 return config_event_type_probe;
182 case LTTNG_EVENT_FUNCTION:
183 return config_event_type_function;
184 case LTTNG_EVENT_FUNCTION_ENTRY:
185 return config_event_type_function_entry;
186 case LTTNG_EVENT_SYSCALL:
187 return config_event_type_syscall;
188 case LTTNG_EVENT_NOOP:
189 return config_event_type_noop;
190 default:
191 return mi_lttng_element_empty;
192 }
193}
194
89b72577
JRJ
195const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val)
196{
197 switch (val) {
198 case LTTNG_EVENT_CONTEXT_PID:
199 return config_event_context_pid;
200 case LTTNG_EVENT_CONTEXT_PERF_COUNTER:
201 return mi_lttng_context_type_perf_counter;
202 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER:
203 return mi_lttng_context_type_perf_thread_counter;
204 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER:
205 return mi_lttng_context_type_perf_cpu_counter;
206 case LTTNG_EVENT_CONTEXT_PROCNAME:
207 return config_event_context_procname;
208 case LTTNG_EVENT_CONTEXT_PRIO:
209 return config_event_context_prio;
210 case LTTNG_EVENT_CONTEXT_NICE:
211 return config_event_context_nice;
212 case LTTNG_EVENT_CONTEXT_VPID:
213 return config_event_context_vpid;
214 case LTTNG_EVENT_CONTEXT_TID:
215 return config_event_context_tid;
216 case LTTNG_EVENT_CONTEXT_VTID:
217 return config_event_context_vtid;
218 case LTTNG_EVENT_CONTEXT_PPID:
219 return config_event_context_ppid;
220 case LTTNG_EVENT_CONTEXT_VPPID:
221 return config_event_context_vppid;
222 case LTTNG_EVENT_CONTEXT_PTHREAD_ID:
223 return config_event_context_pthread_id;
224 case LTTNG_EVENT_CONTEXT_HOSTNAME:
225 return config_event_context_hostname;
226 case LTTNG_EVENT_CONTEXT_IP:
227 return config_event_context_ip;
228 default:
229 return NULL;
230 }
231}
232
5e18ec73
JR
233const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val)
234{
235 switch (val) {
236 case(LTTNG_EVENT_FIELD_INTEGER):
237 return mi_lttng_element_type_integer;
238 case(LTTNG_EVENT_FIELD_ENUM):
239 return mi_lttng_element_type_enum;
240 case(LTTNG_EVENT_FIELD_FLOAT):
241 return mi_lttng_element_type_float;
242 case(LTTNG_EVENT_FIELD_STRING):
243 return mi_lttng_element_type_string;
244 default:
245 return mi_lttng_element_type_other;
246 }
247}
248
249const char *mi_lttng_domaintype_string(enum lttng_domain_type value)
250{
251 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
252 switch (value) {
253 case LTTNG_DOMAIN_KERNEL:
254 return config_domain_type_kernel;
255 case LTTNG_DOMAIN_UST:
256 return config_domain_type_ust;
257 case LTTNG_DOMAIN_JUL:
258 return config_domain_type_jul;
259 default:
260 /* Should not have an unknown domain */
261 assert(0);
262 }
263}
264
265const char *mi_lttng_buffertype_string(enum lttng_buffer_type value)
266{
267 switch (value) {
268 case LTTNG_BUFFER_PER_PID:
269 return config_buffer_type_per_pid;
270 case LTTNG_BUFFER_PER_UID:
271 return config_buffer_type_per_uid;
272 case LTTNG_BUFFER_GLOBAL:
273 return config_buffer_type_global;
274 default:
275 /* Should not have an unknow buffer type */
276 assert(0);
277 }
278}
279
7e66b1b0
JRJ
280const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val)
281{
282 const char *ret;
283
284 switch (val) {
285 case LTTNG_CALIBRATE_FUNCTION:
286 ret = mi_lttng_element_calibrate_function;
287 break;
288 default:
289 ret = mi_lttng_element_empty;
290 break;
291 }
292 return ret;
293}
294
c7e35b03
JR
295LTTNG_HIDDEN
296struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type)
297{
298 struct mi_writer *mi_writer;
299
300 mi_writer = zmalloc(sizeof(struct mi_writer));
301 if (!mi_writer) {
302 PERROR("zmalloc mi_writer_create");
303 goto end;
304 }
305 if (mi_output_type == LTTNG_MI_XML) {
306 mi_writer->writer = config_writer_create(fd_output);
307 if (!mi_writer->writer) {
308 goto err_destroy;
309 }
310 mi_writer->type = LTTNG_MI_XML;
311 } else {
312 goto err_destroy;
313 }
314
315end:
316 return mi_writer;
317
318err_destroy:
319 free(mi_writer);
320 return NULL;
321}
322
323LTTNG_HIDDEN
324int mi_lttng_writer_destroy(struct mi_writer *writer)
325{
326 int ret;
327
328 if (!writer) {
329 ret = -EINVAL;
330 goto end;
331 }
332
333 ret = config_writer_destroy(writer->writer);
334 if (ret < 0) {
335 goto end;
336 }
337
338 free(writer);
339end:
340 return ret;
341}
342
343LTTNG_HIDDEN
344int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command)
345{
346 int ret;
347
348 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command);
349 if (ret) {
350 goto end;
351 }
352 ret = mi_lttng_writer_write_element_string(writer,
353 mi_lttng_element_command_name, command);
354end:
355 return ret;
356}
357
358LTTNG_HIDDEN
359int mi_lttng_writer_command_close(struct mi_writer *writer)
360{
361 return mi_lttng_writer_close_element(writer);
362}
363
364LTTNG_HIDDEN
365int mi_lttng_writer_open_element(struct mi_writer *writer,
366 const char *element_name)
367{
368 return config_writer_open_element(writer->writer, element_name);
369}
370
371LTTNG_HIDDEN
372int mi_lttng_writer_close_element(struct mi_writer *writer)
373{
374 return config_writer_close_element(writer->writer);
375}
376
5e18ec73
JR
377LTTNG_HIDDEN
378int mi_lttng_close_multi_element(struct mi_writer *writer,
379 unsigned int nb_element)
380{
381 int ret, i;
382
383 if (nb_element < 1) {
384 ret = 0;
385 goto end;
386 }
387 for (i = 0; i < nb_element; i++) {
388 ret = mi_lttng_writer_close_element(writer);
389 if (ret) {
390 goto end;
391 }
392 }
393end:
394 return ret;
395}
396
c7e35b03
JR
397LTTNG_HIDDEN
398int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer,
399 const char *element_name, uint64_t value)
400{
401 return config_writer_write_element_unsigned_int(writer->writer,
402 element_name, value);
403}
404
405LTTNG_HIDDEN
406int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer,
407 const char *element_name, int64_t value)
408{
409 return config_writer_write_element_signed_int(writer->writer,
410 element_name, value);
411}
412
413LTTNG_HIDDEN
414int mi_lttng_writer_write_element_bool(struct mi_writer *writer,
415 const char *element_name, int value)
416{
417 return config_writer_write_element_bool(writer->writer,
418 element_name, value);
419}
420
421LTTNG_HIDDEN
422int mi_lttng_writer_write_element_string(struct mi_writer *writer,
423 const char *element_name, const char *value)
424{
425 return config_writer_write_element_string(writer->writer,
426 element_name, value);
427}
428
429LTTNG_HIDDEN
430int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version,
431 const char *lttng_description, const char *lttng_license)
432{
433 int ret;
434
435 /* Open version */
436 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_version);
437 if (ret) {
438 goto end;
439 }
440
441 /* Version string (contain info like rc etc.) */
442 ret = mi_lttng_writer_write_element_string(writer,
443 mi_lttng_element_version_str, VERSION);
444 if (ret) {
445 goto end;
446 }
447
448 /* Major version number */
449 ret = mi_lttng_writer_write_element_unsigned_int(writer,
450 mi_lttng_element_version_major, version->version_major);
451 if (ret) {
452 goto end;
453 }
454
455 /* Minor version number */
456 ret = mi_lttng_writer_write_element_unsigned_int(writer,
457 mi_lttng_element_version_minor, version->version_minor);
458 if (ret) {
459 goto end;
460 }
461
314d5222
JRJ
462 /* Commit version number */
463 ret = mi_lttng_writer_write_element_string(writer,
464 mi_lttng_element_version_commit, version->version_commit);
465 if (ret) {
466 goto end;
467 }
468
c7e35b03
JR
469 /* Patch number */
470 ret = mi_lttng_writer_write_element_unsigned_int(writer,
471 mi_lttng_element_version_patch_level, version->version_patchlevel);
472 if (ret) {
473 goto end;
474 }
475
476 /* Name of the version */
477 ret = mi_lttng_writer_write_element_string(writer,
478 config_element_name, version->version_name);
479 if (ret) {
480 goto end;
481 }
482
483 /* Description mostly related to beer... */
484 ret = mi_lttng_writer_write_element_string(writer,
485 mi_lttng_element_version_description, lttng_description);
486 if (ret) {
487 goto end;
488 }
489
490 /* url */
491 ret = mi_lttng_writer_write_element_string(writer,
492 mi_lttng_element_version_web, version->package_url);
493 if (ret) {
494 goto end;
495 }
496
497 /* License: free as in free beer...no...*speech* */
498 ret = mi_lttng_writer_write_element_string(writer,
499 mi_lttng_element_version_license, lttng_license);
500 if (ret) {
501 goto end;
502 }
503
504 /* Close version element */
505 ret = mi_lttng_writer_close_element(writer);
506
507end:
508 return ret;
509}
510
5e18ec73
JR
511LTTNG_HIDDEN
512int mi_lttng_sessions_open(struct mi_writer *writer)
513{
514 return mi_lttng_writer_open_element(writer, config_element_sessions);
515}
516
c7e35b03
JR
517LTTNG_HIDDEN
518int mi_lttng_session(struct mi_writer *writer,
519 struct lttng_session *session, int is_open)
520{
521 int ret;
522
5e18ec73
JR
523 assert(session);
524
525 /* Open sessions element */
c7e35b03
JR
526 ret = mi_lttng_writer_open_element(writer,
527 config_element_session);
528 if (ret) {
529 goto end;
530 }
531
532 /* Name of the session */
533 ret = mi_lttng_writer_write_element_string(writer,
534 config_element_name, session->name);
535 if (ret) {
536 goto end;
537 }
538
5e18ec73 539 /* Path */
c7e35b03
JR
540 ret = mi_lttng_writer_write_element_string(writer,
541 config_element_path, session->path);
542 if (ret) {
543 goto end;
544 }
545
5e18ec73
JR
546 /* Enabled ? */
547 ret = mi_lttng_writer_write_element_bool(writer,
c7e35b03
JR
548 config_element_enabled, session->enabled);
549 if (ret) {
550 goto end;
551 }
552
5e18ec73 553 /* Snapshot mode */
c7e35b03
JR
554 ret = mi_lttng_writer_write_element_unsigned_int(writer,
555 config_element_snapshot_mode, session->snapshot_mode);
556 if (ret) {
557 goto end;
558 }
559
5e18ec73 560 /* Live timer interval in usec */
c7e35b03
JR
561 ret = mi_lttng_writer_write_element_unsigned_int(writer,
562 config_element_live_timer_interval,
563 session->live_timer_interval);
564 if (ret) {
565 goto end;
566 }
567
568 if (!is_open) {
569 /* Closing session element */
570 ret = mi_lttng_writer_close_element(writer);
571 }
572end:
573 return ret;
574
575}
5e18ec73
JR
576
577LTTNG_HIDDEN
578int mi_lttng_domains_open(struct mi_writer *writer)
579{
580 return mi_lttng_writer_open_element(writer, config_element_domains);
581}
582
583LTTNG_HIDDEN
584int mi_lttng_domain(struct mi_writer *writer,
585 struct lttng_domain *domain, int is_open)
586{
587 int ret = 0;
588 const char *str_domain;
589 const char *str_buffer;
590
591 assert(domain);
592
593 /* Open domain element */
594 ret = mi_lttng_writer_open_element(writer, config_element_domain);
595 if (ret) {
596 goto end;
597 }
598
599 /* Domain Type */
600 str_domain = mi_lttng_domaintype_string(domain->type);
601 ret = mi_lttng_writer_write_element_string(writer, config_element_type,
602 str_domain);
603 if (ret) {
604 goto end;
605 }
606
607 /* Buffer Type */
608 str_buffer= mi_lttng_buffertype_string(domain->buf_type);
609 ret = mi_lttng_writer_write_element_string(writer,
610 config_element_buffer_type, str_buffer);
611 if (ret) {
612 goto end;
613 }
614
615 /* TODO: attr... not sure how to use the union.... */
616
617 if (!is_open) {
618 /* Closing domain element */
619 ret = mi_lttng_writer_close_element(writer);
620 }
621
622end:
623 return ret;
624
625}
626
627LTTNG_HIDDEN
628int mi_lttng_channels_open(struct mi_writer *writer)
629{
630 return mi_lttng_writer_open_element(writer, config_element_channels);
631}
632
633LTTNG_HIDDEN
634int mi_lttng_channel(struct mi_writer *writer,
635 struct lttng_channel *channel, int is_open)
636{
637 int ret = 0;
638
639 assert(channel);
640
641 /* Opening channel element */
642 ret = mi_lttng_writer_open_element(writer, config_element_channel);
643 if (ret) {
644 goto end;
645 }
646
647 /* Name */
648 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
649 channel->name);
650 if (ret) {
651 goto end;
652 }
653
654 /* Enabled ? */
655 ret = mi_lttng_writer_write_element_bool(writer,
656 config_element_enabled, channel->enabled);
657 if (ret) {
658 goto end;
659 }
660
661 /* Attribute */
662 ret = mi_lttng_channel_attr(writer, &channel->attr);
663 if (ret) {
664 goto end;
665 }
666
667 if (!is_open) {
668 /* Closing channel element */
669 ret = mi_lttng_writer_close_element(writer);
670 if (ret) {
671 goto end;
672 }
673 }
674end:
675 return ret;
676}
677
678LTTNG_HIDDEN
679int mi_lttng_channel_attr(struct mi_writer *writer,
680 struct lttng_channel_attr *attr)
681{
682 int ret = 0;
683
684 assert(attr);
685
686 /* Opening Attributes */
687 ret = mi_lttng_writer_open_element(writer, config_element_attributes);
688 if (ret) {
689 goto end;
690 }
691
692 /* Overwrite */
693 ret = mi_lttng_writer_write_element_string(writer,
694 config_element_overwrite_mode,
695 attr->overwrite ? config_overwrite_mode_overwrite :
696 config_overwrite_mode_discard);
697 if (ret) {
698 goto end;
699 }
700
701 /* Sub buffer size in byte */
702 ret = mi_lttng_writer_write_element_unsigned_int(writer,
703 config_element_subbuf_size, attr->subbuf_size);
704 if (ret) {
705 goto end;
706 }
707
708 /* Number of subbuffer (power of two) */
709 ret = mi_lttng_writer_write_element_unsigned_int(writer,
710 config_element_num_subbuf,
711 attr->num_subbuf);
712 if (ret) {
713 goto end;
714 }
715
716 /* Switch timer interval in usec */
717 ret = mi_lttng_writer_write_element_unsigned_int(writer,
718 config_element_switch_timer_interval,
719 attr->switch_timer_interval);
720 if (ret) {
721 goto end;
722 }
723
724 /* Read timer interval in usec */
725 ret = mi_lttng_writer_write_element_unsigned_int(writer,
726 config_element_read_timer_interval,
727 attr->read_timer_interval);
728 if (ret) {
729 goto end;
730 }
731
732 /* Event output */
733 ret = mi_lttng_writer_write_element_string(writer,
734 config_element_output_type,
735 attr->output == LTTNG_EVENT_SPLICE ?
736 config_output_type_splice : config_output_type_mmap);
737 if (ret) {
738 goto end;
739 }
740
741 /* Tracefile size in bytes */
742 ret = mi_lttng_writer_write_element_unsigned_int(writer,
743 config_element_tracefile_size, attr->tracefile_size);
744 if (ret) {
745 goto end;
746 }
747
748 /* Count of tracefiles */
749 ret = mi_lttng_writer_write_element_unsigned_int(writer,
750 config_element_tracefile_count,
751 attr->tracefile_count);
752 if (ret) {
753 goto end;
754 }
755
756 /* Live timer interval in usec*/
757 ret = mi_lttng_writer_write_element_unsigned_int(writer,
758 config_element_live_timer_interval,
759 attr->live_timer_interval);
760 if (ret) {
761 goto end;
762 }
763
764 /* Closing attributes */
765 ret = mi_lttng_writer_close_element(writer);
766 if (ret) {
767 goto end;
768 }
769end:
770 return ret;
771
772}
773
774LTTNG_HIDDEN
775int mi_lttng_event_common_attributes(struct mi_writer *writer,
776 struct lttng_event *event)
777{
778 int ret;
779
780 /* Open event element */
781 ret = mi_lttng_writer_open_element(writer, config_element_event);
782 if (ret) {
783 goto end;
784 }
785
786 /* event name */
787 ret = mi_lttng_writer_write_element_string(writer,
788 config_element_name, event->name);
789 if (ret) {
790 goto end;
791 }
792
793 /* event type */
794 ret = mi_lttng_writer_write_element_string(writer,
795 config_element_type, mi_lttng_eventtype_string(event->type));
796 if (ret) {
797 goto end;
798 }
799
800 /* is event enabled */
801 ret = mi_lttng_writer_write_element_bool(writer,
802 config_element_enabled, event->enabled);
803 if (ret) {
804 goto end;
805 }
806
807 /* event filter enabled? */
808 ret = mi_lttng_writer_write_element_bool(writer,
809 config_element_filter, event->filter);
810
811end:
812 return ret;
813}
814
815LTTNG_HIDDEN
816int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer,
817 struct lttng_event *event)
818{
819 int ret;
820
821 /* event loglevel */
822 ret = mi_lttng_writer_write_element_string(writer,
823 config_element_loglevel, mi_lttng_loglevel_string(event->loglevel));
824 if (ret) {
825 goto end;
826 }
827
828 ret = mi_lttng_writer_write_element_string(writer,
829 config_element_loglevel_type,
830 mi_lttng_logleveltype_string(event->loglevel_type));
831 if (ret) {
832 goto end;
833 }
834
835 /* event exclusion filter */
836 ret = mi_lttng_writer_write_element_bool(writer,
837 config_element_exclusion, event->exclusion);
838 if (ret) {
839 goto end;
840 }
841
842end:
843 return ret;
844}
845
846LTTNG_HIDDEN
847int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer *writer,
848 struct lttng_event *event)
849{
850 /* event exclusion filter */
851 return mi_lttng_writer_write_element_bool(writer,
852 config_element_exclusion, event->exclusion);
853}
854
855LTTNG_HIDDEN
856int mi_lttng_event_function_probe(struct mi_writer *writer,
857 struct lttng_event *event)
858{
859 int ret;
860
861 if (event->attr.probe.addr != 0) {
862 /* event probe address */
863 ret = mi_lttng_writer_write_element_unsigned_int(writer,
864 config_element_address, event->attr.probe.addr);
865 if (ret) {
866 goto end;
867 }
868 } else {
869 /* event probe offset */
870 ret = mi_lttng_writer_write_element_unsigned_int(writer,
871 config_element_offset, event->attr.probe.offset);
872 if (ret) {
873 goto end;
874 }
875
876 /* event probe symbol_name */
877 ret = mi_lttng_writer_write_element_string(writer,
878 config_element_symbol_name, event->attr.probe.symbol_name);
879 if (ret) {
880 goto end;
881 }
882 }
883end:
884 return ret;
885}
886
887LTTNG_HIDDEN
888int mi_lttng_event_function_entry(struct mi_writer *writer,
889 struct lttng_event *event)
890{
891 /* event probe symbol_name */
892 return mi_lttng_writer_write_element_string(writer,
893 config_element_symbol_name, event->attr.ftrace.symbol_name);
894}
895
896LTTNG_HIDDEN
897int mi_lttng_events_open(struct mi_writer *writer)
898{
899 return mi_lttng_writer_open_element(writer, config_element_events);
900}
901
902LTTNG_HIDDEN
903int mi_lttng_event(struct mi_writer *writer,
904 struct lttng_event *event, int is_open)
905{
906 int ret;
907
908 ret = mi_lttng_event_common_attributes(writer, event);
909 if (ret) {
910 goto end;
911 }
912
913 switch (event->type) {
5e18ec73
JR
914 case LTTNG_EVENT_TRACEPOINT:
915 {
916 if (event->loglevel != -1) {
917 ret = mi_lttng_event_tracepoint_loglevel(writer, event);
918 } else {
919 ret = mi_lttng_event_tracepoint_no_loglevel(writer, event);
920 }
921 break;
922 }
923 case LTTNG_EVENT_PROBE:
924 ret = mi_lttng_event_function_probe(writer, event);
925 break;
926 case LTTNG_EVENT_FUNCTION_ENTRY:
927 ret = mi_lttng_event_function_entry(writer, event);
928 break;
89476427
JRJ
929 case LTTNG_EVENT_ALL:
930 /* Fallthrough */
5e18ec73
JR
931 default:
932 break;
933 }
934
935 if (!is_open) {
936 ret = mi_lttng_writer_close_element(writer);
937 }
938
939end:
940 return ret;
941}
942
943LTTNG_HIDDEN
944int mi_lttng_pids_open(struct mi_writer *writer)
945{
946 return mi_lttng_writer_open_element(writer, mi_lttng_element_pids);
947}
948
949LTTNG_HIDDEN
950int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *cmdline,
951 int is_open)
952{
953 int ret;
954
955 /* Open element pid */
956 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_pid);
957 if (ret) {
958 goto end;
959 }
960
961 /* Writing pid number */
962 ret = mi_lttng_writer_write_element_signed_int(writer,
963 mi_lttng_element_pid_id, (int)pid);
964 if (ret) {
965 goto end;
966 }
967
968 /* Writing name of the process */
969 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
970 cmdline);
971 if (ret) {
972 goto end;
973 }
974
975 if (!is_open) {
976 /* Closing Pid */
977 ret = mi_lttng_writer_close_element(writer);
978 }
979
980end:
981 return ret;
982}
983
984LTTNG_HIDDEN
985int mi_lttng_event_fields_open(struct mi_writer *writer)
986{
987 return mi_lttng_writer_open_element(writer, mi_lttng_element_event_fields);
988}
989
990LTTNG_HIDDEN
991int mi_lttng_event_field(struct mi_writer *writer,
992 struct lttng_event_field *field)
993{
994 int ret;
995
996 if (!field->field_name[0]) {
997 /* To Review: not sure if legal david ?
998 * how should this be handle ?
999 */
1000 ret = 0;
1001 goto end;
1002 }
1003
1004 /* Open field */
1005 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_event_field);
1006 if (ret) {
1007 goto end;
1008 }
1009
1010 if (!field->field_name[0]) {
1011 goto close;
1012 }
1013
1014 /* Name */
1015 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
1016 field->field_name);
1017 if (ret) {
1018 goto end;
1019 }
1020
1021 /* Type */
1022 ret = mi_lttng_writer_write_element_string(writer, config_element_type,
1023 mi_lttng_eventfieldtype_string(field->type));
1024 if (ret) {
1025 goto end;
1026 }
1027
1028 /* nowrite */
1029 ret = mi_lttng_writer_write_element_signed_int(writer,
1030 mi_lttng_element_nowrite, field->nowrite);
1031 if (ret) {
1032 goto end;
1033 }
1034
1035close:
1036 /* Close field element */
1037 ret = mi_lttng_writer_close_element(writer);
1038
1039end:
1040 return ret;
1041}
7e66b1b0
JRJ
1042
1043LTTNG_HIDDEN
1044int mi_lttng_calibrate(struct mi_writer *writer,
1045 struct lttng_calibrate *calibrate)
1046{
1047 int ret;
1048
1049 /* Open calibrate element */
1050 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_calibrate);
1051 if (ret) {
1052 goto end;
1053 }
1054
1055 /* Calibration type */
1056 ret = mi_lttng_writer_write_element_string(writer, config_element_type,
1057 mi_lttng_calibratetype_string(calibrate->type));
1058 if (ret) {
1059 goto end;
1060 }
1061
1062 /* Closing calibrate element */
1063 ret = mi_lttng_writer_close_element(writer);
1064end:
1065 return ret;
1066}
89b72577
JRJ
1067LTTNG_HIDDEN
1068int mi_lttng_context(struct mi_writer *writer,
1069 struct lttng_event_context *context, int is_open)
1070{
1071 int ret;
1072 const char *type_string;
1073 struct lttng_event_perf_counter_ctx *perf_context;
1074 /* Open context */
1075 ret = mi_lttng_writer_open_element(writer , config_element_context);
1076 if (ret) {
1077 goto end;
1078 }
1079
1080 type_string = mi_lttng_event_contexttype_string(context->ctx);
1081 if (!type_string) {
1082 ret = -LTTNG_ERR_INVALID;
1083 goto end;
1084 }
1085
1086 /* Print context type */
1087 ret = mi_lttng_writer_write_element_string(writer, config_element_type,
1088 type_string);
1089
1090 /* Special case for PERF_*_COUNTER
1091 * print the lttng_event_perf_counter_ctx*/
1092 switch (context->ctx) {
1093 case LTTNG_EVENT_CONTEXT_PERF_COUNTER:
1094 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER:
1095 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER:
1096 perf_context = &context->u.perf_counter;
1097 ret = mi_lttng_perf_counter_context(writer, perf_context);
1098 if (ret) {
1099 goto end;
1100 }
1101 break;
1102 default:
1103 break;
1104 }
1105
1106 /* Close context */
1107 if (!is_open) {
1108 ret = mi_lttng_writer_close_element(writer);
1109 }
1110
1111end:
1112 return ret;
1113}
1114
1115LTTNG_HIDDEN
1116int mi_lttng_perf_counter_context(struct mi_writer *writer,
1117 struct lttng_event_perf_counter_ctx *perf_context)
1118{
1119 int ret;
1120
1121 /* Open perf_counter_context */
1122 ret = mi_lttng_writer_open_element(writer,
1123 mi_lttng_element_perf_counter_context);
1124 if (ret) {
1125 goto end;
1126 }
1127
1128 /* Type */
1129 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1130 config_element_type, perf_context->type);
1131 if (ret) {
1132 goto end;
1133 }
1134
1135 /* Config */
1136 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1137 config_element_config, perf_context->config);
1138 if (ret) {
1139 goto end;
1140 }
1141
1142 /* Name of the perf counter */
1143 ret = mi_lttng_writer_write_element_string(writer,
1144 config_element_name, perf_context->name);
1145 if (ret) {
1146 goto end;
1147 }
1148
1149 /* Close perf_counter_context */
1150 ret = mi_lttng_writer_close_element(writer);
1151end:
1152 return ret;
1153}
This page took 0.067486 seconds and 5 git commands to generate.