2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
7 #define BT_LOG_TAG "LIB/LIB-LOGGING"
8 #include "lib/logging.h"
19 #include "common/common.h"
20 #include "common/uuid.h"
21 #include <babeltrace2/babeltrace.h>
24 #include "assert-cond.h"
26 #include "integer-range-set.h"
27 #include "object-pool.h"
28 #include "graph/interrupter.h"
29 #include "graph/component-class.h"
30 #include "graph/component-filter.h"
31 #include "graph/component.h"
32 #include "graph/component-sink.h"
33 #include "graph/component-source.h"
34 #include "graph/connection.h"
35 #include "graph/graph.h"
36 #include "graph/message/discarded-items.h"
37 #include "graph/message/event.h"
38 #include "graph/message/iterator.h"
39 #include "graph/message/message.h"
40 #include "graph/message/message-iterator-inactivity.h"
41 #include "graph/message/packet.h"
42 #include "graph/message/stream.h"
43 #include "graph/port.h"
44 #include "plugin/plugin.h"
45 #include "plugin/plugin-so.h"
46 #include "trace-ir/clock-class.h"
47 #include "trace-ir/clock-snapshot.h"
48 #include "trace-ir/event-class.h"
49 #include "trace-ir/event.h"
50 #include "trace-ir/field-class.h"
51 #include "trace-ir/field.h"
52 #include "trace-ir/field-path.h"
53 #include "trace-ir/packet.h"
54 #include "trace-ir/stream-class.h"
55 #include "trace-ir/stream.h"
56 #include "trace-ir/trace-class.h"
57 #include "trace-ir/trace.h"
58 #include "trace-ir/utils.h"
61 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
63 static __thread
char lib_logging_buf
[LIB_LOGGING_BUF_SIZE
];
65 #define BUF_APPEND(_fmt, ...) \
68 size_t _size = LIB_LOGGING_BUF_SIZE - \
69 (size_t) (*buf_ch - lib_logging_buf); \
70 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
71 BT_ASSERT(_count >= 0); \
72 *buf_ch += MIN(_count, _size); \
73 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
78 #define BUF_APPEND_UUID(_uuid) \
80 BUF_APPEND(", %suuid=", prefix); \
81 format_uuid(buf_ch, (_uuid)); \
84 #define PRFIELD(_expr) prefix, (_expr)
86 #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL)
88 #define TMP_PREFIX_LEN 128
89 #define SET_TMP_PREFIX(_prefix2) \
92 snprintf(tmp_prefix, TMP_PREFIX_LEN - 1, "%s%s", \
93 prefix, (_prefix2)); \
95 if (snprintf_ret < 0 || snprintf_ret >= TMP_PREFIX_LEN - 1) { \
99 tmp_prefix[TMP_PREFIX_LEN - 1] = '\0'; \
102 static inline void format_component(char **buf_ch
, bool extended
,
103 const char *prefix
, const struct bt_component
*component
);
105 static inline void format_port(char **buf_ch
, bool extended
,
106 const char *prefix
, const struct bt_port
*port
);
108 static inline void format_connection(char **buf_ch
, bool extended
,
109 const char *prefix
, const struct bt_connection
*connection
);
111 static inline void format_clock_snapshot(char **buf_ch
, bool extended
,
112 const char *prefix
, const struct bt_clock_snapshot
*clock_snapshot
);
114 static inline void format_field_path(char **buf_ch
, bool extended
,
115 const char *prefix
, const struct bt_field_path
*field_path
);
117 static inline void format_object(char **buf_ch
, const char *prefix
,
118 const struct bt_object
*obj
)
120 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
123 static inline void format_uuid(char **buf_ch
, bt_uuid uuid
)
125 BUF_APPEND("\"" BT_UUID_FMT
"\"", BT_UUID_FMT_VALUES(uuid
));
128 static inline void format_object_pool(char **buf_ch
, const char *prefix
,
129 const struct bt_object_pool
*pool
)
131 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
134 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
138 static inline void format_integer_field_class(char **buf_ch
, const char *prefix
,
139 const struct bt_field_class
*field_class
)
141 const struct bt_field_class_integer
*int_fc
=
142 (const void *) field_class
;
144 BUF_APPEND(", %srange-size=%" PRIu64
", %sbase=%s",
145 PRFIELD(int_fc
->range
),
146 PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc
->base
)));
149 static inline void format_array_field_class(char **buf_ch
, const char *prefix
,
150 const struct bt_field_class
*field_class
)
152 const struct bt_field_class_array
*array_fc
=
153 (const void *) field_class
;
155 BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s",
156 PRFIELD(array_fc
->element_fc
),
157 PRFIELD(bt_common_field_class_type_string(array_fc
->element_fc
->type
)));
160 static inline void format_field_class(char **buf_ch
, bool extended
,
161 const char *prefix
, const struct bt_field_class
*field_class
)
163 char tmp_prefix
[TMP_PREFIX_LEN
];
165 BUF_APPEND(", %stype=%s",
166 PRFIELD(bt_common_field_class_type_string(field_class
->type
)));
169 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class
->frozen
));
170 BUF_APPEND(", %sis-part-of-trace-class=%d",
171 PRFIELD(field_class
->part_of_trace_class
));
176 switch (field_class
->type
) {
177 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
179 const struct bt_field_class_bit_array
*ba_fc
=
180 (const void *) field_class
;
182 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(ba_fc
->length
));
185 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
186 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
188 format_integer_field_class(buf_ch
, prefix
, field_class
);
191 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
192 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
194 const struct bt_field_class_enumeration
*enum_fc
=
195 (const void *) field_class
;
197 format_integer_field_class(buf_ch
, prefix
, field_class
);
198 BUF_APPEND(", %smapping-count=%u",
199 PRFIELD(enum_fc
->mappings
->len
));
202 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
204 const struct bt_field_class_structure
*struct_fc
=
205 (const void *) field_class
;
207 if (struct_fc
->common
.named_fcs
) {
208 BUF_APPEND(", %smember-count=%u",
209 PRFIELD(struct_fc
->common
.named_fcs
->len
));
214 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
216 const struct bt_field_class_array_static
*array_fc
=
217 (const void *) field_class
;
219 format_array_field_class(buf_ch
, prefix
, field_class
);
220 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_fc
->length
));
223 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
224 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
226 const struct bt_field_class_array_dynamic
*array_fc
=
227 (const void *) field_class
;
229 format_array_field_class(buf_ch
, prefix
, field_class
);
231 if (array_fc
->length_fc
) {
232 SET_TMP_PREFIX("length-fc-");
233 format_field_class(buf_ch
, extended
, tmp_prefix
,
234 array_fc
->length_fc
);
237 if (array_fc
->length_field_path
) {
238 SET_TMP_PREFIX("length-field-path-");
239 format_field_path(buf_ch
, extended
, tmp_prefix
,
240 array_fc
->length_field_path
);
245 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
246 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
247 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
248 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
250 const struct bt_field_class_option
*opt_fc
=
251 (const void *) field_class
;
253 BUF_APPEND(", %scontent-fc-addr=%p, %scontent-fc-type=%s",
254 PRFIELD(opt_fc
->content_fc
),
255 PRFIELD(bt_common_field_class_type_string(opt_fc
->content_fc
->type
)));
257 if (field_class
->type
!=
258 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
259 const struct bt_field_class_option_with_selector_field
*opt_with_sel_fc
=
260 (const void *) field_class
;
262 if (opt_with_sel_fc
->selector_fc
) {
263 SET_TMP_PREFIX("selector-fc-");
264 format_field_class(buf_ch
, extended
, tmp_prefix
,
265 opt_with_sel_fc
->selector_fc
);
268 if (opt_with_sel_fc
->selector_field_path
) {
269 SET_TMP_PREFIX("selector-field-path-");
270 format_field_path(buf_ch
, extended
, tmp_prefix
,
271 opt_with_sel_fc
->selector_field_path
);
277 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
278 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
279 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
281 const struct bt_field_class_variant
*var_fc
=
282 (const void *) field_class
;
284 if (var_fc
->common
.named_fcs
) {
285 BUF_APPEND(", %soption-count=%u",
286 PRFIELD(var_fc
->common
.named_fcs
->len
));
289 if (field_class
->type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
||
290 field_class
->type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
) {
291 const struct bt_field_class_variant_with_selector_field
*var_with_sel_fc
=
292 (const void *) var_fc
;
294 if (var_with_sel_fc
->selector_fc
) {
295 SET_TMP_PREFIX("selector-fc-");
296 format_field_class(buf_ch
, extended
, tmp_prefix
,
297 var_with_sel_fc
->selector_fc
);
300 if (var_with_sel_fc
->selector_field_path
) {
301 SET_TMP_PREFIX("selector-field-path-");
302 format_field_path(buf_ch
, extended
, tmp_prefix
,
303 var_with_sel_fc
->selector_field_path
);
314 static inline void format_field_integer_extended(char **buf_ch
,
315 const char *prefix
, const struct bt_field
*field
)
317 const struct bt_field_integer
*integer
= (void *) field
;
318 const struct bt_field_class_integer
*field_class
=
319 (void *) field
->class;
320 const char *fmt
= NULL
;
322 BT_ASSERT(field_class
);
324 if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
) {
325 fmt
= ", %svalue=%" PRIo64
;
326 } else if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
) {
327 fmt
= ", %svalue=%" PRIx64
;
330 #pragma GCC diagnostic push
331 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
332 if (field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
333 field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
335 fmt
= ", %svalue=%" PRId64
;
338 BUF_APPEND(fmt
, PRFIELD(integer
->value
.i
));
341 fmt
= ", %svalue=%" PRIu64
;
344 BUF_APPEND(fmt
, PRFIELD(integer
->value
.u
));
346 #pragma GCC diagnostic pop
349 static inline void format_field(char **buf_ch
, bool extended
,
350 const char *prefix
, const struct bt_field
*field
)
352 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->is_set
));
355 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
358 BUF_APPEND(", %sclass-addr=%p", PRFIELD(field
->class));
364 BUF_APPEND(", %sclass-type=%s",
365 PRFIELD(bt_common_field_class_type_string(field
->class->type
)));
367 if (!extended
|| !field
->is_set
) {
371 switch (field
->class->type
) {
372 case BT_FIELD_CLASS_TYPE_BOOL
:
374 const struct bt_field_bool
*bool_field
= (const void *) field
;
376 BUF_APPEND(", %svalue=%d", PRFIELD(bool_field
->value
));
379 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
381 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
383 BUF_APPEND(", %svalue-as-int=%" PRIx64
,
384 PRFIELD(ba_field
->value_as_int
));
387 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
388 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
389 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
390 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
392 format_field_integer_extended(buf_ch
, prefix
, field
);
395 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
396 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
398 const struct bt_field_real
*real_field
= (const void *) field
;
400 BUF_APPEND(", %svalue=%f", PRFIELD(real_field
->value
));
403 case BT_FIELD_CLASS_TYPE_STRING
:
405 const struct bt_field_string
*str
= (const void *) field
;
408 BT_ASSERT(str
->buf
->data
);
409 BUF_APPEND(", %spartial-value=\"%.32s\"",
410 PRFIELD(str
->buf
->data
));
415 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
416 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
417 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
419 const struct bt_field_array
*array_field
= (const void *) field
;
421 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_field
->length
));
423 if (array_field
->fields
) {
424 BUF_APPEND(", %sallocated-length=%u",
425 PRFIELD(array_field
->fields
->len
));
430 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
431 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
432 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
434 const struct bt_field_variant
*var_field
= (const void *) field
;
436 BUF_APPEND(", %sselected-field-index=%" PRIu64
,
437 PRFIELD(var_field
->selected_index
));
445 static inline void format_field_path(char **buf_ch
, bool extended
,
446 const char *prefix
, const struct bt_field_path
*field_path
)
450 if (field_path
->items
) {
451 BT_ASSERT(field_path
->items
);
452 BUF_APPEND(", %sitem-count=%u",
453 PRFIELD(field_path
->items
->len
));
456 if (!extended
|| !field_path
->items
) {
460 BUF_APPEND(", %spath=[%s",
461 PRFIELD(bt_common_scope_string(field_path
->root
)));
463 for (i
= 0; i
< bt_field_path_get_item_count(field_path
); i
++) {
464 const struct bt_field_path_item
*fp_item
=
465 bt_field_path_borrow_item_by_index_const(field_path
, i
);
467 switch (bt_field_path_item_get_type(fp_item
)) {
468 case BT_FIELD_PATH_ITEM_TYPE_INDEX
:
469 BUF_APPEND(", %" PRIu64
,
470 bt_field_path_item_index_get_index(fp_item
));
472 case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
:
473 BUF_APPEND("%s", ", <CUR>");
480 BUF_APPEND("%s", "]");
483 static inline void format_trace_class(char **buf_ch
, bool extended
,
484 const char *prefix
, const struct bt_trace_class
*trace_class
)
490 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class
->frozen
));
492 if (trace_class
->stream_classes
) {
493 BUF_APPEND(", %sstream-class-count=%u",
494 PRFIELD(trace_class
->stream_classes
->len
));
497 BUF_APPEND(", %sassigns-auto-sc-id=%d",
498 PRFIELD(trace_class
->assigns_automatic_stream_class_id
));
501 static inline void format_trace(char **buf_ch
, bool extended
,
502 const char *prefix
, const struct bt_trace
*trace
)
504 char tmp_prefix
[TMP_PREFIX_LEN
];
506 if (trace
->name
.value
) {
507 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
.value
));
514 if (trace
->uuid
.value
) {
515 BUF_APPEND_UUID(trace
->uuid
.value
);
518 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
520 if (trace
->streams
) {
521 BUF_APPEND(", %sstream-count=%u",
522 PRFIELD(trace
->streams
->len
));
529 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace
->class));
530 SET_TMP_PREFIX("trace-class-");
531 format_trace_class(buf_ch
, false, tmp_prefix
, trace
->class);
534 static inline void format_stream_class(char **buf_ch
, bool extended
,
536 const struct bt_stream_class
*stream_class
)
538 const struct bt_trace_class
*trace_class
;
539 char tmp_prefix
[TMP_PREFIX_LEN
];
541 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream_class
->id
));
543 if (stream_class
->name
.value
) {
544 BUF_APPEND(", %sname=\"%s\"",
545 PRFIELD(stream_class
->name
.value
));
552 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
554 if (stream_class
->event_classes
) {
555 BUF_APPEND(", %sevent-class-count=%u",
556 PRFIELD(stream_class
->event_classes
->len
));
559 BUF_APPEND(", %spacket-context-fc-addr=%p, "
560 "%sevent-common-context-fc-addr=%p",
561 PRFIELD(stream_class
->packet_context_fc
),
562 PRFIELD(stream_class
->event_common_context_fc
));
563 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
568 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
569 "%ssupports-packets=%d, "
570 "%spackets-have-begin-default-cs=%d, "
571 "%spackets-have-end-default-cs=%d, "
572 "%ssupports-discarded-events=%d, "
573 "%sdiscarded-events-have-default-cs=%d, "
574 "%ssupports-discarded-packets=%d, "
575 "%sdiscarded-packets-have-default-cs=%d",
576 PRFIELD(stream_class
->assigns_automatic_event_class_id
),
577 PRFIELD(stream_class
->assigns_automatic_stream_id
),
578 PRFIELD(stream_class
->supports_packets
),
579 PRFIELD(stream_class
->packets_have_beginning_default_clock_snapshot
),
580 PRFIELD(stream_class
->packets_have_end_default_clock_snapshot
),
581 PRFIELD(stream_class
->supports_discarded_events
),
582 PRFIELD(stream_class
->discarded_events_have_default_clock_snapshots
),
583 PRFIELD(stream_class
->supports_discarded_packets
),
584 PRFIELD(stream_class
->discarded_packets_have_default_clock_snapshots
));
585 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
586 SET_TMP_PREFIX("trace-class-");
587 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
588 SET_TMP_PREFIX("pcf-pool-");
589 format_object_pool(buf_ch
, tmp_prefix
,
590 &stream_class
->packet_context_field_pool
);
593 static inline void format_event_class(char **buf_ch
, bool extended
,
594 const char *prefix
, const struct bt_event_class
*event_class
)
596 const struct bt_stream_class
*stream_class
;
597 const struct bt_trace_class
*trace_class
;
598 char tmp_prefix
[TMP_PREFIX_LEN
];
600 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(event_class
->id
));
602 if (event_class
->name
.value
) {
603 BUF_APPEND(", %sname=\"%s\"",
604 PRFIELD(event_class
->name
.value
));
611 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class
->frozen
));
613 if (event_class
->log_level
.base
.avail
) {
614 BUF_APPEND(", %slog-level=%s",
615 PRFIELD(bt_common_event_class_log_level_string(
616 (int) event_class
->log_level
.value
)));
619 if (event_class
->emf_uri
.value
) {
620 BUF_APPEND(", %semf-uri=\"%s\"",
621 PRFIELD(event_class
->emf_uri
.value
));
624 BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
625 PRFIELD(event_class
->specific_context_fc
),
626 PRFIELD(event_class
->payload_fc
));
628 stream_class
= bt_event_class_borrow_stream_class_const(event_class
);
633 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
634 SET_TMP_PREFIX("stream-class-");
635 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
636 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
641 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
642 SET_TMP_PREFIX("trace-class-");
643 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
644 SET_TMP_PREFIX("event-pool-");
645 format_object_pool(buf_ch
, tmp_prefix
, &event_class
->event_pool
);
648 static inline void format_stream(char **buf_ch
, bool extended
,
649 const char *prefix
, const struct bt_stream
*stream
)
651 const struct bt_stream_class
*stream_class
;
652 const struct bt_trace_class
*trace_class
= NULL
;
653 const struct bt_trace
*trace
= NULL
;
654 char tmp_prefix
[TMP_PREFIX_LEN
];
656 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream
->id
));
658 if (stream
->name
.value
) {
659 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
.value
));
666 stream_class
= bt_stream_borrow_class_const(stream
);
668 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
669 SET_TMP_PREFIX("stream-class-");
670 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
671 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
675 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
676 SET_TMP_PREFIX("trace-class-");
677 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
680 trace
= bt_stream_borrow_trace_inline(stream
);
682 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
683 SET_TMP_PREFIX("trace-");
684 format_trace(buf_ch
, false, tmp_prefix
, trace
);
687 SET_TMP_PREFIX("packet-pool-");
688 format_object_pool(buf_ch
, tmp_prefix
, &stream
->packet_pool
);
691 static inline void format_packet(char **buf_ch
, bool extended
,
692 const char *prefix
, const struct bt_packet
*packet
)
694 const struct bt_stream
*stream
;
695 const struct bt_trace_class
*trace_class
;
696 char tmp_prefix
[TMP_PREFIX_LEN
];
702 BUF_APPEND(", %sis-frozen=%d, %scontext-field-addr=%p",
703 PRFIELD(packet
->frozen
),
704 PRFIELD(packet
->context_field
? packet
->context_field
->field
: NULL
));
705 stream
= bt_packet_borrow_stream_const(packet
);
710 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
711 SET_TMP_PREFIX("stream-");
712 format_stream(buf_ch
, false, tmp_prefix
, stream
);
713 trace_class
= (const struct bt_trace_class
*) bt_object_borrow_parent(&stream
->base
);
718 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
719 SET_TMP_PREFIX("trace-class-");
720 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
723 static inline void format_event(char **buf_ch
, bool extended
,
724 const char *prefix
, const struct bt_event
*event
)
726 const struct bt_trace_class
*trace_class
;
727 const struct bt_stream_class
*stream_class
;
728 char tmp_prefix
[TMP_PREFIX_LEN
];
734 BUF_APPEND(", %sis-frozen=%d, "
735 "%scommon-context-field-addr=%p, "
736 "%sspecific-context-field-addr=%p, "
737 "%spayload-field-addr=%p, ",
738 PRFIELD(event
->frozen
),
739 PRFIELD(event
->common_context_field
),
740 PRFIELD(event
->specific_context_field
),
741 PRFIELD(event
->payload_field
));
742 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
748 SET_TMP_PREFIX("event-class-");
749 format_event_class(buf_ch
, false, tmp_prefix
, event
->class);
750 stream_class
= bt_event_class_borrow_stream_class(event
->class);
752 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
753 SET_TMP_PREFIX("stream-class-");
754 format_stream_class(buf_ch
, false, tmp_prefix
,
757 trace_class
= bt_stream_class_borrow_trace_class_inline(
760 BUF_APPEND(", %strace-class-addr=%p",
761 PRFIELD(trace_class
));
762 SET_TMP_PREFIX("trace-class-");
763 format_trace_class(buf_ch
, false, tmp_prefix
,
769 BUF_APPEND(", %sstream-addr=%p", PRFIELD(event
->stream
));
770 SET_TMP_PREFIX("stream-");
771 format_stream(buf_ch
, false, tmp_prefix
, event
->stream
);
775 BUF_APPEND(", %spacket-addr=%p", PRFIELD(event
->packet
));
776 SET_TMP_PREFIX("packet-");
777 format_packet(buf_ch
, false, tmp_prefix
, event
->packet
);
781 static inline void format_clock_class(char **buf_ch
, bool extended
,
782 const char *prefix
, const struct bt_clock_class
*clock_class
)
784 char tmp_prefix
[TMP_PREFIX_LEN
];
786 if (clock_class
->name
.value
) {
787 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class
->name
.value
));
790 BUF_APPEND(", %sfreq=%" PRIu64
, PRFIELD(clock_class
->frequency
));
796 if (clock_class
->description
.value
) {
797 BUF_APPEND(", %spartial-descr=\"%.32s\"",
798 PRFIELD(clock_class
->description
.value
));
801 if (clock_class
->uuid
.value
) {
802 BUF_APPEND_UUID(clock_class
->uuid
.value
);
805 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
806 "%soffset-s=%" PRId64
", "
807 "%soffset-cycles=%" PRIu64
", %sorigin-is-unix-epoch=%d, "
808 "%sbase-offset-ns=%" PRId64
,
809 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
810 PRFIELD(clock_class
->offset_seconds
),
811 PRFIELD(clock_class
->offset_cycles
),
812 PRFIELD(clock_class
->origin_is_unix_epoch
),
813 PRFIELD(clock_class
->base_offset
.value_ns
));
815 SET_TMP_PREFIX("cs-pool-");
816 format_object_pool(buf_ch
, tmp_prefix
, &clock_class
->cs_pool
);
819 static inline void format_clock_snapshot(char **buf_ch
, bool extended
,
820 const char *prefix
, const struct bt_clock_snapshot
*clock_snapshot
)
822 char tmp_prefix
[TMP_PREFIX_LEN
];
823 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-origin=%" PRId64
,
824 PRFIELD(clock_snapshot
->value_cycles
),
825 PRFIELD(clock_snapshot
->ns_from_origin
));
831 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_snapshot
->is_set
));
833 if (clock_snapshot
->clock_class
) {
834 BUF_APPEND(", %sclock-class-addr=%p",
835 PRFIELD(clock_snapshot
->clock_class
));
836 SET_TMP_PREFIX("clock-class-");
837 format_clock_class(buf_ch
, false, tmp_prefix
,
838 clock_snapshot
->clock_class
);
842 static inline void format_interrupter(char **buf_ch
, const char *prefix
,
843 const struct bt_interrupter
*intr
)
845 BUF_APPEND(", %sis-set=%d", PRFIELD(intr
->is_set
));
848 static inline void format_value(char **buf_ch
, bool extended
,
849 const char *prefix
, const struct bt_value
*value
)
851 BUF_APPEND(", %stype=%s",
852 PRFIELD(bt_common_value_type_string(bt_value_get_type(value
))));
858 switch (bt_value_get_type(value
)) {
859 case BT_VALUE_TYPE_BOOL
:
861 bt_bool val
= bt_value_bool_get(value
);
863 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
866 case BT_VALUE_TYPE_UNSIGNED_INTEGER
:
868 BUF_APPEND(", %svalue=%" PRIu64
,
869 PRFIELD(bt_value_integer_unsigned_get(value
)));
872 case BT_VALUE_TYPE_SIGNED_INTEGER
:
874 BUF_APPEND(", %svalue=%" PRId64
,
875 PRFIELD(bt_value_integer_signed_get(value
)));
878 case BT_VALUE_TYPE_REAL
:
880 double val
= bt_value_real_get(value
);
882 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
885 case BT_VALUE_TYPE_STRING
:
887 const char *val
= bt_value_string_get(value
);
889 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
892 case BT_VALUE_TYPE_ARRAY
:
894 uint64_t count
= bt_value_array_get_length(value
);
896 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
899 case BT_VALUE_TYPE_MAP
:
901 int64_t count
= bt_value_map_get_size(value
);
903 BT_ASSERT(count
>= 0);
904 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
912 static inline void format_integer_range_set(char **buf_ch
, bool extended
,
914 const struct bt_integer_range_set
*range_set
)
916 BUF_APPEND(", %srange-count=%u", PRFIELD(range_set
->ranges
->len
));
922 BUF_APPEND(", %sis-frozen=%d", PRFIELD(range_set
->frozen
));
925 static inline void format_message(char **buf_ch
, bool extended
,
926 const char *prefix
, const struct bt_message
*msg
)
928 char tmp_prefix
[TMP_PREFIX_LEN
];
930 BUF_APPEND(", %stype=%s",
931 PRFIELD(bt_common_message_type_string(msg
->type
)));
937 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
938 PRFIELD(msg
->frozen
), PRFIELD(msg
->graph
));
941 case BT_MESSAGE_TYPE_EVENT
:
943 const struct bt_message_event
*msg_event
=
946 if (msg_event
->event
) {
947 SET_TMP_PREFIX("event-");
948 format_event(buf_ch
, true, tmp_prefix
,
952 if (msg_event
->default_cs
) {
953 SET_TMP_PREFIX("default-cs-");
954 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
955 msg_event
->default_cs
);
960 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
961 case BT_MESSAGE_TYPE_STREAM_END
:
963 const struct bt_message_stream
*msg_stream
= (const void *) msg
;
965 if (msg_stream
->stream
) {
966 SET_TMP_PREFIX("stream-");
967 format_stream(buf_ch
, true, tmp_prefix
,
971 BUF_APPEND(", %sdefault-cs-state=%s",
972 PRFIELD(bt_message_stream_clock_snapshot_state_string(
973 msg_stream
->default_cs_state
)));
975 if (msg_stream
->default_cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
976 SET_TMP_PREFIX("default-cs-");
977 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
978 msg_stream
->default_cs
);
983 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
984 case BT_MESSAGE_TYPE_PACKET_END
:
986 const struct bt_message_packet
*msg_packet
= (const void *) msg
;
988 if (msg_packet
->packet
) {
989 SET_TMP_PREFIX("packet-");
990 format_packet(buf_ch
, true, tmp_prefix
,
994 if (msg_packet
->default_cs
) {
995 SET_TMP_PREFIX("default-cs-");
996 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
997 msg_packet
->default_cs
);
1002 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
1003 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1005 const struct bt_message_discarded_items
*msg_disc_items
=
1008 if (msg_disc_items
->stream
) {
1009 SET_TMP_PREFIX("stream-");
1010 format_stream(buf_ch
, true, tmp_prefix
,
1011 msg_disc_items
->stream
);
1014 if (msg_disc_items
->default_begin_cs
) {
1015 SET_TMP_PREFIX("begin-default-cs-");
1016 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1017 msg_disc_items
->default_begin_cs
);
1020 if (msg_disc_items
->default_end_cs
) {
1021 SET_TMP_PREFIX("end-default-cs-");
1022 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1023 msg_disc_items
->default_end_cs
);
1026 if (msg_disc_items
->count
.base
.avail
) {
1027 BUF_APPEND(", %scount=%" PRIu64
,
1028 PRFIELD(msg_disc_items
->count
.value
));
1038 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
1040 const struct bt_plugin_so_shared_lib_handle
*handle
)
1042 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
1045 BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle
->path
));
1049 static inline void format_component_class(char **buf_ch
, bool extended
,
1051 const struct bt_component_class
*comp_class
)
1053 char tmp_prefix
[TMP_PREFIX_LEN
];
1055 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1056 PRFIELD(bt_common_component_class_type_string(comp_class
->type
)),
1057 PRFIELD_GSTRING(comp_class
->name
));
1059 if (comp_class
->description
) {
1060 BUF_APPEND(", %spartial-descr=\"%.32s\"",
1061 PRFIELD_GSTRING(comp_class
->description
));
1068 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
1070 if (comp_class
->so_handle
) {
1071 SET_TMP_PREFIX("so-handle-");
1072 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1073 comp_class
->so_handle
);
1077 static inline void format_component(char **buf_ch
, bool extended
,
1078 const char *prefix
, const struct bt_component
*component
)
1080 char tmp_prefix
[TMP_PREFIX_LEN
];
1082 BUF_APPEND(", %sname=\"%s\", %slog-level=%s",
1083 PRFIELD_GSTRING(component
->name
),
1084 PRFIELD(bt_common_logging_level_string(component
->log_level
)));
1086 if (component
->class) {
1087 SET_TMP_PREFIX("class-");
1088 format_component_class(buf_ch
, extended
, tmp_prefix
,
1096 if (component
->input_ports
) {
1097 BUF_APPEND(", %sinput-port-count=%u",
1098 PRFIELD(component
->input_ports
->len
));
1101 if (component
->output_ports
) {
1102 BUF_APPEND(", %soutput-port-count=%u",
1103 PRFIELD(component
->output_ports
->len
));
1107 static inline void format_port(char **buf_ch
, bool extended
,
1108 const char *prefix
, const struct bt_port
*port
)
1110 char tmp_prefix
[TMP_PREFIX_LEN
];
1112 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1113 PRFIELD(bt_port_type_string(port
->type
)),
1114 PRFIELD_GSTRING(port
->name
));
1120 if (port
->connection
) {
1121 SET_TMP_PREFIX("conn-");
1122 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1126 static inline void format_connection(char **buf_ch
, bool extended
,
1127 const char *prefix
, const struct bt_connection
*connection
)
1129 char tmp_prefix
[TMP_PREFIX_LEN
];
1135 if (connection
->upstream_port
) {
1136 SET_TMP_PREFIX("upstream-port-");
1137 format_port(buf_ch
, false, tmp_prefix
,
1138 connection
->upstream_port
);
1141 if (connection
->downstream_port
) {
1142 SET_TMP_PREFIX("downstream-port-");
1143 format_port(buf_ch
, false, tmp_prefix
,
1144 connection
->downstream_port
);
1148 static inline void format_graph(char **buf_ch
, bool extended
,
1149 const char *prefix
, const struct bt_graph
*graph
)
1151 char tmp_prefix
[TMP_PREFIX_LEN
];
1153 BUF_APPEND(", %scan-consume=%d, %sconfig-state=%s",
1154 PRFIELD(graph
->can_consume
),
1155 PRFIELD(bt_graph_configuration_state_string(graph
->config_state
)));
1161 if (graph
->components
) {
1162 BUF_APPEND(", %scomp-count=%u",
1163 PRFIELD(graph
->components
->len
));
1166 if (graph
->connections
) {
1167 BUF_APPEND(", %sconn-count=%u",
1168 PRFIELD(graph
->connections
->len
));
1171 SET_TMP_PREFIX("en-pool-");
1172 format_object_pool(buf_ch
, tmp_prefix
, &graph
->event_msg_pool
);
1173 SET_TMP_PREFIX("pbn-pool-");
1174 format_object_pool(buf_ch
, tmp_prefix
, &graph
->packet_begin_msg_pool
);
1175 SET_TMP_PREFIX("pen-pool-");
1176 format_object_pool(buf_ch
, tmp_prefix
, &graph
->packet_end_msg_pool
);
1179 static inline void format_message_iterator(char **buf_ch
,
1180 bool extended
, const char *prefix
,
1181 const struct bt_message_iterator
*iterator
)
1183 char tmp_prefix
[TMP_PREFIX_LEN
];
1184 const struct bt_message_iterator
*
1185 port_in_iter
= (const void *) iterator
;
1187 if (port_in_iter
->upstream_component
) {
1188 SET_TMP_PREFIX("upstream-comp-");
1189 format_component(buf_ch
, false, tmp_prefix
,
1190 port_in_iter
->upstream_component
);
1197 if (port_in_iter
->upstream_port
) {
1198 SET_TMP_PREFIX("upstream-port-");
1199 format_port(buf_ch
, false, tmp_prefix
,
1200 port_in_iter
->upstream_port
);
1203 if (port_in_iter
->connection
) {
1204 SET_TMP_PREFIX("upstream-conn-");
1205 format_connection(buf_ch
, false, tmp_prefix
,
1206 port_in_iter
->connection
);
1213 static inline void format_plugin(char **buf_ch
, bool extended
,
1214 const char *prefix
, const struct bt_plugin
*plugin
)
1216 char tmp_prefix
[TMP_PREFIX_LEN
];
1218 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1220 if (plugin
->info
.path_set
) {
1221 BUF_APPEND(", %spath=\"%s\"",
1222 PRFIELD_GSTRING(plugin
->info
.path
));
1225 if (plugin
->info
.name_set
) {
1226 BUF_APPEND(", %sname=\"%s\"",
1227 PRFIELD_GSTRING(plugin
->info
.name
));
1234 if (plugin
->info
.author_set
) {
1235 BUF_APPEND(", %sauthor=\"%s\"",
1236 PRFIELD_GSTRING(plugin
->info
.author
));
1239 if (plugin
->info
.license_set
) {
1240 BUF_APPEND(", %slicense=\"%s\"",
1241 PRFIELD_GSTRING(plugin
->info
.license
));
1244 if (plugin
->info
.version_set
) {
1245 BUF_APPEND(", %sversion=%u.%u.%u%s",
1246 PRFIELD(plugin
->info
.version
.major
),
1247 plugin
->info
.version
.minor
,
1248 plugin
->info
.version
.patch
,
1249 plugin
->info
.version
.extra
?
1250 plugin
->info
.version
.extra
->str
: "");
1253 BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, "
1254 "%ssink-comp-class-count=%u",
1255 PRFIELD(plugin
->src_comp_classes
->len
),
1256 PRFIELD(plugin
->flt_comp_classes
->len
),
1257 PRFIELD(plugin
->sink_comp_classes
->len
));
1259 if (plugin
->spec_data
) {
1260 const struct bt_plugin_so_spec_data
*spec_data
=
1261 (const void *) plugin
->spec_data
;
1263 if (spec_data
->shared_lib_handle
) {
1264 SET_TMP_PREFIX("so-handle-");
1265 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1266 spec_data
->shared_lib_handle
);
1271 static inline void format_error_cause(char **buf_ch
, bool extended
,
1272 const char *prefix
, const struct bt_error_cause
*cause
)
1274 const struct bt_error_cause_component_class_id
*comp_class_id
= NULL
;
1276 BUF_APPEND(", %sactor-type=%s, %smodule-name=\"%s\"",
1277 PRFIELD(bt_error_cause_actor_type_string(cause
->actor_type
)),
1278 PRFIELD_GSTRING(cause
->module_name
));
1284 BUF_APPEND(", %spartial-msg=\"%.32s\"",
1285 PRFIELD_GSTRING(cause
->message
));
1287 switch (cause
->actor_type
) {
1288 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT
:
1290 const struct bt_error_cause_component_actor
*spec_cause
=
1291 (const void *) cause
;
1293 BUF_APPEND(", %scomp-name=\"%s\"",
1294 PRFIELD_GSTRING(spec_cause
->comp_name
));
1295 comp_class_id
= &spec_cause
->comp_class_id
;
1298 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS
:
1300 const struct bt_error_cause_component_class_actor
*spec_cause
=
1301 (const void *) cause
;
1303 comp_class_id
= &spec_cause
->comp_class_id
;
1306 case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR
:
1308 const struct bt_error_cause_message_iterator_actor
*spec_cause
=
1309 (const void *) cause
;
1311 BUF_APPEND(", %scomp-name=\"%s\", %scomp-out-port-name=\"%s\"",
1312 PRFIELD_GSTRING(spec_cause
->comp_name
),
1313 PRFIELD_GSTRING(spec_cause
->output_port_name
));
1314 comp_class_id
= &spec_cause
->comp_class_id
;
1321 if (comp_class_id
) {
1322 BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", "
1323 "%splugin-name=\"%s\"",
1324 PRFIELD(bt_common_component_class_type_string(
1325 comp_class_id
->type
)),
1326 PRFIELD_GSTRING(comp_class_id
->name
),
1327 PRFIELD_GSTRING(comp_class_id
->plugin_name
));
1331 static inline void handle_conversion_specifier_bt(
1332 void *priv_data
__attribute__((unused
)),
1334 size_t avail_size
__attribute__((unused
)),
1335 const char **out_fmt_ch
, va_list *args
)
1337 const char *fmt_ch
= *out_fmt_ch
;
1338 bool extended
= false;
1340 char *prefix_ch
= prefix
;
1346 if (*fmt_ch
== 'u') {
1348 obj
= va_arg(*args
, void *);
1349 format_uuid(buf_ch
, obj
);
1353 if (*fmt_ch
== '[') {
1358 if (*fmt_ch
== ']') {
1364 *prefix_ch
= *fmt_ch
;
1372 if (*fmt_ch
== '+') {
1377 obj
= va_arg(*args
, void *);
1378 BUF_APPEND("%saddr=%p", prefix
, obj
);
1386 format_field_class(buf_ch
, extended
, prefix
, obj
);
1389 format_field(buf_ch
, extended
, prefix
, obj
);
1392 format_field_path(buf_ch
, extended
, prefix
, obj
);
1395 format_event_class(buf_ch
, extended
, prefix
, obj
);
1398 format_event(buf_ch
, extended
, prefix
, obj
);
1401 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1404 format_stream(buf_ch
, extended
, prefix
, obj
);
1407 format_packet(buf_ch
, extended
, prefix
, obj
);
1410 format_trace(buf_ch
, extended
, prefix
, obj
);
1413 format_trace_class(buf_ch
, extended
, prefix
, obj
);
1416 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1419 format_clock_snapshot(buf_ch
, extended
, prefix
, obj
);
1422 format_value(buf_ch
, extended
, prefix
, obj
);
1425 format_integer_range_set(buf_ch
, extended
, prefix
, obj
);
1428 format_message(buf_ch
, extended
, prefix
, obj
);
1431 /* Empty, the address is automatically printed. */
1434 format_message_iterator(buf_ch
, extended
, prefix
, obj
);
1437 format_component_class(buf_ch
, extended
, prefix
, obj
);
1440 format_component(buf_ch
, extended
, prefix
, obj
);
1443 format_port(buf_ch
, extended
, prefix
, obj
);
1446 format_connection(buf_ch
, extended
, prefix
, obj
);
1449 format_plugin(buf_ch
, extended
, prefix
, obj
);
1452 format_graph(buf_ch
, extended
, prefix
, obj
);
1455 format_interrupter(buf_ch
, prefix
, obj
);
1458 format_object_pool(buf_ch
, prefix
, obj
);
1461 format_object(buf_ch
, prefix
, obj
);
1464 format_error_cause(buf_ch
, extended
, prefix
, obj
);
1472 *out_fmt_ch
= fmt_ch
;
1476 * This function would normally not be BT_EXPORTed, but it is used by the
1477 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1478 * implemented as a separate shared object, for modularity. It is therefore
1479 * exposed, but not part of the public ABI.
1482 void bt_lib_log_v(const char *func
, const char *file
, unsigned line
,
1483 int lvl
, const char *tag
, const char *fmt
, va_list *args
)
1486 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1487 handle_conversion_specifier_bt
, NULL
, fmt
, args
);
1488 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);
1492 * This function would normally not be BT_EXPORTed, but it is used by the
1493 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1494 * implemented as a separate shared object, for modularity. It is therefore
1495 * exposed, but not part of the public ABI.
1498 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1499 int lvl
, const char *tag
, const char *fmt
, ...)
1504 va_start(args
, fmt
);
1505 bt_lib_log_v(func
, file
, line
, lvl
, tag
, fmt
, &args
);
1510 * This function would normally not be BT_EXPORTed, but it is used by the
1511 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1512 * implemented as a separate shared object, for modularity. It is therefore
1513 * exposed, but not part of the ABI.
1516 void bt_lib_maybe_log_and_append_cause(const char *func
, const char *file
,
1517 unsigned line
, int lvl
, const char *tag
,
1518 const char *fmt
, ...)
1521 bt_current_thread_error_append_cause_status status
;
1524 va_start(args
, fmt
);
1525 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1526 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1529 /* Log conditionally, but always append the error cause */
1530 if (BT_LOG_ON(lvl
)) {
1531 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s",
1535 status
= bt_current_thread_error_append_cause_from_unknown(
1536 BT_LIB_LOG_LIBBABELTRACE2_NAME
, file
, line
, "%s",
1540 * Worst case: this error cause is not appended to the
1541 * current thread's error.
1543 * We can accept this as it's an almost impossible
1544 * scenario and returning an error here would mean you
1545 * need to check the return value of each
1546 * BT_LIB_LOG*_APPEND_CAUSE() macro and that would be
1549 BT_LOGE("Cannot append error cause to current thread's "
1550 "error object: status=%s",
1551 bt_common_func_status_string(status
));