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