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