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