2 * Babeltrace trace converter - parameter parsing
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #define BT_LOG_TAG "CLI-CFG-CLI-ARGS"
31 #include <babeltrace/assert-internal.h>
35 #include <babeltrace/babeltrace.h>
36 #include <babeltrace/common-internal.h>
37 #include <babeltrace/values.h>
38 #include <babeltrace/private-values.h>
41 #include <sys/types.h>
42 #include "babeltrace-cfg.h"
43 #include "babeltrace-cfg-cli-args.h"
44 #include "babeltrace-cfg-cli-args-connect.h"
48 * Error printf() macro which prepends "Error: " the first time it's
49 * called. This gives a nicer feel than having a bunch of error prefixes
50 * (since the following lines usually describe the error and possible
51 * solutions), or the error prefix just at the end.
53 #define printf_err(fmt, args...) \
55 if (is_first_error) { \
56 fprintf(stderr, "Command line error: "); \
57 is_first_error = false; \
59 fprintf(stderr, fmt, ##args); \
62 static bool is_first_error
= true;
64 /* INI-style parsing FSM states */
65 enum ini_parsing_fsm_state
{
66 /* Expect a map key (identifier) */
69 /* Expect an equal character ('=') */
75 /* Expect a negative number value */
76 INI_EXPECT_VALUE_NUMBER_NEG
,
78 /* Expect a comma character (',') */
82 /* INI-style parsing state variables */
83 struct ini_parsing_state
{
84 /* Lexical scanner (owned by this) */
87 /* Output map value object being filled (owned by this) */
88 struct bt_private_value
*params
;
90 /* Next expected FSM state */
91 enum ini_parsing_fsm_state expecting
;
93 /* Last decoded map key (owned by this) */
96 /* Complete INI-style string to parse (not owned by this) */
99 /* Error buffer (not owned by this) */
103 /* Offset option with "is set" boolean */
109 /* Legacy "ctf"/"lttng-live" format options */
110 struct ctf_legacy_opts
{
111 struct offset_opt offset_s
;
112 struct offset_opt offset_ns
;
113 bool stream_intersection
;
116 /* Legacy "text" format options */
117 struct text_legacy_opts
{
119 * output, dbg_info_dir, dbg_info_target_prefix, names,
120 * and fields are owned by this.
123 GString
*dbg_info_dir
;
124 GString
*dbg_info_target_prefix
;
125 struct bt_value
*names
;
126 struct bt_value
*fields
;
134 bool dbg_info_full_path
;
138 /* Legacy input format format */
139 enum legacy_input_format
{
140 LEGACY_INPUT_FORMAT_NONE
= 0,
141 LEGACY_INPUT_FORMAT_CTF
,
142 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
145 /* Legacy output format format */
146 enum legacy_output_format
{
147 LEGACY_OUTPUT_FORMAT_NONE
= 0,
148 LEGACY_OUTPUT_FORMAT_TEXT
,
149 LEGACY_OUTPUT_FORMAT_DUMMY
,
153 * Prints the "out of memory" error.
156 void print_err_oom(void)
158 printf_err("Out of memory\n");
162 * Appends an "expecting token" error to the INI-style parsing state's
166 void ini_append_error_expecting(struct ini_parsing_state
*state
,
167 GScanner
*scanner
, const char *expecting
)
172 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
174 /* Only print error if there's one line */
175 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
179 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
180 pos
= g_scanner_cur_position(scanner
) + 4;
182 if (!g_scanner_eof(scanner
)) {
186 for (i
= 0; i
< pos
; ++i
) {
187 g_string_append_printf(state
->ini_error
, " ");
190 g_string_append_printf(state
->ini_error
, "^\n\n");
194 int ini_handle_state(struct ini_parsing_state
*state
)
197 GTokenType token_type
;
198 struct bt_value
*value
= NULL
;
200 token_type
= g_scanner_get_next_token(state
->scanner
);
201 if (token_type
== G_TOKEN_EOF
) {
202 if (state
->expecting
!= INI_EXPECT_COMMA
) {
203 switch (state
->expecting
) {
204 case INI_EXPECT_EQUAL
:
205 ini_append_error_expecting(state
,
206 state
->scanner
, "'='");
208 case INI_EXPECT_VALUE
:
209 case INI_EXPECT_VALUE_NUMBER_NEG
:
210 ini_append_error_expecting(state
,
211 state
->scanner
, "value");
213 case INI_EXPECT_MAP_KEY
:
214 ini_append_error_expecting(state
,
215 state
->scanner
, "unquoted map key");
228 switch (state
->expecting
) {
229 case INI_EXPECT_MAP_KEY
:
230 if (token_type
!= G_TOKEN_IDENTIFIER
) {
231 ini_append_error_expecting(state
, state
->scanner
,
236 free(state
->last_map_key
);
237 state
->last_map_key
=
238 strdup(state
->scanner
->value
.v_identifier
);
239 if (!state
->last_map_key
) {
240 g_string_append(state
->ini_error
,
245 if (bt_value_map_has_entry(
246 bt_private_value_as_value(state
->params
),
247 state
->last_map_key
)) {
248 g_string_append_printf(state
->ini_error
,
249 "Duplicate parameter key: `%s`\n",
250 state
->last_map_key
);
254 state
->expecting
= INI_EXPECT_EQUAL
;
256 case INI_EXPECT_EQUAL
:
257 if (token_type
!= G_TOKEN_CHAR
) {
258 ini_append_error_expecting(state
,
259 state
->scanner
, "'='");
263 if (state
->scanner
->value
.v_char
!= '=') {
264 ini_append_error_expecting(state
,
265 state
->scanner
, "'='");
269 state
->expecting
= INI_EXPECT_VALUE
;
271 case INI_EXPECT_VALUE
:
273 switch (token_type
) {
275 if (state
->scanner
->value
.v_char
== '-') {
276 /* Negative number */
278 INI_EXPECT_VALUE_NUMBER_NEG
;
281 ini_append_error_expecting(state
,
282 state
->scanner
, "value");
288 /* Positive integer */
289 uint64_t int_val
= state
->scanner
->value
.v_int64
;
291 if (int_val
> (1ULL << 63) - 1) {
292 g_string_append_printf(state
->ini_error
,
293 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
298 value
= bt_private_value_as_value(
299 bt_private_value_integer_create_init(
304 /* Positive floating point number */
305 value
= bt_private_value_as_value(
306 bt_private_value_real_create_init(
307 state
->scanner
->value
.v_float
));
311 value
= bt_private_value_as_value(
312 bt_private_value_string_create_init(
313 state
->scanner
->value
.v_string
));
315 case G_TOKEN_IDENTIFIER
:
318 * Using symbols would be appropriate here,
319 * but said symbols are allowed as map key,
320 * so it's easier to consider everything an
323 * If one of the known symbols is not
324 * recognized here, then fall back to creating
327 const char *id
= state
->scanner
->value
.v_identifier
;
329 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
330 !strcmp(id
, "nul")) {
331 value
= bt_value_null
;
332 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
333 !strcmp(id
, "yes") ||
334 !strcmp(id
, "YES")) {
335 value
= bt_private_value_as_value(
336 bt_private_value_bool_create_init(true));
337 } else if (!strcmp(id
, "false") ||
338 !strcmp(id
, "FALSE") ||
341 value
= bt_private_value_as_value(
342 bt_private_value_bool_create_init(false));
344 value
= bt_private_value_as_value(
345 bt_private_value_string_create_init(id
));
350 /* Unset value variable will trigger the error */
355 ini_append_error_expecting(state
,
356 state
->scanner
, "value");
360 state
->expecting
= INI_EXPECT_COMMA
;
363 case INI_EXPECT_VALUE_NUMBER_NEG
:
365 switch (token_type
) {
368 /* Negative integer */
369 uint64_t int_val
= state
->scanner
->value
.v_int64
;
371 if (int_val
> (1ULL << 63) - 1) {
372 g_string_append_printf(state
->ini_error
,
373 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
378 value
= bt_private_value_as_value(
379 bt_private_value_integer_create_init(
380 -((int64_t) int_val
)));
384 /* Negative floating point number */
385 value
= bt_private_value_as_value(
386 bt_private_value_real_create_init(
387 -state
->scanner
->value
.v_float
));
390 /* Unset value variable will trigger the error */
395 ini_append_error_expecting(state
,
396 state
->scanner
, "value");
400 state
->expecting
= INI_EXPECT_COMMA
;
403 case INI_EXPECT_COMMA
:
404 if (token_type
!= G_TOKEN_CHAR
) {
405 ini_append_error_expecting(state
,
406 state
->scanner
, "','");
410 if (state
->scanner
->value
.v_char
!= ',') {
411 ini_append_error_expecting(state
,
412 state
->scanner
, "','");
416 state
->expecting
= INI_EXPECT_MAP_KEY
;
428 if (bt_private_value_map_insert_entry(state
->params
,
429 state
->last_map_key
, value
)) {
430 /* Only override return value on error */
436 BT_OBJECT_PUT_REF_AND_RESET(value
);
441 * Converts an INI-style argument to an equivalent map value object.
443 * Return value is owned by the caller.
446 struct bt_private_value
*bt_private_value_from_ini(const char *arg
,
449 /* Lexical scanner configuration */
450 GScannerConfig scanner_config
= {
451 /* Skip whitespaces */
452 .cset_skip_characters
= " \t\n",
454 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
455 .cset_identifier_first
=
459 .cset_identifier_nth
=
464 /* "hello" and "Hello" two different keys */
465 .case_sensitive
= TRUE
,
468 .cpair_comment_single
= NULL
,
469 .skip_comment_multi
= TRUE
,
470 .skip_comment_single
= TRUE
,
471 .scan_comment_multi
= FALSE
,
474 * Do scan identifiers, including 1-char identifiers,
475 * but NULL is a normal identifier.
477 .scan_identifier
= TRUE
,
478 .scan_identifier_1char
= TRUE
,
479 .scan_identifier_NULL
= FALSE
,
482 * No specific symbols: null and boolean "symbols" are
483 * scanned as plain identifiers.
485 .scan_symbols
= FALSE
,
486 .symbol_2_token
= FALSE
,
487 .scope_0_fallback
= FALSE
,
490 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
491 * integers prefixed with "$".
497 .scan_hex_dollar
= FALSE
,
499 /* Convert scanned numbers to integer tokens */
500 .numbers_2_int
= TRUE
,
502 /* Support both integers and floating-point numbers */
503 .int_2_float
= FALSE
,
505 /* Scan integers as 64-bit signed integers */
508 /* Only scan double-quoted strings */
509 .scan_string_sq
= FALSE
,
510 .scan_string_dq
= TRUE
,
512 /* Do not converter identifiers to string tokens */
513 .identifier_2_string
= FALSE
,
515 /* Scan characters as G_TOKEN_CHAR token */
516 .char_2_token
= FALSE
,
518 struct ini_parsing_state state
= {
521 .expecting
= INI_EXPECT_MAP_KEY
,
523 .ini_error
= ini_error
,
526 state
.params
= bt_private_value_map_create();
531 state
.scanner
= g_scanner_new(&scanner_config
);
532 if (!state
.scanner
) {
536 /* Let the scan begin */
537 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
540 int ret
= ini_handle_state(&state
);
545 } else if (ret
> 0) {
554 BT_OBJECT_PUT_REF_AND_RESET(state
.params
);
558 g_scanner_destroy(state
.scanner
);
561 free(state
.last_map_key
);
566 * Returns the parameters map value object from a command-line
567 * parameter option's argument.
569 * Return value is owned by the caller.
572 struct bt_private_value
*bt_private_value_from_arg(const char *arg
)
574 struct bt_private_value
*params
= NULL
;
575 GString
*ini_error
= NULL
;
577 ini_error
= g_string_new(NULL
);
583 /* Try INI-style parsing */
584 params
= bt_private_value_from_ini(arg
, ini_error
);
586 printf_err("%s", ini_error
->str
);
592 g_string_free(ini_error
, TRUE
);
599 * Returns the plugin name, component class name, component class type,
600 * and component name from a command-line --component option's argument.
601 * arg must have the following format:
603 * [NAME:]TYPE.PLUGIN.CLS
605 * where NAME is the optional component name, TYPE is either `source`,
606 * `filter`, or `sink`, PLUGIN is the plugin name, and CLS is the
607 * component class name.
609 * On success, both *plugin and *component are not NULL. *plugin
610 * and *comp_cls are owned by the caller. On success, *name can be NULL
611 * if no component class name was found, and *comp_cls_type is set.
614 void plugin_comp_cls_names(const char *arg
, char **name
, char **plugin
,
615 char **comp_cls
, enum bt_component_class_type
*comp_cls_type
)
617 const char *at
= arg
;
618 GString
*gs_name
= NULL
;
619 GString
*gs_comp_cls_type
= NULL
;
620 GString
*gs_plugin
= NULL
;
621 GString
*gs_comp_cls
= NULL
;
627 BT_ASSERT(comp_cls_type
);
629 if (!bt_common_string_is_printable(arg
)) {
630 printf_err("Argument contains a non-printable character\n");
634 /* Parse the component name */
635 gs_name
= bt_common_string_until(at
, ".:\\", ":", &end_pos
);
640 if (arg
[end_pos
] == ':') {
644 g_string_assign(gs_name
, "");
647 /* Parse the component class type */
648 gs_comp_cls_type
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
649 if (!gs_comp_cls_type
|| at
[end_pos
] == '\0') {
650 printf_err("Missing component class type (`source`, `filter`, or `sink`)\n");
654 if (strcmp(gs_comp_cls_type
->str
, "source") == 0 ||
655 strcmp(gs_comp_cls_type
->str
, "src") == 0) {
656 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SOURCE
;
657 } else if (strcmp(gs_comp_cls_type
->str
, "filter") == 0 ||
658 strcmp(gs_comp_cls_type
->str
, "flt") == 0) {
659 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_FILTER
;
660 } else if (strcmp(gs_comp_cls_type
->str
, "sink") == 0) {
661 *comp_cls_type
= BT_COMPONENT_CLASS_TYPE_SINK
;
663 printf_err("Unknown component class type: `%s`\n",
664 gs_comp_cls_type
->str
);
670 /* Parse the plugin name */
671 gs_plugin
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
672 if (!gs_plugin
|| gs_plugin
->len
== 0 || at
[end_pos
] == '\0') {
673 printf_err("Missing plugin or component class name\n");
679 /* Parse the component class name */
680 gs_comp_cls
= bt_common_string_until(at
, ".:\\", ".", &end_pos
);
681 if (!gs_comp_cls
|| gs_comp_cls
->len
== 0) {
682 printf_err("Missing component class name\n");
686 if (at
[end_pos
] != '\0') {
687 /* Found a non-escaped `.` */
692 if (gs_name
->len
== 0) {
694 g_string_free(gs_name
, TRUE
);
696 *name
= gs_name
->str
;
697 g_string_free(gs_name
, FALSE
);
700 g_string_free(gs_name
, TRUE
);
703 *plugin
= gs_plugin
->str
;
704 *comp_cls
= gs_comp_cls
->str
;
705 g_string_free(gs_plugin
, FALSE
);
706 g_string_free(gs_comp_cls
, FALSE
);
722 g_string_free(gs_name
, TRUE
);
726 g_string_free(gs_plugin
, TRUE
);
730 g_string_free(gs_comp_cls
, TRUE
);
733 if (gs_comp_cls_type
) {
734 g_string_free(gs_comp_cls_type
, TRUE
);
741 * Prints the Babeltrace version.
744 void print_version(void)
746 if (GIT_VERSION
[0] == '\0') {
747 puts("Babeltrace " VERSION
);
749 puts("Babeltrace " VERSION
" - " GIT_VERSION
);
754 * Destroys a component configuration.
757 void bt_config_component_destroy(struct bt_object
*obj
)
759 struct bt_config_component
*bt_config_component
=
760 container_of(obj
, struct bt_config_component
, base
);
766 if (bt_config_component
->plugin_name
) {
767 g_string_free(bt_config_component
->plugin_name
, TRUE
);
770 if (bt_config_component
->comp_cls_name
) {
771 g_string_free(bt_config_component
->comp_cls_name
, TRUE
);
774 if (bt_config_component
->instance_name
) {
775 g_string_free(bt_config_component
->instance_name
, TRUE
);
778 BT_OBJECT_PUT_REF_AND_RESET(bt_config_component
->params
);
779 g_free(bt_config_component
);
786 * Creates a component configuration using the given plugin name and
787 * component name. `plugin_name` and `comp_cls_name` are copied (belong
788 * to the return value).
790 * Return value is owned by the caller.
793 struct bt_config_component
*bt_config_component_create(
794 enum bt_component_class_type type
,
795 const char *plugin_name
, const char *comp_cls_name
)
797 struct bt_config_component
*cfg_component
= NULL
;
799 cfg_component
= g_new0(struct bt_config_component
, 1);
800 if (!cfg_component
) {
805 bt_object_init_shared(&cfg_component
->base
,
806 bt_config_component_destroy
);
807 cfg_component
->type
= type
;
808 cfg_component
->plugin_name
= g_string_new(plugin_name
);
809 if (!cfg_component
->plugin_name
) {
814 cfg_component
->comp_cls_name
= g_string_new(comp_cls_name
);
815 if (!cfg_component
->comp_cls_name
) {
820 cfg_component
->instance_name
= g_string_new(NULL
);
821 if (!cfg_component
->instance_name
) {
826 /* Start with empty parameters */
827 cfg_component
->params
= bt_private_value_map_create();
828 if (!cfg_component
->params
) {
836 BT_OBJECT_PUT_REF_AND_RESET(cfg_component
);
839 return cfg_component
;
843 * Creates a component configuration from a command-line --component
847 struct bt_config_component
*bt_config_component_from_arg(const char *arg
)
849 struct bt_config_component
*cfg_comp
= NULL
;
851 char *plugin_name
= NULL
;
852 char *comp_cls_name
= NULL
;
853 enum bt_component_class_type type
;
855 plugin_comp_cls_names(arg
, &name
, &plugin_name
, &comp_cls_name
, &type
);
856 if (!plugin_name
|| !comp_cls_name
) {
860 cfg_comp
= bt_config_component_create(type
, plugin_name
, comp_cls_name
);
866 g_string_assign(cfg_comp
->instance_name
, name
);
872 BT_OBJECT_PUT_REF_AND_RESET(cfg_comp
);
877 g_free(comp_cls_name
);
882 * Destroys a configuration.
885 void bt_config_destroy(struct bt_object
*obj
)
887 struct bt_config
*cfg
=
888 container_of(obj
, struct bt_config
, base
);
894 BT_OBJECT_PUT_REF_AND_RESET(cfg
->plugin_paths
);
896 switch (cfg
->command
) {
897 case BT_CONFIG_COMMAND_RUN
:
898 if (cfg
->cmd_data
.run
.sources
) {
899 g_ptr_array_free(cfg
->cmd_data
.run
.sources
, TRUE
);
902 if (cfg
->cmd_data
.run
.filters
) {
903 g_ptr_array_free(cfg
->cmd_data
.run
.filters
, TRUE
);
906 if (cfg
->cmd_data
.run
.sinks
) {
907 g_ptr_array_free(cfg
->cmd_data
.run
.sinks
, TRUE
);
910 if (cfg
->cmd_data
.run
.connections
) {
911 g_ptr_array_free(cfg
->cmd_data
.run
.connections
,
915 case BT_CONFIG_COMMAND_LIST_PLUGINS
:
917 case BT_CONFIG_COMMAND_HELP
:
918 BT_OBJECT_PUT_REF_AND_RESET(cfg
->cmd_data
.help
.cfg_component
);
920 case BT_CONFIG_COMMAND_QUERY
:
921 BT_OBJECT_PUT_REF_AND_RESET(cfg
->cmd_data
.query
.cfg_component
);
923 if (cfg
->cmd_data
.query
.object
) {
924 g_string_free(cfg
->cmd_data
.query
.object
, TRUE
);
927 case BT_CONFIG_COMMAND_PRINT_CTF_METADATA
:
928 if (cfg
->cmd_data
.print_ctf_metadata
.path
) {
929 g_string_free(cfg
->cmd_data
.print_ctf_metadata
.path
,
932 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
936 case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
:
937 if (cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
939 cfg
->cmd_data
.print_lttng_live_sessions
.url
,
942 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
957 void destroy_glist_of_gstring(GList
*list
)
965 for (at
= list
; at
!= NULL
; at
= g_list_next(at
)) {
966 g_string_free(at
->data
, TRUE
);
973 * Creates a simple lexical scanner for parsing comma-delimited names
976 * Return value is owned by the caller.
979 GScanner
*create_csv_identifiers_scanner(void)
982 GScannerConfig scanner_config
= {
983 .cset_skip_characters
= " \t\n",
984 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
985 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
986 .case_sensitive
= TRUE
,
987 .cpair_comment_single
= NULL
,
988 .skip_comment_multi
= TRUE
,
989 .skip_comment_single
= TRUE
,
990 .scan_comment_multi
= FALSE
,
991 .scan_identifier
= TRUE
,
992 .scan_identifier_1char
= TRUE
,
993 .scan_identifier_NULL
= FALSE
,
994 .scan_symbols
= FALSE
,
995 .symbol_2_token
= FALSE
,
996 .scope_0_fallback
= FALSE
,
997 .scan_binary
= FALSE
,
1001 .scan_hex_dollar
= FALSE
,
1002 .numbers_2_int
= FALSE
,
1003 .int_2_float
= FALSE
,
1004 .store_int64
= FALSE
,
1005 .scan_string_sq
= FALSE
,
1006 .scan_string_dq
= FALSE
,
1007 .identifier_2_string
= FALSE
,
1008 .char_2_token
= TRUE
,
1011 scanner
= g_scanner_new(&scanner_config
);
1020 * Converts a comma-delimited list of known names (--names option) to
1021 * an array value object containing those names as string value objects.
1023 * Return value is owned by the caller.
1026 struct bt_private_value
*names_from_arg(const char *arg
)
1028 GScanner
*scanner
= NULL
;
1029 struct bt_private_value
*names
= NULL
;
1030 bool found_all
= false, found_none
= false, found_item
= false;
1032 names
= bt_private_value_array_create();
1038 scanner
= create_csv_identifiers_scanner();
1043 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1046 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1048 switch (token_type
) {
1049 case G_TOKEN_IDENTIFIER
:
1051 const char *identifier
= scanner
->value
.v_identifier
;
1053 if (!strcmp(identifier
, "payload") ||
1054 !strcmp(identifier
, "args") ||
1055 !strcmp(identifier
, "arg")) {
1057 if (bt_private_value_array_append_string_element(names
,
1061 } else if (!strcmp(identifier
, "context") ||
1062 !strcmp(identifier
, "ctx")) {
1064 if (bt_private_value_array_append_string_element(names
,
1068 } else if (!strcmp(identifier
, "scope") ||
1069 !strcmp(identifier
, "header")) {
1071 if (bt_private_value_array_append_string_element(names
,
1075 } else if (!strcmp(identifier
, "all")) {
1077 if (bt_private_value_array_append_string_element(names
,
1081 } else if (!strcmp(identifier
, "none")) {
1083 if (bt_private_value_array_append_string_element(names
,
1088 printf_err("Unknown name: `%s`\n",
1104 if (found_none
&& found_all
) {
1105 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1109 * Legacy behavior is to clear the defaults (show none) when at
1110 * least one item is specified.
1112 if (found_item
&& !found_none
&& !found_all
) {
1113 if (bt_private_value_array_append_string_element(names
, "none")) {
1118 g_scanner_destroy(scanner
);
1123 BT_OBJECT_PUT_REF_AND_RESET(names
);
1125 g_scanner_destroy(scanner
);
1131 * Converts a comma-delimited list of known fields (--fields option) to
1132 * an array value object containing those fields as string
1135 * Return value is owned by the caller.
1138 struct bt_private_value
*fields_from_arg(const char *arg
)
1140 GScanner
*scanner
= NULL
;
1141 struct bt_private_value
*fields
;
1143 fields
= bt_private_value_array_create();
1149 scanner
= create_csv_identifiers_scanner();
1154 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1157 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1159 switch (token_type
) {
1160 case G_TOKEN_IDENTIFIER
:
1162 const char *identifier
= scanner
->value
.v_identifier
;
1164 if (!strcmp(identifier
, "trace") ||
1165 !strcmp(identifier
, "trace:hostname") ||
1166 !strcmp(identifier
, "trace:domain") ||
1167 !strcmp(identifier
, "trace:procname") ||
1168 !strcmp(identifier
, "trace:vpid") ||
1169 !strcmp(identifier
, "loglevel") ||
1170 !strcmp(identifier
, "emf") ||
1171 !strcmp(identifier
, "callsite") ||
1172 !strcmp(identifier
, "all")) {
1173 if (bt_private_value_array_append_string_element(fields
,
1178 printf_err("Unknown field: `%s`\n",
1196 BT_OBJECT_PUT_REF_AND_RESET(fields
);
1200 g_scanner_destroy(scanner
);
1206 void append_param_arg(GString
*params_arg
, const char *key
, const char *value
)
1208 BT_ASSERT(params_arg
);
1212 if (params_arg
->len
!= 0) {
1213 g_string_append_c(params_arg
, ',');
1216 g_string_append(params_arg
, key
);
1217 g_string_append_c(params_arg
, '=');
1218 g_string_append(params_arg
, value
);
1222 * Inserts the equivalent "prefix-NAME=yes" strings into params_arg
1223 * where the names are in names_array.
1226 int insert_flat_params_from_array(GString
*params_arg
,
1227 struct bt_value
*names_array
, const char *prefix
)
1231 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1232 bool default_set
= false, non_default_set
= false;
1235 * names_array may be NULL if no CLI options were specified to
1236 * trigger its creation.
1242 tmpstr
= g_string_new(NULL
);
1249 default_value
= g_string_new(NULL
);
1250 if (!default_value
) {
1256 for (i
= 0; i
< bt_value_array_get_size(names_array
); i
++) {
1257 struct bt_value
*str_obj
=
1258 bt_value_array_borrow_element_by_index(names_array
, i
);
1260 bool is_default
= false;
1263 printf_err("Unexpected error\n");
1268 suffix
= bt_value_string_get(str_obj
);
1270 g_string_assign(tmpstr
, prefix
);
1271 g_string_append(tmpstr
, "-");
1273 /* Special-case for "all" and "none". */
1274 if (!strcmp(suffix
, "all")) {
1276 g_string_assign(default_value
, "show");
1277 } else if (!strcmp(suffix
, "none")) {
1279 g_string_assign(default_value
, "hide");
1283 g_string_append(tmpstr
, "default");
1284 append_param_arg(params_arg
, tmpstr
->str
,
1285 default_value
->str
);
1287 non_default_set
= true;
1288 g_string_append(tmpstr
, suffix
);
1289 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1293 /* Implicit field-default=hide if any non-default option is set. */
1294 if (non_default_set
&& !default_set
) {
1295 g_string_assign(tmpstr
, prefix
);
1296 g_string_append(tmpstr
, "-default");
1297 g_string_assign(default_value
, "hide");
1298 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1302 if (default_value
) {
1303 g_string_free(default_value
, TRUE
);
1307 g_string_free(tmpstr
, TRUE
);
1320 OPT_CLOCK_FORCE_CORRELATE
,
1323 OPT_CLOCK_OFFSET_NS
,
1331 OPT_DEBUG_INFO_FULL_PATH
,
1332 OPT_DEBUG_INFO_TARGET_PREFIX
,
1342 OPT_OMIT_HOME_PLUGIN_PATH
,
1343 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1349 OPT_RESET_BASE_PARAMS
,
1353 OPT_STREAM_INTERSECTION
,
1360 enum bt_config_component_dest
{
1361 BT_CONFIG_COMPONENT_DEST_UNKNOWN
= -1,
1362 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1363 BT_CONFIG_COMPONENT_DEST_FILTER
,
1364 BT_CONFIG_COMPONENT_DEST_SINK
,
1368 * Adds a configuration component to the appropriate configuration
1369 * array depending on the destination.
1372 void add_run_cfg_comp(struct bt_config
*cfg
,
1373 struct bt_config_component
*cfg_comp
,
1374 enum bt_config_component_dest dest
)
1376 bt_object_get_ref(cfg_comp
);
1379 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1380 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1382 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1383 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1385 case BT_CONFIG_COMPONENT_DEST_SINK
:
1386 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1394 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1395 struct bt_config_component
*cfg_comp
,
1396 enum bt_config_component_dest dest
,
1397 struct bt_private_value
*instance_names
)
1401 if (cfg_comp
->instance_name
->len
== 0) {
1402 printf_err("Found an unnamed component\n");
1407 if (bt_value_map_has_entry(bt_private_value_as_value(instance_names
),
1408 cfg_comp
->instance_name
->str
)) {
1409 printf_err("Duplicate component instance name:\n %s\n",
1410 cfg_comp
->instance_name
->str
);
1415 if (bt_private_value_map_insert_entry(instance_names
,
1416 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1422 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1429 int append_env_var_plugin_paths(struct bt_private_value
*plugin_paths
)
1434 if (bt_common_is_setuid_setgid()) {
1435 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1439 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1444 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1448 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1455 int append_home_and_system_plugin_paths(struct bt_private_value
*plugin_paths
,
1456 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1460 if (!omit_home_plugin_path
) {
1461 if (bt_common_is_setuid_setgid()) {
1462 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1464 char *home_plugin_dir
=
1465 bt_common_get_home_plugin_path();
1467 if (home_plugin_dir
) {
1468 ret
= bt_config_append_plugin_paths(
1469 plugin_paths
, home_plugin_dir
);
1470 free(home_plugin_dir
);
1473 printf_err("Invalid home plugin path\n");
1480 if (!omit_system_plugin_path
) {
1481 if (bt_config_append_plugin_paths(plugin_paths
,
1482 bt_common_get_system_plugin_path())) {
1483 printf_err("Invalid system plugin path\n");
1489 printf_err("Cannot append home and system plugin paths\n");
1494 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1496 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1497 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1501 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1502 struct bt_private_value
*initial_plugin_paths
,
1505 struct bt_config
*cfg
;
1508 cfg
= g_new0(struct bt_config
, 1);
1514 bt_object_init_shared(&cfg
->base
, bt_config_destroy
);
1515 cfg
->command
= command
;
1516 cfg
->command_needs_plugins
= needs_plugins
;
1518 if (initial_plugin_paths
) {
1519 cfg
->plugin_paths
= initial_plugin_paths
;
1520 bt_object_get_ref(cfg
->plugin_paths
);
1522 cfg
->plugin_paths
= bt_private_value_array_create();
1523 if (!cfg
->plugin_paths
) {
1532 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1539 struct bt_config
*bt_config_run_create(
1540 struct bt_private_value
*initial_plugin_paths
)
1542 struct bt_config
*cfg
;
1545 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1546 initial_plugin_paths
, true);
1551 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1552 (GDestroyNotify
) bt_object_put_ref
);
1553 if (!cfg
->cmd_data
.run
.sources
) {
1558 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1559 (GDestroyNotify
) bt_object_put_ref
);
1560 if (!cfg
->cmd_data
.run
.filters
) {
1565 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1566 (GDestroyNotify
) bt_object_put_ref
);
1567 if (!cfg
->cmd_data
.run
.sinks
) {
1572 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1573 (GDestroyNotify
) bt_config_connection_destroy
);
1574 if (!cfg
->cmd_data
.run
.connections
) {
1582 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1589 struct bt_config
*bt_config_list_plugins_create(
1590 struct bt_private_value
*initial_plugin_paths
)
1592 struct bt_config
*cfg
;
1595 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1596 initial_plugin_paths
, true);
1604 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1611 struct bt_config
*bt_config_help_create(
1612 struct bt_private_value
*initial_plugin_paths
)
1614 struct bt_config
*cfg
;
1617 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1618 initial_plugin_paths
, true);
1623 cfg
->cmd_data
.help
.cfg_component
=
1624 bt_config_component_create(-1, NULL
, NULL
);
1625 if (!cfg
->cmd_data
.help
.cfg_component
) {
1632 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1639 struct bt_config
*bt_config_query_create(
1640 struct bt_private_value
*initial_plugin_paths
)
1642 struct bt_config
*cfg
;
1645 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1646 initial_plugin_paths
, true);
1651 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1652 if (!cfg
->cmd_data
.query
.object
) {
1660 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1667 struct bt_config
*bt_config_print_ctf_metadata_create(
1668 struct bt_private_value
*initial_plugin_paths
)
1670 struct bt_config
*cfg
;
1673 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1674 initial_plugin_paths
, true);
1679 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1680 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1685 cfg
->cmd_data
.print_ctf_metadata
.output_path
= g_string_new(NULL
);
1686 if (!cfg
->cmd_data
.print_ctf_metadata
.output_path
) {
1694 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1701 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1702 struct bt_private_value
*initial_plugin_paths
)
1704 struct bt_config
*cfg
;
1707 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1708 initial_plugin_paths
, true);
1713 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1714 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1719 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
=
1721 if (!cfg
->cmd_data
.print_lttng_live_sessions
.output_path
) {
1729 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1736 int bt_config_append_plugin_paths_check_setuid_setgid(
1737 struct bt_private_value
*plugin_paths
, const char *arg
)
1741 if (bt_common_is_setuid_setgid()) {
1742 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1746 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1747 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1758 * Prints the expected format for a --params option.
1761 void print_expected_params_format(FILE *fp
)
1763 fprintf(fp
, "Expected format of PARAMS\n");
1764 fprintf(fp
, "-------------------------\n");
1766 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1768 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1769 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1770 fprintf(fp
, "and VALUE can be one of:\n");
1772 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1773 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1774 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1775 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1776 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1777 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1778 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1779 fprintf(fp
, " the null and boolean value symbols above.\n");
1780 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1782 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1784 fprintf(fp
, "Example:\n");
1786 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1787 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1788 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1790 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1791 fprintf(fp
, "babeltrace from a shell.\n");
1796 * Prints the help command usage.
1799 void print_help_usage(FILE *fp
)
1801 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1802 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] TYPE.PLUGIN.CLS\n");
1804 fprintf(fp
, "Options:\n");
1806 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1807 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1808 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1809 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1810 fprintf(fp
, " dynamic plugins can be loaded\n");
1811 fprintf(fp
, " -h, --help Show this help and quit\n");
1813 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1815 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1819 struct poptOption help_long_options
[] = {
1820 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1821 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1822 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1823 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1824 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1825 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1829 * Creates a Babeltrace config object from the arguments of a help
1832 * *retcode is set to the appropriate exit code to use.
1835 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1836 int *retcode
, bool force_omit_system_plugin_path
,
1837 bool force_omit_home_plugin_path
,
1838 struct bt_private_value
*initial_plugin_paths
)
1840 poptContext pc
= NULL
;
1844 struct bt_config
*cfg
= NULL
;
1845 const char *leftover
;
1846 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1849 cfg
= bt_config_help_create(initial_plugin_paths
);
1854 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1855 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1856 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1862 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1863 help_long_options
, 0);
1865 printf_err("Cannot get popt context\n");
1869 poptReadDefaultConfig(pc
, 0);
1871 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1872 arg
= poptGetOptArg(pc
);
1875 case OPT_PLUGIN_PATH
:
1876 if (bt_config_append_plugin_paths_check_setuid_setgid(
1877 cfg
->plugin_paths
, arg
)) {
1881 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1882 cfg
->omit_system_plugin_path
= true;
1884 case OPT_OMIT_HOME_PLUGIN_PATH
:
1885 cfg
->omit_home_plugin_path
= true;
1888 print_help_usage(stdout
);
1890 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1893 printf_err("Unknown command-line option specified (option code %d)\n",
1902 /* Check for option parsing error */
1904 printf_err("While parsing command-line options, at option %s: %s\n",
1905 poptBadOption(pc
, 0), poptStrerror(opt
));
1909 leftover
= poptGetArg(pc
);
1911 plugin_comp_cls_names(leftover
, NULL
,
1912 &plugin_name
, &comp_cls_name
,
1913 &cfg
->cmd_data
.help
.cfg_component
->type
);
1914 if (plugin_name
&& comp_cls_name
) {
1915 /* Component class help */
1917 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1920 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1923 /* Fall back to plugin help */
1925 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1929 print_help_usage(stdout
);
1931 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1935 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1943 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1946 g_free(plugin_name
);
1947 g_free(comp_cls_name
);
1950 poptFreeContext(pc
);
1958 * Prints the help command usage.
1961 void print_query_usage(FILE *fp
)
1963 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] TYPE.PLUGIN.CLS OBJECT\n");
1965 fprintf(fp
, "Options:\n");
1967 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1968 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1969 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1970 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1971 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1972 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1973 fprintf(fp
, " dynamic plugins can be loaded\n");
1974 fprintf(fp
, " -h, --help Show this help and quit\n");
1975 fprintf(fp
, "\n\n");
1976 print_expected_params_format(fp
);
1980 struct poptOption query_long_options
[] = {
1981 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1982 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1983 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1984 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1985 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1986 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1987 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1991 * Creates a Babeltrace config object from the arguments of a query
1994 * *retcode is set to the appropriate exit code to use.
1997 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1998 int *retcode
, bool force_omit_system_plugin_path
,
1999 bool force_omit_home_plugin_path
,
2000 struct bt_private_value
*initial_plugin_paths
)
2002 poptContext pc
= NULL
;
2006 struct bt_config
*cfg
= NULL
;
2007 const char *leftover
;
2008 struct bt_private_value
*params
= bt_private_value_null
;
2011 cfg
= bt_config_query_create(initial_plugin_paths
);
2016 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2017 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2018 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2024 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2025 query_long_options
, 0);
2027 printf_err("Cannot get popt context\n");
2031 poptReadDefaultConfig(pc
, 0);
2033 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2034 arg
= poptGetOptArg(pc
);
2037 case OPT_PLUGIN_PATH
:
2038 if (bt_config_append_plugin_paths_check_setuid_setgid(
2039 cfg
->plugin_paths
, arg
)) {
2043 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2044 cfg
->omit_system_plugin_path
= true;
2046 case OPT_OMIT_HOME_PLUGIN_PATH
:
2047 cfg
->omit_home_plugin_path
= true;
2051 bt_object_put_ref(params
);
2052 params
= bt_private_value_from_arg(arg
);
2054 printf_err("Invalid format for --params option's argument:\n %s\n",
2061 print_query_usage(stdout
);
2063 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2066 printf_err("Unknown command-line option specified (option code %d)\n",
2075 /* Check for option parsing error */
2077 printf_err("While parsing command-line options, at option %s: %s\n",
2078 poptBadOption(pc
, 0), poptStrerror(opt
));
2083 * We need exactly two leftover arguments which are the
2084 * mandatory component class specification and query object.
2086 leftover
= poptGetArg(pc
);
2088 cfg
->cmd_data
.query
.cfg_component
=
2089 bt_config_component_from_arg(leftover
);
2090 if (!cfg
->cmd_data
.query
.cfg_component
) {
2091 printf_err("Invalid format for component class specification:\n %s\n",
2097 BT_OBJECT_MOVE_REF(cfg
->cmd_data
.query
.cfg_component
->params
,
2100 print_query_usage(stdout
);
2102 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2106 leftover
= poptGetArg(pc
);
2108 if (strlen(leftover
) == 0) {
2109 printf_err("Invalid empty object\n");
2113 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2115 print_query_usage(stdout
);
2117 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2121 leftover
= poptGetArg(pc
);
2123 printf_err("Unexpected argument: %s\n", leftover
);
2127 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2135 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2139 poptFreeContext(pc
);
2142 bt_object_put_ref(params
);
2148 * Prints the list-plugins command usage.
2151 void print_list_plugins_usage(FILE *fp
)
2153 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2155 fprintf(fp
, "Options:\n");
2157 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2158 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2159 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2160 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2161 fprintf(fp
, " dynamic plugins can be loaded\n");
2162 fprintf(fp
, " -h, --help Show this help and quit\n");
2164 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2166 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2170 struct poptOption list_plugins_long_options
[] = {
2171 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2172 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2173 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2174 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2175 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2176 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2180 * Creates a Babeltrace config object from the arguments of a
2181 * list-plugins command.
2183 * *retcode is set to the appropriate exit code to use.
2186 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2187 int *retcode
, bool force_omit_system_plugin_path
,
2188 bool force_omit_home_plugin_path
,
2189 struct bt_private_value
*initial_plugin_paths
)
2191 poptContext pc
= NULL
;
2195 struct bt_config
*cfg
= NULL
;
2196 const char *leftover
;
2199 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2204 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2205 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2206 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2212 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2213 list_plugins_long_options
, 0);
2215 printf_err("Cannot get popt context\n");
2219 poptReadDefaultConfig(pc
, 0);
2221 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2222 arg
= poptGetOptArg(pc
);
2225 case OPT_PLUGIN_PATH
:
2226 if (bt_config_append_plugin_paths_check_setuid_setgid(
2227 cfg
->plugin_paths
, arg
)) {
2231 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2232 cfg
->omit_system_plugin_path
= true;
2234 case OPT_OMIT_HOME_PLUGIN_PATH
:
2235 cfg
->omit_home_plugin_path
= true;
2238 print_list_plugins_usage(stdout
);
2240 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2243 printf_err("Unknown command-line option specified (option code %d)\n",
2252 /* Check for option parsing error */
2254 printf_err("While parsing command-line options, at option %s: %s\n",
2255 poptBadOption(pc
, 0), poptStrerror(opt
));
2259 leftover
= poptGetArg(pc
);
2261 printf_err("Unexpected argument: %s\n", leftover
);
2265 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2273 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2277 poptFreeContext(pc
);
2285 * Prints the run command usage.
2288 void print_run_usage(FILE *fp
)
2290 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2292 fprintf(fp
, "Options:\n");
2294 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2295 fprintf(fp
, " for all the following components until\n");
2296 fprintf(fp
, " --reset-base-params is encountered\n");
2297 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2298 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2299 fprintf(fp
, " Instantiate the component class CLS of type\n");
2300 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2301 fprintf(fp
, " in the plugin PLUGIN, add it to the graph,\n");
2302 fprintf(fp
, " and optionally name it NAME (you can also\n");
2303 fprintf(fp
, " specify the name with --name)\n");
2304 fprintf(fp
, " -C, --connect=CONNECTION Connect two created components (see the\n");
2305 fprintf(fp
, " expected format of CONNECTION below)\n");
2306 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2307 fprintf(fp
, " parameter key to KEY (see --value)\n");
2308 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2309 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2310 fprintf(fp
, " names of the created components)\n");
2311 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2312 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2313 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2314 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2315 fprintf(fp
, " current component (see the expected format\n");
2316 fprintf(fp
, " of PARAMS below)\n");
2317 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2318 fprintf(fp
, " dynamic plugins can be loaded\n");
2319 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2320 fprintf(fp
, " empty map\n");
2321 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2322 fprintf(fp
, " the graph later, retry in DUR µs\n");
2323 fprintf(fp
, " (default: 100000)\n");
2324 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2325 fprintf(fp
, " the current component with a name given by\n");
2326 fprintf(fp
, " the last argument of the --key option and a\n");
2327 fprintf(fp
, " value set to VAL\n");
2328 fprintf(fp
, " -h, --help Show this help and quit\n");
2330 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2331 fprintf(fp
, "\n\n");
2332 fprintf(fp
, "Expected format of CONNECTION\n");
2333 fprintf(fp
, "-----------------------------\n");
2335 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2337 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2338 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2339 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2340 fprintf(fp
, "component with the --name option.\n");
2342 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2343 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2344 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2346 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2347 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2348 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2349 fprintf(fp
, "DOWNSTREAM.\n");
2351 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2352 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2353 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2355 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2356 fprintf(fp
, "can connect a filter component to a sink component.\n");
2358 fprintf(fp
, "Examples:\n");
2360 fprintf(fp
, " my-src:my-sink\n");
2361 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2363 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2364 fprintf(fp
, "babeltrace from a shell.\n");
2365 fprintf(fp
, "\n\n");
2366 print_expected_params_format(fp
);
2370 * Creates a Babeltrace config object from the arguments of a run
2373 * *retcode is set to the appropriate exit code to use.
2376 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2377 int *retcode
, bool force_omit_system_plugin_path
,
2378 bool force_omit_home_plugin_path
,
2379 struct bt_private_value
*initial_plugin_paths
)
2381 poptContext pc
= NULL
;
2383 struct bt_config_component
*cur_cfg_comp
= NULL
;
2384 enum bt_config_component_dest cur_cfg_comp_dest
=
2385 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
2386 struct bt_private_value
*cur_base_params
= NULL
;
2388 struct bt_config
*cfg
= NULL
;
2389 struct bt_private_value
*instance_names
= NULL
;
2390 struct bt_private_value
*connection_args
= NULL
;
2391 GString
*cur_param_key
= NULL
;
2392 char error_buf
[256] = { 0 };
2393 long retry_duration
= -1;
2394 enum bt_value_status status
;
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_LONG
, &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_private_value_map_create();
2434 if (!cur_base_params
) {
2439 instance_names
= bt_private_value_map_create();
2440 if (!instance_names
) {
2445 connection_args
= bt_private_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_OBJECT_PUT_REF_AND_RESET(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 BT_ASSERT(cur_base_params
);
2518 bt_object_put_ref(cur_cfg_comp
->params
);
2519 status
= bt_value_copy(
2520 &cur_cfg_comp
->params
,
2521 bt_private_value_as_value(cur_base_params
));
2522 if (status
!= BT_VALUE_STATUS_OK
) {
2527 cur_cfg_comp_dest
= new_dest
;
2532 struct bt_private_value
*params
;
2533 struct bt_private_value
*params_to_set
;
2535 if (!cur_cfg_comp
) {
2536 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2541 params
= bt_private_value_from_arg(arg
);
2543 printf_err("Invalid format for --params option's argument:\n %s\n",
2548 status
= bt_value_map_extend(¶ms_to_set
,
2549 bt_private_value_as_value(cur_cfg_comp
->params
),
2550 bt_private_value_as_value(params
));
2551 BT_OBJECT_PUT_REF_AND_RESET(params
);
2552 if (status
!= BT_VALUE_STATUS_OK
) {
2553 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2558 BT_OBJECT_MOVE_REF(cur_cfg_comp
->params
, params_to_set
);
2562 if (strlen(arg
) == 0) {
2563 printf_err("Cannot set an empty string as the current parameter key\n");
2567 g_string_assign(cur_param_key
, arg
);
2570 if (!cur_cfg_comp
) {
2571 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2576 if (cur_param_key
->len
== 0) {
2577 printf_err("--value option specified without preceding --key option:\n %s\n",
2582 if (bt_private_value_map_insert_string_entry(cur_cfg_comp
->params
,
2583 cur_param_key
->str
, arg
)) {
2589 if (!cur_cfg_comp
) {
2590 printf_err("Cannot set the name of unavailable component:\n %s\n",
2595 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2597 case OPT_BASE_PARAMS
:
2599 struct bt_private_value
*params
=
2600 bt_private_value_from_arg(arg
);
2603 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2608 BT_OBJECT_MOVE_REF(cur_base_params
, params
);
2611 case OPT_RESET_BASE_PARAMS
:
2612 BT_OBJECT_PUT_REF_AND_RESET(cur_base_params
);
2613 cur_base_params
= bt_private_value_map_create();
2614 if (!cur_base_params
) {
2620 if (bt_private_value_array_append_string_element(
2621 connection_args
, arg
)) {
2626 case OPT_RETRY_DURATION
:
2627 if (retry_duration
< 0) {
2628 printf_err("--retry-duration option's argument must be positive or 0: %ld\n",
2633 cfg
->cmd_data
.run
.retry_duration_us
=
2634 (uint64_t) retry_duration
;
2637 print_run_usage(stdout
);
2639 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2642 printf_err("Unknown command-line option specified (option code %d)\n",
2651 /* Check for option parsing error */
2653 printf_err("While parsing command-line options, at option %s: %s\n",
2654 poptBadOption(pc
, 0), poptStrerror(opt
));
2658 /* This command does not accept leftover arguments */
2659 if (poptPeekArg(pc
)) {
2660 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2664 /* Add current component */
2666 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2667 cur_cfg_comp_dest
, instance_names
);
2668 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2674 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2675 printf_err("Incomplete graph: no source component\n");
2679 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2680 printf_err("Incomplete graph: no sink component\n");
2684 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2688 ret
= bt_config_cli_args_create_connections(cfg
,
2689 bt_private_value_as_value(connection_args
),
2692 printf_err("Cannot creation connections:\n%s", error_buf
);
2700 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2704 poptFreeContext(pc
);
2707 if (cur_param_key
) {
2708 g_string_free(cur_param_key
, TRUE
);
2712 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2713 BT_OBJECT_PUT_REF_AND_RESET(cur_base_params
);
2714 BT_OBJECT_PUT_REF_AND_RESET(instance_names
);
2715 BT_OBJECT_PUT_REF_AND_RESET(connection_args
);
2720 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2721 int *retcode
, bool force_omit_system_plugin_path
,
2722 bool force_omit_home_plugin_path
,
2723 struct bt_private_value
*initial_plugin_paths
)
2725 struct bt_config
*cfg
= NULL
;
2728 const size_t argc
= bt_value_array_get_size(run_args
) + 1;
2730 argv
= calloc(argc
, sizeof(*argv
));
2738 len
= bt_value_array_get_size(run_args
);
2740 printf_err("Invalid executable arguments\n");
2743 for (i
= 0; i
< len
; i
++) {
2744 struct bt_value
*arg_value
=
2745 bt_value_array_borrow_element_by_index(run_args
, i
);
2748 BT_ASSERT(arg_value
);
2749 arg
= bt_value_string_get(arg_value
);
2754 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2755 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2756 initial_plugin_paths
);
2764 * Prints the convert command usage.
2767 void print_convert_usage(FILE *fp
)
2769 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2771 fprintf(fp
, "Options:\n");
2773 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2774 fprintf(fp
, " Instantiate the component class CLS of type\n");
2775 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2776 fprintf(fp
, " in the plugin PLUGIN, add it to the\n");
2777 fprintf(fp
, " conversion graph, and optionally name it\n");
2778 fprintf(fp
, " NAME (you can also specify the name with\n");
2779 fprintf(fp
, " --name)\n");
2780 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2781 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2782 fprintf(fp
, " names of the created components)\n");
2783 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2784 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2785 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2786 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2787 fprintf(fp
, " current component (see the expected format\n");
2788 fprintf(fp
, " of PARAMS below)\n");
2789 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2790 fprintf(fp
, " current component to PATH\n");
2791 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2792 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2793 fprintf(fp
, " the graph later, retry in DUR µs\n");
2794 fprintf(fp
, " (default: 100000)\n");
2795 fprintf(fp
, " dynamic plugins can be loaded\n");
2796 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2797 fprintf(fp
, " `run` command to the standard output,\n");
2798 fprintf(fp
, " formatted for a shell, and quit\n");
2799 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2800 fprintf(fp
, " `run` command to the standard output,\n");
2801 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2802 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2803 fprintf(fp
, " are active\n");
2804 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2805 fprintf(fp
, " current component to URL\n");
2806 fprintf(fp
, " -h, --help Show this help and quit\n");
2808 fprintf(fp
, "Implicit `source.ctf.fs` component options:\n");
2810 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2811 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2813 fprintf(fp
, "Implicit `sink.text.pretty` component options:\n");
2815 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2816 fprintf(fp
, " --clock-date Print timestamp dates\n");
2817 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2818 fprintf(fp
, " time zone instead of the local time zone\n");
2819 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2820 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2821 fprintf(fp
, " --color=(never | auto | always)\n");
2822 fprintf(fp
, " Never, automatically, or always emit\n");
2823 fprintf(fp
, " console color codes\n");
2824 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2825 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2826 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2827 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2828 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2829 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2830 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2831 fprintf(fp
, " (or `ctx`)\n");
2832 fprintf(fp
, " --no-delta Do not print time delta between\n");
2833 fprintf(fp
, " consecutive events\n");
2834 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2835 fprintf(fp
, " the standard output\n");
2837 fprintf(fp
, "Implicit `filter.utils.muxer` component options:\n");
2839 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2840 fprintf(fp
, " correlated across traces\n");
2842 fprintf(fp
, "Implicit `filter.utils.trimmer` component options:\n");
2844 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2845 fprintf(fp
, " time range to BEGIN (see the format of\n");
2846 fprintf(fp
, " BEGIN below)\n");
2847 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2848 fprintf(fp
, " range to END (see the format of END below)\n");
2849 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2850 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2851 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2853 fprintf(fp
, "Implicit `filter.lttng-utils.debug-info` component options:\n");
2855 fprintf(fp
, " --debug-info Create an implicit\n");
2856 fprintf(fp
, " `filter.lttng-utils.debug-info` component\n");
2857 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2858 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2859 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2860 fprintf(fp
, " binary paths instead of just names\n");
2861 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2862 fprintf(fp
, " Use directory DIR as a prefix when\n");
2863 fprintf(fp
, " looking up executables during debug\n");
2864 fprintf(fp
, " info analysis\n");
2866 fprintf(fp
, "Legacy options that still work:\n");
2868 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2869 fprintf(fp
, " `ctf`:\n");
2870 fprintf(fp
, " Create an implicit `source.ctf.fs`\n");
2871 fprintf(fp
, " component\n");
2872 fprintf(fp
, " `lttng-live`:\n");
2873 fprintf(fp
, " Create an implicit `source.ctf.lttng-live`\n");
2874 fprintf(fp
, " component\n");
2875 fprintf(fp
, " -o, --output-format=(text | ctf | dummy | ctf-metadata)\n");
2876 fprintf(fp
, " `text`:\n");
2877 fprintf(fp
, " Create an implicit `sink.text.pretty`\n");
2878 fprintf(fp
, " component\n");
2879 fprintf(fp
, " `ctf`:\n");
2880 fprintf(fp
, " Create an implicit `sink.ctf.fs`\n");
2881 fprintf(fp
, " component\n");
2882 fprintf(fp
, " `dummy`:\n");
2883 fprintf(fp
, " Create an implicit `sink.utils.dummy`\n");
2884 fprintf(fp
, " component\n");
2885 fprintf(fp
, " `ctf-metadata`:\n");
2886 fprintf(fp
, " Query the `source.ctf.fs` component class\n");
2887 fprintf(fp
, " for metadata text and quit\n");
2889 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2890 fprintf(fp
, "\n\n");
2891 fprintf(fp
, "Format of BEGIN and END\n");
2892 fprintf(fp
, "-----------------------\n");
2894 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2895 fprintf(fp
, "\n\n");
2896 print_expected_params_format(fp
);
2900 struct poptOption convert_long_options
[] = {
2901 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2902 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2903 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2904 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2905 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2906 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2907 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2908 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2909 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2910 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2911 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2912 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2913 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2914 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2915 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2916 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2917 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2918 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2919 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2920 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2921 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2922 { "debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO
, NULL
, NULL
},
2923 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2924 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2925 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2926 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2927 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2928 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2929 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2930 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2931 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2932 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2933 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2934 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2935 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2936 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2937 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2938 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2942 GString
*get_component_auto_name(const char *prefix
,
2943 struct bt_value
*existing_names
)
2946 GString
*auto_name
= g_string_new(NULL
);
2953 if (!bt_value_map_has_entry(existing_names
, prefix
)) {
2954 g_string_assign(auto_name
, prefix
);
2959 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2961 } while (bt_value_map_has_entry(existing_names
, auto_name
->str
));
2967 struct implicit_component_args
{
2971 GString
*params_arg
;
2972 struct bt_private_value
*extra_params
;
2976 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
2977 const char *prefix
, struct bt_private_value
*existing_names
,
2978 GList
**comp_names
, bool append_to_comp_names
)
2981 GString
*name
= NULL
;
2983 if (!args
->exists
) {
2987 name
= get_component_auto_name(prefix
,
2988 bt_private_value_as_value(existing_names
));
2995 g_string_assign(args
->name_arg
, name
->str
);
2997 if (bt_private_value_map_insert_entry(existing_names
, name
->str
,
3004 if (append_to_comp_names
) {
3005 *comp_names
= g_list_append(*comp_names
, name
);
3011 g_string_free(name
, TRUE
);
3018 int append_run_args_for_implicit_component(
3019 struct implicit_component_args
*impl_args
,
3020 struct bt_private_value
*run_args
)
3025 if (!impl_args
->exists
) {
3029 if (bt_private_value_array_append_string_element(run_args
, "--component")) {
3034 if (bt_private_value_array_append_string_element(run_args
, impl_args
->comp_arg
->str
)) {
3039 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3044 if (bt_private_value_array_append_string_element(run_args
, impl_args
->name_arg
->str
)) {
3049 if (impl_args
->params_arg
->len
> 0) {
3050 if (bt_private_value_array_append_string_element(run_args
, "--params")) {
3055 if (bt_private_value_array_append_string_element(run_args
,
3056 impl_args
->params_arg
->str
)) {
3062 for (i
= 0; i
< bt_value_array_get_size(
3063 bt_private_value_as_value(impl_args
->extra_params
));
3065 struct bt_value
*elem
;
3068 elem
= bt_value_array_borrow_element_by_index(
3069 bt_private_value_as_value(impl_args
->extra_params
),
3075 BT_ASSERT(bt_value_is_string(elem
));
3076 arg
= bt_value_string_get(elem
);
3077 ret
= bt_private_value_array_append_string_element(run_args
, arg
);
3094 void finalize_implicit_component_args(struct implicit_component_args
*args
)
3098 if (args
->comp_arg
) {
3099 g_string_free(args
->comp_arg
, TRUE
);
3102 if (args
->name_arg
) {
3103 g_string_free(args
->name_arg
, TRUE
);
3106 if (args
->params_arg
) {
3107 g_string_free(args
->params_arg
, TRUE
);
3110 bt_object_put_ref(args
->extra_params
);
3114 void destroy_implicit_component_args(void *args
)
3120 finalize_implicit_component_args(args
);
3125 int init_implicit_component_args(struct implicit_component_args
*args
,
3126 const char *comp_arg
, bool exists
)
3130 args
->exists
= exists
;
3131 args
->comp_arg
= g_string_new(comp_arg
);
3132 args
->name_arg
= g_string_new(NULL
);
3133 args
->params_arg
= g_string_new(NULL
);
3134 args
->extra_params
= bt_private_value_array_create();
3136 if (!args
->comp_arg
|| !args
->name_arg
||
3137 !args
->params_arg
|| !args
->extra_params
) {
3139 finalize_implicit_component_args(args
);
3149 void append_implicit_component_param(struct implicit_component_args
*args
,
3150 const char *key
, const char *value
)
3155 append_param_arg(args
->params_arg
, key
, value
);
3159 int append_implicit_component_extra_param(struct implicit_component_args
*args
,
3160 const char *key
, const char *value
)
3168 if (bt_private_value_array_append_string_element(args
->extra_params
, "--key")) {
3174 if (bt_private_value_array_append_string_element(args
->extra_params
, key
)) {
3180 if (bt_private_value_array_append_string_element(args
->extra_params
, "--value")) {
3186 if (bt_private_value_array_append_string_element(args
->extra_params
, value
)) {
3197 int convert_append_name_param(enum bt_config_component_dest dest
,
3198 GString
*cur_name
, GString
*cur_name_prefix
,
3199 struct bt_private_value
*run_args
,
3200 struct bt_private_value
*all_names
,
3201 GList
**source_names
, GList
**filter_names
,
3206 if (cur_name_prefix
->len
> 0) {
3207 /* We're after a --component option */
3208 GString
*name
= NULL
;
3209 bool append_name_opt
= false;
3211 if (cur_name
->len
== 0) {
3213 * No explicit name was provided for the user
3216 name
= get_component_auto_name(cur_name_prefix
->str
,
3217 bt_private_value_as_value(all_names
));
3218 append_name_opt
= true;
3221 * An explicit name was provided for the user
3224 if (bt_value_map_has_entry(
3225 bt_private_value_as_value(all_names
),
3227 printf_err("Duplicate component instance name:\n %s\n",
3232 name
= g_string_new(cur_name
->str
);
3241 * Remember this name globally, for the uniqueness of
3242 * all component names.
3244 if (bt_private_value_map_insert_entry(all_names
, name
->str
, bt_value_null
)) {
3250 * Append the --name option if necessary.
3252 if (append_name_opt
) {
3253 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3258 if (bt_private_value_array_append_string_element(run_args
, name
->str
)) {
3265 * Remember this name specifically for the type of the
3266 * component. This is to create connection arguments.
3269 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3270 *source_names
= g_list_append(*source_names
, name
);
3272 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3273 *filter_names
= g_list_append(*filter_names
, name
);
3275 case BT_CONFIG_COMPONENT_DEST_SINK
:
3276 *sink_names
= g_list_append(*sink_names
, name
);
3282 g_string_assign(cur_name_prefix
, "");
3295 * Escapes `.`, `:`, and `\` of `input` with `\`.
3298 GString
*escape_dot_colon(const char *input
)
3300 GString
*output
= g_string_new(NULL
);
3308 for (ch
= input
; *ch
!= '\0'; ch
++) {
3309 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3310 g_string_append_c(output
, '\\');
3313 g_string_append_c(output
, *ch
);
3321 * Appends a --connect option to a list of arguments. `upstream_name`
3322 * and `downstream_name` are escaped with escape_dot_colon() in this
3326 int append_connect_arg(struct bt_private_value
*run_args
,
3327 const char *upstream_name
, const char *downstream_name
)
3330 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3331 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3332 GString
*arg
= g_string_new(NULL
);
3334 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3340 ret
= bt_private_value_array_append_string_element(run_args
, "--connect");
3347 g_string_append(arg
, e_upstream_name
->str
);
3348 g_string_append_c(arg
, ':');
3349 g_string_append(arg
, e_downstream_name
->str
);
3350 ret
= bt_private_value_array_append_string_element(run_args
, arg
->str
);
3359 g_string_free(arg
, TRUE
);
3362 if (e_upstream_name
) {
3363 g_string_free(e_upstream_name
, TRUE
);
3366 if (e_downstream_name
) {
3367 g_string_free(e_downstream_name
, TRUE
);
3374 * Appends the run command's --connect options for the convert command.
3377 int convert_auto_connect(struct bt_private_value
*run_args
,
3378 GList
*source_names
, GList
*filter_names
,
3382 GList
*source_at
= source_names
;
3383 GList
*filter_at
= filter_names
;
3385 GList
*sink_at
= sink_names
;
3387 BT_ASSERT(source_names
);
3388 BT_ASSERT(filter_names
);
3389 BT_ASSERT(sink_names
);
3391 /* Connect all sources to the first filter */
3392 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3393 GString
*source_name
= source_at
->data
;
3394 GString
*filter_name
= filter_at
->data
;
3396 ret
= append_connect_arg(run_args
, source_name
->str
,
3403 filter_prev
= filter_at
;
3404 filter_at
= g_list_next(filter_at
);
3406 /* Connect remaining filters */
3407 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3408 GString
*filter_name
= filter_at
->data
;
3409 GString
*filter_prev_name
= filter_prev
->data
;
3411 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3418 /* Connect last filter to all sinks */
3419 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3420 GString
*filter_name
= filter_prev
->data
;
3421 GString
*sink_name
= sink_at
->data
;
3423 ret
= append_connect_arg(run_args
, filter_name
->str
,
3440 int split_timerange(const char *arg
, char **begin
, char **end
)
3443 const char *ch
= arg
;
3445 GString
*g_begin
= NULL
;
3446 GString
*g_end
= NULL
;
3454 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3455 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3461 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3462 if (!g_end
|| g_end
->len
== 0) {
3468 *begin
= g_begin
->str
;
3470 g_string_free(g_begin
, FALSE
);
3471 g_string_free(g_end
, FALSE
);
3481 g_string_free(g_begin
, TRUE
);
3485 g_string_free(g_end
, TRUE
);
3492 int g_list_prepend_gstring(GList
**list
, const char *string
)
3495 GString
*gs
= g_string_new(string
);
3504 *list
= g_list_prepend(*list
, gs
);
3511 struct implicit_component_args
*create_implicit_component_args(void)
3513 struct implicit_component_args
*impl_args
=
3514 g_new0(struct implicit_component_args
, 1);
3520 if (init_implicit_component_args(impl_args
, NULL
, true)) {
3521 destroy_implicit_component_args(impl_args
);
3531 int fill_implicit_ctf_inputs_args(GPtrArray
*implicit_ctf_inputs_args
,
3532 struct implicit_component_args
*base_implicit_ctf_input_args
,
3537 enum bt_value_status status
;
3539 for (leftover
= leftovers
; leftover
!= NULL
;
3540 leftover
= g_list_next(leftover
)) {
3541 GString
*gs_leftover
= leftover
->data
;
3542 struct implicit_component_args
*impl_args
=
3543 create_implicit_component_args();
3550 impl_args
->exists
= true;
3551 g_string_assign(impl_args
->comp_arg
,
3552 base_implicit_ctf_input_args
->comp_arg
->str
);
3553 g_string_assign(impl_args
->params_arg
,
3554 base_implicit_ctf_input_args
->params_arg
->str
);
3557 * We need our own copy of the extra parameters because
3558 * this is where the unique path goes.
3560 BT_OBJECT_PUT_REF_AND_RESET(impl_args
->extra_params
);
3561 status
= bt_value_copy(&impl_args
->extra_params
,
3562 bt_private_value_as_value(
3563 base_implicit_ctf_input_args
->extra_params
));
3564 if (status
!= BT_VALUE_STATUS_OK
) {
3566 destroy_implicit_component_args(impl_args
);
3570 /* Append unique path parameter */
3571 ret
= append_implicit_component_extra_param(impl_args
,
3572 "path", gs_leftover
->str
);
3574 destroy_implicit_component_args(impl_args
);
3578 g_ptr_array_add(implicit_ctf_inputs_args
, impl_args
);
3591 * Creates a Babeltrace config object from the arguments of a convert
3594 * *retcode is set to the appropriate exit code to use.
3597 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3598 int *retcode
, bool force_omit_system_plugin_path
,
3599 bool force_omit_home_plugin_path
,
3600 struct bt_private_value
*initial_plugin_paths
, char *log_level
)
3602 poptContext pc
= NULL
;
3604 enum bt_config_component_dest cur_comp_dest
=
3605 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3607 struct bt_config
*cfg
= NULL
;
3608 bool got_input_format_opt
= false;
3609 bool got_output_format_opt
= false;
3610 bool trimmer_has_begin
= false;
3611 bool trimmer_has_end
= false;
3612 bool stream_intersection_mode
= false;
3613 GString
*cur_name
= NULL
;
3614 GString
*cur_name_prefix
= NULL
;
3615 const char *leftover
= NULL
;
3616 bool print_run_args
= false;
3617 bool print_run_args_0
= false;
3618 bool print_ctf_metadata
= false;
3619 struct bt_private_value
*run_args
= NULL
;
3620 struct bt_private_value
*all_names
= NULL
;
3621 GList
*source_names
= NULL
;
3622 GList
*filter_names
= NULL
;
3623 GList
*sink_names
= NULL
;
3624 GList
*leftovers
= NULL
;
3625 GPtrArray
*implicit_ctf_inputs_args
= NULL
;
3626 struct implicit_component_args base_implicit_ctf_input_args
= { 0 };
3627 struct implicit_component_args implicit_ctf_output_args
= { 0 };
3628 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3629 struct implicit_component_args implicit_dummy_args
= { 0 };
3630 struct implicit_component_args implicit_text_args
= { 0 };
3631 struct implicit_component_args implicit_debug_info_args
= { 0 };
3632 struct implicit_component_args implicit_muxer_args
= { 0 };
3633 struct implicit_component_args implicit_trimmer_args
= { 0 };
3634 struct bt_private_value
*plugin_paths
;
3635 char error_buf
[256] = { 0 };
3637 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3638 char *output
= NULL
;
3640 plugin_paths
= initial_plugin_paths
;
3641 bt_object_get_ref(plugin_paths
);
3646 print_convert_usage(stdout
);
3651 if (init_implicit_component_args(&base_implicit_ctf_input_args
,
3652 "source.ctf.fs", false)) {
3656 if (init_implicit_component_args(&implicit_ctf_output_args
,
3657 "sink.ctf.fs", false)) {
3661 if (init_implicit_component_args(&implicit_lttng_live_args
,
3662 "source.ctf.lttng-live", false)) {
3666 if (init_implicit_component_args(&implicit_text_args
,
3667 "sink.text.pretty", false)) {
3671 if (init_implicit_component_args(&implicit_dummy_args
,
3672 "sink.utils.dummy", false)) {
3676 if (init_implicit_component_args(&implicit_debug_info_args
,
3677 "filter.lttng-utils.debug-info", false)) {
3681 if (init_implicit_component_args(&implicit_muxer_args
,
3682 "filter.utils.muxer", true)) {
3686 if (init_implicit_component_args(&implicit_trimmer_args
,
3687 "filter.utils.trimmer", false)) {
3691 implicit_ctf_inputs_args
= g_ptr_array_new_with_free_func(
3692 (GDestroyNotify
) destroy_implicit_component_args
);
3693 if (!implicit_ctf_inputs_args
) {
3698 all_names
= bt_private_value_map_create();
3704 run_args
= bt_private_value_array_create();
3710 cur_name
= g_string_new(NULL
);
3716 cur_name_prefix
= g_string_new(NULL
);
3717 if (!cur_name_prefix
) {
3722 ret
= append_env_var_plugin_paths(plugin_paths
);
3728 * First pass: collect all arguments which need to be passed
3729 * as is to the run command. This pass can also add --name
3730 * arguments if needed to automatically name unnamed component
3731 * instances. Also it does the following transformations:
3733 * --path=PATH -> --key path --value PATH
3734 * --url=URL -> --key url --value URL
3736 * Also it appends the plugin paths of --plugin-path to
3739 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3740 convert_long_options
, 0);
3742 printf_err("Cannot get popt context\n");
3746 poptReadDefaultConfig(pc
, 0);
3748 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3750 char *plugin_name
= NULL
;
3751 char *comp_cls_name
= NULL
;
3753 arg
= poptGetOptArg(pc
);
3758 enum bt_component_class_type type
;
3759 const char *type_prefix
;
3761 /* Append current component's name if needed */
3762 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3763 cur_name_prefix
, run_args
, all_names
,
3764 &source_names
, &filter_names
, &sink_names
);
3769 /* Parse the argument */
3770 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3771 &comp_cls_name
, &type
);
3772 if (!plugin_name
|| !comp_cls_name
) {
3773 printf_err("Invalid format for --component option's argument:\n %s\n",
3779 g_string_assign(cur_name
, name
);
3781 g_string_assign(cur_name
, "");
3785 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3786 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3787 type_prefix
= "source";
3789 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3790 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
3791 type_prefix
= "filter";
3793 case BT_COMPONENT_CLASS_TYPE_SINK
:
3794 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3795 type_prefix
= "sink";
3801 if (bt_private_value_array_append_string_element(run_args
,
3807 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3812 g_string_assign(cur_name_prefix
, "");
3813 g_string_append_printf(cur_name_prefix
, "%s.%s.%s",
3814 type_prefix
, plugin_name
, comp_cls_name
);
3817 free(comp_cls_name
);
3820 comp_cls_name
= NULL
;
3824 if (cur_name_prefix
->len
== 0) {
3825 printf_err("No current component of which to set parameters:\n %s\n",
3830 if (bt_private_value_array_append_string_element(run_args
,
3836 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3842 if (cur_name_prefix
->len
== 0) {
3843 printf_err("No current component of which to set `path` parameter:\n %s\n",
3848 if (bt_private_value_array_append_string_element(run_args
, "--key")) {
3853 if (bt_private_value_array_append_string_element(run_args
, "path")) {
3858 if (bt_private_value_array_append_string_element(run_args
, "--value")) {
3863 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3869 if (cur_name_prefix
->len
== 0) {
3870 printf_err("No current component of which to set `url` parameter:\n %s\n",
3875 if (bt_private_value_array_append_string_element(run_args
, "--key")) {
3880 if (bt_private_value_array_append_string_element(run_args
, "url")) {
3885 if (bt_private_value_array_append_string_element(run_args
, "--value")) {
3890 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3896 if (cur_name_prefix
->len
== 0) {
3897 printf_err("No current component to name:\n %s\n",
3902 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3907 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3912 g_string_assign(cur_name
, arg
);
3914 case OPT_OMIT_HOME_PLUGIN_PATH
:
3915 force_omit_home_plugin_path
= true;
3917 if (bt_private_value_array_append_string_element(run_args
,
3918 "--omit-home-plugin-path")) {
3923 case OPT_RETRY_DURATION
:
3924 if (bt_private_value_array_append_string_element(run_args
,
3925 "--retry-duration")) {
3930 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3935 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3936 force_omit_system_plugin_path
= true;
3938 if (bt_private_value_array_append_string_element(run_args
,
3939 "--omit-system-plugin-path")) {
3944 case OPT_PLUGIN_PATH
:
3945 if (bt_config_append_plugin_paths_check_setuid_setgid(
3946 plugin_paths
, arg
)) {
3950 if (bt_private_value_array_append_string_element(run_args
,
3956 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3962 print_convert_usage(stdout
);
3964 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
3967 case OPT_CLOCK_CYCLES
:
3968 case OPT_CLOCK_DATE
:
3969 case OPT_CLOCK_FORCE_CORRELATE
:
3971 case OPT_CLOCK_OFFSET
:
3972 case OPT_CLOCK_OFFSET_NS
:
3973 case OPT_CLOCK_SECONDS
:
3976 case OPT_DEBUG_INFO
:
3977 case OPT_DEBUG_INFO_DIR
:
3978 case OPT_DEBUG_INFO_FULL_PATH
:
3979 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3982 case OPT_INPUT_FORMAT
:
3985 case OPT_OUTPUT_FORMAT
:
3988 case OPT_RUN_ARGS_0
:
3989 case OPT_STREAM_INTERSECTION
:
3992 /* Ignore in this pass */
3995 printf_err("Unknown command-line option specified (option code %d)\n",
4004 /* Append current component's name if needed */
4005 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
4006 cur_name_prefix
, run_args
, all_names
, &source_names
,
4007 &filter_names
, &sink_names
);
4012 /* Check for option parsing error */
4014 printf_err("While parsing command-line options, at option %s: %s\n",
4015 poptBadOption(pc
, 0), poptStrerror(opt
));
4019 poptFreeContext(pc
);
4024 * Second pass: transform the convert-specific options and
4025 * arguments into implicit component instances for the run
4028 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
4029 convert_long_options
, 0);
4031 printf_err("Cannot get popt context\n");
4035 poptReadDefaultConfig(pc
, 0);
4037 while ((opt
= poptGetNextOpt(pc
)) > 0) {
4038 arg
= poptGetOptArg(pc
);
4042 if (trimmer_has_begin
) {
4043 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4048 trimmer_has_begin
= true;
4049 ret
= append_implicit_component_extra_param(
4050 &implicit_trimmer_args
, "begin", arg
);
4051 implicit_trimmer_args
.exists
= true;
4057 if (trimmer_has_end
) {
4058 printf("At --end option: --end or --timerange option already specified\n %s\n",
4063 trimmer_has_end
= true;
4064 ret
= append_implicit_component_extra_param(
4065 &implicit_trimmer_args
, "end", arg
);
4066 implicit_trimmer_args
.exists
= true;
4076 if (trimmer_has_begin
|| trimmer_has_end
) {
4077 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4082 ret
= split_timerange(arg
, &begin
, &end
);
4084 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4089 ret
= append_implicit_component_extra_param(
4090 &implicit_trimmer_args
, "begin", begin
);
4091 ret
|= append_implicit_component_extra_param(
4092 &implicit_trimmer_args
, "end", end
);
4093 implicit_trimmer_args
.exists
= true;
4101 case OPT_CLOCK_CYCLES
:
4102 append_implicit_component_param(
4103 &implicit_text_args
, "clock-cycles", "yes");
4104 implicit_text_args
.exists
= true;
4106 case OPT_CLOCK_DATE
:
4107 append_implicit_component_param(
4108 &implicit_text_args
, "clock-date", "yes");
4109 implicit_text_args
.exists
= true;
4111 case OPT_CLOCK_FORCE_CORRELATE
:
4112 append_implicit_component_param(
4113 &implicit_muxer_args
,
4114 "assume-absolute-clock-classes", "yes");
4117 append_implicit_component_param(
4118 &implicit_text_args
, "clock-gmt", "yes");
4119 append_implicit_component_param(
4120 &implicit_trimmer_args
, "clock-gmt", "yes");
4121 implicit_text_args
.exists
= true;
4123 case OPT_CLOCK_OFFSET
:
4124 base_implicit_ctf_input_args
.exists
= true;
4125 append_implicit_component_param(
4126 &base_implicit_ctf_input_args
,
4127 "clock-class-offset-s", arg
);
4129 case OPT_CLOCK_OFFSET_NS
:
4130 base_implicit_ctf_input_args
.exists
= true;
4131 append_implicit_component_param(
4132 &base_implicit_ctf_input_args
,
4133 "clock-class-offset-ns", arg
);
4135 case OPT_CLOCK_SECONDS
:
4136 append_implicit_component_param(
4137 &implicit_text_args
, "clock-seconds", "yes");
4138 implicit_text_args
.exists
= true;
4141 implicit_text_args
.exists
= true;
4142 ret
= append_implicit_component_extra_param(
4143 &implicit_text_args
, "color", arg
);
4148 case OPT_DEBUG_INFO
:
4149 implicit_debug_info_args
.exists
= true;
4151 case OPT_DEBUG_INFO_DIR
:
4152 implicit_debug_info_args
.exists
= true;
4153 ret
= append_implicit_component_extra_param(
4154 &implicit_debug_info_args
, "debug-info-dir", arg
);
4159 case OPT_DEBUG_INFO_FULL_PATH
:
4160 implicit_debug_info_args
.exists
= true;
4161 append_implicit_component_param(
4162 &implicit_debug_info_args
, "full-path", "yes");
4164 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4165 implicit_debug_info_args
.exists
= true;
4166 ret
= append_implicit_component_extra_param(
4167 &implicit_debug_info_args
,
4168 "target-prefix", arg
);
4175 struct bt_private_value
*fields
= fields_from_arg(arg
);
4181 implicit_text_args
.exists
= true;
4182 ret
= insert_flat_params_from_array(
4183 implicit_text_args
.params_arg
,
4184 bt_private_value_as_value(fields
), "field");
4185 bt_object_put_ref(fields
);
4193 struct bt_private_value
*names
= names_from_arg(arg
);
4199 implicit_text_args
.exists
= true;
4200 ret
= insert_flat_params_from_array(
4201 implicit_text_args
.params_arg
,
4202 bt_private_value_as_value(names
), "name");
4203 bt_object_put_ref(names
);
4210 append_implicit_component_param(
4211 &implicit_text_args
, "no-delta", "yes");
4212 implicit_text_args
.exists
= true;
4214 case OPT_INPUT_FORMAT
:
4215 if (got_input_format_opt
) {
4216 printf_err("Duplicate --input-format option\n");
4220 got_input_format_opt
= true;
4222 if (strcmp(arg
, "ctf") == 0) {
4223 base_implicit_ctf_input_args
.exists
= true;
4224 } else if (strcmp(arg
, "lttng-live") == 0) {
4225 implicit_lttng_live_args
.exists
= true;
4227 printf_err("Unknown legacy input format:\n %s\n",
4232 case OPT_OUTPUT_FORMAT
:
4233 if (got_output_format_opt
) {
4234 printf_err("Duplicate --output-format option\n");
4238 got_output_format_opt
= true;
4240 if (strcmp(arg
, "text") == 0) {
4241 implicit_text_args
.exists
= true;
4242 } else if (strcmp(arg
, "ctf") == 0) {
4243 implicit_ctf_output_args
.exists
= true;
4244 } else if (strcmp(arg
, "dummy") == 0) {
4245 implicit_dummy_args
.exists
= true;
4246 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4247 print_ctf_metadata
= true;
4249 printf_err("Unknown legacy output format:\n %s\n",
4256 printf_err("Duplicate --output option\n");
4260 output
= strdup(arg
);
4267 if (print_run_args_0
) {
4268 printf_err("Cannot specify --run-args and --run-args-0\n");
4272 print_run_args
= true;
4274 case OPT_RUN_ARGS_0
:
4275 if (print_run_args
) {
4276 printf_err("Cannot specify --run-args and --run-args-0\n");
4280 print_run_args_0
= true;
4282 case OPT_STREAM_INTERSECTION
:
4284 * Applies to all traces implementing the trace-info
4287 stream_intersection_mode
= true;
4290 if (*log_level
!= 'V' && *log_level
!= 'D') {
4303 /* Check for option parsing error */
4305 printf_err("While parsing command-line options, at option %s: %s\n",
4306 poptBadOption(pc
, 0), poptStrerror(opt
));
4311 * Legacy behaviour: --verbose used to make the `text` output
4312 * format print more information. --verbose is now equivalent to
4313 * the INFO log level, which is why we compare to 'I' here.
4315 if (*log_level
== 'I') {
4316 append_implicit_component_param(&implicit_text_args
,
4321 * Append home and system plugin paths now that we possibly got
4324 if (append_home_and_system_plugin_paths(plugin_paths
,
4325 force_omit_system_plugin_path
,
4326 force_omit_home_plugin_path
)) {
4330 /* Consume and keep leftover arguments */
4331 while ((leftover
= poptGetArg(pc
))) {
4332 GString
*gs_leftover
= g_string_new(leftover
);
4339 leftovers
= g_list_append(leftovers
, gs_leftover
);
4341 g_string_free(gs_leftover
, TRUE
);
4347 /* Print CTF metadata or print LTTng live sessions */
4348 if (print_ctf_metadata
) {
4349 GString
*gs_leftover
;
4351 if (g_list_length(leftovers
) == 0) {
4352 printf_err("--output-format=ctf-metadata specified without a path\n");
4356 if (g_list_length(leftovers
) > 1) {
4357 printf_err("Too many paths specified for --output-format=ctf-metadata\n");
4361 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4366 gs_leftover
= leftovers
->data
;
4367 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4372 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
4380 * If -o ctf was specified, make sure an output path (--output)
4381 * was also specified. --output does not imply -o ctf because
4382 * it's also used for the default, implicit -o text if -o ctf
4385 if (implicit_ctf_output_args
.exists
) {
4387 printf_err("--output-format=ctf specified without --output (trace output path)\n");
4392 * At this point we know that -o ctf AND --output were
4393 * specified. Make sure that no options were specified
4394 * which would imply -o text because --output would be
4395 * ambiguous in this case. For example, this is wrong:
4397 * babeltrace --names=all -o ctf --output=/tmp/path my-trace
4399 * because --names=all implies -o text, and --output
4400 * could apply to both the sink.text.pretty and
4401 * sink.ctf.fs implicit components.
4403 if (implicit_text_args
.exists
) {
4404 printf_err("Ambiguous --output option: --output-format=ctf specified but another option implies --output-format=text\n");
4410 * If -o dummy and -o ctf were not specified, and if there are
4411 * no explicit sink components, then use an implicit
4412 * `sink.text.pretty` component.
4414 if (!implicit_dummy_args
.exists
&& !implicit_ctf_output_args
.exists
&&
4416 implicit_text_args
.exists
= true;
4420 * Set implicit `sink.text.pretty` or `sink.ctf.fs` component's
4421 * `path` parameter if --output was specified.
4424 if (implicit_text_args
.exists
) {
4425 append_implicit_component_extra_param(&implicit_text_args
,
4427 } else if (implicit_ctf_output_args
.exists
) {
4428 append_implicit_component_extra_param(&implicit_ctf_output_args
,
4433 /* Decide where the leftover argument(s) go */
4434 if (g_list_length(leftovers
) > 0) {
4435 if (implicit_lttng_live_args
.exists
) {
4436 GString
*gs_leftover
;
4438 if (g_list_length(leftovers
) > 1) {
4439 printf_err("Too many URLs specified for --output-format=lttng-live\n");
4443 gs_leftover
= leftovers
->data
;
4444 lttng_live_url_parts
=
4445 bt_common_parse_lttng_live_url(gs_leftover
->str
,
4446 error_buf
, sizeof(error_buf
));
4447 if (!lttng_live_url_parts
.proto
) {
4448 printf_err("Invalid LTTng live URL format: %s\n",
4453 if (!lttng_live_url_parts
.session_name
) {
4454 /* Print LTTng live sessions */
4455 cfg
= bt_config_print_lttng_live_sessions_create(
4461 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4466 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
4473 ret
= append_implicit_component_extra_param(
4474 &implicit_lttng_live_args
, "url",
4481 * Append one implicit component argument set
4482 * for each leftover (souce.ctf.fs paths). Copy
4483 * the base implicit component arguments.
4484 * Note that they still have to be named later.
4486 ret
= fill_implicit_ctf_inputs_args(
4487 implicit_ctf_inputs_args
,
4488 &base_implicit_ctf_input_args
, leftovers
);
4496 * Ensure mutual exclusion between implicit `source.ctf.fs` and
4497 * `source.ctf.lttng-live` components.
4499 if (base_implicit_ctf_input_args
.exists
&&
4500 implicit_lttng_live_args
.exists
) {
4501 printf_err("Cannot create both implicit `%s` and `%s` components\n",
4502 base_implicit_ctf_input_args
.comp_arg
->str
,
4503 implicit_lttng_live_args
.comp_arg
->str
);
4508 * If the implicit `source.ctf.fs` or `source.ctf.lttng-live`
4509 * components exists, make sure there's at least one leftover
4510 * (which is the path or URL).
4512 if (base_implicit_ctf_input_args
.exists
&&
4513 g_list_length(leftovers
) == 0) {
4514 printf_err("Missing path for implicit `%s` component\n",
4515 base_implicit_ctf_input_args
.comp_arg
->str
);
4519 if (implicit_lttng_live_args
.exists
&& g_list_length(leftovers
) == 0) {
4520 printf_err("Missing URL for implicit `%s` component\n",
4521 implicit_lttng_live_args
.comp_arg
->str
);
4525 /* Assign names to implicit components */
4526 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4527 struct implicit_component_args
*impl_args
=
4528 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4530 ret
= assign_name_to_implicit_component(impl_args
,
4531 "source-ctf-fs", all_names
, &source_names
, true);
4537 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4538 "lttng-live", all_names
, &source_names
, true);
4543 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4544 "pretty", all_names
, &sink_names
, true);
4549 ret
= assign_name_to_implicit_component(&implicit_ctf_output_args
,
4550 "sink-ctf-fs", all_names
, &sink_names
, true);
4555 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4556 "dummy", all_names
, &sink_names
, true);
4561 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4562 "muxer", all_names
, NULL
, false);
4567 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4568 "trimmer", all_names
, NULL
, false);
4573 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4574 "debug-info", all_names
, NULL
, false);
4579 /* Make sure there's at least one source and one sink */
4580 if (!source_names
) {
4581 printf_err("No source component\n");
4586 printf_err("No sink component\n");
4591 * Prepend the muxer, the trimmer, and the debug info to the
4592 * filter chain so that we have:
4594 * sources -> muxer -> [trimmer] -> [debug info] ->
4595 * [user filters] -> sinks
4597 if (implicit_debug_info_args
.exists
) {
4598 if (g_list_prepend_gstring(&filter_names
,
4599 implicit_debug_info_args
.name_arg
->str
)) {
4604 if (implicit_trimmer_args
.exists
) {
4605 if (g_list_prepend_gstring(&filter_names
,
4606 implicit_trimmer_args
.name_arg
->str
)) {
4611 if (g_list_prepend_gstring(&filter_names
,
4612 implicit_muxer_args
.name_arg
->str
)) {
4617 * Append the equivalent run arguments for the implicit
4620 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4621 struct implicit_component_args
*impl_args
=
4622 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4624 ret
= append_run_args_for_implicit_component(impl_args
,
4631 ret
= append_run_args_for_implicit_component(&implicit_lttng_live_args
,
4637 ret
= append_run_args_for_implicit_component(&implicit_text_args
,
4643 ret
= append_run_args_for_implicit_component(&implicit_ctf_output_args
,
4649 ret
= append_run_args_for_implicit_component(&implicit_dummy_args
,
4655 ret
= append_run_args_for_implicit_component(&implicit_muxer_args
,
4661 ret
= append_run_args_for_implicit_component(&implicit_trimmer_args
,
4667 ret
= append_run_args_for_implicit_component(&implicit_debug_info_args
,
4673 /* Auto-connect components */
4674 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4677 printf_err("Cannot auto-connect components\n");
4682 * We have all the run command arguments now. Depending on
4683 * --run-args, we pass this to the run command or print them
4686 if (print_run_args
|| print_run_args_0
) {
4687 if (stream_intersection_mode
) {
4688 printf_err("Cannot specify --stream-intersection with --run-args or --run-args-0\n");
4692 for (i
= 0; i
< bt_value_array_get_size(
4693 bt_private_value_as_value(run_args
)); i
++) {
4694 struct bt_value
*arg_value
=
4695 bt_value_array_borrow_element_by_index(
4696 bt_private_value_as_value(run_args
),
4699 GString
*quoted
= NULL
;
4700 const char *arg_to_print
;
4702 BT_ASSERT(arg_value
);
4703 arg
= bt_value_string_get(arg_value
);
4705 if (print_run_args
) {
4706 quoted
= bt_common_shell_quote(arg
, true);
4711 arg_to_print
= quoted
->str
;
4716 printf("%s", arg_to_print
);
4719 g_string_free(quoted
, TRUE
);
4722 if (i
< bt_value_array_get_size(
4723 bt_private_value_as_value(run_args
)) - 1) {
4724 if (print_run_args
) {
4733 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4737 cfg
= bt_config_run_from_args_array(
4738 bt_private_value_as_value(run_args
), retcode
,
4739 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
4740 initial_plugin_paths
);
4745 cfg
->cmd_data
.run
.stream_intersection_mode
= stream_intersection_mode
;
4750 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4754 poptFreeContext(pc
);
4761 g_string_free(cur_name
, TRUE
);
4764 if (cur_name_prefix
) {
4765 g_string_free(cur_name_prefix
, TRUE
);
4768 if (implicit_ctf_inputs_args
) {
4769 g_ptr_array_free(implicit_ctf_inputs_args
, TRUE
);
4772 bt_object_put_ref(run_args
);
4773 bt_object_put_ref(all_names
);
4774 destroy_glist_of_gstring(source_names
);
4775 destroy_glist_of_gstring(filter_names
);
4776 destroy_glist_of_gstring(sink_names
);
4777 destroy_glist_of_gstring(leftovers
);
4778 finalize_implicit_component_args(&base_implicit_ctf_input_args
);
4779 finalize_implicit_component_args(&implicit_ctf_output_args
);
4780 finalize_implicit_component_args(&implicit_lttng_live_args
);
4781 finalize_implicit_component_args(&implicit_dummy_args
);
4782 finalize_implicit_component_args(&implicit_text_args
);
4783 finalize_implicit_component_args(&implicit_debug_info_args
);
4784 finalize_implicit_component_args(&implicit_muxer_args
);
4785 finalize_implicit_component_args(&implicit_trimmer_args
);
4786 bt_object_put_ref(plugin_paths
);
4787 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4792 * Prints the Babeltrace 2.x general usage.
4795 void print_gen_usage(FILE *fp
)
4797 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4799 fprintf(fp
, "General options:\n");
4801 fprintf(fp
, " -d, --debug Enable debug mode (same as --log-level=V)\n");
4802 fprintf(fp
, " -h, --help Show this help and quit\n");
4803 fprintf(fp
, " -l, --log-level=LVL Set all log levels to LVL (`N`, `V`, `D`,\n");
4804 fprintf(fp
, " `I`, `W` (default), `E`, or `F`)\n");
4805 fprintf(fp
, " -v, --verbose Enable verbose mode (same as --log-level=I)\n");
4806 fprintf(fp
, " -V, --version Show version and quit\n");
4808 fprintf(fp
, "Available commands:\n");
4810 fprintf(fp
, " convert Convert and trim traces (default)\n");
4811 fprintf(fp
, " help Get help for a plugin or a component class\n");
4812 fprintf(fp
, " list-plugins List available plugins and their content\n");
4813 fprintf(fp
, " query Query objects from a component class\n");
4814 fprintf(fp
, " run Build a processing graph and run it\n");
4816 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4820 char log_level_from_arg(const char *arg
)
4824 if (strcmp(arg
, "VERBOSE") == 0 ||
4825 strcmp(arg
, "V") == 0) {
4827 } else if (strcmp(arg
, "DEBUG") == 0 ||
4828 strcmp(arg
, "D") == 0) {
4830 } else if (strcmp(arg
, "INFO") == 0 ||
4831 strcmp(arg
, "I") == 0) {
4833 } else if (strcmp(arg
, "WARN") == 0 ||
4834 strcmp(arg
, "WARNING") == 0 ||
4835 strcmp(arg
, "W") == 0) {
4837 } else if (strcmp(arg
, "ERROR") == 0 ||
4838 strcmp(arg
, "E") == 0) {
4840 } else if (strcmp(arg
, "FATAL") == 0 ||
4841 strcmp(arg
, "F") == 0) {
4843 } else if (strcmp(arg
, "NONE") == 0 ||
4844 strcmp(arg
, "N") == 0) {
4851 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4852 int *retcode
, bool force_omit_system_plugin_path
,
4853 bool force_omit_home_plugin_path
,
4854 struct bt_private_value
*initial_plugin_paths
)
4856 struct bt_config
*config
= NULL
;
4858 const char **command_argv
= NULL
;
4859 int command_argc
= -1;
4860 const char *command_name
= NULL
;
4861 char log_level
= 'U';
4864 COMMAND_TYPE_NONE
= -1,
4865 COMMAND_TYPE_RUN
= 0,
4866 COMMAND_TYPE_CONVERT
,
4867 COMMAND_TYPE_LIST_PLUGINS
,
4870 } command_type
= COMMAND_TYPE_NONE
;
4874 if (!initial_plugin_paths
) {
4875 initial_plugin_paths
= bt_private_value_array_create();
4876 if (!initial_plugin_paths
) {
4881 bt_object_get_ref(initial_plugin_paths
);
4887 print_gen_usage(stdout
);
4891 for (i
= 1; i
< argc
; i
++) {
4892 const char *cur_arg
= argv
[i
];
4893 const char *next_arg
= i
== (argc
- 1) ? NULL
: argv
[i
+ 1];
4895 if (strcmp(cur_arg
, "-d") == 0 ||
4896 strcmp(cur_arg
, "--debug") == 0) {
4898 } else if (strcmp(cur_arg
, "-v") == 0 ||
4899 strcmp(cur_arg
, "--verbose") == 0) {
4900 if (log_level
!= 'V' && log_level
!= 'D') {
4902 * Legacy: do not override a previous
4903 * --debug because --verbose and --debug
4904 * can be specified together (in this
4905 * case we want the lowest log level to
4910 } else if (strcmp(cur_arg
, "--log-level") == 0 ||
4911 strcmp(cur_arg
, "-l") == 0) {
4913 printf_err("Missing log level value for --log-level option\n");
4918 log_level
= log_level_from_arg(next_arg
);
4919 if (log_level
== 'U') {
4920 printf_err("Invalid argument for --log-level option:\n %s\n",
4927 } else if (strncmp(cur_arg
, "--log-level=", 12) == 0) {
4928 const char *arg
= &cur_arg
[12];
4930 log_level
= log_level_from_arg(arg
);
4931 if (log_level
== 'U') {
4932 printf_err("Invalid argument for --log-level option:\n %s\n",
4937 } else if (strncmp(cur_arg
, "-l", 2) == 0) {
4938 const char *arg
= &cur_arg
[2];
4940 log_level
= log_level_from_arg(arg
);
4941 if (log_level
== 'U') {
4942 printf_err("Invalid argument for --log-level option:\n %s\n",
4947 } else if (strcmp(cur_arg
, "-V") == 0 ||
4948 strcmp(cur_arg
, "--version") == 0) {
4951 } else if (strcmp(cur_arg
, "-h") == 0 ||
4952 strcmp(cur_arg
, "--help") == 0) {
4953 print_gen_usage(stdout
);
4957 * First unknown argument: is it a known command
4960 command_argv
= &argv
[i
];
4961 command_argc
= argc
- i
;
4963 if (strcmp(cur_arg
, "convert") == 0) {
4964 command_type
= COMMAND_TYPE_CONVERT
;
4965 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4966 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4967 } else if (strcmp(cur_arg
, "help") == 0) {
4968 command_type
= COMMAND_TYPE_HELP
;
4969 } else if (strcmp(cur_arg
, "query") == 0) {
4970 command_type
= COMMAND_TYPE_QUERY
;
4971 } else if (strcmp(cur_arg
, "run") == 0) {
4972 command_type
= COMMAND_TYPE_RUN
;
4975 * Unknown argument, but not a known
4976 * command name: assume the default
4977 * `convert` command.
4979 command_type
= COMMAND_TYPE_CONVERT
;
4980 command_name
= "convert";
4981 command_argv
= &argv
[i
- 1];
4982 command_argc
= argc
- i
+ 1;
4988 if (command_type
== COMMAND_TYPE_NONE
) {
4990 * We only got non-help, non-version general options
4991 * like --verbose and --debug, without any other
4992 * arguments, so we can't do anything useful: print the
4995 print_gen_usage(stdout
);
4999 BT_ASSERT(command_argv
);
5000 BT_ASSERT(command_argc
>= 0);
5002 switch (command_type
) {
5003 case COMMAND_TYPE_RUN
:
5004 config
= bt_config_run_from_args(command_argc
, command_argv
,
5005 retcode
, force_omit_system_plugin_path
,
5006 force_omit_home_plugin_path
, initial_plugin_paths
);
5008 case COMMAND_TYPE_CONVERT
:
5009 config
= bt_config_convert_from_args(command_argc
, command_argv
,
5010 retcode
, force_omit_system_plugin_path
,
5011 force_omit_home_plugin_path
,
5012 initial_plugin_paths
, &log_level
);
5014 case COMMAND_TYPE_LIST_PLUGINS
:
5015 config
= bt_config_list_plugins_from_args(command_argc
,
5016 command_argv
, retcode
, force_omit_system_plugin_path
,
5017 force_omit_home_plugin_path
, initial_plugin_paths
);
5019 case COMMAND_TYPE_HELP
:
5020 config
= bt_config_help_from_args(command_argc
,
5021 command_argv
, retcode
, force_omit_system_plugin_path
,
5022 force_omit_home_plugin_path
, initial_plugin_paths
);
5024 case COMMAND_TYPE_QUERY
:
5025 config
= bt_config_query_from_args(command_argc
,
5026 command_argv
, retcode
, force_omit_system_plugin_path
,
5027 force_omit_home_plugin_path
, initial_plugin_paths
);
5034 if (log_level
== 'U') {
5038 config
->log_level
= log_level
;
5039 config
->command_name
= command_name
;
5043 bt_object_put_ref(initial_plugin_paths
);