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