]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - tools/perf/builtin-data.c
x86/speculation: Rework speculative_store_bypass_update()
[mirror_ubuntu-artful-kernel.git] / tools / perf / builtin-data.c
CommitLineData
2245bf14
JO
1#include <linux/compiler.h>
2#include "builtin.h"
3#include "perf.h"
4#include "debug.h"
4b6ab94e 5#include <subcmd/parse-options.h>
3275f68e 6#include "data-convert.h"
edbe9817 7#include "data-convert-bt.h"
2245bf14 8
b0ad8ea6 9typedef int (*data_cmd_fn_t)(int argc, const char **argv);
2245bf14
JO
10
11struct data_cmd {
12 const char *name;
13 const char *summary;
14 data_cmd_fn_t fn;
15};
16
17static struct data_cmd data_cmds[];
18
19#define for_each_cmd(cmd) \
20 for (cmd = data_cmds; cmd && cmd->name; cmd++)
21
22static const struct option data_options[] = {
23 OPT_END()
24};
25
01b7160b
YS
26static const char * const data_subcommands[] = { "convert", NULL };
27
28static const char *data_usage[] = {
2245bf14
JO
29 "perf data [<common options>] <command> [<options>]",
30 NULL
31};
32
33static void print_usage(void)
34{
35 struct data_cmd *cmd;
36
37 printf("Usage:\n");
38 printf("\t%s\n\n", data_usage[0]);
39 printf("\tAvailable commands:\n");
40
41 for_each_cmd(cmd) {
42 printf("\t %s\t- %s\n", cmd->name, cmd->summary);
43 }
44
45 printf("\n");
46}
47
edbe9817
JO
48static const char * const data_convert_usage[] = {
49 "perf data convert [<options>]",
50 NULL
51};
52
b0ad8ea6 53static int cmd_data_convert(int argc, const char **argv)
edbe9817
JO
54{
55 const char *to_ctf = NULL;
3275f68e
WN
56 struct perf_data_convert_opts opts = {
57 .force = false,
f02a6489 58 .all = false,
3275f68e 59 };
edbe9817
JO
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"),
65#endif
3275f68e 66 OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
9e1a7ea1 67 OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
edbe9817
JO
68 OPT_END()
69 };
70
71#ifndef HAVE_LIBBABELTRACE_SUPPORT
72 pr_err("No conversion support compiled in.\n");
73 return -1;
74#endif
75
76 argc = parse_options(argc, argv, options,
77 data_convert_usage, 0);
78 if (argc) {
79 usage_with_options(data_convert_usage, options);
80 return -1;
81 }
82
83 if (to_ctf) {
84#ifdef HAVE_LIBBABELTRACE_SUPPORT
3275f68e 85 return bt_convert__perf2ctf(input_name, to_ctf, &opts);
edbe9817
JO
86#else
87 pr_err("The libbabeltrace support is not compiled in.\n");
88 return -1;
89#endif
90 }
91
92 return 0;
93}
94
2245bf14 95static struct data_cmd data_cmds[] = {
edbe9817 96 { "convert", "converts data file between formats", cmd_data_convert },
1f924c29 97 { .name = NULL, },
2245bf14
JO
98};
99
b0ad8ea6 100int cmd_data(int argc, const char **argv)
2245bf14
JO
101{
102 struct data_cmd *cmd;
103 const char *cmdstr;
104
105 /* No command specified. */
106 if (argc < 2)
107 goto usage;
108
01b7160b 109 argc = parse_options_subcommand(argc, argv, data_options, data_subcommands, data_usage,
2245bf14
JO
110 PARSE_OPT_STOP_AT_NON_OPTION);
111 if (argc < 1)
112 goto usage;
113
114 cmdstr = argv[0];
115
116 for_each_cmd(cmd) {
117 if (strcmp(cmd->name, cmdstr))
118 continue;
119
b0ad8ea6 120 return cmd->fn(argc, argv);
2245bf14
JO
121 }
122
123 pr_err("Unknown command: %s\n", cmdstr);
124usage:
125 print_usage();
126 return -1;
127}