Refactor: use _side_field()
[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_enum_bitmap_mapping {
214 int64_t range_begin;
215 int64_t range_end;
216 const char *label;
217 };
218
219 struct side_enum_bitmap_mappings {
220 const struct side_enum_bitmap_mapping *mappings;
221 uint32_t nr_mappings;
222 };
223
224 struct side_type_description {
225 uint32_t type; /* enum side_type */
226 uint32_t nr_attr;
227 const struct side_attr *attr;
228 union {
229 struct {
230 uint32_t nr_fields;
231 const struct side_event_field *fields;
232 } side_struct;
233 struct {
234 uint32_t length;
235 const struct side_type_description *elem_type;
236 } side_array;
237 struct {
238 const struct side_type_description *elem_type;
239 } side_vla;
240 struct {
241 const struct side_type_description *elem_type;
242 side_visitor visitor;
243 } side_vla_visitor;
244 const struct side_enum_mappings *side_enum_mappings;
245 const struct side_enum_bitmap_mappings *side_enum_bitmap_mappings;
246 } u;
247 };
248
249 struct side_event_field {
250 const char *field_name;
251 struct side_type_description side_type;
252 };
253
254 enum side_event_flags {
255 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
256 };
257
258 struct side_event_description {
259 uint32_t version;
260 uint32_t enabled;
261 uint32_t loglevel; /* enum side_loglevel */
262 uint32_t nr_fields;
263 uint32_t nr_attr;
264 uint32_t _unused;
265 uint64_t flags;
266 const char *provider_name;
267 const char *event_name;
268 const struct side_event_field *fields;
269 const struct side_attr *attr;
270 };
271
272 struct side_arg_dynamic_vec_vla {
273 const struct side_arg_dynamic_vec *sav;
274 uint32_t len;
275 };
276
277 struct side_arg_dynamic_vec {
278 uint32_t dynamic_type; /* enum side_dynamic_type */
279 uint32_t nr_attr;
280 const struct side_attr *attr;
281 union {
282 uint8_t side_bool;
283
284 uint8_t side_u8;
285 uint16_t side_u16;
286 uint32_t side_u32;
287 uint64_t side_u64;
288 int8_t side_s8;
289 int16_t side_s16;
290 int32_t side_s32;
291 int64_t side_s64;
292
293 #if __HAVE_FLOAT16
294 _Float16 side_float_binary16;
295 #endif
296 #if __HAVE_FLOAT32
297 _Float32 side_float_binary32;
298 #endif
299 #if __HAVE_FLOAT64
300 _Float64 side_float_binary64;
301 #endif
302 #if __HAVE_FLOAT128
303 _Float128 side_float_binary128;
304 #endif
305
306 const char *string;
307
308 const struct side_arg_dynamic_event_struct *side_dynamic_struct;
309 struct {
310 void *app_ctx;
311 side_dynamic_struct_visitor visitor;
312 } side_dynamic_struct_visitor;
313
314 const struct side_arg_dynamic_vec_vla *side_dynamic_vla;
315 struct {
316 void *app_ctx;
317 side_dynamic_vla_visitor visitor;
318 } side_dynamic_vla_visitor;
319 } u;
320 };
321
322 struct side_arg_dynamic_event_field {
323 const char *field_name;
324 const struct side_arg_dynamic_vec elem;
325 };
326
327 struct side_arg_dynamic_event_struct {
328 const struct side_arg_dynamic_event_field *fields;
329 uint32_t len;
330 };
331
332 struct side_arg_vec {
333 enum side_type type;
334 union {
335 uint8_t side_bool;
336
337 uint8_t side_u8;
338 uint16_t side_u16;
339 uint32_t side_u32;
340 uint64_t side_u64;
341 int8_t side_s8;
342 int16_t side_s16;
343 int32_t side_s32;
344 int64_t side_s64;
345
346 #if __HAVE_FLOAT16
347 _Float16 side_float_binary16;
348 #endif
349 #if __HAVE_FLOAT32
350 _Float32 side_float_binary32;
351 #endif
352 #if __HAVE_FLOAT64
353 _Float64 side_float_binary64;
354 #endif
355 #if __HAVE_FLOAT128
356 _Float128 side_float_binary128;
357 #endif
358
359 const char *string;
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;
364
365 void *side_array_fixint;
366 struct {
367 void *p;
368 uint32_t length;
369 } side_vla_fixint;
370
371 struct side_arg_dynamic_vec dynamic;
372 } u;
373 };
374
375 struct side_arg_vec_description {
376 const struct side_arg_vec *sav;
377 uint32_t len;
378 };
379
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. */
386 };
387
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. */
393 };
394
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. */
400 };
401
402 #define side_attr(_key, _value) \
403 { \
404 .key = _key, \
405 .value = SIDE_PARAM(_value), \
406 }
407
408 #define side_attr_list(...) \
409 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
410
411 #define _side_type(_type, _attr) \
412 { \
413 .type = _type, \
414 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
415 .attr = _attr, \
416 }
417
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))
433
434 #define _side_field(_name, _type) \
435 { \
436 .field_name = _name, \
437 .side_type = _type, \
438 }
439
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)))
455
456 #define side_type_enum(_type, _mappings, _attr) \
457 { \
458 .type = _type, \
459 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
460 .attr = _attr, \
461 .u = { \
462 .side_enum_mappings = _mappings, \
463 }, \
464 }
465 #define _side_field_enum(_name, _type, _mappings, _attr) \
466 _side_field(_name, side_type_enum(_type, SIDE_PARAM(_mappings), SIDE_PARAM(_attr)))
467
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))
484
485 #define side_type_enum_bitmap(_type, _mappings, _attr) \
486 { \
487 .type = _type, \
488 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
489 .attr = _attr, \
490 .u = { \
491 .side_enum_bitmap_mappings = _mappings, \
492 }, \
493 }
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)))
496
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))
505
506 #define side_type_struct(_fields, _attr) \
507 { \
508 .type = SIDE_TYPE_STRUCT, \
509 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
510 .attr = _attr, \
511 .u = { \
512 .side_struct = { \
513 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
514 .fields = _fields, \
515 }, \
516 }, \
517 }
518 #define side_field_struct(_name, _fields, _attr) \
519 _side_field(_name, side_type_struct(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
520
521 #define side_type_array(_elem_type, _length, _attr) \
522 { \
523 .type = SIDE_TYPE_ARRAY, \
524 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
525 .attr = _attr, \
526 .u = { \
527 .side_array = { \
528 .length = _length, \
529 .elem_type = _elem_type, \
530 }, \
531 }, \
532 }
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)))
535
536 #define side_type_vla(_elem_type, _attr) \
537 { \
538 .type = SIDE_TYPE_VLA, \
539 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
540 .attr = _attr, \
541 .u = { \
542 .side_vla = { \
543 .elem_type = _elem_type, \
544 }, \
545 }, \
546 }
547 #define side_field_vla(_name, _elem_type, _attr) \
548 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
549
550 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
551 { \
552 .type = SIDE_TYPE_VLA_VISITOR, \
553 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
554 .attr = _attr, \
555 .u = { \
556 .side_vla_visitor = { \
557 .elem_type = SIDE_PARAM(_elem_type), \
558 .visitor = _visitor, \
559 }, \
560 }, \
561 }
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)))
564
565 #define side_elem(...) \
566 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
567
568 #define side_field_list(...) \
569 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
570
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) } }
596
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) } }
602
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) } }
611
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) } } }
620
621 #define side_arg_dynamic(dynamic_arg_type) \
622 { \
623 .type = SIDE_TYPE_DYNAMIC, \
624 .u = { \
625 .dynamic = dynamic_arg_type, \
626 }, \
627 }
628
629 #define side_arg_dynamic_null(_attr) \
630 { \
631 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
632 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
633 .attr = _attr, \
634 }
635
636 #define side_arg_dynamic_bool(_val, _attr) \
637 { \
638 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
639 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
640 .attr = _attr, \
641 .u = { \
642 .side_bool = !!(_val), \
643 }, \
644 }
645
646 #define side_arg_dynamic_u8(_val, _attr) \
647 { \
648 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
649 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
650 .attr = _attr, \
651 .u = { \
652 .side_u8 = (_val), \
653 }, \
654 }
655 #define side_arg_dynamic_u16(_val, _attr) \
656 { \
657 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
658 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
659 .attr = _attr, \
660 .u = { \
661 .side_u16 = (_val), \
662 }, \
663 }
664 #define side_arg_dynamic_u32(_val, _attr) \
665 { \
666 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
667 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
668 .attr = _attr, \
669 .u = { \
670 .side_u32 = (_val), \
671 }, \
672 }
673 #define side_arg_dynamic_u64(_val, _attr) \
674 { \
675 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
676 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
677 .attr = _attr, \
678 .u = { \
679 .side_u64 = (_val), \
680 }, \
681 }
682
683 #define side_arg_dynamic_s8(_val, _attr) \
684 { \
685 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
686 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
687 .attr = _attr, \
688 .u = { \
689 .side_s8 = (_val), \
690 }, \
691 }
692 #define side_arg_dynamic_s16(_val, _attr) \
693 { \
694 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
695 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
696 .attr = _attr, \
697 .u = { \
698 .side_s16 = (_val), \
699 }, \
700 }
701 #define side_arg_dynamic_s32(_val, _attr) \
702 { \
703 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
704 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
705 .attr = _attr, \
706 .u = { \
707 .side_s32 = (_val), \
708 }, \
709 }
710 #define side_arg_dynamic_s64(_val, _attr) \
711 { \
712 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
713 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
714 .attr = _attr, \
715 .u = { \
716 .side_s64 = (_val), \
717 }, \
718 }
719
720 #define side_arg_dynamic_float_binary16(_val, _attr) \
721 { \
722 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
723 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
724 .attr = _attr, \
725 .u = { \
726 .side_float_binary16 = (_val), \
727 }, \
728 }
729 #define side_arg_dynamic_float_binary32(_val, _attr) \
730 { \
731 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
732 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
733 .attr = _attr, \
734 .u = { \
735 .side_float_binary32 = (_val), \
736 }, \
737 }
738 #define side_arg_dynamic_float_binary64(_val, _attr) \
739 { \
740 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
741 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
742 .attr = _attr, \
743 .u = { \
744 .side_float_binary64 = (_val), \
745 }, \
746 }
747 #define side_arg_dynamic_float_binary128(_val, _attr) \
748 { \
749 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
750 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
751 .attr = _attr, \
752 .u = { \
753 .side_float_binary128 = (_val), \
754 }, \
755 }
756
757 #define side_arg_dynamic_string(_val, _attr) \
758 { \
759 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
760 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
761 .attr = _attr, \
762 .u = { \
763 .string = (_val), \
764 }, \
765 }
766
767 #define side_arg_dynamic_vla(_vla, _attr) \
768 { \
769 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
770 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
771 .attr = _attr, \
772 .u = { \
773 .side_dynamic_vla = (_vla), \
774 }, \
775 }
776
777 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
778 { \
779 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
780 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
781 .attr = _attr, \
782 .u = { \
783 .side_dynamic_vla_visitor = { \
784 .app_ctx = _ctx, \
785 .visitor = _dynamic_vla_visitor, \
786 }, \
787 }, \
788 }
789
790 #define side_arg_dynamic_struct(_struct, _attr) \
791 { \
792 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
793 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
794 .attr = _attr, \
795 .u = { \
796 .side_dynamic_struct = (_struct), \
797 }, \
798 }
799
800 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
801 { \
802 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
803 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
804 .attr = _attr, \
805 .u = { \
806 .side_dynamic_struct_visitor = { \
807 .app_ctx = _ctx, \
808 .visitor = _dynamic_struct_visitor, \
809 }, \
810 }, \
811 }
812
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), \
818 }
819
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), \
825 }
826
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), \
832 }
833
834 #define side_arg_dynamic_field(_name, _elem) \
835 { \
836 .field_name = _name, \
837 .elem = _elem, \
838 }
839
840 #define side_arg_list(...) __VA_ARGS__
841
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) } }
856
857 #define side_event_cond(desc) if (side_unlikely((desc)->enabled))
858
859 #define side_event_call(desc, _sav) \
860 { \
861 const struct side_arg_vec side_sav[] = { _sav }; \
862 const struct side_arg_vec_description sav_desc = { \
863 .sav = side_sav, \
864 .len = SIDE_ARRAY_SIZE(side_sav), \
865 }; \
866 side_call(desc, &sav_desc); \
867 }
868
869 #define side_event(desc, sav) \
870 side_event_cond(desc) \
871 side_event_call(desc, SIDE_PARAM(sav))
872
873 #define side_event_call_variadic(desc, _sav, _var_fields) \
874 { \
875 const struct side_arg_vec side_sav[] = { _sav }; \
876 const struct side_arg_vec_description sav_desc = { \
877 .sav = side_sav, \
878 .len = SIDE_ARRAY_SIZE(side_sav), \
879 }; \
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), \
884 }; \
885 side_call_variadic(desc, &sav_desc, &var_struct); \
886 }
887
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))
891
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)), \
896 }
897
898 #define side_enum_mapping_list(...) \
899 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
900
901 #define side_enum_mapping_range(_label, _begin, _end) \
902 { \
903 .range_begin = _begin, \
904 .range_end = _end, \
905 .label = _label, \
906 }
907
908 #define side_enum_mapping_value(_label, _value) \
909 { \
910 .range_begin = _value, \
911 .range_end = _value, \
912 .label = _label, \
913 }
914
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)), \
919 }
920
921 #define side_enum_bitmap_mapping_list(...) \
922 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
923
924 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
925 { \
926 .range_begin = _begin, \
927 .range_end = _end, \
928 .label = _label, \
929 }
930
931 #define side_enum_bitmap_mapping_value(_label, _value) \
932 { \
933 .range_begin = _value, \
934 .range_end = _value, \
935 .label = _label, \
936 }
937
938 #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
939 struct side_event_description _identifier = { \
940 .version = 0, \
941 .enabled = 0, \
942 .loglevel = _loglevel, \
943 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
944 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
945 .flags = (_flags), \
946 .provider_name = _provider, \
947 .event_name = _event, \
948 .fields = _fields, \
949 .attr = _attr, \
950 }
951
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)
955
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)
959
960 #define side_declare_event(_identifier) \
961 struct side_event_description _identifier
962
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);
968
969 #endif /* _SIDE_TRACE_H */
This page took 0.048784 seconds and 4 git commands to generate.