From: Philippe Proulx Date: Mon, 17 Jun 2019 22:00:09 +0000 (-0400) Subject: `ctf` plugin: `bt_bfcr`: use object's log level X-Git-Url: https://git.efficios.com/?a=commitdiff_plain;h=80870e64b3eaa36324881feb46773794c3ead8c7;p=babeltrace.git `ctf` plugin: `bt_bfcr`: use object's log level As of this patch, the only user of `bt_bfcr` is `bt_msg_iter`, which sets the new log level parameter to its own (global) log level. The goal is to eventually have a per-component log level for the `ctf` plugin's component classes. Signed-off-by: Philippe Proulx Change-Id: Ie77969d587c03c7d0257c19bb151ee22707b9842 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1487 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- diff --git a/src/cli/babeltrace2.c b/src/cli/babeltrace2.c index db2ed837..5cd3fd43 100644 --- a/src/cli/babeltrace2.c +++ b/src/cli/babeltrace2.c @@ -49,7 +49,6 @@ * modules. */ static const char* log_level_env_var_names[] = { - "BABELTRACE_PLUGIN_CTF_BFCR_LOG_LEVEL", "BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL", "BABELTRACE_PLUGIN_CTF_MSG_ITER_LOG_LEVEL", "BABELTRACE_PLUGIN_CTF_UTILS_LOG_LEVEL", diff --git a/src/plugins/ctf/common/bfcr/Makefile.am b/src/plugins/ctf/common/bfcr/Makefile.am index d0dd8c6f..9b3a1950 100644 --- a/src/plugins/ctf/common/bfcr/Makefile.am +++ b/src/plugins/ctf/common/bfcr/Makefile.am @@ -1,6 +1,4 @@ noinst_LTLIBRARIES = libctf-bfcr.la libctf_bfcr_la_SOURCES = \ bfcr.c \ - bfcr.h \ - logging.c \ - logging.h + bfcr.h diff --git a/src/plugins/ctf/common/bfcr/bfcr.c b/src/plugins/ctf/common/bfcr/bfcr.c index db84fe95..c4266cd8 100644 --- a/src/plugins/ctf/common/bfcr/bfcr.c +++ b/src/plugins/ctf/common/bfcr/bfcr.c @@ -23,8 +23,9 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL (bfcr->log_level) #define BT_LOG_TAG "PLUGIN/CTF/BFCR" -#include "logging.h" +#include "logging/log.h" #include #include @@ -68,8 +69,12 @@ struct stack_entry { int64_t index; }; +struct bt_bfcr; + /* Visit stack */ struct stack { + struct bt_bfcr *bfcr; + /* Entries (struct stack_entry) */ GArray *entries; @@ -89,7 +94,9 @@ enum bfcr_state { /* Binary class reader */ struct bt_bfcr { - /* Bisit stack */ + bt_logging_level log_level; + + /* BFCR stack */ struct stack *stack; /* Current basic field class */ @@ -178,7 +185,7 @@ const char *bfcr_state_string(enum bfcr_state state) } static -struct stack *stack_new(void) +struct stack *stack_new(struct bt_bfcr *bfcr) { struct stack *stack = NULL; @@ -188,6 +195,7 @@ struct stack *stack_new(void) goto error; } + stack->bfcr = bfcr; stack->entries = g_array_new(FALSE, TRUE, sizeof(struct stack_entry)); if (!stack->entries) { BT_LOGE_STR("Failed to allocate a GArray."); @@ -205,10 +213,13 @@ error: static void stack_destroy(struct stack *stack) { + struct bt_bfcr *bfcr; + if (!stack) { return; } + bfcr = stack->bfcr; BT_LOGD("Destroying stack: addr=%p", stack); if (stack->entries) { @@ -223,9 +234,11 @@ int stack_push(struct stack *stack, struct ctf_field_class *base_class, size_t base_len) { struct stack_entry *entry; + struct bt_bfcr *bfcr; BT_ASSERT(stack); BT_ASSERT(base_class); + bfcr = stack->bfcr; BT_LOGV("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", @@ -312,8 +325,11 @@ unsigned int stack_size(struct stack *stack) static void stack_pop(struct stack *stack) { + struct bt_bfcr *bfcr; + BT_ASSERT(stack); BT_ASSERT(stack_size(stack)); + bfcr = stack->bfcr; BT_LOGV("Popping from stack: " "stack-addr=%p, stack-size-before=%u, stack-size-after=%u", stack, stack->entries->len, stack->entries->len - 1); @@ -444,7 +460,7 @@ void stitch_set_from_remaining_buf(struct bt_bfcr *bfcr) } static inline -void read_unsigned_bitfield(const uint8_t *buf, size_t at, +void read_unsigned_bitfield(struct bt_bfcr *bfcr, const uint8_t *buf, size_t at, unsigned int field_size, enum ctf_byte_order bo, uint64_t *v) { @@ -464,7 +480,7 @@ void read_unsigned_bitfield(const uint8_t *buf, size_t at, } static inline -void read_signed_bitfield(const uint8_t *buf, size_t at, +void read_signed_bitfield(struct bt_bfcr *bfcr, const uint8_t *buf, size_t at, unsigned int field_size, enum ctf_byte_order bo, int64_t *v) { switch (bo) { @@ -556,7 +572,7 @@ enum bt_bfcr_status read_basic_float_and_call_cb(struct bt_bfcr *bfcr, float f; } f32; - read_unsigned_bitfield(buf, at, field_size, bo, &v); + read_unsigned_bitfield(bfcr, buf, at, field_size, bo, &v); f32.u = (uint32_t) v; dblval = (double) f32.f; break; @@ -568,7 +584,7 @@ enum bt_bfcr_status read_basic_float_and_call_cb(struct bt_bfcr *bfcr, double d; } f64; - read_unsigned_bitfield(buf, at, field_size, bo, &f64.u); + read_unsigned_bitfield(bfcr, buf, at, field_size, bo, &f64.u); dblval = f64.d; break; } @@ -617,7 +633,7 @@ enum bt_bfcr_status read_basic_int_and_call_cb(struct bt_bfcr *bfcr, if (fc->is_signed) { int64_t v; - read_signed_bitfield(buf, at, field_size, bo, &v); + read_signed_bitfield(bfcr, buf, at, field_size, bo, &v); if (bfcr->user.cbs.classes.signed_int) { BT_LOGV("Calling user function (signed integer)."); @@ -634,7 +650,7 @@ enum bt_bfcr_status read_basic_int_and_call_cb(struct bt_bfcr *bfcr, } else { uint64_t v; - read_unsigned_bitfield(buf, at, field_size, bo, &v); + read_unsigned_bitfield(bfcr, buf, at, field_size, bo, &v); if (bfcr->user.cbs.classes.unsigned_int) { BT_LOGV("Calling user function (unsigned integer)."); @@ -1170,18 +1186,22 @@ enum bt_bfcr_status handle_state(struct bt_bfcr *bfcr) } BT_HIDDEN -struct bt_bfcr *bt_bfcr_create(struct bt_bfcr_cbs cbs, void *data) +struct bt_bfcr *bt_bfcr_create(struct bt_bfcr_cbs cbs, void *data, + bt_logging_level log_level) { struct bt_bfcr *bfcr; - BT_LOGD_STR("Creating binary field class reader (BFCR)."); + BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, log_level, BT_LOG_TAG, + "Creating binary field class reader (BFCR)."); bfcr = g_new0(struct bt_bfcr, 1); if (!bfcr) { - BT_LOGE_STR("Failed to allocate one binary class reader."); + BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG, + "Failed to allocate one binary class reader."); goto end; } - bfcr->stack = stack_new(); + bfcr->log_level = log_level; + bfcr->stack = stack_new(bfcr); if (!bfcr->stack) { BT_LOGE_STR("Cannot create BFCR's stack."); bt_bfcr_destroy(bfcr); diff --git a/src/plugins/ctf/common/bfcr/bfcr.h b/src/plugins/ctf/common/bfcr/bfcr.h index 7d31d2a1..ffa304a5 100644 --- a/src/plugins/ctf/common/bfcr/bfcr.h +++ b/src/plugins/ctf/common/bfcr/bfcr.h @@ -277,7 +277,8 @@ struct bt_bfcr_cbs { * @returns New binary class reader on success, or \c NULL on error */ BT_HIDDEN -struct bt_bfcr *bt_bfcr_create(struct bt_bfcr_cbs cbs, void *data); +struct bt_bfcr *bt_bfcr_create(struct bt_bfcr_cbs cbs, void *data, + bt_logging_level log_level); /** * Destroys a CTF binary class reader, freeing all internal resources. diff --git a/src/plugins/ctf/common/bfcr/logging.c b/src/plugins/ctf/common/bfcr/logging.c deleted file mode 100644 index 77ac65f2..00000000 --- a/src/plugins/ctf/common/bfcr/logging.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017 Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define BT_LOG_OUTPUT_LEVEL bfcr_log_level -#include "logging/log.h" - -BT_LOG_INIT_LOG_LEVEL(bfcr_log_level, "BABELTRACE_PLUGIN_CTF_BFCR_LOG_LEVEL"); diff --git a/src/plugins/ctf/common/bfcr/logging.h b/src/plugins/ctf/common/bfcr/logging.h deleted file mode 100644 index cb284685..00000000 --- a/src/plugins/ctf/common/bfcr/logging.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef CTF_BFCR_LOGGING_H -#define CTF_BFCR_LOGGING_H - -/* - * Copyright (c) 2017 Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define BT_LOG_OUTPUT_LEVEL bfcr_log_level -#include "logging/log.h" - -BT_LOG_LEVEL_EXTERN_SYMBOL(bfcr_log_level); - -#endif /* CTF_BFCR_LOGGING_H */ diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.c b/src/plugins/ctf/common/msg-iter/msg-iter.c index 13914231..99c58598 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.c +++ b/src/plugins/ctf/common/msg-iter/msg-iter.c @@ -2727,7 +2727,7 @@ struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc, goto error; } - notit->bfcr = bt_bfcr_create(cbs, notit); + notit->bfcr = bt_bfcr_create(cbs, notit, BT_LOG_OUTPUT_LEVEL); if (!notit->bfcr) { BT_LOGE_STR("Failed to create binary class reader (BFCR)."); goto error;