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