rotation-api: pass session name explicitly
[lttng-tools.git] / src / common / mi-lttng.c
CommitLineData
c7e35b03
JR
1/*
2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
e10b6a1c 4 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
c7e35b03
JR
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License, version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
6c1c0768 20#define _LGPL_SOURCE
f40ef1d5 21#include <common/config/session-config.h>
41af1adf 22#include <common/defaults.h>
50534d6f 23#include <lttng/snapshot-internal.h>
fb83fe64 24#include <lttng/channel.h>
c7e35b03
JR
25#include "mi-lttng.h"
26
5e18ec73
JR
27#include <assert.h>
28
e10b6a1c
JG
29#define MI_SCHEMA_MAJOR_VERSION 3
30#define MI_SCHEMA_MINOR_VERSION 0
31
32/* Machine interface namespace URI */
c8ecdbb0
JG
33LTTNG_HIDDEN const char * const mi_lttng_xmlns = "xmlns";
34LTTNG_HIDDEN const char * const mi_lttng_xmlns_xsi = "xmlns:xsi";
35LTTNG_HIDDEN const char * const mi_lttng_w3_schema_uri = "http://www.w3.org/2001/XMLSchema-instance";
36LTTNG_HIDDEN const char * const mi_lttng_schema_location = "xsi:schemaLocation";
37LTTNG_HIDDEN const char * const mi_lttng_schema_location_uri =
41af1adf 38 DEFAULT_LTTNG_MI_NAMESPACE " "
a18d9544 39 "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION)
e10b6a1c
JG
40 "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION) "."
41 XSTR(MI_SCHEMA_MINOR_VERSION) ".xsd";
c8ecdbb0
JG
42LTTNG_HIDDEN const char * const mi_lttng_schema_version = "schemaVersion";
43LTTNG_HIDDEN const char * const mi_lttng_schema_version_value = XSTR(MI_SCHEMA_MAJOR_VERSION)
e10b6a1c
JG
44 "." XSTR(MI_SCHEMA_MINOR_VERSION);
45
c7e35b03
JR
46/* Strings related to command */
47const char * const mi_lttng_element_command = "command";
f4a088f7
JRJ
48const char * const mi_lttng_element_command_action = "snapshot_action";
49const char * const mi_lttng_element_command_add_context = "add-context";
f4a088f7
JRJ
50const char * const mi_lttng_element_command_create = "create";
51const char * const mi_lttng_element_command_destroy = "destroy";
52const char * const mi_lttng_element_command_disable_channel = "disable-channel";
53const char * const mi_lttng_element_command_disable_event = "disable-event";
54const char * const mi_lttng_element_command_enable_channels = "enable-channel";
89476427 55const char * const mi_lttng_element_command_enable_event = "enable-event";
c7e35b03 56const char * const mi_lttng_element_command_list = "list";
1734c658 57const char * const mi_lttng_element_command_load = "load";
c8ecdbb0
JG
58LTTNG_HIDDEN const char * const mi_lttng_element_command_metadata = "metadata";
59LTTNG_HIDDEN const char * const mi_lttng_element_command_metadata_action = "metadata_action";
eded6438
JD
60LTTNG_HIDDEN const char * const mi_lttng_element_command_regenerate = "regenerate";
61LTTNG_HIDDEN const char * const mi_lttng_element_command_regenerate_action = "regenerate_action";
f4a088f7
JRJ
62const char * const mi_lttng_element_command_name = "name";
63const char * const mi_lttng_element_command_output = "output";
64const char * const mi_lttng_element_command_save = "save";
65const char * const mi_lttng_element_command_set_session = "set-session";
66const char * const mi_lttng_element_command_snapshot = "snapshot";
67const char * const mi_lttng_element_command_snapshot_add = "add_snapshot";
68const char * const mi_lttng_element_command_snapshot_del = "del_snapshot";
69const char * const mi_lttng_element_command_snapshot_list = "list_snapshot";
70const char * const mi_lttng_element_command_snapshot_record = "record_snapshot";
1cfc0bc8 71const char * const mi_lttng_element_command_start = "start";
e5b83100 72const char * const mi_lttng_element_command_stop = "stop";
1734c658 73const char * const mi_lttng_element_command_success = "success";
ccf10263
MD
74const char * const mi_lttng_element_command_track = "track";
75const char * const mi_lttng_element_command_untrack = "untrack";
f4a088f7 76const char * const mi_lttng_element_command_version = "version";
d68c9a04 77const char * const mi_lttng_element_command_rotate = "rotate";
259c2674
JD
78const char * const mi_lttng_element_command_enable_rotation = "enable-rotation";
79const char * const mi_lttng_element_command_disable_rotation = "disable-rotation";
c7e35b03 80
1734c658 81/* Strings related to version command */
c7e35b03 82const char * const mi_lttng_element_version = "version";
314d5222 83const char * const mi_lttng_element_version_commit = "commit";
f4a088f7 84const char * const mi_lttng_element_version_description = "description";
c7e35b03 85const char * const mi_lttng_element_version_license = "license";
f4a088f7
JRJ
86const char * const mi_lttng_element_version_major = "major";
87const char * const mi_lttng_element_version_minor = "minor";
c7e35b03 88const char * const mi_lttng_element_version_patch_level = "patchLevel";
f4a088f7
JRJ
89const char * const mi_lttng_element_version_str = "string";
90const char * const mi_lttng_element_version_web = "url";
1734c658 91
5e18ec73
JR
92/* String related to a lttng_event_field */
93const char * const mi_lttng_element_event_field = "event_field";
94const char * const mi_lttng_element_event_fields = "event_fields";
95
89b72577 96/* String related to lttng_event_perf_counter_ctx */
a23cb78a 97const char * const mi_lttng_element_perf_counter_context = "perf";
89b72577 98
f4a088f7 99/* Strings related to pid */
bf239d4c 100const char * const mi_lttng_element_pid_id = "id";
f4a088f7
JRJ
101
102/* Strings related to save command */
103const char * const mi_lttng_element_save = "save";
104
105/* Strings related to load command */
106const char * const mi_lttng_element_load = "load";
23cb2d55
JR
107LTTNG_HIDDEN const char * const mi_lttng_element_load_overrides = "overrides";
108LTTNG_HIDDEN const char * const mi_lttng_element_load_override_url = "url";
f4a088f7 109
5e18ec73 110/* General elements of mi_lttng */
f4a088f7
JRJ
111const char * const mi_lttng_element_empty = "";
112const char * const mi_lttng_element_id = "id";
113const char * const mi_lttng_element_nowrite = "nowrite";
114const char * const mi_lttng_element_success = "success";
5e18ec73
JR
115const char * const mi_lttng_element_type_enum = "ENUM";
116const char * const mi_lttng_element_type_float = "FLOAT";
f4a088f7
JRJ
117const char * const mi_lttng_element_type_integer = "INTEGER";
118const char * const mi_lttng_element_type_other = "OTHER";
5e18ec73 119const char * const mi_lttng_element_type_string = "STRING";
5e18ec73
JR
120
121/* String related to loglevel */
122const char * const mi_lttng_loglevel_str_alert = "TRACE_ALERT";
123const char * const mi_lttng_loglevel_str_crit = "TRACE_CRIT";
124const char * const mi_lttng_loglevel_str_debug = "TRACE_DEBUG";
125const char * const mi_lttng_loglevel_str_debug_function = "TRACE_DEBUG_FUNCTION";
126const char * const mi_lttng_loglevel_str_debug_line = "TRACE_DEBUG_LINE";
127const char * const mi_lttng_loglevel_str_debug_module = "TRACE_DEBUG_MODULE";
128const char * const mi_lttng_loglevel_str_debug_process = "TRACE_DEBUG_PROCESS";
129const char * const mi_lttng_loglevel_str_debug_program = "TRACE_DEBUG_PROGRAM";
130const char * const mi_lttng_loglevel_str_debug_system = "TRACE_DEBUG_SYSTEM";
131const char * const mi_lttng_loglevel_str_debug_unit = "TRACE_DEBUG_UNIT";
132const char * const mi_lttng_loglevel_str_emerg = "TRACE_EMERG";
133const char * const mi_lttng_loglevel_str_err = "TRACE_ERR";
134const char * const mi_lttng_loglevel_str_info = "TRACE_INFO";
135const char * const mi_lttng_loglevel_str_notice = "TRACE_NOTICE";
136const char * const mi_lttng_loglevel_str_unknown = "UNKNOWN";
137const char * const mi_lttng_loglevel_str_warning = "TRACE_WARNING";
138
136f2f81
JRJ
139/* String related to loglevel JUL */
140const char * const mi_lttng_loglevel_str_jul_all = "JUL_ALL";
141const char * const mi_lttng_loglevel_str_jul_config = "JUL_CONFIG";
142const char * const mi_lttng_loglevel_str_jul_fine = "JUL_FINE";
143const char * const mi_lttng_loglevel_str_jul_finer = "JUL_FINER";
144const char * const mi_lttng_loglevel_str_jul_finest = "JUL_FINEST";
145const char * const mi_lttng_loglevel_str_jul_info = "JUL_INFO";
146const char * const mi_lttng_loglevel_str_jul_off = "JUL_OFF";
147const char * const mi_lttng_loglevel_str_jul_severe = "JUL_SEVERE";
148const char * const mi_lttng_loglevel_str_jul_warning = "JUL_WARNING";
149
970d848b
DG
150/* String related to loglevel LOG4J */
151const char * const mi_lttng_loglevel_str_log4j_off = "LOG4J_OFF";
152const char * const mi_lttng_loglevel_str_log4j_fatal = "LOG4J_FATAL";
153const char * const mi_lttng_loglevel_str_log4j_error = "LOG4J_ERROR";
154const char * const mi_lttng_loglevel_str_log4j_warn = "LOG4J_WARN";
155const char * const mi_lttng_loglevel_str_log4j_info = "LOG4J_INFO";
156const char * const mi_lttng_loglevel_str_log4j_debug = "LOG4J_DEBUG";
157const char * const mi_lttng_loglevel_str_log4j_trace = "LOG4J_TRACE";
158const char * const mi_lttng_loglevel_str_log4j_all = "LOG4J_ALL";
159
0e115563
DG
160/* String related to loglevel Python */
161const char * const mi_lttng_loglevel_str_python_critical = "PYTHON_CRITICAL";
162const char * const mi_lttng_loglevel_str_python_error = "PYTHON_ERROR";
163const char * const mi_lttng_loglevel_str_python_warning = "PYTHON_WARNING";
164const char * const mi_lttng_loglevel_str_python_info = "PYTHON_INFO";
165const char * const mi_lttng_loglevel_str_python_debug = "PYTHON_DEBUG";
166const char * const mi_lttng_loglevel_str_python_notset = "PYTHON_NOTSET";
167
1734c658 168/* String related to loglevel type */
5e18ec73
JR
169const char * const mi_lttng_loglevel_type_all = "ALL";
170const char * const mi_lttng_loglevel_type_range = "RANGE";
171const char * const mi_lttng_loglevel_type_single = "SINGLE";
172const char * const mi_lttng_loglevel_type_unknown = "UNKNOWN";
173
50534d6f 174/* String related to a lttng_snapshot_output */
50534d6f 175const char * const mi_lttng_element_snapshot_ctrl_url = "ctrl_url";
f4a088f7 176const char * const mi_lttng_element_snapshot_data_url = "data_url";
50534d6f 177const char * const mi_lttng_element_snapshot_max_size = "max_size";
f4a088f7
JRJ
178const char * const mi_lttng_element_snapshot_n_ptr = "n_ptr";
179const char * const mi_lttng_element_snapshot_session_name = "session_name";
180const char * const mi_lttng_element_snapshots = "snapshots";
5e18ec73 181
ebbf5ab7 182/* String related to track/untrack command */
ebbf5ab7
JR
183const char * const mi_lttng_element_track_untrack_all_wildcard = "*";
184
d68c9a04
JD
185LTTNG_HIDDEN const char * const mi_lttng_element_session_name = "session_name";
186
187/* String related to rotate command */
188LTTNG_HIDDEN const char * const mi_lttng_element_rotation = "rotation";
189LTTNG_HIDDEN const char * const mi_lttng_element_rotations = "rotations";
190LTTNG_HIDDEN const char * const mi_lttng_element_rotate_status = "status";
259c2674 191LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule = "rotation_schedule";
d68c9a04 192
59deec0c
JR
193/* String related to add-context command */
194LTTNG_HIDDEN const char * const mi_lttng_element_context_symbol = "symbol";
195
ae8c46e0
JG
196/* Deprecated symbols preserved for ABI compatibility. */
197const char * const mi_lttng_context_type_perf_counter;
198const char * const mi_lttng_context_type_perf_cpu_counter;
199const char * const mi_lttng_context_type_perf_thread_counter;
200const char * const mi_lttng_element_track_untrack_pid_target;
201const char * const mi_lttng_element_track_untrack_targets;
95057847
PP
202const char * const mi_lttng_element_calibrate;
203const char * const mi_lttng_element_calibrate_function;
204const char * const mi_lttng_element_command_calibrate;
ebbf5ab7 205
136f2f81
JRJ
206/* This is a merge of jul loglevel and regular loglevel
207 * Those should never overlap by definition
208 * (see struct lttng_event loglevel)
209 */
ea75976a 210LTTNG_HIDDEN
970d848b 211const char *mi_lttng_loglevel_string(int value, enum lttng_domain_type domain)
5e18ec73 212{
970d848b
DG
213 switch (domain) {
214 case LTTNG_DOMAIN_KERNEL:
215 case LTTNG_DOMAIN_UST:
216 switch (value) {
217 case -1:
218 return mi_lttng_element_empty;
219 case LTTNG_LOGLEVEL_EMERG:
220 return mi_lttng_loglevel_str_emerg;
221 case LTTNG_LOGLEVEL_ALERT:
222 return mi_lttng_loglevel_str_alert;
223 case LTTNG_LOGLEVEL_CRIT:
224 return mi_lttng_loglevel_str_crit;
225 case LTTNG_LOGLEVEL_ERR:
226 return mi_lttng_loglevel_str_err;
227 case LTTNG_LOGLEVEL_WARNING:
228 return mi_lttng_loglevel_str_warning;
229 case LTTNG_LOGLEVEL_NOTICE:
230 return mi_lttng_loglevel_str_notice;
231 case LTTNG_LOGLEVEL_INFO:
232 return mi_lttng_loglevel_str_info;
233 case LTTNG_LOGLEVEL_DEBUG_SYSTEM:
234 return mi_lttng_loglevel_str_debug_system;
235 case LTTNG_LOGLEVEL_DEBUG_PROGRAM:
236 return mi_lttng_loglevel_str_debug_program;
237 case LTTNG_LOGLEVEL_DEBUG_PROCESS:
238 return mi_lttng_loglevel_str_debug_process;
239 case LTTNG_LOGLEVEL_DEBUG_MODULE:
240 return mi_lttng_loglevel_str_debug_module;
241 case LTTNG_LOGLEVEL_DEBUG_UNIT:
242 return mi_lttng_loglevel_str_debug_unit;
243 case LTTNG_LOGLEVEL_DEBUG_FUNCTION:
244 return mi_lttng_loglevel_str_debug_function;
245 case LTTNG_LOGLEVEL_DEBUG_LINE:
246 return mi_lttng_loglevel_str_debug_line;
247 case LTTNG_LOGLEVEL_DEBUG:
248 return mi_lttng_loglevel_str_debug;
249 default:
250 return mi_lttng_loglevel_str_unknown;
251 }
252 break;
253 case LTTNG_DOMAIN_LOG4J:
254 switch (value) {
255 case -1:
256 return mi_lttng_element_empty;
257 case LTTNG_LOGLEVEL_LOG4J_OFF:
258 return mi_lttng_loglevel_str_log4j_off;
259 case LTTNG_LOGLEVEL_LOG4J_FATAL:
260 return mi_lttng_loglevel_str_log4j_fatal;
261 case LTTNG_LOGLEVEL_LOG4J_ERROR:
262 return mi_lttng_loglevel_str_log4j_error;
263 case LTTNG_LOGLEVEL_LOG4J_WARN:
264 return mi_lttng_loglevel_str_log4j_warn;
265 case LTTNG_LOGLEVEL_LOG4J_INFO:
266 return mi_lttng_loglevel_str_log4j_info;
267 case LTTNG_LOGLEVEL_LOG4J_DEBUG:
268 return mi_lttng_loglevel_str_log4j_debug;
269 case LTTNG_LOGLEVEL_LOG4J_TRACE:
270 return mi_lttng_loglevel_str_log4j_trace;
271 case LTTNG_LOGLEVEL_LOG4J_ALL:
272 return mi_lttng_loglevel_str_log4j_all;
273 default:
274 return mi_lttng_loglevel_str_unknown;
275 }
276 break;
277 case LTTNG_DOMAIN_JUL:
278 switch (value) {
279 case -1:
280 return mi_lttng_element_empty;
281 case LTTNG_LOGLEVEL_JUL_OFF:
282 return mi_lttng_loglevel_str_jul_off;
283 case LTTNG_LOGLEVEL_JUL_SEVERE:
284 return mi_lttng_loglevel_str_jul_severe;
285 case LTTNG_LOGLEVEL_JUL_WARNING:
286 return mi_lttng_loglevel_str_jul_warning;
287 case LTTNG_LOGLEVEL_JUL_INFO:
288 return mi_lttng_loglevel_str_jul_info;
289 case LTTNG_LOGLEVEL_JUL_CONFIG:
290 return mi_lttng_loglevel_str_jul_config;
291 case LTTNG_LOGLEVEL_JUL_FINE:
292 return mi_lttng_loglevel_str_jul_fine;
293 case LTTNG_LOGLEVEL_JUL_FINER:
294 return mi_lttng_loglevel_str_jul_finer;
295 case LTTNG_LOGLEVEL_JUL_FINEST:
296 return mi_lttng_loglevel_str_jul_finest;
297 case LTTNG_LOGLEVEL_JUL_ALL:
298 return mi_lttng_loglevel_str_jul_all;
299 default:
300 return mi_lttng_loglevel_str_unknown;
301 }
302 break;
0e115563
DG
303 case LTTNG_DOMAIN_PYTHON:
304 switch (value) {
305 case LTTNG_LOGLEVEL_PYTHON_CRITICAL:
306 return mi_lttng_loglevel_str_python_critical;
307 case LTTNG_LOGLEVEL_PYTHON_ERROR:
308 return mi_lttng_loglevel_str_python_error;
309 case LTTNG_LOGLEVEL_PYTHON_WARNING:
310 return mi_lttng_loglevel_str_python_warning;
311 case LTTNG_LOGLEVEL_PYTHON_INFO:
312 return mi_lttng_loglevel_str_python_info;
313 case LTTNG_LOGLEVEL_PYTHON_DEBUG:
314 return mi_lttng_loglevel_str_python_debug;
315 case LTTNG_LOGLEVEL_PYTHON_NOTSET:
316 return mi_lttng_loglevel_str_python_notset;
317 default:
318 return mi_lttng_loglevel_str_unknown;
319 }
320 break;
bc2718d1
JG
321 default:
322 return mi_lttng_loglevel_str_unknown;
5e18ec73
JR
323 }
324}
325
ea75976a 326LTTNG_HIDDEN
5e18ec73
JR
327const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value)
328{
329 switch (value) {
330 case LTTNG_EVENT_LOGLEVEL_ALL:
331 return mi_lttng_loglevel_type_all;
332 case LTTNG_EVENT_LOGLEVEL_RANGE:
333 return mi_lttng_loglevel_type_range;
334 case LTTNG_EVENT_LOGLEVEL_SINGLE:
335 return mi_lttng_loglevel_type_single;
336 default:
337 return mi_lttng_loglevel_type_unknown;
338 }
339}
340
ea75976a 341LTTNG_HIDDEN
5e18ec73
JR
342const char *mi_lttng_eventtype_string(enum lttng_event_type value)
343{
344 switch (value) {
345 case LTTNG_EVENT_ALL:
346 return config_event_type_all;
347 case LTTNG_EVENT_TRACEPOINT:
348 return config_event_type_tracepoint;
349 case LTTNG_EVENT_PROBE:
350 return config_event_type_probe;
351 case LTTNG_EVENT_FUNCTION:
352 return config_event_type_function;
353 case LTTNG_EVENT_FUNCTION_ENTRY:
354 return config_event_type_function_entry;
355 case LTTNG_EVENT_SYSCALL:
356 return config_event_type_syscall;
357 case LTTNG_EVENT_NOOP:
358 return config_event_type_noop;
359 default:
360 return mi_lttng_element_empty;
361 }
362}
363
a23cb78a 364static
89b72577
JRJ
365const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val)
366{
367 switch (val) {
368 case LTTNG_EVENT_CONTEXT_PID:
369 return config_event_context_pid;
89b72577
JRJ
370 case LTTNG_EVENT_CONTEXT_PROCNAME:
371 return config_event_context_procname;
372 case LTTNG_EVENT_CONTEXT_PRIO:
373 return config_event_context_prio;
374 case LTTNG_EVENT_CONTEXT_NICE:
375 return config_event_context_nice;
376 case LTTNG_EVENT_CONTEXT_VPID:
377 return config_event_context_vpid;
378 case LTTNG_EVENT_CONTEXT_TID:
379 return config_event_context_tid;
380 case LTTNG_EVENT_CONTEXT_VTID:
381 return config_event_context_vtid;
382 case LTTNG_EVENT_CONTEXT_PPID:
383 return config_event_context_ppid;
384 case LTTNG_EVENT_CONTEXT_VPPID:
385 return config_event_context_vppid;
386 case LTTNG_EVENT_CONTEXT_PTHREAD_ID:
387 return config_event_context_pthread_id;
388 case LTTNG_EVENT_CONTEXT_HOSTNAME:
389 return config_event_context_hostname;
390 case LTTNG_EVENT_CONTEXT_IP:
391 return config_event_context_ip;
a72332c3
JR
392 case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE:
393 return config_event_context_interruptible;
394 case LTTNG_EVENT_CONTEXT_PREEMPTIBLE:
395 return config_event_context_preemptible;
396 case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE:
397 return config_event_context_need_reschedule;
398 case LTTNG_EVENT_CONTEXT_MIGRATABLE:
399 return config_event_context_migratable;
16c4c991
FD
400 case LTTNG_EVENT_CONTEXT_CALLSTACK_USER:
401 return config_event_context_callstack_user;
402 case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL:
403 return config_event_context_callstack_kernel;
89b72577
JRJ
404 default:
405 return NULL;
406 }
407}
408
ea75976a 409LTTNG_HIDDEN
5e18ec73
JR
410const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val)
411{
412 switch (val) {
413 case(LTTNG_EVENT_FIELD_INTEGER):
414 return mi_lttng_element_type_integer;
415 case(LTTNG_EVENT_FIELD_ENUM):
416 return mi_lttng_element_type_enum;
417 case(LTTNG_EVENT_FIELD_FLOAT):
418 return mi_lttng_element_type_float;
419 case(LTTNG_EVENT_FIELD_STRING):
420 return mi_lttng_element_type_string;
421 default:
422 return mi_lttng_element_type_other;
423 }
424}
425
ea75976a 426LTTNG_HIDDEN
5e18ec73
JR
427const char *mi_lttng_domaintype_string(enum lttng_domain_type value)
428{
429 /* Note: This is a *duplicate* of get_domain_str from bin/lttng/utils.c */
430 switch (value) {
431 case LTTNG_DOMAIN_KERNEL:
432 return config_domain_type_kernel;
433 case LTTNG_DOMAIN_UST:
434 return config_domain_type_ust;
435 case LTTNG_DOMAIN_JUL:
436 return config_domain_type_jul;
5cdb6027
DG
437 case LTTNG_DOMAIN_LOG4J:
438 return config_domain_type_log4j;
b789735e
PP
439 case LTTNG_DOMAIN_PYTHON:
440 return config_domain_type_python;
5e18ec73
JR
441 default:
442 /* Should not have an unknown domain */
443 assert(0);
2855532e 444 return NULL;
5e18ec73
JR
445 }
446}
447
ea75976a 448LTTNG_HIDDEN
5e18ec73
JR
449const char *mi_lttng_buffertype_string(enum lttng_buffer_type value)
450{
451 switch (value) {
452 case LTTNG_BUFFER_PER_PID:
453 return config_buffer_type_per_pid;
454 case LTTNG_BUFFER_PER_UID:
455 return config_buffer_type_per_uid;
456 case LTTNG_BUFFER_GLOBAL:
457 return config_buffer_type_global;
458 default:
459 /* Should not have an unknow buffer type */
460 assert(0);
2855532e 461 return NULL;
5e18ec73
JR
462 }
463}
464
c7e35b03
JR
465LTTNG_HIDDEN
466struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type)
467{
468 struct mi_writer *mi_writer;
469
470 mi_writer = zmalloc(sizeof(struct mi_writer));
471 if (!mi_writer) {
472 PERROR("zmalloc mi_writer_create");
473 goto end;
474 }
475 if (mi_output_type == LTTNG_MI_XML) {
705bb62f 476 mi_writer->writer = config_writer_create(fd_output, 0);
c7e35b03
JR
477 if (!mi_writer->writer) {
478 goto err_destroy;
479 }
480 mi_writer->type = LTTNG_MI_XML;
481 } else {
482 goto err_destroy;
483 }
484
485end:
486 return mi_writer;
487
488err_destroy:
489 free(mi_writer);
490 return NULL;
491}
492
493LTTNG_HIDDEN
494int mi_lttng_writer_destroy(struct mi_writer *writer)
495{
496 int ret;
497
498 if (!writer) {
499 ret = -EINVAL;
500 goto end;
501 }
502
503 ret = config_writer_destroy(writer->writer);
504 if (ret < 0) {
505 goto end;
506 }
507
508 free(writer);
509end:
510 return ret;
511}
512
513LTTNG_HIDDEN
514int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command)
515{
516 int ret;
517
e10b6a1c
JG
518 /*
519 * A command is always the MI's root node, it must declare the current
520 * namespace and schema URIs and the schema's version.
521 */
522 ret = config_writer_open_element(writer->writer,
523 mi_lttng_element_command);
524 if (ret) {
525 goto end;
526 }
527
528 ret = config_writer_write_attribute(writer->writer,
41af1adf 529 mi_lttng_xmlns, DEFAULT_LTTNG_MI_NAMESPACE);
e10b6a1c
JG
530 if (ret) {
531 goto end;
532 }
533
534 ret = config_writer_write_attribute(writer->writer,
535 mi_lttng_xmlns_xsi, mi_lttng_w3_schema_uri);
c7e35b03
JR
536 if (ret) {
537 goto end;
538 }
e10b6a1c
JG
539
540 ret = config_writer_write_attribute(writer->writer,
541 mi_lttng_schema_location,
542 mi_lttng_schema_location_uri);
543 if (ret) {
544 goto end;
545 }
546
547 ret = config_writer_write_attribute(writer->writer,
548 mi_lttng_schema_version,
549 mi_lttng_schema_version_value);
550 if (ret) {
551 goto end;
552 }
553
c7e35b03
JR
554 ret = mi_lttng_writer_write_element_string(writer,
555 mi_lttng_element_command_name, command);
556end:
557 return ret;
558}
559
560LTTNG_HIDDEN
561int mi_lttng_writer_command_close(struct mi_writer *writer)
562{
563 return mi_lttng_writer_close_element(writer);
564}
565
566LTTNG_HIDDEN
567int mi_lttng_writer_open_element(struct mi_writer *writer,
568 const char *element_name)
569{
570 return config_writer_open_element(writer->writer, element_name);
571}
572
573LTTNG_HIDDEN
574int mi_lttng_writer_close_element(struct mi_writer *writer)
575{
576 return config_writer_close_element(writer->writer);
577}
578
5e18ec73
JR
579LTTNG_HIDDEN
580int mi_lttng_close_multi_element(struct mi_writer *writer,
581 unsigned int nb_element)
582{
583 int ret, i;
584
585 if (nb_element < 1) {
586 ret = 0;
587 goto end;
588 }
589 for (i = 0; i < nb_element; i++) {
590 ret = mi_lttng_writer_close_element(writer);
591 if (ret) {
592 goto end;
593 }
594 }
595end:
596 return ret;
597}
598
c7e35b03
JR
599LTTNG_HIDDEN
600int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer,
601 const char *element_name, uint64_t value)
602{
603 return config_writer_write_element_unsigned_int(writer->writer,
604 element_name, value);
605}
606
607LTTNG_HIDDEN
608int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer,
609 const char *element_name, int64_t value)
610{
611 return config_writer_write_element_signed_int(writer->writer,
612 element_name, value);
613}
614
615LTTNG_HIDDEN
616int mi_lttng_writer_write_element_bool(struct mi_writer *writer,
617 const char *element_name, int value)
618{
619 return config_writer_write_element_bool(writer->writer,
620 element_name, value);
621}
622
623LTTNG_HIDDEN
624int mi_lttng_writer_write_element_string(struct mi_writer *writer,
625 const char *element_name, const char *value)
626{
627 return config_writer_write_element_string(writer->writer,
628 element_name, value);
629}
630
631LTTNG_HIDDEN
632int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version,
633 const char *lttng_description, const char *lttng_license)
634{
635 int ret;
636
637 /* Open version */
638 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_version);
639 if (ret) {
640 goto end;
641 }
642
643 /* Version string (contain info like rc etc.) */
644 ret = mi_lttng_writer_write_element_string(writer,
782f3c61 645 mi_lttng_element_version_str, version->version);
c7e35b03
JR
646 if (ret) {
647 goto end;
648 }
649
650 /* Major version number */
651 ret = mi_lttng_writer_write_element_unsigned_int(writer,
652 mi_lttng_element_version_major, version->version_major);
653 if (ret) {
654 goto end;
655 }
656
657 /* Minor version number */
658 ret = mi_lttng_writer_write_element_unsigned_int(writer,
659 mi_lttng_element_version_minor, version->version_minor);
660 if (ret) {
661 goto end;
662 }
663
314d5222
JRJ
664 /* Commit version number */
665 ret = mi_lttng_writer_write_element_string(writer,
666 mi_lttng_element_version_commit, version->version_commit);
667 if (ret) {
668 goto end;
669 }
670
c7e35b03
JR
671 /* Patch number */
672 ret = mi_lttng_writer_write_element_unsigned_int(writer,
673 mi_lttng_element_version_patch_level, version->version_patchlevel);
674 if (ret) {
675 goto end;
676 }
677
678 /* Name of the version */
679 ret = mi_lttng_writer_write_element_string(writer,
680 config_element_name, version->version_name);
681 if (ret) {
682 goto end;
683 }
684
685 /* Description mostly related to beer... */
686 ret = mi_lttng_writer_write_element_string(writer,
687 mi_lttng_element_version_description, lttng_description);
688 if (ret) {
689 goto end;
690 }
691
692 /* url */
693 ret = mi_lttng_writer_write_element_string(writer,
694 mi_lttng_element_version_web, version->package_url);
695 if (ret) {
696 goto end;
697 }
698
699 /* License: free as in free beer...no...*speech* */
700 ret = mi_lttng_writer_write_element_string(writer,
701 mi_lttng_element_version_license, lttng_license);
702 if (ret) {
703 goto end;
704 }
705
706 /* Close version element */
707 ret = mi_lttng_writer_close_element(writer);
708
709end:
710 return ret;
711}
712
5e18ec73
JR
713LTTNG_HIDDEN
714int mi_lttng_sessions_open(struct mi_writer *writer)
715{
716 return mi_lttng_writer_open_element(writer, config_element_sessions);
717}
718
c7e35b03
JR
719LTTNG_HIDDEN
720int mi_lttng_session(struct mi_writer *writer,
721 struct lttng_session *session, int is_open)
722{
723 int ret;
724
5e18ec73
JR
725 assert(session);
726
727 /* Open sessions element */
c7e35b03
JR
728 ret = mi_lttng_writer_open_element(writer,
729 config_element_session);
730 if (ret) {
731 goto end;
732 }
733
734 /* Name of the session */
735 ret = mi_lttng_writer_write_element_string(writer,
736 config_element_name, session->name);
737 if (ret) {
738 goto end;
739 }
740
5e18ec73 741 /* Path */
c7e35b03
JR
742 ret = mi_lttng_writer_write_element_string(writer,
743 config_element_path, session->path);
744 if (ret) {
745 goto end;
746 }
747
5e18ec73
JR
748 /* Enabled ? */
749 ret = mi_lttng_writer_write_element_bool(writer,
c7e35b03
JR
750 config_element_enabled, session->enabled);
751 if (ret) {
752 goto end;
753 }
754
5e18ec73 755 /* Snapshot mode */
c7e35b03
JR
756 ret = mi_lttng_writer_write_element_unsigned_int(writer,
757 config_element_snapshot_mode, session->snapshot_mode);
758 if (ret) {
759 goto end;
760 }
761
5e18ec73 762 /* Live timer interval in usec */
c7e35b03
JR
763 ret = mi_lttng_writer_write_element_unsigned_int(writer,
764 config_element_live_timer_interval,
765 session->live_timer_interval);
766 if (ret) {
767 goto end;
768 }
769
770 if (!is_open) {
771 /* Closing session element */
772 ret = mi_lttng_writer_close_element(writer);
773 }
774end:
775 return ret;
776
777}
5e18ec73
JR
778
779LTTNG_HIDDEN
780int mi_lttng_domains_open(struct mi_writer *writer)
781{
782 return mi_lttng_writer_open_element(writer, config_element_domains);
783}
784
785LTTNG_HIDDEN
786int mi_lttng_domain(struct mi_writer *writer,
787 struct lttng_domain *domain, int is_open)
788{
789 int ret = 0;
790 const char *str_domain;
791 const char *str_buffer;
792
793 assert(domain);
794
795 /* Open domain element */
796 ret = mi_lttng_writer_open_element(writer, config_element_domain);
797 if (ret) {
798 goto end;
799 }
800
801 /* Domain Type */
802 str_domain = mi_lttng_domaintype_string(domain->type);
803 ret = mi_lttng_writer_write_element_string(writer, config_element_type,
804 str_domain);
805 if (ret) {
806 goto end;
807 }
808
809 /* Buffer Type */
810 str_buffer= mi_lttng_buffertype_string(domain->buf_type);
811 ret = mi_lttng_writer_write_element_string(writer,
812 config_element_buffer_type, str_buffer);
813 if (ret) {
814 goto end;
815 }
816
d813f89b
JRJ
817 /* TODO: union attr
818 * This union is not currently used and was added for
819 * future ust domain support.
820 * Date: 25-06-2014
821 * */
5e18ec73
JR
822
823 if (!is_open) {
824 /* Closing domain element */
825 ret = mi_lttng_writer_close_element(writer);
826 }
827
828end:
829 return ret;
830
831}
832
833LTTNG_HIDDEN
834int mi_lttng_channels_open(struct mi_writer *writer)
835{
836 return mi_lttng_writer_open_element(writer, config_element_channels);
837}
838
839LTTNG_HIDDEN
840int mi_lttng_channel(struct mi_writer *writer,
841 struct lttng_channel *channel, int is_open)
842{
843 int ret = 0;
844
845 assert(channel);
846
847 /* Opening channel element */
848 ret = mi_lttng_writer_open_element(writer, config_element_channel);
849 if (ret) {
850 goto end;
851 }
852
853 /* Name */
854 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
855 channel->name);
856 if (ret) {
857 goto end;
858 }
859
860 /* Enabled ? */
861 ret = mi_lttng_writer_write_element_bool(writer,
862 config_element_enabled, channel->enabled);
863 if (ret) {
864 goto end;
865 }
866
867 /* Attribute */
868 ret = mi_lttng_channel_attr(writer, &channel->attr);
869 if (ret) {
870 goto end;
871 }
872
873 if (!is_open) {
874 /* Closing channel element */
875 ret = mi_lttng_writer_close_element(writer);
876 if (ret) {
877 goto end;
878 }
879 }
880end:
881 return ret;
882}
883
884LTTNG_HIDDEN
885int mi_lttng_channel_attr(struct mi_writer *writer,
886 struct lttng_channel_attr *attr)
887{
888 int ret = 0;
fb83fe64
JD
889 struct lttng_channel *chan = caa_container_of(attr,
890 struct lttng_channel, attr);
cf0bcb51 891 uint64_t discarded_events, lost_packets, monitor_timer_interval;
491d1539 892 int64_t blocking_timeout;
5e18ec73
JR
893
894 assert(attr);
895
fb83fe64
JD
896 ret = lttng_channel_get_discarded_event_count(chan, &discarded_events);
897 if (ret) {
898 goto end;
899 }
900
901 ret = lttng_channel_get_lost_packet_count(chan, &lost_packets);
902 if (ret) {
903 goto end;
904 }
905
cf0bcb51
JG
906 ret = lttng_channel_get_monitor_timer_interval(chan,
907 &monitor_timer_interval);
908 if (ret) {
909 goto end;
910 }
911
491d1539
MD
912 ret = lttng_channel_get_blocking_timeout(chan,
913 &blocking_timeout);
914 if (ret) {
915 goto end;
916 }
917
5e18ec73
JR
918 /* Opening Attributes */
919 ret = mi_lttng_writer_open_element(writer, config_element_attributes);
920 if (ret) {
921 goto end;
922 }
923
924 /* Overwrite */
925 ret = mi_lttng_writer_write_element_string(writer,
926 config_element_overwrite_mode,
927 attr->overwrite ? config_overwrite_mode_overwrite :
928 config_overwrite_mode_discard);
929 if (ret) {
930 goto end;
931 }
932
933 /* Sub buffer size in byte */
934 ret = mi_lttng_writer_write_element_unsigned_int(writer,
935 config_element_subbuf_size, attr->subbuf_size);
936 if (ret) {
937 goto end;
938 }
939
940 /* Number of subbuffer (power of two) */
941 ret = mi_lttng_writer_write_element_unsigned_int(writer,
942 config_element_num_subbuf,
943 attr->num_subbuf);
944 if (ret) {
945 goto end;
946 }
947
948 /* Switch timer interval in usec */
949 ret = mi_lttng_writer_write_element_unsigned_int(writer,
950 config_element_switch_timer_interval,
951 attr->switch_timer_interval);
952 if (ret) {
953 goto end;
954 }
955
956 /* Read timer interval in usec */
957 ret = mi_lttng_writer_write_element_unsigned_int(writer,
958 config_element_read_timer_interval,
959 attr->read_timer_interval);
960 if (ret) {
961 goto end;
962 }
963
cf0bcb51
JG
964 /* Monitor timer interval in usec */
965 ret = mi_lttng_writer_write_element_unsigned_int(writer,
966 config_element_monitor_timer_interval,
967 monitor_timer_interval);
968 if (ret) {
969 goto end;
970 }
971
491d1539
MD
972 /* Retry timeout in usec */
973 ret = mi_lttng_writer_write_element_signed_int(writer,
974 config_element_blocking_timeout,
975 blocking_timeout);
976 if (ret) {
977 goto end;
978 }
979
5e18ec73
JR
980 /* Event output */
981 ret = mi_lttng_writer_write_element_string(writer,
982 config_element_output_type,
983 attr->output == LTTNG_EVENT_SPLICE ?
984 config_output_type_splice : config_output_type_mmap);
985 if (ret) {
986 goto end;
987 }
988
989 /* Tracefile size in bytes */
990 ret = mi_lttng_writer_write_element_unsigned_int(writer,
991 config_element_tracefile_size, attr->tracefile_size);
992 if (ret) {
993 goto end;
994 }
995
996 /* Count of tracefiles */
997 ret = mi_lttng_writer_write_element_unsigned_int(writer,
998 config_element_tracefile_count,
999 attr->tracefile_count);
1000 if (ret) {
1001 goto end;
1002 }
1003
1004 /* Live timer interval in usec*/
1005 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1006 config_element_live_timer_interval,
1007 attr->live_timer_interval);
1008 if (ret) {
fb83fe64
JD
1009 goto end;
1010 }
1011
1012 /* Discarded events */
1013 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1014 config_element_discarded_events,
1015 discarded_events);
1016 if (ret) {
1017 goto end;
1018 }
1019
1020 /* Lost packets */
1021 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1022 config_element_lost_packets,
1023 lost_packets);
1024 if (ret) {
5e18ec73
JR
1025 goto end;
1026 }
1027
1028 /* Closing attributes */
1029 ret = mi_lttng_writer_close_element(writer);
1030 if (ret) {
1031 goto end;
1032 }
1033end:
1034 return ret;
1035
1036}
1037
1038LTTNG_HIDDEN
1039int mi_lttng_event_common_attributes(struct mi_writer *writer,
1040 struct lttng_event *event)
1041{
1042 int ret;
7b4aa11d 1043 const char *filter_expression;
5e18ec73
JR
1044
1045 /* Open event element */
1046 ret = mi_lttng_writer_open_element(writer, config_element_event);
1047 if (ret) {
1048 goto end;
1049 }
1050
f4a088f7 1051 /* Event name */
5e18ec73
JR
1052 ret = mi_lttng_writer_write_element_string(writer,
1053 config_element_name, event->name);
1054 if (ret) {
1055 goto end;
1056 }
1057
f4a088f7 1058 /* Event type */
5e18ec73
JR
1059 ret = mi_lttng_writer_write_element_string(writer,
1060 config_element_type, mi_lttng_eventtype_string(event->type));
1061 if (ret) {
1062 goto end;
1063 }
1064
f4a088f7 1065 /* Is event enabled */
5e18ec73
JR
1066 ret = mi_lttng_writer_write_element_bool(writer,
1067 config_element_enabled, event->enabled);
1068 if (ret) {
1069 goto end;
1070 }
1071
7b4aa11d 1072 /* Event filter expression */
134e72ed 1073 ret = lttng_event_get_filter_expression(event, &filter_expression);
7b4aa11d
PP
1074 if (ret) {
1075 goto end;
1076 }
1077
1078 if (filter_expression) {
1079 ret = mi_lttng_writer_write_element_string(writer,
654f9f5e
JG
1080 config_element_filter_expression,
1081 filter_expression);
7b4aa11d
PP
1082 if (ret) {
1083 goto end;
1084 }
1085 }
1086
5e18ec73
JR
1087end:
1088 return ret;
1089}
1090
eecb9438
PP
1091static int write_event_exclusions(struct mi_writer *writer,
1092 struct lttng_event *event)
1093{
1094 int i;
1095 int ret;
1096 int exclusion_count;
1097
eecb9438
PP
1098 /* Open event exclusions */
1099 ret = mi_lttng_writer_open_element(writer, config_element_exclusions);
1100 if (ret) {
1101 goto end;
1102 }
1103
1104 exclusion_count = lttng_event_get_exclusion_name_count(event);
1105 if (exclusion_count < 0) {
1106 ret = exclusion_count;
1107 goto end;
1108 }
1109
1110 for (i = 0; i < exclusion_count; i++) {
1111 const char *name;
1112
1113 ret = lttng_event_get_exclusion_name(event, i, &name);
1114 if (ret) {
1115 /* Close exclusions */
1116 mi_lttng_writer_close_element(writer);
1117 goto end;
1118 }
1119
1120 ret = mi_lttng_writer_write_element_string(writer,
1121 config_element_exclusion, name);
1122 if (ret) {
1123 /* Close exclusions */
1124 mi_lttng_writer_close_element(writer);
1125 goto end;
1126 }
1127 }
1128
1129 /* Close exclusions */
1130 ret = mi_lttng_writer_close_element(writer);
1131
1132end:
1133 return ret;
1134}
1135
5e18ec73
JR
1136LTTNG_HIDDEN
1137int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer,
970d848b 1138 struct lttng_event *event, enum lttng_domain_type domain)
5e18ec73
JR
1139{
1140 int ret;
1141
f4a088f7 1142 /* Event loglevel */
5e18ec73 1143 ret = mi_lttng_writer_write_element_string(writer,
970d848b
DG
1144 config_element_loglevel,
1145 mi_lttng_loglevel_string(event->loglevel, domain));
5e18ec73
JR
1146 if (ret) {
1147 goto end;
1148 }
1149
f4a088f7 1150 /* Log level type */
5e18ec73
JR
1151 ret = mi_lttng_writer_write_element_string(writer,
1152 config_element_loglevel_type,
1153 mi_lttng_logleveltype_string(event->loglevel_type));
1154 if (ret) {
1155 goto end;
1156 }
1157
eecb9438
PP
1158 /* Event exclusions */
1159 ret = write_event_exclusions(writer, event);
5e18ec73
JR
1160
1161end:
1162 return ret;
1163}
1164
1165LTTNG_HIDDEN
1166int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer *writer,
1167 struct lttng_event *event)
1168{
1169 /* event exclusion filter */
eecb9438 1170 return write_event_exclusions(writer, event);
5e18ec73
JR
1171}
1172
1173LTTNG_HIDDEN
1174int mi_lttng_event_function_probe(struct mi_writer *writer,
1175 struct lttng_event *event)
1176{
1177 int ret;
1178
3b4a6e40
JRJ
1179 ret = mi_lttng_writer_open_element(writer, config_element_attributes);
1180 if (ret) {
1181 goto end;
1182 }
1183
1184 ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes);
1185 if (ret) {
1186 goto end;
1187 }
1188
5e18ec73
JR
1189 if (event->attr.probe.addr != 0) {
1190 /* event probe address */
1191 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1192 config_element_address, event->attr.probe.addr);
1193 if (ret) {
1194 goto end;
1195 }
1196 } else {
1197 /* event probe offset */
1198 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1199 config_element_offset, event->attr.probe.offset);
1200 if (ret) {
1201 goto end;
1202 }
1203
1204 /* event probe symbol_name */
1205 ret = mi_lttng_writer_write_element_string(writer,
1206 config_element_symbol_name, event->attr.probe.symbol_name);
1207 if (ret) {
1208 goto end;
1209 }
1210 }
3b4a6e40
JRJ
1211
1212 /* Close probe_attributes and attributes */
1213 ret = mi_lttng_close_multi_element(writer, 2);
5e18ec73
JR
1214end:
1215 return ret;
1216}
1217
1218LTTNG_HIDDEN
1219int mi_lttng_event_function_entry(struct mi_writer *writer,
1220 struct lttng_event *event)
1221{
3b4a6e40
JRJ
1222 int ret;
1223
1224 ret = mi_lttng_writer_open_element(writer, config_element_attributes);
1225 if (ret) {
1226 goto end;
1227 }
1228
1229 ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes);
1230 if (ret) {
1231 goto end;
1232 }
1233
5e18ec73 1234 /* event probe symbol_name */
3b4a6e40 1235 ret = mi_lttng_writer_write_element_string(writer,
5e18ec73 1236 config_element_symbol_name, event->attr.ftrace.symbol_name);
3b4a6e40
JRJ
1237 if (ret) {
1238 goto end;
1239 }
1240
1241 /* Close function_attributes and attributes */
1242 ret = mi_lttng_close_multi_element(writer, 2);
1243end:
1244 return ret;
5e18ec73
JR
1245}
1246
1247LTTNG_HIDDEN
1248int mi_lttng_events_open(struct mi_writer *writer)
1249{
1250 return mi_lttng_writer_open_element(writer, config_element_events);
1251}
1252
1253LTTNG_HIDDEN
1254int mi_lttng_event(struct mi_writer *writer,
970d848b 1255 struct lttng_event *event, int is_open, enum lttng_domain_type domain)
5e18ec73
JR
1256{
1257 int ret;
1258
1259 ret = mi_lttng_event_common_attributes(writer, event);
1260 if (ret) {
1261 goto end;
1262 }
1263
1264 switch (event->type) {
5e18ec73
JR
1265 case LTTNG_EVENT_TRACEPOINT:
1266 {
1267 if (event->loglevel != -1) {
970d848b 1268 ret = mi_lttng_event_tracepoint_loglevel(writer, event, domain);
5e18ec73
JR
1269 } else {
1270 ret = mi_lttng_event_tracepoint_no_loglevel(writer, event);
1271 }
1272 break;
1273 }
3b4a6e40
JRJ
1274 case LTTNG_EVENT_FUNCTION:
1275 /* Fallthrough */
5e18ec73
JR
1276 case LTTNG_EVENT_PROBE:
1277 ret = mi_lttng_event_function_probe(writer, event);
1278 break;
1279 case LTTNG_EVENT_FUNCTION_ENTRY:
1280 ret = mi_lttng_event_function_entry(writer, event);
1281 break;
89476427
JRJ
1282 case LTTNG_EVENT_ALL:
1283 /* Fallthrough */
5e18ec73
JR
1284 default:
1285 break;
1286 }
1287
1288 if (!is_open) {
1289 ret = mi_lttng_writer_close_element(writer);
1290 }
1291
1292end:
1293 return ret;
1294}
1295
ebbf5ab7
JR
1296LTTNG_HIDDEN
1297int mi_lttng_trackers_open(struct mi_writer *writer)
1298{
1299 return mi_lttng_writer_open_element(writer, config_element_trackers);
1300}
1301
1302LTTNG_HIDDEN
1303int mi_lttng_pid_tracker_open(struct mi_writer *writer)
1304{
1305 int ret;
1306
1307 /* Open element pid_tracker */
1308 ret = mi_lttng_writer_open_element(writer, config_element_pid_tracker);
1309 if (ret) {
1310 goto end;
1311 }
1312
1313 /* Open targets element */
1314 ret = mi_lttng_targets_open(writer);
1315end:
1316 return ret;
1317}
1318
5e18ec73
JR
1319LTTNG_HIDDEN
1320int mi_lttng_pids_open(struct mi_writer *writer)
1321{
ebbf5ab7
JR
1322 return mi_lttng_writer_open_element(writer, config_element_pids);
1323}
1324
bf239d4c
JR
1325/*
1326 * TODO: move the listing of pid for user agent to process semantic on
1327 * mi api bump. The use of process element break the mi api.
1328 */
ebbf5ab7 1329LTTNG_HIDDEN
bf239d4c 1330int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *name,
5e18ec73
JR
1331 int is_open)
1332{
1333 int ret;
1334
bf239d4c
JR
1335 /* Open pid process */
1336 ret = mi_lttng_writer_open_element(writer, config_element_pid);
5e18ec73
JR
1337 if (ret) {
1338 goto end;
1339 }
1340
1341 /* Writing pid number */
1342 ret = mi_lttng_writer_write_element_signed_int(writer,
bf239d4c 1343 mi_lttng_element_pid_id, (int)pid);
5e18ec73
JR
1344 if (ret) {
1345 goto end;
1346 }
1347
1348 /* Writing name of the process */
ebbf5ab7
JR
1349 if (name) {
1350 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
1351 name);
1352 if (ret) {
1353 goto end;
1354 }
1355 }
1356
1357 if (!is_open) {
1358 /* Closing Pid */
1359 ret = mi_lttng_writer_close_element(writer);
1360 }
1361
1362end:
1363 return ret;
1364}
1365
1366LTTNG_HIDDEN
1367int mi_lttng_targets_open(struct mi_writer *writer)
1368{
1369 return mi_lttng_writer_open_element(writer,
f95771e8 1370 config_element_targets);
ebbf5ab7
JR
1371}
1372
1373LTTNG_HIDDEN
1374int mi_lttng_pid_target(struct mi_writer *writer, pid_t pid, int is_open)
1375{
1376 int ret;
1377
1378 ret = mi_lttng_writer_open_element(writer,
f95771e8 1379 config_element_target_pid);
ebbf5ab7
JR
1380 if (ret) {
1381 goto end;
1382 }
1383
1384 /* Writing pid number
1385 * Special case for element all on track untrack command
1386 * All pid is represented as wildcard *
1387 */
1388 if ((int) pid == -1) {
1389 ret = mi_lttng_writer_write_element_string(writer,
1390 config_element_pid,
1391 mi_lttng_element_track_untrack_all_wildcard);
1392 } else {
1393 ret = mi_lttng_writer_write_element_signed_int(writer,
1394 config_element_pid, (int) pid);
1395 }
5e18ec73
JR
1396 if (ret) {
1397 goto end;
1398 }
1399
1400 if (!is_open) {
5e18ec73 1401 ret = mi_lttng_writer_close_element(writer);
ebbf5ab7
JR
1402 if (ret) {
1403 goto end;
1404 }
5e18ec73
JR
1405 }
1406
1407end:
1408 return ret;
1409}
1410
1411LTTNG_HIDDEN
1412int mi_lttng_event_fields_open(struct mi_writer *writer)
1413{
1414 return mi_lttng_writer_open_element(writer, mi_lttng_element_event_fields);
1415}
1416
1417LTTNG_HIDDEN
1418int mi_lttng_event_field(struct mi_writer *writer,
1419 struct lttng_event_field *field)
1420{
1421 int ret;
1422
1423 if (!field->field_name[0]) {
5e18ec73
JR
1424 ret = 0;
1425 goto end;
1426 }
1427
1428 /* Open field */
1429 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_event_field);
1430 if (ret) {
1431 goto end;
1432 }
1433
1434 if (!field->field_name[0]) {
1435 goto close;
1436 }
1437
1438 /* Name */
1439 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
1440 field->field_name);
1441 if (ret) {
1442 goto end;
1443 }
1444
1445 /* Type */
1446 ret = mi_lttng_writer_write_element_string(writer, config_element_type,
1447 mi_lttng_eventfieldtype_string(field->type));
1448 if (ret) {
1449 goto end;
1450 }
1451
1452 /* nowrite */
1453 ret = mi_lttng_writer_write_element_signed_int(writer,
1454 mi_lttng_element_nowrite, field->nowrite);
1455 if (ret) {
1456 goto end;
1457 }
1458
1459close:
1460 /* Close field element */
1461 ret = mi_lttng_writer_close_element(writer);
1462
1463end:
1464 return ret;
1465}
7e66b1b0 1466
89b72577 1467LTTNG_HIDDEN
a23cb78a
JG
1468int mi_lttng_perf_counter_context(struct mi_writer *writer,
1469 struct lttng_event_perf_counter_ctx *perf_context)
89b72577
JRJ
1470{
1471 int ret;
a23cb78a
JG
1472
1473 /* Open perf_counter_context */
1474 ret = mi_lttng_writer_open_element(writer,
1475 mi_lttng_element_perf_counter_context);
89b72577
JRJ
1476 if (ret) {
1477 goto end;
1478 }
1479
a23cb78a
JG
1480 /* Type */
1481 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1482 config_element_type, perf_context->type);
1483 if (ret) {
89b72577
JRJ
1484 goto end;
1485 }
1486
a23cb78a
JG
1487 /* Config */
1488 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1489 config_element_config, perf_context->config);
1490 if (ret) {
1491 goto end;
89b72577
JRJ
1492 }
1493
a23cb78a
JG
1494 /* Name of the perf counter */
1495 ret = mi_lttng_writer_write_element_string(writer,
1496 config_element_name, perf_context->name);
1497 if (ret) {
1498 goto end;
89b72577
JRJ
1499 }
1500
a23cb78a
JG
1501 /* Close perf_counter_context */
1502 ret = mi_lttng_writer_close_element(writer);
89b72577
JRJ
1503end:
1504 return ret;
1505}
1506
a23cb78a
JG
1507static
1508int mi_lttng_app_context(struct mi_writer *writer,
1509 const char *provider_name, const char *ctx_name)
89b72577
JRJ
1510{
1511 int ret;
1512
a23cb78a 1513 /* Open app */
89b72577 1514 ret = mi_lttng_writer_open_element(writer,
a23cb78a 1515 config_element_context_app);
89b72577
JRJ
1516 if (ret) {
1517 goto end;
1518 }
1519
a23cb78a
JG
1520 /* provider_name */
1521 ret = mi_lttng_writer_write_element_string(writer,
1522 config_element_context_app_provider_name,
1523 provider_name);
89b72577
JRJ
1524 if (ret) {
1525 goto end;
1526 }
1527
a23cb78a
JG
1528 /* ctx_name */
1529 ret = mi_lttng_writer_write_element_string(writer,
1530 config_element_context_app_ctx_name, ctx_name);
89b72577
JRJ
1531 if (ret) {
1532 goto end;
1533 }
1534
a23cb78a
JG
1535 /* Close app */
1536 ret = mi_lttng_writer_close_element(writer);
1537end:
1538 return ret;
1539}
1540
1541LTTNG_HIDDEN
1542int mi_lttng_context(struct mi_writer *writer,
1543 struct lttng_event_context *context, int is_open)
1544{
1545 int ret;
1546
1547 /* Open context */
1548 ret = mi_lttng_writer_open_element(writer , config_element_context);
89b72577
JRJ
1549 if (ret) {
1550 goto end;
1551 }
1552
a23cb78a
JG
1553 /* Special case for PERF_*_COUNTER
1554 * print the lttng_event_perf_counter_ctx*/
1555 switch (context->ctx) {
1556 case LTTNG_EVENT_CONTEXT_PERF_COUNTER:
1557 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER:
1558 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER:
1559 {
1560 struct lttng_event_perf_counter_ctx *perf_context =
1561 &context->u.perf_counter;
1562 ret = mi_lttng_perf_counter_context(writer, perf_context);
1563 if (ret) {
1564 goto end;
1565 }
1566 break;
1567 }
1568 case LTTNG_EVENT_CONTEXT_APP_CONTEXT:
1569 {
1570 ret = mi_lttng_app_context(writer,
1571 context->u.app_ctx.provider_name,
1572 context->u.app_ctx.ctx_name);
1573 if (ret) {
1574 goto end;
1575 }
1576 break;
1577 }
1578 default:
1579 {
1580 const char *type_string = mi_lttng_event_contexttype_string(
1581 context->ctx);
1582 if (!type_string) {
1583 ret = -LTTNG_ERR_INVALID;
1584 goto end;
1585 }
1586
1587 /* Print context type */
1588 ret = mi_lttng_writer_write_element_string(writer,
1589 config_element_type, type_string);
1590 break;
1591 }
1592 }
1593
1594 /* Close context */
1595 if (!is_open) {
1596 ret = mi_lttng_writer_close_element(writer);
1597 }
1598
89b72577
JRJ
1599end:
1600 return ret;
1601}
50534d6f
JRJ
1602
1603LTTNG_HIDDEN
1604int mi_lttng_snapshot_output_session_name(struct mi_writer *writer,
1605 const char *session_name)
1606{
1607 int ret;
1608
1609 /* Open session element */
1610 ret = mi_lttng_writer_open_element(writer, config_element_session);
1611 if (ret) {
1612 goto end;
1613 }
1614
1615 /* Snapshot output list for current session name */
1616 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
1617 session_name);
01defc26
JR
1618 if (ret) {
1619 goto end;
1620 }
50534d6f
JRJ
1621
1622 /* Open element snapshots (sequence one snapshot) */
1623 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_snapshots);
1624 if (ret) {
1625 goto end;
1626 }
1627
1628end:
1629 return ret;
1630}
1631
1632LTTNG_HIDDEN
1633int mi_lttng_snapshot_list_output(struct mi_writer *writer,
1634 struct lttng_snapshot_output *output)
1635{
1636 int ret;
1637
1638 /* Open element snapshot output */
1639 ret = mi_lttng_writer_open_element(writer,
1640 mi_lttng_element_command_snapshot);
1641 if (ret) {
1642 goto end;
1643 }
1644
1645 /* ID of the snapshot output */
1646 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1647 mi_lttng_element_id, output->id);
1648 if (ret) {
1649 goto end;
1650 }
1651
1652 /* Name of the output */
1653 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
1654 output->name);
1655 if (ret) {
1656 goto end;
1657 }
1658
1659 /* Destination of the output (ctrl_url)*/
1660 ret = mi_lttng_writer_write_element_string(writer,
1661 mi_lttng_element_snapshot_ctrl_url, output->ctrl_url);
1662 if (ret) {
1663 goto end;
1664 }
1665
1666 /* Destination of the output (data_url) */
1667 ret = mi_lttng_writer_write_element_string(writer,
1668 mi_lttng_element_snapshot_data_url, output->data_url);
1669 if (ret) {
1670 goto end;
1671 }
1672
1673 /* total size of all stream combined */
1674 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1675 mi_lttng_element_snapshot_max_size, output->max_size);
1676 if (ret) {
1677 goto end;
1678 }
1679
1680 /* Close snapshot output element */
1681 ret = mi_lttng_writer_close_element(writer);
1682
1683end:
1684 return ret;
1685}
1686
1687LTTNG_HIDDEN
1688int mi_lttng_snapshot_del_output(struct mi_writer *writer, int id,
1689 const char *name, const char *current_session_name)
1690{
1691 int ret;
1692
1693 /* Open element del_snapshot */
1694 ret = mi_lttng_writer_open_element(writer,
1695 mi_lttng_element_command_snapshot);
1696 if (ret) {
1697 goto end;
1698 }
1699
1700
1701 if (id != UINT32_MAX) {
1702 /* "Snapshot output "id" successfully deleted
1703 * for "current_session_name"
1704 * ID of the snapshot output
1705 */
1706 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1707 mi_lttng_element_id, id);
1708 if (ret) {
1709 goto end;
1710 }
1711 } else {
1712 /* "Snapshot output "name" successfully deleted
1713 * for session "current_session_name"
1714 * Name of the output
1715 */
1716 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
1717 name);
1718 if (ret) {
1719 goto end;
1720 }
1721 }
1722
1723 /* Snapshot was deleted for session "current_session_name"*/
1724 ret = mi_lttng_writer_write_element_string(writer,
1725 mi_lttng_element_snapshot_session_name,
1726 current_session_name);
1727 if (ret) {
1728 goto end;
1729 }
1730
1731 /* Close snapshot element */
1732 ret = mi_lttng_writer_close_element(writer);
1733
1734end:
1735 return ret;
1736}
1737
1738LTTNG_HIDDEN
1739int mi_lttng_snapshot_add_output(struct mi_writer *writer,
1740 const char *current_session_name, const char *n_ptr,
1741 struct lttng_snapshot_output *output)
1742{
1743 int ret;
1744
1745 /* Open element snapshot */
1746 ret = mi_lttng_writer_open_element(writer,
1747 mi_lttng_element_command_snapshot);
1748 if (ret) {
1749 goto end;
1750 }
1751
1752 /* Snapshot output id */
1753 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1754 mi_lttng_element_id, output->id);
1755 if (ret) {
1756 goto end;
1757 }
1758
1759 /* Snapshot output names */
1760 ret = mi_lttng_writer_write_element_string(writer,
1761 config_element_name, n_ptr);
1762 if (ret) {
1763 goto end;
1764 }
1765
1766 /* Destination of the output (ctrl_url)*/
1767 ret = mi_lttng_writer_write_element_string(writer,
1768 mi_lttng_element_snapshot_ctrl_url, output->ctrl_url);
1769 if (ret) {
1770 goto end;
1771 }
1772
1773 /* Snapshot added for session "current_session_name"*/
1774 ret = mi_lttng_writer_write_element_string(writer,
1775 mi_lttng_element_snapshot_session_name, current_session_name);
1776 if (ret) {
1777 goto end;
1778 }
1779
1780 /* total size of all stream combined */
1781 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1782 mi_lttng_element_snapshot_max_size, output->max_size);
1783 if (ret) {
1784 goto end;
1785 }
1786
1787 /* Close snapshot element */
1788 ret = mi_lttng_writer_close_element(writer);
1789
1790end:
1791 return ret;
1792}
1793
1794LTTNG_HIDDEN
1795int mi_lttng_snapshot_record(struct mi_writer *writer,
1796 const char *current_session_name, const char *url,
1797 const char *cmdline_ctrl_url, const char *cmdline_data_url)
1798{
1799 int ret;
1800
1801 /* Open element snapshot */
1802 ret = mi_lttng_writer_open_element(writer,
1803 mi_lttng_element_command_snapshot);
1804 if (ret) {
1805 goto end;
1806 }
1807
1808 /*
1809 * If a valid an URL was given, serialize it,
1810 * else take the command line data and ctrl urls*/
1811 if (url) {
1812 /* Destination of the output (ctrl_url)*/
1813 ret = mi_lttng_writer_write_element_string(writer,
1814 mi_lttng_element_snapshot_ctrl_url, url);
1815 if (ret) {
1816 goto end;
1817 }
1818 } else if (cmdline_ctrl_url) {
1819 /* Destination of the output (ctrl_url)*/
1820 ret = mi_lttng_writer_write_element_string(writer,
1821 mi_lttng_element_snapshot_ctrl_url, cmdline_ctrl_url);
1822 if (ret) {
1823 goto end;
1824 }
1825
1826 /* Destination of the output (data_url) */
1827 ret = mi_lttng_writer_write_element_string(writer,
1828 mi_lttng_element_snapshot_data_url, cmdline_data_url);
1829 if (ret) {
1830 goto end;
1831 }
1832 }
1833
1834 /* Close record_snapshot element */
1835 ret = mi_lttng_writer_close_element(writer);
1836
1837end:
1838 return ret;
1839}
This page took 0.12022 seconds and 5 git commands to generate.