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
)
926 /* Open event element */
927 ret
= mi_lttng_writer_open_element(writer
, config_element_event
);
933 ret
= mi_lttng_writer_write_element_string(writer
,
934 config_element_name
, event
->name
);
940 ret
= mi_lttng_writer_write_element_string(writer
,
941 config_element_type
, mi_lttng_eventtype_string(event
->type
));
946 /* Is event enabled */
947 ret
= mi_lttng_writer_write_element_bool(writer
,
948 config_element_enabled
, event
->enabled
);
953 /* Event filter enabled? */
954 ret
= mi_lttng_writer_write_element_bool(writer
,
955 config_element_filter
, event
->filter
);
962 int mi_lttng_event_tracepoint_loglevel(struct mi_writer
*writer
,
963 struct lttng_event
*event
, enum lttng_domain_type domain
)
968 ret
= mi_lttng_writer_write_element_string(writer
,
969 config_element_loglevel
,
970 mi_lttng_loglevel_string(event
->loglevel
, domain
));
976 ret
= mi_lttng_writer_write_element_string(writer
,
977 config_element_loglevel_type
,
978 mi_lttng_logleveltype_string(event
->loglevel_type
));
983 /* event exclusion filter */
984 ret
= mi_lttng_writer_write_element_bool(writer
,
985 config_element_exclusion
, event
->exclusion
);
995 int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer
*writer
,
996 struct lttng_event
*event
)
998 /* event exclusion filter */
999 return mi_lttng_writer_write_element_bool(writer
,
1000 config_element_exclusion
, event
->exclusion
);
1004 int mi_lttng_event_function_probe(struct mi_writer
*writer
,
1005 struct lttng_event
*event
)
1009 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1014 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1019 if (event
->attr
.probe
.addr
!= 0) {
1020 /* event probe address */
1021 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1022 config_element_address
, event
->attr
.probe
.addr
);
1027 /* event probe offset */
1028 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1029 config_element_offset
, event
->attr
.probe
.offset
);
1034 /* event probe symbol_name */
1035 ret
= mi_lttng_writer_write_element_string(writer
,
1036 config_element_symbol_name
, event
->attr
.probe
.symbol_name
);
1042 /* Close probe_attributes and attributes */
1043 ret
= mi_lttng_close_multi_element(writer
, 2);
1049 int mi_lttng_event_function_entry(struct mi_writer
*writer
,
1050 struct lttng_event
*event
)
1054 ret
= mi_lttng_writer_open_element(writer
, config_element_attributes
);
1059 ret
= mi_lttng_writer_open_element(writer
, config_element_probe_attributes
);
1064 /* event probe symbol_name */
1065 ret
= mi_lttng_writer_write_element_string(writer
,
1066 config_element_symbol_name
, event
->attr
.ftrace
.symbol_name
);
1071 /* Close function_attributes and attributes */
1072 ret
= mi_lttng_close_multi_element(writer
, 2);
1078 int mi_lttng_events_open(struct mi_writer
*writer
)
1080 return mi_lttng_writer_open_element(writer
, config_element_events
);
1084 int mi_lttng_event(struct mi_writer
*writer
,
1085 struct lttng_event
*event
, int is_open
, enum lttng_domain_type domain
)
1089 ret
= mi_lttng_event_common_attributes(writer
, event
);
1094 switch (event
->type
) {
1095 case LTTNG_EVENT_TRACEPOINT
:
1097 if (event
->loglevel
!= -1) {
1098 ret
= mi_lttng_event_tracepoint_loglevel(writer
, event
, domain
);
1100 ret
= mi_lttng_event_tracepoint_no_loglevel(writer
, event
);
1104 case LTTNG_EVENT_FUNCTION
:
1106 case LTTNG_EVENT_PROBE
:
1107 ret
= mi_lttng_event_function_probe(writer
, event
);
1109 case LTTNG_EVENT_FUNCTION_ENTRY
:
1110 ret
= mi_lttng_event_function_entry(writer
, event
);
1112 case LTTNG_EVENT_ALL
:
1119 ret
= mi_lttng_writer_close_element(writer
);
1127 int mi_lttng_trackers_open(struct mi_writer
*writer
)
1129 return mi_lttng_writer_open_element(writer
, config_element_trackers
);
1133 int mi_lttng_pid_tracker_open(struct mi_writer
*writer
)
1137 /* Open element pid_tracker */
1138 ret
= mi_lttng_writer_open_element(writer
, config_element_pid_tracker
);
1143 /* Open targets element */
1144 ret
= mi_lttng_targets_open(writer
);
1150 int mi_lttng_pids_open(struct mi_writer
*writer
)
1152 return mi_lttng_writer_open_element(writer
, config_element_pids
);
1156 * TODO: move the listing of pid for user agent to process semantic on
1157 * mi api bump. The use of process element break the mi api.
1160 int mi_lttng_pid(struct mi_writer
*writer
, pid_t pid
, const char *name
,
1165 /* Open pid process */
1166 ret
= mi_lttng_writer_open_element(writer
, config_element_pid
);
1171 /* Writing pid number */
1172 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1173 mi_lttng_element_pid_id
, (int)pid
);
1178 /* Writing name of the process */
1180 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1189 ret
= mi_lttng_writer_close_element(writer
);
1197 int mi_lttng_targets_open(struct mi_writer
*writer
)
1199 return mi_lttng_writer_open_element(writer
,
1200 config_element_targets
);
1204 int mi_lttng_pid_target(struct mi_writer
*writer
, pid_t pid
, int is_open
)
1208 ret
= mi_lttng_writer_open_element(writer
,
1209 config_element_target_pid
);
1214 /* Writing pid number
1215 * Special case for element all on track untrack command
1216 * All pid is represented as wildcard *
1218 if ((int) pid
== -1) {
1219 ret
= mi_lttng_writer_write_element_string(writer
,
1221 mi_lttng_element_track_untrack_all_wildcard
);
1223 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1224 config_element_pid
, (int) pid
);
1231 ret
= mi_lttng_writer_close_element(writer
);
1242 int mi_lttng_event_fields_open(struct mi_writer
*writer
)
1244 return mi_lttng_writer_open_element(writer
, mi_lttng_element_event_fields
);
1248 int mi_lttng_event_field(struct mi_writer
*writer
,
1249 struct lttng_event_field
*field
)
1253 if (!field
->field_name
[0]) {
1259 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_event_field
);
1264 if (!field
->field_name
[0]) {
1269 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1276 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1277 mi_lttng_eventfieldtype_string(field
->type
));
1283 ret
= mi_lttng_writer_write_element_signed_int(writer
,
1284 mi_lttng_element_nowrite
, field
->nowrite
);
1290 /* Close field element */
1291 ret
= mi_lttng_writer_close_element(writer
);
1298 int mi_lttng_calibrate(struct mi_writer
*writer
,
1299 struct lttng_calibrate
*calibrate
)
1303 /* Open calibrate element */
1304 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_calibrate
);
1309 /* Calibration type */
1310 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1311 mi_lttng_calibratetype_string(calibrate
->type
));
1316 /* Closing calibrate element */
1317 ret
= mi_lttng_writer_close_element(writer
);
1323 int mi_lttng_context(struct mi_writer
*writer
,
1324 struct lttng_event_context
*context
, int is_open
)
1327 const char *type_string
;
1328 struct lttng_event_perf_counter_ctx
*perf_context
;
1330 ret
= mi_lttng_writer_open_element(writer
, config_element_context
);
1335 type_string
= mi_lttng_event_contexttype_string(context
->ctx
);
1337 ret
= -LTTNG_ERR_INVALID
;
1341 /* Print context type */
1342 ret
= mi_lttng_writer_write_element_string(writer
, config_element_type
,
1345 /* Special case for PERF_*_COUNTER
1346 * print the lttng_event_perf_counter_ctx*/
1347 switch (context
->ctx
) {
1348 case LTTNG_EVENT_CONTEXT_PERF_COUNTER
:
1349 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
1350 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER
:
1351 perf_context
= &context
->u
.perf_counter
;
1352 ret
= mi_lttng_perf_counter_context(writer
, perf_context
);
1363 ret
= mi_lttng_writer_close_element(writer
);
1371 int mi_lttng_perf_counter_context(struct mi_writer
*writer
,
1372 struct lttng_event_perf_counter_ctx
*perf_context
)
1376 /* Open perf_counter_context */
1377 ret
= mi_lttng_writer_open_element(writer
,
1378 mi_lttng_element_perf_counter_context
);
1384 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1385 config_element_type
, perf_context
->type
);
1391 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1392 config_element_config
, perf_context
->config
);
1397 /* Name of the perf counter */
1398 ret
= mi_lttng_writer_write_element_string(writer
,
1399 config_element_name
, perf_context
->name
);
1404 /* Close perf_counter_context */
1405 ret
= mi_lttng_writer_close_element(writer
);
1411 int mi_lttng_snapshot_output_session_name(struct mi_writer
*writer
,
1412 const char *session_name
)
1416 /* Open session element */
1417 ret
= mi_lttng_writer_open_element(writer
, config_element_session
);
1422 /* Snapshot output list for current session name */
1423 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1429 /* Open element snapshots (sequence one snapshot) */
1430 ret
= mi_lttng_writer_open_element(writer
, mi_lttng_element_snapshots
);
1440 int mi_lttng_snapshot_list_output(struct mi_writer
*writer
,
1441 struct lttng_snapshot_output
*output
)
1445 /* Open element snapshot output */
1446 ret
= mi_lttng_writer_open_element(writer
,
1447 mi_lttng_element_command_snapshot
);
1452 /* ID of the snapshot output */
1453 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1454 mi_lttng_element_id
, output
->id
);
1459 /* Name of the output */
1460 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1466 /* Destination of the output (ctrl_url)*/
1467 ret
= mi_lttng_writer_write_element_string(writer
,
1468 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1473 /* Destination of the output (data_url) */
1474 ret
= mi_lttng_writer_write_element_string(writer
,
1475 mi_lttng_element_snapshot_data_url
, output
->data_url
);
1480 /* total size of all stream combined */
1481 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1482 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1487 /* Close snapshot output element */
1488 ret
= mi_lttng_writer_close_element(writer
);
1495 int mi_lttng_snapshot_del_output(struct mi_writer
*writer
, int id
,
1496 const char *name
, const char *current_session_name
)
1500 /* Open element del_snapshot */
1501 ret
= mi_lttng_writer_open_element(writer
,
1502 mi_lttng_element_command_snapshot
);
1508 if (id
!= UINT32_MAX
) {
1509 /* "Snapshot output "id" successfully deleted
1510 * for "current_session_name"
1511 * ID of the snapshot output
1513 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1514 mi_lttng_element_id
, id
);
1519 /* "Snapshot output "name" successfully deleted
1520 * for session "current_session_name"
1521 * Name of the output
1523 ret
= mi_lttng_writer_write_element_string(writer
, config_element_name
,
1530 /* Snapshot was deleted for session "current_session_name"*/
1531 ret
= mi_lttng_writer_write_element_string(writer
,
1532 mi_lttng_element_snapshot_session_name
,
1533 current_session_name
);
1538 /* Close snapshot element */
1539 ret
= mi_lttng_writer_close_element(writer
);
1546 int mi_lttng_snapshot_add_output(struct mi_writer
*writer
,
1547 const char *current_session_name
, const char *n_ptr
,
1548 struct lttng_snapshot_output
*output
)
1552 /* Open element snapshot */
1553 ret
= mi_lttng_writer_open_element(writer
,
1554 mi_lttng_element_command_snapshot
);
1559 /* Snapshot output id */
1560 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1561 mi_lttng_element_id
, output
->id
);
1566 /* Snapshot output names */
1567 ret
= mi_lttng_writer_write_element_string(writer
,
1568 config_element_name
, n_ptr
);
1573 /* Destination of the output (ctrl_url)*/
1574 ret
= mi_lttng_writer_write_element_string(writer
,
1575 mi_lttng_element_snapshot_ctrl_url
, output
->ctrl_url
);
1580 /* Snapshot added for session "current_session_name"*/
1581 ret
= mi_lttng_writer_write_element_string(writer
,
1582 mi_lttng_element_snapshot_session_name
, current_session_name
);
1587 /* total size of all stream combined */
1588 ret
= mi_lttng_writer_write_element_unsigned_int(writer
,
1589 mi_lttng_element_snapshot_max_size
, output
->max_size
);
1594 /* Close snapshot element */
1595 ret
= mi_lttng_writer_close_element(writer
);
1602 int mi_lttng_snapshot_record(struct mi_writer
*writer
,
1603 const char *current_session_name
, const char *url
,
1604 const char *cmdline_ctrl_url
, const char *cmdline_data_url
)
1608 /* Open element snapshot */
1609 ret
= mi_lttng_writer_open_element(writer
,
1610 mi_lttng_element_command_snapshot
);
1616 * If a valid an URL was given, serialize it,
1617 * else take the command line data and ctrl urls*/
1619 /* Destination of the output (ctrl_url)*/
1620 ret
= mi_lttng_writer_write_element_string(writer
,
1621 mi_lttng_element_snapshot_ctrl_url
, url
);
1625 } else if (cmdline_ctrl_url
) {
1626 /* Destination of the output (ctrl_url)*/
1627 ret
= mi_lttng_writer_write_element_string(writer
,
1628 mi_lttng_element_snapshot_ctrl_url
, cmdline_ctrl_url
);
1633 /* Destination of the output (data_url) */
1634 ret
= mi_lttng_writer_write_element_string(writer
,
1635 mi_lttng_element_snapshot_data_url
, cmdline_data_url
);
1641 /* Close record_snapshot element */
1642 ret
= mi_lttng_writer_close_element(writer
);