Introduce side_call*
[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 #define SIDE_EVENT_ENABLED_USER_MASK 0x0000FFFF
247 #define SIDE_EVENT_ENABLED_KERNEL_USER_EVENT_MASK 0x80000000
248
249 struct side_event_description {
250 uint32_t version;
251 uint32_t enabled;
252 uint32_t loglevel; /* enum side_loglevel */
253 uint32_t nr_fields;
254 uint32_t nr_attr;
255 uint32_t _unused;
256 uint64_t flags;
257 const char *provider_name;
258 const char *event_name;
259 const struct side_event_field *fields;
260 const struct side_attr *attr;
261 };
262
263 struct side_arg_dynamic_vec_vla {
264 const struct side_arg_dynamic_vec *sav;
265 uint32_t len;
266 };
267
268 struct side_arg_dynamic_vec {
269 uint32_t dynamic_type; /* enum side_dynamic_type */
270 uint32_t nr_attr;
271 const struct side_attr *attr;
272 union {
273 uint8_t side_bool;
274
275 uint8_t side_u8;
276 uint16_t side_u16;
277 uint32_t side_u32;
278 uint64_t side_u64;
279 int8_t side_s8;
280 int16_t side_s16;
281 int32_t side_s32;
282 int64_t side_s64;
283
284 #if __HAVE_FLOAT16
285 _Float16 side_float_binary16;
286 #endif
287 #if __HAVE_FLOAT32
288 _Float32 side_float_binary32;
289 #endif
290 #if __HAVE_FLOAT64
291 _Float64 side_float_binary64;
292 #endif
293 #if __HAVE_FLOAT128
294 _Float128 side_float_binary128;
295 #endif
296
297 const char *string;
298
299 const struct side_arg_dynamic_event_struct *side_dynamic_struct;
300 struct {
301 void *app_ctx;
302 side_dynamic_struct_visitor visitor;
303 } side_dynamic_struct_visitor;
304
305 const struct side_arg_dynamic_vec_vla *side_dynamic_vla;
306 struct {
307 void *app_ctx;
308 side_dynamic_vla_visitor visitor;
309 } side_dynamic_vla_visitor;
310 } u;
311 };
312
313 struct side_arg_dynamic_event_field {
314 const char *field_name;
315 const struct side_arg_dynamic_vec elem;
316 };
317
318 struct side_arg_dynamic_event_struct {
319 const struct side_arg_dynamic_event_field *fields;
320 uint32_t len;
321 };
322
323 struct side_arg_vec {
324 enum side_type type;
325 union {
326 uint8_t side_bool;
327
328 uint8_t side_u8;
329 uint16_t side_u16;
330 uint32_t side_u32;
331 uint64_t side_u64;
332 int8_t side_s8;
333 int16_t side_s16;
334 int32_t side_s32;
335 int64_t side_s64;
336
337 #if __HAVE_FLOAT16
338 _Float16 side_float_binary16;
339 #endif
340 #if __HAVE_FLOAT32
341 _Float32 side_float_binary32;
342 #endif
343 #if __HAVE_FLOAT64
344 _Float64 side_float_binary64;
345 #endif
346 #if __HAVE_FLOAT128
347 _Float128 side_float_binary128;
348 #endif
349
350 const char *string;
351 const struct side_arg_vec_description *side_struct;
352 const struct side_arg_vec_description *side_array;
353 const struct side_arg_vec_description *side_vla;
354 void *side_vla_app_visitor_ctx;
355
356 void *side_array_fixint;
357 struct {
358 void *p;
359 uint32_t length;
360 } side_vla_fixint;
361
362 struct side_arg_dynamic_vec dynamic;
363 } u;
364 };
365
366 struct side_arg_vec_description {
367 const struct side_arg_vec *sav;
368 uint32_t len;
369 };
370
371 /* The visitor pattern is a double-dispatch visitor. */
372 struct side_tracer_visitor_ctx {
373 enum side_visitor_status (*write_elem)(
374 const struct side_tracer_visitor_ctx *tracer_ctx,
375 const struct side_arg_vec *elem);
376 void *priv; /* Private tracer context. */
377 };
378
379 struct side_tracer_dynamic_struct_visitor_ctx {
380 enum side_visitor_status (*write_field)(
381 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
382 const struct side_arg_dynamic_event_field *dynamic_field);
383 void *priv; /* Private tracer context. */
384 };
385
386 struct side_tracer_dynamic_vla_visitor_ctx {
387 enum side_visitor_status (*write_elem)(
388 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
389 const struct side_arg_dynamic_vec *elem);
390 void *priv; /* Private tracer context. */
391 };
392
393 #define side_attr(_key, _value) \
394 { \
395 .key = _key, \
396 .value = SIDE_PARAM(_value), \
397 }
398
399 #define side_attr_list(...) \
400 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
401
402 #define side_type_decl(_type, _attr) \
403 { \
404 .type = _type, \
405 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
406 .attr = _attr, \
407 }
408
409 #define side_field(_name, _type, _attr) \
410 { \
411 .field_name = _name, \
412 .side_type = side_type_decl(_type, SIDE_PARAM(_attr)), \
413 }
414
415 #define side_type_enum_decl(_type, _mappings, _attr) \
416 { \
417 .type = _type, \
418 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
419 .attr = _attr, \
420 .u = { \
421 .side_enum_mappings = _mappings, \
422 }, \
423 }
424 #define side_field_enum(_name, _type, _mappings, _attr) \
425 { \
426 .field_name = _name, \
427 .side_type = side_type_enum_decl(_type, SIDE_PARAM(_mappings), SIDE_PARAM(_attr)), \
428 }
429
430 #define side_type_struct_decl(_fields, _attr) \
431 { \
432 .type = SIDE_TYPE_STRUCT, \
433 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
434 .attr = _attr, \
435 .u = { \
436 .side_struct = { \
437 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
438 .fields = _fields, \
439 }, \
440 }, \
441 }
442 #define side_field_struct(_name, _fields, _attr) \
443 { \
444 .field_name = _name, \
445 .side_type = side_type_struct_decl(SIDE_PARAM(_fields), SIDE_PARAM(_attr)), \
446 }
447
448 #define side_type_array_decl(_elem_type, _length, _attr) \
449 { \
450 .type = SIDE_TYPE_ARRAY, \
451 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
452 .attr = _attr, \
453 .u = { \
454 .side_array = { \
455 .length = _length, \
456 .elem_type = _elem_type, \
457 }, \
458 }, \
459 }
460 #define side_field_array(_name, _elem_type, _length, _attr) \
461 { \
462 .field_name = _name, \
463 .side_type = side_type_array_decl(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)), \
464 }
465
466 #define side_type_vla_decl(_elem_type, _attr) \
467 { \
468 .type = SIDE_TYPE_VLA, \
469 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
470 .attr = _attr, \
471 .u = { \
472 .side_vla = { \
473 .elem_type = _elem_type, \
474 }, \
475 }, \
476 }
477 #define side_field_vla(_name, _elem_type, _attr) \
478 { \
479 .field_name = _name, \
480 .side_type = side_type_vla_decl(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)), \
481 }
482
483 #define side_type_vla_visitor_decl(_elem_type, _visitor, _attr) \
484 { \
485 .type = SIDE_TYPE_VLA_VISITOR, \
486 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
487 .attr = _attr, \
488 .u = { \
489 .side_vla_visitor = { \
490 .elem_type = SIDE_PARAM(_elem_type), \
491 .visitor = _visitor, \
492 }, \
493 }, \
494 }
495 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
496 { \
497 .field_name = _name, \
498 .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)), \
499 }
500
501 #define side_elem(...) \
502 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
503
504 #define side_elem_type(_type, _attr) \
505 side_elem(side_type_decl(_type, SIDE_PARAM(_attr)))
506
507 #define side_field_list(...) \
508 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
509
510 #define side_arg_bool(val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(val) } }
511 #define side_arg_u8(val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (val) } }
512 #define side_arg_u16(val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (val) } }
513 #define side_arg_u32(val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (val) } }
514 #define side_arg_u64(val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (val) } }
515 #define side_arg_s8(val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (val) } }
516 #define side_arg_s16(val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } }
517 #define side_arg_s32(val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } }
518 #define side_arg_s64(val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } }
519 #define side_arg_enum_u8(val) { .type = SIDE_TYPE_ENUM_U8, .u = { .side_u8 = (val) } }
520 #define side_arg_enum_u16(val) { .type = SIDE_TYPE_ENUM_U16, .u = { .side_u16 = (val) } }
521 #define side_arg_enum_u32(val) { .type = SIDE_TYPE_ENUM_U32, .u = { .side_u32 = (val) } }
522 #define side_arg_enum_u64(val) { .type = SIDE_TYPE_ENUM_U64, .u = { .side_u64 = (val) } }
523 #define side_arg_enum_s8(val) { .type = SIDE_TYPE_ENUM_S8, .u = { .side_s8 = (val) } }
524 #define side_arg_enum_s16(val) { .type = SIDE_TYPE_ENUM_S16, .u = { .side_s16 = (val) } }
525 #define side_arg_enum_s32(val) { .type = SIDE_TYPE_ENUM_S32, .u = { .side_s32 = (val) } }
526 #define side_arg_enum_s64(val) { .type = SIDE_TYPE_ENUM_S64, .u = { .side_s64 = (val) } }
527 #define side_arg_enum_bitmap8(val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (val) } }
528 #define side_arg_enum_bitmap16(val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (val) } }
529 #define side_arg_enum_bitmap32(val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (val) } }
530 #define side_arg_enum_bitmap64(val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (val) } }
531 #define side_arg_float_binary16(val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (val) } }
532 #define side_arg_float_binary32(val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (val) } }
533 #define side_arg_float_binary64(val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (val) } }
534 #define side_arg_float_binary128(val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (val) } }
535
536 #define side_arg_string(val) { .type = SIDE_TYPE_STRING, .u = { .string = (val) } }
537 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
538 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
539 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
540 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
541
542 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
543 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
544 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
545 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
546 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
547 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
548 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
549 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
550
551 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
552 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
553 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
554 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
555 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
556 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
557 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
558 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
559
560 #define side_arg_dynamic(dynamic_arg_type) \
561 { \
562 .type = SIDE_TYPE_DYNAMIC, \
563 .u = { \
564 .dynamic = dynamic_arg_type, \
565 }, \
566 }
567
568 #define side_arg_dynamic_null(_attr) \
569 { \
570 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
571 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
572 .attr = _attr, \
573 }
574
575 #define side_arg_dynamic_bool(_val, _attr) \
576 { \
577 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
578 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
579 .attr = _attr, \
580 .u = { \
581 .side_bool = !!(_val), \
582 }, \
583 }
584
585 #define side_arg_dynamic_u8(_val, _attr) \
586 { \
587 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
588 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
589 .attr = _attr, \
590 .u = { \
591 .side_u8 = (_val), \
592 }, \
593 }
594 #define side_arg_dynamic_u16(_val, _attr) \
595 { \
596 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
597 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
598 .attr = _attr, \
599 .u = { \
600 .side_u16 = (_val), \
601 }, \
602 }
603 #define side_arg_dynamic_u32(_val, _attr) \
604 { \
605 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
606 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
607 .attr = _attr, \
608 .u = { \
609 .side_u32 = (_val), \
610 }, \
611 }
612 #define side_arg_dynamic_u64(_val, _attr) \
613 { \
614 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
615 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
616 .attr = _attr, \
617 .u = { \
618 .side_u64 = (_val), \
619 }, \
620 }
621
622 #define side_arg_dynamic_s8(_val, _attr) \
623 { \
624 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
625 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
626 .attr = _attr, \
627 .u = { \
628 .side_s8 = (_val), \
629 }, \
630 }
631 #define side_arg_dynamic_s16(_val, _attr) \
632 { \
633 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
634 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
635 .attr = _attr, \
636 .u = { \
637 .side_s16 = (_val), \
638 }, \
639 }
640 #define side_arg_dynamic_s32(_val, _attr) \
641 { \
642 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
643 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
644 .attr = _attr, \
645 .u = { \
646 .side_s32 = (_val), \
647 }, \
648 }
649 #define side_arg_dynamic_s64(_val, _attr) \
650 { \
651 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
652 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
653 .attr = _attr, \
654 .u = { \
655 .side_s64 = (_val), \
656 }, \
657 }
658
659 #define side_arg_dynamic_float_binary16(_val, _attr) \
660 { \
661 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
662 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
663 .attr = _attr, \
664 .u = { \
665 .side_float_binary16 = (_val), \
666 }, \
667 }
668 #define side_arg_dynamic_float_binary32(_val, _attr) \
669 { \
670 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
671 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
672 .attr = _attr, \
673 .u = { \
674 .side_float_binary32 = (_val), \
675 }, \
676 }
677 #define side_arg_dynamic_float_binary64(_val, _attr) \
678 { \
679 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
680 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
681 .attr = _attr, \
682 .u = { \
683 .side_float_binary64 = (_val), \
684 }, \
685 }
686 #define side_arg_dynamic_float_binary128(_val, _attr) \
687 { \
688 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
689 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
690 .attr = _attr, \
691 .u = { \
692 .side_float_binary128 = (_val), \
693 }, \
694 }
695
696 #define side_arg_dynamic_string(_val, _attr) \
697 { \
698 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
699 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
700 .attr = _attr, \
701 .u = { \
702 .string = (_val), \
703 }, \
704 }
705
706 #define side_arg_dynamic_vla(_vla, _attr) \
707 { \
708 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
709 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
710 .attr = _attr, \
711 .u = { \
712 .side_dynamic_vla = (_vla), \
713 }, \
714 }
715
716 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
717 { \
718 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
719 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
720 .attr = _attr, \
721 .u = { \
722 .side_dynamic_vla_visitor = { \
723 .app_ctx = _ctx, \
724 .visitor = _dynamic_vla_visitor, \
725 }, \
726 }, \
727 }
728
729 #define side_arg_dynamic_struct(_struct, _attr) \
730 { \
731 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
732 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
733 .attr = _attr, \
734 .u = { \
735 .side_dynamic_struct = (_struct), \
736 }, \
737 }
738
739 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
740 { \
741 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
742 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
743 .attr = _attr, \
744 .u = { \
745 .side_dynamic_struct_visitor = { \
746 .app_ctx = _ctx, \
747 .visitor = _dynamic_struct_visitor, \
748 }, \
749 }, \
750 }
751
752 #define side_arg_dynamic_define_vec(_identifier, _sav) \
753 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
754 const struct side_arg_dynamic_vec_vla _identifier = { \
755 .sav = _identifier##_vec, \
756 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
757 }
758
759 #define side_arg_dynamic_define_struct(_identifier, _struct_fields) \
760 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
761 const struct side_arg_dynamic_event_struct _identifier = { \
762 .fields = _identifier##_fields, \
763 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
764 }
765
766 #define side_arg_define_vec(_identifier, _sav) \
767 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
768 const struct side_arg_vec_description _identifier = { \
769 .sav = _identifier##_vec, \
770 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
771 }
772
773 #define side_arg_dynamic_field(_name, _elem) \
774 { \
775 .field_name = _name, \
776 .elem = _elem, \
777 }
778
779 #define side_arg_list(...) __VA_ARGS__
780
781 #define side_attr_bool(val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(val) } }
782 #define side_attr_u8(val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (val) } }
783 #define side_attr_u16(val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (val) } }
784 #define side_attr_u32(val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (val) } }
785 #define side_attr_u64(val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (val) } }
786 #define side_attr_s8(val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (val) } }
787 #define side_attr_s16(val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (val) } }
788 #define side_attr_s32(val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (val) } }
789 #define side_attr_s64(val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (val) } }
790 #define side_attr_float_binary16(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (val) } }
791 #define side_attr_float_binary32(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (val) } }
792 #define side_attr_float_binary64(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (val) } }
793 #define side_attr_float_binary128(val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (val) } }
794 #define side_attr_string(val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (val) } }
795
796 #define side_event_cond(desc) if (side_unlikely((desc)->enabled))
797
798 #define side_event_call(desc, _sav) \
799 { \
800 const struct side_arg_vec side_sav[] = { _sav }; \
801 const struct side_arg_vec_description sav_desc = { \
802 .sav = side_sav, \
803 .len = SIDE_ARRAY_SIZE(side_sav), \
804 }; \
805 side_call(desc, &sav_desc); \
806 }
807
808 #define side_event(desc, sav) \
809 side_event_cond(desc) \
810 side_event_call(desc, SIDE_PARAM(sav))
811
812 #define side_event_call_variadic(desc, _sav, _var_fields) \
813 { \
814 const struct side_arg_vec side_sav[] = { _sav }; \
815 const struct side_arg_vec_description sav_desc = { \
816 .sav = side_sav, \
817 .len = SIDE_ARRAY_SIZE(side_sav), \
818 }; \
819 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
820 const struct side_arg_dynamic_event_struct var_struct = { \
821 .fields = side_fields, \
822 .len = SIDE_ARRAY_SIZE(side_fields), \
823 }; \
824 side_call_variadic(desc, &sav_desc, &var_struct); \
825 }
826
827 #define side_event_variadic(desc, sav, var) \
828 side_event_cond(desc) \
829 side_event_call_variadic(desc, SIDE_PARAM(sav), SIDE_PARAM(var))
830
831 #define side_define_enum(_identifier, _mappings) \
832 const struct side_enum_mappings _identifier = { \
833 .mappings = _mappings, \
834 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
835 }
836
837 #define side_mapping_list(...) \
838 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
839
840 #define side_enum_mapping_range(_label, _begin, _end) \
841 { \
842 .range_begin = _begin, \
843 .range_end = _end, \
844 .label = _label, \
845 }
846
847 #define side_enum_mapping_value(_label, _value) \
848 { \
849 .range_begin = _value, \
850 .range_end = _value, \
851 .label = _label, \
852 }
853
854 #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
855 struct side_event_description _identifier = { \
856 .version = 0, \
857 .enabled = 0, \
858 .loglevel = _loglevel, \
859 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
860 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
861 .flags = (_flags), \
862 .provider_name = _provider, \
863 .event_name = _event, \
864 .fields = _fields, \
865 .attr = _attr, \
866 }
867
868 #define side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
869 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
870 SIDE_PARAM(_attr), 0)
871
872 #define side_define_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
873 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
874 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
875
876 #define side_declare_event(_identifier) \
877 struct side_event_description _identifier
878
879 void side_call(const struct side_event_description *desc,
880 const struct side_arg_vec_description *sav_desc);
881 void side_call_variadic(const struct side_event_description *desc,
882 const struct side_arg_vec_description *sav_desc,
883 const struct side_arg_dynamic_event_struct *var_struct);
884
885 #endif /* _SIDE_TRACE_H */
This page took 0.069376 seconds and 4 git commands to generate.