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 if (event
->attr
.probe
.addr
!= 0) {
918 /* event probe address */
919 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
920 config_element_address
, event
->attr
.probe
.addr
);
925 /* event probe offset */
926 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
927 config_element_offset
, event
->attr
.probe
.offset
);
932 /* event probe symbol_name */
933 ret
= mi_lttng_writer_write_element_string(writer
,
934 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
944 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
945 struct lttng_event
*event
)
947 /* event probe symbol_name */
948 return mi_lttng_writer_write_element_string(writer
,
949 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
953 int mi_lttng_events_open(struct mi_writer
*writer
)
955 return mi_lttng_writer_open_element(writer
, config_element_events
);
959 int mi_lttng_event(struct mi_writer
*writer
,
960 struct lttng_event
*event
, int is_open
)
964 ret
= mi_lttng_event_common_attributes(writer
, event
);
969 switch (event
->type
) {
970 case LTTNG_EVENT_TRACEPOINT
:
972 if (event
->loglevel
!= -1) {
973 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
);
975 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
979 case LTTNG_EVENT_PROBE
:
980 ret
= mi_lttng_event_function_probe(writer
, event
);
982 case LTTNG_EVENT_FUNCTION_ENTRY
:
983 ret
= mi_lttng_event_function_entry(writer
, event
);
985 case LTTNG_EVENT_ALL
:
992 ret
= mi_lttng_writer_close_element(writer
);
1000 int mi_lttng_pids_open(struct mi_writer
*writer
)
1002 return mi_lttng_writer_open_element(writer
, mi_lttng_element_pids
);
1006 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
1011 /* Open element pid */
1012 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_pid
);
1017 /* Writing pid number */
1018 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1019 mi_lttng_element_pid_id
, (int)pid
);
1024 /* Writing name of the process */
1025 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1033 ret
= mi_lttng_writer_close_element(writer
);
1041 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1043 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1047 int mi_lttng_event_field(struct mi_writer
*writer
,
1048 struct lttng_event_field
*field
)
1052 if (!field
->field_name
[0]) {
1058 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1063 if (!field
->field_name
[0]) {
1068 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1075 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1076 mi_lttng_eventfieldtype_string(field
->type
));
1082 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1083 mi_lttng_element_nowrite
, field
->nowrite
);
1089 /* Close field element */
1090 ret
= mi_lttng_writer_close_element(writer
);
1097 int mi_lttng_calibrate(struct mi_writer
*writer
,
1098 struct lttng_calibrate
*calibrate
)
1102 /* Open calibrate element */
1103 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1108 /* Calibration type */
1109 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1110 mi_lttng_calibratetype_string(calibrate
->type
));
1115 /* Closing calibrate element */
1116 ret
= mi_lttng_writer_close_element(writer
);
1121 int mi_lttng_context(struct mi_writer
*writer
,
1122 struct lttng_event_context
*context
, int is_open
)
1125 const char *type_string
;
1126 struct lttng_event_perf_counter_ctx
*perf_context
;
1128 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1133 type_string
= mi_lttng_event_contexttype_string(context
->ctx
);
1135 ret
= -LTTNG_ERR_INVALID
;
1139 /* Print context type */
1140 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1143 /* Special case for PERF_*_COUNTER
1144 * print the lttng_event_perf_counter_ctx*/
1145 switch (context
->ctx
) {
1146 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1147 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1148 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1149 perf_context
= &context
->u
.perf_counter
;
1150 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1161 ret
= mi_lttng_writer_close_element(writer
);
1169 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1170 struct lttng_event_perf_counter_ctx
*perf_context
)
1174 /* Open perf_counter_context */
1175 ret
= mi_lttng_writer_open_element(writer
,
1176 mi_lttng_element_perf_counter_context
);
1182 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1183 config_element_type
, perf_context
->type
);
1189 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1190 config_element_config
, perf_context
->config
);
1195 /* Name of the perf counter */
1196 ret
= mi_lttng_writer_write_element_string(writer
,
1197 config_element_name
, perf_context
->name
);
1202 /* Close perf_counter_context */
1203 ret
= mi_lttng_writer_close_element(writer
);
1209 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1210 const char *session_name
)
1214 /* Open session element */
1215 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1220 /* Snapshot output list for current session name */
1221 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1224 /* Open element snapshots (sequence one snapshot) */
1225 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1235 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1236 struct lttng_snapshot_output
*output
)
1240 /* Open element snapshot output */
1241 ret
= mi_lttng_writer_open_element(writer
,
1242 mi_lttng_element_command_snapshot
);
1247 /* ID of the snapshot output */
1248 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1249 mi_lttng_element_id
, output
->id
);
1254 /* Name of the output */
1255 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1261 /* Destination of the output (ctrl_url)*/
1262 ret
= mi_lttng_writer_write_element_string(writer
,
1263 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1268 /* Destination of the output (data_url) */
1269 ret
= mi_lttng_writer_write_element_string(writer
,
1270 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1275 /* total size of all stream combined */
1276 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1277 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1282 /* Close snapshot output element */
1283 ret
= mi_lttng_writer_close_element(writer
);
1290 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1291 const char *name
, const char *current_session_name
)
1295 /* Open element del_snapshot */
1296 ret
= mi_lttng_writer_open_element(writer
,
1297 mi_lttng_element_command_snapshot
);
1303 if (id
!= UINT32_MAX
) {
1304 /* "Snapshot output "id" successfully deleted
1305 * for "current_session_name"
1306 * ID of the snapshot output
1308 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1309 mi_lttng_element_id
, id
);
1314 /* "Snapshot output "name" successfully deleted
1315 * for session "current_session_name"
1316 * Name of the output
1318 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1325 /* Snapshot was deleted for session "current_session_name"*/
1326 ret
= mi_lttng_writer_write_element_string(writer
,
1327 mi_lttng_element_snapshot_session_name
,
1328 current_session_name
);
1333 /* Close snapshot element */
1334 ret
= mi_lttng_writer_close_element(writer
);
1341 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1342 const char *current_session_name
, const char *n_ptr
,
1343 struct lttng_snapshot_output
*output
)
1347 /* Open element snapshot */
1348 ret
= mi_lttng_writer_open_element(writer
,
1349 mi_lttng_element_command_snapshot
);
1354 /* Snapshot output id */
1355 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1356 mi_lttng_element_id
, output
->id
);
1361 /* Snapshot output names */
1362 ret
= mi_lttng_writer_write_element_string(writer
,
1363 config_element_name
, n_ptr
);
1368 /* Destination of the output (ctrl_url)*/
1369 ret
= mi_lttng_writer_write_element_string(writer
,
1370 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1375 /* Snapshot added for session "current_session_name"*/
1376 ret
= mi_lttng_writer_write_element_string(writer
,
1377 mi_lttng_element_snapshot_session_name
, current_session_name
);
1382 /* total size of all stream combined */
1383 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1384 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1389 /* Close snapshot element */
1390 ret
= mi_lttng_writer_close_element(writer
);
1397 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1398 const char *current_session_name
, const char *url
,
1399 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1403 /* Open element snapshot */
1404 ret
= mi_lttng_writer_open_element(writer
,
1405 mi_lttng_element_command_snapshot
);
1411 * If a valid an URL was given, serialize it,
1412 * else take the command line data and ctrl urls*/
1414 /* Destination of the output (ctrl_url)*/
1415 ret
= mi_lttng_writer_write_element_string(writer
,
1416 mi_lttng_element_snapshot_ctrl_url
, url
);
1420 } else if (cmdline_ctrl_url
) {
1421 /* Destination of the output (ctrl_url)*/
1422 ret
= mi_lttng_writer_write_element_string(writer
,
1423 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1428 /* Destination of the output (data_url) */
1429 ret
= mi_lttng_writer_write_element_string(writer
,
1430 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1436 /* Close record_snapshot element */
1437 ret
= mi_lttng_writer_close_element(writer
);