From 05a67631af7f4005df9a7d921d2965b66251ddd4 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Sat, 11 Feb 2017 18:26:13 -0500 Subject: [PATCH] babeltrace(1): support -o metadata legacy option MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- converter/babeltrace-cfg.c | 82 ++++++++++++++++++------------- converter/babeltrace-cfg.h | 1 + converter/babeltrace.c | 99 +++++++++++++++++++++++++++++++++++--- 3 files changed, 142 insertions(+), 40 deletions(-) diff --git a/converter/babeltrace-cfg.c b/converter/babeltrace-cfg.c index 6e07a437..f3625c3b 100644 --- a/converter/babeltrace-cfg.c +++ b/converter/babeltrace-cfg.c @@ -143,7 +143,6 @@ enum legacy_input_format { enum legacy_output_format { LEGACY_OUTPUT_FORMAT_NONE = 0, LEGACY_OUTPUT_FORMAT_TEXT, - LEGACY_OUTPUT_FORMAT_CTF_METADATA, LEGACY_OUTPUT_FORMAT_DUMMY, }; @@ -1361,10 +1360,6 @@ int append_sinks_from_legacy_opts(GPtrArray *sinks, plugin_name = "text"; component_name = "text"; break; - case LEGACY_OUTPUT_FORMAT_CTF_METADATA: - plugin_name = "ctf"; - component_name = "metadata-text"; - break; case LEGACY_OUTPUT_FORMAT_DUMMY: plugin_name = "utils"; component_name = "dummy"; @@ -1700,9 +1695,6 @@ void print_output_legacy_to_sinks( case LEGACY_OUTPUT_FORMAT_TEXT: output_format = "text"; break; - case LEGACY_OUTPUT_FORMAT_CTF_METADATA: - output_format = "ctf-metadata"; - break; case LEGACY_OUTPUT_FORMAT_DUMMY: output_format = "dummy"; break; @@ -1720,9 +1712,6 @@ void print_output_legacy_to_sinks( case LEGACY_OUTPUT_FORMAT_TEXT: g_string_append(str, "text.text"); break; - case LEGACY_OUTPUT_FORMAT_CTF_METADATA: - g_string_append(str, "ctf.metadata-text"); - break; case LEGACY_OUTPUT_FORMAT_DUMMY: g_string_append(str, "utils.dummy"); break; @@ -1896,7 +1885,8 @@ bool validate_cfg(struct bt_config *cfg, bool legacy_output = false; /* Determine if the input and output should be legacy-style */ - if (*legacy_input_format != LEGACY_INPUT_FORMAT_NONE || + if (cfg->cmd_data.convert.print_ctf_metadata || + *legacy_input_format != LEGACY_INPUT_FORMAT_NONE || !bt_value_array_is_empty(legacy_input_paths) || ctf_legacy_opts_is_any_set(ctf_legacy_opts)) { legacy_input = true; @@ -1930,13 +1920,45 @@ bool validate_cfg(struct bt_config *cfg, /* Make sure no non-legacy sources are specified */ if (cfg->cmd_data.convert.sources->len != 0) { - print_input_legacy_to_sources(*legacy_input_format, - legacy_input_paths, ctf_legacy_opts); + if (cfg->cmd_data.convert.print_ctf_metadata) { + printf_err("You cannot instantiate a source component with the `ctf-metadata` output format\n"); + } else { + print_input_legacy_to_sources( + *legacy_input_format, + legacy_input_paths, ctf_legacy_opts); + } + goto error; } } - if (legacy_output) { + /* + * Strict rule: if we need to print the CTF metadata, the input + * format must be legacy and CTF. Also there should be no + * other sinks, and no legacy output format. + */ + if (cfg->cmd_data.convert.print_ctf_metadata) { + if (*legacy_input_format != LEGACY_INPUT_FORMAT_CTF) { + printf_err("The `ctf-metadata` output format requires legacy `ctf` input format\n"); + goto error; + } + + if (bt_value_array_size(legacy_input_paths) != 1) { + printf_err("You need to specify exactly one path with the `ctf-metadata` output format\n"); + goto error; + } + + if (legacy_output) { + printf_err("You cannot use another legacy output format with the `ctf-metadata` output format\n"); + goto error; + } + + if (cfg->cmd_data.convert.sinks->len != 0) { + printf_err("You cannot instantiate a sink component with the `ctf-metadata` output format\n"); + goto error; + goto error; + } + } else if (legacy_output) { /* * If no legacy output format was specified, default to * "text". @@ -1964,16 +1986,6 @@ bool validate_cfg(struct bt_config *cfg, } } - /* - * If the output is the legacy "ctf-metadata" format, then the - * input should be the legacy "ctf" input format. - */ - if (*legacy_output_format == LEGACY_OUTPUT_FORMAT_CTF_METADATA && - *legacy_input_format != LEGACY_INPUT_FORMAT_CTF) { - printf_err("Legacy `ctf-metadata` output format requires using legacy `ctf` input format\n"); - goto error; - } - return true; error: @@ -3460,14 +3472,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], LEGACY_OUTPUT_FORMAT_DUMMY; break; } else if (!strcmp(arg, "ctf-metadata")) { - /* Legacy CTF-metadata output format */ - if (legacy_output_format) { - print_err_dup_legacy_output(); - goto error; - } - - legacy_output_format = - LEGACY_OUTPUT_FORMAT_CTF_METADATA; + cfg->cmd_data.convert.print_ctf_metadata = true; break; } } @@ -3835,12 +3840,21 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], } else { if (implicit_source_comp && !bt_value_map_is_empty(implicit_source_comp->params)) { - printf_err("Arguments specified for implicit source, but an explicit source has been specified, overriding it\n"); + printf_err("Arguments specified for implicit input format, but an explicit source component instance has been specified: overriding it\n"); goto error; } } } + /* + * At this point if we need to print the CTF metadata text, we + * don't care about the legacy/implicit sinks and component + * connections. + */ + if (cfg->cmd_data.convert.print_ctf_metadata) { + goto end; + } + /* * If there's a legacy output format, convert it to sink * component configurations. diff --git a/converter/babeltrace-cfg.h b/converter/babeltrace-cfg.h index 6779f85e..6cb375b8 100644 --- a/converter/babeltrace-cfg.h +++ b/converter/babeltrace-cfg.h @@ -76,6 +76,7 @@ struct bt_config { bool force_correlate; bool omit_system_plugin_path; bool omit_home_plugin_path; + bool print_ctf_metadata; } convert; /* BT_CONFIG_COMMAND_LIST_PLUGINS */ diff --git a/converter/babeltrace.c b/converter/babeltrace.c index 85851ceb..c94bf967 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -293,6 +293,8 @@ void print_cfg_convert(struct bt_config *cfg) printf(" Force correlate: %s\n", cfg->cmd_data.convert.force_correlate ? "yes" : "no"); print_plugin_paths(cfg->cmd_data.convert.plugin_paths); + printf(" Print CTF metadata: %s\n", + cfg->cmd_data.convert.print_ctf_metadata ? "yes" : "no"); printf(" Source component instances:\n"); print_bt_config_components(cfg->cmd_data.convert.sources); @@ -921,6 +923,86 @@ end: return ret; } +static int print_ctf_metadata(struct bt_config *cfg) +{ + int ret = 0; + struct bt_component_class *comp_cls = NULL; + struct bt_config_component *source_cfg = NULL; + struct bt_value *results = NULL; + struct bt_value *path = NULL; + struct bt_value *params = NULL; + struct bt_value *metadata_text_value = NULL; + const char *metadata_text = NULL; + + assert(cfg->cmd_data.convert.sources->len == 1); + source_cfg = bt_config_get_component(cfg->cmd_data.convert.sources, 0); + assert(source_cfg); + comp_cls = find_component_class(source_cfg->plugin_name->str, + source_cfg->component_name->str, + source_cfg->type); + if (!comp_cls) { + fprintf(stderr, "%s%sCannot find component class %s", + bt_common_color_bold(), + bt_common_color_fg_red(), + bt_common_color_reset()); + print_plugin_comp_cls_opt(stderr, + source_cfg->plugin_name->str, + source_cfg->component_name->str, + source_cfg->type); + fprintf(stderr, "\n"); + ret = -1; + goto end; + } + + path = bt_value_map_get(source_cfg->params, "path"); + if (!path) { + ret = -1; + goto end; + } + + params = bt_value_map_create(); + if (!params) { + ret = -1; + goto end; + } + + ret = bt_value_map_insert(params, "path", path); + if (ret) { + ret = -1; + goto end; + } + + results = bt_component_class_query_info(comp_cls, "get-metadata-info", + params); + if (!results) { + ret = -1; + fprintf(stderr, "%s%sFailed to get metadata info%s\n", + bt_common_color_bold(), + bt_common_color_fg_red(), + bt_common_color_reset()); + goto end; + } + + metadata_text_value = bt_value_map_get(results, "text"); + if (!metadata_text_value) { + ret = -1; + goto end; + } + + ret = bt_value_string_get(metadata_text_value, &metadata_text); + assert(ret == 0); + printf("%s\n", metadata_text); + +end: + bt_put(results); + bt_put(path); + bt_put(params); + bt_put(metadata_text_value); + bt_put(comp_cls); + bt_put(source_cfg); + return 0; +} + static int cmd_convert(struct bt_config *cfg) { int ret = 0; @@ -931,6 +1013,17 @@ static int cmd_convert(struct bt_config *cfg) enum bt_component_status sink_status; struct bt_config_component *source_cfg = NULL, *sink_cfg = NULL; + ret = load_all_plugins(cfg->cmd_data.convert.plugin_paths); + if (ret) { + fprintf(stderr, "Could not load plugins from configured plugin paths. Aborting...\n"); + goto end; + } + + if (cfg->cmd_data.convert.print_ctf_metadata) { + ret = print_ctf_metadata(cfg); + goto end; + } + /* TODO handle more than 1 source and 1 sink. */ if (cfg->cmd_data.convert.sources->len != 1 || cfg->cmd_data.convert.sinks->len != 1) { @@ -939,12 +1032,6 @@ static int cmd_convert(struct bt_config *cfg) goto end; } - ret = load_all_plugins(cfg->cmd_data.convert.plugin_paths); - if (ret) { - fprintf(stderr, "Could not load plugins from configured plugin paths. Aborting...\n"); - goto end; - } - source_cfg = bt_config_get_component(cfg->cmd_data.convert.sources, 0); source_params = bt_get(source_cfg->params); source_class = find_component_class(source_cfg->plugin_name->str, -- 2.34.1