+ nb_domains = lttng_list_domains(session_name, &domains);
+ if (nb_domains < 0) {
+ ret = -1;
+ goto end;
+ }
+ for (domain_idx = 0; domain_idx < nb_domains; domain_idx++) {
+ struct lttng_handle *handle = lttng_create_handle(session_name,
+ &domains[domain_idx]);
+
+ if (!handle) {
+ ERR("Failed to create session handle while printing session statistics.");
+ ret = -1;
+ goto end;
+ }
+
+ count = lttng_list_channels(handle, &channels);
+ for (channel_idx = 0; channel_idx < count; channel_idx++) {
+ uint64_t discarded_events = 0, lost_packets = 0;
+ struct lttng_channel *channel = &channels[channel_idx];
+
+ ret = lttng_channel_get_discarded_event_count(channel,
+ &discarded_events);
+ if (ret) {
+ ERR("Failed to retrieve discarded event count from channel %s",
+ channel->name);
+ }
+
+ ret = lttng_channel_get_lost_packet_count(channel,
+ &lost_packets);
+ if (ret) {
+ ERR("Failed to retrieve lost packet count from channel %s",
+ channel->name);
+ }
+
+ discarded_events_total += discarded_events;
+ lost_packets_total += lost_packets;
+ }
+ lttng_destroy_handle(handle);
+ }
+
+ print_discarded_events = discarded_events_total > 0 &&
+ !selected_session->snapshot_mode;
+ print_lost_packets = lost_packets_total > 0 &&
+ !selected_session->snapshot_mode;
+
+ if (print_discarded_events && print_lost_packets) {
+ ret = asprintf(&stats_str,
+ "Warning: %" PRIu64
+ " events were discarded and %" PRIu64
+ " packets were lost, please refer to "
+ "the documentation on channel configuration.",
+ discarded_events_total, lost_packets_total);
+ } else if (print_discarded_events) {
+ ret = asprintf(&stats_str,
+ "Warning: %" PRIu64
+ " events were discarded, please refer to "
+ "the documentation on channel configuration.",
+ discarded_events_total);
+ } else if (print_lost_packets) {
+ ret = asprintf(&stats_str,
+ "Warning: %" PRIu64
+ " packets were lost, please refer to "
+ "the documentation on channel configuration.",
+ lost_packets_total);
+ } else {
+ ret = 0;
+ }
+
+ if (ret < 0) {
+ ERR("Failed to format lost packet and discarded events statistics");
+ } else {
+ *out_str = stats_str;
+ ret = 0;
+ }
+end:
+ free(sessions);
+ return ret;
+}
+
+int show_cmd_help(const char *cmd_name, const char *help_msg)
+{
+ int ret;
+ char page_name[32];
+
+ ret = sprintf(page_name, "lttng-%s", cmd_name);
+ assert(ret > 0 && ret < 32);
+ ret = utils_show_help(1, page_name, help_msg);
+ if (ret && !help_msg) {
+ ERR("Cannot view man page `lttng-%s(1)`", cmd_name);
+ perror("exec");
+ }
+
+ return ret;
+}
+
+int print_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);
+ 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;
+ break;
+ }
+ default:
+ break;
+ }
+end:
+ if (!printed_location) {
+ MSG(" at an unknown location");
+ }