blob: d6837e9079cb2f3bcb1d6987296a3d1e5a1d91f4 [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
20const int DEFAULT_REPEATS = 100;
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.com58b4ead2012-08-31 16:15:22 +000029" [--mode pow2tile minWidth height[] (multi) | record | simple\n"
scroggo@google.com9a412522012-09-07 15:21:18 +000030" | tile width[] height[] (multi) | playbackCreation]\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +000031" [--pipe]\n"
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000032" [--device bitmap"
33#if SK_SUPPORT_GPU
34" | gpu"
35#endif
36"]"
reed@google.com006db0f2012-06-27 19:33:29 +000037, argv0);
38 SkDebugf("\n\n");
39 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000040" inputDir: A list of directories and files to use as input. Files are\n"
scroggo@google.com9a412522012-09-07 15:21:18 +000041" expected to have the .skp extension.\n\n"
42" --logFile filename : destination for writing log output, in addition to stdout.\n");
scroggo@google.com5239c322012-09-11 19:15:32 +000043 SkDebugf(" --logPerIter 1|0 : "
44 "Log each repeat timer instead of mean, default is disabled.\n");
45 SkDebugf(" --min : Print the minimum times (instead of average).\n");
46 SkDebugf(" --timers [wcgWC]* : "
47 "Display wall, cpu, gpu, truncated wall or truncated cpu time for each picture.\n");
reed@google.com006db0f2012-06-27 19:33:29 +000048 SkDebugf(
scroggo@google.com58b4ead2012-08-31 16:15:22 +000049" --mode pow2tile minWidht height[] (multi) | record | simple\n"
scroggo@google.com9a412522012-09-07 15:21:18 +000050" | tile width[] height[] (multi) | playbackCreation:\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +000051" Run in the corresponding mode.\n"
52" Default is simple.\n");
keyar@chromium.orgcf6c44c2012-07-09 19:37:40 +000053 SkDebugf(
scroggo@google.com58b4ead2012-08-31 16:15:22 +000054" pow2tile minWidth height[], Creates tiles with widths\n"
55" that are all a power of two\n"
56" such that they minimize the\n"
57" amount of wasted tile space.\n"
58" minWidth is the minimum width\n"
59" of these tiles and must be a\n"
60" power of two. Simple\n"
61" rendering using these tiles\n"
62" is benchmarked.\n"
63" Append \"multi\" for multithreaded\n"
64" drawing.\n");
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000065 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000066" record, Benchmark picture to picture recording.\n");
67 SkDebugf(
68" simple, Benchmark a simple rendering.\n");
69 SkDebugf(
scroggo@google.com58b4ead2012-08-31 16:15:22 +000070" tile width[] height[], Benchmark simple rendering using\n"
71" tiles with the given dimensions.\n"
72" Append \"multi\" for multithreaded\n"
73" drawing.\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +000074 SkDebugf(
scroggo@google.com9a412522012-09-07 15:21:18 +000075" playbackCreation, Benchmark creation of the SkPicturePlayback.\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +000076 SkDebugf("\n");
77 SkDebugf(
scroggo@google.com58b4ead2012-08-31 16:15:22 +000078" --pipe: Benchmark SkGPipe rendering. Compatible with tiled, multithreaded rendering.\n");
79 SkDebugf(
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000080" --device bitmap"
81#if SK_SUPPORT_GPU
82" | gpu"
83#endif
84": Use the corresponding device. Default is bitmap.\n");
85 SkDebugf(
86" bitmap, Render to a bitmap.\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000087#if SK_SUPPORT_GPU
keyar@chromium.orga40c20d2012-08-20 15:04:12 +000088 SkDebugf(
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000089" gpu, Render to the GPU.\n");
90#endif
91 SkDebugf("\n");
92 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000093" --repeat: "
reed@google.com006db0f2012-06-27 19:33:29 +000094"Set the number of times to repeat each test."
95" Default is %i.\n", DEFAULT_REPEATS);
reed@google.com006db0f2012-06-27 19:33:29 +000096}
97
scroggo@google.com9a412522012-09-07 15:21:18 +000098SkBenchLogger gLogger;
99
borenet@google.com66bcbd12012-09-17 18:26:06 +0000100static bool run_single_benchmark(const SkString& inputPath,
keyar@chromium.org163b5672012-08-01 17:53:29 +0000101 sk_tools::PictureBenchmark& benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000102 SkFILEStream inputStream;
103
reed@google.com006db0f2012-06-27 19:33:29 +0000104 inputStream.setPath(inputPath.c_str());
105 if (!inputStream.isValid()) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000106 SkString err;
107 err.printf("Could not open file %s\n", inputPath.c_str());
108 gLogger.logError(err);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000109 return false;
reed@google.com006db0f2012-06-27 19:33:29 +0000110 }
111
borenet@google.com66bcbd12012-09-17 18:26:06 +0000112 bool success = false;
113 SkPicture* picture = SkNEW_ARGS(SkPicture, (&inputStream, &success));
borenet@google.come21795e2012-09-14 14:34:28 +0000114 SkAutoTUnref<SkPicture> aur(picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000115 if (!success) {
116 SkString err;
117 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
118 gLogger.logError(err);
119 return false;
120 }
reed@google.com006db0f2012-06-27 19:33:29 +0000121
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000122 SkString filename;
123 sk_tools::get_basename(&filename, inputPath);
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000124
125 SkString result;
borenet@google.come21795e2012-09-14 14:34:28 +0000126 result.printf("running bench [%i %i] %s ", picture->width(),
127 picture->height(), filename.c_str());
scroggo@google.com9a412522012-09-07 15:21:18 +0000128 gLogger.logProgress(result);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000129
borenet@google.come21795e2012-09-14 14:34:28 +0000130 // rescale to avoid memory issues allocating a very large offscreen
131 sk_tools::resize_if_needed(&aur);
132
133 benchmark.run(aur);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000134 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000135}
136
keyar@chromium.org163b5672012-08-01 17:53:29 +0000137static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs,
scroggo@google.com5239c322012-09-11 19:15:32 +0000138 sk_tools::PictureBenchmark* benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000139 const char* argv0 = argv[0];
140 char* const* stop = argv + argc;
141
keyar@chromium.org163b5672012-08-01 17:53:29 +0000142 int repeats = DEFAULT_REPEATS;
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000143 sk_tools::PictureRenderer::SkDeviceTypes deviceType =
144 sk_tools::PictureRenderer::kBitmap_DeviceType;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000145
scroggo@google.com5239c322012-09-11 19:15:32 +0000146 sk_tools::PictureRenderer* renderer = NULL;
147
scroggo@google.com9a412522012-09-07 15:21:18 +0000148 // Create a string to show our current settings.
149 // TODO: Make it prettier. Currently it just repeats the command line.
150 SkString commandLine("bench_pictures:");
151 for (int i = 1; i < argc; i++) {
152 commandLine.appendf(" %s", *(argv+i));
153 }
154 commandLine.append("\n");
155
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000156 bool usePipe = false;
157 bool multiThreaded = false;
158 bool useTiles = false;
159 const char* widthString = NULL;
160 const char* heightString = NULL;
161 bool isPowerOf2Mode = false;
162 const char* mode = NULL;
reed@google.com006db0f2012-06-27 19:33:29 +0000163 for (++argv; argv < stop; ++argv) {
164 if (0 == strcmp(*argv, "--repeat")) {
165 ++argv;
166 if (argv < stop) {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000167 repeats = atoi(*argv);
168 if (repeats < 1) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000169 gLogger.logError("--repeat must be given a value > 0\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000170 exit(-1);
171 }
172 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000173 gLogger.logError("Missing arg for --repeat\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000174 usage(argv0);
175 exit(-1);
176 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000177 } else if (0 == strcmp(*argv, "--pipe")) {
178 usePipe = true;
scroggo@google.com9a412522012-09-07 15:21:18 +0000179 } else if (0 == strcmp(*argv, "--logFile")) {
180 argv++;
181 if (argv < stop) {
182 if (!gLogger.SetLogFile(*argv)) {
183 SkString str;
184 str.printf("Could not open %s for writing.", *argv);
185 gLogger.logError(str);
186 usage(argv0);
borenet@google.coma49bffd2012-09-13 18:54:48 +0000187 // TODO(borenet): We're disabling this for now, due to
188 // write-protected Android devices. The very short-term
189 // solution is to ignore the fact that we have no log file.
190 //exit(-1);
scroggo@google.com9a412522012-09-07 15:21:18 +0000191 }
192 } else {
193 gLogger.logError("Missing arg for --logFile\n");
194 usage(argv0);
195 exit(-1);
196 }
keyar@chromium.org795cd472012-08-02 18:57:53 +0000197 } else if (0 == strcmp(*argv, "--mode")) {
keyar@chromium.org795cd472012-08-02 18:57:53 +0000198
reed@google.com006db0f2012-06-27 19:33:29 +0000199 ++argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000200 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000201 gLogger.logError("Missing mode for --mode\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000202 usage(argv0);
203 exit(-1);
204 }
205
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000206 if (0 == strcmp(*argv, "record")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000207 renderer = SkNEW(sk_tools::RecordPictureRenderer);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000208 } else if (0 == strcmp(*argv, "simple")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000209 renderer = SkNEW(sk_tools::SimplePictureRenderer);
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000210 } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))) {
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000211 useTiles = true;
212 mode = *argv;
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000213
214 if (0 == strcmp(*argv, "pow2tile")) {
215 isPowerOf2Mode = true;
216 }
217
keyar@chromium.org795cd472012-08-02 18:57:53 +0000218 ++argv;
219 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000220 SkString err;
221 err.printf("Missing width for --mode %s\n", mode);
222 gLogger.logError(err);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000223 usage(argv0);
224 exit(-1);
225 }
226
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000227 widthString = *argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000228 ++argv;
229 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000230 gLogger.logError("Missing height for --mode tile\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000231 usage(argv0);
232 exit(-1);
233 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000234 heightString = *argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000235
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000236 ++argv;
237 if (argv < stop && 0 == strcmp(*argv, "multi")) {
238 multiThreaded = true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000239 } else {
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000240 --argv;
reed@google.com006db0f2012-06-27 19:33:29 +0000241 }
scroggo@google.com9a412522012-09-07 15:21:18 +0000242 } else if (0 == strcmp(*argv, "playbackCreation")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000243 renderer = SkNEW(sk_tools::PlaybackCreationRenderer);
reed@google.com006db0f2012-06-27 19:33:29 +0000244 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000245 SkString err;
246 err.printf("%s is not a valid mode for --mode\n", *argv);
247 gLogger.logError(err);
keyar@chromium.org0665f252012-07-10 18:30:18 +0000248 usage(argv0);
reed@google.com006db0f2012-06-27 19:33:29 +0000249 exit(-1);
250 }
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000251 } else if (0 == strcmp(*argv, "--device")) {
252 ++argv;
253 if (argv >= stop) {
borenet@google.coma49bffd2012-09-13 18:54:48 +0000254 gLogger.logError("Missing mode for --device\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000255 usage(argv0);
256 exit(-1);
257 }
258
259 if (0 == strcmp(*argv, "bitmap")) {
260 deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType;
261 }
262#if SK_SUPPORT_GPU
263 else if (0 == strcmp(*argv, "gpu")) {
264 deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
265 }
266#endif
267 else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000268 SkString err;
269 err.printf("%s is not a valid mode for --device\n", *argv);
270 gLogger.logError(err);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000271 usage(argv0);
272 exit(-1);
273 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000274 } else if (0 == strcmp(*argv, "--timers")) {
275 ++argv;
276 if (argv < stop) {
277 bool timerWall = false;
278 bool truncatedTimerWall = false;
279 bool timerCpu = false;
280 bool truncatedTimerCpu = false;
281 bool timerGpu = false;
282 for (char* t = *argv; *t; ++t) {
283 switch (*t) {
284 case 'w':
285 timerWall = true;
286 break;
287 case 'c':
288 timerCpu = true;
289 break;
290 case 'W':
291 truncatedTimerWall = true;
292 break;
293 case 'C':
294 truncatedTimerCpu = true;
295 break;
296 case 'g':
297 timerGpu = true;
298 break;
299 default: {
300 break;
301 }
302 }
303 }
304 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu,
305 truncatedTimerCpu, timerGpu);
306 } else {
307 gLogger.logError("Missing arg for --timers\n");
308 usage(argv0);
309 exit(-1);
310 }
311 } else if (0 == strcmp(*argv, "--min")) {
312 benchmark->setPrintMin(true);
313 } else if (0 == strcmp(*argv, "--logPerIter")) {
314 ++argv;
315 if (argv < stop) {
316 bool log = atoi(*argv) != 0;
317 benchmark->setLogPerIter(log);
318 } else {
319 gLogger.logError("Missing arg for --logPerIter\n");
320 usage(argv0);
321 exit(-1);
322 }
reed@google.com006db0f2012-06-27 19:33:29 +0000323 } else if (0 == strcmp(*argv, "--help") || 0 == strcmp(*argv, "-h")) {
324 usage(argv0);
325 exit(0);
326 } else {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000327 inputs->push_back(SkString(*argv));
reed@google.com006db0f2012-06-27 19:33:29 +0000328 }
329 }
330
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000331 if (useTiles) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000332 SkASSERT(NULL == renderer);
333 sk_tools::TiledPictureRenderer* tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000334 if (isPowerOf2Mode) {
335 int minWidth = atoi(widthString);
336 if (!SkIsPow2(minWidth) || minWidth < 0) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000337 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000338 SkString err;
scroggo@google.com5239c322012-09-11 19:15:32 +0000339 err.printf("-mode %s must be given a width"
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000340 " value that is a power of two\n", mode);
scroggo@google.com9a412522012-09-07 15:21:18 +0000341 gLogger.logError(err);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000342 exit(-1);
343 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000344 tiledRenderer->setTileMinPowerOf2Width(minWidth);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000345 } else if (sk_tools::is_percentage(widthString)) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000346 tiledRenderer->setTileWidthPercentage(atof(widthString));
347 if (!(tiledRenderer->getTileWidthPercentage() > 0)) {
348 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000349 gLogger.logError("--mode tile must be given a width percentage > 0\n");
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000350 exit(-1);
351 }
352 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000353 tiledRenderer->setTileWidth(atoi(widthString));
354 if (!(tiledRenderer->getTileWidth() > 0)) {
355 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000356 gLogger.logError("--mode tile must be given a width > 0\n");
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000357 exit(-1);
358 }
359 }
360
361 if (sk_tools::is_percentage(heightString)) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000362 tiledRenderer->setTileHeightPercentage(atof(heightString));
363 if (!(tiledRenderer->getTileHeightPercentage() > 0)) {
364 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000365 gLogger.logError("--mode tile must be given a height percentage > 0\n");
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000366 exit(-1);
367 }
368 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000369 tiledRenderer->setTileHeight(atoi(heightString));
370 if (!(tiledRenderer->getTileHeight() > 0)) {
371 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000372 gLogger.logError("--mode tile must be given a height > 0\n");
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000373 exit(-1);
374 }
375 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000376 tiledRenderer->setMultiThreaded(multiThreaded);
377 tiledRenderer->setUsePipe(usePipe);
378 renderer = tiledRenderer;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000379 } else if (usePipe) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000380 renderer = SkNEW(sk_tools::PipePictureRenderer);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000381 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000382 if (inputs->count() < 1) {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000383 SkDELETE(benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000384 usage(argv0);
385 exit(-1);
386 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000387
scroggo@google.com5239c322012-09-11 19:15:32 +0000388 if (NULL == renderer) {
389 renderer = SkNEW(sk_tools::SimplePictureRenderer);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000390 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000391 benchmark->setRenderer(renderer)->unref();
keyar@chromium.org163b5672012-08-01 17:53:29 +0000392 benchmark->setRepeats(repeats);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000393 benchmark->setDeviceType(deviceType);
scroggo@google.com9a412522012-09-07 15:21:18 +0000394 benchmark->setLogger(&gLogger);
395 // Report current settings:
396 gLogger.logProgress(commandLine);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000397}
reed@google.com006db0f2012-06-27 19:33:29 +0000398
borenet@google.com66bcbd12012-09-17 18:26:06 +0000399static int process_input(const SkString& input,
400 sk_tools::PictureBenchmark& benchmark) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000401 SkOSFile::Iter iter(input.c_str(), "skp");
402 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000403 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000404 if (iter.next(&inputFilename)) {
405 do {
406 SkString inputPath;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000407 sk_tools::make_filepath(&inputPath, input, inputFilename);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000408 if (!run_single_benchmark(inputPath, benchmark))
409 ++failures;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000410 } while(iter.next(&inputFilename));
411 } else {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000412 if (!run_single_benchmark(input, benchmark))
413 ++failures;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000414 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000415 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000416}
417
418int main(int argc, char* const argv[]) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000419#ifdef SK_ENABLE_INST_COUNT
420 gPrintInstCount = true;
421#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000422 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000423
scroggo@google.com5239c322012-09-11 19:15:32 +0000424 SkTArray<SkString> inputs;
425 sk_tools::PictureBenchmark benchmark;
426
427 parse_commandline(argc, argv, &inputs, &benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000428
borenet@google.com66bcbd12012-09-17 18:26:06 +0000429 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000430 for (int i = 0; i < inputs.count(); ++i) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000431 failures += process_input(inputs[i], benchmark);
432 }
433
434 if (failures != 0) {
435 SkString err;
436 err.printf("Failed to run %i benchmarks.\n", failures);
437 gLogger.logError(err);
438 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000439 }
reed@google.com006db0f2012-06-27 19:33:29 +0000440}