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 |
Hitoshi Mitake | 827f3b4 | 2009-11-18 00:20:09 +0900 | [diff] [blame] | 14 | * mem ... memory access performance |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 15 | * numa ... NUMA scheduling and MM performance |
Davidlohr Bueso | a043971 | 2013-12-14 20:31:55 -0800 | [diff] [blame] | 16 | * futex ... Futex performance |
Davidlohr Bueso | 121dd9e | 2018-11-06 07:22:25 -0800 | [diff] [blame] | 17 | * epoll ... Event poll performance |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 18 | */ |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 19 | #include "perf.h" |
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 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 53 | static struct bench mem_benchmarks[] = { |
Ingo Molnar | 13b1fdc | 2015-10-19 10:04:26 +0200 | [diff] [blame] | 54 | { "memcpy", "Benchmark for memcpy() functions", bench_mem_memcpy }, |
| 55 | { "memset", "Benchmark for memset() functions", bench_mem_memset }, |
Ingo Molnar | aa254af | 2015-10-19 10:04:30 +0200 | [diff] [blame] | 56 | { "all", "Run all memory access benchmarks", NULL }, |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 57 | { NULL, NULL, NULL } |
Hitoshi Mitake | 827f3b4 | 2009-11-18 00:20:09 +0900 | [diff] [blame] | 58 | }; |
| 59 | |
Davidlohr Bueso | a043971 | 2013-12-14 20:31:55 -0800 | [diff] [blame] | 60 | static struct bench futex_benchmarks[] = { |
| 61 | { "hash", "Benchmark for futex hash table", bench_futex_hash }, |
Davidlohr Bueso | 27db783 | 2013-12-14 20:31:56 -0800 | [diff] [blame] | 62 | { "wake", "Benchmark for futex wake calls", bench_futex_wake }, |
Davidlohr Bueso | d65817b | 2015-05-08 11:37:59 -0700 | [diff] [blame] | 63 | { "wake-parallel", "Benchmark for parallel futex wake calls", bench_futex_wake_parallel }, |
Davidlohr Bueso | 0fb298c | 2013-12-14 20:31:57 -0800 | [diff] [blame] | 64 | { "requeue", "Benchmark for futex requeue calls", bench_futex_requeue }, |
Davidlohr Bueso | d2f3f5d | 2015-07-07 01:55:53 -0700 | [diff] [blame] | 65 | /* pi-futexes */ |
| 66 | { "lock-pi", "Benchmark for futex lock_pi calls", bench_futex_lock_pi }, |
Ingo Molnar | aa254af | 2015-10-19 10:04:30 +0200 | [diff] [blame] | 67 | { "all", "Run all futex benchmarks", NULL }, |
Davidlohr Bueso | a043971 | 2013-12-14 20:31:55 -0800 | [diff] [blame] | 68 | { NULL, NULL, NULL } |
| 69 | }; |
| 70 | |
Davidlohr Bueso | 121dd9e | 2018-11-06 07:22:25 -0800 | [diff] [blame] | 71 | #ifdef HAVE_EVENTFD |
| 72 | static struct bench epoll_benchmarks[] = { |
| 73 | { "wait", "Benchmark epoll concurrent epoll_waits", bench_epoll_wait }, |
Davidlohr Bueso | 231457e | 2018-11-06 07:22:26 -0800 | [diff] [blame] | 74 | { "ctl", "Benchmark epoll concurrent epoll_ctls", bench_epoll_ctl }, |
Davidlohr Bueso | 121dd9e | 2018-11-06 07:22:25 -0800 | [diff] [blame] | 75 | { "all", "Run all futex benchmarks", NULL }, |
| 76 | { NULL, NULL, NULL } |
| 77 | }; |
| 78 | #endif // HAVE_EVENTFD |
| 79 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 80 | struct collection { |
| 81 | const char *name; |
| 82 | const char *summary; |
| 83 | struct bench *benchmarks; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 84 | }; |
| 85 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 86 | static struct collection collections[] = { |
Davidlohr Bueso | a043971 | 2013-12-14 20:31:55 -0800 | [diff] [blame] | 87 | { "sched", "Scheduler and IPC benchmarks", sched_benchmarks }, |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 88 | { "mem", "Memory access benchmarks", mem_benchmarks }, |
Ingo Molnar | 89fe808 | 2013-09-30 12:07:11 +0200 | [diff] [blame] | 89 | #ifdef HAVE_LIBNUMA_SUPPORT |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 90 | { "numa", "NUMA scheduling and MM benchmarks", numa_benchmarks }, |
Peter Hurley | 79d824e | 2013-01-27 20:51:22 -0500 | [diff] [blame] | 91 | #endif |
Davidlohr Bueso | a043971 | 2013-12-14 20:31:55 -0800 | [diff] [blame] | 92 | {"futex", "Futex stressing benchmarks", futex_benchmarks }, |
Davidlohr Bueso | 121dd9e | 2018-11-06 07:22:25 -0800 | [diff] [blame] | 93 | #ifdef HAVE_EVENTFD |
| 94 | {"epoll", "Epoll stressing benchmarks", epoll_benchmarks }, |
| 95 | #endif |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 96 | { "all", "All benchmarks", NULL }, |
| 97 | { NULL, NULL, NULL } |
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 | /* Iterate over all benchmark collections: */ |
| 101 | #define for_each_collection(coll) \ |
| 102 | for (coll = collections; coll->name; coll++) |
| 103 | |
| 104 | /* Iterate over all benchmarks within a collection: */ |
| 105 | #define for_each_bench(coll, bench) \ |
Patrick Palka | 6eeefcc | 2014-03-12 18:40:51 -0400 | [diff] [blame] | 106 | for (bench = coll->benchmarks; bench && bench->name; bench++) |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 107 | |
| 108 | static void dump_benchmarks(struct collection *coll) |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 109 | { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 110 | struct bench *bench; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 111 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 112 | 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] | 113 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 114 | for_each_bench(coll, bench) |
| 115 | printf("%14s: %s\n", bench->name, bench->summary); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 116 | |
| 117 | printf("\n"); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 118 | } |
| 119 | |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 120 | static const char *bench_format_str; |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 121 | |
| 122 | /* Output/formatting style, exported to benchmark modules: */ |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 123 | int bench_format = BENCH_FORMAT_DEFAULT; |
Davidlohr Bueso | b6f0629 | 2014-06-16 11:14:19 -0700 | [diff] [blame] | 124 | 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] | 125 | |
| 126 | static const struct option bench_options[] = { |
Ingo Molnar | 7a46a8f | 2015-10-19 10:04:22 +0200 | [diff] [blame] | 127 | 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] | 128 | 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] | 129 | OPT_END() |
| 130 | }; |
| 131 | |
| 132 | static const char * const bench_usage[] = { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 133 | "perf bench [<common options>] <collection> <benchmark> [<options>]", |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 134 | NULL |
| 135 | }; |
| 136 | |
| 137 | static void print_usage(void) |
| 138 | { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 139 | struct collection *coll; |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 140 | int i; |
| 141 | |
| 142 | printf("Usage: \n"); |
| 143 | for (i = 0; bench_usage[i]; i++) |
| 144 | printf("\t%s\n", bench_usage[i]); |
| 145 | printf("\n"); |
| 146 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 147 | printf(" # List of all available benchmark collections:\n\n"); |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 148 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 149 | for_each_collection(coll) |
| 150 | printf("%14s: %s\n", coll->name, coll->summary); |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 151 | printf("\n"); |
| 152 | } |
| 153 | |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 154 | static int bench_str2int(const char *str) |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 155 | { |
| 156 | if (!str) |
| 157 | return BENCH_FORMAT_DEFAULT; |
| 158 | |
| 159 | if (!strcmp(str, BENCH_FORMAT_DEFAULT_STR)) |
| 160 | return BENCH_FORMAT_DEFAULT; |
| 161 | else if (!strcmp(str, BENCH_FORMAT_SIMPLE_STR)) |
| 162 | return BENCH_FORMAT_SIMPLE; |
| 163 | |
| 164 | return BENCH_FORMAT_UNKNOWN; |
| 165 | } |
| 166 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 167 | /* |
| 168 | * Run a specific benchmark but first rename the running task's ->comm[] |
| 169 | * to something meaningful: |
| 170 | */ |
| 171 | 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] | 172 | int argc, const char **argv) |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 173 | { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 174 | int size; |
| 175 | char *name; |
| 176 | int ret; |
| 177 | |
| 178 | size = strlen(coll_name) + 1 + strlen(bench_name) + 1; |
| 179 | |
| 180 | name = zalloc(size); |
| 181 | BUG_ON(!name); |
| 182 | |
| 183 | scnprintf(name, size, "%s-%s", coll_name, bench_name); |
| 184 | |
| 185 | prctl(PR_SET_NAME, name); |
| 186 | argv[0] = name; |
| 187 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 188 | ret = fn(argc, argv); |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 189 | |
| 190 | free(name); |
| 191 | |
| 192 | return ret; |
| 193 | } |
| 194 | |
| 195 | static void run_collection(struct collection *coll) |
| 196 | { |
| 197 | struct bench *bench; |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 198 | const char *argv[2]; |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 199 | |
| 200 | argv[1] = NULL; |
| 201 | /* |
| 202 | * TODO: |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 203 | * |
| 204 | * Preparing preset parameters for |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 205 | * embedded, ordinary PC, HPC, etc... |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 206 | * would be helpful. |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 207 | */ |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 208 | for_each_bench(coll, bench) { |
| 209 | if (!bench->fn) |
| 210 | break; |
| 211 | printf("# Running %s/%s benchmark...\n", coll->name, bench->name); |
Namhyung Kim | 9b494ea | 2013-01-08 18:39:26 +0900 | [diff] [blame] | 212 | fflush(stdout); |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 213 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 214 | argv[1] = bench->name; |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 215 | run_bench(coll->name, bench->name, bench->fn, 1, argv); |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 216 | printf("\n"); |
| 217 | } |
| 218 | } |
| 219 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 220 | static void run_all_collections(void) |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 221 | { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 222 | struct collection *coll; |
| 223 | |
| 224 | for_each_collection(coll) |
| 225 | run_collection(coll); |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 226 | } |
| 227 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 228 | int cmd_bench(int argc, const char **argv) |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 229 | { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 230 | struct collection *coll; |
| 231 | int ret = 0; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 232 | |
| 233 | if (argc < 2) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 234 | /* No collection specified. */ |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 235 | print_usage(); |
| 236 | goto end; |
| 237 | } |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 238 | |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 239 | argc = parse_options(argc, argv, bench_options, bench_usage, |
| 240 | PARSE_OPT_STOP_AT_NON_OPTION); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 241 | |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 242 | bench_format = bench_str2int(bench_format_str); |
| 243 | if (bench_format == BENCH_FORMAT_UNKNOWN) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 244 | printf("Unknown format descriptor: '%s'\n", bench_format_str); |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 245 | goto end; |
| 246 | } |
| 247 | |
Davidlohr Bueso | b6f0629 | 2014-06-16 11:14:19 -0700 | [diff] [blame] | 248 | if (bench_repeat == 0) { |
| 249 | printf("Invalid repeat option: Must specify a positive value\n"); |
| 250 | goto end; |
| 251 | } |
| 252 | |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 253 | if (argc < 1) { |
| 254 | print_usage(); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 255 | goto end; |
| 256 | } |
| 257 | |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 258 | if (!strcmp(argv[0], "all")) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 259 | run_all_collections(); |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 260 | goto end; |
| 261 | } |
| 262 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 263 | for_each_collection(coll) { |
| 264 | struct bench *bench; |
| 265 | |
| 266 | if (strcmp(coll->name, argv[0])) |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 267 | continue; |
| 268 | |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 269 | if (argc < 2) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 270 | /* No bench specified. */ |
| 271 | dump_benchmarks(coll); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 272 | goto end; |
| 273 | } |
| 274 | |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 275 | if (!strcmp(argv[1], "all")) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 276 | run_collection(coll); |
Hitoshi Mitake | 2044279 | 2009-12-13 17:01:59 +0900 | [diff] [blame] | 277 | goto end; |
| 278 | } |
| 279 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 280 | for_each_bench(coll, bench) { |
| 281 | if (strcmp(bench->name, argv[1])) |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 282 | continue; |
| 283 | |
Hitoshi Mitake | 79e295d | 2009-11-11 00:04:00 +0900 | [diff] [blame] | 284 | if (bench_format == BENCH_FORMAT_DEFAULT) |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 285 | printf("# Running '%s/%s' benchmark:\n", coll->name, bench->name); |
Namhyung Kim | 9b494ea | 2013-01-08 18:39:26 +0900 | [diff] [blame] | 286 | fflush(stdout); |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 287 | 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] | 288 | goto end; |
| 289 | } |
| 290 | |
Hitoshi Mitake | 386d7e9 | 2009-11-10 08:20:00 +0900 | [diff] [blame] | 291 | if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 292 | dump_benchmarks(coll); |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 293 | goto end; |
| 294 | } |
| 295 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 296 | printf("Unknown benchmark: '%s' for collection '%s'\n", argv[1], argv[0]); |
| 297 | ret = 1; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 298 | goto end; |
| 299 | } |
| 300 | |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 301 | printf("Unknown collection: '%s'\n", argv[0]); |
| 302 | ret = 1; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 303 | |
| 304 | end: |
Ingo Molnar | 4157922 | 2013-10-23 14:37:56 +0200 | [diff] [blame] | 305 | return ret; |
Hitoshi Mitake | 629cc35 | 2009-11-05 09:31:34 +0900 | [diff] [blame] | 306 | } |