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-location.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_field_location(char **buf_ch
, bool extended
,
113 const char *prefix
, const struct bt_field_location
*field_location
);
115 static inline void format_object(char **buf_ch
, const char *prefix
,
116 const struct bt_object
*obj
)
118 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
121 static inline void format_uuid(char **buf_ch
, bt_uuid uuid
)
123 BUF_APPEND("\"" BT_UUID_FMT
"\"", BT_UUID_FMT_VALUES(uuid
));
126 static inline void format_object_pool(char **buf_ch
, const char *prefix
,
127 const struct bt_object_pool
*pool
)
129 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
132 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
136 static inline void format_integer_field_class(char **buf_ch
, const char *prefix
,
137 const struct bt_field_class
*field_class
)
139 const struct bt_field_class_integer
*int_fc
=
140 (const void *) field_class
;
142 BUF_APPEND(", %srange-size=%" PRIu64
", %sbase=%s",
143 PRFIELD(int_fc
->range
),
144 PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc
->base
)));
147 static inline void format_array_field_class(char **buf_ch
, const char *prefix
,
148 const struct bt_field_class
*field_class
)
150 const struct bt_field_class_array
*array_fc
=
151 (const void *) field_class
;
153 BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s",
154 PRFIELD(array_fc
->element_fc
),
155 PRFIELD(bt_common_field_class_type_string(array_fc
->element_fc
->type
)));
158 static inline void format_blob_field_class(char **buf_ch
, const char *prefix
,
159 const struct bt_field_class_blob
*field_class
)
161 BUF_APPEND(", %smedia-type=\"%s\"",
162 PRFIELD(field_class
->media_type
->str
));
165 static inline void format_field_class(char **buf_ch
, bool extended
,
166 const char *prefix
, const struct bt_field_class
*field_class
)
168 char tmp_prefix
[TMP_PREFIX_LEN
];
170 BUF_APPEND(", %stype=%s",
171 PRFIELD(bt_common_field_class_type_string(field_class
->type
)));
174 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class
->frozen
));
175 BUF_APPEND(", %sis-part-of-trace-class=%d",
176 PRFIELD(field_class
->part_of_trace_class
));
181 switch (field_class
->type
) {
182 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
184 const struct bt_field_class_bit_array
*ba_fc
=
185 (const void *) field_class
;
187 BUF_APPEND(", %slength=%" PRIu64
", %sflag-count=%u",
188 PRFIELD(ba_fc
->length
), PRFIELD(ba_fc
->flags
->len
));
191 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
192 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
194 format_integer_field_class(buf_ch
, prefix
, field_class
);
197 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
198 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
200 const struct bt_field_class_enumeration
*enum_fc
=
201 (const void *) field_class
;
203 format_integer_field_class(buf_ch
, prefix
, field_class
);
204 BUF_APPEND(", %smapping-count=%u",
205 PRFIELD(enum_fc
->mappings
->len
));
208 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
210 const struct bt_field_class_structure
*struct_fc
=
211 (const void *) field_class
;
213 if (struct_fc
->common
.named_fcs
) {
214 BUF_APPEND(", %smember-count=%u",
215 PRFIELD(struct_fc
->common
.named_fcs
->len
));
220 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
222 const struct bt_field_class_array_static
*array_fc
=
223 (const void *) field_class
;
225 format_array_field_class(buf_ch
, prefix
, field_class
);
226 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_fc
->length
));
229 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
230 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
232 const struct bt_field_class_array_dynamic
*array_fc
=
233 (const void *) field_class
;
235 format_array_field_class(buf_ch
, prefix
, field_class
);
237 if (field_class
->type
== BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
) {
238 switch (array_fc
->length_field
.xref_kind
) {
239 case FIELD_XREF_KIND_PATH
:
240 BT_ASSERT(array_fc
->length_field
.path
.class);
241 SET_TMP_PREFIX("length-fc-");
242 format_field_class(buf_ch
, extended
, tmp_prefix
,
243 array_fc
->length_field
.path
.class);
245 if (array_fc
->length_field
.path
.path
) {
246 SET_TMP_PREFIX("length-field-path-");
247 format_field_path(buf_ch
, extended
, tmp_prefix
,
248 array_fc
->length_field
.path
.path
);
251 case FIELD_XREF_KIND_LOCATION
:
252 BT_ASSERT(array_fc
->length_field
.location
);
253 SET_TMP_PREFIX("length-fl-");
254 format_field_location(buf_ch
, extended
, tmp_prefix
,
255 array_fc
->length_field
.location
);
262 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
263 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
264 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
265 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
267 const struct bt_field_class_option
*opt_fc
=
268 (const void *) field_class
;
270 BUF_APPEND(", %scontent-fc-addr=%p, %scontent-fc-type=%s",
271 PRFIELD(opt_fc
->content_fc
),
272 PRFIELD(bt_common_field_class_type_string(opt_fc
->content_fc
->type
)));
274 if (field_class
->type
!=
275 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
276 const struct bt_field_class_option_with_selector_field
*opt_with_sel_fc
=
277 (const void *) field_class
;
279 switch (opt_with_sel_fc
->selector_field_xref_kind
) {
280 case FIELD_XREF_KIND_PATH
:
281 BT_ASSERT(opt_with_sel_fc
->selector_field
.path
.class);
282 SET_TMP_PREFIX("selector-fc-");
283 format_field_class(buf_ch
, extended
, tmp_prefix
,
284 opt_with_sel_fc
->selector_field
.path
.class);
286 if (opt_with_sel_fc
->selector_field
.path
.path
) {
287 SET_TMP_PREFIX("selector-field-path-");
288 format_field_path(buf_ch
, extended
, tmp_prefix
,
289 opt_with_sel_fc
->selector_field
.path
.path
);
292 case FIELD_XREF_KIND_LOCATION
:
293 BT_ASSERT_DBG(opt_with_sel_fc
->selector_field
.location
);
294 SET_TMP_PREFIX("selector-fl-");
295 format_field_location(buf_ch
, extended
, tmp_prefix
,
296 opt_with_sel_fc
->selector_field
.location
);
303 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
304 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
305 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
307 const struct bt_field_class_variant
*var_fc
=
308 (const void *) field_class
;
310 if (var_fc
->common
.named_fcs
) {
311 BUF_APPEND(", %soption-count=%u",
312 PRFIELD(var_fc
->common
.named_fcs
->len
));
315 if (field_class
->type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
||
316 field_class
->type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
) {
317 const struct bt_field_class_variant_with_selector_field
*var_with_sel_fc
=
318 (const void *) var_fc
;
320 switch (var_with_sel_fc
->selector_field_xref_kind
) {
321 case FIELD_XREF_KIND_PATH
:
322 BT_ASSERT(var_with_sel_fc
->selector_field
.path
.class);
323 SET_TMP_PREFIX("selector-fc-");
324 format_field_class(buf_ch
, extended
, tmp_prefix
,
325 var_with_sel_fc
->selector_field
.path
.class);
328 if (var_with_sel_fc
->selector_field
.path
.path
) {
329 SET_TMP_PREFIX("selector-field-path-");
330 format_field_path(buf_ch
, extended
, tmp_prefix
,
331 var_with_sel_fc
->selector_field
.path
.path
);
334 case FIELD_XREF_KIND_LOCATION
:
335 BT_ASSERT(var_with_sel_fc
->selector_field
.location
);
336 SET_TMP_PREFIX("selector-fl-");
337 format_field_location(buf_ch
, extended
, tmp_prefix
,
338 var_with_sel_fc
->selector_field
.location
);
345 case BT_FIELD_CLASS_TYPE_STATIC_BLOB
:
347 const struct bt_field_class_blob_static
*blob_fc
=
348 (const void *) field_class
;
350 format_blob_field_class(buf_ch
, prefix
, (const void *) blob_fc
);
351 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(blob_fc
->length
));
354 case BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITHOUT_LENGTH_FIELD
:
355 case BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD
:
357 const struct bt_field_class_blob_dynamic
*blob_fc
=
358 (const void *) field_class
;
360 format_blob_field_class(buf_ch
, prefix
, (const void *) blob_fc
);
362 if (field_class
->type
== BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD
) {
363 BT_ASSERT(blob_fc
->length_fl
);
364 SET_TMP_PREFIX("length-fl-");
365 format_field_location(buf_ch
, extended
, tmp_prefix
,
377 static inline void format_field_integer_extended(char **buf_ch
,
378 const char *prefix
, const struct bt_field
*field
)
380 const struct bt_field_integer
*integer
= (void *) field
;
381 const struct bt_field_class_integer
*field_class
=
382 (void *) field
->class;
383 const char *fmt
= NULL
;
385 BT_ASSERT(field_class
);
387 if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
) {
388 fmt
= ", %svalue=%" PRIo64
;
389 } else if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
) {
390 fmt
= ", %svalue=%" PRIx64
;
393 #pragma GCC diagnostic push
394 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
395 if (field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
396 field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
398 fmt
= ", %svalue=%" PRId64
;
401 BUF_APPEND(fmt
, PRFIELD(integer
->value
.i
));
404 fmt
= ", %svalue=%" PRIu64
;
407 BUF_APPEND(fmt
, PRFIELD(integer
->value
.u
));
409 #pragma GCC diagnostic pop
412 static inline void format_field(char **buf_ch
, bool extended
,
413 const char *prefix
, const struct bt_field
*field
)
415 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->is_set
));
418 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
421 BUF_APPEND(", %sclass-addr=%p", PRFIELD(field
->class));
427 BUF_APPEND(", %sclass-type=%s",
428 PRFIELD(bt_common_field_class_type_string(field
->class->type
)));
430 if (!extended
|| !field
->is_set
) {
434 switch (field
->class->type
) {
435 case BT_FIELD_CLASS_TYPE_BOOL
:
437 const struct bt_field_bool
*bool_field
= (const void *) field
;
439 BUF_APPEND(", %svalue=%d", PRFIELD(bool_field
->value
));
442 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
444 const struct bt_field_bit_array
*ba_field
= (const void *) field
;
446 BUF_APPEND(", %svalue-as-int=%" PRIx64
,
447 PRFIELD(ba_field
->value_as_int
));
450 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
451 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
452 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
453 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
455 format_field_integer_extended(buf_ch
, prefix
, field
);
458 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
459 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
461 const struct bt_field_real
*real_field
= (const void *) field
;
463 BUF_APPEND(", %svalue=%f", PRFIELD(real_field
->value
));
466 case BT_FIELD_CLASS_TYPE_STRING
:
468 const struct bt_field_string
*str
= (const void *) field
;
471 BT_ASSERT(str
->buf
->data
);
472 BUF_APPEND(", %spartial-value=\"%.32s\"",
473 PRFIELD(str
->buf
->data
));
478 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
479 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
480 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
482 const struct bt_field_array
*array_field
= (const void *) field
;
484 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_field
->length
));
486 if (array_field
->fields
) {
487 BUF_APPEND(", %sallocated-length=%u",
488 PRFIELD(array_field
->fields
->len
));
493 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
494 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
495 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
497 const struct bt_field_variant
*var_field
= (const void *) field
;
499 BUF_APPEND(", %sselected-field-index=%" PRIu64
,
500 PRFIELD(var_field
->selected_index
));
508 static inline void format_field_path(char **buf_ch
, bool extended
,
509 const char *prefix
, const struct bt_field_path
*field_path
)
513 if (field_path
->items
) {
514 BT_ASSERT(field_path
->items
);
515 BUF_APPEND(", %sitem-count=%u",
516 PRFIELD(field_path
->items
->len
));
519 if (!extended
|| !field_path
->items
) {
523 BUF_APPEND(", %spath=[%s",
524 PRFIELD(bt_common_field_path_scope_string(field_path
->root
)));
526 for (i
= 0; i
< bt_field_path_get_item_count(field_path
); i
++) {
527 const struct bt_field_path_item
*fp_item
=
528 bt_field_path_borrow_item_by_index_const(field_path
, i
);
530 switch (bt_field_path_item_get_type(fp_item
)) {
531 case BT_FIELD_PATH_ITEM_TYPE_INDEX
:
532 BUF_APPEND(", %" PRIu64
,
533 bt_field_path_item_index_get_index(fp_item
));
535 case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
:
536 BUF_APPEND("%s", ", <CUR>");
543 BUF_APPEND("%s", "]");
546 static inline void format_field_location(char **buf_ch
, bool extended
,
547 const char *prefix
, const struct bt_field_location
*field_location
)
551 BT_ASSERT(field_location
->items
);
553 BUF_APPEND(", %sitem-count=%u", PRFIELD(field_location
->items
->len
));
559 BUF_APPEND(", %sloc=[%s",
560 PRFIELD(bt_common_field_location_scope_string(field_location
->scope
)));
562 for (i
= 0; i
< bt_field_location_get_item_count(field_location
); i
++) {
564 bt_field_location_get_item_by_index (field_location
, i
);
566 BUF_APPEND(", %s", item
);
570 BUF_APPEND("%s", "]");
573 static inline void format_trace_class(char **buf_ch
, bool extended
,
574 const char *prefix
, const struct bt_trace_class
*trace_class
)
580 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class
->frozen
));
582 if (trace_class
->stream_classes
) {
583 BUF_APPEND(", %sstream-class-count=%u",
584 PRFIELD(trace_class
->stream_classes
->len
));
587 BUF_APPEND(", %sassigns-auto-sc-id=%d",
588 PRFIELD(trace_class
->assigns_automatic_stream_class_id
));
591 static inline void format_trace(char **buf_ch
, bool extended
,
592 const char *prefix
, const struct bt_trace
*trace
)
594 char tmp_prefix
[TMP_PREFIX_LEN
];
597 BUF_APPEND(", %snamespace=\"%s\"", PRFIELD(trace
->ns
));
601 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
));
608 if (trace
->class->mip_version
>= 1) {
609 if (trace
->uid_or_uuid
.uid
) {
610 BUF_APPEND(", %suid=\"%s\"", PRFIELD(trace
->uid_or_uuid
.uid
));
613 if (trace
->uid_or_uuid
.uuid
.value
) {
614 BUF_APPEND_UUID(trace
->uid_or_uuid
.uuid
.value
);
618 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
620 if (trace
->streams
) {
621 BUF_APPEND(", %sstream-count=%u",
622 PRFIELD(trace
->streams
->len
));
629 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace
->class));
630 SET_TMP_PREFIX("trace-class-");
631 format_trace_class(buf_ch
, false, tmp_prefix
, trace
->class);
634 static inline void format_stream_class(char **buf_ch
, bool extended
,
636 const struct bt_stream_class
*stream_class
)
638 const struct bt_trace_class
*trace_class
;
639 char tmp_prefix
[TMP_PREFIX_LEN
];
641 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream_class
->id
));
643 if (stream_class
->ns
) {
644 BUF_APPEND(", %snamespace=\"%s\"", PRFIELD(stream_class
->ns
));
647 if (stream_class
->name
) {
648 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class
->name
));
651 if (stream_class
->uid
) {
652 BUF_APPEND(", %suid=\"%s\"", PRFIELD(stream_class
->uid
));
659 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
661 if (stream_class
->event_classes
) {
662 BUF_APPEND(", %sevent-class-count=%u",
663 PRFIELD(stream_class
->event_classes
->len
));
666 BUF_APPEND(", %spacket-context-fc-addr=%p, "
667 "%sevent-common-context-fc-addr=%p",
668 PRFIELD(stream_class
->packet_context_fc
),
669 PRFIELD(stream_class
->event_common_context_fc
));
670 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
675 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
676 "%ssupports-packets=%d, "
677 "%spackets-have-begin-default-cs=%d, "
678 "%spackets-have-end-default-cs=%d, "
679 "%ssupports-discarded-events=%d, "
680 "%sdiscarded-events-have-default-cs=%d, "
681 "%ssupports-discarded-packets=%d, "
682 "%sdiscarded-packets-have-default-cs=%d",
683 PRFIELD(stream_class
->assigns_automatic_event_class_id
),
684 PRFIELD(stream_class
->assigns_automatic_stream_id
),
685 PRFIELD(stream_class
->supports_packets
),
686 PRFIELD(stream_class
->packets_have_beginning_default_clock_snapshot
),
687 PRFIELD(stream_class
->packets_have_end_default_clock_snapshot
),
688 PRFIELD(stream_class
->supports_discarded_events
),
689 PRFIELD(stream_class
->discarded_events_have_default_clock_snapshots
),
690 PRFIELD(stream_class
->supports_discarded_packets
),
691 PRFIELD(stream_class
->discarded_packets_have_default_clock_snapshots
));
692 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
693 SET_TMP_PREFIX("trace-class-");
694 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
695 SET_TMP_PREFIX("pcf-pool-");
696 format_object_pool(buf_ch
, tmp_prefix
,
697 &stream_class
->packet_context_field_pool
);
700 static inline void format_event_class(char **buf_ch
, bool extended
,
701 const char *prefix
, const struct bt_event_class
*event_class
)
703 const struct bt_stream_class
*stream_class
;
704 const struct bt_trace_class
*trace_class
;
705 char tmp_prefix
[TMP_PREFIX_LEN
];
707 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(event_class
->id
));
709 if (event_class
->ns
) {
710 BUF_APPEND(", %snamespace=\"%s\"", PRFIELD(event_class
->ns
));
713 if (event_class
->name
) {
714 BUF_APPEND(", %sname=\"%s\"", PRFIELD(event_class
->name
));
717 if (event_class
->uid
) {
718 BUF_APPEND(", %suid=\"%s\"", PRFIELD(event_class
->uid
));
725 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class
->frozen
));
727 if (event_class
->log_level
.base
.avail
) {
728 BUF_APPEND(", %slog-level=%s",
729 PRFIELD(bt_common_event_class_log_level_string(
730 (int) event_class
->log_level
.value
)));
733 if (event_class
->emf_uri
) {
734 BUF_APPEND(", %semf-uri=\"%s\"",
735 PRFIELD(event_class
->emf_uri
));
738 BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
739 PRFIELD(event_class
->specific_context_fc
),
740 PRFIELD(event_class
->payload_fc
));
742 stream_class
= bt_event_class_borrow_stream_class_const(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
, stream_class
);
750 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
755 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
756 SET_TMP_PREFIX("trace-class-");
757 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
758 SET_TMP_PREFIX("event-pool-");
759 format_object_pool(buf_ch
, tmp_prefix
, &event_class
->event_pool
);
762 static inline void format_stream(char **buf_ch
, bool extended
,
763 const char *prefix
, const struct bt_stream
*stream
)
765 const struct bt_stream_class
*stream_class
;
766 const struct bt_trace_class
*trace_class
= NULL
;
767 const struct bt_trace
*trace
= NULL
;
768 char tmp_prefix
[TMP_PREFIX_LEN
];
770 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream
->id
));
773 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
));
780 stream_class
= bt_stream_borrow_class_const(stream
);
782 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
783 SET_TMP_PREFIX("stream-class-");
784 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
785 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
789 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
790 SET_TMP_PREFIX("trace-class-");
791 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
794 trace
= bt_stream_borrow_trace_inline(stream
);
796 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
797 SET_TMP_PREFIX("trace-");
798 format_trace(buf_ch
, false, tmp_prefix
, trace
);
801 SET_TMP_PREFIX("packet-pool-");
802 format_object_pool(buf_ch
, tmp_prefix
, &stream
->packet_pool
);
805 static inline void format_packet(char **buf_ch
, bool extended
,
806 const char *prefix
, const struct bt_packet
*packet
)
808 const struct bt_stream
*stream
;
809 const struct bt_trace_class
*trace_class
;
810 char tmp_prefix
[TMP_PREFIX_LEN
];
816 BUF_APPEND(", %sis-frozen=%d, %scontext-field-addr=%p",
817 PRFIELD(packet
->frozen
),
818 PRFIELD(packet
->context_field
? packet
->context_field
->field
: NULL
));
819 stream
= bt_packet_borrow_stream_const(packet
);
824 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
825 SET_TMP_PREFIX("stream-");
826 format_stream(buf_ch
, false, tmp_prefix
, stream
);
827 trace_class
= (const struct bt_trace_class
*) bt_object_borrow_parent(&stream
->base
);
832 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
833 SET_TMP_PREFIX("trace-class-");
834 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
837 static inline void format_event(char **buf_ch
, bool extended
,
838 const char *prefix
, const struct bt_event
*event
)
840 const struct bt_trace_class
*trace_class
;
841 const struct bt_stream_class
*stream_class
;
842 char tmp_prefix
[TMP_PREFIX_LEN
];
848 BUF_APPEND(", %sis-frozen=%d, "
849 "%scommon-context-field-addr=%p, "
850 "%sspecific-context-field-addr=%p, "
851 "%spayload-field-addr=%p, ",
852 PRFIELD(event
->frozen
),
853 PRFIELD(event
->common_context_field
),
854 PRFIELD(event
->specific_context_field
),
855 PRFIELD(event
->payload_field
));
856 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
862 SET_TMP_PREFIX("event-class-");
863 format_event_class(buf_ch
, false, tmp_prefix
, event
->class);
864 stream_class
= bt_event_class_borrow_stream_class(event
->class);
866 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
867 SET_TMP_PREFIX("stream-class-");
868 format_stream_class(buf_ch
, false, tmp_prefix
,
871 trace_class
= bt_stream_class_borrow_trace_class_inline(
874 BUF_APPEND(", %strace-class-addr=%p",
875 PRFIELD(trace_class
));
876 SET_TMP_PREFIX("trace-class-");
877 format_trace_class(buf_ch
, false, tmp_prefix
,
883 BUF_APPEND(", %sstream-addr=%p", PRFIELD(event
->stream
));
884 SET_TMP_PREFIX("stream-");
885 format_stream(buf_ch
, false, tmp_prefix
, event
->stream
);
889 BUF_APPEND(", %spacket-addr=%p", PRFIELD(event
->packet
));
890 SET_TMP_PREFIX("packet-");
891 format_packet(buf_ch
, false, tmp_prefix
, event
->packet
);
895 static inline void format_clock_class(char **buf_ch
, bool extended
,
896 const char *prefix
, const struct bt_clock_class
*clock_class
)
898 char tmp_prefix
[TMP_PREFIX_LEN
];
900 if (clock_class
->ns
) {
901 BUF_APPEND(", %snamepace=\"%s\"", PRFIELD(clock_class
->ns
));
904 if (clock_class
->name
) {
905 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class
->name
));
908 if (clock_class
->uid
) {
909 BUF_APPEND(", %suid=\"%s\"", PRFIELD(clock_class
->uid
));
912 BUF_APPEND(", %sfreq=%" PRIu64
, PRFIELD(clock_class
->frequency
));
918 if (clock_class
->description
) {
919 BUF_APPEND(", %spartial-descr=\"%.32s\"",
920 PRFIELD(clock_class
->description
));
923 if (clock_class
->uuid
.value
) {
924 BUF_APPEND_UUID(clock_class
->uuid
.value
);
927 BUF_APPEND(", %sis-frozen=%d", PRFIELD(clock_class
->frozen
));
929 if (clock_class
->precision
.base
.avail
) {
930 BUF_APPEND(", %sprecision=%" PRIu64
,
931 PRFIELD(clock_class
->precision
.value
));
934 if (clock_class
->accuracy
.base
.avail
) {
935 BUF_APPEND(", %saccuracy=%" PRIu64
,
936 PRFIELD(clock_class
->accuracy
.value
));
939 BUF_APPEND(", %soffset-s=%" PRId64
", "
940 "%soffset-cycles=%" PRIu64
", "
941 "%sorigin-namespace=%s, "
944 "%sbase-offset-ns=%" PRId64
,
945 PRFIELD(clock_class
->offset_seconds
),
946 PRFIELD(clock_class
->offset_cycles
),
947 PRFIELD(clock_class
->origin
.ns
),
948 PRFIELD(clock_class
->origin
.name
),
949 PRFIELD(clock_class
->origin
.uid
),
950 PRFIELD(clock_class
->base_offset
.value_ns
));
952 SET_TMP_PREFIX("cs-pool-");
953 format_object_pool(buf_ch
, tmp_prefix
, &clock_class
->cs_pool
);
956 static inline void format_clock_snapshot(char **buf_ch
, bool extended
,
957 const char *prefix
, const struct bt_clock_snapshot
*clock_snapshot
)
959 char tmp_prefix
[TMP_PREFIX_LEN
];
960 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-origin=%" PRId64
,
961 PRFIELD(clock_snapshot
->value_cycles
),
962 PRFIELD(clock_snapshot
->ns_from_origin
));
968 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_snapshot
->is_set
));
970 if (clock_snapshot
->clock_class
) {
971 BUF_APPEND(", %sclock-class-addr=%p",
972 PRFIELD(clock_snapshot
->clock_class
));
973 SET_TMP_PREFIX("clock-class-");
974 format_clock_class(buf_ch
, false, tmp_prefix
,
975 clock_snapshot
->clock_class
);
979 static inline void format_interrupter(char **buf_ch
, const char *prefix
,
980 const struct bt_interrupter
*intr
)
982 BUF_APPEND(", %sis-set=%d", PRFIELD(intr
->is_set
));
985 static inline void format_value(char **buf_ch
, bool extended
,
986 const char *prefix
, const struct bt_value
*value
)
988 BUF_APPEND(", %stype=%s",
989 PRFIELD(bt_common_value_type_string(bt_value_get_type(value
))));
995 switch (bt_value_get_type(value
)) {
996 case BT_VALUE_TYPE_BOOL
:
998 bt_bool val
= bt_value_bool_get(value
);
1000 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
1003 case BT_VALUE_TYPE_UNSIGNED_INTEGER
:
1005 BUF_APPEND(", %svalue=%" PRIu64
,
1006 PRFIELD(bt_value_integer_unsigned_get(value
)));
1009 case BT_VALUE_TYPE_SIGNED_INTEGER
:
1011 BUF_APPEND(", %svalue=%" PRId64
,
1012 PRFIELD(bt_value_integer_signed_get(value
)));
1015 case BT_VALUE_TYPE_REAL
:
1017 double val
= bt_value_real_get(value
);
1019 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
1022 case BT_VALUE_TYPE_STRING
:
1024 const char *val
= bt_value_string_get(value
);
1026 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
1029 case BT_VALUE_TYPE_ARRAY
:
1031 uint64_t count
= bt_value_array_get_length(value
);
1033 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
1036 case BT_VALUE_TYPE_MAP
:
1038 int64_t count
= bt_value_map_get_size(value
);
1040 BT_ASSERT(count
>= 0);
1041 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
1049 static inline void format_integer_range_set(char **buf_ch
, bool extended
,
1051 const struct bt_integer_range_set
*range_set
)
1053 BUF_APPEND(", %srange-count=%u", PRFIELD(range_set
->ranges
->len
));
1059 BUF_APPEND(", %sis-frozen=%d", PRFIELD(range_set
->frozen
));
1062 static inline void format_message(char **buf_ch
, bool extended
,
1063 const char *prefix
, const struct bt_message
*msg
)
1065 char tmp_prefix
[TMP_PREFIX_LEN
];
1067 BUF_APPEND(", %stype=%s",
1068 PRFIELD(bt_common_message_type_string(msg
->type
)));
1074 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
1075 PRFIELD(msg
->frozen
), PRFIELD(msg
->graph
));
1077 switch (msg
->type
) {
1078 case BT_MESSAGE_TYPE_EVENT
:
1080 const struct bt_message_event
*msg_event
=
1083 if (msg_event
->event
) {
1084 SET_TMP_PREFIX("event-");
1085 format_event(buf_ch
, true, tmp_prefix
,
1089 if (msg_event
->default_cs
) {
1090 SET_TMP_PREFIX("default-cs-");
1091 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1092 msg_event
->default_cs
);
1097 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
1098 case BT_MESSAGE_TYPE_STREAM_END
:
1100 const struct bt_message_stream
*msg_stream
= (const void *) msg
;
1102 if (msg_stream
->stream
) {
1103 SET_TMP_PREFIX("stream-");
1104 format_stream(buf_ch
, true, tmp_prefix
,
1105 msg_stream
->stream
);
1108 BUF_APPEND(", %sdefault-cs-state=%s",
1109 PRFIELD(bt_message_stream_clock_snapshot_state_string(
1110 msg_stream
->default_cs_state
)));
1112 if (msg_stream
->default_cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1113 SET_TMP_PREFIX("default-cs-");
1114 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1115 msg_stream
->default_cs
);
1120 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
1121 case BT_MESSAGE_TYPE_PACKET_END
:
1123 const struct bt_message_packet
*msg_packet
= (const void *) msg
;
1125 if (msg_packet
->packet
) {
1126 SET_TMP_PREFIX("packet-");
1127 format_packet(buf_ch
, true, tmp_prefix
,
1128 msg_packet
->packet
);
1131 if (msg_packet
->default_cs
) {
1132 SET_TMP_PREFIX("default-cs-");
1133 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1134 msg_packet
->default_cs
);
1139 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
1140 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1142 const struct bt_message_discarded_items
*msg_disc_items
=
1145 if (msg_disc_items
->stream
) {
1146 SET_TMP_PREFIX("stream-");
1147 format_stream(buf_ch
, true, tmp_prefix
,
1148 msg_disc_items
->stream
);
1151 if (msg_disc_items
->default_begin_cs
) {
1152 SET_TMP_PREFIX("begin-default-cs-");
1153 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1154 msg_disc_items
->default_begin_cs
);
1157 if (msg_disc_items
->default_end_cs
) {
1158 SET_TMP_PREFIX("end-default-cs-");
1159 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
1160 msg_disc_items
->default_end_cs
);
1163 if (msg_disc_items
->count
.base
.avail
) {
1164 BUF_APPEND(", %scount=%" PRIu64
,
1165 PRFIELD(msg_disc_items
->count
.value
));
1175 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
1177 const struct bt_plugin_so_shared_lib_handle
*handle
)
1179 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
1182 BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle
->path
));
1186 static inline void format_component_class(char **buf_ch
, bool extended
,
1188 const struct bt_component_class
*comp_class
)
1190 char tmp_prefix
[TMP_PREFIX_LEN
];
1192 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1193 PRFIELD(bt_common_component_class_type_string(comp_class
->type
)),
1194 PRFIELD_GSTRING(comp_class
->name
));
1196 if (comp_class
->description
) {
1197 BUF_APPEND(", %spartial-descr=\"%.32s\"",
1198 PRFIELD_GSTRING(comp_class
->description
));
1205 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
1207 if (comp_class
->so_handle
) {
1208 SET_TMP_PREFIX("so-handle-");
1209 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1210 comp_class
->so_handle
);
1214 static inline void format_component(char **buf_ch
, bool extended
,
1215 const char *prefix
, const struct bt_component
*component
)
1217 char tmp_prefix
[TMP_PREFIX_LEN
];
1219 BUF_APPEND(", %sname=\"%s\", %slog-level=%s",
1220 PRFIELD_GSTRING(component
->name
),
1221 PRFIELD(bt_common_logging_level_string(component
->log_level
)));
1223 if (component
->class) {
1224 SET_TMP_PREFIX("class-");
1225 format_component_class(buf_ch
, extended
, tmp_prefix
,
1233 if (component
->input_ports
) {
1234 BUF_APPEND(", %sinput-port-count=%u",
1235 PRFIELD(component
->input_ports
->len
));
1238 if (component
->output_ports
) {
1239 BUF_APPEND(", %soutput-port-count=%u",
1240 PRFIELD(component
->output_ports
->len
));
1244 static inline void format_port(char **buf_ch
, bool extended
,
1245 const char *prefix
, const struct bt_port
*port
)
1247 char tmp_prefix
[TMP_PREFIX_LEN
];
1249 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1250 PRFIELD(bt_port_type_string(port
->type
)),
1251 PRFIELD_GSTRING(port
->name
));
1257 if (port
->connection
) {
1258 SET_TMP_PREFIX("conn-");
1259 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1263 static inline void format_connection(char **buf_ch
, bool extended
,
1264 const char *prefix
, const struct bt_connection
*connection
)
1266 char tmp_prefix
[TMP_PREFIX_LEN
];
1272 if (connection
->upstream_port
) {
1273 SET_TMP_PREFIX("upstream-port-");
1274 format_port(buf_ch
, false, tmp_prefix
,
1275 connection
->upstream_port
);
1278 if (connection
->downstream_port
) {
1279 SET_TMP_PREFIX("downstream-port-");
1280 format_port(buf_ch
, false, tmp_prefix
,
1281 connection
->downstream_port
);
1285 static inline void format_graph(char **buf_ch
, bool extended
,
1286 const char *prefix
, const struct bt_graph
*graph
)
1288 char tmp_prefix
[TMP_PREFIX_LEN
];
1290 BUF_APPEND(", %scan-consume=%d, %sconfig-state=%s",
1291 PRFIELD(graph
->can_consume
),
1292 PRFIELD(bt_graph_configuration_state_string(graph
->config_state
)));
1298 if (graph
->components
) {
1299 BUF_APPEND(", %scomp-count=%u",
1300 PRFIELD(graph
->components
->len
));
1303 if (graph
->connections
) {
1304 BUF_APPEND(", %sconn-count=%u",
1305 PRFIELD(graph
->connections
->len
));
1308 SET_TMP_PREFIX("en-pool-");
1309 format_object_pool(buf_ch
, tmp_prefix
, &graph
->event_msg_pool
);
1310 SET_TMP_PREFIX("pbn-pool-");
1311 format_object_pool(buf_ch
, tmp_prefix
, &graph
->packet_begin_msg_pool
);
1312 SET_TMP_PREFIX("pen-pool-");
1313 format_object_pool(buf_ch
, tmp_prefix
, &graph
->packet_end_msg_pool
);
1316 static inline void format_message_iterator(char **buf_ch
,
1317 bool extended
, const char *prefix
,
1318 const struct bt_message_iterator
*iterator
)
1320 char tmp_prefix
[TMP_PREFIX_LEN
];
1321 const struct bt_message_iterator
*
1322 port_in_iter
= (const void *) iterator
;
1324 if (port_in_iter
->upstream_component
) {
1325 SET_TMP_PREFIX("upstream-comp-");
1326 format_component(buf_ch
, false, tmp_prefix
,
1327 port_in_iter
->upstream_component
);
1334 if (port_in_iter
->upstream_port
) {
1335 SET_TMP_PREFIX("upstream-port-");
1336 format_port(buf_ch
, false, tmp_prefix
,
1337 port_in_iter
->upstream_port
);
1340 if (port_in_iter
->connection
) {
1341 SET_TMP_PREFIX("upstream-conn-");
1342 format_connection(buf_ch
, false, tmp_prefix
,
1343 port_in_iter
->connection
);
1350 static inline void format_plugin(char **buf_ch
, bool extended
,
1351 const char *prefix
, const struct bt_plugin
*plugin
)
1353 char tmp_prefix
[TMP_PREFIX_LEN
];
1355 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1357 if (plugin
->info
.path_set
) {
1358 BUF_APPEND(", %spath=\"%s\"",
1359 PRFIELD_GSTRING(plugin
->info
.path
));
1362 if (plugin
->info
.name_set
) {
1363 BUF_APPEND(", %sname=\"%s\"",
1364 PRFIELD_GSTRING(plugin
->info
.name
));
1371 if (plugin
->info
.author_set
) {
1372 BUF_APPEND(", %sauthor=\"%s\"",
1373 PRFIELD_GSTRING(plugin
->info
.author
));
1376 if (plugin
->info
.license_set
) {
1377 BUF_APPEND(", %slicense=\"%s\"",
1378 PRFIELD_GSTRING(plugin
->info
.license
));
1381 if (plugin
->info
.version_set
) {
1382 BUF_APPEND(", %sversion=%u.%u.%u%s",
1383 PRFIELD(plugin
->info
.version
.major
),
1384 plugin
->info
.version
.minor
,
1385 plugin
->info
.version
.patch
,
1386 plugin
->info
.version
.extra
?
1387 plugin
->info
.version
.extra
->str
: "");
1390 BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, "
1391 "%ssink-comp-class-count=%u",
1392 PRFIELD(plugin
->src_comp_classes
->len
),
1393 PRFIELD(plugin
->flt_comp_classes
->len
),
1394 PRFIELD(plugin
->sink_comp_classes
->len
));
1396 if (plugin
->spec_data
) {
1397 const struct bt_plugin_so_spec_data
*spec_data
=
1398 (const void *) plugin
->spec_data
;
1400 if (spec_data
->shared_lib_handle
) {
1401 SET_TMP_PREFIX("so-handle-");
1402 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1403 spec_data
->shared_lib_handle
);
1408 static inline void format_error_cause(char **buf_ch
, bool extended
,
1409 const char *prefix
, const struct bt_error_cause
*cause
)
1411 const struct bt_error_cause_component_class_id
*comp_class_id
= NULL
;
1413 BUF_APPEND(", %sactor-type=%s, %smodule-name=\"%s\"",
1414 PRFIELD(bt_error_cause_actor_type_string(cause
->actor_type
)),
1415 PRFIELD_GSTRING(cause
->module_name
));
1421 BUF_APPEND(", %spartial-msg=\"%.32s\"",
1422 PRFIELD_GSTRING(cause
->message
));
1424 switch (cause
->actor_type
) {
1425 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT
:
1427 const struct bt_error_cause_component_actor
*spec_cause
=
1428 (const void *) cause
;
1430 BUF_APPEND(", %scomp-name=\"%s\"",
1431 PRFIELD_GSTRING(spec_cause
->comp_name
));
1432 comp_class_id
= &spec_cause
->comp_class_id
;
1435 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS
:
1437 const struct bt_error_cause_component_class_actor
*spec_cause
=
1438 (const void *) cause
;
1440 comp_class_id
= &spec_cause
->comp_class_id
;
1443 case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR
:
1445 const struct bt_error_cause_message_iterator_actor
*spec_cause
=
1446 (const void *) cause
;
1448 BUF_APPEND(", %scomp-name=\"%s\", %scomp-out-port-name=\"%s\"",
1449 PRFIELD_GSTRING(spec_cause
->comp_name
),
1450 PRFIELD_GSTRING(spec_cause
->output_port_name
));
1451 comp_class_id
= &spec_cause
->comp_class_id
;
1458 if (comp_class_id
) {
1459 BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", "
1460 "%splugin-name=\"%s\"",
1461 PRFIELD(bt_common_component_class_type_string(
1462 comp_class_id
->type
)),
1463 PRFIELD_GSTRING(comp_class_id
->name
),
1464 PRFIELD_GSTRING(comp_class_id
->plugin_name
));
1468 static inline void handle_conversion_specifier_bt(
1469 void *priv_data
__attribute__((unused
)),
1471 size_t avail_size
__attribute__((unused
)),
1472 const char **out_fmt_ch
, va_list *args
)
1474 const char *fmt_ch
= *out_fmt_ch
;
1475 bool extended
= false;
1477 char *prefix_ch
= prefix
;
1483 if (*fmt_ch
== 'u') {
1485 obj
= va_arg(*args
, void *);
1486 format_uuid(buf_ch
, obj
);
1490 if (*fmt_ch
== '[') {
1495 if (*fmt_ch
== ']') {
1501 *prefix_ch
= *fmt_ch
;
1509 if (*fmt_ch
== '+') {
1514 obj
= va_arg(*args
, void *);
1515 BUF_APPEND("%saddr=%p", prefix
, obj
);
1523 format_field_class(buf_ch
, extended
, prefix
, obj
);
1526 format_field(buf_ch
, extended
, prefix
, obj
);
1529 format_field_path(buf_ch
, extended
, prefix
, obj
);
1532 format_field_location(buf_ch
, extended
, prefix
, obj
);
1535 format_event_class(buf_ch
, extended
, prefix
, obj
);
1538 format_event(buf_ch
, extended
, prefix
, obj
);
1541 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1544 format_stream(buf_ch
, extended
, prefix
, obj
);
1547 format_packet(buf_ch
, extended
, prefix
, obj
);
1550 format_trace(buf_ch
, extended
, prefix
, obj
);
1553 format_trace_class(buf_ch
, extended
, prefix
, obj
);
1556 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1559 format_clock_snapshot(buf_ch
, extended
, prefix
, obj
);
1562 format_value(buf_ch
, extended
, prefix
, obj
);
1565 format_integer_range_set(buf_ch
, extended
, prefix
, obj
);
1568 format_message(buf_ch
, extended
, prefix
, obj
);
1571 /* Empty, the address is automatically printed. */
1574 format_message_iterator(buf_ch
, extended
, prefix
, obj
);
1577 format_component_class(buf_ch
, extended
, prefix
, obj
);
1580 format_component(buf_ch
, extended
, prefix
, obj
);
1583 format_port(buf_ch
, extended
, prefix
, obj
);
1586 format_connection(buf_ch
, extended
, prefix
, obj
);
1589 format_plugin(buf_ch
, extended
, prefix
, obj
);
1592 format_graph(buf_ch
, extended
, prefix
, obj
);
1595 format_interrupter(buf_ch
, prefix
, obj
);
1598 format_object_pool(buf_ch
, prefix
, obj
);
1601 format_object(buf_ch
, prefix
, obj
);
1604 format_error_cause(buf_ch
, extended
, prefix
, obj
);
1612 *out_fmt_ch
= fmt_ch
;
1616 * This function would normally not be BT_EXPORTed, but it is used by the
1617 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1618 * implemented as a separate shared object, for modularity. It is therefore
1619 * exposed, but not part of the public ABI.
1622 void bt_lib_log_v(const char *file
, const char *func
, unsigned line
,
1623 int lvl
, const char *tag
, const char *fmt
, va_list *args
)
1626 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1627 handle_conversion_specifier_bt
, NULL
, fmt
, args
);
1628 bt_log_write(file
, func
, line
, lvl
, tag
, lib_logging_buf
);
1632 * This function would normally not be BT_EXPORTed, but it is used by the
1633 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1634 * implemented as a separate shared object, for modularity. It is therefore
1635 * exposed, but not part of the public ABI.
1638 void bt_lib_log(const char *file
, const char *func
, unsigned line
,
1639 int lvl
, const char *tag
, const char *fmt
, ...)
1644 va_start(args
, fmt
);
1645 bt_lib_log_v(file
, func
, line
, lvl
, tag
, fmt
, &args
);
1650 * This function would normally not be BT_EXPORTed, but it is used by the
1651 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1652 * implemented as a separate shared object, for modularity. It is therefore
1653 * exposed, but not part of the ABI.
1656 void bt_lib_maybe_log_and_append_cause(const char *func
, const char *file
,
1657 unsigned line
, int lvl
, const char *tag
,
1658 const char *fmt
, ...)
1661 bt_current_thread_error_append_cause_status status
;
1664 va_start(args
, fmt
);
1665 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1666 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1669 /* Log conditionally, but always append the error cause */
1670 if (BT_LOG_ON(lvl
)) {
1671 bt_log_write(file
, func
, line
, lvl
, tag
, lib_logging_buf
);
1674 status
= bt_current_thread_error_append_cause_from_unknown(
1675 BT_LIB_LOG_LIBBABELTRACE2_NAME
, file
, line
, "%s",
1679 * Worst case: this error cause is not appended to the
1680 * current thread's error.
1682 * We can accept this as it's an almost impossible
1683 * scenario and returning an error here would mean you
1684 * need to check the return value of each
1685 * BT_LIB_LOG*_APPEND_CAUSE() macro and that would be
1688 BT_LOGE("Cannot append error cause to current thread's "
1689 "error object: status=%s",
1690 bt_common_func_status_string(status
));