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