Move kernel mask to implementation
[libside.git] / include / side / trace.h
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 */
5
6 #ifndef _SIDE_TRACE_H
7 #define _SIDE_TRACE_H
8
9 #include <stdint.h>
10 #include <inttypes.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <math.h>
14 #include <side/macros.h>
15
16 /* SIDE stands for "Static Instrumentation Dynamically Enabled" */
17
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.
21
22 struct side_arg_vec;
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;
31
32 enum side_type {
33 SIDE_TYPE_BOOL,
34
35 SIDE_TYPE_U8,
36 SIDE_TYPE_U16,
37 SIDE_TYPE_U32,
38 SIDE_TYPE_U64,
39 SIDE_TYPE_S8,
40 SIDE_TYPE_S16,
41 SIDE_TYPE_S32,
42 SIDE_TYPE_S64,
43
44 SIDE_TYPE_ENUM_U8,
45 SIDE_TYPE_ENUM_U16,
46 SIDE_TYPE_ENUM_U32,
47 SIDE_TYPE_ENUM_U64,
48 SIDE_TYPE_ENUM_S8,
49 SIDE_TYPE_ENUM_S16,
50 SIDE_TYPE_ENUM_S32,
51 SIDE_TYPE_ENUM_S64,
52
53 SIDE_TYPE_ENUM_BITMAP8,
54 SIDE_TYPE_ENUM_BITMAP16,
55 SIDE_TYPE_ENUM_BITMAP32,
56 SIDE_TYPE_ENUM_BITMAP64,
57
58 SIDE_TYPE_FLOAT_BINARY16,
59 SIDE_TYPE_FLOAT_BINARY32,
60 SIDE_TYPE_FLOAT_BINARY64,
61 SIDE_TYPE_FLOAT_BINARY128,
62
63 SIDE_TYPE_STRING,
64
65 SIDE_TYPE_STRUCT,
66 SIDE_TYPE_ARRAY,
67 SIDE_TYPE_VLA,
68 SIDE_TYPE_VLA_VISITOR,
69
70 SIDE_TYPE_ARRAY_U8,
71 SIDE_TYPE_ARRAY_U16,
72 SIDE_TYPE_ARRAY_U32,
73 SIDE_TYPE_ARRAY_U64,
74 SIDE_TYPE_ARRAY_S8,
75 SIDE_TYPE_ARRAY_S16,
76 SIDE_TYPE_ARRAY_S32,
77 SIDE_TYPE_ARRAY_S64,
78
79 SIDE_TYPE_VLA_U8,
80 SIDE_TYPE_VLA_U16,
81 SIDE_TYPE_VLA_U32,
82 SIDE_TYPE_VLA_U64,
83 SIDE_TYPE_VLA_S8,
84 SIDE_TYPE_VLA_S16,
85 SIDE_TYPE_VLA_S32,
86 SIDE_TYPE_VLA_S64,
87
88 SIDE_TYPE_DYNAMIC,
89 };
90
91 enum side_dynamic_type {
92 SIDE_DYNAMIC_TYPE_NULL,
93
94 SIDE_DYNAMIC_TYPE_BOOL,
95
96 SIDE_DYNAMIC_TYPE_U8,
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,
104
105 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16,
106 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32,
107 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64,
108 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128,
109
110 SIDE_DYNAMIC_TYPE_STRING,
111
112 SIDE_DYNAMIC_TYPE_STRUCT,
113 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR,
114
115 SIDE_DYNAMIC_TYPE_VLA,
116 SIDE_DYNAMIC_TYPE_VLA_VISITOR,
117 };
118
119 enum side_attr_type {
120 SIDE_ATTR_TYPE_BOOL,
121
122 SIDE_ATTR_TYPE_U8,
123 SIDE_ATTR_TYPE_U16,
124 SIDE_ATTR_TYPE_U32,
125 SIDE_ATTR_TYPE_U64,
126 SIDE_ATTR_TYPE_S8,
127 SIDE_ATTR_TYPE_S16,
128 SIDE_ATTR_TYPE_S32,
129 SIDE_ATTR_TYPE_S64,
130
131 SIDE_ATTR_TYPE_FLOAT_BINARY16,
132 SIDE_ATTR_TYPE_FLOAT_BINARY32,
133 SIDE_ATTR_TYPE_FLOAT_BINARY64,
134 SIDE_ATTR_TYPE_FLOAT_BINARY128,
135
136 SIDE_ATTR_TYPE_STRING,
137 };
138
139 enum side_loglevel {
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,
148 };
149
150 enum side_visitor_status {
151 SIDE_VISITOR_STATUS_OK = 0,
152 SIDE_VISITOR_STATUS_ERROR = -1,
153 };
154
155 typedef enum side_visitor_status (*side_visitor)(
156 const struct side_tracer_visitor_ctx *tracer_ctx,
157 void *app_ctx);
158 typedef enum side_visitor_status (*side_dynamic_struct_visitor)(
159 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
160 void *app_ctx);
161 typedef enum side_visitor_status (*side_dynamic_vla_visitor)(
162 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
163 void *app_ctx);
164
165 struct side_attr_value {
166 uint32_t type; /* enum side_attr_type */
167 union {
168 uint8_t side_bool;
169
170 uint8_t side_u8;
171 uint16_t side_u16;
172 uint32_t side_u32;
173 uint64_t side_u64;
174 int8_t side_s8;
175 int16_t side_s16;
176 int32_t side_s32;
177 int64_t side_s64;
178
179 #if __HAVE_FLOAT16
180 _Float16 side_float_binary16;
181 #endif
182 #if __HAVE_FLOAT32
183 _Float32 side_float_binary32;
184 #endif
185 #if __HAVE_FLOAT64
186 _Float64 side_float_binary64;
187 #endif
188 #if __HAVE_FLOAT128
189 _Float128 side_float_binary128;
190 #endif
191
192 const char *string;
193 } u;
194 };
195
196 /* User attributes. */
197 struct side_attr {
198 const char *key;
199 const struct side_attr_value value;
200 };
201
202 struct side_enum_mapping {
203 int64_t range_begin;
204 int64_t range_end;
205 const char *label;
206 };
207
208 struct side_enum_mappings {
209 const struct side_enum_mapping *mappings;
210 uint32_t nr_mappings;
211 };
212
213 struct side_type_description {
214 uint32_t type; /* enum side_type */
215 uint32_t nr_attr;
216 const struct side_attr *attr;
217 union {
218 struct {
219 uint32_t nr_fields;
220 const struct side_event_field *fields;
221 } side_struct;
222 struct {
223 uint32_t length;
224 const struct side_type_description *elem_type;
225 } side_array;
226 struct {
227 const struct side_type_description *elem_type;
228 } side_vla;
229 struct {
230 const struct side_type_description *elem_type;
231 side_visitor visitor;
232 } side_vla_visitor;
233 const struct side_enum_mappings *side_enum_mappings;
234 } u;
235 };
236
237 struct side_event_field {
238 const char *field_name;
239 struct side_type_description side_type;
240 };
241
242 enum side_event_flags {
243 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
244 };
245
246 struct side_event_description {
247 uint32_t version;
248 uint32_t enabled;
249 uint32_t loglevel; /* enum side_loglevel */
250 uint32_t nr_fields;
251 uint32_t nr_attr;
252 uint32_t _unused;
253 uint64_t flags;
254 const char *provider_name;
255 const char *event_name;
256 const struct side_event_field *fields;
257 const struct side_attr *attr;
258 };
259
260 struct side_arg_dynamic_vec_vla {
261 const struct side_arg_dynamic_vec *sav;
262 uint32_t len;
263 };
264
265 struct side_arg_dynamic_vec {
266 uint32_t dynamic_type; /* enum side_dynamic_type */
267 uint32_t nr_attr;
268 const struct side_attr *attr;
269 union {
270 uint8_t side_bool;
271
272 uint8_t side_u8;
273 uint16_t side_u16;
274 uint32_t side_u32;
275 uint64_t side_u64;
276 int8_t side_s8;
277 int16_t side_s16;
278 int32_t side_s32;
279 int64_t side_s64;
280
281 #if __HAVE_FLOAT16
282 _Float16 side_float_binary16;
283 #endif
284 #if __HAVE_FLOAT32
285 _Float32 side_float_binary32;
286 #endif
287 #if __HAVE_FLOAT64
288 _Float64 side_float_binary64;
289 #endif
290 #if __HAVE_FLOAT128
291 _Float128 side_float_binary128;
292 #endif
293
294 const char *string;
295
296 const struct side_arg_dynamic_event_struct *side_dynamic_struct;
297 struct {
298 void *app_ctx;
299 side_dynamic_struct_visitor visitor;
300 } side_dynamic_struct_visitor;
301
302 const struct side_arg_dynamic_vec_vla *side_dynamic_vla;
303 struct {
304 void *app_ctx;
305 side_dynamic_vla_visitor visitor;
306 } side_dynamic_vla_visitor;
307 } u;
308 };
309
310 struct side_arg_dynamic_event_field {
311 const char *field_name;
312 const struct side_arg_dynamic_vec elem;
313 };
314
315 struct side_arg_dynamic_event_struct {
316 const struct side_arg_dynamic_event_field *fields;
317 uint32_t len;
318 };
319
320 struct side_arg_vec {
321 enum side_type type;
322 union {
323 uint8_t side_bool;
324
325 uint8_t side_u8;
326 uint16_t side_u16;
327 uint32_t side_u32;
328 uint64_t side_u64;
329 int8_t side_s8;
330 int16_t side_s16;
331 int32_t side_s32;
332 int64_t side_s64;
333
334 #if __HAVE_FLOAT16
335 _Float16 side_float_binary16;
336 #endif
337 #if __HAVE_FLOAT32
338 _Float32 side_float_binary32;
339 #endif
340 #if __HAVE_FLOAT64
341 _Float64 side_float_binary64;
342 #endif
343 #if __HAVE_FLOAT128
344 _Float128 side_float_binary128;
345 #endif
346
347 const char *string;
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;
352
353 void *side_array_fixint;
354 struct {
355 void *p;
356 uint32_t length;
357 } side_vla_fixint;
358
359 struct side_arg_dynamic_vec dynamic;
360 } u;
361 };
362
363 struct side_arg_vec_description {
364 const struct side_arg_vec *sav;
365 uint32_t len;
366 };
367
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. */
374 };
375
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. */
381 };
382
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. */
388 };
389
390 #define side_attr(_key, _value) \
391 { \
392 .key = _key, \
393 .value = SIDE_PARAM(_value), \
394 }
395
396 #define side_attr_list(...) \
397 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
398
399 #define side_type_decl(_type, _attr) \
400 { \
401 .type = _type, \
402 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
403 .attr = _attr, \
404 }
405
406 #define side_field(_name, _type, _attr) \
407 { \
408 .field_name = _name, \
409 .side_type = side_type_decl(_type, SIDE_PARAM(_attr)), \
410 }
411
412 #define side_type_enum_decl(_type, _mappings, _attr) \
413 { \
414 .type = _type, \
415 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
416 .attr = _attr, \
417 .u = { \
418 .side_enum_mappings = _mappings, \
419 }, \
420 }
421 #define side_field_enum(_name, _type, _mappings, _attr) \
422 { \
423 .field_name = _name, \
424 .side_type = side_type_enum_decl(_type, SIDE_PARAM(_mappings), SIDE_PARAM(_attr)), \
425 }
426
427 #define side_type_struct_decl(_fields, _attr) \
428 { \
429 .type = SIDE_TYPE_STRUCT, \
430 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
431 .attr = _attr, \
432 .u = { \
433 .side_struct = { \
434 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
435 .fields = _fields, \
436 }, \
437 }, \
438 }
439 #define side_field_struct(_name, _fields, _attr) \
440 { \
441 .field_name = _name, \
442 .side_type = side_type_struct_decl(SIDE_PARAM(_fields), SIDE_PARAM(_attr)), \
443 }
444
445 #define side_type_array_decl(_elem_type, _length, _attr) \
446 { \
447 .type = SIDE_TYPE_ARRAY, \
448 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
449 .attr = _attr, \
450 .u = { \
451 .side_array = { \
452 .length = _length, \
453 .elem_type = _elem_type, \
454 }, \
455 }, \
456 }
457 #define side_field_array(_name, _elem_type, _length, _attr) \
458 { \
459 .field_name = _name, \
460 .side_type = side_type_array_decl(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)), \
461 }
462
463 #define side_type_vla_decl(_elem_type, _attr) \
464 { \
465 .type = SIDE_TYPE_VLA, \
466 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
467 .attr = _attr, \
468 .u = { \
469 .side_vla = { \
470 .elem_type = _elem_type, \
471 }, \
472 }, \
473 }
474 #define side_field_vla(_name, _elem_type, _attr) \
475 { \
476 .field_name = _name, \
477 .side_type = side_type_vla_decl(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)), \
478 }
479
480 #define side_type_vla_visitor_decl(_elem_type, _visitor, _attr) \
481 { \
482 .type = SIDE_TYPE_VLA_VISITOR, \
483 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
484 .attr = _attr, \
485 .u = { \
486 .side_vla_visitor = { \
487 .elem_type = SIDE_PARAM(_elem_type), \
488 .visitor = _visitor, \
489 }, \
490 }, \
491 }
492 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
493 { \
494 .field_name = _name, \
495 .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)), \
496 }
497
498 #define side_elem(...) \
499 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
500
501 #define side_elem_type(_type, _attr) \
502 side_elem(side_type_decl(_type, SIDE_PARAM(_attr)))
503
504 #define side_field_list(...) \
505 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
506
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) } }
532
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) } }
538
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) } }
547
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) } } }
556
557 #define side_arg_dynamic(dynamic_arg_type) \
558 { \
559 .type = SIDE_TYPE_DYNAMIC, \
560 .u = { \
561 .dynamic = dynamic_arg_type, \
562 }, \
563 }
564
565 #define side_arg_dynamic_null(_attr) \
566 { \
567 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
568 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
569 .attr = _attr, \
570 }
571
572 #define side_arg_dynamic_bool(_val, _attr) \
573 { \
574 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
575 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
576 .attr = _attr, \
577 .u = { \
578 .side_bool = !!(_val), \
579 }, \
580 }
581
582 #define side_arg_dynamic_u8(_val, _attr) \
583 { \
584 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
585 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
586 .attr = _attr, \
587 .u = { \
588 .side_u8 = (_val), \
589 }, \
590 }
591 #define side_arg_dynamic_u16(_val, _attr) \
592 { \
593 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
594 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
595 .attr = _attr, \
596 .u = { \
597 .side_u16 = (_val), \
598 }, \
599 }
600 #define side_arg_dynamic_u32(_val, _attr) \
601 { \
602 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
603 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
604 .attr = _attr, \
605 .u = { \
606 .side_u32 = (_val), \
607 }, \
608 }
609 #define side_arg_dynamic_u64(_val, _attr) \
610 { \
611 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
612 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
613 .attr = _attr, \
614 .u = { \
615 .side_u64 = (_val), \
616 }, \
617 }
618
619 #define side_arg_dynamic_s8(_val, _attr) \
620 { \
621 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
622 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
623 .attr = _attr, \
624 .u = { \
625 .side_s8 = (_val), \
626 }, \
627 }
628 #define side_arg_dynamic_s16(_val, _attr) \
629 { \
630 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
631 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
632 .attr = _attr, \
633 .u = { \
634 .side_s16 = (_val), \
635 }, \
636 }
637 #define side_arg_dynamic_s32(_val, _attr) \
638 { \
639 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
640 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
641 .attr = _attr, \
642 .u = { \
643 .side_s32 = (_val), \
644 }, \
645 }
646 #define side_arg_dynamic_s64(_val, _attr) \
647 { \
648 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
649 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
650 .attr = _attr, \
651 .u = { \
652 .side_s64 = (_val), \
653 }, \
654 }
655
656 #define side_arg_dynamic_float_binary16(_val, _attr) \
657 { \
658 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
659 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
660 .attr = _attr, \
661 .u = { \
662 .side_float_binary16 = (_val), \
663 }, \
664 }
665 #define side_arg_dynamic_float_binary32(_val, _attr) \
666 { \
667 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
668 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
669 .attr = _attr, \
670 .u = { \
671 .side_float_binary32 = (_val), \
672 }, \
673 }
674 #define side_arg_dynamic_float_binary64(_val, _attr) \
675 { \
676 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
677 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
678 .attr = _attr, \
679 .u = { \
680 .side_float_binary64 = (_val), \
681 }, \
682 }
683 #define side_arg_dynamic_float_binary128(_val, _attr) \
684 { \
685 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
686 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
687 .attr = _attr, \
688 .u = { \
689 .side_float_binary128 = (_val), \
690 }, \
691 }
692
693 #define side_arg_dynamic_string(_val, _attr) \
694 { \
695 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
696 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
697 .attr = _attr, \
698 .u = { \
699 .string = (_val), \
700 }, \
701 }
702
703 #define side_arg_dynamic_vla(_vla, _attr) \
704 { \
705 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
706 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
707 .attr = _attr, \
708 .u = { \
709 .side_dynamic_vla = (_vla), \
710 }, \
711 }
712
713 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
714 { \
715 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
716 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
717 .attr = _attr, \
718 .u = { \
719 .side_dynamic_vla_visitor = { \
720 .app_ctx = _ctx, \
721 .visitor = _dynamic_vla_visitor, \
722 }, \
723 }, \
724 }
725
726 #define side_arg_dynamic_struct(_struct, _attr) \
727 { \
728 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
729 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
730 .attr = _attr, \
731 .u = { \
732 .side_dynamic_struct = (_struct), \
733 }, \
734 }
735
736 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
737 { \
738 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
739 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
740 .attr = _attr, \
741 .u = { \
742 .side_dynamic_struct_visitor = { \
743 .app_ctx = _ctx, \
744 .visitor = _dynamic_struct_visitor, \
745 }, \
746 }, \
747 }
748
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), \
754 }
755
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), \
761 }
762
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), \
768 }
769
770 #define side_arg_dynamic_field(_name, _elem) \
771 { \
772 .field_name = _name, \
773 .elem = _elem, \
774 }
775
776 #define side_arg_list(...) __VA_ARGS__
777
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) } }
792
793 #define side_event_cond(desc) if (side_unlikely((desc)->enabled))
794
795 #define side_event_call(desc, _sav) \
796 { \
797 const struct side_arg_vec side_sav[] = { _sav }; \
798 const struct side_arg_vec_description sav_desc = { \
799 .sav = side_sav, \
800 .len = SIDE_ARRAY_SIZE(side_sav), \
801 }; \
802 side_call(desc, &sav_desc); \
803 }
804
805 #define side_event(desc, sav) \
806 side_event_cond(desc) \
807 side_event_call(desc, SIDE_PARAM(sav))
808
809 #define side_event_call_variadic(desc, _sav, _var_fields) \
810 { \
811 const struct side_arg_vec side_sav[] = { _sav }; \
812 const struct side_arg_vec_description sav_desc = { \
813 .sav = side_sav, \
814 .len = SIDE_ARRAY_SIZE(side_sav), \
815 }; \
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), \
820 }; \
821 side_call_variadic(desc, &sav_desc, &var_struct); \
822 }
823
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))
827
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)), \
832 }
833
834 #define side_mapping_list(...) \
835 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
836
837 #define side_enum_mapping_range(_label, _begin, _end) \
838 { \
839 .range_begin = _begin, \
840 .range_end = _end, \
841 .label = _label, \
842 }
843
844 #define side_enum_mapping_value(_label, _value) \
845 { \
846 .range_begin = _value, \
847 .range_end = _value, \
848 .label = _label, \
849 }
850
851 #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
852 struct side_event_description _identifier = { \
853 .version = 0, \
854 .enabled = 0, \
855 .loglevel = _loglevel, \
856 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
857 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
858 .flags = (_flags), \
859 .provider_name = _provider, \
860 .event_name = _event, \
861 .fields = _fields, \
862 .attr = _attr, \
863 }
864
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)
868
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)
872
873 #define side_declare_event(_identifier) \
874 struct side_event_description _identifier
875
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);
881
882 #endif /* _SIDE_TRACE_H */
This page took 0.063962 seconds and 5 git commands to generate.