X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Flib-logging.c;h=98572f161d4a8a5b2d9c1fd574f2d71ac4a8d887;hb=eea66fe071c54a96dcc811c4d921e5b2b59feeb3;hp=3fd96dd1ac401ecc2e55931d67b6bb1d340ef88f;hpb=5badd463e184894a3bfd5b8db257efc6f92c6374;p=babeltrace.git diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 3fd96dd1..98572f16 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include #include #include @@ -75,7 +75,7 @@ #define LIB_LOGGING_BUF_SIZE (4096 * 4) -static char __thread lib_logging_buf[LIB_LOGGING_BUF_SIZE]; +static __thread char lib_logging_buf[LIB_LOGGING_BUF_SIZE]; #define BUF_APPEND(_fmt, ...) \ do { \ @@ -100,10 +100,12 @@ static char __thread lib_logging_buf[LIB_LOGGING_BUF_SIZE]; #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL) +#define TMP_PREFIX_LEN 64 #define SET_TMP_PREFIX(_prefix2) \ do { \ - strcpy(tmp_prefix, prefix); \ - strcat(tmp_prefix, (_prefix2)); \ + snprintf(tmp_prefix, TMP_PREFIX_LEN - 1, "%s%s", \ + prefix, (_prefix2)); \ + tmp_prefix[TMP_PREFIX_LEN - 1] = '\0'; \ } while (0) static inline void format_component(char **buf_ch, bool extended, @@ -185,7 +187,7 @@ static inline void format_array_field_class(char **buf_ch, static inline void format_field_class(char **buf_ch, bool extended, const char *prefix, const struct bt_field_class *field_class) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %stype=%s", PRFIELD(bt_common_field_class_type_string(field_class->type))); @@ -409,24 +411,34 @@ static inline void format_field_path(char **buf_ch, bool extended, { uint64_t i; - if (field_path->indexes) { - BT_ASSERT(field_path->indexes); - BUF_APPEND(", %sindex-count=%u", - PRFIELD(field_path->indexes->len)); + if (field_path->items) { + BT_ASSERT(field_path->items); + BUF_APPEND(", %sitem-count=%u", + PRFIELD(field_path->items->len)); } - if (!extended || !field_path->indexes) { + if (!extended || !field_path->items) { return; } BUF_APPEND(", %spath=[%s", PRFIELD(bt_common_scope_string(field_path->root))); - for (i = 0; i < field_path->indexes->len; i++) { - uint64_t index = bt_field_path_get_index_by_index_inline( - field_path, i); - - BUF_APPEND(", %" PRIu64, index); + for (i = 0; i < bt_field_path_get_item_count(field_path); i++) { + const struct bt_field_path_item *fp_item = + bt_field_path_borrow_item_by_index_const(field_path, i); + + switch (bt_field_path_item_get_type(fp_item)) { + case BT_FIELD_PATH_ITEM_TYPE_INDEX: + BUF_APPEND(", %" PRIu64, + bt_field_path_item_index_get_index(fp_item)); + break; + case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT: + BUF_APPEND("%s", ", "); + break; + default: + abort(); + } } BUF_APPEND("%s", "]"); @@ -462,7 +474,7 @@ static inline void format_trace_class(char **buf_ch, bool extended, static inline void format_trace(char **buf_ch, bool extended, const char *prefix, const struct bt_trace *trace) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; if (trace->name.value) { BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name.value)); @@ -479,8 +491,6 @@ static inline void format_trace(char **buf_ch, bool extended, PRFIELD(trace->streams->len)); } - BUF_APPEND(", %sis-static=%d", PRFIELD(trace->is_static)); - if (!trace->class) { return; } @@ -495,7 +505,7 @@ static inline void format_stream_class(char **buf_ch, bool extended, const struct bt_stream_class *stream_class) { const struct bt_trace_class *trace_class; - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream_class->id)); @@ -540,7 +550,7 @@ static inline void format_event_class(char **buf_ch, bool extended, { const struct bt_stream_class *stream_class; const struct bt_trace_class *trace_class; - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %sid=%" PRIu64, PRFIELD(event_class->id)); @@ -597,7 +607,7 @@ static inline void format_stream(char **buf_ch, bool extended, const struct bt_stream_class *stream_class; const struct bt_trace_class *trace_class = NULL; const struct bt_trace *trace = NULL; - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream->id)); @@ -639,7 +649,7 @@ static inline void format_packet(char **buf_ch, bool extended, { const struct bt_stream *stream; const struct bt_trace_class *trace_class; - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; if (!extended) { return; @@ -673,7 +683,7 @@ static inline void format_event(char **buf_ch, bool extended, const struct bt_stream *stream; const struct bt_trace_class *trace_class; const struct bt_stream_class *stream_class; - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; if (!extended) { return; @@ -734,7 +744,7 @@ static inline void format_event(char **buf_ch, bool extended, static inline void format_clock_class(char **buf_ch, bool extended, const char *prefix, const struct bt_clock_class *clock_class) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; if (clock_class->name.value) { BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name.value)); @@ -773,7 +783,7 @@ static inline void format_clock_class(char **buf_ch, bool extended, static inline void format_clock_snapshot(char **buf_ch, bool extended, const char *prefix, const struct bt_clock_snapshot *clock_snapshot) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %svalue=%" PRIu64 ", %sns-from-origin=%" PRId64, PRFIELD(clock_snapshot->value_cycles), PRFIELD(clock_snapshot->ns_from_origin)); @@ -811,11 +821,16 @@ static inline void format_value(char **buf_ch, bool extended, BUF_APPEND(", %svalue=%d", PRFIELD(val)); break; } - case BT_VALUE_TYPE_INTEGER: + case BT_VALUE_TYPE_UNSIGNED_INTEGER: { - int64_t val = bt_value_integer_get(value); - - BUF_APPEND(", %svalue=%" PRId64, PRFIELD(val)); + BUF_APPEND(", %svalue=%" PRIu64, + PRFIELD(bt_value_unsigned_integer_get(value))); + break; + } + case BT_VALUE_TYPE_SIGNED_INTEGER: + { + BUF_APPEND(", %svalue=%" PRId64, + PRFIELD(bt_value_signed_integer_get(value))); break; } case BT_VALUE_TYPE_REAL: @@ -856,7 +871,7 @@ static inline void format_value(char **buf_ch, bool extended, static inline void format_message(char **buf_ch, bool extended, const char *prefix, const struct bt_message *msg) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %stype=%s", PRFIELD(bt_message_type_string(msg->type))); @@ -995,7 +1010,7 @@ static inline void format_component_class(char **buf_ch, bool extended, const char *prefix, const struct bt_component_class *comp_class) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %stype=%s, %sname=\"%s\"", PRFIELD(bt_component_class_type_string(comp_class->type)), @@ -1022,7 +1037,7 @@ static inline void format_component_class(char **buf_ch, bool extended, static inline void format_component(char **buf_ch, bool extended, const char *prefix, const struct bt_component *component) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %sname=\"%s\"", PRFIELD_GSTRING(component->name)); @@ -1051,7 +1066,7 @@ static inline void format_component(char **buf_ch, bool extended, static inline void format_port(char **buf_ch, bool extended, const char *prefix, const struct bt_port *port) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %stype=%s, %sname=\"%s\"", PRFIELD(bt_port_type_string(port->type)), @@ -1070,7 +1085,7 @@ static inline void format_port(char **buf_ch, bool extended, static inline void format_connection(char **buf_ch, bool extended, const char *prefix, const struct bt_connection *connection) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; if (!extended) { return; @@ -1092,7 +1107,7 @@ static inline void format_connection(char **buf_ch, bool extended, static inline void format_graph(char **buf_ch, bool extended, const char *prefix, const struct bt_graph *graph) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %sis-canceled=%d, %scan-consume=%d, " "%sconfig-state=%s", @@ -1130,7 +1145,7 @@ static inline void format_message_iterator(char **buf_ch, const struct bt_message_iterator *iterator) { const char *type; - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; if (iterator->type == BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT) { type = "BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT"; @@ -1194,7 +1209,7 @@ static inline void format_message_iterator(char **buf_ch, static inline void format_plugin(char **buf_ch, bool extended, const char *prefix, const struct bt_plugin *plugin) { - char tmp_prefix[64]; + char tmp_prefix[TMP_PREFIX_LEN]; BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin->type))); @@ -1379,7 +1394,6 @@ update_fmt: *out_fmt_ch = fmt_ch; } -BT_HIDDEN void bt_lib_log(const char *func, const char *file, unsigned line, int lvl, const char *tag, const char *fmt, ...) {