1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
7 #include <subcmd/parse-options.h>
8 #include "data-convert.h"
11 typedef int (*data_cmd_fn_t
)(int argc
, const char **argv
);
19 static struct data_cmd data_cmds
[];
21 #define for_each_cmd(cmd) \
22 for (cmd = data_cmds; cmd && cmd->name; cmd++)
24 static const char * const data_subcommands
[] = { "convert", NULL
};
26 static const char *data_usage
[] = {
27 "perf data convert [<options>]",
33 struct perf_data_convert_opts opts
= {
38 const struct option data_options
[] = {
39 OPT_INCR('v', "verbose", &verbose
, "be more verbose"),
40 OPT_STRING('i', "input", &input_name
, "file", "input file name"),
41 OPT_STRING(0, "to-json", &to_json
, NULL
, "Convert to JSON format"),
42 #ifdef HAVE_LIBBABELTRACE_SUPPORT
43 OPT_STRING(0, "to-ctf", &to_ctf
, NULL
, "Convert to CTF format"),
44 OPT_BOOLEAN(0, "tod", &opts
.tod
, "Convert time to wall clock time"),
46 OPT_BOOLEAN('f', "force", &opts
.force
, "don't complain, do it"),
47 OPT_BOOLEAN(0, "all", &opts
.all
, "Convert all events"),
51 static int cmd_data_convert(int argc
, const char **argv
)
54 argc
= parse_options(argc
, argv
, data_options
,
57 usage_with_options(data_usage
, data_options
);
61 if (to_json
&& to_ctf
) {
62 pr_err("You cannot specify both --to-ctf and --to-json.\n");
65 #ifdef HAVE_LIBBABELTRACE_SUPPORT
66 if (!to_json
&& !to_ctf
) {
67 pr_err("You must specify one of --to-ctf or --to-json.\n");
72 pr_err("You must specify --to-json.\n");
78 return bt_convert__perf2json(input_name
, to_json
, &opts
);
81 #if defined(HAVE_LIBBABELTRACE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
82 return bt_convert__perf2ctf(input_name
, to_ctf
, &opts
);
84 pr_err("The libbabeltrace support is not compiled in. perf should be "
85 "compiled with environment variables LIBBABELTRACE=1 and "
86 "LIBBABELTRACE_DIR=/path/to/libbabeltrace/.\n"
87 "Check also if libbtraceevent devel files are available.\n");
95 static struct data_cmd data_cmds
[] = {
96 { "convert", "converts data file between formats", cmd_data_convert
},
100 int cmd_data(int argc
, const char **argv
)
102 struct data_cmd
*cmd
;
105 argc
= parse_options_subcommand(argc
, argv
, data_options
, data_subcommands
, data_usage
,
106 PARSE_OPT_STOP_AT_NON_OPTION
);
109 usage_with_options(data_usage
, data_options
);
116 if (strcmp(cmd
->name
, cmdstr
))
119 return cmd
->fn(argc
, argv
);
122 pr_err("Unknown command: %s\n", cmdstr
);
123 usage_with_options(data_usage
, data_options
);