5 * General benchmarking subsystem provided by perf
7 * Copyright (C) 2009, Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
13 * Available subsystem list:
14 * sched ... scheduler and IPC mechanism
19 #include "util/util.h"
20 #include "util/parse-options.h"
22 #include "bench/bench.h"
31 int (*fn)(int, const char **, const char *);
34 static struct bench_suite sched_suites[] = {
36 "Benchmark for scheduler and IPC mechanisms",
37 bench_sched_messaging },
39 "Flood of communication over pipe() between two processes",
49 struct bench_suite *suites;
52 static struct bench_subsys subsystems[] = {
54 "scheduler and IPC mechanism",
61 static void dump_suites(int subsys_index)
65 printf("List of available suites for %s...\n\n",
66 subsystems[subsys_index].name);
68 for (i = 0; subsystems[subsys_index].suites[i].name; i++)
70 subsystems[subsys_index].suites[i].name,
71 subsystems[subsys_index].suites[i].summary);
77 static char *bench_format_str;
78 int bench_format = BENCH_FORMAT_DEFAULT;
80 static const struct option bench_options[] = {
81 OPT_STRING('f', "format", &bench_format_str, "default",
82 "Specify format style"),
86 static const char * const bench_usage[] = {
87 "perf bench [<common options>] <subsystem> <suite> [<options>]",
91 static void print_usage(void)
96 for (i = 0; bench_usage[i]; i++)
97 printf("\t%s\n", bench_usage[i]);
100 printf("List of available subsystems...\n\n");
102 for (i = 0; subsystems[i].name; i++)
104 subsystems[i].name, subsystems[i].summary);
108 static int bench_str2int(char *str)
111 return BENCH_FORMAT_DEFAULT;
113 if (!strcmp(str, BENCH_FORMAT_DEFAULT_STR))
114 return BENCH_FORMAT_DEFAULT;
115 else if (!strcmp(str, BENCH_FORMAT_SIMPLE_STR))
116 return BENCH_FORMAT_SIMPLE;
118 return BENCH_FORMAT_UNKNOWN;
121 int cmd_bench(int argc, const char **argv, const char *prefix __used)
123 int i, j, status = 0;
126 /* No subsystem specified. */
131 argc = parse_options(argc, argv, bench_options, bench_usage,
132 PARSE_OPT_STOP_AT_NON_OPTION);
134 bench_format = bench_str2int(bench_format_str);
135 if (bench_format == BENCH_FORMAT_UNKNOWN) {
136 printf("Unknown format descriptor:%s\n", bench_format_str);
145 for (i = 0; subsystems[i].name; i++) {
146 if (strcmp(subsystems[i].name, argv[0]))
150 /* No suite specified. */
155 for (j = 0; subsystems[i].suites[j].name; j++) {
156 if (strcmp(subsystems[i].suites[j].name, argv[1]))
159 if (bench_format == BENCH_FORMAT_DEFAULT)
160 printf("# Running %s/%s benchmark...\n",
162 subsystems[i].suites[j].name);
163 status = subsystems[i].suites[j].fn(argc - 1,
168 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
173 printf("Unknown suite:%s for %s\n", argv[1], argv[0]);
178 printf("Unknown subsystem:%s\n", argv[0]);