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