blob: e602bd923d92e378476fba90206a10ee0649cf2d [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"
scroggo@google.com5a7c6be2012-10-04 21:46:08 +000013#include "SkImageDecoder.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000014#include "SkMath.h"
reed@google.com006db0f2012-06-27 19:33:29 +000015#include "SkOSFile.h"
16#include "SkPicture.h"
17#include "SkStream.h"
18#include "SkTArray.h"
19#include "picture_utils.h"
20
borenet@google.com13fd5a12012-09-17 21:10:05 +000021const int DEFAULT_REPEATS = 1;
reed@google.com006db0f2012-06-27 19:33:29 +000022
23static void usage(const char* argv0) {
24 SkDebugf("SkPicture benchmarking tool\n");
25 SkDebugf("\n"
26"Usage: \n"
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +000027" %s <inputDir>...\n"
scroggo@google.com5239c322012-09-11 19:15:32 +000028" [--logFile filename][--timers [wcgWC]*][--logPerIter 1|0][--min]\n"
keyar@chromium.org795cd472012-08-02 18:57:53 +000029" [--repeat] \n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000030" [--mode pow2tile minWidth height[] | record | simple\n"
31" | tile width[] height[] | playbackCreation]\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +000032" [--pipe]\n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000033" [--multi numThreads]\n"
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000034" [--device bitmap"
35#if SK_SUPPORT_GPU
36" | gpu"
37#endif
38"]"
reed@google.com006db0f2012-06-27 19:33:29 +000039, argv0);
40 SkDebugf("\n\n");
41 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000042" inputDir: A list of directories and files to use as input. Files are\n"
scroggo@google.com9a412522012-09-07 15:21:18 +000043" expected to have the .skp extension.\n\n"
44" --logFile filename : destination for writing log output, in addition to stdout.\n");
scroggo@google.com5239c322012-09-11 19:15:32 +000045 SkDebugf(" --logPerIter 1|0 : "
46 "Log each repeat timer instead of mean, default is disabled.\n");
47 SkDebugf(" --min : Print the minimum times (instead of average).\n");
48 SkDebugf(" --timers [wcgWC]* : "
49 "Display wall, cpu, gpu, truncated wall or truncated cpu time for each picture.\n");
reed@google.com006db0f2012-06-27 19:33:29 +000050 SkDebugf(
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000051" --mode pow2tile minWidht height[] | record | simple\n"
52" | tile width[] height[] | playbackCreation:\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +000053" Run in the corresponding mode.\n"
54" Default is simple.\n");
keyar@chromium.orgcf6c44c2012-07-09 19:37:40 +000055 SkDebugf(
scroggo@google.com58b4ead2012-08-31 16:15:22 +000056" pow2tile minWidth height[], Creates tiles with widths\n"
57" that are all a power of two\n"
58" such that they minimize the\n"
59" amount of wasted tile space.\n"
60" minWidth is the minimum width\n"
61" of these tiles and must be a\n"
62" power of two. Simple\n"
63" rendering using these tiles\n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000064" is benchmarked.\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"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000071" tiles with the given dimensions.\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +000072 SkDebugf(
scroggo@google.com9a412522012-09-07 15:21:18 +000073" playbackCreation, Benchmark creation of the SkPicturePlayback.\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +000074 SkDebugf("\n");
75 SkDebugf(
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000076" --multi numThreads : Set the number of threads for multi threaded drawing. Must be greater\n"
77" than 1. Only works with tiled rendering.\n"
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;
scroggo@google.com5a7c6be2012-10-04 21:46:08 +0000113 SkPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream);
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.com2d2b9a02012-09-20 18:54:04 +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.com2d2b9a02012-09-20 18:54:04 +0000129 benchmark.run(&picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000130 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000131}
132
keyar@chromium.org163b5672012-08-01 17:53:29 +0000133static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs,
scroggo@google.com5239c322012-09-11 19:15:32 +0000134 sk_tools::PictureBenchmark* benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000135 const char* argv0 = argv[0];
136 char* const* stop = argv + argc;
137
keyar@chromium.org163b5672012-08-01 17:53:29 +0000138 int repeats = DEFAULT_REPEATS;
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000139 sk_tools::PictureRenderer::SkDeviceTypes deviceType =
140 sk_tools::PictureRenderer::kBitmap_DeviceType;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000141
scroggo@google.com5239c322012-09-11 19:15:32 +0000142 sk_tools::PictureRenderer* renderer = NULL;
143
scroggo@google.com9a412522012-09-07 15:21:18 +0000144 // Create a string to show our current settings.
145 // TODO: Make it prettier. Currently it just repeats the command line.
146 SkString commandLine("bench_pictures:");
147 for (int i = 1; i < argc; i++) {
148 commandLine.appendf(" %s", *(argv+i));
149 }
150 commandLine.append("\n");
151
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000152 bool usePipe = false;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000153 int numThreads = 1;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000154 bool useTiles = false;
155 const char* widthString = NULL;
156 const char* heightString = NULL;
157 bool isPowerOf2Mode = false;
158 const char* mode = NULL;
reed@google.com006db0f2012-06-27 19:33:29 +0000159 for (++argv; argv < stop; ++argv) {
160 if (0 == strcmp(*argv, "--repeat")) {
161 ++argv;
162 if (argv < stop) {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000163 repeats = atoi(*argv);
164 if (repeats < 1) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000165 gLogger.logError("--repeat must be given a value > 0\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000166 exit(-1);
167 }
168 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000169 gLogger.logError("Missing arg for --repeat\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000170 usage(argv0);
171 exit(-1);
172 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000173 } else if (0 == strcmp(*argv, "--pipe")) {
174 usePipe = true;
scroggo@google.com9a412522012-09-07 15:21:18 +0000175 } else if (0 == strcmp(*argv, "--logFile")) {
176 argv++;
177 if (argv < stop) {
178 if (!gLogger.SetLogFile(*argv)) {
179 SkString str;
180 str.printf("Could not open %s for writing.", *argv);
181 gLogger.logError(str);
182 usage(argv0);
borenet@google.coma49bffd2012-09-13 18:54:48 +0000183 // TODO(borenet): We're disabling this for now, due to
184 // write-protected Android devices. The very short-term
185 // solution is to ignore the fact that we have no log file.
186 //exit(-1);
scroggo@google.com9a412522012-09-07 15:21:18 +0000187 }
188 } else {
189 gLogger.logError("Missing arg for --logFile\n");
190 usage(argv0);
191 exit(-1);
192 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000193 } else if (0 == strcmp(*argv, "--multi")) {
194 ++argv;
195 if (argv >= stop) {
196 gLogger.logError("Missing arg for --multi\n");
197 usage(argv0);
198 exit(-1);
199 }
200 numThreads = atoi(*argv);
201 if (numThreads < 2) {
202 gLogger.logError("Number of threads must be at least 2.\n");
203 usage(argv0);
204 exit(-1);
205 }
keyar@chromium.org795cd472012-08-02 18:57:53 +0000206 } else if (0 == strcmp(*argv, "--mode")) {
keyar@chromium.org795cd472012-08-02 18:57:53 +0000207
reed@google.com006db0f2012-06-27 19:33:29 +0000208 ++argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000209 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000210 gLogger.logError("Missing mode for --mode\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000211 usage(argv0);
212 exit(-1);
213 }
214
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000215 if (0 == strcmp(*argv, "record")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000216 renderer = SkNEW(sk_tools::RecordPictureRenderer);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000217 } else if (0 == strcmp(*argv, "simple")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000218 renderer = SkNEW(sk_tools::SimplePictureRenderer);
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000219 } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))) {
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000220 useTiles = true;
221 mode = *argv;
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000222
223 if (0 == strcmp(*argv, "pow2tile")) {
224 isPowerOf2Mode = true;
225 }
226
keyar@chromium.org795cd472012-08-02 18:57:53 +0000227 ++argv;
228 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000229 SkString err;
230 err.printf("Missing width for --mode %s\n", mode);
231 gLogger.logError(err);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000232 usage(argv0);
233 exit(-1);
234 }
235
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000236 widthString = *argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000237 ++argv;
238 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000239 gLogger.logError("Missing height for --mode tile\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000240 usage(argv0);
241 exit(-1);
242 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000243 heightString = *argv;
scroggo@google.com9a412522012-09-07 15:21:18 +0000244 } else if (0 == strcmp(*argv, "playbackCreation")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000245 renderer = SkNEW(sk_tools::PlaybackCreationRenderer);
reed@google.com006db0f2012-06-27 19:33:29 +0000246 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000247 SkString err;
248 err.printf("%s is not a valid mode for --mode\n", *argv);
249 gLogger.logError(err);
keyar@chromium.org0665f252012-07-10 18:30:18 +0000250 usage(argv0);
reed@google.com006db0f2012-06-27 19:33:29 +0000251 exit(-1);
252 }
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000253 } else if (0 == strcmp(*argv, "--device")) {
254 ++argv;
255 if (argv >= stop) {
borenet@google.coma49bffd2012-09-13 18:54:48 +0000256 gLogger.logError("Missing mode for --device\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000257 usage(argv0);
258 exit(-1);
259 }
260
261 if (0 == strcmp(*argv, "bitmap")) {
262 deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType;
263 }
264#if SK_SUPPORT_GPU
265 else if (0 == strcmp(*argv, "gpu")) {
266 deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
267 }
268#endif
269 else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000270 SkString err;
271 err.printf("%s is not a valid mode for --device\n", *argv);
272 gLogger.logError(err);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000273 usage(argv0);
274 exit(-1);
275 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000276 } else if (0 == strcmp(*argv, "--timers")) {
277 ++argv;
278 if (argv < stop) {
279 bool timerWall = false;
280 bool truncatedTimerWall = false;
281 bool timerCpu = false;
282 bool truncatedTimerCpu = false;
283 bool timerGpu = false;
284 for (char* t = *argv; *t; ++t) {
285 switch (*t) {
286 case 'w':
287 timerWall = true;
288 break;
289 case 'c':
290 timerCpu = true;
291 break;
292 case 'W':
293 truncatedTimerWall = true;
294 break;
295 case 'C':
296 truncatedTimerCpu = true;
297 break;
298 case 'g':
299 timerGpu = true;
300 break;
301 default: {
302 break;
303 }
304 }
305 }
306 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu,
307 truncatedTimerCpu, timerGpu);
308 } else {
309 gLogger.logError("Missing arg for --timers\n");
310 usage(argv0);
311 exit(-1);
312 }
313 } else if (0 == strcmp(*argv, "--min")) {
314 benchmark->setPrintMin(true);
315 } else if (0 == strcmp(*argv, "--logPerIter")) {
316 ++argv;
317 if (argv < stop) {
318 bool log = atoi(*argv) != 0;
319 benchmark->setLogPerIter(log);
320 } else {
321 gLogger.logError("Missing arg for --logPerIter\n");
322 usage(argv0);
323 exit(-1);
324 }
reed@google.com006db0f2012-06-27 19:33:29 +0000325 } else if (0 == strcmp(*argv, "--help") || 0 == strcmp(*argv, "-h")) {
326 usage(argv0);
327 exit(0);
328 } else {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000329 inputs->push_back(SkString(*argv));
reed@google.com006db0f2012-06-27 19:33:29 +0000330 }
331 }
332
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000333 if (numThreads > 1 && !useTiles) {
334 gLogger.logError("Multithreaded drawing requires tiled rendering.\n");
335 usage(argv0);
336 exit(-1);
337 }
338
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000339 if (useTiles) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000340 SkASSERT(NULL == renderer);
341 sk_tools::TiledPictureRenderer* tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000342 if (isPowerOf2Mode) {
343 int minWidth = atoi(widthString);
344 if (!SkIsPow2(minWidth) || minWidth < 0) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000345 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000346 SkString err;
scroggo@google.com5239c322012-09-11 19:15:32 +0000347 err.printf("-mode %s must be given a width"
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000348 " value that is a power of two\n", mode);
scroggo@google.com9a412522012-09-07 15:21:18 +0000349 gLogger.logError(err);
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000350 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000351 exit(-1);
352 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000353 tiledRenderer->setTileMinPowerOf2Width(minWidth);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000354 } else if (sk_tools::is_percentage(widthString)) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000355 tiledRenderer->setTileWidthPercentage(atof(widthString));
356 if (!(tiledRenderer->getTileWidthPercentage() > 0)) {
357 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000358 gLogger.logError("--mode tile must be given a width percentage > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000359 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000360 exit(-1);
361 }
362 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000363 tiledRenderer->setTileWidth(atoi(widthString));
364 if (!(tiledRenderer->getTileWidth() > 0)) {
365 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000366 gLogger.logError("--mode tile must be given a width > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000367 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000368 exit(-1);
369 }
370 }
371
372 if (sk_tools::is_percentage(heightString)) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000373 tiledRenderer->setTileHeightPercentage(atof(heightString));
374 if (!(tiledRenderer->getTileHeightPercentage() > 0)) {
375 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000376 gLogger.logError("--mode tile must be given a height percentage > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000377 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000378 exit(-1);
379 }
380 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000381 tiledRenderer->setTileHeight(atoi(heightString));
382 if (!(tiledRenderer->getTileHeight() > 0)) {
383 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000384 gLogger.logError("--mode tile must be given a height > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000385 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000386 exit(-1);
387 }
388 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000389 if (numThreads > 1) {
390#if SK_SUPPORT_GPU
391 if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) {
392 tiledRenderer->unref();
393 gLogger.logError("GPU not compatible with multithreaded tiling.\n");
394 usage(argv0);
395 exit(-1);
396 }
397#endif
398 tiledRenderer->setNumberOfThreads(numThreads);
399 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000400 tiledRenderer->setUsePipe(usePipe);
401 renderer = tiledRenderer;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000402 } else if (usePipe) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000403 renderer = SkNEW(sk_tools::PipePictureRenderer);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000404 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000405 if (inputs->count() < 1) {
fmalita@google.comc6157be2012-09-27 13:09:58 +0000406 SkSafeUnref(renderer);
reed@google.com006db0f2012-06-27 19:33:29 +0000407 usage(argv0);
408 exit(-1);
409 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000410
scroggo@google.com5239c322012-09-11 19:15:32 +0000411 if (NULL == renderer) {
412 renderer = SkNEW(sk_tools::SimplePictureRenderer);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000413 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000414 benchmark->setRenderer(renderer)->unref();
keyar@chromium.org163b5672012-08-01 17:53:29 +0000415 benchmark->setRepeats(repeats);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000416 benchmark->setDeviceType(deviceType);
scroggo@google.com9a412522012-09-07 15:21:18 +0000417 benchmark->setLogger(&gLogger);
418 // Report current settings:
419 gLogger.logProgress(commandLine);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000420}
reed@google.com006db0f2012-06-27 19:33:29 +0000421
borenet@google.com66bcbd12012-09-17 18:26:06 +0000422static int process_input(const SkString& input,
423 sk_tools::PictureBenchmark& benchmark) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000424 SkOSFile::Iter iter(input.c_str(), "skp");
425 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000426 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000427 if (iter.next(&inputFilename)) {
428 do {
429 SkString inputPath;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000430 sk_tools::make_filepath(&inputPath, input, inputFilename);
borenet@google.com57837bf2012-09-19 17:28:29 +0000431 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000432 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000433 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000434 } while(iter.next(&inputFilename));
borenet@google.com57837bf2012-09-19 17:28:29 +0000435 } else if (SkStrEndsWith(input.c_str(), ".skp")) {
436 if (!run_single_benchmark(input, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000437 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000438 }
439 } else {
440 SkString warning;
441 warning.printf("Warning: skipping %s\n", input.c_str());
442 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000443 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000444 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000445}
446
caryclark@google.com5987f582012-10-02 18:33:14 +0000447int tool_main(int argc, char** argv);
448int tool_main(int argc, char** argv) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000449#ifdef SK_ENABLE_INST_COUNT
450 gPrintInstCount = true;
451#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000452 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000453
scroggo@google.com5239c322012-09-11 19:15:32 +0000454 SkTArray<SkString> inputs;
455 sk_tools::PictureBenchmark benchmark;
456
457 parse_commandline(argc, argv, &inputs, &benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000458
borenet@google.com66bcbd12012-09-17 18:26:06 +0000459 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000460 for (int i = 0; i < inputs.count(); ++i) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000461 failures += process_input(inputs[i], benchmark);
462 }
463
464 if (failures != 0) {
465 SkString err;
466 err.printf("Failed to run %i benchmarks.\n", failures);
467 gLogger.logError(err);
468 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000469 }
caryclark@google.com868e1f62012-10-02 20:00:03 +0000470 return 0;
reed@google.com006db0f2012-06-27 19:33:29 +0000471}
caryclark@google.com5987f582012-10-02 18:33:14 +0000472
473#if !defined SK_BUILD_FOR_IOS
474int main(int argc, char * const argv[]) {
475 return tool_main(argc, (char**) argv);
476}
477#endif