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 <babeltrace/assert-internal.h>
35 #include <babeltrace/babeltrace.h>
36 #include <babeltrace/common-internal.h>
39 #include <sys/types.h>
40 #include "babeltrace-cfg.h"
41 #include "babeltrace-cfg-cli-args.h"
42 #include "babeltrace-cfg-cli-args-connect.h"
46 * Error printf() macro which prepends "Error: " the first time it's
47 * called. This gives a nicer feel than having a bunch of error prefixes
48 * (since the following lines usually describe the error and possible
49 * solutions), or the error prefix just at the end.
51 #define printf_err(fmt, args...) \
53 if (is_first_error) { \
54 fprintf(stderr, "Command line error: "); \
55 is_first_error = false; \
57 fprintf(stderr, fmt, ##args); \
60 static bool is_first_error
= true;
62 /* INI-style parsing FSM states */
63 enum ini_parsing_fsm_state
{
64 /* Expect a map key (identifier) */
67 /* Expect an equal character ('=') */
73 /* Expect a negative number value */
74 INI_EXPECT_VALUE_NUMBER_NEG
,
76 /* Expect a comma character (',') */
80 /* INI-style parsing state variables */
81 struct ini_parsing_state
{
82 /* Lexical scanner (owned by this) */
85 /* Output map value object being filled (owned by this) */
88 /* Next expected FSM state */
89 enum ini_parsing_fsm_state expecting
;
91 /* Last decoded map key (owned by this) */
94 /* Complete INI-style string to parse (not owned by this) */
97 /* Error buffer (not owned by this) */
101 /* Offset option with "is set" boolean */
107 /* Legacy "ctf"/"lttng-live" format options */
108 struct ctf_legacy_opts
{
109 struct offset_opt offset_s
;
110 struct offset_opt offset_ns
;
111 bool stream_intersection
;
114 /* Legacy "text" format options */
115 struct text_legacy_opts
{
117 * output, dbg_info_dir, dbg_info_target_prefix, names,
118 * and fields are owned by this.
121 GString
*dbg_info_dir
;
122 GString
*dbg_info_target_prefix
;
123 const bt_value
*names
;
124 const bt_value
*fields
;
132 bool dbg_info_full_path
;
136 /* Legacy input format format */
137 enum legacy_input_format
{
138 LEGACY_INPUT_FORMAT_NONE
= 0,
139 LEGACY_INPUT_FORMAT_CTF
,
140 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
143 /* Legacy output format format */
144 enum legacy_output_format
{
145 LEGACY_OUTPUT_FORMAT_NONE
= 0,
146 LEGACY_OUTPUT_FORMAT_TEXT
,
147 LEGACY_OUTPUT_FORMAT_DUMMY
,
151 * Prints the "out of memory" error.
154 void print_err_oom(void)
156 printf_err("Out of memory\n");
160 * Appends an "expecting token" error to the INI-style parsing state's
164 void ini_append_error_expecting(struct ini_parsing_state
*state
,
165 GScanner
*scanner
, const char *expecting
)
170 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
172 /* Only print error if there's one line */
173 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
177 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
178 pos
= g_scanner_cur_position(scanner
) + 4;
180 if (!g_scanner_eof(scanner
)) {
184 for (i
= 0; i
< pos
; ++i
) {
185 g_string_append_printf(state
->ini_error
, " ");
188 g_string_append_printf(state
->ini_error
, "^\n\n");
192 int ini_handle_state(struct ini_parsing_state
*state
)
195 GTokenType token_type
;
196 bt_value
*value
= NULL
;
198 token_type
= g_scanner_get_next_token(state
->scanner
);
199 if (token_type
== G_TOKEN_EOF
) {
200 if (state
->expecting
!= INI_EXPECT_COMMA
) {
201 switch (state
->expecting
) {
202 case INI_EXPECT_EQUAL
:
203 ini_append_error_expecting(state
,
204 state
->scanner
, "'='");
206 case INI_EXPECT_VALUE
:
207 case INI_EXPECT_VALUE_NUMBER_NEG
:
208 ini_append_error_expecting(state
,
209 state
->scanner
, "value");
211 case INI_EXPECT_MAP_KEY
:
212 ini_append_error_expecting(state
,
213 state
->scanner
, "unquoted map key");
226 switch (state
->expecting
) {
227 case INI_EXPECT_MAP_KEY
:
228 if (token_type
!= G_TOKEN_IDENTIFIER
) {
229 ini_append_error_expecting(state
, state
->scanner
,
234 free(state
->last_map_key
);
235 state
->last_map_key
=
236 strdup(state
->scanner
->value
.v_identifier
);
237 if (!state
->last_map_key
) {
238 g_string_append(state
->ini_error
,
243 if (bt_value_map_has_entry(state
->params
,
244 state
->last_map_key
)) {
245 g_string_append_printf(state
->ini_error
,
246 "Duplicate parameter key: `%s`\n",
247 state
->last_map_key
);
251 state
->expecting
= INI_EXPECT_EQUAL
;
253 case INI_EXPECT_EQUAL
:
254 if (token_type
!= G_TOKEN_CHAR
) {
255 ini_append_error_expecting(state
,
256 state
->scanner
, "'='");
260 if (state
->scanner
->value
.v_char
!= '=') {
261 ini_append_error_expecting(state
,
262 state
->scanner
, "'='");
266 state
->expecting
= INI_EXPECT_VALUE
;
268 case INI_EXPECT_VALUE
:
270 switch (token_type
) {
272 if (state
->scanner
->value
.v_char
== '-') {
273 /* Negative number */
275 INI_EXPECT_VALUE_NUMBER_NEG
;
278 ini_append_error_expecting(state
,
279 state
->scanner
, "value");
285 /* Positive integer */
286 uint64_t int_val
= state
->scanner
->value
.v_int64
;
288 if (int_val
> (1ULL << 63) - 1) {
289 g_string_append_printf(state
->ini_error
,
290 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
295 value
= bt_value_integer_create_init((int64_t)int_val
);
299 /* Positive floating point number */
300 value
= bt_value_real_create_init(state
->scanner
->value
.v_float
);
304 value
= bt_value_string_create_init(state
->scanner
->value
.v_string
);
306 case G_TOKEN_IDENTIFIER
:
309 * Using symbols would be appropriate here,
310 * but said symbols are allowed as map key,
311 * so it's easier to consider everything an
314 * If one of the known symbols is not
315 * recognized here, then fall back to creating
318 const char *id
= state
->scanner
->value
.v_identifier
;
320 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
321 !strcmp(id
, "nul")) {
322 value
= bt_value_null
;
323 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
324 !strcmp(id
, "yes") ||
325 !strcmp(id
, "YES")) {
326 value
= bt_value_bool_create_init(true);
327 } else if (!strcmp(id
, "false") ||
328 !strcmp(id
, "FALSE") ||
331 value
= bt_value_bool_create_init(false);
333 value
= bt_value_string_create_init(id
);
338 /* Unset value variable will trigger the error */
343 ini_append_error_expecting(state
,
344 state
->scanner
, "value");
348 state
->expecting
= INI_EXPECT_COMMA
;
351 case INI_EXPECT_VALUE_NUMBER_NEG
:
353 switch (token_type
) {
356 /* Negative integer */
357 uint64_t int_val
= state
->scanner
->value
.v_int64
;
359 if (int_val
> (1ULL << 63) - 1) {
360 g_string_append_printf(state
->ini_error
,
361 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
366 value
= bt_value_integer_create_init(-((int64_t)int_val
));
370 /* Negative floating point number */
371 value
= bt_value_real_create_init(-state
->scanner
->value
.v_float
);
374 /* Unset value variable will trigger the error */
379 ini_append_error_expecting(state
,
380 state
->scanner
, "value");
384 state
->expecting
= INI_EXPECT_COMMA
;
387 case INI_EXPECT_COMMA
:
388 if (token_type
!= G_TOKEN_CHAR
) {
389 ini_append_error_expecting(state
,
390 state
->scanner
, "','");
394 if (state
->scanner
->value
.v_char
!= ',') {
395 ini_append_error_expecting(state
,
396 state
->scanner
, "','");
400 state
->expecting
= INI_EXPECT_MAP_KEY
;
412 if (bt_value_map_insert_entry(state
->params
,
413 state
->last_map_key
, value
)) {
414 /* Only override return value on error */
420 BT_VALUE_PUT_REF_AND_RESET(value
);
425 * Converts an INI-style argument to an equivalent map value object.
427 * Return value is owned by the caller.
430 bt_value
*bt_value_from_ini(const char *arg
,
433 /* Lexical scanner configuration */
434 GScannerConfig scanner_config
= {
435 /* Skip whitespaces */
436 .cset_skip_characters
= " \t\n",
438 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
439 .cset_identifier_first
=
443 .cset_identifier_nth
=
448 /* "hello" and "Hello" two different keys */
449 .case_sensitive
= TRUE
,
452 .cpair_comment_single
= NULL
,
453 .skip_comment_multi
= TRUE
,
454 .skip_comment_single
= TRUE
,
455 .scan_comment_multi
= FALSE
,
458 * Do scan identifiers, including 1-char identifiers,
459 * but NULL is a normal identifier.
461 .scan_identifier
= TRUE
,
462 .scan_identifier_1char
= TRUE
,
463 .scan_identifier_NULL
= FALSE
,
466 * No specific symbols: null and boolean "symbols" are
467 * scanned as plain identifiers.
469 .scan_symbols
= FALSE
,
470 .symbol_2_token
= FALSE
,
471 .scope_0_fallback
= FALSE
,
474 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
475 * integers prefixed with "$".
481 .scan_hex_dollar
= FALSE
,
483 /* Convert scanned numbers to integer tokens */
484 .numbers_2_int
= TRUE
,
486 /* Support both integers and floating-point numbers */
487 .int_2_float
= FALSE
,
489 /* Scan integers as 64-bit signed integers */
492 /* Only scan double-quoted strings */
493 .scan_string_sq
= FALSE
,
494 .scan_string_dq
= TRUE
,
496 /* Do not converter identifiers to string tokens */
497 .identifier_2_string
= FALSE
,
499 /* Scan characters as G_TOKEN_CHAR token */
500 .char_2_token
= FALSE
,
502 struct ini_parsing_state state
= {
505 .expecting
= INI_EXPECT_MAP_KEY
,
507 .ini_error
= ini_error
,
510 state
.params
= bt_value_map_create();
515 state
.scanner
= g_scanner_new(&scanner_config
);
516 if (!state
.scanner
) {
520 /* Let the scan begin */
521 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
524 int ret
= ini_handle_state(&state
);
529 } else if (ret
> 0) {
538 BT_VALUE_PUT_REF_AND_RESET(state
.params
);
542 g_scanner_destroy(state
.scanner
);
545 free(state
.last_map_key
);
550 * Returns the parameters map value object from a command-line
551 * parameter option's argument.
553 * Return value is owned by the caller.
556 bt_value
*bt_value_from_arg(const char *arg
)
558 bt_value
*params
= NULL
;
559 GString
*ini_error
= NULL
;
561 ini_error
= g_string_new(NULL
);
567 /* Try INI-style parsing */
568 params
= bt_value_from_ini(arg
, ini_error
);
570 printf_err("%s", ini_error
->str
);
576 g_string_free(ini_error
, TRUE
);
583 * Returns the plugin name, component class name, component class type,
584 * and component name from a command-line --component option's argument.
585 * arg must have the following format:
587 * [NAME:]TYPE.PLUGIN.CLS
589 * where NAME is the optional component name, TYPE is either `source`,
590 * `filter`, or `sink`, PLUGIN is the plugin name, and CLS is the
591 * component class name.
593 * On success, both *plugin and *component are not NULL. *plugin
594 * and *comp_cls are owned by the caller. On success, *name can be NULL
595 * if no component class name was found, and *comp_cls_type is set.
598 void plugin_comp_cls_names(const char *arg
, char **name
, char **plugin
,
599 char **comp_cls
, bt_component_class_type
*comp_cls_type
)
601 const char *at
= arg
;
602 GString
*gs_name
= NULL
;
603 GString
*gs_comp_cls_type
= NULL
;
604 GString
*gs_plugin
= NULL
;
605 GString
*gs_comp_cls
= NULL
;
611 BT_ASSERT(comp_cls_type
);
613 if (!bt_common_string_is_printable(arg
)) {
614 printf_err("Argument contains a non-printable character\n");
618 /* Parse the component name */
619 gs_name
= bt_common_string_until(at
, ".:\\", ":", &end_pos
);
624 if (arg
[end_pos
] == ':') {
628 g_string_assign(gs_name
, "");
631 /* Parse the component class type */
632 gs_comp_cls_type
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
633 if (!gs_comp_cls_type
|| at
[end_pos
] == '\0') {
634 printf_err("Missing component class type (`source`, `filter`, or `sink`)\n");
638 if (strcmp(gs_comp_cls_type
->str
, "source") == 0 ||
639 strcmp(gs_comp_cls_type
->str
, "src") == 0) {
640 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
641 } else if (strcmp(gs_comp_cls_type
->str
, "filter") == 0 ||
642 strcmp(gs_comp_cls_type
->str
, "flt") == 0) {
643 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
644 } else if (strcmp(gs_comp_cls_type
->str
, "sink") == 0) {
645 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
647 printf_err("Unknown component class type: `%s`\n",
648 gs_comp_cls_type
->str
);
654 /* Parse the plugin name */
655 gs_plugin
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
656 if (!gs_plugin
|| gs_plugin
->len
== 0 || at
[end_pos
] == '\0') {
657 printf_err("Missing plugin or component class name\n");
663 /* Parse the component class name */
664 gs_comp_cls
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
665 if (!gs_comp_cls
|| gs_comp_cls
->len
== 0) {
666 printf_err("Missing component class name\n");
670 if (at
[end_pos
] != '\0') {
671 /* Found a non-escaped `.` */
676 if (gs_name
->len
== 0) {
678 g_string_free(gs_name
, TRUE
);
680 *name
= gs_name
->str
;
681 g_string_free(gs_name
, FALSE
);
684 g_string_free(gs_name
, TRUE
);
687 *plugin
= gs_plugin
->str
;
688 *comp_cls
= gs_comp_cls
->str
;
689 g_string_free(gs_plugin
, FALSE
);
690 g_string_free(gs_comp_cls
, FALSE
);
706 g_string_free(gs_name
, TRUE
);
710 g_string_free(gs_plugin
, TRUE
);
714 g_string_free(gs_comp_cls
, TRUE
);
717 if (gs_comp_cls_type
) {
718 g_string_free(gs_comp_cls_type
, TRUE
);
725 * Prints the Babeltrace version.
728 void print_version(void)
730 if (GIT_VERSION
[0] == '\0') {
731 puts("Babeltrace " VERSION
);
733 puts("Babeltrace " VERSION
" - " GIT_VERSION
);
738 * Destroys a component configuration.
741 void bt_config_component_destroy(bt_object
*obj
)
743 struct bt_config_component
*bt_config_component
=
744 container_of(obj
, struct bt_config_component
, base
);
750 if (bt_config_component
->plugin_name
) {
751 g_string_free(bt_config_component
->plugin_name
, TRUE
);
754 if (bt_config_component
->comp_cls_name
) {
755 g_string_free(bt_config_component
->comp_cls_name
, TRUE
);
758 if (bt_config_component
->instance_name
) {
759 g_string_free(bt_config_component
->instance_name
, TRUE
);
762 BT_VALUE_PUT_REF_AND_RESET(bt_config_component
->params
);
763 g_free(bt_config_component
);
770 * Creates a component configuration using the given plugin name and
771 * component name. `plugin_name` and `comp_cls_name` are copied (belong
772 * to the return value).
774 * Return value is owned by the caller.
777 struct bt_config_component
*bt_config_component_create(
778 bt_component_class_type type
,
779 const char *plugin_name
, const char *comp_cls_name
)
781 struct bt_config_component
*cfg_component
= NULL
;
783 cfg_component
= g_new0(struct bt_config_component
, 1);
784 if (!cfg_component
) {
789 bt_object_init_shared(&cfg_component
->base
,
790 bt_config_component_destroy
);
791 cfg_component
->type
= type
;
792 cfg_component
->plugin_name
= g_string_new(plugin_name
);
793 if (!cfg_component
->plugin_name
) {
798 cfg_component
->comp_cls_name
= g_string_new(comp_cls_name
);
799 if (!cfg_component
->comp_cls_name
) {
804 cfg_component
->instance_name
= g_string_new(NULL
);
805 if (!cfg_component
->instance_name
) {
810 /* Start with empty parameters */
811 cfg_component
->params
= bt_value_map_create();
812 if (!cfg_component
->params
) {
820 BT_OBJECT_PUT_REF_AND_RESET(cfg_component
);
823 return cfg_component
;
827 * Creates a component configuration from a command-line --component
831 struct bt_config_component
*bt_config_component_from_arg(const char *arg
)
833 struct bt_config_component
*cfg_comp
= NULL
;
835 char *plugin_name
= NULL
;
836 char *comp_cls_name
= NULL
;
837 bt_component_class_type type
;
839 plugin_comp_cls_names(arg
, &name
, &plugin_name
, &comp_cls_name
, &type
);
840 if (!plugin_name
|| !comp_cls_name
) {
844 cfg_comp
= bt_config_component_create(type
, plugin_name
, comp_cls_name
);
850 g_string_assign(cfg_comp
->instance_name
, name
);
856 BT_OBJECT_PUT_REF_AND_RESET(cfg_comp
);
861 g_free(comp_cls_name
);
866 * Destroys a configuration.
869 void bt_config_destroy(bt_object
*obj
)
871 struct bt_config
*cfg
=
872 container_of(obj
, struct bt_config
, base
);
878 BT_VALUE_PUT_REF_AND_RESET(cfg
->plugin_paths
);
880 switch (cfg
->command
) {
881 case BT_CONFIG_COMMAND_RUN
:
882 if (cfg
->cmd_data
.run
.sources
) {
883 g_ptr_array_free(cfg
->cmd_data
.run
.sources
, TRUE
);
886 if (cfg
->cmd_data
.run
.filters
) {
887 g_ptr_array_free(cfg
->cmd_data
.run
.filters
, TRUE
);
890 if (cfg
->cmd_data
.run
.sinks
) {
891 g_ptr_array_free(cfg
->cmd_data
.run
.sinks
, TRUE
);
894 if (cfg
->cmd_data
.run
.connections
) {
895 g_ptr_array_free(cfg
->cmd_data
.run
.connections
,
899 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
901 case BT_CONFIG_COMMAND_HELP
:
902 BT_OBJECT_PUT_REF_AND_RESET(cfg
->cmd_data
.help
.cfg_component
);
904 case BT_CONFIG_COMMAND_QUERY
:
905 BT_OBJECT_PUT_REF_AND_RESET(cfg
->cmd_data
.query
.cfg_component
);
907 if (cfg
->cmd_data
.query
.object
) {
908 g_string_free(cfg
->cmd_data
.query
.object
, TRUE
);
911 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
912 if (cfg
->cmd_data
.print_ctf_metadata
.path
) {
913 g_string_free(cfg
->cmd_data
.print_ctf_metadata
.path
,
916 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
920 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
921 if (cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
923 cfg
->cmd_data
.print_lttng_live_sessions
.url
,
926 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
941 void destroy_glist_of_gstring(GList
*list
)
949 for (at
= list
; at
!= NULL
; at
= g_list_next(at
)) {
950 g_string_free(at
->data
, TRUE
);
957 * Creates a simple lexical scanner for parsing comma-delimited names
960 * Return value is owned by the caller.
963 GScanner
*create_csv_identifiers_scanner(void)
966 GScannerConfig scanner_config
= {
967 .cset_skip_characters
= " \t\n",
968 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
969 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
970 .case_sensitive
= TRUE
,
971 .cpair_comment_single
= NULL
,
972 .skip_comment_multi
= TRUE
,
973 .skip_comment_single
= TRUE
,
974 .scan_comment_multi
= FALSE
,
975 .scan_identifier
= TRUE
,
976 .scan_identifier_1char
= TRUE
,
977 .scan_identifier_NULL
= FALSE
,
978 .scan_symbols
= FALSE
,
979 .symbol_2_token
= FALSE
,
980 .scope_0_fallback
= FALSE
,
981 .scan_binary
= FALSE
,
985 .scan_hex_dollar
= FALSE
,
986 .numbers_2_int
= FALSE
,
987 .int_2_float
= FALSE
,
988 .store_int64
= FALSE
,
989 .scan_string_sq
= FALSE
,
990 .scan_string_dq
= FALSE
,
991 .identifier_2_string
= FALSE
,
992 .char_2_token
= TRUE
,
995 scanner
= g_scanner_new(&scanner_config
);
1004 * Converts a comma-delimited list of known names (--names option) to
1005 * an array value object containing those names as string value objects.
1007 * Return value is owned by the caller.
1010 bt_value
*names_from_arg(const char *arg
)
1012 GScanner
*scanner
= NULL
;
1013 bt_value
*names
= NULL
;
1014 bool found_all
= false, found_none
= false, found_item
= false;
1016 names
= bt_value_array_create();
1022 scanner
= create_csv_identifiers_scanner();
1027 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1030 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1032 switch (token_type
) {
1033 case G_TOKEN_IDENTIFIER
:
1035 const char *identifier
= scanner
->value
.v_identifier
;
1037 if (!strcmp(identifier
, "payload") ||
1038 !strcmp(identifier
, "args") ||
1039 !strcmp(identifier
, "arg")) {
1041 if (bt_value_array_append_string_element(names
,
1045 } else if (!strcmp(identifier
, "context") ||
1046 !strcmp(identifier
, "ctx")) {
1048 if (bt_value_array_append_string_element(names
,
1052 } else if (!strcmp(identifier
, "scope") ||
1053 !strcmp(identifier
, "header")) {
1055 if (bt_value_array_append_string_element(names
,
1059 } else if (!strcmp(identifier
, "all")) {
1061 if (bt_value_array_append_string_element(names
,
1065 } else if (!strcmp(identifier
, "none")) {
1067 if (bt_value_array_append_string_element(names
,
1072 printf_err("Unknown name: `%s`\n",
1088 if (found_none
&& found_all
) {
1089 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1093 * Legacy behavior is to clear the defaults (show none) when at
1094 * least one item is specified.
1096 if (found_item
&& !found_none
&& !found_all
) {
1097 if (bt_value_array_append_string_element(names
, "none")) {
1102 g_scanner_destroy(scanner
);
1107 BT_VALUE_PUT_REF_AND_RESET(names
);
1109 g_scanner_destroy(scanner
);
1115 * Converts a comma-delimited list of known fields (--fields option) to
1116 * an array value object containing those fields as string
1119 * Return value is owned by the caller.
1122 bt_value
*fields_from_arg(const char *arg
)
1124 GScanner
*scanner
= NULL
;
1127 fields
= bt_value_array_create();
1133 scanner
= create_csv_identifiers_scanner();
1138 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1141 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1143 switch (token_type
) {
1144 case G_TOKEN_IDENTIFIER
:
1146 const char *identifier
= scanner
->value
.v_identifier
;
1148 if (!strcmp(identifier
, "trace") ||
1149 !strcmp(identifier
, "trace:hostname") ||
1150 !strcmp(identifier
, "trace:domain") ||
1151 !strcmp(identifier
, "trace:procname") ||
1152 !strcmp(identifier
, "trace:vpid") ||
1153 !strcmp(identifier
, "loglevel") ||
1154 !strcmp(identifier
, "emf") ||
1155 !strcmp(identifier
, "callsite") ||
1156 !strcmp(identifier
, "all")) {
1157 if (bt_value_array_append_string_element(fields
,
1162 printf_err("Unknown field: `%s`\n",
1180 BT_VALUE_PUT_REF_AND_RESET(fields
);
1184 g_scanner_destroy(scanner
);
1190 void append_param_arg(GString
*params_arg
, const char *key
, const char *value
)
1192 BT_ASSERT(params_arg
);
1196 if (params_arg
->len
!= 0) {
1197 g_string_append_c(params_arg
, ',');
1200 g_string_append(params_arg
, key
);
1201 g_string_append_c(params_arg
, '=');
1202 g_string_append(params_arg
, value
);
1206 * Inserts the equivalent "prefix-NAME=yes" strings into params_arg
1207 * where the names are in names_array.
1210 int insert_flat_params_from_array(GString
*params_arg
,
1211 const bt_value
*names_array
, const char *prefix
)
1215 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1216 bool default_set
= false, non_default_set
= false;
1219 * names_array may be NULL if no CLI options were specified to
1220 * trigger its creation.
1226 tmpstr
= g_string_new(NULL
);
1233 default_value
= g_string_new(NULL
);
1234 if (!default_value
) {
1240 for (i
= 0; i
< bt_value_array_get_size(names_array
); i
++) {
1241 const bt_value
*str_obj
=
1242 bt_value_array_borrow_element_by_index_const(names_array
,
1245 bool is_default
= false;
1248 printf_err("Unexpected error\n");
1253 suffix
= bt_value_string_get(str_obj
);
1255 g_string_assign(tmpstr
, prefix
);
1256 g_string_append(tmpstr
, "-");
1258 /* Special-case for "all" and "none". */
1259 if (!strcmp(suffix
, "all")) {
1261 g_string_assign(default_value
, "show");
1262 } else if (!strcmp(suffix
, "none")) {
1264 g_string_assign(default_value
, "hide");
1268 g_string_append(tmpstr
, "default");
1269 append_param_arg(params_arg
, tmpstr
->str
,
1270 default_value
->str
);
1272 non_default_set
= true;
1273 g_string_append(tmpstr
, suffix
);
1274 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1278 /* Implicit field-default=hide if any non-default option is set. */
1279 if (non_default_set
&& !default_set
) {
1280 g_string_assign(tmpstr
, prefix
);
1281 g_string_append(tmpstr
, "-default");
1282 g_string_assign(default_value
, "hide");
1283 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1287 if (default_value
) {
1288 g_string_free(default_value
, TRUE
);
1292 g_string_free(tmpstr
, TRUE
);
1305 OPT_CLOCK_FORCE_CORRELATE
,
1308 OPT_CLOCK_OFFSET_NS
,
1316 OPT_DEBUG_INFO_FULL_PATH
,
1317 OPT_DEBUG_INFO_TARGET_PREFIX
,
1327 OPT_OMIT_HOME_PLUGIN_PATH
,
1328 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1334 OPT_RESET_BASE_PARAMS
,
1338 OPT_STREAM_INTERSECTION
,
1345 enum bt_config_component_dest
{
1346 BT_CONFIG_COMPONENT_DEST_UNKNOWN
= -1,
1347 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1348 BT_CONFIG_COMPONENT_DEST_FILTER
,
1349 BT_CONFIG_COMPONENT_DEST_SINK
,
1353 * Adds a configuration component to the appropriate configuration
1354 * array depending on the destination.
1357 void add_run_cfg_comp(struct bt_config
*cfg
,
1358 struct bt_config_component
*cfg_comp
,
1359 enum bt_config_component_dest dest
)
1361 bt_object_get_ref(cfg_comp
);
1364 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1365 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1367 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1368 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1370 case BT_CONFIG_COMPONENT_DEST_SINK
:
1371 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1379 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1380 struct bt_config_component
*cfg_comp
,
1381 enum bt_config_component_dest dest
,
1382 bt_value
*instance_names
)
1386 if (cfg_comp
->instance_name
->len
== 0) {
1387 printf_err("Found an unnamed component\n");
1392 if (bt_value_map_has_entry(instance_names
,
1393 cfg_comp
->instance_name
->str
)) {
1394 printf_err("Duplicate component instance name:\n %s\n",
1395 cfg_comp
->instance_name
->str
);
1400 if (bt_value_map_insert_entry(instance_names
,
1401 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1407 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1414 int append_env_var_plugin_paths(bt_value
*plugin_paths
)
1419 if (bt_common_is_setuid_setgid()) {
1420 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1424 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1429 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1433 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1440 int append_home_and_system_plugin_paths(bt_value
*plugin_paths
,
1441 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1445 if (!omit_home_plugin_path
) {
1446 if (bt_common_is_setuid_setgid()) {
1447 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1449 char *home_plugin_dir
=
1450 bt_common_get_home_plugin_path();
1452 if (home_plugin_dir
) {
1453 ret
= bt_config_append_plugin_paths(
1454 plugin_paths
, home_plugin_dir
);
1455 free(home_plugin_dir
);
1458 printf_err("Invalid home plugin path\n");
1465 if (!omit_system_plugin_path
) {
1466 if (bt_config_append_plugin_paths(plugin_paths
,
1467 bt_common_get_system_plugin_path())) {
1468 printf_err("Invalid system plugin path\n");
1474 printf_err("Cannot append home and system plugin paths\n");
1479 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1481 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1482 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1486 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1487 const bt_value
*initial_plugin_paths
,
1490 struct bt_config
*cfg
;
1493 cfg
= g_new0(struct bt_config
, 1);
1499 bt_object_init_shared(&cfg
->base
, bt_config_destroy
);
1500 cfg
->command
= command
;
1501 cfg
->command_needs_plugins
= needs_plugins
;
1503 if (initial_plugin_paths
) {
1504 bt_value
*initial_plugin_paths_copy
;
1506 (void) bt_value_copy(initial_plugin_paths
,
1507 &initial_plugin_paths_copy
);
1508 cfg
->plugin_paths
= initial_plugin_paths_copy
;
1510 cfg
->plugin_paths
= bt_value_array_create();
1511 if (!cfg
->plugin_paths
) {
1520 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1527 struct bt_config
*bt_config_run_create(
1528 const bt_value
*initial_plugin_paths
)
1530 struct bt_config
*cfg
;
1533 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1534 initial_plugin_paths
, true);
1539 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1540 (GDestroyNotify
) bt_object_put_ref
);
1541 if (!cfg
->cmd_data
.run
.sources
) {
1546 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1547 (GDestroyNotify
) bt_object_put_ref
);
1548 if (!cfg
->cmd_data
.run
.filters
) {
1553 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1554 (GDestroyNotify
) bt_object_put_ref
);
1555 if (!cfg
->cmd_data
.run
.sinks
) {
1560 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1561 (GDestroyNotify
) bt_config_connection_destroy
);
1562 if (!cfg
->cmd_data
.run
.connections
) {
1570 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1577 struct bt_config
*bt_config_list_plugins_create(
1578 const bt_value
*initial_plugin_paths
)
1580 struct bt_config
*cfg
;
1583 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1584 initial_plugin_paths
, true);
1592 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1599 struct bt_config
*bt_config_help_create(
1600 const bt_value
*initial_plugin_paths
)
1602 struct bt_config
*cfg
;
1605 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1606 initial_plugin_paths
, true);
1611 cfg
->cmd_data
.help
.cfg_component
=
1612 bt_config_component_create(-1, NULL
, NULL
);
1613 if (!cfg
->cmd_data
.help
.cfg_component
) {
1620 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1627 struct bt_config
*bt_config_query_create(
1628 const bt_value
*initial_plugin_paths
)
1630 struct bt_config
*cfg
;
1633 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1634 initial_plugin_paths
, true);
1639 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1640 if (!cfg
->cmd_data
.query
.object
) {
1648 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1655 struct bt_config
*bt_config_print_ctf_metadata_create(
1656 const bt_value
*initial_plugin_paths
)
1658 struct bt_config
*cfg
;
1661 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1662 initial_plugin_paths
, true);
1667 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1668 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1673 cfg
->cmd_data
.print_ctf_metadata
.output_path
= g_string_new(NULL
);
1674 if (!cfg
->cmd_data
.print_ctf_metadata
.output_path
) {
1682 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1689 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1690 const bt_value
*initial_plugin_paths
)
1692 struct bt_config
*cfg
;
1695 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1696 initial_plugin_paths
, true);
1701 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1702 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1707 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
=
1709 if (!cfg
->cmd_data
.print_lttng_live_sessions
.output_path
) {
1717 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1724 int bt_config_append_plugin_paths_check_setuid_setgid(
1725 bt_value
*plugin_paths
, const char *arg
)
1729 if (bt_common_is_setuid_setgid()) {
1730 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1734 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1735 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1746 * Prints the expected format for a --params option.
1749 void print_expected_params_format(FILE *fp
)
1751 fprintf(fp
, "Expected format of PARAMS\n");
1752 fprintf(fp
, "-------------------------\n");
1754 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1756 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1757 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1758 fprintf(fp
, "and VALUE can be one of:\n");
1760 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1761 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1762 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1763 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1764 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1765 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1766 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1767 fprintf(fp
, " the null and boolean value symbols above.\n");
1768 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1770 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1772 fprintf(fp
, "Example:\n");
1774 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1775 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1776 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1778 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1779 fprintf(fp
, "babeltrace from a shell.\n");
1784 * Prints the help command usage.
1787 void print_help_usage(FILE *fp
)
1789 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1790 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] TYPE.PLUGIN.CLS\n");
1792 fprintf(fp
, "Options:\n");
1794 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1795 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1796 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1797 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1798 fprintf(fp
, " dynamic plugins can be loaded\n");
1799 fprintf(fp
, " -h, --help Show this help and quit\n");
1801 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1803 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1807 struct poptOption help_long_options
[] = {
1808 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1809 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1810 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1811 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1812 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1813 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1817 * Creates a Babeltrace config object from the arguments of a help
1820 * *retcode is set to the appropriate exit code to use.
1823 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1824 int *retcode
, bool force_omit_system_plugin_path
,
1825 bool force_omit_home_plugin_path
,
1826 const bt_value
*initial_plugin_paths
)
1828 poptContext pc
= NULL
;
1832 struct bt_config
*cfg
= NULL
;
1833 const char *leftover
;
1834 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1837 cfg
= bt_config_help_create(initial_plugin_paths
);
1842 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1843 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1844 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1850 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1851 help_long_options
, 0);
1853 printf_err("Cannot get popt context\n");
1857 poptReadDefaultConfig(pc
, 0);
1859 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1860 arg
= poptGetOptArg(pc
);
1863 case OPT_PLUGIN_PATH
:
1864 if (bt_config_append_plugin_paths_check_setuid_setgid(
1865 cfg
->plugin_paths
, arg
)) {
1869 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1870 cfg
->omit_system_plugin_path
= true;
1872 case OPT_OMIT_HOME_PLUGIN_PATH
:
1873 cfg
->omit_home_plugin_path
= true;
1876 print_help_usage(stdout
);
1878 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1881 printf_err("Unknown command-line option specified (option code %d)\n",
1890 /* Check for option parsing error */
1892 printf_err("While parsing command-line options, at option %s: %s\n",
1893 poptBadOption(pc
, 0), poptStrerror(opt
));
1897 leftover
= poptGetArg(pc
);
1899 plugin_comp_cls_names(leftover
, NULL
,
1900 &plugin_name
, &comp_cls_name
,
1901 &cfg
->cmd_data
.help
.cfg_component
->type
);
1902 if (plugin_name
&& comp_cls_name
) {
1903 /* Component class help */
1905 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1908 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1911 /* Fall back to plugin help */
1913 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1917 print_help_usage(stdout
);
1919 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1923 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1931 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1934 g_free(plugin_name
);
1935 g_free(comp_cls_name
);
1938 poptFreeContext(pc
);
1946 * Prints the help command usage.
1949 void print_query_usage(FILE *fp
)
1951 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] TYPE.PLUGIN.CLS OBJECT\n");
1953 fprintf(fp
, "Options:\n");
1955 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1956 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1957 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1958 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1959 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1960 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1961 fprintf(fp
, " dynamic plugins can be loaded\n");
1962 fprintf(fp
, " -h, --help Show this help and quit\n");
1963 fprintf(fp
, "\n\n");
1964 print_expected_params_format(fp
);
1968 struct poptOption query_long_options
[] = {
1969 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1970 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1971 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1972 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1973 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1974 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1975 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1979 * Creates a Babeltrace config object from the arguments of a query
1982 * *retcode is set to the appropriate exit code to use.
1985 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1986 int *retcode
, bool force_omit_system_plugin_path
,
1987 bool force_omit_home_plugin_path
,
1988 const bt_value
*initial_plugin_paths
)
1990 poptContext pc
= NULL
;
1994 struct bt_config
*cfg
= NULL
;
1995 const char *leftover
;
1996 bt_value
*params
= bt_value_null
;
1999 cfg
= bt_config_query_create(initial_plugin_paths
);
2004 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2005 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2006 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2012 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2013 query_long_options
, 0);
2015 printf_err("Cannot get popt context\n");
2019 poptReadDefaultConfig(pc
, 0);
2021 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2022 arg
= poptGetOptArg(pc
);
2025 case OPT_PLUGIN_PATH
:
2026 if (bt_config_append_plugin_paths_check_setuid_setgid(
2027 cfg
->plugin_paths
, arg
)) {
2031 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2032 cfg
->omit_system_plugin_path
= true;
2034 case OPT_OMIT_HOME_PLUGIN_PATH
:
2035 cfg
->omit_home_plugin_path
= true;
2039 bt_value_put_ref(params
);
2040 params
= bt_value_from_arg(arg
);
2042 printf_err("Invalid format for --params option's argument:\n %s\n",
2049 print_query_usage(stdout
);
2051 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2054 printf_err("Unknown command-line option specified (option code %d)\n",
2063 /* Check for option parsing error */
2065 printf_err("While parsing command-line options, at option %s: %s\n",
2066 poptBadOption(pc
, 0), poptStrerror(opt
));
2071 * We need exactly two leftover arguments which are the
2072 * mandatory component class specification and query object.
2074 leftover
= poptGetArg(pc
);
2076 cfg
->cmd_data
.query
.cfg_component
=
2077 bt_config_component_from_arg(leftover
);
2078 if (!cfg
->cmd_data
.query
.cfg_component
) {
2079 printf_err("Invalid format for component class specification:\n %s\n",
2085 BT_OBJECT_MOVE_REF(cfg
->cmd_data
.query
.cfg_component
->params
,
2088 print_query_usage(stdout
);
2090 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2094 leftover
= poptGetArg(pc
);
2096 if (strlen(leftover
) == 0) {
2097 printf_err("Invalid empty object\n");
2101 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2103 print_query_usage(stdout
);
2105 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2109 leftover
= poptGetArg(pc
);
2111 printf_err("Unexpected argument: %s\n", leftover
);
2115 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2123 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2127 poptFreeContext(pc
);
2130 bt_value_put_ref(params
);
2136 * Prints the list-plugins command usage.
2139 void print_list_plugins_usage(FILE *fp
)
2141 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2143 fprintf(fp
, "Options:\n");
2145 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2146 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2147 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2148 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2149 fprintf(fp
, " dynamic plugins can be loaded\n");
2150 fprintf(fp
, " -h, --help Show this help and quit\n");
2152 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2154 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2158 struct poptOption list_plugins_long_options
[] = {
2159 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2160 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2161 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2162 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2163 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2164 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2168 * Creates a Babeltrace config object from the arguments of a
2169 * list-plugins command.
2171 * *retcode is set to the appropriate exit code to use.
2174 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2175 int *retcode
, bool force_omit_system_plugin_path
,
2176 bool force_omit_home_plugin_path
,
2177 const bt_value
*initial_plugin_paths
)
2179 poptContext pc
= NULL
;
2183 struct bt_config
*cfg
= NULL
;
2184 const char *leftover
;
2187 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2192 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2193 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2194 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2200 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2201 list_plugins_long_options
, 0);
2203 printf_err("Cannot get popt context\n");
2207 poptReadDefaultConfig(pc
, 0);
2209 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2210 arg
= poptGetOptArg(pc
);
2213 case OPT_PLUGIN_PATH
:
2214 if (bt_config_append_plugin_paths_check_setuid_setgid(
2215 cfg
->plugin_paths
, arg
)) {
2219 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2220 cfg
->omit_system_plugin_path
= true;
2222 case OPT_OMIT_HOME_PLUGIN_PATH
:
2223 cfg
->omit_home_plugin_path
= true;
2226 print_list_plugins_usage(stdout
);
2228 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2231 printf_err("Unknown command-line option specified (option code %d)\n",
2240 /* Check for option parsing error */
2242 printf_err("While parsing command-line options, at option %s: %s\n",
2243 poptBadOption(pc
, 0), poptStrerror(opt
));
2247 leftover
= poptGetArg(pc
);
2249 printf_err("Unexpected argument: %s\n", leftover
);
2253 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2261 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2265 poptFreeContext(pc
);
2273 * Prints the run command usage.
2276 void print_run_usage(FILE *fp
)
2278 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2280 fprintf(fp
, "Options:\n");
2282 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2283 fprintf(fp
, " for all the following components until\n");
2284 fprintf(fp
, " --reset-base-params is encountered\n");
2285 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2286 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2287 fprintf(fp
, " Instantiate the component class CLS of type\n");
2288 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2289 fprintf(fp
, " in the plugin PLUGIN, add it to the graph,\n");
2290 fprintf(fp
, " and optionally name it NAME (you can also\n");
2291 fprintf(fp
, " specify the name with --name)\n");
2292 fprintf(fp
, " -x, --connect=CONNECTION Connect two created components (see the\n");
2293 fprintf(fp
, " expected format of CONNECTION below)\n");
2294 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2295 fprintf(fp
, " parameter key to KEY (see --value)\n");
2296 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2297 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2298 fprintf(fp
, " names of the created components)\n");
2299 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2300 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2301 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2302 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2303 fprintf(fp
, " current component (see the expected format\n");
2304 fprintf(fp
, " of PARAMS below)\n");
2305 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2306 fprintf(fp
, " dynamic plugins can be loaded\n");
2307 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2308 fprintf(fp
, " empty map\n");
2309 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2310 fprintf(fp
, " the graph later, retry in DUR µs\n");
2311 fprintf(fp
, " (default: 100000)\n");
2312 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2313 fprintf(fp
, " the current component with a name given by\n");
2314 fprintf(fp
, " the last argument of the --key option and a\n");
2315 fprintf(fp
, " value set to VAL\n");
2316 fprintf(fp
, " -h, --help Show this help and quit\n");
2318 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2319 fprintf(fp
, "\n\n");
2320 fprintf(fp
, "Expected format of CONNECTION\n");
2321 fprintf(fp
, "-----------------------------\n");
2323 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2325 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2326 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2327 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2328 fprintf(fp
, "component with the --name option.\n");
2330 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2331 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2332 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2334 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2335 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2336 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2337 fprintf(fp
, "DOWNSTREAM.\n");
2339 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2340 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2341 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2343 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2344 fprintf(fp
, "can connect a filter component to a sink component.\n");
2346 fprintf(fp
, "Examples:\n");
2348 fprintf(fp
, " my-src:my-sink\n");
2349 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2351 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2352 fprintf(fp
, "babeltrace from a shell.\n");
2353 fprintf(fp
, "\n\n");
2354 print_expected_params_format(fp
);
2358 * Creates a Babeltrace config object from the arguments of a run
2361 * *retcode is set to the appropriate exit code to use.
2364 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2365 int *retcode
, bool force_omit_system_plugin_path
,
2366 bool force_omit_home_plugin_path
,
2367 const bt_value
*initial_plugin_paths
)
2369 poptContext pc
= NULL
;
2371 struct bt_config_component
*cur_cfg_comp
= NULL
;
2372 enum bt_config_component_dest cur_cfg_comp_dest
=
2373 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
2374 bt_value
*cur_base_params
= NULL
;
2376 struct bt_config
*cfg
= NULL
;
2377 bt_value
*instance_names
= NULL
;
2378 bt_value
*connection_args
= NULL
;
2379 GString
*cur_param_key
= NULL
;
2380 char error_buf
[256] = { 0 };
2381 long retry_duration
= -1;
2382 bt_value_status status
;
2383 struct poptOption run_long_options
[] = {
2384 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2385 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2386 { "connect", 'x', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2387 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2388 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2389 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2390 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2391 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2392 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2393 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2394 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2395 { "retry-duration", '\0', POPT_ARG_LONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2396 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2397 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2401 cur_param_key
= g_string_new(NULL
);
2402 if (!cur_param_key
) {
2408 print_run_usage(stdout
);
2413 cfg
= bt_config_run_create(initial_plugin_paths
);
2418 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2419 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2420 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2421 cur_base_params
= bt_value_map_create();
2422 if (!cur_base_params
) {
2427 instance_names
= bt_value_map_create();
2428 if (!instance_names
) {
2433 connection_args
= bt_value_array_create();
2434 if (!connection_args
) {
2439 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2445 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2446 run_long_options
, 0);
2448 printf_err("Cannot get popt context\n");
2452 poptReadDefaultConfig(pc
, 0);
2454 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2455 arg
= poptGetOptArg(pc
);
2458 case OPT_PLUGIN_PATH
:
2459 if (bt_config_append_plugin_paths_check_setuid_setgid(
2460 cfg
->plugin_paths
, arg
)) {
2464 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2465 cfg
->omit_system_plugin_path
= true;
2467 case OPT_OMIT_HOME_PLUGIN_PATH
:
2468 cfg
->omit_home_plugin_path
= true;
2472 enum bt_config_component_dest new_dest
;
2475 ret
= add_run_cfg_comp_check_name(cfg
,
2476 cur_cfg_comp
, cur_cfg_comp_dest
,
2478 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2484 cur_cfg_comp
= bt_config_component_from_arg(arg
);
2485 if (!cur_cfg_comp
) {
2486 printf_err("Invalid format for --component option's argument:\n %s\n",
2491 switch (cur_cfg_comp
->type
) {
2492 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
2493 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2495 case BT_COMPONENT_CLASS_TYPE_FILTER
:
2496 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2498 case BT_COMPONENT_CLASS_TYPE_SINK
:
2499 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2505 BT_ASSERT(cur_base_params
);
2506 bt_value_put_ref(cur_cfg_comp
->params
);
2507 status
= bt_value_copy(cur_base_params
,
2508 &cur_cfg_comp
->params
);
2509 if (status
!= BT_VALUE_STATUS_OK
) {
2514 cur_cfg_comp_dest
= new_dest
;
2520 bt_value
*params_to_set
;
2522 if (!cur_cfg_comp
) {
2523 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2528 params
= bt_value_from_arg(arg
);
2530 printf_err("Invalid format for --params option's argument:\n %s\n",
2535 status
= bt_value_map_extend(cur_cfg_comp
->params
,
2536 params
, ¶ms_to_set
);
2537 BT_VALUE_PUT_REF_AND_RESET(params
);
2538 if (status
!= BT_VALUE_STATUS_OK
) {
2539 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2544 BT_OBJECT_MOVE_REF(cur_cfg_comp
->params
, params_to_set
);
2548 if (strlen(arg
) == 0) {
2549 printf_err("Cannot set an empty string as the current parameter key\n");
2553 g_string_assign(cur_param_key
, arg
);
2556 if (!cur_cfg_comp
) {
2557 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2562 if (cur_param_key
->len
== 0) {
2563 printf_err("--value option specified without preceding --key option:\n %s\n",
2568 if (bt_value_map_insert_string_entry(cur_cfg_comp
->params
,
2569 cur_param_key
->str
, arg
)) {
2575 if (!cur_cfg_comp
) {
2576 printf_err("Cannot set the name of unavailable component:\n %s\n",
2581 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2583 case OPT_BASE_PARAMS
:
2586 bt_value_from_arg(arg
);
2589 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2594 BT_OBJECT_MOVE_REF(cur_base_params
, params
);
2597 case OPT_RESET_BASE_PARAMS
:
2598 BT_VALUE_PUT_REF_AND_RESET(cur_base_params
);
2599 cur_base_params
= bt_value_map_create();
2600 if (!cur_base_params
) {
2606 if (bt_value_array_append_string_element(
2607 connection_args
, arg
)) {
2612 case OPT_RETRY_DURATION
:
2613 if (retry_duration
< 0) {
2614 printf_err("--retry-duration option's argument must be positive or 0: %ld\n",
2619 cfg
->cmd_data
.run
.retry_duration_us
=
2620 (uint64_t) retry_duration
;
2623 print_run_usage(stdout
);
2625 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2628 printf_err("Unknown command-line option specified (option code %d)\n",
2637 /* Check for option parsing error */
2639 printf_err("While parsing command-line options, at option %s: %s\n",
2640 poptBadOption(pc
, 0), poptStrerror(opt
));
2644 /* This command does not accept leftover arguments */
2645 if (poptPeekArg(pc
)) {
2646 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2650 /* Add current component */
2652 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2653 cur_cfg_comp_dest
, instance_names
);
2654 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2660 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2661 printf_err("Incomplete graph: no source component\n");
2665 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2666 printf_err("Incomplete graph: no sink component\n");
2670 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2674 ret
= bt_config_cli_args_create_connections(cfg
,
2678 printf_err("Cannot creation connections:\n%s", error_buf
);
2686 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2690 poptFreeContext(pc
);
2693 if (cur_param_key
) {
2694 g_string_free(cur_param_key
, TRUE
);
2698 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2699 BT_VALUE_PUT_REF_AND_RESET(cur_base_params
);
2700 BT_VALUE_PUT_REF_AND_RESET(instance_names
);
2701 BT_VALUE_PUT_REF_AND_RESET(connection_args
);
2706 struct bt_config
*bt_config_run_from_args_array(const bt_value
*run_args
,
2707 int *retcode
, bool force_omit_system_plugin_path
,
2708 bool force_omit_home_plugin_path
,
2709 const bt_value
*initial_plugin_paths
)
2711 struct bt_config
*cfg
= NULL
;
2714 const size_t argc
= bt_value_array_get_size(run_args
) + 1;
2716 argv
= calloc(argc
, sizeof(*argv
));
2724 len
= bt_value_array_get_size(run_args
);
2726 printf_err("Invalid executable arguments\n");
2729 for (i
= 0; i
< len
; i
++) {
2730 const bt_value
*arg_value
=
2731 bt_value_array_borrow_element_by_index_const(run_args
,
2735 BT_ASSERT(arg_value
);
2736 arg
= bt_value_string_get(arg_value
);
2741 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2742 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2743 initial_plugin_paths
);
2751 * Prints the convert command usage.
2754 void print_convert_usage(FILE *fp
)
2756 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2758 fprintf(fp
, "Options:\n");
2760 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2761 fprintf(fp
, " Instantiate the component class CLS of type\n");
2762 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2763 fprintf(fp
, " in the plugin PLUGIN, add it to the\n");
2764 fprintf(fp
, " conversion graph, and optionally name it\n");
2765 fprintf(fp
, " NAME (you can also specify the name with\n");
2766 fprintf(fp
, " --name)\n");
2767 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2768 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2769 fprintf(fp
, " names of the created components)\n");
2770 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2771 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2772 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2773 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2774 fprintf(fp
, " current component (see the expected format\n");
2775 fprintf(fp
, " of PARAMS below)\n");
2776 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2777 fprintf(fp
, " current component to PATH\n");
2778 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2779 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2780 fprintf(fp
, " the graph later, retry in DUR µs\n");
2781 fprintf(fp
, " (default: 100000)\n");
2782 fprintf(fp
, " dynamic plugins can be loaded\n");
2783 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2784 fprintf(fp
, " `run` command to the standard output,\n");
2785 fprintf(fp
, " formatted for a shell, and quit\n");
2786 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2787 fprintf(fp
, " `run` command to the standard output,\n");
2788 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2789 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2790 fprintf(fp
, " are active\n");
2791 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2792 fprintf(fp
, " current component to URL\n");
2793 fprintf(fp
, " -h, --help Show this help and quit\n");
2795 fprintf(fp
, "Implicit `source.ctf.fs` component options:\n");
2797 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2798 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2800 fprintf(fp
, "Implicit `sink.text.pretty` component options:\n");
2802 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2803 fprintf(fp
, " --clock-date Print timestamp dates\n");
2804 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2805 fprintf(fp
, " time zone instead of the local time zone\n");
2806 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2807 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2808 fprintf(fp
, " --color=(never | auto | always)\n");
2809 fprintf(fp
, " Never, automatically, or always emit\n");
2810 fprintf(fp
, " console color codes\n");
2811 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2812 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2813 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2814 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2815 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2816 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2817 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2818 fprintf(fp
, " (or `ctx`)\n");
2819 fprintf(fp
, " --no-delta Do not print time delta between\n");
2820 fprintf(fp
, " consecutive events\n");
2821 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2822 fprintf(fp
, " the standard output\n");
2824 fprintf(fp
, "Implicit `filter.utils.muxer` component options:\n");
2826 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2827 fprintf(fp
, " correlated across traces\n");
2829 fprintf(fp
, "Implicit `filter.utils.trimmer` component options:\n");
2831 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2832 fprintf(fp
, " time range to BEGIN (see the format of\n");
2833 fprintf(fp
, " BEGIN below)\n");
2834 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2835 fprintf(fp
, " range to END (see the format of END below)\n");
2836 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2837 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2838 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2840 fprintf(fp
, "Implicit `filter.lttng-utils.debug-info` component options:\n");
2842 fprintf(fp
, " --debug-info Create an implicit\n");
2843 fprintf(fp
, " `filter.lttng-utils.debug-info` component\n");
2844 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2845 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2846 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2847 fprintf(fp
, " binary paths instead of just names\n");
2848 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2849 fprintf(fp
, " Use directory DIR as a prefix when\n");
2850 fprintf(fp
, " looking up executables during debug\n");
2851 fprintf(fp
, " info analysis\n");
2853 fprintf(fp
, "Legacy options that still work:\n");
2855 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2856 fprintf(fp
, " `ctf`:\n");
2857 fprintf(fp
, " Create an implicit `source.ctf.fs`\n");
2858 fprintf(fp
, " component\n");
2859 fprintf(fp
, " `lttng-live`:\n");
2860 fprintf(fp
, " Create an implicit `source.ctf.lttng-live`\n");
2861 fprintf(fp
, " component\n");
2862 fprintf(fp
, " -o, --output-format=(text | ctf | dummy | ctf-metadata)\n");
2863 fprintf(fp
, " `text`:\n");
2864 fprintf(fp
, " Create an implicit `sink.text.pretty`\n");
2865 fprintf(fp
, " component\n");
2866 fprintf(fp
, " `ctf`:\n");
2867 fprintf(fp
, " Create an implicit `sink.ctf.fs`\n");
2868 fprintf(fp
, " component\n");
2869 fprintf(fp
, " `dummy`:\n");
2870 fprintf(fp
, " Create an implicit `sink.utils.dummy`\n");
2871 fprintf(fp
, " component\n");
2872 fprintf(fp
, " `ctf-metadata`:\n");
2873 fprintf(fp
, " Query the `source.ctf.fs` component class\n");
2874 fprintf(fp
, " for metadata text and quit\n");
2876 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2877 fprintf(fp
, "\n\n");
2878 fprintf(fp
, "Format of BEGIN and END\n");
2879 fprintf(fp
, "-----------------------\n");
2881 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2882 fprintf(fp
, "\n\n");
2883 print_expected_params_format(fp
);
2887 struct poptOption convert_long_options
[] = {
2888 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2889 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2890 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2891 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2892 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2893 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2894 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2895 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2896 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2897 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2898 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2899 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2900 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2901 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2902 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2903 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2904 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2905 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2906 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2907 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2908 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2909 { "debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO
, NULL
, NULL
},
2910 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2911 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2912 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2913 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2914 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2915 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2916 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2917 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2918 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2919 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2920 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2921 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2922 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2923 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2924 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2925 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2929 GString
*get_component_auto_name(const char *prefix
,
2930 const bt_value
*existing_names
)
2933 GString
*auto_name
= g_string_new(NULL
);
2940 if (!bt_value_map_has_entry(existing_names
, prefix
)) {
2941 g_string_assign(auto_name
, prefix
);
2946 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2948 } while (bt_value_map_has_entry(existing_names
, auto_name
->str
));
2954 struct implicit_component_args
{
2958 GString
*params_arg
;
2959 bt_value
*extra_params
;
2963 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
2964 const char *prefix
, bt_value
*existing_names
,
2965 GList
**comp_names
, bool append_to_comp_names
)
2968 GString
*name
= NULL
;
2970 if (!args
->exists
) {
2974 name
= get_component_auto_name(prefix
,
2982 g_string_assign(args
->name_arg
, name
->str
);
2984 if (bt_value_map_insert_entry(existing_names
, name
->str
,
2991 if (append_to_comp_names
) {
2992 *comp_names
= g_list_append(*comp_names
, name
);
2998 g_string_free(name
, TRUE
);
3005 int append_run_args_for_implicit_component(
3006 struct implicit_component_args
*impl_args
,
3012 if (!impl_args
->exists
) {
3016 if (bt_value_array_append_string_element(run_args
, "--component")) {
3021 if (bt_value_array_append_string_element(run_args
, impl_args
->comp_arg
->str
)) {
3026 if (bt_value_array_append_string_element(run_args
, "--name")) {
3031 if (bt_value_array_append_string_element(run_args
, impl_args
->name_arg
->str
)) {
3036 if (impl_args
->params_arg
->len
> 0) {
3037 if (bt_value_array_append_string_element(run_args
, "--params")) {
3042 if (bt_value_array_append_string_element(run_args
,
3043 impl_args
->params_arg
->str
)) {
3049 for (i
= 0; i
< bt_value_array_get_size(impl_args
->extra_params
);
3051 const bt_value
*elem
;
3054 elem
= bt_value_array_borrow_element_by_index(impl_args
->extra_params
,
3060 BT_ASSERT(bt_value_is_string(elem
));
3061 arg
= bt_value_string_get(elem
);
3062 ret
= bt_value_array_append_string_element(run_args
, arg
);
3079 void finalize_implicit_component_args(struct implicit_component_args
*args
)
3083 if (args
->comp_arg
) {
3084 g_string_free(args
->comp_arg
, TRUE
);
3087 if (args
->name_arg
) {
3088 g_string_free(args
->name_arg
, TRUE
);
3091 if (args
->params_arg
) {
3092 g_string_free(args
->params_arg
, TRUE
);
3095 bt_value_put_ref(args
->extra_params
);
3099 void destroy_implicit_component_args(void *args
)
3105 finalize_implicit_component_args(args
);
3110 int init_implicit_component_args(struct implicit_component_args
*args
,
3111 const char *comp_arg
, bool exists
)
3115 args
->exists
= exists
;
3116 args
->comp_arg
= g_string_new(comp_arg
);
3117 args
->name_arg
= g_string_new(NULL
);
3118 args
->params_arg
= g_string_new(NULL
);
3119 args
->extra_params
= bt_value_array_create();
3121 if (!args
->comp_arg
|| !args
->name_arg
||
3122 !args
->params_arg
|| !args
->extra_params
) {
3124 finalize_implicit_component_args(args
);
3134 void append_implicit_component_param(struct implicit_component_args
*args
,
3135 const char *key
, const char *value
)
3140 append_param_arg(args
->params_arg
, key
, value
);
3144 int append_implicit_component_extra_param(struct implicit_component_args
*args
,
3145 const char *key
, const char *value
)
3153 if (bt_value_array_append_string_element(args
->extra_params
, "--key")) {
3159 if (bt_value_array_append_string_element(args
->extra_params
, key
)) {
3165 if (bt_value_array_append_string_element(args
->extra_params
, "--value")) {
3171 if (bt_value_array_append_string_element(args
->extra_params
, value
)) {
3182 int convert_append_name_param(enum bt_config_component_dest dest
,
3183 GString
*cur_name
, GString
*cur_name_prefix
,
3185 bt_value
*all_names
,
3186 GList
**source_names
, GList
**filter_names
,
3191 if (cur_name_prefix
->len
> 0) {
3192 /* We're after a --component option */
3193 GString
*name
= NULL
;
3194 bool append_name_opt
= false;
3196 if (cur_name
->len
== 0) {
3198 * No explicit name was provided for the user
3201 name
= get_component_auto_name(cur_name_prefix
->str
,
3203 append_name_opt
= true;
3206 * An explicit name was provided for the user
3209 if (bt_value_map_has_entry(all_names
,
3211 printf_err("Duplicate component instance name:\n %s\n",
3216 name
= g_string_new(cur_name
->str
);
3225 * Remember this name globally, for the uniqueness of
3226 * all component names.
3228 if (bt_value_map_insert_entry(all_names
, name
->str
, bt_value_null
)) {
3234 * Append the --name option if necessary.
3236 if (append_name_opt
) {
3237 if (bt_value_array_append_string_element(run_args
, "--name")) {
3242 if (bt_value_array_append_string_element(run_args
, name
->str
)) {
3249 * Remember this name specifically for the type of the
3250 * component. This is to create connection arguments.
3253 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3254 *source_names
= g_list_append(*source_names
, name
);
3256 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3257 *filter_names
= g_list_append(*filter_names
, name
);
3259 case BT_CONFIG_COMPONENT_DEST_SINK
:
3260 *sink_names
= g_list_append(*sink_names
, name
);
3266 g_string_assign(cur_name_prefix
, "");
3279 * Escapes `.`, `:`, and `\` of `input` with `\`.
3282 GString
*escape_dot_colon(const char *input
)
3284 GString
*output
= g_string_new(NULL
);
3292 for (ch
= input
; *ch
!= '\0'; ch
++) {
3293 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3294 g_string_append_c(output
, '\\');
3297 g_string_append_c(output
, *ch
);
3305 * Appends a --connect option to a list of arguments. `upstream_name`
3306 * and `downstream_name` are escaped with escape_dot_colon() in this
3310 int append_connect_arg(bt_value
*run_args
,
3311 const char *upstream_name
, const char *downstream_name
)
3314 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3315 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3316 GString
*arg
= g_string_new(NULL
);
3318 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3324 ret
= bt_value_array_append_string_element(run_args
, "--connect");
3331 g_string_append(arg
, e_upstream_name
->str
);
3332 g_string_append_c(arg
, ':');
3333 g_string_append(arg
, e_downstream_name
->str
);
3334 ret
= bt_value_array_append_string_element(run_args
, arg
->str
);
3343 g_string_free(arg
, TRUE
);
3346 if (e_upstream_name
) {
3347 g_string_free(e_upstream_name
, TRUE
);
3350 if (e_downstream_name
) {
3351 g_string_free(e_downstream_name
, TRUE
);
3358 * Appends the run command's --connect options for the convert command.
3361 int convert_auto_connect(bt_value
*run_args
,
3362 GList
*source_names
, GList
*filter_names
,
3366 GList
*source_at
= source_names
;
3367 GList
*filter_at
= filter_names
;
3369 GList
*sink_at
= sink_names
;
3371 BT_ASSERT(source_names
);
3372 BT_ASSERT(filter_names
);
3373 BT_ASSERT(sink_names
);
3375 /* Connect all sources to the first filter */
3376 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3377 GString
*source_name
= source_at
->data
;
3378 GString
*filter_name
= filter_at
->data
;
3380 ret
= append_connect_arg(run_args
, source_name
->str
,
3387 filter_prev
= filter_at
;
3388 filter_at
= g_list_next(filter_at
);
3390 /* Connect remaining filters */
3391 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3392 GString
*filter_name
= filter_at
->data
;
3393 GString
*filter_prev_name
= filter_prev
->data
;
3395 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3402 /* Connect last filter to all sinks */
3403 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3404 GString
*filter_name
= filter_prev
->data
;
3405 GString
*sink_name
= sink_at
->data
;
3407 ret
= append_connect_arg(run_args
, filter_name
->str
,
3424 int split_timerange(const char *arg
, char **begin
, char **end
)
3427 const char *ch
= arg
;
3429 GString
*g_begin
= NULL
;
3430 GString
*g_end
= NULL
;
3438 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3439 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3445 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3446 if (!g_end
|| g_end
->len
== 0) {
3452 *begin
= g_begin
->str
;
3454 g_string_free(g_begin
, FALSE
);
3455 g_string_free(g_end
, FALSE
);
3465 g_string_free(g_begin
, TRUE
);
3469 g_string_free(g_end
, TRUE
);
3476 int g_list_prepend_gstring(GList
**list
, const char *string
)
3479 GString
*gs
= g_string_new(string
);
3488 *list
= g_list_prepend(*list
, gs
);
3495 struct implicit_component_args
*create_implicit_component_args(void)
3497 struct implicit_component_args
*impl_args
=
3498 g_new0(struct implicit_component_args
, 1);
3504 if (init_implicit_component_args(impl_args
, NULL
, true)) {
3505 destroy_implicit_component_args(impl_args
);
3515 int fill_implicit_ctf_inputs_args(GPtrArray
*implicit_ctf_inputs_args
,
3516 struct implicit_component_args
*base_implicit_ctf_input_args
,
3521 bt_value_status status
;
3523 for (leftover
= leftovers
; leftover
!= NULL
;
3524 leftover
= g_list_next(leftover
)) {
3525 GString
*gs_leftover
= leftover
->data
;
3526 struct implicit_component_args
*impl_args
=
3527 create_implicit_component_args();
3534 impl_args
->exists
= true;
3535 g_string_assign(impl_args
->comp_arg
,
3536 base_implicit_ctf_input_args
->comp_arg
->str
);
3537 g_string_assign(impl_args
->params_arg
,
3538 base_implicit_ctf_input_args
->params_arg
->str
);
3541 * We need our own copy of the extra parameters because
3542 * this is where the unique path goes.
3544 BT_VALUE_PUT_REF_AND_RESET(impl_args
->extra_params
);
3545 status
= bt_value_copy(base_implicit_ctf_input_args
->extra_params
,
3546 &impl_args
->extra_params
);
3547 if (status
!= BT_VALUE_STATUS_OK
) {
3549 destroy_implicit_component_args(impl_args
);
3553 /* Append unique path parameter */
3554 ret
= append_implicit_component_extra_param(impl_args
,
3555 "path", gs_leftover
->str
);
3557 destroy_implicit_component_args(impl_args
);
3561 g_ptr_array_add(implicit_ctf_inputs_args
, impl_args
);
3574 * Creates a Babeltrace config object from the arguments of a convert
3577 * *retcode is set to the appropriate exit code to use.
3580 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3581 int *retcode
, bool force_omit_system_plugin_path
,
3582 bool force_omit_home_plugin_path
,
3583 const bt_value
*initial_plugin_paths
, char *log_level
)
3585 poptContext pc
= NULL
;
3587 enum bt_config_component_dest cur_comp_dest
=
3588 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3590 struct bt_config
*cfg
= NULL
;
3591 bool got_input_format_opt
= false;
3592 bool got_output_format_opt
= false;
3593 bool trimmer_has_begin
= false;
3594 bool trimmer_has_end
= false;
3595 bool stream_intersection_mode
= false;
3596 GString
*cur_name
= NULL
;
3597 GString
*cur_name_prefix
= NULL
;
3598 const char *leftover
= NULL
;
3599 bool print_run_args
= false;
3600 bool print_run_args_0
= false;
3601 bool print_ctf_metadata
= false;
3602 bt_value
*run_args
= NULL
;
3603 bt_value
*all_names
= NULL
;
3604 GList
*source_names
= NULL
;
3605 GList
*filter_names
= NULL
;
3606 GList
*sink_names
= NULL
;
3607 GList
*leftovers
= NULL
;
3608 GPtrArray
*implicit_ctf_inputs_args
= NULL
;
3609 struct implicit_component_args base_implicit_ctf_input_args
= { 0 };
3610 struct implicit_component_args implicit_ctf_output_args
= { 0 };
3611 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3612 struct implicit_component_args implicit_dummy_args
= { 0 };
3613 struct implicit_component_args implicit_text_args
= { 0 };
3614 struct implicit_component_args implicit_debug_info_args
= { 0 };
3615 struct implicit_component_args implicit_muxer_args
= { 0 };
3616 struct implicit_component_args implicit_trimmer_args
= { 0 };
3617 bt_value
*plugin_paths
;
3618 char error_buf
[256] = { 0 };
3620 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3621 char *output
= NULL
;
3623 (void) bt_value_copy(initial_plugin_paths
, &plugin_paths
);
3628 print_convert_usage(stdout
);
3633 if (init_implicit_component_args(&base_implicit_ctf_input_args
,
3634 "source.ctf.fs", false)) {
3638 if (init_implicit_component_args(&implicit_ctf_output_args
,
3639 "sink.ctf.fs", false)) {
3643 if (init_implicit_component_args(&implicit_lttng_live_args
,
3644 "source.ctf.lttng-live", false)) {
3648 if (init_implicit_component_args(&implicit_text_args
,
3649 "sink.text.pretty", false)) {
3653 if (init_implicit_component_args(&implicit_dummy_args
,
3654 "sink.utils.dummy", false)) {
3658 if (init_implicit_component_args(&implicit_debug_info_args
,
3659 "filter.lttng-utils.debug-info", false)) {
3663 if (init_implicit_component_args(&implicit_muxer_args
,
3664 "filter.utils.muxer", true)) {
3668 if (init_implicit_component_args(&implicit_trimmer_args
,
3669 "filter.utils.trimmer", false)) {
3673 implicit_ctf_inputs_args
= g_ptr_array_new_with_free_func(
3674 (GDestroyNotify
) destroy_implicit_component_args
);
3675 if (!implicit_ctf_inputs_args
) {
3680 all_names
= bt_value_map_create();
3686 run_args
= bt_value_array_create();
3692 cur_name
= g_string_new(NULL
);
3698 cur_name_prefix
= g_string_new(NULL
);
3699 if (!cur_name_prefix
) {
3704 ret
= append_env_var_plugin_paths(plugin_paths
);
3710 * First pass: collect all arguments which need to be passed
3711 * as is to the run command. This pass can also add --name
3712 * arguments if needed to automatically name unnamed component
3713 * instances. Also it does the following transformations:
3715 * --path=PATH -> --key path --value PATH
3716 * --url=URL -> --key url --value URL
3718 * Also it appends the plugin paths of --plugin-path to
3721 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3722 convert_long_options
, 0);
3724 printf_err("Cannot get popt context\n");
3728 poptReadDefaultConfig(pc
, 0);
3730 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3732 char *plugin_name
= NULL
;
3733 char *comp_cls_name
= NULL
;
3735 arg
= poptGetOptArg(pc
);
3740 bt_component_class_type type
;
3741 const char *type_prefix
;
3743 /* Append current component's name if needed */
3744 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3745 cur_name_prefix
, run_args
, all_names
,
3746 &source_names
, &filter_names
, &sink_names
);
3751 /* Parse the argument */
3752 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3753 &comp_cls_name
, &type
);
3754 if (!plugin_name
|| !comp_cls_name
) {
3755 printf_err("Invalid format for --component option's argument:\n %s\n",
3761 g_string_assign(cur_name
, name
);
3763 g_string_assign(cur_name
, "");
3767 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3768 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3769 type_prefix
= "source";
3771 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3772 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
3773 type_prefix
= "filter";
3775 case BT_COMPONENT_CLASS_TYPE_SINK
:
3776 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3777 type_prefix
= "sink";
3783 if (bt_value_array_append_string_element(run_args
,
3789 if (bt_value_array_append_string_element(run_args
, arg
)) {
3794 g_string_assign(cur_name_prefix
, "");
3795 g_string_append_printf(cur_name_prefix
, "%s.%s.%s",
3796 type_prefix
, plugin_name
, comp_cls_name
);
3799 free(comp_cls_name
);
3802 comp_cls_name
= NULL
;
3806 if (cur_name_prefix
->len
== 0) {
3807 printf_err("No current component of which to set parameters:\n %s\n",
3812 if (bt_value_array_append_string_element(run_args
,
3818 if (bt_value_array_append_string_element(run_args
, arg
)) {
3824 if (cur_name_prefix
->len
== 0) {
3825 printf_err("No current component of which to set `path` parameter:\n %s\n",
3830 if (bt_value_array_append_string_element(run_args
, "--key")) {
3835 if (bt_value_array_append_string_element(run_args
, "path")) {
3840 if (bt_value_array_append_string_element(run_args
, "--value")) {
3845 if (bt_value_array_append_string_element(run_args
, arg
)) {
3851 if (cur_name_prefix
->len
== 0) {
3852 printf_err("No current component of which to set `url` parameter:\n %s\n",
3857 if (bt_value_array_append_string_element(run_args
, "--key")) {
3862 if (bt_value_array_append_string_element(run_args
, "url")) {
3867 if (bt_value_array_append_string_element(run_args
, "--value")) {
3872 if (bt_value_array_append_string_element(run_args
, arg
)) {
3878 if (cur_name_prefix
->len
== 0) {
3879 printf_err("No current component to name:\n %s\n",
3884 if (bt_value_array_append_string_element(run_args
, "--name")) {
3889 if (bt_value_array_append_string_element(run_args
, arg
)) {
3894 g_string_assign(cur_name
, arg
);
3896 case OPT_OMIT_HOME_PLUGIN_PATH
:
3897 force_omit_home_plugin_path
= true;
3899 if (bt_value_array_append_string_element(run_args
,
3900 "--omit-home-plugin-path")) {
3905 case OPT_RETRY_DURATION
:
3906 if (bt_value_array_append_string_element(run_args
,
3907 "--retry-duration")) {
3912 if (bt_value_array_append_string_element(run_args
, arg
)) {
3917 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3918 force_omit_system_plugin_path
= true;
3920 if (bt_value_array_append_string_element(run_args
,
3921 "--omit-system-plugin-path")) {
3926 case OPT_PLUGIN_PATH
:
3927 if (bt_config_append_plugin_paths_check_setuid_setgid(
3928 plugin_paths
, arg
)) {
3932 if (bt_value_array_append_string_element(run_args
,
3938 if (bt_value_array_append_string_element(run_args
, arg
)) {
3944 print_convert_usage(stdout
);
3946 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
3949 case OPT_CLOCK_CYCLES
:
3950 case OPT_CLOCK_DATE
:
3951 case OPT_CLOCK_FORCE_CORRELATE
:
3953 case OPT_CLOCK_OFFSET
:
3954 case OPT_CLOCK_OFFSET_NS
:
3955 case OPT_CLOCK_SECONDS
:
3958 case OPT_DEBUG_INFO
:
3959 case OPT_DEBUG_INFO_DIR
:
3960 case OPT_DEBUG_INFO_FULL_PATH
:
3961 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3964 case OPT_INPUT_FORMAT
:
3967 case OPT_OUTPUT_FORMAT
:
3970 case OPT_RUN_ARGS_0
:
3971 case OPT_STREAM_INTERSECTION
:
3974 /* Ignore in this pass */
3977 printf_err("Unknown command-line option specified (option code %d)\n",
3986 /* Append current component's name if needed */
3987 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3988 cur_name_prefix
, run_args
, all_names
, &source_names
,
3989 &filter_names
, &sink_names
);
3994 /* Check for option parsing error */
3996 printf_err("While parsing command-line options, at option %s: %s\n",
3997 poptBadOption(pc
, 0), poptStrerror(opt
));
4001 poptFreeContext(pc
);
4006 * Second pass: transform the convert-specific options and
4007 * arguments into implicit component instances for the run
4010 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
4011 convert_long_options
, 0);
4013 printf_err("Cannot get popt context\n");
4017 poptReadDefaultConfig(pc
, 0);
4019 while ((opt
= poptGetNextOpt(pc
)) > 0) {
4020 arg
= poptGetOptArg(pc
);
4024 if (trimmer_has_begin
) {
4025 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4030 trimmer_has_begin
= true;
4031 ret
= append_implicit_component_extra_param(
4032 &implicit_trimmer_args
, "begin", arg
);
4033 implicit_trimmer_args
.exists
= true;
4039 if (trimmer_has_end
) {
4040 printf("At --end option: --end or --timerange option already specified\n %s\n",
4045 trimmer_has_end
= true;
4046 ret
= append_implicit_component_extra_param(
4047 &implicit_trimmer_args
, "end", arg
);
4048 implicit_trimmer_args
.exists
= true;
4058 if (trimmer_has_begin
|| trimmer_has_end
) {
4059 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4064 ret
= split_timerange(arg
, &begin
, &end
);
4066 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4071 ret
= append_implicit_component_extra_param(
4072 &implicit_trimmer_args
, "begin", begin
);
4073 ret
|= append_implicit_component_extra_param(
4074 &implicit_trimmer_args
, "end", end
);
4075 implicit_trimmer_args
.exists
= true;
4083 case OPT_CLOCK_CYCLES
:
4084 append_implicit_component_param(
4085 &implicit_text_args
, "clock-cycles", "yes");
4086 implicit_text_args
.exists
= true;
4088 case OPT_CLOCK_DATE
:
4089 append_implicit_component_param(
4090 &implicit_text_args
, "clock-date", "yes");
4091 implicit_text_args
.exists
= true;
4093 case OPT_CLOCK_FORCE_CORRELATE
:
4094 append_implicit_component_param(
4095 &implicit_muxer_args
,
4096 "assume-absolute-clock-classes", "yes");
4099 append_implicit_component_param(
4100 &implicit_text_args
, "clock-gmt", "yes");
4101 append_implicit_component_param(
4102 &implicit_trimmer_args
, "clock-gmt", "yes");
4103 implicit_text_args
.exists
= true;
4105 case OPT_CLOCK_OFFSET
:
4106 base_implicit_ctf_input_args
.exists
= true;
4107 append_implicit_component_param(
4108 &base_implicit_ctf_input_args
,
4109 "clock-class-offset-s", arg
);
4111 case OPT_CLOCK_OFFSET_NS
:
4112 base_implicit_ctf_input_args
.exists
= true;
4113 append_implicit_component_param(
4114 &base_implicit_ctf_input_args
,
4115 "clock-class-offset-ns", arg
);
4117 case OPT_CLOCK_SECONDS
:
4118 append_implicit_component_param(
4119 &implicit_text_args
, "clock-seconds", "yes");
4120 implicit_text_args
.exists
= true;
4123 implicit_text_args
.exists
= true;
4124 ret
= append_implicit_component_extra_param(
4125 &implicit_text_args
, "color", arg
);
4130 case OPT_DEBUG_INFO
:
4131 implicit_debug_info_args
.exists
= true;
4133 case OPT_DEBUG_INFO_DIR
:
4134 implicit_debug_info_args
.exists
= true;
4135 ret
= append_implicit_component_extra_param(
4136 &implicit_debug_info_args
, "debug-info-dir", arg
);
4141 case OPT_DEBUG_INFO_FULL_PATH
:
4142 implicit_debug_info_args
.exists
= true;
4143 append_implicit_component_param(
4144 &implicit_debug_info_args
, "full-path", "yes");
4146 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4147 implicit_debug_info_args
.exists
= true;
4148 ret
= append_implicit_component_extra_param(
4149 &implicit_debug_info_args
,
4150 "target-prefix", arg
);
4157 bt_value
*fields
= fields_from_arg(arg
);
4163 implicit_text_args
.exists
= true;
4164 ret
= insert_flat_params_from_array(
4165 implicit_text_args
.params_arg
,
4167 bt_value_put_ref(fields
);
4175 bt_value
*names
= names_from_arg(arg
);
4181 implicit_text_args
.exists
= true;
4182 ret
= insert_flat_params_from_array(
4183 implicit_text_args
.params_arg
,
4185 bt_value_put_ref(names
);
4192 append_implicit_component_param(
4193 &implicit_text_args
, "no-delta", "yes");
4194 implicit_text_args
.exists
= true;
4196 case OPT_INPUT_FORMAT
:
4197 if (got_input_format_opt
) {
4198 printf_err("Duplicate --input-format option\n");
4202 got_input_format_opt
= true;
4204 if (strcmp(arg
, "ctf") == 0) {
4205 base_implicit_ctf_input_args
.exists
= true;
4206 } else if (strcmp(arg
, "lttng-live") == 0) {
4207 implicit_lttng_live_args
.exists
= true;
4209 printf_err("Unknown legacy input format:\n %s\n",
4214 case OPT_OUTPUT_FORMAT
:
4215 if (got_output_format_opt
) {
4216 printf_err("Duplicate --output-format option\n");
4220 got_output_format_opt
= true;
4222 if (strcmp(arg
, "text") == 0) {
4223 implicit_text_args
.exists
= true;
4224 } else if (strcmp(arg
, "ctf") == 0) {
4225 implicit_ctf_output_args
.exists
= true;
4226 } else if (strcmp(arg
, "dummy") == 0) {
4227 implicit_dummy_args
.exists
= true;
4228 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4229 print_ctf_metadata
= true;
4231 printf_err("Unknown legacy output format:\n %s\n",
4238 printf_err("Duplicate --output option\n");
4242 output
= strdup(arg
);
4249 if (print_run_args_0
) {
4250 printf_err("Cannot specify --run-args and --run-args-0\n");
4254 print_run_args
= true;
4256 case OPT_RUN_ARGS_0
:
4257 if (print_run_args
) {
4258 printf_err("Cannot specify --run-args and --run-args-0\n");
4262 print_run_args_0
= true;
4264 case OPT_STREAM_INTERSECTION
:
4266 * Applies to all traces implementing the trace-info
4269 stream_intersection_mode
= true;
4272 if (*log_level
!= 'V' && *log_level
!= 'D') {
4285 /* Check for option parsing error */
4287 printf_err("While parsing command-line options, at option %s: %s\n",
4288 poptBadOption(pc
, 0), poptStrerror(opt
));
4293 * Legacy behaviour: --verbose used to make the `text` output
4294 * format print more information. --verbose is now equivalent to
4295 * the INFO log level, which is why we compare to 'I' here.
4297 if (*log_level
== 'I') {
4298 append_implicit_component_param(&implicit_text_args
,
4303 * Append home and system plugin paths now that we possibly got
4306 if (append_home_and_system_plugin_paths(plugin_paths
,
4307 force_omit_system_plugin_path
,
4308 force_omit_home_plugin_path
)) {
4312 /* Consume and keep leftover arguments */
4313 while ((leftover
= poptGetArg(pc
))) {
4314 GString
*gs_leftover
= g_string_new(leftover
);
4321 leftovers
= g_list_append(leftovers
, gs_leftover
);
4323 g_string_free(gs_leftover
, TRUE
);
4329 /* Print CTF metadata or print LTTng live sessions */
4330 if (print_ctf_metadata
) {
4331 GString
*gs_leftover
;
4333 if (g_list_length(leftovers
) == 0) {
4334 printf_err("--output-format=ctf-metadata specified without a path\n");
4338 if (g_list_length(leftovers
) > 1) {
4339 printf_err("Too many paths specified for --output-format=ctf-metadata\n");
4343 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4348 gs_leftover
= leftovers
->data
;
4349 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4354 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
4362 * If -o ctf was specified, make sure an output path (--output)
4363 * was also specified. --output does not imply -o ctf because
4364 * it's also used for the default, implicit -o text if -o ctf
4367 if (implicit_ctf_output_args
.exists
) {
4369 printf_err("--output-format=ctf specified without --output (trace output path)\n");
4374 * At this point we know that -o ctf AND --output were
4375 * specified. Make sure that no options were specified
4376 * which would imply -o text because --output would be
4377 * ambiguous in this case. For example, this is wrong:
4379 * babeltrace --names=all -o ctf --output=/tmp/path my-trace
4381 * because --names=all implies -o text, and --output
4382 * could apply to both the sink.text.pretty and
4383 * sink.ctf.fs implicit components.
4385 if (implicit_text_args
.exists
) {
4386 printf_err("Ambiguous --output option: --output-format=ctf specified but another option implies --output-format=text\n");
4392 * If -o dummy and -o ctf were not specified, and if there are
4393 * no explicit sink components, then use an implicit
4394 * `sink.text.pretty` component.
4396 if (!implicit_dummy_args
.exists
&& !implicit_ctf_output_args
.exists
&&
4398 implicit_text_args
.exists
= true;
4402 * Set implicit `sink.text.pretty` or `sink.ctf.fs` component's
4403 * `path` parameter if --output was specified.
4406 if (implicit_text_args
.exists
) {
4407 append_implicit_component_extra_param(&implicit_text_args
,
4409 } else if (implicit_ctf_output_args
.exists
) {
4410 append_implicit_component_extra_param(&implicit_ctf_output_args
,
4415 /* Decide where the leftover argument(s) go */
4416 if (g_list_length(leftovers
) > 0) {
4417 if (implicit_lttng_live_args
.exists
) {
4418 GString
*gs_leftover
;
4420 if (g_list_length(leftovers
) > 1) {
4421 printf_err("Too many URLs specified for --output-format=lttng-live\n");
4425 gs_leftover
= leftovers
->data
;
4426 lttng_live_url_parts
=
4427 bt_common_parse_lttng_live_url(gs_leftover
->str
,
4428 error_buf
, sizeof(error_buf
));
4429 if (!lttng_live_url_parts
.proto
) {
4430 printf_err("Invalid LTTng live URL format: %s\n",
4435 if (!lttng_live_url_parts
.session_name
) {
4436 /* Print LTTng live sessions */
4437 cfg
= bt_config_print_lttng_live_sessions_create(
4443 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4448 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
4455 ret
= append_implicit_component_extra_param(
4456 &implicit_lttng_live_args
, "url",
4463 * Append one implicit component argument set
4464 * for each leftover (souce.ctf.fs paths). Copy
4465 * the base implicit component arguments.
4466 * Note that they still have to be named later.
4468 ret
= fill_implicit_ctf_inputs_args(
4469 implicit_ctf_inputs_args
,
4470 &base_implicit_ctf_input_args
, leftovers
);
4478 * Ensure mutual exclusion between implicit `source.ctf.fs` and
4479 * `source.ctf.lttng-live` components.
4481 if (base_implicit_ctf_input_args
.exists
&&
4482 implicit_lttng_live_args
.exists
) {
4483 printf_err("Cannot create both implicit `%s` and `%s` components\n",
4484 base_implicit_ctf_input_args
.comp_arg
->str
,
4485 implicit_lttng_live_args
.comp_arg
->str
);
4490 * If the implicit `source.ctf.fs` or `source.ctf.lttng-live`
4491 * components exists, make sure there's at least one leftover
4492 * (which is the path or URL).
4494 if (base_implicit_ctf_input_args
.exists
&&
4495 g_list_length(leftovers
) == 0) {
4496 printf_err("Missing path for implicit `%s` component\n",
4497 base_implicit_ctf_input_args
.comp_arg
->str
);
4501 if (implicit_lttng_live_args
.exists
&& g_list_length(leftovers
) == 0) {
4502 printf_err("Missing URL for implicit `%s` component\n",
4503 implicit_lttng_live_args
.comp_arg
->str
);
4507 /* Assign names to implicit components */
4508 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4509 struct implicit_component_args
*impl_args
=
4510 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4512 ret
= assign_name_to_implicit_component(impl_args
,
4513 "source-ctf-fs", all_names
, &source_names
, true);
4519 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4520 "lttng-live", all_names
, &source_names
, true);
4525 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4526 "pretty", all_names
, &sink_names
, true);
4531 ret
= assign_name_to_implicit_component(&implicit_ctf_output_args
,
4532 "sink-ctf-fs", all_names
, &sink_names
, true);
4537 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4538 "dummy", all_names
, &sink_names
, true);
4543 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4544 "muxer", all_names
, NULL
, false);
4549 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4550 "trimmer", all_names
, NULL
, false);
4555 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4556 "debug-info", all_names
, NULL
, false);
4561 /* Make sure there's at least one source and one sink */
4562 if (!source_names
) {
4563 printf_err("No source component\n");
4568 printf_err("No sink component\n");
4573 * Prepend the muxer, the trimmer, and the debug info to the
4574 * filter chain so that we have:
4576 * sources -> muxer -> [trimmer] -> [debug info] ->
4577 * [user filters] -> sinks
4579 if (implicit_debug_info_args
.exists
) {
4580 if (g_list_prepend_gstring(&filter_names
,
4581 implicit_debug_info_args
.name_arg
->str
)) {
4586 if (implicit_trimmer_args
.exists
) {
4587 if (g_list_prepend_gstring(&filter_names
,
4588 implicit_trimmer_args
.name_arg
->str
)) {
4593 if (g_list_prepend_gstring(&filter_names
,
4594 implicit_muxer_args
.name_arg
->str
)) {
4599 * Append the equivalent run arguments for the implicit
4602 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4603 struct implicit_component_args
*impl_args
=
4604 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4606 ret
= append_run_args_for_implicit_component(impl_args
,
4613 ret
= append_run_args_for_implicit_component(&implicit_lttng_live_args
,
4619 ret
= append_run_args_for_implicit_component(&implicit_text_args
,
4625 ret
= append_run_args_for_implicit_component(&implicit_ctf_output_args
,
4631 ret
= append_run_args_for_implicit_component(&implicit_dummy_args
,
4637 ret
= append_run_args_for_implicit_component(&implicit_muxer_args
,
4643 ret
= append_run_args_for_implicit_component(&implicit_trimmer_args
,
4649 ret
= append_run_args_for_implicit_component(&implicit_debug_info_args
,
4655 /* Auto-connect components */
4656 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4659 printf_err("Cannot auto-connect components\n");
4664 * We have all the run command arguments now. Depending on
4665 * --run-args, we pass this to the run command or print them
4668 if (print_run_args
|| print_run_args_0
) {
4669 if (stream_intersection_mode
) {
4670 printf_err("Cannot specify --stream-intersection with --run-args or --run-args-0\n");
4674 for (i
= 0; i
< bt_value_array_get_size(run_args
); i
++) {
4675 const bt_value
*arg_value
=
4676 bt_value_array_borrow_element_by_index(run_args
,
4679 GString
*quoted
= NULL
;
4680 const char *arg_to_print
;
4682 BT_ASSERT(arg_value
);
4683 arg
= bt_value_string_get(arg_value
);
4685 if (print_run_args
) {
4686 quoted
= bt_common_shell_quote(arg
, true);
4691 arg_to_print
= quoted
->str
;
4696 printf("%s", arg_to_print
);
4699 g_string_free(quoted
, TRUE
);
4702 if (i
< bt_value_array_get_size(run_args
) - 1) {
4703 if (print_run_args
) {
4712 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4716 cfg
= bt_config_run_from_args_array(run_args
, retcode
,
4717 force_omit_system_plugin_path
,
4718 force_omit_home_plugin_path
,
4719 initial_plugin_paths
);
4724 cfg
->cmd_data
.run
.stream_intersection_mode
= stream_intersection_mode
;
4729 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4733 poptFreeContext(pc
);
4740 g_string_free(cur_name
, TRUE
);
4743 if (cur_name_prefix
) {
4744 g_string_free(cur_name_prefix
, TRUE
);
4747 if (implicit_ctf_inputs_args
) {
4748 g_ptr_array_free(implicit_ctf_inputs_args
, TRUE
);
4751 bt_value_put_ref(run_args
);
4752 bt_value_put_ref(all_names
);
4753 destroy_glist_of_gstring(source_names
);
4754 destroy_glist_of_gstring(filter_names
);
4755 destroy_glist_of_gstring(sink_names
);
4756 destroy_glist_of_gstring(leftovers
);
4757 finalize_implicit_component_args(&base_implicit_ctf_input_args
);
4758 finalize_implicit_component_args(&implicit_ctf_output_args
);
4759 finalize_implicit_component_args(&implicit_lttng_live_args
);
4760 finalize_implicit_component_args(&implicit_dummy_args
);
4761 finalize_implicit_component_args(&implicit_text_args
);
4762 finalize_implicit_component_args(&implicit_debug_info_args
);
4763 finalize_implicit_component_args(&implicit_muxer_args
);
4764 finalize_implicit_component_args(&implicit_trimmer_args
);
4765 bt_value_put_ref(plugin_paths
);
4766 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4771 * Prints the Babeltrace 2.x general usage.
4774 void print_gen_usage(FILE *fp
)
4776 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4778 fprintf(fp
, "General options:\n");
4780 fprintf(fp
, " -d, --debug Enable debug mode (same as --log-level=V)\n");
4781 fprintf(fp
, " -h, --help Show this help and quit\n");
4782 fprintf(fp
, " -l, --log-level=LVL Set all log levels to LVL (`N`, `V`, `D`,\n");
4783 fprintf(fp
, " `I`, `W` (default), `E`, or `F`)\n");
4784 fprintf(fp
, " -v, --verbose Enable verbose mode (same as --log-level=I)\n");
4785 fprintf(fp
, " -V, --version Show version and quit\n");
4787 fprintf(fp
, "Available commands:\n");
4789 fprintf(fp
, " convert Convert and trim traces (default)\n");
4790 fprintf(fp
, " help Get help for a plugin or a component class\n");
4791 fprintf(fp
, " list-plugins List available plugins and their content\n");
4792 fprintf(fp
, " query Query objects from a component class\n");
4793 fprintf(fp
, " run Build a processing graph and run it\n");
4795 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4799 char log_level_from_arg(const char *arg
)
4803 if (strcmp(arg
, "VERBOSE") == 0 ||
4804 strcmp(arg
, "V") == 0) {
4806 } else if (strcmp(arg
, "DEBUG") == 0 ||
4807 strcmp(arg
, "D") == 0) {
4809 } else if (strcmp(arg
, "INFO") == 0 ||
4810 strcmp(arg
, "I") == 0) {
4812 } else if (strcmp(arg
, "WARN") == 0 ||
4813 strcmp(arg
, "WARNING") == 0 ||
4814 strcmp(arg
, "W") == 0) {
4816 } else if (strcmp(arg
, "ERROR") == 0 ||
4817 strcmp(arg
, "E") == 0) {
4819 } else if (strcmp(arg
, "FATAL") == 0 ||
4820 strcmp(arg
, "F") == 0) {
4822 } else if (strcmp(arg
, "NONE") == 0 ||
4823 strcmp(arg
, "N") == 0) {
4830 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4831 int *retcode
, bool force_omit_system_plugin_path
,
4832 bool force_omit_home_plugin_path
,
4833 const bt_value
*initial_plugin_paths
)
4835 struct bt_config
*config
= NULL
;
4837 const char **command_argv
= NULL
;
4838 int command_argc
= -1;
4839 const char *command_name
= NULL
;
4840 char log_level
= 'U';
4843 COMMAND_TYPE_NONE
= -1,
4844 COMMAND_TYPE_RUN
= 0,
4845 COMMAND_TYPE_CONVERT
,
4846 COMMAND_TYPE_LIST_PLUGINS
,
4849 } command_type
= COMMAND_TYPE_NONE
;
4853 if (!initial_plugin_paths
) {
4854 initial_plugin_paths
= bt_value_array_create();
4855 if (!initial_plugin_paths
) {
4860 bt_value_get_ref(initial_plugin_paths
);
4866 print_gen_usage(stdout
);
4870 for (i
= 1; i
< argc
; i
++) {
4871 const char *cur_arg
= argv
[i
];
4872 const char *next_arg
= i
== (argc
- 1) ? NULL
: argv
[i
+ 1];
4874 if (strcmp(cur_arg
, "-d") == 0 ||
4875 strcmp(cur_arg
, "--debug") == 0) {
4877 } else if (strcmp(cur_arg
, "-v") == 0 ||
4878 strcmp(cur_arg
, "--verbose") == 0) {
4879 if (log_level
!= 'V' && log_level
!= 'D') {
4881 * Legacy: do not override a previous
4882 * --debug because --verbose and --debug
4883 * can be specified together (in this
4884 * case we want the lowest log level to
4889 } else if (strcmp(cur_arg
, "--log-level") == 0 ||
4890 strcmp(cur_arg
, "-l") == 0) {
4892 printf_err("Missing log level value for --log-level option\n");
4897 log_level
= log_level_from_arg(next_arg
);
4898 if (log_level
== 'U') {
4899 printf_err("Invalid argument for --log-level option:\n %s\n",
4906 } else if (strncmp(cur_arg
, "--log-level=", 12) == 0) {
4907 const char *arg
= &cur_arg
[12];
4909 log_level
= log_level_from_arg(arg
);
4910 if (log_level
== 'U') {
4911 printf_err("Invalid argument for --log-level option:\n %s\n",
4916 } else if (strncmp(cur_arg
, "-l", 2) == 0) {
4917 const char *arg
= &cur_arg
[2];
4919 log_level
= log_level_from_arg(arg
);
4920 if (log_level
== 'U') {
4921 printf_err("Invalid argument for --log-level option:\n %s\n",
4926 } else if (strcmp(cur_arg
, "-V") == 0 ||
4927 strcmp(cur_arg
, "--version") == 0) {
4930 } else if (strcmp(cur_arg
, "-h") == 0 ||
4931 strcmp(cur_arg
, "--help") == 0) {
4932 print_gen_usage(stdout
);
4936 * First unknown argument: is it a known command
4939 command_argv
= &argv
[i
];
4940 command_argc
= argc
- i
;
4942 if (strcmp(cur_arg
, "convert") == 0) {
4943 command_type
= COMMAND_TYPE_CONVERT
;
4944 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4945 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4946 } else if (strcmp(cur_arg
, "help") == 0) {
4947 command_type
= COMMAND_TYPE_HELP
;
4948 } else if (strcmp(cur_arg
, "query") == 0) {
4949 command_type
= COMMAND_TYPE_QUERY
;
4950 } else if (strcmp(cur_arg
, "run") == 0) {
4951 command_type
= COMMAND_TYPE_RUN
;
4954 * Unknown argument, but not a known
4955 * command name: assume the default
4956 * `convert` command.
4958 command_type
= COMMAND_TYPE_CONVERT
;
4959 command_name
= "convert";
4960 command_argv
= &argv
[i
- 1];
4961 command_argc
= argc
- i
+ 1;
4967 if (command_type
== COMMAND_TYPE_NONE
) {
4969 * We only got non-help, non-version general options
4970 * like --verbose and --debug, without any other
4971 * arguments, so we can't do anything useful: print the
4974 print_gen_usage(stdout
);
4978 BT_ASSERT(command_argv
);
4979 BT_ASSERT(command_argc
>= 0);
4981 switch (command_type
) {
4982 case COMMAND_TYPE_RUN
:
4983 config
= bt_config_run_from_args(command_argc
, command_argv
,
4984 retcode
, force_omit_system_plugin_path
,
4985 force_omit_home_plugin_path
, initial_plugin_paths
);
4987 case COMMAND_TYPE_CONVERT
:
4988 config
= bt_config_convert_from_args(command_argc
, command_argv
,
4989 retcode
, force_omit_system_plugin_path
,
4990 force_omit_home_plugin_path
,
4991 initial_plugin_paths
, &log_level
);
4993 case COMMAND_TYPE_LIST_PLUGINS
:
4994 config
= bt_config_list_plugins_from_args(command_argc
,
4995 command_argv
, retcode
, force_omit_system_plugin_path
,
4996 force_omit_home_plugin_path
, initial_plugin_paths
);
4998 case COMMAND_TYPE_HELP
:
4999 config
= bt_config_help_from_args(command_argc
,
5000 command_argv
, retcode
, force_omit_system_plugin_path
,
5001 force_omit_home_plugin_path
, initial_plugin_paths
);
5003 case COMMAND_TYPE_QUERY
:
5004 config
= bt_config_query_from_args(command_argc
,
5005 command_argv
, retcode
, force_omit_system_plugin_path
,
5006 force_omit_home_plugin_path
, initial_plugin_paths
);
5013 if (log_level
== 'U') {
5017 config
->log_level
= log_level
;
5018 config
->command_name
= command_name
;
5022 bt_value_put_ref(initial_plugin_paths
);