2 * Babeltrace trace converter - parameter parsing
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <babeltrace/babeltrace.h>
33 #include <babeltrace/common-internal.h>
34 #include <babeltrace/values.h>
37 #include <sys/types.h>
39 #include "babeltrace-cfg.h"
41 #define DEFAULT_SOURCE_COMPONENT_NAME "ctf.fs"
42 #define DEFAULT_SINK_COMPONENT_NAME "text.text"
45 * Error printf() macro which prepends "Error: " the first time it's
46 * called. This gives a nicer feel than having a bunch of error prefixes
47 * (since the following lines usually describe the error and possible
48 * solutions), or the error prefix just at the end.
50 #define printf_err(fmt, args...) \
52 if (is_first_error) { \
53 fprintf(stderr, "Error: "); \
54 is_first_error = false; \
56 fprintf(stderr, fmt, ##args); \
59 static bool is_first_error
= true;
61 /* INI-style parsing FSM states */
62 enum ini_parsing_fsm_state
{
63 /* Expect a map key (identifier) */
66 /* Expect an equal character ('=') */
72 /* Expect a negative number value */
73 INI_EXPECT_VALUE_NUMBER_NEG
,
75 /* Expect a comma character (',') */
79 /* INI-style parsing state variables */
80 struct ini_parsing_state
{
81 /* Lexical scanner (owned by this) */
84 /* Output map value object being filled (owned by this) */
85 struct bt_value
*params
;
87 /* Next expected FSM state */
88 enum ini_parsing_fsm_state expecting
;
90 /* Last decoded map key (owned by this) */
93 /* Complete INI-style string to parse (not owned by this) */
96 /* Error buffer (not owned by this) */
100 /* Offset option with "is set" boolean */
106 /* Legacy "ctf"/"lttng-live" format options */
107 struct ctf_legacy_opts
{
108 struct offset_opt offset_s
;
109 struct offset_opt offset_ns
;
110 bool stream_intersection
;
113 /* Legacy "text" format options */
114 struct text_legacy_opts
{
116 * output, dbg_info_dir, dbg_info_target_prefix, names,
117 * and fields are owned by this.
120 GString
*dbg_info_dir
;
121 GString
*dbg_info_target_prefix
;
122 struct bt_value
*names
;
123 struct bt_value
*fields
;
131 bool dbg_info_full_path
;
134 /* Legacy input format format */
135 enum legacy_input_format
{
136 LEGACY_INPUT_FORMAT_NONE
= 0,
137 LEGACY_INPUT_FORMAT_CTF
,
138 LEGACY_INPUT_FORMAT_LTTNG_LIVE
,
141 /* Legacy output format format */
142 enum legacy_output_format
{
143 LEGACY_OUTPUT_FORMAT_NONE
= 0,
144 LEGACY_OUTPUT_FORMAT_TEXT
,
145 LEGACY_OUTPUT_FORMAT_CTF_METADATA
,
146 LEGACY_OUTPUT_FORMAT_DUMMY
,
150 * Prints the "out of memory" error.
153 void print_err_oom(void)
155 printf_err("Out of memory\n");
159 * Prints duplicate legacy output format error.
162 void print_err_dup_legacy_output(void)
164 printf_err("More than one legacy output format specified\n");
168 * Prints duplicate legacy input format error.
171 void print_err_dup_legacy_input(void)
173 printf_err("More than one legacy input format specified\n");
177 * Checks if any of the "text" legacy options is set.
180 bool text_legacy_opts_is_any_set(struct text_legacy_opts
*opts
)
182 return (opts
->output
&& opts
->output
->len
> 0) ||
183 (opts
->dbg_info_dir
&& opts
->dbg_info_dir
->len
> 0) ||
184 (opts
->dbg_info_target_prefix
&&
185 opts
->dbg_info_target_prefix
->len
> 0) ||
186 bt_value_array_size(opts
->names
) > 0 ||
187 bt_value_array_size(opts
->fields
) > 0 ||
188 opts
->no_delta
|| opts
->clock_cycles
|| opts
->clock_seconds
||
189 opts
->clock_date
|| opts
->clock_gmt
||
190 opts
->dbg_info_full_path
;
194 * Checks if any of the "ctf" legacy options is set.
197 bool ctf_legacy_opts_is_any_set(struct ctf_legacy_opts
*opts
)
199 return opts
->offset_s
.is_set
|| opts
->offset_ns
.is_set
||
200 opts
->stream_intersection
;
204 * Appends an "expecting token" error to the INI-style parsing state's
208 void ini_append_error_expecting(struct ini_parsing_state
*state
,
209 GScanner
*scanner
, const char *expecting
)
214 g_string_append_printf(state
->ini_error
, "Expecting %s:\n", expecting
);
216 /* Only print error if there's one line */
217 if (strchr(state
->arg
, '\n') != NULL
|| strlen(state
->arg
) == 0) {
221 g_string_append_printf(state
->ini_error
, "\n %s\n", state
->arg
);
222 pos
= g_scanner_cur_position(scanner
) + 4;
224 if (!g_scanner_eof(scanner
)) {
228 for (i
= 0; i
< pos
; ++i
) {
229 g_string_append_printf(state
->ini_error
, " ");
232 g_string_append_printf(state
->ini_error
, "^\n\n");
236 int ini_handle_state(struct ini_parsing_state
*state
)
239 GTokenType token_type
;
240 struct bt_value
*value
= NULL
;
242 token_type
= g_scanner_get_next_token(state
->scanner
);
243 if (token_type
== G_TOKEN_EOF
) {
244 if (state
->expecting
!= INI_EXPECT_COMMA
) {
245 switch (state
->expecting
) {
246 case INI_EXPECT_EQUAL
:
247 ini_append_error_expecting(state
,
248 state
->scanner
, "'='");
250 case INI_EXPECT_VALUE
:
251 case INI_EXPECT_VALUE_NUMBER_NEG
:
252 ini_append_error_expecting(state
,
253 state
->scanner
, "value");
255 case INI_EXPECT_MAP_KEY
:
256 ini_append_error_expecting(state
,
257 state
->scanner
, "unquoted map key");
270 switch (state
->expecting
) {
271 case INI_EXPECT_MAP_KEY
:
272 if (token_type
!= G_TOKEN_IDENTIFIER
) {
273 ini_append_error_expecting(state
, state
->scanner
,
278 free(state
->last_map_key
);
279 state
->last_map_key
=
280 strdup(state
->scanner
->value
.v_identifier
);
281 if (!state
->last_map_key
) {
282 g_string_append(state
->ini_error
,
287 if (bt_value_map_has_key(state
->params
, state
->last_map_key
)) {
288 g_string_append_printf(state
->ini_error
,
289 "Duplicate parameter key: `%s`\n",
290 state
->last_map_key
);
294 state
->expecting
= INI_EXPECT_EQUAL
;
296 case INI_EXPECT_EQUAL
:
297 if (token_type
!= G_TOKEN_CHAR
) {
298 ini_append_error_expecting(state
,
299 state
->scanner
, "'='");
303 if (state
->scanner
->value
.v_char
!= '=') {
304 ini_append_error_expecting(state
,
305 state
->scanner
, "'='");
309 state
->expecting
= INI_EXPECT_VALUE
;
311 case INI_EXPECT_VALUE
:
313 switch (token_type
) {
315 if (state
->scanner
->value
.v_char
== '-') {
316 /* Negative number */
318 INI_EXPECT_VALUE_NUMBER_NEG
;
321 ini_append_error_expecting(state
,
322 state
->scanner
, "value");
328 /* Positive integer */
329 uint64_t int_val
= state
->scanner
->value
.v_int64
;
331 if (int_val
> (1ULL << 63) - 1) {
332 g_string_append_printf(state
->ini_error
,
333 "Integer value %" PRIu64
" is outside the range of a 64-bit signed integer\n",
338 value
= bt_value_integer_create_init(
343 /* Positive floating point number */
344 value
= bt_value_float_create_init(
345 state
->scanner
->value
.v_float
);
349 value
= bt_value_string_create_init(
350 state
->scanner
->value
.v_string
);
352 case G_TOKEN_IDENTIFIER
:
355 * Using symbols would be appropriate here,
356 * but said symbols are allowed as map key,
357 * so it's easier to consider everything an
360 * If one of the known symbols is not
361 * recognized here, then fall back to creating
364 const char *id
= state
->scanner
->value
.v_identifier
;
366 if (!strcmp(id
, "null") || !strcmp(id
, "NULL") ||
367 !strcmp(id
, "nul")) {
368 value
= bt_value_null
;
369 } else if (!strcmp(id
, "true") || !strcmp(id
, "TRUE") ||
370 !strcmp(id
, "yes") ||
371 !strcmp(id
, "YES")) {
372 value
= bt_value_bool_create_init(true);
373 } else if (!strcmp(id
, "false") ||
374 !strcmp(id
, "FALSE") ||
377 value
= bt_value_bool_create_init(false);
379 value
= bt_value_string_create_init(id
);
384 /* Unset value variable will trigger the error */
389 ini_append_error_expecting(state
,
390 state
->scanner
, "value");
394 state
->expecting
= INI_EXPECT_COMMA
;
397 case INI_EXPECT_VALUE_NUMBER_NEG
:
399 switch (token_type
) {
402 /* Negative integer */
403 uint64_t int_val
= state
->scanner
->value
.v_int64
;
405 if (int_val
> (1ULL << 63) - 1) {
406 g_string_append_printf(state
->ini_error
,
407 "Integer value -%" PRIu64
" is outside the range of a 64-bit signed integer\n",
412 value
= bt_value_integer_create_init(
413 -((int64_t) int_val
));
417 /* Negative floating point number */
418 value
= bt_value_float_create_init(
419 -state
->scanner
->value
.v_float
);
422 /* Unset value variable will trigger the error */
427 ini_append_error_expecting(state
,
428 state
->scanner
, "value");
432 state
->expecting
= INI_EXPECT_COMMA
;
435 case INI_EXPECT_COMMA
:
436 if (token_type
!= G_TOKEN_CHAR
) {
437 ini_append_error_expecting(state
,
438 state
->scanner
, "','");
442 if (state
->scanner
->value
.v_char
!= ',') {
443 ini_append_error_expecting(state
,
444 state
->scanner
, "','");
448 state
->expecting
= INI_EXPECT_MAP_KEY
;
460 if (bt_value_map_insert(state
->params
,
461 state
->last_map_key
, value
)) {
462 /* Only override return value on error */
473 * Converts an INI-style argument to an equivalent map value object.
475 * Return value is owned by the caller.
478 struct bt_value
*bt_value_from_ini(const char *arg
, GString
*ini_error
)
480 /* Lexical scanner configuration */
481 GScannerConfig scanner_config
= {
482 /* Skip whitespaces */
483 .cset_skip_characters
= " \t\n",
485 /* Identifier syntax is: [a-zA-Z_][a-zA-Z0-9_.:-]* */
486 .cset_identifier_first
=
490 .cset_identifier_nth
=
495 /* "hello" and "Hello" two different keys */
496 .case_sensitive
= TRUE
,
499 .cpair_comment_single
= NULL
,
500 .skip_comment_multi
= TRUE
,
501 .skip_comment_single
= TRUE
,
502 .scan_comment_multi
= FALSE
,
505 * Do scan identifiers, including 1-char identifiers,
506 * but NULL is a normal identifier.
508 .scan_identifier
= TRUE
,
509 .scan_identifier_1char
= TRUE
,
510 .scan_identifier_NULL
= FALSE
,
513 * No specific symbols: null and boolean "symbols" are
514 * scanned as plain identifiers.
516 .scan_symbols
= FALSE
,
517 .symbol_2_token
= FALSE
,
518 .scope_0_fallback
= FALSE
,
521 * Scan "0b"-, "0"-, and "0x"-prefixed integers, but not
522 * integers prefixed with "$".
528 .scan_hex_dollar
= FALSE
,
530 /* Convert scanned numbers to integer tokens */
531 .numbers_2_int
= TRUE
,
533 /* Support both integers and floating-point numbers */
534 .int_2_float
= FALSE
,
536 /* Scan integers as 64-bit signed integers */
539 /* Only scan double-quoted strings */
540 .scan_string_sq
= FALSE
,
541 .scan_string_dq
= TRUE
,
543 /* Do not converter identifiers to string tokens */
544 .identifier_2_string
= FALSE
,
546 /* Scan characters as G_TOKEN_CHAR token */
547 .char_2_token
= FALSE
,
549 struct ini_parsing_state state
= {
552 .expecting
= INI_EXPECT_MAP_KEY
,
554 .ini_error
= ini_error
,
557 state
.params
= bt_value_map_create();
562 state
.scanner
= g_scanner_new(&scanner_config
);
563 if (!state
.scanner
) {
567 /* Let the scan begin */
568 g_scanner_input_text(state
.scanner
, arg
, strlen(arg
));
571 int ret
= ini_handle_state(&state
);
576 } else if (ret
> 0) {
585 BT_PUT(state
.params
);
589 g_scanner_destroy(state
.scanner
);
592 free(state
.last_map_key
);
597 * Returns the parameters map value object from a command-line
598 * parameter option's argument.
600 * Return value is owned by the caller.
603 struct bt_value
*bt_value_from_arg(const char *arg
)
605 struct bt_value
*params
= NULL
;
606 GString
*ini_error
= NULL
;
608 ini_error
= g_string_new(NULL
);
614 /* Try INI-style parsing */
615 params
= bt_value_from_ini(arg
, ini_error
);
617 printf_err("%s", ini_error
->str
);
623 g_string_free(ini_error
, TRUE
);
629 * Returns the plugin and component names from a command-line
630 * source/sink option's argument. arg must have the following format:
634 * where PLUGIN is the plugin name, and COMPONENT is the component
637 * On success, both *plugin and *component are not NULL. *plugin
638 * and *component are owned by the caller.
641 void plugin_component_names_from_arg(const char *arg
, char **plugin
,
647 size_t component_len
;
649 /* Initialize both return values to NULL: not found */
653 dot
= strchr(arg
, '.');
659 end
= arg
+ strlen(arg
);
660 plugin_len
= dot
- arg
;
661 component_len
= end
- dot
- 1;
662 if (plugin_len
== 0 || component_len
== 0) {
666 *plugin
= g_malloc0(plugin_len
+ 1);
672 g_strlcpy(*plugin
, arg
, plugin_len
+ 1);
673 *component
= g_malloc0(component_len
+ 1);
679 g_strlcpy(*component
, dot
+ 1, component_len
+ 1);
686 * Prints the Babeltrace version.
689 void print_version(void)
691 puts("Babeltrace " VERSION
);
695 * Prints the legacy, Babeltrace 1.x command usage. Those options are
696 * still compatible in Babeltrace 2.x, but it is recommended to use
697 * the more generic plugin/component parameters instead of those
698 * hard-coded option names.
701 void print_legacy_usage(FILE *fp
)
703 fprintf(fp
, "Usage: babeltrace [OPTIONS] INPUT...\n");
705 fprintf(fp
, "The following options are compatible with the Babeltrace 1.x options:\n");
707 fprintf(fp
, " --help-legacy Show this help\n");
708 fprintf(fp
, " -V, --version Show version\n");
709 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently correlated\n");
710 fprintf(fp
, " across traces\n");
711 fprintf(fp
, " -d, --debug Enable debug mode\n");
712 fprintf(fp
, " -i, --input-format=FORMAT Input trace format (default: ctf)\n");
713 fprintf(fp
, " -l, --list List available formats\n");
714 fprintf(fp
, " -o, --output-format=FORMAT Output trace format (default: text)\n");
715 fprintf(fp
, " -v, --verbose Enable verbose output\n");
717 fprintf(fp
, " Available input formats: ctf, lttng-live, ctf-metadata\n");
718 fprintf(fp
, " Available output formats: text, dummy\n");
720 fprintf(fp
, "Input formats specific options:\n");
722 fprintf(fp
, " INPUT... Input trace file(s), directory(ies), or URLs\n");
723 fprintf(fp
, " --clock-offset=SEC Set clock offset to SEC seconds\n");
724 fprintf(fp
, " --clock-offset-ns=NS Set clock offset to NS nanoseconds\n");
725 fprintf(fp
, " --stream-intersection Only process events when all streams are active\n");
727 fprintf(fp
, "text output format specific options:\n");
729 fprintf(fp
, " --clock-cycles Print timestamps in clock cycles\n");
730 fprintf(fp
, " --clock-date Print timestamp dates\n");
731 fprintf(fp
, " --clock-gmt Print and parse timestamps in GMT time zone\n");
732 fprintf(fp
, " (default: local time zone)\n");
733 fprintf(fp
, " --clock-seconds Print the timestamps as [SEC.NS]\n");
734 fprintf(fp
, " (default format: [HH:MM:SS.NS])\n");
735 fprintf(fp
, " --debug-info-dir=DIR Search for debug info in directory DIR\n");
736 fprintf(fp
, " (default: `/usr/lib/debug`)\n");
737 fprintf(fp
, " --debug-info-full-path Show full debug info source and binary paths\n");
738 fprintf(fp
, " --debug-info-target-prefix=DIR Use directory DIR as a prefix when looking\n");
739 fprintf(fp
, " up executables during debug info analysis\n");
740 fprintf(fp
, " (default: `/usr/lib/debug`)\n");
741 fprintf(fp
, " -f, --fields=NAME[,NAME]... Print additional fields:\n");
742 fprintf(fp
, " all, trace, trace:hostname, trace:domain,\n");
743 fprintf(fp
, " trace:procname, trace:vpid, loglevel, emf\n");
744 fprintf(fp
, " (default: trace:hostname, trace:procname,\n");
745 fprintf(fp
, " trace:vpid)\n");
746 fprintf(fp
, " -n, --names=NAME[,NAME]... Print field names:\n");
747 fprintf(fp
, " payload (or arg or args)\n");
748 fprintf(fp
, " none, all, scope, header, context (or ctx)\n");
749 fprintf(fp
, " (default: payload, context)\n");
750 fprintf(fp
, " --no-delta Do not print time delta between consecutive\n");
751 fprintf(fp
, " events\n");
752 fprintf(fp
, " -w, --output=PATH Write output to PATH (default: standard output)\n");
756 * Prints the Babeltrace 2.x usage.
759 void print_usage(FILE *fp
)
761 fprintf(fp
, "Usage: babeltrace [OPTIONS]\n");
763 fprintf(fp
, " -b, --base-params=PARAMS Set PARAMS as the current base parameters\n");
764 fprintf(fp
, " of the following source and sink component\n");
765 fprintf(fp
, " instances (see the exact format of PARAMS\n");
766 fprintf(fp
, " below)\n");
767 fprintf(fp
, " -d, --debug Enable debug mode\n");
768 fprintf(fp
, " -l, --list List available plugins and their components\n");
769 fprintf(fp
, " -P, --path=PATH Set the `path` parameter of the latest source\n");
770 fprintf(fp
, " or sink component to PATH\n");
771 fprintf(fp
, " -p, --params=PARAMS Set the parameters of the latest source or\n");
772 fprintf(fp
, " sink component instance (in command-line \n");
773 fprintf(fp
, " order) to PARAMS (see the exact format of\n");
774 fprintf(fp
, " PARAMS below)\n");
775 fprintf(fp
, " --plugin-path=PATH[:PATH]... Set paths from which dynamic plugins can be\n");
776 fprintf(fp
, " loaded to PATH\n");
777 fprintf(fp
, " -r, --reset-base-params Reset the current base parameters of the\n");
778 fprintf(fp
, " following source and sink component\n");
779 fprintf(fp
, " instances to an empty map\n");
780 fprintf(fp
, " -o, --sink=PLUGIN.COMPCLS Instantiate a sink component from plugin\n");
781 fprintf(fp
, " PLUGIN and component class COMPCLS (may be\n");
782 fprintf(fp
, " repeated)\n");
783 fprintf(fp
, " -i, --source=PLUGIN.COMPCLS Instantiate a source component from plugin\n");
784 fprintf(fp
, " PLUGIN and component class COMPCLS (may be\n");
785 fprintf(fp
, " repeated)\n");
786 fprintf(fp
, " --begin Start time: [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
787 fprintf(fp
, " --end End time: [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
788 fprintf(fp
, " --timerange Time range: begin,end or [begin,end] (where [] are actual brackets)\n");
789 fprintf(fp
, " --omit-system-plugin-path Omit system plugins from plugin search path\n");
790 fprintf(fp
, " --omit-home-plugin-path Omit home plugins from plugin search path\n");
791 fprintf(fp
, " -h --help Show this help\n");
792 fprintf(fp
, " --help-legacy Show Babeltrace 1.x legacy options\n");
793 fprintf(fp
, " -v, --verbose Enable verbose output\n");
794 fprintf(fp
, " -V, --version Show version\n");
796 fprintf(fp
, "Format of PARAMS\n");
797 fprintf(fp
, "----------------\n");
799 fprintf(fp
, " PARAM=VALUE[,PARAM=VALUE]...\n");
801 fprintf(fp
, "The parameter string is a comma-separated list of PARAM=VALUE assignments,\n");
802 fprintf(fp
, "where PARAM is the parameter name (C identifier plus [:.-] characters), and\n");
803 fprintf(fp
, "VALUE can be one of:\n");
805 fprintf(fp
, "* `null`, `nul`, `NULL`: null value (no backticks).\n");
806 fprintf(fp
, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
807 fprintf(fp
, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
808 fprintf(fp
, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
809 fprintf(fp
, " (`0x` prefix) signed 64-bit integer.\n");
810 fprintf(fp
, "* Double precision floating point number (scientific notation is accepted).\n");
811 fprintf(fp
, "* Unquoted string with no special characters, and not matching any of\n");
812 fprintf(fp
, " the null and boolean value symbols above.\n");
813 fprintf(fp
, "* Double-quoted string (accepts escape characters).\n");
815 fprintf(fp
, "Whitespaces are allowed around individual `=` and `,` tokens.\n");
817 fprintf(fp
, "Example:\n");
819 fprintf(fp
, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
820 fprintf(fp
, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
821 fprintf(fp
, " escape.chars-are:allowed=\"this is a \\\" double quote\"\n");
823 fprintf(fp
, "IMPORTANT: Make sure to single-quote the whole argument when you run babeltrace\n");
824 fprintf(fp
, "from a shell.\n");
828 * Destroys a component configuration.
831 void bt_config_component_destroy(struct bt_object
*obj
)
833 struct bt_config_component
*bt_config_component
=
834 container_of(obj
, struct bt_config_component
, base
);
840 if (bt_config_component
->plugin_name
) {
841 g_string_free(bt_config_component
->plugin_name
, TRUE
);
844 if (bt_config_component
->component_name
) {
845 g_string_free(bt_config_component
->component_name
, TRUE
);
848 BT_PUT(bt_config_component
->params
);
849 g_free(bt_config_component
);
856 * Creates a component configuration using the given plugin name and
857 * component name. plugin_name and component_name are copied (belong to
860 * Return value is owned by the caller.
863 struct bt_config_component
*bt_config_component_create(const char *plugin_name
,
864 const char *component_name
)
866 struct bt_config_component
*cfg_component
= NULL
;
868 cfg_component
= g_new0(struct bt_config_component
, 1);
869 if (!cfg_component
) {
874 bt_object_init(cfg_component
, bt_config_component_destroy
);
875 cfg_component
->plugin_name
= g_string_new(plugin_name
);
876 if (!cfg_component
->plugin_name
) {
881 cfg_component
->component_name
= g_string_new(component_name
);
882 if (!cfg_component
->component_name
) {
887 /* Start with empty parameters */
888 cfg_component
->params
= bt_value_map_create();
889 if (!cfg_component
->params
) {
897 BT_PUT(cfg_component
);
900 return cfg_component
;
904 * Creates a component configuration from a command-line source/sink
908 struct bt_config_component
*bt_config_component_from_arg(const char *arg
)
910 struct bt_config_component
*bt_config_component
= NULL
;
912 char *component_name
;
914 plugin_component_names_from_arg(arg
, &plugin_name
, &component_name
);
915 if (!plugin_name
|| !component_name
) {
916 printf_err("Cannot get plugin or component class name\n");
920 bt_config_component
= bt_config_component_create(plugin_name
,
922 if (!bt_config_component
) {
929 BT_PUT(bt_config_component
);
933 g_free(component_name
);
934 return bt_config_component
;
938 * Destroys a configuration.
941 void bt_config_destroy(struct bt_object
*obj
)
943 struct bt_config
*bt_config
=
944 container_of(obj
, struct bt_config
, base
);
950 if (bt_config
->sources
) {
951 g_ptr_array_free(bt_config
->sources
, TRUE
);
954 if (bt_config
->sinks
) {
955 g_ptr_array_free(bt_config
->sinks
, TRUE
);
958 BT_PUT(bt_config
->plugin_paths
);
966 bool is_setuid_setgid(void)
968 return (geteuid() != getuid() || getegid() != getgid());
971 static void destroy_gstring(void *data
)
973 g_string_free(data
, TRUE
);
977 * Extracts the various paths from the string arg, delimited by ':',
978 * and converts them to an array value object.
980 * Returned array value object is empty if arg is empty.
982 * Return value is owned by the caller.
985 enum bt_value_status
plugin_paths_from_arg(struct bt_value
*plugin_paths
,
988 enum bt_value_status status
= BT_VALUE_STATUS_OK
;
989 GPtrArray
*dirs
= g_ptr_array_new_with_free_func(destroy_gstring
);
994 status
= BT_VALUE_STATUS_ERROR
;
998 ret
= bt_common_append_plugin_path_dirs(arg
, dirs
);
1000 status
= BT_VALUE_STATUS_ERROR
;
1004 for (i
= 0; i
< dirs
->len
; i
++) {
1005 GString
*dir
= g_ptr_array_index(dirs
, i
);
1007 bt_value_array_append_string(plugin_paths
, dir
->str
);
1011 g_ptr_array_free(dirs
, TRUE
);
1016 * Creates a simple lexical scanner for parsing comma-delimited names
1019 * Return value is owned by the caller.
1022 GScanner
*create_csv_identifiers_scanner(void)
1024 GScannerConfig scanner_config
= {
1025 .cset_skip_characters
= " \t\n",
1026 .cset_identifier_first
= G_CSET_a_2_z G_CSET_A_2_Z
"_",
1027 .cset_identifier_nth
= G_CSET_a_2_z G_CSET_A_2_Z
":_-",
1028 .case_sensitive
= TRUE
,
1029 .cpair_comment_single
= NULL
,
1030 .skip_comment_multi
= TRUE
,
1031 .skip_comment_single
= TRUE
,
1032 .scan_comment_multi
= FALSE
,
1033 .scan_identifier
= TRUE
,
1034 .scan_identifier_1char
= TRUE
,
1035 .scan_identifier_NULL
= FALSE
,
1036 .scan_symbols
= FALSE
,
1037 .symbol_2_token
= FALSE
,
1038 .scope_0_fallback
= FALSE
,
1039 .scan_binary
= FALSE
,
1040 .scan_octal
= FALSE
,
1041 .scan_float
= FALSE
,
1043 .scan_hex_dollar
= FALSE
,
1044 .numbers_2_int
= FALSE
,
1045 .int_2_float
= FALSE
,
1046 .store_int64
= FALSE
,
1047 .scan_string_sq
= FALSE
,
1048 .scan_string_dq
= FALSE
,
1049 .identifier_2_string
= FALSE
,
1050 .char_2_token
= TRUE
,
1053 return g_scanner_new(&scanner_config
);
1057 * Inserts a string (if exists and not empty) or null to a map value
1061 enum bt_value_status
map_insert_string_or_null(struct bt_value
*map
,
1062 const char *key
, GString
*string
)
1064 enum bt_value_status ret
;
1066 if (string
&& string
->len
> 0) {
1067 ret
= bt_value_map_insert_string(map
, key
, string
->str
);
1069 ret
= bt_value_map_insert(map
, key
, bt_value_null
);
1075 * Converts a comma-delimited list of known names (--names option) to
1076 * an array value object containing those names as string value objects.
1078 * Return value is owned by the caller.
1081 struct bt_value
*names_from_arg(const char *arg
)
1083 GScanner
*scanner
= NULL
;
1084 struct bt_value
*names
= NULL
;
1085 bool found_all
= false, found_none
= false, found_item
= false;
1087 names
= bt_value_array_create();
1093 scanner
= create_csv_identifiers_scanner();
1099 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1102 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1104 switch (token_type
) {
1105 case G_TOKEN_IDENTIFIER
:
1107 const char *identifier
= scanner
->value
.v_identifier
;
1109 if (!strcmp(identifier
, "payload") ||
1110 !strcmp(identifier
, "args") ||
1111 !strcmp(identifier
, "arg")) {
1113 if (bt_value_array_append_string(names
,
1117 } else if (!strcmp(identifier
, "context") ||
1118 !strcmp(identifier
, "ctx")) {
1120 if (bt_value_array_append_string(names
,
1124 } else if (!strcmp(identifier
, "scope") ||
1125 !strcmp(identifier
, "header")) {
1127 if (bt_value_array_append_string(names
,
1131 } else if (!strcmp(identifier
, "all")) {
1133 if (bt_value_array_append_string(names
,
1137 } else if (!strcmp(identifier
, "none")) {
1139 if (bt_value_array_append_string(names
,
1144 printf_err("Unknown field name: `%s`\n",
1160 if (found_none
&& found_all
) {
1161 printf_err("Only either `all` or `none` can be specified in the list given to the --names option, but not both.\n");
1165 * Legacy behavior is to clear the defaults (show none) when at
1166 * least one item is specified.
1168 if (found_item
&& !found_none
&& !found_all
) {
1169 if (bt_value_array_append_string(names
, "none")) {
1174 g_scanner_destroy(scanner
);
1181 g_scanner_destroy(scanner
);
1188 * Converts a comma-delimited list of known fields (--fields option) to
1189 * an array value object containing those fields as string
1192 * Return value is owned by the caller.
1195 struct bt_value
*fields_from_arg(const char *arg
)
1197 GScanner
*scanner
= NULL
;
1198 struct bt_value
*fields
;
1200 fields
= bt_value_array_create();
1206 scanner
= create_csv_identifiers_scanner();
1212 g_scanner_input_text(scanner
, arg
, strlen(arg
));
1215 GTokenType token_type
= g_scanner_get_next_token(scanner
);
1217 switch (token_type
) {
1218 case G_TOKEN_IDENTIFIER
:
1220 const char *identifier
= scanner
->value
.v_identifier
;
1222 if (!strcmp(identifier
, "trace") ||
1223 !strcmp(identifier
, "trace:hostname") ||
1224 !strcmp(identifier
, "trace:domain") ||
1225 !strcmp(identifier
, "trace:procname") ||
1226 !strcmp(identifier
, "trace:vpid") ||
1227 !strcmp(identifier
, "loglevel") ||
1228 !strcmp(identifier
, "emf") ||
1229 !strcmp(identifier
, "callsite") ||
1230 !strcmp(identifier
, "all")) {
1231 if (bt_value_array_append_string(fields
,
1236 printf_err("Unknown field name: `%s`\n",
1258 g_scanner_destroy(scanner
);
1264 * Inserts the equivalent "prefix-name" true boolean value objects into
1265 * map_obj where the names are in array_obj.
1268 int insert_flat_names_fields_from_array(struct bt_value
*map_obj
,
1269 struct bt_value
*array_obj
, const char *prefix
)
1273 GString
*tmpstr
= NULL
, *default_value
= NULL
;
1276 * array_obj may be NULL if no CLI options were specified to
1277 * trigger its creation.
1283 tmpstr
= g_string_new(NULL
);
1290 default_value
= g_string_new(NULL
);
1291 if (!default_value
) {
1297 for (i
= 0; i
< bt_value_array_size(array_obj
); i
++) {
1298 struct bt_value
*str_obj
= bt_value_array_get(array_obj
, i
);
1300 bool is_default
= false;
1303 printf_err("Unexpected error\n");
1308 ret
= bt_value_string_get(str_obj
, &suffix
);
1311 printf_err("Unexpected error\n");
1315 g_string_assign(tmpstr
, prefix
);
1316 g_string_append(tmpstr
, "-");
1318 /* Special-case for "all" and "none". */
1319 if (!strcmp(suffix
, "all")) {
1321 g_string_assign(default_value
, "show");
1322 } else if (!strcmp(suffix
, "none")) {
1324 g_string_assign(default_value
, "hide");
1327 g_string_append(tmpstr
, "default");
1328 ret
= map_insert_string_or_null(map_obj
,
1336 g_string_append(tmpstr
, suffix
);
1337 ret
= bt_value_map_insert_bool(map_obj
, tmpstr
->str
,
1347 if (default_value
) {
1348 g_string_free(default_value
, TRUE
);
1351 g_string_free(tmpstr
, TRUE
);
1358 * Returns the parameters (map value object) corresponding to the
1359 * legacy text format options.
1361 * Return value is owned by the caller.
1364 struct bt_value
*params_from_text_legacy_opts(
1365 struct text_legacy_opts
*text_legacy_opts
)
1367 struct bt_value
*params
;
1369 params
= bt_value_map_create();
1375 if (map_insert_string_or_null(params
, "output-path",
1376 text_legacy_opts
->output
)) {
1381 if (map_insert_string_or_null(params
, "debug-info-dir",
1382 text_legacy_opts
->dbg_info_dir
)) {
1387 if (map_insert_string_or_null(params
, "debug-info-target-prefix",
1388 text_legacy_opts
->dbg_info_target_prefix
)) {
1393 if (bt_value_map_insert_bool(params
, "debug-info-full-path",
1394 text_legacy_opts
->dbg_info_full_path
)) {
1399 if (bt_value_map_insert_bool(params
, "no-delta",
1400 text_legacy_opts
->no_delta
)) {
1405 if (bt_value_map_insert_bool(params
, "clock-cycles",
1406 text_legacy_opts
->clock_cycles
)) {
1411 if (bt_value_map_insert_bool(params
, "clock-seconds",
1412 text_legacy_opts
->clock_seconds
)) {
1417 if (bt_value_map_insert_bool(params
, "clock-date",
1418 text_legacy_opts
->clock_date
)) {
1423 if (bt_value_map_insert_bool(params
, "clock-gmt",
1424 text_legacy_opts
->clock_gmt
)) {
1429 if (insert_flat_names_fields_from_array(params
,
1430 text_legacy_opts
->names
, "name")) {
1434 if (insert_flat_names_fields_from_array(params
,
1435 text_legacy_opts
->fields
, "field")) {
1449 int append_sinks_from_legacy_opts(GPtrArray
*sinks
,
1450 enum legacy_output_format legacy_output_format
,
1451 struct text_legacy_opts
*text_legacy_opts
)
1454 struct bt_value
*params
= NULL
;
1455 const char *plugin_name
;
1456 const char *component_name
;
1457 struct bt_config_component
*bt_config_component
= NULL
;
1459 switch (legacy_output_format
) {
1460 case LEGACY_OUTPUT_FORMAT_TEXT
:
1461 plugin_name
= "text";
1462 component_name
= "text";
1464 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1465 plugin_name
= "ctf";
1466 component_name
= "metadata-text";
1468 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1469 plugin_name
= "dummy";
1470 component_name
= "dummy";
1477 if (legacy_output_format
== LEGACY_OUTPUT_FORMAT_TEXT
) {
1478 /* Legacy "text" output format has parameters */
1479 params
= params_from_text_legacy_opts(text_legacy_opts
);
1485 * Legacy "dummy" and "ctf-metadata" output formats do
1486 * not have parameters.
1488 params
= bt_value_map_create();
1495 /* Create a component configuration */
1496 bt_config_component
= bt_config_component_create(plugin_name
,
1498 if (!bt_config_component
) {
1502 BT_MOVE(bt_config_component
->params
, params
);
1504 /* Move created component configuration to the array */
1505 g_ptr_array_add(sinks
, bt_config_component
);
1519 * Returns the parameters (map value object) corresponding to the
1520 * given legacy CTF format options.
1522 * Return value is owned by the caller.
1525 struct bt_value
*params_from_ctf_legacy_opts(
1526 struct ctf_legacy_opts
*ctf_legacy_opts
)
1528 struct bt_value
*params
;
1530 params
= bt_value_map_create();
1536 if (bt_value_map_insert_integer(params
, "offset-s",
1537 ctf_legacy_opts
->offset_s
.value
)) {
1542 if (bt_value_map_insert_integer(params
, "offset-ns",
1543 ctf_legacy_opts
->offset_ns
.value
)) {
1548 if (bt_value_map_insert_bool(params
, "stream-intersection",
1549 ctf_legacy_opts
->stream_intersection
)) {
1564 int append_sources_from_legacy_opts(GPtrArray
*sources
,
1565 enum legacy_input_format legacy_input_format
,
1566 struct ctf_legacy_opts
*ctf_legacy_opts
,
1567 struct bt_value
*legacy_input_paths
)
1571 struct bt_value
*base_params
;
1572 struct bt_value
*params
= NULL
;
1573 struct bt_value
*input_path
= NULL
;
1574 struct bt_value
*input_path_copy
= NULL
;
1575 const char *input_key
;
1576 const char *component_name
;
1578 switch (legacy_input_format
) {
1579 case LEGACY_INPUT_FORMAT_CTF
:
1581 component_name
= "fs";
1583 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1585 component_name
= "lttng-live";
1592 base_params
= params_from_ctf_legacy_opts(ctf_legacy_opts
);
1597 for (i
= 0; i
< bt_value_array_size(legacy_input_paths
); i
++) {
1598 struct bt_config_component
*bt_config_component
= NULL
;
1600 /* Copy base parameters as current parameters */
1601 params
= bt_value_copy(base_params
);
1606 /* Get current input path string value object */
1607 input_path
= bt_value_array_get(legacy_input_paths
, i
);
1612 /* Copy current input path value object */
1613 input_path_copy
= bt_value_copy(input_path
);
1614 if (!input_path_copy
) {
1618 /* Insert input path value object into current parameters */
1619 ret
= bt_value_map_insert(params
, input_key
, input_path_copy
);
1624 /* Create a component configuration */
1625 bt_config_component
= bt_config_component_create("ctf",
1627 if (!bt_config_component
) {
1631 BT_MOVE(bt_config_component
->params
, params
);
1633 /* Move created component configuration to the array */
1634 g_ptr_array_add(sources
, bt_config_component
);
1636 /* Put current stuff */
1638 BT_PUT(input_path_copy
);
1647 BT_PUT(base_params
);
1650 BT_PUT(input_path_copy
);
1655 * Escapes a string for the shell. The string is escaped knowing that
1656 * it's a parameter string value (double-quoted), and that it will be
1657 * entered between single quotes in the shell.
1659 * Return value is owned by the caller.
1662 char *str_shell_escape(const char *input
)
1665 const char *at
= input
;
1666 GString
*str
= g_string_new(NULL
);
1672 while (*at
!= '\0') {
1675 g_string_append(str
, "\\\\");
1678 g_string_append(str
, "\\\"");
1681 g_string_append(str
, "'\"'\"'");
1684 g_string_append(str
, "\\n");
1687 g_string_append(str
, "\\t");
1690 g_string_append_c(str
, *at
);
1700 g_string_free(str
, FALSE
);
1707 int append_prefixed_flag_params(GString
*str
, struct bt_value
*flags
,
1717 for (i
= 0; i
< bt_value_array_size(flags
); i
++) {
1718 struct bt_value
*value
= bt_value_array_get(flags
, i
);
1726 if (bt_value_string_get(value
, &flag
)) {
1732 g_string_append_printf(str
, ",%s-%s=true", prefix
, flag
);
1741 * Appends a boolean parameter string.
1744 void g_string_append_bool_param(GString
*str
, const char *name
, bool value
)
1746 g_string_append_printf(str
, ",%s=%s", name
, value
? "true" : "false");
1750 * Appends a path parameter string, or null if it's empty.
1753 int g_string_append_string_path_param(GString
*str
, const char *name
,
1758 if (path
->len
> 0) {
1759 char *escaped_path
= str_shell_escape(path
->str
);
1761 if (!escaped_path
) {
1766 g_string_append_printf(str
, "%s=\"%s\"", name
, escaped_path
);
1769 g_string_append_printf(str
, "%s=null", name
);
1782 * Prints the non-legacy sink options equivalent to the specified
1783 * legacy output format options.
1786 void print_output_legacy_to_sinks(
1787 enum legacy_output_format legacy_output_format
,
1788 struct text_legacy_opts
*text_legacy_opts
)
1790 const char *input_format
;
1791 GString
*str
= NULL
;
1793 str
= g_string_new(" ");
1799 switch (legacy_output_format
) {
1800 case LEGACY_OUTPUT_FORMAT_TEXT
:
1801 input_format
= "text";
1803 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1804 input_format
= "ctf-metadata";
1806 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1807 input_format
= "dummy";
1813 printf_err("Both `%s` legacy output format and non-legacy sink component\ninstances(s) specified.\n\n",
1815 printf_err("Specify the following non-legacy sink component instance instead of the\nlegacy `%s` output format options:\n\n",
1817 g_string_append(str
, "-o ");
1819 switch (legacy_output_format
) {
1820 case LEGACY_OUTPUT_FORMAT_TEXT
:
1821 g_string_append(str
, "text.text");
1823 case LEGACY_OUTPUT_FORMAT_CTF_METADATA
:
1824 g_string_append(str
, "ctf.metadata-text");
1826 case LEGACY_OUTPUT_FORMAT_DUMMY
:
1827 g_string_append(str
, "dummy.dummy");
1833 if (legacy_output_format
== LEGACY_OUTPUT_FORMAT_TEXT
&&
1834 text_legacy_opts_is_any_set(text_legacy_opts
)) {
1837 g_string_append(str
, " -p '");
1839 if (g_string_append_string_path_param(str
, "output-path",
1840 text_legacy_opts
->output
)) {
1844 g_string_append(str
, ",");
1846 if (g_string_append_string_path_param(str
, "debug-info-dir",
1847 text_legacy_opts
->dbg_info_dir
)) {
1851 g_string_append(str
, ",");
1853 if (g_string_append_string_path_param(str
,
1854 "debug-info-target-prefix",
1855 text_legacy_opts
->dbg_info_target_prefix
)) {
1859 g_string_append_bool_param(str
, "no-delta",
1860 text_legacy_opts
->no_delta
);
1861 g_string_append_bool_param(str
, "clock-cycles",
1862 text_legacy_opts
->clock_cycles
);
1863 g_string_append_bool_param(str
, "clock-seconds",
1864 text_legacy_opts
->clock_seconds
);
1865 g_string_append_bool_param(str
, "clock-date",
1866 text_legacy_opts
->clock_date
);
1867 g_string_append_bool_param(str
, "clock-gmt",
1868 text_legacy_opts
->clock_gmt
);
1869 ret
= append_prefixed_flag_params(str
, text_legacy_opts
->names
,
1875 ret
= append_prefixed_flag_params(str
, text_legacy_opts
->fields
,
1881 /* Remove last comma and close single quote */
1882 g_string_append(str
, "'");
1885 printf_err("%s\n\n", str
->str
);
1889 g_string_free(str
, TRUE
);
1895 * Prints the non-legacy source options equivalent to the specified
1896 * legacy input format options.
1899 void print_input_legacy_to_sources(enum legacy_input_format legacy_input_format
,
1900 struct bt_value
*legacy_input_paths
,
1901 struct ctf_legacy_opts
*ctf_legacy_opts
)
1903 const char *input_format
;
1904 GString
*str
= NULL
;
1907 str
= g_string_new(" ");
1913 switch (legacy_input_format
) {
1914 case LEGACY_INPUT_FORMAT_CTF
:
1915 input_format
= "ctf";
1917 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1918 input_format
= "lttng-live";
1924 printf_err("Both `%s` legacy input format and non-legacy source component\ninstance(s) specified.\n\n",
1926 printf_err("Specify the following non-legacy source component instance(s) instead of the\nlegacy `%s` input format options and positional arguments:\n\n",
1929 for (i
= 0; i
< bt_value_array_size(legacy_input_paths
); i
++) {
1930 struct bt_value
*input_value
=
1931 bt_value_array_get(legacy_input_paths
, i
);
1932 const char *input
= NULL
;
1933 char *escaped_input
;
1936 assert(input_value
);
1937 ret
= bt_value_string_get(input_value
, &input
);
1938 BT_PUT(input_value
);
1939 assert(!ret
&& input
);
1940 escaped_input
= str_shell_escape(input
);
1941 if (!escaped_input
) {
1946 g_string_append(str
, "-i ctf.");
1948 switch (legacy_input_format
) {
1949 case LEGACY_INPUT_FORMAT_CTF
:
1950 g_string_append(str
, "fs -p 'path=\"");
1952 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
1953 g_string_append(str
, "lttng-live -p 'url=\"");
1959 g_string_append(str
, escaped_input
);
1960 g_string_append(str
, "\"");
1961 g_string_append_printf(str
, ",offset-s=%" PRId64
,
1962 ctf_legacy_opts
->offset_s
.value
);
1963 g_string_append_printf(str
, ",offset-ns=%" PRId64
,
1964 ctf_legacy_opts
->offset_ns
.value
);
1965 g_string_append_bool_param(str
, "stream-intersection",
1966 ctf_legacy_opts
->stream_intersection
);
1967 g_string_append(str
, "' ");
1968 g_free(escaped_input
);
1971 printf_err("%s\n\n", str
->str
);
1975 g_string_free(str
, TRUE
);
1981 * Validates a given configuration, with optional legacy input and
1982 * output formats options. Prints useful error messages if anything
1985 * Returns true when the configuration is valid.
1988 bool validate_cfg(struct bt_config
*cfg
,
1989 enum legacy_input_format
*legacy_input_format
,
1990 enum legacy_output_format
*legacy_output_format
,
1991 struct bt_value
*legacy_input_paths
,
1992 struct ctf_legacy_opts
*ctf_legacy_opts
,
1993 struct text_legacy_opts
*text_legacy_opts
)
1995 bool legacy_input
= false;
1996 bool legacy_output
= false;
1998 /* Determine if the input and output should be legacy-style */
1999 if (*legacy_input_format
!= LEGACY_INPUT_FORMAT_NONE
||
2000 !bt_value_array_is_empty(legacy_input_paths
) ||
2001 ctf_legacy_opts_is_any_set(ctf_legacy_opts
)) {
2002 legacy_input
= true;
2005 if (*legacy_output_format
!= LEGACY_OUTPUT_FORMAT_NONE
||
2006 text_legacy_opts_is_any_set(text_legacy_opts
)) {
2007 legacy_output
= true;
2011 /* If no legacy input format was specified, default to CTF */
2012 if (*legacy_input_format
== LEGACY_INPUT_FORMAT_NONE
) {
2013 *legacy_input_format
= LEGACY_INPUT_FORMAT_CTF
;
2016 /* Make sure at least one input path exists */
2017 if (bt_value_array_is_empty(legacy_input_paths
)) {
2018 switch (*legacy_input_format
) {
2019 case LEGACY_INPUT_FORMAT_CTF
:
2020 printf_err("No input path specified for legacy `ctf` input format\n");
2022 case LEGACY_INPUT_FORMAT_LTTNG_LIVE
:
2023 printf_err("No URL specified for legacy `lttng-live` input format\n");
2031 /* Make sure no non-legacy sources are specified */
2032 if (cfg
->sources
->len
!= 0) {
2033 print_input_legacy_to_sources(*legacy_input_format
,
2034 legacy_input_paths
, ctf_legacy_opts
);
2039 if (legacy_output
) {
2041 * If no legacy output format was specified, default to
2044 if (*legacy_output_format
== LEGACY_OUTPUT_FORMAT_NONE
) {
2045 *legacy_output_format
= LEGACY_OUTPUT_FORMAT_TEXT
;
2049 * If any "text" option was specified, the output must be
2052 if (text_legacy_opts_is_any_set(text_legacy_opts
) &&
2053 *legacy_output_format
!=
2054 LEGACY_OUTPUT_FORMAT_TEXT
) {
2055 printf_err("Options for legacy `text` output format specified with a different legacy output format\n");
2059 /* Make sure no non-legacy sinks are specified */
2060 if (cfg
->sinks
->len
!= 0) {
2061 print_output_legacy_to_sinks(*legacy_output_format
,
2068 * If the output is the legacy "ctf-metadata" format, then the
2069 * input should be the legacy "ctf" input format.
2071 if (*legacy_output_format
== LEGACY_OUTPUT_FORMAT_CTF_METADATA
&&
2072 *legacy_input_format
!= LEGACY_INPUT_FORMAT_CTF
) {
2073 printf_err("Legacy `ctf-metadata` output format requires using legacy `ctf` input format\n");
2084 * Parses a 64-bit signed integer.
2086 * Returns a negative value if anything goes wrong.
2089 int parse_int64(const char *arg
, int64_t *val
)
2094 *val
= strtoll(arg
, &endptr
, 0);
2095 if (*endptr
!= '\0' || arg
== endptr
|| errno
!= 0) {
2109 OPT_CLOCK_FORCE_CORRELATE
,
2112 OPT_CLOCK_OFFSET_NS
,
2116 OPT_DEBUG_INFO_FULL_PATH
,
2117 OPT_DEBUG_INFO_TARGET_PREFIX
,
2131 OPT_RESET_BASE_PARAMS
,
2134 OPT_STREAM_INTERSECTION
,
2138 OPT_OMIT_SYSTEM_PLUGIN_PATH
,
2139 OPT_OMIT_HOME_PLUGIN_PATH
,
2142 /* popt long option descriptions */
2143 static struct poptOption long_options
[] = {
2144 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
2145 { "base-params", 'b', POPT_ARG_STRING
, NULL
, OPT_BASE_PARAMS
, NULL
, NULL
},
2146 { "begin", '\0', POPT_ARG_STRING
, NULL
, OPT_BEGIN
, NULL
, NULL
},
2147 { "clock-cycles", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
2148 { "clock-date", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
2149 { "clock-force-correlate", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
2150 { "clock-gmt", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
2151 { "clock-offset", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
2152 { "clock-offset-ns", '\0', POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
2153 { "clock-seconds", '\0', POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
2154 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
2155 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
2156 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
2157 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
2158 { "end", '\0', POPT_ARG_STRING
, NULL
, OPT_END
, NULL
, NULL
},
2159 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
2160 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
2161 { "help-legacy", '\0', POPT_ARG_NONE
, NULL
, OPT_HELP_LEGACY
, NULL
, NULL
},
2162 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
2163 { "list", 'l', POPT_ARG_NONE
, NULL
, OPT_LIST
, NULL
, NULL
},
2164 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
2165 { "no-delta", '\0', POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
2166 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_PATH
, NULL
, NULL
},
2167 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
2168 { "path", 'P', POPT_ARG_STRING
, NULL
, OPT_PATH
, NULL
, NULL
},
2169 { "params", 'p', POPT_ARG_STRING
, NULL
, OPT_PARAMS
, NULL
, NULL
},
2170 { "plugin-path", '\0', POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
2171 { "reset-base-params", 'r', POPT_ARG_NONE
, NULL
, OPT_RESET_BASE_PARAMS
, NULL
, NULL
},
2172 { "sink", '\0', POPT_ARG_STRING
, NULL
, OPT_SINK
, NULL
, NULL
},
2173 { "source", '\0', POPT_ARG_STRING
, NULL
, OPT_SOURCE
, NULL
, NULL
},
2174 { "stream-intersection", '\0', POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
2175 { "timerange", '\0', POPT_ARG_STRING
, NULL
, OPT_TIMERANGE
, NULL
, NULL
},
2176 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
2177 { "version", 'V', POPT_ARG_NONE
, NULL
, OPT_VERSION
, NULL
, NULL
},
2178 { "omit-system-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_SYSTEM_PLUGIN_PATH
, NULL
, NULL
},
2179 { "omit-home-plugin-path", '\0', POPT_ARG_NONE
, NULL
, OPT_OMIT_HOME_PLUGIN_PATH
, NULL
, NULL
},
2180 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
2184 * Sets the value of a given legacy offset option and marks it as set.
2186 static void set_offset_value(struct offset_opt
*offset_opt
, int64_t value
)
2188 offset_opt
->value
= value
;
2189 offset_opt
->is_set
= true;
2192 enum bt_config_component_dest
{
2193 BT_CONFIG_COMPONENT_DEST_SOURCE
,
2194 BT_CONFIG_COMPONENT_DEST_SINK
,
2198 * Adds a configuration component to the appropriate configuration
2199 * array depending on the destination.
2201 static void add_cfg_comp(struct bt_config
*cfg
,
2202 struct bt_config_component
*cfg_comp
,
2203 enum bt_config_component_dest dest
)
2205 if (dest
== BT_CONFIG_COMPONENT_DEST_SOURCE
) {
2206 g_ptr_array_add(cfg
->sources
, cfg_comp
);
2208 g_ptr_array_add(cfg
->sinks
, cfg_comp
);
2212 static int split_timerange(const char *arg
, const char **begin
, const char **end
)
2216 /* Try to match [begin,end] */
2217 c
= strchr(arg
, '[');
2231 /* Try to match begin,end */
2245 static int add_internal_plugin_paths(struct bt_config
*cfg
)
2249 if (!cfg
->omit_home_plugin_path
) {
2250 if (bt_common_is_setuid_setgid()) {
2251 printf_debug("Skipping non-system plugin paths for setuid/setgid binary.");
2253 char *home_plugin_dir
=
2254 bt_common_get_home_plugin_path();
2256 if (home_plugin_dir
) {
2257 ret
= plugin_paths_from_arg(cfg
->plugin_paths
,
2259 free(home_plugin_dir
);
2262 printf_err("Invalid home plugin path\n");
2269 if (!cfg
->omit_system_plugin_path
) {
2270 if (plugin_paths_from_arg(cfg
->plugin_paths
,
2271 bt_common_get_system_plugin_path())) {
2272 printf_err("Invalid system plugin path\n");
2281 static int append_sources_from_implicit_params(GPtrArray
*sources
,
2282 struct bt_config_component
*implicit_source_comp
)
2285 size_t len
= sources
->len
;
2287 for (i
= 0; i
< len
; i
++) {
2288 struct bt_config_component
*comp
;
2289 struct bt_value
*params_to_set
;
2291 comp
= g_ptr_array_index(sources
, i
);
2292 params_to_set
= bt_value_map_extend(comp
->params
,
2293 implicit_source_comp
->params
);
2294 if (!params_to_set
) {
2295 printf_err("Cannot extend legacy component parameters with non-legacy parameters\n");
2298 BT_MOVE(comp
->params
, params_to_set
);
2305 struct bt_config
*bt_config_create(void)
2307 struct bt_config
*cfg
;
2310 cfg
= g_new0(struct bt_config
, 1);
2316 bt_object_init(cfg
, bt_config_destroy
);
2317 cfg
->sources
= g_ptr_array_new_with_free_func((GDestroyNotify
) bt_put
);
2318 if (!cfg
->sources
) {
2323 cfg
->sinks
= g_ptr_array_new_with_free_func((GDestroyNotify
) bt_put
);
2329 cfg
->plugin_paths
= bt_value_array_create();
2330 if (!cfg
->plugin_paths
) {
2342 * Returns a Babeltrace configuration, out of command-line arguments,
2343 * containing everything that is needed to instanciate specific
2344 * components with given parameters.
2346 * Return value is set to the appropriate exit code to use.
2348 int bt_config_init_from_args(struct bt_config
*cfg
, int argc
, const char *argv
[])
2350 poptContext pc
= NULL
;
2352 struct ctf_legacy_opts ctf_legacy_opts
;
2353 struct text_legacy_opts text_legacy_opts
;
2354 enum legacy_input_format legacy_input_format
= LEGACY_INPUT_FORMAT_NONE
;
2355 enum legacy_output_format legacy_output_format
=
2356 LEGACY_OUTPUT_FORMAT_NONE
;
2357 struct bt_value
*legacy_input_paths
= NULL
;
2358 struct bt_config_component
*implicit_source_comp
= NULL
;
2359 struct bt_config_component
*cur_cfg_comp
= NULL
;
2360 bool cur_is_implicit_source
= false;
2361 bool use_implicit_source
= false;
2362 enum bt_config_component_dest cur_cfg_comp_dest
=
2363 BT_CONFIG_COMPONENT_DEST_SOURCE
;
2364 struct bt_value
*cur_base_params
= NULL
;
2367 memset(&ctf_legacy_opts
, 0, sizeof(ctf_legacy_opts
));
2368 memset(&text_legacy_opts
, 0, sizeof(text_legacy_opts
));
2370 text_legacy_opts
.output
= g_string_new(NULL
);
2371 if (!text_legacy_opts
.output
) {
2376 text_legacy_opts
.dbg_info_dir
= g_string_new(NULL
);
2377 if (!text_legacy_opts
.dbg_info_dir
) {
2382 text_legacy_opts
.dbg_info_target_prefix
= g_string_new(NULL
);
2383 if (!text_legacy_opts
.dbg_info_target_prefix
) {
2388 cur_base_params
= bt_value_map_create();
2389 if (!cur_base_params
) {
2394 legacy_input_paths
= bt_value_array_create();
2395 if (!legacy_input_paths
) {
2400 /* Note: implicit source never gets positional base params. */
2401 implicit_source_comp
= bt_config_component_from_arg(DEFAULT_SOURCE_COMPONENT_NAME
);
2402 if (implicit_source_comp
) {
2403 cur_cfg_comp
= implicit_source_comp
;
2404 cur_is_implicit_source
= true;
2405 use_implicit_source
= true;
2407 printf_debug("Cannot find implicit source plugin \"%s\"",
2408 DEFAULT_SOURCE_COMPONENT_NAME
);
2412 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
2414 printf_err("Cannot get popt context\n");
2418 poptReadDefaultConfig(pc
, 0);
2420 while ((opt
= poptGetNextOpt(pc
)) > 0) {
2421 arg
= poptGetOptArg(pc
);
2424 case OPT_PLUGIN_PATH
:
2425 if (is_setuid_setgid()) {
2426 printf_debug("Skipping non-system plugin paths for setuid/setgid binary.");
2428 if (plugin_paths_from_arg(cfg
->plugin_paths
, arg
)) {
2429 printf_err("Invalid --plugin-path option's argument\n");
2434 case OPT_OMIT_SYSTEM_PLUGIN_PATH
:
2435 cfg
->omit_system_plugin_path
= true;
2437 case OPT_OMIT_HOME_PLUGIN_PATH
:
2438 cfg
->omit_home_plugin_path
= true;
2440 case OPT_OUTPUT_PATH
:
2441 if (text_legacy_opts
.output
->len
> 0) {
2442 printf_err("Duplicate --output option\n");
2446 g_string_assign(text_legacy_opts
.output
, arg
);
2448 case OPT_DEBUG_INFO_DIR
:
2449 if (text_legacy_opts
.dbg_info_dir
->len
> 0) {
2450 printf_err("Duplicate --debug-info-dir option\n");
2454 g_string_assign(text_legacy_opts
.dbg_info_dir
, arg
);
2456 case OPT_DEBUG_INFO_TARGET_PREFIX
:
2457 if (text_legacy_opts
.dbg_info_target_prefix
->len
> 0) {
2458 printf_err("Duplicate --debug-info-target-prefix option\n");
2462 g_string_assign(text_legacy_opts
.dbg_info_target_prefix
, arg
);
2464 case OPT_INPUT_FORMAT
:
2467 if (opt
== OPT_INPUT_FORMAT
) {
2468 if (!strcmp(arg
, "ctf")) {
2469 /* Legacy CTF input format */
2470 if (legacy_input_format
) {
2471 print_err_dup_legacy_input();
2475 legacy_input_format
=
2476 LEGACY_INPUT_FORMAT_CTF
;
2478 } else if (!strcmp(arg
, "lttng-live")) {
2479 /* Legacy LTTng-live input format */
2480 if (legacy_input_format
) {
2481 print_err_dup_legacy_input();
2485 legacy_input_format
=
2486 LEGACY_INPUT_FORMAT_LTTNG_LIVE
;
2491 use_implicit_source
= false;
2493 /* Non-legacy: try to create a component config */
2494 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
2495 add_cfg_comp(cfg
, cur_cfg_comp
,
2499 cur_cfg_comp
= bt_config_component_from_arg(arg
);
2500 if (!cur_cfg_comp
) {
2501 printf_err("Invalid format for --source option's argument:\n %s\n",
2505 cur_is_implicit_source
= false;
2507 assert(cur_base_params
);
2508 bt_put(cur_cfg_comp
->params
);
2509 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
2510 if (!cur_cfg_comp
->params
) {
2515 cur_cfg_comp_dest
= BT_CONFIG_COMPONENT_DEST_SOURCE
;
2518 case OPT_OUTPUT_FORMAT
:
2521 if (opt
== OPT_OUTPUT_FORMAT
) {
2522 if (!strcmp(arg
, "text")) {
2523 /* Legacy CTF-text output format */
2524 if (legacy_output_format
) {
2525 print_err_dup_legacy_output();
2529 legacy_output_format
=
2530 LEGACY_OUTPUT_FORMAT_TEXT
;
2532 } else if (!strcmp(arg
, "dummy")) {
2533 /* Legacy dummy output format */
2534 if (legacy_output_format
) {
2535 print_err_dup_legacy_output();
2539 legacy_output_format
=
2540 LEGACY_OUTPUT_FORMAT_DUMMY
;
2542 } else if (!strcmp(arg
, "ctf-metadata")) {
2543 /* Legacy CTF-metadata output format */
2544 if (legacy_output_format
) {
2545 print_err_dup_legacy_output();
2549 legacy_output_format
=
2550 LEGACY_OUTPUT_FORMAT_CTF_METADATA
;
2555 /* Non-legacy: try to create a component config */
2556 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
2557 add_cfg_comp(cfg
, cur_cfg_comp
,
2561 cur_cfg_comp
= bt_config_component_from_arg(arg
);
2562 if (!cur_cfg_comp
) {
2563 printf_err("Invalid format for --sink option's argument:\n %s\n",
2567 cur_is_implicit_source
= false;
2569 assert(cur_base_params
);
2570 bt_put(cur_cfg_comp
->params
);
2571 cur_cfg_comp
->params
= bt_value_copy(cur_base_params
);
2572 if (!cur_cfg_comp
->params
) {
2577 cur_cfg_comp_dest
= BT_CONFIG_COMPONENT_DEST_SINK
;
2582 struct bt_value
*params
;
2583 struct bt_value
*params_to_set
;
2585 if (!cur_cfg_comp
) {
2586 printf_err("Can not apply parameter to unavailable default source component \"%s\".\n",
2587 DEFAULT_SOURCE_COMPONENT_NAME
);
2591 params
= bt_value_from_arg(arg
);
2593 printf_err("Invalid format for --params option's argument:\n %s\n",
2598 params_to_set
= bt_value_map_extend(cur_cfg_comp
->params
,
2601 if (!params_to_set
) {
2602 printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n",
2607 BT_MOVE(cur_cfg_comp
->params
, params_to_set
);
2611 if (!cur_cfg_comp
) {
2612 printf_err("Can not apply parameter to unavailable default source component \"%s\".\n",
2613 DEFAULT_SOURCE_COMPONENT_NAME
);
2617 assert(cur_cfg_comp
->params
);
2619 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2625 case OPT_BASE_PARAMS
:
2627 struct bt_value
*params
= bt_value_from_arg(arg
);
2630 printf_err("Invalid format for --base-params option's argument:\n %s\n",
2635 BT_MOVE(cur_base_params
, params
);
2638 case OPT_RESET_BASE_PARAMS
:
2639 BT_PUT(cur_base_params
);
2640 cur_base_params
= bt_value_map_create();
2641 if (!cur_base_params
) {
2647 if (text_legacy_opts
.names
) {
2648 printf_err("Duplicate --names option\n");
2652 text_legacy_opts
.names
= names_from_arg(arg
);
2653 if (!text_legacy_opts
.names
) {
2654 printf_err("Invalid --names option's argument\n");
2659 if (text_legacy_opts
.fields
) {
2660 printf_err("Duplicate --fields option\n");
2664 text_legacy_opts
.fields
= fields_from_arg(arg
);
2665 if (!text_legacy_opts
.fields
) {
2666 printf_err("Invalid --fields option's argument\n");
2671 text_legacy_opts
.no_delta
= true;
2673 case OPT_CLOCK_CYCLES
:
2674 text_legacy_opts
.clock_cycles
= true;
2676 case OPT_CLOCK_SECONDS
:
2677 text_legacy_opts
.clock_seconds
= true;
2679 case OPT_CLOCK_DATE
:
2680 text_legacy_opts
.clock_date
= true;
2683 text_legacy_opts
.clock_gmt
= true;
2685 case OPT_DEBUG_INFO_FULL_PATH
:
2686 text_legacy_opts
.dbg_info_full_path
= true;
2688 case OPT_CLOCK_OFFSET
:
2692 if (ctf_legacy_opts
.offset_s
.is_set
) {
2693 printf_err("Duplicate --clock-offset option\n");
2697 if (parse_int64(arg
, &val
)) {
2698 printf_err("Invalid --clock-offset option's argument\n");
2702 set_offset_value(&ctf_legacy_opts
.offset_s
, val
);
2705 case OPT_CLOCK_OFFSET_NS
:
2709 if (ctf_legacy_opts
.offset_ns
.is_set
) {
2710 printf_err("Duplicate --clock-offset-ns option\n");
2714 if (parse_int64(arg
, &val
)) {
2715 printf_err("Invalid --clock-offset-ns option's argument\n");
2719 set_offset_value(&ctf_legacy_opts
.offset_ns
, val
);
2722 case OPT_STREAM_INTERSECTION
:
2723 ctf_legacy_opts
.stream_intersection
= true;
2725 case OPT_CLOCK_FORCE_CORRELATE
:
2726 cfg
->force_correlate
= true;
2729 if (!cur_cfg_comp
) {
2730 printf_err("Can not apply parameter to unavailable default source component \"%s\".\n",
2731 DEFAULT_SOURCE_COMPONENT_NAME
);
2734 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
2735 printf_err("--begin option must follow a --source option\n");
2738 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2745 if (!cur_cfg_comp
) {
2746 printf_err("Can not apply parameter to unavailable default source component \"%s\".\n",
2747 DEFAULT_SOURCE_COMPONENT_NAME
);
2750 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
2751 printf_err("--end option must follow a --source option\n");
2754 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2762 const char *begin
, *end
;
2764 if (!cur_cfg_comp
) {
2765 printf_err("Can not apply parameter to unavailable default source component \"%s\".\n",
2766 DEFAULT_SOURCE_COMPONENT_NAME
);
2769 if (cur_cfg_comp_dest
!= BT_CONFIG_COMPONENT_DEST_SOURCE
) {
2770 printf_err("--timerange option must follow a --source option\n");
2773 if (split_timerange(arg
, &begin
, &end
)) {
2774 printf_err("Invalid --timerange format, expecting: begin,end or [begin,end] (where [] are actual brackets)\n");
2777 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2782 if (bt_value_map_insert_string(cur_cfg_comp
->params
,
2790 print_usage(stdout
);
2792 case OPT_HELP_LEGACY
:
2793 print_legacy_usage(stdout
);
2799 cfg
->do_list
= true;
2802 cfg
->verbose
= true;
2808 printf_err("Unknown command-line option specified (option code %d)\n",
2818 print_usage(stdout
);
2822 /* Check for option parsing error */
2824 printf_err("While parsing command-line options, at option %s: %s\n",
2825 poptBadOption(pc
, 0), poptStrerror(opt
));
2829 /* Consume leftover arguments as legacy input paths */
2831 const char *input_path
= poptGetArg(pc
);
2837 if (bt_value_array_append_string(legacy_input_paths
,
2844 if (add_internal_plugin_paths(cfg
)) {
2848 /* Append current component configuration, if any */
2849 if (cur_cfg_comp
&& !cur_is_implicit_source
) {
2850 add_cfg_comp(cfg
, cur_cfg_comp
, cur_cfg_comp_dest
);
2852 cur_cfg_comp
= NULL
;
2854 /* Validate legacy/non-legacy options */
2855 if (!validate_cfg(cfg
, &legacy_input_format
, &legacy_output_format
,
2856 legacy_input_paths
, &ctf_legacy_opts
,
2857 &text_legacy_opts
)) {
2858 printf_err("Command-line options form an invalid configuration\n");
2863 * If there's a legacy input format, convert it to source
2864 * component configurations.
2866 if (legacy_input_format
) {
2867 if (append_sources_from_legacy_opts(cfg
->sources
,
2868 legacy_input_format
, &ctf_legacy_opts
,
2869 legacy_input_paths
)) {
2870 printf_err("Cannot convert legacy input format options to source component instance(s)\n");
2873 if (append_sources_from_implicit_params(cfg
->sources
,
2874 implicit_source_comp
)) {
2875 printf_err("Cannot initialize legacy component parameters\n");
2878 use_implicit_source
= false;
2880 if (use_implicit_source
) {
2881 add_cfg_comp(cfg
, implicit_source_comp
,
2882 BT_CONFIG_COMPONENT_DEST_SOURCE
);
2883 implicit_source_comp
= NULL
;
2885 if (implicit_source_comp
2886 && !bt_value_map_is_empty(implicit_source_comp
->params
)) {
2887 printf_err("Arguments specified for implicit source, but an explicit source has been specified, overriding it\n");
2894 * If there's a legacy output format, convert it to sink
2895 * component configurations.
2897 if (legacy_output_format
) {
2898 if (append_sinks_from_legacy_opts(cfg
->sinks
,
2899 legacy_output_format
, &text_legacy_opts
)) {
2900 printf_err("Cannot convert legacy output format options to sink component instance(s)\n");
2905 if (cfg
->sinks
->len
== 0) {
2906 /* Use implicit sink as default. */
2907 cur_cfg_comp
= bt_config_component_from_arg(DEFAULT_SINK_COMPONENT_NAME
);
2908 if (!cur_cfg_comp
) {
2909 printf_error("Cannot find implicit sink plugin \"%s\"\n",
2910 DEFAULT_SINK_COMPONENT_NAME
);
2912 add_cfg_comp(cfg
, cur_cfg_comp
,
2913 BT_CONFIG_COMPONENT_DEST_SINK
);
2914 cur_cfg_comp
= NULL
;
2923 poptFreeContext(pc
);
2926 if (text_legacy_opts
.output
) {
2927 g_string_free(text_legacy_opts
.output
, TRUE
);
2930 if (text_legacy_opts
.dbg_info_dir
) {
2931 g_string_free(text_legacy_opts
.dbg_info_dir
, TRUE
);
2934 if (text_legacy_opts
.dbg_info_target_prefix
) {
2935 g_string_free(text_legacy_opts
.dbg_info_target_prefix
, TRUE
);
2939 BT_PUT(implicit_source_comp
);
2940 BT_PUT(cur_cfg_comp
);
2941 BT_PUT(cur_base_params
);
2942 BT_PUT(text_legacy_opts
.names
);
2943 BT_PUT(text_legacy_opts
.fields
);
2944 BT_PUT(legacy_input_paths
);