Merge tag 'powerpc-5.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux/fpc-iii.git] / tools / perf / builtin-data.c
blob8d23b8d6ee8e3f760affa96028fb4a01b8eb7349
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include "builtin.h"
6 #include "perf.h"
7 #include "debug.h"
8 #include <subcmd/parse-options.h>
9 #include "data-convert.h"
10 #include "data-convert-bt.h"
12 typedef int (*data_cmd_fn_t)(int argc, const char **argv);
14 struct data_cmd {
15 const char *name;
16 const char *summary;
17 data_cmd_fn_t fn;
20 static struct data_cmd data_cmds[];
22 #define for_each_cmd(cmd) \
23 for (cmd = data_cmds; cmd && cmd->name; cmd++)
25 static const struct option data_options[] = {
26 OPT_END()
29 static const char * const data_subcommands[] = { "convert", NULL };
31 static const char *data_usage[] = {
32 "perf data [<common options>] <command> [<options>]",
33 NULL
36 static void print_usage(void)
38 struct data_cmd *cmd;
40 printf("Usage:\n");
41 printf("\t%s\n\n", data_usage[0]);
42 printf("\tAvailable commands:\n");
44 for_each_cmd(cmd) {
45 printf("\t %s\t- %s\n", cmd->name, cmd->summary);
48 printf("\n");
51 static const char * const data_convert_usage[] = {
52 "perf data convert [<options>]",
53 NULL
56 static int cmd_data_convert(int argc, const char **argv)
58 const char *to_ctf = NULL;
59 struct perf_data_convert_opts opts = {
60 .force = false,
61 .all = false,
63 const struct option options[] = {
64 OPT_INCR('v', "verbose", &verbose, "be more verbose"),
65 OPT_STRING('i', "input", &input_name, "file", "input file name"),
66 #ifdef HAVE_LIBBABELTRACE_SUPPORT
67 OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
68 OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
69 #endif
70 OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
71 OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
72 OPT_END()
75 #ifndef HAVE_LIBBABELTRACE_SUPPORT
76 pr_err("No conversion support compiled in. perf should be compiled with environment variables LIBBABELTRACE=1 and LIBBABELTRACE_DIR=/path/to/libbabeltrace/\n");
77 return -1;
78 #endif
80 argc = parse_options(argc, argv, options,
81 data_convert_usage, 0);
82 if (argc) {
83 usage_with_options(data_convert_usage, options);
84 return -1;
87 if (to_ctf) {
88 #ifdef HAVE_LIBBABELTRACE_SUPPORT
89 return bt_convert__perf2ctf(input_name, to_ctf, &opts);
90 #else
91 pr_err("The libbabeltrace support is not compiled in.\n");
92 return -1;
93 #endif
96 return 0;
99 static struct data_cmd data_cmds[] = {
100 { "convert", "converts data file between formats", cmd_data_convert },
101 { .name = NULL, },
104 int cmd_data(int argc, const char **argv)
106 struct data_cmd *cmd;
107 const char *cmdstr;
109 /* No command specified. */
110 if (argc < 2)
111 goto usage;
113 argc = parse_options_subcommand(argc, argv, data_options, data_subcommands, data_usage,
114 PARSE_OPT_STOP_AT_NON_OPTION);
115 if (argc < 1)
116 goto usage;
118 cmdstr = argv[0];
120 for_each_cmd(cmd) {
121 if (strcmp(cmd->name, cmdstr))
122 continue;
124 return cmd->fn(argc, argv);
127 pr_err("Unknown command: %s\n", cmdstr);
128 usage:
129 print_usage();
130 return -1;