1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 #include <side/trace.h>
15 void tracer_print_struct(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
);
17 void tracer_print_array(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
);
19 void tracer_print_vla(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
);
21 void tracer_print_vla_visitor(const struct side_type_description
*type_desc
, void *app_ctx
);
23 void tracer_print_array_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
);
25 void tracer_print_vla_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
);
27 void tracer_print_dynamic(const struct side_arg_dynamic_vec
*dynamic_item
);
30 void tracer_print_attr_type(const struct side_attr
*attr
)
32 printf("{ key: \"%s\", value: ", attr
->key
);
33 switch (attr
->value
.type
) {
34 case SIDE_ATTR_TYPE_BOOL
:
35 printf("%s", attr
->value
.u
.side_bool
? "true" : "false");
37 case SIDE_ATTR_TYPE_U8
:
38 printf("%" PRIu8
, attr
->value
.u
.side_u8
);
40 case SIDE_ATTR_TYPE_U16
:
41 printf("%" PRIu16
, attr
->value
.u
.side_u16
);
43 case SIDE_ATTR_TYPE_U32
:
44 printf("%" PRIu32
, attr
->value
.u
.side_u32
);
46 case SIDE_ATTR_TYPE_U64
:
47 printf("%" PRIu64
, attr
->value
.u
.side_u64
);
49 case SIDE_ATTR_TYPE_S8
:
50 printf("%" PRId8
, attr
->value
.u
.side_s8
);
52 case SIDE_ATTR_TYPE_S16
:
53 printf("%" PRId16
, attr
->value
.u
.side_s16
);
55 case SIDE_ATTR_TYPE_S32
:
56 printf("%" PRId32
, attr
->value
.u
.side_s32
);
58 case SIDE_ATTR_TYPE_S64
:
59 printf("%" PRId64
, attr
->value
.u
.side_s64
);
61 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
63 printf("%g", (double) attr
->value
.u
.side_float_binary16
);
66 printf("ERROR: Unsupported binary16 float type\n");
69 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
71 printf("%g", (double) attr
->value
.u
.side_float_binary32
);
74 printf("ERROR: Unsupported binary32 float type\n");
77 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
79 printf("%g", (double) attr
->value
.u
.side_float_binary64
);
82 printf("ERROR: Unsupported binary64 float type\n");
85 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
87 printf("%Lg", (long double) attr
->value
.u
.side_float_binary128
);
90 printf("ERROR: Unsupported binary128 float type\n");
93 case SIDE_ATTR_TYPE_STRING
:
94 printf("\"%s\"", attr
->value
.u
.string
);
97 printf("<UNKNOWN TYPE>");
104 void print_attributes(const char *prefix_str
, const struct side_attr
*attr
, uint32_t nr_attr
)
110 printf("%s[ ", prefix_str
);
111 for (i
= 0; i
< nr_attr
; i
++) {
112 printf("%s", i
? ", " : "");
113 tracer_print_attr_type(&attr
[i
]);
119 void print_enum(const struct side_enum_mappings
*side_enum_mappings
, int64_t value
)
121 int i
, print_count
= 0;
123 printf("value: %" PRId64
", labels: [ ", value
);
124 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
125 const struct side_enum_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
127 if (mapping
->range_end
< mapping
->range_begin
) {
128 printf("ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
129 mapping
->range_begin
, mapping
->range_end
);
132 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
133 printf("%s", print_count
++ ? ", " : "");
134 printf("\"%s\"", mapping
->label
);
138 printf("<NO LABEL>");
143 void print_enum_bitmap(const struct side_enum_bitmap_mappings
*side_enum_mappings
, uint64_t value
)
145 int i
, print_count
= 0;
147 printf("value: 0x%" PRIx64
", labels: [ ", value
);
148 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
149 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
153 if (mapping
->range_begin
< 0 || mapping
->range_end
> 63
154 || mapping
->range_end
< mapping
->range_begin
) {
155 printf("ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
156 mapping
->range_begin
, mapping
->range_end
);
159 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
160 if (value
& (1ULL << bit
)) {
166 printf("%s", print_count
++ ? ", " : "");
167 printf("\"%s\"", mapping
->label
);
171 printf("<NO LABEL>");
176 void tracer_print_type(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
178 switch (item
->type
) {
179 case SIDE_TYPE_ARRAY_U8
:
180 case SIDE_TYPE_ARRAY_U16
:
181 case SIDE_TYPE_ARRAY_U32
:
182 case SIDE_TYPE_ARRAY_U64
:
183 case SIDE_TYPE_ARRAY_S8
:
184 case SIDE_TYPE_ARRAY_S16
:
185 case SIDE_TYPE_ARRAY_S32
:
186 case SIDE_TYPE_ARRAY_S64
:
187 case SIDE_TYPE_ARRAY_BLOB
:
188 if (type_desc
->type
!= SIDE_TYPE_ARRAY
) {
189 printf("ERROR: type mismatch between description and arguments\n");
193 case SIDE_TYPE_VLA_U8
:
194 case SIDE_TYPE_VLA_U16
:
195 case SIDE_TYPE_VLA_U32
:
196 case SIDE_TYPE_VLA_U64
:
197 case SIDE_TYPE_VLA_S8
:
198 case SIDE_TYPE_VLA_S16
:
199 case SIDE_TYPE_VLA_S32
:
200 case SIDE_TYPE_VLA_S64
:
201 case SIDE_TYPE_VLA_BLOB
:
202 if (type_desc
->type
!= SIDE_TYPE_VLA
) {
203 printf("ERROR: type mismatch between description and arguments\n");
209 if (type_desc
->type
!= item
->type
) {
210 printf("ERROR: type mismatch between description and arguments\n");
216 print_attributes("attr: ", type_desc
->attr
, type_desc
->nr_attr
);
217 printf("%s", type_desc
->nr_attr
? ", " : "");
218 switch (item
->type
) {
221 printf("%s", item
->u
.side_bool
? "true" : "false");
225 printf("%" PRIu8
, item
->u
.side_u8
);
229 printf("%" PRIu16
, item
->u
.side_u16
);
233 printf("%" PRIu32
, item
->u
.side_u32
);
237 printf("%" PRIu64
, item
->u
.side_u64
);
241 printf("%" PRId8
, item
->u
.side_s8
);
245 printf("%" PRId16
, item
->u
.side_s16
);
249 printf("%" PRId32
, item
->u
.side_s32
);
253 printf("%" PRId64
, item
->u
.side_s64
);
257 printf("0x%" PRIx8
, item
->u
.side_blob
);
260 case SIDE_TYPE_ENUM_U8
:
261 print_enum(type_desc
->u
.side_enum_mappings
,
262 (int64_t) item
->u
.side_u8
);
264 case SIDE_TYPE_ENUM_U16
:
265 print_enum(type_desc
->u
.side_enum_mappings
,
266 (int64_t) item
->u
.side_u16
);
268 case SIDE_TYPE_ENUM_U32
:
269 print_enum(type_desc
->u
.side_enum_mappings
,
270 (int64_t) item
->u
.side_u32
);
272 case SIDE_TYPE_ENUM_U64
:
273 print_enum(type_desc
->u
.side_enum_mappings
,
274 (int64_t) item
->u
.side_u64
);
276 case SIDE_TYPE_ENUM_S8
:
277 print_enum(type_desc
->u
.side_enum_mappings
,
278 (int64_t) item
->u
.side_s8
);
280 case SIDE_TYPE_ENUM_S16
:
281 print_enum(type_desc
->u
.side_enum_mappings
,
282 (int64_t) item
->u
.side_s16
);
284 case SIDE_TYPE_ENUM_S32
:
285 print_enum(type_desc
->u
.side_enum_mappings
,
286 (int64_t) item
->u
.side_s32
);
288 case SIDE_TYPE_ENUM_S64
:
289 print_enum(type_desc
->u
.side_enum_mappings
,
293 case SIDE_TYPE_ENUM_BITMAP8
:
294 print_enum_bitmap(type_desc
->u
.side_enum_bitmap_mappings
,
295 (uint64_t) item
->u
.side_u8
);
297 case SIDE_TYPE_ENUM_BITMAP16
:
298 print_enum_bitmap(type_desc
->u
.side_enum_bitmap_mappings
,
299 (uint64_t) item
->u
.side_u16
);
301 case SIDE_TYPE_ENUM_BITMAP32
:
302 print_enum_bitmap(type_desc
->u
.side_enum_bitmap_mappings
,
303 (uint64_t) item
->u
.side_u32
);
305 case SIDE_TYPE_ENUM_BITMAP64
:
306 print_enum_bitmap(type_desc
->u
.side_enum_bitmap_mappings
,
310 case SIDE_TYPE_FLOAT_BINARY16
:
313 printf("%g", (double) item
->u
.side_float_binary16
);
316 printf("ERROR: Unsupported binary16 float type\n");
319 case SIDE_TYPE_FLOAT_BINARY32
:
322 printf("%g", (double) item
->u
.side_float_binary32
);
325 printf("ERROR: Unsupported binary32 float type\n");
328 case SIDE_TYPE_FLOAT_BINARY64
:
331 printf("%g", (double) item
->u
.side_float_binary64
);
334 printf("ERROR: Unsupported binary64 float type\n");
337 case SIDE_TYPE_FLOAT_BINARY128
:
340 printf("%Lg", (long double) item
->u
.side_float_binary128
);
343 printf("ERROR: Unsupported binary128 float type\n");
346 case SIDE_TYPE_STRING
:
348 printf("\"%s\"", item
->u
.string
);
350 case SIDE_TYPE_STRUCT
:
351 tracer_print_struct(type_desc
, item
->u
.side_struct
);
353 case SIDE_TYPE_ARRAY
:
354 tracer_print_array(type_desc
, item
->u
.side_array
);
357 tracer_print_vla(type_desc
, item
->u
.side_vla
);
359 case SIDE_TYPE_VLA_VISITOR
:
360 tracer_print_vla_visitor(type_desc
, item
->u
.side_vla_app_visitor_ctx
);
362 case SIDE_TYPE_ARRAY_U8
:
363 case SIDE_TYPE_ARRAY_U16
:
364 case SIDE_TYPE_ARRAY_U32
:
365 case SIDE_TYPE_ARRAY_U64
:
366 case SIDE_TYPE_ARRAY_S8
:
367 case SIDE_TYPE_ARRAY_S16
:
368 case SIDE_TYPE_ARRAY_S32
:
369 case SIDE_TYPE_ARRAY_S64
:
370 case SIDE_TYPE_ARRAY_BLOB
:
371 tracer_print_array_fixint(type_desc
, item
);
373 case SIDE_TYPE_VLA_U8
:
374 case SIDE_TYPE_VLA_U16
:
375 case SIDE_TYPE_VLA_U32
:
376 case SIDE_TYPE_VLA_U64
:
377 case SIDE_TYPE_VLA_S8
:
378 case SIDE_TYPE_VLA_S16
:
379 case SIDE_TYPE_VLA_S32
:
380 case SIDE_TYPE_VLA_S64
:
381 case SIDE_TYPE_VLA_BLOB
:
382 tracer_print_vla_fixint(type_desc
, item
);
384 case SIDE_TYPE_DYNAMIC
:
385 tracer_print_dynamic(&item
->u
.dynamic
);
388 printf("<UNKNOWN TYPE>");
395 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg_vec
*item
)
397 printf("%s: ", item_desc
->field_name
);
398 tracer_print_type(&item_desc
->side_type
, item
);
402 void tracer_print_struct(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
404 const struct side_arg_vec
*sav
= sav_desc
->sav
;
405 uint32_t side_sav_len
= sav_desc
->len
;
408 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
409 printf("ERROR: number of fields mismatch between description and arguments of structure\n");
413 print_attributes("attr: ", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
414 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
415 printf("fields: { ");
416 for (i
= 0; i
< side_sav_len
; i
++) {
417 printf("%s", i
? ", " : "");
418 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
424 void tracer_print_array(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
426 const struct side_arg_vec
*sav
= sav_desc
->sav
;
427 uint32_t side_sav_len
= sav_desc
->len
;
430 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
431 printf("ERROR: length mismatch between description and arguments of array\n");
436 for (i
= 0; i
< side_sav_len
; i
++) {
437 printf("%s", i
? ", " : "");
438 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
444 void tracer_print_vla(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
446 const struct side_arg_vec
*sav
= sav_desc
->sav
;
447 uint32_t side_sav_len
= sav_desc
->len
;
452 for (i
= 0; i
< side_sav_len
; i
++) {
453 printf("%s", i
? ", " : "");
454 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
459 struct tracer_visitor_priv
{
460 const struct side_type_description
*elem_type
;
465 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
466 const struct side_arg_vec
*elem
)
468 struct tracer_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
470 printf("%s", tracer_priv
->i
++ ? ", " : "");
471 tracer_print_type(tracer_priv
->elem_type
, elem
);
472 return SIDE_VISITOR_STATUS_OK
;
476 void tracer_print_vla_visitor(const struct side_type_description
*type_desc
, void *app_ctx
)
478 enum side_visitor_status status
;
479 struct tracer_visitor_priv tracer_priv
= {
480 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
483 const struct side_tracer_visitor_ctx tracer_ctx
= {
484 .write_elem
= tracer_write_elem_cb
,
485 .priv
= &tracer_priv
,
490 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
492 case SIDE_VISITOR_STATUS_OK
:
494 case SIDE_VISITOR_STATUS_ERROR
:
495 printf("ERROR: Visitor error\n");
501 void tracer_print_array_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
503 const struct side_type_description
*elem_type
= type_desc
->u
.side_array
.elem_type
;
504 uint32_t side_sav_len
= type_desc
->u
.side_array
.length
;
505 void *p
= item
->u
.side_array_fixint
;
506 enum side_type side_type
;
510 switch (item
->type
) {
511 case SIDE_TYPE_ARRAY_U8
:
512 if (elem_type
->type
!= SIDE_TYPE_U8
)
515 case SIDE_TYPE_ARRAY_U16
:
516 if (elem_type
->type
!= SIDE_TYPE_U16
)
519 case SIDE_TYPE_ARRAY_U32
:
520 if (elem_type
->type
!= SIDE_TYPE_U32
)
523 case SIDE_TYPE_ARRAY_U64
:
524 if (elem_type
->type
!= SIDE_TYPE_U64
)
527 case SIDE_TYPE_ARRAY_S8
:
528 if (elem_type
->type
!= SIDE_TYPE_S8
)
531 case SIDE_TYPE_ARRAY_S16
:
532 if (elem_type
->type
!= SIDE_TYPE_S16
)
535 case SIDE_TYPE_ARRAY_S32
:
536 if (elem_type
->type
!= SIDE_TYPE_S32
)
539 case SIDE_TYPE_ARRAY_S64
:
540 if (elem_type
->type
!= SIDE_TYPE_S64
)
543 case SIDE_TYPE_ARRAY_BLOB
:
544 if (elem_type
->type
!= SIDE_TYPE_BLOB
)
550 side_type
= elem_type
->type
;
553 for (i
= 0; i
< side_sav_len
; i
++) {
554 struct side_arg_vec sav_elem
= {
560 sav_elem
.u
.side_u8
= ((const uint8_t *) p
)[i
];
563 sav_elem
.u
.side_s8
= ((const int8_t *) p
)[i
];
566 sav_elem
.u
.side_u16
= ((const uint16_t *) p
)[i
];
569 sav_elem
.u
.side_s16
= ((const int16_t *) p
)[i
];
572 sav_elem
.u
.side_u32
= ((const uint32_t *) p
)[i
];
575 sav_elem
.u
.side_s32
= ((const int32_t *) p
)[i
];
578 sav_elem
.u
.side_u64
= ((const uint64_t *) p
)[i
];
581 sav_elem
.u
.side_s64
= ((const int64_t *) p
)[i
];
584 sav_elem
.u
.side_blob
= ((const uint8_t *) p
)[i
];
588 printf("ERROR: Unexpected type\n");
592 printf("%s", i
? ", " : "");
593 tracer_print_type(elem_type
, &sav_elem
);
599 printf("ERROR: type mismatch\n");
603 void tracer_print_vla_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
605 const struct side_type_description
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
606 uint32_t side_sav_len
= item
->u
.side_vla_fixint
.length
;
607 void *p
= item
->u
.side_vla_fixint
.p
;
608 enum side_type side_type
;
611 switch (item
->type
) {
612 case SIDE_TYPE_VLA_U8
:
613 if (elem_type
->type
!= SIDE_TYPE_U8
)
616 case SIDE_TYPE_VLA_U16
:
617 if (elem_type
->type
!= SIDE_TYPE_U16
)
620 case SIDE_TYPE_VLA_U32
:
621 if (elem_type
->type
!= SIDE_TYPE_U32
)
624 case SIDE_TYPE_VLA_U64
:
625 if (elem_type
->type
!= SIDE_TYPE_U64
)
628 case SIDE_TYPE_VLA_S8
:
629 if (elem_type
->type
!= SIDE_TYPE_S8
)
632 case SIDE_TYPE_VLA_S16
:
633 if (elem_type
->type
!= SIDE_TYPE_S16
)
636 case SIDE_TYPE_VLA_S32
:
637 if (elem_type
->type
!= SIDE_TYPE_S32
)
640 case SIDE_TYPE_VLA_S64
:
641 if (elem_type
->type
!= SIDE_TYPE_S64
)
644 case SIDE_TYPE_VLA_BLOB
:
645 if (elem_type
->type
!= SIDE_TYPE_BLOB
)
651 side_type
= elem_type
->type
;
654 for (i
= 0; i
< side_sav_len
; i
++) {
655 struct side_arg_vec sav_elem
= {
661 sav_elem
.u
.side_u8
= ((const uint8_t *) p
)[i
];
664 sav_elem
.u
.side_s8
= ((const int8_t *) p
)[i
];
667 sav_elem
.u
.side_u16
= ((const uint16_t *) p
)[i
];
670 sav_elem
.u
.side_s16
= ((const int16_t *) p
)[i
];
673 sav_elem
.u
.side_u32
= ((const uint32_t *) p
)[i
];
676 sav_elem
.u
.side_s32
= ((const int32_t *) p
)[i
];
679 sav_elem
.u
.side_u64
= ((const uint64_t *) p
)[i
];
682 sav_elem
.u
.side_s64
= ((const int64_t *) p
)[i
];
685 sav_elem
.u
.side_blob
= ((const uint8_t *) p
)[i
];
689 printf("ERROR: Unexpected type\n");
693 printf("%s", i
? ", " : "");
694 tracer_print_type(elem_type
, &sav_elem
);
700 printf("ERROR: type mismatch\n");
705 void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct
*dynamic_struct
)
707 const struct side_arg_dynamic_event_field
*fields
= dynamic_struct
->fields
;
708 uint32_t len
= dynamic_struct
->len
;
712 for (i
= 0; i
< len
; i
++) {
713 printf("%s", i
? ", " : "");
714 printf("%s:: ", fields
[i
].field_name
);
715 tracer_print_dynamic(&fields
[i
].elem
);
720 struct tracer_dynamic_struct_visitor_priv
{
725 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
726 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
727 const struct side_arg_dynamic_event_field
*dynamic_field
)
729 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
731 printf("%s", tracer_priv
->i
++ ? ", " : "");
732 printf("%s:: ", dynamic_field
->field_name
);
733 tracer_print_dynamic(&dynamic_field
->elem
);
734 return SIDE_VISITOR_STATUS_OK
;
738 void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec
*item
)
740 enum side_visitor_status status
;
741 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
744 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
745 .write_field
= tracer_dynamic_struct_write_elem_cb
,
746 .priv
= &tracer_priv
,
748 void *app_ctx
= item
->u
.side_dynamic_struct_visitor
.app_ctx
;
751 status
= item
->u
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
753 case SIDE_VISITOR_STATUS_OK
:
755 case SIDE_VISITOR_STATUS_ERROR
:
756 printf("ERROR: Visitor error\n");
763 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla
*vla
)
765 const struct side_arg_dynamic_vec
*sav
= vla
->sav
;
766 uint32_t side_sav_len
= vla
->len
;
770 for (i
= 0; i
< side_sav_len
; i
++) {
771 printf("%s", i
? ", " : "");
772 tracer_print_dynamic(&sav
[i
]);
777 struct tracer_dynamic_vla_visitor_priv
{
782 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
783 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
784 const struct side_arg_dynamic_vec
*elem
)
786 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
788 printf("%s", tracer_priv
->i
++ ? ", " : "");
789 tracer_print_dynamic(elem
);
790 return SIDE_VISITOR_STATUS_OK
;
794 void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec
*item
)
796 enum side_visitor_status status
;
797 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
800 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx
= {
801 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
802 .priv
= &tracer_priv
,
804 void *app_ctx
= item
->u
.side_dynamic_vla_visitor
.app_ctx
;
807 status
= item
->u
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
809 case SIDE_VISITOR_STATUS_OK
:
811 case SIDE_VISITOR_STATUS_ERROR
:
812 printf("ERROR: Visitor error\n");
819 void tracer_print_dynamic(const struct side_arg_dynamic_vec
*item
)
822 print_attributes("attr: ", item
->attr
, item
->nr_attr
);
823 printf("%s", item
->nr_attr
? ", " : "");
825 switch (item
->dynamic_type
) {
826 case SIDE_DYNAMIC_TYPE_NULL
:
827 printf("<NULL TYPE>");
829 case SIDE_DYNAMIC_TYPE_BOOL
:
830 printf("%s", item
->u
.side_bool
? "true" : "false");
832 case SIDE_DYNAMIC_TYPE_U8
:
833 printf("%" PRIu8
, item
->u
.side_u8
);
835 case SIDE_DYNAMIC_TYPE_U16
:
836 printf("%" PRIu16
, item
->u
.side_u16
);
838 case SIDE_DYNAMIC_TYPE_U32
:
839 printf("%" PRIu32
, item
->u
.side_u32
);
841 case SIDE_DYNAMIC_TYPE_U64
:
842 printf("%" PRIu64
, item
->u
.side_u64
);
844 case SIDE_DYNAMIC_TYPE_S8
:
845 printf("%" PRId8
, item
->u
.side_s8
);
847 case SIDE_DYNAMIC_TYPE_S16
:
848 printf("%" PRId16
, item
->u
.side_s16
);
850 case SIDE_DYNAMIC_TYPE_S32
:
851 printf("%" PRId32
, item
->u
.side_s32
);
853 case SIDE_DYNAMIC_TYPE_S64
:
854 printf("%" PRId64
, item
->u
.side_s64
);
856 case SIDE_DYNAMIC_TYPE_BLOB
:
857 printf("0x%" PRIx8
, item
->u
.side_blob
);
860 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
:
862 printf("%g", (double) item
->u
.side_float_binary16
);
865 printf("ERROR: Unsupported binary16 float type\n");
868 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
:
870 printf("%g", (double) item
->u
.side_float_binary32
);
873 printf("ERROR: Unsupported binary32 float type\n");
876 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
:
878 printf("%g", (double) item
->u
.side_float_binary64
);
881 printf("ERROR: Unsupported binary64 float type\n");
884 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
:
886 printf("%Lg", (long double) item
->u
.side_float_binary128
);
889 printf("ERROR: Unsupported binary128 float type\n");
892 case SIDE_DYNAMIC_TYPE_STRING
:
893 printf("\"%s\"", item
->u
.string
);
895 case SIDE_DYNAMIC_TYPE_STRUCT
:
896 tracer_print_dynamic_struct(item
->u
.side_dynamic_struct
);
898 case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
:
899 tracer_print_dynamic_struct_visitor(item
);
901 case SIDE_DYNAMIC_TYPE_VLA
:
902 tracer_print_dynamic_vla(item
->u
.side_dynamic_vla
);
904 case SIDE_DYNAMIC_TYPE_VLA_VISITOR
:
905 tracer_print_dynamic_vla_visitor(item
);
908 printf("<UNKNOWN TYPE>");
915 void tracer_print_static_fields(const struct side_event_description
*desc
,
916 const struct side_arg_vec_description
*sav_desc
,
919 const struct side_arg_vec
*sav
= sav_desc
->sav
;
920 uint32_t side_sav_len
= sav_desc
->len
;
923 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
924 if (desc
->nr_fields
!= side_sav_len
) {
925 printf("ERROR: number of fields mismatch between description and arguments\n");
928 print_attributes(", attributes: ", desc
->attr
, desc
->nr_attr
);
929 printf("%s", side_sav_len
? ", fields: [ " : "");
930 for (i
= 0; i
< side_sav_len
; i
++) {
931 printf("%s", i
? ", " : "");
932 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
938 void tracer_call(const struct side_event_description
*desc
,
939 const struct side_arg_vec_description
*sav_desc
,
940 void *priv
__attribute__((unused
)))
944 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
950 void tracer_call_variadic(const struct side_event_description
*desc
,
951 const struct side_arg_vec_description
*sav_desc
,
952 const struct side_arg_dynamic_event_struct
*var_struct
,
953 void *priv
__attribute__((unused
)))
955 uint32_t var_struct_len
= var_struct
->len
;
956 int nr_fields
= 0, i
;
958 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
960 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
961 printf("ERROR: unexpected non-variadic event description\n");
964 printf("%s", var_struct_len
&& !nr_fields
? ", fields: [ " : "");
965 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
966 printf("%s", nr_fields
? ", " : "");
967 printf("%s:: ", var_struct
->fields
[i
].field_name
);
968 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);