1 #include <linux/compiler.h>
5 #include "parse-options.h"
6 #include "data-convert-bt.h"
8 typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
16 static struct data_cmd data_cmds[];
18 #define for_each_cmd(cmd) \
19 for (cmd = data_cmds; cmd && cmd->name; cmd++)
21 static const struct option data_options[] = {
25 static const char * const data_subcommands[] = { "convert", NULL };
27 static const char *data_usage[] = {
28 "perf data [<common options>] <command> [<options>]",
32 static void print_usage(void)
37 printf("\t%s\n\n", data_usage[0]);
38 printf("\tAvailable commands:\n");
41 printf("\t %s\t- %s\n", cmd->name, cmd->summary);
47 static const char * const data_convert_usage[] = {
48 "perf data convert [<options>]",
52 static int cmd_data_convert(int argc, const char **argv,
53 const char *prefix __maybe_unused)
55 const char *to_ctf = NULL;
56 const struct option options[] = {
57 OPT_INCR('v', "verbose", &verbose, "be more verbose"),
58 OPT_STRING('i', "input", &input_name, "file", "input file name"),
59 #ifdef HAVE_LIBBABELTRACE_SUPPORT
60 OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
65 #ifndef HAVE_LIBBABELTRACE_SUPPORT
66 pr_err("No conversion support compiled in.\n");
70 argc = parse_options(argc, argv, options,
71 data_convert_usage, 0);
73 usage_with_options(data_convert_usage, options);
78 #ifdef HAVE_LIBBABELTRACE_SUPPORT
79 return bt_convert__perf2ctf(input_name, to_ctf);
81 pr_err("The libbabeltrace support is not compiled in.\n");
89 static struct data_cmd data_cmds[] = {
90 { "convert", "converts data file between formats", cmd_data_convert },
94 int cmd_data(int argc, const char **argv, const char *prefix)
99 /* No command specified. */
103 argc = parse_options_subcommand(argc, argv, data_options, data_subcommands, data_usage,
104 PARSE_OPT_STOP_AT_NON_OPTION);
111 if (strcmp(cmd->name, cmdstr))
114 return cmd->fn(argc, argv, prefix);
117 pr_err("Unknown command: %s\n", cmdstr);