2 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define BT_LOG_TAG "LIB-LOGGING"
33 #include <babeltrace/common-internal.h>
34 #include <babeltrace/lib-logging-internal.h>
35 #include <babeltrace/values-internal.h>
36 #include <babeltrace/values-internal.h>
37 #include <babeltrace/object-pool-internal.h>
38 #include <babeltrace/trace-ir/field-classes-internal.h>
39 #include <babeltrace/trace-ir/fields-internal.h>
40 #include <babeltrace/trace-ir/event-class-internal.h>
41 #include <babeltrace/trace-ir/event-internal.h>
42 #include <babeltrace/trace-ir/packet-internal.h>
43 #include <babeltrace/trace-ir/stream-class-internal.h>
44 #include <babeltrace/trace-ir/stream-internal.h>
45 #include <babeltrace/trace-ir/trace-internal.h>
46 #include <babeltrace/trace-ir/clock-class-internal.h>
47 #include <babeltrace/trace-ir/clock-value-internal.h>
48 #include <babeltrace/trace-ir/field-path-internal.h>
49 #include <babeltrace/trace-ir/utils-internal.h>
50 #include <babeltrace/graph/component-class-internal.h>
51 #include <babeltrace/graph/component-class-sink-colander-internal.h>
52 #include <babeltrace/graph/component-filter-internal.h>
53 #include <babeltrace/graph/component-internal.h>
54 #include <babeltrace/graph/component-sink-internal.h>
55 #include <babeltrace/graph/component-source-internal.h>
56 #include <babeltrace/graph/connection-internal.h>
57 #include <babeltrace/graph/graph-internal.h>
58 #include <babeltrace/graph/notification-event-internal.h>
59 #include <babeltrace/graph/notification-inactivity-internal.h>
60 #include <babeltrace/graph/notification-internal.h>
61 #include <babeltrace/graph/notification-iterator-internal.h>
62 #include <babeltrace/graph/notification-packet-internal.h>
63 #include <babeltrace/graph/notification-stream-internal.h>
64 #include <babeltrace/graph/port-internal.h>
65 #include <babeltrace/plugin/plugin-internal.h>
66 #include <babeltrace/plugin/plugin-so-internal.h>
68 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
70 static char __thread lib_logging_buf
[LIB_LOGGING_BUF_SIZE
];
72 #define BUF_APPEND(_fmt, ...) \
75 size_t _size = LIB_LOGGING_BUF_SIZE - \
76 (size_t) (*buf_ch - lib_logging_buf); \
77 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
78 BT_ASSERT(_count >= 0); \
79 *buf_ch += MIN(_count, _size); \
80 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
85 #define BUF_APPEND_UUID(_uuid) \
87 BUF_APPEND(", %suuid=", prefix); \
88 format_uuid(buf_ch, (_uuid)); \
91 #define PRFIELD(_expr) prefix, (_expr)
93 #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL)
95 #define SET_TMP_PREFIX(_prefix2) \
97 strcpy(tmp_prefix, prefix); \
98 strcat(tmp_prefix, (_prefix2)); \
101 static inline void format_component(char **buf_ch
, bool extended
,
102 const char *prefix
, struct bt_component
*component
);
104 static inline void format_port(char **buf_ch
, bool extended
,
105 const char *prefix
, struct bt_port
*port
);
107 static inline void format_connection(char **buf_ch
, bool extended
,
108 const char *prefix
, struct bt_connection
*connection
);
110 static inline void format_clock_value(char **buf_ch
, bool extended
,
111 const char *prefix
, struct bt_clock_value
*clock_value
);
113 static inline void format_field_path(char **buf_ch
, bool extended
,
114 const char *prefix
, struct bt_field_path
*field_path
);
116 static inline void format_object(char **buf_ch
, bool extended
,
117 const char *prefix
, struct bt_object
*obj
)
119 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
122 static inline void format_uuid(char **buf_ch
, bt_uuid uuid
)
124 BUF_APPEND("\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
125 (unsigned int) uuid
[0],
126 (unsigned int) uuid
[1],
127 (unsigned int) uuid
[2],
128 (unsigned int) uuid
[3],
129 (unsigned int) uuid
[4],
130 (unsigned int) uuid
[5],
131 (unsigned int) uuid
[6],
132 (unsigned int) uuid
[7],
133 (unsigned int) uuid
[8],
134 (unsigned int) uuid
[9],
135 (unsigned int) uuid
[10],
136 (unsigned int) uuid
[11],
137 (unsigned int) uuid
[12],
138 (unsigned int) uuid
[13],
139 (unsigned int) uuid
[14],
140 (unsigned int) uuid
[15]);
143 static inline void format_object_pool(char **buf_ch
, bool extended
,
144 const char *prefix
, struct bt_object_pool
*pool
)
146 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
149 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
153 static inline void format_integer_field_class(char **buf_ch
,
154 bool extended
, const char *prefix
,
155 struct bt_field_class
*field_class
)
157 struct bt_field_class_integer
*int_fc
= (void *) field_class
;
159 BUF_APPEND(", %srange-size=%" PRIu64
", %sbase=%s",
160 PRFIELD(int_fc
->range
),
161 PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc
->base
)));
164 static inline void format_array_field_class(char **buf_ch
,
165 bool extended
, const char *prefix
,
166 struct bt_field_class
*field_class
)
168 struct bt_field_class_array
*array_fc
= (void *) field_class
;
170 BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s",
171 PRFIELD(array_fc
->element_fc
),
172 PRFIELD(bt_common_field_class_type_string(array_fc
->element_fc
->type
)));
175 static inline void format_field_class(char **buf_ch
, bool extended
,
176 const char *prefix
, struct bt_field_class
*field_class
)
180 BUF_APPEND(", %stype=%s",
181 PRFIELD(bt_common_field_class_type_string(field_class
->type
)));
184 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class
->frozen
));
185 BUF_APPEND(", %sis-part-of-trace=%d",
186 PRFIELD(field_class
->part_of_trace
));
191 switch (field_class
->type
) {
192 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
193 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
195 format_integer_field_class(buf_ch
, extended
, prefix
, field_class
);
198 case BT_FIELD_CLASS_TYPE_REAL
:
200 struct bt_field_class_real
*real_fc
= (void *) field_class
;
202 BUF_APPEND(", %sis-single-precision=%d",
203 PRFIELD(real_fc
->is_single_precision
));
206 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
207 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
209 struct bt_field_class_enumeration
*enum_fc
=
210 (void *) field_class
;
212 format_integer_field_class(buf_ch
, extended
, prefix
, field_class
);
213 BUF_APPEND(", %smapping-count=%u",
214 PRFIELD(enum_fc
->mappings
->len
));
217 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
219 struct bt_field_class_structure
*struct_fc
=
220 (void *) field_class
;
222 if (struct_fc
->common
.named_fcs
) {
223 BUF_APPEND(", %smember-count=%u",
224 PRFIELD(struct_fc
->common
.named_fcs
->len
));
229 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
231 struct bt_field_class_static_array
*array_fc
=
232 (void *) field_class
;
234 format_array_field_class(buf_ch
, extended
, prefix
, field_class
);
235 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_fc
->length
));
238 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
240 struct bt_field_class_dynamic_array
*array_fc
=
241 (void *) field_class
;
243 format_array_field_class(buf_ch
, extended
, prefix
, field_class
);
245 if (array_fc
->length_fc
) {
246 SET_TMP_PREFIX("length-fc-");
247 format_field_class(buf_ch
, extended
, tmp_prefix
,
248 array_fc
->length_fc
);
251 if (array_fc
->length_field_path
) {
252 SET_TMP_PREFIX("length-field-path-");
253 format_field_path(buf_ch
, extended
, tmp_prefix
,
254 array_fc
->length_field_path
);
259 case BT_FIELD_CLASS_TYPE_VARIANT
:
261 struct bt_field_class_variant
*var_fc
= (void *) field_class
;
263 if (var_fc
->common
.named_fcs
) {
264 BUF_APPEND(", %soption-count=%u",
265 PRFIELD(var_fc
->common
.named_fcs
->len
));
268 if (var_fc
->selector_fc
) {
269 SET_TMP_PREFIX("selector-fc-");
270 format_field_class(buf_ch
, extended
, tmp_prefix
,
271 var_fc
->selector_fc
);
274 if (var_fc
->selector_field_path
) {
275 SET_TMP_PREFIX("selector-field-path-");
276 format_field_path(buf_ch
, extended
, tmp_prefix
,
277 var_fc
->selector_field_path
);
287 static inline void format_field_integer_extended(char **buf_ch
,
288 const char *prefix
, struct bt_field
*field
)
290 struct bt_field_integer
*integer
= (void *) field
;
291 struct bt_field_class_integer
*field_class
= (void *) field
->class;
292 const char *fmt
= NULL
;
294 BT_ASSERT(field_class
);
296 if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
) {
297 fmt
= ", %svalue=%" PRIo64
;
298 } else if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
) {
299 fmt
= ", %svalue=%" PRIx64
;
302 if (field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
303 field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
305 fmt
= ", %svalue=%" PRId64
;
308 BUF_APPEND(fmt
, PRFIELD(integer
->value
.i
));
311 fmt
= ", %svalue=%" PRIu64
;
314 BUF_APPEND(fmt
, PRFIELD(integer
->value
.u
));
318 static inline void format_field(char **buf_ch
, bool extended
,
319 const char *prefix
, struct bt_field
*field
)
321 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->is_set
));
324 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
327 BUF_APPEND(", %sclass-addr=%p", PRFIELD(field
->class));
333 BUF_APPEND(", %sclass-type=%s",
334 PRFIELD(bt_common_field_class_type_string(field
->class->type
)));
336 if (!extended
|| !field
->is_set
) {
340 switch (field
->class->type
) {
341 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
342 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
343 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
344 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
346 format_field_integer_extended(buf_ch
, prefix
, field
);
349 case BT_FIELD_CLASS_TYPE_REAL
:
351 struct bt_field_real
*real_field
= (void *) field
;
353 BUF_APPEND(", %svalue=%f", PRFIELD(real_field
->value
));
356 case BT_FIELD_CLASS_TYPE_STRING
:
358 struct bt_field_string
*str
= (void *) field
;
361 BT_ASSERT(str
->buf
->data
);
362 BUF_APPEND(", %spartial-value=\"%.32s\"",
363 PRFIELD(str
->buf
->data
));
368 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
369 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
371 struct bt_field_array
*array_field
= (void *) field
;
373 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_field
->length
));
375 if (array_field
->fields
) {
376 BUF_APPEND(", %sallocated-length=%u",
377 PRFIELD(array_field
->fields
->len
));
382 case BT_FIELD_CLASS_TYPE_VARIANT
:
384 struct bt_field_variant
*var_field
= (void *) field
;
386 BUF_APPEND(", %sselected-field-index=%" PRIu64
,
387 PRFIELD(var_field
->selected_index
));
395 static inline void format_field_path(char **buf_ch
, bool extended
,
396 const char *prefix
, struct bt_field_path
*field_path
)
400 if (field_path
->indexes
) {
401 BT_ASSERT(field_path
->indexes
);
402 BUF_APPEND(", %sindex-count=%u",
403 PRFIELD(field_path
->indexes
->len
));
406 if (!extended
|| !field_path
->indexes
) {
410 BUF_APPEND(", %spath=[%s",
411 PRFIELD(bt_common_scope_string(field_path
->root
)));
413 for (i
= 0; i
< field_path
->indexes
->len
; i
++) {
414 uint64_t index
= bt_field_path_get_index_by_index_inline(
417 BUF_APPEND(", %" PRIu64
, index
);
420 BUF_APPEND("%s", "]");
423 static inline void format_trace(char **buf_ch
, bool extended
,
424 const char *prefix
, struct bt_trace
*trace
)
428 if (trace
->name
.value
) {
429 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
.value
));
436 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
438 if (trace
->uuid
.value
) {
439 BUF_APPEND_UUID(trace
->uuid
.value
);
442 if (trace
->stream_classes
) {
443 BUF_APPEND(", %sstream-class-count=%u",
444 PRFIELD(trace
->stream_classes
->len
));
447 if (trace
->streams
) {
448 BUF_APPEND(", %sstream-count=%u",
449 PRFIELD(trace
->streams
->len
));
452 BUF_APPEND(", %spacket-header-fc-addr=%p, %sis-static=%d, "
453 "%sassigns-auto-sc-id=%d",
454 PRFIELD(trace
->packet_header_fc
),
455 PRFIELD(trace
->is_static
),
456 PRFIELD(trace
->assigns_automatic_stream_class_id
));
457 SET_TMP_PREFIX("phf-pool-");
458 format_object_pool(buf_ch
, extended
, prefix
,
459 &trace
->packet_header_field_pool
);
462 static inline void format_stream_class(char **buf_ch
, bool extended
,
463 const char *prefix
, struct bt_stream_class
*stream_class
)
465 struct bt_trace
*trace
;
468 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream_class
->id
));
470 if (stream_class
->name
.value
) {
471 BUF_APPEND(", %sname=\"%s\"",
472 PRFIELD(stream_class
->name
.value
));
479 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
481 if (stream_class
->event_classes
) {
482 BUF_APPEND(", %sevent-class-count=%u",
483 PRFIELD(stream_class
->event_classes
->len
));
486 BUF_APPEND(", %spacket-context-fc-addr=%p, "
487 "%sevent-header-fc-addr=%p, %sevent-common-context-fc-addr=%p",
488 PRFIELD(stream_class
->packet_context_fc
),
489 PRFIELD(stream_class
->event_header_fc
),
490 PRFIELD(stream_class
->event_common_context_fc
));
491 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
496 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
497 "%spackets-have-discarded-ev-counter-snapshot=%d, "
498 "%spackets-have-packet-counter-snapshot=%d, "
499 "%spackets-have-default-begin-cv=%d, "
500 "%spackets-have-default-end-cv=%d",
501 PRFIELD(stream_class
->assigns_automatic_event_class_id
),
502 PRFIELD(stream_class
->assigns_automatic_stream_id
),
503 PRFIELD(stream_class
->packets_have_discarded_event_counter_snapshot
),
504 PRFIELD(stream_class
->packets_have_packet_counter_snapshot
),
505 PRFIELD(stream_class
->packets_have_default_beginning_cv
),
506 PRFIELD(stream_class
->packets_have_default_end_cv
));
507 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
508 SET_TMP_PREFIX("trace-");
509 format_trace(buf_ch
, false, tmp_prefix
, trace
);
510 SET_TMP_PREFIX("ehf-pool-");
511 format_object_pool(buf_ch
, extended
, prefix
,
512 &stream_class
->event_header_field_pool
);
513 SET_TMP_PREFIX("pcf-pool-");
514 format_object_pool(buf_ch
, extended
, prefix
,
515 &stream_class
->packet_context_field_pool
);
518 static inline void format_event_class(char **buf_ch
, bool extended
,
519 const char *prefix
, struct bt_event_class
*event_class
)
521 struct bt_stream_class
*stream_class
;
522 struct bt_trace
*trace
;
525 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(event_class
->id
));
527 if (event_class
->name
.value
) {
528 BUF_APPEND(", %sname=\"%s\"",
529 PRFIELD(event_class
->name
.value
));
536 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class
->frozen
));
538 if (event_class
->log_level
.base
.avail
) {
539 BUF_APPEND(", %slog-level=%s",
540 PRFIELD(bt_common_event_class_log_level_string(
541 (int) event_class
->log_level
.value
)));
544 if (event_class
->emf_uri
.value
) {
545 BUF_APPEND(", %semf-uri=\"%s\"",
546 PRFIELD(event_class
->emf_uri
.value
));
549 BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
550 PRFIELD(event_class
->specific_context_fc
),
551 PRFIELD(event_class
->payload_fc
));
553 stream_class
= bt_event_class_borrow_stream_class(event_class
);
558 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
559 SET_TMP_PREFIX("stream-class-");
560 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
561 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
566 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
567 SET_TMP_PREFIX("trace-");
568 format_trace(buf_ch
, false, tmp_prefix
, trace
);
569 SET_TMP_PREFIX("event-pool-");
570 format_object_pool(buf_ch
, extended
, prefix
, &event_class
->event_pool
);
573 static inline void format_stream(char **buf_ch
, bool extended
,
574 const char *prefix
, struct bt_stream
*stream
)
576 struct bt_stream_class
*stream_class
;
577 struct bt_trace
*trace
;
580 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream
->id
));
582 if (stream
->name
.value
) {
583 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
.value
));
590 stream_class
= bt_stream_borrow_class(stream
);
595 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
596 SET_TMP_PREFIX("stream-class-");
597 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
598 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
603 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
604 SET_TMP_PREFIX("trace-");
605 format_trace(buf_ch
, false, tmp_prefix
, trace
);
606 SET_TMP_PREFIX("packet-pool-");
607 format_object_pool(buf_ch
, extended
, prefix
, &stream
->packet_pool
);
610 static inline void format_packet(char **buf_ch
, bool extended
,
611 const char *prefix
, struct bt_packet
*packet
)
613 struct bt_stream
*stream
;
614 struct bt_trace
*trace
;
621 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
622 "%scontext-field-addr=%p",
623 PRFIELD(packet
->frozen
),
624 PRFIELD(packet
->header_field
? packet
->header_field
->field
: NULL
),
625 PRFIELD(packet
->context_field
? packet
->context_field
->field
: NULL
));
626 stream
= bt_packet_borrow_stream(packet
);
631 if (packet
->default_beginning_cv
) {
632 SET_TMP_PREFIX("default-begin-cv-");
633 format_clock_value(buf_ch
, true, tmp_prefix
,
634 packet
->default_beginning_cv
);
637 if (packet
->default_end_cv
) {
638 SET_TMP_PREFIX("default-end-cv-");
639 format_clock_value(buf_ch
, true, tmp_prefix
,
640 packet
->default_end_cv
);
643 if (packet
->discarded_event_counter_snapshot
.base
.avail
) {
644 BUF_APPEND(", %sdiscarded-ev-counter-snapshot=%" PRIu64
,
645 PRFIELD(packet
->discarded_event_counter_snapshot
.value
));
648 if (packet
->packet_counter_snapshot
.base
.avail
) {
649 BUF_APPEND(", %spacket-counter-snapshot=%" PRIu64
,
650 PRFIELD(packet
->packet_counter_snapshot
.value
));
653 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
654 SET_TMP_PREFIX("stream-");
655 format_stream(buf_ch
, false, tmp_prefix
, stream
);
656 trace
= (struct bt_trace
*) bt_object_borrow_parent(&stream
->base
);
661 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
662 SET_TMP_PREFIX("trace-");
663 format_trace(buf_ch
, false, tmp_prefix
, trace
);
666 static inline void format_event(char **buf_ch
, bool extended
,
667 const char *prefix
, struct bt_event
*event
)
669 struct bt_packet
*packet
;
670 struct bt_stream
*stream
;
671 struct bt_trace
*trace
;
672 struct bt_stream_class
*stream_class
;
679 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
680 "%scommon-context-field-addr=%p, "
681 "%sspecific-context-field-addr=%p, "
682 "%spayload-field-addr=%p, ",
683 PRFIELD(event
->frozen
),
684 PRFIELD(event
->header_field
?
685 event
->header_field
->field
: NULL
),
686 PRFIELD(event
->common_context_field
),
687 PRFIELD(event
->specific_context_field
),
688 PRFIELD(event
->payload_field
));
689 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
695 SET_TMP_PREFIX("event-class-");
696 format_event_class(buf_ch
, false, tmp_prefix
, event
->class);
697 stream_class
= bt_event_class_borrow_stream_class(event
->class);
699 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
700 SET_TMP_PREFIX("stream-class-");
701 format_stream_class(buf_ch
, false, tmp_prefix
,
704 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
706 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
707 SET_TMP_PREFIX("trace-");
708 format_trace(buf_ch
, false, tmp_prefix
, trace
);
712 if (event
->default_cv
) {
713 SET_TMP_PREFIX("default-cv-");
714 format_clock_value(buf_ch
, true, tmp_prefix
,
718 packet
= bt_event_borrow_packet(event
);
723 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet
));
724 SET_TMP_PREFIX("packet-");
725 format_packet(buf_ch
, false, tmp_prefix
, packet
);
726 stream
= bt_packet_borrow_stream(packet
);
731 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
732 SET_TMP_PREFIX("stream-");
733 format_stream(buf_ch
, false, tmp_prefix
, stream
);
736 static inline void format_clock_class(char **buf_ch
, bool extended
,
737 const char *prefix
, struct bt_clock_class
*clock_class
)
741 if (clock_class
->name
.value
) {
742 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class
->name
.value
));
745 BUF_APPEND(", %sfreq=%" PRIu64
, PRFIELD(clock_class
->frequency
));
751 if (clock_class
->description
.value
) {
752 BUF_APPEND(", %spartial-descr=\"%.32s\"",
753 PRFIELD(clock_class
->description
.value
));
756 if (clock_class
->uuid
.value
) {
757 BUF_APPEND_UUID(clock_class
->uuid
.value
);
760 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
761 "%soffset-s=%" PRId64
", "
762 "%soffset-cycles=%" PRIu64
", %sis-absolute=%d, "
763 "%sbase-offset-ns=%" PRId64
,
764 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
765 PRFIELD(clock_class
->offset_seconds
),
766 PRFIELD(clock_class
->offset_cycles
),
767 PRFIELD(clock_class
->is_absolute
),
768 PRFIELD(clock_class
->base_offset
.value_ns
));
770 SET_TMP_PREFIX("cv-pool-");
771 format_object_pool(buf_ch
, extended
, prefix
, &clock_class
->cv_pool
);
774 static inline void format_clock_value(char **buf_ch
, bool extended
,
775 const char *prefix
, struct bt_clock_value
*clock_value
)
778 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-origin=%" PRId64
,
779 PRFIELD(clock_value
->value_cycles
),
780 PRFIELD(clock_value
->ns_from_origin
));
786 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_value
->is_set
));
788 if (clock_value
->clock_class
) {
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
,
793 clock_value
->clock_class
);
797 static inline void format_value(char **buf_ch
, bool extended
,
798 const char *prefix
, struct bt_value
*value
)
800 BUF_APPEND(", %stype=%s",
801 PRFIELD(bt_common_value_type_string(bt_value_get_type(value
))));
807 switch (bt_value_get_type(value
)) {
808 case BT_VALUE_TYPE_BOOL
:
810 bt_bool val
= bt_value_bool_get(value
);
812 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
815 case BT_VALUE_TYPE_INTEGER
:
817 int64_t val
= bt_value_integer_get(value
);
819 BUF_APPEND(", %svalue=%" PRId64
, PRFIELD(val
));
822 case BT_VALUE_TYPE_REAL
:
824 double val
= bt_value_real_get(value
);
826 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
829 case BT_VALUE_TYPE_STRING
:
831 const char *val
= bt_value_string_get(value
);
833 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
836 case BT_VALUE_TYPE_ARRAY
:
838 int64_t count
= bt_value_array_get_size(value
);
840 BT_ASSERT(count
>= 0);
841 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
844 case BT_VALUE_TYPE_MAP
:
846 int64_t count
= bt_value_map_get_size(value
);
848 BT_ASSERT(count
>= 0);
849 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
857 static inline void format_notification(char **buf_ch
, bool extended
,
858 const char *prefix
, struct bt_notification
*notif
)
862 BUF_APPEND(", %stype=%s",
863 PRFIELD(bt_notification_type_string(notif
->type
)));
869 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
870 PRFIELD(notif
->frozen
), PRFIELD(notif
->graph
));
872 switch (notif
->type
) {
873 case BT_NOTIFICATION_TYPE_EVENT
:
875 struct bt_notification_event
*notif_event
= (void *) notif
;
877 if (notif_event
->event
) {
878 SET_TMP_PREFIX("event-");
879 format_event(buf_ch
, true, tmp_prefix
, notif_event
->event
);
884 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
886 struct bt_notification_stream_begin
*notif_stream
=
889 if (notif_stream
->stream
) {
890 SET_TMP_PREFIX("stream-");
891 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
896 case BT_NOTIFICATION_TYPE_STREAM_END
:
898 struct bt_notification_stream_end
*notif_stream
=
901 if (notif_stream
->stream
) {
902 SET_TMP_PREFIX("stream-");
903 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
908 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
910 struct bt_notification_packet_begin
*notif_packet
=
913 if (notif_packet
->packet
) {
914 SET_TMP_PREFIX("packet-");
915 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
920 case BT_NOTIFICATION_TYPE_PACKET_END
:
922 struct bt_notification_packet_end
*notif_packet
=
925 if (notif_packet
->packet
) {
926 SET_TMP_PREFIX("packet-");
927 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
937 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
939 struct bt_plugin_so_shared_lib_handle
*handle
)
941 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
944 BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle
->path
));
948 static inline void format_component_class(char **buf_ch
, bool extended
,
949 const char *prefix
, struct bt_component_class
*comp_class
)
953 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
954 PRFIELD(bt_component_class_type_string(comp_class
->type
)),
955 PRFIELD_GSTRING(comp_class
->name
));
957 if (comp_class
->description
) {
958 BUF_APPEND(", %spartial-descr=\"%.32s\"",
959 PRFIELD_GSTRING(comp_class
->description
));
966 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
968 if (comp_class
->so_handle
) {
969 SET_TMP_PREFIX("so-handle-");
970 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
971 comp_class
->so_handle
);
975 static inline void format_component(char **buf_ch
, bool extended
,
976 const char *prefix
, struct bt_component
*component
)
980 BUF_APPEND(", %sname=\"%s\"",
981 PRFIELD_GSTRING(component
->name
));
983 if (component
->class) {
984 SET_TMP_PREFIX("class-");
985 format_component_class(buf_ch
, extended
, tmp_prefix
,
993 if (component
->input_ports
) {
994 BUF_APPEND(", %sinput-port-count=%u",
995 PRFIELD(component
->input_ports
->len
));
998 if (component
->output_ports
) {
999 BUF_APPEND(", %soutput-port-count=%u",
1000 PRFIELD(component
->output_ports
->len
));
1004 static inline void format_port(char **buf_ch
, bool extended
,
1005 const char *prefix
, struct bt_port
*port
)
1007 char tmp_prefix
[64];
1009 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1010 PRFIELD(bt_port_type_string(port
->type
)),
1011 PRFIELD_GSTRING(port
->name
));
1017 if (port
->connection
) {
1018 SET_TMP_PREFIX("conn-");
1019 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1023 static inline void format_connection(char **buf_ch
, bool extended
,
1024 const char *prefix
, struct bt_connection
*connection
)
1026 char tmp_prefix
[64];
1032 if (connection
->upstream_port
) {
1033 SET_TMP_PREFIX("upstream-port-");
1034 format_port(buf_ch
, false, tmp_prefix
,
1035 connection
->upstream_port
);
1038 if (connection
->downstream_port
) {
1039 SET_TMP_PREFIX("downstream-port-");
1040 format_port(buf_ch
, false, tmp_prefix
,
1041 connection
->downstream_port
);
1045 static inline void format_graph(char **buf_ch
, bool extended
,
1046 const char *prefix
, struct bt_graph
*graph
)
1048 char tmp_prefix
[64];
1050 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph
->canceled
));
1056 if (graph
->components
) {
1057 BUF_APPEND(", %scomp-count=%u",
1058 PRFIELD(graph
->components
->len
));
1061 if (graph
->connections
) {
1062 BUF_APPEND(", %sconn-count=%u",
1063 PRFIELD(graph
->connections
->len
));
1066 SET_TMP_PREFIX("en-pool-");
1067 format_object_pool(buf_ch
, extended
, prefix
,
1068 &graph
->event_notif_pool
);
1069 SET_TMP_PREFIX("pbn-pool-");
1070 format_object_pool(buf_ch
, extended
, prefix
,
1071 &graph
->packet_begin_notif_pool
);
1072 SET_TMP_PREFIX("pen-pool-");
1073 format_object_pool(buf_ch
, extended
, prefix
,
1074 &graph
->packet_end_notif_pool
);
1077 static inline void format_notification_iterator(char **buf_ch
,
1078 bool extended
, const char *prefix
,
1079 struct bt_notification_iterator
*iterator
)
1082 char tmp_prefix
[64];
1084 if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
) {
1085 type
= "BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT";
1086 } else if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT
) {
1087 type
= "BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT";
1092 BUF_APPEND(", %stype=%s", PRFIELD(type
));
1094 switch (iterator
->type
) {
1095 case BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
:
1097 struct bt_self_component_port_input_notification_iterator
*
1098 port_in_iter
= (void *) iterator
;
1100 if (port_in_iter
->upstream_component
) {
1101 SET_TMP_PREFIX("upstream-comp-");
1102 format_component(buf_ch
, false, tmp_prefix
,
1103 port_in_iter
->upstream_component
);
1106 if (port_in_iter
->upstream_port
) {
1107 SET_TMP_PREFIX("upstream-port-");
1108 format_port(buf_ch
, false, tmp_prefix
,
1109 port_in_iter
->upstream_port
);
1112 if (port_in_iter
->connection
) {
1113 SET_TMP_PREFIX("upstream-conn-");
1114 format_connection(buf_ch
, false, tmp_prefix
,
1115 port_in_iter
->connection
);
1119 case BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT
:
1121 struct bt_port_output_notification_iterator
*port_out_iter
=
1124 if (port_out_iter
->graph
) {
1125 SET_TMP_PREFIX("graph-");
1126 format_graph(buf_ch
, false, tmp_prefix
,
1127 port_out_iter
->graph
);
1130 if (port_out_iter
->colander
) {
1131 SET_TMP_PREFIX("colander-comp-");
1132 format_component(buf_ch
, false, tmp_prefix
,
1133 (void *) port_out_iter
->colander
);
1143 static inline void format_plugin(char **buf_ch
, bool extended
,
1144 const char *prefix
, const struct bt_plugin
*plugin
)
1146 char tmp_prefix
[64];
1148 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1150 if (plugin
->info
.path_set
) {
1151 BUF_APPEND(", %spath=\"%s\"",
1152 PRFIELD_GSTRING(plugin
->info
.path
));
1155 if (plugin
->info
.name_set
) {
1156 BUF_APPEND(", %sname=\"%s\"",
1157 PRFIELD_GSTRING(plugin
->info
.name
));
1164 if (plugin
->info
.author_set
) {
1165 BUF_APPEND(", %sauthor=\"%s\"",
1166 PRFIELD_GSTRING(plugin
->info
.author
));
1169 if (plugin
->info
.license_set
) {
1170 BUF_APPEND(", %slicense=\"%s\"",
1171 PRFIELD_GSTRING(plugin
->info
.license
));
1174 if (plugin
->info
.version_set
) {
1175 BUF_APPEND(", %sversion=%u.%u.%u%s",
1176 PRFIELD(plugin
->info
.version
.major
),
1177 plugin
->info
.version
.minor
,
1178 plugin
->info
.version
.patch
,
1179 plugin
->info
.version
.extra
?
1180 plugin
->info
.version
.extra
->str
: "");
1183 BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, "
1184 "%ssink-comp-class-count=%u",
1185 PRFIELD(plugin
->src_comp_classes
->len
),
1186 PRFIELD(plugin
->flt_comp_classes
->len
),
1187 PRFIELD(plugin
->sink_comp_classes
->len
));
1189 if (plugin
->spec_data
) {
1190 struct bt_plugin_so_spec_data
*spec_data
=
1191 (void *) plugin
->spec_data
;
1193 if (spec_data
->shared_lib_handle
) {
1194 SET_TMP_PREFIX("so-handle-");
1195 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1196 spec_data
->shared_lib_handle
);
1201 static inline void handle_conversion_specifier_bt(void *priv_data
,
1202 char **buf_ch
, size_t avail_size
,
1203 const char **out_fmt_ch
, va_list *args
)
1205 const char *fmt_ch
= *out_fmt_ch
;
1206 bool extended
= false;
1208 char *prefix_ch
= prefix
;
1214 if (*fmt_ch
== 'u') {
1216 obj
= va_arg(*args
, void *);
1217 format_uuid(buf_ch
, obj
);
1221 if (*fmt_ch
== '[') {
1226 if (*fmt_ch
== ']') {
1232 *prefix_ch
= *fmt_ch
;
1240 if (*fmt_ch
== '+') {
1245 obj
= va_arg(*args
, void *);
1246 BUF_APPEND("%saddr=%p", prefix
, obj
);
1254 format_field_class(buf_ch
, extended
, prefix
, obj
);
1257 format_field(buf_ch
, extended
, prefix
, obj
);
1260 format_field_path(buf_ch
, extended
, prefix
, obj
);
1263 format_event_class(buf_ch
, extended
, prefix
, obj
);
1266 format_event(buf_ch
, extended
, prefix
, obj
);
1269 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1272 format_stream(buf_ch
, extended
, prefix
, obj
);
1275 format_packet(buf_ch
, extended
, prefix
, obj
);
1278 format_trace(buf_ch
, extended
, prefix
, obj
);
1281 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1284 format_clock_value(buf_ch
, extended
, prefix
, obj
);
1287 format_value(buf_ch
, extended
, prefix
, obj
);
1290 format_notification(buf_ch
, extended
, prefix
, obj
);
1293 format_notification_iterator(buf_ch
, extended
, prefix
, obj
);
1296 format_component_class(buf_ch
, extended
, prefix
, obj
);
1299 format_component(buf_ch
, extended
, prefix
, obj
);
1302 format_port(buf_ch
, extended
, prefix
, obj
);
1305 format_connection(buf_ch
, extended
, prefix
, obj
);
1308 format_plugin(buf_ch
, extended
, prefix
, obj
);
1311 format_graph(buf_ch
, extended
, prefix
, obj
);
1314 format_object_pool(buf_ch
, extended
, prefix
, obj
);
1317 format_object(buf_ch
, extended
, prefix
, obj
);
1325 *out_fmt_ch
= fmt_ch
;
1329 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1330 int lvl
, const char *tag
, const char *fmt
, ...)
1335 va_start(args
, fmt
);
1336 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1337 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1339 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);