blob: 6cbb991e732e175d525affe93b1f752226f24ce1 [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;
112 SkPicture* picture = SkNEW_ARGS(SkPicture, (&inputStream, &success));
borenet@google.come21795e2012-09-14 14:34:28 +0000113 SkAutoTUnref<SkPicture> aur(picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000114 if (!success) {
115 SkString err;
116 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
117 gLogger.logError(err);
118 return false;
119 }
reed@google.com006db0f2012-06-27 19:33:29 +0000120
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000121 SkString filename;
122 sk_tools::get_basename(&filename, inputPath);
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000123
124 SkString result;
borenet@google.come21795e2012-09-14 14:34:28 +0000125 result.printf("running bench [%i %i] %s ", picture->width(),
126 picture->height(), filename.c_str());
scroggo@google.com9a412522012-09-07 15:21:18 +0000127 gLogger.logProgress(result);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000128
borenet@google.come21795e2012-09-14 14:34:28 +0000129 // rescale to avoid memory issues allocating a very large offscreen
130 sk_tools::resize_if_needed(&aur);
131
132 benchmark.run(aur);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000133 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000134}
135
keyar@chromium.org163b5672012-08-01 17:53:29 +0000136static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs,
scroggo@google.com5239c322012-09-11 19:15:32 +0000137 sk_tools::PictureBenchmark* benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000138 const char* argv0 = argv[0];
139 char* const* stop = argv + argc;
140
keyar@chromium.org163b5672012-08-01 17:53:29 +0000141 int repeats = DEFAULT_REPEATS;
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000142 sk_tools::PictureRenderer::SkDeviceTypes deviceType =
143 sk_tools::PictureRenderer::kBitmap_DeviceType;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000144
scroggo@google.com5239c322012-09-11 19:15:32 +0000145 sk_tools::PictureRenderer* renderer = NULL;
146
scroggo@google.com9a412522012-09-07 15:21:18 +0000147 // Create a string to show our current settings.
148 // TODO: Make it prettier. Currently it just repeats the command line.
149 SkString commandLine("bench_pictures:");
150 for (int i = 1; i < argc; i++) {
151 commandLine.appendf(" %s", *(argv+i));
152 }
153 commandLine.append("\n");
154
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000155 bool usePipe = false;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000156 int numThreads = 1;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000157 bool useTiles = false;
158 const char* widthString = NULL;
159 const char* heightString = NULL;
160 bool isPowerOf2Mode = false;
161 const char* mode = NULL;
reed@google.com006db0f2012-06-27 19:33:29 +0000162 for (++argv; argv < stop; ++argv) {
163 if (0 == strcmp(*argv, "--repeat")) {
164 ++argv;
165 if (argv < stop) {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000166 repeats = atoi(*argv);
167 if (repeats < 1) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000168 gLogger.logError("--repeat must be given a value > 0\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000169 exit(-1);
170 }
171 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000172 gLogger.logError("Missing arg for --repeat\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000173 usage(argv0);
174 exit(-1);
175 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000176 } else if (0 == strcmp(*argv, "--pipe")) {
177 usePipe = true;
scroggo@google.com9a412522012-09-07 15:21:18 +0000178 } else if (0 == strcmp(*argv, "--logFile")) {
179 argv++;
180 if (argv < stop) {
181 if (!gLogger.SetLogFile(*argv)) {
182 SkString str;
183 str.printf("Could not open %s for writing.", *argv);
184 gLogger.logError(str);
185 usage(argv0);
borenet@google.coma49bffd2012-09-13 18:54:48 +0000186 // TODO(borenet): We're disabling this for now, due to
187 // write-protected Android devices. The very short-term
188 // solution is to ignore the fact that we have no log file.
189 //exit(-1);
scroggo@google.com9a412522012-09-07 15:21:18 +0000190 }
191 } else {
192 gLogger.logError("Missing arg for --logFile\n");
193 usage(argv0);
194 exit(-1);
195 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000196 } else if (0 == strcmp(*argv, "--multi")) {
197 ++argv;
198 if (argv >= stop) {
199 gLogger.logError("Missing arg for --multi\n");
200 usage(argv0);
201 exit(-1);
202 }
203 numThreads = atoi(*argv);
204 if (numThreads < 2) {
205 gLogger.logError("Number of threads must be at least 2.\n");
206 usage(argv0);
207 exit(-1);
208 }
keyar@chromium.org795cd472012-08-02 18:57:53 +0000209 } else if (0 == strcmp(*argv, "--mode")) {
keyar@chromium.org795cd472012-08-02 18:57:53 +0000210
reed@google.com006db0f2012-06-27 19:33:29 +0000211 ++argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000212 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000213 gLogger.logError("Missing mode for --mode\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000214 usage(argv0);
215 exit(-1);
216 }
217
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000218 if (0 == strcmp(*argv, "record")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000219 renderer = SkNEW(sk_tools::RecordPictureRenderer);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000220 } else if (0 == strcmp(*argv, "simple")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000221 renderer = SkNEW(sk_tools::SimplePictureRenderer);
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000222 } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))) {
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000223 useTiles = true;
224 mode = *argv;
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000225
226 if (0 == strcmp(*argv, "pow2tile")) {
227 isPowerOf2Mode = true;
228 }
229
keyar@chromium.org795cd472012-08-02 18:57:53 +0000230 ++argv;
231 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000232 SkString err;
233 err.printf("Missing width for --mode %s\n", mode);
234 gLogger.logError(err);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000235 usage(argv0);
236 exit(-1);
237 }
238
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000239 widthString = *argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000240 ++argv;
241 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000242 gLogger.logError("Missing height for --mode tile\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000243 usage(argv0);
244 exit(-1);
245 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000246 heightString = *argv;
scroggo@google.com9a412522012-09-07 15:21:18 +0000247 } else if (0 == strcmp(*argv, "playbackCreation")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000248 renderer = SkNEW(sk_tools::PlaybackCreationRenderer);
reed@google.com006db0f2012-06-27 19:33:29 +0000249 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000250 SkString err;
251 err.printf("%s is not a valid mode for --mode\n", *argv);
252 gLogger.logError(err);
keyar@chromium.org0665f252012-07-10 18:30:18 +0000253 usage(argv0);
reed@google.com006db0f2012-06-27 19:33:29 +0000254 exit(-1);
255 }
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000256 } else if (0 == strcmp(*argv, "--device")) {
257 ++argv;
258 if (argv >= stop) {
borenet@google.coma49bffd2012-09-13 18:54:48 +0000259 gLogger.logError("Missing mode for --device\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000260 usage(argv0);
261 exit(-1);
262 }
263
264 if (0 == strcmp(*argv, "bitmap")) {
265 deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType;
266 }
267#if SK_SUPPORT_GPU
268 else if (0 == strcmp(*argv, "gpu")) {
269 deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
270 }
271#endif
272 else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000273 SkString err;
274 err.printf("%s is not a valid mode for --device\n", *argv);
275 gLogger.logError(err);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000276 usage(argv0);
277 exit(-1);
278 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000279 } else if (0 == strcmp(*argv, "--timers")) {
280 ++argv;
281 if (argv < stop) {
282 bool timerWall = false;
283 bool truncatedTimerWall = false;
284 bool timerCpu = false;
285 bool truncatedTimerCpu = false;
286 bool timerGpu = false;
287 for (char* t = *argv; *t; ++t) {
288 switch (*t) {
289 case 'w':
290 timerWall = true;
291 break;
292 case 'c':
293 timerCpu = true;
294 break;
295 case 'W':
296 truncatedTimerWall = true;
297 break;
298 case 'C':
299 truncatedTimerCpu = true;
300 break;
301 case 'g':
302 timerGpu = true;
303 break;
304 default: {
305 break;
306 }
307 }
308 }
309 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu,
310 truncatedTimerCpu, timerGpu);
311 } else {
312 gLogger.logError("Missing arg for --timers\n");
313 usage(argv0);
314 exit(-1);
315 }
316 } else if (0 == strcmp(*argv, "--min")) {
317 benchmark->setPrintMin(true);
318 } else if (0 == strcmp(*argv, "--logPerIter")) {
319 ++argv;
320 if (argv < stop) {
321 bool log = atoi(*argv) != 0;
322 benchmark->setLogPerIter(log);
323 } else {
324 gLogger.logError("Missing arg for --logPerIter\n");
325 usage(argv0);
326 exit(-1);
327 }
reed@google.com006db0f2012-06-27 19:33:29 +0000328 } else if (0 == strcmp(*argv, "--help") || 0 == strcmp(*argv, "-h")) {
329 usage(argv0);
330 exit(0);
331 } else {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000332 inputs->push_back(SkString(*argv));
reed@google.com006db0f2012-06-27 19:33:29 +0000333 }
334 }
335
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000336 if (numThreads > 1 && !useTiles) {
337 gLogger.logError("Multithreaded drawing requires tiled rendering.\n");
338 usage(argv0);
339 exit(-1);
340 }
341
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000342 if (useTiles) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000343 SkASSERT(NULL == renderer);
344 sk_tools::TiledPictureRenderer* tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000345 if (isPowerOf2Mode) {
346 int minWidth = atoi(widthString);
347 if (!SkIsPow2(minWidth) || minWidth < 0) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000348 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000349 SkString err;
scroggo@google.com5239c322012-09-11 19:15:32 +0000350 err.printf("-mode %s must be given a width"
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000351 " value that is a power of two\n", mode);
scroggo@google.com9a412522012-09-07 15:21:18 +0000352 gLogger.logError(err);
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000353 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000354 exit(-1);
355 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000356 tiledRenderer->setTileMinPowerOf2Width(minWidth);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000357 } else if (sk_tools::is_percentage(widthString)) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000358 tiledRenderer->setTileWidthPercentage(atof(widthString));
359 if (!(tiledRenderer->getTileWidthPercentage() > 0)) {
360 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000361 gLogger.logError("--mode tile must be given a width percentage > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000362 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000363 exit(-1);
364 }
365 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000366 tiledRenderer->setTileWidth(atoi(widthString));
367 if (!(tiledRenderer->getTileWidth() > 0)) {
368 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000369 gLogger.logError("--mode tile must be given a width > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000370 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000371 exit(-1);
372 }
373 }
374
375 if (sk_tools::is_percentage(heightString)) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000376 tiledRenderer->setTileHeightPercentage(atof(heightString));
377 if (!(tiledRenderer->getTileHeightPercentage() > 0)) {
378 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000379 gLogger.logError("--mode tile must be given a height percentage > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000380 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000381 exit(-1);
382 }
383 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000384 tiledRenderer->setTileHeight(atoi(heightString));
385 if (!(tiledRenderer->getTileHeight() > 0)) {
386 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000387 gLogger.logError("--mode tile must be given a height > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000388 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000389 exit(-1);
390 }
391 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000392 if (numThreads > 1) {
393#if SK_SUPPORT_GPU
394 if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) {
395 tiledRenderer->unref();
396 gLogger.logError("GPU not compatible with multithreaded tiling.\n");
397 usage(argv0);
398 exit(-1);
399 }
400#endif
401 tiledRenderer->setNumberOfThreads(numThreads);
402 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000403 tiledRenderer->setUsePipe(usePipe);
404 renderer = tiledRenderer;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000405 } else if (usePipe) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000406 renderer = SkNEW(sk_tools::PipePictureRenderer);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000407 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000408 if (inputs->count() < 1) {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000409 SkDELETE(benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000410 usage(argv0);
411 exit(-1);
412 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000413
scroggo@google.com5239c322012-09-11 19:15:32 +0000414 if (NULL == renderer) {
415 renderer = SkNEW(sk_tools::SimplePictureRenderer);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000416 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000417 benchmark->setRenderer(renderer)->unref();
keyar@chromium.org163b5672012-08-01 17:53:29 +0000418 benchmark->setRepeats(repeats);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000419 benchmark->setDeviceType(deviceType);
scroggo@google.com9a412522012-09-07 15:21:18 +0000420 benchmark->setLogger(&gLogger);
421 // Report current settings:
422 gLogger.logProgress(commandLine);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000423}
reed@google.com006db0f2012-06-27 19:33:29 +0000424
borenet@google.com66bcbd12012-09-17 18:26:06 +0000425static int process_input(const SkString& input,
426 sk_tools::PictureBenchmark& benchmark) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000427 SkOSFile::Iter iter(input.c_str(), "skp");
428 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000429 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000430 if (iter.next(&inputFilename)) {
431 do {
432 SkString inputPath;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000433 sk_tools::make_filepath(&inputPath, input, inputFilename);
borenet@google.com57837bf2012-09-19 17:28:29 +0000434 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000435 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000436 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000437 } while(iter.next(&inputFilename));
borenet@google.com57837bf2012-09-19 17:28:29 +0000438 } else if (SkStrEndsWith(input.c_str(), ".skp")) {
439 if (!run_single_benchmark(input, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000440 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000441 }
442 } else {
443 SkString warning;
444 warning.printf("Warning: skipping %s\n", input.c_str());
445 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000446 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000447 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000448}
449
450int main(int argc, char* const argv[]) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000451#ifdef SK_ENABLE_INST_COUNT
452 gPrintInstCount = true;
453#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000454 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000455
scroggo@google.com5239c322012-09-11 19:15:32 +0000456 SkTArray<SkString> inputs;
457 sk_tools::PictureBenchmark benchmark;
458
459 parse_commandline(argc, argv, &inputs, &benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000460
borenet@google.com66bcbd12012-09-17 18:26:06 +0000461 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000462 for (int i = 0; i < inputs.count(); ++i) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000463 failures += process_input(inputs[i], benchmark);
464 }
465
466 if (failures != 0) {
467 SkString err;
468 err.printf("Failed to run %i benchmarks.\n", failures);
469 gLogger.logError(err);
470 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000471 }
reed@google.com006db0f2012-06-27 19:33:29 +0000472}