X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Flib-logging.c;h=a22e000f0ee3f56ca0b6140e1446768c5cc29600;hb=HEAD;hp=4c69d62f5b034cf778f0c0fb9bb91a6c6bb51310;hpb=335a2da576e59d32c17de2ece1e7e339c50e9c25;p=babeltrace.git diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index 4c69d62f..7ee7839e 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -1,23 +1,7 @@ /* - * Copyright 2018 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. + * SPDX-License-Identifier: MIT * - * 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. + * Copyright 2018 Philippe Proulx */ #define BT_LOG_TAG "LIB/LIB-LOGGING" @@ -28,35 +12,28 @@ #include #include #include +#include #include #include #include #include "common/common.h" -#include -#include -#include -#include +#include "common/uuid.h" +#include #include "logging.h" -#include "assert-pre.h" -#include "assert-post.h" #include "value.h" +#include "integer-range-set.h" #include "object-pool.h" +#include "graph/interrupter.h" #include "graph/component-class.h" -#include "graph/component-class-sink-colander.h" -#include "graph/component-filter.h" #include "graph/component.h" -#include "graph/component-sink.h" -#include "graph/component-source.h" #include "graph/connection.h" #include "graph/graph.h" +#include "graph/iterator.h" #include "graph/message/discarded-items.h" #include "graph/message/event.h" -#include "graph/message/iterator.h" #include "graph/message/message.h" -#include "graph/message/message-iterator-inactivity.h" #include "graph/message/packet.h" -#include "graph/message/stream-activity.h" #include "graph/message/stream.h" #include "graph/port.h" #include "plugin/plugin.h" @@ -67,15 +44,14 @@ #include "trace-ir/event.h" #include "trace-ir/field-class.h" #include "trace-ir/field.h" +#include "trace-ir/field-location.h" #include "trace-ir/field-path.h" #include "trace-ir/packet.h" #include "trace-ir/stream-class.h" #include "trace-ir/stream.h" #include "trace-ir/trace-class.h" #include "trace-ir/trace.h" -#include "trace-ir/utils.h" #include "error.h" -#include "assert-pre.h" #define LIB_LOGGING_BUF_SIZE (4096 * 4) @@ -104,11 +80,17 @@ static __thread char lib_logging_buf[LIB_LOGGING_BUF_SIZE]; #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL) -#define TMP_PREFIX_LEN 64 +#define TMP_PREFIX_LEN 128 #define SET_TMP_PREFIX(_prefix2) \ do { \ - snprintf(tmp_prefix, TMP_PREFIX_LEN - 1, "%s%s", \ - prefix, (_prefix2)); \ + int snprintf_ret = \ + snprintf(tmp_prefix, TMP_PREFIX_LEN - 1, "%s%s", \ + prefix, (_prefix2)); \ + \ + if (snprintf_ret < 0 || snprintf_ret >= TMP_PREFIX_LEN - 1) { \ + bt_common_abort(); \ + } \ + \ tmp_prefix[TMP_PREFIX_LEN - 1] = '\0'; \ } while (0) @@ -127,35 +109,22 @@ static inline void format_clock_snapshot(char **buf_ch, bool extended, static inline void format_field_path(char **buf_ch, bool extended, const char *prefix, const struct bt_field_path *field_path); -static inline void format_object(char **buf_ch, bool extended, - const char *prefix, const struct bt_object *obj) +static inline void format_field_location(char **buf_ch, bool extended , + const char *prefix, const struct bt_field_location *field_location); + +static inline void format_object(char **buf_ch, const char *prefix, + const struct bt_object *obj) { BUF_APPEND(", %sref-count=%llu", prefix, obj->ref_count); } static inline void format_uuid(char **buf_ch, bt_uuid uuid) { - BUF_APPEND("\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"", - (unsigned int) uuid[0], - (unsigned int) uuid[1], - (unsigned int) uuid[2], - (unsigned int) uuid[3], - (unsigned int) uuid[4], - (unsigned int) uuid[5], - (unsigned int) uuid[6], - (unsigned int) uuid[7], - (unsigned int) uuid[8], - (unsigned int) uuid[9], - (unsigned int) uuid[10], - (unsigned int) uuid[11], - (unsigned int) uuid[12], - (unsigned int) uuid[13], - (unsigned int) uuid[14], - (unsigned int) uuid[15]); + BUF_APPEND("\"" BT_UUID_FMT "\"", BT_UUID_FMT_VALUES(uuid)); } -static inline void format_object_pool(char **buf_ch, bool extended, - const char *prefix, const struct bt_object_pool *pool) +static inline void format_object_pool(char **buf_ch, const char *prefix, + const struct bt_object_pool *pool) { BUF_APPEND(", %ssize=%zu", PRFIELD(pool->size)); @@ -164,8 +133,7 @@ static inline void format_object_pool(char **buf_ch, bool extended, } } -static inline void format_integer_field_class(char **buf_ch, - bool extended, const char *prefix, +static inline void format_integer_field_class(char **buf_ch, const char *prefix, const struct bt_field_class *field_class) { const struct bt_field_class_integer *int_fc = @@ -176,8 +144,7 @@ static inline void format_integer_field_class(char **buf_ch, PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc->base))); } -static inline void format_array_field_class(char **buf_ch, - bool extended, const char *prefix, +static inline void format_array_field_class(char **buf_ch, const char *prefix, const struct bt_field_class *field_class) { const struct bt_field_class_array *array_fc = @@ -188,6 +155,13 @@ static inline void format_array_field_class(char **buf_ch, PRFIELD(bt_common_field_class_type_string(array_fc->element_fc->type))); } +static inline void format_blob_field_class(char **buf_ch, const char *prefix, + const struct bt_field_class_blob *field_class) +{ + BUF_APPEND(", %smedia-type=\"%s\"", + PRFIELD(field_class->media_type->str)); +} + static inline void format_field_class(char **buf_ch, bool extended, const char *prefix, const struct bt_field_class *field_class) { @@ -205,18 +179,19 @@ static inline void format_field_class(char **buf_ch, bool extended, } switch (field_class->type) { - case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: - case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: + case BT_FIELD_CLASS_TYPE_BIT_ARRAY: { - format_integer_field_class(buf_ch, extended, prefix, field_class); + const struct bt_field_class_bit_array *ba_fc = + (const void *) field_class; + + BUF_APPEND(", %slength=%" PRIu64 ", %sflag-count=%u", + PRFIELD(ba_fc->length), PRFIELD(ba_fc->flags->len)); break; } - case BT_FIELD_CLASS_TYPE_REAL: + case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: + case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: { - const struct bt_field_class_real *real_fc = (void *) field_class; - - BUF_APPEND(", %sis-single-precision=%d", - PRFIELD(real_fc->is_single_precision)); + format_integer_field_class(buf_ch, prefix, field_class); break; } case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: @@ -225,7 +200,7 @@ static inline void format_field_class(char **buf_ch, bool extended, const struct bt_field_class_enumeration *enum_fc = (const void *) field_class; - format_integer_field_class(buf_ch, extended, prefix, field_class); + format_integer_field_class(buf_ch, prefix, field_class); BUF_APPEND(", %smapping-count=%u", PRFIELD(enum_fc->mappings->len)); break; @@ -244,35 +219,90 @@ static inline void format_field_class(char **buf_ch, bool extended, } case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: { - const struct bt_field_class_static_array *array_fc = + const struct bt_field_class_array_static *array_fc = (const void *) field_class; - format_array_field_class(buf_ch, extended, prefix, field_class); + format_array_field_class(buf_ch, prefix, field_class); BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_fc->length)); break; } - case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: { - const struct bt_field_class_dynamic_array *array_fc = + const struct bt_field_class_array_dynamic *array_fc = (const void *) field_class; - format_array_field_class(buf_ch, extended, prefix, field_class); - - if (array_fc->length_fc) { - SET_TMP_PREFIX("length-fc-"); - format_field_class(buf_ch, extended, tmp_prefix, - array_fc->length_fc); + format_array_field_class(buf_ch, prefix, field_class); + + if (field_class->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD) { + switch (array_fc->length_field.xref_kind) { + case FIELD_XREF_KIND_PATH: + BT_ASSERT(array_fc->length_field.path.class); + SET_TMP_PREFIX("length-fc-"); + format_field_class(buf_ch, extended, tmp_prefix, + array_fc->length_field.path.class); + + if (array_fc->length_field.path.path) { + SET_TMP_PREFIX("length-field-path-"); + format_field_path(buf_ch, extended, tmp_prefix, + array_fc->length_field.path.path); + } + break; + case FIELD_XREF_KIND_LOCATION: + BT_ASSERT(array_fc->length_field.location); + SET_TMP_PREFIX("length-fl-"); + format_field_location(buf_ch, extended, tmp_prefix, + array_fc->length_field.location); + break; + } } - if (array_fc->length_field_path) { - SET_TMP_PREFIX("length-field-path-"); - format_field_path(buf_ch, extended, tmp_prefix, - array_fc->length_field_path); + break; + } + case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD: + { + const struct bt_field_class_option *opt_fc = + (const void *) field_class; + + BUF_APPEND(", %scontent-fc-addr=%p, %scontent-fc-type=%s", + PRFIELD(opt_fc->content_fc), + PRFIELD(bt_common_field_class_type_string(opt_fc->content_fc->type))); + + if (field_class->type != + BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD) { + const struct bt_field_class_option_with_selector_field *opt_with_sel_fc = + (const void *) field_class; + + switch (opt_with_sel_fc->selector_field_xref_kind) { + case FIELD_XREF_KIND_PATH: + BT_ASSERT(opt_with_sel_fc->selector_field.path.class); + SET_TMP_PREFIX("selector-fc-"); + format_field_class(buf_ch, extended, tmp_prefix, + opt_with_sel_fc->selector_field.path.class); + + if (opt_with_sel_fc->selector_field.path.path) { + SET_TMP_PREFIX("selector-field-path-"); + format_field_path(buf_ch, extended, tmp_prefix, + opt_with_sel_fc->selector_field.path.path); + } + break; + case FIELD_XREF_KIND_LOCATION: + BT_ASSERT_DBG(opt_with_sel_fc->selector_field.location); + SET_TMP_PREFIX("selector-fl-"); + format_field_location(buf_ch, extended, tmp_prefix, + opt_with_sel_fc->selector_field.location); + break; + } } break; } - case BT_FIELD_CLASS_TYPE_VARIANT: + case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD: { const struct bt_field_class_variant *var_fc = (const void *) field_class; @@ -282,16 +312,59 @@ static inline void format_field_class(char **buf_ch, bool extended, PRFIELD(var_fc->common.named_fcs->len)); } - if (var_fc->selector_fc) { - SET_TMP_PREFIX("selector-fc-"); - format_field_class(buf_ch, extended, tmp_prefix, - var_fc->selector_fc); + if (field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || + field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD) { + const struct bt_field_class_variant_with_selector_field *var_with_sel_fc = + (const void *) var_fc; + + switch (var_with_sel_fc->selector_field_xref_kind) { + case FIELD_XREF_KIND_PATH: + BT_ASSERT(var_with_sel_fc->selector_field.path.class); + SET_TMP_PREFIX("selector-fc-"); + format_field_class(buf_ch, extended, tmp_prefix, + var_with_sel_fc->selector_field.path.class); + + + if (var_with_sel_fc->selector_field.path.path) { + SET_TMP_PREFIX("selector-field-path-"); + format_field_path(buf_ch, extended, tmp_prefix, + var_with_sel_fc->selector_field.path.path); + } + break; + case FIELD_XREF_KIND_LOCATION: + BT_ASSERT(var_with_sel_fc->selector_field.location); + SET_TMP_PREFIX("selector-fl-"); + format_field_location(buf_ch, extended, tmp_prefix, + var_with_sel_fc->selector_field.location); + break; + } } - if (var_fc->selector_field_path) { - SET_TMP_PREFIX("selector-field-path-"); - format_field_path(buf_ch, extended, tmp_prefix, - var_fc->selector_field_path); + break; + } + case BT_FIELD_CLASS_TYPE_STATIC_BLOB: + { + const struct bt_field_class_blob_static *blob_fc = + (const void *) field_class; + + format_blob_field_class(buf_ch, prefix, (const void *) blob_fc); + BUF_APPEND(", %slength=%" PRIu64, PRFIELD(blob_fc->length)); + break; + } + case BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITHOUT_LENGTH_FIELD: + case BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD: + { + const struct bt_field_class_blob_dynamic *blob_fc = + (const void *) field_class; + + format_blob_field_class(buf_ch, prefix, (const void *) blob_fc); + + if (field_class->type == BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD) { + BT_ASSERT(blob_fc->length_fl); + SET_TMP_PREFIX("length-fl-"); + format_field_location(buf_ch, extended, tmp_prefix, + blob_fc->length_fl); + break; } break; @@ -317,6 +390,8 @@ static inline void format_field_integer_extended(char **buf_ch, fmt = ", %svalue=%" PRIx64; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" if (field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) { if (!fmt) { @@ -331,6 +406,7 @@ static inline void format_field_integer_extended(char **buf_ch, BUF_APPEND(fmt, PRFIELD(integer->value.u)); } +#pragma GCC diagnostic pop } static inline void format_field(char **buf_ch, bool extended, @@ -356,6 +432,21 @@ static inline void format_field(char **buf_ch, bool extended, } switch (field->class->type) { + case BT_FIELD_CLASS_TYPE_BOOL: + { + const struct bt_field_bool *bool_field = (const void *) field; + + BUF_APPEND(", %svalue=%d", PRFIELD(bool_field->value)); + break; + } + case BT_FIELD_CLASS_TYPE_BIT_ARRAY: + { + const struct bt_field_bit_array *ba_field = (const void *) field; + + BUF_APPEND(", %svalue-as-int=%" PRIx64, + PRFIELD(ba_field->value_as_int)); + break; + } case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: @@ -364,7 +455,8 @@ static inline void format_field(char **buf_ch, bool extended, format_field_integer_extended(buf_ch, prefix, field); break; } - case BT_FIELD_CLASS_TYPE_REAL: + case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: + case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: { const struct bt_field_real *real_field = (const void *) field; @@ -384,7 +476,8 @@ static inline void format_field(char **buf_ch, bool extended, break; } case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: - case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: { const struct bt_field_array *array_field = (const void *) field; @@ -397,7 +490,9 @@ static inline void format_field(char **buf_ch, bool extended, break; } - case BT_FIELD_CLASS_TYPE_VARIANT: + case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD: { const struct bt_field_variant *var_field = (const void *) field; @@ -426,7 +521,7 @@ static inline void format_field_path(char **buf_ch, bool extended, } BUF_APPEND(", %spath=[%s", - PRFIELD(bt_common_scope_string(field_path->root))); + PRFIELD(bt_common_field_path_scope_string(field_path->root))); for (i = 0; i < bt_field_path_get_item_count(field_path); i++) { const struct bt_field_path_item *fp_item = @@ -441,13 +536,40 @@ static inline void format_field_path(char **buf_ch, bool extended, BUF_APPEND("%s", ", "); break; default: - abort(); + bt_common_abort(); } } BUF_APPEND("%s", "]"); } +static inline void format_field_location(char **buf_ch, bool extended, + const char *prefix, const struct bt_field_location *field_location) +{ + uint64_t i; + + BT_ASSERT(field_location->items); + + BUF_APPEND(", %sitem-count=%u", PRFIELD(field_location->items->len)); + + if (!extended) { + return; + } + + BUF_APPEND(", %sloc=[%s", + PRFIELD(bt_common_field_location_scope_string(field_location->scope))); + + for (i = 0; i < bt_field_location_get_item_count(field_location); i++) { + const char *item = + bt_field_location_get_item_by_index (field_location, i); + + BUF_APPEND(", %s", item); + break; + } + + BUF_APPEND("%s", "]"); +} + static inline void format_trace_class(char **buf_ch, bool extended, const char *prefix, const struct bt_trace_class *trace_class) { @@ -471,16 +593,26 @@ static inline void format_trace(char **buf_ch, bool extended, { char tmp_prefix[TMP_PREFIX_LEN]; - if (trace->name.value) { - BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name.value)); + if (trace->ns) { + BUF_APPEND(", %snamespace=\"%s\"", PRFIELD(trace->ns)); + } + + if (trace->name) { + BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name)); } if (!extended) { return; } - if (trace->uuid.value) { - BUF_APPEND_UUID(trace->uuid.value); + if (trace->class->mip_version >= 1) { + if (trace->uid_or_uuid.uid) { + BUF_APPEND(", %suid=\"%s\"", PRFIELD(trace->uid_or_uuid.uid)); + } + } else { + if (trace->uid_or_uuid.uuid.value) { + BUF_APPEND_UUID(trace->uid_or_uuid.uuid.value); + } } BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen)); @@ -508,9 +640,16 @@ static inline void format_stream_class(char **buf_ch, bool extended, BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream_class->id)); - if (stream_class->name.value) { - BUF_APPEND(", %sname=\"%s\"", - PRFIELD(stream_class->name.value)); + if (stream_class->ns) { + BUF_APPEND(", %snamespace=\"%s\"", PRFIELD(stream_class->ns)); + } + + if (stream_class->name) { + BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class->name)); + } + + if (stream_class->uid) { + BUF_APPEND(", %suid=\"%s\"", PRFIELD(stream_class->uid)); } if (!extended) { @@ -534,14 +673,16 @@ static inline void format_stream_class(char **buf_ch, bool extended, } BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, " - "%spackets-have-default-beginning-cs=%d, " - "%spackets-have-default-end-cs=%d, " + "%ssupports-packets=%d, " + "%spackets-have-begin-default-cs=%d, " + "%spackets-have-end-default-cs=%d, " "%ssupports-discarded-events=%d, " "%sdiscarded-events-have-default-cs=%d, " "%ssupports-discarded-packets=%d, " "%sdiscarded-packets-have-default-cs=%d", PRFIELD(stream_class->assigns_automatic_event_class_id), PRFIELD(stream_class->assigns_automatic_stream_id), + PRFIELD(stream_class->supports_packets), PRFIELD(stream_class->packets_have_beginning_default_clock_snapshot), PRFIELD(stream_class->packets_have_end_default_clock_snapshot), PRFIELD(stream_class->supports_discarded_events), @@ -552,7 +693,7 @@ static inline void format_stream_class(char **buf_ch, bool extended, SET_TMP_PREFIX("trace-class-"); format_trace_class(buf_ch, false, tmp_prefix, trace_class); SET_TMP_PREFIX("pcf-pool-"); - format_object_pool(buf_ch, extended, tmp_prefix, + format_object_pool(buf_ch, tmp_prefix, &stream_class->packet_context_field_pool); } @@ -565,9 +706,16 @@ static inline void format_event_class(char **buf_ch, bool extended, BUF_APPEND(", %sid=%" PRIu64, PRFIELD(event_class->id)); - if (event_class->name.value) { - BUF_APPEND(", %sname=\"%s\"", - PRFIELD(event_class->name.value)); + if (event_class->ns) { + BUF_APPEND(", %snamespace=\"%s\"", PRFIELD(event_class->ns)); + } + + if (event_class->name) { + BUF_APPEND(", %sname=\"%s\"", PRFIELD(event_class->name)); + } + + if (event_class->uid) { + BUF_APPEND(", %suid=\"%s\"", PRFIELD(event_class->uid)); } if (!extended) { @@ -582,9 +730,9 @@ static inline void format_event_class(char **buf_ch, bool extended, (int) event_class->log_level.value))); } - if (event_class->emf_uri.value) { + if (event_class->emf_uri) { BUF_APPEND(", %semf-uri=\"%s\"", - PRFIELD(event_class->emf_uri.value)); + PRFIELD(event_class->emf_uri)); } BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p", @@ -608,8 +756,7 @@ static inline void format_event_class(char **buf_ch, bool extended, SET_TMP_PREFIX("trace-class-"); format_trace_class(buf_ch, false, tmp_prefix, trace_class); SET_TMP_PREFIX("event-pool-"); - format_object_pool(buf_ch, extended, tmp_prefix, - &event_class->event_pool); + format_object_pool(buf_ch, tmp_prefix, &event_class->event_pool); } static inline void format_stream(char **buf_ch, bool extended, @@ -622,8 +769,8 @@ static inline void format_stream(char **buf_ch, bool extended, BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream->id)); - if (stream->name.value) { - BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream->name.value)); + if (stream->name) { + BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream->name)); } if (!extended) { @@ -652,7 +799,7 @@ static inline void format_stream(char **buf_ch, bool extended, } SET_TMP_PREFIX("packet-pool-"); - format_object_pool(buf_ch, extended, tmp_prefix, &stream->packet_pool); + format_object_pool(buf_ch, tmp_prefix, &stream->packet_pool); } static inline void format_packet(char **buf_ch, bool extended, @@ -690,8 +837,6 @@ static inline void format_packet(char **buf_ch, bool extended, static inline void format_event(char **buf_ch, bool extended, const char *prefix, const struct bt_event *event) { - const struct bt_packet *packet; - const struct bt_stream *stream; const struct bt_trace_class *trace_class; const struct bt_stream_class *stream_class; char tmp_prefix[TMP_PREFIX_LEN]; @@ -734,22 +879,17 @@ static inline void format_event(char **buf_ch, bool extended, } } - packet = bt_event_borrow_packet_const(event); - if (!packet) { - return; + if (event->stream) { + BUF_APPEND(", %sstream-addr=%p", PRFIELD(event->stream)); + SET_TMP_PREFIX("stream-"); + format_stream(buf_ch, false, tmp_prefix, event->stream); } - BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet)); - SET_TMP_PREFIX("packet-"); - format_packet(buf_ch, false, tmp_prefix, packet); - stream = bt_packet_borrow_stream_const(packet); - if (!stream) { - return; + if (event->packet) { + BUF_APPEND(", %spacket-addr=%p", PRFIELD(event->packet)); + SET_TMP_PREFIX("packet-"); + format_packet(buf_ch, false, tmp_prefix, event->packet); } - - BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream)); - SET_TMP_PREFIX("stream-"); - format_stream(buf_ch, false, tmp_prefix, stream); } static inline void format_clock_class(char **buf_ch, bool extended, @@ -757,8 +897,16 @@ static inline void format_clock_class(char **buf_ch, bool extended, { char tmp_prefix[TMP_PREFIX_LEN]; - if (clock_class->name.value) { - BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name.value)); + if (clock_class->ns) { + BUF_APPEND(", %snamepace=\"%s\"", PRFIELD(clock_class->ns)); + } + + if (clock_class->name) { + BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name)); + } + + if (clock_class->uid) { + BUF_APPEND(", %suid=\"%s\"", PRFIELD(clock_class->uid)); } BUF_APPEND(", %sfreq=%" PRIu64, PRFIELD(clock_class->frequency)); @@ -767,28 +915,42 @@ static inline void format_clock_class(char **buf_ch, bool extended, return; } - if (clock_class->description.value) { + if (clock_class->description) { BUF_APPEND(", %spartial-descr=\"%.32s\"", - PRFIELD(clock_class->description.value)); + PRFIELD(clock_class->description)); } if (clock_class->uuid.value) { BUF_APPEND_UUID(clock_class->uuid.value); } - BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64 ", " - "%soffset-s=%" PRId64 ", " - "%soffset-cycles=%" PRIu64 ", %sorigin-is-unix-epoch=%d, " + BUF_APPEND(", %sis-frozen=%d", PRFIELD(clock_class->frozen)); + + if (clock_class->precision.base.avail) { + BUF_APPEND(", %sprecision=%" PRIu64, + PRFIELD(clock_class->precision.value)); + } + + if (clock_class->accuracy.base.avail) { + BUF_APPEND(", %saccuracy=%" PRIu64, + PRFIELD(clock_class->accuracy.value)); + } + + BUF_APPEND(", %soffset-s=%" PRId64 ", " + "%soffset-cycles=%" PRIu64 ", " + "%sorigin-namespace=%s, " + "%sorigin-name=%s, " + "%sorigin-uid=%s, " "%sbase-offset-ns=%" PRId64, - PRFIELD(clock_class->frozen), PRFIELD(clock_class->precision), PRFIELD(clock_class->offset_seconds), PRFIELD(clock_class->offset_cycles), - PRFIELD(clock_class->origin_is_unix_epoch), + PRFIELD(clock_class->origin.ns), + PRFIELD(clock_class->origin.name), + PRFIELD(clock_class->origin.uid), PRFIELD(clock_class->base_offset.value_ns)); SET_TMP_PREFIX("cs-pool-"); - format_object_pool(buf_ch, extended, tmp_prefix, - &clock_class->cs_pool); + format_object_pool(buf_ch, tmp_prefix, &clock_class->cs_pool); } static inline void format_clock_snapshot(char **buf_ch, bool extended, @@ -814,6 +976,12 @@ static inline void format_clock_snapshot(char **buf_ch, bool extended, } } +static inline void format_interrupter(char **buf_ch, const char *prefix, + const struct bt_interrupter *intr) +{ + BUF_APPEND(", %sis-set=%d", PRFIELD(intr->is_set)); +} + static inline void format_value(char **buf_ch, bool extended, const char *prefix, const struct bt_value *value) { @@ -835,13 +1003,13 @@ static inline void format_value(char **buf_ch, bool extended, case BT_VALUE_TYPE_UNSIGNED_INTEGER: { BUF_APPEND(", %svalue=%" PRIu64, - PRFIELD(bt_value_unsigned_integer_get(value))); + PRFIELD(bt_value_integer_unsigned_get(value))); break; } case BT_VALUE_TYPE_SIGNED_INTEGER: { BUF_APPEND(", %svalue=%" PRId64, - PRFIELD(bt_value_signed_integer_get(value))); + PRFIELD(bt_value_integer_signed_get(value))); break; } case BT_VALUE_TYPE_REAL: @@ -860,9 +1028,8 @@ static inline void format_value(char **buf_ch, bool extended, } case BT_VALUE_TYPE_ARRAY: { - int64_t count = bt_value_array_get_size(value); + uint64_t count = bt_value_array_get_length(value); - BT_ASSERT(count >= 0); BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); break; } @@ -879,13 +1046,26 @@ static inline void format_value(char **buf_ch, bool extended, } } +static inline void format_integer_range_set(char **buf_ch, bool extended, + const char *prefix, + const struct bt_integer_range_set *range_set) +{ + BUF_APPEND(", %srange-count=%u", PRFIELD(range_set->ranges->len)); + + if (!extended) { + return; + } + + BUF_APPEND(", %sis-frozen=%d", PRFIELD(range_set->frozen)); +} + static inline void format_message(char **buf_ch, bool extended, const char *prefix, const struct bt_message *msg) { char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %stype=%s", - PRFIELD(bt_message_type_string(msg->type))); + PRFIELD(bt_common_message_type_string(msg->type))); if (!extended) { return; @@ -925,28 +1105,14 @@ static inline void format_message(char **buf_ch, bool extended, msg_stream->stream); } - break; - } - case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING: - case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END: - { - const struct bt_message_stream_activity *msg_stream_activity = - (const void *) msg; - - if (msg_stream_activity->stream) { - SET_TMP_PREFIX("stream-"); - format_stream(buf_ch, true, tmp_prefix, - msg_stream_activity->stream); - } - BUF_APPEND(", %sdefault-cs-state=%s", - PRFIELD(bt_message_stream_activity_clock_snapshot_state_string( - msg_stream_activity->default_cs_state))); + PRFIELD(bt_message_stream_clock_snapshot_state_string( + msg_stream->default_cs_state))); - if (msg_stream_activity->default_cs) { + if (msg_stream->default_cs_state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) { SET_TMP_PREFIX("default-cs-"); format_clock_snapshot(buf_ch, true, tmp_prefix, - msg_stream_activity->default_cs); + msg_stream->default_cs); } break; @@ -983,13 +1149,13 @@ static inline void format_message(char **buf_ch, bool extended, } if (msg_disc_items->default_begin_cs) { - SET_TMP_PREFIX("default-begin-cs-"); + SET_TMP_PREFIX("begin-default-cs-"); format_clock_snapshot(buf_ch, true, tmp_prefix, msg_disc_items->default_begin_cs); } if (msg_disc_items->default_end_cs) { - SET_TMP_PREFIX("default-end-cs-"); + SET_TMP_PREFIX("end-default-cs-"); format_clock_snapshot(buf_ch, true, tmp_prefix, msg_disc_items->default_end_cs); } @@ -1024,7 +1190,7 @@ static inline void format_component_class(char **buf_ch, bool extended, char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %stype=%s, %sname=\"%s\"", - PRFIELD(bt_component_class_type_string(comp_class->type)), + PRFIELD(bt_common_component_class_type_string(comp_class->type)), PRFIELD_GSTRING(comp_class->name)); if (comp_class->description) { @@ -1121,9 +1287,7 @@ static inline void format_graph(char **buf_ch, bool extended, { char tmp_prefix[TMP_PREFIX_LEN]; - BUF_APPEND(", %sis-canceled=%d, %scan-consume=%d, " - "%sconfig-state=%s", - PRFIELD(graph->canceled), + BUF_APPEND(", %scan-consume=%d, %sconfig-state=%s", PRFIELD(graph->can_consume), PRFIELD(bt_graph_configuration_state_string(graph->config_state))); @@ -1142,80 +1306,45 @@ static inline void format_graph(char **buf_ch, bool extended, } SET_TMP_PREFIX("en-pool-"); - format_object_pool(buf_ch, extended, tmp_prefix, - &graph->event_msg_pool); + format_object_pool(buf_ch, tmp_prefix, &graph->event_msg_pool); SET_TMP_PREFIX("pbn-pool-"); - format_object_pool(buf_ch, extended, tmp_prefix, - &graph->packet_begin_msg_pool); + format_object_pool(buf_ch, tmp_prefix, &graph->packet_begin_msg_pool); SET_TMP_PREFIX("pen-pool-"); - format_object_pool(buf_ch, extended, tmp_prefix, - &graph->packet_end_msg_pool); + format_object_pool(buf_ch, tmp_prefix, &graph->packet_end_msg_pool); } static inline void format_message_iterator(char **buf_ch, bool extended, const char *prefix, const struct bt_message_iterator *iterator) { - const char *type; char tmp_prefix[TMP_PREFIX_LEN]; + const struct bt_message_iterator * + port_in_iter = (const void *) iterator; - if (iterator->type == BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT) { - type = "BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT"; - } else if (iterator->type == BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT) { - type = "BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT"; - } else { - type = "(unknown)"; + if (port_in_iter->upstream_component) { + SET_TMP_PREFIX("upstream-comp-"); + format_component(buf_ch, false, tmp_prefix, + port_in_iter->upstream_component); } - BUF_APPEND(", %stype=%s", PRFIELD(type)); - - switch (iterator->type) { - case BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT: - { - const struct bt_self_component_port_input_message_iterator * - port_in_iter = (const void *) iterator; - - if (port_in_iter->upstream_component) { - SET_TMP_PREFIX("upstream-comp-"); - format_component(buf_ch, false, tmp_prefix, - port_in_iter->upstream_component); - } - - if (port_in_iter->upstream_port) { - SET_TMP_PREFIX("upstream-port-"); - format_port(buf_ch, false, tmp_prefix, - port_in_iter->upstream_port); - } - - if (port_in_iter->connection) { - SET_TMP_PREFIX("upstream-conn-"); - format_connection(buf_ch, false, tmp_prefix, - port_in_iter->connection); - } - break; + if (!extended) { + goto end; } - case BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT: - { - const struct bt_port_output_message_iterator *port_out_iter = - (const void *) iterator; - - if (port_out_iter->graph) { - SET_TMP_PREFIX("graph-"); - format_graph(buf_ch, false, tmp_prefix, - port_out_iter->graph); - } - if (port_out_iter->colander) { - SET_TMP_PREFIX("colander-comp-"); - format_component(buf_ch, false, tmp_prefix, - (void *) port_out_iter->colander); - } - - break; + if (port_in_iter->upstream_port) { + SET_TMP_PREFIX("upstream-port-"); + format_port(buf_ch, false, tmp_prefix, + port_in_iter->upstream_port); } - default: - break; + + if (port_in_iter->connection) { + SET_TMP_PREFIX("upstream-conn-"); + format_connection(buf_ch, false, tmp_prefix, + port_in_iter->connection); } + +end: + return; } static inline void format_plugin(char **buf_ch, bool extended, @@ -1329,15 +1458,17 @@ static inline void format_error_cause(char **buf_ch, bool extended, if (comp_class_id) { BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", " "%splugin-name=\"%s\"", - PRFIELD(bt_component_class_type_string( + PRFIELD(bt_common_component_class_type_string( comp_class_id->type)), PRFIELD_GSTRING(comp_class_id->name), PRFIELD_GSTRING(comp_class_id->plugin_name)); } } -static inline void handle_conversion_specifier_bt(void *priv_data, - char **buf_ch, size_t avail_size, +static inline void handle_conversion_specifier_bt( + void *priv_data __attribute__((unused)), + char **buf_ch, + size_t avail_size __attribute__((unused)), const char **out_fmt_ch, va_list *args) { const char *fmt_ch = *out_fmt_ch; @@ -1397,6 +1528,9 @@ static inline void handle_conversion_specifier_bt(void *priv_data, case 'P': format_field_path(buf_ch, extended, prefix, obj); break; + case 'L': + format_field_location(buf_ch, extended, prefix, obj); + break; case 'E': format_event_class(buf_ch, extended, prefix, obj); break; @@ -1427,9 +1561,15 @@ static inline void handle_conversion_specifier_bt(void *priv_data, case 'v': format_value(buf_ch, extended, prefix, obj); break; + case 'R': + format_integer_range_set(buf_ch, extended, prefix, obj); + break; case 'n': format_message(buf_ch, extended, prefix, obj); break; + case 'I': + /* Empty, the address is automatically printed. */ + break; case 'i': format_message_iterator(buf_ch, extended, prefix, obj); break; @@ -1451,17 +1591,20 @@ static inline void handle_conversion_specifier_bt(void *priv_data, case 'g': format_graph(buf_ch, extended, prefix, obj); break; + case 'z': + format_interrupter(buf_ch, prefix, obj); + break; case 'o': - format_object_pool(buf_ch, extended, prefix, obj); + format_object_pool(buf_ch, prefix, obj); break; case 'O': - format_object(buf_ch, extended, prefix, obj); + format_object(buf_ch, prefix, obj); break; case 'r': format_error_cause(buf_ch, extended, prefix, obj); break; default: - abort(); + bt_common_abort(); } update_fmt: @@ -1469,19 +1612,47 @@ update_fmt: *out_fmt_ch = fmt_ch; } -void bt_lib_log(const char *func, const char *file, unsigned line, +/* + * This function would normally not be BT_EXPORTed, but it is used by the + * Python plugin provider, which is conceptually part of libbabeltrace2, but + * implemented as a separate shared object, for modularity. It is therefore + * exposed, but not part of the public ABI. + */ +BT_EXPORT +void bt_lib_log_v(const char *file, const char *func, unsigned line, + int lvl, const char *tag, const char *fmt, va_list *args) +{ + BT_ASSERT(fmt); + bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', + handle_conversion_specifier_bt, NULL, fmt, args); + bt_log_write(file, func, line, lvl, tag, lib_logging_buf); +} + +/* + * This function would normally not be BT_EXPORTed, but it is used by the + * Python plugin provider, which is conceptually part of libbabeltrace2, but + * implemented as a separate shared object, for modularity. It is therefore + * exposed, but not part of the public ABI. + */ +BT_EXPORT +void bt_lib_log(const char *file, const char *func, unsigned line, int lvl, const char *tag, const char *fmt, ...) { va_list args; BT_ASSERT(fmt); va_start(args, fmt); - bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', - handle_conversion_specifier_bt, NULL, fmt, &args); + bt_lib_log_v(file, func, line, lvl, tag, fmt, &args); va_end(args); - _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf); } +/* + * This function would normally not be BT_EXPORTed, but it is used by the + * Python plugin provider, which is conceptually part of libbabeltrace2, but + * implemented as a separate shared object, for modularity. It is therefore + * exposed, but not part of the ABI. + */ +BT_EXPORT void bt_lib_maybe_log_and_append_cause(const char *func, const char *file, unsigned line, int lvl, const char *tag, const char *fmt, ...) @@ -1497,12 +1668,12 @@ void bt_lib_maybe_log_and_append_cause(const char *func, const char *file, /* Log conditionally, but always append the error cause */ if (BT_LOG_ON(lvl)) { - _bt_log_write_d(func, file, line, lvl, tag, "%s", - lib_logging_buf); + bt_log_write(file, func, line, lvl, tag, lib_logging_buf); } status = bt_current_thread_error_append_cause_from_unknown( - "Babeltrace library", file, line, "%s", lib_logging_buf); + BT_LIB_LOG_LIBBABELTRACE2_NAME, file, line, "%s", + lib_logging_buf); if (status) { /* * Worst case: this error cause is not appended to the