Commit | Line | Data |
---|---|---|
f611d0c3 MD |
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> | |
fb25b355 | 13 | #include <math.h> |
f611d0c3 MD |
14 | #include <side/macros.h> |
15 | ||
16 | /* SIDE stands for "Static Instrumentation Dynamically Enabled" */ | |
17 | ||
64f5abc7 MD |
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 | ||
f611d0c3 | 22 | struct side_arg_vec; |
a2e2357e MD |
23 | struct side_arg_vec_description; |
24 | struct side_arg_dynamic_vec; | |
25 | struct side_arg_dynamic_vec_vla; | |
f611d0c3 MD |
26 | struct side_type_description; |
27 | struct side_event_field; | |
352a4b77 | 28 | struct side_tracer_visitor_ctx; |
c208889e | 29 | struct side_tracer_dynamic_struct_visitor_ctx; |
bdc39c09 | 30 | struct side_tracer_dynamic_vla_visitor_ctx; |
f611d0c3 MD |
31 | |
32 | enum side_type { | |
4f40d951 MD |
33 | SIDE_TYPE_BOOL, |
34 | ||
f611d0c3 MD |
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, | |
ba845af5 | 43 | |
fb25b355 MD |
44 | SIDE_TYPE_FLOAT_BINARY16, |
45 | SIDE_TYPE_FLOAT_BINARY32, | |
46 | SIDE_TYPE_FLOAT_BINARY64, | |
47 | SIDE_TYPE_FLOAT_BINARY128, | |
48 | ||
f611d0c3 | 49 | SIDE_TYPE_STRING, |
bdc39c09 | 50 | |
f611d0c3 MD |
51 | SIDE_TYPE_STRUCT, |
52 | SIDE_TYPE_ARRAY, | |
53 | SIDE_TYPE_VLA, | |
54 | SIDE_TYPE_VLA_VISITOR, | |
ba845af5 MD |
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 | ||
1533629f MD |
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 | ||
bdc39c09 MD |
74 | SIDE_TYPE_DYNAMIC, |
75 | }; | |
76 | ||
77 | enum side_dynamic_type { | |
78 | SIDE_DYNAMIC_TYPE_NULL, | |
79 | ||
4f40d951 MD |
80 | SIDE_DYNAMIC_TYPE_BOOL, |
81 | ||
bdc39c09 MD |
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 | ||
fb25b355 MD |
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 | ||
bdc39c09 MD |
96 | SIDE_DYNAMIC_TYPE_STRING, |
97 | ||
c208889e MD |
98 | SIDE_DYNAMIC_TYPE_STRUCT, |
99 | SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, | |
a2e2357e MD |
100 | |
101 | SIDE_DYNAMIC_TYPE_VLA, | |
bdc39c09 | 102 | SIDE_DYNAMIC_TYPE_VLA_VISITOR, |
f611d0c3 MD |
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 { | |
f611d0c3 | 117 | SIDE_VISITOR_STATUS_OK = 0, |
db6ecef9 | 118 | SIDE_VISITOR_STATUS_ERROR = -1, |
f611d0c3 MD |
119 | }; |
120 | ||
f93e01ac MD |
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); | |
f611d0c3 | 130 | |
65010f43 MD |
131 | /* User attributes. */ |
132 | struct side_attr { | |
133 | const char *key; | |
134 | const char *value; | |
135 | }; | |
136 | ||
f611d0c3 | 137 | struct side_type_description { |
2f5827d5 | 138 | uint32_t type; /* enum side_type */ |
f37a556f MD |
139 | uint32_t nr_attr; |
140 | const struct side_attr *attr; | |
f611d0c3 MD |
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; | |
352a4b77 | 155 | side_visitor visitor; |
f611d0c3 MD |
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 | ||
8a25ce77 MD |
165 | enum side_event_flags { |
166 | SIDE_EVENT_FLAG_VARIADIC = (1 << 0), | |
167 | }; | |
168 | ||
f611d0c3 MD |
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; | |
65010f43 MD |
174 | uint32_t nr_attr; |
175 | uint32_t _unused; | |
8a25ce77 | 176 | uint64_t flags; |
f611d0c3 MD |
177 | const char *provider_name; |
178 | const char *event_name; | |
179 | const struct side_event_field *fields; | |
65010f43 | 180 | const struct side_attr *attr; |
f611d0c3 MD |
181 | }; |
182 | ||
a2e2357e MD |
183 | struct side_arg_dynamic_vec_vla { |
184 | const struct side_arg_dynamic_vec *sav; | |
185 | uint32_t len; | |
186 | }; | |
187 | ||
bdc39c09 | 188 | struct side_arg_dynamic_vec { |
2f5827d5 | 189 | uint32_t dynamic_type; /* enum side_dynamic_type */ |
808bd9bf MD |
190 | uint32_t nr_attr; |
191 | const struct side_attr *attr; | |
bdc39c09 | 192 | union { |
4f40d951 MD |
193 | uint8_t side_bool; |
194 | ||
bdc39c09 MD |
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 | ||
fb25b355 MD |
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 | ||
bdc39c09 MD |
217 | const char *string; |
218 | ||
c208889e | 219 | const struct side_arg_dynamic_event_struct *side_dynamic_struct; |
bdc39c09 | 220 | struct { |
8ceca0cd | 221 | void *app_ctx; |
c208889e MD |
222 | side_dynamic_struct_visitor visitor; |
223 | } side_dynamic_struct_visitor; | |
a2e2357e MD |
224 | |
225 | const struct side_arg_dynamic_vec_vla *side_dynamic_vla; | |
bdc39c09 | 226 | struct { |
8ceca0cd | 227 | void *app_ctx; |
bdc39c09 MD |
228 | side_dynamic_vla_visitor visitor; |
229 | } side_dynamic_vla_visitor; | |
230 | } u; | |
231 | }; | |
232 | ||
465e5e7e MD |
233 | struct side_arg_dynamic_event_field { |
234 | const char *field_name; | |
235 | const struct side_arg_dynamic_vec elem; | |
465e5e7e MD |
236 | }; |
237 | ||
c208889e | 238 | struct side_arg_dynamic_event_struct { |
465e5e7e MD |
239 | const struct side_arg_dynamic_event_field *fields; |
240 | uint32_t len; | |
241 | }; | |
242 | ||
f611d0c3 | 243 | struct side_arg_vec { |
1e8256c9 | 244 | enum side_type type; |
f611d0c3 | 245 | union { |
4f40d951 MD |
246 | uint8_t side_bool; |
247 | ||
f611d0c3 MD |
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; | |
ba845af5 | 256 | |
fb25b355 MD |
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 | ||
f611d0c3 MD |
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; | |
352a4b77 | 274 | void *side_vla_app_visitor_ctx; |
ba845af5 MD |
275 | |
276 | void *side_array_fixint; | |
1533629f MD |
277 | struct { |
278 | void *p; | |
279 | uint32_t length; | |
280 | } side_vla_fixint; | |
bdc39c09 MD |
281 | |
282 | struct side_arg_dynamic_vec dynamic; | |
f611d0c3 MD |
283 | } u; |
284 | }; | |
285 | ||
286 | struct side_arg_vec_description { | |
287 | const struct side_arg_vec *sav; | |
288 | uint32_t len; | |
289 | }; | |
290 | ||
352a4b77 MD |
291 | /* The visitor pattern is a double-dispatch visitor. */ |
292 | struct side_tracer_visitor_ctx { | |
f93e01ac MD |
293 | enum side_visitor_status (*write_elem)( |
294 | const struct side_tracer_visitor_ctx *tracer_ctx, | |
295 | const struct side_arg_vec *elem); | |
352a4b77 MD |
296 | void *priv; /* Private tracer context. */ |
297 | }; | |
298 | ||
c208889e | 299 | struct side_tracer_dynamic_struct_visitor_ctx { |
f93e01ac MD |
300 | enum side_visitor_status (*write_field)( |
301 | const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, | |
2b359235 | 302 | const struct side_arg_dynamic_event_field *dynamic_field); |
bdc39c09 MD |
303 | void *priv; /* Private tracer context. */ |
304 | }; | |
305 | ||
306 | struct side_tracer_dynamic_vla_visitor_ctx { | |
f93e01ac MD |
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); | |
bdc39c09 MD |
310 | void *priv; /* Private tracer context. */ |
311 | }; | |
312 | ||
65010f43 MD |
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 | ||
f37a556f MD |
322 | #define side_type_decl(_type, _attr) \ |
323 | { \ | |
324 | .type = _type, \ | |
325 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ | |
326 | .attr = _attr, \ | |
327 | } | |
f93e01ac | 328 | |
f37a556f | 329 | #define side_field(_name, _type, _attr) \ |
f93e01ac MD |
330 | { \ |
331 | .field_name = _name, \ | |
f37a556f | 332 | .side_type = side_type_decl(_type, SIDE_PARAM(_attr)), \ |
f93e01ac | 333 | } |
f611d0c3 | 334 | |
f37a556f | 335 | #define side_type_struct_decl(_fields, _attr) \ |
f611d0c3 MD |
336 | { \ |
337 | .type = SIDE_TYPE_STRUCT, \ | |
f37a556f MD |
338 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
339 | .attr = _attr, \ | |
f611d0c3 MD |
340 | .u = { \ |
341 | .side_struct = { \ | |
342 | .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ | |
343 | .fields = _fields, \ | |
344 | }, \ | |
345 | }, \ | |
346 | } | |
f37a556f | 347 | #define side_field_struct(_name, _fields, _attr) \ |
f611d0c3 MD |
348 | { \ |
349 | .field_name = _name, \ | |
f37a556f | 350 | .side_type = side_type_struct_decl(SIDE_PARAM(_fields), SIDE_PARAM(_attr)), \ |
f611d0c3 MD |
351 | } |
352 | ||
f37a556f | 353 | #define side_type_array_decl(_elem_type, _length, _attr) \ |
f611d0c3 MD |
354 | { \ |
355 | .type = SIDE_TYPE_ARRAY, \ | |
f37a556f MD |
356 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
357 | .attr = _attr, \ | |
f611d0c3 MD |
358 | .u = { \ |
359 | .side_array = { \ | |
360 | .length = _length, \ | |
361 | .elem_type = _elem_type, \ | |
362 | }, \ | |
363 | }, \ | |
364 | } | |
f37a556f | 365 | #define side_field_array(_name, _elem_type, _length, _attr) \ |
f611d0c3 MD |
366 | { \ |
367 | .field_name = _name, \ | |
f37a556f | 368 | .side_type = side_type_array_decl(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)), \ |
f611d0c3 MD |
369 | } |
370 | ||
f37a556f | 371 | #define side_type_vla_decl(_elem_type, _attr) \ |
f611d0c3 MD |
372 | { \ |
373 | .type = SIDE_TYPE_VLA, \ | |
f37a556f MD |
374 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
375 | .attr = _attr, \ | |
f611d0c3 MD |
376 | .u = { \ |
377 | .side_vla = { \ | |
378 | .elem_type = _elem_type, \ | |
379 | }, \ | |
380 | }, \ | |
381 | } | |
f37a556f | 382 | #define side_field_vla(_name, _elem_type, _attr) \ |
f611d0c3 MD |
383 | { \ |
384 | .field_name = _name, \ | |
f37a556f | 385 | .side_type = side_type_vla_decl(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)), \ |
f611d0c3 MD |
386 | } |
387 | ||
f37a556f | 388 | #define side_type_vla_visitor_decl(_elem_type, _visitor, _attr) \ |
f611d0c3 MD |
389 | { \ |
390 | .type = SIDE_TYPE_VLA_VISITOR, \ | |
f37a556f MD |
391 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
392 | .attr = _attr, \ | |
f611d0c3 MD |
393 | .u = { \ |
394 | .side_vla_visitor = { \ | |
cdd6e858 | 395 | .elem_type = SIDE_PARAM(_elem_type), \ |
352a4b77 | 396 | .visitor = _visitor, \ |
f611d0c3 MD |
397 | }, \ |
398 | }, \ | |
399 | } | |
f37a556f | 400 | #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \ |
f611d0c3 MD |
401 | { \ |
402 | .field_name = _name, \ | |
f37a556f | 403 | .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)), \ |
f611d0c3 MD |
404 | } |
405 | ||
71002b5e | 406 | #define side_elem(...) \ |
cdd6e858 MD |
407 | SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__) |
408 | ||
f37a556f MD |
409 | #define side_elem_type(_type, _attr) \ |
410 | side_elem(side_type_decl(_type, SIDE_PARAM(_attr))) | |
f611d0c3 MD |
411 | |
412 | #define side_field_list(...) \ | |
413 | SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__) | |
414 | ||
4f40d951 | 415 | #define side_arg_bool(val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(val) } } |
f93e01ac MD |
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) } } | |
fb25b355 MD |
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 | ||
f93e01ac | 429 | #define side_arg_string(val) { .type = SIDE_TYPE_STRING, .u = { .string = (val) } } |
f611d0c3 MD |
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) } } | |
352a4b77 | 433 | #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } } |
f611d0c3 | 434 | |
1533629f MD |
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) } } } | |
ba845af5 | 452 | |
bdc39c09 MD |
453 | #define side_arg_dynamic(dynamic_arg_type) \ |
454 | { \ | |
455 | .type = SIDE_TYPE_DYNAMIC, \ | |
456 | .u = { \ | |
457 | .dynamic = dynamic_arg_type, \ | |
458 | }, \ | |
459 | } | |
460 | ||
808bd9bf MD |
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 | ||
fb25b355 MD |
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 | ||
808bd9bf MD |
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) \ | |
bdc39c09 | 610 | { \ |
1e8256c9 | 611 | .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \ |
808bd9bf MD |
612 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
613 | .attr = _attr, \ | |
bdc39c09 | 614 | .u = { \ |
8ceca0cd MD |
615 | .side_dynamic_vla_visitor = { \ |
616 | .app_ctx = _ctx, \ | |
617 | .visitor = _dynamic_vla_visitor, \ | |
618 | }, \ | |
bdc39c09 MD |
619 | }, \ |
620 | } | |
621 | ||
808bd9bf MD |
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) \ | |
bdc39c09 | 633 | { \ |
1e8256c9 | 634 | .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \ |
808bd9bf MD |
635 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
636 | .attr = _attr, \ | |
bdc39c09 | 637 | .u = { \ |
8ceca0cd MD |
638 | .side_dynamic_struct_visitor = { \ |
639 | .app_ctx = _ctx, \ | |
640 | .visitor = _dynamic_struct_visitor, \ | |
641 | }, \ | |
bdc39c09 MD |
642 | }, \ |
643 | } | |
644 | ||
a2e2357e MD |
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 | ||
c208889e MD |
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 = { \ | |
465e5e7e MD |
655 | .fields = _identifier##_fields, \ |
656 | .len = SIDE_ARRAY_SIZE(_identifier##_fields), \ | |
657 | } | |
658 | ||
f611d0c3 MD |
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 | } | |
a2e2357e | 665 | |
465e5e7e MD |
666 | #define side_arg_dynamic_field(_name, _elem) \ |
667 | { \ | |
668 | .field_name = _name, \ | |
669 | .elem = _elem, \ | |
670 | } | |
671 | ||
f611d0c3 MD |
672 | #define side_arg_list(...) __VA_ARGS__ |
673 | ||
674 | #define side_event_cond(desc) if (side_unlikely((desc)->enabled)) | |
19fa6aa2 | 675 | |
f611d0c3 MD |
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) \ | |
6c40fa8b | 688 | side_event_call(desc, SIDE_PARAM(sav)) |
f611d0c3 | 689 | |
19fa6aa2 MD |
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 | ||
399c836b | 709 | #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \ |
f611d0c3 MD |
710 | struct side_event_description _identifier = { \ |
711 | .version = 0, \ | |
712 | .enabled = 0, \ | |
713 | .loglevel = _loglevel, \ | |
714 | .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ | |
65010f43 | 715 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
8a25ce77 | 716 | .flags = (_flags), \ |
f611d0c3 MD |
717 | .provider_name = _provider, \ |
718 | .event_name = _event, \ | |
719 | .fields = _fields, \ | |
65010f43 | 720 | .attr = _attr, \ |
f611d0c3 MD |
721 | } |
722 | ||
399c836b MD |
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) | |
8a25ce77 | 726 | |
399c836b MD |
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) | |
8a25ce77 | 730 | |
f611d0c3 MD |
731 | #define side_declare_event(_identifier) \ |
732 | struct side_event_description _identifier | |
733 | ||
734 | #endif /* _SIDE_TRACE_H */ |