text output
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 7 May 2011 00:07:15 +0000 (20:07 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 7 May 2011 00:07:15 +0000 (20:07 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 files changed:
configure.ac
formats/Makefile.am
formats/ctf-text/types/Makefile.am [new file with mode: 0644]
formats/ctf-text/types/array.c [new file with mode: 0644]
formats/ctf-text/types/enum.c [new file with mode: 0644]
formats/ctf-text/types/float.c [new file with mode: 0644]
formats/ctf-text/types/integer.c [new file with mode: 0644]
formats/ctf-text/types/sequence.c [new file with mode: 0644]
formats/ctf-text/types/string.c [new file with mode: 0644]
formats/ctf-text/types/struct.c [new file with mode: 0644]
formats/ctf-text/types/variant.c [new file with mode: 0644]
formats/ctf/ctf.c
include/babeltrace/ctf-text/types.h
include/babeltrace/ctf/types.h

index 64cea932174845f9c2e1dd250df7b9a33d5c27e7..bf9579c2605e0ae85a8e159c1af05a2f794a9df2 100644 (file)
@@ -54,6 +54,8 @@ AC_CONFIG_FILES([
        formats/Makefile
        formats/ctf/Makefile
        formats/ctf/types/Makefile
+       formats/ctf-text/Makefile
+       formats/ctf-text/types/Makefile
        formats/ctf/metadata/Makefile
        converter/Makefile
        tests/Makefile
index f56df7e2bb651898a914205a02b4070574e4f309..0bf5a74e88c9b287a8a5b17463bc46314fd4a874 100644 (file)
@@ -1,6 +1,6 @@
 AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
 
-SUBDIRS = . ctf
+SUBDIRS = . ctf ctf-text
 
 lib_LTLIBRARIES = libbabeltrace_registry.la
 
diff --git a/formats/ctf-text/types/Makefile.am b/formats/ctf-text/types/Makefile.am
new file mode 100644 (file)
index 0000000..604293e
--- /dev/null
@@ -0,0 +1,13 @@
+AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
+
+lib_LTLIBRARIES = libctf-text-types.la
+
+libctf_text_types_la_SOURCES = \
+       array.c \
+       enum.c \
+       float.c \
+       integer.c \
+       sequence.c \
+       string.c \
+       struct.c \
+       variant.c
diff --git a/formats/ctf-text/types/array.c b/formats/ctf-text/types/array.c
new file mode 100644 (file)
index 0000000..1b8d6be
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Common Trace Format
+ *
+ * Array format access functions.
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <babeltrace/ctf-text/types.h>
+#include <stdio.h>
+
+void ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
+{
+       struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+
+       if (!pos->dummy) {
+               print_pos_tabs(pos);
+               fprintf(pos->fp, "[\n");
+               pos->depth++;
+       }
+       array_rw(ppos, definition);
+       if (!pos->dummy) {
+               pos->depth--;
+               print_pos_tabs(pos);
+               fprintf(pos->fp, "]\n");
+       }
+}
diff --git a/formats/ctf-text/types/enum.c b/formats/ctf-text/types/enum.c
new file mode 100644 (file)
index 0000000..198f782
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Common Trace Format
+ *
+ * Enumeration mapping strings (quarks) from/to integers.
+ *
+ * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <babeltrace/ctf-text/types.h>
+#include <stdio.h>
+#include <stdint.h>
+
+void ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
+{
+       struct definition_enum *enum_definition =
+               container_of(definition, struct definition_enum, p);
+       struct definition_integer *integer_definition =
+               enum_definition->integer;
+       struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+       GArray *qs;
+       int i;
+
+       if (pos->dummy)
+               return;
+       print_pos_tabs(pos);
+       fprintf(pos->fp, "(");
+       pos->depth++;
+       generic_rw(ppos, &integer_definition->p);
+       print_pos_tabs(pos);
+
+       qs = enum_definition->value;
+       assert(qs);
+
+       for (i = 0; i < qs->len; i++) {
+               GQuark q = g_array_index(qs, GQuark, i);
+               const char *str = g_quark_to_string(q);
+               fprintf(pos->fp, "%s\n", str);
+       }
+       pos->depth--;
+       print_pos_tabs(pos);
+       fprintf(pos->fp, ")");
+}
diff --git a/formats/ctf-text/types/float.c b/formats/ctf-text/types/float.c
new file mode 100644 (file)
index 0000000..e96b4dd
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Common Trace Format
+ *
+ * Floating point read/write functions.
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * Reference: ISO C99 standard 5.2.4
+ */
+
+#include <babeltrace/ctf-text/types.h>
+#include <stdio.h>
+
+void ctf_text_float_write(struct stream_pos *ppos, struct definition *definition)
+{
+       struct definition_float *float_definition =
+               container_of(definition, struct definition_float, p);
+       struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+
+       if (pos->dummy)
+               return;
+       print_pos_tabs(pos);
+       fprintf(pos->fp, "%Lg\n", float_definition->value);
+}
diff --git a/formats/ctf-text/types/integer.c b/formats/ctf-text/types/integer.c
new file mode 100644 (file)
index 0000000..6abe9b5
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Common Trace Format
+ *
+ * Integers read/write functions.
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <babeltrace/ctf-text/types.h>
+#include <stdio.h>
+#include <inttypes.h>
+#include <stdint.h>
+
+void ctf_text_integer_write(struct stream_pos *ppos, struct definition *definition)
+{
+       struct definition_integer *integer_definition =
+               container_of(definition, struct definition_integer, p);
+       const struct declaration_integer *integer_declaration =
+               integer_definition->declaration;
+       struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+
+       if (pos->dummy)
+               return;
+       print_pos_tabs(pos);
+       if (!integer_declaration->signedness) {
+               fprintf(pos->fp, "%" PRIu64" (%" PRIX64 ")\n",
+                       integer_definition->value._unsigned,
+                       integer_definition->value._unsigned);
+       } else {
+               fprintf(pos->fp, "%" PRId64" (%" PRIX64 ")\n",
+                       integer_definition->value._signed,
+                       integer_definition->value._signed);
+       }
+}
diff --git a/formats/ctf-text/types/sequence.c b/formats/ctf-text/types/sequence.c
new file mode 100644 (file)
index 0000000..a0f8260
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Common Trace Format
+ *
+ * Sequence format access functions.
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <babeltrace/ctf-text/types.h>
+#include <stdio.h>
+
+void ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definition)
+{
+       struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+
+       if (!pos->dummy) {
+               print_pos_tabs(pos);
+               fprintf(pos->fp, "[\n");
+               pos->depth++;
+       }
+       sequence_rw(ppos, definition);
+       if (!pos->dummy) {
+               pos->depth--;
+               print_pos_tabs(pos);
+               fprintf(pos->fp, "]\n");
+       }
+}
diff --git a/formats/ctf-text/types/string.c b/formats/ctf-text/types/string.c
new file mode 100644 (file)
index 0000000..22103ce
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Common Trace Format
+ *
+ * Strings read/write functions.
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <babeltrace/ctf-text/types.h>
+#include <stdio.h>
+#include <limits.h>            /* C99 limits */
+#include <string.h>
+
+void ctf_text_string_write(struct stream_pos *ppos,
+                     struct definition *definition)
+{
+       struct definition_string *string_definition =
+               container_of(definition, struct definition_string, p);
+       struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+
+       assert(string_definition->value != NULL);
+       if (pos->dummy)
+               return;
+       print_pos_tabs(pos);
+       fprintf(pos->fp, "%s\n", string_definition->value);
+}
diff --git a/formats/ctf-text/types/struct.c b/formats/ctf-text/types/struct.c
new file mode 100644 (file)
index 0000000..20bc1a7
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Common Trace Format
+ *
+ * Structure format access functions.
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <babeltrace/ctf-text/types.h>
+#include <stdio.h>
+
+void ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition)
+{
+       struct declaration *declaration = definition->declaration;
+       struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+
+       if (!pos->dummy) {
+               print_pos_tabs(pos);
+               fprintf(pos->fp, "{\n");
+               pos->depth++;
+       }
+       struct_rw(ppos, definition);
+       if (!pos->dummy) {
+               pos->depth--;
+               print_pos_tabs(pos);
+               fprintf(pos->fp, "}\n");
+       }
+}
diff --git a/formats/ctf-text/types/variant.c b/formats/ctf-text/types/variant.c
new file mode 100644 (file)
index 0000000..5a9df0a
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Common Trace Format
+ *
+ * Variant format access functions.
+ *
+ * Copyright 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <babeltrace/ctf-text/types.h>
+#include <stdio.h>
+
+void ctf_text_variant_write(struct stream_pos *pos, struct definition *definition)
+{
+       variant_rw(pos, definition);
+}
index 1246569e3327662e5ddd2464e8f86eda96a3848f..a63eb60b496c1ca85c9b2621ec7a3985d9c4635d 100644 (file)
@@ -49,7 +49,8 @@ extern int yydebug;
 struct trace_descriptor *ctf_open_trace(const char *path, int flags);
 void ctf_close_trace(struct trace_descriptor *descriptor);
 
-static rw_dispatch read_dispatch_table[] = {
+static
+rw_dispatch read_dispatch_table[] = {
        [ CTF_TYPE_INTEGER ] = ctf_integer_read,
        [ CTF_TYPE_FLOAT ] = ctf_float_read,
        [ CTF_TYPE_ENUM ] = ctf_enum_read,
@@ -60,7 +61,8 @@ static rw_dispatch read_dispatch_table[] = {
        [ CTF_TYPE_SEQUENCE ] = ctf_sequence_rw,
 };
 
-static rw_dispatch write_dispatch_table[] = {
+static
+rw_dispatch write_dispatch_table[] = {
        [ CTF_TYPE_INTEGER ] = ctf_integer_write,
        [ CTF_TYPE_FLOAT ] = ctf_float_write,
        [ CTF_TYPE_ENUM ] = ctf_enum_write,
@@ -71,6 +73,7 @@ static rw_dispatch write_dispatch_table[] = {
        [ CTF_TYPE_SEQUENCE ] = ctf_sequence_rw,
 };
 
+static
 struct format ctf_format = {
        .open_trace = ctf_open_trace,
        .close_trace = ctf_close_trace,
index 1e48b93c6821fb1ba3ec9805bc4b16ef68be8fda..6a363a47a013ef7826b732737fa925f109940e82 100644 (file)
 #include <glib.h>
 #include <babeltrace/babeltrace.h>
 #include <babeltrace/types.h>
+#include <babeltrace/format.h>
 
+/*
+ * Inherit from both struct stream_pos and struct trace_descriptor.
+ */
 struct ctf_text_stream_pos {
-       struct trace_descriptor parent;
+       struct stream_pos parent;
+       struct trace_descriptor trace_descriptor;
        FILE *fp;               /* File pointer. NULL if unset. */
+       int depth;
+       int dummy;              /* disable output */
 };
 
+static inline
+struct ctf_text_stream_pos *ctf_text_pos(struct stream_pos *pos)
+{
+       return container_of(pos, struct ctf_text_stream_pos, parent);
+}
+
 /*
- * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
- *            *not* in bytes.
- *
- * All write primitives, as well as read for dynamically sized entities, can
- * receive a NULL ptr/dest parameter. In this case, no write is performed, but
- * the size is returned.
+ * Write only is supported for now.
  */
+void ctf_text_integer_write(struct stream_pos *pos, struct definition *definition);
+void ctf_text_float_write(struct stream_pos *pos, struct definition *definition);
+void ctf_text_string_write(struct stream_pos *pos, struct definition *definition);
+void ctf_text_enum_write(struct stream_pos *pos, struct definition *definition);
+void ctf_text_struct_write(struct stream_pos *pos, struct definition *definition);
+void ctf_text_variant_write(struct stream_pos *pos, struct definition *definition);
+void ctf_text_array_write(struct stream_pos *pos, struct definition *definition);
+void ctf_text_sequence_write(struct stream_pos *pos, struct definition *definition);
 
-void ctf_text_uint_write(struct stream_pos *pos,
-               const struct declaration_integer *integer_declaration,
-               uint64_t v);
-void ctf_text_int_write(struct stream_pos *pos,
-               const struct declaration_integer *integer_declaration,
-               int64_t v);
-
-void ctf_text_double_write(struct stream_pos *pos,
-               const struct declaration_float *dest,
-               double v);
-void ctf_text_ldouble_write(struct stream_pos *pos,
-               const struct declaration_float *dest,
-               long double v);
-
-void ctf_text_string_write(struct stream_pos *dest, const char *src,
-               const struct declaration_string *string_declaration);
+static inline
+void print_pos_tabs(struct ctf_text_stream_pos *pos)
+{
+       int i;
 
-void ctf_text_enum_write(struct stream_pos *pos,
-               const struct declaration_enum *dest,
-               GQuark q);
-void ctf_text_struct_begin(struct stream_pos *pos,
-               const struct declaration_struct *struct_declaration);
-void ctf_text_struct_end(struct stream_pos *pos,
-               const struct declaration_struct *struct_declaration);
-void ctf_text_variant_begin(struct stream_pos *pos,
-               const struct declaration_variant *variant_declaration);
-void ctf_text_variant_end(struct stream_pos *pos,
-               const struct declaration_variant *variant_declaration);
-void ctf_text_array_begin(struct stream_pos *pos,
-               const struct declaration_array *array_declaration);
-void ctf_text_array_end(struct stream_pos *pos,
-               const struct declaration_array *array_declaration);
-void ctf_text_sequence_begin(struct stream_pos *pos,
-               const struct declaration_sequence *sequence_declaration);
-void ctf_text_sequence_end(struct stream_pos *pos,
-               const struct declaration_sequence *sequence_declaration);
+       for (i = 0; i < pos->depth; i++)
+               fprintf(pos->fp, "\t");
+}
 
 #endif /* _BABELTRACE_CTF_TEXT_TYPES_H */
index 9a1a4d41c4569015a2bd7b6cb812f5ba4165ed4f..2396c4ff5b6f2261f5e8b7205be98944ad348c74 100644 (file)
@@ -63,15 +63,6 @@ struct ctf_stream_pos *ctf_pos(struct stream_pos *pos)
        return container_of(pos, struct ctf_stream_pos, parent);
 }
 
-/*
- * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
- *            *not* in bytes.
- *
- * All write primitives, as well as read for dynamically sized entities, can
- * receive a NULL ptr/dest parameter. In this case, no write is performed, but
- * the size is returned.
- */
-
 void ctf_integer_read(struct stream_pos *pos, struct definition *definition);
 void ctf_integer_write(struct stream_pos *pos, struct definition *definition);
 void ctf_float_read(struct stream_pos *pos, struct definition *definition);
This page took 0.047825 seconds and 4 git commands to generate.