Implement nested scatter-gather struct
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 5 Nov 2022 00:51:15 +0000 (20:51 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 5 Nov 2022 00:51:15 +0000 (20:51 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/side/trace.h
src/test.c
src/tracer.c

index 4892d33e1208711fbca3d548ddeb45fb401a5692..8600a360d27c245d7aaabe9a3f177be0691a548e 100644 (file)
@@ -56,7 +56,6 @@ enum side_type_label {
 
        /* Statically declared compound types */
        SIDE_TYPE_STRUCT,
-       SIDE_TYPE_STRUCT_SG,
        SIDE_TYPE_ARRAY,
        SIDE_TYPE_VLA,
        SIDE_TYPE_VLA_VISITOR,
@@ -832,7 +831,7 @@ struct side_tracer_dynamic_vla_visitor_ctx {
 
 #define side_type_struct_sg(_struct_sg, _offset) \
        { \
-               .type = SIDE_TYPE_STRUCT_SG, \
+               .type = SIDE_TYPE_SG_STRUCT, \
                .u = { \
                        .side_sg = { \
                                .offset = _offset, \
@@ -923,7 +922,7 @@ struct side_tracer_dynamic_vla_visitor_ctx {
 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
 
 #define side_arg_struct(_side_type)    { .type = SIDE_TYPE_STRUCT, .u = { .side_static = { .side_struct = (_side_type) } } }
-#define side_arg_struct_sg(_ptr)       { .type = SIDE_TYPE_STRUCT_SG, .u = { .side_static = { .side_struct_sg_ptr = (_ptr) } } }
+#define side_arg_struct_sg(_ptr)       { .type = SIDE_TYPE_SG_STRUCT, .u = { .side_static = { .side_struct_sg_ptr = (_ptr) } } }
 #define side_arg_unsigned_integer_sg(_ptr)     { .type = SIDE_TYPE_SG_UNSIGNED_INT, .u = { .side_static = { .side_integer_sg_ptr = (_ptr) } } }
 #define side_arg_signed_integer_sg(_ptr)       { .type = SIDE_TYPE_SG_SIGNED_INT, .u = { .side_static = { .side_integer_sg_ptr = (_ptr) } } }
 #define side_arg_array(_side_type)     { .type = SIDE_TYPE_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
index 0808bd5effa85dc80919fbc2b20cae1c5c4b07de..b51bff921861ee983e9cac5fcc6c853ef5ba4857 100644 (file)
@@ -1543,6 +1543,82 @@ void test_struct_sg(void)
        }
 }
 
+struct testnest2 {
+       uint8_t c;
+};
+
+struct testnest1 {
+       uint64_t b;
+       struct testnest2 *nest;
+};
+
+struct testnest0 {
+       uint32_t a;
+       struct testnest1 *nest;
+};
+
+static side_define_struct(mystructsgnest2,
+       side_field_list(
+               side_field_sg_unsigned_integer("c", offsetof(struct testnest2, c),
+                       side_struct_field_sizeof_bit(struct testnest2, c), 0,
+                       side_struct_field_sizeof_bit(struct testnest2, c), side_attr_list()),
+       ),
+       side_attr_list()
+);
+
+static side_define_struct(mystructsgnest1,
+       side_field_list(
+               side_field_sg_unsigned_integer("b", offsetof(struct testnest1, b),
+                       side_struct_field_sizeof_bit(struct testnest1, b), 0,
+                       side_struct_field_sizeof_bit(struct testnest1, b), side_attr_list()),
+               side_field_struct_sg("nest2", &mystructsgnest2,
+                       offsetof(struct testnest1, nest)),
+       ),
+       side_attr_list()
+);
+
+static side_define_struct(mystructsgnest0,
+       side_field_list(
+               side_field_sg_unsigned_integer("a", offsetof(struct testnest0, a),
+                       side_struct_field_sizeof_bit(struct testnest0, a), 0,
+                       side_struct_field_sizeof_bit(struct testnest0, a), side_attr_list()),
+               side_field_struct_sg("nest1", &mystructsgnest1,
+                       offsetof(struct testnest0, nest)),
+       ),
+       side_attr_list()
+);
+
+side_static_event(my_provider_event_structsg_nest,
+       "myprovider", "myeventstructsgnest", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_struct_sg("nest0", &mystructsgnest0, 0),
+       ),
+       side_attr_list()
+);
+
+static
+void test_struct_sg_nest(void)
+{
+       side_event_cond(my_provider_event_structsg_nest) {
+               struct testnest2 mystruct2 = {
+                       .c = 77,
+               };
+               struct testnest1 mystruct1 = {
+                       .b = 66,
+                       .nest = &mystruct2,
+               };
+               struct testnest0 mystruct = {
+                       .a = 55,
+                       .nest = &mystruct1,
+               };
+               side_event_call(my_provider_event_structsg_nest,
+                       side_arg_list(
+                               side_arg_struct_sg(&mystruct),
+                       )
+               );
+       }
+}
+
 int main()
 {
        test_fields();
@@ -1584,5 +1660,6 @@ int main()
        test_endian();
        test_base();
        test_struct_sg();
+       test_struct_sg_nest();
        return 0;
 }
index 2a04018d880cefb0c737844d9d92f6af49026824..722f36c49c653f584bd2cc5f5b5715047c87efc8 100644 (file)
@@ -24,9 +24,9 @@ static struct side_tracer_handle *tracer_handle;
 static
 void tracer_print_struct(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec);
 static
-void tracer_print_sg_struct(const struct side_type_sg *type_sg, void *_ptr);
+void tracer_print_sg_struct(const struct side_type_sg *type_sg, const void *_ptr);
 static
-void tracer_print_sg_integer_type(const struct side_type_sg *type_sg, void *_ptr);
+void tracer_print_sg_integer_type(const struct side_type_sg *type_sg, const void *_ptr);
 static
 void tracer_print_array(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec);
 static
@@ -900,8 +900,8 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
        case SIDE_TYPE_STRUCT:
                tracer_print_struct(type_desc, item->u.side_static.side_struct);
                break;
-       case SIDE_TYPE_STRUCT_SG:
-               tracer_print_sg_struct(&type_desc->u.side_sg, item->u.side_static.side_struct_sg_ptr);
+       case SIDE_TYPE_SG_STRUCT:
+               tracer_print_sg_struct(&type_desc->u.side_sg, &item->u.side_static.side_struct_sg_ptr);
                break;
        case SIDE_TYPE_SG_UNSIGNED_INT:
        case SIDE_TYPE_SG_SIGNED_INT:
@@ -1004,7 +1004,7 @@ void tracer_print_struct(const struct side_type *type_desc, const struct side_ar
 }
 
 static
-void tracer_print_sg_integer_type(const struct side_type_sg *type_sg, void *_ptr)
+void tracer_print_sg_integer_type(const struct side_type_sg *type_sg, const void *_ptr)
 {
        const char *ptr = (const char *) _ptr;
        union side_integer_value value;
@@ -1050,17 +1050,18 @@ void tracer_print_sg_field(const struct side_event_field *field, void *ptr)
 }
 
 static
-void tracer_print_sg_struct(const struct side_type_sg *type_sg, void *_ptr)
+void tracer_print_sg_struct(const struct side_type_sg *type_sg, const void *_ptr)
 {
        char *ptr = (char *) _ptr;
        int i;
 
+       memcpy(&ptr, ptr + type_sg->offset, sizeof(ptr));
        print_attributes("attr", ":", type_sg->u.side_struct->attr, type_sg->u.side_struct->nr_attr);
        printf("%s", type_sg->u.side_struct->nr_attr ? ", " : "");
        printf("fields: { ");
        for (i = 0; i < type_sg->u.side_struct->nr_fields; i++) {
                printf("%s", i ? ", " : "");
-               tracer_print_sg_field(&type_sg->u.side_struct->fields[i], ptr + type_sg->offset);
+               tracer_print_sg_field(&type_sg->u.side_struct->fields[i], ptr);
        }
        printf(" }");
 }
This page took 0.026326 seconds and 4 git commands to generate.