From: Mathieu Desnoyers Date: Fri, 18 Mar 2016 19:52:18 +0000 (-0400) Subject: Implement variant type X-Git-Tag: v2.9.0-rc1~76 X-Git-Url: http://git.lttng.org/?p=lttng-modules.git;a=commitdiff_plain;h=65c85aa61984217039857513bbe988036f371693 Implement variant type Signed-off-by: Mathieu Desnoyers --- diff --git a/lttng-context.c b/lttng-context.c index 93373226..d299d5e2 100644 --- a/lttng-context.c +++ b/lttng-context.c @@ -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: diff --git a/lttng-events.c b/lttng-events.c index a5fe3e86..0c72015f 100644 --- a/lttng-events.c +++ b/lttng-events.c @@ -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); diff --git a/lttng-events.h b/lttng-events.h index 56f5d3ac..9d775d57 100644 --- a/lttng-events.h +++ b/lttng-events.h @@ -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; }; diff --git a/lttng-filter.c b/lttng-filter.c index 96ba1d23..36c6db90 100644 --- a/lttng-filter.c +++ b/lttng-filter.c @@ -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; }