John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
sergeyv | 7dc370b | 2016-06-17 11:21:11 -0700 | [diff] [blame] | 17 | #include "tests/common/LeakChecker.h" |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 18 | #include "tests/common/TestScene.h" |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 19 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 20 | #include "Properties.h" |
Seigo Nonaka | b6e2013 | 2016-11-14 14:07:41 +0900 | [diff] [blame] | 21 | #include "hwui/Typeface.h" |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 22 | #include "protos/hwui.pb.h" |
| 23 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 24 | #include <benchmark/benchmark.h> |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 25 | #include <getopt.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 26 | #include <pthread.h> |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 27 | #include <stdio.h> |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 28 | #include <unistd.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 29 | #include <string> |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 30 | #include <unordered_map> |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 31 | #include <vector> |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 32 | |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 33 | #include <errno.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 34 | #include <fcntl.h> |
| 35 | #include <sys/stat.h> |
| 36 | #include <sys/types.h> |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 37 | |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 38 | using namespace android; |
| 39 | using namespace android::uirenderer; |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 40 | using namespace android::uirenderer::test; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 41 | |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 42 | static int gRepeatCount = 1; |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 43 | static std::vector<TestScene::Info> gRunTests; |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 44 | static TestScene::Options gOpts; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 45 | std::unique_ptr<benchmark::BenchmarkReporter> gBenchmarkReporter; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 46 | |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 47 | void run(const TestScene::Info& info, const TestScene::Options& opts, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 48 | benchmark::BenchmarkReporter* reporter); |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 49 | |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 50 | static void printHelp() { |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 51 | printf(R"( |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 52 | USAGE: hwuimacro [OPTIONS] <TESTNAME> |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 53 | |
| 54 | OPTIONS: |
| 55 | -c, --count=NUM NUM loops a test should run (example, number of frames) |
| 56 | -r, --runs=NUM Repeat the test(s) NUM times |
| 57 | -h, --help Display this help |
| 58 | --list List all tests |
| 59 | --wait-for-gpu Set this to wait for the GPU before producing the |
| 60 | next frame. Note that without locked clocks this will |
| 61 | pathologically bad performance due to large idle time |
| 62 | --report-frametime[=weight] If set, the test will print to stdout the |
| 63 | moving average frametime. Weight is optional, default is 10 |
| 64 | --cpuset=name Adds the test to the specified cpuset before running |
| 65 | Not supported on all devices and needs root |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 66 | --offscreen Render tests off device screen. This option is on by default |
| 67 | --onscreen Render tests on device screen. By default tests |
| 68 | are offscreen rendered |
| 69 | --benchmark_format Set output format. Possible values are tabular, json, csv |
John Reck | 18f442e | 2018-04-09 16:56:34 -0700 | [diff] [blame^] | 70 | --renderer=TYPE Sets the render pipeline to use. May be skiagl or skiavk |
John Reck | ec10097 | 2018-04-05 16:41:41 -0700 | [diff] [blame] | 71 | --render-ahead=NUM Sets how far to render-ahead. Must be 0 (default), 1, or 2. |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 72 | )"); |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static void listTests() { |
| 76 | printf("Tests: \n"); |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 77 | for (auto&& test : TestScene::testMap()) { |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 78 | auto&& info = test.second; |
| 79 | const char* col1 = info.name.c_str(); |
| 80 | int dlen = info.description.length(); |
| 81 | const char* col2 = info.description.c_str(); |
| 82 | // World's best line breaking algorithm. |
| 83 | do { |
| 84 | int toPrint = dlen; |
| 85 | if (toPrint > 50) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 86 | char* found = (char*)memrchr(col2, ' ', 50); |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 87 | if (found) { |
| 88 | toPrint = found - col2; |
| 89 | } else { |
| 90 | toPrint = 50; |
| 91 | } |
| 92 | } |
| 93 | printf("%-20s %.*s\n", col1, toPrint, col2); |
| 94 | col1 = ""; |
| 95 | col2 += toPrint; |
| 96 | dlen -= toPrint; |
| 97 | while (*col2 == ' ') { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 98 | col2++; |
| 99 | dlen--; |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 100 | } |
| 101 | } while (dlen > 0); |
| 102 | printf("\n"); |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 106 | static void moveToCpuSet(const char* cpusetName) { |
| 107 | if (access("/dev/cpuset/tasks", F_OK)) { |
| 108 | fprintf(stderr, "don't have access to cpusets, skipping...\n"); |
| 109 | return; |
| 110 | } |
| 111 | static const int BUF_SIZE = 100; |
| 112 | char buffer[BUF_SIZE]; |
| 113 | |
| 114 | if (snprintf(buffer, BUF_SIZE, "/dev/cpuset/%s/tasks", cpusetName) >= BUF_SIZE) { |
| 115 | fprintf(stderr, "Error, cpusetName too large to fit in buffer '%s'\n", cpusetName); |
| 116 | return; |
| 117 | } |
| 118 | int fd = open(buffer, O_WRONLY | O_CLOEXEC); |
| 119 | if (fd == -1) { |
| 120 | fprintf(stderr, "Error opening file %d\n", errno); |
| 121 | return; |
| 122 | } |
| 123 | pid_t pid = getpid(); |
| 124 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 125 | int towrite = snprintf(buffer, BUF_SIZE, "%ld", (long)pid); |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 126 | if (towrite >= BUF_SIZE) { |
| 127 | fprintf(stderr, "Buffer wasn't large enough?\n"); |
| 128 | } else { |
| 129 | if (write(fd, buffer, towrite) != towrite) { |
| 130 | fprintf(stderr, "Failed to write, errno=%d", errno); |
| 131 | } |
| 132 | } |
| 133 | close(fd); |
| 134 | } |
| 135 | |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 136 | static bool setBenchmarkFormat(const char* format) { |
| 137 | if (!strcmp(format, "tabular")) { |
| 138 | gBenchmarkReporter.reset(new benchmark::ConsoleReporter()); |
| 139 | } else if (!strcmp(format, "json")) { |
| 140 | gBenchmarkReporter.reset(new benchmark::JSONReporter()); |
| 141 | } else if (!strcmp(format, "csv")) { |
| 142 | gBenchmarkReporter.reset(new benchmark::CSVReporter()); |
| 143 | } else { |
| 144 | fprintf(stderr, "Unknown format '%s'", format); |
| 145 | return false; |
| 146 | } |
| 147 | return true; |
| 148 | } |
| 149 | |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 150 | static bool setRenderer(const char* renderer) { |
John Reck | 18f442e | 2018-04-09 16:56:34 -0700 | [diff] [blame^] | 151 | if (!strcmp(renderer, "skiagl")) { |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 152 | Properties::overrideRenderPipelineType(RenderPipelineType::SkiaGL); |
| 153 | } else if (!strcmp(renderer, "skiavk")) { |
| 154 | Properties::overrideRenderPipelineType(RenderPipelineType::SkiaVulkan); |
| 155 | } else { |
| 156 | fprintf(stderr, "Unknown format '%s'", renderer); |
| 157 | return false; |
| 158 | } |
| 159 | return true; |
| 160 | } |
| 161 | |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 162 | // For options that only exist in long-form. Anything in the |
| 163 | // 0-255 range is reserved for short options (which just use their ASCII value) |
| 164 | namespace LongOpts { |
| 165 | enum { |
| 166 | Reserved = 255, |
| 167 | List, |
| 168 | WaitForGpu, |
| 169 | ReportFrametime, |
| 170 | CpuSet, |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 171 | BenchmarkFormat, |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 172 | Onscreen, |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 173 | Offscreen, |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 174 | Renderer, |
John Reck | ec10097 | 2018-04-05 16:41:41 -0700 | [diff] [blame] | 175 | RenderAhead, |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 176 | }; |
| 177 | } |
| 178 | |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 179 | static const struct option LONG_OPTIONS[] = { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 180 | {"frames", required_argument, nullptr, 'f'}, |
| 181 | {"repeat", required_argument, nullptr, 'r'}, |
| 182 | {"help", no_argument, nullptr, 'h'}, |
| 183 | {"list", no_argument, nullptr, LongOpts::List}, |
| 184 | {"wait-for-gpu", no_argument, nullptr, LongOpts::WaitForGpu}, |
| 185 | {"report-frametime", optional_argument, nullptr, LongOpts::ReportFrametime}, |
| 186 | {"cpuset", required_argument, nullptr, LongOpts::CpuSet}, |
| 187 | {"benchmark_format", required_argument, nullptr, LongOpts::BenchmarkFormat}, |
| 188 | {"onscreen", no_argument, nullptr, LongOpts::Onscreen}, |
| 189 | {"offscreen", no_argument, nullptr, LongOpts::Offscreen}, |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 190 | {"renderer", required_argument, nullptr, LongOpts::Renderer}, |
John Reck | ec10097 | 2018-04-05 16:41:41 -0700 | [diff] [blame] | 191 | {"render-ahead", required_argument, nullptr, LongOpts::RenderAhead}, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 192 | {0, 0, 0, 0}}; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 193 | |
| 194 | static const char* SHORT_OPTIONS = "c:r:h"; |
| 195 | |
| 196 | void parseOptions(int argc, char* argv[]) { |
| 197 | int c; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 198 | bool error = false; |
| 199 | opterr = 0; |
| 200 | |
| 201 | while (true) { |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 202 | /* getopt_long stores the option index here. */ |
| 203 | int option_index = 0; |
| 204 | |
| 205 | c = getopt_long(argc, argv, SHORT_OPTIONS, LONG_OPTIONS, &option_index); |
| 206 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 207 | if (c == -1) break; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 208 | |
| 209 | switch (c) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 210 | case 0: |
| 211 | // Option set a flag, don't need to do anything |
| 212 | // (although none of the current LONG_OPTIONS do this...) |
| 213 | break; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 214 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 215 | case LongOpts::List: |
| 216 | listTests(); |
| 217 | exit(EXIT_SUCCESS); |
| 218 | break; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 219 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 220 | case 'c': |
| 221 | gOpts.count = atoi(optarg); |
| 222 | if (!gOpts.count) { |
| 223 | fprintf(stderr, "Invalid frames argument '%s'\n", optarg); |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 224 | error = true; |
| 225 | } |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 226 | break; |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 227 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 228 | case 'r': |
| 229 | gRepeatCount = atoi(optarg); |
| 230 | if (!gRepeatCount) { |
| 231 | fprintf(stderr, "Invalid repeat argument '%s'\n", optarg); |
| 232 | error = true; |
| 233 | } else { |
| 234 | gRepeatCount = (gRepeatCount > 0 ? gRepeatCount : INT_MAX); |
| 235 | } |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 236 | break; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 237 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 238 | case LongOpts::ReportFrametime: |
| 239 | if (optarg) { |
| 240 | gOpts.reportFrametimeWeight = atoi(optarg); |
| 241 | if (!gOpts.reportFrametimeWeight) { |
| 242 | fprintf(stderr, "Invalid report frametime weight '%s'\n", optarg); |
| 243 | error = true; |
| 244 | } |
| 245 | } else { |
| 246 | gOpts.reportFrametimeWeight = 10; |
| 247 | } |
| 248 | break; |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 249 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 250 | case LongOpts::WaitForGpu: |
| 251 | Properties::waitForGpuCompletion = true; |
| 252 | break; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 253 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 254 | case LongOpts::CpuSet: |
| 255 | if (!optarg) { |
| 256 | error = true; |
| 257 | break; |
| 258 | } |
| 259 | moveToCpuSet(optarg); |
| 260 | break; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 261 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 262 | case LongOpts::BenchmarkFormat: |
| 263 | if (!optarg) { |
| 264 | error = true; |
| 265 | break; |
| 266 | } |
| 267 | if (!setBenchmarkFormat(optarg)) { |
| 268 | error = true; |
| 269 | } |
| 270 | break; |
| 271 | |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 272 | case LongOpts::Renderer: |
| 273 | if (!optarg) { |
| 274 | error = true; |
| 275 | break; |
| 276 | } |
| 277 | if (!setRenderer(optarg)) { |
| 278 | error = true; |
| 279 | } |
| 280 | break; |
| 281 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 282 | case LongOpts::Onscreen: |
| 283 | gOpts.renderOffscreen = false; |
| 284 | break; |
| 285 | |
| 286 | case LongOpts::Offscreen: |
| 287 | gOpts.renderOffscreen = true; |
| 288 | break; |
| 289 | |
John Reck | ec10097 | 2018-04-05 16:41:41 -0700 | [diff] [blame] | 290 | case LongOpts::RenderAhead: |
| 291 | if (!optarg) { |
| 292 | error = true; |
| 293 | } |
| 294 | gOpts.renderAhead = atoi(optarg); |
| 295 | if (gOpts.renderAhead < 0 || gOpts.renderAhead > 2) { |
| 296 | error = true; |
| 297 | } |
| 298 | break; |
| 299 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 300 | case 'h': |
| 301 | printHelp(); |
| 302 | exit(EXIT_SUCCESS); |
| 303 | break; |
| 304 | |
| 305 | case '?': |
| 306 | fprintf(stderr, "Unrecognized option '%s'\n", argv[optind - 1]); |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 307 | // fall-through |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 308 | default: |
| 309 | error = true; |
| 310 | break; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
| 314 | if (error) { |
| 315 | fprintf(stderr, "Try 'hwuitest --help' for more information.\n"); |
| 316 | exit(EXIT_FAILURE); |
| 317 | } |
| 318 | |
| 319 | /* Print any remaining command line arguments (not options). */ |
| 320 | if (optind < argc) { |
| 321 | do { |
| 322 | const char* test = argv[optind++]; |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 323 | auto pos = TestScene::testMap().find(test); |
| 324 | if (pos == TestScene::testMap().end()) { |
| 325 | fprintf(stderr, "Unknown test '%s'\n", test); |
| 326 | exit(EXIT_FAILURE); |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 327 | } else { |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 328 | gRunTests.push_back(pos->second); |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 329 | } |
| 330 | } while (optind < argc); |
| 331 | } else { |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 332 | for (auto& iter : TestScene::testMap()) { |
| 333 | gRunTests.push_back(iter.second); |
| 334 | } |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 338 | int main(int argc, char* argv[]) { |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 339 | // set defaults |
| 340 | gOpts.count = 150; |
| 341 | |
Seigo Nonaka | b6e2013 | 2016-11-14 14:07:41 +0900 | [diff] [blame] | 342 | Typeface::setRobotoTypefaceForTest(); |
| 343 | |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 344 | parseOptions(argc, argv); |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 345 | if (!gBenchmarkReporter && gOpts.renderOffscreen) { |
| 346 | gBenchmarkReporter.reset(new benchmark::ConsoleReporter()); |
| 347 | } |
| 348 | |
| 349 | if (gBenchmarkReporter) { |
| 350 | size_t name_field_width = 10; |
| 351 | for (auto&& test : gRunTests) { |
| 352 | name_field_width = std::max<size_t>(name_field_width, test.name.size()); |
| 353 | } |
| 354 | // _50th, _90th, etc... |
| 355 | name_field_width += 5; |
| 356 | |
| 357 | benchmark::BenchmarkReporter::Context context; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 358 | context.name_field_width = name_field_width; |
| 359 | gBenchmarkReporter->ReportContext(context); |
| 360 | } |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 361 | |
| 362 | for (int i = 0; i < gRepeatCount; i++) { |
| 363 | for (auto&& test : gRunTests) { |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 364 | run(test, gOpts, gBenchmarkReporter.get()); |
Tim Murray | 1a0f1c7 | 2015-05-06 11:37:37 -0700 | [diff] [blame] | 365 | } |
| 366 | } |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 367 | |
| 368 | if (gBenchmarkReporter) { |
| 369 | gBenchmarkReporter->Finalize(); |
| 370 | } |
| 371 | |
sergeyv | 7dc370b | 2016-06-17 11:21:11 -0700 | [diff] [blame] | 372 | LeakChecker::checkForLeaks(); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 373 | return 0; |
| 374 | } |