sink.ctf.fs: write bit array field classes and fields
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 13 Aug 2019 23:09:25 +0000 (19:09 -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 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 <eeppeliteloop@gmail.com>
Change-Id: I6375723d8513b06f984dc27f88d3d9b668191d21
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1911
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 9fcd3636c8aae13b563169791c632af63ca9423c..4789f0ffd2321577952c9759ef89cf7b039dff69 100644 (file)
@@ -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;
index ed516b1cb32c8e4bb8707831062604a5b10b9b8e..717571e0d2f3b903d0692ef295136680529cc21e 100644 (file)
@@ -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;
index 2fa7c0fdadfb84ed8eeea5eb47cc983d767b3dfa..399f3b3cfc6291b6146b053e5007003104e4d446 100644 (file)
@@ -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;
index 96455e7014ba7a4e76fd37b30f5f71ef08edbde8..535325d1e8c84b5821b2798022ac812bc4b0571f 100644 (file)
@@ -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:
This page took 0.037305 seconds and 4 git commands to generate.