CTF writer: restore native byte order is the CPU's native byte order
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 3 Apr 2017 22:05:19 +0000 (18:05 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:40 +0000 (12:57 -0400)
To remain compatible with the first experiments of CTF writer, let's
restore this legacy behaviour in which a native byte order means the
native byte order of the CPU running the Babeltrace library.

This only applies to bt_ctf_writer_set_byte_order() when you pass
BT_CTF_BYTE_ORDER_NATIVE: bt_ctf_trace_set_native_byte_order() does
not accept BT_CTF_BYTE_ORDER_NATIVE. Thus, when you create a CTF writer
object with bt_ctf_writer_create(), it sets its trace's native byte
order to the CPU's native byte order.

perf is a CTF writer user known to not call
bt_ctf_writer_set_byte_order() manually: in this case the CTF IR trace
would be invalid because its native byte order would still be set to
BT_CTF_BYTE_ORDER_NATIVE.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/endian.h
lib/ctf-writer/serialize.c
lib/ctf-writer/writer.c

index c5e5d7055f5ff8f1ebf4a3233d7f2a0d7d098c64..55f8d1ec0db346606e2b6a5b3ab243b26ce731b5 100644 (file)
 #endif /* __FLOAT_WORD_ORDER */
 #endif /* FLOAT_WORD_ORDER */
 
+#if (BYTE_ORDER == BIG_ENDIAN)
+# define BT_CTF_MY_BYTE_ORDER  BT_CTF_BYTE_ORDER_BIG_ENDIAN
+#else
+# define BT_CTF_MY_BYTE_ORDER  BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
+#endif
+
 #endif /* _BABELTRACE_ENDIAN_H */
index 6058dd354563b7644015ebd1de8f11ddd8546175..0e04229ff22bb7f6289c36736ffd5ea347642b7c 100644 (file)
 #include <babeltrace/compat/fcntl.h>
 #include <glib.h>
 
-/* "Native" to CTF IR byte order */
-#if (BYTE_ORDER == LITTLE_ENDIAN)
-# define MY_BT_CTF_BYTE_ORDER BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
-#else
-# define MY_BT_CTF_BYTE_ORDER BT_CTF_BYTE_ORDER_BIG_ENDIAN
-#endif
-
 #if (FLT_RADIX != 2)
 # error "Unsupported floating point radix"
 #endif
@@ -69,7 +62,7 @@ int aligned_integer_write(struct bt_ctf_stream_pos *pos,
                union intval value, unsigned int alignment, unsigned int size,
                bool is_signed, enum bt_ctf_byte_order byte_order)
 {
-       bool rbo = (byte_order != MY_BT_CTF_BYTE_ORDER); /* reverse byte order */
+       bool rbo = (byte_order != BT_CTF_MY_BYTE_ORDER); /* reverse byte order */
 
        if (!bt_ctf_stream_pos_align(pos, alignment))
                return -EFAULT;
index c822d63ffc8ff6738a9ed82e6c9263406377cf57..c0dbdbb0d5e2b12cfaea0228bc05bf6561d2440d 100644 (file)
@@ -35,6 +35,7 @@
 #include <babeltrace/ctf-ir/stream-internal.h>
 #include <babeltrace/ctf-ir/trace-internal.h>
 #include <babeltrace/ref.h>
+#include <babeltrace/endian.h>
 #include <babeltrace/compiler.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -49,6 +50,7 @@ void bt_ctf_writer_destroy(struct bt_object *obj);
 
 struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
 {
+       int ret;
        struct bt_ctf_writer *writer = NULL;
 
        if (!path) {
@@ -74,6 +76,11 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
        writer->trace->is_created_by_writer = 1;
        bt_object_set_parent(writer->trace, writer);
        bt_put(writer->trace);
+
+       /* Default to little-endian */
+       ret = bt_ctf_writer_set_byte_order(writer, BT_CTF_BYTE_ORDER_NATIVE);
+       assert(ret == 0);
+
        /* Create trace directory if necessary and open a metadata file */
        if (g_mkdir_with_parents(path, S_IRWXU | S_IRWXG)) {
                perror("g_mkdir_with_parents");
@@ -298,6 +305,10 @@ int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer,
                goto end;
        }
 
+       if (byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
+               byte_order = BT_CTF_MY_BYTE_ORDER;
+       }
+
        ret = bt_ctf_trace_set_native_byte_order(writer->trace,
                byte_order);
 end:
This page took 0.026944 seconds and 4 git commands to generate.