4 * Babeltrace Trace Converter
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/babeltrace.h>
30 #include <babeltrace/plugin/plugin.h>
31 #include <babeltrace/common-internal.h>
32 #include <babeltrace/graph/component.h>
33 #include <babeltrace/graph/component-source.h>
34 #include <babeltrace/graph/component-sink.h>
35 #include <babeltrace/graph/component-filter.h>
36 #include <babeltrace/graph/component-class.h>
37 #include <babeltrace/graph/port.h>
38 #include <babeltrace/graph/graph.h>
39 #include <babeltrace/graph/connection.h>
40 #include <babeltrace/graph/notification-iterator.h>
41 #include <babeltrace/ref.h>
42 #include <babeltrace/values.h>
43 #include <babeltrace/logging.h>
52 #include "babeltrace-cfg.h"
53 #include "babeltrace-cfg-cli-args.h"
54 #include "babeltrace-cfg-cli-args-default.h"
56 #define BT_LOG_TAG "CLI"
59 #define ENV_BABELTRACE_WARN_COMMAND_NAME_DIRECTORY_CLASH "BABELTRACE_CLI_WARN_COMMAND_NAME_DIRECTORY_CLASH"
61 GPtrArray
*loaded_plugins
;
64 int bt_cli_log_level
= BT_LOG_NONE
;
67 void init_static_data(void)
69 loaded_plugins
= g_ptr_array_new_with_free_func(bt_put
);
73 void fini_static_data(void)
75 g_ptr_array_free(loaded_plugins
, TRUE
);
79 struct bt_plugin
*find_plugin(const char *name
)
82 struct bt_plugin
*plugin
= NULL
;
85 BT_LOGD("Finding plugin: name=\"%s\"", name
);
87 for (i
= 0; i
< loaded_plugins
->len
; i
++) {
88 plugin
= g_ptr_array_index(loaded_plugins
, i
);
90 if (strcmp(name
, bt_plugin_get_name(plugin
)) == 0) {
97 if (BT_LOG_ON_DEBUG
) {
99 BT_LOGD("Found plugin: plugin-addr=%p", plugin
);
101 BT_LOGD("Cannot find plugin.");
105 return bt_get(plugin
);
109 struct bt_component_class
*find_component_class(const char *plugin_name
,
110 const char *comp_class_name
,
111 enum bt_component_class_type comp_class_type
)
113 struct bt_component_class
*comp_class
= NULL
;
114 struct bt_plugin
*plugin
;
116 BT_LOGD("Finding component class: plugin-name=\"%s\", "
117 "comp-cls-name=\"%s\", comp-cls-type=%d",
118 plugin_name
, comp_class_name
, comp_class_type
);
120 plugin
= find_plugin(plugin_name
);
126 comp_class
= bt_plugin_get_component_class_by_name_and_type(plugin
,
127 comp_class_name
, comp_class_type
);
131 if (BT_LOG_ON_DEBUG
) {
133 BT_LOGD("Found component class: comp-cls-addr=%p",
136 BT_LOGD("Cannot find component class.");
144 void print_indent(FILE *fp
, size_t indent
)
148 for (i
= 0; i
< indent
; i
++) {
154 const char *component_type_str(enum bt_component_class_type type
)
157 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
159 case BT_COMPONENT_CLASS_TYPE_SINK
:
161 case BT_COMPONENT_CLASS_TYPE_FILTER
:
163 case BT_COMPONENT_CLASS_TYPE_UNKNOWN
:
170 void print_plugin_comp_cls_opt(FILE *fh
, const char *plugin_name
,
171 const char *comp_cls_name
, enum bt_component_class_type type
)
173 GString
*shell_plugin_name
= NULL
;
174 GString
*shell_comp_cls_name
= NULL
;
176 shell_plugin_name
= bt_common_shell_quote(plugin_name
, false);
177 if (!shell_plugin_name
) {
181 shell_comp_cls_name
= bt_common_shell_quote(comp_cls_name
, false);
182 if (!shell_comp_cls_name
) {
186 fprintf(fh
, "%s%s--%s%s %s'%s%s%s%s.%s%s%s'",
187 bt_common_color_bold(),
188 bt_common_color_fg_cyan(),
189 component_type_str(type
),
190 bt_common_color_reset(),
191 bt_common_color_fg_default(),
192 bt_common_color_bold(),
193 bt_common_color_fg_blue(),
194 shell_plugin_name
->str
,
195 bt_common_color_fg_default(),
196 bt_common_color_fg_yellow(),
197 shell_comp_cls_name
->str
,
198 bt_common_color_reset());
201 if (shell_plugin_name
) {
202 g_string_free(shell_plugin_name
, TRUE
);
205 if (shell_comp_cls_name
) {
206 g_string_free(shell_comp_cls_name
, TRUE
);
211 void print_value(FILE *, struct bt_value
*, size_t);
214 void print_value_rec(FILE *, struct bt_value
*, size_t);
216 struct print_map_value_data
{
222 bt_bool
print_map_value(const char *key
, struct bt_value
*object
, void *data
)
224 struct print_map_value_data
*print_map_value_data
= data
;
226 print_indent(print_map_value_data
->fp
, print_map_value_data
->indent
);
227 fprintf(print_map_value_data
->fp
, "%s: ", key
);
229 if (bt_value_is_array(object
) &&
230 bt_value_array_is_empty(object
)) {
231 fprintf(print_map_value_data
->fp
, "[ ]\n");
235 if (bt_value_is_map(object
) &&
236 bt_value_map_is_empty(object
)) {
237 fprintf(print_map_value_data
->fp
, "{ }\n");
241 if (bt_value_is_array(object
) ||
242 bt_value_is_map(object
)) {
243 fprintf(print_map_value_data
->fp
, "\n");
246 print_value_rec(print_map_value_data
->fp
, object
,
247 print_map_value_data
->indent
+ 2);
252 void print_value_rec(FILE *fp
, struct bt_value
*value
, size_t indent
)
265 switch (bt_value_get_type(value
)) {
266 case BT_VALUE_TYPE_NULL
:
267 fprintf(fp
, "%snull%s\n", bt_common_color_bold(),
268 bt_common_color_reset());
270 case BT_VALUE_TYPE_BOOL
:
271 bt_value_bool_get(value
, &bool_val
);
272 fprintf(fp
, "%s%s%s%s\n", bt_common_color_bold(),
273 bt_common_color_fg_cyan(), bool_val
? "yes" : "no",
274 bt_common_color_reset());
276 case BT_VALUE_TYPE_INTEGER
:
277 bt_value_integer_get(value
, &int_val
);
278 fprintf(fp
, "%s%s%" PRId64
"%s\n", bt_common_color_bold(),
279 bt_common_color_fg_red(), int_val
,
280 bt_common_color_reset());
282 case BT_VALUE_TYPE_FLOAT
:
283 bt_value_float_get(value
, &dbl_val
);
284 fprintf(fp
, "%s%s%lf%s\n", bt_common_color_bold(),
285 bt_common_color_fg_red(), dbl_val
,
286 bt_common_color_reset());
288 case BT_VALUE_TYPE_STRING
:
289 bt_value_string_get(value
, &str_val
);
290 fprintf(fp
, "%s%s%s%s\n", bt_common_color_bold(),
291 bt_common_color_fg_green(), str_val
,
292 bt_common_color_reset());
294 case BT_VALUE_TYPE_ARRAY
:
295 size
= bt_value_array_size(value
);
299 print_indent(fp
, indent
);
300 fprintf(fp
, "[ ]\n");
304 for (i
= 0; i
< size
; i
++) {
305 struct bt_value
*element
=
306 bt_value_array_get(value
, i
);
309 print_indent(fp
, indent
);
312 if (bt_value_is_array(element
) &&
313 bt_value_array_is_empty(element
)) {
314 fprintf(fp
, "[ ]\n");
318 if (bt_value_is_map(element
) &&
319 bt_value_map_is_empty(element
)) {
320 fprintf(fp
, "{ }\n");
324 if (bt_value_is_array(element
) ||
325 bt_value_is_map(element
)) {
329 print_value_rec(fp
, element
, indent
+ 2);
333 case BT_VALUE_TYPE_MAP
:
335 struct print_map_value_data data
= {
340 if (bt_value_map_is_empty(value
)) {
341 print_indent(fp
, indent
);
342 fprintf(fp
, "{ }\n");
346 bt_value_map_foreach(value
, print_map_value
, &data
);
355 void print_value(FILE *fp
, struct bt_value
*value
, size_t indent
)
357 if (!bt_value_is_array(value
) && !bt_value_is_map(value
)) {
358 print_indent(fp
, indent
);
361 print_value_rec(fp
, value
, indent
);
365 void print_bt_config_component(struct bt_config_component
*bt_config_component
)
367 fprintf(stderr
, " ");
368 print_plugin_comp_cls_opt(stderr
, bt_config_component
->plugin_name
->str
,
369 bt_config_component
->comp_cls_name
->str
,
370 bt_config_component
->type
);
371 fprintf(stderr
, ":\n");
373 if (bt_config_component
->instance_name
->len
> 0) {
374 fprintf(stderr
, " Name: %s\n",
375 bt_config_component
->instance_name
->str
);
378 fprintf(stderr
, " Parameters:\n");
379 print_value(stderr
, bt_config_component
->params
, 8);
383 void print_bt_config_components(GPtrArray
*array
)
387 for (i
= 0; i
< array
->len
; i
++) {
388 struct bt_config_component
*cfg_component
=
389 bt_config_get_component(array
, i
);
390 print_bt_config_component(cfg_component
);
391 BT_PUT(cfg_component
);
396 void print_plugin_paths(struct bt_value
*plugin_paths
)
398 fprintf(stderr
, " Plugin paths:\n");
399 print_value(stderr
, plugin_paths
, 4);
403 void print_cfg_run(struct bt_config
*cfg
)
407 print_plugin_paths(cfg
->plugin_paths
);
408 fprintf(stderr
, " Source component instances:\n");
409 print_bt_config_components(cfg
->cmd_data
.run
.sources
);
411 if (cfg
->cmd_data
.run
.filters
->len
> 0) {
412 fprintf(stderr
, " Filter component instances:\n");
413 print_bt_config_components(cfg
->cmd_data
.run
.filters
);
416 fprintf(stderr
, " Sink component instances:\n");
417 print_bt_config_components(cfg
->cmd_data
.run
.sinks
);
418 fprintf(stderr
, " Connections:\n");
420 for (i
= 0; i
< cfg
->cmd_data
.run
.connections
->len
; i
++) {
421 struct bt_config_connection
*cfg_connection
=
422 g_ptr_array_index(cfg
->cmd_data
.run
.connections
,
425 fprintf(stderr
, " %s%s%s -> %s%s%s\n",
426 cfg_connection
->upstream_comp_name
->str
,
427 cfg_connection
->upstream_port_glob
->len
> 0 ? "." : "",
428 cfg_connection
->upstream_port_glob
->str
,
429 cfg_connection
->downstream_comp_name
->str
,
430 cfg_connection
->downstream_port_glob
->len
> 0 ? "." : "",
431 cfg_connection
->downstream_port_glob
->str
);
436 void print_cfg_list_plugins(struct bt_config
*cfg
)
438 print_plugin_paths(cfg
->plugin_paths
);
442 void print_cfg_help(struct bt_config
*cfg
)
444 print_plugin_paths(cfg
->plugin_paths
);
448 void print_cfg_print_ctf_metadata(struct bt_config
*cfg
)
450 print_plugin_paths(cfg
->plugin_paths
);
451 fprintf(stderr
, " Path: %s\n",
452 cfg
->cmd_data
.print_ctf_metadata
.path
->str
);
456 void print_cfg_print_lttng_live_sessions(struct bt_config
*cfg
)
458 print_plugin_paths(cfg
->plugin_paths
);
459 fprintf(stderr
, " URL: %s\n",
460 cfg
->cmd_data
.print_lttng_live_sessions
.url
->str
);
464 void print_cfg_query(struct bt_config
*cfg
)
466 print_plugin_paths(cfg
->plugin_paths
);
467 fprintf(stderr
, " Object: `%s`\n", cfg
->cmd_data
.query
.object
->str
);
468 fprintf(stderr
, " Component class:\n");
469 print_bt_config_component(cfg
->cmd_data
.query
.cfg_component
);
473 void print_cfg(struct bt_config
*cfg
)
475 if (!BT_LOG_ON_INFO
) {
479 BT_LOGI_STR("Configuration:");
480 fprintf(stderr
, " Debug mode: %s\n", cfg
->debug
? "yes" : "no");
481 fprintf(stderr
, " Verbose mode: %s\n", cfg
->verbose
? "yes" : "no");
483 switch (cfg
->command
) {
484 case BT_CONFIG_COMMAND_RUN
:
487 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
488 print_cfg_list_plugins(cfg
);
490 case BT_CONFIG_COMMAND_HELP
:
493 case BT_CONFIG_COMMAND_QUERY
:
494 print_cfg_query(cfg
);
496 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
497 print_cfg_print_ctf_metadata(cfg
);
499 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
500 print_cfg_print_lttng_live_sessions(cfg
);
508 void add_to_loaded_plugins(struct bt_plugin_set
*plugin_set
)
513 count
= bt_plugin_set_get_plugin_count(plugin_set
);
516 for (i
= 0; i
< count
; i
++) {
517 struct bt_plugin
*plugin
=
518 bt_plugin_set_get_plugin(plugin_set
, i
);
519 struct bt_plugin
*loaded_plugin
=
520 find_plugin(bt_plugin_get_name(plugin
));
525 BT_LOGI("Not using plugin: another one already exists with the same name: "
526 "plugin-name=\"%s\", plugin-path=\"%s\", "
527 "existing-plugin-path=\"%s\"",
528 bt_plugin_get_name(plugin
),
529 bt_plugin_get_path(plugin
),
530 bt_plugin_get_path(loaded_plugin
));
531 bt_put(loaded_plugin
);
533 /* Add to global array. */
534 BT_LOGD("Adding plugin to loaded plugins: plugin-path=\"%s\"",
535 bt_plugin_get_name(plugin
));
536 g_ptr_array_add(loaded_plugins
, bt_get(plugin
));
544 int load_dynamic_plugins(struct bt_value
*plugin_paths
)
546 int nr_paths
, i
, ret
= 0;
548 nr_paths
= bt_value_array_size(plugin_paths
);
550 BT_LOGE_STR("Cannot load dynamic plugins: no plugin path.");
555 BT_LOGI("Loading dynamic plugins.");
557 for (i
= 0; i
< nr_paths
; i
++) {
558 struct bt_value
*plugin_path_value
= NULL
;
559 const char *plugin_path
;
560 struct bt_plugin_set
*plugin_set
;
562 plugin_path_value
= bt_value_array_get(plugin_paths
, i
);
563 bt_value_string_get(plugin_path_value
, &plugin_path
);
565 plugin_set
= bt_plugin_create_all_from_dir(plugin_path
, false);
567 BT_LOGD("Unable to load dynamic plugins: path=\"%s\"",
569 BT_PUT(plugin_path_value
);
573 add_to_loaded_plugins(plugin_set
);
575 BT_PUT(plugin_path_value
);
582 int load_static_plugins(void)
585 struct bt_plugin_set
*plugin_set
;
587 BT_LOGI("Loading static plugins.");
588 plugin_set
= bt_plugin_create_all_from_static();
590 BT_LOGE("Unable to load static plugins.");
595 add_to_loaded_plugins(plugin_set
);
602 int load_all_plugins(struct bt_value
*plugin_paths
)
606 if (load_dynamic_plugins(plugin_paths
)) {
611 if (load_static_plugins()) {
616 BT_LOGI("Loaded all plugins: count=%u", loaded_plugins
->len
);
623 void print_plugin_info(struct bt_plugin
*plugin
)
625 unsigned int major
, minor
, patch
;
627 enum bt_plugin_status version_status
;
628 const char *plugin_name
;
632 const char *plugin_description
;
634 plugin_name
= bt_plugin_get_name(plugin
);
635 path
= bt_plugin_get_path(plugin
);
636 author
= bt_plugin_get_author(plugin
);
637 license
= bt_plugin_get_license(plugin
);
638 plugin_description
= bt_plugin_get_description(plugin
);
639 version_status
= bt_plugin_get_version(plugin
, &major
, &minor
,
641 printf("%s%s%s%s:\n", bt_common_color_bold(),
642 bt_common_color_fg_blue(), plugin_name
,
643 bt_common_color_reset());
644 printf(" %sPath%s: %s\n", bt_common_color_bold(),
645 bt_common_color_reset(), path
? path
: "(None)");
647 if (version_status
== BT_PLUGIN_STATUS_OK
) {
648 printf(" %sVersion%s: %u.%u.%u",
649 bt_common_color_bold(), bt_common_color_reset(),
650 major
, minor
, patch
);
659 printf(" %sDescription%s: %s\n", bt_common_color_bold(),
660 bt_common_color_reset(),
661 plugin_description
? plugin_description
: "(None)");
662 printf(" %sAuthor%s: %s\n", bt_common_color_bold(),
663 bt_common_color_reset(), author
? author
: "(Unknown)");
664 printf(" %sLicense%s: %s\n", bt_common_color_bold(),
665 bt_common_color_reset(),
666 license
? license
: "(Unknown)");
670 int cmd_query(struct bt_config
*cfg
)
673 struct bt_component_class
*comp_cls
= NULL
;
674 struct bt_value
*results
= NULL
;
676 ret
= load_all_plugins(cfg
->plugin_paths
);
681 comp_cls
= find_component_class(cfg
->cmd_data
.query
.cfg_component
->plugin_name
->str
,
682 cfg
->cmd_data
.query
.cfg_component
->comp_cls_name
->str
,
683 cfg
->cmd_data
.query
.cfg_component
->type
);
685 BT_LOGE("Cannot find component class: plugin-name=\"%s\", "
686 "comp-cls-name=\"%s\", comp-cls-type=%d",
687 cfg
->cmd_data
.query
.cfg_component
->plugin_name
->str
,
688 cfg
->cmd_data
.query
.cfg_component
->comp_cls_name
->str
,
689 cfg
->cmd_data
.query
.cfg_component
->type
);
690 fprintf(stderr
, "%s%sCannot find component class %s",
691 bt_common_color_bold(),
692 bt_common_color_fg_red(),
693 bt_common_color_reset());
694 print_plugin_comp_cls_opt(stderr
,
695 cfg
->cmd_data
.query
.cfg_component
->plugin_name
->str
,
696 cfg
->cmd_data
.query
.cfg_component
->comp_cls_name
->str
,
697 cfg
->cmd_data
.query
.cfg_component
->type
);
698 fprintf(stderr
, "\n");
703 results
= bt_component_class_query(comp_cls
,
704 cfg
->cmd_data
.query
.object
->str
,
705 cfg
->cmd_data
.query
.cfg_component
->params
);
707 BT_LOGE("Failed to query component class: plugin-name=\"%s\", "
708 "comp-cls-name=\"%s\", comp-cls-type=%d "
710 cfg
->cmd_data
.query
.cfg_component
->plugin_name
->str
,
711 cfg
->cmd_data
.query
.cfg_component
->comp_cls_name
->str
,
712 cfg
->cmd_data
.query
.cfg_component
->type
,
713 cfg
->cmd_data
.query
.object
->str
);
714 fprintf(stderr
, "%s%sFailed to query info to %s",
715 bt_common_color_bold(),
716 bt_common_color_fg_red(),
717 bt_common_color_reset());
718 print_plugin_comp_cls_opt(stderr
,
719 cfg
->cmd_data
.query
.cfg_component
->plugin_name
->str
,
720 cfg
->cmd_data
.query
.cfg_component
->comp_cls_name
->str
,
721 cfg
->cmd_data
.query
.cfg_component
->type
);
722 fprintf(stderr
, "%s%s with object `%s`%s\n",
723 bt_common_color_bold(),
724 bt_common_color_fg_red(),
725 cfg
->cmd_data
.query
.object
->str
,
726 bt_common_color_reset());
731 print_value(stdout
, results
, 0);
740 int cmd_help(struct bt_config
*cfg
)
743 struct bt_plugin
*plugin
= NULL
;
746 ret
= load_all_plugins(cfg
->plugin_paths
);
751 plugin
= find_plugin(cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
);
753 BT_LOGE("Cannot find plugin: plugin-name=\"%s\"",
754 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
);
755 fprintf(stderr
, "%s%sCannot find plugin %s%s%s\n",
756 bt_common_color_bold(), bt_common_color_fg_red(),
757 bt_common_color_fg_blue(),
758 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
,
759 bt_common_color_reset());
764 print_plugin_info(plugin
);
765 printf(" %sComponent classes%s: %d\n",
766 bt_common_color_bold(),
767 bt_common_color_reset(),
768 (int) bt_plugin_get_component_class_count(plugin
));
771 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
772 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
773 struct bt_component_class
*needed_comp_cls
=
774 find_component_class(
775 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
,
776 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
->str
,
777 cfg
->cmd_data
.help
.cfg_component
->type
);
779 if (!needed_comp_cls
) {
780 BT_LOGE("Cannot find component class: plugin-name=\"%s\", "
781 "comp-cls-name=\"%s\", comp-cls-type=%d",
782 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
,
783 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
->str
,
784 cfg
->cmd_data
.help
.cfg_component
->type
);
785 fprintf(stderr
, "\n%s%sCannot find component class %s",
786 bt_common_color_bold(),
787 bt_common_color_fg_red(),
788 bt_common_color_reset());
789 print_plugin_comp_cls_opt(stderr
,
790 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
,
791 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
->str
,
792 cfg
->cmd_data
.help
.cfg_component
->type
);
793 fprintf(stderr
, "\n");
798 bt_put(needed_comp_cls
);
801 for (i
= 0; i
< bt_plugin_get_component_class_count(plugin
); i
++) {
802 struct bt_component_class
*comp_cls
=
803 bt_plugin_get_component_class_by_index(plugin
, i
);
804 const char *comp_class_name
=
805 bt_component_class_get_name(comp_cls
);
806 const char *comp_class_description
=
807 bt_component_class_get_description(comp_cls
);
808 const char *comp_class_help
=
809 bt_component_class_get_help(comp_cls
);
810 enum bt_component_class_type type
=
811 bt_component_class_get_type(comp_cls
);
815 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
816 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
817 if (strcmp(cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
->str
,
818 comp_class_name
) != 0 &&
820 cfg
->cmd_data
.help
.cfg_component
->type
) {
827 print_plugin_comp_cls_opt(stdout
,
828 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
,
832 printf(" %sDescription%s: %s\n", bt_common_color_bold(),
833 bt_common_color_reset(),
834 comp_class_description
? comp_class_description
: "(None)");
836 if (comp_class_help
) {
837 printf("\n%s\n", comp_class_help
);
849 int cmd_list_plugins(struct bt_config
*cfg
)
852 int plugins_count
, component_classes_count
= 0, i
;
854 ret
= load_all_plugins(cfg
->plugin_paths
);
859 printf("From the following plugin paths:\n\n");
860 print_value(stdout
, cfg
->plugin_paths
, 2);
862 plugins_count
= loaded_plugins
->len
;
863 if (plugins_count
== 0) {
864 printf("No plugins found.\n");
868 for (i
= 0; i
< plugins_count
; i
++) {
869 struct bt_plugin
*plugin
= g_ptr_array_index(loaded_plugins
, i
);
871 component_classes_count
+= bt_plugin_get_component_class_count(plugin
);
874 printf("Found %s%d%s component classes in %s%d%s plugins.\n",
875 bt_common_color_bold(),
876 component_classes_count
,
877 bt_common_color_reset(),
878 bt_common_color_bold(),
880 bt_common_color_reset());
882 for (i
= 0; i
< plugins_count
; i
++) {
884 struct bt_plugin
*plugin
= g_ptr_array_index(loaded_plugins
, i
);
886 component_classes_count
=
887 bt_plugin_get_component_class_count(plugin
);
889 print_plugin_info(plugin
);
891 if (component_classes_count
== 0) {
892 printf(" %sComponent classes%s: (none)\n",
893 bt_common_color_bold(),
894 bt_common_color_reset());
896 printf(" %sComponent classes%s:\n",
897 bt_common_color_bold(),
898 bt_common_color_reset());
901 for (j
= 0; j
< component_classes_count
; j
++) {
902 struct bt_component_class
*comp_class
=
903 bt_plugin_get_component_class_by_index(
905 const char *comp_class_name
=
906 bt_component_class_get_name(comp_class
);
907 const char *comp_class_description
=
908 bt_component_class_get_description(comp_class
);
909 enum bt_component_class_type type
=
910 bt_component_class_get_type(comp_class
);
913 print_plugin_comp_cls_opt(stdout
,
914 bt_plugin_get_name(plugin
), comp_class_name
,
917 if (comp_class_description
) {
918 printf(": %s", comp_class_description
);
931 int cmd_print_lttng_live_sessions(struct bt_config
*cfg
)
938 int cmd_print_ctf_metadata(struct bt_config
*cfg
)
941 struct bt_component_class
*comp_cls
= NULL
;
942 struct bt_value
*results
= NULL
;
943 struct bt_value
*params
= NULL
;
944 struct bt_value
*metadata_text_value
= NULL
;
945 const char *metadata_text
= NULL
;
946 static const char * const plugin_name
= "ctf";
947 static const char * const comp_cls_name
= "fs";
948 static const enum bt_component_class_type comp_cls_type
=
949 BT_COMPONENT_CLASS_TYPE_SOURCE
;
951 assert(cfg
->cmd_data
.print_ctf_metadata
.path
);
952 comp_cls
= find_component_class(plugin_name
, comp_cls_name
,
955 BT_LOGE("Cannot find component class: plugin-name=\"%s\", "
956 "comp-cls-name=\"%s\", comp-cls-type=%d",
957 plugin_name
, comp_cls_name
,
958 BT_COMPONENT_CLASS_TYPE_SOURCE
);
959 fprintf(stderr
, "%s%sCannot find component class %s",
960 bt_common_color_bold(),
961 bt_common_color_fg_red(),
962 bt_common_color_reset());
963 print_plugin_comp_cls_opt(stderr
, plugin_name
,
964 comp_cls_name
, comp_cls_type
);
965 fprintf(stderr
, "\n");
970 params
= bt_value_map_create();
976 ret
= bt_value_map_insert_string(params
, "path",
977 cfg
->cmd_data
.print_ctf_metadata
.path
->str
);
983 results
= bt_component_class_query(comp_cls
, "metadata-info",
987 BT_LOGE_STR("Failed to query for metadata info.");
988 fprintf(stderr
, "%s%sFailed to request metadata info%s\n",
989 bt_common_color_bold(),
990 bt_common_color_fg_red(),
991 bt_common_color_reset());
995 metadata_text_value
= bt_value_map_get(results
, "text");
996 if (!metadata_text_value
) {
997 BT_LOGE_STR("Cannot find `text` string value in the resulting metadata info object.");
1002 ret
= bt_value_string_get(metadata_text_value
, &metadata_text
);
1004 printf("%s\n", metadata_text
);
1009 bt_put(metadata_text_value
);
1014 struct cmd_run_ctx
{
1016 GHashTable
*components
;
1019 struct bt_graph
*graph
;
1022 struct bt_config
*cfg
;
1028 int cmd_run_ctx_connect_upstream_port_to_downstream_component(
1029 struct cmd_run_ctx
*ctx
, struct bt_component
*upstream_comp
,
1030 struct bt_port
*upstream_port
,
1031 struct bt_config_connection
*cfg_conn
)
1034 GQuark downstreamp_comp_name_quark
;
1035 struct bt_component
*downstream_comp
;
1036 int64_t downstream_port_count
;
1038 int64_t (*port_count_fn
)(struct bt_component
*);
1039 struct bt_port
*(*port_by_index_fn
)(struct bt_component
*, uint64_t);
1042 BT_LOGI("Connecting upstream port to the next available downstream port: "
1043 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1044 "downstream-comp-name=\"%s\", conn-arg=\"%s\"",
1045 upstream_port
, bt_port_get_name(upstream_port
),
1046 cfg_conn
->downstream_comp_name
->str
,
1047 cfg_conn
->arg
->str
);
1048 downstreamp_comp_name_quark
= g_quark_from_string(
1049 cfg_conn
->downstream_comp_name
->str
);
1050 assert(downstreamp_comp_name_quark
> 0);
1051 downstream_comp
= g_hash_table_lookup(ctx
->components
,
1052 (gpointer
) (long) downstreamp_comp_name_quark
);
1053 if (!downstream_comp
) {
1054 BT_LOGE("Cannot find downstream component: comp-name=\"%s\", "
1055 "conn-arg=\"%s\"", cfg_conn
->downstream_comp_name
->str
,
1056 cfg_conn
->arg
->str
);
1057 fprintf(stderr
, "Cannot create connection: cannot find downstream component: %s\n",
1058 cfg_conn
->arg
->str
);
1062 if (bt_component_is_filter(downstream_comp
)) {
1063 port_count_fn
= bt_component_filter_get_input_port_count
;
1064 port_by_index_fn
= bt_component_filter_get_input_port_by_index
;
1065 } else if (bt_component_is_sink(downstream_comp
)) {
1066 port_count_fn
= bt_component_sink_get_input_port_count
;
1067 port_by_index_fn
= bt_component_sink_get_input_port_by_index
;
1070 * Should never happen because the connections are
1071 * validated before we get here.
1073 BT_LOGF("Invalid connection: downstream component is a source: "
1074 "conn-arg=\"%s\"", cfg_conn
->arg
->str
);
1078 downstream_port_count
= port_count_fn(downstream_comp
);
1079 assert(downstream_port_count
>= 0);
1081 for (i
= 0; i
< downstream_port_count
; i
++) {
1082 struct bt_port
*downstream_port
=
1083 port_by_index_fn(downstream_comp
, i
);
1084 const char *downstream_port_name
;
1086 assert(downstream_port
);
1088 /* Skip port if it's already connected */
1089 if (bt_port_is_connected(downstream_port
)) {
1090 bt_put(downstream_port
);
1091 BT_LOGD("Skipping downstream port: already connected: "
1092 "port-addr=%p, port-name=\"%s\"",
1094 bt_port_get_name(downstream_port
));
1098 downstream_port_name
= bt_port_get_name(downstream_port
);
1099 assert(downstream_port_name
);
1101 if (bt_common_star_glob_match(
1102 cfg_conn
->downstream_port_glob
->str
, -1ULL,
1103 downstream_port_name
, -1ULL)) {
1104 /* We have a winner! */
1105 conn
= bt_graph_connect_ports(ctx
->graph
,
1106 upstream_port
, downstream_port
);
1107 bt_put(downstream_port
);
1109 BT_LOGE("Cannot create connection: graph refuses to connect ports: "
1110 "upstream-comp-addr=%p, upstream-comp-name=\"%s\", "
1111 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1112 "downstream-comp-addr=%p, downstream-comp-name=\"%s\", "
1113 "downstream-port-addr=%p, downstream-port-name=\"%s\", "
1115 upstream_comp
, bt_component_get_name(upstream_comp
),
1116 upstream_port
, bt_port_get_name(upstream_port
),
1117 downstream_comp
, cfg_conn
->downstream_comp_name
->str
,
1118 downstream_port
, downstream_port_name
,
1119 cfg_conn
->arg
->str
);
1121 "Cannot create connection: graph refuses to connect ports (`%s` to `%s`): %s\n",
1122 bt_port_get_name(upstream_port
),
1123 downstream_port_name
,
1124 cfg_conn
->arg
->str
);
1128 BT_LOGI("Connected component ports: "
1129 "upstream-comp-addr=%p, upstream-comp-name=\"%s\", "
1130 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1131 "downstream-comp-addr=%p, downstream-comp-name=\"%s\", "
1132 "downstream-port-addr=%p, downstream-port-name=\"%s\", "
1134 upstream_comp
, bt_component_get_name(upstream_comp
),
1135 upstream_port
, bt_port_get_name(upstream_port
),
1136 downstream_comp
, cfg_conn
->downstream_comp_name
->str
,
1137 downstream_port
, downstream_port_name
,
1138 cfg_conn
->arg
->str
);
1143 bt_put(downstream_port
);
1147 BT_LOGE("Cannot create connection: cannot find a matching downstream port for upstream port: "
1148 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1149 "downstream-comp-name=\"%s\", conn-arg=\"%s\"",
1150 upstream_port
, bt_port_get_name(upstream_port
),
1151 cfg_conn
->downstream_comp_name
->str
,
1152 cfg_conn
->arg
->str
);
1154 "Cannot create connection: cannot find a matching downstream port for upstream port `%s`: %s\n",
1155 bt_port_get_name(upstream_port
), cfg_conn
->arg
->str
);
1170 int cmd_run_ctx_connect_upstream_port(struct cmd_run_ctx
*ctx
,
1171 struct bt_port
*upstream_port
)
1174 const char *upstream_port_name
;
1175 const char *upstream_comp_name
;
1176 struct bt_component
*upstream_comp
= NULL
;
1180 assert(upstream_port
);
1181 upstream_port_name
= bt_port_get_name(upstream_port
);
1182 assert(upstream_port_name
);
1183 upstream_comp
= bt_port_get_component(upstream_port
);
1184 if (!upstream_comp
) {
1185 BT_LOGW("Upstream port to connect is not part of a component: "
1186 "port-addr=%p, port-name=\"%s\"",
1187 upstream_port
, upstream_port_name
);
1192 upstream_comp_name
= bt_component_get_name(upstream_comp
);
1193 assert(upstream_comp_name
);
1194 BT_LOGI("Connecting upstream port: comp-addr=%p, comp-name=\"%s\", "
1195 "port-addr=%p, port-name=\"%s\"",
1196 upstream_comp
, upstream_comp_name
,
1197 upstream_port
, upstream_port_name
);
1199 for (i
= 0; i
< ctx
->cfg
->cmd_data
.run
.connections
->len
; i
++) {
1200 struct bt_config_connection
*cfg_conn
=
1202 ctx
->cfg
->cmd_data
.run
.connections
, i
);
1204 if (strcmp(cfg_conn
->upstream_comp_name
->str
,
1205 upstream_comp_name
) == 0) {
1206 if (bt_common_star_glob_match(
1207 cfg_conn
->upstream_port_glob
->str
,
1208 -1ULL, upstream_port_name
, -1ULL)) {
1209 ret
= cmd_run_ctx_connect_upstream_port_to_downstream_component(
1210 ctx
, upstream_comp
, upstream_port
,
1213 BT_LOGE("Cannot connect upstream port: "
1214 "port-addr=%p, port-name=\"%s\"",
1216 upstream_port_name
);
1218 "Cannot connect port `%s` of component `%s` to a downstream port: %s\n",
1221 cfg_conn
->arg
->str
);
1230 BT_LOGE("Cannot connect upstream port: port does not match any connection argument: "
1231 "port-addr=%p, port-name=\"%s\"", upstream_port
,
1232 upstream_port_name
);
1234 "Cannot create connection: upstream port `%s` does not match any connection\n",
1235 upstream_port_name
);
1241 bt_put(upstream_comp
);
1246 void graph_port_added_listener(struct bt_port
*port
, void *data
)
1248 struct bt_component
*comp
= NULL
;
1249 struct cmd_run_ctx
*ctx
= data
;
1251 BT_LOGI("Port added to a graph's component: port-addr=%p, port-name=\"%s\"",
1252 port
, bt_port_get_name(port
));
1254 if (bt_port_is_connected(port
)) {
1255 BT_LOGW_STR("Port is already connected.");
1259 comp
= bt_port_get_component(port
);
1261 BT_LOGW_STR("Port has no component.");
1265 if (!bt_port_is_output(port
)) {
1266 BT_LOGI_STR("Skipping input port.");
1270 if (cmd_run_ctx_connect_upstream_port(ctx
, port
)) {
1271 BT_LOGF_STR("Cannot connect upstream port.");
1272 fprintf(stderr
, "Added port could not be connected: aborting\n");
1282 void graph_port_removed_listener(struct bt_component
*component
,
1283 struct bt_port
*port
, void *data
)
1285 BT_LOGI("Port removed from a graph's component: comp-addr=%p, "
1286 "comp-name=\"%s\", port-addr=%p, port-name=\"%s\"",
1287 component
, bt_component_get_name(component
),
1288 port
, bt_port_get_name(port
));
1292 void graph_ports_connected_listener(struct bt_port
*upstream_port
,
1293 struct bt_port
*downstream_port
, void *data
)
1295 BT_LOGI("Graph's component ports connected: "
1296 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1297 "downstream-port-addr=%p, downstream-port-name=\"%s\"",
1298 upstream_port
, bt_port_get_name(upstream_port
),
1299 downstream_port
, bt_port_get_name(downstream_port
));
1303 void graph_ports_disconnected_listener(
1304 struct bt_component
*upstream_component
,
1305 struct bt_component
*downstream_component
,
1306 struct bt_port
*upstream_port
, struct bt_port
*downstream_port
,
1309 BT_LOGI("Graph's component ports disconnected: "
1310 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1311 "downstream-port-addr=%p, downstream-port-name=\"%s\"",
1312 upstream_port
, bt_port_get_name(upstream_port
),
1313 downstream_port
, bt_port_get_name(downstream_port
));
1317 void cmd_run_ctx_destroy(struct cmd_run_ctx
*ctx
)
1323 if (ctx
->components
) {
1324 g_hash_table_destroy(ctx
->components
);
1325 ctx
->components
= NULL
;
1333 int cmd_run_ctx_init(struct cmd_run_ctx
*ctx
, struct bt_config
*cfg
)
1338 ctx
->connect_ports
= false;
1339 ctx
->components
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
1341 if (!ctx
->components
) {
1345 ctx
->graph
= bt_graph_create();
1350 ret
= bt_graph_add_port_added_listener(ctx
->graph
,
1351 graph_port_added_listener
, ctx
);
1356 ret
= bt_graph_add_port_removed_listener(ctx
->graph
,
1357 graph_port_removed_listener
, ctx
);
1362 ret
= bt_graph_add_ports_connected_listener(ctx
->graph
,
1363 graph_ports_connected_listener
, ctx
);
1368 ret
= bt_graph_add_ports_disconnected_listener(ctx
->graph
,
1369 graph_ports_disconnected_listener
, ctx
);
1377 cmd_run_ctx_destroy(ctx
);
1385 int cmd_run_ctx_create_components_from_config_components(
1386 struct cmd_run_ctx
*ctx
, GPtrArray
*cfg_components
)
1389 struct bt_component_class
*comp_cls
= NULL
;
1390 struct bt_component
*comp
= NULL
;
1393 for (i
= 0; i
< cfg_components
->len
; i
++) {
1394 struct bt_config_component
*cfg_comp
=
1395 g_ptr_array_index(cfg_components
, i
);
1398 comp_cls
= find_component_class(cfg_comp
->plugin_name
->str
,
1399 cfg_comp
->comp_cls_name
->str
, cfg_comp
->type
);
1401 BT_LOGE("Cannot find component class: plugin-name=\"%s\", "
1402 "comp-cls-name=\"%s\", comp-cls-type=%d",
1403 cfg_comp
->plugin_name
->str
,
1404 cfg_comp
->comp_cls_name
->str
,
1406 fprintf(stderr
, "%s%sCannot find component class %s",
1407 bt_common_color_bold(),
1408 bt_common_color_fg_red(),
1409 bt_common_color_reset());
1410 print_plugin_comp_cls_opt(stderr
,
1411 cfg_comp
->plugin_name
->str
,
1412 cfg_comp
->comp_cls_name
->str
,
1414 fprintf(stderr
, "\n");
1418 comp
= bt_component_create(comp_cls
,
1419 cfg_comp
->instance_name
->str
, cfg_comp
->params
);
1421 BT_LOGE("Cannot create component: plugin-name=\"%s\", "
1422 "comp-cls-name=\"%s\", comp-cls-type=%d",
1424 cfg_comp
->plugin_name
->str
,
1425 cfg_comp
->comp_cls_name
->str
,
1426 cfg_comp
->type
, cfg_comp
->instance_name
->str
);
1427 fprintf(stderr
, "%s%sCannot create component `%s`%s\n",
1428 bt_common_color_bold(),
1429 bt_common_color_fg_red(),
1430 cfg_comp
->instance_name
->str
,
1431 bt_common_color_reset());
1435 BT_LOGI("Created and inserted component: comp-addr=%p, comp-name=\"%s\"",
1436 comp
, cfg_comp
->instance_name
->str
);
1437 quark
= g_quark_from_string(cfg_comp
->instance_name
->str
);
1439 g_hash_table_insert(ctx
->components
,
1440 (gpointer
) (long) quark
, comp
);
1457 int cmd_run_ctx_create_components(struct cmd_run_ctx
*ctx
)
1462 * Make sure that, during this phase, our graph's "port added"
1463 * listener does not connect ports while we are creating the
1464 * components because we have a special, initial phase for
1467 ctx
->connect_ports
= false;
1469 ret
= cmd_run_ctx_create_components_from_config_components(
1470 ctx
, ctx
->cfg
->cmd_data
.run
.sources
);
1476 ret
= cmd_run_ctx_create_components_from_config_components(
1477 ctx
, ctx
->cfg
->cmd_data
.run
.filters
);
1483 ret
= cmd_run_ctx_create_components_from_config_components(
1484 ctx
, ctx
->cfg
->cmd_data
.run
.sinks
);
1495 int cmd_run_ctx_connect_comp_ports(struct cmd_run_ctx
*ctx
,
1496 struct bt_component
*comp
,
1497 int64_t (*port_count_fn
)(struct bt_component
*),
1498 struct bt_port
*(*port_by_index_fn
)(struct bt_component
*, uint64_t))
1504 count
= port_count_fn(comp
);
1507 for (i
= 0; i
< count
; i
++) {
1508 struct bt_port
*upstream_port
= port_by_index_fn(comp
, i
);
1510 assert(upstream_port
);
1511 ret
= cmd_run_ctx_connect_upstream_port(ctx
, upstream_port
);
1512 bt_put(upstream_port
);
1523 int cmd_run_ctx_connect_ports(struct cmd_run_ctx
*ctx
)
1526 GHashTableIter iter
;
1527 gpointer g_name_quark
, g_comp
;
1529 ctx
->connect_ports
= true;
1530 g_hash_table_iter_init(&iter
, ctx
->components
);
1532 while (g_hash_table_iter_next(&iter
, &g_name_quark
, &g_comp
)) {
1533 if (bt_component_is_source(g_comp
)) {
1534 ret
= cmd_run_ctx_connect_comp_ports(ctx
,
1535 g_comp
, bt_component_source_get_output_port_count
,
1536 bt_component_source_get_output_port_by_index
);
1537 } else if (bt_component_is_filter(g_comp
)) {
1538 ret
= cmd_run_ctx_connect_comp_ports(ctx
,
1539 g_comp
, bt_component_filter_get_output_port_count
,
1540 bt_component_filter_get_output_port_by_index
);
1553 int cmd_run(struct bt_config
*cfg
)
1556 struct cmd_run_ctx ctx
= { 0 };
1558 ret
= load_all_plugins(cfg
->plugin_paths
);
1563 /* Initialize the command's context and the graph object */
1564 if (cmd_run_ctx_init(&ctx
, cfg
)) {
1565 BT_LOGE_STR("Cannot initialize the command's context.");
1566 fprintf(stderr
, "Cannot initialize the command's context\n");
1570 /* Create the requested component instances */
1571 if (cmd_run_ctx_create_components(&ctx
)) {
1572 BT_LOGE_STR("Cannot create components.");
1573 fprintf(stderr
, "Cannot create components\n");
1577 /* Connect the initially visible component ports */
1578 if (cmd_run_ctx_connect_ports(&ctx
)) {
1579 BT_LOGE_STR("Cannot connect initial component ports.");
1580 fprintf(stderr
, "Cannot connect initial component ports\n");
1584 BT_LOGI_STR("Running the graph.");
1588 enum bt_graph_status graph_status
= bt_graph_run(ctx
.graph
);
1590 switch (graph_status
) {
1591 case BT_GRAPH_STATUS_OK
:
1593 case BT_GRAPH_STATUS_AGAIN
:
1594 if (cfg
->cmd_data
.run
.retry_duration_us
> 0) {
1595 BT_LOGV("Got BT_GRAPH_STATUS_AGAIN: sleeping: "
1597 cfg
->cmd_data
.run
.retry_duration_us
);
1599 if (usleep(cfg
->cmd_data
.run
.retry_duration_us
)) {
1600 // TODO: check EINTR and signal handler
1604 case BT_COMPONENT_STATUS_END
:
1607 BT_LOGE_STR("Graph failed to complete successfully");
1608 fprintf(stderr
, "Graph failed to complete successfully\n");
1621 cmd_run_ctx_destroy(&ctx
);
1626 void warn_command_name_and_directory_clash(struct bt_config
*cfg
)
1628 const char *env_clash
;
1630 if (!cfg
->command_name
) {
1634 env_clash
= getenv(ENV_BABELTRACE_WARN_COMMAND_NAME_DIRECTORY_CLASH
);
1635 if (env_clash
&& strcmp(env_clash
, "0") == 0) {
1639 if (g_file_test(cfg
->command_name
,
1640 G_FILE_TEST_EXISTS
| G_FILE_TEST_IS_DIR
)) {
1641 fprintf(stderr
, "\nNOTE: The `%s` command was executed. If you meant to convert a\n",
1643 fprintf(stderr
, "trace located in the local `%s` directory, please use:\n",
1645 fprintf(stderr
, "\n");
1646 fprintf(stderr
, " babeltrace convert %s [OPTIONS]\n",
1652 void init_log_level(void)
1654 enum bt_logging_level log_level
= BT_LOG_NONE
;
1655 const char *log_level_env
= getenv("BABELTRACE_CLI_LOG_LEVEL");
1657 if (!log_level_env
) {
1661 if (strcmp(log_level_env
, "VERBOSE") == 0) {
1662 log_level
= BT_LOGGING_LEVEL_VERBOSE
;
1663 } else if (strcmp(log_level_env
, "DEBUG") == 0) {
1664 log_level
= BT_LOGGING_LEVEL_DEBUG
;
1665 } else if (strcmp(log_level_env
, "INFO") == 0) {
1666 log_level
= BT_LOGGING_LEVEL_INFO
;
1667 } else if (strcmp(log_level_env
, "WARN") == 0) {
1668 log_level
= BT_LOGGING_LEVEL_WARN
;
1669 } else if (strcmp(log_level_env
, "ERROR") == 0) {
1670 log_level
= BT_LOGGING_LEVEL_ERROR
;
1671 } else if (strcmp(log_level_env
, "FATAL") == 0) {
1672 log_level
= BT_LOGGING_LEVEL_FATAL
;
1673 } else if (strcmp(log_level_env
, "NONE") == 0) {
1674 log_level
= BT_LOGGING_LEVEL_NONE
;
1678 bt_cli_log_level
= log_level
;
1681 int main(int argc
, const char **argv
)
1685 struct bt_config
*cfg
;
1689 cfg
= bt_config_cli_args_create_with_default(argc
, argv
, &retcode
);
1692 /* Quit without errors; typically usage/version */
1694 BT_LOGI_STR("Quitting without errors.");
1699 BT_LOGE("Command-line error: retcode=%d", retcode
);
1704 BT_LOGE_STR("Failed to create a valid Babeltrace configuration.");
1705 fprintf(stderr
, "Failed to create Babeltrace configuration\n");
1711 bt_cli_log_level
= BT_LOGGING_LEVEL_VERBOSE
;
1712 bt_logging_set_global_level(BT_LOGGING_LEVEL_VERBOSE
);
1713 // TODO: for backward compat., set the log level
1714 // environment variables of the known plugins
1716 } else if (cfg
->debug
) {
1717 bt_cli_log_level
= BT_LOGGING_LEVEL_DEBUG
;
1718 bt_logging_set_global_level(BT_LOGGING_LEVEL_DEBUG
);
1719 // TODO: for backward compat., set the log level
1720 // environment variables of the known plugins
1724 babeltrace_debug
= cfg
->debug
;
1725 babeltrace_verbose
= cfg
->verbose
;
1728 if (cfg
->command_needs_plugins
) {
1729 ret
= load_all_plugins(cfg
->plugin_paths
);
1731 BT_LOGE("Failed to load plugins: ret=%d", ret
);
1737 BT_LOGI("Executing command: cmd=%d, command-name=\"%s\"",
1738 cfg
->command
, cfg
->command_name
);
1740 switch (cfg
->command
) {
1741 case BT_CONFIG_COMMAND_RUN
:
1744 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
1745 ret
= cmd_list_plugins(cfg
);
1747 case BT_CONFIG_COMMAND_HELP
:
1748 ret
= cmd_help(cfg
);
1750 case BT_CONFIG_COMMAND_QUERY
:
1751 ret
= cmd_query(cfg
);
1753 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
1754 ret
= cmd_print_ctf_metadata(cfg
);
1756 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
1757 ret
= cmd_print_lttng_live_sessions(cfg
);
1760 BT_LOGF("Invalid command: cmd=%d", cfg
->command
);
1764 warn_command_name_and_directory_clash(cfg
);
1765 retcode
= ret
? 1 : 0;