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 typedef void (*format_func
)(char **, bool, const char *, void *);
114 static inline void format_component(char **buf_ch
, bool extended
,
115 const char *prefix
, struct bt_component
*component
);
117 static inline void format_port(char **buf_ch
, bool extended
,
118 const char *prefix
, struct bt_port
*port
);
120 static inline void format_connection(char **buf_ch
, bool extended
,
121 const char *prefix
, struct bt_connection
*connection
);
123 static inline void format_clock_value(char **buf_ch
, bool extended
,
124 const char *prefix
, struct bt_clock_value
*clock_value
);
126 static inline void format_object(char **buf_ch
, bool extended
,
127 const char *prefix
, struct bt_object
*obj
)
129 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
132 static inline void format_clock_value_set(char **buf_ch
, bool extended
,
133 const char *prefix
, struct bt_clock_value_set
*cv_set
)
137 if (!cv_set
->clock_values
) {
141 BUF_APPEND(", %ssize=%u", PRFIELD(cv_set
->clock_values
->len
));
143 if (cv_set
->default_cv
) {
144 SET_TMP_PREFIX("default-cv-");
145 format_clock_value(buf_ch
, extended
, tmp_prefix
,
150 static inline void format_object_pool(char **buf_ch
, bool extended
,
151 const char *prefix
, struct bt_object_pool
*pool
)
153 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
156 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
160 static inline void format_field_type_common(char **buf_ch
, bool extended
,
161 const char *prefix
, struct bt_field_type_common
*field_type
)
163 BUF_APPEND(", %stype-id=%s, %salignment=%u",
164 PRFIELD(bt_common_field_type_id_string(field_type
->id
)),
165 PRFIELD(field_type
->alignment
));
168 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_type
->frozen
));
173 if (field_type
->id
== BT_FIELD_TYPE_ID_UNKNOWN
) {
177 switch (field_type
->id
) {
178 case BT_FIELD_TYPE_ID_INTEGER
:
180 struct bt_field_type_common_integer
*integer
=
181 BT_FROM_COMMON(field_type
);
183 BUF_APPEND(", %ssize=%u, %sis-signed=%d, %sbyte-order=%s, "
184 "%sbase=%d, %sencoding=%s, "
185 "%smapped-clock-class-addr=%p",
186 PRFIELD(integer
->size
), PRFIELD(integer
->is_signed
),
187 PRFIELD(bt_common_byte_order_string(integer
->user_byte_order
)),
188 PRFIELD(integer
->base
),
189 PRFIELD(bt_common_string_encoding_string(integer
->encoding
)),
190 PRFIELD(integer
->mapped_clock_class
));
192 if (integer
->mapped_clock_class
) {
193 BUF_APPEND(", %smapped-clock-class-name=\"%s\"",
194 PRFIELD(bt_clock_class_get_name(integer
->mapped_clock_class
)));
198 case BT_FIELD_TYPE_ID_FLOAT
:
200 struct bt_field_type_common_floating_point
*flt
=
201 BT_FROM_COMMON(field_type
);
203 BUF_APPEND(", %sexp-dig=%u, %smant-dig=%u, %sbyte-order=%s",
204 PRFIELD(flt
->exp_dig
), PRFIELD(flt
->mant_dig
),
205 PRFIELD(bt_common_byte_order_string(flt
->user_byte_order
)));
208 case BT_FIELD_TYPE_ID_ENUM
:
210 struct bt_field_type_common_enumeration
*enm
=
211 BT_FROM_COMMON(field_type
);
213 BUF_APPEND(", %smapping-count=%u",
214 PRFIELD(enm
->entries
->len
));
217 case BT_FIELD_TYPE_ID_STRING
:
219 struct bt_field_type_common_string
*str
=
220 BT_FROM_COMMON(field_type
);
222 BUF_APPEND(", %sencoding=%s",
223 PRFIELD(bt_common_string_encoding_string(str
->encoding
)));
226 case BT_FIELD_TYPE_ID_STRUCT
:
228 struct bt_field_type_common_structure
*structure
=
229 BT_FROM_COMMON(field_type
);
231 BUF_APPEND(", %sfield-count=%u",
232 PRFIELD(structure
->fields
->len
));
235 case BT_FIELD_TYPE_ID_SEQUENCE
:
237 struct bt_field_type_common_sequence
*seq
=
238 BT_FROM_COMMON(field_type
);
240 BUF_APPEND(", %slength-ft-addr=\"%s\", %selem-ft-addr=%p",
241 PRFIELD(seq
->length_field_name
->str
),
242 PRFIELD(seq
->element_ft
));
245 case BT_FIELD_TYPE_ID_VARIANT
:
247 struct bt_field_type_common_variant
*variant
=
248 BT_FROM_COMMON(field_type
);
250 BUF_APPEND(", %stag-name=\"%s\", %sfield-count=%u",
251 PRFIELD(variant
->tag_name
->str
),
252 PRFIELD(variant
->choices
->len
));
260 static inline void format_field_type(char **buf_ch
, bool extended
,
261 const char *prefix
, struct bt_field_type
*field_type
)
263 format_field_type_common(buf_ch
, extended
, prefix
,
264 (void *) field_type
);
267 static inline void format_field_common_integer_extended(char **buf_ch
,
268 const char *prefix
, struct bt_field_common
*field
)
270 struct bt_field_common_integer
*integer
= BT_FROM_COMMON(field
);
271 struct bt_field_type_common_integer
*field_type
=
272 BT_FROM_COMMON(field
->type
);
273 const char *fmt
= NULL
;
275 BT_ASSERT(field_type
);
277 if (field_type
->base
== 8) {
278 fmt
= ", %svalue=%" PRIo64
;
279 } else if (field_type
->base
== 16) {
280 fmt
= ", %svalue=%" PRIx64
;
283 if (field_type
->is_signed
) {
285 fmt
= ", %svalue=%" PRId64
;
288 BUF_APPEND(fmt
, PRFIELD(integer
->payload
.signd
));
291 fmt
= ", %svalue=%" PRIu64
;
294 BUF_APPEND(fmt
, PRFIELD(integer
->payload
.unsignd
));
298 static inline void format_field_common(char **buf_ch
, bool extended
,
299 const char *prefix
, struct bt_field_common
*field
)
301 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->payload_set
));
304 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
307 BUF_APPEND(", %stype-addr=%p", PRFIELD(field
->type
));
313 BUF_APPEND(", %stype-id=%s",
314 PRFIELD(bt_common_field_type_id_string(field
->type
->id
)));
316 if (!extended
|| field
->type
->id
== BT_FIELD_TYPE_ID_UNKNOWN
||
317 !field
->payload_set
) {
321 switch (field
->type
->id
) {
322 case BT_FIELD_TYPE_ID_INTEGER
:
324 format_field_common_integer_extended(buf_ch
, prefix
, field
);
327 case BT_FIELD_TYPE_ID_FLOAT
:
329 struct bt_field_common_floating_point
*flt
=
330 BT_FROM_COMMON(field
);
332 BUF_APPEND(", %svalue=%f", PRFIELD(flt
->payload
));
335 case BT_FIELD_TYPE_ID_STRING
:
337 struct bt_field_common_string
*str
=
338 BT_FROM_COMMON(field
);
341 BT_ASSERT(str
->buf
->data
);
342 BUF_APPEND(", %spartial-value=\"%.32s\"",
343 PRFIELD(str
->buf
->data
));
348 case BT_FIELD_TYPE_ID_SEQUENCE
:
350 struct bt_field_common_sequence
*seq
=
351 BT_FROM_COMMON(field
);
353 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(seq
->length
));
356 BUF_APPEND(", %sallocated-length=%u",
357 PRFIELD(seq
->elements
->len
));
361 case BT_FIELD_TYPE_ID_VARIANT
:
363 struct bt_field_common_variant
*variant
=
364 BT_FROM_COMMON(field
);
366 BUF_APPEND(", %scur-field-addr=%p",
367 PRFIELD(variant
->current_field
));
375 static inline void format_field(char **buf_ch
, bool extended
,
376 const char *prefix
, struct bt_field
*field
)
378 struct bt_field_common
*common_field
= (void *) field
;
380 format_field_common(buf_ch
, extended
, prefix
, (void *) field
);
386 if (!common_field
->type
) {
390 switch (common_field
->type
->id
) {
391 case BT_FIELD_TYPE_ID_ENUM
:
393 struct bt_field_common_integer
*integer
= (void *) field
;
394 struct bt_field_type_common_enumeration
*enum_ft
=
395 BT_FROM_COMMON(common_field
->type
);
397 if (enum_ft
->container_ft
) {
398 if (enum_ft
->container_ft
->is_signed
) {
399 BUF_APPEND(", %svalue=%" PRId64
,
400 PRFIELD(integer
->payload
.signd
));
402 BUF_APPEND(", %svalue=%" PRIu64
,
403 PRFIELD(integer
->payload
.unsignd
));
413 static inline void format_field_path(char **buf_ch
, bool extended
,
414 const char *prefix
, struct bt_field_path
*field_path
)
418 if (field_path
->indexes
) {
419 BT_ASSERT(field_path
->indexes
);
420 BUF_APPEND(", %sindex-count=%u", PRFIELD(field_path
->indexes
->len
));
423 if (!extended
|| !field_path
->indexes
) {
427 BUF_APPEND(", %spath=[%s", PRFIELD(bt_common_scope_string(field_path
->root
)));
429 for (i
= 0; i
< field_path
->indexes
->len
; i
++) {
430 int index
= g_array_index(field_path
->indexes
, int, i
);
432 BUF_APPEND(", %d", index
);
435 BUF_APPEND("%s", "]");
438 static inline void format_trace_common(char **buf_ch
, bool extended
,
439 const char *prefix
, struct bt_trace_common
*trace
)
442 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
->str
));
449 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
451 if (trace
->uuid_set
) {
452 BUF_APPEND_UUID(trace
->uuid
);
455 if (trace
->clock_classes
) {
456 BUF_APPEND(", %sclock-class-count=%u",
457 PRFIELD(trace
->clock_classes
->len
));
460 if (trace
->stream_classes
) {
461 BUF_APPEND(", %sstream-class-count=%u",
462 PRFIELD(trace
->stream_classes
->len
));
465 if (trace
->streams
) {
466 BUF_APPEND(", %sstream-count=%u",
467 PRFIELD(trace
->streams
->len
));
470 BUF_APPEND(", %spacket-header-ft-addr=%p",
471 PRFIELD(trace
->packet_header_field_type
));
474 static inline void format_trace(char **buf_ch
, bool extended
,
475 const char *prefix
, struct bt_trace
*trace
)
479 format_trace_common(buf_ch
, extended
, prefix
, BT_TO_COMMON(trace
));
485 BUF_APPEND(", %sis-static=%d", PRFIELD(trace
->is_static
));
486 SET_TMP_PREFIX("phf-pool-");
487 format_object_pool(buf_ch
, extended
, prefix
,
488 &trace
->packet_header_field_pool
);
491 static inline void format_stream_class_common(char **buf_ch
, bool extended
,
492 const char *prefix
, struct bt_stream_class_common
*stream_class
,
493 format_func trace_format_func
)
495 struct bt_trace_common
*trace
;
498 if (stream_class
->id_set
) {
499 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(stream_class
->id
));
502 if (stream_class
->name
) {
503 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class
->name
->str
));
510 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
512 if (stream_class
->event_classes
) {
513 BUF_APPEND(", %sevent-class-count=%u",
514 PRFIELD(stream_class
->event_classes
->len
));
517 BUF_APPEND(", %spacket-context-ft-addr=%p, "
518 "%sevent-header-ft-addr=%p, %sevent-context-ft-addr=%p",
519 PRFIELD(stream_class
->packet_context_field_type
),
520 PRFIELD(stream_class
->event_header_field_type
),
521 PRFIELD(stream_class
->event_context_field_type
));
522 trace
= bt_stream_class_common_borrow_trace(stream_class
);
527 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
528 SET_TMP_PREFIX("trace-");
529 trace_format_func(buf_ch
, false, tmp_prefix
, trace
);
532 static inline void format_stream_class(char **buf_ch
, bool extended
,
533 const char *prefix
, struct bt_stream_class
*stream_class
)
537 format_stream_class_common(buf_ch
, extended
, prefix
,
538 BT_TO_COMMON(stream_class
), (format_func
) format_trace
);
544 SET_TMP_PREFIX("ehf-pool-");
545 format_object_pool(buf_ch
, extended
, prefix
,
546 &stream_class
->event_header_field_pool
);
547 SET_TMP_PREFIX("pcf-pool-");
548 format_object_pool(buf_ch
, extended
, prefix
,
549 &stream_class
->packet_context_field_pool
);
552 static inline void format_event_class_common(char **buf_ch
, bool extended
,
553 const char *prefix
, struct bt_event_class_common
*event_class
,
554 format_func format_stream_class_func
,
555 format_func format_trace_func
)
557 struct bt_stream_class_common
*stream_class
;
558 struct bt_trace_common
*trace
;
561 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(event_class
->id
));
563 if (event_class
->name
) {
564 BUF_APPEND(", %sname=\"%s\"", PRFIELD(event_class
->name
->str
));
571 BUF_APPEND(", %sis-frozen=%d, %slog-level=%s",
572 PRFIELD(event_class
->frozen
),
573 PRFIELD(bt_common_event_class_log_level_string(event_class
->log_level
)));
575 if (event_class
->emf_uri
) {
576 BUF_APPEND(", %semf-uri=\"%s\"",
577 PRFIELD(event_class
->emf_uri
->str
));
580 BUF_APPEND(", %scontext-ft-addr=%p, %spayload-ft-addr=%p",
581 PRFIELD(event_class
->context_field_type
),
582 PRFIELD(event_class
->payload_field_type
));
584 stream_class
= bt_event_class_common_borrow_stream_class(event_class
);
589 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
590 SET_TMP_PREFIX("stream-class-");
591 format_stream_class_func(buf_ch
, false, tmp_prefix
, stream_class
);
592 trace
= bt_stream_class_common_borrow_trace(stream_class
);
597 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
598 SET_TMP_PREFIX("trace-");
599 format_trace_func(buf_ch
, false, tmp_prefix
, trace
);
602 static inline void format_event_class(char **buf_ch
, bool extended
,
603 const char *prefix
, struct bt_event_class
*event_class
)
607 format_event_class_common(buf_ch
, extended
, prefix
,
608 BT_TO_COMMON(event_class
), (format_func
) format_stream_class
,
609 (format_func
) format_trace
);
615 SET_TMP_PREFIX("event-pool-");
616 format_object_pool(buf_ch
, extended
, prefix
, &event_class
->event_pool
);
619 static inline void format_stream_common(char **buf_ch
, bool extended
,
620 const char *prefix
, struct bt_stream_common
*stream
,
621 format_func format_stream_class_func
,
622 format_func format_trace_func
)
624 struct bt_stream_class_common
*stream_class
;
625 struct bt_trace_common
*trace
;
628 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(stream
->id
));
631 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
->str
));
638 stream_class
= bt_stream_common_borrow_class(stream
);
643 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
644 SET_TMP_PREFIX("stream-class-");
645 format_stream_class_func(buf_ch
, false, tmp_prefix
, stream_class
);
646 trace
= bt_stream_class_common_borrow_trace(stream_class
);
651 trace
= (void *) bt_object_borrow_parent(&stream
->base
);
656 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
657 SET_TMP_PREFIX("trace-");
658 format_trace_common(buf_ch
, false, tmp_prefix
, trace
);
661 static inline void format_stream(char **buf_ch
, bool extended
,
662 const char *prefix
, struct bt_stream
*stream
)
666 format_stream_common(buf_ch
, extended
, prefix
, BT_TO_COMMON(stream
),
667 (format_func
) format_stream_class
,
668 (format_func
) format_trace
);
669 SET_TMP_PREFIX("packet-pool-");
670 format_object_pool(buf_ch
, extended
, prefix
, &stream
->packet_pool
);
673 static inline void format_packet(char **buf_ch
, bool extended
,
674 const char *prefix
, struct bt_packet
*packet
)
676 struct bt_stream
*stream
;
677 struct bt_trace
*trace
;
684 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
685 "%scontext-field-addr=%p",
686 PRFIELD(packet
->frozen
),
687 PRFIELD(packet
->header
? packet
->header
->field
: NULL
),
688 PRFIELD(packet
->context
));
689 stream
= bt_packet_borrow_stream(packet
);
694 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
695 SET_TMP_PREFIX("stream-");
696 format_stream(buf_ch
, false, tmp_prefix
, stream
);
697 trace
= (struct bt_trace
*) bt_object_borrow_parent(&stream
->common
.base
);
702 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
703 SET_TMP_PREFIX("trace-");
704 format_trace(buf_ch
, false, tmp_prefix
, trace
);
707 static inline void format_event_common(char **buf_ch
, bool extended
,
708 const char *prefix
, struct bt_event_common
*event
,
709 format_func format_event_class_func
,
710 format_func format_stream_class_func
,
711 format_func format_trace_func
)
713 struct bt_trace_common
*trace
;
714 struct bt_stream_class_common
*stream_class
;
721 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
722 "%sstream-context-field-addr=%p, "
723 "%scontext-field-addr=%p, %spayload-field-addr=%p, ",
724 PRFIELD(event
->frozen
),
725 PRFIELD(event
->header_field
? event
->header_field
->field
: NULL
),
726 PRFIELD(event
->stream_event_context_field
),
727 PRFIELD(event
->context_field
),
728 PRFIELD(event
->payload_field
));
729 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
735 SET_TMP_PREFIX("event-class-");
736 format_event_class_func(buf_ch
, false, tmp_prefix
, event
->class);
737 stream_class
= bt_event_class_common_borrow_stream_class(event
->class);
739 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
740 SET_TMP_PREFIX("stream-class-");
741 format_stream_class_func(buf_ch
, false, tmp_prefix
,
744 trace
= bt_stream_class_common_borrow_trace(stream_class
);
746 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
747 SET_TMP_PREFIX("trace-");
748 format_trace_func(buf_ch
, false, tmp_prefix
, trace
);
753 static inline void format_event(char **buf_ch
, bool extended
,
754 const char *prefix
, struct bt_event
*event
)
756 struct bt_packet
*packet
;
757 struct bt_stream
*stream
;
760 format_event_common(buf_ch
, extended
, prefix
, BT_TO_COMMON(event
),
761 (format_func
) format_event_class
,
762 (format_func
) format_stream_class
, (format_func
) format_trace
);
768 SET_TMP_PREFIX("cvs-");
769 format_clock_value_set(buf_ch
, extended
, tmp_prefix
, &event
->cv_set
);
770 packet
= bt_event_borrow_packet(event
);
775 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet
));
776 SET_TMP_PREFIX("packet-");
777 format_packet(buf_ch
, false, tmp_prefix
, packet
);
778 stream
= bt_packet_borrow_stream(packet
);
783 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
784 SET_TMP_PREFIX("stream-");
785 format_stream(buf_ch
, false, tmp_prefix
, stream
);
788 static inline void format_clock_class(char **buf_ch
, bool extended
,
789 const char *prefix
, struct bt_clock_class
*clock_class
)
793 BUF_APPEND(", %sname=\"%s\", %sfreq=%" PRIu64
,
794 PRFIELD(clock_class
->name
->str
),
795 PRFIELD(clock_class
->frequency
));
801 if (clock_class
->description
) {
802 BUF_APPEND(", %spartial-description=\"%.32s\"",
803 PRFIELD(clock_class
->description
->str
));
806 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
807 "%soffset-s=%" PRId64
", "
808 "%soffset-cycles=%" PRId64
", %sis-absolute=%d",
809 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
810 PRFIELD(clock_class
->offset_s
), PRFIELD(clock_class
->offset
),
811 PRFIELD(clock_class
->absolute
));
813 if (clock_class
->uuid_set
) {
814 BUF_APPEND_UUID(clock_class
->uuid
);
817 SET_TMP_PREFIX("cv-pool-");
818 format_object_pool(buf_ch
, extended
, prefix
, &clock_class
->cv_pool
);
821 static inline void format_clock_value(char **buf_ch
, bool extended
,
822 const char *prefix
, struct bt_clock_value
*clock_value
)
825 BUF_APPEND(", %sraw-value=%" PRIu64
", %sns-from-epoch=%" PRId64
,
826 PRFIELD(clock_value
->value
),
827 PRFIELD(clock_value
->ns_from_epoch
));
833 BUF_APPEND(", %sis-frozen=%d, %sis-set=%d",
834 PRFIELD(clock_value
->frozen
), PRFIELD(clock_value
->is_set
));
835 BUF_APPEND(", %sclock-class-addr=%p",
836 PRFIELD(clock_value
->clock_class
));
837 SET_TMP_PREFIX("clock-class-");
838 format_clock_class(buf_ch
, false, tmp_prefix
, clock_value
->clock_class
);
841 static inline void format_value(char **buf_ch
, bool extended
,
842 const char *prefix
, struct bt_value
*value
)
844 BUF_APPEND(", %stype=%s",
845 PRFIELD(bt_value_type_string(bt_value_get_type(value
))));
851 switch (bt_value_get_type(value
)) {
852 case BT_VALUE_TYPE_BOOL
:
856 (void) bt_value_bool_get(value
, &val
);
857 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
860 case BT_VALUE_TYPE_INTEGER
:
864 (void) bt_value_integer_get(value
, &val
);
865 BUF_APPEND(", %svalue=%" PRId64
, PRFIELD(val
));
868 case BT_VALUE_TYPE_FLOAT
:
872 (void) bt_value_float_get(value
, &val
);
873 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
876 case BT_VALUE_TYPE_STRING
:
880 (void) bt_value_string_get(value
, &val
);
881 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
884 case BT_VALUE_TYPE_ARRAY
:
886 int64_t count
= bt_value_array_size(value
);
888 BT_ASSERT(count
>= 0);
889 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
892 case BT_VALUE_TYPE_MAP
:
894 int64_t count
= bt_value_map_size(value
);
896 BT_ASSERT(count
>= 0);
897 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
905 static inline void format_notification(char **buf_ch
, bool extended
,
906 const char *prefix
, struct bt_notification
*notif
)
910 BUF_APPEND(", %stype=%s",
911 PRFIELD(bt_notification_type_string(notif
->type
)));
917 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
918 PRFIELD(notif
->frozen
), PRFIELD(notif
->graph
));
920 switch (notif
->type
) {
921 case BT_NOTIFICATION_TYPE_EVENT
:
923 struct bt_notification_event
*notif_event
= (void *) notif
;
925 SET_TMP_PREFIX("event-");
926 format_event(buf_ch
, true, tmp_prefix
, notif_event
->event
);
929 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
931 struct bt_notification_stream_begin
*notif_stream
=
934 SET_TMP_PREFIX("stream-");
935 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
938 case BT_NOTIFICATION_TYPE_STREAM_END
:
940 struct bt_notification_stream_end
*notif_stream
=
943 SET_TMP_PREFIX("stream-");
944 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
947 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
949 struct bt_notification_packet_begin
*notif_packet
=
952 SET_TMP_PREFIX("packet-");
953 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
956 case BT_NOTIFICATION_TYPE_PACKET_END
:
958 struct bt_notification_packet_end
*notif_packet
=
961 SET_TMP_PREFIX("packet-");
962 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
970 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
972 struct bt_plugin_so_shared_lib_handle
*handle
)
974 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
977 BUF_APPEND(", %spath=\"%s\"", PRFIELD(handle
->path
->str
));
981 static inline void format_component_class(char **buf_ch
, bool extended
,
982 const char *prefix
, struct bt_component_class
*comp_class
)
986 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
987 PRFIELD(bt_component_class_type_string(comp_class
->type
)),
988 PRFIELD(comp_class
->name
? comp_class
->name
->str
: NULL
));
990 if (comp_class
->description
) {
991 BUF_APPEND(", %spartial-descr=\"%.32s\"",
992 PRFIELD(comp_class
->description
->str
));
999 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
1001 if (comp_class
->so_handle
) {
1002 SET_TMP_PREFIX("so-handle-");
1003 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1004 comp_class
->so_handle
);
1008 static inline void format_component(char **buf_ch
, bool extended
,
1009 const char *prefix
, struct bt_component
*component
)
1011 char tmp_prefix
[64];
1013 BUF_APPEND(", %sname=\"%s\"", PRFIELD(component
->name
->str
));
1014 SET_TMP_PREFIX("class-");
1015 format_component_class(buf_ch
, extended
, tmp_prefix
, component
->class);
1021 if (component
->input_ports
) {
1022 BUF_APPEND(", %sinput-port-count=%u",
1023 PRFIELD(component
->input_ports
->len
));
1026 if (component
->output_ports
) {
1027 BUF_APPEND(", %soutput-port-count=%u",
1028 PRFIELD(component
->output_ports
->len
));
1032 static inline void format_port(char **buf_ch
, bool extended
,
1033 const char *prefix
, struct bt_port
*port
)
1035 char tmp_prefix
[64];
1037 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1038 PRFIELD(bt_port_type_string(port
->type
)),
1039 PRFIELD(port
->name
->str
));
1045 if (port
->connection
) {
1046 SET_TMP_PREFIX("conn-");
1047 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1051 static inline void format_connection(char **buf_ch
, bool extended
,
1052 const char *prefix
, struct bt_connection
*connection
)
1054 char tmp_prefix
[64];
1060 if (connection
->upstream_port
) {
1061 SET_TMP_PREFIX("upstream-port-");
1062 format_port(buf_ch
, false, tmp_prefix
,
1063 connection
->upstream_port
);
1066 if (connection
->downstream_port
) {
1067 SET_TMP_PREFIX("downstream-port-");
1068 format_port(buf_ch
, false, tmp_prefix
,
1069 connection
->downstream_port
);
1073 static inline void format_graph(char **buf_ch
, bool extended
,
1074 const char *prefix
, struct bt_graph
*graph
)
1076 char tmp_prefix
[64];
1078 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph
->canceled
));
1084 if (graph
->components
) {
1085 BUF_APPEND(", %scomp-count=%u",
1086 PRFIELD(graph
->components
->len
));
1089 if (graph
->connections
) {
1090 BUF_APPEND(", %sconn-count=%u",
1091 PRFIELD(graph
->connections
->len
));
1094 SET_TMP_PREFIX("en-pool-");
1095 format_object_pool(buf_ch
, extended
, prefix
,
1096 &graph
->event_notif_pool
);
1097 SET_TMP_PREFIX("pbn-pool-");
1098 format_object_pool(buf_ch
, extended
, prefix
,
1099 &graph
->packet_begin_notif_pool
);
1100 SET_TMP_PREFIX("pen-pool-");
1101 format_object_pool(buf_ch
, extended
, prefix
,
1102 &graph
->packet_end_notif_pool
);
1105 static inline void format_notification_iterator(char **buf_ch
,
1106 bool extended
, const char *prefix
,
1107 struct bt_notification_iterator
*iterator
)
1110 char tmp_prefix
[64];
1112 if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
) {
1113 type
= "BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION";
1114 } else if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
) {
1115 type
= "BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT";
1120 BUF_APPEND(", %stype=%s", PRFIELD(type
));
1122 switch (iterator
->type
) {
1123 case BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
:
1125 struct bt_notification_iterator_private_connection
*
1126 iter_priv_conn
= (void *) iterator
;
1128 if (iter_priv_conn
->upstream_component
) {
1129 SET_TMP_PREFIX("upstream-comp-");
1130 format_component(buf_ch
, false, tmp_prefix
,
1131 iter_priv_conn
->upstream_component
);
1134 if (iter_priv_conn
->upstream_port
) {
1135 SET_TMP_PREFIX("upstream-port-");
1136 format_port(buf_ch
, false, tmp_prefix
,
1137 iter_priv_conn
->upstream_port
);
1140 if (iter_priv_conn
->connection
) {
1141 SET_TMP_PREFIX("upstream-conn-");
1142 format_connection(buf_ch
, false, tmp_prefix
,
1143 iter_priv_conn
->connection
);
1147 case BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
:
1149 struct bt_notification_iterator_output_port
*iter_output_port
=
1152 SET_TMP_PREFIX("graph-");
1153 format_graph(buf_ch
, false, tmp_prefix
,
1154 iter_output_port
->graph
);
1155 SET_TMP_PREFIX("colander-comp-");
1156 format_component(buf_ch
, false, tmp_prefix
,
1157 iter_output_port
->colander
);
1165 static inline void format_plugin(char **buf_ch
, bool extended
,
1166 const char *prefix
, struct bt_plugin
*plugin
)
1168 char tmp_prefix
[64];
1170 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1172 if (plugin
->info
.path_set
) {
1173 BUF_APPEND(", %spath=\"%s\"",
1174 PRFIELD(plugin
->info
.path
->str
));
1177 if (plugin
->info
.name_set
) {
1178 BUF_APPEND(", %sname=\"%s\"",
1179 PRFIELD(plugin
->info
.name
->str
));
1186 if (plugin
->info
.author_set
) {
1187 BUF_APPEND(", %sauthor=\"%s\"",
1188 PRFIELD(plugin
->info
.author
->str
));
1191 if (plugin
->info
.license_set
) {
1192 BUF_APPEND(", %slicense=\"%s\"",
1193 PRFIELD(plugin
->info
.license
->str
));
1196 if (plugin
->info
.version_set
) {
1197 BUF_APPEND(", %sversion=%u.%u.%u%s",
1198 PRFIELD(plugin
->info
.version
.major
),
1199 plugin
->info
.version
.minor
,
1200 plugin
->info
.version
.patch
,
1201 plugin
->info
.version
.extra
?
1202 plugin
->info
.version
.extra
->str
: "");
1205 BUF_APPEND(", %sis-frozen=%d, %scomp-class-count=%u",
1206 PRFIELD(plugin
->frozen
),
1207 PRFIELD(plugin
->comp_classes
->len
));
1209 if (plugin
->spec_data
) {
1210 struct bt_plugin_so_spec_data
*spec_data
=
1211 (void *) plugin
->spec_data
;
1213 if (spec_data
->shared_lib_handle
) {
1214 SET_TMP_PREFIX("so-handle-");
1215 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1216 spec_data
->shared_lib_handle
);
1221 static inline void format_stream_class_common_common(char **buf_ch
,
1222 bool extended
, const char *prefix
,
1223 struct bt_stream_class_common
*stream_class
)
1225 format_stream_class_common(buf_ch
, extended
, prefix
, stream_class
,
1226 (format_func
) format_trace_common
);
1229 static inline void format_event_class_common_common(char **buf_ch
,
1230 bool extended
, const char *prefix
,
1231 struct bt_event_class_common
*event_class
)
1233 format_event_class_common(buf_ch
, extended
, prefix
, event_class
,
1234 (format_func
) format_stream_class_common
,
1235 (format_func
) format_trace_common
);
1238 static inline void format_event_common_common(char **buf_ch
,
1239 bool extended
, const char *prefix
,
1240 struct bt_event_common
*event
)
1242 format_event_common(buf_ch
, extended
, prefix
, event
,
1243 (format_func
) format_event_class_common
,
1244 (format_func
) format_stream_class_common
,
1245 (format_func
) format_trace_common
);
1248 static inline void format_stream_common_common(char **buf_ch
, bool extended
,
1249 const char *prefix
, struct bt_stream_common
*stream
)
1251 format_stream_common(buf_ch
, extended
, prefix
, stream
,
1252 (format_func
) format_stream_class_common
,
1253 (format_func
) format_trace_common
);
1256 static inline void handle_conversion_specifier_bt(void *priv_data
,
1257 char **buf_ch
, size_t avail_size
,
1258 const char **out_fmt_ch
, va_list *args
)
1260 const char *fmt_ch
= *out_fmt_ch
;
1261 bool extended
= false;
1263 char *prefix_ch
= prefix
;
1268 } cat
= CAT_DEFAULT
;
1273 if (*fmt_ch
== '[') {
1278 if (*fmt_ch
== ']') {
1284 *prefix_ch
= *fmt_ch
;
1292 if (*fmt_ch
== '+') {
1297 if (*fmt_ch
== '_') {
1302 obj
= va_arg(*args
, void *);
1303 BUF_APPEND("%saddr=%p", prefix
, obj
);
1313 format_field_type(buf_ch
, extended
, prefix
, obj
);
1316 format_field(buf_ch
, extended
, prefix
, obj
);
1319 format_field_path(buf_ch
, extended
, prefix
, obj
);
1322 format_event_class(buf_ch
, extended
, prefix
, obj
);
1325 format_event(buf_ch
, extended
, prefix
, obj
);
1328 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1331 format_stream(buf_ch
, extended
, prefix
, obj
);
1334 format_packet(buf_ch
, extended
, prefix
, obj
);
1337 format_trace(buf_ch
, extended
, prefix
, obj
);
1340 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1343 format_clock_value(buf_ch
, extended
, prefix
, obj
);
1346 format_value(buf_ch
, extended
, prefix
, obj
);
1349 format_notification(buf_ch
, extended
, prefix
, obj
);
1352 format_notification_iterator(buf_ch
, extended
, prefix
, obj
);
1355 format_component_class(buf_ch
, extended
, prefix
, obj
);
1358 format_component(buf_ch
, extended
, prefix
, obj
);
1361 format_port(buf_ch
, extended
, prefix
, obj
);
1364 format_connection(buf_ch
, extended
, prefix
, obj
);
1367 format_plugin(buf_ch
, extended
, prefix
, obj
);
1370 format_graph(buf_ch
, extended
, prefix
, obj
);
1373 format_object_pool(buf_ch
, extended
, prefix
, obj
);
1376 format_object(buf_ch
, extended
, prefix
, obj
);
1385 format_field_type_common(buf_ch
, extended
, prefix
, obj
);
1388 format_field_common(buf_ch
, extended
, prefix
, obj
);
1391 format_event_class_common_common(buf_ch
, extended
, prefix
, obj
);
1394 format_event_common_common(buf_ch
, extended
, prefix
, obj
);
1397 format_stream_class_common_common(buf_ch
, extended
, prefix
, obj
);
1400 format_stream_common_common(buf_ch
, extended
, prefix
, obj
);
1403 format_trace_common(buf_ch
, extended
, prefix
, obj
);
1413 *out_fmt_ch
= fmt_ch
;
1417 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1418 int lvl
, const char *tag
, const char *fmt
, ...)
1423 va_start(args
, fmt
);
1424 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1425 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1427 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);