2 * Babeltrace trace converter - parameter parsing
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #define BT_LOG_TAG "CLI-CFG-CLI-ARGS"
31 #include "common/assert.h"
35 #include <babeltrace2/babeltrace.h>
36 #include "common/common.h"
39 #include <sys/types.h>
40 #include "babeltrace2-cfg.h"
41 #include "babeltrace2-cfg-cli-args.h"
42 #include "babeltrace2-cfg-cli-args-connect.h"
43 #include "babeltrace2-cfg-cli-params-arg.h"
44 #include "common/version.h"
47 * Error printf() macro which prepends "Error: " the first time it's
48 * called. This gives a nicer feel than having a bunch of error prefixes
49 * (since the following lines usually describe the error and possible
50 * solutions), or the error prefix just at the end.
52 #define printf_err(fmt, args...) \
54 if (is_first_error) { \
55 fprintf(stderr, "Command line error: "); \
56 is_first_error = false; \
58 fprintf(stderr, fmt, ##args); \
61 static bool is_first_error
= true;
62 static const int cli_default_log_level
= BT_LOG_WARNING
;
64 /* INI-style parsing FSM states */
65 enum ini_parsing_fsm_state
{
66 /* Expect a map key (identifier) */
69 /* Expect an equal character ('=') */
75 /* Expect a comma character (',') */
79 /* INI-style parsing state variables */
80 struct ini_parsing_state
{
81 /* Lexical scanner (owned by this) */
84 /* Output map value object being filled (owned by this) */
87 /* Next expected FSM state */
88 enum ini_parsing_fsm_state expecting
;
90 /* Last decoded map key (owned by this) */
93 /* Complete INI-style string to parse (not owned by this) */
96 /* Error buffer (not owned by this) */
100 /* Offset option with "is set" boolean */
106 /* Legacy "ctf"/"lttng-live" format options */
107 struct ctf_legacy_opts
{
108 struct offset_opt offset_s
;
109 struct offset_opt offset_ns
;
110 bool stream_intersection
;
113 /* Legacy "text" format options */
114 struct text_legacy_opts
{
116 * output, dbg_info_dir, dbg_info_target_prefix, names,
117 * and fields are owned by this.
120 GString
*dbg_info_dir
;
121 GString
*dbg_info_target_prefix
;
122 const bt_value
*names
;
123 const bt_value
*fields
;
131 bool dbg_info_full_path
;
135 /* Legacy input format format */
136 enum legacy_input_format
{
137 LEGACY_INPUT_FORMAT_NONE
= 0,
138 LEGACY_INPUT_FORMAT_CTF
,
139 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
142 /* Legacy output format format */
143 enum legacy_output_format
{
144 LEGACY_OUTPUT_FORMAT_NONE
= 0,
145 LEGACY_OUTPUT_FORMAT_TEXT
,
146 LEGACY_OUTPUT_FORMAT_DUMMY
,
150 * Prints the "out of memory" error.
153 void print_err_oom(void)
155 printf_err("Out of memory\n");
159 * Returns the plugin name, component class name, component class type,
160 * and component name from a command-line --component option's argument.
161 * arg must have the following format:
163 * [NAME:]TYPE.PLUGIN.CLS
165 * where NAME is the optional component name, TYPE is either `source`,
166 * `filter`, or `sink`, PLUGIN is the plugin name, and CLS is the
167 * component class name.
169 * On success, both *plugin and *component are not NULL. *plugin
170 * and *comp_cls are owned by the caller. On success, *name can be NULL
171 * if no component class name was found, and *comp_cls_type is set.
174 void plugin_comp_cls_names(const char *arg
, char **name
, char **plugin
,
175 char **comp_cls
, bt_component_class_type
*comp_cls_type
)
177 const char *at
= arg
;
178 GString
*gs_name
= NULL
;
179 GString
*gs_comp_cls_type
= NULL
;
180 GString
*gs_plugin
= NULL
;
181 GString
*gs_comp_cls
= NULL
;
187 BT_ASSERT(comp_cls_type
);
189 if (!bt_common_string_is_printable(arg
)) {
190 printf_err("Argument contains a non-printable character\n");
194 /* Parse the component name */
195 gs_name
= bt_common_string_until(at
, ".:\\", ":", &end_pos
);
200 if (arg
[end_pos
] == ':') {
204 g_string_assign(gs_name
, "");
207 /* Parse the component class type */
208 gs_comp_cls_type
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
209 if (!gs_comp_cls_type
|| at
[end_pos
] == '\0') {
210 printf_err("Missing component class type (`source`, `filter`, or `sink`)\n");
214 if (strcmp(gs_comp_cls_type
->str
, "source") == 0 ||
215 strcmp(gs_comp_cls_type
->str
, "src") == 0) {
216 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
217 } else if (strcmp(gs_comp_cls_type
->str
, "filter") == 0 ||
218 strcmp(gs_comp_cls_type
->str
, "flt") == 0) {
219 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
220 } else if (strcmp(gs_comp_cls_type
->str
, "sink") == 0) {
221 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
223 printf_err("Unknown component class type: `%s`\n",
224 gs_comp_cls_type
->str
);
230 /* Parse the plugin name */
231 gs_plugin
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
232 if (!gs_plugin
|| gs_plugin
->len
== 0 || at
[end_pos
] == '\0') {
233 printf_err("Missing plugin or component class name\n");
239 /* Parse the component class name */
240 gs_comp_cls
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
241 if (!gs_comp_cls
|| gs_comp_cls
->len
== 0) {
242 printf_err("Missing component class name\n");
246 if (at
[end_pos
] != '\0') {
247 /* Found a non-escaped `.` */
252 if (gs_name
->len
== 0) {
254 g_string_free(gs_name
, TRUE
);
256 *name
= gs_name
->str
;
257 g_string_free(gs_name
, FALSE
);
260 g_string_free(gs_name
, TRUE
);
263 *plugin
= gs_plugin
->str
;
264 *comp_cls
= gs_comp_cls
->str
;
265 g_string_free(gs_plugin
, FALSE
);
266 g_string_free(gs_comp_cls
, FALSE
);
282 g_string_free(gs_name
, TRUE
);
286 g_string_free(gs_plugin
, TRUE
);
290 g_string_free(gs_comp_cls
, TRUE
);
293 if (gs_comp_cls_type
) {
294 g_string_free(gs_comp_cls_type
, TRUE
);
301 * Prints the Babeltrace version.
304 void print_version(void)
306 if (GIT_VERSION
[0] == '\0') {
307 puts("Babeltrace " VERSION
);
309 puts("Babeltrace " VERSION
" - " GIT_VERSION
);
314 * Destroys a component configuration.
317 void bt_config_component_destroy(bt_object
*obj
)
319 struct bt_config_component
*bt_config_component
=
320 container_of(obj
, struct bt_config_component
, base
);
326 if (bt_config_component
->plugin_name
) {
327 g_string_free(bt_config_component
->plugin_name
, TRUE
);
330 if (bt_config_component
->comp_cls_name
) {
331 g_string_free(bt_config_component
->comp_cls_name
, TRUE
);
334 if (bt_config_component
->instance_name
) {
335 g_string_free(bt_config_component
->instance_name
, TRUE
);
338 BT_VALUE_PUT_REF_AND_RESET(bt_config_component
->params
);
339 g_free(bt_config_component
);
346 * Creates a component configuration using the given plugin name and
347 * component name. `plugin_name` and `comp_cls_name` are copied (belong
348 * to the return value).
350 * Return value is owned by the caller.
353 struct bt_config_component
*bt_config_component_create(
354 bt_component_class_type type
,
355 const char *plugin_name
, const char *comp_cls_name
,
358 struct bt_config_component
*cfg_component
= NULL
;
360 cfg_component
= g_new0(struct bt_config_component
, 1);
361 if (!cfg_component
) {
366 bt_object_init_shared(&cfg_component
->base
,
367 bt_config_component_destroy
);
368 cfg_component
->type
= type
;
369 cfg_component
->plugin_name
= g_string_new(plugin_name
);
370 if (!cfg_component
->plugin_name
) {
375 cfg_component
->comp_cls_name
= g_string_new(comp_cls_name
);
376 if (!cfg_component
->comp_cls_name
) {
381 cfg_component
->instance_name
= g_string_new(NULL
);
382 if (!cfg_component
->instance_name
) {
387 cfg_component
->log_level
= init_log_level
;
389 /* Start with empty parameters */
390 cfg_component
->params
= bt_value_map_create();
391 if (!cfg_component
->params
) {
399 BT_OBJECT_PUT_REF_AND_RESET(cfg_component
);
402 return cfg_component
;
406 * Creates a component configuration from a command-line --component
410 struct bt_config_component
*bt_config_component_from_arg(const char *arg
,
413 struct bt_config_component
*cfg_comp
= NULL
;
415 char *plugin_name
= NULL
;
416 char *comp_cls_name
= NULL
;
417 bt_component_class_type type
;
419 plugin_comp_cls_names(arg
, &name
, &plugin_name
, &comp_cls_name
, &type
);
420 if (!plugin_name
|| !comp_cls_name
) {
424 cfg_comp
= bt_config_component_create(type
, plugin_name
, comp_cls_name
,
431 g_string_assign(cfg_comp
->instance_name
, name
);
437 BT_OBJECT_PUT_REF_AND_RESET(cfg_comp
);
442 g_free(comp_cls_name
);
447 * Destroys a configuration.
450 void bt_config_destroy(bt_object
*obj
)
452 struct bt_config
*cfg
=
453 container_of(obj
, struct bt_config
, base
);
459 BT_VALUE_PUT_REF_AND_RESET(cfg
->plugin_paths
);
461 switch (cfg
->command
) {
462 case BT_CONFIG_COMMAND_RUN
:
463 if (cfg
->cmd_data
.run
.sources
) {
464 g_ptr_array_free(cfg
->cmd_data
.run
.sources
, TRUE
);
467 if (cfg
->cmd_data
.run
.filters
) {
468 g_ptr_array_free(cfg
->cmd_data
.run
.filters
, TRUE
);
471 if (cfg
->cmd_data
.run
.sinks
) {
472 g_ptr_array_free(cfg
->cmd_data
.run
.sinks
, TRUE
);
475 if (cfg
->cmd_data
.run
.connections
) {
476 g_ptr_array_free(cfg
->cmd_data
.run
.connections
,
480 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
482 case BT_CONFIG_COMMAND_HELP
:
483 BT_OBJECT_PUT_REF_AND_RESET(cfg
->cmd_data
.help
.cfg_component
);
485 case BT_CONFIG_COMMAND_QUERY
:
486 BT_OBJECT_PUT_REF_AND_RESET(cfg
->cmd_data
.query
.cfg_component
);
488 if (cfg
->cmd_data
.query
.object
) {
489 g_string_free(cfg
->cmd_data
.query
.object
, TRUE
);
492 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
493 if (cfg
->cmd_data
.print_ctf_metadata
.path
) {
494 g_string_free(cfg
->cmd_data
.print_ctf_metadata
.path
,
497 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
501 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
502 if (cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
504 cfg
->cmd_data
.print_lttng_live_sessions
.url
,
507 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
522 void destroy_glist_of_gstring(GList
*list
)
530 for (at
= list
; at
!= NULL
; at
= g_list_next(at
)) {
531 g_string_free(at
->data
, TRUE
);
538 * Creates a simple lexical scanner for parsing comma-delimited names
541 * Return value is owned by the caller.
544 GScanner
*create_csv_identifiers_scanner(void)
547 GScannerConfig scanner_config
= {
548 .cset_skip_characters
= " \t\n",
549 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
550 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
551 .case_sensitive
= TRUE
,
552 .cpair_comment_single
= NULL
,
553 .skip_comment_multi
= TRUE
,
554 .skip_comment_single
= TRUE
,
555 .scan_comment_multi
= FALSE
,
556 .scan_identifier
= TRUE
,
557 .scan_identifier_1char
= TRUE
,
558 .scan_identifier_NULL
= FALSE
,
559 .scan_symbols
= FALSE
,
560 .symbol_2_token
= FALSE
,
561 .scope_0_fallback
= FALSE
,
562 .scan_binary
= FALSE
,
566 .scan_hex_dollar
= FALSE
,
567 .numbers_2_int
= FALSE
,
568 .int_2_float
= FALSE
,
569 .store_int64
= FALSE
,
570 .scan_string_sq
= FALSE
,
571 .scan_string_dq
= FALSE
,
572 .identifier_2_string
= FALSE
,
573 .char_2_token
= TRUE
,
576 scanner
= g_scanner_new(&scanner_config
);
585 * Converts a comma-delimited list of known names (--names option) to
586 * an array value object containing those names as string value objects.
588 * Return value is owned by the caller.
591 bt_value
*names_from_arg(const char *arg
)
593 GScanner
*scanner
= NULL
;
594 bt_value
*names
= NULL
;
595 bool found_all
= false, found_none
= false, found_item
= false;
597 names
= bt_value_array_create();
603 scanner
= create_csv_identifiers_scanner();
608 g_scanner_input_text(scanner
, arg
, strlen(arg
));
611 GTokenType token_type
= g_scanner_get_next_token(scanner
);
613 switch (token_type
) {
614 case G_TOKEN_IDENTIFIER
:
616 const char *identifier
= scanner
->value
.v_identifier
;
618 if (strcmp(identifier
, "payload") == 0 ||
619 strcmp(identifier
, "args") == 0 ||
620 strcmp(identifier
, "arg") == 0) {
622 if (bt_value_array_append_string_element(names
,
626 } else if (strcmp(identifier
, "context") == 0 ||
627 strcmp(identifier
, "ctx") == 0) {
629 if (bt_value_array_append_string_element(names
,
633 } else if (strcmp(identifier
, "scope") == 0 ||
634 strcmp(identifier
, "header") == 0) {
636 if (bt_value_array_append_string_element(names
,
640 } else if (strcmp(identifier
, "all") == 0) {
642 if (bt_value_array_append_string_element(names
,
646 } else if (strcmp(identifier
, "none") == 0) {
648 if (bt_value_array_append_string_element(names
,
653 printf_err("Unknown name: `%s`\n",
669 if (found_none
&& found_all
) {
670 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
674 * Legacy behavior is to clear the defaults (show none) when at
675 * least one item is specified.
677 if (found_item
&& !found_none
&& !found_all
) {
678 if (bt_value_array_append_string_element(names
, "none")) {
683 g_scanner_destroy(scanner
);
688 BT_VALUE_PUT_REF_AND_RESET(names
);
690 g_scanner_destroy(scanner
);
696 * Converts a comma-delimited list of known fields (--fields option) to
697 * an array value object containing those fields as string
700 * Return value is owned by the caller.
703 bt_value
*fields_from_arg(const char *arg
)
705 GScanner
*scanner
= NULL
;
708 fields
= bt_value_array_create();
714 scanner
= create_csv_identifiers_scanner();
719 g_scanner_input_text(scanner
, arg
, strlen(arg
));
722 GTokenType token_type
= g_scanner_get_next_token(scanner
);
724 switch (token_type
) {
725 case G_TOKEN_IDENTIFIER
:
727 const char *identifier
= scanner
->value
.v_identifier
;
729 if (strcmp(identifier
, "trace") == 0 ||
730 strcmp(identifier
, "trace:hostname") == 0 ||
731 strcmp(identifier
, "trace:domain") == 0 ||
732 strcmp(identifier
, "trace:procname") == 0 ||
733 strcmp(identifier
, "trace:vpid") == 0 ||
734 strcmp(identifier
, "loglevel") == 0 ||
735 strcmp(identifier
, "emf") == 0 ||
736 strcmp(identifier
, "callsite") == 0 ||
737 strcmp(identifier
, "all") == 0) {
738 if (bt_value_array_append_string_element(fields
,
743 printf_err("Unknown field: `%s`\n",
761 BT_VALUE_PUT_REF_AND_RESET(fields
);
765 g_scanner_destroy(scanner
);
771 void append_param_arg(GString
*params_arg
, const char *key
, const char *value
)
773 BT_ASSERT(params_arg
);
777 if (params_arg
->len
!= 0) {
778 g_string_append_c(params_arg
, ',');
781 g_string_append(params_arg
, key
);
782 g_string_append_c(params_arg
, '=');
783 g_string_append(params_arg
, value
);
787 * Inserts the equivalent "prefix-NAME=yes" strings into params_arg
788 * where the names are in names_array.
791 int insert_flat_params_from_array(GString
*params_arg
,
792 const bt_value
*names_array
, const char *prefix
)
796 GString
*tmpstr
= NULL
, *default_value
= NULL
;
797 bool default_set
= false, non_default_set
= false;
800 * names_array may be NULL if no CLI options were specified to
801 * trigger its creation.
807 tmpstr
= g_string_new(NULL
);
814 default_value
= g_string_new(NULL
);
815 if (!default_value
) {
821 for (i
= 0; i
< bt_value_array_get_size(names_array
); i
++) {
822 const bt_value
*str_obj
=
823 bt_value_array_borrow_element_by_index_const(names_array
,
826 bool is_default
= false;
829 printf_err("Unexpected error\n");
834 suffix
= bt_value_string_get(str_obj
);
836 g_string_assign(tmpstr
, prefix
);
837 g_string_append(tmpstr
, "-");
839 /* Special-case for "all" and "none". */
840 if (strcmp(suffix
, "all") == 0) {
842 g_string_assign(default_value
, "show");
843 } else if (strcmp(suffix
, "none") == 0) {
845 g_string_assign(default_value
, "hide");
849 g_string_append(tmpstr
, "default");
850 append_param_arg(params_arg
, tmpstr
->str
,
853 non_default_set
= true;
854 g_string_append(tmpstr
, suffix
);
855 append_param_arg(params_arg
, tmpstr
->str
, "yes");
859 /* Implicit field-default=hide if any non-default option is set. */
860 if (non_default_set
&& !default_set
) {
861 g_string_assign(tmpstr
, prefix
);
862 g_string_append(tmpstr
, "-default");
863 g_string_assign(default_value
, "hide");
864 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
869 g_string_free(default_value
, TRUE
);
873 g_string_free(tmpstr
, TRUE
);
886 OPT_CLOCK_FORCE_CORRELATE
,
897 OPT_DEBUG_INFO_FULL_PATH
,
898 OPT_DEBUG_INFO_TARGET_PREFIX
,
908 OPT_OMIT_HOME_PLUGIN_PATH
,
909 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
915 OPT_RESET_BASE_PARAMS
,
919 OPT_STREAM_INTERSECTION
,
925 enum bt_config_component_dest
{
926 BT_CONFIG_COMPONENT_DEST_UNKNOWN
= -1,
927 BT_CONFIG_COMPONENT_DEST_SOURCE
,
928 BT_CONFIG_COMPONENT_DEST_FILTER
,
929 BT_CONFIG_COMPONENT_DEST_SINK
,
933 * Adds a configuration component to the appropriate configuration
934 * array depending on the destination.
937 void add_run_cfg_comp(struct bt_config
*cfg
,
938 struct bt_config_component
*cfg_comp
,
939 enum bt_config_component_dest dest
)
941 bt_object_get_ref(cfg_comp
);
944 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
945 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
947 case BT_CONFIG_COMPONENT_DEST_FILTER
:
948 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
950 case BT_CONFIG_COMPONENT_DEST_SINK
:
951 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
959 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
960 struct bt_config_component
*cfg_comp
,
961 enum bt_config_component_dest dest
,
962 bt_value
*instance_names
)
966 if (cfg_comp
->instance_name
->len
== 0) {
967 printf_err("Found an unnamed component\n");
972 if (bt_value_map_has_entry(instance_names
,
973 cfg_comp
->instance_name
->str
)) {
974 printf_err("Duplicate component instance name:\n %s\n",
975 cfg_comp
->instance_name
->str
);
980 if (bt_value_map_insert_entry(instance_names
,
981 cfg_comp
->instance_name
->str
, bt_value_null
)) {
987 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
994 int append_env_var_plugin_paths(bt_value
*plugin_paths
)
999 if (bt_common_is_setuid_setgid()) {
1000 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1004 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1009 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1013 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1020 int append_home_and_system_plugin_paths(bt_value
*plugin_paths
,
1021 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1025 if (!omit_home_plugin_path
) {
1026 if (bt_common_is_setuid_setgid()) {
1027 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1029 char *home_plugin_dir
= bt_common_get_home_plugin_path(
1030 BT_LOG_OUTPUT_LEVEL
);
1032 if (home_plugin_dir
) {
1033 ret
= bt_config_append_plugin_paths(
1034 plugin_paths
, home_plugin_dir
);
1035 free(home_plugin_dir
);
1038 printf_err("Invalid home plugin path\n");
1045 if (!omit_system_plugin_path
) {
1046 if (bt_config_append_plugin_paths(plugin_paths
,
1047 bt_common_get_system_plugin_path())) {
1048 printf_err("Invalid system plugin path\n");
1054 printf_err("Cannot append home and system plugin paths\n");
1059 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1061 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1062 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1066 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1067 const bt_value
*initial_plugin_paths
,
1070 struct bt_config
*cfg
;
1073 cfg
= g_new0(struct bt_config
, 1);
1079 bt_object_init_shared(&cfg
->base
, bt_config_destroy
);
1080 cfg
->command
= command
;
1081 cfg
->command_needs_plugins
= needs_plugins
;
1083 if (initial_plugin_paths
) {
1084 bt_value
*initial_plugin_paths_copy
;
1086 (void) bt_value_copy(initial_plugin_paths
,
1087 &initial_plugin_paths_copy
);
1088 cfg
->plugin_paths
= initial_plugin_paths_copy
;
1090 cfg
->plugin_paths
= bt_value_array_create();
1091 if (!cfg
->plugin_paths
) {
1100 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1107 struct bt_config
*bt_config_run_create(
1108 const bt_value
*initial_plugin_paths
)
1110 struct bt_config
*cfg
;
1113 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1114 initial_plugin_paths
, true);
1119 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1120 (GDestroyNotify
) bt_object_put_ref
);
1121 if (!cfg
->cmd_data
.run
.sources
) {
1126 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1127 (GDestroyNotify
) bt_object_put_ref
);
1128 if (!cfg
->cmd_data
.run
.filters
) {
1133 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1134 (GDestroyNotify
) bt_object_put_ref
);
1135 if (!cfg
->cmd_data
.run
.sinks
) {
1140 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1141 (GDestroyNotify
) bt_config_connection_destroy
);
1142 if (!cfg
->cmd_data
.run
.connections
) {
1150 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1157 struct bt_config
*bt_config_list_plugins_create(
1158 const bt_value
*initial_plugin_paths
)
1160 struct bt_config
*cfg
;
1163 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1164 initial_plugin_paths
, true);
1172 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1179 struct bt_config
*bt_config_help_create(
1180 const bt_value
*initial_plugin_paths
,
1181 int default_log_level
)
1183 struct bt_config
*cfg
;
1186 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1187 initial_plugin_paths
, true);
1192 cfg
->cmd_data
.help
.cfg_component
=
1193 bt_config_component_create(-1, NULL
, NULL
, default_log_level
);
1194 if (!cfg
->cmd_data
.help
.cfg_component
) {
1201 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1208 struct bt_config
*bt_config_query_create(
1209 const bt_value
*initial_plugin_paths
)
1211 struct bt_config
*cfg
;
1214 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1215 initial_plugin_paths
, true);
1220 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1221 if (!cfg
->cmd_data
.query
.object
) {
1229 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1236 struct bt_config
*bt_config_print_ctf_metadata_create(
1237 const bt_value
*initial_plugin_paths
)
1239 struct bt_config
*cfg
;
1242 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1243 initial_plugin_paths
, true);
1248 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1249 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1254 cfg
->cmd_data
.print_ctf_metadata
.output_path
= g_string_new(NULL
);
1255 if (!cfg
->cmd_data
.print_ctf_metadata
.output_path
) {
1263 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1270 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1271 const bt_value
*initial_plugin_paths
)
1273 struct bt_config
*cfg
;
1276 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1277 initial_plugin_paths
, true);
1282 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1283 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1288 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
=
1290 if (!cfg
->cmd_data
.print_lttng_live_sessions
.output_path
) {
1298 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1305 int bt_config_append_plugin_paths_check_setuid_setgid(
1306 bt_value
*plugin_paths
, const char *arg
)
1310 if (bt_common_is_setuid_setgid()) {
1311 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1315 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1316 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1327 * Prints the expected format for a --params option.
1330 void print_expected_params_format(FILE *fp
)
1332 fprintf(fp
, "Expected format of PARAMS\n");
1333 fprintf(fp
, "-------------------------\n");
1335 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1337 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1338 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1339 fprintf(fp
, "and VALUE can be one of:\n");
1341 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1342 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1343 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1344 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1345 fprintf(fp
, " (`0x` prefix) unsigned (with `+` prefix) or signed 64-bit integer.\n");
1346 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1347 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1348 fprintf(fp
, " the null and boolean value symbols above.\n");
1349 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1350 fprintf(fp
, "* Array, formatted as an opening `[`, a list of comma-separated values\n");
1351 fprintf(fp
, " (as described by the current list) and a closing `]`.\n");
1353 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1355 fprintf(fp
, "Example:\n");
1357 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1358 fprintf(fp
, " play=+23, observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1359 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\",\n");
1360 fprintf(fp
, " things=[1, \"2\", 3]\n");
1362 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1363 fprintf(fp
, "babeltrace2 from a shell.\n");
1368 * Prints the help command usage.
1371 void print_help_usage(FILE *fp
)
1373 fprintf(fp
, "Usage: babeltrace2 [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1374 fprintf(fp
, " babeltrace2 [GENERAL OPTIONS] help [OPTIONS] TYPE.PLUGIN.CLS\n");
1376 fprintf(fp
, "Options:\n");
1378 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1379 fprintf(fp
, " (~/.local/lib/babeltrace2/plugins)\n");
1380 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1381 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1382 fprintf(fp
, " dynamic plugins can be loaded\n");
1383 fprintf(fp
, " -h, --help Show this help and quit\n");
1385 fprintf(fp
, "See `babeltrace2 --help` for the list of general options.\n");
1387 fprintf(fp
, "Use `babeltrace2 list-plugins` to show the list of available plugins.\n");
1391 struct poptOption help_long_options
[] = {
1392 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1393 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1394 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1395 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1396 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1397 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1401 * Creates a Babeltrace config object from the arguments of a help
1404 * *retcode is set to the appropriate exit code to use.
1407 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1408 int *retcode
, bool force_omit_system_plugin_path
,
1409 bool force_omit_home_plugin_path
,
1410 const bt_value
*initial_plugin_paths
, int default_log_level
)
1412 poptContext pc
= NULL
;
1416 struct bt_config
*cfg
= NULL
;
1417 const char *leftover
;
1418 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1421 cfg
= bt_config_help_create(initial_plugin_paths
, default_log_level
);
1426 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1427 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1428 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1434 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1435 help_long_options
, 0);
1437 printf_err("Cannot get popt context\n");
1441 poptReadDefaultConfig(pc
, 0);
1443 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1444 arg
= poptGetOptArg(pc
);
1447 case OPT_PLUGIN_PATH
:
1448 if (bt_config_append_plugin_paths_check_setuid_setgid(
1449 cfg
->plugin_paths
, arg
)) {
1453 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1454 cfg
->omit_system_plugin_path
= true;
1456 case OPT_OMIT_HOME_PLUGIN_PATH
:
1457 cfg
->omit_home_plugin_path
= true;
1460 print_help_usage(stdout
);
1462 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1465 printf_err("Unknown command-line option specified (option code %d)\n",
1474 /* Check for option parsing error */
1476 printf_err("While parsing command-line options, at option %s: %s\n",
1477 poptBadOption(pc
, 0), poptStrerror(opt
));
1481 leftover
= poptGetArg(pc
);
1483 plugin_comp_cls_names(leftover
, NULL
,
1484 &plugin_name
, &comp_cls_name
,
1485 &cfg
->cmd_data
.help
.cfg_component
->type
);
1486 if (plugin_name
&& comp_cls_name
) {
1487 /* Component class help */
1489 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1492 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1495 /* Fall back to plugin help */
1497 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1501 print_help_usage(stdout
);
1503 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1507 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1515 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1518 g_free(plugin_name
);
1519 g_free(comp_cls_name
);
1522 poptFreeContext(pc
);
1530 * Prints the help command usage.
1533 void print_query_usage(FILE *fp
)
1535 fprintf(fp
, "Usage: babeltrace2 [GEN OPTS] query [OPTS] TYPE.PLUGIN.CLS OBJECT\n");
1537 fprintf(fp
, "Options:\n");
1539 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1540 fprintf(fp
, " (~/.local/lib/babeltrace2/plugins)\n");
1541 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1542 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1543 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1544 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1545 fprintf(fp
, " dynamic plugins can be loaded\n");
1546 fprintf(fp
, " -h, --help Show this help and quit\n");
1547 fprintf(fp
, "\n\n");
1548 print_expected_params_format(fp
);
1552 struct poptOption query_long_options
[] = {
1553 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1554 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1555 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1556 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1557 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1558 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1559 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1563 * Creates a Babeltrace config object from the arguments of a query
1566 * *retcode is set to the appropriate exit code to use.
1569 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1570 int *retcode
, bool force_omit_system_plugin_path
,
1571 bool force_omit_home_plugin_path
,
1572 const bt_value
*initial_plugin_paths
,
1573 int default_log_level
)
1575 poptContext pc
= NULL
;
1579 struct bt_config
*cfg
= NULL
;
1580 const char *leftover
;
1582 GString
*error_str
= NULL
;
1584 params
= bt_value_null
;
1585 bt_value_get_ref(bt_value_null
);
1588 cfg
= bt_config_query_create(initial_plugin_paths
);
1593 error_str
= g_string_new(NULL
);
1599 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1600 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1601 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1607 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1608 query_long_options
, 0);
1610 printf_err("Cannot get popt context\n");
1614 poptReadDefaultConfig(pc
, 0);
1616 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1617 arg
= poptGetOptArg(pc
);
1620 case OPT_PLUGIN_PATH
:
1621 if (bt_config_append_plugin_paths_check_setuid_setgid(
1622 cfg
->plugin_paths
, arg
)) {
1626 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1627 cfg
->omit_system_plugin_path
= true;
1629 case OPT_OMIT_HOME_PLUGIN_PATH
:
1630 cfg
->omit_home_plugin_path
= true;
1634 bt_value_put_ref(params
);
1635 params
= cli_value_from_arg(arg
, error_str
);
1637 printf_err("Invalid format for --params option's argument:\n %s\n",
1644 print_query_usage(stdout
);
1646 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1649 printf_err("Unknown command-line option specified (option code %d)\n",
1658 /* Check for option parsing error */
1660 printf_err("While parsing command-line options, at option %s: %s\n",
1661 poptBadOption(pc
, 0), poptStrerror(opt
));
1666 * We need exactly two leftover arguments which are the
1667 * mandatory component class specification and query object.
1669 leftover
= poptGetArg(pc
);
1671 cfg
->cmd_data
.query
.cfg_component
=
1672 bt_config_component_from_arg(leftover
,
1674 if (!cfg
->cmd_data
.query
.cfg_component
) {
1675 printf_err("Invalid format for component class specification:\n %s\n",
1681 BT_OBJECT_MOVE_REF(cfg
->cmd_data
.query
.cfg_component
->params
,
1684 print_query_usage(stdout
);
1686 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1690 leftover
= poptGetArg(pc
);
1692 if (strlen(leftover
) == 0) {
1693 printf_err("Invalid empty object\n");
1697 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
1699 print_query_usage(stdout
);
1701 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1705 leftover
= poptGetArg(pc
);
1707 printf_err("Unexpected argument: %s\n", leftover
);
1711 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1719 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1723 poptFreeContext(pc
);
1727 g_string_free(error_str
, TRUE
);
1730 bt_value_put_ref(params
);
1736 * Prints the list-plugins command usage.
1739 void print_list_plugins_usage(FILE *fp
)
1741 fprintf(fp
, "Usage: babeltrace2 [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
1743 fprintf(fp
, "Options:\n");
1745 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1746 fprintf(fp
, " (~/.local/lib/babeltrace2/plugins)\n");
1747 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1748 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1749 fprintf(fp
, " dynamic plugins can be loaded\n");
1750 fprintf(fp
, " -h, --help Show this help and quit\n");
1752 fprintf(fp
, "See `babeltrace2 --help` for the list of general options.\n");
1754 fprintf(fp
, "Use `babeltrace2 help` to get help for a specific plugin or component class.\n");
1758 struct poptOption list_plugins_long_options
[] = {
1759 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1760 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1761 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1762 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1763 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1764 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1768 * Creates a Babeltrace config object from the arguments of a
1769 * list-plugins command.
1771 * *retcode is set to the appropriate exit code to use.
1774 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
1775 int *retcode
, bool force_omit_system_plugin_path
,
1776 bool force_omit_home_plugin_path
,
1777 const bt_value
*initial_plugin_paths
)
1779 poptContext pc
= NULL
;
1783 struct bt_config
*cfg
= NULL
;
1784 const char *leftover
;
1787 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
1792 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1793 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1794 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1800 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1801 list_plugins_long_options
, 0);
1803 printf_err("Cannot get popt context\n");
1807 poptReadDefaultConfig(pc
, 0);
1809 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1810 arg
= poptGetOptArg(pc
);
1813 case OPT_PLUGIN_PATH
:
1814 if (bt_config_append_plugin_paths_check_setuid_setgid(
1815 cfg
->plugin_paths
, arg
)) {
1819 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1820 cfg
->omit_system_plugin_path
= true;
1822 case OPT_OMIT_HOME_PLUGIN_PATH
:
1823 cfg
->omit_home_plugin_path
= true;
1826 print_list_plugins_usage(stdout
);
1828 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1831 printf_err("Unknown command-line option specified (option code %d)\n",
1840 /* Check for option parsing error */
1842 printf_err("While parsing command-line options, at option %s: %s\n",
1843 poptBadOption(pc
, 0), poptStrerror(opt
));
1847 leftover
= poptGetArg(pc
);
1849 printf_err("Unexpected argument: %s\n", leftover
);
1853 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1861 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1865 poptFreeContext(pc
);
1873 * Prints the run command usage.
1876 void print_run_usage(FILE *fp
)
1878 fprintf(fp
, "Usage: babeltrace2 [GENERAL OPTIONS] run [OPTIONS]\n");
1880 fprintf(fp
, "Options:\n");
1882 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
1883 fprintf(fp
, " for all the following components until\n");
1884 fprintf(fp
, " --reset-base-params is encountered\n");
1885 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1886 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
1887 fprintf(fp
, " Instantiate the component class CLS of type\n");
1888 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
1889 fprintf(fp
, " in the plugin PLUGIN, add it to the graph,\n");
1890 fprintf(fp
, " and optionally name it NAME (you can also\n");
1891 fprintf(fp
, " specify the name with --name)\n");
1892 fprintf(fp
, " -x, --connect=CONNECTION Connect two created components (see the\n");
1893 fprintf(fp
, " expected format of CONNECTION below)\n");
1894 fprintf(fp
, " -l, --log-level=LVL Set the log level of the current component to LVL\n");
1895 fprintf(fp
, " (`N`, `V`, `D`, `I`, `W`, `E`, or `F`)\n");
1896 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
1897 fprintf(fp
, " to NAME (must be unique amongst all the\n");
1898 fprintf(fp
, " names of the created components)\n");
1899 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1900 fprintf(fp
, " (~/.local/lib/babeltrace2/plugins)\n");
1901 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1902 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
1903 fprintf(fp
, " current component (see the expected format\n");
1904 fprintf(fp
, " of PARAMS below)\n");
1905 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1906 fprintf(fp
, " dynamic plugins can be loaded\n");
1907 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
1908 fprintf(fp
, " empty map\n");
1909 fprintf(fp
, " --retry-duration=DUR When babeltrace2(1) needs to retry to run\n");
1910 fprintf(fp
, " the graph later, retry in DUR µs\n");
1911 fprintf(fp
, " (default: 100000)\n");
1912 fprintf(fp
, " -h, --help Show this help and quit\n");
1914 fprintf(fp
, "See `babeltrace2 --help` for the list of general options.\n");
1915 fprintf(fp
, "\n\n");
1916 fprintf(fp
, "Expected format of CONNECTION\n");
1917 fprintf(fp
, "-----------------------------\n");
1919 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
1921 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
1922 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
1923 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
1924 fprintf(fp
, "component with the --name option.\n");
1926 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
1927 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
1928 fprintf(fp
, "When the port is not specified, `*` is used.\n");
1930 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
1931 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
1932 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
1933 fprintf(fp
, "DOWNSTREAM.\n");
1935 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
1936 fprintf(fp
, "which matches anything. You must escape the following characters\n");
1937 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
1939 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
1940 fprintf(fp
, "can connect a filter component to a sink component.\n");
1942 fprintf(fp
, "Examples:\n");
1944 fprintf(fp
, " my-src:my-sink\n");
1945 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
1947 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1948 fprintf(fp
, "babeltrace2 from a shell.\n");
1949 fprintf(fp
, "\n\n");
1950 print_expected_params_format(fp
);
1954 * Creates a Babeltrace config object from the arguments of a run
1957 * *retcode is set to the appropriate exit code to use.
1960 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
1961 int *retcode
, bool force_omit_system_plugin_path
,
1962 bool force_omit_home_plugin_path
,
1963 const bt_value
*initial_plugin_paths
, int default_log_level
)
1965 poptContext pc
= NULL
;
1967 struct bt_config_component
*cur_cfg_comp
= NULL
;
1968 enum bt_config_component_dest cur_cfg_comp_dest
=
1969 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
1970 bt_value
*cur_base_params
= NULL
;
1972 struct bt_config
*cfg
= NULL
;
1973 bt_value
*instance_names
= NULL
;
1974 bt_value
*connection_args
= NULL
;
1975 char error_buf
[256] = { 0 };
1976 long retry_duration
= -1;
1977 bt_value_map_extend_status extend_status
;
1978 GString
*error_str
= NULL
;
1979 struct poptOption run_long_options
[] = {
1980 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
1981 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
1982 { "connect", 'x', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
1983 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1984 { "log-level", 'l', POPT_ARG_STRING
, NULL
, OPT_LOG_LEVEL
, NULL
, NULL
},
1985 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
1986 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1987 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1988 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1989 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1990 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
1991 { "retry-duration", '\0', POPT_ARG_LONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
1992 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1997 error_str
= g_string_new(NULL
);
2004 print_run_usage(stdout
);
2009 cfg
= bt_config_run_create(initial_plugin_paths
);
2014 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2015 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2016 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2017 cur_base_params
= bt_value_map_create();
2018 if (!cur_base_params
) {
2023 instance_names
= bt_value_map_create();
2024 if (!instance_names
) {
2029 connection_args
= bt_value_array_create();
2030 if (!connection_args
) {
2035 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2041 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2042 run_long_options
, 0);
2044 printf_err("Cannot get popt context\n");
2048 poptReadDefaultConfig(pc
, 0);
2050 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2051 arg
= poptGetOptArg(pc
);
2054 case OPT_PLUGIN_PATH
:
2055 if (bt_config_append_plugin_paths_check_setuid_setgid(
2056 cfg
->plugin_paths
, arg
)) {
2060 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2061 cfg
->omit_system_plugin_path
= true;
2063 case OPT_OMIT_HOME_PLUGIN_PATH
:
2064 cfg
->omit_home_plugin_path
= true;
2068 enum bt_config_component_dest new_dest
;
2071 ret
= add_run_cfg_comp_check_name(cfg
,
2072 cur_cfg_comp
, cur_cfg_comp_dest
,
2074 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2080 cur_cfg_comp
= bt_config_component_from_arg(arg
,
2082 if (!cur_cfg_comp
) {
2083 printf_err("Invalid format for --component option's argument:\n %s\n",
2088 switch (cur_cfg_comp
->type
) {
2089 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
2090 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2092 case BT_COMPONENT_CLASS_TYPE_FILTER
:
2093 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2095 case BT_COMPONENT_CLASS_TYPE_SINK
:
2096 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2102 BT_ASSERT(cur_base_params
);
2103 bt_value_put_ref(cur_cfg_comp
->params
);
2104 if (bt_value_copy(cur_base_params
,
2105 &cur_cfg_comp
->params
) < 0) {
2110 cur_cfg_comp_dest
= new_dest
;
2116 bt_value
*params_to_set
;
2118 if (!cur_cfg_comp
) {
2119 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2124 params
= cli_value_from_arg(arg
, error_str
);
2126 printf_err("Invalid format for --params option's argument:\n %s\n",
2131 extend_status
= bt_value_map_extend(
2132 cur_cfg_comp
->params
, params
, ¶ms_to_set
);
2133 BT_VALUE_PUT_REF_AND_RESET(params
);
2134 if (extend_status
!= BT_VALUE_MAP_EXTEND_STATUS_OK
) {
2135 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2140 BT_OBJECT_MOVE_REF(cur_cfg_comp
->params
, params_to_set
);
2144 if (!cur_cfg_comp
) {
2145 printf_err("Cannot set the name of unavailable component:\n %s\n",
2150 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2153 if (!cur_cfg_comp
) {
2154 printf_err("Cannot set the log level of unavailable component:\n %s\n",
2159 cur_cfg_comp
->log_level
=
2160 bt_log_get_level_from_string(arg
);
2161 if (cur_cfg_comp
->log_level
< 0) {
2162 printf_err("Invalid argument for --log-level option:\n %s\n",
2167 case OPT_BASE_PARAMS
:
2169 bt_value
*params
= cli_value_from_arg(arg
, error_str
);
2172 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2177 BT_OBJECT_MOVE_REF(cur_base_params
, params
);
2180 case OPT_RESET_BASE_PARAMS
:
2181 BT_VALUE_PUT_REF_AND_RESET(cur_base_params
);
2182 cur_base_params
= bt_value_map_create();
2183 if (!cur_base_params
) {
2189 if (bt_value_array_append_string_element(
2190 connection_args
, arg
)) {
2195 case OPT_RETRY_DURATION
:
2196 if (retry_duration
< 0) {
2197 printf_err("--retry-duration option's argument must be positive or 0: %ld\n",
2202 cfg
->cmd_data
.run
.retry_duration_us
=
2203 (uint64_t) retry_duration
;
2206 print_run_usage(stdout
);
2208 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2211 printf_err("Unknown command-line option specified (option code %d)\n",
2220 /* Check for option parsing error */
2222 printf_err("While parsing command-line options, at option %s: %s\n",
2223 poptBadOption(pc
, 0), poptStrerror(opt
));
2227 /* This command does not accept leftover arguments */
2228 if (poptPeekArg(pc
)) {
2229 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2233 /* Add current component */
2235 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2236 cur_cfg_comp_dest
, instance_names
);
2237 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2243 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2244 printf_err("Incomplete graph: no source component\n");
2248 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2249 printf_err("Incomplete graph: no sink component\n");
2253 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2257 ret
= bt_config_cli_args_create_connections(cfg
,
2261 printf_err("Cannot creation connections:\n%s", error_buf
);
2269 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2273 poptFreeContext(pc
);
2277 g_string_free(error_str
, TRUE
);
2281 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2282 BT_VALUE_PUT_REF_AND_RESET(cur_base_params
);
2283 BT_VALUE_PUT_REF_AND_RESET(instance_names
);
2284 BT_VALUE_PUT_REF_AND_RESET(connection_args
);
2289 struct bt_config
*bt_config_run_from_args_array(const bt_value
*run_args
,
2290 int *retcode
, bool force_omit_system_plugin_path
,
2291 bool force_omit_home_plugin_path
,
2292 const bt_value
*initial_plugin_paths
, int default_log_level
)
2294 struct bt_config
*cfg
= NULL
;
2297 const size_t argc
= bt_value_array_get_size(run_args
) + 1;
2299 argv
= calloc(argc
, sizeof(*argv
));
2307 len
= bt_value_array_get_size(run_args
);
2309 printf_err("Invalid executable arguments\n");
2312 for (i
= 0; i
< len
; i
++) {
2313 const bt_value
*arg_value
=
2314 bt_value_array_borrow_element_by_index_const(run_args
,
2318 BT_ASSERT(arg_value
);
2319 arg
= bt_value_string_get(arg_value
);
2324 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2325 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2326 initial_plugin_paths
, default_log_level
);
2334 * Prints the convert command usage.
2337 void print_convert_usage(FILE *fp
)
2339 fprintf(fp
, "Usage: babeltrace2 [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2341 fprintf(fp
, "Options:\n");
2343 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2344 fprintf(fp
, " Instantiate the component class CLS of type\n");
2345 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2346 fprintf(fp
, " in the plugin PLUGIN, add it to the\n");
2347 fprintf(fp
, " conversion graph, and optionally name it\n");
2348 fprintf(fp
, " NAME (you can also specify the name with\n");
2349 fprintf(fp
, " --name)\n");
2350 fprintf(fp
, " -l, --log-level=LVL Set the log level of the current component to LVL\n");
2351 fprintf(fp
, " (`N`, `V`, `D`, `I`, `W`, `E`, or `F`)\n");
2352 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2353 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2354 fprintf(fp
, " names of the created components)\n");
2355 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2356 fprintf(fp
, " (~/.local/lib/babeltrace2/plugins)\n");
2357 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2358 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2359 fprintf(fp
, " current component (see the expected format\n");
2360 fprintf(fp
, " of PARAMS below)\n");
2361 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2362 fprintf(fp
, " current component to PATH\n");
2363 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2364 fprintf(fp
, " dynamic plugins can be loaded\n");
2365 fprintf(fp
, " --retry-duration=DUR When babeltrace2(1) needs to retry to run\n");
2366 fprintf(fp
, " the graph later, retry in DUR µs\n");
2367 fprintf(fp
, " (default: 100000)\n");
2368 fprintf(fp
, " dynamic plugins can be loaded\n");
2369 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2370 fprintf(fp
, " `run` command to the standard output,\n");
2371 fprintf(fp
, " formatted for a shell, and quit\n");
2372 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2373 fprintf(fp
, " `run` command to the standard output,\n");
2374 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2375 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2376 fprintf(fp
, " are active\n");
2377 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2378 fprintf(fp
, " current component to URL\n");
2379 fprintf(fp
, " -h, --help Show this help and quit\n");
2381 fprintf(fp
, "Implicit `source.ctf.fs` component options:\n");
2383 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2384 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2386 fprintf(fp
, "Implicit `sink.text.pretty` component options:\n");
2388 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2389 fprintf(fp
, " --clock-date Print timestamp dates\n");
2390 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2391 fprintf(fp
, " time zone instead of the local time zone\n");
2392 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2393 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2394 fprintf(fp
, " --color=(never | auto | always)\n");
2395 fprintf(fp
, " Never, automatically, or always emit\n");
2396 fprintf(fp
, " console color codes\n");
2397 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2398 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2399 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2400 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2401 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2402 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2403 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2404 fprintf(fp
, " (or `ctx`)\n");
2405 fprintf(fp
, " --no-delta Do not print time delta between\n");
2406 fprintf(fp
, " consecutive events\n");
2407 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2408 fprintf(fp
, " the standard output\n");
2410 fprintf(fp
, "Implicit `filter.utils.muxer` component options:\n");
2412 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2413 fprintf(fp
, " correlated across traces\n");
2415 fprintf(fp
, "Implicit `filter.utils.trimmer` component options:\n");
2417 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2418 fprintf(fp
, " time range to BEGIN (see the format of\n");
2419 fprintf(fp
, " BEGIN below)\n");
2420 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2421 fprintf(fp
, " range to END (see the format of END below)\n");
2422 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2423 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2424 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2426 fprintf(fp
, "Implicit `filter.lttng-utils.debug-info` component options:\n");
2428 fprintf(fp
, " --debug-info Create an implicit\n");
2429 fprintf(fp
, " `filter.lttng-utils.debug-info` component\n");
2430 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2431 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2432 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2433 fprintf(fp
, " binary paths instead of just names\n");
2434 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2435 fprintf(fp
, " Use directory DIR as a prefix when\n");
2436 fprintf(fp
, " looking up executables during debug\n");
2437 fprintf(fp
, " info analysis\n");
2439 fprintf(fp
, "Legacy options that still work:\n");
2441 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2442 fprintf(fp
, " `ctf`:\n");
2443 fprintf(fp
, " Create an implicit `source.ctf.fs`\n");
2444 fprintf(fp
, " component\n");
2445 fprintf(fp
, " `lttng-live`:\n");
2446 fprintf(fp
, " Create an implicit `source.ctf.lttng-live`\n");
2447 fprintf(fp
, " component\n");
2448 fprintf(fp
, " -o, --output-format=(text | ctf | dummy | ctf-metadata)\n");
2449 fprintf(fp
, " `text`:\n");
2450 fprintf(fp
, " Create an implicit `sink.text.pretty`\n");
2451 fprintf(fp
, " component\n");
2452 fprintf(fp
, " `ctf`:\n");
2453 fprintf(fp
, " Create an implicit `sink.ctf.fs`\n");
2454 fprintf(fp
, " component\n");
2455 fprintf(fp
, " `dummy`:\n");
2456 fprintf(fp
, " Create an implicit `sink.utils.dummy`\n");
2457 fprintf(fp
, " component\n");
2458 fprintf(fp
, " `ctf-metadata`:\n");
2459 fprintf(fp
, " Query the `source.ctf.fs` component class\n");
2460 fprintf(fp
, " for metadata text and quit\n");
2462 fprintf(fp
, "See `babeltrace2 --help` for the list of general options.\n");
2463 fprintf(fp
, "\n\n");
2464 fprintf(fp
, "Format of BEGIN and END\n");
2465 fprintf(fp
, "-----------------------\n");
2467 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2468 fprintf(fp
, "\n\n");
2469 print_expected_params_format(fp
);
2473 struct poptOption convert_long_options
[] = {
2474 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2475 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2476 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2477 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2478 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2479 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2480 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2481 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2482 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2483 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2484 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2485 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2486 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2487 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2488 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2489 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2490 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2491 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2492 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2493 { "log-level", 'l', POPT_ARG_STRING
, NULL
, OPT_LOG_LEVEL
, NULL
, NULL
},
2494 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2495 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2496 { "debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO
, NULL
, NULL
},
2497 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2498 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2499 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2500 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2501 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2502 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2503 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2504 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2505 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2506 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2507 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2508 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2509 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2510 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2511 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2512 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2516 GString
*get_component_auto_name(const char *prefix
,
2517 const bt_value
*existing_names
)
2520 GString
*auto_name
= g_string_new(NULL
);
2527 if (!bt_value_map_has_entry(existing_names
, prefix
)) {
2528 g_string_assign(auto_name
, prefix
);
2533 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2535 } while (bt_value_map_has_entry(existing_names
, auto_name
->str
));
2541 struct implicit_component_args
{
2545 GString
*params_arg
;
2546 bt_value
*extra_params
;
2550 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
2551 const char *prefix
, bt_value
*existing_names
,
2552 GList
**comp_names
, bool append_to_comp_names
)
2555 GString
*name
= NULL
;
2557 if (!args
->exists
) {
2561 name
= get_component_auto_name(prefix
,
2569 g_string_assign(args
->name_arg
, name
->str
);
2571 if (bt_value_map_insert_entry(existing_names
, name
->str
,
2578 if (append_to_comp_names
) {
2579 *comp_names
= g_list_append(*comp_names
, name
);
2585 g_string_free(name
, TRUE
);
2592 int append_run_args_for_implicit_component(
2593 struct implicit_component_args
*impl_args
,
2599 if (!impl_args
->exists
) {
2603 if (bt_value_array_append_string_element(run_args
, "--component")) {
2608 if (bt_value_array_append_string_element(run_args
, impl_args
->comp_arg
->str
)) {
2613 if (bt_value_array_append_string_element(run_args
, "--name")) {
2618 if (bt_value_array_append_string_element(run_args
, impl_args
->name_arg
->str
)) {
2623 if (impl_args
->params_arg
->len
> 0) {
2624 if (bt_value_array_append_string_element(run_args
, "--params")) {
2629 if (bt_value_array_append_string_element(run_args
,
2630 impl_args
->params_arg
->str
)) {
2636 for (i
= 0; i
< bt_value_array_get_size(impl_args
->extra_params
);
2638 const bt_value
*elem
;
2641 elem
= bt_value_array_borrow_element_by_index(impl_args
->extra_params
,
2647 BT_ASSERT(bt_value_is_string(elem
));
2648 arg
= bt_value_string_get(elem
);
2649 ret
= bt_value_array_append_string_element(run_args
, arg
);
2666 void finalize_implicit_component_args(struct implicit_component_args
*args
)
2670 if (args
->comp_arg
) {
2671 g_string_free(args
->comp_arg
, TRUE
);
2674 if (args
->name_arg
) {
2675 g_string_free(args
->name_arg
, TRUE
);
2678 if (args
->params_arg
) {
2679 g_string_free(args
->params_arg
, TRUE
);
2682 bt_value_put_ref(args
->extra_params
);
2686 int init_implicit_component_args(struct implicit_component_args
*args
,
2687 const char *comp_arg
, bool exists
)
2691 args
->exists
= exists
;
2692 args
->comp_arg
= g_string_new(comp_arg
);
2693 args
->name_arg
= g_string_new(NULL
);
2694 args
->params_arg
= g_string_new(NULL
);
2695 args
->extra_params
= bt_value_array_create();
2697 if (!args
->comp_arg
|| !args
->name_arg
||
2698 !args
->params_arg
|| !args
->extra_params
) {
2700 finalize_implicit_component_args(args
);
2710 void append_implicit_component_param(struct implicit_component_args
*args
,
2711 const char *key
, const char *value
)
2716 append_param_arg(args
->params_arg
, key
, value
);
2719 /* Escape value to make it suitable to use as a string parameter value. */
2721 gchar
*escape_string_value(const char *value
)
2726 ret
= g_string_new(NULL
);
2737 g_string_append_c(ret
, '\\');
2741 g_string_append_c(ret
, *in
);
2747 return g_string_free(ret
, FALSE
);
2751 int bt_value_to_cli_param_value_append(const bt_value
*value
, GString
*buf
)
2757 switch (bt_value_get_type(value
)) {
2758 case BT_VALUE_TYPE_STRING
:
2760 const char *str_value
= bt_value_string_get(value
);
2761 gchar
*escaped_str_value
;
2763 escaped_str_value
= escape_string_value(str_value
);
2764 if (!escaped_str_value
) {
2768 g_string_append_printf(buf
, "\"%s\"", escaped_str_value
);
2770 g_free(escaped_str_value
);
2773 case BT_VALUE_TYPE_ARRAY
: {
2774 g_string_append_c(buf
, '[');
2775 uint64_t sz
= bt_value_array_get_size(value
);
2776 for (uint64_t i
= 0; i
< sz
; i
++) {
2777 const bt_value
*item
;
2781 g_string_append(buf
, ", ");
2784 item
= bt_value_array_borrow_element_by_index_const(
2786 ret
= bt_value_to_cli_param_value_append(item
, buf
);
2792 g_string_append_c(buf
, ']');
2806 * Convert `value` to its equivalent representation as a command line parameter
2811 gchar
*bt_value_to_cli_param_value(bt_value
*value
)
2814 gchar
*result
= NULL
;
2816 buf
= g_string_new(NULL
);
2822 if (bt_value_to_cli_param_value_append(value
, buf
)) {
2826 result
= g_string_free(buf
, FALSE
);
2833 g_string_free(buf
, TRUE
);
2841 int append_parameter_to_args(bt_value
*args
, const char *key
, bt_value
*value
)
2844 BT_ASSERT(bt_value_get_type(args
) == BT_VALUE_TYPE_ARRAY
);
2849 gchar
*str_value
= NULL
;
2850 GString
*parameter
= NULL
;
2852 if (bt_value_array_append_string_element(args
, "--params")) {
2858 str_value
= bt_value_to_cli_param_value(value
);
2864 parameter
= g_string_new(NULL
);
2871 g_string_printf(parameter
, "%s=%s", key
, str_value
);
2873 if (bt_value_array_append_string_element(args
, parameter
->str
)) {
2881 g_string_free(parameter
, TRUE
);
2894 int append_string_parameter_to_args(bt_value
*args
, const char *key
, const char *value
)
2896 bt_value
*str_value
;
2899 str_value
= bt_value_string_create_init(value
);
2907 ret
= append_parameter_to_args(args
, key
, str_value
);
2910 BT_VALUE_PUT_REF_AND_RESET(str_value
);
2915 int append_implicit_component_extra_param(struct implicit_component_args
*args
,
2916 const char *key
, const char *value
)
2918 return append_string_parameter_to_args(args
->extra_params
, key
, value
);
2922 int convert_append_name_param(enum bt_config_component_dest dest
,
2923 GString
*cur_name
, GString
*cur_name_prefix
,
2925 bt_value
*all_names
,
2926 GList
**source_names
, GList
**filter_names
,
2931 if (cur_name_prefix
->len
> 0) {
2932 /* We're after a --component option */
2933 GString
*name
= NULL
;
2934 bool append_name_opt
= false;
2936 if (cur_name
->len
== 0) {
2938 * No explicit name was provided for the user
2941 name
= get_component_auto_name(cur_name_prefix
->str
,
2943 append_name_opt
= true;
2946 * An explicit name was provided for the user
2949 if (bt_value_map_has_entry(all_names
,
2951 printf_err("Duplicate component instance name:\n %s\n",
2956 name
= g_string_new(cur_name
->str
);
2965 * Remember this name globally, for the uniqueness of
2966 * all component names.
2968 if (bt_value_map_insert_entry(all_names
, name
->str
, bt_value_null
)) {
2974 * Append the --name option if necessary.
2976 if (append_name_opt
) {
2977 if (bt_value_array_append_string_element(run_args
, "--name")) {
2982 if (bt_value_array_append_string_element(run_args
, name
->str
)) {
2989 * Remember this name specifically for the type of the
2990 * component. This is to create connection arguments.
2993 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
2994 *source_names
= g_list_append(*source_names
, name
);
2996 case BT_CONFIG_COMPONENT_DEST_FILTER
:
2997 *filter_names
= g_list_append(*filter_names
, name
);
2999 case BT_CONFIG_COMPONENT_DEST_SINK
:
3000 *sink_names
= g_list_append(*sink_names
, name
);
3006 g_string_assign(cur_name_prefix
, "");
3019 * Escapes `.`, `:`, and `\` of `input` with `\`.
3022 GString
*escape_dot_colon(const char *input
)
3024 GString
*output
= g_string_new(NULL
);
3032 for (ch
= input
; *ch
!= '\0'; ch
++) {
3033 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3034 g_string_append_c(output
, '\\');
3037 g_string_append_c(output
, *ch
);
3045 * Appends a --connect option to a list of arguments. `upstream_name`
3046 * and `downstream_name` are escaped with escape_dot_colon() in this
3050 int append_connect_arg(bt_value
*run_args
,
3051 const char *upstream_name
, const char *downstream_name
)
3054 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3055 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3056 GString
*arg
= g_string_new(NULL
);
3058 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3064 ret
= bt_value_array_append_string_element(run_args
, "--connect");
3071 g_string_append(arg
, e_upstream_name
->str
);
3072 g_string_append_c(arg
, ':');
3073 g_string_append(arg
, e_downstream_name
->str
);
3074 ret
= bt_value_array_append_string_element(run_args
, arg
->str
);
3083 g_string_free(arg
, TRUE
);
3086 if (e_upstream_name
) {
3087 g_string_free(e_upstream_name
, TRUE
);
3090 if (e_downstream_name
) {
3091 g_string_free(e_downstream_name
, TRUE
);
3098 * Appends the run command's --connect options for the convert command.
3101 int convert_auto_connect(bt_value
*run_args
,
3102 GList
*source_names
, GList
*filter_names
,
3106 GList
*source_at
= source_names
;
3107 GList
*filter_at
= filter_names
;
3109 GList
*sink_at
= sink_names
;
3111 BT_ASSERT(source_names
);
3112 BT_ASSERT(filter_names
);
3113 BT_ASSERT(sink_names
);
3115 /* Connect all sources to the first filter */
3116 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3117 GString
*source_name
= source_at
->data
;
3118 GString
*filter_name
= filter_at
->data
;
3120 ret
= append_connect_arg(run_args
, source_name
->str
,
3127 filter_prev
= filter_at
;
3128 filter_at
= g_list_next(filter_at
);
3130 /* Connect remaining filters */
3131 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3132 GString
*filter_name
= filter_at
->data
;
3133 GString
*filter_prev_name
= filter_prev
->data
;
3135 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3142 /* Connect last filter to all sinks */
3143 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3144 GString
*filter_name
= filter_prev
->data
;
3145 GString
*sink_name
= sink_at
->data
;
3147 ret
= append_connect_arg(run_args
, filter_name
->str
,
3164 int split_timerange(const char *arg
, char **begin
, char **end
)
3167 const char *ch
= arg
;
3169 GString
*g_begin
= NULL
;
3170 GString
*g_end
= NULL
;
3178 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3179 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3185 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3186 if (!g_end
|| g_end
->len
== 0) {
3192 *begin
= g_begin
->str
;
3194 g_string_free(g_begin
, FALSE
);
3195 g_string_free(g_end
, FALSE
);
3205 g_string_free(g_begin
, TRUE
);
3209 g_string_free(g_end
, TRUE
);
3216 int g_list_prepend_gstring(GList
**list
, const char *string
)
3219 GString
*gs
= g_string_new(string
);
3228 *list
= g_list_prepend(*list
, gs
);
3235 * Creates a Babeltrace config object from the arguments of a convert
3238 * *retcode is set to the appropriate exit code to use.
3241 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3242 int *retcode
, bool force_omit_system_plugin_path
,
3243 bool force_omit_home_plugin_path
,
3244 const bt_value
*initial_plugin_paths
, int *default_log_level
)
3246 poptContext pc
= NULL
;
3248 enum bt_config_component_dest cur_comp_dest
=
3249 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3251 struct bt_config
*cfg
= NULL
;
3252 bool got_input_format_opt
= false;
3253 bool got_output_format_opt
= false;
3254 bool trimmer_has_begin
= false;
3255 bool trimmer_has_end
= false;
3256 bool stream_intersection_mode
= false;
3257 GString
*cur_name
= NULL
;
3258 GString
*cur_name_prefix
= NULL
;
3259 const char *leftover
= NULL
;
3260 bool print_run_args
= false;
3261 bool print_run_args_0
= false;
3262 bool print_ctf_metadata
= false;
3263 bt_value
*run_args
= NULL
;
3264 bt_value
*all_names
= NULL
;
3265 GList
*source_names
= NULL
;
3266 GList
*filter_names
= NULL
;
3267 GList
*sink_names
= NULL
;
3268 bt_value
*leftovers
= NULL
;
3269 struct implicit_component_args implicit_ctf_input_args
= { 0 };
3270 struct implicit_component_args implicit_ctf_output_args
= { 0 };
3271 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3272 struct implicit_component_args implicit_dummy_args
= { 0 };
3273 struct implicit_component_args implicit_text_args
= { 0 };
3274 struct implicit_component_args implicit_debug_info_args
= { 0 };
3275 struct implicit_component_args implicit_muxer_args
= { 0 };
3276 struct implicit_component_args implicit_trimmer_args
= { 0 };
3277 bt_value
*plugin_paths
;
3278 char error_buf
[256] = { 0 };
3280 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3281 char *output
= NULL
;
3283 (void) bt_value_copy(initial_plugin_paths
, &plugin_paths
);
3288 print_convert_usage(stdout
);
3293 if (init_implicit_component_args(&implicit_ctf_input_args
,
3294 "source.ctf.fs", false)) {
3298 if (init_implicit_component_args(&implicit_ctf_output_args
,
3299 "sink.ctf.fs", false)) {
3303 if (init_implicit_component_args(&implicit_lttng_live_args
,
3304 "source.ctf.lttng-live", false)) {
3308 if (init_implicit_component_args(&implicit_text_args
,
3309 "sink.text.pretty", false)) {
3313 if (init_implicit_component_args(&implicit_dummy_args
,
3314 "sink.utils.dummy", false)) {
3318 if (init_implicit_component_args(&implicit_debug_info_args
,
3319 "filter.lttng-utils.debug-info", false)) {
3323 if (init_implicit_component_args(&implicit_muxer_args
,
3324 "filter.utils.muxer", true)) {
3328 if (init_implicit_component_args(&implicit_trimmer_args
,
3329 "filter.utils.trimmer", false)) {
3333 all_names
= bt_value_map_create();
3339 run_args
= bt_value_array_create();
3345 cur_name
= g_string_new(NULL
);
3351 cur_name_prefix
= g_string_new(NULL
);
3352 if (!cur_name_prefix
) {
3357 ret
= append_env_var_plugin_paths(plugin_paths
);
3362 leftovers
= bt_value_array_create();
3369 * First pass: collect all arguments which need to be passed
3370 * as is to the run command. This pass can also add --name
3371 * arguments if needed to automatically name unnamed component
3372 * instances. Also it does the following transformations:
3374 * --path=PATH -> --params=path="PATH"
3375 * --url=URL -> --params=url="URL"
3377 * Also it appends the plugin paths of --plugin-path to
3380 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3381 convert_long_options
, 0);
3383 printf_err("Cannot get popt context\n");
3387 poptReadDefaultConfig(pc
, 0);
3389 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3391 char *plugin_name
= NULL
;
3392 char *comp_cls_name
= NULL
;
3394 arg
= poptGetOptArg(pc
);
3399 bt_component_class_type type
;
3400 const char *type_prefix
;
3402 /* Append current component's name if needed */
3403 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3404 cur_name_prefix
, run_args
, all_names
,
3405 &source_names
, &filter_names
, &sink_names
);
3410 /* Parse the argument */
3411 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3412 &comp_cls_name
, &type
);
3413 if (!plugin_name
|| !comp_cls_name
) {
3414 printf_err("Invalid format for --component option's argument:\n %s\n",
3420 g_string_assign(cur_name
, name
);
3422 g_string_assign(cur_name
, "");
3426 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3427 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3428 type_prefix
= "source";
3430 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3431 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
3432 type_prefix
= "filter";
3434 case BT_COMPONENT_CLASS_TYPE_SINK
:
3435 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3436 type_prefix
= "sink";
3442 if (bt_value_array_append_string_element(run_args
,
3448 if (bt_value_array_append_string_element(run_args
, arg
)) {
3453 g_string_assign(cur_name_prefix
, "");
3454 g_string_append_printf(cur_name_prefix
, "%s.%s.%s",
3455 type_prefix
, plugin_name
, comp_cls_name
);
3458 free(comp_cls_name
);
3461 comp_cls_name
= NULL
;
3465 if (cur_name_prefix
->len
== 0) {
3466 printf_err("No current component of which to set parameters:\n %s\n",
3471 if (bt_value_array_append_string_element(run_args
,
3477 if (bt_value_array_append_string_element(run_args
, arg
)) {
3483 if (cur_name_prefix
->len
== 0) {
3484 printf_err("No current component of which to set `path` parameter:\n %s\n",
3489 if (append_string_parameter_to_args(run_args
, "path", arg
)) {
3494 if (cur_name_prefix
->len
== 0) {
3495 printf_err("No current component of which to set `url` parameter:\n %s\n",
3501 if (append_string_parameter_to_args(run_args
, "url", arg
)) {
3506 if (cur_name_prefix
->len
== 0) {
3507 printf_err("No current component to name:\n %s\n",
3512 if (bt_value_array_append_string_element(run_args
, "--name")) {
3517 if (bt_value_array_append_string_element(run_args
, arg
)) {
3522 g_string_assign(cur_name
, arg
);
3525 if (cur_name_prefix
->len
== 0) {
3526 printf_err("No current component to assign a log level to:\n %s\n",
3531 if (bt_value_array_append_string_element(run_args
, "--log-level")) {
3536 if (bt_value_array_append_string_element(run_args
, arg
)) {
3542 case OPT_OMIT_HOME_PLUGIN_PATH
:
3543 force_omit_home_plugin_path
= true;
3545 if (bt_value_array_append_string_element(run_args
,
3546 "--omit-home-plugin-path")) {
3551 case OPT_RETRY_DURATION
:
3552 if (bt_value_array_append_string_element(run_args
,
3553 "--retry-duration")) {
3558 if (bt_value_array_append_string_element(run_args
, arg
)) {
3563 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3564 force_omit_system_plugin_path
= true;
3566 if (bt_value_array_append_string_element(run_args
,
3567 "--omit-system-plugin-path")) {
3572 case OPT_PLUGIN_PATH
:
3573 if (bt_config_append_plugin_paths_check_setuid_setgid(
3574 plugin_paths
, arg
)) {
3578 if (bt_value_array_append_string_element(run_args
,
3584 if (bt_value_array_append_string_element(run_args
, arg
)) {
3590 print_convert_usage(stdout
);
3592 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
3595 case OPT_CLOCK_CYCLES
:
3596 case OPT_CLOCK_DATE
:
3597 case OPT_CLOCK_FORCE_CORRELATE
:
3599 case OPT_CLOCK_OFFSET
:
3600 case OPT_CLOCK_OFFSET_NS
:
3601 case OPT_CLOCK_SECONDS
:
3604 case OPT_DEBUG_INFO
:
3605 case OPT_DEBUG_INFO_DIR
:
3606 case OPT_DEBUG_INFO_FULL_PATH
:
3607 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3610 case OPT_INPUT_FORMAT
:
3613 case OPT_OUTPUT_FORMAT
:
3616 case OPT_RUN_ARGS_0
:
3617 case OPT_STREAM_INTERSECTION
:
3620 /* Ignore in this pass */
3623 printf_err("Unknown command-line option specified (option code %d)\n",
3632 /* Append current component's name if needed */
3633 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3634 cur_name_prefix
, run_args
, all_names
, &source_names
,
3635 &filter_names
, &sink_names
);
3640 /* Check for option parsing error */
3642 printf_err("While parsing command-line options, at option %s: %s\n",
3643 poptBadOption(pc
, 0), poptStrerror(opt
));
3647 poptFreeContext(pc
);
3652 * Second pass: transform the convert-specific options and
3653 * arguments into implicit component instances for the run
3656 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3657 convert_long_options
, 0);
3659 printf_err("Cannot get popt context\n");
3663 poptReadDefaultConfig(pc
, 0);
3665 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3666 arg
= poptGetOptArg(pc
);
3670 if (trimmer_has_begin
) {
3671 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
3676 trimmer_has_begin
= true;
3677 ret
= append_implicit_component_extra_param(
3678 &implicit_trimmer_args
, "begin", arg
);
3679 implicit_trimmer_args
.exists
= true;
3685 if (trimmer_has_end
) {
3686 printf("At --end option: --end or --timerange option already specified\n %s\n",
3691 trimmer_has_end
= true;
3692 ret
= append_implicit_component_extra_param(
3693 &implicit_trimmer_args
, "end", arg
);
3694 implicit_trimmer_args
.exists
= true;
3704 if (trimmer_has_begin
|| trimmer_has_end
) {
3705 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
3710 ret
= split_timerange(arg
, &begin
, &end
);
3712 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
3717 ret
= append_implicit_component_extra_param(
3718 &implicit_trimmer_args
, "begin", begin
);
3719 ret
|= append_implicit_component_extra_param(
3720 &implicit_trimmer_args
, "end", end
);
3721 implicit_trimmer_args
.exists
= true;
3729 case OPT_CLOCK_CYCLES
:
3730 append_implicit_component_param(
3731 &implicit_text_args
, "clock-cycles", "yes");
3732 implicit_text_args
.exists
= true;
3734 case OPT_CLOCK_DATE
:
3735 append_implicit_component_param(
3736 &implicit_text_args
, "clock-date", "yes");
3737 implicit_text_args
.exists
= true;
3739 case OPT_CLOCK_FORCE_CORRELATE
:
3740 append_implicit_component_param(
3741 &implicit_muxer_args
,
3742 "assume-absolute-clock-classes", "yes");
3745 append_implicit_component_param(
3746 &implicit_text_args
, "clock-gmt", "yes");
3747 append_implicit_component_param(
3748 &implicit_trimmer_args
, "gmt", "yes");
3749 implicit_text_args
.exists
= true;
3751 case OPT_CLOCK_OFFSET
:
3752 implicit_ctf_input_args
.exists
= true;
3753 append_implicit_component_param(
3754 &implicit_ctf_input_args
,
3755 "clock-class-offset-s", arg
);
3757 case OPT_CLOCK_OFFSET_NS
:
3758 implicit_ctf_input_args
.exists
= true;
3759 append_implicit_component_param(
3760 &implicit_ctf_input_args
,
3761 "clock-class-offset-ns", arg
);
3763 case OPT_CLOCK_SECONDS
:
3764 append_implicit_component_param(
3765 &implicit_text_args
, "clock-seconds", "yes");
3766 implicit_text_args
.exists
= true;
3769 implicit_text_args
.exists
= true;
3770 ret
= append_implicit_component_extra_param(
3771 &implicit_text_args
, "color", arg
);
3776 case OPT_DEBUG_INFO
:
3777 implicit_debug_info_args
.exists
= true;
3779 case OPT_DEBUG_INFO_DIR
:
3780 implicit_debug_info_args
.exists
= true;
3781 ret
= append_implicit_component_extra_param(
3782 &implicit_debug_info_args
, "debug-info-dir", arg
);
3787 case OPT_DEBUG_INFO_FULL_PATH
:
3788 implicit_debug_info_args
.exists
= true;
3789 append_implicit_component_param(
3790 &implicit_debug_info_args
, "full-path", "yes");
3792 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3793 implicit_debug_info_args
.exists
= true;
3794 ret
= append_implicit_component_extra_param(
3795 &implicit_debug_info_args
,
3796 "target-prefix", arg
);
3803 bt_value
*fields
= fields_from_arg(arg
);
3809 implicit_text_args
.exists
= true;
3810 ret
= insert_flat_params_from_array(
3811 implicit_text_args
.params_arg
,
3813 bt_value_put_ref(fields
);
3821 bt_value
*names
= names_from_arg(arg
);
3827 implicit_text_args
.exists
= true;
3828 ret
= insert_flat_params_from_array(
3829 implicit_text_args
.params_arg
,
3831 bt_value_put_ref(names
);
3838 append_implicit_component_param(
3839 &implicit_text_args
, "no-delta", "yes");
3840 implicit_text_args
.exists
= true;
3842 case OPT_INPUT_FORMAT
:
3843 if (got_input_format_opt
) {
3844 printf_err("Duplicate --input-format option\n");
3848 got_input_format_opt
= true;
3850 if (strcmp(arg
, "ctf") == 0) {
3851 implicit_ctf_input_args
.exists
= true;
3852 } else if (strcmp(arg
, "lttng-live") == 0) {
3853 implicit_lttng_live_args
.exists
= true;
3855 printf_err("Unknown legacy input format:\n %s\n",
3860 case OPT_OUTPUT_FORMAT
:
3861 if (got_output_format_opt
) {
3862 printf_err("Duplicate --output-format option\n");
3866 got_output_format_opt
= true;
3868 if (strcmp(arg
, "text") == 0) {
3869 implicit_text_args
.exists
= true;
3870 } else if (strcmp(arg
, "ctf") == 0) {
3871 implicit_ctf_output_args
.exists
= true;
3872 } else if (strcmp(arg
, "dummy") == 0) {
3873 implicit_dummy_args
.exists
= true;
3874 } else if (strcmp(arg
, "ctf-metadata") == 0) {
3875 print_ctf_metadata
= true;
3877 printf_err("Unknown legacy output format:\n %s\n",
3884 printf_err("Duplicate --output option\n");
3888 output
= strdup(arg
);
3895 if (print_run_args_0
) {
3896 printf_err("Cannot specify --run-args and --run-args-0\n");
3900 print_run_args
= true;
3902 case OPT_RUN_ARGS_0
:
3903 if (print_run_args
) {
3904 printf_err("Cannot specify --run-args and --run-args-0\n");
3908 print_run_args_0
= true;
3910 case OPT_STREAM_INTERSECTION
:
3912 * Applies to all traces implementing the trace-info
3915 stream_intersection_mode
= true;
3918 if (*default_log_level
!= BT_LOG_TRACE
&&
3919 *default_log_level
!= BT_LOG_DEBUG
) {
3920 *default_log_level
= BT_LOG_INFO
;
3924 *default_log_level
= BT_LOG_TRACE
;
3934 /* Check for option parsing error */
3936 printf_err("While parsing command-line options, at option %s: %s\n",
3937 poptBadOption(pc
, 0), poptStrerror(opt
));
3942 * Legacy behaviour: --verbose used to make the `text` output
3943 * format print more information. --verbose is now equivalent to
3944 * the INFO log level, which is why we compare to `BT_LOG_INFO`
3947 if (*default_log_level
== BT_LOG_INFO
) {
3948 append_implicit_component_param(&implicit_text_args
,
3953 * Append home and system plugin paths now that we possibly got
3956 if (append_home_and_system_plugin_paths(plugin_paths
,
3957 force_omit_system_plugin_path
,
3958 force_omit_home_plugin_path
)) {
3962 /* Consume and keep leftover arguments */
3963 while ((leftover
= poptGetArg(pc
))) {
3964 if (bt_value_array_append_string_element(leftovers
, leftover
) !=
3965 BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
) {
3971 /* Print CTF metadata or print LTTng live sessions */
3972 if (print_ctf_metadata
) {
3973 const bt_value
*bt_val_leftover
;
3975 if (bt_value_array_is_empty(leftovers
)) {
3976 printf_err("--output-format=ctf-metadata specified without a path\n");
3980 if (bt_value_array_get_size(leftovers
) > 1) {
3981 printf_err("Too many paths specified for --output-format=ctf-metadata\n");
3985 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
3990 bt_val_leftover
= bt_value_array_borrow_element_by_index_const(leftovers
, 0);
3991 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
3992 bt_value_string_get(bt_val_leftover
));
3996 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
4004 * If -o ctf was specified, make sure an output path (--output)
4005 * was also specified. --output does not imply -o ctf because
4006 * it's also used for the default, implicit -o text if -o ctf
4009 if (implicit_ctf_output_args
.exists
) {
4011 printf_err("--output-format=ctf specified without --output (trace output path)\n");
4016 * At this point we know that -o ctf AND --output were
4017 * specified. Make sure that no options were specified
4018 * which would imply -o text because --output would be
4019 * ambiguous in this case. For example, this is wrong:
4021 * babeltrace2 --names=all -o ctf --output=/tmp/path my-trace
4023 * because --names=all implies -o text, and --output
4024 * could apply to both the sink.text.pretty and
4025 * sink.ctf.fs implicit components.
4027 if (implicit_text_args
.exists
) {
4028 printf_err("Ambiguous --output option: --output-format=ctf specified but another option implies --output-format=text\n");
4034 * If -o dummy and -o ctf were not specified, and if there are
4035 * no explicit sink components, then use an implicit
4036 * `sink.text.pretty` component.
4038 if (!implicit_dummy_args
.exists
&& !implicit_ctf_output_args
.exists
&&
4040 implicit_text_args
.exists
= true;
4044 * Set implicit `sink.text.pretty` or `sink.ctf.fs` component's
4045 * `path` parameter if --output was specified.
4048 if (implicit_text_args
.exists
) {
4049 append_implicit_component_extra_param(&implicit_text_args
,
4051 } else if (implicit_ctf_output_args
.exists
) {
4052 append_implicit_component_extra_param(&implicit_ctf_output_args
,
4057 /* Decide where the leftover argument(s) go */
4058 if (bt_value_array_get_size(leftovers
) > 0) {
4059 if (implicit_lttng_live_args
.exists
) {
4060 const bt_value
*bt_val_leftover
;
4062 if (bt_value_array_get_size(leftovers
) > 1) {
4063 printf_err("Too many URLs specified for --input-format=lttng-live\n");
4067 bt_val_leftover
= bt_value_array_borrow_element_by_index_const(leftovers
, 0);
4068 lttng_live_url_parts
=
4069 bt_common_parse_lttng_live_url(bt_value_string_get(bt_val_leftover
),
4070 error_buf
, sizeof(error_buf
));
4071 if (!lttng_live_url_parts
.proto
) {
4072 printf_err("Invalid LTTng live URL format: %s\n",
4077 if (!lttng_live_url_parts
.session_name
) {
4078 /* Print LTTng live sessions */
4079 cfg
= bt_config_print_lttng_live_sessions_create(
4085 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4086 bt_value_string_get(bt_val_leftover
));
4090 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
4097 ret
= append_implicit_component_extra_param(
4098 &implicit_lttng_live_args
, "url",
4099 bt_value_string_get(bt_val_leftover
));
4104 ret
= append_implicit_component_extra_param(
4105 &implicit_lttng_live_args
,
4106 "session-not-found-action", "end");
4112 * Create one source.ctf.fs component, pass it an array
4113 * with the leftovers.
4114 * Note that it still has to be named later.
4116 implicit_ctf_input_args
.exists
= true;
4117 ret
= append_parameter_to_args(implicit_ctf_input_args
.extra_params
,
4118 "paths", leftovers
);
4126 * Ensure mutual exclusion between implicit `source.ctf.fs` and
4127 * `source.ctf.lttng-live` components.
4129 if (implicit_ctf_input_args
.exists
&& implicit_lttng_live_args
.exists
) {
4130 printf_err("Cannot create both implicit `%s` and `%s` components\n",
4131 implicit_ctf_input_args
.comp_arg
->str
,
4132 implicit_lttng_live_args
.comp_arg
->str
);
4137 * If the implicit `source.ctf.fs` or `source.ctf.lttng-live`
4138 * components exists, make sure there's at least one leftover
4139 * (which is the path or URL).
4141 if (implicit_ctf_input_args
.exists
&& bt_value_array_is_empty(leftovers
)) {
4142 printf_err("Missing path for implicit `%s` component\n",
4143 implicit_ctf_input_args
.comp_arg
->str
);
4147 if (implicit_lttng_live_args
.exists
&& bt_value_array_is_empty(leftovers
)) {
4148 printf_err("Missing URL for implicit `%s` component\n",
4149 implicit_lttng_live_args
.comp_arg
->str
);
4153 /* Assign names to implicit components */
4154 ret
= assign_name_to_implicit_component(&implicit_ctf_input_args
,
4155 "source-ctf-fs", all_names
, &source_names
, true);
4160 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4161 "lttng-live", all_names
, &source_names
, true);
4166 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4167 "pretty", all_names
, &sink_names
, true);
4172 ret
= assign_name_to_implicit_component(&implicit_ctf_output_args
,
4173 "sink-ctf-fs", all_names
, &sink_names
, true);
4178 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4179 "dummy", all_names
, &sink_names
, true);
4184 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4185 "muxer", all_names
, NULL
, false);
4190 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4191 "trimmer", all_names
, NULL
, false);
4196 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4197 "debug-info", all_names
, NULL
, false);
4202 /* Make sure there's at least one source and one sink */
4203 if (!source_names
) {
4204 printf_err("No source component\n");
4209 printf_err("No sink component\n");
4214 * Prepend the muxer, the trimmer, and the debug info to the
4215 * filter chain so that we have:
4217 * sources -> muxer -> [trimmer] -> [debug info] ->
4218 * [user filters] -> sinks
4220 if (implicit_debug_info_args
.exists
) {
4221 if (g_list_prepend_gstring(&filter_names
,
4222 implicit_debug_info_args
.name_arg
->str
)) {
4227 if (implicit_trimmer_args
.exists
) {
4228 if (g_list_prepend_gstring(&filter_names
,
4229 implicit_trimmer_args
.name_arg
->str
)) {
4234 if (g_list_prepend_gstring(&filter_names
,
4235 implicit_muxer_args
.name_arg
->str
)) {
4240 * Append the equivalent run arguments for the implicit
4243 ret
= append_run_args_for_implicit_component(&implicit_ctf_input_args
, run_args
);
4248 ret
= append_run_args_for_implicit_component(&implicit_lttng_live_args
,
4254 ret
= append_run_args_for_implicit_component(&implicit_text_args
,
4260 ret
= append_run_args_for_implicit_component(&implicit_ctf_output_args
,
4266 ret
= append_run_args_for_implicit_component(&implicit_dummy_args
,
4272 ret
= append_run_args_for_implicit_component(&implicit_muxer_args
,
4278 ret
= append_run_args_for_implicit_component(&implicit_trimmer_args
,
4284 ret
= append_run_args_for_implicit_component(&implicit_debug_info_args
,
4290 /* Auto-connect components */
4291 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4294 printf_err("Cannot auto-connect components\n");
4299 * We have all the run command arguments now. Depending on
4300 * --run-args, we pass this to the run command or print them
4303 if (print_run_args
|| print_run_args_0
) {
4304 if (stream_intersection_mode
) {
4305 printf_err("Cannot specify --stream-intersection with --run-args or --run-args-0\n");
4309 for (i
= 0; i
< bt_value_array_get_size(run_args
); i
++) {
4310 const bt_value
*arg_value
=
4311 bt_value_array_borrow_element_by_index(run_args
,
4314 GString
*quoted
= NULL
;
4315 const char *arg_to_print
;
4317 BT_ASSERT(arg_value
);
4318 arg
= bt_value_string_get(arg_value
);
4320 if (print_run_args
) {
4321 quoted
= bt_common_shell_quote(arg
, true);
4326 arg_to_print
= quoted
->str
;
4331 printf("%s", arg_to_print
);
4334 g_string_free(quoted
, TRUE
);
4337 if (i
< bt_value_array_get_size(run_args
) - 1) {
4338 if (print_run_args
) {
4347 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4352 * If the log level is still unset at this point, set it to
4353 * the program's default.
4355 if (*default_log_level
< 0) {
4356 *default_log_level
= cli_default_log_level
;
4359 cfg
= bt_config_run_from_args_array(run_args
, retcode
,
4360 force_omit_system_plugin_path
,
4361 force_omit_home_plugin_path
,
4362 initial_plugin_paths
, *default_log_level
);
4367 cfg
->cmd_data
.run
.stream_intersection_mode
= stream_intersection_mode
;
4372 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4376 * If the log level is still unset at this point, set it to
4377 * the program's default.
4379 if (*default_log_level
< 0) {
4380 *default_log_level
= cli_default_log_level
;
4384 poptFreeContext(pc
);
4391 g_string_free(cur_name
, TRUE
);
4394 if (cur_name_prefix
) {
4395 g_string_free(cur_name_prefix
, TRUE
);
4398 bt_value_put_ref(run_args
);
4399 bt_value_put_ref(all_names
);
4400 destroy_glist_of_gstring(source_names
);
4401 destroy_glist_of_gstring(filter_names
);
4402 destroy_glist_of_gstring(sink_names
);
4403 bt_value_put_ref(leftovers
);
4404 finalize_implicit_component_args(&implicit_ctf_input_args
);
4405 finalize_implicit_component_args(&implicit_ctf_output_args
);
4406 finalize_implicit_component_args(&implicit_lttng_live_args
);
4407 finalize_implicit_component_args(&implicit_dummy_args
);
4408 finalize_implicit_component_args(&implicit_text_args
);
4409 finalize_implicit_component_args(&implicit_debug_info_args
);
4410 finalize_implicit_component_args(&implicit_muxer_args
);
4411 finalize_implicit_component_args(&implicit_trimmer_args
);
4412 bt_value_put_ref(plugin_paths
);
4413 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4418 * Prints the Babeltrace 2.x general usage.
4421 void print_gen_usage(FILE *fp
)
4423 fprintf(fp
, "Usage: babeltrace2 [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4425 fprintf(fp
, "General options:\n");
4427 fprintf(fp
, " -d, --debug Enable debug mode (same as --log-level=V)\n");
4428 fprintf(fp
, " -h, --help Show this help and quit\n");
4429 fprintf(fp
, " -l, --log-level=LVL Set the default log level to LVL (`N`, `V`, `D`,\n");
4430 fprintf(fp
, " `I`, `W` (default), `E`, or `F`)\n");
4431 fprintf(fp
, " -v, --verbose Enable verbose mode (same as --log-level=I)\n");
4432 fprintf(fp
, " -V, --version Show version and quit\n");
4434 fprintf(fp
, "Available commands:\n");
4436 fprintf(fp
, " convert Convert and trim traces (default)\n");
4437 fprintf(fp
, " help Get help for a plugin or a component class\n");
4438 fprintf(fp
, " list-plugins List available plugins and their content\n");
4439 fprintf(fp
, " query Query objects from a component class\n");
4440 fprintf(fp
, " run Build a processing graph and run it\n");
4442 fprintf(fp
, "Use `babeltrace2 COMMAND --help` to show the help of COMMAND.\n");
4445 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4446 int *retcode
, bool force_omit_system_plugin_path
,
4447 bool force_omit_home_plugin_path
,
4448 const bt_value
*initial_plugin_paths
)
4450 struct bt_config
*config
= NULL
;
4452 const char **command_argv
= NULL
;
4453 int command_argc
= -1;
4454 const char *command_name
= NULL
;
4455 int default_log_level
= -1;
4458 COMMAND_TYPE_NONE
= -1,
4459 COMMAND_TYPE_RUN
= 0,
4460 COMMAND_TYPE_CONVERT
,
4461 COMMAND_TYPE_LIST_PLUGINS
,
4464 } command_type
= COMMAND_TYPE_NONE
;
4468 if (!initial_plugin_paths
) {
4469 initial_plugin_paths
= bt_value_array_create();
4470 if (!initial_plugin_paths
) {
4475 bt_value_get_ref(initial_plugin_paths
);
4481 print_gen_usage(stdout
);
4485 for (i
= 1; i
< argc
; i
++) {
4486 const char *cur_arg
= argv
[i
];
4487 const char *next_arg
= i
== (argc
- 1) ? NULL
: argv
[i
+ 1];
4489 if (strcmp(cur_arg
, "-d") == 0 ||
4490 strcmp(cur_arg
, "--debug") == 0) {
4491 default_log_level
= BT_LOG_TRACE
;
4492 } else if (strcmp(cur_arg
, "-v") == 0 ||
4493 strcmp(cur_arg
, "--verbose") == 0) {
4494 if (default_log_level
!= BT_LOG_TRACE
&&
4495 default_log_level
!= BT_LOG_DEBUG
) {
4497 * Legacy: do not override a previous
4498 * --debug because --verbose and --debug
4499 * can be specified together (in this
4500 * case we want the lowest log level to
4503 default_log_level
= BT_LOG_INFO
;
4505 } else if (strcmp(cur_arg
, "--log-level") == 0 ||
4506 strcmp(cur_arg
, "-l") == 0) {
4508 printf_err("Missing log level value for --log-level option\n");
4514 bt_log_get_level_from_string(next_arg
);
4515 if (default_log_level
< 0) {
4516 printf_err("Invalid argument for --log-level option:\n %s\n",
4523 } else if (strncmp(cur_arg
, "--log-level=", 12) == 0) {
4524 const char *arg
= &cur_arg
[12];
4526 default_log_level
= bt_log_get_level_from_string(arg
);
4527 if (default_log_level
< 0) {
4528 printf_err("Invalid argument for --log-level option:\n %s\n",
4533 } else if (strncmp(cur_arg
, "-l", 2) == 0) {
4534 const char *arg
= &cur_arg
[2];
4536 default_log_level
= bt_log_get_level_from_string(arg
);
4537 if (default_log_level
< 0) {
4538 printf_err("Invalid argument for --log-level option:\n %s\n",
4543 } else if (strcmp(cur_arg
, "-V") == 0 ||
4544 strcmp(cur_arg
, "--version") == 0) {
4547 } else if (strcmp(cur_arg
, "-h") == 0 ||
4548 strcmp(cur_arg
, "--help") == 0) {
4549 print_gen_usage(stdout
);
4553 * First unknown argument: is it a known command
4556 command_argv
= &argv
[i
];
4557 command_argc
= argc
- i
;
4559 if (strcmp(cur_arg
, "convert") == 0) {
4560 command_type
= COMMAND_TYPE_CONVERT
;
4561 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4562 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4563 } else if (strcmp(cur_arg
, "help") == 0) {
4564 command_type
= COMMAND_TYPE_HELP
;
4565 } else if (strcmp(cur_arg
, "query") == 0) {
4566 command_type
= COMMAND_TYPE_QUERY
;
4567 } else if (strcmp(cur_arg
, "run") == 0) {
4568 command_type
= COMMAND_TYPE_RUN
;
4571 * Unknown argument, but not a known
4572 * command name: assume the default
4573 * `convert` command.
4575 command_type
= COMMAND_TYPE_CONVERT
;
4576 command_name
= "convert";
4577 command_argv
= &argv
[i
- 1];
4578 command_argc
= argc
- i
+ 1;
4584 if (command_type
== COMMAND_TYPE_NONE
) {
4586 * We only got non-help, non-version general options
4587 * like --verbose and --debug, without any other
4588 * arguments, so we can't do anything useful: print the
4591 print_gen_usage(stdout
);
4595 BT_ASSERT(command_argv
);
4596 BT_ASSERT(command_argc
>= 0);
4599 * The convert command can set its own default log level for
4600 * backward compatibility reasons. It only does so if there's no
4601 * log level yet, so do not force one for this command.
4603 if (command_type
!= COMMAND_TYPE_CONVERT
&& default_log_level
< 0) {
4604 /* Default log level */
4605 default_log_level
= cli_default_log_level
;
4608 switch (command_type
) {
4609 case COMMAND_TYPE_RUN
:
4610 config
= bt_config_run_from_args(command_argc
, command_argv
,
4611 retcode
, force_omit_system_plugin_path
,
4612 force_omit_home_plugin_path
, initial_plugin_paths
,
4615 case COMMAND_TYPE_CONVERT
:
4616 config
= bt_config_convert_from_args(command_argc
, command_argv
,
4617 retcode
, force_omit_system_plugin_path
,
4618 force_omit_home_plugin_path
,
4619 initial_plugin_paths
, &default_log_level
);
4621 case COMMAND_TYPE_LIST_PLUGINS
:
4622 config
= bt_config_list_plugins_from_args(command_argc
,
4623 command_argv
, retcode
, force_omit_system_plugin_path
,
4624 force_omit_home_plugin_path
, initial_plugin_paths
);
4626 case COMMAND_TYPE_HELP
:
4627 config
= bt_config_help_from_args(command_argc
,
4628 command_argv
, retcode
, force_omit_system_plugin_path
,
4629 force_omit_home_plugin_path
, initial_plugin_paths
,
4632 case COMMAND_TYPE_QUERY
:
4633 config
= bt_config_query_from_args(command_argc
,
4634 command_argv
, retcode
, force_omit_system_plugin_path
,
4635 force_omit_home_plugin_path
, initial_plugin_paths
,
4643 BT_ASSERT(default_log_level
>= BT_LOG_TRACE
);
4644 config
->log_level
= default_log_level
;
4645 config
->command_name
= command_name
;
4649 bt_value_put_ref(initial_plugin_paths
);