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.h"
31 #include "graph/connection.h"
32 #include "graph/graph.h"
33 #include "graph/message/discarded-items.h"
34 #include "graph/message/event.h"
35 #include "graph/message/iterator.h"
36 #include "graph/message/message.h"
37 #include "graph/message/packet.h"
38 #include "graph/message/stream.h"
39 #include "graph/port.h"
40 #include "plugin/plugin.h"
41 #include "plugin/plugin-so.h"
42 #include "trace-ir/clock-class.h"
43 #include "trace-ir/clock-snapshot.h"
44 #include "trace-ir/event-class.h"
45 #include "trace-ir/event.h"
46 #include "trace-ir/field-class.h"
47 #include "trace-ir/field.h"
48 #include "trace-ir/field-path.h"
49 #include "trace-ir/packet.h"
50 #include "trace-ir/stream-class.h"
51 #include "trace-ir/stream.h"
52 #include "trace-ir/trace-class.h"
53 #include "trace-ir/trace.h"
56 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
58 static __thread
char lib_logging_buf
[LIB_LOGGING_BUF_SIZE
];
60 #define BUF_APPEND(_fmt, ...) \
63 size_t _size = LIB_LOGGING_BUF_SIZE - \
64 (size_t) (*buf_ch - lib_logging_buf); \
65 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
66 BT_ASSERT(_count >= 0); \
67 *buf_ch += MIN(_count, _size); \
68 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
73 #define BUF_APPEND_UUID(_uuid) \
75 BUF_APPEND(", %suuid=", prefix); \
76 format_uuid(buf_ch, (_uuid)); \
79 #define PRFIELD(_expr) prefix, (_expr)
81 #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL)
83 #define TMP_PREFIX_LEN 128
84 #define SET_TMP_PREFIX(_prefix2) \
87 snprintf(tmp_prefix, TMP_PREFIX_LEN - 1, "%s%s", \
88 prefix, (_prefix2)); \
90 if (snprintf_ret < 0 || snprintf_ret >= TMP_PREFIX_LEN - 1) { \
94 tmp_prefix[TMP_PREFIX_LEN - 1] = '\0'; \
97 static inline void format_component(char **buf_ch
, bool extended
,
98 const char *prefix
, const struct bt_component
*component
);
100 static inline void format_port(char **buf_ch
, bool extended
,
101 const char *prefix
, const struct bt_port
*port
);
103 static inline void format_connection(char **buf_ch
, bool extended
,
104 const char *prefix
, const struct bt_connection
*connection
);
106 static inline void format_clock_snapshot(char **buf_ch
, bool extended
,
107 const char *prefix
, const struct bt_clock_snapshot
*clock_snapshot
);
109 static inline void format_field_path(char **buf_ch
, bool extended
,
110 const char *prefix
, const struct bt_field_path
*field_path
);
112 static inline void format_object(char **buf_ch
, const char *prefix
,
113 const struct bt_object
*obj
)
115 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
118 static inline void format_uuid(char **buf_ch
, bt_uuid uuid
)
120 BUF_APPEND("\"" BT_UUID_FMT
"\"", BT_UUID_FMT_VALUES(uuid
));
123 static inline void format_object_pool(char **buf_ch
, const char *prefix
,
124 const struct bt_object_pool
*pool
)
126 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
129 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
133 static inline void format_integer_field_class(char **buf_ch
, const char *prefix
,
134 const struct bt_field_class
*field_class
)
136 const struct bt_field_class_integer
*int_fc
=
137 (const void *) field_class
;
139 BUF_APPEND(", %srange-size=%" PRIu64
", %sbase=%s",
140 PRFIELD(int_fc
->range
),
141 PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc
->base
)));
144 static inline void format_array_field_class(char **buf_ch
, const char *prefix
,
145 const struct bt_field_class
*field_class
)
147 const struct bt_field_class_array
*array_fc
=
148 (const void *) field_class
;
150 BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s",
151 PRFIELD(array_fc
->element_fc
),
152 PRFIELD(bt_common_field_class_type_string(array_fc
->element_fc
->type
)));
155 static inline void format_field_class(char **buf_ch
, bool extended
,
156 const char *prefix
, const struct bt_field_class
*field_class
)
158 char tmp_prefix
[TMP_PREFIX_LEN
];
160 BUF_APPEND(", %stype=%s",
161 PRFIELD(bt_common_field_class_type_string(field_class
->type
)));
164 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class
->frozen
));
165 BUF_APPEND(", %sis-part-of-trace-class=%d",
166 PRFIELD(field_class
->part_of_trace_class
));
171 switch (field_class
->type
) {
172 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
174 const struct bt_field_class_bit_array
*ba_fc
=
175 (const void *) field_class
;
177 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(ba_fc
->length
));
180 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
181 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
183 format_integer_field_class(buf_ch
, prefix
, field_class
);
186 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
187 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
189 const struct bt_field_class_enumeration
*enum_fc
=
190 (const void *) field_class
;
192 format_integer_field_class(buf_ch
, prefix
, field_class
);
193 BUF_APPEND(", %smapping-count=%u",
194 PRFIELD(enum_fc
->mappings
->len
));
197 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
199 const struct bt_field_class_structure
*struct_fc
=
200 (const void *) field_class
;
202 if (struct_fc
->common
.named_fcs
) {
203 BUF_APPEND(", %smember-count=%u",
204 PRFIELD(struct_fc
->common
.named_fcs
->len
));
209 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
211 const struct bt_field_class_array_static
*array_fc
=
212 (const void *) field_class
;
214 format_array_field_class(buf_ch
, prefix
, field_class
);
215 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_fc
->length
));
218 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
219 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
221 const struct bt_field_class_array_dynamic
*array_fc
=
222 (const void *) field_class
;
224 format_array_field_class(buf_ch
, prefix
, field_class
);
226 if (array_fc
->length_fc
) {
227 SET_TMP_PREFIX("length-fc-");
228 format_field_class(buf_ch
, extended
, tmp_prefix
,
229 array_fc
->length_fc
);
232 if (array_fc
->length_field_path
) {
233 SET_TMP_PREFIX("length-field-path-");
234 format_field_path(buf_ch
, extended
, tmp_prefix
,
235 array_fc
->length_field_path
);
240 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
241 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
242 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
243 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
245 const struct bt_field_class_option
*opt_fc
=
246 (const void *) field_class
;
248 BUF_APPEND(", %scontent-fc-addr=%p, %scontent-fc-type=%s",
249 PRFIELD(opt_fc
->content_fc
),
250 PRFIELD(bt_common_field_class_type_string(opt_fc
->content_fc
->type
)));
252 if (field_class
->type
!=
253 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
254 const struct bt_field_class_option_with_selector_field
*opt_with_sel_fc
=
255 (const void *) field_class
;
257 if (opt_with_sel_fc
->selector_fc
) {
258 SET_TMP_PREFIX("selector-fc-");
259 format_field_class(buf_ch
, extended
, tmp_prefix
,
260 opt_with_sel_fc
->selector_fc
);
263 if (opt_with_sel_fc
->selector_field_path
) {
264 SET_TMP_PREFIX("selector-field-path-");
265 format_field_path(buf_ch
, extended
, tmp_prefix
,
266 opt_with_sel_fc
->selector_field_path
);
272 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
273 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
274 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
276 const struct bt_field_class_variant
*var_fc
=
277 (const void *) field_class
;
279 if (var_fc
->common
.named_fcs
) {
280 BUF_APPEND(", %soption-count=%u",
281 PRFIELD(var_fc
->common
.named_fcs
->len
));
284 if (field_class
->type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
||
285 field_class
->type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
) {
286 const struct bt_field_class_variant_with_selector_field
*var_with_sel_fc
=
287 (const void *) var_fc
;
289 if (var_with_sel_fc
->selector_fc
) {
290 SET_TMP_PREFIX("selector-fc-");
291 format_field_class(buf_ch
, extended
, tmp_prefix
,
292 var_with_sel_fc
->selector_fc
);
295 if (var_with_sel_fc
->selector_field_path
) {
296 SET_TMP_PREFIX("selector-field-path-");
297 format_field_path(buf_ch
, extended
, tmp_prefix
,
298 var_with_sel_fc
->selector_field_path
);
309 static inline void format_field_integer_extended(char **buf_ch
,
310 const char *prefix
, const struct bt_field
*field
)
312 const struct bt_field_integer
*integer
= (void *) field
;
313 const struct bt_field_class_integer
*field_class
=
314 (void *) field
->class;
315 const char *fmt
= NULL
;
317 BT_ASSERT(field_class
);
319 if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
) {
320 fmt
= ", %svalue=%" PRIo64
;
321 } else if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
) {
322 fmt
= ", %svalue=%" PRIx64
;
325 #pragma GCC diagnostic push
326 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
327 if (field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
328 field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
330 fmt
= ", %svalue=%" PRId64
;
333 BUF_APPEND(fmt
, PRFIELD(integer
->value
.i
));
336 fmt
= ", %svalue=%" PRIu64
;
339 BUF_APPEND(fmt
, PRFIELD(integer
->value
.u
));
341 #pragma GCC diagnostic pop
344 static inline void format_field(char **buf_ch
, bool extended
,
345 const char *prefix
, const struct bt_field
*field
)
347 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->is_set
));
350 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
353 BUF_APPEND(", %sclass-addr=%p", PRFIELD(field
->class));
359 BUF_APPEND(", %sclass-type=%s",
360 PRFIELD(bt_common_field_class_type_string(field
->class->type
)));
362 if (!extended
|| !field
->is_set
) {
366 switch (field
->class->type
) {
367 case BT_FIELD_CLASS_TYPE_BOOL
:
369 const struct bt_field_bool
*bool_field
= (const void *) field
;
371 BUF_APPEND(", %svalue=%d", PRFIELD(bool_field
->value
));
374 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
376 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
378 BUF_APPEND(", %svalue-as-int=%" PRIx64
,
379 PRFIELD(ba_field
->value_as_int
));
382 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
383 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
384 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
385 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
387 format_field_integer_extended(buf_ch
, prefix
, field
);
390 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
391 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
393 const struct bt_field_real
*real_field
= (const void *) field
;
395 BUF_APPEND(", %svalue=%f", PRFIELD(real_field
->value
));
398 case BT_FIELD_CLASS_TYPE_STRING
:
400 const struct bt_field_string
*str
= (const void *) field
;
403 BT_ASSERT(str
->buf
->data
);
404 BUF_APPEND(", %spartial-value=\"%.32s\"",
405 PRFIELD(str
->buf
->data
));
410 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
411 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
412 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
414 const struct bt_field_array
*array_field
= (const void *) field
;
416 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_field
->length
));
418 if (array_field
->fields
) {
419 BUF_APPEND(", %sallocated-length=%u",
420 PRFIELD(array_field
->fields
->len
));
425 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
426 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
427 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
429 const struct bt_field_variant
*var_field
= (const void *) field
;
431 BUF_APPEND(", %sselected-field-index=%" PRIu64
,
432 PRFIELD(var_field
->selected_index
));
440 static inline void format_field_path(char **buf_ch
, bool extended
,
441 const char *prefix
, const struct bt_field_path
*field_path
)
445 if (field_path
->items
) {
446 BT_ASSERT(field_path
->items
);
447 BUF_APPEND(", %sitem-count=%u",
448 PRFIELD(field_path
->items
->len
));
451 if (!extended
|| !field_path
->items
) {
455 BUF_APPEND(", %spath=[%s",
456 PRFIELD(bt_common_scope_string(field_path
->root
)));
458 for (i
= 0; i
< bt_field_path_get_item_count(field_path
); i
++) {
459 const struct bt_field_path_item
*fp_item
=
460 bt_field_path_borrow_item_by_index_const(field_path
, i
);
462 switch (bt_field_path_item_get_type(fp_item
)) {
463 case BT_FIELD_PATH_ITEM_TYPE_INDEX
:
464 BUF_APPEND(", %" PRIu64
,
465 bt_field_path_item_index_get_index(fp_item
));
467 case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
:
468 BUF_APPEND("%s", ", <CUR>");
475 BUF_APPEND("%s", "]");
478 static inline void format_trace_class(char **buf_ch
, bool extended
,
479 const char *prefix
, const struct bt_trace_class
*trace_class
)
485 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class
->frozen
));
487 if (trace_class
->stream_classes
) {
488 BUF_APPEND(", %sstream-class-count=%u",
489 PRFIELD(trace_class
->stream_classes
->len
));
492 BUF_APPEND(", %sassigns-auto-sc-id=%d",
493 PRFIELD(trace_class
->assigns_automatic_stream_class_id
));
496 static inline void format_trace(char **buf_ch
, bool extended
,
497 const char *prefix
, const struct bt_trace
*trace
)
499 char tmp_prefix
[TMP_PREFIX_LEN
];
501 if (trace
->name
.value
) {
502 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
.value
));
509 if (trace
->uuid
.value
) {
510 BUF_APPEND_UUID(trace
->uuid
.value
);
513 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
515 if (trace
->streams
) {
516 BUF_APPEND(", %sstream-count=%u",
517 PRFIELD(trace
->streams
->len
));
524 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace
->class));
525 SET_TMP_PREFIX("trace-class-");
526 format_trace_class(buf_ch
, false, tmp_prefix
, trace
->class);
529 static inline void format_stream_class(char **buf_ch
, bool extended
,
531 const struct bt_stream_class
*stream_class
)
533 const struct bt_trace_class
*trace_class
;
534 char tmp_prefix
[TMP_PREFIX_LEN
];
536 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream_class
->id
));
538 if (stream_class
->name
.value
) {
539 BUF_APPEND(", %sname=\"%s\"",
540 PRFIELD(stream_class
->name
.value
));
547 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
549 if (stream_class
->event_classes
) {
550 BUF_APPEND(", %sevent-class-count=%u",
551 PRFIELD(stream_class
->event_classes
->len
));
554 BUF_APPEND(", %spacket-context-fc-addr=%p, "
555 "%sevent-common-context-fc-addr=%p",
556 PRFIELD(stream_class
->packet_context_fc
),
557 PRFIELD(stream_class
->event_common_context_fc
));
558 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
563 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
564 "%ssupports-packets=%d, "
565 "%spackets-have-begin-default-cs=%d, "
566 "%spackets-have-end-default-cs=%d, "
567 "%ssupports-discarded-events=%d, "
568 "%sdiscarded-events-have-default-cs=%d, "
569 "%ssupports-discarded-packets=%d, "
570 "%sdiscarded-packets-have-default-cs=%d",
571 PRFIELD(stream_class
->assigns_automatic_event_class_id
),
572 PRFIELD(stream_class
->assigns_automatic_stream_id
),
573 PRFIELD(stream_class
->supports_packets
),
574 PRFIELD(stream_class
->packets_have_beginning_default_clock_snapshot
),
575 PRFIELD(stream_class
->packets_have_end_default_clock_snapshot
),
576 PRFIELD(stream_class
->supports_discarded_events
),
577 PRFIELD(stream_class
->discarded_events_have_default_clock_snapshots
),
578 PRFIELD(stream_class
->supports_discarded_packets
),
579 PRFIELD(stream_class
->discarded_packets_have_default_clock_snapshots
));
580 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
581 SET_TMP_PREFIX("trace-class-");
582 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
583 SET_TMP_PREFIX("pcf-pool-");
584 format_object_pool(buf_ch
, tmp_prefix
,
585 &stream_class
->packet_context_field_pool
);
588 static inline void format_event_class(char **buf_ch
, bool extended
,
589 const char *prefix
, const struct bt_event_class
*event_class
)
591 const struct bt_stream_class
*stream_class
;
592 const struct bt_trace_class
*trace_class
;
593 char tmp_prefix
[TMP_PREFIX_LEN
];
595 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(event_class
->id
));
597 if (event_class
->name
.value
) {
598 BUF_APPEND(", %sname=\"%s\"",
599 PRFIELD(event_class
->name
.value
));
606 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class
->frozen
));
608 if (event_class
->log_level
.base
.avail
) {
609 BUF_APPEND(", %slog-level=%s",
610 PRFIELD(bt_common_event_class_log_level_string(
611 (int) event_class
->log_level
.value
)));
614 if (event_class
->emf_uri
.value
) {
615 BUF_APPEND(", %semf-uri=\"%s\"",
616 PRFIELD(event_class
->emf_uri
.value
));
619 BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
620 PRFIELD(event_class
->specific_context_fc
),
621 PRFIELD(event_class
->payload_fc
));
623 stream_class
= bt_event_class_borrow_stream_class_const(event_class
);
628 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
629 SET_TMP_PREFIX("stream-class-");
630 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
631 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
636 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
637 SET_TMP_PREFIX("trace-class-");
638 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
639 SET_TMP_PREFIX("event-pool-");
640 format_object_pool(buf_ch
, tmp_prefix
, &event_class
->event_pool
);
643 static inline void format_stream(char **buf_ch
, bool extended
,
644 const char *prefix
, const struct bt_stream
*stream
)
646 const struct bt_stream_class
*stream_class
;
647 const struct bt_trace_class
*trace_class
= NULL
;
648 const struct bt_trace
*trace
= NULL
;
649 char tmp_prefix
[TMP_PREFIX_LEN
];
651 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream
->id
));
653 if (stream
->name
.value
) {
654 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
.value
));
661 stream_class
= bt_stream_borrow_class_const(stream
);
663 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
664 SET_TMP_PREFIX("stream-class-");
665 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
666 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
670 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
671 SET_TMP_PREFIX("trace-class-");
672 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
675 trace
= bt_stream_borrow_trace_inline(stream
);
677 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
678 SET_TMP_PREFIX("trace-");
679 format_trace(buf_ch
, false, tmp_prefix
, trace
);
682 SET_TMP_PREFIX("packet-pool-");
683 format_object_pool(buf_ch
, tmp_prefix
, &stream
->packet_pool
);
686 static inline void format_packet(char **buf_ch
, bool extended
,
687 const char *prefix
, const struct bt_packet
*packet
)
689 const struct bt_stream
*stream
;
690 const struct bt_trace_class
*trace_class
;
691 char tmp_prefix
[TMP_PREFIX_LEN
];
697 BUF_APPEND(", %sis-frozen=%d, %scontext-field-addr=%p",
698 PRFIELD(packet
->frozen
),
699 PRFIELD(packet
->context_field
? packet
->context_field
->field
: NULL
));
700 stream
= bt_packet_borrow_stream_const(packet
);
705 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
706 SET_TMP_PREFIX("stream-");
707 format_stream(buf_ch
, false, tmp_prefix
, stream
);
708 trace_class
= (const struct bt_trace_class
*) bt_object_borrow_parent(&stream
->base
);
713 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
714 SET_TMP_PREFIX("trace-class-");
715 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
718 static inline void format_event(char **buf_ch
, bool extended
,
719 const char *prefix
, const struct bt_event
*event
)
721 const struct bt_trace_class
*trace_class
;
722 const struct bt_stream_class
*stream_class
;
723 char tmp_prefix
[TMP_PREFIX_LEN
];
729 BUF_APPEND(", %sis-frozen=%d, "
730 "%scommon-context-field-addr=%p, "
731 "%sspecific-context-field-addr=%p, "
732 "%spayload-field-addr=%p, ",
733 PRFIELD(event
->frozen
),
734 PRFIELD(event
->common_context_field
),
735 PRFIELD(event
->specific_context_field
),
736 PRFIELD(event
->payload_field
));
737 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
743 SET_TMP_PREFIX("event-class-");
744 format_event_class(buf_ch
, false, tmp_prefix
, event
->class);
745 stream_class
= bt_event_class_borrow_stream_class(event
->class);
747 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
748 SET_TMP_PREFIX("stream-class-");
749 format_stream_class(buf_ch
, false, tmp_prefix
,
752 trace_class
= bt_stream_class_borrow_trace_class_inline(
755 BUF_APPEND(", %strace-class-addr=%p",
756 PRFIELD(trace_class
));
757 SET_TMP_PREFIX("trace-class-");
758 format_trace_class(buf_ch
, false, tmp_prefix
,
764 BUF_APPEND(", %sstream-addr=%p", PRFIELD(event
->stream
));
765 SET_TMP_PREFIX("stream-");
766 format_stream(buf_ch
, false, tmp_prefix
, event
->stream
);
770 BUF_APPEND(", %spacket-addr=%p", PRFIELD(event
->packet
));
771 SET_TMP_PREFIX("packet-");
772 format_packet(buf_ch
, false, tmp_prefix
, event
->packet
);
776 static inline void format_clock_class(char **buf_ch
, bool extended
,
777 const char *prefix
, const struct bt_clock_class
*clock_class
)
779 char tmp_prefix
[TMP_PREFIX_LEN
];
781 if (clock_class
->name
.value
) {
782 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class
->name
.value
));
785 BUF_APPEND(", %sfreq=%" PRIu64
, PRFIELD(clock_class
->frequency
));
791 if (clock_class
->description
.value
) {
792 BUF_APPEND(", %spartial-descr=\"%.32s\"",
793 PRFIELD(clock_class
->description
.value
));
796 if (clock_class
->uuid
.value
) {
797 BUF_APPEND_UUID(clock_class
->uuid
.value
);
800 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
801 "%soffset-s=%" PRId64
", "
802 "%soffset-cycles=%" PRIu64
", %sorigin-is-unix-epoch=%d, "
803 "%sbase-offset-ns=%" PRId64
,
804 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
805 PRFIELD(clock_class
->offset_seconds
),
806 PRFIELD(clock_class
->offset_cycles
),
807 PRFIELD(clock_class
->origin_is_unix_epoch
),
808 PRFIELD(clock_class
->base_offset
.value_ns
));
810 SET_TMP_PREFIX("cs-pool-");
811 format_object_pool(buf_ch
, tmp_prefix
, &clock_class
->cs_pool
);
814 static inline void format_clock_snapshot(char **buf_ch
, bool extended
,
815 const char *prefix
, const struct bt_clock_snapshot
*clock_snapshot
)
817 char tmp_prefix
[TMP_PREFIX_LEN
];
818 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-origin=%" PRId64
,
819 PRFIELD(clock_snapshot
->value_cycles
),
820 PRFIELD(clock_snapshot
->ns_from_origin
));
826 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_snapshot
->is_set
));
828 if (clock_snapshot
->clock_class
) {
829 BUF_APPEND(", %sclock-class-addr=%p",
830 PRFIELD(clock_snapshot
->clock_class
));
831 SET_TMP_PREFIX("clock-class-");
832 format_clock_class(buf_ch
, false, tmp_prefix
,
833 clock_snapshot
->clock_class
);
837 static inline void format_interrupter(char **buf_ch
, const char *prefix
,
838 const struct bt_interrupter
*intr
)
840 BUF_APPEND(", %sis-set=%d", PRFIELD(intr
->is_set
));
843 static inline void format_value(char **buf_ch
, bool extended
,
844 const char *prefix
, const struct bt_value
*value
)
846 BUF_APPEND(", %stype=%s",
847 PRFIELD(bt_common_value_type_string(bt_value_get_type(value
))));
853 switch (bt_value_get_type(value
)) {
854 case BT_VALUE_TYPE_BOOL
:
856 bt_bool val
= bt_value_bool_get(value
);
858 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
861 case BT_VALUE_TYPE_UNSIGNED_INTEGER
:
863 BUF_APPEND(", %svalue=%" PRIu64
,
864 PRFIELD(bt_value_integer_unsigned_get(value
)));
867 case BT_VALUE_TYPE_SIGNED_INTEGER
:
869 BUF_APPEND(", %svalue=%" PRId64
,
870 PRFIELD(bt_value_integer_signed_get(value
)));
873 case BT_VALUE_TYPE_REAL
:
875 double val
= bt_value_real_get(value
);
877 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
880 case BT_VALUE_TYPE_STRING
:
882 const char *val
= bt_value_string_get(value
);
884 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
887 case BT_VALUE_TYPE_ARRAY
:
889 uint64_t count
= bt_value_array_get_length(value
);
891 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
894 case BT_VALUE_TYPE_MAP
:
896 int64_t count
= bt_value_map_get_size(value
);
898 BT_ASSERT(count
>= 0);
899 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
907 static inline void format_integer_range_set(char **buf_ch
, bool extended
,
909 const struct bt_integer_range_set
*range_set
)
911 BUF_APPEND(", %srange-count=%u", PRFIELD(range_set
->ranges
->len
));
917 BUF_APPEND(", %sis-frozen=%d", PRFIELD(range_set
->frozen
));
920 static inline void format_message(char **buf_ch
, bool extended
,
921 const char *prefix
, const struct bt_message
*msg
)
923 char tmp_prefix
[TMP_PREFIX_LEN
];
925 BUF_APPEND(", %stype=%s",
926 PRFIELD(bt_common_message_type_string(msg
->type
)));
932 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
933 PRFIELD(msg
->frozen
), PRFIELD(msg
->graph
));
936 case BT_MESSAGE_TYPE_EVENT
:
938 const struct bt_message_event
*msg_event
=
941 if (msg_event
->event
) {
942 SET_TMP_PREFIX("event-");
943 format_event(buf_ch
, true, tmp_prefix
,
947 if (msg_event
->default_cs
) {
948 SET_TMP_PREFIX("default-cs-");
949 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
950 msg_event
->default_cs
);
955 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
956 case BT_MESSAGE_TYPE_STREAM_END
:
958 const struct bt_message_stream
*msg_stream
= (const void *) msg
;
960 if (msg_stream
->stream
) {
961 SET_TMP_PREFIX("stream-");
962 format_stream(buf_ch
, true, tmp_prefix
,
966 BUF_APPEND(", %sdefault-cs-state=%s",
967 PRFIELD(bt_message_stream_clock_snapshot_state_string(
968 msg_stream
->default_cs_state
)));
970 if (msg_stream
->default_cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
971 SET_TMP_PREFIX("default-cs-");
972 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
973 msg_stream
->default_cs
);
978 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
979 case BT_MESSAGE_TYPE_PACKET_END
:
981 const struct bt_message_packet
*msg_packet
= (const void *) msg
;
983 if (msg_packet
->packet
) {
984 SET_TMP_PREFIX("packet-");
985 format_packet(buf_ch
, true, tmp_prefix
,
989 if (msg_packet
->default_cs
) {
990 SET_TMP_PREFIX("default-cs-");
991 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
992 msg_packet
->default_cs
);
997 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
998 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1000 const struct bt_message_discarded_items
*msg_disc_items
=
1003 if (msg_disc_items
->stream
) {
1004 SET_TMP_PREFIX("stream-");
1005 format_stream(buf_ch
, true, tmp_prefix
,
1006 msg_disc_items
->stream
);
1009 if (msg_disc_items
->default_begin_cs
) {
1010 SET_TMP_PREFIX("begin-default-cs-");
1011 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1012 msg_disc_items
->default_begin_cs
);
1015 if (msg_disc_items
->default_end_cs
) {
1016 SET_TMP_PREFIX("end-default-cs-");
1017 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1018 msg_disc_items
->default_end_cs
);
1021 if (msg_disc_items
->count
.base
.avail
) {
1022 BUF_APPEND(", %scount=%" PRIu64
,
1023 PRFIELD(msg_disc_items
->count
.value
));
1033 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
1035 const struct bt_plugin_so_shared_lib_handle
*handle
)
1037 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
1040 BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle
->path
));
1044 static inline void format_component_class(char **buf_ch
, bool extended
,
1046 const struct bt_component_class
*comp_class
)
1048 char tmp_prefix
[TMP_PREFIX_LEN
];
1050 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1051 PRFIELD(bt_common_component_class_type_string(comp_class
->type
)),
1052 PRFIELD_GSTRING(comp_class
->name
));
1054 if (comp_class
->description
) {
1055 BUF_APPEND(", %spartial-descr=\"%.32s\"",
1056 PRFIELD_GSTRING(comp_class
->description
));
1063 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
1065 if (comp_class
->so_handle
) {
1066 SET_TMP_PREFIX("so-handle-");
1067 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1068 comp_class
->so_handle
);
1072 static inline void format_component(char **buf_ch
, bool extended
,
1073 const char *prefix
, const struct bt_component
*component
)
1075 char tmp_prefix
[TMP_PREFIX_LEN
];
1077 BUF_APPEND(", %sname=\"%s\", %slog-level=%s",
1078 PRFIELD_GSTRING(component
->name
),
1079 PRFIELD(bt_common_logging_level_string(component
->log_level
)));
1081 if (component
->class) {
1082 SET_TMP_PREFIX("class-");
1083 format_component_class(buf_ch
, extended
, tmp_prefix
,
1091 if (component
->input_ports
) {
1092 BUF_APPEND(", %sinput-port-count=%u",
1093 PRFIELD(component
->input_ports
->len
));
1096 if (component
->output_ports
) {
1097 BUF_APPEND(", %soutput-port-count=%u",
1098 PRFIELD(component
->output_ports
->len
));
1102 static inline void format_port(char **buf_ch
, bool extended
,
1103 const char *prefix
, const struct bt_port
*port
)
1105 char tmp_prefix
[TMP_PREFIX_LEN
];
1107 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1108 PRFIELD(bt_port_type_string(port
->type
)),
1109 PRFIELD_GSTRING(port
->name
));
1115 if (port
->connection
) {
1116 SET_TMP_PREFIX("conn-");
1117 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1121 static inline void format_connection(char **buf_ch
, bool extended
,
1122 const char *prefix
, const struct bt_connection
*connection
)
1124 char tmp_prefix
[TMP_PREFIX_LEN
];
1130 if (connection
->upstream_port
) {
1131 SET_TMP_PREFIX("upstream-port-");
1132 format_port(buf_ch
, false, tmp_prefix
,
1133 connection
->upstream_port
);
1136 if (connection
->downstream_port
) {
1137 SET_TMP_PREFIX("downstream-port-");
1138 format_port(buf_ch
, false, tmp_prefix
,
1139 connection
->downstream_port
);
1143 static inline void format_graph(char **buf_ch
, bool extended
,
1144 const char *prefix
, const struct bt_graph
*graph
)
1146 char tmp_prefix
[TMP_PREFIX_LEN
];
1148 BUF_APPEND(", %scan-consume=%d, %sconfig-state=%s",
1149 PRFIELD(graph
->can_consume
),
1150 PRFIELD(bt_graph_configuration_state_string(graph
->config_state
)));
1156 if (graph
->components
) {
1157 BUF_APPEND(", %scomp-count=%u",
1158 PRFIELD(graph
->components
->len
));
1161 if (graph
->connections
) {
1162 BUF_APPEND(", %sconn-count=%u",
1163 PRFIELD(graph
->connections
->len
));
1166 SET_TMP_PREFIX("en-pool-");
1167 format_object_pool(buf_ch
, tmp_prefix
, &graph
->event_msg_pool
);
1168 SET_TMP_PREFIX("pbn-pool-");
1169 format_object_pool(buf_ch
, tmp_prefix
, &graph
->packet_begin_msg_pool
);
1170 SET_TMP_PREFIX("pen-pool-");
1171 format_object_pool(buf_ch
, tmp_prefix
, &graph
->packet_end_msg_pool
);
1174 static inline void format_message_iterator(char **buf_ch
,
1175 bool extended
, const char *prefix
,
1176 const struct bt_message_iterator
*iterator
)
1178 char tmp_prefix
[TMP_PREFIX_LEN
];
1179 const struct bt_message_iterator
*
1180 port_in_iter
= (const void *) iterator
;
1182 if (port_in_iter
->upstream_component
) {
1183 SET_TMP_PREFIX("upstream-comp-");
1184 format_component(buf_ch
, false, tmp_prefix
,
1185 port_in_iter
->upstream_component
);
1192 if (port_in_iter
->upstream_port
) {
1193 SET_TMP_PREFIX("upstream-port-");
1194 format_port(buf_ch
, false, tmp_prefix
,
1195 port_in_iter
->upstream_port
);
1198 if (port_in_iter
->connection
) {
1199 SET_TMP_PREFIX("upstream-conn-");
1200 format_connection(buf_ch
, false, tmp_prefix
,
1201 port_in_iter
->connection
);
1208 static inline void format_plugin(char **buf_ch
, bool extended
,
1209 const char *prefix
, const struct bt_plugin
*plugin
)
1211 char tmp_prefix
[TMP_PREFIX_LEN
];
1213 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1215 if (plugin
->info
.path_set
) {
1216 BUF_APPEND(", %spath=\"%s\"",
1217 PRFIELD_GSTRING(plugin
->info
.path
));
1220 if (plugin
->info
.name_set
) {
1221 BUF_APPEND(", %sname=\"%s\"",
1222 PRFIELD_GSTRING(plugin
->info
.name
));
1229 if (plugin
->info
.author_set
) {
1230 BUF_APPEND(", %sauthor=\"%s\"",
1231 PRFIELD_GSTRING(plugin
->info
.author
));
1234 if (plugin
->info
.license_set
) {
1235 BUF_APPEND(", %slicense=\"%s\"",
1236 PRFIELD_GSTRING(plugin
->info
.license
));
1239 if (plugin
->info
.version_set
) {
1240 BUF_APPEND(", %sversion=%u.%u.%u%s",
1241 PRFIELD(plugin
->info
.version
.major
),
1242 plugin
->info
.version
.minor
,
1243 plugin
->info
.version
.patch
,
1244 plugin
->info
.version
.extra
?
1245 plugin
->info
.version
.extra
->str
: "");
1248 BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, "
1249 "%ssink-comp-class-count=%u",
1250 PRFIELD(plugin
->src_comp_classes
->len
),
1251 PRFIELD(plugin
->flt_comp_classes
->len
),
1252 PRFIELD(plugin
->sink_comp_classes
->len
));
1254 if (plugin
->spec_data
) {
1255 const struct bt_plugin_so_spec_data
*spec_data
=
1256 (const void *) plugin
->spec_data
;
1258 if (spec_data
->shared_lib_handle
) {
1259 SET_TMP_PREFIX("so-handle-");
1260 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1261 spec_data
->shared_lib_handle
);
1266 static inline void format_error_cause(char **buf_ch
, bool extended
,
1267 const char *prefix
, const struct bt_error_cause
*cause
)
1269 const struct bt_error_cause_component_class_id
*comp_class_id
= NULL
;
1271 BUF_APPEND(", %sactor-type=%s, %smodule-name=\"%s\"",
1272 PRFIELD(bt_error_cause_actor_type_string(cause
->actor_type
)),
1273 PRFIELD_GSTRING(cause
->module_name
));
1279 BUF_APPEND(", %spartial-msg=\"%.32s\"",
1280 PRFIELD_GSTRING(cause
->message
));
1282 switch (cause
->actor_type
) {
1283 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT
:
1285 const struct bt_error_cause_component_actor
*spec_cause
=
1286 (const void *) cause
;
1288 BUF_APPEND(", %scomp-name=\"%s\"",
1289 PRFIELD_GSTRING(spec_cause
->comp_name
));
1290 comp_class_id
= &spec_cause
->comp_class_id
;
1293 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS
:
1295 const struct bt_error_cause_component_class_actor
*spec_cause
=
1296 (const void *) cause
;
1298 comp_class_id
= &spec_cause
->comp_class_id
;
1301 case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR
:
1303 const struct bt_error_cause_message_iterator_actor
*spec_cause
=
1304 (const void *) cause
;
1306 BUF_APPEND(", %scomp-name=\"%s\", %scomp-out-port-name=\"%s\"",
1307 PRFIELD_GSTRING(spec_cause
->comp_name
),
1308 PRFIELD_GSTRING(spec_cause
->output_port_name
));
1309 comp_class_id
= &spec_cause
->comp_class_id
;
1316 if (comp_class_id
) {
1317 BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", "
1318 "%splugin-name=\"%s\"",
1319 PRFIELD(bt_common_component_class_type_string(
1320 comp_class_id
->type
)),
1321 PRFIELD_GSTRING(comp_class_id
->name
),
1322 PRFIELD_GSTRING(comp_class_id
->plugin_name
));
1326 static inline void handle_conversion_specifier_bt(
1327 void *priv_data
__attribute__((unused
)),
1329 size_t avail_size
__attribute__((unused
)),
1330 const char **out_fmt_ch
, va_list *args
)
1332 const char *fmt_ch
= *out_fmt_ch
;
1333 bool extended
= false;
1335 char *prefix_ch
= prefix
;
1341 if (*fmt_ch
== 'u') {
1343 obj
= va_arg(*args
, void *);
1344 format_uuid(buf_ch
, obj
);
1348 if (*fmt_ch
== '[') {
1353 if (*fmt_ch
== ']') {
1359 *prefix_ch
= *fmt_ch
;
1367 if (*fmt_ch
== '+') {
1372 obj
= va_arg(*args
, void *);
1373 BUF_APPEND("%saddr=%p", prefix
, obj
);
1381 format_field_class(buf_ch
, extended
, prefix
, obj
);
1384 format_field(buf_ch
, extended
, prefix
, obj
);
1387 format_field_path(buf_ch
, extended
, prefix
, obj
);
1390 format_event_class(buf_ch
, extended
, prefix
, obj
);
1393 format_event(buf_ch
, extended
, prefix
, obj
);
1396 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1399 format_stream(buf_ch
, extended
, prefix
, obj
);
1402 format_packet(buf_ch
, extended
, prefix
, obj
);
1405 format_trace(buf_ch
, extended
, prefix
, obj
);
1408 format_trace_class(buf_ch
, extended
, prefix
, obj
);
1411 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1414 format_clock_snapshot(buf_ch
, extended
, prefix
, obj
);
1417 format_value(buf_ch
, extended
, prefix
, obj
);
1420 format_integer_range_set(buf_ch
, extended
, prefix
, obj
);
1423 format_message(buf_ch
, extended
, prefix
, obj
);
1426 /* Empty, the address is automatically printed. */
1429 format_message_iterator(buf_ch
, extended
, prefix
, obj
);
1432 format_component_class(buf_ch
, extended
, prefix
, obj
);
1435 format_component(buf_ch
, extended
, prefix
, obj
);
1438 format_port(buf_ch
, extended
, prefix
, obj
);
1441 format_connection(buf_ch
, extended
, prefix
, obj
);
1444 format_plugin(buf_ch
, extended
, prefix
, obj
);
1447 format_graph(buf_ch
, extended
, prefix
, obj
);
1450 format_interrupter(buf_ch
, prefix
, obj
);
1453 format_object_pool(buf_ch
, prefix
, obj
);
1456 format_object(buf_ch
, prefix
, obj
);
1459 format_error_cause(buf_ch
, extended
, prefix
, obj
);
1467 *out_fmt_ch
= fmt_ch
;
1471 * This function would normally not be BT_EXPORTed, but it is used by the
1472 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1473 * implemented as a separate shared object, for modularity. It is therefore
1474 * exposed, but not part of the public ABI.
1477 void bt_lib_log_v(const char *file
, const char *func
, unsigned line
,
1478 int lvl
, const char *tag
, const char *fmt
, va_list *args
)
1481 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1482 handle_conversion_specifier_bt
, NULL
, fmt
, args
);
1483 bt_log_write(file
, func
, line
, lvl
, tag
, lib_logging_buf
);
1487 * This function would normally not be BT_EXPORTed, but it is used by the
1488 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1489 * implemented as a separate shared object, for modularity. It is therefore
1490 * exposed, but not part of the public ABI.
1493 void bt_lib_log(const char *file
, const char *func
, unsigned line
,
1494 int lvl
, const char *tag
, const char *fmt
, ...)
1499 va_start(args
, fmt
);
1500 bt_lib_log_v(file
, func
, line
, lvl
, tag
, fmt
, &args
);
1505 * This function would normally not be BT_EXPORTed, but it is used by the
1506 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1507 * implemented as a separate shared object, for modularity. It is therefore
1508 * exposed, but not part of the ABI.
1511 void bt_lib_maybe_log_and_append_cause(const char *func
, const char *file
,
1512 unsigned line
, int lvl
, const char *tag
,
1513 const char *fmt
, ...)
1516 bt_current_thread_error_append_cause_status status
;
1519 va_start(args
, fmt
);
1520 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1521 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1524 /* Log conditionally, but always append the error cause */
1525 if (BT_LOG_ON(lvl
)) {
1526 bt_log_write(file
, func
, line
, lvl
, tag
, lib_logging_buf
);
1529 status
= bt_current_thread_error_append_cause_from_unknown(
1530 BT_LIB_LOG_LIBBABELTRACE2_NAME
, file
, line
, "%s",
1534 * Worst case: this error cause is not appended to the
1535 * current thread's error.
1537 * We can accept this as it's an almost impossible
1538 * scenario and returning an error here would mean you
1539 * need to check the return value of each
1540 * BT_LIB_LOG*_APPEND_CAUSE() macro and that would be
1543 BT_LOGE("Cannot append error cause to current thread's "
1544 "error object: status=%s",
1545 bt_common_func_status_string(status
));