From c01594dea908eeacf22c4d8bf5c4e629792a91d5 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 18 Jun 2019 01:22:38 -0400 Subject: [PATCH] src.ctf.lttng-live: honor component's initial log level and query LL Except for `viewer-connection.c` which is pretty consistent in having a named "viewer connection" instance in each function, the other files deal with too many objects/concepts to have a systematic expression to identify the log level, so they use local `log_level` variables. Signed-off-by: Philippe Proulx Change-Id: I102408375d4d3d2df21c756b6581c642ece77ff1 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1494 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- src/cli/babeltrace2.c | 1 - src/plugins/ctf/lttng-live/Makefile.am | 4 +- src/plugins/ctf/lttng-live/data-stream.c | 12 +++-- src/plugins/ctf/lttng-live/logging.c | 26 ---------- src/plugins/ctf/lttng-live/logging.h | 31 ------------ src/plugins/ctf/lttng-live/lttng-live.c | 47 ++++++++++++++----- src/plugins/ctf/lttng-live/lttng-live.h | 12 +++++ src/plugins/ctf/lttng-live/metadata.c | 12 +++-- .../ctf/lttng-live/viewer-connection.c | 13 +++-- .../ctf/lttng-live/viewer-connection.h | 9 +++- 10 files changed, 80 insertions(+), 87 deletions(-) delete mode 100644 src/plugins/ctf/lttng-live/logging.c delete mode 100644 src/plugins/ctf/lttng-live/logging.h diff --git a/src/cli/babeltrace2.c b/src/cli/babeltrace2.c index fed54d9b..01dc9d7f 100644 --- a/src/cli/babeltrace2.c +++ b/src/cli/babeltrace2.c @@ -54,7 +54,6 @@ static const char* log_level_env_var_names[] = { "BABELTRACE_SINK_CTF_FS_LOG_LEVEL", "BABELTRACE_SINK_TEXT_DETAILS_LOG_LEVEL", "BABELTRACE_SRC_CTF_FS_LOG_LEVEL", - "BABELTRACE_SRC_CTF_LTTNG_LIVE_LOG_LEVEL", NULL, }; diff --git a/src/plugins/ctf/lttng-live/Makefile.am b/src/plugins/ctf/lttng-live/Makefile.am index 853f47d6..f22e6b70 100644 --- a/src/plugins/ctf/lttng-live/Makefile.am +++ b/src/plugins/ctf/lttng-live/Makefile.am @@ -7,9 +7,7 @@ libbabeltrace2_plugin_ctf_lttng_live_la_SOURCES = \ metadata.h \ viewer-connection.c \ viewer-connection.h \ - lttng-viewer-abi.h \ - logging.c \ - logging.h + lttng-viewer-abi.h if BABELTRACE_BUILD_WITH_MINGW libbabeltrace2_plugin_ctf_lttng_live_la_LIBADD = -lws2_32 diff --git a/src/plugins/ctf/lttng-live/data-stream.c b/src/plugins/ctf/lttng-live/data-stream.c index 7d3abaae..7e7250ba 100644 --- a/src/plugins/ctf/lttng-live/data-stream.c +++ b/src/plugins/ctf/lttng-live/data-stream.c @@ -23,8 +23,9 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL log_level #define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/DS" -#include "logging.h" +#include "logging/log.h" #include #include @@ -78,6 +79,7 @@ bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t stream_id, void *data) { struct lttng_live_stream_iterator *lttng_live_stream = data; + bt_logging_level log_level = lttng_live_stream->log_level; if (!lttng_live_stream->stream) { uint64_t stream_class_id = bt_stream_class_get_id(stream_class); @@ -128,6 +130,7 @@ enum lttng_live_iterator_status lttng_live_lazy_msg_init( struct lttng_live_component *lttng_live = session->lttng_live_msg_iter->lttng_live_comp; uint64_t trace_idx, stream_iter_idx; + bt_logging_level log_level = session->log_level; if (!session->lazy_stream_msg_init) { return LTTNG_LIVE_ITERATOR_STATUS_OK; @@ -152,7 +155,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, BT_LOG_OUTPUT_LEVEL); + stream_iter, log_level); if (!stream_iter->msg_iter) { goto error; } @@ -176,10 +179,12 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( struct lttng_live_stream_iterator *stream_iter; struct lttng_live_component *lttng_live; struct lttng_live_trace *trace; + bt_logging_level log_level; BT_ASSERT(session); BT_ASSERT(session->lttng_live_msg_iter); BT_ASSERT(session->lttng_live_msg_iter->lttng_live_comp); + log_level = session->log_level; lttng_live = session->lttng_live_msg_iter->lttng_live_comp; @@ -188,6 +193,7 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( goto error; } + stream_iter->log_level = log_level; trace = lttng_live_borrow_trace(session, ctf_trace_id); if (!trace) { goto error; @@ -206,7 +212,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, BT_LOG_OUTPUT_LEVEL); + stream_iter, log_level); if (!stream_iter->msg_iter) { goto error; } diff --git a/src/plugins/ctf/lttng-live/logging.c b/src/plugins/ctf/lttng-live/logging.c deleted file mode 100644 index 98f1b639..00000000 --- a/src/plugins/ctf/lttng-live/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 lttng_live_log_level -#include "logging/log.h" - -BT_LOG_INIT_LOG_LEVEL(lttng_live_log_level, "BABELTRACE_SRC_CTF_LTTNG_LIVE_LOG_LEVEL"); diff --git a/src/plugins/ctf/lttng-live/logging.h b/src/plugins/ctf/lttng-live/logging.h deleted file mode 100644 index de11a5ed..00000000 --- a/src/plugins/ctf/lttng-live/logging.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef LTTNG_LIVE_LOGGING_H -#define LTTNG_LIVE_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 lttng_live_log_level -#include "logging/log.h" - -BT_LOG_LEVEL_EXTERN_SYMBOL(lttng_live_log_level); - -#endif /* LTTNG_LIVE_LOGGING_H */ diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index 65febbe3..c15247d3 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -28,8 +28,9 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL log_level #define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE" -#include "logging.h" +#include "logging/log.h" #include #include @@ -150,6 +151,8 @@ end: static void lttng_live_destroy_trace(struct lttng_live_trace *trace) { + bt_logging_level log_level = trace->log_level; + BT_LOGD("Destroy lttng_live_trace"); BT_ASSERT(trace->stream_iterators); @@ -167,11 +170,13 @@ struct lttng_live_trace *lttng_live_create_trace(struct lttng_live_session *sess uint64_t trace_id) { struct lttng_live_trace *trace = NULL; + bt_logging_level log_level = session->log_level; trace = g_new0(struct lttng_live_trace, 1); if (!trace) { goto error; } + trace->log_level = session->log_level; trace->session = session; trace->id = trace_id; trace->trace_class = NULL; @@ -216,12 +221,14 @@ int lttng_live_add_session(struct lttng_live_msg_iter *lttng_live_msg_iter, { int ret = 0; struct lttng_live_session *session; + bt_logging_level log_level = lttng_live_msg_iter->log_level; session = g_new0(struct lttng_live_session, 1); if (!session) { goto error; } + session->log_level = lttng_live_msg_iter->log_level; session->id = session_id; session->traces = g_ptr_array_new_with_free_func( (GDestroyNotify) lttng_live_destroy_trace); @@ -250,11 +257,13 @@ static void lttng_live_destroy_session(struct lttng_live_session *session) { struct lttng_live_component *live_comp; + bt_logging_level log_level; if (!session) { goto end; } + log_level = session->log_level; BT_LOGD("Destroy lttng live session"); if (session->id != -1ULL) { if (lttng_live_detach_session(session)) { @@ -326,6 +335,8 @@ static enum lttng_live_iterator_status lttng_live_iterator_next_check_stream_state( struct lttng_live_stream_iterator *lttng_live_stream) { + bt_logging_level log_level = lttng_live_stream->log_level; + switch (lttng_live_stream->state) { case LTTNG_LIVE_STREAM_QUIESCENT: case LTTNG_LIVE_STREAM_ACTIVE_DATA: @@ -357,6 +368,7 @@ enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_no_data_stre struct lttng_live_msg_iter *lttng_live_msg_iter, struct lttng_live_stream_iterator *lttng_live_stream) { + bt_logging_level log_level = lttng_live_msg_iter->log_level; enum lttng_live_iterator_status ret = LTTNG_LIVE_ITERATOR_STATUS_OK; struct packet_index index; @@ -615,6 +627,7 @@ int live_get_msg_ts_ns(struct lttng_live_stream_iterator *stream_iter, const bt_clock_snapshot *clock_snapshot = NULL; int ret = 0; bt_message_stream_activity_clock_snapshot_state sa_cs_state; + bt_logging_level log_level = lttng_live_msg_iter->log_level; BT_ASSERT(msg); BT_ASSERT(ts_ns); @@ -748,6 +761,7 @@ enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_active_data_ enum lttng_live_iterator_status ret = LTTNG_LIVE_ITERATOR_STATUS_OK; enum bt_msg_iter_status status; uint64_t session_idx, trace_idx; + bt_logging_level log_level = lttng_live_msg_iter->log_level; for (session_idx = 0; session_idx < lttng_live_msg_iter->sessions->len; session_idx++) { @@ -859,6 +873,7 @@ enum lttng_live_iterator_status lttng_live_iterator_next_on_stream( struct lttng_live_stream_iterator *stream_iter, bt_message **curr_msg) { + bt_logging_level log_level = lttng_live_msg_iter->log_level; enum lttng_live_iterator_status live_status; retry: @@ -906,6 +921,7 @@ enum lttng_live_iterator_status next_stream_iterator_for_trace( enum lttng_live_iterator_status stream_iter_status;; int64_t curr_candidate_msg_ts = INT64_MAX; uint64_t stream_iter_idx; + bt_logging_level log_level = lttng_live_msg_iter->log_level; BT_ASSERT(live_trace); BT_ASSERT(live_trace->stream_iterators); @@ -1314,10 +1330,12 @@ bt_self_message_iterator_status lttng_live_msg_iter_init( bt_self_component_source_as_self_component(self_comp_src); struct lttng_live_component *lttng_live; struct lttng_live_msg_iter *lttng_live_msg_iter; + bt_logging_level log_level; BT_ASSERT(self_msg_it); lttng_live = bt_self_component_get_data(self_comp); + log_level = lttng_live->log_level; /* There can be only one downstream iterator at the same time. */ BT_ASSERT(!lttng_live->has_msg_iter); @@ -1329,6 +1347,7 @@ bt_self_message_iterator_status lttng_live_msg_iter_init( goto end; } + lttng_live_msg_iter->log_level = lttng_live->log_level; lttng_live_msg_iter->lttng_live_comp = lttng_live; lttng_live_msg_iter->self_msg_iter = self_msg_it; @@ -1390,7 +1409,7 @@ end: static bt_query_status lttng_live_query_list_sessions(const bt_value *params, - const bt_value **result) + const bt_value **result, bt_logging_level log_level) { bt_query_status status = BT_QUERY_STATUS_OK; const bt_value *url_value = NULL; @@ -1444,13 +1463,13 @@ BT_HIDDEN bt_query_status lttng_live_query(bt_self_component_class_source *comp_class, const bt_query_executor *query_exec, const char *object, const bt_value *params, - __attribute__((unused)) bt_logging_level log_level, - const bt_value **result) + bt_logging_level log_level, const bt_value **result) { bt_query_status status = BT_QUERY_STATUS_OK; if (strcmp(object, "sessions") == 0) { - status = lttng_live_query_list_sessions(params, result); + status = lttng_live_query_list_sessions(params, result, + log_level); } else { BT_LOGW("Unknown query object `%s`", object); status = BT_QUERY_STATUS_INVALID_OBJECT; @@ -1505,7 +1524,8 @@ enum session_not_found_action parse_session_not_found_action_param( return action; } -struct lttng_live_component *lttng_live_component_create(const bt_value *params) +struct lttng_live_component *lttng_live_component_create(const bt_value *params, + bt_logging_level log_level) { struct lttng_live_component *lttng_live; const bt_value *value = NULL; @@ -1515,6 +1535,7 @@ struct lttng_live_component *lttng_live_component_create(const bt_value *params) if (!lttng_live) { goto end; } + lttng_live->log_level = log_level; lttng_live->max_query_size = MAX_QUERY_SIZE; lttng_live->has_msg_iter = false; @@ -1563,18 +1584,22 @@ end: BT_HIDDEN bt_self_component_status lttng_live_component_init( - bt_self_component_source *self_comp, + bt_self_component_source *self_comp_src, const bt_value *params, __attribute__((unused)) void *init_method_data) { struct lttng_live_component *lttng_live; bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; + bt_self_component *self_comp = + bt_self_component_source_as_self_component(self_comp_src); + bt_logging_level log_level = bt_component_get_logging_level( + bt_self_component_as_component(self_comp)); - lttng_live = lttng_live_component_create(params); + lttng_live = lttng_live_component_create(params, log_level); if (!lttng_live) { ret = BT_SELF_COMPONENT_STATUS_NOMEM; goto error; } - lttng_live->self_comp = self_comp; + lttng_live->self_comp = self_comp_src; if (lttng_live_graph_is_canceled(lttng_live)) { ret = BT_SELF_COMPONENT_STATUS_END; @@ -1588,9 +1613,7 @@ bt_self_component_status lttng_live_component_init( goto error; } - bt_self_component_set_data( - bt_self_component_source_as_self_component(self_comp), - lttng_live); + bt_self_component_set_data(self_comp, lttng_live); goto end; error: diff --git a/src/plugins/ctf/lttng-live/lttng-live.h b/src/plugins/ctf/lttng-live/lttng-live.h index dc49bfb3..35de9051 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.h +++ b/src/plugins/ctf/lttng-live/lttng-live.h @@ -64,6 +64,8 @@ enum lttng_live_stream_state { /* Iterator over a live stream. */ struct lttng_live_stream_iterator { + bt_logging_level log_level; + /* Owned by this. */ bt_stream *stream; @@ -119,6 +121,8 @@ struct lttng_live_stream_iterator { }; struct lttng_live_metadata { + bt_logging_level log_level; + /* Weak reference. */ struct lttng_live_trace *trace; @@ -130,6 +134,8 @@ struct lttng_live_metadata { }; struct lttng_live_trace { + bt_logging_level log_level; + /* Back reference to session. */ struct lttng_live_session *session; @@ -154,6 +160,8 @@ struct lttng_live_trace { }; struct lttng_live_session { + bt_logging_level log_level; + /* Weak reference. */ struct lttng_live_msg_iter *lttng_live_msg_iter; @@ -184,6 +192,8 @@ enum session_not_found_action { * A component instance is an iterator on a single session. */ struct lttng_live_component { + bt_logging_level log_level; + /* Weak reference. */ bt_self_component_source *self_comp; @@ -202,6 +212,8 @@ struct lttng_live_component { }; struct lttng_live_msg_iter { + bt_logging_level log_level; + /* Weak reference. */ struct lttng_live_component *lttng_live_comp; diff --git a/src/plugins/ctf/lttng-live/metadata.c b/src/plugins/ctf/lttng-live/metadata.c index 0ea4c77d..181a92b1 100644 --- a/src/plugins/ctf/lttng-live/metadata.c +++ b/src/plugins/ctf/lttng-live/metadata.c @@ -24,8 +24,9 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL log_level #define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/META" -#include "logging.h" +#include "logging/log.h" #include #include @@ -55,7 +56,8 @@ struct packet_header { static -bool stream_classes_all_have_default_clock_class(bt_trace_class *tc) +bool stream_classes_all_have_default_clock_class(bt_trace_class *tc, + bt_logging_level log_level) { uint64_t i, sc_count; const bt_clock_class *cc = NULL; @@ -124,6 +126,7 @@ enum lttng_live_iterator_status lttng_live_metadata_update( enum ctf_metadata_decoder_status decoder_status; enum lttng_live_iterator_status status = LTTNG_LIVE_ITERATOR_STATUS_OK; + bt_logging_level log_level = trace->log_level; /* No metadata stream yet. */ if (!metadata) { @@ -223,7 +226,7 @@ enum lttng_live_iterator_status lttng_live_metadata_update( metadata->decoder); trace->trace = bt_trace_create(trace->trace_class); if (!stream_classes_all_have_default_clock_class( - trace->trace_class)) { + trace->trace_class, log_level)) { /* Error logged in function. */ goto error; } @@ -270,7 +273,7 @@ int lttng_live_metadata_create_stream(struct lttng_live_session *session, struct lttng_live_trace *trace; const char *match; struct ctf_metadata_decoder_config cfg = { - .log_level = BT_LOG_OUTPUT_LEVEL, + .log_level = session->log_level, .clock_class_offset_s = 0, .clock_class_offset_ns = 0, }; @@ -279,6 +282,7 @@ int lttng_live_metadata_create_stream(struct lttng_live_session *session, if (!metadata) { return -1; } + metadata->log_level = session->log_level; metadata->stream_id = stream_id; match = strstr(trace_name, session->session_name->str); diff --git a/src/plugins/ctf/lttng-live/viewer-connection.c b/src/plugins/ctf/lttng-live/viewer-connection.c index 984caf2b..e81ef872 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.c +++ b/src/plugins/ctf/lttng-live/viewer-connection.c @@ -21,8 +21,9 @@ * SOFTWARE. */ +#define BT_LOG_OUTPUT_LEVEL (viewer_connection->log_level) #define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER" -#include "logging.h" +#include "logging/log.h" #include #include @@ -304,7 +305,7 @@ void connection_release(bt_object *obj) static int list_update_session(bt_value *results, const struct lttng_viewer_session *session, - bool *_found) + bool *_found, struct live_viewer_connection *viewer_connection) { int ret = 0; bt_value *map = NULL; @@ -389,7 +390,8 @@ end: static int list_append_session(bt_value *results, GString *base_url, - const struct lttng_viewer_session *session) + const struct lttng_viewer_session *session, + struct live_viewer_connection *viewer_connection) { int ret = 0; bt_value_status ret_status; @@ -401,7 +403,7 @@ int list_append_session(bt_value *results, * If the session already exists, add the stream count to it, * and do max of client counts. */ - ret = list_update_session(results, session, &found); + ret = list_update_session(results, session, &found, viewer_connection); if (ret || found) { goto end; } @@ -625,7 +627,7 @@ bt_query_status live_viewer_connection_list_sessions( lsession.hostname[LTTNG_VIEWER_HOST_NAME_MAX - 1] = '\0'; lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0'; if (list_append_session(result, viewer_connection->url, - &lsession)) { + &lsession, viewer_connection)) { status = BT_QUERY_STATUS_ERROR; goto error; } @@ -1478,6 +1480,7 @@ struct live_viewer_connection *live_viewer_connection_create( goto error; } + viewer_connection->log_level = lttng_live_msg_iter->log_level; bt_object_init_shared(&viewer_connection->obj, connection_release); viewer_connection->control_sock = BT_INVALID_SOCKET; viewer_connection->port = -1; diff --git a/src/plugins/ctf/lttng-live/viewer-connection.h b/src/plugins/ctf/lttng-live/viewer-connection.h index 761660f6..be6dc5a1 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.h +++ b/src/plugins/ctf/lttng-live/viewer-connection.h @@ -29,8 +29,12 @@ #include "common/macros.h" #include "compat/socket.h" -//TODO: this should not be used by plugins. Should copy code into plugin -//instead. +/* + * FIXME: This is an internal Babeltrace library header; it is not meant + * to be generic as it is now. Make sure this included code does not + * log because it won't find our local log level. + */ +#define BT_OBJECT_DONT_LOG #include "lib/object.h" #define LTTNG_DEFAULT_NETWORK_VIEWER_PORT 5344 @@ -41,6 +45,7 @@ struct lttng_live_component; struct live_viewer_connection { + bt_logging_level log_level; bt_object obj; GString *url; -- 2.34.1