]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - tools/perf/builtin-bench.c
perf bench: Modify command-list.txt for the entry of perf-bench
[mirror_ubuntu-artful-kernel.git] / tools / perf / builtin-bench.c
CommitLineData
629cc356
HM
1/*
2 *
3 * builtin-bench.c
4 *
5 * General benchmarking subsystem provided by perf
6 *
7 * Copyright (C) 2009, Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
8 *
9 */
10
11/*
12 *
13 * Available subsystem list:
14 * sched ... scheduler and IPC mechanism
15 *
16 */
17
18#include "perf.h"
19#include "util/util.h"
20#include "util/parse-options.h"
21#include "builtin.h"
22#include "bench/bench.h"
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27
28struct bench_suite {
29 const char *name;
30 const char *summary;
31 int (*fn)(int, const char **, const char *);
32};
33
34static struct bench_suite sched_suites[] = {
35 { "messaging",
36 "Benchmark for scheduler and IPC mechanisms",
37 bench_sched_messaging },
38 { "pipe",
39 "Flood of communication over pipe() between two processes",
40 bench_sched_pipe },
41 { NULL,
42 NULL,
43 NULL }
44};
45
46struct bench_subsys {
47 const char *name;
48 const char *summary;
49 struct bench_suite *suites;
50};
51
52static struct bench_subsys subsystems[] = {
53 { "sched",
54 "scheduler and IPC mechanism",
55 sched_suites },
56 { NULL,
57 NULL,
58 NULL }
59};
60
61static void dump_suites(int subsys_index)
62{
63 int i;
64
65 printf("List of available suites for %s...\n\n",
66 subsystems[subsys_index].name);
67
68 for (i = 0; subsystems[subsys_index].suites[i].name; i++)
69 printf("\t%s: %s\n",
70 subsystems[subsys_index].suites[i].name,
71 subsystems[subsys_index].suites[i].summary);
72
73 printf("\n");
74 return;
75}
76
386d7e9e
HM
77static char *bench_format_str;
78int bench_format = BENCH_FORMAT_DEFAULT;
79
80static const struct option bench_options[] = {
81 OPT_STRING('f', "format", &bench_format_str, "default",
82 "Specify format style"),
83 OPT_END()
84};
85
86static const char * const bench_usage[] = {
87 "perf bench [<common options>] <subsystem> <suite> [<options>]",
88 NULL
89};
90
91static void print_usage(void)
92{
93 int i;
94
95 printf("Usage: \n");
96 for (i = 0; bench_usage[i]; i++)
97 printf("\t%s\n", bench_usage[i]);
98 printf("\n");
99
100 printf("List of available subsystems...\n\n");
101
102 for (i = 0; subsystems[i].name; i++)
103 printf("\t%s: %s\n",
104 subsystems[i].name, subsystems[i].summary);
105 printf("\n");
106}
107
108static int bench_str2int(char *str)
109{
110 if (!str)
111 return BENCH_FORMAT_DEFAULT;
112
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;
117
118 return BENCH_FORMAT_UNKNOWN;
119}
120
629cc356
HM
121int cmd_bench(int argc, const char **argv, const char *prefix __used)
122{
123 int i, j, status = 0;
124
125 if (argc < 2) {
126 /* No subsystem specified. */
386d7e9e
HM
127 print_usage();
128 goto end;
129 }
629cc356 130
386d7e9e
HM
131 argc = parse_options(argc, argv, bench_options, bench_usage,
132 PARSE_OPT_STOP_AT_NON_OPTION);
133
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);
137 goto end;
138 }
629cc356 139
386d7e9e
HM
140 if (argc < 1) {
141 print_usage();
629cc356
HM
142 goto end;
143 }
144
145 for (i = 0; subsystems[i].name; i++) {
386d7e9e 146 if (strcmp(subsystems[i].name, argv[0]))
629cc356
HM
147 continue;
148
386d7e9e 149 if (argc < 2) {
629cc356
HM
150 /* No suite specified. */
151 dump_suites(i);
152 goto end;
153 }
154
155 for (j = 0; subsystems[i].suites[j].name; j++) {
386d7e9e 156 if (strcmp(subsystems[i].suites[j].name, argv[1]))
629cc356
HM
157 continue;
158
386d7e9e
HM
159 status = subsystems[i].suites[j].fn(argc - 1,
160 argv + 1, prefix);
629cc356
HM
161 goto end;
162 }
163
386d7e9e 164 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
629cc356
HM
165 dump_suites(i);
166 goto end;
167 }
168
386d7e9e 169 printf("Unknown suite:%s for %s\n", argv[1], argv[0]);
629cc356
HM
170 status = 1;
171 goto end;
172 }
173
386d7e9e 174 printf("Unknown subsystem:%s\n", argv[0]);
629cc356
HM
175 status = 1;
176
177end:
178 return status;
179}