blob: f6cd8e9bd7db7e201e54ad34d3681a94a52c2cb9 [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.coma560d00b2013-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).");
scroggo@google.com604e0c22013-04-09 21:25:46 +000045DECLARE_string(readPath);
scroggo@google.com161e1ba2013-03-04 16:41:06 +000046DEFINE_int32(repeat, 1, "Set the number of times to repeat each test.");
47DEFINE_bool(timeIndividualTiles, false, "Report times for drawing individual tiles, rather than "
48 "times for drawing the whole page. Requires tiled rendering.");
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000049DEFINE_bool(purgeDecodedTex, false, "Purge decoded and GPU-uploaded textures "
50 "after each iteration.");
scroggo@google.com65e508d2013-08-02 16:09:10 +000051DEFINE_string(timers, "c", "[wcgWC]*: Display wall, cpu, gpu, truncated wall or truncated cpu time"
scroggo@google.com161e1ba2013-03-04 16:41:06 +000052 " for each picture.");
scroggo@google.comcc690202013-03-04 19:56:21 +000053DEFINE_bool(trackDeferredCaching, false, "Only meaningful with --deferImageDecoding and "
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +000054 "SK_LAZY_CACHE_STATS set to true. Report percentage of cache hits when using "
55 "deferred image decoding.");
reed@google.com006db0f2012-06-27 19:33:29 +000056
commit-bot@chromium.orgba7aedd2014-05-23 01:02:21 +000057DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before timing.");
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +000058
kelvinly4d1a3642014-06-26 11:26:40 -070059// Buildbot-specific parameters
60DEFINE_string(builderName, "", "Name of the builder this is running on.");
61DEFINE_int32(buildNumber, -1, "Build number of the build this test is running on");
62DEFINE_int32(timestamp, 0, "Timestamp of the revision of Skia being tested.");
63DEFINE_string(gitHash, "", "Commit hash of the revision of Skia being run.");
64DEFINE_int32(gitNumber, -1, "Git number of the revision of Skia being run.");
65
66
caryclark@google.coma3622372012-11-06 21:26:13 +000067static char const * const gFilterTypes[] = {
68 "paint",
69 "point",
70 "line",
71 "bitmap",
72 "rect",
jvanverth@google.comd3c208c2013-01-22 13:54:52 +000073 "oval",
caryclark@google.coma3622372012-11-06 21:26:13 +000074 "path",
75 "text",
76 "all",
77};
78
79static const size_t kFilterTypesCount = sizeof(gFilterTypes) / sizeof(gFilterTypes[0]);
80
81static char const * const gFilterFlags[] = {
82 "antiAlias",
83 "filterBitmap",
84 "dither",
85 "underlineText",
86 "strikeThruText",
87 "fakeBoldText",
88 "linearText",
89 "subpixelText",
90 "devKernText",
91 "LCDRenderText",
92 "embeddedBitmapText",
93 "autoHinting",
94 "verticalText",
95 "genA8FromLCD",
96 "blur",
97 "hinting",
98 "slightHinting",
caryclark@google.come3e940c2012-11-07 16:42:17 +000099 "AAClip",
caryclark@google.coma3622372012-11-06 21:26:13 +0000100};
101
102static const size_t kFilterFlagsCount = sizeof(gFilterFlags) / sizeof(gFilterFlags[0]);
103
104static SkString filtersName(sk_tools::PictureRenderer::DrawFilterFlags* drawFilters) {
105 int all = drawFilters[0];
106 size_t tIndex;
107 for (tIndex = 1; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
108 all &= drawFilters[tIndex];
109 }
110 SkString result;
111 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
112 SkString types;
113 if (all & (1 << fIndex)) {
114 types = gFilterTypes[SkDrawFilter::kTypeCount];
115 } else {
116 for (tIndex = 0; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
117 if (drawFilters[tIndex] & (1 << fIndex)) {
118 types += gFilterTypes[tIndex];
119 }
120 }
121 }
122 if (!types.size()) {
123 continue;
124 }
125 result += "_";
126 result += types;
127 result += ".";
128 result += gFilterFlags[fIndex];
129 }
130 return result;
131}
132
133static SkString filterTypesUsage() {
134 SkString result;
135 for (size_t index = 0; index < kFilterTypesCount; ++index) {
136 result += gFilterTypes[index];
137 if (index < kFilterTypesCount - 1) {
138 result += " | ";
139 }
140 }
141 return result;
142}
143
144static SkString filterFlagsUsage() {
145 SkString result;
146 size_t len = 0;
147 for (size_t index = 0; index < kFilterFlagsCount; ++index) {
148 result += gFilterFlags[index];
149 if (result.size() - len >= 72) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000150 result += "\n\t\t";
caryclark@google.coma3622372012-11-06 21:26:13 +0000151 len = result.size();
152 }
153 if (index < kFilterFlagsCount - 1) {
154 result += " | ";
155 }
156 }
157 return result;
158}
159
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000160#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000161static int32_t gTotalCacheHits;
162static int32_t gTotalCacheMisses;
163#endif
164
borenet@google.com66bcbd12012-09-17 18:26:06 +0000165static bool run_single_benchmark(const SkString& inputPath,
keyar@chromium.org163b5672012-08-01 17:53:29 +0000166 sk_tools::PictureBenchmark& benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000167 SkFILEStream inputStream;
168
reed@google.com006db0f2012-06-27 19:33:29 +0000169 inputStream.setPath(inputPath.c_str());
170 if (!inputStream.isValid()) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000171 SkString err;
172 err.printf("Could not open file %s\n", inputPath.c_str());
173 gLogger.logError(err);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000174 return false;
reed@google.com006db0f2012-06-27 19:33:29 +0000175 }
176
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000177 SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000178 // Since the old picture has been deleted, all pixels should be cleared.
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000179 SkASSERT(pool->getRAMUsed() == 0);
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000180 if (FLAGS_countRAM) {
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000181 pool->setRAMBudget(SK_MaxU32);
182 // Set the limit to max, so all pixels will be kept
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000183 }
184
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000185 SkPicture::InstallPixelRefProc proc;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000186 if (FLAGS_deferImageDecoding) {
commit-bot@chromium.org56799e22013-07-16 18:21:46 +0000187 proc = &sk_tools::LazyDecodeBitmap;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000188 } else {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000189 proc = &SkImageDecoder::DecodeMemory;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000190 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000191 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, proc));
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000192
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000193 if (NULL == picture.get()) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000194 SkString err;
195 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
196 gLogger.logError(err);
197 return false;
198 }
reed@google.com006db0f2012-06-27 19:33:29 +0000199
tfarina1c99ea82014-06-11 08:58:50 -0700200 SkString filename = SkOSPath::SkBasename(inputPath.c_str());
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000201
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000202 gWriter.bench(filename.c_str(), picture->width(), picture->height());
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000203
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000204 benchmark.run(picture);
scroggo@google.comcc690202013-03-04 19:56:21 +0000205
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000206#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000207 if (FLAGS_trackDeferredCaching) {
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000208 int cacheHits = pool->getCacheHits();
209 int cacheMisses = pool->getCacheMisses();
210 pool->resetCacheHitsAndMisses();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000211 SkString hitString;
212 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
213 gLogger.logProgress(hitString);
scroggo@google.comcc690202013-03-04 19:56:21 +0000214 gTotalCacheHits += cacheHits;
215 gTotalCacheMisses += cacheMisses;
216 }
217#endif
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000218 if (FLAGS_countRAM) {
219 SkString ramCount("RAM used for bitmaps: ");
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000220 size_t bytes = pool->getRAMUsed();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000221 if (bytes > 1024) {
222 size_t kb = bytes / 1024;
223 if (kb > 1024) {
224 size_t mb = kb / 1024;
225 ramCount.appendf("%zi MB\n", mb);
226 } else {
227 ramCount.appendf("%zi KB\n", kb);
228 }
229 } else {
230 ramCount.appendf("%zi bytes\n", bytes);
231 }
232 gLogger.logProgress(ramCount);
233 }
scroggo@google.comcc690202013-03-04 19:56:21 +0000234
borenet@google.com66bcbd12012-09-17 18:26:06 +0000235 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000236}
237
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000238static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) {
caryclark@google.coma3622372012-11-06 21:26:13 +0000239 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount];
240 sk_bzero(drawFilters, sizeof(drawFilters));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000241
242 if (FLAGS_filter.count() > 0) {
243 const char* filters = FLAGS_filter[0];
244 const char* colon = strchr(filters, ':');
245 if (colon) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000246 int32_t type = -1;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000247 size_t typeLen = colon - filters;
248 for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) {
249 if (typeLen == strlen(gFilterTypes[tIndex])
250 && !strncmp(filters, gFilterTypes[tIndex], typeLen)) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000251 type = SkToS32(tIndex);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000252 break;
reed@google.com006db0f2012-06-27 19:33:29 +0000253 }
reed@google.com006db0f2012-06-27 19:33:29 +0000254 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000255 if (type < 0) {
junov@chromium.org9313ca42012-11-02 18:11:49 +0000256 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000257 err.printf("Unknown type for --filter %s\n", filters);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000258 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000259 exit(-1);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000260 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000261 int flag = -1;
262 size_t flagLen = strlen(filters) - typeLen - 1;
263 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
264 if (flagLen == strlen(gFilterFlags[fIndex])
265 && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) {
266 flag = 1 << fIndex;
267 break;
268 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000269 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000270 if (flag < 0) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000271 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000272 err.printf("Unknown flag for --filter %s\n", filters);
scroggo@google.com9a412522012-09-07 15:21:18 +0000273 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000274 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000275 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000276 for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) {
277 if (type != SkDrawFilter::kTypeCount && index != type) {
278 continue;
scroggo@google.com5239c322012-09-11 19:15:32 +0000279 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000280 drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags)
281 (drawFilters[index] | flag);
scroggo@google.com5239c322012-09-11 19:15:32 +0000282 }
reed@google.com006db0f2012-06-27 19:33:29 +0000283 } else {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000284 SkString err;
285 err.printf("Unknown arg for --filter %s : missing colon\n", filters);
286 gLogger.logError(err);
287 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000288 }
289 }
290
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000291 if (FLAGS_timers.count() > 0) {
292 size_t index = 0;
293 bool timerWall = false;
294 bool truncatedTimerWall = false;
295 bool timerCpu = false;
296 bool truncatedTimerCpu = false;
297 bool timerGpu = false;
298 while (index < strlen(FLAGS_timers[0])) {
299 switch (FLAGS_timers[0][index]) {
300 case 'w':
301 timerWall = true;
302 break;
303 case 'c':
304 timerCpu = true;
305 break;
306 case 'W':
307 truncatedTimerWall = true;
308 break;
309 case 'C':
310 truncatedTimerCpu = true;
311 break;
312 case 'g':
313 timerGpu = true;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000314 break;
315 default:
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000316 SkDebugf("mystery character\n");
scroggo@google.com0556ea02013-02-08 19:38:21 +0000317 break;
318 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000319 index++;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000320 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000321 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, truncatedTimerCpu,
322 timerGpu);
reed@google.com006db0f2012-06-27 19:33:29 +0000323 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000324
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000325 SkString errorString;
326 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
327 kBench_PictureTool));
328
329 if (errorString.size() > 0) {
330 gLogger.logError(errorString);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000331 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000332
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000333 if (NULL == renderer.get()) {
334 exit(-1);
335 }
336
337 if (FLAGS_timeIndividualTiles) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000338 sk_tools::TiledPictureRenderer* tiledRenderer = renderer->getTiledRenderer();
339 if (NULL == tiledRenderer) {
340 gLogger.logError("--timeIndividualTiles requires tiled rendering.\n");
341 exit(-1);
342 }
343 if (!tiledRenderer->supportsTimingIndividualTiles()) {
344 gLogger.logError("This renderer does not support --timeIndividualTiles.\n");
345 exit(-1);
346 }
347 benchmark->setTimeIndividualTiles(true);
348 }
349
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000350 benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex);
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +0000351 benchmark->setPreprocess(FLAGS_preprocess);
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000352
scroggo@google.com604e0c22013-04-09 21:25:46 +0000353 if (FLAGS_readPath.count() < 1) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000354 gLogger.logError(".skp files or directories are required.\n");
355 exit(-1);
356 }
357
caryclark@google.coma3622372012-11-06 21:26:13 +0000358 renderer->setDrawFilters(drawFilters, filtersName(drawFilters));
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +0000359 if (FLAGS_logPerIter) {
360 benchmark->setTimerResultType(TimerData::kPerIter_Result);
361 } else if (FLAGS_min) {
362 benchmark->setTimerResultType(TimerData::kMin_Result);
363 } else {
364 benchmark->setTimerResultType(TimerData::kAvg_Result);
365 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000366 benchmark->setRenderer(renderer);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000367 benchmark->setRepeats(FLAGS_repeat);
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000368 benchmark->setWriter(&gWriter);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000369}
reed@google.com006db0f2012-06-27 19:33:29 +0000370
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000371static int process_input(const char* input,
borenet@google.com66bcbd12012-09-17 18:26:06 +0000372 sk_tools::PictureBenchmark& benchmark) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000373 SkString inputAsSkString(input);
374 SkOSFile::Iter iter(input, "skp");
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000375 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000376 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000377 if (iter.next(&inputFilename)) {
378 do {
tfarinada4ed322014-06-12 08:50:56 -0700379 SkString inputPath = SkOSPath::SkPathJoin(input, inputFilename.c_str());
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) {
mtklein30e6e2a2014-06-18 11:44:15 -0700398 SetupCrashHandler();
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000399 SkString usage;
400 usage.printf("Time drawing .skp files.\n"
401 "\tPossible arguments for --filter: [%s]\n\t\t[%s]",
402 filterTypesUsage().c_str(), filterFlagsUsage().c_str());
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000403 SkCommandLineFlags::SetUsage(usage.c_str());
404 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000405
406 if (FLAGS_repeat < 1) {
407 SkString error;
408 error.printf("--repeats must be >= 1. Was %i\n", FLAGS_repeat);
409 gLogger.logError(error);
410 exit(-1);
411 }
412
413 if (FLAGS_logFile.count() == 1) {
414 if (!gLogger.SetLogFile(FLAGS_logFile[0])) {
415 SkString str;
416 str.printf("Could not open %s for writing.\n", FLAGS_logFile[0]);
417 gLogger.logError(str);
418 // TODO(borenet): We're disabling this for now, due to
419 // write-protected Android devices. The very short-term
420 // solution is to ignore the fact that we have no log file.
421 //exit(-1);
422 }
423 }
424
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000425 SkAutoTDelete<PictureJSONResultsWriter> jsonWriter;
426 if (FLAGS_jsonLog.count() == 1) {
kelvinly4d1a3642014-06-26 11:26:40 -0700427 SkASSERT(FLAGS_builderName.count() == 1 && FLAGS_gitHash.count() == 1);
428 jsonWriter.reset(SkNEW(PictureJSONResultsWriter(
429 FLAGS_jsonLog[0],
430 FLAGS_builderName[0],
431 FLAGS_buildNumber,
432 FLAGS_timestamp,
433 FLAGS_gitHash[0],
434 FLAGS_gitNumber)));
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000435 gWriter.add(jsonWriter.get());
436 }
437
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000438 gWriter.add(&gLogWriter);
439
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000440
bsalomon@google.com4e230682013-01-15 20:37:04 +0000441#if SK_ENABLE_INST_COUNT
scroggo@google.com5239c322012-09-11 19:15:32 +0000442 gPrintInstCount = true;
443#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000444 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000445
scroggo@google.com5239c322012-09-11 19:15:32 +0000446 sk_tools::PictureBenchmark benchmark;
447
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000448 setup_benchmark(&benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000449
borenet@google.com66bcbd12012-09-17 18:26:06 +0000450 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000451 for (int i = 0; i < FLAGS_readPath.count(); ++i) {
452 failures += process_input(FLAGS_readPath[i], benchmark);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000453 }
454
455 if (failures != 0) {
456 SkString err;
457 err.printf("Failed to run %i benchmarks.\n", failures);
458 gLogger.logError(err);
459 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000460 }
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000461#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000462 if (FLAGS_trackDeferredCaching) {
463 SkDebugf("Total cache hit rate: %f\n",
464 (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses));
465 }
466#endif
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000467 gWriter.end();
caryclark@google.com868e1f62012-10-02 20:00:03 +0000468 return 0;
reed@google.com006db0f2012-06-27 19:33:29 +0000469}
caryclark@google.com5987f582012-10-02 18:33:14 +0000470
471#if !defined SK_BUILD_FOR_IOS
472int main(int argc, char * const argv[]) {
473 return tool_main(argc, (char**) argv);
474}
475#endif