blob: 503269af6a7c8a3e3bfb5388eb6de6c8c4782293 [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
tfarinaf168b862014-06-19 12:32:29 -07008#include "BenchLogger.h"
mtklein9ac68ee2014-06-20 11:29:20 -07009#include "Timer.h"
scroggo@google.com4a26d9d2012-11-07 18:01:46 +000010#include "CopyTilesRenderer.h"
tfarinaf168b862014-06-19 12:32:29 -070011#include "CrashHandler.h"
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000012#include "LazyDecodeBitmap.h"
keyar@chromium.org163b5672012-08-01 17:53:29 +000013#include "PictureBenchmark.h"
scroggo@google.com161e1ba2013-03-04 16:41:06 +000014#include "PictureRenderingFlags.h"
tfarinaf168b862014-06-19 12:32:29 -070015#include "PictureResultsWriter.h"
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000016#include "SkCommandLineFlags.h"
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000017#include "SkData.h"
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000018#include "SkDiscardableMemoryPool.h"
scroggo@google.com0a36f432012-09-10 20:29:13 +000019#include "SkGraphics.h"
scroggo@google.com5a7c6be2012-10-04 21:46:08 +000020#include "SkImageDecoder.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000021#include "SkMath.h"
reed@google.com006db0f2012-06-27 19:33:29 +000022#include "SkOSFile.h"
23#include "SkPicture.h"
24#include "SkStream.h"
reed@google.com006db0f2012-06-27 19:33:29 +000025#include "picture_utils.h"
26
tfarinaf168b862014-06-19 12:32:29 -070027BenchLogger gLogger;
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000028PictureResultsLoggerWriter gLogWriter(&gLogger);
29PictureResultsMultiWriter gWriter;
scroggo@google.com161e1ba2013-03-04 16:41:06 +000030
31// Flags used by this file, in alphabetical order.
scroggo@google.coma560d002013-03-04 21:32:32 +000032DEFINE_bool(countRAM, false, "Count the RAM used for bitmap pixels in each skp file");
scroggo@google.com161e1ba2013-03-04 16:41:06 +000033DECLARE_bool(deferImageDecoding);
34DEFINE_string(filter, "",
35 "type:flag : Enable canvas filtering to disable a paint flag, "
36 "use no blur or low quality blur, or use no hinting or "
37 "slight hinting. For all flags except AAClip, specify the "
38 "type of primitive to effect, or choose all. for AAClip "
39 "alone, the filter affects all clips independent of type. "
40 "Specific flags are listed above.");
41DEFINE_string(logFile, "", "Destination for writing log output, in addition to stdout.");
42DEFINE_bool(logPerIter, false, "Log each repeat timer instead of mean.");
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000043DEFINE_string(jsonLog, "", "Destination for writing JSON data.");
scroggo@google.com161e1ba2013-03-04 16:41:06 +000044DEFINE_bool(min, false, "Print the minimum times (instead of average).");
45DECLARE_int32(multi);
scroggo@google.com604e0c22013-04-09 21:25:46 +000046DECLARE_string(readPath);
scroggo@google.com161e1ba2013-03-04 16:41:06 +000047DEFINE_int32(repeat, 1, "Set the number of times to repeat each test.");
48DEFINE_bool(timeIndividualTiles, false, "Report times for drawing individual tiles, rather than "
49 "times for drawing the whole page. Requires tiled rendering.");
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000050DEFINE_bool(purgeDecodedTex, false, "Purge decoded and GPU-uploaded textures "
51 "after each iteration.");
scroggo@google.com65e508d2013-08-02 16:09:10 +000052DEFINE_string(timers, "c", "[wcgWC]*: Display wall, cpu, gpu, truncated wall or truncated cpu time"
scroggo@google.com161e1ba2013-03-04 16:41:06 +000053 " for each picture.");
scroggo@google.comcc690202013-03-04 19:56:21 +000054DEFINE_bool(trackDeferredCaching, false, "Only meaningful with --deferImageDecoding and "
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +000055 "SK_LAZY_CACHE_STATS set to true. Report percentage of cache hits when using "
56 "deferred image decoding.");
reed@google.com006db0f2012-06-27 19:33:29 +000057
commit-bot@chromium.orgba7aedd2014-05-23 01:02:21 +000058DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before timing.");
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +000059
caryclark@google.coma3622372012-11-06 21:26:13 +000060static char const * const gFilterTypes[] = {
61 "paint",
62 "point",
63 "line",
64 "bitmap",
65 "rect",
jvanverth@google.comd3c208c2013-01-22 13:54:52 +000066 "oval",
caryclark@google.coma3622372012-11-06 21:26:13 +000067 "path",
68 "text",
69 "all",
70};
71
72static const size_t kFilterTypesCount = sizeof(gFilterTypes) / sizeof(gFilterTypes[0]);
73
74static char const * const gFilterFlags[] = {
75 "antiAlias",
76 "filterBitmap",
77 "dither",
78 "underlineText",
79 "strikeThruText",
80 "fakeBoldText",
81 "linearText",
82 "subpixelText",
83 "devKernText",
84 "LCDRenderText",
85 "embeddedBitmapText",
86 "autoHinting",
87 "verticalText",
88 "genA8FromLCD",
89 "blur",
90 "hinting",
91 "slightHinting",
caryclark@google.come3e940c2012-11-07 16:42:17 +000092 "AAClip",
caryclark@google.coma3622372012-11-06 21:26:13 +000093};
94
95static const size_t kFilterFlagsCount = sizeof(gFilterFlags) / sizeof(gFilterFlags[0]);
96
97static SkString filtersName(sk_tools::PictureRenderer::DrawFilterFlags* drawFilters) {
98 int all = drawFilters[0];
99 size_t tIndex;
100 for (tIndex = 1; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
101 all &= drawFilters[tIndex];
102 }
103 SkString result;
104 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
105 SkString types;
106 if (all & (1 << fIndex)) {
107 types = gFilterTypes[SkDrawFilter::kTypeCount];
108 } else {
109 for (tIndex = 0; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
110 if (drawFilters[tIndex] & (1 << fIndex)) {
111 types += gFilterTypes[tIndex];
112 }
113 }
114 }
115 if (!types.size()) {
116 continue;
117 }
118 result += "_";
119 result += types;
120 result += ".";
121 result += gFilterFlags[fIndex];
122 }
123 return result;
124}
125
126static SkString filterTypesUsage() {
127 SkString result;
128 for (size_t index = 0; index < kFilterTypesCount; ++index) {
129 result += gFilterTypes[index];
130 if (index < kFilterTypesCount - 1) {
131 result += " | ";
132 }
133 }
134 return result;
135}
136
137static SkString filterFlagsUsage() {
138 SkString result;
139 size_t len = 0;
140 for (size_t index = 0; index < kFilterFlagsCount; ++index) {
141 result += gFilterFlags[index];
142 if (result.size() - len >= 72) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000143 result += "\n\t\t";
caryclark@google.coma3622372012-11-06 21:26:13 +0000144 len = result.size();
145 }
146 if (index < kFilterFlagsCount - 1) {
147 result += " | ";
148 }
149 }
150 return result;
151}
152
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000153#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000154static int32_t gTotalCacheHits;
155static int32_t gTotalCacheMisses;
156#endif
157
borenet@google.com66bcbd12012-09-17 18:26:06 +0000158static bool run_single_benchmark(const SkString& inputPath,
keyar@chromium.org163b5672012-08-01 17:53:29 +0000159 sk_tools::PictureBenchmark& benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000160 SkFILEStream inputStream;
161
reed@google.com006db0f2012-06-27 19:33:29 +0000162 inputStream.setPath(inputPath.c_str());
163 if (!inputStream.isValid()) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000164 SkString err;
165 err.printf("Could not open file %s\n", inputPath.c_str());
166 gLogger.logError(err);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000167 return false;
reed@google.com006db0f2012-06-27 19:33:29 +0000168 }
169
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000170 SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool();
scroggo@google.coma560d002013-03-04 21:32:32 +0000171 // Since the old picture has been deleted, all pixels should be cleared.
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000172 SkASSERT(pool->getRAMUsed() == 0);
scroggo@google.coma560d002013-03-04 21:32:32 +0000173 if (FLAGS_countRAM) {
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000174 pool->setRAMBudget(SK_MaxU32);
175 // Set the limit to max, so all pixels will be kept
scroggo@google.coma560d002013-03-04 21:32:32 +0000176 }
177
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000178 SkPicture::InstallPixelRefProc proc;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000179 if (FLAGS_deferImageDecoding) {
commit-bot@chromium.org56799e22013-07-16 18:21:46 +0000180 proc = &sk_tools::LazyDecodeBitmap;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000181 } else {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000182 proc = &SkImageDecoder::DecodeMemory;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000183 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000184 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, proc));
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000185
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000186 if (NULL == picture.get()) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000187 SkString err;
188 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
189 gLogger.logError(err);
190 return false;
191 }
reed@google.com006db0f2012-06-27 19:33:29 +0000192
tfarina1c99ea82014-06-11 08:58:50 -0700193 SkString filename = SkOSPath::SkBasename(inputPath.c_str());
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000194
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000195 gWriter.bench(filename.c_str(), picture->width(), picture->height());
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000196
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000197 benchmark.run(picture);
scroggo@google.comcc690202013-03-04 19:56:21 +0000198
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000199#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000200 if (FLAGS_trackDeferredCaching) {
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000201 int cacheHits = pool->getCacheHits();
202 int cacheMisses = pool->getCacheMisses();
203 pool->resetCacheHitsAndMisses();
scroggo@google.coma560d002013-03-04 21:32:32 +0000204 SkString hitString;
205 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
206 gLogger.logProgress(hitString);
scroggo@google.comcc690202013-03-04 19:56:21 +0000207 gTotalCacheHits += cacheHits;
208 gTotalCacheMisses += cacheMisses;
209 }
210#endif
scroggo@google.coma560d002013-03-04 21:32:32 +0000211 if (FLAGS_countRAM) {
212 SkString ramCount("RAM used for bitmaps: ");
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000213 size_t bytes = pool->getRAMUsed();
scroggo@google.coma560d002013-03-04 21:32:32 +0000214 if (bytes > 1024) {
215 size_t kb = bytes / 1024;
216 if (kb > 1024) {
217 size_t mb = kb / 1024;
218 ramCount.appendf("%zi MB\n", mb);
219 } else {
220 ramCount.appendf("%zi KB\n", kb);
221 }
222 } else {
223 ramCount.appendf("%zi bytes\n", bytes);
224 }
225 gLogger.logProgress(ramCount);
226 }
scroggo@google.comcc690202013-03-04 19:56:21 +0000227
borenet@google.com66bcbd12012-09-17 18:26:06 +0000228 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000229}
230
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000231static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) {
caryclark@google.coma3622372012-11-06 21:26:13 +0000232 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount];
233 sk_bzero(drawFilters, sizeof(drawFilters));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000234
235 if (FLAGS_filter.count() > 0) {
236 const char* filters = FLAGS_filter[0];
237 const char* colon = strchr(filters, ':');
238 if (colon) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000239 int32_t type = -1;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000240 size_t typeLen = colon - filters;
241 for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) {
242 if (typeLen == strlen(gFilterTypes[tIndex])
243 && !strncmp(filters, gFilterTypes[tIndex], typeLen)) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000244 type = SkToS32(tIndex);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000245 break;
reed@google.com006db0f2012-06-27 19:33:29 +0000246 }
reed@google.com006db0f2012-06-27 19:33:29 +0000247 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000248 if (type < 0) {
junov@chromium.org9313ca42012-11-02 18:11:49 +0000249 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000250 err.printf("Unknown type for --filter %s\n", filters);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000251 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000252 exit(-1);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000253 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000254 int flag = -1;
255 size_t flagLen = strlen(filters) - typeLen - 1;
256 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
257 if (flagLen == strlen(gFilterFlags[fIndex])
258 && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) {
259 flag = 1 << fIndex;
260 break;
261 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000262 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000263 if (flag < 0) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000264 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000265 err.printf("Unknown flag for --filter %s\n", filters);
scroggo@google.com9a412522012-09-07 15:21:18 +0000266 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000267 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000268 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000269 for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) {
270 if (type != SkDrawFilter::kTypeCount && index != type) {
271 continue;
scroggo@google.com5239c322012-09-11 19:15:32 +0000272 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000273 drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags)
274 (drawFilters[index] | flag);
scroggo@google.com5239c322012-09-11 19:15:32 +0000275 }
reed@google.com006db0f2012-06-27 19:33:29 +0000276 } else {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000277 SkString err;
278 err.printf("Unknown arg for --filter %s : missing colon\n", filters);
279 gLogger.logError(err);
280 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000281 }
282 }
283
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000284 if (FLAGS_timers.count() > 0) {
285 size_t index = 0;
286 bool timerWall = false;
287 bool truncatedTimerWall = false;
288 bool timerCpu = false;
289 bool truncatedTimerCpu = false;
290 bool timerGpu = false;
291 while (index < strlen(FLAGS_timers[0])) {
292 switch (FLAGS_timers[0][index]) {
293 case 'w':
294 timerWall = true;
295 break;
296 case 'c':
297 timerCpu = true;
298 break;
299 case 'W':
300 truncatedTimerWall = true;
301 break;
302 case 'C':
303 truncatedTimerCpu = true;
304 break;
305 case 'g':
306 timerGpu = true;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000307 break;
308 default:
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000309 SkDebugf("mystery character\n");
scroggo@google.com0556ea02013-02-08 19:38:21 +0000310 break;
311 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000312 index++;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000313 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000314 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, truncatedTimerCpu,
315 timerGpu);
reed@google.com006db0f2012-06-27 19:33:29 +0000316 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000317
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000318 SkString errorString;
319 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
320 kBench_PictureTool));
321
322 if (errorString.size() > 0) {
323 gLogger.logError(errorString);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000324 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000325
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000326 if (NULL == renderer.get()) {
327 exit(-1);
328 }
329
330 if (FLAGS_timeIndividualTiles) {
331 if (FLAGS_multi > 1) {
332 gLogger.logError("Cannot time individual tiles with more than one thread.\n");
333 exit(-1);
334 }
335 sk_tools::TiledPictureRenderer* tiledRenderer = renderer->getTiledRenderer();
336 if (NULL == tiledRenderer) {
337 gLogger.logError("--timeIndividualTiles requires tiled rendering.\n");
338 exit(-1);
339 }
340 if (!tiledRenderer->supportsTimingIndividualTiles()) {
341 gLogger.logError("This renderer does not support --timeIndividualTiles.\n");
342 exit(-1);
343 }
344 benchmark->setTimeIndividualTiles(true);
345 }
346
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000347 benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex);
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +0000348 benchmark->setPreprocess(FLAGS_preprocess);
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000349
scroggo@google.com604e0c22013-04-09 21:25:46 +0000350 if (FLAGS_readPath.count() < 1) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000351 gLogger.logError(".skp files or directories are required.\n");
352 exit(-1);
353 }
354
caryclark@google.coma3622372012-11-06 21:26:13 +0000355 renderer->setDrawFilters(drawFilters, filtersName(drawFilters));
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +0000356 if (FLAGS_logPerIter) {
357 benchmark->setTimerResultType(TimerData::kPerIter_Result);
358 } else if (FLAGS_min) {
359 benchmark->setTimerResultType(TimerData::kMin_Result);
360 } else {
361 benchmark->setTimerResultType(TimerData::kAvg_Result);
362 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000363 benchmark->setRenderer(renderer);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000364 benchmark->setRepeats(FLAGS_repeat);
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000365 benchmark->setWriter(&gWriter);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000366}
reed@google.com006db0f2012-06-27 19:33:29 +0000367
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000368static int process_input(const char* input,
borenet@google.com66bcbd12012-09-17 18:26:06 +0000369 sk_tools::PictureBenchmark& benchmark) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000370 SkString inputAsSkString(input);
371 SkOSFile::Iter iter(input, "skp");
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000372 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000373 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000374 if (iter.next(&inputFilename)) {
375 do {
tfarinada4ed322014-06-12 08:50:56 -0700376 SkString inputPath = SkOSPath::SkPathJoin(input, inputFilename.c_str());
borenet@google.com57837bf2012-09-19 17:28:29 +0000377 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000378 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000379 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000380 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000381 } else if (SkStrEndsWith(input, ".skp")) {
382 if (!run_single_benchmark(inputAsSkString, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000383 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000384 }
385 } else {
386 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000387 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000388 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000389 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000390 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000391}
392
caryclark@google.com5987f582012-10-02 18:33:14 +0000393int tool_main(int argc, char** argv);
394int tool_main(int argc, char** argv) {
mtklein30e6e2a2014-06-18 11:44:15 -0700395 SetupCrashHandler();
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 SkAutoTDelete<PictureJSONResultsWriter> jsonWriter;
423 if (FLAGS_jsonLog.count() == 1) {
424 jsonWriter.reset(SkNEW(PictureJSONResultsWriter(FLAGS_jsonLog[0])));
425 gWriter.add(jsonWriter.get());
426 }
427
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000428 gWriter.add(&gLogWriter);
429
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000430
bsalomon@google.com4e230682013-01-15 20:37:04 +0000431#if SK_ENABLE_INST_COUNT
scroggo@google.com5239c322012-09-11 19:15:32 +0000432 gPrintInstCount = true;
433#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000434 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000435
scroggo@google.com5239c322012-09-11 19:15:32 +0000436 sk_tools::PictureBenchmark benchmark;
437
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000438 setup_benchmark(&benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000439
borenet@google.com66bcbd12012-09-17 18:26:06 +0000440 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000441 for (int i = 0; i < FLAGS_readPath.count(); ++i) {
442 failures += process_input(FLAGS_readPath[i], benchmark);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000443 }
444
445 if (failures != 0) {
446 SkString err;
447 err.printf("Failed to run %i benchmarks.\n", failures);
448 gLogger.logError(err);
449 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000450 }
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000451#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000452 if (FLAGS_trackDeferredCaching) {
453 SkDebugf("Total cache hit rate: %f\n",
454 (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses));
455 }
456#endif
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000457 gWriter.end();
caryclark@google.com868e1f62012-10-02 20:00:03 +0000458 return 0;
reed@google.com006db0f2012-06-27 19:33:29 +0000459}
caryclark@google.com5987f582012-10-02 18:33:14 +0000460
461#if !defined SK_BUILD_FOR_IOS
462int main(int argc, char * const argv[]) {
463 return tool_main(argc, (char**) argv);
464}
465#endif