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 comma character (',') */
77 /* INI-style parsing state variables */
78 struct ini_parsing_state
{
79 /* Lexical scanner (owned by this) */
82 /* Output map value object being filled (owned by this) */
85 /* Next expected FSM state */
86 enum ini_parsing_fsm_state expecting
;
88 /* Last decoded map key (owned by this) */
91 /* Complete INI-style string to parse (not owned by this) */
94 /* Error buffer (not owned by this) */
98 /* Offset option with "is set" boolean */
104 /* Legacy "ctf"/"lttng-live" format options */
105 struct ctf_legacy_opts
{
106 struct offset_opt offset_s
;
107 struct offset_opt offset_ns
;
108 bool stream_intersection
;
111 /* Legacy "text" format options */
112 struct text_legacy_opts
{
114 * output, dbg_info_dir, dbg_info_target_prefix, names,
115 * and fields are owned by this.
118 GString
*dbg_info_dir
;
119 GString
*dbg_info_target_prefix
;
120 const bt_value
*names
;
121 const bt_value
*fields
;
129 bool dbg_info_full_path
;
133 /* Legacy input format format */
134 enum legacy_input_format
{
135 LEGACY_INPUT_FORMAT_NONE
= 0,
136 LEGACY_INPUT_FORMAT_CTF
,
137 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
140 /* Legacy output format format */
141 enum legacy_output_format
{
142 LEGACY_OUTPUT_FORMAT_NONE
= 0,
143 LEGACY_OUTPUT_FORMAT_TEXT
,
144 LEGACY_OUTPUT_FORMAT_DUMMY
,
148 * Prints the "out of memory" error.
151 void print_err_oom(void)
153 printf_err("Out of memory\n");
157 * Appends an "expecting token" error to the INI-style parsing state's
161 void ini_append_error_expecting(struct ini_parsing_state
*state
,
162 GScanner
*scanner
, const char *expecting
)
167 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
169 /* Only print error if there's one line */
170 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
174 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
175 pos
= g_scanner_cur_position(scanner
) + 4;
177 if (!g_scanner_eof(scanner
)) {
181 for (i
= 0; i
< pos
; ++i
) {
182 g_string_append_printf(state
->ini_error
, " ");
185 g_string_append_printf(state
->ini_error
, "^\n\n");
188 /* Parse the next token as a number and return its negation. */
190 bt_value
*ini_parse_neg_number(struct ini_parsing_state
*state
)
192 bt_value
*value
= NULL
;
193 GTokenType token_type
= g_scanner_get_next_token(state
->scanner
);
195 switch (token_type
) {
198 /* Negative integer */
199 uint64_t int_val
= state
->scanner
->value
.v_int64
;
201 if (int_val
> (1ULL << 63) - 1) {
202 g_string_append_printf(state
->ini_error
,
203 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
206 value
= bt_value_integer_create_init(-((int64_t) int_val
));
212 /* Negative floating point number */
213 value
= bt_value_real_create_init(-state
->scanner
->value
.v_float
);
216 ini_append_error_expecting(state
, state
->scanner
, "value");
224 * Parse the current token (and the following ones if needed) as a value, return
228 bt_value
*ini_parse_value(struct ini_parsing_state
*state
)
230 bt_value
*value
= NULL
;
231 GTokenType token_type
= state
->scanner
->token
;
233 switch (token_type
) {
235 if (state
->scanner
->value
.v_char
== '-') {
236 /* Negative number */
237 value
= ini_parse_neg_number(state
);
239 ini_append_error_expecting(state
, state
->scanner
, "value");
244 /* Positive integer */
245 uint64_t int_val
= state
->scanner
->value
.v_int64
;
247 if (int_val
> (1ULL << 63) - 1) {
248 g_string_append_printf(state
->ini_error
,
249 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
252 value
= bt_value_integer_create_init((int64_t)int_val
);
257 /* Positive floating point number */
258 value
= bt_value_real_create_init(state
->scanner
->value
.v_float
);
262 value
= bt_value_string_create_init(state
->scanner
->value
.v_string
);
264 case G_TOKEN_IDENTIFIER
:
267 * Using symbols would be appropriate here,
268 * but said symbols are allowed as map key,
269 * so it's easier to consider everything an
272 * If one of the known symbols is not
273 * recognized here, then fall back to creating
276 const char *id
= state
->scanner
->value
.v_identifier
;
278 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
279 !strcmp(id
, "nul")) {
280 value
= bt_value_null
;
281 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
282 !strcmp(id
, "yes") ||
283 !strcmp(id
, "YES")) {
284 value
= bt_value_bool_create_init(true);
285 } else if (!strcmp(id
, "false") ||
286 !strcmp(id
, "FALSE") ||
289 value
= bt_value_bool_create_init(false);
291 value
= bt_value_string_create_init(id
);
296 /* Unset value variable will trigger the error */
297 ini_append_error_expecting(state
, state
->scanner
, "value");
305 int ini_handle_state(struct ini_parsing_state
*state
)
308 GTokenType token_type
;
309 bt_value
*value
= NULL
;
311 token_type
= g_scanner_get_next_token(state
->scanner
);
312 if (token_type
== G_TOKEN_EOF
) {
313 if (state
->expecting
!= INI_EXPECT_COMMA
) {
314 switch (state
->expecting
) {
315 case INI_EXPECT_EQUAL
:
316 ini_append_error_expecting(state
,
317 state
->scanner
, "'='");
319 case INI_EXPECT_VALUE
:
320 ini_append_error_expecting(state
,
321 state
->scanner
, "value");
323 case INI_EXPECT_MAP_KEY
:
324 ini_append_error_expecting(state
,
325 state
->scanner
, "unquoted map key");
338 switch (state
->expecting
) {
339 case INI_EXPECT_MAP_KEY
:
340 if (token_type
!= G_TOKEN_IDENTIFIER
) {
341 ini_append_error_expecting(state
, state
->scanner
,
346 free(state
->last_map_key
);
347 state
->last_map_key
=
348 strdup(state
->scanner
->value
.v_identifier
);
349 if (!state
->last_map_key
) {
350 g_string_append(state
->ini_error
,
355 if (bt_value_map_has_entry(state
->params
,
356 state
->last_map_key
)) {
357 g_string_append_printf(state
->ini_error
,
358 "Duplicate parameter key: `%s`\n",
359 state
->last_map_key
);
363 state
->expecting
= INI_EXPECT_EQUAL
;
365 case INI_EXPECT_EQUAL
:
366 if (token_type
!= G_TOKEN_CHAR
) {
367 ini_append_error_expecting(state
,
368 state
->scanner
, "'='");
372 if (state
->scanner
->value
.v_char
!= '=') {
373 ini_append_error_expecting(state
,
374 state
->scanner
, "'='");
378 state
->expecting
= INI_EXPECT_VALUE
;
380 case INI_EXPECT_VALUE
:
382 value
= ini_parse_value(state
);
387 state
->expecting
= INI_EXPECT_COMMA
;
390 case INI_EXPECT_COMMA
:
391 if (token_type
!= G_TOKEN_CHAR
) {
392 ini_append_error_expecting(state
,
393 state
->scanner
, "','");
397 if (state
->scanner
->value
.v_char
!= ',') {
398 ini_append_error_expecting(state
,
399 state
->scanner
, "','");
403 state
->expecting
= INI_EXPECT_MAP_KEY
;
415 if (bt_value_map_insert_entry(state
->params
,
416 state
->last_map_key
, value
)) {
417 /* Only override return value on error */
423 BT_VALUE_PUT_REF_AND_RESET(value
);
428 * Converts an INI-style argument to an equivalent map value object.
430 * Return value is owned by the caller.
433 bt_value
*bt_value_from_ini(const char *arg
,
436 /* Lexical scanner configuration */
437 GScannerConfig scanner_config
= {
438 /* Skip whitespaces */
439 .cset_skip_characters
= " \t\n",
441 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
442 .cset_identifier_first
=
446 .cset_identifier_nth
=
451 /* "hello" and "Hello" two different keys */
452 .case_sensitive
= TRUE
,
455 .cpair_comment_single
= NULL
,
456 .skip_comment_multi
= TRUE
,
457 .skip_comment_single
= TRUE
,
458 .scan_comment_multi
= FALSE
,
461 * Do scan identifiers, including 1-char identifiers,
462 * but NULL is a normal identifier.
464 .scan_identifier
= TRUE
,
465 .scan_identifier_1char
= TRUE
,
466 .scan_identifier_NULL
= FALSE
,
469 * No specific symbols: null and boolean "symbols" are
470 * scanned as plain identifiers.
472 .scan_symbols
= FALSE
,
473 .symbol_2_token
= FALSE
,
474 .scope_0_fallback
= FALSE
,
477 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
478 * integers prefixed with "$".
484 .scan_hex_dollar
= FALSE
,
486 /* Convert scanned numbers to integer tokens */
487 .numbers_2_int
= TRUE
,
489 /* Support both integers and floating-point numbers */
490 .int_2_float
= FALSE
,
492 /* Scan integers as 64-bit signed integers */
495 /* Only scan double-quoted strings */
496 .scan_string_sq
= FALSE
,
497 .scan_string_dq
= TRUE
,
499 /* Do not converter identifiers to string tokens */
500 .identifier_2_string
= FALSE
,
502 /* Scan characters as G_TOKEN_CHAR token */
503 .char_2_token
= FALSE
,
505 struct ini_parsing_state state
= {
508 .expecting
= INI_EXPECT_MAP_KEY
,
510 .ini_error
= ini_error
,
513 state
.params
= bt_value_map_create();
518 state
.scanner
= g_scanner_new(&scanner_config
);
519 if (!state
.scanner
) {
523 /* Let the scan begin */
524 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
527 int ret
= ini_handle_state(&state
);
532 } else if (ret
> 0) {
541 BT_VALUE_PUT_REF_AND_RESET(state
.params
);
545 g_scanner_destroy(state
.scanner
);
548 free(state
.last_map_key
);
553 * Returns the parameters map value object from a command-line
554 * parameter option's argument.
556 * Return value is owned by the caller.
559 bt_value
*bt_value_from_arg(const char *arg
)
561 bt_value
*params
= NULL
;
562 GString
*ini_error
= NULL
;
564 ini_error
= g_string_new(NULL
);
570 /* Try INI-style parsing */
571 params
= bt_value_from_ini(arg
, ini_error
);
573 printf_err("%s", ini_error
->str
);
579 g_string_free(ini_error
, TRUE
);
586 * Returns the plugin name, component class name, component class type,
587 * and component name from a command-line --component option's argument.
588 * arg must have the following format:
590 * [NAME:]TYPE.PLUGIN.CLS
592 * where NAME is the optional component name, TYPE is either `source`,
593 * `filter`, or `sink`, PLUGIN is the plugin name, and CLS is the
594 * component class name.
596 * On success, both *plugin and *component are not NULL. *plugin
597 * and *comp_cls are owned by the caller. On success, *name can be NULL
598 * if no component class name was found, and *comp_cls_type is set.
601 void plugin_comp_cls_names(const char *arg
, char **name
, char **plugin
,
602 char **comp_cls
, bt_component_class_type
*comp_cls_type
)
604 const char *at
= arg
;
605 GString
*gs_name
= NULL
;
606 GString
*gs_comp_cls_type
= NULL
;
607 GString
*gs_plugin
= NULL
;
608 GString
*gs_comp_cls
= NULL
;
614 BT_ASSERT(comp_cls_type
);
616 if (!bt_common_string_is_printable(arg
)) {
617 printf_err("Argument contains a non-printable character\n");
621 /* Parse the component name */
622 gs_name
= bt_common_string_until(at
, ".:\\", ":", &end_pos
);
627 if (arg
[end_pos
] == ':') {
631 g_string_assign(gs_name
, "");
634 /* Parse the component class type */
635 gs_comp_cls_type
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
636 if (!gs_comp_cls_type
|| at
[end_pos
] == '\0') {
637 printf_err("Missing component class type (`source`, `filter`, or `sink`)\n");
641 if (strcmp(gs_comp_cls_type
->str
, "source") == 0 ||
642 strcmp(gs_comp_cls_type
->str
, "src") == 0) {
643 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
644 } else if (strcmp(gs_comp_cls_type
->str
, "filter") == 0 ||
645 strcmp(gs_comp_cls_type
->str
, "flt") == 0) {
646 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
647 } else if (strcmp(gs_comp_cls_type
->str
, "sink") == 0) {
648 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
650 printf_err("Unknown component class type: `%s`\n",
651 gs_comp_cls_type
->str
);
657 /* Parse the plugin name */
658 gs_plugin
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
659 if (!gs_plugin
|| gs_plugin
->len
== 0 || at
[end_pos
] == '\0') {
660 printf_err("Missing plugin or component class name\n");
666 /* Parse the component class name */
667 gs_comp_cls
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
668 if (!gs_comp_cls
|| gs_comp_cls
->len
== 0) {
669 printf_err("Missing component class name\n");
673 if (at
[end_pos
] != '\0') {
674 /* Found a non-escaped `.` */
679 if (gs_name
->len
== 0) {
681 g_string_free(gs_name
, TRUE
);
683 *name
= gs_name
->str
;
684 g_string_free(gs_name
, FALSE
);
687 g_string_free(gs_name
, TRUE
);
690 *plugin
= gs_plugin
->str
;
691 *comp_cls
= gs_comp_cls
->str
;
692 g_string_free(gs_plugin
, FALSE
);
693 g_string_free(gs_comp_cls
, FALSE
);
709 g_string_free(gs_name
, TRUE
);
713 g_string_free(gs_plugin
, TRUE
);
717 g_string_free(gs_comp_cls
, TRUE
);
720 if (gs_comp_cls_type
) {
721 g_string_free(gs_comp_cls_type
, TRUE
);
728 * Prints the Babeltrace version.
731 void print_version(void)
733 if (GIT_VERSION
[0] == '\0') {
734 puts("Babeltrace " VERSION
);
736 puts("Babeltrace " VERSION
" - " GIT_VERSION
);
741 * Destroys a component configuration.
744 void bt_config_component_destroy(bt_object
*obj
)
746 struct bt_config_component
*bt_config_component
=
747 container_of(obj
, struct bt_config_component
, base
);
753 if (bt_config_component
->plugin_name
) {
754 g_string_free(bt_config_component
->plugin_name
, TRUE
);
757 if (bt_config_component
->comp_cls_name
) {
758 g_string_free(bt_config_component
->comp_cls_name
, TRUE
);
761 if (bt_config_component
->instance_name
) {
762 g_string_free(bt_config_component
->instance_name
, TRUE
);
765 BT_VALUE_PUT_REF_AND_RESET(bt_config_component
->params
);
766 g_free(bt_config_component
);
773 * Creates a component configuration using the given plugin name and
774 * component name. `plugin_name` and `comp_cls_name` are copied (belong
775 * to the return value).
777 * Return value is owned by the caller.
780 struct bt_config_component
*bt_config_component_create(
781 bt_component_class_type type
,
782 const char *plugin_name
, const char *comp_cls_name
)
784 struct bt_config_component
*cfg_component
= NULL
;
786 cfg_component
= g_new0(struct bt_config_component
, 1);
787 if (!cfg_component
) {
792 bt_object_init_shared(&cfg_component
->base
,
793 bt_config_component_destroy
);
794 cfg_component
->type
= type
;
795 cfg_component
->plugin_name
= g_string_new(plugin_name
);
796 if (!cfg_component
->plugin_name
) {
801 cfg_component
->comp_cls_name
= g_string_new(comp_cls_name
);
802 if (!cfg_component
->comp_cls_name
) {
807 cfg_component
->instance_name
= g_string_new(NULL
);
808 if (!cfg_component
->instance_name
) {
813 /* Start with empty parameters */
814 cfg_component
->params
= bt_value_map_create();
815 if (!cfg_component
->params
) {
823 BT_OBJECT_PUT_REF_AND_RESET(cfg_component
);
826 return cfg_component
;
830 * Creates a component configuration from a command-line --component
834 struct bt_config_component
*bt_config_component_from_arg(const char *arg
)
836 struct bt_config_component
*cfg_comp
= NULL
;
838 char *plugin_name
= NULL
;
839 char *comp_cls_name
= NULL
;
840 bt_component_class_type type
;
842 plugin_comp_cls_names(arg
, &name
, &plugin_name
, &comp_cls_name
, &type
);
843 if (!plugin_name
|| !comp_cls_name
) {
847 cfg_comp
= bt_config_component_create(type
, plugin_name
, comp_cls_name
);
853 g_string_assign(cfg_comp
->instance_name
, name
);
859 BT_OBJECT_PUT_REF_AND_RESET(cfg_comp
);
864 g_free(comp_cls_name
);
869 * Destroys a configuration.
872 void bt_config_destroy(bt_object
*obj
)
874 struct bt_config
*cfg
=
875 container_of(obj
, struct bt_config
, base
);
881 BT_VALUE_PUT_REF_AND_RESET(cfg
->plugin_paths
);
883 switch (cfg
->command
) {
884 case BT_CONFIG_COMMAND_RUN
:
885 if (cfg
->cmd_data
.run
.sources
) {
886 g_ptr_array_free(cfg
->cmd_data
.run
.sources
, TRUE
);
889 if (cfg
->cmd_data
.run
.filters
) {
890 g_ptr_array_free(cfg
->cmd_data
.run
.filters
, TRUE
);
893 if (cfg
->cmd_data
.run
.sinks
) {
894 g_ptr_array_free(cfg
->cmd_data
.run
.sinks
, TRUE
);
897 if (cfg
->cmd_data
.run
.connections
) {
898 g_ptr_array_free(cfg
->cmd_data
.run
.connections
,
902 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
904 case BT_CONFIG_COMMAND_HELP
:
905 BT_OBJECT_PUT_REF_AND_RESET(cfg
->cmd_data
.help
.cfg_component
);
907 case BT_CONFIG_COMMAND_QUERY
:
908 BT_OBJECT_PUT_REF_AND_RESET(cfg
->cmd_data
.query
.cfg_component
);
910 if (cfg
->cmd_data
.query
.object
) {
911 g_string_free(cfg
->cmd_data
.query
.object
, TRUE
);
914 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
915 if (cfg
->cmd_data
.print_ctf_metadata
.path
) {
916 g_string_free(cfg
->cmd_data
.print_ctf_metadata
.path
,
919 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
923 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
924 if (cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
926 cfg
->cmd_data
.print_lttng_live_sessions
.url
,
929 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
944 void destroy_glist_of_gstring(GList
*list
)
952 for (at
= list
; at
!= NULL
; at
= g_list_next(at
)) {
953 g_string_free(at
->data
, TRUE
);
960 * Creates a simple lexical scanner for parsing comma-delimited names
963 * Return value is owned by the caller.
966 GScanner
*create_csv_identifiers_scanner(void)
969 GScannerConfig scanner_config
= {
970 .cset_skip_characters
= " \t\n",
971 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
972 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
973 .case_sensitive
= TRUE
,
974 .cpair_comment_single
= NULL
,
975 .skip_comment_multi
= TRUE
,
976 .skip_comment_single
= TRUE
,
977 .scan_comment_multi
= FALSE
,
978 .scan_identifier
= TRUE
,
979 .scan_identifier_1char
= TRUE
,
980 .scan_identifier_NULL
= FALSE
,
981 .scan_symbols
= FALSE
,
982 .symbol_2_token
= FALSE
,
983 .scope_0_fallback
= FALSE
,
984 .scan_binary
= FALSE
,
988 .scan_hex_dollar
= FALSE
,
989 .numbers_2_int
= FALSE
,
990 .int_2_float
= FALSE
,
991 .store_int64
= FALSE
,
992 .scan_string_sq
= FALSE
,
993 .scan_string_dq
= FALSE
,
994 .identifier_2_string
= FALSE
,
995 .char_2_token
= TRUE
,
998 scanner
= g_scanner_new(&scanner_config
);
1007 * Converts a comma-delimited list of known names (--names option) to
1008 * an array value object containing those names as string value objects.
1010 * Return value is owned by the caller.
1013 bt_value
*names_from_arg(const char *arg
)
1015 GScanner
*scanner
= NULL
;
1016 bt_value
*names
= NULL
;
1017 bool found_all
= false, found_none
= false, found_item
= false;
1019 names
= bt_value_array_create();
1025 scanner
= create_csv_identifiers_scanner();
1030 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1033 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1035 switch (token_type
) {
1036 case G_TOKEN_IDENTIFIER
:
1038 const char *identifier
= scanner
->value
.v_identifier
;
1040 if (!strcmp(identifier
, "payload") ||
1041 !strcmp(identifier
, "args") ||
1042 !strcmp(identifier
, "arg")) {
1044 if (bt_value_array_append_string_element(names
,
1048 } else if (!strcmp(identifier
, "context") ||
1049 !strcmp(identifier
, "ctx")) {
1051 if (bt_value_array_append_string_element(names
,
1055 } else if (!strcmp(identifier
, "scope") ||
1056 !strcmp(identifier
, "header")) {
1058 if (bt_value_array_append_string_element(names
,
1062 } else if (!strcmp(identifier
, "all")) {
1064 if (bt_value_array_append_string_element(names
,
1068 } else if (!strcmp(identifier
, "none")) {
1070 if (bt_value_array_append_string_element(names
,
1075 printf_err("Unknown name: `%s`\n",
1091 if (found_none
&& found_all
) {
1092 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1096 * Legacy behavior is to clear the defaults (show none) when at
1097 * least one item is specified.
1099 if (found_item
&& !found_none
&& !found_all
) {
1100 if (bt_value_array_append_string_element(names
, "none")) {
1105 g_scanner_destroy(scanner
);
1110 BT_VALUE_PUT_REF_AND_RESET(names
);
1112 g_scanner_destroy(scanner
);
1118 * Converts a comma-delimited list of known fields (--fields option) to
1119 * an array value object containing those fields as string
1122 * Return value is owned by the caller.
1125 bt_value
*fields_from_arg(const char *arg
)
1127 GScanner
*scanner
= NULL
;
1130 fields
= bt_value_array_create();
1136 scanner
= create_csv_identifiers_scanner();
1141 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1144 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1146 switch (token_type
) {
1147 case G_TOKEN_IDENTIFIER
:
1149 const char *identifier
= scanner
->value
.v_identifier
;
1151 if (!strcmp(identifier
, "trace") ||
1152 !strcmp(identifier
, "trace:hostname") ||
1153 !strcmp(identifier
, "trace:domain") ||
1154 !strcmp(identifier
, "trace:procname") ||
1155 !strcmp(identifier
, "trace:vpid") ||
1156 !strcmp(identifier
, "loglevel") ||
1157 !strcmp(identifier
, "emf") ||
1158 !strcmp(identifier
, "callsite") ||
1159 !strcmp(identifier
, "all")) {
1160 if (bt_value_array_append_string_element(fields
,
1165 printf_err("Unknown field: `%s`\n",
1183 BT_VALUE_PUT_REF_AND_RESET(fields
);
1187 g_scanner_destroy(scanner
);
1193 void append_param_arg(GString
*params_arg
, const char *key
, const char *value
)
1195 BT_ASSERT(params_arg
);
1199 if (params_arg
->len
!= 0) {
1200 g_string_append_c(params_arg
, ',');
1203 g_string_append(params_arg
, key
);
1204 g_string_append_c(params_arg
, '=');
1205 g_string_append(params_arg
, value
);
1209 * Inserts the equivalent "prefix-NAME=yes" strings into params_arg
1210 * where the names are in names_array.
1213 int insert_flat_params_from_array(GString
*params_arg
,
1214 const bt_value
*names_array
, const char *prefix
)
1218 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1219 bool default_set
= false, non_default_set
= false;
1222 * names_array may be NULL if no CLI options were specified to
1223 * trigger its creation.
1229 tmpstr
= g_string_new(NULL
);
1236 default_value
= g_string_new(NULL
);
1237 if (!default_value
) {
1243 for (i
= 0; i
< bt_value_array_get_size(names_array
); i
++) {
1244 const bt_value
*str_obj
=
1245 bt_value_array_borrow_element_by_index_const(names_array
,
1248 bool is_default
= false;
1251 printf_err("Unexpected error\n");
1256 suffix
= bt_value_string_get(str_obj
);
1258 g_string_assign(tmpstr
, prefix
);
1259 g_string_append(tmpstr
, "-");
1261 /* Special-case for "all" and "none". */
1262 if (!strcmp(suffix
, "all")) {
1264 g_string_assign(default_value
, "show");
1265 } else if (!strcmp(suffix
, "none")) {
1267 g_string_assign(default_value
, "hide");
1271 g_string_append(tmpstr
, "default");
1272 append_param_arg(params_arg
, tmpstr
->str
,
1273 default_value
->str
);
1275 non_default_set
= true;
1276 g_string_append(tmpstr
, suffix
);
1277 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1281 /* Implicit field-default=hide if any non-default option is set. */
1282 if (non_default_set
&& !default_set
) {
1283 g_string_assign(tmpstr
, prefix
);
1284 g_string_append(tmpstr
, "-default");
1285 g_string_assign(default_value
, "hide");
1286 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1290 if (default_value
) {
1291 g_string_free(default_value
, TRUE
);
1295 g_string_free(tmpstr
, TRUE
);
1308 OPT_CLOCK_FORCE_CORRELATE
,
1311 OPT_CLOCK_OFFSET_NS
,
1319 OPT_DEBUG_INFO_FULL_PATH
,
1320 OPT_DEBUG_INFO_TARGET_PREFIX
,
1330 OPT_OMIT_HOME_PLUGIN_PATH
,
1331 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1337 OPT_RESET_BASE_PARAMS
,
1341 OPT_STREAM_INTERSECTION
,
1348 enum bt_config_component_dest
{
1349 BT_CONFIG_COMPONENT_DEST_UNKNOWN
= -1,
1350 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1351 BT_CONFIG_COMPONENT_DEST_FILTER
,
1352 BT_CONFIG_COMPONENT_DEST_SINK
,
1356 * Adds a configuration component to the appropriate configuration
1357 * array depending on the destination.
1360 void add_run_cfg_comp(struct bt_config
*cfg
,
1361 struct bt_config_component
*cfg_comp
,
1362 enum bt_config_component_dest dest
)
1364 bt_object_get_ref(cfg_comp
);
1367 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1368 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1370 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1371 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1373 case BT_CONFIG_COMPONENT_DEST_SINK
:
1374 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1382 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1383 struct bt_config_component
*cfg_comp
,
1384 enum bt_config_component_dest dest
,
1385 bt_value
*instance_names
)
1389 if (cfg_comp
->instance_name
->len
== 0) {
1390 printf_err("Found an unnamed component\n");
1395 if (bt_value_map_has_entry(instance_names
,
1396 cfg_comp
->instance_name
->str
)) {
1397 printf_err("Duplicate component instance name:\n %s\n",
1398 cfg_comp
->instance_name
->str
);
1403 if (bt_value_map_insert_entry(instance_names
,
1404 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1410 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1417 int append_env_var_plugin_paths(bt_value
*plugin_paths
)
1422 if (bt_common_is_setuid_setgid()) {
1423 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1427 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1432 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1436 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1443 int append_home_and_system_plugin_paths(bt_value
*plugin_paths
,
1444 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1448 if (!omit_home_plugin_path
) {
1449 if (bt_common_is_setuid_setgid()) {
1450 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1452 char *home_plugin_dir
=
1453 bt_common_get_home_plugin_path();
1455 if (home_plugin_dir
) {
1456 ret
= bt_config_append_plugin_paths(
1457 plugin_paths
, home_plugin_dir
);
1458 free(home_plugin_dir
);
1461 printf_err("Invalid home plugin path\n");
1468 if (!omit_system_plugin_path
) {
1469 if (bt_config_append_plugin_paths(plugin_paths
,
1470 bt_common_get_system_plugin_path())) {
1471 printf_err("Invalid system plugin path\n");
1477 printf_err("Cannot append home and system plugin paths\n");
1482 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1484 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1485 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1489 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1490 const bt_value
*initial_plugin_paths
,
1493 struct bt_config
*cfg
;
1496 cfg
= g_new0(struct bt_config
, 1);
1502 bt_object_init_shared(&cfg
->base
, bt_config_destroy
);
1503 cfg
->command
= command
;
1504 cfg
->command_needs_plugins
= needs_plugins
;
1506 if (initial_plugin_paths
) {
1507 bt_value
*initial_plugin_paths_copy
;
1509 (void) bt_value_copy(initial_plugin_paths
,
1510 &initial_plugin_paths_copy
);
1511 cfg
->plugin_paths
= initial_plugin_paths_copy
;
1513 cfg
->plugin_paths
= bt_value_array_create();
1514 if (!cfg
->plugin_paths
) {
1523 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1530 struct bt_config
*bt_config_run_create(
1531 const bt_value
*initial_plugin_paths
)
1533 struct bt_config
*cfg
;
1536 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1537 initial_plugin_paths
, true);
1542 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1543 (GDestroyNotify
) bt_object_put_ref
);
1544 if (!cfg
->cmd_data
.run
.sources
) {
1549 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1550 (GDestroyNotify
) bt_object_put_ref
);
1551 if (!cfg
->cmd_data
.run
.filters
) {
1556 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1557 (GDestroyNotify
) bt_object_put_ref
);
1558 if (!cfg
->cmd_data
.run
.sinks
) {
1563 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1564 (GDestroyNotify
) bt_config_connection_destroy
);
1565 if (!cfg
->cmd_data
.run
.connections
) {
1573 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1580 struct bt_config
*bt_config_list_plugins_create(
1581 const bt_value
*initial_plugin_paths
)
1583 struct bt_config
*cfg
;
1586 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1587 initial_plugin_paths
, true);
1595 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1602 struct bt_config
*bt_config_help_create(
1603 const bt_value
*initial_plugin_paths
)
1605 struct bt_config
*cfg
;
1608 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1609 initial_plugin_paths
, true);
1614 cfg
->cmd_data
.help
.cfg_component
=
1615 bt_config_component_create(-1, NULL
, NULL
);
1616 if (!cfg
->cmd_data
.help
.cfg_component
) {
1623 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1630 struct bt_config
*bt_config_query_create(
1631 const bt_value
*initial_plugin_paths
)
1633 struct bt_config
*cfg
;
1636 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1637 initial_plugin_paths
, true);
1642 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1643 if (!cfg
->cmd_data
.query
.object
) {
1651 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1658 struct bt_config
*bt_config_print_ctf_metadata_create(
1659 const bt_value
*initial_plugin_paths
)
1661 struct bt_config
*cfg
;
1664 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1665 initial_plugin_paths
, true);
1670 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1671 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1676 cfg
->cmd_data
.print_ctf_metadata
.output_path
= g_string_new(NULL
);
1677 if (!cfg
->cmd_data
.print_ctf_metadata
.output_path
) {
1685 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1692 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1693 const bt_value
*initial_plugin_paths
)
1695 struct bt_config
*cfg
;
1698 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1699 initial_plugin_paths
, true);
1704 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1705 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1710 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
=
1712 if (!cfg
->cmd_data
.print_lttng_live_sessions
.output_path
) {
1720 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1727 int bt_config_append_plugin_paths_check_setuid_setgid(
1728 bt_value
*plugin_paths
, const char *arg
)
1732 if (bt_common_is_setuid_setgid()) {
1733 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1737 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1738 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1749 * Prints the expected format for a --params option.
1752 void print_expected_params_format(FILE *fp
)
1754 fprintf(fp
, "Expected format of PARAMS\n");
1755 fprintf(fp
, "-------------------------\n");
1757 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1759 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1760 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1761 fprintf(fp
, "and VALUE can be one of:\n");
1763 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1764 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1765 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1766 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1767 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1768 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1769 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1770 fprintf(fp
, " the null and boolean value symbols above.\n");
1771 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1773 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1775 fprintf(fp
, "Example:\n");
1777 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1778 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1779 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1781 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1782 fprintf(fp
, "babeltrace from a shell.\n");
1787 * Prints the help command usage.
1790 void print_help_usage(FILE *fp
)
1792 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1793 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] TYPE.PLUGIN.CLS\n");
1795 fprintf(fp
, "Options:\n");
1797 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1798 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1799 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1800 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1801 fprintf(fp
, " dynamic plugins can be loaded\n");
1802 fprintf(fp
, " -h, --help Show this help and quit\n");
1804 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1806 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1810 struct poptOption help_long_options
[] = {
1811 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1812 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1813 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1814 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1815 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1816 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1820 * Creates a Babeltrace config object from the arguments of a help
1823 * *retcode is set to the appropriate exit code to use.
1826 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1827 int *retcode
, bool force_omit_system_plugin_path
,
1828 bool force_omit_home_plugin_path
,
1829 const bt_value
*initial_plugin_paths
)
1831 poptContext pc
= NULL
;
1835 struct bt_config
*cfg
= NULL
;
1836 const char *leftover
;
1837 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1840 cfg
= bt_config_help_create(initial_plugin_paths
);
1845 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1846 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1847 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1853 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1854 help_long_options
, 0);
1856 printf_err("Cannot get popt context\n");
1860 poptReadDefaultConfig(pc
, 0);
1862 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1863 arg
= poptGetOptArg(pc
);
1866 case OPT_PLUGIN_PATH
:
1867 if (bt_config_append_plugin_paths_check_setuid_setgid(
1868 cfg
->plugin_paths
, arg
)) {
1872 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1873 cfg
->omit_system_plugin_path
= true;
1875 case OPT_OMIT_HOME_PLUGIN_PATH
:
1876 cfg
->omit_home_plugin_path
= true;
1879 print_help_usage(stdout
);
1881 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1884 printf_err("Unknown command-line option specified (option code %d)\n",
1893 /* Check for option parsing error */
1895 printf_err("While parsing command-line options, at option %s: %s\n",
1896 poptBadOption(pc
, 0), poptStrerror(opt
));
1900 leftover
= poptGetArg(pc
);
1902 plugin_comp_cls_names(leftover
, NULL
,
1903 &plugin_name
, &comp_cls_name
,
1904 &cfg
->cmd_data
.help
.cfg_component
->type
);
1905 if (plugin_name
&& comp_cls_name
) {
1906 /* Component class help */
1908 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1911 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1914 /* Fall back to plugin help */
1916 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1920 print_help_usage(stdout
);
1922 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1926 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1934 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1937 g_free(plugin_name
);
1938 g_free(comp_cls_name
);
1941 poptFreeContext(pc
);
1949 * Prints the help command usage.
1952 void print_query_usage(FILE *fp
)
1954 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] TYPE.PLUGIN.CLS OBJECT\n");
1956 fprintf(fp
, "Options:\n");
1958 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1959 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1960 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1961 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1962 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1963 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1964 fprintf(fp
, " dynamic plugins can be loaded\n");
1965 fprintf(fp
, " -h, --help Show this help and quit\n");
1966 fprintf(fp
, "\n\n");
1967 print_expected_params_format(fp
);
1971 struct poptOption query_long_options
[] = {
1972 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1973 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1974 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1975 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1976 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1977 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1978 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1982 * Creates a Babeltrace config object from the arguments of a query
1985 * *retcode is set to the appropriate exit code to use.
1988 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1989 int *retcode
, bool force_omit_system_plugin_path
,
1990 bool force_omit_home_plugin_path
,
1991 const bt_value
*initial_plugin_paths
)
1993 poptContext pc
= NULL
;
1997 struct bt_config
*cfg
= NULL
;
1998 const char *leftover
;
2001 params
= bt_value_null
;
2002 bt_value_get_ref(bt_value_null
);
2005 cfg
= bt_config_query_create(initial_plugin_paths
);
2010 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2011 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2012 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2018 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2019 query_long_options
, 0);
2021 printf_err("Cannot get popt context\n");
2025 poptReadDefaultConfig(pc
, 0);
2027 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2028 arg
= poptGetOptArg(pc
);
2031 case OPT_PLUGIN_PATH
:
2032 if (bt_config_append_plugin_paths_check_setuid_setgid(
2033 cfg
->plugin_paths
, arg
)) {
2037 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2038 cfg
->omit_system_plugin_path
= true;
2040 case OPT_OMIT_HOME_PLUGIN_PATH
:
2041 cfg
->omit_home_plugin_path
= true;
2045 bt_value_put_ref(params
);
2046 params
= bt_value_from_arg(arg
);
2048 printf_err("Invalid format for --params option's argument:\n %s\n",
2055 print_query_usage(stdout
);
2057 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2060 printf_err("Unknown command-line option specified (option code %d)\n",
2069 /* Check for option parsing error */
2071 printf_err("While parsing command-line options, at option %s: %s\n",
2072 poptBadOption(pc
, 0), poptStrerror(opt
));
2077 * We need exactly two leftover arguments which are the
2078 * mandatory component class specification and query object.
2080 leftover
= poptGetArg(pc
);
2082 cfg
->cmd_data
.query
.cfg_component
=
2083 bt_config_component_from_arg(leftover
);
2084 if (!cfg
->cmd_data
.query
.cfg_component
) {
2085 printf_err("Invalid format for component class specification:\n %s\n",
2091 BT_OBJECT_MOVE_REF(cfg
->cmd_data
.query
.cfg_component
->params
,
2094 print_query_usage(stdout
);
2096 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2100 leftover
= poptGetArg(pc
);
2102 if (strlen(leftover
) == 0) {
2103 printf_err("Invalid empty object\n");
2107 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2109 print_query_usage(stdout
);
2111 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2115 leftover
= poptGetArg(pc
);
2117 printf_err("Unexpected argument: %s\n", leftover
);
2121 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2129 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2133 poptFreeContext(pc
);
2136 bt_value_put_ref(params
);
2142 * Prints the list-plugins command usage.
2145 void print_list_plugins_usage(FILE *fp
)
2147 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2149 fprintf(fp
, "Options:\n");
2151 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2152 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2153 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2154 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2155 fprintf(fp
, " dynamic plugins can be loaded\n");
2156 fprintf(fp
, " -h, --help Show this help and quit\n");
2158 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2160 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2164 struct poptOption list_plugins_long_options
[] = {
2165 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2166 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2167 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2168 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2169 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2170 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2174 * Creates a Babeltrace config object from the arguments of a
2175 * list-plugins command.
2177 * *retcode is set to the appropriate exit code to use.
2180 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2181 int *retcode
, bool force_omit_system_plugin_path
,
2182 bool force_omit_home_plugin_path
,
2183 const bt_value
*initial_plugin_paths
)
2185 poptContext pc
= NULL
;
2189 struct bt_config
*cfg
= NULL
;
2190 const char *leftover
;
2193 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2198 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2199 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2200 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2206 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2207 list_plugins_long_options
, 0);
2209 printf_err("Cannot get popt context\n");
2213 poptReadDefaultConfig(pc
, 0);
2215 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2216 arg
= poptGetOptArg(pc
);
2219 case OPT_PLUGIN_PATH
:
2220 if (bt_config_append_plugin_paths_check_setuid_setgid(
2221 cfg
->plugin_paths
, arg
)) {
2225 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2226 cfg
->omit_system_plugin_path
= true;
2228 case OPT_OMIT_HOME_PLUGIN_PATH
:
2229 cfg
->omit_home_plugin_path
= true;
2232 print_list_plugins_usage(stdout
);
2234 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2237 printf_err("Unknown command-line option specified (option code %d)\n",
2246 /* Check for option parsing error */
2248 printf_err("While parsing command-line options, at option %s: %s\n",
2249 poptBadOption(pc
, 0), poptStrerror(opt
));
2253 leftover
= poptGetArg(pc
);
2255 printf_err("Unexpected argument: %s\n", leftover
);
2259 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2267 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2271 poptFreeContext(pc
);
2279 * Prints the run command usage.
2282 void print_run_usage(FILE *fp
)
2284 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2286 fprintf(fp
, "Options:\n");
2288 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2289 fprintf(fp
, " for all the following components until\n");
2290 fprintf(fp
, " --reset-base-params is encountered\n");
2291 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2292 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2293 fprintf(fp
, " Instantiate the component class CLS of type\n");
2294 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2295 fprintf(fp
, " in the plugin PLUGIN, add it to the graph,\n");
2296 fprintf(fp
, " and optionally name it NAME (you can also\n");
2297 fprintf(fp
, " specify the name with --name)\n");
2298 fprintf(fp
, " -x, --connect=CONNECTION Connect two created components (see the\n");
2299 fprintf(fp
, " expected format of CONNECTION below)\n");
2300 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2301 fprintf(fp
, " parameter key to KEY (see --value)\n");
2302 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2303 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2304 fprintf(fp
, " names of the created components)\n");
2305 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2306 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2307 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2308 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2309 fprintf(fp
, " current component (see the expected format\n");
2310 fprintf(fp
, " of PARAMS below)\n");
2311 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2312 fprintf(fp
, " dynamic plugins can be loaded\n");
2313 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2314 fprintf(fp
, " empty map\n");
2315 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2316 fprintf(fp
, " the graph later, retry in DUR µs\n");
2317 fprintf(fp
, " (default: 100000)\n");
2318 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2319 fprintf(fp
, " the current component with a name given by\n");
2320 fprintf(fp
, " the last argument of the --key option and a\n");
2321 fprintf(fp
, " value set to VAL\n");
2322 fprintf(fp
, " -h, --help Show this help and quit\n");
2324 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2325 fprintf(fp
, "\n\n");
2326 fprintf(fp
, "Expected format of CONNECTION\n");
2327 fprintf(fp
, "-----------------------------\n");
2329 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2331 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2332 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2333 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2334 fprintf(fp
, "component with the --name option.\n");
2336 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2337 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2338 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2340 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2341 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2342 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2343 fprintf(fp
, "DOWNSTREAM.\n");
2345 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2346 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2347 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2349 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2350 fprintf(fp
, "can connect a filter component to a sink component.\n");
2352 fprintf(fp
, "Examples:\n");
2354 fprintf(fp
, " my-src:my-sink\n");
2355 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2357 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2358 fprintf(fp
, "babeltrace from a shell.\n");
2359 fprintf(fp
, "\n\n");
2360 print_expected_params_format(fp
);
2364 * Creates a Babeltrace config object from the arguments of a run
2367 * *retcode is set to the appropriate exit code to use.
2370 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2371 int *retcode
, bool force_omit_system_plugin_path
,
2372 bool force_omit_home_plugin_path
,
2373 const bt_value
*initial_plugin_paths
)
2375 poptContext pc
= NULL
;
2377 struct bt_config_component
*cur_cfg_comp
= NULL
;
2378 enum bt_config_component_dest cur_cfg_comp_dest
=
2379 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
2380 bt_value
*cur_base_params
= NULL
;
2382 struct bt_config
*cfg
= NULL
;
2383 bt_value
*instance_names
= NULL
;
2384 bt_value
*connection_args
= NULL
;
2385 GString
*cur_param_key
= NULL
;
2386 char error_buf
[256] = { 0 };
2387 long retry_duration
= -1;
2388 bt_value_status status
;
2389 struct poptOption run_long_options
[] = {
2390 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2391 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2392 { "connect", 'x', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2393 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2394 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2395 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2396 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2397 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2398 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2399 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2400 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2401 { "retry-duration", '\0', POPT_ARG_LONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2402 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2403 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2407 cur_param_key
= g_string_new(NULL
);
2408 if (!cur_param_key
) {
2414 print_run_usage(stdout
);
2419 cfg
= bt_config_run_create(initial_plugin_paths
);
2424 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2425 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2426 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2427 cur_base_params
= bt_value_map_create();
2428 if (!cur_base_params
) {
2433 instance_names
= bt_value_map_create();
2434 if (!instance_names
) {
2439 connection_args
= bt_value_array_create();
2440 if (!connection_args
) {
2445 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2451 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2452 run_long_options
, 0);
2454 printf_err("Cannot get popt context\n");
2458 poptReadDefaultConfig(pc
, 0);
2460 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2461 arg
= poptGetOptArg(pc
);
2464 case OPT_PLUGIN_PATH
:
2465 if (bt_config_append_plugin_paths_check_setuid_setgid(
2466 cfg
->plugin_paths
, arg
)) {
2470 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2471 cfg
->omit_system_plugin_path
= true;
2473 case OPT_OMIT_HOME_PLUGIN_PATH
:
2474 cfg
->omit_home_plugin_path
= true;
2478 enum bt_config_component_dest new_dest
;
2481 ret
= add_run_cfg_comp_check_name(cfg
,
2482 cur_cfg_comp
, cur_cfg_comp_dest
,
2484 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2490 cur_cfg_comp
= bt_config_component_from_arg(arg
);
2491 if (!cur_cfg_comp
) {
2492 printf_err("Invalid format for --component option's argument:\n %s\n",
2497 switch (cur_cfg_comp
->type
) {
2498 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
2499 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2501 case BT_COMPONENT_CLASS_TYPE_FILTER
:
2502 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2504 case BT_COMPONENT_CLASS_TYPE_SINK
:
2505 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2511 BT_ASSERT(cur_base_params
);
2512 bt_value_put_ref(cur_cfg_comp
->params
);
2513 status
= bt_value_copy(cur_base_params
,
2514 &cur_cfg_comp
->params
);
2515 if (status
!= BT_VALUE_STATUS_OK
) {
2520 cur_cfg_comp_dest
= new_dest
;
2526 bt_value
*params_to_set
;
2528 if (!cur_cfg_comp
) {
2529 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2534 params
= bt_value_from_arg(arg
);
2536 printf_err("Invalid format for --params option's argument:\n %s\n",
2541 status
= bt_value_map_extend(cur_cfg_comp
->params
,
2542 params
, ¶ms_to_set
);
2543 BT_VALUE_PUT_REF_AND_RESET(params
);
2544 if (status
!= BT_VALUE_STATUS_OK
) {
2545 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2550 BT_OBJECT_MOVE_REF(cur_cfg_comp
->params
, params_to_set
);
2554 if (strlen(arg
) == 0) {
2555 printf_err("Cannot set an empty string as the current parameter key\n");
2559 g_string_assign(cur_param_key
, arg
);
2562 if (!cur_cfg_comp
) {
2563 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2568 if (cur_param_key
->len
== 0) {
2569 printf_err("--value option specified without preceding --key option:\n %s\n",
2574 if (bt_value_map_insert_string_entry(cur_cfg_comp
->params
,
2575 cur_param_key
->str
, arg
)) {
2581 if (!cur_cfg_comp
) {
2582 printf_err("Cannot set the name of unavailable component:\n %s\n",
2587 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2589 case OPT_BASE_PARAMS
:
2592 bt_value_from_arg(arg
);
2595 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2600 BT_OBJECT_MOVE_REF(cur_base_params
, params
);
2603 case OPT_RESET_BASE_PARAMS
:
2604 BT_VALUE_PUT_REF_AND_RESET(cur_base_params
);
2605 cur_base_params
= bt_value_map_create();
2606 if (!cur_base_params
) {
2612 if (bt_value_array_append_string_element(
2613 connection_args
, arg
)) {
2618 case OPT_RETRY_DURATION
:
2619 if (retry_duration
< 0) {
2620 printf_err("--retry-duration option's argument must be positive or 0: %ld\n",
2625 cfg
->cmd_data
.run
.retry_duration_us
=
2626 (uint64_t) retry_duration
;
2629 print_run_usage(stdout
);
2631 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2634 printf_err("Unknown command-line option specified (option code %d)\n",
2643 /* Check for option parsing error */
2645 printf_err("While parsing command-line options, at option %s: %s\n",
2646 poptBadOption(pc
, 0), poptStrerror(opt
));
2650 /* This command does not accept leftover arguments */
2651 if (poptPeekArg(pc
)) {
2652 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2656 /* Add current component */
2658 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2659 cur_cfg_comp_dest
, instance_names
);
2660 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2666 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2667 printf_err("Incomplete graph: no source component\n");
2671 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2672 printf_err("Incomplete graph: no sink component\n");
2676 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2680 ret
= bt_config_cli_args_create_connections(cfg
,
2684 printf_err("Cannot creation connections:\n%s", error_buf
);
2692 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2696 poptFreeContext(pc
);
2699 if (cur_param_key
) {
2700 g_string_free(cur_param_key
, TRUE
);
2704 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2705 BT_VALUE_PUT_REF_AND_RESET(cur_base_params
);
2706 BT_VALUE_PUT_REF_AND_RESET(instance_names
);
2707 BT_VALUE_PUT_REF_AND_RESET(connection_args
);
2712 struct bt_config
*bt_config_run_from_args_array(const bt_value
*run_args
,
2713 int *retcode
, bool force_omit_system_plugin_path
,
2714 bool force_omit_home_plugin_path
,
2715 const bt_value
*initial_plugin_paths
)
2717 struct bt_config
*cfg
= NULL
;
2720 const size_t argc
= bt_value_array_get_size(run_args
) + 1;
2722 argv
= calloc(argc
, sizeof(*argv
));
2730 len
= bt_value_array_get_size(run_args
);
2732 printf_err("Invalid executable arguments\n");
2735 for (i
= 0; i
< len
; i
++) {
2736 const bt_value
*arg_value
=
2737 bt_value_array_borrow_element_by_index_const(run_args
,
2741 BT_ASSERT(arg_value
);
2742 arg
= bt_value_string_get(arg_value
);
2747 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2748 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2749 initial_plugin_paths
);
2757 * Prints the convert command usage.
2760 void print_convert_usage(FILE *fp
)
2762 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2764 fprintf(fp
, "Options:\n");
2766 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2767 fprintf(fp
, " Instantiate the component class CLS of type\n");
2768 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2769 fprintf(fp
, " in the plugin PLUGIN, add it to the\n");
2770 fprintf(fp
, " conversion graph, and optionally name it\n");
2771 fprintf(fp
, " NAME (you can also specify the name with\n");
2772 fprintf(fp
, " --name)\n");
2773 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2774 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2775 fprintf(fp
, " names of the created components)\n");
2776 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2777 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2778 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2779 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2780 fprintf(fp
, " current component (see the expected format\n");
2781 fprintf(fp
, " of PARAMS below)\n");
2782 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2783 fprintf(fp
, " current component to PATH\n");
2784 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2785 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2786 fprintf(fp
, " the graph later, retry in DUR µs\n");
2787 fprintf(fp
, " (default: 100000)\n");
2788 fprintf(fp
, " dynamic plugins can be loaded\n");
2789 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2790 fprintf(fp
, " `run` command to the standard output,\n");
2791 fprintf(fp
, " formatted for a shell, and quit\n");
2792 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2793 fprintf(fp
, " `run` command to the standard output,\n");
2794 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2795 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2796 fprintf(fp
, " are active\n");
2797 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2798 fprintf(fp
, " current component to URL\n");
2799 fprintf(fp
, " -h, --help Show this help and quit\n");
2801 fprintf(fp
, "Implicit `source.ctf.fs` component options:\n");
2803 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2804 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2806 fprintf(fp
, "Implicit `sink.text.pretty` component options:\n");
2808 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2809 fprintf(fp
, " --clock-date Print timestamp dates\n");
2810 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2811 fprintf(fp
, " time zone instead of the local time zone\n");
2812 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2813 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2814 fprintf(fp
, " --color=(never | auto | always)\n");
2815 fprintf(fp
, " Never, automatically, or always emit\n");
2816 fprintf(fp
, " console color codes\n");
2817 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2818 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2819 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2820 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2821 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2822 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2823 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2824 fprintf(fp
, " (or `ctx`)\n");
2825 fprintf(fp
, " --no-delta Do not print time delta between\n");
2826 fprintf(fp
, " consecutive events\n");
2827 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2828 fprintf(fp
, " the standard output\n");
2830 fprintf(fp
, "Implicit `filter.utils.muxer` component options:\n");
2832 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2833 fprintf(fp
, " correlated across traces\n");
2835 fprintf(fp
, "Implicit `filter.utils.trimmer` component options:\n");
2837 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2838 fprintf(fp
, " time range to BEGIN (see the format of\n");
2839 fprintf(fp
, " BEGIN below)\n");
2840 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2841 fprintf(fp
, " range to END (see the format of END below)\n");
2842 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2843 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2844 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2846 fprintf(fp
, "Implicit `filter.lttng-utils.debug-info` component options:\n");
2848 fprintf(fp
, " --debug-info Create an implicit\n");
2849 fprintf(fp
, " `filter.lttng-utils.debug-info` component\n");
2850 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2851 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2852 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2853 fprintf(fp
, " binary paths instead of just names\n");
2854 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2855 fprintf(fp
, " Use directory DIR as a prefix when\n");
2856 fprintf(fp
, " looking up executables during debug\n");
2857 fprintf(fp
, " info analysis\n");
2859 fprintf(fp
, "Legacy options that still work:\n");
2861 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2862 fprintf(fp
, " `ctf`:\n");
2863 fprintf(fp
, " Create an implicit `source.ctf.fs`\n");
2864 fprintf(fp
, " component\n");
2865 fprintf(fp
, " `lttng-live`:\n");
2866 fprintf(fp
, " Create an implicit `source.ctf.lttng-live`\n");
2867 fprintf(fp
, " component\n");
2868 fprintf(fp
, " -o, --output-format=(text | ctf | dummy | ctf-metadata)\n");
2869 fprintf(fp
, " `text`:\n");
2870 fprintf(fp
, " Create an implicit `sink.text.pretty`\n");
2871 fprintf(fp
, " component\n");
2872 fprintf(fp
, " `ctf`:\n");
2873 fprintf(fp
, " Create an implicit `sink.ctf.fs`\n");
2874 fprintf(fp
, " component\n");
2875 fprintf(fp
, " `dummy`:\n");
2876 fprintf(fp
, " Create an implicit `sink.utils.dummy`\n");
2877 fprintf(fp
, " component\n");
2878 fprintf(fp
, " `ctf-metadata`:\n");
2879 fprintf(fp
, " Query the `source.ctf.fs` component class\n");
2880 fprintf(fp
, " for metadata text and quit\n");
2882 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2883 fprintf(fp
, "\n\n");
2884 fprintf(fp
, "Format of BEGIN and END\n");
2885 fprintf(fp
, "-----------------------\n");
2887 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2888 fprintf(fp
, "\n\n");
2889 print_expected_params_format(fp
);
2893 struct poptOption convert_long_options
[] = {
2894 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2895 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2896 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2897 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2898 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2899 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2900 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2901 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2902 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2903 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2904 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2905 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2906 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2907 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2908 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2909 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2910 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2911 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2912 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2913 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2914 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2915 { "debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO
, NULL
, NULL
},
2916 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2917 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2918 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2919 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2920 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2921 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2922 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2923 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2924 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2925 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2926 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2927 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2928 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2929 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2930 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2931 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2935 GString
*get_component_auto_name(const char *prefix
,
2936 const bt_value
*existing_names
)
2939 GString
*auto_name
= g_string_new(NULL
);
2946 if (!bt_value_map_has_entry(existing_names
, prefix
)) {
2947 g_string_assign(auto_name
, prefix
);
2952 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2954 } while (bt_value_map_has_entry(existing_names
, auto_name
->str
));
2960 struct implicit_component_args
{
2964 GString
*params_arg
;
2965 bt_value
*extra_params
;
2969 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
2970 const char *prefix
, bt_value
*existing_names
,
2971 GList
**comp_names
, bool append_to_comp_names
)
2974 GString
*name
= NULL
;
2976 if (!args
->exists
) {
2980 name
= get_component_auto_name(prefix
,
2988 g_string_assign(args
->name_arg
, name
->str
);
2990 if (bt_value_map_insert_entry(existing_names
, name
->str
,
2997 if (append_to_comp_names
) {
2998 *comp_names
= g_list_append(*comp_names
, name
);
3004 g_string_free(name
, TRUE
);
3011 int append_run_args_for_implicit_component(
3012 struct implicit_component_args
*impl_args
,
3018 if (!impl_args
->exists
) {
3022 if (bt_value_array_append_string_element(run_args
, "--component")) {
3027 if (bt_value_array_append_string_element(run_args
, impl_args
->comp_arg
->str
)) {
3032 if (bt_value_array_append_string_element(run_args
, "--name")) {
3037 if (bt_value_array_append_string_element(run_args
, impl_args
->name_arg
->str
)) {
3042 if (impl_args
->params_arg
->len
> 0) {
3043 if (bt_value_array_append_string_element(run_args
, "--params")) {
3048 if (bt_value_array_append_string_element(run_args
,
3049 impl_args
->params_arg
->str
)) {
3055 for (i
= 0; i
< bt_value_array_get_size(impl_args
->extra_params
);
3057 const bt_value
*elem
;
3060 elem
= bt_value_array_borrow_element_by_index(impl_args
->extra_params
,
3066 BT_ASSERT(bt_value_is_string(elem
));
3067 arg
= bt_value_string_get(elem
);
3068 ret
= bt_value_array_append_string_element(run_args
, arg
);
3085 void finalize_implicit_component_args(struct implicit_component_args
*args
)
3089 if (args
->comp_arg
) {
3090 g_string_free(args
->comp_arg
, TRUE
);
3093 if (args
->name_arg
) {
3094 g_string_free(args
->name_arg
, TRUE
);
3097 if (args
->params_arg
) {
3098 g_string_free(args
->params_arg
, TRUE
);
3101 bt_value_put_ref(args
->extra_params
);
3105 void destroy_implicit_component_args(void *args
)
3111 finalize_implicit_component_args(args
);
3116 int init_implicit_component_args(struct implicit_component_args
*args
,
3117 const char *comp_arg
, bool exists
)
3121 args
->exists
= exists
;
3122 args
->comp_arg
= g_string_new(comp_arg
);
3123 args
->name_arg
= g_string_new(NULL
);
3124 args
->params_arg
= g_string_new(NULL
);
3125 args
->extra_params
= bt_value_array_create();
3127 if (!args
->comp_arg
|| !args
->name_arg
||
3128 !args
->params_arg
|| !args
->extra_params
) {
3130 finalize_implicit_component_args(args
);
3140 void append_implicit_component_param(struct implicit_component_args
*args
,
3141 const char *key
, const char *value
)
3146 append_param_arg(args
->params_arg
, key
, value
);
3150 int append_implicit_component_extra_param(struct implicit_component_args
*args
,
3151 const char *key
, const char *value
)
3159 if (bt_value_array_append_string_element(args
->extra_params
, "--key")) {
3165 if (bt_value_array_append_string_element(args
->extra_params
, key
)) {
3171 if (bt_value_array_append_string_element(args
->extra_params
, "--value")) {
3177 if (bt_value_array_append_string_element(args
->extra_params
, value
)) {
3188 int convert_append_name_param(enum bt_config_component_dest dest
,
3189 GString
*cur_name
, GString
*cur_name_prefix
,
3191 bt_value
*all_names
,
3192 GList
**source_names
, GList
**filter_names
,
3197 if (cur_name_prefix
->len
> 0) {
3198 /* We're after a --component option */
3199 GString
*name
= NULL
;
3200 bool append_name_opt
= false;
3202 if (cur_name
->len
== 0) {
3204 * No explicit name was provided for the user
3207 name
= get_component_auto_name(cur_name_prefix
->str
,
3209 append_name_opt
= true;
3212 * An explicit name was provided for the user
3215 if (bt_value_map_has_entry(all_names
,
3217 printf_err("Duplicate component instance name:\n %s\n",
3222 name
= g_string_new(cur_name
->str
);
3231 * Remember this name globally, for the uniqueness of
3232 * all component names.
3234 if (bt_value_map_insert_entry(all_names
, name
->str
, bt_value_null
)) {
3240 * Append the --name option if necessary.
3242 if (append_name_opt
) {
3243 if (bt_value_array_append_string_element(run_args
, "--name")) {
3248 if (bt_value_array_append_string_element(run_args
, name
->str
)) {
3255 * Remember this name specifically for the type of the
3256 * component. This is to create connection arguments.
3259 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3260 *source_names
= g_list_append(*source_names
, name
);
3262 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3263 *filter_names
= g_list_append(*filter_names
, name
);
3265 case BT_CONFIG_COMPONENT_DEST_SINK
:
3266 *sink_names
= g_list_append(*sink_names
, name
);
3272 g_string_assign(cur_name_prefix
, "");
3285 * Escapes `.`, `:`, and `\` of `input` with `\`.
3288 GString
*escape_dot_colon(const char *input
)
3290 GString
*output
= g_string_new(NULL
);
3298 for (ch
= input
; *ch
!= '\0'; ch
++) {
3299 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3300 g_string_append_c(output
, '\\');
3303 g_string_append_c(output
, *ch
);
3311 * Appends a --connect option to a list of arguments. `upstream_name`
3312 * and `downstream_name` are escaped with escape_dot_colon() in this
3316 int append_connect_arg(bt_value
*run_args
,
3317 const char *upstream_name
, const char *downstream_name
)
3320 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3321 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3322 GString
*arg
= g_string_new(NULL
);
3324 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3330 ret
= bt_value_array_append_string_element(run_args
, "--connect");
3337 g_string_append(arg
, e_upstream_name
->str
);
3338 g_string_append_c(arg
, ':');
3339 g_string_append(arg
, e_downstream_name
->str
);
3340 ret
= bt_value_array_append_string_element(run_args
, arg
->str
);
3349 g_string_free(arg
, TRUE
);
3352 if (e_upstream_name
) {
3353 g_string_free(e_upstream_name
, TRUE
);
3356 if (e_downstream_name
) {
3357 g_string_free(e_downstream_name
, TRUE
);
3364 * Appends the run command's --connect options for the convert command.
3367 int convert_auto_connect(bt_value
*run_args
,
3368 GList
*source_names
, GList
*filter_names
,
3372 GList
*source_at
= source_names
;
3373 GList
*filter_at
= filter_names
;
3375 GList
*sink_at
= sink_names
;
3377 BT_ASSERT(source_names
);
3378 BT_ASSERT(filter_names
);
3379 BT_ASSERT(sink_names
);
3381 /* Connect all sources to the first filter */
3382 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3383 GString
*source_name
= source_at
->data
;
3384 GString
*filter_name
= filter_at
->data
;
3386 ret
= append_connect_arg(run_args
, source_name
->str
,
3393 filter_prev
= filter_at
;
3394 filter_at
= g_list_next(filter_at
);
3396 /* Connect remaining filters */
3397 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3398 GString
*filter_name
= filter_at
->data
;
3399 GString
*filter_prev_name
= filter_prev
->data
;
3401 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3408 /* Connect last filter to all sinks */
3409 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3410 GString
*filter_name
= filter_prev
->data
;
3411 GString
*sink_name
= sink_at
->data
;
3413 ret
= append_connect_arg(run_args
, filter_name
->str
,
3430 int split_timerange(const char *arg
, char **begin
, char **end
)
3433 const char *ch
= arg
;
3435 GString
*g_begin
= NULL
;
3436 GString
*g_end
= NULL
;
3444 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3445 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3451 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3452 if (!g_end
|| g_end
->len
== 0) {
3458 *begin
= g_begin
->str
;
3460 g_string_free(g_begin
, FALSE
);
3461 g_string_free(g_end
, FALSE
);
3471 g_string_free(g_begin
, TRUE
);
3475 g_string_free(g_end
, TRUE
);
3482 int g_list_prepend_gstring(GList
**list
, const char *string
)
3485 GString
*gs
= g_string_new(string
);
3494 *list
= g_list_prepend(*list
, gs
);
3501 struct implicit_component_args
*create_implicit_component_args(void)
3503 struct implicit_component_args
*impl_args
=
3504 g_new0(struct implicit_component_args
, 1);
3510 if (init_implicit_component_args(impl_args
, NULL
, true)) {
3511 destroy_implicit_component_args(impl_args
);
3521 int fill_implicit_ctf_inputs_args(GPtrArray
*implicit_ctf_inputs_args
,
3522 struct implicit_component_args
*base_implicit_ctf_input_args
,
3527 bt_value_status status
;
3529 for (leftover
= leftovers
; leftover
!= NULL
;
3530 leftover
= g_list_next(leftover
)) {
3531 GString
*gs_leftover
= leftover
->data
;
3532 struct implicit_component_args
*impl_args
=
3533 create_implicit_component_args();
3540 impl_args
->exists
= true;
3541 g_string_assign(impl_args
->comp_arg
,
3542 base_implicit_ctf_input_args
->comp_arg
->str
);
3543 g_string_assign(impl_args
->params_arg
,
3544 base_implicit_ctf_input_args
->params_arg
->str
);
3547 * We need our own copy of the extra parameters because
3548 * this is where the unique path goes.
3550 BT_VALUE_PUT_REF_AND_RESET(impl_args
->extra_params
);
3551 status
= bt_value_copy(base_implicit_ctf_input_args
->extra_params
,
3552 &impl_args
->extra_params
);
3553 if (status
!= BT_VALUE_STATUS_OK
) {
3555 destroy_implicit_component_args(impl_args
);
3559 /* Append unique path parameter */
3560 ret
= append_implicit_component_extra_param(impl_args
,
3561 "path", gs_leftover
->str
);
3563 destroy_implicit_component_args(impl_args
);
3567 g_ptr_array_add(implicit_ctf_inputs_args
, impl_args
);
3580 * Creates a Babeltrace config object from the arguments of a convert
3583 * *retcode is set to the appropriate exit code to use.
3586 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3587 int *retcode
, bool force_omit_system_plugin_path
,
3588 bool force_omit_home_plugin_path
,
3589 const bt_value
*initial_plugin_paths
, char *log_level
)
3591 poptContext pc
= NULL
;
3593 enum bt_config_component_dest cur_comp_dest
=
3594 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3596 struct bt_config
*cfg
= NULL
;
3597 bool got_input_format_opt
= false;
3598 bool got_output_format_opt
= false;
3599 bool trimmer_has_begin
= false;
3600 bool trimmer_has_end
= false;
3601 bool stream_intersection_mode
= false;
3602 GString
*cur_name
= NULL
;
3603 GString
*cur_name_prefix
= NULL
;
3604 const char *leftover
= NULL
;
3605 bool print_run_args
= false;
3606 bool print_run_args_0
= false;
3607 bool print_ctf_metadata
= false;
3608 bt_value
*run_args
= NULL
;
3609 bt_value
*all_names
= NULL
;
3610 GList
*source_names
= NULL
;
3611 GList
*filter_names
= NULL
;
3612 GList
*sink_names
= NULL
;
3613 GList
*leftovers
= NULL
;
3614 GPtrArray
*implicit_ctf_inputs_args
= NULL
;
3615 struct implicit_component_args base_implicit_ctf_input_args
= { 0 };
3616 struct implicit_component_args implicit_ctf_output_args
= { 0 };
3617 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3618 struct implicit_component_args implicit_dummy_args
= { 0 };
3619 struct implicit_component_args implicit_text_args
= { 0 };
3620 struct implicit_component_args implicit_debug_info_args
= { 0 };
3621 struct implicit_component_args implicit_muxer_args
= { 0 };
3622 struct implicit_component_args implicit_trimmer_args
= { 0 };
3623 bt_value
*plugin_paths
;
3624 char error_buf
[256] = { 0 };
3626 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3627 char *output
= NULL
;
3629 (void) bt_value_copy(initial_plugin_paths
, &plugin_paths
);
3634 print_convert_usage(stdout
);
3639 if (init_implicit_component_args(&base_implicit_ctf_input_args
,
3640 "source.ctf.fs", false)) {
3644 if (init_implicit_component_args(&implicit_ctf_output_args
,
3645 "sink.ctf.fs", false)) {
3649 if (init_implicit_component_args(&implicit_lttng_live_args
,
3650 "source.ctf.lttng-live", false)) {
3654 if (init_implicit_component_args(&implicit_text_args
,
3655 "sink.text.pretty", false)) {
3659 if (init_implicit_component_args(&implicit_dummy_args
,
3660 "sink.utils.dummy", false)) {
3664 if (init_implicit_component_args(&implicit_debug_info_args
,
3665 "filter.lttng-utils.debug-info", false)) {
3669 if (init_implicit_component_args(&implicit_muxer_args
,
3670 "filter.utils.muxer", true)) {
3674 if (init_implicit_component_args(&implicit_trimmer_args
,
3675 "filter.utils.trimmer", false)) {
3679 implicit_ctf_inputs_args
= g_ptr_array_new_with_free_func(
3680 (GDestroyNotify
) destroy_implicit_component_args
);
3681 if (!implicit_ctf_inputs_args
) {
3686 all_names
= bt_value_map_create();
3692 run_args
= bt_value_array_create();
3698 cur_name
= g_string_new(NULL
);
3704 cur_name_prefix
= g_string_new(NULL
);
3705 if (!cur_name_prefix
) {
3710 ret
= append_env_var_plugin_paths(plugin_paths
);
3716 * First pass: collect all arguments which need to be passed
3717 * as is to the run command. This pass can also add --name
3718 * arguments if needed to automatically name unnamed component
3719 * instances. Also it does the following transformations:
3721 * --path=PATH -> --key path --value PATH
3722 * --url=URL -> --key url --value URL
3724 * Also it appends the plugin paths of --plugin-path to
3727 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3728 convert_long_options
, 0);
3730 printf_err("Cannot get popt context\n");
3734 poptReadDefaultConfig(pc
, 0);
3736 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3738 char *plugin_name
= NULL
;
3739 char *comp_cls_name
= NULL
;
3741 arg
= poptGetOptArg(pc
);
3746 bt_component_class_type type
;
3747 const char *type_prefix
;
3749 /* Append current component's name if needed */
3750 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3751 cur_name_prefix
, run_args
, all_names
,
3752 &source_names
, &filter_names
, &sink_names
);
3757 /* Parse the argument */
3758 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3759 &comp_cls_name
, &type
);
3760 if (!plugin_name
|| !comp_cls_name
) {
3761 printf_err("Invalid format for --component option's argument:\n %s\n",
3767 g_string_assign(cur_name
, name
);
3769 g_string_assign(cur_name
, "");
3773 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3774 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3775 type_prefix
= "source";
3777 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3778 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
3779 type_prefix
= "filter";
3781 case BT_COMPONENT_CLASS_TYPE_SINK
:
3782 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3783 type_prefix
= "sink";
3789 if (bt_value_array_append_string_element(run_args
,
3795 if (bt_value_array_append_string_element(run_args
, arg
)) {
3800 g_string_assign(cur_name_prefix
, "");
3801 g_string_append_printf(cur_name_prefix
, "%s.%s.%s",
3802 type_prefix
, plugin_name
, comp_cls_name
);
3805 free(comp_cls_name
);
3808 comp_cls_name
= NULL
;
3812 if (cur_name_prefix
->len
== 0) {
3813 printf_err("No current component of which to set parameters:\n %s\n",
3818 if (bt_value_array_append_string_element(run_args
,
3824 if (bt_value_array_append_string_element(run_args
, arg
)) {
3830 if (cur_name_prefix
->len
== 0) {
3831 printf_err("No current component of which to set `path` parameter:\n %s\n",
3836 if (bt_value_array_append_string_element(run_args
, "--key")) {
3841 if (bt_value_array_append_string_element(run_args
, "path")) {
3846 if (bt_value_array_append_string_element(run_args
, "--value")) {
3851 if (bt_value_array_append_string_element(run_args
, arg
)) {
3857 if (cur_name_prefix
->len
== 0) {
3858 printf_err("No current component of which to set `url` parameter:\n %s\n",
3863 if (bt_value_array_append_string_element(run_args
, "--key")) {
3868 if (bt_value_array_append_string_element(run_args
, "url")) {
3873 if (bt_value_array_append_string_element(run_args
, "--value")) {
3878 if (bt_value_array_append_string_element(run_args
, arg
)) {
3884 if (cur_name_prefix
->len
== 0) {
3885 printf_err("No current component to name:\n %s\n",
3890 if (bt_value_array_append_string_element(run_args
, "--name")) {
3895 if (bt_value_array_append_string_element(run_args
, arg
)) {
3900 g_string_assign(cur_name
, arg
);
3902 case OPT_OMIT_HOME_PLUGIN_PATH
:
3903 force_omit_home_plugin_path
= true;
3905 if (bt_value_array_append_string_element(run_args
,
3906 "--omit-home-plugin-path")) {
3911 case OPT_RETRY_DURATION
:
3912 if (bt_value_array_append_string_element(run_args
,
3913 "--retry-duration")) {
3918 if (bt_value_array_append_string_element(run_args
, arg
)) {
3923 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3924 force_omit_system_plugin_path
= true;
3926 if (bt_value_array_append_string_element(run_args
,
3927 "--omit-system-plugin-path")) {
3932 case OPT_PLUGIN_PATH
:
3933 if (bt_config_append_plugin_paths_check_setuid_setgid(
3934 plugin_paths
, arg
)) {
3938 if (bt_value_array_append_string_element(run_args
,
3944 if (bt_value_array_append_string_element(run_args
, arg
)) {
3950 print_convert_usage(stdout
);
3952 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
3955 case OPT_CLOCK_CYCLES
:
3956 case OPT_CLOCK_DATE
:
3957 case OPT_CLOCK_FORCE_CORRELATE
:
3959 case OPT_CLOCK_OFFSET
:
3960 case OPT_CLOCK_OFFSET_NS
:
3961 case OPT_CLOCK_SECONDS
:
3964 case OPT_DEBUG_INFO
:
3965 case OPT_DEBUG_INFO_DIR
:
3966 case OPT_DEBUG_INFO_FULL_PATH
:
3967 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3970 case OPT_INPUT_FORMAT
:
3973 case OPT_OUTPUT_FORMAT
:
3976 case OPT_RUN_ARGS_0
:
3977 case OPT_STREAM_INTERSECTION
:
3980 /* Ignore in this pass */
3983 printf_err("Unknown command-line option specified (option code %d)\n",
3992 /* Append current component's name if needed */
3993 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3994 cur_name_prefix
, run_args
, all_names
, &source_names
,
3995 &filter_names
, &sink_names
);
4000 /* Check for option parsing error */
4002 printf_err("While parsing command-line options, at option %s: %s\n",
4003 poptBadOption(pc
, 0), poptStrerror(opt
));
4007 poptFreeContext(pc
);
4012 * Second pass: transform the convert-specific options and
4013 * arguments into implicit component instances for the run
4016 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
4017 convert_long_options
, 0);
4019 printf_err("Cannot get popt context\n");
4023 poptReadDefaultConfig(pc
, 0);
4025 while ((opt
= poptGetNextOpt(pc
)) > 0) {
4026 arg
= poptGetOptArg(pc
);
4030 if (trimmer_has_begin
) {
4031 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4036 trimmer_has_begin
= true;
4037 ret
= append_implicit_component_extra_param(
4038 &implicit_trimmer_args
, "begin", arg
);
4039 implicit_trimmer_args
.exists
= true;
4045 if (trimmer_has_end
) {
4046 printf("At --end option: --end or --timerange option already specified\n %s\n",
4051 trimmer_has_end
= true;
4052 ret
= append_implicit_component_extra_param(
4053 &implicit_trimmer_args
, "end", arg
);
4054 implicit_trimmer_args
.exists
= true;
4064 if (trimmer_has_begin
|| trimmer_has_end
) {
4065 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4070 ret
= split_timerange(arg
, &begin
, &end
);
4072 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4077 ret
= append_implicit_component_extra_param(
4078 &implicit_trimmer_args
, "begin", begin
);
4079 ret
|= append_implicit_component_extra_param(
4080 &implicit_trimmer_args
, "end", end
);
4081 implicit_trimmer_args
.exists
= true;
4089 case OPT_CLOCK_CYCLES
:
4090 append_implicit_component_param(
4091 &implicit_text_args
, "clock-cycles", "yes");
4092 implicit_text_args
.exists
= true;
4094 case OPT_CLOCK_DATE
:
4095 append_implicit_component_param(
4096 &implicit_text_args
, "clock-date", "yes");
4097 implicit_text_args
.exists
= true;
4099 case OPT_CLOCK_FORCE_CORRELATE
:
4100 append_implicit_component_param(
4101 &implicit_muxer_args
,
4102 "assume-absolute-clock-classes", "yes");
4105 append_implicit_component_param(
4106 &implicit_text_args
, "clock-gmt", "yes");
4107 append_implicit_component_param(
4108 &implicit_trimmer_args
, "gmt", "yes");
4109 implicit_text_args
.exists
= true;
4111 case OPT_CLOCK_OFFSET
:
4112 base_implicit_ctf_input_args
.exists
= true;
4113 append_implicit_component_param(
4114 &base_implicit_ctf_input_args
,
4115 "clock-class-offset-s", arg
);
4117 case OPT_CLOCK_OFFSET_NS
:
4118 base_implicit_ctf_input_args
.exists
= true;
4119 append_implicit_component_param(
4120 &base_implicit_ctf_input_args
,
4121 "clock-class-offset-ns", arg
);
4123 case OPT_CLOCK_SECONDS
:
4124 append_implicit_component_param(
4125 &implicit_text_args
, "clock-seconds", "yes");
4126 implicit_text_args
.exists
= true;
4129 implicit_text_args
.exists
= true;
4130 ret
= append_implicit_component_extra_param(
4131 &implicit_text_args
, "color", arg
);
4136 case OPT_DEBUG_INFO
:
4137 implicit_debug_info_args
.exists
= true;
4139 case OPT_DEBUG_INFO_DIR
:
4140 implicit_debug_info_args
.exists
= true;
4141 ret
= append_implicit_component_extra_param(
4142 &implicit_debug_info_args
, "debug-info-dir", arg
);
4147 case OPT_DEBUG_INFO_FULL_PATH
:
4148 implicit_debug_info_args
.exists
= true;
4149 append_implicit_component_param(
4150 &implicit_debug_info_args
, "full-path", "yes");
4152 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4153 implicit_debug_info_args
.exists
= true;
4154 ret
= append_implicit_component_extra_param(
4155 &implicit_debug_info_args
,
4156 "target-prefix", arg
);
4163 bt_value
*fields
= fields_from_arg(arg
);
4169 implicit_text_args
.exists
= true;
4170 ret
= insert_flat_params_from_array(
4171 implicit_text_args
.params_arg
,
4173 bt_value_put_ref(fields
);
4181 bt_value
*names
= names_from_arg(arg
);
4187 implicit_text_args
.exists
= true;
4188 ret
= insert_flat_params_from_array(
4189 implicit_text_args
.params_arg
,
4191 bt_value_put_ref(names
);
4198 append_implicit_component_param(
4199 &implicit_text_args
, "no-delta", "yes");
4200 implicit_text_args
.exists
= true;
4202 case OPT_INPUT_FORMAT
:
4203 if (got_input_format_opt
) {
4204 printf_err("Duplicate --input-format option\n");
4208 got_input_format_opt
= true;
4210 if (strcmp(arg
, "ctf") == 0) {
4211 base_implicit_ctf_input_args
.exists
= true;
4212 } else if (strcmp(arg
, "lttng-live") == 0) {
4213 implicit_lttng_live_args
.exists
= true;
4215 printf_err("Unknown legacy input format:\n %s\n",
4220 case OPT_OUTPUT_FORMAT
:
4221 if (got_output_format_opt
) {
4222 printf_err("Duplicate --output-format option\n");
4226 got_output_format_opt
= true;
4228 if (strcmp(arg
, "text") == 0) {
4229 implicit_text_args
.exists
= true;
4230 } else if (strcmp(arg
, "ctf") == 0) {
4231 implicit_ctf_output_args
.exists
= true;
4232 } else if (strcmp(arg
, "dummy") == 0) {
4233 implicit_dummy_args
.exists
= true;
4234 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4235 print_ctf_metadata
= true;
4237 printf_err("Unknown legacy output format:\n %s\n",
4244 printf_err("Duplicate --output option\n");
4248 output
= strdup(arg
);
4255 if (print_run_args_0
) {
4256 printf_err("Cannot specify --run-args and --run-args-0\n");
4260 print_run_args
= true;
4262 case OPT_RUN_ARGS_0
:
4263 if (print_run_args
) {
4264 printf_err("Cannot specify --run-args and --run-args-0\n");
4268 print_run_args_0
= true;
4270 case OPT_STREAM_INTERSECTION
:
4272 * Applies to all traces implementing the trace-info
4275 stream_intersection_mode
= true;
4278 if (*log_level
!= 'V' && *log_level
!= 'D') {
4291 /* Check for option parsing error */
4293 printf_err("While parsing command-line options, at option %s: %s\n",
4294 poptBadOption(pc
, 0), poptStrerror(opt
));
4299 * Legacy behaviour: --verbose used to make the `text` output
4300 * format print more information. --verbose is now equivalent to
4301 * the INFO log level, which is why we compare to 'I' here.
4303 if (*log_level
== 'I') {
4304 append_implicit_component_param(&implicit_text_args
,
4309 * Append home and system plugin paths now that we possibly got
4312 if (append_home_and_system_plugin_paths(plugin_paths
,
4313 force_omit_system_plugin_path
,
4314 force_omit_home_plugin_path
)) {
4318 /* Consume and keep leftover arguments */
4319 while ((leftover
= poptGetArg(pc
))) {
4320 GString
*gs_leftover
= g_string_new(leftover
);
4327 leftovers
= g_list_append(leftovers
, gs_leftover
);
4329 g_string_free(gs_leftover
, TRUE
);
4335 /* Print CTF metadata or print LTTng live sessions */
4336 if (print_ctf_metadata
) {
4337 GString
*gs_leftover
;
4339 if (g_list_length(leftovers
) == 0) {
4340 printf_err("--output-format=ctf-metadata specified without a path\n");
4344 if (g_list_length(leftovers
) > 1) {
4345 printf_err("Too many paths specified for --output-format=ctf-metadata\n");
4349 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4354 gs_leftover
= leftovers
->data
;
4355 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4360 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
4368 * If -o ctf was specified, make sure an output path (--output)
4369 * was also specified. --output does not imply -o ctf because
4370 * it's also used for the default, implicit -o text if -o ctf
4373 if (implicit_ctf_output_args
.exists
) {
4375 printf_err("--output-format=ctf specified without --output (trace output path)\n");
4380 * At this point we know that -o ctf AND --output were
4381 * specified. Make sure that no options were specified
4382 * which would imply -o text because --output would be
4383 * ambiguous in this case. For example, this is wrong:
4385 * babeltrace --names=all -o ctf --output=/tmp/path my-trace
4387 * because --names=all implies -o text, and --output
4388 * could apply to both the sink.text.pretty and
4389 * sink.ctf.fs implicit components.
4391 if (implicit_text_args
.exists
) {
4392 printf_err("Ambiguous --output option: --output-format=ctf specified but another option implies --output-format=text\n");
4398 * If -o dummy and -o ctf were not specified, and if there are
4399 * no explicit sink components, then use an implicit
4400 * `sink.text.pretty` component.
4402 if (!implicit_dummy_args
.exists
&& !implicit_ctf_output_args
.exists
&&
4404 implicit_text_args
.exists
= true;
4408 * Set implicit `sink.text.pretty` or `sink.ctf.fs` component's
4409 * `path` parameter if --output was specified.
4412 if (implicit_text_args
.exists
) {
4413 append_implicit_component_extra_param(&implicit_text_args
,
4415 } else if (implicit_ctf_output_args
.exists
) {
4416 append_implicit_component_extra_param(&implicit_ctf_output_args
,
4421 /* Decide where the leftover argument(s) go */
4422 if (g_list_length(leftovers
) > 0) {
4423 if (implicit_lttng_live_args
.exists
) {
4424 GString
*gs_leftover
;
4426 if (g_list_length(leftovers
) > 1) {
4427 printf_err("Too many URLs specified for --output-format=lttng-live\n");
4431 gs_leftover
= leftovers
->data
;
4432 lttng_live_url_parts
=
4433 bt_common_parse_lttng_live_url(gs_leftover
->str
,
4434 error_buf
, sizeof(error_buf
));
4435 if (!lttng_live_url_parts
.proto
) {
4436 printf_err("Invalid LTTng live URL format: %s\n",
4441 if (!lttng_live_url_parts
.session_name
) {
4442 /* Print LTTng live sessions */
4443 cfg
= bt_config_print_lttng_live_sessions_create(
4449 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4454 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
4461 ret
= append_implicit_component_extra_param(
4462 &implicit_lttng_live_args
, "url",
4469 * Append one implicit component argument set
4470 * for each leftover (souce.ctf.fs paths). Copy
4471 * the base implicit component arguments.
4472 * Note that they still have to be named later.
4474 ret
= fill_implicit_ctf_inputs_args(
4475 implicit_ctf_inputs_args
,
4476 &base_implicit_ctf_input_args
, leftovers
);
4484 * Ensure mutual exclusion between implicit `source.ctf.fs` and
4485 * `source.ctf.lttng-live` components.
4487 if (base_implicit_ctf_input_args
.exists
&&
4488 implicit_lttng_live_args
.exists
) {
4489 printf_err("Cannot create both implicit `%s` and `%s` components\n",
4490 base_implicit_ctf_input_args
.comp_arg
->str
,
4491 implicit_lttng_live_args
.comp_arg
->str
);
4496 * If the implicit `source.ctf.fs` or `source.ctf.lttng-live`
4497 * components exists, make sure there's at least one leftover
4498 * (which is the path or URL).
4500 if (base_implicit_ctf_input_args
.exists
&&
4501 g_list_length(leftovers
) == 0) {
4502 printf_err("Missing path for implicit `%s` component\n",
4503 base_implicit_ctf_input_args
.comp_arg
->str
);
4507 if (implicit_lttng_live_args
.exists
&& g_list_length(leftovers
) == 0) {
4508 printf_err("Missing URL for implicit `%s` component\n",
4509 implicit_lttng_live_args
.comp_arg
->str
);
4513 /* Assign names to implicit components */
4514 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4515 struct implicit_component_args
*impl_args
=
4516 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4518 ret
= assign_name_to_implicit_component(impl_args
,
4519 "source-ctf-fs", all_names
, &source_names
, true);
4525 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4526 "lttng-live", all_names
, &source_names
, true);
4531 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4532 "pretty", all_names
, &sink_names
, true);
4537 ret
= assign_name_to_implicit_component(&implicit_ctf_output_args
,
4538 "sink-ctf-fs", all_names
, &sink_names
, true);
4543 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4544 "dummy", all_names
, &sink_names
, true);
4549 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4550 "muxer", all_names
, NULL
, false);
4555 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4556 "trimmer", all_names
, NULL
, false);
4561 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4562 "debug-info", all_names
, NULL
, false);
4567 /* Make sure there's at least one source and one sink */
4568 if (!source_names
) {
4569 printf_err("No source component\n");
4574 printf_err("No sink component\n");
4579 * Prepend the muxer, the trimmer, and the debug info to the
4580 * filter chain so that we have:
4582 * sources -> muxer -> [trimmer] -> [debug info] ->
4583 * [user filters] -> sinks
4585 if (implicit_debug_info_args
.exists
) {
4586 if (g_list_prepend_gstring(&filter_names
,
4587 implicit_debug_info_args
.name_arg
->str
)) {
4592 if (implicit_trimmer_args
.exists
) {
4593 if (g_list_prepend_gstring(&filter_names
,
4594 implicit_trimmer_args
.name_arg
->str
)) {
4599 if (g_list_prepend_gstring(&filter_names
,
4600 implicit_muxer_args
.name_arg
->str
)) {
4605 * Append the equivalent run arguments for the implicit
4608 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4609 struct implicit_component_args
*impl_args
=
4610 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4612 ret
= append_run_args_for_implicit_component(impl_args
,
4619 ret
= append_run_args_for_implicit_component(&implicit_lttng_live_args
,
4625 ret
= append_run_args_for_implicit_component(&implicit_text_args
,
4631 ret
= append_run_args_for_implicit_component(&implicit_ctf_output_args
,
4637 ret
= append_run_args_for_implicit_component(&implicit_dummy_args
,
4643 ret
= append_run_args_for_implicit_component(&implicit_muxer_args
,
4649 ret
= append_run_args_for_implicit_component(&implicit_trimmer_args
,
4655 ret
= append_run_args_for_implicit_component(&implicit_debug_info_args
,
4661 /* Auto-connect components */
4662 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4665 printf_err("Cannot auto-connect components\n");
4670 * We have all the run command arguments now. Depending on
4671 * --run-args, we pass this to the run command or print them
4674 if (print_run_args
|| print_run_args_0
) {
4675 if (stream_intersection_mode
) {
4676 printf_err("Cannot specify --stream-intersection with --run-args or --run-args-0\n");
4680 for (i
= 0; i
< bt_value_array_get_size(run_args
); i
++) {
4681 const bt_value
*arg_value
=
4682 bt_value_array_borrow_element_by_index(run_args
,
4685 GString
*quoted
= NULL
;
4686 const char *arg_to_print
;
4688 BT_ASSERT(arg_value
);
4689 arg
= bt_value_string_get(arg_value
);
4691 if (print_run_args
) {
4692 quoted
= bt_common_shell_quote(arg
, true);
4697 arg_to_print
= quoted
->str
;
4702 printf("%s", arg_to_print
);
4705 g_string_free(quoted
, TRUE
);
4708 if (i
< bt_value_array_get_size(run_args
) - 1) {
4709 if (print_run_args
) {
4718 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4722 cfg
= bt_config_run_from_args_array(run_args
, retcode
,
4723 force_omit_system_plugin_path
,
4724 force_omit_home_plugin_path
,
4725 initial_plugin_paths
);
4730 cfg
->cmd_data
.run
.stream_intersection_mode
= stream_intersection_mode
;
4735 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4739 poptFreeContext(pc
);
4746 g_string_free(cur_name
, TRUE
);
4749 if (cur_name_prefix
) {
4750 g_string_free(cur_name_prefix
, TRUE
);
4753 if (implicit_ctf_inputs_args
) {
4754 g_ptr_array_free(implicit_ctf_inputs_args
, TRUE
);
4757 bt_value_put_ref(run_args
);
4758 bt_value_put_ref(all_names
);
4759 destroy_glist_of_gstring(source_names
);
4760 destroy_glist_of_gstring(filter_names
);
4761 destroy_glist_of_gstring(sink_names
);
4762 destroy_glist_of_gstring(leftovers
);
4763 finalize_implicit_component_args(&base_implicit_ctf_input_args
);
4764 finalize_implicit_component_args(&implicit_ctf_output_args
);
4765 finalize_implicit_component_args(&implicit_lttng_live_args
);
4766 finalize_implicit_component_args(&implicit_dummy_args
);
4767 finalize_implicit_component_args(&implicit_text_args
);
4768 finalize_implicit_component_args(&implicit_debug_info_args
);
4769 finalize_implicit_component_args(&implicit_muxer_args
);
4770 finalize_implicit_component_args(&implicit_trimmer_args
);
4771 bt_value_put_ref(plugin_paths
);
4772 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4777 * Prints the Babeltrace 2.x general usage.
4780 void print_gen_usage(FILE *fp
)
4782 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4784 fprintf(fp
, "General options:\n");
4786 fprintf(fp
, " -d, --debug Enable debug mode (same as --log-level=V)\n");
4787 fprintf(fp
, " -h, --help Show this help and quit\n");
4788 fprintf(fp
, " -l, --log-level=LVL Set all log levels to LVL (`N`, `V`, `D`,\n");
4789 fprintf(fp
, " `I`, `W` (default), `E`, or `F`)\n");
4790 fprintf(fp
, " -v, --verbose Enable verbose mode (same as --log-level=I)\n");
4791 fprintf(fp
, " -V, --version Show version and quit\n");
4793 fprintf(fp
, "Available commands:\n");
4795 fprintf(fp
, " convert Convert and trim traces (default)\n");
4796 fprintf(fp
, " help Get help for a plugin or a component class\n");
4797 fprintf(fp
, " list-plugins List available plugins and their content\n");
4798 fprintf(fp
, " query Query objects from a component class\n");
4799 fprintf(fp
, " run Build a processing graph and run it\n");
4801 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4805 char log_level_from_arg(const char *arg
)
4809 if (strcmp(arg
, "VERBOSE") == 0 ||
4810 strcmp(arg
, "V") == 0) {
4812 } else if (strcmp(arg
, "DEBUG") == 0 ||
4813 strcmp(arg
, "D") == 0) {
4815 } else if (strcmp(arg
, "INFO") == 0 ||
4816 strcmp(arg
, "I") == 0) {
4818 } else if (strcmp(arg
, "WARN") == 0 ||
4819 strcmp(arg
, "WARNING") == 0 ||
4820 strcmp(arg
, "W") == 0) {
4822 } else if (strcmp(arg
, "ERROR") == 0 ||
4823 strcmp(arg
, "E") == 0) {
4825 } else if (strcmp(arg
, "FATAL") == 0 ||
4826 strcmp(arg
, "F") == 0) {
4828 } else if (strcmp(arg
, "NONE") == 0 ||
4829 strcmp(arg
, "N") == 0) {
4836 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4837 int *retcode
, bool force_omit_system_plugin_path
,
4838 bool force_omit_home_plugin_path
,
4839 const bt_value
*initial_plugin_paths
)
4841 struct bt_config
*config
= NULL
;
4843 const char **command_argv
= NULL
;
4844 int command_argc
= -1;
4845 const char *command_name
= NULL
;
4846 char log_level
= 'U';
4849 COMMAND_TYPE_NONE
= -1,
4850 COMMAND_TYPE_RUN
= 0,
4851 COMMAND_TYPE_CONVERT
,
4852 COMMAND_TYPE_LIST_PLUGINS
,
4855 } command_type
= COMMAND_TYPE_NONE
;
4859 if (!initial_plugin_paths
) {
4860 initial_plugin_paths
= bt_value_array_create();
4861 if (!initial_plugin_paths
) {
4866 bt_value_get_ref(initial_plugin_paths
);
4872 print_gen_usage(stdout
);
4876 for (i
= 1; i
< argc
; i
++) {
4877 const char *cur_arg
= argv
[i
];
4878 const char *next_arg
= i
== (argc
- 1) ? NULL
: argv
[i
+ 1];
4880 if (strcmp(cur_arg
, "-d") == 0 ||
4881 strcmp(cur_arg
, "--debug") == 0) {
4883 } else if (strcmp(cur_arg
, "-v") == 0 ||
4884 strcmp(cur_arg
, "--verbose") == 0) {
4885 if (log_level
!= 'V' && log_level
!= 'D') {
4887 * Legacy: do not override a previous
4888 * --debug because --verbose and --debug
4889 * can be specified together (in this
4890 * case we want the lowest log level to
4895 } else if (strcmp(cur_arg
, "--log-level") == 0 ||
4896 strcmp(cur_arg
, "-l") == 0) {
4898 printf_err("Missing log level value for --log-level option\n");
4903 log_level
= log_level_from_arg(next_arg
);
4904 if (log_level
== 'U') {
4905 printf_err("Invalid argument for --log-level option:\n %s\n",
4912 } else if (strncmp(cur_arg
, "--log-level=", 12) == 0) {
4913 const char *arg
= &cur_arg
[12];
4915 log_level
= log_level_from_arg(arg
);
4916 if (log_level
== 'U') {
4917 printf_err("Invalid argument for --log-level option:\n %s\n",
4922 } else if (strncmp(cur_arg
, "-l", 2) == 0) {
4923 const char *arg
= &cur_arg
[2];
4925 log_level
= log_level_from_arg(arg
);
4926 if (log_level
== 'U') {
4927 printf_err("Invalid argument for --log-level option:\n %s\n",
4932 } else if (strcmp(cur_arg
, "-V") == 0 ||
4933 strcmp(cur_arg
, "--version") == 0) {
4936 } else if (strcmp(cur_arg
, "-h") == 0 ||
4937 strcmp(cur_arg
, "--help") == 0) {
4938 print_gen_usage(stdout
);
4942 * First unknown argument: is it a known command
4945 command_argv
= &argv
[i
];
4946 command_argc
= argc
- i
;
4948 if (strcmp(cur_arg
, "convert") == 0) {
4949 command_type
= COMMAND_TYPE_CONVERT
;
4950 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4951 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4952 } else if (strcmp(cur_arg
, "help") == 0) {
4953 command_type
= COMMAND_TYPE_HELP
;
4954 } else if (strcmp(cur_arg
, "query") == 0) {
4955 command_type
= COMMAND_TYPE_QUERY
;
4956 } else if (strcmp(cur_arg
, "run") == 0) {
4957 command_type
= COMMAND_TYPE_RUN
;
4960 * Unknown argument, but not a known
4961 * command name: assume the default
4962 * `convert` command.
4964 command_type
= COMMAND_TYPE_CONVERT
;
4965 command_name
= "convert";
4966 command_argv
= &argv
[i
- 1];
4967 command_argc
= argc
- i
+ 1;
4973 if (command_type
== COMMAND_TYPE_NONE
) {
4975 * We only got non-help, non-version general options
4976 * like --verbose and --debug, without any other
4977 * arguments, so we can't do anything useful: print the
4980 print_gen_usage(stdout
);
4984 BT_ASSERT(command_argv
);
4985 BT_ASSERT(command_argc
>= 0);
4987 switch (command_type
) {
4988 case COMMAND_TYPE_RUN
:
4989 config
= bt_config_run_from_args(command_argc
, command_argv
,
4990 retcode
, force_omit_system_plugin_path
,
4991 force_omit_home_plugin_path
, initial_plugin_paths
);
4993 case COMMAND_TYPE_CONVERT
:
4994 config
= bt_config_convert_from_args(command_argc
, command_argv
,
4995 retcode
, force_omit_system_plugin_path
,
4996 force_omit_home_plugin_path
,
4997 initial_plugin_paths
, &log_level
);
4999 case COMMAND_TYPE_LIST_PLUGINS
:
5000 config
= bt_config_list_plugins_from_args(command_argc
,
5001 command_argv
, retcode
, force_omit_system_plugin_path
,
5002 force_omit_home_plugin_path
, initial_plugin_paths
);
5004 case COMMAND_TYPE_HELP
:
5005 config
= bt_config_help_from_args(command_argc
,
5006 command_argv
, retcode
, force_omit_system_plugin_path
,
5007 force_omit_home_plugin_path
, initial_plugin_paths
);
5009 case COMMAND_TYPE_QUERY
:
5010 config
= bt_config_query_from_args(command_argc
,
5011 command_argv
, retcode
, force_omit_system_plugin_path
,
5012 force_omit_home_plugin_path
, initial_plugin_paths
);
5019 if (log_level
== 'U') {
5023 config
->log_level
= log_level
;
5024 config
->command_name
= command_name
;
5028 bt_value_put_ref(initial_plugin_paths
);