From: Mathieu Desnoyers Date: Sat, 7 May 2011 00:07:15 +0000 (-0400) Subject: text output X-Git-Tag: v0.1~98 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=1ae19169d9cb823765444d22cdb05cd2ed3f162f text output Signed-off-by: Mathieu Desnoyers --- diff --git a/configure.ac b/configure.ac index 64cea932..bf9579c2 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/formats/Makefile.am b/formats/Makefile.am index f56df7e2..0bf5a74e 100644 --- a/formats/Makefile.am +++ b/formats/Makefile.am @@ -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 index 00000000..604293e6 --- /dev/null +++ b/formats/ctf-text/types/Makefile.am @@ -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 index 00000000..1b8d6bee --- /dev/null +++ b/formats/ctf-text/types/array.c @@ -0,0 +1,37 @@ +/* + * Common Trace Format + * + * Array format access functions. + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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 +#include + +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 index 00000000..198f7829 --- /dev/null +++ b/formats/ctf-text/types/enum.c @@ -0,0 +1,52 @@ +/* + * Common Trace Format + * + * Enumeration mapping strings (quarks) from/to integers. + * + * Copyright 2010, 2011 - Mathieu Desnoyers + * + * 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 +#include +#include + +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 index 00000000..e96b4dd5 --- /dev/null +++ b/formats/ctf-text/types/float.c @@ -0,0 +1,34 @@ +/* + * Common Trace Format + * + * Floating point read/write functions. + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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 +#include + +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 index 00000000..6abe9b5e --- /dev/null +++ b/formats/ctf-text/types/integer.c @@ -0,0 +1,44 @@ +/* + * Common Trace Format + * + * Integers read/write functions. + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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 +#include +#include +#include + +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 index 00000000..a0f8260c --- /dev/null +++ b/formats/ctf-text/types/sequence.c @@ -0,0 +1,37 @@ +/* + * Common Trace Format + * + * Sequence format access functions. + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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 +#include + +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 index 00000000..22103ce8 --- /dev/null +++ b/formats/ctf-text/types/string.c @@ -0,0 +1,36 @@ +/* + * Common Trace Format + * + * Strings read/write functions. + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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 +#include +#include /* C99 limits */ +#include + +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 index 00000000..20bc1a7f --- /dev/null +++ b/formats/ctf-text/types/struct.c @@ -0,0 +1,38 @@ +/* + * Common Trace Format + * + * Structure format access functions. + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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 +#include + +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 index 00000000..5a9df0aa --- /dev/null +++ b/formats/ctf-text/types/variant.c @@ -0,0 +1,25 @@ +/* + * Common Trace Format + * + * Variant format access functions. + * + * Copyright 2011 - Mathieu Desnoyers + * + * 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 +#include + +void ctf_text_variant_write(struct stream_pos *pos, struct definition *definition) +{ + variant_rw(pos, definition); +} diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 1246569e..a63eb60b 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -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, diff --git a/include/babeltrace/ctf-text/types.h b/include/babeltrace/ctf-text/types.h index 1e48b93c..6a363a47 100644 --- a/include/babeltrace/ctf-text/types.h +++ b/include/babeltrace/ctf-text/types.h @@ -26,56 +26,44 @@ #include #include #include +#include +/* + * 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 */ diff --git a/include/babeltrace/ctf/types.h b/include/babeltrace/ctf/types.h index 9a1a4d41..2396c4ff 100644 --- a/include/babeltrace/ctf/types.h +++ b/include/babeltrace/ctf/types.h @@ -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);