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