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
32 #include <babeltrace/common-internal.h>
33 #include <babeltrace/lib-logging-internal.h>
34 #include <babeltrace/object-internal.h>
35 #include <babeltrace/ref-internal.h>
36 #include <babeltrace/values-internal.h>
37 #include <babeltrace/ctf-ir/field-types-internal.h>
38 #include <babeltrace/ctf-ir/fields-internal.h>
39 #include <babeltrace/ctf-ir/event-class-internal.h>
40 #include <babeltrace/ctf-ir/event-internal.h>
41 #include <babeltrace/ctf-ir/packet-internal.h>
42 #include <babeltrace/ctf-ir/stream-class-internal.h>
43 #include <babeltrace/ctf-ir/stream-internal.h>
44 #include <babeltrace/ctf-ir/trace-internal.h>
45 #include <babeltrace/ctf-ir/clock-class-internal.h>
46 #include <babeltrace/ctf-ir/clock-value-internal.h>
47 #include <babeltrace/ctf-ir/field-path-internal.h>
48 #include <babeltrace/graph/clock-class-priority-map-internal.h>
49 #include <babeltrace/graph/component-class-internal.h>
50 #include <babeltrace/graph/component-class-sink-colander-internal.h>
51 #include <babeltrace/graph/component-filter-internal.h>
52 #include <babeltrace/graph/component-internal.h>
53 #include <babeltrace/graph/component-sink-internal.h>
54 #include <babeltrace/graph/component-source-internal.h>
55 #include <babeltrace/graph/connection-internal.h>
56 #include <babeltrace/graph/graph-internal.h>
57 #include <babeltrace/graph/notification-discarded-elements-internal.h>
58 #include <babeltrace/graph/notification-event-internal.h>
59 #include <babeltrace/graph/notification-heap-internal.h>
60 #include <babeltrace/graph/notification-inactivity-internal.h>
61 #include <babeltrace/graph/notification-internal.h>
62 #include <babeltrace/graph/notification-iterator-internal.h>
63 #include <babeltrace/graph/notification-packet-internal.h>
64 #include <babeltrace/graph/notification-stream-internal.h>
65 #include <babeltrace/graph/port-internal.h>
66 #include <babeltrace/plugin/plugin-internal.h>
67 #include <babeltrace/plugin/plugin-so-internal.h>
68 #include <babeltrace/ctf-writer/writer-internal.h>
69 #include <babeltrace/ctf-writer/clock-internal.h>
71 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
73 static char __thread lib_logging_buf
[LIB_LOGGING_BUF_SIZE
];
75 #define BUF_APPEND(_fmt, ...) \
78 size_t _size = LIB_LOGGING_BUF_SIZE - \
79 (size_t) (*buf_ch - lib_logging_buf); \
80 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
81 assert(_count >= 0); \
82 *buf_ch += MIN(_count, _size); \
83 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
88 #define BUF_APPEND_UUID(_uuid) \
89 BUF_APPEND(", %suuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"", \
91 (unsigned int) (_uuid)[0], \
92 (unsigned int) (_uuid)[1], \
93 (unsigned int) (_uuid)[2], \
94 (unsigned int) (_uuid)[3], \
95 (unsigned int) (_uuid)[4], \
96 (unsigned int) (_uuid)[5], \
97 (unsigned int) (_uuid)[6], \
98 (unsigned int) (_uuid)[7], \
99 (unsigned int) (_uuid)[8], \
100 (unsigned int) (_uuid)[9], \
101 (unsigned int) (_uuid)[10], \
102 (unsigned int) (_uuid)[11], \
103 (unsigned int) (_uuid)[12], \
104 (unsigned int) (_uuid)[13], \
105 (unsigned int) (_uuid)[14], \
106 (unsigned int) (_uuid)[15])
108 #define PRFIELD(_expr) prefix, (_expr)
110 #define SET_TMP_PREFIX(_prefix2) \
112 strcpy(tmp_prefix, prefix); \
113 strcat(tmp_prefix, (_prefix2)); \
116 static inline void format_component(char **buf_ch
, bool extended
,
117 const char *prefix
, struct bt_component
*component
);
119 static inline void format_port(char **buf_ch
, bool extended
,
120 const char *prefix
, struct bt_port
*port
);
122 static inline void format_connection(char **buf_ch
, bool extended
,
123 const char *prefix
, struct bt_connection
*connection
);
125 static inline void format_ref_count(char **buf_ch
, bool extended
,
126 const char *prefix
, struct bt_object
*obj
)
128 BUF_APPEND(", %sref-count=%lu", prefix
, obj
->ref_count
.count
);
131 static inline void format_field_type(char **buf_ch
, bool extended
,
132 const char *prefix
, struct bt_field_type
*field_type
)
134 BUF_APPEND(", %stype-id=%s, %salignment=%u",
135 PRFIELD(bt_field_type_id_string(field_type
->id
)),
136 PRFIELD(field_type
->alignment
));
139 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_type
->frozen
));
144 if (field_type
->id
== BT_FIELD_TYPE_ID_UNKNOWN
) {
148 switch (field_type
->id
) {
149 case BT_FIELD_TYPE_ID_INTEGER
:
151 struct bt_field_type_integer
*integer
= (void *) field_type
;
153 BUF_APPEND(", %ssize=%u, %sis-signed=%d, %sbyte-order=%s, "
154 "%sbase=%d, %sencoding=%s, "
155 "%smapped-clock-class-addr=%p",
156 PRFIELD(integer
->size
), PRFIELD(integer
->is_signed
),
157 PRFIELD(bt_byte_order_string(integer
->user_byte_order
)),
158 PRFIELD(integer
->base
),
159 PRFIELD(bt_string_encoding_string(integer
->encoding
)),
160 PRFIELD(integer
->mapped_clock
));
162 if (integer
->mapped_clock
) {
163 BUF_APPEND(", %smapped-clock-class-name=\"%s\"",
164 PRFIELD(bt_clock_class_get_name(integer
->mapped_clock
)));
168 case BT_FIELD_TYPE_ID_FLOAT
:
170 struct bt_field_type_floating_point
*flt
= (void *) field_type
;
172 BUF_APPEND(", %sexp-dig=%u, %smant-dig=%u, %sbyte-order=%s",
173 PRFIELD(flt
->exp_dig
), PRFIELD(flt
->mant_dig
),
174 PRFIELD(bt_byte_order_string(flt
->user_byte_order
)));
177 case BT_FIELD_TYPE_ID_ENUM
:
179 struct bt_field_type_enumeration
*enm
= (void *) field_type
;
181 BUF_APPEND(", %smapping-count=%u",
182 PRFIELD(enm
->entries
->len
));
185 case BT_FIELD_TYPE_ID_STRING
:
187 struct bt_field_type_string
*str
= (void *) field_type
;
189 BUF_APPEND(", %sencoding=%s",
190 PRFIELD(bt_string_encoding_string(str
->encoding
)));
193 case BT_FIELD_TYPE_ID_STRUCT
:
195 struct bt_field_type_structure
*structure
= (void *) field_type
;
197 BUF_APPEND(", %sfield-count=%u",
198 PRFIELD(structure
->fields
->len
));
201 case BT_FIELD_TYPE_ID_SEQUENCE
:
203 struct bt_field_type_sequence
*seq
= (void *) field_type
;
205 BUF_APPEND(", %slength-ft-addr=\"%s\", %selem-ft-addr=%p",
206 PRFIELD(seq
->length_field_name
->str
),
207 PRFIELD(seq
->element_type
));
210 case BT_FIELD_TYPE_ID_VARIANT
:
212 struct bt_field_type_variant
*variant
= (void *) field_type
;
214 BUF_APPEND(", %stag-name=\"%s\", %stag-ft-addr=%p, "
216 PRFIELD(variant
->tag_name
->str
),
217 PRFIELD(variant
->tag
), PRFIELD(variant
->fields
->len
));
225 static inline void format_field_integer_extended(char **buf_ch
,
226 const char *prefix
, struct bt_field
*field
)
228 struct bt_field_integer
*integer
= (void *) field
;
229 struct bt_field_type_integer
*field_type
= (void *) field
->type
;
230 const char *fmt
= NULL
;
232 if (field_type
->base
== 8) {
233 fmt
= ", %svalue=%" PRIo64
;
234 } else if (field_type
->base
== 16) {
235 fmt
= ", %svalue=%" PRIx64
;
238 if (field_type
->is_signed
) {
240 fmt
= ", %svalue=%" PRId64
;
243 BUF_APPEND(fmt
, PRFIELD(integer
->payload
.signd
));
246 fmt
= ", %svalue=%" PRIu64
;
249 BUF_APPEND(fmt
, PRFIELD(integer
->payload
.unsignd
));
253 static inline void format_field(char **buf_ch
, bool extended
,
254 const char *prefix
, struct bt_field
*field
)
256 BUF_APPEND(", %sis-set=%d", PRFIELD(field
->payload_set
));
259 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field
->frozen
));
262 BUF_APPEND(", %stype-addr=%p, %stype-id=%s",
263 PRFIELD(field
->type
),
264 PRFIELD(bt_field_type_id_string(field
->type
->id
)));
266 if (!extended
|| field
->type
->id
== BT_FIELD_TYPE_ID_UNKNOWN
||
267 !field
->payload_set
) {
271 switch (field
->type
->id
) {
272 case BT_FIELD_TYPE_ID_INTEGER
:
274 format_field_integer_extended(buf_ch
, prefix
, field
);
277 case BT_FIELD_TYPE_ID_FLOAT
:
279 struct bt_field_floating_point
*flt
= (void *) field
;
281 BUF_APPEND(", %svalue=%f", PRFIELD(flt
->payload
));
284 case BT_FIELD_TYPE_ID_ENUM
:
286 struct bt_field_enumeration
*enm
= (void *) field
;
289 format_field_integer_extended(buf_ch
, prefix
,
294 case BT_FIELD_TYPE_ID_STRING
:
296 struct bt_field_string
*str
= (void *) field
;
298 assert(str
->payload
);
299 BUF_APPEND(", %spartial-value=\"%.32s\"",
300 PRFIELD(str
->payload
->str
));
303 case BT_FIELD_TYPE_ID_SEQUENCE
:
305 struct bt_field_sequence
*seq
= (void *) field
;
307 BUF_APPEND(", %slength-field-addr=%p", PRFIELD(seq
->length
));
310 case BT_FIELD_TYPE_ID_VARIANT
:
312 struct bt_field_variant
*variant
= (void *) field
;
314 BUF_APPEND(", %stag-field-addr=%p, %svalue-field-addr=%p",
315 PRFIELD(variant
->tag
), PRFIELD(variant
->payload
));
323 static inline void format_field_path(char **buf_ch
, bool extended
,
324 const char *prefix
, struct bt_field_path
*field_path
)
328 assert(field_path
->indexes
);
329 BUF_APPEND(", %sindex-count=%u", PRFIELD(field_path
->indexes
->len
));
335 BUF_APPEND(", %spath=[%s", PRFIELD(bt_scope_string(field_path
->root
)));
337 for (i
= 0; i
< field_path
->indexes
->len
; i
++) {
338 int index
= g_array_index(field_path
->indexes
, int, i
);
340 BUF_APPEND(", %d", index
);
343 BUF_APPEND("%s", "]");
346 static inline void format_trace(char **buf_ch
, bool extended
,
347 const char *prefix
, struct bt_trace
*trace
)
350 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace
->name
->str
));
357 BUF_APPEND(", %sis-frozen=%d, %sis-static=%d",
358 PRFIELD(trace
->frozen
), PRFIELD(trace
->is_static
));
360 if (trace
->uuid_set
) {
361 BUF_APPEND_UUID(trace
->uuid
);
364 BUF_APPEND(", %sclock-class-count=%u, %sstream-class-count=%u, "
365 "%sstream-count=%u, %sis-ctf-writer-trace=%d, "
366 "%spacket-header-ft-addr=%p",
367 PRFIELD(trace
->clocks
->len
),
368 PRFIELD(trace
->stream_classes
->len
),
369 PRFIELD(trace
->streams
->len
),
370 PRFIELD(trace
->is_created_by_writer
),
371 PRFIELD(trace
->packet_header_type
));
374 static inline void format_stream_class(char **buf_ch
, bool extended
,
375 const char *prefix
, struct bt_stream_class
*stream_class
)
377 struct bt_trace
*trace
;
380 if (stream_class
->id_set
) {
381 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(stream_class
->id
));
384 if (stream_class
->name
) {
385 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class
->name
->str
));
392 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class
->frozen
));
394 if (stream_class
->clock
) {
395 BUF_APPEND(", %sctf-writer-clock-addr=%p, "
396 "%sctf-writer-clock-name=\"%s\"",
397 PRFIELD(stream_class
->clock
),
398 PRFIELD(bt_clock_class_get_name(stream_class
->clock
->clock_class
)));
401 BUF_APPEND(", %sevent-class-count=%u, %spacket-context-ft-addr=%p, "
402 "%sevent-header-ft-addr=%p, %sevent-context-ft-addr=%p",
403 PRFIELD(stream_class
->event_classes
->len
),
404 PRFIELD(stream_class
->packet_context_type
),
405 PRFIELD(stream_class
->event_header_type
),
406 PRFIELD(stream_class
->event_context_type
));
407 trace
= bt_stream_class_borrow_trace(stream_class
);
412 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
413 SET_TMP_PREFIX("trace-");
414 format_trace(buf_ch
, false, tmp_prefix
, trace
);
417 static inline void format_event_class(char **buf_ch
, bool extended
,
418 const char *prefix
, struct bt_event_class
*event_class
)
420 struct bt_stream_class
*stream_class
;
421 struct bt_trace
*trace
;
424 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(event_class
->id
));
426 if (event_class
->name
) {
427 BUF_APPEND(", %sname=\"%s\"", PRFIELD(event_class
->name
->str
));
434 BUF_APPEND(", %sis-frozen=%d, %slog-level=%s",
435 PRFIELD(event_class
->frozen
),
436 PRFIELD(bt_event_class_log_level_string(event_class
->log_level
)));
438 if (event_class
->emf_uri
) {
439 BUF_APPEND(", %semf-uri=\"%s\"",
440 PRFIELD(event_class
->emf_uri
->str
));
443 BUF_APPEND(", %scontext-ft-addr=%p, %spayload-ft-addr=%p",
444 PRFIELD(event_class
->context
),
445 PRFIELD(event_class
->fields
));
447 stream_class
= bt_event_class_borrow_stream_class(event_class
);
452 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
453 SET_TMP_PREFIX("stream-class-");
454 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
455 trace
= bt_stream_class_borrow_trace(stream_class
);
460 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
461 SET_TMP_PREFIX("trace-");
462 format_trace(buf_ch
, false, tmp_prefix
, trace
);
465 static inline void format_stream(char **buf_ch
, bool extended
,
466 const char *prefix
, struct bt_stream
*stream
)
468 struct bt_stream_class
*stream_class
;
469 struct bt_trace
*trace
;
472 BUF_APPEND(", %sid=%" PRId64
, PRFIELD(stream
->id
));
475 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream
->name
->str
));
478 BUF_APPEND(", %sis-ctf-writer-stream=%d",
479 PRFIELD(stream
->pos
.fd
!= -1));
485 if (stream
->pos
.fd
!= -1) {
486 BUF_APPEND(", %sheader-field-addr=%p, %scontext-field-addr=%p"
487 ", %sfd=%d, %smmap-offset=%zu, "
488 "%smmap-base-offset=%zu, %spacket-size=%" PRIu64
", "
489 "%soffset=%" PRId64
", %sevent-count=%u, "
490 "%sflushed-packet-count=%u, "
491 "%sdiscarded-event-count=%" PRIu64
", "
492 "%ssize=%" PRIu64
", %slast-ts-end=%" PRIu64
,
493 PRFIELD(stream
->packet_header
),
494 PRFIELD(stream
->packet_context
),
495 PRFIELD(stream
->pos
.fd
),
496 PRFIELD((size_t) stream
->pos
.mmap_offset
),
497 PRFIELD((size_t) stream
->pos
.mmap_base_offset
),
498 PRFIELD(stream
->pos
.packet_size
),
499 PRFIELD(stream
->pos
.offset
),
500 PRFIELD(stream
->events
->len
),
501 PRFIELD(stream
->flushed_packet_count
),
502 PRFIELD(stream
->discarded_events
),
503 PRFIELD(stream
->size
), PRFIELD(stream
->last_ts_end
));
506 stream_class
= bt_stream_borrow_stream_class(stream
);
511 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
512 SET_TMP_PREFIX("stream-class-");
513 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
514 trace
= bt_stream_class_borrow_trace(stream_class
);
519 trace
= (struct bt_trace
*) bt_object_borrow_parent(stream
);
524 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
525 SET_TMP_PREFIX("trace-");
526 format_trace(buf_ch
, false, tmp_prefix
, trace
);
529 static inline void format_packet(char **buf_ch
, bool extended
,
530 const char *prefix
, struct bt_packet
*packet
)
532 struct bt_stream
*stream
;
533 struct bt_trace
*trace
;
540 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
541 "%scontext-field-addr=%p",
542 PRFIELD(packet
->frozen
),
543 PRFIELD(packet
->header
),
544 PRFIELD(packet
->context
));
545 stream
= bt_packet_borrow_stream(packet
);
550 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
551 SET_TMP_PREFIX("stream-");
552 format_stream(buf_ch
, false, tmp_prefix
, stream
);
553 trace
= (struct bt_trace
*) bt_object_borrow_parent(stream
);
558 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
559 SET_TMP_PREFIX("trace-");
560 format_trace(buf_ch
, false, tmp_prefix
, trace
);
563 static inline void format_event(char **buf_ch
, bool extended
,
564 const char *prefix
, struct bt_event
*event
)
566 struct bt_trace
*trace
;
567 struct bt_stream_class
*stream_class
;
568 struct bt_packet
*packet
;
569 struct bt_stream
*stream
;
576 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
577 "%sstream-context-field-addr=%p, "
578 "%scontext-field-addr=%p, %spayload-field-addr=%p, "
579 "%sclock-value-count=%u",
580 PRFIELD(event
->frozen
),
581 PRFIELD(event
->event_header
),
582 PRFIELD(event
->stream_event_context
),
583 PRFIELD(event
->context_payload
),
584 PRFIELD(event
->fields_payload
),
585 PRFIELD(g_hash_table_size(event
->clock_values
)));
586 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event
->event_class
));
587 SET_TMP_PREFIX("event-class-");
588 format_event_class(buf_ch
, false, tmp_prefix
, event
->event_class
);
589 stream_class
= bt_event_class_borrow_stream_class(event
->event_class
);
591 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class
));
592 SET_TMP_PREFIX("stream-class-");
593 format_stream_class(buf_ch
, false, tmp_prefix
, stream_class
);
595 trace
= bt_stream_class_borrow_trace(stream_class
);
597 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace
));
598 SET_TMP_PREFIX("trace-");
599 format_trace(buf_ch
, false, tmp_prefix
, trace
);
603 packet
= bt_event_borrow_packet(event
);
608 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet
));
609 SET_TMP_PREFIX("packet-");
610 format_packet(buf_ch
, false, tmp_prefix
, packet
);
611 stream
= bt_packet_borrow_stream(packet
);
616 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream
));
617 SET_TMP_PREFIX("stream-");
618 format_stream(buf_ch
, false, tmp_prefix
, stream
);
621 static inline void format_clock_class(char **buf_ch
, bool extended
,
622 const char *prefix
, struct bt_clock_class
*clock_class
)
624 BUF_APPEND(", %sname=\"%s\", %sfreq=%" PRIu64
,
625 PRFIELD(clock_class
->name
->str
),
626 PRFIELD(clock_class
->frequency
));
632 if (clock_class
->description
) {
633 BUF_APPEND(", %spartial-description=\"%.32s\"",
634 PRFIELD(clock_class
->description
->str
));
637 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64
", "
638 "%soffset-s=%" PRId64
", "
639 "%soffset-cycles=%" PRId64
", %sis-absolute=%d",
640 PRFIELD(clock_class
->frozen
), PRFIELD(clock_class
->precision
),
641 PRFIELD(clock_class
->offset_s
), PRFIELD(clock_class
->offset
),
642 PRFIELD(clock_class
->absolute
));
644 if (clock_class
->uuid_set
) {
645 BUF_APPEND_UUID(clock_class
->uuid
);
649 static inline void format_clock_value(char **buf_ch
, bool extended
,
650 const char *prefix
, struct bt_clock_value
*clock_value
)
653 BUF_APPEND(", %svalue=%" PRIu64
", %sns-from-epoch=%" PRId64
,
654 PRFIELD(clock_value
->value
),
655 PRFIELD(clock_value
->ns_from_epoch
));
661 BUF_APPEND(", %sclock-class-addr=%p",
662 PRFIELD(clock_value
->clock_class
));
663 SET_TMP_PREFIX("clock-class-");
664 format_clock_class(buf_ch
, false, tmp_prefix
, clock_value
->clock_class
);
667 static inline void format_value(char **buf_ch
, bool extended
,
668 const char *prefix
, struct bt_value
*value
)
670 BUF_APPEND(", %stype=%s",
671 PRFIELD(bt_value_type_string(bt_value_get_type(value
))));
677 switch (bt_value_get_type(value
)) {
678 case BT_VALUE_TYPE_BOOL
:
681 int status
= bt_value_bool_get(value
, &val
);
684 BUF_APPEND(", %svalue=%d", PRFIELD(val
));
687 case BT_VALUE_TYPE_INTEGER
:
690 int status
= bt_value_integer_get(value
, &val
);
693 BUF_APPEND(", %svalue=%" PRId64
, PRFIELD(val
));
696 case BT_VALUE_TYPE_FLOAT
:
699 int status
= bt_value_float_get(value
, &val
);
702 BUF_APPEND(", %svalue=%f", PRFIELD(val
));
705 case BT_VALUE_TYPE_STRING
:
708 int status
= bt_value_string_get(value
, &val
);
711 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val
));
714 case BT_VALUE_TYPE_ARRAY
:
716 int64_t count
= bt_value_array_size(value
);
719 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
722 case BT_VALUE_TYPE_MAP
:
724 int64_t count
= bt_value_map_size(value
);
727 BUF_APPEND(", %selement-count=%" PRId64
, PRFIELD(count
));
735 static inline void format_notification(char **buf_ch
, bool extended
,
736 const char *prefix
, struct bt_notification
*notif
)
740 BUF_APPEND(", %stype=%s",
741 PRFIELD(bt_notification_type_string(notif
->type
)));
747 BUF_APPEND(", %sis-frozen=%d", PRFIELD(notif
->frozen
));
749 switch (notif
->type
) {
750 case BT_NOTIFICATION_TYPE_EVENT
:
752 struct bt_notification_event
*notif_event
= (void *) notif
;
754 SET_TMP_PREFIX("event-");
755 format_event(buf_ch
, true, tmp_prefix
, notif_event
->event
);
757 if (!notif_event
->cc_prio_map
) {
761 BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u",
762 PRFIELD(notif_event
->cc_prio_map
),
763 PRFIELD(notif_event
->cc_prio_map
->entries
->len
));
766 case BT_NOTIFICATION_TYPE_INACTIVITY
:
768 struct bt_notification_inactivity
*notif_inactivity
=
771 if (!notif_inactivity
->cc_prio_map
) {
775 BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u",
776 PRFIELD(notif_inactivity
->cc_prio_map
),
777 PRFIELD(notif_inactivity
->cc_prio_map
->entries
->len
));
780 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
782 struct bt_notification_stream_begin
*notif_stream
=
785 SET_TMP_PREFIX("stream-");
786 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
789 case BT_NOTIFICATION_TYPE_STREAM_END
:
791 struct bt_notification_stream_end
*notif_stream
=
794 SET_TMP_PREFIX("stream-");
795 format_stream(buf_ch
, true, tmp_prefix
, notif_stream
->stream
);
798 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
800 struct bt_notification_packet_begin
*notif_packet
=
803 SET_TMP_PREFIX("packet-");
804 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
807 case BT_NOTIFICATION_TYPE_PACKET_END
:
809 struct bt_notification_packet_end
*notif_packet
=
812 SET_TMP_PREFIX("packet-");
813 format_packet(buf_ch
, true, tmp_prefix
, notif_packet
->packet
);
816 case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS
:
817 case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS
:
819 struct bt_notification_discarded_elements
*notif_discarded
=
822 BUF_APPEND(", %scount=%" PRId64
,
823 PRFIELD(notif_discarded
->count
));
825 if (notif_discarded
->begin_clock_value
) {
826 SET_TMP_PREFIX("begin-clock-value-");
827 format_clock_value(buf_ch
, true, tmp_prefix
,
828 notif_discarded
->begin_clock_value
);
831 if (notif_discarded
->end_clock_value
) {
832 SET_TMP_PREFIX("end-clock-value-");
833 format_clock_value(buf_ch
, true, tmp_prefix
,
834 notif_discarded
->end_clock_value
);
843 static inline void format_plugin_so_shared_lib_handle(char **buf_ch
,
845 struct bt_plugin_so_shared_lib_handle
*handle
)
847 BUF_APPEND(", %saddr=%p", PRFIELD(handle
));
850 BUF_APPEND(", %spath=\"%s\"", PRFIELD(handle
->path
->str
));
854 static inline void format_component_class(char **buf_ch
, bool extended
,
855 const char *prefix
, struct bt_component_class
*comp_class
)
859 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
860 PRFIELD(bt_component_class_type_string(comp_class
->type
)),
861 PRFIELD(comp_class
->name
->str
));
863 if (comp_class
->description
) {
864 BUF_APPEND(", %spartial-descr=\"%.32s\"",
865 PRFIELD(comp_class
->description
->str
));
872 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class
->frozen
));
874 if (comp_class
->so_handle
) {
875 SET_TMP_PREFIX("so-handle-");
876 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
877 comp_class
->so_handle
);
881 static inline void format_component(char **buf_ch
, bool extended
,
882 const char *prefix
, struct bt_component
*component
)
886 BUF_APPEND(", %sname=\"%s\"", PRFIELD(component
->name
->str
));
887 SET_TMP_PREFIX("class-");
888 format_component_class(buf_ch
, extended
, tmp_prefix
, component
->class);
894 BUF_APPEND(", %sinput-port-count=%u, %soutput-port-count=%u",
895 PRFIELD(component
->input_ports
? component
->input_ports
->len
: 0),
896 PRFIELD(component
->output_ports
? component
->output_ports
->len
: 0));
899 static inline void format_port(char **buf_ch
, bool extended
,
900 const char *prefix
, struct bt_port
*port
)
904 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
905 PRFIELD(bt_port_type_string(port
->type
)),
906 PRFIELD(port
->name
->str
));
912 if (port
->connection
) {
913 SET_TMP_PREFIX("conn-");
914 format_connection(buf_ch
, false, tmp_prefix
, port
->connection
);
918 static inline void format_connection(char **buf_ch
, bool extended
,
919 const char *prefix
, struct bt_connection
*connection
)
927 if (connection
->upstream_port
) {
928 SET_TMP_PREFIX("upstream-port-");
929 format_port(buf_ch
, false, tmp_prefix
,
930 connection
->upstream_port
);
933 if (connection
->downstream_port
) {
934 SET_TMP_PREFIX("downstream-port-");
935 format_port(buf_ch
, false, tmp_prefix
,
936 connection
->downstream_port
);
940 static inline void format_graph(char **buf_ch
, bool extended
,
941 const char *prefix
, struct bt_graph
*graph
)
943 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph
->canceled
));
949 BUF_APPEND(", %scomp-count=%u, %sconn-count=%u",
950 PRFIELD(graph
->components
->len
),
951 PRFIELD(graph
->connections
->len
));
954 static inline void format_notification_iterator(char **buf_ch
,
955 bool extended
, const char *prefix
,
956 struct bt_notification_iterator
*iterator
)
961 if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
) {
962 type
= "BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION";
963 } else if (iterator
->type
== BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
) {
964 type
= "BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT";
969 BUF_APPEND(", %stype=%s", PRFIELD(type
));
971 switch (iterator
->type
) {
972 case BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION
:
974 struct bt_notification_iterator_private_connection
*
975 iter_priv_conn
= (void *) iterator
;
977 if (iter_priv_conn
->upstream_component
) {
978 SET_TMP_PREFIX("upstream-comp-");
979 format_component(buf_ch
, false, tmp_prefix
,
980 iter_priv_conn
->upstream_component
);
983 if (iter_priv_conn
->upstream_port
) {
984 SET_TMP_PREFIX("upstream-port-");
985 format_port(buf_ch
, false, tmp_prefix
,
986 iter_priv_conn
->upstream_port
);
989 if (iter_priv_conn
->connection
) {
990 SET_TMP_PREFIX("upstream-conn-");
991 format_connection(buf_ch
, false, tmp_prefix
,
992 iter_priv_conn
->connection
);
996 case BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT
:
998 struct bt_notification_iterator_output_port
*iter_output_port
=
1001 SET_TMP_PREFIX("graph-");
1002 format_graph(buf_ch
, false, tmp_prefix
,
1003 iter_output_port
->graph
);
1004 SET_TMP_PREFIX("colander-comp-");
1005 format_component(buf_ch
, false, tmp_prefix
,
1006 iter_output_port
->colander
);
1007 SET_TMP_PREFIX("output-port-");
1008 format_port(buf_ch
, false, tmp_prefix
,
1009 iter_output_port
->output_port
);
1017 static inline void format_plugin(char **buf_ch
, bool extended
,
1018 const char *prefix
, struct bt_plugin
*plugin
)
1020 char tmp_prefix
[64];
1022 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin
->type
)));
1024 if (plugin
->info
.path_set
) {
1025 BUF_APPEND(", %spath=\"%s\"",
1026 PRFIELD(plugin
->info
.path
->str
));
1029 if (plugin
->info
.name_set
) {
1030 BUF_APPEND(", %sname=\"%s\"",
1031 PRFIELD(plugin
->info
.name
->str
));
1038 if (plugin
->info
.author_set
) {
1039 BUF_APPEND(", %sauthor=\"%s\"",
1040 PRFIELD(plugin
->info
.author
->str
));
1043 if (plugin
->info
.license_set
) {
1044 BUF_APPEND(", %slicense=\"%s\"",
1045 PRFIELD(plugin
->info
.license
->str
));
1048 if (plugin
->info
.version_set
) {
1049 BUF_APPEND(", %sversion=%u.%u.%u%s",
1050 PRFIELD(plugin
->info
.version
.major
),
1051 plugin
->info
.version
.minor
,
1052 plugin
->info
.version
.patch
,
1053 plugin
->info
.version
.extra
?
1054 plugin
->info
.version
.extra
->str
: "");
1057 BUF_APPEND(", %sis-frozen=%d, %scomp-class-count=%u",
1058 PRFIELD(plugin
->frozen
),
1059 PRFIELD(plugin
->comp_classes
->len
));
1061 if (plugin
->spec_data
) {
1062 struct bt_plugin_so_spec_data
*spec_data
=
1063 (void *) plugin
->spec_data
;
1065 if (spec_data
->shared_lib_handle
) {
1066 SET_TMP_PREFIX("so-handle-");
1067 format_plugin_so_shared_lib_handle(buf_ch
, tmp_prefix
,
1068 spec_data
->shared_lib_handle
);
1073 static inline void format_ctf_writer(char **buf_ch
, bool extended
,
1074 const char *prefix
, struct bt_ctf_writer
*writer
)
1079 static inline void handle_conversion_specifier_bt(void *priv_data
,
1080 char **buf_ch
, size_t avail_size
,
1081 const char **out_fmt_ch
, va_list *args
)
1083 const char *fmt_ch
= *out_fmt_ch
;
1084 bool extended
= false;
1086 char *prefix_ch
= prefix
;
1092 if (*fmt_ch
== '[') {
1097 if (*fmt_ch
== ']') {
1103 *prefix_ch
= *fmt_ch
;
1111 if (*fmt_ch
== '+') {
1116 obj
= va_arg(*args
, void *);
1117 BUF_APPEND("%saddr=%p", prefix
, obj
);
1125 format_ref_count(buf_ch
, extended
, prefix
, obj
);
1128 format_field_type(buf_ch
, extended
, prefix
, obj
);
1131 format_field(buf_ch
, extended
, prefix
, obj
);
1134 format_field_path(buf_ch
, extended
, prefix
, obj
);
1137 format_event_class(buf_ch
, extended
, prefix
, obj
);
1140 format_event(buf_ch
, extended
, prefix
, obj
);
1143 format_stream_class(buf_ch
, extended
, prefix
, obj
);
1146 format_stream(buf_ch
, extended
, prefix
, obj
);
1149 format_packet(buf_ch
, extended
, prefix
, obj
);
1152 format_trace(buf_ch
, extended
, prefix
, obj
);
1155 format_clock_class(buf_ch
, extended
, prefix
, obj
);
1158 format_clock_value(buf_ch
, extended
, prefix
, obj
);
1161 format_value(buf_ch
, extended
, prefix
, obj
);
1164 format_notification(buf_ch
, extended
, prefix
, obj
);
1167 format_notification_iterator(buf_ch
, extended
, prefix
, obj
);
1170 format_component_class(buf_ch
, extended
, prefix
, obj
);
1173 format_component(buf_ch
, extended
, prefix
, obj
);
1176 format_port(buf_ch
, extended
, prefix
, obj
);
1179 format_connection(buf_ch
, extended
, prefix
, obj
);
1182 format_plugin(buf_ch
, extended
, prefix
, obj
);
1185 format_graph(buf_ch
, extended
, prefix
, obj
);
1188 format_ctf_writer(buf_ch
, extended
, prefix
, obj
);
1196 *out_fmt_ch
= fmt_ch
;
1200 void bt_lib_log(const char *func
, const char *file
, unsigned line
,
1201 int lvl
, const char *tag
, const char *fmt
, ...)
1207 va_start(args
, fmt
);
1208 bt_common_custom_vsnprintf(lib_logging_buf
, LIB_LOGGING_BUF_SIZE
, '!',
1209 handle_conversion_specifier_bt
, NULL
, fmt
, &args
);
1211 _bt_log_write_d(func
, file
, line
, lvl
, tag
, "%s", lib_logging_buf
);