#include "babeltrace2-cfg-src-auto-disc.h"
#include "babeltrace2-plugins.h"
+#include "babeltrace2-query.h"
#include "common/common.h"
/* Finalize and free a `struct auto_source_discovery_result`. */
if (res) {
g_free(res->group);
bt_value_put_ref(res->inputs);
+ bt_value_put_ref(res->original_input_indices);
g_free(res);
}
}
goto error;
}
+ res->original_input_indices = bt_value_array_create();
+ if (!res->original_input_indices) {
+ BT_CLI_LOGE_APPEND_CAUSE("Failed to allocate an array value.");
+ goto error;
+ }
+
goto end;
error:
auto_source_discovery_result_destroy(res);
return status;
}
+static
+const bt_value *borrow_array_value_last_element_const(const bt_value *array)
+{
+ uint64_t last_index = bt_value_array_get_size(array) - 1;
+
+ return bt_value_array_borrow_element_by_index_const(array, last_index);
+}
+
/*
* Assign `input` to source component class `source_cc_name` of plugin
* `plugin_name`, in the group with key `group`.
const char *plugin_name,
const char *source_cc_name,
const char *group,
- const char *input)
+ const char *input,
+ uint64_t original_input_index)
{
int status;
bt_value_array_append_element_status append_status;
guint len;
guint i;
struct auto_source_discovery_result *res = NULL;
+ bool append_index;
len = auto_disc->results->len;
i = len;
goto error;
}
+ /*
+ * Append `original_input_index` to `original_input_indices` if not
+ * there already. We process the `inputs` array in order, so if it is
+ * present, it has to be the last element.
+ */
+ if (bt_value_array_is_empty(res->original_input_indices)) {
+ append_index = true;
+ } else {
+ const bt_value *last_index_value;
+ uint64_t last_index;
+
+ last_index_value =
+ borrow_array_value_last_element_const(res->original_input_indices);
+ last_index = bt_value_integer_unsigned_get(last_index_value);
+
+ BT_ASSERT(last_index <= original_input_index);
+
+ append_index = (last_index != original_input_index);
+ }
+
+ if (append_index) {
+ append_status = bt_value_array_append_unsigned_integer_element(
+ res->original_input_indices, original_input_index);
+
+ if (append_status != BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK) {
+ BT_CLI_LOGE_APPEND_CAUSE("Failed to append an unsigned integer value.");
+ goto error;
+ }
+ }
status = 0;
goto end;
/* Accept signed integer as a convenience for "return 0" or "return 1" in Python. */
*weight = bt_value_integer_signed_get(weight_value);
} else {
- BT_LOGW("support-info query: unexpected type for weight: "
+ BT_LOGW("babeltrace.support-info query: unexpected type for weight: "
"component-class-name=source.%s.%s, input=%s, input-type=%s, "
"expected-entry-type=%s, actual-entry-type=%s",
plugin_name, source_cc_name, input, input_type,
}
if (*weight < 0.0 || *weight > 1.0) {
- BT_LOGW("support-info query: weight value is out of range [0.0, 1.0]: "
+ BT_LOGW("babeltrace.support-info query: weight value is out of range [0.0, 1.0]: "
"component-class-name=source.%s.%s, input=%s, input-type=%s, "
"weight=%f",
plugin_name, source_cc_name, input, input_type, *weight);
static
int support_info_query_all_sources(const char *input,
const char *input_type,
- bt_query_executor *query_executor, size_t plugin_count,
+ uint64_t original_input_index,
+ size_t plugin_count,
const char *plugin_restrict,
const char *component_class_restrict,
enum bt_logging_level log_level,
continue;
}
- BT_LOGD("support-info query: before: component-class-name=source.%s.%s, input=%s, "
+ BT_LOGD("babeltrace.support-info query: before: component-class-name=source.%s.%s, input=%s, "
"type=%s", plugin_name, source_cc_name, input, input_type);
BT_VALUE_PUT_REF_AND_RESET(query_result);
- query_status = bt_query_executor_query(query_executor, cc, "support-info",
- query_params, log_level, &query_result);
+ query_status = cli_query(cc, "babeltrace.support-info",
+ query_params, log_level, NULL, &query_result,
+ NULL);
if (query_status == BT_QUERY_EXECUTOR_QUERY_STATUS_OK) {
double weight;
const bt_value *weight_value;
if (!bt_value_map_has_entry(query_result, "weight")) {
- BT_LOGW("support-info query: result is missing `weight` entry: "
+ BT_LOGW("babeltrace.support-info query: result is missing `weight` entry: "
"component-class-name=source.%s.%s, input=%s, input-type=%s",
bt_plugin_get_name(plugin),
bt_component_class_get_name(cc), input,
/* Do as if no value was passed. */
group_value = NULL;
} else if (bt_value_get_type(group_value) != BT_VALUE_TYPE_STRING) {
- BT_LOGW("support-info query: unexpected type for entry `group`: "
+ BT_LOGW("babeltrace.support-info query: unexpected type for entry `group`: "
"component-class-name=source.%s.%s, input=%s, input-type=%s, "
"expected-entry-type=%s,%s, actual-entry-type=%s",
bt_plugin_get_name(plugin),
}
}
} else {
- BT_LOGW("support-info query: unexpected result type: "
+ BT_LOGW("babeltrace.support-info query: unexpected result type: "
"component-class-name=source.%s.%s, input=%s, input-type=%s, "
"expected-types=%s,%s,%s, actual-type=%s",
bt_plugin_get_name(plugin),
continue;
}
- BT_LOGD("support-info query: success: component-class-name=source.%s.%s, input=%s, "
+ BT_LOGD("babeltrace.support-info query: success: component-class-name=source.%s.%s, input=%s, "
"type=%s, weight=%f\n",
bt_plugin_get_name(plugin), bt_component_class_get_name(cc), input,
input_type, weight);
winner.weigth = weight;
}
} else if (query_status == BT_QUERY_EXECUTOR_QUERY_STATUS_ERROR) {
- BT_CLI_LOGE_APPEND_CAUSE("support-info query failed.");
+ BT_CLI_LOGE_APPEND_CAUSE("babeltrace.support-info query failed.");
goto error;
} else if (query_status == BT_QUERY_EXECUTOR_QUERY_STATUS_MEMORY_ERROR) {
BT_CLI_LOGE_APPEND_CAUSE("Memory error.");
goto error;
} else {
- BT_LOGD("support-info query: failure: component-class-name=source.%s.%s, input=%s, "
+ BT_LOGD("babeltrace.support-info query: failure: component-class-name=source.%s.%s, input=%s, "
"type=%s, status=%s\n",
bt_plugin_get_name(plugin), bt_component_class_get_name(cc), input,
input_type,
BT_LOGI("Input %s is awarded to component class source.%s.%s with weight %f",
input, plugin_name, source_name, winner.weigth);
- status = auto_source_discovery_add(auto_disc, plugin_name, source_name, group, input);
+ status = auto_source_discovery_add(auto_disc, plugin_name,
+ source_name, group, input, original_input_index);
if (status != 0) {
goto error;
}
static
int auto_discover_source_for_input_as_string(const char *input,
- bt_query_executor *query_executor, size_t plugin_count,
- const char *plugin_restrict,
+ uint64_t original_input_index,
+ size_t plugin_count, const char *plugin_restrict,
const char *component_class_restrict,
enum bt_logging_level log_level,
struct auto_source_discovery *auto_disc)
{
return support_info_query_all_sources(input, "string",
- query_executor, plugin_count, plugin_restrict,
+ original_input_index, plugin_count, plugin_restrict,
component_class_restrict, log_level, auto_disc);
}
static
int auto_discover_source_for_input_as_dir_or_file_rec(GString *input,
- bt_query_executor *query_executor, size_t plugin_count,
- const char *plugin_restrict,
+ uint64_t original_input_index,
+ size_t plugin_count, const char *plugin_restrict,
const char *component_class_restrict,
enum bt_logging_level log_level,
struct auto_source_discovery *auto_disc)
if (g_file_test(input->str, G_FILE_TEST_IS_REGULAR)) {
/* It's a file. */
status = support_info_query_all_sources(input->str,
- "file", query_executor, plugin_count,
+ "file", original_input_index, plugin_count,
plugin_restrict, component_class_restrict, log_level, auto_disc);
} else if (g_file_test(input->str, G_FILE_TEST_IS_DIR)) {
GDir *dir;
/* It's a directory. */
status = support_info_query_all_sources(input->str,
- "directory", query_executor, plugin_count,
+ "directory", original_input_index, plugin_count,
plugin_restrict, component_class_restrict, log_level,
auto_disc);
const char *fmt = "Failed to open directory %s: %s";
BT_LOGW(fmt, input->str, error->message);
- if (errno == EACCES) {
+ if (error->code == G_FILE_ERROR_ACCES) {
/* This is not a fatal error, we just skip it. */
status = 1;
goto end;
g_string_append(input, dirent);
status = auto_discover_source_for_input_as_dir_or_file_rec(
- input, query_executor, plugin_count,
+ input, original_input_index, plugin_count,
plugin_restrict, component_class_restrict,
log_level, auto_disc);
BT_LOGW_ERRNO("Failed to read directory entry", ": dir=%s", input->str);
goto error;
}
- } while (dirent != NULL);
+ } while (dirent);
status = dir_status;
static
int auto_discover_source_for_input_as_dir_or_file(const char *input,
- bt_query_executor *query_executor, size_t plugin_count,
- const char *plugin_restrict,
+ uint64_t original_input_index,
+ size_t plugin_count, const char *plugin_restrict,
const char *component_class_restrict,
enum bt_logging_level log_level,
struct auto_source_discovery *auto_disc)
}
status = auto_discover_source_for_input_as_dir_or_file_rec(
- mutable_input, query_executor, plugin_count, plugin_restrict,
+ mutable_input, original_input_index, plugin_count, plugin_restrict,
component_class_restrict, log_level, auto_disc);
g_string_free(mutable_input, TRUE);
uint64_t i_inputs, input_count;
int status;
size_t plugin_count;
- bt_query_executor *query_executor = NULL;
input_count = bt_value_array_get_size(inputs);
plugin_count = get_loaded_plugins_count();
- query_executor = bt_query_executor_create();
- if (!query_executor) {
- BT_CLI_LOGE_APPEND_CAUSE("Failed to allocate a query executor.");
- goto end;
- }
-
for (i_inputs = 0; i_inputs < input_count; i_inputs++) {
const bt_value *input_value;
const char *input;
input_value = bt_value_array_borrow_element_by_index_const(inputs, i_inputs);
input = bt_value_string_get(input_value);
- status = auto_discover_source_for_input_as_string(input, query_executor,
+ status = auto_discover_source_for_input_as_string(input, i_inputs,
plugin_count, plugin_restrict, component_class_restrict,
log_level, auto_disc);
if (status < 0) {
}
status = auto_discover_source_for_input_as_dir_or_file(input,
- query_executor, plugin_count, plugin_restrict,
+ i_inputs, plugin_count, plugin_restrict,
component_class_restrict, log_level, auto_disc);
if (status < 0) {
/* Fatal error. */
status = 0;
end:
- bt_query_executor_put_ref(query_executor);
return status;
}