From: Philippe Proulx Date: Tue, 13 Aug 2019 23:09:25 +0000 (-0400) Subject: sink.ctf.fs: write bit array field classes and fields X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=43a94dc939c1222729d90286b651c5ecc8d2f149 sink.ctf.fs: write bit array field classes and fields This patch makes a `sink.ctf.fs` component handle bit array field classes and fields. Because CTF 1.8 has no bit array field class type, it makes a best effort and translates it to an unsigned integer field class with a hexadecimal base. When a `src.ctf.fs` component reads a trace generated by `sink.ctf.fs` where the input trace IR contained bit array field classes, the corresponding unsigned integer field classes will stay unsigned integer field classes; the source component has no way to determine if the metadata describes a bit array field class or a genuine unsigned integer field class. However, the CTF 1.8 to CTF 1.8 scenario will always be unambiguous because a `src.ctf.fs` component never creates bit array field classes. Signed-off-by: Philippe Proulx Change-Id: I6375723d8513b06f984dc27f88d3d9b668191d21 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1911 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- diff --git a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h index 9fcd3636..4789f0ff 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h +++ b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h @@ -27,6 +27,7 @@ enum fs_sink_ctf_field_class_type { FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, + FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, FS_SINK_CTF_FIELD_CLASS_TYPE_INT, FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT, FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, @@ -248,6 +249,22 @@ void _fs_sink_ctf_named_field_class_fini( named_fc->fc = NULL; } +static inline +struct fs_sink_ctf_field_class_bit_array * +fs_sink_ctf_field_class_bit_array_create( + const bt_field_class *ir_fc, uint64_t index_in_parent) +{ + struct fs_sink_ctf_field_class_bit_array *fc = + g_new0(struct fs_sink_ctf_field_class_bit_array, 1); + + BT_ASSERT(fc); + _fs_sink_ctf_field_class_bit_array_init((void *) fc, + FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, ir_fc, + (unsigned int) bt_field_class_bit_array_get_length(ir_fc), + index_in_parent); + return fc; +} + static inline struct fs_sink_ctf_field_class_bool *fs_sink_ctf_field_class_bool_create( const bt_field_class *ir_fc, uint64_t index_in_parent) @@ -413,6 +430,15 @@ void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class *fc) BT_ASSERT(fc); } +static inline +void _fs_sink_ctf_field_class_bit_array_destroy( + struct fs_sink_ctf_field_class_int *fc) +{ + BT_ASSERT(fc); + _fs_sink_ctf_field_class_fini((void *) fc); + g_free(fc); +} + static inline void _fs_sink_ctf_field_class_bool_destroy( struct fs_sink_ctf_field_class_int *fc) @@ -565,6 +591,9 @@ void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc) case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL: _fs_sink_ctf_field_class_bool_destroy((void *) fc); break; + case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY: + _fs_sink_ctf_field_class_bit_array_destroy((void *) fc); + break; case FS_SINK_CTF_FIELD_CLASS_TYPE_INT: _fs_sink_ctf_field_class_int_destroy((void *) fc); break; diff --git a/src/plugins/ctf/fs-sink/fs-sink-stream.c b/src/plugins/ctf/fs-sink/fs-sink-stream.c index ed516b1c..717571e0 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-stream.c +++ b/src/plugins/ctf/fs-sink/fs-sink-stream.c @@ -212,6 +212,20 @@ int write_bool_field(struct fs_sink_stream *stream, fc->base.base.alignment, fc->base.size, BYTE_ORDER); } +static inline +int write_bit_array_field(struct fs_sink_stream *stream, + struct fs_sink_ctf_field_class_bit_array *fc, + const bt_field *field) +{ + /* + * CTF 1.8 has no bit array field class type, so this component + * translates this bit array field to an unsigned integer field. + */ + return bt_ctfser_write_unsigned_int(&stream->ctfser, + bt_field_bit_array_get_value_as_integer(field), + fc->base.alignment, fc->size, BYTE_ORDER); +} + static inline int write_int_field(struct fs_sink_stream *stream, struct fs_sink_ctf_field_class_int *fc, const bt_field *field) @@ -405,6 +419,9 @@ int write_field(struct fs_sink_stream *stream, case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL: ret = write_bool_field(stream, (void *) fc, field); break; + case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY: + ret = write_bit_array_field(stream, (void *) fc, field); + break; case FS_SINK_CTF_FIELD_CLASS_TYPE_INT: ret = write_int_field(stream, (void *) fc, field); break; diff --git a/src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c b/src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c index 2fa7c0fd..399f3b3c 100644 --- a/src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c +++ b/src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c @@ -195,6 +195,21 @@ void append_bool_field_class(struct ctx *ctx, NULL, NULL, false); } +static +void append_bit_array_field_class(struct ctx *ctx, + struct fs_sink_ctf_field_class_bit_array *fc) +{ + /* + * CTF 1.8 has no bit array field class type, so this component + * translates it to an unsigned integer field class with an + * hexadecimal base. + */ + append_integer_field_class_from_props(ctx, fc->size, + fc->base.alignment, false, + BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL, + NULL, NULL, false); +} + static void append_integer_field_class(struct ctx *ctx, struct fs_sink_ctf_field_class_int *fc) @@ -485,6 +500,10 @@ void append_struct_field_class_members(struct ctx *ctx, append_indent(ctx); g_string_append(ctx->tsdl, "/* The integer field class below was a trace IR boolean field class. */\n"); + } else if (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY) { + append_indent(ctx); + g_string_append(ctx->tsdl, + "/* The integer field class below was a trace IR bit array field class. */\n"); } append_indent(ctx); @@ -547,6 +566,9 @@ void append_field_class(struct ctx *ctx, struct fs_sink_ctf_field_class *fc) case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL: append_bool_field_class(ctx, (void *) fc); break; + case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY: + append_bit_array_field_class(ctx, (void *) fc); + break; case FS_SINK_CTF_FIELD_CLASS_TYPE_INT: append_integer_field_class(ctx, (void *) fc); break; diff --git a/src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c b/src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c index 96455e70..535325d1 100644 --- a/src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c +++ b/src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c @@ -1241,6 +1241,19 @@ int translate_bool_field_class(struct ctx *ctx) return 0; } +static inline +int translate_bit_array_field_class(struct ctx *ctx) +{ + struct fs_sink_ctf_field_class_bit_array *fc = + fs_sink_ctf_field_class_bit_array_create( + cur_path_stack_top(ctx)->ir_fc, + cur_path_stack_top(ctx)->index_in_parent); + + BT_ASSERT(fc); + append_to_parent_field_class(ctx, (void *) fc); + return 0; +} + static inline int translate_integer_field_class(struct ctx *ctx) { @@ -1296,6 +1309,9 @@ int translate_field_class(struct ctx *ctx) case BT_FIELD_CLASS_TYPE_BOOL: ret = translate_bool_field_class(ctx); break; + case BT_FIELD_CLASS_TYPE_BIT_ARRAY: + ret = translate_bit_array_field_class(ctx); + break; case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: