From 3228cc1db0ba3ff2b9007de3872fe61b66502493 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 4 Apr 2017 18:04:44 -0400 Subject: [PATCH] Rename text.text sink CC to text.pretty MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The `text` plugin is expected to contain more than the `text` sink: it could eventually read and write many plain text formats. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- configure.ac | 1 + plugins/text/Makefile.am | 18 +- plugins/text/plugin.c | 38 ++ plugins/text/pretty/Makefile.am | 14 + plugins/text/{text.c => pretty/pretty.c} | 329 +++++++------- plugins/text/{text.h => pretty/pretty.h} | 59 ++- plugins/text/{ => pretty}/print.c | 556 +++++++++++------------ 7 files changed, 536 insertions(+), 479 deletions(-) create mode 100644 plugins/text/plugin.c create mode 100644 plugins/text/pretty/Makefile.am rename plugins/text/{text.c => pretty/pretty.c} (65%) rename plugins/text/{text.h => pretty/pretty.h} (69%) rename plugins/text/{ => pretty}/print.c (68%) diff --git a/configure.ac b/configure.ac index 18335bd5..753a7778 100644 --- a/configure.ac +++ b/configure.ac @@ -499,6 +499,7 @@ AC_CONFIG_FILES([ plugins/ctf/lttng-live/Makefile plugins/muxer/Makefile plugins/text/Makefile + plugins/text/pretty/Makefile plugins/writer/Makefile plugins/utils/Makefile plugins/utils/dummy/Makefile diff --git a/plugins/text/Makefile.am b/plugins/text/Makefile.am index ecf82367..105742b6 100644 --- a/plugins/text/Makefile.am +++ b/plugins/text/Makefile.am @@ -1,19 +1,13 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/plugins -SUBDIRS = . +SUBDIRS = pretty . plugindir = "$(PLUGINSDIR)" -plugin_LTLIBRARIES = libbabeltrace-plugin-ctf-text.la +plugin_LTLIBRARIES = libbabeltrace-plugin-text.la -# ctf-text plugin -libbabeltrace_plugin_ctf_text_la_SOURCES = \ - text.c \ - print.c \ - text.h - -libbabeltrace_plugin_ctf_text_la_LDFLAGS = \ +libbabeltrace_plugin_text_la_SOURCES = plugin.c +libbabeltrace_plugin_text_la_LDFLAGS = \ -version-info $(BABELTRACE_LIBRARY_VERSION) - -libbabeltrace_plugin_ctf_text_la_LIBADD = \ +libbabeltrace_plugin_text_la_LIBADD = \ $(top_builddir)/lib/libbabeltrace.la \ - $(top_builddir)/common/libbabeltrace-common.la + pretty/libbabeltrace-plugin-text-pretty-cc.la diff --git a/plugins/text/plugin.c b/plugins/text/plugin.c new file mode 100644 index 00000000..a7691019 --- /dev/null +++ b/plugins/text/plugin.c @@ -0,0 +1,38 @@ +/* + * Copyright 2017 Philippe Proulx + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "pretty/pretty.h" + +BT_PLUGIN(text); +BT_PLUGIN_DESCRIPTION("Plain text component classes"); +BT_PLUGIN_AUTHOR("Julien Desfossez, Mathieu Desnoyers, Philippe Proulx"); +BT_PLUGIN_LICENSE("MIT"); + +/* pretty sink */ +BT_PLUGIN_SINK_COMPONENT_CLASS(pretty, pretty_consume); +BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(pretty, pretty_init); +BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD(pretty, pretty_finalize); +BT_PLUGIN_SINK_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD(pretty, + pretty_accept_port_connection); +BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(pretty, + "Pretty-printing text output (`text` format of Babeltrace 1)"); diff --git a/plugins/text/pretty/Makefile.am b/plugins/text/pretty/Makefile.am new file mode 100644 index 00000000..badc92a9 --- /dev/null +++ b/plugins/text/pretty/Makefile.am @@ -0,0 +1,14 @@ +AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/plugins + +SUBDIRS = . + +noinst_LTLIBRARIES = libbabeltrace-plugin-text-pretty-cc.la + +# ctf-text plugin +libbabeltrace_plugin_text_pretty_cc_la_SOURCES = \ + pretty.c \ + print.c \ + pretty.h + +libbabeltrace_plugin_text_pretty_cc_la_LIBADD = \ + $(top_builddir)/common/libbabeltrace-common.la diff --git a/plugins/text/text.c b/plugins/text/pretty/pretty.c similarity index 65% rename from plugins/text/text.c rename to plugins/text/pretty/pretty.c index bf7201d2..48a71472 100644 --- a/plugins/text/text.c +++ b/plugins/text/pretty/pretty.c @@ -1,5 +1,5 @@ /* - * text.c + * pretty.c * * Babeltrace CTF Text Output Plugin * @@ -45,9 +45,10 @@ #include #include #include -#include "text.h" #include +#include "pretty.h" + static const char *plugin_options[] = { "color", @@ -78,60 +79,60 @@ const char *plugin_options[] = { }; static -void destroy_text_data(struct text_component *text) +void destroy_pretty_data(struct pretty_component *pretty) { - bt_put(text->input_iterator); - (void) g_string_free(text->string, TRUE); - if (text->out != stdout) { + bt_put(pretty->input_iterator); + (void) g_string_free(pretty->string, TRUE); + if (pretty->out != stdout) { int ret; - ret = fclose(text->out); + ret = fclose(pretty->out); if (ret) { perror("close output file"); } } - g_free(text->options.output_path); - g_free(text->options.debug_info_dir); - g_free(text->options.debug_info_target_prefix); - g_free(text); + g_free(pretty->options.output_path); + g_free(pretty->options.debug_info_dir); + g_free(pretty->options.debug_info_target_prefix); + g_free(pretty); } static -struct text_component *create_text(void) +struct pretty_component *create_pretty(void) { - struct text_component *text; + struct pretty_component *pretty; - text = g_new0(struct text_component, 1); - if (!text) { + pretty = g_new0(struct pretty_component, 1); + if (!pretty) { goto end; } - text->string = g_string_new(""); - if (!text->string) { + pretty->string = g_string_new(""); + if (!pretty->string) { goto error; } end: - return text; + return pretty; error: - g_free(text); + g_free(pretty); return NULL; } -static -void finalize_text(struct bt_private_component *component) +BT_HIDDEN +void pretty_finalize(struct bt_private_component *component) { void *data = bt_private_component_get_user_data(component); - destroy_text_data(data); + destroy_pretty_data(data); } static -enum bt_component_status handle_notification(struct text_component *text, +enum bt_component_status handle_notification(struct pretty_component *pretty, struct bt_notification *notification) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - if (!text) { + if (!pretty) { ret = BT_COMPONENT_STATUS_ERROR; goto end; } @@ -150,7 +151,7 @@ enum bt_component_status handle_notification(struct text_component *text, ret = BT_COMPONENT_STATUS_ERROR; goto end; } - ret = text_print_event(text, event); + ret = pretty_print_event(pretty, event); bt_put(event); if (ret != BT_COMPONENT_STATUS_OK) { goto end; @@ -166,25 +167,25 @@ end: return ret; } -static -enum bt_component_status text_accept_port_connection( +BT_HIDDEN +enum bt_component_status pretty_accept_port_connection( struct bt_private_component *component, struct bt_private_port *self_port, struct bt_port *other_port) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_private_connection *connection; - struct text_component *text; + struct pretty_component *pretty; - text = bt_private_component_get_user_data(component); - assert(text); - assert(!text->input_iterator); + pretty = bt_private_component_get_user_data(component); + assert(pretty); + assert(!pretty->input_iterator); connection = bt_private_port_get_private_connection(self_port); assert(connection); - text->input_iterator = + pretty->input_iterator = bt_private_connection_create_notification_iterator(connection); - if (!text->input_iterator) { + if (!pretty->input_iterator) { ret = BT_COMPONENT_STATUS_ERROR; } @@ -192,17 +193,17 @@ enum bt_component_status text_accept_port_connection( return ret; } -static -enum bt_component_status run(struct bt_private_component *component) +BT_HIDDEN +enum bt_component_status pretty_consume(struct bt_private_component *component) { enum bt_component_status ret; struct bt_notification *notification = NULL; struct bt_notification_iterator *it; - struct text_component *text = + struct pretty_component *pretty = bt_private_component_get_user_data(component); enum bt_notification_iterator_status it_ret; - it = text->input_iterator; + it = pretty->input_iterator; it_ret = bt_notification_iterator_next(it); switch (it_ret) { @@ -211,7 +212,7 @@ enum bt_component_status run(struct bt_private_component *component) goto end; case BT_NOTIFICATION_ITERATOR_STATUS_END: ret = BT_COMPONENT_STATUS_END; - BT_PUT(text->input_iterator); + BT_PUT(pretty->input_iterator); goto end; default: break; @@ -219,8 +220,8 @@ enum bt_component_status run(struct bt_private_component *component) notification = bt_notification_iterator_get_notification(it); assert(notification); - ret = handle_notification(text, notification); - text->processed_first_event = true; + ret = handle_notification(pretty, notification); + pretty->processed_first_event = true; end: bt_put(notification); return ret; @@ -252,12 +253,12 @@ end: static bool check_param_exists(const char *key, struct bt_value *object, void *data) { - struct text_component *text = data; - struct bt_value *plugin_opt_map = text->plugin_opt_map; + struct pretty_component *pretty = data; + struct bt_value *plugin_opt_map = pretty->plugin_opt_map; if (!bt_value_map_get(plugin_opt_map, key)) { - fprintf(text->err, - "[warning] Parameter \"%s\" unknown to \"text\" plugin\n", key); + fprintf(pretty->err, + "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key); } return true; } @@ -324,23 +325,23 @@ end: } static -void warn_wrong_color_param(struct text_component *text) +void warn_wrong_color_param(struct pretty_component *pretty) { - fprintf(text->err, + fprintf(pretty->err, "[warning] Accepted values for the \"color\" parameter are:\n \"always\", \"auto\", \"never\"\n"); } static -enum bt_component_status open_output_file(struct text_component *text) +enum bt_component_status open_output_file(struct pretty_component *pretty) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - if (!text->options.output_path) { + if (!pretty->options.output_path) { goto end; } - text->out = fopen(text->options.output_path, "w"); - if (!text->out) { + pretty->out = fopen(pretty->options.output_path, "w"); + if (!pretty->out) { goto error; } @@ -353,7 +354,7 @@ end: } static -enum bt_component_status apply_params(struct text_component *text, +enum bt_component_status apply_params(struct pretty_component *pretty, struct bt_value *params) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -361,17 +362,17 @@ enum bt_component_status apply_params(struct text_component *text, bool value, found; char *str = NULL; - text->plugin_opt_map = bt_value_map_create(); - if (!text->plugin_opt_map) { + pretty->plugin_opt_map = bt_value_map_create(); + if (!pretty->plugin_opt_map) { ret = BT_COMPONENT_STATUS_ERROR; goto end; } - ret = add_params_to_map(text->plugin_opt_map); + ret = add_params_to_map(pretty->plugin_opt_map); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } /* Report unknown parameters. */ - status = bt_value_map_foreach(params, check_param_exists, text); + status = bt_value_map_foreach(params, check_param_exists, pretty); switch (status) { case BT_VALUE_STATUS_OK: break; @@ -380,7 +381,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } /* Known parameters. */ - text->options.color = TEXT_COLOR_OPT_AUTO; + pretty->options.color = PRETTY_COLOR_OPT_AUTO; if (bt_value_map_has_key(params, "color")) { struct bt_value *color_value; const char *color; @@ -392,16 +393,16 @@ enum bt_component_status apply_params(struct text_component *text, status = bt_value_string_get(color_value, &color); if (status) { - warn_wrong_color_param(text); + warn_wrong_color_param(pretty); } else { if (strcmp(color, "never") == 0) { - text->options.color = TEXT_COLOR_OPT_NEVER; + pretty->options.color = PRETTY_COLOR_OPT_NEVER; } else if (strcmp(color, "auto") == 0) { - text->options.color = TEXT_COLOR_OPT_AUTO; + pretty->options.color = PRETTY_COLOR_OPT_AUTO; } else if (strcmp(color, "always") == 0) { - text->options.color = TEXT_COLOR_OPT_ALWAYS; + pretty->options.color = PRETTY_COLOR_OPT_ALWAYS; } else { - warn_wrong_color_param(text); + warn_wrong_color_param(pretty); } } @@ -410,25 +411,25 @@ enum bt_component_status apply_params(struct text_component *text, ret = apply_one_string("output-path", params, - &text->options.output_path); + &pretty->options.output_path); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - ret = open_output_file(text); + ret = open_output_file(pretty); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } ret = apply_one_string("debug-info-dir", params, - &text->options.debug_info_dir); + &pretty->options.debug_info_dir); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } ret = apply_one_string("debug-info-target-prefix", params, - &text->options.debug_info_target_prefix); + &pretty->options.debug_info_target_prefix); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } @@ -438,49 +439,49 @@ enum bt_component_status apply_params(struct text_component *text, if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - text->options.debug_info_full_path = value; + pretty->options.debug_info_full_path = value; value = false; /* Default. */ ret = apply_one_bool("no-delta", params, &value, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - text->options.print_delta_field = !value; /* Reverse logic. */ + pretty->options.print_delta_field = !value; /* Reverse logic. */ value = false; /* Default. */ ret = apply_one_bool("clock-cycles", params, &value, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - text->options.print_timestamp_cycles = value; + pretty->options.print_timestamp_cycles = value; value = false; /* Default. */ ret = apply_one_bool("clock-seconds", params, &value, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - text->options.clock_seconds = value; + pretty->options.clock_seconds = value; value = false; /* Default. */ ret = apply_one_bool("clock-date", params, &value, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - text->options.clock_date = value; + pretty->options.clock_date = value; value = false; /* Default. */ ret = apply_one_bool("clock-gmt", params, &value, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - text->options.clock_gmt = value; + pretty->options.clock_gmt = value; value = false; /* Default. */ ret = apply_one_bool("verbose", params, &value, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - text->options.verbose = value; + pretty->options.verbose = value; /* Names. */ ret = apply_one_string("name-default", params, &str); @@ -488,11 +489,11 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (!str) { - text->options.name_default = TEXT_DEFAULT_UNSET; + pretty->options.name_default = PRETTY_DEFAULT_UNSET; } else if (!strcmp(str, "show")) { - text->options.name_default = TEXT_DEFAULT_SHOW; + pretty->options.name_default = PRETTY_DEFAULT_SHOW; } else if (!strcmp(str, "hide")) { - text->options.name_default = TEXT_DEFAULT_HIDE; + pretty->options.name_default = PRETTY_DEFAULT_HIDE; } else { ret = BT_COMPONENT_STATUS_ERROR; goto end; @@ -500,24 +501,24 @@ enum bt_component_status apply_params(struct text_component *text, g_free(str); str = NULL; - switch (text->options.name_default) { - case TEXT_DEFAULT_UNSET: - text->options.print_payload_field_names = true; - text->options.print_context_field_names = true; - text->options.print_header_field_names = false; - text->options.print_scope_field_names = false; + switch (pretty->options.name_default) { + case PRETTY_DEFAULT_UNSET: + pretty->options.print_payload_field_names = true; + pretty->options.print_context_field_names = true; + pretty->options.print_header_field_names = false; + pretty->options.print_scope_field_names = false; break; - case TEXT_DEFAULT_SHOW: - text->options.print_payload_field_names = true; - text->options.print_context_field_names = true; - text->options.print_header_field_names = true; - text->options.print_scope_field_names = true; + case PRETTY_DEFAULT_SHOW: + pretty->options.print_payload_field_names = true; + pretty->options.print_context_field_names = true; + pretty->options.print_header_field_names = true; + pretty->options.print_scope_field_names = true; break; - case TEXT_DEFAULT_HIDE: - text->options.print_payload_field_names = false; - text->options.print_context_field_names = false; - text->options.print_header_field_names = false; - text->options.print_scope_field_names = false; + case PRETTY_DEFAULT_HIDE: + pretty->options.print_payload_field_names = false; + pretty->options.print_context_field_names = false; + pretty->options.print_header_field_names = false; + pretty->options.print_scope_field_names = false; break; default: ret = BT_COMPONENT_STATUS_ERROR; @@ -531,7 +532,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_payload_field_names = value; + pretty->options.print_payload_field_names = value; } value = false; @@ -541,7 +542,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_context_field_names = value; + pretty->options.print_context_field_names = value; } value = false; @@ -551,7 +552,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_header_field_names = value; + pretty->options.print_header_field_names = value; } value = false; @@ -561,7 +562,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_scope_field_names = value; + pretty->options.print_scope_field_names = value; } /* Fields. */ @@ -570,11 +571,11 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (!str) { - text->options.field_default = TEXT_DEFAULT_UNSET; + pretty->options.field_default = PRETTY_DEFAULT_UNSET; } else if (!strcmp(str, "show")) { - text->options.field_default = TEXT_DEFAULT_SHOW; + pretty->options.field_default = PRETTY_DEFAULT_SHOW; } else if (!strcmp(str, "hide")) { - text->options.field_default = TEXT_DEFAULT_HIDE; + pretty->options.field_default = PRETTY_DEFAULT_HIDE; } else { ret = BT_COMPONENT_STATUS_ERROR; goto end; @@ -582,36 +583,36 @@ enum bt_component_status apply_params(struct text_component *text, g_free(str); str = NULL; - switch (text->options.field_default) { - case TEXT_DEFAULT_UNSET: - text->options.print_trace_field = false; - text->options.print_trace_hostname_field = true; - text->options.print_trace_domain_field = false; - text->options.print_trace_procname_field = true; - text->options.print_trace_vpid_field = true; - text->options.print_loglevel_field = false; - text->options.print_emf_field = false; - text->options.print_callsite_field = false; + switch (pretty->options.field_default) { + case PRETTY_DEFAULT_UNSET: + pretty->options.print_trace_field = false; + pretty->options.print_trace_hostname_field = true; + pretty->options.print_trace_domain_field = false; + pretty->options.print_trace_procname_field = true; + pretty->options.print_trace_vpid_field = true; + pretty->options.print_loglevel_field = false; + pretty->options.print_emf_field = false; + pretty->options.print_callsite_field = false; break; - case TEXT_DEFAULT_SHOW: - text->options.print_trace_field = true; - text->options.print_trace_hostname_field = true; - text->options.print_trace_domain_field = true; - text->options.print_trace_procname_field = true; - text->options.print_trace_vpid_field = true; - text->options.print_loglevel_field = true; - text->options.print_emf_field = true; - text->options.print_callsite_field = true; + case PRETTY_DEFAULT_SHOW: + pretty->options.print_trace_field = true; + pretty->options.print_trace_hostname_field = true; + pretty->options.print_trace_domain_field = true; + pretty->options.print_trace_procname_field = true; + pretty->options.print_trace_vpid_field = true; + pretty->options.print_loglevel_field = true; + pretty->options.print_emf_field = true; + pretty->options.print_callsite_field = true; break; - case TEXT_DEFAULT_HIDE: - text->options.print_trace_field = false; - text->options.print_trace_hostname_field = false; - text->options.print_trace_domain_field = false; - text->options.print_trace_procname_field = false; - text->options.print_trace_vpid_field = false; - text->options.print_loglevel_field = false; - text->options.print_emf_field = false; - text->options.print_callsite_field = false; + case PRETTY_DEFAULT_HIDE: + pretty->options.print_trace_field = false; + pretty->options.print_trace_hostname_field = false; + pretty->options.print_trace_domain_field = false; + pretty->options.print_trace_procname_field = false; + pretty->options.print_trace_vpid_field = false; + pretty->options.print_loglevel_field = false; + pretty->options.print_emf_field = false; + pretty->options.print_callsite_field = false; break; default: ret = BT_COMPONENT_STATUS_ERROR; @@ -625,7 +626,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_trace_field = value; + pretty->options.print_trace_field = value; } value = false; @@ -635,7 +636,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_trace_hostname_field = value; + pretty->options.print_trace_hostname_field = value; } value = false; @@ -645,7 +646,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_trace_domain_field = value; + pretty->options.print_trace_domain_field = value; } value = false; @@ -655,7 +656,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_trace_procname_field = value; + pretty->options.print_trace_procname_field = value; } value = false; @@ -665,7 +666,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_trace_vpid_field = value; + pretty->options.print_trace_vpid_field = value; } value = false; @@ -675,7 +676,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_loglevel_field = value; + pretty->options.print_loglevel_field = value; } value = false; @@ -685,7 +686,7 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_emf_field = value; + pretty->options.print_emf_field = value; } value = false; @@ -695,29 +696,29 @@ enum bt_component_status apply_params(struct text_component *text, goto end; } if (found) { - text->options.print_callsite_field = value; + pretty->options.print_callsite_field = value; } end: - bt_put(text->plugin_opt_map); - text->plugin_opt_map = NULL; + bt_put(pretty->plugin_opt_map); + pretty->plugin_opt_map = NULL; g_free(str); return ret; } static -void set_use_colors(struct text_component *text) +void set_use_colors(struct pretty_component *pretty) { - switch (text->options.color) { - case TEXT_COLOR_OPT_ALWAYS: - text->use_colors = true; + switch (pretty->options.color) { + case PRETTY_COLOR_OPT_ALWAYS: + pretty->use_colors = true; break; - case TEXT_COLOR_OPT_AUTO: - text->use_colors = text->out == stdout && + case PRETTY_COLOR_OPT_AUTO: + pretty->use_colors = pretty->out == stdout && bt_common_colors_supported(); break; - case TEXT_COLOR_OPT_NEVER: - text->use_colors = false; + case PRETTY_COLOR_OPT_NEVER: + pretty->use_colors = false; break; } } @@ -741,37 +742,37 @@ void init_stream_packet_context_quarks(void) g_quark_from_string("packet_seq_num"); } -static -enum bt_component_status text_component_init( +BT_HIDDEN +enum bt_component_status pretty_init( struct bt_private_component *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { enum bt_component_status ret; - struct text_component *text = create_text(); + struct pretty_component *pretty = create_pretty(); - if (!text) { + if (!pretty) { ret = BT_COMPONENT_STATUS_NOMEM; goto end; } - text->out = stdout; - text->err = stderr; + pretty->out = stdout; + pretty->err = stderr; - text->delta_cycles = -1ULL; - text->last_cycles_timestamp = -1ULL; + pretty->delta_cycles = -1ULL; + pretty->last_cycles_timestamp = -1ULL; - text->delta_real_timestamp = -1ULL; - text->last_real_timestamp = -1ULL; + pretty->delta_real_timestamp = -1ULL; + pretty->last_real_timestamp = -1ULL; - ret = apply_params(text, params); + ret = apply_params(pretty, params); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } - set_use_colors(text); + set_use_colors(pretty); - ret = bt_private_component_set_user_data(component, text); + ret = bt_private_component_set_user_data(component, pretty); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } @@ -781,18 +782,6 @@ enum bt_component_status text_component_init( end: return ret; error: - destroy_text_data(text); + destroy_pretty_data(pretty); return ret; } - -/* Initialize plug-in entry points. */ -BT_PLUGIN(text); -BT_PLUGIN_DESCRIPTION("Babeltrace text output plug-in."); -BT_PLUGIN_AUTHOR("Jérémie Galarneau"); -BT_PLUGIN_LICENSE("MIT"); -BT_PLUGIN_SINK_COMPONENT_CLASS(text, run); -BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(text, text_component_init); -BT_PLUGIN_SINK_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD(text, text_accept_port_connection); -BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD(text, finalize_text); -BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(text, - "Formats CTF-IR to text. Formerly known as ctf-text."); diff --git a/plugins/text/text.h b/plugins/text/pretty/pretty.h similarity index 69% rename from plugins/text/text.h rename to plugins/text/pretty/pretty.h index 222035e8..1eaf20c4 100644 --- a/plugins/text/text.h +++ b/plugins/text/pretty/pretty.h @@ -1,5 +1,5 @@ -#ifndef BABELTRACE_PLUGIN_TEXT_H -#define BABELTRACE_PLUGIN_TEXT_H +#ifndef BABELTRACE_PLUGIN_TEXT_PRETTY_PRETTY_H +#define BABELTRACE_PLUGIN_TEXT_PRETTY_PRETTY_H /* * BabelTrace - CTF Text Output Plug-in @@ -30,26 +30,29 @@ #include #include #include - -enum text_default { - TEXT_DEFAULT_UNSET, - TEXT_DEFAULT_SHOW, - TEXT_DEFAULT_HIDE, +#include +#include +#include + +enum pretty_default { + PRETTY_DEFAULT_UNSET, + PRETTY_DEFAULT_SHOW, + PRETTY_DEFAULT_HIDE, }; -enum text_color_option { - TEXT_COLOR_OPT_NEVER, - TEXT_COLOR_OPT_AUTO, - TEXT_COLOR_OPT_ALWAYS, +enum pretty_color_option { + PRETTY_COLOR_OPT_NEVER, + PRETTY_COLOR_OPT_AUTO, + PRETTY_COLOR_OPT_ALWAYS, }; -struct text_options { +struct pretty_options { char *output_path; char *debug_info_dir; char *debug_info_target_prefix; - enum text_default name_default; - enum text_default field_default; + enum pretty_default name_default; + enum pretty_default field_default; bool print_scope_field_names; bool print_header_field_names; @@ -71,12 +74,12 @@ struct text_options { bool clock_date; bool clock_gmt; bool debug_info_full_path; - enum text_color_option color; + enum pretty_color_option color; bool verbose; }; -struct text_component { - struct text_options options; +struct pretty_component { + struct pretty_options options; struct bt_notification_iterator *input_iterator; FILE *out, *err; bool processed_first_event; /* Should be per-iterator. */ @@ -106,7 +109,25 @@ enum stream_packet_context_quarks_enum { GQuark stream_packet_context_quarks[STREAM_PACKET_CONTEXT_QUARKS_LEN]; BT_HIDDEN -enum bt_component_status text_print_event(struct text_component *text, +enum bt_component_status pretty_init( + struct bt_private_component *component, + struct bt_value *params, + void *init_method_data); + +BT_HIDDEN +enum bt_component_status pretty_consume(struct bt_private_component *component); + +BT_HIDDEN +enum bt_component_status pretty_accept_port_connection( + struct bt_private_component *component, + struct bt_private_port *self_port, + struct bt_port *other_port); + +BT_HIDDEN +void pretty_finalize(struct bt_private_component *component); + +BT_HIDDEN +enum bt_component_status pretty_print_event(struct pretty_component *pretty, struct bt_ctf_event *event); -#endif /* BABELTRACE_PLUGIN_TEXT_H */ +#endif /* BABELTRACE_PLUGIN_TEXT_PRETTY_PRETTY_H */ diff --git a/plugins/text/print.c b/plugins/text/pretty/print.c similarity index 68% rename from plugins/text/print.c rename to plugins/text/pretty/print.c index 3634d068..77c42a08 100644 --- a/plugins/text/print.c +++ b/plugins/text/pretty/print.c @@ -40,7 +40,7 @@ #include #include #include -#include "text.h" +#include "pretty.h" #define NSEC_PER_SEC 1000000000LL @@ -69,33 +69,33 @@ struct timestamp { }; static -enum bt_component_status print_field(struct text_component *text, +enum bt_component_status print_field(struct pretty_component *pretty, struct bt_ctf_field *field, bool print_names, GQuark *filters_fields, int filter_array_len); static -void print_name_equal(struct text_component *text, const char *name) +void print_name_equal(struct pretty_component *pretty, const char *name) { - if (text->use_colors) { - fprintf(text->out, "%s%s%s = ", COLOR_NAME, name, COLOR_RST); + if (pretty->use_colors) { + fprintf(pretty->out, "%s%s%s = ", COLOR_NAME, name, COLOR_RST); } else { - fprintf(text->out, "%s = ", name); + fprintf(pretty->out, "%s = ", name); } } static -void print_field_name_equal(struct text_component *text, const char *name) +void print_field_name_equal(struct pretty_component *pretty, const char *name) { - if (text->use_colors) { - fprintf(text->out, "%s%s%s = ", COLOR_FIELD_NAME, name, + if (pretty->use_colors) { + fprintf(pretty->out, "%s%s%s = ", COLOR_FIELD_NAME, name, COLOR_RST); } else { - fprintf(text->out, "%s = ", name); + fprintf(pretty->out, "%s = ", name); } } static -void print_timestamp_cycles(struct text_component *text, +void print_timestamp_cycles(struct pretty_component *pretty, struct bt_ctf_clock_class *clock_class, struct bt_ctf_event *event) { @@ -105,26 +105,26 @@ void print_timestamp_cycles(struct text_component *text, clock_value = bt_ctf_event_get_clock_value(event, clock_class); if (!clock_value) { - fputs("????????????????????", text->out); + fputs("????????????????????", pretty->out); return; } ret = bt_ctf_clock_value_get_value(clock_value, &cycles); bt_put(clock_value); if (ret) { - fprintf(text->out, "Error"); + fprintf(pretty->out, "Error"); return; } - fprintf(text->out, "%020" PRIu64, cycles); + fprintf(pretty->out, "%020" PRIu64, cycles); - if (text->last_cycles_timestamp != -1ULL) { - text->delta_cycles = cycles - text->last_cycles_timestamp; + if (pretty->last_cycles_timestamp != -1ULL) { + pretty->delta_cycles = cycles - pretty->last_cycles_timestamp; } - text->last_cycles_timestamp = cycles; + pretty->last_cycles_timestamp = cycles; } static -void print_timestamp_wall(struct text_component *text, +void print_timestamp_wall(struct pretty_component *pretty, struct bt_ctf_clock_class *clock_class, struct bt_ctf_event *event) { @@ -137,21 +137,21 @@ void print_timestamp_wall(struct text_component *text, clock_value = bt_ctf_event_get_clock_value(event, clock_class); if (!clock_value) { - fputs("??:??:??.?????????", text->out); + fputs("??:??:??.?????????", pretty->out); return; } ret = bt_ctf_clock_value_get_value_ns_from_epoch(clock_value, &ts_nsec); bt_put(clock_value); if (ret) { - fprintf(text->out, "Error"); + fprintf(pretty->out, "Error"); return; } - if (text->last_real_timestamp != -1ULL) { - text->delta_real_timestamp = ts_nsec - text->last_real_timestamp; + if (pretty->last_real_timestamp != -1ULL) { + pretty->delta_real_timestamp = ts_nsec - pretty->last_real_timestamp; } - text->last_real_timestamp = ts_nsec; + pretty->last_real_timestamp = ts_nsec; ts_sec += ts_nsec / NSEC_PER_SEC; ts_nsec = ts_nsec % NSEC_PER_SEC; @@ -181,7 +181,7 @@ void print_timestamp_wall(struct text_component *text, ts_nsec_abs = -ts_nsec; } - if (!text->options.clock_seconds) { + if (!pretty->options.clock_seconds) { struct tm tm; time_t time_s = (time_t) ts_sec_abs; @@ -190,7 +190,7 @@ void print_timestamp_wall(struct text_component *text, goto seconds; } - if (!text->options.clock_gmt) { + if (!pretty->options.clock_gmt) { struct tm *res; res = localtime_r(&time_s, &tm); @@ -207,7 +207,7 @@ void print_timestamp_wall(struct text_component *text, goto seconds; } } - if (text->options.clock_date) { + if (pretty->options.clock_date) { char timestr[26]; size_t res; @@ -218,31 +218,31 @@ void print_timestamp_wall(struct text_component *text, fprintf(stderr, "[warning] Unable to print ascii time.\n"); goto seconds; } - fprintf(text->out, "%s", timestr); + fprintf(pretty->out, "%s", timestr); } /* Print time in HH:MM:SS.ns */ - fprintf(text->out, "%02d:%02d:%02d.%09" PRIu64, + fprintf(pretty->out, "%02d:%02d:%02d.%09" PRIu64, tm.tm_hour, tm.tm_min, tm.tm_sec, ts_nsec_abs); goto end; } seconds: - fprintf(text->out, "%s%" PRId64 ".%09" PRIu64, + fprintf(pretty->out, "%s%" PRId64 ".%09" PRIu64, is_negative ? "-" : "", ts_sec_abs, ts_nsec_abs); end: return; } static -enum bt_component_status print_event_timestamp(struct text_component *text, +enum bt_component_status print_event_timestamp(struct pretty_component *pretty, struct bt_ctf_event *event, bool *start_line) { - bool print_names = text->options.print_header_field_names; + bool print_names = pretty->options.print_header_field_names; enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_ctf_stream *stream = NULL; struct bt_ctf_stream_class *stream_class = NULL; struct bt_ctf_trace *trace = NULL; struct bt_ctf_clock_class *clock_class = NULL; - FILE *out = text->out; + FILE *out = pretty->out; stream = bt_ctf_event_get_stream(event); if (!stream) { @@ -267,53 +267,53 @@ enum bt_component_status print_event_timestamp(struct text_component *text, } if (print_names) { - print_name_equal(text, "timestamp"); + print_name_equal(pretty, "timestamp"); } else { fputs("[", out); } - if (text->use_colors) { - fputs(COLOR_TIMESTAMP, text->out); + if (pretty->use_colors) { + fputs(COLOR_TIMESTAMP, pretty->out); } - if (text->options.print_timestamp_cycles) { - print_timestamp_cycles(text, clock_class, event); + if (pretty->options.print_timestamp_cycles) { + print_timestamp_cycles(pretty, clock_class, event); } else { - print_timestamp_wall(text, clock_class, event); + print_timestamp_wall(pretty, clock_class, event); } - if (text->use_colors) { - fputs(COLOR_RST, text->out); + if (pretty->use_colors) { + fputs(COLOR_RST, pretty->out); } if (!print_names) fputs("] ", out); - if (text->options.print_delta_field) { + if (pretty->options.print_delta_field) { if (print_names) { - fputs(", ", text->out); - print_name_equal(text, "delta"); + fputs(", ", pretty->out); + print_name_equal(pretty, "delta"); } else { - fputs("(", text->out); + fputs("(", pretty->out); } - if (text->options.print_timestamp_cycles) { - if (text->delta_cycles == -1ULL) { - fputs("+??????????\?\?) ", text->out); /* Not a trigraph. */ + if (pretty->options.print_timestamp_cycles) { + if (pretty->delta_cycles == -1ULL) { + fputs("+??????????\?\?) ", pretty->out); /* Not a trigraph. */ } else { - fprintf(text->out, "+%012" PRIu64, text->delta_cycles); + fprintf(pretty->out, "+%012" PRIu64, pretty->delta_cycles); } } else { - if (text->delta_real_timestamp != -1ULL) { + if (pretty->delta_real_timestamp != -1ULL) { uint64_t delta_sec, delta_nsec, delta; - delta = text->delta_real_timestamp; + delta = pretty->delta_real_timestamp; delta_sec = delta / NSEC_PER_SEC; delta_nsec = delta % NSEC_PER_SEC; - fprintf(text->out, "+%" PRIu64 ".%09" PRIu64, + fprintf(pretty->out, "+%" PRIu64 ".%09" PRIu64, delta_sec, delta_nsec); } else { - fputs("+?.?????????", text->out); + fputs("+?.?????????", pretty->out); } } if (!print_names) { - fputs(") ", text->out); + fputs(") ", pretty->out); } } *start_line = !print_names; @@ -327,10 +327,10 @@ end: } static -enum bt_component_status print_event_header(struct text_component *text, +enum bt_component_status print_event_header(struct pretty_component *pretty, struct bt_ctf_event *event) { - bool print_names = text->options.print_header_field_names; + bool print_names = pretty->options.print_header_field_names; enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_ctf_event_class *event_class = NULL; struct bt_ctf_stream_class *stream_class = NULL; @@ -352,28 +352,28 @@ enum bt_component_status print_event_header(struct text_component *text, ret = BT_COMPONENT_STATUS_ERROR; goto end; } - ret = print_event_timestamp(text, event, &text->start_line); + ret = print_event_timestamp(pretty, event, &pretty->start_line); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - if (text->options.print_trace_field) { + if (pretty->options.print_trace_field) { const char *name; name = bt_ctf_trace_get_name(trace_class); if (name) { - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } if (print_names) { - print_name_equal(text, "trace"); + print_name_equal(pretty, "trace"); } - fprintf(text->out, "%s", name); + fprintf(pretty->out, "%s", name); if (!print_names) { - fprintf(text->out, " "); + fprintf(pretty->out, " "); } } } - if (text->options.print_trace_hostname_field) { + if (pretty->options.print_trace_hostname_field) { struct bt_value *hostname_str; hostname_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class, @@ -381,21 +381,21 @@ enum bt_component_status print_event_header(struct text_component *text, if (hostname_str) { const char *str; - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } if (print_names) { - print_name_equal(text, "trace:hostname"); + print_name_equal(pretty, "trace:hostname"); } if (bt_value_string_get(hostname_str, &str) == BT_VALUE_STATUS_OK) { - fprintf(text->out, "%s", str); + fprintf(pretty->out, "%s", str); } bt_put(hostname_str); dom_print = 1; } } - if (text->options.print_trace_domain_field) { + if (pretty->options.print_trace_domain_field) { struct bt_value *domain_str; domain_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class, @@ -403,23 +403,23 @@ enum bt_component_status print_event_header(struct text_component *text, if (domain_str) { const char *str; - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } if (print_names) { - print_name_equal(text, "trace:domain"); + print_name_equal(pretty, "trace:domain"); } else if (dom_print) { - fputs(":", text->out); + fputs(":", pretty->out); } if (bt_value_string_get(domain_str, &str) == BT_VALUE_STATUS_OK) { - fprintf(text->out, "%s", str); + fprintf(pretty->out, "%s", str); } bt_put(domain_str); dom_print = 1; } } - if (text->options.print_trace_procname_field) { + if (pretty->options.print_trace_procname_field) { struct bt_value *procname_str; procname_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class, @@ -427,23 +427,23 @@ enum bt_component_status print_event_header(struct text_component *text, if (procname_str) { const char *str; - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } if (print_names) { - print_name_equal(text, "trace:procname"); + print_name_equal(pretty, "trace:procname"); } else if (dom_print) { - fputs(":", text->out); + fputs(":", pretty->out); } if (bt_value_string_get(procname_str, &str) == BT_VALUE_STATUS_OK) { - fprintf(text->out, "%s", str); + fprintf(pretty->out, "%s", str); } bt_put(procname_str); dom_print = 1; } } - if (text->options.print_trace_vpid_field) { + if (pretty->options.print_trace_vpid_field) { struct bt_value *vpid_value; vpid_value = bt_ctf_trace_get_environment_field_value_by_name(trace_class, @@ -451,23 +451,23 @@ enum bt_component_status print_event_header(struct text_component *text, if (vpid_value) { int64_t value; - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } if (print_names) { - print_name_equal(text, "trace:vpid"); + print_name_equal(pretty, "trace:vpid"); } else if (dom_print) { - fputs(":", text->out); + fputs(":", pretty->out); } if (bt_value_integer_get(vpid_value, &value) == BT_VALUE_STATUS_OK) { - fprintf(text->out, "(%" PRId64 ")", value); + fprintf(pretty->out, "(%" PRId64 ")", value); } bt_put(vpid_value); dom_print = 1; } } - if (text->options.print_loglevel_field) { + if (pretty->options.print_loglevel_field) { struct bt_value *loglevel_str, *loglevel_value; loglevel_str = bt_ctf_event_class_get_attribute_value_by_name(event_class, @@ -477,20 +477,20 @@ enum bt_component_status print_event_header(struct text_component *text, if (loglevel_str || loglevel_value) { bool has_str = false; - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } if (print_names) { - print_name_equal(text, "loglevel"); + print_name_equal(pretty, "loglevel"); } else if (dom_print) { - fputs(":", text->out); + fputs(":", pretty->out); } if (loglevel_str) { const char *str; if (bt_value_string_get(loglevel_str, &str) == BT_VALUE_STATUS_OK) { - fprintf(text->out, "%s", str); + fprintf(pretty->out, "%s", str); has_str = true; } } @@ -499,7 +499,7 @@ enum bt_component_status print_event_header(struct text_component *text, if (bt_value_integer_get(loglevel_value, &value) == BT_VALUE_STATUS_OK) { - fprintf(text->out, "%s(%" PRId64 ")", + fprintf(pretty->out, "%s(%" PRId64 ")", has_str ? " " : "", value); } } @@ -508,26 +508,26 @@ enum bt_component_status print_event_header(struct text_component *text, dom_print = 1; } } - if (text->options.print_emf_field) { + if (pretty->options.print_emf_field) { struct bt_value *uri_str; uri_str = bt_ctf_event_class_get_attribute_value_by_name(event_class, "model.emf.uri"); if (uri_str) { - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } if (print_names) { - print_name_equal(text, "model.emf.uri"); + print_name_equal(pretty, "model.emf.uri"); } else if (dom_print) { - fputs(":", text->out); + fputs(":", pretty->out); } if (uri_str) { const char *str; if (bt_value_string_get(uri_str, &str) == BT_VALUE_STATUS_OK) { - fprintf(text->out, "%s", str); + fprintf(pretty->out, "%s", str); } } bt_put(uri_str); @@ -535,26 +535,26 @@ enum bt_component_status print_event_header(struct text_component *text, } } if (dom_print && !print_names) { - fputs(" ", text->out); + fputs(" ", pretty->out); } - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } - text->start_line = true; + pretty->start_line = true; if (print_names) { - print_name_equal(text, "name"); + print_name_equal(pretty, "name"); } - if (text->use_colors) { - fputs(COLOR_EVENT_NAME, text->out); + if (pretty->use_colors) { + fputs(COLOR_EVENT_NAME, pretty->out); } - fputs(bt_ctf_event_class_get_name(event_class), text->out); - if (text->use_colors) { - fputs(COLOR_RST, text->out); + fputs(bt_ctf_event_class_get_name(event_class), pretty->out); + if (pretty->use_colors) { + fputs(COLOR_RST, pretty->out); } if (!print_names) { - fputs(": ", text->out); + fputs(": ", pretty->out); } else { - fputs(", ", text->out); + fputs(", ", pretty->out); } end: bt_put(trace_class); @@ -564,7 +564,7 @@ end: } static -enum bt_component_status print_integer(struct text_component *text, +enum bt_component_status print_integer(struct pretty_component *pretty, struct bt_ctf_field *field) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -604,7 +604,7 @@ enum bt_component_status print_integer(struct text_component *text, switch (encoding) { case BT_CTF_STRING_ENCODING_UTF8: case BT_CTF_STRING_ENCODING_ASCII: - g_string_append_c(text->string, (int) v.u); + g_string_append_c(pretty->string, (int) v.u); goto end; case BT_CTF_STRING_ENCODING_NONE: case BT_CTF_STRING_ENCODING_UNKNOWN: @@ -614,8 +614,8 @@ enum bt_component_status print_integer(struct text_component *text, goto end; } - if (text->use_colors) { - fputs(COLOR_NUMBER_VALUE, text->out); + if (pretty->use_colors) { + fputs(COLOR_NUMBER_VALUE, pretty->out); rst_color = true; } @@ -630,10 +630,10 @@ enum bt_component_status print_integer(struct text_component *text, ret = BT_COMPONENT_STATUS_ERROR; goto end; } - fprintf(text->out, "0b"); + fprintf(pretty->out, "0b"); v.u = _bt_piecewise_lshift(v.u, 64 - len); for (bitnr = 0; bitnr < len; bitnr++) { - fprintf(text->out, "%u", (v.u & (1ULL << 63)) ? 1 : 0); + fprintf(pretty->out, "%u", (v.u & (1ULL << 63)) ? 1 : 0); v.u = _bt_piecewise_lshift(v.u, 1); } break; @@ -658,14 +658,14 @@ enum bt_component_status print_integer(struct text_component *text, } } - fprintf(text->out, "0%" PRIo64, v.u); + fprintf(pretty->out, "0%" PRIo64, v.u); break; } case BT_CTF_INTEGER_BASE_DECIMAL: if (!signedness) { - fprintf(text->out, "%" PRIu64, v.u); + fprintf(pretty->out, "%" PRIu64, v.u); } else { - fprintf(text->out, "%" PRId64, v.s); + fprintf(pretty->out, "%" PRId64, v.s); } break; case BT_CTF_INTEGER_BASE_HEXADECIMAL: @@ -684,7 +684,7 @@ enum bt_component_status print_integer(struct text_component *text, v.u &= ((uint64_t) 1 << rounded_len) - 1; } - fprintf(text->out, "0x%" PRIX64, v.u); + fprintf(pretty->out, "0x%" PRIX64, v.u); break; } default: @@ -693,80 +693,80 @@ enum bt_component_status print_integer(struct text_component *text, } end: if (rst_color) { - fputs(COLOR_RST, text->out); + fputs(COLOR_RST, pretty->out); } bt_put(field_type); return ret; } static -void print_escape_string(struct text_component *text, const char *str) +void print_escape_string(struct pretty_component *pretty, const char *str) { int i; - fputc('"', text->out); + fputc('"', pretty->out); for (i = 0; i < strlen(str); i++) { /* Escape sequences not recognized by iscntrl(). */ switch (str[i]) { case '\\': - fputs("\\\\", text->out); + fputs("\\\\", pretty->out); continue; case '\'': - fputs("\\\'", text->out); + fputs("\\\'", pretty->out); continue; case '\"': - fputs("\\\"", text->out); + fputs("\\\"", pretty->out); continue; case '\?': - fputs("\\\?", text->out); + fputs("\\\?", pretty->out); continue; } /* Standard characters. */ if (!iscntrl(str[i])) { - fputc(str[i], text->out); + fputc(str[i], pretty->out); continue; } switch (str[i]) { case '\0': - fputs("\\0", text->out); + fputs("\\0", pretty->out); break; case '\a': - fputs("\\a", text->out); + fputs("\\a", pretty->out); break; case '\b': - fputs("\\b", text->out); + fputs("\\b", pretty->out); break; case '\e': - fputs("\\e", text->out); + fputs("\\e", pretty->out); break; case '\f': - fputs("\\f", text->out); + fputs("\\f", pretty->out); break; case '\n': - fputs("\\n", text->out); + fputs("\\n", pretty->out); break; case '\r': - fputs("\\r", text->out); + fputs("\\r", pretty->out); break; case '\t': - fputs("\\t", text->out); + fputs("\\t", pretty->out); break; case '\v': - fputs("\\v", text->out); + fputs("\\v", pretty->out); break; default: /* Unhandled control-sequence, print as hex. */ - fprintf(text->out, "\\x%02x", str[i]); + fprintf(pretty->out, "\\x%02x", str[i]); break; } } - fputc('"', text->out); + fputc('"', pretty->out); } static -enum bt_component_status print_enum(struct text_component *text, +enum bt_component_status print_enum(struct pretty_component *pretty, struct bt_ctf_field *field) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -822,7 +822,7 @@ enum bt_component_status print_enum(struct text_component *text, ret = BT_COMPONENT_STATUS_ERROR; goto end; } - fprintf(text->out, "( "); + fprintf(pretty->out, "( "); for (;;) { const char *mapping_name; @@ -832,33 +832,33 @@ enum bt_component_status print_enum(struct text_component *text, goto end; } if (nr_mappings++) - fprintf(text->out, ", "); - if (text->use_colors) { - fputs(COLOR_ENUM_MAPPING_NAME, text->out); + fprintf(pretty->out, ", "); + if (pretty->use_colors) { + fputs(COLOR_ENUM_MAPPING_NAME, pretty->out); } - print_escape_string(text, mapping_name); - if (text->use_colors) { - fputs(COLOR_RST, text->out); + print_escape_string(pretty, mapping_name); + if (pretty->use_colors) { + fputs(COLOR_RST, pretty->out); } if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter) < 0) { break; } } if (!nr_mappings) { - if (text->use_colors) { - fputs(COLOR_UNKNOWN, text->out); + if (pretty->use_colors) { + fputs(COLOR_UNKNOWN, pretty->out); } - fprintf(text->out, ""); - if (text->use_colors) { - fputs(COLOR_RST, text->out); + fprintf(pretty->out, ""); + if (pretty->use_colors) { + fputs(COLOR_RST, pretty->out); } } - fprintf(text->out, " : container = "); - ret = print_integer(text, container_field); + fprintf(pretty->out, " : container = "); + ret = print_integer(pretty, container_field); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - fprintf(text->out, " )"); + fprintf(pretty->out, " )"); end: bt_put(iter); bt_put(container_field_type); @@ -868,13 +868,13 @@ end: } static -int filter_field_name(struct text_component *text, const char *field_name, +int filter_field_name(struct pretty_component *pretty, const char *field_name, GQuark *filter_fields, int filter_array_len) { int i; GQuark field_quark = g_quark_try_string(field_name); - if (!field_quark || text->options.verbose) { + if (!field_quark || pretty->options.verbose) { return 1; } @@ -887,7 +887,7 @@ int filter_field_name(struct text_component *text, const char *field_name, } static -enum bt_component_status print_struct_field(struct text_component *text, +enum bt_component_status print_struct_field(struct pretty_component *pretty, struct bt_ctf_field *_struct, struct bt_ctf_field_type *struct_type, int i, bool print_names, int *nr_printed_fields, @@ -909,21 +909,21 @@ enum bt_component_status print_struct_field(struct text_component *text, goto end; } - if (filter_fields && !filter_field_name(text, field_name, + if (filter_fields && !filter_field_name(pretty, field_name, filter_fields, filter_array_len)) { ret = BT_COMPONENT_STATUS_OK; goto end; } if (*nr_printed_fields > 0) { - fprintf(text->out, ", "); + fprintf(pretty->out, ", "); } else { - fprintf(text->out, " "); + fprintf(pretty->out, " "); } if (print_names) { - print_field_name_equal(text, rem_(field_name)); + print_field_name_equal(pretty, rem_(field_name)); } - ret = print_field(text, field, print_names, NULL, 0); + ret = print_field(pretty, field, print_names, NULL, 0); *nr_printed_fields += 1; end: bt_put(field_type); @@ -932,7 +932,7 @@ end: } static -enum bt_component_status print_struct(struct text_component *text, +enum bt_component_status print_struct(struct pretty_component *pretty, struct bt_ctf_field *_struct, bool print_names, GQuark *filter_fields, int filter_array_len) { @@ -950,26 +950,26 @@ enum bt_component_status print_struct(struct text_component *text, ret = BT_COMPONENT_STATUS_ERROR; goto end; } - fprintf(text->out, "{"); - text->depth++; + fprintf(pretty->out, "{"); + pretty->depth++; nr_printed_fields = 0; for (i = 0; i < nr_fields; i++) { - ret = print_struct_field(text, _struct, struct_type, i, + ret = print_struct_field(pretty, _struct, struct_type, i, print_names, &nr_printed_fields, filter_fields, filter_array_len); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } } - text->depth--; - fprintf(text->out, " }"); + pretty->depth--; + fprintf(pretty->out, " }"); end: bt_put(struct_type); return ret; } static -enum bt_component_status print_array_field(struct text_component *text, +enum bt_component_status print_array_field(struct pretty_component *pretty, struct bt_ctf_field *array, uint64_t i, bool is_string, bool print_names) { @@ -978,12 +978,12 @@ enum bt_component_status print_array_field(struct text_component *text, if (!is_string) { if (i != 0) { - fprintf(text->out, ", "); + fprintf(pretty->out, ", "); } else { - fprintf(text->out, " "); + fprintf(pretty->out, " "); } if (print_names) { - fprintf(text->out, "[%" PRIu64 "] = ", i); + fprintf(pretty->out, "[%" PRIu64 "] = ", i); } } field = bt_ctf_field_array_get_field(array, i); @@ -991,14 +991,14 @@ enum bt_component_status print_array_field(struct text_component *text, ret = BT_COMPONENT_STATUS_ERROR; goto end; } - ret = print_field(text, field, print_names, NULL, 0); + ret = print_field(pretty, field, print_names, NULL, 0); end: bt_put(field); return ret; } static -enum bt_component_status print_array(struct text_component *text, +enum bt_component_status print_array(struct pretty_component *pretty, struct bt_ctf_field *array, bool print_names) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -1048,30 +1048,30 @@ enum bt_component_status print_array(struct text_component *text, } if (is_string) { - g_string_assign(text->string, ""); + g_string_assign(pretty->string, ""); } else { - fprintf(text->out, "["); + fprintf(pretty->out, "["); } - text->depth++; + pretty->depth++; for (i = 0; i < len; i++) { - ret = print_array_field(text, array, i, is_string, print_names); + ret = print_array_field(pretty, array, i, is_string, print_names); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } } - text->depth--; + pretty->depth--; if (is_string) { - if (text->use_colors) { - fputs(COLOR_STRING_VALUE, text->out); + if (pretty->use_colors) { + fputs(COLOR_STRING_VALUE, pretty->out); } - print_escape_string(text, text->string->str); - if (text->use_colors) { - fputs(COLOR_RST, text->out); + print_escape_string(pretty, pretty->string->str); + if (pretty->use_colors) { + fputs(COLOR_RST, pretty->out); } } else { - fprintf(text->out, " ]"); + fprintf(pretty->out, " ]"); } end: bt_put(field_type); @@ -1080,7 +1080,7 @@ end: } static -enum bt_component_status print_sequence_field(struct text_component *text, +enum bt_component_status print_sequence_field(struct pretty_component *pretty, struct bt_ctf_field *seq, uint64_t i, bool is_string, bool print_names) { @@ -1089,12 +1089,12 @@ enum bt_component_status print_sequence_field(struct text_component *text, if (!is_string) { if (i != 0) { - fprintf(text->out, ", "); + fprintf(pretty->out, ", "); } else { - fprintf(text->out, " "); + fprintf(pretty->out, " "); } if (print_names) { - fprintf(text->out, "[%" PRIu64 "] = ", i); + fprintf(pretty->out, "[%" PRIu64 "] = ", i); } } field = bt_ctf_field_sequence_get_field(seq, i); @@ -1102,14 +1102,14 @@ enum bt_component_status print_sequence_field(struct text_component *text, ret = BT_COMPONENT_STATUS_ERROR; goto end; } - ret = print_field(text, field, print_names, NULL, 0); + ret = print_field(pretty, field, print_names, NULL, 0); end: bt_put(field); return ret; } static -enum bt_component_status print_sequence(struct text_component *text, +enum bt_component_status print_sequence(struct pretty_component *pretty, struct bt_ctf_field *seq, bool print_names) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -1166,31 +1166,31 @@ enum bt_component_status print_sequence(struct text_component *text, } if (is_string) { - g_string_assign(text->string, ""); + g_string_assign(pretty->string, ""); } else { - fprintf(text->out, "["); + fprintf(pretty->out, "["); } - text->depth++; + pretty->depth++; for (i = 0; i < len; i++) { - ret = print_sequence_field(text, seq, i, + ret = print_sequence_field(pretty, seq, i, is_string, print_names); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } } - text->depth--; + pretty->depth--; if (is_string) { - if (text->use_colors) { - fputs(COLOR_STRING_VALUE, text->out); + if (pretty->use_colors) { + fputs(COLOR_STRING_VALUE, pretty->out); } - print_escape_string(text, text->string->str); - if (text->use_colors) { - fputs(COLOR_RST, text->out); + print_escape_string(pretty, pretty->string->str); + if (pretty->use_colors) { + fputs(COLOR_RST, pretty->out); } } else { - fprintf(text->out, " ]"); + fprintf(pretty->out, " ]"); } end: bt_put(length_field); @@ -1200,7 +1200,7 @@ end: } static -enum bt_component_status print_variant(struct text_component *text, +enum bt_component_status print_variant(struct pretty_component *pretty, struct bt_ctf_field *variant, bool print_names) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -1211,8 +1211,8 @@ enum bt_component_status print_variant(struct text_component *text, ret = BT_COMPONENT_STATUS_ERROR; goto end; } - fprintf(text->out, "{ "); - text->depth++; + fprintf(pretty->out, "{ "); + pretty->depth++; if (print_names) { int iter_ret; struct bt_ctf_field *tag_field = NULL; @@ -1241,23 +1241,23 @@ enum bt_component_status print_variant(struct text_component *text, ret = BT_COMPONENT_STATUS_ERROR; goto end; } - print_field_name_equal(text, rem_(tag_choice)); + print_field_name_equal(pretty, rem_(tag_choice)); bt_put(tag_field); bt_put(iter); } - ret = print_field(text, field, print_names, NULL, 0); + ret = print_field(pretty, field, print_names, NULL, 0); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - text->depth--; - fprintf(text->out, " }"); + pretty->depth--; + fprintf(pretty->out, " }"); end: bt_put(field); return ret; } static -enum bt_component_status print_field(struct text_component *text, +enum bt_component_status print_field(struct pretty_component *pretty, struct bt_ctf_field *field, bool print_names, GQuark *filter_fields, int filter_array_len) { @@ -1266,7 +1266,7 @@ enum bt_component_status print_field(struct text_component *text, type_id = bt_ctf_field_get_type_id(field); switch (type_id) { case CTF_TYPE_INTEGER: - return print_integer(text, field); + return print_integer(pretty, field); case CTF_TYPE_FLOAT: { double v; @@ -1274,44 +1274,44 @@ enum bt_component_status print_field(struct text_component *text, if (bt_ctf_field_floating_point_get_value(field, &v)) { return BT_COMPONENT_STATUS_ERROR; } - if (text->use_colors) { - fputs(COLOR_NUMBER_VALUE, text->out); + if (pretty->use_colors) { + fputs(COLOR_NUMBER_VALUE, pretty->out); } - fprintf(text->out, "%g", v); - if (text->use_colors) { - fputs(COLOR_RST, text->out); + fprintf(pretty->out, "%g", v); + if (pretty->use_colors) { + fputs(COLOR_RST, pretty->out); } return BT_COMPONENT_STATUS_OK; } case CTF_TYPE_ENUM: - return print_enum(text, field); + return print_enum(pretty, field); case CTF_TYPE_STRING: - if (text->use_colors) { - fputs(COLOR_STRING_VALUE, text->out); + if (pretty->use_colors) { + fputs(COLOR_STRING_VALUE, pretty->out); } - print_escape_string(text, bt_ctf_field_string_get_value(field)); - if (text->use_colors) { - fputs(COLOR_RST, text->out); + print_escape_string(pretty, bt_ctf_field_string_get_value(field)); + if (pretty->use_colors) { + fputs(COLOR_RST, pretty->out); } return BT_COMPONENT_STATUS_OK; case CTF_TYPE_STRUCT: - return print_struct(text, field, print_names, filter_fields, + return print_struct(pretty, field, print_names, filter_fields, filter_array_len); case CTF_TYPE_UNTAGGED_VARIANT: case CTF_TYPE_VARIANT: - return print_variant(text, field, print_names); + return print_variant(pretty, field, print_names); case CTF_TYPE_ARRAY: - return print_array(text, field, print_names); + return print_array(pretty, field, print_names); case CTF_TYPE_SEQUENCE: - return print_sequence(text, field, print_names); + return print_sequence(pretty, field, print_names); default: - fprintf(text->err, "[error] Unknown type id: %d\n", (int) type_id); + fprintf(pretty->err, "[error] Unknown type id: %d\n", (int) type_id); return BT_COMPONENT_STATUS_ERROR; } } static -enum bt_component_status print_stream_packet_context(struct text_component *text, +enum bt_component_status print_stream_packet_context(struct pretty_component *pretty, struct bt_ctf_event *event) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -1327,15 +1327,15 @@ enum bt_component_status print_stream_packet_context(struct text_component *text if (!main_field) { goto end; } - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } - text->start_line = false; - if (text->options.print_scope_field_names) { - print_name_equal(text, "stream.packet.context"); + pretty->start_line = false; + if (pretty->options.print_scope_field_names) { + print_name_equal(pretty, "stream.packet.context"); } - ret = print_field(text, main_field, - text->options.print_context_field_names, + ret = print_field(pretty, main_field, + pretty->options.print_context_field_names, stream_packet_context_quarks, STREAM_PACKET_CONTEXT_QUARKS_LEN); end: @@ -1345,7 +1345,7 @@ end: } static -enum bt_component_status print_event_header_raw(struct text_component *text, +enum bt_component_status print_event_header_raw(struct pretty_component *pretty, struct bt_ctf_event *event) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -1355,22 +1355,22 @@ enum bt_component_status print_event_header_raw(struct text_component *text, if (!main_field) { goto end; } - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } - text->start_line = false; - if (text->options.print_scope_field_names) { - print_name_equal(text, "stream.event.header"); + pretty->start_line = false; + if (pretty->options.print_scope_field_names) { + print_name_equal(pretty, "stream.event.header"); } - ret = print_field(text, main_field, - text->options.print_header_field_names, NULL, 0); + ret = print_field(pretty, main_field, + pretty->options.print_header_field_names, NULL, 0); end: bt_put(main_field); return ret; } static -enum bt_component_status print_stream_event_context(struct text_component *text, +enum bt_component_status print_stream_event_context(struct pretty_component *pretty, struct bt_ctf_event *event) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -1380,22 +1380,22 @@ enum bt_component_status print_stream_event_context(struct text_component *text, if (!main_field) { goto end; } - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } - text->start_line = false; - if (text->options.print_scope_field_names) { - print_name_equal(text, "stream.event.context"); + pretty->start_line = false; + if (pretty->options.print_scope_field_names) { + print_name_equal(pretty, "stream.event.context"); } - ret = print_field(text, main_field, - text->options.print_context_field_names, NULL, 0); + ret = print_field(pretty, main_field, + pretty->options.print_context_field_names, NULL, 0); end: bt_put(main_field); return ret; } static -enum bt_component_status print_event_context(struct text_component *text, +enum bt_component_status print_event_context(struct pretty_component *pretty, struct bt_ctf_event *event) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -1405,22 +1405,22 @@ enum bt_component_status print_event_context(struct text_component *text, if (!main_field) { goto end; } - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } - text->start_line = false; - if (text->options.print_scope_field_names) { - print_name_equal(text, "event.context"); + pretty->start_line = false; + if (pretty->options.print_scope_field_names) { + print_name_equal(pretty, "event.context"); } - ret = print_field(text, main_field, - text->options.print_context_field_names, NULL, 0); + ret = print_field(pretty, main_field, + pretty->options.print_context_field_names, NULL, 0); end: bt_put(main_field); return ret; } static -enum bt_component_status print_event_payload(struct text_component *text, +enum bt_component_status print_event_payload(struct pretty_component *pretty, struct bt_ctf_event *event) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -1430,60 +1430,60 @@ enum bt_component_status print_event_payload(struct text_component *text, if (!main_field) { goto end; } - if (!text->start_line) { - fputs(", ", text->out); + if (!pretty->start_line) { + fputs(", ", pretty->out); } - text->start_line = false; - if (text->options.print_scope_field_names) { - print_name_equal(text, "event.fields"); + pretty->start_line = false; + if (pretty->options.print_scope_field_names) { + print_name_equal(pretty, "event.fields"); } - ret = print_field(text, main_field, - text->options.print_payload_field_names, NULL, 0); + ret = print_field(pretty, main_field, + pretty->options.print_payload_field_names, NULL, 0); end: bt_put(main_field); return ret; } BT_HIDDEN -enum bt_component_status text_print_event(struct text_component *text, +enum bt_component_status pretty_print_event(struct pretty_component *pretty, struct bt_ctf_event *event) { enum bt_component_status ret; - text->start_line = true; - ret = print_event_header(text, event); + pretty->start_line = true; + ret = print_event_header(pretty, event); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - ret = print_stream_packet_context(text, event); + ret = print_stream_packet_context(pretty, event); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - if (text->options.verbose) { - ret = print_event_header_raw(text, event); + if (pretty->options.verbose) { + ret = print_event_header_raw(pretty, event); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } } - ret = print_stream_event_context(text, event); + ret = print_stream_event_context(pretty, event); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - ret = print_event_context(text, event); + ret = print_event_context(pretty, event); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - ret = print_event_payload(text, event); + ret = print_event_payload(pretty, event); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - fputc('\n', text->out); + fputc('\n', pretty->out); end: return ret; } -- 2.34.1