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
= bt_object_get_ref(initial_plugin_paths
);
1521 cfg
->plugin_paths
= bt_private_value_array_create();
1522 if (!cfg
->plugin_paths
) {
1531 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1538 struct bt_config
*bt_config_run_create(
1539 struct bt_private_value
*initial_plugin_paths
)
1541 struct bt_config
*cfg
;
1544 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1545 initial_plugin_paths
, true);
1550 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1551 (GDestroyNotify
) bt_object_put_ref
);
1552 if (!cfg
->cmd_data
.run
.sources
) {
1557 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1558 (GDestroyNotify
) bt_object_put_ref
);
1559 if (!cfg
->cmd_data
.run
.filters
) {
1564 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1565 (GDestroyNotify
) bt_object_put_ref
);
1566 if (!cfg
->cmd_data
.run
.sinks
) {
1571 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1572 (GDestroyNotify
) bt_config_connection_destroy
);
1573 if (!cfg
->cmd_data
.run
.connections
) {
1581 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1588 struct bt_config
*bt_config_list_plugins_create(
1589 struct bt_private_value
*initial_plugin_paths
)
1591 struct bt_config
*cfg
;
1594 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1595 initial_plugin_paths
, true);
1603 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1610 struct bt_config
*bt_config_help_create(
1611 struct bt_private_value
*initial_plugin_paths
)
1613 struct bt_config
*cfg
;
1616 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1617 initial_plugin_paths
, true);
1622 cfg
->cmd_data
.help
.cfg_component
=
1623 bt_config_component_create(-1, NULL
, NULL
);
1624 if (!cfg
->cmd_data
.help
.cfg_component
) {
1631 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1638 struct bt_config
*bt_config_query_create(
1639 struct bt_private_value
*initial_plugin_paths
)
1641 struct bt_config
*cfg
;
1644 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1645 initial_plugin_paths
, true);
1650 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1651 if (!cfg
->cmd_data
.query
.object
) {
1659 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1666 struct bt_config
*bt_config_print_ctf_metadata_create(
1667 struct bt_private_value
*initial_plugin_paths
)
1669 struct bt_config
*cfg
;
1672 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1673 initial_plugin_paths
, true);
1678 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1679 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1684 cfg
->cmd_data
.print_ctf_metadata
.output_path
= g_string_new(NULL
);
1685 if (!cfg
->cmd_data
.print_ctf_metadata
.output_path
) {
1693 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1700 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1701 struct bt_private_value
*initial_plugin_paths
)
1703 struct bt_config
*cfg
;
1706 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1707 initial_plugin_paths
, true);
1712 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1713 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1718 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
=
1720 if (!cfg
->cmd_data
.print_lttng_live_sessions
.output_path
) {
1728 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1735 int bt_config_append_plugin_paths_check_setuid_setgid(
1736 struct bt_private_value
*plugin_paths
, const char *arg
)
1740 if (bt_common_is_setuid_setgid()) {
1741 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1745 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1746 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1757 * Prints the expected format for a --params option.
1760 void print_expected_params_format(FILE *fp
)
1762 fprintf(fp
, "Expected format of PARAMS\n");
1763 fprintf(fp
, "-------------------------\n");
1765 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1767 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1768 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1769 fprintf(fp
, "and VALUE can be one of:\n");
1771 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1772 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1773 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1774 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1775 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1776 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1777 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1778 fprintf(fp
, " the null and boolean value symbols above.\n");
1779 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1781 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1783 fprintf(fp
, "Example:\n");
1785 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1786 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1787 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1789 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1790 fprintf(fp
, "babeltrace from a shell.\n");
1795 * Prints the help command usage.
1798 void print_help_usage(FILE *fp
)
1800 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1801 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] TYPE.PLUGIN.CLS\n");
1803 fprintf(fp
, "Options:\n");
1805 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1806 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1807 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1808 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1809 fprintf(fp
, " dynamic plugins can be loaded\n");
1810 fprintf(fp
, " -h, --help Show this help and quit\n");
1812 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1814 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1818 struct poptOption help_long_options
[] = {
1819 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1820 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1821 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1822 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1823 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1824 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1828 * Creates a Babeltrace config object from the arguments of a help
1831 * *retcode is set to the appropriate exit code to use.
1834 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1835 int *retcode
, bool force_omit_system_plugin_path
,
1836 bool force_omit_home_plugin_path
,
1837 struct bt_private_value
*initial_plugin_paths
)
1839 poptContext pc
= NULL
;
1843 struct bt_config
*cfg
= NULL
;
1844 const char *leftover
;
1845 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1848 cfg
= bt_config_help_create(initial_plugin_paths
);
1853 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1854 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1855 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1861 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1862 help_long_options
, 0);
1864 printf_err("Cannot get popt context\n");
1868 poptReadDefaultConfig(pc
, 0);
1870 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1871 arg
= poptGetOptArg(pc
);
1874 case OPT_PLUGIN_PATH
:
1875 if (bt_config_append_plugin_paths_check_setuid_setgid(
1876 cfg
->plugin_paths
, arg
)) {
1880 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1881 cfg
->omit_system_plugin_path
= true;
1883 case OPT_OMIT_HOME_PLUGIN_PATH
:
1884 cfg
->omit_home_plugin_path
= true;
1887 print_help_usage(stdout
);
1889 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1892 printf_err("Unknown command-line option specified (option code %d)\n",
1901 /* Check for option parsing error */
1903 printf_err("While parsing command-line options, at option %s: %s\n",
1904 poptBadOption(pc
, 0), poptStrerror(opt
));
1908 leftover
= poptGetArg(pc
);
1910 plugin_comp_cls_names(leftover
, NULL
,
1911 &plugin_name
, &comp_cls_name
,
1912 &cfg
->cmd_data
.help
.cfg_component
->type
);
1913 if (plugin_name
&& comp_cls_name
) {
1914 /* Component class help */
1916 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1919 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1922 /* Fall back to plugin help */
1924 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1928 print_help_usage(stdout
);
1930 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1934 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1942 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1945 g_free(plugin_name
);
1946 g_free(comp_cls_name
);
1949 poptFreeContext(pc
);
1957 * Prints the help command usage.
1960 void print_query_usage(FILE *fp
)
1962 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] TYPE.PLUGIN.CLS OBJECT\n");
1964 fprintf(fp
, "Options:\n");
1966 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1967 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1968 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1969 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1970 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1971 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1972 fprintf(fp
, " dynamic plugins can be loaded\n");
1973 fprintf(fp
, " -h, --help Show this help and quit\n");
1974 fprintf(fp
, "\n\n");
1975 print_expected_params_format(fp
);
1979 struct poptOption query_long_options
[] = {
1980 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1981 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1982 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1983 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1984 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1985 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1986 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1990 * Creates a Babeltrace config object from the arguments of a query
1993 * *retcode is set to the appropriate exit code to use.
1996 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
1997 int *retcode
, bool force_omit_system_plugin_path
,
1998 bool force_omit_home_plugin_path
,
1999 struct bt_private_value
*initial_plugin_paths
)
2001 poptContext pc
= NULL
;
2005 struct bt_config
*cfg
= NULL
;
2006 const char *leftover
;
2007 struct bt_private_value
*params
= bt_private_value_null
;
2010 cfg
= bt_config_query_create(initial_plugin_paths
);
2015 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2016 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2017 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2023 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2024 query_long_options
, 0);
2026 printf_err("Cannot get popt context\n");
2030 poptReadDefaultConfig(pc
, 0);
2032 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2033 arg
= poptGetOptArg(pc
);
2036 case OPT_PLUGIN_PATH
:
2037 if (bt_config_append_plugin_paths_check_setuid_setgid(
2038 cfg
->plugin_paths
, arg
)) {
2042 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2043 cfg
->omit_system_plugin_path
= true;
2045 case OPT_OMIT_HOME_PLUGIN_PATH
:
2046 cfg
->omit_home_plugin_path
= true;
2050 bt_object_put_ref(params
);
2051 params
= bt_private_value_from_arg(arg
);
2053 printf_err("Invalid format for --params option's argument:\n %s\n",
2060 print_query_usage(stdout
);
2062 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2065 printf_err("Unknown command-line option specified (option code %d)\n",
2074 /* Check for option parsing error */
2076 printf_err("While parsing command-line options, at option %s: %s\n",
2077 poptBadOption(pc
, 0), poptStrerror(opt
));
2082 * We need exactly two leftover arguments which are the
2083 * mandatory component class specification and query object.
2085 leftover
= poptGetArg(pc
);
2087 cfg
->cmd_data
.query
.cfg_component
=
2088 bt_config_component_from_arg(leftover
);
2089 if (!cfg
->cmd_data
.query
.cfg_component
) {
2090 printf_err("Invalid format for component class specification:\n %s\n",
2096 BT_OBJECT_MOVE_REF(cfg
->cmd_data
.query
.cfg_component
->params
,
2099 print_query_usage(stdout
);
2101 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2105 leftover
= poptGetArg(pc
);
2107 if (strlen(leftover
) == 0) {
2108 printf_err("Invalid empty object\n");
2112 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2114 print_query_usage(stdout
);
2116 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2120 leftover
= poptGetArg(pc
);
2122 printf_err("Unexpected argument: %s\n", leftover
);
2126 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2134 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2138 poptFreeContext(pc
);
2141 bt_object_put_ref(params
);
2147 * Prints the list-plugins command usage.
2150 void print_list_plugins_usage(FILE *fp
)
2152 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2154 fprintf(fp
, "Options:\n");
2156 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2157 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2158 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2159 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2160 fprintf(fp
, " dynamic plugins can be loaded\n");
2161 fprintf(fp
, " -h, --help Show this help and quit\n");
2163 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2165 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2169 struct poptOption list_plugins_long_options
[] = {
2170 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2171 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2172 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2173 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2174 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2175 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2179 * Creates a Babeltrace config object from the arguments of a
2180 * list-plugins command.
2182 * *retcode is set to the appropriate exit code to use.
2185 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2186 int *retcode
, bool force_omit_system_plugin_path
,
2187 bool force_omit_home_plugin_path
,
2188 struct bt_private_value
*initial_plugin_paths
)
2190 poptContext pc
= NULL
;
2194 struct bt_config
*cfg
= NULL
;
2195 const char *leftover
;
2198 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2203 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2204 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2205 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2211 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2212 list_plugins_long_options
, 0);
2214 printf_err("Cannot get popt context\n");
2218 poptReadDefaultConfig(pc
, 0);
2220 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2221 arg
= poptGetOptArg(pc
);
2224 case OPT_PLUGIN_PATH
:
2225 if (bt_config_append_plugin_paths_check_setuid_setgid(
2226 cfg
->plugin_paths
, arg
)) {
2230 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2231 cfg
->omit_system_plugin_path
= true;
2233 case OPT_OMIT_HOME_PLUGIN_PATH
:
2234 cfg
->omit_home_plugin_path
= true;
2237 print_list_plugins_usage(stdout
);
2239 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2242 printf_err("Unknown command-line option specified (option code %d)\n",
2251 /* Check for option parsing error */
2253 printf_err("While parsing command-line options, at option %s: %s\n",
2254 poptBadOption(pc
, 0), poptStrerror(opt
));
2258 leftover
= poptGetArg(pc
);
2260 printf_err("Unexpected argument: %s\n", leftover
);
2264 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2272 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2276 poptFreeContext(pc
);
2284 * Prints the run command usage.
2287 void print_run_usage(FILE *fp
)
2289 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2291 fprintf(fp
, "Options:\n");
2293 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2294 fprintf(fp
, " for all the following components until\n");
2295 fprintf(fp
, " --reset-base-params is encountered\n");
2296 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2297 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2298 fprintf(fp
, " Instantiate the component class CLS of type\n");
2299 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2300 fprintf(fp
, " in the plugin PLUGIN, add it to the graph,\n");
2301 fprintf(fp
, " and optionally name it NAME (you can also\n");
2302 fprintf(fp
, " specify the name with --name)\n");
2303 fprintf(fp
, " -C, --connect=CONNECTION Connect two created components (see the\n");
2304 fprintf(fp
, " expected format of CONNECTION below)\n");
2305 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2306 fprintf(fp
, " parameter key to KEY (see --value)\n");
2307 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2308 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2309 fprintf(fp
, " names of the created components)\n");
2310 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2311 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2312 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2313 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2314 fprintf(fp
, " current component (see the expected format\n");
2315 fprintf(fp
, " of PARAMS below)\n");
2316 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2317 fprintf(fp
, " dynamic plugins can be loaded\n");
2318 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2319 fprintf(fp
, " empty map\n");
2320 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2321 fprintf(fp
, " the graph later, retry in DUR µs\n");
2322 fprintf(fp
, " (default: 100000)\n");
2323 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2324 fprintf(fp
, " the current component with a name given by\n");
2325 fprintf(fp
, " the last argument of the --key option and a\n");
2326 fprintf(fp
, " value set to VAL\n");
2327 fprintf(fp
, " -h, --help Show this help and quit\n");
2329 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2330 fprintf(fp
, "\n\n");
2331 fprintf(fp
, "Expected format of CONNECTION\n");
2332 fprintf(fp
, "-----------------------------\n");
2334 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2336 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2337 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2338 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2339 fprintf(fp
, "component with the --name option.\n");
2341 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2342 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2343 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2345 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2346 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2347 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2348 fprintf(fp
, "DOWNSTREAM.\n");
2350 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2351 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2352 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2354 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2355 fprintf(fp
, "can connect a filter component to a sink component.\n");
2357 fprintf(fp
, "Examples:\n");
2359 fprintf(fp
, " my-src:my-sink\n");
2360 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2362 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2363 fprintf(fp
, "babeltrace from a shell.\n");
2364 fprintf(fp
, "\n\n");
2365 print_expected_params_format(fp
);
2369 * Creates a Babeltrace config object from the arguments of a run
2372 * *retcode is set to the appropriate exit code to use.
2375 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2376 int *retcode
, bool force_omit_system_plugin_path
,
2377 bool force_omit_home_plugin_path
,
2378 struct bt_private_value
*initial_plugin_paths
)
2380 poptContext pc
= NULL
;
2382 struct bt_config_component
*cur_cfg_comp
= NULL
;
2383 enum bt_config_component_dest cur_cfg_comp_dest
=
2384 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
2385 struct bt_private_value
*cur_base_params
= NULL
;
2387 struct bt_config
*cfg
= NULL
;
2388 struct bt_private_value
*instance_names
= NULL
;
2389 struct bt_private_value
*connection_args
= NULL
;
2390 GString
*cur_param_key
= NULL
;
2391 char error_buf
[256] = { 0 };
2392 long retry_duration
= -1;
2393 enum bt_value_status status
;
2394 struct poptOption run_long_options
[] = {
2395 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2396 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2397 { "connect", 'C', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2398 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2399 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2400 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2401 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2402 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2403 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2404 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2405 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2406 { "retry-duration", '\0', POPT_ARG_LONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2407 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2408 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2412 cur_param_key
= g_string_new(NULL
);
2413 if (!cur_param_key
) {
2419 print_run_usage(stdout
);
2424 cfg
= bt_config_run_create(initial_plugin_paths
);
2429 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2430 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2431 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2432 cur_base_params
= bt_private_value_map_create();
2433 if (!cur_base_params
) {
2438 instance_names
= bt_private_value_map_create();
2439 if (!instance_names
) {
2444 connection_args
= bt_private_value_array_create();
2445 if (!connection_args
) {
2450 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2456 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2457 run_long_options
, 0);
2459 printf_err("Cannot get popt context\n");
2463 poptReadDefaultConfig(pc
, 0);
2465 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2466 arg
= poptGetOptArg(pc
);
2469 case OPT_PLUGIN_PATH
:
2470 if (bt_config_append_plugin_paths_check_setuid_setgid(
2471 cfg
->plugin_paths
, arg
)) {
2475 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2476 cfg
->omit_system_plugin_path
= true;
2478 case OPT_OMIT_HOME_PLUGIN_PATH
:
2479 cfg
->omit_home_plugin_path
= true;
2483 enum bt_config_component_dest new_dest
;
2486 ret
= add_run_cfg_comp_check_name(cfg
,
2487 cur_cfg_comp
, cur_cfg_comp_dest
,
2489 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2495 cur_cfg_comp
= bt_config_component_from_arg(arg
);
2496 if (!cur_cfg_comp
) {
2497 printf_err("Invalid format for --component option's argument:\n %s\n",
2502 switch (cur_cfg_comp
->type
) {
2503 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
2504 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2506 case BT_COMPONENT_CLASS_TYPE_FILTER
:
2507 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2509 case BT_COMPONENT_CLASS_TYPE_SINK
:
2510 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2516 BT_ASSERT(cur_base_params
);
2517 bt_object_put_ref(cur_cfg_comp
->params
);
2518 status
= bt_value_copy(
2519 &cur_cfg_comp
->params
,
2520 bt_private_value_as_value(cur_base_params
));
2521 if (status
!= BT_VALUE_STATUS_OK
) {
2526 cur_cfg_comp_dest
= new_dest
;
2531 struct bt_private_value
*params
;
2532 struct bt_private_value
*params_to_set
;
2534 if (!cur_cfg_comp
) {
2535 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2540 params
= bt_private_value_from_arg(arg
);
2542 printf_err("Invalid format for --params option's argument:\n %s\n",
2547 status
= bt_value_map_extend(¶ms_to_set
,
2548 bt_private_value_as_value(cur_cfg_comp
->params
),
2549 bt_private_value_as_value(params
));
2550 BT_OBJECT_PUT_REF_AND_RESET(params
);
2551 if (status
!= BT_VALUE_STATUS_OK
) {
2552 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2557 BT_OBJECT_MOVE_REF(cur_cfg_comp
->params
, params_to_set
);
2561 if (strlen(arg
) == 0) {
2562 printf_err("Cannot set an empty string as the current parameter key\n");
2566 g_string_assign(cur_param_key
, arg
);
2569 if (!cur_cfg_comp
) {
2570 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2575 if (cur_param_key
->len
== 0) {
2576 printf_err("--value option specified without preceding --key option:\n %s\n",
2581 if (bt_private_value_map_insert_string_entry(cur_cfg_comp
->params
,
2582 cur_param_key
->str
, arg
)) {
2588 if (!cur_cfg_comp
) {
2589 printf_err("Cannot set the name of unavailable component:\n %s\n",
2594 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2596 case OPT_BASE_PARAMS
:
2598 struct bt_private_value
*params
=
2599 bt_private_value_from_arg(arg
);
2602 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2607 BT_OBJECT_MOVE_REF(cur_base_params
, params
);
2610 case OPT_RESET_BASE_PARAMS
:
2611 BT_OBJECT_PUT_REF_AND_RESET(cur_base_params
);
2612 cur_base_params
= bt_private_value_map_create();
2613 if (!cur_base_params
) {
2619 if (bt_private_value_array_append_string_element(
2620 connection_args
, arg
)) {
2625 case OPT_RETRY_DURATION
:
2626 if (retry_duration
< 0) {
2627 printf_err("--retry-duration option's argument must be positive or 0: %ld\n",
2632 cfg
->cmd_data
.run
.retry_duration_us
=
2633 (uint64_t) retry_duration
;
2636 print_run_usage(stdout
);
2638 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2641 printf_err("Unknown command-line option specified (option code %d)\n",
2650 /* Check for option parsing error */
2652 printf_err("While parsing command-line options, at option %s: %s\n",
2653 poptBadOption(pc
, 0), poptStrerror(opt
));
2657 /* This command does not accept leftover arguments */
2658 if (poptPeekArg(pc
)) {
2659 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2663 /* Add current component */
2665 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2666 cur_cfg_comp_dest
, instance_names
);
2667 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2673 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2674 printf_err("Incomplete graph: no source component\n");
2678 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2679 printf_err("Incomplete graph: no sink component\n");
2683 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2687 ret
= bt_config_cli_args_create_connections(cfg
,
2688 bt_private_value_as_value(connection_args
),
2691 printf_err("Cannot creation connections:\n%s", error_buf
);
2699 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2703 poptFreeContext(pc
);
2706 if (cur_param_key
) {
2707 g_string_free(cur_param_key
, TRUE
);
2711 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2712 BT_OBJECT_PUT_REF_AND_RESET(cur_base_params
);
2713 BT_OBJECT_PUT_REF_AND_RESET(instance_names
);
2714 BT_OBJECT_PUT_REF_AND_RESET(connection_args
);
2719 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2720 int *retcode
, bool force_omit_system_plugin_path
,
2721 bool force_omit_home_plugin_path
,
2722 struct bt_private_value
*initial_plugin_paths
)
2724 struct bt_config
*cfg
= NULL
;
2727 const size_t argc
= bt_value_array_get_size(run_args
) + 1;
2729 argv
= calloc(argc
, sizeof(*argv
));
2737 len
= bt_value_array_get_size(run_args
);
2739 printf_err("Invalid executable arguments\n");
2742 for (i
= 0; i
< len
; i
++) {
2743 struct bt_value
*arg_value
=
2744 bt_value_array_borrow_element_by_index(run_args
, i
);
2747 BT_ASSERT(arg_value
);
2748 arg
= bt_value_string_get(arg_value
);
2753 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2754 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2755 initial_plugin_paths
);
2763 * Prints the convert command usage.
2766 void print_convert_usage(FILE *fp
)
2768 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2770 fprintf(fp
, "Options:\n");
2772 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2773 fprintf(fp
, " Instantiate the component class CLS of type\n");
2774 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2775 fprintf(fp
, " in the plugin PLUGIN, add it to the\n");
2776 fprintf(fp
, " conversion graph, and optionally name it\n");
2777 fprintf(fp
, " NAME (you can also specify the name with\n");
2778 fprintf(fp
, " --name)\n");
2779 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2780 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2781 fprintf(fp
, " names of the created components)\n");
2782 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2783 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2784 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2785 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2786 fprintf(fp
, " current component (see the expected format\n");
2787 fprintf(fp
, " of PARAMS below)\n");
2788 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2789 fprintf(fp
, " current component to PATH\n");
2790 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2791 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2792 fprintf(fp
, " the graph later, retry in DUR µs\n");
2793 fprintf(fp
, " (default: 100000)\n");
2794 fprintf(fp
, " dynamic plugins can be loaded\n");
2795 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2796 fprintf(fp
, " `run` command to the standard output,\n");
2797 fprintf(fp
, " formatted for a shell, and quit\n");
2798 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2799 fprintf(fp
, " `run` command to the standard output,\n");
2800 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2801 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2802 fprintf(fp
, " are active\n");
2803 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2804 fprintf(fp
, " current component to URL\n");
2805 fprintf(fp
, " -h, --help Show this help and quit\n");
2807 fprintf(fp
, "Implicit `source.ctf.fs` component options:\n");
2809 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2810 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2812 fprintf(fp
, "Implicit `sink.text.pretty` component options:\n");
2814 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2815 fprintf(fp
, " --clock-date Print timestamp dates\n");
2816 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2817 fprintf(fp
, " time zone instead of the local time zone\n");
2818 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2819 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2820 fprintf(fp
, " --color=(never | auto | always)\n");
2821 fprintf(fp
, " Never, automatically, or always emit\n");
2822 fprintf(fp
, " console color codes\n");
2823 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2824 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2825 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2826 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2827 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2828 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2829 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2830 fprintf(fp
, " (or `ctx`)\n");
2831 fprintf(fp
, " --no-delta Do not print time delta between\n");
2832 fprintf(fp
, " consecutive events\n");
2833 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2834 fprintf(fp
, " the standard output\n");
2836 fprintf(fp
, "Implicit `filter.utils.muxer` component options:\n");
2838 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2839 fprintf(fp
, " correlated across traces\n");
2841 fprintf(fp
, "Implicit `filter.utils.trimmer` component options:\n");
2843 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2844 fprintf(fp
, " time range to BEGIN (see the format of\n");
2845 fprintf(fp
, " BEGIN below)\n");
2846 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2847 fprintf(fp
, " range to END (see the format of END below)\n");
2848 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2849 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2850 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2852 fprintf(fp
, "Implicit `filter.lttng-utils.debug-info` component options:\n");
2854 fprintf(fp
, " --debug-info Create an implicit\n");
2855 fprintf(fp
, " `filter.lttng-utils.debug-info` component\n");
2856 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2857 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2858 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2859 fprintf(fp
, " binary paths instead of just names\n");
2860 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2861 fprintf(fp
, " Use directory DIR as a prefix when\n");
2862 fprintf(fp
, " looking up executables during debug\n");
2863 fprintf(fp
, " info analysis\n");
2865 fprintf(fp
, "Legacy options that still work:\n");
2867 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2868 fprintf(fp
, " `ctf`:\n");
2869 fprintf(fp
, " Create an implicit `source.ctf.fs`\n");
2870 fprintf(fp
, " component\n");
2871 fprintf(fp
, " `lttng-live`:\n");
2872 fprintf(fp
, " Create an implicit `source.ctf.lttng-live`\n");
2873 fprintf(fp
, " component\n");
2874 fprintf(fp
, " -o, --output-format=(text | ctf | dummy | ctf-metadata)\n");
2875 fprintf(fp
, " `text`:\n");
2876 fprintf(fp
, " Create an implicit `sink.text.pretty`\n");
2877 fprintf(fp
, " component\n");
2878 fprintf(fp
, " `ctf`:\n");
2879 fprintf(fp
, " Create an implicit `sink.ctf.fs`\n");
2880 fprintf(fp
, " component\n");
2881 fprintf(fp
, " `dummy`:\n");
2882 fprintf(fp
, " Create an implicit `sink.utils.dummy`\n");
2883 fprintf(fp
, " component\n");
2884 fprintf(fp
, " `ctf-metadata`:\n");
2885 fprintf(fp
, " Query the `source.ctf.fs` component class\n");
2886 fprintf(fp
, " for metadata text and quit\n");
2888 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2889 fprintf(fp
, "\n\n");
2890 fprintf(fp
, "Format of BEGIN and END\n");
2891 fprintf(fp
, "-----------------------\n");
2893 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2894 fprintf(fp
, "\n\n");
2895 print_expected_params_format(fp
);
2899 struct poptOption convert_long_options
[] = {
2900 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2901 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2902 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2903 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2904 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2905 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2906 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2907 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2908 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2909 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2910 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2911 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2912 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2913 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2914 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2915 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2916 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2917 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2918 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2919 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2920 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2921 { "debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO
, NULL
, NULL
},
2922 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2923 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2924 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2925 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2926 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2927 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2928 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2929 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2930 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2931 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2932 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2933 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2934 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2935 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2936 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2937 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2941 GString
*get_component_auto_name(const char *prefix
,
2942 struct bt_value
*existing_names
)
2945 GString
*auto_name
= g_string_new(NULL
);
2952 if (!bt_value_map_has_entry(existing_names
, prefix
)) {
2953 g_string_assign(auto_name
, prefix
);
2958 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2960 } while (bt_value_map_has_entry(existing_names
, auto_name
->str
));
2966 struct implicit_component_args
{
2970 GString
*params_arg
;
2971 struct bt_private_value
*extra_params
;
2975 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
2976 const char *prefix
, struct bt_private_value
*existing_names
,
2977 GList
**comp_names
, bool append_to_comp_names
)
2980 GString
*name
= NULL
;
2982 if (!args
->exists
) {
2986 name
= get_component_auto_name(prefix
,
2987 bt_private_value_as_value(existing_names
));
2994 g_string_assign(args
->name_arg
, name
->str
);
2996 if (bt_private_value_map_insert_entry(existing_names
, name
->str
,
3003 if (append_to_comp_names
) {
3004 *comp_names
= g_list_append(*comp_names
, name
);
3010 g_string_free(name
, TRUE
);
3017 int append_run_args_for_implicit_component(
3018 struct implicit_component_args
*impl_args
,
3019 struct bt_private_value
*run_args
)
3024 if (!impl_args
->exists
) {
3028 if (bt_private_value_array_append_string_element(run_args
, "--component")) {
3033 if (bt_private_value_array_append_string_element(run_args
, impl_args
->comp_arg
->str
)) {
3038 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3043 if (bt_private_value_array_append_string_element(run_args
, impl_args
->name_arg
->str
)) {
3048 if (impl_args
->params_arg
->len
> 0) {
3049 if (bt_private_value_array_append_string_element(run_args
, "--params")) {
3054 if (bt_private_value_array_append_string_element(run_args
,
3055 impl_args
->params_arg
->str
)) {
3061 for (i
= 0; i
< bt_value_array_get_size(
3062 bt_private_value_as_value(impl_args
->extra_params
));
3064 struct bt_value
*elem
;
3067 elem
= bt_value_array_borrow_element_by_index(
3068 bt_private_value_as_value(impl_args
->extra_params
),
3074 BT_ASSERT(bt_value_is_string(elem
));
3075 arg
= bt_value_string_get(elem
);
3076 ret
= bt_private_value_array_append_string_element(run_args
, arg
);
3093 void finalize_implicit_component_args(struct implicit_component_args
*args
)
3097 if (args
->comp_arg
) {
3098 g_string_free(args
->comp_arg
, TRUE
);
3101 if (args
->name_arg
) {
3102 g_string_free(args
->name_arg
, TRUE
);
3105 if (args
->params_arg
) {
3106 g_string_free(args
->params_arg
, TRUE
);
3109 bt_object_put_ref(args
->extra_params
);
3113 void destroy_implicit_component_args(void *args
)
3119 finalize_implicit_component_args(args
);
3124 int init_implicit_component_args(struct implicit_component_args
*args
,
3125 const char *comp_arg
, bool exists
)
3129 args
->exists
= exists
;
3130 args
->comp_arg
= g_string_new(comp_arg
);
3131 args
->name_arg
= g_string_new(NULL
);
3132 args
->params_arg
= g_string_new(NULL
);
3133 args
->extra_params
= bt_private_value_array_create();
3135 if (!args
->comp_arg
|| !args
->name_arg
||
3136 !args
->params_arg
|| !args
->extra_params
) {
3138 finalize_implicit_component_args(args
);
3148 void append_implicit_component_param(struct implicit_component_args
*args
,
3149 const char *key
, const char *value
)
3154 append_param_arg(args
->params_arg
, key
, value
);
3158 int append_implicit_component_extra_param(struct implicit_component_args
*args
,
3159 const char *key
, const char *value
)
3167 if (bt_private_value_array_append_string_element(args
->extra_params
, "--key")) {
3173 if (bt_private_value_array_append_string_element(args
->extra_params
, key
)) {
3179 if (bt_private_value_array_append_string_element(args
->extra_params
, "--value")) {
3185 if (bt_private_value_array_append_string_element(args
->extra_params
, value
)) {
3196 int convert_append_name_param(enum bt_config_component_dest dest
,
3197 GString
*cur_name
, GString
*cur_name_prefix
,
3198 struct bt_private_value
*run_args
,
3199 struct bt_private_value
*all_names
,
3200 GList
**source_names
, GList
**filter_names
,
3205 if (cur_name_prefix
->len
> 0) {
3206 /* We're after a --component option */
3207 GString
*name
= NULL
;
3208 bool append_name_opt
= false;
3210 if (cur_name
->len
== 0) {
3212 * No explicit name was provided for the user
3215 name
= get_component_auto_name(cur_name_prefix
->str
,
3216 bt_private_value_as_value(all_names
));
3217 append_name_opt
= true;
3220 * An explicit name was provided for the user
3223 if (bt_value_map_has_entry(
3224 bt_private_value_as_value(all_names
),
3226 printf_err("Duplicate component instance name:\n %s\n",
3231 name
= g_string_new(cur_name
->str
);
3240 * Remember this name globally, for the uniqueness of
3241 * all component names.
3243 if (bt_private_value_map_insert_entry(all_names
, name
->str
, bt_value_null
)) {
3249 * Append the --name option if necessary.
3251 if (append_name_opt
) {
3252 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3257 if (bt_private_value_array_append_string_element(run_args
, name
->str
)) {
3264 * Remember this name specifically for the type of the
3265 * component. This is to create connection arguments.
3268 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3269 *source_names
= g_list_append(*source_names
, name
);
3271 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3272 *filter_names
= g_list_append(*filter_names
, name
);
3274 case BT_CONFIG_COMPONENT_DEST_SINK
:
3275 *sink_names
= g_list_append(*sink_names
, name
);
3281 g_string_assign(cur_name_prefix
, "");
3294 * Escapes `.`, `:`, and `\` of `input` with `\`.
3297 GString
*escape_dot_colon(const char *input
)
3299 GString
*output
= g_string_new(NULL
);
3307 for (ch
= input
; *ch
!= '\0'; ch
++) {
3308 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3309 g_string_append_c(output
, '\\');
3312 g_string_append_c(output
, *ch
);
3320 * Appends a --connect option to a list of arguments. `upstream_name`
3321 * and `downstream_name` are escaped with escape_dot_colon() in this
3325 int append_connect_arg(struct bt_private_value
*run_args
,
3326 const char *upstream_name
, const char *downstream_name
)
3329 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3330 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3331 GString
*arg
= g_string_new(NULL
);
3333 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3339 ret
= bt_private_value_array_append_string_element(run_args
, "--connect");
3346 g_string_append(arg
, e_upstream_name
->str
);
3347 g_string_append_c(arg
, ':');
3348 g_string_append(arg
, e_downstream_name
->str
);
3349 ret
= bt_private_value_array_append_string_element(run_args
, arg
->str
);
3358 g_string_free(arg
, TRUE
);
3361 if (e_upstream_name
) {
3362 g_string_free(e_upstream_name
, TRUE
);
3365 if (e_downstream_name
) {
3366 g_string_free(e_downstream_name
, TRUE
);
3373 * Appends the run command's --connect options for the convert command.
3376 int convert_auto_connect(struct bt_private_value
*run_args
,
3377 GList
*source_names
, GList
*filter_names
,
3381 GList
*source_at
= source_names
;
3382 GList
*filter_at
= filter_names
;
3384 GList
*sink_at
= sink_names
;
3386 BT_ASSERT(source_names
);
3387 BT_ASSERT(filter_names
);
3388 BT_ASSERT(sink_names
);
3390 /* Connect all sources to the first filter */
3391 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3392 GString
*source_name
= source_at
->data
;
3393 GString
*filter_name
= filter_at
->data
;
3395 ret
= append_connect_arg(run_args
, source_name
->str
,
3402 filter_prev
= filter_at
;
3403 filter_at
= g_list_next(filter_at
);
3405 /* Connect remaining filters */
3406 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3407 GString
*filter_name
= filter_at
->data
;
3408 GString
*filter_prev_name
= filter_prev
->data
;
3410 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3417 /* Connect last filter to all sinks */
3418 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3419 GString
*filter_name
= filter_prev
->data
;
3420 GString
*sink_name
= sink_at
->data
;
3422 ret
= append_connect_arg(run_args
, filter_name
->str
,
3439 int split_timerange(const char *arg
, char **begin
, char **end
)
3442 const char *ch
= arg
;
3444 GString
*g_begin
= NULL
;
3445 GString
*g_end
= NULL
;
3453 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3454 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3460 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3461 if (!g_end
|| g_end
->len
== 0) {
3467 *begin
= g_begin
->str
;
3469 g_string_free(g_begin
, FALSE
);
3470 g_string_free(g_end
, FALSE
);
3480 g_string_free(g_begin
, TRUE
);
3484 g_string_free(g_end
, TRUE
);
3491 int g_list_prepend_gstring(GList
**list
, const char *string
)
3494 GString
*gs
= g_string_new(string
);
3503 *list
= g_list_prepend(*list
, gs
);
3510 struct implicit_component_args
*create_implicit_component_args(void)
3512 struct implicit_component_args
*impl_args
=
3513 g_new0(struct implicit_component_args
, 1);
3519 if (init_implicit_component_args(impl_args
, NULL
, true)) {
3520 destroy_implicit_component_args(impl_args
);
3530 int fill_implicit_ctf_inputs_args(GPtrArray
*implicit_ctf_inputs_args
,
3531 struct implicit_component_args
*base_implicit_ctf_input_args
,
3536 enum bt_value_status status
;
3538 for (leftover
= leftovers
; leftover
!= NULL
;
3539 leftover
= g_list_next(leftover
)) {
3540 GString
*gs_leftover
= leftover
->data
;
3541 struct implicit_component_args
*impl_args
=
3542 create_implicit_component_args();
3549 impl_args
->exists
= true;
3550 g_string_assign(impl_args
->comp_arg
,
3551 base_implicit_ctf_input_args
->comp_arg
->str
);
3552 g_string_assign(impl_args
->params_arg
,
3553 base_implicit_ctf_input_args
->params_arg
->str
);
3556 * We need our own copy of the extra parameters because
3557 * this is where the unique path goes.
3559 BT_OBJECT_PUT_REF_AND_RESET(impl_args
->extra_params
);
3560 status
= bt_value_copy(&impl_args
->extra_params
,
3561 bt_private_value_as_value(
3562 base_implicit_ctf_input_args
->extra_params
));
3563 if (status
!= BT_VALUE_STATUS_OK
) {
3565 destroy_implicit_component_args(impl_args
);
3569 /* Append unique path parameter */
3570 ret
= append_implicit_component_extra_param(impl_args
,
3571 "path", gs_leftover
->str
);
3573 destroy_implicit_component_args(impl_args
);
3577 g_ptr_array_add(implicit_ctf_inputs_args
, impl_args
);
3590 * Creates a Babeltrace config object from the arguments of a convert
3593 * *retcode is set to the appropriate exit code to use.
3596 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3597 int *retcode
, bool force_omit_system_plugin_path
,
3598 bool force_omit_home_plugin_path
,
3599 struct bt_private_value
*initial_plugin_paths
, char *log_level
)
3601 poptContext pc
= NULL
;
3603 enum bt_config_component_dest cur_comp_dest
=
3604 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3606 struct bt_config
*cfg
= NULL
;
3607 bool got_input_format_opt
= false;
3608 bool got_output_format_opt
= false;
3609 bool trimmer_has_begin
= false;
3610 bool trimmer_has_end
= false;
3611 bool stream_intersection_mode
= false;
3612 GString
*cur_name
= NULL
;
3613 GString
*cur_name_prefix
= NULL
;
3614 const char *leftover
= NULL
;
3615 bool print_run_args
= false;
3616 bool print_run_args_0
= false;
3617 bool print_ctf_metadata
= false;
3618 struct bt_private_value
*run_args
= NULL
;
3619 struct bt_private_value
*all_names
= NULL
;
3620 GList
*source_names
= NULL
;
3621 GList
*filter_names
= NULL
;
3622 GList
*sink_names
= NULL
;
3623 GList
*leftovers
= NULL
;
3624 GPtrArray
*implicit_ctf_inputs_args
= NULL
;
3625 struct implicit_component_args base_implicit_ctf_input_args
= { 0 };
3626 struct implicit_component_args implicit_ctf_output_args
= { 0 };
3627 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3628 struct implicit_component_args implicit_dummy_args
= { 0 };
3629 struct implicit_component_args implicit_text_args
= { 0 };
3630 struct implicit_component_args implicit_debug_info_args
= { 0 };
3631 struct implicit_component_args implicit_muxer_args
= { 0 };
3632 struct implicit_component_args implicit_trimmer_args
= { 0 };
3633 struct bt_private_value
*plugin_paths
=
3634 bt_object_get_ref(initial_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
;
3643 print_convert_usage(stdout
);
3648 if (init_implicit_component_args(&base_implicit_ctf_input_args
,
3649 "source.ctf.fs", false)) {
3653 if (init_implicit_component_args(&implicit_ctf_output_args
,
3654 "sink.ctf.fs", false)) {
3658 if (init_implicit_component_args(&implicit_lttng_live_args
,
3659 "source.ctf.lttng-live", false)) {
3663 if (init_implicit_component_args(&implicit_text_args
,
3664 "sink.text.pretty", false)) {
3668 if (init_implicit_component_args(&implicit_dummy_args
,
3669 "sink.utils.dummy", false)) {
3673 if (init_implicit_component_args(&implicit_debug_info_args
,
3674 "filter.lttng-utils.debug-info", false)) {
3678 if (init_implicit_component_args(&implicit_muxer_args
,
3679 "filter.utils.muxer", true)) {
3683 if (init_implicit_component_args(&implicit_trimmer_args
,
3684 "filter.utils.trimmer", false)) {
3688 implicit_ctf_inputs_args
= g_ptr_array_new_with_free_func(
3689 (GDestroyNotify
) destroy_implicit_component_args
);
3690 if (!implicit_ctf_inputs_args
) {
3695 all_names
= bt_private_value_map_create();
3701 run_args
= bt_private_value_array_create();
3707 cur_name
= g_string_new(NULL
);
3713 cur_name_prefix
= g_string_new(NULL
);
3714 if (!cur_name_prefix
) {
3719 ret
= append_env_var_plugin_paths(plugin_paths
);
3725 * First pass: collect all arguments which need to be passed
3726 * as is to the run command. This pass can also add --name
3727 * arguments if needed to automatically name unnamed component
3728 * instances. Also it does the following transformations:
3730 * --path=PATH -> --key path --value PATH
3731 * --url=URL -> --key url --value URL
3733 * Also it appends the plugin paths of --plugin-path to
3736 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3737 convert_long_options
, 0);
3739 printf_err("Cannot get popt context\n");
3743 poptReadDefaultConfig(pc
, 0);
3745 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3747 char *plugin_name
= NULL
;
3748 char *comp_cls_name
= NULL
;
3750 arg
= poptGetOptArg(pc
);
3755 enum bt_component_class_type type
;
3756 const char *type_prefix
;
3758 /* Append current component's name if needed */
3759 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3760 cur_name_prefix
, run_args
, all_names
,
3761 &source_names
, &filter_names
, &sink_names
);
3766 /* Parse the argument */
3767 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3768 &comp_cls_name
, &type
);
3769 if (!plugin_name
|| !comp_cls_name
) {
3770 printf_err("Invalid format for --component option's argument:\n %s\n",
3776 g_string_assign(cur_name
, name
);
3778 g_string_assign(cur_name
, "");
3782 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3783 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3784 type_prefix
= "source";
3786 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3787 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
3788 type_prefix
= "filter";
3790 case BT_COMPONENT_CLASS_TYPE_SINK
:
3791 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3792 type_prefix
= "sink";
3798 if (bt_private_value_array_append_string_element(run_args
,
3804 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3809 g_string_assign(cur_name_prefix
, "");
3810 g_string_append_printf(cur_name_prefix
, "%s.%s.%s",
3811 type_prefix
, plugin_name
, comp_cls_name
);
3814 free(comp_cls_name
);
3817 comp_cls_name
= NULL
;
3821 if (cur_name_prefix
->len
== 0) {
3822 printf_err("No current component of which to set parameters:\n %s\n",
3827 if (bt_private_value_array_append_string_element(run_args
,
3833 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3839 if (cur_name_prefix
->len
== 0) {
3840 printf_err("No current component of which to set `path` parameter:\n %s\n",
3845 if (bt_private_value_array_append_string_element(run_args
, "--key")) {
3850 if (bt_private_value_array_append_string_element(run_args
, "path")) {
3855 if (bt_private_value_array_append_string_element(run_args
, "--value")) {
3860 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3866 if (cur_name_prefix
->len
== 0) {
3867 printf_err("No current component of which to set `url` parameter:\n %s\n",
3872 if (bt_private_value_array_append_string_element(run_args
, "--key")) {
3877 if (bt_private_value_array_append_string_element(run_args
, "url")) {
3882 if (bt_private_value_array_append_string_element(run_args
, "--value")) {
3887 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3893 if (cur_name_prefix
->len
== 0) {
3894 printf_err("No current component to name:\n %s\n",
3899 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3904 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3909 g_string_assign(cur_name
, arg
);
3911 case OPT_OMIT_HOME_PLUGIN_PATH
:
3912 force_omit_home_plugin_path
= true;
3914 if (bt_private_value_array_append_string_element(run_args
,
3915 "--omit-home-plugin-path")) {
3920 case OPT_RETRY_DURATION
:
3921 if (bt_private_value_array_append_string_element(run_args
,
3922 "--retry-duration")) {
3927 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3932 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3933 force_omit_system_plugin_path
= true;
3935 if (bt_private_value_array_append_string_element(run_args
,
3936 "--omit-system-plugin-path")) {
3941 case OPT_PLUGIN_PATH
:
3942 if (bt_config_append_plugin_paths_check_setuid_setgid(
3943 plugin_paths
, arg
)) {
3947 if (bt_private_value_array_append_string_element(run_args
,
3953 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3959 print_convert_usage(stdout
);
3961 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
3964 case OPT_CLOCK_CYCLES
:
3965 case OPT_CLOCK_DATE
:
3966 case OPT_CLOCK_FORCE_CORRELATE
:
3968 case OPT_CLOCK_OFFSET
:
3969 case OPT_CLOCK_OFFSET_NS
:
3970 case OPT_CLOCK_SECONDS
:
3973 case OPT_DEBUG_INFO
:
3974 case OPT_DEBUG_INFO_DIR
:
3975 case OPT_DEBUG_INFO_FULL_PATH
:
3976 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3979 case OPT_INPUT_FORMAT
:
3982 case OPT_OUTPUT_FORMAT
:
3985 case OPT_RUN_ARGS_0
:
3986 case OPT_STREAM_INTERSECTION
:
3989 /* Ignore in this pass */
3992 printf_err("Unknown command-line option specified (option code %d)\n",
4001 /* Append current component's name if needed */
4002 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
4003 cur_name_prefix
, run_args
, all_names
, &source_names
,
4004 &filter_names
, &sink_names
);
4009 /* Check for option parsing error */
4011 printf_err("While parsing command-line options, at option %s: %s\n",
4012 poptBadOption(pc
, 0), poptStrerror(opt
));
4016 poptFreeContext(pc
);
4021 * Second pass: transform the convert-specific options and
4022 * arguments into implicit component instances for the run
4025 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
4026 convert_long_options
, 0);
4028 printf_err("Cannot get popt context\n");
4032 poptReadDefaultConfig(pc
, 0);
4034 while ((opt
= poptGetNextOpt(pc
)) > 0) {
4035 arg
= poptGetOptArg(pc
);
4039 if (trimmer_has_begin
) {
4040 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4045 trimmer_has_begin
= true;
4046 ret
= append_implicit_component_extra_param(
4047 &implicit_trimmer_args
, "begin", arg
);
4048 implicit_trimmer_args
.exists
= true;
4054 if (trimmer_has_end
) {
4055 printf("At --end option: --end or --timerange option already specified\n %s\n",
4060 trimmer_has_end
= true;
4061 ret
= append_implicit_component_extra_param(
4062 &implicit_trimmer_args
, "end", arg
);
4063 implicit_trimmer_args
.exists
= true;
4073 if (trimmer_has_begin
|| trimmer_has_end
) {
4074 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4079 ret
= split_timerange(arg
, &begin
, &end
);
4081 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4086 ret
= append_implicit_component_extra_param(
4087 &implicit_trimmer_args
, "begin", begin
);
4088 ret
|= append_implicit_component_extra_param(
4089 &implicit_trimmer_args
, "end", end
);
4090 implicit_trimmer_args
.exists
= true;
4098 case OPT_CLOCK_CYCLES
:
4099 append_implicit_component_param(
4100 &implicit_text_args
, "clock-cycles", "yes");
4101 implicit_text_args
.exists
= true;
4103 case OPT_CLOCK_DATE
:
4104 append_implicit_component_param(
4105 &implicit_text_args
, "clock-date", "yes");
4106 implicit_text_args
.exists
= true;
4108 case OPT_CLOCK_FORCE_CORRELATE
:
4109 append_implicit_component_param(
4110 &implicit_muxer_args
,
4111 "assume-absolute-clock-classes", "yes");
4114 append_implicit_component_param(
4115 &implicit_text_args
, "clock-gmt", "yes");
4116 append_implicit_component_param(
4117 &implicit_trimmer_args
, "clock-gmt", "yes");
4118 implicit_text_args
.exists
= true;
4120 case OPT_CLOCK_OFFSET
:
4121 base_implicit_ctf_input_args
.exists
= true;
4122 append_implicit_component_param(
4123 &base_implicit_ctf_input_args
,
4124 "clock-class-offset-s", arg
);
4126 case OPT_CLOCK_OFFSET_NS
:
4127 base_implicit_ctf_input_args
.exists
= true;
4128 append_implicit_component_param(
4129 &base_implicit_ctf_input_args
,
4130 "clock-class-offset-ns", arg
);
4132 case OPT_CLOCK_SECONDS
:
4133 append_implicit_component_param(
4134 &implicit_text_args
, "clock-seconds", "yes");
4135 implicit_text_args
.exists
= true;
4138 implicit_text_args
.exists
= true;
4139 ret
= append_implicit_component_extra_param(
4140 &implicit_text_args
, "color", arg
);
4145 case OPT_DEBUG_INFO
:
4146 implicit_debug_info_args
.exists
= true;
4148 case OPT_DEBUG_INFO_DIR
:
4149 implicit_debug_info_args
.exists
= true;
4150 ret
= append_implicit_component_extra_param(
4151 &implicit_debug_info_args
, "debug-info-dir", arg
);
4156 case OPT_DEBUG_INFO_FULL_PATH
:
4157 implicit_debug_info_args
.exists
= true;
4158 append_implicit_component_param(
4159 &implicit_debug_info_args
, "full-path", "yes");
4161 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4162 implicit_debug_info_args
.exists
= true;
4163 ret
= append_implicit_component_extra_param(
4164 &implicit_debug_info_args
,
4165 "target-prefix", arg
);
4172 struct bt_private_value
*fields
= fields_from_arg(arg
);
4178 implicit_text_args
.exists
= true;
4179 ret
= insert_flat_params_from_array(
4180 implicit_text_args
.params_arg
,
4181 bt_private_value_as_value(fields
), "field");
4182 bt_object_put_ref(fields
);
4190 struct bt_private_value
*names
= names_from_arg(arg
);
4196 implicit_text_args
.exists
= true;
4197 ret
= insert_flat_params_from_array(
4198 implicit_text_args
.params_arg
,
4199 bt_private_value_as_value(names
), "name");
4200 bt_object_put_ref(names
);
4207 append_implicit_component_param(
4208 &implicit_text_args
, "no-delta", "yes");
4209 implicit_text_args
.exists
= true;
4211 case OPT_INPUT_FORMAT
:
4212 if (got_input_format_opt
) {
4213 printf_err("Duplicate --input-format option\n");
4217 got_input_format_opt
= true;
4219 if (strcmp(arg
, "ctf") == 0) {
4220 base_implicit_ctf_input_args
.exists
= true;
4221 } else if (strcmp(arg
, "lttng-live") == 0) {
4222 implicit_lttng_live_args
.exists
= true;
4224 printf_err("Unknown legacy input format:\n %s\n",
4229 case OPT_OUTPUT_FORMAT
:
4230 if (got_output_format_opt
) {
4231 printf_err("Duplicate --output-format option\n");
4235 got_output_format_opt
= true;
4237 if (strcmp(arg
, "text") == 0) {
4238 implicit_text_args
.exists
= true;
4239 } else if (strcmp(arg
, "ctf") == 0) {
4240 implicit_ctf_output_args
.exists
= true;
4241 } else if (strcmp(arg
, "dummy") == 0) {
4242 implicit_dummy_args
.exists
= true;
4243 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4244 print_ctf_metadata
= true;
4246 printf_err("Unknown legacy output format:\n %s\n",
4253 printf_err("Duplicate --output option\n");
4257 output
= strdup(arg
);
4264 if (print_run_args_0
) {
4265 printf_err("Cannot specify --run-args and --run-args-0\n");
4269 print_run_args
= true;
4271 case OPT_RUN_ARGS_0
:
4272 if (print_run_args
) {
4273 printf_err("Cannot specify --run-args and --run-args-0\n");
4277 print_run_args_0
= true;
4279 case OPT_STREAM_INTERSECTION
:
4281 * Applies to all traces implementing the trace-info
4284 stream_intersection_mode
= true;
4287 if (*log_level
!= 'V' && *log_level
!= 'D') {
4300 /* Check for option parsing error */
4302 printf_err("While parsing command-line options, at option %s: %s\n",
4303 poptBadOption(pc
, 0), poptStrerror(opt
));
4308 * Legacy behaviour: --verbose used to make the `text` output
4309 * format print more information. --verbose is now equivalent to
4310 * the INFO log level, which is why we compare to 'I' here.
4312 if (*log_level
== 'I') {
4313 append_implicit_component_param(&implicit_text_args
,
4318 * Append home and system plugin paths now that we possibly got
4321 if (append_home_and_system_plugin_paths(plugin_paths
,
4322 force_omit_system_plugin_path
,
4323 force_omit_home_plugin_path
)) {
4327 /* Consume and keep leftover arguments */
4328 while ((leftover
= poptGetArg(pc
))) {
4329 GString
*gs_leftover
= g_string_new(leftover
);
4336 leftovers
= g_list_append(leftovers
, gs_leftover
);
4338 g_string_free(gs_leftover
, TRUE
);
4344 /* Print CTF metadata or print LTTng live sessions */
4345 if (print_ctf_metadata
) {
4346 GString
*gs_leftover
;
4348 if (g_list_length(leftovers
) == 0) {
4349 printf_err("--output-format=ctf-metadata specified without a path\n");
4353 if (g_list_length(leftovers
) > 1) {
4354 printf_err("Too many paths specified for --output-format=ctf-metadata\n");
4358 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4363 gs_leftover
= leftovers
->data
;
4364 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4369 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
4377 * If -o ctf was specified, make sure an output path (--output)
4378 * was also specified. --output does not imply -o ctf because
4379 * it's also used for the default, implicit -o text if -o ctf
4382 if (implicit_ctf_output_args
.exists
) {
4384 printf_err("--output-format=ctf specified without --output (trace output path)\n");
4389 * At this point we know that -o ctf AND --output were
4390 * specified. Make sure that no options were specified
4391 * which would imply -o text because --output would be
4392 * ambiguous in this case. For example, this is wrong:
4394 * babeltrace --names=all -o ctf --output=/tmp/path my-trace
4396 * because --names=all implies -o text, and --output
4397 * could apply to both the sink.text.pretty and
4398 * sink.ctf.fs implicit components.
4400 if (implicit_text_args
.exists
) {
4401 printf_err("Ambiguous --output option: --output-format=ctf specified but another option implies --output-format=text\n");
4407 * If -o dummy and -o ctf were not specified, and if there are
4408 * no explicit sink components, then use an implicit
4409 * `sink.text.pretty` component.
4411 if (!implicit_dummy_args
.exists
&& !implicit_ctf_output_args
.exists
&&
4413 implicit_text_args
.exists
= true;
4417 * Set implicit `sink.text.pretty` or `sink.ctf.fs` component's
4418 * `path` parameter if --output was specified.
4421 if (implicit_text_args
.exists
) {
4422 append_implicit_component_extra_param(&implicit_text_args
,
4424 } else if (implicit_ctf_output_args
.exists
) {
4425 append_implicit_component_extra_param(&implicit_ctf_output_args
,
4430 /* Decide where the leftover argument(s) go */
4431 if (g_list_length(leftovers
) > 0) {
4432 if (implicit_lttng_live_args
.exists
) {
4433 GString
*gs_leftover
;
4435 if (g_list_length(leftovers
) > 1) {
4436 printf_err("Too many URLs specified for --output-format=lttng-live\n");
4440 gs_leftover
= leftovers
->data
;
4441 lttng_live_url_parts
=
4442 bt_common_parse_lttng_live_url(gs_leftover
->str
,
4443 error_buf
, sizeof(error_buf
));
4444 if (!lttng_live_url_parts
.proto
) {
4445 printf_err("Invalid LTTng live URL format: %s\n",
4450 if (!lttng_live_url_parts
.session_name
) {
4451 /* Print LTTng live sessions */
4452 cfg
= bt_config_print_lttng_live_sessions_create(
4458 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4463 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
4470 ret
= append_implicit_component_extra_param(
4471 &implicit_lttng_live_args
, "url",
4478 * Append one implicit component argument set
4479 * for each leftover (souce.ctf.fs paths). Copy
4480 * the base implicit component arguments.
4481 * Note that they still have to be named later.
4483 ret
= fill_implicit_ctf_inputs_args(
4484 implicit_ctf_inputs_args
,
4485 &base_implicit_ctf_input_args
, leftovers
);
4493 * Ensure mutual exclusion between implicit `source.ctf.fs` and
4494 * `source.ctf.lttng-live` components.
4496 if (base_implicit_ctf_input_args
.exists
&&
4497 implicit_lttng_live_args
.exists
) {
4498 printf_err("Cannot create both implicit `%s` and `%s` components\n",
4499 base_implicit_ctf_input_args
.comp_arg
->str
,
4500 implicit_lttng_live_args
.comp_arg
->str
);
4505 * If the implicit `source.ctf.fs` or `source.ctf.lttng-live`
4506 * components exists, make sure there's at least one leftover
4507 * (which is the path or URL).
4509 if (base_implicit_ctf_input_args
.exists
&&
4510 g_list_length(leftovers
) == 0) {
4511 printf_err("Missing path for implicit `%s` component\n",
4512 base_implicit_ctf_input_args
.comp_arg
->str
);
4516 if (implicit_lttng_live_args
.exists
&& g_list_length(leftovers
) == 0) {
4517 printf_err("Missing URL for implicit `%s` component\n",
4518 implicit_lttng_live_args
.comp_arg
->str
);
4522 /* Assign names to implicit components */
4523 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4524 struct implicit_component_args
*impl_args
=
4525 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4527 ret
= assign_name_to_implicit_component(impl_args
,
4528 "source-ctf-fs", all_names
, &source_names
, true);
4534 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4535 "lttng-live", all_names
, &source_names
, true);
4540 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4541 "pretty", all_names
, &sink_names
, true);
4546 ret
= assign_name_to_implicit_component(&implicit_ctf_output_args
,
4547 "sink-ctf-fs", all_names
, &sink_names
, true);
4552 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4553 "dummy", all_names
, &sink_names
, true);
4558 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4559 "muxer", all_names
, NULL
, false);
4564 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4565 "trimmer", all_names
, NULL
, false);
4570 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4571 "debug-info", all_names
, NULL
, false);
4576 /* Make sure there's at least one source and one sink */
4577 if (!source_names
) {
4578 printf_err("No source component\n");
4583 printf_err("No sink component\n");
4588 * Prepend the muxer, the trimmer, and the debug info to the
4589 * filter chain so that we have:
4591 * sources -> muxer -> [trimmer] -> [debug info] ->
4592 * [user filters] -> sinks
4594 if (implicit_debug_info_args
.exists
) {
4595 if (g_list_prepend_gstring(&filter_names
,
4596 implicit_debug_info_args
.name_arg
->str
)) {
4601 if (implicit_trimmer_args
.exists
) {
4602 if (g_list_prepend_gstring(&filter_names
,
4603 implicit_trimmer_args
.name_arg
->str
)) {
4608 if (g_list_prepend_gstring(&filter_names
,
4609 implicit_muxer_args
.name_arg
->str
)) {
4614 * Append the equivalent run arguments for the implicit
4617 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4618 struct implicit_component_args
*impl_args
=
4619 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4621 ret
= append_run_args_for_implicit_component(impl_args
,
4628 ret
= append_run_args_for_implicit_component(&implicit_lttng_live_args
,
4634 ret
= append_run_args_for_implicit_component(&implicit_text_args
,
4640 ret
= append_run_args_for_implicit_component(&implicit_ctf_output_args
,
4646 ret
= append_run_args_for_implicit_component(&implicit_dummy_args
,
4652 ret
= append_run_args_for_implicit_component(&implicit_muxer_args
,
4658 ret
= append_run_args_for_implicit_component(&implicit_trimmer_args
,
4664 ret
= append_run_args_for_implicit_component(&implicit_debug_info_args
,
4670 /* Auto-connect components */
4671 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4674 printf_err("Cannot auto-connect components\n");
4679 * We have all the run command arguments now. Depending on
4680 * --run-args, we pass this to the run command or print them
4683 if (print_run_args
|| print_run_args_0
) {
4684 if (stream_intersection_mode
) {
4685 printf_err("Cannot specify --stream-intersection with --run-args or --run-args-0\n");
4689 for (i
= 0; i
< bt_value_array_get_size(
4690 bt_private_value_as_value(run_args
)); i
++) {
4691 struct bt_value
*arg_value
=
4692 bt_value_array_borrow_element_by_index(
4693 bt_private_value_as_value(run_args
),
4696 GString
*quoted
= NULL
;
4697 const char *arg_to_print
;
4699 BT_ASSERT(arg_value
);
4700 arg
= bt_value_string_get(arg_value
);
4702 if (print_run_args
) {
4703 quoted
= bt_common_shell_quote(arg
, true);
4708 arg_to_print
= quoted
->str
;
4713 printf("%s", arg_to_print
);
4716 g_string_free(quoted
, TRUE
);
4719 if (i
< bt_value_array_get_size(
4720 bt_private_value_as_value(run_args
)) - 1) {
4721 if (print_run_args
) {
4730 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4734 cfg
= bt_config_run_from_args_array(
4735 bt_private_value_as_value(run_args
), retcode
,
4736 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
4737 initial_plugin_paths
);
4742 cfg
->cmd_data
.run
.stream_intersection_mode
= stream_intersection_mode
;
4747 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4751 poptFreeContext(pc
);
4758 g_string_free(cur_name
, TRUE
);
4761 if (cur_name_prefix
) {
4762 g_string_free(cur_name_prefix
, TRUE
);
4765 if (implicit_ctf_inputs_args
) {
4766 g_ptr_array_free(implicit_ctf_inputs_args
, TRUE
);
4769 bt_object_put_ref(run_args
);
4770 bt_object_put_ref(all_names
);
4771 destroy_glist_of_gstring(source_names
);
4772 destroy_glist_of_gstring(filter_names
);
4773 destroy_glist_of_gstring(sink_names
);
4774 destroy_glist_of_gstring(leftovers
);
4775 finalize_implicit_component_args(&base_implicit_ctf_input_args
);
4776 finalize_implicit_component_args(&implicit_ctf_output_args
);
4777 finalize_implicit_component_args(&implicit_lttng_live_args
);
4778 finalize_implicit_component_args(&implicit_dummy_args
);
4779 finalize_implicit_component_args(&implicit_text_args
);
4780 finalize_implicit_component_args(&implicit_debug_info_args
);
4781 finalize_implicit_component_args(&implicit_muxer_args
);
4782 finalize_implicit_component_args(&implicit_trimmer_args
);
4783 bt_object_put_ref(plugin_paths
);
4784 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4789 * Prints the Babeltrace 2.x general usage.
4792 void print_gen_usage(FILE *fp
)
4794 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4796 fprintf(fp
, "General options:\n");
4798 fprintf(fp
, " -d, --debug Enable debug mode (same as --log-level=V)\n");
4799 fprintf(fp
, " -h, --help Show this help and quit\n");
4800 fprintf(fp
, " -l, --log-level=LVL Set all log levels to LVL (`N`, `V`, `D`,\n");
4801 fprintf(fp
, " `I`, `W` (default), `E`, or `F`)\n");
4802 fprintf(fp
, " -v, --verbose Enable verbose mode (same as --log-level=I)\n");
4803 fprintf(fp
, " -V, --version Show version and quit\n");
4805 fprintf(fp
, "Available commands:\n");
4807 fprintf(fp
, " convert Convert and trim traces (default)\n");
4808 fprintf(fp
, " help Get help for a plugin or a component class\n");
4809 fprintf(fp
, " list-plugins List available plugins and their content\n");
4810 fprintf(fp
, " query Query objects from a component class\n");
4811 fprintf(fp
, " run Build a processing graph and run it\n");
4813 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4817 char log_level_from_arg(const char *arg
)
4821 if (strcmp(arg
, "VERBOSE") == 0 ||
4822 strcmp(arg
, "V") == 0) {
4824 } else if (strcmp(arg
, "DEBUG") == 0 ||
4825 strcmp(arg
, "D") == 0) {
4827 } else if (strcmp(arg
, "INFO") == 0 ||
4828 strcmp(arg
, "I") == 0) {
4830 } else if (strcmp(arg
, "WARN") == 0 ||
4831 strcmp(arg
, "WARNING") == 0 ||
4832 strcmp(arg
, "W") == 0) {
4834 } else if (strcmp(arg
, "ERROR") == 0 ||
4835 strcmp(arg
, "E") == 0) {
4837 } else if (strcmp(arg
, "FATAL") == 0 ||
4838 strcmp(arg
, "F") == 0) {
4840 } else if (strcmp(arg
, "NONE") == 0 ||
4841 strcmp(arg
, "N") == 0) {
4848 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4849 int *retcode
, bool force_omit_system_plugin_path
,
4850 bool force_omit_home_plugin_path
,
4851 struct bt_private_value
*initial_plugin_paths
)
4853 struct bt_config
*config
= NULL
;
4855 const char **command_argv
= NULL
;
4856 int command_argc
= -1;
4857 const char *command_name
= NULL
;
4858 char log_level
= 'U';
4861 COMMAND_TYPE_NONE
= -1,
4862 COMMAND_TYPE_RUN
= 0,
4863 COMMAND_TYPE_CONVERT
,
4864 COMMAND_TYPE_LIST_PLUGINS
,
4867 } command_type
= COMMAND_TYPE_NONE
;
4871 if (!initial_plugin_paths
) {
4872 initial_plugin_paths
= bt_private_value_array_create();
4873 if (!initial_plugin_paths
) {
4878 bt_object_get_ref(initial_plugin_paths
);
4884 print_gen_usage(stdout
);
4888 for (i
= 1; i
< argc
; i
++) {
4889 const char *cur_arg
= argv
[i
];
4890 const char *next_arg
= i
== (argc
- 1) ? NULL
: argv
[i
+ 1];
4892 if (strcmp(cur_arg
, "-d") == 0 ||
4893 strcmp(cur_arg
, "--debug") == 0) {
4895 } else if (strcmp(cur_arg
, "-v") == 0 ||
4896 strcmp(cur_arg
, "--verbose") == 0) {
4897 if (log_level
!= 'V' && log_level
!= 'D') {
4899 * Legacy: do not override a previous
4900 * --debug because --verbose and --debug
4901 * can be specified together (in this
4902 * case we want the lowest log level to
4907 } else if (strcmp(cur_arg
, "--log-level") == 0 ||
4908 strcmp(cur_arg
, "-l") == 0) {
4910 printf_err("Missing log level value for --log-level option\n");
4915 log_level
= log_level_from_arg(next_arg
);
4916 if (log_level
== 'U') {
4917 printf_err("Invalid argument for --log-level option:\n %s\n",
4924 } else if (strncmp(cur_arg
, "--log-level=", 12) == 0) {
4925 const char *arg
= &cur_arg
[12];
4927 log_level
= log_level_from_arg(arg
);
4928 if (log_level
== 'U') {
4929 printf_err("Invalid argument for --log-level option:\n %s\n",
4934 } else if (strncmp(cur_arg
, "-l", 2) == 0) {
4935 const char *arg
= &cur_arg
[2];
4937 log_level
= log_level_from_arg(arg
);
4938 if (log_level
== 'U') {
4939 printf_err("Invalid argument for --log-level option:\n %s\n",
4944 } else if (strcmp(cur_arg
, "-V") == 0 ||
4945 strcmp(cur_arg
, "--version") == 0) {
4948 } else if (strcmp(cur_arg
, "-h") == 0 ||
4949 strcmp(cur_arg
, "--help") == 0) {
4950 print_gen_usage(stdout
);
4954 * First unknown argument: is it a known command
4957 command_argv
= &argv
[i
];
4958 command_argc
= argc
- i
;
4960 if (strcmp(cur_arg
, "convert") == 0) {
4961 command_type
= COMMAND_TYPE_CONVERT
;
4962 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4963 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4964 } else if (strcmp(cur_arg
, "help") == 0) {
4965 command_type
= COMMAND_TYPE_HELP
;
4966 } else if (strcmp(cur_arg
, "query") == 0) {
4967 command_type
= COMMAND_TYPE_QUERY
;
4968 } else if (strcmp(cur_arg
, "run") == 0) {
4969 command_type
= COMMAND_TYPE_RUN
;
4972 * Unknown argument, but not a known
4973 * command name: assume the default
4974 * `convert` command.
4976 command_type
= COMMAND_TYPE_CONVERT
;
4977 command_name
= "convert";
4978 command_argv
= &argv
[i
- 1];
4979 command_argc
= argc
- i
+ 1;
4985 if (command_type
== COMMAND_TYPE_NONE
) {
4987 * We only got non-help, non-version general options
4988 * like --verbose and --debug, without any other
4989 * arguments, so we can't do anything useful: print the
4992 print_gen_usage(stdout
);
4996 BT_ASSERT(command_argv
);
4997 BT_ASSERT(command_argc
>= 0);
4999 switch (command_type
) {
5000 case COMMAND_TYPE_RUN
:
5001 config
= bt_config_run_from_args(command_argc
, command_argv
,
5002 retcode
, force_omit_system_plugin_path
,
5003 force_omit_home_plugin_path
, initial_plugin_paths
);
5005 case COMMAND_TYPE_CONVERT
:
5006 config
= bt_config_convert_from_args(command_argc
, command_argv
,
5007 retcode
, force_omit_system_plugin_path
,
5008 force_omit_home_plugin_path
,
5009 initial_plugin_paths
, &log_level
);
5011 case COMMAND_TYPE_LIST_PLUGINS
:
5012 config
= bt_config_list_plugins_from_args(command_argc
,
5013 command_argv
, retcode
, force_omit_system_plugin_path
,
5014 force_omit_home_plugin_path
, initial_plugin_paths
);
5016 case COMMAND_TYPE_HELP
:
5017 config
= bt_config_help_from_args(command_argc
,
5018 command_argv
, retcode
, force_omit_system_plugin_path
,
5019 force_omit_home_plugin_path
, initial_plugin_paths
);
5021 case COMMAND_TYPE_QUERY
:
5022 config
= bt_config_query_from_args(command_argc
,
5023 command_argv
, retcode
, force_omit_system_plugin_path
,
5024 force_omit_home_plugin_path
, initial_plugin_paths
);
5031 if (log_level
== 'U') {
5035 config
->log_level
= log_level
;
5036 config
->command_name
= command_name
;
5040 bt_object_put_ref(initial_plugin_paths
);