Implement floating point type support
[libside.git] / src / tracer.c
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 */
5
6 #include <stdint.h>
7 #include <inttypes.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10
11 #include <side/trace.h>
12
13 static
14 void tracer_print_struct(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc);
15 static
16 void tracer_print_array(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc);
17 static
18 void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc);
19 static
20 void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *app_ctx);
21 static
22 void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item);
23 static
24 void tracer_print_vla_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item);
25 static
26 void tracer_print_dynamic(const struct side_arg_dynamic_vec *dynamic_item);
27
28 static
29 void print_attributes(const char *prefix_str, const struct side_attr *attr, uint32_t nr_attr)
30 {
31 int i;
32
33 if (!nr_attr)
34 return;
35 printf("%s[ ", prefix_str);
36 for (i = 0; i < nr_attr; i++) {
37 printf("%s", i ? ", " : "");
38 printf("{ key: \"%s\", value: \"%s\" }",
39 attr[i].key, attr[i].value);
40 }
41 printf(" ]");
42 }
43
44 static
45 void tracer_print_type(const struct side_type_description *type_desc, const struct side_arg_vec *item)
46 {
47 switch (item->type) {
48 case SIDE_TYPE_ARRAY_U8:
49 case SIDE_TYPE_ARRAY_U16:
50 case SIDE_TYPE_ARRAY_U32:
51 case SIDE_TYPE_ARRAY_U64:
52 case SIDE_TYPE_ARRAY_S8:
53 case SIDE_TYPE_ARRAY_S16:
54 case SIDE_TYPE_ARRAY_S32:
55 case SIDE_TYPE_ARRAY_S64:
56 if (type_desc->type != SIDE_TYPE_ARRAY) {
57 printf("ERROR: type mismatch between description and arguments\n");
58 abort();
59 }
60 break;
61 case SIDE_TYPE_VLA_U8:
62 case SIDE_TYPE_VLA_U16:
63 case SIDE_TYPE_VLA_U32:
64 case SIDE_TYPE_VLA_U64:
65 case SIDE_TYPE_VLA_S8:
66 case SIDE_TYPE_VLA_S16:
67 case SIDE_TYPE_VLA_S32:
68 case SIDE_TYPE_VLA_S64:
69 if (type_desc->type != SIDE_TYPE_VLA) {
70 printf("ERROR: type mismatch between description and arguments\n");
71 abort();
72 }
73 break;
74
75 default:
76 if (type_desc->type != item->type) {
77 printf("ERROR: type mismatch between description and arguments\n");
78 abort();
79 }
80 break;
81 }
82 printf("{ ");
83 print_attributes("attr: ", type_desc->attr, type_desc->nr_attr);
84 printf("%s", type_desc->nr_attr ? ", " : "");
85 printf("value: ");
86 switch (item->type) {
87 case SIDE_TYPE_BOOL:
88 printf("%s", item->u.side_bool ? "true" : "false");
89 break;
90 case SIDE_TYPE_U8:
91 printf("%" PRIu8, item->u.side_u8);
92 break;
93 case SIDE_TYPE_U16:
94 printf("%" PRIu16, item->u.side_u16);
95 break;
96 case SIDE_TYPE_U32:
97 printf("%" PRIu32, item->u.side_u32);
98 break;
99 case SIDE_TYPE_U64:
100 printf("%" PRIu64, item->u.side_u64);
101 break;
102 case SIDE_TYPE_S8:
103 printf("%" PRId8, item->u.side_s8);
104 break;
105 case SIDE_TYPE_S16:
106 printf("%" PRId16, item->u.side_s16);
107 break;
108 case SIDE_TYPE_S32:
109 printf("%" PRId32, item->u.side_s32);
110 break;
111 case SIDE_TYPE_S64:
112 printf("%" PRId64, item->u.side_s64);
113 break;
114 case SIDE_TYPE_FLOAT_BINARY16:
115 #if __HAVE_FLOAT16
116 printf("%g", (double) item->u.side_float_binary16);
117 break;
118 #else
119 printf("ERROR: Unsupported binary16 float type\n");
120 abort();
121 #endif
122 case SIDE_TYPE_FLOAT_BINARY32:
123 #if __HAVE_FLOAT32
124 printf("%g", (double) item->u.side_float_binary32);
125 break;
126 #else
127 printf("ERROR: Unsupported binary32 float type\n");
128 abort();
129 #endif
130 case SIDE_TYPE_FLOAT_BINARY64:
131 #if __HAVE_FLOAT64
132 printf("%g", (double) item->u.side_float_binary64);
133 break;
134 #else
135 printf("ERROR: Unsupported binary64 float type\n");
136 abort();
137 #endif
138 case SIDE_TYPE_FLOAT_BINARY128:
139 #if __HAVE_FLOAT128
140 printf("%Lg", (long double) item->u.side_float_binary128);
141 break;
142 #else
143 printf("ERROR: Unsupported binary128 float type\n");
144 abort();
145 #endif
146 case SIDE_TYPE_STRING:
147 printf("\"%s\"", item->u.string);
148 break;
149 case SIDE_TYPE_STRUCT:
150 tracer_print_struct(type_desc, item->u.side_struct);
151 break;
152 case SIDE_TYPE_ARRAY:
153 tracer_print_array(type_desc, item->u.side_array);
154 break;
155 case SIDE_TYPE_VLA:
156 tracer_print_vla(type_desc, item->u.side_vla);
157 break;
158 case SIDE_TYPE_VLA_VISITOR:
159 tracer_print_vla_visitor(type_desc, item->u.side_vla_app_visitor_ctx);
160 break;
161 case SIDE_TYPE_ARRAY_U8:
162 case SIDE_TYPE_ARRAY_U16:
163 case SIDE_TYPE_ARRAY_U32:
164 case SIDE_TYPE_ARRAY_U64:
165 case SIDE_TYPE_ARRAY_S8:
166 case SIDE_TYPE_ARRAY_S16:
167 case SIDE_TYPE_ARRAY_S32:
168 case SIDE_TYPE_ARRAY_S64:
169 tracer_print_array_fixint(type_desc, item);
170 break;
171 case SIDE_TYPE_VLA_U8:
172 case SIDE_TYPE_VLA_U16:
173 case SIDE_TYPE_VLA_U32:
174 case SIDE_TYPE_VLA_U64:
175 case SIDE_TYPE_VLA_S8:
176 case SIDE_TYPE_VLA_S16:
177 case SIDE_TYPE_VLA_S32:
178 case SIDE_TYPE_VLA_S64:
179 tracer_print_vla_fixint(type_desc, item);
180 break;
181 case SIDE_TYPE_DYNAMIC:
182 tracer_print_dynamic(&item->u.dynamic);
183 break;
184 default:
185 printf("<UNKNOWN TYPE>");
186 abort();
187 }
188 printf(" }");
189 }
190
191 static
192 void tracer_print_field(const struct side_event_field *item_desc, const struct side_arg_vec *item)
193 {
194 printf("%s: ", item_desc->field_name);
195 tracer_print_type(&item_desc->side_type, item);
196 }
197
198 static
199 void tracer_print_struct(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
200 {
201 const struct side_arg_vec *sav = sav_desc->sav;
202 uint32_t side_sav_len = sav_desc->len;
203 int i;
204
205 if (type_desc->u.side_struct.nr_fields != side_sav_len) {
206 printf("ERROR: number of fields mismatch between description and arguments of structure\n");
207 abort();
208 }
209 printf("{ ");
210 for (i = 0; i < side_sav_len; i++) {
211 printf("%s", i ? ", " : "");
212 tracer_print_field(&type_desc->u.side_struct.fields[i], &sav[i]);
213 }
214 printf(" }");
215 }
216
217 static
218 void tracer_print_array(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
219 {
220 const struct side_arg_vec *sav = sav_desc->sav;
221 uint32_t side_sav_len = sav_desc->len;
222 int i;
223
224 if (type_desc->u.side_array.length != side_sav_len) {
225 printf("ERROR: length mismatch between description and arguments of array\n");
226 abort();
227 }
228 printf("[ ");
229 for (i = 0; i < side_sav_len; i++) {
230 printf("%s", i ? ", " : "");
231 tracer_print_type(type_desc->u.side_array.elem_type, &sav[i]);
232 }
233 printf(" ]");
234 }
235
236 static
237 void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
238 {
239 const struct side_arg_vec *sav = sav_desc->sav;
240 uint32_t side_sav_len = sav_desc->len;
241 int i;
242
243 printf("[ ");
244 for (i = 0; i < side_sav_len; i++) {
245 printf("%s", i ? ", " : "");
246 tracer_print_type(type_desc->u.side_vla.elem_type, &sav[i]);
247 }
248 printf(" ]");
249 }
250
251 struct tracer_visitor_priv {
252 const struct side_type_description *elem_type;
253 int i;
254 };
255
256 static
257 enum side_visitor_status tracer_write_elem_cb(const struct side_tracer_visitor_ctx *tracer_ctx,
258 const struct side_arg_vec *elem)
259 {
260 struct tracer_visitor_priv *tracer_priv = tracer_ctx->priv;
261
262 printf("%s", tracer_priv->i++ ? ", " : "");
263 tracer_print_type(tracer_priv->elem_type, elem);
264 return SIDE_VISITOR_STATUS_OK;
265 }
266
267 static
268 void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *app_ctx)
269 {
270 enum side_visitor_status status;
271 struct tracer_visitor_priv tracer_priv = {
272 .elem_type = type_desc->u.side_vla_visitor.elem_type,
273 .i = 0,
274 };
275 const struct side_tracer_visitor_ctx tracer_ctx = {
276 .write_elem = tracer_write_elem_cb,
277 .priv = &tracer_priv,
278 };
279
280 printf("[ ");
281 status = type_desc->u.side_vla_visitor.visitor(&tracer_ctx, app_ctx);
282 switch (status) {
283 case SIDE_VISITOR_STATUS_OK:
284 break;
285 case SIDE_VISITOR_STATUS_ERROR:
286 printf("ERROR: Visitor error\n");
287 abort();
288 }
289 printf(" ]");
290 }
291
292 void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item)
293 {
294 const struct side_type_description *elem_type = type_desc->u.side_array.elem_type;
295 uint32_t side_sav_len = type_desc->u.side_array.length;
296 void *p = item->u.side_array_fixint;
297 enum side_type side_type;
298 int i;
299
300 switch (item->type) {
301 case SIDE_TYPE_ARRAY_U8:
302 if (elem_type->type != SIDE_TYPE_U8)
303 goto type_error;
304 break;
305 case SIDE_TYPE_ARRAY_U16:
306 if (elem_type->type != SIDE_TYPE_U16)
307 goto type_error;
308 break;
309 case SIDE_TYPE_ARRAY_U32:
310 if (elem_type->type != SIDE_TYPE_U32)
311 goto type_error;
312 break;
313 case SIDE_TYPE_ARRAY_U64:
314 if (elem_type->type != SIDE_TYPE_U64)
315 goto type_error;
316 break;
317 case SIDE_TYPE_ARRAY_S8:
318 if (elem_type->type != SIDE_TYPE_S8)
319 goto type_error;
320 break;
321 case SIDE_TYPE_ARRAY_S16:
322 if (elem_type->type != SIDE_TYPE_S16)
323 goto type_error;
324 break;
325 case SIDE_TYPE_ARRAY_S32:
326 if (elem_type->type != SIDE_TYPE_S32)
327 goto type_error;
328 break;
329 case SIDE_TYPE_ARRAY_S64:
330 if (elem_type->type != SIDE_TYPE_S64)
331 goto type_error;
332 break;
333 default:
334 goto type_error;
335 }
336 side_type = elem_type->type;
337
338 printf("[ ");
339 for (i = 0; i < side_sav_len; i++) {
340 struct side_arg_vec sav_elem = {
341 .type = side_type,
342 };
343
344 switch (side_type) {
345 case SIDE_TYPE_U8:
346 sav_elem.u.side_u8 = ((const uint8_t *) p)[i];
347 break;
348 case SIDE_TYPE_S8:
349 sav_elem.u.side_s8 = ((const int8_t *) p)[i];
350 break;
351 case SIDE_TYPE_U16:
352 sav_elem.u.side_u16 = ((const uint16_t *) p)[i];
353 break;
354 case SIDE_TYPE_S16:
355 sav_elem.u.side_s16 = ((const int16_t *) p)[i];
356 break;
357 case SIDE_TYPE_U32:
358 sav_elem.u.side_u32 = ((const uint32_t *) p)[i];
359 break;
360 case SIDE_TYPE_S32:
361 sav_elem.u.side_s32 = ((const int32_t *) p)[i];
362 break;
363 case SIDE_TYPE_U64:
364 sav_elem.u.side_u64 = ((const uint64_t *) p)[i];
365 break;
366 case SIDE_TYPE_S64:
367 sav_elem.u.side_s64 = ((const int64_t *) p)[i];
368 break;
369
370 default:
371 printf("ERROR: Unexpected type\n");
372 abort();
373 }
374
375 printf("%s", i ? ", " : "");
376 tracer_print_type(elem_type, &sav_elem);
377 }
378 printf(" ]");
379 return;
380
381 type_error:
382 printf("ERROR: type mismatch\n");
383 abort();
384 }
385
386 void tracer_print_vla_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item)
387 {
388 const struct side_type_description *elem_type = type_desc->u.side_vla.elem_type;
389 uint32_t side_sav_len = item->u.side_vla_fixint.length;
390 void *p = item->u.side_vla_fixint.p;
391 enum side_type side_type;
392 int i;
393
394 switch (item->type) {
395 case SIDE_TYPE_VLA_U8:
396 if (elem_type->type != SIDE_TYPE_U8)
397 goto type_error;
398 break;
399 case SIDE_TYPE_VLA_U16:
400 if (elem_type->type != SIDE_TYPE_U16)
401 goto type_error;
402 break;
403 case SIDE_TYPE_VLA_U32:
404 if (elem_type->type != SIDE_TYPE_U32)
405 goto type_error;
406 break;
407 case SIDE_TYPE_VLA_U64:
408 if (elem_type->type != SIDE_TYPE_U64)
409 goto type_error;
410 break;
411 case SIDE_TYPE_VLA_S8:
412 if (elem_type->type != SIDE_TYPE_S8)
413 goto type_error;
414 break;
415 case SIDE_TYPE_VLA_S16:
416 if (elem_type->type != SIDE_TYPE_S16)
417 goto type_error;
418 break;
419 case SIDE_TYPE_VLA_S32:
420 if (elem_type->type != SIDE_TYPE_S32)
421 goto type_error;
422 break;
423 case SIDE_TYPE_VLA_S64:
424 if (elem_type->type != SIDE_TYPE_S64)
425 goto type_error;
426 break;
427 default:
428 goto type_error;
429 }
430 side_type = elem_type->type;
431
432 printf("[ ");
433 for (i = 0; i < side_sav_len; i++) {
434 struct side_arg_vec sav_elem = {
435 .type = side_type,
436 };
437
438 switch (side_type) {
439 case SIDE_TYPE_U8:
440 sav_elem.u.side_u8 = ((const uint8_t *) p)[i];
441 break;
442 case SIDE_TYPE_S8:
443 sav_elem.u.side_s8 = ((const int8_t *) p)[i];
444 break;
445 case SIDE_TYPE_U16:
446 sav_elem.u.side_u16 = ((const uint16_t *) p)[i];
447 break;
448 case SIDE_TYPE_S16:
449 sav_elem.u.side_s16 = ((const int16_t *) p)[i];
450 break;
451 case SIDE_TYPE_U32:
452 sav_elem.u.side_u32 = ((const uint32_t *) p)[i];
453 break;
454 case SIDE_TYPE_S32:
455 sav_elem.u.side_s32 = ((const int32_t *) p)[i];
456 break;
457 case SIDE_TYPE_U64:
458 sav_elem.u.side_u64 = ((const uint64_t *) p)[i];
459 break;
460 case SIDE_TYPE_S64:
461 sav_elem.u.side_s64 = ((const int64_t *) p)[i];
462 break;
463
464 default:
465 printf("ERROR: Unexpected type\n");
466 abort();
467 }
468
469 printf("%s", i ? ", " : "");
470 tracer_print_type(elem_type, &sav_elem);
471 }
472 printf(" ]");
473 return;
474
475 type_error:
476 printf("ERROR: type mismatch\n");
477 abort();
478 }
479
480 static
481 void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct *dynamic_struct)
482 {
483 const struct side_arg_dynamic_event_field *fields = dynamic_struct->fields;
484 uint32_t len = dynamic_struct->len;
485 int i;
486
487 printf("[ ");
488 for (i = 0; i < len; i++) {
489 printf("%s", i ? ", " : "");
490 printf("%s:: ", fields[i].field_name);
491 tracer_print_dynamic(&fields[i].elem);
492 }
493 printf(" ]");
494 }
495
496 struct tracer_dynamic_struct_visitor_priv {
497 int i;
498 };
499
500 static
501 enum side_visitor_status tracer_dynamic_struct_write_elem_cb(
502 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
503 const struct side_arg_dynamic_event_field *dynamic_field)
504 {
505 struct tracer_dynamic_struct_visitor_priv *tracer_priv = tracer_ctx->priv;
506
507 printf("%s", tracer_priv->i++ ? ", " : "");
508 printf("%s:: ", dynamic_field->field_name);
509 tracer_print_dynamic(&dynamic_field->elem);
510 return SIDE_VISITOR_STATUS_OK;
511 }
512
513 static
514 void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec *item)
515 {
516 enum side_visitor_status status;
517 struct tracer_dynamic_struct_visitor_priv tracer_priv = {
518 .i = 0,
519 };
520 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx = {
521 .write_field = tracer_dynamic_struct_write_elem_cb,
522 .priv = &tracer_priv,
523 };
524 void *app_ctx = item->u.side_dynamic_struct_visitor.app_ctx;
525
526 printf("[ ");
527 status = item->u.side_dynamic_struct_visitor.visitor(&tracer_ctx, app_ctx);
528 switch (status) {
529 case SIDE_VISITOR_STATUS_OK:
530 break;
531 case SIDE_VISITOR_STATUS_ERROR:
532 printf("ERROR: Visitor error\n");
533 abort();
534 }
535 printf(" ]");
536 }
537
538 static
539 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla *vla)
540 {
541 const struct side_arg_dynamic_vec *sav = vla->sav;
542 uint32_t side_sav_len = vla->len;
543 int i;
544
545 printf("[ ");
546 for (i = 0; i < side_sav_len; i++) {
547 printf("%s", i ? ", " : "");
548 tracer_print_dynamic(&sav[i]);
549 }
550 printf(" ]");
551 }
552
553 struct tracer_dynamic_vla_visitor_priv {
554 int i;
555 };
556
557 static
558 enum side_visitor_status tracer_dynamic_vla_write_elem_cb(
559 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
560 const struct side_arg_dynamic_vec *elem)
561 {
562 struct tracer_dynamic_vla_visitor_priv *tracer_priv = tracer_ctx->priv;
563
564 printf("%s", tracer_priv->i++ ? ", " : "");
565 tracer_print_dynamic(elem);
566 return SIDE_VISITOR_STATUS_OK;
567 }
568
569 static
570 void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec *item)
571 {
572 enum side_visitor_status status;
573 struct tracer_dynamic_vla_visitor_priv tracer_priv = {
574 .i = 0,
575 };
576 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx = {
577 .write_elem = tracer_dynamic_vla_write_elem_cb,
578 .priv = &tracer_priv,
579 };
580 void *app_ctx = item->u.side_dynamic_vla_visitor.app_ctx;
581
582 printf("[ ");
583 status = item->u.side_dynamic_vla_visitor.visitor(&tracer_ctx, app_ctx);
584 switch (status) {
585 case SIDE_VISITOR_STATUS_OK:
586 break;
587 case SIDE_VISITOR_STATUS_ERROR:
588 printf("ERROR: Visitor error\n");
589 abort();
590 }
591 printf(" ]");
592 }
593
594 static
595 void tracer_print_dynamic(const struct side_arg_dynamic_vec *item)
596 {
597 printf("{ ");
598 print_attributes("attr: ", item->attr, item->nr_attr);
599 printf("%s", item->nr_attr ? ", " : "");
600 printf("value: ");
601 switch (item->dynamic_type) {
602 case SIDE_DYNAMIC_TYPE_NULL:
603 printf("<NULL TYPE>");
604 break;
605 case SIDE_DYNAMIC_TYPE_BOOL:
606 printf("%s", item->u.side_bool ? "true" : "false");
607 break;
608 case SIDE_DYNAMIC_TYPE_U8:
609 printf("%" PRIu8, item->u.side_u8);
610 break;
611 case SIDE_DYNAMIC_TYPE_U16:
612 printf("%" PRIu16, item->u.side_u16);
613 break;
614 case SIDE_DYNAMIC_TYPE_U32:
615 printf("%" PRIu32, item->u.side_u32);
616 break;
617 case SIDE_DYNAMIC_TYPE_U64:
618 printf("%" PRIu64, item->u.side_u64);
619 break;
620 case SIDE_DYNAMIC_TYPE_S8:
621 printf("%" PRId8, item->u.side_s8);
622 break;
623 case SIDE_DYNAMIC_TYPE_S16:
624 printf("%" PRId16, item->u.side_s16);
625 break;
626 case SIDE_DYNAMIC_TYPE_S32:
627 printf("%" PRId32, item->u.side_s32);
628 break;
629 case SIDE_DYNAMIC_TYPE_S64:
630 printf("%" PRId64, item->u.side_s64);
631 break;
632 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16:
633 #if __HAVE_FLOAT16
634 printf("%g", (double) item->u.side_float_binary16);
635 break;
636 #else
637 printf("ERROR: Unsupported binary16 float type\n");
638 abort();
639 #endif
640 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32:
641 #if __HAVE_FLOAT32
642 printf("%g", (double) item->u.side_float_binary32);
643 break;
644 #else
645 printf("ERROR: Unsupported binary32 float type\n");
646 abort();
647 #endif
648 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64:
649 #if __HAVE_FLOAT64
650 printf("%g", (double) item->u.side_float_binary64);
651 break;
652 #else
653 printf("ERROR: Unsupported binary64 float type\n");
654 abort();
655 #endif
656 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128:
657 #if __HAVE_FLOAT128
658 printf("%Lg", (long double) item->u.side_float_binary128);
659 break;
660 #else
661 printf("ERROR: Unsupported binary128 float type\n");
662 abort();
663 #endif
664 case SIDE_DYNAMIC_TYPE_STRING:
665 printf("\"%s\"", item->u.string);
666 break;
667 case SIDE_DYNAMIC_TYPE_STRUCT:
668 tracer_print_dynamic_struct(item->u.side_dynamic_struct);
669 break;
670 case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR:
671 tracer_print_dynamic_struct_visitor(item);
672 break;
673 case SIDE_DYNAMIC_TYPE_VLA:
674 tracer_print_dynamic_vla(item->u.side_dynamic_vla);
675 break;
676 case SIDE_DYNAMIC_TYPE_VLA_VISITOR:
677 tracer_print_dynamic_vla_visitor(item);
678 break;
679 default:
680 printf("<UNKNOWN TYPE>");
681 abort();
682 }
683 printf(" }");
684 }
685
686 static
687 void tracer_print_static_fields(const struct side_event_description *desc,
688 const struct side_arg_vec_description *sav_desc,
689 int *nr_items)
690 {
691 const struct side_arg_vec *sav = sav_desc->sav;
692 uint32_t side_sav_len = sav_desc->len;
693 int i;
694
695 printf("provider: %s, event: %s", desc->provider_name, desc->event_name);
696 if (desc->nr_fields != side_sav_len) {
697 printf("ERROR: number of fields mismatch between description and arguments\n");
698 abort();
699 }
700 print_attributes(", attributes: ", desc->attr, desc->nr_attr);
701 printf("%s", side_sav_len ? ", fields: [ " : "");
702 for (i = 0; i < side_sav_len; i++) {
703 printf("%s", i ? ", " : "");
704 tracer_print_field(&desc->fields[i], &sav[i]);
705 }
706 if (nr_items)
707 *nr_items = i;
708 }
709
710 void tracer_call(const struct side_event_description *desc, const struct side_arg_vec_description *sav_desc)
711 {
712 int nr_fields = 0;
713
714 if (side_unlikely(desc->flags & SIDE_EVENT_FLAG_VARIADIC)) {
715 printf("ERROR: unexpected variadic event description\n");
716 abort();
717 }
718 tracer_print_static_fields(desc, sav_desc, &nr_fields);
719 if (nr_fields)
720 printf(" ]");
721 printf("\n");
722 }
723
724 void tracer_call_variadic(const struct side_event_description *desc,
725 const struct side_arg_vec_description *sav_desc,
726 const struct side_arg_dynamic_event_struct *var_struct)
727 {
728 uint32_t var_struct_len = var_struct->len;
729 int nr_fields = 0, i;
730
731 tracer_print_static_fields(desc, sav_desc, &nr_fields);
732
733 if (side_unlikely(!(desc->flags & SIDE_EVENT_FLAG_VARIADIC))) {
734 printf("ERROR: unexpected non-variadic event description\n");
735 abort();
736 }
737 printf("%s", var_struct_len && !nr_fields ? ", fields: [ " : "");
738 for (i = 0; i < var_struct_len; i++, nr_fields++) {
739 printf("%s", nr_fields ? ", " : "");
740 printf("%s:: ", var_struct->fields[i].field_name);
741 tracer_print_dynamic(&var_struct->fields[i].elem);
742 }
743 if (i)
744 printf(" ]");
745 printf("\n");
746 }
This page took 0.059461 seconds and 5 git commands to generate.