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 JUL */
118 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
119 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
120 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
121 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
122 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
123 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
124 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
125 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
126 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
128 /* String related to loglevel type */
129 const char * const mi_lttng_loglevel_type_all
= "ALL";
130 const char * const mi_lttng_loglevel_type_range
= "RANGE";
131 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
132 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
134 /* String related to lttng_calibrate */
135 const char * const mi_lttng_element_calibrate
= "calibrate";
136 const char * const mi_lttng_element_calibrate_function
= "FUNCTION";
138 /* String related to a lttng_snapshot_output */
139 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
140 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
141 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
142 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
143 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
144 const char * const mi_lttng_element_snapshots
= "snapshots";
146 /* This is a merge of jul loglevel and regular loglevel
147 * Those should never overlap by definition
148 * (see struct lttng_event loglevel)
150 const char *mi_lttng_loglevel_string(int value
)
154 return mi_lttng_element_empty
;
155 case LTTNG_LOGLEVEL_EMERG
:
156 return mi_lttng_loglevel_str_emerg
;
157 case LTTNG_LOGLEVEL_ALERT
:
158 return mi_lttng_loglevel_str_alert
;
159 case LTTNG_LOGLEVEL_CRIT
:
160 return mi_lttng_loglevel_str_crit
;
161 case LTTNG_LOGLEVEL_ERR
:
162 return mi_lttng_loglevel_str_err
;
163 case LTTNG_LOGLEVEL_WARNING
:
164 return mi_lttng_loglevel_str_warning
;
165 case LTTNG_LOGLEVEL_NOTICE
:
166 return mi_lttng_loglevel_str_notice
;
167 case LTTNG_LOGLEVEL_INFO
:
168 return mi_lttng_loglevel_str_info
;
169 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
170 return mi_lttng_loglevel_str_debug_system
;
171 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
172 return mi_lttng_loglevel_str_debug_program
;
173 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
174 return mi_lttng_loglevel_str_debug_process
;
175 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
176 return mi_lttng_loglevel_str_debug_module
;
177 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
178 return mi_lttng_loglevel_str_debug_unit
;
179 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
180 return mi_lttng_loglevel_str_debug_function
;
181 case LTTNG_LOGLEVEL_DEBUG_LINE
:
182 return mi_lttng_loglevel_str_debug_line
;
183 case LTTNG_LOGLEVEL_DEBUG
:
184 return mi_lttng_loglevel_str_debug
;
185 case LTTNG_LOGLEVEL_JUL_OFF
:
186 return mi_lttng_loglevel_str_jul_off
;
187 case LTTNG_LOGLEVEL_JUL_SEVERE
:
188 return mi_lttng_loglevel_str_jul_severe
;
189 case LTTNG_LOGLEVEL_JUL_WARNING
:
190 return mi_lttng_loglevel_str_jul_warning
;
191 case LTTNG_LOGLEVEL_JUL_INFO
:
192 return mi_lttng_loglevel_str_jul_info
;
193 case LTTNG_LOGLEVEL_JUL_CONFIG
:
194 return mi_lttng_loglevel_str_jul_config
;
195 case LTTNG_LOGLEVEL_JUL_FINE
:
196 return mi_lttng_loglevel_str_jul_fine
;
197 case LTTNG_LOGLEVEL_JUL_FINER
:
198 return mi_lttng_loglevel_str_jul_finer
;
199 case LTTNG_LOGLEVEL_JUL_FINEST
:
200 return mi_lttng_loglevel_str_jul_finest
;
201 case LTTNG_LOGLEVEL_JUL_ALL
:
202 return mi_lttng_loglevel_str_jul_all
;
204 return mi_lttng_loglevel_str_unknown
;
208 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
211 case LTTNG_EVENT_LOGLEVEL_ALL
:
212 return mi_lttng_loglevel_type_all
;
213 case LTTNG_EVENT_LOGLEVEL_RANGE
:
214 return mi_lttng_loglevel_type_range
;
215 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
216 return mi_lttng_loglevel_type_single
;
218 return mi_lttng_loglevel_type_unknown
;
222 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
225 case LTTNG_EVENT_ALL
:
226 return config_event_type_all
;
227 case LTTNG_EVENT_TRACEPOINT
:
228 return config_event_type_tracepoint
;
229 case LTTNG_EVENT_PROBE
:
230 return config_event_type_probe
;
231 case LTTNG_EVENT_FUNCTION
:
232 return config_event_type_function
;
233 case LTTNG_EVENT_FUNCTION_ENTRY
:
234 return config_event_type_function_entry
;
235 case LTTNG_EVENT_SYSCALL
:
236 return config_event_type_syscall
;
237 case LTTNG_EVENT_NOOP
:
238 return config_event_type_noop
;
240 return mi_lttng_element_empty
;
244 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
247 case LTTNG_EVENT_CONTEXT_PID
:
248 return config_event_context_pid
;
249 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
250 return mi_lttng_context_type_perf_counter
;
251 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
252 return mi_lttng_context_type_perf_thread_counter
;
253 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
254 return mi_lttng_context_type_perf_cpu_counter
;
255 case LTTNG_EVENT_CONTEXT_PROCNAME
:
256 return config_event_context_procname
;
257 case LTTNG_EVENT_CONTEXT_PRIO
:
258 return config_event_context_prio
;
259 case LTTNG_EVENT_CONTEXT_NICE
:
260 return config_event_context_nice
;
261 case LTTNG_EVENT_CONTEXT_VPID
:
262 return config_event_context_vpid
;
263 case LTTNG_EVENT_CONTEXT_TID
:
264 return config_event_context_tid
;
265 case LTTNG_EVENT_CONTEXT_VTID
:
266 return config_event_context_vtid
;
267 case LTTNG_EVENT_CONTEXT_PPID
:
268 return config_event_context_ppid
;
269 case LTTNG_EVENT_CONTEXT_VPPID
:
270 return config_event_context_vppid
;
271 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
272 return config_event_context_pthread_id
;
273 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
274 return config_event_context_hostname
;
275 case LTTNG_EVENT_CONTEXT_IP
:
276 return config_event_context_ip
;
282 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
285 case(LTTNG_EVENT_FIELD_INTEGER
):
286 return mi_lttng_element_type_integer
;
287 case(LTTNG_EVENT_FIELD_ENUM
):
288 return mi_lttng_element_type_enum
;
289 case(LTTNG_EVENT_FIELD_FLOAT
):
290 return mi_lttng_element_type_float
;
291 case(LTTNG_EVENT_FIELD_STRING
):
292 return mi_lttng_element_type_string
;
294 return mi_lttng_element_type_other
;
298 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
300 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
302 case LTTNG_DOMAIN_KERNEL
:
303 return config_domain_type_kernel
;
304 case LTTNG_DOMAIN_UST
:
305 return config_domain_type_ust
;
306 case LTTNG_DOMAIN_JUL
:
307 return config_domain_type_jul
;
308 case LTTNG_DOMAIN_LOG4J
:
309 return config_domain_type_log4j
;
311 /* Should not have an unknown domain */
316 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
319 case LTTNG_BUFFER_PER_PID
:
320 return config_buffer_type_per_pid
;
321 case LTTNG_BUFFER_PER_UID
:
322 return config_buffer_type_per_uid
;
323 case LTTNG_BUFFER_GLOBAL
:
324 return config_buffer_type_global
;
326 /* Should not have an unknow buffer type */
331 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
)
336 case LTTNG_CALIBRATE_FUNCTION
:
337 ret
= mi_lttng_element_calibrate_function
;
340 ret
= mi_lttng_element_empty
;
347 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
349 struct mi_writer
*mi_writer
;
351 mi_writer
= zmalloc(sizeof(struct mi_writer
));
353 PERROR("zmalloc mi_writer_create");
356 if (mi_output_type
== LTTNG_MI_XML
) {
357 mi_writer
->writer
= config_writer_create(fd_output
, 0);
358 if (!mi_writer
->writer
) {
361 mi_writer
->type
= LTTNG_MI_XML
;
375 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
384 ret
= config_writer_destroy(writer
->writer
);
395 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
399 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_command
);
403 ret
= mi_lttng_writer_write_element_string(writer
,
404 mi_lttng_element_command_name
, command
);
410 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
412 return mi_lttng_writer_close_element(writer
);
416 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
417 const char *element_name
)
419 return config_writer_open_element(writer
->writer
, element_name
);
423 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
425 return config_writer_close_element(writer
->writer
);
429 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
430 unsigned int nb_element
)
434 if (nb_element
< 1) {
438 for (i
= 0; i
< nb_element
; i
++) {
439 ret
= mi_lttng_writer_close_element(writer
);
449 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
450 const char *element_name
, uint64_t value
)
452 return config_writer_write_element_unsigned_int(writer
->writer
,
453 element_name
, value
);
457 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
458 const char *element_name
, int64_t value
)
460 return config_writer_write_element_signed_int(writer
->writer
,
461 element_name
, value
);
465 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
466 const char *element_name
, int value
)
468 return config_writer_write_element_bool(writer
->writer
,
469 element_name
, value
);
473 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
474 const char *element_name
, const char *value
)
476 return config_writer_write_element_string(writer
->writer
,
477 element_name
, value
);
481 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
482 const char *lttng_description
, const char *lttng_license
)
487 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
492 /* Version string (contain info like rc etc.) */
493 ret
= mi_lttng_writer_write_element_string(writer
,
494 mi_lttng_element_version_str
, version
->version
);
499 /* Major version number */
500 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
501 mi_lttng_element_version_major
, version
->version_major
);
506 /* Minor version number */
507 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
508 mi_lttng_element_version_minor
, version
->version_minor
);
513 /* Commit version number */
514 ret
= mi_lttng_writer_write_element_string(writer
,
515 mi_lttng_element_version_commit
, version
->version_commit
);
521 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
522 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
527 /* Name of the version */
528 ret
= mi_lttng_writer_write_element_string(writer
,
529 config_element_name
, version
->version_name
);
534 /* Description mostly related to beer... */
535 ret
= mi_lttng_writer_write_element_string(writer
,
536 mi_lttng_element_version_description
, lttng_description
);
542 ret
= mi_lttng_writer_write_element_string(writer
,
543 mi_lttng_element_version_web
, version
->package_url
);
548 /* License: free as in free beer...no...*speech* */
549 ret
= mi_lttng_writer_write_element_string(writer
,
550 mi_lttng_element_version_license
, lttng_license
);
555 /* Close version element */
556 ret
= mi_lttng_writer_close_element(writer
);
563 int mi_lttng_sessions_open(struct mi_writer
*writer
)
565 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
569 int mi_lttng_session(struct mi_writer
*writer
,
570 struct lttng_session
*session
, int is_open
)
576 /* Open sessions element */
577 ret
= mi_lttng_writer_open_element(writer
,
578 config_element_session
);
583 /* Name of the session */
584 ret
= mi_lttng_writer_write_element_string(writer
,
585 config_element_name
, session
->name
);
591 ret
= mi_lttng_writer_write_element_string(writer
,
592 config_element_path
, session
->path
);
598 ret
= mi_lttng_writer_write_element_bool(writer
,
599 config_element_enabled
, session
->enabled
);
605 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
606 config_element_snapshot_mode
, session
->snapshot_mode
);
611 /* Live timer interval in usec */
612 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
613 config_element_live_timer_interval
,
614 session
->live_timer_interval
);
620 /* Closing session element */
621 ret
= mi_lttng_writer_close_element(writer
);
629 int mi_lttng_domains_open(struct mi_writer
*writer
)
631 return mi_lttng_writer_open_element(writer
, config_element_domains
);
635 int mi_lttng_domain(struct mi_writer
*writer
,
636 struct lttng_domain
*domain
, int is_open
)
639 const char *str_domain
;
640 const char *str_buffer
;
644 /* Open domain element */
645 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
651 str_domain
= mi_lttng_domaintype_string(domain
->type
);
652 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
659 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
660 ret
= mi_lttng_writer_write_element_string(writer
,
661 config_element_buffer_type
, str_buffer
);
667 * This union is not currently used and was added for
668 * future ust domain support.
673 /* Closing domain element */
674 ret
= mi_lttng_writer_close_element(writer
);
683 int mi_lttng_channels_open(struct mi_writer
*writer
)
685 return mi_lttng_writer_open_element(writer
, config_element_channels
);
689 int mi_lttng_channel(struct mi_writer
*writer
,
690 struct lttng_channel
*channel
, int is_open
)
696 /* Opening channel element */
697 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
703 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
710 ret
= mi_lttng_writer_write_element_bool(writer
,
711 config_element_enabled
, channel
->enabled
);
717 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
723 /* Closing channel element */
724 ret
= mi_lttng_writer_close_element(writer
);
734 int mi_lttng_channel_attr(struct mi_writer
*writer
,
735 struct lttng_channel_attr
*attr
)
741 /* Opening Attributes */
742 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
748 ret
= mi_lttng_writer_write_element_string(writer
,
749 config_element_overwrite_mode
,
750 attr
->overwrite
? config_overwrite_mode_overwrite
:
751 config_overwrite_mode_discard
);
756 /* Sub buffer size in byte */
757 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
758 config_element_subbuf_size
, attr
->subbuf_size
);
763 /* Number of subbuffer (power of two) */
764 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
765 config_element_num_subbuf
,
771 /* Switch timer interval in usec */
772 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
773 config_element_switch_timer_interval
,
774 attr
->switch_timer_interval
);
779 /* Read timer interval in usec */
780 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
781 config_element_read_timer_interval
,
782 attr
->read_timer_interval
);
788 ret
= mi_lttng_writer_write_element_string(writer
,
789 config_element_output_type
,
790 attr
->output
== LTTNG_EVENT_SPLICE
?
791 config_output_type_splice
: config_output_type_mmap
);
796 /* Tracefile size in bytes */
797 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
798 config_element_tracefile_size
, attr
->tracefile_size
);
803 /* Count of tracefiles */
804 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
805 config_element_tracefile_count
,
806 attr
->tracefile_count
);
811 /* Live timer interval in usec*/
812 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
813 config_element_live_timer_interval
,
814 attr
->live_timer_interval
);
819 /* Closing attributes */
820 ret
= mi_lttng_writer_close_element(writer
);
830 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
831 struct lttng_event
*event
)
835 /* Open event element */
836 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
842 ret
= mi_lttng_writer_write_element_string(writer
,
843 config_element_name
, event
->name
);
849 ret
= mi_lttng_writer_write_element_string(writer
,
850 config_element_type
, mi_lttng_eventtype_string(event
->type
));
855 /* Is event enabled */
856 ret
= mi_lttng_writer_write_element_bool(writer
,
857 config_element_enabled
, event
->enabled
);
862 /* Event filter enabled? */
863 ret
= mi_lttng_writer_write_element_bool(writer
,
864 config_element_filter
, event
->filter
);
871 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
872 struct lttng_event
*event
)
877 ret
= mi_lttng_writer_write_element_string(writer
,
878 config_element_loglevel
, mi_lttng_loglevel_string(event
->loglevel
));
884 ret
= mi_lttng_writer_write_element_string(writer
,
885 config_element_loglevel_type
,
886 mi_lttng_logleveltype_string(event
->loglevel_type
));
891 /* event exclusion filter */
892 ret
= mi_lttng_writer_write_element_bool(writer
,
893 config_element_exclusion
, event
->exclusion
);
903 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
904 struct lttng_event
*event
)
906 /* event exclusion filter */
907 return mi_lttng_writer_write_element_bool(writer
,
908 config_element_exclusion
, event
->exclusion
);
912 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
913 struct lttng_event
*event
)
917 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
922 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
927 if (event
->attr
.probe
.addr
!= 0) {
928 /* event probe address */
929 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
930 config_element_address
, event
->attr
.probe
.addr
);
935 /* event probe offset */
936 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
937 config_element_offset
, event
->attr
.probe
.offset
);
942 /* event probe symbol_name */
943 ret
= mi_lttng_writer_write_element_string(writer
,
944 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
950 /* Close probe_attributes and attributes */
951 ret
= mi_lttng_close_multi_element(writer
, 2);
957 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
958 struct lttng_event
*event
)
962 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
967 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
972 /* event probe symbol_name */
973 ret
= mi_lttng_writer_write_element_string(writer
,
974 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
979 /* Close function_attributes and attributes */
980 ret
= mi_lttng_close_multi_element(writer
, 2);
986 int mi_lttng_events_open(struct mi_writer
*writer
)
988 return mi_lttng_writer_open_element(writer
, config_element_events
);
992 int mi_lttng_event(struct mi_writer
*writer
,
993 struct lttng_event
*event
, int is_open
)
997 ret
= mi_lttng_event_common_attributes(writer
, event
);
1002 switch (event
->type
) {
1003 case LTTNG_EVENT_TRACEPOINT
:
1005 if (event
->loglevel
!= -1) {
1006 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
);
1008 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1012 case LTTNG_EVENT_FUNCTION
:
1014 case LTTNG_EVENT_PROBE
:
1015 ret
= mi_lttng_event_function_probe(writer
, event
);
1017 case LTTNG_EVENT_FUNCTION_ENTRY
:
1018 ret
= mi_lttng_event_function_entry(writer
, event
);
1020 case LTTNG_EVENT_ALL
:
1027 ret
= mi_lttng_writer_close_element(writer
);
1035 int mi_lttng_pids_open(struct mi_writer
*writer
)
1037 return mi_lttng_writer_open_element(writer
, mi_lttng_element_pids
);
1041 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
1046 /* Open element pid */
1047 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_pid
);
1052 /* Writing pid number */
1053 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1054 mi_lttng_element_pid_id
, (int)pid
);
1059 /* Writing name of the process */
1060 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1068 ret
= mi_lttng_writer_close_element(writer
);
1076 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1078 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1082 int mi_lttng_event_field(struct mi_writer
*writer
,
1083 struct lttng_event_field
*field
)
1087 if (!field
->field_name
[0]) {
1093 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1098 if (!field
->field_name
[0]) {
1103 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1110 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1111 mi_lttng_eventfieldtype_string(field
->type
));
1117 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1118 mi_lttng_element_nowrite
, field
->nowrite
);
1124 /* Close field element */
1125 ret
= mi_lttng_writer_close_element(writer
);
1132 int mi_lttng_calibrate(struct mi_writer
*writer
,
1133 struct lttng_calibrate
*calibrate
)
1137 /* Open calibrate element */
1138 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1143 /* Calibration type */
1144 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1145 mi_lttng_calibratetype_string(calibrate
->type
));
1150 /* Closing calibrate element */
1151 ret
= mi_lttng_writer_close_element(writer
);
1156 int mi_lttng_context(struct mi_writer
*writer
,
1157 struct lttng_event_context
*context
, int is_open
)
1160 const char *type_string
;
1161 struct lttng_event_perf_counter_ctx
*perf_context
;
1163 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1168 type_string
= mi_lttng_event_contexttype_string(context
->ctx
);
1170 ret
= -LTTNG_ERR_INVALID
;
1174 /* Print context type */
1175 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1178 /* Special case for PERF_*_COUNTER
1179 * print the lttng_event_perf_counter_ctx*/
1180 switch (context
->ctx
) {
1181 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1182 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1183 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1184 perf_context
= &context
->u
.perf_counter
;
1185 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1196 ret
= mi_lttng_writer_close_element(writer
);
1204 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1205 struct lttng_event_perf_counter_ctx
*perf_context
)
1209 /* Open perf_counter_context */
1210 ret
= mi_lttng_writer_open_element(writer
,
1211 mi_lttng_element_perf_counter_context
);
1217 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1218 config_element_type
, perf_context
->type
);
1224 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1225 config_element_config
, perf_context
->config
);
1230 /* Name of the perf counter */
1231 ret
= mi_lttng_writer_write_element_string(writer
,
1232 config_element_name
, perf_context
->name
);
1237 /* Close perf_counter_context */
1238 ret
= mi_lttng_writer_close_element(writer
);
1244 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1245 const char *session_name
)
1249 /* Open session element */
1250 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1255 /* Snapshot output list for current session name */
1256 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1259 /* Open element snapshots (sequence one snapshot) */
1260 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1270 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1271 struct lttng_snapshot_output
*output
)
1275 /* Open element snapshot output */
1276 ret
= mi_lttng_writer_open_element(writer
,
1277 mi_lttng_element_command_snapshot
);
1282 /* ID of the snapshot output */
1283 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1284 mi_lttng_element_id
, output
->id
);
1289 /* Name of the output */
1290 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1296 /* Destination of the output (ctrl_url)*/
1297 ret
= mi_lttng_writer_write_element_string(writer
,
1298 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1303 /* Destination of the output (data_url) */
1304 ret
= mi_lttng_writer_write_element_string(writer
,
1305 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1310 /* total size of all stream combined */
1311 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1312 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1317 /* Close snapshot output element */
1318 ret
= mi_lttng_writer_close_element(writer
);
1325 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1326 const char *name
, const char *current_session_name
)
1330 /* Open element del_snapshot */
1331 ret
= mi_lttng_writer_open_element(writer
,
1332 mi_lttng_element_command_snapshot
);
1338 if (id
!= UINT32_MAX
) {
1339 /* "Snapshot output "id" successfully deleted
1340 * for "current_session_name"
1341 * ID of the snapshot output
1343 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1344 mi_lttng_element_id
, id
);
1349 /* "Snapshot output "name" successfully deleted
1350 * for session "current_session_name"
1351 * Name of the output
1353 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1360 /* Snapshot was deleted for session "current_session_name"*/
1361 ret
= mi_lttng_writer_write_element_string(writer
,
1362 mi_lttng_element_snapshot_session_name
,
1363 current_session_name
);
1368 /* Close snapshot element */
1369 ret
= mi_lttng_writer_close_element(writer
);
1376 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1377 const char *current_session_name
, const char *n_ptr
,
1378 struct lttng_snapshot_output
*output
)
1382 /* Open element snapshot */
1383 ret
= mi_lttng_writer_open_element(writer
,
1384 mi_lttng_element_command_snapshot
);
1389 /* Snapshot output id */
1390 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1391 mi_lttng_element_id
, output
->id
);
1396 /* Snapshot output names */
1397 ret
= mi_lttng_writer_write_element_string(writer
,
1398 config_element_name
, n_ptr
);
1403 /* Destination of the output (ctrl_url)*/
1404 ret
= mi_lttng_writer_write_element_string(writer
,
1405 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1410 /* Snapshot added for session "current_session_name"*/
1411 ret
= mi_lttng_writer_write_element_string(writer
,
1412 mi_lttng_element_snapshot_session_name
, current_session_name
);
1417 /* total size of all stream combined */
1418 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1419 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1424 /* Close snapshot element */
1425 ret
= mi_lttng_writer_close_element(writer
);
1432 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1433 const char *current_session_name
, const char *url
,
1434 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1438 /* Open element snapshot */
1439 ret
= mi_lttng_writer_open_element(writer
,
1440 mi_lttng_element_command_snapshot
);
1446 * If a valid an URL was given, serialize it,
1447 * else take the command line data and ctrl urls*/
1449 /* Destination of the output (ctrl_url)*/
1450 ret
= mi_lttng_writer_write_element_string(writer
,
1451 mi_lttng_element_snapshot_ctrl_url
, url
);
1455 } else if (cmdline_ctrl_url
) {
1456 /* Destination of the output (ctrl_url)*/
1457 ret
= mi_lttng_writer_write_element_string(writer
,
1458 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1463 /* Destination of the output (data_url) */
1464 ret
= mi_lttng_writer_write_element_string(writer
,
1465 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1471 /* Close record_snapshot element */
1472 ret
= mi_lttng_writer_close_element(writer
);