From 0f5c5d5ce30884c93b4e4d0662e2914029c3e90f Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 28 Mar 2024 14:31:12 -0400 Subject: [PATCH] ctf: use `bt2c::Logger` throughout `src.ctf.fs`, `src.ctf.lttng-live` A lot of functions and structures have parameters or fields of type `bt_self_component`, `bt_self_component_class` and `bt_logging_level` for the sole purpose of logging. This becomes quite verbose, especially when a function can be used in both self component and self component class context, then it will have both of these parameters. The `bt2c::Logger` class exists to encapsulate this context in a single value that can be passed around. Use it as much as practically possible (as well as the corresponding logging macros) throughout the sources of the ctf plugin, as well as in the common directory that they depend on. Update all format strings to use {fmt}'s format string syntax. Change all "enum to string" functions to be `format_as()` functions understood by {fmt}. Move these functions near the type they format, for convenience. Remove all the macros that appear at the beginning of source files that influence the logging (such as `BT_COMP_LOG_SELF_COMP` and `BT_LOG_TAG`). The log tags were previously defined per-source file, whereas they are now defined per `Logger` object. I tried to re-use the existing log tags when it made sense, but in some places the log tags are now a bit more granular. Remove the `ctf_plugin_metadata_log_level` variable, controlled by the `BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL` environment variable. This variable controlled the logging level in the lexer and parser (generated by flex and bison). It existed because the generated lexer and parser don't provide an easy way to pass user data around. Work around this by define the following variable: thread_local const ctf_scanner *currentCtfScanner; and making the logging in the lexer and parser code use `currentCtfScanner->logger`. Set `currentCtfScanner` when entering the parser in `ctf_scanner_append_ast()` and install an RAII cleanup to reset it. Change-Id: I0f6844d2cb83d2bf52b81ae9dee4179c7b1f2e12 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12199 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/Makefile.am | 4 +- src/compat/socket.hpp | 22 +- src/plugins/ctf/common/src/bfcr/bfcr.cpp | 322 +++--- src/plugins/ctf/common/src/bfcr/bfcr.hpp | 52 +- .../ctf/common/src/metadata/tsdl/ast.hpp | 137 ++- .../src/metadata/tsdl/ctf-meta-resolve.cpp | 393 ++++--- .../ctf-meta-update-default-clock-classes.cpp | 54 +- .../src/metadata/tsdl/ctf-meta-validate.cpp | 173 ++- .../src/metadata/tsdl/ctf-meta-visitors.hpp | 14 +- ...tf-meta-warn-meaningless-header-fields.cpp | 33 +- .../ctf/common/src/metadata/tsdl/ctf-meta.hpp | 104 +- .../decoder-packetized-file-stream-to-buf.cpp | 111 +- .../decoder-packetized-file-stream-to-buf.hpp | 10 +- .../ctf/common/src/metadata/tsdl/decoder.cpp | 195 ++-- .../ctf/common/src/metadata/tsdl/decoder.hpp | 46 +- .../ctf/common/src/metadata/tsdl/lexer.lpp | 24 +- .../ctf/common/src/metadata/tsdl/logging.cpp | 10 - .../ctf/common/src/metadata/tsdl/logging.hpp | 56 +- .../ctf/common/src/metadata/tsdl/objstack.cpp | 34 +- .../ctf/common/src/metadata/tsdl/objstack.hpp | 8 +- .../common/src/metadata/tsdl/parser-wrap.hpp | 5 +- .../ctf/common/src/metadata/tsdl/parser.ypp | 119 +- .../ctf/common/src/metadata/tsdl/scanner.hpp | 18 +- .../src/metadata/tsdl/visitor-generate-ir.cpp | 1002 ++++++++--------- .../metadata/tsdl/visitor-parent-links.cpp | 123 +- .../tsdl/visitor-semantic-validator.cpp | 239 ++-- .../ctf/common/src/msg-iter/msg-iter.cpp | 996 ++++++++-------- .../ctf/common/src/msg-iter/msg-iter.hpp | 90 +- src/plugins/ctf/fs-src/data-stream-file.cpp | 220 ++-- src/plugins/ctf/fs-src/data-stream-file.hpp | 17 +- src/plugins/ctf/fs-src/file.cpp | 35 +- src/plugins/ctf/fs-src/file.hpp | 8 +- src/plugins/ctf/fs-src/fs.cpp | 345 +++--- src/plugins/ctf/fs-src/fs.hpp | 49 +- src/plugins/ctf/fs-src/metadata.cpp | 35 +- src/plugins/ctf/fs-src/metadata.hpp | 9 +- src/plugins/ctf/fs-src/query.cpp | 95 +- src/plugins/ctf/fs-src/query.hpp | 18 +- src/plugins/ctf/lttng-live/data-stream.cpp | 83 +- src/plugins/ctf/lttng-live/lttng-live.cpp | 610 +++++----- src/plugins/ctf/lttng-live/lttng-live.hpp | 102 +- .../ctf/lttng-live/lttng-viewer-abi.hpp | 95 +- src/plugins/ctf/lttng-live/metadata.cpp | 77 +- .../ctf/lttng-live/viewer-connection.cpp | 560 ++++----- .../ctf/lttng-live/viewer-connection.hpp | 19 +- 45 files changed, 3440 insertions(+), 3331 deletions(-) delete mode 100644 src/plugins/ctf/common/src/metadata/tsdl/logging.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 14ff26f9..cde6d6d6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -283,7 +283,6 @@ plugins_ctf_common_metadata_libctf_ast_la_SOURCES = \ plugins/ctf/common/src/metadata/tsdl/decoder.hpp \ plugins/ctf/common/src/metadata/tsdl/decoder-packetized-file-stream-to-buf.cpp \ plugins/ctf/common/src/metadata/tsdl/decoder-packetized-file-stream-to-buf.hpp \ - plugins/ctf/common/src/metadata/tsdl/logging.cpp \ plugins/ctf/common/src/metadata/tsdl/logging.hpp \ plugins/ctf/common/src/metadata/tsdl/ctf-meta.hpp \ plugins/ctf/common/src/metadata/tsdl/ctf-meta-visitors.hpp \ @@ -713,7 +712,8 @@ plugins_ctf_babeltrace_plugin_ctf_la_LIBADD += \ logging/liblogging.la \ plugins/common/muxing/libmuxing.la \ common/libcommon.la \ - ctfser/libctfser.la + ctfser/libctfser.la \ + cpp-common/vendor/fmt/libfmt.la endif # text plugin diff --git a/src/compat/socket.hpp b/src/compat/socket.hpp index 9cb036c3..972f6929 100644 --- a/src/compat/socket.hpp +++ b/src/compat/socket.hpp @@ -10,6 +10,8 @@ #include +#include "cpp-common/bt2c/logging.hpp" + #ifdef __MINGW32__ # include @@ -18,13 +20,7 @@ # define BT_SOCKET_ERROR SOCKET_ERROR # define BT_SOCKET SOCKET -# ifndef BT_LOG_WRITE_CUR_LVL -# define BT_SOCKET_LOG_LEVEL_UNUSED_ATTR __attribute__((unused)) -# else -# define BT_SOCKET_LOG_LEVEL_UNUSED_ATTR -# endif - -static inline int bt_socket_init(int log_level BT_SOCKET_LOG_LEVEL_UNUSED_ATTR) +static inline int bt_socket_init(const bt2c::Logger& logger) { WORD verreq; WSADATA wsa; @@ -35,18 +31,12 @@ static inline int bt_socket_init(int log_level BT_SOCKET_LOG_LEVEL_UNUSED_ATTR) ret = WSAStartup(verreq, &wsa); if (ret != 0) { -# ifdef BT_LOG_WRITE_PRINTF_CUR_LVL - BT_LOG_WRITE_PRINTF_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG, - "Winsock init failed with error: %d", ret); -# endif + BT_CPPLOGE_SPEC(logger, "Winsock init failed with error: {}", ret); goto end; } if (LOBYTE(wsa.wVersion) != 2 || HIBYTE(wsa.wVersion) != 2) { -# ifdef BT_LOG_WRITE_CUR_LVL - BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG, - "Could not init winsock 2.2 support"); -# endif + BT_CPPLOGE_SPEC(logger, "Could not init winsock 2.2 support"); WSACleanup(); ret = -1; } @@ -270,7 +260,7 @@ static inline const char *bt_socket_errormsg(void) # define BT_SOCKET_ERROR -1 # define BT_SOCKET int -static inline int bt_socket_init(int log_level __attribute__((unused))) +static inline int bt_socket_init(const bt2c::Logger&) { return 0; } diff --git a/src/plugins/ctf/common/src/bfcr/bfcr.cpp b/src/plugins/ctf/common/src/bfcr/bfcr.cpp index 920d892e..2b5cb79a 100644 --- a/src/plugins/ctf/common/src/bfcr/bfcr.cpp +++ b/src/plugins/ctf/common/src/bfcr/bfcr.cpp @@ -7,23 +7,12 @@ * Babeltrace - CTF binary field class reader (BFCR) */ -#include -#include -#include -#include -#include - -#include - -#define BT_COMP_LOG_SELF_COMP (bfcr->self_comp) -#define BT_LOG_OUTPUT_LEVEL (bfcr->log_level) -#define BT_LOG_TAG "PLUGIN/CTF/BFCR" -#include "logging/comp-logging.h" - #include "common/align.h" #include "common/assert.h" #include "common/common.h" #include "compat/bitfield.h" +#include "cpp-common/bt2c/logging.hpp" +#include "cpp-common/vendor/fmt/format.h" #include "../metadata/tsdl/ctf-meta.hpp" #include "bfcr.hpp" @@ -77,13 +66,39 @@ enum bfcr_state BFCR_STATE_DONE, }; +static const char *format_as(bfcr_state state) noexcept +{ + switch (state) { + case BFCR_STATE_NEXT_FIELD: + return "NEXT_FIELD"; + + case BFCR_STATE_ALIGN_BASIC: + return "ALIGN_BASIC"; + + case BFCR_STATE_ALIGN_COMPOUND: + return "ALIGN_COMPOUND"; + + case BFCR_STATE_READ_BASIC_BEGIN: + return "READ_BASIC_BEGIN"; + + case BFCR_STATE_READ_BASIC_CONTINUE: + return "READ_BASIC_CONTINUE"; + + case BFCR_STATE_DONE: + return "DONE"; + } + + bt_common_abort(); +} + /* Binary class reader */ struct bt_bfcr { - bt_logging_level log_level = static_cast(0); + explicit bt_bfcr(const bt2c::Logger& parentLogger) : logger {parentLogger, "PLUGIN/CTF/BFCR"} + { + } - /* Weak */ - bt_self_component *self_comp = nullptr; + bt2c::Logger logger; /* BFCR stack */ struct stack *stack = nullptr; @@ -155,44 +170,24 @@ struct bt_bfcr } user; }; -static inline const char *bfcr_state_string(enum bfcr_state state) -{ - switch (state) { - case BFCR_STATE_NEXT_FIELD: - return "NEXT_FIELD"; - case BFCR_STATE_ALIGN_BASIC: - return "ALIGN_BASIC"; - case BFCR_STATE_ALIGN_COMPOUND: - return "ALIGN_COMPOUND"; - case BFCR_STATE_READ_BASIC_BEGIN: - return "READ_BASIC_BEGIN"; - case BFCR_STATE_READ_BASIC_CONTINUE: - return "READ_BASIC_CONTINUE"; - case BFCR_STATE_DONE: - return "DONE"; - } - - bt_common_abort(); -} - static struct stack *stack_new(struct bt_bfcr *bfcr) { struct stack *stack = NULL; stack = g_new0(struct stack, 1); if (!stack) { - BT_COMP_LOGE_STR("Failed to allocate one stack."); + BT_CPPLOGE_STR_SPEC(bfcr->logger, "Failed to allocate one stack."); goto error; } stack->bfcr = bfcr; stack->entries = g_array_new(FALSE, TRUE, sizeof(struct stack_entry)); if (!stack->entries) { - BT_COMP_LOGE_STR("Failed to allocate a GArray."); + BT_CPPLOGE_STR_SPEC(bfcr->logger, "Failed to allocate a GArray."); goto error; } - BT_COMP_LOGD("Created stack: addr=%p", stack); + BT_CPPLOGD_SPEC(bfcr->logger, "Created stack: addr={}", fmt::ptr(stack)); return stack; error: @@ -209,7 +204,7 @@ static void stack_destroy(struct stack *stack) } bfcr = stack->bfcr; - BT_COMP_LOGD("Destroying stack: addr=%p", stack); + BT_CPPLOGD_SPEC(bfcr->logger, "Destroying stack: addr={}", fmt::ptr(stack)); if (stack->entries) { g_array_free(stack->entries, TRUE); @@ -226,10 +221,12 @@ static int stack_push(struct stack *stack, struct ctf_field_class *base_class, s BT_ASSERT_DBG(stack); BT_ASSERT_DBG(base_class); bfcr = stack->bfcr; - BT_COMP_LOGT("Pushing field class on stack: stack-addr=%p, " - "fc-addr=%p, fc-type=%d, base-length=%zu, " - "stack-size-before=%zu, stack-size-after=%zu", - stack, base_class, base_class->type, base_len, stack->size, stack->size + 1); + BT_CPPLOGT_SPEC(bfcr->logger, + "Pushing field class on stack: stack-addr={}, " + "fc-addr={}, fc-type={}, base-length={}, " + "stack-size-before={}, stack-size-after={}", + fmt::ptr(stack), fmt::ptr(base_class), (int) base_class->type, base_len, + stack->size, stack->size + 1); if (stack->entries->len == stack->size) { g_array_set_size(stack->entries, stack->size + 1); @@ -285,9 +282,10 @@ static int stack_push_with_len(struct bt_bfcr *bfcr, struct ctf_field_class *bas int64_t length = get_compound_field_class_length(bfcr, base_class); if (length < 0) { - BT_COMP_LOGW("Cannot get compound field class's field count: " - "bfcr-addr=%p, fc-addr=%p, fc-type=%d", - bfcr, base_class, base_class->type); + BT_CPPLOGW_SPEC(bfcr->logger, + "Cannot get compound field class's field count: " + "bfcr-addr={}, fc-addr={}, fc-type={}", + fmt::ptr(bfcr), fmt::ptr(base_class), (int) base_class->type); ret = BT_BFCR_STATUS_ERROR; goto end; } @@ -311,9 +309,10 @@ static void stack_pop(struct stack *stack) BT_ASSERT_DBG(stack); BT_ASSERT_DBG(stack_size(stack)); bfcr = stack->bfcr; - BT_COMP_LOGT("Popping from stack: " - "stack-addr=%p, stack-size-before=%u, stack-size-after=%u", - stack, stack->entries->len, stack->entries->len - 1); + BT_CPPLOGT_SPEC(bfcr->logger, + "Popping from stack: " + "stack-addr={}, stack-size-before={}, stack-size-after={}", + fmt::ptr(stack), stack->entries->len, stack->entries->len - 1); stack->size--; } @@ -342,8 +341,8 @@ static inline size_t available_bits(struct bt_bfcr *bfcr) static inline void consume_bits(struct bt_bfcr *bfcr, size_t incr) { - BT_COMP_LOGT("Advancing cursor: bfcr-addr=%p, cur-before=%zu, cur-after=%zu", bfcr, - bfcr->buf.at, bfcr->buf.at + incr); + BT_CPPLOGT_SPEC(bfcr->logger, "Advancing cursor: bfcr-addr={}, cur-before={}, cur-after={}", + fmt::ptr(bfcr), bfcr->buf.at, bfcr->buf.at + incr); bfcr->buf.at += incr; } @@ -438,9 +437,8 @@ static inline void read_unsigned_bitfield(struct bt_bfcr *bfcr, const uint8_t *b bt_common_abort(); } - BT_COMP_LOGT("Read unsigned bit array: cur=%zu, size=%u, " - "bo=%d, val=%" PRIu64, - at, field_size, bo, *v); + BT_CPPLOGT_SPEC(bfcr->logger, "Read unsigned bit array: cur={}, size={}, bo={}, val={}", at, + field_size, (int) bo, *v); } static inline void read_signed_bitfield(struct bt_bfcr *bfcr, const uint8_t *buf, size_t at, @@ -457,9 +455,8 @@ static inline void read_signed_bitfield(struct bt_bfcr *bfcr, const uint8_t *buf bt_common_abort(); } - BT_COMP_LOGT("Read signed bit array: cur=%zu, size=%u, " - "bo=%d, val=%" PRId64, - at, field_size, bo, *v); + BT_CPPLOGT_SPEC(bfcr->logger, "Read signed bit array: cur={}, size={}, bo={}, val={}", at, + field_size, (int) bo, *v); } typedef enum bt_bfcr_status (*read_basic_and_call_cb_t)(struct bt_bfcr *, const uint8_t *, size_t); @@ -502,9 +499,10 @@ static inline enum bt_bfcr_status validate_contiguous_bo(struct bt_bfcr *bfcr, end: if (status < 0) { - BT_COMP_LOGW("Cannot read bit array: two different byte orders not at a byte boundary: " - "bfcr-addr=%p, last-bo=%d, next-bo=%d", - bfcr, bfcr->last_bo, next_bo); + BT_CPPLOGW_SPEC(bfcr->logger, + "Cannot read bit array: two different byte orders not at a byte boundary: " + "bfcr-addr={}, last-bo={}, next-bo={}", + fmt::ptr(bfcr), (int) bfcr->last_bo, (int) next_bo); } return status; @@ -556,16 +554,17 @@ static enum bt_bfcr_status read_basic_float_and_call_cb(struct bt_bfcr *bfcr, co bt_common_abort(); } - BT_COMP_LOGT("Read floating point number value: bfcr=%p, cur=%zu, val=%f", bfcr, at, dblval); + BT_CPPLOGT_SPEC(bfcr->logger, "Read floating point number value: bfcr={}, cur={}, val={}", + fmt::ptr(bfcr), at, dblval); if (bfcr->user.cbs.classes.floating_point) { - BT_COMP_LOGT("Calling user function (floating point number)."); + BT_CPPLOGT_SPEC(bfcr->logger, "Calling user function (floating point number)."); status = bfcr->user.cbs.classes.floating_point(dblval, bfcr->cur_basic_field_class, bfcr->user.data); - BT_COMP_LOGT("User function returned: status=%s", bt_bfcr_status_string(status)); + BT_CPPLOGT_SPEC(bfcr->logger, "User function returned: status={}", status); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("User function failed: bfcr-addr=%p, status=%s", bfcr, - bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, "User function failed: bfcr-addr={}, status={}", + fmt::ptr(bfcr), status); } } @@ -596,14 +595,15 @@ static inline enum bt_bfcr_status read_basic_int_and_call_cb(struct bt_bfcr *bfc read_signed_bitfield(bfcr, buf, at, field_size, bo, &v); if (bfcr->user.cbs.classes.signed_int) { - BT_COMP_LOGT("Calling user function (signed integer)."); + BT_CPPLOGT_SPEC(bfcr->logger, "Calling user function (signed integer)."); status = bfcr->user.cbs.classes.signed_int(v, bfcr->cur_basic_field_class, bfcr->user.data); - BT_COMP_LOGT("User function returned: status=%s", bt_bfcr_status_string(status)); + BT_CPPLOGT_SPEC(bfcr->logger, "User function returned: status={}", status); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("User function failed: " - "bfcr-addr=%p, status=%s", - bfcr, bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, + "User function failed: " + "bfcr-addr={}, status={}", + fmt::ptr(bfcr), status); } } } else { @@ -612,14 +612,15 @@ static inline enum bt_bfcr_status read_basic_int_and_call_cb(struct bt_bfcr *bfc read_unsigned_bitfield(bfcr, buf, at, field_size, bo, &v); if (bfcr->user.cbs.classes.unsigned_int) { - BT_COMP_LOGT("Calling user function (unsigned integer)."); + BT_CPPLOGT_SPEC(bfcr->logger, "Calling user function (unsigned integer)."); status = bfcr->user.cbs.classes.unsigned_int(v, bfcr->cur_basic_field_class, bfcr->user.data); - BT_COMP_LOGT("User function returned: status=%s", bt_bfcr_status_string(status)); + BT_CPPLOGT_SPEC(bfcr->logger, "User function returned: status={}", status); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("User function failed: " - "bfcr-addr=%p, status=%s", - bfcr, bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, + "User function failed: " + "bfcr-addr={}, status={}", + fmt::ptr(bfcr), status); } } } @@ -637,25 +638,27 @@ read_bit_array_class_and_call_continue(struct bt_bfcr *bfcr, ctf_field_class_bit_array *fc = ctf_field_class_as_bit_array(bfcr->cur_basic_field_class); if (!at_least_one_bit_left(bfcr)) { - BT_COMP_LOGT("Reached end of data: bfcr-addr=%p", bfcr); + BT_CPPLOGT_SPEC(bfcr->logger, "Reached end of data: bfcr-addr={}", fmt::ptr(bfcr)); status = BT_BFCR_STATUS_EOF; goto end; } available = available_bits(bfcr); needed_bits = fc->size - bfcr->stitch.at; - BT_COMP_LOGT("Continuing basic field decoding: " - "bfcr-addr=%p, field-size=%u, needed-size=%zu, " - "available-size=%zu", - bfcr, fc->size, needed_bits, available); + BT_CPPLOGT_SPEC(bfcr->logger, + "Continuing basic field decoding: " + "bfcr-addr={}, field-size={}, needed-size={}, " + "available-size={}", + fmt::ptr(bfcr), fc->size, needed_bits, available); if (needed_bits <= available) { /* We have all the bits; append to stitch, then decode */ stitch_append_from_buf(bfcr, needed_bits); status = read_basic_and_call_cb(bfcr, bfcr->stitch.buf, bfcr->stitch.offset); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("Cannot read basic field: " - "bfcr-addr=%p, fc-addr=%p, status=%s", - bfcr, bfcr->cur_basic_field_class, bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, + "Cannot read basic field: " + "bfcr-addr={}, fc-addr={}, status={}", + fmt::ptr(bfcr), fmt::ptr(bfcr->cur_basic_field_class), status); goto end; } @@ -672,7 +675,8 @@ read_bit_array_class_and_call_continue(struct bt_bfcr *bfcr, } /* We are here; it means we don't have enough data to decode this */ - BT_COMP_LOGT_STR("Not enough data to read the next basic field: appending to stitch buffer."); + BT_CPPLOGT_STR_SPEC( + bfcr->logger, "Not enough data to read the next basic field: appending to stitch buffer."); stitch_append_from_remaining_buf(bfcr); status = BT_BFCR_STATUS_EOF; @@ -689,7 +693,7 @@ read_bit_array_class_and_call_begin(struct bt_bfcr *bfcr, ctf_field_class_bit_array *fc = ctf_field_class_as_bit_array(bfcr->cur_basic_field_class); if (!at_least_one_bit_left(bfcr)) { - BT_COMP_LOGT("Reached end of data: bfcr-addr=%p", bfcr); + BT_CPPLOGT_SPEC(bfcr->logger, "Reached end of data: bfcr-addr={}", fmt::ptr(bfcr)); status = BT_BFCR_STATUS_EOF; goto end; } @@ -707,9 +711,10 @@ read_bit_array_class_and_call_begin(struct bt_bfcr *bfcr, BT_ASSERT_DBG(bfcr->buf.addr); status = read_basic_and_call_cb(bfcr, bfcr->buf.addr, buf_at_from_addr(bfcr)); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("Cannot read basic field: " - "bfcr-addr=%p, fc-addr=%p, status=%s", - bfcr, bfcr->cur_basic_field_class, bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, + "Cannot read basic field: " + "bfcr-addr={}, fc-addr={}, status={}", + fmt::ptr(bfcr), fmt::ptr(bfcr->cur_basic_field_class), status); goto end; } @@ -729,7 +734,8 @@ read_bit_array_class_and_call_begin(struct bt_bfcr *bfcr, } /* We are here; it means we don't have enough data to decode this */ - BT_COMP_LOGT_STR("Not enough data to read the next basic field: setting stitch buffer."); + BT_CPPLOGT_STR_SPEC(bfcr->logger, + "Not enough data to read the next basic field: setting stitch buffer."); stitch_set_from_remaining_buf(bfcr); bfcr->state = BFCR_STATE_READ_BASIC_CONTINUE; status = BT_BFCR_STATUS_EOF; @@ -767,7 +773,7 @@ static inline enum bt_bfcr_status read_basic_string_class_and_call(struct bt_bfc enum bt_bfcr_status status = BT_BFCR_STATUS_OK; if (!at_least_one_bit_left(bfcr)) { - BT_COMP_LOGT("Reached end of data: bfcr-addr=%p", bfcr); + BT_CPPLOGT_SPEC(bfcr->logger, "Reached end of data: bfcr-addr={}", fmt::ptr(bfcr)); status = BT_BFCR_STATUS_EOF; goto end; } @@ -780,12 +786,12 @@ static inline enum bt_bfcr_status read_basic_string_class_and_call(struct bt_bfc result = (const uint8_t *) memchr(first_chr, '\0', available_bytes); if (begin && bfcr->user.cbs.classes.string_begin) { - BT_COMP_LOGT("Calling user function (string, beginning)."); + BT_CPPLOGT_SPEC(bfcr->logger, "Calling user function (string, beginning)."); status = bfcr->user.cbs.classes.string_begin(bfcr->cur_basic_field_class, bfcr->user.data); - BT_COMP_LOGT("User function returned: status=%s", bt_bfcr_status_string(status)); + BT_CPPLOGT_SPEC(bfcr->logger, "User function returned: status={}", status); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("User function failed: bfcr-addr=%p, status=%s", bfcr, - bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, "User function failed: bfcr-addr={}, status={}", + fmt::ptr(bfcr), status); goto end; } } @@ -793,14 +799,15 @@ static inline enum bt_bfcr_status read_basic_string_class_and_call(struct bt_bfc if (!result) { /* No null character yet */ if (bfcr->user.cbs.classes.string) { - BT_COMP_LOGT("Calling user function (substring)."); + BT_CPPLOGT_SPEC(bfcr->logger, "Calling user function (substring)."); status = bfcr->user.cbs.classes.string((const char *) first_chr, available_bytes, bfcr->cur_basic_field_class, bfcr->user.data); - BT_COMP_LOGT("User function returned: status=%s", bt_bfcr_status_string(status)); + BT_CPPLOGT_SPEC(bfcr->logger, "User function returned: status={}", status); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("User function failed: " - "bfcr-addr=%p, status=%s", - bfcr, bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, + "User function failed: " + "bfcr-addr={}, status={}", + fmt::ptr(bfcr), status); goto end; } } @@ -813,27 +820,29 @@ static inline enum bt_bfcr_status read_basic_string_class_and_call(struct bt_bfc size_t result_len = (size_t) (result - first_chr); if (bfcr->user.cbs.classes.string && result_len) { - BT_COMP_LOGT("Calling user function (substring)."); + BT_CPPLOGT_SPEC(bfcr->logger, "Calling user function (substring)."); status = bfcr->user.cbs.classes.string((const char *) first_chr, result_len, bfcr->cur_basic_field_class, bfcr->user.data); - BT_COMP_LOGT("User function returned: status=%s", bt_bfcr_status_string(status)); + BT_CPPLOGT_SPEC(bfcr->logger, "User function returned: status={}", status); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("User function failed: " - "bfcr-addr=%p, status=%s", - bfcr, bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, + "User function failed: " + "bfcr-addr={}, status={}", + fmt::ptr(bfcr), status); goto end; } } if (bfcr->user.cbs.classes.string_end) { - BT_COMP_LOGT("Calling user function (string, end)."); + BT_CPPLOGT_SPEC(bfcr->logger, "Calling user function (string, end)."); status = bfcr->user.cbs.classes.string_end(bfcr->cur_basic_field_class, bfcr->user.data); - BT_COMP_LOGT("User function returned: status=%s", bt_bfcr_status_string(status)); + BT_CPPLOGT_SPEC(bfcr->logger, "User function returned: status={}", status); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("User function failed: " - "bfcr-addr=%p, status=%s", - bfcr, bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, + "User function failed: " + "bfcr-addr={}, status={}", + fmt::ptr(bfcr), status); goto end; } } @@ -954,7 +963,8 @@ static inline enum bt_bfcr_status align_class_state(struct bt_bfcr *bfcr, goto end; } else { /* No: need more data */ - BT_COMP_LOGT("Reached end of data when aligning: bfcr-addr=%p", bfcr); + BT_CPPLOGT_SPEC(bfcr->logger, "Reached end of data when aligning: bfcr-addr={}", + fmt::ptr(bfcr)); status = BT_BFCR_STATUS_EOF; } @@ -978,12 +988,12 @@ static inline enum bt_bfcr_status next_field_state(struct bt_bfcr *bfcr) /* Are we done with this base class? */ while (top->index == top->base_len) { if (bfcr->user.cbs.classes.compound_end) { - BT_COMP_LOGT("Calling user function (compound, end)."); + BT_CPPLOGT_SPEC(bfcr->logger, "Calling user function (compound, end)."); status = bfcr->user.cbs.classes.compound_end(top->base_class, bfcr->user.data); - BT_COMP_LOGT("User function returned: status=%s", bt_bfcr_status_string(status)); + BT_CPPLOGT_SPEC(bfcr->logger, "User function returned: status={}", status); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("User function failed: bfcr-addr=%p, status=%s", bfcr, - bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, "User function failed: bfcr-addr={}, status={}", + fmt::ptr(bfcr), status); goto end; } } @@ -1025,22 +1035,23 @@ static inline enum bt_bfcr_status next_field_state(struct bt_bfcr *bfcr) } if (!next_field_class) { - BT_COMP_LOGW("Cannot get the field class of the next field: " - "bfcr-addr=%p, base-fc-addr=%p, base-fc-type=%d, " - "index=%" PRId64, - bfcr, top->base_class, top->base_class->type, top->index); + BT_CPPLOGW_SPEC(bfcr->logger, + "Cannot get the field class of the next field: " + "bfcr-addr={}, base-fc-addr={}, base-fc-type={}, index={}", + fmt::ptr(bfcr), fmt::ptr(top->base_class), (int) top->base_class->type, + top->index); status = BT_BFCR_STATUS_ERROR; goto end; } if (next_field_class->is_compound) { if (bfcr->user.cbs.classes.compound_begin) { - BT_COMP_LOGT("Calling user function (compound, begin)."); + BT_CPPLOGT_SPEC(bfcr->logger, "Calling user function (compound, begin)."); status = bfcr->user.cbs.classes.compound_begin(next_field_class, bfcr->user.data); - BT_COMP_LOGT("User function returned: status=%s", bt_bfcr_status_string(status)); + BT_CPPLOGT_SPEC(bfcr->logger, "User function returned: status={}", status); if (status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("User function failed: bfcr-addr=%p, status=%s", bfcr, - bt_bfcr_status_string(status)); + BT_CPPLOGW_SPEC(bfcr->logger, "User function failed: bfcr-addr={}, status={}", + fmt::ptr(bfcr), status); goto end; } } @@ -1056,10 +1067,12 @@ static inline enum bt_bfcr_status next_field_state(struct bt_bfcr *bfcr) bfcr->state = BFCR_STATE_ALIGN_COMPOUND; } else { /* Replace current basic field class */ - BT_COMP_LOGT("Replacing current basic field class: " - "bfcr-addr=%p, cur-basic-fc-addr=%p, " - "next-basic-fc-addr=%p", - bfcr, bfcr->cur_basic_field_class, next_field_class); + BT_CPPLOGT_SPEC(bfcr->logger, + "Replacing current basic field class: " + "bfcr-addr={}, cur-basic-fc-addr={}, " + "next-basic-fc-addr={}", + fmt::ptr(bfcr), fmt::ptr(bfcr->cur_basic_field_class), + fmt::ptr(next_field_class)); bfcr->cur_basic_field_class = next_field_class; /* Next state: align a basic class */ @@ -1074,7 +1087,8 @@ static inline enum bt_bfcr_status handle_state(struct bt_bfcr *bfcr) { enum bt_bfcr_status status = BT_BFCR_STATUS_OK; - BT_COMP_LOGT("Handling state: bfcr-addr=%p, state=%s", bfcr, bfcr_state_string(bfcr->state)); + BT_CPPLOGT_SPEC(bfcr->logger, "Handling state: bfcr-addr={}, state={}", fmt::ptr(bfcr), + bfcr->state); switch (bfcr->state) { case BFCR_STATE_NEXT_FIELD: @@ -1096,22 +1110,18 @@ static inline enum bt_bfcr_status handle_state(struct bt_bfcr *bfcr) break; } - BT_COMP_LOGT("Handled state: bfcr-addr=%p, status=%s", bfcr, bt_bfcr_status_string(status)); + BT_CPPLOGT_SPEC(bfcr->logger, "Handled state: bfcr-addr={}, status={}", fmt::ptr(bfcr), status); return status; } -struct bt_bfcr *bt_bfcr_create(struct bt_bfcr_cbs cbs, void *data, bt_logging_level log_level, - bt_self_component *self_comp) +struct bt_bfcr *bt_bfcr_create(struct bt_bfcr_cbs cbs, void *data, const bt2c::Logger& logger) { - BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, log_level, self_comp, - "Creating binary field class reader (BFCR)."); + BT_CPPLOGD_STR_SPEC(logger, "Creating binary field class reader (BFCR)."); - bt_bfcr *bfcr = new bt_bfcr; - bfcr->log_level = log_level; - bfcr->self_comp = self_comp; + bt_bfcr *bfcr = new bt_bfcr {logger}; bfcr->stack = stack_new(bfcr); if (!bfcr->stack) { - BT_COMP_LOGE_STR("Cannot create BFCR's stack."); + BT_CPPLOGE_STR_SPEC(bfcr->logger, "Cannot create BFCR's stack."); bt_bfcr_destroy(bfcr); bfcr = NULL; goto end; @@ -1120,7 +1130,7 @@ struct bt_bfcr *bt_bfcr_create(struct bt_bfcr_cbs cbs, void *data, bt_logging_le bfcr->state = BFCR_STATE_NEXT_FIELD; bfcr->user.cbs = cbs; bfcr->user.data = data; - BT_COMP_LOGD("Created BFCR: addr=%p", bfcr); + BT_CPPLOGD_SPEC(bfcr->logger, "Created BFCR: addr={}", fmt::ptr(bfcr)); end: return bfcr; @@ -1132,13 +1142,13 @@ void bt_bfcr_destroy(struct bt_bfcr *bfcr) stack_destroy(bfcr->stack); } - BT_COMP_LOGD("Destroying BFCR: addr=%p", bfcr); + BT_CPPLOGD_SPEC(bfcr->logger, "Destroying BFCR: addr={}", fmt::ptr(bfcr)); delete bfcr; } static void reset(struct bt_bfcr *bfcr) { - BT_COMP_LOGD("Resetting BFCR: addr=%p", bfcr); + BT_CPPLOGD_SPEC(bfcr->logger, "Resetting BFCR: addr={}", fmt::ptr(bfcr)); stack_clear(bfcr->stack); stitch_reset(bfcr); bfcr->buf.addr = NULL; @@ -1147,9 +1157,11 @@ static void reset(struct bt_bfcr *bfcr) static void update_packet_offset(struct bt_bfcr *bfcr) { - BT_COMP_LOGT("Updating packet offset for next call: " - "bfcr-addr=%p, cur-packet-offset=%zu, next-packet-offset=%zu", - bfcr, bfcr->buf.packet_offset, bfcr->buf.packet_offset + bfcr->buf.at); + BT_CPPLOGT_SPEC(bfcr->logger, + "Updating packet offset for next call: " + "bfcr-addr={}, cur-packet-offset={}, next-packet-offset={}", + fmt::ptr(bfcr), bfcr->buf.packet_offset, + bfcr->buf.packet_offset + bfcr->buf.at); bfcr->buf.packet_offset += bfcr->buf.at; } @@ -1167,10 +1179,11 @@ size_t bt_bfcr_start(struct bt_bfcr *bfcr, struct ctf_field_class *cls, const ui bfcr->buf.sz = BYTES_TO_BITS(sz) - offset; *status = BT_BFCR_STATUS_OK; - BT_COMP_LOGT("Starting decoding: bfcr-addr=%p, fc-addr=%p, " - "buf-addr=%p, buf-size=%zu, offset=%zu, " - "packet-offset=%zu", - bfcr, cls, buf, sz, offset, packet_offset); + BT_CPPLOGT_SPEC(bfcr->logger, + "Starting decoding: bfcr-addr={}, fc-addr={}, " + "buf-addr={}, buf-size={}, offset={}, " + "packet-offset={}", + fmt::ptr(bfcr), fmt::ptr(cls), fmt::ptr(buf), sz, offset, packet_offset); /* Set root class */ if (cls->is_compound) { @@ -1178,12 +1191,12 @@ size_t bt_bfcr_start(struct bt_bfcr *bfcr, struct ctf_field_class *cls, const ui int stack_ret; if (bfcr->user.cbs.classes.compound_begin) { - BT_COMP_LOGT("Calling user function (compound, begin)."); + BT_CPPLOGT_SPEC(bfcr->logger, "Calling user function (compound, begin)."); *status = bfcr->user.cbs.classes.compound_begin(cls, bfcr->user.data); - BT_COMP_LOGT("User function returned: status=%s", bt_bfcr_status_string(*status)); + BT_CPPLOGT_SPEC(bfcr->logger, "User function returned: status={}", *status); if (*status != BT_BFCR_STATUS_OK) { - BT_COMP_LOGW("User function failed: bfcr-addr=%p, status=%s", bfcr, - bt_bfcr_status_string(*status)); + BT_CPPLOGW_SPEC(bfcr->logger, "User function failed: bfcr-addr={}, status={}", + fmt::ptr(bfcr), *status); goto end; } } @@ -1203,7 +1216,7 @@ size_t bt_bfcr_start(struct bt_bfcr *bfcr, struct ctf_field_class *cls, const ui } /* Run the machine! */ - BT_COMP_LOGT_STR("Running the state machine."); + BT_CPPLOGT_STR_SPEC(bfcr->logger, "Running the state machine."); while (true) { *status = handle_state(bfcr); @@ -1232,10 +1245,11 @@ size_t bt_bfcr_continue(struct bt_bfcr *bfcr, const uint8_t *buf, size_t sz, bfcr->buf.sz = BYTES_TO_BITS(sz); *status = BT_BFCR_STATUS_OK; - BT_COMP_LOGT("Continuing decoding: bfcr-addr=%p, buf-addr=%p, buf-size=%zu", bfcr, buf, sz); + BT_CPPLOGT_SPEC(bfcr->logger, "Continuing decoding: bfcr-addr={}, buf-addr={}, buf-size={}", + fmt::ptr(bfcr), fmt::ptr(buf), sz); /* Continue running the machine */ - BT_COMP_LOGT_STR("Running the state machine."); + BT_CPPLOGT_STR_SPEC(bfcr->logger, "Running the state machine."); while (true) { *status = handle_state(bfcr); diff --git a/src/plugins/ctf/common/src/bfcr/bfcr.hpp b/src/plugins/ctf/common/src/bfcr/bfcr.hpp index 9e3a2dc1..984b695c 100644 --- a/src/plugins/ctf/common/src/bfcr/bfcr.hpp +++ b/src/plugins/ctf/common/src/bfcr/bfcr.hpp @@ -15,8 +15,16 @@ #include +#include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */ + #include "../metadata/tsdl/ctf-meta.hpp" +namespace bt2c { + +class Logger; + +} /* namespace bt2c */ + /** * @file bfcr.h * @@ -61,6 +69,29 @@ enum bt_bfcr_status BT_BFCR_STATUS_OK = 0, }; +inline const char *format_as(bt_bfcr_status status) noexcept +{ + switch (status) { + case BT_BFCR_STATUS_ENOMEM: + return "BT_BFCR_STATUS_ENOMEM"; + + case BT_BFCR_STATUS_EOF: + return "BT_BFCR_STATUS_EOF"; + + case BT_BFCR_STATUS_INVAL: + return "BT_BFCR_STATUS_INVAL"; + + case BT_BFCR_STATUS_ERROR: + return "BT_BFCR_STATUS_ERROR"; + + case BT_BFCR_STATUS_OK: + return "BT_BFCR_STATUS_OK"; + break; + } + + bt_common_abort(); +} + typedef enum bt_bfcr_status (*bt_bfcr_unsigned_int_cb_func)(uint64_t, struct ctf_field_class *, void *); @@ -253,8 +284,7 @@ struct bt_bfcr_cbs * @param data User data (passed to user callback functions) * @returns New binary class reader on success, or \c NULL on error */ -struct bt_bfcr *bt_bfcr_create(struct bt_bfcr_cbs cbs, void *data, bt_logging_level log_level, - bt_self_component *self_comp); +struct bt_bfcr *bt_bfcr_create(struct bt_bfcr_cbs cbs, void *data, const bt2c::Logger& logger); /** * Destroys a CTF binary class reader, freeing all internal resources. @@ -325,22 +355,4 @@ size_t bt_bfcr_continue(struct bt_bfcr *bfcr, const uint8_t *buf, size_t sz, void bt_bfcr_set_unsigned_int_cb(struct bt_bfcr *bfcr, bt_bfcr_unsigned_int_cb_func cb); -static inline const char *bt_bfcr_status_string(enum bt_bfcr_status status) -{ - switch (status) { - case BT_BFCR_STATUS_ENOMEM: - return "ENOMEM"; - case BT_BFCR_STATUS_EOF: - return "EOF"; - case BT_BFCR_STATUS_INVAL: - return "INVAL"; - case BT_BFCR_STATUS_ERROR: - return "ERROR"; - case BT_BFCR_STATUS_OK: - return "OK"; - } - - bt_common_abort(); -} - #endif /* CTF_BFCR_H */ diff --git a/src/plugins/ctf/common/src/metadata/tsdl/ast.hpp b/src/plugins/ctf/common/src/metadata/tsdl/ast.hpp index a6a7e9f7..fcd33843 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/ast.hpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/ast.hpp @@ -15,6 +15,7 @@ #include "common/assert.h" #include "common/list.h" +#include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */ #include "ctf-meta.hpp" #include "decoder.hpp" @@ -65,6 +66,20 @@ enum node_type #undef ENTRY }; +inline const char *format_as(enum node_type type) noexcept +{ + switch (type) { +#define ENTRY(S) \ +case S: \ + return G_STRINGIFY(S); + + FOREACH_CTF_NODES(ENTRY) +#undef ENTRY + } + + bt_common_abort(); +} + enum ctf_unary { UNARY_UNKNOWN = 0, @@ -74,6 +89,28 @@ enum ctf_unary UNARY_SBRAC, }; +inline const char *format_as(ctf_unary value) noexcept +{ + switch (value) { + case UNARY_UNKNOWN: + return "UNARY_UNKNOWN"; + + case UNARY_STRING: + return "UNARY_STRING"; + + case UNARY_SIGNED_CONSTANT: + return "UNARY_SIGNED_CONSTANT"; + + case UNARY_UNSIGNED_CONSTANT: + return "UNARY_UNSIGNED_CONSTANT"; + + case UNARY_SBRAC: + return "UNARY_SBRAC"; + } + + bt_common_abort(); +} + enum ctf_unary_link { UNARY_LINK_UNKNOWN = 0, @@ -89,6 +126,22 @@ enum ctf_typedec TYPEDEC_NESTED, /* (), array or sequence */ }; +inline const char *format_as(ctf_typedec value) noexcept +{ + switch (value) { + case TYPEDEC_UNKNOWN: + return "TYPEDEC_UNKNOWN"; + + case TYPEDEC_ID: + return "TYPEDEC_ID"; + + case TYPEDEC_NESTED: + return "TYPEDEC_NESTED"; + } + + bt_common_abort(); +} + enum ctf_typespec { TYPESPEC_UNKNOWN = 0, @@ -114,6 +167,76 @@ enum ctf_typespec TYPESPEC_ENUM, }; +inline const char *format_as(ctf_typespec value) noexcept +{ + switch (value) { + case TYPESPEC_UNKNOWN: + return "TYPESPEC_UNKNOWN"; + + case TYPESPEC_VOID: + return "TYPESPEC_VOID"; + + case TYPESPEC_CHAR: + return "TYPESPEC_CHAR"; + + case TYPESPEC_SHORT: + return "TYPESPEC_SHORT"; + + case TYPESPEC_INT: + return "TYPESPEC_INT"; + + case TYPESPEC_LONG: + return "TYPESPEC_LONG"; + + case TYPESPEC_FLOAT: + return "TYPESPEC_FLOAT"; + + case TYPESPEC_DOUBLE: + return "TYPESPEC_DOUBLE"; + + case TYPESPEC_SIGNED: + return "TYPESPEC_SIGNED"; + + case TYPESPEC_UNSIGNED: + return "TYPESPEC_UNSIGNED"; + + case TYPESPEC_BOOL: + return "TYPESPEC_BOOL"; + + case TYPESPEC_COMPLEX: + return "TYPESPEC_COMPLEX"; + + case TYPESPEC_IMAGINARY: + return "TYPESPEC_IMAGINARY"; + + case TYPESPEC_CONST: + return "TYPESPEC_CONST"; + + case TYPESPEC_ID_TYPE: + return "TYPESPEC_ID_TYPE"; + + case TYPESPEC_FLOATING_POINT: + return "TYPESPEC_FLOATING_POINT"; + + case TYPESPEC_INTEGER: + return "TYPESPEC_INTEGER"; + + case TYPESPEC_STRING: + return "TYPESPEC_STRING"; + + case TYPESPEC_STRUCT: + return "TYPESPEC_STRUCT"; + + case TYPESPEC_VARIANT: + return "TYPESPEC_VARIANT"; + + case TYPESPEC_ENUM: + return "TYPESPEC_ENUM"; + } + + bt_common_abort(); +} + struct ctf_node { /* @@ -352,8 +475,6 @@ struct ctf_ast const char *node_type(struct ctf_node *node); -struct meta_log_config; - struct ctf_visitor_generate_ir * ctf_visitor_generate_ir_create(const struct ctf_metadata_decoder_config *config); @@ -367,9 +488,9 @@ ctf_visitor_generate_ir_borrow_ctf_trace_class(struct ctf_visitor_generate_ir *v int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, struct ctf_node *node); -int ctf_visitor_semantic_check(int depth, struct ctf_node *node, struct meta_log_config *log_cfg); +int ctf_visitor_semantic_check(int depth, struct ctf_node *node, const bt2c::Logger& logger); -int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_config *log_cfg); +int ctf_visitor_parent_links(int depth, struct ctf_node *node, const bt2c::Logger& logger); static inline char *ctf_ast_concatenate_unary_strings(struct bt_list_head *head) { @@ -422,8 +543,7 @@ error: #endif static inline int ctf_ast_get_unary_uuid(struct bt_list_head *head, bt_uuid_t uuid, - int log_level BT_AST_LOG_LEVEL_UNUSED_ATTR, - bt_self_component *self_comp BT_AST_LOG_LEVEL_UNUSED_ATTR) + const bt2c::Logger& logger) { int i = 0; int ret = 0; @@ -443,10 +563,7 @@ static inline int ctf_ast_get_unary_uuid(struct bt_list_head *head, bt_uuid_t uu src_string = node->u.unary_expression.u.string; ret = bt_uuid_from_str(src_string, uuid); if (ret) { -#ifdef BT_COMP_LOG_CUR_LVL - BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp, - "Cannot parse UUID: uuid=\"%s\"", src_string); -#endif + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot parse UUID: uuid=\"{}\"", src_string); goto end; } } diff --git a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-resolve.cpp b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-resolve.cpp index 6f8ca2d9..0de4c675 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-resolve.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-resolve.cpp @@ -5,22 +5,12 @@ * Copyright 2015 Jérémie Galarneau */ -#include -#include -#include -#include - #include -#define BT_COMP_LOG_SELF_COMP (ctx->self_comp) -#define BT_COMP_LOG_SELF_COMP_CLASS (ctx->self_comp_class) -#define BT_LOG_OUTPUT_LEVEL ((enum bt_log_level) ctx->log_level) -#define BT_LOG_TAG "PLUGIN/CTF/META/RESOLVE" -#include "logging.hpp" -#include "logging/comp-logging.h" - #include "common/assert.h" #include "common/common.h" +#include "cpp-common/bt2c/logging.hpp" +#include "cpp-common/vendor/fmt/format.h" #include "ctf-meta-visitors.hpp" @@ -46,11 +36,12 @@ struct field_class_stack_frame */ struct resolve_context { - bt_logging_level log_level = (bt_logging_level) 0; + explicit resolve_context(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/CTF/META/RESOLVE"} + { + } - /* Weak, exactly one of these must be set */ - bt_self_component *self_comp = nullptr; - bt_self_component_class *self_comp_class = nullptr; + bt2c::Logger logger; struct ctf_trace_class *tc = nullptr; struct ctf_stream_class *sc = nullptr; @@ -129,22 +120,24 @@ static int field_class_stack_push(field_class_stack_t *stack, struct ctf_field_c struct field_class_stack_frame *frame = NULL; if (!stack || !fc) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid parameter: stack or field class is `NULL`."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Invalid parameter: stack or field class is `NULL`."); ret = -1; goto end; } frame = g_new0(struct field_class_stack_frame, 1); if (!frame) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Failed to allocate one field class stack frame."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Failed to allocate one field class stack frame."); ret = -1; goto end; } - BT_COMP_LOGD("Pushing field class on context's stack: " - "fc-addr=%p, stack-size-before=%u", - fc, stack->len); + BT_CPPLOGD_SPEC(ctx->logger, + "Pushing field class on context's stack: " + "fc-addr={}, stack-size-before={}", + fmt::ptr(fc), stack->len); frame->fc = fc; g_ptr_array_add(stack, frame); @@ -201,7 +194,7 @@ static void field_class_stack_pop(field_class_stack_t *stack, struct resolve_con * This will call the frame's destructor and free it, as * well as put its contained field class. */ - BT_COMP_LOGD("Popping context's stack: stack-size-before=%u", stack->len); + BT_CPPLOGD_SPEC(ctx->logger, "Popping context's stack: stack-size-before={}", stack->len); g_ptr_array_set_size(stack, stack->len - 1); } } @@ -254,17 +247,19 @@ static enum ctf_scope get_root_scope_from_absolute_pathstr(const char *pathstr, if (strncmp(pathstr, absolute_path_prefixes[scope], strlen(absolute_path_prefixes[scope]))) { /* Prefix does not match: try the next one */ - BT_COMP_LOGD("Prefix does not match: trying the next one: " - "path=\"%s\", path-prefix=\"%s\", scope=%s", - pathstr, absolute_path_prefixes[scope], ctf_scope_string(scope)); + BT_CPPLOGD_SPEC(ctx->logger, + "Prefix does not match: trying the next one: " + "path=\"{}\", path-prefix=\"{}\", scope={}", + pathstr, absolute_path_prefixes[scope], scope); continue; } /* Found it! */ ret = scope; - BT_COMP_LOGD("Found root scope from absolute path: " - "path=\"%s\", scope=%s", - pathstr, ctf_scope_string(scope)); + BT_CPPLOGD_SPEC(ctx->logger, + "Found root scope from absolute path: " + "path=\"{}\", scope={}", + pathstr, scope); goto end; } @@ -320,8 +315,8 @@ static GList *pathstr_to_ptokens(const char *pathstr, struct resolve_context *ct if (at == last) { /* Error: empty token */ - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Empty path token: path=\"%s\", pos=%u", - pathstr, (unsigned int) (at - pathstr)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "Empty path token: path=\"{}\", pos={}", + pathstr, (unsigned int) (at - pathstr)); goto error; } @@ -368,7 +363,7 @@ static int ptokens_to_field_path(GList *ptokens, struct ctf_field_path *field_pa struct ctf_field_class *child_fc; const char *ft_name = ptoken_get_string(cur_ptoken); - BT_COMP_LOGD("Current path token: token=\"%s\"", ft_name); + BT_CPPLOGD_SPEC(ctx->logger, "Current path token: token=\"{}\"", ft_name); /* Find to which index corresponds the current path token */ if (fc->type == CTF_FIELD_CLASS_TYPE_ARRAY || fc->type == CTF_FIELD_CLASS_TYPE_SEQUENCE) { @@ -381,21 +376,23 @@ static int ptokens_to_field_path(GList *ptokens, struct ctf_field_path *field_pa * Error: field name does not exist or * wrong current class. */ - BT_COMP_LOGD("Cannot get index of field class: " - "field-name=\"%s\", " - "src-index=%" PRId64 ", " - "child-index=%" PRId64 ", " - "first-level-done=%d", - ft_name, src_index, child_index, first_level_done); + BT_CPPLOGD_SPEC(ctx->logger, + "Cannot get index of field class: " + "field-name=\"{}\", " + "src-index={}, " + "child-index={}, " + "first-level-done={}", + ft_name, src_index, child_index, first_level_done); ret = -1; goto end; } else if (child_index > src_index && !first_level_done) { - BT_COMP_LOGD("Child field class is located after source field class: " - "field-name=\"%s\", " - "src-index=%" PRId64 ", " - "child-index=%" PRId64 ", " - "first-level-done=%d", - ft_name, src_index, child_index, first_level_done); + BT_CPPLOGD_SPEC(ctx->logger, + "Child field class is located after source field class: " + "field-name=\"{}\", " + "src-index={}, " + "child-index={}, " + "first-level-done={}", + ft_name, src_index, child_index, first_level_done); ret = -1; goto end; } @@ -441,9 +438,10 @@ static int absolute_ptokens_to_field_path(GList *ptokens, struct ctf_field_path switch (field_path->root) { case CTF_SCOPE_PACKET_HEADER: if (ctx->tc->is_translated) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Trace class is already translated: " - "root-scope=%s", - ctf_scope_string(field_path->root)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Trace class is already translated: " + "root-scope={}", + field_path->root); ret = -1; goto end; } @@ -453,17 +451,19 @@ static int absolute_ptokens_to_field_path(GList *ptokens, struct ctf_field_path case CTF_SCOPE_EVENT_HEADER: case CTF_SCOPE_EVENT_COMMON_CONTEXT: if (!ctx->sc) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("No current stream class: " - "root-scope=%s", - ctf_scope_string(field_path->root)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "No current stream class: " + "root-scope={}", + field_path->root); ret = -1; goto end; } if (ctx->sc->is_translated) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Stream class is already translated: " - "root-scope=%s", - ctf_scope_string(field_path->root)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Stream class is already translated: " + "root-scope={}", + field_path->root); ret = -1; goto end; } @@ -472,17 +472,19 @@ static int absolute_ptokens_to_field_path(GList *ptokens, struct ctf_field_path case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT: case CTF_SCOPE_EVENT_PAYLOAD: if (!ctx->ec) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("No current event class: " - "root-scope=%s", - ctf_scope_string(field_path->root)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "No current event class: " + "root-scope={}", + field_path->root); ret = -1; goto end; } if (ctx->ec->is_translated) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Event class is already translated: " - "root-scope=%s", - ctf_scope_string(field_path->root)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Event class is already translated: " + "root-scope={}", + field_path->root); ret = -1; goto end; } @@ -500,9 +502,10 @@ static int absolute_ptokens_to_field_path(GList *ptokens, struct ctf_field_path fc = borrow_class_from_ctx(ctx, field_path->root); if (!fc) { /* Error: root class is not available */ - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Root field class is not available: " - "root-scope=%s", - ctf_scope_string(field_path->root)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Root field class is not available: " + "root-scope={}", + field_path->root); ret = -1; goto end; } @@ -537,16 +540,17 @@ static int relative_ptokens_to_field_path(GList *ptokens, struct ctf_field_path int64_t cur_index = field_class_stack_at(ctx->field_class_stack, parent_pos_in_stack)->index; - BT_COMP_LOGD("Locating target field class from current parent field class: " - "parent-pos=%" PRId64 ", parent-fc-addr=%p, " - "cur-index=%" PRId64, - parent_pos_in_stack, parent_class, cur_index); + BT_CPPLOGD_SPEC(ctx->logger, + "Locating target field class from current parent field class: " + "parent-pos={}, parent-fc-addr={}, " + "cur-index={}", + parent_pos_in_stack, fmt::ptr(parent_class), cur_index); /* Locate target from current parent class */ ret = ptokens_to_field_path(ptokens, &tail_field_path, parent_class, cur_index, ctx); if (ret) { /* Not found... yet */ - BT_COMP_LOGD_STR("Not found at this point."); + BT_CPPLOGD_STR_SPEC(ctx->logger, "Not found at this point."); ctf_field_path_clear(&tail_field_path); } else { /* Found: stitch tail field path to head field path */ @@ -600,9 +604,10 @@ static int pathstr_to_field_path(const char *pathstr, struct ctf_field_path *fie /* Convert path string to path tokens */ ptokens = pathstr_to_ptokens(pathstr, ctx); if (!ptokens) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot convert path string to path tokens: " - "path=\"%s\"", - pathstr); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot convert path string to path tokens: " + "path=\"{}\"", + pathstr); ret = -1; goto end; } @@ -613,43 +618,38 @@ static int pathstr_to_field_path(const char *pathstr, struct ctf_field_path *fie if (root_scope == CTF_SCOPE_PACKET_UNKNOWN) { /* Relative path: start with current root scope */ field_path->root = ctx->root_scope; - BT_COMP_LOGD("Detected relative path: starting with current root scope: " - "scope=%s", - ctf_scope_string(field_path->root)); + BT_CPPLOGD_SPEC(ctx->logger, + "Detected relative path: starting with current root scope: " + "scope={}", + field_path->root); ret = relative_ptokens_to_field_path(ptokens, field_path, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Cannot get relative field path of path string: " - "path=\"%s\", start-scope=%s, end-scope=%s", - pathstr, ctf_scope_string(ctx->root_scope), ctf_scope_string(field_path->root)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot get relative field path of path string: " + "path=\"{}\", start-scope={}, end-scope={}", + pathstr, ctx->root_scope, field_path->root); goto end; } } else { /* Absolute path: use found root scope */ field_path->root = root_scope; - BT_COMP_LOGD("Detected absolute path: using root scope: " - "scope=%s", - ctf_scope_string(field_path->root)); + BT_CPPLOGD_SPEC(ctx->logger, + "Detected absolute path: using root scope: " + "scope={}", + field_path->root); ret = absolute_ptokens_to_field_path(ptokens, field_path, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Cannot get absolute field path of path string: " - "path=\"%s\", root-scope=%s", - pathstr, ctf_scope_string(root_scope)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot get absolute field path of path string: " + "path=\"{}\", root-scope={}", + pathstr, root_scope); goto end; } } - if (BT_LOG_ON_TRACE && ret == 0) { - GString *field_path_pretty = ctf_field_path_string(field_path); - const char *field_path_pretty_str = field_path_pretty ? field_path_pretty->str : "(null)"; - - BT_COMP_LOGD("Found field path: path=\"%s\", field-path=\"%s\"", pathstr, - field_path_pretty_str); - - if (field_path_pretty) { - g_string_free(field_path_pretty, TRUE); - } + if (ret == 0) { + BT_CPPLOGD_SPEC(ctx->logger, "Found field path: path=\"{}\", field-path=\"{}\"", pathstr, + *field_path); } end: @@ -671,8 +671,8 @@ static struct ctf_field_class *field_path_to_field_class(struct ctf_field_path * fc = borrow_class_from_ctx(ctx, field_path->root); if (!fc) { /* Error: root class is not available */ - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Root field class is not available: root-scope=%s", - ctf_scope_string(field_path->root)); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Root field class is not available: root-scope={}", field_path->root); goto end; } @@ -722,26 +722,10 @@ static int64_t get_field_paths_lca_index(struct ctf_field_path *field_path1, int64_t lca_index = 0; uint64_t field_path1_len, field_path2_len; - if (BT_LOG_ON_TRACE) { - GString *field_path1_pretty = ctf_field_path_string(field_path1); - GString *field_path2_pretty = ctf_field_path_string(field_path2); - const char *field_path1_pretty_str = - field_path1_pretty ? field_path1_pretty->str : "(null)"; - const char *field_path2_pretty_str = - field_path2_pretty ? field_path2_pretty->str : "(null)"; - - BT_COMP_LOGD("Finding lowest common ancestor (LCA) between two field paths: " - "field-path-1=\"%s\", field-path-2=\"%s\"", - field_path1_pretty_str, field_path2_pretty_str); - - if (field_path1_pretty) { - g_string_free(field_path1_pretty, TRUE); - } - - if (field_path2_pretty) { - g_string_free(field_path2_pretty, TRUE); - } - } + BT_CPPLOGD_SPEC(ctx->logger, + "Finding lowest common ancestor (LCA) between two field paths: " + "field-path-1=\"{}\", field-path-2=\"{}\"", + *field_path1, *field_path2); /* * Start from both roots and find the first mismatch. @@ -759,11 +743,12 @@ static int64_t get_field_paths_lca_index(struct ctf_field_path *field_path1, * This is invalid because the target cannot be * an ancestor of the source. */ - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Source field class is an ancestor of target field class or vice versa: " - "lca-index=%" PRId64 ", " - "field-path-1-len=%" PRIu64 ", " - "field-path-2-len=%" PRIu64, + "lca-index={}, " + "field-path-1-len={}, " + "field-path-2-len={}", lca_index, field_path1_len, field_path2_len); lca_index = -1; break; @@ -780,7 +765,7 @@ static int64_t get_field_paths_lca_index(struct ctf_field_path *field_path1, lca_index++; } - BT_COMP_LOGD("Found LCA: lca-index=%" PRId64, lca_index); + BT_CPPLOGD_SPEC(ctx->logger, "Found LCA: lca-index={}", lca_index); return lca_index; } @@ -804,8 +789,8 @@ static int validate_target_field_path(struct ctf_field_path *target_field_path, * Make sure the target is not a root. */ if (target_field_path_len == 0) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Target field path's length is 0 (targeting the root)."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Target field path's length is 0 (targeting the root)."); ret = -1; goto end; } @@ -815,10 +800,10 @@ static int validate_target_field_path(struct ctf_field_path *target_field_path, * after the context field path's root. */ if (target_field_path->root > ctx_field_path.root) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Target field class is located after source field class: " - "target-root=%s, source-root=%s", - ctf_scope_string(target_field_path->root), ctf_scope_string(ctx_field_path.root)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Target field class is located after source field class: " + "target-root={}, source-root={}", + target_field_path->root, ctx_field_path.root); ret = -1; goto end; } @@ -832,7 +817,7 @@ static int validate_target_field_path(struct ctf_field_path *target_field_path, */ lca_index = get_field_paths_lca_index(target_field_path, &ctx_field_path, ctx); if (lca_index < 0) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot get least common ancestor."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "Cannot get least common ancestor."); ret = -1; goto end; } @@ -846,11 +831,12 @@ static int validate_target_field_path(struct ctf_field_path *target_field_path, ctx_index = ctf_field_path_borrow_index_by_index(&ctx_field_path, (uint64_t) lca_index); if (target_index >= ctx_index) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Target field class's index is greater than or equal to source field class's index in LCA: " - "lca-index=%" PRId64 ", " - "target-index=%" PRId64 ", " - "source-index=%" PRId64, + "lca-index={}, " + "target-index={}, " + "source-index={}", lca_index, target_index, ctx_index); ret = -1; goto end; @@ -863,10 +849,11 @@ static int validate_target_field_path(struct ctf_field_path *target_field_path, switch (ctx->cur_fc->type) { case CTF_FIELD_CLASS_TYPE_VARIANT: if (target_fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Variant field class's tag field class is not an enumeration field class: " - "tag-fc-addr=%p, tag-fc-id=%d", - target_fc, target_fc->type); + "tag-fc-addr={}, tag-fc-id={}", + fmt::ptr(target_fc), (int) target_fc->type); ret = -1; goto end; } @@ -875,10 +862,11 @@ static int validate_target_field_path(struct ctf_field_path *target_field_path, { if (target_fc->type != CTF_FIELD_CLASS_TYPE_INT && target_fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Sequence field class's length field class is not an unsigned integer field class: " - "length-fc-addr=%p, length-fc-id=%d", - target_fc, target_fc->type); + "length-fc-addr={}, length-fc-id={}", + fmt::ptr(target_fc), (int) target_fc->type); ret = -1; goto end; } @@ -886,10 +874,11 @@ static int validate_target_field_path(struct ctf_field_path *target_field_path, ctf_field_class_int *int_fc = ctf_field_class_as_int(target_fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Sequence field class's length field class is not an unsigned integer field class: " - "length-fc-addr=%p, length-fc-id=%d", - target_fc, target_fc->type); + "length-fc-addr={}, length-fc-id={}", + fmt::ptr(target_fc), (int) target_fc->type); ret = -1; goto end; } @@ -914,8 +903,6 @@ static int resolve_sequence_or_variant_field_class(struct ctf_field_class *fc, const char *pathstr; struct ctf_field_path target_field_path; struct ctf_field_class *target_fc = NULL; - GString *target_field_path_pretty = NULL; - const char *target_field_path_pretty_str; ctf_field_path_init(&target_field_path); @@ -938,7 +925,7 @@ static int resolve_sequence_or_variant_field_class(struct ctf_field_class *fc, } if (!pathstr) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot get path string."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "Cannot get path string."); ret = -1; goto end; } @@ -946,30 +933,30 @@ static int resolve_sequence_or_variant_field_class(struct ctf_field_class *fc, /* Get target field path out of path string */ ret = pathstr_to_field_path(pathstr, &target_field_path, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot get target field path for path string: " - "path=\"%s\"", - pathstr); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot get target field path for path string: " + "path=\"{}\"", + pathstr); goto end; } - target_field_path_pretty = ctf_field_path_string(&target_field_path); - target_field_path_pretty_str = target_field_path_pretty ? target_field_path_pretty->str : NULL; - /* Get target field class */ target_fc = field_path_to_field_class(&target_field_path, ctx); if (!target_fc) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot get target field class for path string: " - "path=\"%s\", target-field-path=\"%s\"", - pathstr, target_field_path_pretty_str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot get target field class for path string: " + "path=\"{}\", target-field-path=\"{}\"", + pathstr, target_field_path); ret = -1; goto end; } ret = validate_target_field_path(&target_field_path, target_fc, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid target field path for path string: " - "path=\"%s\", target-field-path=\"%s\"", - pathstr, target_field_path_pretty_str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Invalid target field path for path string: " + "path=\"{}\", target-field-path=\"{}\"", + pathstr, target_field_path); goto end; } @@ -996,10 +983,6 @@ static int resolve_sequence_or_variant_field_class(struct ctf_field_class *fc, } end: - if (target_field_path_pretty) { - g_string_free(target_field_path_pretty, TRUE); - } - ctf_field_path_fini(&target_field_path); return ret; } @@ -1024,10 +1007,11 @@ static int resolve_field_class(struct ctf_field_class *fc, struct resolve_contex case CTF_FIELD_CLASS_TYPE_VARIANT: ret = resolve_sequence_or_variant_field_class(fc, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Cannot resolve sequence field class's length or variant field class's tag: " - "ret=%d, fc-addr=%p", - ret, fc); + "ret={}, fc-addr={}", + ret, fmt::ptr(fc)); goto end; } @@ -1048,9 +1032,10 @@ static int resolve_field_class(struct ctf_field_class *fc, struct resolve_contex ret = field_class_stack_push(ctx->field_class_stack, fc, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot push field class on context's stack: " - "fc-addr=%p", - fc); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot push field class on context's stack: " + "fc-addr={}", + fmt::ptr(fc)); goto end; } @@ -1067,10 +1052,11 @@ static int resolve_field_class(struct ctf_field_class *fc, struct resolve_contex field_class_stack_peek(ctx->field_class_stack)->index = (int64_t) i; } - BT_COMP_LOGD("Resolving field class's child field class: " - "parent-fc-addr=%p, child-fc-addr=%p, " - "index=%" PRIu64 ", count=%" PRIu64, - fc, child_fc, i, field_count); + BT_CPPLOGD_SPEC(ctx->logger, + "Resolving field class's child field class: " + "parent-fc-addr={}, child-fc-addr={}, " + "index={}, count={}", + fmt::ptr(fc), fmt::ptr(child_fc), i, field_count); ret = resolve_field_class(child_fc, ctx); if (ret) { goto end; @@ -1118,19 +1104,20 @@ static int resolve_event_class_field_classes(struct resolve_context *ctx, ctx->scopes.event_spec_context = ec->spec_context_fc; ret = resolve_root_class(CTF_SCOPE_EVENT_COMMON_CONTEXT, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Cannot resolve event specific context field class: " - "ret=%d", - ret); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot resolve event specific context field class: " + "ret={}", + ret); goto end; } ctx->scopes.event_payload = ec->payload_fc; ret = resolve_root_class(CTF_SCOPE_EVENT_PAYLOAD, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve event payload field class: " - "ret=%d", - ret); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot resolve event payload field class: " + "ret={}", + ret); goto end; } @@ -1156,28 +1143,30 @@ static int resolve_stream_class_field_classes(struct resolve_context *ctx, ctx->scopes.packet_context = sc->packet_context_fc; ret = resolve_root_class(CTF_SCOPE_PACKET_CONTEXT, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve packet context field class: " - "ret=%d", - ret); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot resolve packet context field class: " + "ret={}", + ret); goto end; } ctx->scopes.event_header = sc->event_header_fc; ret = resolve_root_class(CTF_SCOPE_EVENT_HEADER, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve event header field class: " - "ret=%d", - ret); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot resolve event header field class: " + "ret={}", + ret); goto end; } ctx->scopes.event_common_context = sc->event_common_context_fc; ret = resolve_root_class(CTF_SCOPE_EVENT_COMMON_CONTEXT, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Cannot resolve event common context field class: " - "ret=%d", - ret); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot resolve event common context field class: " + "ret={}", + ret); goto end; } } @@ -1191,9 +1180,10 @@ static int resolve_stream_class_field_classes(struct resolve_context *ctx, ret = resolve_event_class_field_classes(ctx, ec); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve event class's field classes: " - "ec-id=%" PRIu64 ", ec-name=\"%s\"", - ec->id, ec->name->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot resolve event class's field classes: " + "ec-id={}, ec-name=\"{}\"", + ec->id, ec->name->str); goto end; } } @@ -1207,15 +1197,12 @@ end: } int ctf_trace_class_resolve_field_classes(struct ctf_trace_class *tc, - struct meta_log_config *log_cfg) + const bt2c::Logger& parentLogger) { int ret = 0; uint64_t i; - resolve_context local_ctx {}; - local_ctx.log_level = log_cfg->log_level; - local_ctx.self_comp = log_cfg->self_comp; - local_ctx.self_comp_class = log_cfg->self_comp_class; + resolve_context local_ctx(parentLogger); local_ctx.tc = tc; local_ctx.scopes.packet_header = tc->packet_header_fc; local_ctx.root_scope = CTF_SCOPE_PACKET_HEADER; @@ -1225,7 +1212,7 @@ int ctf_trace_class_resolve_field_classes(struct ctf_trace_class *tc, /* Initialize class stack */ ctx->field_class_stack = field_class_stack_create(); if (!ctx->field_class_stack) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot create field class stack."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "Cannot create field class stack."); ret = -1; goto end; } @@ -1234,9 +1221,10 @@ int ctf_trace_class_resolve_field_classes(struct ctf_trace_class *tc, ctx->scopes.packet_header = tc->packet_header_fc; ret = resolve_root_class(CTF_SCOPE_PACKET_HEADER, ctx); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve packet header field class: " - "ret=%d", - ret); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot resolve packet header field class: " + "ret={}", + ret); goto end; } } @@ -1248,9 +1236,10 @@ int ctf_trace_class_resolve_field_classes(struct ctf_trace_class *tc, ret = resolve_stream_class_field_classes(ctx, sc); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve stream class's field classes: " - "sc-id=%" PRIu64, - sc->id); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot resolve stream class's field classes: " + "sc-id={}", + sc->id); goto end; } } diff --git a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-update-default-clock-classes.cpp b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-update-default-clock-classes.cpp index ab10dd4f..cd9acdf2 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-update-default-clock-classes.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-update-default-clock-classes.cpp @@ -4,20 +4,15 @@ * Copyright 2018 Philippe Proulx */ -#include -#include +#include -#define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp) -#define BT_COMP_LOG_SELF_COMP_CLASS (log_cfg->self_comp_class) -#define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level) -#define BT_LOG_TAG "PLUGIN/CTF/META/UPDATE-DEF-CC" -#include "logging.hpp" +#include "cpp-common/bt2c/logging.hpp" #include "ctf-meta-visitors.hpp" static inline int find_mapped_clock_class(struct ctf_field_class *fc, struct ctf_clock_class **clock_class, - struct meta_log_config *log_cfg) + const bt2c::Logger& logger) { int ret = 0; uint64_t i; @@ -34,11 +29,12 @@ static inline int find_mapped_clock_class(struct ctf_field_class *fc, if (int_fc->mapped_clock_class) { if (*clock_class && *clock_class != int_fc->mapped_clock_class) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Stream class contains more than one " - "clock class: expected-cc-name=\"%s\", " - "other-cc-name=\"%s\"", - (*clock_class)->name->str, - int_fc->mapped_clock_class->name->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Stream class contains more than one " + "clock class: expected-cc-name=\"{}\", " + "other-cc-name=\"{}\"", + (*clock_class)->name->str, + int_fc->mapped_clock_class->name->str); ret = -1; goto end; } @@ -56,7 +52,7 @@ static inline int find_mapped_clock_class(struct ctf_field_class *fc, struct ctf_named_field_class *named_fc = ctf_field_class_struct_borrow_member_by_index(struct_fc, i); - ret = find_mapped_clock_class(named_fc->fc, clock_class, log_cfg); + ret = find_mapped_clock_class(named_fc->fc, clock_class, logger); if (ret) { goto end; } @@ -72,7 +68,7 @@ static inline int find_mapped_clock_class(struct ctf_field_class *fc, struct ctf_named_field_class *named_fc = ctf_field_class_variant_borrow_option_by_index(var_fc, i); - ret = find_mapped_clock_class(named_fc->fc, clock_class, log_cfg); + ret = find_mapped_clock_class(named_fc->fc, clock_class, logger); if (ret) { goto end; } @@ -85,7 +81,7 @@ static inline int find_mapped_clock_class(struct ctf_field_class *fc, { struct ctf_field_class_array_base *array_fc = ctf_field_class_as_array_base(fc); - ret = find_mapped_clock_class(array_fc->elem_fc, clock_class, log_cfg); + ret = find_mapped_clock_class(array_fc->elem_fc, clock_class, logger); if (ret) { goto end; } @@ -101,23 +97,23 @@ end: } static inline int update_stream_class_default_clock_class(struct ctf_stream_class *stream_class, - struct meta_log_config *log_cfg) + const bt2c::Logger& logger) { int ret = 0; struct ctf_clock_class *clock_class = stream_class->default_clock_class; uint64_t i; - ret = find_mapped_clock_class(stream_class->packet_context_fc, &clock_class, log_cfg); + ret = find_mapped_clock_class(stream_class->packet_context_fc, &clock_class, logger); if (ret) { goto end; } - ret = find_mapped_clock_class(stream_class->event_header_fc, &clock_class, log_cfg); + ret = find_mapped_clock_class(stream_class->event_header_fc, &clock_class, logger); if (ret) { goto end; } - ret = find_mapped_clock_class(stream_class->event_common_context_fc, &clock_class, log_cfg); + ret = find_mapped_clock_class(stream_class->event_common_context_fc, &clock_class, logger); if (ret) { goto end; } @@ -126,12 +122,12 @@ static inline int update_stream_class_default_clock_class(struct ctf_stream_clas struct ctf_event_class *event_class = (ctf_event_class *) stream_class->event_classes->pdata[i]; - ret = find_mapped_clock_class(event_class->spec_context_fc, &clock_class, log_cfg); + ret = find_mapped_clock_class(event_class->spec_context_fc, &clock_class, logger); if (ret) { goto end; } - ret = find_mapped_clock_class(event_class->payload_fc, &clock_class, log_cfg); + ret = find_mapped_clock_class(event_class->payload_fc, &clock_class, logger); if (ret) { goto end; } @@ -146,13 +142,14 @@ end: } int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class *ctf_tc, - struct meta_log_config *log_cfg) + const bt2c::Logger& parentLogger) { uint64_t i; int ret = 0; struct ctf_clock_class *clock_class = NULL; + bt2c::Logger logger {parentLogger, "PLUGIN/CTF/META/UPDATE-DEF-CC"}; - ret = find_mapped_clock_class(ctf_tc->packet_header_fc, &clock_class, log_cfg); + ret = find_mapped_clock_class(ctf_tc->packet_header_fc, &clock_class, logger); if (ret) { goto end; } @@ -166,11 +163,12 @@ int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class *ctf_tc, struct ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i]; ret = update_stream_class_default_clock_class( - (ctf_stream_class *) ctf_tc->stream_classes->pdata[i], log_cfg); + (ctf_stream_class *) ctf_tc->stream_classes->pdata[i], logger); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Stream class contains more than one " - "clock class: stream-class-id=%" PRIu64, - sc->id); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Stream class contains more than one " + "clock class: stream-class-id={}", + sc->id); goto end; } } diff --git a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-validate.cpp b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-validate.cpp index 9a01c593..cb4e2b88 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-validate.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-validate.cpp @@ -4,17 +4,13 @@ * Copyright 2018 Philippe Proulx */ -#include +#include -#define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp) -#define BT_COMP_LOG_SELF_COMP_CLASS (log_cfg->self_comp_class) -#define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level) -#define BT_LOG_TAG "PLUGIN/CTF/META/VALIDATE" -#include "logging.hpp" +#include "cpp-common/bt2c/logging.hpp" #include "ctf-meta-visitors.hpp" -static int validate_stream_class(struct ctf_stream_class *sc, struct meta_log_config *log_cfg) +static int validate_stream_class(struct ctf_stream_class *sc, const bt2c::Logger& logger) { int ret = 0; struct ctf_field_class_int *int_fc; @@ -28,17 +24,17 @@ static int validate_stream_class(struct ctf_stream_class *sc, struct meta_log_co ctf_field_class_as_struct(sc->packet_context_fc), "timestamp_begin"); if (fc) { if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet context field class: " - "`timestamp_begin` member is not an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Invalid packet context field class: " + "`timestamp_begin` member is not an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: " - "`timestamp_begin` member is signed."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet context field class: " + "`timestamp_begin` member is signed."); goto invalid; } } @@ -47,17 +43,17 @@ static int validate_stream_class(struct ctf_stream_class *sc, struct meta_log_co ctf_field_class_as_struct(sc->packet_context_fc), "timestamp_end"); if (fc) { if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet context field class: " - "`timestamp_end` member is not an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Invalid packet context field class: " + "`timestamp_end` member is not an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: " - "`timestamp_end` member is signed."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet context field class: " + "`timestamp_end` member is signed."); goto invalid; } } @@ -66,17 +62,17 @@ static int validate_stream_class(struct ctf_stream_class *sc, struct meta_log_co ctf_field_class_as_struct(sc->packet_context_fc), "events_discarded"); if (fc) { if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet context field class: " - "`events_discarded` member is not an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + logger, "Invalid packet context field class: " + "`events_discarded` member is not an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: " - "`events_discarded` member is signed."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet context field class: " + "`events_discarded` member is signed."); goto invalid; } } @@ -85,17 +81,17 @@ static int validate_stream_class(struct ctf_stream_class *sc, struct meta_log_co ctf_field_class_as_struct(sc->packet_context_fc), "packet_seq_num"); if (fc) { if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet context field class: " - "`packet_seq_num` member is not an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Invalid packet context field class: " + "`packet_seq_num` member is not an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: " - "`packet_seq_num` member is signed."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet context field class: " + "`packet_seq_num` member is signed."); goto invalid; } } @@ -104,17 +100,17 @@ static int validate_stream_class(struct ctf_stream_class *sc, struct meta_log_co ctf_field_class_as_struct(sc->packet_context_fc), "packet_size"); if (fc) { if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet context field class: " - "`packet_size` member is not an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Invalid packet context field class: " + "`packet_size` member is not an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: " - "`packet_size` member is signed."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet context field class: " + "`packet_size` member is signed."); goto invalid; } } @@ -123,17 +119,17 @@ static int validate_stream_class(struct ctf_stream_class *sc, struct meta_log_co ctf_field_class_as_struct(sc->packet_context_fc), "content_size"); if (fc) { if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet context field class: " - "`content_size` member is not an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Invalid packet context field class: " + "`content_size` member is not an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: " - "`content_size` member is signed."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet context field class: " + "`content_size` member is signed."); goto invalid; } } @@ -142,23 +138,23 @@ static int validate_stream_class(struct ctf_stream_class *sc, struct meta_log_co ctf_field_class_as_struct(sc->event_header_fc), "id"); if (fc) { if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: " - "`id` member is not an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid event header field class: " + "`id` member is not an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: " - "`id` member is signed."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid event header field class: " + "`id` member is signed."); goto invalid; } } else { if (sc->event_classes->len > 1) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: " - "missing `id` member as there's " - "more than one event class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid event header field class: " + "missing `id` member as there's " + "more than one event class."); goto invalid; } } @@ -172,12 +168,14 @@ end: return ret; } -int ctf_trace_class_validate(struct ctf_trace_class *ctf_tc, struct meta_log_config *log_cfg) +int ctf_trace_class_validate(struct ctf_trace_class *ctf_tc, const bt2c::Logger& parentLogger) { int ret = 0; struct ctf_field_class_int *int_fc; uint64_t i; + bt2c::Logger logger {parentLogger, "PLUGIN/CTF/META/VALIDATE"}; + if (!ctf_tc->is_translated) { struct ctf_field_class *fc; @@ -188,29 +186,29 @@ int ctf_trace_class_validate(struct ctf_trace_class *ctf_tc, struct meta_log_con ctf_field_class_as_struct(ctf_tc->packet_header_fc), 0); if (named_fc->fc != fc) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: " - "`magic` member is not the first member."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "`magic` member is not the first member."); goto invalid; } if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet header field class: " - "`magic` member is not an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Invalid packet header field class: " + "`magic` member is not an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: " - "`magic` member is signed."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "`magic` member is signed."); goto invalid; } if (int_fc->base.size != 32) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: " - "`magic` member is not 32-bit."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "`magic` member is not 32-bit."); goto invalid; } } @@ -219,24 +217,24 @@ int ctf_trace_class_validate(struct ctf_trace_class *ctf_tc, struct meta_log_con ctf_field_class_as_struct(ctf_tc->packet_header_fc), "stream_id"); if (fc) { if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet header field class: " - "`stream_id` member is not an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Invalid packet header field class: " + "`stream_id` member is not an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: " - "`stream_id` member is signed."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "`stream_id` member is signed."); goto invalid; } } else { if (ctf_tc->stream_classes->len > 1) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: " - "missing `stream_id` member as there's " - "more than one stream class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "missing `stream_id` member as there's " + "more than one stream class."); goto invalid; } } @@ -245,17 +243,17 @@ int ctf_trace_class_validate(struct ctf_trace_class *ctf_tc, struct meta_log_con ctf_field_class_as_struct(ctf_tc->packet_header_fc), "stream_instance_id"); if (fc) { if (fc->type != CTF_FIELD_CLASS_TYPE_INT && fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet header field class: " - "`stream_instance_id` member is not an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + logger, "Invalid packet header field class: " + "`stream_instance_id` member is not an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: " - "`stream_instance_id` member is signed."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "`stream_instance_id` member is signed."); goto invalid; } } @@ -264,49 +262,47 @@ int ctf_trace_class_validate(struct ctf_trace_class *ctf_tc, struct meta_log_con ctf_field_class_as_struct(ctf_tc->packet_header_fc), "uuid"); if (fc) { if (fc->type != CTF_FIELD_CLASS_TYPE_ARRAY) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet header field class: " - "`uuid` member is not an array field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "`uuid` member is not an array field class."); goto invalid; } ctf_field_class_array *array_fc = ctf_field_class_as_array(fc); if (array_fc->length != 16) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet header field class: " - "`uuid` member is not a 16-element array field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + logger, "Invalid packet header field class: " + "`uuid` member is not a 16-element array field class."); goto invalid; } if (array_fc->base.elem_fc->type != CTF_FIELD_CLASS_TYPE_INT) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid packet header field class: " - "`uuid` member's element field class is not " - "an integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "`uuid` member's element field class is not " + "an integer field class."); goto invalid; } int_fc = ctf_field_class_as_int(array_fc->base.elem_fc); if (int_fc->is_signed) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: " - "`uuid` member's element field class " - "is a signed integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "`uuid` member's element field class " + "is a signed integer field class."); goto invalid; } if (int_fc->base.size != 8) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: " - "`uuid` member's element field class " - "is not an 8-bit integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "`uuid` member's element field class " + "is not an 8-bit integer field class."); goto invalid; } if (int_fc->base.base.alignment != 8) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: " - "`uuid` member's element field class's " - "alignment is not 8."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid packet header field class: " + "`uuid` member's element field class's " + "alignment is not 8."); goto invalid; } } @@ -315,10 +311,9 @@ int ctf_trace_class_validate(struct ctf_trace_class *ctf_tc, struct meta_log_con for (i = 0; i < ctf_tc->stream_classes->len; i++) { struct ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i]; - ret = validate_stream_class(sc, log_cfg); + ret = validate_stream_class(sc, logger); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid stream class: sc-id=%" PRIu64, - sc->id); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Invalid stream class: sc-id={}", sc->id); goto invalid; } } diff --git a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-visitors.hpp b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-visitors.hpp index 5294ecec..1a6f708f 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-visitors.hpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-visitors.hpp @@ -11,16 +11,20 @@ #include "ctf-meta.hpp" -struct meta_log_config; +namespace bt2c { + +class Logger; + +} /* namespace bt2c */ int ctf_trace_class_resolve_field_classes(struct ctf_trace_class *tc, - struct meta_log_config *log_cfg); + const bt2c::Logger& parentLogger); int ctf_trace_class_translate(bt_self_component *self_comp, bt_trace_class *ir_tc, struct ctf_trace_class *tc); int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class *ctf_tc, - struct meta_log_config *log_cfg); + const bt2c::Logger& parentLogger); int ctf_trace_class_update_in_ir(struct ctf_trace_class *ctf_tc); @@ -34,9 +38,9 @@ int ctf_trace_class_update_value_storing_indexes(struct ctf_trace_class *ctf_tc) int ctf_trace_class_update_stream_class_config(struct ctf_trace_class *ctf_tc); -int ctf_trace_class_validate(struct ctf_trace_class *ctf_tc, struct meta_log_config *log_cfg); +int ctf_trace_class_validate(struct ctf_trace_class *ctf_tc, const bt2c::Logger& parentLogger); void ctf_trace_class_warn_meaningless_header_fields(struct ctf_trace_class *ctf_tc, - struct meta_log_config *log_cfg); + const bt2c::Logger& parentLogger); #endif /* _CTF_META_VISITORS_H */ diff --git a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-warn-meaningless-header-fields.cpp b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-warn-meaningless-header-fields.cpp index 6d7e274a..f09a6b33 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-warn-meaningless-header-fields.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta-warn-meaningless-header-fields.cpp @@ -4,28 +4,22 @@ * Copyright 2018 Philippe Proulx */ -#include -#include - -#define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp) -#define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level) -#define BT_LOG_TAG "PLUGIN/CTF/META/WARN-MEANINGLESS-HEADER-FIELDS" -#include "logging.hpp" -#include "logging/comp-logging.h" +#include #include "common/assert.h" +#include "cpp-common/bt2c/logging.hpp" #include "ctf-meta-visitors.hpp" static inline void warn_meaningless_field(const char *name, const char *scope_name, - struct meta_log_config *log_cfg) + const bt2c::Logger& logger) { BT_ASSERT(name); - BT_COMP_LOGW("User field found in %s: ignoring: name=\"%s\"", scope_name, name); + BT_CPPLOGW_SPEC(logger, "User field found in {}: ignoring: name=\"{}\"", scope_name, name); } static inline void warn_meaningless_fields(struct ctf_field_class *fc, const char *name, - const char *scope_name, struct meta_log_config *log_cfg) + const char *scope_name, const bt2c::Logger& logger) { uint64_t i; @@ -41,7 +35,7 @@ static inline void warn_meaningless_fields(struct ctf_field_class *fc, const cha switch (fc->type) { case CTF_FIELD_CLASS_TYPE_FLOAT: case CTF_FIELD_CLASS_TYPE_STRING: - warn_meaningless_field(name, scope_name, log_cfg); + warn_meaningless_field(name, scope_name, logger); break; case CTF_FIELD_CLASS_TYPE_INT: case CTF_FIELD_CLASS_TYPE_ENUM: @@ -49,7 +43,7 @@ static inline void warn_meaningless_fields(struct ctf_field_class *fc, const cha struct ctf_field_class_int *int_fc = ctf_field_class_as_int(fc); if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE && !int_fc->mapped_clock_class) { - warn_meaningless_field(name, scope_name, log_cfg); + warn_meaningless_field(name, scope_name, logger); } break; @@ -62,7 +56,7 @@ static inline void warn_meaningless_fields(struct ctf_field_class *fc, const cha struct ctf_named_field_class *named_fc = ctf_field_class_struct_borrow_member_by_index(struct_fc, i); - warn_meaningless_fields(named_fc->fc, named_fc->name->str, scope_name, log_cfg); + warn_meaningless_fields(named_fc->fc, named_fc->name->str, scope_name, logger); } break; @@ -75,7 +69,7 @@ static inline void warn_meaningless_fields(struct ctf_field_class *fc, const cha struct ctf_named_field_class *named_fc = ctf_field_class_variant_borrow_option_by_index(var_fc, i); - warn_meaningless_fields(named_fc->fc, named_fc->name->str, scope_name, log_cfg); + warn_meaningless_fields(named_fc->fc, named_fc->name->str, scope_name, logger); } break; @@ -93,7 +87,7 @@ static inline void warn_meaningless_fields(struct ctf_field_class *fc, const cha { struct ctf_field_class_array_base *array_fc = ctf_field_class_as_array_base(fc); - warn_meaningless_fields(array_fc->elem_fc, name, scope_name, log_cfg); + warn_meaningless_fields(array_fc->elem_fc, name, scope_name, logger); break; } default: @@ -105,19 +99,20 @@ end: } void ctf_trace_class_warn_meaningless_header_fields(struct ctf_trace_class *ctf_tc, - struct meta_log_config *log_cfg) + const bt2c::Logger& parentLogger) { uint64_t i; + bt2c::Logger logger {parentLogger, "PLUGIN/CTF/META/WARN-MEANINGLESS-HEADER-FIELDS"}; if (!ctf_tc->is_translated) { - warn_meaningless_fields(ctf_tc->packet_header_fc, NULL, "packet header", log_cfg); + warn_meaningless_fields(ctf_tc->packet_header_fc, NULL, "packet header", logger); } for (i = 0; i < ctf_tc->stream_classes->len; i++) { ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i]; if (!sc->is_translated) { - warn_meaningless_fields(sc->event_header_fc, NULL, "event header", log_cfg); + warn_meaningless_fields(sc->event_header_fc, NULL, "event header", logger); } } } diff --git a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta.hpp b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta.hpp index 87469d3b..5efa7106 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta.hpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/ctf-meta.hpp @@ -16,6 +16,7 @@ #include "common/assert.h" #include "common/common.h" #include "common/uuid.h" +#include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */ enum ctf_field_class_type { @@ -29,6 +30,37 @@ enum ctf_field_class_type CTF_FIELD_CLASS_TYPE_VARIANT, }; +inline const char *format_as(ctf_field_class_type type) noexcept +{ + switch (type) { + case CTF_FIELD_CLASS_TYPE_INT: + return "CTF_FIELD_CLASS_TYPE_INT"; + + case CTF_FIELD_CLASS_TYPE_ENUM: + return "CTF_FIELD_CLASS_TYPE_ENUM"; + + case CTF_FIELD_CLASS_TYPE_FLOAT: + return "CTF_FIELD_CLASS_TYPE_FLOAT"; + + case CTF_FIELD_CLASS_TYPE_STRING: + return "CTF_FIELD_CLASS_TYPE_STRING"; + + case CTF_FIELD_CLASS_TYPE_STRUCT: + return "CTF_FIELD_CLASS_TYPE_STRUCT"; + + case CTF_FIELD_CLASS_TYPE_ARRAY: + return "CTF_FIELD_CLASS_TYPE_ARRAY"; + + case CTF_FIELD_CLASS_TYPE_SEQUENCE: + return "CTF_FIELD_CLASS_TYPE_SEQUENCE"; + + case CTF_FIELD_CLASS_TYPE_VARIANT: + return "CTF_FIELD_CLASS_TYPE_VARIANT"; + } + + bt_common_abort(); +} + enum ctf_field_class_meaning { CTF_FIELD_CLASS_MEANING_NONE, @@ -70,6 +102,34 @@ enum ctf_scope CTF_SCOPE_EVENT_PAYLOAD, }; +inline const char *format_as(const ctf_scope scope) noexcept +{ + switch (scope) { + case CTF_SCOPE_PACKET_UNKNOWN: + return "PACKET_UNKNOWN"; + + case CTF_SCOPE_PACKET_HEADER: + return "PACKET_HEADER"; + + case CTF_SCOPE_PACKET_CONTEXT: + return "PACKET_CONTEXT"; + + case CTF_SCOPE_EVENT_HEADER: + return "EVENT_HEADER"; + + case CTF_SCOPE_EVENT_COMMON_CONTEXT: + return "EVENT_COMMON_CONTEXT"; + + case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT: + return "EVENT_SPECIFIC_CONTEXT"; + + case CTF_SCOPE_EVENT_PAYLOAD: + return "EVENT_PAYLOAD"; + } + + bt_common_abort(); +} + struct ctf_clock_class { GString *name; @@ -1135,8 +1195,7 @@ static inline void ctf_field_path_append_index(struct ctf_field_path *fp, int64_ g_array_append_val(fp->path, index); } -static inline int64_t ctf_field_path_borrow_index_by_index(struct ctf_field_path *fp, - uint64_t index) +static inline int64_t ctf_field_path_borrow_index_by_index(const ctf_field_path *fp, uint64_t index) { BT_ASSERT_DBG(fp); BT_ASSERT_DBG(index < fp->path->len); @@ -1149,46 +1208,15 @@ static inline void ctf_field_path_clear(struct ctf_field_path *fp) g_array_set_size(fp->path, 0); } -static inline const char *ctf_scope_string(enum ctf_scope scope) +inline std::string format_as(const ctf_field_path& path) { - switch (scope) { - case CTF_SCOPE_PACKET_HEADER: - return "PACKET_HEADER"; - case CTF_SCOPE_PACKET_CONTEXT: - return "PACKET_CONTEXT"; - case CTF_SCOPE_EVENT_HEADER: - return "EVENT_HEADER"; - case CTF_SCOPE_EVENT_COMMON_CONTEXT: - return "EVENT_COMMON_CONTEXT"; - case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT: - return "EVENT_SPECIFIC_CONTEXT"; - case CTF_SCOPE_EVENT_PAYLOAD: - return "EVENT_PAYLOAD"; - default: - bt_common_abort(); - } -} + std::string str = fmt::format("[{}", path.root); -static inline GString *ctf_field_path_string(struct ctf_field_path *path) -{ - GString *str = g_string_new(NULL); - uint64_t i; - - BT_ASSERT(path); - - if (!str) { - goto end; - } - - g_string_append_printf(str, "[%s", ctf_scope_string(path->root)); - - for (i = 0; i < path->path->len; i++) { - g_string_append_printf(str, ", %" PRId64, ctf_field_path_borrow_index_by_index(path, i)); + for (guint i = 0; i < path.path->len; i++) { + str += fmt::format(", {}", ctf_field_path_borrow_index_by_index(&path, i)); } - g_string_append(str, "]"); - -end: + str += ']'; return str; } diff --git a/src/plugins/ctf/common/src/metadata/tsdl/decoder-packetized-file-stream-to-buf.cpp b/src/plugins/ctf/common/src/metadata/tsdl/decoder-packetized-file-stream-to-buf.cpp index 186ccb42..846df316 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/decoder-packetized-file-stream-to-buf.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/decoder-packetized-file-stream-to-buf.cpp @@ -4,19 +4,9 @@ * Copyright 2016-2017 Philippe Proulx */ -#include +#include #include #include -#include - -#include - -#define BT_COMP_LOG_SELF_COMP self_comp -#define BT_COMP_LOG_SELF_COMP_CLASS self_comp_class -#define BT_LOG_OUTPUT_LEVEL log_level -#define BT_LOG_TAG "PLUGIN/CTF/META/DECODER-DECODE-PACKET" -#include "logging.hpp" -#include "logging/comp-logging.h" #include "common/uuid.h" #include "compat/memstream.h" @@ -41,8 +31,7 @@ struct packet_header } __attribute__((__packed__)); static int decode_packet(FILE *in_fp, FILE *out_fp, int byte_order, bool *is_uuid_set, - uint8_t *uuid, bt_logging_level log_level, bt_self_component *self_comp, - bt_self_component_class *self_comp_class) + uint8_t *uuid, const bt2c::Logger& logger) { struct packet_header header; size_t readlen, writelen, toread; @@ -51,19 +40,18 @@ static int decode_packet(FILE *in_fp, FILE *out_fp, int byte_order, bool *is_uui const long offset = ftell(in_fp); if (offset < 0) { - BT_COMP_LOGE_APPEND_CAUSE_ERRNO(BT_COMP_LOG_SELF_COMP, - "Failed to get current metadata file position", "."); + BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(logger, "Failed to get current metadata file position", + "."); goto error; } - BT_COMP_LOGD("Decoding metadata packet: offset=%ld", offset); + BT_CPPLOGD_SPEC(logger, "Decoding metadata packet: offset={}", offset); readlen = fread(&header, sizeof(header), 1, in_fp); if (feof(in_fp) != 0) { - BT_COMP_LOGI("Reached end of file: offset=%ld", ftell(in_fp)); + BT_CPPLOGI_SPEC(logger, "Reached end of file: offset={}", ftell(in_fp)); goto end; } if (readlen < 1) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot decode metadata packet: offset=%ld", - offset); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot decode metadata packet: offset={}", offset); goto error; } @@ -75,33 +63,39 @@ static int decode_packet(FILE *in_fp, FILE *out_fp, int byte_order, bool *is_uui } if (header.compression_scheme) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + logger, "Metadata packet compression is not supported as of this version: " - "compression-scheme=%u, offset=%ld", + "compression-scheme={}, offset={}", (unsigned int) header.compression_scheme, offset); goto error; } if (header.encryption_scheme) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + logger, "Metadata packet encryption is not supported as of this version: " - "encryption-scheme=%u, offset=%ld", + "encryption-scheme={}, offset={}", (unsigned int) header.encryption_scheme, offset); goto error; } if (header.checksum || header.checksum_scheme) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + auto checksum = header.checksum; + + BT_CPPLOGE_APPEND_CAUSE_SPEC( + logger, "Metadata packet checksum verification is not supported as of this version: " - "checksum-scheme=%u, checksum=%x, offset=%ld", - (unsigned int) header.checksum_scheme, header.checksum, offset); + "checksum-scheme={}, checksum={}, offset={}", + (unsigned int) header.checksum_scheme, checksum, offset); goto error; } if (!ctf_metadata_decoder_is_packet_version_valid(header.major, header.minor)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid metadata packet version: " - "version=%u.%u, offset=%ld", - header.major, header.minor, offset); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Invalid metadata packet version: " + "version={}.{}, offset={}", + header.major, header.minor, offset); goto error; } @@ -111,21 +105,24 @@ static int decode_packet(FILE *in_fp, FILE *out_fp, int byte_order, bool *is_uui bt_uuid_copy(uuid, header.uuid); *is_uuid_set = true; } else if (bt_uuid_compare(header.uuid, uuid)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + logger, "Metadata UUID mismatch between packets of the same stream: " "packet-uuid=\"" BT_UUID_FMT "\", " "expected-uuid=\"" BT_UUID_FMT "\", " - "offset=%ld", + "offset={}", BT_UUID_FMT_VALUES(header.uuid), BT_UUID_FMT_VALUES(uuid), offset); goto error; } } if ((header.content_size / CHAR_BIT) < sizeof(header)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Bad metadata packet content size: content-size=%u, " - "offset=%ld", - header.content_size, offset); + auto content_size = header.content_size; + + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Bad metadata packet content size: content-size={}, " + "offset={}", + content_size, offset); goto error; } @@ -137,24 +134,26 @@ static int decode_packet(FILE *in_fp, FILE *out_fp, int byte_order, bool *is_uui loop_read = MIN(sizeof(buf) - 1, toread); readlen = fread(buf, sizeof(uint8_t), loop_read, in_fp); if (ferror(in_fp)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot read metadata packet buffer: " - "offset=%ld, read-size=%zu", - ftell(in_fp), loop_read); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Cannot read metadata packet buffer: " + "offset={}, read-size={}", + ftell(in_fp), loop_read); goto error; } if (readlen > loop_read) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("fread returned more byte than expected: " - "read-size-asked=%zu, read-size-returned=%zu", - loop_read, readlen); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "fread returned more byte than expected: " + "read-size-asked={}, read-size-returned={}", + loop_read, readlen); goto error; } writelen = fwrite(buf, sizeof(uint8_t), readlen, out_fp); if (writelen < readlen || ferror(out_fp)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Cannot write decoded metadata text to buffer: " - "read-offset=%ld, write-size=%zu", - ftell(in_fp), readlen); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Cannot write decoded metadata text to buffer: " + "read-offset={}, write-size={}", + ftell(in_fp), readlen); goto error; } @@ -166,7 +165,7 @@ static int decode_packet(FILE *in_fp, FILE *out_fp, int byte_order, bool *is_uui toread = (header.packet_size - header.content_size) / CHAR_BIT; fseek_ret = fseek(in_fp, toread, SEEK_CUR); if (fseek_ret < 0) { - BT_COMP_LOGW_STR("Missing padding at the end of the metadata stream."); + BT_CPPLOGW_STR_SPEC(logger, "Missing padding at the end of the metadata stream."); } break; } @@ -183,19 +182,18 @@ end: int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp, char **buf, int byte_order, bool *is_uuid_set, uint8_t *uuid, - bt_logging_level log_level, - bt_self_component *self_comp, - bt_self_component_class *self_comp_class) + const bt2c::Logger& parentLogger) { FILE *out_fp; size_t size; int ret = 0; int tret; size_t packet_index = 0; + bt2c::Logger logger {parentLogger, "PLUGIN/CTF/META/DECODER-DECODE-PACKET"}; out_fp = bt_open_memstream(buf, &size); if (!out_fp) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot open memory stream: %s.", strerror(errno)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot open memory stream: {}.", strerror(errno)); goto error; } @@ -204,11 +202,9 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp, char **buf, int break; } - tret = decode_packet(fp, out_fp, byte_order, is_uuid_set, uuid, log_level, self_comp, - self_comp_class); + tret = decode_packet(fp, out_fp, byte_order, is_uuid_set, uuid, logger); if (tret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot decode packet: index=%zu", - packet_index); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot decode packet: index={}", packet_index); goto error; } @@ -218,8 +214,7 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp, char **buf, int /* Make sure the whole string ends with a null character */ tret = fputc('\0', out_fp); if (tret == EOF) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Cannot append '\\0' to the decoded metadata buffer."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot append '\\0' to the decoded metadata buffer."); goto error; } @@ -233,7 +228,7 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp, char **buf, int */ out_fp = NULL; if (ret < 0) { - BT_COMP_LOGE_APPEND_CAUSE_ERRNO(BT_COMP_LOG_SELF_COMP, "Cannot close memory stream", "."); + BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(logger, "Cannot close memory stream", "."); goto error; } @@ -244,7 +239,7 @@ error: if (out_fp) { if (bt_close_memstream(buf, &size, out_fp)) { - BT_COMP_LOGE_ERRNO("Cannot close memory stream", "."); + BT_CPPLOGE_ERRNO_SPEC(logger, "Cannot close memory stream", "."); } } diff --git a/src/plugins/ctf/common/src/metadata/tsdl/decoder-packetized-file-stream-to-buf.hpp b/src/plugins/ctf/common/src/metadata/tsdl/decoder-packetized-file-stream-to-buf.hpp index 8d831536..6190b061 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/decoder-packetized-file-stream-to-buf.hpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/decoder-packetized-file-stream-to-buf.hpp @@ -13,10 +13,14 @@ #include +namespace bt2c { + +class Logger; + +} /* namespace bt2c */ + int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp, char **buf, int byte_order, bool *is_uuid_set, uint8_t *uuid, - bt_logging_level log_level, - bt_self_component *self_comp, - bt_self_component_class *self_comp_class); + const bt2c::Logger& parentLogger); #endif /* SRC_PLUGINS_CTF_COMMON_METADATA_DECODER_PACKETIZED_FILE_STREAM_TO_BUF */ diff --git a/src/plugins/ctf/common/src/metadata/tsdl/decoder.cpp b/src/plugins/ctf/common/src/metadata/tsdl/decoder.cpp index 382de995..71fdcadf 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/decoder.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/decoder.cpp @@ -4,25 +4,14 @@ * Copyright 2016-2017 Philippe Proulx */ -#include -#include #include #include #include -#include - -#include - -#define BT_COMP_LOG_SELF_COMP (mdec->config.self_comp) -#define BT_COMP_LOG_SELF_COMP_CLASS (mdec->config.self_comp_class) -#define BT_LOG_OUTPUT_LEVEL ((enum bt_log_level) mdec->config.log_level) -#define BT_LOG_TAG "PLUGIN/CTF/META/DECODER" -#include "logging.hpp" -#include "logging/comp-logging.h" #include "common/assert.h" #include "common/uuid.h" #include "compat/memstream.h" +#include "cpp-common/vendor/fmt/format.h" #include "ast.hpp" #include "decoder-packetized-file-stream-to-buf.hpp" @@ -34,6 +23,12 @@ struct ctf_metadata_decoder { + explicit ctf_metadata_decoder(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/CTF/META/DECODER"}, config {logger} + { + } + + bt2c::Logger logger; struct ctf_scanner *scanner = nullptr; GString *text = nullptr; struct ctf_visitor_generate_ir *visitor = nullptr; @@ -41,7 +36,6 @@ struct ctf_metadata_decoder bool is_uuid_set = false; int bo = 0; struct ctf_metadata_decoder_config config; - struct meta_log_config log_cfg; bool has_checked_plaintext_signature = false; }; @@ -60,7 +54,7 @@ struct packet_header } __attribute__((__packed__)); int ctf_metadata_decoder_is_packetized(FILE *fp, bool *is_packetized, int *byte_order, - bt_logging_level log_level, bt_self_component *self_comp) + const bt2c::Logger& logger) { uint32_t magic; size_t len; @@ -69,8 +63,8 @@ int ctf_metadata_decoder_is_packetized(FILE *fp, bool *is_packetized, int *byte_ *is_packetized = false; len = fread(&magic, sizeof(magic), 1, fp); if (len != 1) { - BT_COMP_LOG_CUR_LVL( - BT_LOG_INFO, log_level, self_comp, + BT_CPPLOGI_SPEC( + logger, "Cannot read first metadata packet header: assuming the stream is not packetized."); ret = -1; goto end; @@ -96,29 +90,29 @@ struct ctf_metadata_decoder * ctf_metadata_decoder_create(const struct ctf_metadata_decoder_config *config) { BT_ASSERT(config); - BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, config->log_level, config->self_comp, - "Creating CTF metadata decoder: " - "clock-class-offset-s=%" PRId64 ", " - "clock-class-offset-ns=%" PRId64, - config->clock_class_offset_s, config->clock_class_offset_ns); - - ctf_metadata_decoder *mdec = new ctf_metadata_decoder; - mdec->log_cfg.log_level = config->log_level; - mdec->log_cfg.self_comp = config->self_comp; - mdec->log_cfg.self_comp_class = config->self_comp_class; - mdec->scanner = ctf_scanner_alloc(); + + BT_CPPLOGD_SPEC(config->logger, + "Creating CTF metadata decoder: " + "clock-class-offset-s={}, " + "clock-class-offset-ns={}", + config->clock_class_offset_s, config->clock_class_offset_ns); + + ctf_metadata_decoder *mdec = new ctf_metadata_decoder {config->logger}; + mdec->scanner = ctf_scanner_alloc(mdec->logger); if (!mdec->scanner) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot allocate a metadata lexical scanner: " - "mdec-addr=%p", - mdec); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, + "Cannot allocate a metadata lexical scanner: " + "mdec-addr={}", + fmt::ptr(mdec)); goto error; } mdec->text = g_string_new(NULL); if (!mdec->text) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Failed to allocate one GString: " - "mdec-addr=%p", - mdec); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, + "Failed to allocate one GString: " + "mdec-addr={}", + fmt::ptr(mdec)); goto error; } @@ -126,16 +120,18 @@ ctf_metadata_decoder_create(const struct ctf_metadata_decoder_config *config) mdec->config = *config; mdec->visitor = ctf_visitor_generate_ir_create(config); if (!mdec->visitor) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Failed to create a CTF IR metadata AST visitor: " - "mdec-addr=%p", - mdec); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, + "Failed to create a CTF IR metadata AST visitor: " + "mdec-addr={}", + fmt::ptr(mdec)); goto error; } - BT_COMP_LOGD("Creating CTF metadata decoder: " - "clock-class-offset-s=%" PRId64 ", " - "clock-class-offset-ns=%" PRId64 ", addr=%p", - config->clock_class_offset_s, config->clock_class_offset_ns, mdec); + BT_CPPLOGD_SPEC(mdec->logger, + "Creating CTF metadata decoder: " + "clock-class-offset-s={}, " + "clock-class-offset-ns={}, addr={}", + config->clock_class_offset_s, config->clock_class_offset_ns, fmt::ptr(mdec)); goto end; error: @@ -160,7 +156,7 @@ void ctf_metadata_decoder_destroy(struct ctf_metadata_decoder *mdec) g_string_free(mdec->text, TRUE); } - BT_COMP_LOGD("Destroying CTF metadata decoder: addr=%p", mdec); + BT_CPPLOGD_SPEC(mdec->logger, "Destroying CTF metadata decoder: addr={}", fmt::ptr(mdec)); ctf_visitor_generate_ir_destroy(mdec->visitor); delete mdec; } @@ -176,23 +172,23 @@ ctf_metadata_decoder_append_content(struct ctf_metadata_decoder *mdec, FILE *fp) bool is_packetized; BT_ASSERT(mdec); - ret = ctf_metadata_decoder_is_packetized(fp, &is_packetized, &mdec->bo, mdec->config.log_level, - mdec->config.self_comp); + ret = ctf_metadata_decoder_is_packetized(fp, &is_packetized, &mdec->bo, mdec->logger); if (ret) { status = CTF_METADATA_DECODER_STATUS_ERROR; goto end; } if (is_packetized) { - BT_COMP_LOGI("Metadata stream is packetized: mdec-addr=%p", mdec); + BT_CPPLOGI_SPEC(mdec->logger, "Metadata stream is packetized: mdec-addr={}", + fmt::ptr(mdec)); ret = ctf_metadata_decoder_packetized_file_stream_to_buf( - fp, &buf, mdec->bo, &mdec->is_uuid_set, mdec->uuid, mdec->config.log_level, - mdec->config.self_comp, mdec->config.self_comp_class); + fp, &buf, mdec->bo, &mdec->is_uuid_set, mdec->uuid, mdec->logger); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + mdec->logger, "Cannot decode packetized metadata packets to metadata text: " - "mdec-addr=%p, ret=%d", - mdec, ret); + "mdec-addr={}, ret={}", + fmt::ptr(mdec), ret); status = CTF_METADATA_DECODER_STATUS_ERROR; goto end; } @@ -206,9 +202,10 @@ ctf_metadata_decoder_append_content(struct ctf_metadata_decoder *mdec, FILE *fp) fp = bt_fmemopen(buf, strlen(buf), "rb"); close_fp = true; if (!fp) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot memory-open metadata buffer: %s: " - "mdec-addr=%p", - strerror(errno), mdec); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, + "Cannot memory-open metadata buffer: {}: " + "mdec-addr={}", + strerror(errno), fmt::ptr(mdec)); status = CTF_METADATA_DECODER_STATUS_ERROR; goto end; } @@ -217,11 +214,12 @@ ctf_metadata_decoder_append_content(struct ctf_metadata_decoder *mdec, FILE *fp) ssize_t nr_items; const long init_pos = ftell(fp); - BT_COMP_LOGI("Metadata stream is plain text: mdec-addr=%p", mdec); + BT_CPPLOGI_SPEC(mdec->logger, "Metadata stream is plain text: mdec-addr={}", + fmt::ptr(mdec)); if (init_pos < 0) { - BT_COMP_LOGE_APPEND_CAUSE_ERRNO(BT_COMP_LOG_SELF_COMP, - "Failed to get current file position", "."); + BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(mdec->logger, "Failed to get current file position", + "."); status = CTF_METADATA_DECODER_STATUS_ERROR; goto end; } @@ -229,28 +227,31 @@ ctf_metadata_decoder_append_content(struct ctf_metadata_decoder *mdec, FILE *fp) /* Check text-only metadata header and version */ nr_items = fscanf(fp, "/* CTF %10u.%10u", &major, &minor); if (nr_items < 2) { - BT_COMP_LOGW( + BT_CPPLOGW_SPEC( + mdec->logger, "Missing \"/* CTF major.minor\" signature in plain text metadata file stream: " - "mdec-addr=%p", - mdec); + "mdec-addr={}", + fmt::ptr(mdec)); } - BT_COMP_LOGI("Found metadata stream version in signature: version=%u.%u", major, minor); + BT_CPPLOGI_SPEC(mdec->logger, "Found metadata stream version in signature: version={}.{}", + major, minor); if (!ctf_metadata_decoder_is_packet_version_valid(major, minor)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Invalid metadata version found in plain text signature: " - "version=%u.%u, mdec-addr=%p", - major, minor, mdec); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, + "Invalid metadata version found in plain text signature: " + "version={}.{}, mdec-addr={}", + major, minor, fmt::ptr(mdec)); status = CTF_METADATA_DECODER_STATUS_INVAL_VERSION; goto end; } if (fseek(fp, init_pos, SEEK_SET)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Cannot seek metadata file stream to initial position: %s: " - "mdec-addr=%p", - strerror(errno), mdec); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + mdec->logger, + "Cannot seek metadata file stream to initial position: {}: " + "mdec-addr={}", + strerror(errno), fmt::ptr(mdec)); status = CTF_METADATA_DECODER_STATUS_ERROR; goto end; } @@ -259,7 +260,7 @@ ctf_metadata_decoder_append_content(struct ctf_metadata_decoder *mdec, FILE *fp) } #if YYDEBUG - if (BT_LOG_ON_TRACE) { + if (mdec->logger.wouldLogT()) { yydebug = 1; } #endif @@ -274,10 +275,10 @@ ctf_metadata_decoder_append_content(struct ctf_metadata_decoder *mdec, FILE *fp) /* Append the metadata text content */ ret = ctf_scanner_append_ast(mdec->scanner, fp); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Cannot create the metadata AST out of the metadata text: " - "mdec-addr=%p", - mdec); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, + "Cannot create the metadata AST out of the metadata text: " + "mdec-addr={}", + fmt::ptr(mdec)); status = CTF_METADATA_DECODER_STATUS_INCOMPLETE; goto end; } @@ -287,27 +288,29 @@ ctf_metadata_decoder_append_content(struct ctf_metadata_decoder *mdec, FILE *fp) BT_ASSERT(start_pos != -1); ret = fseek(fp, start_pos, SEEK_SET); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Failed to seek file: ret=%d, mdec-addr=%p", - ret, mdec); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, "Failed to seek file: ret={}, mdec-addr={}", + ret, fmt::ptr(mdec)); status = CTF_METADATA_DECODER_STATUS_ERROR; goto end; } ret = bt_common_append_file_content_to_g_string(mdec->text, fp); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Failed to append to current plain text: " - "ret=%d, mdec-addr=%p", - ret, mdec); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, + "Failed to append to current plain text: " + "ret={}, mdec-addr={}", + ret, fmt::ptr(mdec)); status = CTF_METADATA_DECODER_STATUS_ERROR; goto end; } } - ret = ctf_visitor_semantic_check(0, &mdec->scanner->ast->root, &mdec->log_cfg); + ret = ctf_visitor_semantic_check(0, &mdec->scanner->ast->root, mdec->logger); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Validation of the metadata semantics failed: " - "mdec-addr=%p", - mdec); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, + "Validation of the metadata semantics failed: " + "mdec-addr={}", + fmt::ptr(mdec)); status = CTF_METADATA_DECODER_STATUS_ERROR; goto end; } @@ -319,16 +322,17 @@ ctf_metadata_decoder_append_content(struct ctf_metadata_decoder *mdec, FILE *fp) /* Success */ break; case -EINCOMPLETE: - BT_COMP_LOGD("While visiting metadata AST: incomplete data: " - "mdec-addr=%p", - mdec); + BT_CPPLOGD_SPEC(mdec->logger, + "While visiting metadata AST: incomplete data: " + "mdec-addr={}", + fmt::ptr(mdec)); status = CTF_METADATA_DECODER_STATUS_INCOMPLETE; goto end; default: - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Failed to visit AST node to create CTF IR objects: " - "mdec-addr=%p, ret=%d", - mdec, ret); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, + "Failed to visit AST node to create CTF IR objects: " + "mdec-addr={}, ret={}", + fmt::ptr(mdec), ret); status = CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR; goto end; } @@ -341,9 +345,10 @@ end: if (fp && close_fp) { if (fclose(fp)) { - BT_COMP_LOGE("Cannot close metadata file stream: " - "mdec-addr=%p", - mdec); + BT_CPPLOGE_SPEC(mdec->logger, + "Cannot close metadata file stream: " + "mdec-addr={}", + fmt::ptr(mdec)); } } @@ -412,16 +417,16 @@ static enum ctf_metadata_decoder_status find_uuid_in_trace_decl(struct ctf_metad left = ctf_ast_concatenate_unary_strings(&entry_node->u.ctf_expression.left); if (!left) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot concatenate unary strings."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, "Cannot concatenate unary strings."); status = CTF_METADATA_DECODER_STATUS_ERROR; goto end; } if (strcmp(left, "uuid") == 0) { - ret = ctf_ast_get_unary_uuid(&entry_node->u.ctf_expression.right, uuid, - mdec->config.log_level, mdec->config.self_comp); + ret = + ctf_ast_get_unary_uuid(&entry_node->u.ctf_expression.right, uuid, mdec->logger); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid trace's `uuid` attribute."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(mdec->logger, "Invalid trace's `uuid` attribute."); status = CTF_METADATA_DECODER_STATUS_ERROR; goto end; } diff --git a/src/plugins/ctf/common/src/metadata/tsdl/decoder.hpp b/src/plugins/ctf/common/src/metadata/tsdl/decoder.hpp index 7bb650ca..4460acae 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/decoder.hpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/decoder.hpp @@ -13,6 +13,8 @@ #include #include "common/uuid.h" +#include "cpp-common/bt2c/logging.hpp" +#include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */ /* CTF metadata decoder status */ enum ctf_metadata_decoder_status @@ -25,18 +27,43 @@ enum ctf_metadata_decoder_status CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR = -4, }; +inline const char *format_as(ctf_metadata_decoder_status status) noexcept +{ + switch (status) { + case CTF_METADATA_DECODER_STATUS_OK: + return "CTF_METADATA_DECODER_STATUS_OK"; + + case CTF_METADATA_DECODER_STATUS_NONE: + return "CTF_METADATA_DECODER_STATUS_NONE"; + + case CTF_METADATA_DECODER_STATUS_ERROR: + return "CTF_METADATA_DECODER_STATUS_ERROR"; + + case CTF_METADATA_DECODER_STATUS_INCOMPLETE: + return "CTF_METADATA_DECODER_STATUS_INCOMPLETE"; + + case CTF_METADATA_DECODER_STATUS_INVAL_VERSION: + return "CTF_METADATA_DECODER_STATUS_INVAL_VERSION"; + + case CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR: + return "CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR"; + } + + bt_common_abort(); +} + /* Decoding configuration */ struct ctf_metadata_decoder_config { - /* Active log level to use */ - bt_logging_level log_level = (bt_logging_level) 0; + explicit ctf_metadata_decoder_config(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/CTF/META/DECODER-CONFIG"} + { + } - /* - * Component or component class to use for logging (exactly one of - * them must be non-`NULL`); weak - */ + bt2c::Logger logger; + + /* Weak, used to create a bt_trace_class, if not nullptr. */ bt_self_component *self_comp = nullptr; - bt_self_component_class *self_comp_class = nullptr; /* Additional clock class offset to apply */ int64_t clock_class_offset_s = 0; @@ -114,12 +141,9 @@ ctf_metadata_decoder_borrow_ctf_trace_class(struct ctf_metadata_decoder *mdec); * packetized, setting `is_packetized` accordingly on success. On * success, also sets `*byte_order` to the byte order of the first * packet. - * - * This function uses `log_level` and `self_comp` for logging purposes. - * `self_comp` can be `NULL` if not available. */ int ctf_metadata_decoder_is_packetized(FILE *fp, bool *is_packetized, int *byte_order, - bt_logging_level log_level, bt_self_component *self_comp); + const bt2c::Logger& logger); /* * Returns the byte order of the decoder's metadata stream as set by the diff --git a/src/plugins/ctf/common/src/metadata/tsdl/lexer.lpp b/src/plugins/ctf/common/src/metadata/tsdl/lexer.lpp index 0f6070b5..826cca14 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/lexer.lpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/lexer.lpp @@ -7,30 +7,28 @@ * Common Trace Formal Lexer */ -#include -#include - -#define BT_LOG_OUTPUT_LEVEL ctf_plugin_metadata_log_level -#define BT_LOG_TAG "PLUGIN-CTF-METADATA-LEXER" +#include "plugins/ctf/common/src/metadata/tsdl/ast.hpp" #include "plugins/ctf/common/src/metadata/tsdl/logging.hpp" - -#include "plugins/ctf/common/src/metadata/tsdl/scanner.hpp" #include "plugins/ctf/common/src/metadata/tsdl/parser-wrap.hpp" -#include "plugins/ctf/common/src/metadata/tsdl/ast.hpp" +#include "plugins/ctf/common/src/metadata/tsdl/scanner.hpp" -#define YY_FATAL_ERROR(_msg) BT_LOGF_STR(_msg) +#define YY_FATAL_ERROR(_msg) BT_CPPLOGF_STR_SPEC(currentCtfScanner->logger, _msg) #define PARSE_INTEGER_LITERAL(base) \ do { \ errno = 0; \ yylval->ull = strtoull(yytext, NULL, base); \ if (errno) { \ - _BT_LOGE_APPEND_CAUSE_LINENO(yylineno, \ + _BT_CPPLOGE_APPEND_CAUSE_LINENO( \ + currentCtfScanner->logger, \ + yylineno, \ "Cannot parser constant integer: " \ - "base=%d, text=\"%s\"", base, yytext); \ + "base={}, text=\"{}\"", base, yytext); \ return CTF_ERROR; \ } \ } while (0) + +extern thread_local const ctf_scanner *const currentCtfScanner; %} %x comment_ml comment_sl string_lit char_const @@ -115,7 +113,7 @@ _Imaginary setstring(yyextra, yylval, yytext); return CTF_IMAGINARY; 0{OCTALDIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(8); return CTF_INTEGER_LITERAL; 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(16); return CTF_INTEGER_LITERAL; -{IDENTIFIER} BT_LOGT("Got identifier: id=\"%s\"", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER; +{IDENTIFIER} BT_CPPLOGT_SPEC(currentCtfScanner->logger, "Got identifier: id=\"{}\"", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER; [ \t\r\n] ; /* ignore */ -. _BT_LOGE_APPEND_CAUSE_LINENO(yylineno, "Invalid character: char=\"%c\", val=0x%02x", isprint((unsigned char) yytext[0]) ? yytext[0] : '\0', yytext[0]); return CTF_ERROR; +. _BT_CPPLOGE_APPEND_CAUSE_LINENO(currentCtfScanner->logger, yylineno, "Invalid character: char=\"{}\", val={:#02x}", isprint((unsigned char) yytext[0]) ? yytext[0] : '\0', yytext[0]); return CTF_ERROR; %% diff --git a/src/plugins/ctf/common/src/metadata/tsdl/logging.cpp b/src/plugins/ctf/common/src/metadata/tsdl/logging.cpp deleted file mode 100644 index 058a6b4b..00000000 --- a/src/plugins/ctf/common/src/metadata/tsdl/logging.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (c) 2017 Jérémie Galarneau - */ - -#define BT_LOG_OUTPUT_LEVEL ctf_plugin_metadata_log_level -#include "logging/log-api.h" - -BT_LOG_INIT_LOG_LEVEL(ctf_plugin_metadata_log_level, "BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL"); diff --git a/src/plugins/ctf/common/src/metadata/tsdl/logging.hpp b/src/plugins/ctf/common/src/metadata/tsdl/logging.hpp index 234a1d60..ee019a3c 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/logging.hpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/logging.hpp @@ -9,56 +9,18 @@ #include -#include "logging/comp-logging.h" -#include "logging/log.h" +#include "cpp-common/bt2c/logging.hpp" -/* - * This global log level is for the generated lexer and parser: we can't - * use a contextual log level for their "tracing", so they rely on this. - */ -BT_LOG_LEVEL_EXTERN_SYMBOL(ctf_plugin_metadata_log_level); - -/* - * To be used by functions without a context structure to pass all the - * logging configuration at once. - */ -struct meta_log_config -{ - bt_logging_level log_level; - - /* Weak, exactly one of these must be set */ - bt_self_component *self_comp; - bt_self_component_class *self_comp_class; -}; - -#define _BT_LOGT_LINENO(_lineno, _msg, args...) \ - BT_LOGT("At line %u in metadata stream: " _msg, _lineno, ##args) - -#define _BT_LOGW_LINENO(_lineno, _msg, args...) \ - BT_LOGW("At line %u in metadata stream: " _msg, _lineno, ##args) - -#define _BT_LOGE_APPEND_CAUSE_LINENO(_lineno, _msg, args...) \ - do { \ - BT_LOGE("At line %u in metadata stream: " _msg, _lineno, ##args); \ - (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN( \ - "CTF metadata parser", "At line %u in metadata stream: " _msg, _lineno, ##args); \ - } while (0) - -#define _BT_COMP_LOGT_LINENO(_lineno, _msg, args...) \ - BT_COMP_LOGT("At line %u in metadata stream: " _msg, _lineno, ##args) - -#define _BT_COMP_LOGW_LINENO(_lineno, _msg, args...) \ - BT_COMP_LOGW("At line %u in metadata stream: " _msg, _lineno, ##args) +#define _BT_CPPLOGT_LINENO(logger, _lineno, _msg, args...) \ + BT_CPPLOGT_SPEC((logger), "At line {} in metadata stream: " _msg, _lineno, ##args) -#define _BT_COMP_LOGE_LINENO(_lineno, _msg, args...) \ - BT_COMP_LOGE("At line %u in metadata stream: " _msg, _lineno, ##args) +#define _BT_CPPLOGW_LINENO(logger, _lineno, _msg, args...) \ + BT_CPPLOGW_SPEC((logger), "At line {} in metadata stream: " _msg, _lineno, ##args) -#define _BT_COMP_LOGE_APPEND_CAUSE_LINENO(_lineno, _msg, args...) \ - BT_COMP_LOGE_APPEND_CAUSE(BT_COMP_LOG_SELF_COMP, "At line %u in metadata stream: " _msg, \ - _lineno, ##args) +#define _BT_CPPLOGE_LINENO(logger, _lineno, _msg, args...) \ + BT_CPPLOGE_SPEC((logger), "At line {} in metadata stream: " _msg, _lineno, ##args) -#define _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(_msg, args...) \ - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(BT_COMP_LOG_SELF_COMP, BT_COMP_LOG_SELF_COMP_CLASS, \ - _msg, ##args) +#define _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, _lineno, _msg, args...) \ + BT_CPPLOGE_APPEND_CAUSE_SPEC((logger), "At line {} in metadata stream: " _msg, _lineno, ##args) #endif /* CTF_METADATA_LOGGING_H */ diff --git a/src/plugins/ctf/common/src/metadata/tsdl/objstack.cpp b/src/plugins/ctf/common/src/metadata/tsdl/objstack.cpp index bdf31e02..cb13f63b 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/objstack.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/objstack.cpp @@ -6,14 +6,9 @@ * Common Trace Format Object Stack. */ -#include - -#define BT_LOG_OUTPUT_LEVEL ctf_plugin_metadata_log_level -#define BT_LOG_TAG "PLUGIN/CTF/META/OBJSTACK" -#include "logging.hpp" - #include "common/align.h" #include "common/list.h" +#include "cpp-common/bt2c/logging.hpp" #include "objstack.hpp" @@ -23,7 +18,15 @@ struct objstack { - struct bt_list_head head; /* list of struct objstack_node */ + explicit objstack(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/CTF/META/OBJSTACK"} + { + } + + /* list of struct objstack_node */ + bt_list_head head {}; + + bt2c::Logger logger; }; struct objstack_node @@ -34,20 +37,16 @@ struct objstack_node char __attribute__((aligned(OBJSTACK_ALIGN))) data[]; }; -struct objstack *objstack_create(void) +objstack *objstack_create(const bt2c::Logger& parentLogger) { struct objstack *objstack; struct objstack_node *node; - objstack = (struct objstack *) calloc(1, sizeof(*objstack)); - if (!objstack) { - BT_LOGE_STR("Failed to allocate one object stack."); - return NULL; - } + objstack = new ::objstack {parentLogger}; node = (objstack_node *) calloc(sizeof(struct objstack_node) + OBJSTACK_INIT_LEN, sizeof(char)); if (!node) { - BT_LOGE_STR("Failed to allocate one object stack node."); - free(objstack); + BT_CPPLOGE_STR_SPEC(objstack->logger, "Failed to allocate one object stack node."); + delete objstack; return NULL; } BT_INIT_LIST_HEAD(&objstack->head); @@ -80,7 +79,8 @@ void objstack_destroy(struct objstack *objstack) bt_list_del(&node->node); objstack_node_free(node); } - free(objstack); + + delete objstack; } static struct objstack_node *objstack_append_node(struct objstack *objstack) @@ -94,7 +94,7 @@ static struct objstack_node *objstack_append_node(struct objstack *objstack) new_node = (objstack_node *) calloc(sizeof(struct objstack_node) + (last_node->len << 1), sizeof(char)); if (!new_node) { - BT_LOGE_STR("Failed to allocate one object stack node."); + BT_CPPLOGE_STR_SPEC(objstack->logger, "Failed to allocate one object stack node."); return NULL; } bt_list_add_tail(&new_node->node, &objstack->head); diff --git a/src/plugins/ctf/common/src/metadata/tsdl/objstack.hpp b/src/plugins/ctf/common/src/metadata/tsdl/objstack.hpp index 2c91e140..cc17d433 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/objstack.hpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/objstack.hpp @@ -11,7 +11,13 @@ #include -struct objstack *objstack_create(void); +namespace bt2c { + +class Logger; + +} /* namespace bt2c */ + +struct objstack *objstack_create(const bt2c::Logger& parentLogger); void objstack_destroy(struct objstack *objstack); /* diff --git a/src/plugins/ctf/common/src/metadata/tsdl/parser-wrap.hpp b/src/plugins/ctf/common/src/metadata/tsdl/parser-wrap.hpp index 7b6b580b..bfc0e907 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/parser-wrap.hpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/parser-wrap.hpp @@ -12,11 +12,10 @@ * YYDEBUG (and therefore the yydebug declaration). */ -#include "logging/log.h" +#include "logging/log-api.h" #if BT_LOG_ENABLED_TRACE -# define YYDEBUG 1 -# define YYFPRINTF(_stream, _fmt, args...) BT_LOGT(_fmt, ##args) +# define YYDEBUG 1 #else # define YYDEBUG 0 #endif diff --git a/src/plugins/ctf/common/src/metadata/tsdl/parser.ypp b/src/plugins/ctf/common/src/metadata/tsdl/parser.ypp index b0583695..7ae25b69 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/parser.ypp +++ b/src/plugins/ctf/common/src/metadata/tsdl/parser.ypp @@ -7,18 +7,6 @@ * Common Trace Format Metadata Grammar. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BT_LOG_OUTPUT_LEVEL ctf_plugin_metadata_log_level -#define BT_LOG_TAG "PLUGIN/CTF/META/PARSER" #include "plugins/ctf/common/src/metadata/tsdl/logging.hpp" #include "common/list.h" @@ -35,6 +23,17 @@ */ BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE +thread_local const ctf_scanner *currentCtfScanner; + +#define YYFPRINTF(_stream, _fmt, args...) \ + do { \ + int size = snprintf(NULL, 0, (_fmt), ##args); \ + std::string str(size, '\0'); \ + int written = snprintf(&str[0], size + 1, (_fmt), ##args); \ + BT_ASSERT(size == written); \ + BT_CPPLOGT_STR_SPEC(currentCtfScanner->logger, str.c_str()); \ + } while (0) + /* Join two lists, put "add" at the end of "head". */ static inline void _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head) @@ -268,9 +267,10 @@ int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, lvalp->s = (char *) objstack_alloc(scanner->objstack, len); if (src[0] == 'L') { // TODO: import wide string - _BT_LOGE_APPEND_CAUSE_LINENO(yyget_lineno(scanner), + _BT_CPPLOGE_APPEND_CAUSE_LINENO(currentCtfScanner->logger, + yyget_lineno(scanner), "wide characters are not supported as of this version: " - "scanner-addr=%p", scanner); + "scanner-addr={}", fmt::ptr(scanner)); return -1; } else { return import_basic_string(scanner, lvalp, len, src, delim); @@ -294,7 +294,8 @@ static void push_scope(struct ctf_scanner *scanner) { struct ctf_scanner_scope *ns; - BT_LOGT("Pushing scope: scanner-addr=%p", scanner); + BT_CPPLOGT_SPEC(currentCtfScanner->logger, + "Pushing scope: scanner-addr={}", fmt::ptr(scanner)); ns = (ctf_scanner_scope *) malloc(sizeof(struct ctf_scanner_scope)); init_scope(ns, scanner->cs); scanner->cs = ns; @@ -304,7 +305,8 @@ static void pop_scope(struct ctf_scanner *scanner) { struct ctf_scanner_scope *os; - BT_LOGT("Popping scope: scanner-addr=%p", scanner); + BT_CPPLOGT_SPEC(currentCtfScanner->logger, + "Popping scope: scanner-addr={}", fmt::ptr(scanner)); os = scanner->cs; scanner->cs = os->parent; finalize_scope(os); @@ -316,8 +318,9 @@ static int lookup_type(struct ctf_scanner_scope *s, const char *id) int ret; ret = GPOINTER_TO_INT(g_hash_table_lookup(s->classes, id)); - BT_LOGT("Looked up type: scanner-addr=%p, id=\"%s\", ret=%d", - s, id, ret); + BT_CPPLOGT_SPEC(currentCtfScanner->logger, + "Looked up type: scanner-addr={}, id=\"{}\", ret={}", + fmt::ptr(s), id, ret); return ret; } @@ -332,15 +335,17 @@ int is_type(struct ctf_scanner *scanner, const char *id) break; } } - BT_LOGT("Found if ID is type: scanner-addr=%p, id=\"%s\", ret=%d", - scanner, id, ret); + BT_CPPLOGT_SPEC(currentCtfScanner->logger, + "Found if ID is type: scanner-addr={}, id=\"{}\", ret={}", + fmt::ptr(scanner), id, ret); return ret; } static void add_type(struct ctf_scanner *scanner, char *id) { - BT_LOGT("Adding type: scanner-addr=%p, id=\"%s\"", - scanner, id); + BT_CPPLOGT_SPEC(currentCtfScanner->logger, + "Adding type: scanner-addr={}, id=\"{}\"", fmt::ptr(scanner), + id); if (lookup_type(scanner->cs, id)) return; g_hash_table_insert(scanner->cs->classes, id, id); @@ -353,9 +358,10 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner, node = (ctf_node *) objstack_alloc(scanner->objstack, sizeof(*node)); if (!node) { - _BT_LOGE_APPEND_CAUSE_LINENO(yyget_lineno(scanner->scanner), + _BT_CPPLOGE_APPEND_CAUSE_LINENO(currentCtfScanner->logger, + yyget_lineno(scanner->scanner), "failed to allocate one stack entry: " - "scanner-addr=%p", scanner); + "scanner-addr={}", fmt::ptr(scanner)); return &error_node; } node->type = type; @@ -366,8 +372,8 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner, switch (type) { case NODE_ROOT: node->type = NODE_ERROR; - BT_LOGE("Trying to create root node: scanner-addr=%p", - scanner); + BT_CPPLOGE_SPEC(currentCtfScanner->logger, "Trying to create root node: scanner-addr={}", + fmt::ptr(scanner)); break; case NODE_EVENT: BT_INIT_LIST_HEAD(&node->u.event.declaration_list); @@ -442,8 +448,8 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner, case NODE_UNKNOWN: default: node->type = NODE_ERROR; - BT_LOGE("Unknown node type: scanner-addr=%p, node-type=%d", - scanner, type); + BT_CPPLOGE_SPEC(currentCtfScanner->logger, "Unknown node type: scanner-addr={}, node-type={}", + fmt::ptr(scanner), type); break; } @@ -502,7 +508,7 @@ static int reparent_ctf_expression(struct ctf_node *node, case NODE_UNKNOWN: default: - BT_LOGE("Unknown node type: node-type=%d", parent->type); + BT_CPPLOGE_SPEC(currentCtfScanner->logger, "Unknown node type: node-type={}", parent->type); return -EINVAL; } return 0; @@ -559,7 +565,7 @@ static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent) case NODE_UNKNOWN: default: - BT_LOGE("Unknown node type: node-type=%d", parent->type); + BT_CPPLOGE_SPEC(currentCtfScanner->logger, "Unknown node type: node-type={}", parent->type); return -EINVAL; } return 0; @@ -616,7 +622,7 @@ static int reparent_field_class_alias(struct ctf_node *node, struct ctf_node *pa case NODE_UNKNOWN: default: - BT_LOGE("Unknown node type: node-type=%d", parent->type); + BT_CPPLOGE_SPEC(currentCtfScanner->logger, "Unknown node type: node-type={}", parent->type); return -EINVAL; } return 0; @@ -657,7 +663,7 @@ static int reparent_field_class_specifier(struct ctf_node *node, case NODE_UNKNOWN: default: - BT_LOGE("Unknown node type: node-type=%d", parent->type); + BT_CPPLOGE_SPEC(currentCtfScanner->logger, "Unknown node type: node-type={}", parent->type); return -EINVAL; } return 0; @@ -723,7 +729,7 @@ static int reparent_field_class_specifier_list(struct ctf_node *node, case NODE_UNKNOWN: default: - BT_LOGE("Unknown node type: node-type=%d", parent->type); + BT_CPPLOGE_SPEC(currentCtfScanner->logger, "Unknown node type: node-type={}", parent->type); return -EINVAL; } return 0; @@ -774,7 +780,7 @@ static int reparent_field_class_declarator(struct ctf_node *node, case NODE_UNKNOWN: default: - BT_LOGE("Unknown node type: node-type=%d", parent->type); + BT_CPPLOGE_SPEC(currentCtfScanner->logger, "Unknown node type: node-type={}", parent->type); return -EINVAL; } return 0; @@ -797,7 +803,8 @@ static int set_parent_node(struct ctf_node *node, switch (node->type) { case NODE_ROOT: - BT_LOGE_STR("Trying to reparent root node."); + BT_CPPLOGE_STR_SPEC(currentCtfScanner->logger, + "Trying to reparent root node."); return -EINVAL; case NODE_EVENT: @@ -914,7 +921,7 @@ static int set_parent_node(struct ctf_node *node, case NODE_UNKNOWN: default: - BT_LOGE("Unknown node type: node-type=%d", parent->type); + BT_CPPLOGE_SPEC(currentCtfScanner->logger, "Unknown node type: node-type={}", parent->type); return -EINVAL; } return 0; @@ -923,8 +930,9 @@ static int set_parent_node(struct ctf_node *node, static void yyerror(struct ctf_scanner *scanner, yyscan_t yyscanner, const char *str) { - _BT_LOGE_APPEND_CAUSE_LINENO(yyget_lineno(scanner->scanner), - "%s: token=\"%s\"", str, yyget_text(scanner->scanner)); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(currentCtfScanner->logger, + yyget_lineno(scanner->scanner), + "{}: token=\"{}\"", str, yyget_text(scanner->scanner)); } #define reparent_error(scanner, str) \ @@ -955,25 +963,26 @@ static struct ctf_ast *ctf_ast_alloc(struct ctf_scanner *scanner) int ctf_scanner_append_ast(struct ctf_scanner *scanner, FILE *input) { /* Start processing new stream */ + struct ClearCurrentCtfScanner { + ~ClearCurrentCtfScanner() { + currentCtfScanner = nullptr; + } + } clearMoiLa; + + currentCtfScanner = scanner; yyrestart(input, scanner->scanner); return yyparse(scanner, scanner->scanner); } -struct ctf_scanner *ctf_scanner_alloc(void) +struct ctf_scanner *ctf_scanner_alloc(const bt2c::Logger &parentLogger) { - struct ctf_scanner *scanner; - int ret; - - scanner = (ctf_scanner *) malloc(sizeof(*scanner)); - if (!scanner) - return NULL; - memset(scanner, 0, sizeof(*scanner)); - ret = yylex_init_extra(scanner, &scanner->scanner); + ctf_scanner *scanner = new ctf_scanner {parentLogger}; + int ret = yylex_init_extra(scanner, &scanner->scanner); if (ret) { - BT_LOGE("yylex_init_extra() failed: ret=%d", ret); + BT_CPPLOGE_SPEC(scanner->logger, "yylex_init_extra() failed: ret={}", ret); goto cleanup_scanner; } - scanner->objstack = objstack_create(); + scanner->objstack = objstack_create(scanner->logger); if (!scanner->objstack) goto cleanup_lexer; scanner->ast = ctf_ast_alloc(scanner); @@ -989,10 +998,10 @@ cleanup_objstack: cleanup_lexer: ret = yylex_destroy(scanner->scanner); if (!ret) - BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d", - scanner, ret); + BT_CPPLOGE_SPEC(scanner->logger, "yylex_destroy() failed: scanner-addr={}, ret={}", + fmt::ptr(scanner), ret); cleanup_scanner: - free(scanner); + delete scanner; return NULL; } @@ -1023,9 +1032,9 @@ void ctf_scanner_free(struct ctf_scanner *scanner) objstack_destroy(scanner->objstack); ret = yylex_destroy(scanner->scanner); if (ret) - BT_LOGE("yylex_destroy() failed: scanner-addr=%p, ret=%d", - scanner, ret); - free(scanner); + BT_CPPLOGE_SPEC(currentCtfScanner->logger, "yylex_destroy() failed: scanner-addr={}, ret={}", + fmt::ptr(scanner), ret); + delete scanner; } /* diff --git a/src/plugins/ctf/common/src/metadata/tsdl/scanner.hpp b/src/plugins/ctf/common/src/metadata/tsdl/scanner.hpp index dd16e977..4f2a1f86 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/scanner.hpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/scanner.hpp @@ -25,14 +25,20 @@ struct ctf_scanner_scope struct ctf_scanner { - yyscan_t scanner; - struct ctf_ast *ast; - struct ctf_scanner_scope root_scope; - struct ctf_scanner_scope *cs; - struct objstack *objstack; + explicit ctf_scanner(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/CTF/META/PARSER"} + { + } + + bt2c::Logger logger; + yyscan_t scanner {}; + ctf_ast *ast = nullptr; + ctf_scanner_scope root_scope {}; + ctf_scanner_scope *cs = nullptr; + struct objstack *objstack = nullptr; }; -struct ctf_scanner *ctf_scanner_alloc(void); +struct ctf_scanner *ctf_scanner_alloc(const bt2c::Logger& parentLogger); void ctf_scanner_free(struct ctf_scanner *scanner); diff --git a/src/plugins/ctf/common/src/metadata/tsdl/visitor-generate-ir.cpp b/src/plugins/ctf/common/src/metadata/tsdl/visitor-generate-ir.cpp index 6155641d..ac04a7fa 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/visitor-generate-ir.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/visitor-generate-ir.cpp @@ -7,32 +7,19 @@ * Common Trace Format metadata visitor (generates CTF IR objects). */ -#include - -#include -#include -#include #include #include -#include - -#define BT_COMP_LOG_SELF_COMP (ctx->log_cfg.self_comp) -#define BT_COMP_LOG_SELF_COMP_CLASS (ctx->log_cfg.self_comp_class) -#define BT_LOG_OUTPUT_LEVEL (ctx->log_cfg.log_level) -#define BT_LOG_TAG "PLUGIN/CTF/META/IR-VISITOR" #include "logging.hpp" -#include "logging/comp-logging.h" #include "common/assert.h" #include "common/common.h" #include "common/uuid.h" #include "compat/endian.h" /* IWYU pragma: keep */ +#include "cpp-common/bt2c/logging.hpp" #include "ast.hpp" #include "ctf-meta-visitors.hpp" -#include "ctf-meta.hpp" -#include "decoder.hpp" /* Bit value (left shift) */ #define _BV(_val) (1 << (_val)) @@ -48,7 +35,7 @@ do { \ ret = ctx_push_scope(ctx); \ if (ret) { \ - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot push scope."); \ + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "Cannot push scope."); \ goto error; \ } \ } while (0) @@ -147,18 +134,21 @@ enum loglevel /* First entry in a BT list */ #define _BT_LIST_FIRST_ENTRY(_ptr, _class, _member) bt_list_entry((_ptr)->next, _class, _member) -#define _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(_node, _attr, _entity) \ - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( \ - (_node)->lineno, "Duplicate attribute in %s: attr-name=\"%s\"", _entity, _attr) +#define _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(_node, _attr, _entity) \ + _BT_CPPLOGE_APPEND_CAUSE_LINENO(ctx->logger, (_node)->lineno, \ + "Duplicate attribute in {}: attr-name=\"{}\"", _entity, _attr) -#define _BT_COMP_LOGE_NODE(_node, _msg, args...) _BT_COMP_LOGE_LINENO((_node)->lineno, _msg, ##args) +#define _BT_CPPLOGE_NODE(_node, _msg, args...) \ + _BT_CPPLOGE_LINENO(ctx->logger, (_node)->lineno, _msg, ##args) -#define _BT_COMP_LOGE_APPEND_CAUSE_NODE(_node, _msg, args...) \ - _BT_COMP_LOGE_APPEND_CAUSE_LINENO((_node)->lineno, _msg, ##args) +#define _BT_CPPLOGE_APPEND_CAUSE_NODE(_node, _msg, args...) \ + _BT_CPPLOGE_APPEND_CAUSE_LINENO(ctx->logger, (_node)->lineno, _msg, ##args) -#define _BT_COMP_LOGW_NODE(_node, _msg, args...) _BT_COMP_LOGW_LINENO((_node)->lineno, _msg, ##args) +#define _BT_CPPLOGW_NODE(_node, _msg, args...) \ + _BT_CPPLOGW_LINENO(ctx->logger, (_node)->lineno, _msg, ##args) -#define _BT_COMP_LOGT_NODE(_node, _msg, args...) _BT_COMP_LOGT_LINENO((_node)->lineno, _msg, ##args) +#define _BT_CPPLOGT_NODE(_node, _msg, args...) \ + _BT_CPPLOGT_LINENO(ctx->logger, (_node)->lineno, _msg, ##args) /* * Declaration scope of a visitor context. This represents a TSDL @@ -183,7 +173,12 @@ struct ctx_decl_scope */ struct ctf_visitor_generate_ir { - struct meta_log_config log_cfg; + explicit ctf_visitor_generate_ir(ctf_metadata_decoder_config decoderConfig, + bt2c::Logger loggerParam) : + decoder_config {std::move(decoderConfig)}, + logger {std::move(loggerParam)} + { + } /* Trace IR trace class being filled (owned by this) */ bt_trace_class *trace_class = nullptr; @@ -202,6 +197,8 @@ struct ctf_visitor_generate_ir /* Config passed by the user */ struct ctf_metadata_decoder_config decoder_config; + + bt2c::Logger logger; }; /* @@ -222,7 +219,7 @@ static struct ctx_decl_scope *ctx_decl_scope_create(struct ctf_visitor_generate_ scope = g_new(struct ctx_decl_scope, 1); if (!scope) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Failed to allocate one declaration scope."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "Failed to allocate one declaration scope."); goto end; } @@ -525,37 +522,33 @@ end: * @returns New visitor context, or NULL on error */ static struct ctf_visitor_generate_ir * -ctx_create(const struct ctf_metadata_decoder_config *decoder_config) +ctx_create(const struct ctf_metadata_decoder_config *decoder_config, const bt2c::Logger& logger) { BT_ASSERT(decoder_config); - ctf_visitor_generate_ir *ctx = new ctf_visitor_generate_ir; - ctx->log_cfg.log_level = decoder_config->log_level; - ctx->log_cfg.self_comp = decoder_config->self_comp; - ctx->log_cfg.self_comp_class = decoder_config->self_comp_class; + ctf_visitor_generate_ir *ctx = new ctf_visitor_generate_ir {*decoder_config, logger}; if (decoder_config->self_comp) { ctx->trace_class = bt_trace_class_create(decoder_config->self_comp); if (!ctx->trace_class) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot create empty trace class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "Cannot create empty trace class."); goto error; } } ctx->ctf_tc = ctf_trace_class_create(); if (!ctx->ctf_tc) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot create CTF trace class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "Cannot create CTF trace class."); goto error; } /* Root declaration scope */ ctx->current_scope = ctx_decl_scope_create(ctx, NULL); if (!ctx->current_scope) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot create declaration scope."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "Cannot create declaration scope."); goto error; } - ctx->decoder_config = *decoder_config; goto end; error: @@ -581,7 +574,7 @@ static int ctx_push_scope(struct ctf_visitor_generate_ir *ctx) BT_ASSERT(ctx); new_scope = ctx_decl_scope_create(ctx, ctx->current_scope); if (!new_scope) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot create declaration scope."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "Cannot create declaration scope."); ret = -ENOMEM; goto end; } @@ -727,7 +720,7 @@ static int get_unary_unsigned(struct ctf_visitor_generate_ir *ctx, struct bt_lis int cond = node->type != NODE_UNARY_EXPRESSION || uexpr_type != UNARY_UNSIGNED_CONSTANT || uexpr_link != UNARY_LINK_UNKNOWN || i != 0; if (cond) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Invalid constant unsigned integer."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Invalid constant unsigned integer."); ret = -EINVAL; goto end; } @@ -797,7 +790,7 @@ end: static int get_unary_uuid(struct ctf_visitor_generate_ir *ctx, struct bt_list_head *head, bt_uuid_t uuid) { - return ctf_ast_get_unary_uuid(head, uuid, ctx->log_cfg.log_level, ctx->log_cfg.self_comp); + return ctf_ast_get_unary_uuid(head, uuid, ctx->logger); } static int get_boolean(struct ctf_visitor_generate_ir *ctx, struct ctf_node *unary_expr) @@ -805,8 +798,8 @@ static int get_boolean(struct ctf_visitor_generate_ir *ctx, struct ctf_node *una int ret = 0; if (unary_expr->type != NODE_UNARY_EXPRESSION) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(unary_expr, "Expecting unary expression: node-type=%d", - unary_expr->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(unary_expr, "Expecting unary expression: node-type={}", + unary_expr->type); ret = -EINVAL; goto end; } @@ -827,17 +820,16 @@ static int get_boolean(struct ctf_visitor_generate_ir *ctx, struct ctf_node *una } else if (strcmp(str, "false") == 0 || strcmp(str, "FALSE") == 0) { ret = FALSE; } else { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(unary_expr, "Unexpected boolean value: value=\"%s\"", - str); + _BT_CPPLOGE_APPEND_CAUSE_NODE(unary_expr, "Unexpected boolean value: value=\"{}\"", + str); ret = -EINVAL; goto end; } break; } default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE(unary_expr, - "Unexpected unary expression type: node-type=%d", - unary_expr->u.unary_expression.type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(unary_expr, "Unexpected unary expression type: node-type={}", + unary_expr->u.unary_expression.type); ret = -EINVAL; goto end; } @@ -853,7 +845,7 @@ static enum ctf_byte_order byte_order_from_unary_expr(struct ctf_visitor_generat enum ctf_byte_order bo = CTF_BYTE_ORDER_UNKNOWN; if (unary_expr->u.unary_expression.type != UNARY_STRING) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( unary_expr, "\"byte_order\" attribute: expecting `be`, `le`, `network`, or `native`."); goto end; } @@ -867,11 +859,10 @@ static enum ctf_byte_order byte_order_from_unary_expr(struct ctf_visitor_generat } else if (strcmp(str, "native") == 0) { bo = CTF_BYTE_ORDER_DEFAULT; } else { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - unary_expr, - "Unexpected \"byte_order\" attribute value: " - "expecting `be`, `le`, `network`, or `native`: value=\"%s\"", - str); + _BT_CPPLOGE_APPEND_CAUSE_NODE(unary_expr, + "Unexpected \"byte_order\" attribute value: " + "expecting `be`, `le`, `network`, or `native`: value=\"{}\"", + str); goto end; } @@ -902,8 +893,8 @@ static int get_class_specifier_name(struct ctf_visitor_generate_ir *ctx, int ret = 0; if (cls_specifier->type != NODE_TYPE_SPECIFIER) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(cls_specifier, "Unexpected node type: node-type=%d", - cls_specifier->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(cls_specifier, "Unexpected node type: node-type={}", + cls_specifier->type); ret = -EINVAL; goto end; } @@ -958,7 +949,7 @@ static int get_class_specifier_name(struct ctf_visitor_generate_ir *ctx, struct ctf_node *node = cls_specifier->u.field_class_specifier.node; if (!node->u._struct.name) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Unexpected empty structure field class name."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Unexpected empty structure field class name."); ret = -EINVAL; goto end; } @@ -972,7 +963,7 @@ static int get_class_specifier_name(struct ctf_visitor_generate_ir *ctx, struct ctf_node *node = cls_specifier->u.field_class_specifier.node; if (!node->u.variant.name) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Unexpected empty variant field class name."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Unexpected empty variant field class name."); ret = -EINVAL; goto end; } @@ -986,7 +977,7 @@ static int get_class_specifier_name(struct ctf_visitor_generate_ir *ctx, struct ctf_node *node = cls_specifier->u.field_class_specifier.node; if (!node->u._enum.enum_id) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Unexpected empty enumeration field class (`enum`) name."); ret = -EINVAL; goto end; @@ -1000,9 +991,9 @@ static int get_class_specifier_name(struct ctf_visitor_generate_ir *ctx, case TYPESPEC_INTEGER: case TYPESPEC_STRING: default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE(cls_specifier->u.field_class_specifier.node, - "Unexpected field class specifier type: %d", - cls_specifier->u.field_class_specifier.type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(cls_specifier->u.field_class_specifier.node, + "Unexpected field class specifier type: {}", + cls_specifier->u.field_class_specifier.type); ret = -EINVAL; goto end; } @@ -1086,8 +1077,8 @@ static int visit_field_class_declarator(struct ctf_visitor_generate_ir *ctx, /* Validate field class declarator node */ if (node_field_class_declarator) { if (node_field_class_declarator->u.field_class_declarator.type == TYPEDEC_UNKNOWN) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - node_field_class_declarator, "Unexpected field class declarator type: type=%d", + _BT_CPPLOGE_APPEND_CAUSE_NODE( + node_field_class_declarator, "Unexpected field class declarator type: type={}", node_field_class_declarator->u.field_class_declarator.type); ret = -EINVAL; goto error; @@ -1095,8 +1086,8 @@ static int visit_field_class_declarator(struct ctf_visitor_generate_ir *ctx, /* TODO: GCC bitfields not supported yet */ if (node_field_class_declarator->u.field_class_declarator.bitfield_len != NULL) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node_field_class_declarator, - "GCC bitfields are not supported as of this version."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node_field_class_declarator, + "GCC bitfields are not supported as of this version."); ret = -EPERM; goto error; } @@ -1118,9 +1109,9 @@ static int visit_field_class_declarator(struct ctf_visitor_generate_ir *ctx, nested_decl = ctx_decl_scope_lookup_alias(ctx->current_scope, g_quark_to_string(qalias), -1, true); if (!nested_decl) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node_field_class_declarator, - "Cannot find class alias: name=\"%s\"", - g_quark_to_string(qalias)); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node_field_class_declarator, + "Cannot find class alias: name=\"{}\"", + g_quark_to_string(qalias)); ret = -EINVAL; goto error; } @@ -1169,16 +1160,15 @@ static int visit_field_class_declarator(struct ctf_visitor_generate_ir *ctx, /* Create array/sequence, pass nested_decl as child */ if (bt_list_empty(length)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node_field_class_declarator, - "Expecting length field reference or value."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node_field_class_declarator, + "Expecting length field reference or value."); ret = -EINVAL; goto error; } first = _BT_LIST_FIRST_ENTRY(length, struct ctf_node, siblings); if (first->type != NODE_UNARY_EXPRESSION) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(first, "Unexpected node type: node-type=%d", - first->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(first, "Unexpected node type: node-type={}", first->type); ret = -EINVAL; goto error; } @@ -1203,8 +1193,8 @@ static int visit_field_class_declarator(struct ctf_visitor_generate_ir *ctx, char *length_name = ctf_ast_concatenate_unary_strings(length); if (!length_name) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node_field_class_declarator, - "Cannot concatenate unary strings."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node_field_class_declarator, + "Cannot concatenate unary strings."); ret = -EINVAL; goto error; } @@ -1217,30 +1207,30 @@ static int visit_field_class_declarator(struct ctf_visitor_generate_ir *ctx, struct ctf_field_class_array *array_decl; if (!env_entry) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node_field_class_declarator, - "Cannot find environment entry: " - "name=\"%s\"", - env_entry_name); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node_field_class_declarator, + "Cannot find environment entry: " + "name=\"{}\"", + env_entry_name); ret = -EINVAL; goto error; } if (env_entry->type != CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node_field_class_declarator, - "Wrong environment entry type " - "(expecting integer): " - "name=\"%s\"", - env_entry_name); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node_field_class_declarator, + "Wrong environment entry type " + "(expecting integer): " + "name=\"{}\"", + env_entry_name); ret = -EINVAL; goto error; } if (env_entry->value.i < 0) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node_field_class_declarator, - "Invalid, negative array length: " - "env-entry-name=\"%s\", " - "value=%" PRId64, - env_entry_name, env_entry->value.i); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node_field_class_declarator, + "Invalid, negative array length: " + "env-entry-name=\"{}\", " + "value={}", + env_entry_name, env_entry->value.i); ret = -EINVAL; goto error; } @@ -1330,8 +1320,8 @@ static int visit_struct_decl_field(struct ctf_visitor_generate_ir *ctx, NULL); if (ret) { BT_ASSERT(!field_decl); - _BT_COMP_LOGE_APPEND_CAUSE_NODE(cls_specifier_list, - "Cannot visit field class declarator: ret=%d", ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(cls_specifier_list, + "Cannot visit field class declarator: ret={}", ret); goto error; } @@ -1340,10 +1330,10 @@ static int visit_struct_decl_field(struct ctf_visitor_generate_ir *ctx, /* Check if field with same name already exists */ if (ctf_field_class_struct_borrow_member_by_name(struct_decl, field_name)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(cls_specifier_list, - "Duplicate field in structure field class: " - "field-name=\"%s\"", - field_name); + _BT_CPPLOGE_APPEND_CAUSE_NODE(cls_specifier_list, + "Duplicate field in structure field class: " + "field-name=\"{}\"", + field_name); ret = -EINVAL; goto error; } @@ -1379,8 +1369,8 @@ static int visit_variant_decl_field(struct ctf_visitor_generate_ir *ctx, NULL); if (ret) { BT_ASSERT(!field_decl); - _BT_COMP_LOGE_APPEND_CAUSE_NODE(cls_specifier_list, - "Cannot visit field class declarator: ret=%d", ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(cls_specifier_list, + "Cannot visit field class declarator: ret={}", ret); goto error; } @@ -1389,10 +1379,10 @@ static int visit_variant_decl_field(struct ctf_visitor_generate_ir *ctx, /* Check if field with same name already exists */ if (ctf_field_class_variant_borrow_option_by_name(variant_decl, field_name)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(cls_specifier_list, - "Duplicate field in variant field class: " - "field-name=\"%s\"", - field_name); + _BT_CPPLOGE_APPEND_CAUSE_NODE(cls_specifier_list, + "Duplicate field in variant field class: " + "field-name=\"{}\"", + field_name); ret = -EINVAL; goto error; } @@ -1423,8 +1413,7 @@ static int visit_field_class_def(struct ctf_visitor_generate_ir *ctx, ret = visit_field_class_declarator(ctx, cls_specifier_list, &qidentifier, iter, &class_decl, NULL); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, "Cannot visit field class declarator: ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, "Cannot visit field class declarator: ret={}", ret); ret = -EINVAL; goto end; } @@ -1434,7 +1423,7 @@ static int visit_field_class_def(struct ctf_visitor_generate_ir *ctx, struct ctf_field_class_variant *var_fc = ctf_field_class_as_variant(class_decl); if (var_fc->tag_path.path->len == 0) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( iter, "Type definition of untagged variant field class is not allowed."); ret = -EPERM; goto end; @@ -1444,8 +1433,8 @@ static int visit_field_class_def(struct ctf_visitor_generate_ir *ctx, ret = ctx_decl_scope_register_alias(ctx->current_scope, g_quark_to_string(qidentifier), class_decl); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, "Cannot register field class alias: name=\"%s\"", - g_quark_to_string(qidentifier)); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, "Cannot register field class alias: name=\"{}\"", + g_quark_to_string(qidentifier)); goto end; } } @@ -1478,7 +1467,7 @@ static int visit_field_class_alias(struct ctf_visitor_generate_ir *ctx, struct c node, &class_decl, NULL); if (ret) { BT_ASSERT(!class_decl); - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Cannot visit field class declarator: ret=%d", ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Cannot visit field class declarator: ret={}", ret); goto end; } @@ -1487,7 +1476,7 @@ static int visit_field_class_alias(struct ctf_visitor_generate_ir *ctx, struct c struct ctf_field_class_variant *var_fc = ctf_field_class_as_variant(class_decl); if (var_fc->tag_path.path->len == 0) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( target, "Type definition of untagged variant field class is not allowed."); ret = -EPERM; goto end; @@ -1499,8 +1488,8 @@ static int visit_field_class_alias(struct ctf_visitor_generate_ir *ctx, struct c * abstract or not (if it has an identifier). Check it here. */ if (qdummy_field_name != 0) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(target, "Expecting empty identifier: id=\"%s\"", - g_quark_to_string(qdummy_field_name)); + _BT_CPPLOGE_APPEND_CAUSE_NODE(target, "Expecting empty identifier: id=\"{}\"", + g_quark_to_string(qdummy_field_name)); ret = -EINVAL; goto end; } @@ -1512,8 +1501,8 @@ static int visit_field_class_alias(struct ctf_visitor_generate_ir *ctx, struct c ctx, alias->u.field_class_alias_name.field_class_specifier_list, node); ret = ctx_decl_scope_register_alias(ctx->current_scope, g_quark_to_string(qalias), class_decl); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Cannot register class alias: name=\"%s\"", - g_quark_to_string(qalias)); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Cannot register class alias: name=\"{}\"", + g_quark_to_string(qalias)); goto end; } @@ -1533,8 +1522,8 @@ static int visit_struct_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c ret = visit_field_class_def(ctx, entry_node->u.field_class_def.field_class_specifier_list, &entry_node->u.field_class_def.field_class_declarators); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - entry_node, "Cannot add field class found in structure field class: ret=%d", ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE( + entry_node, "Cannot add field class found in structure field class: ret={}", ret); goto end; } break; @@ -1542,8 +1531,8 @@ static int visit_struct_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c ret = visit_field_class_alias(ctx, entry_node->u.field_class_alias.target, entry_node->u.field_class_alias.alias); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - entry_node, "Cannot add field class alias found in structure field class: ret=%d", + _BT_CPPLOGE_APPEND_CAUSE_NODE( + entry_node, "Cannot add field class alias found in structure field class: ret={}", ret); goto end; } @@ -1559,8 +1548,8 @@ static int visit_struct_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c } break; default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, "Unexpected node type: node-type=%d", - entry_node->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, "Unexpected node type: node-type={}", + entry_node->type); ret = -EINVAL; goto end; } @@ -1580,8 +1569,8 @@ static int visit_variant_decl_entry(struct ctf_visitor_generate_ir *ctx, ret = visit_field_class_def(ctx, entry_node->u.field_class_def.field_class_specifier_list, &entry_node->u.field_class_def.field_class_declarators); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - entry_node, "Cannot add field class found in variant field class: ret=%d", ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE( + entry_node, "Cannot add field class found in variant field class: ret={}", ret); goto end; } break; @@ -1589,8 +1578,8 @@ static int visit_variant_decl_entry(struct ctf_visitor_generate_ir *ctx, ret = visit_field_class_alias(ctx, entry_node->u.field_class_alias.target, entry_node->u.field_class_alias.alias); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - entry_node, "Cannot add field class alias found in variant field class: ret=%d", + _BT_CPPLOGE_APPEND_CAUSE_NODE( + entry_node, "Cannot add field class alias found in variant field class: ret={}", ret); goto end; } @@ -1606,8 +1595,8 @@ static int visit_variant_decl_entry(struct ctf_visitor_generate_ir *ctx, } break; default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, "Unexpected node type: node-type=%d", - entry_node->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, "Unexpected node type: node-type={}", + entry_node->type); ret = -EINVAL; goto end; } @@ -1629,16 +1618,16 @@ static int visit_struct_decl(struct ctf_visitor_generate_ir *ctx, const char *na /* For named struct (without body), lookup in declaration scope */ if (!has_body) { if (!name) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Bodyless structure field class: missing name."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Bodyless structure field class: missing name."); ret = -EPERM; goto error; } *struct_decl = ctx_decl_scope_lookup_struct(ctx->current_scope, name, -1, true); if (!*struct_decl) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Cannot find structure field class: name=\"struct %s\"", name); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Cannot find structure field class: name=\"struct {}\"", name); ret = -EINVAL; goto error; } @@ -1648,9 +1637,10 @@ static int visit_struct_decl(struct ctf_visitor_generate_ir *ctx, const char *na if (name) { if (ctx_decl_scope_lookup_struct(ctx->current_scope, name, 1, false)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Structure field class already declared in local scope: " - "name=\"struct %s\"", + "name=\"struct {}\"", name); ret = -EINVAL; goto error; @@ -1660,9 +1650,10 @@ static int visit_struct_decl(struct ctf_visitor_generate_ir *ctx, const char *na if (!bt_list_empty(min_align)) { ret = get_unary_unsigned(ctx, min_align, &min_align_value); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Unexpected unary expression for structure field class's `align` attribute: " - "ret=%d", + "ret={}", ret); goto error; } @@ -1680,10 +1671,10 @@ static int visit_struct_decl(struct ctf_visitor_generate_ir *ctx, const char *na bt_list_for_each_entry (entry_node, decl_list, siblings) { ret = visit_struct_decl_entry(ctx, entry_node, *struct_decl); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, - "Cannot visit structure field class entry: " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, + "Cannot visit structure field class entry: " + "ret={}", + ret); ctx_pop_scope(ctx); goto error; } @@ -1694,9 +1685,10 @@ static int visit_struct_decl(struct ctf_visitor_generate_ir *ctx, const char *na if (name) { ret = ctx_decl_scope_register_struct(ctx->current_scope, name, *struct_decl); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Cannot register structure field class in declaration scope: " - "name=\"struct %s\", ret=%d", + "name=\"struct {}\", ret={}", name, ret); goto error; } @@ -1724,15 +1716,16 @@ static int visit_variant_decl(struct ctf_visitor_generate_ir *ctx, const char *n /* For named variant (without body), lookup in declaration scope */ if (!has_body) { if (!name) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Bodyless variant field class: missing name."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Bodyless variant field class: missing name."); ret = -EPERM; goto error; } untagged_variant_decl = ctx_decl_scope_lookup_variant(ctx->current_scope, name, -1, true); if (!untagged_variant_decl) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Cannot find variant field class: name=\"variant %s\"", name); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Cannot find variant field class: name=\"variant {}\"", name); ret = -EINVAL; goto error; } @@ -1741,10 +1734,10 @@ static int visit_variant_decl(struct ctf_visitor_generate_ir *ctx, const char *n if (name) { if (ctx_decl_scope_lookup_variant(ctx->current_scope, name, 1, false)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Variant field class already declared in local scope: " - "name=\"variant %s\"", - name); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Variant field class already declared in local scope: " + "name=\"variant {}\"", + name); ret = -EINVAL; goto error; } @@ -1757,10 +1750,10 @@ static int visit_variant_decl(struct ctf_visitor_generate_ir *ctx, const char *n bt_list_for_each_entry (entry_node, decl_list, siblings) { ret = visit_variant_decl_entry(ctx, entry_node, untagged_variant_decl); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, - "Cannot visit variant field class entry: " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, + "Cannot visit variant field class entry: " + "ret={}", + ret); ctx_pop_scope(ctx); goto error; } @@ -1771,9 +1764,10 @@ static int visit_variant_decl(struct ctf_visitor_generate_ir *ctx, const char *n if (name) { ret = ctx_decl_scope_register_variant(ctx->current_scope, name, untagged_variant_decl); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Cannot register variant field class in declaration scope: " - "name=\"variant %s\", ret=%d", + "name=\"variant {}\", ret={}", name, ret); goto error; } @@ -1846,10 +1840,10 @@ static int visit_enum_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ctf struct uori *target; if (iter->type != NODE_UNARY_EXPRESSION) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, - "Wrong expression for enumeration field class label: " - "node-type=%d, label=\"%s\"", - iter->type, label); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, + "Wrong expression for enumeration field class label: " + "node-type={}, label=\"{}\"", + iter->type, label); ret = -EINVAL; goto error; } @@ -1870,18 +1864,18 @@ static int visit_enum_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ctf target->value.u = iter->u.unary_expression.u.unsigned_constant; break; default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, - "Invalid enumeration field class entry: " - "expecting constant signed or unsigned integer: " - "node-type=%d, label=\"%s\"", - iter->u.unary_expression.type, label); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, + "Invalid enumeration field class entry: " + "expecting constant signed or unsigned integer: " + "node-type={}, label=\"{}\"", + iter->u.unary_expression.type, label); ret = -EINVAL; goto error; } if (nr_vals > 1) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - iter, "Invalid enumeration field class entry: label=\"%s\"", label); + _BT_CPPLOGE_APPEND_CAUSE_NODE( + iter, "Invalid enumeration field class entry: label=\"{}\"", label); ret = -EINVAL; goto error; } @@ -1924,17 +1918,18 @@ static int visit_enum_decl(struct ctf_visitor_generate_ir *ctx, const char *name /* For named enum (without body), lookup in declaration scope */ if (!has_body) { if (!name) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Bodyless enumeration field class: missing name."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Bodyless enumeration field class: missing name."); ret = -EPERM; goto error; } *enum_decl = ctx_decl_scope_lookup_enum(ctx->current_scope, name, -1, true); if (!*enum_decl) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot find enumeration field class: " - "name=\"enum %s\"", - name); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Cannot find enumeration field class: " + "name=\"enum {}\"", + name); ret = -EINVAL; goto error; } @@ -1950,9 +1945,10 @@ static int visit_enum_decl(struct ctf_visitor_generate_ir *ctx, const char *name if (name) { if (ctx_decl_scope_lookup_enum(ctx->current_scope, name, 1, false)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Enumeration field class already declared in local scope: " - "name=\"enum %s\"", + "name=\"enum {}\"", name); ret = -EINVAL; goto error; @@ -1963,7 +1959,8 @@ static int visit_enum_decl(struct ctf_visitor_generate_ir *ctx, const char *name integer_decl = ctf_field_class_as_int( ctx_decl_scope_lookup_alias(ctx->current_scope, "int", -1, true)); if (!integer_decl) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Cannot find implicit `int` field class alias for enumeration field class."); ret = -EINVAL; goto error; @@ -1984,9 +1981,10 @@ static int visit_enum_decl(struct ctf_visitor_generate_ir *ctx, const char *name BT_ASSERT(integer_decl); if (integer_decl->base.base.type != CTF_FIELD_CLASS_TYPE_INT) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Container field class for enumeration field class is not an integer field class: " - "fc-type=%d", + "fc-type={}", integer_decl->base.base.type); ret = -EINVAL; goto error; @@ -2001,10 +1999,10 @@ static int visit_enum_decl(struct ctf_visitor_generate_ir *ctx, const char *name bt_list_for_each_entry (iter, enumerator_list, siblings) { ret = visit_enum_decl_entry(ctx, iter, *enum_decl, &last_value); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, - "Cannot visit enumeration field class entry: " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, + "Cannot visit enumeration field class entry: " + "ret={}", + ret); goto error; } } @@ -2012,9 +2010,10 @@ static int visit_enum_decl(struct ctf_visitor_generate_ir *ctx, const char *name if (name) { ret = ctx_decl_scope_register_enum(ctx->current_scope, name, *enum_decl); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Cannot register enumeration field class in declaration scope: " - "ret=%d", + "ret={}", ret); goto error; } @@ -2044,15 +2043,15 @@ static int visit_field_class_specifier(struct ctf_visitor_generate_ir *ctx, str = g_string_new(""); ret = get_class_specifier_list_name(ctx, cls_specifier_list, str); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - cls_specifier_list, "Cannot get field class specifier list's name: ret=%d", ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(cls_specifier_list, + "Cannot get field class specifier list's name: ret={}", ret); goto error; } *decl = ctx_decl_scope_lookup_alias(ctx->current_scope, str->str, -1, true); if (!*decl) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(cls_specifier_list, - "Cannot find field class alias: name=\"%s\"", str->str); + _BT_CPPLOGE_APPEND_CAUSE_NODE(cls_specifier_list, + "Cannot find field class alias: name=\"{}\"", str->str); ret = -EINVAL; goto error; } @@ -2095,25 +2094,25 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis _BT_LIST_FIRST_ENTRY(&expression->u.ctf_expression.right, struct ctf_node, siblings); if (left->u.unary_expression.type != UNARY_STRING) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(left, "Unexpected unary expression type: type=%d", - left->u.unary_expression.type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(left, "Unexpected unary expression type: type={}", + left->u.unary_expression.type); ret = -EINVAL; goto error; } if (strcmp(left->u.unary_expression.u.string, "signed") == 0) { if (_IS_SET(&set, _INTEGER_SIGNED_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "signed", "integer field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "signed", "integer field class"); ret = -EPERM; goto error; } signedness = get_boolean(ctx, right); if (signedness < 0) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid boolean value for integer field class's `signed` attribute: " - "ret=%d", + "ret={}", ret); ret = -EINVAL; goto error; @@ -2122,17 +2121,17 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis _SET(&set, _INTEGER_SIGNED_SET); } else if (strcmp(left->u.unary_expression.u.string, "byte_order") == 0) { if (_IS_SET(&set, _INTEGER_BYTE_ORDER_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "byte_order", "integer field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "byte_order", "integer field class"); ret = -EPERM; goto error; } byte_order = get_real_byte_order(ctx, right); if (byte_order == CTF_BYTE_ORDER_UNKNOWN) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `byte_order` attribute in integer field class: " - "ret=%d", + "ret={}", ret); ret = -EINVAL; goto error; @@ -2141,36 +2140,36 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis _SET(&set, _INTEGER_BYTE_ORDER_SET); } else if (strcmp(left->u.unary_expression.u.string, "size") == 0) { if (_IS_SET(&set, _INTEGER_SIZE_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "size", "integer field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "size", "integer field class"); ret = -EPERM; goto error; } if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(right, - "Invalid `size` attribute in integer field class: " - "expecting unsigned constant integer: " - "node-type=%d", - right->u.unary_expression.type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(right, + "Invalid `size` attribute in integer field class: " + "expecting unsigned constant integer: " + "node-type={}", + right->u.unary_expression.type); ret = -EINVAL; goto error; } size = right->u.unary_expression.u.unsigned_constant; if (size == 0) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(right, - "Invalid `size` attribute in integer field class: " - "expecting positive constant integer: " - "size=%" PRIu64, - size); + _BT_CPPLOGE_APPEND_CAUSE_NODE(right, + "Invalid `size` attribute in integer field class: " + "expecting positive constant integer: " + "size={}", + size); ret = -EINVAL; goto error; } else if (size > 64) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `size` attribute in integer field class: " "integer fields over 64 bits are not supported as of this version: " - "size=%" PRIu64, + "size={}", size); ret = -EINVAL; goto error; @@ -2179,28 +2178,28 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis _SET(&set, _INTEGER_SIZE_SET); } else if (strcmp(left->u.unary_expression.u.string, "align") == 0) { if (_IS_SET(&set, _INTEGER_ALIGN_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "align", "integer field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "align", "integer field class"); ret = -EPERM; goto error; } if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(right, - "Invalid `align` attribute in integer field class: " - "expecting unsigned constant integer: " - "node-type=%d", - right->u.unary_expression.type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(right, + "Invalid `align` attribute in integer field class: " + "expecting unsigned constant integer: " + "node-type={}", + right->u.unary_expression.type); ret = -EINVAL; goto error; } alignment = right->u.unary_expression.u.unsigned_constant; if (!is_align_valid(alignment)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(right, - "Invalid `align` attribute in integer field class: " - "expecting power of two: " - "align=%" PRIu64, - alignment); + _BT_CPPLOGE_APPEND_CAUSE_NODE(right, + "Invalid `align` attribute in integer field class: " + "expecting power of two: " + "align={}", + alignment); ret = -EINVAL; goto error; } @@ -2208,7 +2207,7 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis _SET(&set, _INTEGER_ALIGN_SET); } else if (strcmp(left->u.unary_expression.u.string, "base") == 0) { if (_IS_SET(&set, _INTEGER_BASE_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "base", "integer field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "base", "integer field class"); ret = -EPERM; goto error; } @@ -2232,10 +2231,10 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL; break; default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `base` attribute in integer field class: " - "base=%" PRIu64, + "base={}", right->u.unary_expression.u.unsigned_constant); ret = -EINVAL; goto error; @@ -2247,7 +2246,7 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis char *s_right = ctf_ast_concatenate_unary_strings(&expression->u.ctf_expression.right); if (!s_right) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Unexpected unary expression for integer field class's `base` attribute."); ret = -EINVAL; @@ -2268,10 +2267,10 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis } else if (strcmp(s_right, "binary") == 0 || strcmp(s_right, "b") == 0) { base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY; } else { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Unexpected unary expression for integer field class's `base` attribute: " - "base=\"%s\"", + "base=\"{}\"", s_right); g_free(s_right); ret = -EINVAL; @@ -2282,7 +2281,7 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis break; } default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `base` attribute in integer field class: " "expecting unsigned constant integer or unary string."); ret = -EINVAL; @@ -2294,13 +2293,13 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis char *s_right; if (_IS_SET(&set, _INTEGER_ENCODING_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "encoding", "integer field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "encoding", "integer field class"); ret = -EPERM; goto error; } if (right->u.unary_expression.type != UNARY_STRING) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `encoding` attribute in integer field class: " "expecting unary string."); ret = -EINVAL; @@ -2309,7 +2308,7 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis s_right = ctf_ast_concatenate_unary_strings(&expression->u.ctf_expression.right); if (!s_right) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Unexpected unary expression for integer field class's `encoding` attribute."); ret = -EINVAL; @@ -2323,10 +2322,10 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis } else if (strcmp(s_right, "none") == 0) { encoding = CTF_ENCODING_NONE; } else { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `encoding` attribute in integer field class: " - "unknown encoding: encoding=\"%s\"", + "unknown encoding: encoding=\"{}\"", s_right); g_free(s_right); ret = -EINVAL; @@ -2339,15 +2338,15 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis const char *clock_name; if (_IS_SET(&set, _INTEGER_MAP_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "map", "integer field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "map", "integer field class"); ret = -EPERM; goto error; } if (right->u.unary_expression.type != UNARY_STRING) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(right, - "Invalid `map` attribute in integer field class: " - "expecting unary string."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(right, + "Invalid `map` attribute in integer field class: " + "expecting unary string."); ret = -EINVAL; goto error; } @@ -2358,17 +2357,17 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis ctf_ast_concatenate_unary_strings(&expression->u.ctf_expression.right); if (!s_right) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Unexpected unary expression for integer field class's `map` attribute."); ret = -EINVAL; goto error; } - _BT_COMP_LOGE_NODE(right, - "Invalid `map` attribute in integer field class: " - "cannot find clock class at this point: name=\"%s\"", - s_right); + _BT_CPPLOGE_NODE(right, + "Invalid `map` attribute in integer field class: " + "cannot find clock class at this point: name=\"{}\"", + s_right); _SET(&set, _INTEGER_MAP_SET); g_free(s_right); continue; @@ -2377,27 +2376,26 @@ static int visit_integer_decl(struct ctf_visitor_generate_ir *ctx, struct bt_lis mapped_clock_class = ctf_trace_class_borrow_clock_class_by_name(ctx->ctf_tc, clock_name); if (!mapped_clock_class) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - right, - "Invalid `map` attribute in integer field class: " - "cannot find clock class at this point: name=\"%s\"", - clock_name); + _BT_CPPLOGE_APPEND_CAUSE_NODE(right, + "Invalid `map` attribute in integer field class: " + "cannot find clock class at this point: name=\"{}\"", + clock_name); ret = -EINVAL; goto error; } _SET(&set, _INTEGER_MAP_SET); } else { - _BT_COMP_LOGW_NODE(left, - "Unknown attribute in integer field class: " - "attr-name=\"%s\"", - left->u.unary_expression.u.string); + _BT_CPPLOGW_NODE(left, + "Unknown attribute in integer field class: " + "attr-name=\"{}\"", + left->u.unary_expression.u.string); } } if (!_IS_SET(&set, _INTEGER_SIZE_SET)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Missing `size` attribute in integer field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "Missing `size` attribute in integer field class."); ret = -EPERM; goto error; } @@ -2449,26 +2447,26 @@ static int visit_floating_point_number_decl(struct ctf_visitor_generate_ir *ctx, _BT_LIST_FIRST_ENTRY(&expression->u.ctf_expression.right, struct ctf_node, siblings); if (left->u.unary_expression.type != UNARY_STRING) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(left, "Unexpected unary expression type: type=%d", - left->u.unary_expression.type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(left, "Unexpected unary expression type: type={}", + left->u.unary_expression.type); ret = -EINVAL; goto error; } if (strcmp(left->u.unary_expression.u.string, "byte_order") == 0) { if (_IS_SET(&set, _FLOAT_BYTE_ORDER_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "byte_order", - "floating point number field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "byte_order", + "floating point number field class"); ret = -EPERM; goto error; } byte_order = get_real_byte_order(ctx, right); if (byte_order == CTF_BYTE_ORDER_UNKNOWN) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `byte_order` attribute in floating point number field class: " - "ret=%d", + "ret={}", ret); ret = -EINVAL; goto error; @@ -2477,18 +2475,18 @@ static int visit_floating_point_number_decl(struct ctf_visitor_generate_ir *ctx, _SET(&set, _FLOAT_BYTE_ORDER_SET); } else if (strcmp(left->u.unary_expression.u.string, "exp_dig") == 0) { if (_IS_SET(&set, _FLOAT_EXP_DIG_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "exp_dig", - "floating point number field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "exp_dig", + "floating point number field class"); ret = -EPERM; goto error; } if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `exp_dig` attribute in floating point number field class: " "expecting unsigned constant integer: " - "node-type=%d", + "node-type={}", right->u.unary_expression.type); ret = -EINVAL; goto error; @@ -2498,18 +2496,18 @@ static int visit_floating_point_number_decl(struct ctf_visitor_generate_ir *ctx, _SET(&set, _FLOAT_EXP_DIG_SET); } else if (strcmp(left->u.unary_expression.u.string, "mant_dig") == 0) { if (_IS_SET(&set, _FLOAT_MANT_DIG_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "mant_dig", - "floating point number field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "mant_dig", + "floating point number field class"); ret = -EPERM; goto error; } if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `mant_dig` attribute in floating point number field class: " "expecting unsigned constant integer: " - "node-type=%d", + "node-type={}", right->u.unary_expression.type); ret = -EINVAL; goto error; @@ -2519,18 +2517,18 @@ static int visit_floating_point_number_decl(struct ctf_visitor_generate_ir *ctx, _SET(&set, _FLOAT_MANT_DIG_SET); } else if (strcmp(left->u.unary_expression.u.string, "align") == 0) { if (_IS_SET(&set, _FLOAT_ALIGN_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "align", - "floating point number field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "align", + "floating point number field class"); ret = -EPERM; goto error; } if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `align` attribute in floating point number field class: " "expecting unsigned constant integer: " - "node-type=%d", + "node-type={}", right->u.unary_expression.type); ret = -EINVAL; goto error; @@ -2539,11 +2537,11 @@ static int visit_floating_point_number_decl(struct ctf_visitor_generate_ir *ctx, alignment = right->u.unary_expression.u.unsigned_constant; if (!is_align_valid(alignment)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Invalid `align` attribute in floating point number field class: " "expecting power of two: " - "align=%" PRIu64, + "align={}", alignment); ret = -EINVAL; goto error; @@ -2551,43 +2549,43 @@ static int visit_floating_point_number_decl(struct ctf_visitor_generate_ir *ctx, _SET(&set, _FLOAT_ALIGN_SET); } else { - _BT_COMP_LOGW_NODE(left, - "Unknown attribute in floating point number field class: " - "attr-name=\"%s\"", - left->u.unary_expression.u.string); + _BT_CPPLOGW_NODE(left, + "Unknown attribute in floating point number field class: " + "attr-name=\"{}\"", + left->u.unary_expression.u.string); } } if (!_IS_SET(&set, _FLOAT_MANT_DIG_SET)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Missing `mant_dig` attribute in floating point number field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Missing `mant_dig` attribute in floating point number field class."); ret = -EPERM; goto error; } if (!_IS_SET(&set, _FLOAT_EXP_DIG_SET)) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Missing `exp_dig` attribute in floating point number field class."); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Missing `exp_dig` attribute in floating point number field class."); ret = -EPERM; goto error; } if (mant_dig != 24 && mant_dig != 53) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("`mant_dig` attribute: expecting 24 or 53."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, "`mant_dig` attribute: expecting 24 or 53."); ret = -EPERM; goto error; } if (mant_dig == 24 && exp_dig != 8) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "`exp_dig` attribute: expecting 8 because `mant_dig` is 24."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "`exp_dig` attribute: expecting 8 because `mant_dig` is 24."); ret = -EPERM; goto error; } if (mant_dig == 53 && exp_dig != 11) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "`exp_dig` attribute: expecting 11 because `mant_dig` is 53."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctx->logger, + "`exp_dig` attribute: expecting 11 because `mant_dig` is 53."); ret = -EPERM; goto error; } @@ -2633,8 +2631,8 @@ static int visit_string_decl(struct ctf_visitor_generate_ir *ctx, struct bt_list _BT_LIST_FIRST_ENTRY(&expression->u.ctf_expression.right, struct ctf_node, siblings); if (left->u.unary_expression.type != UNARY_STRING) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(left, "Unexpected unary expression type: type=%d", - left->u.unary_expression.type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(left, "Unexpected unary expression type: type={}", + left->u.unary_expression.type); ret = -EINVAL; goto error; } @@ -2643,22 +2641,22 @@ static int visit_string_decl(struct ctf_visitor_generate_ir *ctx, struct bt_list char *s_right; if (_IS_SET(&set, _STRING_ENCODING_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "encoding", "string field class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(left, "encoding", "string field class"); ret = -EPERM; goto error; } if (right->u.unary_expression.type != UNARY_STRING) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - right, "Invalid `encoding` attribute in string field class: " - "expecting unary string."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(right, + "Invalid `encoding` attribute in string field class: " + "expecting unary string."); ret = -EINVAL; goto error; } s_right = ctf_ast_concatenate_unary_strings(&expression->u.ctf_expression.right); if (!s_right) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( right, "Unexpected unary expression for string field class's `encoding` attribute."); ret = -EINVAL; @@ -2672,11 +2670,10 @@ static int visit_string_decl(struct ctf_visitor_generate_ir *ctx, struct bt_list } else if (strcmp(s_right, "none") == 0) { encoding = CTF_ENCODING_NONE; } else { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - right, - "Invalid `encoding` attribute in string field class: " - "unknown encoding: encoding=\"%s\"", - s_right); + _BT_CPPLOGE_APPEND_CAUSE_NODE(right, + "Invalid `encoding` attribute in string field class: " + "unknown encoding: encoding=\"{}\"", + s_right); g_free(s_right); ret = -EINVAL; goto error; @@ -2685,10 +2682,10 @@ static int visit_string_decl(struct ctf_visitor_generate_ir *ctx, struct bt_list g_free(s_right); _SET(&set, _STRING_ENCODING_SET); } else { - _BT_COMP_LOGW_NODE(left, - "Unknown attribute in string field class: " - "attr-name=\"%s\"", - left->u.unary_expression.u.string); + _BT_CPPLOGW_NODE(left, + "Unknown attribute in string field class: " + "attr-name=\"{}\"", + left->u.unary_expression.u.string); } } @@ -2712,8 +2709,7 @@ static int visit_field_class_specifier_list(struct ctf_visitor_generate_ir *ctx, *decl = NULL; if (ts_list->type != NODE_TYPE_SPECIFIER_LIST) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(ts_list, "Unexpected node type: node-type=%d", - ts_list->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(ts_list, "Unexpected node type: node-type={}", ts_list->type); ret = -EINVAL; goto error; } @@ -2721,7 +2717,7 @@ static int visit_field_class_specifier_list(struct ctf_visitor_generate_ir *ctx, first = _BT_LIST_FIRST_ENTRY(&ts_list->u.field_class_specifier_list.head, struct ctf_node, siblings); if (first->type != NODE_TYPE_SPECIFIER) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(first, "Unexpected node type: node-type=%d", first->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(first, "Unexpected node type: node-type={}", first->type); ret = -EINVAL; goto error; } @@ -2828,16 +2824,14 @@ static int visit_field_class_specifier_list(struct ctf_visitor_generate_ir *ctx, case TYPESPEC_ID_TYPE: ret = visit_field_class_specifier(ctx, ts_list, decl); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(first, "Cannot visit field class specifier: ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(first, "Cannot visit field class specifier: ret={}", ret); BT_ASSERT(!*decl); goto error; } break; default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE(first, - "Unexpected field class specifier type: node-type=%d", - first->u.field_class_specifier.type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(first, "Unexpected field class specifier type: node-type={}", + first->u.field_class_specifier.type); ret = -EINVAL; goto error; } @@ -2863,7 +2857,7 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct ret = visit_field_class_def(ctx, node->u.field_class_def.field_class_specifier_list, &node->u.field_class_def.field_class_declarators); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Cannot add field class found in event class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Cannot add field class found in event class."); goto error; } break; @@ -2871,8 +2865,8 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct ret = visit_field_class_alias(ctx, node->u.field_class_alias.target, node->u.field_class_alias.alias); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Cannot add field class alias found in event class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Cannot add field class alias found in event class."); goto error; } break; @@ -2880,7 +2874,7 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct { left = ctf_ast_concatenate_unary_strings(&node->u.ctf_expression.left); if (!left) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Cannot concatenate unary strings."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Cannot concatenate unary strings."); ret = -EINVAL; goto error; } @@ -2888,7 +2882,7 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct if (strcmp(left, "name") == 0) { /* This is already known at this stage */ if (_IS_SET(set, _EVENT_NAME_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "name", "event class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "name", "event class"); ret = -EPERM; goto error; } @@ -2898,7 +2892,7 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct int64_t id = -1; if (_IS_SET(set, _EVENT_ID_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "id", "event class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "id", "event class"); ret = -EPERM; goto error; } @@ -2906,7 +2900,7 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct ret = get_unary_unsigned(ctx, &node->u.ctf_expression.right, (uint64_t *) &id); /* Only read "id" if get_unary_unsigned() succeeded. */ if (ret || (!ret && id < 0)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Unexpected unary expression for event class's `id` attribute."); ret = -EINVAL; goto error; @@ -2916,7 +2910,7 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct _SET(set, _EVENT_ID_SET); } else if (strcmp(left, "stream_id") == 0) { if (_IS_SET(set, _EVENT_STREAM_ID_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "stream_id", "event class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "stream_id", "event class"); ret = -EPERM; goto error; } @@ -2928,7 +2922,7 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct * succeeded. */ if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Unexpected unary expression for event class's `stream_id` attribute."); ret = -EINVAL; goto error; @@ -2937,7 +2931,7 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct _SET(set, _EVENT_STREAM_ID_SET); } else if (strcmp(left, "context") == 0) { if (_IS_SET(set, _EVENT_CONTEXT_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Duplicate `context` entry in event class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Duplicate `context` entry in event class."); ret = -EPERM; goto error; } @@ -2946,8 +2940,8 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct ctx, _BT_LIST_FIRST_ENTRY(&node->u.ctf_expression.right, struct ctf_node, siblings), &event_class->spec_context_fc); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Cannot create event class's context field class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Cannot create event class's context field class."); goto error; } @@ -2955,7 +2949,7 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct _SET(set, _EVENT_CONTEXT_SET); } else if (strcmp(left, "fields") == 0) { if (_IS_SET(set, _EVENT_FIELDS_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Duplicate `fields` entry in event class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Duplicate `fields` entry in event class."); ret = -EPERM; goto error; } @@ -2964,8 +2958,8 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct ctx, _BT_LIST_FIRST_ENTRY(&node->u.ctf_expression.right, struct ctf_node, siblings), &event_class->payload_fc); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Cannot create event class's payload field class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Cannot create event class's payload field class."); goto error; } @@ -2977,14 +2971,14 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct bt_event_class_log_level log_level; if (_IS_SET(set, _EVENT_LOG_LEVEL_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "loglevel", "event class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "loglevel", "event class"); ret = -EPERM; goto error; } ret = get_unary_unsigned(ctx, &node->u.ctf_expression.right, &loglevel_value); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Unexpected unary expression for event class's `loglevel` attribute."); ret = -EINVAL; goto error; @@ -3038,10 +3032,10 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct break; default: is_log_level_known = false; - _BT_COMP_LOGW_NODE( + _BT_CPPLOGW_NODE( node, "Not setting event class's log level because its value is unknown: " - "log-level=%" PRIu64, + "log-level={}", loglevel_value); } @@ -3054,14 +3048,14 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct char *right; if (_IS_SET(set, _EVENT_MODEL_EMF_URI_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "model.emf.uri", "event class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "model.emf.uri", "event class"); ret = -EPERM; goto error; } right = ctf_ast_concatenate_unary_strings(&node->u.ctf_expression.right); if (!right) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Unexpected unary expression for event class's `model.emf.uri` attribute."); ret = -EINVAL; @@ -3069,7 +3063,7 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct } if (strlen(right) == 0) { - _BT_COMP_LOGW_NODE(node, "Not setting event class's EMF URI because it's empty."); + _BT_CPPLOGW_NODE(node, "Not setting event class's EMF URI because it's empty."); } else { g_string_assign(event_class->emf_uri, right); } @@ -3077,10 +3071,10 @@ static int visit_event_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct g_free(right); _SET(set, _EVENT_MODEL_EMF_URI_SET); } else { - _BT_COMP_LOGW_NODE(node, - "Unknown attribute in event class: " - "attr-name=\"%s\"", - left); + _BT_CPPLOGW_NODE(node, + "Unknown attribute in event class: " + "attr-name=\"{}\"", + left); } g_free(left); @@ -3115,14 +3109,14 @@ static char *get_event_decl_name(struct ctf_visitor_generate_ir *ctx, struct ctf left = ctf_ast_concatenate_unary_strings(&iter->u.ctf_expression.left); if (!left) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, "Cannot concatenate unary strings."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, "Cannot concatenate unary strings."); goto error; } if (strcmp(left, "name") == 0) { name = ctf_ast_concatenate_unary_strings(&iter->u.ctf_expression.right); if (!name) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( iter, "Unexpected unary expression for event class's `name` attribute."); goto error; } @@ -3162,7 +3156,7 @@ static int visit_event_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node node->visited = TRUE; event_name = get_event_decl_name(ctx, node); if (!event_name) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Missing `name` attribute in event class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Missing `name` attribute in event class."); ret = -EPERM; goto error; } @@ -3176,10 +3170,10 @@ static int visit_event_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node bt_list_for_each_entry (iter, decl_list, siblings) { ret = visit_event_decl_entry(ctx, iter, event_class, &stream_id, &set); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, - "Cannot visit event class's entry: " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, + "Cannot visit event class's entry: " + "ret={}", + ret); goto error; } } @@ -3204,7 +3198,7 @@ static int visit_event_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node stream_id = stream_class->id; break; default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Missing `stream_id` attribute in event class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Missing `stream_id` attribute in event class."); ret = -EPERM; goto error; } @@ -3214,10 +3208,10 @@ static int visit_event_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node if (!stream_class) { stream_class = ctf_trace_class_borrow_stream_class_by_id(ctx->ctf_tc, stream_id); if (!stream_class) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Cannot find stream class at this point: " - "id=%" PRId64, - stream_id); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Cannot find stream class at this point: " + "id={}", + stream_id); ret = -EINVAL; goto error; } @@ -3228,7 +3222,7 @@ static int visit_event_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node if (!_IS_SET(&set, _EVENT_ID_SET)) { /* Allow only one event without ID per stream */ if (stream_class->event_classes->len != 0) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Missing `id` attribute in event class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Missing `id` attribute in event class."); ret = -EPERM; goto error; } @@ -3238,10 +3232,10 @@ static int visit_event_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node } if (ctf_stream_class_borrow_event_class_by_id(stream_class, event_class->id)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Duplicate event class (same ID) in the same stream class: " - "id=%" PRId64, - event_class->id); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Duplicate event class (same ID) in the same stream class: " + "id={}", + event_class->id); ret = -EEXIST; goto error; } @@ -3316,9 +3310,9 @@ static int auto_map_field_to_trace_clock_class(struct ctf_visitor_generate_ir *c * Timestamp field not mapped to a clock class and there's more * than one clock class in the trace: this is an error. */ - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - "Timestamp field found with no mapped clock class, " - "but there's more than one clock class in the trace at this point."); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Timestamp field found with no mapped clock class, " + "but there's more than one clock class in the trace at this point."); return -1; } @@ -3366,9 +3360,10 @@ static int auto_map_fields_to_trace_clock_class(struct ctf_visitor_generate_ir * if (strcmp(named_fc->name->str, field_name) == 0) { ret = auto_map_field_to_trace_clock_class(ctx, named_fc->fc); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Cannot automatically map field to trace's clock class: " - "field-name=\"%s\"", + "field-name=\"{}\"", field_name); goto end; } @@ -3376,9 +3371,10 @@ static int auto_map_fields_to_trace_clock_class(struct ctf_visitor_generate_ir * ret = auto_map_fields_to_trace_clock_class(ctx, named_fc->fc, field_name); if (ret) { - _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctx->logger, "Cannot automatically map structure or variant field class's fields to trace's clock class: " - "field-name=\"%s\", root-field-name=\"%s\"", + "field-name=\"{}\", root-field-name=\"{}\"", field_name, named_fc->name->str); goto end; } @@ -3399,7 +3395,7 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c ret = visit_field_class_def(ctx, node->u.field_class_def.field_class_specifier_list, &node->u.field_class_def.field_class_declarators); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Cannot add field class found in stream class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Cannot add field class found in stream class."); goto error; } break; @@ -3407,8 +3403,8 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c ret = visit_field_class_alias(ctx, node->u.field_class_alias.target, node->u.field_class_alias.alias); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Cannot add field class alias found in stream class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Cannot add field class alias found in stream class."); goto error; } break; @@ -3416,7 +3412,7 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c { left = ctf_ast_concatenate_unary_strings(&node->u.ctf_expression.left); if (!left) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Cannot concatenate unary strings."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Cannot concatenate unary strings."); ret = -EINVAL; goto error; } @@ -3425,7 +3421,7 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c int64_t id; if (_IS_SET(set, _STREAM_ID_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "id", "stream declaration"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "id", "stream declaration"); ret = -EPERM; goto error; } @@ -3434,15 +3430,14 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c /* Only read "id" if get_unary_unsigned() succeeded. */ if (ret || (!ret && id < 0)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Unexpected unary expression for stream class's `id` attribute."); ret = -EINVAL; goto error; } if (ctf_trace_class_borrow_stream_class_by_id(ctx->ctf_tc, id)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - node, "Duplicate stream class (same ID): id=%" PRId64, id); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Duplicate stream class (same ID): id={}", id); ret = -EEXIST; goto error; } @@ -3451,8 +3446,8 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c _SET(set, _STREAM_ID_SET); } else if (strcmp(left, "event.header") == 0) { if (_IS_SET(set, _STREAM_EVENT_HEADER_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Duplicate `event.header` entry in stream class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Duplicate `event.header` entry in stream class."); ret = -EPERM; goto error; } @@ -3461,7 +3456,7 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c ctx, _BT_LIST_FIRST_ENTRY(&node->u.ctf_expression.right, struct ctf_node, siblings), &stream_class->event_header_fc); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Cannot create stream class's event header field class."); goto error; } @@ -3470,7 +3465,7 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c ret = auto_map_fields_to_trace_clock_class(ctx, stream_class->event_header_fc, "timestamp"); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Cannot automatically map specific event header field class fields named `timestamp` to trace's clock class."); goto error; @@ -3479,8 +3474,8 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c _SET(set, _STREAM_EVENT_HEADER_SET); } else if (strcmp(left, "event.context") == 0) { if (_IS_SET(set, _STREAM_EVENT_CONTEXT_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Duplicate `event.context` entry in stream class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Duplicate `event.context` entry in stream class."); ret = -EPERM; goto error; } @@ -3489,7 +3484,7 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c ctx, _BT_LIST_FIRST_ENTRY(&node->u.ctf_expression.right, struct ctf_node, siblings), &stream_class->event_common_context_fc); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Cannot create stream class's event context field class."); goto error; } @@ -3498,8 +3493,8 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c _SET(set, _STREAM_EVENT_CONTEXT_SET); } else if (strcmp(left, "packet.context") == 0) { if (_IS_SET(set, _STREAM_PACKET_CONTEXT_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - node, "Duplicate `packet.context` entry in stream class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Duplicate `packet.context` entry in stream class."); ret = -EPERM; goto error; } @@ -3508,7 +3503,7 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c ctx, _BT_LIST_FIRST_ENTRY(&node->u.ctf_expression.right, struct ctf_node, siblings), &stream_class->packet_context_fc); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Cannot create stream class's packet context field class."); goto error; } @@ -3517,7 +3512,7 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c ret = auto_map_fields_to_trace_clock_class(ctx, stream_class->packet_context_fc, "timestamp_begin"); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Cannot automatically map specific packet context field class fields named `timestamp_begin` to trace's clock class."); goto error; @@ -3526,7 +3521,7 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c ret = auto_map_fields_to_trace_clock_class(ctx, stream_class->packet_context_fc, "timestamp_end"); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Cannot automatically map specific packet context field class fields named `timestamp_end` to trace's clock class."); goto error; @@ -3534,10 +3529,10 @@ static int visit_stream_decl_entry(struct ctf_visitor_generate_ir *ctx, struct c _SET(set, _STREAM_PACKET_CONTEXT_SET); } else { - _BT_COMP_LOGW_NODE(node, - "Unknown attribute in stream class: " - "attr-name=\"%s\"", - left); + _BT_CPPLOGW_NODE(node, + "Unknown attribute in stream class: " + "attr-name=\"{}\"", + left); } g_free(left); @@ -3577,10 +3572,10 @@ static int visit_stream_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_nod bt_list_for_each_entry (iter, decl_list, siblings) { ret = visit_stream_decl_entry(ctx, iter, stream_class, &set); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, - "Cannot visit stream class's entry: " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, + "Cannot visit stream class's entry: " + "ret={}", + ret); ctx_pop_scope(ctx); goto error; } @@ -3593,8 +3588,8 @@ static int visit_stream_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_nod struct ctf_named_field_class *named_fc = NULL; if (!ctx->ctf_tc->packet_header_fc) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Stream class has a `id` attribute, " - "but trace has no packet header field class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Stream class has a `id` attribute, " + "but trace has no packet header field class."); ret = -EINVAL; goto error; } @@ -3602,7 +3597,7 @@ static int visit_stream_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_nod named_fc = ctf_field_class_struct_borrow_member_by_name( ctf_field_class_as_struct(ctx->ctf_tc->packet_header_fc), "stream_id"); if (!named_fc) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Stream class has a `id` attribute, " "but trace's packet header field class has no `stream_id` field."); ret = -EINVAL; @@ -3611,7 +3606,7 @@ static int visit_stream_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_nod if (named_fc->fc->type != CTF_FIELD_CLASS_TYPE_INT && named_fc->fc->type != CTF_FIELD_CLASS_TYPE_ENUM) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Stream class has a `id` attribute, " "but trace's packet header field class's `stream_id` field is not an integer field class."); @@ -3621,7 +3616,7 @@ static int visit_stream_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_nod } else { /* Allow only _one_ ID-less stream */ if (ctx->ctf_tc->stream_classes->len != 0) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Missing `id` attribute in stream class as there's more than one stream class in the trace."); ret = -EPERM; @@ -3637,8 +3632,8 @@ static int visit_stream_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_nod * the trace. */ if (ctf_trace_class_borrow_stream_class_by_id(ctx->ctf_tc, stream_class->id)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Duplicate stream class (same ID): id=%" PRId64, - stream_class->id); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Duplicate stream class (same ID): id={}", + stream_class->id); ret = -EINVAL; goto error; } @@ -3667,8 +3662,8 @@ static int visit_trace_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct ret = visit_field_class_def(ctx, node->u.field_class_def.field_class_specifier_list, &node->u.field_class_def.field_class_declarators); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( - node, "Cannot add field class found in trace (`trace` block)."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Cannot add field class found in trace (`trace` block)."); goto error; } break; @@ -3676,7 +3671,7 @@ static int visit_trace_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct ret = visit_field_class_alias(ctx, node->u.field_class_alias.target, node->u.field_class_alias.alias); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Cannot add field class alias found in trace (`trace` block)."); goto error; } @@ -3685,29 +3680,29 @@ static int visit_trace_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct { left = ctf_ast_concatenate_unary_strings(&node->u.ctf_expression.left); if (!left) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Cannot concatenate unary strings."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Cannot concatenate unary strings."); ret = -EINVAL; goto error; } if (strcmp(left, "major") == 0) { if (_IS_SET(set, _TRACE_MAJOR_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "major", "trace"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "major", "trace"); ret = -EPERM; goto error; } ret = get_unary_unsigned(ctx, &node->u.ctf_expression.right, &val); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Unexpected unary expression for trace's `major` attribute."); ret = -EINVAL; goto error; } if (val != 1) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Invalid trace's `minor` attribute: expecting 1."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Invalid trace's `minor` attribute: expecting 1."); ret = -EINVAL; goto error; } @@ -3716,22 +3711,22 @@ static int visit_trace_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct _SET(set, _TRACE_MAJOR_SET); } else if (strcmp(left, "minor") == 0) { if (_IS_SET(set, _TRACE_MINOR_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "minor", "trace"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "minor", "trace"); ret = -EPERM; goto error; } ret = get_unary_unsigned(ctx, &node->u.ctf_expression.right, &val); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Unexpected unary expression for trace's `minor` attribute."); ret = -EINVAL; goto error; } if (val != 8) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Invalid trace's `minor` attribute: expecting 8."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Invalid trace's `minor` attribute: expecting 8."); ret = -EINVAL; goto error; } @@ -3740,14 +3735,14 @@ static int visit_trace_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct _SET(set, _TRACE_MINOR_SET); } else if (strcmp(left, "uuid") == 0) { if (_IS_SET(set, _TRACE_UUID_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "uuid", "trace"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "uuid", "trace"); ret = -EPERM; goto error; } ret = get_unary_uuid(ctx, &node->u.ctf_expression.right, ctx->ctf_tc->uuid); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Invalid trace's `uuid` attribute."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Invalid trace's `uuid` attribute."); goto error; } @@ -3756,7 +3751,7 @@ static int visit_trace_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct } else if (strcmp(left, "byte_order") == 0) { /* Default byte order is already known at this stage */ if (_IS_SET(set, _TRACE_BYTE_ORDER_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "byte_order", "trace"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "byte_order", "trace"); ret = -EPERM; goto error; } @@ -3765,7 +3760,7 @@ static int visit_trace_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct _SET(set, _TRACE_BYTE_ORDER_SET); } else if (strcmp(left, "packet.header") == 0) { if (_IS_SET(set, _TRACE_PACKET_HEADER_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Duplicate `packet.header` entry in trace."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Duplicate `packet.header` entry in trace."); ret = -EPERM; goto error; } @@ -3774,18 +3769,18 @@ static int visit_trace_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct ctx, _BT_LIST_FIRST_ENTRY(&node->u.ctf_expression.right, struct ctf_node, siblings), &ctx->ctf_tc->packet_header_fc); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Cannot create trace's packet header field class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Cannot create trace's packet header field class."); goto error; } BT_ASSERT(ctx->ctf_tc->packet_header_fc); _SET(set, _TRACE_PACKET_HEADER_SET); } else { - _BT_COMP_LOGW_NODE(node, - "Unknown attribute in stream class: " - "attr-name=\"%s\"", - left); + _BT_CPPLOGW_NODE(node, + "Unknown attribute in stream class: " + "attr-name=\"{}\"", + left); } g_free(left); @@ -3793,7 +3788,7 @@ static int visit_trace_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct break; } default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Unknown expression in trace."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Unknown expression in trace."); ret = -EINVAL; goto error; } @@ -3819,7 +3814,7 @@ static int visit_trace_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node node->visited = TRUE; if (ctx->is_trace_visited) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Duplicate trace (`trace` block)."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Duplicate trace (`trace` block)."); ret = -EEXIST; goto error; } @@ -3829,10 +3824,10 @@ static int visit_trace_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node bt_list_for_each_entry (iter, decl_list, siblings) { ret = visit_trace_decl_entry(ctx, iter, &set); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, - "Cannot visit trace's entry (`trace` block): " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, + "Cannot visit trace's entry (`trace` block): " + "ret={}", + ret); ctx_pop_scope(ctx); goto error; } @@ -3841,22 +3836,20 @@ static int visit_trace_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node ctx_pop_scope(ctx); if (!_IS_SET(&set, _TRACE_MAJOR_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Missing `major` attribute in trace (`trace` block)."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Missing `major` attribute in trace (`trace` block)."); ret = -EPERM; goto error; } if (!_IS_SET(&set, _TRACE_MINOR_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Missing `minor` attribute in trace (`trace` block)."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Missing `minor` attribute in trace (`trace` block)."); ret = -EPERM; goto error; } if (!_IS_SET(&set, _TRACE_BYTE_ORDER_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Missing `byte_order` attribute in trace (`trace` block)."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Missing `byte_order` attribute in trace (`trace` block)."); ret = -EPERM; goto error; } @@ -3887,17 +3880,17 @@ static int visit_env(struct ctf_visitor_generate_ir *ctx, struct ctf_node *node) struct bt_list_head *right_head = &entry_node->u.ctf_expression.right; if (entry_node->type != NODE_CTF_EXPRESSION) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, - "Wrong expression in environment entry: " - "node-type=%d", - entry_node->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, + "Wrong expression in environment entry: " + "node-type={}", + entry_node->type); ret = -EPERM; goto error; } left = ctf_ast_concatenate_unary_strings(&entry_node->u.ctf_expression.left); if (!left) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, "Cannot get environment entry's name."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, "Cannot get environment entry's name."); ret = -EINVAL; goto error; } @@ -3906,10 +3899,10 @@ static int visit_env(struct ctf_visitor_generate_ir *ctx, struct ctf_node *node) char *right = ctf_ast_concatenate_unary_strings(right_head); if (!right) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( entry_node, "Unexpected unary expression for environment entry's value: " - "name=\"%s\"", + "name=\"{}\"", left); ret = -EINVAL; goto error; @@ -3917,9 +3910,10 @@ static int visit_env(struct ctf_visitor_generate_ir *ctx, struct ctf_node *node) if (strcmp(left, "tracer_name") == 0) { if (strncmp(right, "lttng", 5) == 0) { - BT_COMP_LOGI("Detected LTTng trace from `%s` environment value: " - "tracer-name=\"%s\"", - left, right); + BT_CPPLOGI_SPEC(ctx->logger, + "Detected LTTng trace from `{}` environment value: " + "tracer-name=\"{}\"", + left, right); ctx->is_lttng = true; } } @@ -3936,10 +3930,10 @@ static int visit_env(struct ctf_visitor_generate_ir *ctx, struct ctf_node *node) ret = get_unary_signed(right_head, &v); } if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( entry_node, "Unexpected unary expression for environment entry's value: " - "name=\"%s\"", + "name=\"{}\"", left); ret = -EINVAL; goto error; @@ -3948,10 +3942,10 @@ static int visit_env(struct ctf_visitor_generate_ir *ctx, struct ctf_node *node) ctf_trace_class_append_env_entry(ctx->ctf_tc, left, CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT, NULL, v); } else { - _BT_COMP_LOGW_NODE(entry_node, - "Environment entry has unknown type: " - "name=\"%s\"", - left); + _BT_CPPLOGW_NODE(entry_node, + "Environment entry has unknown type: " + "name=\"{}\"", + left); } g_free(left); @@ -3980,7 +3974,7 @@ static int set_trace_byte_order(struct ctf_visitor_generate_ir *ctx, struct ctf_ left = ctf_ast_concatenate_unary_strings(&node->u.ctf_expression.left); if (!left) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Cannot concatenate unary strings."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Cannot concatenate unary strings."); ret = -EINVAL; goto error; } @@ -3989,7 +3983,7 @@ static int set_trace_byte_order(struct ctf_visitor_generate_ir *ctx, struct ctf_ enum ctf_byte_order bo; if (_IS_SET(&set, _TRACE_BYTE_ORDER_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(node, "byte_order", "trace"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(node, "byte_order", "trace"); ret = -EPERM; goto error; } @@ -3999,13 +3993,13 @@ static int set_trace_byte_order(struct ctf_visitor_generate_ir *ctx, struct ctf_ _BT_LIST_FIRST_ENTRY(&node->u.ctf_expression.right, struct ctf_node, siblings); bo = byte_order_from_unary_expr(ctx, right_node); if (bo == CTF_BYTE_ORDER_UNKNOWN) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Invalid `byte_order` attribute in trace (`trace` block): " "expecting `le`, `be`, or `network`."); ret = -EINVAL; goto error; } else if (bo == CTF_BYTE_ORDER_DEFAULT) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( node, "Invalid `byte_order` attribute in trace (`trace` block): " "cannot be set to `native` here."); ret = -EPERM; @@ -4021,8 +4015,8 @@ static int set_trace_byte_order(struct ctf_visitor_generate_ir *ctx, struct ctf_ } if (!_IS_SET(&set, _TRACE_BYTE_ORDER_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(trace_node, - "Missing `byte_order` attribute in trace (`trace` block)."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(trace_node, + "Missing `byte_order` attribute in trace (`trace` block)."); ret = -EINVAL; goto error; } @@ -4042,15 +4036,15 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct char *left = NULL; if (entry_node->type != NODE_CTF_EXPRESSION) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, "Unexpected node type: node-type=%d", - entry_node->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, "Unexpected node type: node-type={}", + entry_node->type); ret = -EPERM; goto error; } left = ctf_ast_concatenate_unary_strings(&entry_node->u.ctf_expression.left); if (!left) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, "Cannot concatenate unary strings."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, "Cannot concatenate unary strings."); ret = -EINVAL; goto error; } @@ -4059,14 +4053,14 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct char *right; if (_IS_SET(set, _CLOCK_NAME_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "name", "clock class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "name", "clock class"); ret = -EPERM; goto error; } right = ctf_ast_concatenate_unary_strings(&entry_node->u.ctf_expression.right); if (!right) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( entry_node, "Unexpected unary expression for clock class's `name` attribute."); ret = -EINVAL; goto error; @@ -4079,14 +4073,14 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct bt_uuid_t uuid; if (_IS_SET(set, _CLOCK_UUID_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "uuid", "clock class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "uuid", "clock class"); ret = -EPERM; goto error; } ret = get_unary_uuid(ctx, &entry_node->u.ctf_expression.right, uuid); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, "Invalid clock class's `uuid` attribute."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, "Invalid clock class's `uuid` attribute."); goto error; } @@ -4097,14 +4091,14 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct char *right; if (_IS_SET(set, _CLOCK_DESCRIPTION_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "description", "clock class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "description", "clock class"); ret = -EPERM; goto error; } right = ctf_ast_concatenate_unary_strings(&entry_node->u.ctf_expression.right); if (!right) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( entry_node, "Unexpected unary expression for clock class's `description` attribute."); ret = -EINVAL; @@ -4118,22 +4112,22 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct uint64_t freq = UINT64_C(-1); if (_IS_SET(set, _CLOCK_FREQ_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "freq", "clock class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "freq", "clock class"); ret = -EPERM; goto error; } ret = get_unary_unsigned(ctx, &entry_node->u.ctf_expression.right, &freq); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( entry_node, "Unexpected unary expression for clock class's `freq` attribute."); ret = -EINVAL; goto error; } if (freq == UINT64_C(-1) || freq == 0) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, - "Invalid clock class frequency: freq=%" PRIu64, freq); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, "Invalid clock class frequency: freq={}", + freq); ret = -EINVAL; goto error; } @@ -4144,14 +4138,14 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct uint64_t precision; if (_IS_SET(set, _CLOCK_PRECISION_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "precision", "clock class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "precision", "clock class"); ret = -EPERM; goto error; } ret = get_unary_unsigned(ctx, &entry_node->u.ctf_expression.right, &precision); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( entry_node, "Unexpected unary expression for clock class's `precision` attribute."); ret = -EINVAL; goto error; @@ -4161,14 +4155,14 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct _SET(set, _CLOCK_PRECISION_SET); } else if (strcmp(left, "offset_s") == 0) { if (_IS_SET(set, _CLOCK_OFFSET_S_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "offset_s", "clock class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "offset_s", "clock class"); ret = -EPERM; goto error; } ret = get_unary_signed(&entry_node->u.ctf_expression.right, offset_seconds); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( entry_node, "Unexpected unary expression for clock class's `offset_s` attribute."); ret = -EINVAL; goto error; @@ -4177,14 +4171,14 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct _SET(set, _CLOCK_OFFSET_S_SET); } else if (strcmp(left, "offset") == 0) { if (_IS_SET(set, _CLOCK_OFFSET_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "offset", "clock class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "offset", "clock class"); ret = -EPERM; goto error; } ret = get_unary_unsigned(ctx, &entry_node->u.ctf_expression.right, offset_cycles); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( entry_node, "Unexpected unary expression for clock class's `offset` attribute."); ret = -EINVAL; goto error; @@ -4195,7 +4189,7 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct struct ctf_node *right; if (_IS_SET(set, _CLOCK_ABSOLUTE_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "absolute", "clock class"); + _BT_CPPLOGE_APPEND_CAUSE_DUP_ATTR(entry_node, "absolute", "clock class"); ret = -EPERM; goto error; } @@ -4204,7 +4198,7 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct _BT_LIST_FIRST_ENTRY(&entry_node->u.ctf_expression.right, struct ctf_node, siblings); ret = get_boolean(ctx, right); if (ret < 0) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( entry_node, "Unexpected unary expression for clock class's `absolute` attribute."); ret = -EINVAL; goto error; @@ -4213,7 +4207,7 @@ static int visit_clock_decl_entry(struct ctf_visitor_generate_ir *ctx, struct ct clock->is_absolute = ret; _SET(set, _CLOCK_ABSOLUTE_SET); } else { - _BT_COMP_LOGW_NODE(entry_node, "Unknown attribute in clock class: attr-name=\"%s\"", left); + _BT_CPPLOGW_NODE(entry_node, "Unknown attribute in clock class: attr-name=\"{}\"", left); } g_free(left); @@ -4338,7 +4332,7 @@ static int visit_clock_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node /* CTF 1.8's default frequency for a clock class is 1 GHz */ clock = ctf_clock_class_create(); if (!clock) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(clock_node, "Cannot create default clock class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(clock_node, "Cannot create default clock class."); ret = -ENOMEM; goto end; } @@ -4346,14 +4340,14 @@ static int visit_clock_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node bt_list_for_each_entry (entry_node, decl_list, siblings) { ret = visit_clock_decl_entry(ctx, entry_node, clock, &set, &offset_seconds, &offset_cycles); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(entry_node, "Cannot visit clock class's entry: ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(entry_node, "Cannot visit clock class's entry: ret={}", + ret); goto end; } } if (!_IS_SET(&set, _CLOCK_NAME_SET)) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(clock_node, "Missing `name` attribute in clock class."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(clock_node, "Missing `name` attribute in clock class."); ret = -EPERM; goto end; } @@ -4408,8 +4402,8 @@ static int visit_root_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node visit_field_class_def(ctx, root_decl_node->u.field_class_def.field_class_specifier_list, &root_decl_node->u.field_class_def.field_class_declarators); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(root_decl_node, - "Cannot add field class found in root scope."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(root_decl_node, + "Cannot add field class found in root scope."); goto end; } break; @@ -4417,8 +4411,8 @@ static int visit_root_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node ret = visit_field_class_alias(ctx, root_decl_node->u.field_class_alias.target, root_decl_node->u.field_class_alias.alias); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(root_decl_node, - "Cannot add field class alias found in root scope."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(root_decl_node, + "Cannot add field class alias found in root scope."); goto end; } break; @@ -4432,10 +4426,10 @@ static int visit_root_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node */ ret = visit_field_class_specifier_list(ctx, root_decl_node, &decl); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(root_decl_node, - "Cannot visit root scope's field class: " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(root_decl_node, + "Cannot visit root scope's field class: " + "ret={}", + ret); BT_ASSERT(!decl); goto end; } @@ -4445,8 +4439,8 @@ static int visit_root_decl(struct ctf_visitor_generate_ir *ctx, struct ctf_node break; } default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE(root_decl_node, "Unexpected node type: node-type=%d", - root_decl_node->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(root_decl_node, "Unexpected node type: node-type={}", + root_decl_node->type); ret = -EPERM; goto end; } @@ -4460,11 +4454,12 @@ ctf_visitor_generate_ir_create(const struct ctf_metadata_decoder_config *decoder { struct ctf_visitor_generate_ir *ctx = NULL; + bt2c::Logger logger {decoder_config->logger, "PLUGIN/CTF/META/IR-VISITOR"}; + /* Create visitor's context */ - ctx = ctx_create(decoder_config); + ctx = ctx_create(decoder_config, logger); if (!ctx) { - BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, decoder_config->log_level, decoder_config->self_comp, - "Cannot create visitor's context."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot create visitor's context."); goto error; } @@ -4506,7 +4501,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru { int ret = 0; - BT_COMP_LOGI_STR("Visiting metadata's AST to generate CTF IR objects."); + BT_CPPLOGI_STR_SPEC(ctx->logger, "Visiting metadata's AST to generate CTF IR objects."); switch (node->type) { case NODE_ROOT: @@ -4524,17 +4519,17 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru if (ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_UNKNOWN) { bt_list_for_each_entry (iter, &node->u.root.trace, siblings) { if (got_trace_decl) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Duplicate trace (`trace` block)."); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Duplicate trace (`trace` block)."); ret = -1; goto end; } ret = set_trace_byte_order(ctx, iter); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, - "Cannot set trace's native byte order: " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, + "Cannot set trace's native byte order: " + "ret={}", + ret); goto end; } @@ -4542,7 +4537,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru } if (!got_trace_decl) { - BT_COMP_LOGD_STR("Incomplete AST: need trace (`trace` block)."); + BT_CPPLOGD_STR_SPEC(ctx->logger, "Incomplete AST: need trace (`trace` block)."); ret = -EINCOMPLETE; goto end; } @@ -4556,10 +4551,10 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru bt_list_for_each_entry (iter, &node->u.root.env, siblings) { ret = visit_env(ctx, iter); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE( + _BT_CPPLOGE_APPEND_CAUSE_NODE( iter, "Cannot visit trace's environment (`env` block) entry: " - "ret=%d", + "ret={}", ret); goto end; } @@ -4573,7 +4568,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru bt_list_for_each_entry (iter, &node->u.root.clock, siblings) { ret = visit_clock_decl(ctx, iter); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, "Cannot visit clock class: ret=%d", ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, "Cannot visit clock class: ret={}", ret); goto end; } } @@ -4587,7 +4582,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru bt_list_for_each_entry (iter, &node->u.root.declaration_list, siblings) { ret = visit_root_decl(ctx, iter); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, "Cannot visit root entry: ret=%d", ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, "Cannot visit root entry: ret={}", ret); goto end; } } @@ -4596,7 +4591,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru /* Callsite blocks are not supported */ bt_list_for_each_entry (iter, &node->u.root.callsite, siblings) { - _BT_COMP_LOGW_NODE(iter, "\"callsite\" blocks are not supported as of this version."); + _BT_CPPLOGW_NODE(iter, "\"callsite\" blocks are not supported as of this version."); } BT_ASSERT(ctx->current_scope && !ctx->current_scope->parent_scope); @@ -4605,10 +4600,10 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru bt_list_for_each_entry (iter, &node->u.root.trace, siblings) { ret = visit_trace_decl(ctx, iter); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, - "Cannot visit trace (`trace` block): " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, + "Cannot visit trace (`trace` block): " + "ret={}", + ret); goto end; } } @@ -4619,7 +4614,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru bt_list_for_each_entry (iter, &node->u.root.stream, siblings) { ret = visit_stream_decl(ctx, iter); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, "Cannot visit stream class: ret=%d", ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, "Cannot visit stream class: ret={}", ret); goto end; } } @@ -4630,7 +4625,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru bt_list_for_each_entry (iter, &node->u.root.event, siblings) { ret = visit_event_decl(ctx, iter); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, "Cannot visit event class: ret=%d", ret); + _BT_CPPLOGE_APPEND_CAUSE_NODE(iter, "Cannot visit event class: ret={}", ret); goto end; } } @@ -4639,13 +4634,13 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru break; } default: - _BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Unexpected node type: node-type=%d", node->type); + _BT_CPPLOGE_APPEND_CAUSE_NODE(node, "Unexpected node type: node-type={}", node->type); ret = -EINVAL; goto end; } /* Update default clock classes */ - ret = ctf_trace_class_update_default_clock_classes(ctx->ctf_tc, &ctx->log_cfg); + ret = ctf_trace_class_update_default_clock_classes(ctx->ctf_tc, ctx->logger); if (ret) { ret = -EINVAL; goto end; @@ -4680,7 +4675,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru } /* Resolve sequence lengths and variant tags */ - ret = ctf_trace_class_resolve_field_classes(ctx->ctf_tc, &ctx->log_cfg); + ret = ctf_trace_class_resolve_field_classes(ctx->ctf_tc, ctx->logger); if (ret) { ret = -EINVAL; goto end; @@ -4709,7 +4704,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru } /* Validate what we have so far */ - ret = ctf_trace_class_validate(ctx->ctf_tc, &ctx->log_cfg); + ret = ctf_trace_class_validate(ctx->ctf_tc, ctx->logger); if (ret) { ret = -EINVAL; goto end; @@ -4720,11 +4715,12 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *ctx, stru * itself in the packet header and in event header field * classes, warn about it because they are never translated. */ - ctf_trace_class_warn_meaningless_header_fields(ctx->ctf_tc, &ctx->log_cfg); + ctf_trace_class_warn_meaningless_header_fields(ctx->ctf_tc, ctx->logger); if (ctx->trace_class) { /* Copy new CTF metadata -> new IR metadata */ - ret = ctf_trace_class_translate(ctx->log_cfg.self_comp, ctx->trace_class, ctx->ctf_tc); + ret = + ctf_trace_class_translate(ctx->decoder_config.self_comp, ctx->trace_class, ctx->ctf_tc); if (ret) { ret = -EINVAL; goto end; diff --git a/src/plugins/ctf/common/src/metadata/tsdl/visitor-parent-links.cpp b/src/plugins/ctf/common/src/metadata/tsdl/visitor-parent-links.cpp index 84c504f9..90faaee0 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/visitor-parent-links.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/visitor-parent-links.cpp @@ -7,10 +7,8 @@ */ #include +#include -#define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp) -#define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level) -#define BT_LOG_TAG "PLUGIN/CTF/META/PARENT-LINKS-VISITOR" #include "logging.hpp" #include "common/list.h" @@ -18,7 +16,7 @@ #include "ast.hpp" static int ctf_visitor_unary_expression(int depth, struct ctf_node *node, - struct meta_log_config *log_cfg) + const bt2c::Logger& logger) { int ret = 0; @@ -29,8 +27,9 @@ static int ctf_visitor_unary_expression(int depth, struct ctf_node *node, case UNARY_DOTDOTDOT: break; default: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, "Unknown expression link type: type=%d\n", - node->u.unary_expression.link); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Unknown expression link type: type={}\n", + (int) node->u.unary_expression.link); return -EINVAL; } @@ -41,23 +40,22 @@ static int ctf_visitor_unary_expression(int depth, struct ctf_node *node, break; case UNARY_SBRAC: node->u.unary_expression.u.sbrac_exp->parent = node; - ret = - ctf_visitor_unary_expression(depth + 1, node->u.unary_expression.u.sbrac_exp, log_cfg); + ret = ctf_visitor_unary_expression(depth + 1, node->u.unary_expression.u.sbrac_exp, logger); if (ret) return ret; break; case UNARY_UNKNOWN: default: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, "Unknown expression link type: type=%d\n", - node->u.unary_expression.link); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Unknown expression link type: type={}\n", + (int) node->u.unary_expression.link); return -EINVAL; } return 0; } -static int ctf_visitor_type_specifier(int depth, struct ctf_node *node, - struct meta_log_config *log_cfg) +static int ctf_visitor_type_specifier(int depth, struct ctf_node *node, const bt2c::Logger& logger) { int ret; @@ -84,22 +82,22 @@ static int ctf_visitor_type_specifier(int depth, struct ctf_node *node, case TYPESPEC_VARIANT: case TYPESPEC_ENUM: node->u.field_class_specifier.node->parent = node; - ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_specifier.node, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_specifier.node, logger); if (ret) return ret; break; case TYPESPEC_UNKNOWN: default: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, "Unknown type specifier: type=%d\n", - node->u.field_class_specifier.type); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, "Unknown type specifier: type={}\n", + (int) node->u.field_class_specifier.type); return -EINVAL; } return 0; } static int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, - struct meta_log_config *log_cfg) + const bt2c::Logger& logger) { int ret = 0; struct ctf_node *iter; @@ -108,7 +106,7 @@ static int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, bt_list_for_each_entry (iter, &node->u.field_class_declarator.pointers, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -120,7 +118,7 @@ static int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, if (node->u.field_class_declarator.u.nested.field_class_declarator) { node->u.field_class_declarator.u.nested.field_class_declarator->parent = node; ret = ctf_visitor_parent_links( - depth + 1, node->u.field_class_declarator.u.nested.field_class_declarator, log_cfg); + depth + 1, node->u.field_class_declarator.u.nested.field_class_declarator, logger); if (ret) return ret; } @@ -128,7 +126,7 @@ static int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, bt_list_for_each_entry (iter, &node->u.field_class_declarator.u.nested.length, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -136,22 +134,22 @@ static int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, if (node->u.field_class_declarator.bitfield_len) { node->u.field_class_declarator.bitfield_len = node; ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_declarator.bitfield_len, - log_cfg); + logger); if (ret) return ret; } break; case TYPEDEC_UNKNOWN: default: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, "Unknown type declarator: type=%d\n", - node->u.field_class_declarator.type); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, "Unknown type declarator: type={}\n", + (int) node->u.field_class_declarator.type); return -EINVAL; } depth--; return 0; } -int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_config *log_cfg) +int ctf_visitor_parent_links(int depth, struct ctf_node *node, const bt2c::Logger& parentLogger) { int ret = 0; struct ctf_node *iter; @@ -159,41 +157,43 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c if (node->visited) return 0; + bt2c::Logger logger {parentLogger, "PLUGIN/CTF/META/PARENT-LINKS-VISITOR"}; + switch (node->type) { case NODE_ROOT: bt_list_for_each_entry (iter, &node->u.root.declaration_list, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u.root.trace, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u.root.stream, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u.root.event, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u.root.clock, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u.root.callsite, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -202,7 +202,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_EVENT: bt_list_for_each_entry (iter, &node->u.event.declaration_list, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -210,7 +210,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_STREAM: bt_list_for_each_entry (iter, &node->u.stream.declaration_list, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -218,7 +218,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_ENV: bt_list_for_each_entry (iter, &node->u.env.declaration_list, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -226,7 +226,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_TRACE: bt_list_for_each_entry (iter, &node->u.trace.declaration_list, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -234,7 +234,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_CLOCK: bt_list_for_each_entry (iter, &node->u.clock.declaration_list, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -242,7 +242,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_CALLSITE: bt_list_for_each_entry (iter, &node->u.callsite.declaration_list, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -252,31 +252,31 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c depth++; bt_list_for_each_entry (iter, &node->u.ctf_expression.left, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u.ctf_expression.right, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } depth--; break; case NODE_UNARY_EXPRESSION: - return ctf_visitor_unary_expression(depth, node, log_cfg); + return ctf_visitor_unary_expression(depth, node, logger); case NODE_TYPEDEF: depth++; node->u.field_class_def.field_class_specifier_list->parent = node; ret = ctf_visitor_parent_links(depth + 1, - node->u.field_class_def.field_class_specifier_list, log_cfg); + node->u.field_class_def.field_class_specifier_list, logger); if (ret) return ret; bt_list_for_each_entry (iter, &node->u.field_class_def.field_class_declarators, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -286,13 +286,13 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c depth++; node->u.field_class_alias_target.field_class_specifier_list->parent = node; ret = ctf_visitor_parent_links( - depth + 1, node->u.field_class_alias_target.field_class_specifier_list, log_cfg); + depth + 1, node->u.field_class_alias_target.field_class_specifier_list, logger); if (ret) return ret; bt_list_for_each_entry (iter, &node->u.field_class_alias_target.field_class_declarators, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -302,13 +302,13 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c depth++; node->u.field_class_alias_name.field_class_specifier_list->parent = node; ret = ctf_visitor_parent_links( - depth + 1, node->u.field_class_alias_name.field_class_specifier_list, log_cfg); + depth + 1, node->u.field_class_alias_name.field_class_specifier_list, logger); if (ret) return ret; bt_list_for_each_entry (iter, &node->u.field_class_alias_name.field_class_declarators, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -316,11 +316,11 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c break; case NODE_TYPEALIAS: node->u.field_class_alias.target->parent = node; - ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_alias.target, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_alias.target, logger); if (ret) return ret; node->u.field_class_alias.alias->parent = node; - ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_alias.alias, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_alias.alias, logger); if (ret) return ret; break; @@ -328,21 +328,21 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_TYPE_SPECIFIER_LIST: bt_list_for_each_entry (iter, &node->u.field_class_specifier_list.head, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } break; case NODE_TYPE_SPECIFIER: - ret = ctf_visitor_type_specifier(depth, node, log_cfg); + ret = ctf_visitor_type_specifier(depth, node, logger); if (ret) return ret; break; case NODE_POINTER: break; case NODE_TYPE_DECLARATOR: - ret = ctf_visitor_field_class_declarator(depth, node, log_cfg); + ret = ctf_visitor_field_class_declarator(depth, node, logger); if (ret) return ret; break; @@ -350,7 +350,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_FLOATING_POINT: bt_list_for_each_entry (iter, &node->u.floating_point.expressions, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -358,7 +358,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_INTEGER: bt_list_for_each_entry (iter, &node->u.integer.expressions, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -366,7 +366,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_STRING: bt_list_for_each_entry (iter, &node->u.string.expressions, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -374,7 +374,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_ENUMERATOR: bt_list_for_each_entry (iter, &node->u.enumerator.values, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -382,14 +382,14 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_ENUM: depth++; if (node->u._enum.container_field_class) { - ret = ctf_visitor_parent_links(depth + 1, node->u._enum.container_field_class, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, node->u._enum.container_field_class, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u._enum.enumerator_list, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -398,13 +398,13 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_STRUCT_OR_VARIANT_DECLARATION: node->u.struct_or_variant_declaration.field_class_specifier_list->parent = node; ret = ctf_visitor_parent_links( - depth + 1, node->u.struct_or_variant_declaration.field_class_specifier_list, log_cfg); + depth + 1, node->u.struct_or_variant_declaration.field_class_specifier_list, logger); if (ret) return ret; bt_list_for_each_entry ( iter, &node->u.struct_or_variant_declaration.field_class_declarators, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -412,7 +412,7 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_VARIANT: bt_list_for_each_entry (iter, &node->u.variant.declaration_list, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -420,13 +420,13 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_STRUCT: bt_list_for_each_entry (iter, &node->u._struct.declaration_list, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u._struct.min_align, siblings) { iter->parent = node; - ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); + ret = ctf_visitor_parent_links(depth + 1, iter, logger); if (ret) return ret; } @@ -434,7 +434,8 @@ int ctf_visitor_parent_links(int depth, struct ctf_node *node, struct meta_log_c case NODE_UNKNOWN: default: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, "Unknown node type: type=%d\n", node->type); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, "Unknown node type: type={}\n", + (int) node->type); return -EINVAL; } return ret; diff --git a/src/plugins/ctf/common/src/metadata/tsdl/visitor-semantic-validator.cpp b/src/plugins/ctf/common/src/metadata/tsdl/visitor-semantic-validator.cpp index 4fad1360..59cec938 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/visitor-semantic-validator.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/visitor-semantic-validator.cpp @@ -7,10 +7,8 @@ */ #include +#include -#define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp) -#define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level) -#define BT_LOG_TAG "PLUGIN/CTF/META/SEMANTIC-VALIDATOR-VISITOR" #include "logging.hpp" #include "common/list.h" @@ -20,9 +18,9 @@ #define _bt_list_first_entry(ptr, type, member) bt_list_entry((ptr)->next, type, member) static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, - struct meta_log_config *log_cfg); + const bt2c::Logger& logger); -static int ctf_visitor_unary_expression(int, struct ctf_node *node, struct meta_log_config *log_cfg) +static int ctf_visitor_unary_expression(int, struct ctf_node *node, const bt2c::Logger& logger) { struct ctf_node *iter; int is_ctf_exp = 0, is_ctf_exp_left = 0; @@ -38,8 +36,8 @@ static int ctf_visitor_unary_expression(int, struct ctf_node *node, struct meta_ * We are only allowed to be a string. */ if (node->u.unary_expression.type != UNARY_STRING) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Left child of a CTF expression is only allowed to be a string."); goto errperm; } @@ -57,8 +55,8 @@ static int ctf_visitor_unary_expression(int, struct ctf_node *node, struct meta_ case UNARY_STRING: break; default: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Children of field class declarator and `enum` can only be unsigned numeric constants or references to fields (e.g., `a.b.c`)."); goto errperm; } @@ -72,8 +70,8 @@ static int ctf_visitor_unary_expression(int, struct ctf_node *node, struct meta_ case UNARY_UNSIGNED_CONSTANT: break; default: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Structure alignment attribute can only be an unsigned numeric constant."); goto errperm; } @@ -88,8 +86,8 @@ static int ctf_visitor_unary_expression(int, struct ctf_node *node, struct meta_ * We disallow nested unary expressions and "sbrac" unary * expressions. */ - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, - "Nested unary expressions not allowed (`()` and `[]`)."); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Nested unary expressions not allowed (`()` and `[]`)."); goto errperm; case NODE_ROOT: @@ -122,8 +120,8 @@ static int ctf_visitor_unary_expression(int, struct ctf_node *node, struct meta_ _bt_list_first_entry(is_ctf_exp_left ? &node->parent->u.ctf_expression.left : &node->parent->u.ctf_expression.right, struct ctf_node, siblings) != node) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Empty link is not allowed except on first node of unary expression (need to separate nodes with `.` or `->`)."); goto errperm; } @@ -132,8 +130,9 @@ static int ctf_visitor_unary_expression(int, struct ctf_node *node, struct meta_ case UNARY_ARROWLINK: /* We only allow -> and . links between children of ctf_expression. */ if (node->parent->type != NODE_CTF_EXPRESSION) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, "Links `.` and `->` are only allowed as children of CTF expression."); + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, + "Links `.` and `->` are only allowed as children of CTF expression."); goto errperm; } /* @@ -141,8 +140,8 @@ static int ctf_visitor_unary_expression(int, struct ctf_node *node, struct meta_ * This includes "", '' and non-quoted identifiers. */ if (node->u.unary_expression.type != UNARY_STRING) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Links `.` and `->` are only allowed to separate strings and identifiers."); goto errperm; } @@ -151,8 +150,8 @@ static int ctf_visitor_unary_expression(int, struct ctf_node *node, struct meta_ _bt_list_first_entry(is_ctf_exp_left ? &node->parent->u.ctf_expression.left : &node->parent->u.ctf_expression.right, struct ctf_node, siblings) == node) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Links `.` and `->` are not allowed before first node of the unary expression list."); goto errperm; } @@ -160,41 +159,42 @@ static int ctf_visitor_unary_expression(int, struct ctf_node *node, struct meta_ case UNARY_DOTDOTDOT: /* We only allow ... link between children of enumerator. */ if (node->parent->type != NODE_ENUMERATOR) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, - "Link `...` is only allowed within enumerator."); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Link `...` is only allowed within enumerator."); goto errperm; } /* We don't allow link on the first node of the list */ if (_bt_list_first_entry(&node->parent->u.enumerator.values, struct ctf_node, siblings) == node) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Link `...` is not allowed on the first node of the unary expression list."); goto errperm; } break; default: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, "Unknown expression link type: type=%d", - node->u.unary_expression.link); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Unknown expression link type: type={}", + (int) node->u.unary_expression.link); return -EINVAL; } return 0; errinval: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, "Incoherent parent node's type: node-type=%s, parent-node-type=%s", + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Incoherent parent node's type: node-type={}, parent-node-type={}", node_type(node), node_type(node->parent)); return -EINVAL; /* Incoherent structure */ errperm: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, - "Semantic error: node-type=%s, parent-node-type=%s", - node_type(node), node_type(node->parent)); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Semantic error: node-type={}, parent-node-type={}", + node_type(node), node_type(node->parent)); return -EPERM; /* Structure not allowed */ } static int ctf_visitor_field_class_specifier_list(int, struct ctf_node *node, - struct meta_log_config *log_cfg) + const bt2c::Logger& logger) { switch (node->parent->type) { case NODE_CTF_EXPRESSION: @@ -229,14 +229,13 @@ static int ctf_visitor_field_class_specifier_list(int, struct ctf_node *node, } return 0; errinval: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, "Incoherent parent node's type: node-type=%s, parent-node-type=%s", + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Incoherent parent node's type: node-type={}, parent-node-type={}", node_type(node), node_type(node->parent)); return -EINVAL; /* Incoherent structure */ } -static int ctf_visitor_field_class_specifier(int, struct ctf_node *node, - struct meta_log_config *log_cfg) +static int ctf_visitor_field_class_specifier(int, struct ctf_node *node, const bt2c::Logger& logger) { switch (node->parent->type) { case NODE_TYPE_SPECIFIER_LIST: @@ -271,14 +270,14 @@ static int ctf_visitor_field_class_specifier(int, struct ctf_node *node, } return 0; errinval: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, "Incoherent parent node's type: node-type=%s, parent-node-type=%s", + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Incoherent parent node's type: node-type={}, parent-node-type={}", node_type(node), node_type(node->parent)); return -EINVAL; /* Incoherent structure */ } static int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, - struct meta_log_config *log_cfg) + const bt2c::Logger& logger) { int ret = 0; struct ctf_node *iter; @@ -360,7 +359,7 @@ static int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, } bt_list_for_each_entry (iter, &node->u.field_class_declarator.pointers, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -372,7 +371,7 @@ static int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, { if (node->u.field_class_declarator.u.nested.field_class_declarator) { ret = _ctf_visitor_semantic_check( - depth + 1, node->u.field_class_declarator.u.nested.field_class_declarator, log_cfg); + depth + 1, node->u.field_class_declarator.u.nested.field_class_declarator, logger); if (ret) return ret; } @@ -380,26 +379,26 @@ static int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, bt_list_for_each_entry (iter, &node->u.field_class_declarator.u.nested.length, siblings) { if (iter->type != NODE_UNARY_EXPRESSION) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, "Expecting unary expression as length: node-type=%s", + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Expecting unary expression as length: node-type={}", node_type(iter)); return -EINVAL; } - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } } else { if (node->parent->type == NODE_TYPEALIAS_TARGET) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Abstract array declarator not permitted as target of field class alias."); return -EINVAL; } } if (node->u.field_class_declarator.bitfield_len) { ret = _ctf_visitor_semantic_check(depth + 1, - node->u.field_class_declarator.bitfield_len, log_cfg); + node->u.field_class_declarator.bitfield_len, logger); if (ret) return ret; } @@ -407,28 +406,28 @@ static int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, } case TYPEDEC_UNKNOWN: default: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, "Unknown field class declarator: type=%d", - node->u.field_class_declarator.type); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Unknown field class declarator: type={}", + (int) node->u.field_class_declarator.type); return -EINVAL; } depth--; return 0; errinval: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, "Incoherent parent node's type: node-type=%s, parent-node-type=%s", + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Incoherent parent node's type: node-type={}, parent-node-type={}", node_type(node), node_type(node->parent)); return -EINVAL; /* Incoherent structure */ errperm: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, - "Semantic error: node-type=%s, parent-node-type=%s", - node_type(node), node_type(node->parent)); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Semantic error: node-type={}, parent-node-type={}", + node_type(node), node_type(node->parent)); return -EPERM; /* Structure not allowed */ } -static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, - struct meta_log_config *log_cfg) +static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, const bt2c::Logger& logger) { int ret = 0; struct ctf_node *iter; @@ -439,22 +438,22 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, switch (node->type) { case NODE_ROOT: bt_list_for_each_entry (iter, &node->u.root.declaration_list, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u.root.trace, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u.root.stream, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u.root.event, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -469,7 +468,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } bt_list_for_each_entry (iter, &node->u.event.declaration_list, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -483,7 +482,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } bt_list_for_each_entry (iter, &node->u.stream.declaration_list, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -497,7 +496,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } bt_list_for_each_entry (iter, &node->u.env.declaration_list, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -511,7 +510,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } bt_list_for_each_entry (iter, &node->u.trace.declaration_list, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -525,7 +524,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } bt_list_for_each_entry (iter, &node->u.clock.declaration_list, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -539,7 +538,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } bt_list_for_each_entry (iter, &node->u.callsite.declaration_list, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -580,19 +579,19 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, depth++; bt_list_for_each_entry (iter, &node->u.ctf_expression.left, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } bt_list_for_each_entry (iter, &node->u.ctf_expression.right, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } depth--; break; case NODE_UNARY_EXPRESSION: - return ctf_visitor_unary_expression(depth, node, log_cfg); + return ctf_visitor_unary_expression(depth, node, logger); case NODE_TYPEDEF: switch (node->parent->type) { @@ -629,11 +628,11 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, depth++; ret = _ctf_visitor_semantic_check( - depth + 1, node->u.field_class_def.field_class_specifier_list, log_cfg); + depth + 1, node->u.field_class_def.field_class_specifier_list, logger); if (ret) return ret; bt_list_for_each_entry (iter, &node->u.field_class_def.field_class_declarators, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -652,21 +651,21 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, depth++; ret = _ctf_visitor_semantic_check( - depth + 1, node->u.field_class_alias_target.field_class_specifier_list, log_cfg); + depth + 1, node->u.field_class_alias_target.field_class_specifier_list, logger); if (ret) return ret; nr_declarators = 0; bt_list_for_each_entry (iter, &node->u.field_class_alias_target.field_class_declarators, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; nr_declarators++; } if (nr_declarators > 1) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, - "Too many declarators in field class alias's name (maximum is 1): count=%d", + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, + "Too many declarators in field class alias's name (maximum is 1): count={}", nr_declarators); return -EINVAL; } @@ -686,21 +685,21 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, depth++; ret = _ctf_visitor_semantic_check( - depth + 1, node->u.field_class_alias_name.field_class_specifier_list, log_cfg); + depth + 1, node->u.field_class_alias_name.field_class_specifier_list, logger); if (ret) return ret; nr_declarators = 0; bt_list_for_each_entry (iter, &node->u.field_class_alias_name.field_class_declarators, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; nr_declarators++; } if (nr_declarators > 1) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, - "Too many declarators in field class alias's name (maximum is 1): count=%d", + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, + "Too many declarators in field class alias's name (maximum is 1): count={}", nr_declarators); return -EINVAL; } @@ -740,21 +739,21 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, goto errinval; } - ret = _ctf_visitor_semantic_check(depth + 1, node->u.field_class_alias.target, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, node->u.field_class_alias.target, logger); if (ret) return ret; - ret = _ctf_visitor_semantic_check(depth + 1, node->u.field_class_alias.alias, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, node->u.field_class_alias.alias, logger); if (ret) return ret; break; case NODE_TYPE_SPECIFIER_LIST: - ret = ctf_visitor_field_class_specifier_list(depth, node, log_cfg); + ret = ctf_visitor_field_class_specifier_list(depth, node, logger); if (ret) return ret; break; case NODE_TYPE_SPECIFIER: - ret = ctf_visitor_field_class_specifier(depth, node, log_cfg); + ret = ctf_visitor_field_class_specifier(depth, node, logger); if (ret) return ret; break; @@ -767,7 +766,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } break; case NODE_TYPE_DECLARATOR: - ret = ctf_visitor_field_class_declarator(depth, node, log_cfg); + ret = ctf_visitor_field_class_declarator(depth, node, logger); if (ret) return ret; break; @@ -783,7 +782,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, goto errperm; } bt_list_for_each_entry (iter, &node->u.floating_point.expressions, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -797,7 +796,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } bt_list_for_each_entry (iter, &node->u.integer.expressions, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -814,7 +813,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } bt_list_for_each_entry (iter, &node->u.string.expressions, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -841,8 +840,9 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, (iter->u.unary_expression.type != UNARY_SIGNED_CONSTANT && iter->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) || iter->u.unary_expression.link != UNARY_LINK_UNKNOWN) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - iter->lineno, "First unary expression of enumerator is unexpected."); + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, iter->lineno, + "First unary expression of enumerator is unexpected."); goto errperm; } break; @@ -851,8 +851,9 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, (iter->u.unary_expression.type != UNARY_SIGNED_CONSTANT && iter->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) || iter->u.unary_expression.link != UNARY_DOTDOTDOT) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - iter->lineno, "Second unary expression of enumerator is unexpected."); + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, iter->lineno, + "Second unary expression of enumerator is unexpected."); goto errperm; } break; @@ -863,7 +864,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } bt_list_for_each_entry (iter, &node->u.enumerator.values, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -880,12 +881,12 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, } depth++; - ret = _ctf_visitor_semantic_check(depth + 1, node->u._enum.container_field_class, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, node->u._enum.container_field_class, logger); if (ret) return ret; bt_list_for_each_entry (iter, &node->u._enum.enumerator_list, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -900,12 +901,12 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, goto errinval; } ret = _ctf_visitor_semantic_check( - depth + 1, node->u.struct_or_variant_declaration.field_class_specifier_list, log_cfg); + depth + 1, node->u.struct_or_variant_declaration.field_class_specifier_list, logger); if (ret) return ret; bt_list_for_each_entry ( iter, &node->u.struct_or_variant_declaration.field_class_declarators, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -921,7 +922,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, goto errperm; } bt_list_for_each_entry (iter, &node->u.variant.declaration_list, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -938,7 +939,7 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, goto errperm; } bt_list_for_each_entry (iter, &node->u._struct.declaration_list, siblings) { - ret = _ctf_visitor_semantic_check(depth + 1, iter, log_cfg); + ret = _ctf_visitor_semantic_check(depth + 1, iter, logger); if (ret) return ret; } @@ -946,48 +947,50 @@ static int _ctf_visitor_semantic_check(int depth, struct ctf_node *node, case NODE_UNKNOWN: default: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, "Unknown node type: type=%d", node->type); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, "Unknown node type: type={}", + (int) node->type); return -EINVAL; } return ret; errinval: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO( - node->lineno, "Incoherent parent node's type: node-type=%s, parent-node-type=%s", + _BT_CPPLOGE_APPEND_CAUSE_LINENO( + logger, node->lineno, "Incoherent parent node's type: node-type={}, parent-node-type={}", node_type(node), node_type(node->parent)); return -EINVAL; /* Incoherent structure */ errperm: - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, - "Semantic error: node-type=%s, parent-node-type=%s", - node_type(node), node_type(node->parent)); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Semantic error: node-type={}, parent-node-type={}", + node_type(node), node_type(node->parent)); return -EPERM; /* Structure not allowed */ } -int ctf_visitor_semantic_check(int depth, struct ctf_node *node, struct meta_log_config *log_cfg) +int ctf_visitor_semantic_check(int depth, struct ctf_node *node, const bt2c::Logger& parentLogger) { int ret = 0; + bt2c::Logger logger {parentLogger, "PLUGIN/CTF/META/SEMANTIC-VALIDATOR-VISITOR"}; /* * First make sure we create the parent links for all children. Let's * take the safe route and recreate them at each validation, just in * case the structure has changed. */ - ret = ctf_visitor_parent_links(depth, node, log_cfg); + ret = ctf_visitor_parent_links(depth, node, logger); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, - "Cannot create parent links in metadata's AST: " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Cannot create parent links in metadata's AST: " + "ret={}", + ret); goto end; } - ret = _ctf_visitor_semantic_check(depth, node, log_cfg); + ret = _ctf_visitor_semantic_check(depth, node, logger); if (ret) { - _BT_COMP_LOGE_APPEND_CAUSE_LINENO(node->lineno, - "Cannot check metadata's AST semantics: " - "ret=%d", - ret); + _BT_CPPLOGE_APPEND_CAUSE_LINENO(logger, node->lineno, + "Cannot check metadata's AST semantics: " + "ret={}", + ret); goto end; } diff --git a/src/plugins/ctf/common/src/msg-iter/msg-iter.cpp b/src/plugins/ctf/common/src/msg-iter/msg-iter.cpp index 311affd8..ea9a2472 100644 --- a/src/plugins/ctf/common/src/msg-iter/msg-iter.cpp +++ b/src/plugins/ctf/common/src/msg-iter/msg-iter.cpp @@ -7,21 +7,15 @@ * Babeltrace - CTF message iterator */ -#include -#include #include #include #include -#include - -#define BT_COMP_LOG_SELF_COMP (msg_it->self_comp) -#define BT_LOG_OUTPUT_LEVEL (msg_it->log_level) -#define BT_LOG_TAG "PLUGIN/CTF/MSG-ITER" -#include "logging/comp-logging.h" - #include "common/assert.h" #include "common/common.h" +#include "cpp-common/bt2c/fmt.hpp" +#include "cpp-common/bt2c/logging.hpp" +#include "cpp-common/vendor/fmt/format.h" #include "../bfcr/bfcr.hpp" #include "msg-iter.hpp" @@ -95,6 +89,109 @@ enum state STATE_DONE, }; +static __attribute__((used)) const char *format_as(state state) +{ + switch (state) { + case STATE_INIT: + return "STATE_INIT"; + + case STATE_SWITCH_PACKET: + return "STATE_SWITCH_PACKET"; + + case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN: + return "STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN"; + + case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE: + return "STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE"; + + case STATE_AFTER_TRACE_PACKET_HEADER: + return "STATE_AFTER_TRACE_PACKET_HEADER"; + + case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN: + return "STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN"; + + case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE: + return "STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE"; + + case STATE_AFTER_STREAM_PACKET_CONTEXT: + return "STATE_AFTER_STREAM_PACKET_CONTEXT"; + + case STATE_EMIT_MSG_STREAM_BEGINNING: + return "STATE_EMIT_MSG_STREAM_BEGINNING"; + + case STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS: + return "STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS"; + + case STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS: + return "STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS"; + + case STATE_EMIT_MSG_DISCARDED_EVENTS: + return "STATE_EMIT_MSG_DISCARDED_EVENTS"; + + case STATE_EMIT_MSG_DISCARDED_PACKETS: + return "STATE_EMIT_MSG_DISCARDED_PACKETS"; + + case STATE_EMIT_MSG_PACKET_BEGINNING: + return "STATE_EMIT_MSG_PACKET_BEGINNING"; + + case STATE_DSCOPE_EVENT_HEADER_BEGIN: + return "STATE_DSCOPE_EVENT_HEADER_BEGIN"; + + case STATE_DSCOPE_EVENT_HEADER_CONTINUE: + return "STATE_DSCOPE_EVENT_HEADER_CONTINUE"; + + case STATE_AFTER_EVENT_HEADER: + return "STATE_AFTER_EVENT_HEADER"; + + case STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN: + return "STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN"; + + case STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE: + return "STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE"; + + case STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN: + return "STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN"; + + case STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE: + return "STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE"; + + case STATE_DSCOPE_EVENT_PAYLOAD_BEGIN: + return "STATE_DSCOPE_EVENT_PAYLOAD_BEGIN"; + + case STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE: + return "STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE"; + + case STATE_EMIT_MSG_EVENT: + return "STATE_EMIT_MSG_EVENT"; + + case STATE_EMIT_QUEUED_MSG_EVENT: + return "STATE_EMIT_QUEUED_MSG_EVENT"; + + case STATE_SKIP_PACKET_PADDING: + return "STATE_SKIP_PACKET_PADDING"; + + case STATE_EMIT_MSG_PACKET_END_MULTI: + return "STATE_EMIT_MSG_PACKET_END_MULTI"; + + case STATE_EMIT_MSG_PACKET_END_SINGLE: + return "STATE_EMIT_MSG_PACKET_END_SINGLE"; + + case STATE_EMIT_QUEUED_MSG_PACKET_END: + return "STATE_EMIT_QUEUED_MSG_PACKET_END"; + + case STATE_CHECK_EMIT_MSG_STREAM_END: + return "STATE_CHECK_EMIT_MSG_STREAM_END"; + + case STATE_EMIT_MSG_STREAM_END: + return "STATE_EMIT_MSG_STREAM_END"; + + case STATE_DONE: + return "STATE_DONE"; + } + + bt_common_abort(); +} + struct end_of_packet_snapshots { uint64_t discarded_events = 0; @@ -106,6 +203,10 @@ struct end_of_packet_snapshots /* CTF message iterator */ struct ctf_msg_iter { + explicit ctf_msg_iter(bt2c::Logger loggerParam) noexcept : logger {std::move(loggerParam)} + { + } + /* Visit stack */ struct stack *stack = nullptr; @@ -250,104 +351,28 @@ struct ctf_msg_iter /* Stored values (for sequence lengths, variant tags) */ GArray *stored_values = nullptr; - /* Iterator's current log level */ - bt_logging_level log_level = (bt_logging_level) 0; - - /* Iterator's owning self component, or `NULL` if none (query) */ - bt_self_component *self_comp = nullptr; + bt2c::Logger logger; }; -static inline const char *state_string(enum state state) -{ - switch (state) { - case STATE_INIT: - return "INIT"; - case STATE_SWITCH_PACKET: - return "SWITCH_PACKET"; - case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN: - return "DSCOPE_TRACE_PACKET_HEADER_BEGIN"; - case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE: - return "DSCOPE_TRACE_PACKET_HEADER_CONTINUE"; - case STATE_AFTER_TRACE_PACKET_HEADER: - return "AFTER_TRACE_PACKET_HEADER"; - case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN: - return "DSCOPE_STREAM_PACKET_CONTEXT_BEGIN"; - case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE: - return "DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE"; - case STATE_AFTER_STREAM_PACKET_CONTEXT: - return "AFTER_STREAM_PACKET_CONTEXT"; - case STATE_EMIT_MSG_STREAM_BEGINNING: - return "EMIT_MSG_STREAM_BEGINNING"; - case STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS: - return "CHECK_EMIT_MSG_DISCARDED_EVENTS"; - case STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS: - return "CHECK_EMIT_MSG_DISCARDED_PACKETS"; - case STATE_EMIT_MSG_PACKET_BEGINNING: - return "EMIT_MSG_PACKET_BEGINNING"; - case STATE_EMIT_MSG_DISCARDED_EVENTS: - return "EMIT_MSG_DISCARDED_EVENTS"; - case STATE_EMIT_MSG_DISCARDED_PACKETS: - return "EMIT_MSG_DISCARDED_PACKETS"; - case STATE_DSCOPE_EVENT_HEADER_BEGIN: - return "DSCOPE_EVENT_HEADER_BEGIN"; - case STATE_DSCOPE_EVENT_HEADER_CONTINUE: - return "DSCOPE_EVENT_HEADER_CONTINUE"; - case STATE_AFTER_EVENT_HEADER: - return "AFTER_EVENT_HEADER"; - case STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN: - return "DSCOPE_EVENT_COMMON_CONTEXT_BEGIN"; - case STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE: - return "DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE"; - case STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN: - return "DSCOPE_EVENT_SPEC_CONTEXT_BEGIN"; - case STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE: - return "DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE"; - case STATE_DSCOPE_EVENT_PAYLOAD_BEGIN: - return "DSCOPE_EVENT_PAYLOAD_BEGIN"; - case STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE: - return "DSCOPE_EVENT_PAYLOAD_CONTINUE"; - case STATE_EMIT_MSG_EVENT: - return "EMIT_MSG_EVENT"; - case STATE_EMIT_QUEUED_MSG_EVENT: - return "EMIT_QUEUED_MSG_EVENT"; - case STATE_SKIP_PACKET_PADDING: - return "SKIP_PACKET_PADDING"; - case STATE_EMIT_MSG_PACKET_END_MULTI: - return "EMIT_MSG_PACKET_END_MULTI"; - case STATE_EMIT_MSG_PACKET_END_SINGLE: - return "EMIT_MSG_PACKET_END_SINGLE"; - case STATE_EMIT_QUEUED_MSG_PACKET_END: - return "EMIT_QUEUED_MSG_PACKET_END"; - case STATE_CHECK_EMIT_MSG_STREAM_END: - return "CHECK_EMIT_MSG_STREAM_END"; - case STATE_EMIT_MSG_STREAM_END: - return "EMIT_MSG_STREAM_END"; - case STATE_DONE: - return "DONE"; - } - - bt_common_abort(); -} - static struct stack *stack_new(struct ctf_msg_iter *msg_it) { - bt_self_component *self_comp = msg_it->self_comp; struct stack *stack = NULL; stack = g_new0(struct stack, 1); if (!stack) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to allocate one stack."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, "Failed to allocate one stack."); goto error; } stack->msg_it = msg_it; stack->entries = g_array_new(FALSE, TRUE, sizeof(struct stack_entry)); if (!stack->entries) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to allocate a GArray."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, "Failed to allocate a GArray."); goto error; } - BT_COMP_LOGD("Created stack: msg-it-addr=%p, stack-addr=%p", msg_it, stack); + BT_CPPLOGD_SPEC(msg_it->logger, "Created stack: msg-it-addr={}, stack-addr={}", + fmt::ptr(msg_it), fmt::ptr(stack)); goto end; error: @@ -364,7 +389,7 @@ static void stack_destroy(struct stack *stack) BT_ASSERT_DBG(stack); msg_it = stack->msg_it; - BT_COMP_LOGD("Destroying stack: addr=%p", stack); + BT_CPPLOGD_SPEC(msg_it->logger, "Destroying stack: addr={}", fmt::ptr(stack)); if (stack->entries) { g_array_free(stack->entries, TRUE); @@ -381,9 +406,10 @@ static void stack_push(struct stack *stack, bt_field *base) BT_ASSERT_DBG(stack); msg_it = stack->msg_it; BT_ASSERT_DBG(base); - BT_COMP_LOGT("Pushing base field on stack: stack-addr=%p, " - "stack-size-before=%zu, stack-size-after=%zu", - stack, stack->size, stack->size + 1); + BT_CPPLOGT_SPEC(msg_it->logger, + "Pushing base field on stack: stack-addr={}, " + "stack-size-before={}, stack-size-after={}", + fmt::ptr(stack), stack->size, stack->size + 1); if (stack->entries->len == stack->size) { g_array_set_size(stack->entries, stack->size + 1); @@ -408,9 +434,10 @@ static void stack_pop(struct stack *stack) BT_ASSERT_DBG(stack); BT_ASSERT_DBG(stack_size(stack)); msg_it = stack->msg_it; - BT_COMP_LOGT("Popping from stack: " - "stack-addr=%p, stack-size-before=%zu, stack-size-after=%zu", - stack, stack->size, stack->size - 1); + BT_CPPLOGT_SPEC(msg_it->logger, + "Popping from stack: " + "stack-addr={}, stack-size-before={}, stack-size-after={}", + fmt::ptr(stack), stack->size, stack->size - 1); stack->size--; } @@ -456,25 +483,25 @@ static inline size_t packet_at(struct ctf_msg_iter *msg_it) static inline void buf_consume_bits(struct ctf_msg_iter *msg_it, size_t incr) { - BT_COMP_LOGT("Advancing cursor: msg-it-addr=%p, cur-before=%zu, cur-after=%zu", msg_it, - msg_it->buf.at, msg_it->buf.at + incr); + BT_CPPLOGT_SPEC(msg_it->logger, "Advancing cursor: msg-it-addr={}, cur-before={}, cur-after={}", + fmt::ptr(msg_it), msg_it->buf.at, msg_it->buf.at + incr); msg_it->buf.at += incr; } static enum ctf_msg_iter_status request_medium_bytes(struct ctf_msg_iter *msg_it) { - bt_self_component *self_comp = msg_it->self_comp; uint8_t *buffer_addr = NULL; size_t buffer_sz = 0; enum ctf_msg_iter_medium_status m_status; - BT_COMP_LOGD("Calling user function (request bytes): msg-it-addr=%p, " - "request-size=%zu", - msg_it, msg_it->medium.max_request_sz); + BT_CPPLOGD_SPEC(msg_it->logger, + "Calling user function (request bytes): msg-it-addr={}, " + "request-size={}", + fmt::ptr(msg_it), msg_it->medium.max_request_sz); m_status = msg_it->medium.medops.request_bytes(msg_it->medium.max_request_sz, &buffer_addr, &buffer_sz, msg_it->medium.data); - BT_COMP_LOGD("User function returned: status=%s, buf-addr=%p, buf-size=%zu", - ctf_msg_iter_medium_status_string(m_status), buffer_addr, buffer_sz); + BT_CPPLOGD_SPEC(msg_it->logger, "User function returned: status={}, buf-addr={}, buf-size={}", + m_status, fmt::ptr(buffer_addr), buffer_sz); if (m_status == CTF_MSG_ITER_MEDIUM_STATUS_OK) { BT_ASSERT(buffer_sz != 0); @@ -491,10 +518,13 @@ static enum ctf_msg_iter_status request_medium_bytes(struct ctf_msg_iter *msg_it /* New medium buffer address */ msg_it->buf.addr = buffer_addr; - BT_COMP_LOGD("User function returned new bytes: " - "packet-offset=%zu, cur=%zu, size=%zu, addr=%p", - msg_it->buf.packet_offset, msg_it->buf.at, msg_it->buf.sz, msg_it->buf.addr); - BT_COMP_LOGT_MEM(buffer_addr, buffer_sz, "Returned bytes at %p:", buffer_addr); + BT_CPPLOGD_SPEC(msg_it->logger, + "User function returned new bytes: " + "packet-offset={}, cur={}, size={}, addr={}", + msg_it->buf.packet_offset, msg_it->buf.at, msg_it->buf.sz, + fmt::ptr(msg_it->buf.addr)); + BT_CPPLOGT_MEM_SPEC(msg_it->logger, buffer_addr, buffer_sz, + "Returned bytes at {}:", fmt::ptr(buffer_addr)); } else if (m_status == CTF_MSG_ITER_MEDIUM_STATUS_EOF) { /* * User returned end of stream: validate that we're not @@ -516,20 +546,19 @@ static enum ctf_msg_iter_status request_medium_bytes(struct ctf_msg_iter *msg_it } /* All other states are invalid */ - BT_COMP_LOGE_APPEND_CAUSE( - self_comp, - "User function returned %s, but message iterator is in an unexpected state: " - "state=%s, cur-packet-size=%" PRId64 ", cur=%zu, " - "packet-cur=%zu, last-eh-at=%zu", - ctf_msg_iter_medium_status_string(m_status), state_string(msg_it->state), - msg_it->cur_exp_packet_total_size, msg_it->buf.at, packet_at(msg_it), - msg_it->buf.last_eh_at); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + msg_it->logger, + "User function returned {}, but message iterator is in an unexpected state: " + "state={}, cur-packet-size={}, cur={}, " + "packet-cur={}, last-eh-at={}", + m_status, msg_it->state, msg_it->cur_exp_packet_total_size, msg_it->buf.at, + packet_at(msg_it), msg_it->buf.last_eh_at); m_status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR; } else if (m_status < 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "User function failed: " - "status=%s", - ctf_msg_iter_medium_status_string(m_status)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "User function failed: " + "status={}", + m_status); } end: @@ -556,32 +585,31 @@ read_dscope_begin_state(struct ctf_msg_iter *msg_it, struct ctf_field_class *dsc enum state done_state, enum state continue_state, bt_field *dscope_field) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; enum bt_bfcr_status bfcr_status; size_t consumed_bits; msg_it->cur_dscope_field = dscope_field; - BT_COMP_LOGT("Starting BFCR: msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p", msg_it, msg_it->bfcr, - dscope_fc); + BT_CPPLOGT_SPEC(msg_it->logger, "Starting BFCR: msg-it-addr={}, bfcr-addr={}, fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), fmt::ptr(dscope_fc)); consumed_bits = bt_bfcr_start(msg_it->bfcr, dscope_fc, msg_it->buf.addr, msg_it->buf.at, packet_at(msg_it), msg_it->buf.sz, &bfcr_status); - BT_COMP_LOGT("BFCR consumed bits: size=%zu", consumed_bits); + BT_CPPLOGT_SPEC(msg_it->logger, "BFCR consumed bits: size={}", consumed_bits); switch (bfcr_status) { case BT_BFCR_STATUS_OK: /* Field class was read completely */ - BT_COMP_LOGT_STR("Field was completely decoded."); + BT_CPPLOGT_STR_SPEC(msg_it->logger, "Field was completely decoded."); msg_it->state = done_state; break; case BT_BFCR_STATUS_EOF: - BT_COMP_LOGT_STR("BFCR needs more data to decode field completely."); + BT_CPPLOGT_STR_SPEC(msg_it->logger, "BFCR needs more data to decode field completely."); msg_it->state = continue_state; break; default: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "BFCR failed to start: msg-it-addr=%p, bfcr-addr=%p, " - "status=%s", - msg_it, msg_it->bfcr, bt_bfcr_status_string(bfcr_status)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "BFCR failed to start: msg-it-addr={}, bfcr-addr={}, " + "status={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), bfcr_status); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } @@ -597,46 +625,47 @@ static enum ctf_msg_iter_status read_dscope_continue_state(struct ctf_msg_iter * enum state done_state) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; enum bt_bfcr_status bfcr_status; size_t consumed_bits; - BT_COMP_LOGT("Continuing BFCR: msg-it-addr=%p, bfcr-addr=%p", msg_it, msg_it->bfcr); + BT_CPPLOGT_SPEC(msg_it->logger, "Continuing BFCR: msg-it-addr={}, bfcr-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr)); status = buf_ensure_available_bits(msg_it); if (status != CTF_MSG_ITER_STATUS_OK) { if (status < 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot ensure that buffer has at least one byte: " - "msg-addr=%p, status=%s", - msg_it, ctf_msg_iter_status_string(status)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot ensure that buffer has at least one byte: " + "msg-addr={}, status={}", + fmt::ptr(msg_it), status); } else { - BT_COMP_LOGT("Cannot ensure that buffer has at least one byte: " - "msg-addr=%p, status=%s", - msg_it, ctf_msg_iter_status_string(status)); + BT_CPPLOGT_SPEC(msg_it->logger, + "Cannot ensure that buffer has at least one byte: " + "msg-addr={}, status={}", + fmt::ptr(msg_it), status); } goto end; } consumed_bits = bt_bfcr_continue(msg_it->bfcr, msg_it->buf.addr, msg_it->buf.sz, &bfcr_status); - BT_COMP_LOGT("BFCR consumed bits: size=%zu", consumed_bits); + BT_CPPLOGT_SPEC(msg_it->logger, "BFCR consumed bits: size={}", consumed_bits); switch (bfcr_status) { case BT_BFCR_STATUS_OK: /* Type was read completely. */ - BT_COMP_LOGT_STR("Field was completely decoded."); + BT_CPPLOGT_STR_SPEC(msg_it->logger, "Field was completely decoded."); msg_it->state = done_state; break; case BT_BFCR_STATUS_EOF: /* Stay in this continue state. */ - BT_COMP_LOGT_STR("BFCR needs more data to decode field completely."); + BT_CPPLOGT_STR_SPEC(msg_it->logger, "BFCR needs more data to decode field completely."); break; default: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "BFCR failed to continue: msg-it-addr=%p, bfcr-addr=%p, " - "status=%s", - msg_it, msg_it->bfcr, bt_bfcr_status_string(bfcr_status)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "BFCR failed to continue: msg-it-addr={}, bfcr-addr={}, " + "status={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), bfcr_status); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } @@ -664,7 +693,6 @@ static void release_all_dscopes(struct ctf_msg_iter *msg_it) static enum ctf_msg_iter_status switch_packet_state(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status; - bt_self_component *self_comp = msg_it->self_comp; /* * We don't put the stream class here because we need to make @@ -677,9 +705,10 @@ static enum ctf_msg_iter_status switch_packet_state(struct ctf_msg_iter *msg_it) msg_it->cur_packet_offset += msg_it->cur_exp_packet_total_size; } - BT_COMP_LOGD("Switching packet: msg-it-addr=%p, cur=%zu, " - "packet-offset=%" PRId64, - msg_it, msg_it->buf.at, msg_it->cur_packet_offset); + BT_CPPLOGD_SPEC(msg_it->logger, + "Switching packet: msg-it-addr={}, cur={}, " + "packet-offset={}", + fmt::ptr(msg_it), msg_it->buf.at, msg_it->cur_packet_offset); stack_clear(msg_it->stack); msg_it->meta.ec = NULL; BT_PACKET_PUT_REF_AND_RESET(msg_it->packet); @@ -720,11 +749,11 @@ static enum ctf_msg_iter_status switch_packet_state(struct ctf_msg_iter *msg_it) /* Packets are assumed to start on a byte frontier. */ if (msg_it->buf.at % CHAR_BIT) { - BT_COMP_LOGE_APPEND_CAUSE( - self_comp, + BT_CPPLOGE_APPEND_CAUSE_SPEC( + msg_it->logger, "Cannot switch packet: current position is not a multiple of 8: " - "msg-it-addr=%p, cur=%zu", - msg_it, msg_it->buf.at); + "msg-it-addr={}, cur={}", + fmt::ptr(msg_it), msg_it->buf.at); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } @@ -733,7 +762,8 @@ static enum ctf_msg_iter_status switch_packet_state(struct ctf_msg_iter *msg_it) msg_it->buf.sz -= consumed_bytes; msg_it->buf.at = 0; msg_it->buf.packet_offset = 0; - BT_COMP_LOGD("Adjusted buffer: addr=%p, size=%zu", msg_it->buf.addr, msg_it->buf.sz); + BT_CPPLOGD_SPEC(msg_it->logger, "Adjusted buffer: addr={}, size={}", + fmt::ptr(msg_it->buf.addr), msg_it->buf.sz); } msg_it->cur_exp_packet_content_size = -1; @@ -756,7 +786,6 @@ end: static enum ctf_msg_iter_status read_packet_header_begin_state(struct ctf_msg_iter *msg_it) { struct ctf_field_class *packet_header_fc = NULL; - bt_self_component *self_comp = msg_it->self_comp; enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; /* @@ -786,17 +815,19 @@ static enum ctf_msg_iter_status read_packet_header_begin_state(struct ctf_msg_it msg_it->cur_stream_class_id = -1; msg_it->cur_event_class_id = -1; msg_it->cur_data_stream_id = -1; - BT_COMP_LOGD("Decoding packet header field: " - "msg-it-addr=%p, trace-class-addr=%p, fc-addr=%p", - msg_it, msg_it->meta.tc, packet_header_fc); + BT_CPPLOGD_SPEC(msg_it->logger, + "Decoding packet header field: " + "msg-it-addr={}, trace-class-addr={}, fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.tc), fmt::ptr(packet_header_fc)); status = read_dscope_begin_state(msg_it, packet_header_fc, STATE_AFTER_TRACE_PACKET_HEADER, STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE, NULL); if (status < 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot decode packet header field: " - "msg-it-addr=%p, trace-class-addr=%p, " - "fc-addr=%p", - msg_it, msg_it->meta.tc, packet_header_fc); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot decode packet header field: " + "msg-it-addr={}, trace-class-addr={}, " + "fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.tc), + fmt::ptr(packet_header_fc)); } end: @@ -811,7 +842,6 @@ static enum ctf_msg_iter_status read_packet_header_continue_state(struct ctf_msg static inline enum ctf_msg_iter_status set_current_stream_class(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; struct ctf_stream_class *new_stream_class = NULL; if (msg_it->cur_stream_class_id == -1) { @@ -820,11 +850,11 @@ static inline enum ctf_msg_iter_status set_current_stream_class(struct ctf_msg_i * stream class. */ if (msg_it->meta.tc->stream_classes->len != 1) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Need exactly one stream class since there's " - "no stream class ID field: " - "msg-it-addr=%p", - msg_it); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Need exactly one stream class since there's " + "no stream class ID field: " + "msg-it-addr={}", + fmt::ptr(msg_it)); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } @@ -836,28 +866,28 @@ static inline enum ctf_msg_iter_status set_current_stream_class(struct ctf_msg_i new_stream_class = ctf_trace_class_borrow_stream_class_by_id(msg_it->meta.tc, msg_it->cur_stream_class_id); if (!new_stream_class) { - BT_COMP_LOGE_APPEND_CAUSE( - self_comp, + BT_CPPLOGE_APPEND_CAUSE_SPEC( + msg_it->logger, "No stream class with ID of stream class ID to use in trace class: " - "msg-it-addr=%p, stream-class-id=%" PRIu64 ", " - "trace-class-addr=%p", - msg_it, msg_it->cur_stream_class_id, msg_it->meta.tc); + "msg-it-addr={}, stream-class-id={}, " + "trace-class-addr={}", + fmt::ptr(msg_it), msg_it->cur_stream_class_id, fmt::ptr(msg_it->meta.tc)); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } if (msg_it->meta.sc) { if (new_stream_class != msg_it->meta.sc) { - BT_COMP_LOGE_APPEND_CAUSE( - self_comp, + BT_CPPLOGE_APPEND_CAUSE_SPEC( + msg_it->logger, "Two packets refer to two different stream classes within the same packet sequence: " - "msg-it-addr=%p, prev-stream-class-addr=%p, " - "prev-stream-class-id=%" PRId64 ", " - "next-stream-class-addr=%p, " - "next-stream-class-id=%" PRId64 ", " - "trace-addr=%p", - msg_it, msg_it->meta.sc, msg_it->meta.sc->id, new_stream_class, - new_stream_class->id, msg_it->meta.tc); + "msg-it-addr={}, prev-stream-class-addr={}, " + "prev-stream-class-id={}, " + "next-stream-class-addr={}, " + "next-stream-class-id={}, " + "trace-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.sc), msg_it->meta.sc->id, + fmt::ptr(new_stream_class), new_stream_class->id, fmt::ptr(msg_it->meta.tc)); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } @@ -865,10 +895,11 @@ static inline enum ctf_msg_iter_status set_current_stream_class(struct ctf_msg_i msg_it->meta.sc = new_stream_class; } - BT_COMP_LOGD("Set current stream class: " - "msg-it-addr=%p, stream-class-addr=%p, " - "stream-class-id=%" PRId64, - msg_it, msg_it->meta.sc, msg_it->meta.sc->id); + BT_CPPLOGD_SPEC(msg_it->logger, + "Set current stream class: " + "msg-it-addr={}, stream-class-addr={}, " + "stream-class-id={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.sc), msg_it->meta.sc->id); end: return status; @@ -877,27 +908,27 @@ end: static inline enum ctf_msg_iter_status set_current_stream(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; bt_stream *stream = NULL; - BT_COMP_LOGD("Calling user function (get stream): msg-it-addr=%p, " - "stream-class-addr=%p, stream-class-id=%" PRId64, - msg_it, msg_it->meta.sc, msg_it->meta.sc->id); + BT_CPPLOGD_SPEC(msg_it->logger, + "Calling user function (get stream): msg-it-addr={}, " + "stream-class-addr={}, stream-class-id={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.sc), msg_it->meta.sc->id); stream = msg_it->medium.medops.borrow_stream(msg_it->meta.sc->ir_sc, msg_it->cur_data_stream_id, msg_it->medium.data); bt_stream_get_ref(stream); - BT_COMP_LOGD("User function returned: stream-addr=%p", stream); + BT_CPPLOGD_SPEC(msg_it->logger, "User function returned: stream-addr={}", fmt::ptr(stream)); if (!stream) { - BT_COMP_LOGE_APPEND_CAUSE( - self_comp, + BT_CPPLOGE_APPEND_CAUSE_SPEC( + msg_it->logger, "User function failed to return a stream object for the given stream class."); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } if (msg_it->stream && stream != msg_it->stream) { - BT_COMP_LOGE_APPEND_CAUSE( - self_comp, + BT_CPPLOGE_APPEND_CAUSE_SPEC( + msg_it->logger, "User function returned a different stream than the previous one for the same sequence of packets."); status = CTF_MSG_ITER_STATUS_ERROR; goto end; @@ -913,25 +944,27 @@ end: static inline enum ctf_msg_iter_status set_current_packet(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; bt_packet *packet = NULL; - BT_COMP_LOGD("Creating packet from stream: " - "msg-it-addr=%p, stream-addr=%p, " - "stream-class-addr=%p, " - "stream-class-id=%" PRId64, - msg_it, msg_it->stream, msg_it->meta.sc, msg_it->meta.sc->id); + BT_CPPLOGD_SPEC(msg_it->logger, + "Creating packet from stream: " + "msg-it-addr={}, stream-addr={}, " + "stream-class-addr={}, " + "stream-class-id={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->stream), fmt::ptr(msg_it->meta.sc), + msg_it->meta.sc->id); /* Create packet */ BT_ASSERT(msg_it->stream); packet = bt_packet_create(msg_it->stream); if (!packet) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create packet from stream: " - "msg-it-addr=%p, stream-addr=%p, " - "stream-class-addr=%p, " - "stream-class-id=%" PRId64, - msg_it, msg_it->stream, msg_it->meta.sc, msg_it->meta.sc->id); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot create packet from stream: " + "msg-it-addr={}, stream-addr={}, " + "stream-class-addr={}, " + "stream-class-id={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->stream), + fmt::ptr(msg_it->meta.sc), msg_it->meta.sc->id); goto error; } @@ -978,16 +1011,16 @@ end: static enum ctf_msg_iter_status read_packet_context_begin_state(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; struct ctf_field_class *packet_context_fc; BT_ASSERT(msg_it->meta.sc); packet_context_fc = msg_it->meta.sc->packet_context_fc; if (!packet_context_fc) { - BT_COMP_LOGD("No packet packet context field class in stream class: continuing: " - "msg-it-addr=%p, stream-class-addr=%p, " - "stream-class-id=%" PRId64, - msg_it, msg_it->meta.sc, msg_it->meta.sc->id); + BT_CPPLOGD_SPEC(msg_it->logger, + "No packet packet context field class in stream class: continuing: " + "msg-it-addr={}, stream-class-addr={}, " + "stream-class-id={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.sc), msg_it->meta.sc->id); msg_it->state = STATE_AFTER_STREAM_PACKET_CONTEXT; goto end; } @@ -999,19 +1032,22 @@ static enum ctf_msg_iter_status read_packet_context_begin_state(struct ctf_msg_i BT_ASSERT(msg_it->dscopes.stream_packet_context); } - BT_COMP_LOGD("Decoding packet context field: " - "msg-it-addr=%p, stream-class-addr=%p, " - "stream-class-id=%" PRId64 ", fc-addr=%p", - msg_it, msg_it->meta.sc, msg_it->meta.sc->id, packet_context_fc); + BT_CPPLOGD_SPEC(msg_it->logger, + "Decoding packet context field: " + "msg-it-addr={}, stream-class-addr={}, " + "stream-class-id={}, fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.sc), msg_it->meta.sc->id, + fmt::ptr(packet_context_fc)); status = read_dscope_begin_state(msg_it, packet_context_fc, STATE_AFTER_STREAM_PACKET_CONTEXT, STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE, msg_it->dscopes.stream_packet_context); if (status < 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot decode packet context field: " - "msg-it-addr=%p, stream-class-addr=%p, " - "stream-class-id=%" PRId64 ", fc-addr=%p", - msg_it, msg_it->meta.sc, msg_it->meta.sc->id, packet_context_fc); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot decode packet context field: " + "msg-it-addr={}, stream-class-addr={}, " + "stream-class-id={}, fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.sc), + msg_it->meta.sc->id, fmt::ptr(packet_context_fc)); } end: @@ -1026,7 +1062,6 @@ static enum ctf_msg_iter_status read_packet_context_continue_state(struct ctf_ms static enum ctf_msg_iter_status set_current_packet_content_sizes(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; if (msg_it->cur_exp_packet_total_size == -1) { if (msg_it->cur_exp_packet_content_size != -1) { @@ -1043,21 +1078,23 @@ static enum ctf_msg_iter_status set_current_packet_content_sizes(struct ctf_msg_ (msg_it->cur_exp_packet_total_size < 0 && msg_it->cur_exp_packet_content_size < 0)); if (msg_it->cur_exp_packet_content_size > msg_it->cur_exp_packet_total_size) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Invalid packet or content size: " - "content size is greater than packet size: " - "msg-it-addr=%p, packet-context-field-addr=%p, " - "packet-size=%" PRId64 ", content-size=%" PRId64, - msg_it, msg_it->dscopes.stream_packet_context, - msg_it->cur_exp_packet_total_size, - msg_it->cur_exp_packet_content_size); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + msg_it->logger, + "Invalid packet or content size: " + "content size is greater than packet size: " + "msg-it-addr={}, packet-context-field-addr={}, " + "packet-size={}, content-size={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->dscopes.stream_packet_context), + msg_it->cur_exp_packet_total_size, msg_it->cur_exp_packet_content_size); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } - BT_COMP_LOGD("Set current packet and content sizes: " - "msg-it-addr=%p, packet-size=%" PRIu64 ", content-size=%" PRIu64, - msg_it, msg_it->cur_exp_packet_total_size, msg_it->cur_exp_packet_content_size); + BT_CPPLOGD_SPEC(msg_it->logger, + "Set current packet and content sizes: " + "msg-it-addr={}, packet-size={}, content-size={}", + fmt::ptr(msg_it), msg_it->cur_exp_packet_total_size, + msg_it->cur_exp_packet_content_size); end: return status; @@ -1085,7 +1122,6 @@ end: static enum ctf_msg_iter_status read_event_header_begin_state(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; struct ctf_field_class *event_header_fc = NULL; /* Reset the position of the last event header */ @@ -1096,18 +1132,20 @@ static enum ctf_msg_iter_status read_event_header_begin_state(struct ctf_msg_ite if (msg_it->cur_exp_packet_content_size >= 0) { if (G_UNLIKELY(packet_at(msg_it) == msg_it->cur_exp_packet_content_size)) { /* No more events! */ - BT_COMP_LOGD("Reached end of packet: msg-it-addr=%p, " - "cur=%zu", - msg_it, packet_at(msg_it)); + BT_CPPLOGD_SPEC(msg_it->logger, + "Reached end of packet: msg-it-addr={}, " + "cur={}", + fmt::ptr(msg_it), packet_at(msg_it)); msg_it->state = STATE_EMIT_MSG_PACKET_END_MULTI; goto end; } else if (G_UNLIKELY(packet_at(msg_it) > msg_it->cur_exp_packet_content_size)) { /* That's not supposed to happen */ - BT_COMP_LOGD( + BT_CPPLOGD_SPEC( + msg_it->logger, "Before decoding event header field: cursor is passed the packet's content: " - "msg-it-addr=%p, content-size=%" PRId64 ", " - "cur=%zu", - msg_it, msg_it->cur_exp_packet_content_size, packet_at(msg_it)); + "msg-it-addr={}, content-size={}, " + "cur={}", + fmt::ptr(msg_it), msg_it->cur_exp_packet_content_size, packet_at(msg_it)); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } @@ -1137,19 +1175,22 @@ static enum ctf_msg_iter_status read_event_header_begin_state(struct ctf_msg_ite goto end; } - BT_COMP_LOGD("Decoding event header field: " - "msg-it-addr=%p, stream-class-addr=%p, " - "stream-class-id=%" PRId64 ", " - "fc-addr=%p", - msg_it, msg_it->meta.sc, msg_it->meta.sc->id, event_header_fc); + BT_CPPLOGD_SPEC(msg_it->logger, + "Decoding event header field: " + "msg-it-addr={}, stream-class-addr={}, " + "stream-class-id={}, " + "fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.sc), msg_it->meta.sc->id, + fmt::ptr(event_header_fc)); status = read_dscope_begin_state(msg_it, event_header_fc, STATE_AFTER_EVENT_HEADER, STATE_DSCOPE_EVENT_HEADER_CONTINUE, NULL); if (status < 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot decode event header field: " - "msg-it-addr=%p, stream-class-addr=%p, " - "stream-class-id=%" PRId64 ", fc-addr=%p", - msg_it, msg_it->meta.sc, msg_it->meta.sc->id, event_header_fc); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot decode event header field: " + "msg-it-addr={}, stream-class-addr={}, " + "stream-class-id={}, fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.sc), + msg_it->meta.sc->id, fmt::ptr(event_header_fc)); } end: @@ -1164,7 +1205,6 @@ static enum ctf_msg_iter_status read_event_header_continue_state(struct ctf_msg_ static inline enum ctf_msg_iter_status set_current_event_class(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; struct ctf_event_class *new_event_class = NULL; @@ -1174,11 +1214,11 @@ static inline enum ctf_msg_iter_status set_current_event_class(struct ctf_msg_it * event class. */ if (msg_it->meta.sc->event_classes->len != 1) { - BT_COMP_LOGE_APPEND_CAUSE( - self_comp, + BT_CPPLOGE_APPEND_CAUSE_SPEC( + msg_it->logger, "Need exactly one event class since there's no event class ID field: " - "msg-it-addr=%p", - msg_it); + "msg-it-addr={}", + fmt::ptr(msg_it)); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } @@ -1190,23 +1230,26 @@ static inline enum ctf_msg_iter_status set_current_event_class(struct ctf_msg_it new_event_class = ctf_stream_class_borrow_event_class_by_id(msg_it->meta.sc, msg_it->cur_event_class_id); if (!new_event_class) { - BT_COMP_LOGE_APPEND_CAUSE( - self_comp, + BT_CPPLOGE_APPEND_CAUSE_SPEC( + msg_it->logger, "No event class with ID of event class ID to use in stream class: " - "msg-it-addr=%p, stream-class-id=%" PRIu64 ", " - "event-class-id=%" PRIu64 ", " - "trace-class-addr=%p", - msg_it, msg_it->meta.sc->id, msg_it->cur_event_class_id, msg_it->meta.tc); + "msg-it-addr={}, stream-class-id={}, " + "event-class-id={}, " + "trace-class-addr={}", + fmt::ptr(msg_it), msg_it->meta.sc->id, msg_it->cur_event_class_id, + fmt::ptr(msg_it->meta.tc)); status = CTF_MSG_ITER_STATUS_ERROR; goto end; } msg_it->meta.ec = new_event_class; - BT_COMP_LOGD("Set current event class: " - "msg-it-addr=%p, event-class-addr=%p, " - "event-class-id=%" PRId64 ", " - "event-class-name=\"%s\"", - msg_it, msg_it->meta.ec, msg_it->meta.ec->id, msg_it->meta.ec->name->str); + BT_CPPLOGD_SPEC(msg_it->logger, + "Set current event class: " + "msg-it-addr={}, event-class-addr={}, " + "event-class-id={}, " + "event-class-name=\"{}\"", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.ec), msg_it->meta.ec->id, + msg_it->meta.ec->name->str); end: return status; @@ -1215,14 +1258,15 @@ end: static inline enum ctf_msg_iter_status set_current_event_message(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; bt_message *msg = NULL; BT_ASSERT_DBG(msg_it->meta.ec); BT_ASSERT_DBG(msg_it->packet); - BT_COMP_LOGD("Creating event message from event class and packet: " - "msg-it-addr=%p, ec-addr=%p, ec-name=\"%s\", packet-addr=%p", - msg_it, msg_it->meta.ec, msg_it->meta.ec->name->str, msg_it->packet); + BT_CPPLOGD_SPEC(msg_it->logger, + "Creating event message from event class and packet: " + "msg-it-addr={}, ec-addr={}, ec-name=\"{}\", packet-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.ec), msg_it->meta.ec->name->str, + fmt::ptr(msg_it->packet)); BT_ASSERT_DBG(msg_it->self_msg_iter); BT_ASSERT_DBG(msg_it->meta.sc); @@ -1236,12 +1280,12 @@ static inline enum ctf_msg_iter_status set_current_event_message(struct ctf_msg_ } if (!msg) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create event message: " - "msg-it-addr=%p, ec-addr=%p, ec-name=\"%s\", " - "packet-addr=%p", - msg_it, msg_it->meta.ec, msg_it->meta.ec->name->str, - msg_it->packet); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot create event message: " + "msg-it-addr={}, ec-addr={}, ec-name=\"{}\", " + "packet-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.ec), + msg_it->meta.ec->name->str, fmt::ptr(msg_it->packet)); goto error; } @@ -1287,7 +1331,6 @@ end: static enum ctf_msg_iter_status read_event_common_context_begin_state(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; struct ctf_field_class *event_common_context_fc; event_common_context_fc = msg_it->meta.sc->event_common_context_fc; @@ -1302,21 +1345,23 @@ static enum ctf_msg_iter_status read_event_common_context_begin_state(struct ctf BT_ASSERT_DBG(msg_it->dscopes.event_common_context); } - BT_COMP_LOGT("Decoding event common context field: " - "msg-it-addr=%p, stream-class-addr=%p, " - "stream-class-id=%" PRId64 ", " - "fc-addr=%p", - msg_it, msg_it->meta.sc, msg_it->meta.sc->id, event_common_context_fc); + BT_CPPLOGT_SPEC(msg_it->logger, + "Decoding event common context field: " + "msg-it-addr={}, stream-class-addr={}, " + "stream-class-id={}, " + "fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.sc), msg_it->meta.sc->id, + fmt::ptr(event_common_context_fc)); status = read_dscope_begin_state( msg_it, event_common_context_fc, STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN, STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE, msg_it->dscopes.event_common_context); if (status < 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot decode event common context field: " - "msg-it-addr=%p, stream-class-addr=%p, " - "stream-class-id=%" PRId64 ", fc-addr=%p", - msg_it, msg_it->meta.sc, msg_it->meta.sc->id, - event_common_context_fc); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot decode event common context field: " + "msg-it-addr={}, stream-class-addr={}, " + "stream-class-id={}, fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.sc), + msg_it->meta.sc->id, fmt::ptr(event_common_context_fc)); } end: @@ -1332,7 +1377,6 @@ read_event_common_context_continue_state(struct ctf_msg_iter *msg_it) static enum ctf_msg_iter_status read_event_spec_context_begin_state(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; struct ctf_field_class *event_spec_context_fc; event_spec_context_fc = msg_it->meta.ec->spec_context_fc; @@ -1347,23 +1391,25 @@ static enum ctf_msg_iter_status read_event_spec_context_begin_state(struct ctf_m BT_ASSERT_DBG(msg_it->dscopes.event_spec_context); } - BT_COMP_LOGT("Decoding event specific context field: " - "msg-it-addr=%p, event-class-addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64 ", " - "fc-addr=%p", - msg_it, msg_it->meta.ec, msg_it->meta.ec->name->str, msg_it->meta.ec->id, - event_spec_context_fc); + BT_CPPLOGT_SPEC(msg_it->logger, + "Decoding event specific context field: " + "msg-it-addr={}, event-class-addr={}, " + "event-class-name=\"{}\", event-class-id={}, " + "fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.ec), msg_it->meta.ec->name->str, + msg_it->meta.ec->id, fmt::ptr(event_spec_context_fc)); status = read_dscope_begin_state( msg_it, event_spec_context_fc, STATE_DSCOPE_EVENT_PAYLOAD_BEGIN, STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE, msg_it->dscopes.event_spec_context); if (status < 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot decode event specific context field: " - "msg-it-addr=%p, event-class-addr=%p, " - "event-class-name=\"%s\", " - "event-class-id=%" PRId64 ", fc-addr=%p", - msg_it, msg_it->meta.ec, msg_it->meta.ec->name->str, - msg_it->meta.ec->id, event_spec_context_fc); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot decode event specific context field: " + "msg-it-addr={}, event-class-addr={}, " + "event-class-name=\"{}\", " + "event-class-id={}, fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.ec), + msg_it->meta.ec->name->str, msg_it->meta.ec->id, + fmt::ptr(event_spec_context_fc)); } end: @@ -1378,7 +1424,6 @@ static enum ctf_msg_iter_status read_event_spec_context_continue_state(struct ct static enum ctf_msg_iter_status read_event_payload_begin_state(struct ctf_msg_iter *msg_it) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; struct ctf_field_class *event_payload_fc; event_payload_fc = msg_it->meta.ec->payload_fc; @@ -1393,23 +1438,25 @@ static enum ctf_msg_iter_status read_event_payload_begin_state(struct ctf_msg_it BT_ASSERT_DBG(msg_it->dscopes.event_payload); } - BT_COMP_LOGT("Decoding event payload field: " - "msg-it-addr=%p, event-class-addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64 ", " - "fc-addr=%p", - msg_it, msg_it->meta.ec, msg_it->meta.ec->name->str, msg_it->meta.ec->id, - event_payload_fc); + BT_CPPLOGT_SPEC(msg_it->logger, + "Decoding event payload field: " + "msg-it-addr={}, event-class-addr={}, " + "event-class-name=\"{}\", event-class-id={}, " + "fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.ec), msg_it->meta.ec->name->str, + msg_it->meta.ec->id, fmt::ptr(event_payload_fc)); status = read_dscope_begin_state(msg_it, event_payload_fc, STATE_EMIT_MSG_EVENT, STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE, msg_it->dscopes.event_payload); if (status < 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot decode event payload field: " - "msg-it-addr=%p, event-class-addr=%p, " - "event-class-name=\"%s\", " - "event-class-id=%" PRId64 ", fc-addr=%p", - msg_it, msg_it->meta.ec, msg_it->meta.ec->name->str, - msg_it->meta.ec->id, event_payload_fc); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot decode event payload field: " + "msg-it-addr={}, event-class-addr={}, " + "event-class-name=\"{}\", " + "event-class-id={}, fc-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->meta.ec), + msg_it->meta.ec->name->str, msg_it->meta.ec->id, + fmt::ptr(event_payload_fc)); } end: @@ -1435,16 +1482,17 @@ static enum ctf_msg_iter_status skip_packet_padding_state(struct ctf_msg_iter *m } else { size_t bits_to_consume; - BT_COMP_LOGD("Trying to skip %zu bits of padding: msg-it-addr=%p, size=%zu", bits_to_skip, - msg_it, bits_to_skip); + BT_CPPLOGD_SPEC(msg_it->logger, + "Trying to skip {} bits of padding: msg-it-addr={}, size={}", bits_to_skip, + fmt::ptr(msg_it), bits_to_skip); status = buf_ensure_available_bits(msg_it); if (status != CTF_MSG_ITER_STATUS_OK) { goto end; } bits_to_consume = MIN(buf_available_bits(msg_it), bits_to_skip); - BT_COMP_LOGD("Skipping %zu bits of padding: msg-it-addr=%p, size=%zu", bits_to_consume, - msg_it, bits_to_consume); + BT_CPPLOGD_SPEC(msg_it->logger, "Skipping {} bits of padding: msg-it-addr={}, size={}", + bits_to_consume, fmt::ptr(msg_it), bits_to_consume); buf_consume_bits(msg_it, bits_to_consume); bits_to_skip = msg_it->cur_exp_packet_total_size - packet_at(msg_it); if (bits_to_skip == 0) { @@ -1554,7 +1602,8 @@ static inline enum ctf_msg_iter_status handle_state(struct ctf_msg_iter *msg_it) enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; const enum state state = msg_it->state; - BT_COMP_LOGT("Handling state: msg-it-addr=%p, state=%s", msg_it, state_string(state)); + BT_CPPLOGT_SPEC(msg_it->logger, "Handling state: msg-it-addr={}, state={}", fmt::ptr(msg_it), + state); // TODO: optimalize! switch (state) { @@ -1654,23 +1703,24 @@ static inline enum ctf_msg_iter_status handle_state(struct ctf_msg_iter *msg_it) case STATE_DONE: break; default: - BT_COMP_LOGF("Unknown CTF plugin message iterator state: " - "msg-it-addr=%p, state=%d", - msg_it, msg_it->state); + BT_CPPLOGF_SPEC(msg_it->logger, + "Unknown CTF plugin message iterator state: " + "msg-it-addr={}, state={}", + fmt::ptr(msg_it), msg_it->state); bt_common_abort(); } - BT_COMP_LOGT("Handled state: msg-it-addr=%p, status=%s, " - "prev-state=%s, cur-state=%s", - msg_it, ctf_msg_iter_status_string(status), state_string(state), - state_string(msg_it->state)); + BT_CPPLOGT_SPEC(msg_it->logger, + "Handled state: msg-it-addr={}, status={}, " + "prev-state={}, cur-state={}", + fmt::ptr(msg_it), status, state, msg_it->state); return status; } void ctf_msg_iter_reset_for_next_stream_file(struct ctf_msg_iter *msg_it) { BT_ASSERT(msg_it); - BT_COMP_LOGD("Resetting message iterator: addr=%p", msg_it); + BT_CPPLOGD_SPEC(msg_it->logger, "Resetting message iterator: addr={}", fmt::ptr(msg_it)); stack_clear(msg_it->stack); msg_it->meta.sc = NULL; msg_it->meta.ec = NULL; @@ -1783,9 +1833,10 @@ static void update_default_clock(struct ctf_msg_iter *msg_it, uint64_t new_val, msg_it->default_clock_snapshot |= new_val; end: - BT_COMP_LOGT("Updated default clock's value from integer field's value: " - "value=%" PRIu64, - msg_it->default_clock_snapshot); + BT_CPPLOGT_SPEC(msg_it->logger, + "Updated default clock's value from integer field's value: " + "value={}", + msg_it->default_clock_snapshot); } /* @@ -1806,15 +1857,16 @@ static enum bt_bfcr_status bfcr_unsigned_int_cb(uint64_t value, struct ctf_field void *data) { ctf_msg_iter *msg_it = (ctf_msg_iter *) data; - bt_self_component *self_comp = msg_it->self_comp; enum bt_bfcr_status status = BT_BFCR_STATUS_OK; bt_field *field = NULL; - BT_COMP_LOGT("Unsigned integer function called from BFCR: " - "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, " - "fc-type=%d, fc-in-ir=%d, value=%" PRIu64, - msg_it, msg_it->bfcr, fc, fc->type, fc->in_ir, value); + BT_CPPLOGT_SPEC(msg_it->logger, + "Unsigned integer function called from BFCR: " + "msg-it-addr={}, bfcr-addr={}, fc-addr={}, " + "fc-type={}, fc-in-ir={}, value={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), fmt::ptr(fc), fc->type, fc->in_ir, + value); ctf_field_class_int *int_fc = ctf_field_class_as_int(fc); @@ -1840,10 +1892,9 @@ static enum bt_bfcr_status bfcr_unsigned_int_cb(uint64_t value, struct ctf_field break; case CTF_FIELD_CLASS_MEANING_MAGIC: if (value != 0xc1fc1fc1) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Invalid CTF magic number: msg-it-addr=%p, " - "magic=%" PRIx64, - msg_it, value); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Invalid CTF magic number: msg-it-addr={}, magic={}", + fmt::ptr(msg_it), value); status = BT_BFCR_STATUS_ERROR; goto end; } @@ -1896,15 +1947,16 @@ static enum bt_bfcr_status bfcr_unsigned_int_char_cb(uint64_t value, struct ctf_ { int ret; ctf_msg_iter *msg_it = (ctf_msg_iter *) data; - bt_self_component *self_comp = msg_it->self_comp; enum bt_bfcr_status status = BT_BFCR_STATUS_OK; bt_field *string_field = NULL; char str[2] = {'\0', '\0'}; - BT_COMP_LOGT("Unsigned integer character function called from BFCR: " - "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, " - "fc-type=%d, fc-in-ir=%d, value=%" PRIu64, - msg_it, msg_it->bfcr, fc, fc->type, fc->in_ir, value); + BT_CPPLOGT_SPEC(msg_it->logger, + "Unsigned integer character function called from BFCR: " + "msg-it-addr={}, bfcr-addr={}, fc-addr={}, " + "fc-type={}, fc-in-ir={}, value={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), fmt::ptr(fc), fc->type, fc->in_ir, + value); ctf_field_class_int *int_fc = ctf_field_class_as_int(fc); BT_ASSERT_DBG(int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE); @@ -1931,10 +1983,10 @@ static enum bt_bfcr_status bfcr_unsigned_int_char_cb(uint64_t value, struct ctf_ str[0] = (char) value; ret = bt_field_string_append_with_length(string_field, str, 1); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot append character to string field's value: " - "msg-it-addr=%p, field-addr=%p, ret=%d", - msg_it, string_field, ret); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot append character to string field's value: " + "msg-it-addr={}, field-addr={}, ret={}", + fmt::ptr(msg_it), fmt::ptr(string_field), ret); status = BT_BFCR_STATUS_ERROR; goto end; } @@ -1949,10 +2001,12 @@ static enum bt_bfcr_status bfcr_signed_int_cb(int64_t value, struct ctf_field_cl bt_field *field = NULL; ctf_msg_iter *msg_it = (ctf_msg_iter *) data; - BT_COMP_LOGT("Signed integer function called from BFCR: " - "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, " - "fc-type=%d, fc-in-ir=%d, value=%" PRId64, - msg_it, msg_it->bfcr, fc, fc->type, fc->in_ir, value); + BT_CPPLOGT_SPEC(msg_it->logger, + "Signed integer function called from BFCR: " + "msg-it-addr={}, bfcr-addr={}, fc-addr={}, " + "fc-type={}, fc-in-ir={}, value={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), fmt::ptr(fc), fc->type, fc->in_ir, + value); ctf_field_class_int *int_fc = ctf_field_class_as_int(fc); BT_ASSERT_DBG(int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE); @@ -1987,10 +2041,12 @@ static enum bt_bfcr_status bfcr_floating_point_cb(double value, struct ctf_field ctf_msg_iter *msg_it = (ctf_msg_iter *) data; bt_field_class_type type; - BT_COMP_LOGT("Floating point number function called from BFCR: " - "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, " - "fc-type=%d, fc-in-ir=%d, value=%f", - msg_it, msg_it->bfcr, fc, fc->type, fc->in_ir, value); + BT_CPPLOGT_SPEC(msg_it->logger, + "Floating point number function called from BFCR: " + "msg-it-addr={}, bfcr-addr={}, fc-addr={}, " + "fc-type={}, fc-in-ir={}, value={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), fmt::ptr(fc), fc->type, fc->in_ir, + value); if (G_UNLIKELY(!fc->in_ir || msg_it->dry_run)) { goto end; @@ -2018,10 +2074,11 @@ static enum bt_bfcr_status bfcr_string_begin_cb(struct ctf_field_class *fc, void bt_field *field = NULL; ctf_msg_iter *msg_it = (ctf_msg_iter *) data; - BT_COMP_LOGT("String (beginning) function called from BFCR: " - "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, " - "fc-type=%d, fc-in-ir=%d", - msg_it, msg_it->bfcr, fc, fc->type, fc->in_ir); + BT_CPPLOGT_SPEC(msg_it->logger, + "String (beginning) function called from BFCR: " + "msg-it-addr={}, bfcr-addr={}, fc-addr={}, " + "fc-type={}, fc-in-ir={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), fmt::ptr(fc), fc->type, fc->in_ir); if (G_UNLIKELY(!fc->in_ir || msg_it->dry_run)) { goto end; @@ -2050,13 +2107,14 @@ static enum bt_bfcr_status bfcr_string_cb(const char *value, size_t len, struct enum bt_bfcr_status status = BT_BFCR_STATUS_OK; bt_field *field = NULL; ctf_msg_iter *msg_it = (ctf_msg_iter *) data; - bt_self_component *self_comp = msg_it->self_comp; int ret; - BT_COMP_LOGT("String (substring) function called from BFCR: " - "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, " - "fc-type=%d, fc-in-ir=%d, string-length=%zu", - msg_it, msg_it->bfcr, fc, fc->type, fc->in_ir, len); + BT_CPPLOGT_SPEC(msg_it->logger, + "String (substring) function called from BFCR: " + "msg-it-addr={}, bfcr-addr={}, fc-addr={}, " + "fc-type={}, fc-in-ir={}, string-length={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), fmt::ptr(fc), fc->type, fc->in_ir, + len); if (G_UNLIKELY(!fc->in_ir || msg_it->dry_run)) { goto end; @@ -2068,11 +2126,11 @@ static enum bt_bfcr_status bfcr_string_cb(const char *value, size_t len, struct /* Append current substring */ ret = bt_field_string_append_with_length(field, value, len); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot append substring to string field's value: " - "msg-it-addr=%p, field-addr=%p, string-length=%zu, " - "ret=%d", - msg_it, field, len, ret); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot append substring to string field's value: " + "msg-it-addr={}, field-addr={}, string-length={}, " + "ret={}", + fmt::ptr(msg_it), fmt::ptr(field), len, ret); status = BT_BFCR_STATUS_ERROR; goto end; } @@ -2085,10 +2143,11 @@ static enum bt_bfcr_status bfcr_string_end_cb(struct ctf_field_class *fc, void * { ctf_msg_iter *msg_it = (ctf_msg_iter *) data; - BT_COMP_LOGT("String (end) function called from BFCR: " - "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, " - "fc-type=%d, fc-in-ir=%d", - msg_it, msg_it->bfcr, fc, fc->type, fc->in_ir); + BT_CPPLOGT_SPEC(msg_it->logger, + "String (end) function called from BFCR: " + "msg-it-addr={}, bfcr-addr={}, fc-addr={}, " + "fc-type={}, fc-in-ir={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), fmt::ptr(fc), fc->type, fc->in_ir); if (G_UNLIKELY(!fc->in_ir || msg_it->dry_run)) { goto end; @@ -2109,10 +2168,11 @@ static enum bt_bfcr_status bfcr_compound_begin_cb(struct ctf_field_class *fc, vo ctf_msg_iter *msg_it = (ctf_msg_iter *) data; bt_field *field; - BT_COMP_LOGT("Compound (beginning) function called from BFCR: " - "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, " - "fc-type=%d, fc-in-ir=%d", - msg_it, msg_it->bfcr, fc, fc->type, fc->in_ir); + BT_CPPLOGT_SPEC(msg_it->logger, + "Compound (beginning) function called from BFCR: " + "msg-it-addr={}, bfcr-addr={}, fc-addr={}, " + "fc-type={}, fc-in-ir={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), fmt::ptr(fc), fc->type, fc->in_ir); if (G_UNLIKELY(!fc->in_ir || msg_it->dry_run)) { goto end; @@ -2155,10 +2215,11 @@ static enum bt_bfcr_status bfcr_compound_end_cb(struct ctf_field_class *fc, void { ctf_msg_iter *msg_it = (ctf_msg_iter *) data; - BT_COMP_LOGT("Compound (end) function called from BFCR: " - "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, " - "fc-type=%d, fc-in-ir=%d", - msg_it, msg_it->bfcr, fc, fc->type, fc->in_ir); + BT_CPPLOGT_SPEC(msg_it->logger, + "Compound (end) function called from BFCR: " + "msg-it-addr={}, bfcr-addr={}, fc-addr={}, " + "fc-type={}, fc-in-ir={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->bfcr), fmt::ptr(fc), fc->type, fc->in_ir); if (G_UNLIKELY(!fc->in_ir || msg_it->dry_run)) { goto end; @@ -2197,7 +2258,6 @@ static int64_t bfcr_get_sequence_length_cb(struct ctf_field_class *fc, void *dat { bt_field *seq_field; ctf_msg_iter *msg_it = (ctf_msg_iter *) data; - bt_self_component *self_comp = msg_it->self_comp; struct ctf_field_class_sequence *seq_fc = ctf_field_class_as_sequence(fc); int64_t length; int ret; @@ -2223,11 +2283,11 @@ static int64_t bfcr_get_sequence_length_cb(struct ctf_field_class *fc, void *dat BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY)); ret = bt_field_array_dynamic_set_length(seq_field, (uint64_t) length); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot set dynamic array field's length field: " - "msg-it-addr=%p, field-addr=%p, " - "length=%" PRIu64, - msg_it, seq_field, length); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot set dynamic array field's length field: " + "msg-it-addr={}, field-addr={}, " + "length={}", + fmt::ptr(msg_it), fmt::ptr(seq_field), length); length = -1; } } @@ -2245,7 +2305,6 @@ bfcr_borrow_variant_selected_field_class_cb(struct ctf_field_class *fc, void *da ctf_msg_iter *msg_it = (ctf_msg_iter *) data; ctf_field_class_variant *var_fc = ctf_field_class_as_variant(fc); struct ctf_named_field_class *selected_option = NULL; - bt_self_component *self_comp = msg_it->self_comp; struct ctf_field_class *ret_fc = NULL; union { @@ -2282,11 +2341,11 @@ bfcr_borrow_variant_selected_field_class_cb(struct ctf_field_class *fc, void *da } if (option_index < 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot find variant field class's option: " - "msg-it-addr=%p, var-fc-addr=%p, u-tag=%" PRIu64 ", " - "i-tag=%" PRId64, - msg_it, var_fc, tag.u, tag.i); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot find variant field class's option: " + "msg-it-addr={}, var-fc-addr={}, u-tag={}, " + "i-tag={}", + fmt::ptr(msg_it), fmt::ptr(var_fc), tag.u, tag.i); ret_fc = NULL; goto end; } @@ -2299,11 +2358,11 @@ bfcr_borrow_variant_selected_field_class_cb(struct ctf_field_class *fc, void *da ret = bt_field_variant_select_option_by_index(var_field, option_index); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot select variant field's option field: " - "msg-it-addr=%p, var-field-addr=%p, " - "opt-index=%" PRId64, - msg_it, var_field, option_index); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot select variant field's option field: " + "msg-it-addr={}, var-field-addr={}, " + "opt-index={}", + fmt::ptr(msg_it), fmt::ptr(var_field), option_index); ret_fc = NULL; goto end; } @@ -2317,17 +2376,16 @@ end: static bt_message *create_msg_stream_beginning(struct ctf_msg_iter *msg_it) { - bt_self_component *self_comp = msg_it->self_comp; bt_message *msg; BT_ASSERT(msg_it->stream); BT_ASSERT(msg_it->self_msg_iter); msg = bt_message_stream_beginning_create(msg_it->self_msg_iter, msg_it->stream); if (!msg) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create stream beginning message: " - "msg-it-addr=%p, stream-addr=%p", - msg_it, msg_it->stream); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot create stream beginning message: " + "msg-it-addr={}, stream-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->stream)); } return msg; @@ -2335,14 +2393,13 @@ static bt_message *create_msg_stream_beginning(struct ctf_msg_iter *msg_it) static bt_message *create_msg_stream_end(struct ctf_msg_iter *msg_it) { - bt_self_component *self_comp = msg_it->self_comp; bt_message *msg; if (!msg_it->stream) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create stream end message because stream is NULL: " - "msg-it-addr=%p", - msg_it); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot create stream end message because stream is NULL: " + "msg-it-addr={}", + fmt::ptr(msg_it)); msg = NULL; goto end; } @@ -2350,10 +2407,10 @@ static bt_message *create_msg_stream_end(struct ctf_msg_iter *msg_it) BT_ASSERT(msg_it->self_msg_iter); msg = bt_message_stream_end_create(msg_it->self_msg_iter, msg_it->stream); if (!msg) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create stream end message: " - "msg-it-addr=%p, stream-addr=%p", - msg_it, msg_it->stream); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot create stream end message: " + "msg-it-addr={}, stream-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->stream)); } end: @@ -2362,7 +2419,6 @@ end: static bt_message *create_msg_packet_beginning(struct ctf_msg_iter *msg_it, bool use_default_cs) { - bt_self_component *self_comp = msg_it->self_comp; bt_message *msg; const bt_stream_class *sc = msg_it->meta.sc->ir_sc; @@ -2391,10 +2447,10 @@ static bt_message *create_msg_packet_beginning(struct ctf_msg_iter *msg_it, bool } if (!msg) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create packet beginning message: " - "msg-it-addr=%p, packet-addr=%p", - msg_it, msg_it->packet); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot create packet beginning message: " + "msg-it-addr={}, packet-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->packet)); goto end; } @@ -2424,7 +2480,6 @@ static bt_message *create_msg_packet_end(struct ctf_msg_iter *msg_it) { bt_message *msg; bool update_default_cs = true; - bt_self_component *self_comp = msg_it->self_comp; if (!msg_it->packet) { msg = NULL; @@ -2490,10 +2545,10 @@ static bt_message *create_msg_packet_end(struct ctf_msg_iter *msg_it) } if (!msg) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create packet end message: " - "msg-it-addr=%p, packet-addr=%p", - msg_it, msg_it->packet); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot create packet end message: " + "msg-it-addr={}, packet-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->packet)); goto end; } @@ -2506,7 +2561,6 @@ end: static bt_message *create_msg_discarded_events(struct ctf_msg_iter *msg_it) { bt_message *msg; - bt_self_component *self_comp = msg_it->self_comp; uint64_t beginning_raw_value = UINT64_C(-1); uint64_t end_raw_value = UINT64_C(-1); @@ -2537,10 +2591,10 @@ static bt_message *create_msg_discarded_events(struct ctf_msg_iter *msg_it) } if (!msg) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create discarded events message: " - "msg-it-addr=%p, stream-addr=%p", - msg_it, msg_it->stream); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot create discarded events message: " + "msg-it-addr={}, stream-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->stream)); goto end; } @@ -2557,7 +2611,6 @@ end: static bt_message *create_msg_discarded_packets(struct ctf_msg_iter *msg_it) { bt_message *msg; - bt_self_component *self_comp = msg_it->self_comp; BT_ASSERT(msg_it->self_msg_iter); BT_ASSERT(msg_it->stream); @@ -2575,10 +2628,10 @@ static bt_message *create_msg_discarded_packets(struct ctf_msg_iter *msg_it) } if (!msg) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create discarded packets message: " - "msg-it-addr=%p, stream-addr=%p", - msg_it, msg_it->stream); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot create discarded packets message: " + "msg-it-addr={}, stream-addr={}", + fmt::ptr(msg_it), fmt::ptr(msg_it->stream)); goto end; } @@ -2591,8 +2644,8 @@ end: struct ctf_msg_iter *ctf_msg_iter_create(struct ctf_trace_class *tc, size_t max_request_sz, struct ctf_msg_iter_medium_ops medops, void *data, - bt_logging_level log_level, bt_self_component *self_comp, - bt_self_message_iterator *self_msg_iter) + bt_self_message_iterator *self_msg_iter, + const bt2c::Logger& parentLogger) { struct bt_bfcr_cbs cbs = { .classes = @@ -2618,16 +2671,15 @@ struct ctf_msg_iter *ctf_msg_iter_create(struct ctf_trace_class *tc, size_t max_ BT_ASSERT(medops.borrow_stream); BT_ASSERT(max_request_sz > 0); - BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, log_level, self_comp, - "Creating CTF plugin message iterator: " - "trace-addr=%p, max-request-size=%zu, " - "data=%p, log-level=%s", - tc, max_request_sz, data, bt_common_logging_level_string(log_level)); + bt2c::Logger logger {parentLogger, "PLUGIN/CTF/MSG-ITER"}; + BT_CPPLOGD_SPEC(logger, + "Creating CTF plugin message iterator: " + "trace-addr={}, max-request-size={}, " + "data={}, log-level={}", + fmt::ptr(tc), max_request_sz, fmt::ptr(data), logger.level()); - ctf_msg_iter *msg_it = new ctf_msg_iter; - msg_it->self_comp = self_comp; + ctf_msg_iter *msg_it = new ctf_msg_iter {std::move(logger)}; msg_it->self_msg_iter = self_msg_iter; - msg_it->log_level = log_level; msg_it->meta.tc = tc; msg_it->medium.medops = medops; msg_it->medium.max_request_sz = max_request_sz; @@ -2637,21 +2689,24 @@ struct ctf_msg_iter *ctf_msg_iter_create(struct ctf_trace_class *tc, size_t max_ g_array_set_size(msg_it->stored_values, tc->stored_value_count); if (!msg_it->stack) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create field stack."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, "Failed to create field stack."); goto error; } - msg_it->bfcr = bt_bfcr_create(cbs, msg_it, log_level, NULL); + msg_it->bfcr = bt_bfcr_create(cbs, msg_it, msg_it->logger); if (!msg_it->bfcr) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create binary class reader (BFCR)."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Failed to create binary class reader (BFCR)."); goto error; } ctf_msg_iter_reset(msg_it); - BT_COMP_LOGD("Created CTF plugin message iterator: " - "trace-addr=%p, max-request-size=%zu, " - "data=%p, msg-it-addr=%p, log-level=%s", - tc, max_request_sz, data, msg_it, bt_common_logging_level_string(log_level)); + BT_CPPLOGD_SPEC(msg_it->logger, + "Created CTF plugin message iterator: " + "trace-addr={}, max-request-size={}, " + "data={}, msg-it-addr={}, log-level={}", + fmt::ptr(tc), max_request_sz, fmt::ptr(data), fmt::ptr(msg_it), + msg_it->logger.level()); msg_it->cur_packet_offset = 0; end: @@ -2669,15 +2724,16 @@ void ctf_msg_iter_destroy(struct ctf_msg_iter *msg_it) BT_STREAM_PUT_REF_AND_RESET(msg_it->stream); release_all_dscopes(msg_it); - BT_COMP_LOGD("Destroying CTF plugin message iterator: addr=%p", msg_it); + BT_CPPLOGD_SPEC(msg_it->logger, "Destroying CTF plugin message iterator: addr={}", + fmt::ptr(msg_it)); if (msg_it->stack) { - BT_COMP_LOGD_STR("Destroying field stack."); + BT_CPPLOGD_STR_SPEC(msg_it->logger, "Destroying field stack."); stack_destroy(msg_it->stack); } if (msg_it->bfcr) { - BT_COMP_LOGD("Destroying BFCR: bfcr-addr=%p", msg_it->bfcr); + BT_CPPLOGD_SPEC(msg_it->logger, "Destroying BFCR: bfcr-addr={}", fmt::ptr(msg_it->bfcr)); bt_bfcr_destroy(msg_it->bfcr); } @@ -2692,20 +2748,20 @@ enum ctf_msg_iter_status ctf_msg_iter_get_next_message(struct ctf_msg_iter *msg_ const bt_message **message) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; BT_ASSERT_DBG(msg_it); BT_ASSERT_DBG(message); - BT_COMP_LOGD("Getting next message: msg-it-addr=%p", msg_it); + BT_CPPLOGD_SPEC(msg_it->logger, "Getting next message: msg-it-addr={}", fmt::ptr(msg_it)); while (true) { status = handle_state(msg_it); if (G_UNLIKELY(status == CTF_MSG_ITER_STATUS_AGAIN)) { - BT_COMP_LOGD_STR("Medium returned CTF_MSG_ITER_STATUS_AGAIN."); + BT_CPPLOGD_STR_SPEC(msg_it->logger, "Medium returned CTF_MSG_ITER_STATUS_AGAIN."); goto end; } else if (G_UNLIKELY(status != CTF_MSG_ITER_STATUS_OK)) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot handle state: msg-it-addr=%p, state=%s", - msg_it, state_string(msg_it->state)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot handle state: msg-it-addr={}, state={}", + fmt::ptr(msg_it), msg_it->state); goto end; } @@ -2820,7 +2876,6 @@ static enum ctf_msg_iter_status decode_until_state(struct ctf_msg_iter *msg_it, enum state target_state_2) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; BT_ASSERT_DBG(msg_it); @@ -2835,11 +2890,12 @@ static enum ctf_msg_iter_status decode_until_state(struct ctf_msg_iter *msg_it, status = handle_state(msg_it); if (G_UNLIKELY(status == CTF_MSG_ITER_STATUS_AGAIN)) { - BT_COMP_LOGD_STR("Medium returned CTF_MSG_ITER_STATUS_AGAIN."); + BT_CPPLOGD_STR_SPEC(msg_it->logger, "Medium returned CTF_MSG_ITER_STATUS_AGAIN."); goto end; } else if (G_UNLIKELY(status != CTF_MSG_ITER_STATUS_OK)) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot handle state: msg-it-addr=%p, state=%s", - msg_it, state_string(msg_it->state)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_it->logger, + "Cannot handle state: msg-it-addr={}, state={}", + fmt::ptr(msg_it), msg_it->state); goto end; } @@ -2879,8 +2935,8 @@ static enum ctf_msg_iter_status decode_until_state(struct ctf_msg_iter *msg_it, /* fall-through */ default: /* We should never get to the STATE_DONE state. */ - BT_COMP_LOGF("Unexpected state: msg-it-addr=%p, state=%s", msg_it, - state_string(msg_it->state)); + BT_CPPLOGF_SPEC(msg_it->logger, "Unexpected state: msg-it-addr={}, state={}", + fmt::ptr(msg_it), msg_it->state); bt_common_abort(); } } while (true); diff --git a/src/plugins/ctf/common/src/msg-iter/msg-iter.hpp b/src/plugins/ctf/common/src/msg-iter/msg-iter.hpp index dea4615d..8ad58287 100644 --- a/src/plugins/ctf/common/src/msg-iter/msg-iter.hpp +++ b/src/plugins/ctf/common/src/msg-iter/msg-iter.hpp @@ -18,6 +18,12 @@ #include "../metadata/tsdl/ctf-meta.hpp" +namespace bt2c { + +class Logger; + +} /* namespace bt2c */ + /** * @file ctf-msg-iter.h * @@ -56,6 +62,28 @@ enum ctf_msg_iter_medium_status CTF_MSG_ITER_MEDIUM_STATUS_OK = 0, }; +inline const char *format_as(const ctf_msg_iter_medium_status status) noexcept +{ + switch (status) { + case CTF_MSG_ITER_MEDIUM_STATUS_EOF: + return "EOF"; + + case CTF_MSG_ITER_MEDIUM_STATUS_AGAIN: + return "AGAIN"; + + case CTF_MSG_ITER_MEDIUM_STATUS_ERROR: + return "ERROR"; + + case CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR: + return "MEMORY_ERROR"; + + case CTF_MSG_ITER_MEDIUM_STATUS_OK: + return "OK"; + } + + bt_common_abort(); +} + /** * CTF message iterator API status code. */ @@ -90,6 +118,28 @@ enum ctf_msg_iter_status CTF_MSG_ITER_STATUS_OK = CTF_MSG_ITER_MEDIUM_STATUS_OK, }; +inline const char *format_as(ctf_msg_iter_status status) noexcept +{ + switch (status) { + case CTF_MSG_ITER_STATUS_EOF: + return "EOF"; + + case CTF_MSG_ITER_STATUS_AGAIN: + return "AGAIN"; + + case CTF_MSG_ITER_STATUS_ERROR: + return "ERROR"; + + case CTF_MSG_ITER_STATUS_MEMORY_ERROR: + return "MEMORY_ERROR"; + + case CTF_MSG_ITER_STATUS_OK: + return "OK"; + } + + bt_common_abort(); +} + /** * Medium operations. * @@ -224,8 +274,8 @@ struct ctf_msg_iter_medium_ops */ struct ctf_msg_iter *ctf_msg_iter_create(struct ctf_trace_class *tc, size_t max_request_sz, struct ctf_msg_iter_medium_ops medops, void *medops_data, - bt_logging_level log_level, bt_self_component *self_comp, - bt_self_message_iterator *self_msg_iter); + bt_self_message_iterator *self_msg_iter, + const bt2c::Logger& logger); /** * Destroys a CTF message iterator, freeing all internal resources. @@ -302,40 +352,4 @@ void ctf_msg_iter_reset_for_next_stream_file(struct ctf_msg_iter *msg_it); void ctf_msg_iter_set_dry_run(struct ctf_msg_iter *msg_it, bool val); -static inline const char *ctf_msg_iter_medium_status_string(enum ctf_msg_iter_medium_status status) -{ - switch (status) { - case CTF_MSG_ITER_MEDIUM_STATUS_EOF: - return "EOF"; - case CTF_MSG_ITER_MEDIUM_STATUS_AGAIN: - return "AGAIN"; - case CTF_MSG_ITER_MEDIUM_STATUS_ERROR: - return "ERROR"; - case CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR: - return "MEMORY_ERROR"; - case CTF_MSG_ITER_MEDIUM_STATUS_OK: - return "OK"; - } - - bt_common_abort(); -} - -static inline const char *ctf_msg_iter_status_string(enum ctf_msg_iter_status status) -{ - switch (status) { - case CTF_MSG_ITER_STATUS_EOF: - return "EOF"; - case CTF_MSG_ITER_STATUS_AGAIN: - return "AGAIN"; - case CTF_MSG_ITER_STATUS_ERROR: - return "ERROR"; - case CTF_MSG_ITER_STATUS_MEMORY_ERROR: - return "MEMORY_ERROR"; - case CTF_MSG_ITER_STATUS_OK: - return "OK"; - } - - bt_common_abort(); -} - #endif /* CTF_MSG_ITER_H */ diff --git a/src/plugins/ctf/fs-src/data-stream-file.cpp b/src/plugins/ctf/fs-src/data-stream-file.cpp index 89afb04f..fe6a7c3e 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.cpp +++ b/src/plugins/ctf/fs-src/data-stream-file.cpp @@ -7,23 +7,12 @@ */ #include -#include #include #include -#include -#include - -#define BT_COMP_LOG_SELF_COMP (self_comp) -#define BT_LOG_OUTPUT_LEVEL (log_level) -#define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/DS" -#include - -#include "logging/comp-logging.h" - -#include "common/assert.h" #include "compat/endian.h" /* IWYU pragma: keep */ -#include "compat/mman.h" /* IWYU pragma: keep */ +#include "compat/mman.h" /* IWYU: pragma keep */ +#include "cpp-common/vendor/fmt/format.h" #include "../common/src/msg-iter/msg-iter.hpp" #include "data-stream-file.hpp" @@ -50,8 +39,6 @@ static bool offset_ist_mapped(struct ctf_fs_ds_file *ds_file, off_t offset_in_fi static enum ctf_msg_iter_medium_status ds_file_munmap(struct ctf_fs_ds_file *ds_file) { enum ctf_msg_iter_medium_status status; - bt_self_component *self_comp = ds_file->self_comp; - bt_logging_level log_level = ds_file->log_level; BT_ASSERT(ds_file); @@ -61,10 +48,11 @@ static enum ctf_msg_iter_medium_status ds_file_munmap(struct ctf_fs_ds_file *ds_ } if (bt_munmap(ds_file->mmap_addr, ds_file->mmap_len)) { - BT_COMP_LOGE_ERRNO("Cannot memory-unmap file", - ": address=%p, size=%zu, file_path=\"%s\", file=%p", ds_file->mmap_addr, - ds_file->mmap_len, ds_file->file ? ds_file->file->path->str : "NULL", - ds_file->file ? ds_file->file->fp : NULL); + BT_CPPLOGE_ERRNO_SPEC(ds_file->logger, "Cannot memory-unmap file", + ": address={}, size={}, file_path=\"{}\", file={}", + fmt::ptr(ds_file->mmap_addr), ds_file->mmap_len, + ds_file->file ? ds_file->file->path->str : "NULL", + ds_file->file ? fmt::ptr(ds_file->file->fp) : NULL); status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR; goto end; } @@ -91,8 +79,6 @@ static enum ctf_msg_iter_medium_status ds_file_mmap(struct ctf_fs_ds_file *ds_fi off_t requested_offset_in_file) { enum ctf_msg_iter_medium_status status; - bt_self_component *self_comp = ds_file->self_comp; - bt_logging_level log_level = ds_file->log_level; /* Ensure the requested offset is in the file range. */ BT_ASSERT(requested_offset_in_file >= 0); @@ -120,7 +106,8 @@ static enum ctf_msg_iter_medium_status ds_file_mmap(struct ctf_fs_ds_file *ds_fi * contains `requested_offset_in_file`. */ ds_file->request_offset_in_mapping = - requested_offset_in_file % bt_mmap_get_offset_align_size(ds_file->log_level); + requested_offset_in_file % + bt_mmap_get_offset_align_size(static_cast(ds_file->logger.level())); ds_file->mmap_offset_in_file = requested_offset_in_file - ds_file->request_offset_in_mapping; ds_file->mmap_len = MIN(ds_file->file->size - ds_file->mmap_offset_in_file, ds_file->mmap_max_len); @@ -129,11 +116,12 @@ static enum ctf_msg_iter_medium_status ds_file_mmap(struct ctf_fs_ds_file *ds_fi ds_file->mmap_addr = bt_mmap(ds_file->mmap_len, PROT_READ, MAP_PRIVATE, fileno(ds_file->file->fp), - ds_file->mmap_offset_in_file, ds_file->log_level); + ds_file->mmap_offset_in_file, static_cast(ds_file->logger.level())); if (ds_file->mmap_addr == MAP_FAILED) { - BT_COMP_LOGE("Cannot memory-map address (size %zu) of file \"%s\" (%p) at offset %jd: %s", - ds_file->mmap_len, ds_file->file->path->str, ds_file->file->fp, - (intmax_t) ds_file->mmap_offset_in_file, strerror(errno)); + BT_CPPLOGE_SPEC(ds_file->logger, + "Cannot memory-map address (size {}) of file \"{}\" ({}) at offset {}: {}", + ds_file->mmap_len, ds_file->file->path->str, fmt::ptr(ds_file->file->fp), + (intmax_t) ds_file->mmap_offset_in_file, strerror(errno)); status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR; goto end; } @@ -185,8 +173,6 @@ static enum ctf_msg_iter_medium_status medop_request_bytes(size_t request_sz, ui { enum ctf_msg_iter_medium_status status = CTF_MSG_ITER_MEDIUM_STATUS_OK; struct ctf_fs_ds_file *ds_file = (struct ctf_fs_ds_file *) data; - bt_self_component *self_comp = ds_file->self_comp; - bt_logging_level log_level = ds_file->log_level; BT_ASSERT(request_sz > 0); @@ -197,8 +183,8 @@ static enum ctf_msg_iter_medium_status medop_request_bytes(size_t request_sz, ui if (remaining_mmap_bytes(ds_file) == 0) { /* Are we at the end of the file? */ if (ds_file->mmap_offset_in_file >= ds_file->file->size) { - BT_COMP_LOGD("Reached end of file \"%s\" (%p)", ds_file->file->path->str, - ds_file->file->fp); + BT_CPPLOGD_SPEC(ds_file->logger, "Reached end of file \"{}\" ({})", + ds_file->file->path->str, fmt::ptr(ds_file->file->fp)); status = CTF_MSG_ITER_MEDIUM_STATUS_EOF; goto end; } @@ -210,8 +196,8 @@ static enum ctf_msg_iter_medium_status medop_request_bytes(size_t request_sz, ui case CTF_MSG_ITER_MEDIUM_STATUS_EOF: goto end; default: - BT_COMP_LOGE("Cannot memory-map next region of file \"%s\" (%p)", - ds_file->file->path->str, ds_file->file->fp); + BT_CPPLOGE_SPEC(ds_file->logger, "Cannot memory-map next region of file \"{}\" ({})", + ds_file->file->path->str, fmt::ptr(ds_file->file->fp)); goto error; } } @@ -273,6 +259,13 @@ struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops = { struct ctf_fs_ds_group_medops_data { + explicit ctf_fs_ds_group_medops_data(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.FS/DS-GROUP-MEDOPS"} + { + } + + bt2c::Logger logger; + /* Weak, set once at creation time. */ struct ctf_fs_ds_file_group *ds_file_group = nullptr; @@ -293,7 +286,6 @@ struct ctf_fs_ds_group_medops_data /* Weak, for context / logging / appending causes. */ bt_self_message_iterator *self_msg_iter = nullptr; - bt_logging_level log_level = (bt_logging_level) 0; }; static enum ctf_msg_iter_medium_status medop_group_request_bytes(size_t request_sz, @@ -321,8 +313,7 @@ static bt_stream *medop_group_borrow_stream(bt_stream_class *stream_class, int64 static enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_set_file(struct ctf_fs_ds_group_medops_data *data, - struct ctf_fs_ds_index_entry *index_entry, - bt_self_message_iterator *self_msg_iter, bt_logging_level log_level) + struct ctf_fs_ds_index_entry *index_entry) { enum ctf_msg_iter_medium_status status; @@ -337,9 +328,9 @@ ctf_fs_ds_group_medops_set_file(struct ctf_fs_ds_group_medops_data *data, /* Create the new file. */ data->file = ctf_fs_ds_file_create(data->ds_file_group->ctf_fs_trace, data->ds_file_group->stream, - index_entry->path, log_level); + index_entry->path, data->logger); if (!data->file) { - BT_MSG_ITER_LOGE_APPEND_CAUSE(self_msg_iter, "failed to create ctf_fs_ds_file."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(data->logger, "failed to create ctf_fs_ds_file."); status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR; goto end; } @@ -379,8 +370,7 @@ static enum ctf_msg_iter_medium_status medop_group_switch_packet(void *void_data index_entry = (struct ctf_fs_ds_index_entry *) g_ptr_array_index( data->ds_file_group->index->entries, data->next_index_entry_index); - status = - ctf_fs_ds_group_medops_set_file(data, index_entry, data->self_msg_iter, data->log_level); + status = ctf_fs_ds_group_medops_set_file(data, index_entry); if (status != CTF_MSG_ITER_MEDIUM_STATUS_OK) { goto end; } @@ -408,17 +398,16 @@ end: enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create( struct ctf_fs_ds_file_group *ds_file_group, bt_self_message_iterator *self_msg_iter, - bt_logging_level log_level, struct ctf_fs_ds_group_medops_data **out) + const bt2c::Logger& parentLogger, struct ctf_fs_ds_group_medops_data **out) { BT_ASSERT(self_msg_iter); BT_ASSERT(ds_file_group); BT_ASSERT(ds_file_group->index); BT_ASSERT(ds_file_group->index->entries->len > 0); - ctf_fs_ds_group_medops_data *data = new ctf_fs_ds_group_medops_data; + ctf_fs_ds_group_medops_data *data = new ctf_fs_ds_group_medops_data {parentLogger}; data->ds_file_group = ds_file_group; data->self_msg_iter = self_msg_iter; - data->log_level = log_level; /* * No need to prepare the first file. ctf_msg_iter will call @@ -490,39 +479,41 @@ static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file * struct ctf_stream_class *sc; struct ctf_msg_iter_packet_properties props; uint32_t version_major, version_minor; - bt_self_component *self_comp = ds_file->self_comp; - bt_logging_level log_level = ds_file->log_level; - BT_COMP_LOGI("Building index from .idx file of stream file %s", ds_file->file->path->str); + BT_CPPLOGI_SPEC(ds_file->logger, "Building index from .idx file of stream file {}", + ds_file->file->path->str); ret = ctf_msg_iter_get_packet_properties(msg_iter, &props); if (ret) { - BT_COMP_LOGI_STR("Cannot read first packet's header and context fields."); + BT_CPPLOGI_STR_SPEC(ds_file->logger, + "Cannot read first packet's header and context fields."); goto error; } sc = ctf_trace_class_borrow_stream_class_by_id(ds_file->metadata->tc, props.stream_class_id); BT_ASSERT(sc); if (!sc->default_clock_class) { - BT_COMP_LOGI_STR("Cannot find stream class's default clock class."); + BT_CPPLOGI_STR_SPEC(ds_file->logger, "Cannot find stream class's default clock class."); goto error; } /* Look for index file in relative path index/name.idx. */ basename = g_path_get_basename(ds_file->file->path->str); if (!basename) { - BT_COMP_LOGE("Cannot get the basename of datastream file %s", ds_file->file->path->str); + BT_CPPLOGE_SPEC(ds_file->logger, "Cannot get the basename of datastream file {}", + ds_file->file->path->str); goto error; } directory = g_path_get_dirname(ds_file->file->path->str); if (!directory) { - BT_COMP_LOGE("Cannot get dirname of datastream file %s", ds_file->file->path->str); + BT_CPPLOGE_SPEC(ds_file->logger, "Cannot get dirname of datastream file {}", + ds_file->file->path->str); goto error; } index_basename = g_string_new(basename); if (!index_basename) { - BT_COMP_LOGE_STR("Cannot allocate index file basename string"); + BT_CPPLOGE_STR_SPEC(ds_file->logger, "Cannot allocate index file basename string"); goto error; } @@ -530,7 +521,7 @@ static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file * index_file_path = g_build_filename(directory, "index", index_basename->str, NULL); mapped_file = g_mapped_file_new(index_file_path, FALSE, NULL); if (!mapped_file) { - BT_COMP_LOGD("Cannot create new mapped file %s", index_file_path); + BT_CPPLOGD_SPEC(ds_file->logger, "Cannot create new mapped file {}", index_file_path); goto error; } @@ -541,9 +532,10 @@ static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file * */ filesize = g_mapped_file_get_length(mapped_file); if (filesize < sizeof(*header)) { - BT_COMP_LOGW("Invalid LTTng trace index file: " - "file size (%zu bytes) < header size (%zu bytes)", - filesize, sizeof(*header)); + BT_CPPLOGW_SPEC(ds_file->logger, + "Invalid LTTng trace index file: " + "file size ({} bytes) < header size ({} bytes)", + filesize, sizeof(*header)); goto error; } @@ -552,38 +544,40 @@ static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file * file_pos = g_mapped_file_get_contents(mapped_file) + sizeof(*header); if (be32toh(header->magic) != CTF_INDEX_MAGIC) { - BT_COMP_LOGW_STR("Invalid LTTng trace index: \"magic\" field validation failed"); + BT_CPPLOGW_STR_SPEC(ds_file->logger, + "Invalid LTTng trace index: \"magic\" field validation failed"); goto error; } version_major = be32toh(header->index_major); version_minor = be32toh(header->index_minor); if (version_major != 1) { - BT_COMP_LOGW("Unknown LTTng trace index version: " - "major=%" PRIu32 ", minor=%" PRIu32, - version_major, version_minor); + BT_CPPLOGW_SPEC(ds_file->logger, "Unknown LTTng trace index version: major={}, minor={}", + version_major, version_minor); goto error; } file_index_entry_size = be32toh(header->packet_index_len); if (file_index_entry_size < CTF_INDEX_1_0_SIZE) { - BT_COMP_LOGW( + BT_CPPLOGW_SPEC( + ds_file->logger, "Invalid `packet_index_len` in LTTng trace index file (`packet_index_len` < CTF index 1.0 index entry size): " - "packet_index_len=%zu, CTF_INDEX_1_0_SIZE=%zu", + "packet_index_len={}, CTF_INDEX_1_0_SIZE={}", file_index_entry_size, CTF_INDEX_1_0_SIZE); goto error; } file_entry_count = (filesize - sizeof(*header)) / file_index_entry_size; if ((filesize - sizeof(*header)) % file_index_entry_size) { - BT_COMP_LOGW("Invalid LTTng trace index: the index's size after the header " - "(%zu bytes) is not a multiple of the index entry size " - "(%zu bytes)", - (filesize - sizeof(*header)), sizeof(*header)); + BT_CPPLOGW_SPEC(ds_file->logger, + "Invalid LTTng trace index: the index's size after the header " + "({} bytes) is not a multiple of the index entry size " + "({} bytes)", + (filesize - sizeof(*header)), sizeof(*header)); goto error; } - index = ctf_fs_ds_index_create(ds_file->log_level, ds_file->self_comp); + index = ctf_fs_ds_index_create(ds_file->logger); if (!index) { goto error; } @@ -593,14 +587,15 @@ static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file * uint64_t packet_size = be64toh(file_index->packet_size); if (packet_size % CHAR_BIT) { - BT_COMP_LOGW("Invalid packet size encountered in LTTng trace index file"); + BT_CPPLOGW_SPEC(ds_file->logger, + "Invalid packet size encountered in LTTng trace index file"); goto error; } index_entry = ctf_fs_ds_index_entry_create(); if (!index_entry) { - BT_COMP_LOGE_APPEND_CAUSE(ds_file->self_comp, - "Failed to create a ctf_fs_ds_index_entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ds_file->logger, + "Failed to create a ctf_fs_ds_index_entry."); goto error; } @@ -613,9 +608,10 @@ static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file * index_entry->offset = be64toh(file_index->offset); if (i != 0 && index_entry->offset < prev_index_entry->offset) { - BT_COMP_LOGW( + BT_CPPLOGW_SPEC( + ds_file->logger, "Invalid, non-monotonic, packet offset encountered in LTTng trace index file: " - "previous offset=%" PRIu64 ", current offset=%" PRIu64, + "previous offset={}, current offset={}", prev_index_entry->offset, index_entry->offset); goto error; } @@ -623,9 +619,10 @@ static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file * index_entry->timestamp_begin = be64toh(file_index->timestamp_begin); index_entry->timestamp_end = be64toh(file_index->timestamp_end); if (index_entry->timestamp_end < index_entry->timestamp_begin) { - BT_COMP_LOGW( + BT_CPPLOGW_SPEC( + ds_file->logger, "Invalid packet time bounds encountered in LTTng trace index file (begin > end): " - "timestamp_begin=%" PRIu64 "timestamp_end=%" PRIu64, + "timestamp_begin={}, timestamp_end={}", index_entry->timestamp_begin, index_entry->timestamp_end); goto error; } @@ -634,14 +631,16 @@ static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file * ret = convert_cycles_to_ns(sc->default_clock_class, index_entry->timestamp_begin, &index_entry->timestamp_begin_ns); if (ret) { - BT_COMP_LOGI_STR( + BT_CPPLOGI_STR_SPEC( + ds_file->logger, "Failed to convert raw timestamp to nanoseconds since Epoch during index parsing"); goto error; } ret = convert_cycles_to_ns(sc->default_clock_class, index_entry->timestamp_end, &index_entry->timestamp_end_ns); if (ret) { - BT_COMP_LOGI_STR( + BT_CPPLOGI_STR_SPEC( + ds_file->logger, "Failed to convert raw timestamp to nanoseconds since Epoch during LTTng trace index parsing"); goto error; } @@ -662,9 +661,10 @@ static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file * /* Validate that the index addresses the complete stream. */ if (ds_file->file->size != total_packets_size) { - BT_COMP_LOGW("Invalid LTTng trace index file; indexed size != stream file size: " - "file-size=%" PRIu64 ", total-packets-size=%" PRIu64, - ds_file->file->size, total_packets_size); + BT_CPPLOGW_SPEC(ds_file->logger, + "Invalid LTTng trace index file; indexed size != stream file size: " + "file-size={}, total-packets-size={}", + ds_file->file->size, total_packets_size); goto error; } end: @@ -691,8 +691,6 @@ static int init_index_entry(struct ctf_fs_ds_index_entry *entry, struct ctf_fs_d { int ret = 0; struct ctf_stream_class *sc; - bt_self_component *self_comp = ds_file->self_comp; - bt_logging_level log_level = ds_file->log_level; sc = ctf_trace_class_borrow_stream_class_by_id(ds_file->metadata->tc, props->stream_class_id); BT_ASSERT(sc); @@ -708,7 +706,8 @@ static int init_index_entry(struct ctf_fs_ds_index_entry *entry, struct ctf_fs_d ret = convert_cycles_to_ns(sc->default_clock_class, props->snapshots.beginning_clock, &entry->timestamp_begin_ns); if (ret) { - BT_COMP_LOGI_STR("Failed to convert raw timestamp to nanoseconds since Epoch."); + BT_CPPLOGI_STR_SPEC(ds_file->logger, + "Failed to convert raw timestamp to nanoseconds since Epoch."); goto end; } } else { @@ -723,7 +722,8 @@ static int init_index_entry(struct ctf_fs_ds_index_entry *entry, struct ctf_fs_d ret = convert_cycles_to_ns(sc->default_clock_class, props->snapshots.end_clock, &entry->timestamp_end_ns); if (ret) { - BT_COMP_LOGI_STR("Failed to convert raw timestamp to nanoseconds since Epoch."); + BT_CPPLOGI_STR_SPEC(ds_file->logger, + "Failed to convert raw timestamp to nanoseconds since Epoch."); goto end; } } else { @@ -743,12 +743,10 @@ static struct ctf_fs_ds_index *build_index_from_stream_file(struct ctf_fs_ds_fil struct ctf_fs_ds_index *index = NULL; enum ctf_msg_iter_status iter_status = CTF_MSG_ITER_STATUS_OK; off_t current_packet_offset_bytes = 0; - bt_self_component *self_comp = ds_file->self_comp; - bt_logging_level log_level = ds_file->log_level; - BT_COMP_LOGI("Indexing stream file %s", ds_file->file->path->str); + BT_CPPLOGI_SPEC(ds_file->logger, "Indexing stream file {}", ds_file->file->path->str); - index = ctf_fs_ds_index_create(ds_file->log_level, ds_file->self_comp); + index = ctf_fs_ds_index_create(ds_file->logger); if (!index) { goto error; } @@ -759,10 +757,11 @@ static struct ctf_fs_ds_index *build_index_from_stream_file(struct ctf_fs_ds_fil struct ctf_msg_iter_packet_properties props; if (current_packet_offset_bytes < 0) { - BT_COMP_LOGE_STR("Cannot get the current packet's offset."); + BT_CPPLOGE_STR_SPEC(ds_file->logger, "Cannot get the current packet's offset."); goto error; } else if (current_packet_offset_bytes > ds_file->file->size) { - BT_COMP_LOGE_STR("Unexpected current packet's offset (larger than file)."); + BT_CPPLOGE_STR_SPEC(ds_file->logger, + "Unexpected current packet's offset (larger than file)."); goto error; } else if (current_packet_offset_bytes == ds_file->file->size) { /* No more data */ @@ -786,18 +785,19 @@ static struct ctf_fs_ds_index *build_index_from_stream_file(struct ctf_fs_ds_fil } if (current_packet_offset_bytes + current_packet_size_bytes > ds_file->file->size) { - BT_COMP_LOGW("Invalid packet size reported in file: stream=\"%s\", " - "packet-offset=%jd, packet-size-bytes=%jd, " - "file-size=%jd", - ds_file->file->path->str, (intmax_t) current_packet_offset_bytes, - (intmax_t) current_packet_size_bytes, (intmax_t) ds_file->file->size); + BT_CPPLOGW_SPEC(ds_file->logger, + "Invalid packet size reported in file: stream=\"{}\", " + "packet-offset={}, packet-size-bytes={}, " + "file-size={}", + ds_file->file->path->str, (intmax_t) current_packet_offset_bytes, + (intmax_t) current_packet_size_bytes, (intmax_t) ds_file->file->size); goto error; } index_entry = ctf_fs_ds_index_entry_create(); if (!index_entry) { - BT_COMP_LOGE_APPEND_CAUSE(ds_file->self_comp, - "Failed to create a ctf_fs_ds_index_entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ds_file->logger, + "Failed to create a ctf_fs_ds_index_entry."); goto error; } @@ -814,10 +814,11 @@ static struct ctf_fs_ds_index *build_index_from_stream_file(struct ctf_fs_ds_fil g_ptr_array_add(index->entries, index_entry); current_packet_offset_bytes += current_packet_size_bytes; - BT_COMP_LOGD("Seeking to next packet: current-packet-offset=%jd, " - "next-packet-offset=%jd", - (intmax_t) (current_packet_offset_bytes - current_packet_size_bytes), - (intmax_t) current_packet_offset_bytes); + BT_CPPLOGD_SPEC(ds_file->logger, + "Seeking to next packet: current-packet-offset={}, " + "next-packet-offset={}", + (intmax_t) (current_packet_offset_bytes - current_packet_size_bytes), + (intmax_t) current_packet_offset_bytes); } end: @@ -830,19 +831,17 @@ error: } struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream, - const char *path, bt_logging_level log_level) + const char *path, const bt2c::Logger& parentLogger) { int ret; - const size_t offset_align = bt_mmap_get_offset_align_size(log_level); - ctf_fs_ds_file *ds_file = new ctf_fs_ds_file; + size_t offset_align; + ctf_fs_ds_file *ds_file = new ctf_fs_ds_file {parentLogger}; if (!ds_file) { goto error; } - ds_file->log_level = log_level; - ds_file->self_comp = ctf_fs_trace->self_comp; - ds_file->file = ctf_fs_file_create(log_level, ds_file->self_comp); + ds_file->file = ctf_fs_file_create(parentLogger); if (!ds_file->file) { goto error; } @@ -856,6 +855,7 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, goto error; } + offset_align = bt_mmap_get_offset_align_size(static_cast(ds_file->logger.level())); ds_file->mmap_max_len = offset_align * 2048; goto end; @@ -874,29 +874,25 @@ struct ctf_fs_ds_index *ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_fil struct ctf_msg_iter *msg_iter) { struct ctf_fs_ds_index *index; - bt_self_component *self_comp = ds_file->self_comp; - bt_logging_level log_level = ds_file->log_level; index = build_index_from_idx_file(ds_file, file_info, msg_iter); if (index) { goto end; } - BT_COMP_LOGI("Failed to build index from .index file; " - "falling back to stream indexing."); + BT_CPPLOGI_SPEC(ds_file->logger, "Failed to build index from .index file; " + "falling back to stream indexing."); index = build_index_from_stream_file(ds_file, file_info, msg_iter); end: return index; } -struct ctf_fs_ds_index *ctf_fs_ds_index_create(bt_logging_level log_level, - bt_self_component *self_comp) +struct ctf_fs_ds_index *ctf_fs_ds_index_create(const bt2c::Logger& logger) { ctf_fs_ds_index *index = new ctf_fs_ds_index; index->entries = g_ptr_array_new_with_free_func((GDestroyNotify) ctf_fs_ds_index_entry_destroy); if (!index->entries) { - BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp, - "Failed to allocate index entries."); + BT_CPPLOGE_SPEC(logger, "Failed to allocate index entries."); goto error; } diff --git a/src/plugins/ctf/fs-src/data-stream-file.hpp b/src/plugins/ctf/fs-src/data-stream-file.hpp index f0e7edda..ecf450f4 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.hpp +++ b/src/plugins/ctf/fs-src/data-stream-file.hpp @@ -12,6 +12,8 @@ #include +#include "cpp-common/bt2c/logging.hpp" + #include "../common/src/msg-iter/msg-iter.hpp" struct ctf_fs_ds_file_info @@ -25,10 +27,12 @@ struct ctf_fs_ds_file_info struct ctf_fs_ds_file { - bt_logging_level log_level = (bt_logging_level) 0; + explicit ctf_fs_ds_file(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.FS/DS"} + { + } - /* Weak */ - bt_self_component *self_comp = nullptr; + bt2c::Logger logger; /* Weak */ struct ctf_fs_metadata *metadata = nullptr; @@ -61,7 +65,7 @@ struct ctf_fs_ds_file }; struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream, - const char *path, bt_logging_level log_level); + const char *path, const bt2c::Logger& logger); void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *stream); @@ -69,8 +73,7 @@ struct ctf_fs_ds_index *ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_fil struct ctf_fs_ds_file_info *ds_file_info, struct ctf_msg_iter *msg_iter); -struct ctf_fs_ds_index *ctf_fs_ds_index_create(bt_logging_level log_level, - bt_self_component *self_comp); +struct ctf_fs_ds_index *ctf_fs_ds_index_create(const bt2c::Logger& logger); void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index *index); @@ -93,7 +96,7 @@ extern struct ctf_msg_iter_medium_ops ctf_fs_ds_group_medops; enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create( struct ctf_fs_ds_file_group *ds_file_group, bt_self_message_iterator *self_msg_iter, - bt_logging_level log_level, struct ctf_fs_ds_group_medops_data **out); + const bt2c::Logger& logger, struct ctf_fs_ds_group_medops_data **out); void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data); diff --git a/src/plugins/ctf/fs-src/file.cpp b/src/plugins/ctf/fs-src/file.cpp index 5184de45..ea92ab13 100644 --- a/src/plugins/ctf/fs-src/file.cpp +++ b/src/plugins/ctf/fs-src/file.cpp @@ -8,10 +8,7 @@ #include #include -#define BT_COMP_LOG_SELF_COMP (file->self_comp) -#define BT_LOG_OUTPUT_LEVEL (file->log_level) -#define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/FILE" -#include "logging/comp-logging.h" +#include "cpp-common/vendor/fmt/format.h" #include "file.hpp" #include "fs.hpp" @@ -23,11 +20,12 @@ void ctf_fs_file_destroy(struct ctf_fs_file *file) } if (file->fp) { - BT_COMP_LOGD("Closing file \"%s\" (%p)", file->path ? file->path->str : NULL, file->fp); + BT_CPPLOGD_SPEC(file->logger, "Closing file \"{}\" ({})", + file->path ? file->path->str : NULL, fmt::ptr(file->fp)); if (fclose(file->fp)) { - BT_COMP_LOGE("Cannot close file \"%s\": %s", file->path ? file->path->str : "NULL", - strerror(errno)); + BT_CPPLOGE_SPEC(file->logger, "Cannot close file \"{}\": {}", + file->path ? file->path->str : "NULL", strerror(errno)); } } @@ -38,11 +36,9 @@ void ctf_fs_file_destroy(struct ctf_fs_file *file) delete file; } -struct ctf_fs_file *ctf_fs_file_create(bt_logging_level log_level, bt_self_component *self_comp) +struct ctf_fs_file *ctf_fs_file_create(const bt2c::Logger& parentLogger) { - ctf_fs_file *file = new ctf_fs_file; - file->log_level = log_level; - file->self_comp = self_comp; + ctf_fs_file *file = new ctf_fs_file {parentLogger}; file->path = g_string_new(NULL); if (!file->path) { goto error; @@ -63,24 +59,24 @@ int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode) int ret = 0; struct stat stat; - BT_COMP_LOGI("Opening file \"%s\" with mode \"%s\"", file->path->str, mode); + BT_CPPLOGI_SPEC(file->logger, "Opening file \"{}\" with mode \"{}\"", file->path->str, mode); file->fp = fopen(file->path->str, mode); if (!file->fp) { - BT_COMP_LOGE_APPEND_CAUSE_ERRNO(file->self_comp, "Cannot open file", ": path=%s, mode=%s", - file->path->str, mode); + BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot open file", ": path={}, mode={}", + file->path->str, mode); goto error; } - BT_COMP_LOGI("Opened file: %p", file->fp); + BT_CPPLOGI_SPEC(file->logger, "Opened file: {}", fmt::ptr(file->fp)); if (fstat(fileno(file->fp), &stat)) { - BT_COMP_LOGE_APPEND_CAUSE_ERRNO(file->self_comp, "Cannot get file information", ": path=%s", - file->path->str); + BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot get file information", ": path={}", + file->path->str); goto error; } file->size = stat.st_size; - BT_COMP_LOGI("File is %jd bytes", (intmax_t) file->size); + BT_CPPLOGI_SPEC(file->logger, "File is {} bytes", (intmax_t) file->size); goto end; error: @@ -88,7 +84,8 @@ error: if (file->fp) { if (fclose(file->fp)) { - BT_COMP_LOGE("Cannot close file \"%s\": %s", file->path->str, strerror(errno)); + BT_CPPLOGE_SPEC(file->logger, "Cannot close file \"{}\": {}", file->path->str, + strerror(errno)); } } diff --git a/src/plugins/ctf/fs-src/file.hpp b/src/plugins/ctf/fs-src/file.hpp index 779c9177..8fc01157 100644 --- a/src/plugins/ctf/fs-src/file.hpp +++ b/src/plugins/ctf/fs-src/file.hpp @@ -9,9 +9,15 @@ #include +namespace bt2c { + +class Logger; + +} /* namespace bt2c */ + void ctf_fs_file_destroy(struct ctf_fs_file *file); -struct ctf_fs_file *ctf_fs_file_create(bt_logging_level log_level, bt_self_component *self_comp); +struct ctf_fs_file *ctf_fs_file_create(const bt2c::Logger& parentLogger); int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode); diff --git a/src/plugins/ctf/fs-src/fs.cpp b/src/plugins/ctf/fs-src/fs.cpp index 4ffe410b..8a8fb434 100644 --- a/src/plugins/ctf/fs-src/fs.cpp +++ b/src/plugins/ctf/fs-src/fs.cpp @@ -12,11 +12,6 @@ #include -#define BT_COMP_LOG_SELF_COMP self_comp -#define BT_LOG_OUTPUT_LEVEL ((enum bt_log_level) log_level) -#define BT_LOG_TAG "PLUGIN/SRC.CTF.FS" -#include "logging/comp-logging.h" - #include "common/assert.h" #include "common/common.h" #include "common/uuid.h" @@ -61,7 +56,6 @@ ctf_fs_iterator_next_one(struct ctf_fs_msg_iter_data *msg_iter_data, const bt_me { bt_message_iterator_class_next_method_status status; enum ctf_msg_iter_status msg_iter_status; - bt_logging_level log_level = msg_iter_data->log_level; msg_iter_status = ctf_msg_iter_get_next_message(msg_iter_data->msg_iter, out_msg); @@ -84,14 +78,14 @@ ctf_fs_iterator_next_one(struct ctf_fs_msg_iter_data *msg_iter_data, const bt_me bt_common_abort(); case CTF_MSG_ITER_STATUS_ERROR: - BT_MSG_ITER_LOGE_APPEND_CAUSE(msg_iter_data->self_msg_iter, - "Failed to get next message from CTF message iterator."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_iter_data->logger, + "Failed to get next message from CTF message iterator."); status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR; break; case CTF_MSG_ITER_STATUS_MEMORY_ERROR: - BT_MSG_ITER_LOGE_APPEND_CAUSE(msg_iter_data->self_msg_iter, - "Failed to get next message from CTF message iterator."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_iter_data->logger, + "Failed to get next message from CTF message iterator."); status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_MEMORY_ERROR; break; @@ -205,39 +199,36 @@ ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter, { struct ctf_fs_port_data *port_data; bt_message_iterator_class_initialize_method_status status; - bt_logging_level log_level; enum ctf_msg_iter_medium_status medium_status; - bt_self_component *self_comp = bt_self_message_iterator_borrow_component(self_msg_iter); port_data = (struct ctf_fs_port_data *) bt_self_component_port_get_data( bt_self_component_port_output_as_self_component_port(self_port)); BT_ASSERT(port_data); - log_level = port_data->ctf_fs->log_level; - ctf_fs_msg_iter_data *msg_iter_data = new ctf_fs_msg_iter_data; - msg_iter_data->log_level = log_level; - msg_iter_data->self_comp = self_comp; - msg_iter_data->self_msg_iter = self_msg_iter; + ctf_fs_msg_iter_data *msg_iter_data = new ctf_fs_msg_iter_data {self_msg_iter}; msg_iter_data->ds_file_group = port_data->ds_file_group; - medium_status = - ctf_fs_ds_group_medops_data_create(msg_iter_data->ds_file_group, self_msg_iter, log_level, - &msg_iter_data->msg_iter_medops_data); + medium_status = ctf_fs_ds_group_medops_data_create(msg_iter_data->ds_file_group, self_msg_iter, + msg_iter_data->logger, + &msg_iter_data->msg_iter_medops_data); BT_ASSERT(medium_status == CTF_MSG_ITER_MEDIUM_STATUS_OK || medium_status == CTF_MSG_ITER_MEDIUM_STATUS_ERROR || medium_status == CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR); if (medium_status != CTF_MSG_ITER_MEDIUM_STATUS_OK) { - BT_MSG_ITER_LOGE_APPEND_CAUSE(self_msg_iter, "Failed to create ctf_fs_ds_group_medops"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_iter_data->logger, + "Failed to create ctf_fs_ds_group_medops"); status = ctf_msg_iter_medium_status_to_msg_iter_initialize_status(medium_status); goto error; } msg_iter_data->msg_iter = ctf_msg_iter_create( msg_iter_data->ds_file_group->ctf_fs_trace->metadata->tc, - bt_common_get_page_size(msg_iter_data->log_level) * 8, ctf_fs_ds_group_medops, - msg_iter_data->msg_iter_medops_data, msg_iter_data->log_level, self_comp, self_msg_iter); + bt_common_get_page_size(static_cast(msg_iter_data->logger.level())) * 8, + ctf_fs_ds_group_medops, msg_iter_data->msg_iter_medops_data, self_msg_iter, + msg_iter_data->logger); if (!msg_iter_data->msg_iter) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot create a CTF message iterator."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(msg_iter_data->logger, + "Cannot create a CTF message iterator."); status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto error; } @@ -323,10 +314,9 @@ static void ctf_fs_trace_destroy_notifier(void *data) ctf_fs_trace_destroy(trace); } -struct ctf_fs_component *ctf_fs_component_create(bt_logging_level log_level) +ctf_fs_component *ctf_fs_component_create(const bt2c::Logger& parentLogger) { - ctf_fs_component *ctf_fs = new ctf_fs_component; - ctf_fs->log_level = log_level; + ctf_fs_component *ctf_fs = new ctf_fs_component {parentLogger}; ctf_fs->port_data = g_ptr_array_new_with_free_func(port_data_destroy_notifier); if (!ctf_fs->port_data) { goto error; @@ -399,15 +389,13 @@ static int create_one_port_for_trace(struct ctf_fs_component *ctf_fs, int ret = 0; struct ctf_fs_port_data *port_data = NULL; gchar *port_name; - bt_logging_level log_level = ctf_fs->log_level; - bt_self_component *self_comp = bt_self_component_source_as_self_component(self_comp_src); port_name = ctf_fs_make_port_name(ds_file_group); if (!port_name) { goto error; } - BT_COMP_LOGI("Creating one port named `%s`", port_name); + BT_CPPLOGI_SPEC(ctf_fs->logger, "Creating one port named `{}`", port_name); /* Create output port for this file */ port_data = new ctf_fs_port_data; @@ -438,8 +426,6 @@ static int create_ports_for_trace(struct ctf_fs_component *ctf_fs, { int ret = 0; size_t i; - bt_logging_level log_level = ctf_fs_trace->log_level; - bt_self_component *self_comp = bt_self_component_source_as_self_component(self_comp_src); /* Create one output port for each stream file group */ for (i = 0; i < ctf_fs_trace->ds_file_groups->len; i++) { @@ -448,7 +434,7 @@ static int create_ports_for_trace(struct ctf_fs_component *ctf_fs, ret = create_one_port_for_trace(ctf_fs, ds_file_group, self_comp_src); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot create output port."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Cannot create output port."); goto end; } } @@ -663,25 +649,23 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const struct ctf_msg_iter *msg_iter = NULL; struct ctf_stream_class *sc = NULL; struct ctf_msg_iter_packet_properties props; - bt_logging_level log_level = ctf_fs_trace->log_level; - bt_self_component *self_comp = ctf_fs_trace->self_comp; - bt_self_component_class *self_comp_class = ctf_fs_trace->self_comp_class; /* * Create a temporary ds_file to read some properties about the data * stream file. */ - ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, path, log_level); + ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, path, ctf_fs_trace->logger); if (!ds_file) { goto error; } /* Create a temporary iterator to read the ds_file. */ - msg_iter = - ctf_msg_iter_create(ctf_fs_trace->metadata->tc, bt_common_get_page_size(log_level) * 8, - ctf_fs_ds_file_medops, ds_file, log_level, self_comp, NULL); + msg_iter = ctf_msg_iter_create( + ctf_fs_trace->metadata->tc, + bt_common_get_page_size(static_cast(ctf_fs_trace->logger.level())) * 8, + ctf_fs_ds_file_medops, ds_file, nullptr, ctf_fs_trace->logger); if (!msg_iter) { - BT_COMP_LOGE_STR("Cannot create a CTF message iterator."); + BT_CPPLOGE_STR_SPEC(ctf_fs_trace->logger, "Cannot create a CTF message iterator."); goto error; } @@ -689,9 +673,9 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const ret = ctf_msg_iter_get_packet_properties(msg_iter, &props); if (ret) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp, self_comp_class, - "Cannot get stream file's first packet's header and context fields (`%s`).", path); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctf_fs_trace->logger, + "Cannot get stream file's first packet's header and context fields (`{}`).", path); goto error; } @@ -706,9 +690,9 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const sc->default_clock_class->offset_seconds, sc->default_clock_class->offset_cycles, &begin_ns); if (ret) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp, self_comp_class, - "Cannot convert clock cycles to nanoseconds from origin (`%s`).", path); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctf_fs_trace->logger, + "Cannot convert clock cycles to nanoseconds from origin (`{}`).", path); goto error; } } @@ -720,9 +704,8 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const index = ctf_fs_ds_file_build_index(ds_file, ds_file_info, msg_iter); if (!index) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to index CTF stream file \'%s\'", - ds_file->file->path->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to index CTF stream file \'{}\'", + ds_file->file->path->str); goto error; } @@ -816,16 +799,13 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace) const char *basename; GError *error = NULL; GDir *dir = NULL; - bt_logging_level log_level = ctf_fs_trace->log_level; - bt_self_component *self_comp = ctf_fs_trace->self_comp; - bt_self_component_class *self_comp_class = ctf_fs_trace->self_comp_class; /* Check each file in the path directory, except specific ones */ dir = g_dir_open(ctf_fs_trace->path->str, 0, &error); if (!dir) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp, self_comp_class, "Cannot open directory `%s`: %s (code %d)", - ctf_fs_trace->path->str, error->message, error->code); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, + "Cannot open directory `{}`: {} (code {})", + ctf_fs_trace->path->str, error->message, error->code); goto error; } @@ -834,23 +814,25 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace) if (strcmp(basename, CTF_FS_METADATA_FILENAME) == 0) { /* Ignore the metadata stream. */ - BT_COMP_LOGI("Ignoring metadata file `%s" G_DIR_SEPARATOR_S "%s`", - ctf_fs_trace->path->str, basename); + BT_CPPLOGI_SPEC(ctf_fs_trace->logger, + "Ignoring metadata file `{}" G_DIR_SEPARATOR_S "{}`", + ctf_fs_trace->path->str, basename); continue; } if (basename[0] == '.') { - BT_COMP_LOGI("Ignoring hidden file `%s" G_DIR_SEPARATOR_S "%s`", - ctf_fs_trace->path->str, basename); + BT_CPPLOGI_SPEC(ctf_fs_trace->logger, + "Ignoring hidden file `{}" G_DIR_SEPARATOR_S "{}`", + ctf_fs_trace->path->str, basename); continue; } /* Create the file. */ - file = ctf_fs_file_create(log_level, self_comp); + file = ctf_fs_file_create(ctf_fs_trace->logger); if (!file) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp, self_comp_class, - "Cannot create stream file object for file `%s" G_DIR_SEPARATOR_S "%s`", + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctf_fs_trace->logger, + "Cannot create stream file object for file `{}" G_DIR_SEPARATOR_S "{}`", ctf_fs_trace->path->str, basename); goto error; } @@ -859,7 +841,8 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace) g_string_append_printf(file->path, "%s" G_DIR_SEPARATOR_S "%s", ctf_fs_trace->path->str, basename); if (!g_file_test(file->path->str, G_FILE_TEST_IS_REGULAR)) { - BT_COMP_LOGI("Ignoring non-regular file `%s`", file->path->str); + BT_CPPLOGI_SPEC(ctf_fs_trace->logger, "Ignoring non-regular file `{}`", + file->path->str); ctf_fs_file_destroy(file); file = NULL; continue; @@ -867,23 +850,23 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace) ret = ctf_fs_file_open(file, "rb"); if (ret) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp, self_comp_class, "Cannot open stream file `%s`", file->path->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Cannot open stream file `{}`", + file->path->str); goto error; } if (file->size == 0) { /* Skip empty stream. */ - BT_COMP_LOGI("Ignoring empty file `%s`", file->path->str); + BT_CPPLOGI_SPEC(ctf_fs_trace->logger, "Ignoring empty file `{}`", file->path->str); ctf_fs_file_destroy(file); continue; } ret = add_ds_file_to_ds_file_group(ctf_fs_trace, file->path->str); if (ret) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp, self_comp_class, "Cannot add stream file `%s` to stream file group", - file->path->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, + "Cannot add stream file `{}` to stream file group", + file->path->str); ctf_fs_file_destroy(file); goto error; } @@ -909,8 +892,7 @@ end: return ret; } -static int set_trace_name(bt_trace *trace, const char *name_suffix, bt_logging_level log_level, - bt_self_component *self_comp) +static int set_trace_name(bt_trace *trace, const char *name_suffix, const bt2c::Logger& logger) { int ret = 0; const bt_value *val; @@ -918,7 +900,7 @@ static int set_trace_name(bt_trace *trace, const char *name_suffix, bt_logging_l name = g_string_new(NULL); if (!name) { - BT_COMP_LOGE_STR("Failed to allocate a GString."); + BT_CPPLOGE_STR_SPEC(logger, "Failed to allocate a GString."); ret = -1; goto end; } @@ -955,21 +937,14 @@ end: return ret; } -static struct ctf_fs_trace *ctf_fs_trace_create(bt_self_component *self_comp, - bt_self_component_class *self_comp_class, - const char *path, const char *name, +static struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, struct ctf_fs_metadata_config *metadata_config, - bt_logging_level log_level) + bt_self_component *selfComp, + const bt2c::Logger& parentLogger) { int ret; - /* Only one of them must be set. */ - BT_ASSERT(!self_comp != !self_comp_class); - - ctf_fs_trace *ctf_fs_trace = new struct ctf_fs_trace; - ctf_fs_trace->log_level = log_level; - ctf_fs_trace->self_comp = self_comp; - ctf_fs_trace->self_comp_class = self_comp_class; + ctf_fs_trace *ctf_fs_trace = new struct ctf_fs_trace(parentLogger); ctf_fs_trace->path = g_string_new(path); if (!ctf_fs_trace->path) { goto error; @@ -983,7 +958,7 @@ static struct ctf_fs_trace *ctf_fs_trace_create(bt_self_component *self_comp, goto error; } - ret = ctf_fs_metadata_set_trace_class(self_comp, ctf_fs_trace, metadata_config); + ret = ctf_fs_metadata_set_trace_class(selfComp, ctf_fs_trace, metadata_config); if (ret) { goto error; } @@ -1001,7 +976,7 @@ static struct ctf_fs_trace *ctf_fs_trace_create(bt_self_component *self_comp, goto error; } - ret = set_trace_name(ctf_fs_trace->trace, name, log_level, self_comp); + ret = set_trace_name(ctf_fs_trace->trace, name, ctf_fs_trace->logger); if (ret) { goto error; } @@ -1049,47 +1024,42 @@ end: static int ctf_fs_component_create_ctf_fs_trace_one_path(struct ctf_fs_component *ctf_fs, const char *path_param, const char *trace_name, GPtrArray *traces, - bt_self_component *self_comp, - bt_self_component_class *self_comp_class) + bt_self_component *selfComp) { struct ctf_fs_trace *ctf_fs_trace; int ret; GString *norm_path; - bt_logging_level log_level = ctf_fs->log_level; norm_path = bt_common_normalize_path(path_param, NULL); if (!norm_path) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to normalize path: `%s`.", path_param); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Failed to normalize path: `{}`.", path_param); goto error; } ret = path_is_ctf_trace(norm_path->str); if (ret < 0) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to check if path is a CTF trace: path=%s", - norm_path->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctf_fs->logger, "Failed to check if path is a CTF trace: path={}", norm_path->str); goto error; } else if (ret == 0) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp, self_comp_class, - "Path is not a CTF trace (does not contain a metadata file): `%s`.", norm_path->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctf_fs->logger, "Path is not a CTF trace (does not contain a metadata file): `{}`.", + norm_path->str); goto error; } // FIXME: Remove or ifdef for __MINGW32__ if (strcmp(norm_path->str, "/") == 0) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Opening a trace in `/` is not supported."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Opening a trace in `/` is not supported."); ret = -1; goto end; } - ctf_fs_trace = ctf_fs_trace_create(self_comp, self_comp_class, norm_path->str, trace_name, - &ctf_fs->metadata_config, log_level); + ctf_fs_trace = ctf_fs_trace_create(norm_path->str, trace_name, &ctf_fs->metadata_config, + selfComp, ctf_fs->logger); if (!ctf_fs_trace) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Cannot create trace for `%s`.", norm_path->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Cannot create trace for `{}`.", + norm_path->str); goto error; } @@ -1221,7 +1191,7 @@ static int merge_matching_ctf_fs_ds_file_groups(struct ctf_fs_trace *dest_trace, src_group->sc->id); BT_ASSERT(sc); - index = ctf_fs_ds_index_create(dest_trace->log_level, dest_trace->self_comp); + index = ctf_fs_ds_index_create(dest_trace->logger); if (!index) { ret = -1; goto end; @@ -1330,17 +1300,15 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace, enum ctf_msg_iter_status iter_status = CTF_MSG_ITER_STATUS_OK; struct ctf_fs_ds_file *ds_file = NULL; struct ctf_msg_iter *msg_iter = NULL; - bt_logging_level log_level = ctf_fs_trace->log_level; - bt_self_component *self_comp = ctf_fs_trace->self_comp; int ret = 0; BT_ASSERT(ctf_fs_trace); BT_ASSERT(index_entry); BT_ASSERT(index_entry->path); - ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, index_entry->path, log_level); + ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, index_entry->path, ctf_fs_trace->logger); if (!ds_file) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create a ctf_fs_ds_file"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to create a ctf_fs_ds_file"); ret = -1; goto end; } @@ -1348,9 +1316,10 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace, BT_ASSERT(ctf_fs_trace->metadata); BT_ASSERT(ctf_fs_trace->metadata->tc); - msg_iter = - ctf_msg_iter_create(ctf_fs_trace->metadata->tc, bt_common_get_page_size(log_level) * 8, - ctf_fs_ds_file_medops, ds_file, log_level, self_comp, NULL); + msg_iter = ctf_msg_iter_create( + ctf_fs_trace->metadata->tc, + bt_common_get_page_size(static_cast(ctf_fs_trace->logger.level())) * 8, + ctf_fs_ds_file_medops, ds_file, NULL, ctf_fs_trace->logger); if (!msg_iter) { /* ctf_msg_iter_create() logs errors. */ ret = -1; @@ -1396,7 +1365,8 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace, ret = bt_util_clock_cycles_to_ns_from_origin( *cs, default_cc->frequency, default_cc->offset_seconds, default_cc->offset_cycles, ts_ns); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to convert clock snapshot to timestamp"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, + "Failed to convert clock snapshot to timestamp"); goto end; } @@ -1452,7 +1422,6 @@ static int fix_index_lttng_event_after_packet_bug(struct ctf_fs_trace *trace) int ret = 0; guint ds_file_group_i; GPtrArray *ds_file_groups = trace->ds_file_groups; - bt_logging_level log_level = trace->log_level; for (ds_file_group_i = 0; ds_file_group_i < ds_file_groups->len; ds_file_group_i++) { guint entry_i; @@ -1507,8 +1476,8 @@ static int fix_index_lttng_event_after_packet_bug(struct ctf_fs_trace *trace) &last_entry->timestamp_end, &last_entry->timestamp_end_ns); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE( - trace->self_comp, + BT_CPPLOGE_APPEND_CAUSE_SPEC( + trace->logger, "Failed to decode stream's last packet to get its last event's clock snapshot."); goto end; } @@ -1537,7 +1506,6 @@ static int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace *trace) int ret = 0; guint ds_file_group_i; GPtrArray *ds_file_groups = trace->ds_file_groups; - bt_logging_level log_level = trace->log_level; for (ds_file_group_i = 0; ds_file_group_i < ds_file_groups->len; ds_file_group_i++) { guint entry_i; @@ -1571,8 +1539,8 @@ static int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace *trace) &curr_entry->timestamp_begin, &curr_entry->timestamp_begin_ns); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE(trace->self_comp, - "Failed to decode first event's clock snapshot"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(trace->logger, + "Failed to decode first event's clock snapshot"); goto end; } @@ -1610,7 +1578,6 @@ static int fix_index_lttng_crash_quirk(struct ctf_fs_trace *trace) int ret = 0; guint ds_file_group_idx; GPtrArray *ds_file_groups = trace->ds_file_groups; - bt_logging_level log_level = trace->log_level; for (ds_file_group_idx = 0; ds_file_group_idx < ds_file_groups->len; ds_file_group_idx++) { guint entry_idx; @@ -1644,8 +1611,8 @@ static int fix_index_lttng_crash_quirk(struct ctf_fs_trace *trace) &last_entry->timestamp_end, &last_entry->timestamp_end_ns); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE(trace->self_comp, - "Failed to decode last event's clock snapshot"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(trace->logger, + "Failed to decode last event's clock snapshot"); goto end; } } @@ -1817,15 +1784,12 @@ static bool is_tracer_affected_by_lttng_crash_quirk(struct tracer_info *curr_tra * Looks for trace produced by known buggy tracers and fix up the index * produced earlier. */ -static int fix_packet_index_tracer_bugs(struct ctf_fs_component *ctf_fs, - bt_self_component *self_comp, - bt_self_component_class *self_comp_class) +static int fix_packet_index_tracer_bugs(ctf_fs_trace *trace) { int ret = 0; struct tracer_info current_tracer_info; - bt_logging_level log_level = ctf_fs->log_level; - ret = extract_tracer_info(ctf_fs->trace, ¤t_tracer_info); + ret = extract_tracer_info(trace, ¤t_tracer_info); if (ret) { /* * A trace may not have all the necessary environment @@ -1835,42 +1799,47 @@ static int fix_packet_index_tracer_bugs(struct ctf_fs_component *ctf_fs, * an error. */ ret = 0; - BT_LOGI_STR("Cannot extract tracer information necessary to compare with buggy versions."); + BT_CPPLOGI_STR_SPEC( + trace->logger, + "Cannot extract tracer information necessary to compare with buggy versions."); goto end; - ; } /* Check if the trace may be affected by old tracer bugs. */ if (is_tracer_affected_by_lttng_event_after_packet_bug(¤t_tracer_info)) { - BT_LOGI_STR("Trace may be affected by LTTng tracer packet timestamp bug. Fixing up."); - ret = fix_index_lttng_event_after_packet_bug(ctf_fs->trace); + BT_CPPLOGI_STR_SPEC( + trace->logger, + "Trace may be affected by LTTng tracer packet timestamp bug. Fixing up."); + ret = fix_index_lttng_event_after_packet_bug(trace); if (ret) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to fix LTTng event-after-packet bug."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(trace->logger, + "Failed to fix LTTng event-after-packet bug."); goto end; } - ctf_fs->trace->metadata->tc->quirks.lttng_event_after_packet = true; + trace->metadata->tc->quirks.lttng_event_after_packet = true; } if (is_tracer_affected_by_barectf_event_before_packet_bug(¤t_tracer_info)) { - BT_LOGI_STR("Trace may be affected by barectf tracer packet timestamp bug. Fixing up."); - ret = fix_index_barectf_event_before_packet_bug(ctf_fs->trace); + BT_CPPLOGI_STR_SPEC( + trace->logger, + "Trace may be affected by barectf tracer packet timestamp bug. Fixing up."); + ret = fix_index_barectf_event_before_packet_bug(trace); if (ret) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp, self_comp_class, "Failed to fix barectf event-before-packet bug."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(trace->logger, + "Failed to fix barectf event-before-packet bug."); goto end; } - ctf_fs->trace->metadata->tc->quirks.barectf_event_before_packet = true; + trace->metadata->tc->quirks.barectf_event_before_packet = true; } if (is_tracer_affected_by_lttng_crash_quirk(¤t_tracer_info)) { - ret = fix_index_lttng_crash_quirk(ctf_fs->trace); + ret = fix_index_lttng_crash_quirk(trace); if (ret) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to fix lttng-crash timestamp quirks."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(trace->logger, + "Failed to fix lttng-crash timestamp quirks."); goto end; } - ctf_fs->trace->metadata->tc->quirks.lttng_crash = true; + trace->metadata->tc->quirks.lttng_crash = true; } end: @@ -1904,12 +1873,10 @@ static gint compare_strings(gconstpointer p_a, gconstpointer p_b) int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, const bt_value *paths_value, const bt_value *trace_name_value, - bt_self_component *self_comp, - bt_self_component_class *self_comp_class) + bt_self_component *selfComp) { int ret = 0; uint64_t i; - bt_logging_level log_level = ctf_fs->log_level; GPtrArray *paths = NULL; GPtrArray *traces; const char *trace_name; @@ -1919,15 +1886,13 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, traces = g_ptr_array_new_with_free_func(ctf_fs_trace_destroy_notifier); if (!traces) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to allocate a GPtrArray."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Failed to allocate a GPtrArray."); goto error; } paths = g_ptr_array_new_with_free_func(g_free); if (!paths) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to allocate a GPtrArray."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Failed to allocate a GPtrArray."); goto error; } @@ -1944,8 +1909,7 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, input_copy = g_strdup(input); if (!input_copy) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to copy a string."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Failed to copy a string."); goto error; } @@ -1959,7 +1923,7 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, const char *path = (const char *) g_ptr_array_index(paths, i); ret = ctf_fs_component_create_ctf_fs_trace_one_path(ctf_fs, path, trace_name, traces, - self_comp, self_comp_class); + selfComp); if (ret) { goto end; } @@ -1979,9 +1943,9 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, const uint8_t *this_trace_uuid = this_trace->metadata->tc->uuid; if (!this_trace->metadata->tc->is_uuid_set) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp, self_comp_class, - "Multiple traces given, but a trace does not have a UUID: path=%s", + BT_CPPLOGE_APPEND_CAUSE_SPEC( + ctf_fs->logger, + "Multiple traces given, but a trace does not have a UUID: path={}", this_trace->path->str); goto error; } @@ -1993,21 +1957,20 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, bt_uuid_to_str(first_trace_uuid, first_trace_uuid_str); bt_uuid_to_str(this_trace_uuid, this_trace_uuid_str); - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp, self_comp_class, - "Multiple traces given, but UUIDs don't match: " - "first-trace-uuid=%s, first-trace-path=%s, " - "trace-uuid=%s, trace-path=%s", - first_trace_uuid_str, first_trace->path->str, this_trace_uuid_str, - this_trace->path->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, + "Multiple traces given, but UUIDs don't match: " + "first-trace-uuid={}, first-trace-path={}, " + "trace-uuid={}, trace-path={}", + first_trace_uuid_str, first_trace->path->str, + this_trace_uuid_str, this_trace->path->str); goto error; } } ret = merge_ctf_fs_traces((struct ctf_fs_trace **) traces->pdata, traces->len, &trace); if (ret) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to merge traces with the same UUID."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, + "Failed to merge traces with the same UUID."); goto error; } @@ -2018,10 +1981,9 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, traces->pdata[0] = NULL; } - ret = fix_packet_index_tracer_bugs(ctf_fs, self_comp, self_comp_class); + ret = fix_packet_index_tracer_bugs(ctf_fs->trace); if (ret) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to fix packet index tracer bugs."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Failed to fix packet index tracer bugs."); } /* @@ -2083,8 +2045,6 @@ static int create_streams_for_trace(struct ctf_fs_trace *ctf_fs_trace) int ret; GString *name = NULL; guint i; - bt_logging_level log_level = ctf_fs_trace->log_level; - bt_self_component *self_comp = ctf_fs_trace->self_comp; for (i = 0; i < ctf_fs_trace->ds_file_groups->len; i++) { ctf_fs_ds_file_group *ds_file_group = @@ -2114,19 +2074,19 @@ static int create_streams_for_trace(struct ctf_fs_trace *ctf_fs_trace) } if (!ds_file_group->stream) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create stream for DS file group: " - "addr=%p, stream-name=\"%s\"", - ds_file_group, name->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, + "Cannot create stream for DS file group: " + "addr={}, stream-name=\"{}\"", + fmt::ptr(ds_file_group), name->str); goto error; } ret = bt_stream_set_name(ds_file_group->stream, name->str); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot set stream's name: " - "addr=%p, stream-name=\"%s\"", - ds_file_group->stream, name->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, + "Cannot set stream's name: " + "addr={}, stream-name=\"{}\"", + fmt::ptr(ds_file_group->stream), name->str); goto error; } @@ -2166,18 +2126,16 @@ static bt_param_validation_map_value_entry_descr fs_params_entries_descr[] = { BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END}; bool read_src_fs_parameters(const bt_value *params, const bt_value **inputs, - const bt_value **trace_name, struct ctf_fs_component *ctf_fs, - bt_self_component *self_comp, bt_self_component_class *self_comp_class) + const bt_value **trace_name, struct ctf_fs_component *ctf_fs) { bool ret; const bt_value *value; - bt_logging_level log_level = ctf_fs->log_level; enum bt_param_validation_status validate_value_status; gchar *error = NULL; validate_value_status = bt_param_validation_validate(params, fs_params_entries_descr, &error); if (validate_value_status != BT_PARAM_VALIDATION_STATUS_OK) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, "%s", error); + BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "{}", error); ret = false; goto end; } @@ -2222,20 +2180,18 @@ static struct ctf_fs_component *ctf_fs_create(const bt_value *params, bt_self_component *self_comp = bt_self_component_source_as_self_component(self_comp_src); ctf_fs = ctf_fs_component_create( - bt_component_get_logging_level(bt_self_component_as_component(self_comp))); + bt2c::Logger {bt2::SelfSourceComponent {self_comp_src}, "PLUGIN/SRC.CTF.FS/COMP"}); if (!ctf_fs) { goto error; } - if (!read_src_fs_parameters(params, &inputs_value, &trace_name_value, ctf_fs, self_comp, - NULL)) { + if (!read_src_fs_parameters(params, &inputs_value, &trace_name_value, ctf_fs)) { goto error; } bt_self_component_set_data(self_comp, ctf_fs); - if (ctf_fs_component_create_ctf_fs_trace(ctf_fs, inputs_value, trace_name_value, self_comp, - NULL)) { + if (ctf_fs_component_create_ctf_fs_trace(ctf_fs, inputs_value, trace_name_value, self_comp)) { goto error; } @@ -2274,24 +2230,25 @@ bt_component_class_initialize_method_status ctf_fs_init(bt_self_component_source return ret; } -bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class, +bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class_src, bt_private_query_executor *priv_query_exec, const char *object, const bt_value *params, __attribute__((unused)) void *method_data, const bt_value **result) { bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK; - bt_logging_level log_level = bt_query_executor_get_logging_level( - bt_private_query_executor_as_query_executor_const(priv_query_exec)); + + bt2c::Logger logger {bt2::SelfComponentClass {comp_class_src}, + bt2::PrivateQueryExecutor {priv_query_exec}, "PLUGIN/SRC.CTF.FS/QUERY"}; if (strcmp(object, "metadata-info") == 0) { - status = metadata_info_query(comp_class, params, log_level, result); + status = metadata_info_query(params, logger, result); } else if (strcmp(object, "babeltrace.trace-infos") == 0) { - status = trace_infos_query(comp_class, params, log_level, result); + status = trace_infos_query(params, logger, result); } else if (!strcmp(object, "babeltrace.support-info")) { - status = support_info_query(comp_class, params, log_level, result); + status = support_info_query(params, logger, result); } else { - BT_LOGE("Unknown query object `%s`", object); + BT_CPPLOGE_SPEC(logger, "Unknown query object `{}`", object); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT; goto end; } diff --git a/src/plugins/ctf/fs-src/fs.hpp b/src/plugins/ctf/fs-src/fs.hpp index 320b755a..f80368ad 100644 --- a/src/plugins/ctf/fs-src/fs.hpp +++ b/src/plugins/ctf/fs-src/fs.hpp @@ -14,16 +14,20 @@ #include +#include "cpp-common/bt2c/logging.hpp" + #include "metadata.hpp" extern bool ctf_fs_debug; struct ctf_fs_file { - bt_logging_level log_level = (bt_logging_level) 0; + explicit ctf_fs_file(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.FS/FILE"} + { + } - /* Weak */ - bt_self_component *self_comp = nullptr; + bt2c::Logger logger; /* Owned by this */ GString *path = nullptr; @@ -53,7 +57,12 @@ struct ctf_fs_metadata struct ctf_fs_component { - bt_logging_level log_level = (bt_logging_level) 0; + explicit ctf_fs_component(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"} + { + } + + bt2c::Logger logger; /* Array of struct ctf_fs_port_data *, owned by this */ GPtrArray *port_data = nullptr; @@ -66,15 +75,12 @@ struct ctf_fs_component struct ctf_fs_trace { - bt_logging_level log_level = (bt_logging_level) 0; + explicit ctf_fs_trace(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"} + { + } - /* - * Weak. These are mostly used to generate log messages or to append - * error causes. They are mutually exclusive, only one of them must be - * set. - */ - bt_self_component *self_comp = nullptr; - bt_self_component_class *self_comp_class = nullptr; + bt2c::Logger logger; /* Owned by this */ struct ctf_fs_metadata *metadata = nullptr; @@ -169,14 +175,17 @@ struct ctf_fs_port_data struct ctf_fs_msg_iter_data { - bt_logging_level log_level = (bt_logging_level) 0; - - /* Weak */ - bt_self_component *self_comp = nullptr; + explicit ctf_fs_msg_iter_data(bt_self_message_iterator *selfMsgIter) : + self_msg_iter {selfMsgIter}, logger {bt2::SelfMessageIterator {self_msg_iter}, + "PLUGIN/SRC.CTF.FS/MSG-ITER"} + { + } /* Weak */ bt_self_message_iterator *self_msg_iter = nullptr; + bt2c::Logger logger; + /* Weak, belongs to ctf_fs_trace */ struct ctf_fs_ds_file_group *ds_file_group = nullptr; @@ -222,7 +231,7 @@ ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator); /* Create and initialize a new, empty ctf_fs_component. */ -struct ctf_fs_component *ctf_fs_component_create(bt_logging_level log_level); +ctf_fs_component *ctf_fs_component_create(const bt2c::Logger& parentLogger); /* * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing @@ -239,8 +248,7 @@ struct ctf_fs_component *ctf_fs_component_create(bt_logging_level log_level); int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, const bt_value *paths_value, const bt_value *trace_name_value, - bt_self_component *self_comp, - bt_self_component_class *self_comp_class); + bt_self_component *selfComp); /* Free `ctf_fs` and everything it owns. */ @@ -262,8 +270,7 @@ void ctf_fs_destroy(struct ctf_fs_component *ctf_fs); */ bool read_src_fs_parameters(const bt_value *params, const bt_value **paths, - const bt_value **trace_name, struct ctf_fs_component *ctf_fs, - bt_self_component *self_comp, bt_self_component_class *self_comp_class); + const bt_value **trace_name, struct ctf_fs_component *ctf_fs); /* * Generate the port name to be used for a given data stream file group. diff --git a/src/plugins/ctf/fs-src/metadata.cpp b/src/plugins/ctf/fs-src/metadata.cpp index da8e1fe1..cebd21fc 100644 --- a/src/plugins/ctf/fs-src/metadata.cpp +++ b/src/plugins/ctf/fs-src/metadata.cpp @@ -5,17 +5,6 @@ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation */ -#include -#include -#include - -#include - -#define BT_COMP_LOG_SELF_COMP self_comp -#define BT_LOG_OUTPUT_LEVEL log_level -#define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/META" -#include "logging/comp-logging.h" - #include "common/assert.h" #include "../common/src/metadata/tsdl/decoder.hpp" @@ -23,8 +12,7 @@ #include "fs.hpp" #include "metadata.hpp" -FILE *ctf_fs_metadata_open_file(const char *trace_path, bt_logging_level log_level, - bt_self_component_class *comp_class) +FILE *ctf_fs_metadata_open_file(const char *trace_path, const bt2c::Logger& logger) { GString *metadata_path; FILE *fp = NULL; @@ -37,8 +25,8 @@ FILE *ctf_fs_metadata_open_file(const char *trace_path, bt_logging_level log_lev g_string_append(metadata_path, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME); fp = fopen(metadata_path->str, "rb"); if (!fp) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(comp_class, "Failed to open metadata file", - ": path=\"%s\"", metadata_path->str); + BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(logger, "Failed to open metadata file", ": path=\"{}\"", + metadata_path->str); } g_string_free(metadata_path, TRUE); @@ -47,10 +35,9 @@ end: return fp; } -static struct ctf_fs_file *get_file(const char *trace_path, bt_logging_level log_level, - bt_self_component *self_comp) +static struct ctf_fs_file *get_file(const char *trace_path, const bt2c::Logger& logger) { - struct ctf_fs_file *file = ctf_fs_file_create(log_level, self_comp); + struct ctf_fs_file *file = ctf_fs_file_create(logger); if (!file) { goto error; @@ -80,10 +67,8 @@ int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_ { int ret = 0; struct ctf_fs_file *file = NULL; - bt_logging_level log_level = ctf_fs_trace->log_level; + ctf_metadata_decoder_config decoder_config {ctf_fs_trace->logger}; - ctf_metadata_decoder_config decoder_config; - decoder_config.log_level = ctf_fs_trace->log_level; decoder_config.self_comp = self_comp; decoder_config.clock_class_offset_s = config ? config->clock_class_offset_s : 0; decoder_config.clock_class_offset_ns = config ? config->clock_class_offset_ns : 0; @@ -91,23 +76,23 @@ int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_ config ? config->force_clock_class_origin_unix_epoch : false; decoder_config.create_trace_class = true; - file = get_file(ctf_fs_trace->path->str, log_level, self_comp); + file = get_file(ctf_fs_trace->path->str, ctf_fs_trace->logger); if (!file) { - BT_COMP_LOGE("Cannot create metadata file object."); + BT_CPPLOGE_SPEC(ctf_fs_trace->logger, "Cannot create metadata file object."); ret = -1; goto end; } ctf_fs_trace->metadata->decoder = ctf_metadata_decoder_create(&decoder_config); if (!ctf_fs_trace->metadata->decoder) { - BT_COMP_LOGE("Cannot create metadata decoder object."); + BT_CPPLOGE_SPEC(ctf_fs_trace->logger, "Cannot create metadata decoder object."); ret = -1; goto end; } ret = ctf_metadata_decoder_append_content(ctf_fs_trace->metadata->decoder, file->fp); if (ret) { - BT_COMP_LOGE("Cannot update metadata decoder's content."); + BT_CPPLOGE_SPEC(ctf_fs_trace->logger, "Cannot update metadata decoder's content."); goto end; } diff --git a/src/plugins/ctf/fs-src/metadata.hpp b/src/plugins/ctf/fs-src/metadata.hpp index bd8d2496..cf24aa47 100644 --- a/src/plugins/ctf/fs-src/metadata.hpp +++ b/src/plugins/ctf/fs-src/metadata.hpp @@ -11,6 +11,12 @@ #include +namespace bt2c { + +class Logger; + +} /* namespace bt2c */ + #define CTF_FS_METADATA_FILENAME "metadata" struct ctf_fs_metadata_config @@ -27,8 +33,7 @@ void ctf_fs_metadata_fini(struct ctf_fs_metadata *metadata); int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_trace *ctf_fs_trace, struct ctf_fs_metadata_config *config); -FILE *ctf_fs_metadata_open_file(const char *trace_path, bt_logging_level log_level, - bt_self_component_class *comp_class); +FILE *ctf_fs_metadata_open_file(const char *trace_path, const bt2c::Logger& logger); bool ctf_metadata_is_packetized(FILE *fp, int *byte_order); diff --git a/src/plugins/ctf/fs-src/query.cpp b/src/plugins/ctf/fs-src/query.cpp index c2f6253d..c4bd6541 100644 --- a/src/plugins/ctf/fs-src/query.cpp +++ b/src/plugins/ctf/fs-src/query.cpp @@ -12,16 +12,8 @@ #include -#define BT_LOG_OUTPUT_LEVEL ((enum bt_log_level) log_level) -#define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/QUERY" -#include "logging/comp-logging.h" -#include "logging/log.h" - -#include "common/assert.h" - #include "../common/src/metadata/tsdl/decoder.hpp" #include "fs.hpp" -#include "metadata.hpp" #include "query.hpp" #define METADATA_TEXT_SIG "/* CTF 1.8" @@ -33,13 +25,11 @@ struct range bool set = false; }; -bt_component_class_query_method_status -metadata_info_query(bt_self_component_class_source *self_comp_class_src, const bt_value *params, - bt_logging_level log_level, const bt_value **user_result) +bt_component_class_query_method_status metadata_info_query(const bt_value *params, + const bt2c::Logger& logger, + const bt_value **user_result) { bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK; - bt_self_component_class *self_comp_class = - bt_self_component_class_source_as_self_component_class(self_comp_class_src); bt_value *result = NULL; const bt_value *path_value = NULL; FILE *metadata_fp = NULL; @@ -48,7 +38,7 @@ metadata_info_query(bt_self_component_class_source *self_comp_class_src, const b const char *path; bool is_packetized; struct ctf_metadata_decoder *decoder = NULL; - ctf_metadata_decoder_config decoder_cfg; + ctf_metadata_decoder_config decoder_cfg {logger}; enum ctf_metadata_decoder_status decoder_status; GString *g_metadata_text = NULL; const char *plaintext; @@ -62,22 +52,20 @@ metadata_info_query(bt_self_component_class_source *self_comp_class_src, const b BT_ASSERT(params); if (!bt_value_is_map(params)) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, - "Query parameters is not a map value object."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Query parameters is not a map value object."); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } path_value = bt_value_map_borrow_entry_value_const(params, "path"); if (!path_value) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Mandatory `path` parameter missing"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Mandatory `path` parameter missing"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } if (!bt_value_is_string(path_value)) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, - "`path` parameter is required to be a string value"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "`path` parameter is required to be a string value"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } @@ -85,36 +73,32 @@ metadata_info_query(bt_self_component_class_source *self_comp_class_src, const b path = bt_value_string_get(path_value); BT_ASSERT(path); - metadata_fp = ctf_fs_metadata_open_file(path, log_level, self_comp_class); + metadata_fp = ctf_fs_metadata_open_file(path, logger); if (!metadata_fp) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Cannot open trace metadata: path=\"%s\".", - path); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot open trace metadata: path=\"{}\".", path); goto error; } - ret = ctf_metadata_decoder_is_packetized(metadata_fp, &is_packetized, &bo, log_level, NULL); + ret = ctf_metadata_decoder_is_packetized(metadata_fp, &is_packetized, &bo, logger); if (ret) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp_class, - "Cannot check whether or not the metadata stream is packetized: path=\"%s\".", path); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + logger, "Cannot check whether or not the metadata stream is packetized: path=\"{}\".", + path); goto error; } - decoder_cfg.log_level = log_level; - decoder_cfg.self_comp_class = self_comp_class; decoder_cfg.keep_plain_text = true; decoder = ctf_metadata_decoder_create(&decoder_cfg); if (!decoder) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, - "Cannot create metadata decoder: path=\"%s\".", path); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot create metadata decoder: path=\"{}\".", path); goto error; } rewind(metadata_fp); decoder_status = ctf_metadata_decoder_append_content(decoder, metadata_fp); if (decoder_status) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp_class, "Cannot update metadata decoder's content: path=\"%s\".", path); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + logger, "Cannot update metadata decoder's content: path=\"{}\".", path); goto error; } @@ -134,15 +118,14 @@ metadata_info_query(bt_self_component_class_source *self_comp_class_src, const b ret = bt_value_map_insert_string_entry(result, "text", g_metadata_text->str); if (ret) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, - "Cannot insert metadata text into query result."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot insert metadata text into query result."); goto error; } ret = bt_value_map_insert_bool_entry(result, "is-packetized", is_packetized); if (ret) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE( - self_comp_class, "Cannot insert \"is-packetized\" attribute into query result."); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + logger, "Cannot insert \"is-packetized\" attribute into query result."); goto error; } @@ -165,7 +148,8 @@ end: if (metadata_fp) { ret = fclose(metadata_fp); if (ret) { - BT_LOGE_ERRNO("Cannot close metadata file stream", ": path=\"%s\"", path); + BT_CPPLOGE_ERRNO_SPEC(logger, "Cannot close metadata file stream", ": path=\"{}\"", + path); } } @@ -266,7 +250,7 @@ end: } static int populate_trace_info(const struct ctf_fs_trace *trace, bt_value *trace_info, - bt_logging_level log_level, bt_self_component_class *self_comp_class) + const bt2c::Logger& logger) { int ret = 0; size_t group_idx; @@ -278,8 +262,8 @@ static int populate_trace_info(const struct ctf_fs_trace *trace, bt_value *trace /* Add trace range info only if it contains streams. */ if (trace->ds_file_groups->len == 0) { ret = -1; - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Trace has no streams: trace-path=%s", - trace->path->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Trace has no streams: trace-path={}", + trace->path->str); goto end; } @@ -313,13 +297,10 @@ end: } bt_component_class_query_method_status -trace_infos_query(bt_self_component_class_source *self_comp_class_src, const bt_value *params, - bt_logging_level log_level, const bt_value **user_result) +trace_infos_query(const bt_value *params, const bt2c::Logger& logger, const bt_value **user_result) { struct ctf_fs_component *ctf_fs = NULL; bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK; - bt_self_component_class *self_comp_class = - bt_self_component_class_source_as_self_component_class(self_comp_class_src); bt_value *result = NULL; const bt_value *inputs_value = NULL; const bt_value *trace_name_value; @@ -330,25 +311,22 @@ trace_infos_query(bt_self_component_class_source *self_comp_class_src, const bt_ BT_ASSERT(params); if (!bt_value_is_map(params)) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, - "Query parameters is not a map value object."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Query parameters is not a map value object."); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } - ctf_fs = ctf_fs_component_create(log_level); + ctf_fs = ctf_fs_component_create(logger); if (!ctf_fs) { goto error; } - if (!read_src_fs_parameters(params, &inputs_value, &trace_name_value, ctf_fs, NULL, - self_comp_class)) { + if (!read_src_fs_parameters(params, &inputs_value, &trace_name_value, ctf_fs)) { status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } - if (ctf_fs_component_create_ctf_fs_trace(ctf_fs, inputs_value, trace_name_value, NULL, - self_comp_class)) { + if (ctf_fs_component_create_ctf_fs_trace(ctf_fs, inputs_value, trace_name_value, NULL)) { goto error; } @@ -360,11 +338,11 @@ trace_infos_query(bt_self_component_class_source *self_comp_class_src, const bt_ append_status = bt_value_array_append_empty_map_element(result, &trace_info); if (append_status != BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Failed to create trace info map."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Failed to create trace info map."); goto error; } - ret = populate_trace_info(ctf_fs->trace, trace_info, log_level, self_comp_class); + ret = populate_trace_info(ctf_fs->trace, trace_info, logger); if (ret) { goto error; } @@ -389,8 +367,7 @@ end: } bt_component_class_query_method_status -support_info_query(bt_self_component_class_source *comp_class, const bt_value *params, - bt_logging_level log_level, const bt_value **user_result) +support_info_query(const bt_value *params, const bt2c::Logger& logger, const bt_value **user_result) { const bt_value *input_type_value; const char *input_type; @@ -431,10 +408,7 @@ support_info_query(bt_self_component_class_source *comp_class, const bt_value *p enum ctf_metadata_decoder_status decoder_status; bt_uuid_t uuid; - ctf_metadata_decoder_config metadata_decoder_config; - metadata_decoder_config.log_level = log_level; - metadata_decoder_config.self_comp_class = - bt_self_component_class_source_as_self_component_class(comp_class); + ctf_metadata_decoder_config metadata_decoder_config {logger}; metadata_decoder = ctf_metadata_decoder_create(&metadata_decoder_config); if (!metadata_decoder) { @@ -444,7 +418,8 @@ support_info_query(bt_self_component_class_source *comp_class, const bt_value *p decoder_status = ctf_metadata_decoder_append_content(metadata_decoder, metadata_file); if (decoder_status != CTF_METADATA_DECODER_STATUS_OK) { - BT_LOGW("cannot append metadata content: metadata-decoder-status=%d", decoder_status); + BT_CPPLOGW_SPEC(logger, "cannot append metadata content: metadata-decoder-status={}", + decoder_status); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto end; } diff --git a/src/plugins/ctf/fs-src/query.hpp b/src/plugins/ctf/fs-src/query.hpp index 053540ff..1745c751 100644 --- a/src/plugins/ctf/fs-src/query.hpp +++ b/src/plugins/ctf/fs-src/query.hpp @@ -11,17 +11,19 @@ #include +namespace bt2c { + +class Logger; + +} /* namespace bt2c */ + bt_component_class_query_method_status -metadata_info_query(bt_self_component_class_source *comp_class, const bt_value *params, - bt_logging_level log_level, const bt_value **result); +metadata_info_query(const bt_value *params, const bt2c::Logger& logger, const bt_value **result); -bt_component_class_query_method_status trace_infos_query(bt_self_component_class_source *comp_class, - const bt_value *params, - bt_logging_level log_level, - const bt_value **result); +bt_component_class_query_method_status +trace_infos_query(const bt_value *params, const bt2c::Logger& logger, const bt_value **result); bt_component_class_query_method_status -support_info_query(bt_self_component_class_source *comp_class, const bt_value *params, - bt_logging_level log_level, const bt_value **result); +support_info_query(const bt_value *params, const bt2c::Logger& logger, const bt_value **result); #endif /* BABELTRACE_PLUGIN_CTF_FS_QUERY_H */ diff --git a/src/plugins/ctf/lttng-live/data-stream.cpp b/src/plugins/ctf/lttng-live/data-stream.cpp index e0dca453..c83d8491 100644 --- a/src/plugins/ctf/lttng-live/data-stream.cpp +++ b/src/plugins/ctf/lttng-live/data-stream.cpp @@ -10,23 +10,13 @@ #include #include #include - -#include - -#define BT_COMP_LOG_SELF_COMP self_comp -#define BT_LOG_OUTPUT_LEVEL log_level -#define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/DS" -#include -#include -#include #include #include -#include "logging/comp-logging.h" - #include "common/assert.h" #include "compat/mman.h" /* IWYU pragma: keep */ +#include "cpp-common/vendor/fmt/format.h" #include "../common/src/msg-iter/msg-iter.hpp" #include "data-stream.hpp" @@ -73,15 +63,13 @@ end: static bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t stream_id, void *data) { lttng_live_stream_iterator *lttng_live_stream = (lttng_live_stream_iterator *) data; - bt_logging_level log_level = lttng_live_stream->log_level; - bt_self_component *self_comp = lttng_live_stream->self_comp; if (!lttng_live_stream->stream) { uint64_t stream_class_id = bt_stream_class_get_id(stream_class); - BT_COMP_LOGI("Creating stream %s (ID: %" PRIu64 ") out of stream " - "class %" PRId64, - lttng_live_stream->name->str, stream_id, stream_class_id); + BT_CPPLOGI_SPEC(lttng_live_stream->logger, + "Creating stream {} (ID: {}) out of stream class {}", + lttng_live_stream->name->str, stream_id, stream_class_id); if (stream_id < 0) { /* @@ -98,10 +86,10 @@ static bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t str } if (!lttng_live_stream->stream) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot create stream %s (stream class ID " - "%" PRId64 ", stream ID %" PRIu64 ")", - lttng_live_stream->name->str, stream_class_id, stream_id); + BT_CPPLOGE_APPEND_CAUSE_SPEC( + lttng_live_stream->logger, + "Cannot create stream {} (stream class ID {}, stream ID {})", + lttng_live_stream->name->str, stream_class_id, stream_id); goto end; } @@ -124,16 +112,15 @@ enum lttng_live_iterator_status lttng_live_lazy_msg_init(struct lttng_live_sessi { struct lttng_live_component *lttng_live = session->lttng_live_msg_iter->lttng_live_comp; uint64_t trace_idx, stream_iter_idx; - bt_logging_level log_level = session->log_level; - bt_self_component *self_comp = session->self_comp; if (!session->lazy_stream_msg_init) { return LTTNG_LIVE_ITERATOR_STATUS_OK; } - BT_COMP_LOGD("Lazily initializing self message iterator for live session: " - "session-id=%" PRIu64 ", self-msg-iter-addr=%p", - session->id, self_msg_iter); + BT_CPPLOGD_SPEC(session->logger, + "Lazily initializing self message iterator for live session: " + "session-id={}, self-msg-iter-addr={}", + session->id, fmt::ptr(self_msg_iter)); for (trace_idx = 0; trace_idx < session->traces->len; trace_idx++) { struct lttng_live_trace *trace = @@ -150,15 +137,17 @@ enum lttng_live_iterator_status lttng_live_lazy_msg_init(struct lttng_live_sessi continue; } ctf_tc = ctf_metadata_decoder_borrow_ctf_trace_class(trace->metadata->decoder); - BT_COMP_LOGD("Creating CTF message iterator: " - "session-id=%" PRIu64 ", ctf-tc-addr=%p, " - "stream-iter-name=%s, self-msg-iter-addr=%p", - session->id, ctf_tc, stream_iter->name->str, self_msg_iter); + BT_CPPLOGD_SPEC(stream_iter->logger, + "Creating CTF message iterator: session-id={}, ctf-tc-addr={}, " + "stream-iter-name={}, self-msg-iter-addr={}", + session->id, fmt::ptr(ctf_tc), stream_iter->name->str, + fmt::ptr(self_msg_iter)); stream_iter->msg_iter = ctf_msg_iter_create(ctf_tc, lttng_live->max_query_size, medops, stream_iter, - log_level, self_comp, self_msg_iter); + self_msg_iter, stream_iter->logger); if (!stream_iter->msg_iter) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create CTF message iterator"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(stream_iter->logger, + "Failed to create CTF message iterator"); goto error; } } @@ -176,28 +165,21 @@ struct lttng_live_stream_iterator * lttng_live_stream_iterator_create(struct lttng_live_session *session, uint64_t ctf_trace_id, uint64_t stream_id, bt_self_message_iterator *self_msg_iter) { - struct lttng_live_component *lttng_live; - struct lttng_live_trace *trace; - bt_logging_level log_level; - bt_self_component *self_comp; + lttng_live_stream_iterator *stream_iter = nullptr; BT_ASSERT(session); BT_ASSERT(session->lttng_live_msg_iter); BT_ASSERT(session->lttng_live_msg_iter->lttng_live_comp); - log_level = session->log_level; - self_comp = session->self_comp; - - lttng_live = session->lttng_live_msg_iter->lttng_live_comp; - lttng_live_stream_iterator *stream_iter = new lttng_live_stream_iterator; - stream_iter->log_level = log_level; - stream_iter->self_comp = self_comp; - trace = lttng_live_session_borrow_or_create_trace_by_id(session, ctf_trace_id); + lttng_live_component *lttng_live = session->lttng_live_msg_iter->lttng_live_comp; + lttng_live_trace *trace = + lttng_live_session_borrow_or_create_trace_by_id(session, ctf_trace_id); if (!trace) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to borrow CTF trace."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(session->logger, "Failed to borrow CTF trace."); goto error; } + stream_iter = new lttng_live_stream_iterator {session->logger}; stream_iter->trace = trace; stream_iter->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA; stream_iter->viewer_stream_id = stream_id; @@ -213,23 +195,26 @@ lttng_live_stream_iterator_create(struct lttng_live_session *session, uint64_t c ctf_metadata_decoder_borrow_ctf_trace_class(trace->metadata->decoder); BT_ASSERT(!stream_iter->msg_iter); stream_iter->msg_iter = - ctf_msg_iter_create(ctf_tc, lttng_live->max_query_size, medops, stream_iter, log_level, - self_comp, self_msg_iter); + ctf_msg_iter_create(ctf_tc, lttng_live->max_query_size, medops, stream_iter, + self_msg_iter, stream_iter->logger); if (!stream_iter->msg_iter) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create CTF message iterator"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(stream_iter->logger, + "Failed to create CTF message iterator"); goto error; } } stream_iter->buf = g_new0(uint8_t, lttng_live->max_query_size); if (!stream_iter->buf) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to allocate live stream iterator buffer"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(stream_iter->logger, + "Failed to allocate live stream iterator buffer"); goto error; } stream_iter->buflen = lttng_live->max_query_size; stream_iter->name = g_string_new(NULL); if (!stream_iter->name) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to allocate live stream iterator name buffer"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(stream_iter->logger, + "Failed to allocate live stream iterator name buffer"); goto error; } diff --git a/src/plugins/ctf/lttng-live/lttng-live.cpp b/src/plugins/ctf/lttng-live/lttng-live.cpp index 0d9a7044..ba524f26 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.cpp +++ b/src/plugins/ctf/lttng-live/lttng-live.cpp @@ -9,17 +9,11 @@ */ #include -#include #include -#include - -#define BT_COMP_LOG_SELF_COMP self_comp -#define BT_LOG_OUTPUT_LEVEL log_level -#define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE" -#include "logging/comp-logging.h" - #include "common/assert.h" +#include "cpp-common/bt2c/fmt.hpp" +#include "cpp-common/vendor/fmt/format.h" #include "plugins/common/muxing/muxing.h" #include "plugins/common/param-validation/param-validation.h" @@ -36,73 +30,26 @@ #define SESS_NOT_FOUND_ACTION_FAIL_STR "fail" #define SESS_NOT_FOUND_ACTION_END_STR "end" -#define print_dbg(fmt, ...) BT_COMP_LOGD(fmt, ##__VA_ARGS__) - -static const char *lttng_live_iterator_status_string(enum lttng_live_iterator_status status) -{ - switch (status) { - case LTTNG_LIVE_ITERATOR_STATUS_CONTINUE: - return "LTTNG_LIVE_ITERATOR_STATUS_CONTINUE"; - case LTTNG_LIVE_ITERATOR_STATUS_AGAIN: - return "LTTNG_LIVE_ITERATOR_STATUS_AGAIN"; - case LTTNG_LIVE_ITERATOR_STATUS_END: - return "LTTNG_LIVE_ITERATOR_STATUS_END"; - case LTTNG_LIVE_ITERATOR_STATUS_OK: - return "LTTNG_LIVE_ITERATOR_STATUS_OK"; - case LTTNG_LIVE_ITERATOR_STATUS_INVAL: - return "LTTNG_LIVE_ITERATOR_STATUS_INVAL"; - case LTTNG_LIVE_ITERATOR_STATUS_ERROR: - return "LTTNG_LIVE_ITERATOR_STATUS_ERROR"; - case LTTNG_LIVE_ITERATOR_STATUS_NOMEM: - return "LTTNG_LIVE_ITERATOR_STATUS_NOMEM"; - case LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED: - return "LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED"; - default: - bt_common_abort(); - } -} - -static const char *lttng_live_stream_state_string(enum lttng_live_stream_state state) -{ - switch (state) { - case LTTNG_LIVE_STREAM_ACTIVE_NO_DATA: - return "ACTIVE_NO_DATA"; - case LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA: - return "QUIESCENT_NO_DATA"; - case LTTNG_LIVE_STREAM_QUIESCENT: - return "QUIESCENT"; - case LTTNG_LIVE_STREAM_ACTIVE_DATA: - return "ACTIVE_DATA"; - case LTTNG_LIVE_STREAM_EOF: - return "EOF"; - default: - return "ERROR"; - } -} - void lttng_live_stream_iterator_set_state(struct lttng_live_stream_iterator *stream_iter, enum lttng_live_stream_state new_state) { - bt_self_component *self_comp = stream_iter->self_comp; - bt_logging_level log_level = stream_iter->log_level; - - BT_COMP_LOGD("Setting live stream iterator state: viewer-stream-id=%" PRIu64 - ", old-state=%s, new-state=%s", - stream_iter->viewer_stream_id, lttng_live_stream_state_string(stream_iter->state), - lttng_live_stream_state_string(new_state)); + BT_CPPLOGD_SPEC(stream_iter->logger, + "Setting live stream iterator state: viewer-stream-id={}, " + "old-state={}, new-state={}", + stream_iter->viewer_stream_id, stream_iter->state, new_state); stream_iter->state = new_state; } #define LTTNG_LIVE_LOGD_STREAM_ITER(live_stream_iter) \ do { \ - BT_COMP_LOGD("Live stream iterator state=%s, " \ - "last-inact-ts-is-set=%d, last-inact-ts-value=%" PRId64 ", " \ - "curr-inact-ts=%" PRId64, \ - lttng_live_stream_state_string(live_stream_iter->state), \ - live_stream_iter->last_inactivity_ts.is_set, \ - live_stream_iter->last_inactivity_ts.value, \ - live_stream_iter->current_inactivity_ts); \ + BT_CPPLOGD_SPEC((live_stream_iter)->logger, \ + "Live stream iterator state={}, " \ + "last-inact-ts-is-set={}, last-inact-ts-value={}, " \ + "curr-inact-ts={}", \ + (live_stream_iter)->state, (live_stream_iter)->last_inactivity_ts.is_set, \ + (live_stream_iter)->last_inactivity_ts.value, \ + (live_stream_iter)->current_inactivity_ts); \ } while (0); bool lttng_live_graph_is_canceled(struct lttng_live_msg_iter *msg_iter) @@ -141,10 +88,7 @@ end: static void lttng_live_destroy_trace(struct lttng_live_trace *trace) { - bt_logging_level log_level = trace->log_level; - bt_self_component *self_comp = trace->self_comp; - - BT_COMP_LOGD("Destroying live trace: trace-id=%" PRIu64, trace->id); + BT_CPPLOGD_SPEC(trace->logger, "Destroying live trace: trace-id={}", trace->id); BT_ASSERT(trace->stream_iterators); g_ptr_array_free(trace->stream_iterators, TRUE); @@ -159,16 +103,10 @@ static void lttng_live_destroy_trace(struct lttng_live_trace *trace) static struct lttng_live_trace *lttng_live_create_trace(struct lttng_live_session *session, uint64_t trace_id) { - bt_logging_level log_level = session->log_level; - bt_self_component *self_comp = session->self_comp; + BT_CPPLOGD_SPEC(session->logger, "Creating live trace: session-id={}, trace-id={}", session->id, + trace_id); - BT_COMP_LOGD("Creating live trace: " - "session-id=%" PRIu64 ", trace-id=%" PRIu64, - session->id, trace_id); - - lttng_live_trace *trace = new lttng_live_trace; - trace->log_level = session->log_level; - trace->self_comp = session->self_comp; + lttng_live_trace *trace = new lttng_live_trace {session->logger}; trace->session = session; trace->id = trace_id; trace->trace_class = NULL; @@ -203,15 +141,12 @@ end: int lttng_live_add_session(struct lttng_live_msg_iter *lttng_live_msg_iter, uint64_t session_id, const char *hostname, const char *session_name) { - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; - - BT_COMP_LOGD("Adding live session: " - "session-id=%" PRIu64 ", hostname=\"%s\" session-name=\"%s\"", - session_id, hostname, session_name); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Adding live session: " + "session-id={}, hostname=\"{}\", session-name=\"{}\"", + session_id, hostname, session_name); - lttng_live_session *session = new lttng_live_session; - session->log_level = lttng_live_msg_iter->log_level; + lttng_live_session *session = new lttng_live_session {lttng_live_msg_iter->logger}; session->self_comp = lttng_live_msg_iter->self_comp; session->id = session_id; session->traces = g_ptr_array_new_with_free_func((GDestroyNotify) lttng_live_destroy_trace); @@ -231,23 +166,20 @@ int lttng_live_add_session(struct lttng_live_msg_iter *lttng_live_msg_iter, uint static void lttng_live_destroy_session(struct lttng_live_session *session) { - bt_logging_level log_level; - bt_self_component *self_comp; - if (!session) { goto end; } - log_level = session->log_level; - self_comp = session->self_comp; - BT_COMP_LOGD("Destroying live session: " - "session-id=%" PRIu64 ", session-name=\"%s\"", - session->id, session->session_name->str); + BT_CPPLOGD_SPEC(session->logger, + "Destroying live session: " + "session-id={}, session-name=\"{}\"", + session->id, session->session_name->str); if (session->id != -1ULL) { if (lttng_live_session_detach(session)) { if (!lttng_live_graph_is_canceled(session->lttng_live_msg_iter)) { /* Old relayd cannot detach sessions. */ - BT_COMP_LOGD("Unable to detach lttng live session %" PRIu64, session->id); + BT_CPPLOGD_SPEC(session->logger, "Unable to detach lttng live session {}", + session->id); } } session->id = -1ULL; @@ -312,20 +244,17 @@ void lttng_live_msg_iter_finalize(bt_self_message_iterator *self_msg_iter) static enum lttng_live_iterator_status lttng_live_iterator_next_check_stream_state(struct lttng_live_stream_iterator *lttng_live_stream) { - bt_logging_level log_level = lttng_live_stream->log_level; - bt_self_component *self_comp = lttng_live_stream->self_comp; - switch (lttng_live_stream->state) { case LTTNG_LIVE_STREAM_QUIESCENT: case LTTNG_LIVE_STREAM_ACTIVE_DATA: break; case LTTNG_LIVE_STREAM_ACTIVE_NO_DATA: /* Invalid state. */ - BT_COMP_LOGF("Unexpected stream state \"ACTIVE_NO_DATA\""); + BT_CPPLOGF_SPEC(lttng_live_stream->logger, "Unexpected stream state \"ACTIVE_NO_DATA\""); bt_common_abort(); case LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA: /* Invalid state. */ - BT_COMP_LOGF("Unexpected stream state \"QUIESCENT_NO_DATA\""); + BT_CPPLOGF_SPEC(lttng_live_stream->logger, "Unexpected stream state \"QUIESCENT_NO_DATA\""); bt_common_abort(); case LTTNG_LIVE_STREAM_EOF: break; @@ -345,26 +274,26 @@ static enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_no_da struct lttng_live_msg_iter *lttng_live_msg_iter, struct lttng_live_stream_iterator *lttng_live_stream) { - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; enum lttng_live_iterator_status ret = LTTNG_LIVE_ITERATOR_STATUS_OK; enum lttng_live_stream_state orig_state = lttng_live_stream->state; struct packet_index index; if (lttng_live_stream->trace->metadata_stream_state == LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED) { - BT_COMP_LOGD( + BT_CPPLOGD_SPEC( + lttng_live_msg_iter->logger, "Need to get an update for the metadata stream before proceeding further with this stream: " - "stream-name=\"%s\"", + "stream-name=\"{}\"", lttng_live_stream->name->str); ret = LTTNG_LIVE_ITERATOR_STATUS_CONTINUE; goto end; } if (lttng_live_stream->trace->session->new_streams_needed) { - BT_COMP_LOGD( + BT_CPPLOGD_SPEC( + lttng_live_msg_iter->logger, "Need to get an update of all streams before proceeding further with this stream: " - "stream-name=\"%s\"", + "stream-name=\"{}\"", lttng_live_stream->name->str); ret = LTTNG_LIVE_ITERATOR_STATUS_CONTINUE; goto end; @@ -405,11 +334,12 @@ static enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_no_da lttng_live_stream->offset = index.offset; lttng_live_stream->len = index.packet_size / CHAR_BIT; - BT_COMP_LOGD("Setting live stream reading info: stream-name=\"%s\", " - "viewer-stream-id=%" PRIu64 ", stream-base-offset=%" PRIu64 - ", stream-offset=%" PRIu64 ", stream-len=%" PRIu64, - lttng_live_stream->name->str, lttng_live_stream->viewer_stream_id, - lttng_live_stream->base_offset, lttng_live_stream->offset, lttng_live_stream->len); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Setting live stream reading info: stream-name=\"{}\", " + "viewer-stream-id={}, stream-base-offset={}, stream-offset={}, stream-len={}", + lttng_live_stream->name->str, lttng_live_stream->viewer_stream_id, + lttng_live_stream->base_offset, lttng_live_stream->offset, + lttng_live_stream->len); end: if (ret == LTTNG_LIVE_ITERATOR_STATUS_OK) { @@ -429,13 +359,12 @@ static enum lttng_live_iterator_status lttng_live_get_session(struct lttng_live_msg_iter *lttng_live_msg_iter, struct lttng_live_session *session) { - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; enum lttng_live_iterator_status status; uint64_t trace_idx; if (!session->attached) { - BT_COMP_LOGD("Attach to session: session-id=%" PRIu64, session->id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, "Attach to session: session-id={}", + session->id); enum lttng_live_viewer_status attach_status = lttng_live_session_attach(session, lttng_live_msg_iter->self_msg_iter); if (attach_status != LTTNG_LIVE_VIEWER_STATUS_OK) { @@ -450,15 +379,17 @@ lttng_live_get_session(struct lttng_live_msg_iter *lttng_live_msg_iter, status = LTTNG_LIVE_ITERATOR_STATUS_AGAIN; } else { status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error attaching to LTTng live session"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Error attaching to LTTng live session"); } goto end; } } - BT_COMP_LOGD("Updating all data streams: " - "session-id=%" PRIu64 ", session-name=\"%s\"", - session->id, session->session_name->str); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Updating all data streams: " + "session-id={}, session-name=\"{}\"", + session->id, session->session_name->str); status = lttng_live_session_get_new_streams(session, lttng_live_msg_iter->self_msg_iter); switch (status) { @@ -478,9 +409,10 @@ lttng_live_get_session(struct lttng_live_msg_iter *lttng_live_msg_iter, * stopped before any tracepoint for that event is actually * fired. */ - BT_COMP_LOGD( + BT_CPPLOGD_SPEC( + lttng_live_msg_iter->logger, "Updating streams returned _END status. Override status to _OK in order fetch any remaining metadata:" - "session-id=%" PRIu64 ", session-name=\"%s\"", + "session-id={}, session-name=\"{}\"", session->id, session->session_name->str); status = LTTNG_LIVE_ITERATOR_STATUS_OK; break; @@ -488,9 +420,10 @@ lttng_live_get_session(struct lttng_live_msg_iter *lttng_live_msg_iter, goto end; } - BT_COMP_LOGD("Updating metadata stream for session: " - "session-id=%" PRIu64 ", session-name=\"%s\"", - session->id, session->session_name->str); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Updating metadata stream for session: " + "session-id={}, session-name=\"{}\"", + session->id, session->session_name->str); trace_idx = 0; while (trace_idx < session->traces->len) { @@ -507,10 +440,10 @@ lttng_live_get_session(struct lttng_live_msg_iter *lttng_live_msg_iter, case LTTNG_LIVE_ITERATOR_STATUS_AGAIN: goto end; default: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Error updating trace metadata: " - "stream-iter-status=%s, trace-id=%" PRIu64, - lttng_live_iterator_status_string(status), trace->id); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Error updating trace metadata: " + "stream-iter-status={}, trace-id={}", + status, trace->id); goto end; } } @@ -529,22 +462,22 @@ static void lttng_live_force_new_streams_and_metadata(struct lttng_live_msg_iter *lttng_live_msg_iter) { uint64_t session_idx, trace_idx; - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; for (session_idx = 0; session_idx < lttng_live_msg_iter->sessions->len; session_idx++) { struct lttng_live_session *session = (lttng_live_session *) g_ptr_array_index(lttng_live_msg_iter->sessions, session_idx); - BT_COMP_LOGD("Force marking session as needing new streams: " - "session-id=%" PRIu64, - session->id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Force marking session as needing new streams: " + "session-id={}", + session->id); session->new_streams_needed = true; for (trace_idx = 0; trace_idx < session->traces->len; trace_idx++) { struct lttng_live_trace *trace = (lttng_live_trace *) g_ptr_array_index(session->traces, trace_idx); - BT_COMP_LOGD("Force marking trace metadata state as needing an update: " - "session-id=%" PRIu64 ", trace-id=%" PRIu64, - session->id, trace->id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Force marking trace metadata state as needing an update: " + "session-id={}, trace-id={}", + session->id, trace->id); BT_ASSERT(trace->metadata_stream_state != LTTNG_LIVE_METADATA_STREAM_STATE_CLOSED); @@ -558,16 +491,15 @@ lttng_live_iterator_handle_new_streams_and_metadata(struct lttng_live_msg_iter * { enum lttng_live_iterator_status status; enum lttng_live_viewer_status viewer_status; - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; uint64_t session_idx = 0, nr_sessions_opened = 0; struct lttng_live_session *session; enum session_not_found_action sess_not_found_act = lttng_live_msg_iter->lttng_live_comp->params.sess_not_found_act; - BT_COMP_LOGD("Update data and metadata of all sessions: " - "live-msg-iter-addr=%p", - lttng_live_msg_iter); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Update data and metadata of all sessions: " + "live-msg-iter-addr={}", + fmt::ptr(lttng_live_msg_iter)); /* * In a remotely distant future, we could add a "new * session" flag to the protocol, which would tell us that we @@ -576,12 +508,14 @@ lttng_live_iterator_handle_new_streams_and_metadata(struct lttng_live_msg_iter * */ if (lttng_live_msg_iter->sessions->len == 0) { if (sess_not_found_act != SESSION_NOT_FOUND_ACTION_CONTINUE) { - BT_COMP_LOGD( + BT_CPPLOGD_SPEC( + lttng_live_msg_iter->logger, "No session found. Exiting in accordance with the `session-not-found-action` parameter"); status = LTTNG_LIVE_ITERATOR_STATUS_END; goto end; } else { - BT_COMP_LOGD( + BT_CPPLOGD_SPEC( + lttng_live_msg_iter->logger, "No session found. Try creating a new one in accordance with the `session-not-found-action` parameter"); /* * Retry to create a viewer session for the requested @@ -591,8 +525,8 @@ lttng_live_iterator_handle_new_streams_and_metadata(struct lttng_live_msg_iter * if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Error creating LTTng live viewer session"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Error creating LTTng live viewer session"); } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { status = LTTNG_LIVE_ITERATOR_STATUS_AGAIN; } else { @@ -640,20 +574,21 @@ emit_inactivity_message(struct lttng_live_msg_iter *lttng_live_msg_iter, uint64_t timestamp) { enum lttng_live_iterator_status ret = LTTNG_LIVE_ITERATOR_STATUS_OK; - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; bt_message *msg = NULL; BT_ASSERT(stream_iter->trace->clock_class); - BT_COMP_LOGD("Emitting inactivity message for stream: ctf-stream-id=%" PRIu64 - ", viewer-stream-id=%" PRIu64 ", timestamp=%" PRIu64, - stream_iter->ctf_stream_class_id.value, stream_iter->viewer_stream_id, timestamp); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Emitting inactivity message for stream: ctf-stream-id={}, " + "viewer-stream-id={}, timestamp={}", + stream_iter->ctf_stream_class_id.value, stream_iter->viewer_stream_id, + timestamp); msg = bt_message_message_iterator_inactivity_create(lttng_live_msg_iter->self_msg_iter, stream_iter->trace->clock_class, timestamp); if (!msg) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error emitting message iterator inactivity message"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Error emitting message iterator inactivity message"); goto error; } @@ -704,15 +639,14 @@ static int live_get_msg_ts_ns(struct lttng_live_msg_iter *lttng_live_msg_iter, { const bt_clock_snapshot *clock_snapshot = NULL; int ret = 0; - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; BT_ASSERT_DBG(msg); BT_ASSERT_DBG(ts_ns); - BT_COMP_LOGD("Getting message's timestamp: iter-data-addr=%p, msg-addr=%p, " - "last-msg-ts=%" PRId64, - lttng_live_msg_iter, msg, last_msg_ts_ns); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Getting message's timestamp: iter-data-addr={}, msg-addr={}, " + "last-msg-ts={}", + fmt::ptr(lttng_live_msg_iter), fmt::ptr(msg), last_msg_ts_ns); switch (bt_message_get_type(msg)) { case BT_MESSAGE_TYPE_EVENT: @@ -737,17 +671,18 @@ static int live_get_msg_ts_ns(struct lttng_live_msg_iter *lttng_live_msg_iter, break; default: /* All the other messages have a higher priority */ - BT_COMP_LOGD_STR("Message has no timestamp: using the last message timestamp."); + BT_CPPLOGD_STR_SPEC(lttng_live_msg_iter->logger, + "Message has no timestamp: using the last message timestamp."); *ts_ns = last_msg_ts_ns; goto end; } ret = bt_clock_snapshot_get_ns_from_origin(clock_snapshot, ts_ns); if (ret) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot get nanoseconds from Epoch of clock snapshot: " - "clock-snapshot-addr=%p", - clock_snapshot); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Cannot get nanoseconds from Epoch of clock snapshot: " + "clock-snapshot-addr={}", + fmt::ptr(clock_snapshot)); goto error; } @@ -758,10 +693,10 @@ error: end: if (ret == 0) { - BT_COMP_LOGD("Found message's timestamp: " - "iter-data-addr=%p, msg-addr=%p, " - "last-msg-ts=%" PRId64 ", ts=%" PRId64, - lttng_live_msg_iter, msg, last_msg_ts_ns, *ts_ns); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Found message's timestamp: iter-data-addr={}, msg-addr={}, " + "last-msg-ts={}, ts={}", + fmt::ptr(lttng_live_msg_iter), fmt::ptr(msg), last_msg_ts_ns, *ts_ns); } return ret; @@ -772,8 +707,6 @@ static enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_activ struct lttng_live_stream_iterator *lttng_live_stream, const bt_message **message) { enum lttng_live_iterator_status ret = LTTNG_LIVE_ITERATOR_STATUS_OK; - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; enum ctf_msg_iter_status status; uint64_t session_idx, trace_idx; @@ -782,9 +715,10 @@ static enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_activ (lttng_live_session *) g_ptr_array_index(lttng_live_msg_iter->sessions, session_idx); if (session->new_streams_needed) { - BT_COMP_LOGD("Need an update for streams: " - "session-id=%" PRIu64, - session->id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Need an update for streams: " + "session-id={}", + session->id); ret = LTTNG_LIVE_ITERATOR_STATUS_CONTINUE; goto end; } @@ -792,9 +726,10 @@ static enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_activ struct lttng_live_trace *trace = (lttng_live_trace *) g_ptr_array_index(session->traces, trace_idx); if (trace->metadata_stream_state == LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED) { - BT_COMP_LOGD("Need an update for metadata stream: " - "session-id=%" PRIu64 ", trace-id=%" PRIu64, - session->id, trace->id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Need an update for metadata stream: " + "session-id={}, trace-id={}", + session->id, trace->id); ret = LTTNG_LIVE_ITERATOR_STATUS_CONTINUE; goto end; } @@ -803,10 +738,10 @@ static enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_activ if (lttng_live_stream->state != LTTNG_LIVE_STREAM_ACTIVE_DATA) { ret = LTTNG_LIVE_ITERATOR_STATUS_ERROR; - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Invalid state of live stream iterator" - "stream-iter-status=%s", - lttng_live_stream_state_string(lttng_live_stream->state)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Invalid state of live stream iterator" + "stream-iter-status={}", + lttng_live_stream->state); goto end; } @@ -829,10 +764,10 @@ static enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_activ case CTF_MSG_ITER_STATUS_ERROR: default: ret = LTTNG_LIVE_ITERATOR_STATUS_ERROR; - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "CTF message iterator failed to get next message: " - "msg-iter=%p, msg-iter-status=%s", - lttng_live_stream->msg_iter, ctf_msg_iter_status_string(status)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "CTF message iterator failed to get next message: " + "msg-iter={}, msg-iter-status={}", + fmt::ptr(lttng_live_stream->msg_iter), status); break; } @@ -846,12 +781,11 @@ lttng_live_iterator_close_stream(struct lttng_live_msg_iter *lttng_live_msg_iter const bt_message **curr_msg) { enum lttng_live_iterator_status live_status = LTTNG_LIVE_ITERATOR_STATUS_OK; - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; - BT_COMP_LOGD("Closing live stream iterator: stream-name=\"%s\", " - "viewer-stream-id=%" PRIu64, - stream_iter->name->str, stream_iter->viewer_stream_id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Closing live stream iterator: stream-name=\"{}\", " + "viewer-stream-id={}", + stream_iter->name->str, stream_iter->viewer_stream_id); /* * The viewer has hung up on us so we are closing the stream. The @@ -862,12 +796,13 @@ lttng_live_iterator_close_stream(struct lttng_live_msg_iter *lttng_live_msg_iter ctf_msg_iter_get_next_message(stream_iter->msg_iter, curr_msg); if (status == CTF_MSG_ITER_STATUS_ERROR) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Error getting the next message from CTF message iterator"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Error getting the next message from CTF message iterator"); live_status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; goto end; } else if (status == CTF_MSG_ITER_STATUS_EOF) { - BT_COMP_LOGI("Reached the end of the live stream iterator."); + BT_CPPLOGI_SPEC(lttng_live_msg_iter->logger, + "Reached the end of the live stream iterator."); live_status = LTTNG_LIVE_ITERATOR_STATUS_END; goto end; } @@ -931,13 +866,12 @@ lttng_live_iterator_next_msg_on_stream(struct lttng_live_msg_iter *lttng_live_ms struct lttng_live_stream_iterator *stream_iter, const bt_message **curr_msg) { - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; enum lttng_live_iterator_status live_status; - BT_COMP_LOGD("Advancing live stream iterator until next message if possible: " - "stream-name=\"%s\", viewer-stream-id=%" PRIu64, - stream_iter->name->str, stream_iter->viewer_stream_id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Advancing live stream iterator until next message if possible: " + "stream-name=\"{}\", viewer-stream-id={}", + stream_iter->name->str, stream_iter->viewer_stream_id); if (stream_iter->has_stream_hung_up) { /* @@ -993,14 +927,16 @@ retry: end: if (live_status == LTTNG_LIVE_ITERATOR_STATUS_CONTINUE) { - BT_COMP_LOGD("Ask the relay daemon for an updated view of the data and metadata streams"); + BT_CPPLOGD_SPEC( + lttng_live_msg_iter->logger, + "Ask the relay daemon for an updated view of the data and metadata streams"); goto retry; } - BT_COMP_LOGD("Returning from advancing live stream iterator: status=%s, " - "stream-name=\"%s\", viewer-stream-id=%" PRIu64, - lttng_live_iterator_status_string(live_status), stream_iter->name->str, - stream_iter->viewer_stream_id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Returning from advancing live stream iterator: status={}, " + "stream-name=\"{}\", viewer-stream-id={}", + live_status, stream_iter->name->str, stream_iter->viewer_stream_id); return live_status; } @@ -1076,8 +1012,6 @@ handle_late_message(struct lttng_live_msg_iter *lttng_live_msg_iter, struct lttng_live_stream_iterator *stream_iter, int64_t late_msg_ts_ns, const bt_message *late_msg) { - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; - bt_logging_level log_level = lttng_live_msg_iter->log_level; const bt_clock_class *clock_class; const bt_stream_class *stream_class; enum bt_clock_class_cycles_to_ns_from_origin_status ts_ns_status; @@ -1115,24 +1049,26 @@ handle_late_message(struct lttng_live_msg_iter *lttng_live_msg_iter, * timespan we sent downstream through the inactivity message. */ - BT_COMP_LOGD("Handling late message on live stream iterator: " - "stream-name=\"%s\", viewer-stream-id=%" PRIu64, - stream_iter->name->str, stream_iter->viewer_stream_id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Handling late message on live stream iterator: " + "stream-name=\"{}\", viewer-stream-id={}", + stream_iter->name->str, stream_iter->viewer_stream_id); if (!stream_iter->last_inactivity_ts.is_set) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Invalid live stream state: " - "have a late message when no inactivity message " - "was ever sent for that stream."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Invalid live stream state: " + "have a late message when no inactivity message " + "was ever sent for that stream."); stream_iter_status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; goto end; } if (!is_discarded_packet_or_event_message(late_msg)) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Invalid live stream state: " - "have a late message that is not a packet discarded or " - "event discarded message: late-msg-type=%s", - bt_common_message_type_string(bt_message_get_type(late_msg))); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Invalid live stream state: " + "have a late message that is not a packet discarded or " + "event discarded message: late-msg-type={}", + static_cast(bt_message_get_type(late_msg))); stream_iter_status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; goto end; } @@ -1143,19 +1079,20 @@ handle_late_message(struct lttng_live_msg_iter *lttng_live_msg_iter, ts_ns_status = bt_clock_class_cycles_to_ns_from_origin( clock_class, stream_iter->last_inactivity_ts.value, &last_inactivity_ts_ns); if (ts_ns_status != BT_CLOCK_CLASS_CYCLES_TO_NS_FROM_ORIGIN_STATUS_OK) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error converting last " - "inactivity message timestamp to nanoseconds"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Error converting last " + "inactivity message timestamp to nanoseconds"); stream_iter_status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; goto end; } if (last_inactivity_ts_ns <= late_msg_ts_ns) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Invalid live stream state: " - "have a late message that is none included in a stream " - "inactivity timespan: last-inactivity-ts-ns=%" PRIu64 - "late-msg-ts-ns=%" PRIu64, - last_inactivity_ts_ns, late_msg_ts_ns); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Invalid live stream state: " + "have a late message that is none included in a stream " + "inactivity timespan: last-inactivity-ts-ns={}, " + "late-msg-ts-ns={}", + last_inactivity_ts_ns, late_msg_ts_ns); stream_iter_status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; goto end; } @@ -1164,10 +1101,11 @@ handle_late_message(struct lttng_live_msg_iter *lttng_live_msg_iter, * We now know that it's okay for this message to be late, we can now * adjust its timestamp to ensure monotonicity. */ - BT_COMP_LOGD("Adjusting the timestamp of late message: late-msg-type=%s, " - "msg-new-ts-ns=%" PRIu64, - bt_common_message_type_string(bt_message_get_type(late_msg)), - stream_iter->last_inactivity_ts.value); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Adjusting the timestamp of late message: late-msg-type={}, " + "msg-new-ts-ns={}", + static_cast(bt_message_get_type(late_msg)), + stream_iter->last_inactivity_ts.value); switch (bt_message_get_type(late_msg)) { case BT_MESSAGE_TYPE_DISCARDED_EVENTS: adjust_status = adjust_discarded_events_message( @@ -1203,19 +1141,17 @@ next_stream_iterator_for_trace(struct lttng_live_msg_iter *lttng_live_msg_iter, struct lttng_live_stream_iterator **youngest_trace_stream_iter) { struct lttng_live_stream_iterator *youngest_candidate_stream_iter = NULL; - bt_logging_level log_level = lttng_live_msg_iter->log_level; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; enum lttng_live_iterator_status stream_iter_status; - ; int64_t youngest_candidate_msg_ts = INT64_MAX; uint64_t stream_iter_idx; BT_ASSERT_DBG(live_trace); BT_ASSERT_DBG(live_trace->stream_iterators); - BT_COMP_LOGD("Finding the next stream iterator for trace: " - "trace-id=%" PRIu64, - live_trace->id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Finding the next stream iterator for trace: " + "trace-id={}", + live_trace->id); /* * Update the current message of every stream iterators of this trace. * The current msg of every stream must have a timestamp equal or @@ -1251,10 +1187,11 @@ next_stream_iterator_for_trace(struct lttng_live_msg_iter *lttng_live_msg_iter, BT_ASSERT_DBG(msg); - BT_COMP_LOGD("Live stream iterator returned message: msg-type=%s, " - "stream-name=\"%s\", viewer-stream-id=%" PRIu64, - bt_common_message_type_string(bt_message_get_type(msg)), - stream_iter->name->str, stream_iter->viewer_stream_id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Live stream iterator returned message: msg-type={}, " + "stream-name=\"{}\", viewer-stream-id={}", + static_cast(bt_message_get_type(msg)), + stream_iter->name->str, stream_iter->viewer_stream_id); /* * Get the timestamp in nanoseconds from origin of this @@ -1280,13 +1217,14 @@ next_stream_iterator_for_trace(struct lttng_live_msg_iter *lttng_live_msg_iter, stream_iter_status = handle_late_message(lttng_live_msg_iter, stream_iter, curr_msg_ts_ns, msg); if (stream_iter_status != LTTNG_LIVE_ITERATOR_STATUS_OK) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Late message could not be handled correctly: " - "lttng-live-msg-iter-addr=%p, " - "stream-name=\"%s\", " - "curr-msg-ts=%" PRId64 ", last-msg-ts=%" PRId64, - lttng_live_msg_iter, stream_iter->name->str, - curr_msg_ts_ns, lttng_live_msg_iter->last_msg_ts_ns); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Late message could not be handled correctly: " + "lttng-live-msg-iter-addr={}, " + "stream-name=\"{}\", " + "curr-msg-ts={}, last-msg-ts={}", + fmt::ptr(lttng_live_msg_iter), + stream_iter->name->str, curr_msg_ts_ns, + lttng_live_msg_iter->last_msg_ts_ns); stream_iter_status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; goto end; } @@ -1326,11 +1264,12 @@ next_stream_iterator_for_trace(struct lttng_live_msg_iter *lttng_live_msg_iter, * Unable to pick which one should go * first. */ - BT_COMP_LOGW( + BT_CPPLOGW_SPEC( + lttng_live_msg_iter->logger, "Cannot deterministically pick next live stream message iterator because they have identical next messages: " - "stream-iter-addr=%p" - "stream-iter-addr=%p", - stream_iter, youngest_candidate_stream_iter); + "stream-iter-addr={}" + "stream-iter-addr={}", + fmt::ptr(stream_iter), fmt::ptr(youngest_candidate_stream_iter)); } } @@ -1370,16 +1309,15 @@ next_stream_iterator_for_session(struct lttng_live_msg_iter *lttng_live_msg_iter struct lttng_live_session *session, struct lttng_live_stream_iterator **youngest_session_stream_iter) { - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; - bt_logging_level log_level = lttng_live_msg_iter->log_level; enum lttng_live_iterator_status stream_iter_status; uint64_t trace_idx = 0; int64_t youngest_candidate_msg_ts = INT64_MAX; struct lttng_live_stream_iterator *youngest_candidate_stream_iter = NULL; - BT_COMP_LOGD("Finding the next stream iterator for session: " - "session-id=%" PRIu64, - session->id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Finding the next stream iterator for session: " + "session-id={}", + session->id); /* * Make sure we are attached to the session and look for new streams * and metadata. @@ -1435,11 +1373,12 @@ next_stream_iterator_for_session(struct lttng_live_msg_iter *lttng_live_msg_iter youngest_candidate_stream_iter = stream_iter; } else if (ret == 0) { /* Unable to pick which one should go first. */ - BT_COMP_LOGW( + BT_CPPLOGW_SPEC( + lttng_live_msg_iter->logger, "Cannot deterministically pick next live stream message iterator because they have identical next messages: " - "stream-iter-addr=%p" - "stream-iter-addr=%p", - stream_iter, youngest_candidate_stream_iter); + "stream-iter-addr={}" + "youngest-candidate-stream-iter-addr={}", + fmt::ptr(stream_iter), fmt::ptr(youngest_candidate_stream_iter)); } } trace_idx++; @@ -1490,8 +1429,6 @@ lttng_live_msg_iter_next(bt_self_message_iterator *self_msg_it, bt_message_array struct lttng_live_msg_iter *lttng_live_msg_iter = (struct lttng_live_msg_iter *) bt_self_message_iterator_get_data(self_msg_it); struct lttng_live_component *lttng_live = lttng_live_msg_iter->lttng_live_comp; - bt_self_component *self_comp = lttng_live_msg_iter->self_comp; - bt_logging_level log_level = lttng_live_msg_iter->log_level; enum lttng_live_iterator_status stream_iter_status; uint64_t session_idx; @@ -1509,8 +1446,8 @@ lttng_live_msg_iter_next(bt_self_message_iterator *self_msg_it, bt_message_array * iterator in an messed up internal state. */ status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR; - BT_COMP_LOGE_APPEND_CAUSE( - self_comp, + BT_CPPLOGE_APPEND_CAUSE_SPEC( + lttng_live_msg_iter->logger, "Message iterator was interrupted during a previous call to the `next()` and currently does not support continuing after such event."); goto end; } @@ -1540,8 +1477,8 @@ lttng_live_msg_iter_next(bt_self_message_iterator *self_msg_it, bt_message_array if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR; - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Error creating LTTng live viewer session"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Error creating LTTng live viewer session"); } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_AGAIN; } else { @@ -1625,7 +1562,8 @@ lttng_live_msg_iter_next(bt_self_message_iterator *self_msg_it, bt_message_array * that of the current candidate message. We * must break the tie in a predictable manner. */ - BT_COMP_LOGD_STR( + BT_CPPLOGD_STR_SPEC( + lttng_live_msg_iter->logger, "Two of the next message candidates have the same timestamps, pick one deterministically."); /* * Order the messages in an arbitrary but @@ -1643,11 +1581,12 @@ lttng_live_msg_iter_next(bt_self_message_iterator *self_msg_it, bt_message_array youngest_stream_iter = candidate_stream_iter; } else if (ret == 0) { /* Unable to pick which one should go first. */ - BT_COMP_LOGW( + BT_CPPLOGW_SPEC( + lttng_live_msg_iter->logger, "Cannot deterministically pick next live stream message iterator because they have identical next messages: " - "next-stream-iter-addr=%p" - "candidate-stream-iter-addr=%p", - youngest_stream_iter, candidate_stream_iter); + "next-stream-iter-addr={}" + "candidate-stream-iter-addr={}", + fmt::ptr(youngest_stream_iter), fmt::ptr(candidate_stream_iter)); } } @@ -1701,19 +1640,19 @@ return_status: status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END; break; case LTTNG_LIVE_ITERATOR_STATUS_NOMEM: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Memory error preparing the next batch of messages: " - "live-iter-status=%s", - lttng_live_iterator_status_string(stream_iter_status)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Memory error preparing the next batch of messages: " + "live-iter-status={}", + stream_iter_status); status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_MEMORY_ERROR; break; case LTTNG_LIVE_ITERATOR_STATUS_ERROR: case LTTNG_LIVE_ITERATOR_STATUS_INVAL: case LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Error preparing the next batch of messages: " - "live-iter-status=%s", - lttng_live_iterator_status_string(stream_iter_status)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Error preparing the next batch of messages: " + "live-iter-status={}", + stream_iter_status); status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR; /* Put all existing messages on error. */ @@ -1731,21 +1670,20 @@ static struct lttng_live_msg_iter * lttng_live_msg_iter_create(struct lttng_live_component *lttng_live_comp, bt_self_message_iterator *self_msg_it) { - lttng_live_msg_iter *lttng_live_msg_iter = new struct lttng_live_msg_iter; - lttng_live_msg_iter->log_level = lttng_live_comp->log_level; - lttng_live_msg_iter->self_comp = lttng_live_comp->self_comp; - lttng_live_msg_iter->lttng_live_comp = lttng_live_comp; - lttng_live_msg_iter->self_msg_iter = self_msg_it; + lttng_live_msg_iter *msg_iter = new lttng_live_msg_iter {lttng_live_comp->logger}; + msg_iter->self_comp = lttng_live_comp->self_comp; + msg_iter->lttng_live_comp = lttng_live_comp; + msg_iter->self_msg_iter = self_msg_it; - lttng_live_msg_iter->active_stream_iter = 0; - lttng_live_msg_iter->last_msg_ts_ns = INT64_MIN; - lttng_live_msg_iter->was_interrupted = false; + msg_iter->active_stream_iter = 0; + msg_iter->last_msg_ts_ns = INT64_MIN; + msg_iter->was_interrupted = false; - lttng_live_msg_iter->sessions = + msg_iter->sessions = g_ptr_array_new_with_free_func((GDestroyNotify) lttng_live_destroy_session); - BT_ASSERT(lttng_live_msg_iter->sessions); + BT_ASSERT(msg_iter->sessions); - return lttng_live_msg_iter; + return msg_iter; } bt_message_iterator_class_initialize_method_status @@ -1756,12 +1694,9 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it, struct lttng_live_component *lttng_live; struct lttng_live_msg_iter *lttng_live_msg_iter; enum lttng_live_viewer_status viewer_status; - bt_logging_level log_level; bt_self_component *self_comp = bt_self_message_iterator_borrow_component(self_msg_it); lttng_live = (lttng_live_component *) bt_self_component_get_data(self_comp); - log_level = lttng_live->log_level; - self_comp = lttng_live->self_comp; /* There can be only one downstream iterator at the same time. */ BT_ASSERT(!lttng_live->has_msg_iter); @@ -1769,23 +1704,25 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it, lttng_live_msg_iter = lttng_live_msg_iter_create(lttng_live, self_msg_it); if (!lttng_live_msg_iter) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create lttng_live_msg_iter"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live->logger, "Failed to create lttng_live_msg_iter"); status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto error; } - viewer_status = live_viewer_connection_create( - self_comp, NULL, log_level, lttng_live->params.url->str, false, lttng_live_msg_iter, - <tng_live_msg_iter->viewer_connection); + viewer_status = live_viewer_connection_create(lttng_live->params.url->str, false, + lttng_live_msg_iter, lttng_live_msg_iter->logger, + <tng_live_msg_iter->viewer_connection); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create viewer connection"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Failed to create viewer connection"); } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { /* * Interruption in the _iter_init() method is not * supported. Return an error. */ - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Interrupted while creating viewer connection"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Interrupted while creating viewer connection"); } status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR; @@ -1795,13 +1732,15 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it, viewer_status = lttng_live_create_viewer_session(lttng_live_msg_iter); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create viewer session"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Failed to create viewer session"); } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { /* * Interruption in the _iter_init() method is not * supported. Return an error. */ - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Interrupted when creating viewer session"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger, + "Interrupted when creating viewer session"); } status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR; @@ -1811,26 +1750,29 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it, if (lttng_live_msg_iter->sessions->len == 0) { switch (lttng_live->params.sess_not_found_act) { case SESSION_NOT_FOUND_ACTION_CONTINUE: - BT_COMP_LOGI( - "Unable to connect to the requested live viewer session. Keep trying to connect because of " - "%s=\"%s\" component parameter: url=\"%s\"", + BT_CPPLOGI_SPEC( + lttng_live_msg_iter->logger, + "Unable to connect to the requested live viewer session. Keep " + "trying to connect because of {}=\"{}\" component parameter: url=\"{}\"", SESS_NOT_FOUND_ACTION_PARAM, SESS_NOT_FOUND_ACTION_CONTINUE_STR, lttng_live->params.url->str); break; case SESSION_NOT_FOUND_ACTION_FAIL: - BT_COMP_LOGE_APPEND_CAUSE( - self_comp, - "Unable to connect to the requested live viewer session. Fail the message iterator initialization because of %s=\"%s\" " - "component parameter: url =\"%s\"", + BT_CPPLOGE_APPEND_CAUSE_SPEC( + lttng_live_msg_iter->logger, + "Unable to connect to the requested live viewer session. Fail " + "the message iterator initialization because of {}=\"{}\" " + "component parameter: url =\"{}\"", SESS_NOT_FOUND_ACTION_PARAM, SESS_NOT_FOUND_ACTION_FAIL_STR, lttng_live->params.url->str); status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto error; case SESSION_NOT_FOUND_ACTION_END: - BT_COMP_LOGI( + BT_CPPLOGI_SPEC( + lttng_live_msg_iter->logger, "Unable to connect to the requested live viewer session. End gracefully at the first _next() " - "call because of %s=\"%s\" component parameter: " - "url=\"%s\"", + "call because of {}=\"{}\" component parameter: " + "url=\"{}\"", SESS_NOT_FOUND_ACTION_PARAM, SESS_NOT_FOUND_ACTION_END_STR, lttng_live->params.url->str); break; @@ -1856,7 +1798,7 @@ static struct bt_param_validation_map_value_entry_descr list_sessions_params[] = static bt_component_class_query_method_status lttng_live_query_list_sessions(const bt_value *params, const bt_value **result, - bt_self_component_class *self_comp_class, bt_logging_level log_level) + const bt2c::Logger& logger) { bt_component_class_query_method_status status; const bt_value *url_value = NULL; @@ -1872,18 +1814,17 @@ lttng_live_query_list_sessions(const bt_value *params, const bt_value **result, goto error; } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) { status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "%s", validate_error); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "{}", validate_error); goto error; } url_value = bt_value_map_borrow_entry_value_const(params, URL_PARAM); url = bt_value_string_get(url_value); - viewer_status = live_viewer_connection_create(NULL, self_comp_class, log_level, url, true, NULL, - &viewer_connection); + viewer_status = live_viewer_connection_create(url, true, NULL, logger, &viewer_connection); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Failed to create viewer connection"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Failed to create viewer connection"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_AGAIN; @@ -1895,7 +1836,7 @@ lttng_live_query_list_sessions(const bt_value *params, const bt_value **result, status = live_viewer_connection_list_sessions(viewer_connection, result); if (status != BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Failed to list viewer sessions"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Failed to list viewer sessions"); goto error; } @@ -1920,7 +1861,7 @@ end: static bt_component_class_query_method_status lttng_live_query_support_info(const bt_value *params, const bt_value **result, - bt_self_component_class *self_comp_class, bt_logging_level log_level) + const bt2c::Logger& logger) { bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK; const bt_value *input_type_value; @@ -1934,12 +1875,12 @@ lttng_live_query_support_info(const bt_value *params, const bt_value **result, *result = NULL; input_type_value = bt_value_map_borrow_entry_value_const(params, "type"); if (!input_type_value) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Missing expected `type` parameter."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Missing expected `type` parameter."); goto error; } if (!bt_value_is_string(input_type_value)) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "`type` parameter is not a string value."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "`type` parameter is not a string value."); goto error; } @@ -1950,13 +1891,12 @@ lttng_live_query_support_info(const bt_value *params, const bt_value **result, input_value = bt_value_map_borrow_entry_value_const(params, "input"); if (!input_value) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Missing expected `input` parameter."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Missing expected `input` parameter."); goto error; } if (!bt_value_is_string(input_value)) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, - "`input` parameter is not a string value."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "`input` parameter is not a string value."); goto error; } @@ -1997,18 +1937,16 @@ bt_component_class_query_method_status lttng_live_query(bt_self_component_class_ const bt_value **result) { bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK; - bt_self_component *self_comp = NULL; - bt_self_component_class *self_comp_class = - bt_self_component_class_source_as_self_component_class(comp_class); - bt_logging_level log_level = bt_query_executor_get_logging_level( - bt_private_query_executor_as_query_executor_const(priv_query_exec)); + bt2c::Logger logger {bt2::SelfComponentClass {comp_class}, + bt2::PrivateQueryExecutor {priv_query_exec}, + "PLUGIN/SRC.CTF.LTTNG-LIVE/QUERY"}; if (strcmp(object, "sessions") == 0) { - status = lttng_live_query_list_sessions(params, result, self_comp_class, log_level); + status = lttng_live_query_list_sessions(params, result, logger); } else if (strcmp(object, "babeltrace.support-info") == 0) { - status = lttng_live_query_support_info(params, result, self_comp_class, log_level); + status = lttng_live_query_support_info(params, result, logger); } else { - BT_COMP_LOGI("Unknown query object `%s`", object); + BT_CPPLOGI_SPEC(logger, "Unknown query object `{}`", object); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT; goto end; } @@ -2076,8 +2014,8 @@ static struct bt_param_validation_map_value_entry_descr params_descr[] = { BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END}; static bt_component_class_initialize_method_status -lttng_live_component_create(const bt_value *params, bt_logging_level log_level, - bt_self_component *self_comp, struct lttng_live_component **component) +lttng_live_component_create(const bt_value *params, bt_self_component_source *self_comp, + struct lttng_live_component **component) { struct lttng_live_component *lttng_live = NULL; const bt_value *inputs_value; @@ -2087,20 +2025,20 @@ lttng_live_component_create(const bt_value *params, bt_logging_level log_level, enum bt_param_validation_status validation_status; gchar *validation_error = NULL; bt_component_class_initialize_method_status status; + bt2c::Logger logger {bt2::SelfSourceComponent {self_comp}, "PLUGIN/SRC.CTF.LTTNG-LIVE/COMP"}; validation_status = bt_param_validation_validate(params, params_descr, &validation_error); if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) { status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; goto error; } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "%s", validation_error); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "{}", validation_error); status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; goto error; } - lttng_live = new lttng_live_component; - lttng_live->log_level = log_level; - lttng_live->self_comp = self_comp; + lttng_live = new lttng_live_component {std::move(logger)}; + lttng_live->self_comp = bt_self_component_source_as_self_component(self_comp); lttng_live->max_query_size = MAX_QUERY_SIZE; lttng_live->has_msg_iter = false; @@ -2118,9 +2056,9 @@ lttng_live_component_create(const bt_value *params, bt_logging_level log_level, if (value) { lttng_live->params.sess_not_found_act = parse_session_not_found_action_param(value); } else { - BT_COMP_LOGI("Optional `%s` parameter is missing: " - "defaulting to `%s`.", - SESS_NOT_FOUND_ACTION_PARAM, SESS_NOT_FOUND_ACTION_CONTINUE_STR); + BT_CPPLOGI_SPEC(lttng_live->logger, + "Optional `{}` parameter is missing: defaulting to `{}`.", + SESS_NOT_FOUND_ACTION_PARAM, SESS_NOT_FOUND_ACTION_CONTINUE_STR); lttng_live->params.sess_not_found_act = SESSION_NOT_FOUND_ACTION_CONTINUE; } @@ -2144,11 +2082,9 @@ lttng_live_component_init(bt_self_component_source *self_comp_src, struct lttng_live_component *lttng_live; bt_component_class_initialize_method_status ret; bt_self_component *self_comp = bt_self_component_source_as_self_component(self_comp_src); - bt_logging_level log_level = - bt_component_get_logging_level(bt_self_component_as_component(self_comp)); bt_self_component_add_port_status add_port_status; - ret = lttng_live_component_create(params, log_level, self_comp, <tng_live); + ret = lttng_live_component_create(params, self_comp_src, <tng_live); if (ret != BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) { goto error; } diff --git a/src/plugins/ctf/lttng-live/lttng-live.hpp b/src/plugins/ctf/lttng-live/lttng-live.hpp index 4f84ca79..7d93326f 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.hpp +++ b/src/plugins/ctf/lttng-live/lttng-live.hpp @@ -16,6 +16,8 @@ #include +#include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */ + #include "../common/src/metadata/tsdl/decoder.hpp" #include "../common/src/msg-iter/msg-iter.hpp" #include "viewer-connection.hpp" @@ -40,11 +42,37 @@ enum lttng_live_stream_state LTTNG_LIVE_STREAM_EOF, }; +inline const char *format_as(const lttng_live_stream_state state) noexcept +{ + switch (state) { + case LTTNG_LIVE_STREAM_ACTIVE_NO_DATA: + return "ACTIVE_NO_DATA"; + + case LTTNG_LIVE_STREAM_QUIESCENT_NO_DATA: + return "QUIESCENT_NO_DATA"; + + case LTTNG_LIVE_STREAM_QUIESCENT: + return "QUIESCENT"; + + case LTTNG_LIVE_STREAM_ACTIVE_DATA: + return "ACTIVE_DATA"; + + case LTTNG_LIVE_STREAM_EOF: + return "EOF"; + } + + bt_common_abort(); +} + /* Iterator over a live stream. */ struct lttng_live_stream_iterator { - bt_logging_level log_level = (bt_logging_level) 0; - bt_self_component *self_comp = nullptr; + explicit lttng_live_stream_iterator(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/STREAM-ITER"} + { + } + + bt2c::Logger logger; /* Owned by this. */ bt_stream *stream = nullptr; @@ -112,8 +140,12 @@ struct lttng_live_stream_iterator struct lttng_live_metadata { - bt_logging_level log_level = (bt_logging_level) 0; - bt_self_component *self_comp = nullptr; + explicit lttng_live_metadata(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/METADATA"} + { + } + + bt2c::Logger logger; uint64_t stream_id = 0; /* Weak reference. */ @@ -144,8 +176,12 @@ enum lttng_live_metadata_stream_state struct lttng_live_trace { - bt_logging_level log_level = (bt_logging_level) 0; - bt_self_component *self_comp = nullptr; + explicit lttng_live_trace(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/TRACE"} + { + } + + bt2c::Logger logger; /* Back reference to session. */ struct lttng_live_session *session = nullptr; @@ -173,7 +209,13 @@ struct lttng_live_trace struct lttng_live_session { - bt_logging_level log_level = (bt_logging_level) 0; + explicit lttng_live_session(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/SESSION"} + { + } + + bt2c::Logger logger; + bt_self_component *self_comp = nullptr; /* Weak reference. */ @@ -208,7 +250,12 @@ enum session_not_found_action */ struct lttng_live_component { - bt_logging_level log_level = (bt_logging_level) 0; + explicit lttng_live_component(bt2c::Logger loggerParam) noexcept : + logger {std::move(loggerParam)} + { + } + + bt2c::Logger logger; /* Weak reference. */ bt_self_component *self_comp = nullptr; @@ -230,7 +277,13 @@ struct lttng_live_component struct lttng_live_msg_iter { - bt_logging_level log_level = (bt_logging_level) 0; + explicit lttng_live_msg_iter(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/MSG-ITER"} + { + } + + bt2c::Logger logger; + bt_self_component *self_comp = nullptr; /* Weak reference. */ @@ -275,6 +328,37 @@ enum lttng_live_iterator_status LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED = -4, }; +inline const char *format_as(const lttng_live_iterator_status status) noexcept +{ + switch (status) { + case LTTNG_LIVE_ITERATOR_STATUS_CONTINUE: + return "LTTNG_LIVE_ITERATOR_STATUS_CONTINUE"; + + case LTTNG_LIVE_ITERATOR_STATUS_AGAIN: + return "LTTNG_LIVE_ITERATOR_STATUS_AGAIN"; + + case LTTNG_LIVE_ITERATOR_STATUS_END: + return "LTTNG_LIVE_ITERATOR_STATUS_END"; + + case LTTNG_LIVE_ITERATOR_STATUS_OK: + return "LTTNG_LIVE_ITERATOR_STATUS_OK"; + + case LTTNG_LIVE_ITERATOR_STATUS_INVAL: + return "LTTNG_LIVE_ITERATOR_STATUS_INVAL"; + + case LTTNG_LIVE_ITERATOR_STATUS_ERROR: + return "LTTNG_LIVE_ITERATOR_STATUS_ERROR"; + + case LTTNG_LIVE_ITERATOR_STATUS_NOMEM: + return "LTTNG_LIVE_ITERATOR_STATUS_NOMEM"; + + case LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED: + return "LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED"; + } + + bt_common_abort(); +} + bt_component_class_initialize_method_status lttng_live_component_init(bt_self_component_source *self_comp, bt_self_component_source_configuration *config, const bt_value *params, diff --git a/src/plugins/ctf/lttng-live/lttng-viewer-abi.hpp b/src/plugins/ctf/lttng-live/lttng-viewer-abi.hpp index bf9abae4..926ace11 100644 --- a/src/plugins/ctf/lttng-live/lttng-viewer-abi.hpp +++ b/src/plugins/ctf/lttng-live/lttng-viewer-abi.hpp @@ -11,7 +11,9 @@ #include -#include "compat/limits.h" /* IWYU pragma: keep */ +#include "common/common.h" +#include "compat/limits.h" /* IWYU pragma: keep */ +#include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */ #define LTTNG_VIEWER_PATH_MAX 4096 #define LTTNG_VIEWER_NAME_MAX 255 @@ -39,6 +41,40 @@ enum lttng_viewer_command LTTNG_VIEWER_DETACH_SESSION = 9, }; +inline const char *format_as(const lttng_viewer_command cmd) noexcept +{ + switch (cmd) { + case LTTNG_VIEWER_CONNECT: + return "CONNECT"; + + case LTTNG_VIEWER_LIST_SESSIONS: + return "LIST_SESSIONS"; + + case LTTNG_VIEWER_ATTACH_SESSION: + return "ATTACH_SESSION"; + + case LTTNG_VIEWER_GET_NEXT_INDEX: + return "GET_NEXT_INDEX"; + + case LTTNG_VIEWER_GET_PACKET: + return "GET_PACKET"; + + case LTTNG_VIEWER_GET_METADATA: + return "GET_METADATA"; + + case LTTNG_VIEWER_GET_NEW_STREAMS: + return "GET_NEW_STREAMS"; + + case LTTNG_VIEWER_CREATE_SESSION: + return "CREATE_SESSION"; + + case LTTNG_VIEWER_DETACH_SESSION: + return "DETACH_SESSION"; + } + + bt_common_abort(); +} + enum lttng_viewer_attach_return_code { LTTNG_VIEWER_ATTACH_OK = 1, /* The attach command succeeded. */ @@ -66,6 +102,31 @@ enum lttng_viewer_next_index_return_code LTTNG_VIEWER_INDEX_EOF = 6, /* End of index file. */ }; +inline const char *format_as(const lttng_viewer_next_index_return_code code) noexcept +{ + switch (code) { + case LTTNG_VIEWER_INDEX_OK: + return "INDEX_OK"; + + case LTTNG_VIEWER_INDEX_RETRY: + return "INDEX_RETRY"; + + case LTTNG_VIEWER_INDEX_HUP: + return "INDEX_HUP"; + + case LTTNG_VIEWER_INDEX_ERR: + return "INDEX_ERR"; + + case LTTNG_VIEWER_INDEX_INACTIVE: + return "INDEX_INACTIVE"; + + case LTTNG_VIEWER_INDEX_EOF: + return "INDEX_EOF"; + } + + bt_common_abort(); +} + enum lttng_viewer_get_packet_return_code { LTTNG_VIEWER_GET_PACKET_OK = 1, @@ -74,6 +135,25 @@ enum lttng_viewer_get_packet_return_code LTTNG_VIEWER_GET_PACKET_EOF = 4, }; +inline const char *format_as(const lttng_viewer_get_packet_return_code code) noexcept +{ + switch (code) { + case LTTNG_VIEWER_GET_PACKET_OK: + return "GET_PACKET_OK"; + + case LTTNG_VIEWER_GET_PACKET_RETRY: + return "GET_PACKET_RETRY"; + + case LTTNG_VIEWER_GET_PACKET_ERR: + return "GET_PACKET_ERR"; + + case LTTNG_VIEWER_GET_PACKET_EOF: + return "GET_PACKET_EOF"; + } + + bt_common_abort(); +}; + enum lttng_viewer_get_metadata_return_code { LTTNG_VIEWER_METADATA_OK = 1, @@ -95,6 +175,19 @@ enum lttng_viewer_seek LTTNG_VIEWER_SEEK_LAST = 2, }; +inline const char *format_as(const lttng_viewer_seek seek) noexcept +{ + switch (seek) { + case LTTNG_VIEWER_SEEK_BEGINNING: + return "SEEK_BEGINNING"; + + case LTTNG_VIEWER_SEEK_LAST: + return "SEEK_LAST"; + } + + bt_common_abort(); +} + enum lttng_viewer_new_streams_return_code { LTTNG_VIEWER_NEW_STREAMS_OK = 1, /* If new streams are being sent. */ diff --git a/src/plugins/ctf/lttng-live/metadata.cpp b/src/plugins/ctf/lttng-live/metadata.cpp index 4cc750b8..6aaa7beb 100644 --- a/src/plugins/ctf/lttng-live/metadata.cpp +++ b/src/plugins/ctf/lttng-live/metadata.cpp @@ -6,18 +6,6 @@ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation */ -#include -#include -#include -#include - -#include - -#define BT_COMP_LOG_SELF_COMP self_comp -#define BT_LOG_OUTPUT_LEVEL log_level -#define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/META" -#include "logging/comp-logging.h" - #include "compat/memstream.h" #include "../common/src/metadata/tsdl/ctf-meta-configure-ir-trace.hpp" @@ -42,8 +30,7 @@ struct packet_header } __attribute__((__packed__)); static bool stream_classes_all_have_default_clock_class(bt_trace_class *tc, - bt_logging_level log_level, - bt_self_component *self_comp) + const bt2c::Logger& logger) { uint64_t i, sc_count; const bt_clock_class *cc = NULL; @@ -59,10 +46,10 @@ static bool stream_classes_all_have_default_clock_class(bt_trace_class *tc, cc = bt_stream_class_borrow_default_clock_class_const(sc); if (!cc) { ret = false; - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Stream class doesn't have a default clock class: " - "sc-id=%" PRIu64 ", sc-name=\"%s\"", - bt_stream_class_get_id(sc), bt_stream_class_get_name(sc)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, + "Stream class doesn't have a default clock class: " + "sc-id={}, sc-name=\"{}\"", + bt_stream_class_get_id(sc), bt_stream_class_get_name(sc)); goto end; } } @@ -106,12 +93,10 @@ enum lttng_live_iterator_status lttng_live_metadata_update(struct lttng_live_tra FILE *fp = NULL; enum ctf_metadata_decoder_status decoder_status; enum lttng_live_iterator_status status = LTTNG_LIVE_ITERATOR_STATUS_OK; - bt_logging_level log_level = trace->log_level; - bt_self_component *self_comp = trace->self_comp; enum lttng_live_get_one_metadata_status metadata_status; - BT_COMP_LOGD("Updating metadata for trace: session-id=%" PRIu64 ", trace-id=%" PRIu64, - session->id, trace->id); + BT_CPPLOGD_SPEC(metadata->logger, "Updating metadata for trace: session-id={}, trace-id={}", + session->id, trace->id); /* No metadata stream yet. */ if (!metadata) { @@ -145,7 +130,7 @@ enum lttng_live_iterator_status lttng_live_metadata_update(struct lttng_live_tra session->lttng_live_msg_iter->was_interrupted = true; status = LTTNG_LIVE_ITERATOR_STATUS_AGAIN; } else { - BT_COMP_LOGE_APPEND_CAUSE_ERRNO(self_comp, "Metadata open_memstream", "."); + BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(metadata->logger, "Metadata open_memstream", "."); status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; } goto end; @@ -177,9 +162,11 @@ enum lttng_live_iterator_status lttng_live_metadata_update(struct lttng_live_tra keep_receiving = false; break; case LTTNG_LIVE_GET_ONE_METADATA_STATUS_CLOSED: - BT_COMP_LOGD("Metadata stream was closed by the Relay, the trace is no longer active: " - "trace-id=%" PRIu64 ", metadata-stream-id=%" PRIu64, - trace->id, metadata->stream_id); + BT_CPPLOGD_SPEC( + metadata->logger, + "Metadata stream was closed by the Relay, the trace is no longer active: " + "trace-id={}, metadata-stream-id={}", + trace->id, metadata->stream_id); /* * The stream was closed and we received everything * there was to receive for this metadata stream. @@ -190,10 +177,9 @@ enum lttng_live_iterator_status lttng_live_metadata_update(struct lttng_live_tra trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_CLOSED; break; case LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Error getting one trace metadata packet: " - "trace-id=%" PRIu64, - trace->id); + BT_CPPLOGE_APPEND_CAUSE_SPEC(metadata->logger, + "Error getting one trace metadata packet: trace-id={}", + trace->id); goto error; default: bt_common_abort(); @@ -202,7 +188,7 @@ enum lttng_live_iterator_status lttng_live_metadata_update(struct lttng_live_tra /* The memory buffer `metadata_buf` contains all the metadata. */ if (bt_close_memstream(&metadata_buf, &size, fp)) { - BT_COMP_LOGW_ERRNO("Metadata bt_close_memstream", "."); + BT_CPPLOGW_ERRNO_SPEC(metadata->logger, "Metadata bt_close_memstream", "."); } fp = NULL; @@ -228,7 +214,8 @@ enum lttng_live_iterator_status lttng_live_metadata_update(struct lttng_live_tra session->lttng_live_msg_iter->was_interrupted = true; status = LTTNG_LIVE_ITERATOR_STATUS_AGAIN; } else { - BT_COMP_LOGE_APPEND_CAUSE_ERRNO(self_comp, "Cannot memory-open metadata buffer", "."); + BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(metadata->logger, + "Cannot memory-open metadata buffer", "."); status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; } goto end; @@ -238,7 +225,7 @@ enum lttng_live_iterator_status lttng_live_metadata_update(struct lttng_live_tra * The call to ctf_metadata_decoder_append_content() will append * new metadata to our current trace class. */ - BT_COMP_LOGD("Appending new metadata to the ctf_trace class"); + BT_CPPLOGD_SPEC(metadata->logger, "Appending new metadata to the ctf_trace class"); decoder_status = ctf_metadata_decoder_append_content(metadata->decoder, fp); switch (decoder_status) { case CTF_METADATA_DECODER_STATUS_OK: @@ -249,15 +236,16 @@ enum lttng_live_iterator_status lttng_live_metadata_update(struct lttng_live_tra trace->trace_class = ctf_metadata_decoder_get_ir_trace_class(metadata->decoder); trace->trace = bt_trace_create(trace->trace_class); if (!trace->trace) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create bt_trace"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(metadata->logger, "Failed to create bt_trace"); goto error; } if (ctf_trace_class_configure_ir_trace(tc, trace->trace)) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to configure ctf trace class"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(metadata->logger, + "Failed to configure ctf trace class"); goto error; } - if (!stream_classes_all_have_default_clock_class(trace->trace_class, log_level, - self_comp)) { + if (!stream_classes_all_have_default_clock_class(trace->trace_class, + metadata->logger)) { /* Error logged in function. */ goto error; } @@ -282,7 +270,7 @@ end: closeret = fclose(fp); if (closeret) { - BT_COMP_LOGW_ERRNO("Error on fclose", "."); + BT_CPPLOGW_ERRNO_SPEC(metadata->logger, "Error on fclose", "."); } } free(metadata_buf); @@ -292,30 +280,25 @@ end: int lttng_live_metadata_create_stream(struct lttng_live_session *session, uint64_t ctf_trace_id, uint64_t stream_id) { - bt_self_component *self_comp = session->self_comp; - bt_logging_level log_level = session->log_level; struct lttng_live_trace *trace; - ctf_metadata_decoder_config cfg; - cfg.log_level = session->log_level; + ctf_metadata_decoder_config cfg {session->logger}; cfg.self_comp = session->self_comp; cfg.clock_class_offset_s = 0; cfg.clock_class_offset_ns = 0; cfg.create_trace_class = true; - lttng_live_metadata *metadata = new lttng_live_metadata; - metadata->log_level = session->log_level; - metadata->self_comp = session->self_comp; + lttng_live_metadata *metadata = new lttng_live_metadata {session->logger}; metadata->stream_id = stream_id; metadata->decoder = ctf_metadata_decoder_create(&cfg); if (!metadata->decoder) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create CTF metadata decoder"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(session->logger, "Failed to create CTF metadata decoder"); goto error; } trace = lttng_live_session_borrow_or_create_trace_by_id(session, ctf_trace_id); if (!trace) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to borrow trace"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(session->logger, "Failed to borrow trace"); goto error; } trace->metadata = metadata; diff --git a/src/plugins/ctf/lttng-live/viewer-connection.cpp b/src/plugins/ctf/lttng-live/viewer-connection.cpp index 61b8a8cf..a92a2eac 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.cpp +++ b/src/plugins/ctf/lttng-live/viewer-connection.cpp @@ -11,11 +11,6 @@ #include -#define BT_COMP_LOG_SELF_COMP (viewer_connection->self_comp) -#define BT_LOG_OUTPUT_LEVEL ((enum bt_log_level) viewer_connection->log_level) -#define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER" -#include "logging/comp-logging.h" - #include "common/common.h" #include "compat/endian.h" /* IWYU pragma: keep */ @@ -25,119 +20,32 @@ #include "metadata.hpp" #include "viewer-connection.hpp" -#define viewer_handle_send_recv_status(_self_comp, _self_comp_class, _status, _action, _msg_str) \ +#define viewer_handle_send_recv_status(_status, _action, _msg_str) \ do { \ switch (_status) { \ case LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED: \ break; \ case LTTNG_LIVE_VIEWER_STATUS_ERROR: \ - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(_self_comp, _self_comp_class, \ - "Error " _action " " _msg_str); \ + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, \ + "Error " _action " " _msg_str); \ break; \ default: \ bt_common_abort(); \ } \ } while (0) -#define viewer_handle_send_status(_self_comp, _self_comp_class, _status, _msg_str) \ - viewer_handle_send_recv_status(_self_comp, _self_comp_class, _status, "sending", _msg_str) +#define viewer_handle_send_status(_status, _msg_str) \ + viewer_handle_send_recv_status(_status, "sending", _msg_str) -#define viewer_handle_recv_status(_self_comp, _self_comp_class, _status, _msg_str) \ - viewer_handle_send_recv_status(_self_comp, _self_comp_class, _status, "receiving", _msg_str) +#define viewer_handle_recv_status(_status, _msg_str) \ + viewer_handle_send_recv_status(_status, "receiving", _msg_str) -#define LTTNG_LIVE_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(_self_comp, _self_comp_class, _msg, \ - _fmt, ...) \ +#define LTTNG_LIVE_CPPLOGE_APPEND_CAUSE_ERRNO(_msg, _fmt, ...) \ do { \ - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(_self_comp, _self_comp_class, _msg ": %s" _fmt, \ - bt_socket_errormsg(), ##__VA_ARGS__); \ + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, _msg ": {}" _fmt, \ + bt_socket_errormsg(), ##__VA_ARGS__); \ } while (0) -static const char *lttng_viewer_command_string(enum lttng_viewer_command cmd) -{ - switch (cmd) { - case LTTNG_VIEWER_CONNECT: - return "CONNECT"; - case LTTNG_VIEWER_LIST_SESSIONS: - return "LIST_SESSIONS"; - case LTTNG_VIEWER_ATTACH_SESSION: - return "ATTACH_SESSION"; - case LTTNG_VIEWER_GET_NEXT_INDEX: - return "GET_NEXT_INDEX"; - case LTTNG_VIEWER_GET_PACKET: - return "GET_PACKET"; - case LTTNG_VIEWER_GET_METADATA: - return "GET_METADATA"; - case LTTNG_VIEWER_GET_NEW_STREAMS: - return "GET_NEW_STREAMS"; - case LTTNG_VIEWER_CREATE_SESSION: - return "CREATE_SESSION"; - case LTTNG_VIEWER_DETACH_SESSION: - return "DETACH_SESSION"; - } - - bt_common_abort(); -} - -static const char * -lttng_viewer_next_index_return_code_string(enum lttng_viewer_next_index_return_code code) -{ - switch (code) { - case LTTNG_VIEWER_INDEX_OK: - return "INDEX_OK"; - case LTTNG_VIEWER_INDEX_RETRY: - return "INDEX_RETRY"; - case LTTNG_VIEWER_INDEX_HUP: - return "INDEX_HUP"; - case LTTNG_VIEWER_INDEX_ERR: - return "INDEX_ERR"; - case LTTNG_VIEWER_INDEX_INACTIVE: - return "INDEX_INACTIVE"; - case LTTNG_VIEWER_INDEX_EOF: - return "INDEX_EOF"; - } - - bt_common_abort(); -} - -static const char *lttng_viewer_next_index_return_code_string(uint32_t code) -{ - return lttng_viewer_next_index_return_code_string((lttng_viewer_next_index_return_code) code); -} - -static const char * -lttng_viewer_get_packet_return_code_string(enum lttng_viewer_get_packet_return_code code) -{ - switch (code) { - case LTTNG_VIEWER_GET_PACKET_OK: - return "GET_PACKET_OK"; - case LTTNG_VIEWER_GET_PACKET_RETRY: - return "GET_PACKET_RETRY"; - case LTTNG_VIEWER_GET_PACKET_ERR: - return "GET_PACKET_ERR"; - case LTTNG_VIEWER_GET_PACKET_EOF: - return "GET_PACKET_EOF"; - } - - bt_common_abort(); -}; - -static const char *lttng_viewer_get_packet_return_code_string(uint32_t code) -{ - return lttng_viewer_get_packet_return_code_string((lttng_viewer_get_packet_return_code) code); -} - -static const char *lttng_viewer_seek_string(enum lttng_viewer_seek seek) -{ - switch (seek) { - case LTTNG_VIEWER_SEEK_BEGINNING: - return "SEEK_BEGINNING"; - case LTTNG_VIEWER_SEEK_LAST: - return "SEEK_LAST"; - } - - bt_common_abort(); -} - static inline enum lttng_live_iterator_status viewer_status_to_live_iterator_status(enum lttng_live_viewer_status viewer_status) { @@ -170,12 +78,10 @@ viewer_status_to_ctf_msg_iter_medium_status(enum lttng_live_viewer_status viewer static inline void viewer_connection_close_socket(struct live_viewer_connection *viewer_connection) { - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; - bt_self_component *self_comp = viewer_connection->self_comp; int ret = bt_socket_close(viewer_connection->control_sock); if (ret == -1) { - BT_COMP_OR_COMP_CLASS_LOGW_ERRNO(self_comp, self_comp_class, - "Error closing viewer connection socket: ", "."); + BT_CPPLOGW_ERRNO_SPEC(viewer_connection->logger, + "Error closing viewer connection socket: ", "."); } viewer_connection->control_sock = BT_INVALID_SOCKET; @@ -191,8 +97,6 @@ static enum lttng_live_viewer_status lttng_live_recv(struct live_viewer_connection *viewer_connection, void *buf, size_t len) { ssize_t received; - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; - bt_self_component *self_comp = viewer_connection->self_comp; size_t total_received = 0, to_receive = len; struct lttng_live_msg_iter *lttng_live_msg_iter = viewer_connection->lttng_live_msg_iter; enum lttng_live_viewer_status status; @@ -226,8 +130,7 @@ lttng_live_recv(struct live_viewer_connection *viewer_connection, void *buf, siz * For any other types of socket error, close * the socket and return an error. */ - LTTNG_LIVE_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO( - self_comp, self_comp_class, "Error receiving from Relay", "."); + LTTNG_LIVE_CPPLOGE_APPEND_CAUSE_ERRNO("Error receiving from Relay", "."); viewer_connection_close_socket(viewer_connection); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; @@ -241,8 +144,8 @@ lttng_live_recv(struct live_viewer_connection *viewer_connection, void *buf, siz * a message from it, it means something when wrong. * Close the socket and return an error. */ - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Remote side has closed connection"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Remote side has closed connection"); viewer_connection_close_socket(viewer_connection); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; @@ -271,8 +174,6 @@ static enum lttng_live_viewer_status lttng_live_send(struct live_viewer_connection *viewer_connection, const void *buf, size_t len) { enum lttng_live_viewer_status status; - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; - bt_self_component *self_comp = viewer_connection->self_comp; struct lttng_live_msg_iter *lttng_live_msg_iter = viewer_connection->lttng_live_msg_iter; BT_SOCKET sock = viewer_connection->control_sock; size_t to_send = len; @@ -302,8 +203,7 @@ lttng_live_send(struct live_viewer_connection *viewer_connection, const void *bu * For any other types of socket error, close * the socket and return an error. */ - LTTNG_LIVE_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO( - self_comp, self_comp_class, "Error sending to Relay", "."); + LTTNG_LIVE_CPPLOGE_APPEND_CAUSE_ERRNO("Error sending to Relay", "."); viewer_connection_close_socket(viewer_connection); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; @@ -327,8 +227,6 @@ end: static int parse_url(struct live_viewer_connection *viewer_connection) { char error_buf[256] = {0}; - bt_self_component *self_comp = viewer_connection->self_comp; - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; struct bt_common_lttng_live_url_parts lttng_live_url_parts = {}; int ret = -1; const char *path = viewer_connection->url->str; @@ -339,8 +237,8 @@ static int parse_url(struct live_viewer_connection *viewer_connection) lttng_live_url_parts = bt_common_parse_lttng_live_url(path, error_buf, sizeof(error_buf)); if (!lttng_live_url_parts.proto) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Invalid LTTng live URL format: %s", error_buf); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Invalid LTTng live URL format: {}", + error_buf); goto end; } viewer_connection->proto = lttng_live_url_parts.proto; @@ -376,15 +274,12 @@ lttng_live_handshake(struct live_viewer_connection *viewer_connection) struct lttng_viewer_cmd cmd; struct lttng_viewer_connect connect; enum lttng_live_viewer_status status; - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; - bt_self_component *self_comp = viewer_connection->self_comp; const size_t cmd_buf_len = sizeof(cmd) + sizeof(connect); char cmd_buf[cmd_buf_len]; - BT_COMP_OR_COMP_CLASS_LOGD( - self_comp, self_comp_class, - "Handshaking with the relay daemon: cmd=%s, major-version=%u, minor-version=%u", - lttng_viewer_command_string(LTTNG_VIEWER_CONNECT), LTTNG_LIVE_MAJOR, LTTNG_LIVE_MINOR); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Handshaking with the relay daemon: cmd={}, major-version={}, minor-version={}", + LTTNG_VIEWER_CONNECT, LTTNG_LIVE_MAJOR, LTTNG_LIVE_MINOR); cmd.cmd = htobe32(LTTNG_VIEWER_CONNECT); cmd.data_size = htobe64((uint64_t) sizeof(connect)); @@ -405,24 +300,24 @@ lttng_live_handshake(struct live_viewer_connection *viewer_connection) status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_send_status(self_comp, self_comp_class, status, "viewer connect command"); + viewer_handle_send_status(status, "viewer connect command"); goto end; } status = lttng_live_recv(viewer_connection, &connect, sizeof(connect)); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, self_comp_class, status, "viewer connect reply"); + viewer_handle_recv_status(status, "viewer connect reply"); goto end; } - BT_COMP_OR_COMP_CLASS_LOGI(self_comp, self_comp_class, "Received viewer session ID : %" PRIu64, - (uint64_t) be64toh(connect.viewer_session_id)); - BT_COMP_OR_COMP_CLASS_LOGI(self_comp, self_comp_class, "Relayd version : %u.%u", - be32toh(connect.major), be32toh(connect.minor)); + BT_CPPLOGI_SPEC(viewer_connection->logger, "Received viewer session ID : {}", + (uint64_t) be64toh(connect.viewer_session_id)); + BT_CPPLOGI_SPEC(viewer_connection->logger, "Relayd version : {}.{}", be32toh(connect.major), + be32toh(connect.minor)); if (LTTNG_LIVE_MAJOR != be32toh(connect.major)) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Incompatible lttng-relayd protocol"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Incompatible lttng-relayd protocol"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; } @@ -448,19 +343,16 @@ lttng_live_connect_viewer(struct live_viewer_connection *viewer_connection) struct hostent *host; struct sockaddr_in server_addr; enum lttng_live_viewer_status status; - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; - bt_self_component *self_comp = viewer_connection->self_comp; if (parse_url(viewer_connection)) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, "Failed to parse URL"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Failed to parse URL"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto error; } - BT_COMP_OR_COMP_CLASS_LOGD( - self_comp, self_comp_class, - "Connecting to hostname : %s, port : %d, " - "target hostname : %s, session name : %s, proto : %s", + BT_CPPLOGD_SPEC( + viewer_connection->logger, + "Connecting to hostname : {}, port : {}, target hostname : {}, session name : {}, proto : {}", viewer_connection->relay_hostname->str, viewer_connection->port, !viewer_connection->target_hostname ? "" : viewer_connection->target_hostname->str, !viewer_connection->session_name ? "" : viewer_connection->session_name->str, @@ -468,16 +360,16 @@ lttng_live_connect_viewer(struct live_viewer_connection *viewer_connection) host = gethostbyname(viewer_connection->relay_hostname->str); if (!host) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Cannot lookup hostname: hostname=\"%s\"", - viewer_connection->relay_hostname->str); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Cannot lookup hostname: hostname=\"{}\"", + viewer_connection->relay_hostname->str); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto error; } if ((viewer_connection->control_sock = socket(AF_INET, SOCK_STREAM, 0)) == BT_INVALID_SOCKET) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Socket creation failed: %s", bt_socket_errormsg()); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Socket creation failed: {}", + bt_socket_errormsg()); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto error; } @@ -489,8 +381,8 @@ lttng_live_connect_viewer(struct live_viewer_connection *viewer_connection) if (connect(viewer_connection->control_sock, (struct sockaddr *) &server_addr, sizeof(struct sockaddr)) == BT_SOCKET_ERROR) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, "Connection failed: %s", - bt_socket_errormsg()); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Connection failed: {}", + bt_socket_errormsg()); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto error; } @@ -502,8 +394,7 @@ lttng_live_connect_viewer(struct live_viewer_connection *viewer_connection) * interruption. */ if (status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Viewer handshake failed"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Viewer handshake failed"); goto error; } else if (status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { goto end; @@ -514,8 +405,8 @@ lttng_live_connect_viewer(struct live_viewer_connection *viewer_connection) error: if (viewer_connection->control_sock != BT_INVALID_SOCKET) { if (bt_socket_close(viewer_connection->control_sock) == BT_SOCKET_ERROR) { - BT_COMP_OR_COMP_CLASS_LOGW(self_comp, self_comp_class, "Error closing socket: %s.", - bt_socket_errormsg()); + BT_CPPLOGW_SPEC(viewer_connection->logger, "Error closing socket: {}.", + bt_socket_errormsg()); } } viewer_connection->control_sock = BT_INVALID_SOCKET; @@ -525,15 +416,12 @@ end: static void lttng_live_disconnect_viewer(struct live_viewer_connection *viewer_connection) { - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; - bt_self_component *self_comp = viewer_connection->self_comp; - if (viewer_connection->control_sock == BT_INVALID_SOCKET) { return; } if (bt_socket_close(viewer_connection->control_sock) == BT_SOCKET_ERROR) { - BT_COMP_OR_COMP_CLASS_LOGW(self_comp, self_comp_class, "Error closing socket: %s", - bt_socket_errormsg()); + BT_CPPLOGW_SPEC(viewer_connection->logger, "Error closing socket: {}", + bt_socket_errormsg()); viewer_connection->control_sock = BT_INVALID_SOCKET; } } @@ -541,8 +429,6 @@ static void lttng_live_disconnect_viewer(struct live_viewer_connection *viewer_c static int list_update_session(bt_value *results, const struct lttng_viewer_session *session, bool *_found, struct live_viewer_connection *viewer_connection) { - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; - bt_self_component *self_comp = viewer_connection->self_comp; int ret = 0; uint64_t i, len; bt_value *map = NULL; @@ -559,15 +445,15 @@ static int list_update_session(bt_value *results, const struct lttng_viewer_sess map = bt_value_array_borrow_element_by_index(results, i); hostname = bt_value_map_borrow_entry_value(map, "target-hostname"); if (!hostname) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Error borrowing \"target-hostname\" entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error borrowing \"target-hostname\" entry."); ret = -1; goto end; } session_name = bt_value_map_borrow_entry_value(map, "session-name"); if (!session_name) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Error borrowing \"session-name\" entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error borrowing \"session-name\" entry."); ret = -1; goto end; } @@ -584,8 +470,8 @@ static int list_update_session(bt_value *results, const struct lttng_viewer_sess btval = bt_value_map_borrow_entry_value(map, "stream-count"); if (!btval) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Error borrowing \"stream-count\" entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error borrowing \"stream-count\" entry."); ret = -1; goto end; } @@ -596,8 +482,8 @@ static int list_update_session(bt_value *results, const struct lttng_viewer_sess btval = bt_value_map_borrow_entry_value(map, "client-count"); if (!btval) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Error borrowing \"client-count\" entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error borrowing \"client-count\" entry."); ret = -1; goto end; } @@ -621,7 +507,6 @@ static int list_append_session(bt_value *results, GString *base_url, struct live_viewer_connection *viewer_connection) { int ret = 0; - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; bt_value_map_insert_entry_status insert_status; bt_value_array_append_element_status append_status; bt_value *map = NULL; @@ -639,13 +524,14 @@ static int list_append_session(bt_value *results, GString *base_url, map = bt_value_map_create(); if (!map) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error creating map value."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error creating map value."); ret = -1; goto end; } if (base_url->len < 1) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error: base_url length smaller than 1."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error: base_url length smaller than 1."); ret = -1; goto end; } @@ -661,7 +547,7 @@ static int list_append_session(bt_value *results, GString *base_url, insert_status = bt_value_map_insert_string_entry(map, "url", url->str); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error inserting \"url\" entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error inserting \"url\" entry."); ret = -1; goto end; } @@ -672,8 +558,8 @@ static int list_append_session(bt_value *results, GString *base_url, */ insert_status = bt_value_map_insert_string_entry(map, "target-hostname", session->hostname); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, - "Error inserting \"target-hostname\" entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error inserting \"target-hostname\" entry."); ret = -1; goto end; } @@ -684,7 +570,8 @@ static int list_append_session(bt_value *results, GString *base_url, */ insert_status = bt_value_map_insert_string_entry(map, "session-name", session->session_name); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error inserting \"session-name\" entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error inserting \"session-name\" entry."); ret = -1; goto end; } @@ -698,7 +585,8 @@ static int list_append_session(bt_value *results, GString *base_url, insert_status = bt_value_map_insert_unsigned_integer_entry(map, "timer-us", live_timer); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error inserting \"timer-us\" entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error inserting \"timer-us\" entry."); ret = -1; goto end; } @@ -713,8 +601,8 @@ static int list_append_session(bt_value *results, GString *base_url, insert_status = bt_value_map_insert_unsigned_integer_entry(map, "stream-count", streams); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, - "Error inserting \"stream-count\" entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error inserting \"stream-count\" entry."); ret = -1; goto end; } @@ -729,8 +617,8 @@ static int list_append_session(bt_value *results, GString *base_url, insert_status = bt_value_map_insert_unsigned_integer_entry(map, "client-count", clients); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, - "Error inserting \"client-count\" entry."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error inserting \"client-count\" entry."); ret = -1; goto end; } @@ -738,7 +626,7 @@ static int list_append_session(bt_value *results, GString *base_url, append_status = bt_value_array_append_element(results, map); if (append_status != BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error appending map to results."); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error appending map to results."); ret = -1; } @@ -790,7 +678,6 @@ bt_component_class_query_method_status live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_connection, const bt_value **user_result) { - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK; bt_value *result = NULL; enum lttng_live_viewer_status viewer_status; @@ -800,13 +687,13 @@ live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_conne result = bt_value_array_create(); if (!result) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error creating array"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error creating array"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR; goto error; } - BT_LOGD("Requesting list of sessions: cmd=%s", - lttng_viewer_command_string(LTTNG_VIEWER_LIST_SESSIONS)); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Requesting list of sessions: cmd={}", + LTTNG_VIEWER_LIST_SESSIONS); cmd.cmd = htobe32(LTTNG_VIEWER_LIST_SESSIONS); cmd.data_size = htobe64((uint64_t) 0); @@ -814,7 +701,8 @@ live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_conne viewer_status = lttng_live_send(viewer_connection, &cmd, sizeof(cmd)); if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error sending list sessions command"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error sending list sessions command"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { @@ -824,7 +712,7 @@ live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_conne viewer_status = lttng_live_recv(viewer_connection, &list, sizeof(list)); if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error receiving session list"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error receiving session list"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { @@ -838,7 +726,7 @@ live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_conne viewer_status = lttng_live_recv(viewer_connection, &lsession, sizeof(lsession)); if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error receiving session:"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error receiving session:"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } else if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { @@ -849,7 +737,7 @@ live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_conne lsession.hostname[LTTNG_VIEWER_HOST_NAME_MAX - 1] = '\0'; lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0'; if (list_append_session(result, viewer_connection->url, &lsession, viewer_connection)) { - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Error appending session"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error appending session"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } @@ -873,11 +761,10 @@ lttng_live_query_session_ids(struct lttng_live_msg_iter *lttng_live_msg_iter) uint64_t session_id; enum lttng_live_viewer_status status; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; - bt_self_component *self_comp = viewer_connection->self_comp; - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; - BT_COMP_LOGD("Asking the relay daemon for the list of sessions: cmd=%s", - lttng_viewer_command_string(LTTNG_VIEWER_LIST_SESSIONS)); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Asking the relay daemon for the list of sessions: cmd={}", + LTTNG_VIEWER_LIST_SESSIONS); cmd.cmd = htobe32(LTTNG_VIEWER_LIST_SESSIONS); cmd.data_size = htobe64((uint64_t) 0); @@ -885,13 +772,13 @@ lttng_live_query_session_ids(struct lttng_live_msg_iter *lttng_live_msg_iter) status = lttng_live_send(viewer_connection, &cmd, sizeof(cmd)); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_send_status(self_comp, self_comp_class, status, "list sessions command"); + viewer_handle_send_status(status, "list sessions command"); goto end; } status = lttng_live_recv(viewer_connection, &list, sizeof(list)); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, self_comp_class, status, "session list reply"); + viewer_handle_recv_status(status, "session list reply"); goto end; } @@ -899,16 +786,17 @@ lttng_live_query_session_ids(struct lttng_live_msg_iter *lttng_live_msg_iter) for (i = 0; i < sessions_count; i++) { status = lttng_live_recv(viewer_connection, &lsession, sizeof(lsession)); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, self_comp_class, status, "session reply"); + viewer_handle_recv_status(status, "session reply"); goto end; } lsession.hostname[LTTNG_VIEWER_HOST_NAME_MAX - 1] = '\0'; lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0'; session_id = be64toh(lsession.id); - BT_COMP_LOGI("Adding session to internal list: " - "session-id=%" PRIu64 ", hostname=\"%s\", session-name=\"%s\"", - session_id, lsession.hostname, lsession.session_name); + BT_CPPLOGI_SPEC(viewer_connection->logger, + "Adding session to internal list: " + "session-id={}, hostname=\"{}\", session-name=\"{}\"", + session_id, lsession.hostname, lsession.session_name); if ((strncmp(lsession.session_name, viewer_connection->session_name->str, LTTNG_VIEWER_NAME_MAX) == 0) && @@ -916,7 +804,8 @@ lttng_live_query_session_ids(struct lttng_live_msg_iter *lttng_live_msg_iter) LTTNG_VIEWER_HOST_NAME_MAX) == 0)) { if (lttng_live_add_session(lttng_live_msg_iter, session_id, lsession.hostname, lsession.session_name)) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to add live session"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Failed to add live session"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; } @@ -936,11 +825,9 @@ lttng_live_create_viewer_session(struct lttng_live_msg_iter *lttng_live_msg_iter struct lttng_viewer_create_session_response resp; enum lttng_live_viewer_status status; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; - bt_self_component *self_comp = viewer_connection->self_comp; - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; - BT_COMP_OR_COMP_CLASS_LOGD(self_comp, self_comp_class, "Creating a viewer session: cmd=%s", - lttng_viewer_command_string(LTTNG_VIEWER_CREATE_SESSION)); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Creating a viewer session: cmd={}", + LTTNG_VIEWER_CREATE_SESSION); cmd.cmd = htobe32(LTTNG_VIEWER_CREATE_SESSION); cmd.data_size = htobe64((uint64_t) 0); @@ -948,25 +835,26 @@ lttng_live_create_viewer_session(struct lttng_live_msg_iter *lttng_live_msg_iter status = lttng_live_send(viewer_connection, &cmd, sizeof(cmd)); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_send_status(self_comp, self_comp_class, status, "create session command"); + viewer_handle_send_status(status, "create session command"); goto end; } status = lttng_live_recv(viewer_connection, &resp, sizeof(resp)); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, self_comp_class, status, "create session reply"); + viewer_handle_recv_status(status, "create session reply"); goto end; } if (be32toh(resp.status) != LTTNG_VIEWER_CREATE_SESSION_OK) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error creating viewer session"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error creating viewer session"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; } status = lttng_live_query_session_ids(lttng_live_msg_iter); if (status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to query live viewer session ids"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Failed to query live viewer session ids"); goto end; } else if (status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { goto end; @@ -984,9 +872,8 @@ static enum lttng_live_viewer_status receive_streams(struct lttng_live_session * struct lttng_live_msg_iter *lttng_live_msg_iter = session->lttng_live_msg_iter; enum lttng_live_viewer_status status; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; - bt_self_component *self_comp = viewer_connection->self_comp; - BT_COMP_LOGI("Getting %" PRIu32 " new streams", stream_count); + BT_CPPLOGI_SPEC(viewer_connection->logger, "Getting {} new streams", stream_count); for (i = 0; i < stream_count; i++) { struct lttng_viewer_stream stream; struct lttng_live_stream_iterator *live_stream; @@ -995,7 +882,7 @@ static enum lttng_live_viewer_status receive_streams(struct lttng_live_session * status = lttng_live_recv(viewer_connection, &stream, sizeof(stream)); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, NULL, status, "stream reply"); + viewer_handle_recv_status(status, "stream reply"); goto end; } stream.path_name[LTTNG_VIEWER_PATH_MAX - 1] = '\0'; @@ -1004,21 +891,22 @@ static enum lttng_live_viewer_status receive_streams(struct lttng_live_session * ctf_trace_id = be64toh(stream.ctf_trace_id); if (stream.metadata_flag) { - BT_COMP_LOGI(" metadata stream %" PRIu64 " : %s/%s", stream_id, stream.path_name, - stream.channel_name); + BT_CPPLOGI_SPEC(viewer_connection->logger, " metadata stream {} : {}/{}", stream_id, + stream.path_name, stream.channel_name); if (lttng_live_metadata_create_stream(session, ctf_trace_id, stream_id)) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error creating metadata stream"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Error creating metadata stream"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; } session->lazy_stream_msg_init = true; } else { - BT_COMP_LOGI(" stream %" PRIu64 " : %s/%s", stream_id, stream.path_name, - stream.channel_name); + BT_CPPLOGI_SPEC(viewer_connection->logger, " stream {} : {}/{}", stream_id, + stream.path_name, stream.channel_name); live_stream = lttng_live_stream_iterator_create(session, ctf_trace_id, stream_id, self_msg_iter); if (!live_stream) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error creating stream"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error creating stream"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; } @@ -1039,15 +927,14 @@ enum lttng_live_viewer_status lttng_live_session_attach(struct lttng_live_sessio struct lttng_viewer_attach_session_response rp; struct lttng_live_msg_iter *lttng_live_msg_iter = session->lttng_live_msg_iter; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; - bt_self_component *self_comp = viewer_connection->self_comp; uint64_t session_id = session->id; uint32_t streams_count; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); char cmd_buf[cmd_buf_len]; - BT_COMP_LOGD("Attaching to session: cmd=%s, session-id=%" PRIu64 ", seek=%s", - lttng_viewer_command_string(LTTNG_VIEWER_ATTACH_SESSION), session_id, - lttng_viewer_seek_string(LTTNG_VIEWER_SEEK_LAST)); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Attaching to session: cmd={}, session-id={}, seek={}", + LTTNG_VIEWER_ATTACH_SESSION, session_id, LTTNG_VIEWER_SEEK_LAST); cmd.cmd = htobe32(LTTNG_VIEWER_ATTACH_SESSION); cmd.data_size = htobe64((uint64_t) sizeof(rq)); @@ -1068,13 +955,13 @@ enum lttng_live_viewer_status lttng_live_session_attach(struct lttng_live_sessio memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_send_status(self_comp, NULL, status, "attach session command"); + viewer_handle_send_status(status, "attach session command"); goto end; } status = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, NULL, status, "attach session reply"); + viewer_handle_recv_status(status, "attach session reply"); goto end; } @@ -1083,23 +970,26 @@ enum lttng_live_viewer_status lttng_live_session_attach(struct lttng_live_sessio case LTTNG_VIEWER_ATTACH_OK: break; case LTTNG_VIEWER_ATTACH_UNK: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Session id %" PRIu64 " is unknown", session_id); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Session id {} is unknown", + session_id); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; case LTTNG_VIEWER_ATTACH_ALREADY: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "There is already a viewer attached to this session"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "There is already a viewer attached to this session"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; case LTTNG_VIEWER_ATTACH_NOT_LIVE: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Not a live session"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Not a live session"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; case LTTNG_VIEWER_ATTACH_SEEK_ERR: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Wrong seek parameter"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Wrong seek parameter"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; default: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Unknown attach return code %u", be32toh(rp.status)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Unknown attach return code {}", + be32toh(rp.status)); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; } @@ -1112,7 +1002,7 @@ enum lttng_live_viewer_status lttng_live_session_attach(struct lttng_live_sessio case LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED: goto end; case LTTNG_LIVE_VIEWER_STATUS_ERROR: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error receiving streams"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Error receiving streams"); goto end; default: bt_common_abort(); @@ -1132,7 +1022,6 @@ enum lttng_live_viewer_status lttng_live_session_detach(struct lttng_live_sessio struct lttng_viewer_detach_session_request rq; struct lttng_viewer_detach_session_response rp; struct lttng_live_msg_iter *lttng_live_msg_iter = session->lttng_live_msg_iter; - bt_self_component *self_comp = session->self_comp; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; uint64_t session_id = session->id; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); @@ -1147,8 +1036,8 @@ enum lttng_live_viewer_status lttng_live_session_detach(struct lttng_live_sessio return LTTNG_LIVE_VIEWER_STATUS_OK; } - BT_COMP_LOGD("Detaching from session: cmd=%s, session-id=%" PRIu64, - lttng_viewer_command_string(LTTNG_VIEWER_DETACH_SESSION), session_id); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Detaching from session: cmd={}, session-id={}", + LTTNG_VIEWER_DETACH_SESSION, session_id); cmd.cmd = htobe32(LTTNG_VIEWER_DETACH_SESSION); cmd.data_size = htobe64((uint64_t) sizeof(rq)); @@ -1166,13 +1055,13 @@ enum lttng_live_viewer_status lttng_live_session_detach(struct lttng_live_sessio memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_send_status(self_comp, NULL, status, "detach session command"); + viewer_handle_send_status(status, "detach session command"); goto end; } status = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, NULL, status, "detach session reply"); + viewer_handle_recv_status(status, "detach session reply"); goto end; } @@ -1180,15 +1069,16 @@ enum lttng_live_viewer_status lttng_live_session_detach(struct lttng_live_sessio case LTTNG_VIEWER_DETACH_SESSION_OK: break; case LTTNG_VIEWER_DETACH_SESSION_UNK: - BT_COMP_LOGW("Session id %" PRIu64 " is unknown", session_id); + BT_CPPLOGW_SPEC(viewer_connection->logger, "Session id {} is unknown", session_id); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; case LTTNG_VIEWER_DETACH_SESSION_ERR: - BT_COMP_LOGW("Error detaching session id %" PRIu64 "", session_id); + BT_CPPLOGW_SPEC(viewer_connection->logger, "Error detaching session id {}", session_id); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; default: - BT_COMP_LOGE("Unknown detach return code %u", be32toh(rp.status)); + BT_CPPLOGE_SPEC(viewer_connection->logger, "Unknown detach return code {}", + be32toh(rp.status)); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; } @@ -1216,14 +1106,13 @@ lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, siz struct lttng_live_msg_iter *lttng_live_msg_iter = session->lttng_live_msg_iter; struct lttng_live_metadata *metadata = trace->metadata; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; - bt_self_component *self_comp = viewer_connection->self_comp; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); char cmd_buf[cmd_buf_len]; - BT_COMP_LOGD("Requesting new metadata for trace:" - "cmd=%s, trace-id=%" PRIu64 ", metadata-stream-id=%" PRIu64, - lttng_viewer_command_string(LTTNG_VIEWER_GET_METADATA), trace->id, - metadata->stream_id); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Requesting new metadata for trace:" + "cmd={}, trace-id={}, metadata-stream-id={}", + LTTNG_VIEWER_GET_METADATA, trace->id, metadata->stream_id); rq.stream_id = htobe64(metadata->stream_id); cmd.cmd = htobe32(LTTNG_VIEWER_GET_METADATA); @@ -1239,24 +1128,24 @@ lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, siz memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); viewer_status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_send_status(self_comp, NULL, viewer_status, "get metadata command"); + viewer_handle_send_status(viewer_status, "get metadata command"); status = (enum lttng_live_get_one_metadata_status) viewer_status; goto end; } viewer_status = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, NULL, viewer_status, "get metadata reply"); + viewer_handle_recv_status(viewer_status, "get metadata reply"); status = (enum lttng_live_get_one_metadata_status) viewer_status; goto end; } switch (be32toh(rp.status)) { case LTTNG_VIEWER_METADATA_OK: - BT_COMP_LOGD("Received get_metadata response: ok"); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Received get_metadata response: ok"); break; case LTTNG_VIEWER_NO_NEW_METADATA: - BT_COMP_LOGD("Received get_metadata response: no new"); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Received get_metadata response: no new"); status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_END; goto end; case LTTNG_VIEWER_METADATA_ERR: @@ -1265,11 +1154,12 @@ lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, siz * gone already. This can happen in short lived UST app * in a per-pid session. */ - BT_COMP_LOGD("Received get_metadata response: error"); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Received get_metadata response: error"); status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_CLOSED; goto end; default: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Received get_metadata response: unknown"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Received get_metadata response: unknown"); status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR; goto end; } @@ -1281,28 +1171,30 @@ lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, siz * length of 0. This means we must try again. This scenario * arises when a clear command is performed on an lttng session. */ - BT_COMP_LOGD( + BT_CPPLOGD_SPEC( + viewer_connection->logger, "Expecting a metadata packet of size 0. Retry to get a packet from the relay."); goto empty_metadata_packet_retry; } - BT_COMP_LOGD("Writing %" PRIu64 " bytes to metadata", len); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Writing {} bytes to metadata", len); if (len <= 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Erroneous response length"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Erroneous response length"); status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR; goto end; } data = g_new0(gchar, len); if (!data) { - BT_COMP_LOGE_APPEND_CAUSE_ERRNO(self_comp, "Failed to allocate data buffer", "."); + BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Failed to allocate data buffer", "."); status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR; goto end; } viewer_status = lttng_live_recv(viewer_connection, data, len); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, NULL, viewer_status, "get metadata packet"); + viewer_handle_recv_status(viewer_status, "get metadata packet"); status = (enum lttng_live_get_one_metadata_status) viewer_status; goto end; } @@ -1312,7 +1204,8 @@ lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, siz */ writelen = fwrite(data, sizeof(uint8_t), len, fp); if (writelen != len) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Writing in the metadata file stream"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Writing in the metadata file stream"); status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR; goto end; } @@ -1346,14 +1239,14 @@ static void lttng_index_to_packet_index(struct lttng_viewer_index *lindex, static void lttng_live_need_new_streams(struct lttng_live_msg_iter *lttng_live_msg_iter) { uint64_t session_idx; - struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; for (session_idx = 0; session_idx < lttng_live_msg_iter->sessions->len; session_idx++) { struct lttng_live_session *session = (lttng_live_session *) g_ptr_array_index(lttng_live_msg_iter->sessions, session_idx); - BT_COMP_LOGD("Marking session as needing new streams: " - "session-id=%" PRIu64, - session->id); + BT_CPPLOGD_SPEC(lttng_live_msg_iter->logger, + "Marking session as needing new streams: " + "session-id={}", + session->id); session->new_streams_needed = true; } } @@ -1368,16 +1261,15 @@ lttng_live_get_next_index(struct lttng_live_msg_iter *lttng_live_msg_iter, struct lttng_viewer_index rp; enum lttng_live_iterator_status status; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; - bt_self_component *self_comp = viewer_connection->self_comp; struct lttng_live_trace *trace = stream->trace; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); char cmd_buf[cmd_buf_len]; uint32_t flags, rp_status; - BT_COMP_LOGD("Requesting next index for stream: cmd=%s, " - "viewer-stream-id=%" PRIu64, - lttng_viewer_command_string(LTTNG_VIEWER_GET_NEXT_INDEX), - stream->viewer_stream_id); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Requesting next index for stream: cmd={}, " + "viewer-stream-id={}", + LTTNG_VIEWER_GET_NEXT_INDEX, stream->viewer_stream_id); cmd.cmd = htobe32(LTTNG_VIEWER_GET_NEXT_INDEX); cmd.data_size = htobe64((uint64_t) sizeof(rq)); cmd.cmd_version = htobe32(0); @@ -1395,27 +1287,28 @@ lttng_live_get_next_index(struct lttng_live_msg_iter *lttng_live_msg_iter, viewer_status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_send_status(self_comp, NULL, viewer_status, "get next index command"); + viewer_handle_send_status(viewer_status, "get next index command"); goto error; } viewer_status = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, NULL, viewer_status, "get next index reply"); + viewer_handle_recv_status(viewer_status, "get next index reply"); goto error; } flags = be32toh(rp.flags); rp_status = be32toh(rp.status); - BT_COMP_LOGD("Received response from relay daemon: cmd=%s, response=%s", - lttng_viewer_command_string(LTTNG_VIEWER_GET_NEXT_INDEX), - lttng_viewer_next_index_return_code_string(rp_status)); + BT_CPPLOGD_SPEC( + viewer_connection->logger, "Received response from relay daemon: cmd=%s, response={}", + LTTNG_VIEWER_GET_NEXT_INDEX, static_cast(rp_status)); if (flags & LTTNG_VIEWER_FLAG_NEW_STREAM) { - BT_COMP_LOGD("Marking all sessions as possibly needing new streams: " - "response=%s, response-flag=NEW_STREAM", - lttng_viewer_next_index_return_code_string(rp_status)); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Marking all sessions as possibly needing new streams: " + "response={}, response-flag=NEW_STREAM", + static_cast(rp_status)); lttng_live_need_new_streams(lttng_live_msg_iter); } @@ -1453,9 +1346,10 @@ lttng_live_get_next_index(struct lttng_live_msg_iter *lttng_live_msg_iter, lttng_live_stream_iterator_set_state(stream, LTTNG_LIVE_STREAM_ACTIVE_DATA); if (flags & LTTNG_VIEWER_FLAG_NEW_METADATA) { - BT_COMP_LOGD("Marking trace as needing new metadata: " - "response=%s, response-flag=NEW_METADATA, trace-id=%" PRIu64, - lttng_viewer_next_index_return_code_string(rp_status), trace->id); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Marking trace as needing new metadata: " + "response={}, response-flag=NEW_METADATA, trace-id={}", + static_cast(rp_status), trace->id); trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED; } status = LTTNG_LIVE_ITERATOR_STATUS_OK; @@ -1479,7 +1373,8 @@ lttng_live_get_next_index(struct lttng_live_msg_iter *lttng_live_msg_iter, status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; goto end; default: - BT_COMP_LOGD("Received get_next_index response: unknown value"); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Received get_next_index response: unknown value"); memset(index, 0, sizeof(struct packet_index)); lttng_live_stream_iterator_set_state(stream, LTTNG_LIVE_STREAM_ACTIVE_NO_DATA); status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; @@ -1505,15 +1400,15 @@ lttng_live_get_stream_bytes(struct lttng_live_msg_iter *lttng_live_msg_iter, struct lttng_viewer_cmd cmd; struct lttng_viewer_get_packet rq; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; - bt_self_component *self_comp = viewer_connection->self_comp; struct lttng_live_trace *trace = stream->trace; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); char cmd_buf[cmd_buf_len]; uint32_t flags, rp_status; - BT_COMP_LOGD("Requesting data from stream: cmd=%s, " - "offset=%" PRIu64 ", request-len=%" PRIu64, - lttng_viewer_command_string(LTTNG_VIEWER_GET_PACKET), offset, req_len); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Requesting data from stream: cmd={}, " + "offset={}, request-len={}", + LTTNG_VIEWER_GET_PACKET, offset, req_len); cmd.cmd = htobe32(LTTNG_VIEWER_GET_PACKET); cmd.data_size = htobe64((uint64_t) sizeof(rq)); @@ -1534,27 +1429,28 @@ lttng_live_get_stream_bytes(struct lttng_live_msg_iter *lttng_live_msg_iter, viewer_status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_send_status(self_comp, NULL, viewer_status, "get data packet command"); + viewer_handle_send_status(viewer_status, "get data packet command"); goto error_convert_status; } viewer_status = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, NULL, viewer_status, "get data packet reply"); + viewer_handle_recv_status(viewer_status, "get data packet reply"); goto error_convert_status; } flags = be32toh(rp.flags); rp_status = be32toh(rp.status); - BT_COMP_LOGD("Received response from relay daemon: cmd=%s, response=%s", - lttng_viewer_command_string(LTTNG_VIEWER_GET_PACKET), - lttng_viewer_get_packet_return_code_string(rp_status)); + BT_CPPLOGD_SPEC( + viewer_connection->logger, "Received response from relay daemon: cmd={}, response={}", + LTTNG_VIEWER_GET_PACKET, static_cast(rp_status)); switch (rp_status) { case LTTNG_VIEWER_GET_PACKET_OK: req_len = be32toh(rp.len); - BT_COMP_LOGD("Got packet from relay daemon: response=%s, packet-len=%" PRIu64 "", - lttng_viewer_get_packet_return_code_string(rp_status), req_len); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Got packet from relay daemon: response={}, packet-len={}", + static_cast(rp_status), req_len); break; case LTTNG_VIEWER_GET_PACKET_RETRY: /* Unimplemented by relay daemon */ @@ -1562,32 +1458,36 @@ lttng_live_get_stream_bytes(struct lttng_live_msg_iter *lttng_live_msg_iter, goto end; case LTTNG_VIEWER_GET_PACKET_ERR: if (flags & LTTNG_VIEWER_FLAG_NEW_METADATA) { - BT_COMP_LOGD("Marking trace as needing new metadata: " - "response=%s, response-flag=NEW_METADATA, trace-id=%" PRIu64, - lttng_viewer_next_index_return_code_string(rp_status), trace->id); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Marking trace as needing new metadata: " + "response={}, response-flag=NEW_METADATA, trace-id={}", + static_cast(rp_status), trace->id); trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED; } if (flags & LTTNG_VIEWER_FLAG_NEW_STREAM) { - BT_COMP_LOGD("Marking all sessions as possibly needing new streams: " - "response=%s, response-flag=NEW_STREAM", - lttng_viewer_next_index_return_code_string(rp_status)); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Marking all sessions as possibly needing new streams: " + "response={}, response-flag=NEW_STREAM", + static_cast(rp_status)); lttng_live_need_new_streams(lttng_live_msg_iter); } if (flags & (LTTNG_VIEWER_FLAG_NEW_METADATA | LTTNG_VIEWER_FLAG_NEW_STREAM)) { status = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN; - BT_COMP_LOGD("Reply with any one flags set means we should retry: response=%s", - lttng_viewer_get_packet_return_code_string(rp_status)); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Reply with any one flags set means we should retry: response={}", + static_cast(rp_status)); goto end; } - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Received get_data_packet response: error"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Received get_data_packet response: error"); status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR; goto end; case LTTNG_VIEWER_GET_PACKET_EOF: status = CTF_MSG_ITER_MEDIUM_STATUS_EOF; goto end; default: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Received get_data_packet response: unknown (%d)", - rp_status); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Received get_data_packet response: unknown ({})", rp_status); status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR; goto end; } @@ -1599,7 +1499,7 @@ lttng_live_get_stream_bytes(struct lttng_live_msg_iter *lttng_live_msg_iter, viewer_status = lttng_live_recv(viewer_connection, buf, req_len); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, NULL, viewer_status, "get data packet"); + viewer_handle_recv_status(viewer_status, "get data packet"); goto error_convert_status; } *recv_len = req_len; @@ -1627,7 +1527,6 @@ lttng_live_session_get_new_streams(struct lttng_live_session *session, struct lttng_live_msg_iter *lttng_live_msg_iter = session->lttng_live_msg_iter; enum lttng_live_viewer_status viewer_status; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; - bt_self_component *self_comp = viewer_connection->self_comp; uint32_t streams_count; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); char cmd_buf[cmd_buf_len]; @@ -1637,9 +1536,9 @@ lttng_live_session_get_new_streams(struct lttng_live_session *session, goto end; } - BT_COMP_LOGD("Requesting new streams for session: cmd=%s, " - "session-id=%" PRIu64, - lttng_viewer_command_string(LTTNG_VIEWER_GET_NEW_STREAMS), session->id); + BT_CPPLOGD_SPEC(viewer_connection->logger, + "Requesting new streams for session: cmd={}, session-id={}", + LTTNG_VIEWER_GET_NEW_STREAMS, session->id); cmd.cmd = htobe32(LTTNG_VIEWER_GET_NEW_STREAMS); cmd.data_size = htobe64((uint64_t) sizeof(rq)); @@ -1658,14 +1557,14 @@ lttng_live_session_get_new_streams(struct lttng_live_session *session, viewer_status = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_send_status(self_comp, NULL, viewer_status, "get new streams command"); + viewer_handle_send_status(viewer_status, "get new streams command"); status = viewer_status_to_live_iterator_status(viewer_status); goto end; } viewer_status = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, NULL, viewer_status, "get new streams reply"); + viewer_handle_recv_status(viewer_status, "get new streams reply"); status = viewer_status_to_live_iterator_status(viewer_status); goto end; } @@ -1685,21 +1584,21 @@ lttng_live_session_get_new_streams(struct lttng_live_session *session, status = LTTNG_LIVE_ITERATOR_STATUS_END; goto end; case LTTNG_VIEWER_NEW_STREAMS_ERR: - BT_COMP_LOGD("Received get_new_streams response: error"); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Received get_new_streams response: error"); status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; goto end; default: - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Received get_new_streams response: Unknown:" - "return code %u", - be32toh(rp.status)); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Received get_new_streams response: Unknown:" + "return code {}", + be32toh(rp.status)); status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; goto end; } viewer_status = receive_streams(session, streams_count, self_msg_iter); if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) { - viewer_handle_recv_status(self_comp, NULL, viewer_status, "new streams"); + viewer_handle_recv_status(viewer_status, "new streams"); status = viewer_status_to_live_iterator_status(viewer_status); goto end; } @@ -1710,56 +1609,46 @@ end: } enum lttng_live_viewer_status live_viewer_connection_create( - bt_self_component *self_comp, bt_self_component_class *self_comp_class, - bt_logging_level log_level, const char *url, bool in_query, - struct lttng_live_msg_iter *lttng_live_msg_iter, struct live_viewer_connection **viewer) + const char *url, bool in_query, struct lttng_live_msg_iter *lttng_live_msg_iter, + const bt2c::Logger& parentLogger, struct live_viewer_connection **viewer) { enum lttng_live_viewer_status status; - live_viewer_connection *viewer_connection = new live_viewer_connection; + live_viewer_connection *viewer_connection = new live_viewer_connection {parentLogger}; - if (bt_socket_init(log_level) != 0) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to init socket"); + if (bt_socket_init(viewer_connection->logger) != 0) { + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Failed to init socket"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto error; } - viewer_connection->log_level = log_level; - - viewer_connection->self_comp = self_comp; - viewer_connection->self_comp_class = self_comp_class; - viewer_connection->control_sock = BT_INVALID_SOCKET; viewer_connection->port = -1; viewer_connection->in_query = in_query; viewer_connection->lttng_live_msg_iter = lttng_live_msg_iter; viewer_connection->url = g_string_new(url); if (!viewer_connection->url) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to allocate URL buffer"); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, "Failed to allocate URL buffer"); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto error; } - BT_COMP_OR_COMP_CLASS_LOGD(self_comp, self_comp_class, - "Establishing connection to url \"%s\"...", url); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Establishing connection to url \"{}\"...", url); status = lttng_live_connect_viewer(viewer_connection); /* * Only print error and append cause in case of error. not in case of * interruption. */ if (status == LTTNG_LIVE_VIEWER_STATUS_ERROR) { - BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, - "Failed to establish connection: " - "url=\"%s\"", - url); + BT_CPPLOGE_APPEND_CAUSE_SPEC(viewer_connection->logger, + "Failed to establish connection: " + "url=\"{}\"", + url); goto error; } else if (status == LTTNG_LIVE_VIEWER_STATUS_INTERRUPTED) { goto error; } - BT_COMP_OR_COMP_CLASS_LOGD(self_comp, self_comp_class, - "Connection to url \"%s\" is established", url); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Connection to url \"{}\" is established", url); *viewer = viewer_connection; status = LTTNG_LIVE_VIEWER_STATUS_OK; @@ -1775,17 +1664,12 @@ end: void live_viewer_connection_destroy(struct live_viewer_connection *viewer_connection) { - bt_self_component *self_comp = viewer_connection->self_comp; - bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; - if (!viewer_connection) { goto end; } - BT_COMP_OR_COMP_CLASS_LOGD(self_comp, self_comp_class, - "Closing connection to relay:" - "relay-url=\"%s\"", - viewer_connection->url->str); + BT_CPPLOGD_SPEC(viewer_connection->logger, "Closing connection to relay: relay-url=\"{}\"", + viewer_connection->url->str); lttng_live_disconnect_viewer(viewer_connection); diff --git a/src/plugins/ctf/lttng-live/viewer-connection.hpp b/src/plugins/ctf/lttng-live/viewer-connection.hpp index 9770092f..4dfae18c 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.hpp +++ b/src/plugins/ctf/lttng-live/viewer-connection.hpp @@ -13,6 +13,7 @@ #include #include "compat/socket.hpp" +#include "cpp-common/bt2c/logging.hpp" #define LTTNG_DEFAULT_NETWORK_VIEWER_PORT 5344 @@ -46,9 +47,12 @@ enum lttng_live_get_one_metadata_status struct live_viewer_connection { - bt_logging_level log_level = (bt_logging_level) 0; - bt_self_component *self_comp = nullptr; - bt_self_component_class *self_comp_class = nullptr; + explicit live_viewer_connection(const bt2c::Logger& parentLogger) : + logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER"} + { + } + + bt2c::Logger logger; GString *url = nullptr; @@ -88,12 +92,9 @@ struct packet_index uint64_t packet_seq_num; /* packet sequence number */ }; -enum lttng_live_viewer_status -live_viewer_connection_create(bt_self_component *self_comp, - bt_self_component_class *self_comp_class, bt_logging_level log_level, - const char *url, bool in_query, - struct lttng_live_msg_iter *lttng_live_msg_iter, - struct live_viewer_connection **viewer_connection); +enum lttng_live_viewer_status live_viewer_connection_create( + const char *url, bool in_query, struct lttng_live_msg_iter *lttng_live_msg_iter, + const bt2c::Logger& parentLogger, struct live_viewer_connection **viewer); void live_viewer_connection_destroy(struct live_viewer_connection *conn); -- 2.34.1