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> | |
13 | #include <side/macros.h> | |
14 | ||
15 | /* SIDE stands for "Static Instrumentation Dynamically Enabled" */ | |
16 | ||
17 | struct side_arg_vec; | |
a2e2357e MD |
18 | struct side_arg_vec_description; |
19 | struct side_arg_dynamic_vec; | |
20 | struct side_arg_dynamic_vec_vla; | |
f611d0c3 MD |
21 | struct side_type_description; |
22 | struct side_event_field; | |
352a4b77 | 23 | struct side_tracer_visitor_ctx; |
c208889e | 24 | struct side_tracer_dynamic_struct_visitor_ctx; |
bdc39c09 | 25 | struct side_tracer_dynamic_vla_visitor_ctx; |
f611d0c3 MD |
26 | |
27 | enum side_type { | |
4f40d951 MD |
28 | SIDE_TYPE_BOOL, |
29 | ||
f611d0c3 MD |
30 | SIDE_TYPE_U8, |
31 | SIDE_TYPE_U16, | |
32 | SIDE_TYPE_U32, | |
33 | SIDE_TYPE_U64, | |
34 | SIDE_TYPE_S8, | |
35 | SIDE_TYPE_S16, | |
36 | SIDE_TYPE_S32, | |
37 | SIDE_TYPE_S64, | |
ba845af5 | 38 | |
f611d0c3 | 39 | SIDE_TYPE_STRING, |
bdc39c09 | 40 | |
f611d0c3 MD |
41 | SIDE_TYPE_STRUCT, |
42 | SIDE_TYPE_ARRAY, | |
43 | SIDE_TYPE_VLA, | |
44 | SIDE_TYPE_VLA_VISITOR, | |
ba845af5 MD |
45 | |
46 | SIDE_TYPE_ARRAY_U8, | |
47 | SIDE_TYPE_ARRAY_U16, | |
48 | SIDE_TYPE_ARRAY_U32, | |
49 | SIDE_TYPE_ARRAY_U64, | |
50 | SIDE_TYPE_ARRAY_S8, | |
51 | SIDE_TYPE_ARRAY_S16, | |
52 | SIDE_TYPE_ARRAY_S32, | |
53 | SIDE_TYPE_ARRAY_S64, | |
54 | ||
1533629f MD |
55 | SIDE_TYPE_VLA_U8, |
56 | SIDE_TYPE_VLA_U16, | |
57 | SIDE_TYPE_VLA_U32, | |
58 | SIDE_TYPE_VLA_U64, | |
59 | SIDE_TYPE_VLA_S8, | |
60 | SIDE_TYPE_VLA_S16, | |
61 | SIDE_TYPE_VLA_S32, | |
62 | SIDE_TYPE_VLA_S64, | |
63 | ||
bdc39c09 MD |
64 | SIDE_TYPE_DYNAMIC, |
65 | }; | |
66 | ||
67 | enum side_dynamic_type { | |
68 | SIDE_DYNAMIC_TYPE_NULL, | |
69 | ||
4f40d951 MD |
70 | SIDE_DYNAMIC_TYPE_BOOL, |
71 | ||
bdc39c09 MD |
72 | SIDE_DYNAMIC_TYPE_U8, |
73 | SIDE_DYNAMIC_TYPE_U16, | |
74 | SIDE_DYNAMIC_TYPE_U32, | |
75 | SIDE_DYNAMIC_TYPE_U64, | |
76 | SIDE_DYNAMIC_TYPE_S8, | |
77 | SIDE_DYNAMIC_TYPE_S16, | |
78 | SIDE_DYNAMIC_TYPE_S32, | |
79 | SIDE_DYNAMIC_TYPE_S64, | |
80 | ||
81 | SIDE_DYNAMIC_TYPE_STRING, | |
82 | ||
c208889e MD |
83 | SIDE_DYNAMIC_TYPE_STRUCT, |
84 | SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, | |
a2e2357e MD |
85 | |
86 | SIDE_DYNAMIC_TYPE_VLA, | |
bdc39c09 | 87 | SIDE_DYNAMIC_TYPE_VLA_VISITOR, |
f611d0c3 MD |
88 | }; |
89 | ||
90 | enum side_loglevel { | |
91 | SIDE_LOGLEVEL_EMERG = 0, | |
92 | SIDE_LOGLEVEL_ALERT = 1, | |
93 | SIDE_LOGLEVEL_CRIT = 2, | |
94 | SIDE_LOGLEVEL_ERR = 3, | |
95 | SIDE_LOGLEVEL_WARNING = 4, | |
96 | SIDE_LOGLEVEL_NOTICE = 5, | |
97 | SIDE_LOGLEVEL_INFO = 6, | |
98 | SIDE_LOGLEVEL_DEBUG = 7, | |
99 | }; | |
100 | ||
101 | enum side_visitor_status { | |
f611d0c3 | 102 | SIDE_VISITOR_STATUS_OK = 0, |
db6ecef9 | 103 | SIDE_VISITOR_STATUS_ERROR = -1, |
f611d0c3 MD |
104 | }; |
105 | ||
f93e01ac MD |
106 | typedef enum side_visitor_status (*side_visitor)( |
107 | const struct side_tracer_visitor_ctx *tracer_ctx, | |
108 | void *app_ctx); | |
109 | typedef enum side_visitor_status (*side_dynamic_struct_visitor)( | |
110 | const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, | |
111 | void *app_ctx); | |
112 | typedef enum side_visitor_status (*side_dynamic_vla_visitor)( | |
113 | const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx, | |
114 | void *app_ctx); | |
f611d0c3 | 115 | |
65010f43 MD |
116 | /* User attributes. */ |
117 | struct side_attr { | |
118 | const char *key; | |
119 | const char *value; | |
120 | }; | |
121 | ||
f611d0c3 | 122 | struct side_type_description { |
2f5827d5 | 123 | uint32_t type; /* enum side_type */ |
f37a556f MD |
124 | uint32_t nr_attr; |
125 | const struct side_attr *attr; | |
f611d0c3 MD |
126 | union { |
127 | struct { | |
128 | uint32_t nr_fields; | |
129 | const struct side_event_field *fields; | |
130 | } side_struct; | |
131 | struct { | |
132 | uint32_t length; | |
133 | const struct side_type_description *elem_type; | |
134 | } side_array; | |
135 | struct { | |
136 | const struct side_type_description *elem_type; | |
137 | } side_vla; | |
138 | struct { | |
139 | const struct side_type_description *elem_type; | |
352a4b77 | 140 | side_visitor visitor; |
f611d0c3 MD |
141 | } side_vla_visitor; |
142 | } u; | |
143 | }; | |
144 | ||
145 | struct side_event_field { | |
146 | const char *field_name; | |
147 | struct side_type_description side_type; | |
148 | }; | |
149 | ||
8a25ce77 MD |
150 | enum side_event_flags { |
151 | SIDE_EVENT_FLAG_VARIADIC = (1 << 0), | |
152 | }; | |
153 | ||
f611d0c3 MD |
154 | struct side_event_description { |
155 | uint32_t version; | |
156 | uint32_t enabled; | |
157 | uint32_t loglevel; /* enum side_loglevel */ | |
158 | uint32_t nr_fields; | |
65010f43 MD |
159 | uint32_t nr_attr; |
160 | uint32_t _unused; | |
8a25ce77 | 161 | uint64_t flags; |
f611d0c3 MD |
162 | const char *provider_name; |
163 | const char *event_name; | |
164 | const struct side_event_field *fields; | |
65010f43 | 165 | const struct side_attr *attr; |
f611d0c3 MD |
166 | }; |
167 | ||
a2e2357e MD |
168 | struct side_arg_dynamic_vec_vla { |
169 | const struct side_arg_dynamic_vec *sav; | |
170 | uint32_t len; | |
171 | }; | |
172 | ||
bdc39c09 | 173 | struct side_arg_dynamic_vec { |
2f5827d5 | 174 | uint32_t dynamic_type; /* enum side_dynamic_type */ |
bdc39c09 | 175 | union { |
4f40d951 MD |
176 | uint8_t side_bool; |
177 | ||
bdc39c09 MD |
178 | uint8_t side_u8; |
179 | uint16_t side_u16; | |
180 | uint32_t side_u32; | |
181 | uint64_t side_u64; | |
182 | int8_t side_s8; | |
183 | int16_t side_s16; | |
184 | int32_t side_s32; | |
185 | int64_t side_s64; | |
186 | ||
187 | const char *string; | |
188 | ||
c208889e | 189 | const struct side_arg_dynamic_event_struct *side_dynamic_struct; |
bdc39c09 | 190 | struct { |
8ceca0cd | 191 | void *app_ctx; |
c208889e MD |
192 | side_dynamic_struct_visitor visitor; |
193 | } side_dynamic_struct_visitor; | |
a2e2357e MD |
194 | |
195 | const struct side_arg_dynamic_vec_vla *side_dynamic_vla; | |
bdc39c09 | 196 | struct { |
8ceca0cd | 197 | void *app_ctx; |
bdc39c09 MD |
198 | side_dynamic_vla_visitor visitor; |
199 | } side_dynamic_vla_visitor; | |
200 | } u; | |
201 | }; | |
202 | ||
465e5e7e MD |
203 | struct side_arg_dynamic_event_field { |
204 | const char *field_name; | |
205 | const struct side_arg_dynamic_vec elem; | |
206 | //TODO: we should add something like a list of user attributes (namespaced strings) | |
207 | }; | |
208 | ||
c208889e | 209 | struct side_arg_dynamic_event_struct { |
465e5e7e MD |
210 | const struct side_arg_dynamic_event_field *fields; |
211 | uint32_t len; | |
212 | }; | |
213 | ||
f611d0c3 | 214 | struct side_arg_vec { |
1e8256c9 | 215 | enum side_type type; |
f611d0c3 | 216 | union { |
4f40d951 MD |
217 | uint8_t side_bool; |
218 | ||
f611d0c3 MD |
219 | uint8_t side_u8; |
220 | uint16_t side_u16; | |
221 | uint32_t side_u32; | |
222 | uint64_t side_u64; | |
223 | int8_t side_s8; | |
224 | int16_t side_s16; | |
225 | int32_t side_s32; | |
226 | int64_t side_s64; | |
ba845af5 | 227 | |
f611d0c3 MD |
228 | const char *string; |
229 | const struct side_arg_vec_description *side_struct; | |
230 | const struct side_arg_vec_description *side_array; | |
231 | const struct side_arg_vec_description *side_vla; | |
352a4b77 | 232 | void *side_vla_app_visitor_ctx; |
ba845af5 MD |
233 | |
234 | void *side_array_fixint; | |
1533629f MD |
235 | struct { |
236 | void *p; | |
237 | uint32_t length; | |
238 | } side_vla_fixint; | |
bdc39c09 MD |
239 | |
240 | struct side_arg_dynamic_vec dynamic; | |
f611d0c3 MD |
241 | } u; |
242 | }; | |
243 | ||
244 | struct side_arg_vec_description { | |
245 | const struct side_arg_vec *sav; | |
246 | uint32_t len; | |
247 | }; | |
248 | ||
352a4b77 MD |
249 | /* The visitor pattern is a double-dispatch visitor. */ |
250 | struct side_tracer_visitor_ctx { | |
f93e01ac MD |
251 | enum side_visitor_status (*write_elem)( |
252 | const struct side_tracer_visitor_ctx *tracer_ctx, | |
253 | const struct side_arg_vec *elem); | |
352a4b77 MD |
254 | void *priv; /* Private tracer context. */ |
255 | }; | |
256 | ||
c208889e | 257 | struct side_tracer_dynamic_struct_visitor_ctx { |
f93e01ac MD |
258 | enum side_visitor_status (*write_field)( |
259 | const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, | |
2b359235 | 260 | const struct side_arg_dynamic_event_field *dynamic_field); |
bdc39c09 MD |
261 | void *priv; /* Private tracer context. */ |
262 | }; | |
263 | ||
264 | struct side_tracer_dynamic_vla_visitor_ctx { | |
f93e01ac MD |
265 | enum side_visitor_status (*write_elem)( |
266 | const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx, | |
267 | const struct side_arg_dynamic_vec *elem); | |
bdc39c09 MD |
268 | void *priv; /* Private tracer context. */ |
269 | }; | |
270 | ||
65010f43 MD |
271 | #define side_attr(_key, _value) \ |
272 | { \ | |
273 | .key = _key, \ | |
274 | .value = _value, \ | |
275 | } | |
276 | ||
277 | #define side_attr_list(...) \ | |
278 | SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__) | |
279 | ||
f37a556f MD |
280 | #define side_type_decl(_type, _attr) \ |
281 | { \ | |
282 | .type = _type, \ | |
283 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ | |
284 | .attr = _attr, \ | |
285 | } | |
f93e01ac | 286 | |
f37a556f | 287 | #define side_field(_name, _type, _attr) \ |
f93e01ac MD |
288 | { \ |
289 | .field_name = _name, \ | |
f37a556f | 290 | .side_type = side_type_decl(_type, SIDE_PARAM(_attr)), \ |
f93e01ac | 291 | } |
f611d0c3 | 292 | |
f37a556f | 293 | #define side_type_struct_decl(_fields, _attr) \ |
f611d0c3 MD |
294 | { \ |
295 | .type = SIDE_TYPE_STRUCT, \ | |
f37a556f MD |
296 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
297 | .attr = _attr, \ | |
f611d0c3 MD |
298 | .u = { \ |
299 | .side_struct = { \ | |
300 | .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ | |
301 | .fields = _fields, \ | |
302 | }, \ | |
303 | }, \ | |
304 | } | |
f37a556f | 305 | #define side_field_struct(_name, _fields, _attr) \ |
f611d0c3 MD |
306 | { \ |
307 | .field_name = _name, \ | |
f37a556f | 308 | .side_type = side_type_struct_decl(SIDE_PARAM(_fields), SIDE_PARAM(_attr)), \ |
f611d0c3 MD |
309 | } |
310 | ||
f37a556f | 311 | #define side_type_array_decl(_elem_type, _length, _attr) \ |
f611d0c3 MD |
312 | { \ |
313 | .type = SIDE_TYPE_ARRAY, \ | |
f37a556f MD |
314 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
315 | .attr = _attr, \ | |
f611d0c3 MD |
316 | .u = { \ |
317 | .side_array = { \ | |
318 | .length = _length, \ | |
319 | .elem_type = _elem_type, \ | |
320 | }, \ | |
321 | }, \ | |
322 | } | |
f37a556f | 323 | #define side_field_array(_name, _elem_type, _length, _attr) \ |
f611d0c3 MD |
324 | { \ |
325 | .field_name = _name, \ | |
f37a556f | 326 | .side_type = side_type_array_decl(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)), \ |
f611d0c3 MD |
327 | } |
328 | ||
f37a556f | 329 | #define side_type_vla_decl(_elem_type, _attr) \ |
f611d0c3 MD |
330 | { \ |
331 | .type = SIDE_TYPE_VLA, \ | |
f37a556f MD |
332 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
333 | .attr = _attr, \ | |
f611d0c3 MD |
334 | .u = { \ |
335 | .side_vla = { \ | |
336 | .elem_type = _elem_type, \ | |
337 | }, \ | |
338 | }, \ | |
339 | } | |
f37a556f | 340 | #define side_field_vla(_name, _elem_type, _attr) \ |
f611d0c3 MD |
341 | { \ |
342 | .field_name = _name, \ | |
f37a556f | 343 | .side_type = side_type_vla_decl(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)), \ |
f611d0c3 MD |
344 | } |
345 | ||
f37a556f | 346 | #define side_type_vla_visitor_decl(_elem_type, _visitor, _attr) \ |
f611d0c3 MD |
347 | { \ |
348 | .type = SIDE_TYPE_VLA_VISITOR, \ | |
f37a556f MD |
349 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
350 | .attr = _attr, \ | |
f611d0c3 MD |
351 | .u = { \ |
352 | .side_vla_visitor = { \ | |
cdd6e858 | 353 | .elem_type = SIDE_PARAM(_elem_type), \ |
352a4b77 | 354 | .visitor = _visitor, \ |
f611d0c3 MD |
355 | }, \ |
356 | }, \ | |
357 | } | |
f37a556f | 358 | #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \ |
f611d0c3 MD |
359 | { \ |
360 | .field_name = _name, \ | |
f37a556f | 361 | .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)), \ |
f611d0c3 MD |
362 | } |
363 | ||
71002b5e | 364 | #define side_elem(...) \ |
cdd6e858 MD |
365 | SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__) |
366 | ||
f37a556f MD |
367 | #define side_elem_type(_type, _attr) \ |
368 | side_elem(side_type_decl(_type, SIDE_PARAM(_attr))) | |
f611d0c3 MD |
369 | |
370 | #define side_field_list(...) \ | |
371 | SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__) | |
372 | ||
4f40d951 | 373 | #define side_arg_bool(val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(val) } } |
f93e01ac MD |
374 | #define side_arg_u8(val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (val) } } |
375 | #define side_arg_u16(val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (val) } } | |
376 | #define side_arg_u32(val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (val) } } | |
377 | #define side_arg_u64(val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (val) } } | |
378 | #define side_arg_s8(val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (val) } } | |
379 | #define side_arg_s16(val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } } | |
380 | #define side_arg_s32(val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } } | |
381 | #define side_arg_s64(val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } } | |
382 | #define side_arg_string(val) { .type = SIDE_TYPE_STRING, .u = { .string = (val) } } | |
f611d0c3 MD |
383 | #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } } |
384 | #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } } | |
385 | #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } } | |
352a4b77 | 386 | #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } } |
f611d0c3 | 387 | |
1533629f MD |
388 | #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } } |
389 | #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } } | |
390 | #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } } | |
391 | #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } } | |
392 | #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } } | |
393 | #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } } | |
394 | #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } } | |
395 | #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } } | |
396 | ||
397 | #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } | |
398 | #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } | |
399 | #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } | |
400 | #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } | |
401 | #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } | |
402 | #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } | |
403 | #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } | |
404 | #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } | |
ba845af5 | 405 | |
bdc39c09 MD |
406 | #define side_arg_dynamic(dynamic_arg_type) \ |
407 | { \ | |
408 | .type = SIDE_TYPE_DYNAMIC, \ | |
409 | .u = { \ | |
410 | .dynamic = dynamic_arg_type, \ | |
411 | }, \ | |
412 | } | |
413 | ||
1e8256c9 | 414 | #define side_arg_dynamic_null(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_NULL } |
bdc39c09 | 415 | |
4f40d951 | 416 | #define side_arg_dynamic_bool(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, .u = { .side_bool = !!(val) } } |
1e8256c9 MD |
417 | #define side_arg_dynamic_u8(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U8, .u = { .side_u8 = (val) } } |
418 | #define side_arg_dynamic_u16(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U16, .u = { .side_u16 = (val) } } | |
419 | #define side_arg_dynamic_u32(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U32, .u = { .side_u32 = (val) } } | |
420 | #define side_arg_dynamic_u64(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U64, .u = { .side_u64 = (val) } } | |
421 | #define side_arg_dynamic_s8(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_S8, .u = { .side_s8 = (val) } } | |
422 | #define side_arg_dynamic_s16(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_S16, .u = { .side_s16 = (val) } } | |
423 | #define side_arg_dynamic_s32(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_S32, .u = { .side_s32 = (val) } } | |
424 | #define side_arg_dynamic_s64(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_S64, .u = { .side_s64 = (val) } } | |
425 | #define side_arg_dynamic_string(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, .u = { .string = (val) } } | |
bdc39c09 | 426 | |
1e8256c9 | 427 | #define side_arg_dynamic_vla(_vla) { .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, .u = { .side_dynamic_vla = (_vla) } } |
bdc39c09 MD |
428 | #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx) \ |
429 | { \ | |
1e8256c9 | 430 | .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \ |
bdc39c09 | 431 | .u = { \ |
8ceca0cd MD |
432 | .side_dynamic_vla_visitor = { \ |
433 | .app_ctx = _ctx, \ | |
434 | .visitor = _dynamic_vla_visitor, \ | |
435 | }, \ | |
bdc39c09 MD |
436 | }, \ |
437 | } | |
438 | ||
1e8256c9 | 439 | #define side_arg_dynamic_struct(_struct) { .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, .u = { .side_dynamic_struct = (_struct) } } |
c208889e | 440 | #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx) \ |
bdc39c09 | 441 | { \ |
1e8256c9 | 442 | .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \ |
bdc39c09 | 443 | .u = { \ |
8ceca0cd MD |
444 | .side_dynamic_struct_visitor = { \ |
445 | .app_ctx = _ctx, \ | |
446 | .visitor = _dynamic_struct_visitor, \ | |
447 | }, \ | |
bdc39c09 MD |
448 | }, \ |
449 | } | |
450 | ||
a2e2357e MD |
451 | #define side_arg_dynamic_define_vec(_identifier, _sav) \ |
452 | const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \ | |
453 | const struct side_arg_dynamic_vec_vla _identifier = { \ | |
454 | .sav = _identifier##_vec, \ | |
455 | .len = SIDE_ARRAY_SIZE(_identifier##_vec), \ | |
456 | } | |
457 | ||
c208889e MD |
458 | #define side_arg_dynamic_define_struct(_identifier, _struct_fields) \ |
459 | const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \ | |
460 | const struct side_arg_dynamic_event_struct _identifier = { \ | |
465e5e7e MD |
461 | .fields = _identifier##_fields, \ |
462 | .len = SIDE_ARRAY_SIZE(_identifier##_fields), \ | |
463 | } | |
464 | ||
f611d0c3 MD |
465 | #define side_arg_define_vec(_identifier, _sav) \ |
466 | const struct side_arg_vec _identifier##_vec[] = { _sav }; \ | |
467 | const struct side_arg_vec_description _identifier = { \ | |
468 | .sav = _identifier##_vec, \ | |
469 | .len = SIDE_ARRAY_SIZE(_identifier##_vec), \ | |
470 | } | |
a2e2357e | 471 | |
465e5e7e MD |
472 | #define side_arg_dynamic_field(_name, _elem) \ |
473 | { \ | |
474 | .field_name = _name, \ | |
475 | .elem = _elem, \ | |
476 | } | |
477 | ||
f611d0c3 MD |
478 | #define side_arg_list(...) __VA_ARGS__ |
479 | ||
480 | #define side_event_cond(desc) if (side_unlikely((desc)->enabled)) | |
19fa6aa2 | 481 | |
f611d0c3 MD |
482 | #define side_event_call(desc, _sav) \ |
483 | { \ | |
484 | const struct side_arg_vec side_sav[] = { _sav }; \ | |
485 | const struct side_arg_vec_description sav_desc = { \ | |
486 | .sav = side_sav, \ | |
487 | .len = SIDE_ARRAY_SIZE(side_sav), \ | |
488 | }; \ | |
489 | tracer_call(desc, &sav_desc); \ | |
490 | } | |
491 | ||
492 | #define side_event(desc, sav) \ | |
493 | side_event_cond(desc) \ | |
6c40fa8b | 494 | side_event_call(desc, SIDE_PARAM(sav)) |
f611d0c3 | 495 | |
19fa6aa2 MD |
496 | #define side_event_call_variadic(desc, _sav, _var_fields) \ |
497 | { \ | |
498 | const struct side_arg_vec side_sav[] = { _sav }; \ | |
499 | const struct side_arg_vec_description sav_desc = { \ | |
500 | .sav = side_sav, \ | |
501 | .len = SIDE_ARRAY_SIZE(side_sav), \ | |
502 | }; \ | |
503 | const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \ | |
504 | const struct side_arg_dynamic_event_struct var_struct = { \ | |
505 | .fields = side_fields, \ | |
506 | .len = SIDE_ARRAY_SIZE(side_fields), \ | |
507 | }; \ | |
508 | tracer_call_variadic(desc, &sav_desc, &var_struct); \ | |
509 | } | |
510 | ||
511 | #define side_event_variadic(desc, sav, var) \ | |
512 | side_event_cond(desc) \ | |
513 | side_event_call_variadic(desc, SIDE_PARAM(sav), SIDE_PARAM(var)) | |
514 | ||
399c836b | 515 | #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \ |
f611d0c3 MD |
516 | struct side_event_description _identifier = { \ |
517 | .version = 0, \ | |
518 | .enabled = 0, \ | |
519 | .loglevel = _loglevel, \ | |
520 | .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ | |
65010f43 | 521 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
8a25ce77 | 522 | .flags = (_flags), \ |
f611d0c3 MD |
523 | .provider_name = _provider, \ |
524 | .event_name = _event, \ | |
525 | .fields = _fields, \ | |
65010f43 | 526 | .attr = _attr, \ |
f611d0c3 MD |
527 | } |
528 | ||
399c836b MD |
529 | #define side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \ |
530 | _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ | |
531 | SIDE_PARAM(_attr), 0) | |
8a25ce77 | 532 | |
399c836b MD |
533 | #define side_define_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \ |
534 | _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ | |
535 | SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC) | |
8a25ce77 | 536 | |
f611d0c3 MD |
537 | #define side_declare_event(_identifier) \ |
538 | struct side_event_description _identifier | |
539 | ||
540 | #endif /* _SIDE_TRACE_H */ |