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 | ||
3cd4c495 PP |
23 | #define BT_LOG_TAG "LIB/LIB-LOGGING" |
24 | #include "lib/logging.h" | |
3dca2276 | 25 | |
476ef981 PP |
26 | #include <stdarg.h> |
27 | #include <stdio.h> | |
28 | #include <stdlib.h> | |
29 | #include <string.h> | |
30 | #include <inttypes.h> | |
31 | #include <stdint.h> | |
476ef981 PP |
32 | #include <wchar.h> |
33 | #include <glib.h> | |
578e048b | 34 | #include "common/common.h" |
6162e6b7 | 35 | #include "common/uuid.h" |
4fa90f32 | 36 | #include <babeltrace2/babeltrace.h> |
578e048b | 37 | |
51375aa9 PP |
38 | #include "logging.h" |
39 | #include "assert-pre.h" | |
40 | #include "assert-post.h" | |
41 | #include "value.h" | |
6769570a | 42 | #include "integer-range-set.h" |
51375aa9 | 43 | #include "object-pool.h" |
b70d57a1 | 44 | #include "graph/interrupter.h" |
578e048b | 45 | #include "graph/component-class.h" |
578e048b MJ |
46 | #include "graph/component-filter.h" |
47 | #include "graph/component.h" | |
48 | #include "graph/component-sink.h" | |
49 | #include "graph/component-source.h" | |
50 | #include "graph/connection.h" | |
51 | #include "graph/graph.h" | |
52 | #include "graph/message/discarded-items.h" | |
53 | #include "graph/message/event.h" | |
54 | #include "graph/message/iterator.h" | |
55 | #include "graph/message/message.h" | |
56 | #include "graph/message/message-iterator-inactivity.h" | |
57 | #include "graph/message/packet.h" | |
578e048b MJ |
58 | #include "graph/message/stream.h" |
59 | #include "graph/port.h" | |
578e048b MJ |
60 | #include "plugin/plugin.h" |
61 | #include "plugin/plugin-so.h" | |
62 | #include "trace-ir/clock-class.h" | |
63 | #include "trace-ir/clock-snapshot.h" | |
64 | #include "trace-ir/event-class.h" | |
65 | #include "trace-ir/event.h" | |
66 | #include "trace-ir/field-class.h" | |
67 | #include "trace-ir/field.h" | |
68 | #include "trace-ir/field-path.h" | |
69 | #include "trace-ir/packet.h" | |
70 | #include "trace-ir/stream-class.h" | |
71 | #include "trace-ir/stream.h" | |
72 | #include "trace-ir/trace-class.h" | |
73 | #include "trace-ir/trace.h" | |
74 | #include "trace-ir/utils.h" | |
553c4bab PP |
75 | #include "error.h" |
76 | #include "assert-pre.h" | |
476ef981 PP |
77 | |
78 | #define LIB_LOGGING_BUF_SIZE (4096 * 4) | |
79 | ||
c9fe7f23 | 80 | static __thread char lib_logging_buf[LIB_LOGGING_BUF_SIZE]; |
476ef981 PP |
81 | |
82 | #define BUF_APPEND(_fmt, ...) \ | |
83 | do { \ | |
84 | int _count; \ | |
85 | size_t _size = LIB_LOGGING_BUF_SIZE - \ | |
86 | (size_t) (*buf_ch - lib_logging_buf); \ | |
87 | _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \ | |
f6ccaed9 | 88 | BT_ASSERT(_count >= 0); \ |
476ef981 PP |
89 | *buf_ch += MIN(_count, _size); \ |
90 | if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \ | |
91 | return; \ | |
92 | } \ | |
93 | } while (0) | |
94 | ||
95 | #define BUF_APPEND_UUID(_uuid) \ | |
44c440bc PP |
96 | do { \ |
97 | BUF_APPEND(", %suuid=", prefix); \ | |
98 | format_uuid(buf_ch, (_uuid)); \ | |
99 | } while (0) | |
476ef981 PP |
100 | |
101 | #define PRFIELD(_expr) prefix, (_expr) | |
102 | ||
d94d92ac PP |
103 | #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL) |
104 | ||
b293c529 | 105 | #define TMP_PREFIX_LEN 128 |
476ef981 PP |
106 | #define SET_TMP_PREFIX(_prefix2) \ |
107 | do { \ | |
b293c529 PP |
108 | int snprintf_ret = \ |
109 | snprintf(tmp_prefix, TMP_PREFIX_LEN - 1, "%s%s", \ | |
110 | prefix, (_prefix2)); \ | |
111 | \ | |
112 | if (snprintf_ret < 0 || snprintf_ret >= TMP_PREFIX_LEN - 1) { \ | |
113 | abort(); \ | |
114 | } \ | |
115 | \ | |
eea66fe0 | 116 | tmp_prefix[TMP_PREFIX_LEN - 1] = '\0'; \ |
476ef981 PP |
117 | } while (0) |
118 | ||
119 | static inline void format_component(char **buf_ch, bool extended, | |
862ca4ed | 120 | const char *prefix, const struct bt_component *component); |
476ef981 PP |
121 | |
122 | static inline void format_port(char **buf_ch, bool extended, | |
862ca4ed | 123 | const char *prefix, const struct bt_port *port); |
476ef981 PP |
124 | |
125 | static inline void format_connection(char **buf_ch, bool extended, | |
862ca4ed | 126 | const char *prefix, const struct bt_connection *connection); |
476ef981 | 127 | |
605e1019 PP |
128 | static inline void format_clock_snapshot(char **buf_ch, bool extended, |
129 | const char *prefix, const struct bt_clock_snapshot *clock_snapshot); | |
e22b45d0 | 130 | |
44c440bc | 131 | static inline void format_field_path(char **buf_ch, bool extended, |
862ca4ed | 132 | const char *prefix, const struct bt_field_path *field_path); |
44c440bc | 133 | |
3fea54f6 | 134 | static inline void format_object(char **buf_ch, bool extended, |
862ca4ed | 135 | const char *prefix, const struct bt_object *obj) |
476ef981 | 136 | { |
3fea54f6 | 137 | BUF_APPEND(", %sref-count=%llu", prefix, obj->ref_count); |
476ef981 PP |
138 | } |
139 | ||
44c440bc | 140 | static inline void format_uuid(char **buf_ch, bt_uuid uuid) |
e22b45d0 | 141 | { |
6162e6b7 | 142 | BUF_APPEND("\"" BT_UUID_FMT "\"", BT_UUID_FMT_VALUES(uuid)); |
e22b45d0 PP |
143 | } |
144 | ||
312c056a | 145 | static inline void format_object_pool(char **buf_ch, bool extended, |
862ca4ed | 146 | const char *prefix, const struct bt_object_pool *pool) |
312c056a PP |
147 | { |
148 | BUF_APPEND(", %ssize=%zu", PRFIELD(pool->size)); | |
149 | ||
150 | if (pool->objects) { | |
151 | BUF_APPEND(", %scap=%u", PRFIELD(pool->objects->len)); | |
152 | } | |
153 | } | |
154 | ||
5cd6d0e5 | 155 | static inline void format_integer_field_class(char **buf_ch, |
44c440bc | 156 | bool extended, const char *prefix, |
862ca4ed | 157 | const struct bt_field_class *field_class) |
44c440bc | 158 | { |
862ca4ed PP |
159 | const struct bt_field_class_integer *int_fc = |
160 | (const void *) field_class; | |
44c440bc PP |
161 | |
162 | BUF_APPEND(", %srange-size=%" PRIu64 ", %sbase=%s", | |
5cd6d0e5 PP |
163 | PRFIELD(int_fc->range), |
164 | PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc->base))); | |
44c440bc PP |
165 | } |
166 | ||
5cd6d0e5 | 167 | static inline void format_array_field_class(char **buf_ch, |
44c440bc | 168 | bool extended, const char *prefix, |
862ca4ed | 169 | const struct bt_field_class *field_class) |
44c440bc | 170 | { |
862ca4ed PP |
171 | const struct bt_field_class_array *array_fc = |
172 | (const void *) field_class; | |
44c440bc | 173 | |
864cad70 | 174 | BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s", |
5cd6d0e5 | 175 | PRFIELD(array_fc->element_fc), |
864cad70 | 176 | PRFIELD(bt_common_field_class_type_string(array_fc->element_fc->type))); |
44c440bc PP |
177 | } |
178 | ||
5cd6d0e5 | 179 | static inline void format_field_class(char **buf_ch, bool extended, |
862ca4ed | 180 | const char *prefix, const struct bt_field_class *field_class) |
476ef981 | 181 | { |
879e14e8 | 182 | char tmp_prefix[TMP_PREFIX_LEN]; |
44c440bc | 183 | |
864cad70 PP |
184 | BUF_APPEND(", %stype=%s", |
185 | PRFIELD(bt_common_field_class_type_string(field_class->type))); | |
476ef981 PP |
186 | |
187 | if (extended) { | |
5cd6d0e5 | 188 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class->frozen)); |
862ca4ed PP |
189 | BUF_APPEND(", %sis-part-of-trace-class=%d", |
190 | PRFIELD(field_class->part_of_trace_class)); | |
476ef981 PP |
191 | } else { |
192 | return; | |
193 | } | |
194 | ||
864cad70 PP |
195 | switch (field_class->type) { |
196 | case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: | |
197 | case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: | |
476ef981 | 198 | { |
5cd6d0e5 | 199 | format_integer_field_class(buf_ch, extended, prefix, field_class); |
476ef981 PP |
200 | break; |
201 | } | |
864cad70 | 202 | case BT_FIELD_CLASS_TYPE_REAL: |
476ef981 | 203 | { |
862ca4ed | 204 | const struct bt_field_class_real *real_fc = (void *) field_class; |
476ef981 | 205 | |
44c440bc | 206 | BUF_APPEND(", %sis-single-precision=%d", |
5cd6d0e5 | 207 | PRFIELD(real_fc->is_single_precision)); |
476ef981 PP |
208 | break; |
209 | } | |
864cad70 PP |
210 | case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: |
211 | case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: | |
476ef981 | 212 | { |
862ca4ed PP |
213 | const struct bt_field_class_enumeration *enum_fc = |
214 | (const void *) field_class; | |
476ef981 | 215 | |
5cd6d0e5 | 216 | format_integer_field_class(buf_ch, extended, prefix, field_class); |
476ef981 | 217 | BUF_APPEND(", %smapping-count=%u", |
5cd6d0e5 | 218 | PRFIELD(enum_fc->mappings->len)); |
476ef981 PP |
219 | break; |
220 | } | |
864cad70 | 221 | case BT_FIELD_CLASS_TYPE_STRUCTURE: |
476ef981 | 222 | { |
862ca4ed PP |
223 | const struct bt_field_class_structure *struct_fc = |
224 | (const void *) field_class; | |
44c440bc | 225 | |
5cd6d0e5 | 226 | if (struct_fc->common.named_fcs) { |
44c440bc | 227 | BUF_APPEND(", %smember-count=%u", |
5cd6d0e5 | 228 | PRFIELD(struct_fc->common.named_fcs->len)); |
44c440bc | 229 | } |
476ef981 | 230 | |
476ef981 PP |
231 | break; |
232 | } | |
864cad70 | 233 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: |
476ef981 | 234 | { |
9c08c816 | 235 | const struct bt_field_class_array_static *array_fc = |
862ca4ed | 236 | (const void *) field_class; |
476ef981 | 237 | |
5cd6d0e5 PP |
238 | format_array_field_class(buf_ch, extended, prefix, field_class); |
239 | BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_fc->length)); | |
476ef981 PP |
240 | break; |
241 | } | |
864cad70 | 242 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: |
476ef981 | 243 | { |
9c08c816 | 244 | const struct bt_field_class_array_dynamic *array_fc = |
862ca4ed | 245 | (const void *) field_class; |
44c440bc | 246 | |
5cd6d0e5 | 247 | format_array_field_class(buf_ch, extended, prefix, field_class); |
44c440bc | 248 | |
5cd6d0e5 PP |
249 | if (array_fc->length_fc) { |
250 | SET_TMP_PREFIX("length-fc-"); | |
251 | format_field_class(buf_ch, extended, tmp_prefix, | |
252 | array_fc->length_fc); | |
44c440bc PP |
253 | } |
254 | ||
5cd6d0e5 | 255 | if (array_fc->length_field_path) { |
44c440bc PP |
256 | SET_TMP_PREFIX("length-field-path-"); |
257 | format_field_path(buf_ch, extended, tmp_prefix, | |
5cd6d0e5 | 258 | array_fc->length_field_path); |
44c440bc | 259 | } |
476ef981 | 260 | |
476ef981 PP |
261 | break; |
262 | } | |
b38aea74 PP |
263 | case BT_FIELD_CLASS_TYPE_OPTION: |
264 | { | |
265 | const struct bt_field_class_option *opt_fc = | |
266 | (const void *) field_class; | |
267 | ||
268 | BUF_APPEND(", %scontent-fc-addr=%p, %scontent-fc-type=%s", | |
269 | PRFIELD(opt_fc->content_fc), | |
270 | PRFIELD(bt_common_field_class_type_string(opt_fc->content_fc->type))); | |
271 | ||
272 | if (opt_fc->selector_fc) { | |
273 | SET_TMP_PREFIX("selector-fc-"); | |
274 | format_field_class(buf_ch, extended, tmp_prefix, | |
275 | opt_fc->selector_fc); | |
276 | } | |
277 | ||
278 | if (opt_fc->selector_field_path) { | |
279 | SET_TMP_PREFIX("selector-field-path-"); | |
280 | format_field_path(buf_ch, extended, tmp_prefix, | |
281 | opt_fc->selector_field_path); | |
282 | } | |
283 | ||
284 | break; | |
285 | } | |
45c51519 PP |
286 | case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: |
287 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR: | |
288 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR: | |
476ef981 | 289 | { |
862ca4ed PP |
290 | const struct bt_field_class_variant *var_fc = |
291 | (const void *) field_class; | |
44c440bc | 292 | |
5cd6d0e5 | 293 | if (var_fc->common.named_fcs) { |
44c440bc | 294 | BUF_APPEND(", %soption-count=%u", |
5cd6d0e5 | 295 | PRFIELD(var_fc->common.named_fcs->len)); |
44c440bc PP |
296 | } |
297 | ||
45c51519 PP |
298 | if (field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR || |
299 | field_class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) { | |
300 | const struct bt_field_class_variant_with_selector *var_with_sel_fc = | |
301 | (const void *) var_fc; | |
302 | ||
303 | if (var_with_sel_fc->selector_fc) { | |
304 | SET_TMP_PREFIX("selector-fc-"); | |
305 | format_field_class(buf_ch, extended, tmp_prefix, | |
306 | var_with_sel_fc->selector_fc); | |
307 | } | |
308 | ||
309 | if (var_with_sel_fc->selector_field_path) { | |
310 | SET_TMP_PREFIX("selector-field-path-"); | |
311 | format_field_path(buf_ch, extended, tmp_prefix, | |
312 | var_with_sel_fc->selector_field_path); | |
313 | } | |
44c440bc | 314 | } |
476ef981 | 315 | |
476ef981 PP |
316 | break; |
317 | } | |
318 | default: | |
319 | break; | |
320 | } | |
321 | } | |
322 | ||
cb6f1f7d | 323 | static inline void format_field_integer_extended(char **buf_ch, |
862ca4ed | 324 | const char *prefix, const struct bt_field *field) |
476ef981 | 325 | { |
862ca4ed PP |
326 | const struct bt_field_integer *integer = (void *) field; |
327 | const struct bt_field_class_integer *field_class = | |
328 | (void *) field->class; | |
476ef981 PP |
329 | const char *fmt = NULL; |
330 | ||
5cd6d0e5 | 331 | BT_ASSERT(field_class); |
312c056a | 332 | |
5cd6d0e5 | 333 | if (field_class->base == BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL) { |
476ef981 | 334 | fmt = ", %svalue=%" PRIo64; |
5cd6d0e5 | 335 | } else if (field_class->base == BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL) { |
476ef981 PP |
336 | fmt = ", %svalue=%" PRIx64; |
337 | } | |
338 | ||
864cad70 PP |
339 | if (field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || |
340 | field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) { | |
476ef981 PP |
341 | if (!fmt) { |
342 | fmt = ", %svalue=%" PRId64; | |
343 | } | |
344 | ||
44c440bc | 345 | BUF_APPEND(fmt, PRFIELD(integer->value.i)); |
476ef981 PP |
346 | } else { |
347 | if (!fmt) { | |
348 | fmt = ", %svalue=%" PRIu64; | |
349 | } | |
350 | ||
44c440bc | 351 | BUF_APPEND(fmt, PRFIELD(integer->value.u)); |
476ef981 PP |
352 | } |
353 | } | |
354 | ||
cb6f1f7d | 355 | static inline void format_field(char **buf_ch, bool extended, |
862ca4ed | 356 | const char *prefix, const struct bt_field *field) |
476ef981 | 357 | { |
44c440bc | 358 | BUF_APPEND(", %sis-set=%d", PRFIELD(field->is_set)); |
476ef981 PP |
359 | |
360 | if (extended) { | |
361 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(field->frozen)); | |
362 | } | |
363 | ||
864cad70 | 364 | BUF_APPEND(", %sclass-addr=%p", PRFIELD(field->class)); |
312c056a | 365 | |
5cd6d0e5 | 366 | if (!field->class) { |
312c056a PP |
367 | return; |
368 | } | |
369 | ||
864cad70 PP |
370 | BUF_APPEND(", %sclass-type=%s", |
371 | PRFIELD(bt_common_field_class_type_string(field->class->type))); | |
476ef981 | 372 | |
44c440bc | 373 | if (!extended || !field->is_set) { |
476ef981 PP |
374 | return; |
375 | } | |
376 | ||
864cad70 | 377 | switch (field->class->type) { |
5cebbe7f PP |
378 | case BT_FIELD_CLASS_TYPE_BOOL: |
379 | { | |
380 | const struct bt_field_bool *bool_field = (const void *) field; | |
381 | ||
382 | BUF_APPEND(", %svalue=%d", PRFIELD(bool_field->value)); | |
383 | break; | |
384 | } | |
864cad70 PP |
385 | case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: |
386 | case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: | |
387 | case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: | |
388 | case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: | |
476ef981 | 389 | { |
cb6f1f7d | 390 | format_field_integer_extended(buf_ch, prefix, field); |
476ef981 PP |
391 | break; |
392 | } | |
864cad70 | 393 | case BT_FIELD_CLASS_TYPE_REAL: |
476ef981 | 394 | { |
862ca4ed | 395 | const struct bt_field_real *real_field = (const void *) field; |
476ef981 | 396 | |
44c440bc | 397 | BUF_APPEND(", %svalue=%f", PRFIELD(real_field->value)); |
476ef981 PP |
398 | break; |
399 | } | |
864cad70 | 400 | case BT_FIELD_CLASS_TYPE_STRING: |
476ef981 | 401 | { |
862ca4ed | 402 | const struct bt_field_string *str = (const void *) field; |
476ef981 | 403 | |
4d4b475d PP |
404 | if (str->buf) { |
405 | BT_ASSERT(str->buf->data); | |
312c056a | 406 | BUF_APPEND(", %spartial-value=\"%.32s\"", |
4d4b475d | 407 | PRFIELD(str->buf->data)); |
312c056a | 408 | } |
44c440bc | 409 | |
476ef981 PP |
410 | break; |
411 | } | |
864cad70 PP |
412 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: |
413 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: | |
476ef981 | 414 | { |
862ca4ed | 415 | const struct bt_field_array *array_field = (const void *) field; |
476ef981 | 416 | |
44c440bc | 417 | BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_field->length)); |
312c056a | 418 | |
44c440bc | 419 | if (array_field->fields) { |
312c056a | 420 | BUF_APPEND(", %sallocated-length=%u", |
44c440bc | 421 | PRFIELD(array_field->fields->len)); |
312c056a | 422 | } |
44c440bc | 423 | |
476ef981 PP |
424 | break; |
425 | } | |
45c51519 PP |
426 | case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: |
427 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR: | |
428 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR: | |
476ef981 | 429 | { |
862ca4ed | 430 | const struct bt_field_variant *var_field = (const void *) field; |
312c056a | 431 | |
44c440bc PP |
432 | BUF_APPEND(", %sselected-field-index=%" PRIu64, |
433 | PRFIELD(var_field->selected_index)); | |
312c056a PP |
434 | break; |
435 | } | |
436 | default: | |
437 | break; | |
438 | } | |
3dca2276 PP |
439 | } |
440 | ||
476ef981 | 441 | static inline void format_field_path(char **buf_ch, bool extended, |
862ca4ed | 442 | const char *prefix, const struct bt_field_path *field_path) |
476ef981 PP |
443 | { |
444 | uint64_t i; | |
445 | ||
66ddcddf PP |
446 | if (field_path->items) { |
447 | BT_ASSERT(field_path->items); | |
448 | BUF_APPEND(", %sitem-count=%u", | |
449 | PRFIELD(field_path->items->len)); | |
312c056a | 450 | } |
476ef981 | 451 | |
66ddcddf | 452 | if (!extended || !field_path->items) { |
476ef981 PP |
453 | return; |
454 | } | |
455 | ||
cb6f1f7d PP |
456 | BUF_APPEND(", %spath=[%s", |
457 | PRFIELD(bt_common_scope_string(field_path->root))); | |
476ef981 | 458 | |
66ddcddf PP |
459 | for (i = 0; i < bt_field_path_get_item_count(field_path); i++) { |
460 | const struct bt_field_path_item *fp_item = | |
461 | bt_field_path_borrow_item_by_index_const(field_path, i); | |
462 | ||
463 | switch (bt_field_path_item_get_type(fp_item)) { | |
464 | case BT_FIELD_PATH_ITEM_TYPE_INDEX: | |
465 | BUF_APPEND(", %" PRIu64, | |
466 | bt_field_path_item_index_get_index(fp_item)); | |
467 | break; | |
468 | case BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT: | |
469 | BUF_APPEND("%s", ", <CUR>"); | |
470 | break; | |
471 | default: | |
472 | abort(); | |
473 | } | |
476ef981 PP |
474 | } |
475 | ||
476 | BUF_APPEND("%s", "]"); | |
477 | } | |
478 | ||
862ca4ed PP |
479 | static inline void format_trace_class(char **buf_ch, bool extended, |
480 | const char *prefix, const struct bt_trace_class *trace_class) | |
476ef981 | 481 | { |
476ef981 PP |
482 | if (!extended) { |
483 | return; | |
484 | } | |
485 | ||
862ca4ed | 486 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class->frozen)); |
476ef981 | 487 | |
862ca4ed | 488 | if (trace_class->stream_classes) { |
312c056a | 489 | BUF_APPEND(", %sstream-class-count=%u", |
862ca4ed | 490 | PRFIELD(trace_class->stream_classes->len)); |
312c056a PP |
491 | } |
492 | ||
83ebb7f1 | 493 | BUF_APPEND(", %sassigns-auto-sc-id=%d", |
862ca4ed | 494 | PRFIELD(trace_class->assigns_automatic_stream_class_id)); |
862ca4ed PP |
495 | } |
496 | ||
497 | static inline void format_trace(char **buf_ch, bool extended, | |
498 | const char *prefix, const struct bt_trace *trace) | |
499 | { | |
879e14e8 | 500 | char tmp_prefix[TMP_PREFIX_LEN]; |
862ca4ed PP |
501 | |
502 | if (trace->name.value) { | |
503 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name.value)); | |
504 | } | |
505 | ||
506 | if (!extended) { | |
507 | return; | |
508 | } | |
509 | ||
335a2da5 PP |
510 | if (trace->uuid.value) { |
511 | BUF_APPEND_UUID(trace->uuid.value); | |
512 | } | |
513 | ||
862ca4ed PP |
514 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen)); |
515 | ||
312c056a PP |
516 | if (trace->streams) { |
517 | BUF_APPEND(", %sstream-count=%u", | |
518 | PRFIELD(trace->streams->len)); | |
519 | } | |
520 | ||
862ca4ed PP |
521 | if (!trace->class) { |
522 | return; | |
523 | } | |
524 | ||
525 | BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace->class)); | |
526 | SET_TMP_PREFIX("trace-class-"); | |
527 | format_trace_class(buf_ch, false, tmp_prefix, trace->class); | |
3dca2276 PP |
528 | } |
529 | ||
cb6f1f7d | 530 | static inline void format_stream_class(char **buf_ch, bool extended, |
862ca4ed PP |
531 | const char *prefix, |
532 | const struct bt_stream_class *stream_class) | |
3dca2276 | 533 | { |
862ca4ed | 534 | const struct bt_trace_class *trace_class; |
879e14e8 | 535 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 | 536 | |
44c440bc | 537 | BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream_class->id)); |
476ef981 | 538 | |
44c440bc PP |
539 | if (stream_class->name.value) { |
540 | BUF_APPEND(", %sname=\"%s\"", | |
541 | PRFIELD(stream_class->name.value)); | |
476ef981 PP |
542 | } |
543 | ||
544 | if (!extended) { | |
545 | return; | |
546 | } | |
547 | ||
548 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class->frozen)); | |
312c056a PP |
549 | |
550 | if (stream_class->event_classes) { | |
551 | BUF_APPEND(", %sevent-class-count=%u", | |
552 | PRFIELD(stream_class->event_classes->len)); | |
553 | } | |
554 | ||
5cd6d0e5 | 555 | BUF_APPEND(", %spacket-context-fc-addr=%p, " |
83ebb7f1 | 556 | "%sevent-common-context-fc-addr=%p", |
5cd6d0e5 | 557 | PRFIELD(stream_class->packet_context_fc), |
5cd6d0e5 | 558 | PRFIELD(stream_class->event_common_context_fc)); |
862ca4ed PP |
559 | trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); |
560 | if (!trace_class) { | |
476ef981 PP |
561 | return; |
562 | } | |
563 | ||
7fe92073 | 564 | BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, " |
26fc5aed PP |
565 | "%ssupports-packets=%d, " |
566 | "%spackets-have-begin-default-cs=%d, " | |
567 | "%spackets-have-end-default-cs=%d, " | |
2e90378a PP |
568 | "%ssupports-discarded-events=%d, " |
569 | "%sdiscarded-events-have-default-cs=%d, " | |
570 | "%ssupports-discarded-packets=%d, " | |
571 | "%sdiscarded-packets-have-default-cs=%d", | |
44c440bc | 572 | PRFIELD(stream_class->assigns_automatic_event_class_id), |
7fe92073 | 573 | PRFIELD(stream_class->assigns_automatic_stream_id), |
26fc5aed | 574 | PRFIELD(stream_class->supports_packets), |
9b24b6aa PP |
575 | PRFIELD(stream_class->packets_have_beginning_default_clock_snapshot), |
576 | PRFIELD(stream_class->packets_have_end_default_clock_snapshot), | |
2e90378a PP |
577 | PRFIELD(stream_class->supports_discarded_events), |
578 | PRFIELD(stream_class->discarded_events_have_default_clock_snapshots), | |
579 | PRFIELD(stream_class->supports_discarded_packets), | |
580 | PRFIELD(stream_class->discarded_packets_have_default_clock_snapshots)); | |
862ca4ed PP |
581 | BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class)); |
582 | SET_TMP_PREFIX("trace-class-"); | |
583 | format_trace_class(buf_ch, false, tmp_prefix, trace_class); | |
5c563278 | 584 | SET_TMP_PREFIX("pcf-pool-"); |
9a6502b6 | 585 | format_object_pool(buf_ch, extended, tmp_prefix, |
5c563278 | 586 | &stream_class->packet_context_field_pool); |
3dca2276 PP |
587 | } |
588 | ||
cb6f1f7d | 589 | static inline void format_event_class(char **buf_ch, bool extended, |
862ca4ed | 590 | const char *prefix, const struct bt_event_class *event_class) |
3dca2276 | 591 | { |
862ca4ed PP |
592 | const struct bt_stream_class *stream_class; |
593 | const struct bt_trace_class *trace_class; | |
879e14e8 | 594 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 | 595 | |
44c440bc | 596 | BUF_APPEND(", %sid=%" PRIu64, PRFIELD(event_class->id)); |
476ef981 | 597 | |
44c440bc | 598 | if (event_class->name.value) { |
cb6f1f7d | 599 | BUF_APPEND(", %sname=\"%s\"", |
44c440bc | 600 | PRFIELD(event_class->name.value)); |
476ef981 PP |
601 | } |
602 | ||
603 | if (!extended) { | |
604 | return; | |
605 | } | |
606 | ||
44c440bc PP |
607 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(event_class->frozen)); |
608 | ||
609 | if (event_class->log_level.base.avail) { | |
610 | BUF_APPEND(", %slog-level=%s", | |
611 | PRFIELD(bt_common_event_class_log_level_string( | |
612 | (int) event_class->log_level.value))); | |
613 | } | |
476ef981 | 614 | |
44c440bc | 615 | if (event_class->emf_uri.value) { |
476ef981 | 616 | BUF_APPEND(", %semf-uri=\"%s\"", |
44c440bc | 617 | PRFIELD(event_class->emf_uri.value)); |
476ef981 PP |
618 | } |
619 | ||
5cd6d0e5 PP |
620 | BUF_APPEND(", %sspecific-context-fc-addr=%p, %spayload-fc-addr=%p", |
621 | PRFIELD(event_class->specific_context_fc), | |
622 | PRFIELD(event_class->payload_fc)); | |
476ef981 | 623 | |
862ca4ed | 624 | stream_class = bt_event_class_borrow_stream_class_const(event_class); |
476ef981 PP |
625 | if (!stream_class) { |
626 | return; | |
627 | } | |
628 | ||
629 | BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); | |
630 | SET_TMP_PREFIX("stream-class-"); | |
cb6f1f7d | 631 | format_stream_class(buf_ch, false, tmp_prefix, stream_class); |
862ca4ed PP |
632 | trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); |
633 | if (!trace_class) { | |
476ef981 PP |
634 | return; |
635 | } | |
636 | ||
862ca4ed PP |
637 | BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class)); |
638 | SET_TMP_PREFIX("trace-class-"); | |
639 | format_trace_class(buf_ch, false, tmp_prefix, trace_class); | |
312c056a | 640 | SET_TMP_PREFIX("event-pool-"); |
9a6502b6 PP |
641 | format_object_pool(buf_ch, extended, tmp_prefix, |
642 | &event_class->event_pool); | |
3dca2276 PP |
643 | } |
644 | ||
cb6f1f7d | 645 | static inline void format_stream(char **buf_ch, bool extended, |
862ca4ed | 646 | const char *prefix, const struct bt_stream *stream) |
3dca2276 | 647 | { |
862ca4ed PP |
648 | const struct bt_stream_class *stream_class; |
649 | const struct bt_trace_class *trace_class = NULL; | |
650 | const struct bt_trace *trace = NULL; | |
879e14e8 | 651 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 | 652 | |
44c440bc | 653 | BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream->id)); |
476ef981 | 654 | |
44c440bc PP |
655 | if (stream->name.value) { |
656 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream->name.value)); | |
476ef981 PP |
657 | } |
658 | ||
476ef981 PP |
659 | if (!extended) { |
660 | return; | |
661 | } | |
662 | ||
862ca4ed PP |
663 | stream_class = bt_stream_borrow_class_const(stream); |
664 | if (stream_class) { | |
665 | BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); | |
666 | SET_TMP_PREFIX("stream-class-"); | |
667 | format_stream_class(buf_ch, false, tmp_prefix, stream_class); | |
668 | trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); | |
476ef981 PP |
669 | } |
670 | ||
862ca4ed PP |
671 | if (trace_class) { |
672 | BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class)); | |
673 | SET_TMP_PREFIX("trace-class-"); | |
674 | format_trace_class(buf_ch, false, tmp_prefix, trace_class); | |
675 | } | |
676 | ||
677 | trace = bt_stream_borrow_trace_inline(stream); | |
678 | if (trace) { | |
679 | BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); | |
680 | SET_TMP_PREFIX("trace-"); | |
681 | format_trace(buf_ch, false, tmp_prefix, trace); | |
476ef981 PP |
682 | } |
683 | ||
312c056a | 684 | SET_TMP_PREFIX("packet-pool-"); |
9a6502b6 | 685 | format_object_pool(buf_ch, extended, tmp_prefix, &stream->packet_pool); |
3dca2276 PP |
686 | } |
687 | ||
476ef981 | 688 | static inline void format_packet(char **buf_ch, bool extended, |
862ca4ed | 689 | const char *prefix, const struct bt_packet *packet) |
476ef981 | 690 | { |
862ca4ed PP |
691 | const struct bt_stream *stream; |
692 | const struct bt_trace_class *trace_class; | |
879e14e8 | 693 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 PP |
694 | |
695 | if (!extended) { | |
696 | return; | |
697 | } | |
698 | ||
83ebb7f1 | 699 | BUF_APPEND(", %sis-frozen=%d, %scontext-field-addr=%p", |
476ef981 | 700 | PRFIELD(packet->frozen), |
44c440bc | 701 | PRFIELD(packet->context_field ? packet->context_field->field : NULL)); |
862ca4ed | 702 | stream = bt_packet_borrow_stream_const(packet); |
476ef981 PP |
703 | if (!stream) { |
704 | return; | |
705 | } | |
706 | ||
707 | BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream)); | |
708 | SET_TMP_PREFIX("stream-"); | |
709 | format_stream(buf_ch, false, tmp_prefix, stream); | |
862ca4ed PP |
710 | trace_class = (const struct bt_trace_class *) bt_object_borrow_parent(&stream->base); |
711 | if (!trace_class) { | |
476ef981 PP |
712 | return; |
713 | } | |
714 | ||
862ca4ed PP |
715 | BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class)); |
716 | SET_TMP_PREFIX("trace-class-"); | |
717 | format_trace_class(buf_ch, false, tmp_prefix, trace_class); | |
476ef981 PP |
718 | } |
719 | ||
cb6f1f7d | 720 | static inline void format_event(char **buf_ch, bool extended, |
862ca4ed | 721 | const char *prefix, const struct bt_event *event) |
476ef981 | 722 | { |
862ca4ed PP |
723 | const struct bt_trace_class *trace_class; |
724 | const struct bt_stream_class *stream_class; | |
879e14e8 | 725 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 PP |
726 | |
727 | if (!extended) { | |
728 | return; | |
729 | } | |
730 | ||
83ebb7f1 | 731 | BUF_APPEND(", %sis-frozen=%d, " |
44c440bc | 732 | "%scommon-context-field-addr=%p, " |
d94d92ac | 733 | "%sspecific-context-field-addr=%p, " |
44c440bc | 734 | "%spayload-field-addr=%p, ", |
476ef981 | 735 | PRFIELD(event->frozen), |
44c440bc PP |
736 | PRFIELD(event->common_context_field), |
737 | PRFIELD(event->specific_context_field), | |
3dca2276 PP |
738 | PRFIELD(event->payload_field)); |
739 | BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event->class)); | |
312c056a PP |
740 | |
741 | if (!event->class) { | |
742 | return; | |
743 | } | |
744 | ||
476ef981 | 745 | SET_TMP_PREFIX("event-class-"); |
cb6f1f7d PP |
746 | format_event_class(buf_ch, false, tmp_prefix, event->class); |
747 | stream_class = bt_event_class_borrow_stream_class(event->class); | |
476ef981 PP |
748 | if (stream_class) { |
749 | BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); | |
750 | SET_TMP_PREFIX("stream-class-"); | |
cb6f1f7d | 751 | format_stream_class(buf_ch, false, tmp_prefix, |
3dca2276 | 752 | stream_class); |
476ef981 | 753 | |
862ca4ed PP |
754 | trace_class = bt_stream_class_borrow_trace_class_inline( |
755 | stream_class); | |
756 | if (trace_class) { | |
757 | BUF_APPEND(", %strace-class-addr=%p", | |
758 | PRFIELD(trace_class)); | |
759 | SET_TMP_PREFIX("trace-class-"); | |
760 | format_trace_class(buf_ch, false, tmp_prefix, | |
761 | trace_class); | |
476ef981 PP |
762 | } |
763 | } | |
3dca2276 | 764 | |
26fc5aed PP |
765 | if (event->stream) { |
766 | BUF_APPEND(", %sstream-addr=%p", PRFIELD(event->stream)); | |
767 | SET_TMP_PREFIX("stream-"); | |
768 | format_stream(buf_ch, false, tmp_prefix, event->stream); | |
476ef981 PP |
769 | } |
770 | ||
26fc5aed PP |
771 | if (event->packet) { |
772 | BUF_APPEND(", %spacket-addr=%p", PRFIELD(event->packet)); | |
773 | SET_TMP_PREFIX("packet-"); | |
774 | format_packet(buf_ch, false, tmp_prefix, event->packet); | |
476ef981 | 775 | } |
476ef981 PP |
776 | } |
777 | ||
778 | static inline void format_clock_class(char **buf_ch, bool extended, | |
862ca4ed | 779 | const char *prefix, const struct bt_clock_class *clock_class) |
476ef981 | 780 | { |
879e14e8 | 781 | char tmp_prefix[TMP_PREFIX_LEN]; |
312c056a | 782 | |
44c440bc PP |
783 | if (clock_class->name.value) { |
784 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name.value)); | |
785 | } | |
786 | ||
787 | BUF_APPEND(", %sfreq=%" PRIu64, PRFIELD(clock_class->frequency)); | |
476ef981 PP |
788 | |
789 | if (!extended) { | |
790 | return; | |
791 | } | |
792 | ||
44c440bc PP |
793 | if (clock_class->description.value) { |
794 | BUF_APPEND(", %spartial-descr=\"%.32s\"", | |
795 | PRFIELD(clock_class->description.value)); | |
796 | } | |
797 | ||
798 | if (clock_class->uuid.value) { | |
799 | BUF_APPEND_UUID(clock_class->uuid.value); | |
476ef981 PP |
800 | } |
801 | ||
802 | BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64 ", " | |
803 | "%soffset-s=%" PRId64 ", " | |
5552377a | 804 | "%soffset-cycles=%" PRIu64 ", %sorigin-is-unix-epoch=%d, " |
44c440bc | 805 | "%sbase-offset-ns=%" PRId64, |
476ef981 | 806 | PRFIELD(clock_class->frozen), PRFIELD(clock_class->precision), |
44c440bc PP |
807 | PRFIELD(clock_class->offset_seconds), |
808 | PRFIELD(clock_class->offset_cycles), | |
5552377a | 809 | PRFIELD(clock_class->origin_is_unix_epoch), |
44c440bc | 810 | PRFIELD(clock_class->base_offset.value_ns)); |
312c056a | 811 | |
605e1019 | 812 | SET_TMP_PREFIX("cs-pool-"); |
9a6502b6 PP |
813 | format_object_pool(buf_ch, extended, tmp_prefix, |
814 | &clock_class->cs_pool); | |
476ef981 PP |
815 | } |
816 | ||
605e1019 PP |
817 | static inline void format_clock_snapshot(char **buf_ch, bool extended, |
818 | const char *prefix, const struct bt_clock_snapshot *clock_snapshot) | |
476ef981 | 819 | { |
879e14e8 | 820 | char tmp_prefix[TMP_PREFIX_LEN]; |
44c440bc | 821 | BUF_APPEND(", %svalue=%" PRIu64 ", %sns-from-origin=%" PRId64, |
605e1019 PP |
822 | PRFIELD(clock_snapshot->value_cycles), |
823 | PRFIELD(clock_snapshot->ns_from_origin)); | |
476ef981 PP |
824 | |
825 | if (!extended) { | |
826 | return; | |
827 | } | |
828 | ||
605e1019 | 829 | BUF_APPEND(", %sis-set=%d", PRFIELD(clock_snapshot->is_set)); |
d94d92ac | 830 | |
605e1019 | 831 | if (clock_snapshot->clock_class) { |
d94d92ac | 832 | BUF_APPEND(", %sclock-class-addr=%p", |
605e1019 | 833 | PRFIELD(clock_snapshot->clock_class)); |
d94d92ac PP |
834 | SET_TMP_PREFIX("clock-class-"); |
835 | format_clock_class(buf_ch, false, tmp_prefix, | |
605e1019 | 836 | clock_snapshot->clock_class); |
d94d92ac | 837 | } |
476ef981 PP |
838 | } |
839 | ||
b70d57a1 PP |
840 | static inline void format_interrupter(char **buf_ch, bool extended, |
841 | const char *prefix, const struct bt_interrupter *intr) | |
842 | { | |
843 | BUF_APPEND(", %sis-set=%d", PRFIELD(intr->is_set)); | |
844 | } | |
845 | ||
476ef981 | 846 | static inline void format_value(char **buf_ch, bool extended, |
862ca4ed | 847 | const char *prefix, const struct bt_value *value) |
476ef981 PP |
848 | { |
849 | BUF_APPEND(", %stype=%s", | |
da91b29a | 850 | PRFIELD(bt_common_value_type_string(bt_value_get_type(value)))); |
476ef981 PP |
851 | |
852 | if (!extended) { | |
853 | return; | |
854 | } | |
855 | ||
856 | switch (bt_value_get_type(value)) { | |
857 | case BT_VALUE_TYPE_BOOL: | |
858 | { | |
601b0d3c | 859 | bt_bool val = bt_value_bool_get(value); |
476ef981 | 860 | |
476ef981 PP |
861 | BUF_APPEND(", %svalue=%d", PRFIELD(val)); |
862 | break; | |
863 | } | |
fdd3a2da | 864 | case BT_VALUE_TYPE_UNSIGNED_INTEGER: |
476ef981 | 865 | { |
fdd3a2da | 866 | BUF_APPEND(", %svalue=%" PRIu64, |
9c08c816 | 867 | PRFIELD(bt_value_integer_unsigned_get(value))); |
fdd3a2da PP |
868 | break; |
869 | } | |
870 | case BT_VALUE_TYPE_SIGNED_INTEGER: | |
871 | { | |
872 | BUF_APPEND(", %svalue=%" PRId64, | |
9c08c816 | 873 | PRFIELD(bt_value_integer_signed_get(value))); |
476ef981 PP |
874 | break; |
875 | } | |
a373bf69 | 876 | case BT_VALUE_TYPE_REAL: |
476ef981 | 877 | { |
601b0d3c | 878 | double val = bt_value_real_get(value); |
476ef981 | 879 | |
476ef981 PP |
880 | BUF_APPEND(", %svalue=%f", PRFIELD(val)); |
881 | break; | |
882 | } | |
883 | case BT_VALUE_TYPE_STRING: | |
884 | { | |
601b0d3c | 885 | const char *val = bt_value_string_get(value); |
476ef981 | 886 | |
476ef981 PP |
887 | BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val)); |
888 | break; | |
889 | } | |
890 | case BT_VALUE_TYPE_ARRAY: | |
891 | { | |
07208d85 | 892 | int64_t count = bt_value_array_get_size(value); |
476ef981 | 893 | |
f6ccaed9 | 894 | BT_ASSERT(count >= 0); |
476ef981 PP |
895 | BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); |
896 | break; | |
897 | } | |
898 | case BT_VALUE_TYPE_MAP: | |
899 | { | |
07208d85 | 900 | int64_t count = bt_value_map_get_size(value); |
476ef981 | 901 | |
f6ccaed9 | 902 | BT_ASSERT(count >= 0); |
476ef981 PP |
903 | BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); |
904 | break; | |
905 | } | |
906 | default: | |
907 | break; | |
908 | } | |
909 | } | |
910 | ||
6769570a PP |
911 | static inline void format_integer_range_set(char **buf_ch, bool extended, |
912 | const char *prefix, | |
913 | const struct bt_integer_range_set *range_set) | |
914 | { | |
915 | BUF_APPEND(", %srange-count=%u", PRFIELD(range_set->ranges->len)); | |
916 | ||
917 | if (!extended) { | |
918 | return; | |
919 | } | |
920 | ||
921 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(range_set->frozen)); | |
922 | } | |
923 | ||
d6e69534 PP |
924 | static inline void format_message(char **buf_ch, bool extended, |
925 | const char *prefix, const struct bt_message *msg) | |
476ef981 | 926 | { |
879e14e8 | 927 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 PP |
928 | |
929 | BUF_APPEND(", %stype=%s", | |
d6e69534 | 930 | PRFIELD(bt_message_type_string(msg->type))); |
476ef981 PP |
931 | |
932 | if (!extended) { | |
933 | return; | |
934 | } | |
935 | ||
5c563278 | 936 | BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p", |
d6e69534 | 937 | PRFIELD(msg->frozen), PRFIELD(msg->graph)); |
476ef981 | 938 | |
d6e69534 PP |
939 | switch (msg->type) { |
940 | case BT_MESSAGE_TYPE_EVENT: | |
476ef981 | 941 | { |
d6e69534 PP |
942 | const struct bt_message_event *msg_event = |
943 | (const void *) msg; | |
476ef981 | 944 | |
d6e69534 | 945 | if (msg_event->event) { |
d94d92ac | 946 | SET_TMP_PREFIX("event-"); |
5df26c89 PP |
947 | format_event(buf_ch, true, tmp_prefix, |
948 | msg_event->event); | |
d94d92ac PP |
949 | } |
950 | ||
8fc0367b PP |
951 | if (msg_event->default_cs) { |
952 | SET_TMP_PREFIX("default-cs-"); | |
953 | format_clock_snapshot(buf_ch, true, tmp_prefix, | |
954 | msg_event->default_cs); | |
955 | } | |
956 | ||
476ef981 PP |
957 | break; |
958 | } | |
d6e69534 | 959 | case BT_MESSAGE_TYPE_STREAM_BEGINNING: |
5df26c89 | 960 | case BT_MESSAGE_TYPE_STREAM_END: |
476ef981 | 961 | { |
5df26c89 | 962 | const struct bt_message_stream *msg_stream = (const void *) msg; |
476ef981 | 963 | |
d6e69534 | 964 | if (msg_stream->stream) { |
d94d92ac | 965 | SET_TMP_PREFIX("stream-"); |
5df26c89 PP |
966 | format_stream(buf_ch, true, tmp_prefix, |
967 | msg_stream->stream); | |
d94d92ac PP |
968 | } |
969 | ||
5df26c89 | 970 | BUF_APPEND(", %sdefault-cs-state=%s", |
188edac1 SM |
971 | PRFIELD(bt_message_stream_clock_snapshot_state_string( |
972 | msg_stream->default_cs_state))); | |
476ef981 | 973 | |
188edac1 | 974 | if (msg_stream->default_cs_state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) { |
5df26c89 PP |
975 | SET_TMP_PREFIX("default-cs-"); |
976 | format_clock_snapshot(buf_ch, true, tmp_prefix, | |
188edac1 | 977 | msg_stream->default_cs); |
d94d92ac PP |
978 | } |
979 | ||
476ef981 PP |
980 | break; |
981 | } | |
5df26c89 | 982 | case BT_MESSAGE_TYPE_PACKET_BEGINNING: |
d6e69534 | 983 | case BT_MESSAGE_TYPE_PACKET_END: |
476ef981 | 984 | { |
5df26c89 | 985 | const struct bt_message_packet *msg_packet = (const void *) msg; |
476ef981 | 986 | |
d6e69534 | 987 | if (msg_packet->packet) { |
d94d92ac | 988 | SET_TMP_PREFIX("packet-"); |
5df26c89 PP |
989 | format_packet(buf_ch, true, tmp_prefix, |
990 | msg_packet->packet); | |
d94d92ac PP |
991 | } |
992 | ||
8fc0367b PP |
993 | if (msg_packet->default_cs) { |
994 | SET_TMP_PREFIX("default-cs-"); | |
995 | format_clock_snapshot(buf_ch, true, tmp_prefix, | |
996 | msg_packet->default_cs); | |
997 | } | |
998 | ||
476ef981 PP |
999 | break; |
1000 | } | |
4c833281 | 1001 | case BT_MESSAGE_TYPE_DISCARDED_EVENTS: |
4237f1f2 | 1002 | case BT_MESSAGE_TYPE_DISCARDED_PACKETS: |
4c833281 PP |
1003 | { |
1004 | const struct bt_message_discarded_items *msg_disc_items = | |
1005 | (const void *) msg; | |
1006 | ||
1007 | if (msg_disc_items->stream) { | |
1008 | SET_TMP_PREFIX("stream-"); | |
1009 | format_stream(buf_ch, true, tmp_prefix, | |
1010 | msg_disc_items->stream); | |
1011 | } | |
1012 | ||
1013 | if (msg_disc_items->default_begin_cs) { | |
26fc5aed | 1014 | SET_TMP_PREFIX("begin-default-cs-"); |
4c833281 PP |
1015 | format_clock_snapshot(buf_ch, true, tmp_prefix, |
1016 | msg_disc_items->default_begin_cs); | |
1017 | } | |
1018 | ||
1019 | if (msg_disc_items->default_end_cs) { | |
26fc5aed | 1020 | SET_TMP_PREFIX("end-default-cs-"); |
4c833281 PP |
1021 | format_clock_snapshot(buf_ch, true, tmp_prefix, |
1022 | msg_disc_items->default_end_cs); | |
1023 | } | |
1024 | ||
1025 | if (msg_disc_items->count.base.avail) { | |
1026 | BUF_APPEND(", %scount=%" PRIu64, | |
1027 | PRFIELD(msg_disc_items->count.value)); | |
1028 | } | |
1029 | ||
1030 | break; | |
1031 | } | |
476ef981 PP |
1032 | default: |
1033 | break; | |
1034 | } | |
1035 | } | |
1036 | ||
1037 | static inline void format_plugin_so_shared_lib_handle(char **buf_ch, | |
1038 | const char *prefix, | |
862ca4ed | 1039 | const struct bt_plugin_so_shared_lib_handle *handle) |
476ef981 PP |
1040 | { |
1041 | BUF_APPEND(", %saddr=%p", PRFIELD(handle)); | |
1042 | ||
1043 | if (handle->path) { | |
d94d92ac | 1044 | BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle->path)); |
476ef981 PP |
1045 | } |
1046 | } | |
1047 | ||
1048 | static inline void format_component_class(char **buf_ch, bool extended, | |
862ca4ed PP |
1049 | const char *prefix, |
1050 | const struct bt_component_class *comp_class) | |
476ef981 | 1051 | { |
879e14e8 | 1052 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 PP |
1053 | |
1054 | BUF_APPEND(", %stype=%s, %sname=\"%s\"", | |
1055 | PRFIELD(bt_component_class_type_string(comp_class->type)), | |
d94d92ac | 1056 | PRFIELD_GSTRING(comp_class->name)); |
476ef981 PP |
1057 | |
1058 | if (comp_class->description) { | |
1059 | BUF_APPEND(", %spartial-descr=\"%.32s\"", | |
d94d92ac | 1060 | PRFIELD_GSTRING(comp_class->description)); |
476ef981 PP |
1061 | } |
1062 | ||
1063 | if (!extended) { | |
1064 | return; | |
1065 | } | |
1066 | ||
1067 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class->frozen)); | |
1068 | ||
1069 | if (comp_class->so_handle) { | |
1070 | SET_TMP_PREFIX("so-handle-"); | |
1071 | format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix, | |
1072 | comp_class->so_handle); | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | static inline void format_component(char **buf_ch, bool extended, | |
862ca4ed | 1077 | const char *prefix, const struct bt_component *component) |
476ef981 | 1078 | { |
879e14e8 | 1079 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 | 1080 | |
e874da19 PP |
1081 | BUF_APPEND(", %sname=\"%s\", %slog-level=%s", |
1082 | PRFIELD_GSTRING(component->name), | |
1083 | PRFIELD(bt_common_logging_level_string(component->log_level))); | |
d94d92ac PP |
1084 | |
1085 | if (component->class) { | |
1086 | SET_TMP_PREFIX("class-"); | |
1087 | format_component_class(buf_ch, extended, tmp_prefix, | |
1088 | component->class); | |
1089 | } | |
476ef981 PP |
1090 | |
1091 | if (!extended) { | |
1092 | return; | |
1093 | } | |
1094 | ||
312c056a PP |
1095 | if (component->input_ports) { |
1096 | BUF_APPEND(", %sinput-port-count=%u", | |
1097 | PRFIELD(component->input_ports->len)); | |
1098 | } | |
1099 | ||
1100 | if (component->output_ports) { | |
1101 | BUF_APPEND(", %soutput-port-count=%u", | |
1102 | PRFIELD(component->output_ports->len)); | |
1103 | } | |
476ef981 PP |
1104 | } |
1105 | ||
1106 | static inline void format_port(char **buf_ch, bool extended, | |
862ca4ed | 1107 | const char *prefix, const struct bt_port *port) |
476ef981 | 1108 | { |
879e14e8 | 1109 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 PP |
1110 | |
1111 | BUF_APPEND(", %stype=%s, %sname=\"%s\"", | |
1112 | PRFIELD(bt_port_type_string(port->type)), | |
d94d92ac | 1113 | PRFIELD_GSTRING(port->name)); |
476ef981 PP |
1114 | |
1115 | if (!extended) { | |
1116 | return; | |
1117 | } | |
1118 | ||
1119 | if (port->connection) { | |
1120 | SET_TMP_PREFIX("conn-"); | |
1121 | format_connection(buf_ch, false, tmp_prefix, port->connection); | |
1122 | } | |
1123 | } | |
1124 | ||
1125 | static inline void format_connection(char **buf_ch, bool extended, | |
862ca4ed | 1126 | const char *prefix, const struct bt_connection *connection) |
476ef981 | 1127 | { |
879e14e8 | 1128 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 PP |
1129 | |
1130 | if (!extended) { | |
1131 | return; | |
1132 | } | |
1133 | ||
1134 | if (connection->upstream_port) { | |
1135 | SET_TMP_PREFIX("upstream-port-"); | |
1136 | format_port(buf_ch, false, tmp_prefix, | |
1137 | connection->upstream_port); | |
1138 | } | |
1139 | ||
1140 | if (connection->downstream_port) { | |
1141 | SET_TMP_PREFIX("downstream-port-"); | |
1142 | format_port(buf_ch, false, tmp_prefix, | |
1143 | connection->downstream_port); | |
1144 | } | |
1145 | } | |
1146 | ||
1147 | static inline void format_graph(char **buf_ch, bool extended, | |
862ca4ed | 1148 | const char *prefix, const struct bt_graph *graph) |
476ef981 | 1149 | { |
879e14e8 | 1150 | char tmp_prefix[TMP_PREFIX_LEN]; |
5c563278 | 1151 | |
9b4f9b42 | 1152 | BUF_APPEND(", %scan-consume=%d, %sconfig-state=%s", |
5badd463 PP |
1153 | PRFIELD(graph->can_consume), |
1154 | PRFIELD(bt_graph_configuration_state_string(graph->config_state))); | |
476ef981 PP |
1155 | |
1156 | if (!extended) { | |
1157 | return; | |
1158 | } | |
1159 | ||
312c056a PP |
1160 | if (graph->components) { |
1161 | BUF_APPEND(", %scomp-count=%u", | |
1162 | PRFIELD(graph->components->len)); | |
1163 | } | |
1164 | ||
1165 | if (graph->connections) { | |
1166 | BUF_APPEND(", %sconn-count=%u", | |
1167 | PRFIELD(graph->connections->len)); | |
1168 | } | |
5c563278 PP |
1169 | |
1170 | SET_TMP_PREFIX("en-pool-"); | |
9a6502b6 | 1171 | format_object_pool(buf_ch, extended, tmp_prefix, |
d6e69534 | 1172 | &graph->event_msg_pool); |
5c563278 | 1173 | SET_TMP_PREFIX("pbn-pool-"); |
9a6502b6 | 1174 | format_object_pool(buf_ch, extended, tmp_prefix, |
d6e69534 | 1175 | &graph->packet_begin_msg_pool); |
5c563278 | 1176 | SET_TMP_PREFIX("pen-pool-"); |
9a6502b6 | 1177 | format_object_pool(buf_ch, extended, tmp_prefix, |
d6e69534 | 1178 | &graph->packet_end_msg_pool); |
476ef981 PP |
1179 | } |
1180 | ||
d6e69534 | 1181 | static inline void format_message_iterator(char **buf_ch, |
476ef981 | 1182 | bool extended, const char *prefix, |
d6e69534 | 1183 | const struct bt_message_iterator *iterator) |
476ef981 | 1184 | { |
879e14e8 | 1185 | char tmp_prefix[TMP_PREFIX_LEN]; |
6c373cc9 PP |
1186 | const struct bt_self_component_port_input_message_iterator * |
1187 | port_in_iter = (const void *) iterator; | |
476ef981 | 1188 | |
6c373cc9 PP |
1189 | if (port_in_iter->upstream_component) { |
1190 | SET_TMP_PREFIX("upstream-comp-"); | |
1191 | format_component(buf_ch, false, tmp_prefix, | |
1192 | port_in_iter->upstream_component); | |
476ef981 PP |
1193 | } |
1194 | ||
6c373cc9 PP |
1195 | if (!extended) { |
1196 | goto end; | |
476ef981 | 1197 | } |
476ef981 | 1198 | |
6c373cc9 PP |
1199 | if (port_in_iter->upstream_port) { |
1200 | SET_TMP_PREFIX("upstream-port-"); | |
1201 | format_port(buf_ch, false, tmp_prefix, | |
1202 | port_in_iter->upstream_port); | |
476ef981 | 1203 | } |
6c373cc9 PP |
1204 | |
1205 | if (port_in_iter->connection) { | |
1206 | SET_TMP_PREFIX("upstream-conn-"); | |
1207 | format_connection(buf_ch, false, tmp_prefix, | |
1208 | port_in_iter->connection); | |
476ef981 | 1209 | } |
6c373cc9 PP |
1210 | |
1211 | end: | |
1212 | return; | |
476ef981 PP |
1213 | } |
1214 | ||
1215 | static inline void format_plugin(char **buf_ch, bool extended, | |
92fed4e1 | 1216 | const char *prefix, const struct bt_plugin *plugin) |
476ef981 | 1217 | { |
879e14e8 | 1218 | char tmp_prefix[TMP_PREFIX_LEN]; |
476ef981 PP |
1219 | |
1220 | BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin->type))); | |
1221 | ||
1222 | if (plugin->info.path_set) { | |
1223 | BUF_APPEND(", %spath=\"%s\"", | |
d94d92ac | 1224 | PRFIELD_GSTRING(plugin->info.path)); |
476ef981 PP |
1225 | } |
1226 | ||
1227 | if (plugin->info.name_set) { | |
1228 | BUF_APPEND(", %sname=\"%s\"", | |
d94d92ac | 1229 | PRFIELD_GSTRING(plugin->info.name)); |
476ef981 PP |
1230 | } |
1231 | ||
1232 | if (!extended) { | |
1233 | return; | |
1234 | } | |
1235 | ||
1236 | if (plugin->info.author_set) { | |
1237 | BUF_APPEND(", %sauthor=\"%s\"", | |
d94d92ac | 1238 | PRFIELD_GSTRING(plugin->info.author)); |
476ef981 PP |
1239 | } |
1240 | ||
1241 | if (plugin->info.license_set) { | |
1242 | BUF_APPEND(", %slicense=\"%s\"", | |
d94d92ac | 1243 | PRFIELD_GSTRING(plugin->info.license)); |
476ef981 PP |
1244 | } |
1245 | ||
1246 | if (plugin->info.version_set) { | |
1247 | BUF_APPEND(", %sversion=%u.%u.%u%s", | |
1248 | PRFIELD(plugin->info.version.major), | |
1249 | plugin->info.version.minor, | |
1250 | plugin->info.version.patch, | |
1251 | plugin->info.version.extra ? | |
1252 | plugin->info.version.extra->str : ""); | |
1253 | } | |
1254 | ||
d94d92ac PP |
1255 | BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, " |
1256 | "%ssink-comp-class-count=%u", | |
1257 | PRFIELD(plugin->src_comp_classes->len), | |
1258 | PRFIELD(plugin->flt_comp_classes->len), | |
1259 | PRFIELD(plugin->sink_comp_classes->len)); | |
476ef981 PP |
1260 | |
1261 | if (plugin->spec_data) { | |
862ca4ed PP |
1262 | const struct bt_plugin_so_spec_data *spec_data = |
1263 | (const void *) plugin->spec_data; | |
476ef981 PP |
1264 | |
1265 | if (spec_data->shared_lib_handle) { | |
1266 | SET_TMP_PREFIX("so-handle-"); | |
1267 | format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix, | |
1268 | spec_data->shared_lib_handle); | |
1269 | } | |
1270 | } | |
1271 | } | |
1272 | ||
553c4bab PP |
1273 | static inline void format_error_cause(char **buf_ch, bool extended, |
1274 | const char *prefix, const struct bt_error_cause *cause) | |
1275 | { | |
1276 | const struct bt_error_cause_component_class_id *comp_class_id = NULL; | |
1277 | ||
1278 | BUF_APPEND(", %sactor-type=%s, %smodule-name=\"%s\"", | |
1279 | PRFIELD(bt_error_cause_actor_type_string(cause->actor_type)), | |
1280 | PRFIELD_GSTRING(cause->module_name)); | |
1281 | ||
1282 | if (!extended) { | |
1283 | return; | |
1284 | } | |
1285 | ||
1286 | BUF_APPEND(", %spartial-msg=\"%.32s\"", | |
1287 | PRFIELD_GSTRING(cause->message)); | |
1288 | ||
1289 | switch (cause->actor_type) { | |
1290 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT: | |
1291 | { | |
1292 | const struct bt_error_cause_component_actor *spec_cause = | |
1293 | (const void *) cause; | |
1294 | ||
1295 | BUF_APPEND(", %scomp-name=\"%s\"", | |
1296 | PRFIELD_GSTRING(spec_cause->comp_name)); | |
1297 | comp_class_id = &spec_cause->comp_class_id; | |
1298 | break; | |
1299 | } | |
1300 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS: | |
1301 | { | |
1302 | const struct bt_error_cause_component_class_actor *spec_cause = | |
1303 | (const void *) cause; | |
1304 | ||
1305 | comp_class_id = &spec_cause->comp_class_id; | |
1306 | break; | |
1307 | } | |
1308 | case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR: | |
1309 | { | |
1310 | const struct bt_error_cause_message_iterator_actor *spec_cause = | |
1311 | (const void *) cause; | |
1312 | ||
1313 | BUF_APPEND(", %scomp-name=\"%s\", %scomp-out-port-name=\"%s\"", | |
1314 | PRFIELD_GSTRING(spec_cause->comp_name), | |
1315 | PRFIELD_GSTRING(spec_cause->output_port_name)); | |
1316 | comp_class_id = &spec_cause->comp_class_id; | |
1317 | break; | |
1318 | } | |
1319 | default: | |
1320 | break; | |
1321 | } | |
1322 | ||
1323 | if (comp_class_id) { | |
1324 | BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", " | |
1325 | "%splugin-name=\"%s\"", | |
1326 | PRFIELD(bt_component_class_type_string( | |
1327 | comp_class_id->type)), | |
1328 | PRFIELD_GSTRING(comp_class_id->name), | |
1329 | PRFIELD_GSTRING(comp_class_id->plugin_name)); | |
1330 | } | |
1331 | } | |
1332 | ||
476ef981 PP |
1333 | static inline void handle_conversion_specifier_bt(void *priv_data, |
1334 | char **buf_ch, size_t avail_size, | |
1335 | const char **out_fmt_ch, va_list *args) | |
1336 | { | |
1337 | const char *fmt_ch = *out_fmt_ch; | |
1338 | bool extended = false; | |
1339 | char prefix[64]; | |
1340 | char *prefix_ch = prefix; | |
862ca4ed | 1341 | const void *obj; |
476ef981 PP |
1342 | |
1343 | /* skip "%!" */ | |
1344 | fmt_ch += 2; | |
1345 | ||
44c440bc PP |
1346 | if (*fmt_ch == 'u') { |
1347 | /* UUID */ | |
1348 | obj = va_arg(*args, void *); | |
1349 | format_uuid(buf_ch, obj); | |
1350 | goto update_fmt; | |
1351 | } | |
1352 | ||
476ef981 PP |
1353 | if (*fmt_ch == '[') { |
1354 | /* local prefix */ | |
1355 | fmt_ch++; | |
1356 | ||
1357 | while (true) { | |
1358 | if (*fmt_ch == ']') { | |
1359 | *prefix_ch = '\0'; | |
1360 | fmt_ch++; | |
1361 | break; | |
1362 | } | |
1363 | ||
1364 | *prefix_ch = *fmt_ch; | |
1365 | prefix_ch++; | |
1366 | fmt_ch++; | |
1367 | } | |
1368 | } | |
1369 | ||
1370 | *prefix_ch = '\0'; | |
1371 | ||
1372 | if (*fmt_ch == '+') { | |
1373 | extended = true; | |
1374 | fmt_ch++; | |
1375 | } | |
1376 | ||
1377 | obj = va_arg(*args, void *); | |
1378 | BUF_APPEND("%saddr=%p", prefix, obj); | |
1379 | ||
1380 | if (!obj) { | |
1381 | goto update_fmt; | |
1382 | } | |
1383 | ||
cb6f1f7d PP |
1384 | switch (*fmt_ch) { |
1385 | case 'F': | |
5cd6d0e5 | 1386 | format_field_class(buf_ch, extended, prefix, obj); |
476ef981 | 1387 | break; |
cb6f1f7d PP |
1388 | case 'f': |
1389 | format_field(buf_ch, extended, prefix, obj); | |
1390 | break; | |
1391 | case 'P': | |
1392 | format_field_path(buf_ch, extended, prefix, obj); | |
1393 | break; | |
1394 | case 'E': | |
1395 | format_event_class(buf_ch, extended, prefix, obj); | |
1396 | break; | |
1397 | case 'e': | |
1398 | format_event(buf_ch, extended, prefix, obj); | |
1399 | break; | |
1400 | case 'S': | |
1401 | format_stream_class(buf_ch, extended, prefix, obj); | |
476ef981 | 1402 | break; |
cb6f1f7d PP |
1403 | case 's': |
1404 | format_stream(buf_ch, extended, prefix, obj); | |
1405 | break; | |
1406 | case 'a': | |
1407 | format_packet(buf_ch, extended, prefix, obj); | |
1408 | break; | |
1409 | case 't': | |
1410 | format_trace(buf_ch, extended, prefix, obj); | |
1411 | break; | |
862ca4ed PP |
1412 | case 'T': |
1413 | format_trace_class(buf_ch, extended, prefix, obj); | |
1414 | break; | |
cb6f1f7d PP |
1415 | case 'K': |
1416 | format_clock_class(buf_ch, extended, prefix, obj); | |
1417 | break; | |
1418 | case 'k': | |
605e1019 | 1419 | format_clock_snapshot(buf_ch, extended, prefix, obj); |
cb6f1f7d PP |
1420 | break; |
1421 | case 'v': | |
1422 | format_value(buf_ch, extended, prefix, obj); | |
1423 | break; | |
6769570a PP |
1424 | case 'R': |
1425 | format_integer_range_set(buf_ch, extended, prefix, obj); | |
1426 | break; | |
cb6f1f7d | 1427 | case 'n': |
d6e69534 | 1428 | format_message(buf_ch, extended, prefix, obj); |
cb6f1f7d PP |
1429 | break; |
1430 | case 'i': | |
d6e69534 | 1431 | format_message_iterator(buf_ch, extended, prefix, obj); |
cb6f1f7d PP |
1432 | break; |
1433 | case 'C': | |
1434 | format_component_class(buf_ch, extended, prefix, obj); | |
1435 | break; | |
1436 | case 'c': | |
1437 | format_component(buf_ch, extended, prefix, obj); | |
1438 | break; | |
1439 | case 'p': | |
1440 | format_port(buf_ch, extended, prefix, obj); | |
1441 | break; | |
1442 | case 'x': | |
1443 | format_connection(buf_ch, extended, prefix, obj); | |
1444 | break; | |
44c440bc | 1445 | case 'l': |
cb6f1f7d PP |
1446 | format_plugin(buf_ch, extended, prefix, obj); |
1447 | break; | |
1448 | case 'g': | |
1449 | format_graph(buf_ch, extended, prefix, obj); | |
1450 | break; | |
b70d57a1 PP |
1451 | case 'z': |
1452 | format_interrupter(buf_ch, extended, prefix, obj); | |
1453 | break; | |
cb6f1f7d PP |
1454 | case 'o': |
1455 | format_object_pool(buf_ch, extended, prefix, obj); | |
1456 | break; | |
1457 | case 'O': | |
1458 | format_object(buf_ch, extended, prefix, obj); | |
1459 | break; | |
553c4bab PP |
1460 | case 'r': |
1461 | format_error_cause(buf_ch, extended, prefix, obj); | |
1462 | break; | |
cb6f1f7d PP |
1463 | default: |
1464 | abort(); | |
476ef981 PP |
1465 | } |
1466 | ||
1467 | update_fmt: | |
1468 | fmt_ch++; | |
1469 | *out_fmt_ch = fmt_ch; | |
1470 | } | |
1471 | ||
476ef981 PP |
1472 | void bt_lib_log(const char *func, const char *file, unsigned line, |
1473 | int lvl, const char *tag, const char *fmt, ...) | |
1474 | { | |
1475 | va_list args; | |
1476 | ||
f6ccaed9 | 1477 | BT_ASSERT(fmt); |
476ef981 PP |
1478 | va_start(args, fmt); |
1479 | bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', | |
1480 | handle_conversion_specifier_bt, NULL, fmt, &args); | |
1481 | va_end(args); | |
1482 | _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf); | |
1483 | } | |
3cd4c495 PP |
1484 | |
1485 | void bt_lib_maybe_log_and_append_cause(const char *func, const char *file, | |
1486 | unsigned line, int lvl, const char *tag, | |
1487 | const char *fmt, ...) | |
1488 | { | |
1489 | va_list args; | |
1490 | bt_current_thread_error_append_cause_status status; | |
1491 | ||
1492 | BT_ASSERT(fmt); | |
1493 | va_start(args, fmt); | |
1494 | bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', | |
1495 | handle_conversion_specifier_bt, NULL, fmt, &args); | |
1496 | va_end(args); | |
1497 | ||
1498 | /* Log conditionally, but always append the error cause */ | |
1499 | if (BT_LOG_ON(lvl)) { | |
1500 | _bt_log_write_d(func, file, line, lvl, tag, "%s", | |
1501 | lib_logging_buf); | |
1502 | } | |
1503 | ||
1504 | status = bt_current_thread_error_append_cause_from_unknown( | |
1505 | "Babeltrace library", file, line, "%s", lib_logging_buf); | |
1506 | if (status) { | |
1507 | /* | |
1508 | * Worst case: this error cause is not appended to the | |
1509 | * current thread's error. | |
1510 | * | |
1511 | * We can accept this as it's an almost impossible | |
1512 | * scenario and returning an error here would mean you | |
1513 | * need to check the return value of each | |
1514 | * BT_LIB_LOG*_APPEND_CAUSE() macro and that would be | |
1515 | * cumbersome. | |
1516 | */ | |
1517 | BT_LOGE("Cannot append error cause to current thread's " | |
1518 | "error object: status=%s", | |
1519 | bt_common_func_status_string(status)); | |
1520 | } | |
1521 | } |