]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - tools/perf/builtin-data.c
perf tools: Fix the bash completion for listing subcommands of perf
[mirror_ubuntu-zesty-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"
5#include "parse-options.h"
edbe9817 6#include "data-convert-bt.h"
2245bf14
JO
7
8typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
9
10struct data_cmd {
11 const char *name;
12 const char *summary;
13 data_cmd_fn_t fn;
14};
15
16static struct data_cmd data_cmds[];
17
18#define for_each_cmd(cmd) \
19 for (cmd = data_cmds; cmd && cmd->name; cmd++)
20
21static const struct option data_options[] = {
22 OPT_END()
23};
24
25static const char * const data_usage[] = {
26 "perf data [<common options>] <command> [<options>]",
27 NULL
28};
29
30static void print_usage(void)
31{
32 struct data_cmd *cmd;
33
34 printf("Usage:\n");
35 printf("\t%s\n\n", data_usage[0]);
36 printf("\tAvailable commands:\n");
37
38 for_each_cmd(cmd) {
39 printf("\t %s\t- %s\n", cmd->name, cmd->summary);
40 }
41
42 printf("\n");
43}
44
edbe9817
JO
45static const char * const data_convert_usage[] = {
46 "perf data convert [<options>]",
47 NULL
48};
49
50static int cmd_data_convert(int argc, const char **argv,
51 const char *prefix __maybe_unused)
52{
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"),
59#endif
60 OPT_END()
61 };
62
63#ifndef HAVE_LIBBABELTRACE_SUPPORT
64 pr_err("No conversion support compiled in.\n");
65 return -1;
66#endif
67
68 argc = parse_options(argc, argv, options,
69 data_convert_usage, 0);
70 if (argc) {
71 usage_with_options(data_convert_usage, options);
72 return -1;
73 }
74
75 if (to_ctf) {
76#ifdef HAVE_LIBBABELTRACE_SUPPORT
77 return bt_convert__perf2ctf(input_name, to_ctf);
78#else
79 pr_err("The libbabeltrace support is not compiled in.\n");
80 return -1;
81#endif
82 }
83
84 return 0;
85}
86
2245bf14 87static struct data_cmd data_cmds[] = {
edbe9817 88 { "convert", "converts data file between formats", cmd_data_convert },
1f924c29 89 { .name = NULL, },
2245bf14
JO
90};
91
92int cmd_data(int argc, const char **argv, const char *prefix)
93{
94 struct data_cmd *cmd;
95 const char *cmdstr;
96
97 /* No command specified. */
98 if (argc < 2)
99 goto usage;
100
101 argc = parse_options(argc, argv, data_options, data_usage,
102 PARSE_OPT_STOP_AT_NON_OPTION);
103 if (argc < 1)
104 goto usage;
105
106 cmdstr = argv[0];
107
108 for_each_cmd(cmd) {
109 if (strcmp(cmd->name, cmdstr))
110 continue;
111
112 return cmd->fn(argc, argv, prefix);
113 }
114
115 pr_err("Unknown command: %s\n", cmdstr);
116usage:
117 print_usage();
118 return -1;
119}