1 #include <linux/compiler.h>
5 #include <subcmd/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
;
57 const struct option options
[] = {
58 OPT_INCR('v', "verbose", &verbose
, "be more verbose"),
59 OPT_STRING('i', "input", &input_name
, "file", "input file name"),
60 #ifdef HAVE_LIBBABELTRACE_SUPPORT
61 OPT_STRING(0, "to-ctf", &to_ctf
, NULL
, "Convert to CTF format"),
63 OPT_BOOLEAN('f', "force", &force
, "don't complain, do it"),
67 #ifndef HAVE_LIBBABELTRACE_SUPPORT
68 pr_err("No conversion support compiled in.\n");
72 argc
= parse_options(argc
, argv
, options
,
73 data_convert_usage
, 0);
75 usage_with_options(data_convert_usage
, options
);
80 #ifdef HAVE_LIBBABELTRACE_SUPPORT
81 return bt_convert__perf2ctf(input_name
, to_ctf
, force
);
83 pr_err("The libbabeltrace support is not compiled in.\n");
91 static struct data_cmd data_cmds
[] = {
92 { "convert", "converts data file between formats", cmd_data_convert
},
96 int cmd_data(int argc
, const char **argv
, const char *prefix
)
101 /* No command specified. */
105 argc
= parse_options_subcommand(argc
, argv
, data_options
, data_subcommands
, data_usage
,
106 PARSE_OPT_STOP_AT_NON_OPTION
);
113 if (strcmp(cmd
->name
, cmdstr
))
116 return cmd
->fn(argc
, argv
, prefix
);
119 pr_err("Unknown command: %s\n", cmdstr
);