2 * Babeltrace trace converter - parameter parsing
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #define BT_LOG_TAG "CLI-CFG-CLI-ARGS"
35 #include <babeltrace/babeltrace.h>
36 #include <babeltrace/common-internal.h>
37 #include <babeltrace/values.h>
40 #include <sys/types.h>
41 #include "babeltrace-cfg.h"
42 #include "babeltrace-cfg-cli-args.h"
43 #include "babeltrace-cfg-cli-args-connect.h"
46 * Error printf() macro which prepends "Error: " the first time it's
47 * called. This gives a nicer feel than having a bunch of error prefixes
48 * (since the following lines usually describe the error and possible
49 * solutions), or the error prefix just at the end.
51 #define printf_err(fmt, args...) \
53 if (is_first_error) { \
54 fprintf(stderr, "Command line error: "); \
55 is_first_error = false; \
57 fprintf(stderr, fmt, ##args); \
60 static bool is_first_error
= true;
62 /* INI-style parsing FSM states */
63 enum ini_parsing_fsm_state
{
64 /* Expect a map key (identifier) */
67 /* Expect an equal character ('=') */
73 /* Expect a negative number value */
74 INI_EXPECT_VALUE_NUMBER_NEG
,
76 /* Expect a comma character (',') */
80 /* INI-style parsing state variables */
81 struct ini_parsing_state
{
82 /* Lexical scanner (owned by this) */
85 /* Output map value object being filled (owned by this) */
86 struct bt_value
*params
;
88 /* Next expected FSM state */
89 enum ini_parsing_fsm_state expecting
;
91 /* Last decoded map key (owned by this) */
94 /* Complete INI-style string to parse (not owned by this) */
97 /* Error buffer (not owned by this) */
101 /* Offset option with "is set" boolean */
107 /* Legacy "ctf"/"lttng-live" format options */
108 struct ctf_legacy_opts
{
109 struct offset_opt offset_s
;
110 struct offset_opt offset_ns
;
111 bool stream_intersection
;
114 /* Legacy "text" format options */
115 struct text_legacy_opts
{
117 * output, dbg_info_dir, dbg_info_target_prefix, names,
118 * and fields are owned by this.
121 GString
*dbg_info_dir
;
122 GString
*dbg_info_target_prefix
;
123 struct bt_value
*names
;
124 struct bt_value
*fields
;
132 bool dbg_info_full_path
;
136 /* Legacy input format format */
137 enum legacy_input_format
{
138 LEGACY_INPUT_FORMAT_NONE
= 0,
139 LEGACY_INPUT_FORMAT_CTF
,
140 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
143 /* Legacy output format format */
144 enum legacy_output_format
{
145 LEGACY_OUTPUT_FORMAT_NONE
= 0,
146 LEGACY_OUTPUT_FORMAT_TEXT
,
147 LEGACY_OUTPUT_FORMAT_DUMMY
,
151 * Prints the "out of memory" error.
154 void print_err_oom(void)
156 printf_err("Out of memory\n");
160 * Appends an "expecting token" error to the INI-style parsing state's
164 void ini_append_error_expecting(struct ini_parsing_state
*state
,
165 GScanner
*scanner
, const char *expecting
)
170 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
172 /* Only print error if there's one line */
173 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
177 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
178 pos
= g_scanner_cur_position(scanner
) + 4;
180 if (!g_scanner_eof(scanner
)) {
184 for (i
= 0; i
< pos
; ++i
) {
185 g_string_append_printf(state
->ini_error
, " ");
188 g_string_append_printf(state
->ini_error
, "^\n\n");
192 int ini_handle_state(struct ini_parsing_state
*state
)
195 GTokenType token_type
;
196 struct bt_value
*value
= NULL
;
198 token_type
= g_scanner_get_next_token(state
->scanner
);
199 if (token_type
== G_TOKEN_EOF
) {
200 if (state
->expecting
!= INI_EXPECT_COMMA
) {
201 switch (state
->expecting
) {
202 case INI_EXPECT_EQUAL
:
203 ini_append_error_expecting(state
,
204 state
->scanner
, "'='");
206 case INI_EXPECT_VALUE
:
207 case INI_EXPECT_VALUE_NUMBER_NEG
:
208 ini_append_error_expecting(state
,
209 state
->scanner
, "value");
211 case INI_EXPECT_MAP_KEY
:
212 ini_append_error_expecting(state
,
213 state
->scanner
, "unquoted map key");
226 switch (state
->expecting
) {
227 case INI_EXPECT_MAP_KEY
:
228 if (token_type
!= G_TOKEN_IDENTIFIER
) {
229 ini_append_error_expecting(state
, state
->scanner
,
234 free(state
->last_map_key
);
235 state
->last_map_key
=
236 strdup(state
->scanner
->value
.v_identifier
);
237 if (!state
->last_map_key
) {
238 g_string_append(state
->ini_error
,
243 if (bt_value_map_has_key(state
->params
, state
->last_map_key
)) {
244 g_string_append_printf(state
->ini_error
,
245 "Duplicate parameter key: `%s`\n",
246 state
->last_map_key
);
250 state
->expecting
= INI_EXPECT_EQUAL
;
252 case INI_EXPECT_EQUAL
:
253 if (token_type
!= G_TOKEN_CHAR
) {
254 ini_append_error_expecting(state
,
255 state
->scanner
, "'='");
259 if (state
->scanner
->value
.v_char
!= '=') {
260 ini_append_error_expecting(state
,
261 state
->scanner
, "'='");
265 state
->expecting
= INI_EXPECT_VALUE
;
267 case INI_EXPECT_VALUE
:
269 switch (token_type
) {
271 if (state
->scanner
->value
.v_char
== '-') {
272 /* Negative number */
274 INI_EXPECT_VALUE_NUMBER_NEG
;
277 ini_append_error_expecting(state
,
278 state
->scanner
, "value");
284 /* Positive integer */
285 uint64_t int_val
= state
->scanner
->value
.v_int64
;
287 if (int_val
> (1ULL << 63) - 1) {
288 g_string_append_printf(state
->ini_error
,
289 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
294 value
= bt_value_integer_create_init(
299 /* Positive floating point number */
300 value
= bt_value_float_create_init(
301 state
->scanner
->value
.v_float
);
305 value
= bt_value_string_create_init(
306 state
->scanner
->value
.v_string
);
308 case G_TOKEN_IDENTIFIER
:
311 * Using symbols would be appropriate here,
312 * but said symbols are allowed as map key,
313 * so it's easier to consider everything an
316 * If one of the known symbols is not
317 * recognized here, then fall back to creating
320 const char *id
= state
->scanner
->value
.v_identifier
;
322 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
323 !strcmp(id
, "nul")) {
324 value
= bt_value_null
;
325 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
326 !strcmp(id
, "yes") ||
327 !strcmp(id
, "YES")) {
328 value
= bt_value_bool_create_init(true);
329 } else if (!strcmp(id
, "false") ||
330 !strcmp(id
, "FALSE") ||
333 value
= bt_value_bool_create_init(false);
335 value
= bt_value_string_create_init(id
);
340 /* Unset value variable will trigger the error */
345 ini_append_error_expecting(state
,
346 state
->scanner
, "value");
350 state
->expecting
= INI_EXPECT_COMMA
;
353 case INI_EXPECT_VALUE_NUMBER_NEG
:
355 switch (token_type
) {
358 /* Negative integer */
359 uint64_t int_val
= state
->scanner
->value
.v_int64
;
361 if (int_val
> (1ULL << 63) - 1) {
362 g_string_append_printf(state
->ini_error
,
363 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
368 value
= bt_value_integer_create_init(
369 -((int64_t) int_val
));
373 /* Negative floating point number */
374 value
= bt_value_float_create_init(
375 -state
->scanner
->value
.v_float
);
378 /* Unset value variable will trigger the error */
383 ini_append_error_expecting(state
,
384 state
->scanner
, "value");
388 state
->expecting
= INI_EXPECT_COMMA
;
391 case INI_EXPECT_COMMA
:
392 if (token_type
!= G_TOKEN_CHAR
) {
393 ini_append_error_expecting(state
,
394 state
->scanner
, "','");
398 if (state
->scanner
->value
.v_char
!= ',') {
399 ini_append_error_expecting(state
,
400 state
->scanner
, "','");
404 state
->expecting
= INI_EXPECT_MAP_KEY
;
416 if (bt_value_map_insert(state
->params
,
417 state
->last_map_key
, value
)) {
418 /* Only override return value on error */
429 * Converts an INI-style argument to an equivalent map value object.
431 * Return value is owned by the caller.
434 struct bt_value
*bt_value_from_ini(const char *arg
, GString
*ini_error
)
436 /* Lexical scanner configuration */
437 GScannerConfig scanner_config
= {
438 /* Skip whitespaces */
439 .cset_skip_characters
= " \t\n",
441 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
442 .cset_identifier_first
=
446 .cset_identifier_nth
=
451 /* "hello" and "Hello" two different keys */
452 .case_sensitive
= TRUE
,
455 .cpair_comment_single
= NULL
,
456 .skip_comment_multi
= TRUE
,
457 .skip_comment_single
= TRUE
,
458 .scan_comment_multi
= FALSE
,
461 * Do scan identifiers, including 1-char identifiers,
462 * but NULL is a normal identifier.
464 .scan_identifier
= TRUE
,
465 .scan_identifier_1char
= TRUE
,
466 .scan_identifier_NULL
= FALSE
,
469 * No specific symbols: null and boolean "symbols" are
470 * scanned as plain identifiers.
472 .scan_symbols
= FALSE
,
473 .symbol_2_token
= FALSE
,
474 .scope_0_fallback
= FALSE
,
477 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
478 * integers prefixed with "$".
484 .scan_hex_dollar
= FALSE
,
486 /* Convert scanned numbers to integer tokens */
487 .numbers_2_int
= TRUE
,
489 /* Support both integers and floating-point numbers */
490 .int_2_float
= FALSE
,
492 /* Scan integers as 64-bit signed integers */
495 /* Only scan double-quoted strings */
496 .scan_string_sq
= FALSE
,
497 .scan_string_dq
= TRUE
,
499 /* Do not converter identifiers to string tokens */
500 .identifier_2_string
= FALSE
,
502 /* Scan characters as G_TOKEN_CHAR token */
503 .char_2_token
= FALSE
,
505 struct ini_parsing_state state
= {
508 .expecting
= INI_EXPECT_MAP_KEY
,
510 .ini_error
= ini_error
,
513 state
.params
= bt_value_map_create();
518 state
.scanner
= g_scanner_new(&scanner_config
);
519 if (!state
.scanner
) {
523 /* Let the scan begin */
524 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
527 int ret
= ini_handle_state(&state
);
532 } else if (ret
> 0) {
541 BT_PUT(state
.params
);
545 g_scanner_destroy(state
.scanner
);
548 free(state
.last_map_key
);
553 * Returns the parameters map value object from a command-line
554 * parameter option's argument.
556 * Return value is owned by the caller.
559 struct bt_value
*bt_value_from_arg(const char *arg
)
561 struct bt_value
*params
= NULL
;
562 GString
*ini_error
= NULL
;
564 ini_error
= g_string_new(NULL
);
570 /* Try INI-style parsing */
571 params
= bt_value_from_ini(arg
, ini_error
);
573 printf_err("%s", ini_error
->str
);
579 g_string_free(ini_error
, TRUE
);
585 * Returns the plugin name, component class name, component class type,
586 * and component name from a command-line --component option's argument.
587 * arg must have the following format:
589 * [NAME:]TYPE.PLUGIN.CLS
591 * where NAME is the optional component name, TYPE is either `source`,
592 * `filter`, or `sink`, PLUGIN is the plugin name, and CLS is the
593 * component class name.
595 * On success, both *plugin and *component are not NULL. *plugin
596 * and *component are owned by the caller. On success, *name can be NULL
597 * if no component name was found, and *comp_cls_type is set.
600 void plugin_comp_cls_names(const char *arg
, char **name
, char **plugin
,
601 char **comp_cls
, enum bt_component_class_type
*comp_cls_type
)
603 const char *at
= arg
;
604 GString
*gs_name
= NULL
;
605 GString
*gs_comp_cls_type
= NULL
;
606 GString
*gs_plugin
= NULL
;
607 GString
*gs_comp_cls
= NULL
;
613 assert(comp_cls_type
);
615 if (!bt_common_string_is_printable(arg
)) {
616 printf_err("Argument contains a non-printable character\n");
620 /* Parse the component name */
621 gs_name
= bt_common_string_until(at
, ".:\\", ":", &end_pos
);
626 if (arg
[end_pos
] == ':') {
630 g_string_assign(gs_name
, "");
633 /* Parse the component class type */
634 gs_comp_cls_type
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
635 if (!gs_comp_cls_type
|| at
[end_pos
] == '\0') {
636 printf_err("Missing component class type (`source`, `filter`, or `sink`)\n");
640 if (strcmp(gs_comp_cls_type
->str
, "source") == 0 ||
641 strcmp(gs_comp_cls_type
->str
, "src") == 0) {
642 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
643 } else if (strcmp(gs_comp_cls_type
->str
, "filter") == 0 ||
644 strcmp(gs_comp_cls_type
->str
, "flt") == 0) {
645 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
646 } else if (strcmp(gs_comp_cls_type
->str
, "sink") == 0) {
647 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
649 printf_err("Unknown component class type: `%s`\n",
650 gs_comp_cls_type
->str
);
656 /* Parse the plugin name */
657 gs_plugin
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
658 if (!gs_plugin
|| gs_plugin
->len
== 0 || at
[end_pos
] == '\0') {
659 printf_err("Missing plugin name\n");
665 /* Parse the component class name */
666 gs_comp_cls
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
667 if (!gs_comp_cls
|| gs_comp_cls
->len
== 0) {
668 printf_err("Missing component class name\n");
672 if (at
[end_pos
] != '\0') {
673 /* Found a non-escaped `.` */
678 if (gs_name
->len
== 0) {
680 g_string_free(gs_name
, TRUE
);
682 *name
= gs_name
->str
;
683 g_string_free(gs_name
, FALSE
);
686 g_string_free(gs_name
, TRUE
);
689 *plugin
= gs_plugin
->str
;
690 *comp_cls
= gs_comp_cls
->str
;
691 g_string_free(gs_plugin
, FALSE
);
692 g_string_free(gs_comp_cls
, FALSE
);
708 g_string_free(gs_name
, TRUE
);
712 g_string_free(gs_plugin
, TRUE
);
716 g_string_free(gs_comp_cls
, TRUE
);
719 if (gs_comp_cls_type
) {
720 g_string_free(gs_comp_cls_type
, TRUE
);
727 * Prints the Babeltrace version.
730 void print_version(void)
732 puts("Babeltrace " VERSION
);
736 * Destroys a component configuration.
739 void bt_config_component_destroy(struct bt_object
*obj
)
741 struct bt_config_component
*bt_config_component
=
742 container_of(obj
, struct bt_config_component
, base
);
748 if (bt_config_component
->plugin_name
) {
749 g_string_free(bt_config_component
->plugin_name
, TRUE
);
752 if (bt_config_component
->comp_cls_name
) {
753 g_string_free(bt_config_component
->comp_cls_name
, TRUE
);
756 if (bt_config_component
->instance_name
) {
757 g_string_free(bt_config_component
->instance_name
, TRUE
);
760 BT_PUT(bt_config_component
->params
);
761 g_free(bt_config_component
);
768 * Creates a component configuration using the given plugin name and
769 * component name. `plugin_name` and `comp_cls_name` are copied (belong
770 * to the return value).
772 * Return value is owned by the caller.
775 struct bt_config_component
*bt_config_component_create(
776 enum bt_component_class_type type
,
777 const char *plugin_name
, const char *comp_cls_name
)
779 struct bt_config_component
*cfg_component
= NULL
;
781 cfg_component
= g_new0(struct bt_config_component
, 1);
782 if (!cfg_component
) {
787 bt_object_init(cfg_component
, bt_config_component_destroy
);
788 cfg_component
->type
= type
;
789 cfg_component
->plugin_name
= g_string_new(plugin_name
);
790 if (!cfg_component
->plugin_name
) {
795 cfg_component
->comp_cls_name
= g_string_new(comp_cls_name
);
796 if (!cfg_component
->comp_cls_name
) {
801 cfg_component
->instance_name
= g_string_new(NULL
);
802 if (!cfg_component
->instance_name
) {
807 /* Start with empty parameters */
808 cfg_component
->params
= bt_value_map_create();
809 if (!cfg_component
->params
) {
817 BT_PUT(cfg_component
);
820 return cfg_component
;
824 * Creates a component configuration from a command-line --component
828 struct bt_config_component
*bt_config_component_from_arg(const char *arg
)
830 struct bt_config_component
*cfg_comp
= NULL
;
832 char *plugin_name
= NULL
;
833 char *comp_cls_name
= NULL
;
834 enum bt_component_class_type type
;
836 plugin_comp_cls_names(arg
, &name
, &plugin_name
, &comp_cls_name
, &type
);
837 if (!plugin_name
|| !comp_cls_name
) {
841 cfg_comp
= bt_config_component_create(type
, plugin_name
, comp_cls_name
);
847 g_string_assign(cfg_comp
->instance_name
, name
);
858 g_free(comp_cls_name
);
863 * Destroys a configuration.
866 void bt_config_destroy(struct bt_object
*obj
)
868 struct bt_config
*cfg
=
869 container_of(obj
, struct bt_config
, base
);
875 BT_PUT(cfg
->plugin_paths
);
877 switch (cfg
->command
) {
878 case BT_CONFIG_COMMAND_RUN
:
879 if (cfg
->cmd_data
.run
.sources
) {
880 g_ptr_array_free(cfg
->cmd_data
.run
.sources
, TRUE
);
883 if (cfg
->cmd_data
.run
.filters
) {
884 g_ptr_array_free(cfg
->cmd_data
.run
.filters
, TRUE
);
887 if (cfg
->cmd_data
.run
.sinks
) {
888 g_ptr_array_free(cfg
->cmd_data
.run
.sinks
, TRUE
);
891 if (cfg
->cmd_data
.run
.connections
) {
892 g_ptr_array_free(cfg
->cmd_data
.run
.connections
,
896 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
898 case BT_CONFIG_COMMAND_HELP
:
899 BT_PUT(cfg
->cmd_data
.help
.cfg_component
);
901 case BT_CONFIG_COMMAND_QUERY
:
902 BT_PUT(cfg
->cmd_data
.query
.cfg_component
);
904 if (cfg
->cmd_data
.query
.object
) {
905 g_string_free(cfg
->cmd_data
.query
.object
, TRUE
);
908 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
909 if (cfg
->cmd_data
.print_ctf_metadata
.path
) {
910 g_string_free(cfg
->cmd_data
.print_ctf_metadata
.path
,
914 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
915 if (cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
917 cfg
->cmd_data
.print_lttng_live_sessions
.url
,
932 void destroy_glist_of_gstring(GList
*list
)
940 for (at
= list
; at
!= NULL
; at
= g_list_next(at
)) {
941 g_string_free(at
->data
, TRUE
);
948 * Creates a simple lexical scanner for parsing comma-delimited names
951 * Return value is owned by the caller.
954 GScanner
*create_csv_identifiers_scanner(void)
957 GScannerConfig scanner_config
= {
958 .cset_skip_characters
= " \t\n",
959 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
960 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
961 .case_sensitive
= TRUE
,
962 .cpair_comment_single
= NULL
,
963 .skip_comment_multi
= TRUE
,
964 .skip_comment_single
= TRUE
,
965 .scan_comment_multi
= FALSE
,
966 .scan_identifier
= TRUE
,
967 .scan_identifier_1char
= TRUE
,
968 .scan_identifier_NULL
= FALSE
,
969 .scan_symbols
= FALSE
,
970 .symbol_2_token
= FALSE
,
971 .scope_0_fallback
= FALSE
,
972 .scan_binary
= FALSE
,
976 .scan_hex_dollar
= FALSE
,
977 .numbers_2_int
= FALSE
,
978 .int_2_float
= FALSE
,
979 .store_int64
= FALSE
,
980 .scan_string_sq
= FALSE
,
981 .scan_string_dq
= FALSE
,
982 .identifier_2_string
= FALSE
,
983 .char_2_token
= TRUE
,
986 scanner
= g_scanner_new(&scanner_config
);
995 * Converts a comma-delimited list of known names (--names option) to
996 * an array value object containing those names as string value objects.
998 * Return value is owned by the caller.
1001 struct bt_value
*names_from_arg(const char *arg
)
1003 GScanner
*scanner
= NULL
;
1004 struct bt_value
*names
= NULL
;
1005 bool found_all
= false, found_none
= false, found_item
= false;
1007 names
= bt_value_array_create();
1013 scanner
= create_csv_identifiers_scanner();
1018 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1021 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1023 switch (token_type
) {
1024 case G_TOKEN_IDENTIFIER
:
1026 const char *identifier
= scanner
->value
.v_identifier
;
1028 if (!strcmp(identifier
, "payload") ||
1029 !strcmp(identifier
, "args") ||
1030 !strcmp(identifier
, "arg")) {
1032 if (bt_value_array_append_string(names
,
1036 } else if (!strcmp(identifier
, "context") ||
1037 !strcmp(identifier
, "ctx")) {
1039 if (bt_value_array_append_string(names
,
1043 } else if (!strcmp(identifier
, "scope") ||
1044 !strcmp(identifier
, "header")) {
1046 if (bt_value_array_append_string(names
,
1050 } else if (!strcmp(identifier
, "all")) {
1052 if (bt_value_array_append_string(names
,
1056 } else if (!strcmp(identifier
, "none")) {
1058 if (bt_value_array_append_string(names
,
1063 printf_err("Unknown name: `%s`\n",
1079 if (found_none
&& found_all
) {
1080 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1084 * Legacy behavior is to clear the defaults (show none) when at
1085 * least one item is specified.
1087 if (found_item
&& !found_none
&& !found_all
) {
1088 if (bt_value_array_append_string(names
, "none")) {
1093 g_scanner_destroy(scanner
);
1100 g_scanner_destroy(scanner
);
1106 * Converts a comma-delimited list of known fields (--fields option) to
1107 * an array value object containing those fields as string
1110 * Return value is owned by the caller.
1113 struct bt_value
*fields_from_arg(const char *arg
)
1115 GScanner
*scanner
= NULL
;
1116 struct bt_value
*fields
;
1118 fields
= bt_value_array_create();
1124 scanner
= create_csv_identifiers_scanner();
1129 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1132 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1134 switch (token_type
) {
1135 case G_TOKEN_IDENTIFIER
:
1137 const char *identifier
= scanner
->value
.v_identifier
;
1139 if (!strcmp(identifier
, "trace") ||
1140 !strcmp(identifier
, "trace:hostname") ||
1141 !strcmp(identifier
, "trace:domain") ||
1142 !strcmp(identifier
, "trace:procname") ||
1143 !strcmp(identifier
, "trace:vpid") ||
1144 !strcmp(identifier
, "loglevel") ||
1145 !strcmp(identifier
, "emf") ||
1146 !strcmp(identifier
, "callsite") ||
1147 !strcmp(identifier
, "all")) {
1148 if (bt_value_array_append_string(fields
,
1153 printf_err("Unknown field: `%s`\n",
1175 g_scanner_destroy(scanner
);
1181 void append_param_arg(GString
*params_arg
, const char *key
, const char *value
)
1187 if (params_arg
->len
!= 0) {
1188 g_string_append_c(params_arg
, ',');
1191 g_string_append(params_arg
, key
);
1192 g_string_append_c(params_arg
, '=');
1193 g_string_append(params_arg
, value
);
1197 * Inserts the equivalent "prefix-NAME=yes" strings into params_arg
1198 * where the names are in names_array.
1201 int insert_flat_params_from_array(GString
*params_arg
,
1202 struct bt_value
*names_array
, const char *prefix
)
1206 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1207 bool default_set
= false, non_default_set
= false;
1210 * names_array may be NULL if no CLI options were specified to
1211 * trigger its creation.
1217 tmpstr
= g_string_new(NULL
);
1224 default_value
= g_string_new(NULL
);
1225 if (!default_value
) {
1231 for (i
= 0; i
< bt_value_array_size(names_array
); i
++) {
1232 struct bt_value
*str_obj
= bt_value_array_get(names_array
, i
);
1234 bool is_default
= false;
1237 printf_err("Unexpected error\n");
1242 ret
= bt_value_string_get(str_obj
, &suffix
);
1245 printf_err("Unexpected error\n");
1249 g_string_assign(tmpstr
, prefix
);
1250 g_string_append(tmpstr
, "-");
1252 /* Special-case for "all" and "none". */
1253 if (!strcmp(suffix
, "all")) {
1255 g_string_assign(default_value
, "show");
1256 } else if (!strcmp(suffix
, "none")) {
1258 g_string_assign(default_value
, "hide");
1262 g_string_append(tmpstr
, "default");
1263 append_param_arg(params_arg
, tmpstr
->str
,
1264 default_value
->str
);
1266 non_default_set
= true;
1267 g_string_append(tmpstr
, suffix
);
1268 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1272 /* Implicit field-default=hide if any non-default option is set. */
1273 if (non_default_set
&& !default_set
) {
1274 g_string_assign(tmpstr
, prefix
);
1275 g_string_append(tmpstr
, "-default");
1276 g_string_assign(default_value
, "hide");
1277 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1281 if (default_value
) {
1282 g_string_free(default_value
, TRUE
);
1286 g_string_free(tmpstr
, TRUE
);
1299 OPT_CLOCK_FORCE_CORRELATE
,
1302 OPT_CLOCK_OFFSET_NS
,
1309 OPT_DEBUG_INFO_FULL_PATH
,
1310 OPT_DEBUG_INFO_TARGET_PREFIX
,
1321 OPT_OMIT_HOME_PLUGIN_PATH
,
1322 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1328 OPT_RESET_BASE_PARAMS
,
1332 OPT_STREAM_INTERSECTION
,
1339 enum bt_config_component_dest
{
1340 BT_CONFIG_COMPONENT_DEST_UNKNOWN
= -1,
1341 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1342 BT_CONFIG_COMPONENT_DEST_FILTER
,
1343 BT_CONFIG_COMPONENT_DEST_SINK
,
1347 * Adds a configuration component to the appropriate configuration
1348 * array depending on the destination.
1351 void add_run_cfg_comp(struct bt_config
*cfg
,
1352 struct bt_config_component
*cfg_comp
,
1353 enum bt_config_component_dest dest
)
1358 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1359 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1361 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1362 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1364 case BT_CONFIG_COMPONENT_DEST_SINK
:
1365 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1373 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1374 struct bt_config_component
*cfg_comp
,
1375 enum bt_config_component_dest dest
,
1376 struct bt_value
*instance_names
)
1380 if (cfg_comp
->instance_name
->len
== 0) {
1381 printf_err("Found an unnamed component\n");
1386 if (bt_value_map_has_key(instance_names
, cfg_comp
->instance_name
->str
)) {
1387 printf_err("Duplicate component instance name:\n %s\n",
1388 cfg_comp
->instance_name
->str
);
1393 if (bt_value_map_insert(instance_names
,
1394 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1400 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1407 int append_env_var_plugin_paths(struct bt_value
*plugin_paths
)
1412 if (bt_common_is_setuid_setgid()) {
1413 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1417 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1422 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1426 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1433 int append_home_and_system_plugin_paths(struct bt_value
*plugin_paths
,
1434 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1438 if (!omit_home_plugin_path
) {
1439 if (bt_common_is_setuid_setgid()) {
1440 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1442 char *home_plugin_dir
=
1443 bt_common_get_home_plugin_path();
1445 if (home_plugin_dir
) {
1446 ret
= bt_config_append_plugin_paths(
1447 plugin_paths
, home_plugin_dir
);
1448 free(home_plugin_dir
);
1451 printf_err("Invalid home plugin path\n");
1458 if (!omit_system_plugin_path
) {
1459 if (bt_config_append_plugin_paths(plugin_paths
,
1460 bt_common_get_system_plugin_path())) {
1461 printf_err("Invalid system plugin path\n");
1467 printf_err("Cannot append home and system plugin paths\n");
1472 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1474 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1475 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1479 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1480 struct bt_value
*initial_plugin_paths
, bool needs_plugins
)
1482 struct bt_config
*cfg
;
1485 cfg
= g_new0(struct bt_config
, 1);
1491 bt_object_init(cfg
, bt_config_destroy
);
1492 cfg
->command
= command
;
1493 cfg
->command_needs_plugins
= needs_plugins
;
1495 if (initial_plugin_paths
) {
1496 cfg
->plugin_paths
= bt_get(initial_plugin_paths
);
1498 cfg
->plugin_paths
= bt_value_array_create();
1499 if (!cfg
->plugin_paths
) {
1515 struct bt_config
*bt_config_run_create(
1516 struct bt_value
*initial_plugin_paths
)
1518 struct bt_config
*cfg
;
1521 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1522 initial_plugin_paths
, true);
1527 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1528 (GDestroyNotify
) bt_put
);
1529 if (!cfg
->cmd_data
.run
.sources
) {
1534 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1535 (GDestroyNotify
) bt_put
);
1536 if (!cfg
->cmd_data
.run
.filters
) {
1541 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1542 (GDestroyNotify
) bt_put
);
1543 if (!cfg
->cmd_data
.run
.sinks
) {
1548 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1549 (GDestroyNotify
) bt_config_connection_destroy
);
1550 if (!cfg
->cmd_data
.run
.connections
) {
1565 struct bt_config
*bt_config_list_plugins_create(
1566 struct bt_value
*initial_plugin_paths
)
1568 struct bt_config
*cfg
;
1571 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1572 initial_plugin_paths
, true);
1587 struct bt_config
*bt_config_help_create(
1588 struct bt_value
*initial_plugin_paths
)
1590 struct bt_config
*cfg
;
1593 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1594 initial_plugin_paths
, true);
1599 cfg
->cmd_data
.help
.cfg_component
=
1600 bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN
,
1602 if (!cfg
->cmd_data
.help
.cfg_component
) {
1616 struct bt_config
*bt_config_query_create(
1617 struct bt_value
*initial_plugin_paths
)
1619 struct bt_config
*cfg
;
1622 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1623 initial_plugin_paths
, true);
1628 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1629 if (!cfg
->cmd_data
.query
.object
) {
1644 struct bt_config
*bt_config_print_ctf_metadata_create(
1645 struct bt_value
*initial_plugin_paths
)
1647 struct bt_config
*cfg
;
1650 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1651 initial_plugin_paths
, true);
1656 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1657 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1672 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1673 struct bt_value
*initial_plugin_paths
)
1675 struct bt_config
*cfg
;
1678 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1679 initial_plugin_paths
, true);
1684 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1685 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1700 int bt_config_append_plugin_paths_check_setuid_setgid(
1701 struct bt_value
*plugin_paths
, const char *arg
)
1705 if (bt_common_is_setuid_setgid()) {
1706 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1710 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1711 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1722 * Prints the expected format for a --params option.
1725 void print_expected_params_format(FILE *fp
)
1727 fprintf(fp
, "Expected format of PARAMS\n");
1728 fprintf(fp
, "-------------------------\n");
1730 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1732 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1733 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1734 fprintf(fp
, "and VALUE can be one of:\n");
1736 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1737 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1738 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1739 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1740 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1741 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1742 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1743 fprintf(fp
, " the null and boolean value symbols above.\n");
1744 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1746 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1748 fprintf(fp
, "Example:\n");
1750 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1751 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1752 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1754 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1755 fprintf(fp
, "babeltrace from a shell.\n");
1760 * Prints the help command usage.
1763 void print_help_usage(FILE *fp
)
1765 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1766 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] --component=TYPE.PLUGIN.CLS\n");
1768 fprintf(fp
, "Options:\n");
1770 fprintf(fp
, " -c, --component=TYPE.PLUGIN.CLS Get help for the component class CLS of\n");
1771 fprintf(fp
, " type TYPE (`source`, `filter`, or `sink`)\n");
1772 fprintf(fp
, " found in the plugin PLUGIN\n");
1773 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1774 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1775 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1776 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1777 fprintf(fp
, " dynamic plugins can be loaded\n");
1778 fprintf(fp
, " -h, --help Show this help and quit\n");
1780 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1782 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1786 struct poptOption help_long_options
[] = {
1787 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1788 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
1789 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1790 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1791 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1792 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1793 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1797 * Creates a Babeltrace config object from the arguments of a help
1800 * *retcode is set to the appropriate exit code to use.
1803 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1804 int *retcode
, bool force_omit_system_plugin_path
,
1805 bool force_omit_home_plugin_path
,
1806 struct bt_value
*initial_plugin_paths
)
1808 poptContext pc
= NULL
;
1812 struct bt_config
*cfg
= NULL
;
1813 const char *leftover
;
1814 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1815 char *plug_comp_cls_names
= NULL
;
1818 cfg
= bt_config_help_create(initial_plugin_paths
);
1823 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1824 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1825 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1831 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1832 help_long_options
, 0);
1834 printf_err("Cannot get popt context\n");
1838 poptReadDefaultConfig(pc
, 0);
1840 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1841 arg
= poptGetOptArg(pc
);
1844 case OPT_PLUGIN_PATH
:
1845 if (bt_config_append_plugin_paths_check_setuid_setgid(
1846 cfg
->plugin_paths
, arg
)) {
1850 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1851 cfg
->omit_system_plugin_path
= true;
1853 case OPT_OMIT_HOME_PLUGIN_PATH
:
1854 cfg
->omit_home_plugin_path
= true;
1857 if (plug_comp_cls_names
) {
1858 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
1863 plug_comp_cls_names
= strdup(arg
);
1864 if (!plug_comp_cls_names
) {
1870 print_help_usage(stdout
);
1875 printf_err("Unknown command-line option specified (option code %d)\n",
1884 /* Check for option parsing error */
1886 printf_err("While parsing command-line options, at option %s: %s\n",
1887 poptBadOption(pc
, 0), poptStrerror(opt
));
1891 leftover
= poptGetArg(pc
);
1893 if (plug_comp_cls_names
) {
1894 printf_err("Cannot specify plugin name and --component component class:\n %s\n",
1899 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1902 if (!plug_comp_cls_names
) {
1903 print_help_usage(stdout
);
1909 plugin_comp_cls_names(plug_comp_cls_names
, NULL
,
1910 &plugin_name
, &comp_cls_name
,
1911 &cfg
->cmd_data
.help
.cfg_component
->type
);
1912 if (plugin_name
&& comp_cls_name
) {
1913 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1915 g_string_assign(cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1918 printf_err("Invalid --component option's argument:\n %s\n",
1919 plug_comp_cls_names
);
1924 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1935 free(plug_comp_cls_names
);
1936 g_free(plugin_name
);
1937 g_free(comp_cls_name
);
1940 poptFreeContext(pc
);
1948 * Prints the help command usage.
1951 void print_query_usage(FILE *fp
)
1953 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] OBJECT --component=TYPE.PLUGIN.CLS\n");
1955 fprintf(fp
, "Options:\n");
1957 fprintf(fp
, " -c, --component=TYPE.PLUGIN.CLS Query the component class CLS of type TYPE\n");
1958 fprintf(fp
, " (`source`, `filter`, or `sink`) found in\n");
1959 fprintf(fp
, " the plugin PLUGIN\n");
1960 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1961 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1962 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1963 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1964 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1965 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1966 fprintf(fp
, " dynamic plugins can be loaded\n");
1967 fprintf(fp
, " -h, --help Show this help and quit\n");
1968 fprintf(fp
, "\n\n");
1969 print_expected_params_format(fp
);
1973 struct poptOption query_long_options
[] = {
1974 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1975 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
1976 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1977 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1978 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1979 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1980 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1981 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1985 * Creates a Babeltrace config object from the arguments of a query
1988 * *retcode is set to the appropriate exit code to use.
1991 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1992 int *retcode
, bool force_omit_system_plugin_path
,
1993 bool force_omit_home_plugin_path
,
1994 struct bt_value
*initial_plugin_paths
)
1996 poptContext pc
= NULL
;
2000 struct bt_config
*cfg
= NULL
;
2001 const char *leftover
;
2002 struct bt_value
*params
= bt_value_null
;
2005 cfg
= bt_config_query_create(initial_plugin_paths
);
2010 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2011 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2012 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2018 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2019 query_long_options
, 0);
2021 printf_err("Cannot get popt context\n");
2025 poptReadDefaultConfig(pc
, 0);
2027 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2028 arg
= poptGetOptArg(pc
);
2031 case OPT_PLUGIN_PATH
:
2032 if (bt_config_append_plugin_paths_check_setuid_setgid(
2033 cfg
->plugin_paths
, arg
)) {
2037 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2038 cfg
->omit_system_plugin_path
= true;
2040 case OPT_OMIT_HOME_PLUGIN_PATH
:
2041 cfg
->omit_home_plugin_path
= true;
2044 if (cfg
->cmd_data
.query
.cfg_component
) {
2045 printf_err("Cannot specify more than one plugin and component class:\n %s\n",
2050 cfg
->cmd_data
.query
.cfg_component
=
2051 bt_config_component_from_arg(arg
);
2052 if (!cfg
->cmd_data
.query
.cfg_component
) {
2053 printf_err("Invalid format for --component option's argument:\n %s\n",
2058 /* Default parameters: null */
2059 bt_put(cfg
->cmd_data
.query
.cfg_component
->params
);
2060 cfg
->cmd_data
.query
.cfg_component
->params
=
2065 params
= bt_value_from_arg(arg
);
2067 printf_err("Invalid format for --params option's argument:\n %s\n",
2074 print_query_usage(stdout
);
2079 printf_err("Unknown command-line option specified (option code %d)\n",
2088 if (!cfg
->cmd_data
.query
.cfg_component
) {
2089 printf_err("No target component class specified with --component option\n");
2094 BT_MOVE(cfg
->cmd_data
.query
.cfg_component
->params
, params
);
2096 /* Check for option parsing error */
2098 printf_err("While parsing command-line options, at option %s: %s\n",
2099 poptBadOption(pc
, 0), poptStrerror(opt
));
2104 * We need exactly one leftover argument which is the
2107 leftover
= poptGetArg(pc
);
2109 if (strlen(leftover
) == 0) {
2110 printf_err("Invalid empty object\n");
2114 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2116 print_query_usage(stdout
);
2122 leftover
= poptGetArg(pc
);
2124 printf_err("Unexpected argument: %s\n", leftover
);
2128 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2140 poptFreeContext(pc
);
2149 * Prints the list-plugins command usage.
2152 void print_list_plugins_usage(FILE *fp
)
2154 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2156 fprintf(fp
, "Options:\n");
2158 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2159 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2160 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2161 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2162 fprintf(fp
, " dynamic plugins can be loaded\n");
2163 fprintf(fp
, " -h, --help Show this help and quit\n");
2165 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2167 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2171 struct poptOption list_plugins_long_options
[] = {
2172 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2173 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2174 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2175 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2176 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2177 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2181 * Creates a Babeltrace config object from the arguments of a
2182 * list-plugins command.
2184 * *retcode is set to the appropriate exit code to use.
2187 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2188 int *retcode
, bool force_omit_system_plugin_path
,
2189 bool force_omit_home_plugin_path
,
2190 struct bt_value
*initial_plugin_paths
)
2192 poptContext pc
= NULL
;
2196 struct bt_config
*cfg
= NULL
;
2197 const char *leftover
;
2200 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2205 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2206 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2207 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2213 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2214 list_plugins_long_options
, 0);
2216 printf_err("Cannot get popt context\n");
2220 poptReadDefaultConfig(pc
, 0);
2222 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2223 arg
= poptGetOptArg(pc
);
2226 case OPT_PLUGIN_PATH
:
2227 if (bt_config_append_plugin_paths_check_setuid_setgid(
2228 cfg
->plugin_paths
, arg
)) {
2232 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2233 cfg
->omit_system_plugin_path
= true;
2235 case OPT_OMIT_HOME_PLUGIN_PATH
:
2236 cfg
->omit_home_plugin_path
= true;
2239 print_list_plugins_usage(stdout
);
2244 printf_err("Unknown command-line option specified (option code %d)\n",
2253 /* Check for option parsing error */
2255 printf_err("While parsing command-line options, at option %s: %s\n",
2256 poptBadOption(pc
, 0), poptStrerror(opt
));
2260 leftover
= poptGetArg(pc
);
2262 printf_err("Unexpected argument: %s\n", leftover
);
2266 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2278 poptFreeContext(pc
);
2286 * Prints the run command usage.
2289 void print_run_usage(FILE *fp
)
2291 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2293 fprintf(fp
, "Options:\n");
2295 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2296 fprintf(fp
, " for all the following components until\n");
2297 fprintf(fp
, " --reset-base-params is encountered\n");
2298 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2299 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2300 fprintf(fp
, " Instantiate the component class CLS of type\n");
2301 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2302 fprintf(fp
, " in the plugin PLUGIN, add it to the graph,\n");
2303 fprintf(fp
, " and optionally name it NAME (you can also\n");
2304 fprintf(fp
, " specify the name with --name)\n");
2305 fprintf(fp
, " -C, --connect=CONNECTION Connect two created components (see the\n");
2306 fprintf(fp
, " expected format of CONNECTION below)\n");
2307 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2308 fprintf(fp
, " parameter key to KEY (see --value)\n");
2309 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2310 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2311 fprintf(fp
, " names of the created components)\n");
2312 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2313 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2314 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2315 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2316 fprintf(fp
, " current component (see the expected format\n");
2317 fprintf(fp
, " of PARAMS below)\n");
2318 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2319 fprintf(fp
, " dynamic plugins can be loaded\n");
2320 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2321 fprintf(fp
, " empty map\n");
2322 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2323 fprintf(fp
, " the graph later, retry in DUR µs\n");
2324 fprintf(fp
, " (default: 100000)\n");
2325 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2326 fprintf(fp
, " the current component with a name given by\n");
2327 fprintf(fp
, " the last argument of the --key option and a\n");
2328 fprintf(fp
, " value set to VAL\n");
2329 fprintf(fp
, " -h, --help Show this help and quit\n");
2331 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2332 fprintf(fp
, "\n\n");
2333 fprintf(fp
, "Expected format of CONNECTION\n");
2334 fprintf(fp
, "-----------------------------\n");
2336 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2338 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2339 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2340 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2341 fprintf(fp
, "component with the --name option.\n");
2343 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2344 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2345 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2347 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2348 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2349 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2350 fprintf(fp
, "DOWNSTREAM.\n");
2352 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2353 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2354 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2356 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2357 fprintf(fp
, "can connect a filter component to a sink component.\n");
2359 fprintf(fp
, "Examples:\n");
2361 fprintf(fp
, " my-src:my-sink\n");
2362 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2364 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2365 fprintf(fp
, "babeltrace from a shell.\n");
2366 fprintf(fp
, "\n\n");
2367 print_expected_params_format(fp
);
2371 * Creates a Babeltrace config object from the arguments of a run
2374 * *retcode is set to the appropriate exit code to use.
2377 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2378 int *retcode
, bool force_omit_system_plugin_path
,
2379 bool force_omit_home_plugin_path
,
2380 struct bt_value
*initial_plugin_paths
)
2382 poptContext pc
= NULL
;
2384 struct bt_config_component
*cur_cfg_comp
= NULL
;
2385 enum bt_config_component_dest cur_cfg_comp_dest
=
2386 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
2387 struct bt_value
*cur_base_params
= NULL
;
2389 struct bt_config
*cfg
= NULL
;
2390 struct bt_value
*instance_names
= NULL
;
2391 struct bt_value
*connection_args
= NULL
;
2392 GString
*cur_param_key
= NULL
;
2393 char error_buf
[256] = { 0 };
2394 long long retry_duration
= -1;
2395 struct poptOption run_long_options
[] = {
2396 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2397 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2398 { "connect", 'C', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2399 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2400 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2401 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2402 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2403 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2404 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2405 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2406 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2407 { "retry-duration", '\0', POPT_ARG_LONGLONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2408 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2409 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2413 cur_param_key
= g_string_new(NULL
);
2414 if (!cur_param_key
) {
2420 print_run_usage(stdout
);
2425 cfg
= bt_config_run_create(initial_plugin_paths
);
2430 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2431 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2432 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2433 cur_base_params
= bt_value_map_create();
2434 if (!cur_base_params
) {
2439 instance_names
= bt_value_map_create();
2440 if (!instance_names
) {
2445 connection_args
= bt_value_array_create();
2446 if (!connection_args
) {
2451 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2457 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2458 run_long_options
, 0);
2460 printf_err("Cannot get popt context\n");
2464 poptReadDefaultConfig(pc
, 0);
2466 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2467 arg
= poptGetOptArg(pc
);
2470 case OPT_PLUGIN_PATH
:
2471 if (bt_config_append_plugin_paths_check_setuid_setgid(
2472 cfg
->plugin_paths
, arg
)) {
2476 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2477 cfg
->omit_system_plugin_path
= true;
2479 case OPT_OMIT_HOME_PLUGIN_PATH
:
2480 cfg
->omit_home_plugin_path
= true;
2484 enum bt_config_component_dest new_dest
;
2487 ret
= add_run_cfg_comp_check_name(cfg
,
2488 cur_cfg_comp
, cur_cfg_comp_dest
,
2490 BT_PUT(cur_cfg_comp
);
2496 cur_cfg_comp
= bt_config_component_from_arg(arg
);
2497 if (!cur_cfg_comp
) {
2498 printf_err("Invalid format for --component option's argument:\n %s\n",
2503 switch (cur_cfg_comp
->type
) {
2504 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
2505 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2507 case BT_COMPONENT_CLASS_TYPE_FILTER
:
2508 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2510 case BT_COMPONENT_CLASS_TYPE_SINK
:
2511 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2517 assert(cur_base_params
);
2518 bt_put(cur_cfg_comp
->params
);
2519 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
2520 if (!cur_cfg_comp
->params
) {
2525 cur_cfg_comp_dest
= new_dest
;
2530 struct bt_value
*params
;
2531 struct bt_value
*params_to_set
;
2533 if (!cur_cfg_comp
) {
2534 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2539 params
= bt_value_from_arg(arg
);
2541 printf_err("Invalid format for --params option's argument:\n %s\n",
2546 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
2549 if (!params_to_set
) {
2550 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2555 BT_MOVE(cur_cfg_comp
->params
, params_to_set
);
2559 if (strlen(arg
) == 0) {
2560 printf_err("Cannot set an empty string as the current parameter key\n");
2564 g_string_assign(cur_param_key
, arg
);
2567 if (!cur_cfg_comp
) {
2568 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2573 if (cur_param_key
->len
== 0) {
2574 printf_err("--value option specified without preceding --key option:\n %s\n",
2579 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2580 cur_param_key
->str
, arg
)) {
2586 if (!cur_cfg_comp
) {
2587 printf_err("Cannot set the name of unavailable component:\n %s\n",
2592 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2594 case OPT_BASE_PARAMS
:
2596 struct bt_value
*params
= bt_value_from_arg(arg
);
2599 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2604 BT_MOVE(cur_base_params
, params
);
2607 case OPT_RESET_BASE_PARAMS
:
2608 BT_PUT(cur_base_params
);
2609 cur_base_params
= bt_value_map_create();
2610 if (!cur_base_params
) {
2616 if (bt_value_array_append_string(connection_args
,
2622 case OPT_RETRY_DURATION
:
2623 if (retry_duration
< 0) {
2624 printf_err("--retry-duration option's argument must be positive or 0: %lld\n",
2629 cfg
->cmd_data
.run
.retry_duration_us
=
2630 (uint64_t) retry_duration
;
2633 print_run_usage(stdout
);
2638 printf_err("Unknown command-line option specified (option code %d)\n",
2647 /* Check for option parsing error */
2649 printf_err("While parsing command-line options, at option %s: %s\n",
2650 poptBadOption(pc
, 0), poptStrerror(opt
));
2654 /* This command does not accept leftover arguments */
2655 if (poptPeekArg(pc
)) {
2656 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2660 /* Add current component */
2662 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2663 cur_cfg_comp_dest
, instance_names
);
2664 BT_PUT(cur_cfg_comp
);
2670 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2671 printf_err("Incomplete graph: no source component\n");
2675 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2676 printf_err("Incomplete graph: no sink component\n");
2680 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2684 ret
= bt_config_cli_args_create_connections(cfg
, connection_args
,
2687 printf_err("Cannot creation connections:\n%s", error_buf
);
2699 poptFreeContext(pc
);
2702 if (cur_param_key
) {
2703 g_string_free(cur_param_key
, TRUE
);
2707 BT_PUT(cur_cfg_comp
);
2708 BT_PUT(cur_base_params
);
2709 BT_PUT(instance_names
);
2710 BT_PUT(connection_args
);
2715 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2716 int *retcode
, bool force_omit_system_plugin_path
,
2717 bool force_omit_home_plugin_path
,
2718 struct bt_value
*initial_plugin_paths
)
2720 struct bt_config
*cfg
= NULL
;
2723 const size_t argc
= bt_value_array_size(run_args
) + 1;
2725 argv
= calloc(argc
, sizeof(*argv
));
2733 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
2735 struct bt_value
*arg_value
= bt_value_array_get(run_args
, i
);
2739 ret
= bt_value_string_get(arg_value
, &arg
);
2746 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2747 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2748 initial_plugin_paths
);
2756 * Prints the convert command usage.
2759 void print_convert_usage(FILE *fp
)
2761 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2763 fprintf(fp
, "Options:\n");
2765 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2766 fprintf(fp
, " Instantiate the component class CLS of type\n");
2767 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2768 fprintf(fp
, " in the plugin PLUGIN, add it to the\n");
2769 fprintf(fp
, " conversion graph, and optionally name it\n");
2770 fprintf(fp
, " NAME (you can also specify the name with\n");
2771 fprintf(fp
, " --name)\n");
2772 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2773 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2774 fprintf(fp
, " names of the created components)\n");
2775 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2776 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2777 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2778 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2779 fprintf(fp
, " current component (see the expected format\n");
2780 fprintf(fp
, " of PARAMS below)\n");
2781 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2782 fprintf(fp
, " current component to PATH\n");
2783 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2784 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2785 fprintf(fp
, " the graph later, retry in DUR µs\n");
2786 fprintf(fp
, " (default: 100000)\n");
2787 fprintf(fp
, " dynamic plugins can be loaded\n");
2788 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2789 fprintf(fp
, " `run` command to the standard output,\n");
2790 fprintf(fp
, " formatted for a shell, and quit\n");
2791 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2792 fprintf(fp
, " `run` command to the standard output,\n");
2793 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2794 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2795 fprintf(fp
, " current component to URL\n");
2796 fprintf(fp
, " -h, --help Show this help and quit\n");
2798 fprintf(fp
, "Implicit `source.ctf.fs` component options:\n");
2800 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2801 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2802 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2803 fprintf(fp
, " are active\n");
2805 fprintf(fp
, "Implicit `sink.text.pretty` component options:\n");
2807 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2808 fprintf(fp
, " --clock-date Print timestamp dates\n");
2809 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2810 fprintf(fp
, " time zone instead of the local time zone\n");
2811 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2812 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2813 fprintf(fp
, " --color=(never | auto | always)\n");
2814 fprintf(fp
, " Never, automatically, or always emit\n");
2815 fprintf(fp
, " console color codes\n");
2816 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2817 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2818 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2819 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2820 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2821 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2822 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2823 fprintf(fp
, " (or `ctx`)\n");
2824 fprintf(fp
, " --no-delta Do not print time delta between\n");
2825 fprintf(fp
, " consecutive events\n");
2826 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2827 fprintf(fp
, " the standard output\n");
2829 fprintf(fp
, "Implicit `filter.utils.muxer` component options:\n");
2831 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2832 fprintf(fp
, " correlated across traces\n");
2834 fprintf(fp
, "Implicit `filter.utils.trimmer` component options:\n");
2836 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2837 fprintf(fp
, " time range to BEGIN (see the format of\n");
2838 fprintf(fp
, " BEGIN below)\n");
2839 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2840 fprintf(fp
, " range to END (see the format of END below)\n");
2841 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2842 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2843 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2845 fprintf(fp
, "Implicit `filter.lttng-utils.debug-info` component options:\n");
2847 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2848 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2849 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2850 fprintf(fp
, " binary paths instead of just names\n");
2851 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2852 fprintf(fp
, " Use directory DIR as a prefix when\n");
2853 fprintf(fp
, " looking up executables during debug\n");
2854 fprintf(fp
, " info analysis\n");
2855 fprintf(fp
, " --no-debug-info Do not create an implicit\n");
2856 fprintf(fp
, " `lttng-utils.debug-info` filter component\n");
2858 fprintf(fp
, "Legacy options that still work:\n");
2860 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2861 fprintf(fp
, " `ctf`:\n");
2862 fprintf(fp
, " Create an implicit `source.ctf.fs`\n");
2863 fprintf(fp
, " component\n");
2864 fprintf(fp
, " `lttng-live`:\n");
2865 fprintf(fp
, " Create an implicit `source.ctf.lttng-live`\n");
2866 fprintf(fp
, " component\n");
2867 fprintf(fp
, " -o, --output-format=(text | ctf | dummy | ctf-metadata)\n");
2868 fprintf(fp
, " `text`:\n");
2869 fprintf(fp
, " Create an implicit `sink.text.pretty`\n");
2870 fprintf(fp
, " component\n");
2871 fprintf(fp
, " `ctf`:\n");
2872 fprintf(fp
, " Create an implicit `sink.ctf.fs`\n");
2873 fprintf(fp
, " component\n");
2874 fprintf(fp
, " `dummy`:\n");
2875 fprintf(fp
, " Create an implicit `sink.utils.dummy`\n");
2876 fprintf(fp
, " component\n");
2877 fprintf(fp
, " `ctf-metadata`:\n");
2878 fprintf(fp
, " Query the `source.ctf.fs` component class\n");
2879 fprintf(fp
, " for metadata text and quit\n");
2881 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2882 fprintf(fp
, "\n\n");
2883 fprintf(fp
, "Format of BEGIN and END\n");
2884 fprintf(fp
, "-----------------------\n");
2886 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2887 fprintf(fp
, "\n\n");
2888 print_expected_params_format(fp
);
2892 struct poptOption convert_long_options
[] = {
2893 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2894 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2895 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2896 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2897 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2898 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2899 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2900 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2901 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2902 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2903 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2904 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2905 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2906 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2907 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2908 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2909 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2910 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2911 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2912 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2913 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2914 { "no-debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DEBUG_INFO
, NULL
, NULL
},
2915 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2916 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2917 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2918 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2919 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2920 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2921 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2922 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2923 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2924 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2925 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2926 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2927 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2928 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2929 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2930 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2934 GString
*get_component_auto_name(const char *prefix
,
2935 struct bt_value
*existing_names
)
2938 GString
*auto_name
= g_string_new(NULL
);
2945 if (!bt_value_map_has_key(existing_names
, prefix
)) {
2946 g_string_assign(auto_name
, prefix
);
2951 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2953 } while (bt_value_map_has_key(existing_names
, auto_name
->str
));
2959 struct implicit_component_args
{
2963 GString
*params_arg
;
2964 struct bt_value
*extra_params
;
2968 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
2969 const char *prefix
, struct bt_value
*existing_names
,
2970 GList
**comp_names
, bool append_to_comp_names
)
2973 GString
*name
= NULL
;
2975 if (!args
->exists
) {
2979 name
= get_component_auto_name(prefix
, existing_names
);
2986 g_string_assign(args
->name_arg
, name
->str
);
2988 if (bt_value_map_insert(existing_names
, name
->str
,
2995 if (append_to_comp_names
) {
2996 *comp_names
= g_list_append(*comp_names
, name
);
3002 g_string_free(name
, TRUE
);
3009 int append_run_args_for_implicit_component(
3010 struct implicit_component_args
*impl_args
,
3011 struct bt_value
*run_args
)
3016 if (!impl_args
->exists
) {
3020 if (bt_value_array_append_string(run_args
, "--component")) {
3025 if (bt_value_array_append_string(run_args
, impl_args
->comp_arg
->str
)) {
3030 if (bt_value_array_append_string(run_args
, "--name")) {
3035 if (bt_value_array_append_string(run_args
, impl_args
->name_arg
->str
)) {
3040 if (impl_args
->params_arg
->len
> 0) {
3041 if (bt_value_array_append_string(run_args
, "--params")) {
3046 if (bt_value_array_append_string(run_args
,
3047 impl_args
->params_arg
->str
)) {
3053 for (i
= 0; i
< bt_value_array_size(impl_args
->extra_params
); i
++) {
3054 struct bt_value
*elem
;
3057 elem
= bt_value_array_get(impl_args
->extra_params
, i
);
3062 assert(bt_value_is_string(elem
));
3063 if (bt_value_string_get(elem
, &arg
)) {
3067 ret
= bt_value_array_append_string(run_args
, arg
);
3085 void finalize_implicit_component_args(struct implicit_component_args
*args
)
3089 if (args
->comp_arg
) {
3090 g_string_free(args
->comp_arg
, TRUE
);
3093 if (args
->name_arg
) {
3094 g_string_free(args
->name_arg
, TRUE
);
3097 if (args
->params_arg
) {
3098 g_string_free(args
->params_arg
, TRUE
);
3101 bt_put(args
->extra_params
);
3105 void destroy_implicit_component_args(void *args
)
3111 finalize_implicit_component_args(args
);
3116 int init_implicit_component_args(struct implicit_component_args
*args
,
3117 const char *comp_arg
, bool exists
)
3121 args
->exists
= exists
;
3122 args
->comp_arg
= g_string_new(comp_arg
);
3123 args
->name_arg
= g_string_new(NULL
);
3124 args
->params_arg
= g_string_new(NULL
);
3125 args
->extra_params
= bt_value_array_create();
3127 if (!args
->comp_arg
|| !args
->name_arg
||
3128 !args
->params_arg
|| !args
->extra_params
) {
3130 finalize_implicit_component_args(args
);
3140 void append_implicit_component_param(struct implicit_component_args
*args
,
3141 const char *key
, const char *value
)
3146 append_param_arg(args
->params_arg
, key
, value
);
3150 int append_implicit_component_extra_param(struct implicit_component_args
*args
,
3151 const char *key
, const char *value
)
3159 if (bt_value_array_append_string(args
->extra_params
, "--key")) {
3165 if (bt_value_array_append_string(args
->extra_params
, key
)) {
3171 if (bt_value_array_append_string(args
->extra_params
, "--value")) {
3177 if (bt_value_array_append_string(args
->extra_params
, value
)) {
3188 int convert_append_name_param(enum bt_config_component_dest dest
,
3189 GString
*cur_name
, GString
*cur_name_prefix
,
3190 struct bt_value
*run_args
, struct bt_value
*all_names
,
3191 GList
**source_names
, GList
**filter_names
,
3196 if (cur_name_prefix
->len
> 0) {
3197 /* We're after a --component option */
3198 GString
*name
= NULL
;
3199 bool append_name_opt
= false;
3201 if (cur_name
->len
== 0) {
3203 * No explicit name was provided for the user
3206 name
= get_component_auto_name(cur_name_prefix
->str
,
3208 append_name_opt
= true;
3211 * An explicit name was provided for the user
3214 if (bt_value_map_has_key(all_names
,
3216 printf_err("Duplicate component instance name:\n %s\n",
3221 name
= g_string_new(cur_name
->str
);
3230 * Remember this name globally, for the uniqueness of
3231 * all component names.
3233 if (bt_value_map_insert(all_names
, name
->str
, bt_value_null
)) {
3239 * Append the --name option if necessary.
3241 if (append_name_opt
) {
3242 if (bt_value_array_append_string(run_args
, "--name")) {
3247 if (bt_value_array_append_string(run_args
, name
->str
)) {
3254 * Remember this name specifically for the type of the
3255 * component. This is to create connection arguments.
3258 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3259 *source_names
= g_list_append(*source_names
, name
);
3261 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3262 *filter_names
= g_list_append(*filter_names
, name
);
3264 case BT_CONFIG_COMPONENT_DEST_SINK
:
3265 *sink_names
= g_list_append(*sink_names
, name
);
3271 g_string_assign(cur_name_prefix
, "");
3284 * Escapes `.`, `:`, and `\` of `input` with `\`.
3287 GString
*escape_dot_colon(const char *input
)
3289 GString
*output
= g_string_new(NULL
);
3297 for (ch
= input
; *ch
!= '\0'; ch
++) {
3298 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3299 g_string_append_c(output
, '\\');
3302 g_string_append_c(output
, *ch
);
3310 * Appends a --connect option to a list of arguments. `upstream_name`
3311 * and `downstream_name` are escaped with escape_dot_colon() in this
3315 int append_connect_arg(struct bt_value
*run_args
,
3316 const char *upstream_name
, const char *downstream_name
)
3319 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3320 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3321 GString
*arg
= g_string_new(NULL
);
3323 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3329 ret
= bt_value_array_append_string(run_args
, "--connect");
3336 g_string_append(arg
, e_upstream_name
->str
);
3337 g_string_append_c(arg
, ':');
3338 g_string_append(arg
, e_downstream_name
->str
);
3339 ret
= bt_value_array_append_string(run_args
, arg
->str
);
3348 g_string_free(arg
, TRUE
);
3351 if (e_upstream_name
) {
3352 g_string_free(e_upstream_name
, TRUE
);
3355 if (e_downstream_name
) {
3356 g_string_free(e_downstream_name
, TRUE
);
3363 * Appends the run command's --connect options for the convert command.
3366 int convert_auto_connect(struct bt_value
*run_args
,
3367 GList
*source_names
, GList
*filter_names
,
3371 GList
*source_at
= source_names
;
3372 GList
*filter_at
= filter_names
;
3374 GList
*sink_at
= sink_names
;
3376 assert(source_names
);
3377 assert(filter_names
);
3380 /* Connect all sources to the first filter */
3381 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3382 GString
*source_name
= source_at
->data
;
3383 GString
*filter_name
= filter_at
->data
;
3385 ret
= append_connect_arg(run_args
, source_name
->str
,
3392 filter_prev
= filter_at
;
3393 filter_at
= g_list_next(filter_at
);
3395 /* Connect remaining filters */
3396 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3397 GString
*filter_name
= filter_at
->data
;
3398 GString
*filter_prev_name
= filter_prev
->data
;
3400 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3407 /* Connect last filter to all sinks */
3408 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3409 GString
*filter_name
= filter_prev
->data
;
3410 GString
*sink_name
= sink_at
->data
;
3412 ret
= append_connect_arg(run_args
, filter_name
->str
,
3429 int split_timerange(const char *arg
, char **begin
, char **end
)
3432 const char *ch
= arg
;
3434 GString
*g_begin
= NULL
;
3435 GString
*g_end
= NULL
;
3443 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3444 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3450 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3451 if (!g_end
|| g_end
->len
== 0) {
3457 *begin
= g_begin
->str
;
3459 g_string_free(g_begin
, FALSE
);
3460 g_string_free(g_end
, FALSE
);
3470 g_string_free(g_begin
, TRUE
);
3474 g_string_free(g_end
, TRUE
);
3481 int g_list_prepend_gstring(GList
**list
, const char *string
)
3484 GString
*gs
= g_string_new(string
);
3493 *list
= g_list_prepend(*list
, gs
);
3500 struct implicit_component_args
*create_implicit_component_args(void)
3502 struct implicit_component_args
*impl_args
=
3503 g_new0(struct implicit_component_args
, 1);
3509 if (init_implicit_component_args(impl_args
, NULL
, true)) {
3510 destroy_implicit_component_args(impl_args
);
3520 int fill_implicit_ctf_inputs_args(GPtrArray
*implicit_ctf_inputs_args
,
3521 struct implicit_component_args
*base_implicit_ctf_input_args
,
3527 for (leftover
= leftovers
; leftover
!= NULL
;
3528 leftover
= g_list_next(leftover
)) {
3529 GString
*gs_leftover
= leftover
->data
;
3530 struct implicit_component_args
*impl_args
=
3531 create_implicit_component_args();
3538 impl_args
->exists
= true;
3539 g_string_assign(impl_args
->comp_arg
,
3540 base_implicit_ctf_input_args
->comp_arg
->str
);
3541 g_string_assign(impl_args
->params_arg
,
3542 base_implicit_ctf_input_args
->params_arg
->str
);
3545 * We need our own copy of the extra parameters because
3546 * this is where the unique path goes.
3548 BT_PUT(impl_args
->extra_params
);
3549 impl_args
->extra_params
=
3550 bt_value_copy(base_implicit_ctf_input_args
->extra_params
);
3553 destroy_implicit_component_args(impl_args
);
3557 /* Append unique path parameter */
3558 ret
= append_implicit_component_extra_param(impl_args
,
3559 "path", gs_leftover
->str
);
3561 destroy_implicit_component_args(impl_args
);
3565 g_ptr_array_add(implicit_ctf_inputs_args
, impl_args
);
3578 * Creates a Babeltrace config object from the arguments of a convert
3581 * *retcode is set to the appropriate exit code to use.
3584 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3585 int *retcode
, bool force_omit_system_plugin_path
,
3586 bool force_omit_home_plugin_path
, bool force_no_debug_info
,
3587 struct bt_value
*initial_plugin_paths
, char *log_level
)
3589 poptContext pc
= NULL
;
3591 enum bt_config_component_dest cur_comp_dest
=
3592 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3594 struct bt_config
*cfg
= NULL
;
3595 bool got_input_format_opt
= false;
3596 bool got_output_format_opt
= false;
3597 bool trimmer_has_begin
= false;
3598 bool trimmer_has_end
= false;
3599 GString
*cur_name
= NULL
;
3600 GString
*cur_name_prefix
= NULL
;
3601 const char *leftover
= NULL
;
3602 bool print_run_args
= false;
3603 bool print_run_args_0
= false;
3604 bool print_ctf_metadata
= false;
3605 struct bt_value
*run_args
= NULL
;
3606 struct bt_value
*all_names
= NULL
;
3607 GList
*source_names
= NULL
;
3608 GList
*filter_names
= NULL
;
3609 GList
*sink_names
= NULL
;
3610 GList
*leftovers
= NULL
;
3611 GPtrArray
*implicit_ctf_inputs_args
= NULL
;
3612 struct implicit_component_args base_implicit_ctf_input_args
= { 0 };
3613 struct implicit_component_args implicit_ctf_output_args
= { 0 };
3614 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3615 struct implicit_component_args implicit_dummy_args
= { 0 };
3616 struct implicit_component_args implicit_text_args
= { 0 };
3617 struct implicit_component_args implicit_debug_info_args
= { 0 };
3618 struct implicit_component_args implicit_muxer_args
= { 0 };
3619 struct implicit_component_args implicit_trimmer_args
= { 0 };
3620 struct bt_value
*plugin_paths
= bt_get(initial_plugin_paths
);
3621 char error_buf
[256] = { 0 };
3623 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3624 char *output
= NULL
;
3629 print_convert_usage(stdout
);
3634 if (init_implicit_component_args(&base_implicit_ctf_input_args
,
3635 "source.ctf.fs", false)) {
3639 if (init_implicit_component_args(&implicit_ctf_output_args
,
3640 "sink.ctf.fs", false)) {
3644 if (init_implicit_component_args(&implicit_lttng_live_args
,
3645 "source.ctf.lttng-live", false)) {
3649 if (init_implicit_component_args(&implicit_text_args
,
3650 "sink.text.pretty", false)) {
3654 if (init_implicit_component_args(&implicit_dummy_args
,
3655 "sink.utils.dummy", false)) {
3659 if (init_implicit_component_args(&implicit_debug_info_args
,
3660 "filter.lttng-utils.debug-info", !force_no_debug_info
)) {
3664 if (init_implicit_component_args(&implicit_muxer_args
,
3665 "filter.utils.muxer", true)) {
3669 if (init_implicit_component_args(&implicit_trimmer_args
,
3670 "filter.utils.trimmer", false)) {
3674 implicit_ctf_inputs_args
= g_ptr_array_new_with_free_func(
3675 (GDestroyNotify
) destroy_implicit_component_args
);
3676 if (!implicit_ctf_inputs_args
) {
3681 all_names
= bt_value_map_create();
3687 run_args
= bt_value_array_create();
3693 cur_name
= g_string_new(NULL
);
3699 cur_name_prefix
= g_string_new(NULL
);
3700 if (!cur_name_prefix
) {
3705 ret
= append_env_var_plugin_paths(plugin_paths
);
3711 * First pass: collect all arguments which need to be passed
3712 * as is to the run command. This pass can also add --name
3713 * arguments if needed to automatically name unnamed component
3714 * instances. Also it does the following transformations:
3716 * --path=PATH -> --key path --value PATH
3717 * --url=URL -> --key url --value URL
3719 * Also it appends the plugin paths of --plugin-path to
3722 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3723 convert_long_options
, 0);
3725 printf_err("Cannot get popt context\n");
3729 poptReadDefaultConfig(pc
, 0);
3731 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3733 char *plugin_name
= NULL
;
3734 char *comp_cls_name
= NULL
;
3736 arg
= poptGetOptArg(pc
);
3741 enum bt_component_class_type type
;
3742 const char *type_prefix
;
3744 /* Append current component's name if needed */
3745 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3746 cur_name_prefix
, run_args
, all_names
,
3747 &source_names
, &filter_names
, &sink_names
);
3752 /* Parse the argument */
3753 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3754 &comp_cls_name
, &type
);
3755 if (!plugin_name
|| !comp_cls_name
) {
3756 printf_err("Invalid format for --component option's argument:\n %s\n",
3762 g_string_assign(cur_name
, name
);
3764 g_string_assign(cur_name
, "");
3768 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3769 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3770 type_prefix
= "source";
3772 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3773 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
3774 type_prefix
= "filter";
3776 case BT_COMPONENT_CLASS_TYPE_SINK
:
3777 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3778 type_prefix
= "sink";
3784 if (bt_value_array_append_string(run_args
,
3790 if (bt_value_array_append_string(run_args
, arg
)) {
3795 g_string_assign(cur_name_prefix
, "");
3796 g_string_append_printf(cur_name_prefix
, "%s.%s.%s",
3797 type_prefix
, plugin_name
, comp_cls_name
);
3800 free(comp_cls_name
);
3803 comp_cls_name
= NULL
;
3807 if (cur_name_prefix
->len
== 0) {
3808 printf_err("No current component of which to set parameters:\n %s\n",
3813 if (bt_value_array_append_string(run_args
,
3819 if (bt_value_array_append_string(run_args
, arg
)) {
3825 if (cur_name_prefix
->len
== 0) {
3826 printf_err("No current component of which to set `path` parameter:\n %s\n",
3831 if (bt_value_array_append_string(run_args
, "--key")) {
3836 if (bt_value_array_append_string(run_args
, "path")) {
3841 if (bt_value_array_append_string(run_args
, "--value")) {
3846 if (bt_value_array_append_string(run_args
, arg
)) {
3852 if (cur_name_prefix
->len
== 0) {
3853 printf_err("No current component of which to set `url` parameter:\n %s\n",
3858 if (bt_value_array_append_string(run_args
, "--key")) {
3863 if (bt_value_array_append_string(run_args
, "url")) {
3868 if (bt_value_array_append_string(run_args
, "--value")) {
3873 if (bt_value_array_append_string(run_args
, arg
)) {
3879 if (cur_name_prefix
->len
== 0) {
3880 printf_err("No current component to name:\n %s\n",
3885 if (bt_value_array_append_string(run_args
, "--name")) {
3890 if (bt_value_array_append_string(run_args
, arg
)) {
3895 g_string_assign(cur_name
, arg
);
3897 case OPT_OMIT_HOME_PLUGIN_PATH
:
3898 force_omit_home_plugin_path
= true;
3900 if (bt_value_array_append_string(run_args
,
3901 "--omit-home-plugin-path")) {
3906 case OPT_RETRY_DURATION
:
3907 if (bt_value_array_append_string(run_args
,
3908 "--retry-duration")) {
3913 if (bt_value_array_append_string(run_args
, arg
)) {
3918 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3919 force_omit_system_plugin_path
= true;
3921 if (bt_value_array_append_string(run_args
,
3922 "--omit-system-plugin-path")) {
3927 case OPT_PLUGIN_PATH
:
3928 if (bt_config_append_plugin_paths_check_setuid_setgid(
3929 plugin_paths
, arg
)) {
3933 if (bt_value_array_append_string(run_args
,
3939 if (bt_value_array_append_string(run_args
, arg
)) {
3945 print_convert_usage(stdout
);
3950 case OPT_CLOCK_CYCLES
:
3951 case OPT_CLOCK_DATE
:
3952 case OPT_CLOCK_FORCE_CORRELATE
:
3954 case OPT_CLOCK_OFFSET
:
3955 case OPT_CLOCK_OFFSET_NS
:
3956 case OPT_CLOCK_SECONDS
:
3959 case OPT_DEBUG_INFO_DIR
:
3960 case OPT_DEBUG_INFO_FULL_PATH
:
3961 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3964 case OPT_INPUT_FORMAT
:
3966 case OPT_NO_DEBUG_INFO
:
3968 case OPT_OUTPUT_FORMAT
:
3971 case OPT_RUN_ARGS_0
:
3972 case OPT_STREAM_INTERSECTION
:
3975 /* Ignore in this pass */
3978 printf_err("Unknown command-line option specified (option code %d)\n",
3987 /* Append current component's name if needed */
3988 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3989 cur_name_prefix
, run_args
, all_names
, &source_names
,
3990 &filter_names
, &sink_names
);
3995 /* Check for option parsing error */
3997 printf_err("While parsing command-line options, at option %s: %s\n",
3998 poptBadOption(pc
, 0), poptStrerror(opt
));
4002 poptFreeContext(pc
);
4007 * Second pass: transform the convert-specific options and
4008 * arguments into implicit component instances for the run
4011 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
4012 convert_long_options
, 0);
4014 printf_err("Cannot get popt context\n");
4018 poptReadDefaultConfig(pc
, 0);
4020 while ((opt
= poptGetNextOpt(pc
)) > 0) {
4021 arg
= poptGetOptArg(pc
);
4025 if (trimmer_has_begin
) {
4026 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4031 trimmer_has_begin
= true;
4032 ret
= append_implicit_component_extra_param(
4033 &implicit_trimmer_args
, "begin", arg
);
4034 implicit_trimmer_args
.exists
= true;
4040 if (trimmer_has_end
) {
4041 printf("At --end option: --end or --timerange option already specified\n %s\n",
4046 trimmer_has_end
= true;
4047 ret
= append_implicit_component_extra_param(
4048 &implicit_trimmer_args
, "end", arg
);
4049 implicit_trimmer_args
.exists
= true;
4059 if (trimmer_has_begin
|| trimmer_has_end
) {
4060 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4065 ret
= split_timerange(arg
, &begin
, &end
);
4067 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4072 ret
= append_implicit_component_extra_param(
4073 &implicit_trimmer_args
, "begin", begin
);
4074 ret
|= append_implicit_component_extra_param(
4075 &implicit_trimmer_args
, "end", end
);
4076 implicit_trimmer_args
.exists
= true;
4084 case OPT_CLOCK_CYCLES
:
4085 append_implicit_component_param(
4086 &implicit_text_args
, "clock-cycles", "yes");
4087 implicit_text_args
.exists
= true;
4089 case OPT_CLOCK_DATE
:
4090 append_implicit_component_param(
4091 &implicit_text_args
, "clock-date", "yes");
4092 implicit_text_args
.exists
= true;
4094 case OPT_CLOCK_FORCE_CORRELATE
:
4095 append_implicit_component_param(
4096 &implicit_muxer_args
,
4097 "assume-absolute-clock-classes", "yes");
4100 append_implicit_component_param(
4101 &implicit_text_args
, "clock-gmt", "yes");
4102 append_implicit_component_param(
4103 &implicit_trimmer_args
, "clock-gmt", "yes");
4104 implicit_text_args
.exists
= true;
4106 case OPT_CLOCK_OFFSET
:
4107 base_implicit_ctf_input_args
.exists
= true;
4108 append_implicit_component_param(
4109 &implicit_muxer_args
,
4110 "clock-class-offset-s", arg
);
4115 case OPT_CLOCK_OFFSET_NS
:
4116 base_implicit_ctf_input_args
.exists
= true;
4117 ret
= append_implicit_component_extra_param(
4118 &base_implicit_ctf_input_args
,
4119 "clock-class-offset-ns", arg
);
4124 case OPT_CLOCK_SECONDS
:
4125 append_implicit_component_param(
4126 &implicit_text_args
, "clock-seconds", "yes");
4127 implicit_text_args
.exists
= true;
4130 implicit_text_args
.exists
= true;
4131 ret
= append_implicit_component_extra_param(
4132 &implicit_text_args
, "color", arg
);
4137 case OPT_NO_DEBUG_INFO
:
4138 implicit_debug_info_args
.exists
= false;
4140 case OPT_DEBUG_INFO_DIR
:
4141 implicit_debug_info_args
.exists
= true;
4142 ret
= append_implicit_component_extra_param(
4143 &implicit_debug_info_args
, "dir", arg
);
4148 case OPT_DEBUG_INFO_FULL_PATH
:
4149 implicit_debug_info_args
.exists
= true;
4150 append_implicit_component_param(
4151 &implicit_debug_info_args
, "full-path", "yes");
4153 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4154 implicit_debug_info_args
.exists
= true;
4155 ret
= append_implicit_component_extra_param(
4156 &implicit_debug_info_args
,
4157 "target-prefix", arg
);
4164 struct bt_value
*fields
= fields_from_arg(arg
);
4170 implicit_text_args
.exists
= true;
4171 ret
= insert_flat_params_from_array(
4172 implicit_text_args
.params_arg
,
4182 struct bt_value
*names
= names_from_arg(arg
);
4188 implicit_text_args
.exists
= true;
4189 ret
= insert_flat_params_from_array(
4190 implicit_text_args
.params_arg
,
4199 append_implicit_component_param(
4200 &implicit_text_args
, "no-delta", "yes");
4201 implicit_text_args
.exists
= true;
4203 case OPT_INPUT_FORMAT
:
4204 if (got_input_format_opt
) {
4205 printf_err("Duplicate --input-format option\n");
4209 got_input_format_opt
= true;
4211 if (strcmp(arg
, "ctf") == 0) {
4212 base_implicit_ctf_input_args
.exists
= true;
4213 } else if (strcmp(arg
, "lttng-live") == 0) {
4214 implicit_lttng_live_args
.exists
= true;
4216 printf_err("Unknown legacy input format:\n %s\n",
4221 case OPT_OUTPUT_FORMAT
:
4222 if (got_output_format_opt
) {
4223 printf_err("Duplicate --output-format option\n");
4227 got_output_format_opt
= true;
4229 if (strcmp(arg
, "text") == 0) {
4230 implicit_text_args
.exists
= true;
4231 } else if (strcmp(arg
, "ctf") == 0) {
4232 implicit_ctf_output_args
.exists
= true;
4233 } else if (strcmp(arg
, "dummy") == 0) {
4234 implicit_dummy_args
.exists
= true;
4235 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4236 print_ctf_metadata
= true;
4238 printf_err("Unknown legacy output format:\n %s\n",
4245 printf_err("Duplicate --output option\n");
4249 output
= strdup(arg
);
4256 if (print_run_args_0
) {
4257 printf_err("Cannot specify --run-args and --run-args-0\n");
4261 print_run_args
= true;
4263 case OPT_RUN_ARGS_0
:
4264 if (print_run_args
) {
4265 printf_err("Cannot specify --run-args and --run-args-0\n");
4269 print_run_args_0
= true;
4271 case OPT_STREAM_INTERSECTION
:
4272 append_implicit_component_param(
4273 &base_implicit_ctf_input_args
,
4274 "stream-intersection", "yes");
4275 base_implicit_ctf_input_args
.exists
= true;
4278 if (*log_level
!= 'V' && *log_level
!= 'D') {
4291 /* Check for option parsing error */
4293 printf_err("While parsing command-line options, at option %s: %s\n",
4294 poptBadOption(pc
, 0), poptStrerror(opt
));
4299 * Legacy behaviour: --verbose used to make the `text` output
4300 * format print more information. --verbose is now equivalent to
4301 * the INFO log level, which is why we compare to 'I' here.
4303 if (*log_level
== 'I') {
4304 append_implicit_component_param(&implicit_text_args
,
4309 * Append home and system plugin paths now that we possibly got
4312 if (append_home_and_system_plugin_paths(plugin_paths
,
4313 force_omit_system_plugin_path
,
4314 force_omit_home_plugin_path
)) {
4318 /* Consume and keep leftover arguments */
4319 while ((leftover
= poptGetArg(pc
))) {
4320 GString
*gs_leftover
= g_string_new(leftover
);
4327 leftovers
= g_list_append(leftovers
, gs_leftover
);
4329 g_string_free(gs_leftover
, TRUE
);
4335 /* Print CTF metadata or print LTTng live sessions */
4336 if (print_ctf_metadata
) {
4337 GString
*gs_leftover
;
4339 if (g_list_length(leftovers
) == 0) {
4340 printf_err("--output-format=ctf-metadata specified without a path\n");
4344 if (g_list_length(leftovers
) > 1) {
4345 printf_err("Too many paths specified for --output-format=ctf-metadata\n");
4349 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4354 gs_leftover
= leftovers
->data
;
4355 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4361 * If -o ctf was specified, make sure an output path (--output)
4362 * was also specified. --output does not imply -o ctf because
4363 * it's also used for the default, implicit -o text if -o ctf
4366 if (implicit_ctf_output_args
.exists
) {
4368 printf_err("--output-format=ctf specified without --output (trace output path)\n");
4373 * At this point we know that -o ctf AND --output were
4374 * specified. Make sure that no options were specified
4375 * which would imply -o text because --output would be
4376 * ambiguous in this case. For example, this is wrong:
4378 * babeltrace --names=all -o ctf --output=/tmp/path my-trace
4380 * because --names=all implies -o text, and --output
4381 * could apply to both the sink.text.pretty and
4382 * sink.ctf.fs implicit components.
4384 if (implicit_text_args
.exists
) {
4385 printf_err("Ambiguous --output option: --output-format=ctf specified but another option implies --output-format=text\n");
4391 * If -o dummy and -o ctf were not specified, and if there are
4392 * no explicit sink components, then use an implicit
4393 * `sink.text.pretty` component.
4395 if (!implicit_dummy_args
.exists
&& !implicit_ctf_output_args
.exists
&&
4397 implicit_text_args
.exists
= true;
4401 * Set implicit `sink.text.pretty` or `sink.ctf.fs` component's
4402 * `path` parameter if --output was specified.
4405 if (implicit_text_args
.exists
) {
4406 append_implicit_component_extra_param(&implicit_text_args
,
4408 } else if (implicit_ctf_output_args
.exists
) {
4409 append_implicit_component_extra_param(&implicit_ctf_output_args
,
4414 /* Decide where the leftover argument(s) go */
4415 if (g_list_length(leftovers
) > 0) {
4416 if (implicit_lttng_live_args
.exists
) {
4417 GString
*gs_leftover
;
4419 if (g_list_length(leftovers
) > 1) {
4420 printf_err("Too many URLs specified for --output-format=lttng-live\n");
4424 gs_leftover
= leftovers
->data
;
4425 lttng_live_url_parts
=
4426 bt_common_parse_lttng_live_url(gs_leftover
->str
,
4427 error_buf
, sizeof(error_buf
));
4428 if (!lttng_live_url_parts
.proto
) {
4429 printf_err("Invalid LTTng live URL format: %s\n",
4434 if (!lttng_live_url_parts
.session_name
) {
4435 /* Print LTTng live sessions */
4436 cfg
= bt_config_print_lttng_live_sessions_create(
4442 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4447 ret
= append_implicit_component_extra_param(
4448 &implicit_lttng_live_args
, "url",
4455 * Append one implicit component argument set
4456 * for each leftover (souce.ctf.fs paths). Copy
4457 * the base implicit component arguments.
4458 * Note that they still have to be named later.
4460 ret
= fill_implicit_ctf_inputs_args(
4461 implicit_ctf_inputs_args
,
4462 &base_implicit_ctf_input_args
, leftovers
);
4470 * Ensure mutual exclusion between implicit `source.ctf.fs` and
4471 * `source.ctf.lttng-live` components.
4473 if (base_implicit_ctf_input_args
.exists
&&
4474 implicit_lttng_live_args
.exists
) {
4475 printf_err("Cannot create both implicit `%s` and `%s` components\n",
4476 base_implicit_ctf_input_args
.comp_arg
->str
,
4477 implicit_lttng_live_args
.comp_arg
->str
);
4482 * If the implicit `source.ctf.fs` or `source.ctf.lttng-live`
4483 * components exists, make sure there's at least one leftover
4484 * (which is the path or URL).
4486 if (base_implicit_ctf_input_args
.exists
&&
4487 g_list_length(leftovers
) == 0) {
4488 printf_err("Missing path for implicit `%s` component\n",
4489 base_implicit_ctf_input_args
.comp_arg
->str
);
4493 if (implicit_lttng_live_args
.exists
&& g_list_length(leftovers
) == 0) {
4494 printf_err("Missing URL for implicit `%s` component\n",
4495 implicit_lttng_live_args
.comp_arg
->str
);
4499 /* Assign names to implicit components */
4500 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4501 struct implicit_component_args
*impl_args
=
4502 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4504 ret
= assign_name_to_implicit_component(impl_args
,
4505 "source-ctf-fs", all_names
, &source_names
, true);
4511 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4512 "lttng-live", all_names
, &source_names
, true);
4517 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4518 "pretty", all_names
, &sink_names
, true);
4523 ret
= assign_name_to_implicit_component(&implicit_ctf_output_args
,
4524 "sink-ctf-fs", all_names
, &sink_names
, true);
4529 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4530 "dummy", all_names
, &sink_names
, true);
4535 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4536 "muxer", all_names
, NULL
, false);
4541 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4542 "trimmer", all_names
, NULL
, false);
4547 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4548 "debug-info", all_names
, NULL
, false);
4553 /* Make sure there's at least one source and one sink */
4554 if (!source_names
) {
4555 printf_err("No source component\n");
4560 printf_err("No sink component\n");
4565 * Prepend the muxer, the trimmer, and the debug info to the
4566 * filter chain so that we have:
4568 * sources -> muxer -> [trimmer] -> [debug info] ->
4569 * [user filters] -> sinks
4571 if (implicit_debug_info_args
.exists
) {
4572 if (g_list_prepend_gstring(&filter_names
,
4573 implicit_debug_info_args
.name_arg
->str
)) {
4578 if (implicit_trimmer_args
.exists
) {
4579 if (g_list_prepend_gstring(&filter_names
,
4580 implicit_trimmer_args
.name_arg
->str
)) {
4585 if (g_list_prepend_gstring(&filter_names
,
4586 implicit_muxer_args
.name_arg
->str
)) {
4591 * Append the equivalent run arguments for the implicit
4594 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4595 struct implicit_component_args
*impl_args
=
4596 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4598 ret
= append_run_args_for_implicit_component(impl_args
,
4605 ret
= append_run_args_for_implicit_component(&implicit_lttng_live_args
,
4611 ret
= append_run_args_for_implicit_component(&implicit_text_args
,
4617 ret
= append_run_args_for_implicit_component(&implicit_ctf_output_args
,
4623 ret
= append_run_args_for_implicit_component(&implicit_dummy_args
,
4629 ret
= append_run_args_for_implicit_component(&implicit_muxer_args
,
4635 ret
= append_run_args_for_implicit_component(&implicit_trimmer_args
,
4641 ret
= append_run_args_for_implicit_component(&implicit_debug_info_args
,
4647 /* Auto-connect components */
4648 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4651 printf_err("Cannot auto-connect components\n");
4656 * We have all the run command arguments now. Depending on
4657 * --run-args, we pass this to the run command or print them
4660 if (print_run_args
|| print_run_args_0
) {
4661 for (i
= 0; i
< bt_value_array_size(run_args
); i
++) {
4662 struct bt_value
*arg_value
=
4663 bt_value_array_get(run_args
, i
);
4665 GString
*quoted
= NULL
;
4666 const char *arg_to_print
;
4669 ret
= bt_value_string_get(arg_value
, &arg
);
4673 if (print_run_args
) {
4674 quoted
= bt_common_shell_quote(arg
, true);
4679 arg_to_print
= quoted
->str
;
4684 printf("%s", arg_to_print
);
4687 g_string_free(quoted
, TRUE
);
4690 if (i
< bt_value_array_size(run_args
) - 1) {
4691 if (print_run_args
) {
4704 cfg
= bt_config_run_from_args_array(run_args
, retcode
,
4705 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
4706 initial_plugin_paths
);
4719 poptFreeContext(pc
);
4726 g_string_free(cur_name
, TRUE
);
4729 if (cur_name_prefix
) {
4730 g_string_free(cur_name_prefix
, TRUE
);
4733 if (implicit_ctf_inputs_args
) {
4734 g_ptr_array_free(implicit_ctf_inputs_args
, TRUE
);
4739 destroy_glist_of_gstring(source_names
);
4740 destroy_glist_of_gstring(filter_names
);
4741 destroy_glist_of_gstring(sink_names
);
4742 destroy_glist_of_gstring(leftovers
);
4743 finalize_implicit_component_args(&base_implicit_ctf_input_args
);
4744 finalize_implicit_component_args(&implicit_ctf_output_args
);
4745 finalize_implicit_component_args(&implicit_lttng_live_args
);
4746 finalize_implicit_component_args(&implicit_dummy_args
);
4747 finalize_implicit_component_args(&implicit_text_args
);
4748 finalize_implicit_component_args(&implicit_debug_info_args
);
4749 finalize_implicit_component_args(&implicit_muxer_args
);
4750 finalize_implicit_component_args(&implicit_trimmer_args
);
4751 bt_put(plugin_paths
);
4752 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4757 * Prints the Babeltrace 2.x general usage.
4760 void print_gen_usage(FILE *fp
)
4762 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4764 fprintf(fp
, "General options:\n");
4766 fprintf(fp
, " -d, --debug Enable debug mode (same as --log-level=V)\n");
4767 fprintf(fp
, " -h, --help Show this help and quit\n");
4768 fprintf(fp
, " --log-level=LVL Set all log levels to LVL (`N`, `V`, `D`,\n");
4769 fprintf(fp
, " `I`, `W` (default), `E`, or `F`)\n");
4770 fprintf(fp
, " -v, --verbose Enable verbose mode (same as --log-level=I)\n");
4771 fprintf(fp
, " -V, --version Show version and quit\n");
4773 fprintf(fp
, "Available commands:\n");
4775 fprintf(fp
, " convert Convert and trim traces (default)\n");
4776 fprintf(fp
, " help Get help for a plugin or a component class\n");
4777 fprintf(fp
, " list-plugins List available plugins and their content\n");
4778 fprintf(fp
, " query Query objects from a component class\n");
4779 fprintf(fp
, " run Build a processing graph and run it\n");
4781 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4785 char log_level_from_arg(const char *arg
)
4789 if (strcmp(arg
, "VERBOSE") == 0 ||
4790 strcmp(arg
, "V") == 0) {
4792 } else if (strcmp(arg
, "DEBUG") == 0 ||
4793 strcmp(arg
, "D") == 0) {
4795 } else if (strcmp(arg
, "INFO") == 0 ||
4796 strcmp(arg
, "I") == 0) {
4798 } else if (strcmp(arg
, "WARN") == 0 ||
4799 strcmp(arg
, "WARNING") == 0 ||
4800 strcmp(arg
, "W") == 0) {
4802 } else if (strcmp(arg
, "ERROR") == 0 ||
4803 strcmp(arg
, "E") == 0) {
4805 } else if (strcmp(arg
, "FATAL") == 0 ||
4806 strcmp(arg
, "F") == 0) {
4808 } else if (strcmp(arg
, "NONE") == 0 ||
4809 strcmp(arg
, "N") == 0) {
4816 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4817 int *retcode
, bool force_omit_system_plugin_path
,
4818 bool force_omit_home_plugin_path
, bool force_no_debug_info
,
4819 struct bt_value
*initial_plugin_paths
)
4821 struct bt_config
*config
= NULL
;
4823 const char **command_argv
= NULL
;
4824 int command_argc
= -1;
4825 const char *command_name
= NULL
;
4826 char log_level
= 'U';
4829 COMMAND_TYPE_NONE
= -1,
4830 COMMAND_TYPE_RUN
= 0,
4831 COMMAND_TYPE_CONVERT
,
4832 COMMAND_TYPE_LIST_PLUGINS
,
4835 } command_type
= COMMAND_TYPE_NONE
;
4839 if (!initial_plugin_paths
) {
4840 initial_plugin_paths
= bt_value_array_create();
4841 if (!initial_plugin_paths
) {
4846 bt_get(initial_plugin_paths
);
4850 print_gen_usage(stdout
);
4854 for (i
= 1; i
< argc
; i
++) {
4855 const char *cur_arg
= argv
[i
];
4856 const char *next_arg
= i
== (argc
- 1) ? NULL
: argv
[i
+ 1];
4858 if (strcmp(cur_arg
, "-d") == 0 ||
4859 strcmp(cur_arg
, "--debug") == 0) {
4861 } else if (strcmp(cur_arg
, "-v") == 0 ||
4862 strcmp(cur_arg
, "--verbose") == 0) {
4863 if (log_level
!= 'V' && log_level
!= 'D') {
4865 * Legacy: do not override a previous
4866 * --debug because --verbose and --debug
4867 * can be specified together (in this
4868 * case we want the lowest log level to
4873 } else if (strcmp(cur_arg
, "--log-level") == 0) {
4875 printf_err("Missing log level value for --log-level option\n");
4880 log_level
= log_level_from_arg(next_arg
);
4881 if (log_level
== 'U') {
4882 printf_err("Invalid argument for --log-level option:\n %s\n",
4889 } else if (strncmp(cur_arg
, "--log-level=", 12) == 0) {
4890 const char *arg
= &cur_arg
[12];
4892 log_level
= log_level_from_arg(arg
);
4893 if (log_level
== 'U') {
4894 printf_err("Invalid argument for --log-level option:\n %s\n",
4899 } else if (strcmp(cur_arg
, "-V") == 0 ||
4900 strcmp(cur_arg
, "--version") == 0) {
4903 } else if (strcmp(cur_arg
, "-h") == 0 ||
4904 strcmp(cur_arg
, "--help") == 0) {
4905 print_gen_usage(stdout
);
4909 * First unknown argument: is it a known command
4912 command_argv
= &argv
[i
];
4913 command_argc
= argc
- i
;
4915 if (strcmp(cur_arg
, "convert") == 0) {
4916 command_type
= COMMAND_TYPE_CONVERT
;
4917 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4918 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4919 } else if (strcmp(cur_arg
, "help") == 0) {
4920 command_type
= COMMAND_TYPE_HELP
;
4921 } else if (strcmp(cur_arg
, "query") == 0) {
4922 command_type
= COMMAND_TYPE_QUERY
;
4923 } else if (strcmp(cur_arg
, "run") == 0) {
4924 command_type
= COMMAND_TYPE_RUN
;
4927 * Unknown argument, but not a known
4928 * command name: assume the default
4929 * `convert` command.
4931 command_type
= COMMAND_TYPE_CONVERT
;
4932 command_name
= "convert";
4933 command_argv
= &argv
[i
- 1];
4934 command_argc
= argc
- i
+ 1;
4940 if (command_type
== COMMAND_TYPE_NONE
) {
4942 * We only got non-help, non-version general options
4943 * like --verbose and --debug, without any other
4944 * arguments, so we can't do anything useful: print the
4947 print_gen_usage(stdout
);
4951 assert(command_argv
);
4952 assert(command_argc
>= 0);
4954 switch (command_type
) {
4955 case COMMAND_TYPE_RUN
:
4956 config
= bt_config_run_from_args(command_argc
, command_argv
,
4957 retcode
, force_omit_system_plugin_path
,
4958 force_omit_home_plugin_path
, initial_plugin_paths
);
4960 case COMMAND_TYPE_CONVERT
:
4961 config
= bt_config_convert_from_args(command_argc
, command_argv
,
4962 retcode
, force_omit_system_plugin_path
,
4963 force_omit_home_plugin_path
, force_no_debug_info
,
4964 initial_plugin_paths
, &log_level
);
4966 case COMMAND_TYPE_LIST_PLUGINS
:
4967 config
= bt_config_list_plugins_from_args(command_argc
,
4968 command_argv
, retcode
, force_omit_system_plugin_path
,
4969 force_omit_home_plugin_path
, initial_plugin_paths
);
4971 case COMMAND_TYPE_HELP
:
4972 config
= bt_config_help_from_args(command_argc
,
4973 command_argv
, retcode
, force_omit_system_plugin_path
,
4974 force_omit_home_plugin_path
, initial_plugin_paths
);
4976 case COMMAND_TYPE_QUERY
:
4977 config
= bt_config_query_from_args(command_argc
,
4978 command_argv
, retcode
, force_omit_system_plugin_path
,
4979 force_omit_home_plugin_path
, initial_plugin_paths
);
4986 if (log_level
== 'U') {
4990 config
->log_level
= log_level
;
4991 config
->command_name
= command_name
;
4995 bt_put(initial_plugin_paths
);