1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 #include <side/macros.h>
16 /* SIDE stands for "Static Instrumentation Dynamically Enabled" */
18 //TODO: as those structures will be ABI, we need to either consider them
19 //fixed forever, or think of a scheme that would allow their binary
20 //representation to be extended if need be.
23 struct side_arg_vec_description
;
24 struct side_arg_dynamic_vec
;
25 struct side_arg_dynamic_vec_vla
;
26 struct side_type_description
;
27 struct side_event_field
;
28 struct side_tracer_visitor_ctx
;
29 struct side_tracer_dynamic_struct_visitor_ctx
;
30 struct side_tracer_dynamic_vla_visitor_ctx
;
53 SIDE_TYPE_ENUM_BITMAP8
,
54 SIDE_TYPE_ENUM_BITMAP16
,
55 SIDE_TYPE_ENUM_BITMAP32
,
56 SIDE_TYPE_ENUM_BITMAP64
,
58 SIDE_TYPE_FLOAT_BINARY16
,
59 SIDE_TYPE_FLOAT_BINARY32
,
60 SIDE_TYPE_FLOAT_BINARY64
,
61 SIDE_TYPE_FLOAT_BINARY128
,
68 SIDE_TYPE_VLA_VISITOR
,
91 enum side_dynamic_type
{
92 SIDE_DYNAMIC_TYPE_NULL
,
94 SIDE_DYNAMIC_TYPE_BOOL
,
97 SIDE_DYNAMIC_TYPE_U16
,
98 SIDE_DYNAMIC_TYPE_U32
,
99 SIDE_DYNAMIC_TYPE_U64
,
100 SIDE_DYNAMIC_TYPE_S8
,
101 SIDE_DYNAMIC_TYPE_S16
,
102 SIDE_DYNAMIC_TYPE_S32
,
103 SIDE_DYNAMIC_TYPE_S64
,
105 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
,
106 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
,
107 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
,
108 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
,
110 SIDE_DYNAMIC_TYPE_STRING
,
112 SIDE_DYNAMIC_TYPE_STRUCT
,
113 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
,
115 SIDE_DYNAMIC_TYPE_VLA
,
116 SIDE_DYNAMIC_TYPE_VLA_VISITOR
,
119 enum side_attr_type
{
131 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
132 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
133 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
134 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
136 SIDE_ATTR_TYPE_STRING
,
140 SIDE_LOGLEVEL_EMERG
= 0,
141 SIDE_LOGLEVEL_ALERT
= 1,
142 SIDE_LOGLEVEL_CRIT
= 2,
143 SIDE_LOGLEVEL_ERR
= 3,
144 SIDE_LOGLEVEL_WARNING
= 4,
145 SIDE_LOGLEVEL_NOTICE
= 5,
146 SIDE_LOGLEVEL_INFO
= 6,
147 SIDE_LOGLEVEL_DEBUG
= 7,
150 enum side_visitor_status
{
151 SIDE_VISITOR_STATUS_OK
= 0,
152 SIDE_VISITOR_STATUS_ERROR
= -1,
155 typedef enum side_visitor_status (*side_visitor
)(
156 const struct side_tracer_visitor_ctx
*tracer_ctx
,
158 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
159 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
161 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
162 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
165 struct side_attr_value
{
166 uint32_t type
; /* enum side_attr_type */
180 _Float16 side_float_binary16
;
183 _Float32 side_float_binary32
;
186 _Float64 side_float_binary64
;
189 _Float128 side_float_binary128
;
196 /* User attributes. */
199 const struct side_attr_value value
;
202 struct side_enum_mapping
{
208 struct side_enum_mappings
{
209 const struct side_enum_mapping
*mappings
;
210 uint32_t nr_mappings
;
213 struct side_type_description
{
214 uint32_t type
; /* enum side_type */
216 const struct side_attr
*attr
;
220 const struct side_event_field
*fields
;
224 const struct side_type_description
*elem_type
;
227 const struct side_type_description
*elem_type
;
230 const struct side_type_description
*elem_type
;
231 side_visitor visitor
;
233 const struct side_enum_mappings
*side_enum_mappings
;
237 struct side_event_field
{
238 const char *field_name
;
239 struct side_type_description side_type
;
242 enum side_event_flags
{
243 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
246 #define SIDE_EVENT_ENABLED_USER_MASK 0x0000FFFF
247 #define SIDE_EVENT_ENABLED_KERNEL_USER_EVENT_MASK 0x80000000
249 struct side_event_description
{
252 uint32_t loglevel
; /* enum side_loglevel */
257 const char *provider_name
;
258 const char *event_name
;
259 const struct side_event_field
*fields
;
260 const struct side_attr
*attr
;
263 struct side_arg_dynamic_vec_vla
{
264 const struct side_arg_dynamic_vec
*sav
;
268 struct side_arg_dynamic_vec
{
269 uint32_t dynamic_type
; /* enum side_dynamic_type */
271 const struct side_attr
*attr
;
285 _Float16 side_float_binary16
;
288 _Float32 side_float_binary32
;
291 _Float64 side_float_binary64
;
294 _Float128 side_float_binary128
;
299 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
302 side_dynamic_struct_visitor visitor
;
303 } side_dynamic_struct_visitor
;
305 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
308 side_dynamic_vla_visitor visitor
;
309 } side_dynamic_vla_visitor
;
313 struct side_arg_dynamic_event_field
{
314 const char *field_name
;
315 const struct side_arg_dynamic_vec elem
;
318 struct side_arg_dynamic_event_struct
{
319 const struct side_arg_dynamic_event_field
*fields
;
323 struct side_arg_vec
{
338 _Float16 side_float_binary16
;
341 _Float32 side_float_binary32
;
344 _Float64 side_float_binary64
;
347 _Float128 side_float_binary128
;
351 const struct side_arg_vec_description
*side_struct
;
352 const struct side_arg_vec_description
*side_array
;
353 const struct side_arg_vec_description
*side_vla
;
354 void *side_vla_app_visitor_ctx
;
356 void *side_array_fixint
;
362 struct side_arg_dynamic_vec dynamic
;
366 struct side_arg_vec_description
{
367 const struct side_arg_vec
*sav
;
371 /* The visitor pattern is a double-dispatch visitor. */
372 struct side_tracer_visitor_ctx
{
373 enum side_visitor_status (*write_elem
)(
374 const struct side_tracer_visitor_ctx
*tracer_ctx
,
375 const struct side_arg_vec
*elem
);
376 void *priv
; /* Private tracer context. */
379 struct side_tracer_dynamic_struct_visitor_ctx
{
380 enum side_visitor_status (*write_field
)(
381 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
382 const struct side_arg_dynamic_event_field
*dynamic_field
);
383 void *priv
; /* Private tracer context. */
386 struct side_tracer_dynamic_vla_visitor_ctx
{
387 enum side_visitor_status (*write_elem
)(
388 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
389 const struct side_arg_dynamic_vec
*elem
);
390 void *priv
; /* Private tracer context. */
393 #define side_attr(_key, _value) \
396 .value = SIDE_PARAM(_value), \
399 #define side_attr_list(...) \
400 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
402 #define side_type_decl(_type, _attr) \
405 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
409 #define side_field(_name, _type, _attr) \
411 .field_name = _name, \
412 .side_type = side_type_decl(_type, SIDE_PARAM(_attr)), \
415 #define side_type_enum_decl(_type, _mappings, _attr) \
418 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
421 .side_enum_mappings = _mappings, \
424 #define side_field_enum(_name, _type, _mappings, _attr) \
426 .field_name = _name, \
427 .side_type = side_type_enum_decl(_type, SIDE_PARAM(_mappings), SIDE_PARAM(_attr)), \
430 #define side_type_struct_decl(_fields, _attr) \
432 .type = SIDE_TYPE_STRUCT, \
433 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
437 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
442 #define side_field_struct(_name, _fields, _attr) \
444 .field_name = _name, \
445 .side_type = side_type_struct_decl(SIDE_PARAM(_fields), SIDE_PARAM(_attr)), \
448 #define side_type_array_decl(_elem_type, _length, _attr) \
450 .type = SIDE_TYPE_ARRAY, \
451 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
456 .elem_type = _elem_type, \
460 #define side_field_array(_name, _elem_type, _length, _attr) \
462 .field_name = _name, \
463 .side_type = side_type_array_decl(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)), \
466 #define side_type_vla_decl(_elem_type, _attr) \
468 .type = SIDE_TYPE_VLA, \
469 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
473 .elem_type = _elem_type, \
477 #define side_field_vla(_name, _elem_type, _attr) \
479 .field_name = _name, \
480 .side_type = side_type_vla_decl(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)), \
483 #define side_type_vla_visitor_decl(_elem_type, _visitor, _attr) \
485 .type = SIDE_TYPE_VLA_VISITOR, \
486 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
489 .side_vla_visitor = { \
490 .elem_type = SIDE_PARAM(_elem_type), \
491 .visitor = _visitor, \
495 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
497 .field_name = _name, \
498 .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)), \
501 #define side_elem(...) \
502 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
504 #define side_elem_type(_type, _attr) \
505 side_elem(side_type_decl(_type, SIDE_PARAM(_attr)))
507 #define side_field_list(...) \
508 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
510 #define side_arg_bool(val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(val) } }
511 #define side_arg_u8(val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (val) } }
512 #define side_arg_u16(val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (val) } }
513 #define side_arg_u32(val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (val) } }
514 #define side_arg_u64(val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (val) } }
515 #define side_arg_s8(val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (val) } }
516 #define side_arg_s16(val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } }
517 #define side_arg_s32(val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } }
518 #define side_arg_s64(val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } }
519 #define side_arg_enum_u8(val) { .type = SIDE_TYPE_ENUM_U8, .u = { .side_u8 = (val) } }
520 #define side_arg_enum_u16(val) { .type = SIDE_TYPE_ENUM_U16, .u = { .side_u16 = (val) } }
521 #define side_arg_enum_u32(val) { .type = SIDE_TYPE_ENUM_U32, .u = { .side_u32 = (val) } }
522 #define side_arg_enum_u64(val) { .type = SIDE_TYPE_ENUM_U64, .u = { .side_u64 = (val) } }
523 #define side_arg_enum_s8(val) { .type = SIDE_TYPE_ENUM_S8, .u = { .side_s8 = (val) } }
524 #define side_arg_enum_s16(val) { .type = SIDE_TYPE_ENUM_S16, .u = { .side_s16 = (val) } }
525 #define side_arg_enum_s32(val) { .type = SIDE_TYPE_ENUM_S32, .u = { .side_s32 = (val) } }
526 #define side_arg_enum_s64(val) { .type = SIDE_TYPE_ENUM_S64, .u = { .side_s64 = (val) } }
527 #define side_arg_enum_bitmap8(val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (val) } }
528 #define side_arg_enum_bitmap16(val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (val) } }
529 #define side_arg_enum_bitmap32(val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (val) } }
530 #define side_arg_enum_bitmap64(val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (val) } }
531 #define side_arg_float_binary16(val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (val) } }
532 #define side_arg_float_binary32(val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (val) } }
533 #define side_arg_float_binary64(val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (val) } }
534 #define side_arg_float_binary128(val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (val) } }
536 #define side_arg_string(val) { .type = SIDE_TYPE_STRING, .u = { .string = (val) } }
537 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
538 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
539 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
540 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
542 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
543 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
544 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
545 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
546 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
547 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
548 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
549 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
551 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
552 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
553 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
554 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
555 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
556 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
557 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
558 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
560 #define side_arg_dynamic(dynamic_arg_type) \
562 .type = SIDE_TYPE_DYNAMIC, \
564 .dynamic = dynamic_arg_type, \
568 #define side_arg_dynamic_null(_attr) \
570 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
571 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
575 #define side_arg_dynamic_bool(_val, _attr) \
577 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
578 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
581 .side_bool = !!(_val), \
585 #define side_arg_dynamic_u8(_val, _attr) \
587 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
588 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
594 #define side_arg_dynamic_u16(_val, _attr) \
596 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
597 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
600 .side_u16 = (_val), \
603 #define side_arg_dynamic_u32(_val, _attr) \
605 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
606 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
609 .side_u32 = (_val), \
612 #define side_arg_dynamic_u64(_val, _attr) \
614 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
615 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
618 .side_u64 = (_val), \
622 #define side_arg_dynamic_s8(_val, _attr) \
624 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
625 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
631 #define side_arg_dynamic_s16(_val, _attr) \
633 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
634 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
637 .side_s16 = (_val), \
640 #define side_arg_dynamic_s32(_val, _attr) \
642 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
643 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
646 .side_s32 = (_val), \
649 #define side_arg_dynamic_s64(_val, _attr) \
651 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
652 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
655 .side_s64 = (_val), \
659 #define side_arg_dynamic_float_binary16(_val, _attr) \
661 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
662 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
665 .side_float_binary16 = (_val), \
668 #define side_arg_dynamic_float_binary32(_val, _attr) \
670 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
671 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
674 .side_float_binary32 = (_val), \
677 #define side_arg_dynamic_float_binary64(_val, _attr) \
679 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
680 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
683 .side_float_binary64 = (_val), \
686 #define side_arg_dynamic_float_binary128(_val, _attr) \
688 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
689 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
692 .side_float_binary128 = (_val), \
696 #define side_arg_dynamic_string(_val, _attr) \
698 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
699 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
706 #define side_arg_dynamic_vla(_vla, _attr) \
708 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
709 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
712 .side_dynamic_vla = (_vla), \
716 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
718 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
719 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
722 .side_dynamic_vla_visitor = { \
724 .visitor = _dynamic_vla_visitor, \
729 #define side_arg_dynamic_struct(_struct, _attr) \
731 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
732 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
735 .side_dynamic_struct = (_struct), \
739 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
741 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
742 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
745 .side_dynamic_struct_visitor = { \
747 .visitor = _dynamic_struct_visitor, \
752 #define side_arg_dynamic_define_vec(_identifier, _sav) \
753 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
754 const struct side_arg_dynamic_vec_vla _identifier = { \
755 .sav = _identifier##_vec, \
756 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
759 #define side_arg_dynamic_define_struct(_identifier, _struct_fields) \
760 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
761 const struct side_arg_dynamic_event_struct _identifier = { \
762 .fields = _identifier##_fields, \
763 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
766 #define side_arg_define_vec(_identifier, _sav) \
767 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
768 const struct side_arg_vec_description _identifier = { \
769 .sav = _identifier##_vec, \
770 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
773 #define side_arg_dynamic_field(_name, _elem) \
775 .field_name = _name, \
779 #define side_arg_list(...) __VA_ARGS__
781 #define side_attr_bool(val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(val) } }
782 #define side_attr_u8(val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (val) } }
783 #define side_attr_u16(val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (val) } }
784 #define side_attr_u32(val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (val) } }
785 #define side_attr_u64(val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (val) } }
786 #define side_attr_s8(val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (val) } }
787 #define side_attr_s16(val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (val) } }
788 #define side_attr_s32(val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (val) } }
789 #define side_attr_s64(val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (val) } }
790 #define side_attr_float_binary16(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (val) } }
791 #define side_attr_float_binary32(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (val) } }
792 #define side_attr_float_binary64(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (val) } }
793 #define side_attr_float_binary128(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (val) } }
794 #define side_attr_string(val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (val) } }
796 #define side_event_cond(desc) if (side_unlikely((desc)->enabled))
798 #define side_event_call(desc, _sav) \
800 const struct side_arg_vec side_sav[] = { _sav }; \
801 const struct side_arg_vec_description sav_desc = { \
803 .len = SIDE_ARRAY_SIZE(side_sav), \
805 side_call(desc, &sav_desc); \
808 #define side_event(desc, sav) \
809 side_event_cond(desc) \
810 side_event_call(desc, SIDE_PARAM(sav))
812 #define side_event_call_variadic(desc, _sav, _var_fields) \
814 const struct side_arg_vec side_sav[] = { _sav }; \
815 const struct side_arg_vec_description sav_desc = { \
817 .len = SIDE_ARRAY_SIZE(side_sav), \
819 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
820 const struct side_arg_dynamic_event_struct var_struct = { \
821 .fields = side_fields, \
822 .len = SIDE_ARRAY_SIZE(side_fields), \
824 side_call_variadic(desc, &sav_desc, &var_struct); \
827 #define side_event_variadic(desc, sav, var) \
828 side_event_cond(desc) \
829 side_event_call_variadic(desc, SIDE_PARAM(sav), SIDE_PARAM(var))
831 #define side_define_enum(_identifier, _mappings) \
832 const struct side_enum_mappings _identifier = { \
833 .mappings = _mappings, \
834 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
837 #define side_mapping_list(...) \
838 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
840 #define side_enum_mapping_range(_label, _begin, _end) \
842 .range_begin = _begin, \
847 #define side_enum_mapping_value(_label, _value) \
849 .range_begin = _value, \
850 .range_end = _value, \
854 #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
855 struct side_event_description _identifier = { \
858 .loglevel = _loglevel, \
859 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
860 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
862 .provider_name = _provider, \
863 .event_name = _event, \
868 #define side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
869 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
870 SIDE_PARAM(_attr), 0)
872 #define side_define_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
873 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
874 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
876 #define side_declare_event(_identifier) \
877 struct side_event_description _identifier
879 void side_call(const struct side_event_description
*desc
,
880 const struct side_arg_vec_description
*sav_desc
);
881 void side_call_variadic(const struct side_event_description
*desc
,
882 const struct side_arg_vec_description
*sav_desc
,
883 const struct side_arg_dynamic_event_struct
*var_struct
);
885 #endif /* _SIDE_TRACE_H */