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