lib: use object pool for event and packet notifications
[babeltrace.git] / lib / lib-logging.c
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
23 #define BT_LOG_TAG "LIB-LOGGING"
24
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <inttypes.h>
30 #include <stdint.h>
31 #include <wchar.h>
32 #include <glib.h>
33 #include <babeltrace/common-internal.h>
34 #include <babeltrace/lib-logging-internal.h>
35 #include <babeltrace/ref-internal.h>
36 #include <babeltrace/values-internal.h>
37 #include <babeltrace/object-pool-internal.h>
38 #include <babeltrace/ctf-ir/field-types-internal.h>
39 #include <babeltrace/ctf-ir/fields-internal.h>
40 #include <babeltrace/ctf-ir/event-class-internal.h>
41 #include <babeltrace/ctf-ir/event-internal.h>
42 #include <babeltrace/ctf-ir/packet-internal.h>
43 #include <babeltrace/ctf-ir/stream-class-internal.h>
44 #include <babeltrace/ctf-ir/stream-internal.h>
45 #include <babeltrace/ctf-ir/trace-internal.h>
46 #include <babeltrace/ctf-ir/clock-class-internal.h>
47 #include <babeltrace/ctf-ir/clock-value-internal.h>
48 #include <babeltrace/ctf-ir/field-path-internal.h>
49 #include <babeltrace/ctf-ir/utils-internal.h>
50 #include <babeltrace/ctf-writer/field-types-internal.h>
51 #include <babeltrace/ctf-writer/fields-internal.h>
52 #include <babeltrace/ctf-writer/event-internal.h>
53 #include <babeltrace/ctf-writer/stream-class-internal.h>
54 #include <babeltrace/ctf-writer/stream-internal.h>
55 #include <babeltrace/ctf-writer/trace-internal.h>
56 #include <babeltrace/ctf-writer/clock-internal.h>
57 #include <babeltrace/ctf-writer/writer-internal.h>
58 #include <babeltrace/graph/clock-class-priority-map-internal.h>
59 #include <babeltrace/graph/component-class-internal.h>
60 #include <babeltrace/graph/component-class-sink-colander-internal.h>
61 #include <babeltrace/graph/component-filter-internal.h>
62 #include <babeltrace/graph/component-internal.h>
63 #include <babeltrace/graph/component-sink-internal.h>
64 #include <babeltrace/graph/component-source-internal.h>
65 #include <babeltrace/graph/connection-internal.h>
66 #include <babeltrace/graph/graph-internal.h>
67 #include <babeltrace/graph/notification-discarded-elements-internal.h>
68 #include <babeltrace/graph/notification-event-internal.h>
69 #include <babeltrace/graph/notification-inactivity-internal.h>
70 #include <babeltrace/graph/notification-internal.h>
71 #include <babeltrace/graph/notification-iterator-internal.h>
72 #include <babeltrace/graph/notification-packet-internal.h>
73 #include <babeltrace/graph/notification-stream-internal.h>
74 #include <babeltrace/graph/port-internal.h>
75 #include <babeltrace/plugin/plugin-internal.h>
76 #include <babeltrace/plugin/plugin-so-internal.h>
77
78 #define LIB_LOGGING_BUF_SIZE (4096 * 4)
79
80 static char __thread lib_logging_buf[LIB_LOGGING_BUF_SIZE];
81
82 #define BUF_APPEND(_fmt, ...) \
83 do { \
84 int _count; \
85 size_t _size = LIB_LOGGING_BUF_SIZE - \
86 (size_t) (*buf_ch - lib_logging_buf); \
87 _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \
88 BT_ASSERT(_count >= 0); \
89 *buf_ch += MIN(_count, _size); \
90 if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \
91 return; \
92 } \
93 } while (0)
94
95 #define BUF_APPEND_UUID(_uuid) \
96 BUF_APPEND(", %suuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"", \
97 prefix, \
98 (unsigned int) (_uuid)[0], \
99 (unsigned int) (_uuid)[1], \
100 (unsigned int) (_uuid)[2], \
101 (unsigned int) (_uuid)[3], \
102 (unsigned int) (_uuid)[4], \
103 (unsigned int) (_uuid)[5], \
104 (unsigned int) (_uuid)[6], \
105 (unsigned int) (_uuid)[7], \
106 (unsigned int) (_uuid)[8], \
107 (unsigned int) (_uuid)[9], \
108 (unsigned int) (_uuid)[10], \
109 (unsigned int) (_uuid)[11], \
110 (unsigned int) (_uuid)[12], \
111 (unsigned int) (_uuid)[13], \
112 (unsigned int) (_uuid)[14], \
113 (unsigned int) (_uuid)[15])
114
115 #define PRFIELD(_expr) prefix, (_expr)
116
117 #define SET_TMP_PREFIX(_prefix2) \
118 do { \
119 strcpy(tmp_prefix, prefix); \
120 strcat(tmp_prefix, (_prefix2)); \
121 } while (0)
122
123 typedef void (*format_func)(char **, bool, const char *, void *);
124
125 static inline void format_component(char **buf_ch, bool extended,
126 const char *prefix, struct bt_component *component);
127
128 static inline void format_port(char **buf_ch, bool extended,
129 const char *prefix, struct bt_port *port);
130
131 static inline void format_connection(char **buf_ch, bool extended,
132 const char *prefix, struct bt_connection *connection);
133
134 static inline void format_ref_count(char **buf_ch, bool extended,
135 const char *prefix, struct bt_object *obj)
136 {
137 BUF_APPEND(", %sref-count=%lu", prefix, obj->ref_count.count);
138 }
139
140 static inline void format_object_pool(char **buf_ch, bool extended,
141 const char *prefix, struct bt_object_pool *pool)
142 {
143 BUF_APPEND(", %ssize=%zu", PRFIELD(pool->size));
144
145 if (pool->objects) {
146 BUF_APPEND(", %scap=%u", PRFIELD(pool->objects->len));
147 }
148 }
149
150 static inline void format_field_type_common(char **buf_ch, bool extended,
151 const char *prefix, struct bt_field_type_common *field_type)
152 {
153 BUF_APPEND(", %stype-id=%s, %salignment=%u",
154 PRFIELD(bt_common_field_type_id_string(field_type->id)),
155 PRFIELD(field_type->alignment));
156
157 if (extended) {
158 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_type->frozen));
159 } else {
160 return;
161 }
162
163 if (field_type->id == BT_FIELD_TYPE_ID_UNKNOWN) {
164 return;
165 }
166
167 switch (field_type->id) {
168 case BT_FIELD_TYPE_ID_INTEGER:
169 {
170 struct bt_field_type_common_integer *integer =
171 BT_FROM_COMMON(field_type);
172
173 BUF_APPEND(", %ssize=%u, %sis-signed=%d, %sbyte-order=%s, "
174 "%sbase=%d, %sencoding=%s, "
175 "%smapped-clock-class-addr=%p",
176 PRFIELD(integer->size), PRFIELD(integer->is_signed),
177 PRFIELD(bt_common_byte_order_string(integer->user_byte_order)),
178 PRFIELD(integer->base),
179 PRFIELD(bt_common_string_encoding_string(integer->encoding)),
180 PRFIELD(integer->mapped_clock_class));
181
182 if (integer->mapped_clock_class) {
183 BUF_APPEND(", %smapped-clock-class-name=\"%s\"",
184 PRFIELD(bt_clock_class_get_name(integer->mapped_clock_class)));
185 }
186 break;
187 }
188 case BT_FIELD_TYPE_ID_FLOAT:
189 {
190 struct bt_field_type_common_floating_point *flt =
191 BT_FROM_COMMON(field_type);
192
193 BUF_APPEND(", %sexp-dig=%u, %smant-dig=%u, %sbyte-order=%s",
194 PRFIELD(flt->exp_dig), PRFIELD(flt->mant_dig),
195 PRFIELD(bt_common_byte_order_string(flt->user_byte_order)));
196 break;
197 }
198 case BT_FIELD_TYPE_ID_ENUM:
199 {
200 struct bt_field_type_common_enumeration *enm =
201 BT_FROM_COMMON(field_type);
202
203 BUF_APPEND(", %smapping-count=%u",
204 PRFIELD(enm->entries->len));
205 break;
206 }
207 case BT_FIELD_TYPE_ID_STRING:
208 {
209 struct bt_field_type_common_string *str =
210 BT_FROM_COMMON(field_type);
211
212 BUF_APPEND(", %sencoding=%s",
213 PRFIELD(bt_common_string_encoding_string(str->encoding)));
214 break;
215 }
216 case BT_FIELD_TYPE_ID_STRUCT:
217 {
218 struct bt_field_type_common_structure *structure =
219 BT_FROM_COMMON(field_type);
220
221 BUF_APPEND(", %sfield-count=%u",
222 PRFIELD(structure->fields->len));
223 break;
224 }
225 case BT_FIELD_TYPE_ID_SEQUENCE:
226 {
227 struct bt_field_type_common_sequence *seq =
228 BT_FROM_COMMON(field_type);
229
230 BUF_APPEND(", %slength-ft-addr=\"%s\", %selem-ft-addr=%p",
231 PRFIELD(seq->length_field_name->str),
232 PRFIELD(seq->element_ft));
233 break;
234 }
235 case BT_FIELD_TYPE_ID_VARIANT:
236 {
237 struct bt_field_type_common_variant *variant =
238 BT_FROM_COMMON(field_type);
239
240 BUF_APPEND(", %stag-name=\"%s\", %sfield-count=%u",
241 PRFIELD(variant->tag_name->str),
242 PRFIELD(variant->choices->len));
243 break;
244 }
245 default:
246 break;
247 }
248 }
249
250 static inline void format_field_type(char **buf_ch, bool extended,
251 const char *prefix, struct bt_field_type *field_type)
252 {
253 format_field_type_common(buf_ch, extended, prefix,
254 (void *) field_type);
255 }
256
257 static inline void format_writer_field_type(char **buf_ch, bool extended,
258 const char *prefix, struct bt_ctf_field_type *field_type)
259 {
260 format_field_type_common(buf_ch, extended, prefix,
261 (void *) field_type);
262 }
263
264 static inline void format_field_common_integer_extended(char **buf_ch,
265 const char *prefix, struct bt_field_common *field)
266 {
267 struct bt_field_common_integer *integer = BT_FROM_COMMON(field);
268 struct bt_field_type_common_integer *field_type =
269 BT_FROM_COMMON(field->type);
270 const char *fmt = NULL;
271
272 BT_ASSERT(field_type);
273
274 if (field_type->base == 8) {
275 fmt = ", %svalue=%" PRIo64;
276 } else if (field_type->base == 16) {
277 fmt = ", %svalue=%" PRIx64;
278 }
279
280 if (field_type->is_signed) {
281 if (!fmt) {
282 fmt = ", %svalue=%" PRId64;
283 }
284
285 BUF_APPEND(fmt, PRFIELD(integer->payload.signd));
286 } else {
287 if (!fmt) {
288 fmt = ", %svalue=%" PRIu64;
289 }
290
291 BUF_APPEND(fmt, PRFIELD(integer->payload.unsignd));
292 }
293 }
294
295 static inline void format_field_common(char **buf_ch, bool extended,
296 const char *prefix, struct bt_field_common *field)
297 {
298 BUF_APPEND(", %sis-set=%d", PRFIELD(field->payload_set));
299
300 if (extended) {
301 BUF_APPEND(", %sis-frozen=%d", PRFIELD(field->frozen));
302 }
303
304 BUF_APPEND(", %stype-addr=%p", PRFIELD(field->type));
305
306 if (!field->type) {
307 return;
308 }
309
310 BUF_APPEND(", %stype-id=%s",
311 PRFIELD(bt_common_field_type_id_string(field->type->id)));
312
313 if (!extended || field->type->id == BT_FIELD_TYPE_ID_UNKNOWN ||
314 !field->payload_set) {
315 return;
316 }
317
318 switch (field->type->id) {
319 case BT_FIELD_TYPE_ID_INTEGER:
320 {
321 format_field_common_integer_extended(buf_ch, prefix, field);
322 break;
323 }
324 case BT_FIELD_TYPE_ID_FLOAT:
325 {
326 struct bt_field_common_floating_point *flt =
327 BT_FROM_COMMON(field);
328
329 BUF_APPEND(", %svalue=%f", PRFIELD(flt->payload));
330 break;
331 }
332 case BT_FIELD_TYPE_ID_STRING:
333 {
334 struct bt_field_common_string *str =
335 BT_FROM_COMMON(field);
336
337 if (str->payload) {
338 BT_ASSERT(str->payload);
339 BUF_APPEND(", %spartial-value=\"%.32s\"",
340 PRFIELD(str->payload->str));
341
342 }
343 break;
344 }
345 case BT_FIELD_TYPE_ID_SEQUENCE:
346 {
347 struct bt_field_common_sequence *seq =
348 BT_FROM_COMMON(field);
349
350 BUF_APPEND(", %slength=%" PRIu64, PRFIELD(seq->length));
351
352 if (seq->elements) {
353 BUF_APPEND(", %sallocated-length=%u",
354 PRFIELD(seq->elements->len));
355 }
356 break;
357 }
358 case BT_FIELD_TYPE_ID_VARIANT:
359 {
360 struct bt_field_common_variant *variant =
361 BT_FROM_COMMON(field);
362
363 BUF_APPEND(", %scur-field-addr=%p",
364 PRFIELD(variant->current_field));
365 break;
366 }
367 default:
368 break;
369 }
370 }
371
372 static inline void format_field(char **buf_ch, bool extended,
373 const char *prefix, struct bt_field *field)
374 {
375 struct bt_field_common *common_field = (void *) field;
376
377 format_field_common(buf_ch, extended, prefix, (void *) field);
378
379 if (!extended) {
380 return;
381 }
382
383 if (!common_field->type) {
384 return;
385 }
386
387 switch (common_field->type->id) {
388 case BT_FIELD_TYPE_ID_ENUM:
389 {
390 struct bt_field_common_integer *integer = (void *) field;
391 struct bt_field_type_common_enumeration *enum_ft =
392 BT_FROM_COMMON(common_field->type);
393
394 if (enum_ft->container_ft) {
395 if (enum_ft->container_ft->is_signed) {
396 BUF_APPEND(", %svalue=%" PRId64,
397 PRFIELD(integer->payload.signd));
398 } else {
399 BUF_APPEND(", %svalue=%" PRIu64,
400 PRFIELD(integer->payload.unsignd));
401 }
402 }
403 break;
404 }
405 default:
406 break;
407 }
408 }
409
410 static inline void format_writer_field(char **buf_ch, bool extended,
411 const char *prefix, struct bt_ctf_field *field)
412 {
413 struct bt_field_common *common_field = (void *) field;
414
415 format_field_common(buf_ch, extended, prefix, (void *) field);
416
417 if (!extended) {
418 return;
419 }
420
421 if (!common_field->type) {
422 return;
423 }
424
425 switch (common_field->type->id) {
426 case BT_FIELD_TYPE_ID_ENUM:
427 {
428 struct bt_ctf_field_enumeration *enumeration = (void *) field;
429
430 if (enumeration->container) {
431 format_writer_field(buf_ch, extended, prefix,
432 (void *) enumeration->container);
433 }
434 break;
435 }
436 case BT_FIELD_TYPE_ID_VARIANT:
437 {
438 struct bt_ctf_field_variant *variant = (void *) field;
439
440 BUF_APPEND(", %stag-field-addr=%p", PRFIELD(variant->tag));
441 break;
442 }
443 default:
444 break;
445 }
446 }
447
448 static inline void format_field_path(char **buf_ch, bool extended,
449 const char *prefix, struct bt_field_path *field_path)
450 {
451 uint64_t i;
452
453 if (field_path->indexes) {
454 BT_ASSERT(field_path->indexes);
455 BUF_APPEND(", %sindex-count=%u", PRFIELD(field_path->indexes->len));
456 }
457
458 if (!extended || !field_path->indexes) {
459 return;
460 }
461
462 BUF_APPEND(", %spath=[%s", PRFIELD(bt_common_scope_string(field_path->root)));
463
464 for (i = 0; i < field_path->indexes->len; i++) {
465 int index = g_array_index(field_path->indexes, int, i);
466
467 BUF_APPEND(", %d", index);
468 }
469
470 BUF_APPEND("%s", "]");
471 }
472
473 static inline void format_trace_common(char **buf_ch, bool extended,
474 const char *prefix, struct bt_trace_common *trace)
475 {
476 if (trace->name) {
477 BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name->str));
478 }
479
480 if (!extended) {
481 return;
482 }
483
484 BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen));
485
486 if (trace->uuid_set) {
487 BUF_APPEND_UUID(trace->uuid);
488 }
489
490 if (trace->clock_classes) {
491 BUF_APPEND(", %sclock-class-count=%u",
492 PRFIELD(trace->clock_classes->len));
493 }
494
495 if (trace->stream_classes) {
496 BUF_APPEND(", %sstream-class-count=%u",
497 PRFIELD(trace->stream_classes->len));
498 }
499
500 if (trace->streams) {
501 BUF_APPEND(", %sstream-count=%u",
502 PRFIELD(trace->streams->len));
503 }
504
505 BUF_APPEND(", %spacket-header-ft-addr=%p",
506 PRFIELD(trace->packet_header_field_type));
507 }
508
509 static inline void format_trace(char **buf_ch, bool extended,
510 const char *prefix, struct bt_trace *trace)
511 {
512 char tmp_prefix[64];
513
514 format_trace_common(buf_ch, extended, prefix, BT_TO_COMMON(trace));
515
516 if (!extended) {
517 return;
518 }
519
520 BUF_APPEND(", %sis-static=%d", PRFIELD(trace->is_static));
521 SET_TMP_PREFIX("phf-pool-");
522 format_object_pool(buf_ch, extended, prefix,
523 &trace->packet_header_field_pool);
524 }
525
526 static inline void format_writer_trace(char **buf_ch, bool extended,
527 const char *prefix, struct bt_ctf_trace *trace)
528 {
529 format_trace_common(buf_ch, extended, prefix, BT_TO_COMMON(trace));
530 }
531
532 static inline void format_stream_class_common(char **buf_ch, bool extended,
533 const char *prefix, struct bt_stream_class_common *stream_class,
534 format_func trace_format_func)
535 {
536 struct bt_trace_common *trace;
537 char tmp_prefix[64];
538
539 if (stream_class->id_set) {
540 BUF_APPEND(", %sid=%" PRId64, PRFIELD(stream_class->id));
541 }
542
543 if (stream_class->name) {
544 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class->name->str));
545 }
546
547 if (!extended) {
548 return;
549 }
550
551 BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class->frozen));
552
553 if (stream_class->event_classes) {
554 BUF_APPEND(", %sevent-class-count=%u",
555 PRFIELD(stream_class->event_classes->len));
556 }
557
558 BUF_APPEND(", %spacket-context-ft-addr=%p, "
559 "%sevent-header-ft-addr=%p, %sevent-context-ft-addr=%p",
560 PRFIELD(stream_class->packet_context_field_type),
561 PRFIELD(stream_class->event_header_field_type),
562 PRFIELD(stream_class->event_context_field_type));
563 trace = bt_stream_class_common_borrow_trace(stream_class);
564 if (!trace) {
565 return;
566 }
567
568 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace));
569 SET_TMP_PREFIX("trace-");
570 trace_format_func(buf_ch, false, tmp_prefix, trace);
571 }
572
573 static inline void format_stream_class(char **buf_ch, bool extended,
574 const char *prefix, struct bt_stream_class *stream_class)
575 {
576 char tmp_prefix[64];
577
578 format_stream_class_common(buf_ch, extended, prefix,
579 BT_TO_COMMON(stream_class), (format_func) format_trace);
580
581 if (!extended) {
582 return;
583 }
584
585 SET_TMP_PREFIX("ehf-pool-");
586 format_object_pool(buf_ch, extended, prefix,
587 &stream_class->event_header_field_pool);
588 SET_TMP_PREFIX("pcf-pool-");
589 format_object_pool(buf_ch, extended, prefix,
590 &stream_class->packet_context_field_pool);
591 }
592
593 static inline void format_writer_stream_class(char **buf_ch, bool extended,
594 const char *prefix, struct bt_ctf_stream_class *stream_class)
595 {
596 format_stream_class_common(buf_ch, extended, prefix,
597 BT_TO_COMMON(stream_class), (format_func) format_writer_trace);
598
599 if (extended && stream_class->clock) {
600 BUF_APPEND(", %sctf-writer-clock-addr=%p, "
601 "%sctf-writer-clock-name=\"%s\"",
602 PRFIELD(stream_class->clock),
603 PRFIELD(bt_clock_class_get_name(
604 BT_TO_COMMON(stream_class->clock->clock_class))));
605 }
606 }
607
608 static inline void format_event_class_common(char **buf_ch, bool extended,
609 const char *prefix, struct bt_event_class_common *event_class,
610 format_func format_stream_class_func,
611 format_func format_trace_func)
612 {
613 struct bt_stream_class_common *stream_class;
614 struct bt_trace_common *trace;
615 char tmp_prefix[64];
616
617 BUF_APPEND(", %sid=%" PRId64, PRFIELD(event_class->id));
618
619 if (event_class->name) {
620 BUF_APPEND(", %sname=\"%s\"", PRFIELD(event_class->name->str));
621 }
622
623 if (!extended) {
624 return;
625 }
626
627 BUF_APPEND(", %sis-frozen=%d, %slog-level=%s",
628 PRFIELD(event_class->frozen),
629 PRFIELD(bt_common_event_class_log_level_string(event_class->log_level)));
630
631 if (event_class->emf_uri) {
632 BUF_APPEND(", %semf-uri=\"%s\"",
633 PRFIELD(event_class->emf_uri->str));
634 }
635
636 BUF_APPEND(", %scontext-ft-addr=%p, %spayload-ft-addr=%p",
637 PRFIELD(event_class->context_field_type),
638 PRFIELD(event_class->payload_field_type));
639
640 stream_class = bt_event_class_common_borrow_stream_class(event_class);
641 if (!stream_class) {
642 return;
643 }
644
645 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class));
646 SET_TMP_PREFIX("stream-class-");
647 format_stream_class_func(buf_ch, false, tmp_prefix, stream_class);
648 trace = bt_stream_class_common_borrow_trace(stream_class);
649 if (!trace) {
650 return;
651 }
652
653 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace));
654 SET_TMP_PREFIX("trace-");
655 format_trace_func(buf_ch, false, tmp_prefix, trace);
656 }
657
658 static inline void format_event_class(char **buf_ch, bool extended,
659 const char *prefix, struct bt_event_class *event_class)
660 {
661 char tmp_prefix[64];
662
663 format_event_class_common(buf_ch, extended, prefix,
664 BT_TO_COMMON(event_class), (format_func) format_stream_class,
665 (format_func) format_trace);
666
667 if (!extended) {
668 return;
669 }
670
671 SET_TMP_PREFIX("event-pool-");
672 format_object_pool(buf_ch, extended, prefix, &event_class->event_pool);
673 }
674
675 static inline void format_writer_event_class(char **buf_ch, bool extended,
676 const char *prefix, struct bt_ctf_event_class *event_class)
677 {
678 format_event_class_common(buf_ch, extended, prefix,
679 BT_TO_COMMON(event_class),
680 (format_func) format_writer_stream_class,
681 (format_func) format_writer_trace);
682 }
683
684 static inline void format_stream_common(char **buf_ch, bool extended,
685 const char *prefix, struct bt_stream_common *stream,
686 format_func format_stream_class_func,
687 format_func format_trace_func)
688 {
689 struct bt_stream_class_common *stream_class;
690 struct bt_trace_common *trace;
691 char tmp_prefix[64];
692
693 BUF_APPEND(", %sid=%" PRId64, PRFIELD(stream->id));
694
695 if (stream->name) {
696 BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream->name->str));
697 }
698
699 if (!extended) {
700 return;
701 }
702
703 stream_class = bt_stream_common_borrow_class(stream);
704 if (!stream_class) {
705 return;
706 }
707
708 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class));
709 SET_TMP_PREFIX("stream-class-");
710 format_stream_class_func(buf_ch, false, tmp_prefix, stream_class);
711 trace = bt_stream_class_common_borrow_trace(stream_class);
712 if (!trace) {
713 return;
714 }
715
716 trace = (void *) bt_object_borrow_parent(stream);
717 if (!trace) {
718 return;
719 }
720
721 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace));
722 SET_TMP_PREFIX("trace-");
723 format_trace_common(buf_ch, false, tmp_prefix, trace);
724 }
725
726 static inline void format_stream(char **buf_ch, bool extended,
727 const char *prefix, struct bt_stream *stream)
728 {
729 char tmp_prefix[64];
730
731 format_stream_common(buf_ch, extended, prefix, BT_TO_COMMON(stream),
732 (format_func) format_stream_class,
733 (format_func) format_trace);
734 SET_TMP_PREFIX("packet-pool-");
735 format_object_pool(buf_ch, extended, prefix, &stream->packet_pool);
736 }
737
738 static inline void format_writer_stream(char **buf_ch, bool extended,
739 const char *prefix, struct bt_ctf_stream *stream)
740 {
741 format_stream_common(buf_ch, extended, prefix, BT_TO_COMMON(stream),
742 (format_func) format_writer_stream_class,
743 (format_func) format_writer_trace);
744
745 BUF_APPEND(", %sheader-field-addr=%p, %scontext-field-addr=%p"
746 ", %sfd=%d, %smmap-offset=%zu, "
747 "%smmap-base-offset=%zu, %spacket-size=%" PRIu64 ", "
748 "%soffset=%" PRId64 ", %sevent-count=%u, "
749 "%sflushed-packet-count=%u, "
750 "%sdiscarded-event-count=%" PRIu64 ", "
751 "%ssize=%" PRIu64 ", %slast-ts-end=%" PRIu64,
752 PRFIELD(stream->packet_header),
753 PRFIELD(stream->packet_context),
754 PRFIELD(stream->pos.fd),
755 PRFIELD((size_t) stream->pos.mmap_offset),
756 PRFIELD((size_t) stream->pos.mmap_base_offset),
757 PRFIELD(stream->pos.packet_size),
758 PRFIELD(stream->pos.offset),
759 PRFIELD(stream->events->len),
760 PRFIELD(stream->flushed_packet_count),
761 PRFIELD(stream->discarded_events),
762 PRFIELD(stream->size), PRFIELD(stream->last_ts_end));
763
764 if (stream->events) {
765 BUF_APPEND(", %sevent-count=%u", PRFIELD(stream->events->len));
766 }
767
768 BUF_APPEND(", %sheader-field-addr=%p, %scontext-field-addr=%p"
769 ", %sfd=%d, %smmap-offset=%zu, "
770 "%smmap-base-offset=%zu, %spacket-size=%" PRIu64 ", "
771 "%soffset=%" PRId64 ", "
772 "%sflushed-packet-count=%u, "
773 "%sdiscarded-event-count=%" PRIu64 ", "
774 "%ssize=%" PRIu64 ", %slast-ts-end=%" PRIu64,
775 PRFIELD(stream->packet_header),
776 PRFIELD(stream->packet_context),
777 PRFIELD(stream->pos.fd),
778 PRFIELD((size_t) stream->pos.mmap_offset),
779 PRFIELD((size_t) stream->pos.mmap_base_offset),
780 PRFIELD(stream->pos.packet_size),
781 PRFIELD(stream->pos.offset),
782 PRFIELD(stream->flushed_packet_count),
783 PRFIELD(stream->discarded_events),
784 PRFIELD(stream->size), PRFIELD(stream->last_ts_end));
785 }
786
787 static inline void format_packet(char **buf_ch, bool extended,
788 const char *prefix, struct bt_packet *packet)
789 {
790 struct bt_stream *stream;
791 struct bt_trace *trace;
792 char tmp_prefix[64];
793
794 if (!extended) {
795 return;
796 }
797
798 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
799 "%scontext-field-addr=%p",
800 PRFIELD(packet->frozen),
801 PRFIELD(packet->header ? packet->header->field : NULL),
802 PRFIELD(packet->context));
803 stream = bt_packet_borrow_stream(packet);
804 if (!stream) {
805 return;
806 }
807
808 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream));
809 SET_TMP_PREFIX("stream-");
810 format_stream(buf_ch, false, tmp_prefix, stream);
811 trace = (struct bt_trace *) bt_object_borrow_parent(stream);
812 if (!trace) {
813 return;
814 }
815
816 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace));
817 SET_TMP_PREFIX("trace-");
818 format_trace(buf_ch, false, tmp_prefix, trace);
819 }
820
821 static inline void format_event_common(char **buf_ch, bool extended,
822 const char *prefix, struct bt_event_common *event,
823 format_func format_event_class_func,
824 format_func format_stream_class_func,
825 format_func format_trace_func)
826 {
827 struct bt_trace_common *trace;
828 struct bt_stream_class_common *stream_class;
829 char tmp_prefix[64];
830
831 if (!extended) {
832 return;
833 }
834
835 BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, "
836 "%sstream-context-field-addr=%p, "
837 "%scontext-field-addr=%p, %spayload-field-addr=%p, ",
838 PRFIELD(event->frozen),
839 PRFIELD(event->header_field ? event->header_field->field : NULL),
840 PRFIELD(event->stream_event_context_field),
841 PRFIELD(event->context_field),
842 PRFIELD(event->payload_field));
843 BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event->class));
844
845 if (!event->class) {
846 return;
847 }
848
849 SET_TMP_PREFIX("event-class-");
850 format_event_class_func(buf_ch, false, tmp_prefix, event->class);
851 stream_class = bt_event_class_common_borrow_stream_class(event->class);
852 if (stream_class) {
853 BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class));
854 SET_TMP_PREFIX("stream-class-");
855 format_stream_class_func(buf_ch, false, tmp_prefix,
856 stream_class);
857
858 trace = bt_stream_class_common_borrow_trace(stream_class);
859 if (trace) {
860 BUF_APPEND(", %strace-addr=%p", PRFIELD(trace));
861 SET_TMP_PREFIX("trace-");
862 format_trace_func(buf_ch, false, tmp_prefix, trace);
863 }
864 }
865 }
866
867 static inline void format_event(char **buf_ch, bool extended,
868 const char *prefix, struct bt_event *event)
869 {
870 struct bt_packet *packet;
871 struct bt_stream *stream;
872 char tmp_prefix[64];
873
874 format_event_common(buf_ch, extended, prefix, BT_TO_COMMON(event),
875 (format_func) format_event_class,
876 (format_func) format_stream_class, (format_func) format_trace);
877
878 if (!extended) {
879 return;
880 }
881
882 if (event->clock_values) {
883 BUF_APPEND(", %sclock-value-count=%u",
884 PRFIELD(g_hash_table_size(event->clock_values)));
885 }
886
887 packet = bt_event_borrow_packet(event);
888 if (!packet) {
889 return;
890 }
891
892 BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet));
893 SET_TMP_PREFIX("packet-");
894 format_packet(buf_ch, false, tmp_prefix, packet);
895 stream = bt_packet_borrow_stream(packet);
896 if (!stream) {
897 return;
898 }
899
900 BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream));
901 SET_TMP_PREFIX("stream-");
902 format_stream(buf_ch, false, tmp_prefix, stream);
903 }
904
905 static inline void format_writer_event(char **buf_ch, bool extended,
906 const char *prefix, struct bt_event *event)
907 {
908 format_event_common(buf_ch, extended, prefix, BT_TO_COMMON(event),
909 (format_func) format_writer_event_class,
910 (format_func) format_writer_stream_class,
911 (format_func) format_writer_trace);
912 }
913
914 static inline void format_clock_class(char **buf_ch, bool extended,
915 const char *prefix, struct bt_clock_class *clock_class)
916 {
917 char tmp_prefix[64];
918
919 BUF_APPEND(", %sname=\"%s\", %sfreq=%" PRIu64,
920 PRFIELD(clock_class->name->str),
921 PRFIELD(clock_class->frequency));
922
923 if (!extended) {
924 return;
925 }
926
927 if (clock_class->description) {
928 BUF_APPEND(", %spartial-description=\"%.32s\"",
929 PRFIELD(clock_class->description->str));
930 }
931
932 BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64 ", "
933 "%soffset-s=%" PRId64 ", "
934 "%soffset-cycles=%" PRId64 ", %sis-absolute=%d",
935 PRFIELD(clock_class->frozen), PRFIELD(clock_class->precision),
936 PRFIELD(clock_class->offset_s), PRFIELD(clock_class->offset),
937 PRFIELD(clock_class->absolute));
938
939 if (clock_class->uuid_set) {
940 BUF_APPEND_UUID(clock_class->uuid);
941 }
942
943 SET_TMP_PREFIX("cv-pool-");
944 format_object_pool(buf_ch, extended, prefix, &clock_class->cv_pool);
945 }
946
947 static inline void format_clock_value(char **buf_ch, bool extended,
948 const char *prefix, struct bt_clock_value *clock_value)
949 {
950 char tmp_prefix[64];
951 BUF_APPEND(", %svalue=%" PRIu64 ", %sns-from-epoch=%" PRId64,
952 PRFIELD(clock_value->value),
953 PRFIELD(clock_value->ns_from_epoch));
954
955 if (!extended) {
956 return;
957 }
958
959 BUF_APPEND(", %sis-frozen=%d, %sis-set=%d",
960 PRFIELD(clock_value->frozen), PRFIELD(clock_value->is_set));
961 BUF_APPEND(", %sclock-class-addr=%p",
962 PRFIELD(clock_value->clock_class));
963 SET_TMP_PREFIX("clock-class-");
964 format_clock_class(buf_ch, false, tmp_prefix, clock_value->clock_class);
965 }
966
967 static inline void format_value(char **buf_ch, bool extended,
968 const char *prefix, struct bt_value *value)
969 {
970 BUF_APPEND(", %stype=%s",
971 PRFIELD(bt_value_type_string(bt_value_get_type(value))));
972
973 if (!extended) {
974 return;
975 }
976
977 switch (bt_value_get_type(value)) {
978 case BT_VALUE_TYPE_BOOL:
979 {
980 bt_bool val;
981
982 (void) bt_value_bool_get(value, &val);
983 BUF_APPEND(", %svalue=%d", PRFIELD(val));
984 break;
985 }
986 case BT_VALUE_TYPE_INTEGER:
987 {
988 int64_t val;
989
990 (void) bt_value_integer_get(value, &val);
991 BUF_APPEND(", %svalue=%" PRId64, PRFIELD(val));
992 break;
993 }
994 case BT_VALUE_TYPE_FLOAT:
995 {
996 double val;
997
998 (void) bt_value_float_get(value, &val);
999 BUF_APPEND(", %svalue=%f", PRFIELD(val));
1000 break;
1001 }
1002 case BT_VALUE_TYPE_STRING:
1003 {
1004 const char *val;
1005
1006 (void) bt_value_string_get(value, &val);
1007 BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val));
1008 break;
1009 }
1010 case BT_VALUE_TYPE_ARRAY:
1011 {
1012 int64_t count = bt_value_array_size(value);
1013
1014 BT_ASSERT(count >= 0);
1015 BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count));
1016 break;
1017 }
1018 case BT_VALUE_TYPE_MAP:
1019 {
1020 int64_t count = bt_value_map_size(value);
1021
1022 BT_ASSERT(count >= 0);
1023 BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count));
1024 break;
1025 }
1026 default:
1027 break;
1028 }
1029 }
1030
1031 static inline void format_notification(char **buf_ch, bool extended,
1032 const char *prefix, struct bt_notification *notif)
1033 {
1034 char tmp_prefix[64];
1035
1036 BUF_APPEND(", %stype=%s",
1037 PRFIELD(bt_notification_type_string(notif->type)));
1038
1039 if (!extended) {
1040 return;
1041 }
1042
1043 BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p",
1044 PRFIELD(notif->frozen), PRFIELD(notif->graph));
1045
1046 switch (notif->type) {
1047 case BT_NOTIFICATION_TYPE_EVENT:
1048 {
1049 struct bt_notification_event *notif_event = (void *) notif;
1050
1051 SET_TMP_PREFIX("event-");
1052 format_event(buf_ch, true, tmp_prefix, notif_event->event);
1053
1054 if (!notif_event->cc_prio_map) {
1055 return;
1056 }
1057
1058 BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u",
1059 PRFIELD(notif_event->cc_prio_map),
1060 PRFIELD(notif_event->cc_prio_map->entries->len));
1061 break;
1062 }
1063 case BT_NOTIFICATION_TYPE_INACTIVITY:
1064 {
1065 struct bt_notification_inactivity *notif_inactivity =
1066 (void *) notif;
1067
1068 if (!notif_inactivity->cc_prio_map) {
1069 return;
1070 }
1071
1072 BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u",
1073 PRFIELD(notif_inactivity->cc_prio_map),
1074 PRFIELD(notif_inactivity->cc_prio_map->entries->len));
1075 break;
1076 }
1077 case BT_NOTIFICATION_TYPE_STREAM_BEGIN:
1078 {
1079 struct bt_notification_stream_begin *notif_stream =
1080 (void *) notif;
1081
1082 SET_TMP_PREFIX("stream-");
1083 format_stream(buf_ch, true, tmp_prefix, notif_stream->stream);
1084 break;
1085 }
1086 case BT_NOTIFICATION_TYPE_STREAM_END:
1087 {
1088 struct bt_notification_stream_end *notif_stream =
1089 (void *) notif;
1090
1091 SET_TMP_PREFIX("stream-");
1092 format_stream(buf_ch, true, tmp_prefix, notif_stream->stream);
1093 break;
1094 }
1095 case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
1096 {
1097 struct bt_notification_packet_begin *notif_packet =
1098 (void *) notif;
1099
1100 SET_TMP_PREFIX("packet-");
1101 format_packet(buf_ch, true, tmp_prefix, notif_packet->packet);
1102 break;
1103 }
1104 case BT_NOTIFICATION_TYPE_PACKET_END:
1105 {
1106 struct bt_notification_packet_end *notif_packet =
1107 (void *) notif;
1108
1109 SET_TMP_PREFIX("packet-");
1110 format_packet(buf_ch, true, tmp_prefix, notif_packet->packet);
1111 break;
1112 }
1113 case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS:
1114 case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS:
1115 {
1116 struct bt_notification_discarded_elements *notif_discarded =
1117 (void *) notif;
1118
1119 BUF_APPEND(", %scount=%" PRId64,
1120 PRFIELD(notif_discarded->count));
1121
1122 if (notif_discarded->begin_clock_value) {
1123 SET_TMP_PREFIX("begin-clock-value-");
1124 format_clock_value(buf_ch, true, tmp_prefix,
1125 notif_discarded->begin_clock_value);
1126 }
1127
1128 if (notif_discarded->end_clock_value) {
1129 SET_TMP_PREFIX("end-clock-value-");
1130 format_clock_value(buf_ch, true, tmp_prefix,
1131 notif_discarded->end_clock_value);
1132 }
1133 break;
1134 }
1135 default:
1136 break;
1137 }
1138 }
1139
1140 static inline void format_plugin_so_shared_lib_handle(char **buf_ch,
1141 const char *prefix,
1142 struct bt_plugin_so_shared_lib_handle *handle)
1143 {
1144 BUF_APPEND(", %saddr=%p", PRFIELD(handle));
1145
1146 if (handle->path) {
1147 BUF_APPEND(", %spath=\"%s\"", PRFIELD(handle->path->str));
1148 }
1149 }
1150
1151 static inline void format_component_class(char **buf_ch, bool extended,
1152 const char *prefix, struct bt_component_class *comp_class)
1153 {
1154 char tmp_prefix[64];
1155
1156 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1157 PRFIELD(bt_component_class_type_string(comp_class->type)),
1158 PRFIELD(comp_class->name ? comp_class->name->str : NULL));
1159
1160 if (comp_class->description) {
1161 BUF_APPEND(", %spartial-descr=\"%.32s\"",
1162 PRFIELD(comp_class->description->str));
1163 }
1164
1165 if (!extended) {
1166 return;
1167 }
1168
1169 BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class->frozen));
1170
1171 if (comp_class->so_handle) {
1172 SET_TMP_PREFIX("so-handle-");
1173 format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix,
1174 comp_class->so_handle);
1175 }
1176 }
1177
1178 static inline void format_component(char **buf_ch, bool extended,
1179 const char *prefix, struct bt_component *component)
1180 {
1181 char tmp_prefix[64];
1182
1183 BUF_APPEND(", %sname=\"%s\"", PRFIELD(component->name->str));
1184 SET_TMP_PREFIX("class-");
1185 format_component_class(buf_ch, extended, tmp_prefix, component->class);
1186
1187 if (!extended) {
1188 return;
1189 }
1190
1191 if (component->input_ports) {
1192 BUF_APPEND(", %sinput-port-count=%u",
1193 PRFIELD(component->input_ports->len));
1194 }
1195
1196 if (component->output_ports) {
1197 BUF_APPEND(", %soutput-port-count=%u",
1198 PRFIELD(component->output_ports->len));
1199 }
1200 }
1201
1202 static inline void format_port(char **buf_ch, bool extended,
1203 const char *prefix, struct bt_port *port)
1204 {
1205 char tmp_prefix[64];
1206
1207 BUF_APPEND(", %stype=%s, %sname=\"%s\"",
1208 PRFIELD(bt_port_type_string(port->type)),
1209 PRFIELD(port->name->str));
1210
1211 if (!extended) {
1212 return;
1213 }
1214
1215 if (port->connection) {
1216 SET_TMP_PREFIX("conn-");
1217 format_connection(buf_ch, false, tmp_prefix, port->connection);
1218 }
1219 }
1220
1221 static inline void format_connection(char **buf_ch, bool extended,
1222 const char *prefix, struct bt_connection *connection)
1223 {
1224 char tmp_prefix[64];
1225
1226 if (!extended) {
1227 return;
1228 }
1229
1230 if (connection->upstream_port) {
1231 SET_TMP_PREFIX("upstream-port-");
1232 format_port(buf_ch, false, tmp_prefix,
1233 connection->upstream_port);
1234 }
1235
1236 if (connection->downstream_port) {
1237 SET_TMP_PREFIX("downstream-port-");
1238 format_port(buf_ch, false, tmp_prefix,
1239 connection->downstream_port);
1240 }
1241 }
1242
1243 static inline void format_graph(char **buf_ch, bool extended,
1244 const char *prefix, struct bt_graph *graph)
1245 {
1246 char tmp_prefix[64];
1247
1248 BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph->canceled));
1249
1250 if (!extended) {
1251 return;
1252 }
1253
1254 if (graph->components) {
1255 BUF_APPEND(", %scomp-count=%u",
1256 PRFIELD(graph->components->len));
1257 }
1258
1259 if (graph->connections) {
1260 BUF_APPEND(", %sconn-count=%u",
1261 PRFIELD(graph->connections->len));
1262 }
1263
1264 SET_TMP_PREFIX("en-pool-");
1265 format_object_pool(buf_ch, extended, prefix,
1266 &graph->event_notif_pool);
1267 SET_TMP_PREFIX("pbn-pool-");
1268 format_object_pool(buf_ch, extended, prefix,
1269 &graph->packet_begin_notif_pool);
1270 SET_TMP_PREFIX("pen-pool-");
1271 format_object_pool(buf_ch, extended, prefix,
1272 &graph->packet_end_notif_pool);
1273 }
1274
1275 static inline void format_notification_iterator(char **buf_ch,
1276 bool extended, const char *prefix,
1277 struct bt_notification_iterator *iterator)
1278 {
1279 const char *type;
1280 char tmp_prefix[64];
1281
1282 if (iterator->type == BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION) {
1283 type = "BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION";
1284 } else if (iterator->type == BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT) {
1285 type = "BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT";
1286 } else {
1287 type = "(unknown)";
1288 }
1289
1290 BUF_APPEND(", %stype=%s", PRFIELD(type));
1291
1292 switch (iterator->type) {
1293 case BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION:
1294 {
1295 struct bt_notification_iterator_private_connection *
1296 iter_priv_conn = (void *) iterator;
1297
1298 if (iter_priv_conn->upstream_component) {
1299 SET_TMP_PREFIX("upstream-comp-");
1300 format_component(buf_ch, false, tmp_prefix,
1301 iter_priv_conn->upstream_component);
1302 }
1303
1304 if (iter_priv_conn->upstream_port) {
1305 SET_TMP_PREFIX("upstream-port-");
1306 format_port(buf_ch, false, tmp_prefix,
1307 iter_priv_conn->upstream_port);
1308 }
1309
1310 if (iter_priv_conn->connection) {
1311 SET_TMP_PREFIX("upstream-conn-");
1312 format_connection(buf_ch, false, tmp_prefix,
1313 iter_priv_conn->connection);
1314 }
1315 break;
1316 }
1317 case BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT:
1318 {
1319 struct bt_notification_iterator_output_port *iter_output_port =
1320 (void *) iterator;
1321
1322 SET_TMP_PREFIX("graph-");
1323 format_graph(buf_ch, false, tmp_prefix,
1324 iter_output_port->graph);
1325 SET_TMP_PREFIX("colander-comp-");
1326 format_component(buf_ch, false, tmp_prefix,
1327 iter_output_port->colander);
1328 SET_TMP_PREFIX("output-port-");
1329 format_port(buf_ch, false, tmp_prefix,
1330 iter_output_port->output_port);
1331 break;
1332 }
1333 default:
1334 break;
1335 }
1336 }
1337
1338 static inline void format_plugin(char **buf_ch, bool extended,
1339 const char *prefix, struct bt_plugin *plugin)
1340 {
1341 char tmp_prefix[64];
1342
1343 BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin->type)));
1344
1345 if (plugin->info.path_set) {
1346 BUF_APPEND(", %spath=\"%s\"",
1347 PRFIELD(plugin->info.path->str));
1348 }
1349
1350 if (plugin->info.name_set) {
1351 BUF_APPEND(", %sname=\"%s\"",
1352 PRFIELD(plugin->info.name->str));
1353 }
1354
1355 if (!extended) {
1356 return;
1357 }
1358
1359 if (plugin->info.author_set) {
1360 BUF_APPEND(", %sauthor=\"%s\"",
1361 PRFIELD(plugin->info.author->str));
1362 }
1363
1364 if (plugin->info.license_set) {
1365 BUF_APPEND(", %slicense=\"%s\"",
1366 PRFIELD(plugin->info.license->str));
1367 }
1368
1369 if (plugin->info.version_set) {
1370 BUF_APPEND(", %sversion=%u.%u.%u%s",
1371 PRFIELD(plugin->info.version.major),
1372 plugin->info.version.minor,
1373 plugin->info.version.patch,
1374 plugin->info.version.extra ?
1375 plugin->info.version.extra->str : "");
1376 }
1377
1378 BUF_APPEND(", %sis-frozen=%d, %scomp-class-count=%u",
1379 PRFIELD(plugin->frozen),
1380 PRFIELD(plugin->comp_classes->len));
1381
1382 if (plugin->spec_data) {
1383 struct bt_plugin_so_spec_data *spec_data =
1384 (void *) plugin->spec_data;
1385
1386 if (spec_data->shared_lib_handle) {
1387 SET_TMP_PREFIX("so-handle-");
1388 format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix,
1389 spec_data->shared_lib_handle);
1390 }
1391 }
1392 }
1393
1394 static inline void format_ctf_writer(char **buf_ch, bool extended,
1395 const char *prefix, struct bt_ctf_writer *writer)
1396 {
1397 /* TODO */
1398 }
1399
1400 static inline void format_stream_class_common_common(char **buf_ch,
1401 bool extended, const char *prefix,
1402 struct bt_stream_class_common *stream_class)
1403 {
1404 format_stream_class_common(buf_ch, extended, prefix, stream_class,
1405 (format_func) format_trace_common);
1406 }
1407
1408 static inline void format_event_class_common_common(char **buf_ch,
1409 bool extended, const char *prefix,
1410 struct bt_event_class_common *event_class)
1411 {
1412 format_event_class_common(buf_ch, extended, prefix, event_class,
1413 (format_func) format_stream_class_common,
1414 (format_func) format_trace_common);
1415 }
1416
1417 static inline void format_event_common_common(char **buf_ch,
1418 bool extended, const char *prefix,
1419 struct bt_event_common *event)
1420 {
1421 format_event_common(buf_ch, extended, prefix, event,
1422 (format_func) format_event_class_common,
1423 (format_func) format_stream_class_common,
1424 (format_func) format_trace_common);
1425 }
1426
1427 static inline void format_stream_common_common(char **buf_ch, bool extended,
1428 const char *prefix, struct bt_stream_common *stream)
1429 {
1430 format_stream_common(buf_ch, extended, prefix, stream,
1431 (format_func) format_stream_class_common,
1432 (format_func) format_trace_common);
1433 }
1434
1435 static inline void handle_conversion_specifier_bt(void *priv_data,
1436 char **buf_ch, size_t avail_size,
1437 const char **out_fmt_ch, va_list *args)
1438 {
1439 const char *fmt_ch = *out_fmt_ch;
1440 bool extended = false;
1441 char prefix[64];
1442 char *prefix_ch = prefix;
1443 void *obj;
1444 enum {
1445 CAT_DEFAULT,
1446 CAT_WRITER,
1447 CAT_COMMON,
1448 } cat = CAT_DEFAULT;
1449
1450 /* skip "%!" */
1451 fmt_ch += 2;
1452
1453 if (*fmt_ch == '[') {
1454 /* local prefix */
1455 fmt_ch++;
1456
1457 while (true) {
1458 if (*fmt_ch == ']') {
1459 *prefix_ch = '\0';
1460 fmt_ch++;
1461 break;
1462 }
1463
1464 *prefix_ch = *fmt_ch;
1465 prefix_ch++;
1466 fmt_ch++;
1467 }
1468 }
1469
1470 *prefix_ch = '\0';
1471
1472 if (*fmt_ch == '+') {
1473 extended = true;
1474 fmt_ch++;
1475 }
1476
1477 if (*fmt_ch == 'w') {
1478 cat = CAT_WRITER;
1479 fmt_ch++;
1480 } else if (*fmt_ch == '_') {
1481 cat = CAT_COMMON;
1482 fmt_ch++;
1483 }
1484
1485 obj = va_arg(*args, void *);
1486 BUF_APPEND("%saddr=%p", prefix, obj);
1487
1488 if (!obj) {
1489 goto update_fmt;
1490 }
1491
1492 switch (cat) {
1493 case CAT_DEFAULT:
1494 switch (*fmt_ch) {
1495 case 'r':
1496 format_ref_count(buf_ch, extended, prefix, obj);
1497 break;
1498 case 'F':
1499 format_field_type(buf_ch, extended, prefix, obj);
1500 break;
1501 case 'f':
1502 format_field(buf_ch, extended, prefix, obj);
1503 break;
1504 case 'P':
1505 format_field_path(buf_ch, extended, prefix, obj);
1506 break;
1507 case 'E':
1508 format_event_class(buf_ch, extended, prefix, obj);
1509 break;
1510 case 'e':
1511 format_event(buf_ch, extended, prefix, obj);
1512 break;
1513 case 'S':
1514 format_stream_class(buf_ch, extended, prefix, obj);
1515 break;
1516 case 's':
1517 format_stream(buf_ch, extended, prefix, obj);
1518 break;
1519 case 'a':
1520 format_packet(buf_ch, extended, prefix, obj);
1521 break;
1522 case 't':
1523 format_trace(buf_ch, extended, prefix, obj);
1524 break;
1525 case 'K':
1526 format_clock_class(buf_ch, extended, prefix, obj);
1527 break;
1528 case 'k':
1529 format_clock_value(buf_ch, extended, prefix, obj);
1530 break;
1531 case 'v':
1532 format_value(buf_ch, extended, prefix, obj);
1533 break;
1534 case 'n':
1535 format_notification(buf_ch, extended, prefix, obj);
1536 break;
1537 case 'i':
1538 format_notification_iterator(buf_ch, extended, prefix, obj);
1539 break;
1540 case 'C':
1541 format_component_class(buf_ch, extended, prefix, obj);
1542 break;
1543 case 'c':
1544 format_component(buf_ch, extended, prefix, obj);
1545 break;
1546 case 'p':
1547 format_port(buf_ch, extended, prefix, obj);
1548 break;
1549 case 'x':
1550 format_connection(buf_ch, extended, prefix, obj);
1551 break;
1552 case 'u':
1553 format_plugin(buf_ch, extended, prefix, obj);
1554 break;
1555 case 'g':
1556 format_graph(buf_ch, extended, prefix, obj);
1557 break;
1558 case 'o':
1559 format_object_pool(buf_ch, extended, prefix, obj);
1560 break;
1561 default:
1562 abort();
1563 }
1564 break;
1565 case CAT_WRITER:
1566 switch (*fmt_ch) {
1567 case 'F':
1568 format_writer_field_type(buf_ch, extended, prefix, obj);
1569 break;
1570 case 'f':
1571 format_writer_field(buf_ch, extended, prefix, obj);
1572 break;
1573 case 'E':
1574 format_writer_event_class(buf_ch, extended, prefix, obj);
1575 break;
1576 case 'e':
1577 format_writer_event(buf_ch, extended, prefix, obj);
1578 break;
1579 case 'S':
1580 format_writer_stream_class(buf_ch, extended, prefix, obj);
1581 break;
1582 case 's':
1583 format_writer_stream(buf_ch, extended, prefix, obj);
1584 break;
1585 case 't':
1586 format_writer_trace(buf_ch, extended, prefix, obj);
1587 break;
1588 case 'w':
1589 format_ctf_writer(buf_ch, extended, prefix, obj);
1590 break;
1591 default:
1592 abort();
1593 }
1594 break;
1595 case CAT_COMMON:
1596 switch (*fmt_ch) {
1597 case 'F':
1598 format_field_type_common(buf_ch, extended, prefix, obj);
1599 break;
1600 case 'f':
1601 format_field_common(buf_ch, extended, prefix, obj);
1602 break;
1603 case 'E':
1604 format_event_class_common_common(buf_ch, extended, prefix, obj);
1605 break;
1606 case 'e':
1607 format_event_common_common(buf_ch, extended, prefix, obj);
1608 break;
1609 case 'S':
1610 format_stream_class_common_common(buf_ch, extended, prefix, obj);
1611 break;
1612 case 's':
1613 format_stream_common_common(buf_ch, extended, prefix, obj);
1614 break;
1615 case 't':
1616 format_trace_common(buf_ch, extended, prefix, obj);
1617 break;
1618 default:
1619 abort();
1620 }
1621 break;
1622 }
1623
1624 update_fmt:
1625 fmt_ch++;
1626 *out_fmt_ch = fmt_ch;
1627 }
1628
1629 BT_HIDDEN
1630 void bt_lib_log(const char *func, const char *file, unsigned line,
1631 int lvl, const char *tag, const char *fmt, ...)
1632 {
1633 va_list args;
1634
1635 BT_ASSERT(fmt);
1636 va_start(args, fmt);
1637 bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!',
1638 handle_conversion_specifier_bt, NULL, fmt, &args);
1639 va_end(args);
1640 _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf);
1641 }
This page took 0.082486 seconds and 5 git commands to generate.