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_enum_bitmap_mapping
{
219 struct side_enum_bitmap_mappings
{
220 const struct side_enum_bitmap_mapping
*mappings
;
221 uint32_t nr_mappings
;
224 struct side_type_description
{
225 uint32_t type
; /* enum side_type */
227 const struct side_attr
*attr
;
231 const struct side_event_field
*fields
;
235 const struct side_type_description
*elem_type
;
238 const struct side_type_description
*elem_type
;
241 const struct side_type_description
*elem_type
;
242 side_visitor visitor
;
244 const struct side_enum_mappings
*side_enum_mappings
;
245 const struct side_enum_bitmap_mappings
*side_enum_bitmap_mappings
;
249 struct side_event_field
{
250 const char *field_name
;
251 struct side_type_description side_type
;
254 enum side_event_flags
{
255 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
258 struct side_event_description
{
261 uint32_t loglevel
; /* enum side_loglevel */
266 const char *provider_name
;
267 const char *event_name
;
268 const struct side_event_field
*fields
;
269 const struct side_attr
*attr
;
272 struct side_arg_dynamic_vec_vla
{
273 const struct side_arg_dynamic_vec
*sav
;
277 struct side_arg_dynamic_vec
{
278 uint32_t dynamic_type
; /* enum side_dynamic_type */
280 const struct side_attr
*attr
;
294 _Float16 side_float_binary16
;
297 _Float32 side_float_binary32
;
300 _Float64 side_float_binary64
;
303 _Float128 side_float_binary128
;
308 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
311 side_dynamic_struct_visitor visitor
;
312 } side_dynamic_struct_visitor
;
314 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
317 side_dynamic_vla_visitor visitor
;
318 } side_dynamic_vla_visitor
;
322 struct side_arg_dynamic_event_field
{
323 const char *field_name
;
324 const struct side_arg_dynamic_vec elem
;
327 struct side_arg_dynamic_event_struct
{
328 const struct side_arg_dynamic_event_field
*fields
;
332 struct side_arg_vec
{
347 _Float16 side_float_binary16
;
350 _Float32 side_float_binary32
;
353 _Float64 side_float_binary64
;
356 _Float128 side_float_binary128
;
360 const struct side_arg_vec_description
*side_struct
;
361 const struct side_arg_vec_description
*side_array
;
362 const struct side_arg_vec_description
*side_vla
;
363 void *side_vla_app_visitor_ctx
;
365 void *side_array_fixint
;
371 struct side_arg_dynamic_vec dynamic
;
375 struct side_arg_vec_description
{
376 const struct side_arg_vec
*sav
;
380 /* The visitor pattern is a double-dispatch visitor. */
381 struct side_tracer_visitor_ctx
{
382 enum side_visitor_status (*write_elem
)(
383 const struct side_tracer_visitor_ctx
*tracer_ctx
,
384 const struct side_arg_vec
*elem
);
385 void *priv
; /* Private tracer context. */
388 struct side_tracer_dynamic_struct_visitor_ctx
{
389 enum side_visitor_status (*write_field
)(
390 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
391 const struct side_arg_dynamic_event_field
*dynamic_field
);
392 void *priv
; /* Private tracer context. */
395 struct side_tracer_dynamic_vla_visitor_ctx
{
396 enum side_visitor_status (*write_elem
)(
397 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
398 const struct side_arg_dynamic_vec
*elem
);
399 void *priv
; /* Private tracer context. */
402 #define side_attr(_key, _value) \
405 .value = SIDE_PARAM(_value), \
408 #define side_attr_list(...) \
409 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
411 #define _side_type(_type, _attr) \
414 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
418 #define side_type_bool(_attr) _side_type(SIDE_TYPE_BOOL, SIDE_PARAM(_attr))
419 #define side_type_u8(_attr) _side_type(SIDE_TYPE_U8, SIDE_PARAM(_attr))
420 #define side_type_u16(_attr) _side_type(SIDE_TYPE_U16, SIDE_PARAM(_attr))
421 #define side_type_u32(_attr) _side_type(SIDE_TYPE_U32, SIDE_PARAM(_attr))
422 #define side_type_u64(_attr) _side_type(SIDE_TYPE_U64, SIDE_PARAM(_attr))
423 #define side_type_s8(_attr) _side_type(SIDE_TYPE_S8, SIDE_PARAM(_attr))
424 #define side_type_s16(_attr) _side_type(SIDE_TYPE_S16, SIDE_PARAM(_attr))
425 #define side_type_s32(_attr) _side_type(SIDE_TYPE_S32, SIDE_PARAM(_attr))
426 #define side_type_s64(_attr) _side_type(SIDE_TYPE_S64, SIDE_PARAM(_attr))
427 #define side_type_float_binary16(_attr) _side_type(SIDE_TYPE_FLOAT_BINARY16, SIDE_PARAM(_attr))
428 #define side_type_float_binary32(_attr) _side_type(SIDE_TYPE_FLOAT_BINARY32, SIDE_PARAM(_attr))
429 #define side_type_float_binary64(_attr) _side_type(SIDE_TYPE_FLOAT_BINARY64, SIDE_PARAM(_attr))
430 #define side_type_float_binary128(_attr) _side_type(SIDE_TYPE_FLOAT_BINARY128, SIDE_PARAM(_attr))
431 #define side_type_string(_attr) _side_type(SIDE_TYPE_STRING, SIDE_PARAM(_attr))
432 #define side_type_dynamic(_attr) _side_type(SIDE_TYPE_DYNAMIC, SIDE_PARAM(_attr))
434 #define _side_field(_name, _type) \
436 .field_name = _name, \
437 .side_type = _type, \
440 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
441 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
442 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
443 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
444 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
445 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
446 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
447 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
448 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
449 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
450 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
451 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
452 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
453 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
454 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
456 #define side_type_enum(_type, _mappings, _attr) \
459 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
462 .side_enum_mappings = _mappings, \
465 #define _side_field_enum(_name, _type, _mappings, _attr) \
466 _side_field(_name, side_type_enum(_type, SIDE_PARAM(_mappings), SIDE_PARAM(_attr)))
468 #define side_field_enum_u8(_name, _mappings, _attr) \
469 _side_field_enum(_name, SIDE_TYPE_ENUM_U8, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
470 #define side_field_enum_u16(_name, _mappings, _attr) \
471 _side_field_enum(_name, SIDE_TYPE_ENUM_U16, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
472 #define side_field_enum_u32(_name, _mappings, _attr) \
473 _side_field_enum(_name, SIDE_TYPE_ENUM_U32, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
474 #define side_field_enum_u64(_name, _mappings, _attr) \
475 _side_field_enum(_name, SIDE_TYPE_ENUM_U64, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
476 #define side_field_enum_s8(_name, _mappings, _attr) \
477 _side_field_enum(_name, SIDE_TYPE_ENUM_S8, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
478 #define side_field_enum_s16(_name, _mappings, _attr) \
479 _side_field_enum(_name, SIDE_TYPE_ENUM_S16, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
480 #define side_field_enum_s32(_name, _mappings, _attr) \
481 _side_field_enum(_name, SIDE_TYPE_ENUM_S32, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
482 #define side_field_enum_s64(_name, _mappings, _attr) \
483 _side_field_enum(_name, SIDE_TYPE_ENUM_S64, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
485 #define side_type_enum_bitmap(_type, _mappings, _attr) \
488 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
491 .side_enum_bitmap_mappings = _mappings, \
494 #define _side_field_enum_bitmap(_name, _type, _mappings, _attr) \
495 _side_field(_name, side_type_enum_bitmap(_type, SIDE_PARAM(_mappings), SIDE_PARAM(_attr)))
497 #define side_field_enum_bitmap8(_name, _mappings, _attr) \
498 _side_field_enum_bitmap(_name, SIDE_TYPE_ENUM_BITMAP8, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
499 #define side_field_enum_bitmap16(_name, _mappings, _attr) \
500 _side_field_enum_bitmap(_name, SIDE_TYPE_ENUM_BITMAP16, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
501 #define side_field_enum_bitmap32(_name, _mappings, _attr) \
502 _side_field_enum_bitmap(_name, SIDE_TYPE_ENUM_BITMAP32, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
503 #define side_field_enum_bitmap64(_name, _mappings, _attr) \
504 _side_field_enum_bitmap(_name, SIDE_TYPE_ENUM_BITMAP64, SIDE_PARAM(_mappings), SIDE_PARAM(_attr))
506 #define side_type_struct(_fields, _attr) \
508 .type = SIDE_TYPE_STRUCT, \
509 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
513 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
518 #define side_field_struct(_name, _fields, _attr) \
519 _side_field(_name, side_type_struct(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
521 #define side_type_array(_elem_type, _length, _attr) \
523 .type = SIDE_TYPE_ARRAY, \
524 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
529 .elem_type = _elem_type, \
533 #define side_field_array(_name, _elem_type, _length, _attr) \
534 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
536 #define side_type_vla(_elem_type, _attr) \
538 .type = SIDE_TYPE_VLA, \
539 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
543 .elem_type = _elem_type, \
547 #define side_field_vla(_name, _elem_type, _attr) \
548 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
550 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
552 .type = SIDE_TYPE_VLA_VISITOR, \
553 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
556 .side_vla_visitor = { \
557 .elem_type = SIDE_PARAM(_elem_type), \
558 .visitor = _visitor, \
562 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
563 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
565 #define side_elem(...) \
566 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
568 #define side_field_list(...) \
569 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
571 #define side_arg_bool(val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(val) } }
572 #define side_arg_u8(val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (val) } }
573 #define side_arg_u16(val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (val) } }
574 #define side_arg_u32(val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (val) } }
575 #define side_arg_u64(val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (val) } }
576 #define side_arg_s8(val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (val) } }
577 #define side_arg_s16(val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } }
578 #define side_arg_s32(val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } }
579 #define side_arg_s64(val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } }
580 #define side_arg_enum_u8(val) { .type = SIDE_TYPE_ENUM_U8, .u = { .side_u8 = (val) } }
581 #define side_arg_enum_u16(val) { .type = SIDE_TYPE_ENUM_U16, .u = { .side_u16 = (val) } }
582 #define side_arg_enum_u32(val) { .type = SIDE_TYPE_ENUM_U32, .u = { .side_u32 = (val) } }
583 #define side_arg_enum_u64(val) { .type = SIDE_TYPE_ENUM_U64, .u = { .side_u64 = (val) } }
584 #define side_arg_enum_s8(val) { .type = SIDE_TYPE_ENUM_S8, .u = { .side_s8 = (val) } }
585 #define side_arg_enum_s16(val) { .type = SIDE_TYPE_ENUM_S16, .u = { .side_s16 = (val) } }
586 #define side_arg_enum_s32(val) { .type = SIDE_TYPE_ENUM_S32, .u = { .side_s32 = (val) } }
587 #define side_arg_enum_s64(val) { .type = SIDE_TYPE_ENUM_S64, .u = { .side_s64 = (val) } }
588 #define side_arg_enum_bitmap8(val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (val) } }
589 #define side_arg_enum_bitmap16(val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (val) } }
590 #define side_arg_enum_bitmap32(val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (val) } }
591 #define side_arg_enum_bitmap64(val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (val) } }
592 #define side_arg_float_binary16(val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (val) } }
593 #define side_arg_float_binary32(val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (val) } }
594 #define side_arg_float_binary64(val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (val) } }
595 #define side_arg_float_binary128(val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (val) } }
597 #define side_arg_string(val) { .type = SIDE_TYPE_STRING, .u = { .string = (val) } }
598 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
599 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
600 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
601 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
603 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
604 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
605 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
606 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
607 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
608 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
609 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
610 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
612 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
613 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
614 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
615 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
616 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
617 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
618 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
619 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
621 #define side_arg_dynamic(dynamic_arg_type) \
623 .type = SIDE_TYPE_DYNAMIC, \
625 .dynamic = dynamic_arg_type, \
629 #define side_arg_dynamic_null(_attr) \
631 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
632 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
636 #define side_arg_dynamic_bool(_val, _attr) \
638 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
639 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
642 .side_bool = !!(_val), \
646 #define side_arg_dynamic_u8(_val, _attr) \
648 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
649 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
655 #define side_arg_dynamic_u16(_val, _attr) \
657 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
658 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
661 .side_u16 = (_val), \
664 #define side_arg_dynamic_u32(_val, _attr) \
666 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
667 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
670 .side_u32 = (_val), \
673 #define side_arg_dynamic_u64(_val, _attr) \
675 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
676 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
679 .side_u64 = (_val), \
683 #define side_arg_dynamic_s8(_val, _attr) \
685 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
686 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
692 #define side_arg_dynamic_s16(_val, _attr) \
694 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
695 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
698 .side_s16 = (_val), \
701 #define side_arg_dynamic_s32(_val, _attr) \
703 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
704 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
707 .side_s32 = (_val), \
710 #define side_arg_dynamic_s64(_val, _attr) \
712 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
713 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
716 .side_s64 = (_val), \
720 #define side_arg_dynamic_float_binary16(_val, _attr) \
722 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
723 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
726 .side_float_binary16 = (_val), \
729 #define side_arg_dynamic_float_binary32(_val, _attr) \
731 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
732 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
735 .side_float_binary32 = (_val), \
738 #define side_arg_dynamic_float_binary64(_val, _attr) \
740 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
741 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
744 .side_float_binary64 = (_val), \
747 #define side_arg_dynamic_float_binary128(_val, _attr) \
749 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
750 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
753 .side_float_binary128 = (_val), \
757 #define side_arg_dynamic_string(_val, _attr) \
759 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
760 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
767 #define side_arg_dynamic_vla(_vla, _attr) \
769 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
770 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
773 .side_dynamic_vla = (_vla), \
777 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
779 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
780 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
783 .side_dynamic_vla_visitor = { \
785 .visitor = _dynamic_vla_visitor, \
790 #define side_arg_dynamic_struct(_struct, _attr) \
792 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
793 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
796 .side_dynamic_struct = (_struct), \
800 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
802 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
803 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
806 .side_dynamic_struct_visitor = { \
808 .visitor = _dynamic_struct_visitor, \
813 #define side_arg_dynamic_define_vec(_identifier, _sav) \
814 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
815 const struct side_arg_dynamic_vec_vla _identifier = { \
816 .sav = _identifier##_vec, \
817 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
820 #define side_arg_dynamic_define_struct(_identifier, _struct_fields) \
821 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
822 const struct side_arg_dynamic_event_struct _identifier = { \
823 .fields = _identifier##_fields, \
824 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
827 #define side_arg_define_vec(_identifier, _sav) \
828 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
829 const struct side_arg_vec_description _identifier = { \
830 .sav = _identifier##_vec, \
831 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
834 #define side_arg_dynamic_field(_name, _elem) \
836 .field_name = _name, \
840 #define side_arg_list(...) __VA_ARGS__
842 #define side_attr_bool(val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(val) } }
843 #define side_attr_u8(val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (val) } }
844 #define side_attr_u16(val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (val) } }
845 #define side_attr_u32(val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (val) } }
846 #define side_attr_u64(val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (val) } }
847 #define side_attr_s8(val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (val) } }
848 #define side_attr_s16(val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (val) } }
849 #define side_attr_s32(val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (val) } }
850 #define side_attr_s64(val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (val) } }
851 #define side_attr_float_binary16(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (val) } }
852 #define side_attr_float_binary32(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (val) } }
853 #define side_attr_float_binary64(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (val) } }
854 #define side_attr_float_binary128(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (val) } }
855 #define side_attr_string(val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (val) } }
857 #define side_event_cond(desc) if (side_unlikely((desc)->enabled))
859 #define side_event_call(desc, _sav) \
861 const struct side_arg_vec side_sav[] = { _sav }; \
862 const struct side_arg_vec_description sav_desc = { \
864 .len = SIDE_ARRAY_SIZE(side_sav), \
866 side_call(desc, &sav_desc); \
869 #define side_event(desc, sav) \
870 side_event_cond(desc) \
871 side_event_call(desc, SIDE_PARAM(sav))
873 #define side_event_call_variadic(desc, _sav, _var_fields) \
875 const struct side_arg_vec side_sav[] = { _sav }; \
876 const struct side_arg_vec_description sav_desc = { \
878 .len = SIDE_ARRAY_SIZE(side_sav), \
880 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
881 const struct side_arg_dynamic_event_struct var_struct = { \
882 .fields = side_fields, \
883 .len = SIDE_ARRAY_SIZE(side_fields), \
885 side_call_variadic(desc, &sav_desc, &var_struct); \
888 #define side_event_variadic(desc, sav, var) \
889 side_event_cond(desc) \
890 side_event_call_variadic(desc, SIDE_PARAM(sav), SIDE_PARAM(var))
892 #define side_define_enum(_identifier, _mappings) \
893 const struct side_enum_mappings _identifier = { \
894 .mappings = _mappings, \
895 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
898 #define side_enum_mapping_list(...) \
899 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
901 #define side_enum_mapping_range(_label, _begin, _end) \
903 .range_begin = _begin, \
908 #define side_enum_mapping_value(_label, _value) \
910 .range_begin = _value, \
911 .range_end = _value, \
915 #define side_define_enum_bitmap(_identifier, _mappings) \
916 const struct side_enum_bitmap_mappings _identifier = { \
917 .mappings = _mappings, \
918 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
921 #define side_enum_bitmap_mapping_list(...) \
922 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
924 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
926 .range_begin = _begin, \
931 #define side_enum_bitmap_mapping_value(_label, _value) \
933 .range_begin = _value, \
934 .range_end = _value, \
938 #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
939 struct side_event_description _identifier = { \
942 .loglevel = _loglevel, \
943 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
944 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
946 .provider_name = _provider, \
947 .event_name = _event, \
952 #define side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
953 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
954 SIDE_PARAM(_attr), 0)
956 #define side_define_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
957 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
958 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
960 #define side_declare_event(_identifier) \
961 struct side_event_description _identifier
963 void side_call(const struct side_event_description
*desc
,
964 const struct side_arg_vec_description
*sav_desc
);
965 void side_call_variadic(const struct side_event_description
*desc
,
966 const struct side_arg_vec_description
*sav_desc
,
967 const struct side_arg_dynamic_event_struct
*var_struct
);
969 #endif /* _SIDE_TRACE_H */