blob: 5ff519c8c5e67e9aa6aef4ce47e3637f7197518f [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
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +000052DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before timing.");
53
caryclark@google.coma3622372012-11-06 21:26:13 +000054static char const * const gFilterTypes[] = {
55 "paint",
56 "point",
57 "line",
58 "bitmap",
59 "rect",
jvanverth@google.comd3c208c2013-01-22 13:54:52 +000060 "oval",
caryclark@google.coma3622372012-11-06 21:26:13 +000061 "path",
62 "text",
63 "all",
64};
65
66static const size_t kFilterTypesCount = sizeof(gFilterTypes) / sizeof(gFilterTypes[0]);
67
68static char const * const gFilterFlags[] = {
69 "antiAlias",
70 "filterBitmap",
71 "dither",
72 "underlineText",
73 "strikeThruText",
74 "fakeBoldText",
75 "linearText",
76 "subpixelText",
77 "devKernText",
78 "LCDRenderText",
79 "embeddedBitmapText",
80 "autoHinting",
81 "verticalText",
82 "genA8FromLCD",
83 "blur",
84 "hinting",
85 "slightHinting",
caryclark@google.come3e940c2012-11-07 16:42:17 +000086 "AAClip",
caryclark@google.coma3622372012-11-06 21:26:13 +000087};
88
89static const size_t kFilterFlagsCount = sizeof(gFilterFlags) / sizeof(gFilterFlags[0]);
90
91static SkString filtersName(sk_tools::PictureRenderer::DrawFilterFlags* drawFilters) {
92 int all = drawFilters[0];
93 size_t tIndex;
94 for (tIndex = 1; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
95 all &= drawFilters[tIndex];
96 }
97 SkString result;
98 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
99 SkString types;
100 if (all & (1 << fIndex)) {
101 types = gFilterTypes[SkDrawFilter::kTypeCount];
102 } else {
103 for (tIndex = 0; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
104 if (drawFilters[tIndex] & (1 << fIndex)) {
105 types += gFilterTypes[tIndex];
106 }
107 }
108 }
109 if (!types.size()) {
110 continue;
111 }
112 result += "_";
113 result += types;
114 result += ".";
115 result += gFilterFlags[fIndex];
116 }
117 return result;
118}
119
120static SkString filterTypesUsage() {
121 SkString result;
122 for (size_t index = 0; index < kFilterTypesCount; ++index) {
123 result += gFilterTypes[index];
124 if (index < kFilterTypesCount - 1) {
125 result += " | ";
126 }
127 }
128 return result;
129}
130
131static SkString filterFlagsUsage() {
132 SkString result;
133 size_t len = 0;
134 for (size_t index = 0; index < kFilterFlagsCount; ++index) {
135 result += gFilterFlags[index];
136 if (result.size() - len >= 72) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000137 result += "\n\t\t";
caryclark@google.coma3622372012-11-06 21:26:13 +0000138 len = result.size();
139 }
140 if (index < kFilterFlagsCount - 1) {
141 result += " | ";
142 }
143 }
144 return result;
145}
146
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000147#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000148static int32_t gTotalCacheHits;
149static int32_t gTotalCacheMisses;
150#endif
151
borenet@google.com66bcbd12012-09-17 18:26:06 +0000152static bool run_single_benchmark(const SkString& inputPath,
keyar@chromium.org163b5672012-08-01 17:53:29 +0000153 sk_tools::PictureBenchmark& benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000154 SkFILEStream inputStream;
155
reed@google.com006db0f2012-06-27 19:33:29 +0000156 inputStream.setPath(inputPath.c_str());
157 if (!inputStream.isValid()) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000158 SkString err;
159 err.printf("Could not open file %s\n", inputPath.c_str());
160 gLogger.logError(err);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000161 return false;
reed@google.com006db0f2012-06-27 19:33:29 +0000162 }
163
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000164 SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000165 // Since the old picture has been deleted, all pixels should be cleared.
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000166 SkASSERT(pool->getRAMUsed() == 0);
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000167 if (FLAGS_countRAM) {
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000168 pool->setRAMBudget(SK_MaxU32);
169 // Set the limit to max, so all pixels will be kept
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000170 }
171
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000172 SkPicture::InstallPixelRefProc proc;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000173 if (FLAGS_deferImageDecoding) {
commit-bot@chromium.org56799e22013-07-16 18:21:46 +0000174 proc = &sk_tools::LazyDecodeBitmap;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000175 } else {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000176 proc = &SkImageDecoder::DecodeMemory;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000177 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000178 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, proc));
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000179
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000180 if (NULL == picture.get()) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000181 SkString err;
182 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
183 gLogger.logError(err);
184 return false;
185 }
reed@google.com006db0f2012-06-27 19:33:29 +0000186
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000187 SkString filename;
188 sk_tools::get_basename(&filename, inputPath);
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000189
190 SkString result;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000191 result.printf("running bench [%i %i] %s ", picture->width(), picture->height(),
192 filename.c_str());
scroggo@google.com9a412522012-09-07 15:21:18 +0000193 gLogger.logProgress(result);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000194
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000195 benchmark.run(picture);
scroggo@google.comcc690202013-03-04 19:56:21 +0000196
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000197#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000198 if (FLAGS_trackDeferredCaching) {
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000199 int cacheHits = pool->getCacheHits();
200 int cacheMisses = pool->getCacheMisses();
201 pool->resetCacheHitsAndMisses();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000202 SkString hitString;
203 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
204 gLogger.logProgress(hitString);
scroggo@google.comcc690202013-03-04 19:56:21 +0000205 gTotalCacheHits += cacheHits;
206 gTotalCacheMisses += cacheMisses;
207 }
208#endif
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000209 if (FLAGS_countRAM) {
210 SkString ramCount("RAM used for bitmaps: ");
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000211 size_t bytes = pool->getRAMUsed();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000212 if (bytes > 1024) {
213 size_t kb = bytes / 1024;
214 if (kb > 1024) {
215 size_t mb = kb / 1024;
216 ramCount.appendf("%zi MB\n", mb);
217 } else {
218 ramCount.appendf("%zi KB\n", kb);
219 }
220 } else {
221 ramCount.appendf("%zi bytes\n", bytes);
222 }
223 gLogger.logProgress(ramCount);
224 }
scroggo@google.comcc690202013-03-04 19:56:21 +0000225
borenet@google.com66bcbd12012-09-17 18:26:06 +0000226 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000227}
228
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000229static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) {
caryclark@google.coma3622372012-11-06 21:26:13 +0000230 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount];
231 sk_bzero(drawFilters, sizeof(drawFilters));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000232
233 if (FLAGS_filter.count() > 0) {
234 const char* filters = FLAGS_filter[0];
235 const char* colon = strchr(filters, ':');
236 if (colon) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000237 int32_t type = -1;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000238 size_t typeLen = colon - filters;
239 for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) {
240 if (typeLen == strlen(gFilterTypes[tIndex])
241 && !strncmp(filters, gFilterTypes[tIndex], typeLen)) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000242 type = SkToS32(tIndex);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000243 break;
reed@google.com006db0f2012-06-27 19:33:29 +0000244 }
reed@google.com006db0f2012-06-27 19:33:29 +0000245 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000246 if (type < 0) {
junov@chromium.org9313ca42012-11-02 18:11:49 +0000247 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000248 err.printf("Unknown type for --filter %s\n", filters);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000249 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000250 exit(-1);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000251 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000252 int flag = -1;
253 size_t flagLen = strlen(filters) - typeLen - 1;
254 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
255 if (flagLen == strlen(gFilterFlags[fIndex])
256 && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) {
257 flag = 1 << fIndex;
258 break;
259 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000260 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000261 if (flag < 0) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000262 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000263 err.printf("Unknown flag for --filter %s\n", filters);
scroggo@google.com9a412522012-09-07 15:21:18 +0000264 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000265 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000266 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000267 for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) {
268 if (type != SkDrawFilter::kTypeCount && index != type) {
269 continue;
scroggo@google.com5239c322012-09-11 19:15:32 +0000270 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000271 drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags)
272 (drawFilters[index] | flag);
scroggo@google.com5239c322012-09-11 19:15:32 +0000273 }
reed@google.com006db0f2012-06-27 19:33:29 +0000274 } else {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000275 SkString err;
276 err.printf("Unknown arg for --filter %s : missing colon\n", filters);
277 gLogger.logError(err);
278 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000279 }
280 }
281
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000282 if (FLAGS_timers.count() > 0) {
283 size_t index = 0;
284 bool timerWall = false;
285 bool truncatedTimerWall = false;
286 bool timerCpu = false;
287 bool truncatedTimerCpu = false;
288 bool timerGpu = false;
289 while (index < strlen(FLAGS_timers[0])) {
290 switch (FLAGS_timers[0][index]) {
291 case 'w':
292 timerWall = true;
293 break;
294 case 'c':
295 timerCpu = true;
296 break;
297 case 'W':
298 truncatedTimerWall = true;
299 break;
300 case 'C':
301 truncatedTimerCpu = true;
302 break;
303 case 'g':
304 timerGpu = true;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000305 break;
306 default:
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000307 SkDebugf("mystery character\n");
scroggo@google.com0556ea02013-02-08 19:38:21 +0000308 break;
309 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000310 index++;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000311 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000312 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, truncatedTimerCpu,
313 timerGpu);
reed@google.com006db0f2012-06-27 19:33:29 +0000314 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000315
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000316 SkString errorString;
317 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
318 kBench_PictureTool));
319
320 if (errorString.size() > 0) {
321 gLogger.logError(errorString);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000322 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000323
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000324 if (NULL == renderer.get()) {
325 exit(-1);
326 }
327
328 if (FLAGS_timeIndividualTiles) {
329 if (FLAGS_multi > 1) {
330 gLogger.logError("Cannot time individual tiles with more than one thread.\n");
331 exit(-1);
332 }
333 sk_tools::TiledPictureRenderer* tiledRenderer = renderer->getTiledRenderer();
334 if (NULL == tiledRenderer) {
335 gLogger.logError("--timeIndividualTiles requires tiled rendering.\n");
336 exit(-1);
337 }
338 if (!tiledRenderer->supportsTimingIndividualTiles()) {
339 gLogger.logError("This renderer does not support --timeIndividualTiles.\n");
340 exit(-1);
341 }
342 benchmark->setTimeIndividualTiles(true);
343 }
344
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000345 benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex);
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +0000346 benchmark->setPreprocess(FLAGS_preprocess);
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000347
scroggo@google.com604e0c22013-04-09 21:25:46 +0000348 if (FLAGS_readPath.count() < 1) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000349 gLogger.logError(".skp files or directories are required.\n");
350 exit(-1);
351 }
352
caryclark@google.coma3622372012-11-06 21:26:13 +0000353 renderer->setDrawFilters(drawFilters, filtersName(drawFilters));
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +0000354 if (FLAGS_logPerIter) {
355 benchmark->setTimerResultType(TimerData::kPerIter_Result);
356 } else if (FLAGS_min) {
357 benchmark->setTimerResultType(TimerData::kMin_Result);
358 } else {
359 benchmark->setTimerResultType(TimerData::kAvg_Result);
360 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000361 benchmark->setRenderer(renderer);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000362 benchmark->setRepeats(FLAGS_repeat);
scroggo@google.com9a412522012-09-07 15:21:18 +0000363 benchmark->setLogger(&gLogger);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000364}
reed@google.com006db0f2012-06-27 19:33:29 +0000365
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000366static int process_input(const char* input,
borenet@google.com66bcbd12012-09-17 18:26:06 +0000367 sk_tools::PictureBenchmark& benchmark) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000368 SkString inputAsSkString(input);
369 SkOSFile::Iter iter(input, "skp");
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000370 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000371 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000372 if (iter.next(&inputFilename)) {
373 do {
374 SkString inputPath;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000375 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
borenet@google.com57837bf2012-09-19 17:28:29 +0000376 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000377 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000378 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000379 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000380 } else if (SkStrEndsWith(input, ".skp")) {
381 if (!run_single_benchmark(inputAsSkString, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000382 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000383 }
384 } else {
385 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000386 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000387 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000388 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000389 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000390}
391
caryclark@google.com5987f582012-10-02 18:33:14 +0000392int tool_main(int argc, char** argv);
393int tool_main(int argc, char** argv) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000394 SkString usage;
395 usage.printf("Time drawing .skp files.\n"
396 "\tPossible arguments for --filter: [%s]\n\t\t[%s]",
397 filterTypesUsage().c_str(), filterFlagsUsage().c_str());
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000398 SkCommandLineFlags::SetUsage(usage.c_str());
399 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000400
401 if (FLAGS_repeat < 1) {
402 SkString error;
403 error.printf("--repeats must be >= 1. Was %i\n", FLAGS_repeat);
404 gLogger.logError(error);
405 exit(-1);
406 }
407
408 if (FLAGS_logFile.count() == 1) {
409 if (!gLogger.SetLogFile(FLAGS_logFile[0])) {
410 SkString str;
411 str.printf("Could not open %s for writing.\n", FLAGS_logFile[0]);
412 gLogger.logError(str);
413 // TODO(borenet): We're disabling this for now, due to
414 // write-protected Android devices. The very short-term
415 // solution is to ignore the fact that we have no log file.
416 //exit(-1);
417 }
418 }
419
420
bsalomon@google.com4e230682013-01-15 20:37:04 +0000421#if SK_ENABLE_INST_COUNT
scroggo@google.com5239c322012-09-11 19:15:32 +0000422 gPrintInstCount = true;
423#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000424 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000425
scroggo@google.com5239c322012-09-11 19:15:32 +0000426 sk_tools::PictureBenchmark benchmark;
427
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000428 setup_benchmark(&benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000429
borenet@google.com66bcbd12012-09-17 18:26:06 +0000430 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000431 for (int i = 0; i < FLAGS_readPath.count(); ++i) {
432 failures += process_input(FLAGS_readPath[i], benchmark);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000433 }
434
435 if (failures != 0) {
436 SkString err;
437 err.printf("Failed to run %i benchmarks.\n", failures);
438 gLogger.logError(err);
439 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000440 }
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000441#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000442 if (FLAGS_trackDeferredCaching) {
443 SkDebugf("Total cache hit rate: %f\n",
444 (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses));
445 }
446#endif
caryclark@google.com868e1f62012-10-02 20:00:03 +0000447 return 0;
reed@google.com006db0f2012-06-27 19:33:29 +0000448}
caryclark@google.com5987f582012-10-02 18:33:14 +0000449
450#if !defined SK_BUILD_FOR_IOS
451int main(int argc, char * const argv[]) {
452 return tool_main(argc, (char**) argv);
453}
454#endif