sink.ctf.fs: honor component's initial log level
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 18 Jun 2019 17:24:33 +0000 (13:24 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 20 Jun 2019 18:01:16 +0000 (14:01 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5381ab04b9f2e3611c5f08006896a30e63451635
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1496
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
13 files changed:
src/cli/babeltrace2.c
src/plugins/ctf/fs-sink/Makefile.am
src/plugins/ctf/fs-sink/fs-sink-stream.c
src/plugins/ctf/fs-sink/fs-sink-stream.h
src/plugins/ctf/fs-sink/fs-sink-trace.c
src/plugins/ctf/fs-sink/fs-sink-trace.h
src/plugins/ctf/fs-sink/fs-sink.c
src/plugins/ctf/fs-sink/fs-sink.h
src/plugins/ctf/fs-sink/logging.c [deleted file]
src/plugins/ctf/fs-sink/logging.h [deleted file]
src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c
src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c
src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.h

index 01dc9d7f5cb98acc758748f06867a50a2f56828e..d3cabdc920be1e079e92dce1993bf440c05bbb31 100644 (file)
@@ -51,7 +51,6 @@
 static const char* log_level_env_var_names[] = {
        "BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL",
        "BABELTRACE_PYTHON_BT2_LOG_LEVEL",
-       "BABELTRACE_SINK_CTF_FS_LOG_LEVEL",
        "BABELTRACE_SINK_TEXT_DETAILS_LOG_LEVEL",
        "BABELTRACE_SRC_CTF_FS_LOG_LEVEL",
        NULL,
index 6035b1a1acfaa5e7b2fc05c756390e1b533d8c70..03d91643b42f28c72d80ae9dd895f38f9fe2bc75 100644 (file)
@@ -4,8 +4,6 @@ libbabeltrace2_plugin_ctf_fs_sink_la_LIBADD =
 libbabeltrace2_plugin_ctf_fs_sink_la_SOURCES = \
        fs-sink.c \
        fs-sink.h \
-       logging.c \
-       logging.h \
        fs-sink-ctf-meta.h \
        translate-trace-ir-to-ctf-ir.c \
        translate-trace-ir-to-ctf-ir.h \
index 52da0acfc93c25cf465e157a4c7b3cdc5b898aa3..a8fd554733b654f1ebf5cd11ff3079245e73a38b 100644 (file)
@@ -20,8 +20,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_OUTPUT_LEVEL (stream->log_level)
 #define BT_LOG_TAG "PLUGIN/SINK.CTF.FS/STREAM"
-#include "logging.h"
+#include "logging/log.h"
 
 #include <babeltrace2/babeltrace.h>
 #include <stdio.h>
@@ -153,6 +154,7 @@ struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
                goto end;
        }
 
+       stream->log_level = trace->log_level;
        stream->trace = trace;
        stream->ir_stream = ir_stream;
        stream->packet_state.beginning_cs = UINT64_C(-1);
@@ -161,14 +163,16 @@ struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
        stream->prev_packet_state.discarded_events_counter = UINT64_C(-1);
        stream->prev_packet_state.seq_num = UINT64_C(-1);
        ret = try_translate_stream_class_trace_ir_to_ctf_ir(trace->tc,
-               bt_stream_borrow_class_const(ir_stream), &stream->sc);
+               bt_stream_borrow_class_const(ir_stream), &stream->sc,
+               stream->log_level);
        if (ret) {
                goto error;
        }
 
        set_stream_file_name(stream);
        g_string_append_printf(path, "/%s", stream->file_name->str);
-       ret = bt_ctfser_init(&stream->ctfser, path->str, BT_LOG_OUTPUT_LEVEL);
+       ret = bt_ctfser_init(&stream->ctfser, path->str,
+               stream->log_level);
        if (ret) {
                goto error;
        }
index adefbb20db3769f253b49a87dea93799a6c8d1b5..e3d7ba5eb1f02a86dbc8399f95ee24710e3d9a5b 100644 (file)
@@ -35,6 +35,7 @@
 struct fs_sink_trace;
 
 struct fs_sink_stream {
+       bt_logging_level log_level;
        struct fs_sink_trace *trace;
        struct bt_ctfser ctfser;
 
index 7ff928083d54164b48eca7167fe60749d6a92b2e..e235820fdad2526801609c315d38c83f32e0f94d 100644 (file)
@@ -20,8 +20,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_OUTPUT_LEVEL (trace->log_level)
 #define BT_LOG_TAG "PLUGIN/SINK.CTF.FS/TRACE"
-#include "logging.h"
+#include "logging/log.h"
 
 #include <babeltrace2/babeltrace.h>
 #include <stdio.h>
@@ -137,7 +138,8 @@ GString *make_unique_trace_path(const char *path)
  */
 
 static
-int lttng_validate_datetime(const char *datetime)
+int lttng_validate_datetime(const struct fs_sink_trace *trace,
+               const char *datetime)
 {
        GTimeVal tv;
        int ret = -1;
@@ -160,7 +162,8 @@ end:
 }
 
 static
-int append_lttng_trace_path_ust_uid(GString *path, const bt_trace_class *tc)
+int append_lttng_trace_path_ust_uid(const struct fs_sink_trace *trace,
+               GString *path, const bt_trace_class *tc)
 {
        const bt_value *v;
        int ret;
@@ -194,7 +197,8 @@ end:
 }
 
 static
-int append_lttng_trace_path_ust_pid(GString *path, const bt_trace_class *tc)
+int append_lttng_trace_path_ust_pid(const struct fs_sink_trace *trace,
+               GString *path, const bt_trace_class *tc)
 {
        const bt_value *v;
        const char *datetime;
@@ -224,7 +228,7 @@ int append_lttng_trace_path_ust_pid(GString *path, const bt_trace_class *tc)
 
        datetime = bt_value_string_get(v);
 
-       if (lttng_validate_datetime(datetime)) {
+       if (lttng_validate_datetime(trace, datetime)) {
                goto error;
        }
 
@@ -320,7 +324,7 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
 
        datetime = bt_value_string_get(v);
 
-       if (lttng_validate_datetime(datetime)) {
+       if (lttng_validate_datetime(trace, datetime)) {
                goto error;
        }
 
@@ -348,11 +352,11 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
                g_string_append_printf(path, G_DIR_SEPARATOR_S "%s", tracer_buffering_scheme);
 
                if (g_str_equal(tracer_buffering_scheme, "uid")) {
-                       if (append_lttng_trace_path_ust_uid(path, tc)) {
+                       if (append_lttng_trace_path_ust_uid(trace, path, tc)) {
                                goto error;
                        }
                } else if (g_str_equal(tracer_buffering_scheme, "pid")){
-                       if (append_lttng_trace_path_ust_pid(path, tc)) {
+                       if (append_lttng_trace_path_ust_pid(trace, path, tc)) {
                                goto error;
                        }
                } else {
@@ -567,11 +571,13 @@ struct fs_sink_trace *fs_sink_trace_create(struct fs_sink_comp *fs_sink,
                goto end;
        }
 
+       trace->log_level = fs_sink->log_level;
        trace->fs_sink = fs_sink;
        trace->ir_trace = ir_trace;
        trace->ir_trace_destruction_listener_id = UINT64_C(-1);
        trace->tc = translate_trace_class_trace_ir_to_ctf_ir(
-               bt_trace_borrow_class_const(ir_trace));
+               bt_trace_borrow_class_const(ir_trace),
+               fs_sink->log_level);
        if (!trace->tc) {
                goto error;
        }
index f60cad93aef5743a76da46fc63a6defb44292157..9ca03d1bcf11caecf4af41b43895fd580ef8c7c5 100644 (file)
@@ -35,6 +35,7 @@
 struct fs_sink_comp;
 
 struct fs_sink_trace {
+       bt_logging_level log_level;
        struct fs_sink_comp *fs_sink;
 
        /* Owned by this */
index 0e839dd9f4163c6f4200b6bce2b08da1f324f82f..f6b5bab41f8d8afb9f59f46f930627aa0e61853d 100644 (file)
@@ -20,8 +20,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_OUTPUT_LEVEL (fs_sink->log_level)
 #define BT_LOG_TAG "PLUGIN/SINK.CTF.FS"
-#include "logging.h"
+#include "logging/log.h"
 
 #include <babeltrace2/babeltrace.h>
 #include <stdio.h>
@@ -163,21 +164,27 @@ end:
 
 BT_HIDDEN
 bt_self_component_status ctf_fs_sink_init(
-               bt_self_component_sink *self_comp, const bt_value *params,
+               bt_self_component_sink *self_comp_sink, const bt_value *params,
                void *init_method_data)
 {
        bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
        struct fs_sink_comp *fs_sink = NULL;
+       bt_self_component *self_comp =
+               bt_self_component_sink_as_self_component(self_comp_sink);
+       bt_logging_level log_level = bt_component_get_logging_level(
+               bt_self_component_as_component(self_comp));
 
        fs_sink = g_new0(struct fs_sink_comp, 1);
        if (!fs_sink) {
-               BT_LOGE_STR("Failed to allocate one CTF FS sink structure.");
+               BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG,
+                       "Failed to allocate one CTF FS sink structure.");
                status = BT_SELF_COMPONENT_STATUS_NOMEM;
                goto end;
        }
 
+       fs_sink->log_level = log_level;
        fs_sink->output_dir_path = g_string_new(NULL);
-       fs_sink->self_comp = self_comp;
+       fs_sink->self_comp = self_comp_sink;
        status = configure_component(fs_sink, params);
        if (status != BT_SELF_COMPONENT_STATUS_OK) {
                /* configure_component() logs errors */
@@ -207,14 +214,13 @@ bt_self_component_status ctf_fs_sink_init(
                goto end;
        }
 
-       status = bt_self_component_sink_add_input_port(self_comp, in_port_name,
-               NULL, NULL);
+       status = bt_self_component_sink_add_input_port(self_comp_sink,
+               in_port_name, NULL, NULL);
        if (status != BT_SELF_COMPONENT_STATUS_OK) {
                goto end;
        }
 
-       bt_self_component_set_data(
-               bt_self_component_sink_as_self_component(self_comp), fs_sink);
+       bt_self_component_set_data(self_comp, fs_sink);
 
 end:
        if (status != BT_SELF_COMPONENT_STATUS_OK) {
@@ -279,7 +285,8 @@ bt_self_component_status handle_event_msg(struct fs_sink_comp *fs_sink,
        }
 
        ret = try_translate_event_class_trace_ir_to_ctf_ir(stream->sc,
-               bt_event_borrow_class_const(ir_event), &ec);
+               bt_event_borrow_class_const(ir_event), &ec,
+               fs_sink->log_level);
        if (ret) {
                status = BT_SELF_COMPONENT_STATUS_ERROR;
                goto end;
index d4255aefb9076094b1df78fd9280f552c856cf27..ccdf3b3c7482c0685c50890ef44abbea71c8d8f3 100644 (file)
@@ -29,6 +29,7 @@
 #include <glib.h>
 
 struct fs_sink_comp {
+       bt_logging_level log_level;
        bt_self_component_sink *self_comp;
 
        /* Owned by this */
diff --git a/src/plugins/ctf/fs-sink/logging.c b/src/plugins/ctf/fs-sink/logging.c
deleted file mode 100644 (file)
index 0469b7a..0000000
+++ /dev/null
@@ -1,27 +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_plugin_fs_sink_log_level
-#include "logging/log.h"
-
-BT_LOG_INIT_LOG_LEVEL(bt_plugin_fs_sink_log_level,
-       "BABELTRACE_SINK_CTF_FS_LOG_LEVEL");
diff --git a/src/plugins/ctf/fs-sink/logging.h b/src/plugins/ctf/fs-sink/logging.h
deleted file mode 100644 (file)
index a6c9dd4..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef PLUGINS_FS_SINK_LOGGING_H
-#define PLUGINS_FS_SINK_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_plugin_fs_sink_log_level
-#include "logging/log.h"
-
-BT_LOG_LEVEL_EXTERN_SYMBOL(bt_plugin_fs_sink_log_level);
-
-#endif /* PLUGINS_FS_SINK_LOGGING_H */
index ec6de88d9d5a2ce8ea7131b9946df34b2f25b972..4c0653a988024f94d7e49c0a3bebc6b862968dfe 100644 (file)
@@ -20,9 +20,6 @@
  * SOFTWARE.
  */
 
-#define BT_LOG_TAG "PLUGIN/SINK.CTF.FS/TRANSLATE-CTF-IR-TO-TSDL"
-#include "logging.h"
-
 #include <babeltrace2/babeltrace.h>
 #include "common/macros.h"
 #include <stdio.h>
index 7bd9423b032790cba022387a180ab4b22cf6bca8..a4f9761de76f6c7e5c0e87f868794ebb85a7d093 100644 (file)
@@ -20,8 +20,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_OUTPUT_LEVEL (ctx->log_level)
 #define BT_LOG_TAG "PLUGIN/SINK.CTF.FS/TRANSLATE-TRACE-IR-TO-CTF-IR"
-#include "logging.h"
+#include "logging/log.h"
 
 #include <babeltrace2/babeltrace.h>
 #include "common/macros.h"
@@ -46,6 +47,8 @@ struct field_path_elem {
 };
 
 struct ctx {
+       bt_logging_level log_level;
+
        /* Weak */
        struct fs_sink_ctf_stream_class *cur_sc;
 
@@ -1027,12 +1030,13 @@ end:
 }
 
 static inline
-void ctx_init(struct ctx *ctx)
+void ctx_init(struct ctx *ctx, bt_logging_level log_level)
 {
        memset(ctx, 0, sizeof(struct ctx));
        ctx->cur_path = g_array_new(FALSE, TRUE,
                sizeof(struct field_path_elem));
        BT_ASSERT(ctx->cur_path);
+       ctx->log_level = log_level;
 }
 
 static inline
@@ -1047,7 +1051,8 @@ void ctx_fini(struct ctx *ctx)
 static
 int translate_event_class(struct fs_sink_ctf_stream_class *sc,
                const bt_event_class *ir_ec,
-               struct fs_sink_ctf_event_class **out_ec)
+               struct fs_sink_ctf_event_class **out_ec,
+               bt_logging_level log_level)
 {
        int ret = 0;
        struct ctx ctx;
@@ -1056,7 +1061,7 @@ int translate_event_class(struct fs_sink_ctf_stream_class *sc,
        BT_ASSERT(sc);
        BT_ASSERT(ir_ec);
 
-       ctx_init(&ctx);
+       ctx_init(&ctx, log_level);
        ec = fs_sink_ctf_event_class_create(sc, ir_ec);
        BT_ASSERT(ec);
        ctx.cur_sc = sc;
@@ -1086,7 +1091,8 @@ BT_HIDDEN
 int try_translate_event_class_trace_ir_to_ctf_ir(
                struct fs_sink_ctf_stream_class *sc,
                const bt_event_class *ir_ec,
-               struct fs_sink_ctf_event_class **out_ec)
+               struct fs_sink_ctf_event_class **out_ec,
+               bt_logging_level log_level)
 {
        int ret = 0;
 
@@ -1099,7 +1105,7 @@ int try_translate_event_class_trace_ir_to_ctf_ir(
                goto end;
        }
 
-       ret = translate_event_class(sc, ir_ec, out_ec);
+       ret = translate_event_class(sc, ir_ec, out_ec, log_level);
 
 end:
        return ret;
@@ -1150,14 +1156,15 @@ void make_unique_default_clock_class_name(struct fs_sink_ctf_stream_class *sc)
 static
 int translate_stream_class(struct fs_sink_ctf_trace_class *tc,
                const bt_stream_class *ir_sc,
-               struct fs_sink_ctf_stream_class **out_sc)
+               struct fs_sink_ctf_stream_class **out_sc,
+               bt_logging_level log_level)
 {
        int ret = 0;
        struct ctx ctx;
 
        BT_ASSERT(tc);
        BT_ASSERT(ir_sc);
-       ctx_init(&ctx);
+       ctx_init(&ctx, log_level);
        *out_sc = fs_sink_ctf_stream_class_create(tc, ir_sc);
        BT_ASSERT(*out_sc);
 
@@ -1224,7 +1231,8 @@ BT_HIDDEN
 int try_translate_stream_class_trace_ir_to_ctf_ir(
                struct fs_sink_ctf_trace_class *tc,
                const bt_stream_class *ir_sc,
-               struct fs_sink_ctf_stream_class **out_sc)
+               struct fs_sink_ctf_stream_class **out_sc,
+               bt_logging_level log_level)
 {
        int ret = 0;
        uint64_t i;
@@ -1240,7 +1248,7 @@ int try_translate_stream_class_trace_ir_to_ctf_ir(
                }
        }
 
-       ret = translate_stream_class(tc, ir_sc, out_sc);
+       ret = translate_stream_class(tc, ir_sc, out_sc, log_level);
 
 end:
        return ret;
@@ -1248,7 +1256,7 @@ end:
 
 BT_HIDDEN
 struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
-               const bt_trace_class *ir_tc)
+               const bt_trace_class *ir_tc, bt_logging_level log_level)
 {
        uint64_t count;
        uint64_t i;
@@ -1264,7 +1272,9 @@ struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
                        ir_tc, i, &name, &val);
 
                if (!fs_sink_ctf_ist_valid_identifier(name)) {
-                       BT_LOGE("Unsupported trace class's environment entry name: "
+                       BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level,
+                               BT_LOG_TAG,
+                               "Unsupported trace class's environment entry name: "
                                "name=\"%s\"", name);
                        goto end;
                }
@@ -1274,7 +1284,9 @@ struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
                case BT_VALUE_TYPE_STRING:
                        break;
                default:
-                       BT_LOGE("Unsupported trace class's environment entry value type: "
+                       BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level,
+                               BT_LOG_TAG,
+                               "Unsupported trace class's environment entry value type: "
                                "type=%s",
                                bt_common_value_type_string(
                                        bt_value_get_type(val)));
index 23a9e2b537b1a047862bedbf68d7a2cee8f22f2b..8abba50f38190a2eebd33136d625003f2fa39be9 100644 (file)
@@ -32,16 +32,18 @@ BT_HIDDEN
 int try_translate_event_class_trace_ir_to_ctf_ir(
                struct fs_sink_ctf_stream_class *sc,
                const bt_event_class *ir_ec,
-               struct fs_sink_ctf_event_class **out_ec);
+               struct fs_sink_ctf_event_class **out_ec,
+               bt_logging_level log_level);
 
 BT_HIDDEN
 int try_translate_stream_class_trace_ir_to_ctf_ir(
                struct fs_sink_ctf_trace_class *tc,
                const bt_stream_class *ir_sc,
-               struct fs_sink_ctf_stream_class **out_sc);
+               struct fs_sink_ctf_stream_class **out_sc,
+               bt_logging_level log_level);
 
 BT_HIDDEN
 struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
-               const bt_trace_class *ir_tc);
+               const bt_trace_class *ir_tc, bt_logging_level log_level);
 
 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_TRANSLATE_TRACE_IR_TO_CTF_IR_H */
This page took 0.033489 seconds and 4 git commands to generate.