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
AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
-SUBDIRS = . ctf
+SUBDIRS = . ctf ctf-text
lib_LTLIBRARIES = libbabeltrace_registry.la
--- /dev/null
+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
--- /dev/null
+/*
+ * 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");
+ }
+}
--- /dev/null
+/*
+ * 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, ")");
+}
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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");
+ }
+}
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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");
+ }
+}
--- /dev/null
+/*
+ * 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);
+}
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,
[ 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,
[ CTF_TYPE_SEQUENCE ] = ctf_sequence_rw,
};
+static
struct format ctf_format = {
.open_trace = ctf_open_trace,
.close_trace = ctf_close_trace,
#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 */
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);