1 #include <linux/compiler.h>
5 #include <subcmd/parse-options.h>
6 #include "data-convert.h"
7 #include "data-convert-bt.h"
9 typedef int (*data_cmd_fn_t
)(int argc
, const char **argv
);
17 static struct data_cmd data_cmds
[];
19 #define for_each_cmd(cmd) \
20 for (cmd = data_cmds; cmd && cmd->name; cmd++)
22 static const struct option data_options
[] = {
26 static const char * const data_subcommands
[] = { "convert", NULL
};
28 static const char *data_usage
[] = {
29 "perf data [<common options>] <command> [<options>]",
33 static void print_usage(void)
38 printf("\t%s\n\n", data_usage
[0]);
39 printf("\tAvailable commands:\n");
42 printf("\t %s\t- %s\n", cmd
->name
, cmd
->summary
);
48 static const char * const data_convert_usage
[] = {
49 "perf data convert [<options>]",
53 static int cmd_data_convert(int argc
, const char **argv
)
55 const char *to_ctf
= NULL
;
56 struct perf_data_convert_opts opts
= {
60 const struct option options
[] = {
61 OPT_INCR('v', "verbose", &verbose
, "be more verbose"),
62 OPT_STRING('i', "input", &input_name
, "file", "input file name"),
63 #ifdef HAVE_LIBBABELTRACE_SUPPORT
64 OPT_STRING(0, "to-ctf", &to_ctf
, NULL
, "Convert to CTF format"),
66 OPT_BOOLEAN('f', "force", &opts
.force
, "don't complain, do it"),
67 OPT_BOOLEAN(0, "all", &opts
.all
, "Convert all events"),
71 #ifndef HAVE_LIBBABELTRACE_SUPPORT
72 pr_err("No conversion support compiled in. perf should be compiled with environment variables LIBBABELTRACE=1 and LIBBABELTRACE_DIR=/path/to/libbabeltrace/\n");
76 argc
= parse_options(argc
, argv
, options
,
77 data_convert_usage
, 0);
79 usage_with_options(data_convert_usage
, options
);
84 #ifdef HAVE_LIBBABELTRACE_SUPPORT
85 return bt_convert__perf2ctf(input_name
, to_ctf
, &opts
);
87 pr_err("The libbabeltrace support is not compiled in.\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 /* No command specified. */
109 argc
= parse_options_subcommand(argc
, argv
, data_options
, data_subcommands
, data_usage
,
110 PARSE_OPT_STOP_AT_NON_OPTION
);
117 if (strcmp(cmd
->name
, cmdstr
))
120 return cmd
->fn(argc
, argv
);
123 pr_err("Unknown command: %s\n", cmdstr
);