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 struct side_event_description
{
249 uint32_t loglevel
; /* enum side_loglevel */
254 const char *provider_name
;
255 const char *event_name
;
256 const struct side_event_field
*fields
;
257 const struct side_attr
*attr
;
260 struct side_arg_dynamic_vec_vla
{
261 const struct side_arg_dynamic_vec
*sav
;
265 struct side_arg_dynamic_vec
{
266 uint32_t dynamic_type
; /* enum side_dynamic_type */
268 const struct side_attr
*attr
;
282 _Float16 side_float_binary16
;
285 _Float32 side_float_binary32
;
288 _Float64 side_float_binary64
;
291 _Float128 side_float_binary128
;
296 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
299 side_dynamic_struct_visitor visitor
;
300 } side_dynamic_struct_visitor
;
302 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
305 side_dynamic_vla_visitor visitor
;
306 } side_dynamic_vla_visitor
;
310 struct side_arg_dynamic_event_field
{
311 const char *field_name
;
312 const struct side_arg_dynamic_vec elem
;
315 struct side_arg_dynamic_event_struct
{
316 const struct side_arg_dynamic_event_field
*fields
;
320 struct side_arg_vec
{
335 _Float16 side_float_binary16
;
338 _Float32 side_float_binary32
;
341 _Float64 side_float_binary64
;
344 _Float128 side_float_binary128
;
348 const struct side_arg_vec_description
*side_struct
;
349 const struct side_arg_vec_description
*side_array
;
350 const struct side_arg_vec_description
*side_vla
;
351 void *side_vla_app_visitor_ctx
;
353 void *side_array_fixint
;
359 struct side_arg_dynamic_vec dynamic
;
363 struct side_arg_vec_description
{
364 const struct side_arg_vec
*sav
;
368 /* The visitor pattern is a double-dispatch visitor. */
369 struct side_tracer_visitor_ctx
{
370 enum side_visitor_status (*write_elem
)(
371 const struct side_tracer_visitor_ctx
*tracer_ctx
,
372 const struct side_arg_vec
*elem
);
373 void *priv
; /* Private tracer context. */
376 struct side_tracer_dynamic_struct_visitor_ctx
{
377 enum side_visitor_status (*write_field
)(
378 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
379 const struct side_arg_dynamic_event_field
*dynamic_field
);
380 void *priv
; /* Private tracer context. */
383 struct side_tracer_dynamic_vla_visitor_ctx
{
384 enum side_visitor_status (*write_elem
)(
385 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
386 const struct side_arg_dynamic_vec
*elem
);
387 void *priv
; /* Private tracer context. */
390 #define side_attr(_key, _value) \
393 .value = SIDE_PARAM(_value), \
396 #define side_attr_list(...) \
397 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
399 #define side_type_decl(_type, _attr) \
402 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
406 #define side_field(_name, _type, _attr) \
408 .field_name = _name, \
409 .side_type = side_type_decl(_type, SIDE_PARAM(_attr)), \
412 #define side_type_enum_decl(_type, _mappings, _attr) \
415 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
418 .side_enum_mappings = _mappings, \
421 #define side_field_enum(_name, _type, _mappings, _attr) \
423 .field_name = _name, \
424 .side_type = side_type_enum_decl(_type, SIDE_PARAM(_mappings), SIDE_PARAM(_attr)), \
427 #define side_type_struct_decl(_fields, _attr) \
429 .type = SIDE_TYPE_STRUCT, \
430 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
434 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
439 #define side_field_struct(_name, _fields, _attr) \
441 .field_name = _name, \
442 .side_type = side_type_struct_decl(SIDE_PARAM(_fields), SIDE_PARAM(_attr)), \
445 #define side_type_array_decl(_elem_type, _length, _attr) \
447 .type = SIDE_TYPE_ARRAY, \
448 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
453 .elem_type = _elem_type, \
457 #define side_field_array(_name, _elem_type, _length, _attr) \
459 .field_name = _name, \
460 .side_type = side_type_array_decl(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)), \
463 #define side_type_vla_decl(_elem_type, _attr) \
465 .type = SIDE_TYPE_VLA, \
466 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
470 .elem_type = _elem_type, \
474 #define side_field_vla(_name, _elem_type, _attr) \
476 .field_name = _name, \
477 .side_type = side_type_vla_decl(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)), \
480 #define side_type_vla_visitor_decl(_elem_type, _visitor, _attr) \
482 .type = SIDE_TYPE_VLA_VISITOR, \
483 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
486 .side_vla_visitor = { \
487 .elem_type = SIDE_PARAM(_elem_type), \
488 .visitor = _visitor, \
492 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
494 .field_name = _name, \
495 .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)), \
498 #define side_elem(...) \
499 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
501 #define side_elem_type(_type, _attr) \
502 side_elem(side_type_decl(_type, SIDE_PARAM(_attr)))
504 #define side_field_list(...) \
505 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
507 #define side_arg_bool(val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(val) } }
508 #define side_arg_u8(val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (val) } }
509 #define side_arg_u16(val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (val) } }
510 #define side_arg_u32(val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (val) } }
511 #define side_arg_u64(val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (val) } }
512 #define side_arg_s8(val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (val) } }
513 #define side_arg_s16(val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } }
514 #define side_arg_s32(val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } }
515 #define side_arg_s64(val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } }
516 #define side_arg_enum_u8(val) { .type = SIDE_TYPE_ENUM_U8, .u = { .side_u8 = (val) } }
517 #define side_arg_enum_u16(val) { .type = SIDE_TYPE_ENUM_U16, .u = { .side_u16 = (val) } }
518 #define side_arg_enum_u32(val) { .type = SIDE_TYPE_ENUM_U32, .u = { .side_u32 = (val) } }
519 #define side_arg_enum_u64(val) { .type = SIDE_TYPE_ENUM_U64, .u = { .side_u64 = (val) } }
520 #define side_arg_enum_s8(val) { .type = SIDE_TYPE_ENUM_S8, .u = { .side_s8 = (val) } }
521 #define side_arg_enum_s16(val) { .type = SIDE_TYPE_ENUM_S16, .u = { .side_s16 = (val) } }
522 #define side_arg_enum_s32(val) { .type = SIDE_TYPE_ENUM_S32, .u = { .side_s32 = (val) } }
523 #define side_arg_enum_s64(val) { .type = SIDE_TYPE_ENUM_S64, .u = { .side_s64 = (val) } }
524 #define side_arg_enum_bitmap8(val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (val) } }
525 #define side_arg_enum_bitmap16(val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (val) } }
526 #define side_arg_enum_bitmap32(val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (val) } }
527 #define side_arg_enum_bitmap64(val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (val) } }
528 #define side_arg_float_binary16(val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (val) } }
529 #define side_arg_float_binary32(val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (val) } }
530 #define side_arg_float_binary64(val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (val) } }
531 #define side_arg_float_binary128(val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (val) } }
533 #define side_arg_string(val) { .type = SIDE_TYPE_STRING, .u = { .string = (val) } }
534 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
535 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
536 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
537 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
539 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
540 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
541 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
542 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
543 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
544 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
545 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
546 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
548 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
549 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
550 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
551 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
552 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
553 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
554 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
555 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
557 #define side_arg_dynamic(dynamic_arg_type) \
559 .type = SIDE_TYPE_DYNAMIC, \
561 .dynamic = dynamic_arg_type, \
565 #define side_arg_dynamic_null(_attr) \
567 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
568 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
572 #define side_arg_dynamic_bool(_val, _attr) \
574 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
575 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
578 .side_bool = !!(_val), \
582 #define side_arg_dynamic_u8(_val, _attr) \
584 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
585 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
591 #define side_arg_dynamic_u16(_val, _attr) \
593 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
594 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
597 .side_u16 = (_val), \
600 #define side_arg_dynamic_u32(_val, _attr) \
602 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
603 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
606 .side_u32 = (_val), \
609 #define side_arg_dynamic_u64(_val, _attr) \
611 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
612 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
615 .side_u64 = (_val), \
619 #define side_arg_dynamic_s8(_val, _attr) \
621 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
622 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
628 #define side_arg_dynamic_s16(_val, _attr) \
630 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
631 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
634 .side_s16 = (_val), \
637 #define side_arg_dynamic_s32(_val, _attr) \
639 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
640 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
643 .side_s32 = (_val), \
646 #define side_arg_dynamic_s64(_val, _attr) \
648 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
649 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
652 .side_s64 = (_val), \
656 #define side_arg_dynamic_float_binary16(_val, _attr) \
658 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
659 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
662 .side_float_binary16 = (_val), \
665 #define side_arg_dynamic_float_binary32(_val, _attr) \
667 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
668 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
671 .side_float_binary32 = (_val), \
674 #define side_arg_dynamic_float_binary64(_val, _attr) \
676 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
677 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
680 .side_float_binary64 = (_val), \
683 #define side_arg_dynamic_float_binary128(_val, _attr) \
685 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
686 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
689 .side_float_binary128 = (_val), \
693 #define side_arg_dynamic_string(_val, _attr) \
695 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
696 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
703 #define side_arg_dynamic_vla(_vla, _attr) \
705 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
706 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
709 .side_dynamic_vla = (_vla), \
713 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
715 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
716 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
719 .side_dynamic_vla_visitor = { \
721 .visitor = _dynamic_vla_visitor, \
726 #define side_arg_dynamic_struct(_struct, _attr) \
728 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
729 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
732 .side_dynamic_struct = (_struct), \
736 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
738 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
739 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
742 .side_dynamic_struct_visitor = { \
744 .visitor = _dynamic_struct_visitor, \
749 #define side_arg_dynamic_define_vec(_identifier, _sav) \
750 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
751 const struct side_arg_dynamic_vec_vla _identifier = { \
752 .sav = _identifier##_vec, \
753 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
756 #define side_arg_dynamic_define_struct(_identifier, _struct_fields) \
757 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
758 const struct side_arg_dynamic_event_struct _identifier = { \
759 .fields = _identifier##_fields, \
760 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
763 #define side_arg_define_vec(_identifier, _sav) \
764 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
765 const struct side_arg_vec_description _identifier = { \
766 .sav = _identifier##_vec, \
767 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
770 #define side_arg_dynamic_field(_name, _elem) \
772 .field_name = _name, \
776 #define side_arg_list(...) __VA_ARGS__
778 #define side_attr_bool(val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(val) } }
779 #define side_attr_u8(val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (val) } }
780 #define side_attr_u16(val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (val) } }
781 #define side_attr_u32(val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (val) } }
782 #define side_attr_u64(val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (val) } }
783 #define side_attr_s8(val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (val) } }
784 #define side_attr_s16(val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (val) } }
785 #define side_attr_s32(val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (val) } }
786 #define side_attr_s64(val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (val) } }
787 #define side_attr_float_binary16(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (val) } }
788 #define side_attr_float_binary32(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (val) } }
789 #define side_attr_float_binary64(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (val) } }
790 #define side_attr_float_binary128(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (val) } }
791 #define side_attr_string(val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (val) } }
793 #define side_event_cond(desc) if (side_unlikely((desc)->enabled))
795 #define side_event_call(desc, _sav) \
797 const struct side_arg_vec side_sav[] = { _sav }; \
798 const struct side_arg_vec_description sav_desc = { \
800 .len = SIDE_ARRAY_SIZE(side_sav), \
802 side_call(desc, &sav_desc); \
805 #define side_event(desc, sav) \
806 side_event_cond(desc) \
807 side_event_call(desc, SIDE_PARAM(sav))
809 #define side_event_call_variadic(desc, _sav, _var_fields) \
811 const struct side_arg_vec side_sav[] = { _sav }; \
812 const struct side_arg_vec_description sav_desc = { \
814 .len = SIDE_ARRAY_SIZE(side_sav), \
816 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
817 const struct side_arg_dynamic_event_struct var_struct = { \
818 .fields = side_fields, \
819 .len = SIDE_ARRAY_SIZE(side_fields), \
821 side_call_variadic(desc, &sav_desc, &var_struct); \
824 #define side_event_variadic(desc, sav, var) \
825 side_event_cond(desc) \
826 side_event_call_variadic(desc, SIDE_PARAM(sav), SIDE_PARAM(var))
828 #define side_define_enum(_identifier, _mappings) \
829 const struct side_enum_mappings _identifier = { \
830 .mappings = _mappings, \
831 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
834 #define side_mapping_list(...) \
835 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
837 #define side_enum_mapping_range(_label, _begin, _end) \
839 .range_begin = _begin, \
844 #define side_enum_mapping_value(_label, _value) \
846 .range_begin = _value, \
847 .range_end = _value, \
851 #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
852 struct side_event_description _identifier = { \
855 .loglevel = _loglevel, \
856 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
857 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
859 .provider_name = _provider, \
860 .event_name = _event, \
865 #define side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
866 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
867 SIDE_PARAM(_attr), 0)
869 #define side_define_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
870 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
871 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
873 #define side_declare_event(_identifier) \
874 struct side_event_description _identifier
876 void side_call(const struct side_event_description
*desc
,
877 const struct side_arg_vec_description
*sav_desc
);
878 void side_call_variadic(const struct side_event_description
*desc
,
879 const struct side_arg_vec_description
*sav_desc
,
880 const struct side_arg_dynamic_event_struct
*var_struct
);
882 #endif /* _SIDE_TRACE_H */