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