src.ctf.fs: add stream port name to trace-info query, use it for stream intersection
[babeltrace.git] / cli / babeltrace.c
index 5abbcd0d8c065a3a3c51966f367de2245b66b6c6..913a74216c2d600d15a916e2ad3ae16d6059844d 100644 (file)
 static const char* log_level_env_var_names[] = {
        "BABELTRACE_COMMON_LOG_LEVEL",
        "BABELTRACE_COMPAT_LOG_LEVEL",
-       "BABELTRACE_PLUGIN_CTF_BTR_LOG_LEVEL",
-       "BABELTRACE_SINK_CTF_FS_LOG_LEVEL",
-       "BABELTRACE_SRC_CTF_FS_LOG_LEVEL",
-       "BABELTRACE_SRC_CTF_LTTNG_LIVE_LOG_LEVEL",
-       "BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL",
-       "BABELTRACE_PLUGIN_CTF_MSG_ITER_LOG_LEVEL",
-       "BABELTRACE_PLUGIN_CTFCOPYTRACE_LIB_LOG_LEVEL",
+       "BABELTRACE_CTFSER_LOG_LEVEL",
+       "BABELTRACE_FD_CACHE_LOG_LEVEL",
        "BABELTRACE_FLT_LTTNG_UTILS_DEBUG_INFO_LOG_LEVEL",
-       "BABELTRACE_SRC_TEXT_DMESG_LOG_LEVEL",
-       "BABELTRACE_SINK_TEXT_PRETTY_LOG_LEVEL",
+       "BABELTRACE_FLT_UTILS_COUNTER_LOG_LEVEL",
        "BABELTRACE_FLT_UTILS_MUXER_LOG_LEVEL",
        "BABELTRACE_FLT_UTILS_TRIMMER_LOG_LEVEL",
+       "BABELTRACE_PLUGIN_CTF_BFCR_LOG_LEVEL",
+       "BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL",
+       "BABELTRACE_PLUGIN_CTF_MSG_ITER_LOG_LEVEL",
+       "BABELTRACE_PLUGIN_CTF_UTILS_LOG_LEVEL",
        "BABELTRACE_PYTHON_BT2_LOG_LEVEL",
-       "BABELTRACE_PYTHON_PLUGIN_PROVIDER_LOG_LEVEL",
+       "BABELTRACE_SINK_CTF_FS_LOG_LEVEL",
+       "BABELTRACE_SINK_TEXT_PRETTY_LOG_LEVEL",
+       "BABELTRACE_SRC_CTF_FS_LOG_LEVEL",
+       "BABELTRACE_SRC_CTF_LTTNG_LIVE_LOG_LEVEL",
+       "BABELTRACE_SRC_TEXT_DMESG_LOG_LEVEL",
        NULL,
 };
 
@@ -174,7 +176,7 @@ int query(const bt_component_class *comp_cls, const char *obj,
                const char **fail_reason)
 {
        const bt_value *result = NULL;
-       enum bt_query_executor_status status;
+       bt_query_executor_status status;
        *fail_reason = "unknown error";
        int ret = 0;
 
@@ -360,7 +362,7 @@ const bt_component_class_sink *find_sink_component_class(
 static
 const bt_component_class *find_component_class(const char *plugin_name,
                const char *comp_class_name,
-               enum bt_component_class_type comp_class_type)
+               bt_component_class_type comp_class_type)
 {
        const bt_component_class *comp_cls = NULL;
 
@@ -392,7 +394,7 @@ void print_indent(FILE *fp, size_t indent)
 }
 
 static
-const char *component_type_str(enum bt_component_class_type type)
+const char *component_type_str(bt_component_class_type type)
 {
        switch (type) {
        case BT_COMPONENT_CLASS_TYPE_SOURCE:
@@ -408,7 +410,7 @@ const char *component_type_str(enum bt_component_class_type type)
 
 static
 void print_plugin_comp_cls_opt(FILE *fh, const char *plugin_name,
-               const char *comp_cls_name, enum bt_component_class_type type)
+               const char *comp_cls_name, bt_component_class_type type)
 {
        GString *shell_plugin_name = NULL;
        GString *shell_comp_cls_name = NULL;
@@ -493,6 +495,7 @@ void print_value_rec(FILE *fp, const bt_value *value, size_t indent)
 {
        bt_bool bool_val;
        int64_t int_val;
+       uint64_t uint_val;
        double dbl_val;
        const char *str_val;
        int size;
@@ -513,8 +516,14 @@ void print_value_rec(FILE *fp, const bt_value *value, size_t indent)
                        bt_common_color_fg_cyan(), bool_val ? "yes" : "no",
                        bt_common_color_reset());
                break;
-       case BT_VALUE_TYPE_INTEGER:
-               int_val = bt_value_integer_get(value);
+       case BT_VALUE_TYPE_UNSIGNED_INTEGER:
+               uint_val = bt_value_unsigned_integer_get(value);
+               fprintf(fp, "%s%s%" PRIu64 "%s\n", bt_common_color_bold(),
+                       bt_common_color_fg_red(), uint_val,
+                       bt_common_color_reset());
+               break;
+       case BT_VALUE_TYPE_SIGNED_INTEGER:
+               int_val = bt_value_signed_integer_get(value);
                fprintf(fp, "%s%s%" PRId64 "%s\n", bt_common_color_bold(),
                        bt_common_color_fg_red(), int_val,
                        bt_common_color_reset());
@@ -883,7 +892,7 @@ void print_plugin_info(const bt_plugin *plugin)
 {
        unsigned int major, minor, patch;
        const char *extra;
-       enum bt_property_availability version_avail;
+       bt_property_availability version_avail;
        const char *plugin_name;
        const char *path;
        const char *author;
@@ -1010,7 +1019,7 @@ void print_component_class_help(const char *plugin_name,
                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_type type =
                bt_component_class_get_type(comp_cls);
 
        print_plugin_comp_cls_opt(stdout, plugin_name, comp_class_name, type);
@@ -1110,13 +1119,15 @@ void cmd_list_plugins_print_component_classes(const bt_plugin *plugin,
        uint64_t i;
 
        if (count == 0) {
-               printf("  %s%s component classes%s: (none)\n", cc_type_name,
+               printf("  %s%s component classes%s: (none)\n",
                        bt_common_color_bold(),
+                       cc_type_name,
                        bt_common_color_reset());
                goto end;
        } else {
-               printf("  %s%s component classes%s:\n", cc_type_name,
+               printf("  %s%s component classes%s:\n",
                        bt_common_color_bold(),
+                       cc_type_name,
                        bt_common_color_reset());
        }
 
@@ -1128,7 +1139,7 @@ void cmd_list_plugins_print_component_classes(const bt_plugin *plugin,
                        bt_component_class_get_name(comp_class);
                const char *comp_class_description =
                        bt_component_class_get_description(comp_class);
-               enum bt_component_class_type type =
+               bt_component_class_type type =
                        bt_component_class_get_type(comp_class);
 
                printf("    ");
@@ -1187,19 +1198,19 @@ int cmd_list_plugins(struct bt_config *cfg)
                cmd_list_plugins_print_component_classes(plugin, "Source",
                        bt_plugin_get_source_component_class_count(plugin),
                        (plugin_borrow_comp_cls_by_index_func_t)
-                               bt_plugin_borrow_source_component_class_by_name_const,
+                               bt_plugin_borrow_source_component_class_by_index_const,
                        (spec_comp_cls_borrow_comp_cls_func_t)
                                bt_component_class_source_as_component_class);
                cmd_list_plugins_print_component_classes(plugin, "Filter",
                        bt_plugin_get_filter_component_class_count(plugin),
                        (plugin_borrow_comp_cls_by_index_func_t)
-                               bt_plugin_borrow_filter_component_class_by_name_const,
+                               bt_plugin_borrow_filter_component_class_by_index_const,
                        (spec_comp_cls_borrow_comp_cls_func_t)
                                bt_component_class_filter_as_component_class);
                cmd_list_plugins_print_component_classes(plugin, "Sink",
                        bt_plugin_get_sink_component_class_count(plugin),
                        (plugin_borrow_comp_cls_by_index_func_t)
-                               bt_plugin_borrow_sink_component_class_by_name_const,
+                               bt_plugin_borrow_sink_component_class_by_index_const,
                        (spec_comp_cls_borrow_comp_cls_func_t)
                                bt_component_class_sink_as_component_class);
        }
@@ -1219,7 +1230,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
        const bt_value *v = NULL;
        static const char * const plugin_name = "ctf";
        static const char * const comp_cls_name = "lttng-live";
-       static const enum bt_component_class_type comp_cls_type =
+       static const bt_component_class_type comp_cls_type =
                BT_COMPONENT_CLASS_TYPE_SOURCE;
        int64_t array_size, i;
        const char *fail_reason = NULL;
@@ -1311,21 +1322,21 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                        BT_LOGE_STR("Unexpected empty array \"timer-us\" entry.");
                        goto error;
                }
-               timer_us = bt_value_integer_get(v);
+               timer_us = bt_value_signed_integer_get(v);
                fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us);
                v = bt_value_map_borrow_entry_value_const(map, "stream-count");
                if (!v) {
                        BT_LOGE_STR("Unexpected empty array \"stream-count\" entry.");
                        goto error;
                }
-               streams = bt_value_integer_get(v);
+               streams = bt_value_signed_integer_get(v);
                fprintf(out_stream, "%" PRIu64 " stream(s), ", streams);
                v = bt_value_map_borrow_entry_value_const(map, "client-count");
                if (!v) {
                        BT_LOGE_STR("Unexpected empty array \"client-count\" entry.");
                        goto error;
                }
-               clients = bt_value_integer_get(v);
+               clients = bt_value_signed_integer_get(v);
                fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients);
        }
 
@@ -1357,7 +1368,7 @@ end:
                }
        }
 
-       return 0;
+       return ret;
 }
 
 static
@@ -1371,7 +1382,7 @@ int cmd_print_ctf_metadata(struct bt_config *cfg)
        const char *metadata_text = NULL;
        static const char * const plugin_name = "ctf";
        static const char * const comp_cls_name = "fs";
-       static const enum bt_component_class_type comp_cls_type =
+       static const bt_component_class_type comp_cls_type =
                BT_COMPONENT_CLASS_TYPE_SOURCE;
        const char *fail_reason = NULL;
        FILE *out_stream = stdout;
@@ -1441,8 +1452,11 @@ int cmd_print_ctf_metadata(struct bt_config *cfg)
        if (ret < 0) {
                BT_LOGE("Cannot write whole metadata text to output stream: "
                        "ret=%d", ret);
+               goto end;
        }
 
+       ret = 0;
+
        goto end;
 
 failed:
@@ -1469,7 +1483,7 @@ end:
                }
        }
 
-       return 0;
+       return ret;
 }
 
 struct port_id {
@@ -1610,7 +1624,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component(
        uint64_t i;
        input_port_count_func_t port_count_fn;
        borrow_input_port_by_index_func_t port_by_index_fn;
-       enum bt_graph_status status = BT_GRAPH_STATUS_ERROR;
+       bt_graph_status status = BT_GRAPH_STATUS_ERROR;
        bool insert_trimmer = false;
        bt_value *trimmer_params = NULL;
        char *intersection_begin = NULL;
@@ -1636,7 +1650,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component(
                range = (struct trace_range *) g_hash_table_lookup(
                        ctx->intersections, &port_id);
                if (range) {
-                       enum bt_value_status status;
+                       bt_value_status status;
 
                        intersection_begin = s_from_ns(
                                range->intersection_range_begin_ns);
@@ -1707,7 +1721,6 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component(
        }
 
        downstream_port_count = port_count_fn(downstream_comp);
-       BT_ASSERT(downstream_port_count >= 0);
 
        for (i = 0; i < downstream_port_count; i++) {
                const bt_port_input *in_downstream_port =
@@ -1756,7 +1769,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component(
                         * source and the trimmer.
                         */
                        char *trimmer_name = NULL;
-                       enum bt_graph_status graph_status;
+                       bt_graph_status graph_status;
 
                        ret = asprintf(&trimmer_name,
                                "stream-intersection-trimmer-%s",
@@ -1988,11 +2001,13 @@ end:
 }
 
 static
-void graph_output_port_added_listener(struct cmd_run_ctx *ctx,
+bt_graph_listener_status
+graph_output_port_added_listener(struct cmd_run_ctx *ctx,
                const bt_port_output *out_port)
 {
        const bt_component *comp;
        const bt_port *port = bt_port_output_as_port_const(out_port);
+       bt_graph_listener_status ret = BT_GRAPH_LISTENER_STATUS_OK;
 
        comp = bt_port_borrow_component_const(port);
        BT_LOGI("Port added to a graph's component: comp-addr=%p, "
@@ -2017,27 +2032,28 @@ void graph_output_port_added_listener(struct cmd_run_ctx *ctx,
        if (cmd_run_ctx_connect_upstream_port(ctx, out_port)) {
                BT_LOGF_STR("Cannot connect upstream port.");
                fprintf(stderr, "Added port could not be connected: aborting\n");
-               abort();
+               ret = BT_GRAPH_LISTENER_STATUS_ERROR;
+               goto end;
        }
 
 end:
-       return;
+       return ret;
 }
 
 static
-void graph_source_output_port_added_listener(
+bt_graph_listener_status graph_source_output_port_added_listener(
                const bt_component_source *component,
                const bt_port_output *port, void *data)
 {
-       graph_output_port_added_listener(data, port);
+       return graph_output_port_added_listener(data, port);
 }
 
 static
-void graph_filter_output_port_added_listener(
+bt_graph_listener_status graph_filter_output_port_added_listener(
                const bt_component_filter *component,
                const bt_port_output *port, void *data)
 {
-       graph_output_port_added_listener(data, port);
+       return graph_output_port_added_listener(data, port);
 }
 
 static
@@ -2076,7 +2092,7 @@ static
 int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg)
 {
        int ret = 0;
-       enum bt_graph_status status;
+       bt_graph_status status;
 
        ctx->cfg = cfg;
        ctx->connect_ports = false;
@@ -2147,17 +2163,12 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
        int ret = 0;
        uint64_t trace_idx;
        int64_t trace_count;
-       enum bt_value_status value_status;
        const char *path = NULL;
-       const bt_value *component_path_value = NULL;
-       bt_value *query_params = NULL;
        const bt_value *query_result = NULL;
        const bt_value *trace_info = NULL;
        const bt_value *intersection_range = NULL;
        const bt_value *intersection_begin = NULL;
        const bt_value *intersection_end = NULL;
-       const bt_value *stream_path_value = NULL;
-       const bt_value *stream_paths = NULL;
        const bt_value *stream_infos = NULL;
        const bt_value *stream_info = NULL;
        struct port_id *port_id = NULL;
@@ -2166,33 +2177,8 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
        const bt_component_class *comp_cls =
                bt_component_class_source_as_component_class_const(src_comp_cls);
 
-       component_path_value = bt_value_map_borrow_entry_value(cfg_comp->params,
-                                                              "path");
-       if (component_path_value && !bt_value_is_string(component_path_value)) {
-               BT_LOGD("Cannot get path parameter: component-name=%s",
-                       cfg_comp->instance_name->str);
-               ret = -1;
-               goto error;
-       }
-
-       path = bt_value_string_get(component_path_value);
-       query_params = bt_value_map_create();
-       if (!query_params) {
-               BT_LOGE_STR("Cannot create query parameters.");
-               ret = -1;
-               goto error;
-       }
-
-       value_status = bt_value_map_insert_string_entry(query_params, "path",
-               path);
-       if (value_status != BT_VALUE_STATUS_OK) {
-               BT_LOGE_STR("Cannot insert path parameter in query parameter map.");
-               ret = -1;
-               goto error;
-       }
-
        ret = query(comp_cls, "trace-info",
-               query_params, &query_result,
+               cfg_comp->params, &query_result,
                &fail_reason);
        if (ret) {
                BT_LOGD("Component class does not support the `trace-info` query: %s: "
@@ -2255,8 +2241,8 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
                        goto error;
                }
 
-               begin = bt_value_integer_get(intersection_begin);
-               end = bt_value_integer_get(intersection_end);
+               begin = bt_value_signed_integer_get(intersection_begin);
+               end = bt_value_signed_integer_get(intersection_end);
 
                if (begin < 0 || end < 0 || end < begin) {
                        BT_LOGW("Invalid trace stream intersection values: "
@@ -2281,20 +2267,8 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
                        goto error;
                }
 
-               /*
-                * FIXME
-                *
-                * The first path of a stream's "paths" is currently used to
-                * associate streams/ports to a given trace intersection.
-                *
-                * This is a fragile hack as it relies on the port names
-                * being set to the various streams path.
-                *
-                * A stream name should be introduced as part of the trace-info
-                * query result.
-                */
                for (stream_idx = 0; stream_idx < stream_count; stream_idx++) {
-                       const char *stream_path;
+                       const bt_value *port_name;
 
                        port_id = g_new0(struct port_id, 1);
                        if (!port_id) {
@@ -2326,26 +2300,14 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
                                goto error;
                        }
 
-                       stream_paths = bt_value_map_borrow_entry_value_const(stream_info,
-                                                                            "paths");
-                       if (!stream_paths || !bt_value_is_array(stream_paths)) {
+                       port_name = bt_value_map_borrow_entry_value_const(stream_info, "port-name");
+                       if (!port_name || !bt_value_is_string(port_name)) {
                                ret = -1;
-                               BT_LOGD_STR("Cannot retrieve stream paths from trace in query result.");
+                               BT_LOGD_STR("Cannot retrieve port name in query result.");
                                goto error;
                        }
 
-                       stream_path_value =
-                               bt_value_array_borrow_element_by_index_const(
-                                       stream_paths, 0);
-                       if (!stream_path_value ||
-                               !bt_value_is_string(stream_path_value)) {
-                               ret = -1;
-                               BT_LOGD_STR("Cannot retrieve stream path value from trace in query result.");
-                               goto error;
-                       }
-
-                       stream_path = bt_value_string_get(stream_path_value);
-                       port_id->port_name = strdup(stream_path);
+                       port_id->port_name = g_strdup(bt_value_string_get(port_name));
                        if (!port_id->port_name) {
                                ret = -1;
                                BT_LOGE_STR("Cannot allocate memory for port_id port_name.");
@@ -2370,7 +2332,6 @@ error:
                path ? path : "(unknown)",
                bt_common_color_reset());
 end:
-       bt_value_put_ref(query_params);
        bt_value_put_ref(query_result);
        g_free(port_id);
        g_free(trace_range);
@@ -2564,7 +2525,6 @@ int cmd_run_ctx_connect_comp_ports(struct cmd_run_ctx *ctx,
        uint64_t i;
 
        count = port_count_fn(comp);
-       BT_ASSERT(count >= 0);
 
        for (i = 0; i < count; i++) {
                const bt_port_output *upstream_port = port_by_index_fn(comp, i);
@@ -2619,7 +2579,7 @@ end:
 }
 
 static inline
-const char *bt_graph_status_str(enum bt_graph_status status)
+const char *bt_graph_status_str(bt_graph_status status)
 {
        switch (status) {
        case BT_GRAPH_STATUS_OK:
@@ -2634,8 +2594,6 @@ const char *bt_graph_status_str(enum bt_graph_status status)
                return "BT_GRAPH_STATUS_CANCELED";
        case BT_GRAPH_STATUS_ERROR:
                return "BT_GRAPH_STATUS_ERROR";
-       case BT_GRAPH_STATUS_NO_SINK:
-               return "BT_GRAPH_STATUS_NO_SINK";
        case BT_GRAPH_STATUS_NOMEM:
                return "BT_GRAPH_STATUS_NOMEM";
        default:
@@ -2693,7 +2651,7 @@ int cmd_run(struct bt_config *cfg)
 
        /* Run the graph */
        while (true) {
-               enum bt_graph_status graph_status = bt_graph_run(ctx.graph);
+               bt_graph_status graph_status = bt_graph_run(ctx.graph);
 
                /*
                 * Reset console in case something messed with console
This page took 0.031456 seconds and 4 git commands to generate.