#include <common/config/session-config.h>
#include <common/defaults.h>
#include <lttng/snapshot-internal.h>
+#include <lttng/tracker-internal.h>
#include <lttng/channel.h>
#include "mi-lttng.h"
#define MI_SCHEMA_MINOR_VERSION 0
/* Machine interface namespace URI */
-const char * const mi_lttng_xmlns = "xmlns";
-const char * const mi_lttng_xmlns_xsi = "xmlns:xsi";
-const char * const mi_lttng_w3_schema_uri = "http://www.w3.org/2001/XMLSchema-instance";
-const char * const mi_lttng_schema_location = "xsi:schemaLocation";
-const char * const mi_lttng_schema_location_uri =
+LTTNG_HIDDEN const char * const mi_lttng_xmlns = "xmlns";
+LTTNG_HIDDEN const char * const mi_lttng_xmlns_xsi = "xmlns:xsi";
+LTTNG_HIDDEN const char * const mi_lttng_w3_schema_uri = "http://www.w3.org/2001/XMLSchema-instance";
+LTTNG_HIDDEN const char * const mi_lttng_schema_location = "xsi:schemaLocation";
+LTTNG_HIDDEN const char * const mi_lttng_schema_location_uri =
DEFAULT_LTTNG_MI_NAMESPACE " "
- "http://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION)
+ "https://lttng.org/xml/schemas/lttng-mi/" XSTR(MI_SCHEMA_MAJOR_VERSION)
"/lttng-mi-" XSTR(MI_SCHEMA_MAJOR_VERSION) "."
XSTR(MI_SCHEMA_MINOR_VERSION) ".xsd";
-const char * const mi_lttng_schema_version = "schemaVersion";
-const char * const mi_lttng_schema_version_value = XSTR(MI_SCHEMA_MAJOR_VERSION)
+LTTNG_HIDDEN const char * const mi_lttng_schema_version = "schemaVersion";
+LTTNG_HIDDEN const char * const mi_lttng_schema_version_value = XSTR(MI_SCHEMA_MAJOR_VERSION)
"." XSTR(MI_SCHEMA_MINOR_VERSION);
/* Strings related to command */
const char * const mi_lttng_element_command = "command";
const char * const mi_lttng_element_command_action = "snapshot_action";
const char * const mi_lttng_element_command_add_context = "add-context";
-const char * const mi_lttng_element_command_calibrate = "calibrate";
const char * const mi_lttng_element_command_create = "create";
const char * const mi_lttng_element_command_destroy = "destroy";
const char * const mi_lttng_element_command_disable_channel = "disable-channel";
const char * const mi_lttng_element_command_enable_event = "enable-event";
const char * const mi_lttng_element_command_list = "list";
const char * const mi_lttng_element_command_load = "load";
-const char * const mi_lttng_element_command_metadata = "metadata";
-const char * const mi_lttng_element_command_metadata_action = "metadata_action";
+LTTNG_HIDDEN const char * const mi_lttng_element_command_metadata = "metadata";
+LTTNG_HIDDEN const char * const mi_lttng_element_command_metadata_action = "metadata_action";
+LTTNG_HIDDEN const char * const mi_lttng_element_command_regenerate = "regenerate";
+LTTNG_HIDDEN const char * const mi_lttng_element_command_regenerate_action = "regenerate_action";
const char * const mi_lttng_element_command_name = "name";
const char * const mi_lttng_element_command_output = "output";
const char * const mi_lttng_element_command_save = "save";
const char * const mi_lttng_element_command_track = "track";
const char * const mi_lttng_element_command_untrack = "untrack";
const char * const mi_lttng_element_command_version = "version";
+LTTNG_HIDDEN const char * const mi_lttng_element_command_rotate = "rotate";
+LTTNG_HIDDEN const char * const mi_lttng_element_command_enable_rotation = "enable-rotation";
+LTTNG_HIDDEN const char * const mi_lttng_element_command_disable_rotation = "disable-rotation";
+LTTNG_HIDDEN const char * const mi_lttng_element_command_clear = "clear";
/* Strings related to version command */
const char * const mi_lttng_element_version = "version";
/* Strings related to load command */
const char * const mi_lttng_element_load = "load";
+LTTNG_HIDDEN const char * const mi_lttng_element_load_overrides = "overrides";
+LTTNG_HIDDEN const char * const mi_lttng_element_load_override_url = "url";
/* General elements of mi_lttng */
const char * const mi_lttng_element_empty = "";
const char * const mi_lttng_loglevel_type_single = "SINGLE";
const char * const mi_lttng_loglevel_type_unknown = "UNKNOWN";
-/* String related to lttng_calibrate */
-const char * const mi_lttng_element_calibrate = "calibrate";
-const char * const mi_lttng_element_calibrate_function = "FUNCTION";
-
/* String related to a lttng_snapshot_output */
const char * const mi_lttng_element_snapshot_ctrl_url = "ctrl_url";
const char * const mi_lttng_element_snapshot_data_url = "data_url";
/* String related to track/untrack command */
const char * const mi_lttng_element_track_untrack_all_wildcard = "*";
+LTTNG_HIDDEN const char * const mi_lttng_element_session_name = "session_name";
+
+/* String related to rotate command */
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation = "rotation";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotate_status = "status";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule = "rotation_schedule";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedules = "rotation_schedules";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_result = "rotation_schedule_result";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_results = "rotation_schedule_results";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_periodic = "periodic";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_periodic_time_us = "time_us";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_size_threshold = "size_threshold";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_schedule_size_threshold_bytes = "bytes";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_state = "state";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location = "location";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_local = "local";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_local_absolute_path = "absolute_path";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay = "relay";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay_host = "host";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay_control_port = "control_port";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay_data_port = "data_port";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay_protocol = "protocol";
+LTTNG_HIDDEN const char * const mi_lttng_element_rotation_location_relay_relative_path = "relative_path";
+
+/* String related to enum lttng_rotation_state */
+LTTNG_HIDDEN const char * const mi_lttng_rotation_state_str_ongoing = "ONGOING";
+LTTNG_HIDDEN const char * const mi_lttng_rotation_state_str_completed = "COMPLETED";
+LTTNG_HIDDEN const char * const mi_lttng_rotation_state_str_expired = "EXPIRED";
+LTTNG_HIDDEN const char * const mi_lttng_rotation_state_str_error = "ERROR";
+
+/* String related to enum lttng_trace_archive_location_relay_protocol_type */
+LTTNG_HIDDEN const char * const mi_lttng_rotation_location_relay_protocol_str_tcp = "TCP";
+
+/* String related to add-context command */
+LTTNG_HIDDEN const char * const mi_lttng_element_context_symbol = "symbol";
+
+/* Deprecated symbols preserved for ABI compatibility. */
+const char * const mi_lttng_context_type_perf_counter;
+const char * const mi_lttng_context_type_perf_cpu_counter;
+const char * const mi_lttng_context_type_perf_thread_counter;
+const char * const mi_lttng_element_track_untrack_pid_target;
+const char * const mi_lttng_element_track_untrack_targets;
+const char * const mi_lttng_element_calibrate;
+const char * const mi_lttng_element_calibrate_function;
+const char * const mi_lttng_element_command_calibrate;
/* This is a merge of jul loglevel and regular loglevel
* Those should never overlap by definition
return mi_lttng_loglevel_str_unknown;
}
break;
+ default:
+ return mi_lttng_loglevel_str_unknown;
}
-
- /* Reaching this means the domain is unknown. */
- return mi_lttng_loglevel_str_unknown;
}
LTTNG_HIDDEN
}
}
-LTTNG_HIDDEN
+static
const char *mi_lttng_eventtype_string(enum lttng_event_type value)
{
switch (value) {
return config_event_type_tracepoint;
case LTTNG_EVENT_PROBE:
return config_event_type_probe;
+ case LTTNG_EVENT_USERSPACE_PROBE:
+ return config_event_type_userspace_probe;
case LTTNG_EVENT_FUNCTION:
return config_event_type_function;
case LTTNG_EVENT_FUNCTION_ENTRY:
return config_event_context_hostname;
case LTTNG_EVENT_CONTEXT_IP:
return config_event_context_ip;
+ case LTTNG_EVENT_CONTEXT_INTERRUPTIBLE:
+ return config_event_context_interruptible;
+ case LTTNG_EVENT_CONTEXT_PREEMPTIBLE:
+ return config_event_context_preemptible;
+ case LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE:
+ return config_event_context_need_reschedule;
+ case LTTNG_EVENT_CONTEXT_MIGRATABLE:
+ return config_event_context_migratable;
+ case LTTNG_EVENT_CONTEXT_CALLSTACK_USER:
+ return config_event_context_callstack_user;
+ case LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL:
+ return config_event_context_callstack_kernel;
+ case LTTNG_EVENT_CONTEXT_CGROUP_NS:
+ return config_event_context_cgroup_ns;
+ case LTTNG_EVENT_CONTEXT_IPC_NS:
+ return config_event_context_ipc_ns;
+ case LTTNG_EVENT_CONTEXT_MNT_NS:
+ return config_event_context_mnt_ns;
+ case LTTNG_EVENT_CONTEXT_NET_NS:
+ return config_event_context_net_ns;
+ case LTTNG_EVENT_CONTEXT_PID_NS:
+ return config_event_context_pid_ns;
+ case LTTNG_EVENT_CONTEXT_USER_NS:
+ return config_event_context_user_ns;
+ case LTTNG_EVENT_CONTEXT_UTS_NS:
+ return config_event_context_uts_ns;
+ case LTTNG_EVENT_CONTEXT_UID:
+ return config_event_context_uid;
+ case LTTNG_EVENT_CONTEXT_EUID:
+ return config_event_context_euid;
+ case LTTNG_EVENT_CONTEXT_SUID:
+ return config_event_context_suid;
+ case LTTNG_EVENT_CONTEXT_GID:
+ return config_event_context_gid;
+ case LTTNG_EVENT_CONTEXT_EGID:
+ return config_event_context_egid;
+ case LTTNG_EVENT_CONTEXT_SGID:
+ return config_event_context_sgid;
+ case LTTNG_EVENT_CONTEXT_VUID:
+ return config_event_context_vuid;
+ case LTTNG_EVENT_CONTEXT_VEUID:
+ return config_event_context_veuid;
+ case LTTNG_EVENT_CONTEXT_VSUID:
+ return config_event_context_vsuid;
+ case LTTNG_EVENT_CONTEXT_VGID:
+ return config_event_context_vgid;
+ case LTTNG_EVENT_CONTEXT_VEGID:
+ return config_event_context_vegid;
+ case LTTNG_EVENT_CONTEXT_VSGID:
+ return config_event_context_vsgid;
default:
return NULL;
}
}
LTTNG_HIDDEN
-const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val)
+const char *mi_lttng_rotation_state_string(enum lttng_rotation_state value)
{
- const char *ret;
+ switch (value) {
+ case LTTNG_ROTATION_STATE_ONGOING:
+ return mi_lttng_rotation_state_str_ongoing;
+ case LTTNG_ROTATION_STATE_COMPLETED:
+ return mi_lttng_rotation_state_str_completed;
+ case LTTNG_ROTATION_STATE_EXPIRED:
+ return mi_lttng_rotation_state_str_expired;
+ case LTTNG_ROTATION_STATE_ERROR:
+ return mi_lttng_rotation_state_str_error;
+ default:
+ /* Should not have an unknow rotation state. */
+ assert(0);
+ return NULL;
+ }
+}
- switch (val) {
- case LTTNG_CALIBRATE_FUNCTION:
- ret = mi_lttng_element_calibrate_function;
- break;
+LTTNG_HIDDEN
+const char *mi_lttng_trace_archive_location_relay_protocol_type_string(
+ enum lttng_trace_archive_location_relay_protocol_type value)
+{
+ switch (value) {
+ case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP:
+ return mi_lttng_rotation_location_relay_protocol_str_tcp;
default:
- ret = mi_lttng_element_empty;
- break;
+ /* Should not have an unknow relay protocol. */
+ assert(0);
+ return NULL;
}
- return ret;
}
LTTNG_HIDDEN
int ret = 0;
struct lttng_channel *chan = caa_container_of(attr,
struct lttng_channel, attr);
- uint64_t discarded_events, lost_packets;
+ uint64_t discarded_events, lost_packets, monitor_timer_interval;
+ int64_t blocking_timeout;
assert(attr);
goto end;
}
+ ret = lttng_channel_get_monitor_timer_interval(chan,
+ &monitor_timer_interval);
+ if (ret) {
+ goto end;
+ }
+
+ ret = lttng_channel_get_blocking_timeout(chan,
+ &blocking_timeout);
+ if (ret) {
+ goto end;
+ }
+
/* Opening Attributes */
ret = mi_lttng_writer_open_element(writer, config_element_attributes);
if (ret) {
goto end;
}
+ /* Monitor timer interval in usec */
+ ret = mi_lttng_writer_write_element_unsigned_int(writer,
+ config_element_monitor_timer_interval,
+ monitor_timer_interval);
+ if (ret) {
+ goto end;
+ }
+
+ /* Retry timeout in usec */
+ ret = mi_lttng_writer_write_element_signed_int(writer,
+ config_element_blocking_timeout,
+ blocking_timeout);
+ if (ret) {
+ goto end;
+ }
+
/* Event output */
ret = mi_lttng_writer_write_element_string(writer,
config_element_output_type,
return ret;
}
+static
+int mi_lttng_event_userspace_probe(struct mi_writer *writer,
+ struct lttng_event *event)
+{
+ int ret;
+ const struct lttng_userspace_probe_location *location;
+ const struct lttng_userspace_probe_location_lookup_method *lookup_method;
+ enum lttng_userspace_probe_location_lookup_method_type lookup_type;
+
+ location = lttng_event_get_userspace_probe_location(event);
+ if (!location) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ lookup_method = lttng_userspace_probe_location_get_lookup_method(location);
+ if (!lookup_method) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ lookup_type = lttng_userspace_probe_location_lookup_method_get_type(lookup_method);
+
+ ret = mi_lttng_writer_open_element(writer, config_element_attributes);
+ if (ret) {
+ goto end;
+ }
+
+ switch (lttng_userspace_probe_location_get_type(location)) {
+ case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION:
+ {
+ const char *function_name;
+ const char *binary_path;
+
+ ret = mi_lttng_writer_open_element(writer,
+ config_element_userspace_probe_function_attributes);
+ if (ret) {
+ goto end;
+ }
+
+ switch (lookup_type) {
+ case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF:
+ ret = mi_lttng_writer_write_element_string(writer,
+ config_element_userspace_probe_lookup,
+ config_element_userspace_probe_lookup_function_elf);
+ if (ret) {
+ goto end;
+ }
+ break;
+ case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT:
+ ret = mi_lttng_writer_write_element_string(writer,
+ config_element_userspace_probe_lookup,
+ config_element_userspace_probe_lookup_function_default);
+ if (ret) {
+ goto end;
+ }
+ break;
+ default:
+ goto end;
+ }
+
+ binary_path = lttng_userspace_probe_location_function_get_binary_path(location);
+ ret = mi_lttng_writer_write_element_string(writer,
+ config_element_userspace_probe_location_binary_path, binary_path);
+ if (ret) {
+ goto end;
+ }
+
+ function_name = lttng_userspace_probe_location_function_get_function_name(location);
+ ret = mi_lttng_writer_write_element_string(writer,
+ config_element_userspace_probe_function_location_function_name,
+ function_name);
+ if (ret) {
+ goto end;
+ }
+
+ break;
+ }
+ case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT:
+ {
+ const char *probe_name, *provider_name;
+ const char *binary_path;
+
+ ret = mi_lttng_writer_open_element(writer,
+ config_element_userspace_probe_function_attributes);
+ if (ret) {
+ goto end;
+ }
+
+ switch (lookup_type) {
+ case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT:
+ ret = mi_lttng_writer_write_element_string(writer,
+ config_element_userspace_probe_lookup,
+ config_element_userspace_probe_lookup_tracepoint_sdt);
+ if (ret) {
+ goto end;
+ }
+ break;
+ default:
+ goto end;
+ }
+
+ binary_path = lttng_userspace_probe_location_tracepoint_get_binary_path(location);
+ ret = mi_lttng_writer_write_element_string(writer,
+ config_element_userspace_probe_location_binary_path,
+ binary_path);
+ if (ret) {
+ goto end;
+ }
+
+ provider_name = lttng_userspace_probe_location_tracepoint_get_provider_name(location);
+ ret = mi_lttng_writer_write_element_string(writer,
+ config_element_userspace_probe_tracepoint_location_provider_name,
+ provider_name);
+ if (ret) {
+ goto end;
+ }
+
+ probe_name = lttng_userspace_probe_location_tracepoint_get_probe_name(location);
+ ret = mi_lttng_writer_write_element_string(writer,
+ config_element_userspace_probe_tracepoint_location_probe_name, probe_name);
+ if (ret) {
+ goto end;
+ }
+ break;
+ }
+ default:
+ ERR("Invalid probe type encountered");
+ }
+ /* Close probe_attributes and attributes */
+ ret = mi_lttng_close_multi_element(writer, 2);
+end:
+ return ret;
+}
+
LTTNG_HIDDEN
int mi_lttng_event_function_entry(struct mi_writer *writer,
struct lttng_event *event)
case LTTNG_EVENT_FUNCTION_ENTRY:
ret = mi_lttng_event_function_entry(writer, event);
break;
+ case LTTNG_EVENT_USERSPACE_PROBE:
+ ret = mi_lttng_event_userspace_probe(writer, event);
+ break;
case LTTNG_EVENT_ALL:
/* Fallthrough */
default:
break;
}
+ if (ret) {
+ goto end;
+ }
+
if (!is_open) {
ret = mi_lttng_writer_close_element(writer);
}
return mi_lttng_writer_open_element(writer, config_element_trackers);
}
+static int get_tracker_elements(enum lttng_tracker_type tracker_type,
+ const char **element_id_tracker,
+ const char **element_target_id)
+{
+ int ret = 0;
+
+ switch (tracker_type) {
+ case LTTNG_TRACKER_PID:
+ *element_id_tracker = config_element_pid_tracker;
+ *element_target_id = config_element_target_pid;
+ break;
+ case LTTNG_TRACKER_VPID:
+ *element_id_tracker = config_element_vpid_tracker;
+ *element_target_id = config_element_target_vpid;
+ break;
+ case LTTNG_TRACKER_UID:
+ *element_id_tracker = config_element_uid_tracker;
+ *element_target_id = config_element_target_uid;
+ break;
+ case LTTNG_TRACKER_VUID:
+ *element_id_tracker = config_element_vuid_tracker;
+ *element_target_id = config_element_target_vuid;
+ break;
+ case LTTNG_TRACKER_GID:
+ *element_id_tracker = config_element_gid_tracker;
+ *element_target_id = config_element_target_gid;
+ break;
+ case LTTNG_TRACKER_VGID:
+ *element_id_tracker = config_element_vgid_tracker;
+ *element_target_id = config_element_target_vgid;
+ break;
+ default:
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ }
+ return ret;
+}
+
LTTNG_HIDDEN
-int mi_lttng_pid_tracker_open(struct mi_writer *writer)
+int mi_lttng_id_tracker_open(
+ struct mi_writer *writer, enum lttng_tracker_type tracker_type)
{
int ret;
+ const char *element_id_tracker, *element_target_id;
- /* Open element pid_tracker */
- ret = mi_lttng_writer_open_element(writer, config_element_pid_tracker);
+ ret = get_tracker_elements(
+ tracker_type, &element_id_tracker, &element_target_id);
+ if (ret) {
+ return ret;
+ }
+
+ /* Open element $id_tracker */
+ ret = mi_lttng_writer_open_element(writer, element_id_tracker);
if (ret) {
goto end;
}
* mi api bump. The use of process element break the mi api.
*/
LTTNG_HIDDEN
-int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *name,
+int mi_lttng_pid(struct mi_writer *writer,
+ pid_t pid,
+ const char *name,
int is_open)
{
int ret;
}
LTTNG_HIDDEN
-int mi_lttng_pid_target(struct mi_writer *writer, pid_t pid, int is_open)
+int mi_lttng_id_target(struct mi_writer *writer,
+ enum lttng_tracker_type tracker_type,
+ const struct lttng_tracker_id *id,
+ int is_open)
{
int ret;
+ const char *element_id_tracker, *element_target_id;
+ enum lttng_tracker_id_status status;
+ int value;
+ const char *string;
- ret = mi_lttng_writer_open_element(writer,
- config_element_target_pid);
+ ret = get_tracker_elements(
+ tracker_type, &element_id_tracker, &element_target_id);
if (ret) {
- goto end;
+ return ret;
}
- /* Writing pid number
- * Special case for element all on track untrack command
- * All pid is represented as wildcard *
- */
- if ((int) pid == -1) {
- ret = mi_lttng_writer_write_element_string(writer,
- config_element_pid,
- mi_lttng_element_track_untrack_all_wildcard);
- } else {
- ret = mi_lttng_writer_write_element_signed_int(writer,
- config_element_pid, (int) pid);
+ switch (lttng_tracker_id_get_type(id)) {
+ case LTTNG_ID_ALL:
+ ret = mi_lttng_writer_open_element(writer, element_target_id);
+ if (ret) {
+ goto end;
+ }
+ ret = mi_lttng_writer_open_element(writer, config_element_type);
+ if (ret) {
+ goto end;
+ }
+ ret = mi_lttng_writer_write_element_bool(
+ writer, config_element_all, 1);
+ if (ret) {
+ goto end;
+ }
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+ break;
+ case LTTNG_ID_VALUE:
+ ret = mi_lttng_writer_open_element(writer, element_target_id);
+ if (ret) {
+ goto end;
+ }
+ ret = mi_lttng_writer_open_element(writer, config_element_type);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_tracker_id_get_value(id, &value);
+ if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_signed_int(
+ writer, config_element_id, value);
+ if (ret) {
+ goto end;
+ }
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+ break;
+ case LTTNG_ID_STRING:
+ ret = mi_lttng_writer_open_element(writer, element_target_id);
+ if (ret) {
+ goto end;
+ }
+ ret = mi_lttng_writer_open_element(writer, config_element_type);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_tracker_id_get_string(id, &string);
+ if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_string(
+ writer, config_element_name, string);
+ if (ret) {
+ goto end;
+ }
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+ break;
+ case LTTNG_ID_UNKNOWN:
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
}
if (ret) {
goto end;
return ret;
}
-LTTNG_HIDDEN
-int mi_lttng_calibrate(struct mi_writer *writer,
- struct lttng_calibrate *calibrate)
-{
- int ret;
-
- /* Open calibrate element */
- ret = mi_lttng_writer_open_element(writer, mi_lttng_element_calibrate);
- if (ret) {
- goto end;
- }
-
- /* Calibration type */
- ret = mi_lttng_writer_write_element_string(writer, config_element_type,
- mi_lttng_calibratetype_string(calibrate->type));
- if (ret) {
- goto end;
- }
-
- /* Closing calibrate element */
- ret = mi_lttng_writer_close_element(writer);
-end:
- return ret;
-}
-
LTTNG_HIDDEN
int mi_lttng_perf_counter_context(struct mi_writer *writer,
struct lttng_event_perf_counter_ctx *perf_context)
end:
return ret;
}
+
+LTTNG_HIDDEN
+int mi_lttng_rotation_schedule(struct mi_writer *writer,
+ const struct lttng_rotation_schedule *schedule)
+{
+ int ret = 0;
+ enum lttng_rotation_status status;
+ uint64_t value;
+ const char *element_name;
+ const char *value_name;
+ bool empty_schedule = false;
+
+ switch (lttng_rotation_schedule_get_type(schedule)) {
+ case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC:
+ status = lttng_rotation_schedule_periodic_get_period(schedule,
+ &value);
+ element_name = mi_lttng_element_rotation_schedule_periodic;
+ value_name = mi_lttng_element_rotation_schedule_periodic_time_us;
+ break;
+ case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD:
+ status = lttng_rotation_schedule_size_threshold_get_threshold(
+ schedule, &value);
+ element_name = mi_lttng_element_rotation_schedule_size_threshold;
+ value_name = mi_lttng_element_rotation_schedule_size_threshold_bytes;
+ break;
+ default:
+ ret = -1;
+ goto end;
+ }
+
+ if (status != LTTNG_ROTATION_STATUS_OK) {
+ if (status == LTTNG_ROTATION_STATUS_UNAVAILABLE) {
+ empty_schedule = true;
+ } else {
+ ret = -1;
+ goto end;
+ }
+ }
+
+ ret = mi_lttng_writer_open_element(writer, element_name);
+ if (ret) {
+ goto end;
+ }
+
+ if (!empty_schedule) {
+ ret = mi_lttng_writer_write_element_unsigned_int(writer,
+ value_name, value);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ /* Close schedule descriptor element. */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+end:
+ return ret;
+}
+
+LTTNG_HIDDEN
+int mi_lttng_rotation_schedule_result(struct mi_writer *writer,
+ const struct lttng_rotation_schedule *schedule,
+ bool success)
+{
+ int ret = 0;
+
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_rotation_schedule_result);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_rotation_schedule);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_rotation_schedule(writer, schedule);
+ if (ret) {
+ goto end;
+ }
+
+ /* Close rotation_schedule element */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_bool(writer,
+ mi_lttng_element_command_success, success);
+ if (ret) {
+ goto end;
+ }
+
+ /* Close rotation_schedule_result element */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+end:
+ return ret;
+}
+
+static
+int mi_lttng_location(struct mi_writer *writer,
+ const struct lttng_trace_archive_location *location)
+{
+ int ret = 0;
+ enum lttng_trace_archive_location_type location_type;
+ enum lttng_trace_archive_location_status status;
+
+ location_type = lttng_trace_archive_location_get_type(location);
+
+ switch (location_type) {
+ case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL:
+ {
+ const char *absolute_path;
+
+ status = lttng_trace_archive_location_local_get_absolute_path(
+ location, &absolute_path);
+ if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_rotation_location_local);
+ if (ret) {
+ goto end;
+ }
+
+
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_rotation_location_local_absolute_path,
+ absolute_path);
+ if (ret) {
+ goto end;
+ }
+
+ /* Close local element */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+ break;
+ }
+ case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY:
+ {
+ uint16_t control_port, data_port;
+ const char *host, *relative_path;
+ enum lttng_trace_archive_location_relay_protocol_type protocol;
+
+ /* Fetch all relay location parameters. */
+ status = lttng_trace_archive_location_relay_get_protocol_type(
+ location, &protocol);
+ if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
+ ret = -1;
+ goto end;
+ }
+
+ status = lttng_trace_archive_location_relay_get_host(
+ location, &host);
+ if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
+ ret = -1;
+ goto end;
+ }
+
+ status = lttng_trace_archive_location_relay_get_control_port(
+ location, &control_port);
+ if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
+ ret = -1;
+ goto end;
+ }
+
+ status = lttng_trace_archive_location_relay_get_data_port(
+ location, &data_port);
+ if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
+ ret = -1;
+ goto end;
+ }
+
+ status = lttng_trace_archive_location_relay_get_relative_path(
+ location, &relative_path);
+ if (status != LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_rotation_location_relay);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_rotation_location_relay_host,
+ host);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_unsigned_int(writer,
+ mi_lttng_element_rotation_location_relay_control_port,
+ control_port);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_unsigned_int(writer,
+ mi_lttng_element_rotation_location_relay_data_port,
+ data_port);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_rotation_location_relay_protocol,
+ mi_lttng_trace_archive_location_relay_protocol_type_string(protocol));
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_rotation_location_relay_relative_path,
+ relative_path);
+ if (ret) {
+ goto end;
+ }
+
+ /* Close relay element */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+ break;
+ }
+ default:
+ abort();
+ }
+end:
+ return ret;
+}
+
+LTTNG_HIDDEN
+int mi_lttng_rotate(struct mi_writer *writer,
+ const char *session_name,
+ enum lttng_rotation_state rotation_state,
+ const struct lttng_trace_archive_location *location)
+{
+ int ret;
+
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_rotation);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_session_name,
+ session_name);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_rotation_state,
+ mi_lttng_rotation_state_string(rotation_state));
+ if (ret) {
+ goto end;
+ }
+
+ if (!location) {
+ /* Not a serialization error. */
+ goto close_rotation;
+ }
+
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_rotation_location);
+ if (ret) {
+ goto end;
+ }
+
+ ret = mi_lttng_location(writer, location);
+ if (ret) {
+ goto close_location;
+ }
+
+close_location:
+ /* Close location element */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+
+close_rotation:
+ /* Close rotation element */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+end:
+ return ret;
+}