Implement variant type
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 18 Mar 2016 19:52:18 +0000 (15:52 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 2 May 2016 16:37:33 +0000 (12:37 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lttng-context.c
lttng-events.c
lttng-events.h
lttng-filter.c

index 933732266e9eb076ff26d0adefa1381a351b6399..d299d5e2e97412f90e05dec1e78295ebd01a2fd3 100644 (file)
@@ -144,6 +144,7 @@ void lttng_context_update(struct lttng_ctx *ctx)
                        case atype_struct:
                        case atype_array_compound:
                        case atype_sequence_compound:
+                       case atype_variant:
                        default:
                                WARN_ON_ONCE(1);
                                break;
@@ -166,6 +167,7 @@ void lttng_context_update(struct lttng_ctx *ctx)
                        case atype_struct:
                        case atype_array_compound:
                        case atype_sequence_compound:
+                       case atype_variant:
                        default:
                                WARN_ON_ONCE(1);
                                break;
@@ -187,6 +189,7 @@ void lttng_context_update(struct lttng_ctx *ctx)
                        case atype_struct:
                        case atype_array_compound:
                        case atype_sequence_compound:
+                       case atype_variant:
                        default:
                                WARN_ON_ONCE(1);
                                break;
@@ -199,6 +202,7 @@ void lttng_context_update(struct lttng_ctx *ctx)
                case atype_struct:
                case atype_array_compound:
                case atype_sequence_compound:
+               case atype_variant:
                        break;
 
                case atype_enum:
index a5fe3e865c4f9e16444917901ca1a1c4b906457f..0c72015fd1a56edc79f4ef9e4106c8aa3745c48c 100644 (file)
@@ -1736,6 +1736,62 @@ int _lttng_struct_statedump(struct lttng_session *session,
        return ret;
 }
 
+/*
+ * Must be called with sessions_mutex held.
+ */
+static
+int _lttng_variant_type_statedump(struct lttng_session *session,
+               const struct lttng_type *type,
+               size_t nesting)
+{
+       int ret;
+       uint32_t i, nr_choices;
+
+       ret = print_tabs(session, nesting);
+       if (ret)
+               return ret;
+       ret = lttng_metadata_printf(session,
+               "variant <_%s> {\n",
+               type->u.variant.tag_name);
+       if (ret)
+               return ret;
+       nr_choices = type->u.variant.nr_choices;
+       for (i = 0; i < nr_choices; i++) {
+               const struct lttng_event_field *iter_field;
+
+               iter_field = &type->u.variant.choices[i];
+               ret = _lttng_field_statedump(session, iter_field, nesting + 1);
+               if (ret)
+                       return ret;
+       }
+       ret = print_tabs(session, nesting);
+       if (ret)
+               return ret;
+       ret = lttng_metadata_printf(session,
+               "}");
+       return ret;
+}
+
+/*
+ * Must be called with sessions_mutex held.
+ */
+static
+int _lttng_variant_statedump(struct lttng_session *session,
+               const struct lttng_event_field *field,
+               size_t nesting)
+{
+       int ret;
+
+       ret = _lttng_variant_type_statedump(session,
+                       &field->type, nesting);
+       if (ret)
+               return ret;
+       ret = lttng_metadata_printf(session,
+               "_%s;\n",
+               field->name);
+       return ret;
+}
+
 /*
  * Must be called with sessions_mutex held.
  */
@@ -1747,7 +1803,7 @@ int _lttng_array_compound_statedump(struct lttng_session *session,
        int ret;
        const struct lttng_type *elem_type;
 
-       /* Only array of structures are currently supported. */
+       /* Only array of structures and variants are currently supported. */
        elem_type = field->type.u.array_compound.elem_type;
        switch (elem_type->atype) {
        case atype_struct:
@@ -1755,6 +1811,11 @@ int _lttng_array_compound_statedump(struct lttng_session *session,
                if (ret)
                        return ret;
                break;
+       case atype_variant:
+               ret = _lttng_variant_type_statedump(session, elem_type, nesting);
+               if (ret)
+                       return ret;
+               break;
        default:
                return -EINVAL;
        }
@@ -1779,7 +1840,7 @@ int _lttng_sequence_compound_statedump(struct lttng_session *session,
 
        length_name = field->type.u.sequence_compound.length_name;
 
-       /* Only array of structures are currently supported. */
+       /* Only array of structures and variants are currently supported. */
        elem_type = field->type.u.sequence_compound.elem_type;
        switch (elem_type->atype) {
        case atype_struct:
@@ -1787,6 +1848,11 @@ int _lttng_sequence_compound_statedump(struct lttng_session *session,
                if (ret)
                        return ret;
                break;
+       case atype_variant:
+               ret = _lttng_variant_type_statedump(session, elem_type, nesting);
+               if (ret)
+                       return ret;
+               break;
        default:
                return -EINVAL;
        }
@@ -1962,6 +2028,9 @@ int _lttng_field_statedump(struct lttng_session *session,
        case atype_sequence_compound:
                ret = _lttng_sequence_compound_statedump(session, field, nesting);
                break;
+       case atype_variant:
+               ret = _lttng_variant_statedump(session, field, nesting);
+               break;
 
        default:
                WARN_ON_ONCE(1);
index 56f5d3ac2a0670ac2ed4edfbc731e2aa6a8f5a59..9d775d5723d17d614547023c770ecc19ed0c8fbf 100644 (file)
@@ -52,6 +52,7 @@ enum abstract_types {
        atype_struct,
        atype_array_compound,           /* Array of compound types. */
        atype_sequence_compound,        /* Sequence of compound types. */
+       atype_variant,
        NR_ABSTRACT_TYPES,
 };
 
@@ -139,6 +140,11 @@ struct lttng_type {
                        struct lttng_type *elem_type;
                        const char *length_name;
                } sequence_compound;
+               struct {
+                       const char *tag_name;
+                       struct lttng_event_field *choices; /* Array of fields. */
+                       uint32_t nr_choices;
+               } variant;
        } u;
 };
 
index 96ba1d23fa497c9a51afc5ce0bad862691297d31..36c6db908227326599d158f9c48284edd07ae60c 100644 (file)
@@ -186,6 +186,7 @@ int apply_field_reloc(struct lttng_event *event,
                case atype_struct:              /* Unsupported. */
                case atype_array_compound:      /* Unsupported. */
                case atype_sequence_compound:   /* Unsupported. */
+               case atype_variant:             /* Unsupported. */
                default:
                        return -EINVAL;
                }
@@ -221,6 +222,7 @@ int apply_field_reloc(struct lttng_event *event,
        case atype_struct:              /* Unsupported. */
        case atype_array_compound:      /* Unsupported. */
        case atype_sequence_compound:   /* Unsupported. */
+       case atype_variant:             /* Unsupported. */
        default:
                return -EINVAL;
        }
@@ -271,6 +273,7 @@ int apply_context_reloc(struct lttng_event *event,
        case atype_struct:      /* Unsupported. */
        case atype_array_compound:      /* Unsupported. */
        case atype_sequence_compound:   /* Unsupported. */
+       case atype_variant:             /* Unsupported. */
        default:
                return -EINVAL;
        }
This page took 0.03139 seconds and 4 git commands to generate.