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 \
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
#include <stdbool.h>
+#include "cpp-common/bt2c/logging.hpp"
+
#ifdef __MINGW32__
# include <winsock2.h>
# 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;
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;
}
# 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;
}
* Babeltrace - CTF binary field class reader (BFCR)
*/
-#include <glib.h>
-#include <inttypes.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h>
-
-#include <babeltrace2/babeltrace.h>
-
-#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"
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<bt_logging_level>(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;
} 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:
}
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);
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);
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;
}
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--;
}
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;
}
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,
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);
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;
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);
}
}
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 {
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);
}
}
}
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;
}
}
/* 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;
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;
}
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;
}
}
/* 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;
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;
}
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;
}
}
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;
}
}
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;
}
}
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;
}
/* 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;
}
}
}
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;
}
}
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 */
{
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:
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;
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;
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;
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;
}
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) {
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;
}
}
}
/* 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);
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);
#include <babeltrace2/babeltrace.h>
+#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
*
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 *);
* @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.
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 */
#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"
#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,
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,
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,
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
{
/*
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);
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)
{
#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;
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;
}
}
* Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*/
-#include <glib.h>
-#include <inttypes.h>
-#include <stdlib.h>
-#include <string.h>
-
#include <babeltrace2/babeltrace.h>
-#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"
*/
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;
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);
* 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);
}
}
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;
}
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;
}
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) {
* 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;
}
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;
}
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;
}
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;
}
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;
}
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 */
/* 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;
}
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:
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;
}
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.
* 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;
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;
}
* 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;
}
* 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;
}
*/
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;
}
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;
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;
}
{
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;
}
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;
}
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);
}
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;
}
/* 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;
}
}
end:
- if (target_field_path_pretty) {
- g_string_free(target_field_path_pretty, TRUE);
- }
-
ctf_field_path_fini(&target_field_path);
return ret;
}
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;
}
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;
}
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;
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;
}
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;
}
}
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;
}
}
}
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;
/* 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;
}
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;
}
}
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;
}
}
* Copyright 2018 Philippe Proulx <pproulx@efficios.com>
*/
-#include <inttypes.h>
-#include <string.h>
+#include <babeltrace2/babeltrace.h>
-#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;
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;
}
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;
}
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;
}
{
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;
}
}
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;
}
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;
}
}
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;
}
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;
}
}
* Copyright 2018 Philippe Proulx <pproulx@efficios.com>
*/
-#include <inttypes.h>
+#include <babeltrace2/babeltrace.h>
-#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;
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
#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);
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 */
* Copyright 2018 Philippe Proulx <pproulx@efficios.com>
*/
-#include <stdint.h>
-#include <string.h>
-
-#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 <babeltrace2/babeltrace.h>
#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;
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:
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;
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;
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;
{
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:
}
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);
}
}
}
#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
{
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,
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;
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);
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;
}
* Copyright 2016-2017 Philippe Proulx <pproulx@efficios.com>
*/
-#include <glib.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
-#include <string.h>
-
-#include <babeltrace2/babeltrace.h>
-
-#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"
} __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;
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;
}
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
/* 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;
}
*/
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;
}
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", ".");
}
}
#include <babeltrace2/babeltrace.h>
+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 */
* Copyright 2016-2017 Philippe Proulx <pproulx@efficios.com>
*/
-#include <glib.h>
-#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
-
-#include <babeltrace2/babeltrace.h>
-
-#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"
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;
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;
};
} __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;
*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;
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;
}
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:
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;
}
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;
}
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;
}
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;
}
/* 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;
}
}
#if YYDEBUG
- if (BT_LOG_ON_TRACE) {
+ if (mdec->logger.wouldLogT()) {
yydebug = 1;
}
#endif
/* 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;
}
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;
}
/* 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;
}
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));
}
}
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;
}
#include <babeltrace2/babeltrace.h>
#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
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;
* 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
* Common Trace Formal Lexer
*/
-#include <ctype.h>
-#include <stdio.h>
-
-#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
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;
%%
+++ /dev/null
-/*
- * SPDX-License-Identifier: MIT
- *
- * Copyright (c) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- */
-
-#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");
#include <babeltrace2/babeltrace.h>
-#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 */
* Common Trace Format Object Stack.
*/
-#include <stdlib.h>
-
-#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"
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
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);
bt_list_del(&node->node);
objstack_node_free(node);
}
- free(objstack);
+
+ delete objstack;
}
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);
#include <cstddef>
-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);
/*
* 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
* Common Trace Format Metadata Grammar.
*/
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <glib.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#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"
*/
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)
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);
{
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;
{
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);
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;
}
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);
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;
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);
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;
}
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;
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;
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;
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;
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;
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;
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:
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;
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) \
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);
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;
}
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;
}
/*
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);
* Common Trace Format metadata visitor (generates CTF IR objects).
*/
-#include <string>
-
-#include <errno.h>
-#include <glib.h>
-#include <inttypes.h>
#include <stdio.h>
#include <string.h>
-#include <babeltrace2/babeltrace.h>
-
-#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))
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)
/* 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
*/
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;
/* Config passed by the user */
struct ctf_metadata_decoder_config decoder_config;
+
+ bt2c::Logger logger;
};
/*
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;
}
* @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:
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;
}
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;
}
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)
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;
}
} 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;
}
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;
}
} 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;
}
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;
}
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;
}
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;
}
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;
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;
}
/* 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;
/* 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;
}
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;
}
/* 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;
}
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;
}
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;
}
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;
}
/* 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;
}
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;
}
/* 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;
}
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;
}
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;
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;
}
}
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;
}
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;
* 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;
}
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;
}
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;
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;
}
}
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;
}
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;
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;
}
}
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;
}
/* 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;
}
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;
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;
}
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;
}
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;
}
/* 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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
/* 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;
}
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;
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;
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;
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;
}
}
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;
}
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;
}
_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;
_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;
_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;
_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;
}
_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;
}
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;
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;
} 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;
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;
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;
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;
} 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;
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;
}
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;
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;
}
_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;
_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;
_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;
_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;
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;
_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;
}
_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;
}
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;
} 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;
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);
}
}
*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;
}
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;
}
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;
}
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;
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;
{
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, "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;
}
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;
}
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;
_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;
}
* 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;
_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;
}
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;
}
_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;
}
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;
}
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;
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);
}
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;
}
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);
}
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);
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;
}
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;
}
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;
}
}
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;
}
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;
}
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;
}
}
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;
}
* 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;
}
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;
}
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;
}
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;
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;
{
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;
}
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;
}
/* 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;
}
_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;
}
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;
}
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;
_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;
}
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;
}
_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;
}
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;
}
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;
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;
_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);
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;
}
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;
}
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;
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.");
} 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;
* 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;
}
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;
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;
}
{
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;
}
_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;
}
_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;
}
} 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;
}
_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;
}
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);
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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;
}
}
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;
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);
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;
}
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;
}
_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;
}
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;
}
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;
}
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;
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;
}
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;
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;
}
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;
_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;
_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;
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;
}
_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;
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);
/* 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;
}
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;
}
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;
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;
*/
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;
}
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;
}
{
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;
}
{
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:
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;
}
}
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;
}
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;
}
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;
}
}
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;
}
}
/* 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);
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;
}
}
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;
}
}
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;
}
}
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;
}
/* 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;
}
/* 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;
* 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;
*/
#include <errno.h>
+#include <unistd.h>
-#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"
#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;
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;
}
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;
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;
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;
}
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;
}
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;
}
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
*/
#include <errno.h>
+#include <unistd.h>
-#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"
#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;
* 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;
}
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;
}
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;
}
* 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:
_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;
}
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;
}
/*
* 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;
}
_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;
}
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:
}
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:
}
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;
}
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;
}
{
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;
}
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;
}
}
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;
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
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) {
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;
}
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;
}
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;
}
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;
}
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;
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;
}
}
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;
}
}
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;
}
(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;
(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;
}
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;
}
}
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;
}
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;
}
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;
}
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;
}
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;
}
* Babeltrace - CTF message iterator
*/
-#include <glib.h>
-#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
-#include <babeltrace2/babeltrace.h>
-
-#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"
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;
/* 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;
/* 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:
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);
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);
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--;
}
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);
/* 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
}
/* 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:
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;
}
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;
}
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
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);
/* 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;
}
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;
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;
/*
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:
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) {
* 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;
}
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;
}
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;
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;
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;
}
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;
}
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:
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) {
(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;
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 */
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;
}
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:
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;
* 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;
}
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;
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);
}
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;
}
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;
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:
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;
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:
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;
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:
} 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) {
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) {
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;
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);
}
/*
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);
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;
}
{
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);
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;
}
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);
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;
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;
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;
/* 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;
}
{
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;
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;
{
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;
{
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;
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;
}
}
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
{
}
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;
}
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;
}
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;
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;
}
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:
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;
}
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;
}
{
bt_message *msg;
bool update_default_cs = true;
- bt_self_component *self_comp = msg_it->self_comp;
if (!msg_it->packet) {
msg = NULL;
}
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;
}
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);
}
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;
}
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);
}
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;
}
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 =
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;
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:
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);
}
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;
}
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);
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;
}
/* 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);
#include "../metadata/tsdl/ctf-meta.hpp"
+namespace bt2c {
+
+class Logger;
+
+} /* namespace bt2c */
+
/**
* @file ctf-msg-iter.h
*
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.
*/
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.
*
*/
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.
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 */
*/
#include <glib.h>
-#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
-#include <string.h>
-#include <babeltrace2/babeltrace.h>
-
-#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 <string.h>
-
-#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"
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);
}
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;
}
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);
* 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<int>(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);
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<int>(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;
}
{
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);
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;
}
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;
}
}
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;
/* 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,
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;
/* 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;
}
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;
}
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
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;
}
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;
}
*/
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
/* 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:
{
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);
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 {
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 {
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;
}
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 */
}
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;
}
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:
}
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;
}
goto error;
}
+ offset_align = bt_mmap_get_offset_align_size(static_cast<int>(ds_file->logger.level()));
ds_file->mmap_max_len = offset_align * 2048;
goto end;
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;
}
#include <babeltrace2/babeltrace.h>
+#include "cpp-common/bt2c/logging.hpp"
+
#include "../common/src/msg-iter/msg-iter.hpp"
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;
};
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);
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);
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);
#include <stdio.h>
#include <sys/stat.h>
-#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"
}
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));
}
}
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;
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:
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));
}
}
#include <babeltrace2/babeltrace.h>
+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);
#include <babeltrace2/babeltrace.h>
-#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"
{
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);
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;
{
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<int>(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;
}
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;
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;
{
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++) {
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;
}
}
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<int>(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;
}
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;
}
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;
}
}
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;
}
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;
}
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;
}
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;
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;
}
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;
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;
}
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;
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;
}
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;
}
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;
}
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;
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;
}
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<int>(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;
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;
}
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;
&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;
}
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;
&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;
}
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;
&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;
}
}
* 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
* 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:
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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.");
}
/*
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 =
}
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;
}
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;
}
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;
}
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;
}
#include <babeltrace2/babeltrace.h>
+#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;
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;
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;
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;
/* 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
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. */
*/
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.
* Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
*/
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <babeltrace2/babeltrace.h>
-
-#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"
#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;
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);
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;
{
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;
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;
}
#include <babeltrace2/babeltrace.h>
+namespace bt2c {
+
+class Logger;
+
+} /* namespace bt2c */
+
#define CTF_FS_METADATA_FILENAME "metadata"
struct ctf_fs_metadata_config
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);
#include <babeltrace2/babeltrace.h>
-#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"
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;
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;
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;
}
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;
}
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;
}
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);
}
}
}
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;
/* 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;
}
}
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;
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;
}
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;
}
}
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;
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) {
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;
}
#include <babeltrace2/babeltrace.h>
+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 */
#include <glib.h>
#include <inttypes.h>
#include <stdio.h>
-
-#include <babeltrace2/babeltrace.h>
-
-#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 <glib.h>
-#include <inttypes.h>
-#include <stdio.h>
#include <stdlib.h>
#include <babeltrace2/babeltrace.h>
-#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"
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) {
/*
}
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;
}
{
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 =
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;
}
}
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;
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;
}
*/
#include <glib.h>
-#include <inttypes.h>
#include <unistd.h>
-#include <babeltrace2/babeltrace.h>
-
-#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"
#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)
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);
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;
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);
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;
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;
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;
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) {
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) {
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) {
* 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;
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) {
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;
}
}
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);
{
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
*/
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
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 {
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;
}
{
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:
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;
}
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;
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;
(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;
}
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;
}
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;
}
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;
}
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
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;
}
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) {
/*
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;
}
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;
* 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<bt2::MessageType>(bt_message_get_type(late_msg)));
stream_iter_status = LTTNG_LIVE_ITERATOR_STATUS_ERROR;
goto end;
}
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;
}
* 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<bt2::MessageType>(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(
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
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<bt2::MessageType>(bt_message_get_type(msg)),
+ stream_iter->name->str, stream_iter->viewer_stream_id);
/*
* Get the timestamp in nanoseconds from origin of this
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;
}
* 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));
}
}
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.
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++;
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;
* 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;
}
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 {
* 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
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));
}
}
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. */
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
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);
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;
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;
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;
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;
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;
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;
}
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;
*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;
}
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;
}
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;
}
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;
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;
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;
}
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;
}
#include <babeltrace2/babeltrace.h>
+#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"
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;
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. */
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;
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. */
*/
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;
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. */
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,
#include <stdint.h>
-#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
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. */
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,
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,
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. */
* Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
*/
-#include <glib.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <babeltrace2/babeltrace.h>
-
-#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"
} __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;
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;
}
}
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) {
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;
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.
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();
/* 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;
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;
* 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:
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;
}
closeret = fclose(fp);
if (closeret) {
- BT_COMP_LOGW_ERRNO("Error on fclose", ".");
+ BT_CPPLOGW_ERRNO_SPEC(metadata->logger, "Error on fclose", ".");
}
}
free(metadata_buf);
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;
#include <babeltrace2/babeltrace.h>
-#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 */
#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)
{
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;
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;
* 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;
* 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;
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;
* 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;
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;
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;
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));
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;
}
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 ? "<none>" : viewer_connection->target_hostname->str,
!viewer_connection->session_name ? "<none>" : viewer_connection->session_name->str,
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;
}
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;
}
* 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;
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;
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;
}
}
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;
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;
}
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;
}
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;
}
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;
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;
}
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;
}
*/
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;
}
*/
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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);
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) {
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) {
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) {
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;
}
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);
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;
}
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) &&
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;
}
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);
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;
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;
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';
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;
}
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));
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;
}
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;
}
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();
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);
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));
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;
}
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;
}
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);
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:
* 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;
}
* 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;
}
*/
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;
}
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;
}
}
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);
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<lttng_viewer_next_index_return_code>(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<lttng_viewer_next_index_return_code>(rp_status));
lttng_live_need_new_streams(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<lttng_viewer_next_index_return_code>(rp_status), trace->id);
trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED;
}
status = LTTNG_LIVE_ITERATOR_STATUS_OK;
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;
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));
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<lttng_viewer_get_packet_return_code>(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<lttng_viewer_get_packet_return_code>(rp_status), req_len);
break;
case LTTNG_VIEWER_GET_PACKET_RETRY:
/* Unimplemented by relay daemon */
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<lttng_viewer_get_packet_return_code>(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<lttng_viewer_get_packet_return_code>(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<lttng_viewer_get_packet_return_code>(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;
}
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;
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];
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));
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;
}
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;
}
}
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;
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);
#include <babeltrace2/babeltrace.h>
#include "compat/socket.hpp"
+#include "cpp-common/bt2c/logging.hpp"
#define LTTNG_DEFAULT_NETWORK_VIEWER_PORT 5344
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;
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);