X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Futils.c;h=680d24134cf49d6d58ab6c43cdb4784ed6d2fe04;hp=0e96ef0c3daf36f08b41c26749356a56705dac01;hb=1831ae68b70dece8e9b847081526495adbbf05e5;hpb=4fd2697fac67a7dc7078bcaa9dad78b874d19b0b diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.c index 0e96ef0c3..680d24134 100644 --- a/src/bin/lttng/utils.c +++ b/src/bin/lttng/utils.c @@ -1,18 +1,8 @@ /* - * Copyright (c) 2011 David Goulet + * Copyright (C) 2011 David Goulet * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #define _LGPL_SOURCE @@ -51,7 +41,8 @@ static const char *str_function = "Function"; static char *_get_session_name(int quiet) { - char *path, *session_name = NULL; + const char *path; + char *session_name = NULL; /* Get path to config file */ path = utils_get_home_dir(); @@ -137,6 +128,25 @@ void list_cmd_options(FILE *ofp, struct poptOption *options) } } +/* + * Same as list_cmd_options, but for options specified for argpar. + */ +void list_cmd_options_argpar(FILE *ofp, const struct argpar_opt_descr *options) +{ + int i; + const struct argpar_opt_descr *option = NULL; + + for (i = 0; options[i].long_name != NULL; i++) { + option = &options[i]; + + fprintf(ofp, "--%s\n", option->long_name); + + if (isprint(option->short_name)) { + fprintf(ofp, "-%c\n", option->short_name); + } + } +} + /* * fls: returns the position of the most significant bit. * Returns 0 if no bit is set, else returns the position of the most @@ -158,7 +168,7 @@ unsigned int fls_u32(uint32_t x) #define HAS_FLS_U32 #endif -#if defined(__x86_64) +#if defined(__x86_64) && defined(__LP64__) static inline unsigned int fls_u64(uint64_t x) { @@ -554,3 +564,98 @@ int show_cmd_help(const char *cmd_name, const char *help_msg) 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"); + } + return ret; +}