blob: 4952571fade30f71f29cc0dece167032047b6b94 [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"
scroggo@google.com4a26d9d2012-11-07 18:01:46 +00009#include "CopyTilesRenderer.h"
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000010#include "LazyDecodeBitmap.h"
keyar@chromium.org163b5672012-08-01 17:53:29 +000011#include "PictureBenchmark.h"
scroggo@google.com161e1ba2013-03-04 16:41:06 +000012#include "PictureRenderingFlags.h"
scroggo@google.com9a412522012-09-07 15:21:18 +000013#include "SkBenchLogger.h"
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000014#include "SkCommandLineFlags.h"
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000015#include "SkDiscardableMemoryPool.h"
scroggo@google.com0a36f432012-09-10 20:29:13 +000016#include "SkGraphics.h"
scroggo@google.com5a7c6be2012-10-04 21:46:08 +000017#include "SkImageDecoder.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000018#include "SkMath.h"
reed@google.com006db0f2012-06-27 19:33:29 +000019#include "SkOSFile.h"
20#include "SkPicture.h"
21#include "SkStream.h"
reed@google.com006db0f2012-06-27 19:33:29 +000022#include "picture_utils.h"
23
scroggo@google.com161e1ba2013-03-04 16:41:06 +000024SkBenchLogger gLogger;
25
26// Flags used by this file, in alphabetical order.
scroggo@google.coma560d00b2013-03-04 21:32:32 +000027DEFINE_bool(countRAM, false, "Count the RAM used for bitmap pixels in each skp file");
scroggo@google.com161e1ba2013-03-04 16:41:06 +000028DECLARE_bool(deferImageDecoding);
29DEFINE_string(filter, "",
30 "type:flag : Enable canvas filtering to disable a paint flag, "
31 "use no blur or low quality blur, or use no hinting or "
32 "slight hinting. For all flags except AAClip, specify the "
33 "type of primitive to effect, or choose all. for AAClip "
34 "alone, the filter affects all clips independent of type. "
35 "Specific flags are listed above.");
36DEFINE_string(logFile, "", "Destination for writing log output, in addition to stdout.");
37DEFINE_bool(logPerIter, false, "Log each repeat timer instead of mean.");
38DEFINE_bool(min, false, "Print the minimum times (instead of average).");
39DECLARE_int32(multi);
scroggo@google.com604e0c22013-04-09 21:25:46 +000040DECLARE_string(readPath);
scroggo@google.com161e1ba2013-03-04 16:41:06 +000041DEFINE_int32(repeat, 1, "Set the number of times to repeat each test.");
42DEFINE_bool(timeIndividualTiles, false, "Report times for drawing individual tiles, rather than "
43 "times for drawing the whole page. Requires tiled rendering.");
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000044DEFINE_bool(purgeDecodedTex, false, "Purge decoded and GPU-uploaded textures "
45 "after each iteration.");
scroggo@google.com65e508d2013-08-02 16:09:10 +000046DEFINE_string(timers, "c", "[wcgWC]*: Display wall, cpu, gpu, truncated wall or truncated cpu time"
scroggo@google.com161e1ba2013-03-04 16:41:06 +000047 " for each picture.");
scroggo@google.comcc690202013-03-04 19:56:21 +000048DEFINE_bool(trackDeferredCaching, false, "Only meaningful with --deferImageDecoding and "
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +000049 "SK_LAZY_CACHE_STATS set to true. Report percentage of cache hits when using "
50 "deferred image decoding.");
reed@google.com006db0f2012-06-27 19:33:29 +000051
caryclark@google.coma3622372012-11-06 21:26:13 +000052static char const * const gFilterTypes[] = {
53 "paint",
54 "point",
55 "line",
56 "bitmap",
57 "rect",
jvanverth@google.comd3c208c2013-01-22 13:54:52 +000058 "oval",
caryclark@google.coma3622372012-11-06 21:26:13 +000059 "path",
60 "text",
61 "all",
62};
63
64static const size_t kFilterTypesCount = sizeof(gFilterTypes) / sizeof(gFilterTypes[0]);
65
66static char const * const gFilterFlags[] = {
67 "antiAlias",
68 "filterBitmap",
69 "dither",
70 "underlineText",
71 "strikeThruText",
72 "fakeBoldText",
73 "linearText",
74 "subpixelText",
75 "devKernText",
76 "LCDRenderText",
77 "embeddedBitmapText",
78 "autoHinting",
79 "verticalText",
80 "genA8FromLCD",
81 "blur",
82 "hinting",
83 "slightHinting",
caryclark@google.come3e940c2012-11-07 16:42:17 +000084 "AAClip",
caryclark@google.coma3622372012-11-06 21:26:13 +000085};
86
87static const size_t kFilterFlagsCount = sizeof(gFilterFlags) / sizeof(gFilterFlags[0]);
88
89static SkString filtersName(sk_tools::PictureRenderer::DrawFilterFlags* drawFilters) {
90 int all = drawFilters[0];
91 size_t tIndex;
92 for (tIndex = 1; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
93 all &= drawFilters[tIndex];
94 }
95 SkString result;
96 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
97 SkString types;
98 if (all & (1 << fIndex)) {
99 types = gFilterTypes[SkDrawFilter::kTypeCount];
100 } else {
101 for (tIndex = 0; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
102 if (drawFilters[tIndex] & (1 << fIndex)) {
103 types += gFilterTypes[tIndex];
104 }
105 }
106 }
107 if (!types.size()) {
108 continue;
109 }
110 result += "_";
111 result += types;
112 result += ".";
113 result += gFilterFlags[fIndex];
114 }
115 return result;
116}
117
118static SkString filterTypesUsage() {
119 SkString result;
120 for (size_t index = 0; index < kFilterTypesCount; ++index) {
121 result += gFilterTypes[index];
122 if (index < kFilterTypesCount - 1) {
123 result += " | ";
124 }
125 }
126 return result;
127}
128
129static SkString filterFlagsUsage() {
130 SkString result;
131 size_t len = 0;
132 for (size_t index = 0; index < kFilterFlagsCount; ++index) {
133 result += gFilterFlags[index];
134 if (result.size() - len >= 72) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000135 result += "\n\t\t";
caryclark@google.coma3622372012-11-06 21:26:13 +0000136 len = result.size();
137 }
138 if (index < kFilterFlagsCount - 1) {
139 result += " | ";
140 }
141 }
142 return result;
143}
144
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000145#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000146static int32_t gTotalCacheHits;
147static int32_t gTotalCacheMisses;
148#endif
149
borenet@google.com66bcbd12012-09-17 18:26:06 +0000150static bool run_single_benchmark(const SkString& inputPath,
keyar@chromium.org163b5672012-08-01 17:53:29 +0000151 sk_tools::PictureBenchmark& benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000152 SkFILEStream inputStream;
153
reed@google.com006db0f2012-06-27 19:33:29 +0000154 inputStream.setPath(inputPath.c_str());
155 if (!inputStream.isValid()) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000156 SkString err;
157 err.printf("Could not open file %s\n", inputPath.c_str());
158 gLogger.logError(err);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000159 return false;
reed@google.com006db0f2012-06-27 19:33:29 +0000160 }
161
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000162 SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000163 // Since the old picture has been deleted, all pixels should be cleared.
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000164 SkASSERT(pool->getRAMUsed() == 0);
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000165 if (FLAGS_countRAM) {
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000166 pool->setRAMBudget(SK_MaxU32);
167 // Set the limit to max, so all pixels will be kept
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000168 }
169
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000170 SkPicture::InstallPixelRefProc proc;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000171 if (FLAGS_deferImageDecoding) {
commit-bot@chromium.org56799e22013-07-16 18:21:46 +0000172 proc = &sk_tools::LazyDecodeBitmap;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000173 } else {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000174 proc = &SkImageDecoder::DecodeMemory;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000175 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000176 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, proc));
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000177
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000178 if (NULL == picture.get()) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000179 SkString err;
180 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
181 gLogger.logError(err);
182 return false;
183 }
reed@google.com006db0f2012-06-27 19:33:29 +0000184
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000185 SkString filename;
186 sk_tools::get_basename(&filename, inputPath);
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000187
188 SkString result;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000189 result.printf("running bench [%i %i] %s ", picture->width(), picture->height(),
190 filename.c_str());
scroggo@google.com9a412522012-09-07 15:21:18 +0000191 gLogger.logProgress(result);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000192
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000193 benchmark.run(picture);
scroggo@google.comcc690202013-03-04 19:56:21 +0000194
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000195#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000196 if (FLAGS_trackDeferredCaching) {
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000197 int cacheHits = pool->getCacheHits();
198 int cacheMisses = pool->getCacheMisses();
199 pool->resetCacheHitsAndMisses();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000200 SkString hitString;
201 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
202 gLogger.logProgress(hitString);
scroggo@google.comcc690202013-03-04 19:56:21 +0000203 gTotalCacheHits += cacheHits;
204 gTotalCacheMisses += cacheMisses;
205 }
206#endif
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000207 if (FLAGS_countRAM) {
208 SkString ramCount("RAM used for bitmaps: ");
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000209 size_t bytes = pool->getRAMUsed();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000210 if (bytes > 1024) {
211 size_t kb = bytes / 1024;
212 if (kb > 1024) {
213 size_t mb = kb / 1024;
214 ramCount.appendf("%zi MB\n", mb);
215 } else {
216 ramCount.appendf("%zi KB\n", kb);
217 }
218 } else {
219 ramCount.appendf("%zi bytes\n", bytes);
220 }
221 gLogger.logProgress(ramCount);
222 }
scroggo@google.comcc690202013-03-04 19:56:21 +0000223
borenet@google.com66bcbd12012-09-17 18:26:06 +0000224 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000225}
226
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000227static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) {
caryclark@google.coma3622372012-11-06 21:26:13 +0000228 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount];
229 sk_bzero(drawFilters, sizeof(drawFilters));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000230
231 if (FLAGS_filter.count() > 0) {
232 const char* filters = FLAGS_filter[0];
233 const char* colon = strchr(filters, ':');
234 if (colon) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000235 int32_t type = -1;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000236 size_t typeLen = colon - filters;
237 for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) {
238 if (typeLen == strlen(gFilterTypes[tIndex])
239 && !strncmp(filters, gFilterTypes[tIndex], typeLen)) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000240 type = SkToS32(tIndex);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000241 break;
reed@google.com006db0f2012-06-27 19:33:29 +0000242 }
reed@google.com006db0f2012-06-27 19:33:29 +0000243 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000244 if (type < 0) {
junov@chromium.org9313ca42012-11-02 18:11:49 +0000245 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000246 err.printf("Unknown type for --filter %s\n", filters);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000247 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000248 exit(-1);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000249 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000250 int flag = -1;
251 size_t flagLen = strlen(filters) - typeLen - 1;
252 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
253 if (flagLen == strlen(gFilterFlags[fIndex])
254 && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) {
255 flag = 1 << fIndex;
256 break;
257 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000258 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000259 if (flag < 0) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000260 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000261 err.printf("Unknown flag for --filter %s\n", filters);
scroggo@google.com9a412522012-09-07 15:21:18 +0000262 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000263 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000264 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000265 for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) {
266 if (type != SkDrawFilter::kTypeCount && index != type) {
267 continue;
scroggo@google.com5239c322012-09-11 19:15:32 +0000268 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000269 drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags)
270 (drawFilters[index] | flag);
scroggo@google.com5239c322012-09-11 19:15:32 +0000271 }
reed@google.com006db0f2012-06-27 19:33:29 +0000272 } else {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000273 SkString err;
274 err.printf("Unknown arg for --filter %s : missing colon\n", filters);
275 gLogger.logError(err);
276 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000277 }
278 }
279
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000280 if (FLAGS_timers.count() > 0) {
281 size_t index = 0;
282 bool timerWall = false;
283 bool truncatedTimerWall = false;
284 bool timerCpu = false;
285 bool truncatedTimerCpu = false;
286 bool timerGpu = false;
287 while (index < strlen(FLAGS_timers[0])) {
288 switch (FLAGS_timers[0][index]) {
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;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000303 break;
304 default:
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000305 SkDebugf("mystery character\n");
scroggo@google.com0556ea02013-02-08 19:38:21 +0000306 break;
307 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000308 index++;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000309 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000310 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, truncatedTimerCpu,
311 timerGpu);
reed@google.com006db0f2012-06-27 19:33:29 +0000312 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000313
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000314 SkString errorString;
315 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
316 kBench_PictureTool));
317
318 if (errorString.size() > 0) {
319 gLogger.logError(errorString);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000320 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000321
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000322 if (NULL == renderer.get()) {
323 exit(-1);
324 }
325
326 if (FLAGS_timeIndividualTiles) {
327 if (FLAGS_multi > 1) {
328 gLogger.logError("Cannot time individual tiles with more than one thread.\n");
329 exit(-1);
330 }
331 sk_tools::TiledPictureRenderer* tiledRenderer = renderer->getTiledRenderer();
332 if (NULL == tiledRenderer) {
333 gLogger.logError("--timeIndividualTiles requires tiled rendering.\n");
334 exit(-1);
335 }
336 if (!tiledRenderer->supportsTimingIndividualTiles()) {
337 gLogger.logError("This renderer does not support --timeIndividualTiles.\n");
338 exit(-1);
339 }
340 benchmark->setTimeIndividualTiles(true);
341 }
342
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000343 benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex);
344
scroggo@google.com604e0c22013-04-09 21:25:46 +0000345 if (FLAGS_readPath.count() < 1) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000346 gLogger.logError(".skp files or directories are required.\n");
347 exit(-1);
348 }
349
caryclark@google.coma3622372012-11-06 21:26:13 +0000350 renderer->setDrawFilters(drawFilters, filtersName(drawFilters));
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +0000351 if (FLAGS_logPerIter) {
352 benchmark->setTimerResultType(TimerData::kPerIter_Result);
353 } else if (FLAGS_min) {
354 benchmark->setTimerResultType(TimerData::kMin_Result);
355 } else {
356 benchmark->setTimerResultType(TimerData::kAvg_Result);
357 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000358 benchmark->setRenderer(renderer);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000359 benchmark->setRepeats(FLAGS_repeat);
scroggo@google.com9a412522012-09-07 15:21:18 +0000360 benchmark->setLogger(&gLogger);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000361}
reed@google.com006db0f2012-06-27 19:33:29 +0000362
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000363static int process_input(const char* input,
borenet@google.com66bcbd12012-09-17 18:26:06 +0000364 sk_tools::PictureBenchmark& benchmark) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000365 SkString inputAsSkString(input);
366 SkOSFile::Iter iter(input, "skp");
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000367 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000368 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000369 if (iter.next(&inputFilename)) {
370 do {
371 SkString inputPath;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000372 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
borenet@google.com57837bf2012-09-19 17:28:29 +0000373 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000374 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000375 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000376 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000377 } else if (SkStrEndsWith(input, ".skp")) {
378 if (!run_single_benchmark(inputAsSkString, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000379 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000380 }
381 } else {
382 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000383 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000384 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000385 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000386 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000387}
388
caryclark@google.com5987f582012-10-02 18:33:14 +0000389int tool_main(int argc, char** argv);
390int tool_main(int argc, char** argv) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000391 SkString usage;
392 usage.printf("Time drawing .skp files.\n"
393 "\tPossible arguments for --filter: [%s]\n\t\t[%s]",
394 filterTypesUsage().c_str(), filterFlagsUsage().c_str());
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000395 SkCommandLineFlags::SetUsage(usage.c_str());
396 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000397
398 if (FLAGS_repeat < 1) {
399 SkString error;
400 error.printf("--repeats must be >= 1. Was %i\n", FLAGS_repeat);
401 gLogger.logError(error);
402 exit(-1);
403 }
404
405 if (FLAGS_logFile.count() == 1) {
406 if (!gLogger.SetLogFile(FLAGS_logFile[0])) {
407 SkString str;
408 str.printf("Could not open %s for writing.\n", FLAGS_logFile[0]);
409 gLogger.logError(str);
410 // TODO(borenet): We're disabling this for now, due to
411 // write-protected Android devices. The very short-term
412 // solution is to ignore the fact that we have no log file.
413 //exit(-1);
414 }
415 }
416
417
bsalomon@google.com4e230682013-01-15 20:37:04 +0000418#if SK_ENABLE_INST_COUNT
scroggo@google.com5239c322012-09-11 19:15:32 +0000419 gPrintInstCount = true;
420#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000421 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000422
scroggo@google.com5239c322012-09-11 19:15:32 +0000423 sk_tools::PictureBenchmark benchmark;
424
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000425 setup_benchmark(&benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000426
borenet@google.com66bcbd12012-09-17 18:26:06 +0000427 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000428 for (int i = 0; i < FLAGS_readPath.count(); ++i) {
429 failures += process_input(FLAGS_readPath[i], benchmark);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000430 }
431
432 if (failures != 0) {
433 SkString err;
434 err.printf("Failed to run %i benchmarks.\n", failures);
435 gLogger.logError(err);
436 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000437 }
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000438#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000439 if (FLAGS_trackDeferredCaching) {
440 SkDebugf("Total cache hit rate: %f\n",
441 (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses));
442 }
443#endif
caryclark@google.com868e1f62012-10-02 20:00:03 +0000444 return 0;
reed@google.com006db0f2012-06-27 19:33:29 +0000445}
caryclark@google.com5987f582012-10-02 18:33:14 +0000446
447#if !defined SK_BUILD_FOR_IOS
448int main(int argc, char * const argv[]) {
449 return tool_main(argc, (char**) argv);
450}
451#endif