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_usage[] = {
26 "perf data [<common options>] <command> [<options>]",
30 static void print_usage(void)
35 printf("\t%s\n\n", data_usage[0]);
36 printf("\tAvailable commands:\n");
39 printf("\t %s\t- %s\n", cmd->name, cmd->summary);
45 static const char * const data_convert_usage[] = {
46 "perf data convert [<options>]",
50 static int cmd_data_convert(int argc, const char **argv,
51 const char *prefix __maybe_unused)
53 const char *to_ctf = NULL;
54 const struct option options[] = {
55 OPT_INCR('v', "verbose", &verbose, "be more verbose"),
56 OPT_STRING('i', "input", &input_name, "file", "input file name"),
57 #ifdef HAVE_LIBBABELTRACE_SUPPORT
58 OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
63 #ifndef HAVE_LIBBABELTRACE_SUPPORT
64 pr_err("No conversion support compiled in.\n");
68 argc = parse_options(argc, argv, options,
69 data_convert_usage, 0);
71 usage_with_options(data_convert_usage, options);
76 #ifdef HAVE_LIBBABELTRACE_SUPPORT
77 return bt_convert__perf2ctf(input_name, to_ctf);
79 pr_err("The libbabeltrace support is not compiled in.\n");
87 static struct data_cmd data_cmds[] = {
88 { "convert", "converts data file between formats", cmd_data_convert },
92 int cmd_data(int argc, const char **argv, const char *prefix)
97 /* No command specified. */
101 argc = parse_options(argc, argv, data_options, data_usage,
102 PARSE_OPT_STOP_AT_NON_OPTION);
109 if (strcmp(cmd->name, cmdstr))
112 return cmd->fn(argc, argv, prefix);
115 pr_err("Unknown command: %s\n", cmdstr);