From 3b6cfcc54e7adaf6725738cb4dd97325cef14ee5 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 10 Feb 2017 01:33:06 -0500 Subject: [PATCH] babeltrace convert: add --name option MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The --name option sets the name of the current (latest) component instance, e.g.: babeltrace convert --source=abc.xzy --name=my-component ... This can be useful to locate specific instances in the conversion graph, in particular in case of error. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- converter/babeltrace-cfg.c | 44 ++++++++++++++++++++++++++++++++++++++ converter/babeltrace-cfg.h | 1 + converter/babeltrace.c | 6 ++++++ 3 files changed, 51 insertions(+) diff --git a/converter/babeltrace-cfg.c b/converter/babeltrace-cfg.c index 999c773f..6d8ff8d9 100644 --- a/converter/babeltrace-cfg.c +++ b/converter/babeltrace-cfg.c @@ -712,6 +712,10 @@ void bt_config_component_destroy(struct bt_object *obj) g_string_free(bt_config_component->component_name, TRUE); } + if (bt_config_component->instance_name) { + g_string_free(bt_config_component->instance_name, TRUE); + } + BT_PUT(bt_config_component->params); g_free(bt_config_component); @@ -751,6 +755,12 @@ struct bt_config_component *bt_config_component_create(const char *plugin_name, goto error; } + cfg_component->instance_name = g_string_new(NULL); + if (!cfg_component->instance_name) { + print_err_oom(); + goto error; + } + /* Start with empty parameters */ cfg_component->params = bt_value_map_create(); if (!cfg_component->params) { @@ -1998,6 +2008,7 @@ enum { OPT_HELP, OPT_INPUT_FORMAT, OPT_LIST, + OPT_NAME, OPT_NAMES, OPT_NO_DELTA, OPT_OMIT_HOME_PLUGIN_PATH, @@ -2761,6 +2772,9 @@ void print_convert_usage(FILE *fp) fprintf(fp, " --end=END Set the `end` parameter of the latest\n"); fprintf(fp, " source component instance to END\n"); fprintf(fp, " (see the suggested format of BEGIN below)\n"); + fprintf(fp, " --name=NAME Set the name of the latest component\n"); + fprintf(fp, " instance to NAME (must be unique amongst\n"); + fprintf(fp, " all the names of the component instances)\n"); fprintf(fp, " --omit-home-plugin-path Omit home plugins from plugin search path\n"); fprintf(fp, " (~/.local/lib/babeltrace/plugins)\n"); fprintf(fp, " --omit-system-plugin-path Omit system plugins from plugin search path\n"); @@ -2843,6 +2857,7 @@ static struct poptOption convert_long_options[] = { { "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL }, { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL }, { "input-format", 'i', POPT_ARG_STRING, NULL, OPT_INPUT_FORMAT, NULL, NULL }, + { "name", '\0', POPT_ARG_STRING, NULL, OPT_NAME, NULL, NULL }, { "names", 'n', POPT_ARG_STRING, NULL, OPT_NAMES, NULL, NULL }, { "no-delta", '\0', POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL }, { "omit-home-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_HOME_PLUGIN_PATH, NULL, NULL }, @@ -2889,6 +2904,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], struct bt_value *cur_base_params = NULL; int opt, ret = 0; struct bt_config *cfg = NULL; + struct bt_value *instance_names = NULL; *retcode = 0; memset(&ctf_legacy_opts, 0, sizeof(ctf_legacy_opts)); @@ -2938,6 +2954,12 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } + instance_names = bt_value_map_create(); + if (!instance_names) { + print_err_oom(); + goto error; + } + ret = append_env_var_plugin_paths(cfg->cmd_data.convert.plugin_paths); if (ret) { printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n"); @@ -3173,6 +3195,27 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], goto error; } break; + case OPT_NAME: + if (!cur_cfg_comp) { + printf_err("Cannot set the name of unavailable default source component `%s`:\n %s\n", + DEFAULT_SOURCE_COMPONENT_NAME, arg); + goto error; + } + + if (bt_value_map_has_key(instance_names, arg)) { + printf_err("Duplicate component instance name:\n %s\n", + arg); + goto error; + } + + g_string_assign(cur_cfg_comp->instance_name, arg); + + if (bt_value_map_insert(instance_names, + arg, bt_value_null)) { + print_err_oom(); + goto error; + } + break; case OPT_BASE_PARAMS: { struct bt_value *params = bt_value_from_arg(arg); @@ -3497,6 +3540,7 @@ end: BT_PUT(text_legacy_opts.names); BT_PUT(text_legacy_opts.fields); BT_PUT(legacy_input_paths); + BT_PUT(instance_names); return cfg; } diff --git a/converter/babeltrace-cfg.h b/converter/babeltrace-cfg.h index 4245012c..a452d59f 100644 --- a/converter/babeltrace-cfg.h +++ b/converter/babeltrace-cfg.h @@ -39,6 +39,7 @@ struct bt_config_component { GString *plugin_name; GString *component_name; struct bt_value *params; + GString *instance_name; }; enum bt_config_command { diff --git a/converter/babeltrace.c b/converter/babeltrace.c index ddb3b0ee..04185214 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -232,6 +232,12 @@ void print_bt_config_component(struct bt_config_component *bt_config_component) { printf(" %s.%s:\n", bt_config_component->plugin_name->str, bt_config_component->component_name->str); + + if (bt_config_component->instance_name->len > 0) { + printf(" Name: %s\n", + bt_config_component->instance_name->str); + } + printf(" Parameters:\n"); print_value(bt_config_component->params, 8); } -- 2.34.1