Logging: pass dynamic log level to common functions and subsystems
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 15 Jun 2019 03:59:04 +0000 (23:59 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 20 Jun 2019 18:01:16 +0000 (14:01 -0400)
This patch makes the project's common functions and subsystems get a
dynamic log level instead of using a global one set from an environment
variable. The goal is to achieve per-component log levels, so the common
functions and subsystems must receive, eventually, the component's
specific log level.

"Naked" functions (without a context object of some sort) simply get
their log level from a new parameter. In that case `BT_LOG_OUTPUT_LEVEL`
is simply defined to `log_level`, so a local `log_level` variable must
exist when using logging statements. Subsystems, such as an FD cache or
a CTF serializer, get their log level from a new parameter in their
initialization function and then use it for their other operations.

It was somehow hard to do this for `src/common` alone without also doing
it for the rest so I'm doing all of them at once here.

For those subsystems, the local `logging.c` and `logging.h` disappear.

`tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c` needs to pass
a log level to the FD cache subsystem; I used the WARN level instead of
setting the log level from an environment variable for this test alone.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I35979a8fe4c74afe5921c3b6651015cd7ee2760a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1460
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
30 files changed:
src/cli/babeltrace2-cfg-cli-args.c
src/cli/babeltrace2.c
src/common/Makefile.am
src/common/common.c
src/common/common.h
src/common/logging.c [deleted file]
src/common/logging.h [deleted file]
src/common/mmap-align.h
src/compat/Makefile.am
src/compat/logging.c [deleted file]
src/compat/logging.h [deleted file]
src/compat/mman.c
src/compat/uuid.c
src/ctf-writer/stream.c
src/ctfser/Makefile.am
src/ctfser/ctfser.c
src/ctfser/ctfser.h
src/ctfser/logging.c [deleted file]
src/ctfser/logging.h [deleted file]
src/fd-cache/Makefile.am
src/fd-cache/fd-cache.c
src/fd-cache/fd-cache.h
src/fd-cache/logging.c [deleted file]
src/fd-cache/logging.h [deleted file]
src/lib/plugin/plugin.c
src/plugins/ctf/fs-sink/fs-sink-stream.c
src/plugins/ctf/fs-src/data-stream-file.c
src/plugins/ctf/fs-src/fs.c
src/plugins/lttng-utils/debug-info/debug-info.c
tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c

index cad2b4aa4f37da40e6870d072e0f2a11f1172411..6e9aac954c534ef380200a441c2e293da21ba4cf 100644 (file)
@@ -1553,8 +1553,8 @@ int append_home_and_system_plugin_paths(bt_value *plugin_paths,
                if (bt_common_is_setuid_setgid()) {
                        BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
                } else {
-                       char *home_plugin_dir =
-                               bt_common_get_home_plugin_path();
+                       char *home_plugin_dir = bt_common_get_home_plugin_path(
+                               BT_LOG_OUTPUT_LEVEL);
 
                        if (home_plugin_dir) {
                                ret = bt_config_append_plugin_paths(
index d4145f1de22895928869efc58f17d935533e925b..9aa52a873ed165abcd71c432edfc353b803f7d78 100644 (file)
  * modules.
  */
 static const char* log_level_env_var_names[] = {
-       "BABELTRACE_COMMON_LOG_LEVEL",
-       "BABELTRACE_COMPAT_LOG_LEVEL",
-       "BABELTRACE_CTFSER_LOG_LEVEL",
-       "BABELTRACE_FD_CACHE_LOG_LEVEL",
        "BABELTRACE_FLT_LTTNG_UTILS_DEBUG_INFO_LOG_LEVEL",
        "BABELTRACE_FLT_UTILS_COUNTER_LOG_LEVEL",
        "BABELTRACE_FLT_UTILS_MUXER_LOG_LEVEL",
index 7db98d7af11d9cfe43d792e544eb6ac47f847c9a..b2a232e899b29b6c439a9f27bd4dcbd4adea91bd 100644 (file)
@@ -6,9 +6,7 @@ libbabeltrace2_common_la_SOURCES = \
        assert.h \
        assert.c \
        common.c \
-       common.h \
-       logging.c \
-       logging.h
+       common.h
 
 noinst_HEADERS = \
        align.h \
index 3c48e84f31bc6d8b1a6209441b7e4e6817972ef8..d5f05062968629a31cce75bd2f7e02af9d478455 100644 (file)
@@ -22,8 +22,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_OUTPUT_LEVEL log_level
 #define BT_LOG_TAG "COMMON"
-#include "logging.h"
+#include "logging/log.h"
 
 #include <unistd.h>
 #include <string.h>
@@ -116,7 +117,7 @@ bool bt_common_is_setuid_setgid(void)
 #endif /* __MINGW32__ */
 
 static
-char *bt_secure_getenv(const char *name)
+char *bt_secure_getenv(const char *name, int log_level)
 {
        if (bt_common_is_setuid_setgid()) {
                BT_LOGD("Disregarding environment variable for setuid/setgid binary: "
@@ -128,18 +129,18 @@ char *bt_secure_getenv(const char *name)
 
 #ifdef __MINGW32__
 static
-const char *bt_get_home_dir(void)
+const char *bt_get_home_dir(int log_level)
 {
        return g_get_home_dir();
 }
 #else /* __MINGW32__ */
 static
-const char *bt_get_home_dir(void)
+const char *bt_get_home_dir(int log_level)
 {
        char *val = NULL;
        struct passwd *pwd;
 
-       val = bt_secure_getenv(HOME_ENV_VAR);
+       val = bt_secure_getenv(HOME_ENV_VAR, log_level);
        if (val) {
                goto end;
        }
@@ -155,13 +156,13 @@ end:
 #endif /* __MINGW32__ */
 
 BT_HIDDEN
-char *bt_common_get_home_plugin_path(void)
+char *bt_common_get_home_plugin_path(int log_level)
 {
        char *path = NULL;
        const char *home_dir;
        size_t length;
 
-       home_dir = bt_get_home_dir();
+       home_dir = bt_get_home_dir(log_level);
        if (!home_dir) {
                goto end;
        }
@@ -1238,7 +1239,7 @@ end:
 #endif
 
 BT_HIDDEN
-size_t bt_common_get_page_size(void)
+size_t bt_common_get_page_size(int log_level)
 {
        int page_size;
 
index c62da1a3b80d214c03c7e1014541549327cfb941..8ac995358bf7d746977ebef36fa677a2e546d26c 100644 (file)
@@ -93,7 +93,7 @@ const char *bt_common_get_system_plugin_path(void);
  * return value.
  */
 BT_HIDDEN
-char *bt_common_get_home_plugin_path(void);
+char *bt_common_get_home_plugin_path(int log_level);
 
 /*
  * Appends the list of directories in `paths` to the array `dirs`.
@@ -310,7 +310,7 @@ void bt_common_custom_snprintf(char *buf, size_t buf_size,
  * Returns the system page size.
  */
 BT_HIDDEN
-size_t bt_common_get_page_size(void);
+size_t bt_common_get_page_size(int log_level);
 
 /*
  * Adds the digit separator `sep` as many times as needed to form groups
@@ -334,7 +334,7 @@ void bt_common_sep_digits(char *str, unsigned int digits_per_group, char sep);
  * value smaller than the requested `count`.
  */
 static inline
-ssize_t bt_common_read(int fd, void *buf, size_t count)
+ssize_t bt_common_read(int fd, void *buf, size_t count, int log_level)
 {
        size_t i = 0;
        ssize_t ret;
@@ -348,15 +348,18 @@ ssize_t bt_common_read(int fd, void *buf, size_t count)
                ret = read(fd, buf + i, count - i);
                if (ret < 0) {
                        if (errno == EINTR) {
-#ifdef BT_LOGD_STR
-                               BT_LOGD_STR("read() call interrupted; retrying...");
+#ifdef BT_LOG_WRITE_CUR_LVL
+                               BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, log_level,
+                                       BT_LOG_TAG,
+                                       "read() call interrupted; retrying...");
 #endif
                                /* retry operation */
                                continue;
                        } else {
-#ifdef BT_LOGE_ERRNO
-                               BT_LOGE_ERRNO("Error while reading", ": fd=%d",
-                                       fd);
+#ifdef BT_LOG_WRITE_ERRNO_CUR_LVL
+                               BT_LOG_WRITE_ERRNO_CUR_LVL(BT_LOG_ERROR,
+                                       log_level, BT_LOG_TAG,
+                                       "Error while reading", ": fd=%d", fd);
 #endif
                                goto end;
                        }
diff --git a/src/common/logging.c b/src/common/logging.c
deleted file mode 100644 (file)
index 7af804b..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 bt_common_log_level
-#include "logging/log.h"
-
-BT_LOG_INIT_LOG_LEVEL(bt_common_log_level, "BABELTRACE_COMMON_LOG_LEVEL");
diff --git a/src/common/logging.h b/src/common/logging.h
deleted file mode 100644 (file)
index 48e1f7b..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef COMMON_LOGGING_H
-#define COMMON_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 bt_common_log_level
-#include "logging/log.h"
-
-BT_LOG_LEVEL_EXTERN_SYMBOL(bt_common_log_level);
-
-#endif /* COMMON_LOGGING_H */
index 1bb2b72fad8719601235a2fea7020a919b215b7b..5d91c03523f240c47623a216ea8532b21cf3cb5c 100644 (file)
@@ -72,13 +72,13 @@ off_t get_page_aligned_offset(off_t offset, size_t page_size)
 
 static inline
 struct mmap_align *mmap_align(size_t length, int prot,
-               int flags, int fd, off_t offset)
+               int flags, int fd, off_t offset, int log_level)
 {
        struct mmap_align *mma;
        off_t page_aligned_offset;      /* mmap offset, aligned to floor */
        size_t page_size;
 
-       page_size = bt_common_get_page_size();
+       page_size = bt_common_get_page_size(log_level);
 
        mma = malloc(sizeof(*mma));
        if (!mma)
index 040ccc8dc5b300b75fee4ffa28493cfc95a1d9b9..939b169b56f0093ca1be769413c32fa7dff3c7bd 100644 (file)
@@ -1,8 +1,6 @@
 noinst_LTLIBRARIES = libcompat.la
 
 libcompat_la_SOURCES = \
-       logging.c \
-       logging.h \
        mman.c \
        mman.h \
        uuid.c \
diff --git a/src/compat/logging.c b/src/compat/logging.c
deleted file mode 100644 (file)
index a79cc10..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2017 Michael Jeanson <mjeanson@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 bt_compat_log_level
-#include "logging/log.h"
-
-BT_LOG_INIT_LOG_LEVEL(bt_compat_log_level, "BABELTRACE_COMPAT_LOG_LEVEL");
diff --git a/src/compat/logging.h b/src/compat/logging.h
deleted file mode 100644 (file)
index ccb77a9..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef COMPAT_LOGGING_H
-#define COMPAT_LOGGING_H
-
-/*
- * Copyright (c) 2017 Michael Jeanson <mjeanson@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 bt_compat_log_level
-#include "logging/log.h"
-
-BT_LOG_LEVEL_EXTERN_SYMBOL(bt_compat_log_level);
-
-#endif /* COMPAT_LOGGING_H */
index edc59edabed37025722d231872cf573234221a63..de1d7b34a4d9bf5b07a39e0a7f28bb8fcd4922f3 100644 (file)
@@ -26,8 +26,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_OUTPUT_LEVEL (mapping->log_level)
 #define BT_LOG_TAG "COMPAT/MMAN"
-#include "logging.h"
+#include "logging/log.h"
 
 #include "common/macros.h"
 
@@ -52,6 +53,8 @@ int bt_mman_dummy_symbol;
 #include "compat/mman.h"
 
 struct mmap_mapping {
+       int log_level;
+
        /* The duplicated handle. */
        HANDLE file_handle;
        /* Handle returned by CreateFileMapping. */
@@ -102,13 +105,18 @@ void addr_clean(void *addr)
 {
        /* Cleanup of handles should never fail. */
        if (!UnmapViewOfFile(addr)) {
-               BT_LOGF_STR("Failed to unmap mmap mapping.");
+               /*
+                * FIXME: We don't have access to the mapping's log
+                * level here, so force a FATAL level.
+                */
+               BT_LOG_WRITE_CUR_LVL(BT_LOG_FATAL, BT_LOG_FATAL, BT_LOG_TAG,
+                       "Failed to unmap mmap mapping.");
                abort();
        }
 }
 
 static
-void mmap_lock(void)
+void mmap_lock(int log_level)
 {
        if (pthread_mutex_lock(&mmap_mutex)) {
                BT_LOGF_STR("Failed to acquire mmap_mutex.");
@@ -117,7 +125,7 @@ void mmap_lock(void)
 }
 
 static
-void mmap_unlock(void)
+void mmap_unlock(int log_level)
 {
        if (pthread_mutex_unlock(&mmap_mutex)) {
                BT_LOGF_STR("Failed to release mmap_mutex.");
@@ -163,7 +171,7 @@ DWORD map_prot_flags(int prot, DWORD *dwDesiredAccess)
 
 BT_HIDDEN
 void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
-               off_t offset)
+               off_t offset, int log_level)
 {
        struct mmap_mapping *mapping = NULL;
        void *mapping_addr;
@@ -191,9 +199,10 @@ void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
        }
 
        /* Allocate the mapping struct. */
-       mapping = mapping_create();
+       mapping = mapping_create(log_level);
        if (!mapping) {
-               BT_LOGE_STR("Failed to allocate mmap mapping.");
+               BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG,
+                       "Failed to allocate mmap mapping.");
                _set_errno(ENOMEM);
                goto error;
        }
@@ -233,7 +242,7 @@ void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
                goto error;
        }
 
-       mmap_lock();
+       mmap_lock(log_level);
 
        /* If we have never done any mappings, allocate the hashtable. */
        if (!mmap_mappings) {
@@ -250,12 +259,12 @@ void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
        /* Add the new mapping to the hashtable. */
        g_hash_table_insert(mmap_mappings, mapping_addr, mapping);
 
-       mmap_unlock();
+       mmap_unlock(log_level);
 
        return mapping_addr;
 
 error_mutex_unlock:
-       mmap_unlock();
+       mmap_unlock(log_level);
 error:
        mapping_clean(mapping);
        return MAP_FAILED;
@@ -265,8 +274,12 @@ BT_HIDDEN
 int bt_munmap(void *addr, size_t length)
 {
        int ret = 0;
+       struct mmap_mapping *mapping = addr;
+       int log_level;
 
-       mmap_lock();
+       BT_ASSERT(mapping);
+       log_level = mapping->log_level;
+       mmap_lock(log_level);
 
        /* Check if the mapping exists in the hashtable. */
        if (g_hash_table_lookup(mmap_mappings, addr) == NULL) {
@@ -282,7 +295,7 @@ int bt_munmap(void *addr, size_t length)
        }
 
 end:
-       mmap_unlock();
+       mmap_unlock(log_level);
        return ret;
 }
 
index 547a79217c9546215cc443e0c8aa8adc5d09d94b..1f60939a4b45a1b489160dd2cd4c417b157e31a6 100644 (file)
@@ -22,9 +22,6 @@
  * SOFTWARE.
  */
 
-#define BT_LOG_TAG "COMPAT/UUID"
-#include "logging.h"
-
 #ifdef __APPLE__
 /*
  * On macOS, we need a dummy symbol so that the linker won't
index e456dcfb316eba2039d209939d0a3d075707b1d1..c7540264e8fa838fb3076bf37655b2e2c82a11b5 100644 (file)
@@ -1026,7 +1026,8 @@ append_ids:
                goto end;
        }
 
-       ret = bt_ctfser_init(&stream->ctfser, file_path);
+       ret = bt_ctfser_init(&stream->ctfser, file_path,
+               BT_LOG_OUTPUT_LEVEL);
        g_free(file_path);
        if (ret) {
                /* bt_ctfser_init() logs errors */
index e6ae86f5b85b843514de56c8bc40dbf853d85987..c56e75cda1b2494097476f65eaf6fbfec4126fbb 100644 (file)
@@ -4,6 +4,4 @@ noinst_LTLIBRARIES = libbabeltrace2-ctfser.la
 
 libbabeltrace2_ctfser_la_SOURCES = \
        ctfser.c \
-       ctfser.h \
-       logging.c \
-       logging.h
+       ctfser.h
index 6043db32b80b83280598c90a8c5ee0d205712cc7..b28845cf8f5649bad43d69f7a4d87ea98e9faf0a 100644 (file)
@@ -20,8 +20,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_OUTPUT_LEVEL (ctfser->log_level)
 #define BT_LOG_TAG "CTFSER"
-#include "logging.h"
+#include "logging/log.h"
 
 #include <unistd.h>
 #include <string.h>
@@ -44,9 +45,9 @@
 #include "compat/fcntl.h"
 
 static inline
-uint64_t get_packet_size_increment_bytes(void)
+uint64_t get_packet_size_increment_bytes(struct bt_ctfser *ctfser)
 {
-       return bt_common_get_page_size() * 8;
+       return bt_common_get_page_size(ctfser->log_level) * 8;
 }
 
 static inline
@@ -54,7 +55,7 @@ void mmap_align_ctfser(struct bt_ctfser *ctfser)
 {
        ctfser->base_mma = mmap_align(ctfser->cur_packet_size_bytes,
                PROT_READ | PROT_WRITE,
-               MAP_SHARED, ctfser->fd, ctfser->mmap_offset);
+               MAP_SHARED, ctfser->fd, ctfser->mmap_offset, ctfser->log_level);
 }
 
 BT_HIDDEN
@@ -77,7 +78,8 @@ int _bt_ctfser_increase_cur_packet_size(struct bt_ctfser *ctfser)
                goto end;
        }
 
-       ctfser->cur_packet_size_bytes += get_packet_size_increment_bytes();
+       ctfser->cur_packet_size_bytes += get_packet_size_increment_bytes(
+               ctfser);
 
        do {
                ret = bt_posix_fallocate(ctfser->fd, ctfser->mmap_offset,
@@ -110,7 +112,7 @@ end:
 }
 
 BT_HIDDEN
-int bt_ctfser_init(struct bt_ctfser *ctfser, const char *path)
+int bt_ctfser_init(struct bt_ctfser *ctfser, const char *path, int log_level)
 {
        int ret = 0;
 
@@ -118,6 +120,7 @@ int bt_ctfser_init(struct bt_ctfser *ctfser, const char *path)
        memset(ctfser, 0, sizeof(*ctfser));
        ctfser->fd = open(path, O_RDWR | O_CREAT | O_TRUNC,
                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+       ctfser->log_level = log_level;
        if (ctfser->fd < 0) {
                BT_LOGW_ERRNO("Failed to open stream file for writing",
                        ": path=\"%s\", ret=%d",
@@ -220,7 +223,8 @@ int bt_ctfser_open_packet(struct bt_ctfser *ctfser)
        ctfser->prev_packet_size_bytes = 0;
 
        /* Make initial space for the current packet */
-       ctfser->cur_packet_size_bytes = get_packet_size_increment_bytes();
+       ctfser->cur_packet_size_bytes = get_packet_size_increment_bytes(
+               ctfser);
 
        do {
                ret = bt_posix_fallocate(ctfser->fd, ctfser->mmap_offset,
index c59af924152bd5e704c66b9ebe6cc80f09ce773d..f8bbfae2de70558b3fd90686148759e331c4206b 100644 (file)
@@ -72,6 +72,9 @@ struct bt_ctfser {
 
        /* Stream file's path (for debugging) */
        GString *path;
+
+       /* Serializer's log level */
+       int log_level;
 };
 
 /*
@@ -80,7 +83,8 @@ struct bt_ctfser {
  * This function opens the file `path` for writing.
  */
 BT_HIDDEN
-int bt_ctfser_init(struct bt_ctfser *ctfser, const char *path);
+int bt_ctfser_init(struct bt_ctfser *ctfser, const char *path,
+               int log_level);
 
 /*
  * Finalizes a CTF serializer.
diff --git a/src/ctfser/logging.c b/src/ctfser/logging.c
deleted file mode 100644 (file)
index 779078d..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 bt_ctfser_log_level
-#include "logging/log.h"
-
-BT_LOG_INIT_LOG_LEVEL(bt_ctfser_log_level, "BABELTRACE_CTFSER_LOG_LEVEL");
diff --git a/src/ctfser/logging.h b/src/ctfser/logging.h
deleted file mode 100644 (file)
index 547f1ac..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef COMMON_LOGGING_H
-#define COMMON_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 bt_ctfser_log_level
-#include "logging/log.h"
-
-BT_LOG_LEVEL_EXTERN_SYMBOL(bt_ctfser_log_level);
-
-#endif /* COMMON_LOGGING_H */
index c4a128825c7bed5d9fcd1ec8f1617a6b7eed700b..804a1a17ea07982775a864434416413bdb8a45db 100644 (file)
@@ -4,6 +4,4 @@ noinst_LTLIBRARIES = libbabeltrace2-fd-cache.la
 
 libbabeltrace2_fd_cache_la_SOURCES = \
        fd-cache.c \
-       fd-cache.h \
-       logging.c \
-       logging.h
+       fd-cache.h
index cb1472b9a84347ebfcffec000dddd7b0c8f772d0..9a742a4515028a554969ba7aec04d9b0ae2cdb10 100644 (file)
@@ -26,8 +26,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_OUTPUT_LEVEL (fdc->log_level)
 #define BT_LOG_TAG "FD-CACHE"
-#include "logging.h"
+#include "logging/log.h"
 
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -102,10 +103,11 @@ void file_key_destroy(gpointer data)
 }
 
 BT_HIDDEN
-int bt_fd_cache_init(struct bt_fd_cache *fdc)
+int bt_fd_cache_init(struct bt_fd_cache *fdc, int log_level)
 {
        int ret = 0;
 
+       fdc->log_level = log_level;
        fdc->cache = g_hash_table_new_full(file_key_hash, file_key_equal,
                file_key_destroy, (GDestroyNotify) fd_cache_handle_internal_destroy);
        if (!fdc->cache) {
index 977aaf4d1610ad9753a2a3b574d38c284794a44c..7a935b8f75bffc253b43571981f63fb4d24fd5a9 100644 (file)
@@ -35,6 +35,7 @@ struct bt_fd_cache_handle {
 };
 
 struct bt_fd_cache {
+       int log_level;
        GHashTable *cache;
 };
 
@@ -45,7 +46,7 @@ int bt_fd_cache_handle_get_fd(struct bt_fd_cache_handle *handle)
 }
 
 BT_HIDDEN
-int bt_fd_cache_init(struct bt_fd_cache *fdc);
+int bt_fd_cache_init(struct bt_fd_cache *fdc, int log_level);
 
 BT_HIDDEN
 void bt_fd_cache_fini(struct bt_fd_cache *fdc);
diff --git a/src/fd-cache/logging.c b/src/fd-cache/logging.c
deleted file mode 100644 (file)
index 875f3ba..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@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 bt_fd_cache_log_level
-#include "logging/log.h"
-
-BT_LOG_INIT_LOG_LEVEL(bt_fd_cache_log_level, "BABELTRACE_FD_CACHE_LOG_LEVEL");
diff --git a/src/fd-cache/logging.h b/src/fd-cache/logging.h
deleted file mode 100644 (file)
index 89a783b..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef FD_CACHE_LOGGING_H
-#define FD_CACHE_LOGGING_H
-
-/*
- * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@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 bt_fd_cache_log_level
-#include "logging/log.h"
-
-BT_LOG_LEVEL_EXTERN_SYMBOL(bt_fd_cache_log_level);
-
-#endif /* FD_CACHE_LOGGING_H */
index 30c10ed2af272011f35df1ab93b95258071bd9ac..9459438662b9e5ad9a1bd9042c2b42dc4cc79a2a 100644 (file)
@@ -214,7 +214,7 @@ const struct bt_plugin *bt_plugin_find(const char *plugin_name)
                }
        }
 
-       home_plugin_dir = bt_common_get_home_plugin_path();
+       home_plugin_dir = bt_common_get_home_plugin_path(BT_LOG_OUTPUT_LEVEL);
        if (home_plugin_dir) {
                GString *home_plugin_dir_str =
                        g_string_new(home_plugin_dir);
index 41098dc796341087e72e90e69f5a0819593a2244..52da0acfc93c25cf465e157a4c7b3cdc5b898aa3 100644 (file)
@@ -168,7 +168,7 @@ struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
 
        set_stream_file_name(stream);
        g_string_append_printf(path, "/%s", stream->file_name->str);
-       ret = bt_ctfser_init(&stream->ctfser, path->str);
+       ret = bt_ctfser_init(&stream->ctfser, path->str, BT_LOG_OUTPUT_LEVEL);
        if (ret) {
                goto error;
        }
index 1a451925e55e8117cd5da0173692a62ce88489ed..c3ae979c53e67b3364b2d23ce3497ed173ac1fae 100644 (file)
@@ -222,7 +222,8 @@ enum bt_msg_iter_medium_status medop_seek(enum bt_msg_iter_seek_whence whence,
        if (ds_file->mmap_addr && (offset < ds_file->mmap_offset ||
                        offset >= ds_file->mmap_offset + ds_file->mmap_len)) {
                int unmap_ret;
-               off_t offset_in_mapping = offset % bt_common_get_page_size();
+               off_t offset_in_mapping = offset %
+                       bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL);
 
                BT_LOGD("Medium seek request cannot be accomodated by the current "
                                "file mapping: offset=%jd, mmap-offset=%jd, "
@@ -608,7 +609,7 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create(
                bt_stream *stream, const char *path)
 {
        int ret;
-       const size_t page_size = bt_common_get_page_size();
+       const size_t page_size = bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL);
        struct ctf_fs_ds_file *ds_file = g_new0(struct ctf_fs_ds_file, 1);
 
        if (!ds_file) {
index d0a729b6d214cbc2a0074d8bf5f6370b62660c91..4530248d52745be8276b7b5b581713d011e64489 100644 (file)
@@ -260,7 +260,7 @@ bt_self_message_iterator_status ctf_fs_iterator_init(
        msg_iter_data->pc_msg_iter = self_msg_iter;
        msg_iter_data->msg_iter = bt_msg_iter_create(
                port_data->ds_file_group->ctf_fs_trace->metadata->tc,
-               bt_common_get_page_size() * 8,
+               bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL) * 8,
                ctf_fs_ds_file_medops, NULL);
        if (!msg_iter_data->msg_iter) {
                BT_LOGE_STR("Cannot create a CTF message iterator.");
@@ -721,7 +721,8 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace,
        struct bt_msg_iter_packet_properties props;
 
        msg_iter = bt_msg_iter_create(ctf_fs_trace->metadata->tc,
-               bt_common_get_page_size() * 8, ctf_fs_ds_file_medops, NULL);
+               bt_common_get_page_size(BT_LOG_OUTPUT_LEVEL) * 8,
+               ctf_fs_ds_file_medops, NULL);
        if (!msg_iter) {
                BT_LOGE_STR("Cannot create a CTF message iterator.");
                goto error;
index 8fee09ab2ffee4ca1576516bd57d55b377019197..9f6f0968953e7eb815d90012e6379b24b0eada27 100644 (file)
@@ -1995,7 +1995,8 @@ bt_self_message_iterator_status debug_info_msg_iter_init(
                goto error;
        }
 
-       ret = bt_fd_cache_init(&debug_info_msg_iter->fd_cache);
+       ret = bt_fd_cache_init(&debug_info_msg_iter->fd_cache,
+               BT_LOG_OUTPUT_LEVEL);
        if (ret) {
                status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
                goto error;
index d681ef5621abc948c00b6d6266fda030a7c9e4e2..c55201c116f389841bef0fc0db32d53b4ea1f093 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#define BT_LOG_OUTPUT_LEVEL BT_LOG_WARN
+#define BT_LOG_TAG "TEST/BIN-INFO"
+#include "logging/log.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -223,7 +227,7 @@ void test_bin_info_build_id(const char *bin_info_dir)
                exit(EXIT_FAILURE);
        }
 
-       ret = bt_fd_cache_init(&fdc);
+       ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL);
        if (ret != 0) {
                diag("Failed to initialize FD cache");
                exit(EXIT_FAILURE);
@@ -277,7 +281,7 @@ void test_bin_info_debug_link(const char *bin_info_dir)
                exit(EXIT_FAILURE);
        }
 
-       ret = bt_fd_cache_init(&fdc);
+       ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL);
        if (ret != 0) {
                diag("Failed to initialize FD cache");
                exit(EXIT_FAILURE);
@@ -327,7 +331,7 @@ void test_bin_info_elf(const char *bin_info_dir)
                exit(EXIT_FAILURE);
        }
 
-       ret = bt_fd_cache_init(&fdc);
+       ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL);
        if (ret != 0) {
                diag("Failed to initialize FD cache");
                exit(EXIT_FAILURE);
@@ -375,7 +379,7 @@ void test_bin_info_bundled(const char *bin_info_dir)
                exit(EXIT_FAILURE);
        }
 
-       ret = bt_fd_cache_init(&fdc);
+       ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL);
        if (ret != 0) {
                diag("Failed to initialize FD cache");
                exit(EXIT_FAILURE);
This page took 0.043099 seconds and 4 git commands to generate.