2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
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.
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
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.
20 #include <include/config.h>
21 #include <common/config/config.h>
22 #include <lttng/snapshot-internal.h>
27 /* Strings related to command */
28 const char * const mi_lttng_element_command
= "command";
29 const char * const mi_lttng_element_command_action
= "snapshot_action";
30 const char * const mi_lttng_element_command_add_context
= "add-context";
31 const char * const mi_lttng_element_command_calibrate
= "calibrate";
32 const char * const mi_lttng_element_command_create
= "create";
33 const char * const mi_lttng_element_command_destroy
= "destroy";
34 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
35 const char * const mi_lttng_element_command_disable_event
= "disable-event";
36 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
37 const char * const mi_lttng_element_command_enable_event
= "enable-event";
38 const char * const mi_lttng_element_command_list
= "list";
39 const char * const mi_lttng_element_command_load
= "load";
40 const char * const mi_lttng_element_command_name
= "name";
41 const char * const mi_lttng_element_command_output
= "output";
42 const char * const mi_lttng_element_command_save
= "save";
43 const char * const mi_lttng_element_command_set_session
= "set-session";
44 const char * const mi_lttng_element_command_snapshot
= "snapshot";
45 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
46 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
47 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
48 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
49 const char * const mi_lttng_element_command_start
= "start";
50 const char * const mi_lttng_element_command_stop
= "stop";
51 const char * const mi_lttng_element_command_success
= "success";
52 const char * const mi_lttng_element_command_version
= "version";
54 /* Strings related to version command */
55 const char * const mi_lttng_element_version
= "version";
56 const char * const mi_lttng_element_version_commit
= "commit";
57 const char * const mi_lttng_element_version_description
= "description";
58 const char * const mi_lttng_element_version_license
= "license";
59 const char * const mi_lttng_element_version_major
= "major";
60 const char * const mi_lttng_element_version_minor
= "minor";
61 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
62 const char * const mi_lttng_element_version_str
= "string";
63 const char * const mi_lttng_element_version_web
= "url";
65 /* String related to a lttng_event_field */
66 const char * const mi_lttng_element_event_field
= "event_field";
67 const char * const mi_lttng_element_event_fields
= "event_fields";
69 /* String related to lttng_event_context */
70 const char * const mi_lttng_context_type_perf_counter
= "PERF_COUNTER";
71 const char * const mi_lttng_context_type_perf_cpu_counter
= "PERF_CPU_COUNTER";
72 const char * const mi_lttng_context_type_perf_thread_counter
= "PERF_THREAD_COUNTER";
74 /* String related to lttng_event_perf_counter_ctx */
75 const char * const mi_lttng_element_perf_counter_context
= "perf_counter_context";
77 /* Strings related to pid */
78 const char * const mi_lttng_element_pids
= "pids";
79 const char * const mi_lttng_element_pid
= "pid";
80 const char * const mi_lttng_element_pid_id
= "id";
82 /* Strings related to save command */
83 const char * const mi_lttng_element_save
= "save";
85 /* Strings related to load command */
86 const char * const mi_lttng_element_load
= "load";
88 /* General elements of mi_lttng */
89 const char * const mi_lttng_element_empty
= "";
90 const char * const mi_lttng_element_id
= "id";
91 const char * const mi_lttng_element_nowrite
= "nowrite";
92 const char * const mi_lttng_element_success
= "success";
93 const char * const mi_lttng_element_type_enum
= "ENUM";
94 const char * const mi_lttng_element_type_float
= "FLOAT";
95 const char * const mi_lttng_element_type_integer
= "INTEGER";
96 const char * const mi_lttng_element_type_other
= "OTHER";
97 const char * const mi_lttng_element_type_string
= "STRING";
99 /* String related to loglevel */
100 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
101 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
102 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
103 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
104 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
105 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
106 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
107 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
108 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
109 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
110 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
111 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
112 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
113 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
114 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
115 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
117 /* String related to loglevel type */
118 const char * const mi_lttng_loglevel_type_all
= "ALL";
119 const char * const mi_lttng_loglevel_type_range
= "RANGE";
120 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
121 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
123 /* String related to lttng_calibrate */
124 const char * const mi_lttng_element_calibrate
= "calibrate";
125 const char * const mi_lttng_element_calibrate_function
= "FUNCTION";
127 /* String related to a lttng_snapshot_output */
128 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
129 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
130 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
131 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
132 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
133 const char * const mi_lttng_element_snapshots
= "snapshots";
135 const char *mi_lttng_loglevel_string(int value
)
139 return mi_lttng_element_empty
;
140 case LTTNG_LOGLEVEL_EMERG
:
141 return mi_lttng_loglevel_str_emerg
;
142 case LTTNG_LOGLEVEL_ALERT
:
143 return mi_lttng_loglevel_str_alert
;
144 case LTTNG_LOGLEVEL_CRIT
:
145 return mi_lttng_loglevel_str_crit
;
146 case LTTNG_LOGLEVEL_ERR
:
147 return mi_lttng_loglevel_str_err
;
148 case LTTNG_LOGLEVEL_WARNING
:
149 return mi_lttng_loglevel_str_warning
;
150 case LTTNG_LOGLEVEL_NOTICE
:
151 return mi_lttng_loglevel_str_notice
;
152 case LTTNG_LOGLEVEL_INFO
:
153 return mi_lttng_loglevel_str_info
;
154 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
155 return mi_lttng_loglevel_str_debug_system
;
156 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
157 return mi_lttng_loglevel_str_debug_program
;
158 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
159 return mi_lttng_loglevel_str_debug_process
;
160 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
161 return mi_lttng_loglevel_str_debug_module
;
162 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
163 return mi_lttng_loglevel_str_debug_unit
;
164 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
165 return mi_lttng_loglevel_str_debug_function
;
166 case LTTNG_LOGLEVEL_DEBUG_LINE
:
167 return mi_lttng_loglevel_str_debug_line
;
168 case LTTNG_LOGLEVEL_DEBUG
:
169 return mi_lttng_loglevel_str_debug
;
171 return mi_lttng_loglevel_str_unknown
;
175 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
178 case LTTNG_EVENT_LOGLEVEL_ALL
:
179 return mi_lttng_loglevel_type_all
;
180 case LTTNG_EVENT_LOGLEVEL_RANGE
:
181 return mi_lttng_loglevel_type_range
;
182 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
183 return mi_lttng_loglevel_type_single
;
185 return mi_lttng_loglevel_type_unknown
;
189 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
192 case LTTNG_EVENT_ALL
:
193 return config_event_type_all
;
194 case LTTNG_EVENT_TRACEPOINT
:
195 return config_event_type_tracepoint
;
196 case LTTNG_EVENT_PROBE
:
197 return config_event_type_probe
;
198 case LTTNG_EVENT_FUNCTION
:
199 return config_event_type_function
;
200 case LTTNG_EVENT_FUNCTION_ENTRY
:
201 return config_event_type_function_entry
;
202 case LTTNG_EVENT_SYSCALL
:
203 return config_event_type_syscall
;
204 case LTTNG_EVENT_NOOP
:
205 return config_event_type_noop
;
207 return mi_lttng_element_empty
;
211 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
214 case LTTNG_EVENT_CONTEXT_PID
:
215 return config_event_context_pid
;
216 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
217 return mi_lttng_context_type_perf_counter
;
218 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
219 return mi_lttng_context_type_perf_thread_counter
;
220 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
221 return mi_lttng_context_type_perf_cpu_counter
;
222 case LTTNG_EVENT_CONTEXT_PROCNAME
:
223 return config_event_context_procname
;
224 case LTTNG_EVENT_CONTEXT_PRIO
:
225 return config_event_context_prio
;
226 case LTTNG_EVENT_CONTEXT_NICE
:
227 return config_event_context_nice
;
228 case LTTNG_EVENT_CONTEXT_VPID
:
229 return config_event_context_vpid
;
230 case LTTNG_EVENT_CONTEXT_TID
:
231 return config_event_context_tid
;
232 case LTTNG_EVENT_CONTEXT_VTID
:
233 return config_event_context_vtid
;
234 case LTTNG_EVENT_CONTEXT_PPID
:
235 return config_event_context_ppid
;
236 case LTTNG_EVENT_CONTEXT_VPPID
:
237 return config_event_context_vppid
;
238 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
239 return config_event_context_pthread_id
;
240 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
241 return config_event_context_hostname
;
242 case LTTNG_EVENT_CONTEXT_IP
:
243 return config_event_context_ip
;
249 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
252 case(LTTNG_EVENT_FIELD_INTEGER
):
253 return mi_lttng_element_type_integer
;
254 case(LTTNG_EVENT_FIELD_ENUM
):
255 return mi_lttng_element_type_enum
;
256 case(LTTNG_EVENT_FIELD_FLOAT
):
257 return mi_lttng_element_type_float
;
258 case(LTTNG_EVENT_FIELD_STRING
):
259 return mi_lttng_element_type_string
;
261 return mi_lttng_element_type_other
;
265 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
267 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
269 case LTTNG_DOMAIN_KERNEL
:
270 return config_domain_type_kernel
;
271 case LTTNG_DOMAIN_UST
:
272 return config_domain_type_ust
;
273 case LTTNG_DOMAIN_JUL
:
274 return config_domain_type_jul
;
276 /* Should not have an unknown domain */
281 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
284 case LTTNG_BUFFER_PER_PID
:
285 return config_buffer_type_per_pid
;
286 case LTTNG_BUFFER_PER_UID
:
287 return config_buffer_type_per_uid
;
288 case LTTNG_BUFFER_GLOBAL
:
289 return config_buffer_type_global
;
291 /* Should not have an unknow buffer type */
296 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
)
301 case LTTNG_CALIBRATE_FUNCTION
:
302 ret
= mi_lttng_element_calibrate_function
;
305 ret
= mi_lttng_element_empty
;
312 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
314 struct mi_writer
*mi_writer
;
316 mi_writer
= zmalloc(sizeof(struct mi_writer
));
318 PERROR("zmalloc mi_writer_create");
321 if (mi_output_type
== LTTNG_MI_XML
) {
322 mi_writer
->writer
= config_writer_create(fd_output
);
323 if (!mi_writer
->writer
) {
326 mi_writer
->type
= LTTNG_MI_XML
;
340 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
349 ret
= config_writer_destroy(writer
->writer
);
360 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
364 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_command
);
368 ret
= mi_lttng_writer_write_element_string(writer
,
369 mi_lttng_element_command_name
, command
);
375 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
377 return mi_lttng_writer_close_element(writer
);
381 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
382 const char *element_name
)
384 return config_writer_open_element(writer
->writer
, element_name
);
388 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
390 return config_writer_close_element(writer
->writer
);
394 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
395 unsigned int nb_element
)
399 if (nb_element
< 1) {
403 for (i
= 0; i
< nb_element
; i
++) {
404 ret
= mi_lttng_writer_close_element(writer
);
414 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
415 const char *element_name
, uint64_t value
)
417 return config_writer_write_element_unsigned_int(writer
->writer
,
418 element_name
, value
);
422 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
423 const char *element_name
, int64_t value
)
425 return config_writer_write_element_signed_int(writer
->writer
,
426 element_name
, value
);
430 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
431 const char *element_name
, int value
)
433 return config_writer_write_element_bool(writer
->writer
,
434 element_name
, value
);
438 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
439 const char *element_name
, const char *value
)
441 return config_writer_write_element_string(writer
->writer
,
442 element_name
, value
);
446 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
447 const char *lttng_description
, const char *lttng_license
)
452 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
457 /* Version string (contain info like rc etc.) */
458 ret
= mi_lttng_writer_write_element_string(writer
,
459 mi_lttng_element_version_str
, VERSION
);
464 /* Major version number */
465 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
466 mi_lttng_element_version_major
, version
->version_major
);
471 /* Minor version number */
472 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
473 mi_lttng_element_version_minor
, version
->version_minor
);
478 /* Commit version number */
479 ret
= mi_lttng_writer_write_element_string(writer
,
480 mi_lttng_element_version_commit
, version
->version_commit
);
486 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
487 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
492 /* Name of the version */
493 ret
= mi_lttng_writer_write_element_string(writer
,
494 config_element_name
, version
->version_name
);
499 /* Description mostly related to beer... */
500 ret
= mi_lttng_writer_write_element_string(writer
,
501 mi_lttng_element_version_description
, lttng_description
);
507 ret
= mi_lttng_writer_write_element_string(writer
,
508 mi_lttng_element_version_web
, version
->package_url
);
513 /* License: free as in free beer...no...*speech* */
514 ret
= mi_lttng_writer_write_element_string(writer
,
515 mi_lttng_element_version_license
, lttng_license
);
520 /* Close version element */
521 ret
= mi_lttng_writer_close_element(writer
);
528 int mi_lttng_sessions_open(struct mi_writer
*writer
)
530 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
534 int mi_lttng_session(struct mi_writer
*writer
,
535 struct lttng_session
*session
, int is_open
)
541 /* Open sessions element */
542 ret
= mi_lttng_writer_open_element(writer
,
543 config_element_session
);
548 /* Name of the session */
549 ret
= mi_lttng_writer_write_element_string(writer
,
550 config_element_name
, session
->name
);
556 ret
= mi_lttng_writer_write_element_string(writer
,
557 config_element_path
, session
->path
);
563 ret
= mi_lttng_writer_write_element_bool(writer
,
564 config_element_enabled
, session
->enabled
);
570 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
571 config_element_snapshot_mode
, session
->snapshot_mode
);
576 /* Live timer interval in usec */
577 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
578 config_element_live_timer_interval
,
579 session
->live_timer_interval
);
585 /* Closing session element */
586 ret
= mi_lttng_writer_close_element(writer
);
594 int mi_lttng_domains_open(struct mi_writer
*writer
)
596 return mi_lttng_writer_open_element(writer
, config_element_domains
);
600 int mi_lttng_domain(struct mi_writer
*writer
,
601 struct lttng_domain
*domain
, int is_open
)
604 const char *str_domain
;
605 const char *str_buffer
;
609 /* Open domain element */
610 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
616 str_domain
= mi_lttng_domaintype_string(domain
->type
);
617 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
624 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
625 ret
= mi_lttng_writer_write_element_string(writer
,
626 config_element_buffer_type
, str_buffer
);
631 /* TODO: attr... not sure how to use the union.... */
634 /* Closing domain element */
635 ret
= mi_lttng_writer_close_element(writer
);
644 int mi_lttng_channels_open(struct mi_writer
*writer
)
646 return mi_lttng_writer_open_element(writer
, config_element_channels
);
650 int mi_lttng_channel(struct mi_writer
*writer
,
651 struct lttng_channel
*channel
, int is_open
)
657 /* Opening channel element */
658 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
664 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
671 ret
= mi_lttng_writer_write_element_bool(writer
,
672 config_element_enabled
, channel
->enabled
);
678 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
684 /* Closing channel element */
685 ret
= mi_lttng_writer_close_element(writer
);
695 int mi_lttng_channel_attr(struct mi_writer
*writer
,
696 struct lttng_channel_attr
*attr
)
702 /* Opening Attributes */
703 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
709 ret
= mi_lttng_writer_write_element_string(writer
,
710 config_element_overwrite_mode
,
711 attr
->overwrite
? config_overwrite_mode_overwrite
:
712 config_overwrite_mode_discard
);
717 /* Sub buffer size in byte */
718 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
719 config_element_subbuf_size
, attr
->subbuf_size
);
724 /* Number of subbuffer (power of two) */
725 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
726 config_element_num_subbuf
,
732 /* Switch timer interval in usec */
733 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
734 config_element_switch_timer_interval
,
735 attr
->switch_timer_interval
);
740 /* Read timer interval in usec */
741 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
742 config_element_read_timer_interval
,
743 attr
->read_timer_interval
);
749 ret
= mi_lttng_writer_write_element_string(writer
,
750 config_element_output_type
,
751 attr
->output
== LTTNG_EVENT_SPLICE
?
752 config_output_type_splice
: config_output_type_mmap
);
757 /* Tracefile size in bytes */
758 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
759 config_element_tracefile_size
, attr
->tracefile_size
);
764 /* Count of tracefiles */
765 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
766 config_element_tracefile_count
,
767 attr
->tracefile_count
);
772 /* Live timer interval in usec*/
773 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
774 config_element_live_timer_interval
,
775 attr
->live_timer_interval
);
780 /* Closing attributes */
781 ret
= mi_lttng_writer_close_element(writer
);
791 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
792 struct lttng_event
*event
)
796 /* Open event element */
797 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
803 ret
= mi_lttng_writer_write_element_string(writer
,
804 config_element_name
, event
->name
);
810 ret
= mi_lttng_writer_write_element_string(writer
,
811 config_element_type
, mi_lttng_eventtype_string(event
->type
));
816 /* Is event enabled */
817 ret
= mi_lttng_writer_write_element_bool(writer
,
818 config_element_enabled
, event
->enabled
);
823 /* Event filter enabled? */
824 ret
= mi_lttng_writer_write_element_bool(writer
,
825 config_element_filter
, event
->filter
);
832 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
833 struct lttng_event
*event
)
838 ret
= mi_lttng_writer_write_element_string(writer
,
839 config_element_loglevel
, mi_lttng_loglevel_string(event
->loglevel
));
845 ret
= mi_lttng_writer_write_element_string(writer
,
846 config_element_loglevel_type
,
847 mi_lttng_logleveltype_string(event
->loglevel_type
));
852 /* event exclusion filter */
853 ret
= mi_lttng_writer_write_element_bool(writer
,
854 config_element_exclusion
, event
->exclusion
);
864 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
865 struct lttng_event
*event
)
867 /* event exclusion filter */
868 return mi_lttng_writer_write_element_bool(writer
,
869 config_element_exclusion
, event
->exclusion
);
873 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
874 struct lttng_event
*event
)
878 if (event
->attr
.probe
.addr
!= 0) {
879 /* event probe address */
880 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
881 config_element_address
, event
->attr
.probe
.addr
);
886 /* event probe offset */
887 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
888 config_element_offset
, event
->attr
.probe
.offset
);
893 /* event probe symbol_name */
894 ret
= mi_lttng_writer_write_element_string(writer
,
895 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
905 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
906 struct lttng_event
*event
)
908 /* event probe symbol_name */
909 return mi_lttng_writer_write_element_string(writer
,
910 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
914 int mi_lttng_events_open(struct mi_writer
*writer
)
916 return mi_lttng_writer_open_element(writer
, config_element_events
);
920 int mi_lttng_event(struct mi_writer
*writer
,
921 struct lttng_event
*event
, int is_open
)
925 ret
= mi_lttng_event_common_attributes(writer
, event
);
930 switch (event
->type
) {
931 case LTTNG_EVENT_TRACEPOINT
:
933 if (event
->loglevel
!= -1) {
934 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
);
936 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
940 case LTTNG_EVENT_PROBE
:
941 ret
= mi_lttng_event_function_probe(writer
, event
);
943 case LTTNG_EVENT_FUNCTION_ENTRY
:
944 ret
= mi_lttng_event_function_entry(writer
, event
);
946 case LTTNG_EVENT_ALL
:
953 ret
= mi_lttng_writer_close_element(writer
);
961 int mi_lttng_pids_open(struct mi_writer
*writer
)
963 return mi_lttng_writer_open_element(writer
, mi_lttng_element_pids
);
967 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
972 /* Open element pid */
973 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_pid
);
978 /* Writing pid number */
979 ret
= mi_lttng_writer_write_element_signed_int(writer
,
980 mi_lttng_element_pid_id
, (int)pid
);
985 /* Writing name of the process */
986 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
994 ret
= mi_lttng_writer_close_element(writer
);
1002 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1004 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1008 int mi_lttng_event_field(struct mi_writer
*writer
,
1009 struct lttng_event_field
*field
)
1013 if (!field
->field_name
[0]) {
1019 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1024 if (!field
->field_name
[0]) {
1029 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1036 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1037 mi_lttng_eventfieldtype_string(field
->type
));
1043 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1044 mi_lttng_element_nowrite
, field
->nowrite
);
1050 /* Close field element */
1051 ret
= mi_lttng_writer_close_element(writer
);
1058 int mi_lttng_calibrate(struct mi_writer
*writer
,
1059 struct lttng_calibrate
*calibrate
)
1063 /* Open calibrate element */
1064 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1069 /* Calibration type */
1070 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1071 mi_lttng_calibratetype_string(calibrate
->type
));
1076 /* Closing calibrate element */
1077 ret
= mi_lttng_writer_close_element(writer
);
1082 int mi_lttng_context(struct mi_writer
*writer
,
1083 struct lttng_event_context
*context
, int is_open
)
1086 const char *type_string
;
1087 struct lttng_event_perf_counter_ctx
*perf_context
;
1089 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1094 type_string
= mi_lttng_event_contexttype_string(context
->ctx
);
1096 ret
= -LTTNG_ERR_INVALID
;
1100 /* Print context type */
1101 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1104 /* Special case for PERF_*_COUNTER
1105 * print the lttng_event_perf_counter_ctx*/
1106 switch (context
->ctx
) {
1107 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1108 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1109 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1110 perf_context
= &context
->u
.perf_counter
;
1111 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1122 ret
= mi_lttng_writer_close_element(writer
);
1130 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1131 struct lttng_event_perf_counter_ctx
*perf_context
)
1135 /* Open perf_counter_context */
1136 ret
= mi_lttng_writer_open_element(writer
,
1137 mi_lttng_element_perf_counter_context
);
1143 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1144 config_element_type
, perf_context
->type
);
1150 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1151 config_element_config
, perf_context
->config
);
1156 /* Name of the perf counter */
1157 ret
= mi_lttng_writer_write_element_string(writer
,
1158 config_element_name
, perf_context
->name
);
1163 /* Close perf_counter_context */
1164 ret
= mi_lttng_writer_close_element(writer
);
1170 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1171 const char *session_name
)
1175 /* Open session element */
1176 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1181 /* Snapshot output list for current session name */
1182 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1185 /* Open element snapshots (sequence one snapshot) */
1186 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1196 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1197 struct lttng_snapshot_output
*output
)
1201 /* Open element snapshot output */
1202 ret
= mi_lttng_writer_open_element(writer
,
1203 mi_lttng_element_command_snapshot
);
1208 /* ID of the snapshot output */
1209 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1210 mi_lttng_element_id
, output
->id
);
1215 /* Name of the output */
1216 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1222 /* Destination of the output (ctrl_url)*/
1223 ret
= mi_lttng_writer_write_element_string(writer
,
1224 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1229 /* Destination of the output (data_url) */
1230 ret
= mi_lttng_writer_write_element_string(writer
,
1231 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1236 /* total size of all stream combined */
1237 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1238 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1243 /* Close snapshot output element */
1244 ret
= mi_lttng_writer_close_element(writer
);
1251 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1252 const char *name
, const char *current_session_name
)
1256 /* Open element del_snapshot */
1257 ret
= mi_lttng_writer_open_element(writer
,
1258 mi_lttng_element_command_snapshot
);
1264 if (id
!= UINT32_MAX
) {
1265 /* "Snapshot output "id" successfully deleted
1266 * for "current_session_name"
1267 * ID of the snapshot output
1269 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1270 mi_lttng_element_id
, id
);
1275 /* "Snapshot output "name" successfully deleted
1276 * for session "current_session_name"
1277 * Name of the output
1279 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1286 /* Snapshot was deleted for session "current_session_name"*/
1287 ret
= mi_lttng_writer_write_element_string(writer
,
1288 mi_lttng_element_snapshot_session_name
,
1289 current_session_name
);
1294 /* Close snapshot element */
1295 ret
= mi_lttng_writer_close_element(writer
);
1302 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1303 const char *current_session_name
, const char *n_ptr
,
1304 struct lttng_snapshot_output
*output
)
1308 /* Open element snapshot */
1309 ret
= mi_lttng_writer_open_element(writer
,
1310 mi_lttng_element_command_snapshot
);
1315 /* Snapshot output id */
1316 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1317 mi_lttng_element_id
, output
->id
);
1322 /* Snapshot output names */
1323 ret
= mi_lttng_writer_write_element_string(writer
,
1324 config_element_name
, n_ptr
);
1329 /* Destination of the output (ctrl_url)*/
1330 ret
= mi_lttng_writer_write_element_string(writer
,
1331 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1336 /* Snapshot added for session "current_session_name"*/
1337 ret
= mi_lttng_writer_write_element_string(writer
,
1338 mi_lttng_element_snapshot_session_name
, current_session_name
);
1343 /* total size of all stream combined */
1344 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1345 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1350 /* Close snapshot element */
1351 ret
= mi_lttng_writer_close_element(writer
);
1358 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1359 const char *current_session_name
, const char *url
,
1360 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1364 /* Open element snapshot */
1365 ret
= mi_lttng_writer_open_element(writer
,
1366 mi_lttng_element_command_snapshot
);
1372 * If a valid an URL was given, serialize it,
1373 * else take the command line data and ctrl urls*/
1375 /* Destination of the output (ctrl_url)*/
1376 ret
= mi_lttng_writer_write_element_string(writer
,
1377 mi_lttng_element_snapshot_ctrl_url
, url
);
1381 } else if (cmdline_ctrl_url
) {
1382 /* Destination of the output (ctrl_url)*/
1383 ret
= mi_lttng_writer_write_element_string(writer
,
1384 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1389 /* Destination of the output (data_url) */
1390 ret
= mi_lttng_writer_write_element_string(writer
,
1391 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1397 /* Close record_snapshot element */
1398 ret
= mi_lttng_writer_close_element(writer
);