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>
38 #include <babeltrace/private-values.h>
41 #include <sys/types.h>
42 #include "babeltrace-cfg.h"
43 #include "babeltrace-cfg-cli-args.h"
44 #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_private_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(
245 bt_private_value_borrow_value(state
->params
),
246 state
->last_map_key
)) {
247 g_string_append_printf(state
->ini_error
,
248 "Duplicate parameter key: `%s`\n",
249 state
->last_map_key
);
253 state
->expecting
= INI_EXPECT_EQUAL
;
255 case INI_EXPECT_EQUAL
:
256 if (token_type
!= G_TOKEN_CHAR
) {
257 ini_append_error_expecting(state
,
258 state
->scanner
, "'='");
262 if (state
->scanner
->value
.v_char
!= '=') {
263 ini_append_error_expecting(state
,
264 state
->scanner
, "'='");
268 state
->expecting
= INI_EXPECT_VALUE
;
270 case INI_EXPECT_VALUE
:
272 switch (token_type
) {
274 if (state
->scanner
->value
.v_char
== '-') {
275 /* Negative number */
277 INI_EXPECT_VALUE_NUMBER_NEG
;
280 ini_append_error_expecting(state
,
281 state
->scanner
, "value");
287 /* Positive integer */
288 uint64_t int_val
= state
->scanner
->value
.v_int64
;
290 if (int_val
> (1ULL << 63) - 1) {
291 g_string_append_printf(state
->ini_error
,
292 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
297 value
= bt_private_value_borrow_value(
298 bt_private_value_integer_create_init(
303 /* Positive floating point number */
304 value
= bt_private_value_borrow_value(
305 bt_private_value_real_create_init(
306 state
->scanner
->value
.v_float
));
310 value
= bt_private_value_borrow_value(
311 bt_private_value_string_create_init(
312 state
->scanner
->value
.v_string
));
314 case G_TOKEN_IDENTIFIER
:
317 * Using symbols would be appropriate here,
318 * but said symbols are allowed as map key,
319 * so it's easier to consider everything an
322 * If one of the known symbols is not
323 * recognized here, then fall back to creating
326 const char *id
= state
->scanner
->value
.v_identifier
;
328 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
329 !strcmp(id
, "nul")) {
330 value
= bt_value_null
;
331 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
332 !strcmp(id
, "yes") ||
333 !strcmp(id
, "YES")) {
334 value
= bt_private_value_borrow_value(
335 bt_private_value_bool_create_init(true));
336 } else if (!strcmp(id
, "false") ||
337 !strcmp(id
, "FALSE") ||
340 value
= bt_private_value_borrow_value(
341 bt_private_value_bool_create_init(false));
343 value
= bt_private_value_borrow_value(
344 bt_private_value_string_create_init(id
));
349 /* Unset value variable will trigger the error */
354 ini_append_error_expecting(state
,
355 state
->scanner
, "value");
359 state
->expecting
= INI_EXPECT_COMMA
;
362 case INI_EXPECT_VALUE_NUMBER_NEG
:
364 switch (token_type
) {
367 /* Negative integer */
368 uint64_t int_val
= state
->scanner
->value
.v_int64
;
370 if (int_val
> (1ULL << 63) - 1) {
371 g_string_append_printf(state
->ini_error
,
372 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
377 value
= bt_private_value_borrow_value(
378 bt_private_value_integer_create_init(
379 -((int64_t) int_val
)));
383 /* Negative floating point number */
384 value
= bt_private_value_borrow_value(
385 bt_private_value_real_create_init(
386 -state
->scanner
->value
.v_float
));
389 /* Unset value variable will trigger the error */
394 ini_append_error_expecting(state
,
395 state
->scanner
, "value");
399 state
->expecting
= INI_EXPECT_COMMA
;
402 case INI_EXPECT_COMMA
:
403 if (token_type
!= G_TOKEN_CHAR
) {
404 ini_append_error_expecting(state
,
405 state
->scanner
, "','");
409 if (state
->scanner
->value
.v_char
!= ',') {
410 ini_append_error_expecting(state
,
411 state
->scanner
, "','");
415 state
->expecting
= INI_EXPECT_MAP_KEY
;
427 if (bt_private_value_map_insert_entry(state
->params
,
428 state
->last_map_key
, value
)) {
429 /* Only override return value on error */
435 BT_OBJECT_PUT_REF_AND_RESET(value
);
440 * Converts an INI-style argument to an equivalent map value object.
442 * Return value is owned by the caller.
445 struct bt_private_value
*bt_private_value_from_ini(const char *arg
,
448 /* Lexical scanner configuration */
449 GScannerConfig scanner_config
= {
450 /* Skip whitespaces */
451 .cset_skip_characters
= " \t\n",
453 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
454 .cset_identifier_first
=
458 .cset_identifier_nth
=
463 /* "hello" and "Hello" two different keys */
464 .case_sensitive
= TRUE
,
467 .cpair_comment_single
= NULL
,
468 .skip_comment_multi
= TRUE
,
469 .skip_comment_single
= TRUE
,
470 .scan_comment_multi
= FALSE
,
473 * Do scan identifiers, including 1-char identifiers,
474 * but NULL is a normal identifier.
476 .scan_identifier
= TRUE
,
477 .scan_identifier_1char
= TRUE
,
478 .scan_identifier_NULL
= FALSE
,
481 * No specific symbols: null and boolean "symbols" are
482 * scanned as plain identifiers.
484 .scan_symbols
= FALSE
,
485 .symbol_2_token
= FALSE
,
486 .scope_0_fallback
= FALSE
,
489 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
490 * integers prefixed with "$".
496 .scan_hex_dollar
= FALSE
,
498 /* Convert scanned numbers to integer tokens */
499 .numbers_2_int
= TRUE
,
501 /* Support both integers and floating-point numbers */
502 .int_2_float
= FALSE
,
504 /* Scan integers as 64-bit signed integers */
507 /* Only scan double-quoted strings */
508 .scan_string_sq
= FALSE
,
509 .scan_string_dq
= TRUE
,
511 /* Do not converter identifiers to string tokens */
512 .identifier_2_string
= FALSE
,
514 /* Scan characters as G_TOKEN_CHAR token */
515 .char_2_token
= FALSE
,
517 struct ini_parsing_state state
= {
520 .expecting
= INI_EXPECT_MAP_KEY
,
522 .ini_error
= ini_error
,
525 state
.params
= bt_private_value_map_create();
530 state
.scanner
= g_scanner_new(&scanner_config
);
531 if (!state
.scanner
) {
535 /* Let the scan begin */
536 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
539 int ret
= ini_handle_state(&state
);
544 } else if (ret
> 0) {
553 BT_OBJECT_PUT_REF_AND_RESET(state
.params
);
557 g_scanner_destroy(state
.scanner
);
560 free(state
.last_map_key
);
565 * Returns the parameters map value object from a command-line
566 * parameter option's argument.
568 * Return value is owned by the caller.
571 struct bt_private_value
*bt_private_value_from_arg(const char *arg
)
573 struct bt_private_value
*params
= NULL
;
574 GString
*ini_error
= NULL
;
576 ini_error
= g_string_new(NULL
);
582 /* Try INI-style parsing */
583 params
= bt_private_value_from_ini(arg
, ini_error
);
585 printf_err("%s", ini_error
->str
);
591 g_string_free(ini_error
, TRUE
);
598 * Returns the plugin name, component class name, component class type,
599 * and component name from a command-line --component option's argument.
600 * arg must have the following format:
602 * [NAME:]TYPE.PLUGIN.CLS
604 * where NAME is the optional component name, TYPE is either `source`,
605 * `filter`, or `sink`, PLUGIN is the plugin name, and CLS is the
606 * component class name.
608 * On success, both *plugin and *component are not NULL. *plugin
609 * and *comp_cls are owned by the caller. On success, *name can be NULL
610 * if no component class name was found, and *comp_cls_type is set.
613 void plugin_comp_cls_names(const char *arg
, char **name
, char **plugin
,
614 char **comp_cls
, enum bt_component_class_type
*comp_cls_type
)
616 const char *at
= arg
;
617 GString
*gs_name
= NULL
;
618 GString
*gs_comp_cls_type
= NULL
;
619 GString
*gs_plugin
= NULL
;
620 GString
*gs_comp_cls
= NULL
;
626 BT_ASSERT(comp_cls_type
);
628 if (!bt_common_string_is_printable(arg
)) {
629 printf_err("Argument contains a non-printable character\n");
633 /* Parse the component name */
634 gs_name
= bt_common_string_until(at
, ".:\\", ":", &end_pos
);
639 if (arg
[end_pos
] == ':') {
643 g_string_assign(gs_name
, "");
646 /* Parse the component class type */
647 gs_comp_cls_type
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
648 if (!gs_comp_cls_type
|| at
[end_pos
] == '\0') {
649 printf_err("Missing component class type (`source`, `filter`, or `sink`)\n");
653 if (strcmp(gs_comp_cls_type
->str
, "source") == 0 ||
654 strcmp(gs_comp_cls_type
->str
, "src") == 0) {
655 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
656 } else if (strcmp(gs_comp_cls_type
->str
, "filter") == 0 ||
657 strcmp(gs_comp_cls_type
->str
, "flt") == 0) {
658 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
659 } else if (strcmp(gs_comp_cls_type
->str
, "sink") == 0) {
660 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
662 printf_err("Unknown component class type: `%s`\n",
663 gs_comp_cls_type
->str
);
669 /* Parse the plugin name */
670 gs_plugin
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
671 if (!gs_plugin
|| gs_plugin
->len
== 0 || at
[end_pos
] == '\0') {
672 printf_err("Missing plugin or component class name\n");
678 /* Parse the component class name */
679 gs_comp_cls
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
680 if (!gs_comp_cls
|| gs_comp_cls
->len
== 0) {
681 printf_err("Missing component class name\n");
685 if (at
[end_pos
] != '\0') {
686 /* Found a non-escaped `.` */
691 if (gs_name
->len
== 0) {
693 g_string_free(gs_name
, TRUE
);
695 *name
= gs_name
->str
;
696 g_string_free(gs_name
, FALSE
);
699 g_string_free(gs_name
, TRUE
);
702 *plugin
= gs_plugin
->str
;
703 *comp_cls
= gs_comp_cls
->str
;
704 g_string_free(gs_plugin
, FALSE
);
705 g_string_free(gs_comp_cls
, FALSE
);
721 g_string_free(gs_name
, TRUE
);
725 g_string_free(gs_plugin
, TRUE
);
729 g_string_free(gs_comp_cls
, TRUE
);
732 if (gs_comp_cls_type
) {
733 g_string_free(gs_comp_cls_type
, TRUE
);
740 * Prints the Babeltrace version.
743 void print_version(void)
745 puts("Babeltrace " VERSION
);
749 * Destroys a component configuration.
752 void bt_config_component_destroy(struct bt_object
*obj
)
754 struct bt_config_component
*bt_config_component
=
755 container_of(obj
, struct bt_config_component
, base
);
761 if (bt_config_component
->plugin_name
) {
762 g_string_free(bt_config_component
->plugin_name
, TRUE
);
765 if (bt_config_component
->comp_cls_name
) {
766 g_string_free(bt_config_component
->comp_cls_name
, TRUE
);
769 if (bt_config_component
->instance_name
) {
770 g_string_free(bt_config_component
->instance_name
, TRUE
);
773 BT_OBJECT_PUT_REF_AND_RESET(bt_config_component
->params
);
774 g_free(bt_config_component
);
781 * Creates a component configuration using the given plugin name and
782 * component name. `plugin_name` and `comp_cls_name` are copied (belong
783 * to the return value).
785 * Return value is owned by the caller.
788 struct bt_config_component
*bt_config_component_create(
789 enum bt_component_class_type type
,
790 const char *plugin_name
, const char *comp_cls_name
)
792 struct bt_config_component
*cfg_component
= NULL
;
794 cfg_component
= g_new0(struct bt_config_component
, 1);
795 if (!cfg_component
) {
800 bt_object_init_shared(&cfg_component
->base
,
801 bt_config_component_destroy
);
802 cfg_component
->type
= type
;
803 cfg_component
->plugin_name
= g_string_new(plugin_name
);
804 if (!cfg_component
->plugin_name
) {
809 cfg_component
->comp_cls_name
= g_string_new(comp_cls_name
);
810 if (!cfg_component
->comp_cls_name
) {
815 cfg_component
->instance_name
= g_string_new(NULL
);
816 if (!cfg_component
->instance_name
) {
821 /* Start with empty parameters */
822 cfg_component
->params
= bt_private_value_map_create();
823 if (!cfg_component
->params
) {
831 BT_OBJECT_PUT_REF_AND_RESET(cfg_component
);
834 return cfg_component
;
838 * Creates a component configuration from a command-line --component
842 struct bt_config_component
*bt_config_component_from_arg(const char *arg
)
844 struct bt_config_component
*cfg_comp
= NULL
;
846 char *plugin_name
= NULL
;
847 char *comp_cls_name
= NULL
;
848 enum bt_component_class_type type
;
850 plugin_comp_cls_names(arg
, &name
, &plugin_name
, &comp_cls_name
, &type
);
851 if (!plugin_name
|| !comp_cls_name
) {
855 cfg_comp
= bt_config_component_create(type
, plugin_name
, comp_cls_name
);
861 g_string_assign(cfg_comp
->instance_name
, name
);
867 BT_OBJECT_PUT_REF_AND_RESET(cfg_comp
);
872 g_free(comp_cls_name
);
877 * Destroys a configuration.
880 void bt_config_destroy(struct bt_object
*obj
)
882 struct bt_config
*cfg
=
883 container_of(obj
, struct bt_config
, base
);
889 BT_OBJECT_PUT_REF_AND_RESET(cfg
->plugin_paths
);
891 switch (cfg
->command
) {
892 case BT_CONFIG_COMMAND_RUN
:
893 if (cfg
->cmd_data
.run
.sources
) {
894 g_ptr_array_free(cfg
->cmd_data
.run
.sources
, TRUE
);
897 if (cfg
->cmd_data
.run
.filters
) {
898 g_ptr_array_free(cfg
->cmd_data
.run
.filters
, TRUE
);
901 if (cfg
->cmd_data
.run
.sinks
) {
902 g_ptr_array_free(cfg
->cmd_data
.run
.sinks
, TRUE
);
905 if (cfg
->cmd_data
.run
.connections
) {
906 g_ptr_array_free(cfg
->cmd_data
.run
.connections
,
910 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
912 case BT_CONFIG_COMMAND_HELP
:
913 BT_OBJECT_PUT_REF_AND_RESET(cfg
->cmd_data
.help
.cfg_component
);
915 case BT_CONFIG_COMMAND_QUERY
:
916 BT_OBJECT_PUT_REF_AND_RESET(cfg
->cmd_data
.query
.cfg_component
);
918 if (cfg
->cmd_data
.query
.object
) {
919 g_string_free(cfg
->cmd_data
.query
.object
, TRUE
);
922 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
923 if (cfg
->cmd_data
.print_ctf_metadata
.path
) {
924 g_string_free(cfg
->cmd_data
.print_ctf_metadata
.path
,
927 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
931 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
932 if (cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
934 cfg
->cmd_data
.print_lttng_live_sessions
.url
,
937 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
952 void destroy_glist_of_gstring(GList
*list
)
960 for (at
= list
; at
!= NULL
; at
= g_list_next(at
)) {
961 g_string_free(at
->data
, TRUE
);
968 * Creates a simple lexical scanner for parsing comma-delimited names
971 * Return value is owned by the caller.
974 GScanner
*create_csv_identifiers_scanner(void)
977 GScannerConfig scanner_config
= {
978 .cset_skip_characters
= " \t\n",
979 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
980 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
981 .case_sensitive
= TRUE
,
982 .cpair_comment_single
= NULL
,
983 .skip_comment_multi
= TRUE
,
984 .skip_comment_single
= TRUE
,
985 .scan_comment_multi
= FALSE
,
986 .scan_identifier
= TRUE
,
987 .scan_identifier_1char
= TRUE
,
988 .scan_identifier_NULL
= FALSE
,
989 .scan_symbols
= FALSE
,
990 .symbol_2_token
= FALSE
,
991 .scope_0_fallback
= FALSE
,
992 .scan_binary
= FALSE
,
996 .scan_hex_dollar
= FALSE
,
997 .numbers_2_int
= FALSE
,
998 .int_2_float
= FALSE
,
999 .store_int64
= FALSE
,
1000 .scan_string_sq
= FALSE
,
1001 .scan_string_dq
= FALSE
,
1002 .identifier_2_string
= FALSE
,
1003 .char_2_token
= TRUE
,
1006 scanner
= g_scanner_new(&scanner_config
);
1015 * Converts a comma-delimited list of known names (--names option) to
1016 * an array value object containing those names as string value objects.
1018 * Return value is owned by the caller.
1021 struct bt_private_value
*names_from_arg(const char *arg
)
1023 GScanner
*scanner
= NULL
;
1024 struct bt_private_value
*names
= NULL
;
1025 bool found_all
= false, found_none
= false, found_item
= false;
1027 names
= bt_private_value_array_create();
1033 scanner
= create_csv_identifiers_scanner();
1038 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1041 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1043 switch (token_type
) {
1044 case G_TOKEN_IDENTIFIER
:
1046 const char *identifier
= scanner
->value
.v_identifier
;
1048 if (!strcmp(identifier
, "payload") ||
1049 !strcmp(identifier
, "args") ||
1050 !strcmp(identifier
, "arg")) {
1052 if (bt_private_value_array_append_string_element(names
,
1056 } else if (!strcmp(identifier
, "context") ||
1057 !strcmp(identifier
, "ctx")) {
1059 if (bt_private_value_array_append_string_element(names
,
1063 } else if (!strcmp(identifier
, "scope") ||
1064 !strcmp(identifier
, "header")) {
1066 if (bt_private_value_array_append_string_element(names
,
1070 } else if (!strcmp(identifier
, "all")) {
1072 if (bt_private_value_array_append_string_element(names
,
1076 } else if (!strcmp(identifier
, "none")) {
1078 if (bt_private_value_array_append_string_element(names
,
1083 printf_err("Unknown name: `%s`\n",
1099 if (found_none
&& found_all
) {
1100 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1104 * Legacy behavior is to clear the defaults (show none) when at
1105 * least one item is specified.
1107 if (found_item
&& !found_none
&& !found_all
) {
1108 if (bt_private_value_array_append_string_element(names
, "none")) {
1113 g_scanner_destroy(scanner
);
1118 BT_OBJECT_PUT_REF_AND_RESET(names
);
1120 g_scanner_destroy(scanner
);
1126 * Converts a comma-delimited list of known fields (--fields option) to
1127 * an array value object containing those fields as string
1130 * Return value is owned by the caller.
1133 struct bt_private_value
*fields_from_arg(const char *arg
)
1135 GScanner
*scanner
= NULL
;
1136 struct bt_private_value
*fields
;
1138 fields
= bt_private_value_array_create();
1144 scanner
= create_csv_identifiers_scanner();
1149 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1152 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1154 switch (token_type
) {
1155 case G_TOKEN_IDENTIFIER
:
1157 const char *identifier
= scanner
->value
.v_identifier
;
1159 if (!strcmp(identifier
, "trace") ||
1160 !strcmp(identifier
, "trace:hostname") ||
1161 !strcmp(identifier
, "trace:domain") ||
1162 !strcmp(identifier
, "trace:procname") ||
1163 !strcmp(identifier
, "trace:vpid") ||
1164 !strcmp(identifier
, "loglevel") ||
1165 !strcmp(identifier
, "emf") ||
1166 !strcmp(identifier
, "callsite") ||
1167 !strcmp(identifier
, "all")) {
1168 if (bt_private_value_array_append_string_element(fields
,
1173 printf_err("Unknown field: `%s`\n",
1191 BT_OBJECT_PUT_REF_AND_RESET(fields
);
1195 g_scanner_destroy(scanner
);
1201 void append_param_arg(GString
*params_arg
, const char *key
, const char *value
)
1203 BT_ASSERT(params_arg
);
1207 if (params_arg
->len
!= 0) {
1208 g_string_append_c(params_arg
, ',');
1211 g_string_append(params_arg
, key
);
1212 g_string_append_c(params_arg
, '=');
1213 g_string_append(params_arg
, value
);
1217 * Inserts the equivalent "prefix-NAME=yes" strings into params_arg
1218 * where the names are in names_array.
1221 int insert_flat_params_from_array(GString
*params_arg
,
1222 struct bt_value
*names_array
, const char *prefix
)
1226 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1227 bool default_set
= false, non_default_set
= false;
1230 * names_array may be NULL if no CLI options were specified to
1231 * trigger its creation.
1237 tmpstr
= g_string_new(NULL
);
1244 default_value
= g_string_new(NULL
);
1245 if (!default_value
) {
1251 for (i
= 0; i
< bt_value_array_get_size(names_array
); i
++) {
1252 struct bt_value
*str_obj
=
1253 bt_value_array_borrow_element_by_index(names_array
, i
);
1255 bool is_default
= false;
1258 printf_err("Unexpected error\n");
1263 suffix
= bt_value_string_get(str_obj
);
1265 g_string_assign(tmpstr
, prefix
);
1266 g_string_append(tmpstr
, "-");
1268 /* Special-case for "all" and "none". */
1269 if (!strcmp(suffix
, "all")) {
1271 g_string_assign(default_value
, "show");
1272 } else if (!strcmp(suffix
, "none")) {
1274 g_string_assign(default_value
, "hide");
1278 g_string_append(tmpstr
, "default");
1279 append_param_arg(params_arg
, tmpstr
->str
,
1280 default_value
->str
);
1282 non_default_set
= true;
1283 g_string_append(tmpstr
, suffix
);
1284 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1288 /* Implicit field-default=hide if any non-default option is set. */
1289 if (non_default_set
&& !default_set
) {
1290 g_string_assign(tmpstr
, prefix
);
1291 g_string_append(tmpstr
, "-default");
1292 g_string_assign(default_value
, "hide");
1293 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1297 if (default_value
) {
1298 g_string_free(default_value
, TRUE
);
1302 g_string_free(tmpstr
, TRUE
);
1315 OPT_CLOCK_FORCE_CORRELATE
,
1318 OPT_CLOCK_OFFSET_NS
,
1326 OPT_DEBUG_INFO_FULL_PATH
,
1327 OPT_DEBUG_INFO_TARGET_PREFIX
,
1337 OPT_OMIT_HOME_PLUGIN_PATH
,
1338 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1344 OPT_RESET_BASE_PARAMS
,
1348 OPT_STREAM_INTERSECTION
,
1355 enum bt_config_component_dest
{
1356 BT_CONFIG_COMPONENT_DEST_UNKNOWN
= -1,
1357 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1358 BT_CONFIG_COMPONENT_DEST_FILTER
,
1359 BT_CONFIG_COMPONENT_DEST_SINK
,
1363 * Adds a configuration component to the appropriate configuration
1364 * array depending on the destination.
1367 void add_run_cfg_comp(struct bt_config
*cfg
,
1368 struct bt_config_component
*cfg_comp
,
1369 enum bt_config_component_dest dest
)
1371 bt_object_get_ref(cfg_comp
);
1374 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1375 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1377 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1378 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1380 case BT_CONFIG_COMPONENT_DEST_SINK
:
1381 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1389 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1390 struct bt_config_component
*cfg_comp
,
1391 enum bt_config_component_dest dest
,
1392 struct bt_private_value
*instance_names
)
1396 if (cfg_comp
->instance_name
->len
== 0) {
1397 printf_err("Found an unnamed component\n");
1402 if (bt_value_map_has_entry(bt_private_value_borrow_value(instance_names
),
1403 cfg_comp
->instance_name
->str
)) {
1404 printf_err("Duplicate component instance name:\n %s\n",
1405 cfg_comp
->instance_name
->str
);
1410 if (bt_private_value_map_insert_entry(instance_names
,
1411 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1417 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1424 int append_env_var_plugin_paths(struct bt_private_value
*plugin_paths
)
1429 if (bt_common_is_setuid_setgid()) {
1430 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1434 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1439 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1443 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1450 int append_home_and_system_plugin_paths(struct bt_private_value
*plugin_paths
,
1451 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1455 if (!omit_home_plugin_path
) {
1456 if (bt_common_is_setuid_setgid()) {
1457 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1459 char *home_plugin_dir
=
1460 bt_common_get_home_plugin_path();
1462 if (home_plugin_dir
) {
1463 ret
= bt_config_append_plugin_paths(
1464 plugin_paths
, home_plugin_dir
);
1465 free(home_plugin_dir
);
1468 printf_err("Invalid home plugin path\n");
1475 if (!omit_system_plugin_path
) {
1476 if (bt_config_append_plugin_paths(plugin_paths
,
1477 bt_common_get_system_plugin_path())) {
1478 printf_err("Invalid system plugin path\n");
1484 printf_err("Cannot append home and system plugin paths\n");
1489 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1491 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1492 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1496 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1497 struct bt_private_value
*initial_plugin_paths
,
1500 struct bt_config
*cfg
;
1503 cfg
= g_new0(struct bt_config
, 1);
1509 bt_object_init_shared(&cfg
->base
, bt_config_destroy
);
1510 cfg
->command
= command
;
1511 cfg
->command_needs_plugins
= needs_plugins
;
1513 if (initial_plugin_paths
) {
1514 cfg
->plugin_paths
= bt_object_get_ref(initial_plugin_paths
);
1516 cfg
->plugin_paths
= bt_private_value_array_create();
1517 if (!cfg
->plugin_paths
) {
1526 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1533 struct bt_config
*bt_config_run_create(
1534 struct bt_private_value
*initial_plugin_paths
)
1536 struct bt_config
*cfg
;
1539 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1540 initial_plugin_paths
, true);
1545 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1546 (GDestroyNotify
) bt_object_put_ref
);
1547 if (!cfg
->cmd_data
.run
.sources
) {
1552 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1553 (GDestroyNotify
) bt_object_put_ref
);
1554 if (!cfg
->cmd_data
.run
.filters
) {
1559 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1560 (GDestroyNotify
) bt_object_put_ref
);
1561 if (!cfg
->cmd_data
.run
.sinks
) {
1566 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1567 (GDestroyNotify
) bt_config_connection_destroy
);
1568 if (!cfg
->cmd_data
.run
.connections
) {
1576 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1583 struct bt_config
*bt_config_list_plugins_create(
1584 struct bt_private_value
*initial_plugin_paths
)
1586 struct bt_config
*cfg
;
1589 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1590 initial_plugin_paths
, true);
1598 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1605 struct bt_config
*bt_config_help_create(
1606 struct bt_private_value
*initial_plugin_paths
)
1608 struct bt_config
*cfg
;
1611 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1612 initial_plugin_paths
, true);
1617 cfg
->cmd_data
.help
.cfg_component
=
1618 bt_config_component_create(-1, NULL
, NULL
);
1619 if (!cfg
->cmd_data
.help
.cfg_component
) {
1626 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1633 struct bt_config
*bt_config_query_create(
1634 struct bt_private_value
*initial_plugin_paths
)
1636 struct bt_config
*cfg
;
1639 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1640 initial_plugin_paths
, true);
1645 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1646 if (!cfg
->cmd_data
.query
.object
) {
1654 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1661 struct bt_config
*bt_config_print_ctf_metadata_create(
1662 struct bt_private_value
*initial_plugin_paths
)
1664 struct bt_config
*cfg
;
1667 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1668 initial_plugin_paths
, true);
1673 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1674 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1679 cfg
->cmd_data
.print_ctf_metadata
.output_path
= g_string_new(NULL
);
1680 if (!cfg
->cmd_data
.print_ctf_metadata
.output_path
) {
1688 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1695 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1696 struct bt_private_value
*initial_plugin_paths
)
1698 struct bt_config
*cfg
;
1701 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1702 initial_plugin_paths
, true);
1707 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1708 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1713 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
=
1715 if (!cfg
->cmd_data
.print_lttng_live_sessions
.output_path
) {
1723 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1730 int bt_config_append_plugin_paths_check_setuid_setgid(
1731 struct bt_private_value
*plugin_paths
, const char *arg
)
1735 if (bt_common_is_setuid_setgid()) {
1736 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1740 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1741 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1752 * Prints the expected format for a --params option.
1755 void print_expected_params_format(FILE *fp
)
1757 fprintf(fp
, "Expected format of PARAMS\n");
1758 fprintf(fp
, "-------------------------\n");
1760 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1762 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1763 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1764 fprintf(fp
, "and VALUE can be one of:\n");
1766 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1767 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1768 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1769 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1770 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1771 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1772 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1773 fprintf(fp
, " the null and boolean value symbols above.\n");
1774 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1776 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1778 fprintf(fp
, "Example:\n");
1780 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1781 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1782 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1784 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1785 fprintf(fp
, "babeltrace from a shell.\n");
1790 * Prints the help command usage.
1793 void print_help_usage(FILE *fp
)
1795 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1796 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] TYPE.PLUGIN.CLS\n");
1798 fprintf(fp
, "Options:\n");
1800 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1801 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1802 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1803 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1804 fprintf(fp
, " dynamic plugins can be loaded\n");
1805 fprintf(fp
, " -h, --help Show this help and quit\n");
1807 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1809 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1813 struct poptOption help_long_options
[] = {
1814 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1815 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1816 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1817 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1818 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1819 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1823 * Creates a Babeltrace config object from the arguments of a help
1826 * *retcode is set to the appropriate exit code to use.
1829 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1830 int *retcode
, bool force_omit_system_plugin_path
,
1831 bool force_omit_home_plugin_path
,
1832 struct bt_private_value
*initial_plugin_paths
)
1834 poptContext pc
= NULL
;
1838 struct bt_config
*cfg
= NULL
;
1839 const char *leftover
;
1840 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1843 cfg
= bt_config_help_create(initial_plugin_paths
);
1848 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1849 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1850 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1856 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1857 help_long_options
, 0);
1859 printf_err("Cannot get popt context\n");
1863 poptReadDefaultConfig(pc
, 0);
1865 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1866 arg
= poptGetOptArg(pc
);
1869 case OPT_PLUGIN_PATH
:
1870 if (bt_config_append_plugin_paths_check_setuid_setgid(
1871 cfg
->plugin_paths
, arg
)) {
1875 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1876 cfg
->omit_system_plugin_path
= true;
1878 case OPT_OMIT_HOME_PLUGIN_PATH
:
1879 cfg
->omit_home_plugin_path
= true;
1882 print_help_usage(stdout
);
1884 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1887 printf_err("Unknown command-line option specified (option code %d)\n",
1896 /* Check for option parsing error */
1898 printf_err("While parsing command-line options, at option %s: %s\n",
1899 poptBadOption(pc
, 0), poptStrerror(opt
));
1903 leftover
= poptGetArg(pc
);
1905 plugin_comp_cls_names(leftover
, NULL
,
1906 &plugin_name
, &comp_cls_name
,
1907 &cfg
->cmd_data
.help
.cfg_component
->type
);
1908 if (plugin_name
&& comp_cls_name
) {
1909 /* Component class help */
1911 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1914 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1917 /* Fall back to plugin help */
1919 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1923 print_help_usage(stdout
);
1925 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1929 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1937 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1940 g_free(plugin_name
);
1941 g_free(comp_cls_name
);
1944 poptFreeContext(pc
);
1952 * Prints the help command usage.
1955 void print_query_usage(FILE *fp
)
1957 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] TYPE.PLUGIN.CLS OBJECT\n");
1959 fprintf(fp
, "Options:\n");
1961 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1962 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1963 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1964 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1965 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1966 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1967 fprintf(fp
, " dynamic plugins can be loaded\n");
1968 fprintf(fp
, " -h, --help Show this help and quit\n");
1969 fprintf(fp
, "\n\n");
1970 print_expected_params_format(fp
);
1974 struct poptOption query_long_options
[] = {
1975 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1976 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1977 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1978 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1979 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1980 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1981 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1985 * Creates a Babeltrace config object from the arguments of a query
1988 * *retcode is set to the appropriate exit code to use.
1991 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1992 int *retcode
, bool force_omit_system_plugin_path
,
1993 bool force_omit_home_plugin_path
,
1994 struct bt_private_value
*initial_plugin_paths
)
1996 poptContext pc
= NULL
;
2000 struct bt_config
*cfg
= NULL
;
2001 const char *leftover
;
2002 struct bt_private_value
*params
= bt_private_value_null
;
2005 cfg
= bt_config_query_create(initial_plugin_paths
);
2010 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2011 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2012 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2018 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2019 query_long_options
, 0);
2021 printf_err("Cannot get popt context\n");
2025 poptReadDefaultConfig(pc
, 0);
2027 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2028 arg
= poptGetOptArg(pc
);
2031 case OPT_PLUGIN_PATH
:
2032 if (bt_config_append_plugin_paths_check_setuid_setgid(
2033 cfg
->plugin_paths
, arg
)) {
2037 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2038 cfg
->omit_system_plugin_path
= true;
2040 case OPT_OMIT_HOME_PLUGIN_PATH
:
2041 cfg
->omit_home_plugin_path
= true;
2045 bt_object_put_ref(params
);
2046 params
= bt_private_value_from_arg(arg
);
2048 printf_err("Invalid format for --params option's argument:\n %s\n",
2055 print_query_usage(stdout
);
2057 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2060 printf_err("Unknown command-line option specified (option code %d)\n",
2069 /* Check for option parsing error */
2071 printf_err("While parsing command-line options, at option %s: %s\n",
2072 poptBadOption(pc
, 0), poptStrerror(opt
));
2077 * We need exactly two leftover arguments which are the
2078 * mandatory component class specification and query object.
2080 leftover
= poptGetArg(pc
);
2082 cfg
->cmd_data
.query
.cfg_component
=
2083 bt_config_component_from_arg(leftover
);
2084 if (!cfg
->cmd_data
.query
.cfg_component
) {
2085 printf_err("Invalid format for component class specification:\n %s\n",
2091 BT_OBJECT_MOVE_REF(cfg
->cmd_data
.query
.cfg_component
->params
,
2094 print_query_usage(stdout
);
2096 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2100 leftover
= poptGetArg(pc
);
2102 if (strlen(leftover
) == 0) {
2103 printf_err("Invalid empty object\n");
2107 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2109 print_query_usage(stdout
);
2111 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2115 leftover
= poptGetArg(pc
);
2117 printf_err("Unexpected argument: %s\n", leftover
);
2121 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2129 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2133 poptFreeContext(pc
);
2136 bt_object_put_ref(params
);
2142 * Prints the list-plugins command usage.
2145 void print_list_plugins_usage(FILE *fp
)
2147 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2149 fprintf(fp
, "Options:\n");
2151 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2152 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2153 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2154 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2155 fprintf(fp
, " dynamic plugins can be loaded\n");
2156 fprintf(fp
, " -h, --help Show this help and quit\n");
2158 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2160 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2164 struct poptOption list_plugins_long_options
[] = {
2165 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2166 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2167 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2168 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2169 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2170 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2174 * Creates a Babeltrace config object from the arguments of a
2175 * list-plugins command.
2177 * *retcode is set to the appropriate exit code to use.
2180 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2181 int *retcode
, bool force_omit_system_plugin_path
,
2182 bool force_omit_home_plugin_path
,
2183 struct bt_private_value
*initial_plugin_paths
)
2185 poptContext pc
= NULL
;
2189 struct bt_config
*cfg
= NULL
;
2190 const char *leftover
;
2193 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2198 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2199 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2200 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2206 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2207 list_plugins_long_options
, 0);
2209 printf_err("Cannot get popt context\n");
2213 poptReadDefaultConfig(pc
, 0);
2215 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2216 arg
= poptGetOptArg(pc
);
2219 case OPT_PLUGIN_PATH
:
2220 if (bt_config_append_plugin_paths_check_setuid_setgid(
2221 cfg
->plugin_paths
, arg
)) {
2225 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2226 cfg
->omit_system_plugin_path
= true;
2228 case OPT_OMIT_HOME_PLUGIN_PATH
:
2229 cfg
->omit_home_plugin_path
= true;
2232 print_list_plugins_usage(stdout
);
2234 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2237 printf_err("Unknown command-line option specified (option code %d)\n",
2246 /* Check for option parsing error */
2248 printf_err("While parsing command-line options, at option %s: %s\n",
2249 poptBadOption(pc
, 0), poptStrerror(opt
));
2253 leftover
= poptGetArg(pc
);
2255 printf_err("Unexpected argument: %s\n", leftover
);
2259 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2267 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2271 poptFreeContext(pc
);
2279 * Prints the run command usage.
2282 void print_run_usage(FILE *fp
)
2284 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2286 fprintf(fp
, "Options:\n");
2288 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2289 fprintf(fp
, " for all the following components until\n");
2290 fprintf(fp
, " --reset-base-params is encountered\n");
2291 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2292 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2293 fprintf(fp
, " Instantiate the component class CLS of type\n");
2294 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2295 fprintf(fp
, " in the plugin PLUGIN, add it to the graph,\n");
2296 fprintf(fp
, " and optionally name it NAME (you can also\n");
2297 fprintf(fp
, " specify the name with --name)\n");
2298 fprintf(fp
, " -C, --connect=CONNECTION Connect two created components (see the\n");
2299 fprintf(fp
, " expected format of CONNECTION below)\n");
2300 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2301 fprintf(fp
, " parameter key to KEY (see --value)\n");
2302 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2303 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2304 fprintf(fp
, " names of the created components)\n");
2305 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2306 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2307 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2308 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2309 fprintf(fp
, " current component (see the expected format\n");
2310 fprintf(fp
, " of PARAMS below)\n");
2311 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2312 fprintf(fp
, " dynamic plugins can be loaded\n");
2313 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2314 fprintf(fp
, " empty map\n");
2315 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2316 fprintf(fp
, " the graph later, retry in DUR µs\n");
2317 fprintf(fp
, " (default: 100000)\n");
2318 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2319 fprintf(fp
, " the current component with a name given by\n");
2320 fprintf(fp
, " the last argument of the --key option and a\n");
2321 fprintf(fp
, " value set to VAL\n");
2322 fprintf(fp
, " -h, --help Show this help and quit\n");
2324 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2325 fprintf(fp
, "\n\n");
2326 fprintf(fp
, "Expected format of CONNECTION\n");
2327 fprintf(fp
, "-----------------------------\n");
2329 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2331 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2332 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2333 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2334 fprintf(fp
, "component with the --name option.\n");
2336 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2337 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2338 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2340 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2341 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2342 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2343 fprintf(fp
, "DOWNSTREAM.\n");
2345 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2346 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2347 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2349 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2350 fprintf(fp
, "can connect a filter component to a sink component.\n");
2352 fprintf(fp
, "Examples:\n");
2354 fprintf(fp
, " my-src:my-sink\n");
2355 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2357 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2358 fprintf(fp
, "babeltrace from a shell.\n");
2359 fprintf(fp
, "\n\n");
2360 print_expected_params_format(fp
);
2364 * Creates a Babeltrace config object from the arguments of a run
2367 * *retcode is set to the appropriate exit code to use.
2370 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2371 int *retcode
, bool force_omit_system_plugin_path
,
2372 bool force_omit_home_plugin_path
,
2373 struct bt_private_value
*initial_plugin_paths
)
2375 poptContext pc
= NULL
;
2377 struct bt_config_component
*cur_cfg_comp
= NULL
;
2378 enum bt_config_component_dest cur_cfg_comp_dest
=
2379 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
2380 struct bt_private_value
*cur_base_params
= NULL
;
2382 struct bt_config
*cfg
= NULL
;
2383 struct bt_private_value
*instance_names
= NULL
;
2384 struct bt_private_value
*connection_args
= NULL
;
2385 GString
*cur_param_key
= NULL
;
2386 char error_buf
[256] = { 0 };
2387 long retry_duration
= -1;
2388 enum bt_value_status status
;
2389 struct poptOption run_long_options
[] = {
2390 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2391 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2392 { "connect", 'C', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2393 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2394 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2395 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2396 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2397 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2398 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2399 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2400 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2401 { "retry-duration", '\0', POPT_ARG_LONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2402 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2403 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2407 cur_param_key
= g_string_new(NULL
);
2408 if (!cur_param_key
) {
2414 print_run_usage(stdout
);
2419 cfg
= bt_config_run_create(initial_plugin_paths
);
2424 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2425 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2426 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2427 cur_base_params
= bt_private_value_map_create();
2428 if (!cur_base_params
) {
2433 instance_names
= bt_private_value_map_create();
2434 if (!instance_names
) {
2439 connection_args
= bt_private_value_array_create();
2440 if (!connection_args
) {
2445 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2451 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2452 run_long_options
, 0);
2454 printf_err("Cannot get popt context\n");
2458 poptReadDefaultConfig(pc
, 0);
2460 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2461 arg
= poptGetOptArg(pc
);
2464 case OPT_PLUGIN_PATH
:
2465 if (bt_config_append_plugin_paths_check_setuid_setgid(
2466 cfg
->plugin_paths
, arg
)) {
2470 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2471 cfg
->omit_system_plugin_path
= true;
2473 case OPT_OMIT_HOME_PLUGIN_PATH
:
2474 cfg
->omit_home_plugin_path
= true;
2478 enum bt_config_component_dest new_dest
;
2481 ret
= add_run_cfg_comp_check_name(cfg
,
2482 cur_cfg_comp
, cur_cfg_comp_dest
,
2484 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2490 cur_cfg_comp
= bt_config_component_from_arg(arg
);
2491 if (!cur_cfg_comp
) {
2492 printf_err("Invalid format for --component option's argument:\n %s\n",
2497 switch (cur_cfg_comp
->type
) {
2498 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
2499 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2501 case BT_COMPONENT_CLASS_TYPE_FILTER
:
2502 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2504 case BT_COMPONENT_CLASS_TYPE_SINK
:
2505 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2511 BT_ASSERT(cur_base_params
);
2512 bt_object_put_ref(cur_cfg_comp
->params
);
2513 status
= bt_value_copy(
2514 &cur_cfg_comp
->params
,
2515 bt_private_value_borrow_value(cur_base_params
));
2516 if (status
!= BT_VALUE_STATUS_OK
) {
2521 cur_cfg_comp_dest
= new_dest
;
2526 struct bt_private_value
*params
;
2527 struct bt_private_value
*params_to_set
;
2529 if (!cur_cfg_comp
) {
2530 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2535 params
= bt_private_value_from_arg(arg
);
2537 printf_err("Invalid format for --params option's argument:\n %s\n",
2542 status
= bt_value_map_extend(¶ms_to_set
,
2543 bt_private_value_borrow_value(cur_cfg_comp
->params
),
2544 bt_private_value_borrow_value(params
));
2545 BT_OBJECT_PUT_REF_AND_RESET(params
);
2546 if (status
!= BT_VALUE_STATUS_OK
) {
2547 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2552 BT_OBJECT_MOVE_REF(cur_cfg_comp
->params
, params_to_set
);
2556 if (strlen(arg
) == 0) {
2557 printf_err("Cannot set an empty string as the current parameter key\n");
2561 g_string_assign(cur_param_key
, arg
);
2564 if (!cur_cfg_comp
) {
2565 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2570 if (cur_param_key
->len
== 0) {
2571 printf_err("--value option specified without preceding --key option:\n %s\n",
2576 if (bt_private_value_map_insert_string_entry(cur_cfg_comp
->params
,
2577 cur_param_key
->str
, arg
)) {
2583 if (!cur_cfg_comp
) {
2584 printf_err("Cannot set the name of unavailable component:\n %s\n",
2589 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2591 case OPT_BASE_PARAMS
:
2593 struct bt_private_value
*params
=
2594 bt_private_value_from_arg(arg
);
2597 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2602 BT_OBJECT_MOVE_REF(cur_base_params
, params
);
2605 case OPT_RESET_BASE_PARAMS
:
2606 BT_OBJECT_PUT_REF_AND_RESET(cur_base_params
);
2607 cur_base_params
= bt_private_value_map_create();
2608 if (!cur_base_params
) {
2614 if (bt_private_value_array_append_string_element(
2615 connection_args
, arg
)) {
2620 case OPT_RETRY_DURATION
:
2621 if (retry_duration
< 0) {
2622 printf_err("--retry-duration option's argument must be positive or 0: %ld\n",
2627 cfg
->cmd_data
.run
.retry_duration_us
=
2628 (uint64_t) retry_duration
;
2631 print_run_usage(stdout
);
2633 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2636 printf_err("Unknown command-line option specified (option code %d)\n",
2645 /* Check for option parsing error */
2647 printf_err("While parsing command-line options, at option %s: %s\n",
2648 poptBadOption(pc
, 0), poptStrerror(opt
));
2652 /* This command does not accept leftover arguments */
2653 if (poptPeekArg(pc
)) {
2654 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2658 /* Add current component */
2660 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2661 cur_cfg_comp_dest
, instance_names
);
2662 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2668 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2669 printf_err("Incomplete graph: no source component\n");
2673 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2674 printf_err("Incomplete graph: no sink component\n");
2678 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2682 ret
= bt_config_cli_args_create_connections(cfg
,
2683 bt_private_value_borrow_value(connection_args
),
2686 printf_err("Cannot creation connections:\n%s", error_buf
);
2694 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2698 poptFreeContext(pc
);
2701 if (cur_param_key
) {
2702 g_string_free(cur_param_key
, TRUE
);
2706 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2707 BT_OBJECT_PUT_REF_AND_RESET(cur_base_params
);
2708 BT_OBJECT_PUT_REF_AND_RESET(instance_names
);
2709 BT_OBJECT_PUT_REF_AND_RESET(connection_args
);
2714 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2715 int *retcode
, bool force_omit_system_plugin_path
,
2716 bool force_omit_home_plugin_path
,
2717 struct bt_private_value
*initial_plugin_paths
)
2719 struct bt_config
*cfg
= NULL
;
2722 const size_t argc
= bt_value_array_get_size(run_args
) + 1;
2724 argv
= calloc(argc
, sizeof(*argv
));
2732 len
= bt_value_array_get_size(run_args
);
2734 printf_err("Invalid executable arguments\n");
2737 for (i
= 0; i
< len
; i
++) {
2738 struct bt_value
*arg_value
=
2739 bt_value_array_borrow_element_by_index(run_args
, i
);
2742 BT_ASSERT(arg_value
);
2743 arg
= bt_value_string_get(arg_value
);
2748 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2749 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2750 initial_plugin_paths
);
2758 * Prints the convert command usage.
2761 void print_convert_usage(FILE *fp
)
2763 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2765 fprintf(fp
, "Options:\n");
2767 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2768 fprintf(fp
, " Instantiate the component class CLS of type\n");
2769 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2770 fprintf(fp
, " in the plugin PLUGIN, add it to the\n");
2771 fprintf(fp
, " conversion graph, and optionally name it\n");
2772 fprintf(fp
, " NAME (you can also specify the name with\n");
2773 fprintf(fp
, " --name)\n");
2774 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2775 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2776 fprintf(fp
, " names of the created components)\n");
2777 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2778 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2779 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2780 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2781 fprintf(fp
, " current component (see the expected format\n");
2782 fprintf(fp
, " of PARAMS below)\n");
2783 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2784 fprintf(fp
, " current component to PATH\n");
2785 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2786 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2787 fprintf(fp
, " the graph later, retry in DUR µs\n");
2788 fprintf(fp
, " (default: 100000)\n");
2789 fprintf(fp
, " dynamic plugins can be loaded\n");
2790 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2791 fprintf(fp
, " `run` command to the standard output,\n");
2792 fprintf(fp
, " formatted for a shell, and quit\n");
2793 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2794 fprintf(fp
, " `run` command to the standard output,\n");
2795 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2796 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2797 fprintf(fp
, " are active\n");
2798 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2799 fprintf(fp
, " current component to URL\n");
2800 fprintf(fp
, " -h, --help Show this help and quit\n");
2802 fprintf(fp
, "Implicit `source.ctf.fs` component options:\n");
2804 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2805 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2807 fprintf(fp
, "Implicit `sink.text.pretty` component options:\n");
2809 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2810 fprintf(fp
, " --clock-date Print timestamp dates\n");
2811 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2812 fprintf(fp
, " time zone instead of the local time zone\n");
2813 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2814 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2815 fprintf(fp
, " --color=(never | auto | always)\n");
2816 fprintf(fp
, " Never, automatically, or always emit\n");
2817 fprintf(fp
, " console color codes\n");
2818 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2819 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2820 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2821 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2822 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2823 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2824 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2825 fprintf(fp
, " (or `ctx`)\n");
2826 fprintf(fp
, " --no-delta Do not print time delta between\n");
2827 fprintf(fp
, " consecutive events\n");
2828 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2829 fprintf(fp
, " the standard output\n");
2831 fprintf(fp
, "Implicit `filter.utils.muxer` component options:\n");
2833 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2834 fprintf(fp
, " correlated across traces\n");
2836 fprintf(fp
, "Implicit `filter.utils.trimmer` component options:\n");
2838 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2839 fprintf(fp
, " time range to BEGIN (see the format of\n");
2840 fprintf(fp
, " BEGIN below)\n");
2841 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2842 fprintf(fp
, " range to END (see the format of END below)\n");
2843 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2844 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2845 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2847 fprintf(fp
, "Implicit `filter.lttng-utils.debug-info` component options:\n");
2849 fprintf(fp
, " --debug-info Create an implicit\n");
2850 fprintf(fp
, " `filter.lttng-utils.debug-info` component\n");
2851 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2852 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2853 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2854 fprintf(fp
, " binary paths instead of just names\n");
2855 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2856 fprintf(fp
, " Use directory DIR as a prefix when\n");
2857 fprintf(fp
, " looking up executables during debug\n");
2858 fprintf(fp
, " info analysis\n");
2860 fprintf(fp
, "Legacy options that still work:\n");
2862 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2863 fprintf(fp
, " `ctf`:\n");
2864 fprintf(fp
, " Create an implicit `source.ctf.fs`\n");
2865 fprintf(fp
, " component\n");
2866 fprintf(fp
, " `lttng-live`:\n");
2867 fprintf(fp
, " Create an implicit `source.ctf.lttng-live`\n");
2868 fprintf(fp
, " component\n");
2869 fprintf(fp
, " -o, --output-format=(text | ctf | dummy | ctf-metadata)\n");
2870 fprintf(fp
, " `text`:\n");
2871 fprintf(fp
, " Create an implicit `sink.text.pretty`\n");
2872 fprintf(fp
, " component\n");
2873 fprintf(fp
, " `ctf`:\n");
2874 fprintf(fp
, " Create an implicit `sink.ctf.fs`\n");
2875 fprintf(fp
, " component\n");
2876 fprintf(fp
, " `dummy`:\n");
2877 fprintf(fp
, " Create an implicit `sink.utils.dummy`\n");
2878 fprintf(fp
, " component\n");
2879 fprintf(fp
, " `ctf-metadata`:\n");
2880 fprintf(fp
, " Query the `source.ctf.fs` component class\n");
2881 fprintf(fp
, " for metadata text and quit\n");
2883 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2884 fprintf(fp
, "\n\n");
2885 fprintf(fp
, "Format of BEGIN and END\n");
2886 fprintf(fp
, "-----------------------\n");
2888 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2889 fprintf(fp
, "\n\n");
2890 print_expected_params_format(fp
);
2894 struct poptOption convert_long_options
[] = {
2895 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2896 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2897 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2898 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2899 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2900 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2901 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2902 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2903 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2904 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2905 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2906 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2907 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2908 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2909 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2910 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2911 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2912 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2913 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2914 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2915 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2916 { "debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO
, NULL
, NULL
},
2917 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2918 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2919 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2920 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2921 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2922 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2923 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2924 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2925 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2926 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2927 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2928 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2929 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2930 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2931 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2932 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2936 GString
*get_component_auto_name(const char *prefix
,
2937 struct bt_value
*existing_names
)
2940 GString
*auto_name
= g_string_new(NULL
);
2947 if (!bt_value_map_has_entry(existing_names
, prefix
)) {
2948 g_string_assign(auto_name
, prefix
);
2953 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2955 } while (bt_value_map_has_entry(existing_names
, auto_name
->str
));
2961 struct implicit_component_args
{
2965 GString
*params_arg
;
2966 struct bt_private_value
*extra_params
;
2970 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
2971 const char *prefix
, struct bt_private_value
*existing_names
,
2972 GList
**comp_names
, bool append_to_comp_names
)
2975 GString
*name
= NULL
;
2977 if (!args
->exists
) {
2981 name
= get_component_auto_name(prefix
,
2982 bt_private_value_borrow_value(existing_names
));
2989 g_string_assign(args
->name_arg
, name
->str
);
2991 if (bt_private_value_map_insert_entry(existing_names
, name
->str
,
2998 if (append_to_comp_names
) {
2999 *comp_names
= g_list_append(*comp_names
, name
);
3005 g_string_free(name
, TRUE
);
3012 int append_run_args_for_implicit_component(
3013 struct implicit_component_args
*impl_args
,
3014 struct bt_private_value
*run_args
)
3019 if (!impl_args
->exists
) {
3023 if (bt_private_value_array_append_string_element(run_args
, "--component")) {
3028 if (bt_private_value_array_append_string_element(run_args
, impl_args
->comp_arg
->str
)) {
3033 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3038 if (bt_private_value_array_append_string_element(run_args
, impl_args
->name_arg
->str
)) {
3043 if (impl_args
->params_arg
->len
> 0) {
3044 if (bt_private_value_array_append_string_element(run_args
, "--params")) {
3049 if (bt_private_value_array_append_string_element(run_args
,
3050 impl_args
->params_arg
->str
)) {
3056 for (i
= 0; i
< bt_value_array_get_size(
3057 bt_private_value_borrow_value(impl_args
->extra_params
));
3059 struct bt_value
*elem
;
3062 elem
= bt_value_array_borrow_element_by_index(
3063 bt_private_value_borrow_value(impl_args
->extra_params
),
3069 BT_ASSERT(bt_value_is_string(elem
));
3070 arg
= bt_value_string_get(elem
);
3071 ret
= bt_private_value_array_append_string_element(run_args
, arg
);
3088 void finalize_implicit_component_args(struct implicit_component_args
*args
)
3092 if (args
->comp_arg
) {
3093 g_string_free(args
->comp_arg
, TRUE
);
3096 if (args
->name_arg
) {
3097 g_string_free(args
->name_arg
, TRUE
);
3100 if (args
->params_arg
) {
3101 g_string_free(args
->params_arg
, TRUE
);
3104 bt_object_put_ref(args
->extra_params
);
3108 void destroy_implicit_component_args(void *args
)
3114 finalize_implicit_component_args(args
);
3119 int init_implicit_component_args(struct implicit_component_args
*args
,
3120 const char *comp_arg
, bool exists
)
3124 args
->exists
= exists
;
3125 args
->comp_arg
= g_string_new(comp_arg
);
3126 args
->name_arg
= g_string_new(NULL
);
3127 args
->params_arg
= g_string_new(NULL
);
3128 args
->extra_params
= bt_private_value_array_create();
3130 if (!args
->comp_arg
|| !args
->name_arg
||
3131 !args
->params_arg
|| !args
->extra_params
) {
3133 finalize_implicit_component_args(args
);
3143 void append_implicit_component_param(struct implicit_component_args
*args
,
3144 const char *key
, const char *value
)
3149 append_param_arg(args
->params_arg
, key
, value
);
3153 int append_implicit_component_extra_param(struct implicit_component_args
*args
,
3154 const char *key
, const char *value
)
3162 if (bt_private_value_array_append_string_element(args
->extra_params
, "--key")) {
3168 if (bt_private_value_array_append_string_element(args
->extra_params
, key
)) {
3174 if (bt_private_value_array_append_string_element(args
->extra_params
, "--value")) {
3180 if (bt_private_value_array_append_string_element(args
->extra_params
, value
)) {
3191 int convert_append_name_param(enum bt_config_component_dest dest
,
3192 GString
*cur_name
, GString
*cur_name_prefix
,
3193 struct bt_private_value
*run_args
,
3194 struct bt_private_value
*all_names
,
3195 GList
**source_names
, GList
**filter_names
,
3200 if (cur_name_prefix
->len
> 0) {
3201 /* We're after a --component option */
3202 GString
*name
= NULL
;
3203 bool append_name_opt
= false;
3205 if (cur_name
->len
== 0) {
3207 * No explicit name was provided for the user
3210 name
= get_component_auto_name(cur_name_prefix
->str
,
3211 bt_private_value_borrow_value(all_names
));
3212 append_name_opt
= true;
3215 * An explicit name was provided for the user
3218 if (bt_value_map_has_entry(
3219 bt_private_value_borrow_value(all_names
),
3221 printf_err("Duplicate component instance name:\n %s\n",
3226 name
= g_string_new(cur_name
->str
);
3235 * Remember this name globally, for the uniqueness of
3236 * all component names.
3238 if (bt_private_value_map_insert_entry(all_names
, name
->str
, bt_value_null
)) {
3244 * Append the --name option if necessary.
3246 if (append_name_opt
) {
3247 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3252 if (bt_private_value_array_append_string_element(run_args
, name
->str
)) {
3259 * Remember this name specifically for the type of the
3260 * component. This is to create connection arguments.
3263 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3264 *source_names
= g_list_append(*source_names
, name
);
3266 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3267 *filter_names
= g_list_append(*filter_names
, name
);
3269 case BT_CONFIG_COMPONENT_DEST_SINK
:
3270 *sink_names
= g_list_append(*sink_names
, name
);
3276 g_string_assign(cur_name_prefix
, "");
3289 * Escapes `.`, `:`, and `\` of `input` with `\`.
3292 GString
*escape_dot_colon(const char *input
)
3294 GString
*output
= g_string_new(NULL
);
3302 for (ch
= input
; *ch
!= '\0'; ch
++) {
3303 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3304 g_string_append_c(output
, '\\');
3307 g_string_append_c(output
, *ch
);
3315 * Appends a --connect option to a list of arguments. `upstream_name`
3316 * and `downstream_name` are escaped with escape_dot_colon() in this
3320 int append_connect_arg(struct bt_private_value
*run_args
,
3321 const char *upstream_name
, const char *downstream_name
)
3324 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3325 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3326 GString
*arg
= g_string_new(NULL
);
3328 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3334 ret
= bt_private_value_array_append_string_element(run_args
, "--connect");
3341 g_string_append(arg
, e_upstream_name
->str
);
3342 g_string_append_c(arg
, ':');
3343 g_string_append(arg
, e_downstream_name
->str
);
3344 ret
= bt_private_value_array_append_string_element(run_args
, arg
->str
);
3353 g_string_free(arg
, TRUE
);
3356 if (e_upstream_name
) {
3357 g_string_free(e_upstream_name
, TRUE
);
3360 if (e_downstream_name
) {
3361 g_string_free(e_downstream_name
, TRUE
);
3368 * Appends the run command's --connect options for the convert command.
3371 int convert_auto_connect(struct bt_private_value
*run_args
,
3372 GList
*source_names
, GList
*filter_names
,
3376 GList
*source_at
= source_names
;
3377 GList
*filter_at
= filter_names
;
3379 GList
*sink_at
= sink_names
;
3381 BT_ASSERT(source_names
);
3382 BT_ASSERT(filter_names
);
3383 BT_ASSERT(sink_names
);
3385 /* Connect all sources to the first filter */
3386 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3387 GString
*source_name
= source_at
->data
;
3388 GString
*filter_name
= filter_at
->data
;
3390 ret
= append_connect_arg(run_args
, source_name
->str
,
3397 filter_prev
= filter_at
;
3398 filter_at
= g_list_next(filter_at
);
3400 /* Connect remaining filters */
3401 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3402 GString
*filter_name
= filter_at
->data
;
3403 GString
*filter_prev_name
= filter_prev
->data
;
3405 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3412 /* Connect last filter to all sinks */
3413 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3414 GString
*filter_name
= filter_prev
->data
;
3415 GString
*sink_name
= sink_at
->data
;
3417 ret
= append_connect_arg(run_args
, filter_name
->str
,
3434 int split_timerange(const char *arg
, char **begin
, char **end
)
3437 const char *ch
= arg
;
3439 GString
*g_begin
= NULL
;
3440 GString
*g_end
= NULL
;
3448 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3449 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3455 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3456 if (!g_end
|| g_end
->len
== 0) {
3462 *begin
= g_begin
->str
;
3464 g_string_free(g_begin
, FALSE
);
3465 g_string_free(g_end
, FALSE
);
3475 g_string_free(g_begin
, TRUE
);
3479 g_string_free(g_end
, TRUE
);
3486 int g_list_prepend_gstring(GList
**list
, const char *string
)
3489 GString
*gs
= g_string_new(string
);
3498 *list
= g_list_prepend(*list
, gs
);
3505 struct implicit_component_args
*create_implicit_component_args(void)
3507 struct implicit_component_args
*impl_args
=
3508 g_new0(struct implicit_component_args
, 1);
3514 if (init_implicit_component_args(impl_args
, NULL
, true)) {
3515 destroy_implicit_component_args(impl_args
);
3525 int fill_implicit_ctf_inputs_args(GPtrArray
*implicit_ctf_inputs_args
,
3526 struct implicit_component_args
*base_implicit_ctf_input_args
,
3531 enum bt_value_status status
;
3533 for (leftover
= leftovers
; leftover
!= NULL
;
3534 leftover
= g_list_next(leftover
)) {
3535 GString
*gs_leftover
= leftover
->data
;
3536 struct implicit_component_args
*impl_args
=
3537 create_implicit_component_args();
3544 impl_args
->exists
= true;
3545 g_string_assign(impl_args
->comp_arg
,
3546 base_implicit_ctf_input_args
->comp_arg
->str
);
3547 g_string_assign(impl_args
->params_arg
,
3548 base_implicit_ctf_input_args
->params_arg
->str
);
3551 * We need our own copy of the extra parameters because
3552 * this is where the unique path goes.
3554 BT_OBJECT_PUT_REF_AND_RESET(impl_args
->extra_params
);
3555 status
= bt_value_copy(&impl_args
->extra_params
,
3556 bt_private_value_borrow_value(
3557 base_implicit_ctf_input_args
->extra_params
));
3558 if (status
!= BT_VALUE_STATUS_OK
) {
3560 destroy_implicit_component_args(impl_args
);
3564 /* Append unique path parameter */
3565 ret
= append_implicit_component_extra_param(impl_args
,
3566 "path", gs_leftover
->str
);
3568 destroy_implicit_component_args(impl_args
);
3572 g_ptr_array_add(implicit_ctf_inputs_args
, impl_args
);
3585 * Creates a Babeltrace config object from the arguments of a convert
3588 * *retcode is set to the appropriate exit code to use.
3591 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3592 int *retcode
, bool force_omit_system_plugin_path
,
3593 bool force_omit_home_plugin_path
,
3594 struct bt_private_value
*initial_plugin_paths
, char *log_level
)
3596 poptContext pc
= NULL
;
3598 enum bt_config_component_dest cur_comp_dest
=
3599 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3601 struct bt_config
*cfg
= NULL
;
3602 bool got_input_format_opt
= false;
3603 bool got_output_format_opt
= false;
3604 bool trimmer_has_begin
= false;
3605 bool trimmer_has_end
= false;
3606 bool stream_intersection_mode
= false;
3607 GString
*cur_name
= NULL
;
3608 GString
*cur_name_prefix
= NULL
;
3609 const char *leftover
= NULL
;
3610 bool print_run_args
= false;
3611 bool print_run_args_0
= false;
3612 bool print_ctf_metadata
= false;
3613 struct bt_private_value
*run_args
= NULL
;
3614 struct bt_private_value
*all_names
= NULL
;
3615 GList
*source_names
= NULL
;
3616 GList
*filter_names
= NULL
;
3617 GList
*sink_names
= NULL
;
3618 GList
*leftovers
= NULL
;
3619 GPtrArray
*implicit_ctf_inputs_args
= NULL
;
3620 struct implicit_component_args base_implicit_ctf_input_args
= { 0 };
3621 struct implicit_component_args implicit_ctf_output_args
= { 0 };
3622 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3623 struct implicit_component_args implicit_dummy_args
= { 0 };
3624 struct implicit_component_args implicit_text_args
= { 0 };
3625 struct implicit_component_args implicit_debug_info_args
= { 0 };
3626 struct implicit_component_args implicit_muxer_args
= { 0 };
3627 struct implicit_component_args implicit_trimmer_args
= { 0 };
3628 struct bt_private_value
*plugin_paths
=
3629 bt_object_get_ref(initial_plugin_paths
);
3630 char error_buf
[256] = { 0 };
3632 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3633 char *output
= NULL
;
3638 print_convert_usage(stdout
);
3643 if (init_implicit_component_args(&base_implicit_ctf_input_args
,
3644 "source.ctf.fs", false)) {
3648 if (init_implicit_component_args(&implicit_ctf_output_args
,
3649 "sink.ctf.fs", false)) {
3653 if (init_implicit_component_args(&implicit_lttng_live_args
,
3654 "source.ctf.lttng-live", false)) {
3658 if (init_implicit_component_args(&implicit_text_args
,
3659 "sink.text.pretty", false)) {
3663 if (init_implicit_component_args(&implicit_dummy_args
,
3664 "sink.utils.dummy", false)) {
3668 if (init_implicit_component_args(&implicit_debug_info_args
,
3669 "filter.lttng-utils.debug-info", false)) {
3673 if (init_implicit_component_args(&implicit_muxer_args
,
3674 "filter.utils.muxer", true)) {
3678 if (init_implicit_component_args(&implicit_trimmer_args
,
3679 "filter.utils.trimmer", false)) {
3683 implicit_ctf_inputs_args
= g_ptr_array_new_with_free_func(
3684 (GDestroyNotify
) destroy_implicit_component_args
);
3685 if (!implicit_ctf_inputs_args
) {
3690 all_names
= bt_private_value_map_create();
3696 run_args
= bt_private_value_array_create();
3702 cur_name
= g_string_new(NULL
);
3708 cur_name_prefix
= g_string_new(NULL
);
3709 if (!cur_name_prefix
) {
3714 ret
= append_env_var_plugin_paths(plugin_paths
);
3720 * First pass: collect all arguments which need to be passed
3721 * as is to the run command. This pass can also add --name
3722 * arguments if needed to automatically name unnamed component
3723 * instances. Also it does the following transformations:
3725 * --path=PATH -> --key path --value PATH
3726 * --url=URL -> --key url --value URL
3728 * Also it appends the plugin paths of --plugin-path to
3731 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3732 convert_long_options
, 0);
3734 printf_err("Cannot get popt context\n");
3738 poptReadDefaultConfig(pc
, 0);
3740 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3742 char *plugin_name
= NULL
;
3743 char *comp_cls_name
= NULL
;
3745 arg
= poptGetOptArg(pc
);
3750 enum bt_component_class_type type
;
3751 const char *type_prefix
;
3753 /* Append current component's name if needed */
3754 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3755 cur_name_prefix
, run_args
, all_names
,
3756 &source_names
, &filter_names
, &sink_names
);
3761 /* Parse the argument */
3762 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3763 &comp_cls_name
, &type
);
3764 if (!plugin_name
|| !comp_cls_name
) {
3765 printf_err("Invalid format for --component option's argument:\n %s\n",
3771 g_string_assign(cur_name
, name
);
3773 g_string_assign(cur_name
, "");
3777 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3778 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3779 type_prefix
= "source";
3781 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3782 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
3783 type_prefix
= "filter";
3785 case BT_COMPONENT_CLASS_TYPE_SINK
:
3786 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3787 type_prefix
= "sink";
3793 if (bt_private_value_array_append_string_element(run_args
,
3799 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3804 g_string_assign(cur_name_prefix
, "");
3805 g_string_append_printf(cur_name_prefix
, "%s.%s.%s",
3806 type_prefix
, plugin_name
, comp_cls_name
);
3809 free(comp_cls_name
);
3812 comp_cls_name
= NULL
;
3816 if (cur_name_prefix
->len
== 0) {
3817 printf_err("No current component of which to set parameters:\n %s\n",
3822 if (bt_private_value_array_append_string_element(run_args
,
3828 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3834 if (cur_name_prefix
->len
== 0) {
3835 printf_err("No current component of which to set `path` parameter:\n %s\n",
3840 if (bt_private_value_array_append_string_element(run_args
, "--key")) {
3845 if (bt_private_value_array_append_string_element(run_args
, "path")) {
3850 if (bt_private_value_array_append_string_element(run_args
, "--value")) {
3855 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3861 if (cur_name_prefix
->len
== 0) {
3862 printf_err("No current component of which to set `url` parameter:\n %s\n",
3867 if (bt_private_value_array_append_string_element(run_args
, "--key")) {
3872 if (bt_private_value_array_append_string_element(run_args
, "url")) {
3877 if (bt_private_value_array_append_string_element(run_args
, "--value")) {
3882 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3888 if (cur_name_prefix
->len
== 0) {
3889 printf_err("No current component to name:\n %s\n",
3894 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3899 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3904 g_string_assign(cur_name
, arg
);
3906 case OPT_OMIT_HOME_PLUGIN_PATH
:
3907 force_omit_home_plugin_path
= true;
3909 if (bt_private_value_array_append_string_element(run_args
,
3910 "--omit-home-plugin-path")) {
3915 case OPT_RETRY_DURATION
:
3916 if (bt_private_value_array_append_string_element(run_args
,
3917 "--retry-duration")) {
3922 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3927 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3928 force_omit_system_plugin_path
= true;
3930 if (bt_private_value_array_append_string_element(run_args
,
3931 "--omit-system-plugin-path")) {
3936 case OPT_PLUGIN_PATH
:
3937 if (bt_config_append_plugin_paths_check_setuid_setgid(
3938 plugin_paths
, arg
)) {
3942 if (bt_private_value_array_append_string_element(run_args
,
3948 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3954 print_convert_usage(stdout
);
3956 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
3959 case OPT_CLOCK_CYCLES
:
3960 case OPT_CLOCK_DATE
:
3961 case OPT_CLOCK_FORCE_CORRELATE
:
3963 case OPT_CLOCK_OFFSET
:
3964 case OPT_CLOCK_OFFSET_NS
:
3965 case OPT_CLOCK_SECONDS
:
3968 case OPT_DEBUG_INFO
:
3969 case OPT_DEBUG_INFO_DIR
:
3970 case OPT_DEBUG_INFO_FULL_PATH
:
3971 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3974 case OPT_INPUT_FORMAT
:
3977 case OPT_OUTPUT_FORMAT
:
3980 case OPT_RUN_ARGS_0
:
3981 case OPT_STREAM_INTERSECTION
:
3984 /* Ignore in this pass */
3987 printf_err("Unknown command-line option specified (option code %d)\n",
3996 /* Append current component's name if needed */
3997 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3998 cur_name_prefix
, run_args
, all_names
, &source_names
,
3999 &filter_names
, &sink_names
);
4004 /* Check for option parsing error */
4006 printf_err("While parsing command-line options, at option %s: %s\n",
4007 poptBadOption(pc
, 0), poptStrerror(opt
));
4011 poptFreeContext(pc
);
4016 * Second pass: transform the convert-specific options and
4017 * arguments into implicit component instances for the run
4020 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
4021 convert_long_options
, 0);
4023 printf_err("Cannot get popt context\n");
4027 poptReadDefaultConfig(pc
, 0);
4029 while ((opt
= poptGetNextOpt(pc
)) > 0) {
4030 arg
= poptGetOptArg(pc
);
4034 if (trimmer_has_begin
) {
4035 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4040 trimmer_has_begin
= true;
4041 ret
= append_implicit_component_extra_param(
4042 &implicit_trimmer_args
, "begin", arg
);
4043 implicit_trimmer_args
.exists
= true;
4049 if (trimmer_has_end
) {
4050 printf("At --end option: --end or --timerange option already specified\n %s\n",
4055 trimmer_has_end
= true;
4056 ret
= append_implicit_component_extra_param(
4057 &implicit_trimmer_args
, "end", arg
);
4058 implicit_trimmer_args
.exists
= true;
4068 if (trimmer_has_begin
|| trimmer_has_end
) {
4069 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4074 ret
= split_timerange(arg
, &begin
, &end
);
4076 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4081 ret
= append_implicit_component_extra_param(
4082 &implicit_trimmer_args
, "begin", begin
);
4083 ret
|= append_implicit_component_extra_param(
4084 &implicit_trimmer_args
, "end", end
);
4085 implicit_trimmer_args
.exists
= true;
4093 case OPT_CLOCK_CYCLES
:
4094 append_implicit_component_param(
4095 &implicit_text_args
, "clock-cycles", "yes");
4096 implicit_text_args
.exists
= true;
4098 case OPT_CLOCK_DATE
:
4099 append_implicit_component_param(
4100 &implicit_text_args
, "clock-date", "yes");
4101 implicit_text_args
.exists
= true;
4103 case OPT_CLOCK_FORCE_CORRELATE
:
4104 append_implicit_component_param(
4105 &implicit_muxer_args
,
4106 "assume-absolute-clock-classes", "yes");
4109 append_implicit_component_param(
4110 &implicit_text_args
, "clock-gmt", "yes");
4111 append_implicit_component_param(
4112 &implicit_trimmer_args
, "clock-gmt", "yes");
4113 implicit_text_args
.exists
= true;
4115 case OPT_CLOCK_OFFSET
:
4116 base_implicit_ctf_input_args
.exists
= true;
4117 append_implicit_component_param(
4118 &base_implicit_ctf_input_args
,
4119 "clock-class-offset-s", arg
);
4121 case OPT_CLOCK_OFFSET_NS
:
4122 base_implicit_ctf_input_args
.exists
= true;
4123 append_implicit_component_param(
4124 &base_implicit_ctf_input_args
,
4125 "clock-class-offset-ns", arg
);
4127 case OPT_CLOCK_SECONDS
:
4128 append_implicit_component_param(
4129 &implicit_text_args
, "clock-seconds", "yes");
4130 implicit_text_args
.exists
= true;
4133 implicit_text_args
.exists
= true;
4134 ret
= append_implicit_component_extra_param(
4135 &implicit_text_args
, "color", arg
);
4140 case OPT_DEBUG_INFO
:
4141 implicit_debug_info_args
.exists
= true;
4143 case OPT_DEBUG_INFO_DIR
:
4144 implicit_debug_info_args
.exists
= true;
4145 ret
= append_implicit_component_extra_param(
4146 &implicit_debug_info_args
, "debug-info-dir", arg
);
4151 case OPT_DEBUG_INFO_FULL_PATH
:
4152 implicit_debug_info_args
.exists
= true;
4153 append_implicit_component_param(
4154 &implicit_debug_info_args
, "full-path", "yes");
4156 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4157 implicit_debug_info_args
.exists
= true;
4158 ret
= append_implicit_component_extra_param(
4159 &implicit_debug_info_args
,
4160 "target-prefix", arg
);
4167 struct bt_private_value
*fields
= fields_from_arg(arg
);
4173 implicit_text_args
.exists
= true;
4174 ret
= insert_flat_params_from_array(
4175 implicit_text_args
.params_arg
,
4176 bt_private_value_borrow_value(fields
), "field");
4177 bt_object_put_ref(fields
);
4185 struct bt_private_value
*names
= names_from_arg(arg
);
4191 implicit_text_args
.exists
= true;
4192 ret
= insert_flat_params_from_array(
4193 implicit_text_args
.params_arg
,
4194 bt_private_value_borrow_value(names
), "name");
4195 bt_object_put_ref(names
);
4202 append_implicit_component_param(
4203 &implicit_text_args
, "no-delta", "yes");
4204 implicit_text_args
.exists
= true;
4206 case OPT_INPUT_FORMAT
:
4207 if (got_input_format_opt
) {
4208 printf_err("Duplicate --input-format option\n");
4212 got_input_format_opt
= true;
4214 if (strcmp(arg
, "ctf") == 0) {
4215 base_implicit_ctf_input_args
.exists
= true;
4216 } else if (strcmp(arg
, "lttng-live") == 0) {
4217 implicit_lttng_live_args
.exists
= true;
4219 printf_err("Unknown legacy input format:\n %s\n",
4224 case OPT_OUTPUT_FORMAT
:
4225 if (got_output_format_opt
) {
4226 printf_err("Duplicate --output-format option\n");
4230 got_output_format_opt
= true;
4232 if (strcmp(arg
, "text") == 0) {
4233 implicit_text_args
.exists
= true;
4234 } else if (strcmp(arg
, "ctf") == 0) {
4235 implicit_ctf_output_args
.exists
= true;
4236 } else if (strcmp(arg
, "dummy") == 0) {
4237 implicit_dummy_args
.exists
= true;
4238 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4239 print_ctf_metadata
= true;
4241 printf_err("Unknown legacy output format:\n %s\n",
4248 printf_err("Duplicate --output option\n");
4252 output
= strdup(arg
);
4259 if (print_run_args_0
) {
4260 printf_err("Cannot specify --run-args and --run-args-0\n");
4264 print_run_args
= true;
4266 case OPT_RUN_ARGS_0
:
4267 if (print_run_args
) {
4268 printf_err("Cannot specify --run-args and --run-args-0\n");
4272 print_run_args_0
= true;
4274 case OPT_STREAM_INTERSECTION
:
4276 * Applies to all traces implementing the trace-info
4279 stream_intersection_mode
= true;
4282 if (*log_level
!= 'V' && *log_level
!= 'D') {
4295 /* Check for option parsing error */
4297 printf_err("While parsing command-line options, at option %s: %s\n",
4298 poptBadOption(pc
, 0), poptStrerror(opt
));
4303 * Legacy behaviour: --verbose used to make the `text` output
4304 * format print more information. --verbose is now equivalent to
4305 * the INFO log level, which is why we compare to 'I' here.
4307 if (*log_level
== 'I') {
4308 append_implicit_component_param(&implicit_text_args
,
4313 * Append home and system plugin paths now that we possibly got
4316 if (append_home_and_system_plugin_paths(plugin_paths
,
4317 force_omit_system_plugin_path
,
4318 force_omit_home_plugin_path
)) {
4322 /* Consume and keep leftover arguments */
4323 while ((leftover
= poptGetArg(pc
))) {
4324 GString
*gs_leftover
= g_string_new(leftover
);
4331 leftovers
= g_list_append(leftovers
, gs_leftover
);
4333 g_string_free(gs_leftover
, TRUE
);
4339 /* Print CTF metadata or print LTTng live sessions */
4340 if (print_ctf_metadata
) {
4341 GString
*gs_leftover
;
4343 if (g_list_length(leftovers
) == 0) {
4344 printf_err("--output-format=ctf-metadata specified without a path\n");
4348 if (g_list_length(leftovers
) > 1) {
4349 printf_err("Too many paths specified for --output-format=ctf-metadata\n");
4353 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4358 gs_leftover
= leftovers
->data
;
4359 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4364 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
4372 * If -o ctf was specified, make sure an output path (--output)
4373 * was also specified. --output does not imply -o ctf because
4374 * it's also used for the default, implicit -o text if -o ctf
4377 if (implicit_ctf_output_args
.exists
) {
4379 printf_err("--output-format=ctf specified without --output (trace output path)\n");
4384 * At this point we know that -o ctf AND --output were
4385 * specified. Make sure that no options were specified
4386 * which would imply -o text because --output would be
4387 * ambiguous in this case. For example, this is wrong:
4389 * babeltrace --names=all -o ctf --output=/tmp/path my-trace
4391 * because --names=all implies -o text, and --output
4392 * could apply to both the sink.text.pretty and
4393 * sink.ctf.fs implicit components.
4395 if (implicit_text_args
.exists
) {
4396 printf_err("Ambiguous --output option: --output-format=ctf specified but another option implies --output-format=text\n");
4402 * If -o dummy and -o ctf were not specified, and if there are
4403 * no explicit sink components, then use an implicit
4404 * `sink.text.pretty` component.
4406 if (!implicit_dummy_args
.exists
&& !implicit_ctf_output_args
.exists
&&
4408 implicit_text_args
.exists
= true;
4412 * Set implicit `sink.text.pretty` or `sink.ctf.fs` component's
4413 * `path` parameter if --output was specified.
4416 if (implicit_text_args
.exists
) {
4417 append_implicit_component_extra_param(&implicit_text_args
,
4419 } else if (implicit_ctf_output_args
.exists
) {
4420 append_implicit_component_extra_param(&implicit_ctf_output_args
,
4425 /* Decide where the leftover argument(s) go */
4426 if (g_list_length(leftovers
) > 0) {
4427 if (implicit_lttng_live_args
.exists
) {
4428 GString
*gs_leftover
;
4430 if (g_list_length(leftovers
) > 1) {
4431 printf_err("Too many URLs specified for --output-format=lttng-live\n");
4435 gs_leftover
= leftovers
->data
;
4436 lttng_live_url_parts
=
4437 bt_common_parse_lttng_live_url(gs_leftover
->str
,
4438 error_buf
, sizeof(error_buf
));
4439 if (!lttng_live_url_parts
.proto
) {
4440 printf_err("Invalid LTTng live URL format: %s\n",
4445 if (!lttng_live_url_parts
.session_name
) {
4446 /* Print LTTng live sessions */
4447 cfg
= bt_config_print_lttng_live_sessions_create(
4453 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4458 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
4465 ret
= append_implicit_component_extra_param(
4466 &implicit_lttng_live_args
, "url",
4473 * Append one implicit component argument set
4474 * for each leftover (souce.ctf.fs paths). Copy
4475 * the base implicit component arguments.
4476 * Note that they still have to be named later.
4478 ret
= fill_implicit_ctf_inputs_args(
4479 implicit_ctf_inputs_args
,
4480 &base_implicit_ctf_input_args
, leftovers
);
4488 * Ensure mutual exclusion between implicit `source.ctf.fs` and
4489 * `source.ctf.lttng-live` components.
4491 if (base_implicit_ctf_input_args
.exists
&&
4492 implicit_lttng_live_args
.exists
) {
4493 printf_err("Cannot create both implicit `%s` and `%s` components\n",
4494 base_implicit_ctf_input_args
.comp_arg
->str
,
4495 implicit_lttng_live_args
.comp_arg
->str
);
4500 * If the implicit `source.ctf.fs` or `source.ctf.lttng-live`
4501 * components exists, make sure there's at least one leftover
4502 * (which is the path or URL).
4504 if (base_implicit_ctf_input_args
.exists
&&
4505 g_list_length(leftovers
) == 0) {
4506 printf_err("Missing path for implicit `%s` component\n",
4507 base_implicit_ctf_input_args
.comp_arg
->str
);
4511 if (implicit_lttng_live_args
.exists
&& g_list_length(leftovers
) == 0) {
4512 printf_err("Missing URL for implicit `%s` component\n",
4513 implicit_lttng_live_args
.comp_arg
->str
);
4517 /* Assign names to implicit components */
4518 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4519 struct implicit_component_args
*impl_args
=
4520 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4522 ret
= assign_name_to_implicit_component(impl_args
,
4523 "source-ctf-fs", all_names
, &source_names
, true);
4529 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4530 "lttng-live", all_names
, &source_names
, true);
4535 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4536 "pretty", all_names
, &sink_names
, true);
4541 ret
= assign_name_to_implicit_component(&implicit_ctf_output_args
,
4542 "sink-ctf-fs", all_names
, &sink_names
, true);
4547 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4548 "dummy", all_names
, &sink_names
, true);
4553 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4554 "muxer", all_names
, NULL
, false);
4559 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4560 "trimmer", all_names
, NULL
, false);
4565 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4566 "debug-info", all_names
, NULL
, false);
4571 /* Make sure there's at least one source and one sink */
4572 if (!source_names
) {
4573 printf_err("No source component\n");
4578 printf_err("No sink component\n");
4583 * Prepend the muxer, the trimmer, and the debug info to the
4584 * filter chain so that we have:
4586 * sources -> muxer -> [trimmer] -> [debug info] ->
4587 * [user filters] -> sinks
4589 if (implicit_debug_info_args
.exists
) {
4590 if (g_list_prepend_gstring(&filter_names
,
4591 implicit_debug_info_args
.name_arg
->str
)) {
4596 if (implicit_trimmer_args
.exists
) {
4597 if (g_list_prepend_gstring(&filter_names
,
4598 implicit_trimmer_args
.name_arg
->str
)) {
4603 if (g_list_prepend_gstring(&filter_names
,
4604 implicit_muxer_args
.name_arg
->str
)) {
4609 * Append the equivalent run arguments for the implicit
4612 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4613 struct implicit_component_args
*impl_args
=
4614 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4616 ret
= append_run_args_for_implicit_component(impl_args
,
4623 ret
= append_run_args_for_implicit_component(&implicit_lttng_live_args
,
4629 ret
= append_run_args_for_implicit_component(&implicit_text_args
,
4635 ret
= append_run_args_for_implicit_component(&implicit_ctf_output_args
,
4641 ret
= append_run_args_for_implicit_component(&implicit_dummy_args
,
4647 ret
= append_run_args_for_implicit_component(&implicit_muxer_args
,
4653 ret
= append_run_args_for_implicit_component(&implicit_trimmer_args
,
4659 ret
= append_run_args_for_implicit_component(&implicit_debug_info_args
,
4665 /* Auto-connect components */
4666 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4669 printf_err("Cannot auto-connect components\n");
4674 * We have all the run command arguments now. Depending on
4675 * --run-args, we pass this to the run command or print them
4678 if (print_run_args
|| print_run_args_0
) {
4679 if (stream_intersection_mode
) {
4680 printf_err("Cannot specify --stream-intersection with --run-args or --run-args-0\n");
4684 for (i
= 0; i
< bt_value_array_get_size(
4685 bt_private_value_borrow_value(run_args
)); i
++) {
4686 struct bt_value
*arg_value
=
4687 bt_value_array_borrow_element_by_index(
4688 bt_private_value_borrow_value(run_args
),
4691 GString
*quoted
= NULL
;
4692 const char *arg_to_print
;
4694 BT_ASSERT(arg_value
);
4695 arg
= bt_value_string_get(arg_value
);
4697 if (print_run_args
) {
4698 quoted
= bt_common_shell_quote(arg
, true);
4703 arg_to_print
= quoted
->str
;
4708 printf("%s", arg_to_print
);
4711 g_string_free(quoted
, TRUE
);
4714 if (i
< bt_value_array_get_size(
4715 bt_private_value_borrow_value(run_args
)) - 1) {
4716 if (print_run_args
) {
4725 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4729 cfg
= bt_config_run_from_args_array(
4730 bt_private_value_borrow_value(run_args
), retcode
,
4731 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
4732 initial_plugin_paths
);
4737 cfg
->cmd_data
.run
.stream_intersection_mode
= stream_intersection_mode
;
4742 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4746 poptFreeContext(pc
);
4753 g_string_free(cur_name
, TRUE
);
4756 if (cur_name_prefix
) {
4757 g_string_free(cur_name_prefix
, TRUE
);
4760 if (implicit_ctf_inputs_args
) {
4761 g_ptr_array_free(implicit_ctf_inputs_args
, TRUE
);
4764 bt_object_put_ref(run_args
);
4765 bt_object_put_ref(all_names
);
4766 destroy_glist_of_gstring(source_names
);
4767 destroy_glist_of_gstring(filter_names
);
4768 destroy_glist_of_gstring(sink_names
);
4769 destroy_glist_of_gstring(leftovers
);
4770 finalize_implicit_component_args(&base_implicit_ctf_input_args
);
4771 finalize_implicit_component_args(&implicit_ctf_output_args
);
4772 finalize_implicit_component_args(&implicit_lttng_live_args
);
4773 finalize_implicit_component_args(&implicit_dummy_args
);
4774 finalize_implicit_component_args(&implicit_text_args
);
4775 finalize_implicit_component_args(&implicit_debug_info_args
);
4776 finalize_implicit_component_args(&implicit_muxer_args
);
4777 finalize_implicit_component_args(&implicit_trimmer_args
);
4778 bt_object_put_ref(plugin_paths
);
4779 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4784 * Prints the Babeltrace 2.x general usage.
4787 void print_gen_usage(FILE *fp
)
4789 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4791 fprintf(fp
, "General options:\n");
4793 fprintf(fp
, " -d, --debug Enable debug mode (same as --log-level=V)\n");
4794 fprintf(fp
, " -h, --help Show this help and quit\n");
4795 fprintf(fp
, " -l, --log-level=LVL Set all log levels to LVL (`N`, `V`, `D`,\n");
4796 fprintf(fp
, " `I`, `W` (default), `E`, or `F`)\n");
4797 fprintf(fp
, " -v, --verbose Enable verbose mode (same as --log-level=I)\n");
4798 fprintf(fp
, " -V, --version Show version and quit\n");
4800 fprintf(fp
, "Available commands:\n");
4802 fprintf(fp
, " convert Convert and trim traces (default)\n");
4803 fprintf(fp
, " help Get help for a plugin or a component class\n");
4804 fprintf(fp
, " list-plugins List available plugins and their content\n");
4805 fprintf(fp
, " query Query objects from a component class\n");
4806 fprintf(fp
, " run Build a processing graph and run it\n");
4808 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4812 char log_level_from_arg(const char *arg
)
4816 if (strcmp(arg
, "VERBOSE") == 0 ||
4817 strcmp(arg
, "V") == 0) {
4819 } else if (strcmp(arg
, "DEBUG") == 0 ||
4820 strcmp(arg
, "D") == 0) {
4822 } else if (strcmp(arg
, "INFO") == 0 ||
4823 strcmp(arg
, "I") == 0) {
4825 } else if (strcmp(arg
, "WARN") == 0 ||
4826 strcmp(arg
, "WARNING") == 0 ||
4827 strcmp(arg
, "W") == 0) {
4829 } else if (strcmp(arg
, "ERROR") == 0 ||
4830 strcmp(arg
, "E") == 0) {
4832 } else if (strcmp(arg
, "FATAL") == 0 ||
4833 strcmp(arg
, "F") == 0) {
4835 } else if (strcmp(arg
, "NONE") == 0 ||
4836 strcmp(arg
, "N") == 0) {
4843 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4844 int *retcode
, bool force_omit_system_plugin_path
,
4845 bool force_omit_home_plugin_path
,
4846 struct bt_private_value
*initial_plugin_paths
)
4848 struct bt_config
*config
= NULL
;
4850 const char **command_argv
= NULL
;
4851 int command_argc
= -1;
4852 const char *command_name
= NULL
;
4853 char log_level
= 'U';
4856 COMMAND_TYPE_NONE
= -1,
4857 COMMAND_TYPE_RUN
= 0,
4858 COMMAND_TYPE_CONVERT
,
4859 COMMAND_TYPE_LIST_PLUGINS
,
4862 } command_type
= COMMAND_TYPE_NONE
;
4866 if (!initial_plugin_paths
) {
4867 initial_plugin_paths
= bt_private_value_array_create();
4868 if (!initial_plugin_paths
) {
4873 bt_object_get_ref(initial_plugin_paths
);
4879 print_gen_usage(stdout
);
4883 for (i
= 1; i
< argc
; i
++) {
4884 const char *cur_arg
= argv
[i
];
4885 const char *next_arg
= i
== (argc
- 1) ? NULL
: argv
[i
+ 1];
4887 if (strcmp(cur_arg
, "-d") == 0 ||
4888 strcmp(cur_arg
, "--debug") == 0) {
4890 } else if (strcmp(cur_arg
, "-v") == 0 ||
4891 strcmp(cur_arg
, "--verbose") == 0) {
4892 if (log_level
!= 'V' && log_level
!= 'D') {
4894 * Legacy: do not override a previous
4895 * --debug because --verbose and --debug
4896 * can be specified together (in this
4897 * case we want the lowest log level to
4902 } else if (strcmp(cur_arg
, "--log-level") == 0 ||
4903 strcmp(cur_arg
, "-l") == 0) {
4905 printf_err("Missing log level value for --log-level option\n");
4910 log_level
= log_level_from_arg(next_arg
);
4911 if (log_level
== 'U') {
4912 printf_err("Invalid argument for --log-level option:\n %s\n",
4919 } else if (strncmp(cur_arg
, "--log-level=", 12) == 0) {
4920 const char *arg
= &cur_arg
[12];
4922 log_level
= log_level_from_arg(arg
);
4923 if (log_level
== 'U') {
4924 printf_err("Invalid argument for --log-level option:\n %s\n",
4929 } else if (strncmp(cur_arg
, "-l", 2) == 0) {
4930 const char *arg
= &cur_arg
[2];
4932 log_level
= log_level_from_arg(arg
);
4933 if (log_level
== 'U') {
4934 printf_err("Invalid argument for --log-level option:\n %s\n",
4939 } else if (strcmp(cur_arg
, "-V") == 0 ||
4940 strcmp(cur_arg
, "--version") == 0) {
4943 } else if (strcmp(cur_arg
, "-h") == 0 ||
4944 strcmp(cur_arg
, "--help") == 0) {
4945 print_gen_usage(stdout
);
4949 * First unknown argument: is it a known command
4952 command_argv
= &argv
[i
];
4953 command_argc
= argc
- i
;
4955 if (strcmp(cur_arg
, "convert") == 0) {
4956 command_type
= COMMAND_TYPE_CONVERT
;
4957 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4958 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4959 } else if (strcmp(cur_arg
, "help") == 0) {
4960 command_type
= COMMAND_TYPE_HELP
;
4961 } else if (strcmp(cur_arg
, "query") == 0) {
4962 command_type
= COMMAND_TYPE_QUERY
;
4963 } else if (strcmp(cur_arg
, "run") == 0) {
4964 command_type
= COMMAND_TYPE_RUN
;
4967 * Unknown argument, but not a known
4968 * command name: assume the default
4969 * `convert` command.
4971 command_type
= COMMAND_TYPE_CONVERT
;
4972 command_name
= "convert";
4973 command_argv
= &argv
[i
- 1];
4974 command_argc
= argc
- i
+ 1;
4980 if (command_type
== COMMAND_TYPE_NONE
) {
4982 * We only got non-help, non-version general options
4983 * like --verbose and --debug, without any other
4984 * arguments, so we can't do anything useful: print the
4987 print_gen_usage(stdout
);
4991 BT_ASSERT(command_argv
);
4992 BT_ASSERT(command_argc
>= 0);
4994 switch (command_type
) {
4995 case COMMAND_TYPE_RUN
:
4996 config
= bt_config_run_from_args(command_argc
, command_argv
,
4997 retcode
, force_omit_system_plugin_path
,
4998 force_omit_home_plugin_path
, initial_plugin_paths
);
5000 case COMMAND_TYPE_CONVERT
:
5001 config
= bt_config_convert_from_args(command_argc
, command_argv
,
5002 retcode
, force_omit_system_plugin_path
,
5003 force_omit_home_plugin_path
,
5004 initial_plugin_paths
, &log_level
);
5006 case COMMAND_TYPE_LIST_PLUGINS
:
5007 config
= bt_config_list_plugins_from_args(command_argc
,
5008 command_argv
, retcode
, force_omit_system_plugin_path
,
5009 force_omit_home_plugin_path
, initial_plugin_paths
);
5011 case COMMAND_TYPE_HELP
:
5012 config
= bt_config_help_from_args(command_argc
,
5013 command_argv
, retcode
, force_omit_system_plugin_path
,
5014 force_omit_home_plugin_path
, initial_plugin_paths
);
5016 case COMMAND_TYPE_QUERY
:
5017 config
= bt_config_query_from_args(command_argc
,
5018 command_argv
, retcode
, force_omit_system_plugin_path
,
5019 force_omit_home_plugin_path
, initial_plugin_paths
);
5026 if (log_level
== 'U') {
5030 config
->log_level
= log_level
;
5031 config
->command_name
= command_name
;
5035 bt_object_put_ref(initial_plugin_paths
);