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
31 #include <babeltrace/common-internal.h>
32 #include <babeltrace/lib-logging-internal.h>
33 #include <babeltrace/object-internal.h>
34 #include <babeltrace/ref-internal.h>
35 #include <babeltrace/values-internal.h>
36 #include <babeltrace/ctf-ir/field-types-internal.h>
37 #include <babeltrace/ctf-ir/fields-internal.h>
38 #include <babeltrace/ctf-ir/event-class-internal.h>
39 #include <babeltrace/ctf-ir/event-internal.h>
40 #include <babeltrace/ctf-ir/packet-internal.h>
41 #include <babeltrace/ctf-ir/stream-class-internal.h>
42 #include <babeltrace/ctf-ir/stream-internal.h>
43 #include <babeltrace/ctf-ir/trace-internal.h>
44 #include <babeltrace/ctf-ir/clock-class-internal.h>
45 #include <babeltrace/ctf-ir/clock-value-internal.h>
46 #include <babeltrace/ctf-ir/field-path-internal.h>
47 #include <babeltrace/graph/clock-class-priority-map-internal.h>
48 #include <babeltrace/graph/component-class-internal.h>
49 #include <babeltrace/graph/component-class-sink-colander-internal.h>
50 #include <babeltrace/graph/component-filter-internal.h>
51 #include <babeltrace/graph/component-internal.h>
52 #include <babeltrace/graph/component-sink-internal.h>
53 #include <babeltrace/graph/component-source-internal.h>
54 #include <babeltrace/graph/connection-internal.h>
55 #include <babeltrace/graph/graph-internal.h>
56 #include <babeltrace/graph/notification-discarded-elements-internal.h>
57 #include <babeltrace/graph/notification-event-internal.h>
58 #include <babeltrace/graph/notification-heap-internal.h>
59 #include <babeltrace/graph/notification-inactivity-internal.h>
60 #include <babeltrace/graph/notification-internal.h>
61 #include <babeltrace/graph/notification-iterator-internal.h>
62 #include <babeltrace/graph/notification-packet-internal.h>
63 #include <babeltrace/graph/notification-stream-internal.h>
64 #include <babeltrace/graph/port-internal.h>
65 #include <babeltrace/plugin/plugin-internal.h>
66 #include <babeltrace/plugin/plugin-so-internal.h>
67 #include <babeltrace/ctf-writer/writer-internal.h>
68 #include <babeltrace/ctf-writer/clock-internal.h>
70 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
72 static char __thread lib_logging_buf
[LIB_LOGGING_BUF_SIZE
];
74 #define BUF_APPEND(_fmt, ...) \
77 size_t _size = LIB_LOGGING_BUF_SIZE - \
78 (size_t) (*buf_ch - lib_logging_buf); \
79 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
80 BT_ASSERT(_count >= 0); \
81 *buf_ch += MIN(_count, _size); \
82 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
87 #define BUF_APPEND_UUID(_uuid) \
88 BUF_APPEND(", %suuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"", \
90 (unsigned int) (_uuid)[0], \
91 (unsigned int) (_uuid)[1], \
92 (unsigned int) (_uuid)[2], \
93 (unsigned int) (_uuid)[3], \
94 (unsigned int) (_uuid)[4], \
95 (unsigned int) (_uuid)[5], \
96 (unsigned int) (_uuid)[6], \
97 (unsigned int) (_uuid)[7], \
98 (unsigned int) (_uuid)[8], \
99 (unsigned int) (_uuid)[9], \
100 (unsigned int) (_uuid)[10], \
101 (unsigned int) (_uuid)[11], \
102 (unsigned int) (_uuid)[12], \
103 (unsigned int) (_uuid)[13], \
104 (unsigned int) (_uuid)[14], \
105 (unsigned int) (_uuid)[15])
107 #define PRFIELD(_expr) prefix, (_expr)
109 #define SET_TMP_PREFIX(_prefix2) \
111 strcpy(tmp_prefix, prefix); \
112 strcat(tmp_prefix, (_prefix2)); \
115 static inline void format_component(char **buf_ch
, bool extended
,
116 const char *prefix
, struct bt_component
*component
);
118 static inline void format_port(char **buf_ch
, bool extended
,
119 const char *prefix
, struct bt_port
*port
);
121 static inline void format_connection(char **buf_ch
, bool extended
,
122 const char *prefix
, struct bt_connection
*connection
);
124 static inline void format_ref_count(char **buf_ch
, bool extended
,
125 const char *prefix
, struct bt_object
*obj
)
127 BUF_APPEND(", %sref-count=%lu", prefix
, obj
->ref_count
.count
);
130 static inline void format_field_type(char **buf_ch
, bool extended
,
131 const char *prefix
, struct bt_field_type
*field_type
)
133 BUF_APPEND(", %stype-id=%s, %salignment=%u",
134 PRFIELD(bt_field_type_id_string(field_type
->id
)),
135 PRFIELD(field_type
->alignment
));
138 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_type
->frozen
));
143 if (field_type
->id
== BT_FIELD_TYPE_ID_UNKNOWN
) {
147 switch (field_type
->id
) {
148 case BT_FIELD_TYPE_ID_INTEGER
:
150 struct bt_field_type_integer
*integer
= (void *) field_type
;
152 BUF_APPEND(", %ssize=%u, %sis-signed=%d, %sbyte-order=%s, "
153 "%sbase=%d, %sencoding=%s, "
154 "%smapped-clock-class-addr=%p",
155 PRFIELD(integer
->size
), PRFIELD(integer
->is_signed
),
156 PRFIELD(bt_byte_order_string(integer
->user_byte_order
)),
157 PRFIELD(integer
->base
),
158 PRFIELD(bt_string_encoding_string(integer
->encoding
)),
159 PRFIELD(integer
->mapped_clock
));
161 if (integer
->mapped_clock
) {
162 BUF_APPEND(", %smapped-clock-class-name=\"%s\"",
163 PRFIELD(bt_clock_class_get_name(integer
->mapped_clock
)));
167 case BT_FIELD_TYPE_ID_FLOAT
:
169 struct bt_field_type_floating_point
*flt
= (void *) field_type
;
171 BUF_APPEND(", %sexp-dig=%u, %smant-dig=%u, %sbyte-order=%s",
172 PRFIELD(flt
->exp_dig
), PRFIELD(flt
->mant_dig
),
173 PRFIELD(bt_byte_order_string(flt
->user_byte_order
)));
176 case BT_FIELD_TYPE_ID_ENUM
:
178 struct bt_field_type_enumeration
*enm
= (void *) field_type
;
180 BUF_APPEND(", %smapping-count=%u",
181 PRFIELD(enm
->entries
->len
));
184 case BT_FIELD_TYPE_ID_STRING
:
186 struct bt_field_type_string
*str
= (void *) field_type
;
188 BUF_APPEND(", %sencoding=%s",
189 PRFIELD(bt_string_encoding_string(str
->encoding
)));
192 case BT_FIELD_TYPE_ID_STRUCT
:
194 struct bt_field_type_structure
*structure
= (void *) field_type
;
196 BUF_APPEND(", %sfield-count=%u",
197 PRFIELD(structure
->fields
->len
));
200 case BT_FIELD_TYPE_ID_SEQUENCE
:
202 struct bt_field_type_sequence
*seq
= (void *) field_type
;
204 BUF_APPEND(", %slength-ft-addr=\"%s\", %selem-ft-addr=%p",
205 PRFIELD(seq
->length_field_name
->str
),
206 PRFIELD(seq
->element_type
));
209 case BT_FIELD_TYPE_ID_VARIANT
:
211 struct bt_field_type_variant
*variant
= (void *) field_type
;
213 BUF_APPEND(", %stag-name=\"%s\", %stag-ft-addr=%p, "
215 PRFIELD(variant
->tag_name
->str
),
216 PRFIELD(variant
->tag
), PRFIELD(variant
->fields
->len
));
224 static inline void format_field_integer_extended(char **buf_ch
,
225 const char *prefix
, struct bt_field
*field
)
227 struct bt_field_integer
*integer
= (void *) field
;
228 struct bt_field_type_integer
*field_type
= (void *) field
->type
;
229 const char *fmt
= NULL
;
231 if (field_type
->base
== 8) {
232 fmt
= ", %svalue=%" PRIo64
;
233 } else if (field_type
->base
== 16) {
234 fmt
= ", %svalue=%" PRIx64
;
237 if (field_type
->is_signed
) {
239 fmt
= ", %svalue=%" PRId64
;
242 BUF_APPEND(fmt
, PRFIELD(integer
->payload
.signd
));
245 fmt
= ", %svalue=%" PRIu64
;
248 BUF_APPEND(fmt
, PRFIELD(integer
->payload
.unsignd
));
252 static inline void format_field(char **buf_ch
, bool extended
,
253 const char *prefix
, struct bt_field
*field
)
255 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->payload_set
));
258 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
261 BUF_APPEND(", %stype-addr=%p, %stype-id=%s",
262 PRFIELD(field
->type
),
263 PRFIELD(bt_field_type_id_string(field
->type
->id
)));
265 if (!extended
|| field
->type
->id
== BT_FIELD_TYPE_ID_UNKNOWN
||
266 !field
->payload_set
) {
270 switch (field
->type
->id
) {
271 case BT_FIELD_TYPE_ID_INTEGER
:
273 format_field_integer_extended(buf_ch
, prefix
, field
);
276 case BT_FIELD_TYPE_ID_FLOAT
:
278 struct bt_field_floating_point
*flt
= (void *) field
;
280 BUF_APPEND(", %svalue=%f", PRFIELD(flt
->payload
));
283 case BT_FIELD_TYPE_ID_ENUM
:
285 struct bt_field_enumeration
*enm
= (void *) field
;
288 format_field_integer_extended(buf_ch
, prefix
,
293 case BT_FIELD_TYPE_ID_STRING
:
295 struct bt_field_string
*str
= (void *) field
;
297 BT_ASSERT(str
->payload
);
298 BUF_APPEND(", %spartial-value=\"%.32s\"",
299 PRFIELD(str
->payload
->str
));
302 case BT_FIELD_TYPE_ID_SEQUENCE
:
304 struct bt_field_sequence
*seq
= (void *) field
;
306 BUF_APPEND(", %slength-field-addr=%p", PRFIELD(seq
->length
));
309 case BT_FIELD_TYPE_ID_VARIANT
:
311 struct bt_field_variant
*variant
= (void *) field
;
313 BUF_APPEND(", %stag-field-addr=%p, %svalue-field-addr=%p",
314 PRFIELD(variant
->tag
), PRFIELD(variant
->payload
));
322 static inline void format_field_path(char **buf_ch
, bool extended
,
323 const char *prefix
, struct bt_field_path
*field_path
)
327 BT_ASSERT(field_path
->indexes
);
328 BUF_APPEND(", %sindex-count=%u", PRFIELD(field_path
->indexes
->len
));
334 BUF_APPEND(", %spath=[%s", PRFIELD(bt_scope_string(field_path
->root
)));
336 for (i
= 0; i
< field_path
->indexes
->len
; i
++) {
337 int index
= g_array_index(field_path
->indexes
, int, i
);
339 BUF_APPEND(", %d", index
);
342 BUF_APPEND("%s", "]");
345 static inline void format_trace(char **buf_ch
, bool extended
,
346 const char *prefix
, struct bt_trace
*trace
)
349 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
->str
));
356 BUF_APPEND(", %sis-frozen=%d, %sis-static=%d",
357 PRFIELD(trace
->frozen
), PRFIELD(trace
->is_static
));
359 if (trace
->uuid_set
) {
360 BUF_APPEND_UUID(trace
->uuid
);
363 BUF_APPEND(", %sclock-class-count=%u, %sstream-class-count=%u, "
364 "%sstream-count=%u, %sis-ctf-writer-trace=%d, "
365 "%spacket-header-ft-addr=%p",
366 PRFIELD(trace
->clocks
->len
),
367 PRFIELD(trace
->stream_classes
->len
),
368 PRFIELD(trace
->streams
->len
),
369 PRFIELD(trace
->is_created_by_writer
),
370 PRFIELD(trace
->packet_header_type
));
373 static inline void format_stream_class(char **buf_ch
, bool extended
,
374 const char *prefix
, struct bt_stream_class
*stream_class
)
376 struct bt_trace
*trace
;
379 if (stream_class
->id_set
) {
380 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(stream_class
->id
));
383 if (stream_class
->name
) {
384 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class
->name
->str
));
391 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
393 if (stream_class
->clock
) {
394 BUF_APPEND(", %sctf-writer-clock-addr=%p, "
395 "%sctf-writer-clock-name=\"%s\"",
396 PRFIELD(stream_class
->clock
),
397 PRFIELD(bt_clock_class_get_name(stream_class
->clock
->clock_class
)));
400 BUF_APPEND(", %sevent-class-count=%u, %spacket-context-ft-addr=%p, "
401 "%sevent-header-ft-addr=%p, %sevent-context-ft-addr=%p",
402 PRFIELD(stream_class
->event_classes
->len
),
403 PRFIELD(stream_class
->packet_context_type
),
404 PRFIELD(stream_class
->event_header_type
),
405 PRFIELD(stream_class
->event_context_type
));
406 trace
= bt_stream_class_borrow_trace(stream_class
);
411 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
412 SET_TMP_PREFIX("trace-");
413 format_trace(buf_ch
, false, tmp_prefix
, trace
);
416 static inline void format_event_class(char **buf_ch
, bool extended
,
417 const char *prefix
, struct bt_event_class
*event_class
)
419 struct bt_stream_class
*stream_class
;
420 struct bt_trace
*trace
;
423 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(event_class
->id
));
425 if (event_class
->name
) {
426 BUF_APPEND(", %sname=\"%s\"", PRFIELD(event_class
->name
->str
));
433 BUF_APPEND(", %sis-frozen=%d, %slog-level=%s",
434 PRFIELD(event_class
->frozen
),
435 PRFIELD(bt_event_class_log_level_string(event_class
->log_level
)));
437 if (event_class
->emf_uri
) {
438 BUF_APPEND(", %semf-uri=\"%s\"",
439 PRFIELD(event_class
->emf_uri
->str
));
442 BUF_APPEND(", %scontext-ft-addr=%p, %spayload-ft-addr=%p",
443 PRFIELD(event_class
->context
),
444 PRFIELD(event_class
->fields
));
446 stream_class
= bt_event_class_borrow_stream_class(event_class
);
451 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
452 SET_TMP_PREFIX("stream-class-");
453 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
454 trace
= bt_stream_class_borrow_trace(stream_class
);
459 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
460 SET_TMP_PREFIX("trace-");
461 format_trace(buf_ch
, false, tmp_prefix
, trace
);
464 static inline void format_stream(char **buf_ch
, bool extended
,
465 const char *prefix
, struct bt_stream
*stream
)
467 struct bt_stream_class
*stream_class
;
468 struct bt_trace
*trace
;
471 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(stream
->id
));
474 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
->str
));
477 BUF_APPEND(", %sis-ctf-writer-stream=%d",
478 PRFIELD(stream
->pos
.fd
!= -1));
484 if (stream
->pos
.fd
!= -1) {
485 BUF_APPEND(", %sheader-field-addr=%p, %scontext-field-addr=%p"
486 ", %sfd=%d, %smmap-offset=%zu, "
487 "%smmap-base-offset=%zu, %spacket-size=%" PRIu64
", "
488 "%soffset=%" PRId64
", %sevent-count=%u, "
489 "%sflushed-packet-count=%u, "
490 "%sdiscarded-event-count=%" PRIu64
", "
491 "%ssize=%" PRIu64
", %slast-ts-end=%" PRIu64
,
492 PRFIELD(stream
->packet_header
),
493 PRFIELD(stream
->packet_context
),
494 PRFIELD(stream
->pos
.fd
),
495 PRFIELD((size_t) stream
->pos
.mmap_offset
),
496 PRFIELD((size_t) stream
->pos
.mmap_base_offset
),
497 PRFIELD(stream
->pos
.packet_size
),
498 PRFIELD(stream
->pos
.offset
),
499 PRFIELD(stream
->events
->len
),
500 PRFIELD(stream
->flushed_packet_count
),
501 PRFIELD(stream
->discarded_events
),
502 PRFIELD(stream
->size
), PRFIELD(stream
->last_ts_end
));
505 stream_class
= bt_stream_borrow_stream_class(stream
);
510 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
511 SET_TMP_PREFIX("stream-class-");
512 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
513 trace
= bt_stream_class_borrow_trace(stream_class
);
518 trace
= (struct bt_trace
*) bt_object_borrow_parent(stream
);
523 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
524 SET_TMP_PREFIX("trace-");
525 format_trace(buf_ch
, false, tmp_prefix
, trace
);
528 static inline void format_packet(char **buf_ch
, bool extended
,
529 const char *prefix
, struct bt_packet
*packet
)
531 struct bt_stream
*stream
;
532 struct bt_trace
*trace
;
539 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
540 "%scontext-field-addr=%p",
541 PRFIELD(packet
->frozen
),
542 PRFIELD(packet
->header
),
543 PRFIELD(packet
->context
));
544 stream
= bt_packet_borrow_stream(packet
);
549 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
550 SET_TMP_PREFIX("stream-");
551 format_stream(buf_ch
, false, tmp_prefix
, stream
);
552 trace
= (struct bt_trace
*) bt_object_borrow_parent(stream
);
557 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
558 SET_TMP_PREFIX("trace-");
559 format_trace(buf_ch
, false, tmp_prefix
, trace
);
562 static inline void format_event(char **buf_ch
, bool extended
,
563 const char *prefix
, struct bt_event
*event
)
565 struct bt_trace
*trace
;
566 struct bt_stream_class
*stream_class
;
567 struct bt_packet
*packet
;
568 struct bt_stream
*stream
;
575 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
576 "%sstream-context-field-addr=%p, "
577 "%scontext-field-addr=%p, %spayload-field-addr=%p, "
578 "%sclock-value-count=%u",
579 PRFIELD(event
->frozen
),
580 PRFIELD(event
->event_header
),
581 PRFIELD(event
->stream_event_context
),
582 PRFIELD(event
->context_payload
),
583 PRFIELD(event
->fields_payload
),
584 PRFIELD(g_hash_table_size(event
->clock_values
)));
585 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->event_class
));
586 SET_TMP_PREFIX("event-class-");
587 format_event_class(buf_ch
, false, tmp_prefix
, event
->event_class
);
588 stream_class
= bt_event_class_borrow_stream_class(event
->event_class
);
590 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
591 SET_TMP_PREFIX("stream-class-");
592 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
594 trace
= bt_stream_class_borrow_trace(stream_class
);
596 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
597 SET_TMP_PREFIX("trace-");
598 format_trace(buf_ch
, false, tmp_prefix
, trace
);
602 packet
= bt_event_borrow_packet(event
);
607 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet
));
608 SET_TMP_PREFIX("packet-");
609 format_packet(buf_ch
, false, tmp_prefix
, packet
);
610 stream
= bt_packet_borrow_stream(packet
);
615 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
616 SET_TMP_PREFIX("stream-");
617 format_stream(buf_ch
, false, tmp_prefix
, stream
);
620 static inline void format_clock_class(char **buf_ch
, bool extended
,
621 const char *prefix
, struct bt_clock_class
*clock_class
)
623 BUF_APPEND(", %sname=\"%s\", %sfreq=%" PRIu64
,
624 PRFIELD(clock_class
->name
->str
),
625 PRFIELD(clock_class
->frequency
));
631 if (clock_class
->description
) {
632 BUF_APPEND(", %spartial-description=\"%.32s\"",
633 PRFIELD(clock_class
->description
->str
));
636 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
637 "%soffset-s=%" PRId64
", "
638 "%soffset-cycles=%" PRId64
", %sis-absolute=%d",
639 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
640 PRFIELD(clock_class
->offset_s
), PRFIELD(clock_class
->offset
),
641 PRFIELD(clock_class
->absolute
));
643 if (clock_class
->uuid_set
) {
644 BUF_APPEND_UUID(clock_class
->uuid
);
648 static inline void format_clock_value(char **buf_ch
, bool extended
,
649 const char *prefix
, struct bt_clock_value
*clock_value
)
652 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-epoch=%" PRId64
,
653 PRFIELD(clock_value
->value
),
654 PRFIELD(clock_value
->ns_from_epoch
));
660 BUF_APPEND(", %sclock-class-addr=%p",
661 PRFIELD(clock_value
->clock_class
));
662 SET_TMP_PREFIX("clock-class-");
663 format_clock_class(buf_ch
, false, tmp_prefix
, clock_value
->clock_class
);
666 static inline void format_value(char **buf_ch
, bool extended
,
667 const char *prefix
, struct bt_value
*value
)
669 BUF_APPEND(", %stype=%s",
670 PRFIELD(bt_value_type_string(bt_value_get_type(value
))));
676 switch (bt_value_get_type(value
)) {
677 case BT_VALUE_TYPE_BOOL
:
681 (void) bt_value_bool_get(value
, &val
);
682 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
685 case BT_VALUE_TYPE_INTEGER
:
689 (void) bt_value_integer_get(value
, &val
);
690 BUF_APPEND(", %svalue=%" PRId64
, PRFIELD(val
));
693 case BT_VALUE_TYPE_FLOAT
:
697 (void) bt_value_float_get(value
, &val
);
698 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
701 case BT_VALUE_TYPE_STRING
:
705 (void) bt_value_string_get(value
, &val
);
706 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
709 case BT_VALUE_TYPE_ARRAY
:
711 int64_t count
= bt_value_array_size(value
);
713 BT_ASSERT(count
>= 0);
714 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
717 case BT_VALUE_TYPE_MAP
:
719 int64_t count
= bt_value_map_size(value
);
721 BT_ASSERT(count
>= 0);
722 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
730 static inline void format_notification(char **buf_ch
, bool extended
,
731 const char *prefix
, struct bt_notification
*notif
)
735 BUF_APPEND(", %stype=%s",
736 PRFIELD(bt_notification_type_string(notif
->type
)));
742 BUF_APPEND(", %sis-frozen=%d", PRFIELD(notif
->frozen
));
744 switch (notif
->type
) {
745 case BT_NOTIFICATION_TYPE_EVENT
:
747 struct bt_notification_event
*notif_event
= (void *) notif
;
749 SET_TMP_PREFIX("event-");
750 format_event(buf_ch
, true, tmp_prefix
, notif_event
->event
);
752 if (!notif_event
->cc_prio_map
) {
756 BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u",
757 PRFIELD(notif_event
->cc_prio_map
),
758 PRFIELD(notif_event
->cc_prio_map
->entries
->len
));
761 case BT_NOTIFICATION_TYPE_INACTIVITY
:
763 struct bt_notification_inactivity
*notif_inactivity
=
766 if (!notif_inactivity
->cc_prio_map
) {
770 BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u",
771 PRFIELD(notif_inactivity
->cc_prio_map
),
772 PRFIELD(notif_inactivity
->cc_prio_map
->entries
->len
));
775 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
777 struct bt_notification_stream_begin
*notif_stream
=
780 SET_TMP_PREFIX("stream-");
781 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
784 case BT_NOTIFICATION_TYPE_STREAM_END
:
786 struct bt_notification_stream_end
*notif_stream
=
789 SET_TMP_PREFIX("stream-");
790 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
793 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
795 struct bt_notification_packet_begin
*notif_packet
=
798 SET_TMP_PREFIX("packet-");
799 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
802 case BT_NOTIFICATION_TYPE_PACKET_END
:
804 struct bt_notification_packet_end
*notif_packet
=
807 SET_TMP_PREFIX("packet-");
808 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
811 case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS
:
812 case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS
:
814 struct bt_notification_discarded_elements
*notif_discarded
=
817 BUF_APPEND(", %scount=%" PRId64
,
818 PRFIELD(notif_discarded
->count
));
820 if (notif_discarded
->begin_clock_value
) {
821 SET_TMP_PREFIX("begin-clock-value-");
822 format_clock_value(buf_ch
, true, tmp_prefix
,
823 notif_discarded
->begin_clock_value
);
826 if (notif_discarded
->end_clock_value
) {
827 SET_TMP_PREFIX("end-clock-value-");
828 format_clock_value(buf_ch
, true, tmp_prefix
,
829 notif_discarded
->end_clock_value
);
838 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
840 struct bt_plugin_so_shared_lib_handle
*handle
)
842 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
845 BUF_APPEND(", %spath=\"%s\"", PRFIELD(handle
->path
->str
));
849 static inline void format_component_class(char **buf_ch
, bool extended
,
850 const char *prefix
, struct bt_component_class
*comp_class
)
854 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
855 PRFIELD(bt_component_class_type_string(comp_class
->type
)),
856 PRFIELD(comp_class
->name
->str
));
858 if (comp_class
->description
) {
859 BUF_APPEND(", %spartial-descr=\"%.32s\"",
860 PRFIELD(comp_class
->description
->str
));
867 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
869 if (comp_class
->so_handle
) {
870 SET_TMP_PREFIX("so-handle-");
871 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
872 comp_class
->so_handle
);
876 static inline void format_component(char **buf_ch
, bool extended
,
877 const char *prefix
, struct bt_component
*component
)
881 BUF_APPEND(", %sname=\"%s\"", PRFIELD(component
->name
->str
));
882 SET_TMP_PREFIX("class-");
883 format_component_class(buf_ch
, extended
, tmp_prefix
, component
->class);
889 BUF_APPEND(", %sinput-port-count=%u, %soutput-port-count=%u",
890 PRFIELD(component
->input_ports
? component
->input_ports
->len
: 0),
891 PRFIELD(component
->output_ports
? component
->output_ports
->len
: 0));
894 static inline void format_port(char **buf_ch
, bool extended
,
895 const char *prefix
, struct bt_port
*port
)
899 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
900 PRFIELD(bt_port_type_string(port
->type
)),
901 PRFIELD(port
->name
->str
));
907 if (port
->connection
) {
908 SET_TMP_PREFIX("conn-");
909 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
913 static inline void format_connection(char **buf_ch
, bool extended
,
914 const char *prefix
, struct bt_connection
*connection
)
922 if (connection
->upstream_port
) {
923 SET_TMP_PREFIX("upstream-port-");
924 format_port(buf_ch
, false, tmp_prefix
,
925 connection
->upstream_port
);
928 if (connection
->downstream_port
) {
929 SET_TMP_PREFIX("downstream-port-");
930 format_port(buf_ch
, false, tmp_prefix
,
931 connection
->downstream_port
);
935 static inline void format_graph(char **buf_ch
, bool extended
,
936 const char *prefix
, struct bt_graph
*graph
)
938 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph
->canceled
));
944 BUF_APPEND(", %scomp-count=%u, %sconn-count=%u",
945 PRFIELD(graph
->components
->len
),
946 PRFIELD(graph
->connections
->len
));
949 static inline void format_notification_iterator(char **buf_ch
,
950 bool extended
, const char *prefix
,
951 struct bt_notification_iterator
*iterator
)
956 if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
) {
957 type
= "BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION";
958 } else if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
) {
959 type
= "BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT";
964 BUF_APPEND(", %stype=%s", PRFIELD(type
));
966 switch (iterator
->type
) {
967 case BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
:
969 struct bt_notification_iterator_private_connection
*
970 iter_priv_conn
= (void *) iterator
;
972 if (iter_priv_conn
->upstream_component
) {
973 SET_TMP_PREFIX("upstream-comp-");
974 format_component(buf_ch
, false, tmp_prefix
,
975 iter_priv_conn
->upstream_component
);
978 if (iter_priv_conn
->upstream_port
) {
979 SET_TMP_PREFIX("upstream-port-");
980 format_port(buf_ch
, false, tmp_prefix
,
981 iter_priv_conn
->upstream_port
);
984 if (iter_priv_conn
->connection
) {
985 SET_TMP_PREFIX("upstream-conn-");
986 format_connection(buf_ch
, false, tmp_prefix
,
987 iter_priv_conn
->connection
);
991 case BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
:
993 struct bt_notification_iterator_output_port
*iter_output_port
=
996 SET_TMP_PREFIX("graph-");
997 format_graph(buf_ch
, false, tmp_prefix
,
998 iter_output_port
->graph
);
999 SET_TMP_PREFIX("colander-comp-");
1000 format_component(buf_ch
, false, tmp_prefix
,
1001 iter_output_port
->colander
);
1002 SET_TMP_PREFIX("output-port-");
1003 format_port(buf_ch
, false, tmp_prefix
,
1004 iter_output_port
->output_port
);
1012 static inline void format_plugin(char **buf_ch
, bool extended
,
1013 const char *prefix
, struct bt_plugin
*plugin
)
1015 char tmp_prefix
[64];
1017 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1019 if (plugin
->info
.path_set
) {
1020 BUF_APPEND(", %spath=\"%s\"",
1021 PRFIELD(plugin
->info
.path
->str
));
1024 if (plugin
->info
.name_set
) {
1025 BUF_APPEND(", %sname=\"%s\"",
1026 PRFIELD(plugin
->info
.name
->str
));
1033 if (plugin
->info
.author_set
) {
1034 BUF_APPEND(", %sauthor=\"%s\"",
1035 PRFIELD(plugin
->info
.author
->str
));
1038 if (plugin
->info
.license_set
) {
1039 BUF_APPEND(", %slicense=\"%s\"",
1040 PRFIELD(plugin
->info
.license
->str
));
1043 if (plugin
->info
.version_set
) {
1044 BUF_APPEND(", %sversion=%u.%u.%u%s",
1045 PRFIELD(plugin
->info
.version
.major
),
1046 plugin
->info
.version
.minor
,
1047 plugin
->info
.version
.patch
,
1048 plugin
->info
.version
.extra
?
1049 plugin
->info
.version
.extra
->str
: "");
1052 BUF_APPEND(", %sis-frozen=%d, %scomp-class-count=%u",
1053 PRFIELD(plugin
->frozen
),
1054 PRFIELD(plugin
->comp_classes
->len
));
1056 if (plugin
->spec_data
) {
1057 struct bt_plugin_so_spec_data
*spec_data
=
1058 (void *) plugin
->spec_data
;
1060 if (spec_data
->shared_lib_handle
) {
1061 SET_TMP_PREFIX("so-handle-");
1062 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1063 spec_data
->shared_lib_handle
);
1068 static inline void format_ctf_writer(char **buf_ch
, bool extended
,
1069 const char *prefix
, struct bt_ctf_writer
*writer
)
1074 static inline void handle_conversion_specifier_bt(void *priv_data
,
1075 char **buf_ch
, size_t avail_size
,
1076 const char **out_fmt_ch
, va_list *args
)
1078 const char *fmt_ch
= *out_fmt_ch
;
1079 bool extended
= false;
1081 char *prefix_ch
= prefix
;
1087 if (*fmt_ch
== '[') {
1092 if (*fmt_ch
== ']') {
1098 *prefix_ch
= *fmt_ch
;
1106 if (*fmt_ch
== '+') {
1111 obj
= va_arg(*args
, void *);
1112 BUF_APPEND("%saddr=%p", prefix
, obj
);
1120 format_ref_count(buf_ch
, extended
, prefix
, obj
);
1123 format_field_type(buf_ch
, extended
, prefix
, obj
);
1126 format_field(buf_ch
, extended
, prefix
, obj
);
1129 format_field_path(buf_ch
, extended
, prefix
, obj
);
1132 format_event_class(buf_ch
, extended
, prefix
, obj
);
1135 format_event(buf_ch
, extended
, prefix
, obj
);
1138 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1141 format_stream(buf_ch
, extended
, prefix
, obj
);
1144 format_packet(buf_ch
, extended
, prefix
, obj
);
1147 format_trace(buf_ch
, extended
, prefix
, obj
);
1150 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1153 format_clock_value(buf_ch
, extended
, prefix
, obj
);
1156 format_value(buf_ch
, extended
, prefix
, obj
);
1159 format_notification(buf_ch
, extended
, prefix
, obj
);
1162 format_notification_iterator(buf_ch
, extended
, prefix
, obj
);
1165 format_component_class(buf_ch
, extended
, prefix
, obj
);
1168 format_component(buf_ch
, extended
, prefix
, obj
);
1171 format_port(buf_ch
, extended
, prefix
, obj
);
1174 format_connection(buf_ch
, extended
, prefix
, obj
);
1177 format_plugin(buf_ch
, extended
, prefix
, obj
);
1180 format_graph(buf_ch
, extended
, prefix
, obj
);
1183 format_ctf_writer(buf_ch
, extended
, prefix
, obj
);
1191 *out_fmt_ch
= fmt_ch
;
1195 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1196 int lvl
, const char *tag
, const char *fmt
, ...)
1201 va_start(args
, fmt
);
1202 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1203 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1205 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);