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
32 #include <babeltrace/babeltrace.h>
33 #include <babeltrace/common-internal.h>
34 #include <babeltrace/values.h>
37 #include <sys/types.h>
39 #include "babeltrace-cfg.h"
40 #include "babeltrace-cfg-cli-args.h"
41 #include "babeltrace-cfg-cli-args-connect.h"
43 #define BT_LOG_TAG "CLI-CFG-ARGS"
47 * Error printf() macro which prepends "Error: " the first time it's
48 * called. This gives a nicer feel than having a bunch of error prefixes
49 * (since the following lines usually describe the error and possible
50 * solutions), or the error prefix just at the end.
52 #define printf_err(fmt, args...) \
54 if (is_first_error) { \
55 fprintf(stderr, "Command line error: "); \
56 is_first_error = false; \
58 fprintf(stderr, fmt, ##args); \
61 static bool is_first_error
= true;
63 /* INI-style parsing FSM states */
64 enum ini_parsing_fsm_state
{
65 /* Expect a map key (identifier) */
68 /* Expect an equal character ('=') */
74 /* Expect a negative number value */
75 INI_EXPECT_VALUE_NUMBER_NEG
,
77 /* Expect a comma character (',') */
81 /* INI-style parsing state variables */
82 struct ini_parsing_state
{
83 /* Lexical scanner (owned by this) */
86 /* Output map value object being filled (owned by this) */
87 struct bt_value
*params
;
89 /* Next expected FSM state */
90 enum ini_parsing_fsm_state expecting
;
92 /* Last decoded map key (owned by this) */
95 /* Complete INI-style string to parse (not owned by this) */
98 /* Error buffer (not owned by this) */
102 /* Offset option with "is set" boolean */
108 /* Legacy "ctf"/"lttng-live" format options */
109 struct ctf_legacy_opts
{
110 struct offset_opt offset_s
;
111 struct offset_opt offset_ns
;
112 bool stream_intersection
;
115 /* Legacy "text" format options */
116 struct text_legacy_opts
{
118 * output, dbg_info_dir, dbg_info_target_prefix, names,
119 * and fields are owned by this.
122 GString
*dbg_info_dir
;
123 GString
*dbg_info_target_prefix
;
124 struct bt_value
*names
;
125 struct bt_value
*fields
;
133 bool dbg_info_full_path
;
137 /* Legacy input format format */
138 enum legacy_input_format
{
139 LEGACY_INPUT_FORMAT_NONE
= 0,
140 LEGACY_INPUT_FORMAT_CTF
,
141 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
144 /* Legacy output format format */
145 enum legacy_output_format
{
146 LEGACY_OUTPUT_FORMAT_NONE
= 0,
147 LEGACY_OUTPUT_FORMAT_TEXT
,
148 LEGACY_OUTPUT_FORMAT_DUMMY
,
152 * Prints the "out of memory" error.
155 void print_err_oom(void)
157 printf_err("Out of memory\n");
161 * Appends an "expecting token" error to the INI-style parsing state's
165 void ini_append_error_expecting(struct ini_parsing_state
*state
,
166 GScanner
*scanner
, const char *expecting
)
171 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
173 /* Only print error if there's one line */
174 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
178 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
179 pos
= g_scanner_cur_position(scanner
) + 4;
181 if (!g_scanner_eof(scanner
)) {
185 for (i
= 0; i
< pos
; ++i
) {
186 g_string_append_printf(state
->ini_error
, " ");
189 g_string_append_printf(state
->ini_error
, "^\n\n");
193 int ini_handle_state(struct ini_parsing_state
*state
)
196 GTokenType token_type
;
197 struct bt_value
*value
= NULL
;
199 token_type
= g_scanner_get_next_token(state
->scanner
);
200 if (token_type
== G_TOKEN_EOF
) {
201 if (state
->expecting
!= INI_EXPECT_COMMA
) {
202 switch (state
->expecting
) {
203 case INI_EXPECT_EQUAL
:
204 ini_append_error_expecting(state
,
205 state
->scanner
, "'='");
207 case INI_EXPECT_VALUE
:
208 case INI_EXPECT_VALUE_NUMBER_NEG
:
209 ini_append_error_expecting(state
,
210 state
->scanner
, "value");
212 case INI_EXPECT_MAP_KEY
:
213 ini_append_error_expecting(state
,
214 state
->scanner
, "unquoted map key");
227 switch (state
->expecting
) {
228 case INI_EXPECT_MAP_KEY
:
229 if (token_type
!= G_TOKEN_IDENTIFIER
) {
230 ini_append_error_expecting(state
, state
->scanner
,
235 free(state
->last_map_key
);
236 state
->last_map_key
=
237 strdup(state
->scanner
->value
.v_identifier
);
238 if (!state
->last_map_key
) {
239 g_string_append(state
->ini_error
,
244 if (bt_value_map_has_key(state
->params
, state
->last_map_key
)) {
245 g_string_append_printf(state
->ini_error
,
246 "Duplicate parameter key: `%s`\n",
247 state
->last_map_key
);
251 state
->expecting
= INI_EXPECT_EQUAL
;
253 case INI_EXPECT_EQUAL
:
254 if (token_type
!= G_TOKEN_CHAR
) {
255 ini_append_error_expecting(state
,
256 state
->scanner
, "'='");
260 if (state
->scanner
->value
.v_char
!= '=') {
261 ini_append_error_expecting(state
,
262 state
->scanner
, "'='");
266 state
->expecting
= INI_EXPECT_VALUE
;
268 case INI_EXPECT_VALUE
:
270 switch (token_type
) {
272 if (state
->scanner
->value
.v_char
== '-') {
273 /* Negative number */
275 INI_EXPECT_VALUE_NUMBER_NEG
;
278 ini_append_error_expecting(state
,
279 state
->scanner
, "value");
285 /* Positive integer */
286 uint64_t int_val
= state
->scanner
->value
.v_int64
;
288 if (int_val
> (1ULL << 63) - 1) {
289 g_string_append_printf(state
->ini_error
,
290 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
295 value
= bt_value_integer_create_init(
300 /* Positive floating point number */
301 value
= bt_value_float_create_init(
302 state
->scanner
->value
.v_float
);
306 value
= bt_value_string_create_init(
307 state
->scanner
->value
.v_string
);
309 case G_TOKEN_IDENTIFIER
:
312 * Using symbols would be appropriate here,
313 * but said symbols are allowed as map key,
314 * so it's easier to consider everything an
317 * If one of the known symbols is not
318 * recognized here, then fall back to creating
321 const char *id
= state
->scanner
->value
.v_identifier
;
323 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
324 !strcmp(id
, "nul")) {
325 value
= bt_value_null
;
326 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
327 !strcmp(id
, "yes") ||
328 !strcmp(id
, "YES")) {
329 value
= bt_value_bool_create_init(true);
330 } else if (!strcmp(id
, "false") ||
331 !strcmp(id
, "FALSE") ||
334 value
= bt_value_bool_create_init(false);
336 value
= bt_value_string_create_init(id
);
341 /* Unset value variable will trigger the error */
346 ini_append_error_expecting(state
,
347 state
->scanner
, "value");
351 state
->expecting
= INI_EXPECT_COMMA
;
354 case INI_EXPECT_VALUE_NUMBER_NEG
:
356 switch (token_type
) {
359 /* Negative integer */
360 uint64_t int_val
= state
->scanner
->value
.v_int64
;
362 if (int_val
> (1ULL << 63) - 1) {
363 g_string_append_printf(state
->ini_error
,
364 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
369 value
= bt_value_integer_create_init(
370 -((int64_t) int_val
));
374 /* Negative floating point number */
375 value
= bt_value_float_create_init(
376 -state
->scanner
->value
.v_float
);
379 /* Unset value variable will trigger the error */
384 ini_append_error_expecting(state
,
385 state
->scanner
, "value");
389 state
->expecting
= INI_EXPECT_COMMA
;
392 case INI_EXPECT_COMMA
:
393 if (token_type
!= G_TOKEN_CHAR
) {
394 ini_append_error_expecting(state
,
395 state
->scanner
, "','");
399 if (state
->scanner
->value
.v_char
!= ',') {
400 ini_append_error_expecting(state
,
401 state
->scanner
, "','");
405 state
->expecting
= INI_EXPECT_MAP_KEY
;
417 if (bt_value_map_insert(state
->params
,
418 state
->last_map_key
, value
)) {
419 /* Only override return value on error */
430 * Converts an INI-style argument to an equivalent map value object.
432 * Return value is owned by the caller.
435 struct bt_value
*bt_value_from_ini(const char *arg
, GString
*ini_error
)
437 /* Lexical scanner configuration */
438 GScannerConfig scanner_config
= {
439 /* Skip whitespaces */
440 .cset_skip_characters
= " \t\n",
442 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
443 .cset_identifier_first
=
447 .cset_identifier_nth
=
452 /* "hello" and "Hello" two different keys */
453 .case_sensitive
= TRUE
,
456 .cpair_comment_single
= NULL
,
457 .skip_comment_multi
= TRUE
,
458 .skip_comment_single
= TRUE
,
459 .scan_comment_multi
= FALSE
,
462 * Do scan identifiers, including 1-char identifiers,
463 * but NULL is a normal identifier.
465 .scan_identifier
= TRUE
,
466 .scan_identifier_1char
= TRUE
,
467 .scan_identifier_NULL
= FALSE
,
470 * No specific symbols: null and boolean "symbols" are
471 * scanned as plain identifiers.
473 .scan_symbols
= FALSE
,
474 .symbol_2_token
= FALSE
,
475 .scope_0_fallback
= FALSE
,
478 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
479 * integers prefixed with "$".
485 .scan_hex_dollar
= FALSE
,
487 /* Convert scanned numbers to integer tokens */
488 .numbers_2_int
= TRUE
,
490 /* Support both integers and floating-point numbers */
491 .int_2_float
= FALSE
,
493 /* Scan integers as 64-bit signed integers */
496 /* Only scan double-quoted strings */
497 .scan_string_sq
= FALSE
,
498 .scan_string_dq
= TRUE
,
500 /* Do not converter identifiers to string tokens */
501 .identifier_2_string
= FALSE
,
503 /* Scan characters as G_TOKEN_CHAR token */
504 .char_2_token
= FALSE
,
506 struct ini_parsing_state state
= {
509 .expecting
= INI_EXPECT_MAP_KEY
,
511 .ini_error
= ini_error
,
514 state
.params
= bt_value_map_create();
519 state
.scanner
= g_scanner_new(&scanner_config
);
520 if (!state
.scanner
) {
524 /* Let the scan begin */
525 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
528 int ret
= ini_handle_state(&state
);
533 } else if (ret
> 0) {
542 BT_PUT(state
.params
);
546 g_scanner_destroy(state
.scanner
);
549 free(state
.last_map_key
);
554 * Returns the parameters map value object from a command-line
555 * parameter option's argument.
557 * Return value is owned by the caller.
560 struct bt_value
*bt_value_from_arg(const char *arg
)
562 struct bt_value
*params
= NULL
;
563 GString
*ini_error
= NULL
;
565 ini_error
= g_string_new(NULL
);
571 /* Try INI-style parsing */
572 params
= bt_value_from_ini(arg
, ini_error
);
574 printf_err("%s", ini_error
->str
);
580 g_string_free(ini_error
, TRUE
);
586 * Returns the plugin name, component class name, component class type,
587 * and component name from a command-line --component option's argument.
588 * arg must have the following format:
590 * [NAME:]TYPE.PLUGIN.CLS
592 * where NAME is the optional component name, TYPE is either `source`,
593 * `filter`, or `sink`, PLUGIN is the plugin name, and CLS is the
594 * component class name.
596 * On success, both *plugin and *component are not NULL. *plugin
597 * and *component are owned by the caller. On success, *name can be NULL
598 * if no component name was found, and *comp_cls_type is set.
601 void plugin_comp_cls_names(const char *arg
, char **name
, char **plugin
,
602 char **comp_cls
, enum bt_component_class_type
*comp_cls_type
)
604 const char *at
= arg
;
605 GString
*gs_name
= NULL
;
606 GString
*gs_comp_cls_type
= NULL
;
607 GString
*gs_plugin
= NULL
;
608 GString
*gs_comp_cls
= NULL
;
614 assert(comp_cls_type
);
616 if (!bt_common_string_is_printable(arg
)) {
617 printf_err("Argument contains a non-printable character\n");
621 /* Parse the component name */
622 gs_name
= bt_common_string_until(at
, ".:\\", ":", &end_pos
);
627 if (arg
[end_pos
] == ':') {
631 g_string_assign(gs_name
, "");
634 /* Parse the component class type */
635 gs_comp_cls_type
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
636 if (!gs_comp_cls_type
|| at
[end_pos
] == '\0') {
637 printf_err("Missing component class type (`source`, `filter`, or `sink`)\n");
641 if (strcmp(gs_comp_cls_type
->str
, "source") == 0 ||
642 strcmp(gs_comp_cls_type
->str
, "src") == 0) {
643 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
644 } else if (strcmp(gs_comp_cls_type
->str
, "filter") == 0 ||
645 strcmp(gs_comp_cls_type
->str
, "flt") == 0) {
646 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
647 } else if (strcmp(gs_comp_cls_type
->str
, "sink") == 0) {
648 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
650 printf_err("Unknown component class type: `%s`\n",
651 gs_comp_cls_type
->str
);
657 /* Parse the plugin name */
658 gs_plugin
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
659 if (!gs_plugin
|| gs_plugin
->len
== 0 || at
[end_pos
] == '\0') {
660 printf_err("Missing plugin name\n");
666 /* Parse the component class name */
667 gs_comp_cls
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
668 if (!gs_comp_cls
|| gs_comp_cls
->len
== 0) {
669 printf_err("Missing component class name\n");
673 if (at
[end_pos
] != '\0') {
674 /* Found a non-escaped `.` */
679 if (gs_name
->len
== 0) {
681 g_string_free(gs_name
, TRUE
);
683 *name
= gs_name
->str
;
684 g_string_free(gs_name
, FALSE
);
687 g_string_free(gs_name
, TRUE
);
690 *plugin
= gs_plugin
->str
;
691 *comp_cls
= gs_comp_cls
->str
;
692 g_string_free(gs_plugin
, FALSE
);
693 g_string_free(gs_comp_cls
, FALSE
);
709 g_string_free(gs_name
, TRUE
);
713 g_string_free(gs_plugin
, TRUE
);
717 g_string_free(gs_comp_cls
, TRUE
);
720 if (gs_comp_cls_type
) {
721 g_string_free(gs_comp_cls_type
, TRUE
);
728 * Prints the Babeltrace version.
731 void print_version(void)
733 puts("Babeltrace " VERSION
);
737 * Destroys a component configuration.
740 void bt_config_component_destroy(struct bt_object
*obj
)
742 struct bt_config_component
*bt_config_component
=
743 container_of(obj
, struct bt_config_component
, base
);
749 if (bt_config_component
->plugin_name
) {
750 g_string_free(bt_config_component
->plugin_name
, TRUE
);
753 if (bt_config_component
->comp_cls_name
) {
754 g_string_free(bt_config_component
->comp_cls_name
, TRUE
);
757 if (bt_config_component
->instance_name
) {
758 g_string_free(bt_config_component
->instance_name
, TRUE
);
761 BT_PUT(bt_config_component
->params
);
762 g_free(bt_config_component
);
769 * Creates a component configuration using the given plugin name and
770 * component name. `plugin_name` and `comp_cls_name` are copied (belong
771 * to the return value).
773 * Return value is owned by the caller.
776 struct bt_config_component
*bt_config_component_create(
777 enum bt_component_class_type type
,
778 const char *plugin_name
, const char *comp_cls_name
)
780 struct bt_config_component
*cfg_component
= NULL
;
782 cfg_component
= g_new0(struct bt_config_component
, 1);
783 if (!cfg_component
) {
788 bt_object_init(cfg_component
, bt_config_component_destroy
);
789 cfg_component
->type
= type
;
790 cfg_component
->plugin_name
= g_string_new(plugin_name
);
791 if (!cfg_component
->plugin_name
) {
796 cfg_component
->comp_cls_name
= g_string_new(comp_cls_name
);
797 if (!cfg_component
->comp_cls_name
) {
802 cfg_component
->instance_name
= g_string_new(NULL
);
803 if (!cfg_component
->instance_name
) {
808 /* Start with empty parameters */
809 cfg_component
->params
= bt_value_map_create();
810 if (!cfg_component
->params
) {
818 BT_PUT(cfg_component
);
821 return cfg_component
;
825 * Creates a component configuration from a command-line --component
829 struct bt_config_component
*bt_config_component_from_arg(const char *arg
)
831 struct bt_config_component
*cfg_comp
= NULL
;
833 char *plugin_name
= NULL
;
834 char *comp_cls_name
= NULL
;
835 enum bt_component_class_type type
;
837 plugin_comp_cls_names(arg
, &name
, &plugin_name
, &comp_cls_name
, &type
);
838 if (!plugin_name
|| !comp_cls_name
) {
842 cfg_comp
= bt_config_component_create(type
, plugin_name
, comp_cls_name
);
848 g_string_assign(cfg_comp
->instance_name
, name
);
859 g_free(comp_cls_name
);
864 * Destroys a configuration.
867 void bt_config_destroy(struct bt_object
*obj
)
869 struct bt_config
*cfg
=
870 container_of(obj
, struct bt_config
, base
);
876 BT_PUT(cfg
->plugin_paths
);
878 switch (cfg
->command
) {
879 case BT_CONFIG_COMMAND_RUN
:
880 if (cfg
->cmd_data
.run
.sources
) {
881 g_ptr_array_free(cfg
->cmd_data
.run
.sources
, TRUE
);
884 if (cfg
->cmd_data
.run
.filters
) {
885 g_ptr_array_free(cfg
->cmd_data
.run
.filters
, TRUE
);
888 if (cfg
->cmd_data
.run
.sinks
) {
889 g_ptr_array_free(cfg
->cmd_data
.run
.sinks
, TRUE
);
892 if (cfg
->cmd_data
.run
.connections
) {
893 g_ptr_array_free(cfg
->cmd_data
.run
.connections
,
897 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
899 case BT_CONFIG_COMMAND_HELP
:
900 BT_PUT(cfg
->cmd_data
.help
.cfg_component
);
902 case BT_CONFIG_COMMAND_QUERY
:
903 BT_PUT(cfg
->cmd_data
.query
.cfg_component
);
905 if (cfg
->cmd_data
.query
.object
) {
906 g_string_free(cfg
->cmd_data
.query
.object
, TRUE
);
909 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
910 if (cfg
->cmd_data
.print_ctf_metadata
.path
) {
911 g_string_free(cfg
->cmd_data
.print_ctf_metadata
.path
,
915 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
916 if (cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
918 cfg
->cmd_data
.print_lttng_live_sessions
.url
,
933 void destroy_glist_of_gstring(GList
*list
)
941 for (at
= list
; at
!= NULL
; at
= g_list_next(at
)) {
942 g_string_free(at
->data
, TRUE
);
949 * Creates a simple lexical scanner for parsing comma-delimited names
952 * Return value is owned by the caller.
955 GScanner
*create_csv_identifiers_scanner(void)
958 GScannerConfig scanner_config
= {
959 .cset_skip_characters
= " \t\n",
960 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
961 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
962 .case_sensitive
= TRUE
,
963 .cpair_comment_single
= NULL
,
964 .skip_comment_multi
= TRUE
,
965 .skip_comment_single
= TRUE
,
966 .scan_comment_multi
= FALSE
,
967 .scan_identifier
= TRUE
,
968 .scan_identifier_1char
= TRUE
,
969 .scan_identifier_NULL
= FALSE
,
970 .scan_symbols
= FALSE
,
971 .symbol_2_token
= FALSE
,
972 .scope_0_fallback
= FALSE
,
973 .scan_binary
= FALSE
,
977 .scan_hex_dollar
= FALSE
,
978 .numbers_2_int
= FALSE
,
979 .int_2_float
= FALSE
,
980 .store_int64
= FALSE
,
981 .scan_string_sq
= FALSE
,
982 .scan_string_dq
= FALSE
,
983 .identifier_2_string
= FALSE
,
984 .char_2_token
= TRUE
,
987 scanner
= g_scanner_new(&scanner_config
);
996 * Converts a comma-delimited list of known names (--names option) to
997 * an array value object containing those names as string value objects.
999 * Return value is owned by the caller.
1002 struct bt_value
*names_from_arg(const char *arg
)
1004 GScanner
*scanner
= NULL
;
1005 struct bt_value
*names
= NULL
;
1006 bool found_all
= false, found_none
= false, found_item
= false;
1008 names
= bt_value_array_create();
1014 scanner
= create_csv_identifiers_scanner();
1019 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1022 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1024 switch (token_type
) {
1025 case G_TOKEN_IDENTIFIER
:
1027 const char *identifier
= scanner
->value
.v_identifier
;
1029 if (!strcmp(identifier
, "payload") ||
1030 !strcmp(identifier
, "args") ||
1031 !strcmp(identifier
, "arg")) {
1033 if (bt_value_array_append_string(names
,
1037 } else if (!strcmp(identifier
, "context") ||
1038 !strcmp(identifier
, "ctx")) {
1040 if (bt_value_array_append_string(names
,
1044 } else if (!strcmp(identifier
, "scope") ||
1045 !strcmp(identifier
, "header")) {
1047 if (bt_value_array_append_string(names
,
1051 } else if (!strcmp(identifier
, "all")) {
1053 if (bt_value_array_append_string(names
,
1057 } else if (!strcmp(identifier
, "none")) {
1059 if (bt_value_array_append_string(names
,
1064 printf_err("Unknown name: `%s`\n",
1080 if (found_none
&& found_all
) {
1081 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1085 * Legacy behavior is to clear the defaults (show none) when at
1086 * least one item is specified.
1088 if (found_item
&& !found_none
&& !found_all
) {
1089 if (bt_value_array_append_string(names
, "none")) {
1094 g_scanner_destroy(scanner
);
1101 g_scanner_destroy(scanner
);
1107 * Converts a comma-delimited list of known fields (--fields option) to
1108 * an array value object containing those fields as string
1111 * Return value is owned by the caller.
1114 struct bt_value
*fields_from_arg(const char *arg
)
1116 GScanner
*scanner
= NULL
;
1117 struct bt_value
*fields
;
1119 fields
= bt_value_array_create();
1125 scanner
= create_csv_identifiers_scanner();
1130 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1133 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1135 switch (token_type
) {
1136 case G_TOKEN_IDENTIFIER
:
1138 const char *identifier
= scanner
->value
.v_identifier
;
1140 if (!strcmp(identifier
, "trace") ||
1141 !strcmp(identifier
, "trace:hostname") ||
1142 !strcmp(identifier
, "trace:domain") ||
1143 !strcmp(identifier
, "trace:procname") ||
1144 !strcmp(identifier
, "trace:vpid") ||
1145 !strcmp(identifier
, "loglevel") ||
1146 !strcmp(identifier
, "emf") ||
1147 !strcmp(identifier
, "callsite") ||
1148 !strcmp(identifier
, "all")) {
1149 if (bt_value_array_append_string(fields
,
1154 printf_err("Unknown field: `%s`\n",
1176 g_scanner_destroy(scanner
);
1182 void append_param_arg(GString
*params_arg
, const char *key
, const char *value
)
1188 if (params_arg
->len
!= 0) {
1189 g_string_append_c(params_arg
, ',');
1192 g_string_append(params_arg
, key
);
1193 g_string_append_c(params_arg
, '=');
1194 g_string_append(params_arg
, value
);
1198 * Inserts the equivalent "prefix-NAME=yes" strings into params_arg
1199 * where the names are in names_array.
1202 int insert_flat_params_from_array(GString
*params_arg
,
1203 struct bt_value
*names_array
, const char *prefix
)
1207 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1208 bool default_set
= false, non_default_set
= false;
1211 * names_array may be NULL if no CLI options were specified to
1212 * trigger its creation.
1218 tmpstr
= g_string_new(NULL
);
1225 default_value
= g_string_new(NULL
);
1226 if (!default_value
) {
1232 for (i
= 0; i
< bt_value_array_size(names_array
); i
++) {
1233 struct bt_value
*str_obj
= bt_value_array_get(names_array
, i
);
1235 bool is_default
= false;
1238 printf_err("Unexpected error\n");
1243 ret
= bt_value_string_get(str_obj
, &suffix
);
1246 printf_err("Unexpected error\n");
1250 g_string_assign(tmpstr
, prefix
);
1251 g_string_append(tmpstr
, "-");
1253 /* Special-case for "all" and "none". */
1254 if (!strcmp(suffix
, "all")) {
1256 g_string_assign(default_value
, "show");
1257 } else if (!strcmp(suffix
, "none")) {
1259 g_string_assign(default_value
, "hide");
1263 g_string_append(tmpstr
, "default");
1264 append_param_arg(params_arg
, tmpstr
->str
,
1265 default_value
->str
);
1267 non_default_set
= true;
1268 g_string_append(tmpstr
, suffix
);
1269 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1273 /* Implicit field-default=hide if any non-default option is set. */
1274 if (non_default_set
&& !default_set
) {
1275 g_string_assign(tmpstr
, prefix
);
1276 g_string_append(tmpstr
, "-default");
1277 g_string_assign(default_value
, "hide");
1278 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1282 if (default_value
) {
1283 g_string_free(default_value
, TRUE
);
1287 g_string_free(tmpstr
, TRUE
);
1300 OPT_CLOCK_FORCE_CORRELATE
,
1303 OPT_CLOCK_OFFSET_NS
,
1310 OPT_DEBUG_INFO_FULL_PATH
,
1311 OPT_DEBUG_INFO_TARGET_PREFIX
,
1322 OPT_OMIT_HOME_PLUGIN_PATH
,
1323 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1329 OPT_RESET_BASE_PARAMS
,
1333 OPT_STREAM_INTERSECTION
,
1340 enum bt_config_component_dest
{
1341 BT_CONFIG_COMPONENT_DEST_UNKNOWN
= -1,
1342 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1343 BT_CONFIG_COMPONENT_DEST_FILTER
,
1344 BT_CONFIG_COMPONENT_DEST_SINK
,
1348 * Adds a configuration component to the appropriate configuration
1349 * array depending on the destination.
1352 void add_run_cfg_comp(struct bt_config
*cfg
,
1353 struct bt_config_component
*cfg_comp
,
1354 enum bt_config_component_dest dest
)
1359 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1360 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1362 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1363 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1365 case BT_CONFIG_COMPONENT_DEST_SINK
:
1366 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1374 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1375 struct bt_config_component
*cfg_comp
,
1376 enum bt_config_component_dest dest
,
1377 struct bt_value
*instance_names
)
1381 if (cfg_comp
->instance_name
->len
== 0) {
1382 printf_err("Found an unnamed component\n");
1387 if (bt_value_map_has_key(instance_names
, cfg_comp
->instance_name
->str
)) {
1388 printf_err("Duplicate component instance name:\n %s\n",
1389 cfg_comp
->instance_name
->str
);
1394 if (bt_value_map_insert(instance_names
,
1395 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1401 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1408 int append_env_var_plugin_paths(struct bt_value
*plugin_paths
)
1413 if (bt_common_is_setuid_setgid()) {
1414 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1418 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1423 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1427 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1434 int append_home_and_system_plugin_paths(struct bt_value
*plugin_paths
,
1435 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1439 if (!omit_home_plugin_path
) {
1440 if (bt_common_is_setuid_setgid()) {
1441 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1443 char *home_plugin_dir
=
1444 bt_common_get_home_plugin_path();
1446 if (home_plugin_dir
) {
1447 ret
= bt_config_append_plugin_paths(
1448 plugin_paths
, home_plugin_dir
);
1449 free(home_plugin_dir
);
1452 printf_err("Invalid home plugin path\n");
1459 if (!omit_system_plugin_path
) {
1460 if (bt_config_append_plugin_paths(plugin_paths
,
1461 bt_common_get_system_plugin_path())) {
1462 printf_err("Invalid system plugin path\n");
1468 printf_err("Cannot append home and system plugin paths\n");
1473 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1475 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1476 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1480 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1481 struct bt_value
*initial_plugin_paths
, bool needs_plugins
)
1483 struct bt_config
*cfg
;
1486 cfg
= g_new0(struct bt_config
, 1);
1492 bt_object_init(cfg
, bt_config_destroy
);
1493 cfg
->command
= command
;
1494 cfg
->command_needs_plugins
= needs_plugins
;
1496 if (initial_plugin_paths
) {
1497 cfg
->plugin_paths
= bt_get(initial_plugin_paths
);
1499 cfg
->plugin_paths
= bt_value_array_create();
1500 if (!cfg
->plugin_paths
) {
1516 struct bt_config
*bt_config_run_create(
1517 struct bt_value
*initial_plugin_paths
)
1519 struct bt_config
*cfg
;
1522 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1523 initial_plugin_paths
, true);
1528 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1529 (GDestroyNotify
) bt_put
);
1530 if (!cfg
->cmd_data
.run
.sources
) {
1535 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1536 (GDestroyNotify
) bt_put
);
1537 if (!cfg
->cmd_data
.run
.filters
) {
1542 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1543 (GDestroyNotify
) bt_put
);
1544 if (!cfg
->cmd_data
.run
.sinks
) {
1549 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1550 (GDestroyNotify
) bt_config_connection_destroy
);
1551 if (!cfg
->cmd_data
.run
.connections
) {
1566 struct bt_config
*bt_config_list_plugins_create(
1567 struct bt_value
*initial_plugin_paths
)
1569 struct bt_config
*cfg
;
1572 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1573 initial_plugin_paths
, true);
1588 struct bt_config
*bt_config_help_create(
1589 struct bt_value
*initial_plugin_paths
)
1591 struct bt_config
*cfg
;
1594 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1595 initial_plugin_paths
, true);
1600 cfg
->cmd_data
.help
.cfg_component
=
1601 bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN
,
1603 if (!cfg
->cmd_data
.help
.cfg_component
) {
1617 struct bt_config
*bt_config_query_create(
1618 struct bt_value
*initial_plugin_paths
)
1620 struct bt_config
*cfg
;
1623 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1624 initial_plugin_paths
, true);
1629 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1630 if (!cfg
->cmd_data
.query
.object
) {
1645 struct bt_config
*bt_config_print_ctf_metadata_create(
1646 struct bt_value
*initial_plugin_paths
)
1648 struct bt_config
*cfg
;
1651 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1652 initial_plugin_paths
, true);
1657 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1658 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1673 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1674 struct bt_value
*initial_plugin_paths
)
1676 struct bt_config
*cfg
;
1679 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1680 initial_plugin_paths
, true);
1685 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1686 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1701 int bt_config_append_plugin_paths_check_setuid_setgid(
1702 struct bt_value
*plugin_paths
, const char *arg
)
1706 if (bt_common_is_setuid_setgid()) {
1707 printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
1711 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1712 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1723 * Prints the expected format for a --params option.
1726 void print_expected_params_format(FILE *fp
)
1728 fprintf(fp
, "Expected format of PARAMS\n");
1729 fprintf(fp
, "-------------------------\n");
1731 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1733 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1734 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1735 fprintf(fp
, "and VALUE can be one of:\n");
1737 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1738 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1739 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1740 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1741 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1742 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1743 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1744 fprintf(fp
, " the null and boolean value symbols above.\n");
1745 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1747 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1749 fprintf(fp
, "Example:\n");
1751 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1752 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1753 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1755 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1756 fprintf(fp
, "babeltrace from a shell.\n");
1761 * Prints the help command usage.
1764 void print_help_usage(FILE *fp
)
1766 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1767 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --component=TYPE.PLUGIN.CLS\n");
1769 fprintf(fp
, "Options:\n");
1771 fprintf(fp
, " -c, --component=TYPE.PLUGIN.CLS Get help for the component class CLS of\n");
1772 fprintf(fp
, " type TYPE (`source`, `filter`, or `sink`)\n");
1773 fprintf(fp
, " found in the plugin PLUGIN\n");
1774 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1775 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1776 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1777 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1778 fprintf(fp
, " dynamic plugins can be loaded\n");
1779 fprintf(fp
, " -h --help Show this help and quit\n");
1781 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1783 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1787 struct poptOption help_long_options
[] = {
1788 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1789 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
1790 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1791 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1792 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1793 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1794 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1798 * Creates a Babeltrace config object from the arguments of a help
1801 * *retcode is set to the appropriate exit code to use.
1804 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1805 int *retcode
, bool force_omit_system_plugin_path
,
1806 bool force_omit_home_plugin_path
,
1807 struct bt_value
*initial_plugin_paths
)
1809 poptContext pc
= NULL
;
1813 struct bt_config
*cfg
= NULL
;
1814 const char *leftover
;
1815 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1816 char *plug_comp_cls_names
= NULL
;
1819 cfg
= bt_config_help_create(initial_plugin_paths
);
1824 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1825 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1826 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1832 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1833 help_long_options
, 0);
1835 printf_err("Cannot get popt context\n");
1839 poptReadDefaultConfig(pc
, 0);
1841 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1842 arg
= poptGetOptArg(pc
);
1845 case OPT_PLUGIN_PATH
:
1846 if (bt_config_append_plugin_paths_check_setuid_setgid(
1847 cfg
->plugin_paths
, arg
)) {
1851 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1852 cfg
->omit_system_plugin_path
= true;
1854 case OPT_OMIT_HOME_PLUGIN_PATH
:
1855 cfg
->omit_home_plugin_path
= true;
1858 if (plug_comp_cls_names
) {
1859 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
1864 plug_comp_cls_names
= strdup(arg
);
1865 if (!plug_comp_cls_names
) {
1871 print_help_usage(stdout
);
1876 printf_err("Unknown command-line option specified (option code %d)\n",
1885 /* Check for option parsing error */
1887 printf_err("While parsing command-line options, at option %s: %s\n",
1888 poptBadOption(pc
, 0), poptStrerror(opt
));
1892 leftover
= poptGetArg(pc
);
1894 if (!plug_comp_cls_names
) {
1895 printf_err("Cannot specify plugin name and --component component class:\n %s\n",
1900 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1903 if (!plug_comp_cls_names
) {
1904 print_help_usage(stdout
);
1910 plugin_comp_cls_names(plug_comp_cls_names
, NULL
,
1911 &plugin_name
, &comp_cls_name
,
1912 &cfg
->cmd_data
.help
.cfg_component
->type
);
1913 if (plugin_name
&& comp_cls_name
) {
1914 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1916 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1919 printf_err("Invalid --component option's argument:\n %s\n",
1920 plug_comp_cls_names
);
1925 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1936 free(plug_comp_cls_names
);
1937 g_free(plugin_name
);
1938 g_free(comp_cls_name
);
1941 poptFreeContext(pc
);
1949 * Prints the help command usage.
1952 void print_query_usage(FILE *fp
)
1954 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] OBJECT --component=TYPE.PLUGIN.CLS\n");
1956 fprintf(fp
, "Options:\n");
1958 fprintf(fp
, " -c, --component=TYPE.PLUGIN.CLS Query the component class CLS of type TYPE\n");
1959 fprintf(fp
, " (`source`, `filter`, or `sink`) found in\n");
1960 fprintf(fp
, " the plugin PLUGIN\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 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
1977 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1978 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1979 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1980 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1981 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1982 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1986 * Creates a Babeltrace config object from the arguments of a query
1989 * *retcode is set to the appropriate exit code to use.
1992 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1993 int *retcode
, bool force_omit_system_plugin_path
,
1994 bool force_omit_home_plugin_path
,
1995 struct bt_value
*initial_plugin_paths
)
1997 poptContext pc
= NULL
;
2001 struct bt_config
*cfg
= NULL
;
2002 const char *leftover
;
2003 struct bt_value
*params
= bt_value_null
;
2006 cfg
= bt_config_query_create(initial_plugin_paths
);
2011 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2012 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2013 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2019 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2020 query_long_options
, 0);
2022 printf_err("Cannot get popt context\n");
2026 poptReadDefaultConfig(pc
, 0);
2028 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2029 arg
= poptGetOptArg(pc
);
2032 case OPT_PLUGIN_PATH
:
2033 if (bt_config_append_plugin_paths_check_setuid_setgid(
2034 cfg
->plugin_paths
, arg
)) {
2038 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2039 cfg
->omit_system_plugin_path
= true;
2041 case OPT_OMIT_HOME_PLUGIN_PATH
:
2042 cfg
->omit_home_plugin_path
= true;
2045 if (cfg
->cmd_data
.query
.cfg_component
) {
2046 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
2051 cfg
->cmd_data
.query
.cfg_component
=
2052 bt_config_component_from_arg(arg
);
2053 if (!cfg
->cmd_data
.query
.cfg_component
) {
2054 printf_err("Invalid format for --component option's argument:\n %s\n",
2059 /* Default parameters: null */
2060 bt_put(cfg
->cmd_data
.query
.cfg_component
->params
);
2061 cfg
->cmd_data
.query
.cfg_component
->params
=
2066 params
= bt_value_from_arg(arg
);
2068 printf_err("Invalid format for --params option's argument:\n %s\n",
2075 print_query_usage(stdout
);
2080 printf_err("Unknown command-line option specified (option code %d)\n",
2089 if (!cfg
->cmd_data
.query
.cfg_component
) {
2090 printf_err("No target component class specified with --component option\n");
2095 BT_MOVE(cfg
->cmd_data
.query
.cfg_component
->params
, params
);
2097 /* Check for option parsing error */
2099 printf_err("While parsing command-line options, at option %s: %s\n",
2100 poptBadOption(pc
, 0), poptStrerror(opt
));
2105 * We need exactly one leftover argument which is the
2108 leftover
= poptGetArg(pc
);
2110 if (strlen(leftover
) == 0) {
2111 printf_err("Invalid empty object\n");
2115 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2117 print_query_usage(stdout
);
2123 leftover
= poptGetArg(pc
);
2125 printf_err("Unexpected argument: %s\n", leftover
);
2129 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2141 poptFreeContext(pc
);
2150 * Prints the list-plugins command usage.
2153 void print_list_plugins_usage(FILE *fp
)
2155 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2157 fprintf(fp
, "Options:\n");
2159 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2160 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2161 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2162 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2163 fprintf(fp
, " dynamic plugins can be loaded\n");
2164 fprintf(fp
, " -h --help Show this help and quit\n");
2166 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2168 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2172 struct poptOption list_plugins_long_options
[] = {
2173 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2174 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2175 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2176 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2177 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2178 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2182 * Creates a Babeltrace config object from the arguments of a
2183 * list-plugins command.
2185 * *retcode is set to the appropriate exit code to use.
2188 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2189 int *retcode
, bool force_omit_system_plugin_path
,
2190 bool force_omit_home_plugin_path
,
2191 struct bt_value
*initial_plugin_paths
)
2193 poptContext pc
= NULL
;
2197 struct bt_config
*cfg
= NULL
;
2198 const char *leftover
;
2201 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2206 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2207 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2208 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2214 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2215 list_plugins_long_options
, 0);
2217 printf_err("Cannot get popt context\n");
2221 poptReadDefaultConfig(pc
, 0);
2223 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2224 arg
= poptGetOptArg(pc
);
2227 case OPT_PLUGIN_PATH
:
2228 if (bt_config_append_plugin_paths_check_setuid_setgid(
2229 cfg
->plugin_paths
, arg
)) {
2233 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2234 cfg
->omit_system_plugin_path
= true;
2236 case OPT_OMIT_HOME_PLUGIN_PATH
:
2237 cfg
->omit_home_plugin_path
= true;
2240 print_list_plugins_usage(stdout
);
2245 printf_err("Unknown command-line option specified (option code %d)\n",
2254 /* Check for option parsing error */
2256 printf_err("While parsing command-line options, at option %s: %s\n",
2257 poptBadOption(pc
, 0), poptStrerror(opt
));
2261 leftover
= poptGetArg(pc
);
2263 printf_err("Unexpected argument: %s\n", leftover
);
2267 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2279 poptFreeContext(pc
);
2287 * Prints the run command usage.
2290 void print_run_usage(FILE *fp
)
2292 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2294 fprintf(fp
, "Options:\n");
2296 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2297 fprintf(fp
, " for all the following components until\n");
2298 fprintf(fp
, " --reset-base-params is encountered\n");
2299 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2300 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2301 fprintf(fp
, " Instantiate the component class CLS of type\n");
2302 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2303 fprintf(fp
, " in the plugin PLUGIN, add it to the graph,\n");
2304 fprintf(fp
, " and optionally name it NAME (you can also\n");
2305 fprintf(fp
, " specify the name with --name)\n");
2306 fprintf(fp
, " -C, --connect=CONNECTION Connect two created components (see the\n");
2307 fprintf(fp
, " expected format of CONNECTION below)\n");
2308 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2309 fprintf(fp
, " parameter key to KEY (see --value)\n");
2310 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2311 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2312 fprintf(fp
, " names of the created components)\n");
2313 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2314 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2315 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2316 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2317 fprintf(fp
, " current component (see the expected format\n");
2318 fprintf(fp
, " of PARAMS below)\n");
2319 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2320 fprintf(fp
, " dynamic plugins can be loaded\n");
2321 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2322 fprintf(fp
, " empty map\n");
2323 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2324 fprintf(fp
, " the graph later, retry in DUR µs\n");
2325 fprintf(fp
, " (default: 100000)\n");
2326 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2327 fprintf(fp
, " the current component with a name given by\n");
2328 fprintf(fp
, " the last argument of the --key option and a\n");
2329 fprintf(fp
, " value set to VAL\n");
2330 fprintf(fp
, " -h --help Show this help and quit\n");
2332 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2333 fprintf(fp
, "\n\n");
2334 fprintf(fp
, "Expected format of CONNECTION\n");
2335 fprintf(fp
, "-----------------------------\n");
2337 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2339 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2340 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2341 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2342 fprintf(fp
, "component with the --name option.\n");
2344 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2345 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2346 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2348 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2349 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2350 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2351 fprintf(fp
, "DOWNSTREAM.\n");
2353 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2354 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2355 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2357 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2358 fprintf(fp
, "can connect a filter component to a sink component.\n");
2360 fprintf(fp
, "Examples:\n");
2362 fprintf(fp
, " my-src:my-sink\n");
2363 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2365 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2366 fprintf(fp
, "babeltrace from a shell.\n");
2367 fprintf(fp
, "\n\n");
2368 print_expected_params_format(fp
);
2372 * Creates a Babeltrace config object from the arguments of a run
2375 * *retcode is set to the appropriate exit code to use.
2378 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2379 int *retcode
, bool force_omit_system_plugin_path
,
2380 bool force_omit_home_plugin_path
,
2381 struct bt_value
*initial_plugin_paths
)
2383 poptContext pc
= NULL
;
2385 struct bt_config_component
*cur_cfg_comp
= NULL
;
2386 enum bt_config_component_dest cur_cfg_comp_dest
=
2387 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
2388 struct bt_value
*cur_base_params
= NULL
;
2390 struct bt_config
*cfg
= NULL
;
2391 struct bt_value
*instance_names
= NULL
;
2392 struct bt_value
*connection_args
= NULL
;
2393 GString
*cur_param_key
= NULL
;
2394 char error_buf
[256] = { 0 };
2395 long long retry_duration
= -1;
2396 struct poptOption run_long_options
[] = {
2397 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2398 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2399 { "connect", 'C', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2400 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2401 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2402 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2403 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2404 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2405 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2406 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2407 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2408 { "retry-duration", '\0', POPT_ARG_LONGLONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2409 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2410 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2414 cur_param_key
= g_string_new(NULL
);
2415 if (!cur_param_key
) {
2421 print_run_usage(stdout
);
2426 cfg
= bt_config_run_create(initial_plugin_paths
);
2431 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2432 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2433 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2434 cur_base_params
= bt_value_map_create();
2435 if (!cur_base_params
) {
2440 instance_names
= bt_value_map_create();
2441 if (!instance_names
) {
2446 connection_args
= bt_value_array_create();
2447 if (!connection_args
) {
2452 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2458 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2459 run_long_options
, 0);
2461 printf_err("Cannot get popt context\n");
2465 poptReadDefaultConfig(pc
, 0);
2467 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2468 arg
= poptGetOptArg(pc
);
2471 case OPT_PLUGIN_PATH
:
2472 if (bt_config_append_plugin_paths_check_setuid_setgid(
2473 cfg
->plugin_paths
, arg
)) {
2477 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2478 cfg
->omit_system_plugin_path
= true;
2480 case OPT_OMIT_HOME_PLUGIN_PATH
:
2481 cfg
->omit_home_plugin_path
= true;
2485 enum bt_config_component_dest new_dest
;
2488 ret
= add_run_cfg_comp_check_name(cfg
,
2489 cur_cfg_comp
, cur_cfg_comp_dest
,
2491 BT_PUT(cur_cfg_comp
);
2497 cur_cfg_comp
= bt_config_component_from_arg(arg
);
2498 if (!cur_cfg_comp
) {
2499 printf_err("Invalid format for --component option's argument:\n %s\n",
2504 switch (cur_cfg_comp
->type
) {
2505 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
2506 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2508 case BT_COMPONENT_CLASS_TYPE_FILTER
:
2509 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2511 case BT_COMPONENT_CLASS_TYPE_SINK
:
2512 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2518 assert(cur_base_params
);
2519 bt_put(cur_cfg_comp
->params
);
2520 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
2521 if (!cur_cfg_comp
->params
) {
2526 cur_cfg_comp_dest
= new_dest
;
2531 struct bt_value
*params
;
2532 struct bt_value
*params_to_set
;
2534 if (!cur_cfg_comp
) {
2535 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2540 params
= bt_value_from_arg(arg
);
2542 printf_err("Invalid format for --params option's argument:\n %s\n",
2547 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
2550 if (!params_to_set
) {
2551 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2556 BT_MOVE(cur_cfg_comp
->params
, params_to_set
);
2560 if (strlen(arg
) == 0) {
2561 printf_err("Cannot set an empty string as the current parameter key\n");
2565 g_string_assign(cur_param_key
, arg
);
2568 if (!cur_cfg_comp
) {
2569 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2574 if (cur_param_key
->len
== 0) {
2575 printf_err("--value option specified without preceding --key option:\n %s\n",
2580 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2581 cur_param_key
->str
, arg
)) {
2587 if (!cur_cfg_comp
) {
2588 printf_err("Cannot set the name of unavailable component:\n %s\n",
2593 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2595 case OPT_BASE_PARAMS
:
2597 struct bt_value
*params
= bt_value_from_arg(arg
);
2600 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2605 BT_MOVE(cur_base_params
, params
);
2608 case OPT_RESET_BASE_PARAMS
:
2609 BT_PUT(cur_base_params
);
2610 cur_base_params
= bt_value_map_create();
2611 if (!cur_base_params
) {
2617 if (bt_value_array_append_string(connection_args
,
2623 case OPT_RETRY_DURATION
:
2624 if (retry_duration
< 0) {
2625 printf_err("--retry-duration option's argument must be positive or 0: %lld\n",
2630 cfg
->cmd_data
.run
.retry_duration_us
=
2631 (uint64_t) retry_duration
;
2634 print_run_usage(stdout
);
2639 printf_err("Unknown command-line option specified (option code %d)\n",
2648 /* Check for option parsing error */
2650 printf_err("While parsing command-line options, at option %s: %s\n",
2651 poptBadOption(pc
, 0), poptStrerror(opt
));
2655 /* This command does not accept leftover arguments */
2656 if (poptPeekArg(pc
)) {
2657 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2661 /* Add current component */
2663 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2664 cur_cfg_comp_dest
, instance_names
);
2665 BT_PUT(cur_cfg_comp
);
2671 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2672 printf_err("Incomplete graph: no source component\n");
2676 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2677 printf_err("Incomplete graph: no sink component\n");
2681 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2685 ret
= bt_config_cli_args_create_connections(cfg
, connection_args
,
2688 printf_err("Cannot creation connections:\n%s", error_buf
);
2700 poptFreeContext(pc
);
2703 if (cur_param_key
) {
2704 g_string_free(cur_param_key
, TRUE
);
2708 BT_PUT(cur_cfg_comp
);
2709 BT_PUT(cur_base_params
);
2710 BT_PUT(instance_names
);
2711 BT_PUT(connection_args
);
2716 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2717 int *retcode
, bool force_omit_system_plugin_path
,
2718 bool force_omit_home_plugin_path
,
2719 struct bt_value
*initial_plugin_paths
)
2721 struct bt_config
*cfg
= NULL
;
2724 const size_t argc
= bt_value_array_size(run_args
) + 1;
2726 argv
= calloc(argc
, sizeof(*argv
));
2734 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
2736 struct bt_value
*arg_value
= bt_value_array_get(run_args
, i
);
2740 ret
= bt_value_string_get(arg_value
, &arg
);
2747 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2748 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2749 initial_plugin_paths
);
2757 * Prints the convert command usage.
2760 void print_convert_usage(FILE *fp
)
2762 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2764 fprintf(fp
, "Options:\n");
2766 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2767 fprintf(fp
, " Instantiate the component class CLS of type\n");
2768 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2769 fprintf(fp
, " in the plugin PLUGIN, add it to the\n");
2770 fprintf(fp
, " conversion graph, and optionally name it\n");
2771 fprintf(fp
, " NAME (you can also specify the name with\n");
2772 fprintf(fp
, " --name)\n");
2773 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2774 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2775 fprintf(fp
, " names of the created components)\n");
2776 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2777 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2778 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2779 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2780 fprintf(fp
, " current component (see the expected format\n");
2781 fprintf(fp
, " of PARAMS below)\n");
2782 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2783 fprintf(fp
, " current component to PATH\n");
2784 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2785 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2786 fprintf(fp
, " the graph later, retry in DUR µs\n");
2787 fprintf(fp
, " (default: 100000)\n");
2788 fprintf(fp
, " dynamic plugins can be loaded\n");
2789 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2790 fprintf(fp
, " `run` command to the standard output,\n");
2791 fprintf(fp
, " formatted for a shell, and quit\n");
2792 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2793 fprintf(fp
, " `run` command to the standard output,\n");
2794 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2795 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2796 fprintf(fp
, " current component to URL\n");
2797 fprintf(fp
, " -h --help Show this help and quit\n");
2799 fprintf(fp
, "Implicit `source.ctf.fs` component options:\n");
2801 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2802 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2803 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2804 fprintf(fp
, " are active\n");
2806 fprintf(fp
, "Implicit `sink.text.pretty` component options:\n");
2808 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2809 fprintf(fp
, " --clock-date Print timestamp dates\n");
2810 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2811 fprintf(fp
, " time zone instead of the local time zone\n");
2812 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2813 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2814 fprintf(fp
, " --color=(never | auto | always)\n");
2815 fprintf(fp
, " Never, automatically, or always emit\n");
2816 fprintf(fp
, " console color codes\n");
2817 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2818 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2819 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2820 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2821 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2822 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2823 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2824 fprintf(fp
, " (or `ctx`)\n");
2825 fprintf(fp
, " --no-delta Do not print time delta between\n");
2826 fprintf(fp
, " consecutive events\n");
2827 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2828 fprintf(fp
, " the standard output\n");
2830 fprintf(fp
, "Implicit `filter.utils.muxer` component options:\n");
2832 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2833 fprintf(fp
, " correlated across traces\n");
2835 fprintf(fp
, "Implicit `filter.utils.trimmer` component options:\n");
2837 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2838 fprintf(fp
, " time range to BEGIN (see the format of\n");
2839 fprintf(fp
, " BEGIN below)\n");
2840 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2841 fprintf(fp
, " range to END (see the format of END below)\n");
2842 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2843 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2844 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2846 fprintf(fp
, "Implicit `filter.lttng-utils.debug-info` component options:\n");
2848 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2849 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2850 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2851 fprintf(fp
, " binary paths instead of just names\n");
2852 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2853 fprintf(fp
, " Use directory DIR as a prefix when\n");
2854 fprintf(fp
, " looking up executables during debug\n");
2855 fprintf(fp
, " info analysis\n");
2856 fprintf(fp
, " --no-debug-info Do not create an implicit\n");
2857 fprintf(fp
, " `lttng-utils.debug-info` filter component\n");
2859 fprintf(fp
, "Legacy options that still work:\n");
2861 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2862 fprintf(fp
, " `ctf`:\n");
2863 fprintf(fp
, " Create an implicit `source.ctf.fs`\n");
2864 fprintf(fp
, " component\n");
2865 fprintf(fp
, " `lttng-live`:\n");
2866 fprintf(fp
, " Create an implicit `source.ctf.lttng-live`\n");
2867 fprintf(fp
, " component\n");
2868 fprintf(fp
, " -o, --output-format=(text | ctf | dummy | ctf-metadata)\n");
2869 fprintf(fp
, " `text`:\n");
2870 fprintf(fp
, " Create an implicit `sink.text.pretty`\n");
2871 fprintf(fp
, " component\n");
2872 fprintf(fp
, " `text`:\n");
2873 fprintf(fp
, " Create an implicit `sink.ctf.fs`\n");
2874 fprintf(fp
, " component\n");
2875 fprintf(fp
, " `dummy`:\n");
2876 fprintf(fp
, " Create an implicit `sink.utils.dummy`\n");
2877 fprintf(fp
, " component\n");
2878 fprintf(fp
, " `ctf-metadata`:\n");
2879 fprintf(fp
, " Query the `source.ctf.fs` component class\n");
2880 fprintf(fp
, " for metadata text and quit\n");
2882 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2883 fprintf(fp
, "\n\n");
2884 fprintf(fp
, "Format of BEGIN and END\n");
2885 fprintf(fp
, "-----------------------\n");
2887 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2888 fprintf(fp
, "\n\n");
2889 print_expected_params_format(fp
);
2893 struct poptOption convert_long_options
[] = {
2894 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2895 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2896 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2897 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2898 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2899 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2900 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2901 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2902 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2903 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2904 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2905 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2906 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2907 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2908 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2909 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2910 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2911 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2912 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2913 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2914 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2915 { "no-debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DEBUG_INFO
, NULL
, NULL
},
2916 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2917 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2918 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2919 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2920 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2921 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2922 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2923 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2924 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2925 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2926 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2927 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2928 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2929 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2930 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2931 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2935 GString
*get_component_auto_name(const char *prefix
,
2936 struct bt_value
*existing_names
)
2939 GString
*auto_name
= g_string_new(NULL
);
2946 if (!bt_value_map_has_key(existing_names
, prefix
)) {
2947 g_string_assign(auto_name
, prefix
);
2952 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2954 } while (bt_value_map_has_key(existing_names
, auto_name
->str
));
2960 struct implicit_component_args
{
2964 GString
*params_arg
;
2965 struct bt_value
*extra_params
;
2969 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
2970 const char *prefix
, struct bt_value
*existing_names
,
2971 GList
**comp_names
, bool append_to_comp_names
)
2974 GString
*name
= NULL
;
2976 if (!args
->exists
) {
2980 name
= get_component_auto_name(prefix
, existing_names
);
2987 g_string_assign(args
->name_arg
, name
->str
);
2989 if (bt_value_map_insert(existing_names
, name
->str
,
2996 if (append_to_comp_names
) {
2997 *comp_names
= g_list_append(*comp_names
, name
);
3003 g_string_free(name
, TRUE
);
3010 int append_run_args_for_implicit_component(
3011 struct implicit_component_args
*impl_args
,
3012 struct bt_value
*run_args
)
3017 if (!impl_args
->exists
) {
3021 if (bt_value_array_append_string(run_args
, "--component")) {
3026 if (bt_value_array_append_string(run_args
, impl_args
->comp_arg
->str
)) {
3031 if (bt_value_array_append_string(run_args
, "--name")) {
3036 if (bt_value_array_append_string(run_args
, impl_args
->name_arg
->str
)) {
3041 if (impl_args
->params_arg
->len
> 0) {
3042 if (bt_value_array_append_string(run_args
, "--params")) {
3047 if (bt_value_array_append_string(run_args
,
3048 impl_args
->params_arg
->str
)) {
3054 for (i
= 0; i
< bt_value_array_size(impl_args
->extra_params
); i
++) {
3055 struct bt_value
*elem
;
3058 elem
= bt_value_array_get(impl_args
->extra_params
, i
);
3063 assert(bt_value_is_string(elem
));
3064 if (bt_value_string_get(elem
, &arg
)) {
3068 ret
= bt_value_array_append_string(run_args
, arg
);
3086 void finalize_implicit_component_args(struct implicit_component_args
*args
)
3090 if (args
->comp_arg
) {
3091 g_string_free(args
->comp_arg
, TRUE
);
3094 if (args
->name_arg
) {
3095 g_string_free(args
->name_arg
, TRUE
);
3098 if (args
->params_arg
) {
3099 g_string_free(args
->params_arg
, TRUE
);
3102 bt_put(args
->extra_params
);
3106 void destroy_implicit_component_args(void *args
)
3112 finalize_implicit_component_args(args
);
3117 int init_implicit_component_args(struct implicit_component_args
*args
,
3118 const char *comp_arg
, bool exists
)
3122 args
->exists
= exists
;
3123 args
->comp_arg
= g_string_new(comp_arg
);
3124 args
->name_arg
= g_string_new(NULL
);
3125 args
->params_arg
= g_string_new(NULL
);
3126 args
->extra_params
= bt_value_array_create();
3128 if (!args
->comp_arg
|| !args
->name_arg
||
3129 !args
->params_arg
|| !args
->extra_params
) {
3131 finalize_implicit_component_args(args
);
3141 void append_implicit_component_param(struct implicit_component_args
*args
,
3142 const char *key
, const char *value
)
3147 append_param_arg(args
->params_arg
, key
, value
);
3151 int append_implicit_component_extra_param(struct implicit_component_args
*args
,
3152 const char *key
, const char *value
)
3160 if (bt_value_array_append_string(args
->extra_params
, "--key")) {
3166 if (bt_value_array_append_string(args
->extra_params
, key
)) {
3172 if (bt_value_array_append_string(args
->extra_params
, "--value")) {
3178 if (bt_value_array_append_string(args
->extra_params
, value
)) {
3189 int convert_append_name_param(enum bt_config_component_dest dest
,
3190 GString
*cur_name
, GString
*cur_name_prefix
,
3191 struct bt_value
*run_args
, struct bt_value
*all_names
,
3192 GList
**source_names
, GList
**filter_names
,
3197 if (cur_name_prefix
->len
> 0) {
3198 /* We're after a --component option */
3199 GString
*name
= NULL
;
3200 bool append_name_opt
= false;
3202 if (cur_name
->len
== 0) {
3204 * No explicit name was provided for the user
3207 name
= get_component_auto_name(cur_name_prefix
->str
,
3209 append_name_opt
= true;
3212 * An explicit name was provided for the user
3215 if (bt_value_map_has_key(all_names
,
3217 printf_err("Duplicate component instance name:\n %s\n",
3222 name
= g_string_new(cur_name
->str
);
3231 * Remember this name globally, for the uniqueness of
3232 * all component names.
3234 if (bt_value_map_insert(all_names
, name
->str
, bt_value_null
)) {
3240 * Append the --name option if necessary.
3242 if (append_name_opt
) {
3243 if (bt_value_array_append_string(run_args
, "--name")) {
3248 if (bt_value_array_append_string(run_args
, name
->str
)) {
3255 * Remember this name specifically for the type of the
3256 * component. This is to create connection arguments.
3259 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3260 *source_names
= g_list_append(*source_names
, name
);
3262 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3263 *filter_names
= g_list_append(*filter_names
, name
);
3265 case BT_CONFIG_COMPONENT_DEST_SINK
:
3266 *sink_names
= g_list_append(*sink_names
, name
);
3272 g_string_assign(cur_name_prefix
, "");
3285 * Escapes `.`, `:`, and `\` of `input` with `\`.
3288 GString
*escape_dot_colon(const char *input
)
3290 GString
*output
= g_string_new(NULL
);
3298 for (ch
= input
; *ch
!= '\0'; ch
++) {
3299 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3300 g_string_append_c(output
, '\\');
3303 g_string_append_c(output
, *ch
);
3311 * Appends a --connect option to a list of arguments. `upstream_name`
3312 * and `downstream_name` are escaped with escape_dot_colon() in this
3316 int append_connect_arg(struct bt_value
*run_args
,
3317 const char *upstream_name
, const char *downstream_name
)
3320 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3321 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3322 GString
*arg
= g_string_new(NULL
);
3324 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3330 ret
= bt_value_array_append_string(run_args
, "--connect");
3337 g_string_append(arg
, e_upstream_name
->str
);
3338 g_string_append_c(arg
, ':');
3339 g_string_append(arg
, e_downstream_name
->str
);
3340 ret
= bt_value_array_append_string(run_args
, arg
->str
);
3349 g_string_free(arg
, TRUE
);
3352 if (e_upstream_name
) {
3353 g_string_free(e_upstream_name
, TRUE
);
3356 if (e_downstream_name
) {
3357 g_string_free(e_downstream_name
, TRUE
);
3364 * Appends the run command's --connect options for the convert command.
3367 int convert_auto_connect(struct bt_value
*run_args
,
3368 GList
*source_names
, GList
*filter_names
,
3372 GList
*source_at
= source_names
;
3373 GList
*filter_at
= filter_names
;
3375 GList
*sink_at
= sink_names
;
3377 assert(source_names
);
3378 assert(filter_names
);
3381 /* Connect all sources to the first filter */
3382 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3383 GString
*source_name
= source_at
->data
;
3384 GString
*filter_name
= filter_at
->data
;
3386 ret
= append_connect_arg(run_args
, source_name
->str
,
3393 filter_prev
= filter_at
;
3394 filter_at
= g_list_next(filter_at
);
3396 /* Connect remaining filters */
3397 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3398 GString
*filter_name
= filter_at
->data
;
3399 GString
*filter_prev_name
= filter_prev
->data
;
3401 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3408 /* Connect last filter to all sinks */
3409 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3410 GString
*filter_name
= filter_prev
->data
;
3411 GString
*sink_name
= sink_at
->data
;
3413 ret
= append_connect_arg(run_args
, filter_name
->str
,
3430 int split_timerange(const char *arg
, char **begin
, char **end
)
3433 const char *ch
= arg
;
3435 GString
*g_begin
= NULL
;
3436 GString
*g_end
= NULL
;
3444 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3445 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3451 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3452 if (!g_end
|| g_end
->len
== 0) {
3458 *begin
= g_begin
->str
;
3460 g_string_free(g_begin
, FALSE
);
3461 g_string_free(g_end
, FALSE
);
3471 g_string_free(g_begin
, TRUE
);
3475 g_string_free(g_end
, TRUE
);
3482 int g_list_prepend_gstring(GList
**list
, const char *string
)
3485 GString
*gs
= g_string_new(string
);
3494 *list
= g_list_prepend(*list
, gs
);
3501 struct implicit_component_args
*create_implicit_component_args(void)
3503 struct implicit_component_args
*impl_args
=
3504 g_new0(struct implicit_component_args
, 1);
3510 if (init_implicit_component_args(impl_args
, NULL
, true)) {
3511 destroy_implicit_component_args(impl_args
);
3521 int fill_implicit_ctf_inputs_args(GPtrArray
*implicit_ctf_inputs_args
,
3522 struct implicit_component_args
*base_implicit_ctf_input_args
,
3528 for (leftover
= leftovers
; leftover
!= NULL
;
3529 leftover
= g_list_next(leftover
)) {
3530 GString
*gs_leftover
= leftover
->data
;
3531 struct implicit_component_args
*impl_args
=
3532 create_implicit_component_args();
3539 impl_args
->exists
= true;
3540 g_string_assign(impl_args
->comp_arg
,
3541 base_implicit_ctf_input_args
->comp_arg
->str
);
3542 g_string_assign(impl_args
->params_arg
,
3543 base_implicit_ctf_input_args
->params_arg
->str
);
3546 * We need our own copy of the extra parameters because
3547 * this is where the unique path goes.
3549 BT_PUT(impl_args
->extra_params
);
3550 impl_args
->extra_params
=
3551 bt_value_copy(base_implicit_ctf_input_args
->extra_params
);
3554 destroy_implicit_component_args(impl_args
);
3558 /* Append unique path parameter */
3559 ret
= append_implicit_component_extra_param(impl_args
,
3560 "path", gs_leftover
->str
);
3562 destroy_implicit_component_args(impl_args
);
3566 g_ptr_array_add(implicit_ctf_inputs_args
, impl_args
);
3579 * Creates a Babeltrace config object from the arguments of a convert
3582 * *retcode is set to the appropriate exit code to use.
3585 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3586 int *retcode
, bool force_omit_system_plugin_path
,
3587 bool force_omit_home_plugin_path
, bool force_no_debug_info
,
3588 struct bt_value
*initial_plugin_paths
)
3590 poptContext pc
= NULL
;
3592 enum bt_config_component_dest cur_comp_dest
=
3593 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3595 struct bt_config
*cfg
= NULL
;
3596 bool got_verbose_opt
= false;
3597 bool got_debug_opt
= false;
3598 bool got_input_format_opt
= false;
3599 bool got_output_format_opt
= false;
3600 bool trimmer_has_begin
= false;
3601 bool trimmer_has_end
= false;
3602 GString
*cur_name
= NULL
;
3603 GString
*cur_name_prefix
= NULL
;
3604 const char *leftover
= NULL
;
3605 bool print_run_args
= false;
3606 bool print_run_args_0
= false;
3607 bool print_ctf_metadata
= false;
3608 struct bt_value
*run_args
= NULL
;
3609 struct bt_value
*all_names
= NULL
;
3610 GList
*source_names
= NULL
;
3611 GList
*filter_names
= NULL
;
3612 GList
*sink_names
= NULL
;
3613 GList
*leftovers
= NULL
;
3614 GPtrArray
*implicit_ctf_inputs_args
= NULL
;
3615 struct implicit_component_args base_implicit_ctf_input_args
= { 0 };
3616 struct implicit_component_args implicit_ctf_output_args
= { 0 };
3617 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3618 struct implicit_component_args implicit_dummy_args
= { 0 };
3619 struct implicit_component_args implicit_text_args
= { 0 };
3620 struct implicit_component_args implicit_debug_info_args
= { 0 };
3621 struct implicit_component_args implicit_muxer_args
= { 0 };
3622 struct implicit_component_args implicit_trimmer_args
= { 0 };
3623 struct bt_value
*plugin_paths
= bt_get(initial_plugin_paths
);
3624 char error_buf
[256] = { 0 };
3626 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3627 char *output
= NULL
;
3632 print_convert_usage(stdout
);
3637 if (init_implicit_component_args(&base_implicit_ctf_input_args
,
3638 "source.ctf.fs", false)) {
3642 if (init_implicit_component_args(&implicit_ctf_output_args
,
3643 "sink.ctf.fs", false)) {
3647 if (init_implicit_component_args(&implicit_lttng_live_args
,
3648 "source.ctf.lttng-live", false)) {
3652 if (init_implicit_component_args(&implicit_text_args
,
3653 "sink.text.pretty", false)) {
3657 if (init_implicit_component_args(&implicit_dummy_args
,
3658 "sink.utils.dummy", false)) {
3662 if (init_implicit_component_args(&implicit_debug_info_args
,
3663 "filter.lttng-utils.debug-info", !force_no_debug_info
)) {
3667 if (init_implicit_component_args(&implicit_muxer_args
,
3668 "filter.utils.muxer", true)) {
3672 if (init_implicit_component_args(&implicit_trimmer_args
,
3673 "filter.utils.trimmer", false)) {
3677 implicit_ctf_inputs_args
= g_ptr_array_new_with_free_func(
3678 (GDestroyNotify
) destroy_implicit_component_args
);
3679 if (!implicit_ctf_inputs_args
) {
3684 all_names
= bt_value_map_create();
3690 run_args
= bt_value_array_create();
3696 cur_name
= g_string_new(NULL
);
3702 cur_name_prefix
= g_string_new(NULL
);
3703 if (!cur_name_prefix
) {
3708 ret
= append_env_var_plugin_paths(plugin_paths
);
3714 * First pass: collect all arguments which need to be passed
3715 * as is to the run command. This pass can also add --name
3716 * arguments if needed to automatically name unnamed component
3717 * instances. Also it does the following transformations:
3719 * --path=PATH -> --key path --value PATH
3720 * --url=URL -> --key url --value URL
3722 * Also it appends the plugin paths of --plugin-path to
3725 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3726 convert_long_options
, 0);
3728 printf_err("Cannot get popt context\n");
3732 poptReadDefaultConfig(pc
, 0);
3734 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3736 char *plugin_name
= NULL
;
3737 char *comp_cls_name
= NULL
;
3739 arg
= poptGetOptArg(pc
);
3744 enum bt_component_class_type type
;
3745 const char *type_prefix
;
3747 /* Append current component's name if needed */
3748 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3749 cur_name_prefix
, run_args
, all_names
,
3750 &source_names
, &filter_names
, &sink_names
);
3755 /* Parse the argument */
3756 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3757 &comp_cls_name
, &type
);
3758 if (!plugin_name
|| !comp_cls_name
) {
3759 printf_err("Invalid format for --component option's argument:\n %s\n",
3765 g_string_assign(cur_name
, name
);
3767 g_string_assign(cur_name
, "");
3771 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3772 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3773 type_prefix
= "source";
3775 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3776 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
3777 type_prefix
= "filter";
3779 case BT_COMPONENT_CLASS_TYPE_SINK
:
3780 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3781 type_prefix
= "sink";
3787 if (bt_value_array_append_string(run_args
,
3793 if (bt_value_array_append_string(run_args
, arg
)) {
3798 g_string_assign(cur_name_prefix
, "");
3799 g_string_append_printf(cur_name_prefix
, "%s.%s.%s",
3800 type_prefix
, plugin_name
, comp_cls_name
);
3803 free(comp_cls_name
);
3806 comp_cls_name
= NULL
;
3810 if (cur_name_prefix
->len
== 0) {
3811 printf_err("No current component of which to set parameters:\n %s\n",
3816 if (bt_value_array_append_string(run_args
,
3822 if (bt_value_array_append_string(run_args
, arg
)) {
3828 if (cur_name_prefix
->len
== 0) {
3829 printf_err("No current component of which to set `path` parameter:\n %s\n",
3834 if (bt_value_array_append_string(run_args
, "--key")) {
3839 if (bt_value_array_append_string(run_args
, "path")) {
3844 if (bt_value_array_append_string(run_args
, "--value")) {
3849 if (bt_value_array_append_string(run_args
, arg
)) {
3855 if (cur_name_prefix
->len
== 0) {
3856 printf_err("No current component of which to set `url` parameter:\n %s\n",
3861 if (bt_value_array_append_string(run_args
, "--key")) {
3866 if (bt_value_array_append_string(run_args
, "url")) {
3871 if (bt_value_array_append_string(run_args
, "--value")) {
3876 if (bt_value_array_append_string(run_args
, arg
)) {
3882 if (cur_name_prefix
->len
== 0) {
3883 printf_err("No current component to name:\n %s\n",
3888 if (bt_value_array_append_string(run_args
, "--name")) {
3893 if (bt_value_array_append_string(run_args
, arg
)) {
3898 g_string_assign(cur_name
, arg
);
3900 case OPT_OMIT_HOME_PLUGIN_PATH
:
3901 force_omit_home_plugin_path
= true;
3903 if (bt_value_array_append_string(run_args
,
3904 "--omit-home-plugin-path")) {
3909 case OPT_RETRY_DURATION
:
3910 if (bt_value_array_append_string(run_args
,
3911 "--retry-duration")) {
3916 if (bt_value_array_append_string(run_args
, arg
)) {
3921 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3922 force_omit_system_plugin_path
= true;
3924 if (bt_value_array_append_string(run_args
,
3925 "--omit-system-plugin-path")) {
3930 case OPT_PLUGIN_PATH
:
3931 if (bt_config_append_plugin_paths_check_setuid_setgid(
3932 plugin_paths
, arg
)) {
3936 if (bt_value_array_append_string(run_args
,
3942 if (bt_value_array_append_string(run_args
, arg
)) {
3948 print_convert_usage(stdout
);
3953 case OPT_CLOCK_CYCLES
:
3954 case OPT_CLOCK_DATE
:
3955 case OPT_CLOCK_FORCE_CORRELATE
:
3957 case OPT_CLOCK_OFFSET
:
3958 case OPT_CLOCK_OFFSET_NS
:
3959 case OPT_CLOCK_SECONDS
:
3962 case OPT_DEBUG_INFO_DIR
:
3963 case OPT_DEBUG_INFO_FULL_PATH
:
3964 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3967 case OPT_INPUT_FORMAT
:
3969 case OPT_NO_DEBUG_INFO
:
3971 case OPT_OUTPUT_FORMAT
:
3974 case OPT_RUN_ARGS_0
:
3975 case OPT_STREAM_INTERSECTION
:
3978 /* Ignore in this pass */
3981 printf_err("Unknown command-line option specified (option code %d)\n",
3990 /* Append current component's name if needed */
3991 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3992 cur_name_prefix
, run_args
, all_names
, &source_names
,
3993 &filter_names
, &sink_names
);
3998 /* Check for option parsing error */
4000 printf_err("While parsing command-line options, at option %s: %s\n",
4001 poptBadOption(pc
, 0), poptStrerror(opt
));
4005 poptFreeContext(pc
);
4010 * Second pass: transform the convert-specific options and
4011 * arguments into implicit component instances for the run
4014 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
4015 convert_long_options
, 0);
4017 printf_err("Cannot get popt context\n");
4021 poptReadDefaultConfig(pc
, 0);
4023 while ((opt
= poptGetNextOpt(pc
)) > 0) {
4024 arg
= poptGetOptArg(pc
);
4028 if (trimmer_has_begin
) {
4029 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4034 trimmer_has_begin
= true;
4035 ret
= append_implicit_component_extra_param(
4036 &implicit_trimmer_args
, "begin", arg
);
4037 implicit_trimmer_args
.exists
= true;
4043 if (trimmer_has_end
) {
4044 printf("At --end option: --end or --timerange option already specified\n %s\n",
4049 trimmer_has_end
= true;
4050 ret
= append_implicit_component_extra_param(
4051 &implicit_trimmer_args
, "end", arg
);
4052 implicit_trimmer_args
.exists
= true;
4062 if (trimmer_has_begin
|| trimmer_has_end
) {
4063 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4068 ret
= split_timerange(arg
, &begin
, &end
);
4070 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4075 ret
= append_implicit_component_extra_param(
4076 &implicit_trimmer_args
, "begin", begin
);
4077 ret
|= append_implicit_component_extra_param(
4078 &implicit_trimmer_args
, "end", end
);
4079 implicit_trimmer_args
.exists
= true;
4087 case OPT_CLOCK_CYCLES
:
4088 append_implicit_component_param(
4089 &implicit_text_args
, "clock-cycles", "yes");
4090 implicit_text_args
.exists
= true;
4092 case OPT_CLOCK_DATE
:
4093 append_implicit_component_param(
4094 &implicit_text_args
, "clock-date", "yes");
4095 implicit_text_args
.exists
= true;
4097 case OPT_CLOCK_FORCE_CORRELATE
:
4098 append_implicit_component_param(
4099 &implicit_muxer_args
, "assume-absolute-clock-classes", "yes");
4102 append_implicit_component_param(
4103 &implicit_text_args
, "clock-gmt", "yes");
4104 implicit_text_args
.exists
= true;
4106 case OPT_CLOCK_OFFSET
:
4107 base_implicit_ctf_input_args
.exists
= true;
4108 ret
= append_implicit_component_extra_param(
4109 &base_implicit_ctf_input_args
, "clock-offset-cycles", arg
);
4114 case OPT_CLOCK_OFFSET_NS
:
4115 base_implicit_ctf_input_args
.exists
= true;
4116 ret
= append_implicit_component_extra_param(
4117 &base_implicit_ctf_input_args
,
4118 "clock-offset-ns", arg
);
4123 case OPT_CLOCK_SECONDS
:
4124 append_implicit_component_param(
4125 &implicit_text_args
, "clock-seconds", "yes");
4126 implicit_text_args
.exists
= true;
4129 implicit_text_args
.exists
= true;
4130 ret
= append_implicit_component_extra_param(
4131 &implicit_text_args
, "color", arg
);
4136 case OPT_NO_DEBUG_INFO
:
4137 implicit_debug_info_args
.exists
= false;
4139 case OPT_DEBUG_INFO_DIR
:
4140 implicit_debug_info_args
.exists
= true;
4141 ret
= append_implicit_component_extra_param(
4142 &implicit_debug_info_args
, "dir", arg
);
4147 case OPT_DEBUG_INFO_FULL_PATH
:
4148 implicit_debug_info_args
.exists
= true;
4149 append_implicit_component_param(
4150 &implicit_debug_info_args
, "full-path", "yes");
4152 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4153 implicit_debug_info_args
.exists
= true;
4154 ret
= append_implicit_component_extra_param(
4155 &implicit_debug_info_args
,
4156 "target-prefix", arg
);
4163 struct bt_value
*fields
= fields_from_arg(arg
);
4169 implicit_text_args
.exists
= true;
4170 ret
= insert_flat_params_from_array(
4171 implicit_text_args
.params_arg
,
4181 struct bt_value
*names
= names_from_arg(arg
);
4187 implicit_text_args
.exists
= true;
4188 ret
= insert_flat_params_from_array(
4189 implicit_text_args
.params_arg
,
4198 append_implicit_component_param(
4199 &implicit_text_args
, "no-delta", "yes");
4200 implicit_text_args
.exists
= true;
4202 case OPT_INPUT_FORMAT
:
4203 if (got_input_format_opt
) {
4204 printf_err("Duplicate --input-format option\n");
4208 got_input_format_opt
= true;
4210 if (strcmp(arg
, "ctf") == 0) {
4211 base_implicit_ctf_input_args
.exists
= true;
4212 } else if (strcmp(arg
, "lttng-live") == 0) {
4213 implicit_lttng_live_args
.exists
= true;
4215 printf_err("Unknown legacy input format:\n %s\n",
4220 case OPT_OUTPUT_FORMAT
:
4221 if (got_output_format_opt
) {
4222 printf_err("Duplicate --output-format option\n");
4226 got_output_format_opt
= true;
4228 if (strcmp(arg
, "text") == 0) {
4229 implicit_text_args
.exists
= true;
4230 } else if (strcmp(arg
, "ctf") == 0) {
4231 implicit_ctf_output_args
.exists
= true;
4232 } else if (strcmp(arg
, "dummy") == 0) {
4233 implicit_dummy_args
.exists
= true;
4234 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4235 print_ctf_metadata
= true;
4237 printf_err("Unknown legacy output format:\n %s\n",
4244 printf_err("Duplicate --output option\n");
4248 output
= strdup(arg
);
4255 if (print_run_args_0
) {
4256 printf_err("Cannot specify --run-args and --run-args-0\n");
4260 print_run_args
= true;
4262 case OPT_RUN_ARGS_0
:
4263 if (print_run_args
) {
4264 printf_err("Cannot specify --run-args and --run-args-0\n");
4268 print_run_args_0
= true;
4270 case OPT_STREAM_INTERSECTION
:
4271 append_implicit_component_param(
4272 &base_implicit_ctf_input_args
,
4273 "stream-intersection", "yes");
4274 base_implicit_ctf_input_args
.exists
= true;
4277 if (got_verbose_opt
) {
4278 printf_err("Duplicate -v/--verbose option\n");
4282 append_implicit_component_param(&implicit_text_args
,
4284 implicit_text_args
.exists
= true;
4285 got_verbose_opt
= true;
4288 got_debug_opt
= true;
4296 /* Check for option parsing error */
4298 printf_err("While parsing command-line options, at option %s: %s\n",
4299 poptBadOption(pc
, 0), poptStrerror(opt
));
4304 * Append home and system plugin paths now that we possibly got
4307 if (append_home_and_system_plugin_paths(plugin_paths
,
4308 force_omit_system_plugin_path
,
4309 force_omit_home_plugin_path
)) {
4313 /* Consume and keep leftover arguments */
4314 while ((leftover
= poptGetArg(pc
))) {
4315 GString
*gs_leftover
= g_string_new(leftover
);
4322 leftovers
= g_list_append(leftovers
, gs_leftover
);
4324 g_string_free(gs_leftover
, TRUE
);
4330 /* Print CTF metadata or print LTTng live sessions */
4331 if (print_ctf_metadata
) {
4332 GString
*gs_leftover
;
4334 if (g_list_length(leftovers
) == 0) {
4335 printf_err("--output-format=ctf-metadata specified without a path\n");
4339 if (g_list_length(leftovers
) > 1) {
4340 printf_err("Too many paths specified for --output-format=ctf-metadata\n");
4344 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4349 cfg
->debug
= got_debug_opt
;
4350 cfg
->verbose
= got_verbose_opt
;
4351 gs_leftover
= leftovers
->data
;
4352 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4358 * If -o ctf was specified, make sure an output path (--output)
4359 * was also specified. --output does not imply -o ctf because
4360 * it's also used for the default, implicit -o text if -o ctf
4363 if (implicit_ctf_output_args
.exists
) {
4365 printf_err("--output-format=ctf specified without --output (trace output path)\n");
4370 * At this point we know that -o ctf AND --output were
4371 * specified. Make sure that no options were specified
4372 * which would imply -o text because --output would be
4373 * ambiguous in this case. For example, this is wrong:
4375 * babeltrace --names=all -o ctf --output=/tmp/path my-trace
4377 * because --names=all implies -o text, and --output
4378 * could apply to both the sink.text.pretty and
4379 * sink.ctf.fs implicit components.
4381 if (implicit_text_args
.exists
) {
4382 printf_err("Ambiguous --output option: --output-format=ctf specified but another option implies --output-format=text\n");
4388 * If -o dummy and -o ctf were not specified, and if there are
4389 * no explicit sink components, then use an implicit
4390 * `sink.text.pretty` component.
4392 if (!implicit_dummy_args
.exists
&& !implicit_ctf_output_args
.exists
&&
4394 implicit_text_args
.exists
= true;
4398 * Set implicit `sink.text.pretty` or `sink.ctf.fs` component's
4399 * `path` parameter if --output was specified.
4402 if (implicit_text_args
.exists
) {
4403 append_implicit_component_extra_param(&implicit_text_args
,
4405 } else if (implicit_ctf_output_args
.exists
) {
4406 append_implicit_component_extra_param(&implicit_ctf_output_args
,
4411 /* Decide where the leftover argument(s) go */
4412 if (g_list_length(leftovers
) > 0) {
4413 if (implicit_lttng_live_args
.exists
) {
4414 GString
*gs_leftover
;
4416 if (g_list_length(leftovers
) > 1) {
4417 printf_err("Too many URLs specified for --output-format=lttng-live\n");
4421 gs_leftover
= leftovers
->data
;
4422 lttng_live_url_parts
=
4423 bt_common_parse_lttng_live_url(gs_leftover
->str
,
4424 error_buf
, sizeof(error_buf
));
4425 if (!lttng_live_url_parts
.proto
) {
4426 printf_err("Invalid LTTng live URL format: %s\n",
4431 if (!lttng_live_url_parts
.session_name
) {
4432 /* Print LTTng live sessions */
4433 cfg
= bt_config_print_lttng_live_sessions_create(
4439 cfg
->debug
= got_debug_opt
;
4440 cfg
->verbose
= got_verbose_opt
;
4441 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4446 ret
= append_implicit_component_extra_param(
4447 &implicit_lttng_live_args
, "url",
4454 * Append one implicit component argument set
4455 * for each leftover (souce.ctf.fs paths). Copy
4456 * the base implicit component arguments.
4457 * Note that they still have to be named later.
4459 ret
= fill_implicit_ctf_inputs_args(
4460 implicit_ctf_inputs_args
,
4461 &base_implicit_ctf_input_args
, leftovers
);
4469 * Ensure mutual exclusion between implicit `source.ctf.fs` and
4470 * `source.ctf.lttng-live` components.
4472 if (base_implicit_ctf_input_args
.exists
&&
4473 implicit_lttng_live_args
.exists
) {
4474 printf_err("Cannot create both implicit `%s` and `%s` components\n",
4475 base_implicit_ctf_input_args
.comp_arg
->str
,
4476 implicit_lttng_live_args
.comp_arg
->str
);
4481 * If the implicit `source.ctf.fs` or `source.ctf.lttng-live`
4482 * components exists, make sure there's at least one leftover
4483 * (which is the path or URL).
4485 if (base_implicit_ctf_input_args
.exists
&&
4486 g_list_length(leftovers
) == 0) {
4487 printf_err("Missing path for implicit `%s` component\n",
4488 base_implicit_ctf_input_args
.comp_arg
->str
);
4492 if (implicit_lttng_live_args
.exists
&& g_list_length(leftovers
) == 0) {
4493 printf_err("Missing URL for implicit `%s` component\n",
4494 implicit_lttng_live_args
.comp_arg
->str
);
4498 /* Assign names to implicit components */
4499 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4500 struct implicit_component_args
*impl_args
=
4501 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4503 ret
= assign_name_to_implicit_component(impl_args
,
4504 "source-ctf-fs", all_names
, &source_names
, true);
4510 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4511 "lttng-live", all_names
, &source_names
, true);
4516 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4517 "pretty", all_names
, &sink_names
, true);
4522 ret
= assign_name_to_implicit_component(&implicit_ctf_output_args
,
4523 "sink-ctf-fs", all_names
, &sink_names
, true);
4528 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4529 "dummy", all_names
, &sink_names
, true);
4534 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4535 "muxer", all_names
, NULL
, false);
4540 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4541 "trimmer", all_names
, NULL
, false);
4546 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4547 "debug-info", all_names
, NULL
, false);
4552 /* Make sure there's at least one source and one sink */
4553 if (!source_names
) {
4554 printf_err("No source component\n");
4559 printf_err("No sink component\n");
4564 * Prepend the muxer, the trimmer, and the debug info to the
4565 * filter chain so that we have:
4567 * sources -> muxer -> [trimmer] -> [debug info] ->
4568 * [user filters] -> sinks
4570 if (implicit_debug_info_args
.exists
) {
4571 if (g_list_prepend_gstring(&filter_names
,
4572 implicit_debug_info_args
.name_arg
->str
)) {
4577 if (implicit_trimmer_args
.exists
) {
4578 if (g_list_prepend_gstring(&filter_names
,
4579 implicit_trimmer_args
.name_arg
->str
)) {
4584 if (g_list_prepend_gstring(&filter_names
,
4585 implicit_muxer_args
.name_arg
->str
)) {
4590 * Append the equivalent run arguments for the implicit
4593 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4594 struct implicit_component_args
*impl_args
=
4595 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4597 ret
= append_run_args_for_implicit_component(impl_args
,
4604 ret
= append_run_args_for_implicit_component(&implicit_lttng_live_args
,
4610 ret
= append_run_args_for_implicit_component(&implicit_text_args
,
4616 ret
= append_run_args_for_implicit_component(&implicit_ctf_output_args
,
4622 ret
= append_run_args_for_implicit_component(&implicit_dummy_args
,
4628 ret
= append_run_args_for_implicit_component(&implicit_muxer_args
,
4634 ret
= append_run_args_for_implicit_component(&implicit_trimmer_args
,
4640 ret
= append_run_args_for_implicit_component(&implicit_debug_info_args
,
4646 /* Auto-connect components */
4647 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4650 printf_err("Cannot auto-connect components\n");
4655 * We have all the run command arguments now. Depending on
4656 * --run-args, we pass this to the run command or print them
4659 if (print_run_args
|| print_run_args_0
) {
4660 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
4661 struct bt_value
*arg_value
=
4662 bt_value_array_get(run_args
, i
);
4664 GString
*quoted
= NULL
;
4665 const char *arg_to_print
;
4668 ret
= bt_value_string_get(arg_value
, &arg
);
4672 if (print_run_args
) {
4673 quoted
= bt_common_shell_quote(arg
, true);
4678 arg_to_print
= quoted
->str
;
4683 printf("%s", arg_to_print
);
4686 g_string_free(quoted
, TRUE
);
4689 if (i
< bt_value_array_size(run_args
) - 1) {
4690 if (print_run_args
) {
4703 cfg
= bt_config_run_from_args_array(run_args
, retcode
,
4704 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
4705 initial_plugin_paths
);
4710 cfg
->debug
= got_debug_opt
;
4711 cfg
->verbose
= got_verbose_opt
;
4720 poptFreeContext(pc
);
4727 g_string_free(cur_name
, TRUE
);
4730 if (cur_name_prefix
) {
4731 g_string_free(cur_name_prefix
, TRUE
);
4734 if (implicit_ctf_inputs_args
) {
4735 g_ptr_array_free(implicit_ctf_inputs_args
, TRUE
);
4740 destroy_glist_of_gstring(source_names
);
4741 destroy_glist_of_gstring(filter_names
);
4742 destroy_glist_of_gstring(sink_names
);
4743 destroy_glist_of_gstring(leftovers
);
4744 finalize_implicit_component_args(&base_implicit_ctf_input_args
);
4745 finalize_implicit_component_args(&implicit_ctf_output_args
);
4746 finalize_implicit_component_args(&implicit_lttng_live_args
);
4747 finalize_implicit_component_args(&implicit_dummy_args
);
4748 finalize_implicit_component_args(&implicit_text_args
);
4749 finalize_implicit_component_args(&implicit_debug_info_args
);
4750 finalize_implicit_component_args(&implicit_muxer_args
);
4751 finalize_implicit_component_args(&implicit_trimmer_args
);
4752 bt_put(plugin_paths
);
4753 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4758 * Prints the Babeltrace 2.x general usage.
4761 void print_gen_usage(FILE *fp
)
4763 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4765 fprintf(fp
, "General options:\n");
4767 fprintf(fp
, " -d, --debug Turn on debug mode\n");
4768 fprintf(fp
, " -h --help Show this help and quit\n");
4769 fprintf(fp
, " -v, --verbose Turn on verbose mode\n");
4770 fprintf(fp
, " -V, --version Show version and quit\n");
4772 fprintf(fp
, "Available commands:\n");
4774 fprintf(fp
, " convert Convert and trim traces (default)\n");
4775 fprintf(fp
, " help Get help for a plugin or a component class\n");
4776 fprintf(fp
, " list-plugins List available plugins and their content\n");
4777 fprintf(fp
, " query Query objects from a component class\n");
4778 fprintf(fp
, " run Build a processing graph and run it\n");
4780 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4783 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4784 int *retcode
, bool force_omit_system_plugin_path
,
4785 bool force_omit_home_plugin_path
, bool force_no_debug_info
,
4786 struct bt_value
*initial_plugin_paths
)
4788 struct bt_config
*config
= NULL
;
4789 bool verbose
= false;
4792 const char **command_argv
= NULL
;
4793 int command_argc
= -1;
4794 const char *command_name
= NULL
;
4797 COMMAND_TYPE_NONE
= -1,
4798 COMMAND_TYPE_RUN
= 0,
4799 COMMAND_TYPE_CONVERT
,
4800 COMMAND_TYPE_LIST_PLUGINS
,
4803 } command_type
= COMMAND_TYPE_NONE
;
4807 if (!initial_plugin_paths
) {
4808 initial_plugin_paths
= bt_value_array_create();
4809 if (!initial_plugin_paths
) {
4814 bt_get(initial_plugin_paths
);
4818 print_gen_usage(stdout
);
4822 for (i
= 1; i
< argc
; i
++) {
4823 const char *cur_arg
= argv
[i
];
4825 if (strcmp(cur_arg
, "-d") == 0 ||
4826 strcmp(cur_arg
, "--debug") == 0) {
4828 } else if (strcmp(cur_arg
, "-v") == 0 ||
4829 strcmp(cur_arg
, "--verbose") == 0) {
4831 } else if (strcmp(cur_arg
, "-V") == 0 ||
4832 strcmp(cur_arg
, "--version") == 0) {
4835 } else if (strcmp(cur_arg
, "-h") == 0 ||
4836 strcmp(cur_arg
, "--help") == 0) {
4837 print_gen_usage(stdout
);
4840 bool has_command
= true;
4843 * First unknown argument: is it a known command
4846 if (strcmp(cur_arg
, "convert") == 0) {
4847 command_type
= COMMAND_TYPE_CONVERT
;
4848 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4849 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4850 } else if (strcmp(cur_arg
, "help") == 0) {
4851 command_type
= COMMAND_TYPE_HELP
;
4852 } else if (strcmp(cur_arg
, "query") == 0) {
4853 command_type
= COMMAND_TYPE_QUERY
;
4854 } else if (strcmp(cur_arg
, "run") == 0) {
4855 command_type
= COMMAND_TYPE_RUN
;
4858 * Unknown argument, but not a known
4859 * command name: assume the whole
4860 * arguments are for the default convert
4863 command_type
= COMMAND_TYPE_CONVERT
;
4864 command_argv
= argv
;
4865 command_argc
= argc
;
4866 has_command
= false;
4870 command_argv
= &argv
[i
];
4871 command_argc
= argc
- i
;
4872 command_name
= cur_arg
;
4878 if (command_type
== COMMAND_TYPE_NONE
) {
4880 * We only got non-help, non-version general options
4881 * like --verbose and --debug, without any other
4882 * arguments, so we can't do anything useful: print the
4885 print_gen_usage(stdout
);
4889 assert(command_argv
);
4890 assert(command_argc
>= 0);
4892 switch (command_type
) {
4893 case COMMAND_TYPE_RUN
:
4894 config
= bt_config_run_from_args(command_argc
, command_argv
,
4895 retcode
, force_omit_system_plugin_path
,
4896 force_omit_home_plugin_path
, initial_plugin_paths
);
4898 case COMMAND_TYPE_CONVERT
:
4899 config
= bt_config_convert_from_args(command_argc
, command_argv
,
4900 retcode
, force_omit_system_plugin_path
,
4901 force_omit_home_plugin_path
, force_no_debug_info
,
4902 initial_plugin_paths
);
4904 case COMMAND_TYPE_LIST_PLUGINS
:
4905 config
= bt_config_list_plugins_from_args(command_argc
,
4906 command_argv
, retcode
, force_omit_system_plugin_path
,
4907 force_omit_home_plugin_path
, initial_plugin_paths
);
4909 case COMMAND_TYPE_HELP
:
4910 config
= bt_config_help_from_args(command_argc
,
4911 command_argv
, retcode
, force_omit_system_plugin_path
,
4912 force_omit_home_plugin_path
, initial_plugin_paths
);
4914 case COMMAND_TYPE_QUERY
:
4915 config
= bt_config_query_from_args(command_argc
,
4916 command_argv
, retcode
, force_omit_system_plugin_path
,
4917 force_omit_home_plugin_path
, initial_plugin_paths
);
4925 config
->verbose
= true;
4929 config
->debug
= true;
4932 config
->command_name
= command_name
;
4936 bt_put(initial_plugin_paths
);