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