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 <common/config/session-config.h>
21 #include <lttng/snapshot-internal.h>
26 /* Strings related to command */
27 const char * const mi_lttng_element_command
= "command";
28 const char * const mi_lttng_element_command_action
= "snapshot_action";
29 const char * const mi_lttng_element_command_add_context
= "add-context";
30 const char * const mi_lttng_element_command_calibrate
= "calibrate";
31 const char * const mi_lttng_element_command_create
= "create";
32 const char * const mi_lttng_element_command_destroy
= "destroy";
33 const char * const mi_lttng_element_command_disable_channel
= "disable-channel";
34 const char * const mi_lttng_element_command_disable_event
= "disable-event";
35 const char * const mi_lttng_element_command_enable_channels
= "enable-channel";
36 const char * const mi_lttng_element_command_enable_event
= "enable-event";
37 const char * const mi_lttng_element_command_list
= "list";
38 const char * const mi_lttng_element_command_load
= "load";
39 const char * const mi_lttng_element_command_name
= "name";
40 const char * const mi_lttng_element_command_output
= "output";
41 const char * const mi_lttng_element_command_save
= "save";
42 const char * const mi_lttng_element_command_set_session
= "set-session";
43 const char * const mi_lttng_element_command_snapshot
= "snapshot";
44 const char * const mi_lttng_element_command_snapshot_add
= "add_snapshot";
45 const char * const mi_lttng_element_command_snapshot_del
= "del_snapshot";
46 const char * const mi_lttng_element_command_snapshot_list
= "list_snapshot";
47 const char * const mi_lttng_element_command_snapshot_record
= "record_snapshot";
48 const char * const mi_lttng_element_command_start
= "start";
49 const char * const mi_lttng_element_command_stop
= "stop";
50 const char * const mi_lttng_element_command_success
= "success";
51 const char * const mi_lttng_element_command_track
= "track";
52 const char * const mi_lttng_element_command_untrack
= "untrack";
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_pid_id
= "id";
81 /* Strings related to save command */
82 const char * const mi_lttng_element_save
= "save";
84 /* Strings related to load command */
85 const char * const mi_lttng_element_load
= "load";
87 /* General elements of mi_lttng */
88 const char * const mi_lttng_element_empty
= "";
89 const char * const mi_lttng_element_id
= "id";
90 const char * const mi_lttng_element_nowrite
= "nowrite";
91 const char * const mi_lttng_element_success
= "success";
92 const char * const mi_lttng_element_type_enum
= "ENUM";
93 const char * const mi_lttng_element_type_float
= "FLOAT";
94 const char * const mi_lttng_element_type_integer
= "INTEGER";
95 const char * const mi_lttng_element_type_other
= "OTHER";
96 const char * const mi_lttng_element_type_string
= "STRING";
98 /* String related to loglevel */
99 const char * const mi_lttng_loglevel_str_alert
= "TRACE_ALERT";
100 const char * const mi_lttng_loglevel_str_crit
= "TRACE_CRIT";
101 const char * const mi_lttng_loglevel_str_debug
= "TRACE_DEBUG";
102 const char * const mi_lttng_loglevel_str_debug_function
= "TRACE_DEBUG_FUNCTION";
103 const char * const mi_lttng_loglevel_str_debug_line
= "TRACE_DEBUG_LINE";
104 const char * const mi_lttng_loglevel_str_debug_module
= "TRACE_DEBUG_MODULE";
105 const char * const mi_lttng_loglevel_str_debug_process
= "TRACE_DEBUG_PROCESS";
106 const char * const mi_lttng_loglevel_str_debug_program
= "TRACE_DEBUG_PROGRAM";
107 const char * const mi_lttng_loglevel_str_debug_system
= "TRACE_DEBUG_SYSTEM";
108 const char * const mi_lttng_loglevel_str_debug_unit
= "TRACE_DEBUG_UNIT";
109 const char * const mi_lttng_loglevel_str_emerg
= "TRACE_EMERG";
110 const char * const mi_lttng_loglevel_str_err
= "TRACE_ERR";
111 const char * const mi_lttng_loglevel_str_info
= "TRACE_INFO";
112 const char * const mi_lttng_loglevel_str_notice
= "TRACE_NOTICE";
113 const char * const mi_lttng_loglevel_str_unknown
= "UNKNOWN";
114 const char * const mi_lttng_loglevel_str_warning
= "TRACE_WARNING";
116 /* String related to loglevel JUL */
117 const char * const mi_lttng_loglevel_str_jul_all
= "JUL_ALL";
118 const char * const mi_lttng_loglevel_str_jul_config
= "JUL_CONFIG";
119 const char * const mi_lttng_loglevel_str_jul_fine
= "JUL_FINE";
120 const char * const mi_lttng_loglevel_str_jul_finer
= "JUL_FINER";
121 const char * const mi_lttng_loglevel_str_jul_finest
= "JUL_FINEST";
122 const char * const mi_lttng_loglevel_str_jul_info
= "JUL_INFO";
123 const char * const mi_lttng_loglevel_str_jul_off
= "JUL_OFF";
124 const char * const mi_lttng_loglevel_str_jul_severe
= "JUL_SEVERE";
125 const char * const mi_lttng_loglevel_str_jul_warning
= "JUL_WARNING";
127 /* String related to loglevel LOG4J */
128 const char * const mi_lttng_loglevel_str_log4j_off
= "LOG4J_OFF";
129 const char * const mi_lttng_loglevel_str_log4j_fatal
= "LOG4J_FATAL";
130 const char * const mi_lttng_loglevel_str_log4j_error
= "LOG4J_ERROR";
131 const char * const mi_lttng_loglevel_str_log4j_warn
= "LOG4J_WARN";
132 const char * const mi_lttng_loglevel_str_log4j_info
= "LOG4J_INFO";
133 const char * const mi_lttng_loglevel_str_log4j_debug
= "LOG4J_DEBUG";
134 const char * const mi_lttng_loglevel_str_log4j_trace
= "LOG4J_TRACE";
135 const char * const mi_lttng_loglevel_str_log4j_all
= "LOG4J_ALL";
137 /* String related to loglevel Python */
138 const char * const mi_lttng_loglevel_str_python_critical
= "PYTHON_CRITICAL";
139 const char * const mi_lttng_loglevel_str_python_error
= "PYTHON_ERROR";
140 const char * const mi_lttng_loglevel_str_python_warning
= "PYTHON_WARNING";
141 const char * const mi_lttng_loglevel_str_python_info
= "PYTHON_INFO";
142 const char * const mi_lttng_loglevel_str_python_debug
= "PYTHON_DEBUG";
143 const char * const mi_lttng_loglevel_str_python_notset
= "PYTHON_NOTSET";
145 /* String related to loglevel type */
146 const char * const mi_lttng_loglevel_type_all
= "ALL";
147 const char * const mi_lttng_loglevel_type_range
= "RANGE";
148 const char * const mi_lttng_loglevel_type_single
= "SINGLE";
149 const char * const mi_lttng_loglevel_type_unknown
= "UNKNOWN";
151 /* String related to lttng_calibrate */
152 const char * const mi_lttng_element_calibrate
= "calibrate";
153 const char * const mi_lttng_element_calibrate_function
= "FUNCTION";
155 /* String related to a lttng_snapshot_output */
156 const char * const mi_lttng_element_snapshot_ctrl_url
= "ctrl_url";
157 const char * const mi_lttng_element_snapshot_data_url
= "data_url";
158 const char * const mi_lttng_element_snapshot_max_size
= "max_size";
159 const char * const mi_lttng_element_snapshot_n_ptr
= "n_ptr";
160 const char * const mi_lttng_element_snapshot_session_name
= "session_name";
161 const char * const mi_lttng_element_snapshots
= "snapshots";
163 /* String related to track/untrack command */
164 const char * const mi_lttng_element_track_untrack_all_wildcard
= "*";
167 /* This is a merge of jul loglevel and regular loglevel
168 * Those should never overlap by definition
169 * (see struct lttng_event loglevel)
172 const char *mi_lttng_loglevel_string(int value
, enum lttng_domain_type domain
)
175 case LTTNG_DOMAIN_KERNEL
:
176 case LTTNG_DOMAIN_UST
:
179 return mi_lttng_element_empty
;
180 case LTTNG_LOGLEVEL_EMERG
:
181 return mi_lttng_loglevel_str_emerg
;
182 case LTTNG_LOGLEVEL_ALERT
:
183 return mi_lttng_loglevel_str_alert
;
184 case LTTNG_LOGLEVEL_CRIT
:
185 return mi_lttng_loglevel_str_crit
;
186 case LTTNG_LOGLEVEL_ERR
:
187 return mi_lttng_loglevel_str_err
;
188 case LTTNG_LOGLEVEL_WARNING
:
189 return mi_lttng_loglevel_str_warning
;
190 case LTTNG_LOGLEVEL_NOTICE
:
191 return mi_lttng_loglevel_str_notice
;
192 case LTTNG_LOGLEVEL_INFO
:
193 return mi_lttng_loglevel_str_info
;
194 case LTTNG_LOGLEVEL_DEBUG_SYSTEM
:
195 return mi_lttng_loglevel_str_debug_system
;
196 case LTTNG_LOGLEVEL_DEBUG_PROGRAM
:
197 return mi_lttng_loglevel_str_debug_program
;
198 case LTTNG_LOGLEVEL_DEBUG_PROCESS
:
199 return mi_lttng_loglevel_str_debug_process
;
200 case LTTNG_LOGLEVEL_DEBUG_MODULE
:
201 return mi_lttng_loglevel_str_debug_module
;
202 case LTTNG_LOGLEVEL_DEBUG_UNIT
:
203 return mi_lttng_loglevel_str_debug_unit
;
204 case LTTNG_LOGLEVEL_DEBUG_FUNCTION
:
205 return mi_lttng_loglevel_str_debug_function
;
206 case LTTNG_LOGLEVEL_DEBUG_LINE
:
207 return mi_lttng_loglevel_str_debug_line
;
208 case LTTNG_LOGLEVEL_DEBUG
:
209 return mi_lttng_loglevel_str_debug
;
211 return mi_lttng_loglevel_str_unknown
;
214 case LTTNG_DOMAIN_LOG4J
:
217 return mi_lttng_element_empty
;
218 case LTTNG_LOGLEVEL_LOG4J_OFF
:
219 return mi_lttng_loglevel_str_log4j_off
;
220 case LTTNG_LOGLEVEL_LOG4J_FATAL
:
221 return mi_lttng_loglevel_str_log4j_fatal
;
222 case LTTNG_LOGLEVEL_LOG4J_ERROR
:
223 return mi_lttng_loglevel_str_log4j_error
;
224 case LTTNG_LOGLEVEL_LOG4J_WARN
:
225 return mi_lttng_loglevel_str_log4j_warn
;
226 case LTTNG_LOGLEVEL_LOG4J_INFO
:
227 return mi_lttng_loglevel_str_log4j_info
;
228 case LTTNG_LOGLEVEL_LOG4J_DEBUG
:
229 return mi_lttng_loglevel_str_log4j_debug
;
230 case LTTNG_LOGLEVEL_LOG4J_TRACE
:
231 return mi_lttng_loglevel_str_log4j_trace
;
232 case LTTNG_LOGLEVEL_LOG4J_ALL
:
233 return mi_lttng_loglevel_str_log4j_all
;
235 return mi_lttng_loglevel_str_unknown
;
238 case LTTNG_DOMAIN_JUL
:
241 return mi_lttng_element_empty
;
242 case LTTNG_LOGLEVEL_JUL_OFF
:
243 return mi_lttng_loglevel_str_jul_off
;
244 case LTTNG_LOGLEVEL_JUL_SEVERE
:
245 return mi_lttng_loglevel_str_jul_severe
;
246 case LTTNG_LOGLEVEL_JUL_WARNING
:
247 return mi_lttng_loglevel_str_jul_warning
;
248 case LTTNG_LOGLEVEL_JUL_INFO
:
249 return mi_lttng_loglevel_str_jul_info
;
250 case LTTNG_LOGLEVEL_JUL_CONFIG
:
251 return mi_lttng_loglevel_str_jul_config
;
252 case LTTNG_LOGLEVEL_JUL_FINE
:
253 return mi_lttng_loglevel_str_jul_fine
;
254 case LTTNG_LOGLEVEL_JUL_FINER
:
255 return mi_lttng_loglevel_str_jul_finer
;
256 case LTTNG_LOGLEVEL_JUL_FINEST
:
257 return mi_lttng_loglevel_str_jul_finest
;
258 case LTTNG_LOGLEVEL_JUL_ALL
:
259 return mi_lttng_loglevel_str_jul_all
;
261 return mi_lttng_loglevel_str_unknown
;
264 case LTTNG_DOMAIN_PYTHON
:
266 case LTTNG_LOGLEVEL_PYTHON_CRITICAL
:
267 return mi_lttng_loglevel_str_python_critical
;
268 case LTTNG_LOGLEVEL_PYTHON_ERROR
:
269 return mi_lttng_loglevel_str_python_error
;
270 case LTTNG_LOGLEVEL_PYTHON_WARNING
:
271 return mi_lttng_loglevel_str_python_warning
;
272 case LTTNG_LOGLEVEL_PYTHON_INFO
:
273 return mi_lttng_loglevel_str_python_info
;
274 case LTTNG_LOGLEVEL_PYTHON_DEBUG
:
275 return mi_lttng_loglevel_str_python_debug
;
276 case LTTNG_LOGLEVEL_PYTHON_NOTSET
:
277 return mi_lttng_loglevel_str_python_notset
;
279 return mi_lttng_loglevel_str_unknown
;
284 /* Reaching this means the domain is unknown. */
285 return mi_lttng_loglevel_str_unknown
;
289 const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value
)
292 case LTTNG_EVENT_LOGLEVEL_ALL
:
293 return mi_lttng_loglevel_type_all
;
294 case LTTNG_EVENT_LOGLEVEL_RANGE
:
295 return mi_lttng_loglevel_type_range
;
296 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
297 return mi_lttng_loglevel_type_single
;
299 return mi_lttng_loglevel_type_unknown
;
304 const char *mi_lttng_eventtype_string(enum lttng_event_type value
)
307 case LTTNG_EVENT_ALL
:
308 return config_event_type_all
;
309 case LTTNG_EVENT_TRACEPOINT
:
310 return config_event_type_tracepoint
;
311 case LTTNG_EVENT_PROBE
:
312 return config_event_type_probe
;
313 case LTTNG_EVENT_FUNCTION
:
314 return config_event_type_function
;
315 case LTTNG_EVENT_FUNCTION_ENTRY
:
316 return config_event_type_function_entry
;
317 case LTTNG_EVENT_SYSCALL
:
318 return config_event_type_syscall
;
319 case LTTNG_EVENT_NOOP
:
320 return config_event_type_noop
;
322 return mi_lttng_element_empty
;
327 const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val
)
330 case LTTNG_EVENT_CONTEXT_PID
:
331 return config_event_context_pid
;
332 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
333 return mi_lttng_context_type_perf_counter
;
334 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
335 return mi_lttng_context_type_perf_thread_counter
;
336 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
337 return mi_lttng_context_type_perf_cpu_counter
;
338 case LTTNG_EVENT_CONTEXT_PROCNAME
:
339 return config_event_context_procname
;
340 case LTTNG_EVENT_CONTEXT_PRIO
:
341 return config_event_context_prio
;
342 case LTTNG_EVENT_CONTEXT_NICE
:
343 return config_event_context_nice
;
344 case LTTNG_EVENT_CONTEXT_VPID
:
345 return config_event_context_vpid
;
346 case LTTNG_EVENT_CONTEXT_TID
:
347 return config_event_context_tid
;
348 case LTTNG_EVENT_CONTEXT_VTID
:
349 return config_event_context_vtid
;
350 case LTTNG_EVENT_CONTEXT_PPID
:
351 return config_event_context_ppid
;
352 case LTTNG_EVENT_CONTEXT_VPPID
:
353 return config_event_context_vppid
;
354 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
355 return config_event_context_pthread_id
;
356 case LTTNG_EVENT_CONTEXT_HOSTNAME
:
357 return config_event_context_hostname
;
358 case LTTNG_EVENT_CONTEXT_IP
:
359 return config_event_context_ip
;
366 const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val
)
369 case(LTTNG_EVENT_FIELD_INTEGER
):
370 return mi_lttng_element_type_integer
;
371 case(LTTNG_EVENT_FIELD_ENUM
):
372 return mi_lttng_element_type_enum
;
373 case(LTTNG_EVENT_FIELD_FLOAT
):
374 return mi_lttng_element_type_float
;
375 case(LTTNG_EVENT_FIELD_STRING
):
376 return mi_lttng_element_type_string
;
378 return mi_lttng_element_type_other
;
383 const char *mi_lttng_domaintype_string(enum lttng_domain_type value
)
385 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
387 case LTTNG_DOMAIN_KERNEL
:
388 return config_domain_type_kernel
;
389 case LTTNG_DOMAIN_UST
:
390 return config_domain_type_ust
;
391 case LTTNG_DOMAIN_JUL
:
392 return config_domain_type_jul
;
393 case LTTNG_DOMAIN_LOG4J
:
394 return config_domain_type_log4j
;
395 case LTTNG_DOMAIN_PYTHON
:
396 return config_domain_type_python
;
398 /* Should not have an unknown domain */
405 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value
)
408 case LTTNG_BUFFER_PER_PID
:
409 return config_buffer_type_per_pid
;
410 case LTTNG_BUFFER_PER_UID
:
411 return config_buffer_type_per_uid
;
412 case LTTNG_BUFFER_GLOBAL
:
413 return config_buffer_type_global
;
415 /* Should not have an unknow buffer type */
422 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val
)
427 case LTTNG_CALIBRATE_FUNCTION
:
428 ret
= mi_lttng_element_calibrate_function
;
431 ret
= mi_lttng_element_empty
;
438 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
)
440 struct mi_writer
*mi_writer
;
442 mi_writer
= zmalloc(sizeof(struct mi_writer
));
444 PERROR("zmalloc mi_writer_create");
447 if (mi_output_type
== LTTNG_MI_XML
) {
448 mi_writer
->writer
= config_writer_create(fd_output
, 0);
449 if (!mi_writer
->writer
) {
452 mi_writer
->type
= LTTNG_MI_XML
;
466 int mi_lttng_writer_destroy(struct mi_writer
*writer
)
475 ret
= config_writer_destroy(writer
->writer
);
486 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
)
490 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_command
);
494 ret
= mi_lttng_writer_write_element_string(writer
,
495 mi_lttng_element_command_name
, command
);
501 int mi_lttng_writer_command_close(struct mi_writer
*writer
)
503 return mi_lttng_writer_close_element(writer
);
507 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
508 const char *element_name
)
510 return config_writer_open_element(writer
->writer
, element_name
);
514 int mi_lttng_writer_close_element(struct mi_writer
*writer
)
516 return config_writer_close_element(writer
->writer
);
520 int mi_lttng_close_multi_element(struct mi_writer
*writer
,
521 unsigned int nb_element
)
525 if (nb_element
< 1) {
529 for (i
= 0; i
< nb_element
; i
++) {
530 ret
= mi_lttng_writer_close_element(writer
);
540 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
541 const char *element_name
, uint64_t value
)
543 return config_writer_write_element_unsigned_int(writer
->writer
,
544 element_name
, value
);
548 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
549 const char *element_name
, int64_t value
)
551 return config_writer_write_element_signed_int(writer
->writer
,
552 element_name
, value
);
556 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
557 const char *element_name
, int value
)
559 return config_writer_write_element_bool(writer
->writer
,
560 element_name
, value
);
564 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
565 const char *element_name
, const char *value
)
567 return config_writer_write_element_string(writer
->writer
,
568 element_name
, value
);
572 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
573 const char *lttng_description
, const char *lttng_license
)
578 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_version
);
583 /* Version string (contain info like rc etc.) */
584 ret
= mi_lttng_writer_write_element_string(writer
,
585 mi_lttng_element_version_str
, version
->version
);
590 /* Major version number */
591 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
592 mi_lttng_element_version_major
, version
->version_major
);
597 /* Minor version number */
598 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
599 mi_lttng_element_version_minor
, version
->version_minor
);
604 /* Commit version number */
605 ret
= mi_lttng_writer_write_element_string(writer
,
606 mi_lttng_element_version_commit
, version
->version_commit
);
612 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
613 mi_lttng_element_version_patch_level
, version
->version_patchlevel
);
618 /* Name of the version */
619 ret
= mi_lttng_writer_write_element_string(writer
,
620 config_element_name
, version
->version_name
);
625 /* Description mostly related to beer... */
626 ret
= mi_lttng_writer_write_element_string(writer
,
627 mi_lttng_element_version_description
, lttng_description
);
633 ret
= mi_lttng_writer_write_element_string(writer
,
634 mi_lttng_element_version_web
, version
->package_url
);
639 /* License: free as in free beer...no...*speech* */
640 ret
= mi_lttng_writer_write_element_string(writer
,
641 mi_lttng_element_version_license
, lttng_license
);
646 /* Close version element */
647 ret
= mi_lttng_writer_close_element(writer
);
654 int mi_lttng_sessions_open(struct mi_writer
*writer
)
656 return mi_lttng_writer_open_element(writer
, config_element_sessions
);
660 int mi_lttng_session(struct mi_writer
*writer
,
661 struct lttng_session
*session
, int is_open
)
667 /* Open sessions element */
668 ret
= mi_lttng_writer_open_element(writer
,
669 config_element_session
);
674 /* Name of the session */
675 ret
= mi_lttng_writer_write_element_string(writer
,
676 config_element_name
, session
->name
);
682 ret
= mi_lttng_writer_write_element_string(writer
,
683 config_element_path
, session
->path
);
689 ret
= mi_lttng_writer_write_element_bool(writer
,
690 config_element_enabled
, session
->enabled
);
696 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
697 config_element_snapshot_mode
, session
->snapshot_mode
);
702 /* Live timer interval in usec */
703 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
704 config_element_live_timer_interval
,
705 session
->live_timer_interval
);
711 /* Closing session element */
712 ret
= mi_lttng_writer_close_element(writer
);
720 int mi_lttng_domains_open(struct mi_writer
*writer
)
722 return mi_lttng_writer_open_element(writer
, config_element_domains
);
726 int mi_lttng_domain(struct mi_writer
*writer
,
727 struct lttng_domain
*domain
, int is_open
)
730 const char *str_domain
;
731 const char *str_buffer
;
735 /* Open domain element */
736 ret
= mi_lttng_writer_open_element(writer
, config_element_domain
);
742 str_domain
= mi_lttng_domaintype_string(domain
->type
);
743 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
750 str_buffer
= mi_lttng_buffertype_string(domain
->buf_type
);
751 ret
= mi_lttng_writer_write_element_string(writer
,
752 config_element_buffer_type
, str_buffer
);
758 * This union is not currently used and was added for
759 * future ust domain support.
764 /* Closing domain element */
765 ret
= mi_lttng_writer_close_element(writer
);
774 int mi_lttng_channels_open(struct mi_writer
*writer
)
776 return mi_lttng_writer_open_element(writer
, config_element_channels
);
780 int mi_lttng_channel(struct mi_writer
*writer
,
781 struct lttng_channel
*channel
, int is_open
)
787 /* Opening channel element */
788 ret
= mi_lttng_writer_open_element(writer
, config_element_channel
);
794 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
801 ret
= mi_lttng_writer_write_element_bool(writer
,
802 config_element_enabled
, channel
->enabled
);
808 ret
= mi_lttng_channel_attr(writer
, &channel
->attr
);
814 /* Closing channel element */
815 ret
= mi_lttng_writer_close_element(writer
);
825 int mi_lttng_channel_attr(struct mi_writer
*writer
,
826 struct lttng_channel_attr
*attr
)
832 /* Opening Attributes */
833 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
839 ret
= mi_lttng_writer_write_element_string(writer
,
840 config_element_overwrite_mode
,
841 attr
->overwrite
? config_overwrite_mode_overwrite
:
842 config_overwrite_mode_discard
);
847 /* Sub buffer size in byte */
848 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
849 config_element_subbuf_size
, attr
->subbuf_size
);
854 /* Number of subbuffer (power of two) */
855 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
856 config_element_num_subbuf
,
862 /* Switch timer interval in usec */
863 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
864 config_element_switch_timer_interval
,
865 attr
->switch_timer_interval
);
870 /* Read timer interval in usec */
871 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
872 config_element_read_timer_interval
,
873 attr
->read_timer_interval
);
879 ret
= mi_lttng_writer_write_element_string(writer
,
880 config_element_output_type
,
881 attr
->output
== LTTNG_EVENT_SPLICE
?
882 config_output_type_splice
: config_output_type_mmap
);
887 /* Tracefile size in bytes */
888 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
889 config_element_tracefile_size
, attr
->tracefile_size
);
894 /* Count of tracefiles */
895 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
896 config_element_tracefile_count
,
897 attr
->tracefile_count
);
902 /* Live timer interval in usec*/
903 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
904 config_element_live_timer_interval
,
905 attr
->live_timer_interval
);
910 /* Closing attributes */
911 ret
= mi_lttng_writer_close_element(writer
);
921 int mi_lttng_event_common_attributes(struct mi_writer
*writer
,
922 struct lttng_event
*event
)
925 const char *filter_expression
;
927 /* Open event element */
928 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
934 ret
= mi_lttng_writer_write_element_string(writer
,
935 config_element_name
, event
->name
);
941 ret
= mi_lttng_writer_write_element_string(writer
,
942 config_element_type
, mi_lttng_eventtype_string(event
->type
));
947 /* Is event enabled */
948 ret
= mi_lttng_writer_write_element_bool(writer
,
949 config_element_enabled
, event
->enabled
);
954 /* Event filter enabled? */
955 ret
= mi_lttng_writer_write_element_bool(writer
,
956 config_element_filter
, event
->filter
);
958 /* Event filter expression */
959 ret
= lttng_event_get_filter_string(event
, &filter_expression
);
965 if (filter_expression
) {
966 ret
= mi_lttng_writer_write_element_string(writer
,
967 config_element_filter_expression
,
980 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
981 struct lttng_event
*event
, enum lttng_domain_type domain
)
986 ret
= mi_lttng_writer_write_element_string(writer
,
987 config_element_loglevel
,
988 mi_lttng_loglevel_string(event
->loglevel
, domain
));
994 ret
= mi_lttng_writer_write_element_string(writer
,
995 config_element_loglevel_type
,
996 mi_lttng_logleveltype_string(event
->loglevel_type
));
1001 /* event exclusion filter */
1002 ret
= mi_lttng_writer_write_element_bool(writer
,
1003 config_element_exclusion
, event
->exclusion
);
1013 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
1014 struct lttng_event
*event
)
1016 /* event exclusion filter */
1017 return mi_lttng_writer_write_element_bool(writer
,
1018 config_element_exclusion
, event
->exclusion
);
1022 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1023 struct lttng_event
*event
)
1027 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1032 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1037 if (event
->attr
.probe
.addr
!= 0) {
1038 /* event probe address */
1039 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1040 config_element_address
, event
->attr
.probe
.addr
);
1045 /* event probe offset */
1046 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1047 config_element_offset
, event
->attr
.probe
.offset
);
1052 /* event probe symbol_name */
1053 ret
= mi_lttng_writer_write_element_string(writer
,
1054 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1060 /* Close probe_attributes and attributes */
1061 ret
= mi_lttng_close_multi_element(writer
, 2);
1067 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1068 struct lttng_event
*event
)
1072 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1077 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1082 /* event probe symbol_name */
1083 ret
= mi_lttng_writer_write_element_string(writer
,
1084 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1089 /* Close function_attributes and attributes */
1090 ret
= mi_lttng_close_multi_element(writer
, 2);
1096 int mi_lttng_events_open(struct mi_writer
*writer
)
1098 return mi_lttng_writer_open_element(writer
, config_element_events
);
1102 int mi_lttng_event(struct mi_writer
*writer
,
1103 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1107 ret
= mi_lttng_event_common_attributes(writer
, event
);
1112 switch (event
->type
) {
1113 case LTTNG_EVENT_TRACEPOINT
:
1115 if (event
->loglevel
!= -1) {
1116 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1118 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1122 case LTTNG_EVENT_FUNCTION
:
1124 case LTTNG_EVENT_PROBE
:
1125 ret
= mi_lttng_event_function_probe(writer
, event
);
1127 case LTTNG_EVENT_FUNCTION_ENTRY
:
1128 ret
= mi_lttng_event_function_entry(writer
, event
);
1130 case LTTNG_EVENT_ALL
:
1137 ret
= mi_lttng_writer_close_element(writer
);
1145 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1147 return mi_lttng_writer_open_element(writer
, config_element_trackers
);
1151 int mi_lttng_pid_tracker_open(struct mi_writer
*writer
)
1155 /* Open element pid_tracker */
1156 ret
= mi_lttng_writer_open_element(writer
, config_element_pid_tracker
);
1161 /* Open targets element */
1162 ret
= mi_lttng_targets_open(writer
);
1168 int mi_lttng_pids_open(struct mi_writer
*writer
)
1170 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1174 * TODO: move the listing of pid for user agent to process semantic on
1175 * mi api bump. The use of process element break the mi api.
1178 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *name
,
1183 /* Open pid process */
1184 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1189 /* Writing pid number */
1190 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1191 mi_lttng_element_pid_id
, (int)pid
);
1196 /* Writing name of the process */
1198 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1207 ret
= mi_lttng_writer_close_element(writer
);
1215 int mi_lttng_targets_open(struct mi_writer
*writer
)
1217 return mi_lttng_writer_open_element(writer
,
1218 config_element_targets
);
1222 int mi_lttng_pid_target(struct mi_writer
*writer
, pid_t pid
, int is_open
)
1226 ret
= mi_lttng_writer_open_element(writer
,
1227 config_element_target_pid
);
1232 /* Writing pid number
1233 * Special case for element all on track untrack command
1234 * All pid is represented as wildcard *
1236 if ((int) pid
== -1) {
1237 ret
= mi_lttng_writer_write_element_string(writer
,
1239 mi_lttng_element_track_untrack_all_wildcard
);
1241 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1242 config_element_pid
, (int) pid
);
1249 ret
= mi_lttng_writer_close_element(writer
);
1260 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1262 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1266 int mi_lttng_event_field(struct mi_writer
*writer
,
1267 struct lttng_event_field
*field
)
1271 if (!field
->field_name
[0]) {
1277 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1282 if (!field
->field_name
[0]) {
1287 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1294 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1295 mi_lttng_eventfieldtype_string(field
->type
));
1301 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1302 mi_lttng_element_nowrite
, field
->nowrite
);
1308 /* Close field element */
1309 ret
= mi_lttng_writer_close_element(writer
);
1316 int mi_lttng_calibrate(struct mi_writer
*writer
,
1317 struct lttng_calibrate
*calibrate
)
1321 /* Open calibrate element */
1322 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1327 /* Calibration type */
1328 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1329 mi_lttng_calibratetype_string(calibrate
->type
));
1334 /* Closing calibrate element */
1335 ret
= mi_lttng_writer_close_element(writer
);
1341 int mi_lttng_context(struct mi_writer
*writer
,
1342 struct lttng_event_context
*context
, int is_open
)
1345 const char *type_string
;
1346 struct lttng_event_perf_counter_ctx
*perf_context
;
1348 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1353 type_string
= mi_lttng_event_contexttype_string(context
->ctx
);
1355 ret
= -LTTNG_ERR_INVALID
;
1359 /* Print context type */
1360 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1363 /* Special case for PERF_*_COUNTER
1364 * print the lttng_event_perf_counter_ctx*/
1365 switch (context
->ctx
) {
1366 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1367 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1368 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1369 perf_context
= &context
->u
.perf_counter
;
1370 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1381 ret
= mi_lttng_writer_close_element(writer
);
1389 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1390 struct lttng_event_perf_counter_ctx
*perf_context
)
1394 /* Open perf_counter_context */
1395 ret
= mi_lttng_writer_open_element(writer
,
1396 mi_lttng_element_perf_counter_context
);
1402 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1403 config_element_type
, perf_context
->type
);
1409 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1410 config_element_config
, perf_context
->config
);
1415 /* Name of the perf counter */
1416 ret
= mi_lttng_writer_write_element_string(writer
,
1417 config_element_name
, perf_context
->name
);
1422 /* Close perf_counter_context */
1423 ret
= mi_lttng_writer_close_element(writer
);
1429 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1430 const char *session_name
)
1434 /* Open session element */
1435 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1440 /* Snapshot output list for current session name */
1441 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1447 /* Open element snapshots (sequence one snapshot) */
1448 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1458 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1459 struct lttng_snapshot_output
*output
)
1463 /* Open element snapshot output */
1464 ret
= mi_lttng_writer_open_element(writer
,
1465 mi_lttng_element_command_snapshot
);
1470 /* ID of the snapshot output */
1471 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1472 mi_lttng_element_id
, output
->id
);
1477 /* Name of the output */
1478 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1484 /* Destination of the output (ctrl_url)*/
1485 ret
= mi_lttng_writer_write_element_string(writer
,
1486 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1491 /* Destination of the output (data_url) */
1492 ret
= mi_lttng_writer_write_element_string(writer
,
1493 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1498 /* total size of all stream combined */
1499 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1500 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1505 /* Close snapshot output element */
1506 ret
= mi_lttng_writer_close_element(writer
);
1513 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1514 const char *name
, const char *current_session_name
)
1518 /* Open element del_snapshot */
1519 ret
= mi_lttng_writer_open_element(writer
,
1520 mi_lttng_element_command_snapshot
);
1526 if (id
!= UINT32_MAX
) {
1527 /* "Snapshot output "id" successfully deleted
1528 * for "current_session_name"
1529 * ID of the snapshot output
1531 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1532 mi_lttng_element_id
, id
);
1537 /* "Snapshot output "name" successfully deleted
1538 * for session "current_session_name"
1539 * Name of the output
1541 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1548 /* Snapshot was deleted for session "current_session_name"*/
1549 ret
= mi_lttng_writer_write_element_string(writer
,
1550 mi_lttng_element_snapshot_session_name
,
1551 current_session_name
);
1556 /* Close snapshot element */
1557 ret
= mi_lttng_writer_close_element(writer
);
1564 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1565 const char *current_session_name
, const char *n_ptr
,
1566 struct lttng_snapshot_output
*output
)
1570 /* Open element snapshot */
1571 ret
= mi_lttng_writer_open_element(writer
,
1572 mi_lttng_element_command_snapshot
);
1577 /* Snapshot output id */
1578 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1579 mi_lttng_element_id
, output
->id
);
1584 /* Snapshot output names */
1585 ret
= mi_lttng_writer_write_element_string(writer
,
1586 config_element_name
, n_ptr
);
1591 /* Destination of the output (ctrl_url)*/
1592 ret
= mi_lttng_writer_write_element_string(writer
,
1593 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1598 /* Snapshot added for session "current_session_name"*/
1599 ret
= mi_lttng_writer_write_element_string(writer
,
1600 mi_lttng_element_snapshot_session_name
, current_session_name
);
1605 /* total size of all stream combined */
1606 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1607 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1612 /* Close snapshot element */
1613 ret
= mi_lttng_writer_close_element(writer
);
1620 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1621 const char *current_session_name
, const char *url
,
1622 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1626 /* Open element snapshot */
1627 ret
= mi_lttng_writer_open_element(writer
,
1628 mi_lttng_element_command_snapshot
);
1634 * If a valid an URL was given, serialize it,
1635 * else take the command line data and ctrl urls*/
1637 /* Destination of the output (ctrl_url)*/
1638 ret
= mi_lttng_writer_write_element_string(writer
,
1639 mi_lttng_element_snapshot_ctrl_url
, url
);
1643 } else if (cmdline_ctrl_url
) {
1644 /* Destination of the output (ctrl_url)*/
1645 ret
= mi_lttng_writer_write_element_string(writer
,
1646 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1651 /* Destination of the output (data_url) */
1652 ret
= mi_lttng_writer_write_element_string(writer
,
1653 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1659 /* Close record_snapshot element */
1660 ret
= mi_lttng_writer_close_element(writer
);