mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-09 22:50:41 +00:00
76 lines
1.3 KiB
C
76 lines
1.3 KiB
C
|
#include <linux/compiler.h>
|
||
|
#include "builtin.h"
|
||
|
#include "perf.h"
|
||
|
#include "debug.h"
|
||
|
#include "parse-options.h"
|
||
|
|
||
|
typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
|
||
|
|
||
|
struct data_cmd {
|
||
|
const char *name;
|
||
|
const char *summary;
|
||
|
data_cmd_fn_t fn;
|
||
|
};
|
||
|
|
||
|
static struct data_cmd data_cmds[];
|
||
|
|
||
|
#define for_each_cmd(cmd) \
|
||
|
for (cmd = data_cmds; cmd && cmd->name; cmd++)
|
||
|
|
||
|
static const struct option data_options[] = {
|
||
|
OPT_END()
|
||
|
};
|
||
|
|
||
|
static const char * const data_usage[] = {
|
||
|
"perf data [<common options>] <command> [<options>]",
|
||
|
NULL
|
||
|
};
|
||
|
|
||
|
static void print_usage(void)
|
||
|
{
|
||
|
struct data_cmd *cmd;
|
||
|
|
||
|
printf("Usage:\n");
|
||
|
printf("\t%s\n\n", data_usage[0]);
|
||
|
printf("\tAvailable commands:\n");
|
||
|
|
||
|
for_each_cmd(cmd) {
|
||
|
printf("\t %s\t- %s\n", cmd->name, cmd->summary);
|
||
|
}
|
||
|
|
||
|
printf("\n");
|
||
|
}
|
||
|
|
||
|
static struct data_cmd data_cmds[] = {
|
||
|
{ NULL },
|
||
|
};
|
||
|
|
||
|
int cmd_data(int argc, const char **argv, const char *prefix)
|
||
|
{
|
||
|
struct data_cmd *cmd;
|
||
|
const char *cmdstr;
|
||
|
|
||
|
/* No command specified. */
|
||
|
if (argc < 2)
|
||
|
goto usage;
|
||
|
|
||
|
argc = parse_options(argc, argv, data_options, data_usage,
|
||
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
||
|
if (argc < 1)
|
||
|
goto usage;
|
||
|
|
||
|
cmdstr = argv[0];
|
||
|
|
||
|
for_each_cmd(cmd) {
|
||
|
if (strcmp(cmd->name, cmdstr))
|
||
|
continue;
|
||
|
|
||
|
return cmd->fn(argc, argv, prefix);
|
||
|
}
|
||
|
|
||
|
pr_err("Unknown command: %s\n", cmdstr);
|
||
|
usage:
|
||
|
print_usage();
|
||
|
return -1;
|
||
|
}
|