sink.ctf.fs: write boolean field classes and fields
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sun, 11 Aug 2019 16:03:55 +0000 (12:03 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 15 Aug 2019 15:41:44 +0000 (11:41 -0400)
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 <eeppeliteloop@gmail.com>
Change-Id: I6be5967c2312bdb0e67be7db14ab663912872403
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1895
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h
src/plugins/ctf/fs-sink/fs-sink-stream.c
src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c
src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c

index ff73eb5e58bbc5f7817f093b9747571e7220c0e2..a96cbad8e5c30bedf4e53106be4394e8c1f9aaeb 100644 (file)
@@ -26,6 +26,7 @@
 #include <ctype.h>
 
 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;
index a8bf2dc73b848d8c93af460ae3d0daba184b198c..28f70e4f99d36a5c7a6b2b091afebc11d4fb4541 100644 (file)
@@ -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;
index fd0d10f243f13037b2591f9fe88093bda0615355..b21917ac3584c2b850dcf57f4a86eca45c5ba5b1 100644 (file)
@@ -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;
index 30f4552ef4a681da7e0402563d47c79ccb786f51..ce4ec6f09646657e37dbdbd1d317ba7ffcc01735 100644 (file)
@@ -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:
This page took 0.028793 seconds and 4 git commands to generate.