From f6e2a9d238221cbfc59dfc2ec78113ca6b021bd4 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Tue, 22 Oct 2019 12:28:23 -0400 Subject: [PATCH] src.ctf.lttng-live: use `_APPEND_CAUSE` variants of logging macros This commit adds `BT_COMP_CLASS_LOGE()` and `BT_COMP_OR_COMP_CLASS_LOGE()` macros for convenience. Signed-off-by: Francis Deslauriers Change-Id: I86b9bbe89574d40fa5e65297a166ca0e7cff54a2 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2242 Reviewed-by: Simon Marchi --- src/logging/comp-logging.h | 19 + src/plugins/ctf/lttng-live/data-stream.c | 15 +- src/plugins/ctf/lttng-live/lttng-live.c | 68 +++- src/plugins/ctf/lttng-live/metadata.c | 26 +- .../ctf/lttng-live/viewer-connection.c | 337 ++++++++++++------ .../ctf/lttng-live/viewer-connection.h | 3 + 6 files changed, 343 insertions(+), 125 deletions(-) diff --git a/src/logging/comp-logging.h b/src/logging/comp-logging.h index 1edabc00..8d429ed1 100644 --- a/src/logging/comp-logging.h +++ b/src/logging/comp-logging.h @@ -169,6 +169,10 @@ #define BT_COMP_LOGE_APPEND_CAUSE_ERRNO(_self_comp, _msg, _fmt, ...) \ BT_COMP_LOG_APPEND_CAUSE_ERRNO(_self_comp, BT_LOG_ERROR, _msg, _fmt, ##__VA_ARGS__) +/* Logs error from component class context. */ +#define BT_COMP_CLASS_LOGE(_self_comp_class, _fmt, ...) \ + BT_COMP_CLASS_LOG(BT_LOG_ERROR,_self_comp_class, _fmt, ##__VA_ARGS__) + /* Logs and appends error cause from component class context. */ #define BT_COMP_CLASS_LOG_APPEND_CAUSE(_self_comp_class, _lvl, _fmt, ...) \ do { \ @@ -202,6 +206,21 @@ BT_COMP_CLASS_LOG_APPEND_CAUSE_ERRNO(_self_comp_class, BT_LOG_ERROR, _msg, _fmt, \ ##__VA_ARGS__) +/* + * Logs error from component or component class context, depending on whichever + * is set. + */ +#define BT_COMP_OR_COMP_CLASS_LOGE(_self_comp, _self_comp_class, _fmt, ...) \ + do { \ + /* Only one of `_self_comp` and `_self_comp_class` must be set. */ \ + BT_ASSERT((!!(_self_comp) != (!!_self_comp_class))); \ + if (_self_comp) { \ + BT_COMP_LOGE(_fmt, ##__VA_ARGS__); \ + } else { \ + BT_COMP_CLASS_LOGE(_self_comp_class, _fmt, ##__VA_ARGS__); \ + } \ + } while (0) + /* * Logs error and appends error cause from component or component class context, * depending on whichever is set. diff --git a/src/plugins/ctf/lttng-live/data-stream.c b/src/plugins/ctf/lttng-live/data-stream.c index ee351648..ce304963 100644 --- a/src/plugins/ctf/lttng-live/data-stream.c +++ b/src/plugins/ctf/lttng-live/data-stream.c @@ -113,7 +113,8 @@ bt_stream *medop_borrow_stream(bt_stream_class *stream_class, } if (!lttng_live_stream->stream) { - BT_COMP_LOGE("Cannot create stream %s (stream class ID " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot create stream %s (stream class ID " "%" PRId64 ", stream ID %" PRIu64 ")", lttng_live_stream->name->str, stream_class_id, stream_id); @@ -169,6 +170,8 @@ enum lttng_live_iterator_status lttng_live_lazy_msg_init( lttng_live->max_query_size, medops, stream_iter, log_level, self_comp); if (!stream_iter->msg_iter) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to create CTF message iterator"); goto error; } @@ -209,6 +212,8 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( stream_iter = g_new0(struct lttng_live_stream_iterator, 1); if (!stream_iter) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to allocate struct lttng_live_stream_iterator"); goto error; } @@ -216,6 +221,8 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( stream_iter->self_comp = self_comp; trace = lttng_live_borrow_trace(session, ctf_trace_id); if (!trace) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to borrow CTF trace."); goto error; } @@ -234,6 +241,8 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( lttng_live->max_query_size, medops, stream_iter, log_level, self_comp); if (!stream_iter->msg_iter) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to create CTF message iterator"); goto error; } @@ -244,12 +253,16 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( } stream_iter->buf = g_new0(uint8_t, lttng_live->max_query_size); if (!stream_iter->buf) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to allocate live stream iterator buffer"); goto error; } stream_iter->buflen = lttng_live->max_query_size; stream_iter->name = g_string_new(NULL); if (!stream_iter->name) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to allocate live stream iterator name buffer"); goto error; } diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index fa493cbb..d12b674d 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -178,6 +178,8 @@ struct lttng_live_trace *lttng_live_create_trace(struct lttng_live_session *sess trace = g_new0(struct lttng_live_trace, 1); if (!trace) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to allocate live trace"); goto error; } trace->log_level = session->log_level; @@ -231,6 +233,8 @@ int lttng_live_add_session(struct lttng_live_msg_iter *lttng_live_msg_iter, session = g_new0(struct lttng_live_session, 1); if (!session) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to allocate live session"); goto error; } @@ -253,7 +257,7 @@ int lttng_live_add_session(struct lttng_live_msg_iter *lttng_live_msg_iter, g_ptr_array_add(lttng_live_msg_iter->sessions, session); goto end; error: - BT_COMP_LOGE("Error adding session"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error adding session"); g_free(session); ret = -1; end: @@ -435,6 +439,8 @@ enum lttng_live_iterator_status lttng_live_get_session( struct lttng_live_msg_iter *lttng_live_msg_iter, struct lttng_live_session *session) { + bt_logging_level log_level = lttng_live_msg_iter->log_level; + bt_self_component *self_comp = lttng_live_msg_iter->self_comp; enum lttng_live_iterator_status status; uint64_t trace_idx; @@ -443,9 +449,18 @@ enum lttng_live_iterator_status lttng_live_get_session( lttng_live_attach_session(session); if (attach_status != LTTNG_LIVE_ATTACH_SESSION_STATUS_OK) { if (lttng_live_graph_is_canceled(lttng_live_msg_iter)) { + /* + * Clear any causes appended in + * `lttng_live_attach_session()` as we want to + * return gracefully since the graph was + * cancelled. + */ + bt_current_thread_clear_error(); status = LTTNG_LIVE_ITERATOR_STATUS_AGAIN; } else { status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error attaching to LTTng live session"); } goto end; } @@ -527,6 +542,8 @@ lttng_live_iterator_handle_new_streams_and_metadata( struct lttng_live_msg_iter *lttng_live_msg_iter) { enum lttng_live_iterator_status ret = LTTNG_LIVE_ITERATOR_STATUS_OK; + bt_logging_level log_level = lttng_live_msg_iter->log_level; + bt_self_component *self_comp = lttng_live_msg_iter->self_comp; uint64_t session_idx = 0, nr_sessions_opened = 0; struct lttng_live_session *session; enum session_not_found_action sess_not_found_act = @@ -549,6 +566,8 @@ lttng_live_iterator_handle_new_streams_and_metadata( */ if (lttng_live_create_viewer_session(lttng_live_msg_iter)) { ret = LTTNG_LIVE_ITERATOR_STATUS_ERROR; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating LTTng live viewer session"); goto end; } } @@ -588,6 +607,8 @@ enum lttng_live_iterator_status emit_inactivity_message( bt_message **message, uint64_t timestamp) { enum lttng_live_iterator_status ret = LTTNG_LIVE_ITERATOR_STATUS_OK; + bt_logging_level log_level = lttng_live_msg_iter->log_level; + bt_self_component *self_comp = lttng_live_msg_iter->self_comp; bt_message *msg = NULL; BT_ASSERT(stream_iter->trace->clock_class); @@ -596,6 +617,8 @@ enum lttng_live_iterator_status emit_inactivity_message( lttng_live_msg_iter->self_msg_iter, stream_iter->trace->clock_class, timestamp); if (!msg) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error emitting message iterator inactivity message"); goto error; } @@ -713,7 +736,8 @@ int live_get_msg_ts_ns(struct lttng_live_stream_iterator *stream_iter, ret = bt_clock_snapshot_get_ns_from_origin(clock_snapshot, ts_ns); if (ret) { - BT_COMP_LOGE("Cannot get nanoseconds from Epoch of clock snapshot: " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot get nanoseconds from Epoch of clock snapshot: " "clock-snapshot-addr=%p", clock_snapshot); goto error; } @@ -793,8 +817,9 @@ enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_active_data_ case BT_MSG_ITER_STATUS_ERROR: default: ret = LTTNG_LIVE_ITERATOR_STATUS_ERROR; - BT_COMP_LOGW("CTF msg iterator return an error or failed msg_iter=%p", - lttng_live_stream->msg_iter); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "CTF message iterator return an error or failed: " + "msg_iter=%p", lttng_live_stream->msg_iter); break; } @@ -810,6 +835,8 @@ enum lttng_live_iterator_status lttng_live_iterator_close_stream( { enum lttng_live_iterator_status live_status = LTTNG_LIVE_ITERATOR_STATUS_OK; + bt_logging_level log_level = lttng_live_msg_iter->log_level; + bt_self_component *self_comp = lttng_live_msg_iter->self_comp; /* * The viewer has hung up on us so we are closing the stream. The * `bt_msg_iter` should simply realize that it needs to close the @@ -820,6 +847,8 @@ enum lttng_live_iterator_status lttng_live_iterator_close_stream( curr_msg); if (status == BT_MSG_ITER_STATUS_ERROR) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error getting the next message from CTF message iterator"); live_status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; goto end; } @@ -1016,7 +1045,8 @@ enum lttng_live_iterator_status next_stream_iterator_for_trace( * We received a message in the past. To ensure * monotonicity, we can't send it forward. */ - BT_COMP_LOGE("Message's timestamp is less than " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Message's timestamp is less than " "lttng-live's message iterator's last " "returned timestamp: " "lttng-live-msg-iter-addr=%p, ts=%" PRId64 ", " @@ -1476,7 +1506,7 @@ bt_component_class_message_iterator_initialize_method_status lttng_live_msg_iter lttng_live_msg_iter->viewer_connection = live_viewer_connection_create(lttng_live->params.url->str, false, - lttng_live_msg_iter, log_level); + lttng_live_msg_iter, self_comp, NULL, log_level); if (!lttng_live_msg_iter->viewer_connection) { goto error; } @@ -1495,7 +1525,7 @@ bt_component_class_message_iterator_initialize_method_status lttng_live_msg_iter lttng_live->params.url->str); break; case SESSION_NOT_FOUND_ACTION_FAIL: - BT_COMP_LOGE("Unable to connect to the requested live viewer " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Unable to connect to the requested live viewer " "session. Fail the message iterator" "initialization because of %s=\"%s\" " "component parameter: url =\"%s\"", @@ -1551,7 +1581,8 @@ bt_component_class_query_method_status lttng_live_query_list_sessions( goto error; } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) { status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; - BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "%s", validate_error); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "%s", + validate_error); goto error; } @@ -1559,8 +1590,10 @@ bt_component_class_query_method_status lttng_live_query_list_sessions( url = bt_value_string_get(url_value); viewer_connection = live_viewer_connection_create(url, true, NULL, - log_level); + NULL, self_comp_class, log_level); if (!viewer_connection) { + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Failed to create viewer connection"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } @@ -1568,6 +1601,8 @@ bt_component_class_query_method_status lttng_live_query_list_sessions( status = live_viewer_connection_list_sessions(viewer_connection, result); if (status != BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK) { + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Failed to list viewer sessions"); goto error; } @@ -1593,6 +1628,7 @@ end: static bt_component_class_query_method_status lttng_live_query_support_info( const bt_value *params, const bt_value **result, + bt_self_component_class *self_comp_class, bt_logging_level log_level) { bt_component_class_query_method_status status = @@ -1609,12 +1645,14 @@ bt_component_class_query_method_status lttng_live_query_support_info( input_type_value = bt_value_map_borrow_entry_value_const(params, "type"); if (!input_type_value) { - BT_COMP_LOGE("Missing expected `type` parameter."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Missing expected `type` parameter."); goto error; } if (!bt_value_is_string(input_type_value)) { - BT_COMP_LOGE("`type` parameter is not a string value."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "`type` parameter is not a string value."); goto error; } @@ -1625,12 +1663,14 @@ bt_component_class_query_method_status lttng_live_query_support_info( input_value = bt_value_map_borrow_entry_value_const(params, "input"); if (!input_value) { - BT_COMP_LOGE("Missing expected `input` parameter."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Missing expected `input` parameter."); goto error; } if (!bt_value_is_string(input_value)) { - BT_COMP_LOGE("`input` parameter is not a string value."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "`input` parameter is not a string value."); goto error; } @@ -1687,7 +1727,7 @@ bt_component_class_query_method_status lttng_live_query( self_comp_class, log_level); } else if (strcmp(object, "babeltrace.support-info") == 0) { status = lttng_live_query_support_info(params, result, - log_level); + self_comp_class, log_level); } else { BT_COMP_LOGI("Unknown query object `%s`", object); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT; diff --git a/src/plugins/ctf/lttng-live/metadata.c b/src/plugins/ctf/lttng-live/metadata.c index df75b15f..b9278467 100644 --- a/src/plugins/ctf/lttng-live/metadata.c +++ b/src/plugins/ctf/lttng-live/metadata.c @@ -76,7 +76,8 @@ bool stream_classes_all_have_default_clock_class(bt_trace_class *tc, cc = bt_stream_class_borrow_default_clock_class_const(sc); if (!cc) { ret = false; - BT_COMP_LOGE("Stream class doesn't have a default clock class: " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Stream class doesn't have a default clock class: " "sc-id=%" PRIu64 ", sc-name=\"%s\"", bt_stream_class_get_id(sc), bt_stream_class_get_name(sc)); @@ -153,7 +154,8 @@ enum lttng_live_iterator_status lttng_live_metadata_update( /* Open for writing */ fp = bt_open_memstream(&metadata_buf, &size); if (!fp) { - BT_COMP_LOGE("Metadata open_memstream: %s", strerror(errno)); + BT_COMP_LOGE_APPEND_CAUSE_ERRNO(self_comp, + "Metadata open_memstream", "."); goto error; } @@ -203,7 +205,8 @@ enum lttng_live_iterator_status lttng_live_metadata_update( } if (bt_close_memstream(&metadata_buf, &size, fp)) { - BT_COMP_LOGE("bt_close_memstream: %s", strerror(errno)); + BT_COMP_LOGE_APPEND_CAUSE_ERRNO(self_comp, + "Metadata bt_close_memstream", "."); } fp = NULL; @@ -219,8 +222,8 @@ enum lttng_live_iterator_status lttng_live_metadata_update( fp = bt_fmemopen(metadata_buf, len_read, "rb"); if (!fp) { - BT_COMP_LOGE("Cannot memory-open metadata buffer: %s", - strerror(errno)); + BT_COMP_LOGE_APPEND_CAUSE_ERRNO(self_comp, + "Cannot memory-open metadata buffer", "."); goto error; } @@ -242,10 +245,14 @@ enum lttng_live_iterator_status lttng_live_metadata_update( metadata->decoder); trace->trace = bt_trace_create(trace->trace_class); if (!trace->trace) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to create bt_trace"); goto error; } if (ctf_trace_class_configure_ir_trace(tc, trace->trace)) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to configure ctf trace class"); goto error; } if (!stream_classes_all_have_default_clock_class( @@ -283,7 +290,8 @@ end: closeret = fclose(fp); if (closeret) { - BT_COMP_LOGE("Error on fclose"); + BT_COMP_LOGE_APPEND_CAUSE_ERRNO(self_comp, + "Error on fclose", "."); } } free(metadata_buf); @@ -295,6 +303,8 @@ int lttng_live_metadata_create_stream(struct lttng_live_session *session, uint64_t ctf_trace_id, uint64_t stream_id, const char *trace_name) { + bt_self_component *self_comp = session->self_comp; + bt_logging_level log_level = session->log_level; struct lttng_live_metadata *metadata = NULL; struct lttng_live_trace *trace; struct ctf_metadata_decoder_config cfg = { @@ -315,10 +325,14 @@ int lttng_live_metadata_create_stream(struct lttng_live_session *session, metadata->decoder = ctf_metadata_decoder_create(&cfg); if (!metadata->decoder) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to create CTF metadata decoder"); goto error; } trace = lttng_live_borrow_trace(session, ctf_trace_id); if (!trace) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to borrow trace"); goto error; } metadata->trace = trace; diff --git a/src/plugins/ctf/lttng-live/viewer-connection.c b/src/plugins/ctf/lttng-live/viewer-connection.c index e3ac7f8d..6fa1456f 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.c +++ b/src/plugins/ctf/lttng-live/viewer-connection.c @@ -112,6 +112,8 @@ static int parse_url(struct live_viewer_connection *viewer_connection) { char error_buf[256] = { 0 }; + bt_self_component *self_comp = viewer_connection->self_comp; + bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; struct bt_common_lttng_live_url_parts lttng_live_url_parts = { 0 }; int ret = -1; const char *path = viewer_connection->url->str; @@ -123,7 +125,9 @@ int parse_url(struct live_viewer_connection *viewer_connection) lttng_live_url_parts = bt_common_parse_lttng_live_url(path, error_buf, sizeof(error_buf)); if (!lttng_live_url_parts.proto) { - BT_COMP_LOGW("Invalid LTTng live URL format: %s", error_buf); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class,"Invalid LTTng live URL format: %s", + error_buf); goto end; } @@ -165,6 +169,8 @@ int lttng_live_handshake(struct live_viewer_connection *viewer_connection) { struct lttng_viewer_cmd cmd; struct lttng_viewer_connect connect; + bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; + bt_self_component *self_comp = viewer_connection->self_comp; const size_t cmd_buf_len = sizeof(cmd) + sizeof(connect); char cmd_buf[cmd_buf_len]; int ret; @@ -188,7 +194,9 @@ int lttng_live_handshake(struct live_viewer_connection *viewer_connection) memcpy(cmd_buf + sizeof(cmd), &connect, sizeof(connect)); ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error sending version: %s", bt_socket_errormsg()); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Error sending version: %s", + bt_socket_errormsg()); goto error; } @@ -196,11 +204,14 @@ int lttng_live_handshake(struct live_viewer_connection *viewer_connection) ret_len = lttng_live_recv(viewer_connection, &connect, sizeof(connect)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving version: %s", bt_socket_errormsg()); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Error receiving version: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == sizeof(connect)); @@ -211,7 +222,8 @@ int lttng_live_handshake(struct live_viewer_connection *viewer_connection) be32toh(connect.minor)); if (LTTNG_LIVE_MAJOR != be32toh(connect.major)) { - BT_COMP_LOGE("Incompatible lttng-relayd protocol"); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Incompatible lttng-relayd protocol"); goto error; } /* Use the smallest protocol version implemented. */ @@ -225,7 +237,6 @@ int lttng_live_handshake(struct live_viewer_connection *viewer_connection) return ret; error: - BT_COMP_LOGE("Unable to establish connection"); return -1; } @@ -234,21 +245,27 @@ int lttng_live_connect_viewer(struct live_viewer_connection *viewer_connection) { struct hostent *host; struct sockaddr_in server_addr; + bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; + bt_self_component *self_comp = viewer_connection->self_comp; int ret; if (parse_url(viewer_connection)) { + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Failed to parse URL"); goto error; } host = gethostbyname(viewer_connection->relay_hostname->str); if (!host) { - BT_COMP_LOGE("Cannot lookup hostname %s", + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Cannot lookup hostname: hostname=\"%s\"", viewer_connection->relay_hostname->str); goto error; } if ((viewer_connection->control_sock = socket(AF_INET, SOCK_STREAM, 0)) == BT_INVALID_SOCKET) { - BT_COMP_LOGE("Socket creation failed: %s", bt_socket_errormsg()); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Socket creation failed: %s", bt_socket_errormsg()); goto error; } @@ -259,10 +276,14 @@ int lttng_live_connect_viewer(struct live_viewer_connection *viewer_connection) if (connect(viewer_connection->control_sock, (struct sockaddr *) &server_addr, sizeof(struct sockaddr)) == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Connection failed: %s", bt_socket_errormsg()); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Connection failed: %s", + bt_socket_errormsg()); goto error; } if (lttng_live_handshake(viewer_connection)) { + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Viewer handshake failed"); goto error; } @@ -273,7 +294,8 @@ int lttng_live_connect_viewer(struct live_viewer_connection *viewer_connection) error: if (viewer_connection->control_sock != BT_INVALID_SOCKET) { if (bt_socket_close(viewer_connection->control_sock) == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Close: %s", bt_socket_errormsg()); + BT_COMP_OR_COMP_CLASS_LOGE(self_comp, self_comp_class, + "Error closing socket: %s", bt_socket_errormsg()); } } viewer_connection->control_sock = BT_INVALID_SOCKET; @@ -288,7 +310,8 @@ void lttng_live_disconnect_viewer( return; } if (bt_socket_close(viewer_connection->control_sock) == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Close: %s", bt_socket_errormsg()); + BT_COMP_LOGE("Error closing socket: %s", + bt_socket_errormsg()); viewer_connection->control_sock = BT_INVALID_SOCKET; } } @@ -307,6 +330,8 @@ int list_update_session(bt_value *results, const struct lttng_viewer_session *session, bool *_found, struct live_viewer_connection *viewer_connection) { + bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; + bt_self_component *self_comp = viewer_connection->self_comp; int ret = 0; uint64_t i, len; bt_value *map = NULL; @@ -323,13 +348,17 @@ int list_update_session(bt_value *results, map = bt_value_array_borrow_element_by_index(results, i); hostname = bt_value_map_borrow_entry_value(map, "target-hostname"); if (!hostname) { - BT_COMP_LOGE_STR("Error borrowing \"target-hostname\" entry."); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, + "Error borrowing \"target-hostname\" entry."); ret = -1; goto end; } session_name = bt_value_map_borrow_entry_value(map, "session-name"); if (!session_name) { - BT_COMP_LOGE_STR("Error borrowing \"session-name\" entry."); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, + "Error borrowing \"session-name\" entry."); ret = -1; goto end; } @@ -346,7 +375,9 @@ int list_update_session(bt_value *results, btval = bt_value_map_borrow_entry_value(map, "stream-count"); if (!btval) { - BT_COMP_LOGE_STR("Error borrowing \"stream-count\" entry."); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + self_comp, self_comp_class, + "Error borrowing \"stream-count\" entry."); ret = -1; goto end; } @@ -357,7 +388,9 @@ int list_update_session(bt_value *results, btval = bt_value_map_borrow_entry_value(map, "client-count"); if (!btval) { - BT_COMP_LOGE_STR("Error borrowing \"client-count\" entry."); + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE( + self_comp, self_comp_class, + "Error borrowing \"client-count\" entry."); ret = -1; goto end; } @@ -383,6 +416,7 @@ int list_append_session(bt_value *results, struct live_viewer_connection *viewer_connection) { int ret = 0; + bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; bt_value_map_insert_entry_status insert_status; bt_value_array_append_element_status append_status; bt_value *map = NULL; @@ -400,13 +434,15 @@ int list_append_session(bt_value *results, map = bt_value_map_create(); if (!map) { - BT_COMP_LOGE_STR("Error creating map value."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error creating map value."); ret = -1; goto end; } if (base_url->len < 1) { - BT_COMP_LOGE_STR("Error: base_url length smaller than 1."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error: base_url length smaller than 1."); ret = -1; goto end; } @@ -422,7 +458,8 @@ int list_append_session(bt_value *results, insert_status = bt_value_map_insert_string_entry(map, "url", url->str); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_LOGE_STR("Error inserting \"url\" entry."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error inserting \"url\" entry."); ret = -1; goto end; } @@ -434,7 +471,8 @@ int list_append_session(bt_value *results, insert_status = bt_value_map_insert_string_entry(map, "target-hostname", session->hostname); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_LOGE_STR("Error inserting \"target-hostname\" entry."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error inserting \"target-hostname\" entry."); ret = -1; goto end; } @@ -446,7 +484,8 @@ int list_append_session(bt_value *results, insert_status = bt_value_map_insert_string_entry(map, "session-name", session->session_name); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_LOGE_STR("Error inserting \"session-name\" entry."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error inserting \"session-name\" entry."); ret = -1; goto end; } @@ -461,7 +500,8 @@ int list_append_session(bt_value *results, insert_status = bt_value_map_insert_unsigned_integer_entry( map, "timer-us", live_timer); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_LOGE_STR("Error inserting \"timer-us\" entry."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error inserting \"timer-us\" entry."); ret = -1; goto end; } @@ -477,7 +517,8 @@ int list_append_session(bt_value *results, insert_status = bt_value_map_insert_unsigned_integer_entry(map, "stream-count", streams); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_LOGE_STR("Error inserting \"stream-count\" entry."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error inserting \"stream-count\" entry."); ret = -1; goto end; } @@ -493,7 +534,8 @@ int list_append_session(bt_value *results, insert_status = bt_value_map_insert_unsigned_integer_entry(map, "client-count", clients); if (insert_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { - BT_COMP_LOGE_STR("Error inserting \"client-count\" entry."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error inserting \"client-count\" entry."); ret = -1; goto end; } @@ -501,7 +543,8 @@ int list_append_session(bt_value *results, append_status = bt_value_array_append_element(results, map); if (append_status != BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK) { - BT_COMP_LOGE_STR("Error appending map to results."); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error appending map to results."); ret = -1; } @@ -554,6 +597,7 @@ bt_component_class_query_method_status live_viewer_connection_list_sessions( struct live_viewer_connection *viewer_connection, const bt_value **user_result) { + bt_self_component_class *self_comp_class = viewer_connection->self_comp_class; bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK; bt_value *result = NULL; @@ -564,7 +608,8 @@ bt_component_class_query_method_status live_viewer_connection_list_sessions( result = bt_value_array_create(); if (!result) { - BT_COMP_LOGE("Error creating array"); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error creating array"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR; goto error; } @@ -575,7 +620,8 @@ bt_component_class_query_method_status live_viewer_connection_list_sessions( ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd)); if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error sending cmd: %s", bt_socket_errormsg()); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error sending cmd: %s", bt_socket_errormsg()); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } @@ -583,12 +629,15 @@ bt_component_class_query_method_status live_viewer_connection_list_sessions( ret_len = lttng_live_recv(viewer_connection, &list, sizeof(list)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Remote side has closed connection"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving session list: %s", bt_socket_errormsg()); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error receiving session list: %s", + bt_socket_errormsg()); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } @@ -601,12 +650,15 @@ bt_component_class_query_method_status live_viewer_connection_list_sessions( ret_len = lttng_live_recv(viewer_connection, &lsession, sizeof(lsession)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Remote side has closed connection"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving session: %s", bt_socket_errormsg()); + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error receiving session: %s", + bt_socket_errormsg()); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } @@ -615,6 +667,8 @@ bt_component_class_query_method_status live_viewer_connection_list_sessions( lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0'; if (list_append_session(result, viewer_connection->url, &lsession, viewer_connection)) { + BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, + "Error appending session"); status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; goto error; } @@ -638,7 +692,8 @@ int lttng_live_query_session_ids(struct lttng_live_msg_iter *lttng_live_msg_iter ssize_t ret_len; uint64_t session_id; struct live_viewer_connection *viewer_connection = - lttng_live_msg_iter->viewer_connection; + lttng_live_msg_iter->viewer_connection; + bt_self_component *self_comp = viewer_connection->self_comp; cmd.cmd = htobe32(LTTNG_VIEWER_LIST_SESSIONS); cmd.data_size = htobe64((uint64_t) 0); @@ -646,18 +701,22 @@ int lttng_live_query_session_ids(struct lttng_live_msg_iter *lttng_live_msg_iter ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd)); if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error sending cmd: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error sending cmd: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == sizeof(cmd)); ret_len = lttng_live_recv(viewer_connection, &list, sizeof(list)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving session list: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error receiving session list: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == sizeof(list)); @@ -667,11 +726,14 @@ int lttng_live_query_session_ids(struct lttng_live_msg_iter *lttng_live_msg_iter ret_len = lttng_live_recv(viewer_connection, &lsession, sizeof(lsession)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving session: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error receiving session: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == sizeof(lsession)); @@ -690,6 +752,8 @@ int lttng_live_query_session_ids(struct lttng_live_msg_iter *lttng_live_msg_iter if (lttng_live_add_session(lttng_live_msg_iter, session_id, lsession.hostname, lsession.session_name)) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to add live session"); goto error; } } @@ -698,7 +762,6 @@ int lttng_live_query_session_ids(struct lttng_live_msg_iter *lttng_live_msg_iter return 0; error: - BT_COMP_LOGE("Unable to query session ids"); return -1; } @@ -710,7 +773,8 @@ int lttng_live_create_viewer_session( struct lttng_viewer_create_session_response resp; ssize_t ret_len; struct live_viewer_connection *viewer_connection = - lttng_live_msg_iter->viewer_connection; + lttng_live_msg_iter->viewer_connection; + bt_self_component *self_comp = viewer_connection->self_comp; cmd.cmd = htobe32(LTTNG_VIEWER_CREATE_SESSION); cmd.data_size = htobe64((uint64_t) 0); @@ -718,27 +782,34 @@ int lttng_live_create_viewer_session( ret_len = lttng_live_send(viewer_connection, &cmd, sizeof(cmd)); if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error sending cmd: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error sending cmd: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == sizeof(cmd)); ret_len = lttng_live_recv(viewer_connection, &resp, sizeof(resp)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving create session reply: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error receiving create session reply: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == sizeof(resp)); if (be32toh(resp.status) != LTTNG_VIEWER_CREATE_SESSION_OK) { - BT_COMP_LOGE("Error creating viewer session"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating viewer session"); goto error; } if (lttng_live_query_session_ids(lttng_live_msg_iter)) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to query live viewer session ids"); goto error; } @@ -758,6 +829,7 @@ int receive_streams(struct lttng_live_session *session, session->lttng_live_msg_iter; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; + bt_self_component *self_comp = viewer_connection->self_comp; BT_COMP_LOGI("Getting %" PRIu32 " new streams:", stream_count); for (i = 0; i < stream_count; i++) { @@ -768,11 +840,13 @@ int receive_streams(struct lttng_live_session *session, ret_len = lttng_live_recv(viewer_connection, &stream, sizeof(stream)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving stream"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error receiving stream"); goto error; } BT_ASSERT(ret_len == sizeof(stream)); @@ -787,7 +861,8 @@ int receive_streams(struct lttng_live_session *session, if (lttng_live_metadata_create_stream(session, ctf_trace_id, stream_id, stream.path_name)) { - BT_COMP_LOGE("Error creating metadata stream"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating metadata stream"); goto error; } @@ -798,7 +873,8 @@ int receive_streams(struct lttng_live_session *session, live_stream = lttng_live_stream_iterator_create(session, ctf_trace_id, stream_id); if (!live_stream) { - BT_COMP_LOGE("Error creating streamn"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating stream"); goto error; } } @@ -821,6 +897,7 @@ enum lttng_live_attach_session_status lttng_live_attach_session( session->lttng_live_msg_iter; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; + bt_self_component *self_comp = viewer_connection->self_comp; uint64_t session_id = session->id; uint32_t streams_count; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); @@ -846,18 +923,23 @@ enum lttng_live_attach_session_status lttng_live_attach_session( memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error sending attach request: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error sending attach request: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving attach response: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error receiving attach response: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == sizeof(rp)); @@ -867,24 +949,28 @@ enum lttng_live_attach_session_status lttng_live_attach_session( case LTTNG_VIEWER_ATTACH_OK: break; case LTTNG_VIEWER_ATTACH_UNK: - BT_COMP_LOGW("Session id %" PRIu64 " is unknown", session_id); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Session id %" PRIu64 " is unknown", session_id); goto error; case LTTNG_VIEWER_ATTACH_ALREADY: - BT_COMP_LOGW("There is already a viewer attached to this session"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "There is already a viewer attached to this session"); goto error; case LTTNG_VIEWER_ATTACH_NOT_LIVE: - BT_COMP_LOGW("Not a live session"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Not a live session"); goto error; case LTTNG_VIEWER_ATTACH_SEEK_ERR: - BT_COMP_LOGE("Wrong seek parameter"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Wrong seek parameter"); goto error; default: - BT_COMP_LOGE("Unknown attach return code %u", be32toh(rp.status)); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Unknown attach return code %u", be32toh(rp.status)); goto error; } /* We receive the initial list of streams. */ if (receive_streams(session, streams_count)) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error receiving streams"); goto error; } @@ -936,18 +1022,20 @@ int lttng_live_detach_session(struct lttng_live_session *session) memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error sending detach request: %s", bt_socket_errormsg()); + BT_COMP_LOGE("Error sending detach request: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE("Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving detach response: %s", bt_socket_errormsg()); + BT_COMP_LOGE("Error receiving detach response: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == sizeof(rp)); @@ -991,6 +1079,7 @@ enum lttng_live_get_one_metadata_status lttng_live_get_one_metadata_packet( struct lttng_live_metadata *metadata = trace->metadata; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; + bt_self_component *self_comp = viewer_connection->self_comp; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); char cmd_buf[cmd_buf_len]; @@ -1008,25 +1097,30 @@ enum lttng_live_get_one_metadata_status lttng_live_get_one_metadata_packet( memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error sending get_metadata request: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error sending get_metadata request: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving get_metadata response: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error receiving get_metadata response: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == sizeof(rp)); switch (be32toh(rp.status)) { case LTTNG_VIEWER_METADATA_OK: - BT_COMP_LOGD("Received get_metadata response : OK"); + BT_COMP_LOGD("Received get_metadata response: ok"); break; case LTTNG_VIEWER_NO_NEW_METADATA: BT_COMP_LOGD("Received get_metadata response: no new"); @@ -1042,19 +1136,23 @@ enum lttng_live_get_one_metadata_status lttng_live_get_one_metadata_packet( metadata_status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_CLOSED; goto end; default: - BT_COMP_LOGD("get_metadata : UNKNOWN"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Received get_metadata response: unknown"); goto error; } len = be64toh(rp.len); BT_COMP_LOGD("Writing %" PRIu64" bytes to metadata", len); if (len <= 0) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Erroneous response length"); goto error; } data = calloc(1, len); if (!data) { - BT_COMP_LOGE("relay data calloc: %s", strerror(errno)); + BT_COMP_LOGE_APPEND_CAUSE_ERRNO(self_comp, + "Failed to allocate data buffer", "."); goto error; } ret_len = lttng_live_recv(viewer_connection, data, len); @@ -1063,7 +1161,8 @@ enum lttng_live_get_one_metadata_status lttng_live_get_one_metadata_packet( goto error_free_data; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving trace packet: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error receiving trace packet: %s", bt_socket_errormsg()); goto error_free_data; } BT_ASSERT(ret_len == len); @@ -1072,7 +1171,8 @@ enum lttng_live_get_one_metadata_status lttng_live_get_one_metadata_packet( ret_len = fwrite(data, 1, len, fp); } while (ret_len < 0 && errno == EINTR); if (ret_len < 0) { - BT_COMP_LOGE("Writing in the metadata fp"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Writing in the metadata file stream"); goto error_free_data; } BT_ASSERT(ret_len == len); @@ -1120,7 +1220,8 @@ enum lttng_live_iterator_status lttng_live_get_next_index( struct lttng_viewer_index rp; enum lttng_live_iterator_status retstatus = LTTNG_LIVE_ITERATOR_STATUS_OK; struct live_viewer_connection *viewer_connection = - lttng_live_msg_iter->viewer_connection; + lttng_live_msg_iter->viewer_connection; + bt_self_component *self_comp = viewer_connection->self_comp; struct lttng_live_trace *trace = stream->trace; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); char cmd_buf[cmd_buf_len]; @@ -1144,20 +1245,23 @@ enum lttng_live_iterator_status lttng_live_get_next_index( memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error sending get_next_index request: %s", - bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error sending get_next_index request: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving get_next_index response: %s", - bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error receiving get_next_index response: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == sizeof(rp)); @@ -1170,7 +1274,7 @@ enum lttng_live_iterator_status lttng_live_get_next_index( { uint64_t ctf_stream_class_id; - BT_COMP_LOGD("get_next_index: inactive"); + BT_COMP_LOGD("Received get_next_index response: inactive"); memset(index, 0, sizeof(struct packet_index)); index->ts_cycles.timestamp_end = be64toh(rp.timestamp_end); stream->current_inactivity_ts = index->ts_cycles.timestamp_end; @@ -1188,7 +1292,7 @@ enum lttng_live_iterator_status lttng_live_get_next_index( { uint64_t ctf_stream_class_id; - BT_COMP_LOGD("get_next_index: OK"); + BT_COMP_LOGD("Received get_next_index response: OK"); lttng_index_to_packet_index(&rp, index); ctf_stream_class_id = be64toh(rp.stream_id); if (stream->ctf_stream_class_id != -1ULL) { @@ -1201,23 +1305,23 @@ enum lttng_live_iterator_status lttng_live_get_next_index( stream->state = LTTNG_LIVE_STREAM_ACTIVE_DATA; if (flags & LTTNG_VIEWER_FLAG_NEW_METADATA) { - BT_COMP_LOGD("get_next_index: new metadata needed"); + BT_COMP_LOGD("Received get_next_index response: new metadata needed"); trace->new_metadata_needed = true; } if (flags & LTTNG_VIEWER_FLAG_NEW_STREAM) { - BT_COMP_LOGD("get_next_index: new streams needed"); + BT_COMP_LOGD("Received get_next_index response: new streams needed"); lttng_live_need_new_streams(lttng_live_msg_iter); } break; } case LTTNG_VIEWER_INDEX_RETRY: - BT_COMP_LOGD("get_next_index: retry"); + BT_COMP_LOGD("Received get_next_index response: retry"); memset(index, 0, sizeof(struct packet_index)); retstatus = LTTNG_LIVE_ITERATOR_STATUS_AGAIN; stream->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA; goto end; case LTTNG_VIEWER_INDEX_HUP: - BT_COMP_LOGD("get_next_index: stream hung up"); + BT_COMP_LOGD("Received get_next_index response: stream hung up"); memset(index, 0, sizeof(struct packet_index)); index->offset = EOF; retstatus = LTTNG_LIVE_ITERATOR_STATUS_END; @@ -1225,12 +1329,12 @@ enum lttng_live_iterator_status lttng_live_get_next_index( stream->has_stream_hung_up = true; break; case LTTNG_VIEWER_INDEX_ERR: - BT_COMP_LOGE("get_next_index: error"); + BT_COMP_LOGD("Received get_next_index response: error"); memset(index, 0, sizeof(struct packet_index)); stream->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA; goto error; default: - BT_COMP_LOGE("get_next_index: unknown value"); + BT_COMP_LOGD("Received get_next_index response: unknown value"); memset(index, 0, sizeof(struct packet_index)); stream->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA; goto error; @@ -1258,7 +1362,8 @@ enum bt_msg_iter_medium_status lttng_live_get_stream_bytes( struct lttng_viewer_cmd cmd; struct lttng_viewer_get_packet rq; struct live_viewer_connection *viewer_connection = - lttng_live_msg_iter->viewer_connection; + lttng_live_msg_iter->viewer_connection; + bt_self_component *self_comp = viewer_connection->self_comp; struct lttng_live_trace *trace = stream->trace; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); char cmd_buf[cmd_buf_len]; @@ -1285,24 +1390,28 @@ enum bt_msg_iter_medium_status lttng_live_get_stream_bytes( memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error sending get_data request: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error sending get_data_packet request: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving get_data response: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Socket error receiving get_data response: %s", + bt_socket_errormsg()); goto error; } if (ret_len != sizeof(rp)) { - BT_COMP_LOGE("get_data_packet: expected %zu" - ", received %zd", sizeof(rp), - ret_len); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "get_data_packet: " + "expected %zu, received %zd", sizeof(rp), ret_len); goto error; } @@ -1312,11 +1421,12 @@ enum bt_msg_iter_medium_status lttng_live_get_stream_bytes( switch (status) { case LTTNG_VIEWER_GET_PACKET_OK: req_len = be32toh(rp.len); - BT_COMP_LOGD("get_data_packet: Ok, packet size : %" PRIu64 "", req_len); + BT_COMP_LOGD("Received get_data_packet response: Ok, " + "packet size : %" PRIu64 "", req_len); break; case LTTNG_VIEWER_GET_PACKET_RETRY: /* Unimplemented by relay daemon */ - BT_COMP_LOGD("get_data_packet: retry"); + BT_COMP_LOGD("Received get_data_packet response: retry"); retstatus = BT_MSG_ITER_MEDIUM_STATUS_AGAIN; goto end; case LTTNG_VIEWER_GET_PACKET_ERR: @@ -1333,13 +1443,15 @@ enum bt_msg_iter_medium_status lttng_live_get_stream_bytes( retstatus = BT_MSG_ITER_MEDIUM_STATUS_AGAIN; goto end; } - BT_COMP_LOGE("get_data_packet: error"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Received get_data_packet response: error"); goto error; case LTTNG_VIEWER_GET_PACKET_EOF: retstatus = BT_MSG_ITER_MEDIUM_STATUS_EOF; goto end; default: - BT_COMP_LOGE("get_data_packet: unknown"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Received get_data_packet response: unknown"); goto error; } @@ -1349,11 +1461,14 @@ enum bt_msg_iter_medium_status lttng_live_get_stream_bytes( ret_len = lttng_live_recv(viewer_connection, buf, req_len); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving trace packet: %s", bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error receiving trace packet: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == req_len); @@ -1386,6 +1501,7 @@ enum lttng_live_iterator_status lttng_live_get_new_streams( session->lttng_live_msg_iter; struct live_viewer_connection *viewer_connection = lttng_live_msg_iter->viewer_connection; + bt_self_component *self_comp = viewer_connection->self_comp; uint32_t streams_count; const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); char cmd_buf[cmd_buf_len]; @@ -1411,19 +1527,22 @@ enum lttng_live_iterator_status lttng_live_get_new_streams( memcpy(cmd_buf + sizeof(cmd), &rq, sizeof(rq)); ret_len = lttng_live_send(viewer_connection, &cmd_buf, cmd_buf_len); if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error sending get_new_streams request: %s", - bt_socket_errormsg()); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error sending get_new_streams request: %s", + bt_socket_errormsg()); goto error; } BT_ASSERT(ret_len == cmd_buf_len); ret_len = lttng_live_recv(viewer_connection, &rp, sizeof(rp)); if (ret_len == 0) { - BT_COMP_LOGI("Remote side has closed connection"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Remote side has closed connection"); goto error; } if (ret_len == BT_SOCKET_ERROR) { - BT_COMP_LOGE("Error receiving get_new_streams response"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error receiving get_new_streams response"); goto error; } BT_ASSERT(ret_len == sizeof(rp)); @@ -1443,14 +1562,17 @@ enum lttng_live_iterator_status lttng_live_get_new_streams( status = LTTNG_LIVE_ITERATOR_STATUS_END; goto end; case LTTNG_VIEWER_NEW_STREAMS_ERR: - BT_COMP_LOGE("get_new_streams error"); + BT_COMP_LOGD("Received get_new_streams response: error"); goto error; default: - BT_COMP_LOGE("Unknown return code %u", be32toh(rp.status)); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Received get_new_streams response: Unknown:" + "return code %u", be32toh(rp.status)); goto error; } if (receive_streams(session, streams_count)) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error receiving streams"); goto error; } end: @@ -1461,6 +1583,7 @@ error: status = LTTNG_LIVE_ITERATOR_STATUS_AGAIN; } else { status = LTTNG_LIVE_ITERATOR_STATUS_ERROR; + BT_COMP_LOGE("Error receiving streams."); } return status; } @@ -1469,6 +1592,8 @@ BT_HIDDEN struct live_viewer_connection *live_viewer_connection_create( const char *url, bool in_query, struct lttng_live_msg_iter *lttng_live_msg_iter, + bt_self_component *self_comp, + bt_self_component_class *self_comp_class, bt_logging_level log_level) { struct live_viewer_connection *viewer_connection; @@ -1476,14 +1601,15 @@ struct live_viewer_connection *live_viewer_connection_create( viewer_connection = g_new0(struct live_viewer_connection, 1); if (bt_socket_init(log_level) != 0) { + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Failed to init socket"); goto error; } viewer_connection->log_level = log_level; - if (lttng_live_msg_iter) { - viewer_connection->self_comp = lttng_live_msg_iter->self_comp; - } + viewer_connection->self_comp = self_comp; + viewer_connection->self_comp_class = self_comp_class; bt_object_init_shared(&viewer_connection->obj, connection_release); viewer_connection->control_sock = BT_INVALID_SOCKET; @@ -1492,18 +1618,21 @@ struct live_viewer_connection *live_viewer_connection_create( viewer_connection->lttng_live_msg_iter = lttng_live_msg_iter; viewer_connection->url = g_string_new(url); if (!viewer_connection->url) { + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Failed to allocate URL buffer"); goto error; } BT_COMP_LOGI("Establishing connection to url \"%s\"...", url); if (lttng_live_connect_viewer(viewer_connection)) { - goto error_report; + BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, + self_comp_class, "Failed to establish connection: " + "url=\"%s\"", url); + goto error; } BT_COMP_LOGI("Connection to url \"%s\" is established", url); return viewer_connection; -error_report: - BT_COMP_LOGW("Failure to establish connection to url \"%s\"", url); error: if (viewer_connection) { live_viewer_connection_destroy(viewer_connection); diff --git a/src/plugins/ctf/lttng-live/viewer-connection.h b/src/plugins/ctf/lttng-live/viewer-connection.h index daa138a2..fcdd4c4d 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.h +++ b/src/plugins/ctf/lttng-live/viewer-connection.h @@ -49,6 +49,7 @@ struct live_viewer_connection { bt_object obj; bt_logging_level log_level; bt_self_component *self_comp; + bt_self_component_class *self_comp_class; GString *url; @@ -88,6 +89,8 @@ struct packet_index { struct live_viewer_connection * live_viewer_connection_create( const char *url, bool in_query, struct lttng_live_msg_iter *lttng_live_msg_iter, + bt_self_component *self_comp, + bt_self_component_class *self_comp_class, bt_logging_level log_level); void live_viewer_connection_destroy( -- 2.34.1