From d335f0f72a86c7cdcc18e524c74b82a51ad01b16 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 24 May 2011 10:09:06 -0400 Subject: [PATCH] Filter out redundant packet context fields unless in verbose mode Signed-off-by: Mathieu Desnoyers --- formats/ctf-text/ctf-text.c | 37 +++++++++++++++++++++++++++++ formats/ctf-text/types/array.c | 3 +++ formats/ctf-text/types/enum.c | 3 +++ formats/ctf-text/types/float.c | 3 +++ formats/ctf-text/types/integer.c | 3 +++ formats/ctf-text/types/sequence.c | 3 +++ formats/ctf-text/types/string.c | 4 ++++ formats/ctf-text/types/struct.c | 3 +++ formats/ctf-text/types/variant.c | 3 +++ include/babeltrace/ctf-text/types.h | 5 ++++ 10 files changed, 67 insertions(+) diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c index 0d551179..1500d735 100644 --- a/formats/ctf-text/ctf-text.c +++ b/formats/ctf-text/ctf-text.c @@ -53,6 +53,43 @@ struct format ctf_text_format = { .close_trace = ctf_text_close_trace, }; +static GQuark Q_STREAM_PACKET_CONTEXT_TIMESTAMP_BEGIN, + Q_STREAM_PACKET_CONTEXT_TIMESTAMP_END, + Q_STREAM_PACKET_CONTEXT_EVENTS_DISCARDED, + Q_STREAM_PACKET_CONTEXT_CONTENT_SIZE, + Q_STREAM_PACKET_CONTEXT_PACKET_SIZE; + +static +void __attribute__((constructor)) init_quarks(void) +{ + Q_STREAM_PACKET_CONTEXT_TIMESTAMP_BEGIN = g_quark_from_static_string("stream.packet.context.timestamp_begin"); + Q_STREAM_PACKET_CONTEXT_TIMESTAMP_END = g_quark_from_static_string("stream.packet.context.timestamp_end"); + Q_STREAM_PACKET_CONTEXT_EVENTS_DISCARDED = g_quark_from_static_string("stream.packet.context.events_discarded"); + Q_STREAM_PACKET_CONTEXT_CONTENT_SIZE = g_quark_from_static_string("stream.packet.context.content_size"); + Q_STREAM_PACKET_CONTEXT_PACKET_SIZE = g_quark_from_static_string("stream.packet.context.packet_size"); +} + +int print_field(struct definition *definition) +{ + /* Print all fields in verbose mode */ + if (babeltrace_verbose) + return 1; + + /* Filter out part of the packet context */ + if (definition->path == Q_STREAM_PACKET_CONTEXT_TIMESTAMP_BEGIN) + return 0; + if (definition->path == Q_STREAM_PACKET_CONTEXT_TIMESTAMP_END) + return 0; + if (definition->path == Q_STREAM_PACKET_CONTEXT_EVENTS_DISCARDED) + return 0; + if (definition->path == Q_STREAM_PACKET_CONTEXT_CONTENT_SIZE) + return 0; + if (definition->path == Q_STREAM_PACKET_CONTEXT_PACKET_SIZE) + return 0; + + return 1; +} + static int ctf_text_write_event(struct stream_pos *ppos, struct ctf_stream *stream) diff --git a/formats/ctf-text/types/array.c b/formats/ctf-text/types/array.c index db941426..1ee556a0 100644 --- a/formats/ctf-text/types/array.c +++ b/formats/ctf-text/types/array.c @@ -30,6 +30,9 @@ int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition) int field_nr_saved; int ret = 0; + if (!print_field(definition)) + return 0; + if (!pos->dummy) { if (pos->field_nr++ != 0) fprintf(pos->fp, ","); diff --git a/formats/ctf-text/types/enum.c b/formats/ctf-text/types/enum.c index 4a3eac0f..9043277d 100644 --- a/formats/ctf-text/types/enum.c +++ b/formats/ctf-text/types/enum.c @@ -31,6 +31,9 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition) int i, ret; int field_nr_saved; + if (!print_field(definition)) + return 0; + if (pos->dummy) return 0; diff --git a/formats/ctf-text/types/float.c b/formats/ctf-text/types/float.c index 2ec7728e..7fe4fe00 100644 --- a/formats/ctf-text/types/float.c +++ b/formats/ctf-text/types/float.c @@ -27,6 +27,9 @@ int ctf_text_float_write(struct stream_pos *ppos, struct definition *definition) container_of(definition, struct definition_float, p); struct ctf_text_stream_pos *pos = ctf_text_pos(ppos); + if (!print_field(definition)) + return 0; + if (pos->dummy) return 0; diff --git a/formats/ctf-text/types/integer.c b/formats/ctf-text/types/integer.c index 457ea804..30209d6b 100644 --- a/formats/ctf-text/types/integer.c +++ b/formats/ctf-text/types/integer.c @@ -30,6 +30,9 @@ int ctf_text_integer_write(struct stream_pos *ppos, struct definition *definitio integer_definition->declaration; struct ctf_text_stream_pos *pos = ctf_text_pos(ppos); + if (!print_field(definition)) + return 0; + if (pos->dummy) return 0; diff --git a/formats/ctf-text/types/sequence.c b/formats/ctf-text/types/sequence.c index a3982a21..cdf39308 100644 --- a/formats/ctf-text/types/sequence.c +++ b/formats/ctf-text/types/sequence.c @@ -30,6 +30,9 @@ int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definiti int field_nr_saved; int ret = 0; + if (!print_field(definition)) + return 0; + if (!pos->dummy) { if (pos->field_nr++ != 0) fprintf(pos->fp, ","); diff --git a/formats/ctf-text/types/string.c b/formats/ctf-text/types/string.c index eca5f91f..610d6db3 100644 --- a/formats/ctf-text/types/string.c +++ b/formats/ctf-text/types/string.c @@ -29,6 +29,10 @@ int ctf_text_string_write(struct stream_pos *ppos, struct ctf_text_stream_pos *pos = ctf_text_pos(ppos); assert(string_definition->value != NULL); + + if (!print_field(definition)) + return 0; + if (pos->dummy) return 0; diff --git a/formats/ctf-text/types/struct.c b/formats/ctf-text/types/struct.c index 3a69994f..cc36fde9 100644 --- a/formats/ctf-text/types/struct.c +++ b/formats/ctf-text/types/struct.c @@ -29,6 +29,9 @@ int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition int field_nr_saved; int ret; + if (!print_field(definition)) + return 0; + if (!pos->dummy) { if (pos->depth >= 0) { if (pos->field_nr++ != 0) diff --git a/formats/ctf-text/types/variant.c b/formats/ctf-text/types/variant.c index 50d21903..a21197aa 100644 --- a/formats/ctf-text/types/variant.c +++ b/formats/ctf-text/types/variant.c @@ -25,6 +25,9 @@ int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definitio int field_nr_saved; int ret; + if (!print_field(definition)) + return 0; + if (!pos->dummy) { if (pos->depth >= 0) { if (pos->field_nr++ != 0) diff --git a/include/babeltrace/ctf-text/types.h b/include/babeltrace/ctf-text/types.h index 7703e7b8..1b05523e 100644 --- a/include/babeltrace/ctf-text/types.h +++ b/include/babeltrace/ctf-text/types.h @@ -69,4 +69,9 @@ void print_pos_tabs(struct ctf_text_stream_pos *pos) fprintf(pos->fp, "\t"); } +/* + * Check if the field must be printed. + */ +int print_field(struct definition *definition); + #endif /* _BABELTRACE_CTF_TEXT_TYPES_H */ -- 2.34.1