From ea14c7dd641ec094a4c63e2f6de59aab8cbb8603 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 17 Jun 2019 18:13:54 -0400 Subject: [PATCH] `ctf` plugin: `bt_msg_iter`: use object's log level As of this patch, the users of `bt_msg_iter` set the new log level parameter to their 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: I279d22831c5857dc10622e6cabacf64c32fa5ed4 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1488 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- src/cli/babeltrace2.c | 1 - src/plugins/ctf/common/msg-iter/Makefile.am | 4 +-- src/plugins/ctf/common/msg-iter/logging.c | 27 -------------- src/plugins/ctf/common/msg-iter/logging.h | 31 ---------------- src/plugins/ctf/common/msg-iter/msg-iter.c | 39 ++++++++++++++++----- src/plugins/ctf/common/msg-iter/msg-iter.h | 2 +- src/plugins/ctf/fs-src/fs.c | 4 +-- src/plugins/ctf/lttng-live/data-stream.c | 4 +-- 8 files changed, 37 insertions(+), 75 deletions(-) delete mode 100644 src/plugins/ctf/common/msg-iter/logging.c delete mode 100644 src/plugins/ctf/common/msg-iter/logging.h diff --git a/src/cli/babeltrace2.c b/src/cli/babeltrace2.c index 5cd3fd43..830ebf5a 100644 --- a/src/cli/babeltrace2.c +++ b/src/cli/babeltrace2.c @@ -50,7 +50,6 @@ */ static const char* log_level_env_var_names[] = { "BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL", - "BABELTRACE_PLUGIN_CTF_MSG_ITER_LOG_LEVEL", "BABELTRACE_PLUGIN_CTF_UTILS_LOG_LEVEL", "BABELTRACE_PYTHON_BT2_LOG_LEVEL", "BABELTRACE_SINK_CTF_FS_LOG_LEVEL", diff --git a/src/plugins/ctf/common/msg-iter/Makefile.am b/src/plugins/ctf/common/msg-iter/Makefile.am index 7c3c2087..e1a00ad9 100644 --- a/src/plugins/ctf/common/msg-iter/Makefile.am +++ b/src/plugins/ctf/common/msg-iter/Makefile.am @@ -2,6 +2,4 @@ noinst_LTLIBRARIES = libctf-msg-iter.la libctf_msg_iter_la_SOURCES = \ msg-iter.c \ - msg-iter.h \ - logging.c \ - logging.h + msg-iter.h diff --git a/src/plugins/ctf/common/msg-iter/logging.c b/src/plugins/ctf/common/msg-iter/logging.c deleted file mode 100644 index 662c4433..00000000 --- a/src/plugins/ctf/common/msg-iter/logging.c +++ /dev/null @@ -1,27 +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 ctf_msg_iter_log_level -#include "logging/log.h" - -BT_LOG_INIT_LOG_LEVEL(ctf_msg_iter_log_level, - "BABELTRACE_PLUGIN_CTF_MSG_ITER_LOG_LEVEL"); diff --git a/src/plugins/ctf/common/msg-iter/logging.h b/src/plugins/ctf/common/msg-iter/logging.h deleted file mode 100644 index 9788916a..00000000 --- a/src/plugins/ctf/common/msg-iter/logging.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef CTF_MSG_ITER_LOGGING_H -#define CTF_MSG_ITER_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 ctf_msg_iter_log_level -#include "logging/log.h" - -BT_LOG_LEVEL_EXTERN_SYMBOL(ctf_msg_iter_log_level); - -#endif /* CTF_MSG_ITER_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 99c58598..60d83e15 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.c +++ b/src/plugins/ctf/common/msg-iter/msg-iter.c @@ -23,8 +23,9 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL (notit->log_level) #define BT_LOG_TAG "PLUGIN/CTF/MSG-ITER" -#include "logging.h" +#include "logging/log.h" #include #include @@ -62,8 +63,12 @@ struct stack_entry { size_t index; }; +struct bt_msg_iter; + /* Visit stack */ struct stack { + struct bt_msg_iter *notit; + /* Entries (struct stack_entry) */ GArray *entries; @@ -244,6 +249,9 @@ struct bt_msg_iter { /* Stored values (for sequence lengths, variant tags) */ GArray *stored_values; + + /* Iterator's current log level */ + bt_logging_level log_level; }; static inline @@ -325,6 +333,7 @@ struct stack *stack_new(struct bt_msg_iter *notit) goto error; } + stack->notit = notit; stack->entries = g_array_new(FALSE, TRUE, sizeof(struct stack_entry)); if (!stack->entries) { BT_LOGE_STR("Failed to allocate a GArray."); @@ -345,7 +354,10 @@ end: static void stack_destroy(struct stack *stack) { + struct bt_msg_iter *notit; + BT_ASSERT(stack); + notit = stack->notit; BT_LOGD("Destroying stack: addr=%p", stack); if (stack->entries) { @@ -359,8 +371,10 @@ static void stack_push(struct stack *stack, bt_field *base) { struct stack_entry *entry; + struct bt_msg_iter *notit; BT_ASSERT(stack); + notit = stack->notit; BT_ASSERT(base); BT_LOGV("Pushing base field on stack: stack-addr=%p, " "stack-size-before=%zu, stack-size-after=%zu", @@ -386,8 +400,11 @@ unsigned int stack_size(struct stack *stack) static void stack_pop(struct stack *stack) { + struct bt_msg_iter *notit; + BT_ASSERT(stack); BT_ASSERT(stack_size(stack)); + notit = stack->notit; BT_LOGV("Popping from stack: " "stack-addr=%p, stack-size-before=%zu, stack-size-after=%zu", stack, stack->size, stack->size - 1); @@ -2683,7 +2700,8 @@ void create_msg_discarded_packets(struct bt_msg_iter *notit, BT_HIDDEN struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc, size_t max_request_sz, - struct bt_msg_iter_medium_ops medops, void *data) + struct bt_msg_iter_medium_ops medops, void *data, + bt_logging_level log_level) { struct bt_msg_iter *notit = NULL; struct bt_bfcr_cbs cbs = { @@ -2706,14 +2724,18 @@ struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc, BT_ASSERT(tc); BT_ASSERT(medops.request_bytes); BT_ASSERT(medops.borrow_stream); - BT_LOGD("Creating CTF plugin message iterator: " + BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, log_level, BT_LOG_TAG, + "Creating CTF plugin message iterator: " "trace-addr=%p, max-request-size=%zu, " - "data=%p", tc, max_request_sz, data); + "data=%p, log-level=%s", tc, max_request_sz, data, + bt_common_logging_level_string(log_level)); notit = g_new0(struct bt_msg_iter, 1); if (!notit) { - BT_LOGE_STR("Failed to allocate one CTF plugin message iterator."); + BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG, + "Failed to allocate one CTF plugin message iterator."); goto end; } + notit->log_level = log_level; notit->meta.tc = tc; notit->medium.medops = medops; notit->medium.max_request_sz = max_request_sz; @@ -2727,7 +2749,7 @@ struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc, goto error; } - notit->bfcr = bt_bfcr_create(cbs, notit, BT_LOG_OUTPUT_LEVEL); + notit->bfcr = bt_bfcr_create(cbs, notit, log_level); if (!notit->bfcr) { BT_LOGE_STR("Failed to create binary class reader (BFCR)."); goto error; @@ -2736,8 +2758,9 @@ struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc, bt_msg_iter_reset(notit); BT_LOGD("Created CTF plugin message iterator: " "trace-addr=%p, max-request-size=%zu, " - "data=%p, notit-addr=%p", - tc, max_request_sz, data, notit); + "data=%p, notit-addr=%p, log-level=%s", + tc, max_request_sz, data, notit, + bt_common_logging_level_string(log_level)); notit->cur_packet_offset = 0; end: diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.h b/src/plugins/ctf/common/msg-iter/msg-iter.h index 77849db6..1aeeafe5 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.h +++ b/src/plugins/ctf/common/msg-iter/msg-iter.h @@ -253,7 +253,7 @@ struct bt_msg_iter; BT_HIDDEN struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc, size_t max_request_sz, struct bt_msg_iter_medium_ops medops, - void *medops_data); + void *medops_data, bt_logging_level log_level); /** * Destroys a CTF message iterator, freeing all internal resources. diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c index dc94e95b..7ea06e13 100644 --- a/src/plugins/ctf/fs-src/fs.c +++ b/src/plugins/ctf/fs-src/fs.c @@ -261,7 +261,7 @@ bt_self_message_iterator_status ctf_fs_iterator_init( msg_iter_data->msg_iter = bt_msg_iter_create( port_data->ds_file_group->ctf_fs_trace->metadata->tc, bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL) * 8, - ctf_fs_ds_file_medops, NULL); + ctf_fs_ds_file_medops, NULL, BT_LOG_OUTPUT_LEVEL); if (!msg_iter_data->msg_iter) { BT_LOGE_STR("Cannot create a CTF message iterator."); ret = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM; @@ -722,7 +722,7 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, msg_iter = bt_msg_iter_create(ctf_fs_trace->metadata->tc, bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL) * 8, - ctf_fs_ds_file_medops, NULL); + ctf_fs_ds_file_medops, NULL, BT_LOG_OUTPUT_LEVEL); if (!msg_iter) { BT_LOGE_STR("Cannot create a CTF message iterator."); goto error; diff --git a/src/plugins/ctf/lttng-live/data-stream.c b/src/plugins/ctf/lttng-live/data-stream.c index 5641d281..7d3abaae 100644 --- a/src/plugins/ctf/lttng-live/data-stream.c +++ b/src/plugins/ctf/lttng-live/data-stream.c @@ -152,7 +152,7 @@ enum lttng_live_iterator_status lttng_live_lazy_msg_init( trace->metadata->decoder); stream_iter->msg_iter = bt_msg_iter_create(ctf_tc, lttng_live->max_query_size, medops, - stream_iter); + stream_iter, BT_LOG_OUTPUT_LEVEL); if (!stream_iter->msg_iter) { goto error; } @@ -206,7 +206,7 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( BT_ASSERT(!stream_iter->msg_iter); stream_iter->msg_iter = bt_msg_iter_create(ctf_tc, lttng_live->max_query_size, medops, - stream_iter); + stream_iter, BT_LOG_OUTPUT_LEVEL); if (!stream_iter->msg_iter) { goto error; } -- 2.34.1