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) \
86 BUF_APPEND(", %suuid=", prefix); \
87 format_uuid(buf_ch, (_uuid)); \
90 #define PRFIELD(_expr) prefix, (_expr)
92 #define SET_TMP_PREFIX(_prefix2) \
94 strcpy(tmp_prefix, prefix); \
95 strcat(tmp_prefix, (_prefix2)); \
98 static inline void format_component(char **buf_ch
, bool extended
,
99 const char *prefix
, struct bt_component
*component
);
101 static inline void format_port(char **buf_ch
, bool extended
,
102 const char *prefix
, struct bt_port
*port
);
104 static inline void format_connection(char **buf_ch
, bool extended
,
105 const char *prefix
, struct bt_connection
*connection
);
107 static inline void format_clock_value(char **buf_ch
, bool extended
,
108 const char *prefix
, struct bt_clock_value
*clock_value
);
110 static inline void format_field_path(char **buf_ch
, bool extended
,
111 const char *prefix
, struct bt_field_path
*field_path
);
113 static inline void format_object(char **buf_ch
, bool extended
,
114 const char *prefix
, struct bt_object
*obj
)
116 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
119 static inline void format_uuid(char **buf_ch
, bt_uuid uuid
)
121 BUF_APPEND("\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
122 (unsigned int) uuid
[0],
123 (unsigned int) uuid
[1],
124 (unsigned int) uuid
[2],
125 (unsigned int) uuid
[3],
126 (unsigned int) uuid
[4],
127 (unsigned int) uuid
[5],
128 (unsigned int) uuid
[6],
129 (unsigned int) uuid
[7],
130 (unsigned int) uuid
[8],
131 (unsigned int) uuid
[9],
132 (unsigned int) uuid
[10],
133 (unsigned int) uuid
[11],
134 (unsigned int) uuid
[12],
135 (unsigned int) uuid
[13],
136 (unsigned int) uuid
[14],
137 (unsigned int) uuid
[15]);
140 static inline void format_object_pool(char **buf_ch
, bool extended
,
141 const char *prefix
, struct bt_object_pool
*pool
)
143 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
146 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
150 static inline void format_integer_field_type(char **buf_ch
,
151 bool extended
, const char *prefix
,
152 struct bt_field_type
*field_type
)
154 struct bt_field_type_integer
*int_ft
= (void *) field_type
;
156 BUF_APPEND(", %srange-size=%" PRIu64
", %sbase=%s",
157 PRFIELD(int_ft
->range
),
158 PRFIELD(bt_common_field_type_integer_preferred_display_base_string(int_ft
->base
)));
161 static inline void format_array_field_type(char **buf_ch
,
162 bool extended
, const char *prefix
,
163 struct bt_field_type
*field_type
)
165 struct bt_field_type_array
*array_ft
= (void *) field_type
;
167 BUF_APPEND(", %selement-ft-addr=%p, %selement-ft-id=%s",
168 PRFIELD(array_ft
->element_ft
),
169 PRFIELD(bt_common_field_type_id_string(array_ft
->element_ft
->id
)));
172 static inline void format_field_type(char **buf_ch
, bool extended
,
173 const char *prefix
, struct bt_field_type
*field_type
)
177 BUF_APPEND(", %sid=%s",
178 PRFIELD(bt_common_field_type_id_string(field_type
->id
)));
181 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_type
->frozen
));
182 BUF_APPEND(", %sis-part-of-trace=%d",
183 PRFIELD(field_type
->part_of_trace
));
188 switch (field_type
->id
) {
189 case BT_FIELD_TYPE_ID_UNSIGNED_INTEGER
:
190 case BT_FIELD_TYPE_ID_SIGNED_INTEGER
:
192 format_integer_field_type(buf_ch
, extended
, prefix
, field_type
);
195 case BT_FIELD_TYPE_ID_REAL
:
197 struct bt_field_type_real
*real_ft
= (void *) field_type
;
199 BUF_APPEND(", %sis-single-precision=%d",
200 PRFIELD(real_ft
->is_single_precision
));
203 case BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION
:
204 case BT_FIELD_TYPE_ID_SIGNED_ENUMERATION
:
206 struct bt_field_type_enumeration
*enum_ft
=
209 format_integer_field_type(buf_ch
, extended
, prefix
, field_type
);
210 BUF_APPEND(", %smapping-count=%u",
211 PRFIELD(enum_ft
->mappings
->len
));
214 case BT_FIELD_TYPE_ID_STRUCTURE
:
216 struct bt_field_type_structure
*struct_ft
=
219 if (struct_ft
->common
.named_fts
) {
220 BUF_APPEND(", %smember-count=%u",
221 PRFIELD(struct_ft
->common
.named_fts
->len
));
226 case BT_FIELD_TYPE_ID_STATIC_ARRAY
:
228 struct bt_field_type_static_array
*array_ft
=
231 format_array_field_type(buf_ch
, extended
, prefix
, field_type
);
232 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_ft
->length
));
235 case BT_FIELD_TYPE_ID_DYNAMIC_ARRAY
:
237 struct bt_field_type_dynamic_array
*array_ft
=
240 format_array_field_type(buf_ch
, extended
, prefix
, field_type
);
242 if (array_ft
->length_ft
) {
243 SET_TMP_PREFIX("length-ft-");
244 format_field_type(buf_ch
, extended
, tmp_prefix
,
245 array_ft
->length_ft
);
248 if (array_ft
->length_field_path
) {
249 SET_TMP_PREFIX("length-field-path-");
250 format_field_path(buf_ch
, extended
, tmp_prefix
,
251 array_ft
->length_field_path
);
256 case BT_FIELD_TYPE_ID_VARIANT
:
258 struct bt_field_type_variant
*var_ft
= (void *) field_type
;
260 if (var_ft
->common
.named_fts
) {
261 BUF_APPEND(", %soption-count=%u",
262 PRFIELD(var_ft
->common
.named_fts
->len
));
265 if (var_ft
->selector_ft
) {
266 SET_TMP_PREFIX("selector-ft-");
267 format_field_type(buf_ch
, extended
, tmp_prefix
,
268 var_ft
->selector_ft
);
271 if (var_ft
->selector_field_path
) {
272 SET_TMP_PREFIX("selector-field-path-");
273 format_field_path(buf_ch
, extended
, tmp_prefix
,
274 var_ft
->selector_field_path
);
284 static inline void format_field_integer_extended(char **buf_ch
,
285 const char *prefix
, struct bt_field
*field
)
287 struct bt_field_integer
*integer
= (void *) field
;
288 struct bt_field_type_integer
*field_type
= (void *) field
->type
;
289 const char *fmt
= NULL
;
291 BT_ASSERT(field_type
);
293 if (field_type
->base
== BT_FIELD_TYPE_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
) {
294 fmt
= ", %svalue=%" PRIo64
;
295 } else if (field_type
->base
== BT_FIELD_TYPE_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
) {
296 fmt
= ", %svalue=%" PRIx64
;
299 if (field_type
->common
.id
== BT_FIELD_TYPE_ID_SIGNED_INTEGER
||
300 field_type
->common
.id
== BT_FIELD_TYPE_ID_SIGNED_ENUMERATION
) {
302 fmt
= ", %svalue=%" PRId64
;
305 BUF_APPEND(fmt
, PRFIELD(integer
->value
.i
));
308 fmt
= ", %svalue=%" PRIu64
;
311 BUF_APPEND(fmt
, PRFIELD(integer
->value
.u
));
315 static inline void format_field(char **buf_ch
, bool extended
,
316 const char *prefix
, struct bt_field
*field
)
318 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->is_set
));
321 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
324 BUF_APPEND(", %stype-addr=%p", PRFIELD(field
->type
));
330 BUF_APPEND(", %stype-id=%s",
331 PRFIELD(bt_common_field_type_id_string(field
->type
->id
)));
333 if (!extended
|| !field
->is_set
) {
337 switch (field
->type
->id
) {
338 case BT_FIELD_TYPE_ID_UNSIGNED_INTEGER
:
339 case BT_FIELD_TYPE_ID_SIGNED_INTEGER
:
340 case BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION
:
341 case BT_FIELD_TYPE_ID_SIGNED_ENUMERATION
:
343 format_field_integer_extended(buf_ch
, prefix
, field
);
346 case BT_FIELD_TYPE_ID_REAL
:
348 struct bt_field_real
*real_field
= (void *) field
;
350 BUF_APPEND(", %svalue=%f", PRFIELD(real_field
->value
));
353 case BT_FIELD_TYPE_ID_STRING
:
355 struct bt_field_string
*str
= (void *) field
;
358 BT_ASSERT(str
->buf
->data
);
359 BUF_APPEND(", %spartial-value=\"%.32s\"",
360 PRFIELD(str
->buf
->data
));
365 case BT_FIELD_TYPE_ID_STATIC_ARRAY
:
366 case BT_FIELD_TYPE_ID_DYNAMIC_ARRAY
:
368 struct bt_field_array
*array_field
= (void *) field
;
370 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_field
->length
));
372 if (array_field
->fields
) {
373 BUF_APPEND(", %sallocated-length=%u",
374 PRFIELD(array_field
->fields
->len
));
379 case BT_FIELD_TYPE_ID_VARIANT
:
381 struct bt_field_variant
*var_field
= (void *) field
;
383 BUF_APPEND(", %sselected-field-index=%" PRIu64
,
384 PRFIELD(var_field
->selected_index
));
392 static inline void format_field_path(char **buf_ch
, bool extended
,
393 const char *prefix
, struct bt_field_path
*field_path
)
397 if (field_path
->indexes
) {
398 BT_ASSERT(field_path
->indexes
);
399 BUF_APPEND(", %sindex-count=%u",
400 PRFIELD(field_path
->indexes
->len
));
403 if (!extended
|| !field_path
->indexes
) {
407 BUF_APPEND(", %spath=[%s",
408 PRFIELD(bt_common_scope_string(field_path
->root
)));
410 for (i
= 0; i
< field_path
->indexes
->len
; i
++) {
411 uint64_t index
= bt_field_path_get_index_by_index_inline(
414 BUF_APPEND(", %" PRIu64
, index
);
417 BUF_APPEND("%s", "]");
420 static inline void format_trace(char **buf_ch
, bool extended
,
421 const char *prefix
, struct bt_trace
*trace
)
425 if (trace
->name
.value
) {
426 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
.value
));
433 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
435 if (trace
->uuid
.value
) {
436 BUF_APPEND_UUID(trace
->uuid
.value
);
439 if (trace
->stream_classes
) {
440 BUF_APPEND(", %sstream-class-count=%u",
441 PRFIELD(trace
->stream_classes
->len
));
444 if (trace
->streams
) {
445 BUF_APPEND(", %sstream-count=%u",
446 PRFIELD(trace
->streams
->len
));
449 BUF_APPEND(", %spacket-header-ft-addr=%p, %sis-static=%d, "
450 "%sassigns-auto-sc-id=%d",
451 PRFIELD(trace
->packet_header_ft
),
452 PRFIELD(trace
->is_static
),
453 PRFIELD(trace
->assigns_automatic_stream_class_id
));
454 SET_TMP_PREFIX("phf-pool-");
455 format_object_pool(buf_ch
, extended
, prefix
,
456 &trace
->packet_header_field_pool
);
459 static inline void format_stream_class(char **buf_ch
, bool extended
,
460 const char *prefix
, struct bt_stream_class
*stream_class
)
462 struct bt_trace
*trace
;
465 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream_class
->id
));
467 if (stream_class
->name
.value
) {
468 BUF_APPEND(", %sname=\"%s\"",
469 PRFIELD(stream_class
->name
.value
));
476 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
478 if (stream_class
->event_classes
) {
479 BUF_APPEND(", %sevent-class-count=%u",
480 PRFIELD(stream_class
->event_classes
->len
));
483 BUF_APPEND(", %spacket-context-ft-addr=%p, "
484 "%sevent-header-ft-addr=%p, %sevent-common-context-ft-addr=%p",
485 PRFIELD(stream_class
->packet_context_ft
),
486 PRFIELD(stream_class
->event_header_ft
),
487 PRFIELD(stream_class
->event_common_context_ft
));
488 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
493 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
494 "%spackets-have-discarded-ev-counter-snapshot=%d, "
495 "%spackets-have-packet-counter-snapshot=%d, "
496 "%spackets-have-default-begin-cv=%d, "
497 "%spackets-have-default-end-cv=%d",
498 PRFIELD(stream_class
->assigns_automatic_event_class_id
),
499 PRFIELD(stream_class
->assigns_automatic_stream_id
),
500 PRFIELD(stream_class
->packets_have_discarded_event_counter_snapshot
),
501 PRFIELD(stream_class
->packets_have_packet_counter_snapshot
),
502 PRFIELD(stream_class
->packets_have_default_beginning_cv
),
503 PRFIELD(stream_class
->packets_have_default_end_cv
));
504 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
505 SET_TMP_PREFIX("trace-");
506 format_trace(buf_ch
, false, tmp_prefix
, trace
);
507 SET_TMP_PREFIX("ehf-pool-");
508 format_object_pool(buf_ch
, extended
, prefix
,
509 &stream_class
->event_header_field_pool
);
510 SET_TMP_PREFIX("pcf-pool-");
511 format_object_pool(buf_ch
, extended
, prefix
,
512 &stream_class
->packet_context_field_pool
);
515 static inline void format_event_class(char **buf_ch
, bool extended
,
516 const char *prefix
, struct bt_event_class
*event_class
)
518 struct bt_stream_class
*stream_class
;
519 struct bt_trace
*trace
;
522 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(event_class
->id
));
524 if (event_class
->name
.value
) {
525 BUF_APPEND(", %sname=\"%s\"",
526 PRFIELD(event_class
->name
.value
));
533 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class
->frozen
));
535 if (event_class
->log_level
.base
.avail
) {
536 BUF_APPEND(", %slog-level=%s",
537 PRFIELD(bt_common_event_class_log_level_string(
538 (int) event_class
->log_level
.value
)));
541 if (event_class
->emf_uri
.value
) {
542 BUF_APPEND(", %semf-uri=\"%s\"",
543 PRFIELD(event_class
->emf_uri
.value
));
546 BUF_APPEND(", %sspecific-context-ft-addr=%p, %spayload-ft-addr=%p",
547 PRFIELD(event_class
->specific_context_ft
),
548 PRFIELD(event_class
->payload_ft
));
550 stream_class
= bt_event_class_borrow_stream_class(event_class
);
555 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
556 SET_TMP_PREFIX("stream-class-");
557 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
558 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
563 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
564 SET_TMP_PREFIX("trace-");
565 format_trace(buf_ch
, false, tmp_prefix
, trace
);
566 SET_TMP_PREFIX("event-pool-");
567 format_object_pool(buf_ch
, extended
, prefix
, &event_class
->event_pool
);
570 static inline void format_stream(char **buf_ch
, bool extended
,
571 const char *prefix
, struct bt_stream
*stream
)
573 struct bt_stream_class
*stream_class
;
574 struct bt_trace
*trace
;
577 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream
->id
));
579 if (stream
->name
.value
) {
580 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
.value
));
587 stream_class
= bt_stream_borrow_class(stream
);
592 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
593 SET_TMP_PREFIX("stream-class-");
594 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
595 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
600 trace
= (void *) bt_object_borrow_parent(&stream
->base
);
605 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
606 SET_TMP_PREFIX("trace-");
607 format_trace(buf_ch
, false, tmp_prefix
, trace
);
608 SET_TMP_PREFIX("packet-pool-");
609 format_object_pool(buf_ch
, extended
, prefix
, &stream
->packet_pool
);
612 static inline void format_packet(char **buf_ch
, bool extended
,
613 const char *prefix
, struct bt_packet
*packet
)
615 struct bt_stream
*stream
;
616 struct bt_trace
*trace
;
623 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
624 "%scontext-field-addr=%p",
625 PRFIELD(packet
->frozen
),
626 PRFIELD(packet
->header_field
? packet
->header_field
->field
: NULL
),
627 PRFIELD(packet
->context_field
? packet
->context_field
->field
: NULL
));
628 stream
= bt_packet_borrow_stream(packet
);
633 if (packet
->default_beginning_cv
) {
634 SET_TMP_PREFIX("default-begin-cv-");
635 format_clock_value(buf_ch
, true, tmp_prefix
,
636 packet
->default_beginning_cv
);
639 if (packet
->default_end_cv
) {
640 SET_TMP_PREFIX("default-end-cv-");
641 format_clock_value(buf_ch
, true, tmp_prefix
,
642 packet
->default_end_cv
);
645 if (packet
->discarded_event_counter_snapshot
.base
.avail
) {
646 BUF_APPEND(", %sdiscarded-ev-counter-snapshot=%" PRIu64
,
647 PRFIELD(packet
->discarded_event_counter_snapshot
.value
));
650 if (packet
->packet_counter_snapshot
.base
.avail
) {
651 BUF_APPEND(", %spacket-counter-snapshot=%" PRIu64
,
652 PRFIELD(packet
->packet_counter_snapshot
.value
));
655 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
656 SET_TMP_PREFIX("stream-");
657 format_stream(buf_ch
, false, tmp_prefix
, stream
);
658 trace
= (struct bt_trace
*) bt_object_borrow_parent(&stream
->base
);
663 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
664 SET_TMP_PREFIX("trace-");
665 format_trace(buf_ch
, false, tmp_prefix
, trace
);
668 static inline void format_event(char **buf_ch
, bool extended
,
669 const char *prefix
, struct bt_event
*event
)
671 struct bt_packet
*packet
;
672 struct bt_stream
*stream
;
673 struct bt_trace
*trace
;
674 struct bt_stream_class
*stream_class
;
681 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
682 "%scommon-context-field-addr=%p, "
683 "%specific-scontext-field-addr=%p, "
684 "%spayload-field-addr=%p, ",
685 PRFIELD(event
->frozen
),
686 PRFIELD(event
->header_field
?
687 event
->header_field
->field
: NULL
),
688 PRFIELD(event
->common_context_field
),
689 PRFIELD(event
->specific_context_field
),
690 PRFIELD(event
->payload_field
));
691 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
697 SET_TMP_PREFIX("event-class-");
698 format_event_class(buf_ch
, false, tmp_prefix
, event
->class);
699 stream_class
= bt_event_class_borrow_stream_class(event
->class);
701 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
702 SET_TMP_PREFIX("stream-class-");
703 format_stream_class(buf_ch
, false, tmp_prefix
,
706 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
708 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
709 SET_TMP_PREFIX("trace-");
710 format_trace(buf_ch
, false, tmp_prefix
, trace
);
714 if (event
->default_cv
) {
715 SET_TMP_PREFIX("default-cv-");
716 format_clock_value(buf_ch
, true, tmp_prefix
,
720 packet
= bt_event_borrow_packet(event
);
725 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet
));
726 SET_TMP_PREFIX("packet-");
727 format_packet(buf_ch
, false, tmp_prefix
, packet
);
728 stream
= bt_packet_borrow_stream(packet
);
733 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
734 SET_TMP_PREFIX("stream-");
735 format_stream(buf_ch
, false, tmp_prefix
, stream
);
738 static inline void format_clock_class(char **buf_ch
, bool extended
,
739 const char *prefix
, struct bt_clock_class
*clock_class
)
743 if (clock_class
->name
.value
) {
744 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class
->name
.value
));
747 BUF_APPEND(", %sfreq=%" PRIu64
, PRFIELD(clock_class
->frequency
));
753 if (clock_class
->description
.value
) {
754 BUF_APPEND(", %spartial-descr=\"%.32s\"",
755 PRFIELD(clock_class
->description
.value
));
758 if (clock_class
->uuid
.value
) {
759 BUF_APPEND_UUID(clock_class
->uuid
.value
);
762 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
763 "%soffset-s=%" PRId64
", "
764 "%soffset-cycles=%" PRIu64
", %sis-absolute=%d, "
765 "%sbase-offset-ns=%" PRId64
,
766 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
767 PRFIELD(clock_class
->offset_seconds
),
768 PRFIELD(clock_class
->offset_cycles
),
769 PRFIELD(clock_class
->is_absolute
),
770 PRFIELD(clock_class
->base_offset
.value_ns
));
772 SET_TMP_PREFIX("cv-pool-");
773 format_object_pool(buf_ch
, extended
, prefix
, &clock_class
->cv_pool
);
776 static inline void format_clock_value(char **buf_ch
, bool extended
,
777 const char *prefix
, struct bt_clock_value
*clock_value
)
780 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-origin=%" PRId64
,
781 PRFIELD(clock_value
->value_cycles
),
782 PRFIELD(clock_value
->ns_from_origin
));
788 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_value
->is_set
));
789 BUF_APPEND(", %sclock-class-addr=%p",
790 PRFIELD(clock_value
->clock_class
));
791 SET_TMP_PREFIX("clock-class-");
792 format_clock_class(buf_ch
, false, tmp_prefix
, clock_value
->clock_class
);
795 static inline void format_value(char **buf_ch
, bool extended
,
796 const char *prefix
, struct bt_value
*value
)
798 BUF_APPEND(", %stype=%s",
799 PRFIELD(bt_value_type_string(bt_value_get_type(value
))));
805 switch (bt_value_get_type(value
)) {
806 case BT_VALUE_TYPE_BOOL
:
810 (void) bt_value_bool_get(value
, &val
);
811 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
814 case BT_VALUE_TYPE_INTEGER
:
818 (void) bt_value_integer_get(value
, &val
);
819 BUF_APPEND(", %svalue=%" PRId64
, PRFIELD(val
));
822 case BT_VALUE_TYPE_FLOAT
:
826 (void) bt_value_float_get(value
, &val
);
827 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
830 case BT_VALUE_TYPE_STRING
:
834 (void) bt_value_string_get(value
, &val
);
835 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
838 case BT_VALUE_TYPE_ARRAY
:
840 int64_t count
= bt_value_array_size(value
);
842 BT_ASSERT(count
>= 0);
843 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
846 case BT_VALUE_TYPE_MAP
:
848 int64_t count
= bt_value_map_size(value
);
850 BT_ASSERT(count
>= 0);
851 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
859 static inline void format_notification(char **buf_ch
, bool extended
,
860 const char *prefix
, struct bt_notification
*notif
)
864 BUF_APPEND(", %stype=%s",
865 PRFIELD(bt_notification_type_string(notif
->type
)));
871 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
872 PRFIELD(notif
->frozen
), PRFIELD(notif
->graph
));
874 switch (notif
->type
) {
875 case BT_NOTIFICATION_TYPE_EVENT
:
877 struct bt_notification_event
*notif_event
= (void *) notif
;
879 SET_TMP_PREFIX("event-");
880 format_event(buf_ch
, true, tmp_prefix
, notif_event
->event
);
883 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
885 struct bt_notification_stream_begin
*notif_stream
=
888 SET_TMP_PREFIX("stream-");
889 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
892 case BT_NOTIFICATION_TYPE_STREAM_END
:
894 struct bt_notification_stream_end
*notif_stream
=
897 SET_TMP_PREFIX("stream-");
898 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
901 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
903 struct bt_notification_packet_begin
*notif_packet
=
906 SET_TMP_PREFIX("packet-");
907 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
910 case BT_NOTIFICATION_TYPE_PACKET_END
:
912 struct bt_notification_packet_end
*notif_packet
=
915 SET_TMP_PREFIX("packet-");
916 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
924 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
926 struct bt_plugin_so_shared_lib_handle
*handle
)
928 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
931 BUF_APPEND(", %spath=\"%s\"", PRFIELD(handle
->path
->str
));
935 static inline void format_component_class(char **buf_ch
, bool extended
,
936 const char *prefix
, struct bt_component_class
*comp_class
)
940 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
941 PRFIELD(bt_component_class_type_string(comp_class
->type
)),
942 PRFIELD(comp_class
->name
? comp_class
->name
->str
: NULL
));
944 if (comp_class
->description
) {
945 BUF_APPEND(", %spartial-descr=\"%.32s\"",
946 PRFIELD(comp_class
->description
->str
));
953 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
955 if (comp_class
->so_handle
) {
956 SET_TMP_PREFIX("so-handle-");
957 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
958 comp_class
->so_handle
);
962 static inline void format_component(char **buf_ch
, bool extended
,
963 const char *prefix
, struct bt_component
*component
)
967 BUF_APPEND(", %sname=\"%s\"", PRFIELD(component
->name
->str
));
968 SET_TMP_PREFIX("class-");
969 format_component_class(buf_ch
, extended
, tmp_prefix
, component
->class);
975 if (component
->input_ports
) {
976 BUF_APPEND(", %sinput-port-count=%u",
977 PRFIELD(component
->input_ports
->len
));
980 if (component
->output_ports
) {
981 BUF_APPEND(", %soutput-port-count=%u",
982 PRFIELD(component
->output_ports
->len
));
986 static inline void format_port(char **buf_ch
, bool extended
,
987 const char *prefix
, struct bt_port
*port
)
991 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
992 PRFIELD(bt_port_type_string(port
->type
)),
993 PRFIELD(port
->name
->str
));
999 if (port
->connection
) {
1000 SET_TMP_PREFIX("conn-");
1001 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1005 static inline void format_connection(char **buf_ch
, bool extended
,
1006 const char *prefix
, struct bt_connection
*connection
)
1008 char tmp_prefix
[64];
1014 if (connection
->upstream_port
) {
1015 SET_TMP_PREFIX("upstream-port-");
1016 format_port(buf_ch
, false, tmp_prefix
,
1017 connection
->upstream_port
);
1020 if (connection
->downstream_port
) {
1021 SET_TMP_PREFIX("downstream-port-");
1022 format_port(buf_ch
, false, tmp_prefix
,
1023 connection
->downstream_port
);
1027 static inline void format_graph(char **buf_ch
, bool extended
,
1028 const char *prefix
, struct bt_graph
*graph
)
1030 char tmp_prefix
[64];
1032 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph
->canceled
));
1038 if (graph
->components
) {
1039 BUF_APPEND(", %scomp-count=%u",
1040 PRFIELD(graph
->components
->len
));
1043 if (graph
->connections
) {
1044 BUF_APPEND(", %sconn-count=%u",
1045 PRFIELD(graph
->connections
->len
));
1048 SET_TMP_PREFIX("en-pool-");
1049 format_object_pool(buf_ch
, extended
, prefix
,
1050 &graph
->event_notif_pool
);
1051 SET_TMP_PREFIX("pbn-pool-");
1052 format_object_pool(buf_ch
, extended
, prefix
,
1053 &graph
->packet_begin_notif_pool
);
1054 SET_TMP_PREFIX("pen-pool-");
1055 format_object_pool(buf_ch
, extended
, prefix
,
1056 &graph
->packet_end_notif_pool
);
1059 static inline void format_notification_iterator(char **buf_ch
,
1060 bool extended
, const char *prefix
,
1061 struct bt_notification_iterator
*iterator
)
1064 char tmp_prefix
[64];
1066 if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
) {
1067 type
= "BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION";
1068 } else if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
) {
1069 type
= "BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT";
1074 BUF_APPEND(", %stype=%s", PRFIELD(type
));
1076 switch (iterator
->type
) {
1077 case BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
:
1079 struct bt_notification_iterator_private_connection
*
1080 iter_priv_conn
= (void *) iterator
;
1082 if (iter_priv_conn
->upstream_component
) {
1083 SET_TMP_PREFIX("upstream-comp-");
1084 format_component(buf_ch
, false, tmp_prefix
,
1085 iter_priv_conn
->upstream_component
);
1088 if (iter_priv_conn
->upstream_port
) {
1089 SET_TMP_PREFIX("upstream-port-");
1090 format_port(buf_ch
, false, tmp_prefix
,
1091 iter_priv_conn
->upstream_port
);
1094 if (iter_priv_conn
->connection
) {
1095 SET_TMP_PREFIX("upstream-conn-");
1096 format_connection(buf_ch
, false, tmp_prefix
,
1097 iter_priv_conn
->connection
);
1101 case BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
:
1103 struct bt_notification_iterator_output_port
*iter_output_port
=
1106 SET_TMP_PREFIX("graph-");
1107 format_graph(buf_ch
, false, tmp_prefix
,
1108 iter_output_port
->graph
);
1109 SET_TMP_PREFIX("colander-comp-");
1110 format_component(buf_ch
, false, tmp_prefix
,
1111 iter_output_port
->colander
);
1119 static inline void format_plugin(char **buf_ch
, bool extended
,
1120 const char *prefix
, struct bt_plugin
*plugin
)
1122 char tmp_prefix
[64];
1124 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1126 if (plugin
->info
.path_set
) {
1127 BUF_APPEND(", %spath=\"%s\"",
1128 PRFIELD(plugin
->info
.path
->str
));
1131 if (plugin
->info
.name_set
) {
1132 BUF_APPEND(", %sname=\"%s\"",
1133 PRFIELD(plugin
->info
.name
->str
));
1140 if (plugin
->info
.author_set
) {
1141 BUF_APPEND(", %sauthor=\"%s\"",
1142 PRFIELD(plugin
->info
.author
->str
));
1145 if (plugin
->info
.license_set
) {
1146 BUF_APPEND(", %slicense=\"%s\"",
1147 PRFIELD(plugin
->info
.license
->str
));
1150 if (plugin
->info
.version_set
) {
1151 BUF_APPEND(", %sversion=%u.%u.%u%s",
1152 PRFIELD(plugin
->info
.version
.major
),
1153 plugin
->info
.version
.minor
,
1154 plugin
->info
.version
.patch
,
1155 plugin
->info
.version
.extra
?
1156 plugin
->info
.version
.extra
->str
: "");
1159 BUF_APPEND(", %sis-frozen=%d, %scomp-class-count=%u",
1160 PRFIELD(plugin
->frozen
),
1161 PRFIELD(plugin
->comp_classes
->len
));
1163 if (plugin
->spec_data
) {
1164 struct bt_plugin_so_spec_data
*spec_data
=
1165 (void *) plugin
->spec_data
;
1167 if (spec_data
->shared_lib_handle
) {
1168 SET_TMP_PREFIX("so-handle-");
1169 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1170 spec_data
->shared_lib_handle
);
1175 static inline void handle_conversion_specifier_bt(void *priv_data
,
1176 char **buf_ch
, size_t avail_size
,
1177 const char **out_fmt_ch
, va_list *args
)
1179 const char *fmt_ch
= *out_fmt_ch
;
1180 bool extended
= false;
1182 char *prefix_ch
= prefix
;
1188 if (*fmt_ch
== 'u') {
1190 obj
= va_arg(*args
, void *);
1191 format_uuid(buf_ch
, obj
);
1195 if (*fmt_ch
== '[') {
1200 if (*fmt_ch
== ']') {
1206 *prefix_ch
= *fmt_ch
;
1214 if (*fmt_ch
== '+') {
1219 obj
= va_arg(*args
, void *);
1220 BUF_APPEND("%saddr=%p", prefix
, obj
);
1228 format_field_type(buf_ch
, extended
, prefix
, obj
);
1231 format_field(buf_ch
, extended
, prefix
, obj
);
1234 format_field_path(buf_ch
, extended
, prefix
, obj
);
1237 format_event_class(buf_ch
, extended
, prefix
, obj
);
1240 format_event(buf_ch
, extended
, prefix
, obj
);
1243 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1246 format_stream(buf_ch
, extended
, prefix
, obj
);
1249 format_packet(buf_ch
, extended
, prefix
, obj
);
1252 format_trace(buf_ch
, extended
, prefix
, obj
);
1255 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1258 format_clock_value(buf_ch
, extended
, prefix
, obj
);
1261 format_value(buf_ch
, extended
, prefix
, obj
);
1264 format_notification(buf_ch
, extended
, prefix
, obj
);
1267 format_notification_iterator(buf_ch
, extended
, prefix
, obj
);
1270 format_component_class(buf_ch
, extended
, prefix
, obj
);
1273 format_component(buf_ch
, extended
, prefix
, obj
);
1276 format_port(buf_ch
, extended
, prefix
, obj
);
1279 format_connection(buf_ch
, extended
, prefix
, obj
);
1282 format_plugin(buf_ch
, extended
, prefix
, obj
);
1285 format_graph(buf_ch
, extended
, prefix
, obj
);
1288 format_object_pool(buf_ch
, extended
, prefix
, obj
);
1291 format_object(buf_ch
, extended
, prefix
, obj
);
1299 *out_fmt_ch
= fmt_ch
;
1303 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1304 int lvl
, const char *tag
, const char *fmt
, ...)
1309 va_start(args
, fmt
);
1310 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1311 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1313 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);