From: Philippe Proulx Date: Sun, 11 Aug 2019 16:03:55 +0000 (-0400) Subject: sink.ctf.fs: write boolean field classes and fields X-Git-Tag: v2.0.0-rc1~280 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=dc9cc972b8dc1b63f637f1dcf78a662be29f5c11 sink.ctf.fs: write boolean field classes and fields This patch makes a `sink.ctf.fs` component handle boolean field classes and fields. Because CTF 1.8 has no boolean field class type, it makes a best effort and translates it to an 8-bit unsigned integer field class. A boolean field is written as an 8-bit unsigned integer field having the value 0 (false) or 1 (true). When a `src.ctf.fs` component reads a trace generated by `sink.ctf.fs` where the input trace IR contained boolean field classes, the 8-bit unsigned integer field classes will stay integer field classes; the source component has no way to determine if the metadata describes a boolean field class or a genuine 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 boolean field classes. Signed-off-by: Philippe Proulx Change-Id: I6be5967c2312bdb0e67be7db14ab663912872403 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1895 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 ff73eb5e..a96cbad8 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h +++ b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h @@ -26,6 +26,7 @@ #include enum fs_sink_ctf_field_class_type { + FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, FS_SINK_CTF_FIELD_CLASS_TYPE_INT, FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT, FS_SINK_CTF_FIELD_CLASS_TYPE_STRING, @@ -52,6 +53,10 @@ struct fs_sink_ctf_field_class_bit_array { unsigned int size; }; +struct fs_sink_ctf_field_class_bool { + struct fs_sink_ctf_field_class_bit_array base; +}; + struct fs_sink_ctf_field_class_int { struct fs_sink_ctf_field_class_bit_array base; bool is_signed; @@ -236,6 +241,25 @@ void _fs_sink_ctf_named_field_class_fini( named_fc->fc = NULL; } +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) +{ + struct fs_sink_ctf_field_class_bool *fc = + g_new0(struct fs_sink_ctf_field_class_bool, 1); + + BT_ASSERT(fc); + + /* + * CTF 1.8 has no boolean field class type, so this component + * translates it to an 8-bit unsigned integer field class. + */ + _fs_sink_ctf_field_class_bit_array_init((void *) fc, + FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, ir_fc, + 8, index_in_parent); + return fc; +} + static inline struct fs_sink_ctf_field_class_int *fs_sink_ctf_field_class_int_create( const bt_field_class *ir_fc, uint64_t index_in_parent) @@ -366,6 +390,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_bool_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_int_destroy( struct fs_sink_ctf_field_class_int *fc) @@ -490,6 +523,9 @@ void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc) } switch (fc->type) { + 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_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 a8bf2dc7..28f70e4f 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-stream.c +++ b/src/plugins/ctf/fs-sink/fs-sink-stream.c @@ -198,6 +198,20 @@ static int write_field(struct fs_sink_stream *stream, struct fs_sink_ctf_field_class *fc, const bt_field *field); +static inline +int write_bool_field(struct fs_sink_stream *stream, + struct fs_sink_ctf_field_class_int *fc, const bt_field *field) +{ + /* + * CTF 1.8 has no boolean field class type, so this component + * translates this boolean field to an 8-bit unsigned integer + * field which has the value 0 (false) or 1 (true). + */ + return bt_ctfser_write_unsigned_int(&stream->ctfser, + bt_field_bool_get_value(field) ? 1 : 0, + fc->base.base.alignment, fc->base.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) @@ -354,6 +368,9 @@ int write_field(struct fs_sink_stream *stream, int ret; switch (fc->type) { + case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL: + ret = write_bool_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 fd0d10f2..b21917ac 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 @@ -181,6 +181,20 @@ void append_end_block_semi_nl_nl(struct ctx *ctx) g_string_append_c(ctx->tsdl, '\n'); } +static +void append_bool_field_class(struct ctx *ctx, + __attribute__((unused)) struct fs_sink_ctf_field_class_bool *fc) +{ + /* + * CTF 1.8 has no boolean field class type, so this component + * translates it to an 8-bit unsigned integer field class. + */ + append_integer_field_class_from_props(ctx, fc->base.size, + fc->base.base.alignment, false, + BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL, + NULL, NULL, false); +} + static void append_integer_field_class(struct ctx *ctx, struct fs_sink_ctf_field_class_int *fc) @@ -424,6 +438,10 @@ void append_struct_field_class_members(struct ctx *ctx, g_string_append_printf(ctx->tsdl, " %s;\n", var_fc->tag_ref->str); } + } else if (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL) { + append_indent(ctx); + g_string_append(ctx->tsdl, + "/* The integer field class below was a trace IR boolean field class. */\n"); } append_indent(ctx); @@ -469,6 +487,9 @@ static void append_field_class(struct ctx *ctx, struct fs_sink_ctf_field_class *fc) { switch (fc->type) { + case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL: + append_bool_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 30f4552e..ce4ec6f0 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 @@ -1166,6 +1166,19 @@ end: return ret; } +static inline +int translate_bool_field_class(struct ctx *ctx) +{ + struct fs_sink_ctf_field_class_bool *fc = + fs_sink_ctf_field_class_bool_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) { @@ -1218,6 +1231,9 @@ int translate_field_class(struct ctx *ctx) int ret; switch (bt_field_class_get_type(cur_path_stack_top(ctx)->ir_fc)) { + case BT_FIELD_CLASS_TYPE_BOOL: + ret = translate_bool_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: