X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Frotate.c;h=68bc59a33bf59037cd827a694637a530f5724c06;hb=dbd512ea8aa5349849aeeccda6130aa9e28cf23c;hp=f8cba7992157c45ccb9fa7e8dd567d3b040f75e0;hpb=d68c9a04537b683991a7355b812b0af954008cf1;p=lttng-tools.git diff --git a/src/bin/lttng/commands/rotate.c b/src/bin/lttng/commands/rotate.c index f8cba7992..68bc59a33 100644 --- a/src/bin/lttng/commands/rotate.c +++ b/src/bin/lttng/commands/rotate.c @@ -32,11 +32,18 @@ #include "../command.h" #include +#include static char *opt_session_name; static int opt_no_wait; static struct mi_writer *writer; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, @@ -94,28 +101,121 @@ end: return ret; } +static int output_trace_archive_location( + const struct lttng_trace_archive_location *location, + const char *session_name) +{ + int ret = 0; + enum lttng_trace_archive_location_type location_type; + enum lttng_trace_archive_location_status status; + bool printed_location = false; + + location_type = lttng_trace_archive_location_get_type(location); + + _MSG("Trace chunk archive for session %s is now readable", + session_name); + 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; + } + MSG(" at %s", absolute_path); + ret = mi_output_rotate("completed", absolute_path, + session_name); + if (ret) { + goto end; + } + printed_location = true; + break; + } + case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY: + { + uint16_t control_port, data_port; + const char *host, *relative_path, *protocol_str; + 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; + } + + switch (protocol) { + case LTTNG_TRACE_ARCHIVE_LOCATION_RELAY_PROTOCOL_TYPE_TCP: + protocol_str = "tcp"; + break; + default: + protocol_str = "unknown"; + break; + } + + MSG(" on relay %s://%s/%s [control port %" PRIu16 ", data port %" + PRIu16 "]", protocol_str, host, + relative_path, control_port, data_port); + printed_location = true; + ret = mi_output_rotate("completed", relative_path, + session_name); + if (ret) { + goto end; + } + break; + } + default: + break; + } +end: + if (!printed_location) { + MSG(" at an unknown location"); + } + return ret; +} + static int rotate_tracing(char *session_name) { int ret; - struct lttng_rotation_immediate_attr *attr = NULL; struct lttng_rotation_handle *handle = NULL; enum lttng_rotation_status rotation_status; enum lttng_rotation_state rotation_state = LTTNG_ROTATION_STATE_ONGOING; DBG("Rotating the output files of session %s", session_name); - attr = lttng_rotation_immediate_attr_create(); - if (!attr) { - goto error; - } - - ret = lttng_rotation_immediate_attr_set_session_name(attr, session_name); - if (ret < 0) { - ERR("Session name exceeds the maximal allowed length"); - goto error; - } - - ret = lttng_rotate_session(attr, &handle); + ret = lttng_rotate_session(session_name, NULL, &handle); if (ret < 0) { switch (-ret) { case LTTNG_ERR_SESSION_NOT_STARTED: @@ -170,17 +270,15 @@ static int rotate_tracing(char *session_name) switch (rotation_state) { case LTTNG_ROTATION_STATE_COMPLETED: { - const char *path; + const struct lttng_trace_archive_location *location; - rotation_status = lttng_rotation_handle_get_completed_archive_location( - handle, &path); + rotation_status = lttng_rotation_handle_get_archive_location( + handle, &location); if (rotation_status != LTTNG_ROTATION_STATUS_OK) { ERR("Failed to retrieve the rotation's completed chunk archive location"); goto error; } - MSG("Trace chunk archive for session %s is now readable at %s", - session_name, path); - ret = mi_output_rotate("completed", path, session_name); + ret = output_trace_archive_location(location, session_name); if (ret) { goto error; } @@ -204,7 +302,6 @@ error: ret = CMD_ERROR; end: lttng_rotation_handle_destroy(handle); - lttng_rotation_immediate_attr_destroy(attr); return ret; }