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/object-pool-internal.h>
37 #include <babeltrace/ctf-ir/field-types-internal.h>
38 #include <babeltrace/ctf-ir/fields-internal.h>
39 #include <babeltrace/ctf-ir/event-class-internal.h>
40 #include <babeltrace/ctf-ir/event-internal.h>
41 #include <babeltrace/ctf-ir/packet-internal.h>
42 #include <babeltrace/ctf-ir/stream-class-internal.h>
43 #include <babeltrace/ctf-ir/stream-internal.h>
44 #include <babeltrace/ctf-ir/trace-internal.h>
45 #include <babeltrace/ctf-ir/clock-class-internal.h>
46 #include <babeltrace/ctf-ir/clock-value-internal.h>
47 #include <babeltrace/ctf-ir/field-path-internal.h>
48 #include <babeltrace/ctf-ir/utils-internal.h>
49 #include <babeltrace/graph/component-class-internal.h>
50 #include <babeltrace/graph/component-class-sink-colander-internal.h>
51 #include <babeltrace/graph/component-filter-internal.h>
52 #include <babeltrace/graph/component-internal.h>
53 #include <babeltrace/graph/component-sink-internal.h>
54 #include <babeltrace/graph/component-source-internal.h>
55 #include <babeltrace/graph/connection-internal.h>
56 #include <babeltrace/graph/graph-internal.h>
57 #include <babeltrace/graph/notification-event-internal.h>
58 #include <babeltrace/graph/notification-inactivity-internal.h>
59 #include <babeltrace/graph/notification-internal.h>
60 #include <babeltrace/graph/notification-iterator-internal.h>
61 #include <babeltrace/graph/notification-packet-internal.h>
62 #include <babeltrace/graph/notification-stream-internal.h>
63 #include <babeltrace/graph/port-internal.h>
64 #include <babeltrace/plugin/plugin-internal.h>
65 #include <babeltrace/plugin/plugin-so-internal.h>
67 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
69 static char __thread lib_logging_buf
[LIB_LOGGING_BUF_SIZE
];
71 #define BUF_APPEND(_fmt, ...) \
74 size_t _size = LIB_LOGGING_BUF_SIZE - \
75 (size_t) (*buf_ch - lib_logging_buf); \
76 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
77 BT_ASSERT(_count >= 0); \
78 *buf_ch += MIN(_count, _size); \
79 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
84 #define BUF_APPEND_UUID(_uuid) \
85 BUF_APPEND(", %suuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"", \
87 (unsigned int) (_uuid)[0], \
88 (unsigned int) (_uuid)[1], \
89 (unsigned int) (_uuid)[2], \
90 (unsigned int) (_uuid)[3], \
91 (unsigned int) (_uuid)[4], \
92 (unsigned int) (_uuid)[5], \
93 (unsigned int) (_uuid)[6], \
94 (unsigned int) (_uuid)[7], \
95 (unsigned int) (_uuid)[8], \
96 (unsigned int) (_uuid)[9], \
97 (unsigned int) (_uuid)[10], \
98 (unsigned int) (_uuid)[11], \
99 (unsigned int) (_uuid)[12], \
100 (unsigned int) (_uuid)[13], \
101 (unsigned int) (_uuid)[14], \
102 (unsigned int) (_uuid)[15])
104 #define PRFIELD(_expr) prefix, (_expr)
106 #define SET_TMP_PREFIX(_prefix2) \
108 strcpy(tmp_prefix, prefix); \
109 strcat(tmp_prefix, (_prefix2)); \
112 static inline void format_component(char **buf_ch
, bool extended
,
113 const char *prefix
, struct bt_component
*component
);
115 static inline void format_port(char **buf_ch
, bool extended
,
116 const char *prefix
, struct bt_port
*port
);
118 static inline void format_connection(char **buf_ch
, bool extended
,
119 const char *prefix
, struct bt_connection
*connection
);
121 static inline void format_clock_value(char **buf_ch
, bool extended
,
122 const char *prefix
, struct bt_clock_value
*clock_value
);
124 static inline void format_object(char **buf_ch
, bool extended
,
125 const char *prefix
, struct bt_object
*obj
)
127 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
130 static inline void format_clock_value_set(char **buf_ch
, bool extended
,
131 const char *prefix
, struct bt_clock_value_set
*cv_set
)
135 if (!cv_set
->clock_values
) {
139 BUF_APPEND(", %ssize=%u", PRFIELD(cv_set
->clock_values
->len
));
141 if (cv_set
->default_cv
) {
142 SET_TMP_PREFIX("default-cv-");
143 format_clock_value(buf_ch
, extended
, tmp_prefix
,
148 static inline void format_object_pool(char **buf_ch
, bool extended
,
149 const char *prefix
, struct bt_object_pool
*pool
)
151 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
154 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
158 static inline void format_field_type(char **buf_ch
, bool extended
,
159 const char *prefix
, struct bt_field_type
*field_type
)
161 BUF_APPEND(", %stype-id=%s, %salignment=%u",
162 PRFIELD(bt_common_field_type_id_string(field_type
->id
)),
163 PRFIELD(field_type
->alignment
));
166 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_type
->frozen
));
171 if (field_type
->id
== BT_FIELD_TYPE_ID_UNKNOWN
) {
175 switch (field_type
->id
) {
176 case BT_FIELD_TYPE_ID_INTEGER
:
178 struct bt_field_type_integer
*integer
= (void *) field_type
;
180 BUF_APPEND(", %ssize=%u, %sis-signed=%d, %sbyte-order=%s, "
181 "%sbase=%d, %sencoding=%s, "
182 "%smapped-clock-class-addr=%p",
183 PRFIELD(integer
->size
), PRFIELD(integer
->is_signed
),
184 PRFIELD(bt_common_byte_order_string(
185 integer
->user_byte_order
)),
186 PRFIELD(integer
->base
),
187 PRFIELD(bt_common_string_encoding_string(
189 PRFIELD(integer
->mapped_clock_class
));
191 if (integer
->mapped_clock_class
) {
192 BUF_APPEND(", %smapped-clock-class-name=\"%s\"",
193 PRFIELD(bt_clock_class_get_name(
194 integer
->mapped_clock_class
)));
198 case BT_FIELD_TYPE_ID_FLOAT
:
200 struct bt_field_type_floating_point
*flt
= (void *) field_type
;
202 BUF_APPEND(", %sexp-dig=%u, %smant-dig=%u, %sbyte-order=%s",
203 PRFIELD(flt
->exp_dig
), PRFIELD(flt
->mant_dig
),
204 PRFIELD(bt_common_byte_order_string(
205 flt
->user_byte_order
)));
208 case BT_FIELD_TYPE_ID_ENUM
:
210 struct bt_field_type_enumeration
*enm
= (void *) field_type
;
212 BUF_APPEND(", %smapping-count=%u",
213 PRFIELD(enm
->entries
->len
));
216 case BT_FIELD_TYPE_ID_STRING
:
218 struct bt_field_type_string
*str
= (void *) field_type
;
220 BUF_APPEND(", %sencoding=%s",
221 PRFIELD(bt_common_string_encoding_string(
225 case BT_FIELD_TYPE_ID_STRUCT
:
227 struct bt_field_type_structure
*structure
= (void *) field_type
;
229 BUF_APPEND(", %sfield-count=%u",
230 PRFIELD(structure
->fields
->len
));
233 case BT_FIELD_TYPE_ID_SEQUENCE
:
235 struct bt_field_type_sequence
*seq
= (void *) field_type
;
237 BUF_APPEND(", %slength-ft-addr=\"%s\", %selem-ft-addr=%p",
238 PRFIELD(seq
->length_field_name
->str
),
239 PRFIELD(seq
->element_ft
));
242 case BT_FIELD_TYPE_ID_VARIANT
:
244 struct bt_field_type_variant
*variant
= (void *) field_type
;
246 BUF_APPEND(", %stag-name=\"%s\", %sfield-count=%u",
247 PRFIELD(variant
->tag_name
->str
),
248 PRFIELD(variant
->choices
->len
));
256 static inline void format_field_integer_extended(char **buf_ch
,
257 const char *prefix
, struct bt_field
*field
)
259 struct bt_field_integer
*integer
= (void *) field
;
260 struct bt_field_type_integer
*field_type
= (void *) field
->type
;
261 const char *fmt
= NULL
;
263 BT_ASSERT(field_type
);
265 if (field_type
->base
== 8) {
266 fmt
= ", %svalue=%" PRIo64
;
267 } else if (field_type
->base
== 16) {
268 fmt
= ", %svalue=%" PRIx64
;
271 if (field_type
->is_signed
) {
273 fmt
= ", %svalue=%" PRId64
;
276 BUF_APPEND(fmt
, PRFIELD(integer
->payload
.signd
));
279 fmt
= ", %svalue=%" PRIu64
;
282 BUF_APPEND(fmt
, PRFIELD(integer
->payload
.unsignd
));
286 static inline void format_field(char **buf_ch
, bool extended
,
287 const char *prefix
, struct bt_field
*field
)
289 struct bt_field
*common_field
= (void *) field
;
291 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->payload_set
));
294 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
297 BUF_APPEND(", %stype-addr=%p", PRFIELD(field
->type
));
303 BUF_APPEND(", %stype-id=%s",
304 PRFIELD(bt_common_field_type_id_string(field
->type
->id
)));
306 if (!extended
|| field
->type
->id
== BT_FIELD_TYPE_ID_UNKNOWN
||
307 !field
->payload_set
) {
311 switch (field
->type
->id
) {
312 case BT_FIELD_TYPE_ID_INTEGER
:
314 format_field_integer_extended(buf_ch
, prefix
, field
);
317 case BT_FIELD_TYPE_ID_FLOAT
:
319 struct bt_field_floating_point
*flt
= (void *) field
;
321 BUF_APPEND(", %svalue=%f", PRFIELD(flt
->payload
));
324 case BT_FIELD_TYPE_ID_STRING
:
326 struct bt_field_string
*str
= (void *) field
;
329 BT_ASSERT(str
->buf
->data
);
330 BUF_APPEND(", %spartial-value=\"%.32s\"",
331 PRFIELD(str
->buf
->data
));
336 case BT_FIELD_TYPE_ID_SEQUENCE
:
338 struct bt_field_sequence
*seq
= (void *) field
;
340 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(seq
->length
));
343 BUF_APPEND(", %sallocated-length=%u",
344 PRFIELD(seq
->elements
->len
));
348 case BT_FIELD_TYPE_ID_VARIANT
:
350 struct bt_field_variant
*variant
= (void *) field
;
352 BUF_APPEND(", %scur-field-addr=%p",
353 PRFIELD(variant
->current_field
));
360 if (!common_field
->type
) {
364 switch (common_field
->type
->id
) {
365 case BT_FIELD_TYPE_ID_ENUM
:
367 struct bt_field_integer
*integer
= (void *) field
;
368 struct bt_field_type_enumeration
*enum_ft
=
369 (void *) common_field
->type
;
371 if (enum_ft
->container_ft
) {
372 if (enum_ft
->container_ft
->is_signed
) {
373 BUF_APPEND(", %svalue=%" PRId64
,
374 PRFIELD(integer
->payload
.signd
));
376 BUF_APPEND(", %svalue=%" PRIu64
,
377 PRFIELD(integer
->payload
.unsignd
));
387 static inline void format_field_path(char **buf_ch
, bool extended
,
388 const char *prefix
, struct bt_field_path
*field_path
)
392 if (field_path
->indexes
) {
393 BT_ASSERT(field_path
->indexes
);
394 BUF_APPEND(", %sindex-count=%u",
395 PRFIELD(field_path
->indexes
->len
));
398 if (!extended
|| !field_path
->indexes
) {
402 BUF_APPEND(", %spath=[%s",
403 PRFIELD(bt_common_scope_string(field_path
->root
)));
405 for (i
= 0; i
< field_path
->indexes
->len
; i
++) {
406 int index
= g_array_index(field_path
->indexes
, int, i
);
408 BUF_APPEND(", %d", index
);
411 BUF_APPEND("%s", "]");
414 static inline void format_trace(char **buf_ch
, bool extended
,
415 const char *prefix
, struct bt_trace
*trace
)
420 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
->str
));
427 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
429 if (trace
->uuid_set
) {
430 BUF_APPEND_UUID(trace
->uuid
);
433 if (trace
->clock_classes
) {
434 BUF_APPEND(", %sclock-class-count=%u",
435 PRFIELD(trace
->clock_classes
->len
));
438 if (trace
->stream_classes
) {
439 BUF_APPEND(", %sstream-class-count=%u",
440 PRFIELD(trace
->stream_classes
->len
));
443 if (trace
->streams
) {
444 BUF_APPEND(", %sstream-count=%u",
445 PRFIELD(trace
->streams
->len
));
448 BUF_APPEND(", %spacket-header-ft-addr=%p",
449 PRFIELD(trace
->packet_header_field_type
));
450 BUF_APPEND(", %sis-static=%d", PRFIELD(trace
->is_static
));
451 SET_TMP_PREFIX("phf-pool-");
452 format_object_pool(buf_ch
, extended
, prefix
,
453 &trace
->packet_header_field_pool
);
456 static inline void format_stream_class(char **buf_ch
, bool extended
,
457 const char *prefix
, struct bt_stream_class
*stream_class
)
459 struct bt_trace
*trace
;
462 if (stream_class
->id_set
) {
463 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(stream_class
->id
));
466 if (stream_class
->name
) {
467 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class
->name
->str
));
474 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
476 if (stream_class
->event_classes
) {
477 BUF_APPEND(", %sevent-class-count=%u",
478 PRFIELD(stream_class
->event_classes
->len
));
481 BUF_APPEND(", %spacket-context-ft-addr=%p, "
482 "%sevent-header-ft-addr=%p, %sevent-context-ft-addr=%p",
483 PRFIELD(stream_class
->packet_context_field_type
),
484 PRFIELD(stream_class
->event_header_field_type
),
485 PRFIELD(stream_class
->event_context_field_type
));
486 trace
= bt_stream_class_borrow_trace(stream_class
);
491 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
492 SET_TMP_PREFIX("trace-");
493 format_trace(buf_ch
, false, tmp_prefix
, trace
);
494 SET_TMP_PREFIX("ehf-pool-");
495 format_object_pool(buf_ch
, extended
, prefix
,
496 &stream_class
->event_header_field_pool
);
497 SET_TMP_PREFIX("pcf-pool-");
498 format_object_pool(buf_ch
, extended
, prefix
,
499 &stream_class
->packet_context_field_pool
);
502 static inline void format_event_class(char **buf_ch
, bool extended
,
503 const char *prefix
, struct bt_event_class
*event_class
)
505 struct bt_stream_class
*stream_class
;
506 struct bt_trace
*trace
;
509 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(event_class
->id
));
511 if (event_class
->name
) {
512 BUF_APPEND(", %sname=\"%s\"",
513 PRFIELD(event_class
->name
->str
));
520 BUF_APPEND(", %sis-frozen=%d, %slog-level=%s",
521 PRFIELD(event_class
->frozen
),
522 PRFIELD(bt_common_event_class_log_level_string(
523 event_class
->log_level
)));
525 if (event_class
->emf_uri
) {
526 BUF_APPEND(", %semf-uri=\"%s\"",
527 PRFIELD(event_class
->emf_uri
->str
));
530 BUF_APPEND(", %scontext-ft-addr=%p, %spayload-ft-addr=%p",
531 PRFIELD(event_class
->context_field_type
),
532 PRFIELD(event_class
->payload_field_type
));
534 stream_class
= bt_event_class_borrow_stream_class(event_class
);
539 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
540 SET_TMP_PREFIX("stream-class-");
541 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
542 trace
= bt_stream_class_borrow_trace(stream_class
);
547 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
548 SET_TMP_PREFIX("trace-");
549 format_trace(buf_ch
, false, tmp_prefix
, trace
);
550 SET_TMP_PREFIX("event-pool-");
551 format_object_pool(buf_ch
, extended
, prefix
, &event_class
->event_pool
);
554 static inline void format_stream(char **buf_ch
, bool extended
,
555 const char *prefix
, struct bt_stream
*stream
)
557 struct bt_stream_class
*stream_class
;
558 struct bt_trace
*trace
;
561 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(stream
->id
));
564 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
->str
));
571 stream_class
= bt_stream_borrow_class(stream
);
576 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
577 SET_TMP_PREFIX("stream-class-");
578 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
579 trace
= bt_stream_class_borrow_trace(stream_class
);
584 trace
= (void *) bt_object_borrow_parent(&stream
->base
);
589 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
590 SET_TMP_PREFIX("trace-");
591 format_trace(buf_ch
, false, tmp_prefix
, trace
);
592 SET_TMP_PREFIX("packet-pool-");
593 format_object_pool(buf_ch
, extended
, prefix
, &stream
->packet_pool
);
596 static inline void format_packet(char **buf_ch
, bool extended
,
597 const char *prefix
, struct bt_packet
*packet
)
599 struct bt_stream
*stream
;
600 struct bt_trace
*trace
;
607 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
608 "%scontext-field-addr=%p",
609 PRFIELD(packet
->frozen
),
610 PRFIELD(packet
->header
? packet
->header
->field
: NULL
),
611 PRFIELD(packet
->context
));
612 stream
= bt_packet_borrow_stream(packet
);
617 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
618 SET_TMP_PREFIX("stream-");
619 format_stream(buf_ch
, false, tmp_prefix
, stream
);
620 trace
= (struct bt_trace
*)
621 bt_object_borrow_parent(&stream
->base
);
626 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
627 SET_TMP_PREFIX("trace-");
628 format_trace(buf_ch
, false, tmp_prefix
, trace
);
631 static inline void format_event(char **buf_ch
, bool extended
,
632 const char *prefix
, struct bt_event
*event
)
634 struct bt_packet
*packet
;
635 struct bt_stream
*stream
;
636 struct bt_trace
*trace
;
637 struct bt_stream_class
*stream_class
;
644 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
645 "%sstream-context-field-addr=%p, "
646 "%scontext-field-addr=%p, %spayload-field-addr=%p, ",
647 PRFIELD(event
->frozen
),
648 PRFIELD(event
->header_field
?
649 event
->header_field
->field
: NULL
),
650 PRFIELD(event
->stream_event_context_field
),
651 PRFIELD(event
->context_field
),
652 PRFIELD(event
->payload_field
));
653 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
659 SET_TMP_PREFIX("event-class-");
660 format_event_class(buf_ch
, false, tmp_prefix
, event
->class);
661 stream_class
= bt_event_class_borrow_stream_class(event
->class);
663 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
664 SET_TMP_PREFIX("stream-class-");
665 format_stream_class(buf_ch
, false, tmp_prefix
,
668 trace
= bt_stream_class_borrow_trace(stream_class
);
670 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
671 SET_TMP_PREFIX("trace-");
672 format_trace(buf_ch
, false, tmp_prefix
, trace
);
676 SET_TMP_PREFIX("cvs-");
677 format_clock_value_set(buf_ch
, extended
, tmp_prefix
, &event
->cv_set
);
678 packet
= bt_event_borrow_packet(event
);
683 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet
));
684 SET_TMP_PREFIX("packet-");
685 format_packet(buf_ch
, false, tmp_prefix
, packet
);
686 stream
= bt_packet_borrow_stream(packet
);
691 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
692 SET_TMP_PREFIX("stream-");
693 format_stream(buf_ch
, false, tmp_prefix
, stream
);
696 static inline void format_clock_class(char **buf_ch
, bool extended
,
697 const char *prefix
, struct bt_clock_class
*clock_class
)
701 BUF_APPEND(", %sname=\"%s\", %sfreq=%" PRIu64
,
702 PRFIELD(clock_class
->name
->str
),
703 PRFIELD(clock_class
->frequency
));
709 if (clock_class
->description
) {
710 BUF_APPEND(", %spartial-description=\"%.32s\"",
711 PRFIELD(clock_class
->description
->str
));
714 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
715 "%soffset-s=%" PRId64
", "
716 "%soffset-cycles=%" PRId64
", %sis-absolute=%d",
717 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
718 PRFIELD(clock_class
->offset_s
), PRFIELD(clock_class
->offset
),
719 PRFIELD(clock_class
->absolute
));
721 if (clock_class
->uuid_set
) {
722 BUF_APPEND_UUID(clock_class
->uuid
);
725 SET_TMP_PREFIX("cv-pool-");
726 format_object_pool(buf_ch
, extended
, prefix
, &clock_class
->cv_pool
);
729 static inline void format_clock_value(char **buf_ch
, bool extended
,
730 const char *prefix
, struct bt_clock_value
*clock_value
)
733 BUF_APPEND(", %sraw-value=%" PRIu64
", %sns-from-epoch=%" PRId64
,
734 PRFIELD(clock_value
->value
),
735 PRFIELD(clock_value
->ns_from_epoch
));
741 BUF_APPEND(", %sis-frozen=%d, %sis-set=%d",
742 PRFIELD(clock_value
->frozen
), PRFIELD(clock_value
->is_set
));
743 BUF_APPEND(", %sclock-class-addr=%p",
744 PRFIELD(clock_value
->clock_class
));
745 SET_TMP_PREFIX("clock-class-");
746 format_clock_class(buf_ch
, false, tmp_prefix
, clock_value
->clock_class
);
749 static inline void format_value(char **buf_ch
, bool extended
,
750 const char *prefix
, struct bt_value
*value
)
752 BUF_APPEND(", %stype=%s",
753 PRFIELD(bt_value_type_string(bt_value_get_type(value
))));
759 switch (bt_value_get_type(value
)) {
760 case BT_VALUE_TYPE_BOOL
:
764 (void) bt_value_bool_get(value
, &val
);
765 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
768 case BT_VALUE_TYPE_INTEGER
:
772 (void) bt_value_integer_get(value
, &val
);
773 BUF_APPEND(", %svalue=%" PRId64
, PRFIELD(val
));
776 case BT_VALUE_TYPE_FLOAT
:
780 (void) bt_value_float_get(value
, &val
);
781 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
784 case BT_VALUE_TYPE_STRING
:
788 (void) bt_value_string_get(value
, &val
);
789 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
792 case BT_VALUE_TYPE_ARRAY
:
794 int64_t count
= bt_value_array_size(value
);
796 BT_ASSERT(count
>= 0);
797 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
800 case BT_VALUE_TYPE_MAP
:
802 int64_t count
= bt_value_map_size(value
);
804 BT_ASSERT(count
>= 0);
805 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
813 static inline void format_notification(char **buf_ch
, bool extended
,
814 const char *prefix
, struct bt_notification
*notif
)
818 BUF_APPEND(", %stype=%s",
819 PRFIELD(bt_notification_type_string(notif
->type
)));
825 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
826 PRFIELD(notif
->frozen
), PRFIELD(notif
->graph
));
828 switch (notif
->type
) {
829 case BT_NOTIFICATION_TYPE_EVENT
:
831 struct bt_notification_event
*notif_event
= (void *) notif
;
833 SET_TMP_PREFIX("event-");
834 format_event(buf_ch
, true, tmp_prefix
, notif_event
->event
);
837 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
839 struct bt_notification_stream_begin
*notif_stream
=
842 SET_TMP_PREFIX("stream-");
843 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
846 case BT_NOTIFICATION_TYPE_STREAM_END
:
848 struct bt_notification_stream_end
*notif_stream
=
851 SET_TMP_PREFIX("stream-");
852 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
855 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
857 struct bt_notification_packet_begin
*notif_packet
=
860 SET_TMP_PREFIX("packet-");
861 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
864 case BT_NOTIFICATION_TYPE_PACKET_END
:
866 struct bt_notification_packet_end
*notif_packet
=
869 SET_TMP_PREFIX("packet-");
870 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
878 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
880 struct bt_plugin_so_shared_lib_handle
*handle
)
882 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
885 BUF_APPEND(", %spath=\"%s\"", PRFIELD(handle
->path
->str
));
889 static inline void format_component_class(char **buf_ch
, bool extended
,
890 const char *prefix
, struct bt_component_class
*comp_class
)
894 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
895 PRFIELD(bt_component_class_type_string(comp_class
->type
)),
896 PRFIELD(comp_class
->name
? comp_class
->name
->str
: NULL
));
898 if (comp_class
->description
) {
899 BUF_APPEND(", %spartial-descr=\"%.32s\"",
900 PRFIELD(comp_class
->description
->str
));
907 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
909 if (comp_class
->so_handle
) {
910 SET_TMP_PREFIX("so-handle-");
911 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
912 comp_class
->so_handle
);
916 static inline void format_component(char **buf_ch
, bool extended
,
917 const char *prefix
, struct bt_component
*component
)
921 BUF_APPEND(", %sname=\"%s\"", PRFIELD(component
->name
->str
));
922 SET_TMP_PREFIX("class-");
923 format_component_class(buf_ch
, extended
, tmp_prefix
, component
->class);
929 if (component
->input_ports
) {
930 BUF_APPEND(", %sinput-port-count=%u",
931 PRFIELD(component
->input_ports
->len
));
934 if (component
->output_ports
) {
935 BUF_APPEND(", %soutput-port-count=%u",
936 PRFIELD(component
->output_ports
->len
));
940 static inline void format_port(char **buf_ch
, bool extended
,
941 const char *prefix
, struct bt_port
*port
)
945 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
946 PRFIELD(bt_port_type_string(port
->type
)),
947 PRFIELD(port
->name
->str
));
953 if (port
->connection
) {
954 SET_TMP_PREFIX("conn-");
955 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
959 static inline void format_connection(char **buf_ch
, bool extended
,
960 const char *prefix
, struct bt_connection
*connection
)
968 if (connection
->upstream_port
) {
969 SET_TMP_PREFIX("upstream-port-");
970 format_port(buf_ch
, false, tmp_prefix
,
971 connection
->upstream_port
);
974 if (connection
->downstream_port
) {
975 SET_TMP_PREFIX("downstream-port-");
976 format_port(buf_ch
, false, tmp_prefix
,
977 connection
->downstream_port
);
981 static inline void format_graph(char **buf_ch
, bool extended
,
982 const char *prefix
, struct bt_graph
*graph
)
986 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph
->canceled
));
992 if (graph
->components
) {
993 BUF_APPEND(", %scomp-count=%u",
994 PRFIELD(graph
->components
->len
));
997 if (graph
->connections
) {
998 BUF_APPEND(", %sconn-count=%u",
999 PRFIELD(graph
->connections
->len
));
1002 SET_TMP_PREFIX("en-pool-");
1003 format_object_pool(buf_ch
, extended
, prefix
,
1004 &graph
->event_notif_pool
);
1005 SET_TMP_PREFIX("pbn-pool-");
1006 format_object_pool(buf_ch
, extended
, prefix
,
1007 &graph
->packet_begin_notif_pool
);
1008 SET_TMP_PREFIX("pen-pool-");
1009 format_object_pool(buf_ch
, extended
, prefix
,
1010 &graph
->packet_end_notif_pool
);
1013 static inline void format_notification_iterator(char **buf_ch
,
1014 bool extended
, const char *prefix
,
1015 struct bt_notification_iterator
*iterator
)
1018 char tmp_prefix
[64];
1020 if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
) {
1021 type
= "BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION";
1022 } else if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
) {
1023 type
= "BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT";
1028 BUF_APPEND(", %stype=%s", PRFIELD(type
));
1030 switch (iterator
->type
) {
1031 case BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
:
1033 struct bt_notification_iterator_private_connection
*
1034 iter_priv_conn
= (void *) iterator
;
1036 if (iter_priv_conn
->upstream_component
) {
1037 SET_TMP_PREFIX("upstream-comp-");
1038 format_component(buf_ch
, false, tmp_prefix
,
1039 iter_priv_conn
->upstream_component
);
1042 if (iter_priv_conn
->upstream_port
) {
1043 SET_TMP_PREFIX("upstream-port-");
1044 format_port(buf_ch
, false, tmp_prefix
,
1045 iter_priv_conn
->upstream_port
);
1048 if (iter_priv_conn
->connection
) {
1049 SET_TMP_PREFIX("upstream-conn-");
1050 format_connection(buf_ch
, false, tmp_prefix
,
1051 iter_priv_conn
->connection
);
1055 case BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
:
1057 struct bt_notification_iterator_output_port
*iter_output_port
=
1060 SET_TMP_PREFIX("graph-");
1061 format_graph(buf_ch
, false, tmp_prefix
,
1062 iter_output_port
->graph
);
1063 SET_TMP_PREFIX("colander-comp-");
1064 format_component(buf_ch
, false, tmp_prefix
,
1065 iter_output_port
->colander
);
1073 static inline void format_plugin(char **buf_ch
, bool extended
,
1074 const char *prefix
, struct bt_plugin
*plugin
)
1076 char tmp_prefix
[64];
1078 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1080 if (plugin
->info
.path_set
) {
1081 BUF_APPEND(", %spath=\"%s\"",
1082 PRFIELD(plugin
->info
.path
->str
));
1085 if (plugin
->info
.name_set
) {
1086 BUF_APPEND(", %sname=\"%s\"",
1087 PRFIELD(plugin
->info
.name
->str
));
1094 if (plugin
->info
.author_set
) {
1095 BUF_APPEND(", %sauthor=\"%s\"",
1096 PRFIELD(plugin
->info
.author
->str
));
1099 if (plugin
->info
.license_set
) {
1100 BUF_APPEND(", %slicense=\"%s\"",
1101 PRFIELD(plugin
->info
.license
->str
));
1104 if (plugin
->info
.version_set
) {
1105 BUF_APPEND(", %sversion=%u.%u.%u%s",
1106 PRFIELD(plugin
->info
.version
.major
),
1107 plugin
->info
.version
.minor
,
1108 plugin
->info
.version
.patch
,
1109 plugin
->info
.version
.extra
?
1110 plugin
->info
.version
.extra
->str
: "");
1113 BUF_APPEND(", %sis-frozen=%d, %scomp-class-count=%u",
1114 PRFIELD(plugin
->frozen
),
1115 PRFIELD(plugin
->comp_classes
->len
));
1117 if (plugin
->spec_data
) {
1118 struct bt_plugin_so_spec_data
*spec_data
=
1119 (void *) plugin
->spec_data
;
1121 if (spec_data
->shared_lib_handle
) {
1122 SET_TMP_PREFIX("so-handle-");
1123 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1124 spec_data
->shared_lib_handle
);
1129 static inline void handle_conversion_specifier_bt(void *priv_data
,
1130 char **buf_ch
, size_t avail_size
,
1131 const char **out_fmt_ch
, va_list *args
)
1133 const char *fmt_ch
= *out_fmt_ch
;
1134 bool extended
= false;
1136 char *prefix_ch
= prefix
;
1142 if (*fmt_ch
== '[') {
1147 if (*fmt_ch
== ']') {
1153 *prefix_ch
= *fmt_ch
;
1161 if (*fmt_ch
== '+') {
1166 obj
= va_arg(*args
, void *);
1167 BUF_APPEND("%saddr=%p", prefix
, obj
);
1175 format_field_type(buf_ch
, extended
, prefix
, obj
);
1178 format_field(buf_ch
, extended
, prefix
, obj
);
1181 format_field_path(buf_ch
, extended
, prefix
, obj
);
1184 format_event_class(buf_ch
, extended
, prefix
, obj
);
1187 format_event(buf_ch
, extended
, prefix
, obj
);
1190 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1193 format_stream(buf_ch
, extended
, prefix
, obj
);
1196 format_packet(buf_ch
, extended
, prefix
, obj
);
1199 format_trace(buf_ch
, extended
, prefix
, obj
);
1202 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1205 format_clock_value(buf_ch
, extended
, prefix
, obj
);
1208 format_value(buf_ch
, extended
, prefix
, obj
);
1211 format_notification(buf_ch
, extended
, prefix
, obj
);
1214 format_notification_iterator(buf_ch
, extended
, prefix
, obj
);
1217 format_component_class(buf_ch
, extended
, prefix
, obj
);
1220 format_component(buf_ch
, extended
, prefix
, obj
);
1223 format_port(buf_ch
, extended
, prefix
, obj
);
1226 format_connection(buf_ch
, extended
, prefix
, obj
);
1229 format_plugin(buf_ch
, extended
, prefix
, obj
);
1232 format_graph(buf_ch
, extended
, prefix
, obj
);
1235 format_object_pool(buf_ch
, extended
, prefix
, obj
);
1238 format_object(buf_ch
, extended
, prefix
, obj
);
1246 *out_fmt_ch
= fmt_ch
;
1250 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1251 int lvl
, const char *tag
, const char *fmt
, ...)
1256 va_start(args
, fmt
);
1257 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1258 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1260 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);