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/lib-logging-internal.h>
34 #include <babeltrace/assert-pre-internal.h>
35 #include <babeltrace/common-internal.h>
36 #include <babeltrace/lib-logging-internal.h>
37 #include <babeltrace/value-internal.h>
38 #include <babeltrace/value-internal.h>
39 #include <babeltrace/object-pool-internal.h>
40 #include <babeltrace/trace-ir/field-class-internal.h>
41 #include <babeltrace/trace-ir/field-internal.h>
42 #include <babeltrace/trace-ir/event-class-internal.h>
43 #include <babeltrace/trace-ir/event-const.h>
44 #include <babeltrace/trace-ir/event-internal.h>
45 #include <babeltrace/trace-ir/packet-const.h>
46 #include <babeltrace/trace-ir/packet-internal.h>
47 #include <babeltrace/trace-ir/stream-class-internal.h>
48 #include <babeltrace/trace-ir/stream-internal.h>
49 #include <babeltrace/trace-ir/stream-const.h>
50 #include <babeltrace/trace-ir/trace-internal.h>
51 #include <babeltrace/trace-ir/trace-class-internal.h>
52 #include <babeltrace/trace-ir/clock-class-internal.h>
53 #include <babeltrace/trace-ir/clock-snapshot-internal.h>
54 #include <babeltrace/trace-ir/field-path-internal.h>
55 #include <babeltrace/trace-ir/utils-internal.h>
56 #include <babeltrace/graph/component-class-internal.h>
57 #include <babeltrace/graph/component-class-sink-colander-internal.h>
58 #include <babeltrace/graph/component-filter-internal.h>
59 #include <babeltrace/graph/component-internal.h>
60 #include <babeltrace/graph/component-sink-internal.h>
61 #include <babeltrace/graph/component-source-internal.h>
62 #include <babeltrace/graph/connection-internal.h>
63 #include <babeltrace/graph/graph-internal.h>
64 #include <babeltrace/graph/message-event-internal.h>
65 #include <babeltrace/graph/message-message-iterator-inactivity-internal.h>
66 #include <babeltrace/graph/message-internal.h>
67 #include <babeltrace/graph/message-iterator-internal.h>
68 #include <babeltrace/graph/message-packet-internal.h>
69 #include <babeltrace/graph/message-stream-internal.h>
70 #include <babeltrace/graph/message-stream-activity-internal.h>
71 #include <babeltrace/graph/message-discarded-items-internal.h>
72 #include <babeltrace/graph/port-internal.h>
73 #include <babeltrace/plugin/plugin-internal.h>
74 #include <babeltrace/plugin/plugin-so-internal.h>
76 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
78 static __thread
char lib_logging_buf
[LIB_LOGGING_BUF_SIZE
];
80 #define BUF_APPEND(_fmt, ...) \
83 size_t _size = LIB_LOGGING_BUF_SIZE - \
84 (size_t) (*buf_ch - lib_logging_buf); \
85 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
86 BT_ASSERT(_count >= 0); \
87 *buf_ch += MIN(_count, _size); \
88 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
93 #define BUF_APPEND_UUID(_uuid) \
95 BUF_APPEND(", %suuid=", prefix); \
96 format_uuid(buf_ch, (_uuid)); \
99 #define PRFIELD(_expr) prefix, (_expr)
101 #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL)
103 #define TMP_PREFIX_LEN 64
104 #define SET_TMP_PREFIX(_prefix2) \
106 strncpy(tmp_prefix, prefix, TMP_PREFIX_LEN); \
107 strncat(tmp_prefix, (_prefix2), TMP_PREFIX_LEN); \
110 static inline void format_component(char **buf_ch
, bool extended
,
111 const char *prefix
, const struct bt_component
*component
);
113 static inline void format_port(char **buf_ch
, bool extended
,
114 const char *prefix
, const struct bt_port
*port
);
116 static inline void format_connection(char **buf_ch
, bool extended
,
117 const char *prefix
, const struct bt_connection
*connection
);
119 static inline void format_clock_snapshot(char **buf_ch
, bool extended
,
120 const char *prefix
, const struct bt_clock_snapshot
*clock_snapshot
);
122 static inline void format_field_path(char **buf_ch
, bool extended
,
123 const char *prefix
, const struct bt_field_path
*field_path
);
125 static inline void format_object(char **buf_ch
, bool extended
,
126 const char *prefix
, const struct bt_object
*obj
)
128 BUF_APPEND(", %sref-count=%llu", prefix
, obj
->ref_count
);
131 static inline void format_uuid(char **buf_ch
, bt_uuid uuid
)
133 BUF_APPEND("\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
134 (unsigned int) uuid
[0],
135 (unsigned int) uuid
[1],
136 (unsigned int) uuid
[2],
137 (unsigned int) uuid
[3],
138 (unsigned int) uuid
[4],
139 (unsigned int) uuid
[5],
140 (unsigned int) uuid
[6],
141 (unsigned int) uuid
[7],
142 (unsigned int) uuid
[8],
143 (unsigned int) uuid
[9],
144 (unsigned int) uuid
[10],
145 (unsigned int) uuid
[11],
146 (unsigned int) uuid
[12],
147 (unsigned int) uuid
[13],
148 (unsigned int) uuid
[14],
149 (unsigned int) uuid
[15]);
152 static inline void format_object_pool(char **buf_ch
, bool extended
,
153 const char *prefix
, const struct bt_object_pool
*pool
)
155 BUF_APPEND(", %ssize=%zu", PRFIELD(pool
->size
));
158 BUF_APPEND(", %scap=%u", PRFIELD(pool
->objects
->len
));
162 static inline void format_integer_field_class(char **buf_ch
,
163 bool extended
, const char *prefix
,
164 const struct bt_field_class
*field_class
)
166 const struct bt_field_class_integer
*int_fc
=
167 (const void *) field_class
;
169 BUF_APPEND(", %srange-size=%" PRIu64
", %sbase=%s",
170 PRFIELD(int_fc
->range
),
171 PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc
->base
)));
174 static inline void format_array_field_class(char **buf_ch
,
175 bool extended
, const char *prefix
,
176 const struct bt_field_class
*field_class
)
178 const struct bt_field_class_array
*array_fc
=
179 (const void *) field_class
;
181 BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s",
182 PRFIELD(array_fc
->element_fc
),
183 PRFIELD(bt_common_field_class_type_string(array_fc
->element_fc
->type
)));
186 static inline void format_field_class(char **buf_ch
, bool extended
,
187 const char *prefix
, const struct bt_field_class
*field_class
)
189 char tmp_prefix
[TMP_PREFIX_LEN
];
191 BUF_APPEND(", %stype=%s",
192 PRFIELD(bt_common_field_class_type_string(field_class
->type
)));
195 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class
->frozen
));
196 BUF_APPEND(", %sis-part-of-trace-class=%d",
197 PRFIELD(field_class
->part_of_trace_class
));
202 switch (field_class
->type
) {
203 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
204 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
206 format_integer_field_class(buf_ch
, extended
, prefix
, field_class
);
209 case BT_FIELD_CLASS_TYPE_REAL
:
211 const struct bt_field_class_real
*real_fc
= (void *) field_class
;
213 BUF_APPEND(", %sis-single-precision=%d",
214 PRFIELD(real_fc
->is_single_precision
));
217 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
218 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
220 const struct bt_field_class_enumeration
*enum_fc
=
221 (const void *) field_class
;
223 format_integer_field_class(buf_ch
, extended
, prefix
, field_class
);
224 BUF_APPEND(", %smapping-count=%u",
225 PRFIELD(enum_fc
->mappings
->len
));
228 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
230 const struct bt_field_class_structure
*struct_fc
=
231 (const void *) field_class
;
233 if (struct_fc
->common
.named_fcs
) {
234 BUF_APPEND(", %smember-count=%u",
235 PRFIELD(struct_fc
->common
.named_fcs
->len
));
240 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
242 const struct bt_field_class_static_array
*array_fc
=
243 (const void *) field_class
;
245 format_array_field_class(buf_ch
, extended
, prefix
, field_class
);
246 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_fc
->length
));
249 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
251 const struct bt_field_class_dynamic_array
*array_fc
=
252 (const void *) field_class
;
254 format_array_field_class(buf_ch
, extended
, prefix
, field_class
);
256 if (array_fc
->length_fc
) {
257 SET_TMP_PREFIX("length-fc-");
258 format_field_class(buf_ch
, extended
, tmp_prefix
,
259 array_fc
->length_fc
);
262 if (array_fc
->length_field_path
) {
263 SET_TMP_PREFIX("length-field-path-");
264 format_field_path(buf_ch
, extended
, tmp_prefix
,
265 array_fc
->length_field_path
);
270 case BT_FIELD_CLASS_TYPE_VARIANT
:
272 const struct bt_field_class_variant
*var_fc
=
273 (const void *) field_class
;
275 if (var_fc
->common
.named_fcs
) {
276 BUF_APPEND(", %soption-count=%u",
277 PRFIELD(var_fc
->common
.named_fcs
->len
));
280 if (var_fc
->selector_fc
) {
281 SET_TMP_PREFIX("selector-fc-");
282 format_field_class(buf_ch
, extended
, tmp_prefix
,
283 var_fc
->selector_fc
);
286 if (var_fc
->selector_field_path
) {
287 SET_TMP_PREFIX("selector-field-path-");
288 format_field_path(buf_ch
, extended
, tmp_prefix
,
289 var_fc
->selector_field_path
);
299 static inline void format_field_integer_extended(char **buf_ch
,
300 const char *prefix
, const struct bt_field
*field
)
302 const struct bt_field_integer
*integer
= (void *) field
;
303 const struct bt_field_class_integer
*field_class
=
304 (void *) field
->class;
305 const char *fmt
= NULL
;
307 BT_ASSERT(field_class
);
309 if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
) {
310 fmt
= ", %svalue=%" PRIo64
;
311 } else if (field_class
->base
== BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
) {
312 fmt
= ", %svalue=%" PRIx64
;
315 if (field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
316 field_class
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
318 fmt
= ", %svalue=%" PRId64
;
321 BUF_APPEND(fmt
, PRFIELD(integer
->value
.i
));
324 fmt
= ", %svalue=%" PRIu64
;
327 BUF_APPEND(fmt
, PRFIELD(integer
->value
.u
));
331 static inline void format_field(char **buf_ch
, bool extended
,
332 const char *prefix
, const struct bt_field
*field
)
334 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->is_set
));
337 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
340 BUF_APPEND(", %sclass-addr=%p", PRFIELD(field
->class));
346 BUF_APPEND(", %sclass-type=%s",
347 PRFIELD(bt_common_field_class_type_string(field
->class->type
)));
349 if (!extended
|| !field
->is_set
) {
353 switch (field
->class->type
) {
354 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
355 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
356 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
357 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
359 format_field_integer_extended(buf_ch
, prefix
, field
);
362 case BT_FIELD_CLASS_TYPE_REAL
:
364 const struct bt_field_real
*real_field
= (const void *) field
;
366 BUF_APPEND(", %svalue=%f", PRFIELD(real_field
->value
));
369 case BT_FIELD_CLASS_TYPE_STRING
:
371 const struct bt_field_string
*str
= (const void *) field
;
374 BT_ASSERT(str
->buf
->data
);
375 BUF_APPEND(", %spartial-value=\"%.32s\"",
376 PRFIELD(str
->buf
->data
));
381 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
382 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
384 const struct bt_field_array
*array_field
= (const void *) field
;
386 BUF_APPEND(", %slength=%" PRIu64
, PRFIELD(array_field
->length
));
388 if (array_field
->fields
) {
389 BUF_APPEND(", %sallocated-length=%u",
390 PRFIELD(array_field
->fields
->len
));
395 case BT_FIELD_CLASS_TYPE_VARIANT
:
397 const struct bt_field_variant
*var_field
= (const void *) field
;
399 BUF_APPEND(", %sselected-field-index=%" PRIu64
,
400 PRFIELD(var_field
->selected_index
));
408 static inline void format_field_path(char **buf_ch
, bool extended
,
409 const char *prefix
, const struct bt_field_path
*field_path
)
413 if (field_path
->items
) {
414 BT_ASSERT(field_path
->items
);
415 BUF_APPEND(", %sitem-count=%u",
416 PRFIELD(field_path
->items
->len
));
419 if (!extended
|| !field_path
->items
) {
423 BUF_APPEND(", %spath=[%s",
424 PRFIELD(bt_common_scope_string(field_path
->root
)));
426 for (i
= 0; i
< bt_field_path_get_item_count(field_path
); i
++) {
427 const struct bt_field_path_item
*fp_item
=
428 bt_field_path_borrow_item_by_index_const(field_path
, i
);
430 switch (bt_field_path_item_get_type(fp_item
)) {
431 case BT_FIELD_PATH_ITEM_TYPE_INDEX
:
432 BUF_APPEND(", %" PRIu64
,
433 bt_field_path_item_index_get_index(fp_item
));
435 case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
:
436 BUF_APPEND("%s", ", <CUR>");
443 BUF_APPEND("%s", "]");
446 static inline void format_trace_class(char **buf_ch
, bool extended
,
447 const char *prefix
, const struct bt_trace_class
*trace_class
)
449 if (trace_class
->name
.value
) {
450 BUF_APPEND(", %sname=\"%s\"",
451 PRFIELD(trace_class
->name
.value
));
458 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class
->frozen
));
460 if (trace_class
->uuid
.value
) {
461 BUF_APPEND_UUID(trace_class
->uuid
.value
);
464 if (trace_class
->stream_classes
) {
465 BUF_APPEND(", %sstream-class-count=%u",
466 PRFIELD(trace_class
->stream_classes
->len
));
469 BUF_APPEND(", %sassigns-auto-sc-id=%d",
470 PRFIELD(trace_class
->assigns_automatic_stream_class_id
));
473 static inline void format_trace(char **buf_ch
, bool extended
,
474 const char *prefix
, const struct bt_trace
*trace
)
476 char tmp_prefix
[TMP_PREFIX_LEN
];
478 if (trace
->name
.value
) {
479 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
.value
));
486 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
488 if (trace
->streams
) {
489 BUF_APPEND(", %sstream-count=%u",
490 PRFIELD(trace
->streams
->len
));
497 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace
->class));
498 SET_TMP_PREFIX("trace-class-");
499 format_trace_class(buf_ch
, false, tmp_prefix
, trace
->class);
502 static inline void format_stream_class(char **buf_ch
, bool extended
,
504 const struct bt_stream_class
*stream_class
)
506 const struct bt_trace_class
*trace_class
;
507 char tmp_prefix
[TMP_PREFIX_LEN
];
509 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream_class
->id
));
511 if (stream_class
->name
.value
) {
512 BUF_APPEND(", %sname=\"%s\"",
513 PRFIELD(stream_class
->name
.value
));
520 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
522 if (stream_class
->event_classes
) {
523 BUF_APPEND(", %sevent-class-count=%u",
524 PRFIELD(stream_class
->event_classes
->len
));
527 BUF_APPEND(", %spacket-context-fc-addr=%p, "
528 "%sevent-common-context-fc-addr=%p",
529 PRFIELD(stream_class
->packet_context_fc
),
530 PRFIELD(stream_class
->event_common_context_fc
));
531 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
536 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d",
537 PRFIELD(stream_class
->assigns_automatic_event_class_id
),
538 PRFIELD(stream_class
->assigns_automatic_stream_id
));
539 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
540 SET_TMP_PREFIX("trace-class-");
541 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
542 SET_TMP_PREFIX("pcf-pool-");
543 format_object_pool(buf_ch
, extended
, tmp_prefix
,
544 &stream_class
->packet_context_field_pool
);
547 static inline void format_event_class(char **buf_ch
, bool extended
,
548 const char *prefix
, const struct bt_event_class
*event_class
)
550 const struct bt_stream_class
*stream_class
;
551 const struct bt_trace_class
*trace_class
;
552 char tmp_prefix
[TMP_PREFIX_LEN
];
554 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(event_class
->id
));
556 if (event_class
->name
.value
) {
557 BUF_APPEND(", %sname=\"%s\"",
558 PRFIELD(event_class
->name
.value
));
565 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class
->frozen
));
567 if (event_class
->log_level
.base
.avail
) {
568 BUF_APPEND(", %slog-level=%s",
569 PRFIELD(bt_common_event_class_log_level_string(
570 (int) event_class
->log_level
.value
)));
573 if (event_class
->emf_uri
.value
) {
574 BUF_APPEND(", %semf-uri=\"%s\"",
575 PRFIELD(event_class
->emf_uri
.value
));
578 BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
579 PRFIELD(event_class
->specific_context_fc
),
580 PRFIELD(event_class
->payload_fc
));
582 stream_class
= bt_event_class_borrow_stream_class_const(event_class
);
587 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
588 SET_TMP_PREFIX("stream-class-");
589 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
590 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
595 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
596 SET_TMP_PREFIX("trace-class-");
597 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
598 SET_TMP_PREFIX("event-pool-");
599 format_object_pool(buf_ch
, extended
, tmp_prefix
,
600 &event_class
->event_pool
);
603 static inline void format_stream(char **buf_ch
, bool extended
,
604 const char *prefix
, const struct bt_stream
*stream
)
606 const struct bt_stream_class
*stream_class
;
607 const struct bt_trace_class
*trace_class
= NULL
;
608 const struct bt_trace
*trace
= NULL
;
609 char tmp_prefix
[TMP_PREFIX_LEN
];
611 BUF_APPEND(", %sid=%" PRIu64
, PRFIELD(stream
->id
));
613 if (stream
->name
.value
) {
614 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
.value
));
621 stream_class
= bt_stream_borrow_class_const(stream
);
623 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
624 SET_TMP_PREFIX("stream-class-");
625 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
626 trace_class
= bt_stream_class_borrow_trace_class_inline(stream_class
);
630 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
631 SET_TMP_PREFIX("trace-class-");
632 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
635 trace
= bt_stream_borrow_trace_inline(stream
);
637 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
638 SET_TMP_PREFIX("trace-");
639 format_trace(buf_ch
, false, tmp_prefix
, trace
);
642 SET_TMP_PREFIX("packet-pool-");
643 format_object_pool(buf_ch
, extended
, tmp_prefix
, &stream
->packet_pool
);
646 static inline void format_packet(char **buf_ch
, bool extended
,
647 const char *prefix
, const struct bt_packet
*packet
)
649 const struct bt_stream
*stream
;
650 const struct bt_trace_class
*trace_class
;
651 char tmp_prefix
[TMP_PREFIX_LEN
];
657 BUF_APPEND(", %sis-frozen=%d, %scontext-field-addr=%p",
658 PRFIELD(packet
->frozen
),
659 PRFIELD(packet
->context_field
? packet
->context_field
->field
: NULL
));
660 stream
= bt_packet_borrow_stream_const(packet
);
665 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
666 SET_TMP_PREFIX("stream-");
667 format_stream(buf_ch
, false, tmp_prefix
, stream
);
668 trace_class
= (const struct bt_trace_class
*) bt_object_borrow_parent(&stream
->base
);
673 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class
));
674 SET_TMP_PREFIX("trace-class-");
675 format_trace_class(buf_ch
, false, tmp_prefix
, trace_class
);
678 static inline void format_event(char **buf_ch
, bool extended
,
679 const char *prefix
, const struct bt_event
*event
)
681 const struct bt_packet
*packet
;
682 const struct bt_stream
*stream
;
683 const struct bt_trace_class
*trace_class
;
684 const struct bt_stream_class
*stream_class
;
685 char tmp_prefix
[TMP_PREFIX_LEN
];
691 BUF_APPEND(", %sis-frozen=%d, "
692 "%scommon-context-field-addr=%p, "
693 "%sspecific-context-field-addr=%p, "
694 "%spayload-field-addr=%p, ",
695 PRFIELD(event
->frozen
),
696 PRFIELD(event
->common_context_field
),
697 PRFIELD(event
->specific_context_field
),
698 PRFIELD(event
->payload_field
));
699 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
705 SET_TMP_PREFIX("event-class-");
706 format_event_class(buf_ch
, false, tmp_prefix
, event
->class);
707 stream_class
= bt_event_class_borrow_stream_class(event
->class);
709 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
710 SET_TMP_PREFIX("stream-class-");
711 format_stream_class(buf_ch
, false, tmp_prefix
,
714 trace_class
= bt_stream_class_borrow_trace_class_inline(
717 BUF_APPEND(", %strace-class-addr=%p",
718 PRFIELD(trace_class
));
719 SET_TMP_PREFIX("trace-class-");
720 format_trace_class(buf_ch
, false, tmp_prefix
,
725 packet
= bt_event_borrow_packet_const(event
);
730 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet
));
731 SET_TMP_PREFIX("packet-");
732 format_packet(buf_ch
, false, tmp_prefix
, packet
);
733 stream
= bt_packet_borrow_stream_const(packet
);
738 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
739 SET_TMP_PREFIX("stream-");
740 format_stream(buf_ch
, false, tmp_prefix
, stream
);
743 static inline void format_clock_class(char **buf_ch
, bool extended
,
744 const char *prefix
, const struct bt_clock_class
*clock_class
)
746 char tmp_prefix
[TMP_PREFIX_LEN
];
748 if (clock_class
->name
.value
) {
749 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class
->name
.value
));
752 BUF_APPEND(", %sfreq=%" PRIu64
, PRFIELD(clock_class
->frequency
));
758 if (clock_class
->description
.value
) {
759 BUF_APPEND(", %spartial-descr=\"%.32s\"",
760 PRFIELD(clock_class
->description
.value
));
763 if (clock_class
->uuid
.value
) {
764 BUF_APPEND_UUID(clock_class
->uuid
.value
);
767 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
768 "%soffset-s=%" PRId64
", "
769 "%soffset-cycles=%" PRIu64
", %sorigin-is-unix-epoch=%d, "
770 "%sbase-offset-ns=%" PRId64
,
771 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
772 PRFIELD(clock_class
->offset_seconds
),
773 PRFIELD(clock_class
->offset_cycles
),
774 PRFIELD(clock_class
->origin_is_unix_epoch
),
775 PRFIELD(clock_class
->base_offset
.value_ns
));
777 SET_TMP_PREFIX("cs-pool-");
778 format_object_pool(buf_ch
, extended
, tmp_prefix
,
779 &clock_class
->cs_pool
);
782 static inline void format_clock_snapshot(char **buf_ch
, bool extended
,
783 const char *prefix
, const struct bt_clock_snapshot
*clock_snapshot
)
785 char tmp_prefix
[TMP_PREFIX_LEN
];
786 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-origin=%" PRId64
,
787 PRFIELD(clock_snapshot
->value_cycles
),
788 PRFIELD(clock_snapshot
->ns_from_origin
));
794 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_snapshot
->is_set
));
796 if (clock_snapshot
->clock_class
) {
797 BUF_APPEND(", %sclock-class-addr=%p",
798 PRFIELD(clock_snapshot
->clock_class
));
799 SET_TMP_PREFIX("clock-class-");
800 format_clock_class(buf_ch
, false, tmp_prefix
,
801 clock_snapshot
->clock_class
);
805 static inline void format_value(char **buf_ch
, bool extended
,
806 const char *prefix
, const struct bt_value
*value
)
808 BUF_APPEND(", %stype=%s",
809 PRFIELD(bt_common_value_type_string(bt_value_get_type(value
))));
815 switch (bt_value_get_type(value
)) {
816 case BT_VALUE_TYPE_BOOL
:
818 bt_bool val
= bt_value_bool_get(value
);
820 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
823 case BT_VALUE_TYPE_UNSIGNED_INTEGER
:
825 BUF_APPEND(", %svalue=%" PRIu64
,
826 PRFIELD(bt_value_unsigned_integer_get(value
)));
829 case BT_VALUE_TYPE_SIGNED_INTEGER
:
831 BUF_APPEND(", %svalue=%" PRId64
,
832 PRFIELD(bt_value_signed_integer_get(value
)));
835 case BT_VALUE_TYPE_REAL
:
837 double val
= bt_value_real_get(value
);
839 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
842 case BT_VALUE_TYPE_STRING
:
844 const char *val
= bt_value_string_get(value
);
846 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
849 case BT_VALUE_TYPE_ARRAY
:
851 int64_t count
= bt_value_array_get_size(value
);
853 BT_ASSERT(count
>= 0);
854 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
857 case BT_VALUE_TYPE_MAP
:
859 int64_t count
= bt_value_map_get_size(value
);
861 BT_ASSERT(count
>= 0);
862 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
870 static inline void format_message(char **buf_ch
, bool extended
,
871 const char *prefix
, const struct bt_message
*msg
)
873 char tmp_prefix
[TMP_PREFIX_LEN
];
875 BUF_APPEND(", %stype=%s",
876 PRFIELD(bt_message_type_string(msg
->type
)));
882 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
883 PRFIELD(msg
->frozen
), PRFIELD(msg
->graph
));
886 case BT_MESSAGE_TYPE_EVENT
:
888 const struct bt_message_event
*msg_event
=
891 if (msg_event
->event
) {
892 SET_TMP_PREFIX("event-");
893 format_event(buf_ch
, true, tmp_prefix
,
897 if (msg_event
->default_cs
) {
898 SET_TMP_PREFIX("default-cs-");
899 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
900 msg_event
->default_cs
);
905 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
906 case BT_MESSAGE_TYPE_STREAM_END
:
908 const struct bt_message_stream
*msg_stream
= (const void *) msg
;
910 if (msg_stream
->stream
) {
911 SET_TMP_PREFIX("stream-");
912 format_stream(buf_ch
, true, tmp_prefix
,
918 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
:
919 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
:
921 const struct bt_message_stream_activity
*msg_stream_activity
=
924 if (msg_stream_activity
->stream
) {
925 SET_TMP_PREFIX("stream-");
926 format_stream(buf_ch
, true, tmp_prefix
,
927 msg_stream_activity
->stream
);
930 BUF_APPEND(", %sdefault-cs-state=%s",
931 PRFIELD(bt_message_stream_activity_clock_snapshot_state_string(
932 msg_stream_activity
->default_cs_state
)));
934 if (msg_stream_activity
->default_cs
) {
935 SET_TMP_PREFIX("default-cs-");
936 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
937 msg_stream_activity
->default_cs
);
942 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
943 case BT_MESSAGE_TYPE_PACKET_END
:
945 const struct bt_message_packet
*msg_packet
= (const void *) msg
;
947 if (msg_packet
->packet
) {
948 SET_TMP_PREFIX("packet-");
949 format_packet(buf_ch
, true, tmp_prefix
,
953 if (msg_packet
->default_cs
) {
954 SET_TMP_PREFIX("default-cs-");
955 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
956 msg_packet
->default_cs
);
961 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
962 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
964 const struct bt_message_discarded_items
*msg_disc_items
=
967 if (msg_disc_items
->stream
) {
968 SET_TMP_PREFIX("stream-");
969 format_stream(buf_ch
, true, tmp_prefix
,
970 msg_disc_items
->stream
);
973 if (msg_disc_items
->default_begin_cs
) {
974 SET_TMP_PREFIX("default-begin-cs-");
975 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
976 msg_disc_items
->default_begin_cs
);
979 if (msg_disc_items
->default_end_cs
) {
980 SET_TMP_PREFIX("default-end-cs-");
981 format_clock_snapshot(buf_ch
, true, tmp_prefix
,
982 msg_disc_items
->default_end_cs
);
985 if (msg_disc_items
->count
.base
.avail
) {
986 BUF_APPEND(", %scount=%" PRIu64
,
987 PRFIELD(msg_disc_items
->count
.value
));
997 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
999 const struct bt_plugin_so_shared_lib_handle
*handle
)
1001 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
1004 BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle
->path
));
1008 static inline void format_component_class(char **buf_ch
, bool extended
,
1010 const struct bt_component_class
*comp_class
)
1012 char tmp_prefix
[TMP_PREFIX_LEN
];
1014 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1015 PRFIELD(bt_component_class_type_string(comp_class
->type
)),
1016 PRFIELD_GSTRING(comp_class
->name
));
1018 if (comp_class
->description
) {
1019 BUF_APPEND(", %spartial-descr=\"%.32s\"",
1020 PRFIELD_GSTRING(comp_class
->description
));
1027 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
1029 if (comp_class
->so_handle
) {
1030 SET_TMP_PREFIX("so-handle-");
1031 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1032 comp_class
->so_handle
);
1036 static inline void format_component(char **buf_ch
, bool extended
,
1037 const char *prefix
, const struct bt_component
*component
)
1039 char tmp_prefix
[TMP_PREFIX_LEN
];
1041 BUF_APPEND(", %sname=\"%s\"",
1042 PRFIELD_GSTRING(component
->name
));
1044 if (component
->class) {
1045 SET_TMP_PREFIX("class-");
1046 format_component_class(buf_ch
, extended
, tmp_prefix
,
1054 if (component
->input_ports
) {
1055 BUF_APPEND(", %sinput-port-count=%u",
1056 PRFIELD(component
->input_ports
->len
));
1059 if (component
->output_ports
) {
1060 BUF_APPEND(", %soutput-port-count=%u",
1061 PRFIELD(component
->output_ports
->len
));
1065 static inline void format_port(char **buf_ch
, bool extended
,
1066 const char *prefix
, const struct bt_port
*port
)
1068 char tmp_prefix
[TMP_PREFIX_LEN
];
1070 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1071 PRFIELD(bt_port_type_string(port
->type
)),
1072 PRFIELD_GSTRING(port
->name
));
1078 if (port
->connection
) {
1079 SET_TMP_PREFIX("conn-");
1080 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1084 static inline void format_connection(char **buf_ch
, bool extended
,
1085 const char *prefix
, const struct bt_connection
*connection
)
1087 char tmp_prefix
[TMP_PREFIX_LEN
];
1093 if (connection
->upstream_port
) {
1094 SET_TMP_PREFIX("upstream-port-");
1095 format_port(buf_ch
, false, tmp_prefix
,
1096 connection
->upstream_port
);
1099 if (connection
->downstream_port
) {
1100 SET_TMP_PREFIX("downstream-port-");
1101 format_port(buf_ch
, false, tmp_prefix
,
1102 connection
->downstream_port
);
1106 static inline void format_graph(char **buf_ch
, bool extended
,
1107 const char *prefix
, const struct bt_graph
*graph
)
1109 char tmp_prefix
[TMP_PREFIX_LEN
];
1111 BUF_APPEND(", %sis-canceled=%d, %scan-consume=%d, "
1112 "%sconfig-state=%s",
1113 PRFIELD(graph
->canceled
),
1114 PRFIELD(graph
->can_consume
),
1115 PRFIELD(bt_graph_configuration_state_string(graph
->config_state
)));
1121 if (graph
->components
) {
1122 BUF_APPEND(", %scomp-count=%u",
1123 PRFIELD(graph
->components
->len
));
1126 if (graph
->connections
) {
1127 BUF_APPEND(", %sconn-count=%u",
1128 PRFIELD(graph
->connections
->len
));
1131 SET_TMP_PREFIX("en-pool-");
1132 format_object_pool(buf_ch
, extended
, tmp_prefix
,
1133 &graph
->event_msg_pool
);
1134 SET_TMP_PREFIX("pbn-pool-");
1135 format_object_pool(buf_ch
, extended
, tmp_prefix
,
1136 &graph
->packet_begin_msg_pool
);
1137 SET_TMP_PREFIX("pen-pool-");
1138 format_object_pool(buf_ch
, extended
, tmp_prefix
,
1139 &graph
->packet_end_msg_pool
);
1142 static inline void format_message_iterator(char **buf_ch
,
1143 bool extended
, const char *prefix
,
1144 const struct bt_message_iterator
*iterator
)
1147 char tmp_prefix
[TMP_PREFIX_LEN
];
1149 if (iterator
->type
== BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
) {
1150 type
= "BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT";
1151 } else if (iterator
->type
== BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT
) {
1152 type
= "BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT";
1157 BUF_APPEND(", %stype=%s", PRFIELD(type
));
1159 switch (iterator
->type
) {
1160 case BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
:
1162 const struct bt_self_component_port_input_message_iterator
*
1163 port_in_iter
= (const void *) iterator
;
1165 if (port_in_iter
->upstream_component
) {
1166 SET_TMP_PREFIX("upstream-comp-");
1167 format_component(buf_ch
, false, tmp_prefix
,
1168 port_in_iter
->upstream_component
);
1171 if (port_in_iter
->upstream_port
) {
1172 SET_TMP_PREFIX("upstream-port-");
1173 format_port(buf_ch
, false, tmp_prefix
,
1174 port_in_iter
->upstream_port
);
1177 if (port_in_iter
->connection
) {
1178 SET_TMP_PREFIX("upstream-conn-");
1179 format_connection(buf_ch
, false, tmp_prefix
,
1180 port_in_iter
->connection
);
1184 case BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT
:
1186 const struct bt_port_output_message_iterator
*port_out_iter
=
1187 (const void *) iterator
;
1189 if (port_out_iter
->graph
) {
1190 SET_TMP_PREFIX("graph-");
1191 format_graph(buf_ch
, false, tmp_prefix
,
1192 port_out_iter
->graph
);
1195 if (port_out_iter
->colander
) {
1196 SET_TMP_PREFIX("colander-comp-");
1197 format_component(buf_ch
, false, tmp_prefix
,
1198 (void *) port_out_iter
->colander
);
1208 static inline void format_plugin(char **buf_ch
, bool extended
,
1209 const char *prefix
, const struct bt_plugin
*plugin
)
1211 char tmp_prefix
[TMP_PREFIX_LEN
];
1213 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1215 if (plugin
->info
.path_set
) {
1216 BUF_APPEND(", %spath=\"%s\"",
1217 PRFIELD_GSTRING(plugin
->info
.path
));
1220 if (plugin
->info
.name_set
) {
1221 BUF_APPEND(", %sname=\"%s\"",
1222 PRFIELD_GSTRING(plugin
->info
.name
));
1229 if (plugin
->info
.author_set
) {
1230 BUF_APPEND(", %sauthor=\"%s\"",
1231 PRFIELD_GSTRING(plugin
->info
.author
));
1234 if (plugin
->info
.license_set
) {
1235 BUF_APPEND(", %slicense=\"%s\"",
1236 PRFIELD_GSTRING(plugin
->info
.license
));
1239 if (plugin
->info
.version_set
) {
1240 BUF_APPEND(", %sversion=%u.%u.%u%s",
1241 PRFIELD(plugin
->info
.version
.major
),
1242 plugin
->info
.version
.minor
,
1243 plugin
->info
.version
.patch
,
1244 plugin
->info
.version
.extra
?
1245 plugin
->info
.version
.extra
->str
: "");
1248 BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, "
1249 "%ssink-comp-class-count=%u",
1250 PRFIELD(plugin
->src_comp_classes
->len
),
1251 PRFIELD(plugin
->flt_comp_classes
->len
),
1252 PRFIELD(plugin
->sink_comp_classes
->len
));
1254 if (plugin
->spec_data
) {
1255 const struct bt_plugin_so_spec_data
*spec_data
=
1256 (const void *) plugin
->spec_data
;
1258 if (spec_data
->shared_lib_handle
) {
1259 SET_TMP_PREFIX("so-handle-");
1260 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1261 spec_data
->shared_lib_handle
);
1266 static inline void handle_conversion_specifier_bt(void *priv_data
,
1267 char **buf_ch
, size_t avail_size
,
1268 const char **out_fmt_ch
, va_list *args
)
1270 const char *fmt_ch
= *out_fmt_ch
;
1271 bool extended
= false;
1273 char *prefix_ch
= prefix
;
1279 if (*fmt_ch
== 'u') {
1281 obj
= va_arg(*args
, void *);
1282 format_uuid(buf_ch
, obj
);
1286 if (*fmt_ch
== '[') {
1291 if (*fmt_ch
== ']') {
1297 *prefix_ch
= *fmt_ch
;
1305 if (*fmt_ch
== '+') {
1310 obj
= va_arg(*args
, void *);
1311 BUF_APPEND("%saddr=%p", prefix
, obj
);
1319 format_field_class(buf_ch
, extended
, prefix
, obj
);
1322 format_field(buf_ch
, extended
, prefix
, obj
);
1325 format_field_path(buf_ch
, extended
, prefix
, obj
);
1328 format_event_class(buf_ch
, extended
, prefix
, obj
);
1331 format_event(buf_ch
, extended
, prefix
, obj
);
1334 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1337 format_stream(buf_ch
, extended
, prefix
, obj
);
1340 format_packet(buf_ch
, extended
, prefix
, obj
);
1343 format_trace(buf_ch
, extended
, prefix
, obj
);
1346 format_trace_class(buf_ch
, extended
, prefix
, obj
);
1349 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1352 format_clock_snapshot(buf_ch
, extended
, prefix
, obj
);
1355 format_value(buf_ch
, extended
, prefix
, obj
);
1358 format_message(buf_ch
, extended
, prefix
, obj
);
1361 format_message_iterator(buf_ch
, extended
, prefix
, obj
);
1364 format_component_class(buf_ch
, extended
, prefix
, obj
);
1367 format_component(buf_ch
, extended
, prefix
, obj
);
1370 format_port(buf_ch
, extended
, prefix
, obj
);
1373 format_connection(buf_ch
, extended
, prefix
, obj
);
1376 format_plugin(buf_ch
, extended
, prefix
, obj
);
1379 format_graph(buf_ch
, extended
, prefix
, obj
);
1382 format_object_pool(buf_ch
, extended
, prefix
, obj
);
1385 format_object(buf_ch
, extended
, prefix
, obj
);
1393 *out_fmt_ch
= fmt_ch
;
1396 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1397 int lvl
, const char *tag
, const char *fmt
, ...)
1402 va_start(args
, fmt
);
1403 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1404 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1406 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);