blob: c267c4cb9ba0f05598b8fdee8cc7259bc5b9071f [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
tfarina1c99ea82014-06-11 08:58:50 -0700194 SkString filename = SkOSPath::SkBasename(inputPath.c_str());
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000195
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000196 gWriter.bench(filename.c_str(), picture->width(), picture->height());
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000197
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000198 benchmark.run(picture);
scroggo@google.comcc690202013-03-04 19:56:21 +0000199
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000200#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000201 if (FLAGS_trackDeferredCaching) {
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000202 int cacheHits = pool->getCacheHits();
203 int cacheMisses = pool->getCacheMisses();
204 pool->resetCacheHitsAndMisses();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000205 SkString hitString;
206 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
207 gLogger.logProgress(hitString);
scroggo@google.comcc690202013-03-04 19:56:21 +0000208 gTotalCacheHits += cacheHits;
209 gTotalCacheMisses += cacheMisses;
210 }
211#endif
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000212 if (FLAGS_countRAM) {
213 SkString ramCount("RAM used for bitmaps: ");
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000214 size_t bytes = pool->getRAMUsed();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000215 if (bytes > 1024) {
216 size_t kb = bytes / 1024;
217 if (kb > 1024) {
218 size_t mb = kb / 1024;
219 ramCount.appendf("%zi MB\n", mb);
220 } else {
221 ramCount.appendf("%zi KB\n", kb);
222 }
223 } else {
224 ramCount.appendf("%zi bytes\n", bytes);
225 }
226 gLogger.logProgress(ramCount);
227 }
scroggo@google.comcc690202013-03-04 19:56:21 +0000228
borenet@google.com66bcbd12012-09-17 18:26:06 +0000229 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000230}
231
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000232static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) {
caryclark@google.coma3622372012-11-06 21:26:13 +0000233 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount];
234 sk_bzero(drawFilters, sizeof(drawFilters));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000235
236 if (FLAGS_filter.count() > 0) {
237 const char* filters = FLAGS_filter[0];
238 const char* colon = strchr(filters, ':');
239 if (colon) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000240 int32_t type = -1;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000241 size_t typeLen = colon - filters;
242 for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) {
243 if (typeLen == strlen(gFilterTypes[tIndex])
244 && !strncmp(filters, gFilterTypes[tIndex], typeLen)) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000245 type = SkToS32(tIndex);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000246 break;
reed@google.com006db0f2012-06-27 19:33:29 +0000247 }
reed@google.com006db0f2012-06-27 19:33:29 +0000248 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000249 if (type < 0) {
junov@chromium.org9313ca42012-11-02 18:11:49 +0000250 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000251 err.printf("Unknown type for --filter %s\n", filters);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000252 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000253 exit(-1);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000254 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000255 int flag = -1;
256 size_t flagLen = strlen(filters) - typeLen - 1;
257 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
258 if (flagLen == strlen(gFilterFlags[fIndex])
259 && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) {
260 flag = 1 << fIndex;
261 break;
262 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000263 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000264 if (flag < 0) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000265 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000266 err.printf("Unknown flag for --filter %s\n", filters);
scroggo@google.com9a412522012-09-07 15:21:18 +0000267 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000268 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000269 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000270 for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) {
271 if (type != SkDrawFilter::kTypeCount && index != type) {
272 continue;
scroggo@google.com5239c322012-09-11 19:15:32 +0000273 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000274 drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags)
275 (drawFilters[index] | flag);
scroggo@google.com5239c322012-09-11 19:15:32 +0000276 }
reed@google.com006db0f2012-06-27 19:33:29 +0000277 } else {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000278 SkString err;
279 err.printf("Unknown arg for --filter %s : missing colon\n", filters);
280 gLogger.logError(err);
281 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000282 }
283 }
284
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000285 if (FLAGS_timers.count() > 0) {
286 size_t index = 0;
287 bool timerWall = false;
288 bool truncatedTimerWall = false;
289 bool timerCpu = false;
290 bool truncatedTimerCpu = false;
291 bool timerGpu = false;
292 while (index < strlen(FLAGS_timers[0])) {
293 switch (FLAGS_timers[0][index]) {
294 case 'w':
295 timerWall = true;
296 break;
297 case 'c':
298 timerCpu = true;
299 break;
300 case 'W':
301 truncatedTimerWall = true;
302 break;
303 case 'C':
304 truncatedTimerCpu = true;
305 break;
306 case 'g':
307 timerGpu = true;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000308 break;
309 default:
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000310 SkDebugf("mystery character\n");
scroggo@google.com0556ea02013-02-08 19:38:21 +0000311 break;
312 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000313 index++;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000314 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000315 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, truncatedTimerCpu,
316 timerGpu);
reed@google.com006db0f2012-06-27 19:33:29 +0000317 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000318
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000319 SkString errorString;
320 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
321 kBench_PictureTool));
322
323 if (errorString.size() > 0) {
324 gLogger.logError(errorString);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000325 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000326
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000327 if (NULL == renderer.get()) {
328 exit(-1);
329 }
330
331 if (FLAGS_timeIndividualTiles) {
332 if (FLAGS_multi > 1) {
333 gLogger.logError("Cannot time individual tiles with more than one thread.\n");
334 exit(-1);
335 }
336 sk_tools::TiledPictureRenderer* tiledRenderer = renderer->getTiledRenderer();
337 if (NULL == tiledRenderer) {
338 gLogger.logError("--timeIndividualTiles requires tiled rendering.\n");
339 exit(-1);
340 }
341 if (!tiledRenderer->supportsTimingIndividualTiles()) {
342 gLogger.logError("This renderer does not support --timeIndividualTiles.\n");
343 exit(-1);
344 }
345 benchmark->setTimeIndividualTiles(true);
346 }
347
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000348 benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex);
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +0000349 benchmark->setPreprocess(FLAGS_preprocess);
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000350
scroggo@google.com604e0c22013-04-09 21:25:46 +0000351 if (FLAGS_readPath.count() < 1) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000352 gLogger.logError(".skp files or directories are required.\n");
353 exit(-1);
354 }
355
caryclark@google.coma3622372012-11-06 21:26:13 +0000356 renderer->setDrawFilters(drawFilters, filtersName(drawFilters));
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +0000357 if (FLAGS_logPerIter) {
358 benchmark->setTimerResultType(TimerData::kPerIter_Result);
359 } else if (FLAGS_min) {
360 benchmark->setTimerResultType(TimerData::kMin_Result);
361 } else {
362 benchmark->setTimerResultType(TimerData::kAvg_Result);
363 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000364 benchmark->setRenderer(renderer);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000365 benchmark->setRepeats(FLAGS_repeat);
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000366 benchmark->setWriter(&gWriter);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000367}
reed@google.com006db0f2012-06-27 19:33:29 +0000368
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000369static int process_input(const char* input,
borenet@google.com66bcbd12012-09-17 18:26:06 +0000370 sk_tools::PictureBenchmark& benchmark) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000371 SkString inputAsSkString(input);
372 SkOSFile::Iter iter(input, "skp");
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000373 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000374 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000375 if (iter.next(&inputFilename)) {
376 do {
tfarinada4ed322014-06-12 08:50:56 -0700377 SkString inputPath = SkOSPath::SkPathJoin(input, inputFilename.c_str());
borenet@google.com57837bf2012-09-19 17:28:29 +0000378 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000379 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000380 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000381 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000382 } else if (SkStrEndsWith(input, ".skp")) {
383 if (!run_single_benchmark(inputAsSkString, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000384 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000385 }
386 } else {
387 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000388 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000389 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000390 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000391 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000392}
393
caryclark@google.com5987f582012-10-02 18:33:14 +0000394int tool_main(int argc, char** argv);
395int tool_main(int argc, char** argv) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000396 SkString usage;
397 usage.printf("Time drawing .skp files.\n"
398 "\tPossible arguments for --filter: [%s]\n\t\t[%s]",
399 filterTypesUsage().c_str(), filterFlagsUsage().c_str());
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000400 SkCommandLineFlags::SetUsage(usage.c_str());
401 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000402
403 if (FLAGS_repeat < 1) {
404 SkString error;
405 error.printf("--repeats must be >= 1. Was %i\n", FLAGS_repeat);
406 gLogger.logError(error);
407 exit(-1);
408 }
409
410 if (FLAGS_logFile.count() == 1) {
411 if (!gLogger.SetLogFile(FLAGS_logFile[0])) {
412 SkString str;
413 str.printf("Could not open %s for writing.\n", FLAGS_logFile[0]);
414 gLogger.logError(str);
415 // TODO(borenet): We're disabling this for now, due to
416 // write-protected Android devices. The very short-term
417 // solution is to ignore the fact that we have no log file.
418 //exit(-1);
419 }
420 }
421
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000422#ifdef SK_BUILD_JSON_WRITER
423 SkAutoTDelete<PictureJSONResultsWriter> jsonWriter;
424 if (FLAGS_jsonLog.count() == 1) {
425 jsonWriter.reset(SkNEW(PictureJSONResultsWriter(FLAGS_jsonLog[0])));
426 gWriter.add(jsonWriter.get());
427 }
428
429#endif
430 gWriter.add(&gLogWriter);
431
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000432
bsalomon@google.com4e230682013-01-15 20:37:04 +0000433#if SK_ENABLE_INST_COUNT
scroggo@google.com5239c322012-09-11 19:15:32 +0000434 gPrintInstCount = true;
435#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000436 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000437
scroggo@google.com5239c322012-09-11 19:15:32 +0000438 sk_tools::PictureBenchmark benchmark;
439
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000440 setup_benchmark(&benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000441
borenet@google.com66bcbd12012-09-17 18:26:06 +0000442 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000443 for (int i = 0; i < FLAGS_readPath.count(); ++i) {
444 failures += process_input(FLAGS_readPath[i], benchmark);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000445 }
446
447 if (failures != 0) {
448 SkString err;
449 err.printf("Failed to run %i benchmarks.\n", failures);
450 gLogger.logError(err);
451 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000452 }
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000453#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000454 if (FLAGS_trackDeferredCaching) {
455 SkDebugf("Total cache hit rate: %f\n",
456 (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses));
457 }
458#endif
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000459 gWriter.end();
caryclark@google.com868e1f62012-10-02 20:00:03 +0000460 return 0;
reed@google.com006db0f2012-06-27 19:33:29 +0000461}
caryclark@google.com5987f582012-10-02 18:33:14 +0000462
463#if !defined SK_BUILD_FOR_IOS
464int main(int argc, char * const argv[]) {
465 return tool_main(argc, (char**) argv);
466}
467#endif