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