Commit | Line | Data |
---|---|---|
476ef981 PP |
1 | /* |
2 | * Copyright 2018 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | * of this software and associated documentation files (the "Software"), to deal | |
6 | * in the Software without restriction, including without limitation the rights | |
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | * copies of the Software, and to permit persons to whom the Software is | |
9 | * furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
20 | * SOFTWARE. | |
21 | */ | |
22 | ||
23 | #include <stdarg.h> | |
24 | #include <stdio.h> | |
25 | #include <stdlib.h> | |
26 | #include <string.h> | |
27 | #include <inttypes.h> | |
28 | #include <stdint.h> | |
29 | #include <assert.h> | |
30 | #include <wchar.h> | |
31 | #include <glib.h> | |
32 | #include <babeltrace/common-internal.h> | |
33 | #include <babeltrace/lib-logging-internal.h> | |
34 | #include <babeltrace/object-internal.h> | |
35 | #include <babeltrace/ref-internal.h> | |
36 | #include <babeltrace/values-internal.h> | |
37 | #include <babeltrace/ctf-ir/field-types-internal.h> | |
38 | #include <babeltrace/ctf-ir/fields-internal.h> | |
39 | #include <babeltrace/ctf-ir/event-class-internal.h> | |
40 | #include <babeltrace/ctf-ir/event-internal.h> | |
41 | #include <babeltrace/ctf-ir/packet-internal.h> | |
42 | #include <babeltrace/ctf-ir/stream-class-internal.h> | |
43 | #include <babeltrace/ctf-ir/stream-internal.h> | |
44 | #include <babeltrace/ctf-ir/trace-internal.h> | |
45 | #include <babeltrace/ctf-ir/clock-class-internal.h> | |
46 | #include <babeltrace/ctf-ir/clock-value-internal.h> | |
47 | #include <babeltrace/ctf-ir/field-path-internal.h> | |
48 | #include <babeltrace/graph/clock-class-priority-map-internal.h> | |
49 | #include <babeltrace/graph/component-class-internal.h> | |
50 | #include <babeltrace/graph/component-class-sink-colander-internal.h> | |
51 | #include <babeltrace/graph/component-filter-internal.h> | |
52 | #include <babeltrace/graph/component-internal.h> | |
53 | #include <babeltrace/graph/component-sink-internal.h> | |
54 | #include <babeltrace/graph/component-source-internal.h> | |
55 | #include <babeltrace/graph/connection-internal.h> | |
56 | #include <babeltrace/graph/graph-internal.h> | |
57 | #include <babeltrace/graph/notification-discarded-elements-internal.h> | |
58 | #include <babeltrace/graph/notification-event-internal.h> | |
59 | #include <babeltrace/graph/notification-heap-internal.h> | |
60 | #include <babeltrace/graph/notification-inactivity-internal.h> | |
61 | #include <babeltrace/graph/notification-internal.h> | |
62 | #include <babeltrace/graph/notification-iterator-internal.h> | |
63 | #include <babeltrace/graph/notification-packet-internal.h> | |
64 | #include <babeltrace/graph/notification-stream-internal.h> | |
65 | #include <babeltrace/graph/port-internal.h> | |
66 | #include <babeltrace/plugin/plugin-internal.h> | |
67 | #include <babeltrace/plugin/plugin-so-internal.h> | |
68 | #include <babeltrace/ctf-writer/writer-internal.h> | |
69 | #include <babeltrace/ctf-writer/clock-internal.h> | |
70 | ||
71 | #define LIB_LOGGING_BUF_SIZE (4096 * 4) | |
72 | ||
73 | static char __thread lib_logging_buf[LIB_LOGGING_BUF_SIZE]; | |
74 | ||
75 | #define BUF_APPEND(_fmt, ...) \ | |
76 | do { \ | |
77 | int _count; \ | |
78 | size_t _size = LIB_LOGGING_BUF_SIZE - \ | |
79 | (size_t) (*buf_ch - lib_logging_buf); \ | |
80 | _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \ | |
81 | assert(_count >= 0); \ | |
82 | *buf_ch += MIN(_count, _size); \ | |
83 | if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \ | |
84 | return; \ | |
85 | } \ | |
86 | } while (0) | |
87 | ||
88 | #define BUF_APPEND_UUID(_uuid) \ | |
89 | BUF_APPEND(", %suuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"", \ | |
90 | prefix, \ | |
91 | (unsigned int) (_uuid)[0], \ | |
92 | (unsigned int) (_uuid)[1], \ | |
93 | (unsigned int) (_uuid)[2], \ | |
94 | (unsigned int) (_uuid)[3], \ | |
95 | (unsigned int) (_uuid)[4], \ | |
96 | (unsigned int) (_uuid)[5], \ | |
97 | (unsigned int) (_uuid)[6], \ | |
98 | (unsigned int) (_uuid)[7], \ | |
99 | (unsigned int) (_uuid)[8], \ | |
100 | (unsigned int) (_uuid)[9], \ | |
101 | (unsigned int) (_uuid)[10], \ | |
102 | (unsigned int) (_uuid)[11], \ | |
103 | (unsigned int) (_uuid)[12], \ | |
104 | (unsigned int) (_uuid)[13], \ | |
105 | (unsigned int) (_uuid)[14], \ | |
106 | (unsigned int) (_uuid)[15]) | |
107 | ||
108 | #define PRFIELD(_expr) prefix, (_expr) | |
109 | ||
110 | #define SET_TMP_PREFIX(_prefix2) \ | |
111 | do { \ | |
112 | strcpy(tmp_prefix, prefix); \ | |
113 | strcat(tmp_prefix, (_prefix2)); \ | |
114 | } while (0) | |
115 | ||
116 | static inline void format_component(char **buf_ch, bool extended, | |
117 | const char *prefix, struct bt_component *component); | |
118 | ||
119 | static inline void format_port(char **buf_ch, bool extended, | |
120 | const char *prefix, struct bt_port *port); | |
121 | ||
122 | static inline void format_connection(char **buf_ch, bool extended, | |
123 | const char *prefix, struct bt_connection *connection); | |
124 | ||
125 | static inline void format_ref_count(char **buf_ch, bool extended, | |
126 | const char *prefix, struct bt_object *obj) | |
127 | { | |
128 | BUF_APPEND(", %sref-count=%lu", prefix, obj->ref_count.count); | |
129 | } | |
130 | ||
131 | static inline void format_field_type(char **buf_ch, bool extended, | |
132 | const char *prefix, struct bt_field_type *field_type) | |
133 | { | |
134 | BUF_APPEND(", %stype-id=%s, %salignment=%u", | |
135 | PRFIELD(bt_field_type_id_string(field_type->id)), | |
136 | PRFIELD(field_type->alignment)); | |
137 | ||
138 | if (extended) { | |
139 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_type->frozen)); | |
140 | } else { | |
141 | return; | |
142 | } | |
143 | ||
144 | if (field_type->id == BT_FIELD_TYPE_ID_UNKNOWN) { | |
145 | return; | |
146 | } | |
147 | ||
148 | switch (field_type->id) { | |
149 | case BT_FIELD_TYPE_ID_INTEGER: | |
150 | { | |
151 | struct bt_field_type_integer *integer = (void *) field_type; | |
152 | ||
153 | BUF_APPEND(", %ssize=%u, %sis-signed=%d, %sbyte-order=%s, " | |
154 | "%sbase=%d, %sencoding=%s, " | |
155 | "%smapped-clock-class-addr=%p", | |
156 | PRFIELD(integer->size), PRFIELD(integer->is_signed), | |
157 | PRFIELD(bt_byte_order_string(integer->user_byte_order)), | |
158 | PRFIELD(integer->base), | |
159 | PRFIELD(bt_string_encoding_string(integer->encoding)), | |
160 | PRFIELD(integer->mapped_clock)); | |
161 | ||
162 | if (integer->mapped_clock) { | |
163 | BUF_APPEND(", %smapped-clock-class-name=\"%s\"", | |
164 | PRFIELD(bt_clock_class_get_name(integer->mapped_clock))); | |
165 | } | |
166 | break; | |
167 | } | |
168 | case BT_FIELD_TYPE_ID_FLOAT: | |
169 | { | |
170 | struct bt_field_type_floating_point *flt = (void *) field_type; | |
171 | ||
172 | BUF_APPEND(", %sexp-dig=%u, %smant-dig=%u, %sbyte-order=%s", | |
173 | PRFIELD(flt->exp_dig), PRFIELD(flt->mant_dig), | |
174 | PRFIELD(bt_byte_order_string(flt->user_byte_order))); | |
175 | break; | |
176 | } | |
177 | case BT_FIELD_TYPE_ID_ENUM: | |
178 | { | |
179 | struct bt_field_type_enumeration *enm = (void *) field_type; | |
180 | ||
181 | BUF_APPEND(", %smapping-count=%u", | |
182 | PRFIELD(enm->entries->len)); | |
183 | break; | |
184 | } | |
185 | case BT_FIELD_TYPE_ID_STRING: | |
186 | { | |
187 | struct bt_field_type_string *str = (void *) field_type; | |
188 | ||
189 | BUF_APPEND(", %sencoding=%s", | |
190 | PRFIELD(bt_string_encoding_string(str->encoding))); | |
191 | break; | |
192 | } | |
193 | case BT_FIELD_TYPE_ID_STRUCT: | |
194 | { | |
195 | struct bt_field_type_structure *structure = (void *) field_type; | |
196 | ||
197 | BUF_APPEND(", %sfield-count=%u", | |
198 | PRFIELD(structure->fields->len)); | |
199 | break; | |
200 | } | |
201 | case BT_FIELD_TYPE_ID_SEQUENCE: | |
202 | { | |
203 | struct bt_field_type_sequence *seq = (void *) field_type; | |
204 | ||
205 | BUF_APPEND(", %slength-ft-addr=\"%s\", %selem-ft-addr=%p", | |
206 | PRFIELD(seq->length_field_name->str), | |
207 | PRFIELD(seq->element_type)); | |
208 | break; | |
209 | } | |
210 | case BT_FIELD_TYPE_ID_VARIANT: | |
211 | { | |
212 | struct bt_field_type_variant *variant = (void *) field_type; | |
213 | ||
214 | BUF_APPEND(", %stag-name=\"%s\", %stag-ft-addr=%p, " | |
215 | "%sfield-count=%u", | |
216 | PRFIELD(variant->tag_name->str), | |
217 | PRFIELD(variant->tag), PRFIELD(variant->fields->len)); | |
218 | break; | |
219 | } | |
220 | default: | |
221 | break; | |
222 | } | |
223 | } | |
224 | ||
225 | static inline void format_field_integer_extended(char **buf_ch, | |
226 | const char *prefix, struct bt_field *field) | |
227 | { | |
228 | struct bt_field_integer *integer = (void *) field; | |
229 | struct bt_field_type_integer *field_type = (void *) field->type; | |
230 | const char *fmt = NULL; | |
231 | ||
232 | if (field_type->base == 8) { | |
233 | fmt = ", %svalue=%" PRIo64; | |
234 | } else if (field_type->base == 16) { | |
235 | fmt = ", %svalue=%" PRIx64; | |
236 | } | |
237 | ||
238 | if (field_type->is_signed) { | |
239 | if (!fmt) { | |
240 | fmt = ", %svalue=%" PRId64; | |
241 | } | |
242 | ||
243 | BUF_APPEND(fmt, PRFIELD(integer->payload.signd)); | |
244 | } else { | |
245 | if (!fmt) { | |
246 | fmt = ", %svalue=%" PRIu64; | |
247 | } | |
248 | ||
249 | BUF_APPEND(fmt, PRFIELD(integer->payload.unsignd)); | |
250 | } | |
251 | } | |
252 | ||
253 | static inline void format_field(char **buf_ch, bool extended, | |
254 | const char *prefix, struct bt_field *field) | |
255 | { | |
256 | BUF_APPEND(", %sis-set=%d", PRFIELD(field->payload_set)); | |
257 | ||
258 | if (extended) { | |
259 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(field->frozen)); | |
260 | } | |
261 | ||
262 | BUF_APPEND(", %stype-addr=%p, %stype-id=%s", | |
263 | PRFIELD(field->type), | |
264 | PRFIELD(bt_field_type_id_string(field->type->id))); | |
265 | ||
266 | if (!extended || field->type->id == BT_FIELD_TYPE_ID_UNKNOWN || | |
267 | !field->payload_set) { | |
268 | return; | |
269 | } | |
270 | ||
271 | switch (field->type->id) { | |
272 | case BT_FIELD_TYPE_ID_INTEGER: | |
273 | { | |
274 | format_field_integer_extended(buf_ch, prefix, field); | |
275 | break; | |
276 | } | |
277 | case BT_FIELD_TYPE_ID_FLOAT: | |
278 | { | |
279 | struct bt_field_floating_point *flt = (void *) field; | |
280 | ||
281 | BUF_APPEND(", %svalue=%f", PRFIELD(flt->payload)); | |
282 | break; | |
283 | } | |
284 | case BT_FIELD_TYPE_ID_ENUM: | |
285 | { | |
286 | struct bt_field_enumeration *enm = (void *) field; | |
287 | ||
288 | if (enm->payload) { | |
289 | format_field_integer_extended(buf_ch, prefix, | |
290 | enm->payload); | |
291 | } | |
292 | break; | |
293 | } | |
294 | case BT_FIELD_TYPE_ID_STRING: | |
295 | { | |
296 | struct bt_field_string *str = (void *) field; | |
297 | ||
298 | assert(str->payload); | |
299 | BUF_APPEND(", %spartial-value=\"%.32s\"", | |
300 | PRFIELD(str->payload->str)); | |
301 | break; | |
302 | } | |
303 | case BT_FIELD_TYPE_ID_SEQUENCE: | |
304 | { | |
305 | struct bt_field_sequence *seq = (void *) field; | |
306 | ||
307 | BUF_APPEND(", %slength-field-addr=%p", PRFIELD(seq->length)); | |
308 | break; | |
309 | } | |
310 | case BT_FIELD_TYPE_ID_VARIANT: | |
311 | { | |
312 | struct bt_field_variant *variant = (void *) field; | |
313 | ||
314 | BUF_APPEND(", %stag-field-addr=%p, %svalue-field-addr=%p", | |
315 | PRFIELD(variant->tag), PRFIELD(variant->payload)); | |
316 | break; | |
317 | } | |
318 | default: | |
319 | break; | |
320 | } | |
321 | } | |
322 | ||
323 | static inline void format_field_path(char **buf_ch, bool extended, | |
324 | const char *prefix, struct bt_field_path *field_path) | |
325 | { | |
326 | uint64_t i; | |
327 | ||
328 | assert(field_path->indexes); | |
329 | BUF_APPEND(", %sindex-count=%u", PRFIELD(field_path->indexes->len)); | |
330 | ||
331 | if (!extended) { | |
332 | return; | |
333 | } | |
334 | ||
335 | BUF_APPEND(", %spath=[%s", PRFIELD(bt_scope_string(field_path->root))); | |
336 | ||
337 | for (i = 0; i < field_path->indexes->len; i++) { | |
338 | int index = g_array_index(field_path->indexes, int, i); | |
339 | ||
340 | BUF_APPEND(", %d", index); | |
341 | } | |
342 | ||
343 | BUF_APPEND("%s", "]"); | |
344 | } | |
345 | ||
346 | static inline void format_trace(char **buf_ch, bool extended, | |
347 | const char *prefix, struct bt_trace *trace) | |
348 | { | |
349 | if (trace->name) { | |
350 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name->str)); | |
351 | } | |
352 | ||
353 | if (!extended) { | |
354 | return; | |
355 | } | |
356 | ||
357 | BUF_APPEND(", %sis-frozen=%d, %sis-static=%d", | |
358 | PRFIELD(trace->frozen), PRFIELD(trace->is_static)); | |
359 | ||
360 | if (trace->uuid_set) { | |
361 | BUF_APPEND_UUID(trace->uuid); | |
362 | } | |
363 | ||
364 | BUF_APPEND(", %sclock-class-count=%u, %sstream-class-count=%u, " | |
365 | "%sstream-count=%u, %sis-ctf-writer-trace=%d, " | |
366 | "%spacket-header-ft-addr=%p", | |
367 | PRFIELD(trace->clocks->len), | |
368 | PRFIELD(trace->stream_classes->len), | |
369 | PRFIELD(trace->streams->len), | |
370 | PRFIELD(trace->is_created_by_writer), | |
371 | PRFIELD(trace->packet_header_type)); | |
372 | } | |
373 | ||
374 | static inline void format_stream_class(char **buf_ch, bool extended, | |
375 | const char *prefix, struct bt_stream_class *stream_class) | |
376 | { | |
377 | struct bt_trace *trace; | |
378 | char tmp_prefix[64]; | |
379 | ||
380 | if (stream_class->id_set) { | |
381 | BUF_APPEND(", %sid=%" PRId64, PRFIELD(stream_class->id)); | |
382 | } | |
383 | ||
384 | if (stream_class->name) { | |
385 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream_class->name->str)); | |
386 | } | |
387 | ||
388 | if (!extended) { | |
389 | return; | |
390 | } | |
391 | ||
392 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class->frozen)); | |
393 | ||
394 | if (stream_class->clock) { | |
395 | BUF_APPEND(", %sctf-writer-clock-addr=%p, " | |
396 | "%sctf-writer-clock-name=\"%s\"", | |
397 | PRFIELD(stream_class->clock), | |
398 | PRFIELD(bt_clock_class_get_name(stream_class->clock->clock_class))); | |
399 | } | |
400 | ||
401 | BUF_APPEND(", %sevent-class-count=%u, %spacket-context-ft-addr=%p, " | |
402 | "%sevent-header-ft-addr=%p, %sevent-context-ft-addr=%p", | |
403 | PRFIELD(stream_class->event_classes->len), | |
404 | PRFIELD(stream_class->packet_context_type), | |
405 | PRFIELD(stream_class->event_header_type), | |
406 | PRFIELD(stream_class->event_context_type)); | |
407 | trace = bt_stream_class_borrow_trace(stream_class); | |
408 | if (!trace) { | |
409 | return; | |
410 | } | |
411 | ||
412 | BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); | |
413 | SET_TMP_PREFIX("trace-"); | |
414 | format_trace(buf_ch, false, tmp_prefix, trace); | |
415 | } | |
416 | ||
417 | static inline void format_event_class(char **buf_ch, bool extended, | |
418 | const char *prefix, struct bt_event_class *event_class) | |
419 | { | |
420 | struct bt_stream_class *stream_class; | |
421 | struct bt_trace *trace; | |
422 | char tmp_prefix[64]; | |
423 | ||
424 | BUF_APPEND(", %sid=%" PRId64, PRFIELD(event_class->id)); | |
425 | ||
426 | if (event_class->name) { | |
427 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(event_class->name->str)); | |
428 | } | |
429 | ||
430 | if (!extended) { | |
431 | return; | |
432 | } | |
433 | ||
434 | BUF_APPEND(", %sis-frozen=%d, %slog-level=%s", | |
435 | PRFIELD(event_class->frozen), | |
436 | PRFIELD(bt_event_class_log_level_string(event_class->log_level))); | |
437 | ||
438 | if (event_class->emf_uri) { | |
439 | BUF_APPEND(", %semf-uri=\"%s\"", | |
440 | PRFIELD(event_class->emf_uri->str)); | |
441 | } | |
442 | ||
443 | BUF_APPEND(", %scontext-ft-addr=%p, %spayload-ft-addr=%p", | |
444 | PRFIELD(event_class->context), | |
445 | PRFIELD(event_class->fields)); | |
446 | ||
447 | stream_class = bt_event_class_borrow_stream_class(event_class); | |
448 | if (!stream_class) { | |
449 | return; | |
450 | } | |
451 | ||
452 | BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); | |
453 | SET_TMP_PREFIX("stream-class-"); | |
454 | format_stream_class(buf_ch, false, tmp_prefix, stream_class); | |
455 | trace = bt_stream_class_borrow_trace(stream_class); | |
456 | if (!trace) { | |
457 | return; | |
458 | } | |
459 | ||
460 | BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); | |
461 | SET_TMP_PREFIX("trace-"); | |
462 | format_trace(buf_ch, false, tmp_prefix, trace); | |
463 | } | |
464 | ||
465 | static inline void format_stream(char **buf_ch, bool extended, | |
466 | const char *prefix, struct bt_stream *stream) | |
467 | { | |
468 | struct bt_stream_class *stream_class; | |
469 | struct bt_trace *trace; | |
470 | char tmp_prefix[64]; | |
471 | ||
472 | BUF_APPEND(", %sid=%" PRId64, PRFIELD(stream->id)); | |
473 | ||
474 | if (stream->name) { | |
475 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream->name->str)); | |
476 | } | |
477 | ||
478 | BUF_APPEND(", %sis-ctf-writer-stream=%d", | |
479 | PRFIELD(stream->pos.fd != -1)); | |
480 | ||
481 | if (!extended) { | |
482 | return; | |
483 | } | |
484 | ||
485 | if (stream->pos.fd != -1) { | |
486 | BUF_APPEND(", %sheader-field-addr=%p, %scontext-field-addr=%p" | |
487 | ", %sfd=%d, %smmap-offset=%zu, " | |
488 | "%smmap-base-offset=%zu, %spacket-size=%" PRIu64 ", " | |
489 | "%soffset=%" PRId64 ", %sevent-count=%u, " | |
490 | "%sflushed-packet-count=%u, " | |
491 | "%sdiscarded-event-count=%" PRIu64 ", " | |
492 | "%ssize=%" PRIu64 ", %slast-ts-end=%" PRIu64, | |
493 | PRFIELD(stream->packet_header), | |
494 | PRFIELD(stream->packet_context), | |
495 | PRFIELD(stream->pos.fd), | |
496 | PRFIELD((size_t) stream->pos.mmap_offset), | |
497 | PRFIELD((size_t) stream->pos.mmap_base_offset), | |
498 | PRFIELD(stream->pos.packet_size), | |
499 | PRFIELD(stream->pos.offset), | |
500 | PRFIELD(stream->events->len), | |
501 | PRFIELD(stream->flushed_packet_count), | |
502 | PRFIELD(stream->discarded_events), | |
503 | PRFIELD(stream->size), PRFIELD(stream->last_ts_end)); | |
504 | } | |
505 | ||
506 | stream_class = bt_stream_borrow_stream_class(stream); | |
507 | if (!stream_class) { | |
508 | return; | |
509 | } | |
510 | ||
511 | BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); | |
512 | SET_TMP_PREFIX("stream-class-"); | |
513 | format_stream_class(buf_ch, false, tmp_prefix, stream_class); | |
514 | trace = bt_stream_class_borrow_trace(stream_class); | |
515 | if (!trace) { | |
516 | return; | |
517 | } | |
518 | ||
519 | trace = (struct bt_trace *) bt_object_borrow_parent(stream); | |
520 | if (!trace) { | |
521 | return; | |
522 | } | |
523 | ||
524 | BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); | |
525 | SET_TMP_PREFIX("trace-"); | |
526 | format_trace(buf_ch, false, tmp_prefix, trace); | |
527 | } | |
528 | ||
529 | static inline void format_packet(char **buf_ch, bool extended, | |
530 | const char *prefix, struct bt_packet *packet) | |
531 | { | |
532 | struct bt_stream *stream; | |
533 | struct bt_trace *trace; | |
534 | char tmp_prefix[64]; | |
535 | ||
536 | if (!extended) { | |
537 | return; | |
538 | } | |
539 | ||
540 | BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, " | |
541 | "%scontext-field-addr=%p", | |
542 | PRFIELD(packet->frozen), | |
543 | PRFIELD(packet->header), | |
544 | PRFIELD(packet->context)); | |
545 | stream = bt_packet_borrow_stream(packet); | |
546 | if (!stream) { | |
547 | return; | |
548 | } | |
549 | ||
550 | BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream)); | |
551 | SET_TMP_PREFIX("stream-"); | |
552 | format_stream(buf_ch, false, tmp_prefix, stream); | |
553 | trace = (struct bt_trace *) bt_object_borrow_parent(stream); | |
554 | if (!trace) { | |
555 | return; | |
556 | } | |
557 | ||
558 | BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); | |
559 | SET_TMP_PREFIX("trace-"); | |
560 | format_trace(buf_ch, false, tmp_prefix, trace); | |
561 | } | |
562 | ||
563 | static inline void format_event(char **buf_ch, bool extended, | |
564 | const char *prefix, struct bt_event *event) | |
565 | { | |
566 | struct bt_trace *trace; | |
567 | struct bt_stream_class *stream_class; | |
568 | struct bt_packet *packet; | |
569 | struct bt_stream *stream; | |
570 | char tmp_prefix[64]; | |
571 | ||
572 | if (!extended) { | |
573 | return; | |
574 | } | |
575 | ||
576 | BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, " | |
577 | "%sstream-context-field-addr=%p, " | |
578 | "%scontext-field-addr=%p, %spayload-field-addr=%p, " | |
579 | "%sclock-value-count=%u", | |
580 | PRFIELD(event->frozen), | |
581 | PRFIELD(event->event_header), | |
582 | PRFIELD(event->stream_event_context), | |
583 | PRFIELD(event->context_payload), | |
584 | PRFIELD(event->fields_payload), | |
585 | PRFIELD(g_hash_table_size(event->clock_values))); | |
586 | BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event->event_class)); | |
587 | SET_TMP_PREFIX("event-class-"); | |
588 | format_event_class(buf_ch, false, tmp_prefix, event->event_class); | |
589 | stream_class = bt_event_class_borrow_stream_class(event->event_class); | |
590 | if (stream_class) { | |
591 | BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); | |
592 | SET_TMP_PREFIX("stream-class-"); | |
593 | format_stream_class(buf_ch, false, tmp_prefix, stream_class); | |
594 | ||
595 | trace = bt_stream_class_borrow_trace(stream_class); | |
596 | if (trace) { | |
597 | BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); | |
598 | SET_TMP_PREFIX("trace-"); | |
599 | format_trace(buf_ch, false, tmp_prefix, trace); | |
600 | } | |
601 | } | |
602 | ||
603 | packet = bt_event_borrow_packet(event); | |
604 | if (!packet) { | |
605 | return; | |
606 | } | |
607 | ||
608 | BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet)); | |
609 | SET_TMP_PREFIX("packet-"); | |
610 | format_packet(buf_ch, false, tmp_prefix, packet); | |
611 | stream = bt_packet_borrow_stream(packet); | |
612 | if (!stream) { | |
613 | return; | |
614 | } | |
615 | ||
616 | BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream)); | |
617 | SET_TMP_PREFIX("stream-"); | |
618 | format_stream(buf_ch, false, tmp_prefix, stream); | |
619 | } | |
620 | ||
621 | static inline void format_clock_class(char **buf_ch, bool extended, | |
622 | const char *prefix, struct bt_clock_class *clock_class) | |
623 | { | |
624 | BUF_APPEND(", %sname=\"%s\", %sfreq=%" PRIu64, | |
625 | PRFIELD(clock_class->name->str), | |
626 | PRFIELD(clock_class->frequency)); | |
627 | ||
628 | if (!extended) { | |
629 | return; | |
630 | } | |
631 | ||
632 | if (clock_class->description) { | |
633 | BUF_APPEND(", %spartial-description=\"%.32s\"", | |
634 | PRFIELD(clock_class->description->str)); | |
635 | } | |
636 | ||
637 | BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64 ", " | |
638 | "%soffset-s=%" PRId64 ", " | |
639 | "%soffset-cycles=%" PRId64 ", %sis-absolute=%d", | |
640 | PRFIELD(clock_class->frozen), PRFIELD(clock_class->precision), | |
641 | PRFIELD(clock_class->offset_s), PRFIELD(clock_class->offset), | |
642 | PRFIELD(clock_class->absolute)); | |
643 | ||
644 | if (clock_class->uuid_set) { | |
645 | BUF_APPEND_UUID(clock_class->uuid); | |
646 | } | |
647 | } | |
648 | ||
649 | static inline void format_clock_value(char **buf_ch, bool extended, | |
650 | const char *prefix, struct bt_clock_value *clock_value) | |
651 | { | |
652 | char tmp_prefix[64]; | |
653 | BUF_APPEND(", %svalue=%" PRIu64 ", %sns-from-epoch=%" PRId64, | |
654 | PRFIELD(clock_value->value), | |
655 | PRFIELD(clock_value->ns_from_epoch)); | |
656 | ||
657 | if (!extended) { | |
658 | return; | |
659 | } | |
660 | ||
661 | BUF_APPEND(", %sclock-class-addr=%p", | |
662 | PRFIELD(clock_value->clock_class)); | |
663 | SET_TMP_PREFIX("clock-class-"); | |
664 | format_clock_class(buf_ch, false, tmp_prefix, clock_value->clock_class); | |
665 | } | |
666 | ||
667 | static inline void format_value(char **buf_ch, bool extended, | |
668 | const char *prefix, struct bt_value *value) | |
669 | { | |
670 | BUF_APPEND(", %stype=%s", | |
671 | PRFIELD(bt_value_type_string(bt_value_get_type(value)))); | |
672 | ||
673 | if (!extended) { | |
674 | return; | |
675 | } | |
676 | ||
677 | switch (bt_value_get_type(value)) { | |
678 | case BT_VALUE_TYPE_BOOL: | |
679 | { | |
680 | bt_bool val; | |
681 | int status = bt_value_bool_get(value, &val); | |
682 | ||
683 | assert(status == 0); | |
684 | BUF_APPEND(", %svalue=%d", PRFIELD(val)); | |
685 | break; | |
686 | } | |
687 | case BT_VALUE_TYPE_INTEGER: | |
688 | { | |
689 | int64_t val; | |
690 | int status = bt_value_integer_get(value, &val); | |
691 | ||
692 | assert(status == 0); | |
693 | BUF_APPEND(", %svalue=%" PRId64, PRFIELD(val)); | |
694 | break; | |
695 | } | |
696 | case BT_VALUE_TYPE_FLOAT: | |
697 | { | |
698 | double val; | |
699 | int status = bt_value_float_get(value, &val); | |
700 | ||
701 | assert(status == 0); | |
702 | BUF_APPEND(", %svalue=%f", PRFIELD(val)); | |
703 | break; | |
704 | } | |
705 | case BT_VALUE_TYPE_STRING: | |
706 | { | |
707 | const char *val; | |
708 | int status = bt_value_string_get(value, &val); | |
709 | ||
710 | assert(status == 0); | |
711 | BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val)); | |
712 | break; | |
713 | } | |
714 | case BT_VALUE_TYPE_ARRAY: | |
715 | { | |
716 | int64_t count = bt_value_array_size(value); | |
717 | ||
718 | assert(count >= 0); | |
719 | BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); | |
720 | break; | |
721 | } | |
722 | case BT_VALUE_TYPE_MAP: | |
723 | { | |
724 | int64_t count = bt_value_map_size(value); | |
725 | ||
726 | assert(count >= 0); | |
727 | BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); | |
728 | break; | |
729 | } | |
730 | default: | |
731 | break; | |
732 | } | |
733 | } | |
734 | ||
735 | static inline void format_notification(char **buf_ch, bool extended, | |
736 | const char *prefix, struct bt_notification *notif) | |
737 | { | |
738 | char tmp_prefix[64]; | |
739 | ||
740 | BUF_APPEND(", %stype=%s", | |
741 | PRFIELD(bt_notification_type_string(notif->type))); | |
742 | ||
743 | if (!extended) { | |
744 | return; | |
745 | } | |
746 | ||
747 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(notif->frozen)); | |
748 | ||
749 | switch (notif->type) { | |
750 | case BT_NOTIFICATION_TYPE_EVENT: | |
751 | { | |
752 | struct bt_notification_event *notif_event = (void *) notif; | |
753 | ||
754 | SET_TMP_PREFIX("event-"); | |
755 | format_event(buf_ch, true, tmp_prefix, notif_event->event); | |
756 | ||
757 | if (!notif_event->cc_prio_map) { | |
758 | return; | |
759 | } | |
760 | ||
761 | BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u", | |
762 | PRFIELD(notif_event->cc_prio_map), | |
763 | PRFIELD(notif_event->cc_prio_map->entries->len)); | |
764 | break; | |
765 | } | |
766 | case BT_NOTIFICATION_TYPE_INACTIVITY: | |
767 | { | |
768 | struct bt_notification_inactivity *notif_inactivity = | |
769 | (void *) notif; | |
770 | ||
771 | if (!notif_inactivity->cc_prio_map) { | |
772 | return; | |
773 | } | |
774 | ||
775 | BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u", | |
776 | PRFIELD(notif_inactivity->cc_prio_map), | |
777 | PRFIELD(notif_inactivity->cc_prio_map->entries->len)); | |
778 | break; | |
779 | } | |
780 | case BT_NOTIFICATION_TYPE_STREAM_BEGIN: | |
781 | { | |
782 | struct bt_notification_stream_begin *notif_stream = | |
783 | (void *) notif; | |
784 | ||
785 | SET_TMP_PREFIX("stream-"); | |
786 | format_stream(buf_ch, true, tmp_prefix, notif_stream->stream); | |
787 | break; | |
788 | } | |
789 | case BT_NOTIFICATION_TYPE_STREAM_END: | |
790 | { | |
791 | struct bt_notification_stream_end *notif_stream = | |
792 | (void *) notif; | |
793 | ||
794 | SET_TMP_PREFIX("stream-"); | |
795 | format_stream(buf_ch, true, tmp_prefix, notif_stream->stream); | |
796 | break; | |
797 | } | |
798 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: | |
799 | { | |
800 | struct bt_notification_packet_begin *notif_packet = | |
801 | (void *) notif; | |
802 | ||
803 | SET_TMP_PREFIX("packet-"); | |
804 | format_packet(buf_ch, true, tmp_prefix, notif_packet->packet); | |
805 | break; | |
806 | } | |
807 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
808 | { | |
809 | struct bt_notification_packet_end *notif_packet = | |
810 | (void *) notif; | |
811 | ||
812 | SET_TMP_PREFIX("packet-"); | |
813 | format_packet(buf_ch, true, tmp_prefix, notif_packet->packet); | |
814 | break; | |
815 | } | |
816 | case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS: | |
817 | case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS: | |
818 | { | |
819 | struct bt_notification_discarded_elements *notif_discarded = | |
820 | (void *) notif; | |
821 | ||
822 | BUF_APPEND(", %scount=%" PRId64, | |
823 | PRFIELD(notif_discarded->count)); | |
824 | ||
825 | if (notif_discarded->begin_clock_value) { | |
826 | SET_TMP_PREFIX("begin-clock-value-"); | |
827 | format_clock_value(buf_ch, true, tmp_prefix, | |
828 | notif_discarded->begin_clock_value); | |
829 | } | |
830 | ||
831 | if (notif_discarded->end_clock_value) { | |
832 | SET_TMP_PREFIX("end-clock-value-"); | |
833 | format_clock_value(buf_ch, true, tmp_prefix, | |
834 | notif_discarded->end_clock_value); | |
835 | } | |
836 | break; | |
837 | } | |
838 | default: | |
839 | break; | |
840 | } | |
841 | } | |
842 | ||
843 | static inline void format_plugin_so_shared_lib_handle(char **buf_ch, | |
844 | const char *prefix, | |
845 | struct bt_plugin_so_shared_lib_handle *handle) | |
846 | { | |
847 | BUF_APPEND(", %saddr=%p", PRFIELD(handle)); | |
848 | ||
849 | if (handle->path) { | |
850 | BUF_APPEND(", %spath=\"%s\"", PRFIELD(handle->path->str)); | |
851 | } | |
852 | } | |
853 | ||
854 | static inline void format_component_class(char **buf_ch, bool extended, | |
855 | const char *prefix, struct bt_component_class *comp_class) | |
856 | { | |
857 | char tmp_prefix[64]; | |
858 | ||
859 | BUF_APPEND(", %stype=%s, %sname=\"%s\"", | |
860 | PRFIELD(bt_component_class_type_string(comp_class->type)), | |
861 | PRFIELD(comp_class->name->str)); | |
862 | ||
863 | if (comp_class->description) { | |
864 | BUF_APPEND(", %spartial-descr=\"%.32s\"", | |
865 | PRFIELD(comp_class->description->str)); | |
866 | } | |
867 | ||
868 | if (!extended) { | |
869 | return; | |
870 | } | |
871 | ||
872 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class->frozen)); | |
873 | ||
874 | if (comp_class->so_handle) { | |
875 | SET_TMP_PREFIX("so-handle-"); | |
876 | format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix, | |
877 | comp_class->so_handle); | |
878 | } | |
879 | } | |
880 | ||
881 | static inline void format_component(char **buf_ch, bool extended, | |
882 | const char *prefix, struct bt_component *component) | |
883 | { | |
884 | char tmp_prefix[64]; | |
885 | ||
886 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(component->name->str)); | |
887 | SET_TMP_PREFIX("class-"); | |
888 | format_component_class(buf_ch, extended, tmp_prefix, component->class); | |
889 | ||
890 | if (!extended) { | |
891 | return; | |
892 | } | |
893 | ||
894 | BUF_APPEND(", %sinput-port-count=%u, %soutput-port-count=%u", | |
895 | PRFIELD(component->input_ports ? component->input_ports->len : 0), | |
896 | PRFIELD(component->output_ports ? component->output_ports->len : 0)); | |
897 | } | |
898 | ||
899 | static inline void format_port(char **buf_ch, bool extended, | |
900 | const char *prefix, struct bt_port *port) | |
901 | { | |
902 | char tmp_prefix[64]; | |
903 | ||
904 | BUF_APPEND(", %stype=%s, %sname=\"%s\"", | |
905 | PRFIELD(bt_port_type_string(port->type)), | |
906 | PRFIELD(port->name->str)); | |
907 | ||
908 | if (!extended) { | |
909 | return; | |
910 | } | |
911 | ||
912 | if (port->connection) { | |
913 | SET_TMP_PREFIX("conn-"); | |
914 | format_connection(buf_ch, false, tmp_prefix, port->connection); | |
915 | } | |
916 | } | |
917 | ||
918 | static inline void format_connection(char **buf_ch, bool extended, | |
919 | const char *prefix, struct bt_connection *connection) | |
920 | { | |
921 | char tmp_prefix[64]; | |
922 | ||
923 | if (!extended) { | |
924 | return; | |
925 | } | |
926 | ||
927 | if (connection->upstream_port) { | |
928 | SET_TMP_PREFIX("upstream-port-"); | |
929 | format_port(buf_ch, false, tmp_prefix, | |
930 | connection->upstream_port); | |
931 | } | |
932 | ||
933 | if (connection->downstream_port) { | |
934 | SET_TMP_PREFIX("downstream-port-"); | |
935 | format_port(buf_ch, false, tmp_prefix, | |
936 | connection->downstream_port); | |
937 | } | |
938 | } | |
939 | ||
940 | static inline void format_graph(char **buf_ch, bool extended, | |
941 | const char *prefix, struct bt_graph *graph) | |
942 | { | |
943 | BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph->canceled)); | |
944 | ||
945 | if (!extended) { | |
946 | return; | |
947 | } | |
948 | ||
949 | BUF_APPEND(", %scomp-count=%u, %sconn-count=%u", | |
950 | PRFIELD(graph->components->len), | |
951 | PRFIELD(graph->connections->len)); | |
952 | } | |
953 | ||
954 | static inline void format_notification_iterator(char **buf_ch, | |
955 | bool extended, const char *prefix, | |
956 | struct bt_notification_iterator *iterator) | |
957 | { | |
958 | const char *type; | |
959 | char tmp_prefix[64]; | |
960 | ||
961 | if (iterator->type == BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION) { | |
962 | type = "BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION"; | |
963 | } else if (iterator->type == BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT) { | |
964 | type = "BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT"; | |
965 | } else { | |
966 | type = "(unknown)"; | |
967 | } | |
968 | ||
969 | BUF_APPEND(", %stype=%s", PRFIELD(type)); | |
970 | ||
971 | switch (iterator->type) { | |
972 | case BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION: | |
973 | { | |
974 | struct bt_notification_iterator_private_connection * | |
975 | iter_priv_conn = (void *) iterator; | |
976 | ||
977 | if (iter_priv_conn->upstream_component) { | |
978 | SET_TMP_PREFIX("upstream-comp-"); | |
979 | format_component(buf_ch, false, tmp_prefix, | |
980 | iter_priv_conn->upstream_component); | |
981 | } | |
982 | ||
983 | if (iter_priv_conn->upstream_port) { | |
984 | SET_TMP_PREFIX("upstream-port-"); | |
985 | format_port(buf_ch, false, tmp_prefix, | |
986 | iter_priv_conn->upstream_port); | |
987 | } | |
988 | ||
989 | if (iter_priv_conn->connection) { | |
990 | SET_TMP_PREFIX("upstream-conn-"); | |
991 | format_connection(buf_ch, false, tmp_prefix, | |
992 | iter_priv_conn->connection); | |
993 | } | |
994 | break; | |
995 | } | |
996 | case BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT: | |
997 | { | |
998 | struct bt_notification_iterator_output_port *iter_output_port = | |
999 | (void *) iterator; | |
1000 | ||
1001 | SET_TMP_PREFIX("graph-"); | |
1002 | format_graph(buf_ch, false, tmp_prefix, | |
1003 | iter_output_port->graph); | |
1004 | SET_TMP_PREFIX("colander-comp-"); | |
1005 | format_component(buf_ch, false, tmp_prefix, | |
1006 | iter_output_port->colander); | |
1007 | SET_TMP_PREFIX("output-port-"); | |
1008 | format_port(buf_ch, false, tmp_prefix, | |
1009 | iter_output_port->output_port); | |
1010 | break; | |
1011 | } | |
1012 | default: | |
1013 | break; | |
1014 | } | |
1015 | } | |
1016 | ||
1017 | static inline void format_plugin(char **buf_ch, bool extended, | |
1018 | const char *prefix, struct bt_plugin *plugin) | |
1019 | { | |
1020 | char tmp_prefix[64]; | |
1021 | ||
1022 | BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin->type))); | |
1023 | ||
1024 | if (plugin->info.path_set) { | |
1025 | BUF_APPEND(", %spath=\"%s\"", | |
1026 | PRFIELD(plugin->info.path->str)); | |
1027 | } | |
1028 | ||
1029 | if (plugin->info.name_set) { | |
1030 | BUF_APPEND(", %sname=\"%s\"", | |
1031 | PRFIELD(plugin->info.name->str)); | |
1032 | } | |
1033 | ||
1034 | if (!extended) { | |
1035 | return; | |
1036 | } | |
1037 | ||
1038 | if (plugin->info.author_set) { | |
1039 | BUF_APPEND(", %sauthor=\"%s\"", | |
1040 | PRFIELD(plugin->info.author->str)); | |
1041 | } | |
1042 | ||
1043 | if (plugin->info.license_set) { | |
1044 | BUF_APPEND(", %slicense=\"%s\"", | |
1045 | PRFIELD(plugin->info.license->str)); | |
1046 | } | |
1047 | ||
1048 | if (plugin->info.version_set) { | |
1049 | BUF_APPEND(", %sversion=%u.%u.%u%s", | |
1050 | PRFIELD(plugin->info.version.major), | |
1051 | plugin->info.version.minor, | |
1052 | plugin->info.version.patch, | |
1053 | plugin->info.version.extra ? | |
1054 | plugin->info.version.extra->str : ""); | |
1055 | } | |
1056 | ||
1057 | BUF_APPEND(", %sis-frozen=%d, %scomp-class-count=%u", | |
1058 | PRFIELD(plugin->frozen), | |
1059 | PRFIELD(plugin->comp_classes->len)); | |
1060 | ||
1061 | if (plugin->spec_data) { | |
1062 | struct bt_plugin_so_spec_data *spec_data = | |
1063 | (void *) plugin->spec_data; | |
1064 | ||
1065 | if (spec_data->shared_lib_handle) { | |
1066 | SET_TMP_PREFIX("so-handle-"); | |
1067 | format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix, | |
1068 | spec_data->shared_lib_handle); | |
1069 | } | |
1070 | } | |
1071 | } | |
1072 | ||
1073 | static inline void format_ctf_writer(char **buf_ch, bool extended, | |
1074 | const char *prefix, struct bt_ctf_writer *writer) | |
1075 | { | |
1076 | /* TODO */ | |
1077 | } | |
1078 | ||
1079 | static inline void handle_conversion_specifier_bt(void *priv_data, | |
1080 | char **buf_ch, size_t avail_size, | |
1081 | const char **out_fmt_ch, va_list *args) | |
1082 | { | |
1083 | const char *fmt_ch = *out_fmt_ch; | |
1084 | bool extended = false; | |
1085 | char prefix[64]; | |
1086 | char *prefix_ch = prefix; | |
1087 | void *obj; | |
1088 | ||
1089 | /* skip "%!" */ | |
1090 | fmt_ch += 2; | |
1091 | ||
1092 | if (*fmt_ch == '[') { | |
1093 | /* local prefix */ | |
1094 | fmt_ch++; | |
1095 | ||
1096 | while (true) { | |
1097 | if (*fmt_ch == ']') { | |
1098 | *prefix_ch = '\0'; | |
1099 | fmt_ch++; | |
1100 | break; | |
1101 | } | |
1102 | ||
1103 | *prefix_ch = *fmt_ch; | |
1104 | prefix_ch++; | |
1105 | fmt_ch++; | |
1106 | } | |
1107 | } | |
1108 | ||
1109 | *prefix_ch = '\0'; | |
1110 | ||
1111 | if (*fmt_ch == '+') { | |
1112 | extended = true; | |
1113 | fmt_ch++; | |
1114 | } | |
1115 | ||
1116 | obj = va_arg(*args, void *); | |
1117 | BUF_APPEND("%saddr=%p", prefix, obj); | |
1118 | ||
1119 | if (!obj) { | |
1120 | goto update_fmt; | |
1121 | } | |
1122 | ||
1123 | switch (*fmt_ch) { | |
1124 | case 'r': | |
1125 | format_ref_count(buf_ch, extended, prefix, obj); | |
1126 | break; | |
1127 | case 'F': | |
1128 | format_field_type(buf_ch, extended, prefix, obj); | |
1129 | break; | |
1130 | case 'f': | |
1131 | format_field(buf_ch, extended, prefix, obj); | |
1132 | break; | |
1133 | case 'P': | |
1134 | format_field_path(buf_ch, extended, prefix, obj); | |
1135 | break; | |
1136 | case 'E': | |
1137 | format_event_class(buf_ch, extended, prefix, obj); | |
1138 | break; | |
1139 | case 'e': | |
1140 | format_event(buf_ch, extended, prefix, obj); | |
1141 | break; | |
1142 | case 'S': | |
1143 | format_stream_class(buf_ch, extended, prefix, obj); | |
1144 | break; | |
1145 | case 's': | |
1146 | format_stream(buf_ch, extended, prefix, obj); | |
1147 | break; | |
1148 | case 'a': | |
1149 | format_packet(buf_ch, extended, prefix, obj); | |
1150 | break; | |
1151 | case 't': | |
1152 | format_trace(buf_ch, extended, prefix, obj); | |
1153 | break; | |
1154 | case 'K': | |
1155 | format_clock_class(buf_ch, extended, prefix, obj); | |
1156 | break; | |
1157 | case 'k': | |
1158 | format_clock_value(buf_ch, extended, prefix, obj); | |
1159 | break; | |
1160 | case 'v': | |
1161 | format_value(buf_ch, extended, prefix, obj); | |
1162 | break; | |
1163 | case 'n': | |
1164 | format_notification(buf_ch, extended, prefix, obj); | |
1165 | break; | |
1166 | case 'i': | |
1167 | format_notification_iterator(buf_ch, extended, prefix, obj); | |
1168 | break; | |
1169 | case 'C': | |
1170 | format_component_class(buf_ch, extended, prefix, obj); | |
1171 | break; | |
1172 | case 'c': | |
1173 | format_component(buf_ch, extended, prefix, obj); | |
1174 | break; | |
1175 | case 'p': | |
1176 | format_port(buf_ch, extended, prefix, obj); | |
1177 | break; | |
1178 | case 'x': | |
1179 | format_connection(buf_ch, extended, prefix, obj); | |
1180 | break; | |
1181 | case 'u': | |
1182 | format_plugin(buf_ch, extended, prefix, obj); | |
1183 | break; | |
1184 | case 'g': | |
1185 | format_graph(buf_ch, extended, prefix, obj); | |
1186 | break; | |
1187 | case 'w': | |
1188 | format_ctf_writer(buf_ch, extended, prefix, obj); | |
1189 | break; | |
1190 | default: | |
1191 | abort(); | |
1192 | } | |
1193 | ||
1194 | update_fmt: | |
1195 | fmt_ch++; | |
1196 | *out_fmt_ch = fmt_ch; | |
1197 | } | |
1198 | ||
1199 | BT_HIDDEN | |
1200 | void bt_lib_log(const char *func, const char *file, unsigned line, | |
1201 | int lvl, const char *tag, const char *fmt, ...) | |
1202 | { | |
1203 | va_list args; | |
1204 | ||
1205 | assert(tag); | |
1206 | assert(fmt); | |
1207 | va_start(args, fmt); | |
1208 | bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', | |
1209 | handle_conversion_specifier_bt, NULL, fmt, &args); | |
1210 | va_end(args); | |
1211 | _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf); | |
1212 | } |