Skip to content

Commit

Permalink
src.ctf.lttng-live: use _APPEND_CAUSE variants of logging macros
Browse files Browse the repository at this point in the history
This commit adds `BT_COMP_CLASS_LOGE()` and
`BT_COMP_OR_COMP_CLASS_LOGE()` macros for convenience.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I86b9bbe89574d40fa5e65297a166ca0e7cff54a2
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2242
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
  • Loading branch information
frdeso committed Oct 31, 2019
1 parent eee8e74 commit 1419db2
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 125 deletions.
19 changes: 19 additions & 0 deletions src/logging/comp-logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 14 additions & 1 deletion src/plugins/ctf/lttng-live/data-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -209,13 +212,17 @@ 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;
}

stream_iter->log_level = log_level;
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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
68 changes: 54 additions & 14 deletions src/plugins/ctf/lttng-live/lttng-live.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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:
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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 =
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 ", "
Expand Down Expand Up @@ -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;
}
Expand All @@ -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\"",
Expand Down Expand Up @@ -1551,23 +1581,28 @@ 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;
}

url_value = bt_value_map_borrow_entry_value_const(params, URL_PARAM);
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;
}

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;
}

Expand All @@ -1593,6 +1628,7 @@ bt_component_class_query_method_status lttng_live_query_list_sessions(
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 =
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 1419db2

Please sign in to comment.