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/trace-ir/field-classes-internal.h>
38 #include <babeltrace/trace-ir/fields-internal.h>
39 #include <babeltrace/trace-ir/event-class-internal.h>
40 #include <babeltrace/trace-ir/event-internal.h>
41 #include <babeltrace/trace-ir/packet-internal.h>
42 #include <babeltrace/trace-ir/stream-class-internal.h>
43 #include <babeltrace/trace-ir/stream-internal.h>
44 #include <babeltrace/trace-ir/trace-internal.h>
45 #include <babeltrace/trace-ir/clock-class-internal.h>
46 #include <babeltrace/trace-ir/clock-value-internal.h>
47 #include <babeltrace/trace-ir/field-path-internal.h>
48 #include <babeltrace/trace-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 PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL)
94 #define SET_TMP_PREFIX(_prefix2) \
96 strcpy(tmp_prefix, prefix); \
97 strcat(tmp_prefix, (_prefix2)); \
100 static inline void format_component(char **buf_ch
, bool extended
,
101 const char *prefix
, struct bt_component
*component
);
103 static inline void format_port(char **buf_ch
, bool extended
,
104 const char *prefix
, struct bt_port
*port
);
106 static inline void format_connection(char **buf_ch
, bool extended
,
107 const char *prefix
, struct bt_connection
*connection
);
109 static inline void format_clock_value(char **buf_ch
, bool extended
,
110 const char *prefix
, struct bt_clock_value
*clock_value
);
112 static inline void format_field_path(char **buf_ch
, bool extended
,
113 const char *prefix
, struct bt_field_path
*field_path
);
115 static inline void format_object(char **buf_ch
, bool extended
,
116 const char *prefix
, struct bt_object
*obj
)
118 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
121 static inline void format_uuid(char **buf_ch
, bt_uuid uuid
)
123 BUF_APPEND("\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
124 (unsigned int) uuid
[0],
125 (unsigned int) uuid
[1],
126 (unsigned int) uuid
[2],
127 (unsigned int) uuid
[3],
128 (unsigned int) uuid
[4],
129 (unsigned int) uuid
[5],
130 (unsigned int) uuid
[6],
131 (unsigned int) uuid
[7],
132 (unsigned int) uuid
[8],
133 (unsigned int) uuid
[9],
134 (unsigned int) uuid
[10],
135 (unsigned int) uuid
[11],
136 (unsigned int) uuid
[12],
137 (unsigned int) uuid
[13],
138 (unsigned int) uuid
[14],
139 (unsigned int) uuid
[15]);
142 static inline void format_object_pool(char **buf_ch
, bool extended
,
143 const char *prefix
, struct bt_object_pool
*pool
)
145 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
148 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
152 static inline void format_integer_field_class(char **buf_ch
,
153 bool extended
, const char *prefix
,
154 struct bt_field_class
*field_class
)
156 struct bt_field_class_integer
*int_fc
= (void *) field_class
;
158 BUF_APPEND(", %srange-size=%" PRIu64
", %sbase=%s",
159 PRFIELD(int_fc
->range
),
160 PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc
->base
)));
163 static inline void format_array_field_class(char **buf_ch
,
164 bool extended
, const char *prefix
,
165 struct bt_field_class
*field_class
)
167 struct bt_field_class_array
*array_fc
= (void *) field_class
;
169 BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s",
170 PRFIELD(array_fc
->element_fc
),
171 PRFIELD(bt_common_field_class_type_string(array_fc
->element_fc
->type
)));
174 static inline void format_field_class(char **buf_ch
, bool extended
,
175 const char *prefix
, struct bt_field_class
*field_class
)
179 BUF_APPEND(", %stype=%s",
180 PRFIELD(bt_common_field_class_type_string(field_class
->type
)));
183 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class
->frozen
));
184 BUF_APPEND(", %sis-part-of-trace=%d",
185 PRFIELD(field_class
->part_of_trace
));
190 switch (field_class
->type
) {
191 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
192 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
194 format_integer_field_class(buf_ch
, extended
, prefix
, field_class
);
197 case BT_FIELD_CLASS_TYPE_REAL
:
199 struct bt_field_class_real
*real_fc
= (void *) field_class
;
201 BUF_APPEND(", %sis-single-precision=%d",
202 PRFIELD(real_fc
->is_single_precision
));
205 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
206 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
208 struct bt_field_class_enumeration
*enum_fc
=
209 (void *) field_class
;
211 format_integer_field_class(buf_ch
, extended
, prefix
, field_class
);
212 BUF_APPEND(", %smapping-count=%u",
213 PRFIELD(enum_fc
->mappings
->len
));
216 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
218 struct bt_field_class_structure
*struct_fc
=
219 (void *) field_class
;
221 if (struct_fc
->common
.named_fcs
) {
222 BUF_APPEND(", %smember-count=%u",
223 PRFIELD(struct_fc
->common
.named_fcs
->len
));
228 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
230 struct bt_field_class_static_array
*array_fc
=
231 (void *) field_class
;
233 format_array_field_class(buf_ch
, extended
, prefix
, field_class
);
234 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_fc
->length
));
237 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
239 struct bt_field_class_dynamic_array
*array_fc
=
240 (void *) field_class
;
242 format_array_field_class(buf_ch
, extended
, prefix
, field_class
);
244 if (array_fc
->length_fc
) {
245 SET_TMP_PREFIX("length-fc-");
246 format_field_class(buf_ch
, extended
, tmp_prefix
,
247 array_fc
->length_fc
);
250 if (array_fc
->length_field_path
) {
251 SET_TMP_PREFIX("length-field-path-");
252 format_field_path(buf_ch
, extended
, tmp_prefix
,
253 array_fc
->length_field_path
);
258 case BT_FIELD_CLASS_TYPE_VARIANT
:
260 struct bt_field_class_variant
*var_fc
= (void *) field_class
;
262 if (var_fc
->common
.named_fcs
) {
263 BUF_APPEND(", %soption-count=%u",
264 PRFIELD(var_fc
->common
.named_fcs
->len
));
267 if (var_fc
->selector_fc
) {
268 SET_TMP_PREFIX("selector-fc-");
269 format_field_class(buf_ch
, extended
, tmp_prefix
,
270 var_fc
->selector_fc
);
273 if (var_fc
->selector_field_path
) {
274 SET_TMP_PREFIX("selector-field-path-");
275 format_field_path(buf_ch
, extended
, tmp_prefix
,
276 var_fc
->selector_field_path
);
286 static inline void format_field_integer_extended(char **buf_ch
,
287 const char *prefix
, struct bt_field
*field
)
289 struct bt_field_integer
*integer
= (void *) field
;
290 struct bt_field_class_integer
*field_class
= (void *) field
->class;
291 const char *fmt
= NULL
;
293 BT_ASSERT(field_class
);
295 if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
) {
296 fmt
= ", %svalue=%" PRIo64
;
297 } else if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
) {
298 fmt
= ", %svalue=%" PRIx64
;
301 if (field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
302 field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
304 fmt
= ", %svalue=%" PRId64
;
307 BUF_APPEND(fmt
, PRFIELD(integer
->value
.i
));
310 fmt
= ", %svalue=%" PRIu64
;
313 BUF_APPEND(fmt
, PRFIELD(integer
->value
.u
));
317 static inline void format_field(char **buf_ch
, bool extended
,
318 const char *prefix
, struct bt_field
*field
)
320 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->is_set
));
323 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
326 BUF_APPEND(", %sclass-addr=%p", PRFIELD(field
->class));
332 BUF_APPEND(", %sclass-type=%s",
333 PRFIELD(bt_common_field_class_type_string(field
->class->type
)));
335 if (!extended
|| !field
->is_set
) {
339 switch (field
->class->type
) {
340 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
341 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
342 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
343 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
345 format_field_integer_extended(buf_ch
, prefix
, field
);
348 case BT_FIELD_CLASS_TYPE_REAL
:
350 struct bt_field_real
*real_field
= (void *) field
;
352 BUF_APPEND(", %svalue=%f", PRFIELD(real_field
->value
));
355 case BT_FIELD_CLASS_TYPE_STRING
:
357 struct bt_field_string
*str
= (void *) field
;
360 BT_ASSERT(str
->buf
->data
);
361 BUF_APPEND(", %spartial-value=\"%.32s\"",
362 PRFIELD(str
->buf
->data
));
367 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
368 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
370 struct bt_field_array
*array_field
= (void *) field
;
372 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_field
->length
));
374 if (array_field
->fields
) {
375 BUF_APPEND(", %sallocated-length=%u",
376 PRFIELD(array_field
->fields
->len
));
381 case BT_FIELD_CLASS_TYPE_VARIANT
:
383 struct bt_field_variant
*var_field
= (void *) field
;
385 BUF_APPEND(", %sselected-field-index=%" PRIu64
,
386 PRFIELD(var_field
->selected_index
));
394 static inline void format_field_path(char **buf_ch
, bool extended
,
395 const char *prefix
, struct bt_field_path
*field_path
)
399 if (field_path
->indexes
) {
400 BT_ASSERT(field_path
->indexes
);
401 BUF_APPEND(", %sindex-count=%u",
402 PRFIELD(field_path
->indexes
->len
));
405 if (!extended
|| !field_path
->indexes
) {
409 BUF_APPEND(", %spath=[%s",
410 PRFIELD(bt_common_scope_string(field_path
->root
)));
412 for (i
= 0; i
< field_path
->indexes
->len
; i
++) {
413 uint64_t index
= bt_field_path_get_index_by_index_inline(
416 BUF_APPEND(", %" PRIu64
, index
);
419 BUF_APPEND("%s", "]");
422 static inline void format_trace(char **buf_ch
, bool extended
,
423 const char *prefix
, struct bt_trace
*trace
)
427 if (trace
->name
.value
) {
428 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
.value
));
435 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
437 if (trace
->uuid
.value
) {
438 BUF_APPEND_UUID(trace
->uuid
.value
);
441 if (trace
->stream_classes
) {
442 BUF_APPEND(", %sstream-class-count=%u",
443 PRFIELD(trace
->stream_classes
->len
));
446 if (trace
->streams
) {
447 BUF_APPEND(", %sstream-count=%u",
448 PRFIELD(trace
->streams
->len
));
451 BUF_APPEND(", %spacket-header-fc-addr=%p, %sis-static=%d, "
452 "%sassigns-auto-sc-id=%d",
453 PRFIELD(trace
->packet_header_fc
),
454 PRFIELD(trace
->is_static
),
455 PRFIELD(trace
->assigns_automatic_stream_class_id
));
456 SET_TMP_PREFIX("phf-pool-");
457 format_object_pool(buf_ch
, extended
, prefix
,
458 &trace
->packet_header_field_pool
);
461 static inline void format_stream_class(char **buf_ch
, bool extended
,
462 const char *prefix
, struct bt_stream_class
*stream_class
)
464 struct bt_trace
*trace
;
467 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream_class
->id
));
469 if (stream_class
->name
.value
) {
470 BUF_APPEND(", %sname=\"%s\"",
471 PRFIELD(stream_class
->name
.value
));
478 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
480 if (stream_class
->event_classes
) {
481 BUF_APPEND(", %sevent-class-count=%u",
482 PRFIELD(stream_class
->event_classes
->len
));
485 BUF_APPEND(", %spacket-context-fc-addr=%p, "
486 "%sevent-header-fc-addr=%p, %sevent-common-context-fc-addr=%p",
487 PRFIELD(stream_class
->packet_context_fc
),
488 PRFIELD(stream_class
->event_header_fc
),
489 PRFIELD(stream_class
->event_common_context_fc
));
490 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
495 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
496 "%spackets-have-discarded-ev-counter-snapshot=%d, "
497 "%spackets-have-packet-counter-snapshot=%d, "
498 "%spackets-have-default-begin-cv=%d, "
499 "%spackets-have-default-end-cv=%d",
500 PRFIELD(stream_class
->assigns_automatic_event_class_id
),
501 PRFIELD(stream_class
->assigns_automatic_stream_id
),
502 PRFIELD(stream_class
->packets_have_discarded_event_counter_snapshot
),
503 PRFIELD(stream_class
->packets_have_packet_counter_snapshot
),
504 PRFIELD(stream_class
->packets_have_default_beginning_cv
),
505 PRFIELD(stream_class
->packets_have_default_end_cv
));
506 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
507 SET_TMP_PREFIX("trace-");
508 format_trace(buf_ch
, false, tmp_prefix
, trace
);
509 SET_TMP_PREFIX("ehf-pool-");
510 format_object_pool(buf_ch
, extended
, prefix
,
511 &stream_class
->event_header_field_pool
);
512 SET_TMP_PREFIX("pcf-pool-");
513 format_object_pool(buf_ch
, extended
, prefix
,
514 &stream_class
->packet_context_field_pool
);
517 static inline void format_event_class(char **buf_ch
, bool extended
,
518 const char *prefix
, struct bt_event_class
*event_class
)
520 struct bt_stream_class
*stream_class
;
521 struct bt_trace
*trace
;
524 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(event_class
->id
));
526 if (event_class
->name
.value
) {
527 BUF_APPEND(", %sname=\"%s\"",
528 PRFIELD(event_class
->name
.value
));
535 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class
->frozen
));
537 if (event_class
->log_level
.base
.avail
) {
538 BUF_APPEND(", %slog-level=%s",
539 PRFIELD(bt_common_event_class_log_level_string(
540 (int) event_class
->log_level
.value
)));
543 if (event_class
->emf_uri
.value
) {
544 BUF_APPEND(", %semf-uri=\"%s\"",
545 PRFIELD(event_class
->emf_uri
.value
));
548 BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
549 PRFIELD(event_class
->specific_context_fc
),
550 PRFIELD(event_class
->payload_fc
));
552 stream_class
= bt_event_class_borrow_stream_class(event_class
);
557 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
558 SET_TMP_PREFIX("stream-class-");
559 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
560 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
565 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
566 SET_TMP_PREFIX("trace-");
567 format_trace(buf_ch
, false, tmp_prefix
, trace
);
568 SET_TMP_PREFIX("event-pool-");
569 format_object_pool(buf_ch
, extended
, prefix
, &event_class
->event_pool
);
572 static inline void format_stream(char **buf_ch
, bool extended
,
573 const char *prefix
, struct bt_stream
*stream
)
575 struct bt_stream_class
*stream_class
;
576 struct bt_trace
*trace
;
579 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream
->id
));
581 if (stream
->name
.value
) {
582 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
.value
));
589 stream_class
= bt_stream_borrow_class(stream
);
594 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
595 SET_TMP_PREFIX("stream-class-");
596 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
597 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
602 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
603 SET_TMP_PREFIX("trace-");
604 format_trace(buf_ch
, false, tmp_prefix
, trace
);
605 SET_TMP_PREFIX("packet-pool-");
606 format_object_pool(buf_ch
, extended
, prefix
, &stream
->packet_pool
);
609 static inline void format_packet(char **buf_ch
, bool extended
,
610 const char *prefix
, struct bt_packet
*packet
)
612 struct bt_stream
*stream
;
613 struct bt_trace
*trace
;
620 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
621 "%scontext-field-addr=%p",
622 PRFIELD(packet
->frozen
),
623 PRFIELD(packet
->header_field
? packet
->header_field
->field
: NULL
),
624 PRFIELD(packet
->context_field
? packet
->context_field
->field
: NULL
));
625 stream
= bt_packet_borrow_stream(packet
);
630 if (packet
->default_beginning_cv
) {
631 SET_TMP_PREFIX("default-begin-cv-");
632 format_clock_value(buf_ch
, true, tmp_prefix
,
633 packet
->default_beginning_cv
);
636 if (packet
->default_end_cv
) {
637 SET_TMP_PREFIX("default-end-cv-");
638 format_clock_value(buf_ch
, true, tmp_prefix
,
639 packet
->default_end_cv
);
642 if (packet
->discarded_event_counter_snapshot
.base
.avail
) {
643 BUF_APPEND(", %sdiscarded-ev-counter-snapshot=%" PRIu64
,
644 PRFIELD(packet
->discarded_event_counter_snapshot
.value
));
647 if (packet
->packet_counter_snapshot
.base
.avail
) {
648 BUF_APPEND(", %spacket-counter-snapshot=%" PRIu64
,
649 PRFIELD(packet
->packet_counter_snapshot
.value
));
652 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
653 SET_TMP_PREFIX("stream-");
654 format_stream(buf_ch
, false, tmp_prefix
, stream
);
655 trace
= (struct bt_trace
*) bt_object_borrow_parent(&stream
->base
);
660 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
661 SET_TMP_PREFIX("trace-");
662 format_trace(buf_ch
, false, tmp_prefix
, trace
);
665 static inline void format_event(char **buf_ch
, bool extended
,
666 const char *prefix
, struct bt_event
*event
)
668 struct bt_packet
*packet
;
669 struct bt_stream
*stream
;
670 struct bt_trace
*trace
;
671 struct bt_stream_class
*stream_class
;
678 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
679 "%scommon-context-field-addr=%p, "
680 "%sspecific-context-field-addr=%p, "
681 "%spayload-field-addr=%p, ",
682 PRFIELD(event
->frozen
),
683 PRFIELD(event
->header_field
?
684 event
->header_field
->field
: NULL
),
685 PRFIELD(event
->common_context_field
),
686 PRFIELD(event
->specific_context_field
),
687 PRFIELD(event
->payload_field
));
688 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
694 SET_TMP_PREFIX("event-class-");
695 format_event_class(buf_ch
, false, tmp_prefix
, event
->class);
696 stream_class
= bt_event_class_borrow_stream_class(event
->class);
698 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
699 SET_TMP_PREFIX("stream-class-");
700 format_stream_class(buf_ch
, false, tmp_prefix
,
703 trace
= bt_stream_class_borrow_trace_inline(stream_class
);
705 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
706 SET_TMP_PREFIX("trace-");
707 format_trace(buf_ch
, false, tmp_prefix
, trace
);
711 if (event
->default_cv
) {
712 SET_TMP_PREFIX("default-cv-");
713 format_clock_value(buf_ch
, true, tmp_prefix
,
717 packet
= bt_event_borrow_packet(event
);
722 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet
));
723 SET_TMP_PREFIX("packet-");
724 format_packet(buf_ch
, false, tmp_prefix
, packet
);
725 stream
= bt_packet_borrow_stream(packet
);
730 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
731 SET_TMP_PREFIX("stream-");
732 format_stream(buf_ch
, false, tmp_prefix
, stream
);
735 static inline void format_clock_class(char **buf_ch
, bool extended
,
736 const char *prefix
, struct bt_clock_class
*clock_class
)
740 if (clock_class
->name
.value
) {
741 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class
->name
.value
));
744 BUF_APPEND(", %sfreq=%" PRIu64
, PRFIELD(clock_class
->frequency
));
750 if (clock_class
->description
.value
) {
751 BUF_APPEND(", %spartial-descr=\"%.32s\"",
752 PRFIELD(clock_class
->description
.value
));
755 if (clock_class
->uuid
.value
) {
756 BUF_APPEND_UUID(clock_class
->uuid
.value
);
759 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
760 "%soffset-s=%" PRId64
", "
761 "%soffset-cycles=%" PRIu64
", %sis-absolute=%d, "
762 "%sbase-offset-ns=%" PRId64
,
763 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
764 PRFIELD(clock_class
->offset_seconds
),
765 PRFIELD(clock_class
->offset_cycles
),
766 PRFIELD(clock_class
->is_absolute
),
767 PRFIELD(clock_class
->base_offset
.value_ns
));
769 SET_TMP_PREFIX("cv-pool-");
770 format_object_pool(buf_ch
, extended
, prefix
, &clock_class
->cv_pool
);
773 static inline void format_clock_value(char **buf_ch
, bool extended
,
774 const char *prefix
, struct bt_clock_value
*clock_value
)
777 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-origin=%" PRId64
,
778 PRFIELD(clock_value
->value_cycles
),
779 PRFIELD(clock_value
->ns_from_origin
));
785 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_value
->is_set
));
787 if (clock_value
->clock_class
) {
788 BUF_APPEND(", %sclock-class-addr=%p",
789 PRFIELD(clock_value
->clock_class
));
790 SET_TMP_PREFIX("clock-class-");
791 format_clock_class(buf_ch
, false, tmp_prefix
,
792 clock_value
->clock_class
);
796 static inline void format_value(char **buf_ch
, bool extended
,
797 const char *prefix
, struct bt_value
*value
)
799 BUF_APPEND(", %stype=%s",
800 PRFIELD(bt_common_value_type_string(bt_value_get_type(value
))));
806 switch (bt_value_get_type(value
)) {
807 case BT_VALUE_TYPE_BOOL
:
809 bt_bool val
= bt_value_bool_get(value
);
811 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
814 case BT_VALUE_TYPE_INTEGER
:
816 int64_t val
= bt_value_integer_get(value
);
818 BUF_APPEND(", %svalue=%" PRId64
, PRFIELD(val
));
821 case BT_VALUE_TYPE_REAL
:
823 double val
= bt_value_real_get(value
);
825 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
828 case BT_VALUE_TYPE_STRING
:
830 const char *val
= bt_value_string_get(value
);
832 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
835 case BT_VALUE_TYPE_ARRAY
:
837 int64_t count
= bt_value_array_get_size(value
);
839 BT_ASSERT(count
>= 0);
840 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
843 case BT_VALUE_TYPE_MAP
:
845 int64_t count
= bt_value_map_get_size(value
);
847 BT_ASSERT(count
>= 0);
848 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
856 static inline void format_notification(char **buf_ch
, bool extended
,
857 const char *prefix
, struct bt_notification
*notif
)
861 BUF_APPEND(", %stype=%s",
862 PRFIELD(bt_notification_type_string(notif
->type
)));
868 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
869 PRFIELD(notif
->frozen
), PRFIELD(notif
->graph
));
871 switch (notif
->type
) {
872 case BT_NOTIFICATION_TYPE_EVENT
:
874 struct bt_notification_event
*notif_event
= (void *) notif
;
876 if (notif_event
->event
) {
877 SET_TMP_PREFIX("event-");
878 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 if (notif_stream
->stream
) {
889 SET_TMP_PREFIX("stream-");
890 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
895 case BT_NOTIFICATION_TYPE_STREAM_END
:
897 struct bt_notification_stream_end
*notif_stream
=
900 if (notif_stream
->stream
) {
901 SET_TMP_PREFIX("stream-");
902 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
907 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
909 struct bt_notification_packet_begin
*notif_packet
=
912 if (notif_packet
->packet
) {
913 SET_TMP_PREFIX("packet-");
914 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
919 case BT_NOTIFICATION_TYPE_PACKET_END
:
921 struct bt_notification_packet_end
*notif_packet
=
924 if (notif_packet
->packet
) {
925 SET_TMP_PREFIX("packet-");
926 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
936 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
938 struct bt_plugin_so_shared_lib_handle
*handle
)
940 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
943 BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle
->path
));
947 static inline void format_component_class(char **buf_ch
, bool extended
,
948 const char *prefix
, struct bt_component_class
*comp_class
)
952 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
953 PRFIELD(bt_component_class_type_string(comp_class
->type
)),
954 PRFIELD_GSTRING(comp_class
->name
));
956 if (comp_class
->description
) {
957 BUF_APPEND(", %spartial-descr=\"%.32s\"",
958 PRFIELD_GSTRING(comp_class
->description
));
965 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
967 if (comp_class
->so_handle
) {
968 SET_TMP_PREFIX("so-handle-");
969 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
970 comp_class
->so_handle
);
974 static inline void format_component(char **buf_ch
, bool extended
,
975 const char *prefix
, struct bt_component
*component
)
979 BUF_APPEND(", %sname=\"%s\"",
980 PRFIELD_GSTRING(component
->name
));
982 if (component
->class) {
983 SET_TMP_PREFIX("class-");
984 format_component_class(buf_ch
, extended
, tmp_prefix
,
992 if (component
->input_ports
) {
993 BUF_APPEND(", %sinput-port-count=%u",
994 PRFIELD(component
->input_ports
->len
));
997 if (component
->output_ports
) {
998 BUF_APPEND(", %soutput-port-count=%u",
999 PRFIELD(component
->output_ports
->len
));
1003 static inline void format_port(char **buf_ch
, bool extended
,
1004 const char *prefix
, struct bt_port
*port
)
1006 char tmp_prefix
[64];
1008 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1009 PRFIELD(bt_port_type_string(port
->type
)),
1010 PRFIELD_GSTRING(port
->name
));
1016 if (port
->connection
) {
1017 SET_TMP_PREFIX("conn-");
1018 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1022 static inline void format_connection(char **buf_ch
, bool extended
,
1023 const char *prefix
, struct bt_connection
*connection
)
1025 char tmp_prefix
[64];
1031 if (connection
->upstream_port
) {
1032 SET_TMP_PREFIX("upstream-port-");
1033 format_port(buf_ch
, false, tmp_prefix
,
1034 connection
->upstream_port
);
1037 if (connection
->downstream_port
) {
1038 SET_TMP_PREFIX("downstream-port-");
1039 format_port(buf_ch
, false, tmp_prefix
,
1040 connection
->downstream_port
);
1044 static inline void format_graph(char **buf_ch
, bool extended
,
1045 const char *prefix
, struct bt_graph
*graph
)
1047 char tmp_prefix
[64];
1049 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph
->canceled
));
1055 if (graph
->components
) {
1056 BUF_APPEND(", %scomp-count=%u",
1057 PRFIELD(graph
->components
->len
));
1060 if (graph
->connections
) {
1061 BUF_APPEND(", %sconn-count=%u",
1062 PRFIELD(graph
->connections
->len
));
1065 SET_TMP_PREFIX("en-pool-");
1066 format_object_pool(buf_ch
, extended
, prefix
,
1067 &graph
->event_notif_pool
);
1068 SET_TMP_PREFIX("pbn-pool-");
1069 format_object_pool(buf_ch
, extended
, prefix
,
1070 &graph
->packet_begin_notif_pool
);
1071 SET_TMP_PREFIX("pen-pool-");
1072 format_object_pool(buf_ch
, extended
, prefix
,
1073 &graph
->packet_end_notif_pool
);
1076 static inline void format_notification_iterator(char **buf_ch
,
1077 bool extended
, const char *prefix
,
1078 struct bt_notification_iterator
*iterator
)
1081 char tmp_prefix
[64];
1083 if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
) {
1084 type
= "BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT";
1085 } else if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT
) {
1086 type
= "BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT";
1091 BUF_APPEND(", %stype=%s", PRFIELD(type
));
1093 switch (iterator
->type
) {
1094 case BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
:
1096 struct bt_self_component_port_input_notification_iterator
*
1097 port_in_iter
= (void *) iterator
;
1099 if (port_in_iter
->upstream_component
) {
1100 SET_TMP_PREFIX("upstream-comp-");
1101 format_component(buf_ch
, false, tmp_prefix
,
1102 port_in_iter
->upstream_component
);
1105 if (port_in_iter
->upstream_port
) {
1106 SET_TMP_PREFIX("upstream-port-");
1107 format_port(buf_ch
, false, tmp_prefix
,
1108 port_in_iter
->upstream_port
);
1111 if (port_in_iter
->connection
) {
1112 SET_TMP_PREFIX("upstream-conn-");
1113 format_connection(buf_ch
, false, tmp_prefix
,
1114 port_in_iter
->connection
);
1118 case BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT
:
1120 struct bt_port_output_notification_iterator
*port_out_iter
=
1123 if (port_out_iter
->graph
) {
1124 SET_TMP_PREFIX("graph-");
1125 format_graph(buf_ch
, false, tmp_prefix
,
1126 port_out_iter
->graph
);
1129 if (port_out_iter
->colander
) {
1130 SET_TMP_PREFIX("colander-comp-");
1131 format_component(buf_ch
, false, tmp_prefix
,
1132 (void *) port_out_iter
->colander
);
1142 static inline void format_plugin(char **buf_ch
, bool extended
,
1143 const char *prefix
, struct bt_plugin
*plugin
)
1145 char tmp_prefix
[64];
1147 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1149 if (plugin
->info
.path_set
) {
1150 BUF_APPEND(", %spath=\"%s\"",
1151 PRFIELD_GSTRING(plugin
->info
.path
));
1154 if (plugin
->info
.name_set
) {
1155 BUF_APPEND(", %sname=\"%s\"",
1156 PRFIELD_GSTRING(plugin
->info
.name
));
1163 if (plugin
->info
.author_set
) {
1164 BUF_APPEND(", %sauthor=\"%s\"",
1165 PRFIELD_GSTRING(plugin
->info
.author
));
1168 if (plugin
->info
.license_set
) {
1169 BUF_APPEND(", %slicense=\"%s\"",
1170 PRFIELD_GSTRING(plugin
->info
.license
));
1173 if (plugin
->info
.version_set
) {
1174 BUF_APPEND(", %sversion=%u.%u.%u%s",
1175 PRFIELD(plugin
->info
.version
.major
),
1176 plugin
->info
.version
.minor
,
1177 plugin
->info
.version
.patch
,
1178 plugin
->info
.version
.extra
?
1179 plugin
->info
.version
.extra
->str
: "");
1182 BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, "
1183 "%ssink-comp-class-count=%u",
1184 PRFIELD(plugin
->src_comp_classes
->len
),
1185 PRFIELD(plugin
->flt_comp_classes
->len
),
1186 PRFIELD(plugin
->sink_comp_classes
->len
));
1188 if (plugin
->spec_data
) {
1189 struct bt_plugin_so_spec_data
*spec_data
=
1190 (void *) plugin
->spec_data
;
1192 if (spec_data
->shared_lib_handle
) {
1193 SET_TMP_PREFIX("so-handle-");
1194 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1195 spec_data
->shared_lib_handle
);
1200 static inline void handle_conversion_specifier_bt(void *priv_data
,
1201 char **buf_ch
, size_t avail_size
,
1202 const char **out_fmt_ch
, va_list *args
)
1204 const char *fmt_ch
= *out_fmt_ch
;
1205 bool extended
= false;
1207 char *prefix_ch
= prefix
;
1213 if (*fmt_ch
== 'u') {
1215 obj
= va_arg(*args
, void *);
1216 format_uuid(buf_ch
, obj
);
1220 if (*fmt_ch
== '[') {
1225 if (*fmt_ch
== ']') {
1231 *prefix_ch
= *fmt_ch
;
1239 if (*fmt_ch
== '+') {
1244 obj
= va_arg(*args
, void *);
1245 BUF_APPEND("%saddr=%p", prefix
, obj
);
1253 format_field_class(buf_ch
, extended
, prefix
, obj
);
1256 format_field(buf_ch
, extended
, prefix
, obj
);
1259 format_field_path(buf_ch
, extended
, prefix
, obj
);
1262 format_event_class(buf_ch
, extended
, prefix
, obj
);
1265 format_event(buf_ch
, extended
, prefix
, obj
);
1268 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1271 format_stream(buf_ch
, extended
, prefix
, obj
);
1274 format_packet(buf_ch
, extended
, prefix
, obj
);
1277 format_trace(buf_ch
, extended
, prefix
, obj
);
1280 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1283 format_clock_value(buf_ch
, extended
, prefix
, obj
);
1286 format_value(buf_ch
, extended
, prefix
, obj
);
1289 format_notification(buf_ch
, extended
, prefix
, obj
);
1292 format_notification_iterator(buf_ch
, extended
, prefix
, obj
);
1295 format_component_class(buf_ch
, extended
, prefix
, obj
);
1298 format_component(buf_ch
, extended
, prefix
, obj
);
1301 format_port(buf_ch
, extended
, prefix
, obj
);
1304 format_connection(buf_ch
, extended
, prefix
, obj
);
1307 format_plugin(buf_ch
, extended
, prefix
, obj
);
1310 format_graph(buf_ch
, extended
, prefix
, obj
);
1313 format_object_pool(buf_ch
, extended
, prefix
, obj
);
1316 format_object(buf_ch
, extended
, prefix
, obj
);
1324 *out_fmt_ch
= fmt_ch
;
1328 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1329 int lvl
, const char *tag
, const char *fmt
, ...)
1334 va_start(args
, fmt
);
1335 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1336 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1338 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);