blob: 1eee97d020fabce67cbfbb84fa10fc2b68b0b78f [file] [log] [blame]
Jiri Olsa2245bf12015-02-20 23:16:59 +01001#include <linux/compiler.h>
2#include "builtin.h"
3#include "perf.h"
4#include "debug.h"
5#include "parse-options.h"
6
7typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
8
9struct data_cmd {
10 const char *name;
11 const char *summary;
12 data_cmd_fn_t fn;
13};
14
15static struct data_cmd data_cmds[];
16
17#define for_each_cmd(cmd) \
18 for (cmd = data_cmds; cmd && cmd->name; cmd++)
19
20static const struct option data_options[] = {
21 OPT_END()
22};
23
24static const char * const data_usage[] = {
25 "perf data [<common options>] <command> [<options>]",
26 NULL
27};
28
29static void print_usage(void)
30{
31 struct data_cmd *cmd;
32
33 printf("Usage:\n");
34 printf("\t%s\n\n", data_usage[0]);
35 printf("\tAvailable commands:\n");
36
37 for_each_cmd(cmd) {
38 printf("\t %s\t- %s\n", cmd->name, cmd->summary);
39 }
40
41 printf("\n");
42}
43
44static struct data_cmd data_cmds[] = {
45 { NULL },
46};
47
48int cmd_data(int argc, const char **argv, const char *prefix)
49{
50 struct data_cmd *cmd;
51 const char *cmdstr;
52
53 /* No command specified. */
54 if (argc < 2)
55 goto usage;
56
57 argc = parse_options(argc, argv, data_options, data_usage,
58 PARSE_OPT_STOP_AT_NON_OPTION);
59 if (argc < 1)
60 goto usage;
61
62 cmdstr = argv[0];
63
64 for_each_cmd(cmd) {
65 if (strcmp(cmd->name, cmdstr))
66 continue;
67
68 return cmd->fn(argc, argv, prefix);
69 }
70
71 pr_err("Unknown command: %s\n", cmdstr);
72usage:
73 print_usage();
74 return -1;
75}