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