lttng-create(1): specify that `--shm-path` only applies to UST channels
[lttng-tools.git] / src / common / mi-lttng.c
CommitLineData
c7e35b03 1/*
ab5be9fa
MJ
2 * Copyright (C) 2014 Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * Copyright (C) 2014 Olivier Cotte <olivier.cotte@polymtl.ca>
4 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
c7e35b03 5 *
ab5be9fa 6 * SPDX-License-Identifier: GPL-2.0-only
c7e35b03 7 *
c7e35b03
JR
8 */
9
159b042f 10#include "lttng/tracker.h"
6c1c0768 11#define _LGPL_SOURCE
159b042f 12#include "mi-lttng.h"
f40ef1d5 13#include <common/config/session-config.h>
41af1adf 14#include <common/defaults.h>
159b042f 15#include <common/tracker.h>
fb83fe64 16#include <lttng/channel.h>
159b042f 17#include <lttng/snapshot-internal.h>
c7e35b03 18
5e18ec73
JR
19#include <assert.h>
20
a92b6bcc 21#define MI_SCHEMA_MAJOR_VERSION 4
ebc5e6b0 22#define MI_SCHEMA_MINOR_VERSION 1
e10b6a1c
JG
23
24/* Machine interface namespace URI */
c8ecdbb0
JG
25LTTNG_HIDDEN const char * const mi_lttng_xmlns = "xmlns";
26LTTNG_HIDDEN const char * const mi_lttng_xmlns_xsi = "xmlns:xsi";
27LTTNG_HIDDEN const char * const mi_lttng_w3_schema_uri = "http://www.w3.org/2001/XMLSchema-instance";
28LTTNG_HIDDEN const char * const mi_lttng_schema_location = "xsi:schemaLocation";
29LTTNG_HIDDEN const char * const mi_lttng_schema_location_uri =
41af1adf 30 DEFAULT_LTTNG_MI_NAMESPACE " "
a18d9544 31 "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION)
e10b6a1c
JG
32 "/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION) "."
33 XSTR(MI_SCHEMA_MINOR_VERSION) ".xsd";
c8ecdbb0
JG
34LTTNG_HIDDEN const char * const mi_lttng_schema_version = "schemaVersion";
35LTTNG_HIDDEN const char * const mi_lttng_schema_version_value = XSTR(MI_SCHEMA_MAJOR_VERSION)
e10b6a1c
JG
36 "." XSTR(MI_SCHEMA_MINOR_VERSION);
37
c7e35b03
JR
38/* Strings related to command */
39const char * const mi_lttng_element_command = "command";
f4a088f7
JRJ
40const char * const mi_lttng_element_command_action = "snapshot_action";
41const char * const mi_lttng_element_command_add_context = "add-context";
0f7c2963 42const char *const mi_lttng_element_command_add_trigger = "add-trigger";
f4a088f7
JRJ
43const char * const mi_lttng_element_command_create = "create";
44const char * const mi_lttng_element_command_destroy = "destroy";
45const char * const mi_lttng_element_command_disable_channel = "disable-channel";
46const char * const mi_lttng_element_command_disable_event = "disable-event";
47const char * const mi_lttng_element_command_enable_channels = "enable-channel";
89476427 48const char * const mi_lttng_element_command_enable_event = "enable-event";
c7e35b03 49const char * const mi_lttng_element_command_list = "list";
27692bb8 50const char *const mi_lttng_element_command_list_trigger = "list-trigger";
1734c658 51const char * const mi_lttng_element_command_load = "load";
c8ecdbb0
JG
52LTTNG_HIDDEN const char * const mi_lttng_element_command_metadata = "metadata";
53LTTNG_HIDDEN const char * const mi_lttng_element_command_metadata_action = "metadata_action";
eded6438
JD
54LTTNG_HIDDEN const char * const mi_lttng_element_command_regenerate = "regenerate";
55LTTNG_HIDDEN const char * const mi_lttng_element_command_regenerate_action = "regenerate_action";
f4a088f7
JRJ
56const char * const mi_lttng_element_command_name = "name";
57const char * const mi_lttng_element_command_output = "output";
0f7c2963 58const char *const mi_lttng_element_command_remove_trigger = "remove-trigger";
f4a088f7
JRJ
59const char * const mi_lttng_element_command_save = "save";
60const char * const mi_lttng_element_command_set_session = "set-session";
61const char * const mi_lttng_element_command_snapshot = "snapshot";
62const char * const mi_lttng_element_command_snapshot_add = "add_snapshot";
63const char * const mi_lttng_element_command_snapshot_del = "del_snapshot";
64const char * const mi_lttng_element_command_snapshot_list = "list_snapshot";
65const char * const mi_lttng_element_command_snapshot_record = "record_snapshot";
1cfc0bc8 66const char * const mi_lttng_element_command_start = "start";
e5b83100 67const char * const mi_lttng_element_command_stop = "stop";
1734c658 68const char * const mi_lttng_element_command_success = "success";
ccf10263
MD
69const char * const mi_lttng_element_command_track = "track";
70const char * const mi_lttng_element_command_untrack = "untrack";
f4a088f7 71const char * const mi_lttng_element_command_version = "version";
a416382b
JG
72LTTNG_HIDDEN const char * const mi_lttng_element_command_rotate = "rotate";
73LTTNG_HIDDEN const char * const mi_lttng_element_command_enable_rotation = "enable-rotation";
74LTTNG_HIDDEN const char * const mi_lttng_element_command_disable_rotation = "disable-rotation";
511ed4e2 75LTTNG_HIDDEN const char * const mi_lttng_element_command_clear = "clear";
c7e35b03 76
1734c658 77/* Strings related to version command */
c7e35b03 78const char * const mi_lttng_element_version = "version";
314d5222 79const char * const mi_lttng_element_version_commit = "commit";
f4a088f7 80const char * const mi_lttng_element_version_description = "description";
c7e35b03 81const char * const mi_lttng_element_version_license = "license";
f4a088f7
JRJ
82const char * const mi_lttng_element_version_major = "major";
83const char * const mi_lttng_element_version_minor = "minor";
c7e35b03 84const char * const mi_lttng_element_version_patch_level = "patchLevel";
f4a088f7
JRJ
85const char * const mi_lttng_element_version_str = "string";
86const char * const mi_lttng_element_version_web = "url";
1734c658 87
5e18ec73
JR
88/* String related to a lttng_event_field */
89const char * const mi_lttng_element_event_field = "event_field";
90const char * const mi_lttng_element_event_fields = "event_fields";
91
89b72577 92/* String related to lttng_event_perf_counter_ctx */
a23cb78a 93const char * const mi_lttng_element_perf_counter_context = "perf";
89b72577 94
f4a088f7 95/* Strings related to pid */
bf239d4c 96const char * const mi_lttng_element_pid_id = "id";
f4a088f7
JRJ
97
98/* Strings related to save command */
99const char * const mi_lttng_element_save = "save";
100
101/* Strings related to load command */
102const char * const mi_lttng_element_load = "load";
23cb2d55
JR
103LTTNG_HIDDEN const char * const mi_lttng_element_load_overrides = "overrides";
104LTTNG_HIDDEN const char * const mi_lttng_element_load_override_url = "url";
f4a088f7 105
5e18ec73 106/* General elements of mi_lttng */
f4a088f7
JRJ
107const char * const mi_lttng_element_empty = "";
108const char * const mi_lttng_element_id = "id";
109const char * const mi_lttng_element_nowrite = "nowrite";
110const char * const mi_lttng_element_success = "success";
5e18ec73
JR
111const char * const mi_lttng_element_type_enum = "ENUM";
112const char * const mi_lttng_element_type_float = "FLOAT";
f4a088f7
JRJ
113const char * const mi_lttng_element_type_integer = "INTEGER";
114const char * const mi_lttng_element_type_other = "OTHER";
5e18ec73 115const char * const mi_lttng_element_type_string = "STRING";
5e18ec73
JR
116
117/* String related to loglevel */
118const char * const mi_lttng_loglevel_str_alert = "TRACE_ALERT";
119const char * const mi_lttng_loglevel_str_crit = "TRACE_CRIT";
120const char * const mi_lttng_loglevel_str_debug = "TRACE_DEBUG";
121const char * const mi_lttng_loglevel_str_debug_function = "TRACE_DEBUG_FUNCTION";
122const char * const mi_lttng_loglevel_str_debug_line = "TRACE_DEBUG_LINE";
123const char * const mi_lttng_loglevel_str_debug_module = "TRACE_DEBUG_MODULE";
124const char * const mi_lttng_loglevel_str_debug_process = "TRACE_DEBUG_PROCESS";
125const char * const mi_lttng_loglevel_str_debug_program = "TRACE_DEBUG_PROGRAM";
126const char * const mi_lttng_loglevel_str_debug_system = "TRACE_DEBUG_SYSTEM";
127const char * const mi_lttng_loglevel_str_debug_unit = "TRACE_DEBUG_UNIT";
128const char * const mi_lttng_loglevel_str_emerg = "TRACE_EMERG";
129const char * const mi_lttng_loglevel_str_err = "TRACE_ERR";
130const char * const mi_lttng_loglevel_str_info = "TRACE_INFO";
131const char * const mi_lttng_loglevel_str_notice = "TRACE_NOTICE";
132const char * const mi_lttng_loglevel_str_unknown = "UNKNOWN";
133const char * const mi_lttng_loglevel_str_warning = "TRACE_WARNING";
134
136f2f81
JRJ
135/* String related to loglevel JUL */
136const char * const mi_lttng_loglevel_str_jul_all = "JUL_ALL";
137const char * const mi_lttng_loglevel_str_jul_config = "JUL_CONFIG";
138const char * const mi_lttng_loglevel_str_jul_fine = "JUL_FINE";
139const char * const mi_lttng_loglevel_str_jul_finer = "JUL_FINER";
140const char * const mi_lttng_loglevel_str_jul_finest = "JUL_FINEST";
141const char * const mi_lttng_loglevel_str_jul_info = "JUL_INFO";
142const char * const mi_lttng_loglevel_str_jul_off = "JUL_OFF";
143const char * const mi_lttng_loglevel_str_jul_severe = "JUL_SEVERE";
144const char * const mi_lttng_loglevel_str_jul_warning = "JUL_WARNING";
145
970d848b
DG
146/* String related to loglevel LOG4J */
147const char * const mi_lttng_loglevel_str_log4j_off = "LOG4J_OFF";
148const char * const mi_lttng_loglevel_str_log4j_fatal = "LOG4J_FATAL";
149const char * const mi_lttng_loglevel_str_log4j_error = "LOG4J_ERROR";
150const char * const mi_lttng_loglevel_str_log4j_warn = "LOG4J_WARN";
151const char * const mi_lttng_loglevel_str_log4j_info = "LOG4J_INFO";
152const char * const mi_lttng_loglevel_str_log4j_debug = "LOG4J_DEBUG";
153const char * const mi_lttng_loglevel_str_log4j_trace = "LOG4J_TRACE";
154const char * const mi_lttng_loglevel_str_log4j_all = "LOG4J_ALL";
155
0e115563
DG
156/* String related to loglevel Python */
157const char * const mi_lttng_loglevel_str_python_critical = "PYTHON_CRITICAL";
158const char * const mi_lttng_loglevel_str_python_error = "PYTHON_ERROR";
159const char * const mi_lttng_loglevel_str_python_warning = "PYTHON_WARNING";
160const char * const mi_lttng_loglevel_str_python_info = "PYTHON_INFO";
161const char * const mi_lttng_loglevel_str_python_debug = "PYTHON_DEBUG";
162const char * const mi_lttng_loglevel_str_python_notset = "PYTHON_NOTSET";
163
1734c658 164/* String related to loglevel type */
5e18ec73
JR
165const char * const mi_lttng_loglevel_type_all = "ALL";
166const char * const mi_lttng_loglevel_type_range = "RANGE";
167const char * const mi_lttng_loglevel_type_single = "SINGLE";
168const char * const mi_lttng_loglevel_type_unknown = "UNKNOWN";
169
50534d6f 170/* String related to a lttng_snapshot_output */
50534d6f 171const char * const mi_lttng_element_snapshot_ctrl_url = "ctrl_url";
f4a088f7 172const char * const mi_lttng_element_snapshot_data_url = "data_url";
50534d6f 173const char * const mi_lttng_element_snapshot_max_size = "max_size";
f4a088f7
JRJ
174const char * const mi_lttng_element_snapshot_n_ptr = "n_ptr";
175const char * const mi_lttng_element_snapshot_session_name = "session_name";
176const char * const mi_lttng_element_snapshots = "snapshots";
5e18ec73 177
ebbf5ab7 178/* String related to track/untrack command */
ebbf5ab7
JR
179const char * const mi_lttng_element_track_untrack_all_wildcard = "*";
180
d68c9a04
JD
181LTTNG_HIDDEN const char * const mi_lttng_element_session_name = "session_name";
182
183/* String related to rotate command */
184LTTNG_HIDDEN const char * const mi_lttng_element_rotation = "rotation";
d68c9a04 185LTTNG_HIDDEN const char * const mi_lttng_element_rotate_status = "status";
259c2674 186LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule = "rotation_schedule";
66ea93b1
JG
187LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedules = "rotation_schedules";
188LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_result = "rotation_schedule_result";
189LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_results = "rotation_schedule_results";
190LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_periodic = "periodic";
191LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_periodic_time_us = "time_us";
192LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_size_threshold = "size_threshold";
193LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_size_threshold_bytes = "bytes";
91c4d516
JG
194LTTNG_HIDDEN const char * const mi_lttng_element_rotation_state = "state";
195LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location = "location";
196LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_local = "local";
197LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_local_absolute_path = "absolute_path";
198LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay = "relay";
199LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay_host = "host";
200LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay_control_port = "control_port";
201LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay_data_port = "data_port";
202LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay_protocol = "protocol";
203LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay_relative_path = "relative_path";
204
205/* String related to enum lttng_rotation_state */
206LTTNG_HIDDEN const char * const mi_lttng_rotation_state_str_ongoing = "ONGOING";
207LTTNG_HIDDEN const char * const mi_lttng_rotation_state_str_completed = "COMPLETED";
208LTTNG_HIDDEN const char * const mi_lttng_rotation_state_str_expired = "EXPIRED";
209LTTNG_HIDDEN const char * const mi_lttng_rotation_state_str_error = "ERROR";
210
211/* String related to enum lttng_trace_archive_location_relay_protocol_type */
212LTTNG_HIDDEN const char * const mi_lttng_rotation_location_relay_protocol_str_tcp = "TCP";
d68c9a04 213
0f7c2963
JR
214/* String related to rate_policy elements */
215LTTNG_HIDDEN const char *const mi_lttng_element_rate_policy = "rate_policy";
216LTTNG_HIDDEN const char *const mi_lttng_element_rate_policy_every_n =
217 "rate_policy_every_n";
218LTTNG_HIDDEN const char *const mi_lttng_element_rate_policy_once_after_n =
219 "rate_policy_once_after_n";
220
221LTTNG_HIDDEN const char *const mi_lttng_element_rate_policy_every_n_interval =
222 "interval";
223LTTNG_HIDDEN const char
224 *const mi_lttng_element_rate_policy_once_after_n_threshold =
225 "threshold";
226
227/* String related to action elements */
228LTTNG_HIDDEN const char *const mi_lttng_element_action = "action";
229LTTNG_HIDDEN const char *const mi_lttng_element_action_list = "action_list";
230LTTNG_HIDDEN const char *const mi_lttng_element_action_notify = "action_notify";
231LTTNG_HIDDEN const char *const mi_lttng_element_action_start_session =
232 "action_start_session";
233LTTNG_HIDDEN const char *const mi_lttng_element_action_stop_session =
234 "action_stop_session";
235LTTNG_HIDDEN const char *const mi_lttng_element_action_rotate_session =
236 "action_rotate_session";
237LTTNG_HIDDEN const char *const mi_lttng_element_action_snapshot_session =
238 "action_snapshot_session";
239LTTNG_HIDDEN const char *const mi_lttng_element_action_snapshot_session_output =
240 "output";
241
242/* String related to condition */
243LTTNG_HIDDEN const char *const mi_lttng_element_condition = "condition";
244LTTNG_HIDDEN const char *const mi_lttng_element_condition_buffer_usage_high =
245 "condition_buffer_usage_high";
246LTTNG_HIDDEN const char *const mi_lttng_element_condition_buffer_usage_low =
247 "condition_buffer_usage_low";
248LTTNG_HIDDEN const char *const mi_lttng_element_condition_event_rule_matches =
249 "condition_event_rule_matches";
250LTTNG_HIDDEN const char *const mi_lttng_element_condition_session_consumed_size =
251 "condition_session_consumed_size";
252LTTNG_HIDDEN const char *const mi_lttng_element_condition_session_rotation =
253 "condition_session_rotation";
254LTTNG_HIDDEN const char
255 *const mi_lttng_element_condition_session_rotation_completed =
256 "condition_session_rotation_completed";
257LTTNG_HIDDEN const char
258 *const mi_lttng_element_condition_session_rotation_ongoing =
259 "condition_session_rotation_ongoing";
260
261LTTNG_HIDDEN const char *const mi_lttng_element_condition_channel_name =
262 "channel_name";
263LTTNG_HIDDEN const char *const mi_lttng_element_condition_threshold_bytes =
264 "threshold_bytes";
265LTTNG_HIDDEN const char *const mi_lttng_element_condition_threshold_ratio =
266 "threshold_ratio";
267
268/* String related to capture descriptor */
269LTTNG_HIDDEN const char *const mi_lttng_element_capture_descriptor =
270 "capture_descriptor";
271LTTNG_HIDDEN const char *const mi_lttng_element_capture_descriptors =
272 "capture_descriptors";
273
274/* String related to event expression */
275LTTNG_HIDDEN const char *const mi_lttng_element_event_expr = "event_expr";
276LTTNG_HIDDEN const char *const mi_lttng_element_event_expr_payload_field =
277 "event_expr_payload_field";
278LTTNG_HIDDEN const char *const mi_lttng_element_event_expr_channel_context_field =
279 "event_expr_channel_context_field";
280LTTNG_HIDDEN const char
281 *const mi_lttng_element_event_expr_app_specific_context_field =
282 "event_expr_app_specific_context_field";
283LTTNG_HIDDEN const char *const mi_lttng_element_event_expr_array_field_element =
284 "event_expr_array_field_element";
285LTTNG_HIDDEN const char *const mi_lttng_element_event_expr_provider_name =
286 "provider_name";
287LTTNG_HIDDEN const char *const mi_lttng_element_event_expr_type_name =
288 "type_name";
289LTTNG_HIDDEN const char *const mi_lttng_element_event_expr_index = "index";
290
291/* String related to event rule */
292LTTNG_HIDDEN const char *const mi_lttng_element_event_rule = "event_rule";
293
294/* String related to lttng_event_rule_type */
295LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_event_name =
296 "event_name";
297LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_name_pattern =
298 "name_pattern";
299LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_filter_expression =
300 "filter_expression";
301
302LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_jul_logging =
303 "event_rule_jul_logging";
304LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_kernel_kprobe =
305 "event_rule_kernel_kprobe";
306LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_kernel_syscall =
307 "event_rule_kernel_syscall";
308LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_kernel_tracepoint =
309 "event_rule_kernel_tracepoint";
310LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_kernel_uprobe =
311 "event_rule_kernel_uprobe";
312LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_log4j_logging =
313 "event_rule_log4j_logging";
314LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_python_logging =
315 "event_rule_python_logging";
316LTTNG_HIDDEN const char *const mi_lttng_element_event_rule_user_tracepoint =
317 "event_rule_user_tracepoint";
318
319/* String related to lttng_event_rule_kernel_syscall. */
320LTTNG_HIDDEN const char *const
321 mi_lttng_element_event_rule_kernel_syscall_emission_site =
322 "emission_site";
323
324/* String related to enum lttng_event_rule_kernel_syscall_emission_site. */
325LTTNG_HIDDEN const char *const
326 mi_lttng_event_rule_kernel_syscall_emission_site_entry_exit =
327 "entry+exit";
328LTTNG_HIDDEN const char
329 *const mi_lttng_event_rule_kernel_syscall_emission_site_entry =
330 "entry";
331LTTNG_HIDDEN const char *const
332 mi_lttng_event_rule_kernel_syscall_emission_site_exit = "exit";
333
334/* String related to lttng_event_rule_user_tracepoint */
335LTTNG_HIDDEN const char *const
336 mi_lttng_element_event_rule_user_tracepoint_name_pattern_exclusions =
337 "name_pattern_exclusions";
338LTTNG_HIDDEN const char *const
339 mi_lttng_element_event_rule_user_tracepoint_name_pattern_exclusion =
340 "name_pattern_exclusion";
341
342/* String related to log level rule. */
343LTTNG_HIDDEN const char *const mi_lttng_element_log_level_rule =
344 "log_level_rule";
345LTTNG_HIDDEN const char *const mi_lttng_element_log_level_rule_exactly =
346 "log_level_rule_exactly";
347LTTNG_HIDDEN const char
348 *const mi_lttng_element_log_level_rule_at_least_as_severe_as =
349 "log_level_rule_at_least_as_severe_as";
350LTTNG_HIDDEN const char *const mi_lttng_element_log_level_rule_level = "level";
351
352/* String related to kernel probe location. */
353LTTNG_HIDDEN const char *const mi_lttng_element_kernel_probe_location =
354 "kernel_probe_location";
355LTTNG_HIDDEN const char
356 *const mi_lttng_element_kernel_probe_location_symbol_offset =
357 "kernel_probe_location_symbol_offset";
358LTTNG_HIDDEN const char *const
359 mi_lttng_element_kernel_probe_location_symbol_offset_name =
360 "name";
361LTTNG_HIDDEN const char *const
362 mi_lttng_element_kernel_probe_location_symbol_offset_offset =
363 "offset";
364
365LTTNG_HIDDEN const char *const mi_lttng_element_kernel_probe_location_address =
366 "kernel_probe_location_address";
367LTTNG_HIDDEN const char
368 *const mi_lttng_element_kernel_probe_location_address_address =
369 "address";
370
371/* String related to userspace probe location. */
372LTTNG_HIDDEN const char *const mi_lttng_element_userspace_probe_location =
373 "userspace_probe_location";
374LTTNG_HIDDEN const char
375 *const mi_lttng_element_userspace_probe_location_binary_path =
376 "binary_path";
377LTTNG_HIDDEN const char
378 *const mi_lttng_element_userspace_probe_location_function =
379 "userspace_probe_location_function";
380LTTNG_HIDDEN const char
381 *const mi_lttng_element_userspace_probe_location_function_name =
382 "name";
383LTTNG_HIDDEN const char
384 *const mi_lttng_element_userspace_probe_location_lookup_method =
385 "userspace_probe_location_lookup_method";
386LTTNG_HIDDEN const char *const
387 mi_lttng_element_userspace_probe_location_lookup_method_function_default =
388 "userspace_probe_location_lookup_method_function_default";
389LTTNG_HIDDEN const char *const
390 mi_lttng_element_userspace_probe_location_lookup_method_function_elf =
391 "userspace_probe_location_lookup_method_function_elf";
392LTTNG_HIDDEN const char *const
393 mi_lttng_element_userspace_probe_location_lookup_method_tracepoint_sdt =
394 "userspace_probe_location_lookup_method_tracepoint_sdt";
395LTTNG_HIDDEN const char
396 *const mi_lttng_element_userspace_probe_location_tracepoint =
397 "userspace_probe_location_tracepoint";
398LTTNG_HIDDEN const char *const
399 mi_lttng_element_userspace_probe_location_tracepoint_probe_name =
400 "probe_name";
401LTTNG_HIDDEN const char *const
402 mi_lttng_element_userspace_probe_location_tracepoint_provider_name =
403 "provider_name";
404
405/* String related to enum
406 * lttng_userspace_probe_location_function_instrumentation_type */
407LTTNG_HIDDEN const char *const
408 mi_lttng_element_userspace_probe_location_function_instrumentation_type =
409 "instrumentation_type";
410LTTNG_HIDDEN const char *const
411 mi_lttng_userspace_probe_location_function_instrumentation_type_entry =
412 "ENTRY";
413
414/* String related to trigger */
415LTTNG_HIDDEN const char *const mi_lttng_element_triggers = "triggers";
416LTTNG_HIDDEN const char *const mi_lttng_element_trigger = "trigger";
417LTTNG_HIDDEN const char *const mi_lttng_element_trigger_owner_uid = "owner_uid";
418
419/* String related to error_query. */
420LTTNG_HIDDEN const char *const mi_lttng_element_error_query_result =
421 "error_query_result";
422LTTNG_HIDDEN const char *const mi_lttng_element_error_query_result_counter =
423 "error_query_result_counter";
424LTTNG_HIDDEN const char *const
425 mi_lttng_element_error_query_result_counter_value = "value";
426LTTNG_HIDDEN const char *const mi_lttng_element_error_query_result_description =
427 "description";
428LTTNG_HIDDEN const char *const mi_lttng_element_error_query_result_name =
429 "name";
430LTTNG_HIDDEN const char *const mi_lttng_element_error_query_result_type =
431 "type";
432LTTNG_HIDDEN const char *const mi_lttng_element_error_query_results =
433 "error_query_results";
434
59deec0c
JR
435/* String related to add-context command */
436LTTNG_HIDDEN const char * const mi_lttng_element_context_symbol = "symbol";
437
ae8c46e0
JG
438/* Deprecated symbols preserved for ABI compatibility. */
439const char * const mi_lttng_context_type_perf_counter;
440const char * const mi_lttng_context_type_perf_cpu_counter;
441const char * const mi_lttng_context_type_perf_thread_counter;
442const char * const mi_lttng_element_track_untrack_pid_target;
443const char * const mi_lttng_element_track_untrack_targets;
95057847
PP
444const char * const mi_lttng_element_calibrate;
445const char * const mi_lttng_element_calibrate_function;
446const char * const mi_lttng_element_command_calibrate;
ebbf5ab7 447
136f2f81
JRJ
448/* This is a merge of jul loglevel and regular loglevel
449 * Those should never overlap by definition
450 * (see struct lttng_event loglevel)
451 */
ea75976a 452LTTNG_HIDDEN
970d848b 453const char *mi_lttng_loglevel_string(int value, enum lttng_domain_type domain)
5e18ec73 454{
970d848b
DG
455 switch (domain) {
456 case LTTNG_DOMAIN_KERNEL:
457 case LTTNG_DOMAIN_UST:
458 switch (value) {
459 case -1:
460 return mi_lttng_element_empty;
461 case LTTNG_LOGLEVEL_EMERG:
462 return mi_lttng_loglevel_str_emerg;
463 case LTTNG_LOGLEVEL_ALERT:
464 return mi_lttng_loglevel_str_alert;
465 case LTTNG_LOGLEVEL_CRIT:
466 return mi_lttng_loglevel_str_crit;
467 case LTTNG_LOGLEVEL_ERR:
468 return mi_lttng_loglevel_str_err;
469 case LTTNG_LOGLEVEL_WARNING:
470 return mi_lttng_loglevel_str_warning;
471 case LTTNG_LOGLEVEL_NOTICE:
472 return mi_lttng_loglevel_str_notice;
473 case LTTNG_LOGLEVEL_INFO:
474 return mi_lttng_loglevel_str_info;
475 case LTTNG_LOGLEVEL_DEBUG_SYSTEM:
476 return mi_lttng_loglevel_str_debug_system;
477 case LTTNG_LOGLEVEL_DEBUG_PROGRAM:
478 return mi_lttng_loglevel_str_debug_program;
479 case LTTNG_LOGLEVEL_DEBUG_PROCESS:
480 return mi_lttng_loglevel_str_debug_process;
481 case LTTNG_LOGLEVEL_DEBUG_MODULE:
482 return mi_lttng_loglevel_str_debug_module;
483 case LTTNG_LOGLEVEL_DEBUG_UNIT:
484 return mi_lttng_loglevel_str_debug_unit;
485 case LTTNG_LOGLEVEL_DEBUG_FUNCTION:
486 return mi_lttng_loglevel_str_debug_function;
487 case LTTNG_LOGLEVEL_DEBUG_LINE:
488 return mi_lttng_loglevel_str_debug_line;
489 case LTTNG_LOGLEVEL_DEBUG:
490 return mi_lttng_loglevel_str_debug;
491 default:
492 return mi_lttng_loglevel_str_unknown;
493 }
494 break;
495 case LTTNG_DOMAIN_LOG4J:
496 switch (value) {
497 case -1:
498 return mi_lttng_element_empty;
499 case LTTNG_LOGLEVEL_LOG4J_OFF:
500 return mi_lttng_loglevel_str_log4j_off;
501 case LTTNG_LOGLEVEL_LOG4J_FATAL:
502 return mi_lttng_loglevel_str_log4j_fatal;
503 case LTTNG_LOGLEVEL_LOG4J_ERROR:
504 return mi_lttng_loglevel_str_log4j_error;
505 case LTTNG_LOGLEVEL_LOG4J_WARN:
506 return mi_lttng_loglevel_str_log4j_warn;
507 case LTTNG_LOGLEVEL_LOG4J_INFO:
508 return mi_lttng_loglevel_str_log4j_info;
509 case LTTNG_LOGLEVEL_LOG4J_DEBUG:
510 return mi_lttng_loglevel_str_log4j_debug;
511 case LTTNG_LOGLEVEL_LOG4J_TRACE:
512 return mi_lttng_loglevel_str_log4j_trace;
513 case LTTNG_LOGLEVEL_LOG4J_ALL:
514 return mi_lttng_loglevel_str_log4j_all;
515 default:
516 return mi_lttng_loglevel_str_unknown;
517 }
518 break;
519 case LTTNG_DOMAIN_JUL:
520 switch (value) {
521 case -1:
522 return mi_lttng_element_empty;
523 case LTTNG_LOGLEVEL_JUL_OFF:
524 return mi_lttng_loglevel_str_jul_off;
525 case LTTNG_LOGLEVEL_JUL_SEVERE:
526 return mi_lttng_loglevel_str_jul_severe;
527 case LTTNG_LOGLEVEL_JUL_WARNING:
528 return mi_lttng_loglevel_str_jul_warning;
529 case LTTNG_LOGLEVEL_JUL_INFO:
530 return mi_lttng_loglevel_str_jul_info;
531 case LTTNG_LOGLEVEL_JUL_CONFIG:
532 return mi_lttng_loglevel_str_jul_config;
533 case LTTNG_LOGLEVEL_JUL_FINE:
534 return mi_lttng_loglevel_str_jul_fine;
535 case LTTNG_LOGLEVEL_JUL_FINER:
536 return mi_lttng_loglevel_str_jul_finer;
537 case LTTNG_LOGLEVEL_JUL_FINEST:
538 return mi_lttng_loglevel_str_jul_finest;
539 case LTTNG_LOGLEVEL_JUL_ALL:
540 return mi_lttng_loglevel_str_jul_all;
541 default:
542 return mi_lttng_loglevel_str_unknown;
543 }
544 break;
0e115563
DG
545 case LTTNG_DOMAIN_PYTHON:
546 switch (value) {
547 case LTTNG_LOGLEVEL_PYTHON_CRITICAL:
548 return mi_lttng_loglevel_str_python_critical;
549 case LTTNG_LOGLEVEL_PYTHON_ERROR:
550 return mi_lttng_loglevel_str_python_error;
551 case LTTNG_LOGLEVEL_PYTHON_WARNING:
552 return mi_lttng_loglevel_str_python_warning;
553 case LTTNG_LOGLEVEL_PYTHON_INFO:
554 return mi_lttng_loglevel_str_python_info;
555 case LTTNG_LOGLEVEL_PYTHON_DEBUG:
556 return mi_lttng_loglevel_str_python_debug;
557 case LTTNG_LOGLEVEL_PYTHON_NOTSET:
558 return mi_lttng_loglevel_str_python_notset;
559 default:
560 return mi_lttng_loglevel_str_unknown;
561 }
562 break;
bc2718d1
JG
563 default:
564 return mi_lttng_loglevel_str_unknown;
5e18ec73
JR
565 }
566}
567
ea75976a 568LTTNG_HIDDEN
5e18ec73
JR
569const char *mi_lttng_logleveltype_string(enum lttng_loglevel_type value)
570{
571 switch (value) {
572 case LTTNG_EVENT_LOGLEVEL_ALL:
573 return mi_lttng_loglevel_type_all;
574 case LTTNG_EVENT_LOGLEVEL_RANGE:
575 return mi_lttng_loglevel_type_range;
576 case LTTNG_EVENT_LOGLEVEL_SINGLE:
577 return mi_lttng_loglevel_type_single;
578 default:
579 return mi_lttng_loglevel_type_unknown;
580 }
581}
582
f5a2d630 583static
5e18ec73
JR
584const char *mi_lttng_eventtype_string(enum lttng_event_type value)
585{
586 switch (value) {
587 case LTTNG_EVENT_ALL:
588 return config_event_type_all;
589 case LTTNG_EVENT_TRACEPOINT:
590 return config_event_type_tracepoint;
591 case LTTNG_EVENT_PROBE:
592 return config_event_type_probe;
5a1c0a75
FD
593 case LTTNG_EVENT_USERSPACE_PROBE:
594 return config_event_type_userspace_probe;
5e18ec73
JR
595 case LTTNG_EVENT_FUNCTION:
596 return config_event_type_function;
597 case LTTNG_EVENT_FUNCTION_ENTRY:
598 return config_event_type_function_entry;
599 case LTTNG_EVENT_SYSCALL:
600 return config_event_type_syscall;
601 case LTTNG_EVENT_NOOP:
602 return config_event_type_noop;
603 default:
604 return mi_lttng_element_empty;
605 }
606}
607
a23cb78a 608static
89b72577
JRJ
609const char *mi_lttng_event_contexttype_string(enum lttng_event_context_type val)
610{
611 switch (val) {
612 case LTTNG_EVENT_CONTEXT_PID:
613 return config_event_context_pid;
89b72577
JRJ
614 case LTTNG_EVENT_CONTEXT_PROCNAME:
615 return config_event_context_procname;
616 case LTTNG_EVENT_CONTEXT_PRIO:
617 return config_event_context_prio;
618 case LTTNG_EVENT_CONTEXT_NICE:
619 return config_event_context_nice;
620 case LTTNG_EVENT_CONTEXT_VPID:
621 return config_event_context_vpid;
622 case LTTNG_EVENT_CONTEXT_TID:
623 return config_event_context_tid;
624 case LTTNG_EVENT_CONTEXT_VTID:
625 return config_event_context_vtid;
626 case LTTNG_EVENT_CONTEXT_PPID:
627 return config_event_context_ppid;
628 case LTTNG_EVENT_CONTEXT_VPPID:
629 return config_event_context_vppid;
630 case LTTNG_EVENT_CONTEXT_PTHREAD_ID:
631 return config_event_context_pthread_id;
632 case LTTNG_EVENT_CONTEXT_HOSTNAME:
633 return config_event_context_hostname;
634 case LTTNG_EVENT_CONTEXT_IP:
635 return config_event_context_ip;
a72332c3
JR
636 case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE:
637 return config_event_context_interruptible;
638 case LTTNG_EVENT_CONTEXT_PREEMPTIBLE:
639 return config_event_context_preemptible;
640 case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE:
641 return config_event_context_need_reschedule;
642 case LTTNG_EVENT_CONTEXT_MIGRATABLE:
643 return config_event_context_migratable;
16c4c991
FD
644 case LTTNG_EVENT_CONTEXT_CALLSTACK_USER:
645 return config_event_context_callstack_user;
646 case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL:
647 return config_event_context_callstack_kernel;
65ae1ae9
JR
648 case LTTNG_EVENT_CONTEXT_CGROUP_NS:
649 return config_event_context_cgroup_ns;
650 case LTTNG_EVENT_CONTEXT_IPC_NS:
651 return config_event_context_ipc_ns;
652 case LTTNG_EVENT_CONTEXT_MNT_NS:
653 return config_event_context_mnt_ns;
654 case LTTNG_EVENT_CONTEXT_NET_NS:
655 return config_event_context_net_ns;
656 case LTTNG_EVENT_CONTEXT_PID_NS:
657 return config_event_context_pid_ns;
d37ac3cd
MJ
658 case LTTNG_EVENT_CONTEXT_TIME_NS:
659 return config_event_context_time_ns;
65ae1ae9
JR
660 case LTTNG_EVENT_CONTEXT_USER_NS:
661 return config_event_context_user_ns;
662 case LTTNG_EVENT_CONTEXT_UTS_NS:
663 return config_event_context_uts_ns;
664 case LTTNG_EVENT_CONTEXT_UID:
665 return config_event_context_uid;
666 case LTTNG_EVENT_CONTEXT_EUID:
667 return config_event_context_euid;
668 case LTTNG_EVENT_CONTEXT_SUID:
669 return config_event_context_suid;
670 case LTTNG_EVENT_CONTEXT_GID:
671 return config_event_context_gid;
672 case LTTNG_EVENT_CONTEXT_EGID:
673 return config_event_context_egid;
674 case LTTNG_EVENT_CONTEXT_SGID:
675 return config_event_context_sgid;
676 case LTTNG_EVENT_CONTEXT_VUID:
677 return config_event_context_vuid;
678 case LTTNG_EVENT_CONTEXT_VEUID:
679 return config_event_context_veuid;
680 case LTTNG_EVENT_CONTEXT_VSUID:
681 return config_event_context_vsuid;
682 case LTTNG_EVENT_CONTEXT_VGID:
683 return config_event_context_vgid;
684 case LTTNG_EVENT_CONTEXT_VEGID:
685 return config_event_context_vegid;
686 case LTTNG_EVENT_CONTEXT_VSGID:
687 return config_event_context_vsgid;
89b72577
JRJ
688 default:
689 return NULL;
690 }
691}
692
ea75976a 693LTTNG_HIDDEN
5e18ec73
JR
694const char *mi_lttng_eventfieldtype_string(enum lttng_event_field_type val)
695{
696 switch (val) {
697 case(LTTNG_EVENT_FIELD_INTEGER):
698 return mi_lttng_element_type_integer;
699 case(LTTNG_EVENT_FIELD_ENUM):
700 return mi_lttng_element_type_enum;
701 case(LTTNG_EVENT_FIELD_FLOAT):
702 return mi_lttng_element_type_float;
703 case(LTTNG_EVENT_FIELD_STRING):
704 return mi_lttng_element_type_string;
705 default:
706 return mi_lttng_element_type_other;
707 }
708}
709
ea75976a 710LTTNG_HIDDEN
5e18ec73
JR
711const char *mi_lttng_domaintype_string(enum lttng_domain_type value)
712{
5e18ec73
JR
713 switch (value) {
714 case LTTNG_DOMAIN_KERNEL:
715 return config_domain_type_kernel;
716 case LTTNG_DOMAIN_UST:
717 return config_domain_type_ust;
718 case LTTNG_DOMAIN_JUL:
719 return config_domain_type_jul;
5cdb6027
DG
720 case LTTNG_DOMAIN_LOG4J:
721 return config_domain_type_log4j;
b789735e
PP
722 case LTTNG_DOMAIN_PYTHON:
723 return config_domain_type_python;
5e18ec73
JR
724 default:
725 /* Should not have an unknown domain */
726 assert(0);
2855532e 727 return NULL;
5e18ec73
JR
728 }
729}
730
ea75976a 731LTTNG_HIDDEN
5e18ec73
JR
732const char *mi_lttng_buffertype_string(enum lttng_buffer_type value)
733{
734 switch (value) {
735 case LTTNG_BUFFER_PER_PID:
736 return config_buffer_type_per_pid;
737 case LTTNG_BUFFER_PER_UID:
738 return config_buffer_type_per_uid;
739 case LTTNG_BUFFER_GLOBAL:
740 return config_buffer_type_global;
741 default:
742 /* Should not have an unknow buffer type */
743 assert(0);
2855532e 744 return NULL;
5e18ec73
JR
745 }
746}
747
91c4d516
JG
748LTTNG_HIDDEN
749const char *mi_lttng_rotation_state_string(enum lttng_rotation_state value)
750{
751 switch (value) {
752 case LTTNG_ROTATION_STATE_ONGOING:
753 return mi_lttng_rotation_state_str_ongoing;
754 case LTTNG_ROTATION_STATE_COMPLETED:
755 return mi_lttng_rotation_state_str_completed;
756 case LTTNG_ROTATION_STATE_EXPIRED:
757 return mi_lttng_rotation_state_str_expired;
758 case LTTNG_ROTATION_STATE_ERROR:
759 return mi_lttng_rotation_state_str_error;
760 default:
761 /* Should not have an unknow rotation state. */
762 assert(0);
763 return NULL;
764 }
765}
766
767LTTNG_HIDDEN
768const char *mi_lttng_trace_archive_location_relay_protocol_type_string(
769 enum lttng_trace_archive_location_relay_protocol_type value)
770{
771 switch (value) {
772 case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP:
773 return mi_lttng_rotation_location_relay_protocol_str_tcp;
774 default:
0f7c2963 775 /* Should not have an unknown relay protocol. */
91c4d516
JG
776 assert(0);
777 return NULL;
778 }
779}
780
c7e35b03
JR
781LTTNG_HIDDEN
782struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type)
783{
784 struct mi_writer *mi_writer;
785
786 mi_writer = zmalloc(sizeof(struct mi_writer));
787 if (!mi_writer) {
788 PERROR("zmalloc mi_writer_create");
789 goto end;
790 }
791 if (mi_output_type == LTTNG_MI_XML) {
705bb62f 792 mi_writer->writer = config_writer_create(fd_output, 0);
c7e35b03
JR
793 if (!mi_writer->writer) {
794 goto err_destroy;
795 }
796 mi_writer->type = LTTNG_MI_XML;
797 } else {
798 goto err_destroy;
799 }
800
801end:
802 return mi_writer;
803
804err_destroy:
805 free(mi_writer);
806 return NULL;
807}
808
809LTTNG_HIDDEN
810int mi_lttng_writer_destroy(struct mi_writer *writer)
811{
812 int ret;
813
814 if (!writer) {
815 ret = -EINVAL;
816 goto end;
817 }
818
819 ret = config_writer_destroy(writer->writer);
820 if (ret < 0) {
821 goto end;
822 }
823
824 free(writer);
825end:
826 return ret;
827}
828
829LTTNG_HIDDEN
830int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command)
831{
832 int ret;
833
e10b6a1c
JG
834 /*
835 * A command is always the MI's root node, it must declare the current
836 * namespace and schema URIs and the schema's version.
837 */
838 ret = config_writer_open_element(writer->writer,
839 mi_lttng_element_command);
840 if (ret) {
841 goto end;
842 }
843
844 ret = config_writer_write_attribute(writer->writer,
41af1adf 845 mi_lttng_xmlns, DEFAULT_LTTNG_MI_NAMESPACE);
e10b6a1c
JG
846 if (ret) {
847 goto end;
848 }
849
850 ret = config_writer_write_attribute(writer->writer,
851 mi_lttng_xmlns_xsi, mi_lttng_w3_schema_uri);
c7e35b03
JR
852 if (ret) {
853 goto end;
854 }
e10b6a1c
JG
855
856 ret = config_writer_write_attribute(writer->writer,
857 mi_lttng_schema_location,
858 mi_lttng_schema_location_uri);
859 if (ret) {
860 goto end;
861 }
862
863 ret = config_writer_write_attribute(writer->writer,
864 mi_lttng_schema_version,
865 mi_lttng_schema_version_value);
866 if (ret) {
867 goto end;
868 }
869
c7e35b03
JR
870 ret = mi_lttng_writer_write_element_string(writer,
871 mi_lttng_element_command_name, command);
872end:
873 return ret;
874}
875
876LTTNG_HIDDEN
877int mi_lttng_writer_command_close(struct mi_writer *writer)
878{
879 return mi_lttng_writer_close_element(writer);
880}
881
882LTTNG_HIDDEN
883int mi_lttng_writer_open_element(struct mi_writer *writer,
884 const char *element_name)
885{
886 return config_writer_open_element(writer->writer, element_name);
887}
888
889LTTNG_HIDDEN
890int mi_lttng_writer_close_element(struct mi_writer *writer)
891{
892 return config_writer_close_element(writer->writer);
893}
894
5e18ec73
JR
895LTTNG_HIDDEN
896int mi_lttng_close_multi_element(struct mi_writer *writer,
897 unsigned int nb_element)
898{
899 int ret, i;
900
901 if (nb_element < 1) {
902 ret = 0;
903 goto end;
904 }
905 for (i = 0; i < nb_element; i++) {
906 ret = mi_lttng_writer_close_element(writer);
907 if (ret) {
908 goto end;
909 }
910 }
911end:
912 return ret;
913}
914
c7e35b03
JR
915LTTNG_HIDDEN
916int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer,
917 const char *element_name, uint64_t value)
918{
919 return config_writer_write_element_unsigned_int(writer->writer,
920 element_name, value);
921}
922
923LTTNG_HIDDEN
924int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer,
925 const char *element_name, int64_t value)
926{
927 return config_writer_write_element_signed_int(writer->writer,
928 element_name, value);
929}
930
931LTTNG_HIDDEN
932int mi_lttng_writer_write_element_bool(struct mi_writer *writer,
933 const char *element_name, int value)
934{
935 return config_writer_write_element_bool(writer->writer,
936 element_name, value);
937}
938
939LTTNG_HIDDEN
940int mi_lttng_writer_write_element_string(struct mi_writer *writer,
941 const char *element_name, const char *value)
942{
943 return config_writer_write_element_string(writer->writer,
944 element_name, value);
945}
946
7c9e11fd
JR
947LTTNG_HIDDEN
948int mi_lttng_writer_write_element_double(struct mi_writer *writer,
949 const char *element_name,
950 double value)
951{
952 return config_writer_write_element_double(
953 writer->writer, element_name, value);
954}
955
c7e35b03
JR
956LTTNG_HIDDEN
957int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version,
958 const char *lttng_description, const char *lttng_license)
959{
960 int ret;
961
962 /* Open version */
963 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_version);
964 if (ret) {
965 goto end;
966 }
967
968 /* Version string (contain info like rc etc.) */
969 ret = mi_lttng_writer_write_element_string(writer,
782f3c61 970 mi_lttng_element_version_str, version->version);
c7e35b03
JR
971 if (ret) {
972 goto end;
973 }
974
975 /* Major version number */
976 ret = mi_lttng_writer_write_element_unsigned_int(writer,
977 mi_lttng_element_version_major, version->version_major);
978 if (ret) {
979 goto end;
980 }
981
982 /* Minor version number */
983 ret = mi_lttng_writer_write_element_unsigned_int(writer,
984 mi_lttng_element_version_minor, version->version_minor);
985 if (ret) {
986 goto end;
987 }
988
314d5222
JRJ
989 /* Commit version number */
990 ret = mi_lttng_writer_write_element_string(writer,
991 mi_lttng_element_version_commit, version->version_commit);
992 if (ret) {
993 goto end;
994 }
995
c7e35b03
JR
996 /* Patch number */
997 ret = mi_lttng_writer_write_element_unsigned_int(writer,
998 mi_lttng_element_version_patch_level, version->version_patchlevel);
999 if (ret) {
1000 goto end;
1001 }
1002
1003 /* Name of the version */
1004 ret = mi_lttng_writer_write_element_string(writer,
1005 config_element_name, version->version_name);
1006 if (ret) {
1007 goto end;
1008 }
1009
1010 /* Description mostly related to beer... */
1011 ret = mi_lttng_writer_write_element_string(writer,
1012 mi_lttng_element_version_description, lttng_description);
1013 if (ret) {
1014 goto end;
1015 }
1016
1017 /* url */
1018 ret = mi_lttng_writer_write_element_string(writer,
1019 mi_lttng_element_version_web, version->package_url);
1020 if (ret) {
1021 goto end;
1022 }
1023
1024 /* License: free as in free beer...no...*speech* */
1025 ret = mi_lttng_writer_write_element_string(writer,
1026 mi_lttng_element_version_license, lttng_license);
1027 if (ret) {
1028 goto end;
1029 }
1030
1031 /* Close version element */
1032 ret = mi_lttng_writer_close_element(writer);
1033
1034end:
1035 return ret;
1036}
1037
5e18ec73
JR
1038LTTNG_HIDDEN
1039int mi_lttng_sessions_open(struct mi_writer *writer)
1040{
1041 return mi_lttng_writer_open_element(writer, config_element_sessions);
1042}
1043
c7e35b03
JR
1044LTTNG_HIDDEN
1045int mi_lttng_session(struct mi_writer *writer,
1046 struct lttng_session *session, int is_open)
1047{
1048 int ret;
1049
5e18ec73
JR
1050 assert(session);
1051
1052 /* Open sessions element */
c7e35b03
JR
1053 ret = mi_lttng_writer_open_element(writer,
1054 config_element_session);
1055 if (ret) {
1056 goto end;
1057 }
1058
1059 /* Name of the session */
1060 ret = mi_lttng_writer_write_element_string(writer,
1061 config_element_name, session->name);
1062 if (ret) {
1063 goto end;
1064 }
1065
5e18ec73 1066 /* Path */
c7e35b03
JR
1067 ret = mi_lttng_writer_write_element_string(writer,
1068 config_element_path, session->path);
1069 if (ret) {
1070 goto end;
1071 }
1072
5e18ec73
JR
1073 /* Enabled ? */
1074 ret = mi_lttng_writer_write_element_bool(writer,
c7e35b03
JR
1075 config_element_enabled, session->enabled);
1076 if (ret) {
1077 goto end;
1078 }
1079
5e18ec73 1080 /* Snapshot mode */
c7e35b03
JR
1081 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1082 config_element_snapshot_mode, session->snapshot_mode);
1083 if (ret) {
1084 goto end;
1085 }
1086
5e18ec73 1087 /* Live timer interval in usec */
c7e35b03
JR
1088 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1089 config_element_live_timer_interval,
1090 session->live_timer_interval);
1091 if (ret) {
1092 goto end;
1093 }
1094
1095 if (!is_open) {
1096 /* Closing session element */
1097 ret = mi_lttng_writer_close_element(writer);
1098 }
1099end:
1100 return ret;
1101
1102}
5e18ec73
JR
1103
1104LTTNG_HIDDEN
1105int mi_lttng_domains_open(struct mi_writer *writer)
1106{
1107 return mi_lttng_writer_open_element(writer, config_element_domains);
1108}
1109
1110LTTNG_HIDDEN
1111int mi_lttng_domain(struct mi_writer *writer,
1112 struct lttng_domain *domain, int is_open)
1113{
1114 int ret = 0;
1115 const char *str_domain;
1116 const char *str_buffer;
1117
1118 assert(domain);
1119
1120 /* Open domain element */
1121 ret = mi_lttng_writer_open_element(writer, config_element_domain);
1122 if (ret) {
1123 goto end;
1124 }
1125
1126 /* Domain Type */
1127 str_domain = mi_lttng_domaintype_string(domain->type);
1128 ret = mi_lttng_writer_write_element_string(writer, config_element_type,
1129 str_domain);
1130 if (ret) {
1131 goto end;
1132 }
1133
1134 /* Buffer Type */
1135 str_buffer= mi_lttng_buffertype_string(domain->buf_type);
1136 ret = mi_lttng_writer_write_element_string(writer,
1137 config_element_buffer_type, str_buffer);
1138 if (ret) {
1139 goto end;
1140 }
1141
d813f89b
JRJ
1142 /* TODO: union attr
1143 * This union is not currently used and was added for
1144 * future ust domain support.
1145 * Date: 25-06-2014
1146 * */
5e18ec73
JR
1147
1148 if (!is_open) {
1149 /* Closing domain element */
1150 ret = mi_lttng_writer_close_element(writer);
1151 }
1152
1153end:
1154 return ret;
1155
1156}
1157
1158LTTNG_HIDDEN
1159int mi_lttng_channels_open(struct mi_writer *writer)
1160{
1161 return mi_lttng_writer_open_element(writer, config_element_channels);
1162}
1163
1164LTTNG_HIDDEN
1165int mi_lttng_channel(struct mi_writer *writer,
1166 struct lttng_channel *channel, int is_open)
1167{
1168 int ret = 0;
1169
1170 assert(channel);
1171
1172 /* Opening channel element */
1173 ret = mi_lttng_writer_open_element(writer, config_element_channel);
1174 if (ret) {
1175 goto end;
1176 }
1177
1178 /* Name */
1179 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
1180 channel->name);
1181 if (ret) {
1182 goto end;
1183 }
1184
1185 /* Enabled ? */
1186 ret = mi_lttng_writer_write_element_bool(writer,
1187 config_element_enabled, channel->enabled);
1188 if (ret) {
1189 goto end;
1190 }
1191
1192 /* Attribute */
1193 ret = mi_lttng_channel_attr(writer, &channel->attr);
1194 if (ret) {
1195 goto end;
1196 }
1197
1198 if (!is_open) {
1199 /* Closing channel element */
1200 ret = mi_lttng_writer_close_element(writer);
1201 if (ret) {
1202 goto end;
1203 }
1204 }
1205end:
1206 return ret;
1207}
1208
1209LTTNG_HIDDEN
1210int mi_lttng_channel_attr(struct mi_writer *writer,
1211 struct lttng_channel_attr *attr)
1212{
1213 int ret = 0;
fb83fe64
JD
1214 struct lttng_channel *chan = caa_container_of(attr,
1215 struct lttng_channel, attr);
cf0bcb51 1216 uint64_t discarded_events, lost_packets, monitor_timer_interval;
491d1539 1217 int64_t blocking_timeout;
5e18ec73
JR
1218
1219 assert(attr);
1220
fb83fe64
JD
1221 ret = lttng_channel_get_discarded_event_count(chan, &discarded_events);
1222 if (ret) {
1223 goto end;
1224 }
1225
1226 ret = lttng_channel_get_lost_packet_count(chan, &lost_packets);
1227 if (ret) {
1228 goto end;
1229 }
1230
cf0bcb51
JG
1231 ret = lttng_channel_get_monitor_timer_interval(chan,
1232 &monitor_timer_interval);
1233 if (ret) {
1234 goto end;
1235 }
1236
491d1539
MD
1237 ret = lttng_channel_get_blocking_timeout(chan,
1238 &blocking_timeout);
1239 if (ret) {
1240 goto end;
1241 }
1242
5e18ec73
JR
1243 /* Opening Attributes */
1244 ret = mi_lttng_writer_open_element(writer, config_element_attributes);
1245 if (ret) {
1246 goto end;
1247 }
1248
1249 /* Overwrite */
1250 ret = mi_lttng_writer_write_element_string(writer,
1251 config_element_overwrite_mode,
1252 attr->overwrite ? config_overwrite_mode_overwrite :
1253 config_overwrite_mode_discard);
1254 if (ret) {
1255 goto end;
1256 }
1257
1258 /* Sub buffer size in byte */
1259 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1260 config_element_subbuf_size, attr->subbuf_size);
1261 if (ret) {
1262 goto end;
1263 }
1264
1265 /* Number of subbuffer (power of two) */
1266 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1267 config_element_num_subbuf,
1268 attr->num_subbuf);
1269 if (ret) {
1270 goto end;
1271 }
1272
1273 /* Switch timer interval in usec */
1274 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1275 config_element_switch_timer_interval,
1276 attr->switch_timer_interval);
1277 if (ret) {
1278 goto end;
1279 }
1280
1281 /* Read timer interval in usec */
1282 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1283 config_element_read_timer_interval,
1284 attr->read_timer_interval);
1285 if (ret) {
1286 goto end;
1287 }
1288
cf0bcb51
JG
1289 /* Monitor timer interval in usec */
1290 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1291 config_element_monitor_timer_interval,
1292 monitor_timer_interval);
1293 if (ret) {
1294 goto end;
1295 }
1296
491d1539
MD
1297 /* Retry timeout in usec */
1298 ret = mi_lttng_writer_write_element_signed_int(writer,
1299 config_element_blocking_timeout,
1300 blocking_timeout);
1301 if (ret) {
1302 goto end;
1303 }
1304
5e18ec73
JR
1305 /* Event output */
1306 ret = mi_lttng_writer_write_element_string(writer,
1307 config_element_output_type,
1308 attr->output == LTTNG_EVENT_SPLICE ?
1309 config_output_type_splice : config_output_type_mmap);
1310 if (ret) {
1311 goto end;
1312 }
1313
1314 /* Tracefile size in bytes */
1315 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1316 config_element_tracefile_size, attr->tracefile_size);
1317 if (ret) {
1318 goto end;
1319 }
1320
1321 /* Count of tracefiles */
1322 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1323 config_element_tracefile_count,
1324 attr->tracefile_count);
1325 if (ret) {
1326 goto end;
1327 }
1328
1329 /* Live timer interval in usec*/
1330 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1331 config_element_live_timer_interval,
1332 attr->live_timer_interval);
1333 if (ret) {
fb83fe64
JD
1334 goto end;
1335 }
1336
1337 /* Discarded events */
1338 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1339 config_element_discarded_events,
1340 discarded_events);
1341 if (ret) {
1342 goto end;
1343 }
1344
1345 /* Lost packets */
1346 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1347 config_element_lost_packets,
1348 lost_packets);
1349 if (ret) {
5e18ec73
JR
1350 goto end;
1351 }
1352
1353 /* Closing attributes */
1354 ret = mi_lttng_writer_close_element(writer);
1355 if (ret) {
1356 goto end;
1357 }
1358end:
1359 return ret;
1360
1361}
1362
1363LTTNG_HIDDEN
1364int mi_lttng_event_common_attributes(struct mi_writer *writer,
1365 struct lttng_event *event)
1366{
1367 int ret;
7b4aa11d 1368 const char *filter_expression;
5e18ec73
JR
1369
1370 /* Open event element */
1371 ret = mi_lttng_writer_open_element(writer, config_element_event);
1372 if (ret) {
1373 goto end;
1374 }
1375
f4a088f7 1376 /* Event name */
5e18ec73
JR
1377 ret = mi_lttng_writer_write_element_string(writer,
1378 config_element_name, event->name);
1379 if (ret) {
1380 goto end;
1381 }
1382
f4a088f7 1383 /* Event type */
5e18ec73
JR
1384 ret = mi_lttng_writer_write_element_string(writer,
1385 config_element_type, mi_lttng_eventtype_string(event->type));
1386 if (ret) {
1387 goto end;
1388 }
1389
f4a088f7 1390 /* Is event enabled */
5e18ec73
JR
1391 ret = mi_lttng_writer_write_element_bool(writer,
1392 config_element_enabled, event->enabled);
1393 if (ret) {
1394 goto end;
1395 }
1396
7b4aa11d 1397 /* Event filter expression */
134e72ed 1398 ret = lttng_event_get_filter_expression(event, &filter_expression);
7b4aa11d
PP
1399 if (ret) {
1400 goto end;
1401 }
1402
1403 if (filter_expression) {
1404 ret = mi_lttng_writer_write_element_string(writer,
654f9f5e
JG
1405 config_element_filter_expression,
1406 filter_expression);
7b4aa11d
PP
1407 if (ret) {
1408 goto end;
1409 }
1410 }
1411
5e18ec73
JR
1412end:
1413 return ret;
1414}
1415
eecb9438
PP
1416static int write_event_exclusions(struct mi_writer *writer,
1417 struct lttng_event *event)
1418{
1419 int i;
1420 int ret;
1421 int exclusion_count;
1422
eecb9438
PP
1423 /* Open event exclusions */
1424 ret = mi_lttng_writer_open_element(writer, config_element_exclusions);
1425 if (ret) {
1426 goto end;
1427 }
1428
1429 exclusion_count = lttng_event_get_exclusion_name_count(event);
1430 if (exclusion_count < 0) {
1431 ret = exclusion_count;
1432 goto end;
1433 }
1434
1435 for (i = 0; i < exclusion_count; i++) {
1436 const char *name;
1437
1438 ret = lttng_event_get_exclusion_name(event, i, &name);
1439 if (ret) {
1440 /* Close exclusions */
1441 mi_lttng_writer_close_element(writer);
1442 goto end;
1443 }
1444
1445 ret = mi_lttng_writer_write_element_string(writer,
1446 config_element_exclusion, name);
1447 if (ret) {
1448 /* Close exclusions */
1449 mi_lttng_writer_close_element(writer);
1450 goto end;
1451 }
1452 }
1453
1454 /* Close exclusions */
1455 ret = mi_lttng_writer_close_element(writer);
1456
1457end:
1458 return ret;
1459}
1460
5e18ec73
JR
1461LTTNG_HIDDEN
1462int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer,
970d848b 1463 struct lttng_event *event, enum lttng_domain_type domain)
5e18ec73
JR
1464{
1465 int ret;
1466
f4a088f7 1467 /* Event loglevel */
5e18ec73 1468 ret = mi_lttng_writer_write_element_string(writer,
970d848b
DG
1469 config_element_loglevel,
1470 mi_lttng_loglevel_string(event->loglevel, domain));
5e18ec73
JR
1471 if (ret) {
1472 goto end;
1473 }
1474
f4a088f7 1475 /* Log level type */
5e18ec73
JR
1476 ret = mi_lttng_writer_write_element_string(writer,
1477 config_element_loglevel_type,
1478 mi_lttng_logleveltype_string(event->loglevel_type));
1479 if (ret) {
1480 goto end;
1481 }
1482
eecb9438
PP
1483 /* Event exclusions */
1484 ret = write_event_exclusions(writer, event);
5e18ec73
JR
1485
1486end:
1487 return ret;
1488}
1489
1490LTTNG_HIDDEN
1491int mi_lttng_event_tracepoint_no_loglevel(struct mi_writer *writer,
1492 struct lttng_event *event)
1493{
1494 /* event exclusion filter */
eecb9438 1495 return write_event_exclusions(writer, event);
5e18ec73
JR
1496}
1497
1498LTTNG_HIDDEN
1499int mi_lttng_event_function_probe(struct mi_writer *writer,
1500 struct lttng_event *event)
1501{
1502 int ret;
1503
3b4a6e40
JRJ
1504 ret = mi_lttng_writer_open_element(writer, config_element_attributes);
1505 if (ret) {
1506 goto end;
1507 }
1508
1509 ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes);
1510 if (ret) {
1511 goto end;
1512 }
1513
5e18ec73
JR
1514 if (event->attr.probe.addr != 0) {
1515 /* event probe address */
1516 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1517 config_element_address, event->attr.probe.addr);
1518 if (ret) {
1519 goto end;
1520 }
1521 } else {
1522 /* event probe offset */
1523 ret = mi_lttng_writer_write_element_unsigned_int(writer,
1524 config_element_offset, event->attr.probe.offset);
1525 if (ret) {
1526 goto end;
1527 }
1528
1529 /* event probe symbol_name */
1530 ret = mi_lttng_writer_write_element_string(writer,
1531 config_element_symbol_name, event->attr.probe.symbol_name);
1532 if (ret) {
1533 goto end;
1534 }
1535 }
3b4a6e40
JRJ
1536
1537 /* Close probe_attributes and attributes */
1538 ret = mi_lttng_close_multi_element(writer, 2);
5e18ec73
JR
1539end:
1540 return ret;
1541}
1542
f5a2d630 1543static
5a1c0a75
FD
1544int mi_lttng_event_userspace_probe(struct mi_writer *writer,
1545 struct lttng_event *event)
1546{
1547 int ret;
87597c2c
JG
1548 const struct lttng_userspace_probe_location *location;
1549 const struct lttng_userspace_probe_location_lookup_method *lookup_method;
5a1c0a75
FD
1550 enum lttng_userspace_probe_location_lookup_method_type lookup_type;
1551
1552 location = lttng_event_get_userspace_probe_location(event);
1553 if (!location) {
1554 ret = -LTTNG_ERR_INVALID;
1555 goto end;
1556 }
1557
1558 lookup_method = lttng_userspace_probe_location_get_lookup_method(location);
1559 if (!lookup_method) {
1560 ret = -LTTNG_ERR_INVALID;
1561 goto end;
1562 }
1563
1564 lookup_type = lttng_userspace_probe_location_lookup_method_get_type(lookup_method);
1565
1566 ret = mi_lttng_writer_open_element(writer, config_element_attributes);
1567 if (ret) {
1568 goto end;
1569 }
1570
1571 switch (lttng_userspace_probe_location_get_type(location)) {
1572 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION:
1573 {
1574 const char *function_name;
1575 const char *binary_path;
1576
1577 ret = mi_lttng_writer_open_element(writer,
1578 config_element_userspace_probe_function_attributes);
1579 if (ret) {
1580 goto end;
1581 }
1582
1583 switch (lookup_type) {
1584 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF:
1585 ret = mi_lttng_writer_write_element_string(writer,
1586 config_element_userspace_probe_lookup,
1587 config_element_userspace_probe_lookup_function_elf);
1588 if (ret) {
1589 goto end;
1590 }
1591 break;
1592 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT:
1593 ret = mi_lttng_writer_write_element_string(writer,
1594 config_element_userspace_probe_lookup,
1595 config_element_userspace_probe_lookup_function_default);
1596 if (ret) {
1597 goto end;
1598 }
1599 break;
1600 default:
1601 goto end;
1602 }
1603
1604 binary_path = lttng_userspace_probe_location_function_get_binary_path(location);
1605 ret = mi_lttng_writer_write_element_string(writer,
1606 config_element_userspace_probe_location_binary_path, binary_path);
1607 if (ret) {
1608 goto end;
1609 }
1610
1611 function_name = lttng_userspace_probe_location_function_get_function_name(location);
1612 ret = mi_lttng_writer_write_element_string(writer,
1613 config_element_userspace_probe_function_location_function_name,
1614 function_name);
1615 if (ret) {
1616 goto end;
1617 }
1618
1619 break;
1620 }
1621 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT:
1622 {
1623 const char *probe_name, *provider_name;
1624 const char *binary_path;
1625
1626 ret = mi_lttng_writer_open_element(writer,
1627 config_element_userspace_probe_function_attributes);
1628 if (ret) {
1629 goto end;
1630 }
1631
1632 switch (lookup_type) {
1633 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT:
1634 ret = mi_lttng_writer_write_element_string(writer,
1635 config_element_userspace_probe_lookup,
1636 config_element_userspace_probe_lookup_tracepoint_sdt);
1637 if (ret) {
1638 goto end;
1639 }
1640 break;
1641 default:
1642 goto end;
1643 }
1644
1645 binary_path = lttng_userspace_probe_location_tracepoint_get_binary_path(location);
1646 ret = mi_lttng_writer_write_element_string(writer,
1647 config_element_userspace_probe_location_binary_path,
1648 binary_path);
1649 if (ret) {
1650 goto end;
1651 }
1652
1653 provider_name = lttng_userspace_probe_location_tracepoint_get_provider_name(location);
1654 ret = mi_lttng_writer_write_element_string(writer,
1655 config_element_userspace_probe_tracepoint_location_provider_name,
1656 provider_name);
1657 if (ret) {
1658 goto end;
1659 }
1660
1661 probe_name = lttng_userspace_probe_location_tracepoint_get_probe_name(location);
1662 ret = mi_lttng_writer_write_element_string(writer,
1663 config_element_userspace_probe_tracepoint_location_probe_name, probe_name);
1664 if (ret) {
1665 goto end;
1666 }
1667 break;
1668 }
1669 default:
1670 ERR("Invalid probe type encountered");
1671 }
1672 /* Close probe_attributes and attributes */
1673 ret = mi_lttng_close_multi_element(writer, 2);
1674end:
1675 return ret;
1676}
1677
5e18ec73
JR
1678LTTNG_HIDDEN
1679int mi_lttng_event_function_entry(struct mi_writer *writer,
1680 struct lttng_event *event)
1681{
3b4a6e40
JRJ
1682 int ret;
1683
1684 ret = mi_lttng_writer_open_element(writer, config_element_attributes);
1685 if (ret) {
1686 goto end;
1687 }
1688
1689 ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes);
1690 if (ret) {
1691 goto end;
1692 }
1693
5e18ec73 1694 /* event probe symbol_name */
3b4a6e40 1695 ret = mi_lttng_writer_write_element_string(writer,
5e18ec73 1696 config_element_symbol_name, event->attr.ftrace.symbol_name);
3b4a6e40
JRJ
1697 if (ret) {
1698 goto end;
1699 }
1700
1701 /* Close function_attributes and attributes */
1702 ret = mi_lttng_close_multi_element(writer, 2);
1703end:
1704 return ret;
5e18ec73
JR
1705}
1706
1707LTTNG_HIDDEN
1708int mi_lttng_events_open(struct mi_writer *writer)
1709{
1710 return mi_lttng_writer_open_element(writer, config_element_events);
1711}
1712
1713LTTNG_HIDDEN
1714int mi_lttng_event(struct mi_writer *writer,
970d848b 1715 struct lttng_event *event, int is_open, enum lttng_domain_type domain)
5e18ec73
JR
1716{
1717 int ret;
1718
1719 ret = mi_lttng_event_common_attributes(writer, event);
1720 if (ret) {
1721 goto end;
1722 }
1723
1724 switch (event->type) {
5e18ec73
JR
1725 case LTTNG_EVENT_TRACEPOINT:
1726 {
1727 if (event->loglevel != -1) {
970d848b 1728 ret = mi_lttng_event_tracepoint_loglevel(writer, event, domain);
5e18ec73
JR
1729 } else {
1730 ret = mi_lttng_event_tracepoint_no_loglevel(writer, event);
1731 }
1732 break;
1733 }
3b4a6e40
JRJ
1734 case LTTNG_EVENT_FUNCTION:
1735 /* Fallthrough */
5e18ec73
JR
1736 case LTTNG_EVENT_PROBE:
1737 ret = mi_lttng_event_function_probe(writer, event);
1738 break;
1739 case LTTNG_EVENT_FUNCTION_ENTRY:
1740 ret = mi_lttng_event_function_entry(writer, event);
1741 break;
5a1c0a75
FD
1742 case LTTNG_EVENT_USERSPACE_PROBE:
1743 ret = mi_lttng_event_userspace_probe(writer, event);
1744 break;
89476427
JRJ
1745 case LTTNG_EVENT_ALL:
1746 /* Fallthrough */
5e18ec73
JR
1747 default:
1748 break;
1749 }
1750
5a1c0a75
FD
1751 if (ret) {
1752 goto end;
1753 }
1754
5e18ec73
JR
1755 if (!is_open) {
1756 ret = mi_lttng_writer_close_element(writer);
1757 }
1758
1759end:
1760 return ret;
1761}
1762
ebbf5ab7
JR
1763LTTNG_HIDDEN
1764int mi_lttng_trackers_open(struct mi_writer *writer)
1765{
159b042f
JG
1766 return mi_lttng_writer_open_element(
1767 writer, config_element_process_attr_trackers);
ebbf5ab7
JR
1768}
1769
159b042f
JG
1770static int get_tracker_elements(enum lttng_process_attr process_attr,
1771 const char **element_process_attr_tracker,
1772 const char **element_process_attr_value)
83d6d6c4
JR
1773{
1774 int ret = 0;
1775
159b042f
JG
1776 switch (process_attr) {
1777 case LTTNG_PROCESS_ATTR_PROCESS_ID:
1778 *element_process_attr_tracker =
1779 config_element_process_attr_tracker_pid;
1780 *element_process_attr_value =
1781 config_element_process_attr_pid_value;
83d6d6c4 1782 break;
159b042f
JG
1783 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
1784 *element_process_attr_tracker =
1785 config_element_process_attr_tracker_vpid;
1786 *element_process_attr_value =
1787 config_element_process_attr_vpid_value;
83d6d6c4 1788 break;
159b042f
JG
1789 case LTTNG_PROCESS_ATTR_USER_ID:
1790 *element_process_attr_tracker =
1791 config_element_process_attr_tracker_uid;
1792 *element_process_attr_value =
1793 config_element_process_attr_uid_value;
83d6d6c4 1794 break;
159b042f
JG
1795 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID:
1796 *element_process_attr_tracker =
1797 config_element_process_attr_tracker_vuid;
1798 *element_process_attr_value =
1799 config_element_process_attr_vuid_value;
83d6d6c4 1800 break;
159b042f
JG
1801 case LTTNG_PROCESS_ATTR_GROUP_ID:
1802 *element_process_attr_tracker =
1803 config_element_process_attr_tracker_gid;
1804 *element_process_attr_value =
1805 config_element_process_attr_gid_value;
83d6d6c4 1806 break;
159b042f
JG
1807 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID:
1808 *element_process_attr_tracker =
1809 config_element_process_attr_tracker_vgid;
1810 *element_process_attr_value =
1811 config_element_process_attr_vgid_value;
83d6d6c4
JR
1812 break;
1813 default:
1814 ret = LTTNG_ERR_SAVE_IO_FAIL;
1815 }
1816 return ret;
1817}
1818
ebbf5ab7 1819LTTNG_HIDDEN
159b042f
JG
1820int mi_lttng_process_attribute_tracker_open(
1821 struct mi_writer *writer, enum lttng_process_attr process_attr)
ebbf5ab7
JR
1822{
1823 int ret;
159b042f 1824 const char *element_tracker, *element_value;
83d6d6c4
JR
1825
1826 ret = get_tracker_elements(
159b042f 1827 process_attr, &element_tracker, &element_value);
83d6d6c4
JR
1828 if (ret) {
1829 return ret;
1830 }
ebbf5ab7 1831
159b042f
JG
1832 /* Open process attribute tracker element */
1833 ret = mi_lttng_writer_open_element(writer, element_tracker);
ebbf5ab7
JR
1834 if (ret) {
1835 goto end;
1836 }
1837
159b042f
JG
1838 /* Open values element */
1839 ret = mi_lttng_process_attr_values_open(writer);
ebbf5ab7
JR
1840end:
1841 return ret;
1842}
1843
5e18ec73
JR
1844LTTNG_HIDDEN
1845int mi_lttng_pids_open(struct mi_writer *writer)
1846{
ebbf5ab7
JR
1847 return mi_lttng_writer_open_element(writer, config_element_pids);
1848}
1849
bf239d4c
JR
1850/*
1851 * TODO: move the listing of pid for user agent to process semantic on
1852 * mi api bump. The use of process element break the mi api.
1853 */
ebbf5ab7 1854LTTNG_HIDDEN
83d6d6c4
JR
1855int mi_lttng_pid(struct mi_writer *writer,
1856 pid_t pid,
1857 const char *name,
5e18ec73
JR
1858 int is_open)
1859{
1860 int ret;
1861
bf239d4c
JR
1862 /* Open pid process */
1863 ret = mi_lttng_writer_open_element(writer, config_element_pid);
5e18ec73
JR
1864 if (ret) {
1865 goto end;
1866 }
1867
1868 /* Writing pid number */
1869 ret = mi_lttng_writer_write_element_signed_int(writer,
bf239d4c 1870 mi_lttng_element_pid_id, (int)pid);
5e18ec73
JR
1871 if (ret) {
1872 goto end;
1873 }
1874
1875 /* Writing name of the process */
ebbf5ab7
JR
1876 if (name) {
1877 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
1878 name);
1879 if (ret) {
1880 goto end;
1881 }
1882 }
1883
1884 if (!is_open) {
1885 /* Closing Pid */
1886 ret = mi_lttng_writer_close_element(writer);
1887 }
1888
1889end:
1890 return ret;
1891}
1892
1893LTTNG_HIDDEN
159b042f 1894int mi_lttng_process_attr_values_open(struct mi_writer *writer)
ebbf5ab7 1895{
159b042f
JG
1896 return mi_lttng_writer_open_element(
1897 writer, config_element_process_attr_values);
ebbf5ab7
JR
1898}
1899
1900LTTNG_HIDDEN
159b042f
JG
1901int mi_lttng_all_process_attribute_value(struct mi_writer *writer,
1902 enum lttng_process_attr process_attr,
1903 bool is_open)
ebbf5ab7
JR
1904{
1905 int ret;
83d6d6c4 1906 const char *element_id_tracker, *element_target_id;
ebbf5ab7 1907
83d6d6c4 1908 ret = get_tracker_elements(
159b042f 1909 process_attr, &element_id_tracker, &element_target_id);
ebbf5ab7 1910 if (ret) {
83d6d6c4 1911 return ret;
ebbf5ab7
JR
1912 }
1913
159b042f
JG
1914 ret = mi_lttng_writer_open_element(writer, element_target_id);
1915 if (ret) {
1916 goto end;
1917 }
2d97a006 1918
159b042f
JG
1919 ret = mi_lttng_writer_open_element(writer, config_element_type);
1920 if (ret) {
1921 goto end;
1922 }
2d97a006 1923
159b042f
JG
1924 ret = mi_lttng_writer_write_element_bool(writer, config_element_all, 1);
1925 if (ret) {
1926 goto end;
1927 }
1928
1929 ret = mi_lttng_writer_close_element(writer);
1930 if (ret) {
1931 goto end;
1932 }
1933
1934 if (!is_open) {
83d6d6c4
JR
1935 ret = mi_lttng_writer_close_element(writer);
1936 if (ret) {
1937 goto end;
1938 }
159b042f
JG
1939 }
1940end:
1941 return ret;
1942}
2d97a006 1943
159b042f
JG
1944LTTNG_HIDDEN
1945int mi_lttng_integral_process_attribute_value(struct mi_writer *writer,
1946 enum lttng_process_attr process_attr,
1947 int64_t value,
1948 bool is_open)
1949{
1950 int ret;
1951 const char *element_id_tracker, *element_target_id;
2d97a006 1952
159b042f
JG
1953 ret = get_tracker_elements(
1954 process_attr, &element_id_tracker, &element_target_id);
1955 if (ret) {
1956 return ret;
1957 }
1958
1959 ret = mi_lttng_writer_open_element(writer, element_target_id);
1960 if (ret) {
1961 goto end;
1962 }
1963
1964 ret = mi_lttng_writer_open_element(writer, config_element_type);
1965 if (ret) {
1966 goto end;
1967 }
1968
1969 ret = mi_lttng_writer_write_element_signed_int(
1970 writer, config_element_process_attr_id, value);
1971 if (ret) {
1972 goto end;
1973 }
1974
1975 ret = mi_lttng_writer_close_element(writer);
1976 if (ret) {
1977 goto end;
1978 }
1979
1980 if (!is_open) {
83d6d6c4
JR
1981 ret = mi_lttng_writer_close_element(writer);
1982 if (ret) {
1983 goto end;
1984 }
159b042f
JG
1985 }
1986
1987end:
1988 return ret;
1989}
1990
1991LTTNG_HIDDEN
1992int mi_lttng_string_process_attribute_value(struct mi_writer *writer,
1993 enum lttng_process_attr process_attr,
1994 const char *value,
1995 bool is_open)
1996
1997{
1998 int ret;
1999 const char *element_id_tracker, *element_target_id;
2000
2001 ret = get_tracker_elements(
2002 process_attr, &element_id_tracker, &element_target_id);
2003 if (ret) {
2004 return ret;
2005 }
2006
2007 ret = mi_lttng_writer_open_element(writer, element_target_id);
2008 if (ret) {
2009 goto end;
2010 }
2011
2012 ret = mi_lttng_writer_open_element(writer, config_element_type);
2013 if (ret) {
2014 goto end;
2015 }
2016
2017 ret = mi_lttng_writer_write_element_string(
2018 writer, config_element_name, value);
2019 if (ret) {
2020 goto end;
2021 }
2022
2023 ret = mi_lttng_writer_close_element(writer);
2024 if (ret) {
83d6d6c4 2025 goto end;
ebbf5ab7 2026 }
5e18ec73
JR
2027
2028 if (!is_open) {
5e18ec73 2029 ret = mi_lttng_writer_close_element(writer);
ebbf5ab7
JR
2030 if (ret) {
2031 goto end;
2032 }
5e18ec73
JR
2033 }
2034
2035end:
2036 return ret;
2037}
2038
2039LTTNG_HIDDEN
2040int mi_lttng_event_fields_open(struct mi_writer *writer)
2041{
2042 return mi_lttng_writer_open_element(writer, mi_lttng_element_event_fields);
2043}
2044
2045LTTNG_HIDDEN
2046int mi_lttng_event_field(struct mi_writer *writer,
2047 struct lttng_event_field *field)
2048{
2049 int ret;
2050
2051 if (!field->field_name[0]) {
5e18ec73
JR
2052 ret = 0;
2053 goto end;
2054 }
2055
2056 /* Open field */
2057 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_event_field);
2058 if (ret) {
2059 goto end;
2060 }
2061
2062 if (!field->field_name[0]) {
2063 goto close;
2064 }
2065
2066 /* Name */
2067 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
2068 field->field_name);
2069 if (ret) {
2070 goto end;
2071 }
2072
2073 /* Type */
2074 ret = mi_lttng_writer_write_element_string(writer, config_element_type,
2075 mi_lttng_eventfieldtype_string(field->type));
2076 if (ret) {
2077 goto end;
2078 }
2079
2080 /* nowrite */
2081 ret = mi_lttng_writer_write_element_signed_int(writer,
2082 mi_lttng_element_nowrite, field->nowrite);
2083 if (ret) {
2084 goto end;
2085 }
2086
2087close:
2088 /* Close field element */
2089 ret = mi_lttng_writer_close_element(writer);
2090
2091end:
2092 return ret;
2093}
7e66b1b0 2094
89b72577 2095LTTNG_HIDDEN
a23cb78a
JG
2096int mi_lttng_perf_counter_context(struct mi_writer *writer,
2097 struct lttng_event_perf_counter_ctx *perf_context)
89b72577
JRJ
2098{
2099 int ret;
a23cb78a
JG
2100
2101 /* Open perf_counter_context */
2102 ret = mi_lttng_writer_open_element(writer,
2103 mi_lttng_element_perf_counter_context);
89b72577
JRJ
2104 if (ret) {
2105 goto end;
2106 }
2107
a23cb78a
JG
2108 /* Type */
2109 ret = mi_lttng_writer_write_element_unsigned_int(writer,
2110 config_element_type, perf_context->type);
2111 if (ret) {
89b72577
JRJ
2112 goto end;
2113 }
2114
a23cb78a
JG
2115 /* Config */
2116 ret = mi_lttng_writer_write_element_unsigned_int(writer,
2117 config_element_config, perf_context->config);
2118 if (ret) {
2119 goto end;
89b72577
JRJ
2120 }
2121
a23cb78a
JG
2122 /* Name of the perf counter */
2123 ret = mi_lttng_writer_write_element_string(writer,
2124 config_element_name, perf_context->name);
2125 if (ret) {
2126 goto end;
89b72577
JRJ
2127 }
2128
a23cb78a
JG
2129 /* Close perf_counter_context */
2130 ret = mi_lttng_writer_close_element(writer);
89b72577
JRJ
2131end:
2132 return ret;
2133}
2134
a23cb78a
JG
2135static
2136int mi_lttng_app_context(struct mi_writer *writer,
2137 const char *provider_name, const char *ctx_name)
89b72577
JRJ
2138{
2139 int ret;
2140
a23cb78a 2141 /* Open app */
89b72577 2142 ret = mi_lttng_writer_open_element(writer,
a23cb78a 2143 config_element_context_app);
89b72577
JRJ
2144 if (ret) {
2145 goto end;
2146 }
2147
a23cb78a
JG
2148 /* provider_name */
2149 ret = mi_lttng_writer_write_element_string(writer,
2150 config_element_context_app_provider_name,
2151 provider_name);
89b72577
JRJ
2152 if (ret) {
2153 goto end;
2154 }
2155
a23cb78a
JG
2156 /* ctx_name */
2157 ret = mi_lttng_writer_write_element_string(writer,
2158 config_element_context_app_ctx_name, ctx_name);
89b72577
JRJ
2159 if (ret) {
2160 goto end;
2161 }
2162
a23cb78a
JG
2163 /* Close app */
2164 ret = mi_lttng_writer_close_element(writer);
2165end:
2166 return ret;
2167}
2168
2169LTTNG_HIDDEN
2170int mi_lttng_context(struct mi_writer *writer,
2171 struct lttng_event_context *context, int is_open)
2172{
2173 int ret;
2174
2175 /* Open context */
2176 ret = mi_lttng_writer_open_element(writer , config_element_context);
89b72577
JRJ
2177 if (ret) {
2178 goto end;
2179 }
2180
a23cb78a
JG
2181 /* Special case for PERF_*_COUNTER
2182 * print the lttng_event_perf_counter_ctx*/
2183 switch (context->ctx) {
2184 case LTTNG_EVENT_CONTEXT_PERF_COUNTER:
2185 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER:
2186 case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER:
2187 {
2188 struct lttng_event_perf_counter_ctx *perf_context =
2189 &context->u.perf_counter;
2190 ret = mi_lttng_perf_counter_context(writer, perf_context);
2191 if (ret) {
2192 goto end;
2193 }
2194 break;
2195 }
2196 case LTTNG_EVENT_CONTEXT_APP_CONTEXT:
2197 {
2198 ret = mi_lttng_app_context(writer,
2199 context->u.app_ctx.provider_name,
2200 context->u.app_ctx.ctx_name);
2201 if (ret) {
2202 goto end;
2203 }
2204 break;
2205 }
2206 default:
2207 {
2208 const char *type_string = mi_lttng_event_contexttype_string(
2209 context->ctx);
2210 if (!type_string) {
2211 ret = -LTTNG_ERR_INVALID;
2212 goto end;
2213 }
2214
2215 /* Print context type */
2216 ret = mi_lttng_writer_write_element_string(writer,
2217 config_element_type, type_string);
2218 break;
2219 }
2220 }
2221
2222 /* Close context */
2223 if (!is_open) {
2224 ret = mi_lttng_writer_close_element(writer);
2225 }
2226
89b72577
JRJ
2227end:
2228 return ret;
2229}
50534d6f
JRJ
2230
2231LTTNG_HIDDEN
2232int mi_lttng_snapshot_output_session_name(struct mi_writer *writer,
2233 const char *session_name)
2234{
2235 int ret;
2236
2237 /* Open session element */
2238 ret = mi_lttng_writer_open_element(writer, config_element_session);
2239 if (ret) {
2240 goto end;
2241 }
2242
2243 /* Snapshot output list for current session name */
2244 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
2245 session_name);
01defc26
JR
2246 if (ret) {
2247 goto end;
2248 }
50534d6f
JRJ
2249
2250 /* Open element snapshots (sequence one snapshot) */
2251 ret = mi_lttng_writer_open_element(writer, mi_lttng_element_snapshots);
2252 if (ret) {
2253 goto end;
2254 }
2255
2256end:
2257 return ret;
2258}
2259
2260LTTNG_HIDDEN
2261int mi_lttng_snapshot_list_output(struct mi_writer *writer,
0f7c2963 2262 const struct lttng_snapshot_output *output)
50534d6f
JRJ
2263{
2264 int ret;
2265
2266 /* Open element snapshot output */
2267 ret = mi_lttng_writer_open_element(writer,
2268 mi_lttng_element_command_snapshot);
2269 if (ret) {
2270 goto end;
2271 }
2272
2273 /* ID of the snapshot output */
2274 ret = mi_lttng_writer_write_element_unsigned_int(writer,
2275 mi_lttng_element_id, output->id);
2276 if (ret) {
2277 goto end;
2278 }
2279
2280 /* Name of the output */
2281 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
2282 output->name);
2283 if (ret) {
2284 goto end;
2285 }
2286
2287 /* Destination of the output (ctrl_url)*/
2288 ret = mi_lttng_writer_write_element_string(writer,
2289 mi_lttng_element_snapshot_ctrl_url, output->ctrl_url);
2290 if (ret) {
2291 goto end;
2292 }
2293
2294 /* Destination of the output (data_url) */
2295 ret = mi_lttng_writer_write_element_string(writer,
2296 mi_lttng_element_snapshot_data_url, output->data_url);
2297 if (ret) {
2298 goto end;
2299 }
2300
2301 /* total size of all stream combined */
2302 ret = mi_lttng_writer_write_element_unsigned_int(writer,
2303 mi_lttng_element_snapshot_max_size, output->max_size);
2304 if (ret) {
2305 goto end;
2306 }
2307
2308 /* Close snapshot output element */
2309 ret = mi_lttng_writer_close_element(writer);
2310
2311end:
2312 return ret;
2313}
2314
2315LTTNG_HIDDEN
2316int mi_lttng_snapshot_del_output(struct mi_writer *writer, int id,
2317 const char *name, const char *current_session_name)
2318{
2319 int ret;
2320
2321 /* Open element del_snapshot */
2322 ret = mi_lttng_writer_open_element(writer,
2323 mi_lttng_element_command_snapshot);
2324 if (ret) {
2325 goto end;
2326 }
2327
2328
2329 if (id != UINT32_MAX) {
2330 /* "Snapshot output "id" successfully deleted
2331 * for "current_session_name"
2332 * ID of the snapshot output
2333 */
2334 ret = mi_lttng_writer_write_element_unsigned_int(writer,
2335 mi_lttng_element_id, id);
2336 if (ret) {
2337 goto end;
2338 }
2339 } else {
2340 /* "Snapshot output "name" successfully deleted
2341 * for session "current_session_name"
2342 * Name of the output
2343 */
2344 ret = mi_lttng_writer_write_element_string(writer, config_element_name,
2345 name);
2346 if (ret) {
2347 goto end;
2348 }
2349 }
2350
2351 /* Snapshot was deleted for session "current_session_name"*/
2352 ret = mi_lttng_writer_write_element_string(writer,
2353 mi_lttng_element_snapshot_session_name,
2354 current_session_name);
2355 if (ret) {
2356 goto end;
2357 }
2358
2359 /* Close snapshot element */
2360 ret = mi_lttng_writer_close_element(writer);
2361
2362end:
2363 return ret;
2364}
2365
2366LTTNG_HIDDEN
2367int mi_lttng_snapshot_add_output(struct mi_writer *writer,
2368 const char *current_session_name, const char *n_ptr,
2369 struct lttng_snapshot_output *output)
2370{
2371 int ret;
2372
2373 /* Open element snapshot */
2374 ret = mi_lttng_writer_open_element(writer,
2375 mi_lttng_element_command_snapshot);
2376 if (ret) {
2377 goto end;
2378 }
2379
2380 /* Snapshot output id */
2381 ret = mi_lttng_writer_write_element_unsigned_int(writer,
2382 mi_lttng_element_id, output->id);
2383 if (ret) {
2384 goto end;
2385 }
2386
2387 /* Snapshot output names */
2388 ret = mi_lttng_writer_write_element_string(writer,
2389 config_element_name, n_ptr);
2390 if (ret) {
2391 goto end;
2392 }
2393
2394 /* Destination of the output (ctrl_url)*/
2395 ret = mi_lttng_writer_write_element_string(writer,
2396 mi_lttng_element_snapshot_ctrl_url, output->ctrl_url);
2397 if (ret) {
2398 goto end;
2399 }
2400
2401 /* Snapshot added for session "current_session_name"*/
2402 ret = mi_lttng_writer_write_element_string(writer,
2403 mi_lttng_element_snapshot_session_name, current_session_name);
2404 if (ret) {
2405 goto end;
2406 }
2407
2408 /* total size of all stream combined */
2409 ret = mi_lttng_writer_write_element_unsigned_int(writer,
2410 mi_lttng_element_snapshot_max_size, output->max_size);
2411 if (ret) {
2412 goto end;
2413 }
2414
2415 /* Close snapshot element */
2416 ret = mi_lttng_writer_close_element(writer);
2417
2418end:
2419 return ret;
2420}
2421
2422LTTNG_HIDDEN
2423int mi_lttng_snapshot_record(struct mi_writer *writer,
2424 const char *current_session_name, const char *url,
2425 const char *cmdline_ctrl_url, const char *cmdline_data_url)
2426{
2427 int ret;
2428
2429 /* Open element snapshot */
2430 ret = mi_lttng_writer_open_element(writer,
2431 mi_lttng_element_command_snapshot);
2432 if (ret) {
2433 goto end;
2434 }
2435
2436 /*
2437 * If a valid an URL was given, serialize it,
2438 * else take the command line data and ctrl urls*/
2439 if (url) {
2440 /* Destination of the output (ctrl_url)*/
2441 ret = mi_lttng_writer_write_element_string(writer,
2442 mi_lttng_element_snapshot_ctrl_url, url);
2443 if (ret) {
2444 goto end;
2445 }
2446 } else if (cmdline_ctrl_url) {
2447 /* Destination of the output (ctrl_url)*/
2448 ret = mi_lttng_writer_write_element_string(writer,
2449 mi_lttng_element_snapshot_ctrl_url, cmdline_ctrl_url);
2450 if (ret) {
2451 goto end;
2452 }
2453
2454 /* Destination of the output (data_url) */
2455 ret = mi_lttng_writer_write_element_string(writer,
2456 mi_lttng_element_snapshot_data_url, cmdline_data_url);
2457 if (ret) {
2458 goto end;
2459 }
2460 }
2461
2462 /* Close record_snapshot element */
2463 ret = mi_lttng_writer_close_element(writer);
2464
2465end:
2466 return ret;
2467}
66ea93b1
JG
2468
2469LTTNG_HIDDEN
2470int mi_lttng_rotation_schedule(struct mi_writer *writer,
2471 const struct lttng_rotation_schedule *schedule)
2472{
2473 int ret = 0;
2474 enum lttng_rotation_status status;
2475 uint64_t value;
2476 const char *element_name;
2477 const char *value_name;
2478 bool empty_schedule = false;
2479
2480 switch (lttng_rotation_schedule_get_type(schedule)) {
2481 case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC:
2482 status = lttng_rotation_schedule_periodic_get_period(schedule,
2483 &value);
2484 element_name = mi_lttng_element_rotation_schedule_periodic;
3b13cbcc 2485 value_name = mi_lttng_element_rotation_schedule_periodic_time_us;
66ea93b1
JG
2486 break;
2487 case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD:
2488 status = lttng_rotation_schedule_size_threshold_get_threshold(
2489 schedule, &value);
2490 element_name = mi_lttng_element_rotation_schedule_size_threshold;
3b13cbcc 2491 value_name = mi_lttng_element_rotation_schedule_size_threshold_bytes;
66ea93b1
JG
2492 break;
2493 default:
2494 ret = -1;
2495 goto end;
2496 }
2497
2498 if (status != LTTNG_ROTATION_STATUS_OK) {
2499 if (status == LTTNG_ROTATION_STATUS_UNAVAILABLE) {
2500 empty_schedule = true;
2501 } else {
2502 ret = -1;
2503 goto end;
2504 }
2505 }
2506
2507 ret = mi_lttng_writer_open_element(writer, element_name);
2508 if (ret) {
2509 goto end;
2510 }
2511
2512 if (!empty_schedule) {
2513 ret = mi_lttng_writer_write_element_unsigned_int(writer,
2514 value_name, value);
2515 if (ret) {
2516 goto end;
2517 }
2518 }
2519
2520 /* Close schedule descriptor element. */
2521 ret = mi_lttng_writer_close_element(writer);
2522 if (ret) {
2523 goto end;
2524 }
2525end:
2526 return ret;
2527}
2528
2529LTTNG_HIDDEN
2530int mi_lttng_rotation_schedule_result(struct mi_writer *writer,
2531 const struct lttng_rotation_schedule *schedule,
2532 bool success)
2533{
2534 int ret = 0;
2535
2536 ret = mi_lttng_writer_open_element(writer,
2537 mi_lttng_element_rotation_schedule_result);
2538 if (ret) {
2539 goto end;
2540 }
2541
2542 ret = mi_lttng_writer_open_element(writer,
2543 mi_lttng_element_rotation_schedule);
2544 if (ret) {
2545 goto end;
2546 }
2547
2548 ret = mi_lttng_rotation_schedule(writer, schedule);
2549 if (ret) {
2550 goto end;
2551 }
2552
2553 /* Close rotation_schedule element */
2554 ret = mi_lttng_writer_close_element(writer);
2555 if (ret) {
2556 goto end;
2557 }
2558
2559 ret = mi_lttng_writer_write_element_bool(writer,
2560 mi_lttng_element_command_success, success);
2561 if (ret) {
2562 goto end;
2563 }
2564
2565 /* Close rotation_schedule_result element */
3b13cbcc 2566 ret = mi_lttng_writer_close_element(writer);
66ea93b1
JG
2567 if (ret) {
2568 goto end;
2569 }
2570end:
2571 return ret;
2572}
91c4d516
JG
2573
2574static
2575int mi_lttng_location(struct mi_writer *writer,
2576 const struct lttng_trace_archive_location *location)
2577{
2578 int ret = 0;
2579 enum lttng_trace_archive_location_type location_type;
2580 enum lttng_trace_archive_location_status status;
2581
2582 location_type = lttng_trace_archive_location_get_type(location);
2583
2584 switch (location_type) {
2585 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL:
2586 {
2587 const char *absolute_path;
2588
2589 status = lttng_trace_archive_location_local_get_absolute_path(
2590 location, &absolute_path);
2591 if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
2592 ret = -1;
2593 goto end;
2594 }
2595
2596 ret = mi_lttng_writer_open_element(writer,
2597 mi_lttng_element_rotation_location_local);
2598 if (ret) {
2599 goto end;
2600 }
2601
2602
2603 ret = mi_lttng_writer_write_element_string(writer,
2604 mi_lttng_element_rotation_location_local_absolute_path,
2605 absolute_path);
2606 if (ret) {
2607 goto end;
2608 }
2609
2610 /* Close local element */
2611 ret = mi_lttng_writer_close_element(writer);
2612 if (ret) {
2613 goto end;
2614 }
2615 break;
2616 }
2617 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY:
2618 {
2619 uint16_t control_port, data_port;
2620 const char *host, *relative_path;
2621 enum lttng_trace_archive_location_relay_protocol_type protocol;
2622
2623 /* Fetch all relay location parameters. */
2624 status = lttng_trace_archive_location_relay_get_protocol_type(
2625 location, &protocol);
2626 if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
2627 ret = -1;
2628 goto end;
2629 }
2630
2631 status = lttng_trace_archive_location_relay_get_host(
2632 location, &host);
2633 if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
2634 ret = -1;
2635 goto end;
2636 }
2637
2638 status = lttng_trace_archive_location_relay_get_control_port(
2639 location, &control_port);
2640 if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
2641 ret = -1;
2642 goto end;
2643 }
2644
2645 status = lttng_trace_archive_location_relay_get_data_port(
2646 location, &data_port);
2647 if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
2648 ret = -1;
2649 goto end;
2650 }
2651
2652 status = lttng_trace_archive_location_relay_get_relative_path(
2653 location, &relative_path);
2654 if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
2655 ret = -1;
2656 goto end;
2657 }
2658
2659 ret = mi_lttng_writer_open_element(writer,
2660 mi_lttng_element_rotation_location_relay);
2661 if (ret) {
2662 goto end;
2663 }
2664
2665 ret = mi_lttng_writer_write_element_string(writer,
2666 mi_lttng_element_rotation_location_relay_host,
2667 host);
2668 if (ret) {
2669 goto end;
2670 }
2671
2672 ret = mi_lttng_writer_write_element_unsigned_int(writer,
2673 mi_lttng_element_rotation_location_relay_control_port,
2674 control_port);
2675 if (ret) {
2676 goto end;
2677 }
2678
2679 ret = mi_lttng_writer_write_element_unsigned_int(writer,
2680 mi_lttng_element_rotation_location_relay_data_port,
2681 data_port);
2682 if (ret) {
2683 goto end;
2684 }
2685
2686 ret = mi_lttng_writer_write_element_string(writer,
2687 mi_lttng_element_rotation_location_relay_protocol,
2688 mi_lttng_trace_archive_location_relay_protocol_type_string(protocol));
2689 if (ret) {
2690 goto end;
2691 }
2692
2693 ret = mi_lttng_writer_write_element_string(writer,
2694 mi_lttng_element_rotation_location_relay_relative_path,
2695 relative_path);
2696 if (ret) {
2697 goto end;
2698 }
2699
2700 /* Close relay element */
2701 ret = mi_lttng_writer_close_element(writer);
2702 if (ret) {
2703 goto end;
2704 }
2705 break;
2706 }
2707 default:
2708 abort();
2709 }
2710end:
2711 return ret;
2712}
2713
2714LTTNG_HIDDEN
2715int mi_lttng_rotate(struct mi_writer *writer,
2716 const char *session_name,
2717 enum lttng_rotation_state rotation_state,
2718 const struct lttng_trace_archive_location *location)
2719{
2720 int ret;
2721
2722 ret = mi_lttng_writer_open_element(writer,
2723 mi_lttng_element_rotation);
2724 if (ret) {
2725 goto end;
2726 }
2727
2728 ret = mi_lttng_writer_write_element_string(writer,
2729 mi_lttng_element_session_name,
2730 session_name);
2731 if (ret) {
2732 goto end;
2733 }
2734
2735 ret = mi_lttng_writer_write_element_string(writer,
2736 mi_lttng_element_rotation_state,
2737 mi_lttng_rotation_state_string(rotation_state));
2738 if (ret) {
2739 goto end;
2740 }
2741
2742 if (!location) {
2743 /* Not a serialization error. */
2744 goto close_rotation;
2745 }
2746
2747 ret = mi_lttng_writer_open_element(writer,
2748 mi_lttng_element_rotation_location);
2749 if (ret) {
2750 goto end;
2751 }
2752
2753 ret = mi_lttng_location(writer, location);
2754 if (ret) {
2755 goto close_location;
2756 }
2757
2758close_location:
2759 /* Close location element */
2760 ret = mi_lttng_writer_close_element(writer);
2761 if (ret) {
2762 goto end;
2763 }
2764
2765close_rotation:
2766 /* Close rotation element */
2767 ret = mi_lttng_writer_close_element(writer);
2768 if (ret) {
2769 goto end;
2770 }
2771end:
2772 return ret;
2773}
This page took 0.170692 seconds and 4 git commands to generate.