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.
21 #include <include/config.h>
22 #include <common/config/config.h>
23 #include <lttng/snapshot-internal.h>
28 /* Strings related to command */
29 const char * const mi_lttng_element_command
= "command";
30 const char * const mi_lttng_element_command_action
= "snapshot_action";
31 const char * const mi_lttng_element_command_add_context
= "add-context";
32 const char * const mi_lttng_element_command_calibrate
= "calibrate";
33 const char * const mi_lttng_element_command_create
= "create";
34 const char * const mi_lttng_element_command_destroy
= "destroy";
35 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
36 const char * const mi_lttng_element_command_disable_event
= "disable-event";
37 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
38 const char * const mi_lttng_element_command_enable_event
= "enable-event";
39 const char * const mi_lttng_element_command_list
= "list";
40 const char * const mi_lttng_element_command_load
= "load";
41 const char * const mi_lttng_element_command_name
= "name";
42 const char * const mi_lttng_element_command_output
= "output";
43 const char * const mi_lttng_element_command_save
= "save";
44 const char * const mi_lttng_element_command_set_session
= "set-session";
45 const char * const mi_lttng_element_command_snapshot
= "snapshot";
46 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
47 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
48 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
49 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
50 const char * const mi_lttng_element_command_start
= "start";
51 const char * const mi_lttng_element_command_stop
= "stop";
52 const char * const mi_lttng_element_command_success
= "success";
53 const char * const mi_lttng_element_command_version
= "version";
55 /* Strings related to version command */
56 const char * const mi_lttng_element_version
= "version";
57 const char * const mi_lttng_element_version_commit
= "commit";
58 const char * const mi_lttng_element_version_description
= "description";
59 const char * const mi_lttng_element_version_license
= "license";
60 const char * const mi_lttng_element_version_major
= "major";
61 const char * const mi_lttng_element_version_minor
= "minor";
62 const char * const mi_lttng_element_version_patch_level
= "patchLevel";
63 const char * const mi_lttng_element_version_str
= "string";
64 const char * const mi_lttng_element_version_web
= "url";
66 /* String related to a lttng_event_field */
67 const char * const mi_lttng_element_event_field
= "event_field";
68 const char * const mi_lttng_element_event_fields
= "event_fields";
70 /* String related to lttng_event_context */
71 const char * const mi_lttng_context_type_perf_counter
= "PERF_COUNTER";
72 const char * const mi_lttng_context_type_perf_cpu_counter
= "PERF_CPU_COUNTER";
73 const char * const mi_lttng_context_type_perf_thread_counter
= "PERF_THREAD_COUNTER";
75 /* String related to lttng_event_perf_counter_ctx */
76 const char * const mi_lttng_element_perf_counter_context
= "perf_counter_context";
78 /* Strings related to pid */
79 const char * const mi_lttng_element_pids
= "pids";
80 const char * const mi_lttng_element_pid
= "pid";
81 const char * const mi_lttng_element_pid_id
= "id";
83 /* Strings related to save command */
84 const char * const mi_lttng_element_save
= "save";
86 /* Strings related to load command */
87 const char * const mi_lttng_element_load
= "load";
89 /* General elements of mi_lttng */
90 const char * const mi_lttng_element_empty
= "";
91 const char * const mi_lttng_element_id
= "id";
92 const char * const mi_lttng_element_nowrite
= "nowrite";
93 const char * const mi_lttng_element_success
= "success";
94 const char * const mi_lttng_element_type_enum
= "ENUM";
95 const char * const mi_lttng_element_type_float
= "FLOAT";
96 const char * const mi_lttng_element_type_integer
= "INTEGER";
97 const char * const mi_lttng_element_type_other
= "OTHER";
98 const char * const mi_lttng_element_type_string
= "STRING";
100 /* String related to loglevel */
101 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
102 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
103 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
104 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
105 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
106 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
107 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
108 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
109 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
110 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
111 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
112 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
113 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
114 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
115 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
116 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
118 /* String related to loglevel JUL */
119 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
120 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
121 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
122 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
123 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
124 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
125 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
126 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
127 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
129 /* String related to loglevel LOG4J */
130 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
131 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
132 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
133 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
134 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
135 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
136 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
137 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
139 /* String related to loglevel Python */
140 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
141 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
142 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
143 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
144 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
145 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
147 /* String related to loglevel type */
148 const char * const mi_lttng_loglevel_type_all
= "ALL";
149 const char * const mi_lttng_loglevel_type_range
= "RANGE";
150 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
151 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
153 /* String related to lttng_calibrate */
154 const char * const mi_lttng_element_calibrate
= "calibrate";
155 const char * const mi_lttng_element_calibrate_function
= "FUNCTION";
157 /* String related to a lttng_snapshot_output */
158 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
159 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
160 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
161 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
162 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
163 const char * const mi_lttng_element_snapshots
= "snapshots";
165 /* This is a merge of jul loglevel and regular loglevel
166 * Those should never overlap by definition
167 * (see struct lttng_event loglevel)
170 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
173 case LTTNG_DOMAIN_KERNEL
:
174 case LTTNG_DOMAIN_UST
:
177 return mi_lttng_element_empty
;
178 case LTTNG_LOGLEVEL_EMERG
:
179 return mi_lttng_loglevel_str_emerg
;
180 case LTTNG_LOGLEVEL_ALERT
:
181 return mi_lttng_loglevel_str_alert
;
182 case LTTNG_LOGLEVEL_CRIT
:
183 return mi_lttng_loglevel_str_crit
;
184 case LTTNG_LOGLEVEL_ERR
:
185 return mi_lttng_loglevel_str_err
;
186 case LTTNG_LOGLEVEL_WARNING
:
187 return mi_lttng_loglevel_str_warning
;
188 case LTTNG_LOGLEVEL_NOTICE
:
189 return mi_lttng_loglevel_str_notice
;
190 case LTTNG_LOGLEVEL_INFO
:
191 return mi_lttng_loglevel_str_info
;
192 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
193 return mi_lttng_loglevel_str_debug_system
;
194 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
195 return mi_lttng_loglevel_str_debug_program
;
196 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
197 return mi_lttng_loglevel_str_debug_process
;
198 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
199 return mi_lttng_loglevel_str_debug_module
;
200 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
201 return mi_lttng_loglevel_str_debug_unit
;
202 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
203 return mi_lttng_loglevel_str_debug_function
;
204 case LTTNG_LOGLEVEL_DEBUG_LINE
:
205 return mi_lttng_loglevel_str_debug_line
;
206 case LTTNG_LOGLEVEL_DEBUG
:
207 return mi_lttng_loglevel_str_debug
;
209 return mi_lttng_loglevel_str_unknown
;
212 case LTTNG_DOMAIN_LOG4J
:
215 return mi_lttng_element_empty
;
216 case LTTNG_LOGLEVEL_LOG4J_OFF
:
217 return mi_lttng_loglevel_str_log4j_off
;
218 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
219 return mi_lttng_loglevel_str_log4j_fatal
;
220 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
221 return mi_lttng_loglevel_str_log4j_error
;
222 case LTTNG_LOGLEVEL_LOG4J_WARN
:
223 return mi_lttng_loglevel_str_log4j_warn
;
224 case LTTNG_LOGLEVEL_LOG4J_INFO
:
225 return mi_lttng_loglevel_str_log4j_info
;
226 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
227 return mi_lttng_loglevel_str_log4j_debug
;
228 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
229 return mi_lttng_loglevel_str_log4j_trace
;
230 case LTTNG_LOGLEVEL_LOG4J_ALL
:
231 return mi_lttng_loglevel_str_log4j_all
;
233 return mi_lttng_loglevel_str_unknown
;
236 case LTTNG_DOMAIN_JUL
:
239 return mi_lttng_element_empty
;
240 case LTTNG_LOGLEVEL_JUL_OFF
:
241 return mi_lttng_loglevel_str_jul_off
;
242 case LTTNG_LOGLEVEL_JUL_SEVERE
:
243 return mi_lttng_loglevel_str_jul_severe
;
244 case LTTNG_LOGLEVEL_JUL_WARNING
:
245 return mi_lttng_loglevel_str_jul_warning
;
246 case LTTNG_LOGLEVEL_JUL_INFO
:
247 return mi_lttng_loglevel_str_jul_info
;
248 case LTTNG_LOGLEVEL_JUL_CONFIG
:
249 return mi_lttng_loglevel_str_jul_config
;
250 case LTTNG_LOGLEVEL_JUL_FINE
:
251 return mi_lttng_loglevel_str_jul_fine
;
252 case LTTNG_LOGLEVEL_JUL_FINER
:
253 return mi_lttng_loglevel_str_jul_finer
;
254 case LTTNG_LOGLEVEL_JUL_FINEST
:
255 return mi_lttng_loglevel_str_jul_finest
;
256 case LTTNG_LOGLEVEL_JUL_ALL
:
257 return mi_lttng_loglevel_str_jul_all
;
259 return mi_lttng_loglevel_str_unknown
;
262 case LTTNG_DOMAIN_PYTHON
:
264 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
265 return mi_lttng_loglevel_str_python_critical
;
266 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
267 return mi_lttng_loglevel_str_python_error
;
268 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
269 return mi_lttng_loglevel_str_python_warning
;
270 case LTTNG_LOGLEVEL_PYTHON_INFO
:
271 return mi_lttng_loglevel_str_python_info
;
272 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
273 return mi_lttng_loglevel_str_python_debug
;
274 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
275 return mi_lttng_loglevel_str_python_notset
;
277 return mi_lttng_loglevel_str_unknown
;
282 /* Reaching this means the domain is unknown. */
283 return mi_lttng_loglevel_str_unknown
;
287 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
290 case LTTNG_EVENT_LOGLEVEL_ALL
:
291 return mi_lttng_loglevel_type_all
;
292 case LTTNG_EVENT_LOGLEVEL_RANGE
:
293 return mi_lttng_loglevel_type_range
;
294 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
295 return mi_lttng_loglevel_type_single
;
297 return mi_lttng_loglevel_type_unknown
;
302 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
305 case LTTNG_EVENT_ALL
:
306 return config_event_type_all
;
307 case LTTNG_EVENT_TRACEPOINT
:
308 return config_event_type_tracepoint
;
309 case LTTNG_EVENT_PROBE
:
310 return config_event_type_probe
;
311 case LTTNG_EVENT_FUNCTION
:
312 return config_event_type_function
;
313 case LTTNG_EVENT_FUNCTION_ENTRY
:
314 return config_event_type_function_entry
;
315 case LTTNG_EVENT_SYSCALL
:
316 return config_event_type_syscall
;
317 case LTTNG_EVENT_NOOP
:
318 return config_event_type_noop
;
320 return mi_lttng_element_empty
;
325 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
328 case LTTNG_EVENT_CONTEXT_PID
:
329 return config_event_context_pid
;
330 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
331 return mi_lttng_context_type_perf_counter
;
332 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
333 return mi_lttng_context_type_perf_thread_counter
;
334 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
335 return mi_lttng_context_type_perf_cpu_counter
;
336 case LTTNG_EVENT_CONTEXT_PROCNAME
:
337 return config_event_context_procname
;
338 case LTTNG_EVENT_CONTEXT_PRIO
:
339 return config_event_context_prio
;
340 case LTTNG_EVENT_CONTEXT_NICE
:
341 return config_event_context_nice
;
342 case LTTNG_EVENT_CONTEXT_VPID
:
343 return config_event_context_vpid
;
344 case LTTNG_EVENT_CONTEXT_TID
:
345 return config_event_context_tid
;
346 case LTTNG_EVENT_CONTEXT_VTID
:
347 return config_event_context_vtid
;
348 case LTTNG_EVENT_CONTEXT_PPID
:
349 return config_event_context_ppid
;
350 case LTTNG_EVENT_CONTEXT_VPPID
:
351 return config_event_context_vppid
;
352 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
353 return config_event_context_pthread_id
;
354 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
355 return config_event_context_hostname
;
356 case LTTNG_EVENT_CONTEXT_IP
:
357 return config_event_context_ip
;
364 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
367 case(LTTNG_EVENT_FIELD_INTEGER
):
368 return mi_lttng_element_type_integer
;
369 case(LTTNG_EVENT_FIELD_ENUM
):
370 return mi_lttng_element_type_enum
;
371 case(LTTNG_EVENT_FIELD_FLOAT
):
372 return mi_lttng_element_type_float
;
373 case(LTTNG_EVENT_FIELD_STRING
):
374 return mi_lttng_element_type_string
;
376 return mi_lttng_element_type_other
;
381 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
383 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
385 case LTTNG_DOMAIN_KERNEL
:
386 return config_domain_type_kernel
;
387 case LTTNG_DOMAIN_UST
:
388 return config_domain_type_ust
;
389 case LTTNG_DOMAIN_JUL
:
390 return config_domain_type_jul
;
391 case LTTNG_DOMAIN_LOG4J
:
392 return config_domain_type_log4j
;
394 /* Should not have an unknown domain */
400 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
403 case LTTNG_BUFFER_PER_PID
:
404 return config_buffer_type_per_pid
;
405 case LTTNG_BUFFER_PER_UID
:
406 return config_buffer_type_per_uid
;
407 case LTTNG_BUFFER_GLOBAL
:
408 return config_buffer_type_global
;
410 /* Should not have an unknow buffer type */
416 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
)
421 case LTTNG_CALIBRATE_FUNCTION
:
422 ret
= mi_lttng_element_calibrate_function
;
425 ret
= mi_lttng_element_empty
;
432 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
434 struct mi_writer
*mi_writer
;
436 mi_writer
= zmalloc(sizeof(struct mi_writer
));
438 PERROR("zmalloc mi_writer_create");
441 if (mi_output_type
== LTTNG_MI_XML
) {
442 mi_writer
->writer
= config_writer_create(fd_output
, 0);
443 if (!mi_writer
->writer
) {
446 mi_writer
->type
= LTTNG_MI_XML
;
460 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
469 ret
= config_writer_destroy(writer
->writer
);
480 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
484 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_command
);
488 ret
= mi_lttng_writer_write_element_string(writer
,
489 mi_lttng_element_command_name
, command
);
495 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
497 return mi_lttng_writer_close_element(writer
);
501 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
502 const char *element_name
)
504 return config_writer_open_element(writer
->writer
, element_name
);
508 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
510 return config_writer_close_element(writer
->writer
);
514 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
515 unsigned int nb_element
)
519 if (nb_element
< 1) {
523 for (i
= 0; i
< nb_element
; i
++) {
524 ret
= mi_lttng_writer_close_element(writer
);
534 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
535 const char *element_name
, uint64_t value
)
537 return config_writer_write_element_unsigned_int(writer
->writer
,
538 element_name
, value
);
542 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
543 const char *element_name
, int64_t value
)
545 return config_writer_write_element_signed_int(writer
->writer
,
546 element_name
, value
);
550 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
551 const char *element_name
, int value
)
553 return config_writer_write_element_bool(writer
->writer
,
554 element_name
, value
);
558 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
559 const char *element_name
, const char *value
)
561 return config_writer_write_element_string(writer
->writer
,
562 element_name
, value
);
566 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
567 const char *lttng_description
, const char *lttng_license
)
572 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
577 /* Version string (contain info like rc etc.) */
578 ret
= mi_lttng_writer_write_element_string(writer
,
579 mi_lttng_element_version_str
, version
->version
);
584 /* Major version number */
585 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
586 mi_lttng_element_version_major
, version
->version_major
);
591 /* Minor version number */
592 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
593 mi_lttng_element_version_minor
, version
->version_minor
);
598 /* Commit version number */
599 ret
= mi_lttng_writer_write_element_string(writer
,
600 mi_lttng_element_version_commit
, version
->version_commit
);
606 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
607 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
612 /* Name of the version */
613 ret
= mi_lttng_writer_write_element_string(writer
,
614 config_element_name
, version
->version_name
);
619 /* Description mostly related to beer... */
620 ret
= mi_lttng_writer_write_element_string(writer
,
621 mi_lttng_element_version_description
, lttng_description
);
627 ret
= mi_lttng_writer_write_element_string(writer
,
628 mi_lttng_element_version_web
, version
->package_url
);
633 /* License: free as in free beer...no...*speech* */
634 ret
= mi_lttng_writer_write_element_string(writer
,
635 mi_lttng_element_version_license
, lttng_license
);
640 /* Close version element */
641 ret
= mi_lttng_writer_close_element(writer
);
648 int mi_lttng_sessions_open(struct mi_writer
*writer
)
650 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
654 int mi_lttng_session(struct mi_writer
*writer
,
655 struct lttng_session
*session
, int is_open
)
661 /* Open sessions element */
662 ret
= mi_lttng_writer_open_element(writer
,
663 config_element_session
);
668 /* Name of the session */
669 ret
= mi_lttng_writer_write_element_string(writer
,
670 config_element_name
, session
->name
);
676 ret
= mi_lttng_writer_write_element_string(writer
,
677 config_element_path
, session
->path
);
683 ret
= mi_lttng_writer_write_element_bool(writer
,
684 config_element_enabled
, session
->enabled
);
690 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
691 config_element_snapshot_mode
, session
->snapshot_mode
);
696 /* Live timer interval in usec */
697 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
698 config_element_live_timer_interval
,
699 session
->live_timer_interval
);
705 /* Closing session element */
706 ret
= mi_lttng_writer_close_element(writer
);
714 int mi_lttng_domains_open(struct mi_writer
*writer
)
716 return mi_lttng_writer_open_element(writer
, config_element_domains
);
720 int mi_lttng_domain(struct mi_writer
*writer
,
721 struct lttng_domain
*domain
, int is_open
)
724 const char *str_domain
;
725 const char *str_buffer
;
729 /* Open domain element */
730 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
736 str_domain
= mi_lttng_domaintype_string(domain
->type
);
737 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
744 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
745 ret
= mi_lttng_writer_write_element_string(writer
,
746 config_element_buffer_type
, str_buffer
);
752 * This union is not currently used and was added for
753 * future ust domain support.
758 /* Closing domain element */
759 ret
= mi_lttng_writer_close_element(writer
);
768 int mi_lttng_channels_open(struct mi_writer
*writer
)
770 return mi_lttng_writer_open_element(writer
, config_element_channels
);
774 int mi_lttng_channel(struct mi_writer
*writer
,
775 struct lttng_channel
*channel
, int is_open
)
781 /* Opening channel element */
782 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
788 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
795 ret
= mi_lttng_writer_write_element_bool(writer
,
796 config_element_enabled
, channel
->enabled
);
802 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
808 /* Closing channel element */
809 ret
= mi_lttng_writer_close_element(writer
);
819 int mi_lttng_channel_attr(struct mi_writer
*writer
,
820 struct lttng_channel_attr
*attr
)
826 /* Opening Attributes */
827 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
833 ret
= mi_lttng_writer_write_element_string(writer
,
834 config_element_overwrite_mode
,
835 attr
->overwrite
? config_overwrite_mode_overwrite
:
836 config_overwrite_mode_discard
);
841 /* Sub buffer size in byte */
842 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
843 config_element_subbuf_size
, attr
->subbuf_size
);
848 /* Number of subbuffer (power of two) */
849 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
850 config_element_num_subbuf
,
856 /* Switch timer interval in usec */
857 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
858 config_element_switch_timer_interval
,
859 attr
->switch_timer_interval
);
864 /* Read timer interval in usec */
865 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
866 config_element_read_timer_interval
,
867 attr
->read_timer_interval
);
873 ret
= mi_lttng_writer_write_element_string(writer
,
874 config_element_output_type
,
875 attr
->output
== LTTNG_EVENT_SPLICE
?
876 config_output_type_splice
: config_output_type_mmap
);
881 /* Tracefile size in bytes */
882 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
883 config_element_tracefile_size
, attr
->tracefile_size
);
888 /* Count of tracefiles */
889 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
890 config_element_tracefile_count
,
891 attr
->tracefile_count
);
896 /* Live timer interval in usec*/
897 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
898 config_element_live_timer_interval
,
899 attr
->live_timer_interval
);
904 /* Closing attributes */
905 ret
= mi_lttng_writer_close_element(writer
);
915 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
916 struct lttng_event
*event
)
920 /* Open event element */
921 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
927 ret
= mi_lttng_writer_write_element_string(writer
,
928 config_element_name
, event
->name
);
934 ret
= mi_lttng_writer_write_element_string(writer
,
935 config_element_type
, mi_lttng_eventtype_string(event
->type
));
940 /* Is event enabled */
941 ret
= mi_lttng_writer_write_element_bool(writer
,
942 config_element_enabled
, event
->enabled
);
947 /* Event filter enabled? */
948 ret
= mi_lttng_writer_write_element_bool(writer
,
949 config_element_filter
, event
->filter
);
956 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
957 struct lttng_event
*event
, enum lttng_domain_type domain
)
962 ret
= mi_lttng_writer_write_element_string(writer
,
963 config_element_loglevel
,
964 mi_lttng_loglevel_string(event
->loglevel
, domain
));
970 ret
= mi_lttng_writer_write_element_string(writer
,
971 config_element_loglevel_type
,
972 mi_lttng_logleveltype_string(event
->loglevel_type
));
977 /* event exclusion filter */
978 ret
= mi_lttng_writer_write_element_bool(writer
,
979 config_element_exclusion
, event
->exclusion
);
989 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
990 struct lttng_event
*event
)
992 /* event exclusion filter */
993 return mi_lttng_writer_write_element_bool(writer
,
994 config_element_exclusion
, event
->exclusion
);
998 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
999 struct lttng_event
*event
)
1003 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1008 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1013 if (event
->attr
.probe
.addr
!= 0) {
1014 /* event probe address */
1015 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1016 config_element_address
, event
->attr
.probe
.addr
);
1021 /* event probe offset */
1022 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1023 config_element_offset
, event
->attr
.probe
.offset
);
1028 /* event probe symbol_name */
1029 ret
= mi_lttng_writer_write_element_string(writer
,
1030 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1036 /* Close probe_attributes and attributes */
1037 ret
= mi_lttng_close_multi_element(writer
, 2);
1043 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1044 struct lttng_event
*event
)
1048 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1053 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1058 /* event probe symbol_name */
1059 ret
= mi_lttng_writer_write_element_string(writer
,
1060 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1065 /* Close function_attributes and attributes */
1066 ret
= mi_lttng_close_multi_element(writer
, 2);
1072 int mi_lttng_events_open(struct mi_writer
*writer
)
1074 return mi_lttng_writer_open_element(writer
, config_element_events
);
1078 int mi_lttng_event(struct mi_writer
*writer
,
1079 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1083 ret
= mi_lttng_event_common_attributes(writer
, event
);
1088 switch (event
->type
) {
1089 case LTTNG_EVENT_TRACEPOINT
:
1091 if (event
->loglevel
!= -1) {
1092 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1094 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1098 case LTTNG_EVENT_FUNCTION
:
1100 case LTTNG_EVENT_PROBE
:
1101 ret
= mi_lttng_event_function_probe(writer
, event
);
1103 case LTTNG_EVENT_FUNCTION_ENTRY
:
1104 ret
= mi_lttng_event_function_entry(writer
, event
);
1106 case LTTNG_EVENT_ALL
:
1113 ret
= mi_lttng_writer_close_element(writer
);
1121 int mi_lttng_pids_open(struct mi_writer
*writer
)
1123 return mi_lttng_writer_open_element(writer
, mi_lttng_element_pids
);
1127 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *cmdline
,
1132 /* Open element pid */
1133 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_pid
);
1138 /* Writing pid number */
1139 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1140 mi_lttng_element_pid_id
, (int)pid
);
1145 /* Writing name of the process */
1146 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1154 ret
= mi_lttng_writer_close_element(writer
);
1162 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1164 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1168 int mi_lttng_event_field(struct mi_writer
*writer
,
1169 struct lttng_event_field
*field
)
1173 if (!field
->field_name
[0]) {
1179 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1184 if (!field
->field_name
[0]) {
1189 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1196 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1197 mi_lttng_eventfieldtype_string(field
->type
));
1203 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1204 mi_lttng_element_nowrite
, field
->nowrite
);
1210 /* Close field element */
1211 ret
= mi_lttng_writer_close_element(writer
);
1218 int mi_lttng_calibrate(struct mi_writer
*writer
,
1219 struct lttng_calibrate
*calibrate
)
1223 /* Open calibrate element */
1224 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1229 /* Calibration type */
1230 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1231 mi_lttng_calibratetype_string(calibrate
->type
));
1236 /* Closing calibrate element */
1237 ret
= mi_lttng_writer_close_element(writer
);
1242 int mi_lttng_context(struct mi_writer
*writer
,
1243 struct lttng_event_context
*context
, int is_open
)
1246 const char *type_string
;
1247 struct lttng_event_perf_counter_ctx
*perf_context
;
1249 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1254 type_string
= mi_lttng_event_contexttype_string(context
->ctx
);
1256 ret
= -LTTNG_ERR_INVALID
;
1260 /* Print context type */
1261 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1264 /* Special case for PERF_*_COUNTER
1265 * print the lttng_event_perf_counter_ctx*/
1266 switch (context
->ctx
) {
1267 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1268 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1269 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1270 perf_context
= &context
->u
.perf_counter
;
1271 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1282 ret
= mi_lttng_writer_close_element(writer
);
1290 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1291 struct lttng_event_perf_counter_ctx
*perf_context
)
1295 /* Open perf_counter_context */
1296 ret
= mi_lttng_writer_open_element(writer
,
1297 mi_lttng_element_perf_counter_context
);
1303 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1304 config_element_type
, perf_context
->type
);
1310 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1311 config_element_config
, perf_context
->config
);
1316 /* Name of the perf counter */
1317 ret
= mi_lttng_writer_write_element_string(writer
,
1318 config_element_name
, perf_context
->name
);
1323 /* Close perf_counter_context */
1324 ret
= mi_lttng_writer_close_element(writer
);
1330 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1331 const char *session_name
)
1335 /* Open session element */
1336 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1341 /* Snapshot output list for current session name */
1342 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1345 /* Open element snapshots (sequence one snapshot) */
1346 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1356 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1357 struct lttng_snapshot_output
*output
)
1361 /* Open element snapshot output */
1362 ret
= mi_lttng_writer_open_element(writer
,
1363 mi_lttng_element_command_snapshot
);
1368 /* ID of the snapshot output */
1369 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1370 mi_lttng_element_id
, output
->id
);
1375 /* Name of the output */
1376 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1382 /* Destination of the output (ctrl_url)*/
1383 ret
= mi_lttng_writer_write_element_string(writer
,
1384 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1389 /* Destination of the output (data_url) */
1390 ret
= mi_lttng_writer_write_element_string(writer
,
1391 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1396 /* total size of all stream combined */
1397 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1398 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1403 /* Close snapshot output element */
1404 ret
= mi_lttng_writer_close_element(writer
);
1411 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1412 const char *name
, const char *current_session_name
)
1416 /* Open element del_snapshot */
1417 ret
= mi_lttng_writer_open_element(writer
,
1418 mi_lttng_element_command_snapshot
);
1424 if (id
!= UINT32_MAX
) {
1425 /* "Snapshot output "id" successfully deleted
1426 * for "current_session_name"
1427 * ID of the snapshot output
1429 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1430 mi_lttng_element_id
, id
);
1435 /* "Snapshot output "name" successfully deleted
1436 * for session "current_session_name"
1437 * Name of the output
1439 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1446 /* Snapshot was deleted for session "current_session_name"*/
1447 ret
= mi_lttng_writer_write_element_string(writer
,
1448 mi_lttng_element_snapshot_session_name
,
1449 current_session_name
);
1454 /* Close snapshot element */
1455 ret
= mi_lttng_writer_close_element(writer
);
1462 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1463 const char *current_session_name
, const char *n_ptr
,
1464 struct lttng_snapshot_output
*output
)
1468 /* Open element snapshot */
1469 ret
= mi_lttng_writer_open_element(writer
,
1470 mi_lttng_element_command_snapshot
);
1475 /* Snapshot output id */
1476 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1477 mi_lttng_element_id
, output
->id
);
1482 /* Snapshot output names */
1483 ret
= mi_lttng_writer_write_element_string(writer
,
1484 config_element_name
, n_ptr
);
1489 /* Destination of the output (ctrl_url)*/
1490 ret
= mi_lttng_writer_write_element_string(writer
,
1491 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1496 /* Snapshot added for session "current_session_name"*/
1497 ret
= mi_lttng_writer_write_element_string(writer
,
1498 mi_lttng_element_snapshot_session_name
, current_session_name
);
1503 /* total size of all stream combined */
1504 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1505 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1510 /* Close snapshot element */
1511 ret
= mi_lttng_writer_close_element(writer
);
1518 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1519 const char *current_session_name
, const char *url
,
1520 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1524 /* Open element snapshot */
1525 ret
= mi_lttng_writer_open_element(writer
,
1526 mi_lttng_element_command_snapshot
);
1532 * If a valid an URL was given, serialize it,
1533 * else take the command line data and ctrl urls*/
1535 /* Destination of the output (ctrl_url)*/
1536 ret
= mi_lttng_writer_write_element_string(writer
,
1537 mi_lttng_element_snapshot_ctrl_url
, url
);
1541 } else if (cmdline_ctrl_url
) {
1542 /* Destination of the output (ctrl_url)*/
1543 ret
= mi_lttng_writer_write_element_string(writer
,
1544 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1549 /* Destination of the output (data_url) */
1550 ret
= mi_lttng_writer_write_element_string(writer
,
1551 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1557 /* Close record_snapshot element */
1558 ret
= mi_lttng_writer_close_element(writer
);