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