ed039fa77c8b15d5483978dadc5a26449f7a6764
[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 <side/macros.h>
14
15 /* SIDE stands for "Static Instrumentation Dynamically Enabled" */
16
17 struct side_arg_vec;
18 struct side_arg_vec_description;
19 struct side_arg_dynamic_vec;
20 struct side_arg_dynamic_vec_vla;
21 struct side_type_description;
22 struct side_event_field;
23 struct side_tracer_visitor_ctx;
24 struct side_tracer_dynamic_struct_visitor_ctx;
25 struct side_tracer_dynamic_vla_visitor_ctx;
26
27 enum side_type {
28 SIDE_TYPE_BOOL,
29
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,
38
39 SIDE_TYPE_STRING,
40
41 SIDE_TYPE_STRUCT,
42 SIDE_TYPE_ARRAY,
43 SIDE_TYPE_VLA,
44 SIDE_TYPE_VLA_VISITOR,
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
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
64 SIDE_TYPE_DYNAMIC,
65 };
66
67 enum side_dynamic_type {
68 SIDE_DYNAMIC_TYPE_NULL,
69
70 SIDE_DYNAMIC_TYPE_BOOL,
71
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
83 SIDE_DYNAMIC_TYPE_STRUCT,
84 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR,
85
86 SIDE_DYNAMIC_TYPE_VLA,
87 SIDE_DYNAMIC_TYPE_VLA_VISITOR,
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 {
102 SIDE_VISITOR_STATUS_OK = 0,
103 SIDE_VISITOR_STATUS_ERROR = -1,
104 };
105
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);
115
116 /* User attributes. */
117 struct side_attr {
118 const char *key;
119 const char *value;
120 };
121
122 struct side_type_description {
123 uint32_t type; /* enum side_type */
124 uint32_t nr_attr;
125 const struct side_attr *attr;
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;
140 side_visitor visitor;
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
150 enum side_event_flags {
151 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
152 };
153
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;
159 uint32_t nr_attr;
160 uint32_t _unused;
161 uint64_t flags;
162 const char *provider_name;
163 const char *event_name;
164 const struct side_event_field *fields;
165 const struct side_attr *attr;
166 };
167
168 struct side_arg_dynamic_vec_vla {
169 const struct side_arg_dynamic_vec *sav;
170 uint32_t len;
171 };
172
173 struct side_arg_dynamic_vec {
174 uint32_t dynamic_type; /* enum side_dynamic_type */
175 uint32_t nr_attr;
176 const struct side_attr *attr;
177 union {
178 uint8_t side_bool;
179
180 uint8_t side_u8;
181 uint16_t side_u16;
182 uint32_t side_u32;
183 uint64_t side_u64;
184 int8_t side_s8;
185 int16_t side_s16;
186 int32_t side_s32;
187 int64_t side_s64;
188
189 const char *string;
190
191 const struct side_arg_dynamic_event_struct *side_dynamic_struct;
192 struct {
193 void *app_ctx;
194 side_dynamic_struct_visitor visitor;
195 } side_dynamic_struct_visitor;
196
197 const struct side_arg_dynamic_vec_vla *side_dynamic_vla;
198 struct {
199 void *app_ctx;
200 side_dynamic_vla_visitor visitor;
201 } side_dynamic_vla_visitor;
202 } u;
203 };
204
205 struct side_arg_dynamic_event_field {
206 const char *field_name;
207 const struct side_arg_dynamic_vec elem;
208 };
209
210 struct side_arg_dynamic_event_struct {
211 const struct side_arg_dynamic_event_field *fields;
212 uint32_t len;
213 };
214
215 struct side_arg_vec {
216 enum side_type type;
217 union {
218 uint8_t side_bool;
219
220 uint8_t side_u8;
221 uint16_t side_u16;
222 uint32_t side_u32;
223 uint64_t side_u64;
224 int8_t side_s8;
225 int16_t side_s16;
226 int32_t side_s32;
227 int64_t side_s64;
228
229 const char *string;
230 const struct side_arg_vec_description *side_struct;
231 const struct side_arg_vec_description *side_array;
232 const struct side_arg_vec_description *side_vla;
233 void *side_vla_app_visitor_ctx;
234
235 void *side_array_fixint;
236 struct {
237 void *p;
238 uint32_t length;
239 } side_vla_fixint;
240
241 struct side_arg_dynamic_vec dynamic;
242 } u;
243 };
244
245 struct side_arg_vec_description {
246 const struct side_arg_vec *sav;
247 uint32_t len;
248 };
249
250 /* The visitor pattern is a double-dispatch visitor. */
251 struct side_tracer_visitor_ctx {
252 enum side_visitor_status (*write_elem)(
253 const struct side_tracer_visitor_ctx *tracer_ctx,
254 const struct side_arg_vec *elem);
255 void *priv; /* Private tracer context. */
256 };
257
258 struct side_tracer_dynamic_struct_visitor_ctx {
259 enum side_visitor_status (*write_field)(
260 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
261 const struct side_arg_dynamic_event_field *dynamic_field);
262 void *priv; /* Private tracer context. */
263 };
264
265 struct side_tracer_dynamic_vla_visitor_ctx {
266 enum side_visitor_status (*write_elem)(
267 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
268 const struct side_arg_dynamic_vec *elem);
269 void *priv; /* Private tracer context. */
270 };
271
272 #define side_attr(_key, _value) \
273 { \
274 .key = _key, \
275 .value = _value, \
276 }
277
278 #define side_attr_list(...) \
279 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
280
281 #define side_type_decl(_type, _attr) \
282 { \
283 .type = _type, \
284 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
285 .attr = _attr, \
286 }
287
288 #define side_field(_name, _type, _attr) \
289 { \
290 .field_name = _name, \
291 .side_type = side_type_decl(_type, SIDE_PARAM(_attr)), \
292 }
293
294 #define side_type_struct_decl(_fields, _attr) \
295 { \
296 .type = SIDE_TYPE_STRUCT, \
297 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
298 .attr = _attr, \
299 .u = { \
300 .side_struct = { \
301 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
302 .fields = _fields, \
303 }, \
304 }, \
305 }
306 #define side_field_struct(_name, _fields, _attr) \
307 { \
308 .field_name = _name, \
309 .side_type = side_type_struct_decl(SIDE_PARAM(_fields), SIDE_PARAM(_attr)), \
310 }
311
312 #define side_type_array_decl(_elem_type, _length, _attr) \
313 { \
314 .type = SIDE_TYPE_ARRAY, \
315 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
316 .attr = _attr, \
317 .u = { \
318 .side_array = { \
319 .length = _length, \
320 .elem_type = _elem_type, \
321 }, \
322 }, \
323 }
324 #define side_field_array(_name, _elem_type, _length, _attr) \
325 { \
326 .field_name = _name, \
327 .side_type = side_type_array_decl(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)), \
328 }
329
330 #define side_type_vla_decl(_elem_type, _attr) \
331 { \
332 .type = SIDE_TYPE_VLA, \
333 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
334 .attr = _attr, \
335 .u = { \
336 .side_vla = { \
337 .elem_type = _elem_type, \
338 }, \
339 }, \
340 }
341 #define side_field_vla(_name, _elem_type, _attr) \
342 { \
343 .field_name = _name, \
344 .side_type = side_type_vla_decl(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)), \
345 }
346
347 #define side_type_vla_visitor_decl(_elem_type, _visitor, _attr) \
348 { \
349 .type = SIDE_TYPE_VLA_VISITOR, \
350 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
351 .attr = _attr, \
352 .u = { \
353 .side_vla_visitor = { \
354 .elem_type = SIDE_PARAM(_elem_type), \
355 .visitor = _visitor, \
356 }, \
357 }, \
358 }
359 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
360 { \
361 .field_name = _name, \
362 .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)), \
363 }
364
365 #define side_elem(...) \
366 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
367
368 #define side_elem_type(_type, _attr) \
369 side_elem(side_type_decl(_type, SIDE_PARAM(_attr)))
370
371 #define side_field_list(...) \
372 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
373
374 #define side_arg_bool(val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(val) } }
375 #define side_arg_u8(val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (val) } }
376 #define side_arg_u16(val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (val) } }
377 #define side_arg_u32(val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (val) } }
378 #define side_arg_u64(val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (val) } }
379 #define side_arg_s8(val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (val) } }
380 #define side_arg_s16(val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } }
381 #define side_arg_s32(val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } }
382 #define side_arg_s64(val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } }
383 #define side_arg_string(val) { .type = SIDE_TYPE_STRING, .u = { .string = (val) } }
384 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
385 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
386 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
387 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
388
389 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
390 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
391 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
392 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
393 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
394 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
395 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
396 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
397
398 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
399 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
400 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
401 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
402 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
403 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
404 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
405 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
406
407 #define side_arg_dynamic(dynamic_arg_type) \
408 { \
409 .type = SIDE_TYPE_DYNAMIC, \
410 .u = { \
411 .dynamic = dynamic_arg_type, \
412 }, \
413 }
414
415 #define side_arg_dynamic_null(_attr) \
416 { \
417 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
418 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
419 .attr = _attr, \
420 }
421
422 #define side_arg_dynamic_bool(_val, _attr) \
423 { \
424 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
425 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
426 .attr = _attr, \
427 .u = { \
428 .side_bool = !!(_val), \
429 }, \
430 }
431
432 #define side_arg_dynamic_u8(_val, _attr) \
433 { \
434 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
435 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
436 .attr = _attr, \
437 .u = { \
438 .side_u8 = (_val), \
439 }, \
440 }
441 #define side_arg_dynamic_u16(_val, _attr) \
442 { \
443 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
444 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
445 .attr = _attr, \
446 .u = { \
447 .side_u16 = (_val), \
448 }, \
449 }
450 #define side_arg_dynamic_u32(_val, _attr) \
451 { \
452 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
453 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
454 .attr = _attr, \
455 .u = { \
456 .side_u32 = (_val), \
457 }, \
458 }
459 #define side_arg_dynamic_u64(_val, _attr) \
460 { \
461 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
462 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
463 .attr = _attr, \
464 .u = { \
465 .side_u64 = (_val), \
466 }, \
467 }
468
469 #define side_arg_dynamic_s8(_val, _attr) \
470 { \
471 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
472 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
473 .attr = _attr, \
474 .u = { \
475 .side_s8 = (_val), \
476 }, \
477 }
478 #define side_arg_dynamic_s16(_val, _attr) \
479 { \
480 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
481 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
482 .attr = _attr, \
483 .u = { \
484 .side_s16 = (_val), \
485 }, \
486 }
487 #define side_arg_dynamic_s32(_val, _attr) \
488 { \
489 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
490 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
491 .attr = _attr, \
492 .u = { \
493 .side_s32 = (_val), \
494 }, \
495 }
496 #define side_arg_dynamic_s64(_val, _attr) \
497 { \
498 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
499 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
500 .attr = _attr, \
501 .u = { \
502 .side_s64 = (_val), \
503 }, \
504 }
505
506 #define side_arg_dynamic_string(_val, _attr) \
507 { \
508 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
509 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
510 .attr = _attr, \
511 .u = { \
512 .string = (_val), \
513 }, \
514 }
515
516 #define side_arg_dynamic_vla(_vla, _attr) \
517 { \
518 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
519 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
520 .attr = _attr, \
521 .u = { \
522 .side_dynamic_vla = (_vla), \
523 }, \
524 }
525
526 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
527 { \
528 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
529 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
530 .attr = _attr, \
531 .u = { \
532 .side_dynamic_vla_visitor = { \
533 .app_ctx = _ctx, \
534 .visitor = _dynamic_vla_visitor, \
535 }, \
536 }, \
537 }
538
539 #define side_arg_dynamic_struct(_struct, _attr) \
540 { \
541 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
542 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
543 .attr = _attr, \
544 .u = { \
545 .side_dynamic_struct = (_struct), \
546 }, \
547 }
548
549 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
550 { \
551 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
552 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
553 .attr = _attr, \
554 .u = { \
555 .side_dynamic_struct_visitor = { \
556 .app_ctx = _ctx, \
557 .visitor = _dynamic_struct_visitor, \
558 }, \
559 }, \
560 }
561
562 #define side_arg_dynamic_define_vec(_identifier, _sav) \
563 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
564 const struct side_arg_dynamic_vec_vla _identifier = { \
565 .sav = _identifier##_vec, \
566 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
567 }
568
569 #define side_arg_dynamic_define_struct(_identifier, _struct_fields) \
570 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
571 const struct side_arg_dynamic_event_struct _identifier = { \
572 .fields = _identifier##_fields, \
573 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
574 }
575
576 #define side_arg_define_vec(_identifier, _sav) \
577 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
578 const struct side_arg_vec_description _identifier = { \
579 .sav = _identifier##_vec, \
580 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
581 }
582
583 #define side_arg_dynamic_field(_name, _elem) \
584 { \
585 .field_name = _name, \
586 .elem = _elem, \
587 }
588
589 #define side_arg_list(...) __VA_ARGS__
590
591 #define side_event_cond(desc) if (side_unlikely((desc)->enabled))
592
593 #define side_event_call(desc, _sav) \
594 { \
595 const struct side_arg_vec side_sav[] = { _sav }; \
596 const struct side_arg_vec_description sav_desc = { \
597 .sav = side_sav, \
598 .len = SIDE_ARRAY_SIZE(side_sav), \
599 }; \
600 tracer_call(desc, &sav_desc); \
601 }
602
603 #define side_event(desc, sav) \
604 side_event_cond(desc) \
605 side_event_call(desc, SIDE_PARAM(sav))
606
607 #define side_event_call_variadic(desc, _sav, _var_fields) \
608 { \
609 const struct side_arg_vec side_sav[] = { _sav }; \
610 const struct side_arg_vec_description sav_desc = { \
611 .sav = side_sav, \
612 .len = SIDE_ARRAY_SIZE(side_sav), \
613 }; \
614 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
615 const struct side_arg_dynamic_event_struct var_struct = { \
616 .fields = side_fields, \
617 .len = SIDE_ARRAY_SIZE(side_fields), \
618 }; \
619 tracer_call_variadic(desc, &sav_desc, &var_struct); \
620 }
621
622 #define side_event_variadic(desc, sav, var) \
623 side_event_cond(desc) \
624 side_event_call_variadic(desc, SIDE_PARAM(sav), SIDE_PARAM(var))
625
626 #define _side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
627 struct side_event_description _identifier = { \
628 .version = 0, \
629 .enabled = 0, \
630 .loglevel = _loglevel, \
631 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
632 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
633 .flags = (_flags), \
634 .provider_name = _provider, \
635 .event_name = _event, \
636 .fields = _fields, \
637 .attr = _attr, \
638 }
639
640 #define side_define_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
641 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
642 SIDE_PARAM(_attr), 0)
643
644 #define side_define_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
645 _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
646 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
647
648 #define side_declare_event(_identifier) \
649 struct side_event_description _identifier
650
651 #endif /* _SIDE_TRACE_H */
This page took 0.044121 seconds and 4 git commands to generate.