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/object-internal.h>
36 #include <babeltrace/ref-internal.h>
37 #include <babeltrace/values-internal.h>
38 #include <babeltrace/ctf-ir/field-types-internal.h>
39 #include <babeltrace/ctf-ir/fields-internal.h>
40 #include <babeltrace/ctf-ir/event-class-internal.h>
41 #include <babeltrace/ctf-ir/event-internal.h>
42 #include <babeltrace/ctf-ir/packet-internal.h>
43 #include <babeltrace/ctf-ir/stream-class-internal.h>
44 #include <babeltrace/ctf-ir/stream-internal.h>
45 #include <babeltrace/ctf-ir/trace-internal.h>
46 #include <babeltrace/ctf-ir/clock-class-internal.h>
47 #include <babeltrace/ctf-ir/clock-value-internal.h>
48 #include <babeltrace/ctf-ir/field-path-internal.h>
49 #include <babeltrace/ctf-ir/utils-internal.h>
50 #include <babeltrace/ctf-writer/field-types-internal.h>
51 #include <babeltrace/ctf-writer/fields-internal.h>
52 #include <babeltrace/ctf-writer/event-internal.h>
53 #include <babeltrace/ctf-writer/stream-class-internal.h>
54 #include <babeltrace/ctf-writer/stream-internal.h>
55 #include <babeltrace/ctf-writer/trace-internal.h>
56 #include <babeltrace/ctf-writer/clock-internal.h>
57 #include <babeltrace/ctf-writer/writer-internal.h>
58 #include <babeltrace/graph/clock-class-priority-map-internal.h>
59 #include <babeltrace/graph/component-class-internal.h>
60 #include <babeltrace/graph/component-class-sink-colander-internal.h>
61 #include <babeltrace/graph/component-filter-internal.h>
62 #include <babeltrace/graph/component-internal.h>
63 #include <babeltrace/graph/component-sink-internal.h>
64 #include <babeltrace/graph/component-source-internal.h>
65 #include <babeltrace/graph/connection-internal.h>
66 #include <babeltrace/graph/graph-internal.h>
67 #include <babeltrace/graph/notification-discarded-elements-internal.h>
68 #include <babeltrace/graph/notification-event-internal.h>
69 #include <babeltrace/graph/notification-heap-internal.h>
70 #include <babeltrace/graph/notification-inactivity-internal.h>
71 #include <babeltrace/graph/notification-internal.h>
72 #include <babeltrace/graph/notification-iterator-internal.h>
73 #include <babeltrace/graph/notification-packet-internal.h>
74 #include <babeltrace/graph/notification-stream-internal.h>
75 #include <babeltrace/graph/port-internal.h>
76 #include <babeltrace/plugin/plugin-internal.h>
77 #include <babeltrace/plugin/plugin-so-internal.h>
79 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
81 static char __thread lib_logging_buf
[LIB_LOGGING_BUF_SIZE
];
83 #define BUF_APPEND(_fmt, ...) \
86 size_t _size = LIB_LOGGING_BUF_SIZE - \
87 (size_t) (*buf_ch - lib_logging_buf); \
88 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
89 BT_ASSERT(_count >= 0); \
90 *buf_ch += MIN(_count, _size); \
91 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
96 #define BUF_APPEND_UUID(_uuid) \
97 BUF_APPEND(", %suuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"", \
99 (unsigned int) (_uuid)[0], \
100 (unsigned int) (_uuid)[1], \
101 (unsigned int) (_uuid)[2], \
102 (unsigned int) (_uuid)[3], \
103 (unsigned int) (_uuid)[4], \
104 (unsigned int) (_uuid)[5], \
105 (unsigned int) (_uuid)[6], \
106 (unsigned int) (_uuid)[7], \
107 (unsigned int) (_uuid)[8], \
108 (unsigned int) (_uuid)[9], \
109 (unsigned int) (_uuid)[10], \
110 (unsigned int) (_uuid)[11], \
111 (unsigned int) (_uuid)[12], \
112 (unsigned int) (_uuid)[13], \
113 (unsigned int) (_uuid)[14], \
114 (unsigned int) (_uuid)[15])
116 #define PRFIELD(_expr) prefix, (_expr)
118 #define SET_TMP_PREFIX(_prefix2) \
120 strcpy(tmp_prefix, prefix); \
121 strcat(tmp_prefix, (_prefix2)); \
124 typedef void (*format_func
)(char **, bool, const char *, void *);
126 static inline void format_component(char **buf_ch
, bool extended
,
127 const char *prefix
, struct bt_component
*component
);
129 static inline void format_port(char **buf_ch
, bool extended
,
130 const char *prefix
, struct bt_port
*port
);
132 static inline void format_connection(char **buf_ch
, bool extended
,
133 const char *prefix
, struct bt_connection
*connection
);
135 static inline void format_ref_count(char **buf_ch
, bool extended
,
136 const char *prefix
, struct bt_object
*obj
)
138 BUF_APPEND(", %sref-count=%lu", prefix
, obj
->ref_count
.count
);
141 static inline void format_field_type_common(char **buf_ch
, bool extended
,
142 const char *prefix
, struct bt_field_type_common
*field_type
)
144 BUF_APPEND(", %stype-id=%s, %salignment=%u",
145 PRFIELD(bt_common_field_type_id_string(field_type
->id
)),
146 PRFIELD(field_type
->alignment
));
149 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_type
->frozen
));
154 if (field_type
->id
== BT_FIELD_TYPE_ID_UNKNOWN
) {
158 switch (field_type
->id
) {
159 case BT_FIELD_TYPE_ID_INTEGER
:
161 struct bt_field_type_common_integer
*integer
=
162 BT_FROM_COMMON(field_type
);
164 BUF_APPEND(", %ssize=%u, %sis-signed=%d, %sbyte-order=%s, "
165 "%sbase=%d, %sencoding=%s, "
166 "%smapped-clock-class-addr=%p",
167 PRFIELD(integer
->size
), PRFIELD(integer
->is_signed
),
168 PRFIELD(bt_common_byte_order_string(integer
->user_byte_order
)),
169 PRFIELD(integer
->base
),
170 PRFIELD(bt_common_string_encoding_string(integer
->encoding
)),
171 PRFIELD(integer
->mapped_clock_class
));
173 if (integer
->mapped_clock_class
) {
174 BUF_APPEND(", %smapped-clock-class-name=\"%s\"",
175 PRFIELD(bt_clock_class_get_name(integer
->mapped_clock_class
)));
179 case BT_FIELD_TYPE_ID_FLOAT
:
181 struct bt_field_type_common_floating_point
*flt
=
182 BT_FROM_COMMON(field_type
);
184 BUF_APPEND(", %sexp-dig=%u, %smant-dig=%u, %sbyte-order=%s",
185 PRFIELD(flt
->exp_dig
), PRFIELD(flt
->mant_dig
),
186 PRFIELD(bt_common_byte_order_string(flt
->user_byte_order
)));
189 case BT_FIELD_TYPE_ID_ENUM
:
191 struct bt_field_type_common_enumeration
*enm
=
192 BT_FROM_COMMON(field_type
);
194 BUF_APPEND(", %smapping-count=%u",
195 PRFIELD(enm
->entries
->len
));
198 case BT_FIELD_TYPE_ID_STRING
:
200 struct bt_field_type_common_string
*str
=
201 BT_FROM_COMMON(field_type
);
203 BUF_APPEND(", %sencoding=%s",
204 PRFIELD(bt_common_string_encoding_string(str
->encoding
)));
207 case BT_FIELD_TYPE_ID_STRUCT
:
209 struct bt_field_type_common_structure
*structure
=
210 BT_FROM_COMMON(field_type
);
212 BUF_APPEND(", %sfield-count=%u",
213 PRFIELD(structure
->fields
->len
));
216 case BT_FIELD_TYPE_ID_SEQUENCE
:
218 struct bt_field_type_common_sequence
*seq
=
219 BT_FROM_COMMON(field_type
);
221 BUF_APPEND(", %slength-ft-addr=\"%s\", %selem-ft-addr=%p",
222 PRFIELD(seq
->length_field_name
->str
),
223 PRFIELD(seq
->element_ft
));
226 case BT_FIELD_TYPE_ID_VARIANT
:
228 struct bt_field_type_common_variant
*variant
=
229 BT_FROM_COMMON(field_type
);
231 BUF_APPEND(", %stag-name=\"%s\", %stag-ft-addr=%p, "
233 PRFIELD(variant
->tag_name
->str
),
234 PRFIELD(variant
->tag_ft
), PRFIELD(variant
->fields
->len
));
242 static inline void format_field_type(char **buf_ch
, bool extended
,
243 const char *prefix
, struct bt_field_type
*field_type
)
245 format_field_type_common(buf_ch
, extended
, prefix
,
246 (void *) field_type
);
249 static inline void format_writer_field_type(char **buf_ch
, bool extended
,
250 const char *prefix
, struct bt_ctf_field_type
*field_type
)
252 format_field_type_common(buf_ch
, extended
, prefix
,
253 (void *) field_type
);
256 static inline void format_field_common_integer_extended(char **buf_ch
,
257 const char *prefix
, struct bt_field_common
*field
)
259 struct bt_field_common_integer
*integer
= BT_FROM_COMMON(field
);
260 struct bt_field_type_common_integer
*field_type
=
261 BT_FROM_COMMON(field
->type
);
262 const char *fmt
= NULL
;
264 if (field_type
->base
== 8) {
265 fmt
= ", %svalue=%" PRIo64
;
266 } else if (field_type
->base
== 16) {
267 fmt
= ", %svalue=%" PRIx64
;
270 if (field_type
->is_signed
) {
272 fmt
= ", %svalue=%" PRId64
;
275 BUF_APPEND(fmt
, PRFIELD(integer
->payload
.signd
));
278 fmt
= ", %svalue=%" PRIu64
;
281 BUF_APPEND(fmt
, PRFIELD(integer
->payload
.unsignd
));
285 static inline void format_field_common(char **buf_ch
, bool extended
,
286 const char *prefix
, struct bt_field_common
*field
)
288 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->payload_set
));
291 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
294 BUF_APPEND(", %stype-addr=%p, %stype-id=%s",
295 PRFIELD(field
->type
),
296 PRFIELD(bt_common_field_type_id_string(field
->type
->id
)));
298 if (!extended
|| field
->type
->id
== BT_FIELD_TYPE_ID_UNKNOWN
||
299 !field
->payload_set
) {
303 switch (field
->type
->id
) {
304 case BT_FIELD_TYPE_ID_INTEGER
:
306 format_field_common_integer_extended(buf_ch
, prefix
, field
);
309 case BT_FIELD_TYPE_ID_FLOAT
:
311 struct bt_field_common_floating_point
*flt
=
312 BT_FROM_COMMON(field
);
314 BUF_APPEND(", %svalue=%f", PRFIELD(flt
->payload
));
317 case BT_FIELD_TYPE_ID_ENUM
:
319 struct bt_field_common_enumeration
*enm
=
320 BT_FROM_COMMON(field
);
323 format_field_common_integer_extended(buf_ch
, prefix
,
328 case BT_FIELD_TYPE_ID_STRING
:
330 struct bt_field_common_string
*str
=
331 BT_FROM_COMMON(field
);
333 BT_ASSERT(str
->payload
);
334 BUF_APPEND(", %spartial-value=\"%.32s\"",
335 PRFIELD(str
->payload
->str
));
338 case BT_FIELD_TYPE_ID_SEQUENCE
:
340 struct bt_field_common_sequence
*seq
=
341 BT_FROM_COMMON(field
);
343 BUF_APPEND(", %slength-field-addr=%p", PRFIELD(seq
->length
));
346 case BT_FIELD_TYPE_ID_VARIANT
:
348 struct bt_field_common_variant
*variant
=
349 BT_FROM_COMMON(field
);
351 BUF_APPEND(", %stag-field-addr=%p, %svalue-field-addr=%p",
352 PRFIELD(variant
->tag
), PRFIELD(variant
->payload
));
360 static inline void format_field(char **buf_ch
, bool extended
,
361 const char *prefix
, struct bt_field
*field
)
363 format_field_common(buf_ch
, extended
, prefix
, (void *) field
);
366 static inline void format_writer_field(char **buf_ch
, bool extended
,
367 const char *prefix
, struct bt_ctf_field
*field
)
369 format_field_common(buf_ch
, extended
, prefix
, (void *) field
);
372 static inline void format_field_path(char **buf_ch
, bool extended
,
373 const char *prefix
, struct bt_field_path
*field_path
)
377 BT_ASSERT(field_path
->indexes
);
378 BUF_APPEND(", %sindex-count=%u", PRFIELD(field_path
->indexes
->len
));
384 BUF_APPEND(", %spath=[%s", PRFIELD(bt_common_scope_string(field_path
->root
)));
386 for (i
= 0; i
< field_path
->indexes
->len
; i
++) {
387 int index
= g_array_index(field_path
->indexes
, int, i
);
389 BUF_APPEND(", %d", index
);
392 BUF_APPEND("%s", "]");
395 static inline void format_trace_common(char **buf_ch
, bool extended
,
396 const char *prefix
, struct bt_trace_common
*trace
)
399 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
->str
));
406 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace
->frozen
));
408 if (trace
->uuid_set
) {
409 BUF_APPEND_UUID(trace
->uuid
);
412 BUF_APPEND(", %sclock-class-count=%u, %sstream-class-count=%u, "
413 "%sstream-count=%u, %spacket-header-ft-addr=%p",
414 PRFIELD(trace
->clock_classes
->len
),
415 PRFIELD(trace
->stream_classes
->len
),
416 PRFIELD(trace
->streams
->len
),
417 PRFIELD(trace
->packet_header_field_type
));
420 static inline void format_trace(char **buf_ch
, bool extended
,
421 const char *prefix
, struct bt_trace
*trace
)
423 format_trace_common(buf_ch
, extended
, prefix
, BT_TO_COMMON(trace
));
426 BUF_APPEND(", %sis-static=%d", PRFIELD(trace
->is_static
));
430 static inline void format_writer_trace(char **buf_ch
, bool extended
,
431 const char *prefix
, struct bt_ctf_trace
*trace
)
433 format_trace_common(buf_ch
, extended
, prefix
, BT_TO_COMMON(trace
));
436 static inline void format_stream_class_common(char **buf_ch
, bool extended
,
437 const char *prefix
, struct bt_stream_class_common
*stream_class
,
438 format_func trace_format_func
)
440 struct bt_trace_common
*trace
;
443 if (stream_class
->id_set
) {
444 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(stream_class
->id
));
447 if (stream_class
->name
) {
448 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class
->name
->str
));
455 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
456 BUF_APPEND(", %sevent-class-count=%u, %spacket-context-ft-addr=%p, "
457 "%sevent-header-ft-addr=%p, %sevent-context-ft-addr=%p",
458 PRFIELD(stream_class
->event_classes
->len
),
459 PRFIELD(stream_class
->packet_context_field_type
),
460 PRFIELD(stream_class
->event_header_field_type
),
461 PRFIELD(stream_class
->event_context_field_type
));
462 trace
= bt_stream_class_common_borrow_trace(stream_class
);
467 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
468 SET_TMP_PREFIX("trace-");
469 trace_format_func(buf_ch
, false, tmp_prefix
, trace
);
472 static inline void format_stream_class(char **buf_ch
, bool extended
,
473 const char *prefix
, struct bt_stream_class
*stream_class
)
475 format_stream_class_common(buf_ch
, extended
, prefix
,
476 BT_TO_COMMON(stream_class
), (format_func
) format_trace
);
479 static inline void format_writer_stream_class(char **buf_ch
, bool extended
,
480 const char *prefix
, struct bt_ctf_stream_class
*stream_class
)
482 format_stream_class_common(buf_ch
, extended
, prefix
,
483 BT_TO_COMMON(stream_class
), (format_func
) format_writer_trace
);
485 if (extended
&& stream_class
->clock
) {
486 BUF_APPEND(", %sctf-writer-clock-addr=%p, "
487 "%sctf-writer-clock-name=\"%s\"",
488 PRFIELD(stream_class
->clock
),
489 PRFIELD(bt_clock_class_get_name(
490 BT_TO_COMMON(stream_class
->clock
->clock_class
))));
494 static inline void format_event_class_common(char **buf_ch
, bool extended
,
495 const char *prefix
, struct bt_event_class_common
*event_class
,
496 format_func format_stream_class_func
,
497 format_func format_trace_func
)
499 struct bt_stream_class_common
*stream_class
;
500 struct bt_trace_common
*trace
;
503 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(event_class
->id
));
505 if (event_class
->name
) {
506 BUF_APPEND(", %sname=\"%s\"", PRFIELD(event_class
->name
->str
));
513 BUF_APPEND(", %sis-frozen=%d, %slog-level=%s",
514 PRFIELD(event_class
->frozen
),
515 PRFIELD(bt_common_event_class_log_level_string(event_class
->log_level
)));
517 if (event_class
->emf_uri
) {
518 BUF_APPEND(", %semf-uri=\"%s\"",
519 PRFIELD(event_class
->emf_uri
->str
));
522 BUF_APPEND(", %scontext-ft-addr=%p, %spayload-ft-addr=%p",
523 PRFIELD(event_class
->context_field_type
),
524 PRFIELD(event_class
->payload_field_type
));
526 stream_class
= bt_event_class_common_borrow_stream_class(event_class
);
531 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
532 SET_TMP_PREFIX("stream-class-");
533 format_stream_class_func(buf_ch
, false, tmp_prefix
, stream_class
);
534 trace
= bt_stream_class_common_borrow_trace(stream_class
);
539 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
540 SET_TMP_PREFIX("trace-");
541 format_trace_func(buf_ch
, false, tmp_prefix
, trace
);
544 static inline void format_event_class(char **buf_ch
, bool extended
,
545 const char *prefix
, struct bt_event_class
*event_class
)
547 format_event_class_common(buf_ch
, extended
, prefix
,
548 BT_TO_COMMON(event_class
), (format_func
) format_stream_class
,
549 (format_func
) format_trace
);
552 static inline void format_writer_event_class(char **buf_ch
, bool extended
,
553 const char *prefix
, struct bt_ctf_event_class
*event_class
)
555 format_event_class_common(buf_ch
, extended
, prefix
,
556 BT_TO_COMMON(event_class
),
557 (format_func
) format_writer_stream_class
,
558 (format_func
) format_writer_trace
);
561 static inline void format_stream_common(char **buf_ch
, bool extended
,
562 const char *prefix
, struct bt_stream_common
*stream
,
563 format_func format_stream_class_func
,
564 format_func format_trace_func
)
566 struct bt_stream_class_common
*stream_class
;
567 struct bt_trace_common
*trace
;
570 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(stream
->id
));
573 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
->str
));
580 stream_class
= bt_stream_common_borrow_class(stream
);
585 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
586 SET_TMP_PREFIX("stream-class-");
587 format_stream_class_func(buf_ch
, false, tmp_prefix
, stream_class
);
588 trace
= bt_stream_class_common_borrow_trace(stream_class
);
593 trace
= (void *) bt_object_borrow_parent(stream
);
598 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
599 SET_TMP_PREFIX("trace-");
600 format_trace_common(buf_ch
, false, tmp_prefix
, trace
);
603 static inline void format_stream(char **buf_ch
, bool extended
,
604 const char *prefix
, struct bt_stream
*stream
)
606 format_stream_common(buf_ch
, extended
, prefix
, BT_TO_COMMON(stream
),
607 (format_func
) format_stream_class
,
608 (format_func
) format_trace
);
611 static inline void format_writer_stream(char **buf_ch
, bool extended
,
612 const char *prefix
, struct bt_ctf_stream
*stream
)
614 format_stream_common(buf_ch
, extended
, prefix
, BT_TO_COMMON(stream
),
615 (format_func
) format_writer_stream_class
,
616 (format_func
) format_writer_trace
);
618 BUF_APPEND(", %sheader-field-addr=%p, %scontext-field-addr=%p"
619 ", %sfd=%d, %smmap-offset=%zu, "
620 "%smmap-base-offset=%zu, %spacket-size=%" PRIu64
", "
621 "%soffset=%" PRId64
", %sevent-count=%u, "
622 "%sflushed-packet-count=%u, "
623 "%sdiscarded-event-count=%" PRIu64
", "
624 "%ssize=%" PRIu64
", %slast-ts-end=%" PRIu64
,
625 PRFIELD(stream
->packet_header
),
626 PRFIELD(stream
->packet_context
),
627 PRFIELD(stream
->pos
.fd
),
628 PRFIELD((size_t) stream
->pos
.mmap_offset
),
629 PRFIELD((size_t) stream
->pos
.mmap_base_offset
),
630 PRFIELD(stream
->pos
.packet_size
),
631 PRFIELD(stream
->pos
.offset
),
632 PRFIELD(stream
->events
->len
),
633 PRFIELD(stream
->flushed_packet_count
),
634 PRFIELD(stream
->discarded_events
),
635 PRFIELD(stream
->size
), PRFIELD(stream
->last_ts_end
));
638 static inline void format_packet(char **buf_ch
, bool extended
,
639 const char *prefix
, struct bt_packet
*packet
)
641 struct bt_stream
*stream
;
642 struct bt_trace
*trace
;
649 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
650 "%scontext-field-addr=%p",
651 PRFIELD(packet
->frozen
),
652 PRFIELD(packet
->header
),
653 PRFIELD(packet
->context
));
654 stream
= bt_packet_borrow_stream(packet
);
659 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
660 SET_TMP_PREFIX("stream-");
661 format_stream(buf_ch
, false, tmp_prefix
, stream
);
662 trace
= (struct bt_trace
*) bt_object_borrow_parent(stream
);
667 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
668 SET_TMP_PREFIX("trace-");
669 format_trace(buf_ch
, false, tmp_prefix
, trace
);
672 static inline void format_event_common(char **buf_ch
, bool extended
,
673 const char *prefix
, struct bt_event_common
*event
,
674 format_func format_event_class_func
,
675 format_func format_stream_class_func
,
676 format_func format_trace_func
)
678 struct bt_trace_common
*trace
;
679 struct bt_stream_class_common
*stream_class
;
686 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
687 "%sstream-context-field-addr=%p, "
688 "%scontext-field-addr=%p, %spayload-field-addr=%p, ",
689 PRFIELD(event
->frozen
),
690 PRFIELD(event
->header_field
),
691 PRFIELD(event
->stream_event_context_field
),
692 PRFIELD(event
->context_field
),
693 PRFIELD(event
->payload_field
));
694 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->class));
695 SET_TMP_PREFIX("event-class-");
696 format_event_class_func(buf_ch
, false, tmp_prefix
, event
->class);
697 stream_class
= bt_event_class_common_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_func(buf_ch
, false, tmp_prefix
,
704 trace
= bt_stream_class_common_borrow_trace(stream_class
);
706 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
707 SET_TMP_PREFIX("trace-");
708 format_trace_func(buf_ch
, false, tmp_prefix
, trace
);
713 static inline void format_event(char **buf_ch
, bool extended
,
714 const char *prefix
, struct bt_event
*event
)
716 struct bt_packet
*packet
;
717 struct bt_stream
*stream
;
720 format_event_common(buf_ch
, extended
, prefix
, BT_TO_COMMON(event
),
721 (format_func
) format_event_class
,
722 (format_func
) format_stream_class
, (format_func
) format_trace
);
728 BUF_APPEND(", %sclock-value-count=%u",
729 PRFIELD(g_hash_table_size(event
->clock_values
)));
731 packet
= bt_event_borrow_packet(event
);
736 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet
));
737 SET_TMP_PREFIX("packet-");
738 format_packet(buf_ch
, false, tmp_prefix
, packet
);
739 stream
= bt_packet_borrow_stream(packet
);
744 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
745 SET_TMP_PREFIX("stream-");
746 format_stream(buf_ch
, false, tmp_prefix
, stream
);
749 static inline void format_writer_event(char **buf_ch
, bool extended
,
750 const char *prefix
, struct bt_event
*event
)
752 format_event_common(buf_ch
, extended
, prefix
, BT_TO_COMMON(event
),
753 (format_func
) format_writer_event_class
,
754 (format_func
) format_writer_stream_class
,
755 (format_func
) format_writer_trace
);
758 static inline void format_clock_class(char **buf_ch
, bool extended
,
759 const char *prefix
, struct bt_clock_class
*clock_class
)
761 BUF_APPEND(", %sname=\"%s\", %sfreq=%" PRIu64
,
762 PRFIELD(clock_class
->name
->str
),
763 PRFIELD(clock_class
->frequency
));
769 if (clock_class
->description
) {
770 BUF_APPEND(", %spartial-description=\"%.32s\"",
771 PRFIELD(clock_class
->description
->str
));
774 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
775 "%soffset-s=%" PRId64
", "
776 "%soffset-cycles=%" PRId64
", %sis-absolute=%d",
777 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
778 PRFIELD(clock_class
->offset_s
), PRFIELD(clock_class
->offset
),
779 PRFIELD(clock_class
->absolute
));
781 if (clock_class
->uuid_set
) {
782 BUF_APPEND_UUID(clock_class
->uuid
);
786 static inline void format_clock_value(char **buf_ch
, bool extended
,
787 const char *prefix
, struct bt_clock_value
*clock_value
)
790 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-epoch=%" PRId64
,
791 PRFIELD(clock_value
->value
),
792 PRFIELD(clock_value
->ns_from_epoch
));
798 BUF_APPEND(", %sclock-class-addr=%p",
799 PRFIELD(clock_value
->clock_class
));
800 SET_TMP_PREFIX("clock-class-");
801 format_clock_class(buf_ch
, false, tmp_prefix
, clock_value
->clock_class
);
804 static inline void format_value(char **buf_ch
, bool extended
,
805 const char *prefix
, struct bt_value
*value
)
807 BUF_APPEND(", %stype=%s",
808 PRFIELD(bt_value_type_string(bt_value_get_type(value
))));
814 switch (bt_value_get_type(value
)) {
815 case BT_VALUE_TYPE_BOOL
:
819 (void) bt_value_bool_get(value
, &val
);
820 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
823 case BT_VALUE_TYPE_INTEGER
:
827 (void) bt_value_integer_get(value
, &val
);
828 BUF_APPEND(", %svalue=%" PRId64
, PRFIELD(val
));
831 case BT_VALUE_TYPE_FLOAT
:
835 (void) bt_value_float_get(value
, &val
);
836 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
839 case BT_VALUE_TYPE_STRING
:
843 (void) bt_value_string_get(value
, &val
);
844 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
847 case BT_VALUE_TYPE_ARRAY
:
849 int64_t count
= bt_value_array_size(value
);
851 BT_ASSERT(count
>= 0);
852 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
855 case BT_VALUE_TYPE_MAP
:
857 int64_t count
= bt_value_map_size(value
);
859 BT_ASSERT(count
>= 0);
860 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
868 static inline void format_notification(char **buf_ch
, bool extended
,
869 const char *prefix
, struct bt_notification
*notif
)
873 BUF_APPEND(", %stype=%s",
874 PRFIELD(bt_notification_type_string(notif
->type
)));
880 BUF_APPEND(", %sis-frozen=%d", PRFIELD(notif
->frozen
));
882 switch (notif
->type
) {
883 case BT_NOTIFICATION_TYPE_EVENT
:
885 struct bt_notification_event
*notif_event
= (void *) notif
;
887 SET_TMP_PREFIX("event-");
888 format_event(buf_ch
, true, tmp_prefix
, notif_event
->event
);
890 if (!notif_event
->cc_prio_map
) {
894 BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u",
895 PRFIELD(notif_event
->cc_prio_map
),
896 PRFIELD(notif_event
->cc_prio_map
->entries
->len
));
899 case BT_NOTIFICATION_TYPE_INACTIVITY
:
901 struct bt_notification_inactivity
*notif_inactivity
=
904 if (!notif_inactivity
->cc_prio_map
) {
908 BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u",
909 PRFIELD(notif_inactivity
->cc_prio_map
),
910 PRFIELD(notif_inactivity
->cc_prio_map
->entries
->len
));
913 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
915 struct bt_notification_stream_begin
*notif_stream
=
918 SET_TMP_PREFIX("stream-");
919 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
922 case BT_NOTIFICATION_TYPE_STREAM_END
:
924 struct bt_notification_stream_end
*notif_stream
=
927 SET_TMP_PREFIX("stream-");
928 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
931 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
933 struct bt_notification_packet_begin
*notif_packet
=
936 SET_TMP_PREFIX("packet-");
937 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
940 case BT_NOTIFICATION_TYPE_PACKET_END
:
942 struct bt_notification_packet_end
*notif_packet
=
945 SET_TMP_PREFIX("packet-");
946 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
949 case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS
:
950 case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS
:
952 struct bt_notification_discarded_elements
*notif_discarded
=
955 BUF_APPEND(", %scount=%" PRId64
,
956 PRFIELD(notif_discarded
->count
));
958 if (notif_discarded
->begin_clock_value
) {
959 SET_TMP_PREFIX("begin-clock-value-");
960 format_clock_value(buf_ch
, true, tmp_prefix
,
961 notif_discarded
->begin_clock_value
);
964 if (notif_discarded
->end_clock_value
) {
965 SET_TMP_PREFIX("end-clock-value-");
966 format_clock_value(buf_ch
, true, tmp_prefix
,
967 notif_discarded
->end_clock_value
);
976 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
978 struct bt_plugin_so_shared_lib_handle
*handle
)
980 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
983 BUF_APPEND(", %spath=\"%s\"", PRFIELD(handle
->path
->str
));
987 static inline void format_component_class(char **buf_ch
, bool extended
,
988 const char *prefix
, struct bt_component_class
*comp_class
)
992 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
993 PRFIELD(bt_component_class_type_string(comp_class
->type
)),
994 PRFIELD(comp_class
->name
->str
));
996 if (comp_class
->description
) {
997 BUF_APPEND(", %spartial-descr=\"%.32s\"",
998 PRFIELD(comp_class
->description
->str
));
1005 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
1007 if (comp_class
->so_handle
) {
1008 SET_TMP_PREFIX("so-handle-");
1009 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1010 comp_class
->so_handle
);
1014 static inline void format_component(char **buf_ch
, bool extended
,
1015 const char *prefix
, struct bt_component
*component
)
1017 char tmp_prefix
[64];
1019 BUF_APPEND(", %sname=\"%s\"", PRFIELD(component
->name
->str
));
1020 SET_TMP_PREFIX("class-");
1021 format_component_class(buf_ch
, extended
, tmp_prefix
, component
->class);
1027 BUF_APPEND(", %sinput-port-count=%u, %soutput-port-count=%u",
1028 PRFIELD(component
->input_ports
? component
->input_ports
->len
: 0),
1029 PRFIELD(component
->output_ports
? component
->output_ports
->len
: 0));
1032 static inline void format_port(char **buf_ch
, bool extended
,
1033 const char *prefix
, struct bt_port
*port
)
1035 char tmp_prefix
[64];
1037 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1038 PRFIELD(bt_port_type_string(port
->type
)),
1039 PRFIELD(port
->name
->str
));
1045 if (port
->connection
) {
1046 SET_TMP_PREFIX("conn-");
1047 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
1051 static inline void format_connection(char **buf_ch
, bool extended
,
1052 const char *prefix
, struct bt_connection
*connection
)
1054 char tmp_prefix
[64];
1060 if (connection
->upstream_port
) {
1061 SET_TMP_PREFIX("upstream-port-");
1062 format_port(buf_ch
, false, tmp_prefix
,
1063 connection
->upstream_port
);
1066 if (connection
->downstream_port
) {
1067 SET_TMP_PREFIX("downstream-port-");
1068 format_port(buf_ch
, false, tmp_prefix
,
1069 connection
->downstream_port
);
1073 static inline void format_graph(char **buf_ch
, bool extended
,
1074 const char *prefix
, struct bt_graph
*graph
)
1076 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph
->canceled
));
1082 BUF_APPEND(", %scomp-count=%u, %sconn-count=%u",
1083 PRFIELD(graph
->components
->len
),
1084 PRFIELD(graph
->connections
->len
));
1087 static inline void format_notification_iterator(char **buf_ch
,
1088 bool extended
, const char *prefix
,
1089 struct bt_notification_iterator
*iterator
)
1092 char tmp_prefix
[64];
1094 if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
) {
1095 type
= "BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION";
1096 } else if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
) {
1097 type
= "BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT";
1102 BUF_APPEND(", %stype=%s", PRFIELD(type
));
1104 switch (iterator
->type
) {
1105 case BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
:
1107 struct bt_notification_iterator_private_connection
*
1108 iter_priv_conn
= (void *) iterator
;
1110 if (iter_priv_conn
->upstream_component
) {
1111 SET_TMP_PREFIX("upstream-comp-");
1112 format_component(buf_ch
, false, tmp_prefix
,
1113 iter_priv_conn
->upstream_component
);
1116 if (iter_priv_conn
->upstream_port
) {
1117 SET_TMP_PREFIX("upstream-port-");
1118 format_port(buf_ch
, false, tmp_prefix
,
1119 iter_priv_conn
->upstream_port
);
1122 if (iter_priv_conn
->connection
) {
1123 SET_TMP_PREFIX("upstream-conn-");
1124 format_connection(buf_ch
, false, tmp_prefix
,
1125 iter_priv_conn
->connection
);
1129 case BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
:
1131 struct bt_notification_iterator_output_port
*iter_output_port
=
1134 SET_TMP_PREFIX("graph-");
1135 format_graph(buf_ch
, false, tmp_prefix
,
1136 iter_output_port
->graph
);
1137 SET_TMP_PREFIX("colander-comp-");
1138 format_component(buf_ch
, false, tmp_prefix
,
1139 iter_output_port
->colander
);
1140 SET_TMP_PREFIX("output-port-");
1141 format_port(buf_ch
, false, tmp_prefix
,
1142 iter_output_port
->output_port
);
1150 static inline void format_plugin(char **buf_ch
, bool extended
,
1151 const char *prefix
, struct bt_plugin
*plugin
)
1153 char tmp_prefix
[64];
1155 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1157 if (plugin
->info
.path_set
) {
1158 BUF_APPEND(", %spath=\"%s\"",
1159 PRFIELD(plugin
->info
.path
->str
));
1162 if (plugin
->info
.name_set
) {
1163 BUF_APPEND(", %sname=\"%s\"",
1164 PRFIELD(plugin
->info
.name
->str
));
1171 if (plugin
->info
.author_set
) {
1172 BUF_APPEND(", %sauthor=\"%s\"",
1173 PRFIELD(plugin
->info
.author
->str
));
1176 if (plugin
->info
.license_set
) {
1177 BUF_APPEND(", %slicense=\"%s\"",
1178 PRFIELD(plugin
->info
.license
->str
));
1181 if (plugin
->info
.version_set
) {
1182 BUF_APPEND(", %sversion=%u.%u.%u%s",
1183 PRFIELD(plugin
->info
.version
.major
),
1184 plugin
->info
.version
.minor
,
1185 plugin
->info
.version
.patch
,
1186 plugin
->info
.version
.extra
?
1187 plugin
->info
.version
.extra
->str
: "");
1190 BUF_APPEND(", %sis-frozen=%d, %scomp-class-count=%u",
1191 PRFIELD(plugin
->frozen
),
1192 PRFIELD(plugin
->comp_classes
->len
));
1194 if (plugin
->spec_data
) {
1195 struct bt_plugin_so_spec_data
*spec_data
=
1196 (void *) plugin
->spec_data
;
1198 if (spec_data
->shared_lib_handle
) {
1199 SET_TMP_PREFIX("so-handle-");
1200 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1201 spec_data
->shared_lib_handle
);
1206 static inline void format_ctf_writer(char **buf_ch
, bool extended
,
1207 const char *prefix
, struct bt_ctf_writer
*writer
)
1212 static inline void format_stream_class_common_common(char **buf_ch
,
1213 bool extended
, const char *prefix
,
1214 struct bt_stream_class_common
*stream_class
)
1216 format_stream_class_common(buf_ch
, extended
, prefix
, stream_class
,
1217 (format_func
) format_trace_common
);
1220 static inline void format_event_class_common_common(char **buf_ch
,
1221 bool extended
, const char *prefix
,
1222 struct bt_event_class_common
*event_class
)
1224 format_event_class_common(buf_ch
, extended
, prefix
, event_class
,
1225 (format_func
) format_stream_class_common
,
1226 (format_func
) format_trace_common
);
1229 static inline void format_event_common_common(char **buf_ch
,
1230 bool extended
, const char *prefix
,
1231 struct bt_event_common
*event
)
1233 format_event_common(buf_ch
, extended
, prefix
, event
,
1234 (format_func
) format_event_class_common
,
1235 (format_func
) format_stream_class_common
,
1236 (format_func
) format_trace_common
);
1239 static inline void format_stream_common_common(char **buf_ch
, bool extended
,
1240 const char *prefix
, struct bt_stream_common
*stream
)
1242 format_stream_common(buf_ch
, extended
, prefix
, stream
,
1243 (format_func
) format_stream_class_common
,
1244 (format_func
) format_trace_common
);
1247 static inline void handle_conversion_specifier_bt(void *priv_data
,
1248 char **buf_ch
, size_t avail_size
,
1249 const char **out_fmt_ch
, va_list *args
)
1251 const char *fmt_ch
= *out_fmt_ch
;
1252 bool extended
= false;
1254 char *prefix_ch
= prefix
;
1260 } cat
= CAT_DEFAULT
;
1265 if (*fmt_ch
== '[') {
1270 if (*fmt_ch
== ']') {
1276 *prefix_ch
= *fmt_ch
;
1284 if (*fmt_ch
== '+') {
1289 if (*fmt_ch
== 'w') {
1292 } else if (*fmt_ch
== '_') {
1297 obj
= va_arg(*args
, void *);
1298 BUF_APPEND("%saddr=%p", prefix
, obj
);
1308 format_ref_count(buf_ch
, extended
, prefix
, obj
);
1311 format_field_type(buf_ch
, extended
, prefix
, obj
);
1314 format_field(buf_ch
, extended
, prefix
, obj
);
1317 format_field_path(buf_ch
, extended
, prefix
, obj
);
1320 format_event_class(buf_ch
, extended
, prefix
, obj
);
1323 format_event(buf_ch
, extended
, prefix
, obj
);
1326 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1329 format_stream(buf_ch
, extended
, prefix
, obj
);
1332 format_packet(buf_ch
, extended
, prefix
, obj
);
1335 format_trace(buf_ch
, extended
, prefix
, obj
);
1338 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1341 format_clock_value(buf_ch
, extended
, prefix
, obj
);
1344 format_value(buf_ch
, extended
, prefix
, obj
);
1347 format_notification(buf_ch
, extended
, prefix
, obj
);
1350 format_notification_iterator(buf_ch
, extended
, prefix
, obj
);
1353 format_component_class(buf_ch
, extended
, prefix
, obj
);
1356 format_component(buf_ch
, extended
, prefix
, obj
);
1359 format_port(buf_ch
, extended
, prefix
, obj
);
1362 format_connection(buf_ch
, extended
, prefix
, obj
);
1365 format_plugin(buf_ch
, extended
, prefix
, obj
);
1368 format_graph(buf_ch
, extended
, prefix
, obj
);
1377 format_writer_field_type(buf_ch
, extended
, prefix
, obj
);
1380 format_writer_field(buf_ch
, extended
, prefix
, obj
);
1383 format_writer_event_class(buf_ch
, extended
, prefix
, obj
);
1386 format_writer_event(buf_ch
, extended
, prefix
, obj
);
1389 format_writer_stream_class(buf_ch
, extended
, prefix
, obj
);
1392 format_writer_stream(buf_ch
, extended
, prefix
, obj
);
1395 format_writer_trace(buf_ch
, extended
, prefix
, obj
);
1398 format_ctf_writer(buf_ch
, extended
, prefix
, obj
);
1407 format_field_type_common(buf_ch
, extended
, prefix
, obj
);
1410 format_field_common(buf_ch
, extended
, prefix
, obj
);
1413 format_event_class_common_common(buf_ch
, extended
, prefix
, obj
);
1416 format_event_common_common(buf_ch
, extended
, prefix
, obj
);
1419 format_stream_class_common_common(buf_ch
, extended
, prefix
, obj
);
1422 format_stream_common_common(buf_ch
, extended
, prefix
, obj
);
1425 format_trace_common(buf_ch
, extended
, prefix
, obj
);
1435 *out_fmt_ch
= fmt_ch
;
1439 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1440 int lvl
, const char *tag
, const char *fmt
, ...)
1445 va_start(args
, fmt
);
1446 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1447 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1449 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);