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