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