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_value_borrow_from_private(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_value_borrow_from_private(
299 bt_private_value_integer_create_init(
304 /* Positive floating point number */
305 value
= bt_value_borrow_from_private(
306 bt_private_value_real_create_init(
307 state
->scanner
->value
.v_float
));
311 value
= bt_value_borrow_from_private(
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_value_borrow_from_private(
336 bt_private_value_bool_create_init(true));
337 } else if (!strcmp(id
, "false") ||
338 !strcmp(id
, "FALSE") ||
341 value
= bt_value_borrow_from_private(
342 bt_private_value_bool_create_init(false));
344 value
= bt_value_borrow_from_private(
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_value_borrow_from_private(
379 bt_private_value_integer_create_init(
380 -((int64_t) int_val
)));
384 /* Negative floating point number */
385 value
= bt_value_borrow_from_private(
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 ret
= bt_value_string_get(str_obj
, &suffix
);
1270 printf_err("Unexpected error\n");
1274 g_string_assign(tmpstr
, prefix
);
1275 g_string_append(tmpstr
, "-");
1277 /* Special-case for "all" and "none". */
1278 if (!strcmp(suffix
, "all")) {
1280 g_string_assign(default_value
, "show");
1281 } else if (!strcmp(suffix
, "none")) {
1283 g_string_assign(default_value
, "hide");
1287 g_string_append(tmpstr
, "default");
1288 append_param_arg(params_arg
, tmpstr
->str
,
1289 default_value
->str
);
1291 non_default_set
= true;
1292 g_string_append(tmpstr
, suffix
);
1293 append_param_arg(params_arg
, tmpstr
->str
, "yes");
1297 /* Implicit field-default=hide if any non-default option is set. */
1298 if (non_default_set
&& !default_set
) {
1299 g_string_assign(tmpstr
, prefix
);
1300 g_string_append(tmpstr
, "-default");
1301 g_string_assign(default_value
, "hide");
1302 append_param_arg(params_arg
, tmpstr
->str
, default_value
->str
);
1306 if (default_value
) {
1307 g_string_free(default_value
, TRUE
);
1311 g_string_free(tmpstr
, TRUE
);
1324 OPT_CLOCK_FORCE_CORRELATE
,
1327 OPT_CLOCK_OFFSET_NS
,
1335 OPT_DEBUG_INFO_FULL_PATH
,
1336 OPT_DEBUG_INFO_TARGET_PREFIX
,
1346 OPT_OMIT_HOME_PLUGIN_PATH
,
1347 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
1353 OPT_RESET_BASE_PARAMS
,
1357 OPT_STREAM_INTERSECTION
,
1364 enum bt_config_component_dest
{
1365 BT_CONFIG_COMPONENT_DEST_UNKNOWN
= -1,
1366 BT_CONFIG_COMPONENT_DEST_SOURCE
,
1367 BT_CONFIG_COMPONENT_DEST_FILTER
,
1368 BT_CONFIG_COMPONENT_DEST_SINK
,
1372 * Adds a configuration component to the appropriate configuration
1373 * array depending on the destination.
1376 void add_run_cfg_comp(struct bt_config
*cfg
,
1377 struct bt_config_component
*cfg_comp
,
1378 enum bt_config_component_dest dest
)
1380 bt_object_get_ref(cfg_comp
);
1383 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
1384 g_ptr_array_add(cfg
->cmd_data
.run
.sources
, cfg_comp
);
1386 case BT_CONFIG_COMPONENT_DEST_FILTER
:
1387 g_ptr_array_add(cfg
->cmd_data
.run
.filters
, cfg_comp
);
1389 case BT_CONFIG_COMPONENT_DEST_SINK
:
1390 g_ptr_array_add(cfg
->cmd_data
.run
.sinks
, cfg_comp
);
1398 int add_run_cfg_comp_check_name(struct bt_config
*cfg
,
1399 struct bt_config_component
*cfg_comp
,
1400 enum bt_config_component_dest dest
,
1401 struct bt_private_value
*instance_names
)
1405 if (cfg_comp
->instance_name
->len
== 0) {
1406 printf_err("Found an unnamed component\n");
1411 if (bt_value_map_has_entry(bt_value_borrow_from_private(instance_names
),
1412 cfg_comp
->instance_name
->str
)) {
1413 printf_err("Duplicate component instance name:\n %s\n",
1414 cfg_comp
->instance_name
->str
);
1419 if (bt_private_value_map_insert_entry(instance_names
,
1420 cfg_comp
->instance_name
->str
, bt_value_null
)) {
1426 add_run_cfg_comp(cfg
, cfg_comp
, dest
);
1433 int append_env_var_plugin_paths(struct bt_private_value
*plugin_paths
)
1438 if (bt_common_is_setuid_setgid()) {
1439 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1443 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
1448 ret
= bt_config_append_plugin_paths(plugin_paths
, envvar
);
1452 printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
1459 int append_home_and_system_plugin_paths(struct bt_private_value
*plugin_paths
,
1460 bool omit_system_plugin_path
, bool omit_home_plugin_path
)
1464 if (!omit_home_plugin_path
) {
1465 if (bt_common_is_setuid_setgid()) {
1466 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1468 char *home_plugin_dir
=
1469 bt_common_get_home_plugin_path();
1471 if (home_plugin_dir
) {
1472 ret
= bt_config_append_plugin_paths(
1473 plugin_paths
, home_plugin_dir
);
1474 free(home_plugin_dir
);
1477 printf_err("Invalid home plugin path\n");
1484 if (!omit_system_plugin_path
) {
1485 if (bt_config_append_plugin_paths(plugin_paths
,
1486 bt_common_get_system_plugin_path())) {
1487 printf_err("Invalid system plugin path\n");
1493 printf_err("Cannot append home and system plugin paths\n");
1498 int append_home_and_system_plugin_paths_cfg(struct bt_config
*cfg
)
1500 return append_home_and_system_plugin_paths(cfg
->plugin_paths
,
1501 cfg
->omit_system_plugin_path
, cfg
->omit_home_plugin_path
);
1505 struct bt_config
*bt_config_base_create(enum bt_config_command command
,
1506 struct bt_private_value
*initial_plugin_paths
,
1509 struct bt_config
*cfg
;
1512 cfg
= g_new0(struct bt_config
, 1);
1518 bt_object_init_shared(&cfg
->base
, bt_config_destroy
);
1519 cfg
->command
= command
;
1520 cfg
->command_needs_plugins
= needs_plugins
;
1522 if (initial_plugin_paths
) {
1523 cfg
->plugin_paths
= bt_object_get_ref(initial_plugin_paths
);
1525 cfg
->plugin_paths
= bt_private_value_array_create();
1526 if (!cfg
->plugin_paths
) {
1535 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1542 struct bt_config
*bt_config_run_create(
1543 struct bt_private_value
*initial_plugin_paths
)
1545 struct bt_config
*cfg
;
1548 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_RUN
,
1549 initial_plugin_paths
, true);
1554 cfg
->cmd_data
.run
.sources
= g_ptr_array_new_with_free_func(
1555 (GDestroyNotify
) bt_object_put_ref
);
1556 if (!cfg
->cmd_data
.run
.sources
) {
1561 cfg
->cmd_data
.run
.filters
= g_ptr_array_new_with_free_func(
1562 (GDestroyNotify
) bt_object_put_ref
);
1563 if (!cfg
->cmd_data
.run
.filters
) {
1568 cfg
->cmd_data
.run
.sinks
= g_ptr_array_new_with_free_func(
1569 (GDestroyNotify
) bt_object_put_ref
);
1570 if (!cfg
->cmd_data
.run
.sinks
) {
1575 cfg
->cmd_data
.run
.connections
= g_ptr_array_new_with_free_func(
1576 (GDestroyNotify
) bt_config_connection_destroy
);
1577 if (!cfg
->cmd_data
.run
.connections
) {
1585 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1592 struct bt_config
*bt_config_list_plugins_create(
1593 struct bt_private_value
*initial_plugin_paths
)
1595 struct bt_config
*cfg
;
1598 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_LIST_PLUGINS
,
1599 initial_plugin_paths
, true);
1607 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1614 struct bt_config
*bt_config_help_create(
1615 struct bt_private_value
*initial_plugin_paths
)
1617 struct bt_config
*cfg
;
1620 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_HELP
,
1621 initial_plugin_paths
, true);
1626 cfg
->cmd_data
.help
.cfg_component
=
1627 bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN
,
1629 if (!cfg
->cmd_data
.help
.cfg_component
) {
1636 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1643 struct bt_config
*bt_config_query_create(
1644 struct bt_private_value
*initial_plugin_paths
)
1646 struct bt_config
*cfg
;
1649 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_QUERY
,
1650 initial_plugin_paths
, true);
1655 cfg
->cmd_data
.query
.object
= g_string_new(NULL
);
1656 if (!cfg
->cmd_data
.query
.object
) {
1664 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1671 struct bt_config
*bt_config_print_ctf_metadata_create(
1672 struct bt_private_value
*initial_plugin_paths
)
1674 struct bt_config
*cfg
;
1677 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_CTF_METADATA
,
1678 initial_plugin_paths
, true);
1683 cfg
->cmd_data
.print_ctf_metadata
.path
= g_string_new(NULL
);
1684 if (!cfg
->cmd_data
.print_ctf_metadata
.path
) {
1689 cfg
->cmd_data
.print_ctf_metadata
.output_path
= g_string_new(NULL
);
1690 if (!cfg
->cmd_data
.print_ctf_metadata
.output_path
) {
1698 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1705 struct bt_config
*bt_config_print_lttng_live_sessions_create(
1706 struct bt_private_value
*initial_plugin_paths
)
1708 struct bt_config
*cfg
;
1711 cfg
= bt_config_base_create(BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS
,
1712 initial_plugin_paths
, true);
1717 cfg
->cmd_data
.print_lttng_live_sessions
.url
= g_string_new(NULL
);
1718 if (!cfg
->cmd_data
.print_lttng_live_sessions
.url
) {
1723 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
=
1725 if (!cfg
->cmd_data
.print_lttng_live_sessions
.output_path
) {
1733 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1740 int bt_config_append_plugin_paths_check_setuid_setgid(
1741 struct bt_private_value
*plugin_paths
, const char *arg
)
1745 if (bt_common_is_setuid_setgid()) {
1746 BT_LOGI_STR("Skipping non-system plugin paths for setuid/setgid binary.");
1750 if (bt_config_append_plugin_paths(plugin_paths
, arg
)) {
1751 printf_err("Invalid --plugin-path option's argument:\n %s\n",
1762 * Prints the expected format for a --params option.
1765 void print_expected_params_format(FILE *fp
)
1767 fprintf(fp
, "Expected format of PARAMS\n");
1768 fprintf(fp
, "-------------------------\n");
1770 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
1772 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
1773 fprintf(fp
, "where PARAM is the parameter name (C identifier plus the [:.-] characters),\n");
1774 fprintf(fp
, "and VALUE can be one of:\n");
1776 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
1777 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
1778 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
1779 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
1780 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
1781 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
1782 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
1783 fprintf(fp
, " the null and boolean value symbols above.\n");
1784 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
1786 fprintf(fp
, "You can put whitespaces allowed around individual `=` and `,` symbols.\n");
1788 fprintf(fp
, "Example:\n");
1790 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
1791 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
1792 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
1794 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
1795 fprintf(fp
, "babeltrace from a shell.\n");
1800 * Prints the help command usage.
1803 void print_help_usage(FILE *fp
)
1805 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
1806 fprintf(fp
, " babeltrace [GENERAL OPTIONS] help [OPTIONS] TYPE.PLUGIN.CLS\n");
1808 fprintf(fp
, "Options:\n");
1810 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1811 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1812 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1813 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1814 fprintf(fp
, " dynamic plugins can be loaded\n");
1815 fprintf(fp
, " -h, --help Show this help and quit\n");
1817 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
1819 fprintf(fp
, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
1823 struct poptOption help_long_options
[] = {
1824 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1825 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1826 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1827 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1828 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1829 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1833 * Creates a Babeltrace config object from the arguments of a help
1836 * *retcode is set to the appropriate exit code to use.
1839 struct bt_config
*bt_config_help_from_args(int argc
, const char *argv
[],
1840 int *retcode
, bool force_omit_system_plugin_path
,
1841 bool force_omit_home_plugin_path
,
1842 struct bt_private_value
*initial_plugin_paths
)
1844 poptContext pc
= NULL
;
1848 struct bt_config
*cfg
= NULL
;
1849 const char *leftover
;
1850 char *plugin_name
= NULL
, *comp_cls_name
= NULL
;
1853 cfg
= bt_config_help_create(initial_plugin_paths
);
1858 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
1859 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
1860 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
1866 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
1867 help_long_options
, 0);
1869 printf_err("Cannot get popt context\n");
1873 poptReadDefaultConfig(pc
, 0);
1875 while ((opt
= poptGetNextOpt(pc
)) > 0) {
1876 arg
= poptGetOptArg(pc
);
1879 case OPT_PLUGIN_PATH
:
1880 if (bt_config_append_plugin_paths_check_setuid_setgid(
1881 cfg
->plugin_paths
, arg
)) {
1885 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
1886 cfg
->omit_system_plugin_path
= true;
1888 case OPT_OMIT_HOME_PLUGIN_PATH
:
1889 cfg
->omit_home_plugin_path
= true;
1892 print_help_usage(stdout
);
1894 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1897 printf_err("Unknown command-line option specified (option code %d)\n",
1906 /* Check for option parsing error */
1908 printf_err("While parsing command-line options, at option %s: %s\n",
1909 poptBadOption(pc
, 0), poptStrerror(opt
));
1913 leftover
= poptGetArg(pc
);
1915 plugin_comp_cls_names(leftover
, NULL
,
1916 &plugin_name
, &comp_cls_name
,
1917 &cfg
->cmd_data
.help
.cfg_component
->type
);
1918 if (plugin_name
&& comp_cls_name
) {
1919 /* Component class help */
1921 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1924 cfg
->cmd_data
.help
.cfg_component
->comp_cls_name
,
1927 /* Fall back to plugin help */
1928 cfg
->cmd_data
.help
.cfg_component
->type
=
1929 BT_COMPONENT_CLASS_TYPE_UNKNOWN
;
1931 cfg
->cmd_data
.help
.cfg_component
->plugin_name
,
1935 print_help_usage(stdout
);
1937 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1941 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
1949 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
1952 g_free(plugin_name
);
1953 g_free(comp_cls_name
);
1956 poptFreeContext(pc
);
1964 * Prints the help command usage.
1967 void print_query_usage(FILE *fp
)
1969 fprintf(fp
, "Usage: babeltrace [GEN OPTS] query [OPTS] TYPE.PLUGIN.CLS OBJECT\n");
1971 fprintf(fp
, "Options:\n");
1973 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
1974 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
1975 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
1976 fprintf(fp
, " -p, --params=PARAMS Set the query parameters to PARAMS\n");
1977 fprintf(fp
, " (see the expected format of PARAMS below)\n");
1978 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
1979 fprintf(fp
, " dynamic plugins can be loaded\n");
1980 fprintf(fp
, " -h, --help Show this help and quit\n");
1981 fprintf(fp
, "\n\n");
1982 print_expected_params_format(fp
);
1986 struct poptOption query_long_options
[] = {
1987 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1988 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
1989 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
1990 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
1991 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
1992 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
1993 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
1997 * Creates a Babeltrace config object from the arguments of a query
2000 * *retcode is set to the appropriate exit code to use.
2003 struct bt_config
*bt_config_query_from_args(int argc
, const char *argv
[],
2004 int *retcode
, bool force_omit_system_plugin_path
,
2005 bool force_omit_home_plugin_path
,
2006 struct bt_private_value
*initial_plugin_paths
)
2008 poptContext pc
= NULL
;
2012 struct bt_config
*cfg
= NULL
;
2013 const char *leftover
;
2014 struct bt_private_value
*params
= bt_private_value_null
;
2017 cfg
= bt_config_query_create(initial_plugin_paths
);
2022 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2023 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2024 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2030 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2031 query_long_options
, 0);
2033 printf_err("Cannot get popt context\n");
2037 poptReadDefaultConfig(pc
, 0);
2039 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2040 arg
= poptGetOptArg(pc
);
2043 case OPT_PLUGIN_PATH
:
2044 if (bt_config_append_plugin_paths_check_setuid_setgid(
2045 cfg
->plugin_paths
, arg
)) {
2049 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2050 cfg
->omit_system_plugin_path
= true;
2052 case OPT_OMIT_HOME_PLUGIN_PATH
:
2053 cfg
->omit_home_plugin_path
= true;
2057 bt_object_put_ref(params
);
2058 params
= bt_private_value_from_arg(arg
);
2060 printf_err("Invalid format for --params option's argument:\n %s\n",
2067 print_query_usage(stdout
);
2069 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2072 printf_err("Unknown command-line option specified (option code %d)\n",
2081 /* Check for option parsing error */
2083 printf_err("While parsing command-line options, at option %s: %s\n",
2084 poptBadOption(pc
, 0), poptStrerror(opt
));
2089 * We need exactly two leftover arguments which are the
2090 * mandatory component class specification and query object.
2092 leftover
= poptGetArg(pc
);
2094 cfg
->cmd_data
.query
.cfg_component
=
2095 bt_config_component_from_arg(leftover
);
2096 if (!cfg
->cmd_data
.query
.cfg_component
) {
2097 printf_err("Invalid format for component class specification:\n %s\n",
2103 BT_OBJECT_MOVE_REF(cfg
->cmd_data
.query
.cfg_component
->params
,
2106 print_query_usage(stdout
);
2108 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2112 leftover
= poptGetArg(pc
);
2114 if (strlen(leftover
) == 0) {
2115 printf_err("Invalid empty object\n");
2119 g_string_assign(cfg
->cmd_data
.query
.object
, leftover
);
2121 print_query_usage(stdout
);
2123 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2127 leftover
= poptGetArg(pc
);
2129 printf_err("Unexpected argument: %s\n", leftover
);
2133 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2141 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2145 poptFreeContext(pc
);
2148 bt_object_put_ref(params
);
2154 * Prints the list-plugins command usage.
2157 void print_list_plugins_usage(FILE *fp
)
2159 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] list-plugins [OPTIONS]\n");
2161 fprintf(fp
, "Options:\n");
2163 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2164 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2165 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2166 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2167 fprintf(fp
, " dynamic plugins can be loaded\n");
2168 fprintf(fp
, " -h, --help Show this help and quit\n");
2170 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2172 fprintf(fp
, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
2176 struct poptOption list_plugins_long_options
[] = {
2177 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2178 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2179 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2180 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2181 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2182 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2186 * Creates a Babeltrace config object from the arguments of a
2187 * list-plugins command.
2189 * *retcode is set to the appropriate exit code to use.
2192 struct bt_config
*bt_config_list_plugins_from_args(int argc
, const char *argv
[],
2193 int *retcode
, bool force_omit_system_plugin_path
,
2194 bool force_omit_home_plugin_path
,
2195 struct bt_private_value
*initial_plugin_paths
)
2197 poptContext pc
= NULL
;
2201 struct bt_config
*cfg
= NULL
;
2202 const char *leftover
;
2205 cfg
= bt_config_list_plugins_create(initial_plugin_paths
);
2210 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2211 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2212 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2218 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2219 list_plugins_long_options
, 0);
2221 printf_err("Cannot get popt context\n");
2225 poptReadDefaultConfig(pc
, 0);
2227 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2228 arg
= poptGetOptArg(pc
);
2231 case OPT_PLUGIN_PATH
:
2232 if (bt_config_append_plugin_paths_check_setuid_setgid(
2233 cfg
->plugin_paths
, arg
)) {
2237 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2238 cfg
->omit_system_plugin_path
= true;
2240 case OPT_OMIT_HOME_PLUGIN_PATH
:
2241 cfg
->omit_home_plugin_path
= true;
2244 print_list_plugins_usage(stdout
);
2246 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2249 printf_err("Unknown command-line option specified (option code %d)\n",
2258 /* Check for option parsing error */
2260 printf_err("While parsing command-line options, at option %s: %s\n",
2261 poptBadOption(pc
, 0), poptStrerror(opt
));
2265 leftover
= poptGetArg(pc
);
2267 printf_err("Unexpected argument: %s\n", leftover
);
2271 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2279 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2283 poptFreeContext(pc
);
2291 * Prints the run command usage.
2294 void print_run_usage(FILE *fp
)
2296 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] run [OPTIONS]\n");
2298 fprintf(fp
, "Options:\n");
2300 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
2301 fprintf(fp
, " for all the following components until\n");
2302 fprintf(fp
, " --reset-base-params is encountered\n");
2303 fprintf(fp
, " (see the expected format of PARAMS below)\n");
2304 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2305 fprintf(fp
, " Instantiate the component class CLS of type\n");
2306 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2307 fprintf(fp
, " in the plugin PLUGIN, add it to the graph,\n");
2308 fprintf(fp
, " and optionally name it NAME (you can also\n");
2309 fprintf(fp
, " specify the name with --name)\n");
2310 fprintf(fp
, " -C, --connect=CONNECTION Connect two created components (see the\n");
2311 fprintf(fp
, " expected format of CONNECTION below)\n");
2312 fprintf(fp
, " --key=KEY Set the current initialization string\n");
2313 fprintf(fp
, " parameter key to KEY (see --value)\n");
2314 fprintf(fp
, " -n, --name=NAME Set the name of the current component\n");
2315 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2316 fprintf(fp
, " names of the created components)\n");
2317 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2318 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2319 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2320 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2321 fprintf(fp
, " current component (see the expected format\n");
2322 fprintf(fp
, " of PARAMS below)\n");
2323 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2324 fprintf(fp
, " dynamic plugins can be loaded\n");
2325 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters to an\n");
2326 fprintf(fp
, " empty map\n");
2327 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2328 fprintf(fp
, " the graph later, retry in DUR µs\n");
2329 fprintf(fp
, " (default: 100000)\n");
2330 fprintf(fp
, " --value=VAL Add a string initialization parameter to\n");
2331 fprintf(fp
, " the current component with a name given by\n");
2332 fprintf(fp
, " the last argument of the --key option and a\n");
2333 fprintf(fp
, " value set to VAL\n");
2334 fprintf(fp
, " -h, --help Show this help and quit\n");
2336 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2337 fprintf(fp
, "\n\n");
2338 fprintf(fp
, "Expected format of CONNECTION\n");
2339 fprintf(fp
, "-----------------------------\n");
2341 fprintf(fp
, " UPSTREAM[.UPSTREAM-PORT]:DOWNSTREAM[.DOWNSTREAM-PORT]\n");
2343 fprintf(fp
, "UPSTREAM and DOWNSTREAM are names of the upstream and downstream\n");
2344 fprintf(fp
, "components to connect together. You must escape the following characters\n\n");
2345 fprintf(fp
, "with `\\`: `\\`, `.`, and `:`. You can set the name of the current\n");
2346 fprintf(fp
, "component with the --name option.\n");
2348 fprintf(fp
, "UPSTREAM-PORT and DOWNSTREAM-PORT are optional globbing patterns to\n");
2349 fprintf(fp
, "identify the upstream and downstream ports to use for the connection.\n");
2350 fprintf(fp
, "When the port is not specified, `*` is used.\n");
2352 fprintf(fp
, "When a component named UPSTREAM has an available port which matches the\n");
2353 fprintf(fp
, "UPSTREAM-PORT globbing pattern, it is connected to the first port which\n");
2354 fprintf(fp
, "matches the DOWNSTREAM-PORT globbing pattern of the component named\n");
2355 fprintf(fp
, "DOWNSTREAM.\n");
2357 fprintf(fp
, "The only special character in UPSTREAM-PORT and DOWNSTREAM-PORT is `*`\n");
2358 fprintf(fp
, "which matches anything. You must escape the following characters\n");
2359 fprintf(fp
, "with `\\`: `\\`, `*`, `?`, `[`, `.`, and `:`.\n");
2361 fprintf(fp
, "You can connect a source component to a filter or sink component. You\n");
2362 fprintf(fp
, "can connect a filter component to a sink component.\n");
2364 fprintf(fp
, "Examples:\n");
2366 fprintf(fp
, " my-src:my-sink\n");
2367 fprintf(fp
, " ctf-fs.*stream*:utils-muxer:*\n");
2369 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run\n");
2370 fprintf(fp
, "babeltrace from a shell.\n");
2371 fprintf(fp
, "\n\n");
2372 print_expected_params_format(fp
);
2376 * Creates a Babeltrace config object from the arguments of a run
2379 * *retcode is set to the appropriate exit code to use.
2382 struct bt_config
*bt_config_run_from_args(int argc
, const char *argv
[],
2383 int *retcode
, bool force_omit_system_plugin_path
,
2384 bool force_omit_home_plugin_path
,
2385 struct bt_private_value
*initial_plugin_paths
)
2387 poptContext pc
= NULL
;
2389 struct bt_config_component
*cur_cfg_comp
= NULL
;
2390 enum bt_config_component_dest cur_cfg_comp_dest
=
2391 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
2392 struct bt_private_value
*cur_base_params
= NULL
;
2394 struct bt_config
*cfg
= NULL
;
2395 struct bt_private_value
*instance_names
= NULL
;
2396 struct bt_private_value
*connection_args
= NULL
;
2397 GString
*cur_param_key
= NULL
;
2398 char error_buf
[256] = { 0 };
2399 long retry_duration
= -1;
2400 struct poptOption run_long_options
[] = {
2401 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2402 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2403 { "connect", 'C', POPT_ARG_STRING
, NULL
, OPT_CONNECT
, NULL
, NULL
},
2404 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2405 { "key", '\0', POPT_ARG_STRING
, NULL
, OPT_KEY
, NULL
, NULL
},
2406 { "name", 'n', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2407 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2408 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2409 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2410 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2411 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2412 { "retry-duration", '\0', POPT_ARG_LONG
, &retry_duration
, OPT_RETRY_DURATION
, NULL
, NULL
},
2413 { "value", '\0', POPT_ARG_STRING
, NULL
, OPT_VALUE
, NULL
, NULL
},
2414 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2418 cur_param_key
= g_string_new(NULL
);
2419 if (!cur_param_key
) {
2425 print_run_usage(stdout
);
2430 cfg
= bt_config_run_create(initial_plugin_paths
);
2435 cfg
->cmd_data
.run
.retry_duration_us
= 100000;
2436 cfg
->omit_system_plugin_path
= force_omit_system_plugin_path
;
2437 cfg
->omit_home_plugin_path
= force_omit_home_plugin_path
;
2438 cur_base_params
= bt_private_value_map_create();
2439 if (!cur_base_params
) {
2444 instance_names
= bt_private_value_map_create();
2445 if (!instance_names
) {
2450 connection_args
= bt_private_value_array_create();
2451 if (!connection_args
) {
2456 ret
= append_env_var_plugin_paths(cfg
->plugin_paths
);
2462 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
2463 run_long_options
, 0);
2465 printf_err("Cannot get popt context\n");
2469 poptReadDefaultConfig(pc
, 0);
2471 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2472 arg
= poptGetOptArg(pc
);
2475 case OPT_PLUGIN_PATH
:
2476 if (bt_config_append_plugin_paths_check_setuid_setgid(
2477 cfg
->plugin_paths
, arg
)) {
2481 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2482 cfg
->omit_system_plugin_path
= true;
2484 case OPT_OMIT_HOME_PLUGIN_PATH
:
2485 cfg
->omit_home_plugin_path
= true;
2489 enum bt_config_component_dest new_dest
;
2492 ret
= add_run_cfg_comp_check_name(cfg
,
2493 cur_cfg_comp
, cur_cfg_comp_dest
,
2495 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2501 cur_cfg_comp
= bt_config_component_from_arg(arg
);
2502 if (!cur_cfg_comp
) {
2503 printf_err("Invalid format for --component option's argument:\n %s\n",
2508 switch (cur_cfg_comp
->type
) {
2509 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
2510 new_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2512 case BT_COMPONENT_CLASS_TYPE_FILTER
:
2513 new_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
2515 case BT_COMPONENT_CLASS_TYPE_SINK
:
2516 new_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2522 BT_ASSERT(cur_base_params
);
2523 bt_object_put_ref(cur_cfg_comp
->params
);
2524 cur_cfg_comp
->params
= bt_value_copy(
2525 bt_value_borrow_from_private(cur_base_params
));
2526 if (!cur_cfg_comp
->params
) {
2531 cur_cfg_comp_dest
= new_dest
;
2536 struct bt_private_value
*params
;
2537 struct bt_private_value
*params_to_set
;
2539 if (!cur_cfg_comp
) {
2540 printf_err("Cannot add parameters to unavailable component:\n %s\n",
2545 params
= bt_private_value_from_arg(arg
);
2547 printf_err("Invalid format for --params option's argument:\n %s\n",
2552 params_to_set
= bt_value_map_extend(
2553 bt_value_borrow_from_private(cur_cfg_comp
->params
),
2554 bt_value_borrow_from_private(params
));
2555 BT_OBJECT_PUT_REF_AND_RESET(params
);
2556 if (!params_to_set
) {
2557 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2562 BT_OBJECT_MOVE_REF(cur_cfg_comp
->params
, params_to_set
);
2566 if (strlen(arg
) == 0) {
2567 printf_err("Cannot set an empty string as the current parameter key\n");
2571 g_string_assign(cur_param_key
, arg
);
2574 if (!cur_cfg_comp
) {
2575 printf_err("Cannot set a parameter's value of unavailable component:\n %s\n",
2580 if (cur_param_key
->len
== 0) {
2581 printf_err("--value option specified without preceding --key option:\n %s\n",
2586 if (bt_private_value_map_insert_string_entry(cur_cfg_comp
->params
,
2587 cur_param_key
->str
, arg
)) {
2593 if (!cur_cfg_comp
) {
2594 printf_err("Cannot set the name of unavailable component:\n %s\n",
2599 g_string_assign(cur_cfg_comp
->instance_name
, arg
);
2601 case OPT_BASE_PARAMS
:
2603 struct bt_private_value
*params
=
2604 bt_private_value_from_arg(arg
);
2607 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2612 BT_OBJECT_MOVE_REF(cur_base_params
, params
);
2615 case OPT_RESET_BASE_PARAMS
:
2616 BT_OBJECT_PUT_REF_AND_RESET(cur_base_params
);
2617 cur_base_params
= bt_private_value_map_create();
2618 if (!cur_base_params
) {
2624 if (bt_private_value_array_append_string_element(
2625 connection_args
, arg
)) {
2630 case OPT_RETRY_DURATION
:
2631 if (retry_duration
< 0) {
2632 printf_err("--retry-duration option's argument must be positive or 0: %ld\n",
2637 cfg
->cmd_data
.run
.retry_duration_us
=
2638 (uint64_t) retry_duration
;
2641 print_run_usage(stdout
);
2643 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2646 printf_err("Unknown command-line option specified (option code %d)\n",
2655 /* Check for option parsing error */
2657 printf_err("While parsing command-line options, at option %s: %s\n",
2658 poptBadOption(pc
, 0), poptStrerror(opt
));
2662 /* This command does not accept leftover arguments */
2663 if (poptPeekArg(pc
)) {
2664 printf_err("Unexpected argument: %s\n", poptPeekArg(pc
));
2668 /* Add current component */
2670 ret
= add_run_cfg_comp_check_name(cfg
, cur_cfg_comp
,
2671 cur_cfg_comp_dest
, instance_names
);
2672 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2678 if (cfg
->cmd_data
.run
.sources
->len
== 0) {
2679 printf_err("Incomplete graph: no source component\n");
2683 if (cfg
->cmd_data
.run
.sinks
->len
== 0) {
2684 printf_err("Incomplete graph: no sink component\n");
2688 if (append_home_and_system_plugin_paths_cfg(cfg
)) {
2692 ret
= bt_config_cli_args_create_connections(cfg
,
2693 bt_value_borrow_from_private(connection_args
),
2696 printf_err("Cannot creation connections:\n%s", error_buf
);
2704 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
2708 poptFreeContext(pc
);
2711 if (cur_param_key
) {
2712 g_string_free(cur_param_key
, TRUE
);
2716 BT_OBJECT_PUT_REF_AND_RESET(cur_cfg_comp
);
2717 BT_OBJECT_PUT_REF_AND_RESET(cur_base_params
);
2718 BT_OBJECT_PUT_REF_AND_RESET(instance_names
);
2719 BT_OBJECT_PUT_REF_AND_RESET(connection_args
);
2724 struct bt_config
*bt_config_run_from_args_array(struct bt_value
*run_args
,
2725 int *retcode
, bool force_omit_system_plugin_path
,
2726 bool force_omit_home_plugin_path
,
2727 struct bt_private_value
*initial_plugin_paths
)
2729 struct bt_config
*cfg
= NULL
;
2732 const size_t argc
= bt_value_array_get_size(run_args
) + 1;
2734 argv
= calloc(argc
, sizeof(*argv
));
2742 len
= bt_value_array_get_size(run_args
);
2744 printf_err("Invalid executable arguments\n");
2747 for (i
= 0; i
< len
; i
++) {
2749 struct bt_value
*arg_value
=
2750 bt_value_array_borrow_element_by_index(run_args
, i
);
2753 BT_ASSERT(arg_value
);
2754 ret
= bt_value_string_get(arg_value
, &arg
);
2755 BT_ASSERT(ret
== 0);
2760 cfg
= bt_config_run_from_args(argc
, argv
, retcode
,
2761 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
2762 initial_plugin_paths
);
2770 * Prints the convert command usage.
2773 void print_convert_usage(FILE *fp
)
2775 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [convert] [OPTIONS] [PATH/URL]\n");
2777 fprintf(fp
, "Options:\n");
2779 fprintf(fp
, " -c, --component=[NAME:]TYPE.PLUGIN.CLS\n");
2780 fprintf(fp
, " Instantiate the component class CLS of type\n");
2781 fprintf(fp
, " TYPE (`source`, `filter`, or `sink`) found\n");
2782 fprintf(fp
, " in the plugin PLUGIN, add it to the\n");
2783 fprintf(fp
, " conversion graph, and optionally name it\n");
2784 fprintf(fp
, " NAME (you can also specify the name with\n");
2785 fprintf(fp
, " --name)\n");
2786 fprintf(fp
, " --name=NAME Set the name of the current component\n");
2787 fprintf(fp
, " to NAME (must be unique amongst all the\n");
2788 fprintf(fp
, " names of the created components)\n");
2789 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
2790 fprintf(fp
, " (~/.local/lib/babeltrace/plugins)\n");
2791 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
2792 fprintf(fp
, " -p, --params=PARAMS Add initialization parameters PARAMS to the\n");
2793 fprintf(fp
, " current component (see the expected format\n");
2794 fprintf(fp
, " of PARAMS below)\n");
2795 fprintf(fp
, " -P, --path=PATH Set the `path` string parameter of the\n");
2796 fprintf(fp
, " current component to PATH\n");
2797 fprintf(fp
, " --plugin-path=PATH[:PATH]... Add PATH to the list of paths from which\n");
2798 fprintf(fp
, " --retry-duration=DUR When babeltrace(1) needs to retry to run\n");
2799 fprintf(fp
, " the graph later, retry in DUR µs\n");
2800 fprintf(fp
, " (default: 100000)\n");
2801 fprintf(fp
, " dynamic plugins can be loaded\n");
2802 fprintf(fp
, " --run-args Print the equivalent arguments for the\n");
2803 fprintf(fp
, " `run` command to the standard output,\n");
2804 fprintf(fp
, " formatted for a shell, and quit\n");
2805 fprintf(fp
, " --run-args-0 Print the equivalent arguments for the\n");
2806 fprintf(fp
, " `run` command to the standard output,\n");
2807 fprintf(fp
, " formatted for `xargs -0`, and quit\n");
2808 fprintf(fp
, " --stream-intersection Only process events when all streams\n");
2809 fprintf(fp
, " are active\n");
2810 fprintf(fp
, " -u, --url=URL Set the `url` string parameter of the\n");
2811 fprintf(fp
, " current component to URL\n");
2812 fprintf(fp
, " -h, --help Show this help and quit\n");
2814 fprintf(fp
, "Implicit `source.ctf.fs` component options:\n");
2816 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
2817 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS ns\n");
2819 fprintf(fp
, "Implicit `sink.text.pretty` component options:\n");
2821 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
2822 fprintf(fp
, " --clock-date Print timestamp dates\n");
2823 fprintf(fp
, " --clock-gmt Print and parse timestamps in the GMT\n");
2824 fprintf(fp
, " time zone instead of the local time zone\n");
2825 fprintf(fp
, " --clock-seconds Print the timestamps as `SEC.NS` instead\n");
2826 fprintf(fp
, " of `hh:mm:ss.nnnnnnnnn`\n");
2827 fprintf(fp
, " --color=(never | auto | always)\n");
2828 fprintf(fp
, " Never, automatically, or always emit\n");
2829 fprintf(fp
, " console color codes\n");
2830 fprintf(fp
, " -f, --fields=FIELD[,FIELD]... Print additional fields; FIELD can be:\n");
2831 fprintf(fp
, " `all`, `trace`, `trace:hostname`,\n");
2832 fprintf(fp
, " `trace:domain`, `trace:procname`,\n");
2833 fprintf(fp
, " `trace:vpid`, `loglevel`, `emf`\n");
2834 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names; NAME can be:\n");
2835 fprintf(fp
, " `payload` (or `arg` or `args`), `none`,\n");
2836 fprintf(fp
, " `all`, `scope`, `header`, `context`\n");
2837 fprintf(fp
, " (or `ctx`)\n");
2838 fprintf(fp
, " --no-delta Do not print time delta between\n");
2839 fprintf(fp
, " consecutive events\n");
2840 fprintf(fp
, " -w, --output=PATH Write output text to PATH instead of\n");
2841 fprintf(fp
, " the standard output\n");
2843 fprintf(fp
, "Implicit `filter.utils.muxer` component options:\n");
2845 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently\n");
2846 fprintf(fp
, " correlated across traces\n");
2848 fprintf(fp
, "Implicit `filter.utils.trimmer` component options:\n");
2850 fprintf(fp
, " -b, --begin=BEGIN Set the beginning time of the conversion\n");
2851 fprintf(fp
, " time range to BEGIN (see the format of\n");
2852 fprintf(fp
, " BEGIN below)\n");
2853 fprintf(fp
, " -e, --end=END Set the end time of the conversion time\n");
2854 fprintf(fp
, " range to END (see the format of END below)\n");
2855 fprintf(fp
, " -t, --timerange=TIMERANGE Set conversion time range to TIMERANGE:\n");
2856 fprintf(fp
, " BEGIN,END or [BEGIN,END] (literally `[` and\n");
2857 fprintf(fp
, " `]`) (see the format of BEGIN/END below)\n");
2859 fprintf(fp
, "Implicit `filter.lttng-utils.debug-info` component options:\n");
2861 fprintf(fp
, " --debug-info Create an implicit\n");
2862 fprintf(fp
, " `filter.lttng-utils.debug-info` component\n");
2863 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
2864 fprintf(fp
, " instead of `/usr/lib/debug`\n");
2865 fprintf(fp
, " --debug-info-full-path Show full debug info source and\n");
2866 fprintf(fp
, " binary paths instead of just names\n");
2867 fprintf(fp
, " --debug-info-target-prefix=DIR\n");
2868 fprintf(fp
, " Use directory DIR as a prefix when\n");
2869 fprintf(fp
, " looking up executables during debug\n");
2870 fprintf(fp
, " info analysis\n");
2872 fprintf(fp
, "Legacy options that still work:\n");
2874 fprintf(fp
, " -i, --input-format=(ctf | lttng-live)\n");
2875 fprintf(fp
, " `ctf`:\n");
2876 fprintf(fp
, " Create an implicit `source.ctf.fs`\n");
2877 fprintf(fp
, " component\n");
2878 fprintf(fp
, " `lttng-live`:\n");
2879 fprintf(fp
, " Create an implicit `source.ctf.lttng-live`\n");
2880 fprintf(fp
, " component\n");
2881 fprintf(fp
, " -o, --output-format=(text | ctf | dummy | ctf-metadata)\n");
2882 fprintf(fp
, " `text`:\n");
2883 fprintf(fp
, " Create an implicit `sink.text.pretty`\n");
2884 fprintf(fp
, " component\n");
2885 fprintf(fp
, " `ctf`:\n");
2886 fprintf(fp
, " Create an implicit `sink.ctf.fs`\n");
2887 fprintf(fp
, " component\n");
2888 fprintf(fp
, " `dummy`:\n");
2889 fprintf(fp
, " Create an implicit `sink.utils.dummy`\n");
2890 fprintf(fp
, " component\n");
2891 fprintf(fp
, " `ctf-metadata`:\n");
2892 fprintf(fp
, " Query the `source.ctf.fs` component class\n");
2893 fprintf(fp
, " for metadata text and quit\n");
2895 fprintf(fp
, "See `babeltrace --help` for the list of general options.\n");
2896 fprintf(fp
, "\n\n");
2897 fprintf(fp
, "Format of BEGIN and END\n");
2898 fprintf(fp
, "-----------------------\n");
2900 fprintf(fp
, " [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
2901 fprintf(fp
, "\n\n");
2902 print_expected_params_format(fp
);
2906 struct poptOption convert_long_options
[] = {
2907 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2908 { "begin", 'b', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2909 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2910 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2911 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2912 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2913 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2914 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2915 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2916 { "color", '\0', POPT_ARG_STRING
, NULL
, OPT_COLOR
, NULL
, NULL
},
2917 { "component", 'c', POPT_ARG_STRING
, NULL
, OPT_COMPONENT
, NULL
, NULL
},
2918 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2919 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2920 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2921 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2922 { "end", 'e', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2923 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2924 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2925 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2926 { "name", '\0', POPT_ARG_STRING
, NULL
, OPT_NAME
, NULL
, NULL
},
2927 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2928 { "debug-info", '\0', POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO
, NULL
, NULL
},
2929 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2930 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2931 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2932 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT
, NULL
, NULL
},
2933 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2934 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2935 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2936 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2937 { "retry-duration", '\0', POPT_ARG_STRING
, NULL
, OPT_RETRY_DURATION
, NULL
, NULL
},
2938 { "run-args", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS
, NULL
, NULL
},
2939 { "run-args-0", '\0', POPT_ARG_NONE
, NULL
, OPT_RUN_ARGS_0
, NULL
, NULL
},
2940 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2941 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2942 { "url", 'u', POPT_ARG_STRING
, NULL
, OPT_URL
, NULL
, NULL
},
2943 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2944 { NULL
, 0, '\0', NULL
, 0, NULL
, NULL
},
2948 GString
*get_component_auto_name(const char *prefix
,
2949 struct bt_value
*existing_names
)
2952 GString
*auto_name
= g_string_new(NULL
);
2959 if (!bt_value_map_has_entry(existing_names
, prefix
)) {
2960 g_string_assign(auto_name
, prefix
);
2965 g_string_printf(auto_name
, "%s-%d", prefix
, i
);
2967 } while (bt_value_map_has_entry(existing_names
, auto_name
->str
));
2973 struct implicit_component_args
{
2977 GString
*params_arg
;
2978 struct bt_private_value
*extra_params
;
2982 int assign_name_to_implicit_component(struct implicit_component_args
*args
,
2983 const char *prefix
, struct bt_private_value
*existing_names
,
2984 GList
**comp_names
, bool append_to_comp_names
)
2987 GString
*name
= NULL
;
2989 if (!args
->exists
) {
2993 name
= get_component_auto_name(prefix
,
2994 bt_value_borrow_from_private(existing_names
));
3001 g_string_assign(args
->name_arg
, name
->str
);
3003 if (bt_private_value_map_insert_entry(existing_names
, name
->str
,
3010 if (append_to_comp_names
) {
3011 *comp_names
= g_list_append(*comp_names
, name
);
3017 g_string_free(name
, TRUE
);
3024 int append_run_args_for_implicit_component(
3025 struct implicit_component_args
*impl_args
,
3026 struct bt_private_value
*run_args
)
3031 if (!impl_args
->exists
) {
3035 if (bt_private_value_array_append_string_element(run_args
, "--component")) {
3040 if (bt_private_value_array_append_string_element(run_args
, impl_args
->comp_arg
->str
)) {
3045 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3050 if (bt_private_value_array_append_string_element(run_args
, impl_args
->name_arg
->str
)) {
3055 if (impl_args
->params_arg
->len
> 0) {
3056 if (bt_private_value_array_append_string_element(run_args
, "--params")) {
3061 if (bt_private_value_array_append_string_element(run_args
,
3062 impl_args
->params_arg
->str
)) {
3068 for (i
= 0; i
< bt_value_array_get_size(
3069 bt_value_borrow_from_private(impl_args
->extra_params
));
3071 struct bt_value
*elem
;
3074 elem
= bt_value_array_borrow_element_by_index(
3075 bt_value_borrow_from_private(impl_args
->extra_params
),
3081 BT_ASSERT(bt_value_is_string(elem
));
3082 if (bt_value_string_get(elem
, &arg
)) {
3086 ret
= bt_private_value_array_append_string_element(run_args
, arg
);
3103 void finalize_implicit_component_args(struct implicit_component_args
*args
)
3107 if (args
->comp_arg
) {
3108 g_string_free(args
->comp_arg
, TRUE
);
3111 if (args
->name_arg
) {
3112 g_string_free(args
->name_arg
, TRUE
);
3115 if (args
->params_arg
) {
3116 g_string_free(args
->params_arg
, TRUE
);
3119 bt_object_put_ref(args
->extra_params
);
3123 void destroy_implicit_component_args(void *args
)
3129 finalize_implicit_component_args(args
);
3134 int init_implicit_component_args(struct implicit_component_args
*args
,
3135 const char *comp_arg
, bool exists
)
3139 args
->exists
= exists
;
3140 args
->comp_arg
= g_string_new(comp_arg
);
3141 args
->name_arg
= g_string_new(NULL
);
3142 args
->params_arg
= g_string_new(NULL
);
3143 args
->extra_params
= bt_private_value_array_create();
3145 if (!args
->comp_arg
|| !args
->name_arg
||
3146 !args
->params_arg
|| !args
->extra_params
) {
3148 finalize_implicit_component_args(args
);
3158 void append_implicit_component_param(struct implicit_component_args
*args
,
3159 const char *key
, const char *value
)
3164 append_param_arg(args
->params_arg
, key
, value
);
3168 int append_implicit_component_extra_param(struct implicit_component_args
*args
,
3169 const char *key
, const char *value
)
3177 if (bt_private_value_array_append_string_element(args
->extra_params
, "--key")) {
3183 if (bt_private_value_array_append_string_element(args
->extra_params
, key
)) {
3189 if (bt_private_value_array_append_string_element(args
->extra_params
, "--value")) {
3195 if (bt_private_value_array_append_string_element(args
->extra_params
, value
)) {
3206 int convert_append_name_param(enum bt_config_component_dest dest
,
3207 GString
*cur_name
, GString
*cur_name_prefix
,
3208 struct bt_private_value
*run_args
,
3209 struct bt_private_value
*all_names
,
3210 GList
**source_names
, GList
**filter_names
,
3215 if (cur_name_prefix
->len
> 0) {
3216 /* We're after a --component option */
3217 GString
*name
= NULL
;
3218 bool append_name_opt
= false;
3220 if (cur_name
->len
== 0) {
3222 * No explicit name was provided for the user
3225 name
= get_component_auto_name(cur_name_prefix
->str
,
3226 bt_value_borrow_from_private(all_names
));
3227 append_name_opt
= true;
3230 * An explicit name was provided for the user
3233 if (bt_value_map_has_entry(
3234 bt_value_borrow_from_private(all_names
),
3236 printf_err("Duplicate component instance name:\n %s\n",
3241 name
= g_string_new(cur_name
->str
);
3250 * Remember this name globally, for the uniqueness of
3251 * all component names.
3253 if (bt_private_value_map_insert_entry(all_names
, name
->str
, bt_value_null
)) {
3259 * Append the --name option if necessary.
3261 if (append_name_opt
) {
3262 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3267 if (bt_private_value_array_append_string_element(run_args
, name
->str
)) {
3274 * Remember this name specifically for the type of the
3275 * component. This is to create connection arguments.
3278 case BT_CONFIG_COMPONENT_DEST_SOURCE
:
3279 *source_names
= g_list_append(*source_names
, name
);
3281 case BT_CONFIG_COMPONENT_DEST_FILTER
:
3282 *filter_names
= g_list_append(*filter_names
, name
);
3284 case BT_CONFIG_COMPONENT_DEST_SINK
:
3285 *sink_names
= g_list_append(*sink_names
, name
);
3291 g_string_assign(cur_name_prefix
, "");
3304 * Escapes `.`, `:`, and `\` of `input` with `\`.
3307 GString
*escape_dot_colon(const char *input
)
3309 GString
*output
= g_string_new(NULL
);
3317 for (ch
= input
; *ch
!= '\0'; ch
++) {
3318 if (*ch
== '\\' || *ch
== '.' || *ch
== ':') {
3319 g_string_append_c(output
, '\\');
3322 g_string_append_c(output
, *ch
);
3330 * Appends a --connect option to a list of arguments. `upstream_name`
3331 * and `downstream_name` are escaped with escape_dot_colon() in this
3335 int append_connect_arg(struct bt_private_value
*run_args
,
3336 const char *upstream_name
, const char *downstream_name
)
3339 GString
*e_upstream_name
= escape_dot_colon(upstream_name
);
3340 GString
*e_downstream_name
= escape_dot_colon(downstream_name
);
3341 GString
*arg
= g_string_new(NULL
);
3343 if (!e_upstream_name
|| !e_downstream_name
|| !arg
) {
3349 ret
= bt_private_value_array_append_string_element(run_args
, "--connect");
3356 g_string_append(arg
, e_upstream_name
->str
);
3357 g_string_append_c(arg
, ':');
3358 g_string_append(arg
, e_downstream_name
->str
);
3359 ret
= bt_private_value_array_append_string_element(run_args
, arg
->str
);
3368 g_string_free(arg
, TRUE
);
3371 if (e_upstream_name
) {
3372 g_string_free(e_upstream_name
, TRUE
);
3375 if (e_downstream_name
) {
3376 g_string_free(e_downstream_name
, TRUE
);
3383 * Appends the run command's --connect options for the convert command.
3386 int convert_auto_connect(struct bt_private_value
*run_args
,
3387 GList
*source_names
, GList
*filter_names
,
3391 GList
*source_at
= source_names
;
3392 GList
*filter_at
= filter_names
;
3394 GList
*sink_at
= sink_names
;
3396 BT_ASSERT(source_names
);
3397 BT_ASSERT(filter_names
);
3398 BT_ASSERT(sink_names
);
3400 /* Connect all sources to the first filter */
3401 for (source_at
= source_names
; source_at
!= NULL
; source_at
= g_list_next(source_at
)) {
3402 GString
*source_name
= source_at
->data
;
3403 GString
*filter_name
= filter_at
->data
;
3405 ret
= append_connect_arg(run_args
, source_name
->str
,
3412 filter_prev
= filter_at
;
3413 filter_at
= g_list_next(filter_at
);
3415 /* Connect remaining filters */
3416 for (; filter_at
!= NULL
; filter_prev
= filter_at
, filter_at
= g_list_next(filter_at
)) {
3417 GString
*filter_name
= filter_at
->data
;
3418 GString
*filter_prev_name
= filter_prev
->data
;
3420 ret
= append_connect_arg(run_args
, filter_prev_name
->str
,
3427 /* Connect last filter to all sinks */
3428 for (sink_at
= sink_names
; sink_at
!= NULL
; sink_at
= g_list_next(sink_at
)) {
3429 GString
*filter_name
= filter_prev
->data
;
3430 GString
*sink_name
= sink_at
->data
;
3432 ret
= append_connect_arg(run_args
, filter_name
->str
,
3449 int split_timerange(const char *arg
, char **begin
, char **end
)
3452 const char *ch
= arg
;
3454 GString
*g_begin
= NULL
;
3455 GString
*g_end
= NULL
;
3463 g_begin
= bt_common_string_until(ch
, "", ",", &end_pos
);
3464 if (!g_begin
|| ch
[end_pos
] != ',' || g_begin
->len
== 0) {
3470 g_end
= bt_common_string_until(ch
, "", "]", &end_pos
);
3471 if (!g_end
|| g_end
->len
== 0) {
3477 *begin
= g_begin
->str
;
3479 g_string_free(g_begin
, FALSE
);
3480 g_string_free(g_end
, FALSE
);
3490 g_string_free(g_begin
, TRUE
);
3494 g_string_free(g_end
, TRUE
);
3501 int g_list_prepend_gstring(GList
**list
, const char *string
)
3504 GString
*gs
= g_string_new(string
);
3513 *list
= g_list_prepend(*list
, gs
);
3520 struct implicit_component_args
*create_implicit_component_args(void)
3522 struct implicit_component_args
*impl_args
=
3523 g_new0(struct implicit_component_args
, 1);
3529 if (init_implicit_component_args(impl_args
, NULL
, true)) {
3530 destroy_implicit_component_args(impl_args
);
3540 int fill_implicit_ctf_inputs_args(GPtrArray
*implicit_ctf_inputs_args
,
3541 struct implicit_component_args
*base_implicit_ctf_input_args
,
3547 for (leftover
= leftovers
; leftover
!= NULL
;
3548 leftover
= g_list_next(leftover
)) {
3549 GString
*gs_leftover
= leftover
->data
;
3550 struct implicit_component_args
*impl_args
=
3551 create_implicit_component_args();
3558 impl_args
->exists
= true;
3559 g_string_assign(impl_args
->comp_arg
,
3560 base_implicit_ctf_input_args
->comp_arg
->str
);
3561 g_string_assign(impl_args
->params_arg
,
3562 base_implicit_ctf_input_args
->params_arg
->str
);
3565 * We need our own copy of the extra parameters because
3566 * this is where the unique path goes.
3568 BT_OBJECT_PUT_REF_AND_RESET(impl_args
->extra_params
);
3569 impl_args
->extra_params
=
3570 bt_value_copy(bt_value_borrow_from_private(
3571 base_implicit_ctf_input_args
->extra_params
));
3572 if (!impl_args
->extra_params
) {
3574 destroy_implicit_component_args(impl_args
);
3578 /* Append unique path parameter */
3579 ret
= append_implicit_component_extra_param(impl_args
,
3580 "path", gs_leftover
->str
);
3582 destroy_implicit_component_args(impl_args
);
3586 g_ptr_array_add(implicit_ctf_inputs_args
, impl_args
);
3599 * Creates a Babeltrace config object from the arguments of a convert
3602 * *retcode is set to the appropriate exit code to use.
3605 struct bt_config
*bt_config_convert_from_args(int argc
, const char *argv
[],
3606 int *retcode
, bool force_omit_system_plugin_path
,
3607 bool force_omit_home_plugin_path
,
3608 struct bt_private_value
*initial_plugin_paths
, char *log_level
)
3610 poptContext pc
= NULL
;
3612 enum bt_config_component_dest cur_comp_dest
=
3613 BT_CONFIG_COMPONENT_DEST_UNKNOWN
;
3615 struct bt_config
*cfg
= NULL
;
3616 bool got_input_format_opt
= false;
3617 bool got_output_format_opt
= false;
3618 bool trimmer_has_begin
= false;
3619 bool trimmer_has_end
= false;
3620 bool stream_intersection_mode
= false;
3621 GString
*cur_name
= NULL
;
3622 GString
*cur_name_prefix
= NULL
;
3623 const char *leftover
= NULL
;
3624 bool print_run_args
= false;
3625 bool print_run_args_0
= false;
3626 bool print_ctf_metadata
= false;
3627 struct bt_private_value
*run_args
= NULL
;
3628 struct bt_private_value
*all_names
= NULL
;
3629 GList
*source_names
= NULL
;
3630 GList
*filter_names
= NULL
;
3631 GList
*sink_names
= NULL
;
3632 GList
*leftovers
= NULL
;
3633 GPtrArray
*implicit_ctf_inputs_args
= NULL
;
3634 struct implicit_component_args base_implicit_ctf_input_args
= { 0 };
3635 struct implicit_component_args implicit_ctf_output_args
= { 0 };
3636 struct implicit_component_args implicit_lttng_live_args
= { 0 };
3637 struct implicit_component_args implicit_dummy_args
= { 0 };
3638 struct implicit_component_args implicit_text_args
= { 0 };
3639 struct implicit_component_args implicit_debug_info_args
= { 0 };
3640 struct implicit_component_args implicit_muxer_args
= { 0 };
3641 struct implicit_component_args implicit_trimmer_args
= { 0 };
3642 struct bt_private_value
*plugin_paths
=
3643 bt_object_get_ref(initial_plugin_paths
);
3644 char error_buf
[256] = { 0 };
3646 struct bt_common_lttng_live_url_parts lttng_live_url_parts
= { 0 };
3647 char *output
= NULL
;
3652 print_convert_usage(stdout
);
3657 if (init_implicit_component_args(&base_implicit_ctf_input_args
,
3658 "source.ctf.fs", false)) {
3662 if (init_implicit_component_args(&implicit_ctf_output_args
,
3663 "sink.ctf.fs", false)) {
3667 if (init_implicit_component_args(&implicit_lttng_live_args
,
3668 "source.ctf.lttng-live", false)) {
3672 if (init_implicit_component_args(&implicit_text_args
,
3673 "sink.text.pretty", false)) {
3677 if (init_implicit_component_args(&implicit_dummy_args
,
3678 "sink.utils.dummy", false)) {
3682 if (init_implicit_component_args(&implicit_debug_info_args
,
3683 "filter.lttng-utils.debug-info", false)) {
3687 if (init_implicit_component_args(&implicit_muxer_args
,
3688 "filter.utils.muxer", true)) {
3692 if (init_implicit_component_args(&implicit_trimmer_args
,
3693 "filter.utils.trimmer", false)) {
3697 implicit_ctf_inputs_args
= g_ptr_array_new_with_free_func(
3698 (GDestroyNotify
) destroy_implicit_component_args
);
3699 if (!implicit_ctf_inputs_args
) {
3704 all_names
= bt_private_value_map_create();
3710 run_args
= bt_private_value_array_create();
3716 cur_name
= g_string_new(NULL
);
3722 cur_name_prefix
= g_string_new(NULL
);
3723 if (!cur_name_prefix
) {
3728 ret
= append_env_var_plugin_paths(plugin_paths
);
3734 * First pass: collect all arguments which need to be passed
3735 * as is to the run command. This pass can also add --name
3736 * arguments if needed to automatically name unnamed component
3737 * instances. Also it does the following transformations:
3739 * --path=PATH -> --key path --value PATH
3740 * --url=URL -> --key url --value URL
3742 * Also it appends the plugin paths of --plugin-path to
3745 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
3746 convert_long_options
, 0);
3748 printf_err("Cannot get popt context\n");
3752 poptReadDefaultConfig(pc
, 0);
3754 while ((opt
= poptGetNextOpt(pc
)) > 0) {
3756 char *plugin_name
= NULL
;
3757 char *comp_cls_name
= NULL
;
3759 arg
= poptGetOptArg(pc
);
3764 enum bt_component_class_type type
;
3765 const char *type_prefix
;
3767 /* Append current component's name if needed */
3768 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
3769 cur_name_prefix
, run_args
, all_names
,
3770 &source_names
, &filter_names
, &sink_names
);
3775 /* Parse the argument */
3776 plugin_comp_cls_names(arg
, &name
, &plugin_name
,
3777 &comp_cls_name
, &type
);
3778 if (!plugin_name
|| !comp_cls_name
) {
3779 printf_err("Invalid format for --component option's argument:\n %s\n",
3785 g_string_assign(cur_name
, name
);
3787 g_string_assign(cur_name
, "");
3791 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
3792 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
3793 type_prefix
= "source";
3795 case BT_COMPONENT_CLASS_TYPE_FILTER
:
3796 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_FILTER
;
3797 type_prefix
= "filter";
3799 case BT_COMPONENT_CLASS_TYPE_SINK
:
3800 cur_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
3801 type_prefix
= "sink";
3807 if (bt_private_value_array_append_string_element(run_args
,
3813 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3818 g_string_assign(cur_name_prefix
, "");
3819 g_string_append_printf(cur_name_prefix
, "%s.%s.%s",
3820 type_prefix
, plugin_name
, comp_cls_name
);
3823 free(comp_cls_name
);
3826 comp_cls_name
= NULL
;
3830 if (cur_name_prefix
->len
== 0) {
3831 printf_err("No current component of which to set parameters:\n %s\n",
3836 if (bt_private_value_array_append_string_element(run_args
,
3842 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3848 if (cur_name_prefix
->len
== 0) {
3849 printf_err("No current component of which to set `path` parameter:\n %s\n",
3854 if (bt_private_value_array_append_string_element(run_args
, "--key")) {
3859 if (bt_private_value_array_append_string_element(run_args
, "path")) {
3864 if (bt_private_value_array_append_string_element(run_args
, "--value")) {
3869 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3875 if (cur_name_prefix
->len
== 0) {
3876 printf_err("No current component of which to set `url` parameter:\n %s\n",
3881 if (bt_private_value_array_append_string_element(run_args
, "--key")) {
3886 if (bt_private_value_array_append_string_element(run_args
, "url")) {
3891 if (bt_private_value_array_append_string_element(run_args
, "--value")) {
3896 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3902 if (cur_name_prefix
->len
== 0) {
3903 printf_err("No current component to name:\n %s\n",
3908 if (bt_private_value_array_append_string_element(run_args
, "--name")) {
3913 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3918 g_string_assign(cur_name
, arg
);
3920 case OPT_OMIT_HOME_PLUGIN_PATH
:
3921 force_omit_home_plugin_path
= true;
3923 if (bt_private_value_array_append_string_element(run_args
,
3924 "--omit-home-plugin-path")) {
3929 case OPT_RETRY_DURATION
:
3930 if (bt_private_value_array_append_string_element(run_args
,
3931 "--retry-duration")) {
3936 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3941 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
3942 force_omit_system_plugin_path
= true;
3944 if (bt_private_value_array_append_string_element(run_args
,
3945 "--omit-system-plugin-path")) {
3950 case OPT_PLUGIN_PATH
:
3951 if (bt_config_append_plugin_paths_check_setuid_setgid(
3952 plugin_paths
, arg
)) {
3956 if (bt_private_value_array_append_string_element(run_args
,
3962 if (bt_private_value_array_append_string_element(run_args
, arg
)) {
3968 print_convert_usage(stdout
);
3970 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
3973 case OPT_CLOCK_CYCLES
:
3974 case OPT_CLOCK_DATE
:
3975 case OPT_CLOCK_FORCE_CORRELATE
:
3977 case OPT_CLOCK_OFFSET
:
3978 case OPT_CLOCK_OFFSET_NS
:
3979 case OPT_CLOCK_SECONDS
:
3982 case OPT_DEBUG_INFO
:
3983 case OPT_DEBUG_INFO_DIR
:
3984 case OPT_DEBUG_INFO_FULL_PATH
:
3985 case OPT_DEBUG_INFO_TARGET_PREFIX
:
3988 case OPT_INPUT_FORMAT
:
3991 case OPT_OUTPUT_FORMAT
:
3994 case OPT_RUN_ARGS_0
:
3995 case OPT_STREAM_INTERSECTION
:
3998 /* Ignore in this pass */
4001 printf_err("Unknown command-line option specified (option code %d)\n",
4010 /* Append current component's name if needed */
4011 ret
= convert_append_name_param(cur_comp_dest
, cur_name
,
4012 cur_name_prefix
, run_args
, all_names
, &source_names
,
4013 &filter_names
, &sink_names
);
4018 /* Check for option parsing error */
4020 printf_err("While parsing command-line options, at option %s: %s\n",
4021 poptBadOption(pc
, 0), poptStrerror(opt
));
4025 poptFreeContext(pc
);
4030 * Second pass: transform the convert-specific options and
4031 * arguments into implicit component instances for the run
4034 pc
= poptGetContext(NULL
, argc
, (const char **) argv
,
4035 convert_long_options
, 0);
4037 printf_err("Cannot get popt context\n");
4041 poptReadDefaultConfig(pc
, 0);
4043 while ((opt
= poptGetNextOpt(pc
)) > 0) {
4044 arg
= poptGetOptArg(pc
);
4048 if (trimmer_has_begin
) {
4049 printf("At --begin option: --begin or --timerange option already specified\n %s\n",
4054 trimmer_has_begin
= true;
4055 ret
= append_implicit_component_extra_param(
4056 &implicit_trimmer_args
, "begin", arg
);
4057 implicit_trimmer_args
.exists
= true;
4063 if (trimmer_has_end
) {
4064 printf("At --end option: --end or --timerange option already specified\n %s\n",
4069 trimmer_has_end
= true;
4070 ret
= append_implicit_component_extra_param(
4071 &implicit_trimmer_args
, "end", arg
);
4072 implicit_trimmer_args
.exists
= true;
4082 if (trimmer_has_begin
|| trimmer_has_end
) {
4083 printf("At --timerange option: --begin, --end, or --timerange option already specified\n %s\n",
4088 ret
= split_timerange(arg
, &begin
, &end
);
4090 printf_err("Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:\n %s\n",
4095 ret
= append_implicit_component_extra_param(
4096 &implicit_trimmer_args
, "begin", begin
);
4097 ret
|= append_implicit_component_extra_param(
4098 &implicit_trimmer_args
, "end", end
);
4099 implicit_trimmer_args
.exists
= true;
4107 case OPT_CLOCK_CYCLES
:
4108 append_implicit_component_param(
4109 &implicit_text_args
, "clock-cycles", "yes");
4110 implicit_text_args
.exists
= true;
4112 case OPT_CLOCK_DATE
:
4113 append_implicit_component_param(
4114 &implicit_text_args
, "clock-date", "yes");
4115 implicit_text_args
.exists
= true;
4117 case OPT_CLOCK_FORCE_CORRELATE
:
4118 append_implicit_component_param(
4119 &implicit_muxer_args
,
4120 "assume-absolute-clock-classes", "yes");
4123 append_implicit_component_param(
4124 &implicit_text_args
, "clock-gmt", "yes");
4125 append_implicit_component_param(
4126 &implicit_trimmer_args
, "clock-gmt", "yes");
4127 implicit_text_args
.exists
= true;
4129 case OPT_CLOCK_OFFSET
:
4130 base_implicit_ctf_input_args
.exists
= true;
4131 append_implicit_component_param(
4132 &base_implicit_ctf_input_args
,
4133 "clock-class-offset-s", arg
);
4135 case OPT_CLOCK_OFFSET_NS
:
4136 base_implicit_ctf_input_args
.exists
= true;
4137 append_implicit_component_param(
4138 &base_implicit_ctf_input_args
,
4139 "clock-class-offset-ns", arg
);
4141 case OPT_CLOCK_SECONDS
:
4142 append_implicit_component_param(
4143 &implicit_text_args
, "clock-seconds", "yes");
4144 implicit_text_args
.exists
= true;
4147 implicit_text_args
.exists
= true;
4148 ret
= append_implicit_component_extra_param(
4149 &implicit_text_args
, "color", arg
);
4154 case OPT_DEBUG_INFO
:
4155 implicit_debug_info_args
.exists
= true;
4157 case OPT_DEBUG_INFO_DIR
:
4158 implicit_debug_info_args
.exists
= true;
4159 ret
= append_implicit_component_extra_param(
4160 &implicit_debug_info_args
, "debug-info-dir", arg
);
4165 case OPT_DEBUG_INFO_FULL_PATH
:
4166 implicit_debug_info_args
.exists
= true;
4167 append_implicit_component_param(
4168 &implicit_debug_info_args
, "full-path", "yes");
4170 case OPT_DEBUG_INFO_TARGET_PREFIX
:
4171 implicit_debug_info_args
.exists
= true;
4172 ret
= append_implicit_component_extra_param(
4173 &implicit_debug_info_args
,
4174 "target-prefix", arg
);
4181 struct bt_private_value
*fields
= fields_from_arg(arg
);
4187 implicit_text_args
.exists
= true;
4188 ret
= insert_flat_params_from_array(
4189 implicit_text_args
.params_arg
,
4190 bt_value_borrow_from_private(fields
), "field");
4191 bt_object_put_ref(fields
);
4199 struct bt_private_value
*names
= names_from_arg(arg
);
4205 implicit_text_args
.exists
= true;
4206 ret
= insert_flat_params_from_array(
4207 implicit_text_args
.params_arg
,
4208 bt_value_borrow_from_private(names
), "name");
4209 bt_object_put_ref(names
);
4216 append_implicit_component_param(
4217 &implicit_text_args
, "no-delta", "yes");
4218 implicit_text_args
.exists
= true;
4220 case OPT_INPUT_FORMAT
:
4221 if (got_input_format_opt
) {
4222 printf_err("Duplicate --input-format option\n");
4226 got_input_format_opt
= true;
4228 if (strcmp(arg
, "ctf") == 0) {
4229 base_implicit_ctf_input_args
.exists
= true;
4230 } else if (strcmp(arg
, "lttng-live") == 0) {
4231 implicit_lttng_live_args
.exists
= true;
4233 printf_err("Unknown legacy input format:\n %s\n",
4238 case OPT_OUTPUT_FORMAT
:
4239 if (got_output_format_opt
) {
4240 printf_err("Duplicate --output-format option\n");
4244 got_output_format_opt
= true;
4246 if (strcmp(arg
, "text") == 0) {
4247 implicit_text_args
.exists
= true;
4248 } else if (strcmp(arg
, "ctf") == 0) {
4249 implicit_ctf_output_args
.exists
= true;
4250 } else if (strcmp(arg
, "dummy") == 0) {
4251 implicit_dummy_args
.exists
= true;
4252 } else if (strcmp(arg
, "ctf-metadata") == 0) {
4253 print_ctf_metadata
= true;
4255 printf_err("Unknown legacy output format:\n %s\n",
4262 printf_err("Duplicate --output option\n");
4266 output
= strdup(arg
);
4273 if (print_run_args_0
) {
4274 printf_err("Cannot specify --run-args and --run-args-0\n");
4278 print_run_args
= true;
4280 case OPT_RUN_ARGS_0
:
4281 if (print_run_args
) {
4282 printf_err("Cannot specify --run-args and --run-args-0\n");
4286 print_run_args_0
= true;
4288 case OPT_STREAM_INTERSECTION
:
4290 * Applies to all traces implementing the trace-info
4293 stream_intersection_mode
= true;
4296 if (*log_level
!= 'V' && *log_level
!= 'D') {
4309 /* Check for option parsing error */
4311 printf_err("While parsing command-line options, at option %s: %s\n",
4312 poptBadOption(pc
, 0), poptStrerror(opt
));
4317 * Legacy behaviour: --verbose used to make the `text` output
4318 * format print more information. --verbose is now equivalent to
4319 * the INFO log level, which is why we compare to 'I' here.
4321 if (*log_level
== 'I') {
4322 append_implicit_component_param(&implicit_text_args
,
4327 * Append home and system plugin paths now that we possibly got
4330 if (append_home_and_system_plugin_paths(plugin_paths
,
4331 force_omit_system_plugin_path
,
4332 force_omit_home_plugin_path
)) {
4336 /* Consume and keep leftover arguments */
4337 while ((leftover
= poptGetArg(pc
))) {
4338 GString
*gs_leftover
= g_string_new(leftover
);
4345 leftovers
= g_list_append(leftovers
, gs_leftover
);
4347 g_string_free(gs_leftover
, TRUE
);
4353 /* Print CTF metadata or print LTTng live sessions */
4354 if (print_ctf_metadata
) {
4355 GString
*gs_leftover
;
4357 if (g_list_length(leftovers
) == 0) {
4358 printf_err("--output-format=ctf-metadata specified without a path\n");
4362 if (g_list_length(leftovers
) > 1) {
4363 printf_err("Too many paths specified for --output-format=ctf-metadata\n");
4367 cfg
= bt_config_print_ctf_metadata_create(plugin_paths
);
4372 gs_leftover
= leftovers
->data
;
4373 g_string_assign(cfg
->cmd_data
.print_ctf_metadata
.path
,
4378 cfg
->cmd_data
.print_ctf_metadata
.output_path
,
4386 * If -o ctf was specified, make sure an output path (--output)
4387 * was also specified. --output does not imply -o ctf because
4388 * it's also used for the default, implicit -o text if -o ctf
4391 if (implicit_ctf_output_args
.exists
) {
4393 printf_err("--output-format=ctf specified without --output (trace output path)\n");
4398 * At this point we know that -o ctf AND --output were
4399 * specified. Make sure that no options were specified
4400 * which would imply -o text because --output would be
4401 * ambiguous in this case. For example, this is wrong:
4403 * babeltrace --names=all -o ctf --output=/tmp/path my-trace
4405 * because --names=all implies -o text, and --output
4406 * could apply to both the sink.text.pretty and
4407 * sink.ctf.fs implicit components.
4409 if (implicit_text_args
.exists
) {
4410 printf_err("Ambiguous --output option: --output-format=ctf specified but another option implies --output-format=text\n");
4416 * If -o dummy and -o ctf were not specified, and if there are
4417 * no explicit sink components, then use an implicit
4418 * `sink.text.pretty` component.
4420 if (!implicit_dummy_args
.exists
&& !implicit_ctf_output_args
.exists
&&
4422 implicit_text_args
.exists
= true;
4426 * Set implicit `sink.text.pretty` or `sink.ctf.fs` component's
4427 * `path` parameter if --output was specified.
4430 if (implicit_text_args
.exists
) {
4431 append_implicit_component_extra_param(&implicit_text_args
,
4433 } else if (implicit_ctf_output_args
.exists
) {
4434 append_implicit_component_extra_param(&implicit_ctf_output_args
,
4439 /* Decide where the leftover argument(s) go */
4440 if (g_list_length(leftovers
) > 0) {
4441 if (implicit_lttng_live_args
.exists
) {
4442 GString
*gs_leftover
;
4444 if (g_list_length(leftovers
) > 1) {
4445 printf_err("Too many URLs specified for --output-format=lttng-live\n");
4449 gs_leftover
= leftovers
->data
;
4450 lttng_live_url_parts
=
4451 bt_common_parse_lttng_live_url(gs_leftover
->str
,
4452 error_buf
, sizeof(error_buf
));
4453 if (!lttng_live_url_parts
.proto
) {
4454 printf_err("Invalid LTTng live URL format: %s\n",
4459 if (!lttng_live_url_parts
.session_name
) {
4460 /* Print LTTng live sessions */
4461 cfg
= bt_config_print_lttng_live_sessions_create(
4467 g_string_assign(cfg
->cmd_data
.print_lttng_live_sessions
.url
,
4472 cfg
->cmd_data
.print_lttng_live_sessions
.output_path
,
4479 ret
= append_implicit_component_extra_param(
4480 &implicit_lttng_live_args
, "url",
4487 * Append one implicit component argument set
4488 * for each leftover (souce.ctf.fs paths). Copy
4489 * the base implicit component arguments.
4490 * Note that they still have to be named later.
4492 ret
= fill_implicit_ctf_inputs_args(
4493 implicit_ctf_inputs_args
,
4494 &base_implicit_ctf_input_args
, leftovers
);
4502 * Ensure mutual exclusion between implicit `source.ctf.fs` and
4503 * `source.ctf.lttng-live` components.
4505 if (base_implicit_ctf_input_args
.exists
&&
4506 implicit_lttng_live_args
.exists
) {
4507 printf_err("Cannot create both implicit `%s` and `%s` components\n",
4508 base_implicit_ctf_input_args
.comp_arg
->str
,
4509 implicit_lttng_live_args
.comp_arg
->str
);
4514 * If the implicit `source.ctf.fs` or `source.ctf.lttng-live`
4515 * components exists, make sure there's at least one leftover
4516 * (which is the path or URL).
4518 if (base_implicit_ctf_input_args
.exists
&&
4519 g_list_length(leftovers
) == 0) {
4520 printf_err("Missing path for implicit `%s` component\n",
4521 base_implicit_ctf_input_args
.comp_arg
->str
);
4525 if (implicit_lttng_live_args
.exists
&& g_list_length(leftovers
) == 0) {
4526 printf_err("Missing URL for implicit `%s` component\n",
4527 implicit_lttng_live_args
.comp_arg
->str
);
4531 /* Assign names to implicit components */
4532 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4533 struct implicit_component_args
*impl_args
=
4534 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4536 ret
= assign_name_to_implicit_component(impl_args
,
4537 "source-ctf-fs", all_names
, &source_names
, true);
4543 ret
= assign_name_to_implicit_component(&implicit_lttng_live_args
,
4544 "lttng-live", all_names
, &source_names
, true);
4549 ret
= assign_name_to_implicit_component(&implicit_text_args
,
4550 "pretty", all_names
, &sink_names
, true);
4555 ret
= assign_name_to_implicit_component(&implicit_ctf_output_args
,
4556 "sink-ctf-fs", all_names
, &sink_names
, true);
4561 ret
= assign_name_to_implicit_component(&implicit_dummy_args
,
4562 "dummy", all_names
, &sink_names
, true);
4567 ret
= assign_name_to_implicit_component(&implicit_muxer_args
,
4568 "muxer", all_names
, NULL
, false);
4573 ret
= assign_name_to_implicit_component(&implicit_trimmer_args
,
4574 "trimmer", all_names
, NULL
, false);
4579 ret
= assign_name_to_implicit_component(&implicit_debug_info_args
,
4580 "debug-info", all_names
, NULL
, false);
4585 /* Make sure there's at least one source and one sink */
4586 if (!source_names
) {
4587 printf_err("No source component\n");
4592 printf_err("No sink component\n");
4597 * Prepend the muxer, the trimmer, and the debug info to the
4598 * filter chain so that we have:
4600 * sources -> muxer -> [trimmer] -> [debug info] ->
4601 * [user filters] -> sinks
4603 if (implicit_debug_info_args
.exists
) {
4604 if (g_list_prepend_gstring(&filter_names
,
4605 implicit_debug_info_args
.name_arg
->str
)) {
4610 if (implicit_trimmer_args
.exists
) {
4611 if (g_list_prepend_gstring(&filter_names
,
4612 implicit_trimmer_args
.name_arg
->str
)) {
4617 if (g_list_prepend_gstring(&filter_names
,
4618 implicit_muxer_args
.name_arg
->str
)) {
4623 * Append the equivalent run arguments for the implicit
4626 for (i
= 0; i
< implicit_ctf_inputs_args
->len
; i
++) {
4627 struct implicit_component_args
*impl_args
=
4628 g_ptr_array_index(implicit_ctf_inputs_args
, i
);
4630 ret
= append_run_args_for_implicit_component(impl_args
,
4637 ret
= append_run_args_for_implicit_component(&implicit_lttng_live_args
,
4643 ret
= append_run_args_for_implicit_component(&implicit_text_args
,
4649 ret
= append_run_args_for_implicit_component(&implicit_ctf_output_args
,
4655 ret
= append_run_args_for_implicit_component(&implicit_dummy_args
,
4661 ret
= append_run_args_for_implicit_component(&implicit_muxer_args
,
4667 ret
= append_run_args_for_implicit_component(&implicit_trimmer_args
,
4673 ret
= append_run_args_for_implicit_component(&implicit_debug_info_args
,
4679 /* Auto-connect components */
4680 ret
= convert_auto_connect(run_args
, source_names
, filter_names
,
4683 printf_err("Cannot auto-connect components\n");
4688 * We have all the run command arguments now. Depending on
4689 * --run-args, we pass this to the run command or print them
4692 if (print_run_args
|| print_run_args_0
) {
4693 if (stream_intersection_mode
) {
4694 printf_err("Cannot specify --stream-intersection with --run-args or --run-args-0\n");
4698 for (i
= 0; i
< bt_value_array_get_size(
4699 bt_value_borrow_from_private(run_args
)); i
++) {
4700 struct bt_value
*arg_value
=
4701 bt_value_array_borrow_element_by_index(
4702 bt_value_borrow_from_private(run_args
),
4705 GString
*quoted
= NULL
;
4706 const char *arg_to_print
;
4708 BT_ASSERT(arg_value
);
4709 ret
= bt_value_string_get(arg_value
, &arg
);
4710 BT_ASSERT(ret
== 0);
4712 if (print_run_args
) {
4713 quoted
= bt_common_shell_quote(arg
, true);
4718 arg_to_print
= quoted
->str
;
4723 printf("%s", arg_to_print
);
4726 g_string_free(quoted
, TRUE
);
4729 if (i
< bt_value_array_get_size(
4730 bt_value_borrow_from_private(run_args
)) - 1) {
4731 if (print_run_args
) {
4740 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4744 cfg
= bt_config_run_from_args_array(
4745 bt_value_borrow_from_private(run_args
), retcode
,
4746 force_omit_system_plugin_path
, force_omit_home_plugin_path
,
4747 initial_plugin_paths
);
4752 cfg
->cmd_data
.run
.stream_intersection_mode
= stream_intersection_mode
;
4757 BT_OBJECT_PUT_REF_AND_RESET(cfg
);
4761 poptFreeContext(pc
);
4768 g_string_free(cur_name
, TRUE
);
4771 if (cur_name_prefix
) {
4772 g_string_free(cur_name_prefix
, TRUE
);
4775 if (implicit_ctf_inputs_args
) {
4776 g_ptr_array_free(implicit_ctf_inputs_args
, TRUE
);
4779 bt_object_put_ref(run_args
);
4780 bt_object_put_ref(all_names
);
4781 destroy_glist_of_gstring(source_names
);
4782 destroy_glist_of_gstring(filter_names
);
4783 destroy_glist_of_gstring(sink_names
);
4784 destroy_glist_of_gstring(leftovers
);
4785 finalize_implicit_component_args(&base_implicit_ctf_input_args
);
4786 finalize_implicit_component_args(&implicit_ctf_output_args
);
4787 finalize_implicit_component_args(&implicit_lttng_live_args
);
4788 finalize_implicit_component_args(&implicit_dummy_args
);
4789 finalize_implicit_component_args(&implicit_text_args
);
4790 finalize_implicit_component_args(&implicit_debug_info_args
);
4791 finalize_implicit_component_args(&implicit_muxer_args
);
4792 finalize_implicit_component_args(&implicit_trimmer_args
);
4793 bt_object_put_ref(plugin_paths
);
4794 bt_common_destroy_lttng_live_url_parts(<tng_live_url_parts
);
4799 * Prints the Babeltrace 2.x general usage.
4802 void print_gen_usage(FILE *fp
)
4804 fprintf(fp
, "Usage: babeltrace [GENERAL OPTIONS] [COMMAND] [COMMAND ARGUMENTS]\n");
4806 fprintf(fp
, "General options:\n");
4808 fprintf(fp
, " -d, --debug Enable debug mode (same as --log-level=V)\n");
4809 fprintf(fp
, " -h, --help Show this help and quit\n");
4810 fprintf(fp
, " -l, --log-level=LVL Set all log levels to LVL (`N`, `V`, `D`,\n");
4811 fprintf(fp
, " `I`, `W` (default), `E`, or `F`)\n");
4812 fprintf(fp
, " -v, --verbose Enable verbose mode (same as --log-level=I)\n");
4813 fprintf(fp
, " -V, --version Show version and quit\n");
4815 fprintf(fp
, "Available commands:\n");
4817 fprintf(fp
, " convert Convert and trim traces (default)\n");
4818 fprintf(fp
, " help Get help for a plugin or a component class\n");
4819 fprintf(fp
, " list-plugins List available plugins and their content\n");
4820 fprintf(fp
, " query Query objects from a component class\n");
4821 fprintf(fp
, " run Build a processing graph and run it\n");
4823 fprintf(fp
, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
4827 char log_level_from_arg(const char *arg
)
4831 if (strcmp(arg
, "VERBOSE") == 0 ||
4832 strcmp(arg
, "V") == 0) {
4834 } else if (strcmp(arg
, "DEBUG") == 0 ||
4835 strcmp(arg
, "D") == 0) {
4837 } else if (strcmp(arg
, "INFO") == 0 ||
4838 strcmp(arg
, "I") == 0) {
4840 } else if (strcmp(arg
, "WARN") == 0 ||
4841 strcmp(arg
, "WARNING") == 0 ||
4842 strcmp(arg
, "W") == 0) {
4844 } else if (strcmp(arg
, "ERROR") == 0 ||
4845 strcmp(arg
, "E") == 0) {
4847 } else if (strcmp(arg
, "FATAL") == 0 ||
4848 strcmp(arg
, "F") == 0) {
4850 } else if (strcmp(arg
, "NONE") == 0 ||
4851 strcmp(arg
, "N") == 0) {
4858 struct bt_config
*bt_config_cli_args_create(int argc
, const char *argv
[],
4859 int *retcode
, bool force_omit_system_plugin_path
,
4860 bool force_omit_home_plugin_path
,
4861 struct bt_private_value
*initial_plugin_paths
)
4863 struct bt_config
*config
= NULL
;
4865 const char **command_argv
= NULL
;
4866 int command_argc
= -1;
4867 const char *command_name
= NULL
;
4868 char log_level
= 'U';
4871 COMMAND_TYPE_NONE
= -1,
4872 COMMAND_TYPE_RUN
= 0,
4873 COMMAND_TYPE_CONVERT
,
4874 COMMAND_TYPE_LIST_PLUGINS
,
4877 } command_type
= COMMAND_TYPE_NONE
;
4881 if (!initial_plugin_paths
) {
4882 initial_plugin_paths
= bt_private_value_array_create();
4883 if (!initial_plugin_paths
) {
4888 bt_object_get_ref(initial_plugin_paths
);
4894 print_gen_usage(stdout
);
4898 for (i
= 1; i
< argc
; i
++) {
4899 const char *cur_arg
= argv
[i
];
4900 const char *next_arg
= i
== (argc
- 1) ? NULL
: argv
[i
+ 1];
4902 if (strcmp(cur_arg
, "-d") == 0 ||
4903 strcmp(cur_arg
, "--debug") == 0) {
4905 } else if (strcmp(cur_arg
, "-v") == 0 ||
4906 strcmp(cur_arg
, "--verbose") == 0) {
4907 if (log_level
!= 'V' && log_level
!= 'D') {
4909 * Legacy: do not override a previous
4910 * --debug because --verbose and --debug
4911 * can be specified together (in this
4912 * case we want the lowest log level to
4917 } else if (strcmp(cur_arg
, "--log-level") == 0 ||
4918 strcmp(cur_arg
, "-l") == 0) {
4920 printf_err("Missing log level value for --log-level option\n");
4925 log_level
= log_level_from_arg(next_arg
);
4926 if (log_level
== 'U') {
4927 printf_err("Invalid argument for --log-level option:\n %s\n",
4934 } else if (strncmp(cur_arg
, "--log-level=", 12) == 0) {
4935 const char *arg
= &cur_arg
[12];
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 (strncmp(cur_arg
, "-l", 2) == 0) {
4945 const char *arg
= &cur_arg
[2];
4947 log_level
= log_level_from_arg(arg
);
4948 if (log_level
== 'U') {
4949 printf_err("Invalid argument for --log-level option:\n %s\n",
4954 } else if (strcmp(cur_arg
, "-V") == 0 ||
4955 strcmp(cur_arg
, "--version") == 0) {
4958 } else if (strcmp(cur_arg
, "-h") == 0 ||
4959 strcmp(cur_arg
, "--help") == 0) {
4960 print_gen_usage(stdout
);
4964 * First unknown argument: is it a known command
4967 command_argv
= &argv
[i
];
4968 command_argc
= argc
- i
;
4970 if (strcmp(cur_arg
, "convert") == 0) {
4971 command_type
= COMMAND_TYPE_CONVERT
;
4972 } else if (strcmp(cur_arg
, "list-plugins") == 0) {
4973 command_type
= COMMAND_TYPE_LIST_PLUGINS
;
4974 } else if (strcmp(cur_arg
, "help") == 0) {
4975 command_type
= COMMAND_TYPE_HELP
;
4976 } else if (strcmp(cur_arg
, "query") == 0) {
4977 command_type
= COMMAND_TYPE_QUERY
;
4978 } else if (strcmp(cur_arg
, "run") == 0) {
4979 command_type
= COMMAND_TYPE_RUN
;
4982 * Unknown argument, but not a known
4983 * command name: assume the default
4984 * `convert` command.
4986 command_type
= COMMAND_TYPE_CONVERT
;
4987 command_name
= "convert";
4988 command_argv
= &argv
[i
- 1];
4989 command_argc
= argc
- i
+ 1;
4995 if (command_type
== COMMAND_TYPE_NONE
) {
4997 * We only got non-help, non-version general options
4998 * like --verbose and --debug, without any other
4999 * arguments, so we can't do anything useful: print the
5002 print_gen_usage(stdout
);
5006 BT_ASSERT(command_argv
);
5007 BT_ASSERT(command_argc
>= 0);
5009 switch (command_type
) {
5010 case COMMAND_TYPE_RUN
:
5011 config
= bt_config_run_from_args(command_argc
, command_argv
,
5012 retcode
, force_omit_system_plugin_path
,
5013 force_omit_home_plugin_path
, initial_plugin_paths
);
5015 case COMMAND_TYPE_CONVERT
:
5016 config
= bt_config_convert_from_args(command_argc
, command_argv
,
5017 retcode
, force_omit_system_plugin_path
,
5018 force_omit_home_plugin_path
,
5019 initial_plugin_paths
, &log_level
);
5021 case COMMAND_TYPE_LIST_PLUGINS
:
5022 config
= bt_config_list_plugins_from_args(command_argc
,
5023 command_argv
, retcode
, force_omit_system_plugin_path
,
5024 force_omit_home_plugin_path
, initial_plugin_paths
);
5026 case COMMAND_TYPE_HELP
:
5027 config
= bt_config_help_from_args(command_argc
,
5028 command_argv
, retcode
, force_omit_system_plugin_path
,
5029 force_omit_home_plugin_path
, initial_plugin_paths
);
5031 case COMMAND_TYPE_QUERY
:
5032 config
= bt_config_query_from_args(command_argc
,
5033 command_argv
, retcode
, force_omit_system_plugin_path
,
5034 force_omit_home_plugin_path
, initial_plugin_paths
);
5041 if (log_level
== 'U') {
5045 config
->log_level
= log_level
;
5046 config
->command_name
= command_name
;
5050 bt_object_put_ref(initial_plugin_paths
);