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>
51 #include "babeltrace-cfg.h"
52 #include "babeltrace-cfg-cli-args.h"
53 #include "babeltrace-cfg-cli-args-default.h"
55 #define BT_LOG_TAG "CLI"
58 #define ENV_BABELTRACE_WARN_COMMAND_NAME_DIRECTORY_CLASH "BABELTRACE_CLI_WARN_COMMAND_NAME_DIRECTORY_CLASH"
60 GPtrArray
*loaded_plugins
;
63 int bt_cli_log_level
= BT_LOG_NONE
;
66 void init_static_data(void)
68 loaded_plugins
= g_ptr_array_new_with_free_func(bt_put
);
72 void fini_static_data(void)
74 g_ptr_array_free(loaded_plugins
, TRUE
);
78 struct bt_plugin
*find_plugin(const char *name
)
81 struct bt_plugin
*plugin
= NULL
;
84 BT_LOGD("Finding plugin: name=\"%s\"", name
);
86 for (i
= 0; i
< loaded_plugins
->len
; i
++) {
87 plugin
= g_ptr_array_index(loaded_plugins
, i
);
89 if (strcmp(name
, bt_plugin_get_name(plugin
)) == 0) {
96 if (BT_LOG_ON_DEBUG
) {
98 BT_LOGD("Found plugin: plugin-addr=%p", plugin
);
100 BT_LOGD("Cannot find plugin.");
104 return bt_get(plugin
);
108 struct bt_component_class
*find_component_class(const char *plugin_name
,
109 const char *comp_class_name
,
110 enum bt_component_class_type comp_class_type
)
112 struct bt_component_class
*comp_class
= NULL
;
113 struct bt_plugin
*plugin
;
115 BT_LOGD("Finding component class: plugin-name=\"%s\", "
116 "comp-cls-name=\"%s\", comp-cls-type=%d",
117 plugin_name
, comp_class_name
, comp_class_type
);
119 plugin
= find_plugin(plugin_name
);
125 comp_class
= bt_plugin_get_component_class_by_name_and_type(plugin
,
126 comp_class_name
, comp_class_type
);
130 if (BT_LOG_ON_DEBUG
) {
132 BT_LOGD("Found component class: comp-cls-addr=%p",
135 BT_LOGD("Cannot find component class.");
143 void print_indent(FILE *fp
, size_t indent
)
147 for (i
= 0; i
< indent
; i
++) {
153 const char *component_type_str(enum bt_component_class_type type
)
156 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
158 case BT_COMPONENT_CLASS_TYPE_SINK
:
160 case BT_COMPONENT_CLASS_TYPE_FILTER
:
162 case BT_COMPONENT_CLASS_TYPE_UNKNOWN
:
169 void print_plugin_comp_cls_opt(FILE *fh
, const char *plugin_name
,
170 const char *comp_cls_name
, enum bt_component_class_type type
)
172 GString
*shell_plugin_name
= NULL
;
173 GString
*shell_comp_cls_name
= NULL
;
175 shell_plugin_name
= bt_common_shell_quote(plugin_name
, false);
176 if (!shell_plugin_name
) {
180 shell_comp_cls_name
= bt_common_shell_quote(comp_cls_name
, false);
181 if (!shell_comp_cls_name
) {
185 fprintf(fh
, "%s%s--%s%s %s'%s%s%s%s.%s%s%s'",
186 bt_common_color_bold(),
187 bt_common_color_fg_cyan(),
188 component_type_str(type
),
189 bt_common_color_reset(),
190 bt_common_color_fg_default(),
191 bt_common_color_bold(),
192 bt_common_color_fg_blue(),
193 shell_plugin_name
->str
,
194 bt_common_color_fg_default(),
195 bt_common_color_fg_yellow(),
196 shell_comp_cls_name
->str
,
197 bt_common_color_reset());
200 if (shell_plugin_name
) {
201 g_string_free(shell_plugin_name
, TRUE
);
204 if (shell_comp_cls_name
) {
205 g_string_free(shell_comp_cls_name
, TRUE
);
210 void print_value(FILE *, struct bt_value
*, size_t);
213 void print_value_rec(FILE *, struct bt_value
*, size_t);
215 struct print_map_value_data
{
221 bt_bool
print_map_value(const char *key
, struct bt_value
*object
, void *data
)
223 struct print_map_value_data
*print_map_value_data
= data
;
225 print_indent(print_map_value_data
->fp
, print_map_value_data
->indent
);
226 fprintf(print_map_value_data
->fp
, "%s: ", key
);
228 if (bt_value_is_array(object
) &&
229 bt_value_array_is_empty(object
)) {
230 fprintf(print_map_value_data
->fp
, "[ ]\n");
234 if (bt_value_is_map(object
) &&
235 bt_value_map_is_empty(object
)) {
236 fprintf(print_map_value_data
->fp
, "{ }\n");
240 if (bt_value_is_array(object
) ||
241 bt_value_is_map(object
)) {
242 fprintf(print_map_value_data
->fp
, "\n");
245 print_value_rec(print_map_value_data
->fp
, object
,
246 print_map_value_data
->indent
+ 2);
251 void print_value_rec(FILE *fp
, struct bt_value
*value
, size_t indent
)
264 switch (bt_value_get_type(value
)) {
265 case BT_VALUE_TYPE_NULL
:
266 fprintf(fp
, "%snull%s\n", bt_common_color_bold(),
267 bt_common_color_reset());
269 case BT_VALUE_TYPE_BOOL
:
270 bt_value_bool_get(value
, &bool_val
);
271 fprintf(fp
, "%s%s%s%s\n", bt_common_color_bold(),
272 bt_common_color_fg_cyan(), bool_val
? "yes" : "no",
273 bt_common_color_reset());
275 case BT_VALUE_TYPE_INTEGER
:
276 bt_value_integer_get(value
, &int_val
);
277 fprintf(fp
, "%s%s%" PRId64
"%s\n", bt_common_color_bold(),
278 bt_common_color_fg_red(), int_val
,
279 bt_common_color_reset());
281 case BT_VALUE_TYPE_FLOAT
:
282 bt_value_float_get(value
, &dbl_val
);
283 fprintf(fp
, "%s%s%lf%s\n", bt_common_color_bold(),
284 bt_common_color_fg_red(), dbl_val
,
285 bt_common_color_reset());
287 case BT_VALUE_TYPE_STRING
:
288 bt_value_string_get(value
, &str_val
);
289 fprintf(fp
, "%s%s%s%s\n", bt_common_color_bold(),
290 bt_common_color_fg_green(), str_val
,
291 bt_common_color_reset());
293 case BT_VALUE_TYPE_ARRAY
:
294 size
= bt_value_array_size(value
);
298 print_indent(fp
, indent
);
299 fprintf(fp
, "[ ]\n");
303 for (i
= 0; i
< size
; i
++) {
304 struct bt_value
*element
=
305 bt_value_array_get(value
, i
);
308 print_indent(fp
, indent
);
311 if (bt_value_is_array(element
) &&
312 bt_value_array_is_empty(element
)) {
313 fprintf(fp
, "[ ]\n");
317 if (bt_value_is_map(element
) &&
318 bt_value_map_is_empty(element
)) {
319 fprintf(fp
, "{ }\n");
323 if (bt_value_is_array(element
) ||
324 bt_value_is_map(element
)) {
328 print_value_rec(fp
, element
, indent
+ 2);
332 case BT_VALUE_TYPE_MAP
:
334 struct print_map_value_data data
= {
339 if (bt_value_map_is_empty(value
)) {
340 print_indent(fp
, indent
);
341 fprintf(fp
, "{ }\n");
345 bt_value_map_foreach(value
, print_map_value
, &data
);
354 void print_value(FILE *fp
, struct bt_value
*value
, size_t indent
)
356 if (!bt_value_is_array(value
) && !bt_value_is_map(value
)) {
357 print_indent(fp
, indent
);
360 print_value_rec(fp
, value
, indent
);
364 void print_bt_config_component(struct bt_config_component
*bt_config_component
)
366 fprintf(stderr
, " ");
367 print_plugin_comp_cls_opt(stderr
, bt_config_component
->plugin_name
->str
,
368 bt_config_component
->comp_cls_name
->str
,
369 bt_config_component
->type
);
370 fprintf(stderr
, ":\n");
372 if (bt_config_component
->instance_name
->len
> 0) {
373 fprintf(stderr
, " Name: %s\n",
374 bt_config_component
->instance_name
->str
);
377 fprintf(stderr
, " Parameters:\n");
378 print_value(stderr
, bt_config_component
->params
, 8);
382 void print_bt_config_components(GPtrArray
*array
)
386 for (i
= 0; i
< array
->len
; i
++) {
387 struct bt_config_component
*cfg_component
=
388 bt_config_get_component(array
, i
);
389 print_bt_config_component(cfg_component
);
390 BT_PUT(cfg_component
);
395 void print_plugin_paths(struct bt_value
*plugin_paths
)
397 fprintf(stderr
, " Plugin paths:\n");
398 print_value(stderr
, plugin_paths
, 4);
402 void print_cfg_run(struct bt_config
*cfg
)
406 print_plugin_paths(cfg
->plugin_paths
);
407 fprintf(stderr
, " Source component instances:\n");
408 print_bt_config_components(cfg
->cmd_data
.run
.sources
);
410 if (cfg
->cmd_data
.run
.filters
->len
> 0) {
411 fprintf(stderr
, " Filter component instances:\n");
412 print_bt_config_components(cfg
->cmd_data
.run
.filters
);
415 fprintf(stderr
, " Sink component instances:\n");
416 print_bt_config_components(cfg
->cmd_data
.run
.sinks
);
417 fprintf(stderr
, " Connections:\n");
419 for (i
= 0; i
< cfg
->cmd_data
.run
.connections
->len
; i
++) {
420 struct bt_config_connection
*cfg_connection
=
421 g_ptr_array_index(cfg
->cmd_data
.run
.connections
,
424 fprintf(stderr
, " %s%s%s -> %s%s%s\n",
425 cfg_connection
->upstream_comp_name
->str
,
426 cfg_connection
->upstream_port_glob
->len
> 0 ? "." : "",
427 cfg_connection
->upstream_port_glob
->str
,
428 cfg_connection
->downstream_comp_name
->str
,
429 cfg_connection
->downstream_port_glob
->len
> 0 ? "." : "",
430 cfg_connection
->downstream_port_glob
->str
);
435 void print_cfg_list_plugins(struct bt_config
*cfg
)
437 print_plugin_paths(cfg
->plugin_paths
);
441 void print_cfg_help(struct bt_config
*cfg
)
443 print_plugin_paths(cfg
->plugin_paths
);
447 void print_cfg_print_ctf_metadata(struct bt_config
*cfg
)
449 print_plugin_paths(cfg
->plugin_paths
);
450 fprintf(stderr
, " Path: %s\n",
451 cfg
->cmd_data
.print_ctf_metadata
.path
->str
);
455 void print_cfg_print_lttng_live_sessions(struct bt_config
*cfg
)
457 print_plugin_paths(cfg
->plugin_paths
);
458 fprintf(stderr
, " URL: %s\n",
459 cfg
->cmd_data
.print_lttng_live_sessions
.url
->str
);
463 void print_cfg_query(struct bt_config
*cfg
)
465 print_plugin_paths(cfg
->plugin_paths
);
466 fprintf(stderr
, " Object: `%s`\n", cfg
->cmd_data
.query
.object
->str
);
467 fprintf(stderr
, " Component class:\n");
468 print_bt_config_component(cfg
->cmd_data
.query
.cfg_component
);
472 void print_cfg(struct bt_config
*cfg
)
474 if (!BT_LOG_ON_INFO
) {
478 BT_LOGI_STR("Configuration:");
479 fprintf(stderr
, " Debug mode: %s\n", cfg
->debug
? "yes" : "no");
480 fprintf(stderr
, " Verbose mode: %s\n", cfg
->verbose
? "yes" : "no");
482 switch (cfg
->command
) {
483 case BT_CONFIG_COMMAND_RUN
:
486 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
487 print_cfg_list_plugins(cfg
);
489 case BT_CONFIG_COMMAND_HELP
:
492 case BT_CONFIG_COMMAND_QUERY
:
493 print_cfg_query(cfg
);
495 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
496 print_cfg_print_ctf_metadata(cfg
);
498 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
499 print_cfg_print_lttng_live_sessions(cfg
);
507 void add_to_loaded_plugins(struct bt_plugin_set
*plugin_set
)
512 count
= bt_plugin_set_get_plugin_count(plugin_set
);
515 for (i
= 0; i
< count
; i
++) {
516 struct bt_plugin
*plugin
=
517 bt_plugin_set_get_plugin(plugin_set
, i
);
518 struct bt_plugin
*loaded_plugin
=
519 find_plugin(bt_plugin_get_name(plugin
));
524 BT_LOGI("Not using plugin: another one already exists with the same name: "
525 "plugin-name=\"%s\", plugin-path=\"%s\", "
526 "existing-plugin-path=\"%s\"",
527 bt_plugin_get_name(plugin
),
528 bt_plugin_get_path(plugin
),
529 bt_plugin_get_path(loaded_plugin
));
530 bt_put(loaded_plugin
);
532 /* Add to global array. */
533 BT_LOGD("Adding plugin to loaded plugins: plugin-path=\"%s\"",
534 bt_plugin_get_name(plugin
));
535 g_ptr_array_add(loaded_plugins
, bt_get(plugin
));
543 int load_dynamic_plugins(struct bt_value
*plugin_paths
)
545 int nr_paths
, i
, ret
= 0;
547 nr_paths
= bt_value_array_size(plugin_paths
);
549 BT_LOGE_STR("Cannot load dynamic plugins: no plugin path.");
554 BT_LOGI("Loading dynamic plugins.");
556 for (i
= 0; i
< nr_paths
; i
++) {
557 struct bt_value
*plugin_path_value
= NULL
;
558 const char *plugin_path
;
559 struct bt_plugin_set
*plugin_set
;
561 plugin_path_value
= bt_value_array_get(plugin_paths
, i
);
562 bt_value_string_get(plugin_path_value
, &plugin_path
);
564 plugin_set
= bt_plugin_create_all_from_dir(plugin_path
, false);
566 BT_LOGD("Unable to load dynamic plugins: path=\"%s\"",
568 BT_PUT(plugin_path_value
);
572 add_to_loaded_plugins(plugin_set
);
574 BT_PUT(plugin_path_value
);
581 int load_static_plugins(void)
584 struct bt_plugin_set
*plugin_set
;
586 BT_LOGI("Loading static plugins.");
587 plugin_set
= bt_plugin_create_all_from_static();
589 BT_LOGE("Unable to load static plugins.");
594 add_to_loaded_plugins(plugin_set
);
601 int load_all_plugins(struct bt_value
*plugin_paths
)
605 if (load_dynamic_plugins(plugin_paths
)) {
610 if (load_static_plugins()) {
615 BT_LOGI("Loaded all plugins: count=%u", loaded_plugins
->len
);
622 void print_plugin_info(struct bt_plugin
*plugin
)
624 unsigned int major
, minor
, patch
;
626 enum bt_plugin_status version_status
;
627 const char *plugin_name
;
631 const char *plugin_description
;
633 plugin_name
= bt_plugin_get_name(plugin
);
634 path
= bt_plugin_get_path(plugin
);
635 author
= bt_plugin_get_author(plugin
);
636 license
= bt_plugin_get_license(plugin
);
637 plugin_description
= bt_plugin_get_description(plugin
);
638 version_status
= bt_plugin_get_version(plugin
, &major
, &minor
,
640 printf("%s%s%s%s:\n", bt_common_color_bold(),
641 bt_common_color_fg_blue(), plugin_name
,
642 bt_common_color_reset());
643 printf(" %sPath%s: %s\n", bt_common_color_bold(),
644 bt_common_color_reset(), path
? path
: "(None)");
646 if (version_status
== BT_PLUGIN_STATUS_OK
) {
647 printf(" %sVersion%s: %u.%u.%u",
648 bt_common_color_bold(), bt_common_color_reset(),
649 major
, minor
, patch
);
658 printf(" %sDescription%s: %s\n", bt_common_color_bold(),
659 bt_common_color_reset(),
660 plugin_description
? plugin_description
: "(None)");
661 printf(" %sAuthor%s: %s\n", bt_common_color_bold(),
662 bt_common_color_reset(), author
? author
: "(Unknown)");
663 printf(" %sLicense%s: %s\n", bt_common_color_bold(),
664 bt_common_color_reset(),
665 license
? license
: "(Unknown)");
669 int cmd_query(struct bt_config
*cfg
)
672 struct bt_component_class
*comp_cls
= NULL
;
673 struct bt_value
*results
= NULL
;
675 ret
= load_all_plugins(cfg
->plugin_paths
);
680 comp_cls
= find_component_class(cfg
->cmd_data
.query
.cfg_component
->plugin_name
->str
,
681 cfg
->cmd_data
.query
.cfg_component
->comp_cls_name
->str
,
682 cfg
->cmd_data
.query
.cfg_component
->type
);
684 BT_LOGE("Cannot find component class: plugin-name=\"%s\", "
685 "comp-cls-name=\"%s\", comp-cls-type=%d",
686 cfg
->cmd_data
.query
.cfg_component
->plugin_name
->str
,
687 cfg
->cmd_data
.query
.cfg_component
->comp_cls_name
->str
,
688 cfg
->cmd_data
.query
.cfg_component
->type
);
689 fprintf(stderr
, "%s%sCannot find component class %s",
690 bt_common_color_bold(),
691 bt_common_color_fg_red(),
692 bt_common_color_reset());
693 print_plugin_comp_cls_opt(stderr
,
694 cfg
->cmd_data
.query
.cfg_component
->plugin_name
->str
,
695 cfg
->cmd_data
.query
.cfg_component
->comp_cls_name
->str
,
696 cfg
->cmd_data
.query
.cfg_component
->type
);
697 fprintf(stderr
, "\n");
702 results
= bt_component_class_query(comp_cls
,
703 cfg
->cmd_data
.query
.object
->str
,
704 cfg
->cmd_data
.query
.cfg_component
->params
);
706 BT_LOGE("Failed to query component class: plugin-name=\"%s\", "
707 "comp-cls-name=\"%s\", comp-cls-type=%d "
709 cfg
->cmd_data
.query
.cfg_component
->plugin_name
->str
,
710 cfg
->cmd_data
.query
.cfg_component
->comp_cls_name
->str
,
711 cfg
->cmd_data
.query
.cfg_component
->type
,
712 cfg
->cmd_data
.query
.object
->str
);
713 fprintf(stderr
, "%s%sFailed to query info to %s",
714 bt_common_color_bold(),
715 bt_common_color_fg_red(),
716 bt_common_color_reset());
717 print_plugin_comp_cls_opt(stderr
,
718 cfg
->cmd_data
.query
.cfg_component
->plugin_name
->str
,
719 cfg
->cmd_data
.query
.cfg_component
->comp_cls_name
->str
,
720 cfg
->cmd_data
.query
.cfg_component
->type
);
721 fprintf(stderr
, "%s%s with object `%s`%s\n",
722 bt_common_color_bold(),
723 bt_common_color_fg_red(),
724 cfg
->cmd_data
.query
.object
->str
,
725 bt_common_color_reset());
730 print_value(stdout
, results
, 0);
739 int cmd_help(struct bt_config
*cfg
)
742 struct bt_plugin
*plugin
= NULL
;
745 ret
= load_all_plugins(cfg
->plugin_paths
);
750 plugin
= find_plugin(cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
);
752 BT_LOGE("Cannot find plugin: plugin-name=\"%s\"",
753 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
);
754 fprintf(stderr
, "%s%sCannot find plugin %s%s%s\n",
755 bt_common_color_bold(), bt_common_color_fg_red(),
756 bt_common_color_fg_blue(),
757 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
,
758 bt_common_color_reset());
763 print_plugin_info(plugin
);
764 printf(" %sComponent classes%s: %d\n",
765 bt_common_color_bold(),
766 bt_common_color_reset(),
767 (int) bt_plugin_get_component_class_count(plugin
));
770 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
771 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
772 struct bt_component_class
*needed_comp_cls
=
773 find_component_class(
774 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
,
775 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
->str
,
776 cfg
->cmd_data
.help
.cfg_component
->type
);
778 if (!needed_comp_cls
) {
779 BT_LOGE("Cannot find component class: plugin-name=\"%s\", "
780 "comp-cls-name=\"%s\", comp-cls-type=%d",
781 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
,
782 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
->str
,
783 cfg
->cmd_data
.help
.cfg_component
->type
);
784 fprintf(stderr
, "\n%s%sCannot find component class %s",
785 bt_common_color_bold(),
786 bt_common_color_fg_red(),
787 bt_common_color_reset());
788 print_plugin_comp_cls_opt(stderr
,
789 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
,
790 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
->str
,
791 cfg
->cmd_data
.help
.cfg_component
->type
);
792 fprintf(stderr
, "\n");
797 bt_put(needed_comp_cls
);
800 for (i
= 0; i
< bt_plugin_get_component_class_count(plugin
); i
++) {
801 struct bt_component_class
*comp_cls
=
802 bt_plugin_get_component_class_by_index(plugin
, i
);
803 const char *comp_class_name
=
804 bt_component_class_get_name(comp_cls
);
805 const char *comp_class_description
=
806 bt_component_class_get_description(comp_cls
);
807 const char *comp_class_help
=
808 bt_component_class_get_help(comp_cls
);
809 enum bt_component_class_type type
=
810 bt_component_class_get_type(comp_cls
);
814 if (cfg
->cmd_data
.help
.cfg_component
->type
!=
815 BT_COMPONENT_CLASS_TYPE_UNKNOWN
) {
816 if (strcmp(cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
->str
,
817 comp_class_name
) != 0 &&
819 cfg
->cmd_data
.help
.cfg_component
->type
) {
826 print_plugin_comp_cls_opt(stdout
,
827 cfg
->cmd_data
.help
.cfg_component
->plugin_name
->str
,
831 printf(" %sDescription%s: %s\n", bt_common_color_bold(),
832 bt_common_color_reset(),
833 comp_class_description
? comp_class_description
: "(None)");
835 if (comp_class_help
) {
836 printf("\n%s\n", comp_class_help
);
848 int cmd_list_plugins(struct bt_config
*cfg
)
851 int plugins_count
, component_classes_count
= 0, i
;
853 ret
= load_all_plugins(cfg
->plugin_paths
);
858 printf("From the following plugin paths:\n\n");
859 print_value(stdout
, cfg
->plugin_paths
, 2);
861 plugins_count
= loaded_plugins
->len
;
862 if (plugins_count
== 0) {
863 printf("No plugins found.\n");
867 for (i
= 0; i
< plugins_count
; i
++) {
868 struct bt_plugin
*plugin
= g_ptr_array_index(loaded_plugins
, i
);
870 component_classes_count
+= bt_plugin_get_component_class_count(plugin
);
873 printf("Found %s%d%s component classes in %s%d%s plugins.\n",
874 bt_common_color_bold(),
875 component_classes_count
,
876 bt_common_color_reset(),
877 bt_common_color_bold(),
879 bt_common_color_reset());
881 for (i
= 0; i
< plugins_count
; i
++) {
883 struct bt_plugin
*plugin
= g_ptr_array_index(loaded_plugins
, i
);
885 component_classes_count
=
886 bt_plugin_get_component_class_count(plugin
);
888 print_plugin_info(plugin
);
890 if (component_classes_count
== 0) {
891 printf(" %sComponent classes%s: (none)\n",
892 bt_common_color_bold(),
893 bt_common_color_reset());
895 printf(" %sComponent classes%s:\n",
896 bt_common_color_bold(),
897 bt_common_color_reset());
900 for (j
= 0; j
< component_classes_count
; j
++) {
901 struct bt_component_class
*comp_class
=
902 bt_plugin_get_component_class_by_index(
904 const char *comp_class_name
=
905 bt_component_class_get_name(comp_class
);
906 const char *comp_class_description
=
907 bt_component_class_get_description(comp_class
);
908 enum bt_component_class_type type
=
909 bt_component_class_get_type(comp_class
);
912 print_plugin_comp_cls_opt(stdout
,
913 bt_plugin_get_name(plugin
), comp_class_name
,
916 if (comp_class_description
) {
917 printf(": %s", comp_class_description
);
930 int cmd_print_lttng_live_sessions(struct bt_config
*cfg
)
937 int cmd_print_ctf_metadata(struct bt_config
*cfg
)
940 struct bt_component_class
*comp_cls
= NULL
;
941 struct bt_value
*results
= NULL
;
942 struct bt_value
*params
= NULL
;
943 struct bt_value
*metadata_text_value
= NULL
;
944 const char *metadata_text
= NULL
;
945 static const char * const plugin_name
= "ctf";
946 static const char * const comp_cls_name
= "fs";
947 static const enum bt_component_class_type comp_cls_type
=
948 BT_COMPONENT_CLASS_TYPE_SOURCE
;
950 assert(cfg
->cmd_data
.print_ctf_metadata
.path
);
951 comp_cls
= find_component_class(plugin_name
, comp_cls_name
,
954 BT_LOGE("Cannot find component class: plugin-name=\"%s\", "
955 "comp-cls-name=\"%s\", comp-cls-type=%d",
956 plugin_name
, comp_cls_name
,
957 BT_COMPONENT_CLASS_TYPE_SOURCE
);
958 fprintf(stderr
, "%s%sCannot find component class %s",
959 bt_common_color_bold(),
960 bt_common_color_fg_red(),
961 bt_common_color_reset());
962 print_plugin_comp_cls_opt(stderr
, plugin_name
,
963 comp_cls_name
, comp_cls_type
);
964 fprintf(stderr
, "\n");
969 params
= bt_value_map_create();
975 ret
= bt_value_map_insert_string(params
, "path",
976 cfg
->cmd_data
.print_ctf_metadata
.path
->str
);
982 results
= bt_component_class_query(comp_cls
, "metadata-info",
986 BT_LOGE_STR("Failed to query for metadata info.");
987 fprintf(stderr
, "%s%sFailed to request metadata info%s\n",
988 bt_common_color_bold(),
989 bt_common_color_fg_red(),
990 bt_common_color_reset());
994 metadata_text_value
= bt_value_map_get(results
, "text");
995 if (!metadata_text_value
) {
996 BT_LOGE_STR("Cannot find `text` string value in the resulting metadata info object.");
1001 ret
= bt_value_string_get(metadata_text_value
, &metadata_text
);
1003 printf("%s\n", metadata_text
);
1008 bt_put(metadata_text_value
);
1013 struct cmd_run_ctx
{
1015 GHashTable
*components
;
1018 struct bt_graph
*graph
;
1021 struct bt_config
*cfg
;
1027 int cmd_run_ctx_connect_upstream_port_to_downstream_component(
1028 struct cmd_run_ctx
*ctx
, struct bt_component
*upstream_comp
,
1029 struct bt_port
*upstream_port
,
1030 struct bt_config_connection
*cfg_conn
)
1033 GQuark downstreamp_comp_name_quark
;
1034 struct bt_component
*downstream_comp
;
1035 int64_t downstream_port_count
;
1037 int64_t (*port_count_fn
)(struct bt_component
*);
1038 struct bt_port
*(*port_by_index_fn
)(struct bt_component
*, uint64_t);
1041 BT_LOGI("Connecting upstream port to the next available downstream port: "
1042 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1043 "downstream-comp-name=\"%s\", conn-arg=\"%s\"",
1044 upstream_port
, bt_port_get_name(upstream_port
),
1045 cfg_conn
->downstream_comp_name
->str
,
1046 cfg_conn
->arg
->str
);
1047 downstreamp_comp_name_quark
= g_quark_from_string(
1048 cfg_conn
->downstream_comp_name
->str
);
1049 assert(downstreamp_comp_name_quark
> 0);
1050 downstream_comp
= g_hash_table_lookup(ctx
->components
,
1051 (gpointer
) (long) downstreamp_comp_name_quark
);
1052 if (!downstream_comp
) {
1053 BT_LOGE("Cannot find downstream component: comp-name=\"%s\", "
1054 "conn-arg=\"%s\"", cfg_conn
->downstream_comp_name
->str
,
1055 cfg_conn
->arg
->str
);
1056 fprintf(stderr
, "Cannot create connection: cannot find downstream component: %s\n",
1057 cfg_conn
->arg
->str
);
1061 if (bt_component_is_filter(downstream_comp
)) {
1062 port_count_fn
= bt_component_filter_get_input_port_count
;
1063 port_by_index_fn
= bt_component_filter_get_input_port_by_index
;
1064 } else if (bt_component_is_sink(downstream_comp
)) {
1065 port_count_fn
= bt_component_sink_get_input_port_count
;
1066 port_by_index_fn
= bt_component_sink_get_input_port_by_index
;
1069 * Should never happen because the connections are
1070 * validated before we get here.
1072 BT_LOGF("Invalid connection: downstream component is a source: "
1073 "conn-arg=\"%s\"", cfg_conn
->arg
->str
);
1077 downstream_port_count
= port_count_fn(downstream_comp
);
1078 assert(downstream_port_count
>= 0);
1080 for (i
= 0; i
< downstream_port_count
; i
++) {
1081 struct bt_port
*downstream_port
=
1082 port_by_index_fn(downstream_comp
, i
);
1083 const char *downstream_port_name
;
1085 assert(downstream_port
);
1087 /* Skip port if it's already connected */
1088 if (bt_port_is_connected(downstream_port
)) {
1089 bt_put(downstream_port
);
1090 BT_LOGD("Skipping downstream port: already connected: "
1091 "port-addr=%p, port-name=\"%s\"",
1093 bt_port_get_name(downstream_port
));
1097 downstream_port_name
= bt_port_get_name(downstream_port
);
1098 assert(downstream_port_name
);
1100 if (bt_common_star_glob_match(
1101 cfg_conn
->downstream_port_glob
->str
, -1ULL,
1102 downstream_port_name
, -1ULL)) {
1103 /* We have a winner! */
1104 conn
= bt_graph_connect_ports(ctx
->graph
,
1105 upstream_port
, downstream_port
);
1106 bt_put(downstream_port
);
1108 BT_LOGE("Cannot create connection: graph refuses to connect ports: "
1109 "upstream-comp-addr=%p, upstream-comp-name=\"%s\", "
1110 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1111 "downstream-comp-addr=%p, downstream-comp-name=\"%s\", "
1112 "downstream-port-addr=%p, downstream-port-name=\"%s\", "
1114 upstream_comp
, bt_component_get_name(upstream_comp
),
1115 upstream_port
, bt_port_get_name(upstream_port
),
1116 downstream_comp
, cfg_conn
->downstream_comp_name
->str
,
1117 downstream_port
, downstream_port_name
,
1118 cfg_conn
->arg
->str
);
1120 "Cannot create connection: graph refuses to connect ports (`%s` to `%s`): %s\n",
1121 bt_port_get_name(upstream_port
),
1122 downstream_port_name
,
1123 cfg_conn
->arg
->str
);
1127 BT_LOGI("Connected component ports: "
1128 "upstream-comp-addr=%p, upstream-comp-name=\"%s\", "
1129 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1130 "downstream-comp-addr=%p, downstream-comp-name=\"%s\", "
1131 "downstream-port-addr=%p, downstream-port-name=\"%s\", "
1133 upstream_comp
, bt_component_get_name(upstream_comp
),
1134 upstream_port
, bt_port_get_name(upstream_port
),
1135 downstream_comp
, cfg_conn
->downstream_comp_name
->str
,
1136 downstream_port
, downstream_port_name
,
1137 cfg_conn
->arg
->str
);
1142 bt_put(downstream_port
);
1146 BT_LOGE("Cannot create connection: cannot find a matching downstream port for upstream port: "
1147 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1148 "downstream-comp-name=\"%s\", conn-arg=\"%s\"",
1149 upstream_port
, bt_port_get_name(upstream_port
),
1150 cfg_conn
->downstream_comp_name
->str
,
1151 cfg_conn
->arg
->str
);
1153 "Cannot create connection: cannot find a matching downstream port for upstream port `%s`: %s\n",
1154 bt_port_get_name(upstream_port
), cfg_conn
->arg
->str
);
1169 int cmd_run_ctx_connect_upstream_port(struct cmd_run_ctx
*ctx
,
1170 struct bt_port
*upstream_port
)
1173 const char *upstream_port_name
;
1174 const char *upstream_comp_name
;
1175 struct bt_component
*upstream_comp
= NULL
;
1179 assert(upstream_port
);
1180 upstream_port_name
= bt_port_get_name(upstream_port
);
1181 assert(upstream_port_name
);
1182 upstream_comp
= bt_port_get_component(upstream_port
);
1183 if (!upstream_comp
) {
1184 BT_LOGW("Upstream port to connect is not part of a component: "
1185 "port-addr=%p, port-name=\"%s\"",
1186 upstream_port
, upstream_port_name
);
1191 upstream_comp_name
= bt_component_get_name(upstream_comp
);
1192 assert(upstream_comp_name
);
1193 BT_LOGI("Connecting upstream port: comp-addr=%p, comp-name=\"%s\", "
1194 "port-addr=%p, port-name=\"%s\"",
1195 upstream_comp
, upstream_comp_name
,
1196 upstream_port
, upstream_port_name
);
1198 for (i
= 0; i
< ctx
->cfg
->cmd_data
.run
.connections
->len
; i
++) {
1199 struct bt_config_connection
*cfg_conn
=
1201 ctx
->cfg
->cmd_data
.run
.connections
, i
);
1203 if (strcmp(cfg_conn
->upstream_comp_name
->str
,
1204 upstream_comp_name
) == 0) {
1205 if (bt_common_star_glob_match(
1206 cfg_conn
->upstream_port_glob
->str
,
1207 -1ULL, upstream_port_name
, -1ULL)) {
1208 ret
= cmd_run_ctx_connect_upstream_port_to_downstream_component(
1209 ctx
, upstream_comp
, upstream_port
,
1212 BT_LOGE("Cannot connect upstream port: "
1213 "port-addr=%p, port-name=\"%s\"",
1215 upstream_port_name
);
1217 "Cannot connect port `%s` of component `%s` to a downstream port: %s\n",
1220 cfg_conn
->arg
->str
);
1229 BT_LOGE("Cannot connect upstream port: port does not match any connection argument: "
1230 "port-addr=%p, port-name=\"%s\"", upstream_port
,
1231 upstream_port_name
);
1233 "Cannot create connection: upstream port `%s` does not match any connection\n",
1234 upstream_port_name
);
1240 bt_put(upstream_comp
);
1245 void graph_port_added_listener(struct bt_port
*port
, void *data
)
1247 struct bt_component
*comp
= NULL
;
1248 struct cmd_run_ctx
*ctx
= data
;
1250 BT_LOGI("Port added to a graph's component: port-addr=%p, port-name=\"%s\"",
1251 port
, bt_port_get_name(port
));
1253 if (bt_port_is_connected(port
)) {
1254 BT_LOGW_STR("Port is already connected.");
1258 comp
= bt_port_get_component(port
);
1260 BT_LOGW_STR("Port has no component.");
1264 if (!bt_port_is_output(port
)) {
1265 BT_LOGI_STR("Skipping input port.");
1269 if (cmd_run_ctx_connect_upstream_port(ctx
, port
)) {
1270 BT_LOGF_STR("Cannot connect upstream port.");
1271 fprintf(stderr
, "Added port could not be connected: aborting\n");
1281 void graph_port_removed_listener(struct bt_component
*component
,
1282 struct bt_port
*port
, void *data
)
1284 BT_LOGI("Port removed from a graph's component: comp-addr=%p, "
1285 "comp-name=\"%s\", port-addr=%p, port-name=\"%s\"",
1286 component
, bt_component_get_name(component
),
1287 port
, bt_port_get_name(port
));
1291 void graph_ports_connected_listener(struct bt_port
*upstream_port
,
1292 struct bt_port
*downstream_port
, void *data
)
1294 BT_LOGI("Graph's component ports connected: "
1295 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1296 "downstream-port-addr=%p, downstream-port-name=\"%s\"",
1297 upstream_port
, bt_port_get_name(upstream_port
),
1298 downstream_port
, bt_port_get_name(downstream_port
));
1302 void graph_ports_disconnected_listener(
1303 struct bt_component
*upstream_component
,
1304 struct bt_component
*downstream_component
,
1305 struct bt_port
*upstream_port
, struct bt_port
*downstream_port
,
1308 BT_LOGI("Graph's component ports disconnected: "
1309 "upstream-port-addr=%p, upstream-port-name=\"%s\", "
1310 "downstream-port-addr=%p, downstream-port-name=\"%s\"",
1311 upstream_port
, bt_port_get_name(upstream_port
),
1312 downstream_port
, bt_port_get_name(downstream_port
));
1316 void cmd_run_ctx_destroy(struct cmd_run_ctx
*ctx
)
1322 if (ctx
->components
) {
1323 g_hash_table_destroy(ctx
->components
);
1324 ctx
->components
= NULL
;
1332 int cmd_run_ctx_init(struct cmd_run_ctx
*ctx
, struct bt_config
*cfg
)
1337 ctx
->connect_ports
= false;
1338 ctx
->components
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
1340 if (!ctx
->components
) {
1344 ctx
->graph
= bt_graph_create();
1349 ret
= bt_graph_add_port_added_listener(ctx
->graph
,
1350 graph_port_added_listener
, ctx
);
1355 ret
= bt_graph_add_port_removed_listener(ctx
->graph
,
1356 graph_port_removed_listener
, ctx
);
1361 ret
= bt_graph_add_ports_connected_listener(ctx
->graph
,
1362 graph_ports_connected_listener
, ctx
);
1367 ret
= bt_graph_add_ports_disconnected_listener(ctx
->graph
,
1368 graph_ports_disconnected_listener
, ctx
);
1376 cmd_run_ctx_destroy(ctx
);
1384 int cmd_run_ctx_create_components_from_config_components(
1385 struct cmd_run_ctx
*ctx
, GPtrArray
*cfg_components
)
1388 struct bt_component_class
*comp_cls
= NULL
;
1389 struct bt_component
*comp
= NULL
;
1392 for (i
= 0; i
< cfg_components
->len
; i
++) {
1393 struct bt_config_component
*cfg_comp
=
1394 g_ptr_array_index(cfg_components
, i
);
1397 comp_cls
= find_component_class(cfg_comp
->plugin_name
->str
,
1398 cfg_comp
->comp_cls_name
->str
, cfg_comp
->type
);
1400 BT_LOGE("Cannot find component class: plugin-name=\"%s\", "
1401 "comp-cls-name=\"%s\", comp-cls-type=%d",
1402 cfg_comp
->plugin_name
->str
,
1403 cfg_comp
->comp_cls_name
->str
,
1405 fprintf(stderr
, "%s%sCannot find component class %s",
1406 bt_common_color_bold(),
1407 bt_common_color_fg_red(),
1408 bt_common_color_reset());
1409 print_plugin_comp_cls_opt(stderr
,
1410 cfg_comp
->plugin_name
->str
,
1411 cfg_comp
->comp_cls_name
->str
,
1413 fprintf(stderr
, "\n");
1417 comp
= bt_component_create(comp_cls
,
1418 cfg_comp
->instance_name
->str
, cfg_comp
->params
);
1420 BT_LOGE("Cannot create component: plugin-name=\"%s\", "
1421 "comp-cls-name=\"%s\", comp-cls-type=%d",
1423 cfg_comp
->plugin_name
->str
,
1424 cfg_comp
->comp_cls_name
->str
,
1425 cfg_comp
->type
, cfg_comp
->instance_name
->str
);
1426 fprintf(stderr
, "%s%sCannot create component `%s`%s\n",
1427 bt_common_color_bold(),
1428 bt_common_color_fg_red(),
1429 cfg_comp
->instance_name
->str
,
1430 bt_common_color_reset());
1434 BT_LOGI("Created and inserted component: comp-addr=%p, comp-name=\"%s\"",
1435 comp
, cfg_comp
->instance_name
->str
);
1436 quark
= g_quark_from_string(cfg_comp
->instance_name
->str
);
1438 g_hash_table_insert(ctx
->components
,
1439 (gpointer
) (long) quark
, comp
);
1456 int cmd_run_ctx_create_components(struct cmd_run_ctx
*ctx
)
1461 * Make sure that, during this phase, our graph's "port added"
1462 * listener does not connect ports while we are creating the
1463 * components because we have a special, initial phase for
1466 ctx
->connect_ports
= false;
1468 ret
= cmd_run_ctx_create_components_from_config_components(
1469 ctx
, ctx
->cfg
->cmd_data
.run
.sources
);
1475 ret
= cmd_run_ctx_create_components_from_config_components(
1476 ctx
, ctx
->cfg
->cmd_data
.run
.filters
);
1482 ret
= cmd_run_ctx_create_components_from_config_components(
1483 ctx
, ctx
->cfg
->cmd_data
.run
.sinks
);
1494 int cmd_run_ctx_connect_comp_ports(struct cmd_run_ctx
*ctx
,
1495 struct bt_component
*comp
,
1496 int64_t (*port_count_fn
)(struct bt_component
*),
1497 struct bt_port
*(*port_by_index_fn
)(struct bt_component
*, uint64_t))
1503 count
= port_count_fn(comp
);
1506 for (i
= 0; i
< count
; i
++) {
1507 struct bt_port
*upstream_port
= port_by_index_fn(comp
, i
);
1509 assert(upstream_port
);
1510 ret
= cmd_run_ctx_connect_upstream_port(ctx
, upstream_port
);
1511 bt_put(upstream_port
);
1522 int cmd_run_ctx_connect_ports(struct cmd_run_ctx
*ctx
)
1525 GHashTableIter iter
;
1526 gpointer g_name_quark
, g_comp
;
1528 ctx
->connect_ports
= true;
1529 g_hash_table_iter_init(&iter
, ctx
->components
);
1531 while (g_hash_table_iter_next(&iter
, &g_name_quark
, &g_comp
)) {
1532 if (bt_component_is_source(g_comp
)) {
1533 ret
= cmd_run_ctx_connect_comp_ports(ctx
,
1534 g_comp
, bt_component_source_get_output_port_count
,
1535 bt_component_source_get_output_port_by_index
);
1536 } else if (bt_component_is_filter(g_comp
)) {
1537 ret
= cmd_run_ctx_connect_comp_ports(ctx
,
1538 g_comp
, bt_component_filter_get_output_port_count
,
1539 bt_component_filter_get_output_port_by_index
);
1552 int cmd_run(struct bt_config
*cfg
)
1555 struct cmd_run_ctx ctx
= { 0 };
1557 ret
= load_all_plugins(cfg
->plugin_paths
);
1562 /* Initialize the command's context and the graph object */
1563 if (cmd_run_ctx_init(&ctx
, cfg
)) {
1564 BT_LOGE_STR("Cannot initialize the command's context.");
1565 fprintf(stderr
, "Cannot initialize the command's context\n");
1569 /* Create the requested component instances */
1570 if (cmd_run_ctx_create_components(&ctx
)) {
1571 BT_LOGE_STR("Cannot create components.");
1572 fprintf(stderr
, "Cannot create components\n");
1576 /* Connect the initially visible component ports */
1577 if (cmd_run_ctx_connect_ports(&ctx
)) {
1578 BT_LOGE_STR("Cannot connect initial component ports.");
1579 fprintf(stderr
, "Cannot connect initial component ports\n");
1583 BT_LOGI_STR("Running the graph.");
1587 enum bt_graph_status graph_status
= bt_graph_run(ctx
.graph
);
1589 switch (graph_status
) {
1590 case BT_GRAPH_STATUS_OK
:
1592 case BT_GRAPH_STATUS_AGAIN
:
1593 if (cfg
->cmd_data
.run
.retry_duration_us
> 0) {
1594 BT_LOGV("Got BT_GRAPH_STATUS_AGAIN: sleeping: "
1596 cfg
->cmd_data
.run
.retry_duration_us
);
1598 if (usleep(cfg
->cmd_data
.run
.retry_duration_us
)) {
1599 // TODO: check EINTR and signal handler
1603 case BT_COMPONENT_STATUS_END
:
1606 BT_LOGE_STR("Graph failed to complete successfully");
1607 fprintf(stderr
, "Graph failed to complete successfully\n");
1620 cmd_run_ctx_destroy(&ctx
);
1625 void warn_command_name_and_directory_clash(struct bt_config
*cfg
)
1627 const char *env_clash
;
1629 if (!cfg
->command_name
) {
1633 env_clash
= getenv(ENV_BABELTRACE_WARN_COMMAND_NAME_DIRECTORY_CLASH
);
1634 if (env_clash
&& strcmp(env_clash
, "0") == 0) {
1638 if (g_file_test(cfg
->command_name
,
1639 G_FILE_TEST_EXISTS
| G_FILE_TEST_IS_DIR
)) {
1640 fprintf(stderr
, "\nNOTE: The `%s` command was executed. If you meant to convert a\n",
1642 fprintf(stderr
, "trace located in the local `%s` directory, please use:\n",
1644 fprintf(stderr
, "\n");
1645 fprintf(stderr
, " babeltrace convert %s [OPTIONS]\n",
1651 void init_log_level(void)
1653 enum bt_logging_level log_level
= BT_LOG_NONE
;
1654 const char *log_level_env
= getenv("BABELTRACE_CLI_LOG_LEVEL");
1656 if (!log_level_env
) {
1660 if (strcmp(log_level_env
, "VERBOSE") == 0) {
1661 log_level
= BT_LOGGING_LEVEL_VERBOSE
;
1662 } else if (strcmp(log_level_env
, "DEBUG") == 0) {
1663 log_level
= BT_LOGGING_LEVEL_DEBUG
;
1664 } else if (strcmp(log_level_env
, "INFO") == 0) {
1665 log_level
= BT_LOGGING_LEVEL_INFO
;
1666 } else if (strcmp(log_level_env
, "WARN") == 0) {
1667 log_level
= BT_LOGGING_LEVEL_WARN
;
1668 } else if (strcmp(log_level_env
, "ERROR") == 0) {
1669 log_level
= BT_LOGGING_LEVEL_ERROR
;
1670 } else if (strcmp(log_level_env
, "FATAL") == 0) {
1671 log_level
= BT_LOGGING_LEVEL_FATAL
;
1672 } else if (strcmp(log_level_env
, "NONE") == 0) {
1673 log_level
= BT_LOGGING_LEVEL_NONE
;
1677 bt_cli_log_level
= log_level
;
1680 int main(int argc
, const char **argv
)
1684 struct bt_config
*cfg
;
1688 cfg
= bt_config_cli_args_create_with_default(argc
, argv
, &retcode
);
1691 /* Quit without errors; typically usage/version */
1693 BT_LOGI_STR("Quitting without errors.");
1698 BT_LOGE("Command-line error: retcode=%d", retcode
);
1703 BT_LOGE_STR("Failed to create a valid Babeltrace configuration.");
1704 fprintf(stderr
, "Failed to create Babeltrace configuration\n");
1710 bt_cli_log_level
= BT_LOGGING_LEVEL_VERBOSE
;
1711 bt_logging_set_global_level(BT_LOGGING_LEVEL_VERBOSE
);
1712 // TODO: for backward compat., set the log level
1713 // environment variables of the known plugins
1715 } else if (cfg
->debug
) {
1716 bt_cli_log_level
= BT_LOGGING_LEVEL_DEBUG
;
1717 bt_logging_set_global_level(BT_LOGGING_LEVEL_DEBUG
);
1718 // TODO: for backward compat., set the log level
1719 // environment variables of the known plugins
1723 babeltrace_debug
= cfg
->debug
;
1724 babeltrace_verbose
= cfg
->verbose
;
1727 if (cfg
->command_needs_plugins
) {
1728 ret
= load_all_plugins(cfg
->plugin_paths
);
1730 BT_LOGE("Failed to load plugins: ret=%d", ret
);
1736 BT_LOGI("Executing command: cmd=%d, command-name=\"%s\"",
1737 cfg
->command
, cfg
->command_name
);
1739 switch (cfg
->command
) {
1740 case BT_CONFIG_COMMAND_RUN
:
1743 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
1744 ret
= cmd_list_plugins(cfg
);
1746 case BT_CONFIG_COMMAND_HELP
:
1747 ret
= cmd_help(cfg
);
1749 case BT_CONFIG_COMMAND_QUERY
:
1750 ret
= cmd_query(cfg
);
1752 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
1753 ret
= cmd_print_ctf_metadata(cfg
);
1755 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
1756 ret
= cmd_print_lttng_live_sessions(cfg
);
1759 BT_LOGF("Invalid command: cmd=%d", cfg
->command
);
1763 warn_command_name_and_directory_clash(cfg
);
1764 retcode
= ret
? 1 : 0;