X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=converter%2Fbabeltrace.c;h=85851ceb0b989a4e87273e86fcac10514504597d;hb=c1081aa6b31fb4ff1fa9f0d46f06f1df89bc8dc4;hp=65d2ec9310af9b1aecbfdec03de520b5bde58282;hpb=290725f719d3d1a8896b73334736d47c5c935040;p=babeltrace.git diff --git a/converter/babeltrace.c b/converter/babeltrace.c index 65d2ec93..85851ceb 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -44,6 +44,7 @@ #include #include #include "babeltrace-cfg.h" +#include "babeltrace-cfg-connect.h" #include "default-cfg.h" GPtrArray *loaded_plugins; @@ -111,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) { @@ -136,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; @@ -156,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); @@ -209,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; @@ -227,11 +240,27 @@ 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) { 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); } @@ -259,13 +288,36 @@ void print_plugin_paths(struct bt_value *plugin_paths) static void print_cfg_convert(struct bt_config *cfg) { + size_t i; + printf(" Force correlate: %s\n", cfg->cmd_data.convert.force_correlate ? "yes" : "no"); print_plugin_paths(cfg->cmd_data.convert.plugin_paths); printf(" Source component instances:\n"); print_bt_config_components(cfg->cmd_data.convert.sources); + + if (cfg->cmd_data.convert.filters->len > 0) { + printf(" Filter component instances:\n"); + print_bt_config_components(cfg->cmd_data.convert.filters); + } + printf(" Sink component instances:\n"); print_bt_config_components(cfg->cmd_data.convert.sinks); + printf(" Connections:\n"); + + for (i = 0; i < cfg->cmd_data.convert.connections->len; i++) { + struct bt_config_connection *cfg_connection = + g_ptr_array_index(cfg->cmd_data.convert.connections, + i); + + printf(" %s%s%s -> %s%s%s\n", + cfg_connection->src_instance_name->str, + cfg_connection->src_port_name->len > 0 ? "." : "", + cfg_connection->src_port_name->str, + cfg_connection->dst_instance_name->str, + cfg_connection->dst_port_name->len > 0 ? "." : "", + cfg_connection->dst_port_name->str); + } } static @@ -274,6 +326,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) { @@ -292,6 +359,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); } @@ -541,6 +614,226 @@ end: return ret; } +static void print_plugin_info(struct bt_plugin *plugin) +{ + unsigned int major, minor, patch; + const char *extra; + enum bt_plugin_status version_status; + const char *plugin_name; + const char *path; + const char *author; + const char *license; + const char *plugin_description; + + plugin_name = bt_plugin_get_name(plugin); + path = bt_plugin_get_path(plugin); + author = bt_plugin_get_author(plugin); + license = bt_plugin_get_license(plugin); + plugin_description = bt_plugin_get_description(plugin); + version_status = bt_plugin_get_version(plugin, &major, &minor, + &patch, &extra); + printf("%s%s%s%s:\n", bt_common_color_bold(), + bt_common_color_fg_blue(), plugin_name, + bt_common_color_reset()); + printf(" %sPath%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), path ? path : "(None)"); + + if (version_status == BT_PLUGIN_STATUS_OK) { + printf(" %sVersion%s: %u.%u.%u", + bt_common_color_bold(), bt_common_color_reset(), + major, minor, patch); + + if (extra) { + printf("%s", extra); + } + + printf("\n"); + } + + printf(" %sDescription%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), + plugin_description ? plugin_description : "(None)"); + printf(" %sAuthor%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), author ? author : "(Unknown)"); + printf(" %sLicense%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), + license ? license : "(Unknown)"); +} + +static void print_plugin_comp_cls_opt(FILE *fh, const char *plugin_name, + const char *comp_cls_name, enum bt_component_class_type type) +{ + fprintf(fh, "%s%s--%s%s %s%s%s.%s%s%s", + bt_common_color_bold(), + bt_common_color_fg_cyan(), + component_type_str(type), + bt_common_color_fg_default(), + bt_common_color_fg_blue(), + plugin_name, + bt_common_color_fg_default(), + bt_common_color_fg_yellow(), + comp_cls_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; + struct bt_plugin *plugin = NULL; + size_t i; + + ret = load_all_plugins(cfg->cmd_data.list_plugins.plugin_paths); + if (ret) { + goto end; + } + + 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.cfg_component->plugin_name->str, + bt_common_color_reset()); + ret = -1; + goto end; + } + + print_plugin_info(plugin); + printf(" %sComponent classes%s: %d\n", + bt_common_color_bold(), + bt_common_color_reset(), + bt_plugin_get_component_class_count(plugin)); + + + 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.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", + bt_common_color_bold(), + bt_common_color_fg_red(), + bt_common_color_reset()); + print_plugin_comp_cls_opt(stderr, + 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; + } + + bt_put(needed_comp_cls); + } + + for (i = 0; i < bt_plugin_get_component_class_count(plugin); i++) { + struct bt_component_class *comp_cls = + bt_plugin_get_component_class(plugin, i); + const char *comp_class_name = + bt_component_class_get_name(comp_cls); + const char *comp_class_description = + bt_component_class_get_description(comp_cls); + const char *comp_class_help = + bt_component_class_get_help(comp_cls); + enum bt_component_class_type type = + bt_component_class_get_type(comp_cls); + + assert(comp_cls); + + if (cfg->cmd_data.help.cfg_component->type != + BT_COMPONENT_CLASS_TYPE_UNKNOWN) { + if (strcmp(cfg->cmd_data.help.cfg_component->component_name->str, + comp_class_name) != 0 && + type == + cfg->cmd_data.help.cfg_component->type) { + bt_put(comp_cls); + continue; + } + } + + printf("\n"); + print_plugin_comp_cls_opt(stdout, + cfg->cmd_data.help.cfg_component->plugin_name->str, + comp_class_name, + type); + printf("\n"); + printf(" %sDescription%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), + comp_class_description ? comp_class_description : "(None)"); + + if (comp_class_help) { + printf("\n%s\n", comp_class_help); + } + + bt_put(comp_cls); + } + +end: + bt_put(plugin); + return ret; +} + static int cmd_list_plugins(struct bt_config *cfg) { int ret; @@ -551,6 +844,9 @@ static int cmd_list_plugins(struct bt_config *cfg) goto end; } + printf("From the following plugin paths:\n\n"); + print_value(cfg->cmd_data.list_plugins.plugin_paths, 2); + printf("\n"); plugins_count = loaded_plugins->len; if (plugins_count == 0) { fprintf(stderr, "%s%sNo plugins found.%s\n", @@ -581,47 +877,11 @@ static int cmd_list_plugins(struct bt_config *cfg) for (i = 0; i < plugins_count; i++) { int j; struct bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i); - unsigned int major, minor, patch; - const char *extra; - enum bt_plugin_status version_status; - const char *plugin_name = bt_plugin_get_name(plugin); - const char *path = bt_plugin_get_path(plugin); - const char *author = bt_plugin_get_author(plugin); - const char *license = bt_plugin_get_license(plugin); - const char *plugin_description = - bt_plugin_get_description(plugin); component_classes_count = bt_plugin_get_component_class_count(plugin); - version_status = bt_plugin_get_version(plugin, &major, &minor, - &patch, &extra); - - printf("\n%s%s%s%s:\n", bt_common_color_bold(), - bt_common_color_fg_blue(), plugin_name, - bt_common_color_reset()); - printf(" %sPath%s: %s\n", bt_common_color_bold(), - bt_common_color_reset(), path ? path : "(None)"); - - if (version_status == BT_PLUGIN_STATUS_OK) { - printf(" %sVersion%s: %u.%u.%u", - bt_common_color_bold(), bt_common_color_reset(), - major, minor, patch); - - if (extra) { - printf("%s", extra); - } - - printf("\n"); - } - - printf(" %sDescription%s: %s\n", bt_common_color_bold(), - bt_common_color_reset(), - plugin_description ? plugin_description : "(None)"); - printf(" %sAuthor%s: %s\n", bt_common_color_bold(), - bt_common_color_reset(), author ? author : "(Unknown)"); - printf(" %sLicense%s: %s\n", bt_common_color_bold(), - bt_common_color_reset(), - license ? license : "(Unknown)"); + printf("\n"); + print_plugin_info(plugin); if (component_classes_count == 0) { printf(" %sComponent classes%s: (None)\n", @@ -643,17 +903,10 @@ static int cmd_list_plugins(struct bt_config *cfg) enum bt_component_class_type type = bt_component_class_get_type(comp_class); - printf(" %s%s--%s%s %s%s%s.%s%s%s", - bt_common_color_bold(), - bt_common_color_fg_cyan(), - component_type_str(type), - bt_common_color_fg_default(), - bt_common_color_fg_blue(), - plugin_name, - bt_common_color_fg_default(), - bt_common_color_fg_yellow(), - comp_class_name, - bt_common_color_reset()); + printf(" "); + print_plugin_comp_cls_opt(stdout, + bt_plugin_get_name(plugin), comp_class_name, + type); if (comp_class_description) { printf(": %s", comp_class_description); @@ -681,12 +934,14 @@ static int cmd_convert(struct bt_config *cfg) /* TODO handle more than 1 source and 1 sink. */ if (cfg->cmd_data.convert.sources->len != 1 || cfg->cmd_data.convert.sinks->len != 1) { + fprintf(stderr, "Only one source and one sink component class are supported. Aborting...\n"); ret = -1; 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; } @@ -819,6 +1074,12 @@ int main(int argc, const char **argv) case BT_CONFIG_COMMAND_LIST_PLUGINS: ret = cmd_list_plugins(cfg); break; + 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); }