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