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
15 * mem ... memory access performance
20 #include "util/util.h"
21 #include "util/parse-options.h"
23 #include "bench/bench.h"
32 int (*fn
)(int, const char **, const char *);
35 static struct bench_suite sched_suites
[] = {
37 "Benchmark for scheduler and IPC mechanisms",
38 bench_sched_messaging
},
40 "Flood of communication over pipe() between two processes",
47 static struct bench_suite mem_suites
[] = {
49 "Simple memory copy in various ways",
59 struct bench_suite
*suites
;
62 static struct bench_subsys subsystems
[] = {
64 "scheduler and IPC mechanism",
67 "memory access performance",
74 static void dump_suites(int subsys_index
)
78 printf("List of available suites for %s...\n\n",
79 subsystems
[subsys_index
].name
);
81 for (i
= 0; subsystems
[subsys_index
].suites
[i
].name
; i
++)
83 subsystems
[subsys_index
].suites
[i
].name
,
84 subsystems
[subsys_index
].suites
[i
].summary
);
90 static char *bench_format_str
;
91 int bench_format
= BENCH_FORMAT_DEFAULT
;
93 static const struct option bench_options
[] = {
94 OPT_STRING('f', "format", &bench_format_str
, "default",
95 "Specify format style"),
99 static const char * const bench_usage
[] = {
100 "perf bench [<common options>] <subsystem> <suite> [<options>]",
104 static void print_usage(void)
109 for (i
= 0; bench_usage
[i
]; i
++)
110 printf("\t%s\n", bench_usage
[i
]);
113 printf("List of available subsystems...\n\n");
115 for (i
= 0; subsystems
[i
].name
; i
++)
117 subsystems
[i
].name
, subsystems
[i
].summary
);
121 static int bench_str2int(char *str
)
124 return BENCH_FORMAT_DEFAULT
;
126 if (!strcmp(str
, BENCH_FORMAT_DEFAULT_STR
))
127 return BENCH_FORMAT_DEFAULT
;
128 else if (!strcmp(str
, BENCH_FORMAT_SIMPLE_STR
))
129 return BENCH_FORMAT_SIMPLE
;
131 return BENCH_FORMAT_UNKNOWN
;
134 int cmd_bench(int argc
, const char **argv
, const char *prefix __used
)
136 int i
, j
, status
= 0;
139 /* No subsystem specified. */
144 argc
= parse_options(argc
, argv
, bench_options
, bench_usage
,
145 PARSE_OPT_STOP_AT_NON_OPTION
);
147 bench_format
= bench_str2int(bench_format_str
);
148 if (bench_format
== BENCH_FORMAT_UNKNOWN
) {
149 printf("Unknown format descriptor:%s\n", bench_format_str
);
158 for (i
= 0; subsystems
[i
].name
; i
++) {
159 if (strcmp(subsystems
[i
].name
, argv
[0]))
163 /* No suite specified. */
168 for (j
= 0; subsystems
[i
].suites
[j
].name
; j
++) {
169 if (strcmp(subsystems
[i
].suites
[j
].name
, argv
[1]))
172 if (bench_format
== BENCH_FORMAT_DEFAULT
)
173 printf("# Running %s/%s benchmark...\n",
175 subsystems
[i
].suites
[j
].name
);
176 status
= subsystems
[i
].suites
[j
].fn(argc
- 1,
181 if (!strcmp(argv
[1], "-h") || !strcmp(argv
[1], "--help")) {
186 printf("Unknown suite:%s for %s\n", argv
[1], argv
[0]);
191 printf("Unknown subsystem:%s\n", argv
[0]);