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