2 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define BT_LOG_TAG "LIB-LOGGING"
33 #include <babeltrace/common-internal.h>
34 #include <babeltrace/lib-logging-internal.h>
35 #include <babeltrace/values-internal.h>
36 #include <babeltrace/values-internal.h>
37 #include <babeltrace/object-pool-internal.h>
38 #include <babeltrace/trace-ir/field-classes-internal.h>
39 #include <babeltrace/trace-ir/fields-internal.h>
40 #include <babeltrace/trace-ir/event-class-internal.h>
41 #include <babeltrace/trace-ir/event-const.h>
42 #include <babeltrace/trace-ir/event-internal.h>
43 #include <babeltrace/trace-ir/packet-const.h>
44 #include <babeltrace/trace-ir/packet-internal.h>
45 #include <babeltrace/trace-ir/stream-class-internal.h>
46 #include <babeltrace/trace-ir/stream-internal.h>
47 #include <babeltrace/trace-ir/stream-const.h>
48 #include <babeltrace/trace-ir/trace-internal.h>
49 #include <babeltrace/trace-ir/trace-class-internal.h>
50 #include <babeltrace/trace-ir/clock-class-internal.h>
51 #include <babeltrace/trace-ir/clock-value-internal.h>
52 #include <babeltrace/trace-ir/field-path-internal.h>
53 #include <babeltrace/trace-ir/utils-internal.h>
54 #include <babeltrace/graph/component-class-internal.h>
55 #include <babeltrace/graph/component-class-sink-colander-internal.h>
56 #include <babeltrace/graph/component-filter-internal.h>
57 #include <babeltrace/graph/component-internal.h>
58 #include <babeltrace/graph/component-sink-internal.h>
59 #include <babeltrace/graph/component-source-internal.h>
60 #include <babeltrace/graph/connection-internal.h>
61 #include <babeltrace/graph/graph-internal.h>
62 #include <babeltrace/graph/notification-event-internal.h>
63 #include <babeltrace/graph/notification-inactivity-internal.h>
64 #include <babeltrace/graph/notification-internal.h>
65 #include <babeltrace/graph/notification-iterator-internal.h>
66 #include <babeltrace/graph/notification-packet-internal.h>
67 #include <babeltrace/graph/notification-stream-internal.h>
68 #include <babeltrace/graph/port-internal.h>
69 #include <babeltrace/plugin/plugin-internal.h>
70 #include <babeltrace/plugin/plugin-so-internal.h>
72 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
74 static char __thread lib_logging_buf
[LIB_LOGGING_BUF_SIZE
];
76 #define BUF_APPEND(_fmt, ...) \
79 size_t _size = LIB_LOGGING_BUF_SIZE - \
80 (size_t) (*buf_ch - lib_logging_buf); \
81 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
82 BT_ASSERT(_count >= 0); \
83 *buf_ch += MIN(_count, _size); \
84 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
89 #define BUF_APPEND_UUID(_uuid) \
91 BUF_APPEND(", %suuid=", prefix); \
92 format_uuid(buf_ch, (_uuid)); \
95 #define PRFIELD(_expr) prefix, (_expr)
97 #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL)
99 #define SET_TMP_PREFIX(_prefix2) \
101 strcpy(tmp_prefix, prefix); \
102 strcat(tmp_prefix, (_prefix2)); \
105 static inline void format_component(char **buf_ch
, bool extended
,
106 const char *prefix
, const struct bt_component
*component
);
108 static inline void format_port(char **buf_ch
, bool extended
,
109 const char *prefix
, const struct bt_port
*port
);
111 static inline void format_connection(char **buf_ch
, bool extended
,
112 const char *prefix
, const struct bt_connection
*connection
);
114 static inline void format_clock_value(char **buf_ch
, bool extended
,
115 const char *prefix
, const struct bt_clock_value
*clock_value
);
117 static inline void format_field_path(char **buf_ch
, bool extended
,
118 const char *prefix
, const struct bt_field_path
*field_path
);
120 static inline void format_object(char **buf_ch
, bool extended
,
121 const char *prefix
, const struct bt_object
*obj
)
123 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
126 static inline void format_uuid(char **buf_ch
, bt_uuid uuid
)
128 BUF_APPEND("\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
129 (unsigned int) uuid
[0],
130 (unsigned int) uuid
[1],
131 (unsigned int) uuid
[2],
132 (unsigned int) uuid
[3],
133 (unsigned int) uuid
[4],
134 (unsigned int) uuid
[5],
135 (unsigned int) uuid
[6],
136 (unsigned int) uuid
[7],
137 (unsigned int) uuid
[8],
138 (unsigned int) uuid
[9],
139 (unsigned int) uuid
[10],
140 (unsigned int) uuid
[11],
141 (unsigned int) uuid
[12],
142 (unsigned int) uuid
[13],
143 (unsigned int) uuid
[14],
144 (unsigned int) uuid
[15]);
147 static inline void format_object_pool(char **buf_ch
, bool extended
,
148 const char *prefix
, const struct bt_object_pool
*pool
)
150 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
153 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
157 static inline void format_integer_field_class(char **buf_ch
,
158 bool extended
, const char *prefix
,
159 const struct bt_field_class
*field_class
)
161 const struct bt_field_class_integer
*int_fc
=
162 (const void *) field_class
;
164 BUF_APPEND(", %srange-size=%" PRIu64
", %sbase=%s",
165 PRFIELD(int_fc
->range
),
166 PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc
->base
)));
169 static inline void format_array_field_class(char **buf_ch
,
170 bool extended
, const char *prefix
,
171 const struct bt_field_class
*field_class
)
173 const struct bt_field_class_array
*array_fc
=
174 (const void *) field_class
;
176 BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s",
177 PRFIELD(array_fc
->element_fc
),
178 PRFIELD(bt_common_field_class_type_string(array_fc
->element_fc
->type
)));
181 static inline void format_field_class(char **buf_ch
, bool extended
,
182 const char *prefix
, const struct bt_field_class
*field_class
)
186 BUF_APPEND(", %stype=%s",
187 PRFIELD(bt_common_field_class_type_string(field_class
->type
)));
190 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class
->frozen
));
191 BUF_APPEND(", %sis-part-of-trace-class=%d",
192 PRFIELD(field_class
->part_of_trace_class
));
197 switch (field_class
->type
) {
198 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
199 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
201 format_integer_field_class(buf_ch
, extended
, prefix
, field_class
);
204 case BT_FIELD_CLASS_TYPE_REAL
:
206 const struct bt_field_class_real
*real_fc
= (void *) field_class
;
208 BUF_APPEND(", %sis-single-precision=%d",
209 PRFIELD(real_fc
->is_single_precision
));
212 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
213 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
215 const struct bt_field_class_enumeration
*enum_fc
=
216 (const void *) field_class
;
218 format_integer_field_class(buf_ch
, extended
, prefix
, field_class
);
219 BUF_APPEND(", %smapping-count=%u",
220 PRFIELD(enum_fc
->mappings
->len
));
223 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
225 const struct bt_field_class_structure
*struct_fc
=
226 (const void *) field_class
;
228 if (struct_fc
->common
.named_fcs
) {
229 BUF_APPEND(", %smember-count=%u",
230 PRFIELD(struct_fc
->common
.named_fcs
->len
));
235 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
237 const struct bt_field_class_static_array
*array_fc
=
238 (const void *) field_class
;
240 format_array_field_class(buf_ch
, extended
, prefix
, field_class
);
241 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_fc
->length
));
244 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
246 const struct bt_field_class_dynamic_array
*array_fc
=
247 (const void *) field_class
;
249 format_array_field_class(buf_ch
, extended
, prefix
, field_class
);
251 if (array_fc
->length_fc
) {
252 SET_TMP_PREFIX("length-fc-");
253 format_field_class(buf_ch
, extended
, tmp_prefix
,
254 array_fc
->length_fc
);
257 if (array_fc
->length_field_path
) {
258 SET_TMP_PREFIX("length-field-path-");
259 format_field_path(buf_ch
, extended
, tmp_prefix
,
260 array_fc
->length_field_path
);
265 case BT_FIELD_CLASS_TYPE_VARIANT
:
267 const struct bt_field_class_variant
*var_fc
=
268 (const void *) field_class
;
270 if (var_fc
->common
.named_fcs
) {
271 BUF_APPEND(", %soption-count=%u",
272 PRFIELD(var_fc
->common
.named_fcs
->len
));
275 if (var_fc
->selector_fc
) {
276 SET_TMP_PREFIX("selector-fc-");
277 format_field_class(buf_ch
, extended
, tmp_prefix
,
278 var_fc
->selector_fc
);
281 if (var_fc
->selector_field_path
) {
282 SET_TMP_PREFIX("selector-field-path-");
283 format_field_path(buf_ch
, extended
, tmp_prefix
,
284 var_fc
->selector_field_path
);
294 static inline void format_field_integer_extended(char **buf_ch
,
295 const char *prefix
, const struct bt_field
*field
)
297 const struct bt_field_integer
*integer
= (void *) field
;
298 const struct bt_field_class_integer
*field_class
=
299 (void *) field
->class;
300 const char *fmt
= NULL
;
302 BT_ASSERT(field_class
);
304 if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
) {
305 fmt
= ", %svalue=%" PRIo64
;
306 } else if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
) {
307 fmt
= ", %svalue=%" PRIx64
;
310 if (field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
311 field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
313 fmt
= ", %svalue=%" PRId64
;
316 BUF_APPEND(fmt
, PRFIELD(integer
->value
.i
));
319 fmt
= ", %svalue=%" PRIu64
;
322 BUF_APPEND(fmt
, PRFIELD(integer
->value
.u
));
326 static inline void format_field(char **buf_ch
, bool extended
,
327 const char *prefix
, const struct bt_field
*field
)
329 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->is_set
));
332 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
335 BUF_APPEND(", %sclass-addr=%p", PRFIELD(field
->class));
341 BUF_APPEND(", %sclass-type=%s",
342 PRFIELD(bt_common_field_class_type_string(field
->class->type
)));
344 if (!extended
|| !field
->is_set
) {
348 switch (field
->class->type
) {
349 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
350 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
351 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
352 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
354 format_field_integer_extended(buf_ch
, prefix
, field
);
357 case BT_FIELD_CLASS_TYPE_REAL
:
359 const struct bt_field_real
*real_field
= (const void *) field
;
361 BUF_APPEND(", %svalue=%f", PRFIELD(real_field
->value
));
364 case BT_FIELD_CLASS_TYPE_STRING
:
366 const struct bt_field_string
*str
= (const void *) field
;
369 BT_ASSERT(str
->buf
->data
);
370 BUF_APPEND(", %spartial-value=\"%.32s\"",
371 PRFIELD(str
->buf
->data
));
376 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
377 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
379 const struct bt_field_array
*array_field
= (const void *) field
;
381 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_field
->length
));
383 if (array_field
->fields
) {
384 BUF_APPEND(", %sallocated-length=%u",
385 PRFIELD(array_field
->fields
->len
));
390 case BT_FIELD_CLASS_TYPE_VARIANT
:
392 const struct bt_field_variant
*var_field
= (const void *) field
;
394 BUF_APPEND(", %sselected-field-index=%" PRIu64
,
395 PRFIELD(var_field
->selected_index
));
403 static inline void format_field_path(char **buf_ch
, bool extended
,
404 const char *prefix
, const struct bt_field_path
*field_path
)
408 if (field_path
->indexes
) {
409 BT_ASSERT(field_path
->indexes
);
410 BUF_APPEND(", %sindex-count=%u",
411 PRFIELD(field_path
->indexes
->len
));
414 if (!extended
|| !field_path
->indexes
) {
418 BUF_APPEND(", %spath=[%s",
419 PRFIELD(bt_common_scope_string(field_path
->root
)));
421 for (i
= 0; i
< field_path
->indexes
->len
; i
++) {
422 uint64_t index
= bt_field_path_get_index_by_index_inline(
425 BUF_APPEND(", %" PRIu64
, index
);
428 BUF_APPEND("%s", "]");
431 static inline void format_trace_class(char **buf_ch
, bool extended
,
432 const char *prefix
, const struct bt_trace_class
*trace_class
)
436 if (trace_class
->name
.value
) {
437 BUF_APPEND(", %sname=\"%s\"",
438 PRFIELD(trace_class
->name
.value
));
445 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class
->frozen
));
447 if (trace_class
->uuid
.value
) {
448 BUF_APPEND_UUID(trace_class
->uuid
.value
);
451 if (trace_class
->stream_classes
) {
452 BUF_APPEND(", %sstream-class-count=%u",
453 PRFIELD(trace_class
->stream_classes
->len
));
456 BUF_APPEND(", %spacket-header-fc-addr=%p, "
457 "%sassigns-auto-sc-id=%d",
458 PRFIELD(trace_class
->packet_header_fc
),
459 PRFIELD(trace_class
->assigns_automatic_stream_class_id
));
460 SET_TMP_PREFIX("phf-pool-");
461 format_object_pool(buf_ch
, extended
, prefix
,
462 &trace_class
->packet_header_field_pool
);
465 static inline void format_trace(char **buf_ch
, bool extended
,
466 const char *prefix
, const struct bt_trace
*trace
)
470 if (trace
->name
.value
) {
471 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
.value
));
478 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
480 if (trace
->streams
) {
481 BUF_APPEND(", %sstream-count=%u",
482 PRFIELD(trace
->streams
->len
));
485 BUF_APPEND(", %sis-static=%d", PRFIELD(trace
->is_static
));
491 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace
->class));
492 SET_TMP_PREFIX("trace-class-");
493 format_trace_class(buf_ch
, false, tmp_prefix
, trace
->class);
496 static inline void format_stream_class(char **buf_ch
, bool extended
,
498 const struct bt_stream_class
*stream_class
)
500 const struct bt_trace_class
*trace_class
;
503 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream_class
->id
));
505 if (stream_class
->name
.value
) {
506 BUF_APPEND(", %sname=\"%s\"",
507 PRFIELD(stream_class
->name
.value
));
514 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
516 if (stream_class
->event_classes
) {
517 BUF_APPEND(", %sevent-class-count=%u",
518 PRFIELD(stream_class
->event_classes
->len
));
521 BUF_APPEND(", %spacket-context-fc-addr=%p, "
522 "%sevent-header-fc-addr=%p, %sevent-common-context-fc-addr=%p",
523 PRFIELD(stream_class
->packet_context_fc
),
524 PRFIELD(stream_class
->event_header_fc
),
525 PRFIELD(stream_class
->event_common_context_fc
));
526 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
531 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
532 "%spackets-have-discarded-ev-counter-snapshot=%d, "
533 "%spackets-have-packet-counter-snapshot=%d, "
534 "%spackets-have-default-begin-cv=%d, "
535 "%spackets-have-default-end-cv=%d",
536 PRFIELD(stream_class
->assigns_automatic_event_class_id
),
537 PRFIELD(stream_class
->assigns_automatic_stream_id
),
538 PRFIELD(stream_class
->packets_have_discarded_event_counter_snapshot
),
539 PRFIELD(stream_class
->packets_have_packet_counter_snapshot
),
540 PRFIELD(stream_class
->packets_have_default_beginning_cv
),
541 PRFIELD(stream_class
->packets_have_default_end_cv
));
542 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
543 SET_TMP_PREFIX("trace-class-");
544 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
545 SET_TMP_PREFIX("ehf-pool-");
546 format_object_pool(buf_ch
, extended
, prefix
,
547 &stream_class
->event_header_field_pool
);
548 SET_TMP_PREFIX("pcf-pool-");
549 format_object_pool(buf_ch
, extended
, prefix
,
550 &stream_class
->packet_context_field_pool
);
553 static inline void format_event_class(char **buf_ch
, bool extended
,
554 const char *prefix
, const struct bt_event_class
*event_class
)
556 const struct bt_stream_class
*stream_class
;
557 const struct bt_trace_class
*trace_class
;
560 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(event_class
->id
));
562 if (event_class
->name
.value
) {
563 BUF_APPEND(", %sname=\"%s\"",
564 PRFIELD(event_class
->name
.value
));
571 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class
->frozen
));
573 if (event_class
->log_level
.base
.avail
) {
574 BUF_APPEND(", %slog-level=%s",
575 PRFIELD(bt_common_event_class_log_level_string(
576 (int) event_class
->log_level
.value
)));
579 if (event_class
->emf_uri
.value
) {
580 BUF_APPEND(", %semf-uri=\"%s\"",
581 PRFIELD(event_class
->emf_uri
.value
));
584 BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
585 PRFIELD(event_class
->specific_context_fc
),
586 PRFIELD(event_class
->payload_fc
));
588 stream_class
= bt_event_class_borrow_stream_class_const(event_class
);
593 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
594 SET_TMP_PREFIX("stream-class-");
595 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
596 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
601 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
602 SET_TMP_PREFIX("trace-class-");
603 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
604 SET_TMP_PREFIX("event-pool-");
605 format_object_pool(buf_ch
, extended
, prefix
, &event_class
->event_pool
);
608 static inline void format_stream(char **buf_ch
, bool extended
,
609 const char *prefix
, const struct bt_stream
*stream
)
611 const struct bt_stream_class
*stream_class
;
612 const struct bt_trace_class
*trace_class
= NULL
;
613 const struct bt_trace
*trace
= NULL
;
616 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream
->id
));
618 if (stream
->name
.value
) {
619 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
.value
));
626 stream_class
= bt_stream_borrow_class_const(stream
);
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
);
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
);
640 trace
= bt_stream_borrow_trace_inline(stream
);
642 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
643 SET_TMP_PREFIX("trace-");
644 format_trace(buf_ch
, false, tmp_prefix
, trace
);
647 SET_TMP_PREFIX("packet-pool-");
648 format_object_pool(buf_ch
, extended
, prefix
, &stream
->packet_pool
);
651 static inline void format_packet(char **buf_ch
, bool extended
,
652 const char *prefix
, const struct bt_packet
*packet
)
654 const struct bt_stream
*stream
;
655 const struct bt_trace_class
*trace_class
;
662 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
663 "%scontext-field-addr=%p",
664 PRFIELD(packet
->frozen
),
665 PRFIELD(packet
->header_field
? packet
->header_field
->field
: NULL
),
666 PRFIELD(packet
->context_field
? packet
->context_field
->field
: NULL
));
667 stream
= bt_packet_borrow_stream_const(packet
);
672 if (packet
->default_beginning_cv
) {
673 SET_TMP_PREFIX("default-begin-cv-");
674 format_clock_value(buf_ch
, true, tmp_prefix
,
675 packet
->default_beginning_cv
);
678 if (packet
->default_end_cv
) {
679 SET_TMP_PREFIX("default-end-cv-");
680 format_clock_value(buf_ch
, true, tmp_prefix
,
681 packet
->default_end_cv
);
684 if (packet
->discarded_event_counter_snapshot
.base
.avail
) {
685 BUF_APPEND(", %sdiscarded-ev-counter-snapshot=%" PRIu64
,
686 PRFIELD(packet
->discarded_event_counter_snapshot
.value
));
689 if (packet
->packet_counter_snapshot
.base
.avail
) {
690 BUF_APPEND(", %spacket-counter-snapshot=%" PRIu64
,
691 PRFIELD(packet
->packet_counter_snapshot
.value
));
694 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
695 SET_TMP_PREFIX("stream-");
696 format_stream(buf_ch
, false, tmp_prefix
, stream
);
697 trace_class
= (const struct bt_trace_class
*) bt_object_borrow_parent(&stream
->base
);
702 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
703 SET_TMP_PREFIX("trace-class-");
704 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
707 static inline void format_event(char **buf_ch
, bool extended
,
708 const char *prefix
, const struct bt_event
*event
)
710 const struct bt_packet
*packet
;
711 const struct bt_stream
*stream
;
712 const struct bt_trace_class
*trace_class
;
713 const struct bt_stream_class
*stream_class
;
720 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
721 "%scommon-context-field-addr=%p, "
722 "%sspecific-context-field-addr=%p, "
723 "%spayload-field-addr=%p, ",
724 PRFIELD(event
->frozen
),
725 PRFIELD(event
->header_field
?
726 event
->header_field
->field
: NULL
),
727 PRFIELD(event
->common_context_field
),
728 PRFIELD(event
->specific_context_field
),
729 PRFIELD(event
->payload_field
));
730 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
736 SET_TMP_PREFIX("event-class-");
737 format_event_class(buf_ch
, false, tmp_prefix
, event
->class);
738 stream_class
= bt_event_class_borrow_stream_class(event
->class);
740 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
741 SET_TMP_PREFIX("stream-class-");
742 format_stream_class(buf_ch
, false, tmp_prefix
,
745 trace_class
= bt_stream_class_borrow_trace_class_inline(
748 BUF_APPEND(", %strace-class-addr=%p",
749 PRFIELD(trace_class
));
750 SET_TMP_PREFIX("trace-class-");
751 format_trace_class(buf_ch
, false, tmp_prefix
,
756 if (event
->default_cv
) {
757 SET_TMP_PREFIX("default-cv-");
758 format_clock_value(buf_ch
, true, tmp_prefix
,
762 packet
= bt_event_borrow_packet_const(event
);
767 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet
));
768 SET_TMP_PREFIX("packet-");
769 format_packet(buf_ch
, false, tmp_prefix
, packet
);
770 stream
= bt_packet_borrow_stream_const(packet
);
775 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
776 SET_TMP_PREFIX("stream-");
777 format_stream(buf_ch
, false, tmp_prefix
, stream
);
780 static inline void format_clock_class(char **buf_ch
, bool extended
,
781 const char *prefix
, const struct bt_clock_class
*clock_class
)
785 if (clock_class
->name
.value
) {
786 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class
->name
.value
));
789 BUF_APPEND(", %sfreq=%" PRIu64
, PRFIELD(clock_class
->frequency
));
795 if (clock_class
->description
.value
) {
796 BUF_APPEND(", %spartial-descr=\"%.32s\"",
797 PRFIELD(clock_class
->description
.value
));
800 if (clock_class
->uuid
.value
) {
801 BUF_APPEND_UUID(clock_class
->uuid
.value
);
804 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
805 "%soffset-s=%" PRId64
", "
806 "%soffset-cycles=%" PRIu64
", %sis-absolute=%d, "
807 "%sbase-offset-ns=%" PRId64
,
808 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
809 PRFIELD(clock_class
->offset_seconds
),
810 PRFIELD(clock_class
->offset_cycles
),
811 PRFIELD(clock_class
->is_absolute
),
812 PRFIELD(clock_class
->base_offset
.value_ns
));
814 SET_TMP_PREFIX("cv-pool-");
815 format_object_pool(buf_ch
, extended
, prefix
, &clock_class
->cv_pool
);
818 static inline void format_clock_value(char **buf_ch
, bool extended
,
819 const char *prefix
, const struct bt_clock_value
*clock_value
)
822 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-origin=%" PRId64
,
823 PRFIELD(clock_value
->value_cycles
),
824 PRFIELD(clock_value
->ns_from_origin
));
830 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_value
->is_set
));
832 if (clock_value
->clock_class
) {
833 BUF_APPEND(", %sclock-class-addr=%p",
834 PRFIELD(clock_value
->clock_class
));
835 SET_TMP_PREFIX("clock-class-");
836 format_clock_class(buf_ch
, false, tmp_prefix
,
837 clock_value
->clock_class
);
841 static inline void format_value(char **buf_ch
, bool extended
,
842 const char *prefix
, const struct bt_value
*value
)
844 BUF_APPEND(", %stype=%s",
845 PRFIELD(bt_common_value_type_string(bt_value_get_type(value
))));
851 switch (bt_value_get_type(value
)) {
852 case BT_VALUE_TYPE_BOOL
:
854 bt_bool val
= bt_value_bool_get(value
);
856 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
859 case BT_VALUE_TYPE_INTEGER
:
861 int64_t val
= bt_value_integer_get(value
);
863 BUF_APPEND(", %svalue=%" PRId64
, PRFIELD(val
));
866 case BT_VALUE_TYPE_REAL
:
868 double val
= bt_value_real_get(value
);
870 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
873 case BT_VALUE_TYPE_STRING
:
875 const char *val
= bt_value_string_get(value
);
877 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
880 case BT_VALUE_TYPE_ARRAY
:
882 int64_t count
= bt_value_array_get_size(value
);
884 BT_ASSERT(count
>= 0);
885 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
888 case BT_VALUE_TYPE_MAP
:
890 int64_t count
= bt_value_map_get_size(value
);
892 BT_ASSERT(count
>= 0);
893 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
901 static inline void format_notification(char **buf_ch
, bool extended
,
902 const char *prefix
, const struct bt_notification
*notif
)
906 BUF_APPEND(", %stype=%s",
907 PRFIELD(bt_notification_type_string(notif
->type
)));
913 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
914 PRFIELD(notif
->frozen
), PRFIELD(notif
->graph
));
916 switch (notif
->type
) {
917 case BT_NOTIFICATION_TYPE_EVENT
:
919 const struct bt_notification_event
*notif_event
=
920 (const void *) notif
;
922 if (notif_event
->event
) {
923 SET_TMP_PREFIX("event-");
924 format_event(buf_ch
, true, tmp_prefix
, notif_event
->event
);
929 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
931 const struct bt_notification_stream_begin
*notif_stream
=
932 (const void *) notif
;
934 if (notif_stream
->stream
) {
935 SET_TMP_PREFIX("stream-");
936 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
941 case BT_NOTIFICATION_TYPE_STREAM_END
:
943 const struct bt_notification_stream_end
*notif_stream
=
944 (const void *) notif
;
946 if (notif_stream
->stream
) {
947 SET_TMP_PREFIX("stream-");
948 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
953 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
955 const struct bt_notification_packet_begin
*notif_packet
=
956 (const void *) notif
;
958 if (notif_packet
->packet
) {
959 SET_TMP_PREFIX("packet-");
960 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
965 case BT_NOTIFICATION_TYPE_PACKET_END
:
967 const struct bt_notification_packet_end
*notif_packet
=
968 (const void *) notif
;
970 if (notif_packet
->packet
) {
971 SET_TMP_PREFIX("packet-");
972 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
982 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
984 const struct bt_plugin_so_shared_lib_handle
*handle
)
986 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
989 BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle
->path
));
993 static inline void format_component_class(char **buf_ch
, bool extended
,
995 const struct bt_component_class
*comp_class
)
999 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1000 PRFIELD(bt_component_class_type_string(comp_class
->type
)),
1001 PRFIELD_GSTRING(comp_class
->name
));
1003 if (comp_class
->description
) {
1004 BUF_APPEND(", %spartial-descr=\"%.32s\"",
1005 PRFIELD_GSTRING(comp_class
->description
));
1012 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
1014 if (comp_class
->so_handle
) {
1015 SET_TMP_PREFIX("so-handle-");
1016 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1017 comp_class
->so_handle
);
1021 static inline void format_component(char **buf_ch
, bool extended
,
1022 const char *prefix
, const struct bt_component
*component
)
1024 char tmp_prefix
[64];
1026 BUF_APPEND(", %sname=\"%s\"",
1027 PRFIELD_GSTRING(component
->name
));
1029 if (component
->class) {
1030 SET_TMP_PREFIX("class-");
1031 format_component_class(buf_ch
, extended
, tmp_prefix
,
1039 if (component
->input_ports
) {
1040 BUF_APPEND(", %sinput-port-count=%u",
1041 PRFIELD(component
->input_ports
->len
));
1044 if (component
->output_ports
) {
1045 BUF_APPEND(", %soutput-port-count=%u",
1046 PRFIELD(component
->output_ports
->len
));
1050 static inline void format_port(char **buf_ch
, bool extended
,
1051 const char *prefix
, const struct bt_port
*port
)
1053 char tmp_prefix
[64];
1055 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1056 PRFIELD(bt_port_type_string(port
->type
)),
1057 PRFIELD_GSTRING(port
->name
));
1063 if (port
->connection
) {
1064 SET_TMP_PREFIX("conn-");
1065 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1069 static inline void format_connection(char **buf_ch
, bool extended
,
1070 const char *prefix
, const struct bt_connection
*connection
)
1072 char tmp_prefix
[64];
1078 if (connection
->upstream_port
) {
1079 SET_TMP_PREFIX("upstream-port-");
1080 format_port(buf_ch
, false, tmp_prefix
,
1081 connection
->upstream_port
);
1084 if (connection
->downstream_port
) {
1085 SET_TMP_PREFIX("downstream-port-");
1086 format_port(buf_ch
, false, tmp_prefix
,
1087 connection
->downstream_port
);
1091 static inline void format_graph(char **buf_ch
, bool extended
,
1092 const char *prefix
, const struct bt_graph
*graph
)
1094 char tmp_prefix
[64];
1096 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph
->canceled
));
1102 if (graph
->components
) {
1103 BUF_APPEND(", %scomp-count=%u",
1104 PRFIELD(graph
->components
->len
));
1107 if (graph
->connections
) {
1108 BUF_APPEND(", %sconn-count=%u",
1109 PRFIELD(graph
->connections
->len
));
1112 SET_TMP_PREFIX("en-pool-");
1113 format_object_pool(buf_ch
, extended
, prefix
,
1114 &graph
->event_notif_pool
);
1115 SET_TMP_PREFIX("pbn-pool-");
1116 format_object_pool(buf_ch
, extended
, prefix
,
1117 &graph
->packet_begin_notif_pool
);
1118 SET_TMP_PREFIX("pen-pool-");
1119 format_object_pool(buf_ch
, extended
, prefix
,
1120 &graph
->packet_end_notif_pool
);
1123 static inline void format_notification_iterator(char **buf_ch
,
1124 bool extended
, const char *prefix
,
1125 const struct bt_notification_iterator
*iterator
)
1128 char tmp_prefix
[64];
1130 if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
) {
1131 type
= "BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT";
1132 } else if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT
) {
1133 type
= "BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT";
1138 BUF_APPEND(", %stype=%s", PRFIELD(type
));
1140 switch (iterator
->type
) {
1141 case BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
:
1143 const struct bt_self_component_port_input_notification_iterator
*
1144 port_in_iter
= (const void *) iterator
;
1146 if (port_in_iter
->upstream_component
) {
1147 SET_TMP_PREFIX("upstream-comp-");
1148 format_component(buf_ch
, false, tmp_prefix
,
1149 port_in_iter
->upstream_component
);
1152 if (port_in_iter
->upstream_port
) {
1153 SET_TMP_PREFIX("upstream-port-");
1154 format_port(buf_ch
, false, tmp_prefix
,
1155 port_in_iter
->upstream_port
);
1158 if (port_in_iter
->connection
) {
1159 SET_TMP_PREFIX("upstream-conn-");
1160 format_connection(buf_ch
, false, tmp_prefix
,
1161 port_in_iter
->connection
);
1165 case BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT
:
1167 const struct bt_port_output_notification_iterator
*port_out_iter
=
1168 (const void *) iterator
;
1170 if (port_out_iter
->graph
) {
1171 SET_TMP_PREFIX("graph-");
1172 format_graph(buf_ch
, false, tmp_prefix
,
1173 port_out_iter
->graph
);
1176 if (port_out_iter
->colander
) {
1177 SET_TMP_PREFIX("colander-comp-");
1178 format_component(buf_ch
, false, tmp_prefix
,
1179 (void *) port_out_iter
->colander
);
1189 static inline void format_plugin(char **buf_ch
, bool extended
,
1190 const char *prefix
, const struct bt_plugin
*plugin
)
1192 char tmp_prefix
[64];
1194 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1196 if (plugin
->info
.path_set
) {
1197 BUF_APPEND(", %spath=\"%s\"",
1198 PRFIELD_GSTRING(plugin
->info
.path
));
1201 if (plugin
->info
.name_set
) {
1202 BUF_APPEND(", %sname=\"%s\"",
1203 PRFIELD_GSTRING(plugin
->info
.name
));
1210 if (plugin
->info
.author_set
) {
1211 BUF_APPEND(", %sauthor=\"%s\"",
1212 PRFIELD_GSTRING(plugin
->info
.author
));
1215 if (plugin
->info
.license_set
) {
1216 BUF_APPEND(", %slicense=\"%s\"",
1217 PRFIELD_GSTRING(plugin
->info
.license
));
1220 if (plugin
->info
.version_set
) {
1221 BUF_APPEND(", %sversion=%u.%u.%u%s",
1222 PRFIELD(plugin
->info
.version
.major
),
1223 plugin
->info
.version
.minor
,
1224 plugin
->info
.version
.patch
,
1225 plugin
->info
.version
.extra
?
1226 plugin
->info
.version
.extra
->str
: "");
1229 BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, "
1230 "%ssink-comp-class-count=%u",
1231 PRFIELD(plugin
->src_comp_classes
->len
),
1232 PRFIELD(plugin
->flt_comp_classes
->len
),
1233 PRFIELD(plugin
->sink_comp_classes
->len
));
1235 if (plugin
->spec_data
) {
1236 const struct bt_plugin_so_spec_data
*spec_data
=
1237 (const void *) plugin
->spec_data
;
1239 if (spec_data
->shared_lib_handle
) {
1240 SET_TMP_PREFIX("so-handle-");
1241 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1242 spec_data
->shared_lib_handle
);
1247 static inline void handle_conversion_specifier_bt(void *priv_data
,
1248 char **buf_ch
, size_t avail_size
,
1249 const char **out_fmt_ch
, va_list *args
)
1251 const char *fmt_ch
= *out_fmt_ch
;
1252 bool extended
= false;
1254 char *prefix_ch
= prefix
;
1260 if (*fmt_ch
== 'u') {
1262 obj
= va_arg(*args
, void *);
1263 format_uuid(buf_ch
, obj
);
1267 if (*fmt_ch
== '[') {
1272 if (*fmt_ch
== ']') {
1278 *prefix_ch
= *fmt_ch
;
1286 if (*fmt_ch
== '+') {
1291 obj
= va_arg(*args
, void *);
1292 BUF_APPEND("%saddr=%p", prefix
, obj
);
1300 format_field_class(buf_ch
, extended
, prefix
, obj
);
1303 format_field(buf_ch
, extended
, prefix
, obj
);
1306 format_field_path(buf_ch
, extended
, prefix
, obj
);
1309 format_event_class(buf_ch
, extended
, prefix
, obj
);
1312 format_event(buf_ch
, extended
, prefix
, obj
);
1315 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1318 format_stream(buf_ch
, extended
, prefix
, obj
);
1321 format_packet(buf_ch
, extended
, prefix
, obj
);
1324 format_trace(buf_ch
, extended
, prefix
, obj
);
1327 format_trace_class(buf_ch
, extended
, prefix
, obj
);
1330 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1333 format_clock_value(buf_ch
, extended
, prefix
, obj
);
1336 format_value(buf_ch
, extended
, prefix
, obj
);
1339 format_notification(buf_ch
, extended
, prefix
, obj
);
1342 format_notification_iterator(buf_ch
, extended
, prefix
, obj
);
1345 format_component_class(buf_ch
, extended
, prefix
, obj
);
1348 format_component(buf_ch
, extended
, prefix
, obj
);
1351 format_port(buf_ch
, extended
, prefix
, obj
);
1354 format_connection(buf_ch
, extended
, prefix
, obj
);
1357 format_plugin(buf_ch
, extended
, prefix
, obj
);
1360 format_graph(buf_ch
, extended
, prefix
, obj
);
1363 format_object_pool(buf_ch
, extended
, prefix
, obj
);
1366 format_object(buf_ch
, extended
, prefix
, obj
);
1374 *out_fmt_ch
= fmt_ch
;
1378 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1379 int lvl
, const char *tag
, const char *fmt
, ...)
1384 va_start(args
, fmt
);
1385 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1386 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1388 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);