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