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