Split nr callbacks from enabled references
[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 struct side_event_description;
32 struct side_arg_dynamic_event_struct;
33 struct side_events_register_handle;
34
35 enum side_type {
36 /* Basic types */
37 SIDE_TYPE_BOOL,
38 SIDE_TYPE_U8,
39 SIDE_TYPE_U16,
40 SIDE_TYPE_U32,
41 SIDE_TYPE_U64,
42 SIDE_TYPE_S8,
43 SIDE_TYPE_S16,
44 SIDE_TYPE_S32,
45 SIDE_TYPE_S64,
46 SIDE_TYPE_BYTE,
47 SIDE_TYPE_FLOAT_BINARY16,
48 SIDE_TYPE_FLOAT_BINARY32,
49 SIDE_TYPE_FLOAT_BINARY64,
50 SIDE_TYPE_FLOAT_BINARY128,
51 SIDE_TYPE_STRING,
52
53 /* Compound types */
54 SIDE_TYPE_STRUCT,
55 SIDE_TYPE_ARRAY,
56 SIDE_TYPE_VLA,
57 SIDE_TYPE_VLA_VISITOR,
58
59 SIDE_TYPE_ARRAY_U8,
60 SIDE_TYPE_ARRAY_U16,
61 SIDE_TYPE_ARRAY_U32,
62 SIDE_TYPE_ARRAY_U64,
63 SIDE_TYPE_ARRAY_S8,
64 SIDE_TYPE_ARRAY_S16,
65 SIDE_TYPE_ARRAY_S32,
66 SIDE_TYPE_ARRAY_S64,
67 SIDE_TYPE_ARRAY_BYTE,
68
69 SIDE_TYPE_VLA_U8,
70 SIDE_TYPE_VLA_U16,
71 SIDE_TYPE_VLA_U32,
72 SIDE_TYPE_VLA_U64,
73 SIDE_TYPE_VLA_S8,
74 SIDE_TYPE_VLA_S16,
75 SIDE_TYPE_VLA_S32,
76 SIDE_TYPE_VLA_S64,
77 SIDE_TYPE_VLA_BYTE,
78
79 /* Enumeration types */
80 SIDE_TYPE_ENUM,
81 SIDE_TYPE_ENUM_BITMAP,
82
83 /* Dynamic type */
84 SIDE_TYPE_DYNAMIC,
85 };
86
87 enum side_dynamic_type {
88 /* Basic types */
89 SIDE_DYNAMIC_TYPE_NULL,
90 SIDE_DYNAMIC_TYPE_BOOL,
91 SIDE_DYNAMIC_TYPE_U8,
92 SIDE_DYNAMIC_TYPE_U16,
93 SIDE_DYNAMIC_TYPE_U32,
94 SIDE_DYNAMIC_TYPE_U64,
95 SIDE_DYNAMIC_TYPE_S8,
96 SIDE_DYNAMIC_TYPE_S16,
97 SIDE_DYNAMIC_TYPE_S32,
98 SIDE_DYNAMIC_TYPE_S64,
99 SIDE_DYNAMIC_TYPE_BYTE,
100 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16,
101 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32,
102 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64,
103 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128,
104 SIDE_DYNAMIC_TYPE_STRING,
105
106 /* Compound types */
107 SIDE_DYNAMIC_TYPE_STRUCT,
108 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR,
109 SIDE_DYNAMIC_TYPE_VLA,
110 SIDE_DYNAMIC_TYPE_VLA_VISITOR,
111 };
112
113 enum side_attr_type {
114 SIDE_ATTR_TYPE_NULL,
115 SIDE_ATTR_TYPE_BOOL,
116 SIDE_ATTR_TYPE_U8,
117 SIDE_ATTR_TYPE_U16,
118 SIDE_ATTR_TYPE_U32,
119 SIDE_ATTR_TYPE_U64,
120 SIDE_ATTR_TYPE_S8,
121 SIDE_ATTR_TYPE_S16,
122 SIDE_ATTR_TYPE_S32,
123 SIDE_ATTR_TYPE_S64,
124 SIDE_ATTR_TYPE_FLOAT_BINARY16,
125 SIDE_ATTR_TYPE_FLOAT_BINARY32,
126 SIDE_ATTR_TYPE_FLOAT_BINARY64,
127 SIDE_ATTR_TYPE_FLOAT_BINARY128,
128 SIDE_ATTR_TYPE_STRING,
129 };
130
131 enum side_loglevel {
132 SIDE_LOGLEVEL_EMERG = 0,
133 SIDE_LOGLEVEL_ALERT = 1,
134 SIDE_LOGLEVEL_CRIT = 2,
135 SIDE_LOGLEVEL_ERR = 3,
136 SIDE_LOGLEVEL_WARNING = 4,
137 SIDE_LOGLEVEL_NOTICE = 5,
138 SIDE_LOGLEVEL_INFO = 6,
139 SIDE_LOGLEVEL_DEBUG = 7,
140 };
141
142 enum side_visitor_status {
143 SIDE_VISITOR_STATUS_OK = 0,
144 SIDE_VISITOR_STATUS_ERROR = -1,
145 };
146
147 enum side_error {
148 SIDE_ERROR_OK = 0,
149 SIDE_ERROR_INVAL = 1,
150 SIDE_ERROR_EXIST = 2,
151 SIDE_ERROR_NOMEM = 3,
152 SIDE_ERROR_NOENT = 4,
153 SIDE_ERROR_EXITING = 5,
154 };
155
156 typedef enum side_visitor_status (*side_visitor)(
157 const struct side_tracer_visitor_ctx *tracer_ctx,
158 void *app_ctx);
159 typedef enum side_visitor_status (*side_dynamic_struct_visitor)(
160 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
161 void *app_ctx);
162 typedef enum side_visitor_status (*side_dynamic_vla_visitor)(
163 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
164 void *app_ctx);
165
166 struct side_attr_value {
167 uint32_t type; /* enum side_attr_type */
168 union {
169 uint8_t side_bool;
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 #if __HAVE_FLOAT16
179 _Float16 side_float_binary16;
180 #endif
181 #if __HAVE_FLOAT32
182 _Float32 side_float_binary32;
183 #endif
184 #if __HAVE_FLOAT64
185 _Float64 side_float_binary64;
186 #endif
187 #if __HAVE_FLOAT128
188 _Float128 side_float_binary128;
189 #endif
190 const char *string;
191 } u;
192 };
193
194 /* User attributes. */
195 struct side_attr {
196 const char *key;
197 const struct side_attr_value value;
198 };
199
200 struct side_enum_mapping {
201 int64_t range_begin;
202 int64_t range_end;
203 const char *label;
204 };
205
206 struct side_enum_mappings {
207 const struct side_enum_mapping *mappings;
208 const struct side_attr *attr;
209 uint32_t nr_mappings;
210 uint32_t nr_attr;
211 };
212
213 struct side_enum_bitmap_mapping {
214 uint64_t range_begin;
215 uint64_t range_end;
216 const char *label;
217 };
218
219 struct side_enum_bitmap_mappings {
220 const struct side_enum_bitmap_mapping *mappings;
221 const struct side_attr *attr;
222 uint32_t nr_mappings;
223 uint32_t nr_attr;
224 };
225
226 struct side_type_struct {
227 uint32_t nr_fields;
228 uint32_t nr_attr;
229 const struct side_event_field *fields;
230 const struct side_attr *attr;
231 };
232
233 struct side_type_description {
234 uint32_t type; /* enum side_type */
235 union {
236 /* Basic types */
237 struct {
238 const struct side_attr *attr;
239 uint32_t nr_attr;
240 } side_basic;
241
242 /* Compound types */
243 struct {
244 const struct side_type_description *elem_type;
245 const struct side_attr *attr;
246 uint32_t length;
247 uint32_t nr_attr;
248 } side_array;
249 struct {
250 const struct side_type_description *elem_type;
251 const struct side_attr *attr;
252 uint32_t nr_attr;
253 } side_vla;
254 struct {
255 const struct side_type_description *elem_type;
256 side_visitor visitor;
257 const struct side_attr *attr;
258 uint32_t nr_attr;
259 } side_vla_visitor;
260 const struct side_type_struct *side_struct;
261
262 /* Enumeration types */
263 struct {
264 const struct side_enum_mappings *mappings;
265 const struct side_type_description *elem_type;
266 } side_enum;
267 struct {
268 const struct side_enum_bitmap_mappings *mappings;
269 const struct side_type_description *elem_type;
270 } side_enum_bitmap;
271 } u;
272 };
273
274 struct side_event_field {
275 const char *field_name;
276 struct side_type_description side_type;
277 };
278
279 enum side_event_flags {
280 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
281 };
282
283 struct side_callback {
284 union {
285 void (*call)(const struct side_event_description *desc,
286 const struct side_arg_vec_description *sav_desc,
287 void *priv);
288 void (*call_variadic)(const struct side_event_description *desc,
289 const struct side_arg_vec_description *sav_desc,
290 const struct side_arg_dynamic_event_struct *var_struct,
291 void *priv);
292 } u;
293 void *priv;
294 };
295
296 struct side_event_description {
297 uint32_t version;
298 uint32_t *enabled;
299 uint32_t loglevel; /* enum side_loglevel */
300 uint32_t nr_fields;
301 uint32_t nr_attr;
302 uint32_t nr_callbacks;
303 uint64_t flags;
304 const char *provider_name;
305 const char *event_name;
306 const struct side_event_field *fields;
307 const struct side_attr *attr;
308 const struct side_callback *callbacks;
309 };
310
311 struct side_arg_dynamic_vec {
312 uint32_t dynamic_type; /* enum side_dynamic_type */
313 union {
314 /* Basic types */
315 struct {
316 const struct side_attr *attr;
317 uint32_t nr_attr;
318 union {
319 uint8_t side_bool;
320 uint8_t side_u8;
321 uint16_t side_u16;
322 uint32_t side_u32;
323 uint64_t side_u64;
324 int8_t side_s8;
325 int16_t side_s16;
326 int32_t side_s32;
327 int64_t side_s64;
328 uint8_t side_byte;
329 #if __HAVE_FLOAT16
330 _Float16 side_float_binary16;
331 #endif
332 #if __HAVE_FLOAT32
333 _Float32 side_float_binary32;
334 #endif
335 #if __HAVE_FLOAT64
336 _Float64 side_float_binary64;
337 #endif
338 #if __HAVE_FLOAT128
339 _Float128 side_float_binary128;
340 #endif
341 const char *string;
342 } u;
343 } side_basic;
344
345 /* Compound types */
346 const struct side_arg_dynamic_event_struct *side_dynamic_struct;
347 struct {
348 void *app_ctx;
349 side_dynamic_struct_visitor visitor;
350 const struct side_attr *attr;
351 uint32_t nr_attr;
352 } side_dynamic_struct_visitor;
353 const struct side_arg_dynamic_vec_vla *side_dynamic_vla;
354 struct {
355 void *app_ctx;
356 side_dynamic_vla_visitor visitor;
357 const struct side_attr *attr;
358 uint32_t nr_attr;
359 } side_dynamic_vla_visitor;
360 } u;
361 };
362
363 struct side_arg_dynamic_vec_vla {
364 const struct side_arg_dynamic_vec *sav;
365 const struct side_attr *attr;
366 uint32_t len;
367 uint32_t nr_attr;
368 };
369
370 struct side_arg_dynamic_event_field {
371 const char *field_name;
372 const struct side_arg_dynamic_vec elem;
373 };
374
375 struct side_arg_dynamic_event_struct {
376 const struct side_arg_dynamic_event_field *fields;
377 const struct side_attr *attr;
378 uint32_t len;
379 uint32_t nr_attr;
380 };
381
382 struct side_arg_vec {
383 enum side_type type;
384 union {
385 /* Basic types */
386 uint8_t side_bool;
387 uint8_t side_u8;
388 uint16_t side_u16;
389 uint32_t side_u32;
390 uint64_t side_u64;
391 int8_t side_s8;
392 int16_t side_s16;
393 int32_t side_s32;
394 int64_t side_s64;
395 uint8_t side_byte;
396 #if __HAVE_FLOAT16
397 _Float16 side_float_binary16;
398 #endif
399 #if __HAVE_FLOAT32
400 _Float32 side_float_binary32;
401 #endif
402 #if __HAVE_FLOAT64
403 _Float64 side_float_binary64;
404 #endif
405 #if __HAVE_FLOAT128
406 _Float128 side_float_binary128;
407 #endif
408 const char *string;
409
410 /* Compound types */
411 const struct side_arg_vec_description *side_struct;
412 const struct side_arg_vec_description *side_array;
413 const struct side_arg_vec_description *side_vla;
414 void *side_vla_app_visitor_ctx;
415 void *side_array_fixint;
416 struct {
417 void *p;
418 uint32_t length;
419 } side_vla_fixint;
420
421 /* Dynamic type */
422 struct side_arg_dynamic_vec dynamic;
423 } u;
424 };
425
426 struct side_arg_vec_description {
427 const struct side_arg_vec *sav;
428 uint32_t len;
429 };
430
431 /* The visitor pattern is a double-dispatch visitor. */
432 struct side_tracer_visitor_ctx {
433 enum side_visitor_status (*write_elem)(
434 const struct side_tracer_visitor_ctx *tracer_ctx,
435 const struct side_arg_vec *elem);
436 void *priv; /* Private tracer context. */
437 };
438
439 struct side_tracer_dynamic_struct_visitor_ctx {
440 enum side_visitor_status (*write_field)(
441 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
442 const struct side_arg_dynamic_event_field *dynamic_field);
443 void *priv; /* Private tracer context. */
444 };
445
446 struct side_tracer_dynamic_vla_visitor_ctx {
447 enum side_visitor_status (*write_elem)(
448 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
449 const struct side_arg_dynamic_vec *elem);
450 void *priv; /* Private tracer context. */
451 };
452
453 /* Event and type attributes */
454
455 #define side_attr(_key, _value) \
456 { \
457 .key = _key, \
458 .value = SIDE_PARAM(_value), \
459 }
460
461 #define side_attr_list(...) \
462 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
463
464 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
465 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
466 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
467 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
468 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
469 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
470 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
471 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
472 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
473 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
474 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
475 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
476 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
477 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
478 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (_val) } }
479
480 /* Static field definition */
481
482 #define _side_type_basic(_type, _attr) \
483 { \
484 .type = _type, \
485 .u = { \
486 .side_basic = { \
487 .attr = _attr, \
488 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
489 }, \
490 }, \
491 }
492
493 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_PARAM(_attr))
494 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_PARAM(_attr))
495 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_PARAM(_attr))
496 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_PARAM(_attr))
497 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_PARAM(_attr))
498 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_PARAM(_attr))
499 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_PARAM(_attr))
500 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_PARAM(_attr))
501 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_PARAM(_attr))
502 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_PARAM(_attr))
503 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_PARAM(_attr))
504 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_PARAM(_attr))
505 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_PARAM(_attr))
506 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_PARAM(_attr))
507 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_PARAM(_attr))
508 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_PARAM(_attr))
509
510 #define _side_field(_name, _type) \
511 { \
512 .field_name = _name, \
513 .side_type = _type, \
514 }
515
516 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
517 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
518 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
519 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
520 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
521 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
522 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
523 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
524 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
525 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
526 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
527 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
528 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
529 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
530 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
531 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
532
533 #define side_type_enum(_mappings, _elem_type) \
534 { \
535 .type = SIDE_TYPE_ENUM, \
536 .u = { \
537 .side_enum = { \
538 .mappings = _mappings, \
539 .elem_type = _elem_type, \
540 }, \
541 }, \
542 }
543 #define side_field_enum(_name, _mappings, _elem_type) \
544 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
545
546 #define side_type_enum_bitmap(_mappings, _elem_type) \
547 { \
548 .type = SIDE_TYPE_ENUM_BITMAP, \
549 .u = { \
550 .side_enum_bitmap = { \
551 .mappings = _mappings, \
552 .elem_type = _elem_type, \
553 }, \
554 }, \
555 }
556 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
557 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
558
559 #define side_type_struct(_struct) \
560 { \
561 .type = SIDE_TYPE_STRUCT, \
562 .u = { \
563 .side_struct = _struct, \
564 }, \
565 }
566 #define side_field_struct(_name, _struct) \
567 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
568
569 #define _side_type_struct_define(_fields, _attr) \
570 { \
571 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
572 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
573 .fields = _fields, \
574 .attr = _attr, \
575 }
576
577 #define side_define_struct(_identifier, _fields, _attr) \
578 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
579
580 #define side_struct_literal(_fields, _attr) \
581 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
582 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
583
584 #define side_type_array(_elem_type, _length, _attr) \
585 { \
586 .type = SIDE_TYPE_ARRAY, \
587 .u = { \
588 .side_array = { \
589 .elem_type = _elem_type, \
590 .attr = _attr, \
591 .length = _length, \
592 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
593 }, \
594 }, \
595 }
596 #define side_field_array(_name, _elem_type, _length, _attr) \
597 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
598
599 #define side_type_vla(_elem_type, _attr) \
600 { \
601 .type = SIDE_TYPE_VLA, \
602 .u = { \
603 .side_vla = { \
604 .elem_type = _elem_type, \
605 .attr = _attr, \
606 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
607 }, \
608 }, \
609 }
610 #define side_field_vla(_name, _elem_type, _attr) \
611 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
612
613 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
614 { \
615 .type = SIDE_TYPE_VLA_VISITOR, \
616 .u = { \
617 .side_vla_visitor = { \
618 .elem_type = SIDE_PARAM(_elem_type), \
619 .visitor = _visitor, \
620 .attr = _attr, \
621 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
622 }, \
623 }, \
624 }
625 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
626 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
627
628 #define side_elem(...) \
629 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
630
631 #define side_field_list(...) \
632 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
633
634 /* Static field arguments */
635
636 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
637 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
638 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
639 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
640 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
641 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
642 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
643 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
644 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
645 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
646 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
647 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
648 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
649 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
650 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
651 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
652 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
653 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
654 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
655 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
656
657 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (_val) } }
658 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
659 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
660 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
661 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
662
663 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
664 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
665 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
666 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
667 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
668 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
669 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
670 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
671 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
672
673 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
674 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
675 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
676 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
677 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
678 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
679 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
680 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
681 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
682
683 #define side_arg_dynamic(_dynamic_arg_type) \
684 { \
685 .type = SIDE_TYPE_DYNAMIC, \
686 .u = { \
687 .dynamic = _dynamic_arg_type, \
688 }, \
689 }
690
691 /* Dynamic field arguments */
692
693 #define side_arg_dynamic_null(_attr) \
694 { \
695 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
696 .u = { \
697 .side_basic = { \
698 .attr = _attr, \
699 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
700 }, \
701 }, \
702 }
703
704 #define side_arg_dynamic_bool(_val, _attr) \
705 { \
706 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
707 .u = { \
708 .side_basic = { \
709 .attr = _attr, \
710 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
711 .u = { \
712 .side_bool = !!(_val), \
713 }, \
714 }, \
715 }, \
716 }
717
718 #define side_arg_dynamic_u8(_val, _attr) \
719 { \
720 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
721 .u = { \
722 .side_basic = { \
723 .attr = _attr, \
724 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
725 .u = { \
726 .side_u8 = (_val), \
727 }, \
728 }, \
729 }, \
730 }
731 #define side_arg_dynamic_u16(_val, _attr) \
732 { \
733 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
734 .u = { \
735 .side_basic = { \
736 .attr = _attr, \
737 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
738 .u = { \
739 .side_u16 = (_val), \
740 }, \
741 }, \
742 }, \
743 }
744 #define side_arg_dynamic_u32(_val, _attr) \
745 { \
746 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
747 .u = { \
748 .side_basic = { \
749 .attr = _attr, \
750 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
751 .u = { \
752 .side_u32 = (_val), \
753 }, \
754 }, \
755 }, \
756 }
757 #define side_arg_dynamic_u64(_val, _attr) \
758 { \
759 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
760 .u = { \
761 .side_basic = { \
762 .attr = _attr, \
763 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
764 .u = { \
765 .side_u64 = (_val), \
766 }, \
767 }, \
768 }, \
769 }
770
771 #define side_arg_dynamic_s8(_val, _attr) \
772 { \
773 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
774 .u = { \
775 .side_basic = { \
776 .attr = _attr, \
777 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
778 .u = { \
779 .side_s8 = (_val), \
780 }, \
781 }, \
782 }, \
783 }
784 #define side_arg_dynamic_s16(_val, _attr) \
785 { \
786 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
787 .u = { \
788 .side_basic = { \
789 .attr = _attr, \
790 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
791 .u = { \
792 .side_s16 = (_val), \
793 }, \
794 }, \
795 }, \
796 }
797 #define side_arg_dynamic_s32(_val, _attr) \
798 { \
799 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
800 .u = { \
801 .side_basic = { \
802 .attr = _attr, \
803 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
804 .u = { \
805 .side_s32 = (_val), \
806 }, \
807 }, \
808 }, \
809 }
810 #define side_arg_dynamic_s64(_val, _attr) \
811 { \
812 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
813 .u = { \
814 .side_basic = { \
815 .attr = _attr, \
816 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
817 .u = { \
818 .side_s64 = (_val), \
819 }, \
820 }, \
821 }, \
822 }
823 #define side_arg_dynamic_byte(_val, _attr) \
824 { \
825 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
826 .u = { \
827 .side_basic = { \
828 .attr = _attr, \
829 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
830 .u = { \
831 .side_byte = (_val), \
832 }, \
833 }, \
834 }, \
835 }
836
837 #define side_arg_dynamic_float_binary16(_val, _attr) \
838 { \
839 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
840 .u = { \
841 .side_basic = { \
842 .attr = _attr, \
843 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
844 .u = { \
845 .side_float_binary16 = (_val), \
846 }, \
847 }, \
848 }, \
849 }
850 #define side_arg_dynamic_float_binary32(_val, _attr) \
851 { \
852 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
853 .u = { \
854 .side_basic = { \
855 .attr = _attr, \
856 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
857 .u = { \
858 .side_float_binary32 = (_val), \
859 }, \
860 }, \
861 }, \
862 }
863 #define side_arg_dynamic_float_binary64(_val, _attr) \
864 { \
865 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
866 .u = { \
867 .side_basic = { \
868 .attr = _attr, \
869 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
870 .u = { \
871 .side_float_binary64 = (_val), \
872 }, \
873 }, \
874 }, \
875 }
876 #define side_arg_dynamic_float_binary128(_val, _attr) \
877 { \
878 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
879 .u = { \
880 .side_basic = { \
881 .attr = _attr, \
882 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
883 .u = { \
884 .side_float_binary128 = (_val), \
885 }, \
886 }, \
887 }, \
888 }
889
890 #define side_arg_dynamic_string(_val, _attr) \
891 { \
892 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
893 .u = { \
894 .side_basic = { \
895 .attr = _attr, \
896 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
897 .u = { \
898 .string = (_val), \
899 }, \
900 }, \
901 }, \
902 }
903
904 #define side_arg_dynamic_vla(_vla) \
905 { \
906 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
907 .u = { \
908 .side_dynamic_vla = (_vla), \
909 }, \
910 }
911
912 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
913 { \
914 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
915 .u = { \
916 .side_dynamic_vla_visitor = { \
917 .app_ctx = _ctx, \
918 .visitor = _dynamic_vla_visitor, \
919 .attr = _attr, \
920 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
921 }, \
922 }, \
923 }
924
925 #define side_arg_dynamic_struct(_struct) \
926 { \
927 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
928 .u = { \
929 .side_dynamic_struct = (_struct), \
930 }, \
931 }
932
933 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
934 { \
935 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
936 .u = { \
937 .side_dynamic_struct_visitor = { \
938 .app_ctx = _ctx, \
939 .visitor = _dynamic_struct_visitor, \
940 .attr = _attr, \
941 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
942 }, \
943 }, \
944 }
945
946 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
947 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
948 const struct side_arg_dynamic_vec_vla _identifier = { \
949 .sav = _identifier##_vec, \
950 .attr = _attr, \
951 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
952 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
953 }
954
955 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
956 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
957 const struct side_arg_dynamic_event_struct _identifier = { \
958 .fields = _identifier##_fields, \
959 .attr = _attr, \
960 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
961 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
962 }
963
964 #define side_arg_define_vec(_identifier, _sav) \
965 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
966 const struct side_arg_vec_description _identifier = { \
967 .sav = _identifier##_vec, \
968 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
969 }
970
971 #define side_arg_dynamic_field(_name, _elem) \
972 { \
973 .field_name = _name, \
974 .elem = _elem, \
975 }
976
977 #define side_arg_list(...) __VA_ARGS__
978
979 #define side_define_enum(_identifier, _mappings, _attr) \
980 const struct side_enum_mappings _identifier = { \
981 .mappings = _mappings, \
982 .attr = _attr, \
983 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
984 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
985 }
986
987 #define side_enum_mapping_list(...) \
988 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
989
990 #define side_enum_mapping_range(_label, _begin, _end) \
991 { \
992 .range_begin = _begin, \
993 .range_end = _end, \
994 .label = _label, \
995 }
996
997 #define side_enum_mapping_value(_label, _value) \
998 { \
999 .range_begin = _value, \
1000 .range_end = _value, \
1001 .label = _label, \
1002 }
1003
1004 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1005 const struct side_enum_bitmap_mappings _identifier = { \
1006 .mappings = _mappings, \
1007 .attr = _attr, \
1008 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1009 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1010 }
1011
1012 #define side_enum_bitmap_mapping_list(...) \
1013 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1014
1015 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1016 { \
1017 .range_begin = _begin, \
1018 .range_end = _end, \
1019 .label = _label, \
1020 }
1021
1022 #define side_enum_bitmap_mapping_value(_label, _value) \
1023 { \
1024 .range_begin = _value, \
1025 .range_end = _value, \
1026 .label = _label, \
1027 }
1028
1029 #define side_event_cond(_identifier) \
1030 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1031 __ATOMIC_RELAXED)))
1032
1033 #define side_event_call(_identifier, _sav) \
1034 { \
1035 const struct side_arg_vec side_sav[] = { _sav }; \
1036 const struct side_arg_vec_description sav_desc = { \
1037 .sav = side_sav, \
1038 .len = SIDE_ARRAY_SIZE(side_sav), \
1039 }; \
1040 side_call(&(_identifier), &sav_desc); \
1041 }
1042
1043 #define side_event(_identifier, _sav) \
1044 side_event_cond(_identifier) \
1045 side_event_call(_identifier, SIDE_PARAM(_sav))
1046
1047 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1048 { \
1049 const struct side_arg_vec side_sav[] = { _sav }; \
1050 const struct side_arg_vec_description sav_desc = { \
1051 .sav = side_sav, \
1052 .len = SIDE_ARRAY_SIZE(side_sav), \
1053 }; \
1054 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1055 const struct side_arg_dynamic_event_struct var_struct = { \
1056 .fields = side_fields, \
1057 .attr = _attr, \
1058 .len = SIDE_ARRAY_SIZE(side_fields), \
1059 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1060 }; \
1061 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1062 }
1063
1064 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1065 side_event_cond(_identifier) \
1066 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1067
1068 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1069 _linkage uint32_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1070 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1071 _identifier = { \
1072 .version = 0, \
1073 .enabled = &(side_event_enable__##_identifier), \
1074 .loglevel = _loglevel, \
1075 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1076 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1077 .nr_callbacks = 0, \
1078 .flags = (_flags), \
1079 .provider_name = _provider, \
1080 .event_name = _event, \
1081 .fields = _fields, \
1082 .attr = _attr, \
1083 .callbacks = &side_empty_callback, \
1084 }; \
1085 static const struct side_event_description *side_event_ptr__##_identifier \
1086 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1087
1088 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1089 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1090 SIDE_PARAM(_attr), 0)
1091
1092 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1093 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1094 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1095
1096 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1097 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1098 SIDE_PARAM(_attr), 0)
1099
1100 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1101 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1102 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1103
1104 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1105 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1106 SIDE_PARAM(_attr), 0)
1107
1108 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1109 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1110 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1111
1112 #define side_declare_event(_identifier) \
1113 extern uint32_t side_event_enable_##_identifier; \
1114 extern struct side_event_description _identifier
1115
1116 extern const struct side_callback side_empty_callback;
1117
1118 void side_call(const struct side_event_description *desc,
1119 const struct side_arg_vec_description *sav_desc);
1120 void side_call_variadic(const struct side_event_description *desc,
1121 const struct side_arg_vec_description *sav_desc,
1122 const struct side_arg_dynamic_event_struct *var_struct);
1123
1124 int side_tracer_callback_register(struct side_event_description *desc,
1125 void (*call)(const struct side_event_description *desc,
1126 const struct side_arg_vec_description *sav_desc,
1127 void *priv),
1128 void *priv);
1129 int side_tracer_callback_variadic_register(struct side_event_description *desc,
1130 void (*call_variadic)(const struct side_event_description *desc,
1131 const struct side_arg_vec_description *sav_desc,
1132 const struct side_arg_dynamic_event_struct *var_struct,
1133 void *priv),
1134 void *priv);
1135 int side_tracer_callback_unregister(struct side_event_description *desc,
1136 void (*call)(const struct side_event_description *desc,
1137 const struct side_arg_vec_description *sav_desc,
1138 void *priv),
1139 void *priv);
1140 int side_tracer_callback_variadic_unregister(struct side_event_description *desc,
1141 void (*call_variadic)(const struct side_event_description *desc,
1142 const struct side_arg_vec_description *sav_desc,
1143 const struct side_arg_dynamic_event_struct *var_struct,
1144 void *priv),
1145 void *priv);
1146
1147 struct side_events_register_handle *side_events_register(struct side_event_description **events, uint32_t nr_events);
1148 void side_events_unregister(struct side_events_register_handle *handle);
1149
1150 enum side_tracer_notification {
1151 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS,
1152 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS,
1153 };
1154
1155 /* Callback is invoked with side library internal lock held. */
1156 struct side_tracer_handle *side_tracer_event_notification_register(
1157 void (*cb)(enum side_tracer_notification notif,
1158 struct side_event_description **events, uint32_t nr_events, void *priv),
1159 void *priv);
1160 void side_tracer_event_notification_unregister(struct side_tracer_handle *handle);
1161
1162 void side_init(void);
1163 void side_exit(void);
1164
1165 /*
1166 * These weak symbols, the constructor, and destructor take care of
1167 * registering only _one_ instance of the side instrumentation per
1168 * shared-ojbect (or for the whole main program).
1169 */
1170 extern struct side_event_description * __start_side_event_description_ptr[]
1171 __attribute__((weak, visibility("hidden")));
1172 extern struct side_event_description * __stop_side_event_description_ptr[]
1173 __attribute__((weak, visibility("hidden")));
1174 int side_event_description_ptr_registered
1175 __attribute__((weak, visibility("hidden")));
1176 struct side_events_register_handle *side_events_handle
1177 __attribute__((weak, visibility("hidden")));
1178
1179 static void
1180 side_event_description_ptr_init(void)
1181 __attribute__((no_instrument_function))
1182 __attribute__((constructor));
1183 static void
1184 side_event_description_ptr_init(void)
1185 {
1186 if (side_event_description_ptr_registered++)
1187 return;
1188 side_events_handle = side_events_register(__start_side_event_description_ptr,
1189 __stop_side_event_description_ptr - __start_side_event_description_ptr);
1190 }
1191
1192 static void
1193 side_event_description_ptr_exit(void)
1194 __attribute__((no_instrument_function))
1195 __attribute__((destructor));
1196 static void
1197 side_event_description_ptr_exit(void)
1198 {
1199 if (--side_event_description_ptr_registered)
1200 return;
1201 side_events_unregister(side_events_handle);
1202 side_events_handle = NULL;
1203 }
1204
1205 #endif /* _SIDE_TRACE_H */
This page took 0.052515 seconds and 5 git commands to generate.