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 /* sentinel: easy for help */
36 #define suite_all { "all", "Test all benchmark suites", NULL }
38 #ifdef LIBNUMA_SUPPORT
39 static struct bench_suite numa_suites[] = {
41 "Benchmark for NUMA workloads",
50 static struct bench_suite sched_suites[] = {
52 "Benchmark for scheduler and IPC mechanisms",
53 bench_sched_messaging },
55 "Flood of communication over pipe() between two processes",
63 static struct bench_suite mem_suites[] = {
65 "Simple memory copy in various ways",
68 "Simple memory set in various ways",
79 struct bench_suite *suites;
82 static struct bench_subsys subsystems[] = {
83 #ifdef LIBNUMA_SUPPORT
85 "NUMA scheduling and MM behavior",
89 "scheduler and IPC mechanism",
92 "memory access performance",
94 { "all", /* sentinel: easy for help */
95 "all benchmark subsystem",
102 static void dump_suites(int subsys_index)
106 printf("# List of available suites for %s...\n\n",
107 subsystems[subsys_index].name);
109 for (i = 0; subsystems[subsys_index].suites[i].name; i++)
111 subsystems[subsys_index].suites[i].name,
112 subsystems[subsys_index].suites[i].summary);
118 static const char *bench_format_str;
119 int bench_format = BENCH_FORMAT_DEFAULT;
121 static const struct option bench_options[] = {
122 OPT_STRING('f', "format", &bench_format_str, "default",
123 "Specify format style"),
127 static const char * const bench_usage[] = {
128 "perf bench [<common options>] <subsystem> <suite> [<options>]",
132 static void print_usage(void)
137 for (i = 0; bench_usage[i]; i++)
138 printf("\t%s\n", bench_usage[i]);
141 printf("# List of available subsystems...\n\n");
143 for (i = 0; subsystems[i].name; i++)
145 subsystems[i].name, subsystems[i].summary);
149 static int bench_str2int(const char *str)
152 return BENCH_FORMAT_DEFAULT;
154 if (!strcmp(str, BENCH_FORMAT_DEFAULT_STR))
155 return BENCH_FORMAT_DEFAULT;
156 else if (!strcmp(str, BENCH_FORMAT_SIMPLE_STR))
157 return BENCH_FORMAT_SIMPLE;
159 return BENCH_FORMAT_UNKNOWN;
162 static void all_suite(struct bench_subsys *subsys) /* FROM HERE */
166 struct bench_suite *suites = subsys->suites;
171 * preparing preset parameters for
172 * embedded, ordinary PC, HPC, etc...
175 for (i = 0; suites[i].fn; i++) {
176 printf("# Running %s/%s benchmark...\n",
181 argv[1] = suites[i].name;
182 suites[i].fn(1, argv, NULL);
187 static void all_subsystem(void)
190 for (i = 0; subsystems[i].suites; i++)
191 all_suite(&subsystems[i]);
194 int cmd_bench(int argc, const char **argv, const char *prefix __maybe_unused)
196 int i, j, status = 0;
199 /* No subsystem specified. */
204 argc = parse_options(argc, argv, bench_options, bench_usage,
205 PARSE_OPT_STOP_AT_NON_OPTION);
207 bench_format = bench_str2int(bench_format_str);
208 if (bench_format == BENCH_FORMAT_UNKNOWN) {
209 printf("Unknown format descriptor:%s\n", bench_format_str);
218 if (!strcmp(argv[0], "all")) {
223 for (i = 0; subsystems[i].name; i++) {
224 if (strcmp(subsystems[i].name, argv[0]))
228 /* No suite specified. */
233 if (!strcmp(argv[1], "all")) {
234 all_suite(&subsystems[i]);
238 for (j = 0; subsystems[i].suites[j].name; j++) {
239 if (strcmp(subsystems[i].suites[j].name, argv[1]))
242 if (bench_format == BENCH_FORMAT_DEFAULT)
243 printf("# Running %s/%s benchmark...\n",
245 subsystems[i].suites[j].name);
247 status = subsystems[i].suites[j].fn(argc - 1,
252 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
257 printf("Unknown suite:%s for %s\n", argv[1], argv[0]);
262 printf("Unknown subsystem:%s\n", argv[0]);