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