babeltrace convert: add --name option
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 10 Feb 2017 06:33:06 +0000 (01:33 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:38 +0000 (12:57 -0400)
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 <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
converter/babeltrace-cfg.c
converter/babeltrace-cfg.h
converter/babeltrace.c

index 999c773ff1ff103034acb0ad5fc8027da9bfafb5..6d8ff8d9846e23853853cf8af577369139dbde70 100644 (file)
@@ -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;
 }
 
index 4245012c2ed20eb3a7d8afc0d11a4b570b58c78d..a452d59f424d75f09e5544de83c27f32556904e3 100644 (file)
@@ -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 {
index ddb3b0ee5d15a8bd72fdd9939a9423fe7a9e57e9..04185214eff798cc8224cc08eb0f399991e6a758 100644 (file)
@@ -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);
 }
This page took 0.0283600000000001 seconds and 4 git commands to generate.