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>
37 #include <babeltrace/values.h>
40 #include <sys/types.h>
41 #include "babeltrace-cfg.h"
42 #include "babeltrace-cfg-cli-args.h"
43 #include "babeltrace-cfg-cli-args-connect.h"
47 * Error printf() macro which prepends "Error: " the first time it's
48 * called. This gives a nicer feel than having a bunch of error prefixes
49 * (since the following lines usually describe the error and possible
50 * solutions), or the error prefix just at the end.
52 #define printf_err(fmt, args...) \
54 if (is_first_error) { \
55 fprintf(stderr, "Command line error: "); \
56 is_first_error = false; \
58 fprintf(stderr, fmt, ##args); \
61 static bool is_first_error
= true;
63 /* INI-style parsing FSM states */
64 enum ini_parsing_fsm_state
{
65 /* Expect a map key (identifier) */
68 /* Expect an equal character ('=') */
74 /* Expect a negative number value */
75 INI_EXPECT_VALUE_NUMBER_NEG
,
77 /* Expect a comma character (',') */
81 /* INI-style parsing state variables */
82 struct ini_parsing_state
{
83 /* Lexical scanner (owned by this) */
86 /* Output map value object being filled (owned by this) */
87 struct bt_value
*params
;
89 /* Next expected FSM state */
90 enum ini_parsing_fsm_state expecting
;
92 /* Last decoded map key (owned by this) */
95 /* Complete INI-style string to parse (not owned by this) */
98 /* Error buffer (not owned by this) */
102 /* Offset option with "is set" boolean */
108 /* Legacy "ctf"/"lttng-live" format options */
109 struct ctf_legacy_opts
{
110 struct offset_opt offset_s
;
111 struct offset_opt offset_ns
;
112 bool stream_intersection
;
115 /* Legacy "text" format options */
116 struct text_legacy_opts
{
118 * output, dbg_info_dir, dbg_info_target_prefix, names,
119 * and fields are owned by this.
122 GString
*dbg_info_dir
;
123 GString
*dbg_info_target_prefix
;
124 struct bt_value
*names
;
125 struct bt_value
*fields
;
133 bool dbg_info_full_path
;
137 /* Legacy input format format */
138 enum legacy_input_format
{
139 LEGACY_INPUT_FORMAT_NONE
= 0,
140 LEGACY_INPUT_FORMAT_CTF
,
141 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
144 /* Legacy output format format */
145 enum legacy_output_format
{
146 LEGACY_OUTPUT_FORMAT_NONE
= 0,
147 LEGACY_OUTPUT_FORMAT_TEXT
,
148 LEGACY_OUTPUT_FORMAT_DUMMY
,
152 * Prints the "out of memory" error.
155 void print_err_oom(void)
157 printf_err("Out of memory\n");
161 * Appends an "expecting token" error to the INI-style parsing state's
165 void ini_append_error_expecting(struct ini_parsing_state
*state
,
166 GScanner
*scanner
, const char *expecting
)
171 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
173 /* Only print error if there's one line */
174 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
178 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
179 pos
= g_scanner_cur_position(scanner
) + 4;
181 if (!g_scanner_eof(scanner
)) {
185 for (i
= 0; i
< pos
; ++i
) {
186 g_string_append_printf(state
->ini_error
, " ");
189 g_string_append_printf(state
->ini_error
, "^\n\n");
193 int ini_handle_state(struct ini_parsing_state
*state
)
196 GTokenType token_type
;
197 struct bt_value
*value
= NULL
;
199 token_type
= g_scanner_get_next_token(state
->scanner
);
200 if (token_type
== G_TOKEN_EOF
) {
201 if (state
->expecting
!= INI_EXPECT_COMMA
) {
202 switch (state
->expecting
) {
203 case INI_EXPECT_EQUAL
:
204 ini_append_error_expecting(state
,
205 state
->scanner
, "'='");
207 case INI_EXPECT_VALUE
:
208 case INI_EXPECT_VALUE_NUMBER_NEG
:
209 ini_append_error_expecting(state
,
210 state
->scanner
, "value");
212 case INI_EXPECT_MAP_KEY
:
213 ini_append_error_expecting(state
,
214 state
->scanner
, "unquoted map key");
227 switch (state
->expecting
) {
228 case INI_EXPECT_MAP_KEY
:
229 if (token_type
!= G_TOKEN_IDENTIFIER
) {
230 ini_append_error_expecting(state
, state
->scanner
,
235 free(state
->last_map_key
);
236 state
->last_map_key
=
237 strdup(state
->scanner
->value
.v_identifier
);
238 if (!state
->last_map_key
) {
239 g_string_append(state
->ini_error
,
244 if (bt_value_map_has_entry(state
->params
, state
->last_map_key
)) {
245 g_string_append_printf(state
->ini_error
,
246 "Duplicate parameter key: `%s`\n",
247 state
->last_map_key
);
251 state
->expecting
= INI_EXPECT_EQUAL
;
253 case INI_EXPECT_EQUAL
:
254 if (token_type
!= G_TOKEN_CHAR
) {
255 ini_append_error_expecting(state
,
256 state
->scanner
, "'='");
260 if (state
->scanner
->value
.v_char
!= '=') {
261 ini_append_error_expecting(state
,
262 state
->scanner
, "'='");
266 state
->expecting
= INI_EXPECT_VALUE
;
268 case INI_EXPECT_VALUE
:
270 switch (token_type
) {
272 if (state
->scanner
->value
.v_char
== '-') {
273 /* Negative number */
275 INI_EXPECT_VALUE_NUMBER_NEG
;
278 ini_append_error_expecting(state
,
279 state
->scanner
, "value");
285 /* Positive integer */
286 uint64_t int_val
= state
->scanner
->value
.v_int64
;
288 if (int_val
> (1ULL << 63) - 1) {
289 g_string_append_printf(state
->ini_error
,
290 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
295 value
= bt_value_integer_create_init(
300 /* Positive floating point number */
301 value
= bt_value_real_create_init(
302 state
->scanner
->value
.v_float
);
306 value
= bt_value_string_create_init(
307 state
->scanner
->value
.v_string
);
309 case G_TOKEN_IDENTIFIER
:
312 * Using symbols would be appropriate here,
313 * but said symbols are allowed as map key,
314 * so it's easier to consider everything an
317 * If one of the known symbols is not
318 * recognized here, then fall back to creating
321 const char *id
= state
->scanner
->value
.v_identifier
;
323 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
324 !strcmp(id
, "nul")) {
325 value
= bt_value_null
;
326 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
327 !strcmp(id
, "yes") ||
328 !strcmp(id
, "YES")) {
329 value
= bt_value_bool_create_init(true);
330 } else if (!strcmp(id
, "false") ||
331 !strcmp(id
, "FALSE") ||
334 value
= bt_value_bool_create_init(false);
336 value
= bt_value_string_create_init(id
);
341 /* Unset value variable will trigger the error */
346 ini_append_error_expecting(state
,
347 state
->scanner
, "value");
351 state
->expecting
= INI_EXPECT_COMMA
;
354 case INI_EXPECT_VALUE_NUMBER_NEG
:
356 switch (token_type
) {
359 /* Negative integer */
360 uint64_t int_val
= state
->scanner
->value
.v_int64
;
362 if (int_val
> (1ULL << 63) - 1) {
363 g_string_append_printf(state
->ini_error
,
364 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
369 value
= bt_value_integer_create_init(
370 -((int64_t) int_val
));
374 /* Negative floating point number */
375 value
= bt_value_real_create_init(
376 -state
->scanner
->value
.v_float
);
379 /* Unset value variable will trigger the error */
384 ini_append_error_expecting(state
,
385 state
->scanner
, "value");
389 state
->expecting
= INI_EXPECT_COMMA
;
392 case INI_EXPECT_COMMA
:
393 if (token_type
!= G_TOKEN_CHAR
) {
394 ini_append_error_expecting(state
,
395 state
->scanner
, "','");
399 if (state
->scanner
->value
.v_char
!= ',') {
400 ini_append_error_expecting(state
,
401 state
->scanner
, "','");
405 state
->expecting
= INI_EXPECT_MAP_KEY
;
417 if (bt_value_map_insert_entry(state
->params
,
418 state
->last_map_key
, value
)) {
419 /* Only override return value on error */
425 BT_OBJECT_PUT_REF_AND_RESET(value
);
430 * Converts an INI-style argument to an equivalent map value object.
432 * Return value is owned by the caller.
435 struct bt_value
*bt_value_from_ini(const char *arg
, GString
*ini_error
)
437 /* Lexical scanner configuration */
438 GScannerConfig scanner_config
= {
439 /* Skip whitespaces */
440 .cset_skip_characters
= " \t\n",
442 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
443 .cset_identifier_first
=
447 .cset_identifier_nth
=
452 /* "hello" and "Hello" two different keys */
453 .case_sensitive
= TRUE
,
456 .cpair_comment_single
= NULL
,
457 .skip_comment_multi
= TRUE
,
458 .skip_comment_single
= TRUE
,
459 .scan_comment_multi
= FALSE
,
462 * Do scan identifiers, including 1-char identifiers,
463 * but NULL is a normal identifier.
465 .scan_identifier
= TRUE
,
466 .scan_identifier_1char
= TRUE
,
467 .scan_identifier_NULL
= FALSE
,
470 * No specific symbols: null and boolean "symbols" are
471 * scanned as plain identifiers.
473 .scan_symbols
= FALSE
,
474 .symbol_2_token
= FALSE
,
475 .scope_0_fallback
= FALSE
,
478 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
479 * integers prefixed with "$".
485 .scan_hex_dollar
= FALSE
,
487 /* Convert scanned numbers to integer tokens */
488 .numbers_2_int
= TRUE
,
490 /* Support both integers and floating-point numbers */
491 .int_2_float
= FALSE
,
493 /* Scan integers as 64-bit signed integers */
496 /* Only scan double-quoted strings */
497 .scan_string_sq
= FALSE
,
498 .scan_string_dq
= TRUE
,
500 /* Do not converter identifiers to string tokens */
501 .identifier_2_string
= FALSE
,
503 /* Scan characters as G_TOKEN_CHAR token */
504 .char_2_token
= FALSE
,
506 struct ini_parsing_state state
= {
509 .expecting
= INI_EXPECT_MAP_KEY
,
511 .ini_error
= ini_error
,
514 state
.params
= bt_value_map_create();
519 state
.scanner
= g_scanner_new(&scanner_config
);
520 if (!state
.scanner
) {
524 /* Let the scan begin */
525 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
528 int ret
= ini_handle_state(&state
);
533 } else if (ret
> 0) {
542 BT_OBJECT_PUT_REF_AND_RESET(state
.params
);
546 g_scanner_destroy(state
.scanner
);
549 free(state
.last_map_key
);
554 * Returns the parameters map value object from a command-line
555 * parameter option's argument.
557 * Return value is owned by the caller.
560 struct bt_value
*bt_value_from_arg(const char *arg
)
562 struct bt_value
*params
= NULL
;
563 GString
*ini_error
= NULL
;
565 ini_error
= g_string_new(NULL
);
571 /* Try INI-style parsing */
572 params
= bt_value_from_ini(arg
, ini_error
);
574 printf_err("%s", ini_error
->str
);
580 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
, enum 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(struct 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_OBJECT_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 enum 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 enum 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(struct bt_object
*obj
)
874 struct bt_config
*cfg
=
875 container_of(obj
, struct bt_config
, base
);
881 BT_OBJECT_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 struct bt_value
*names_from_arg(const char *arg
)
1015 GScanner
*scanner
= NULL
;
1016 struct 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_OBJECT_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 struct bt_value
*fields_from_arg(const char *arg
)
1127 GScanner
*scanner
= NULL
;
1128 struct bt_value
*fields
;
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_OBJECT_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 struct 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 struct bt_value
*str_obj
=
1245 bt_value_array_borrow_element_by_index(names_array
, i
);
1247 bool is_default
= false;
1250 printf_err("Unexpected error\n");
1255 ret
= bt_value_string_get(str_obj
, &suffix
);
1257 printf_err("Unexpected error\n");
1261 g_string_assign(tmpstr
, prefix
);
1262 g_string_append(tmpstr
, "-");
1264 /* Special-case for "all" and "none". */
1265 if (!strcmp(suffix
, "all")) {
1267 g_string_assign(default_value
, "show");
1268 } else if (!strcmp(suffix
, "none")) {
1270 g_string_assign(default_value
, "hide");
1274 g_string_append(tmpstr
, "default");
1275 append_param_arg(params_arg
, tmpstr
->str
,
1276 default_value
->str
);
1278 non_default_set
= true;
1279 g_string_append(tmpstr
, suffix
);
1280 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1284 /* Implicit field-default=hide if any non-default option is set. */
1285 if (non_default_set
&& !default_set
) {
1286 g_string_assign(tmpstr
, prefix
);
1287 g_string_append(tmpstr
, "-default");
1288 g_string_assign(default_value
, "hide");
1289 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1293 if (default_value
) {
1294 g_string_free(default_value
, TRUE
);
1298 g_string_free(tmpstr
, TRUE
);
1311 OPT_CLOCK_FORCE_CORRELATE
,
1314 OPT_CLOCK_OFFSET_NS
,
1322 OPT_DEBUG_INFO_FULL_PATH
,
1323 OPT_DEBUG_INFO_TARGET_PREFIX
,
1333 OPT_OMIT_HOME_PLUGIN_PATH
,
1334 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1340 OPT_RESET_BASE_PARAMS
,
1344 OPT_STREAM_INTERSECTION
,
1351 enum bt_config_component_dest
{
1352 BT_CONFIG_COMPONENT_DEST_UNKNOWN
= -1,
1353 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1354 BT_CONFIG_COMPONENT_DEST_FILTER
,
1355 BT_CONFIG_COMPONENT_DEST_SINK
,
1359 * Adds a configuration component to the appropriate configuration
1360 * array depending on the destination.
1363 void add_run_cfg_comp(struct bt_config
*cfg
,
1364 struct bt_config_component
*cfg_comp
,
1365 enum bt_config_component_dest dest
)
1367 bt_object_get_ref(cfg_comp
);
1370 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1371 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1373 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1374 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1376 case BT_CONFIG_COMPONENT_DEST_SINK
:
1377 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1385 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1386 struct bt_config_component
*cfg_comp
,
1387 enum bt_config_component_dest dest
,
1388 struct bt_value
*instance_names
)
1392 if (cfg_comp
->instance_name
->len
== 0) {
1393 printf_err("Found an unnamed component\n");
1398 if (bt_value_map_has_entry(instance_names
, cfg_comp
->instance_name
->str
)) {
1399 printf_err("Duplicate component instance name:\n %s\n",
1400 cfg_comp
->instance_name
->str
);
1405 if (bt_value_map_insert_entry(instance_names
,
1406 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1412 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1419 int append_env_var_plugin_paths(struct bt_value
*plugin_paths
)
1424 if (bt_common_is_setuid_setgid()) {
1425 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1429 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1434 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1438 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1445 int append_home_and_system_plugin_paths(struct bt_value
*plugin_paths
,
1446 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1450 if (!omit_home_plugin_path
) {
1451 if (bt_common_is_setuid_setgid()) {
1452 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1454 char *home_plugin_dir
=
1455 bt_common_get_home_plugin_path();
1457 if (home_plugin_dir
) {
1458 ret
= bt_config_append_plugin_paths(
1459 plugin_paths
, home_plugin_dir
);
1460 free(home_plugin_dir
);
1463 printf_err("Invalid home plugin path\n");
1470 if (!omit_system_plugin_path
) {
1471 if (bt_config_append_plugin_paths(plugin_paths
,
1472 bt_common_get_system_plugin_path())) {
1473 printf_err("Invalid system plugin path\n");
1479 printf_err("Cannot append home and system plugin paths\n");
1484 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1486 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1487 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1491 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1492 struct bt_value
*initial_plugin_paths
, bool needs_plugins
)
1494 struct bt_config
*cfg
;
1497 cfg
= g_new0(struct bt_config
, 1);
1503 bt_object_init_shared(&cfg
->base
, bt_config_destroy
);
1504 cfg
->command
= command
;
1505 cfg
->command_needs_plugins
= needs_plugins
;
1507 if (initial_plugin_paths
) {
1508 cfg
->plugin_paths
= bt_object_get_ref(initial_plugin_paths
);
1510 cfg
->plugin_paths
= bt_value_array_create();
1511 if (!cfg
->plugin_paths
) {
1520 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1527 struct bt_config
*bt_config_run_create(
1528 struct bt_value
*initial_plugin_paths
)
1530 struct bt_config
*cfg
;
1533 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1534 initial_plugin_paths
, true);
1539 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1540 (GDestroyNotify
) bt_object_put_ref
);
1541 if (!cfg
->cmd_data
.run
.sources
) {
1546 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1547 (GDestroyNotify
) bt_object_put_ref
);
1548 if (!cfg
->cmd_data
.run
.filters
) {
1553 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1554 (GDestroyNotify
) bt_object_put_ref
);
1555 if (!cfg
->cmd_data
.run
.sinks
) {
1560 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1561 (GDestroyNotify
) bt_config_connection_destroy
);
1562 if (!cfg
->cmd_data
.run
.connections
) {
1570 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1577 struct bt_config
*bt_config_list_plugins_create(
1578 struct bt_value
*initial_plugin_paths
)
1580 struct bt_config
*cfg
;
1583 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1584 initial_plugin_paths
, true);
1592 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1599 struct bt_config
*bt_config_help_create(
1600 struct bt_value
*initial_plugin_paths
)
1602 struct bt_config
*cfg
;
1605 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1606 initial_plugin_paths
, true);
1611 cfg
->cmd_data
.help
.cfg_component
=
1612 bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN
,
1614 if (!cfg
->cmd_data
.help
.cfg_component
) {
1621 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1628 struct bt_config
*bt_config_query_create(
1629 struct bt_value
*initial_plugin_paths
)
1631 struct bt_config
*cfg
;
1634 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1635 initial_plugin_paths
, true);
1640 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1641 if (!cfg
->cmd_data
.query
.object
) {
1649 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1656 struct bt_config
*bt_config_print_ctf_metadata_create(
1657 struct bt_value
*initial_plugin_paths
)
1659 struct bt_config
*cfg
;
1662 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1663 initial_plugin_paths
, true);
1668 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1669 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1674 cfg
->cmd_data
.print_ctf_metadata
.output_path
= g_string_new(NULL
);
1675 if (!cfg
->cmd_data
.print_ctf_metadata
.output_path
) {
1683 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1690 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1691 struct bt_value
*initial_plugin_paths
)
1693 struct bt_config
*cfg
;
1696 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1697 initial_plugin_paths
, true);
1702 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1703 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1708 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
=
1710 if (!cfg
->cmd_data
.print_lttng_live_sessions
.output_path
) {
1718 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1725 int bt_config_append_plugin_paths_check_setuid_setgid(
1726 struct bt_value
*plugin_paths
, const char *arg
)
1730 if (bt_common_is_setuid_setgid()) {
1731 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1735 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1736 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1747 * Prints the expected format for a --params option.
1750 void print_expected_params_format(FILE *fp
)
1752 fprintf(fp
, "Expected format of PARAMS\n");
1753 fprintf(fp
, "-------------------------\n");
1755 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1757 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1758 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1759 fprintf(fp
, "and VALUE can be one of:\n");
1761 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1762 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1763 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1764 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1765 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1766 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1767 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1768 fprintf(fp
, " the null and boolean value symbols above.\n");
1769 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1771 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1773 fprintf(fp
, "Example:\n");
1775 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1776 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1777 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1779 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1780 fprintf(fp
, "babeltrace from a shell.\n");
1785 * Prints the help command usage.
1788 void print_help_usage(FILE *fp
)
1790 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1791 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] TYPE.PLUGIN.CLS\n");
1793 fprintf(fp
, "Options:\n");
1795 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1796 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1797 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1798 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1799 fprintf(fp
, " dynamic plugins can be loaded\n");
1800 fprintf(fp
, " -h, --help Show this help and quit\n");
1802 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1804 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1808 struct poptOption help_long_options
[] = {
1809 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1810 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1811 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1812 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1813 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1814 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1818 * Creates a Babeltrace config object from the arguments of a help
1821 * *retcode is set to the appropriate exit code to use.
1824 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1825 int *retcode
, bool force_omit_system_plugin_path
,
1826 bool force_omit_home_plugin_path
,
1827 struct bt_value
*initial_plugin_paths
)
1829 poptContext pc
= NULL
;
1833 struct bt_config
*cfg
= NULL
;
1834 const char *leftover
;
1835 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1838 cfg
= bt_config_help_create(initial_plugin_paths
);
1843 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1844 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1845 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1851 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1852 help_long_options
, 0);
1854 printf_err("Cannot get popt context\n");
1858 poptReadDefaultConfig(pc
, 0);
1860 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1861 arg
= poptGetOptArg(pc
);
1864 case OPT_PLUGIN_PATH
:
1865 if (bt_config_append_plugin_paths_check_setuid_setgid(
1866 cfg
->plugin_paths
, arg
)) {
1870 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1871 cfg
->omit_system_plugin_path
= true;
1873 case OPT_OMIT_HOME_PLUGIN_PATH
:
1874 cfg
->omit_home_plugin_path
= true;
1877 print_help_usage(stdout
);
1879 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1882 printf_err("Unknown command-line option specified (option code %d)\n",
1891 /* Check for option parsing error */
1893 printf_err("While parsing command-line options, at option %s: %s\n",
1894 poptBadOption(pc
, 0), poptStrerror(opt
));
1898 leftover
= poptGetArg(pc
);
1900 plugin_comp_cls_names(leftover
, NULL
,
1901 &plugin_name
, &comp_cls_name
,
1902 &cfg
->cmd_data
.help
.cfg_component
->type
);
1903 if (plugin_name
&& comp_cls_name
) {
1904 /* Component class help */
1906 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1909 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1912 /* Fall back to plugin help */
1913 cfg
->cmd_data
.help
.cfg_component
->type
=
1914 BT_COMPONENT_CLASS_TYPE_UNKNOWN
;
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 struct bt_value
*initial_plugin_paths
)
1993 poptContext pc
= NULL
;
1997 struct bt_config
*cfg
= NULL
;
1998 const char *leftover
;
1999 struct bt_value
*params
= bt_value_null
;
2002 cfg
= bt_config_query_create(initial_plugin_paths
);
2007 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2008 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2009 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2015 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2016 query_long_options
, 0);
2018 printf_err("Cannot get popt context\n");
2022 poptReadDefaultConfig(pc
, 0);
2024 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2025 arg
= poptGetOptArg(pc
);
2028 case OPT_PLUGIN_PATH
:
2029 if (bt_config_append_plugin_paths_check_setuid_setgid(
2030 cfg
->plugin_paths
, arg
)) {
2034 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2035 cfg
->omit_system_plugin_path
= true;
2037 case OPT_OMIT_HOME_PLUGIN_PATH
:
2038 cfg
->omit_home_plugin_path
= true;
2042 bt_object_put_ref(params
);
2043 params
= bt_value_from_arg(arg
);
2045 printf_err("Invalid format for --params option's argument:\n %s\n",
2052 print_query_usage(stdout
);
2054 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2057 printf_err("Unknown command-line option specified (option code %d)\n",
2066 /* Check for option parsing error */
2068 printf_err("While parsing command-line options, at option %s: %s\n",
2069 poptBadOption(pc
, 0), poptStrerror(opt
));
2074 * We need exactly two leftover arguments which are the
2075 * mandatory component class specification and query object.
2077 leftover
= poptGetArg(pc
);
2079 cfg
->cmd_data
.query
.cfg_component
=
2080 bt_config_component_from_arg(leftover
);
2081 if (!cfg
->cmd_data
.query
.cfg_component
) {
2082 printf_err("Invalid format for component class specification:\n %s\n",
2088 BT_OBJECT_MOVE_REF(cfg
->cmd_data
.query
.cfg_component
->params
, params
);
2090 print_query_usage(stdout
);
2092 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2096 leftover
= poptGetArg(pc
);
2098 if (strlen(leftover
) == 0) {
2099 printf_err("Invalid empty object\n");
2103 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2105 print_query_usage(stdout
);
2107 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2111 leftover
= poptGetArg(pc
);
2113 printf_err("Unexpected argument: %s\n", leftover
);
2117 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2125 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2129 poptFreeContext(pc
);
2132 bt_object_put_ref(params
);
2138 * Prints the list-plugins command usage.
2141 void print_list_plugins_usage(FILE *fp
)
2143 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2145 fprintf(fp
, "Options:\n");
2147 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2148 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2149 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2150 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2151 fprintf(fp
, " dynamic plugins can be loaded\n");
2152 fprintf(fp
, " -h, --help Show this help and quit\n");
2154 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2156 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2160 struct poptOption list_plugins_long_options
[] = {
2161 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2162 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2163 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2164 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2165 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2166 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2170 * Creates a Babeltrace config object from the arguments of a
2171 * list-plugins command.
2173 * *retcode is set to the appropriate exit code to use.
2176 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2177 int *retcode
, bool force_omit_system_plugin_path
,
2178 bool force_omit_home_plugin_path
,
2179 struct bt_value
*initial_plugin_paths
)
2181 poptContext pc
= NULL
;
2185 struct bt_config
*cfg
= NULL
;
2186 const char *leftover
;
2189 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2194 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2195 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2196 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2202 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2203 list_plugins_long_options
, 0);
2205 printf_err("Cannot get popt context\n");
2209 poptReadDefaultConfig(pc
, 0);
2211 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2212 arg
= poptGetOptArg(pc
);
2215 case OPT_PLUGIN_PATH
:
2216 if (bt_config_append_plugin_paths_check_setuid_setgid(
2217 cfg
->plugin_paths
, arg
)) {
2221 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2222 cfg
->omit_system_plugin_path
= true;
2224 case OPT_OMIT_HOME_PLUGIN_PATH
:
2225 cfg
->omit_home_plugin_path
= true;
2228 print_list_plugins_usage(stdout
);
2230 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2233 printf_err("Unknown command-line option specified (option code %d)\n",
2242 /* Check for option parsing error */
2244 printf_err("While parsing command-line options, at option %s: %s\n",
2245 poptBadOption(pc
, 0), poptStrerror(opt
));
2249 leftover
= poptGetArg(pc
);
2251 printf_err("Unexpected argument: %s\n", leftover
);
2255 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2263 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2267 poptFreeContext(pc
);
2275 * Prints the run command usage.
2278 void print_run_usage(FILE *fp
)
2280 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2282 fprintf(fp
, "Options:\n");
2284 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2285 fprintf(fp
, " for all the following components until\n");
2286 fprintf(fp
, " --reset-base-params is encountered\n");
2287 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2288 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2289 fprintf(fp
, " Instantiate the component class CLS of type\n");
2290 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2291 fprintf(fp
, " in the plugin PLUGIN, add it to the graph,\n");
2292 fprintf(fp
, " and optionally name it NAME (you can also\n");
2293 fprintf(fp
, " specify the name with --name)\n");
2294 fprintf(fp
, " -C, --connect=CONNECTION Connect two created components (see the\n");
2295 fprintf(fp
, " expected format of CONNECTION below)\n");
2296 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2297 fprintf(fp
, " parameter key to KEY (see --value)\n");
2298 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2299 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2300 fprintf(fp
, " names of the created components)\n");
2301 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2302 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2303 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2304 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2305 fprintf(fp
, " current component (see the expected format\n");
2306 fprintf(fp
, " of PARAMS below)\n");
2307 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2308 fprintf(fp
, " dynamic plugins can be loaded\n");
2309 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2310 fprintf(fp
, " empty map\n");
2311 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2312 fprintf(fp
, " the graph later, retry in DUR µs\n");
2313 fprintf(fp
, " (default: 100000)\n");
2314 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2315 fprintf(fp
, " the current component with a name given by\n");
2316 fprintf(fp
, " the last argument of the --key option and a\n");
2317 fprintf(fp
, " value set to VAL\n");
2318 fprintf(fp
, " -h, --help Show this help and quit\n");
2320 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2321 fprintf(fp
, "\n\n");
2322 fprintf(fp
, "Expected format of CONNECTION\n");
2323 fprintf(fp
, "-----------------------------\n");
2325 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2327 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2328 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2329 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2330 fprintf(fp
, "component with the --name option.\n");
2332 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2333 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2334 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2336 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2337 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2338 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2339 fprintf(fp
, "DOWNSTREAM.\n");
2341 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2342 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2343 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2345 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2346 fprintf(fp
, "can connect a filter component to a sink component.\n");
2348 fprintf(fp
, "Examples:\n");
2350 fprintf(fp
, " my-src:my-sink\n");
2351 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2353 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2354 fprintf(fp
, "babeltrace from a shell.\n");
2355 fprintf(fp
, "\n\n");
2356 print_expected_params_format(fp
);
2360 * Creates a Babeltrace config object from the arguments of a run
2363 * *retcode is set to the appropriate exit code to use.
2366 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2367 int *retcode
, bool force_omit_system_plugin_path
,
2368 bool force_omit_home_plugin_path
,
2369 struct bt_value
*initial_plugin_paths
)
2371 poptContext pc
= NULL
;
2373 struct bt_config_component
*cur_cfg_comp
= NULL
;
2374 enum bt_config_component_dest cur_cfg_comp_dest
=
2375 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
2376 struct bt_value
*cur_base_params
= NULL
;
2378 struct bt_config
*cfg
= NULL
;
2379 struct bt_value
*instance_names
= NULL
;
2380 struct bt_value
*connection_args
= NULL
;
2381 GString
*cur_param_key
= NULL
;
2382 char error_buf
[256] = { 0 };
2383 long retry_duration
= -1;
2384 struct poptOption run_long_options
[] = {
2385 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2386 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2387 { "connect", 'C', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2388 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2389 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2390 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2391 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2392 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2393 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2394 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2395 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2396 { "retry-duration", '\0', POPT_ARG_LONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2397 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2398 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2402 cur_param_key
= g_string_new(NULL
);
2403 if (!cur_param_key
) {
2409 print_run_usage(stdout
);
2414 cfg
= bt_config_run_create(initial_plugin_paths
);
2419 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2420 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2421 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2422 cur_base_params
= bt_value_map_create();
2423 if (!cur_base_params
) {
2428 instance_names
= bt_value_map_create();
2429 if (!instance_names
) {
2434 connection_args
= bt_value_array_create();
2435 if (!connection_args
) {
2440 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2446 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2447 run_long_options
, 0);
2449 printf_err("Cannot get popt context\n");
2453 poptReadDefaultConfig(pc
, 0);
2455 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2456 arg
= poptGetOptArg(pc
);
2459 case OPT_PLUGIN_PATH
:
2460 if (bt_config_append_plugin_paths_check_setuid_setgid(
2461 cfg
->plugin_paths
, arg
)) {
2465 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2466 cfg
->omit_system_plugin_path
= true;
2468 case OPT_OMIT_HOME_PLUGIN_PATH
:
2469 cfg
->omit_home_plugin_path
= true;
2473 enum bt_config_component_dest new_dest
;
2476 ret
= add_run_cfg_comp_check_name(cfg
,
2477 cur_cfg_comp
, cur_cfg_comp_dest
,
2479 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2485 cur_cfg_comp
= bt_config_component_from_arg(arg
);
2486 if (!cur_cfg_comp
) {
2487 printf_err("Invalid format for --component option's argument:\n %s\n",
2492 switch (cur_cfg_comp
->type
) {
2493 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
2494 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2496 case BT_COMPONENT_CLASS_TYPE_FILTER
:
2497 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2499 case BT_COMPONENT_CLASS_TYPE_SINK
:
2500 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2506 BT_ASSERT(cur_base_params
);
2507 bt_object_put_ref(cur_cfg_comp
->params
);
2508 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
2509 if (!cur_cfg_comp
->params
) {
2514 cur_cfg_comp_dest
= new_dest
;
2519 struct bt_value
*params
;
2520 struct bt_value
*params_to_set
;
2522 if (!cur_cfg_comp
) {
2523 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2528 params
= bt_value_from_arg(arg
);
2530 printf_err("Invalid format for --params option's argument:\n %s\n",
2535 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
2537 BT_OBJECT_PUT_REF_AND_RESET(params
);
2538 if (!params_to_set
) {
2539 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2544 BT_OBJECT_MOVE_REF(cur_cfg_comp
->params
, params_to_set
);
2548 if (strlen(arg
) == 0) {
2549 printf_err("Cannot set an empty string as the current parameter key\n");
2553 g_string_assign(cur_param_key
, arg
);
2556 if (!cur_cfg_comp
) {
2557 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2562 if (cur_param_key
->len
== 0) {
2563 printf_err("--value option specified without preceding --key option:\n %s\n",
2568 if (bt_value_map_insert_string_entry(cur_cfg_comp
->params
,
2569 cur_param_key
->str
, arg
)) {
2575 if (!cur_cfg_comp
) {
2576 printf_err("Cannot set the name of unavailable component:\n %s\n",
2581 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2583 case OPT_BASE_PARAMS
:
2585 struct bt_value
*params
= bt_value_from_arg(arg
);
2588 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2593 BT_OBJECT_MOVE_REF(cur_base_params
, params
);
2596 case OPT_RESET_BASE_PARAMS
:
2597 BT_OBJECT_PUT_REF_AND_RESET(cur_base_params
);
2598 cur_base_params
= bt_value_map_create();
2599 if (!cur_base_params
) {
2605 if (bt_value_array_append_string_element(
2606 connection_args
, arg
)) {
2611 case OPT_RETRY_DURATION
:
2612 if (retry_duration
< 0) {
2613 printf_err("--retry-duration option's argument must be positive or 0: %ld\n",
2618 cfg
->cmd_data
.run
.retry_duration_us
=
2619 (uint64_t) retry_duration
;
2622 print_run_usage(stdout
);
2624 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2627 printf_err("Unknown command-line option specified (option code %d)\n",
2636 /* Check for option parsing error */
2638 printf_err("While parsing command-line options, at option %s: %s\n",
2639 poptBadOption(pc
, 0), poptStrerror(opt
));
2643 /* This command does not accept leftover arguments */
2644 if (poptPeekArg(pc
)) {
2645 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2649 /* Add current component */
2651 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2652 cur_cfg_comp_dest
, instance_names
);
2653 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2659 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2660 printf_err("Incomplete graph: no source component\n");
2664 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2665 printf_err("Incomplete graph: no sink component\n");
2669 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2673 ret
= bt_config_cli_args_create_connections(cfg
, connection_args
,
2676 printf_err("Cannot creation connections:\n%s", error_buf
);
2684 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2688 poptFreeContext(pc
);
2691 if (cur_param_key
) {
2692 g_string_free(cur_param_key
, TRUE
);
2696 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2697 BT_OBJECT_PUT_REF_AND_RESET(cur_base_params
);
2698 BT_OBJECT_PUT_REF_AND_RESET(instance_names
);
2699 BT_OBJECT_PUT_REF_AND_RESET(connection_args
);
2704 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2705 int *retcode
, bool force_omit_system_plugin_path
,
2706 bool force_omit_home_plugin_path
,
2707 struct bt_value
*initial_plugin_paths
)
2709 struct bt_config
*cfg
= NULL
;
2712 const size_t argc
= bt_value_array_get_size(run_args
) + 1;
2714 argv
= calloc(argc
, sizeof(*argv
));
2722 len
= bt_value_array_get_size(run_args
);
2724 printf_err("Invalid executable arguments\n");
2727 for (i
= 0; i
< len
; i
++) {
2729 struct bt_value
*arg_value
=
2730 bt_value_array_borrow_element_by_index(run_args
, i
);
2733 BT_ASSERT(arg_value
);
2734 ret
= bt_value_string_get(arg_value
, &arg
);
2735 BT_ASSERT(ret
== 0);
2740 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2741 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2742 initial_plugin_paths
);
2750 * Prints the convert command usage.
2753 void print_convert_usage(FILE *fp
)
2755 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2757 fprintf(fp
, "Options:\n");
2759 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2760 fprintf(fp
, " Instantiate the component class CLS of type\n");
2761 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2762 fprintf(fp
, " in the plugin PLUGIN, add it to the\n");
2763 fprintf(fp
, " conversion graph, and optionally name it\n");
2764 fprintf(fp
, " NAME (you can also specify the name with\n");
2765 fprintf(fp
, " --name)\n");
2766 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2767 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2768 fprintf(fp
, " names of the created components)\n");
2769 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2770 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2771 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2772 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2773 fprintf(fp
, " current component (see the expected format\n");
2774 fprintf(fp
, " of PARAMS below)\n");
2775 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2776 fprintf(fp
, " current component to PATH\n");
2777 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2778 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2779 fprintf(fp
, " the graph later, retry in DUR µs\n");
2780 fprintf(fp
, " (default: 100000)\n");
2781 fprintf(fp
, " dynamic plugins can be loaded\n");
2782 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2783 fprintf(fp
, " `run` command to the standard output,\n");
2784 fprintf(fp
, " formatted for a shell, and quit\n");
2785 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2786 fprintf(fp
, " `run` command to the standard output,\n");
2787 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2788 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2789 fprintf(fp
, " are active\n");
2790 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2791 fprintf(fp
, " current component to URL\n");
2792 fprintf(fp
, " -h, --help Show this help and quit\n");
2794 fprintf(fp
, "Implicit `source.ctf.fs` component options:\n");
2796 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2797 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2799 fprintf(fp
, "Implicit `sink.text.pretty` component options:\n");
2801 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2802 fprintf(fp
, " --clock-date Print timestamp dates\n");
2803 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2804 fprintf(fp
, " time zone instead of the local time zone\n");
2805 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2806 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2807 fprintf(fp
, " --color=(never | auto | always)\n");
2808 fprintf(fp
, " Never, automatically, or always emit\n");
2809 fprintf(fp
, " console color codes\n");
2810 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2811 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2812 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2813 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2814 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2815 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2816 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2817 fprintf(fp
, " (or `ctx`)\n");
2818 fprintf(fp
, " --no-delta Do not print time delta between\n");
2819 fprintf(fp
, " consecutive events\n");
2820 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2821 fprintf(fp
, " the standard output\n");
2823 fprintf(fp
, "Implicit `filter.utils.muxer` component options:\n");
2825 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2826 fprintf(fp
, " correlated across traces\n");
2828 fprintf(fp
, "Implicit `filter.utils.trimmer` component options:\n");
2830 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2831 fprintf(fp
, " time range to BEGIN (see the format of\n");
2832 fprintf(fp
, " BEGIN below)\n");
2833 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2834 fprintf(fp
, " range to END (see the format of END below)\n");
2835 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2836 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2837 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2839 fprintf(fp
, "Implicit `filter.lttng-utils.debug-info` component options:\n");
2841 fprintf(fp
, " --debug-info Create an implicit\n");
2842 fprintf(fp
, " `filter.lttng-utils.debug-info` component\n");
2843 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2844 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2845 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2846 fprintf(fp
, " binary paths instead of just names\n");
2847 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2848 fprintf(fp
, " Use directory DIR as a prefix when\n");
2849 fprintf(fp
, " looking up executables during debug\n");
2850 fprintf(fp
, " info analysis\n");
2852 fprintf(fp
, "Legacy options that still work:\n");
2854 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2855 fprintf(fp
, " `ctf`:\n");
2856 fprintf(fp
, " Create an implicit `source.ctf.fs`\n");
2857 fprintf(fp
, " component\n");
2858 fprintf(fp
, " `lttng-live`:\n");
2859 fprintf(fp
, " Create an implicit `source.ctf.lttng-live`\n");
2860 fprintf(fp
, " component\n");
2861 fprintf(fp
, " -o, --output-format=(text | ctf | dummy | ctf-metadata)\n");
2862 fprintf(fp
, " `text`:\n");
2863 fprintf(fp
, " Create an implicit `sink.text.pretty`\n");
2864 fprintf(fp
, " component\n");
2865 fprintf(fp
, " `ctf`:\n");
2866 fprintf(fp
, " Create an implicit `sink.ctf.fs`\n");
2867 fprintf(fp
, " component\n");
2868 fprintf(fp
, " `dummy`:\n");
2869 fprintf(fp
, " Create an implicit `sink.utils.dummy`\n");
2870 fprintf(fp
, " component\n");
2871 fprintf(fp
, " `ctf-metadata`:\n");
2872 fprintf(fp
, " Query the `source.ctf.fs` component class\n");
2873 fprintf(fp
, " for metadata text and quit\n");
2875 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2876 fprintf(fp
, "\n\n");
2877 fprintf(fp
, "Format of BEGIN and END\n");
2878 fprintf(fp
, "-----------------------\n");
2880 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2881 fprintf(fp
, "\n\n");
2882 print_expected_params_format(fp
);
2886 struct poptOption convert_long_options
[] = {
2887 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2888 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2889 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2890 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2891 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2892 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2893 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2894 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2895 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2896 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2897 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2898 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2899 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2900 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2901 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2902 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2903 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2904 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2905 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2906 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2907 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2908 { "debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO
, NULL
, NULL
},
2909 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2910 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2911 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2912 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2913 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2914 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2915 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2916 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2917 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2918 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2919 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2920 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2921 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2922 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2923 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2924 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2928 GString
*get_component_auto_name(const char *prefix
,
2929 struct bt_value
*existing_names
)
2932 GString
*auto_name
= g_string_new(NULL
);
2939 if (!bt_value_map_has_entry(existing_names
, prefix
)) {
2940 g_string_assign(auto_name
, prefix
);
2945 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2947 } while (bt_value_map_has_entry(existing_names
, auto_name
->str
));
2953 struct implicit_component_args
{
2957 GString
*params_arg
;
2958 struct bt_value
*extra_params
;
2962 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
2963 const char *prefix
, struct bt_value
*existing_names
,
2964 GList
**comp_names
, bool append_to_comp_names
)
2967 GString
*name
= NULL
;
2969 if (!args
->exists
) {
2973 name
= get_component_auto_name(prefix
, existing_names
);
2980 g_string_assign(args
->name_arg
, name
->str
);
2982 if (bt_value_map_insert_entry(existing_names
, name
->str
,
2989 if (append_to_comp_names
) {
2990 *comp_names
= g_list_append(*comp_names
, name
);
2996 g_string_free(name
, TRUE
);
3003 int append_run_args_for_implicit_component(
3004 struct implicit_component_args
*impl_args
,
3005 struct bt_value
*run_args
)
3010 if (!impl_args
->exists
) {
3014 if (bt_value_array_append_string_element(run_args
, "--component")) {
3019 if (bt_value_array_append_string_element(run_args
, impl_args
->comp_arg
->str
)) {
3024 if (bt_value_array_append_string_element(run_args
, "--name")) {
3029 if (bt_value_array_append_string_element(run_args
, impl_args
->name_arg
->str
)) {
3034 if (impl_args
->params_arg
->len
> 0) {
3035 if (bt_value_array_append_string_element(run_args
, "--params")) {
3040 if (bt_value_array_append_string_element(run_args
,
3041 impl_args
->params_arg
->str
)) {
3047 for (i
= 0; i
< bt_value_array_get_size(impl_args
->extra_params
); i
++) {
3048 struct bt_value
*elem
;
3051 elem
= bt_value_array_borrow_element_by_index(
3052 impl_args
->extra_params
, i
);
3057 BT_ASSERT(bt_value_is_string(elem
));
3058 if (bt_value_string_get(elem
, &arg
)) {
3062 ret
= bt_value_array_append_string_element(run_args
, arg
);
3079 void finalize_implicit_component_args(struct implicit_component_args
*args
)
3083 if (args
->comp_arg
) {
3084 g_string_free(args
->comp_arg
, TRUE
);
3087 if (args
->name_arg
) {
3088 g_string_free(args
->name_arg
, TRUE
);
3091 if (args
->params_arg
) {
3092 g_string_free(args
->params_arg
, TRUE
);
3095 bt_object_put_ref(args
->extra_params
);
3099 void destroy_implicit_component_args(void *args
)
3105 finalize_implicit_component_args(args
);
3110 int init_implicit_component_args(struct implicit_component_args
*args
,
3111 const char *comp_arg
, bool exists
)
3115 args
->exists
= exists
;
3116 args
->comp_arg
= g_string_new(comp_arg
);
3117 args
->name_arg
= g_string_new(NULL
);
3118 args
->params_arg
= g_string_new(NULL
);
3119 args
->extra_params
= bt_value_array_create();
3121 if (!args
->comp_arg
|| !args
->name_arg
||
3122 !args
->params_arg
|| !args
->extra_params
) {
3124 finalize_implicit_component_args(args
);
3134 void append_implicit_component_param(struct implicit_component_args
*args
,
3135 const char *key
, const char *value
)
3140 append_param_arg(args
->params_arg
, key
, value
);
3144 int append_implicit_component_extra_param(struct implicit_component_args
*args
,
3145 const char *key
, const char *value
)
3153 if (bt_value_array_append_string_element(args
->extra_params
, "--key")) {
3159 if (bt_value_array_append_string_element(args
->extra_params
, key
)) {
3165 if (bt_value_array_append_string_element(args
->extra_params
, "--value")) {
3171 if (bt_value_array_append_string_element(args
->extra_params
, value
)) {
3182 int convert_append_name_param(enum bt_config_component_dest dest
,
3183 GString
*cur_name
, GString
*cur_name_prefix
,
3184 struct bt_value
*run_args
, struct bt_value
*all_names
,
3185 GList
**source_names
, GList
**filter_names
,
3190 if (cur_name_prefix
->len
> 0) {
3191 /* We're after a --component option */
3192 GString
*name
= NULL
;
3193 bool append_name_opt
= false;
3195 if (cur_name
->len
== 0) {
3197 * No explicit name was provided for the user
3200 name
= get_component_auto_name(cur_name_prefix
->str
,
3202 append_name_opt
= true;
3205 * An explicit name was provided for the user
3208 if (bt_value_map_has_entry(all_names
,
3210 printf_err("Duplicate component instance name:\n %s\n",
3215 name
= g_string_new(cur_name
->str
);
3224 * Remember this name globally, for the uniqueness of
3225 * all component names.
3227 if (bt_value_map_insert_entry(all_names
, name
->str
, bt_value_null
)) {
3233 * Append the --name option if necessary.
3235 if (append_name_opt
) {
3236 if (bt_value_array_append_string_element(run_args
, "--name")) {
3241 if (bt_value_array_append_string_element(run_args
, name
->str
)) {
3248 * Remember this name specifically for the type of the
3249 * component. This is to create connection arguments.
3252 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3253 *source_names
= g_list_append(*source_names
, name
);
3255 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3256 *filter_names
= g_list_append(*filter_names
, name
);
3258 case BT_CONFIG_COMPONENT_DEST_SINK
:
3259 *sink_names
= g_list_append(*sink_names
, name
);
3265 g_string_assign(cur_name_prefix
, "");
3278 * Escapes `.`, `:`, and `\` of `input` with `\`.
3281 GString
*escape_dot_colon(const char *input
)
3283 GString
*output
= g_string_new(NULL
);
3291 for (ch
= input
; *ch
!= '\0'; ch
++) {
3292 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3293 g_string_append_c(output
, '\\');
3296 g_string_append_c(output
, *ch
);
3304 * Appends a --connect option to a list of arguments. `upstream_name`
3305 * and `downstream_name` are escaped with escape_dot_colon() in this
3309 int append_connect_arg(struct bt_value
*run_args
,
3310 const char *upstream_name
, const char *downstream_name
)
3313 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3314 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3315 GString
*arg
= g_string_new(NULL
);
3317 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3323 ret
= bt_value_array_append_string_element(run_args
, "--connect");
3330 g_string_append(arg
, e_upstream_name
->str
);
3331 g_string_append_c(arg
, ':');
3332 g_string_append(arg
, e_downstream_name
->str
);
3333 ret
= bt_value_array_append_string_element(run_args
, arg
->str
);
3342 g_string_free(arg
, TRUE
);
3345 if (e_upstream_name
) {
3346 g_string_free(e_upstream_name
, TRUE
);
3349 if (e_downstream_name
) {
3350 g_string_free(e_downstream_name
, TRUE
);
3357 * Appends the run command's --connect options for the convert command.
3360 int convert_auto_connect(struct bt_value
*run_args
,
3361 GList
*source_names
, GList
*filter_names
,
3365 GList
*source_at
= source_names
;
3366 GList
*filter_at
= filter_names
;
3368 GList
*sink_at
= sink_names
;
3370 BT_ASSERT(source_names
);
3371 BT_ASSERT(filter_names
);
3372 BT_ASSERT(sink_names
);
3374 /* Connect all sources to the first filter */
3375 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3376 GString
*source_name
= source_at
->data
;
3377 GString
*filter_name
= filter_at
->data
;
3379 ret
= append_connect_arg(run_args
, source_name
->str
,
3386 filter_prev
= filter_at
;
3387 filter_at
= g_list_next(filter_at
);
3389 /* Connect remaining filters */
3390 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3391 GString
*filter_name
= filter_at
->data
;
3392 GString
*filter_prev_name
= filter_prev
->data
;
3394 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3401 /* Connect last filter to all sinks */
3402 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3403 GString
*filter_name
= filter_prev
->data
;
3404 GString
*sink_name
= sink_at
->data
;
3406 ret
= append_connect_arg(run_args
, filter_name
->str
,
3423 int split_timerange(const char *arg
, char **begin
, char **end
)
3426 const char *ch
= arg
;
3428 GString
*g_begin
= NULL
;
3429 GString
*g_end
= NULL
;
3437 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3438 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3444 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3445 if (!g_end
|| g_end
->len
== 0) {
3451 *begin
= g_begin
->str
;
3453 g_string_free(g_begin
, FALSE
);
3454 g_string_free(g_end
, FALSE
);
3464 g_string_free(g_begin
, TRUE
);
3468 g_string_free(g_end
, TRUE
);
3475 int g_list_prepend_gstring(GList
**list
, const char *string
)
3478 GString
*gs
= g_string_new(string
);
3487 *list
= g_list_prepend(*list
, gs
);
3494 struct implicit_component_args
*create_implicit_component_args(void)
3496 struct implicit_component_args
*impl_args
=
3497 g_new0(struct implicit_component_args
, 1);
3503 if (init_implicit_component_args(impl_args
, NULL
, true)) {
3504 destroy_implicit_component_args(impl_args
);
3514 int fill_implicit_ctf_inputs_args(GPtrArray
*implicit_ctf_inputs_args
,
3515 struct implicit_component_args
*base_implicit_ctf_input_args
,
3521 for (leftover
= leftovers
; leftover
!= NULL
;
3522 leftover
= g_list_next(leftover
)) {
3523 GString
*gs_leftover
= leftover
->data
;
3524 struct implicit_component_args
*impl_args
=
3525 create_implicit_component_args();
3532 impl_args
->exists
= true;
3533 g_string_assign(impl_args
->comp_arg
,
3534 base_implicit_ctf_input_args
->comp_arg
->str
);
3535 g_string_assign(impl_args
->params_arg
,
3536 base_implicit_ctf_input_args
->params_arg
->str
);
3539 * We need our own copy of the extra parameters because
3540 * this is where the unique path goes.
3542 BT_OBJECT_PUT_REF_AND_RESET(impl_args
->extra_params
);
3543 impl_args
->extra_params
=
3544 bt_value_copy(base_implicit_ctf_input_args
->extra_params
);
3545 if (!impl_args
->extra_params
) {
3547 destroy_implicit_component_args(impl_args
);
3551 /* Append unique path parameter */
3552 ret
= append_implicit_component_extra_param(impl_args
,
3553 "path", gs_leftover
->str
);
3555 destroy_implicit_component_args(impl_args
);
3559 g_ptr_array_add(implicit_ctf_inputs_args
, impl_args
);
3572 * Creates a Babeltrace config object from the arguments of a convert
3575 * *retcode is set to the appropriate exit code to use.
3578 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3579 int *retcode
, bool force_omit_system_plugin_path
,
3580 bool force_omit_home_plugin_path
,
3581 struct bt_value
*initial_plugin_paths
, char *log_level
)
3583 poptContext pc
= NULL
;
3585 enum bt_config_component_dest cur_comp_dest
=
3586 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3588 struct bt_config
*cfg
= NULL
;
3589 bool got_input_format_opt
= false;
3590 bool got_output_format_opt
= false;
3591 bool trimmer_has_begin
= false;
3592 bool trimmer_has_end
= false;
3593 bool stream_intersection_mode
= false;
3594 GString
*cur_name
= NULL
;
3595 GString
*cur_name_prefix
= NULL
;
3596 const char *leftover
= NULL
;
3597 bool print_run_args
= false;
3598 bool print_run_args_0
= false;
3599 bool print_ctf_metadata
= false;
3600 struct bt_value
*run_args
= NULL
;
3601 struct bt_value
*all_names
= NULL
;
3602 GList
*source_names
= NULL
;
3603 GList
*filter_names
= NULL
;
3604 GList
*sink_names
= NULL
;
3605 GList
*leftovers
= NULL
;
3606 GPtrArray
*implicit_ctf_inputs_args
= NULL
;
3607 struct implicit_component_args base_implicit_ctf_input_args
= { 0 };
3608 struct implicit_component_args implicit_ctf_output_args
= { 0 };
3609 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3610 struct implicit_component_args implicit_dummy_args
= { 0 };
3611 struct implicit_component_args implicit_text_args
= { 0 };
3612 struct implicit_component_args implicit_debug_info_args
= { 0 };
3613 struct implicit_component_args implicit_muxer_args
= { 0 };
3614 struct implicit_component_args implicit_trimmer_args
= { 0 };
3615 struct bt_value
*plugin_paths
= bt_object_get_ref(initial_plugin_paths
);
3616 char error_buf
[256] = { 0 };
3618 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3619 char *output
= NULL
;
3624 print_convert_usage(stdout
);
3629 if (init_implicit_component_args(&base_implicit_ctf_input_args
,
3630 "source.ctf.fs", false)) {
3634 if (init_implicit_component_args(&implicit_ctf_output_args
,
3635 "sink.ctf.fs", false)) {
3639 if (init_implicit_component_args(&implicit_lttng_live_args
,
3640 "source.ctf.lttng-live", false)) {
3644 if (init_implicit_component_args(&implicit_text_args
,
3645 "sink.text.pretty", false)) {
3649 if (init_implicit_component_args(&implicit_dummy_args
,
3650 "sink.utils.dummy", false)) {
3654 if (init_implicit_component_args(&implicit_debug_info_args
,
3655 "filter.lttng-utils.debug-info", false)) {
3659 if (init_implicit_component_args(&implicit_muxer_args
,
3660 "filter.utils.muxer", true)) {
3664 if (init_implicit_component_args(&implicit_trimmer_args
,
3665 "filter.utils.trimmer", false)) {
3669 implicit_ctf_inputs_args
= g_ptr_array_new_with_free_func(
3670 (GDestroyNotify
) destroy_implicit_component_args
);
3671 if (!implicit_ctf_inputs_args
) {
3676 all_names
= bt_value_map_create();
3682 run_args
= bt_value_array_create();
3688 cur_name
= g_string_new(NULL
);
3694 cur_name_prefix
= g_string_new(NULL
);
3695 if (!cur_name_prefix
) {
3700 ret
= append_env_var_plugin_paths(plugin_paths
);
3706 * First pass: collect all arguments which need to be passed
3707 * as is to the run command. This pass can also add --name
3708 * arguments if needed to automatically name unnamed component
3709 * instances. Also it does the following transformations:
3711 * --path=PATH -> --key path --value PATH
3712 * --url=URL -> --key url --value URL
3714 * Also it appends the plugin paths of --plugin-path to
3717 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3718 convert_long_options
, 0);
3720 printf_err("Cannot get popt context\n");
3724 poptReadDefaultConfig(pc
, 0);
3726 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3728 char *plugin_name
= NULL
;
3729 char *comp_cls_name
= NULL
;
3731 arg
= poptGetOptArg(pc
);
3736 enum bt_component_class_type type
;
3737 const char *type_prefix
;
3739 /* Append current component's name if needed */
3740 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3741 cur_name_prefix
, run_args
, all_names
,
3742 &source_names
, &filter_names
, &sink_names
);
3747 /* Parse the argument */
3748 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3749 &comp_cls_name
, &type
);
3750 if (!plugin_name
|| !comp_cls_name
) {
3751 printf_err("Invalid format for --component option's argument:\n %s\n",
3757 g_string_assign(cur_name
, name
);
3759 g_string_assign(cur_name
, "");
3763 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3764 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3765 type_prefix
= "source";
3767 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3768 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
3769 type_prefix
= "filter";
3771 case BT_COMPONENT_CLASS_TYPE_SINK
:
3772 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3773 type_prefix
= "sink";
3779 if (bt_value_array_append_string_element(run_args
,
3785 if (bt_value_array_append_string_element(run_args
, arg
)) {
3790 g_string_assign(cur_name_prefix
, "");
3791 g_string_append_printf(cur_name_prefix
, "%s.%s.%s",
3792 type_prefix
, plugin_name
, comp_cls_name
);
3795 free(comp_cls_name
);
3798 comp_cls_name
= NULL
;
3802 if (cur_name_prefix
->len
== 0) {
3803 printf_err("No current component of which to set parameters:\n %s\n",
3808 if (bt_value_array_append_string_element(run_args
,
3814 if (bt_value_array_append_string_element(run_args
, arg
)) {
3820 if (cur_name_prefix
->len
== 0) {
3821 printf_err("No current component of which to set `path` parameter:\n %s\n",
3826 if (bt_value_array_append_string_element(run_args
, "--key")) {
3831 if (bt_value_array_append_string_element(run_args
, "path")) {
3836 if (bt_value_array_append_string_element(run_args
, "--value")) {
3841 if (bt_value_array_append_string_element(run_args
, arg
)) {
3847 if (cur_name_prefix
->len
== 0) {
3848 printf_err("No current component of which to set `url` parameter:\n %s\n",
3853 if (bt_value_array_append_string_element(run_args
, "--key")) {
3858 if (bt_value_array_append_string_element(run_args
, "url")) {
3863 if (bt_value_array_append_string_element(run_args
, "--value")) {
3868 if (bt_value_array_append_string_element(run_args
, arg
)) {
3874 if (cur_name_prefix
->len
== 0) {
3875 printf_err("No current component to name:\n %s\n",
3880 if (bt_value_array_append_string_element(run_args
, "--name")) {
3885 if (bt_value_array_append_string_element(run_args
, arg
)) {
3890 g_string_assign(cur_name
, arg
);
3892 case OPT_OMIT_HOME_PLUGIN_PATH
:
3893 force_omit_home_plugin_path
= true;
3895 if (bt_value_array_append_string_element(run_args
,
3896 "--omit-home-plugin-path")) {
3901 case OPT_RETRY_DURATION
:
3902 if (bt_value_array_append_string_element(run_args
,
3903 "--retry-duration")) {
3908 if (bt_value_array_append_string_element(run_args
, arg
)) {
3913 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3914 force_omit_system_plugin_path
= true;
3916 if (bt_value_array_append_string_element(run_args
,
3917 "--omit-system-plugin-path")) {
3922 case OPT_PLUGIN_PATH
:
3923 if (bt_config_append_plugin_paths_check_setuid_setgid(
3924 plugin_paths
, arg
)) {
3928 if (bt_value_array_append_string_element(run_args
,
3934 if (bt_value_array_append_string_element(run_args
, arg
)) {
3940 print_convert_usage(stdout
);
3942 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
3945 case OPT_CLOCK_CYCLES
:
3946 case OPT_CLOCK_DATE
:
3947 case OPT_CLOCK_FORCE_CORRELATE
:
3949 case OPT_CLOCK_OFFSET
:
3950 case OPT_CLOCK_OFFSET_NS
:
3951 case OPT_CLOCK_SECONDS
:
3954 case OPT_DEBUG_INFO
:
3955 case OPT_DEBUG_INFO_DIR
:
3956 case OPT_DEBUG_INFO_FULL_PATH
:
3957 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3960 case OPT_INPUT_FORMAT
:
3963 case OPT_OUTPUT_FORMAT
:
3966 case OPT_RUN_ARGS_0
:
3967 case OPT_STREAM_INTERSECTION
:
3970 /* Ignore in this pass */
3973 printf_err("Unknown command-line option specified (option code %d)\n",
3982 /* Append current component's name if needed */
3983 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3984 cur_name_prefix
, run_args
, all_names
, &source_names
,
3985 &filter_names
, &sink_names
);
3990 /* Check for option parsing error */
3992 printf_err("While parsing command-line options, at option %s: %s\n",
3993 poptBadOption(pc
, 0), poptStrerror(opt
));
3997 poptFreeContext(pc
);
4002 * Second pass: transform the convert-specific options and
4003 * arguments into implicit component instances for the run
4006 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
4007 convert_long_options
, 0);
4009 printf_err("Cannot get popt context\n");
4013 poptReadDefaultConfig(pc
, 0);
4015 while ((opt
= poptGetNextOpt(pc
)) > 0) {
4016 arg
= poptGetOptArg(pc
);
4020 if (trimmer_has_begin
) {
4021 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4026 trimmer_has_begin
= true;
4027 ret
= append_implicit_component_extra_param(
4028 &implicit_trimmer_args
, "begin", arg
);
4029 implicit_trimmer_args
.exists
= true;
4035 if (trimmer_has_end
) {
4036 printf("At --end option: --end or --timerange option already specified\n %s\n",
4041 trimmer_has_end
= true;
4042 ret
= append_implicit_component_extra_param(
4043 &implicit_trimmer_args
, "end", arg
);
4044 implicit_trimmer_args
.exists
= true;
4054 if (trimmer_has_begin
|| trimmer_has_end
) {
4055 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4060 ret
= split_timerange(arg
, &begin
, &end
);
4062 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4067 ret
= append_implicit_component_extra_param(
4068 &implicit_trimmer_args
, "begin", begin
);
4069 ret
|= append_implicit_component_extra_param(
4070 &implicit_trimmer_args
, "end", end
);
4071 implicit_trimmer_args
.exists
= true;
4079 case OPT_CLOCK_CYCLES
:
4080 append_implicit_component_param(
4081 &implicit_text_args
, "clock-cycles", "yes");
4082 implicit_text_args
.exists
= true;
4084 case OPT_CLOCK_DATE
:
4085 append_implicit_component_param(
4086 &implicit_text_args
, "clock-date", "yes");
4087 implicit_text_args
.exists
= true;
4089 case OPT_CLOCK_FORCE_CORRELATE
:
4090 append_implicit_component_param(
4091 &implicit_muxer_args
,
4092 "assume-absolute-clock-classes", "yes");
4095 append_implicit_component_param(
4096 &implicit_text_args
, "clock-gmt", "yes");
4097 append_implicit_component_param(
4098 &implicit_trimmer_args
, "clock-gmt", "yes");
4099 implicit_text_args
.exists
= true;
4101 case OPT_CLOCK_OFFSET
:
4102 base_implicit_ctf_input_args
.exists
= true;
4103 append_implicit_component_param(
4104 &base_implicit_ctf_input_args
,
4105 "clock-class-offset-s", arg
);
4107 case OPT_CLOCK_OFFSET_NS
:
4108 base_implicit_ctf_input_args
.exists
= true;
4109 append_implicit_component_param(
4110 &base_implicit_ctf_input_args
,
4111 "clock-class-offset-ns", arg
);
4113 case OPT_CLOCK_SECONDS
:
4114 append_implicit_component_param(
4115 &implicit_text_args
, "clock-seconds", "yes");
4116 implicit_text_args
.exists
= true;
4119 implicit_text_args
.exists
= true;
4120 ret
= append_implicit_component_extra_param(
4121 &implicit_text_args
, "color", arg
);
4126 case OPT_DEBUG_INFO
:
4127 implicit_debug_info_args
.exists
= true;
4129 case OPT_DEBUG_INFO_DIR
:
4130 implicit_debug_info_args
.exists
= true;
4131 ret
= append_implicit_component_extra_param(
4132 &implicit_debug_info_args
, "debug-info-dir", arg
);
4137 case OPT_DEBUG_INFO_FULL_PATH
:
4138 implicit_debug_info_args
.exists
= true;
4139 append_implicit_component_param(
4140 &implicit_debug_info_args
, "full-path", "yes");
4142 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4143 implicit_debug_info_args
.exists
= true;
4144 ret
= append_implicit_component_extra_param(
4145 &implicit_debug_info_args
,
4146 "target-prefix", arg
);
4153 struct bt_value
*fields
= fields_from_arg(arg
);
4159 implicit_text_args
.exists
= true;
4160 ret
= insert_flat_params_from_array(
4161 implicit_text_args
.params_arg
,
4163 bt_object_put_ref(fields
);
4171 struct bt_value
*names
= names_from_arg(arg
);
4177 implicit_text_args
.exists
= true;
4178 ret
= insert_flat_params_from_array(
4179 implicit_text_args
.params_arg
,
4181 bt_object_put_ref(names
);
4188 append_implicit_component_param(
4189 &implicit_text_args
, "no-delta", "yes");
4190 implicit_text_args
.exists
= true;
4192 case OPT_INPUT_FORMAT
:
4193 if (got_input_format_opt
) {
4194 printf_err("Duplicate --input-format option\n");
4198 got_input_format_opt
= true;
4200 if (strcmp(arg
, "ctf") == 0) {
4201 base_implicit_ctf_input_args
.exists
= true;
4202 } else if (strcmp(arg
, "lttng-live") == 0) {
4203 implicit_lttng_live_args
.exists
= true;
4205 printf_err("Unknown legacy input format:\n %s\n",
4210 case OPT_OUTPUT_FORMAT
:
4211 if (got_output_format_opt
) {
4212 printf_err("Duplicate --output-format option\n");
4216 got_output_format_opt
= true;
4218 if (strcmp(arg
, "text") == 0) {
4219 implicit_text_args
.exists
= true;
4220 } else if (strcmp(arg
, "ctf") == 0) {
4221 implicit_ctf_output_args
.exists
= true;
4222 } else if (strcmp(arg
, "dummy") == 0) {
4223 implicit_dummy_args
.exists
= true;
4224 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4225 print_ctf_metadata
= true;
4227 printf_err("Unknown legacy output format:\n %s\n",
4234 printf_err("Duplicate --output option\n");
4238 output
= strdup(arg
);
4245 if (print_run_args_0
) {
4246 printf_err("Cannot specify --run-args and --run-args-0\n");
4250 print_run_args
= true;
4252 case OPT_RUN_ARGS_0
:
4253 if (print_run_args
) {
4254 printf_err("Cannot specify --run-args and --run-args-0\n");
4258 print_run_args_0
= true;
4260 case OPT_STREAM_INTERSECTION
:
4262 * Applies to all traces implementing the trace-info
4265 stream_intersection_mode
= true;
4268 if (*log_level
!= 'V' && *log_level
!= 'D') {
4281 /* Check for option parsing error */
4283 printf_err("While parsing command-line options, at option %s: %s\n",
4284 poptBadOption(pc
, 0), poptStrerror(opt
));
4289 * Legacy behaviour: --verbose used to make the `text` output
4290 * format print more information. --verbose is now equivalent to
4291 * the INFO log level, which is why we compare to 'I' here.
4293 if (*log_level
== 'I') {
4294 append_implicit_component_param(&implicit_text_args
,
4299 * Append home and system plugin paths now that we possibly got
4302 if (append_home_and_system_plugin_paths(plugin_paths
,
4303 force_omit_system_plugin_path
,
4304 force_omit_home_plugin_path
)) {
4308 /* Consume and keep leftover arguments */
4309 while ((leftover
= poptGetArg(pc
))) {
4310 GString
*gs_leftover
= g_string_new(leftover
);
4317 leftovers
= g_list_append(leftovers
, gs_leftover
);
4319 g_string_free(gs_leftover
, TRUE
);
4325 /* Print CTF metadata or print LTTng live sessions */
4326 if (print_ctf_metadata
) {
4327 GString
*gs_leftover
;
4329 if (g_list_length(leftovers
) == 0) {
4330 printf_err("--output-format=ctf-metadata specified without a path\n");
4334 if (g_list_length(leftovers
) > 1) {
4335 printf_err("Too many paths specified for --output-format=ctf-metadata\n");
4339 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4344 gs_leftover
= leftovers
->data
;
4345 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4350 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
4358 * If -o ctf was specified, make sure an output path (--output)
4359 * was also specified. --output does not imply -o ctf because
4360 * it's also used for the default, implicit -o text if -o ctf
4363 if (implicit_ctf_output_args
.exists
) {
4365 printf_err("--output-format=ctf specified without --output (trace output path)\n");
4370 * At this point we know that -o ctf AND --output were
4371 * specified. Make sure that no options were specified
4372 * which would imply -o text because --output would be
4373 * ambiguous in this case. For example, this is wrong:
4375 * babeltrace --names=all -o ctf --output=/tmp/path my-trace
4377 * because --names=all implies -o text, and --output
4378 * could apply to both the sink.text.pretty and
4379 * sink.ctf.fs implicit components.
4381 if (implicit_text_args
.exists
) {
4382 printf_err("Ambiguous --output option: --output-format=ctf specified but another option implies --output-format=text\n");
4388 * If -o dummy and -o ctf were not specified, and if there are
4389 * no explicit sink components, then use an implicit
4390 * `sink.text.pretty` component.
4392 if (!implicit_dummy_args
.exists
&& !implicit_ctf_output_args
.exists
&&
4394 implicit_text_args
.exists
= true;
4398 * Set implicit `sink.text.pretty` or `sink.ctf.fs` component's
4399 * `path` parameter if --output was specified.
4402 if (implicit_text_args
.exists
) {
4403 append_implicit_component_extra_param(&implicit_text_args
,
4405 } else if (implicit_ctf_output_args
.exists
) {
4406 append_implicit_component_extra_param(&implicit_ctf_output_args
,
4411 /* Decide where the leftover argument(s) go */
4412 if (g_list_length(leftovers
) > 0) {
4413 if (implicit_lttng_live_args
.exists
) {
4414 GString
*gs_leftover
;
4416 if (g_list_length(leftovers
) > 1) {
4417 printf_err("Too many URLs specified for --output-format=lttng-live\n");
4421 gs_leftover
= leftovers
->data
;
4422 lttng_live_url_parts
=
4423 bt_common_parse_lttng_live_url(gs_leftover
->str
,
4424 error_buf
, sizeof(error_buf
));
4425 if (!lttng_live_url_parts
.proto
) {
4426 printf_err("Invalid LTTng live URL format: %s\n",
4431 if (!lttng_live_url_parts
.session_name
) {
4432 /* Print LTTng live sessions */
4433 cfg
= bt_config_print_lttng_live_sessions_create(
4439 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4444 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
4451 ret
= append_implicit_component_extra_param(
4452 &implicit_lttng_live_args
, "url",
4459 * Append one implicit component argument set
4460 * for each leftover (souce.ctf.fs paths). Copy
4461 * the base implicit component arguments.
4462 * Note that they still have to be named later.
4464 ret
= fill_implicit_ctf_inputs_args(
4465 implicit_ctf_inputs_args
,
4466 &base_implicit_ctf_input_args
, leftovers
);
4474 * Ensure mutual exclusion between implicit `source.ctf.fs` and
4475 * `source.ctf.lttng-live` components.
4477 if (base_implicit_ctf_input_args
.exists
&&
4478 implicit_lttng_live_args
.exists
) {
4479 printf_err("Cannot create both implicit `%s` and `%s` components\n",
4480 base_implicit_ctf_input_args
.comp_arg
->str
,
4481 implicit_lttng_live_args
.comp_arg
->str
);
4486 * If the implicit `source.ctf.fs` or `source.ctf.lttng-live`
4487 * components exists, make sure there's at least one leftover
4488 * (which is the path or URL).
4490 if (base_implicit_ctf_input_args
.exists
&&
4491 g_list_length(leftovers
) == 0) {
4492 printf_err("Missing path for implicit `%s` component\n",
4493 base_implicit_ctf_input_args
.comp_arg
->str
);
4497 if (implicit_lttng_live_args
.exists
&& g_list_length(leftovers
) == 0) {
4498 printf_err("Missing URL for implicit `%s` component\n",
4499 implicit_lttng_live_args
.comp_arg
->str
);
4503 /* Assign names to implicit components */
4504 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4505 struct implicit_component_args
*impl_args
=
4506 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4508 ret
= assign_name_to_implicit_component(impl_args
,
4509 "source-ctf-fs", all_names
, &source_names
, true);
4515 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4516 "lttng-live", all_names
, &source_names
, true);
4521 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4522 "pretty", all_names
, &sink_names
, true);
4527 ret
= assign_name_to_implicit_component(&implicit_ctf_output_args
,
4528 "sink-ctf-fs", all_names
, &sink_names
, true);
4533 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4534 "dummy", all_names
, &sink_names
, true);
4539 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4540 "muxer", all_names
, NULL
, false);
4545 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4546 "trimmer", all_names
, NULL
, false);
4551 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4552 "debug-info", all_names
, NULL
, false);
4557 /* Make sure there's at least one source and one sink */
4558 if (!source_names
) {
4559 printf_err("No source component\n");
4564 printf_err("No sink component\n");
4569 * Prepend the muxer, the trimmer, and the debug info to the
4570 * filter chain so that we have:
4572 * sources -> muxer -> [trimmer] -> [debug info] ->
4573 * [user filters] -> sinks
4575 if (implicit_debug_info_args
.exists
) {
4576 if (g_list_prepend_gstring(&filter_names
,
4577 implicit_debug_info_args
.name_arg
->str
)) {
4582 if (implicit_trimmer_args
.exists
) {
4583 if (g_list_prepend_gstring(&filter_names
,
4584 implicit_trimmer_args
.name_arg
->str
)) {
4589 if (g_list_prepend_gstring(&filter_names
,
4590 implicit_muxer_args
.name_arg
->str
)) {
4595 * Append the equivalent run arguments for the implicit
4598 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4599 struct implicit_component_args
*impl_args
=
4600 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4602 ret
= append_run_args_for_implicit_component(impl_args
,
4609 ret
= append_run_args_for_implicit_component(&implicit_lttng_live_args
,
4615 ret
= append_run_args_for_implicit_component(&implicit_text_args
,
4621 ret
= append_run_args_for_implicit_component(&implicit_ctf_output_args
,
4627 ret
= append_run_args_for_implicit_component(&implicit_dummy_args
,
4633 ret
= append_run_args_for_implicit_component(&implicit_muxer_args
,
4639 ret
= append_run_args_for_implicit_component(&implicit_trimmer_args
,
4645 ret
= append_run_args_for_implicit_component(&implicit_debug_info_args
,
4651 /* Auto-connect components */
4652 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4655 printf_err("Cannot auto-connect components\n");
4660 * We have all the run command arguments now. Depending on
4661 * --run-args, we pass this to the run command or print them
4664 if (print_run_args
|| print_run_args_0
) {
4665 if (stream_intersection_mode
) {
4666 printf_err("Cannot specify --stream-intersection with --run-args or --run-args-0\n");
4670 for (i
= 0; i
< bt_value_array_get_size(run_args
); i
++) {
4671 struct bt_value
*arg_value
=
4672 bt_value_array_borrow_element_by_index(
4675 GString
*quoted
= NULL
;
4676 const char *arg_to_print
;
4678 BT_ASSERT(arg_value
);
4679 ret
= bt_value_string_get(arg_value
, &arg
);
4680 BT_ASSERT(ret
== 0);
4682 if (print_run_args
) {
4683 quoted
= bt_common_shell_quote(arg
, true);
4688 arg_to_print
= quoted
->str
;
4693 printf("%s", arg_to_print
);
4696 g_string_free(quoted
, TRUE
);
4699 if (i
< bt_value_array_get_size(run_args
) - 1) {
4700 if (print_run_args
) {
4709 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4713 cfg
= bt_config_run_from_args_array(run_args
, retcode
,
4714 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
4715 initial_plugin_paths
);
4720 cfg
->cmd_data
.run
.stream_intersection_mode
= stream_intersection_mode
;
4725 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4729 poptFreeContext(pc
);
4736 g_string_free(cur_name
, TRUE
);
4739 if (cur_name_prefix
) {
4740 g_string_free(cur_name_prefix
, TRUE
);
4743 if (implicit_ctf_inputs_args
) {
4744 g_ptr_array_free(implicit_ctf_inputs_args
, TRUE
);
4747 bt_object_put_ref(run_args
);
4748 bt_object_put_ref(all_names
);
4749 destroy_glist_of_gstring(source_names
);
4750 destroy_glist_of_gstring(filter_names
);
4751 destroy_glist_of_gstring(sink_names
);
4752 destroy_glist_of_gstring(leftovers
);
4753 finalize_implicit_component_args(&base_implicit_ctf_input_args
);
4754 finalize_implicit_component_args(&implicit_ctf_output_args
);
4755 finalize_implicit_component_args(&implicit_lttng_live_args
);
4756 finalize_implicit_component_args(&implicit_dummy_args
);
4757 finalize_implicit_component_args(&implicit_text_args
);
4758 finalize_implicit_component_args(&implicit_debug_info_args
);
4759 finalize_implicit_component_args(&implicit_muxer_args
);
4760 finalize_implicit_component_args(&implicit_trimmer_args
);
4761 bt_object_put_ref(plugin_paths
);
4762 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4767 * Prints the Babeltrace 2.x general usage.
4770 void print_gen_usage(FILE *fp
)
4772 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4774 fprintf(fp
, "General options:\n");
4776 fprintf(fp
, " -d, --debug Enable debug mode (same as --log-level=V)\n");
4777 fprintf(fp
, " -h, --help Show this help and quit\n");
4778 fprintf(fp
, " -l, --log-level=LVL Set all log levels to LVL (`N`, `V`, `D`,\n");
4779 fprintf(fp
, " `I`, `W` (default), `E`, or `F`)\n");
4780 fprintf(fp
, " -v, --verbose Enable verbose mode (same as --log-level=I)\n");
4781 fprintf(fp
, " -V, --version Show version and quit\n");
4783 fprintf(fp
, "Available commands:\n");
4785 fprintf(fp
, " convert Convert and trim traces (default)\n");
4786 fprintf(fp
, " help Get help for a plugin or a component class\n");
4787 fprintf(fp
, " list-plugins List available plugins and their content\n");
4788 fprintf(fp
, " query Query objects from a component class\n");
4789 fprintf(fp
, " run Build a processing graph and run it\n");
4791 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4795 char log_level_from_arg(const char *arg
)
4799 if (strcmp(arg
, "VERBOSE") == 0 ||
4800 strcmp(arg
, "V") == 0) {
4802 } else if (strcmp(arg
, "DEBUG") == 0 ||
4803 strcmp(arg
, "D") == 0) {
4805 } else if (strcmp(arg
, "INFO") == 0 ||
4806 strcmp(arg
, "I") == 0) {
4808 } else if (strcmp(arg
, "WARN") == 0 ||
4809 strcmp(arg
, "WARNING") == 0 ||
4810 strcmp(arg
, "W") == 0) {
4812 } else if (strcmp(arg
, "ERROR") == 0 ||
4813 strcmp(arg
, "E") == 0) {
4815 } else if (strcmp(arg
, "FATAL") == 0 ||
4816 strcmp(arg
, "F") == 0) {
4818 } else if (strcmp(arg
, "NONE") == 0 ||
4819 strcmp(arg
, "N") == 0) {
4826 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4827 int *retcode
, bool force_omit_system_plugin_path
,
4828 bool force_omit_home_plugin_path
,
4829 struct bt_value
*initial_plugin_paths
)
4831 struct bt_config
*config
= NULL
;
4833 const char **command_argv
= NULL
;
4834 int command_argc
= -1;
4835 const char *command_name
= NULL
;
4836 char log_level
= 'U';
4839 COMMAND_TYPE_NONE
= -1,
4840 COMMAND_TYPE_RUN
= 0,
4841 COMMAND_TYPE_CONVERT
,
4842 COMMAND_TYPE_LIST_PLUGINS
,
4845 } command_type
= COMMAND_TYPE_NONE
;
4849 if (!initial_plugin_paths
) {
4850 initial_plugin_paths
= bt_value_array_create();
4851 if (!initial_plugin_paths
) {
4856 bt_object_get_ref(initial_plugin_paths
);
4862 print_gen_usage(stdout
);
4866 for (i
= 1; i
< argc
; i
++) {
4867 const char *cur_arg
= argv
[i
];
4868 const char *next_arg
= i
== (argc
- 1) ? NULL
: argv
[i
+ 1];
4870 if (strcmp(cur_arg
, "-d") == 0 ||
4871 strcmp(cur_arg
, "--debug") == 0) {
4873 } else if (strcmp(cur_arg
, "-v") == 0 ||
4874 strcmp(cur_arg
, "--verbose") == 0) {
4875 if (log_level
!= 'V' && log_level
!= 'D') {
4877 * Legacy: do not override a previous
4878 * --debug because --verbose and --debug
4879 * can be specified together (in this
4880 * case we want the lowest log level to
4885 } else if (strcmp(cur_arg
, "--log-level") == 0 ||
4886 strcmp(cur_arg
, "-l") == 0) {
4888 printf_err("Missing log level value for --log-level option\n");
4893 log_level
= log_level_from_arg(next_arg
);
4894 if (log_level
== 'U') {
4895 printf_err("Invalid argument for --log-level option:\n %s\n",
4902 } else if (strncmp(cur_arg
, "--log-level=", 12) == 0) {
4903 const char *arg
= &cur_arg
[12];
4905 log_level
= log_level_from_arg(arg
);
4906 if (log_level
== 'U') {
4907 printf_err("Invalid argument for --log-level option:\n %s\n",
4912 } else if (strncmp(cur_arg
, "-l", 2) == 0) {
4913 const char *arg
= &cur_arg
[2];
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 (strcmp(cur_arg
, "-V") == 0 ||
4923 strcmp(cur_arg
, "--version") == 0) {
4926 } else if (strcmp(cur_arg
, "-h") == 0 ||
4927 strcmp(cur_arg
, "--help") == 0) {
4928 print_gen_usage(stdout
);
4932 * First unknown argument: is it a known command
4935 command_argv
= &argv
[i
];
4936 command_argc
= argc
- i
;
4938 if (strcmp(cur_arg
, "convert") == 0) {
4939 command_type
= COMMAND_TYPE_CONVERT
;
4940 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4941 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4942 } else if (strcmp(cur_arg
, "help") == 0) {
4943 command_type
= COMMAND_TYPE_HELP
;
4944 } else if (strcmp(cur_arg
, "query") == 0) {
4945 command_type
= COMMAND_TYPE_QUERY
;
4946 } else if (strcmp(cur_arg
, "run") == 0) {
4947 command_type
= COMMAND_TYPE_RUN
;
4950 * Unknown argument, but not a known
4951 * command name: assume the default
4952 * `convert` command.
4954 command_type
= COMMAND_TYPE_CONVERT
;
4955 command_name
= "convert";
4956 command_argv
= &argv
[i
- 1];
4957 command_argc
= argc
- i
+ 1;
4963 if (command_type
== COMMAND_TYPE_NONE
) {
4965 * We only got non-help, non-version general options
4966 * like --verbose and --debug, without any other
4967 * arguments, so we can't do anything useful: print the
4970 print_gen_usage(stdout
);
4974 BT_ASSERT(command_argv
);
4975 BT_ASSERT(command_argc
>= 0);
4977 switch (command_type
) {
4978 case COMMAND_TYPE_RUN
:
4979 config
= bt_config_run_from_args(command_argc
, command_argv
,
4980 retcode
, force_omit_system_plugin_path
,
4981 force_omit_home_plugin_path
, initial_plugin_paths
);
4983 case COMMAND_TYPE_CONVERT
:
4984 config
= bt_config_convert_from_args(command_argc
, command_argv
,
4985 retcode
, force_omit_system_plugin_path
,
4986 force_omit_home_plugin_path
,
4987 initial_plugin_paths
, &log_level
);
4989 case COMMAND_TYPE_LIST_PLUGINS
:
4990 config
= bt_config_list_plugins_from_args(command_argc
,
4991 command_argv
, retcode
, force_omit_system_plugin_path
,
4992 force_omit_home_plugin_path
, initial_plugin_paths
);
4994 case COMMAND_TYPE_HELP
:
4995 config
= bt_config_help_from_args(command_argc
,
4996 command_argv
, retcode
, force_omit_system_plugin_path
,
4997 force_omit_home_plugin_path
, initial_plugin_paths
);
4999 case COMMAND_TYPE_QUERY
:
5000 config
= bt_config_query_from_args(command_argc
,
5001 command_argv
, retcode
, force_omit_system_plugin_path
,
5002 force_omit_home_plugin_path
, initial_plugin_paths
);
5009 if (log_level
== 'U') {
5013 config
->log_level
= log_level
;
5014 config
->command_name
= command_name
;
5018 bt_object_put_ref(initial_plugin_paths
);