blob: 76d5ad3bd1f3ff79d483dc47391185da2de16d5f [file] [log] [blame]
reed@google.com006db0f2012-06-27 19:33:29 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "BenchTimer.h"
keyar@chromium.org163b5672012-08-01 17:53:29 +00009#include "PictureBenchmark.h"
scroggo@google.com9a412522012-09-07 15:21:18 +000010#include "SkBenchLogger.h"
reed@google.com006db0f2012-06-27 19:33:29 +000011#include "SkCanvas.h"
scroggo@google.com0a36f432012-09-10 20:29:13 +000012#include "SkGraphics.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000013#include "SkMath.h"
reed@google.com006db0f2012-06-27 19:33:29 +000014#include "SkOSFile.h"
15#include "SkPicture.h"
16#include "SkStream.h"
17#include "SkTArray.h"
18#include "picture_utils.h"
19
borenet@google.com13fd5a12012-09-17 21:10:05 +000020const int DEFAULT_REPEATS = 1;
reed@google.com006db0f2012-06-27 19:33:29 +000021
22static void usage(const char* argv0) {
23 SkDebugf("SkPicture benchmarking tool\n");
24 SkDebugf("\n"
25"Usage: \n"
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +000026" %s <inputDir>...\n"
scroggo@google.com5239c322012-09-11 19:15:32 +000027" [--logFile filename][--timers [wcgWC]*][--logPerIter 1|0][--min]\n"
keyar@chromium.org795cd472012-08-02 18:57:53 +000028" [--repeat] \n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000029" [--mode pow2tile minWidth height[] | record | simple\n"
30" | tile width[] height[] | playbackCreation]\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +000031" [--pipe]\n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000032" [--multi numThreads]\n"
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000033" [--device bitmap"
34#if SK_SUPPORT_GPU
35" | gpu"
36#endif
37"]"
reed@google.com006db0f2012-06-27 19:33:29 +000038, argv0);
39 SkDebugf("\n\n");
40 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000041" inputDir: A list of directories and files to use as input. Files are\n"
scroggo@google.com9a412522012-09-07 15:21:18 +000042" expected to have the .skp extension.\n\n"
43" --logFile filename : destination for writing log output, in addition to stdout.\n");
scroggo@google.com5239c322012-09-11 19:15:32 +000044 SkDebugf(" --logPerIter 1|0 : "
45 "Log each repeat timer instead of mean, default is disabled.\n");
46 SkDebugf(" --min : Print the minimum times (instead of average).\n");
47 SkDebugf(" --timers [wcgWC]* : "
48 "Display wall, cpu, gpu, truncated wall or truncated cpu time for each picture.\n");
reed@google.com006db0f2012-06-27 19:33:29 +000049 SkDebugf(
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000050" --mode pow2tile minWidht height[] | record | simple\n"
51" | tile width[] height[] | playbackCreation:\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +000052" Run in the corresponding mode.\n"
53" Default is simple.\n");
keyar@chromium.orgcf6c44c2012-07-09 19:37:40 +000054 SkDebugf(
scroggo@google.com58b4ead2012-08-31 16:15:22 +000055" pow2tile minWidth height[], Creates tiles with widths\n"
56" that are all a power of two\n"
57" such that they minimize the\n"
58" amount of wasted tile space.\n"
59" minWidth is the minimum width\n"
60" of these tiles and must be a\n"
61" power of two. Simple\n"
62" rendering using these tiles\n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000063" is benchmarked.\n");
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000064 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000065" record, Benchmark picture to picture recording.\n");
66 SkDebugf(
67" simple, Benchmark a simple rendering.\n");
68 SkDebugf(
scroggo@google.com58b4ead2012-08-31 16:15:22 +000069" tile width[] height[], Benchmark simple rendering using\n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000070" tiles with the given dimensions.\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +000071 SkDebugf(
scroggo@google.com9a412522012-09-07 15:21:18 +000072" playbackCreation, Benchmark creation of the SkPicturePlayback.\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +000073 SkDebugf("\n");
74 SkDebugf(
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000075" --multi numThreads : Set the number of threads for multi threaded drawing. Must be greater\n"
76" than 1. Only works with tiled rendering.\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +000077" --pipe: Benchmark SkGPipe rendering. Compatible with tiled, multithreaded rendering.\n");
78 SkDebugf(
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000079" --device bitmap"
80#if SK_SUPPORT_GPU
81" | gpu"
82#endif
83": Use the corresponding device. Default is bitmap.\n");
84 SkDebugf(
85" bitmap, Render to a bitmap.\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000086#if SK_SUPPORT_GPU
keyar@chromium.orga40c20d2012-08-20 15:04:12 +000087 SkDebugf(
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000088" gpu, Render to the GPU.\n");
89#endif
90 SkDebugf("\n");
91 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000092" --repeat: "
reed@google.com006db0f2012-06-27 19:33:29 +000093"Set the number of times to repeat each test."
94" Default is %i.\n", DEFAULT_REPEATS);
reed@google.com006db0f2012-06-27 19:33:29 +000095}
96
scroggo@google.com9a412522012-09-07 15:21:18 +000097SkBenchLogger gLogger;
98
borenet@google.com66bcbd12012-09-17 18:26:06 +000099static bool run_single_benchmark(const SkString& inputPath,
keyar@chromium.org163b5672012-08-01 17:53:29 +0000100 sk_tools::PictureBenchmark& benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000101 SkFILEStream inputStream;
102
reed@google.com006db0f2012-06-27 19:33:29 +0000103 inputStream.setPath(inputPath.c_str());
104 if (!inputStream.isValid()) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000105 SkString err;
106 err.printf("Could not open file %s\n", inputPath.c_str());
107 gLogger.logError(err);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000108 return false;
reed@google.com006db0f2012-06-27 19:33:29 +0000109 }
110
borenet@google.com66bcbd12012-09-17 18:26:06 +0000111 bool success = false;
borenet@google.com2d2b9a02012-09-20 18:54:04 +0000112 SkPicture picture(&inputStream, &success);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000113 if (!success) {
114 SkString err;
115 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
116 gLogger.logError(err);
117 return false;
118 }
reed@google.com006db0f2012-06-27 19:33:29 +0000119
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000120 SkString filename;
121 sk_tools::get_basename(&filename, inputPath);
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000122
123 SkString result;
borenet@google.com2d2b9a02012-09-20 18:54:04 +0000124 result.printf("running bench [%i %i] %s ", picture.width(),
125 picture.height(), filename.c_str());
scroggo@google.com9a412522012-09-07 15:21:18 +0000126 gLogger.logProgress(result);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000127
borenet@google.com2d2b9a02012-09-20 18:54:04 +0000128 benchmark.run(&picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000129 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000130}
131
keyar@chromium.org163b5672012-08-01 17:53:29 +0000132static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs,
scroggo@google.com5239c322012-09-11 19:15:32 +0000133 sk_tools::PictureBenchmark* benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000134 const char* argv0 = argv[0];
135 char* const* stop = argv + argc;
136
keyar@chromium.org163b5672012-08-01 17:53:29 +0000137 int repeats = DEFAULT_REPEATS;
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000138 sk_tools::PictureRenderer::SkDeviceTypes deviceType =
139 sk_tools::PictureRenderer::kBitmap_DeviceType;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000140
scroggo@google.com5239c322012-09-11 19:15:32 +0000141 sk_tools::PictureRenderer* renderer = NULL;
142
scroggo@google.com9a412522012-09-07 15:21:18 +0000143 // Create a string to show our current settings.
144 // TODO: Make it prettier. Currently it just repeats the command line.
145 SkString commandLine("bench_pictures:");
146 for (int i = 1; i < argc; i++) {
147 commandLine.appendf(" %s", *(argv+i));
148 }
149 commandLine.append("\n");
150
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000151 bool usePipe = false;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000152 int numThreads = 1;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000153 bool useTiles = false;
154 const char* widthString = NULL;
155 const char* heightString = NULL;
156 bool isPowerOf2Mode = false;
157 const char* mode = NULL;
reed@google.com006db0f2012-06-27 19:33:29 +0000158 for (++argv; argv < stop; ++argv) {
159 if (0 == strcmp(*argv, "--repeat")) {
160 ++argv;
161 if (argv < stop) {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000162 repeats = atoi(*argv);
163 if (repeats < 1) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000164 gLogger.logError("--repeat must be given a value > 0\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000165 exit(-1);
166 }
167 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000168 gLogger.logError("Missing arg for --repeat\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000169 usage(argv0);
170 exit(-1);
171 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000172 } else if (0 == strcmp(*argv, "--pipe")) {
173 usePipe = true;
scroggo@google.com9a412522012-09-07 15:21:18 +0000174 } else if (0 == strcmp(*argv, "--logFile")) {
175 argv++;
176 if (argv < stop) {
177 if (!gLogger.SetLogFile(*argv)) {
178 SkString str;
179 str.printf("Could not open %s for writing.", *argv);
180 gLogger.logError(str);
181 usage(argv0);
borenet@google.coma49bffd2012-09-13 18:54:48 +0000182 // TODO(borenet): We're disabling this for now, due to
183 // write-protected Android devices. The very short-term
184 // solution is to ignore the fact that we have no log file.
185 //exit(-1);
scroggo@google.com9a412522012-09-07 15:21:18 +0000186 }
187 } else {
188 gLogger.logError("Missing arg for --logFile\n");
189 usage(argv0);
190 exit(-1);
191 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000192 } else if (0 == strcmp(*argv, "--multi")) {
193 ++argv;
194 if (argv >= stop) {
195 gLogger.logError("Missing arg for --multi\n");
196 usage(argv0);
197 exit(-1);
198 }
199 numThreads = atoi(*argv);
200 if (numThreads < 2) {
201 gLogger.logError("Number of threads must be at least 2.\n");
202 usage(argv0);
203 exit(-1);
204 }
keyar@chromium.org795cd472012-08-02 18:57:53 +0000205 } else if (0 == strcmp(*argv, "--mode")) {
keyar@chromium.org795cd472012-08-02 18:57:53 +0000206
reed@google.com006db0f2012-06-27 19:33:29 +0000207 ++argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000208 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000209 gLogger.logError("Missing mode for --mode\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000210 usage(argv0);
211 exit(-1);
212 }
213
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000214 if (0 == strcmp(*argv, "record")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000215 renderer = SkNEW(sk_tools::RecordPictureRenderer);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000216 } else if (0 == strcmp(*argv, "simple")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000217 renderer = SkNEW(sk_tools::SimplePictureRenderer);
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000218 } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))) {
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000219 useTiles = true;
220 mode = *argv;
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000221
222 if (0 == strcmp(*argv, "pow2tile")) {
223 isPowerOf2Mode = true;
224 }
225
keyar@chromium.org795cd472012-08-02 18:57:53 +0000226 ++argv;
227 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000228 SkString err;
229 err.printf("Missing width for --mode %s\n", mode);
230 gLogger.logError(err);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000231 usage(argv0);
232 exit(-1);
233 }
234
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000235 widthString = *argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000236 ++argv;
237 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000238 gLogger.logError("Missing height for --mode tile\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000239 usage(argv0);
240 exit(-1);
241 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000242 heightString = *argv;
scroggo@google.com9a412522012-09-07 15:21:18 +0000243 } else if (0 == strcmp(*argv, "playbackCreation")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000244 renderer = SkNEW(sk_tools::PlaybackCreationRenderer);
reed@google.com006db0f2012-06-27 19:33:29 +0000245 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000246 SkString err;
247 err.printf("%s is not a valid mode for --mode\n", *argv);
248 gLogger.logError(err);
keyar@chromium.org0665f252012-07-10 18:30:18 +0000249 usage(argv0);
reed@google.com006db0f2012-06-27 19:33:29 +0000250 exit(-1);
251 }
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000252 } else if (0 == strcmp(*argv, "--device")) {
253 ++argv;
254 if (argv >= stop) {
borenet@google.coma49bffd2012-09-13 18:54:48 +0000255 gLogger.logError("Missing mode for --device\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000256 usage(argv0);
257 exit(-1);
258 }
259
260 if (0 == strcmp(*argv, "bitmap")) {
261 deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType;
262 }
263#if SK_SUPPORT_GPU
264 else if (0 == strcmp(*argv, "gpu")) {
265 deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
266 }
267#endif
268 else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000269 SkString err;
270 err.printf("%s is not a valid mode for --device\n", *argv);
271 gLogger.logError(err);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000272 usage(argv0);
273 exit(-1);
274 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000275 } else if (0 == strcmp(*argv, "--timers")) {
276 ++argv;
277 if (argv < stop) {
278 bool timerWall = false;
279 bool truncatedTimerWall = false;
280 bool timerCpu = false;
281 bool truncatedTimerCpu = false;
282 bool timerGpu = false;
283 for (char* t = *argv; *t; ++t) {
284 switch (*t) {
285 case 'w':
286 timerWall = true;
287 break;
288 case 'c':
289 timerCpu = true;
290 break;
291 case 'W':
292 truncatedTimerWall = true;
293 break;
294 case 'C':
295 truncatedTimerCpu = true;
296 break;
297 case 'g':
298 timerGpu = true;
299 break;
300 default: {
301 break;
302 }
303 }
304 }
305 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu,
306 truncatedTimerCpu, timerGpu);
307 } else {
308 gLogger.logError("Missing arg for --timers\n");
309 usage(argv0);
310 exit(-1);
311 }
312 } else if (0 == strcmp(*argv, "--min")) {
313 benchmark->setPrintMin(true);
314 } else if (0 == strcmp(*argv, "--logPerIter")) {
315 ++argv;
316 if (argv < stop) {
317 bool log = atoi(*argv) != 0;
318 benchmark->setLogPerIter(log);
319 } else {
320 gLogger.logError("Missing arg for --logPerIter\n");
321 usage(argv0);
322 exit(-1);
323 }
reed@google.com006db0f2012-06-27 19:33:29 +0000324 } else if (0 == strcmp(*argv, "--help") || 0 == strcmp(*argv, "-h")) {
325 usage(argv0);
326 exit(0);
327 } else {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000328 inputs->push_back(SkString(*argv));
reed@google.com006db0f2012-06-27 19:33:29 +0000329 }
330 }
331
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000332 if (numThreads > 1 && !useTiles) {
333 gLogger.logError("Multithreaded drawing requires tiled rendering.\n");
334 usage(argv0);
335 exit(-1);
336 }
337
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000338 if (useTiles) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000339 SkASSERT(NULL == renderer);
340 sk_tools::TiledPictureRenderer* tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000341 if (isPowerOf2Mode) {
342 int minWidth = atoi(widthString);
343 if (!SkIsPow2(minWidth) || minWidth < 0) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000344 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000345 SkString err;
scroggo@google.com5239c322012-09-11 19:15:32 +0000346 err.printf("-mode %s must be given a width"
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000347 " value that is a power of two\n", mode);
scroggo@google.com9a412522012-09-07 15:21:18 +0000348 gLogger.logError(err);
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000349 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000350 exit(-1);
351 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000352 tiledRenderer->setTileMinPowerOf2Width(minWidth);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000353 } else if (sk_tools::is_percentage(widthString)) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000354 tiledRenderer->setTileWidthPercentage(atof(widthString));
355 if (!(tiledRenderer->getTileWidthPercentage() > 0)) {
356 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000357 gLogger.logError("--mode tile must be given a width percentage > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000358 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000359 exit(-1);
360 }
361 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000362 tiledRenderer->setTileWidth(atoi(widthString));
363 if (!(tiledRenderer->getTileWidth() > 0)) {
364 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000365 gLogger.logError("--mode tile must be given a width > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000366 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000367 exit(-1);
368 }
369 }
370
371 if (sk_tools::is_percentage(heightString)) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000372 tiledRenderer->setTileHeightPercentage(atof(heightString));
373 if (!(tiledRenderer->getTileHeightPercentage() > 0)) {
374 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000375 gLogger.logError("--mode tile must be given a height percentage > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000376 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000377 exit(-1);
378 }
379 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000380 tiledRenderer->setTileHeight(atoi(heightString));
381 if (!(tiledRenderer->getTileHeight() > 0)) {
382 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000383 gLogger.logError("--mode tile must be given a height > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000384 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000385 exit(-1);
386 }
387 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000388 if (numThreads > 1) {
389#if SK_SUPPORT_GPU
390 if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) {
391 tiledRenderer->unref();
392 gLogger.logError("GPU not compatible with multithreaded tiling.\n");
393 usage(argv0);
394 exit(-1);
395 }
396#endif
397 tiledRenderer->setNumberOfThreads(numThreads);
398 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000399 tiledRenderer->setUsePipe(usePipe);
400 renderer = tiledRenderer;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000401 } else if (usePipe) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000402 renderer = SkNEW(sk_tools::PipePictureRenderer);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000403 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000404 if (inputs->count() < 1) {
fmalita@google.comc6157be2012-09-27 13:09:58 +0000405 SkSafeUnref(renderer);
reed@google.com006db0f2012-06-27 19:33:29 +0000406 usage(argv0);
407 exit(-1);
408 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000409
scroggo@google.com5239c322012-09-11 19:15:32 +0000410 if (NULL == renderer) {
411 renderer = SkNEW(sk_tools::SimplePictureRenderer);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000412 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000413 benchmark->setRenderer(renderer)->unref();
keyar@chromium.org163b5672012-08-01 17:53:29 +0000414 benchmark->setRepeats(repeats);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000415 benchmark->setDeviceType(deviceType);
scroggo@google.com9a412522012-09-07 15:21:18 +0000416 benchmark->setLogger(&gLogger);
417 // Report current settings:
418 gLogger.logProgress(commandLine);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000419}
reed@google.com006db0f2012-06-27 19:33:29 +0000420
borenet@google.com66bcbd12012-09-17 18:26:06 +0000421static int process_input(const SkString& input,
422 sk_tools::PictureBenchmark& benchmark) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000423 SkOSFile::Iter iter(input.c_str(), "skp");
424 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000425 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000426 if (iter.next(&inputFilename)) {
427 do {
428 SkString inputPath;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000429 sk_tools::make_filepath(&inputPath, input, inputFilename);
borenet@google.com57837bf2012-09-19 17:28:29 +0000430 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000431 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000432 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000433 } while(iter.next(&inputFilename));
borenet@google.com57837bf2012-09-19 17:28:29 +0000434 } else if (SkStrEndsWith(input.c_str(), ".skp")) {
435 if (!run_single_benchmark(input, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000436 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000437 }
438 } else {
439 SkString warning;
440 warning.printf("Warning: skipping %s\n", input.c_str());
441 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000442 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000443 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000444}
445
caryclark@google.com5987f582012-10-02 18:33:14 +0000446int tool_main(int argc, char** argv);
447int tool_main(int argc, char** argv) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000448#ifdef SK_ENABLE_INST_COUNT
449 gPrintInstCount = true;
450#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000451 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000452
scroggo@google.com5239c322012-09-11 19:15:32 +0000453 SkTArray<SkString> inputs;
454 sk_tools::PictureBenchmark benchmark;
455
456 parse_commandline(argc, argv, &inputs, &benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000457
borenet@google.com66bcbd12012-09-17 18:26:06 +0000458 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000459 for (int i = 0; i < inputs.count(); ++i) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000460 failures += process_input(inputs[i], benchmark);
461 }
462
463 if (failures != 0) {
464 SkString err;
465 err.printf("Failed to run %i benchmarks.\n", failures);
466 gLogger.logError(err);
467 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000468 }
reed@google.com006db0f2012-06-27 19:33:29 +0000469}
caryclark@google.com5987f582012-10-02 18:33:14 +0000470
471#if !defined SK_BUILD_FOR_IOS
472int main(int argc, char * const argv[]) {
473 return tool_main(argc, (char**) argv);
474}
475#endif