blob: ade93fc3e6f05108df5aa8695818d41b929269cf [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
robertphillips754f4e92014-09-18 13:52:08 -070057#if GR_GPU_STATS
58DEFINE_bool(gpuStats, false, "Only meaningful with gpu configurations. "
59 "Report some GPU call statistics.");
60#endif
61
commit-bot@chromium.orgba7aedd2014-05-23 01:02:21 +000062DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before timing.");
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +000063
kelvinly4d1a3642014-06-26 11:26:40 -070064// Buildbot-specific parameters
65DEFINE_string(builderName, "", "Name of the builder this is running on.");
66DEFINE_int32(buildNumber, -1, "Build number of the build this test is running on");
67DEFINE_int32(timestamp, 0, "Timestamp of the revision of Skia being tested.");
68DEFINE_string(gitHash, "", "Commit hash of the revision of Skia being run.");
69DEFINE_int32(gitNumber, -1, "Git number of the revision of Skia being run.");
70
71
caryclark@google.coma3622372012-11-06 21:26:13 +000072static char const * const gFilterTypes[] = {
73 "paint",
74 "point",
75 "line",
76 "bitmap",
77 "rect",
jvanverth@google.comd3c208c2013-01-22 13:54:52 +000078 "oval",
caryclark@google.coma3622372012-11-06 21:26:13 +000079 "path",
80 "text",
81 "all",
82};
83
84static const size_t kFilterTypesCount = sizeof(gFilterTypes) / sizeof(gFilterTypes[0]);
85
86static char const * const gFilterFlags[] = {
87 "antiAlias",
88 "filterBitmap",
89 "dither",
90 "underlineText",
91 "strikeThruText",
92 "fakeBoldText",
93 "linearText",
94 "subpixelText",
95 "devKernText",
96 "LCDRenderText",
97 "embeddedBitmapText",
98 "autoHinting",
99 "verticalText",
100 "genA8FromLCD",
101 "blur",
102 "hinting",
103 "slightHinting",
caryclark@google.come3e940c2012-11-07 16:42:17 +0000104 "AAClip",
caryclark@google.coma3622372012-11-06 21:26:13 +0000105};
106
107static const size_t kFilterFlagsCount = sizeof(gFilterFlags) / sizeof(gFilterFlags[0]);
108
109static SkString filtersName(sk_tools::PictureRenderer::DrawFilterFlags* drawFilters) {
110 int all = drawFilters[0];
111 size_t tIndex;
112 for (tIndex = 1; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
113 all &= drawFilters[tIndex];
114 }
115 SkString result;
116 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
117 SkString types;
118 if (all & (1 << fIndex)) {
119 types = gFilterTypes[SkDrawFilter::kTypeCount];
120 } else {
121 for (tIndex = 0; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
122 if (drawFilters[tIndex] & (1 << fIndex)) {
123 types += gFilterTypes[tIndex];
124 }
125 }
126 }
127 if (!types.size()) {
128 continue;
129 }
130 result += "_";
131 result += types;
132 result += ".";
133 result += gFilterFlags[fIndex];
134 }
135 return result;
136}
137
138static SkString filterTypesUsage() {
139 SkString result;
140 for (size_t index = 0; index < kFilterTypesCount; ++index) {
141 result += gFilterTypes[index];
142 if (index < kFilterTypesCount - 1) {
143 result += " | ";
144 }
145 }
146 return result;
147}
148
149static SkString filterFlagsUsage() {
150 SkString result;
151 size_t len = 0;
152 for (size_t index = 0; index < kFilterFlagsCount; ++index) {
153 result += gFilterFlags[index];
154 if (result.size() - len >= 72) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000155 result += "\n\t\t";
caryclark@google.coma3622372012-11-06 21:26:13 +0000156 len = result.size();
157 }
158 if (index < kFilterFlagsCount - 1) {
159 result += " | ";
160 }
161 }
162 return result;
163}
164
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000165#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000166static int32_t gTotalCacheHits;
167static int32_t gTotalCacheMisses;
168#endif
169
borenet@google.com66bcbd12012-09-17 18:26:06 +0000170static bool run_single_benchmark(const SkString& inputPath,
keyar@chromium.org163b5672012-08-01 17:53:29 +0000171 sk_tools::PictureBenchmark& benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000172 SkFILEStream inputStream;
173
reed@google.com006db0f2012-06-27 19:33:29 +0000174 inputStream.setPath(inputPath.c_str());
175 if (!inputStream.isValid()) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000176 SkString err;
177 err.printf("Could not open file %s\n", inputPath.c_str());
178 gLogger.logError(err);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000179 return false;
reed@google.com006db0f2012-06-27 19:33:29 +0000180 }
181
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000182 SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000183 // Since the old picture has been deleted, all pixels should be cleared.
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000184 SkASSERT(pool->getRAMUsed() == 0);
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000185 if (FLAGS_countRAM) {
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000186 pool->setRAMBudget(SK_MaxU32);
187 // Set the limit to max, so all pixels will be kept
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000188 }
189
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000190 SkPicture::InstallPixelRefProc proc;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000191 if (FLAGS_deferImageDecoding) {
commit-bot@chromium.org56799e22013-07-16 18:21:46 +0000192 proc = &sk_tools::LazyDecodeBitmap;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000193 } else {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000194 proc = &SkImageDecoder::DecodeMemory;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000195 }
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000196 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, proc));
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000197
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000198 if (NULL == picture.get()) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000199 SkString err;
200 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
201 gLogger.logError(err);
202 return false;
203 }
reed@google.com006db0f2012-06-27 19:33:29 +0000204
robertphillipse9470752014-08-12 10:12:40 -0700205 if (FLAGS_preprocess) {
206 // Because the GPU preprocessing step relies on the in-memory picture
207 // statistics we need to rerecord the picture here
208 SkPictureRecorder recorder;
robertphillipsc5ba71d2014-09-04 08:42:50 -0700209 picture->playback(recorder.beginRecording(picture->cullRect().width(),
210 picture->cullRect().height(),
211 NULL, 0));
robertphillipse9470752014-08-12 10:12:40 -0700212 picture.reset(recorder.endRecording());
213 }
214
tfarinaa8e2e152014-07-28 19:26:58 -0700215 SkString filename = SkOSPath::Basename(inputPath.c_str());
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000216
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700217 gWriter.bench(filename.c_str(),
218 SkScalarCeilToInt(picture->cullRect().width()),
219 SkScalarCeilToInt(picture->cullRect().height()));
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000220
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000221 benchmark.run(picture);
scroggo@google.comcc690202013-03-04 19:56:21 +0000222
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000223#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000224 if (FLAGS_trackDeferredCaching) {
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000225 int cacheHits = pool->getCacheHits();
226 int cacheMisses = pool->getCacheMisses();
227 pool->resetCacheHitsAndMisses();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000228 SkString hitString;
229 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
230 gLogger.logProgress(hitString);
scroggo@google.comcc690202013-03-04 19:56:21 +0000231 gTotalCacheHits += cacheHits;
232 gTotalCacheMisses += cacheMisses;
233 }
234#endif
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000235 if (FLAGS_countRAM) {
236 SkString ramCount("RAM used for bitmaps: ");
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +0000237 size_t bytes = pool->getRAMUsed();
scroggo@google.coma560d00b2013-03-04 21:32:32 +0000238 if (bytes > 1024) {
239 size_t kb = bytes / 1024;
240 if (kb > 1024) {
241 size_t mb = kb / 1024;
242 ramCount.appendf("%zi MB\n", mb);
243 } else {
244 ramCount.appendf("%zi KB\n", kb);
245 }
246 } else {
247 ramCount.appendf("%zi bytes\n", bytes);
248 }
249 gLogger.logProgress(ramCount);
250 }
scroggo@google.comcc690202013-03-04 19:56:21 +0000251
borenet@google.com66bcbd12012-09-17 18:26:06 +0000252 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000253}
254
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000255static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) {
caryclark@google.coma3622372012-11-06 21:26:13 +0000256 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount];
257 sk_bzero(drawFilters, sizeof(drawFilters));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000258
259 if (FLAGS_filter.count() > 0) {
260 const char* filters = FLAGS_filter[0];
261 const char* colon = strchr(filters, ':');
262 if (colon) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000263 int32_t type = -1;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000264 size_t typeLen = colon - filters;
265 for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) {
266 if (typeLen == strlen(gFilterTypes[tIndex])
267 && !strncmp(filters, gFilterTypes[tIndex], typeLen)) {
scroggo@google.comcc690202013-03-04 19:56:21 +0000268 type = SkToS32(tIndex);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000269 break;
reed@google.com006db0f2012-06-27 19:33:29 +0000270 }
reed@google.com006db0f2012-06-27 19:33:29 +0000271 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000272 if (type < 0) {
junov@chromium.org9313ca42012-11-02 18:11:49 +0000273 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000274 err.printf("Unknown type for --filter %s\n", filters);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000275 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000276 exit(-1);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000277 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000278 int flag = -1;
279 size_t flagLen = strlen(filters) - typeLen - 1;
280 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
281 if (flagLen == strlen(gFilterFlags[fIndex])
282 && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) {
283 flag = 1 << fIndex;
284 break;
285 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000286 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000287 if (flag < 0) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000288 SkString err;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000289 err.printf("Unknown flag for --filter %s\n", filters);
scroggo@google.com9a412522012-09-07 15:21:18 +0000290 gLogger.logError(err);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000291 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000292 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000293 for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) {
294 if (type != SkDrawFilter::kTypeCount && index != type) {
295 continue;
scroggo@google.com5239c322012-09-11 19:15:32 +0000296 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000297 drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags)
298 (drawFilters[index] | flag);
scroggo@google.com5239c322012-09-11 19:15:32 +0000299 }
reed@google.com006db0f2012-06-27 19:33:29 +0000300 } else {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000301 SkString err;
302 err.printf("Unknown arg for --filter %s : missing colon\n", filters);
303 gLogger.logError(err);
304 exit(-1);
reed@google.com006db0f2012-06-27 19:33:29 +0000305 }
306 }
307
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000308 if (FLAGS_timers.count() > 0) {
309 size_t index = 0;
310 bool timerWall = false;
311 bool truncatedTimerWall = false;
312 bool timerCpu = false;
313 bool truncatedTimerCpu = false;
314 bool timerGpu = false;
315 while (index < strlen(FLAGS_timers[0])) {
316 switch (FLAGS_timers[0][index]) {
317 case 'w':
318 timerWall = true;
319 break;
320 case 'c':
321 timerCpu = true;
322 break;
323 case 'W':
324 truncatedTimerWall = true;
325 break;
326 case 'C':
327 truncatedTimerCpu = true;
328 break;
329 case 'g':
330 timerGpu = true;
scroggo@google.com0556ea02013-02-08 19:38:21 +0000331 break;
332 default:
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000333 SkDebugf("mystery character\n");
scroggo@google.com0556ea02013-02-08 19:38:21 +0000334 break;
335 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000336 index++;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000337 }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000338 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, truncatedTimerCpu,
339 timerGpu);
reed@google.com006db0f2012-06-27 19:33:29 +0000340 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000341
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000342 SkString errorString;
343 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
344 kBench_PictureTool));
345
346 if (errorString.size() > 0) {
347 gLogger.logError(errorString);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000348 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000349
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000350 if (NULL == renderer.get()) {
351 exit(-1);
352 }
353
354 if (FLAGS_timeIndividualTiles) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000355 sk_tools::TiledPictureRenderer* tiledRenderer = renderer->getTiledRenderer();
356 if (NULL == tiledRenderer) {
357 gLogger.logError("--timeIndividualTiles requires tiled rendering.\n");
358 exit(-1);
359 }
360 if (!tiledRenderer->supportsTimingIndividualTiles()) {
361 gLogger.logError("This renderer does not support --timeIndividualTiles.\n");
362 exit(-1);
363 }
364 benchmark->setTimeIndividualTiles(true);
365 }
366
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000367 benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex);
commit-bot@chromium.orgc8733292014-04-11 15:54:14 +0000368 benchmark->setPreprocess(FLAGS_preprocess);
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +0000369
scroggo@google.com604e0c22013-04-09 21:25:46 +0000370 if (FLAGS_readPath.count() < 1) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000371 gLogger.logError(".skp files or directories are required.\n");
372 exit(-1);
373 }
374
caryclark@google.coma3622372012-11-06 21:26:13 +0000375 renderer->setDrawFilters(drawFilters, filtersName(drawFilters));
commit-bot@chromium.org55fd6122013-07-31 20:00:56 +0000376 if (FLAGS_logPerIter) {
377 benchmark->setTimerResultType(TimerData::kPerIter_Result);
378 } else if (FLAGS_min) {
379 benchmark->setTimerResultType(TimerData::kMin_Result);
380 } else {
381 benchmark->setTimerResultType(TimerData::kAvg_Result);
382 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000383 benchmark->setRenderer(renderer);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000384 benchmark->setRepeats(FLAGS_repeat);
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000385 benchmark->setWriter(&gWriter);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000386}
reed@google.com006db0f2012-06-27 19:33:29 +0000387
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000388static int process_input(const char* input,
borenet@google.com66bcbd12012-09-17 18:26:06 +0000389 sk_tools::PictureBenchmark& benchmark) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000390 SkString inputAsSkString(input);
391 SkOSFile::Iter iter(input, "skp");
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000392 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000393 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000394 if (iter.next(&inputFilename)) {
395 do {
tfarinaa8e2e152014-07-28 19:26:58 -0700396 SkString inputPath = SkOSPath::Join(input, inputFilename.c_str());
borenet@google.com57837bf2012-09-19 17:28:29 +0000397 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000398 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000399 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000400 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000401 } else if (SkStrEndsWith(input, ".skp")) {
402 if (!run_single_benchmark(inputAsSkString, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000403 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000404 }
405 } else {
406 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000407 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000408 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000409 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000410 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000411}
412
caryclark@google.com5987f582012-10-02 18:33:14 +0000413int tool_main(int argc, char** argv);
414int tool_main(int argc, char** argv) {
mtklein30e6e2a2014-06-18 11:44:15 -0700415 SetupCrashHandler();
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000416 SkString usage;
417 usage.printf("Time drawing .skp files.\n"
418 "\tPossible arguments for --filter: [%s]\n\t\t[%s]",
419 filterTypesUsage().c_str(), filterFlagsUsage().c_str());
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000420 SkCommandLineFlags::SetUsage(usage.c_str());
421 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000422
423 if (FLAGS_repeat < 1) {
424 SkString error;
425 error.printf("--repeats must be >= 1. Was %i\n", FLAGS_repeat);
426 gLogger.logError(error);
427 exit(-1);
428 }
429
430 if (FLAGS_logFile.count() == 1) {
431 if (!gLogger.SetLogFile(FLAGS_logFile[0])) {
432 SkString str;
433 str.printf("Could not open %s for writing.\n", FLAGS_logFile[0]);
434 gLogger.logError(str);
435 // TODO(borenet): We're disabling this for now, due to
436 // write-protected Android devices. The very short-term
437 // solution is to ignore the fact that we have no log file.
438 //exit(-1);
439 }
440 }
441
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000442 SkAutoTDelete<PictureJSONResultsWriter> jsonWriter;
443 if (FLAGS_jsonLog.count() == 1) {
kelvinly4d1a3642014-06-26 11:26:40 -0700444 SkASSERT(FLAGS_builderName.count() == 1 && FLAGS_gitHash.count() == 1);
445 jsonWriter.reset(SkNEW(PictureJSONResultsWriter(
446 FLAGS_jsonLog[0],
447 FLAGS_builderName[0],
448 FLAGS_buildNumber,
449 FLAGS_timestamp,
450 FLAGS_gitHash[0],
451 FLAGS_gitNumber)));
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000452 gWriter.add(jsonWriter.get());
453 }
454
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000455 gWriter.add(&gLogWriter);
456
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000457
bsalomon@google.com4e230682013-01-15 20:37:04 +0000458#if SK_ENABLE_INST_COUNT
scroggo@google.com5239c322012-09-11 19:15:32 +0000459 gPrintInstCount = true;
460#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000461 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000462
scroggo@google.com5239c322012-09-11 19:15:32 +0000463 sk_tools::PictureBenchmark benchmark;
464
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000465 setup_benchmark(&benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000466
borenet@google.com66bcbd12012-09-17 18:26:06 +0000467 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000468 for (int i = 0; i < FLAGS_readPath.count(); ++i) {
469 failures += process_input(FLAGS_readPath[i], benchmark);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000470 }
471
472 if (failures != 0) {
473 SkString err;
474 err.printf("Failed to run %i benchmarks.\n", failures);
475 gLogger.logError(err);
476 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000477 }
commit-bot@chromium.orgcf2f0082014-04-04 16:43:38 +0000478#if SK_LAZY_CACHE_STATS
scroggo@google.comcc690202013-03-04 19:56:21 +0000479 if (FLAGS_trackDeferredCaching) {
480 SkDebugf("Total cache hit rate: %f\n",
481 (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses));
482 }
483#endif
robertphillips754f4e92014-09-18 13:52:08 -0700484
485#if GR_GPU_STATS
486 if (FLAGS_gpuStats && benchmark.renderer()->isUsingGpuDevice()) {
487 GrContext* ctx = benchmark.renderer()->getGrContext();
488 SkDebugf("RenderTarget Binds: %d\n", ctx->gpuStats()->renderTargetBinds());
489 SkDebugf("Shader Compilations: %d\n", ctx->gpuStats()->shaderCompilations());
490 }
491#endif
492
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +0000493 gWriter.end();
caryclark@google.com868e1f62012-10-02 20:00:03 +0000494 return 0;
reed@google.com006db0f2012-06-27 19:33:29 +0000495}
caryclark@google.com5987f582012-10-02 18:33:14 +0000496
497#if !defined SK_BUILD_FOR_IOS
498int main(int argc, char * const argv[]) {
499 return tool_main(argc, (char**) argv);
500}
501#endif