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