kernel/hw_breakpoint.c: Fix local/global shadowing
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / tools / perf / builtin-bench.c
blobe043eb83092aa3576a89016f70e8698e36c97e49
1 /*
3 * builtin-bench.c
5 * General benchmarking subsystem provided by perf
7 * Copyright (C) 2009, Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
9 */
13 * Available subsystem list:
14 * sched ... scheduler and IPC mechanism
15 * mem ... memory access performance
19 #include "perf.h"
20 #include "util/util.h"
21 #include "util/parse-options.h"
22 #include "builtin.h"
23 #include "bench/bench.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
29 struct bench_suite {
30 const char *name;
31 const char *summary;
32 int (*fn)(int, const char **, const char *);
35 static struct bench_suite sched_suites[] = {
36 { "messaging",
37 "Benchmark for scheduler and IPC mechanisms",
38 bench_sched_messaging },
39 { "pipe",
40 "Flood of communication over pipe() between two processes",
41 bench_sched_pipe },
42 { NULL,
43 NULL,
44 NULL }
47 static struct bench_suite mem_suites[] = {
48 { "memcpy",
49 "Simple memory copy in various ways",
50 bench_mem_memcpy },
51 { NULL,
52 NULL,
53 NULL }
56 struct bench_subsys {
57 const char *name;
58 const char *summary;
59 struct bench_suite *suites;
62 static struct bench_subsys subsystems[] = {
63 { "sched",
64 "scheduler and IPC mechanism",
65 sched_suites },
66 { "mem",
67 "memory access performance",
68 mem_suites },
69 { NULL,
70 NULL,
71 NULL }
74 static void dump_suites(int subsys_index)
76 int i;
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++)
82 printf("\t%s: %s\n",
83 subsystems[subsys_index].suites[i].name,
84 subsystems[subsys_index].suites[i].summary);
86 printf("\n");
87 return;
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"),
96 OPT_END()
99 static const char * const bench_usage[] = {
100 "perf bench [<common options>] <subsystem> <suite> [<options>]",
101 NULL
104 static void print_usage(void)
106 int i;
108 printf("Usage: \n");
109 for (i = 0; bench_usage[i]; i++)
110 printf("\t%s\n", bench_usage[i]);
111 printf("\n");
113 printf("List of available subsystems...\n\n");
115 for (i = 0; subsystems[i].name; i++)
116 printf("\t%s: %s\n",
117 subsystems[i].name, subsystems[i].summary);
118 printf("\n");
121 static int bench_str2int(char *str)
123 if (!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;
138 if (argc < 2) {
139 /* No subsystem specified. */
140 print_usage();
141 goto end;
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);
150 goto end;
153 if (argc < 1) {
154 print_usage();
155 goto end;
158 for (i = 0; subsystems[i].name; i++) {
159 if (strcmp(subsystems[i].name, argv[0]))
160 continue;
162 if (argc < 2) {
163 /* No suite specified. */
164 dump_suites(i);
165 goto end;
168 for (j = 0; subsystems[i].suites[j].name; j++) {
169 if (strcmp(subsystems[i].suites[j].name, argv[1]))
170 continue;
172 if (bench_format == BENCH_FORMAT_DEFAULT)
173 printf("# Running %s/%s benchmark...\n",
174 subsystems[i].name,
175 subsystems[i].suites[j].name);
176 status = subsystems[i].suites[j].fn(argc - 1,
177 argv + 1, prefix);
178 goto end;
181 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
182 dump_suites(i);
183 goto end;
186 printf("Unknown suite:%s for %s\n", argv[1], argv[0]);
187 status = 1;
188 goto end;
191 printf("Unknown subsystem:%s\n", argv[0]);
192 status = 1;
194 end:
195 return status;