Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 2 | /* |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 3 | * builtin-bench.c |
| 4 | * |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 5 | * General benchmarking collections provided by perf |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 6 | * |
| 7 | * Copyright (C) 2009, Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp> |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 11 | * Available benchmark collection list: |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 12 | * |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 13 | * sched ... scheduler and IPC performance |
Davidlohr Bueso | c2a0820 | 2019-03-08 10:17:47 -0800 | [diff] [blame] | 14 | * syscall ... System call performance |
Hitoshi Mitake | 827f3b4 | 2009-11-18 00:20:09 +0900 | [diff] [blame] | 15 | * mem ... memory access performance |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 16 | * numa ... NUMA scheduling and MM performance |
Davidlohr Bueso | a043971 | 2013-12-14 20:31:55 -0800 | [diff] [blame] | 17 | * futex ... Futex performance |
Davidlohr Bueso | 121dd9e | 2018-11-06 07:22:25 -0800 | [diff] [blame] | 18 | * epoll ... Event poll performance |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 19 | */ |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 20 | #include <subcmd/parse-options.h> |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 21 | #include "builtin.h" |
| 22 | #include "bench/bench.h" |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 27 | #include <sys/prctl.h> |
Arnaldo Carvalho de Melo | 7f7c536 | 2019-07-04 11:32:27 -0300 | [diff] [blame] | 28 | #include <linux/zalloc.h> |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 29 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 30 | typedef int (*bench_fn_t)(int argc, const char **argv); |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 31 | |
| 32 | struct bench { |
| 33 | const char *name; |
| 34 | const char *summary; |
| 35 | bench_fn_t fn; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 36 | }; |
| 37 | |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 38 | #ifdef HAVE_LIBNUMA_SUPPORT |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 39 | static struct bench numa_benchmarks[] = { |
| 40 | { "mem", "Benchmark for NUMA workloads", bench_numa }, |
Ingo Molnar | aa254af | 2015-10-19 10:04:30 +0200 | [diff] [blame] | 41 | { "all", "Run all NUMA benchmarks", NULL }, |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 42 | { NULL, NULL, NULL } |
Ingo Molnar | 1c13f3c | 2012-12-06 13:51:59 +0100 | [diff] [blame] | 43 | }; |
Peter Hurley | 79d824e | 2013-01-27 20:51:22 -0500 | [diff] [blame] | 44 | #endif |
Ingo Molnar | 1c13f3c | 2012-12-06 13:51:59 +0100 | [diff] [blame] | 45 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 46 | static struct bench sched_benchmarks[] = { |
| 47 | { "messaging", "Benchmark for scheduling and IPC", bench_sched_messaging }, |
| 48 | { "pipe", "Benchmark for pipe() between two processes", bench_sched_pipe }, |
Ingo Molnar | aa254af | 2015-10-19 10:04:30 +0200 | [diff] [blame] | 49 | { "all", "Run all scheduler benchmarks", NULL }, |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 50 | { NULL, NULL, NULL } |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 51 | }; |
| 52 | |
Davidlohr Bueso | c2a0820 | 2019-03-08 10:17:47 -0800 | [diff] [blame] | 53 | static struct bench syscall_benchmarks[] = { |
| 54 | { "basic", "Benchmark for basic getppid(2) calls", bench_syscall_basic }, |
| 55 | { "all", "Run all syscall benchmarks", NULL }, |
| 56 | { NULL, NULL, NULL }, |
| 57 | }; |
| 58 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 59 | static struct bench mem_benchmarks[] = { |
Ingo Molnar | 13b1fdc | 2015-10-19 10:04:26 +0200 | [diff] [blame] | 60 | { "memcpy", "Benchmark for memcpy() functions", bench_mem_memcpy }, |
| 61 | { "memset", "Benchmark for memset() functions", bench_mem_memset }, |
Ian Rogers | 7c43b0c | 2020-07-29 15:00:34 -0700 | [diff] [blame] | 62 | { "find_bit", "Benchmark for find_bit() functions", bench_mem_find_bit }, |
Ingo Molnar | aa254af | 2015-10-19 10:04:30 +0200 | [diff] [blame] | 63 | { "all", "Run all memory access benchmarks", NULL }, |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 64 | { NULL, NULL, NULL } |
Hitoshi Mitake | 827f3b4 | 2009-11-18 00:20:09 +0900 | [diff] [blame] | 65 | }; |
| 66 | |
Davidlohr Bueso | a043971 | 2013-12-14 20:31:55 -0800 | [diff] [blame] | 67 | static struct bench futex_benchmarks[] = { |
| 68 | { "hash", "Benchmark for futex hash table", bench_futex_hash }, |
Davidlohr Bueso | 27db783 | 2013-12-14 20:31:56 -0800 | [diff] [blame] | 69 | { "wake", "Benchmark for futex wake calls", bench_futex_wake }, |
Davidlohr Bueso | d65817b | 2015-05-08 11:37:59 -0700 | [diff] [blame] | 70 | { "wake-parallel", "Benchmark for parallel futex wake calls", bench_futex_wake_parallel }, |
Davidlohr Bueso | 0fb298c | 2013-12-14 20:31:57 -0800 | [diff] [blame] | 71 | { "requeue", "Benchmark for futex requeue calls", bench_futex_requeue }, |
Davidlohr Bueso | d2f3f5d | 2015-07-07 01:55:53 -0700 | [diff] [blame] | 72 | /* pi-futexes */ |
| 73 | { "lock-pi", "Benchmark for futex lock_pi calls", bench_futex_lock_pi }, |
Ingo Molnar | aa254af | 2015-10-19 10:04:30 +0200 | [diff] [blame] | 74 | { "all", "Run all futex benchmarks", NULL }, |
Davidlohr Bueso | a043971 | 2013-12-14 20:31:55 -0800 | [diff] [blame] | 75 | { NULL, NULL, NULL } |
| 76 | }; |
| 77 | |
Arnaldo Carvalho de Melo | ba35fe9 | 2020-05-20 12:21:07 -0300 | [diff] [blame] | 78 | #ifdef HAVE_EVENTFD_SUPPORT |
Davidlohr Bueso | 121dd9e | 2018-11-06 07:22:25 -0800 | [diff] [blame] | 79 | static struct bench epoll_benchmarks[] = { |
| 80 | { "wait", "Benchmark epoll concurrent epoll_waits", bench_epoll_wait }, |
Davidlohr Bueso | 231457e | 2018-11-06 07:22:26 -0800 | [diff] [blame] | 81 | { "ctl", "Benchmark epoll concurrent epoll_ctls", bench_epoll_ctl }, |
Davidlohr Bueso | 121dd9e | 2018-11-06 07:22:25 -0800 | [diff] [blame] | 82 | { "all", "Run all futex benchmarks", NULL }, |
| 83 | { NULL, NULL, NULL } |
| 84 | }; |
Arnaldo Carvalho de Melo | ba35fe9 | 2020-05-20 12:21:07 -0300 | [diff] [blame] | 85 | #endif // HAVE_EVENTFD_SUPPORT |
Davidlohr Bueso | 121dd9e | 2018-11-06 07:22:25 -0800 | [diff] [blame] | 86 | |
Ian Rogers | 2a4b516 | 2020-04-02 08:43:53 -0700 | [diff] [blame] | 87 | static struct bench internals_benchmarks[] = { |
| 88 | { "synthesize", "Benchmark perf event synthesis", bench_synthesize }, |
Ian Rogers | 51876bd | 2020-05-01 15:13:13 -0700 | [diff] [blame] | 89 | { "kallsyms-parse", "Benchmark kallsyms parsing", bench_kallsyms_parse }, |
Namhyung Kim | 0bf02a0 | 2020-10-12 16:02:09 +0900 | [diff] [blame] | 90 | { "inject-build-id", "Benchmark build-id injection", bench_inject_build_id }, |
Ian Rogers | 2a4b516 | 2020-04-02 08:43:53 -0700 | [diff] [blame] | 91 | { NULL, NULL, NULL } |
| 92 | }; |
| 93 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 94 | struct collection { |
| 95 | const char *name; |
| 96 | const char *summary; |
| 97 | struct bench *benchmarks; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 98 | }; |
| 99 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 100 | static struct collection collections[] = { |
Davidlohr Bueso | a043971 | 2013-12-14 20:31:55 -0800 | [diff] [blame] | 101 | { "sched", "Scheduler and IPC benchmarks", sched_benchmarks }, |
Davidlohr Bueso | c2a0820 | 2019-03-08 10:17:47 -0800 | [diff] [blame] | 102 | { "syscall", "System call benchmarks", syscall_benchmarks }, |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 103 | { "mem", "Memory access benchmarks", mem_benchmarks }, |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 104 | #ifdef HAVE_LIBNUMA_SUPPORT |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 105 | { "numa", "NUMA scheduling and MM benchmarks", numa_benchmarks }, |
Peter Hurley | 79d824e | 2013-01-27 20:51:22 -0500 | [diff] [blame] | 106 | #endif |
Davidlohr Bueso | a043971 | 2013-12-14 20:31:55 -0800 | [diff] [blame] | 107 | {"futex", "Futex stressing benchmarks", futex_benchmarks }, |
Arnaldo Carvalho de Melo | ba35fe9 | 2020-05-20 12:21:07 -0300 | [diff] [blame] | 108 | #ifdef HAVE_EVENTFD_SUPPORT |
Davidlohr Bueso | 121dd9e | 2018-11-06 07:22:25 -0800 | [diff] [blame] | 109 | {"epoll", "Epoll stressing benchmarks", epoll_benchmarks }, |
| 110 | #endif |
Ian Rogers | 2a4b516 | 2020-04-02 08:43:53 -0700 | [diff] [blame] | 111 | { "internals", "Perf-internals benchmarks", internals_benchmarks }, |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 112 | { "all", "All benchmarks", NULL }, |
| 113 | { NULL, NULL, NULL } |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 114 | }; |
| 115 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 116 | /* Iterate over all benchmark collections: */ |
| 117 | #define for_each_collection(coll) \ |
| 118 | for (coll = collections; coll->name; coll++) |
| 119 | |
| 120 | /* Iterate over all benchmarks within a collection: */ |
| 121 | #define for_each_bench(coll, bench) \ |
Patrick Palka | 6eeefcc | 2014-03-12 18:40:51 -0400 | [diff] [blame] | 122 | for (bench = coll->benchmarks; bench && bench->name; bench++) |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 123 | |
| 124 | static void dump_benchmarks(struct collection *coll) |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 125 | { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 126 | struct bench *bench; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 127 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 128 | printf("\n # List of available benchmarks for collection '%s':\n\n", coll->name); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 129 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 130 | for_each_bench(coll, bench) |
| 131 | printf("%14s: %s\n", bench->name, bench->summary); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 132 | |
| 133 | printf("\n"); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 134 | } |
| 135 | |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 136 | static const char *bench_format_str; |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 137 | |
| 138 | /* Output/formatting style, exported to benchmark modules: */ |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 139 | int bench_format = BENCH_FORMAT_DEFAULT; |
Davidlohr Bueso | b6f0629 | 2014-06-16 11:14:19 -0700 | [diff] [blame] | 140 | unsigned int bench_repeat = 10; /* default number of times to repeat the run */ |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 141 | |
| 142 | static const struct option bench_options[] = { |
Ingo Molnar | 7a46a8f | 2015-10-19 10:04:22 +0200 | [diff] [blame] | 143 | OPT_STRING('f', "format", &bench_format_str, "default|simple", "Specify the output formatting style"), |
Davidlohr Bueso | b6f0629 | 2014-06-16 11:14:19 -0700 | [diff] [blame] | 144 | OPT_UINTEGER('r', "repeat", &bench_repeat, "Specify amount of times to repeat the run"), |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 145 | OPT_END() |
| 146 | }; |
| 147 | |
| 148 | static const char * const bench_usage[] = { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 149 | "perf bench [<common options>] <collection> <benchmark> [<options>]", |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 150 | NULL |
| 151 | }; |
| 152 | |
| 153 | static void print_usage(void) |
| 154 | { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 155 | struct collection *coll; |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 156 | int i; |
| 157 | |
| 158 | printf("Usage: \n"); |
| 159 | for (i = 0; bench_usage[i]; i++) |
| 160 | printf("\t%s\n", bench_usage[i]); |
| 161 | printf("\n"); |
| 162 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 163 | printf(" # List of all available benchmark collections:\n\n"); |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 164 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 165 | for_each_collection(coll) |
| 166 | printf("%14s: %s\n", coll->name, coll->summary); |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 167 | printf("\n"); |
| 168 | } |
| 169 | |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 170 | static int bench_str2int(const char *str) |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 171 | { |
| 172 | if (!str) |
| 173 | return BENCH_FORMAT_DEFAULT; |
| 174 | |
| 175 | if (!strcmp(str, BENCH_FORMAT_DEFAULT_STR)) |
| 176 | return BENCH_FORMAT_DEFAULT; |
| 177 | else if (!strcmp(str, BENCH_FORMAT_SIMPLE_STR)) |
| 178 | return BENCH_FORMAT_SIMPLE; |
| 179 | |
| 180 | return BENCH_FORMAT_UNKNOWN; |
| 181 | } |
| 182 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 183 | /* |
| 184 | * Run a specific benchmark but first rename the running task's ->comm[] |
| 185 | * to something meaningful: |
| 186 | */ |
| 187 | static int run_bench(const char *coll_name, const char *bench_name, bench_fn_t fn, |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 188 | int argc, const char **argv) |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 189 | { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 190 | int size; |
| 191 | char *name; |
| 192 | int ret; |
| 193 | |
| 194 | size = strlen(coll_name) + 1 + strlen(bench_name) + 1; |
| 195 | |
| 196 | name = zalloc(size); |
| 197 | BUG_ON(!name); |
| 198 | |
| 199 | scnprintf(name, size, "%s-%s", coll_name, bench_name); |
| 200 | |
| 201 | prctl(PR_SET_NAME, name); |
| 202 | argv[0] = name; |
| 203 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 204 | ret = fn(argc, argv); |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 205 | |
| 206 | free(name); |
| 207 | |
| 208 | return ret; |
| 209 | } |
| 210 | |
| 211 | static void run_collection(struct collection *coll) |
| 212 | { |
| 213 | struct bench *bench; |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 214 | const char *argv[2]; |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 215 | |
| 216 | argv[1] = NULL; |
| 217 | /* |
| 218 | * TODO: |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 219 | * |
| 220 | * Preparing preset parameters for |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 221 | * embedded, ordinary PC, HPC, etc... |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 222 | * would be helpful. |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 223 | */ |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 224 | for_each_bench(coll, bench) { |
| 225 | if (!bench->fn) |
| 226 | break; |
| 227 | printf("# Running %s/%s benchmark...\n", coll->name, bench->name); |
Namhyung Kim | 9b494ea | 2013-01-08 18:39:26 +0900 | [diff] [blame] | 228 | fflush(stdout); |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 229 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 230 | argv[1] = bench->name; |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 231 | run_bench(coll->name, bench->name, bench->fn, 1, argv); |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 232 | printf("\n"); |
| 233 | } |
| 234 | } |
| 235 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 236 | static void run_all_collections(void) |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 237 | { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 238 | struct collection *coll; |
| 239 | |
| 240 | for_each_collection(coll) |
| 241 | run_collection(coll); |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 242 | } |
| 243 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 244 | int cmd_bench(int argc, const char **argv) |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 245 | { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 246 | struct collection *coll; |
| 247 | int ret = 0; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 248 | |
| 249 | if (argc < 2) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 250 | /* No collection specified. */ |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 251 | print_usage(); |
| 252 | goto end; |
| 253 | } |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 254 | |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 255 | argc = parse_options(argc, argv, bench_options, bench_usage, |
| 256 | PARSE_OPT_STOP_AT_NON_OPTION); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 257 | |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 258 | bench_format = bench_str2int(bench_format_str); |
| 259 | if (bench_format == BENCH_FORMAT_UNKNOWN) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 260 | printf("Unknown format descriptor: '%s'\n", bench_format_str); |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 261 | goto end; |
| 262 | } |
| 263 | |
Davidlohr Bueso | b6f0629 | 2014-06-16 11:14:19 -0700 | [diff] [blame] | 264 | if (bench_repeat == 0) { |
| 265 | printf("Invalid repeat option: Must specify a positive value\n"); |
| 266 | goto end; |
| 267 | } |
| 268 | |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 269 | if (argc < 1) { |
| 270 | print_usage(); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 271 | goto end; |
| 272 | } |
| 273 | |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 274 | if (!strcmp(argv[0], "all")) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 275 | run_all_collections(); |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 276 | goto end; |
| 277 | } |
| 278 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 279 | for_each_collection(coll) { |
| 280 | struct bench *bench; |
| 281 | |
| 282 | if (strcmp(coll->name, argv[0])) |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 283 | continue; |
| 284 | |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 285 | if (argc < 2) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 286 | /* No bench specified. */ |
| 287 | dump_benchmarks(coll); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 288 | goto end; |
| 289 | } |
| 290 | |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 291 | if (!strcmp(argv[1], "all")) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 292 | run_collection(coll); |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 293 | goto end; |
| 294 | } |
| 295 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 296 | for_each_bench(coll, bench) { |
| 297 | if (strcmp(bench->name, argv[1])) |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 298 | continue; |
| 299 | |
Hitoshi Mitake | 79e295d | 2009-11-11 00:04:00 +0900 | [diff] [blame] | 300 | if (bench_format == BENCH_FORMAT_DEFAULT) |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 301 | printf("# Running '%s/%s' benchmark:\n", coll->name, bench->name); |
Namhyung Kim | 9b494ea | 2013-01-08 18:39:26 +0900 | [diff] [blame] | 302 | fflush(stdout); |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 303 | ret = run_bench(coll->name, bench->name, bench->fn, argc-1, argv+1); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 304 | goto end; |
| 305 | } |
| 306 | |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 307 | if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 308 | dump_benchmarks(coll); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 309 | goto end; |
| 310 | } |
| 311 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 312 | printf("Unknown benchmark: '%s' for collection '%s'\n", argv[1], argv[0]); |
| 313 | ret = 1; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 314 | goto end; |
| 315 | } |
| 316 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 317 | printf("Unknown collection: '%s'\n", argv[0]); |
| 318 | ret = 1; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 319 | |
| 320 | end: |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 321 | return ret; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 322 | } |