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>
25 #include "integer-range-set.h"
26 #include "object-pool.h"
27 #include "graph/interrupter.h"
28 #include "graph/component-class.h"
29 #include "graph/component.h"
30 #include "graph/connection.h"
31 #include "graph/graph.h"
32 #include "graph/iterator.h"
33 #include "graph/message/discarded-items.h"
34 #include "graph/message/event.h"
35 #include "graph/message/message.h"
36 #include "graph/message/packet.h"
37 #include "graph/message/stream.h"
38 #include "graph/port.h"
39 #include "plugin/plugin.h"
40 #include "plugin/plugin-so.h"
41 #include "trace-ir/clock-class.h"
42 #include "trace-ir/clock-snapshot.h"
43 #include "trace-ir/event-class.h"
44 #include "trace-ir/event.h"
45 #include "trace-ir/field-class.h"
46 #include "trace-ir/field.h"
47 #include "trace-ir/field-path.h"
48 #include "trace-ir/packet.h"
49 #include "trace-ir/stream-class.h"
50 #include "trace-ir/stream.h"
51 #include "trace-ir/trace-class.h"
52 #include "trace-ir/trace.h"
55 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
57 static __thread
char lib_logging_buf
[LIB_LOGGING_BUF_SIZE
];
59 #define BUF_APPEND(_fmt, ...) \
62 size_t _size = LIB_LOGGING_BUF_SIZE - \
63 (size_t) (*buf_ch - lib_logging_buf); \
64 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
65 BT_ASSERT(_count >= 0); \
66 *buf_ch += MIN(_count, _size); \
67 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
72 #define BUF_APPEND_UUID(_uuid) \
74 BUF_APPEND(", %suuid=", prefix); \
75 format_uuid(buf_ch, (_uuid)); \
78 #define PRFIELD(_expr) prefix, (_expr)
80 #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL)
82 #define TMP_PREFIX_LEN 128
83 #define SET_TMP_PREFIX(_prefix2) \
86 snprintf(tmp_prefix, TMP_PREFIX_LEN - 1, "%s%s", \
87 prefix, (_prefix2)); \
89 if (snprintf_ret < 0 || snprintf_ret >= TMP_PREFIX_LEN - 1) { \
93 tmp_prefix[TMP_PREFIX_LEN - 1] = '\0'; \
96 static inline void format_component(char **buf_ch
, bool extended
,
97 const char *prefix
, const struct bt_component
*component
);
99 static inline void format_port(char **buf_ch
, bool extended
,
100 const char *prefix
, const struct bt_port
*port
);
102 static inline void format_connection(char **buf_ch
, bool extended
,
103 const char *prefix
, const struct bt_connection
*connection
);
105 static inline void format_clock_snapshot(char **buf_ch
, bool extended
,
106 const char *prefix
, const struct bt_clock_snapshot
*clock_snapshot
);
108 static inline void format_field_path(char **buf_ch
, bool extended
,
109 const char *prefix
, const struct bt_field_path
*field_path
);
111 static inline void format_object(char **buf_ch
, const char *prefix
,
112 const struct bt_object
*obj
)
114 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
117 static inline void format_uuid(char **buf_ch
, bt_uuid uuid
)
119 BUF_APPEND("\"" BT_UUID_FMT
"\"", BT_UUID_FMT_VALUES(uuid
));
122 static inline void format_object_pool(char **buf_ch
, const char *prefix
,
123 const struct bt_object_pool
*pool
)
125 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
128 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
132 static inline void format_integer_field_class(char **buf_ch
, const char *prefix
,
133 const struct bt_field_class
*field_class
)
135 const struct bt_field_class_integer
*int_fc
=
136 (const void *) field_class
;
138 BUF_APPEND(", %srange-size=%" PRIu64
", %sbase=%s",
139 PRFIELD(int_fc
->range
),
140 PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc
->base
)));
143 static inline void format_array_field_class(char **buf_ch
, const char *prefix
,
144 const struct bt_field_class
*field_class
)
146 const struct bt_field_class_array
*array_fc
=
147 (const void *) field_class
;
149 BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s",
150 PRFIELD(array_fc
->element_fc
),
151 PRFIELD(bt_common_field_class_type_string(array_fc
->element_fc
->type
)));
154 static inline void format_field_class(char **buf_ch
, bool extended
,
155 const char *prefix
, const struct bt_field_class
*field_class
)
157 char tmp_prefix
[TMP_PREFIX_LEN
];
159 BUF_APPEND(", %stype=%s",
160 PRFIELD(bt_common_field_class_type_string(field_class
->type
)));
163 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class
->frozen
));
164 BUF_APPEND(", %sis-part-of-trace-class=%d",
165 PRFIELD(field_class
->part_of_trace_class
));
170 switch (field_class
->type
) {
171 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
173 const struct bt_field_class_bit_array
*ba_fc
=
174 (const void *) field_class
;
176 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(ba_fc
->length
));
179 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
180 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
182 format_integer_field_class(buf_ch
, prefix
, field_class
);
185 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
186 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
188 const struct bt_field_class_enumeration
*enum_fc
=
189 (const void *) field_class
;
191 format_integer_field_class(buf_ch
, prefix
, field_class
);
192 BUF_APPEND(", %smapping-count=%u",
193 PRFIELD(enum_fc
->mappings
->len
));
196 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
198 const struct bt_field_class_structure
*struct_fc
=
199 (const void *) field_class
;
201 if (struct_fc
->common
.named_fcs
) {
202 BUF_APPEND(", %smember-count=%u",
203 PRFIELD(struct_fc
->common
.named_fcs
->len
));
208 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
210 const struct bt_field_class_array_static
*array_fc
=
211 (const void *) field_class
;
213 format_array_field_class(buf_ch
, prefix
, field_class
);
214 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_fc
->length
));
217 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
218 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
220 const struct bt_field_class_array_dynamic
*array_fc
=
221 (const void *) field_class
;
223 format_array_field_class(buf_ch
, prefix
, field_class
);
225 if (array_fc
->length_fc
) {
226 SET_TMP_PREFIX("length-fc-");
227 format_field_class(buf_ch
, extended
, tmp_prefix
,
228 array_fc
->length_fc
);
231 if (array_fc
->length_field_path
) {
232 SET_TMP_PREFIX("length-field-path-");
233 format_field_path(buf_ch
, extended
, tmp_prefix
,
234 array_fc
->length_field_path
);
239 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
240 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
241 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
242 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
244 const struct bt_field_class_option
*opt_fc
=
245 (const void *) field_class
;
247 BUF_APPEND(", %scontent-fc-addr=%p, %scontent-fc-type=%s",
248 PRFIELD(opt_fc
->content_fc
),
249 PRFIELD(bt_common_field_class_type_string(opt_fc
->content_fc
->type
)));
251 if (field_class
->type
!=
252 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
253 const struct bt_field_class_option_with_selector_field
*opt_with_sel_fc
=
254 (const void *) field_class
;
256 if (opt_with_sel_fc
->selector_fc
) {
257 SET_TMP_PREFIX("selector-fc-");
258 format_field_class(buf_ch
, extended
, tmp_prefix
,
259 opt_with_sel_fc
->selector_fc
);
262 if (opt_with_sel_fc
->selector_field_path
) {
263 SET_TMP_PREFIX("selector-field-path-");
264 format_field_path(buf_ch
, extended
, tmp_prefix
,
265 opt_with_sel_fc
->selector_field_path
);
271 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
272 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
273 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
275 const struct bt_field_class_variant
*var_fc
=
276 (const void *) field_class
;
278 if (var_fc
->common
.named_fcs
) {
279 BUF_APPEND(", %soption-count=%u",
280 PRFIELD(var_fc
->common
.named_fcs
->len
));
283 if (field_class
->type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
||
284 field_class
->type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
) {
285 const struct bt_field_class_variant_with_selector_field
*var_with_sel_fc
=
286 (const void *) var_fc
;
288 if (var_with_sel_fc
->selector_fc
) {
289 SET_TMP_PREFIX("selector-fc-");
290 format_field_class(buf_ch
, extended
, tmp_prefix
,
291 var_with_sel_fc
->selector_fc
);
294 if (var_with_sel_fc
->selector_field_path
) {
295 SET_TMP_PREFIX("selector-field-path-");
296 format_field_path(buf_ch
, extended
, tmp_prefix
,
297 var_with_sel_fc
->selector_field_path
);
308 static inline void format_field_integer_extended(char **buf_ch
,
309 const char *prefix
, const struct bt_field
*field
)
311 const struct bt_field_integer
*integer
= (void *) field
;
312 const struct bt_field_class_integer
*field_class
=
313 (void *) field
->class;
314 const char *fmt
= NULL
;
316 BT_ASSERT(field_class
);
318 if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
) {
319 fmt
= ", %svalue=%" PRIo64
;
320 } else if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
) {
321 fmt
= ", %svalue=%" PRIx64
;
324 #pragma GCC diagnostic push
325 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
326 if (field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
327 field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
329 fmt
= ", %svalue=%" PRId64
;
332 BUF_APPEND(fmt
, PRFIELD(integer
->value
.i
));
335 fmt
= ", %svalue=%" PRIu64
;
338 BUF_APPEND(fmt
, PRFIELD(integer
->value
.u
));
340 #pragma GCC diagnostic pop
343 static inline void format_field(char **buf_ch
, bool extended
,
344 const char *prefix
, const struct bt_field
*field
)
346 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->is_set
));
349 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
352 BUF_APPEND(", %sclass-addr=%p", PRFIELD(field
->class));
358 BUF_APPEND(", %sclass-type=%s",
359 PRFIELD(bt_common_field_class_type_string(field
->class->type
)));
361 if (!extended
|| !field
->is_set
) {
365 switch (field
->class->type
) {
366 case BT_FIELD_CLASS_TYPE_BOOL
:
368 const struct bt_field_bool
*bool_field
= (const void *) field
;
370 BUF_APPEND(", %svalue=%d", PRFIELD(bool_field
->value
));
373 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
375 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
377 BUF_APPEND(", %svalue-as-int=%" PRIx64
,
378 PRFIELD(ba_field
->value_as_int
));
381 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
382 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
383 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
384 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
386 format_field_integer_extended(buf_ch
, prefix
, field
);
389 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
390 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
392 const struct bt_field_real
*real_field
= (const void *) field
;
394 BUF_APPEND(", %svalue=%f", PRFIELD(real_field
->value
));
397 case BT_FIELD_CLASS_TYPE_STRING
:
399 const struct bt_field_string
*str
= (const void *) field
;
402 BT_ASSERT(str
->buf
->data
);
403 BUF_APPEND(", %spartial-value=\"%.32s\"",
404 PRFIELD(str
->buf
->data
));
409 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
410 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
411 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
413 const struct bt_field_array
*array_field
= (const void *) field
;
415 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_field
->length
));
417 if (array_field
->fields
) {
418 BUF_APPEND(", %sallocated-length=%u",
419 PRFIELD(array_field
->fields
->len
));
424 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
425 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
426 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
428 const struct bt_field_variant
*var_field
= (const void *) field
;
430 BUF_APPEND(", %sselected-field-index=%" PRIu64
,
431 PRFIELD(var_field
->selected_index
));
439 static inline void format_field_path(char **buf_ch
, bool extended
,
440 const char *prefix
, const struct bt_field_path
*field_path
)
444 if (field_path
->items
) {
445 BT_ASSERT(field_path
->items
);
446 BUF_APPEND(", %sitem-count=%u",
447 PRFIELD(field_path
->items
->len
));
450 if (!extended
|| !field_path
->items
) {
454 BUF_APPEND(", %spath=[%s",
455 PRFIELD(bt_common_scope_string(field_path
->root
)));
457 for (i
= 0; i
< bt_field_path_get_item_count(field_path
); i
++) {
458 const struct bt_field_path_item
*fp_item
=
459 bt_field_path_borrow_item_by_index_const(field_path
, i
);
461 switch (bt_field_path_item_get_type(fp_item
)) {
462 case BT_FIELD_PATH_ITEM_TYPE_INDEX
:
463 BUF_APPEND(", %" PRIu64
,
464 bt_field_path_item_index_get_index(fp_item
));
466 case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
:
467 BUF_APPEND("%s", ", <CUR>");
474 BUF_APPEND("%s", "]");
477 static inline void format_trace_class(char **buf_ch
, bool extended
,
478 const char *prefix
, const struct bt_trace_class
*trace_class
)
484 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class
->frozen
));
486 if (trace_class
->stream_classes
) {
487 BUF_APPEND(", %sstream-class-count=%u",
488 PRFIELD(trace_class
->stream_classes
->len
));
491 BUF_APPEND(", %sassigns-auto-sc-id=%d",
492 PRFIELD(trace_class
->assigns_automatic_stream_class_id
));
495 static inline void format_trace(char **buf_ch
, bool extended
,
496 const char *prefix
, const struct bt_trace
*trace
)
498 char tmp_prefix
[TMP_PREFIX_LEN
];
500 if (trace
->name
.value
) {
501 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
.value
));
508 if (trace
->uuid
.value
) {
509 BUF_APPEND_UUID(trace
->uuid
.value
);
512 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
514 if (trace
->streams
) {
515 BUF_APPEND(", %sstream-count=%u",
516 PRFIELD(trace
->streams
->len
));
523 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace
->class));
524 SET_TMP_PREFIX("trace-class-");
525 format_trace_class(buf_ch
, false, tmp_prefix
, trace
->class);
528 static inline void format_stream_class(char **buf_ch
, bool extended
,
530 const struct bt_stream_class
*stream_class
)
532 const struct bt_trace_class
*trace_class
;
533 char tmp_prefix
[TMP_PREFIX_LEN
];
535 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream_class
->id
));
537 if (stream_class
->name
.value
) {
538 BUF_APPEND(", %sname=\"%s\"",
539 PRFIELD(stream_class
->name
.value
));
546 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
548 if (stream_class
->event_classes
) {
549 BUF_APPEND(", %sevent-class-count=%u",
550 PRFIELD(stream_class
->event_classes
->len
));
553 BUF_APPEND(", %spacket-context-fc-addr=%p, "
554 "%sevent-common-context-fc-addr=%p",
555 PRFIELD(stream_class
->packet_context_fc
),
556 PRFIELD(stream_class
->event_common_context_fc
));
557 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
562 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
563 "%ssupports-packets=%d, "
564 "%spackets-have-begin-default-cs=%d, "
565 "%spackets-have-end-default-cs=%d, "
566 "%ssupports-discarded-events=%d, "
567 "%sdiscarded-events-have-default-cs=%d, "
568 "%ssupports-discarded-packets=%d, "
569 "%sdiscarded-packets-have-default-cs=%d",
570 PRFIELD(stream_class
->assigns_automatic_event_class_id
),
571 PRFIELD(stream_class
->assigns_automatic_stream_id
),
572 PRFIELD(stream_class
->supports_packets
),
573 PRFIELD(stream_class
->packets_have_beginning_default_clock_snapshot
),
574 PRFIELD(stream_class
->packets_have_end_default_clock_snapshot
),
575 PRFIELD(stream_class
->supports_discarded_events
),
576 PRFIELD(stream_class
->discarded_events_have_default_clock_snapshots
),
577 PRFIELD(stream_class
->supports_discarded_packets
),
578 PRFIELD(stream_class
->discarded_packets_have_default_clock_snapshots
));
579 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
580 SET_TMP_PREFIX("trace-class-");
581 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
582 SET_TMP_PREFIX("pcf-pool-");
583 format_object_pool(buf_ch
, tmp_prefix
,
584 &stream_class
->packet_context_field_pool
);
587 static inline void format_event_class(char **buf_ch
, bool extended
,
588 const char *prefix
, const struct bt_event_class
*event_class
)
590 const struct bt_stream_class
*stream_class
;
591 const struct bt_trace_class
*trace_class
;
592 char tmp_prefix
[TMP_PREFIX_LEN
];
594 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(event_class
->id
));
596 if (event_class
->name
.value
) {
597 BUF_APPEND(", %sname=\"%s\"",
598 PRFIELD(event_class
->name
.value
));
605 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class
->frozen
));
607 if (event_class
->log_level
.base
.avail
) {
608 BUF_APPEND(", %slog-level=%s",
609 PRFIELD(bt_common_event_class_log_level_string(
610 (int) event_class
->log_level
.value
)));
613 if (event_class
->emf_uri
.value
) {
614 BUF_APPEND(", %semf-uri=\"%s\"",
615 PRFIELD(event_class
->emf_uri
.value
));
618 BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
619 PRFIELD(event_class
->specific_context_fc
),
620 PRFIELD(event_class
->payload_fc
));
622 stream_class
= bt_event_class_borrow_stream_class_const(event_class
);
627 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
628 SET_TMP_PREFIX("stream-class-");
629 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
630 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
635 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
636 SET_TMP_PREFIX("trace-class-");
637 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
638 SET_TMP_PREFIX("event-pool-");
639 format_object_pool(buf_ch
, tmp_prefix
, &event_class
->event_pool
);
642 static inline void format_stream(char **buf_ch
, bool extended
,
643 const char *prefix
, const struct bt_stream
*stream
)
645 const struct bt_stream_class
*stream_class
;
646 const struct bt_trace_class
*trace_class
= NULL
;
647 const struct bt_trace
*trace
= NULL
;
648 char tmp_prefix
[TMP_PREFIX_LEN
];
650 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream
->id
));
652 if (stream
->name
.value
) {
653 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
.value
));
660 stream_class
= bt_stream_borrow_class_const(stream
);
662 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
663 SET_TMP_PREFIX("stream-class-");
664 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
665 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
669 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
670 SET_TMP_PREFIX("trace-class-");
671 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
674 trace
= bt_stream_borrow_trace_inline(stream
);
676 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
677 SET_TMP_PREFIX("trace-");
678 format_trace(buf_ch
, false, tmp_prefix
, trace
);
681 SET_TMP_PREFIX("packet-pool-");
682 format_object_pool(buf_ch
, tmp_prefix
, &stream
->packet_pool
);
685 static inline void format_packet(char **buf_ch
, bool extended
,
686 const char *prefix
, const struct bt_packet
*packet
)
688 const struct bt_stream
*stream
;
689 const struct bt_trace_class
*trace_class
;
690 char tmp_prefix
[TMP_PREFIX_LEN
];
696 BUF_APPEND(", %sis-frozen=%d, %scontext-field-addr=%p",
697 PRFIELD(packet
->frozen
),
698 PRFIELD(packet
->context_field
? packet
->context_field
->field
: NULL
));
699 stream
= bt_packet_borrow_stream_const(packet
);
704 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
705 SET_TMP_PREFIX("stream-");
706 format_stream(buf_ch
, false, tmp_prefix
, stream
);
707 trace_class
= (const struct bt_trace_class
*) bt_object_borrow_parent(&stream
->base
);
712 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
713 SET_TMP_PREFIX("trace-class-");
714 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
717 static inline void format_event(char **buf_ch
, bool extended
,
718 const char *prefix
, const struct bt_event
*event
)
720 const struct bt_trace_class
*trace_class
;
721 const struct bt_stream_class
*stream_class
;
722 char tmp_prefix
[TMP_PREFIX_LEN
];
728 BUF_APPEND(", %sis-frozen=%d, "
729 "%scommon-context-field-addr=%p, "
730 "%sspecific-context-field-addr=%p, "
731 "%spayload-field-addr=%p, ",
732 PRFIELD(event
->frozen
),
733 PRFIELD(event
->common_context_field
),
734 PRFIELD(event
->specific_context_field
),
735 PRFIELD(event
->payload_field
));
736 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
742 SET_TMP_PREFIX("event-class-");
743 format_event_class(buf_ch
, false, tmp_prefix
, event
->class);
744 stream_class
= bt_event_class_borrow_stream_class(event
->class);
746 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
747 SET_TMP_PREFIX("stream-class-");
748 format_stream_class(buf_ch
, false, tmp_prefix
,
751 trace_class
= bt_stream_class_borrow_trace_class_inline(
754 BUF_APPEND(", %strace-class-addr=%p",
755 PRFIELD(trace_class
));
756 SET_TMP_PREFIX("trace-class-");
757 format_trace_class(buf_ch
, false, tmp_prefix
,
763 BUF_APPEND(", %sstream-addr=%p", PRFIELD(event
->stream
));
764 SET_TMP_PREFIX("stream-");
765 format_stream(buf_ch
, false, tmp_prefix
, event
->stream
);
769 BUF_APPEND(", %spacket-addr=%p", PRFIELD(event
->packet
));
770 SET_TMP_PREFIX("packet-");
771 format_packet(buf_ch
, false, tmp_prefix
, event
->packet
);
775 static inline void format_clock_class(char **buf_ch
, bool extended
,
776 const char *prefix
, const struct bt_clock_class
*clock_class
)
778 char tmp_prefix
[TMP_PREFIX_LEN
];
780 if (clock_class
->name
.value
) {
781 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class
->name
.value
));
784 BUF_APPEND(", %sfreq=%" PRIu64
, PRFIELD(clock_class
->frequency
));
790 if (clock_class
->description
.value
) {
791 BUF_APPEND(", %spartial-descr=\"%.32s\"",
792 PRFIELD(clock_class
->description
.value
));
795 if (clock_class
->uuid
.value
) {
796 BUF_APPEND_UUID(clock_class
->uuid
.value
);
799 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
800 "%soffset-s=%" PRId64
", "
801 "%soffset-cycles=%" PRIu64
", %sorigin-is-unix-epoch=%d, "
802 "%sbase-offset-ns=%" PRId64
,
803 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
804 PRFIELD(clock_class
->offset_seconds
),
805 PRFIELD(clock_class
->offset_cycles
),
806 PRFIELD(clock_class
->origin_is_unix_epoch
),
807 PRFIELD(clock_class
->base_offset
.value_ns
));
809 SET_TMP_PREFIX("cs-pool-");
810 format_object_pool(buf_ch
, tmp_prefix
, &clock_class
->cs_pool
);
813 static inline void format_clock_snapshot(char **buf_ch
, bool extended
,
814 const char *prefix
, const struct bt_clock_snapshot
*clock_snapshot
)
816 char tmp_prefix
[TMP_PREFIX_LEN
];
817 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-origin=%" PRId64
,
818 PRFIELD(clock_snapshot
->value_cycles
),
819 PRFIELD(clock_snapshot
->ns_from_origin
));
825 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_snapshot
->is_set
));
827 if (clock_snapshot
->clock_class
) {
828 BUF_APPEND(", %sclock-class-addr=%p",
829 PRFIELD(clock_snapshot
->clock_class
));
830 SET_TMP_PREFIX("clock-class-");
831 format_clock_class(buf_ch
, false, tmp_prefix
,
832 clock_snapshot
->clock_class
);
836 static inline void format_interrupter(char **buf_ch
, const char *prefix
,
837 const struct bt_interrupter
*intr
)
839 BUF_APPEND(", %sis-set=%d", PRFIELD(intr
->is_set
));
842 static inline void format_value(char **buf_ch
, bool extended
,
843 const char *prefix
, const struct bt_value
*value
)
845 BUF_APPEND(", %stype=%s",
846 PRFIELD(bt_common_value_type_string(bt_value_get_type(value
))));
852 switch (bt_value_get_type(value
)) {
853 case BT_VALUE_TYPE_BOOL
:
855 bt_bool val
= bt_value_bool_get(value
);
857 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
860 case BT_VALUE_TYPE_UNSIGNED_INTEGER
:
862 BUF_APPEND(", %svalue=%" PRIu64
,
863 PRFIELD(bt_value_integer_unsigned_get(value
)));
866 case BT_VALUE_TYPE_SIGNED_INTEGER
:
868 BUF_APPEND(", %svalue=%" PRId64
,
869 PRFIELD(bt_value_integer_signed_get(value
)));
872 case BT_VALUE_TYPE_REAL
:
874 double val
= bt_value_real_get(value
);
876 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
879 case BT_VALUE_TYPE_STRING
:
881 const char *val
= bt_value_string_get(value
);
883 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
886 case BT_VALUE_TYPE_ARRAY
:
888 uint64_t count
= bt_value_array_get_length(value
);
890 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
893 case BT_VALUE_TYPE_MAP
:
895 int64_t count
= bt_value_map_get_size(value
);
897 BT_ASSERT(count
>= 0);
898 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
906 static inline void format_integer_range_set(char **buf_ch
, bool extended
,
908 const struct bt_integer_range_set
*range_set
)
910 BUF_APPEND(", %srange-count=%u", PRFIELD(range_set
->ranges
->len
));
916 BUF_APPEND(", %sis-frozen=%d", PRFIELD(range_set
->frozen
));
919 static inline void format_message(char **buf_ch
, bool extended
,
920 const char *prefix
, const struct bt_message
*msg
)
922 char tmp_prefix
[TMP_PREFIX_LEN
];
924 BUF_APPEND(", %stype=%s",
925 PRFIELD(bt_common_message_type_string(msg
->type
)));
931 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
932 PRFIELD(msg
->frozen
), PRFIELD(msg
->graph
));
935 case BT_MESSAGE_TYPE_EVENT
:
937 const struct bt_message_event
*msg_event
=
940 if (msg_event
->event
) {
941 SET_TMP_PREFIX("event-");
942 format_event(buf_ch
, true, tmp_prefix
,
946 if (msg_event
->default_cs
) {
947 SET_TMP_PREFIX("default-cs-");
948 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
949 msg_event
->default_cs
);
954 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
955 case BT_MESSAGE_TYPE_STREAM_END
:
957 const struct bt_message_stream
*msg_stream
= (const void *) msg
;
959 if (msg_stream
->stream
) {
960 SET_TMP_PREFIX("stream-");
961 format_stream(buf_ch
, true, tmp_prefix
,
965 BUF_APPEND(", %sdefault-cs-state=%s",
966 PRFIELD(bt_message_stream_clock_snapshot_state_string(
967 msg_stream
->default_cs_state
)));
969 if (msg_stream
->default_cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
970 SET_TMP_PREFIX("default-cs-");
971 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
972 msg_stream
->default_cs
);
977 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
978 case BT_MESSAGE_TYPE_PACKET_END
:
980 const struct bt_message_packet
*msg_packet
= (const void *) msg
;
982 if (msg_packet
->packet
) {
983 SET_TMP_PREFIX("packet-");
984 format_packet(buf_ch
, true, tmp_prefix
,
988 if (msg_packet
->default_cs
) {
989 SET_TMP_PREFIX("default-cs-");
990 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
991 msg_packet
->default_cs
);
996 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
997 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
999 const struct bt_message_discarded_items
*msg_disc_items
=
1002 if (msg_disc_items
->stream
) {
1003 SET_TMP_PREFIX("stream-");
1004 format_stream(buf_ch
, true, tmp_prefix
,
1005 msg_disc_items
->stream
);
1008 if (msg_disc_items
->default_begin_cs
) {
1009 SET_TMP_PREFIX("begin-default-cs-");
1010 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1011 msg_disc_items
->default_begin_cs
);
1014 if (msg_disc_items
->default_end_cs
) {
1015 SET_TMP_PREFIX("end-default-cs-");
1016 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1017 msg_disc_items
->default_end_cs
);
1020 if (msg_disc_items
->count
.base
.avail
) {
1021 BUF_APPEND(", %scount=%" PRIu64
,
1022 PRFIELD(msg_disc_items
->count
.value
));
1032 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
1034 const struct bt_plugin_so_shared_lib_handle
*handle
)
1036 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
1039 BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle
->path
));
1043 static inline void format_component_class(char **buf_ch
, bool extended
,
1045 const struct bt_component_class
*comp_class
)
1047 char tmp_prefix
[TMP_PREFIX_LEN
];
1049 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1050 PRFIELD(bt_common_component_class_type_string(comp_class
->type
)),
1051 PRFIELD_GSTRING(comp_class
->name
));
1053 if (comp_class
->description
) {
1054 BUF_APPEND(", %spartial-descr=\"%.32s\"",
1055 PRFIELD_GSTRING(comp_class
->description
));
1062 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
1064 if (comp_class
->so_handle
) {
1065 SET_TMP_PREFIX("so-handle-");
1066 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1067 comp_class
->so_handle
);
1071 static inline void format_component(char **buf_ch
, bool extended
,
1072 const char *prefix
, const struct bt_component
*component
)
1074 char tmp_prefix
[TMP_PREFIX_LEN
];
1076 BUF_APPEND(", %sname=\"%s\", %slog-level=%s",
1077 PRFIELD_GSTRING(component
->name
),
1078 PRFIELD(bt_common_logging_level_string(component
->log_level
)));
1080 if (component
->class) {
1081 SET_TMP_PREFIX("class-");
1082 format_component_class(buf_ch
, extended
, tmp_prefix
,
1090 if (component
->input_ports
) {
1091 BUF_APPEND(", %sinput-port-count=%u",
1092 PRFIELD(component
->input_ports
->len
));
1095 if (component
->output_ports
) {
1096 BUF_APPEND(", %soutput-port-count=%u",
1097 PRFIELD(component
->output_ports
->len
));
1101 static inline void format_port(char **buf_ch
, bool extended
,
1102 const char *prefix
, const struct bt_port
*port
)
1104 char tmp_prefix
[TMP_PREFIX_LEN
];
1106 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1107 PRFIELD(bt_port_type_string(port
->type
)),
1108 PRFIELD_GSTRING(port
->name
));
1114 if (port
->connection
) {
1115 SET_TMP_PREFIX("conn-");
1116 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1120 static inline void format_connection(char **buf_ch
, bool extended
,
1121 const char *prefix
, const struct bt_connection
*connection
)
1123 char tmp_prefix
[TMP_PREFIX_LEN
];
1129 if (connection
->upstream_port
) {
1130 SET_TMP_PREFIX("upstream-port-");
1131 format_port(buf_ch
, false, tmp_prefix
,
1132 connection
->upstream_port
);
1135 if (connection
->downstream_port
) {
1136 SET_TMP_PREFIX("downstream-port-");
1137 format_port(buf_ch
, false, tmp_prefix
,
1138 connection
->downstream_port
);
1142 static inline void format_graph(char **buf_ch
, bool extended
,
1143 const char *prefix
, const struct bt_graph
*graph
)
1145 char tmp_prefix
[TMP_PREFIX_LEN
];
1147 BUF_APPEND(", %scan-consume=%d, %sconfig-state=%s",
1148 PRFIELD(graph
->can_consume
),
1149 PRFIELD(bt_graph_configuration_state_string(graph
->config_state
)));
1155 if (graph
->components
) {
1156 BUF_APPEND(", %scomp-count=%u",
1157 PRFIELD(graph
->components
->len
));
1160 if (graph
->connections
) {
1161 BUF_APPEND(", %sconn-count=%u",
1162 PRFIELD(graph
->connections
->len
));
1165 SET_TMP_PREFIX("en-pool-");
1166 format_object_pool(buf_ch
, tmp_prefix
, &graph
->event_msg_pool
);
1167 SET_TMP_PREFIX("pbn-pool-");
1168 format_object_pool(buf_ch
, tmp_prefix
, &graph
->packet_begin_msg_pool
);
1169 SET_TMP_PREFIX("pen-pool-");
1170 format_object_pool(buf_ch
, tmp_prefix
, &graph
->packet_end_msg_pool
);
1173 static inline void format_message_iterator(char **buf_ch
,
1174 bool extended
, const char *prefix
,
1175 const struct bt_message_iterator
*iterator
)
1177 char tmp_prefix
[TMP_PREFIX_LEN
];
1178 const struct bt_message_iterator
*
1179 port_in_iter
= (const void *) iterator
;
1181 if (port_in_iter
->upstream_component
) {
1182 SET_TMP_PREFIX("upstream-comp-");
1183 format_component(buf_ch
, false, tmp_prefix
,
1184 port_in_iter
->upstream_component
);
1191 if (port_in_iter
->upstream_port
) {
1192 SET_TMP_PREFIX("upstream-port-");
1193 format_port(buf_ch
, false, tmp_prefix
,
1194 port_in_iter
->upstream_port
);
1197 if (port_in_iter
->connection
) {
1198 SET_TMP_PREFIX("upstream-conn-");
1199 format_connection(buf_ch
, false, tmp_prefix
,
1200 port_in_iter
->connection
);
1207 static inline void format_plugin(char **buf_ch
, bool extended
,
1208 const char *prefix
, const struct bt_plugin
*plugin
)
1210 char tmp_prefix
[TMP_PREFIX_LEN
];
1212 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1214 if (plugin
->info
.path_set
) {
1215 BUF_APPEND(", %spath=\"%s\"",
1216 PRFIELD_GSTRING(plugin
->info
.path
));
1219 if (plugin
->info
.name_set
) {
1220 BUF_APPEND(", %sname=\"%s\"",
1221 PRFIELD_GSTRING(plugin
->info
.name
));
1228 if (plugin
->info
.author_set
) {
1229 BUF_APPEND(", %sauthor=\"%s\"",
1230 PRFIELD_GSTRING(plugin
->info
.author
));
1233 if (plugin
->info
.license_set
) {
1234 BUF_APPEND(", %slicense=\"%s\"",
1235 PRFIELD_GSTRING(plugin
->info
.license
));
1238 if (plugin
->info
.version_set
) {
1239 BUF_APPEND(", %sversion=%u.%u.%u%s",
1240 PRFIELD(plugin
->info
.version
.major
),
1241 plugin
->info
.version
.minor
,
1242 plugin
->info
.version
.patch
,
1243 plugin
->info
.version
.extra
?
1244 plugin
->info
.version
.extra
->str
: "");
1247 BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, "
1248 "%ssink-comp-class-count=%u",
1249 PRFIELD(plugin
->src_comp_classes
->len
),
1250 PRFIELD(plugin
->flt_comp_classes
->len
),
1251 PRFIELD(plugin
->sink_comp_classes
->len
));
1253 if (plugin
->spec_data
) {
1254 const struct bt_plugin_so_spec_data
*spec_data
=
1255 (const void *) plugin
->spec_data
;
1257 if (spec_data
->shared_lib_handle
) {
1258 SET_TMP_PREFIX("so-handle-");
1259 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1260 spec_data
->shared_lib_handle
);
1265 static inline void format_error_cause(char **buf_ch
, bool extended
,
1266 const char *prefix
, const struct bt_error_cause
*cause
)
1268 const struct bt_error_cause_component_class_id
*comp_class_id
= NULL
;
1270 BUF_APPEND(", %sactor-type=%s, %smodule-name=\"%s\"",
1271 PRFIELD(bt_error_cause_actor_type_string(cause
->actor_type
)),
1272 PRFIELD_GSTRING(cause
->module_name
));
1278 BUF_APPEND(", %spartial-msg=\"%.32s\"",
1279 PRFIELD_GSTRING(cause
->message
));
1281 switch (cause
->actor_type
) {
1282 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT
:
1284 const struct bt_error_cause_component_actor
*spec_cause
=
1285 (const void *) cause
;
1287 BUF_APPEND(", %scomp-name=\"%s\"",
1288 PRFIELD_GSTRING(spec_cause
->comp_name
));
1289 comp_class_id
= &spec_cause
->comp_class_id
;
1292 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS
:
1294 const struct bt_error_cause_component_class_actor
*spec_cause
=
1295 (const void *) cause
;
1297 comp_class_id
= &spec_cause
->comp_class_id
;
1300 case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR
:
1302 const struct bt_error_cause_message_iterator_actor
*spec_cause
=
1303 (const void *) cause
;
1305 BUF_APPEND(", %scomp-name=\"%s\", %scomp-out-port-name=\"%s\"",
1306 PRFIELD_GSTRING(spec_cause
->comp_name
),
1307 PRFIELD_GSTRING(spec_cause
->output_port_name
));
1308 comp_class_id
= &spec_cause
->comp_class_id
;
1315 if (comp_class_id
) {
1316 BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", "
1317 "%splugin-name=\"%s\"",
1318 PRFIELD(bt_common_component_class_type_string(
1319 comp_class_id
->type
)),
1320 PRFIELD_GSTRING(comp_class_id
->name
),
1321 PRFIELD_GSTRING(comp_class_id
->plugin_name
));
1325 static inline void handle_conversion_specifier_bt(
1326 void *priv_data
__attribute__((unused
)),
1328 size_t avail_size
__attribute__((unused
)),
1329 const char **out_fmt_ch
, va_list *args
)
1331 const char *fmt_ch
= *out_fmt_ch
;
1332 bool extended
= false;
1334 char *prefix_ch
= prefix
;
1340 if (*fmt_ch
== 'u') {
1342 obj
= va_arg(*args
, void *);
1343 format_uuid(buf_ch
, obj
);
1347 if (*fmt_ch
== '[') {
1352 if (*fmt_ch
== ']') {
1358 *prefix_ch
= *fmt_ch
;
1366 if (*fmt_ch
== '+') {
1371 obj
= va_arg(*args
, void *);
1372 BUF_APPEND("%saddr=%p", prefix
, obj
);
1380 format_field_class(buf_ch
, extended
, prefix
, obj
);
1383 format_field(buf_ch
, extended
, prefix
, obj
);
1386 format_field_path(buf_ch
, extended
, prefix
, obj
);
1389 format_event_class(buf_ch
, extended
, prefix
, obj
);
1392 format_event(buf_ch
, extended
, prefix
, obj
);
1395 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1398 format_stream(buf_ch
, extended
, prefix
, obj
);
1401 format_packet(buf_ch
, extended
, prefix
, obj
);
1404 format_trace(buf_ch
, extended
, prefix
, obj
);
1407 format_trace_class(buf_ch
, extended
, prefix
, obj
);
1410 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1413 format_clock_snapshot(buf_ch
, extended
, prefix
, obj
);
1416 format_value(buf_ch
, extended
, prefix
, obj
);
1419 format_integer_range_set(buf_ch
, extended
, prefix
, obj
);
1422 format_message(buf_ch
, extended
, prefix
, obj
);
1425 /* Empty, the address is automatically printed. */
1428 format_message_iterator(buf_ch
, extended
, prefix
, obj
);
1431 format_component_class(buf_ch
, extended
, prefix
, obj
);
1434 format_component(buf_ch
, extended
, prefix
, obj
);
1437 format_port(buf_ch
, extended
, prefix
, obj
);
1440 format_connection(buf_ch
, extended
, prefix
, obj
);
1443 format_plugin(buf_ch
, extended
, prefix
, obj
);
1446 format_graph(buf_ch
, extended
, prefix
, obj
);
1449 format_interrupter(buf_ch
, prefix
, obj
);
1452 format_object_pool(buf_ch
, prefix
, obj
);
1455 format_object(buf_ch
, prefix
, obj
);
1458 format_error_cause(buf_ch
, extended
, prefix
, obj
);
1466 *out_fmt_ch
= fmt_ch
;
1470 * This function would normally not be BT_EXPORTed, but it is used by the
1471 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1472 * implemented as a separate shared object, for modularity. It is therefore
1473 * exposed, but not part of the public ABI.
1476 void bt_lib_log_v(const char *file
, const char *func
, unsigned line
,
1477 int lvl
, const char *tag
, const char *fmt
, va_list *args
)
1480 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1481 handle_conversion_specifier_bt
, NULL
, fmt
, args
);
1482 bt_log_write(file
, func
, line
, lvl
, tag
, lib_logging_buf
);
1486 * This function would normally not be BT_EXPORTed, but it is used by the
1487 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1488 * implemented as a separate shared object, for modularity. It is therefore
1489 * exposed, but not part of the public ABI.
1492 void bt_lib_log(const char *file
, const char *func
, unsigned line
,
1493 int lvl
, const char *tag
, const char *fmt
, ...)
1498 va_start(args
, fmt
);
1499 bt_lib_log_v(file
, func
, line
, lvl
, tag
, fmt
, &args
);
1504 * This function would normally not be BT_EXPORTed, but it is used by the
1505 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1506 * implemented as a separate shared object, for modularity. It is therefore
1507 * exposed, but not part of the ABI.
1510 void bt_lib_maybe_log_and_append_cause(const char *func
, const char *file
,
1511 unsigned line
, int lvl
, const char *tag
,
1512 const char *fmt
, ...)
1515 bt_current_thread_error_append_cause_status status
;
1518 va_start(args
, fmt
);
1519 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1520 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1523 /* Log conditionally, but always append the error cause */
1524 if (BT_LOG_ON(lvl
)) {
1525 bt_log_write(file
, func
, line
, lvl
, tag
, lib_logging_buf
);
1528 status
= bt_current_thread_error_append_cause_from_unknown(
1529 BT_LIB_LOG_LIBBABELTRACE2_NAME
, file
, line
, "%s",
1533 * Worst case: this error cause is not appended to the
1534 * current thread's error.
1536 * We can accept this as it's an almost impossible
1537 * scenario and returning an error here would mean you
1538 * need to check the return value of each
1539 * BT_LIB_LOG*_APPEND_CAUSE() macro and that would be
1542 BT_LOGE("Cannot append error cause to current thread's "
1543 "error object: status=%s",
1544 bt_common_func_status_string(status
));