Document TODO for extensibility requirement
[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 extected 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_FLOAT_BINARY16,
45 SIDE_TYPE_FLOAT_BINARY32,
46 SIDE_TYPE_FLOAT_BINARY64,
47 SIDE_TYPE_FLOAT_BINARY128,
48
49 SIDE_TYPE_STRING,
50
51 SIDE_TYPE_STRUCT,
52 SIDE_TYPE_ARRAY,
53 SIDE_TYPE_VLA,
54 SIDE_TYPE_VLA_VISITOR,
55
56 SIDE_TYPE_ARRAY_U8,
57 SIDE_TYPE_ARRAY_U16,
58 SIDE_TYPE_ARRAY_U32,
59 SIDE_TYPE_ARRAY_U64,
60 SIDE_TYPE_ARRAY_S8,
61 SIDE_TYPE_ARRAY_S16,
62 SIDE_TYPE_ARRAY_S32,
63 SIDE_TYPE_ARRAY_S64,
64
65 SIDE_TYPE_VLA_U8,
66 SIDE_TYPE_VLA_U16,
67 SIDE_TYPE_VLA_U32,
68 SIDE_TYPE_VLA_U64,
69 SIDE_TYPE_VLA_S8,
70 SIDE_TYPE_VLA_S16,
71 SIDE_TYPE_VLA_S32,
72 SIDE_TYPE_VLA_S64,
73
74 SIDE_TYPE_DYNAMIC,
75 };
76
77 enum side_dynamic_type {
78 SIDE_DYNAMIC_TYPE_NULL,
79
80 SIDE_DYNAMIC_TYPE_BOOL,
81
82 SIDE_DYNAMIC_TYPE_U8,
83 SIDE_DYNAMIC_TYPE_U16,
84 SIDE_DYNAMIC_TYPE_U32,
85 SIDE_DYNAMIC_TYPE_U64,
86 SIDE_DYNAMIC_TYPE_S8,
87 SIDE_DYNAMIC_TYPE_S16,
88 SIDE_DYNAMIC_TYPE_S32,
89 SIDE_DYNAMIC_TYPE_S64,
90
91 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16,
92 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32,
93 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64,
94 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128,
95
96 SIDE_DYNAMIC_TYPE_STRING,
97
98 SIDE_DYNAMIC_TYPE_STRUCT,
99 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR,
100
101 SIDE_DYNAMIC_TYPE_VLA,
102 SIDE_DYNAMIC_TYPE_VLA_VISITOR,
103 };
104
105 enum side_loglevel {
106 SIDE_LOGLEVEL_EMERG = 0,
107 SIDE_LOGLEVEL_ALERT = 1,
108 SIDE_LOGLEVEL_CRIT = 2,
109 SIDE_LOGLEVEL_ERR = 3,
110 SIDE_LOGLEVEL_WARNING = 4,
111 SIDE_LOGLEVEL_NOTICE = 5,
112 SIDE_LOGLEVEL_INFO = 6,
113 SIDE_LOGLEVEL_DEBUG = 7,
114 };
115
116 enum side_visitor_status {
117 SIDE_VISITOR_STATUS_OK = 0,
118 SIDE_VISITOR_STATUS_ERROR = -1,
119 };
120
121 typedef enum side_visitor_status (*side_visitor)(
122 const struct side_tracer_visitor_ctx *tracer_ctx,
123 void *app_ctx);
124 typedef enum side_visitor_status (*side_dynamic_struct_visitor)(
125 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
126 void *app_ctx);
127 typedef enum side_visitor_status (*side_dynamic_vla_visitor)(
128 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
129 void *app_ctx);
130
131 /* User attributes. */
132 struct side_attr {
133 const char *key;
134 const char *value;
135 };
136
137 struct side_type_description {
138 uint32_t type; /* enum side_type */
139 uint32_t nr_attr;
140 const struct side_attr *attr;
141 union {
142 struct {
143 uint32_t nr_fields;
144 const struct side_event_field *fields;
145 } side_struct;
146 struct {
147 uint32_t length;
148 const struct side_type_description *elem_type;
149 } side_array;
150 struct {
151 const struct side_type_description *elem_type;
152 } side_vla;
153 struct {
154 const struct side_type_description *elem_type;
155 side_visitor visitor;
156 } side_vla_visitor;
157 } u;
158 };
159
160 struct side_event_field {
161 const char *field_name;
162 struct side_type_description side_type;
163 };
164
165 enum side_event_flags {
166 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
167 };
168
169 struct side_event_description {
170 uint32_t version;
171 uint32_t enabled;
172 uint32_t loglevel; /* enum side_loglevel */
173 uint32_t nr_fields;
174 uint32_t nr_attr;
175 uint32_t _unused;
176 uint64_t flags;
177 const char *provider_name;
178 const char *event_name;
179 const struct side_event_field *fields;
180 const struct side_attr *attr;
181 };
182
183 struct side_arg_dynamic_vec_vla {
184 const struct side_arg_dynamic_vec *sav;
185 uint32_t len;
186 };
187
188 struct side_arg_dynamic_vec {
189 uint32_t dynamic_type; /* enum side_dynamic_type */
190 uint32_t nr_attr;
191 const struct side_attr *attr;
192 union {
193 uint8_t side_bool;
194
195 uint8_t side_u8;
196 uint16_t side_u16;
197 uint32_t side_u32;
198 uint64_t side_u64;
199 int8_t side_s8;
200 int16_t side_s16;
201 int32_t side_s32;
202 int64_t side_s64;
203
204 #if __HAVE_FLOAT16
205 _Float16 side_float_binary16;
206 #endif
207 #if __HAVE_FLOAT32
208 _Float32 side_float_binary32;
209 #endif
210 #if __HAVE_FLOAT64
211 _Float64 side_float_binary64;
212 #endif
213 #if __HAVE_FLOAT128
214 _Float128 side_float_binary128;
215 #endif
216
217 const char *string;
218
219 const struct side_arg_dynamic_event_struct *side_dynamic_struct;
220 struct {
221 void *app_ctx;
222 side_dynamic_struct_visitor visitor;
223 } side_dynamic_struct_visitor;
224
225 const struct side_arg_dynamic_vec_vla *side_dynamic_vla;
226 struct {
227 void *app_ctx;
228 side_dynamic_vla_visitor visitor;
229 } side_dynamic_vla_visitor;
230 } u;
231 };
232
233 struct side_arg_dynamic_event_field {
234 const char *field_name;
235 const struct side_arg_dynamic_vec elem;
236 };
237
238 struct side_arg_dynamic_event_struct {
239 const struct side_arg_dynamic_event_field *fields;
240 uint32_t len;
241 };
242
243 struct side_arg_vec {
244 enum side_type type;
245 union {
246 uint8_t side_bool;
247
248 uint8_t side_u8;
249 uint16_t side_u16;
250 uint32_t side_u32;
251 uint64_t side_u64;
252 int8_t side_s8;
253 int16_t side_s16;
254 int32_t side_s32;
255 int64_t side_s64;
256
257 #if __HAVE_FLOAT16
258 _Float16 side_float_binary16;
259 #endif
260 #if __HAVE_FLOAT32
261 _Float32 side_float_binary32;
262 #endif
263 #if __HAVE_FLOAT64
264 _Float64 side_float_binary64;
265 #endif
266 #if __HAVE_FLOAT128
267 _Float128 side_float_binary128;
268 #endif
269
270 const char *string;
271 const struct side_arg_vec_description *side_struct;
272 const struct side_arg_vec_description *side_array;
273 const struct side_arg_vec_description *side_vla;
274 void *side_vla_app_visitor_ctx;
275
276 void *side_array_fixint;
277 struct {
278 void *p;
279 uint32_t length;
280 } side_vla_fixint;
281
282 struct side_arg_dynamic_vec dynamic;
283 } u;
284 };
285
286 struct side_arg_vec_description {
287 const struct side_arg_vec *sav;
288 uint32_t len;
289 };
290
291 /* The visitor pattern is a double-dispatch visitor. */
292 struct side_tracer_visitor_ctx {
293 enum side_visitor_status (*write_elem)(
294 const struct side_tracer_visitor_ctx *tracer_ctx,
295 const struct side_arg_vec *elem);
296 void *priv; /* Private tracer context. */
297 };
298
299 struct side_tracer_dynamic_struct_visitor_ctx {
300 enum side_visitor_status (*write_field)(
301 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
302 const struct side_arg_dynamic_event_field *dynamic_field);
303 void *priv; /* Private tracer context. */
304 };
305
306 struct side_tracer_dynamic_vla_visitor_ctx {
307 enum side_visitor_status (*write_elem)(
308 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
309 const struct side_arg_dynamic_vec *elem);
310 void *priv; /* Private tracer context. */
311 };
312
313 #define side_attr(_key, _value) \
314 { \
315 .key = _key, \
316 .value = _value, \
317 }
318
319 #define side_attr_list(...) \
320 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
321
322 #define side_type_decl(_type, _attr) \
323 { \
324 .type = _type, \
325 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
326 .attr = _attr, \
327 }
328
329 #define side_field(_name, _type, _attr) \
330 { \
331 .field_name = _name, \
332 .side_type = side_type_decl(_type, SIDE_PARAM(_attr)), \
333 }
334
335 #define side_type_struct_decl(_fields, _attr) \
336 { \
337 .type = SIDE_TYPE_STRUCT, \
338 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
339 .attr = _attr, \
340 .u = { \
341 .side_struct = { \
342 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
343 .fields = _fields, \
344 }, \
345 }, \
346 }
347 #define side_field_struct(_name, _fields, _attr) \
348 { \
349 .field_name = _name, \
350 .side_type = side_type_struct_decl(SIDE_PARAM(_fields), SIDE_PARAM(_attr)), \
351 }
352
353 #define side_type_array_decl(_elem_type, _length, _attr) \
354 { \
355 .type = SIDE_TYPE_ARRAY, \
356 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
357 .attr = _attr, \
358 .u = { \
359 .side_array = { \
360 .length = _length, \
361 .elem_type = _elem_type, \
362 }, \
363 }, \
364 }
365 #define side_field_array(_name, _elem_type, _length, _attr) \
366 { \
367 .field_name = _name, \
368 .side_type = side_type_array_decl(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)), \
369 }
370
371 #define side_type_vla_decl(_elem_type, _attr) \
372 { \
373 .type = SIDE_TYPE_VLA, \
374 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
375 .attr = _attr, \
376 .u = { \
377 .side_vla = { \
378 .elem_type = _elem_type, \
379 }, \
380 }, \
381 }
382 #define side_field_vla(_name, _elem_type, _attr) \
383 { \
384 .field_name = _name, \
385 .side_type = side_type_vla_decl(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)), \
386 }
387
388 #define side_type_vla_visitor_decl(_elem_type, _visitor, _attr) \
389 { \
390 .type = SIDE_TYPE_VLA_VISITOR, \
391 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
392 .attr = _attr, \
393 .u = { \
394 .side_vla_visitor = { \
395 .elem_type = SIDE_PARAM(_elem_type), \
396 .visitor = _visitor, \
397 }, \
398 }, \
399 }
400 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
401 { \
402 .field_name = _name, \
403 .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)), \
404 }
405
406 #define side_elem(...) \
407 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
408
409 #define side_elem_type(_type, _attr) \
410 side_elem(side_type_decl(_type, SIDE_PARAM(_attr)))
411
412 #define side_field_list(...) \
413 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
414
415 #define side_arg_bool(val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(val) } }
416 #define side_arg_u8(val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (val) } }
417 #define side_arg_u16(val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (val) } }
418 #define side_arg_u32(val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (val) } }
419 #define side_arg_u64(val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (val) } }
420 #define side_arg_s8(val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (val) } }
421 #define side_arg_s16(val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } }
422 #define side_arg_s32(val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } }
423 #define side_arg_s64(val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } }
424 #define side_arg_float_binary16(val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (val) } }
425 #define side_arg_float_binary32(val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (val) } }
426 #define side_arg_float_binary64(val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (val) } }
427 #define side_arg_float_binary128(val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (val) } }
428
429 #define side_arg_string(val) { .type = SIDE_TYPE_STRING, .u = { .string = (val) } }
430 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
431 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
432 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
433 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
434
435 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
436 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
437 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
438 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
439 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
440 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
441 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
442 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
443
444 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
445 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
446 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
447 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
448 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
449 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
450 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
451 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
452
453 #define side_arg_dynamic(dynamic_arg_type) \
454 { \
455 .type = SIDE_TYPE_DYNAMIC, \
456 .u = { \
457 .dynamic = dynamic_arg_type, \
458 }, \
459 }
460
461 #define side_arg_dynamic_null(_attr) \
462 { \
463 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
464 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
465 .attr = _attr, \
466 }
467
468 #define side_arg_dynamic_bool(_val, _attr) \
469 { \
470 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
471 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
472 .attr = _attr, \
473 .u = { \
474 .side_bool = !!(_val), \
475 }, \
476 }
477
478 #define side_arg_dynamic_u8(_val, _attr) \
479 { \
480 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
481 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
482 .attr = _attr, \
483 .u = { \
484 .side_u8 = (_val), \
485 }, \
486 }
487 #define side_arg_dynamic_u16(_val, _attr) \
488 { \
489 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
490 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
491 .attr = _attr, \
492 .u = { \
493 .side_u16 = (_val), \
494 }, \
495 }
496 #define side_arg_dynamic_u32(_val, _attr) \
497 { \
498 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
499 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
500 .attr = _attr, \
501 .u = { \
502 .side_u32 = (_val), \
503 }, \
504 }
505 #define side_arg_dynamic_u64(_val, _attr) \
506 { \
507 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
508 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
509 .attr = _attr, \
510 .u = { \
511 .side_u64 = (_val), \
512 }, \
513 }
514
515 #define side_arg_dynamic_s8(_val, _attr) \
516 { \
517 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
518 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
519 .attr = _attr, \
520 .u = { \
521 .side_s8 = (_val), \
522 }, \
523 }
524 #define side_arg_dynamic_s16(_val, _attr) \
525 { \
526 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
527 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
528 .attr = _attr, \
529 .u = { \
530 .side_s16 = (_val), \
531 }, \
532 }
533 #define side_arg_dynamic_s32(_val, _attr) \
534 { \
535 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
536 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
537 .attr = _attr, \
538 .u = { \
539 .side_s32 = (_val), \
540 }, \
541 }
542 #define side_arg_dynamic_s64(_val, _attr) \
543 { \
544 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
545 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
546 .attr = _attr, \
547 .u = { \
548 .side_s64 = (_val), \
549 }, \
550 }
551
552 #define side_arg_dynamic_float_binary16(_val, _attr) \
553 { \
554 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
555 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
556 .attr = _attr, \
557 .u = { \
558 .side_float_binary16 = (_val), \
559 }, \
560 }
561 #define side_arg_dynamic_float_binary32(_val, _attr) \
562 { \
563 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
564 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
565 .attr = _attr, \
566 .u = { \
567 .side_float_binary32 = (_val), \
568 }, \
569 }
570 #define side_arg_dynamic_float_binary64(_val, _attr) \
571 { \
572 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
573 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
574 .attr = _attr, \
575 .u = { \
576 .side_float_binary64 = (_val), \
577 }, \
578 }
579 #define side_arg_dynamic_float_binary128(_val, _attr) \
580 { \
581 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
582 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
583 .attr = _attr, \
584 .u = { \
585 .side_float_binary128 = (_val), \
586 }, \
587 }
588
589 #define side_arg_dynamic_string(_val, _attr) \
590 { \
591 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
592 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
593 .attr = _attr, \
594 .u = { \
595 .string = (_val), \
596 }, \
597 }
598
599 #define side_arg_dynamic_vla(_vla, _attr) \
600 { \
601 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
602 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
603 .attr = _attr, \
604 .u = { \
605 .side_dynamic_vla = (_vla), \
606 }, \
607 }
608
609 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
610 { \
611 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
612 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
613 .attr = _attr, \
614 .u = { \
615 .side_dynamic_vla_visitor = { \
616 .app_ctx = _ctx, \
617 .visitor = _dynamic_vla_visitor, \
618 }, \
619 }, \
620 }
621
622 #define side_arg_dynamic_struct(_struct, _attr) \
623 { \
624 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
625 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
626 .attr = _attr, \
627 .u = { \
628 .side_dynamic_struct = (_struct), \
629 }, \
630 }
631
632 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
633 { \
634 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
635 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
636 .attr = _attr, \
637 .u = { \
638 .side_dynamic_struct_visitor = { \
639 .app_ctx = _ctx, \
640 .visitor = _dynamic_struct_visitor, \
641 }, \
642 }, \
643 }
644
645 #define side_arg_dynamic_define_vec(_identifier, _sav) \
646 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
647 const struct side_arg_dynamic_vec_vla _identifier = { \
648 .sav = _identifier##_vec, \
649 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
650 }
651
652 #define side_arg_dynamic_define_struct(_identifier, _struct_fields) \
653 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
654 const struct side_arg_dynamic_event_struct _identifier = { \
655 .fields = _identifier##_fields, \
656 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
657 }
658
659 #define side_arg_define_vec(_identifier, _sav) \
660 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
661 const struct side_arg_vec_description _identifier = { \
662 .sav = _identifier##_vec, \
663 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
664 }
665
666 #define side_arg_dynamic_field(_name, _elem) \
667 { \
668 .field_name = _name, \
669 .elem = _elem, \
670 }
671
672 #define side_arg_list(...) __VA_ARGS__
673
674 #define side_event_cond(desc) if (side_unlikely((desc)->enabled))
675
676 #define side_event_call(desc, _sav) \
677 { \
678 const struct side_arg_vec side_sav[] = { _sav }; \
679 const struct side_arg_vec_description sav_desc = { \
680 .sav = side_sav, \
681 .len = SIDE_ARRAY_SIZE(side_sav), \
682 }; \
683 tracer_call(desc, &sav_desc); \
684 }
685
686 #define side_event(desc, sav) \
687 side_event_cond(desc) \
688 side_event_call(desc, SIDE_PARAM(sav))
689
690 #define side_event_call_variadic(desc, _sav, _var_fields) \
691 { \
692 const struct side_arg_vec side_sav[] = { _sav }; \
693 const struct side_arg_vec_description sav_desc = { \
694 .sav = side_sav, \
695 .len = SIDE_ARRAY_SIZE(side_sav), \
696 }; \
697 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
698 const struct side_arg_dynamic_event_struct var_struct = { \
699 .fields = side_fields, \
700 .len = SIDE_ARRAY_SIZE(side_fields), \
701 }; \
702 tracer_call_variadic(desc, &sav_desc, &var_struct); \
703 }
704
705 #define side_event_variadic(desc, sav, var) \
706 side_event_cond(desc) \
707 side_event_call_variadic(desc, SIDE_PARAM(sav), SIDE_PARAM(var))
708
709 #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
710 struct side_event_description _identifier = { \
711 .version = 0, \
712 .enabled = 0, \
713 .loglevel = _loglevel, \
714 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
715 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
716 .flags = (_flags), \
717 .provider_name = _provider, \
718 .event_name = _event, \
719 .fields = _fields, \
720 .attr = _attr, \
721 }
722
723 #define side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
724 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
725 SIDE_PARAM(_attr), 0)
726
727 #define side_define_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
728 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
729 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
730
731 #define side_declare_event(_identifier) \
732 struct side_event_description _identifier
733
734 #endif /* _SIDE_TRACE_H */
This page took 0.053307 seconds and 5 git commands to generate.