lib: remove CV snapshot property from stream beginning/end message
[babeltrace.git] / lib / lib-logging.c
CommitLineData
57ffc2f1
PP
1/*
2 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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
20 * SOFTWARE.
21 */
22
8deee039
PP
23#define BT_LOG_TAG "LIB-LOGGING"
24
57ffc2f1
PP
25#include <stdarg.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <inttypes.h>
30#include <stdint.h>
57ffc2f1
PP
31#include <wchar.h>
32#include <glib.h>
8c6884d9
PP
33#include <babeltrace/lib-logging-internal.h>
34#include <babeltrace/assert-pre-internal.h>
57ffc2f1
PP
35#include <babeltrace/common-internal.h>
36#include <babeltrace/lib-logging-internal.h>
0f15f666
PP
37#include <babeltrace/value-internal.h>
38#include <babeltrace/value-internal.h>
a6918753 39#include <babeltrace/object-pool-internal.h>
0f15f666
PP
40#include <babeltrace/trace-ir/field-class-internal.h>
41#include <babeltrace/trace-ir/field-internal.h>
108b91d0 42#include <babeltrace/trace-ir/event-class-internal.h>
10b7a2e4 43#include <babeltrace/trace-ir/event-const.h>
108b91d0 44#include <babeltrace/trace-ir/event-internal.h>
10b7a2e4 45#include <babeltrace/trace-ir/packet-const.h>
108b91d0
PP
46#include <babeltrace/trace-ir/packet-internal.h>
47#include <babeltrace/trace-ir/stream-class-internal.h>
48#include <babeltrace/trace-ir/stream-internal.h>
10b7a2e4 49#include <babeltrace/trace-ir/stream-const.h>
108b91d0 50#include <babeltrace/trace-ir/trace-internal.h>
10b7a2e4 51#include <babeltrace/trace-ir/trace-class-internal.h>
108b91d0 52#include <babeltrace/trace-ir/clock-class-internal.h>
ecbb78c0 53#include <babeltrace/trace-ir/clock-snapshot-internal.h>
108b91d0
PP
54#include <babeltrace/trace-ir/field-path-internal.h>
55#include <babeltrace/trace-ir/utils-internal.h>
57ffc2f1
PP
56#include <babeltrace/graph/component-class-internal.h>
57#include <babeltrace/graph/component-class-sink-colander-internal.h>
58#include <babeltrace/graph/component-filter-internal.h>
59#include <babeltrace/graph/component-internal.h>
60#include <babeltrace/graph/component-sink-internal.h>
61#include <babeltrace/graph/component-source-internal.h>
62#include <babeltrace/graph/connection-internal.h>
63#include <babeltrace/graph/graph-internal.h>
b09a5592
PP
64#include <babeltrace/graph/message-event-internal.h>
65#include <babeltrace/graph/message-inactivity-internal.h>
66#include <babeltrace/graph/message-internal.h>
67#include <babeltrace/graph/message-iterator-internal.h>
68#include <babeltrace/graph/message-packet-internal.h>
69#include <babeltrace/graph/message-stream-internal.h>
57ffc2f1
PP
70#include <babeltrace/graph/port-internal.h>
71#include <babeltrace/plugin/plugin-internal.h>
72#include <babeltrace/plugin/plugin-so-internal.h>
57ffc2f1
PP
73
74#define LIB_LOGGING_BUF_SIZE (4096 * 4)
75
76static char __thread lib_logging_buf[LIB_LOGGING_BUF_SIZE];
77
78#define BUF_APPEND(_fmt, ...) \
79 do { \
80 int _count; \
81 size_t _size = LIB_LOGGING_BUF_SIZE - \
82 (size_t) (*buf_ch - lib_logging_buf); \
83 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
8b45963b 84 BT_ASSERT(_count >= 0); \
57ffc2f1
PP
85 *buf_ch += MIN(_count, _size); \
86 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
87 return; \
88 } \
89 } while (0)
90
91#define BUF_APPEND_UUID(_uuid) \
7b33a0e0
PP
92 do { \
93 BUF_APPEND(", %suuid=", prefix); \
94 format_uuid(buf_ch, (_uuid)); \
95 } while (0)
57ffc2f1
PP
96
97#define PRFIELD(_expr) prefix, (_expr)
98
834e9996
PP
99#define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL)
100
57ffc2f1
PP
101#define SET_TMP_PREFIX(_prefix2) \
102 do { \
103 strcpy(tmp_prefix, prefix); \
104 strcat(tmp_prefix, (_prefix2)); \
105 } while (0)
106
107static inline void format_component(char **buf_ch, bool extended,
10b7a2e4 108 const char *prefix, const struct bt_component *component);
57ffc2f1
PP
109
110static inline void format_port(char **buf_ch, bool extended,
10b7a2e4 111 const char *prefix, const struct bt_port *port);
57ffc2f1
PP
112
113static inline void format_connection(char **buf_ch, bool extended,
10b7a2e4 114 const char *prefix, const struct bt_connection *connection);
57ffc2f1 115
ecbb78c0
PP
116static inline void format_clock_snapshot(char **buf_ch, bool extended,
117 const char *prefix, const struct bt_clock_snapshot *clock_snapshot);
8fc063a2 118
7b33a0e0 119static inline void format_field_path(char **buf_ch, bool extended,
10b7a2e4 120 const char *prefix, const struct bt_field_path *field_path);
7b33a0e0 121
1d7bf349 122static inline void format_object(char **buf_ch, bool extended,
10b7a2e4 123 const char *prefix, const struct bt_object *obj)
57ffc2f1 124{
1d7bf349 125 BUF_APPEND(", %sref-count=%llu", prefix, obj->ref_count);
57ffc2f1
PP
126}
127
7b33a0e0 128static inline void format_uuid(char **buf_ch, bt_uuid uuid)
8fc063a2 129{
7b33a0e0
PP
130 BUF_APPEND("\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
131 (unsigned int) uuid[0],
132 (unsigned int) uuid[1],
133 (unsigned int) uuid[2],
134 (unsigned int) uuid[3],
135 (unsigned int) uuid[4],
136 (unsigned int) uuid[5],
137 (unsigned int) uuid[6],
138 (unsigned int) uuid[7],
139 (unsigned int) uuid[8],
140 (unsigned int) uuid[9],
141 (unsigned int) uuid[10],
142 (unsigned int) uuid[11],
143 (unsigned int) uuid[12],
144 (unsigned int) uuid[13],
145 (unsigned int) uuid[14],
146 (unsigned int) uuid[15]);
8fc063a2
PP
147}
148
a6918753 149static inline void format_object_pool(char **buf_ch, bool extended,
10b7a2e4 150 const char *prefix, const struct bt_object_pool *pool)
a6918753
PP
151{
152 BUF_APPEND(", %ssize=%zu", PRFIELD(pool->size));
153
154 if (pool->objects) {
155 BUF_APPEND(", %scap=%u", PRFIELD(pool->objects->len));
156 }
157}
158
939190b3 159static inline void format_integer_field_class(char **buf_ch,
7b33a0e0 160 bool extended, const char *prefix,
10b7a2e4 161 const struct bt_field_class *field_class)
7b33a0e0 162{
10b7a2e4
PP
163 const struct bt_field_class_integer *int_fc =
164 (const void *) field_class;
7b33a0e0
PP
165
166 BUF_APPEND(", %srange-size=%" PRIu64 ", %sbase=%s",
939190b3
PP
167 PRFIELD(int_fc->range),
168 PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc->base)));
7b33a0e0
PP
169}
170
939190b3 171static inline void format_array_field_class(char **buf_ch,
7b33a0e0 172 bool extended, const char *prefix,
10b7a2e4 173 const struct bt_field_class *field_class)
7b33a0e0 174{
10b7a2e4
PP
175 const struct bt_field_class_array *array_fc =
176 (const void *) field_class;
7b33a0e0 177
af0c18e3 178 BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s",
939190b3 179 PRFIELD(array_fc->element_fc),
af0c18e3 180 PRFIELD(bt_common_field_class_type_string(array_fc->element_fc->type)));
7b33a0e0
PP
181}
182
939190b3 183static inline void format_field_class(char **buf_ch, bool extended,
10b7a2e4 184 const char *prefix, const struct bt_field_class *field_class)
57ffc2f1 185{
7b33a0e0
PP
186 char tmp_prefix[64];
187
af0c18e3
PP
188 BUF_APPEND(", %stype=%s",
189 PRFIELD(bt_common_field_class_type_string(field_class->type)));
57ffc2f1
PP
190
191 if (extended) {
939190b3 192 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class->frozen));
10b7a2e4
PP
193 BUF_APPEND(", %sis-part-of-trace-class=%d",
194 PRFIELD(field_class->part_of_trace_class));
57ffc2f1
PP
195 } else {
196 return;
197 }
198
af0c18e3
PP
199 switch (field_class->type) {
200 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
201 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
57ffc2f1 202 {
939190b3 203 format_integer_field_class(buf_ch, extended, prefix, field_class);
57ffc2f1
PP
204 break;
205 }
af0c18e3 206 case BT_FIELD_CLASS_TYPE_REAL:
57ffc2f1 207 {
10b7a2e4 208 const struct bt_field_class_real *real_fc = (void *) field_class;
57ffc2f1 209
7b33a0e0 210 BUF_APPEND(", %sis-single-precision=%d",
939190b3 211 PRFIELD(real_fc->is_single_precision));
57ffc2f1
PP
212 break;
213 }
af0c18e3
PP
214 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
215 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
57ffc2f1 216 {
10b7a2e4
PP
217 const struct bt_field_class_enumeration *enum_fc =
218 (const void *) field_class;
57ffc2f1 219
939190b3 220 format_integer_field_class(buf_ch, extended, prefix, field_class);
57ffc2f1 221 BUF_APPEND(", %smapping-count=%u",
939190b3 222 PRFIELD(enum_fc->mappings->len));
57ffc2f1
PP
223 break;
224 }
af0c18e3 225 case BT_FIELD_CLASS_TYPE_STRUCTURE:
57ffc2f1 226 {
10b7a2e4
PP
227 const struct bt_field_class_structure *struct_fc =
228 (const void *) field_class;
7b33a0e0 229
939190b3 230 if (struct_fc->common.named_fcs) {
7b33a0e0 231 BUF_APPEND(", %smember-count=%u",
939190b3 232 PRFIELD(struct_fc->common.named_fcs->len));
7b33a0e0 233 }
57ffc2f1 234
57ffc2f1
PP
235 break;
236 }
af0c18e3 237 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
57ffc2f1 238 {
10b7a2e4
PP
239 const struct bt_field_class_static_array *array_fc =
240 (const void *) field_class;
57ffc2f1 241
939190b3
PP
242 format_array_field_class(buf_ch, extended, prefix, field_class);
243 BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_fc->length));
57ffc2f1
PP
244 break;
245 }
af0c18e3 246 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
57ffc2f1 247 {
10b7a2e4
PP
248 const struct bt_field_class_dynamic_array *array_fc =
249 (const void *) field_class;
7b33a0e0 250
939190b3 251 format_array_field_class(buf_ch, extended, prefix, field_class);
7b33a0e0 252
939190b3
PP
253 if (array_fc->length_fc) {
254 SET_TMP_PREFIX("length-fc-");
255 format_field_class(buf_ch, extended, tmp_prefix,
256 array_fc->length_fc);
7b33a0e0
PP
257 }
258
939190b3 259 if (array_fc->length_field_path) {
7b33a0e0
PP
260 SET_TMP_PREFIX("length-field-path-");
261 format_field_path(buf_ch, extended, tmp_prefix,
939190b3 262 array_fc->length_field_path);
7b33a0e0 263 }
57ffc2f1 264
57ffc2f1
PP
265 break;
266 }
af0c18e3 267 case BT_FIELD_CLASS_TYPE_VARIANT:
57ffc2f1 268 {
10b7a2e4
PP
269 const struct bt_field_class_variant *var_fc =
270 (const void *) field_class;
7b33a0e0 271
939190b3 272 if (var_fc->common.named_fcs) {
7b33a0e0 273 BUF_APPEND(", %soption-count=%u",
939190b3 274 PRFIELD(var_fc->common.named_fcs->len));
7b33a0e0
PP
275 }
276
939190b3
PP
277 if (var_fc->selector_fc) {
278 SET_TMP_PREFIX("selector-fc-");
279 format_field_class(buf_ch, extended, tmp_prefix,
280 var_fc->selector_fc);
7b33a0e0
PP
281 }
282
939190b3 283 if (var_fc->selector_field_path) {
7b33a0e0
PP
284 SET_TMP_PREFIX("selector-field-path-");
285 format_field_path(buf_ch, extended, tmp_prefix,
939190b3 286 var_fc->selector_field_path);
7b33a0e0 287 }
57ffc2f1 288
57ffc2f1
PP
289 break;
290 }
291 default:
292 break;
293 }
294}
295
18acc6f8 296static inline void format_field_integer_extended(char **buf_ch,
10b7a2e4 297 const char *prefix, const struct bt_field *field)
57ffc2f1 298{
10b7a2e4
PP
299 const struct bt_field_integer *integer = (void *) field;
300 const struct bt_field_class_integer *field_class =
301 (void *) field->class;
57ffc2f1
PP
302 const char *fmt = NULL;
303
939190b3 304 BT_ASSERT(field_class);
a6918753 305
939190b3 306 if (field_class->base == BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL) {
57ffc2f1 307 fmt = ", %svalue=%" PRIo64;
939190b3 308 } else if (field_class->base == BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL) {
57ffc2f1
PP
309 fmt = ", %svalue=%" PRIx64;
310 }
311
af0c18e3
PP
312 if (field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER ||
313 field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) {
57ffc2f1
PP
314 if (!fmt) {
315 fmt = ", %svalue=%" PRId64;
316 }
317
7b33a0e0 318 BUF_APPEND(fmt, PRFIELD(integer->value.i));
57ffc2f1
PP
319 } else {
320 if (!fmt) {
321 fmt = ", %svalue=%" PRIu64;
322 }
323
7b33a0e0 324 BUF_APPEND(fmt, PRFIELD(integer->value.u));
57ffc2f1
PP
325 }
326}
327
18acc6f8 328static inline void format_field(char **buf_ch, bool extended,
10b7a2e4 329 const char *prefix, const struct bt_field *field)
57ffc2f1 330{
7b33a0e0 331 BUF_APPEND(", %sis-set=%d", PRFIELD(field->is_set));
57ffc2f1
PP
332
333 if (extended) {
334 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field->frozen));
335 }
336
af0c18e3 337 BUF_APPEND(", %sclass-addr=%p", PRFIELD(field->class));
a6918753 338
939190b3 339 if (!field->class) {
a6918753
PP
340 return;
341 }
342
af0c18e3
PP
343 BUF_APPEND(", %sclass-type=%s",
344 PRFIELD(bt_common_field_class_type_string(field->class->type)));
57ffc2f1 345
7b33a0e0 346 if (!extended || !field->is_set) {
57ffc2f1
PP
347 return;
348 }
349
af0c18e3
PP
350 switch (field->class->type) {
351 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
352 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
353 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
354 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
57ffc2f1 355 {
18acc6f8 356 format_field_integer_extended(buf_ch, prefix, field);
57ffc2f1
PP
357 break;
358 }
af0c18e3 359 case BT_FIELD_CLASS_TYPE_REAL:
57ffc2f1 360 {
10b7a2e4 361 const struct bt_field_real *real_field = (const void *) field;
57ffc2f1 362
7b33a0e0 363 BUF_APPEND(", %svalue=%f", PRFIELD(real_field->value));
57ffc2f1
PP
364 break;
365 }
af0c18e3 366 case BT_FIELD_CLASS_TYPE_STRING:
57ffc2f1 367 {
10b7a2e4 368 const struct bt_field_string *str = (const void *) field;
57ffc2f1 369
e42dd763
PP
370 if (str->buf) {
371 BT_ASSERT(str->buf->data);
a6918753 372 BUF_APPEND(", %spartial-value=\"%.32s\"",
e42dd763 373 PRFIELD(str->buf->data));
a6918753 374 }
7b33a0e0 375
57ffc2f1
PP
376 break;
377 }
af0c18e3
PP
378 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
379 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
57ffc2f1 380 {
10b7a2e4 381 const struct bt_field_array *array_field = (const void *) field;
57ffc2f1 382
7b33a0e0 383 BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_field->length));
a6918753 384
7b33a0e0 385 if (array_field->fields) {
a6918753 386 BUF_APPEND(", %sallocated-length=%u",
7b33a0e0 387 PRFIELD(array_field->fields->len));
a6918753 388 }
7b33a0e0 389
57ffc2f1
PP
390 break;
391 }
af0c18e3 392 case BT_FIELD_CLASS_TYPE_VARIANT:
57ffc2f1 393 {
10b7a2e4 394 const struct bt_field_variant *var_field = (const void *) field;
a6918753 395
7b33a0e0
PP
396 BUF_APPEND(", %sselected-field-index=%" PRIu64,
397 PRFIELD(var_field->selected_index));
a6918753
PP
398 break;
399 }
400 default:
401 break;
402 }
8deee039
PP
403}
404
57ffc2f1 405static inline void format_field_path(char **buf_ch, bool extended,
10b7a2e4 406 const char *prefix, const struct bt_field_path *field_path)
57ffc2f1
PP
407{
408 uint64_t i;
409
a6918753
PP
410 if (field_path->indexes) {
411 BT_ASSERT(field_path->indexes);
18acc6f8
PP
412 BUF_APPEND(", %sindex-count=%u",
413 PRFIELD(field_path->indexes->len));
a6918753 414 }
57ffc2f1 415
a6918753 416 if (!extended || !field_path->indexes) {
57ffc2f1
PP
417 return;
418 }
419
18acc6f8
PP
420 BUF_APPEND(", %spath=[%s",
421 PRFIELD(bt_common_scope_string(field_path->root)));
57ffc2f1
PP
422
423 for (i = 0; i < field_path->indexes->len; i++) {
7b33a0e0
PP
424 uint64_t index = bt_field_path_get_index_by_index_inline(
425 field_path, i);
57ffc2f1 426
7b33a0e0 427 BUF_APPEND(", %" PRIu64, index);
57ffc2f1
PP
428 }
429
430 BUF_APPEND("%s", "]");
431}
432
10b7a2e4
PP
433static inline void format_trace_class(char **buf_ch, bool extended,
434 const char *prefix, const struct bt_trace_class *trace_class)
57ffc2f1 435{
10b7a2e4
PP
436 if (trace_class->name.value) {
437 BUF_APPEND(", %sname=\"%s\"",
438 PRFIELD(trace_class->name.value));
57ffc2f1
PP
439 }
440
441 if (!extended) {
442 return;
443 }
444
10b7a2e4 445 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class->frozen));
57ffc2f1 446
10b7a2e4
PP
447 if (trace_class->uuid.value) {
448 BUF_APPEND_UUID(trace_class->uuid.value);
a6918753
PP
449 }
450
10b7a2e4 451 if (trace_class->stream_classes) {
a6918753 452 BUF_APPEND(", %sstream-class-count=%u",
10b7a2e4 453 PRFIELD(trace_class->stream_classes->len));
a6918753
PP
454 }
455
0476f6f7 456 BUF_APPEND(", %sassigns-auto-sc-id=%d",
10b7a2e4 457 PRFIELD(trace_class->assigns_automatic_stream_class_id));
10b7a2e4
PP
458}
459
460static inline void format_trace(char **buf_ch, bool extended,
461 const char *prefix, const struct bt_trace *trace)
462{
463 char tmp_prefix[64];
464
465 if (trace->name.value) {
466 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name.value));
467 }
468
469 if (!extended) {
470 return;
471 }
472
473 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen));
474
a6918753
PP
475 if (trace->streams) {
476 BUF_APPEND(", %sstream-count=%u",
477 PRFIELD(trace->streams->len));
478 }
479
10b7a2e4
PP
480 BUF_APPEND(", %sis-static=%d", PRFIELD(trace->is_static));
481
482 if (!trace->class) {
483 return;
484 }
485
486 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace->class));
487 SET_TMP_PREFIX("trace-class-");
488 format_trace_class(buf_ch, false, tmp_prefix, trace->class);
8deee039
PP
489}
490
18acc6f8 491static inline void format_stream_class(char **buf_ch, bool extended,
10b7a2e4
PP
492 const char *prefix,
493 const struct bt_stream_class *stream_class)
8deee039 494{
10b7a2e4 495 const struct bt_trace_class *trace_class;
57ffc2f1
PP
496 char tmp_prefix[64];
497
7b33a0e0 498 BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream_class->id));
57ffc2f1 499
7b33a0e0
PP
500 if (stream_class->name.value) {
501 BUF_APPEND(", %sname=\"%s\"",
502 PRFIELD(stream_class->name.value));
57ffc2f1
PP
503 }
504
505 if (!extended) {
506 return;
507 }
508
509 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class->frozen));
a6918753
PP
510
511 if (stream_class->event_classes) {
512 BUF_APPEND(", %sevent-class-count=%u",
513 PRFIELD(stream_class->event_classes->len));
514 }
515
939190b3 516 BUF_APPEND(", %spacket-context-fc-addr=%p, "
0476f6f7 517 "%sevent-common-context-fc-addr=%p",
939190b3 518 PRFIELD(stream_class->packet_context_fc),
939190b3 519 PRFIELD(stream_class->event_common_context_fc));
10b7a2e4
PP
520 trace_class = bt_stream_class_borrow_trace_class_inline(stream_class);
521 if (!trace_class) {
57ffc2f1
PP
522 return;
523 }
524
7b33a0e0
PP
525 BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, "
526 "%spackets-have-discarded-ev-counter-snapshot=%d, "
527 "%spackets-have-packet-counter-snapshot=%d, "
ecbb78c0
PP
528 "%spackets-have-default-begin-cs=%d, "
529 "%spackets-have-default-end-cs=%d",
7b33a0e0
PP
530 PRFIELD(stream_class->assigns_automatic_event_class_id),
531 PRFIELD(stream_class->assigns_automatic_stream_id),
532 PRFIELD(stream_class->packets_have_discarded_event_counter_snapshot),
533 PRFIELD(stream_class->packets_have_packet_counter_snapshot),
ecbb78c0
PP
534 PRFIELD(stream_class->packets_have_default_beginning_cs),
535 PRFIELD(stream_class->packets_have_default_end_cs));
10b7a2e4
PP
536 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class));
537 SET_TMP_PREFIX("trace-class-");
538 format_trace_class(buf_ch, false, tmp_prefix, trace_class);
f7c3ac09
PP
539 SET_TMP_PREFIX("pcf-pool-");
540 format_object_pool(buf_ch, extended, prefix,
541 &stream_class->packet_context_field_pool);
8deee039
PP
542}
543
18acc6f8 544static inline void format_event_class(char **buf_ch, bool extended,
10b7a2e4 545 const char *prefix, const struct bt_event_class *event_class)
8deee039 546{
10b7a2e4
PP
547 const struct bt_stream_class *stream_class;
548 const struct bt_trace_class *trace_class;
57ffc2f1
PP
549 char tmp_prefix[64];
550
7b33a0e0 551 BUF_APPEND(", %sid=%" PRIu64, PRFIELD(event_class->id));
57ffc2f1 552
7b33a0e0 553 if (event_class->name.value) {
18acc6f8 554 BUF_APPEND(", %sname=\"%s\"",
7b33a0e0 555 PRFIELD(event_class->name.value));
57ffc2f1
PP
556 }
557
558 if (!extended) {
559 return;
560 }
561
7b33a0e0
PP
562 BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class->frozen));
563
564 if (event_class->log_level.base.avail) {
565 BUF_APPEND(", %slog-level=%s",
566 PRFIELD(bt_common_event_class_log_level_string(
567 (int) event_class->log_level.value)));
568 }
57ffc2f1 569
7b33a0e0 570 if (event_class->emf_uri.value) {
57ffc2f1 571 BUF_APPEND(", %semf-uri=\"%s\"",
7b33a0e0 572 PRFIELD(event_class->emf_uri.value));
57ffc2f1
PP
573 }
574
939190b3
PP
575 BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p",
576 PRFIELD(event_class->specific_context_fc),
577 PRFIELD(event_class->payload_fc));
57ffc2f1 578
10b7a2e4 579 stream_class = bt_event_class_borrow_stream_class_const(event_class);
57ffc2f1
PP
580 if (!stream_class) {
581 return;
582 }
583
584 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class));
585 SET_TMP_PREFIX("stream-class-");
18acc6f8 586 format_stream_class(buf_ch, false, tmp_prefix, stream_class);
10b7a2e4
PP
587 trace_class = bt_stream_class_borrow_trace_class_inline(stream_class);
588 if (!trace_class) {
57ffc2f1
PP
589 return;
590 }
591
10b7a2e4
PP
592 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class));
593 SET_TMP_PREFIX("trace-class-");
594 format_trace_class(buf_ch, false, tmp_prefix, trace_class);
a6918753
PP
595 SET_TMP_PREFIX("event-pool-");
596 format_object_pool(buf_ch, extended, prefix, &event_class->event_pool);
8deee039
PP
597}
598
18acc6f8 599static inline void format_stream(char **buf_ch, bool extended,
10b7a2e4 600 const char *prefix, const struct bt_stream *stream)
8deee039 601{
10b7a2e4
PP
602 const struct bt_stream_class *stream_class;
603 const struct bt_trace_class *trace_class = NULL;
604 const struct bt_trace *trace = NULL;
57ffc2f1
PP
605 char tmp_prefix[64];
606
7b33a0e0 607 BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream->id));
57ffc2f1 608
7b33a0e0
PP
609 if (stream->name.value) {
610 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream->name.value));
57ffc2f1
PP
611 }
612
57ffc2f1
PP
613 if (!extended) {
614 return;
615 }
616
10b7a2e4
PP
617 stream_class = bt_stream_borrow_class_const(stream);
618 if (stream_class) {
619 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class));
620 SET_TMP_PREFIX("stream-class-");
621 format_stream_class(buf_ch, false, tmp_prefix, stream_class);
622 trace_class = bt_stream_class_borrow_trace_class_inline(stream_class);
57ffc2f1
PP
623 }
624
10b7a2e4
PP
625 if (trace_class) {
626 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class));
627 SET_TMP_PREFIX("trace-class-");
628 format_trace_class(buf_ch, false, tmp_prefix, trace_class);
629 }
630
631 trace = bt_stream_borrow_trace_inline(stream);
632 if (trace) {
633 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace));
634 SET_TMP_PREFIX("trace-");
635 format_trace(buf_ch, false, tmp_prefix, trace);
57ffc2f1
PP
636 }
637
a6918753
PP
638 SET_TMP_PREFIX("packet-pool-");
639 format_object_pool(buf_ch, extended, prefix, &stream->packet_pool);
8deee039
PP
640}
641
57ffc2f1 642static inline void format_packet(char **buf_ch, bool extended,
10b7a2e4 643 const char *prefix, const struct bt_packet *packet)
57ffc2f1 644{
10b7a2e4
PP
645 const struct bt_stream *stream;
646 const struct bt_trace_class *trace_class;
57ffc2f1
PP
647 char tmp_prefix[64];
648
649 if (!extended) {
650 return;
651 }
652
0476f6f7 653 BUF_APPEND(", %sis-frozen=%d, %scontext-field-addr=%p",
57ffc2f1 654 PRFIELD(packet->frozen),
7b33a0e0 655 PRFIELD(packet->context_field ? packet->context_field->field : NULL));
10b7a2e4 656 stream = bt_packet_borrow_stream_const(packet);
57ffc2f1
PP
657 if (!stream) {
658 return;
659 }
660
ecbb78c0
PP
661 if (packet->default_beginning_cs) {
662 SET_TMP_PREFIX("default-begin-cs-");
663 format_clock_snapshot(buf_ch, true, tmp_prefix,
664 packet->default_beginning_cs);
7b33a0e0
PP
665 }
666
ecbb78c0
PP
667 if (packet->default_end_cs) {
668 SET_TMP_PREFIX("default-end-cs-");
669 format_clock_snapshot(buf_ch, true, tmp_prefix,
670 packet->default_end_cs);
7b33a0e0
PP
671 }
672
673 if (packet->discarded_event_counter_snapshot.base.avail) {
674 BUF_APPEND(", %sdiscarded-ev-counter-snapshot=%" PRIu64,
675 PRFIELD(packet->discarded_event_counter_snapshot.value));
676 }
677
678 if (packet->packet_counter_snapshot.base.avail) {
679 BUF_APPEND(", %spacket-counter-snapshot=%" PRIu64,
680 PRFIELD(packet->packet_counter_snapshot.value));
681 }
682
57ffc2f1
PP
683 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream));
684 SET_TMP_PREFIX("stream-");
685 format_stream(buf_ch, false, tmp_prefix, stream);
10b7a2e4
PP
686 trace_class = (const struct bt_trace_class *) bt_object_borrow_parent(&stream->base);
687 if (!trace_class) {
57ffc2f1
PP
688 return;
689 }
690
10b7a2e4
PP
691 BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class));
692 SET_TMP_PREFIX("trace-class-");
693 format_trace_class(buf_ch, false, tmp_prefix, trace_class);
57ffc2f1
PP
694}
695
18acc6f8 696static inline void format_event(char **buf_ch, bool extended,
10b7a2e4 697 const char *prefix, const struct bt_event *event)
57ffc2f1 698{
10b7a2e4
PP
699 const struct bt_packet *packet;
700 const struct bt_stream *stream;
701 const struct bt_trace_class *trace_class;
702 const struct bt_stream_class *stream_class;
57ffc2f1
PP
703 char tmp_prefix[64];
704
705 if (!extended) {
706 return;
707 }
708
0476f6f7 709 BUF_APPEND(", %sis-frozen=%d, "
7b33a0e0 710 "%scommon-context-field-addr=%p, "
834e9996 711 "%sspecific-context-field-addr=%p, "
7b33a0e0 712 "%spayload-field-addr=%p, ",
57ffc2f1 713 PRFIELD(event->frozen),
7b33a0e0
PP
714 PRFIELD(event->common_context_field),
715 PRFIELD(event->specific_context_field),
8deee039
PP
716 PRFIELD(event->payload_field));
717 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event->class));
a6918753
PP
718
719 if (!event->class) {
720 return;
721 }
722
57ffc2f1 723 SET_TMP_PREFIX("event-class-");
18acc6f8
PP
724 format_event_class(buf_ch, false, tmp_prefix, event->class);
725 stream_class = bt_event_class_borrow_stream_class(event->class);
57ffc2f1
PP
726 if (stream_class) {
727 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class));
728 SET_TMP_PREFIX("stream-class-");
18acc6f8 729 format_stream_class(buf_ch, false, tmp_prefix,
8deee039 730 stream_class);
57ffc2f1 731
10b7a2e4
PP
732 trace_class = bt_stream_class_borrow_trace_class_inline(
733 stream_class);
734 if (trace_class) {
735 BUF_APPEND(", %strace-class-addr=%p",
736 PRFIELD(trace_class));
737 SET_TMP_PREFIX("trace-class-");
738 format_trace_class(buf_ch, false, tmp_prefix,
739 trace_class);
57ffc2f1
PP
740 }
741 }
8deee039 742
ecbb78c0
PP
743 if (event->default_cs) {
744 SET_TMP_PREFIX("default-cs-");
745 format_clock_snapshot(buf_ch, true, tmp_prefix,
746 event->default_cs);
7b33a0e0
PP
747 }
748
10b7a2e4 749 packet = bt_event_borrow_packet_const(event);
57ffc2f1
PP
750 if (!packet) {
751 return;
752 }
753
754 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet));
755 SET_TMP_PREFIX("packet-");
756 format_packet(buf_ch, false, tmp_prefix, packet);
10b7a2e4 757 stream = bt_packet_borrow_stream_const(packet);
57ffc2f1
PP
758 if (!stream) {
759 return;
760 }
761
762 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream));
763 SET_TMP_PREFIX("stream-");
764 format_stream(buf_ch, false, tmp_prefix, stream);
765}
766
767static inline void format_clock_class(char **buf_ch, bool extended,
10b7a2e4 768 const char *prefix, const struct bt_clock_class *clock_class)
57ffc2f1 769{
a6918753
PP
770 char tmp_prefix[64];
771
7b33a0e0
PP
772 if (clock_class->name.value) {
773 BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name.value));
774 }
775
776 BUF_APPEND(", %sfreq=%" PRIu64, PRFIELD(clock_class->frequency));
57ffc2f1
PP
777
778 if (!extended) {
779 return;
780 }
781
7b33a0e0
PP
782 if (clock_class->description.value) {
783 BUF_APPEND(", %spartial-descr=\"%.32s\"",
784 PRFIELD(clock_class->description.value));
785 }
786
787 if (clock_class->uuid.value) {
788 BUF_APPEND_UUID(clock_class->uuid.value);
57ffc2f1
PP
789 }
790
791 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64 ", "
792 "%soffset-s=%" PRId64 ", "
7b33a0e0
PP
793 "%soffset-cycles=%" PRIu64 ", %sis-absolute=%d, "
794 "%sbase-offset-ns=%" PRId64,
57ffc2f1 795 PRFIELD(clock_class->frozen), PRFIELD(clock_class->precision),
7b33a0e0
PP
796 PRFIELD(clock_class->offset_seconds),
797 PRFIELD(clock_class->offset_cycles),
798 PRFIELD(clock_class->is_absolute),
799 PRFIELD(clock_class->base_offset.value_ns));
a6918753 800
ecbb78c0
PP
801 SET_TMP_PREFIX("cs-pool-");
802 format_object_pool(buf_ch, extended, prefix, &clock_class->cs_pool);
57ffc2f1
PP
803}
804
ecbb78c0
PP
805static inline void format_clock_snapshot(char **buf_ch, bool extended,
806 const char *prefix, const struct bt_clock_snapshot *clock_snapshot)
57ffc2f1
PP
807{
808 char tmp_prefix[64];
7b33a0e0 809 BUF_APPEND(", %svalue=%" PRIu64 ", %sns-from-origin=%" PRId64,
ecbb78c0
PP
810 PRFIELD(clock_snapshot->value_cycles),
811 PRFIELD(clock_snapshot->ns_from_origin));
57ffc2f1
PP
812
813 if (!extended) {
814 return;
815 }
816
ecbb78c0 817 BUF_APPEND(", %sis-set=%d", PRFIELD(clock_snapshot->is_set));
834e9996 818
ecbb78c0 819 if (clock_snapshot->clock_class) {
834e9996 820 BUF_APPEND(", %sclock-class-addr=%p",
ecbb78c0 821 PRFIELD(clock_snapshot->clock_class));
834e9996
PP
822 SET_TMP_PREFIX("clock-class-");
823 format_clock_class(buf_ch, false, tmp_prefix,
ecbb78c0 824 clock_snapshot->clock_class);
834e9996 825 }
57ffc2f1
PP
826}
827
828static inline void format_value(char **buf_ch, bool extended,
10b7a2e4 829 const char *prefix, const struct bt_value *value)
57ffc2f1
PP
830{
831 BUF_APPEND(", %stype=%s",
17582c6d 832 PRFIELD(bt_common_value_type_string(bt_value_get_type(value))));
57ffc2f1
PP
833
834 if (!extended) {
835 return;
836 }
837
838 switch (bt_value_get_type(value)) {
839 case BT_VALUE_TYPE_BOOL:
840 {
b5cdc106 841 bt_bool val = bt_value_bool_get(value);
57ffc2f1 842
57ffc2f1
PP
843 BUF_APPEND(", %svalue=%d", PRFIELD(val));
844 break;
845 }
846 case BT_VALUE_TYPE_INTEGER:
847 {
b5cdc106 848 int64_t val = bt_value_integer_get(value);
57ffc2f1 849
57ffc2f1
PP
850 BUF_APPEND(", %svalue=%" PRId64, PRFIELD(val));
851 break;
852 }
944421ed 853 case BT_VALUE_TYPE_REAL:
57ffc2f1 854 {
b5cdc106 855 double val = bt_value_real_get(value);
57ffc2f1 856
57ffc2f1
PP
857 BUF_APPEND(", %svalue=%f", PRFIELD(val));
858 break;
859 }
860 case BT_VALUE_TYPE_STRING:
861 {
b5cdc106 862 const char *val = bt_value_string_get(value);
57ffc2f1 863
57ffc2f1
PP
864 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val));
865 break;
866 }
867 case BT_VALUE_TYPE_ARRAY:
868 {
44514773 869 int64_t count = bt_value_array_get_size(value);
57ffc2f1 870
8b45963b 871 BT_ASSERT(count >= 0);
57ffc2f1
PP
872 BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count));
873 break;
874 }
875 case BT_VALUE_TYPE_MAP:
876 {
44514773 877 int64_t count = bt_value_map_get_size(value);
57ffc2f1 878
8b45963b 879 BT_ASSERT(count >= 0);
57ffc2f1
PP
880 BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count));
881 break;
882 }
883 default:
884 break;
885 }
886}
887
b09a5592
PP
888static inline void format_message(char **buf_ch, bool extended,
889 const char *prefix, const struct bt_message *msg)
57ffc2f1
PP
890{
891 char tmp_prefix[64];
892
893 BUF_APPEND(", %stype=%s",
b09a5592 894 PRFIELD(bt_message_type_string(msg->type)));
57ffc2f1
PP
895
896 if (!extended) {
897 return;
898 }
899
f7c3ac09 900 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
b09a5592 901 PRFIELD(msg->frozen), PRFIELD(msg->graph));
57ffc2f1 902
b09a5592
PP
903 switch (msg->type) {
904 case BT_MESSAGE_TYPE_EVENT:
57ffc2f1 905 {
b09a5592
PP
906 const struct bt_message_event *msg_event =
907 (const void *) msg;
57ffc2f1 908
b09a5592 909 if (msg_event->event) {
834e9996 910 SET_TMP_PREFIX("event-");
b09a5592 911 format_event(buf_ch, true, tmp_prefix, msg_event->event);
834e9996
PP
912 }
913
57ffc2f1
PP
914 break;
915 }
b09a5592 916 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
57ffc2f1 917 {
b09a5592
PP
918 const struct bt_message_stream_beginning *msg_stream =
919 (const void *) msg;
57ffc2f1 920
b09a5592 921 if (msg_stream->stream) {
834e9996 922 SET_TMP_PREFIX("stream-");
b09a5592 923 format_stream(buf_ch, true, tmp_prefix, msg_stream->stream);
834e9996
PP
924 }
925
57ffc2f1
PP
926 break;
927 }
b09a5592 928 case BT_MESSAGE_TYPE_STREAM_END:
57ffc2f1 929 {
b09a5592
PP
930 const struct bt_message_stream_end *msg_stream =
931 (const void *) msg;
57ffc2f1 932
b09a5592 933 if (msg_stream->stream) {
834e9996 934 SET_TMP_PREFIX("stream-");
b09a5592 935 format_stream(buf_ch, true, tmp_prefix, msg_stream->stream);
834e9996
PP
936 }
937
57ffc2f1
PP
938 break;
939 }
b09a5592 940 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
57ffc2f1 941 {
b09a5592
PP
942 const struct bt_message_packet_beginning *msg_packet =
943 (const void *) msg;
57ffc2f1 944
b09a5592 945 if (msg_packet->packet) {
834e9996 946 SET_TMP_PREFIX("packet-");
b09a5592 947 format_packet(buf_ch, true, tmp_prefix, msg_packet->packet);
834e9996
PP
948 }
949
57ffc2f1
PP
950 break;
951 }
b09a5592 952 case BT_MESSAGE_TYPE_PACKET_END:
57ffc2f1 953 {
b09a5592
PP
954 const struct bt_message_packet_end *msg_packet =
955 (const void *) msg;
57ffc2f1 956
b09a5592 957 if (msg_packet->packet) {
834e9996 958 SET_TMP_PREFIX("packet-");
b09a5592 959 format_packet(buf_ch, true, tmp_prefix, msg_packet->packet);
834e9996
PP
960 }
961
57ffc2f1
PP
962 break;
963 }
57ffc2f1
PP
964 default:
965 break;
966 }
967}
968
969static inline void format_plugin_so_shared_lib_handle(char **buf_ch,
970 const char *prefix,
10b7a2e4 971 const struct bt_plugin_so_shared_lib_handle *handle)
57ffc2f1
PP
972{
973 BUF_APPEND(", %saddr=%p", PRFIELD(handle));
974
975 if (handle->path) {
834e9996 976 BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle->path));
57ffc2f1
PP
977 }
978}
979
980static inline void format_component_class(char **buf_ch, bool extended,
10b7a2e4
PP
981 const char *prefix,
982 const struct bt_component_class *comp_class)
57ffc2f1
PP
983{
984 char tmp_prefix[64];
985
986 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
987 PRFIELD(bt_component_class_type_string(comp_class->type)),
834e9996 988 PRFIELD_GSTRING(comp_class->name));
57ffc2f1
PP
989
990 if (comp_class->description) {
991 BUF_APPEND(", %spartial-descr=\"%.32s\"",
834e9996 992 PRFIELD_GSTRING(comp_class->description));
57ffc2f1
PP
993 }
994
995 if (!extended) {
996 return;
997 }
998
999 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class->frozen));
1000
1001 if (comp_class->so_handle) {
1002 SET_TMP_PREFIX("so-handle-");
1003 format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix,
1004 comp_class->so_handle);
1005 }
1006}
1007
1008static inline void format_component(char **buf_ch, bool extended,
10b7a2e4 1009 const char *prefix, const struct bt_component *component)
57ffc2f1
PP
1010{
1011 char tmp_prefix[64];
1012
834e9996
PP
1013 BUF_APPEND(", %sname=\"%s\"",
1014 PRFIELD_GSTRING(component->name));
1015
1016 if (component->class) {
1017 SET_TMP_PREFIX("class-");
1018 format_component_class(buf_ch, extended, tmp_prefix,
1019 component->class);
1020 }
57ffc2f1
PP
1021
1022 if (!extended) {
1023 return;
1024 }
1025
a6918753
PP
1026 if (component->input_ports) {
1027 BUF_APPEND(", %sinput-port-count=%u",
1028 PRFIELD(component->input_ports->len));
1029 }
1030
1031 if (component->output_ports) {
1032 BUF_APPEND(", %soutput-port-count=%u",
1033 PRFIELD(component->output_ports->len));
1034 }
57ffc2f1
PP
1035}
1036
1037static inline void format_port(char **buf_ch, bool extended,
10b7a2e4 1038 const char *prefix, const struct bt_port *port)
57ffc2f1
PP
1039{
1040 char tmp_prefix[64];
1041
1042 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1043 PRFIELD(bt_port_type_string(port->type)),
834e9996 1044 PRFIELD_GSTRING(port->name));
57ffc2f1
PP
1045
1046 if (!extended) {
1047 return;
1048 }
1049
1050 if (port->connection) {
1051 SET_TMP_PREFIX("conn-");
1052 format_connection(buf_ch, false, tmp_prefix, port->connection);
1053 }
1054}
1055
1056static inline void format_connection(char **buf_ch, bool extended,
10b7a2e4 1057 const char *prefix, const struct bt_connection *connection)
57ffc2f1
PP
1058{
1059 char tmp_prefix[64];
1060
1061 if (!extended) {
1062 return;
1063 }
1064
1065 if (connection->upstream_port) {
1066 SET_TMP_PREFIX("upstream-port-");
1067 format_port(buf_ch, false, tmp_prefix,
1068 connection->upstream_port);
1069 }
1070
1071 if (connection->downstream_port) {
1072 SET_TMP_PREFIX("downstream-port-");
1073 format_port(buf_ch, false, tmp_prefix,
1074 connection->downstream_port);
1075 }
1076}
1077
1078static inline void format_graph(char **buf_ch, bool extended,
10b7a2e4 1079 const char *prefix, const struct bt_graph *graph)
57ffc2f1 1080{
f7c3ac09
PP
1081 char tmp_prefix[64];
1082
57ffc2f1
PP
1083 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph->canceled));
1084
1085 if (!extended) {
1086 return;
1087 }
1088
a6918753
PP
1089 if (graph->components) {
1090 BUF_APPEND(", %scomp-count=%u",
1091 PRFIELD(graph->components->len));
1092 }
1093
1094 if (graph->connections) {
1095 BUF_APPEND(", %sconn-count=%u",
1096 PRFIELD(graph->connections->len));
1097 }
f7c3ac09
PP
1098
1099 SET_TMP_PREFIX("en-pool-");
1100 format_object_pool(buf_ch, extended, prefix,
b09a5592 1101 &graph->event_msg_pool);
f7c3ac09
PP
1102 SET_TMP_PREFIX("pbn-pool-");
1103 format_object_pool(buf_ch, extended, prefix,
b09a5592 1104 &graph->packet_begin_msg_pool);
f7c3ac09
PP
1105 SET_TMP_PREFIX("pen-pool-");
1106 format_object_pool(buf_ch, extended, prefix,
b09a5592 1107 &graph->packet_end_msg_pool);
57ffc2f1
PP
1108}
1109
b09a5592 1110static inline void format_message_iterator(char **buf_ch,
57ffc2f1 1111 bool extended, const char *prefix,
b09a5592 1112 const struct bt_message_iterator *iterator)
57ffc2f1
PP
1113{
1114 const char *type;
1115 char tmp_prefix[64];
1116
b09a5592
PP
1117 if (iterator->type == BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT) {
1118 type = "BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT";
1119 } else if (iterator->type == BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT) {
1120 type = "BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT";
57ffc2f1
PP
1121 } else {
1122 type = "(unknown)";
1123 }
1124
1125 BUF_APPEND(", %stype=%s", PRFIELD(type));
1126
1127 switch (iterator->type) {
b09a5592 1128 case BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT:
57ffc2f1 1129 {
b09a5592 1130 const struct bt_self_component_port_input_message_iterator *
10b7a2e4 1131 port_in_iter = (const void *) iterator;
57ffc2f1 1132
834e9996 1133 if (port_in_iter->upstream_component) {
57ffc2f1
PP
1134 SET_TMP_PREFIX("upstream-comp-");
1135 format_component(buf_ch, false, tmp_prefix,
834e9996 1136 port_in_iter->upstream_component);
57ffc2f1
PP
1137 }
1138
834e9996 1139 if (port_in_iter->upstream_port) {
57ffc2f1
PP
1140 SET_TMP_PREFIX("upstream-port-");
1141 format_port(buf_ch, false, tmp_prefix,
834e9996 1142 port_in_iter->upstream_port);
57ffc2f1
PP
1143 }
1144
834e9996 1145 if (port_in_iter->connection) {
57ffc2f1
PP
1146 SET_TMP_PREFIX("upstream-conn-");
1147 format_connection(buf_ch, false, tmp_prefix,
834e9996 1148 port_in_iter->connection);
57ffc2f1
PP
1149 }
1150 break;
1151 }
b09a5592 1152 case BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT:
57ffc2f1 1153 {
b09a5592 1154 const struct bt_port_output_message_iterator *port_out_iter =
10b7a2e4 1155 (const void *) iterator;
57ffc2f1 1156
834e9996
PP
1157 if (port_out_iter->graph) {
1158 SET_TMP_PREFIX("graph-");
1159 format_graph(buf_ch, false, tmp_prefix,
1160 port_out_iter->graph);
1161 }
1162
1163 if (port_out_iter->colander) {
1164 SET_TMP_PREFIX("colander-comp-");
1165 format_component(buf_ch, false, tmp_prefix,
1166 (void *) port_out_iter->colander);
1167 }
1168
57ffc2f1
PP
1169 break;
1170 }
1171 default:
1172 break;
1173 }
1174}
1175
1176static inline void format_plugin(char **buf_ch, bool extended,
3a2cb327 1177 const char *prefix, const struct bt_plugin *plugin)
57ffc2f1
PP
1178{
1179 char tmp_prefix[64];
1180
1181 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin->type)));
1182
1183 if (plugin->info.path_set) {
1184 BUF_APPEND(", %spath=\"%s\"",
834e9996 1185 PRFIELD_GSTRING(plugin->info.path));
57ffc2f1
PP
1186 }
1187
1188 if (plugin->info.name_set) {
1189 BUF_APPEND(", %sname=\"%s\"",
834e9996 1190 PRFIELD_GSTRING(plugin->info.name));
57ffc2f1
PP
1191 }
1192
1193 if (!extended) {
1194 return;
1195 }
1196
1197 if (plugin->info.author_set) {
1198 BUF_APPEND(", %sauthor=\"%s\"",
834e9996 1199 PRFIELD_GSTRING(plugin->info.author));
57ffc2f1
PP
1200 }
1201
1202 if (plugin->info.license_set) {
1203 BUF_APPEND(", %slicense=\"%s\"",
834e9996 1204 PRFIELD_GSTRING(plugin->info.license));
57ffc2f1
PP
1205 }
1206
1207 if (plugin->info.version_set) {
1208 BUF_APPEND(", %sversion=%u.%u.%u%s",
1209 PRFIELD(plugin->info.version.major),
1210 plugin->info.version.minor,
1211 plugin->info.version.patch,
1212 plugin->info.version.extra ?
1213 plugin->info.version.extra->str : "");
1214 }
1215
834e9996
PP
1216 BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, "
1217 "%ssink-comp-class-count=%u",
1218 PRFIELD(plugin->src_comp_classes->len),
1219 PRFIELD(plugin->flt_comp_classes->len),
1220 PRFIELD(plugin->sink_comp_classes->len));
57ffc2f1
PP
1221
1222 if (plugin->spec_data) {
10b7a2e4
PP
1223 const struct bt_plugin_so_spec_data *spec_data =
1224 (const void *) plugin->spec_data;
57ffc2f1
PP
1225
1226 if (spec_data->shared_lib_handle) {
1227 SET_TMP_PREFIX("so-handle-");
1228 format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix,
1229 spec_data->shared_lib_handle);
1230 }
1231 }
1232}
1233
57ffc2f1
PP
1234static inline void handle_conversion_specifier_bt(void *priv_data,
1235 char **buf_ch, size_t avail_size,
1236 const char **out_fmt_ch, va_list *args)
1237{
1238 const char *fmt_ch = *out_fmt_ch;
1239 bool extended = false;
1240 char prefix[64];
1241 char *prefix_ch = prefix;
10b7a2e4 1242 const void *obj;
57ffc2f1
PP
1243
1244 /* skip "%!" */
1245 fmt_ch += 2;
1246
7b33a0e0
PP
1247 if (*fmt_ch == 'u') {
1248 /* UUID */
1249 obj = va_arg(*args, void *);
1250 format_uuid(buf_ch, obj);
1251 goto update_fmt;
1252 }
1253
57ffc2f1
PP
1254 if (*fmt_ch == '[') {
1255 /* local prefix */
1256 fmt_ch++;
1257
1258 while (true) {
1259 if (*fmt_ch == ']') {
1260 *prefix_ch = '\0';
1261 fmt_ch++;
1262 break;
1263 }
1264
1265 *prefix_ch = *fmt_ch;
1266 prefix_ch++;
1267 fmt_ch++;
1268 }
1269 }
1270
1271 *prefix_ch = '\0';
1272
1273 if (*fmt_ch == '+') {
1274 extended = true;
1275 fmt_ch++;
1276 }
1277
1278 obj = va_arg(*args, void *);
1279 BUF_APPEND("%saddr=%p", prefix, obj);
1280
1281 if (!obj) {
1282 goto update_fmt;
1283 }
1284
18acc6f8
PP
1285 switch (*fmt_ch) {
1286 case 'F':
939190b3 1287 format_field_class(buf_ch, extended, prefix, obj);
57ffc2f1 1288 break;
18acc6f8
PP
1289 case 'f':
1290 format_field(buf_ch, extended, prefix, obj);
1291 break;
1292 case 'P':
1293 format_field_path(buf_ch, extended, prefix, obj);
1294 break;
1295 case 'E':
1296 format_event_class(buf_ch, extended, prefix, obj);
1297 break;
1298 case 'e':
1299 format_event(buf_ch, extended, prefix, obj);
1300 break;
1301 case 'S':
1302 format_stream_class(buf_ch, extended, prefix, obj);
57ffc2f1 1303 break;
18acc6f8
PP
1304 case 's':
1305 format_stream(buf_ch, extended, prefix, obj);
1306 break;
1307 case 'a':
1308 format_packet(buf_ch, extended, prefix, obj);
1309 break;
1310 case 't':
1311 format_trace(buf_ch, extended, prefix, obj);
1312 break;
10b7a2e4
PP
1313 case 'T':
1314 format_trace_class(buf_ch, extended, prefix, obj);
1315 break;
18acc6f8
PP
1316 case 'K':
1317 format_clock_class(buf_ch, extended, prefix, obj);
1318 break;
1319 case 'k':
ecbb78c0 1320 format_clock_snapshot(buf_ch, extended, prefix, obj);
18acc6f8
PP
1321 break;
1322 case 'v':
1323 format_value(buf_ch, extended, prefix, obj);
1324 break;
1325 case 'n':
b09a5592 1326 format_message(buf_ch, extended, prefix, obj);
18acc6f8
PP
1327 break;
1328 case 'i':
b09a5592 1329 format_message_iterator(buf_ch, extended, prefix, obj);
18acc6f8
PP
1330 break;
1331 case 'C':
1332 format_component_class(buf_ch, extended, prefix, obj);
1333 break;
1334 case 'c':
1335 format_component(buf_ch, extended, prefix, obj);
1336 break;
1337 case 'p':
1338 format_port(buf_ch, extended, prefix, obj);
1339 break;
1340 case 'x':
1341 format_connection(buf_ch, extended, prefix, obj);
1342 break;
7b33a0e0 1343 case 'l':
18acc6f8
PP
1344 format_plugin(buf_ch, extended, prefix, obj);
1345 break;
1346 case 'g':
1347 format_graph(buf_ch, extended, prefix, obj);
1348 break;
1349 case 'o':
1350 format_object_pool(buf_ch, extended, prefix, obj);
1351 break;
1352 case 'O':
1353 format_object(buf_ch, extended, prefix, obj);
1354 break;
1355 default:
1356 abort();
57ffc2f1
PP
1357 }
1358
1359update_fmt:
1360 fmt_ch++;
1361 *out_fmt_ch = fmt_ch;
1362}
1363
1364BT_HIDDEN
1365void bt_lib_log(const char *func, const char *file, unsigned line,
1366 int lvl, const char *tag, const char *fmt, ...)
1367{
1368 va_list args;
1369
8b45963b 1370 BT_ASSERT(fmt);
57ffc2f1
PP
1371 va_start(args, fmt);
1372 bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!',
1373 handle_conversion_specifier_bt, NULL, fmt, &args);
1374 va_end(args);
1375 _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf);
1376}
This page took 0.096542 seconds and 4 git commands to generate.