blob: b79dfedff230f1eb0f799c3db1e51fce6d3ac3d8 [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"
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000015#include "SkData.h"
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000016#include "SkDiscardableMemoryPool.h"
scroggo@google.com0a36f432012-09-10 20:29:13 +000017#include "SkGraphics.h"
scroggo@google.com5a7c6be2012-10-04 21:46:08 +000018#include "SkImageDecoder.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000019#include "SkMath.h"
reed@google.com006db0f2012-06-27 19:33:29 +000020#include "SkOSFile.h"
21#include "SkPicture.h"
22#include "SkStream.h"
reed@google.com006db0f2012-06-27 19:33:29 +000023#include "picture_utils.h"
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000024#include "PictureResultsWriter.h"
reed@google.com006db0f2012-06-27 19:33:29 +000025
scroggo@google.com161e1ba2013-03-04 16:41:06 +000026SkBenchLogger gLogger;
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000027PictureResultsLoggerWriter gLogWriter(&gLogger);
28PictureResultsMultiWriter gWriter;
scroggo@google.com161e1ba2013-03-04 16:41:06 +000029
30// Flags used by this file, in alphabetical order.
scroggo@google.coma560d00b2013-03-04 21:32:32 +000031DEFINE_bool(countRAM, false, "Count the RAM used for bitmap pixels in each skp file");
scroggo@google.com161e1ba2013-03-04 16:41:06 +000032DECLARE_bool(deferImageDecoding);
33DEFINE_string(filter, "",
34 "type:flag : Enable canvas filtering to disable a paint flag, "
35 "use no blur or low quality blur, or use no hinting or "
36 "slight hinting. For all flags except AAClip, specify the "
37 "type of primitive to effect, or choose all. for AAClip "
38 "alone, the filter affects all clips independent of type. "
39 "Specific flags are listed above.");
40DEFINE_string(logFile, "", "Destination for writing log output, in addition to stdout.");
41DEFINE_bool(logPerIter, false, "Log each repeat timer instead of mean.");
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000042#ifdef SK_BUILD_JSON_WRITER
43DEFINE_string(jsonLog, "", "Destination for writing JSON data.");
44#endif
scroggo@google.com161e1ba2013-03-04 16:41:06 +000045DEFINE_bool(min, false, "Print the minimum times (instead of average).");
46DECLARE_int32(multi);
scroggo@google.com604e0c22013-04-09 21:25:46 +000047DECLARE_string(readPath);
scroggo@google.com161e1ba2013-03-04 16:41:06 +000048DEFINE_int32(repeat, 1, "Set the number of times to repeat each test.");
49DEFINE_bool(timeIndividualTiles, false, "Report times for drawing individual tiles, rather than "
50 "times for drawing the whole page. Requires tiled rendering.");
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000051DEFINE_bool(purgeDecodedTex, false, "Purge decoded and GPU-uploaded textures "
52 "after each iteration.");
scroggo@google.com65e508d2013-08-02 16:09:10 +000053DEFINE_string(timers, "c", "[wcgWC]*: Display wall, cpu, gpu, truncated wall or truncated cpu time"
scroggo@google.com161e1ba2013-03-04 16:41:06 +000054 " for each picture.");
scroggo@google.comcc690202013-03-04 19:56:21 +000055DEFINE_bool(trackDeferredCaching, false, "Only meaningful with --deferImageDecoding and "
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +000056 "SK_LAZY_CACHE_STATS set to true. Report percentage of cache hits when using "
57 "deferred image decoding.");
reed@google.com006db0f2012-06-27 19:33:29 +000058
commit-bot@chromium.orgba7aedd2014-05-23 01:02:21 +000059DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before timing.");
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +000060
caryclark@google.coma3622372012-11-06 21:26:13 +000061static char const * const gFilterTypes[] = {
62 "paint",
63 "point",
64 "line",
65 "bitmap",
66 "rect",
jvanverth@google.comd3c208c2013-01-22 13:54:52 +000067 "oval",
caryclark@google.coma3622372012-11-06 21:26:13 +000068 "path",
69 "text",
70 "all",
71};
72
73static const size_t kFilterTypesCount = sizeof(gFilterTypes) / sizeof(gFilterTypes[0]);
74
75static char const * const gFilterFlags[] = {
76 "antiAlias",
77 "filterBitmap",
78 "dither",
79 "underlineText",
80 "strikeThruText",
81 "fakeBoldText",
82 "linearText",
83 "subpixelText",
84 "devKernText",
85 "LCDRenderText",
86 "embeddedBitmapText",
87 "autoHinting",
88 "verticalText",
89 "genA8FromLCD",
90 "blur",
91 "hinting",
92 "slightHinting",
caryclark@google.come3e940c2012-11-07 16:42:17 +000093 "AAClip",
caryclark@google.coma3622372012-11-06 21:26:13 +000094};
95
96static const size_t kFilterFlagsCount = sizeof(gFilterFlags) / sizeof(gFilterFlags[0]);
97
98static SkString filtersName(sk_tools::PictureRenderer::DrawFilterFlags* drawFilters) {
99 int all = drawFilters[0];
100 size_t tIndex;
101 for (tIndex = 1; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
102 all &= drawFilters[tIndex];
103 }
104 SkString result;
105 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
106 SkString types;
107 if (all & (1 << fIndex)) {
108 types = gFilterTypes[SkDrawFilter::kTypeCount];
109 } else {
110 for (tIndex = 0; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
111 if (drawFilters[tIndex] & (1 << fIndex)) {
112 types += gFilterTypes[tIndex];
113 }
114 }
115 }
116 if (!types.size()) {
117 continue;
118 }
119 result += "_";
120 result += types;
121 result += ".";
122 result += gFilterFlags[fIndex];
123 }
124 return result;
125}
126
127static SkString filterTypesUsage() {
128 SkString result;
129 for (size_t index = 0; index < kFilterTypesCount; ++index) {
130 result += gFilterTypes[index];
131 if (index < kFilterTypesCount - 1) {
132 result += " | ";
133 }
134 }
135 return result;
136}
137
138static SkString filterFlagsUsage() {
139 SkString result;
140 size_t len = 0;
141 for (size_t index = 0; index < kFilterFlagsCount; ++index) {
142 result += gFilterFlags[index];
143 if (result.size() - len >= 72) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000144 result += "\n\t\t";
caryclark@google.coma3622372012-11-06 21:26:13 +0000145 len = result.size();
146 }
147 if (index < kFilterFlagsCount - 1) {
148 result += " | ";
149 }
150 }
151 return result;
152}
153
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000154#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000155static int32_t gTotalCacheHits;
156static int32_t gTotalCacheMisses;
157#endif
158
borenet@google.com66bcbd12012-09-17 18:26:06 +0000159static bool run_single_benchmark(const SkString& inputPath,
keyar@chromium.org163b5672012-08-01 17:53:29 +0000160 sk_tools::PictureBenchmark& benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000161 SkFILEStream inputStream;
162
reed@google.com006db0f2012-06-27 19:33:29 +0000163 inputStream.setPath(inputPath.c_str());
164 if (!inputStream.isValid()) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000165 SkString err;
166 err.printf("Could not open file %s\n", inputPath.c_str());
167 gLogger.logError(err);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000168 return false;
reed@google.com006db0f2012-06-27 19:33:29 +0000169 }
170
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000171 SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000172 // Since the old picture has been deleted, all pixels should be cleared.
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000173 SkASSERT(pool->getRAMUsed() == 0);
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000174 if (FLAGS_countRAM) {
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000175 pool->setRAMBudget(SK_MaxU32);
176 // Set the limit to max, so all pixels will be kept
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000177 }
178
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000179 SkPicture::InstallPixelRefProc proc;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000180 if (FLAGS_deferImageDecoding) {
commit-bot@chromium.org56799e22013-07-16 18:21:46 +0000181 proc = &sk_tools::LazyDecodeBitmap;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000182 } else {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000183 proc = &SkImageDecoder::DecodeMemory;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000184 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000185 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, proc));
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000186
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000187 if (NULL == picture.get()) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000188 SkString err;
189 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
190 gLogger.logError(err);
191 return false;
192 }
reed@google.com006db0f2012-06-27 19:33:29 +0000193
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000194 SkString filename;
195 sk_tools::get_basename(&filename, inputPath);
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000196
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000197 gWriter.bench(filename.c_str(), picture->width(), picture->height());
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000198
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000199 benchmark.run(picture);
scroggo@google.comcc690202013-03-04 19:56:21 +0000200
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000201#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000202 if (FLAGS_trackDeferredCaching) {
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000203 int cacheHits = pool->getCacheHits();
204 int cacheMisses = pool->getCacheMisses();
205 pool->resetCacheHitsAndMisses();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000206 SkString hitString;
207 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
208 gLogger.logProgress(hitString);
scroggo@google.comcc690202013-03-04 19:56:21 +0000209 gTotalCacheHits += cacheHits;
210 gTotalCacheMisses += cacheMisses;
211 }
212#endif
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000213 if (FLAGS_countRAM) {
214 SkString ramCount("RAM used for bitmaps: ");
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000215 size_t bytes = pool->getRAMUsed();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000216 if (bytes > 1024) {
217 size_t kb = bytes / 1024;
218 if (kb > 1024) {
219 size_t mb = kb / 1024;
220 ramCount.appendf("%zi MB\n", mb);
221 } else {
222 ramCount.appendf("%zi KB\n", kb);
223 }
224 } else {
225 ramCount.appendf("%zi bytes\n", bytes);
226 }
227 gLogger.logProgress(ramCount);
228 }
scroggo@google.comcc690202013-03-04 19:56:21 +0000229
borenet@google.com66bcbd12012-09-17 18:26:06 +0000230 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000231}
232
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000233static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) {
caryclark@google.coma3622372012-11-06 21:26:13 +0000234 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount];
235 sk_bzero(drawFilters, sizeof(drawFilters));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000236
237 if (FLAGS_filter.count() > 0) {
238 const char* filters = FLAGS_filter[0];
239 const char* colon = strchr(filters, ':');
240 if (colon) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000241 int32_t type = -1;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000242 size_t typeLen = colon - filters;
243 for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) {
244 if (typeLen == strlen(gFilterTypes[tIndex])
245 && !strncmp(filters, gFilterTypes[tIndex], typeLen)) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000246 type = SkToS32(tIndex);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000247 break;
reed@google.com006db0f2012-06-27 19:33:29 +0000248 }
reed@google.com006db0f2012-06-27 19:33:29 +0000249 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000250 if (type < 0) {
junov@chromium.org9313ca42012-11-02 18:11:49 +0000251 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000252 err.printf("Unknown type for --filter %s\n", filters);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000253 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000254 exit(-1);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000255 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000256 int flag = -1;
257 size_t flagLen = strlen(filters) - typeLen - 1;
258 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
259 if (flagLen == strlen(gFilterFlags[fIndex])
260 && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) {
261 flag = 1 << fIndex;
262 break;
263 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000264 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000265 if (flag < 0) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000266 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000267 err.printf("Unknown flag for --filter %s\n", filters);
scroggo@google.com9a412522012-09-07 15:21:18 +0000268 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000269 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000270 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000271 for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) {
272 if (type != SkDrawFilter::kTypeCount && index != type) {
273 continue;
scroggo@google.com5239c322012-09-11 19:15:32 +0000274 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000275 drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags)
276 (drawFilters[index] | flag);
scroggo@google.com5239c322012-09-11 19:15:32 +0000277 }
reed@google.com006db0f2012-06-27 19:33:29 +0000278 } else {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000279 SkString err;
280 err.printf("Unknown arg for --filter %s : missing colon\n", filters);
281 gLogger.logError(err);
282 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000283 }
284 }
285
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000286 if (FLAGS_timers.count() > 0) {
287 size_t index = 0;
288 bool timerWall = false;
289 bool truncatedTimerWall = false;
290 bool timerCpu = false;
291 bool truncatedTimerCpu = false;
292 bool timerGpu = false;
293 while (index < strlen(FLAGS_timers[0])) {
294 switch (FLAGS_timers[0][index]) {
295 case 'w':
296 timerWall = true;
297 break;
298 case 'c':
299 timerCpu = true;
300 break;
301 case 'W':
302 truncatedTimerWall = true;
303 break;
304 case 'C':
305 truncatedTimerCpu = true;
306 break;
307 case 'g':
308 timerGpu = true;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000309 break;
310 default:
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000311 SkDebugf("mystery character\n");
scroggo@google.com0556ea02013-02-08 19:38:21 +0000312 break;
313 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000314 index++;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000315 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000316 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, truncatedTimerCpu,
317 timerGpu);
reed@google.com006db0f2012-06-27 19:33:29 +0000318 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000319
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000320 SkString errorString;
321 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
322 kBench_PictureTool));
323
324 if (errorString.size() > 0) {
325 gLogger.logError(errorString);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000326 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000327
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000328 if (NULL == renderer.get()) {
329 exit(-1);
330 }
331
332 if (FLAGS_timeIndividualTiles) {
333 if (FLAGS_multi > 1) {
334 gLogger.logError("Cannot time individual tiles with more than one thread.\n");
335 exit(-1);
336 }
337 sk_tools::TiledPictureRenderer* tiledRenderer = renderer->getTiledRenderer();
338 if (NULL == tiledRenderer) {
339 gLogger.logError("--timeIndividualTiles requires tiled rendering.\n");
340 exit(-1);
341 }
342 if (!tiledRenderer->supportsTimingIndividualTiles()) {
343 gLogger.logError("This renderer does not support --timeIndividualTiles.\n");
344 exit(-1);
345 }
346 benchmark->setTimeIndividualTiles(true);
347 }
348
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000349 benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex);
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +0000350 benchmark->setPreprocess(FLAGS_preprocess);
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000351
scroggo@google.com604e0c22013-04-09 21:25:46 +0000352 if (FLAGS_readPath.count() < 1) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000353 gLogger.logError(".skp files or directories are required.\n");
354 exit(-1);
355 }
356
caryclark@google.coma3622372012-11-06 21:26:13 +0000357 renderer->setDrawFilters(drawFilters, filtersName(drawFilters));
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +0000358 if (FLAGS_logPerIter) {
359 benchmark->setTimerResultType(TimerData::kPerIter_Result);
360 } else if (FLAGS_min) {
361 benchmark->setTimerResultType(TimerData::kMin_Result);
362 } else {
363 benchmark->setTimerResultType(TimerData::kAvg_Result);
364 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000365 benchmark->setRenderer(renderer);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000366 benchmark->setRepeats(FLAGS_repeat);
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000367 benchmark->setWriter(&gWriter);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000368}
reed@google.com006db0f2012-06-27 19:33:29 +0000369
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000370static int process_input(const char* input,
borenet@google.com66bcbd12012-09-17 18:26:06 +0000371 sk_tools::PictureBenchmark& benchmark) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000372 SkString inputAsSkString(input);
373 SkOSFile::Iter iter(input, "skp");
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000374 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000375 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000376 if (iter.next(&inputFilename)) {
377 do {
378 SkString inputPath;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000379 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
borenet@google.com57837bf2012-09-19 17:28:29 +0000380 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000381 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000382 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000383 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000384 } else if (SkStrEndsWith(input, ".skp")) {
385 if (!run_single_benchmark(inputAsSkString, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000386 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000387 }
388 } else {
389 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000390 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000391 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000392 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000393 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000394}
395
caryclark@google.com5987f582012-10-02 18:33:14 +0000396int tool_main(int argc, char** argv);
397int tool_main(int argc, char** argv) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000398 SkString usage;
399 usage.printf("Time drawing .skp files.\n"
400 "\tPossible arguments for --filter: [%s]\n\t\t[%s]",
401 filterTypesUsage().c_str(), filterFlagsUsage().c_str());
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000402 SkCommandLineFlags::SetUsage(usage.c_str());
403 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000404
405 if (FLAGS_repeat < 1) {
406 SkString error;
407 error.printf("--repeats must be >= 1. Was %i\n", FLAGS_repeat);
408 gLogger.logError(error);
409 exit(-1);
410 }
411
412 if (FLAGS_logFile.count() == 1) {
413 if (!gLogger.SetLogFile(FLAGS_logFile[0])) {
414 SkString str;
415 str.printf("Could not open %s for writing.\n", FLAGS_logFile[0]);
416 gLogger.logError(str);
417 // TODO(borenet): We're disabling this for now, due to
418 // write-protected Android devices. The very short-term
419 // solution is to ignore the fact that we have no log file.
420 //exit(-1);
421 }
422 }
423
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000424#ifdef SK_BUILD_JSON_WRITER
425 SkAutoTDelete<PictureJSONResultsWriter> jsonWriter;
426 if (FLAGS_jsonLog.count() == 1) {
427 jsonWriter.reset(SkNEW(PictureJSONResultsWriter(FLAGS_jsonLog[0])));
428 gWriter.add(jsonWriter.get());
429 }
430
431#endif
432 gWriter.add(&gLogWriter);
433
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000434
bsalomon@google.com4e230682013-01-15 20:37:04 +0000435#if SK_ENABLE_INST_COUNT
scroggo@google.com5239c322012-09-11 19:15:32 +0000436 gPrintInstCount = true;
437#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000438 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000439
scroggo@google.com5239c322012-09-11 19:15:32 +0000440 sk_tools::PictureBenchmark benchmark;
441
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000442 setup_benchmark(&benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000443
borenet@google.com66bcbd12012-09-17 18:26:06 +0000444 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000445 for (int i = 0; i < FLAGS_readPath.count(); ++i) {
446 failures += process_input(FLAGS_readPath[i], benchmark);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000447 }
448
449 if (failures != 0) {
450 SkString err;
451 err.printf("Failed to run %i benchmarks.\n", failures);
452 gLogger.logError(err);
453 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000454 }
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000455#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000456 if (FLAGS_trackDeferredCaching) {
457 SkDebugf("Total cache hit rate: %f\n",
458 (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses));
459 }
460#endif
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000461 gWriter.end();
caryclark@google.com868e1f62012-10-02 20:00:03 +0000462 return 0;
reed@google.com006db0f2012-06-27 19:33:29 +0000463}
caryclark@google.com5987f582012-10-02 18:33:14 +0000464
465#if !defined SK_BUILD_FOR_IOS
466int main(int argc, char * const argv[]) {
467 return tool_main(argc, (char**) argv);
468}
469#endif