Commit | Line | Data |
---|---|---|
476ef981 PP |
1 | /* |
2 | * Copyright 2018 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | * of this software and associated documentation files (the "Software"), to deal | |
6 | * in the Software without restriction, including without limitation the rights | |
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | * copies of the Software, and to permit persons to whom the Software is | |
9 | * furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
20 | * SOFTWARE. | |
21 | */ | |
22 | ||
3dca2276 PP |
23 | #define BT_LOG_TAG "LIB-LOGGING" |
24 | ||
476ef981 PP |
25 | #include <stdarg.h> |
26 | #include <stdio.h> | |
27 | #include <stdlib.h> | |
28 | #include <string.h> | |
29 | #include <inttypes.h> | |
30 | #include <stdint.h> | |
476ef981 PP |
31 | #include <wchar.h> |
32 | #include <glib.h> | |
317e35ec PP |
33 | #include <babeltrace/lib-logging-internal.h> |
34 | #include <babeltrace/assert-pre-internal.h> | |
476ef981 PP |
35 | #include <babeltrace/common-internal.h> |
36 | #include <babeltrace/lib-logging-internal.h> | |
c319d0ae PP |
37 | #include <babeltrace/value-internal.h> |
38 | #include <babeltrace/value-internal.h> | |
312c056a | 39 | #include <babeltrace/object-pool-internal.h> |
c319d0ae PP |
40 | #include <babeltrace/trace-ir/field-class-internal.h> |
41 | #include <babeltrace/trace-ir/field-internal.h> | |
577dc45a | 42 | #include <babeltrace/trace-ir/event-class-internal.h> |
3b4c8c43 | 43 | #include <babeltrace/trace-ir/event-const.h> |
577dc45a | 44 | #include <babeltrace/trace-ir/event-internal.h> |
3b4c8c43 | 45 | #include <babeltrace/trace-ir/packet-const.h> |
577dc45a PP |
46 | #include <babeltrace/trace-ir/packet-internal.h> |
47 | #include <babeltrace/trace-ir/stream-class-internal.h> | |
48 | #include <babeltrace/trace-ir/stream-internal.h> | |
3b4c8c43 | 49 | #include <babeltrace/trace-ir/stream-const.h> |
577dc45a | 50 | #include <babeltrace/trace-ir/trace-internal.h> |
3b4c8c43 | 51 | #include <babeltrace/trace-ir/trace-class-internal.h> |
577dc45a | 52 | #include <babeltrace/trace-ir/clock-class-internal.h> |
b1824349 | 53 | #include <babeltrace/trace-ir/clock-snapshot-internal.h> |
577dc45a PP |
54 | #include <babeltrace/trace-ir/field-path-internal.h> |
55 | #include <babeltrace/trace-ir/utils-internal.h> | |
476ef981 PP |
56 | #include <babeltrace/graph/component-class-internal.h> |
57 | #include <babeltrace/graph/component-class-sink-colander-internal.h> | |
58 | #include <babeltrace/graph/component-filter-internal.h> | |
59 | #include <babeltrace/graph/component-internal.h> | |
60 | #include <babeltrace/graph/component-sink-internal.h> | |
61 | #include <babeltrace/graph/component-source-internal.h> | |
62 | #include <babeltrace/graph/connection-internal.h> | |
63 | #include <babeltrace/graph/graph-internal.h> | |
c14831f0 PP |
64 | #include <babeltrace/graph/message-event-internal.h> |
65 | #include <babeltrace/graph/message-inactivity-internal.h> | |
66 | #include <babeltrace/graph/message-internal.h> | |
67 | #include <babeltrace/graph/message-iterator-internal.h> | |
68 | #include <babeltrace/graph/message-packet-internal.h> | |
69 | #include <babeltrace/graph/message-stream-internal.h> | |
2accc83a | 70 | #include <babeltrace/graph/message-stream-activity-internal.h> |
476ef981 PP |
71 | #include <babeltrace/graph/port-internal.h> |
72 | #include <babeltrace/plugin/plugin-internal.h> | |
73 | #include <babeltrace/plugin/plugin-so-internal.h> | |
476ef981 PP |
74 | |
75 | #define LIB_LOGGING_BUF_SIZE (4096 * 4) | |
76 | ||
77 | static char __thread lib_logging_buf[LIB_LOGGING_BUF_SIZE]; | |
78 | ||
79 | #define BUF_APPEND(_fmt, ...) \ | |
80 | do { \ | |
81 | int _count; \ | |
82 | size_t _size = LIB_LOGGING_BUF_SIZE - \ | |
83 | (size_t) (*buf_ch - lib_logging_buf); \ | |
84 | _count = snprintf(*buf_ch, _size, (_fmt), __VA_ARGS__); \ | |
f6ccaed9 | 85 | BT_ASSERT(_count >= 0); \ |
476ef981 PP |
86 | *buf_ch += MIN(_count, _size); \ |
87 | if (*buf_ch >= lib_logging_buf + LIB_LOGGING_BUF_SIZE - 1) { \ | |
88 | return; \ | |
89 | } \ | |
90 | } while (0) | |
91 | ||
92 | #define BUF_APPEND_UUID(_uuid) \ | |
61f59358 PP |
93 | do { \ |
94 | BUF_APPEND(", %suuid=", prefix); \ | |
95 | format_uuid(buf_ch, (_uuid)); \ | |
96 | } while (0) | |
476ef981 PP |
97 | |
98 | #define PRFIELD(_expr) prefix, (_expr) | |
99 | ||
d27a81b2 PP |
100 | #define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL) |
101 | ||
476ef981 PP |
102 | #define SET_TMP_PREFIX(_prefix2) \ |
103 | do { \ | |
104 | strcpy(tmp_prefix, prefix); \ | |
105 | strcat(tmp_prefix, (_prefix2)); \ | |
106 | } while (0) | |
107 | ||
108 | static inline void format_component(char **buf_ch, bool extended, | |
3b4c8c43 | 109 | const char *prefix, const struct bt_component *component); |
476ef981 PP |
110 | |
111 | static inline void format_port(char **buf_ch, bool extended, | |
3b4c8c43 | 112 | const char *prefix, const struct bt_port *port); |
476ef981 PP |
113 | |
114 | static inline void format_connection(char **buf_ch, bool extended, | |
3b4c8c43 | 115 | const char *prefix, const struct bt_connection *connection); |
476ef981 | 116 | |
b1824349 PP |
117 | static inline void format_clock_snapshot(char **buf_ch, bool extended, |
118 | const char *prefix, const struct bt_clock_snapshot *clock_snapshot); | |
e22b45d0 | 119 | |
61f59358 | 120 | static inline void format_field_path(char **buf_ch, bool extended, |
3b4c8c43 | 121 | const char *prefix, const struct bt_field_path *field_path); |
61f59358 | 122 | |
3fea54f6 | 123 | static inline void format_object(char **buf_ch, bool extended, |
3b4c8c43 | 124 | const char *prefix, const struct bt_object *obj) |
476ef981 | 125 | { |
3fea54f6 | 126 | BUF_APPEND(", %sref-count=%llu", prefix, obj->ref_count); |
476ef981 PP |
127 | } |
128 | ||
61f59358 | 129 | static inline void format_uuid(char **buf_ch, bt_uuid uuid) |
e22b45d0 | 130 | { |
61f59358 PP |
131 | BUF_APPEND("\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"", |
132 | (unsigned int) uuid[0], | |
133 | (unsigned int) uuid[1], | |
134 | (unsigned int) uuid[2], | |
135 | (unsigned int) uuid[3], | |
136 | (unsigned int) uuid[4], | |
137 | (unsigned int) uuid[5], | |
138 | (unsigned int) uuid[6], | |
139 | (unsigned int) uuid[7], | |
140 | (unsigned int) uuid[8], | |
141 | (unsigned int) uuid[9], | |
142 | (unsigned int) uuid[10], | |
143 | (unsigned int) uuid[11], | |
144 | (unsigned int) uuid[12], | |
145 | (unsigned int) uuid[13], | |
146 | (unsigned int) uuid[14], | |
147 | (unsigned int) uuid[15]); | |
e22b45d0 PP |
148 | } |
149 | ||
312c056a | 150 | static inline void format_object_pool(char **buf_ch, bool extended, |
3b4c8c43 | 151 | const char *prefix, const struct bt_object_pool *pool) |
312c056a PP |
152 | { |
153 | BUF_APPEND(", %ssize=%zu", PRFIELD(pool->size)); | |
154 | ||
155 | if (pool->objects) { | |
156 | BUF_APPEND(", %scap=%u", PRFIELD(pool->objects->len)); | |
157 | } | |
158 | } | |
159 | ||
c82deff2 | 160 | static inline void format_integer_field_class(char **buf_ch, |
61f59358 | 161 | bool extended, const char *prefix, |
3b4c8c43 | 162 | const struct bt_field_class *field_class) |
61f59358 | 163 | { |
3b4c8c43 PP |
164 | const struct bt_field_class_integer *int_fc = |
165 | (const void *) field_class; | |
61f59358 PP |
166 | |
167 | BUF_APPEND(", %srange-size=%" PRIu64 ", %sbase=%s", | |
c82deff2 PP |
168 | PRFIELD(int_fc->range), |
169 | PRFIELD(bt_common_field_class_integer_preferred_display_base_string(int_fc->base))); | |
61f59358 PP |
170 | } |
171 | ||
c82deff2 | 172 | static inline void format_array_field_class(char **buf_ch, |
61f59358 | 173 | bool extended, const char *prefix, |
3b4c8c43 | 174 | const struct bt_field_class *field_class) |
61f59358 | 175 | { |
3b4c8c43 PP |
176 | const struct bt_field_class_array *array_fc = |
177 | (const void *) field_class; | |
61f59358 | 178 | |
63749226 | 179 | BUF_APPEND(", %selement-fc-addr=%p, %selement-fc-type=%s", |
c82deff2 | 180 | PRFIELD(array_fc->element_fc), |
63749226 | 181 | PRFIELD(bt_common_field_class_type_string(array_fc->element_fc->type))); |
61f59358 PP |
182 | } |
183 | ||
c82deff2 | 184 | static inline void format_field_class(char **buf_ch, bool extended, |
3b4c8c43 | 185 | const char *prefix, const struct bt_field_class *field_class) |
476ef981 | 186 | { |
61f59358 PP |
187 | char tmp_prefix[64]; |
188 | ||
63749226 PP |
189 | BUF_APPEND(", %stype=%s", |
190 | PRFIELD(bt_common_field_class_type_string(field_class->type))); | |
476ef981 PP |
191 | |
192 | if (extended) { | |
c82deff2 | 193 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(field_class->frozen)); |
3b4c8c43 PP |
194 | BUF_APPEND(", %sis-part-of-trace-class=%d", |
195 | PRFIELD(field_class->part_of_trace_class)); | |
476ef981 PP |
196 | } else { |
197 | return; | |
198 | } | |
199 | ||
63749226 PP |
200 | switch (field_class->type) { |
201 | case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: | |
202 | case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: | |
476ef981 | 203 | { |
c82deff2 | 204 | format_integer_field_class(buf_ch, extended, prefix, field_class); |
476ef981 PP |
205 | break; |
206 | } | |
63749226 | 207 | case BT_FIELD_CLASS_TYPE_REAL: |
476ef981 | 208 | { |
3b4c8c43 | 209 | const struct bt_field_class_real *real_fc = (void *) field_class; |
476ef981 | 210 | |
61f59358 | 211 | BUF_APPEND(", %sis-single-precision=%d", |
c82deff2 | 212 | PRFIELD(real_fc->is_single_precision)); |
476ef981 PP |
213 | break; |
214 | } | |
63749226 PP |
215 | case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: |
216 | case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: | |
476ef981 | 217 | { |
3b4c8c43 PP |
218 | const struct bt_field_class_enumeration *enum_fc = |
219 | (const void *) field_class; | |
476ef981 | 220 | |
c82deff2 | 221 | format_integer_field_class(buf_ch, extended, prefix, field_class); |
476ef981 | 222 | BUF_APPEND(", %smapping-count=%u", |
c82deff2 | 223 | PRFIELD(enum_fc->mappings->len)); |
476ef981 PP |
224 | break; |
225 | } | |
63749226 | 226 | case BT_FIELD_CLASS_TYPE_STRUCTURE: |
476ef981 | 227 | { |
3b4c8c43 PP |
228 | const struct bt_field_class_structure *struct_fc = |
229 | (const void *) field_class; | |
61f59358 | 230 | |
c82deff2 | 231 | if (struct_fc->common.named_fcs) { |
61f59358 | 232 | BUF_APPEND(", %smember-count=%u", |
c82deff2 | 233 | PRFIELD(struct_fc->common.named_fcs->len)); |
61f59358 | 234 | } |
476ef981 | 235 | |
476ef981 PP |
236 | break; |
237 | } | |
63749226 | 238 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: |
476ef981 | 239 | { |
3b4c8c43 PP |
240 | const struct bt_field_class_static_array *array_fc = |
241 | (const void *) field_class; | |
476ef981 | 242 | |
c82deff2 PP |
243 | format_array_field_class(buf_ch, extended, prefix, field_class); |
244 | BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_fc->length)); | |
476ef981 PP |
245 | break; |
246 | } | |
63749226 | 247 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: |
476ef981 | 248 | { |
3b4c8c43 PP |
249 | const struct bt_field_class_dynamic_array *array_fc = |
250 | (const void *) field_class; | |
61f59358 | 251 | |
c82deff2 | 252 | format_array_field_class(buf_ch, extended, prefix, field_class); |
61f59358 | 253 | |
c82deff2 PP |
254 | if (array_fc->length_fc) { |
255 | SET_TMP_PREFIX("length-fc-"); | |
256 | format_field_class(buf_ch, extended, tmp_prefix, | |
257 | array_fc->length_fc); | |
61f59358 PP |
258 | } |
259 | ||
c82deff2 | 260 | if (array_fc->length_field_path) { |
61f59358 PP |
261 | SET_TMP_PREFIX("length-field-path-"); |
262 | format_field_path(buf_ch, extended, tmp_prefix, | |
c82deff2 | 263 | array_fc->length_field_path); |
61f59358 | 264 | } |
476ef981 | 265 | |
476ef981 PP |
266 | break; |
267 | } | |
63749226 | 268 | case BT_FIELD_CLASS_TYPE_VARIANT: |
476ef981 | 269 | { |
3b4c8c43 PP |
270 | const struct bt_field_class_variant *var_fc = |
271 | (const void *) field_class; | |
61f59358 | 272 | |
c82deff2 | 273 | if (var_fc->common.named_fcs) { |
61f59358 | 274 | BUF_APPEND(", %soption-count=%u", |
c82deff2 | 275 | PRFIELD(var_fc->common.named_fcs->len)); |
61f59358 PP |
276 | } |
277 | ||
c82deff2 PP |
278 | if (var_fc->selector_fc) { |
279 | SET_TMP_PREFIX("selector-fc-"); | |
280 | format_field_class(buf_ch, extended, tmp_prefix, | |
281 | var_fc->selector_fc); | |
61f59358 PP |
282 | } |
283 | ||
c82deff2 | 284 | if (var_fc->selector_field_path) { |
61f59358 PP |
285 | SET_TMP_PREFIX("selector-field-path-"); |
286 | format_field_path(buf_ch, extended, tmp_prefix, | |
c82deff2 | 287 | var_fc->selector_field_path); |
61f59358 | 288 | } |
476ef981 | 289 | |
476ef981 PP |
290 | break; |
291 | } | |
292 | default: | |
293 | break; | |
294 | } | |
295 | } | |
296 | ||
cb6f1f7d | 297 | static inline void format_field_integer_extended(char **buf_ch, |
3b4c8c43 | 298 | const char *prefix, const struct bt_field *field) |
476ef981 | 299 | { |
3b4c8c43 PP |
300 | const struct bt_field_integer *integer = (void *) field; |
301 | const struct bt_field_class_integer *field_class = | |
302 | (void *) field->class; | |
476ef981 PP |
303 | const char *fmt = NULL; |
304 | ||
c82deff2 | 305 | BT_ASSERT(field_class); |
312c056a | 306 | |
c82deff2 | 307 | if (field_class->base == BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL) { |
476ef981 | 308 | fmt = ", %svalue=%" PRIo64; |
c82deff2 | 309 | } else if (field_class->base == BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL) { |
476ef981 PP |
310 | fmt = ", %svalue=%" PRIx64; |
311 | } | |
312 | ||
63749226 PP |
313 | if (field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || |
314 | field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) { | |
476ef981 PP |
315 | if (!fmt) { |
316 | fmt = ", %svalue=%" PRId64; | |
317 | } | |
318 | ||
61f59358 | 319 | BUF_APPEND(fmt, PRFIELD(integer->value.i)); |
476ef981 PP |
320 | } else { |
321 | if (!fmt) { | |
322 | fmt = ", %svalue=%" PRIu64; | |
323 | } | |
324 | ||
61f59358 | 325 | BUF_APPEND(fmt, PRFIELD(integer->value.u)); |
476ef981 PP |
326 | } |
327 | } | |
328 | ||
cb6f1f7d | 329 | static inline void format_field(char **buf_ch, bool extended, |
3b4c8c43 | 330 | const char *prefix, const struct bt_field *field) |
476ef981 | 331 | { |
61f59358 | 332 | BUF_APPEND(", %sis-set=%d", PRFIELD(field->is_set)); |
476ef981 PP |
333 | |
334 | if (extended) { | |
335 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(field->frozen)); | |
336 | } | |
337 | ||
63749226 | 338 | BUF_APPEND(", %sclass-addr=%p", PRFIELD(field->class)); |
312c056a | 339 | |
c82deff2 | 340 | if (!field->class) { |
312c056a PP |
341 | return; |
342 | } | |
343 | ||
63749226 PP |
344 | BUF_APPEND(", %sclass-type=%s", |
345 | PRFIELD(bt_common_field_class_type_string(field->class->type))); | |
476ef981 | 346 | |
61f59358 | 347 | if (!extended || !field->is_set) { |
476ef981 PP |
348 | return; |
349 | } | |
350 | ||
63749226 PP |
351 | switch (field->class->type) { |
352 | case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: | |
353 | case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: | |
354 | case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: | |
355 | case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: | |
476ef981 | 356 | { |
cb6f1f7d | 357 | format_field_integer_extended(buf_ch, prefix, field); |
476ef981 PP |
358 | break; |
359 | } | |
63749226 | 360 | case BT_FIELD_CLASS_TYPE_REAL: |
476ef981 | 361 | { |
3b4c8c43 | 362 | const struct bt_field_real *real_field = (const void *) field; |
476ef981 | 363 | |
61f59358 | 364 | BUF_APPEND(", %svalue=%f", PRFIELD(real_field->value)); |
476ef981 PP |
365 | break; |
366 | } | |
63749226 | 367 | case BT_FIELD_CLASS_TYPE_STRING: |
476ef981 | 368 | { |
3b4c8c43 | 369 | const struct bt_field_string *str = (const void *) field; |
476ef981 | 370 | |
4d4b475d PP |
371 | if (str->buf) { |
372 | BT_ASSERT(str->buf->data); | |
312c056a | 373 | BUF_APPEND(", %spartial-value=\"%.32s\"", |
4d4b475d | 374 | PRFIELD(str->buf->data)); |
312c056a | 375 | } |
61f59358 | 376 | |
476ef981 PP |
377 | break; |
378 | } | |
63749226 PP |
379 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: |
380 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: | |
476ef981 | 381 | { |
3b4c8c43 | 382 | const struct bt_field_array *array_field = (const void *) field; |
476ef981 | 383 | |
61f59358 | 384 | BUF_APPEND(", %slength=%" PRIu64, PRFIELD(array_field->length)); |
312c056a | 385 | |
61f59358 | 386 | if (array_field->fields) { |
312c056a | 387 | BUF_APPEND(", %sallocated-length=%u", |
61f59358 | 388 | PRFIELD(array_field->fields->len)); |
312c056a | 389 | } |
61f59358 | 390 | |
476ef981 PP |
391 | break; |
392 | } | |
63749226 | 393 | case BT_FIELD_CLASS_TYPE_VARIANT: |
476ef981 | 394 | { |
3b4c8c43 | 395 | const struct bt_field_variant *var_field = (const void *) field; |
312c056a | 396 | |
61f59358 PP |
397 | BUF_APPEND(", %sselected-field-index=%" PRIu64, |
398 | PRFIELD(var_field->selected_index)); | |
312c056a PP |
399 | break; |
400 | } | |
401 | default: | |
402 | break; | |
403 | } | |
3dca2276 PP |
404 | } |
405 | ||
476ef981 | 406 | static inline void format_field_path(char **buf_ch, bool extended, |
3b4c8c43 | 407 | const char *prefix, const struct bt_field_path *field_path) |
476ef981 PP |
408 | { |
409 | uint64_t i; | |
410 | ||
312c056a PP |
411 | if (field_path->indexes) { |
412 | BT_ASSERT(field_path->indexes); | |
cb6f1f7d PP |
413 | BUF_APPEND(", %sindex-count=%u", |
414 | PRFIELD(field_path->indexes->len)); | |
312c056a | 415 | } |
476ef981 | 416 | |
312c056a | 417 | if (!extended || !field_path->indexes) { |
476ef981 PP |
418 | return; |
419 | } | |
420 | ||
cb6f1f7d PP |
421 | BUF_APPEND(", %spath=[%s", |
422 | PRFIELD(bt_common_scope_string(field_path->root))); | |
476ef981 PP |
423 | |
424 | for (i = 0; i < field_path->indexes->len; i++) { | |
61f59358 PP |
425 | uint64_t index = bt_field_path_get_index_by_index_inline( |
426 | field_path, i); | |
476ef981 | 427 | |
61f59358 | 428 | BUF_APPEND(", %" PRIu64, index); |
476ef981 PP |
429 | } |
430 | ||
431 | BUF_APPEND("%s", "]"); | |
432 | } | |
433 | ||
3b4c8c43 PP |
434 | static inline void format_trace_class(char **buf_ch, bool extended, |
435 | const char *prefix, const struct bt_trace_class *trace_class) | |
476ef981 | 436 | { |
3b4c8c43 PP |
437 | if (trace_class->name.value) { |
438 | BUF_APPEND(", %sname=\"%s\"", | |
439 | PRFIELD(trace_class->name.value)); | |
476ef981 PP |
440 | } |
441 | ||
442 | if (!extended) { | |
443 | return; | |
444 | } | |
445 | ||
3b4c8c43 | 446 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class->frozen)); |
476ef981 | 447 | |
3b4c8c43 PP |
448 | if (trace_class->uuid.value) { |
449 | BUF_APPEND_UUID(trace_class->uuid.value); | |
312c056a PP |
450 | } |
451 | ||
3b4c8c43 | 452 | if (trace_class->stream_classes) { |
312c056a | 453 | BUF_APPEND(", %sstream-class-count=%u", |
3b4c8c43 | 454 | PRFIELD(trace_class->stream_classes->len)); |
312c056a PP |
455 | } |
456 | ||
e076423c | 457 | BUF_APPEND(", %sassigns-auto-sc-id=%d", |
3b4c8c43 | 458 | PRFIELD(trace_class->assigns_automatic_stream_class_id)); |
3b4c8c43 PP |
459 | } |
460 | ||
461 | static inline void format_trace(char **buf_ch, bool extended, | |
462 | const char *prefix, const struct bt_trace *trace) | |
463 | { | |
464 | char tmp_prefix[64]; | |
465 | ||
466 | if (trace->name.value) { | |
467 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(trace->name.value)); | |
468 | } | |
469 | ||
470 | if (!extended) { | |
471 | return; | |
472 | } | |
473 | ||
474 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen)); | |
475 | ||
312c056a PP |
476 | if (trace->streams) { |
477 | BUF_APPEND(", %sstream-count=%u", | |
478 | PRFIELD(trace->streams->len)); | |
479 | } | |
480 | ||
3b4c8c43 PP |
481 | BUF_APPEND(", %sis-static=%d", PRFIELD(trace->is_static)); |
482 | ||
483 | if (!trace->class) { | |
484 | return; | |
485 | } | |
486 | ||
487 | BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace->class)); | |
488 | SET_TMP_PREFIX("trace-class-"); | |
489 | format_trace_class(buf_ch, false, tmp_prefix, trace->class); | |
3dca2276 PP |
490 | } |
491 | ||
cb6f1f7d | 492 | static inline void format_stream_class(char **buf_ch, bool extended, |
3b4c8c43 PP |
493 | const char *prefix, |
494 | const struct bt_stream_class *stream_class) | |
3dca2276 | 495 | { |
3b4c8c43 | 496 | const struct bt_trace_class *trace_class; |
476ef981 PP |
497 | char tmp_prefix[64]; |
498 | ||
61f59358 | 499 | BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream_class->id)); |
476ef981 | 500 | |
61f59358 PP |
501 | if (stream_class->name.value) { |
502 | BUF_APPEND(", %sname=\"%s\"", | |
503 | PRFIELD(stream_class->name.value)); | |
476ef981 PP |
504 | } |
505 | ||
506 | if (!extended) { | |
507 | return; | |
508 | } | |
509 | ||
510 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(stream_class->frozen)); | |
312c056a PP |
511 | |
512 | if (stream_class->event_classes) { | |
513 | BUF_APPEND(", %sevent-class-count=%u", | |
514 | PRFIELD(stream_class->event_classes->len)); | |
515 | } | |
516 | ||
c82deff2 | 517 | BUF_APPEND(", %spacket-context-fc-addr=%p, " |
e076423c | 518 | "%sevent-common-context-fc-addr=%p", |
c82deff2 | 519 | PRFIELD(stream_class->packet_context_fc), |
c82deff2 | 520 | PRFIELD(stream_class->event_common_context_fc)); |
3b4c8c43 PP |
521 | trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); |
522 | if (!trace_class) { | |
476ef981 PP |
523 | return; |
524 | } | |
525 | ||
61f59358 PP |
526 | BUF_APPEND(", %sassigns-auto-ec-id=%d, %sassigns-auto-stream-id=%d, " |
527 | "%spackets-have-discarded-ev-counter-snapshot=%d, " | |
528 | "%spackets-have-packet-counter-snapshot=%d, " | |
b1824349 PP |
529 | "%spackets-have-default-begin-cs=%d, " |
530 | "%spackets-have-default-end-cs=%d", | |
61f59358 PP |
531 | PRFIELD(stream_class->assigns_automatic_event_class_id), |
532 | PRFIELD(stream_class->assigns_automatic_stream_id), | |
533 | PRFIELD(stream_class->packets_have_discarded_event_counter_snapshot), | |
534 | PRFIELD(stream_class->packets_have_packet_counter_snapshot), | |
b1824349 PP |
535 | PRFIELD(stream_class->packets_have_default_beginning_cs), |
536 | PRFIELD(stream_class->packets_have_default_end_cs)); | |
3b4c8c43 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); | |
5c563278 PP |
540 | SET_TMP_PREFIX("pcf-pool-"); |
541 | format_object_pool(buf_ch, extended, prefix, | |
542 | &stream_class->packet_context_field_pool); | |
3dca2276 PP |
543 | } |
544 | ||
cb6f1f7d | 545 | static inline void format_event_class(char **buf_ch, bool extended, |
3b4c8c43 | 546 | const char *prefix, const struct bt_event_class *event_class) |
3dca2276 | 547 | { |
3b4c8c43 PP |
548 | const struct bt_stream_class *stream_class; |
549 | const struct bt_trace_class *trace_class; | |
476ef981 PP |
550 | char tmp_prefix[64]; |
551 | ||
61f59358 | 552 | BUF_APPEND(", %sid=%" PRIu64, PRFIELD(event_class->id)); |
476ef981 | 553 | |
61f59358 | 554 | if (event_class->name.value) { |
cb6f1f7d | 555 | BUF_APPEND(", %sname=\"%s\"", |
61f59358 | 556 | PRFIELD(event_class->name.value)); |
476ef981 PP |
557 | } |
558 | ||
559 | if (!extended) { | |
560 | return; | |
561 | } | |
562 | ||
61f59358 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 | } | |
476ef981 | 570 | |
61f59358 | 571 | if (event_class->emf_uri.value) { |
476ef981 | 572 | BUF_APPEND(", %semf-uri=\"%s\"", |
61f59358 | 573 | PRFIELD(event_class->emf_uri.value)); |
476ef981 PP |
574 | } |
575 | ||
c82deff2 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)); | |
476ef981 | 579 | |
3b4c8c43 | 580 | stream_class = bt_event_class_borrow_stream_class_const(event_class); |
476ef981 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-"); | |
cb6f1f7d | 587 | format_stream_class(buf_ch, false, tmp_prefix, stream_class); |
3b4c8c43 PP |
588 | trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); |
589 | if (!trace_class) { | |
476ef981 PP |
590 | return; |
591 | } | |
592 | ||
3b4c8c43 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); | |
312c056a PP |
596 | SET_TMP_PREFIX("event-pool-"); |
597 | format_object_pool(buf_ch, extended, prefix, &event_class->event_pool); | |
3dca2276 PP |
598 | } |
599 | ||
cb6f1f7d | 600 | static inline void format_stream(char **buf_ch, bool extended, |
3b4c8c43 | 601 | const char *prefix, const struct bt_stream *stream) |
3dca2276 | 602 | { |
3b4c8c43 PP |
603 | const struct bt_stream_class *stream_class; |
604 | const struct bt_trace_class *trace_class = NULL; | |
605 | const struct bt_trace *trace = NULL; | |
476ef981 PP |
606 | char tmp_prefix[64]; |
607 | ||
61f59358 | 608 | BUF_APPEND(", %sid=%" PRIu64, PRFIELD(stream->id)); |
476ef981 | 609 | |
61f59358 PP |
610 | if (stream->name.value) { |
611 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(stream->name.value)); | |
476ef981 PP |
612 | } |
613 | ||
476ef981 PP |
614 | if (!extended) { |
615 | return; | |
616 | } | |
617 | ||
3b4c8c43 PP |
618 | stream_class = bt_stream_borrow_class_const(stream); |
619 | if (stream_class) { | |
620 | BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); | |
621 | SET_TMP_PREFIX("stream-class-"); | |
622 | format_stream_class(buf_ch, false, tmp_prefix, stream_class); | |
623 | trace_class = bt_stream_class_borrow_trace_class_inline(stream_class); | |
476ef981 PP |
624 | } |
625 | ||
3b4c8c43 PP |
626 | if (trace_class) { |
627 | BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class)); | |
628 | SET_TMP_PREFIX("trace-class-"); | |
629 | format_trace_class(buf_ch, false, tmp_prefix, trace_class); | |
630 | } | |
631 | ||
632 | trace = bt_stream_borrow_trace_inline(stream); | |
633 | if (trace) { | |
634 | BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); | |
635 | SET_TMP_PREFIX("trace-"); | |
636 | format_trace(buf_ch, false, tmp_prefix, trace); | |
476ef981 PP |
637 | } |
638 | ||
312c056a PP |
639 | SET_TMP_PREFIX("packet-pool-"); |
640 | format_object_pool(buf_ch, extended, prefix, &stream->packet_pool); | |
3dca2276 PP |
641 | } |
642 | ||
476ef981 | 643 | static inline void format_packet(char **buf_ch, bool extended, |
3b4c8c43 | 644 | const char *prefix, const struct bt_packet *packet) |
476ef981 | 645 | { |
3b4c8c43 PP |
646 | const struct bt_stream *stream; |
647 | const struct bt_trace_class *trace_class; | |
476ef981 PP |
648 | char tmp_prefix[64]; |
649 | ||
650 | if (!extended) { | |
651 | return; | |
652 | } | |
653 | ||
e076423c | 654 | BUF_APPEND(", %sis-frozen=%d, %scontext-field-addr=%p", |
476ef981 | 655 | PRFIELD(packet->frozen), |
61f59358 | 656 | PRFIELD(packet->context_field ? packet->context_field->field : NULL)); |
3b4c8c43 | 657 | stream = bt_packet_borrow_stream_const(packet); |
476ef981 PP |
658 | if (!stream) { |
659 | return; | |
660 | } | |
661 | ||
b1824349 PP |
662 | if (packet->default_beginning_cs) { |
663 | SET_TMP_PREFIX("default-begin-cs-"); | |
664 | format_clock_snapshot(buf_ch, true, tmp_prefix, | |
665 | packet->default_beginning_cs); | |
61f59358 PP |
666 | } |
667 | ||
b1824349 PP |
668 | if (packet->default_end_cs) { |
669 | SET_TMP_PREFIX("default-end-cs-"); | |
670 | format_clock_snapshot(buf_ch, true, tmp_prefix, | |
671 | packet->default_end_cs); | |
61f59358 PP |
672 | } |
673 | ||
674 | if (packet->discarded_event_counter_snapshot.base.avail) { | |
675 | BUF_APPEND(", %sdiscarded-ev-counter-snapshot=%" PRIu64, | |
676 | PRFIELD(packet->discarded_event_counter_snapshot.value)); | |
677 | } | |
678 | ||
679 | if (packet->packet_counter_snapshot.base.avail) { | |
680 | BUF_APPEND(", %spacket-counter-snapshot=%" PRIu64, | |
681 | PRFIELD(packet->packet_counter_snapshot.value)); | |
682 | } | |
683 | ||
476ef981 PP |
684 | BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream)); |
685 | SET_TMP_PREFIX("stream-"); | |
686 | format_stream(buf_ch, false, tmp_prefix, stream); | |
3b4c8c43 PP |
687 | trace_class = (const struct bt_trace_class *) bt_object_borrow_parent(&stream->base); |
688 | if (!trace_class) { | |
476ef981 PP |
689 | return; |
690 | } | |
691 | ||
3b4c8c43 PP |
692 | BUF_APPEND(", %strace-class-addr=%p", PRFIELD(trace_class)); |
693 | SET_TMP_PREFIX("trace-class-"); | |
694 | format_trace_class(buf_ch, false, tmp_prefix, trace_class); | |
476ef981 PP |
695 | } |
696 | ||
cb6f1f7d | 697 | static inline void format_event(char **buf_ch, bool extended, |
3b4c8c43 | 698 | const char *prefix, const struct bt_event *event) |
476ef981 | 699 | { |
3b4c8c43 PP |
700 | const struct bt_packet *packet; |
701 | const struct bt_stream *stream; | |
702 | const struct bt_trace_class *trace_class; | |
703 | const struct bt_stream_class *stream_class; | |
476ef981 PP |
704 | char tmp_prefix[64]; |
705 | ||
706 | if (!extended) { | |
707 | return; | |
708 | } | |
709 | ||
e076423c | 710 | BUF_APPEND(", %sis-frozen=%d, " |
61f59358 | 711 | "%scommon-context-field-addr=%p, " |
d27a81b2 | 712 | "%sspecific-context-field-addr=%p, " |
61f59358 | 713 | "%spayload-field-addr=%p, ", |
476ef981 | 714 | PRFIELD(event->frozen), |
61f59358 PP |
715 | PRFIELD(event->common_context_field), |
716 | PRFIELD(event->specific_context_field), | |
3dca2276 PP |
717 | PRFIELD(event->payload_field)); |
718 | BUF_APPEND(", %sevent-class-addr=%p", PRFIELD(event->class)); | |
312c056a PP |
719 | |
720 | if (!event->class) { | |
721 | return; | |
722 | } | |
723 | ||
476ef981 | 724 | SET_TMP_PREFIX("event-class-"); |
cb6f1f7d PP |
725 | format_event_class(buf_ch, false, tmp_prefix, event->class); |
726 | stream_class = bt_event_class_borrow_stream_class(event->class); | |
476ef981 PP |
727 | if (stream_class) { |
728 | BUF_APPEND(", %sstream-class-addr=%p", PRFIELD(stream_class)); | |
729 | SET_TMP_PREFIX("stream-class-"); | |
cb6f1f7d | 730 | format_stream_class(buf_ch, false, tmp_prefix, |
3dca2276 | 731 | stream_class); |
476ef981 | 732 | |
3b4c8c43 PP |
733 | trace_class = bt_stream_class_borrow_trace_class_inline( |
734 | stream_class); | |
735 | if (trace_class) { | |
736 | BUF_APPEND(", %strace-class-addr=%p", | |
737 | PRFIELD(trace_class)); | |
738 | SET_TMP_PREFIX("trace-class-"); | |
739 | format_trace_class(buf_ch, false, tmp_prefix, | |
740 | trace_class); | |
476ef981 PP |
741 | } |
742 | } | |
3dca2276 | 743 | |
b1824349 PP |
744 | if (event->default_cs) { |
745 | SET_TMP_PREFIX("default-cs-"); | |
746 | format_clock_snapshot(buf_ch, true, tmp_prefix, | |
747 | event->default_cs); | |
61f59358 PP |
748 | } |
749 | ||
3b4c8c43 | 750 | packet = bt_event_borrow_packet_const(event); |
476ef981 PP |
751 | if (!packet) { |
752 | return; | |
753 | } | |
754 | ||
755 | BUF_APPEND(", %spacket-addr=%p", PRFIELD(packet)); | |
756 | SET_TMP_PREFIX("packet-"); | |
757 | format_packet(buf_ch, false, tmp_prefix, packet); | |
3b4c8c43 | 758 | stream = bt_packet_borrow_stream_const(packet); |
476ef981 PP |
759 | if (!stream) { |
760 | return; | |
761 | } | |
762 | ||
763 | BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream)); | |
764 | SET_TMP_PREFIX("stream-"); | |
765 | format_stream(buf_ch, false, tmp_prefix, stream); | |
766 | } | |
767 | ||
768 | static inline void format_clock_class(char **buf_ch, bool extended, | |
3b4c8c43 | 769 | const char *prefix, const struct bt_clock_class *clock_class) |
476ef981 | 770 | { |
312c056a PP |
771 | char tmp_prefix[64]; |
772 | ||
61f59358 PP |
773 | if (clock_class->name.value) { |
774 | BUF_APPEND(", %sname=\"%s\"", PRFIELD(clock_class->name.value)); | |
775 | } | |
776 | ||
777 | BUF_APPEND(", %sfreq=%" PRIu64, PRFIELD(clock_class->frequency)); | |
476ef981 PP |
778 | |
779 | if (!extended) { | |
780 | return; | |
781 | } | |
782 | ||
61f59358 PP |
783 | if (clock_class->description.value) { |
784 | BUF_APPEND(", %spartial-descr=\"%.32s\"", | |
785 | PRFIELD(clock_class->description.value)); | |
786 | } | |
787 | ||
788 | if (clock_class->uuid.value) { | |
789 | BUF_APPEND_UUID(clock_class->uuid.value); | |
476ef981 PP |
790 | } |
791 | ||
792 | BUF_APPEND(", %sis-frozen=%d, %sprecision=%" PRIu64 ", " | |
793 | "%soffset-s=%" PRId64 ", " | |
61f59358 PP |
794 | "%soffset-cycles=%" PRIu64 ", %sis-absolute=%d, " |
795 | "%sbase-offset-ns=%" PRId64, | |
476ef981 | 796 | PRFIELD(clock_class->frozen), PRFIELD(clock_class->precision), |
61f59358 PP |
797 | PRFIELD(clock_class->offset_seconds), |
798 | PRFIELD(clock_class->offset_cycles), | |
799 | PRFIELD(clock_class->is_absolute), | |
800 | PRFIELD(clock_class->base_offset.value_ns)); | |
312c056a | 801 | |
b1824349 PP |
802 | SET_TMP_PREFIX("cs-pool-"); |
803 | format_object_pool(buf_ch, extended, prefix, &clock_class->cs_pool); | |
476ef981 PP |
804 | } |
805 | ||
b1824349 PP |
806 | static inline void format_clock_snapshot(char **buf_ch, bool extended, |
807 | const char *prefix, const struct bt_clock_snapshot *clock_snapshot) | |
476ef981 PP |
808 | { |
809 | char tmp_prefix[64]; | |
61f59358 | 810 | BUF_APPEND(", %svalue=%" PRIu64 ", %sns-from-origin=%" PRId64, |
b1824349 PP |
811 | PRFIELD(clock_snapshot->value_cycles), |
812 | PRFIELD(clock_snapshot->ns_from_origin)); | |
476ef981 PP |
813 | |
814 | if (!extended) { | |
815 | return; | |
816 | } | |
817 | ||
b1824349 | 818 | BUF_APPEND(", %sis-set=%d", PRFIELD(clock_snapshot->is_set)); |
d27a81b2 | 819 | |
b1824349 | 820 | if (clock_snapshot->clock_class) { |
d27a81b2 | 821 | BUF_APPEND(", %sclock-class-addr=%p", |
b1824349 | 822 | PRFIELD(clock_snapshot->clock_class)); |
d27a81b2 PP |
823 | SET_TMP_PREFIX("clock-class-"); |
824 | format_clock_class(buf_ch, false, tmp_prefix, | |
b1824349 | 825 | clock_snapshot->clock_class); |
d27a81b2 | 826 | } |
476ef981 PP |
827 | } |
828 | ||
829 | static inline void format_value(char **buf_ch, bool extended, | |
3b4c8c43 | 830 | const char *prefix, const struct bt_value *value) |
476ef981 PP |
831 | { |
832 | BUF_APPEND(", %stype=%s", | |
351704a7 | 833 | PRFIELD(bt_common_value_type_string(bt_value_get_type(value)))); |
476ef981 PP |
834 | |
835 | if (!extended) { | |
836 | return; | |
837 | } | |
838 | ||
839 | switch (bt_value_get_type(value)) { | |
840 | case BT_VALUE_TYPE_BOOL: | |
841 | { | |
605c62ba | 842 | bt_bool val = bt_value_bool_get(value); |
476ef981 | 843 | |
476ef981 PP |
844 | BUF_APPEND(", %svalue=%d", PRFIELD(val)); |
845 | break; | |
846 | } | |
847 | case BT_VALUE_TYPE_INTEGER: | |
848 | { | |
605c62ba | 849 | int64_t val = bt_value_integer_get(value); |
476ef981 | 850 | |
476ef981 PP |
851 | BUF_APPEND(", %svalue=%" PRId64, PRFIELD(val)); |
852 | break; | |
853 | } | |
9db4d871 | 854 | case BT_VALUE_TYPE_REAL: |
476ef981 | 855 | { |
605c62ba | 856 | double val = bt_value_real_get(value); |
476ef981 | 857 | |
476ef981 PP |
858 | BUF_APPEND(", %svalue=%f", PRFIELD(val)); |
859 | break; | |
860 | } | |
861 | case BT_VALUE_TYPE_STRING: | |
862 | { | |
605c62ba | 863 | const char *val = bt_value_string_get(value); |
476ef981 | 864 | |
476ef981 PP |
865 | BUF_APPEND(", %spartial-value=\"%.32s\"", PRFIELD(val)); |
866 | break; | |
867 | } | |
868 | case BT_VALUE_TYPE_ARRAY: | |
869 | { | |
7fce1b50 | 870 | int64_t count = bt_value_array_get_size(value); |
476ef981 | 871 | |
f6ccaed9 | 872 | BT_ASSERT(count >= 0); |
476ef981 PP |
873 | BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); |
874 | break; | |
875 | } | |
876 | case BT_VALUE_TYPE_MAP: | |
877 | { | |
7fce1b50 | 878 | int64_t count = bt_value_map_get_size(value); |
476ef981 | 879 | |
f6ccaed9 | 880 | BT_ASSERT(count >= 0); |
476ef981 PP |
881 | BUF_APPEND(", %selement-count=%" PRId64, PRFIELD(count)); |
882 | break; | |
883 | } | |
884 | default: | |
885 | break; | |
886 | } | |
887 | } | |
888 | ||
c14831f0 PP |
889 | static inline void format_message(char **buf_ch, bool extended, |
890 | const char *prefix, const struct bt_message *msg) | |
476ef981 PP |
891 | { |
892 | char tmp_prefix[64]; | |
893 | ||
894 | BUF_APPEND(", %stype=%s", | |
c14831f0 | 895 | PRFIELD(bt_message_type_string(msg->type))); |
476ef981 PP |
896 | |
897 | if (!extended) { | |
898 | return; | |
899 | } | |
900 | ||
5c563278 | 901 | BUF_APPEND(", %sis-frozen=%d, %sgraph-addr=%p", |
c14831f0 | 902 | PRFIELD(msg->frozen), PRFIELD(msg->graph)); |
476ef981 | 903 | |
c14831f0 PP |
904 | switch (msg->type) { |
905 | case BT_MESSAGE_TYPE_EVENT: | |
476ef981 | 906 | { |
c14831f0 PP |
907 | const struct bt_message_event *msg_event = |
908 | (const void *) msg; | |
476ef981 | 909 | |
c14831f0 | 910 | if (msg_event->event) { |
d27a81b2 | 911 | SET_TMP_PREFIX("event-"); |
2accc83a PP |
912 | format_event(buf_ch, true, tmp_prefix, |
913 | msg_event->event); | |
d27a81b2 PP |
914 | } |
915 | ||
476ef981 PP |
916 | break; |
917 | } | |
c14831f0 | 918 | case BT_MESSAGE_TYPE_STREAM_BEGINNING: |
2accc83a | 919 | case BT_MESSAGE_TYPE_STREAM_END: |
476ef981 | 920 | { |
2accc83a | 921 | const struct bt_message_stream *msg_stream = (const void *) msg; |
476ef981 | 922 | |
c14831f0 | 923 | if (msg_stream->stream) { |
d27a81b2 | 924 | SET_TMP_PREFIX("stream-"); |
2accc83a PP |
925 | format_stream(buf_ch, true, tmp_prefix, |
926 | msg_stream->stream); | |
d27a81b2 PP |
927 | } |
928 | ||
476ef981 PP |
929 | break; |
930 | } | |
2accc83a PP |
931 | case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING: |
932 | case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END: | |
476ef981 | 933 | { |
2accc83a | 934 | const struct bt_message_stream_activity *msg_stream_activity = |
c14831f0 | 935 | (const void *) msg; |
476ef981 | 936 | |
2accc83a | 937 | if (msg_stream_activity->stream) { |
d27a81b2 | 938 | SET_TMP_PREFIX("stream-"); |
2accc83a PP |
939 | format_stream(buf_ch, true, tmp_prefix, |
940 | msg_stream_activity->stream); | |
d27a81b2 PP |
941 | } |
942 | ||
2accc83a PP |
943 | BUF_APPEND(", %sdefault-cs-state=%s", |
944 | PRFIELD(bt_message_stream_activity_clock_snapshot_state_string( | |
945 | msg_stream_activity->default_cs_state))); | |
476ef981 | 946 | |
2accc83a PP |
947 | if (msg_stream_activity->default_cs) { |
948 | SET_TMP_PREFIX("default-cs-"); | |
949 | format_clock_snapshot(buf_ch, true, tmp_prefix, | |
950 | msg_stream_activity->default_cs); | |
d27a81b2 PP |
951 | } |
952 | ||
476ef981 PP |
953 | break; |
954 | } | |
2accc83a | 955 | case BT_MESSAGE_TYPE_PACKET_BEGINNING: |
c14831f0 | 956 | case BT_MESSAGE_TYPE_PACKET_END: |
476ef981 | 957 | { |
2accc83a | 958 | const struct bt_message_packet *msg_packet = (const void *) msg; |
476ef981 | 959 | |
c14831f0 | 960 | if (msg_packet->packet) { |
d27a81b2 | 961 | SET_TMP_PREFIX("packet-"); |
2accc83a PP |
962 | format_packet(buf_ch, true, tmp_prefix, |
963 | msg_packet->packet); | |
d27a81b2 PP |
964 | } |
965 | ||
476ef981 PP |
966 | break; |
967 | } | |
476ef981 PP |
968 | default: |
969 | break; | |
970 | } | |
971 | } | |
972 | ||
973 | static inline void format_plugin_so_shared_lib_handle(char **buf_ch, | |
974 | const char *prefix, | |
3b4c8c43 | 975 | const struct bt_plugin_so_shared_lib_handle *handle) |
476ef981 PP |
976 | { |
977 | BUF_APPEND(", %saddr=%p", PRFIELD(handle)); | |
978 | ||
979 | if (handle->path) { | |
d27a81b2 | 980 | BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle->path)); |
476ef981 PP |
981 | } |
982 | } | |
983 | ||
984 | static inline void format_component_class(char **buf_ch, bool extended, | |
3b4c8c43 PP |
985 | const char *prefix, |
986 | const struct bt_component_class *comp_class) | |
476ef981 PP |
987 | { |
988 | char tmp_prefix[64]; | |
989 | ||
990 | BUF_APPEND(", %stype=%s, %sname=\"%s\"", | |
991 | PRFIELD(bt_component_class_type_string(comp_class->type)), | |
d27a81b2 | 992 | PRFIELD_GSTRING(comp_class->name)); |
476ef981 PP |
993 | |
994 | if (comp_class->description) { | |
995 | BUF_APPEND(", %spartial-descr=\"%.32s\"", | |
d27a81b2 | 996 | PRFIELD_GSTRING(comp_class->description)); |
476ef981 PP |
997 | } |
998 | ||
999 | if (!extended) { | |
1000 | return; | |
1001 | } | |
1002 | ||
1003 | BUF_APPEND(", %sis-frozen=%d", PRFIELD(comp_class->frozen)); | |
1004 | ||
1005 | if (comp_class->so_handle) { | |
1006 | SET_TMP_PREFIX("so-handle-"); | |
1007 | format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix, | |
1008 | comp_class->so_handle); | |
1009 | } | |
1010 | } | |
1011 | ||
1012 | static inline void format_component(char **buf_ch, bool extended, | |
3b4c8c43 | 1013 | const char *prefix, const struct bt_component *component) |
476ef981 PP |
1014 | { |
1015 | char tmp_prefix[64]; | |
1016 | ||
d27a81b2 PP |
1017 | BUF_APPEND(", %sname=\"%s\"", |
1018 | PRFIELD_GSTRING(component->name)); | |
1019 | ||
1020 | if (component->class) { | |
1021 | SET_TMP_PREFIX("class-"); | |
1022 | format_component_class(buf_ch, extended, tmp_prefix, | |
1023 | component->class); | |
1024 | } | |
476ef981 PP |
1025 | |
1026 | if (!extended) { | |
1027 | return; | |
1028 | } | |
1029 | ||
312c056a PP |
1030 | if (component->input_ports) { |
1031 | BUF_APPEND(", %sinput-port-count=%u", | |
1032 | PRFIELD(component->input_ports->len)); | |
1033 | } | |
1034 | ||
1035 | if (component->output_ports) { | |
1036 | BUF_APPEND(", %soutput-port-count=%u", | |
1037 | PRFIELD(component->output_ports->len)); | |
1038 | } | |
476ef981 PP |
1039 | } |
1040 | ||
1041 | static inline void format_port(char **buf_ch, bool extended, | |
3b4c8c43 | 1042 | const char *prefix, const struct bt_port *port) |
476ef981 PP |
1043 | { |
1044 | char tmp_prefix[64]; | |
1045 | ||
1046 | BUF_APPEND(", %stype=%s, %sname=\"%s\"", | |
1047 | PRFIELD(bt_port_type_string(port->type)), | |
d27a81b2 | 1048 | PRFIELD_GSTRING(port->name)); |
476ef981 PP |
1049 | |
1050 | if (!extended) { | |
1051 | return; | |
1052 | } | |
1053 | ||
1054 | if (port->connection) { | |
1055 | SET_TMP_PREFIX("conn-"); | |
1056 | format_connection(buf_ch, false, tmp_prefix, port->connection); | |
1057 | } | |
1058 | } | |
1059 | ||
1060 | static inline void format_connection(char **buf_ch, bool extended, | |
3b4c8c43 | 1061 | const char *prefix, const struct bt_connection *connection) |
476ef981 PP |
1062 | { |
1063 | char tmp_prefix[64]; | |
1064 | ||
1065 | if (!extended) { | |
1066 | return; | |
1067 | } | |
1068 | ||
1069 | if (connection->upstream_port) { | |
1070 | SET_TMP_PREFIX("upstream-port-"); | |
1071 | format_port(buf_ch, false, tmp_prefix, | |
1072 | connection->upstream_port); | |
1073 | } | |
1074 | ||
1075 | if (connection->downstream_port) { | |
1076 | SET_TMP_PREFIX("downstream-port-"); | |
1077 | format_port(buf_ch, false, tmp_prefix, | |
1078 | connection->downstream_port); | |
1079 | } | |
1080 | } | |
1081 | ||
1082 | static inline void format_graph(char **buf_ch, bool extended, | |
3b4c8c43 | 1083 | const char *prefix, const struct bt_graph *graph) |
476ef981 | 1084 | { |
5c563278 PP |
1085 | char tmp_prefix[64]; |
1086 | ||
476ef981 PP |
1087 | BUF_APPEND(", %sis-canceled=%d", PRFIELD(graph->canceled)); |
1088 | ||
1089 | if (!extended) { | |
1090 | return; | |
1091 | } | |
1092 | ||
312c056a PP |
1093 | if (graph->components) { |
1094 | BUF_APPEND(", %scomp-count=%u", | |
1095 | PRFIELD(graph->components->len)); | |
1096 | } | |
1097 | ||
1098 | if (graph->connections) { | |
1099 | BUF_APPEND(", %sconn-count=%u", | |
1100 | PRFIELD(graph->connections->len)); | |
1101 | } | |
5c563278 PP |
1102 | |
1103 | SET_TMP_PREFIX("en-pool-"); | |
1104 | format_object_pool(buf_ch, extended, prefix, | |
c14831f0 | 1105 | &graph->event_msg_pool); |
5c563278 PP |
1106 | SET_TMP_PREFIX("pbn-pool-"); |
1107 | format_object_pool(buf_ch, extended, prefix, | |
c14831f0 | 1108 | &graph->packet_begin_msg_pool); |
5c563278 PP |
1109 | SET_TMP_PREFIX("pen-pool-"); |
1110 | format_object_pool(buf_ch, extended, prefix, | |
c14831f0 | 1111 | &graph->packet_end_msg_pool); |
476ef981 PP |
1112 | } |
1113 | ||
c14831f0 | 1114 | static inline void format_message_iterator(char **buf_ch, |
476ef981 | 1115 | bool extended, const char *prefix, |
c14831f0 | 1116 | const struct bt_message_iterator *iterator) |
476ef981 PP |
1117 | { |
1118 | const char *type; | |
1119 | char tmp_prefix[64]; | |
1120 | ||
c14831f0 PP |
1121 | if (iterator->type == BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT) { |
1122 | type = "BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT"; | |
1123 | } else if (iterator->type == BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT) { | |
1124 | type = "BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT"; | |
476ef981 PP |
1125 | } else { |
1126 | type = "(unknown)"; | |
1127 | } | |
1128 | ||
1129 | BUF_APPEND(", %stype=%s", PRFIELD(type)); | |
1130 | ||
1131 | switch (iterator->type) { | |
c14831f0 | 1132 | case BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT: |
476ef981 | 1133 | { |
c14831f0 | 1134 | const struct bt_self_component_port_input_message_iterator * |
3b4c8c43 | 1135 | port_in_iter = (const void *) iterator; |
476ef981 | 1136 | |
d27a81b2 | 1137 | if (port_in_iter->upstream_component) { |
476ef981 PP |
1138 | SET_TMP_PREFIX("upstream-comp-"); |
1139 | format_component(buf_ch, false, tmp_prefix, | |
d27a81b2 | 1140 | port_in_iter->upstream_component); |
476ef981 PP |
1141 | } |
1142 | ||
d27a81b2 | 1143 | if (port_in_iter->upstream_port) { |
476ef981 PP |
1144 | SET_TMP_PREFIX("upstream-port-"); |
1145 | format_port(buf_ch, false, tmp_prefix, | |
d27a81b2 | 1146 | port_in_iter->upstream_port); |
476ef981 PP |
1147 | } |
1148 | ||
d27a81b2 | 1149 | if (port_in_iter->connection) { |
476ef981 PP |
1150 | SET_TMP_PREFIX("upstream-conn-"); |
1151 | format_connection(buf_ch, false, tmp_prefix, | |
d27a81b2 | 1152 | port_in_iter->connection); |
476ef981 PP |
1153 | } |
1154 | break; | |
1155 | } | |
c14831f0 | 1156 | case BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT: |
476ef981 | 1157 | { |
c14831f0 | 1158 | const struct bt_port_output_message_iterator *port_out_iter = |
3b4c8c43 | 1159 | (const void *) iterator; |
476ef981 | 1160 | |
d27a81b2 PP |
1161 | if (port_out_iter->graph) { |
1162 | SET_TMP_PREFIX("graph-"); | |
1163 | format_graph(buf_ch, false, tmp_prefix, | |
1164 | port_out_iter->graph); | |
1165 | } | |
1166 | ||
1167 | if (port_out_iter->colander) { | |
1168 | SET_TMP_PREFIX("colander-comp-"); | |
1169 | format_component(buf_ch, false, tmp_prefix, | |
1170 | (void *) port_out_iter->colander); | |
1171 | } | |
1172 | ||
476ef981 PP |
1173 | break; |
1174 | } | |
1175 | default: | |
1176 | break; | |
1177 | } | |
1178 | } | |
1179 | ||
1180 | static inline void format_plugin(char **buf_ch, bool extended, | |
41c0a8aa | 1181 | const char *prefix, const struct bt_plugin *plugin) |
476ef981 PP |
1182 | { |
1183 | char tmp_prefix[64]; | |
1184 | ||
1185 | BUF_APPEND(", %stype=%s", PRFIELD(bt_plugin_type_string(plugin->type))); | |
1186 | ||
1187 | if (plugin->info.path_set) { | |
1188 | BUF_APPEND(", %spath=\"%s\"", | |
d27a81b2 | 1189 | PRFIELD_GSTRING(plugin->info.path)); |
476ef981 PP |
1190 | } |
1191 | ||
1192 | if (plugin->info.name_set) { | |
1193 | BUF_APPEND(", %sname=\"%s\"", | |
d27a81b2 | 1194 | PRFIELD_GSTRING(plugin->info.name)); |
476ef981 PP |
1195 | } |
1196 | ||
1197 | if (!extended) { | |
1198 | return; | |
1199 | } | |
1200 | ||
1201 | if (plugin->info.author_set) { | |
1202 | BUF_APPEND(", %sauthor=\"%s\"", | |
d27a81b2 | 1203 | PRFIELD_GSTRING(plugin->info.author)); |
476ef981 PP |
1204 | } |
1205 | ||
1206 | if (plugin->info.license_set) { | |
1207 | BUF_APPEND(", %slicense=\"%s\"", | |
d27a81b2 | 1208 | PRFIELD_GSTRING(plugin->info.license)); |
476ef981 PP |
1209 | } |
1210 | ||
1211 | if (plugin->info.version_set) { | |
1212 | BUF_APPEND(", %sversion=%u.%u.%u%s", | |
1213 | PRFIELD(plugin->info.version.major), | |
1214 | plugin->info.version.minor, | |
1215 | plugin->info.version.patch, | |
1216 | plugin->info.version.extra ? | |
1217 | plugin->info.version.extra->str : ""); | |
1218 | } | |
1219 | ||
d27a81b2 PP |
1220 | BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, " |
1221 | "%ssink-comp-class-count=%u", | |
1222 | PRFIELD(plugin->src_comp_classes->len), | |
1223 | PRFIELD(plugin->flt_comp_classes->len), | |
1224 | PRFIELD(plugin->sink_comp_classes->len)); | |
476ef981 PP |
1225 | |
1226 | if (plugin->spec_data) { | |
3b4c8c43 PP |
1227 | const struct bt_plugin_so_spec_data *spec_data = |
1228 | (const void *) plugin->spec_data; | |
476ef981 PP |
1229 | |
1230 | if (spec_data->shared_lib_handle) { | |
1231 | SET_TMP_PREFIX("so-handle-"); | |
1232 | format_plugin_so_shared_lib_handle(buf_ch, tmp_prefix, | |
1233 | spec_data->shared_lib_handle); | |
1234 | } | |
1235 | } | |
1236 | } | |
1237 | ||
476ef981 PP |
1238 | static inline void handle_conversion_specifier_bt(void *priv_data, |
1239 | char **buf_ch, size_t avail_size, | |
1240 | const char **out_fmt_ch, va_list *args) | |
1241 | { | |
1242 | const char *fmt_ch = *out_fmt_ch; | |
1243 | bool extended = false; | |
1244 | char prefix[64]; | |
1245 | char *prefix_ch = prefix; | |
3b4c8c43 | 1246 | const void *obj; |
476ef981 PP |
1247 | |
1248 | /* skip "%!" */ | |
1249 | fmt_ch += 2; | |
1250 | ||
61f59358 PP |
1251 | if (*fmt_ch == 'u') { |
1252 | /* UUID */ | |
1253 | obj = va_arg(*args, void *); | |
1254 | format_uuid(buf_ch, obj); | |
1255 | goto update_fmt; | |
1256 | } | |
1257 | ||
476ef981 PP |
1258 | if (*fmt_ch == '[') { |
1259 | /* local prefix */ | |
1260 | fmt_ch++; | |
1261 | ||
1262 | while (true) { | |
1263 | if (*fmt_ch == ']') { | |
1264 | *prefix_ch = '\0'; | |
1265 | fmt_ch++; | |
1266 | break; | |
1267 | } | |
1268 | ||
1269 | *prefix_ch = *fmt_ch; | |
1270 | prefix_ch++; | |
1271 | fmt_ch++; | |
1272 | } | |
1273 | } | |
1274 | ||
1275 | *prefix_ch = '\0'; | |
1276 | ||
1277 | if (*fmt_ch == '+') { | |
1278 | extended = true; | |
1279 | fmt_ch++; | |
1280 | } | |
1281 | ||
1282 | obj = va_arg(*args, void *); | |
1283 | BUF_APPEND("%saddr=%p", prefix, obj); | |
1284 | ||
1285 | if (!obj) { | |
1286 | goto update_fmt; | |
1287 | } | |
1288 | ||
cb6f1f7d PP |
1289 | switch (*fmt_ch) { |
1290 | case 'F': | |
c82deff2 | 1291 | format_field_class(buf_ch, extended, prefix, obj); |
476ef981 | 1292 | break; |
cb6f1f7d PP |
1293 | case 'f': |
1294 | format_field(buf_ch, extended, prefix, obj); | |
1295 | break; | |
1296 | case 'P': | |
1297 | format_field_path(buf_ch, extended, prefix, obj); | |
1298 | break; | |
1299 | case 'E': | |
1300 | format_event_class(buf_ch, extended, prefix, obj); | |
1301 | break; | |
1302 | case 'e': | |
1303 | format_event(buf_ch, extended, prefix, obj); | |
1304 | break; | |
1305 | case 'S': | |
1306 | format_stream_class(buf_ch, extended, prefix, obj); | |
476ef981 | 1307 | break; |
cb6f1f7d PP |
1308 | case 's': |
1309 | format_stream(buf_ch, extended, prefix, obj); | |
1310 | break; | |
1311 | case 'a': | |
1312 | format_packet(buf_ch, extended, prefix, obj); | |
1313 | break; | |
1314 | case 't': | |
1315 | format_trace(buf_ch, extended, prefix, obj); | |
1316 | break; | |
3b4c8c43 PP |
1317 | case 'T': |
1318 | format_trace_class(buf_ch, extended, prefix, obj); | |
1319 | break; | |
cb6f1f7d PP |
1320 | case 'K': |
1321 | format_clock_class(buf_ch, extended, prefix, obj); | |
1322 | break; | |
1323 | case 'k': | |
b1824349 | 1324 | format_clock_snapshot(buf_ch, extended, prefix, obj); |
cb6f1f7d PP |
1325 | break; |
1326 | case 'v': | |
1327 | format_value(buf_ch, extended, prefix, obj); | |
1328 | break; | |
1329 | case 'n': | |
c14831f0 | 1330 | format_message(buf_ch, extended, prefix, obj); |
cb6f1f7d PP |
1331 | break; |
1332 | case 'i': | |
c14831f0 | 1333 | format_message_iterator(buf_ch, extended, prefix, obj); |
cb6f1f7d PP |
1334 | break; |
1335 | case 'C': | |
1336 | format_component_class(buf_ch, extended, prefix, obj); | |
1337 | break; | |
1338 | case 'c': | |
1339 | format_component(buf_ch, extended, prefix, obj); | |
1340 | break; | |
1341 | case 'p': | |
1342 | format_port(buf_ch, extended, prefix, obj); | |
1343 | break; | |
1344 | case 'x': | |
1345 | format_connection(buf_ch, extended, prefix, obj); | |
1346 | break; | |
61f59358 | 1347 | case 'l': |
cb6f1f7d PP |
1348 | format_plugin(buf_ch, extended, prefix, obj); |
1349 | break; | |
1350 | case 'g': | |
1351 | format_graph(buf_ch, extended, prefix, obj); | |
1352 | break; | |
1353 | case 'o': | |
1354 | format_object_pool(buf_ch, extended, prefix, obj); | |
1355 | break; | |
1356 | case 'O': | |
1357 | format_object(buf_ch, extended, prefix, obj); | |
1358 | break; | |
1359 | default: | |
1360 | abort(); | |
476ef981 PP |
1361 | } |
1362 | ||
1363 | update_fmt: | |
1364 | fmt_ch++; | |
1365 | *out_fmt_ch = fmt_ch; | |
1366 | } | |
1367 | ||
1368 | BT_HIDDEN | |
1369 | void bt_lib_log(const char *func, const char *file, unsigned line, | |
1370 | int lvl, const char *tag, const char *fmt, ...) | |
1371 | { | |
1372 | va_list args; | |
1373 | ||
f6ccaed9 | 1374 | BT_ASSERT(fmt); |
476ef981 PP |
1375 | va_start(args, fmt); |
1376 | bt_common_custom_vsnprintf(lib_logging_buf, LIB_LOGGING_BUF_SIZE, '!', | |
1377 | handle_conversion_specifier_bt, NULL, fmt, &args); | |
1378 | va_end(args); | |
1379 | _bt_log_write_d(func, file, line, lvl, tag, "%s", lib_logging_buf); | |
1380 | } |