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