`ctf` plugin: `bt_bfcr`: use object's log level
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 17 Jun 2019 22:00:09 +0000 (18:00 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 20 Jun 2019 18:01:16 +0000 (14:01 -0400)
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 <eeppeliteloop@gmail.com>
Change-Id: Ie77969d587c03c7d0257c19bb151ee22707b9842
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1487
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/cli/babeltrace2.c
src/plugins/ctf/common/bfcr/Makefile.am
src/plugins/ctf/common/bfcr/bfcr.c
src/plugins/ctf/common/bfcr/bfcr.h
src/plugins/ctf/common/bfcr/logging.c [deleted file]
src/plugins/ctf/common/bfcr/logging.h [deleted file]
src/plugins/ctf/common/msg-iter/msg-iter.c

index db2ed837ca893c83ae5ab87ba5f9ee3d5f054dbd..5cd3fd4357e9db51b158d92a8cfffffcc965f9b8 100644 (file)
@@ -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",
index d0dd8c6f280b746dac7d605d72e957720a6821ba..9b3a195086d9ae3a04b324fb217999f6a8ac3b10 100644 (file)
@@ -1,6 +1,4 @@
 noinst_LTLIBRARIES = libctf-bfcr.la
 libctf_bfcr_la_SOURCES = \
        bfcr.c \
-       bfcr.h \
-       logging.c \
-       logging.h
+       bfcr.h
index db84fe95644886f0955d1de3f29eac874b1d9bdd..c4266cd8df17fe7f0afc42011e1d778bdcf5eb51 100644 (file)
@@ -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 <stdlib.h>
 #include <stdint.h>
@@ -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);
index 7d31d2a1414a3324feabbb049092cbd204fc4813..ffa304a55a3b311dcbb9079ae07b40b2bdf438ae 100644 (file)
@@ -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 (file)
index 77ac65f..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
- *
- * 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 (file)
index cb28468..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef CTF_BFCR_LOGGING_H
-#define CTF_BFCR_LOGGING_H
-
-/*
- * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
- *
- * 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 */
index 13914231bbc0b70336b3a3ee8ca91d6903b1038f..99c585980bf8db9b97f151c3921676613ab1b9be 100644 (file)
@@ -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;
This page took 0.033368 seconds and 4 git commands to generate.