babeltrace(1): support -o metadata legacy option
[babeltrace.git] / converter / babeltrace.c
index af7a5ba6157eabb53f4f300d79cff983ab8bba6e..c94bf9675a59a49bc49cf86ea20e9593eca7cdea 100644 (file)
@@ -112,6 +112,9 @@ void print_indent(size_t indent)
 static
 void print_value(struct bt_value *, size_t);
 
+static
+void print_value_rec(struct bt_value *, size_t);
+
 static
 bool print_map_value(const char *key, struct bt_value *object, void *data)
 {
@@ -137,12 +140,12 @@ bool print_map_value(const char *key, struct bt_value *object, void *data)
                printf("\n");
        }
 
-       print_value(object, *indent + 2);
+       print_value_rec(object, *indent + 2);
        return true;
 }
 
 static
-void print_value(struct bt_value *value, size_t indent)
+void print_value_rec(struct bt_value *value, size_t indent)
 {
        bool bool_val;
        int64_t int_val;
@@ -157,23 +160,32 @@ void print_value(struct bt_value *value, size_t indent)
 
        switch (bt_value_get_type(value)) {
        case BT_VALUE_TYPE_NULL:
-               printf("null\n");
+               printf("%snull%s\n", bt_common_color_bold(),
+                       bt_common_color_reset());
                break;
        case BT_VALUE_TYPE_BOOL:
                bt_value_bool_get(value, &bool_val);
-               printf("%s\n", bool_val ? "yes" : "no");
+               printf("%s%s%s%s\n", bt_common_color_bold(),
+                       bt_common_color_fg_cyan(), bool_val ? "yes" : "no",
+                       bt_common_color_reset());
                break;
        case BT_VALUE_TYPE_INTEGER:
                bt_value_integer_get(value, &int_val);
-               printf("%" PRId64 "\n", int_val);
+               printf("%s%s%" PRId64 "%s\n", bt_common_color_bold(),
+                       bt_common_color_fg_red(), int_val,
+                       bt_common_color_reset());
                break;
        case BT_VALUE_TYPE_FLOAT:
                bt_value_float_get(value, &dbl_val);
-               printf("%lf\n", dbl_val);
+               printf("%s%s%lf%s\n", bt_common_color_bold(),
+                       bt_common_color_fg_red(), dbl_val,
+                       bt_common_color_reset());
                break;
        case BT_VALUE_TYPE_STRING:
                bt_value_string_get(value, &str_val);
-               printf("%s\n", str_val);
+               printf("%s%s%s%s\n", bt_common_color_bold(),
+                       bt_common_color_fg_green(), str_val,
+                       bt_common_color_reset());
                break;
        case BT_VALUE_TYPE_ARRAY:
                size = bt_value_array_size(value);
@@ -210,7 +222,7 @@ void print_value(struct bt_value *value, size_t indent)
                                printf("\n");
                        }
 
-                       print_value(element, indent + 2);
+                       print_value_rec(element, indent + 2);
                        BT_PUT(element);
                }
                break;
@@ -228,6 +240,16 @@ void print_value(struct bt_value *value, size_t indent)
        }
 }
 
+static
+void print_value(struct bt_value *value, size_t indent)
+{
+       if (!bt_value_is_array(value) && !bt_value_is_map(value)) {
+               print_indent(indent);
+       }
+
+       print_value_rec(value, indent);
+}
+
 static
 void print_bt_config_component(struct bt_config_component *bt_config_component)
 {
@@ -271,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);
 
@@ -304,6 +328,21 @@ void print_cfg_list_plugins(struct bt_config *cfg)
        print_plugin_paths(cfg->cmd_data.list_plugins.plugin_paths);
 }
 
+static
+void print_cfg_help(struct bt_config *cfg)
+{
+       print_plugin_paths(cfg->cmd_data.help.plugin_paths);
+}
+
+static
+void print_cfg_query_info(struct bt_config *cfg)
+{
+       print_plugin_paths(cfg->cmd_data.query_info.plugin_paths);
+       printf("  Action: `%s`\n", cfg->cmd_data.query_info.action->str);
+       printf("  Component class:\n");
+       print_bt_config_component(cfg->cmd_data.query_info.cfg_component);
+}
+
 static
 void print_cfg(struct bt_config *cfg)
 {
@@ -322,6 +361,12 @@ void print_cfg(struct bt_config *cfg)
        case BT_CONFIG_COMMAND_LIST_PLUGINS:
                print_cfg_list_plugins(cfg);
                break;
+       case BT_CONFIG_COMMAND_HELP:
+               print_cfg_help(cfg);
+               break;
+       case BT_CONFIG_COMMAND_QUERY_INFO:
+               print_cfg_query_info(cfg);
+               break;
        default:
                assert(false);
        }
@@ -633,6 +678,63 @@ static void print_plugin_comp_cls_opt(FILE *fh, const char *plugin_name,
                bt_common_color_reset());
 }
 
+static int cmd_query_info(struct bt_config *cfg)
+{
+       int ret;
+       struct bt_component_class *comp_cls = NULL;
+       struct bt_value *results = NULL;
+
+       ret = load_all_plugins(cfg->cmd_data.list_plugins.plugin_paths);
+       if (ret) {
+               goto end;
+       }
+
+       comp_cls = find_component_class(cfg->cmd_data.query_info.cfg_component->plugin_name->str,
+               cfg->cmd_data.query_info.cfg_component->component_name->str,
+               cfg->cmd_data.query_info.cfg_component->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,
+                       cfg->cmd_data.query_info.cfg_component->plugin_name->str,
+                       cfg->cmd_data.query_info.cfg_component->component_name->str,
+                       cfg->cmd_data.query_info.cfg_component->type);
+               fprintf(stderr, "\n");
+               ret = -1;
+               goto end;
+       }
+
+       results = bt_component_class_query_info(comp_cls,
+               cfg->cmd_data.query_info.action->str,
+               cfg->cmd_data.query_info.cfg_component->params);
+       if (!results) {
+               fprintf(stderr, "%s%sFailed to query info to %s",
+                       bt_common_color_bold(),
+                       bt_common_color_fg_red(),
+                       bt_common_color_reset());
+               print_plugin_comp_cls_opt(stderr,
+                       cfg->cmd_data.query_info.cfg_component->plugin_name->str,
+                       cfg->cmd_data.query_info.cfg_component->component_name->str,
+                       cfg->cmd_data.query_info.cfg_component->type);
+               fprintf(stderr, "%s%s with action `%s`%s\n",
+                       bt_common_color_bold(),
+                       bt_common_color_fg_red(),
+                       cfg->cmd_data.query_info.action->str,
+                       bt_common_color_reset());
+               ret = -1;
+               goto end;
+       }
+
+       print_value(results, 0);
+
+end:
+       bt_put(comp_cls);
+       bt_put(results);
+       return ret;
+}
+
 static int cmd_help(struct bt_config *cfg)
 {
        int ret;
@@ -644,12 +746,12 @@ static int cmd_help(struct bt_config *cfg)
                goto end;
        }
 
-       plugin = find_plugin(cfg->cmd_data.help.plugin_name->str);
+       plugin = find_plugin(cfg->cmd_data.help.cfg_component->plugin_name->str);
        if (!plugin) {
                fprintf(stderr, "%s%sCannot find plugin %s%s%s\n",
                        bt_common_color_bold(), bt_common_color_fg_red(),
                        bt_common_color_fg_blue(),
-                       cfg->cmd_data.help.plugin_name->str,
+                       cfg->cmd_data.help.cfg_component->plugin_name->str,
                        bt_common_color_reset());
                ret = -1;
                goto end;
@@ -662,13 +764,13 @@ static int cmd_help(struct bt_config *cfg)
                        bt_plugin_get_component_class_count(plugin));
 
 
-       if (cfg->cmd_data.help.comp_cls_type !=
+       if (cfg->cmd_data.help.cfg_component->type !=
                        BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
                struct bt_component_class *needed_comp_cls =
                        find_component_class(
-                               cfg->cmd_data.help.plugin_name->str,
-                               cfg->cmd_data.help.component_name->str,
-                               cfg->cmd_data.help.comp_cls_type);
+                               cfg->cmd_data.help.cfg_component->plugin_name->str,
+                               cfg->cmd_data.help.cfg_component->component_name->str,
+                               cfg->cmd_data.help.cfg_component->type);
 
                if (!needed_comp_cls) {
                        fprintf(stderr, "\n%s%sCannot find component class %s",
@@ -676,9 +778,9 @@ static int cmd_help(struct bt_config *cfg)
                                bt_common_color_fg_red(),
                                bt_common_color_reset());
                        print_plugin_comp_cls_opt(stderr,
-                               cfg->cmd_data.help.plugin_name->str,
-                               cfg->cmd_data.help.component_name->str,
-                               cfg->cmd_data.help.comp_cls_type);
+                               cfg->cmd_data.help.cfg_component->plugin_name->str,
+                               cfg->cmd_data.help.cfg_component->component_name->str,
+                               cfg->cmd_data.help.cfg_component->type);
                        fprintf(stderr, "\n");
                        ret = -1;
                        goto end;
@@ -701,12 +803,12 @@ static int cmd_help(struct bt_config *cfg)
 
                assert(comp_cls);
 
-               if (cfg->cmd_data.help.comp_cls_type !=
+               if (cfg->cmd_data.help.cfg_component->type !=
                                BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
-                       if (strcmp(cfg->cmd_data.help.component_name->str,
+                       if (strcmp(cfg->cmd_data.help.cfg_component->component_name->str,
                                        comp_class_name) != 0 &&
                                        type ==
-                                       cfg->cmd_data.help.comp_cls_type) {
+                                       cfg->cmd_data.help.cfg_component->type) {
                                bt_put(comp_cls);
                                continue;
                        }
@@ -714,7 +816,7 @@ static int cmd_help(struct bt_config *cfg)
 
                printf("\n");
                print_plugin_comp_cls_opt(stdout,
-                       cfg->cmd_data.help.plugin_name->str,
+                       cfg->cmd_data.help.cfg_component->plugin_name->str,
                        comp_class_name,
                        type);
                printf("\n");
@@ -821,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;
@@ -831,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) {
@@ -839,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,
@@ -977,6 +1164,9 @@ int main(int argc, const char **argv)
        case BT_CONFIG_COMMAND_HELP:
                ret = cmd_help(cfg);
                break;
+       case BT_CONFIG_COMMAND_QUERY_INFO:
+               ret = cmd_query_info(cfg);
+               break;
        default:
                assert(false);
        }
This page took 0.028749 seconds and 4 git commands to generate.