blob: a5a70d9220b768a89454ccaa8cbdf2fd1be521b9 [file] [log] [blame]
mtkleinf3723212014-06-25 14:08:00 -07001/*
2 * Copyright 2014 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
mtkleinbb6a0282014-07-01 08:43:42 -07008#include <ctype.h>
9
tomhudsond968a6f2015-03-26 11:28:06 -070010#include "nanobench.h"
11
mtkleinf3723212014-06-25 14:08:00 -070012#include "Benchmark.h"
scroggo60869a42015-04-01 12:09:17 -070013#include "CodecBench.h"
mtkleinf3723212014-06-25 14:08:00 -070014#include "CrashHandler.h"
msarett95f192d2015-02-13 09:05:41 -080015#include "DecodingBench.h"
mtkleine714e752014-07-31 12:13:48 -070016#include "GMBench.h"
mtkleinafb43792014-08-19 15:55:55 -070017#include "ProcStats.h"
mtklein60317d0f2014-07-14 11:30:37 -070018#include "ResultsWriter.h"
mtkleinfd731ce2014-09-10 12:19:30 -070019#include "RecordingBench.h"
joshualitt261c3ad2015-04-27 09:16:57 -070020#include "SKPAnimationBench.h"
mtklein92007582014-08-01 07:46:52 -070021#include "SKPBench.h"
msarettb23e6aa2015-06-09 13:56:10 -070022#include "SubsetBenchPriv.h"
msarettb23e6aa2015-06-09 13:56:10 -070023#include "SubsetSingleBench.h"
24#include "SubsetTranslateBench.h"
25#include "SubsetZoomBench.h"
mtkleinf3723212014-06-25 14:08:00 -070026#include "Stats.h"
27#include "Timer.h"
28
mtklein6838d852014-10-29 14:15:10 -070029#include "SkBBoxHierarchy.h"
mtkleinf3723212014-06-25 14:08:00 -070030#include "SkCanvas.h"
scroggo60869a42015-04-01 12:09:17 -070031#include "SkCodec.h"
caryclark17f0b6d2014-07-22 10:15:34 -070032#include "SkCommonFlags.h"
msarett95f192d2015-02-13 09:05:41 -080033#include "SkData.h"
mtkleinf3723212014-06-25 14:08:00 -070034#include "SkForceLinking.h"
35#include "SkGraphics.h"
mtklein20840502014-08-21 15:51:22 -070036#include "SkOSFile.h"
37#include "SkPictureRecorder.h"
mtklein051e56d2014-12-04 08:46:51 -080038#include "SkPictureUtils.h"
scroggo9b2cdbf42015-07-10 12:07:02 -070039#include "SkScanlineDecoder.h"
mtkleinf3723212014-06-25 14:08:00 -070040#include "SkString.h"
41#include "SkSurface.h"
robertphillips5b693772014-11-21 06:19:36 -080042#include "SkTaskGroup.h"
mtkleinf3723212014-06-25 14:08:00 -070043
bungeman60e0fee2015-08-26 05:15:46 -070044#include <stdlib.h>
45
tomhudsond968a6f2015-03-26 11:28:06 -070046#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
47 #include "nanobenchAndroid.h"
48#endif
49
mtkleinbb6a0282014-07-01 08:43:42 -070050#if SK_SUPPORT_GPU
jcgregoriobf5e5232014-07-17 13:14:16 -070051 #include "gl/GrGLDefines.h"
bsalomon76228632015-05-29 08:02:10 -070052 #include "GrCaps.h"
mtkleinbb6a0282014-07-01 08:43:42 -070053 #include "GrContextFactory.h"
krajcevski69a55602014-08-13 10:46:31 -070054 SkAutoTDelete<GrContextFactory> gGrFactory;
mtkleinbb6a0282014-07-01 08:43:42 -070055#endif
56
bsalomon682c2692015-05-22 14:01:46 -070057 struct GrContextOptions;
58
mtkleinf3723212014-06-25 14:08:00 -070059__SK_FORCE_IMAGE_DECODER_LINKING;
60
cdaltone1b89582015-06-25 19:17:08 -070061static const int kTimedSampling = 0;
62
reed53249782014-10-10 09:09:52 -070063static const int kAutoTuneLoops = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -070064
mtkleinb5110422014-08-07 15:20:02 -070065static const int kDefaultLoops =
bsalomon6eb03cc2014-08-07 14:28:50 -070066#ifdef SK_DEBUG
67 1;
mtkleina189ccd2014-07-14 12:28:47 -070068#else
bsalomon6eb03cc2014-08-07 14:28:50 -070069 kAutoTuneLoops;
mtkleina189ccd2014-07-14 12:28:47 -070070#endif
71
bsalomon6eb03cc2014-08-07 14:28:50 -070072static SkString loops_help_txt() {
73 SkString help;
74 help.printf("Number of times to run each bench. Set this to %d to auto-"
75 "tune for each bench. Timings are only reported when auto-tuning.",
76 kAutoTuneLoops);
77 return help;
78}
79
cdaltone1b89582015-06-25 19:17:08 -070080static SkString to_string(int n) {
81 SkString str;
82 str.appendS32(n);
83 return str;
84}
85
bsalomon6eb03cc2014-08-07 14:28:50 -070086DEFINE_int32(loops, kDefaultLoops, loops_help_txt().c_str());
87
mtkleinf3723212014-06-25 14:08:00 -070088DEFINE_int32(samples, 10, "Number of samples to measure for each bench.");
cdaltone1b89582015-06-25 19:17:08 -070089DEFINE_string(samplingTime, "0", "Amount of time to run each bench. Takes precedence over samples."
90 "Must be \"0\", \"%%lfs\", or \"%%lfms\"");
mtkleinf3723212014-06-25 14:08:00 -070091DEFINE_int32(overheadLoops, 100000, "Loops to estimate timer overhead.");
92DEFINE_double(overheadGoal, 0.0001,
93 "Loop until timer overhead is at most this fraction of our measurments.");
mtkleinbb6a0282014-07-01 08:43:42 -070094DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
cdaltond416a5b2015-06-23 13:23:44 -070095DEFINE_int32(gpuFrameLag, 5, "If unknown, estimated maximum number of frames GPU allows to lag.");
krajcevski12b35442014-08-13 12:06:26 -070096DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to "
97 "software path rendering.");
mtkleinf3723212014-06-25 14:08:00 -070098
mtklein60317d0f2014-07-14 11:30:37 -070099DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
mtklein55b0ffc2014-07-17 08:38:23 -0700100DEFINE_int32(maxCalibrationAttempts, 3,
101 "Try up to this many times to guess loops for a bench, or skip the bench.");
102DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this.");
mtklein92007582014-08-01 07:46:52 -0700103DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
104DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
cdalton63a82852015-06-29 14:06:10 -0700105DEFINE_string(zoom, "1.0,0", "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom "
106 "function that ping-pongs between 1.0 and zoomMax.");
mtklein20840502014-08-21 15:51:22 -0700107DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
robertphillips5b693772014-11-21 06:19:36 -0800108DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
cdaltonb4022962015-06-25 10:51:56 -0700109DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?");
mtkleine070c2b2014-10-14 08:40:43 -0700110DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run.");
mtklein55e88b22015-01-21 15:50:13 -0800111DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test.");
bsalomonb12ea412015-02-02 21:19:50 -0800112DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
mtklein92007582014-08-01 07:46:52 -0700113
mtkleinf3723212014-06-25 14:08:00 -0700114static SkString humanize(double ms) {
mtkleindc5bbab2014-09-24 06:34:09 -0700115 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
mtklein748ca3b2015-01-15 10:56:12 -0800116 return HumanizeMs(ms);
mtkleinf3723212014-06-25 14:08:00 -0700117}
mtklein55b0ffc2014-07-17 08:38:23 -0700118#define HUMANIZE(ms) humanize(ms).c_str()
mtkleinf3723212014-06-25 14:08:00 -0700119
tomhudsond968a6f2015-03-26 11:28:06 -0700120bool Target::init(SkImageInfo info, Benchmark* bench) {
121 if (Benchmark::kRaster_Backend == config.backend) {
122 this->surface.reset(SkSurface::NewRaster(info));
123 if (!this->surface.get()) {
124 return false;
125 }
126 }
127 return true;
128}
129bool Target::capturePixels(SkBitmap* bmp) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700130 SkCanvas* canvas = this->getCanvas();
tomhudsond968a6f2015-03-26 11:28:06 -0700131 if (!canvas) {
132 return false;
133 }
134 bmp->setInfo(canvas->imageInfo());
135 if (!canvas->readPixels(bmp, 0, 0)) {
136 SkDebugf("Can't read canvas pixels.\n");
137 return false;
138 }
139 return true;
140}
141
142#if SK_SUPPORT_GPU
143struct GPUTarget : public Target {
halcanary96fcdcc2015-08-27 07:41:13 -0700144 explicit GPUTarget(const Config& c) : Target(c), gl(nullptr) { }
tomhudsond968a6f2015-03-26 11:28:06 -0700145 SkGLContext* gl;
146
147 void setup() override {
148 this->gl->makeCurrent();
149 // Make sure we're done with whatever came before.
150 SK_GL(*this->gl, Finish());
151 }
152 void endTiming() override {
153 if (this->gl) {
154 SK_GL(*this->gl, Flush());
155 this->gl->swapBuffers();
156 }
157 }
158 void fence() override {
159 SK_GL(*this->gl, Finish());
160 }
mtkleind75c4662015-04-30 07:11:22 -0700161
cdaltond416a5b2015-06-23 13:23:44 -0700162 bool needsFrameTiming(int* maxFrameLag) const override {
163 if (!this->gl->getMaxGpuFrameLag(maxFrameLag)) {
164 // Frame lag is unknown.
165 *maxFrameLag = FLAGS_gpuFrameLag;
166 }
167 return true;
168 }
tomhudsond968a6f2015-03-26 11:28:06 -0700169 bool init(SkImageInfo info, Benchmark* bench) override {
bsalomonafcd7cd2015-08-31 12:39:41 -0700170 uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag :
171 0;
tomhudsond968a6f2015-03-26 11:28:06 -0700172 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
173 this->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(this->config.ctxType),
174 SkSurface::kNo_Budgeted, info,
175 this->config.samples, &props));
176 this->gl = gGrFactory->getGLContext(this->config.ctxType);
177 if (!this->surface.get()) {
178 return false;
179 }
cdaltond416a5b2015-06-23 13:23:44 -0700180 if (!this->gl->fenceSyncSupport()) {
181 SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. "
182 "Timings might not be accurate.\n", this->config.name);
183 }
tomhudsond968a6f2015-03-26 11:28:06 -0700184 return true;
185 }
186 void fillOptions(ResultsWriter* log) override {
187 const GrGLubyte* version;
188 SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION));
189 log->configOption("GL_VERSION", (const char*)(version));
190
191 SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER));
192 log->configOption("GL_RENDERER", (const char*) version);
193
194 SK_GL_RET(*this->gl, version, GetString(GR_GL_VENDOR));
195 log->configOption("GL_VENDOR", (const char*) version);
196
197 SK_GL_RET(*this->gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
198 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
199 }
200};
mtkleind75c4662015-04-30 07:11:22 -0700201
tomhudsond968a6f2015-03-26 11:28:06 -0700202#endif
203
tomhudson75a0ebb2015-03-27 12:11:44 -0700204static double time(int loops, Benchmark* bench, Target* target) {
205 SkCanvas* canvas = target->getCanvas();
bsalomon6eb03cc2014-08-07 14:28:50 -0700206 if (canvas) {
207 canvas->clear(SK_ColorWHITE);
208 }
mtkleinbb6a0282014-07-01 08:43:42 -0700209 WallTimer timer;
210 timer.start();
tomhudson75a0ebb2015-03-27 12:11:44 -0700211 canvas = target->beginTiming(canvas);
212 bench->draw(loops, canvas);
mtkleinbb6a0282014-07-01 08:43:42 -0700213 if (canvas) {
214 canvas->flush();
215 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700216 target->endTiming();
mtkleinbb6a0282014-07-01 08:43:42 -0700217 timer.end();
218 return timer.fWall;
219}
220
mtkleinf3723212014-06-25 14:08:00 -0700221static double estimate_timer_overhead() {
222 double overhead = 0;
mtkleinf3723212014-06-25 14:08:00 -0700223 for (int i = 0; i < FLAGS_overheadLoops; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700224 WallTimer timer;
225 timer.start();
226 timer.end();
227 overhead += timer.fWall;
mtkleinf3723212014-06-25 14:08:00 -0700228 }
229 return overhead / FLAGS_overheadLoops;
230}
231
reed53249782014-10-10 09:09:52 -0700232static int detect_forever_loops(int loops) {
233 // look for a magic run-forever value
234 if (loops < 0) {
235 loops = SK_MaxS32;
236 }
237 return loops;
238}
239
mtklein55b0ffc2014-07-17 08:38:23 -0700240static int clamp_loops(int loops) {
241 if (loops < 1) {
mtklein527930f2014-11-06 08:04:34 -0800242 SkDebugf("ERROR: clamping loops from %d to 1. "
243 "There's probably something wrong with the bench.\n", loops);
mtklein55b0ffc2014-07-17 08:38:23 -0700244 return 1;
245 }
246 if (loops > FLAGS_maxLoops) {
247 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
248 return FLAGS_maxLoops;
249 }
250 return loops;
251}
252
tomhudsond968a6f2015-03-26 11:28:06 -0700253static bool write_canvas_png(Target* target, const SkString& filename) {
254
bsalomon6eb03cc2014-08-07 14:28:50 -0700255 if (filename.isEmpty()) {
256 return false;
257 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700258 if (target->getCanvas() &&
259 kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700260 return false;
261 }
tomhudsond968a6f2015-03-26 11:28:06 -0700262
bsalomon6eb03cc2014-08-07 14:28:50 -0700263 SkBitmap bmp;
tomhudsond968a6f2015-03-26 11:28:06 -0700264
265 if (!target->capturePixels(&bmp)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700266 return false;
267 }
tomhudsond968a6f2015-03-26 11:28:06 -0700268
bsalomon6eb03cc2014-08-07 14:28:50 -0700269 SkString dir = SkOSPath::Dirname(filename.c_str());
270 if (!sk_mkdir(dir.c_str())) {
271 SkDebugf("Can't make dir %s.\n", dir.c_str());
272 return false;
273 }
274 SkFILEWStream stream(filename.c_str());
275 if (!stream.isValid()) {
276 SkDebugf("Can't write %s.\n", filename.c_str());
277 return false;
278 }
279 if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) {
280 SkDebugf("Can't encode a PNG.\n");
281 return false;
282 }
283 return true;
284}
285
286static int kFailedLoops = -2;
cdaltone1b89582015-06-25 19:17:08 -0700287static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) {
mtkleinbb6a0282014-07-01 08:43:42 -0700288 // First figure out approximately how many loops of bench it takes to make overhead negligible.
mtklein2069e222014-08-04 13:57:39 -0700289 double bench_plus_overhead = 0.0;
mtklein55b0ffc2014-07-17 08:38:23 -0700290 int round = 0;
cdaltonb4022962015-06-25 10:51:56 -0700291 int loops = bench->calculateLoops(FLAGS_loops);
292 if (kAutoTuneLoops == loops) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700293 while (bench_plus_overhead < overhead) {
294 if (round++ == FLAGS_maxCalibrationAttempts) {
295 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
mtklein96289052014-09-10 12:05:59 -0700296 bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
bsalomon6eb03cc2014-08-07 14:28:50 -0700297 return kFailedLoops;
298 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700299 bench_plus_overhead = time(1, bench, target);
mtklein55b0ffc2014-07-17 08:38:23 -0700300 }
mtklein2069e222014-08-04 13:57:39 -0700301 }
mtkleinf3723212014-06-25 14:08:00 -0700302
mtkleinbb6a0282014-07-01 08:43:42 -0700303 // Later we'll just start and stop the timer once but loop N times.
mtkleinf3723212014-06-25 14:08:00 -0700304 // We'll pick N to make timer overhead negligible:
305 //
mtkleinbb6a0282014-07-01 08:43:42 -0700306 // overhead
307 // ------------------------- < FLAGS_overheadGoal
308 // overhead + N * Bench Time
mtkleinf3723212014-06-25 14:08:00 -0700309 //
mtkleinbb6a0282014-07-01 08:43:42 -0700310 // where bench_plus_overhead ≈ overhead + Bench Time.
mtkleinf3723212014-06-25 14:08:00 -0700311 //
312 // Doing some math, we get:
313 //
mtkleinbb6a0282014-07-01 08:43:42 -0700314 // (overhead / FLAGS_overheadGoal) - overhead
315 // ------------------------------------------ < N
316 // bench_plus_overhead - overhead)
mtkleinf3723212014-06-25 14:08:00 -0700317 //
318 // Luckily, this also works well in practice. :)
bsalomon6eb03cc2014-08-07 14:28:50 -0700319 if (kAutoTuneLoops == loops) {
320 const double numer = overhead / FLAGS_overheadGoal - overhead;
321 const double denom = bench_plus_overhead - overhead;
322 loops = (int)ceil(numer / denom);
reed53249782014-10-10 09:09:52 -0700323 loops = clamp_loops(loops);
324 } else {
325 loops = detect_forever_loops(loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700326 }
mtkleinbb6a0282014-07-01 08:43:42 -0700327
mtkleinbb6a0282014-07-01 08:43:42 -0700328 return loops;
mtkleinf3723212014-06-25 14:08:00 -0700329}
330
cdaltone1b89582015-06-25 19:17:08 -0700331static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) {
mtkleinbb6a0282014-07-01 08:43:42 -0700332 // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
cdaltonb4022962015-06-25 10:51:56 -0700333 int loops = bench->calculateLoops(FLAGS_loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700334 if (kAutoTuneLoops == loops) {
335 loops = 1;
mtkleina189ccd2014-07-14 12:28:47 -0700336 double elapsed = 0;
337 do {
mtklein527930f2014-11-06 08:04:34 -0800338 if (1<<30 == loops) {
339 // We're about to wrap. Something's wrong with the bench.
340 loops = 0;
341 break;
342 }
mtkleina189ccd2014-07-14 12:28:47 -0700343 loops *= 2;
344 // If the GPU lets frames lag at all, we need to make sure we're timing
cdaltond416a5b2015-06-23 13:23:44 -0700345 // _this_ round, not still timing last round.
346 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700347 elapsed = time(loops, bench, target);
mtkleina189ccd2014-07-14 12:28:47 -0700348 }
349 } while (elapsed < FLAGS_gpuMs);
mtkleinbb6a0282014-07-01 08:43:42 -0700350
mtkleina189ccd2014-07-14 12:28:47 -0700351 // We've overshot at least a little. Scale back linearly.
352 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
reed53249782014-10-10 09:09:52 -0700353 loops = clamp_loops(loops);
mtkleinbb6a0282014-07-01 08:43:42 -0700354
tomhudsond968a6f2015-03-26 11:28:06 -0700355 // Make sure we're not still timing our calibration.
356 target->fence();
reed53249782014-10-10 09:09:52 -0700357 } else {
358 loops = detect_forever_loops(loops);
mtkleina189ccd2014-07-14 12:28:47 -0700359 }
mtkleinbb6a0282014-07-01 08:43:42 -0700360
361 // Pretty much the same deal as the calibration: do some warmup to make
362 // sure we're timing steady-state pipelined frames.
cdaltond416a5b2015-06-23 13:23:44 -0700363 for (int i = 0; i < maxGpuFrameLag - 1; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700364 time(loops, bench, target);
mtkleinf3723212014-06-25 14:08:00 -0700365 }
mtkleinbb6a0282014-07-01 08:43:42 -0700366
mtkleinbb6a0282014-07-01 08:43:42 -0700367 return loops;
368}
mtkleinbb6a0282014-07-01 08:43:42 -0700369
370static SkString to_lower(const char* str) {
371 SkString lower(str);
372 for (size_t i = 0; i < lower.size(); i++) {
373 lower[i] = tolower(lower[i]);
374 }
375 return lower;
mtkleinf3723212014-06-25 14:08:00 -0700376}
377
bsalomonc2553372014-07-22 13:09:05 -0700378static bool is_cpu_config_allowed(const char* name) {
mtkleinbb6a0282014-07-01 08:43:42 -0700379 for (int i = 0; i < FLAGS_config.count(); i++) {
bsalomonc2553372014-07-22 13:09:05 -0700380 if (to_lower(FLAGS_config[i]).equals(name)) {
381 return true;
mtkleinf3723212014-06-25 14:08:00 -0700382 }
383 }
bsalomonc2553372014-07-22 13:09:05 -0700384 return false;
mtkleinbb6a0282014-07-01 08:43:42 -0700385}
386
bsalomonc2553372014-07-22 13:09:05 -0700387#if SK_SUPPORT_GPU
388static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextType ctxType,
389 int sampleCnt) {
390 if (!is_cpu_config_allowed(name)) {
391 return false;
392 }
krajcevski69a55602014-08-13 10:46:31 -0700393 if (const GrContext* ctx = gGrFactory->get(ctxType)) {
bsalomon76228632015-05-29 08:02:10 -0700394 return sampleCnt <= ctx->caps()->maxSampleCount();
bsalomonc2553372014-07-22 13:09:05 -0700395 }
396 return false;
397}
398#endif
mtkleinbb6a0282014-07-01 08:43:42 -0700399
bsalomonc2553372014-07-22 13:09:05 -0700400#if SK_SUPPORT_GPU
401#define kBogusGLContextType GrContextFactory::kNative_GLContextType
402#else
403#define kBogusGLContextType 0
mtkleine714e752014-07-31 12:13:48 -0700404#endif
bsalomonc2553372014-07-22 13:09:05 -0700405
406// Append all configs that are enabled and supported.
407static void create_configs(SkTDArray<Config>* configs) {
jvanverth4736e142014-11-07 07:12:46 -0800408 #define CPU_CONFIG(name, backend, color, alpha) \
409 if (is_cpu_config_allowed(#name)) { \
410 Config config = { #name, Benchmark::backend, color, alpha, 0, \
411 kBogusGLContextType, false }; \
412 configs->push(config); \
mtkleinbb6a0282014-07-01 08:43:42 -0700413 }
mtkleine714e752014-07-31 12:13:48 -0700414
mtklein40b32be2014-07-09 08:46:49 -0700415 if (FLAGS_cpu) {
bsalomonc2553372014-07-22 13:09:05 -0700416 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kUnpremul_SkAlphaType)
417 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType)
418 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType)
mtklein40b32be2014-07-09 08:46:49 -0700419 }
mtkleinbb6a0282014-07-01 08:43:42 -0700420
421#if SK_SUPPORT_GPU
jvanverth4736e142014-11-07 07:12:46 -0800422 #define GPU_CONFIG(name, ctxType, samples, useDFText) \
bsalomonc2553372014-07-22 13:09:05 -0700423 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \
424 Config config = { \
425 #name, \
426 Benchmark::kGPU_Backend, \
427 kN32_SkColorType, \
428 kPremul_SkAlphaType, \
429 samples, \
jvanverth4736e142014-11-07 07:12:46 -0800430 GrContextFactory::ctxType, \
431 useDFText }; \
bsalomonc2553372014-07-22 13:09:05 -0700432 configs->push(config); \
mtkleinbb6a0282014-07-01 08:43:42 -0700433 }
mtkleine714e752014-07-31 12:13:48 -0700434
mtklein40b32be2014-07-09 08:46:49 -0700435 if (FLAGS_gpu) {
jvanverth4736e142014-11-07 07:12:46 -0800436 GPU_CONFIG(gpu, kNative_GLContextType, 0, false)
437 GPU_CONFIG(msaa4, kNative_GLContextType, 4, false)
438 GPU_CONFIG(msaa16, kNative_GLContextType, 16, false)
439 GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4, false)
440 GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16, false)
441 GPU_CONFIG(gpudft, kNative_GLContextType, 0, true)
442 GPU_CONFIG(debug, kDebug_GLContextType, 0, false)
443 GPU_CONFIG(nullgpu, kNull_GLContextType, 0, false)
bsalomon3b4d0772014-08-06 10:52:33 -0700444#ifdef SK_ANGLE
jvanverth4736e142014-11-07 07:12:46 -0800445 GPU_CONFIG(angle, kANGLE_GLContextType, 0, false)
bsalomon3b4d0772014-08-06 10:52:33 -0700446#endif
hendrikw885bf092015-08-27 10:38:39 -0700447#ifdef SK_COMMAND_BUFFER
448 GPU_CONFIG(commandbuffer, kCommandBuffer_GLContextType, 0, false)
449#endif
cdaltond416a5b2015-06-23 13:23:44 -0700450#if SK_MESA
451 GPU_CONFIG(mesa, kMESA_GLContextType, 0, false)
452#endif
mtklein40b32be2014-07-09 08:46:49 -0700453 }
mtkleinbb6a0282014-07-01 08:43:42 -0700454#endif
tomhudsond968a6f2015-03-26 11:28:06 -0700455
456#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
457 if (is_cpu_config_allowed("hwui")) {
458 Config config = { "hwui", Benchmark::kHWUI_Backend, kRGBA_8888_SkColorType,
459 kPremul_SkAlphaType, 0, kBogusGLContextType, false };
460 configs->push(config);
461 }
462#endif
mtkleinf3723212014-06-25 14:08:00 -0700463}
464
halcanary96fcdcc2015-08-27 07:41:13 -0700465// If bench is enabled for config, returns a Target* for it, otherwise nullptr.
bsalomonc2553372014-07-22 13:09:05 -0700466static Target* is_enabled(Benchmark* bench, const Config& config) {
467 if (!bench->isSuitableFor(config.backend)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700468 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700469 }
470
reede5ea5002014-09-03 11:54:58 -0700471 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
472 config.color, config.alpha);
bsalomonc2553372014-07-22 13:09:05 -0700473
halcanary96fcdcc2015-08-27 07:41:13 -0700474 Target* target = nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700475
tomhudsond968a6f2015-03-26 11:28:06 -0700476 switch (config.backend) {
bsalomonc2553372014-07-22 13:09:05 -0700477#if SK_SUPPORT_GPU
tomhudsond968a6f2015-03-26 11:28:06 -0700478 case Benchmark::kGPU_Backend:
479 target = new GPUTarget(config);
480 break;
bsalomonc2553372014-07-22 13:09:05 -0700481#endif
tomhudsond968a6f2015-03-26 11:28:06 -0700482#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
483 case Benchmark::kHWUI_Backend:
484 target = new HWUITarget(config, bench);
485 break;
486#endif
487 default:
488 target = new Target(config);
489 break;
490 }
bsalomonc2553372014-07-22 13:09:05 -0700491
tomhudsond968a6f2015-03-26 11:28:06 -0700492 if (!target->init(info, bench)) {
bsalomonc2553372014-07-22 13:09:05 -0700493 delete target;
halcanary96fcdcc2015-08-27 07:41:13 -0700494 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700495 }
496 return target;
497}
498
msarettb23e6aa2015-06-09 13:56:10 -0700499/*
500 * Returns true if set up for a subset decode succeeds, false otherwise
501 * If the set-up succeeds, the width and height parameters will be set
502 */
503static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool useCodec,
504 int* width, int* height) {
505 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
506 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded));
507
msarettab80e352015-06-17 10:28:22 -0700508 // Check that we can create a codec or image decoder.
msarettb23e6aa2015-06-09 13:56:10 -0700509 if (useCodec) {
510 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
halcanary96fcdcc2015-08-27 07:41:13 -0700511 if (nullptr == codec) {
msarettb23e6aa2015-06-09 13:56:10 -0700512 SkDebugf("Could not create codec for %s. Skipping bench.\n", path.c_str());
513 return false;
514 }
515
516 // These will be initialized by SkCodec if the color type is kIndex8 and
517 // unused otherwise.
518 SkPMColor colors[256];
519 int colorCount;
520 const SkImageInfo info = codec->getInfo().makeColorType(colorType);
halcanary385fe4d2015-08-26 13:07:48 -0700521 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]);
scroggo1c005e42015-08-04 09:24:45 -0700522 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewFromData(encoded));
halcanary96fcdcc2015-08-27 07:41:13 -0700523 if (nullptr == scanlineDecoder || scanlineDecoder->start(info, nullptr,
scroggo1c005e42015-08-04 09:24:45 -0700524 colors, &colorCount) != SkCodec::kSuccess)
525 {
msarettb23e6aa2015-06-09 13:56:10 -0700526 SkDebugf("Could not create scanline decoder for %s with color type %s. "
527 "Skipping bench.\n", path.c_str(), get_color_name(colorType));
528 return false;
529 }
530 *width = info.width();
531 *height = info.height();
532 } else {
533 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream));
halcanary96fcdcc2015-08-27 07:41:13 -0700534 if (nullptr == decoder) {
msarettb23e6aa2015-06-09 13:56:10 -0700535 SkDebugf("Could not create decoder for %s. Skipping bench.\n", path.c_str());
536 return false;
537 }
538 //FIXME: See skbug.com/3921
539 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) {
540 SkDebugf("Cannot use image subset decoder for %s with color type %s. "
541 "Skipping bench.\n", path.c_str(), get_color_name(colorType));
542 return false;
543 }
544 if (!decoder->buildTileIndex(stream.detach(), width, height)) {
545 SkDebugf("Could not build tile index for %s. Skipping bench.\n", path.c_str());
546 return false;
547 }
548 }
msarettab80e352015-06-17 10:28:22 -0700549
550 // Check if the image is large enough for a meaningful subset benchmark.
551 if (*width <= 512 && *height <= 512) {
552 // This should not print a message since it is not an error.
553 return false;
554 }
555
msarettb23e6aa2015-06-09 13:56:10 -0700556 return true;
557}
jcgregoriobf5e5232014-07-17 13:14:16 -0700558
egdaniel3bf92062015-06-26 08:12:46 -0700559static void cleanup_run(Target* target) {
halcanary385fe4d2015-08-26 13:07:48 -0700560 delete target;
egdaniel3bf92062015-06-26 08:12:46 -0700561#if SK_SUPPORT_GPU
562 if (FLAGS_abandonGpuContext) {
563 gGrFactory->abandonContexts();
564 }
565 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) {
566 gGrFactory->destroyContexts();
567 }
568#endif
569}
570
mtkleine714e752014-07-31 12:13:48 -0700571class BenchmarkStream {
572public:
mtklein92007582014-08-01 07:46:52 -0700573 BenchmarkStream() : fBenches(BenchRegistry::Head())
574 , fGMs(skiagm::GMRegistry::Head())
mtkleinfd731ce2014-09-10 12:19:30 -0700575 , fCurrentRecording(0)
mtklein92007582014-08-01 07:46:52 -0700576 , fCurrentScale(0)
robertphillips5b693772014-11-21 06:19:36 -0800577 , fCurrentSKP(0)
msarett95f192d2015-02-13 09:05:41 -0800578 , fCurrentUseMPD(0)
scroggo60869a42015-04-01 12:09:17 -0700579 , fCurrentCodec(0)
msarett95f192d2015-02-13 09:05:41 -0800580 , fCurrentImage(0)
581 , fCurrentSubsetImage(0)
582 , fCurrentColorType(0)
msarettb23e6aa2015-06-09 13:56:10 -0700583 , fCurrentSubsetType(0)
584 , fUseCodec(0)
585 , fCurrentAnimSKP(0) {
mtklein92007582014-08-01 07:46:52 -0700586 for (int i = 0; i < FLAGS_skps.count(); i++) {
587 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
588 fSKPs.push_back() = FLAGS_skps[i];
589 } else {
590 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
591 SkString path;
592 while (it.next(&path)) {
593 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
594 }
595 }
596 }
mtkleine714e752014-07-31 12:13:48 -0700597
mtklein92007582014-08-01 07:46:52 -0700598 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
599 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
600 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
601 exit(1);
602 }
603
604 for (int i = 0; i < FLAGS_scales.count(); i++) {
605 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
606 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
607 exit(1);
608 }
609 }
robertphillips5b693772014-11-21 06:19:36 -0800610
cdalton63a82852015-06-29 14:06:10 -0700611 if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) {
612 SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]);
joshualitt261c3ad2015-04-27 09:16:57 -0700613 exit(1);
614 }
615
robertphillips5b693772014-11-21 06:19:36 -0800616 if (FLAGS_mpd) {
617 fUseMPDs.push_back() = true;
618 }
mtkleinc751ecb2015-06-15 08:56:38 -0700619 fUseMPDs.push_back() = false;
mtklein95553d92015-03-12 08:24:21 -0700620
msarett95f192d2015-02-13 09:05:41 -0800621 // Prepare the images for decoding
622 for (int i = 0; i < FLAGS_images.count(); i++) {
623 const char* flag = FLAGS_images[i];
624 if (sk_isdir(flag)) {
625 // If the value passed in is a directory, add all the images
626 SkOSFile::Iter it(flag);
627 SkString file;
628 while (it.next(&file)) {
629 fImages.push_back() = SkOSPath::Join(flag, file.c_str());
630 }
631 } else if (sk_exists(flag)) {
632 // Also add the value if it is a single image
633 fImages.push_back() = flag;
634 }
635 }
mtklein95553d92015-03-12 08:24:21 -0700636
msarett95f192d2015-02-13 09:05:41 -0800637 // Choose the candidate color types for image decoding
638 const SkColorType colorTypes[] =
msarettb23e6aa2015-06-09 13:56:10 -0700639 { kN32_SkColorType,
640 kRGB_565_SkColorType,
641 kAlpha_8_SkColorType,
642 kIndex_8_SkColorType,
643 kGray_8_SkColorType };
msarett95f192d2015-02-13 09:05:41 -0800644 fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes);
mtklein92007582014-08-01 07:46:52 -0700645 }
646
mtkleinfd731ce2014-09-10 12:19:30 -0700647 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
648 // Not strictly necessary, as it will be checked again later,
649 // but helps to avoid a lot of pointless work if we're going to skip it.
650 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
651 return false;
652 }
653
scroggoa1193e42015-01-21 12:09:53 -0800654 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
halcanary96fcdcc2015-08-27 07:41:13 -0700655 if (stream.get() == nullptr) {
mtkleinfd731ce2014-09-10 12:19:30 -0700656 SkDebugf("Could not read %s.\n", path);
657 return false;
658 }
659
mtklein57f27bd2015-02-09 11:58:41 -0800660 pic->reset(SkPicture::CreateFromStream(stream.get()));
halcanary96fcdcc2015-08-27 07:41:13 -0700661 if (pic->get() == nullptr) {
mtkleinfd731ce2014-09-10 12:19:30 -0700662 SkDebugf("Could not read %s as an SkPicture.\n", path);
663 return false;
664 }
665 return true;
666 }
667
mtklein92007582014-08-01 07:46:52 -0700668 Benchmark* next() {
mtkleine714e752014-07-31 12:13:48 -0700669 if (fBenches) {
halcanary96fcdcc2015-08-27 07:41:13 -0700670 Benchmark* bench = fBenches->factory()(nullptr);
mtkleine714e752014-07-31 12:13:48 -0700671 fBenches = fBenches->next();
mtklein92007582014-08-01 07:46:52 -0700672 fSourceType = "bench";
mtkleinfd731ce2014-09-10 12:19:30 -0700673 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700674 return bench;
675 }
mtklein92007582014-08-01 07:46:52 -0700676
mtkleine714e752014-07-31 12:13:48 -0700677 while (fGMs) {
halcanary96fcdcc2015-08-27 07:41:13 -0700678 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr));
mtkleine714e752014-07-31 12:13:48 -0700679 fGMs = fGMs->next();
mtkleincf5d9c92015-01-23 10:31:45 -0800680 if (gm->runAsBench()) {
mtklein92007582014-08-01 07:46:52 -0700681 fSourceType = "gm";
mtkleinfd731ce2014-09-10 12:19:30 -0700682 fBenchType = "micro";
halcanary385fe4d2015-08-26 13:07:48 -0700683 return new GMBench(gm.detach());
mtkleine714e752014-07-31 12:13:48 -0700684 }
685 }
mtklein92007582014-08-01 07:46:52 -0700686
mtkleinfd731ce2014-09-10 12:19:30 -0700687 // First add all .skps as RecordingBenches.
688 while (fCurrentRecording < fSKPs.count()) {
689 const SkString& path = fSKPs[fCurrentRecording++];
690 SkAutoTUnref<SkPicture> pic;
691 if (!ReadPicture(path.c_str(), &pic)) {
692 continue;
693 }
694 SkString name = SkOSPath::Basename(path.c_str());
695 fSourceType = "skp";
696 fBenchType = "recording";
bsalomon0aa5cea2014-12-15 09:13:35 -0800697 fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic));
mtklein051e56d2014-12-04 08:46:51 -0800698 fSKPOps = pic->approximateOpCount();
halcanary385fe4d2015-08-26 13:07:48 -0700699 return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh);
mtkleinfd731ce2014-09-10 12:19:30 -0700700 }
701
702 // Then once each for each scale as SKPBenches (playback).
mtklein92007582014-08-01 07:46:52 -0700703 while (fCurrentScale < fScales.count()) {
704 while (fCurrentSKP < fSKPs.count()) {
robertphillips5b693772014-11-21 06:19:36 -0800705 const SkString& path = fSKPs[fCurrentSKP];
mtkleinfd731ce2014-09-10 12:19:30 -0700706 SkAutoTUnref<SkPicture> pic;
707 if (!ReadPicture(path.c_str(), &pic)) {
robertphillips5b693772014-11-21 06:19:36 -0800708 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700709 continue;
710 }
robertphillips5b693772014-11-21 06:19:36 -0800711
712 while (fCurrentUseMPD < fUseMPDs.count()) {
713 if (FLAGS_bbh) {
714 // The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
715 SkRTreeFactory factory;
716 SkPictureRecorder recorder;
717 static const int kFlags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
718 pic->playback(recorder.beginRecording(pic->cullRect().width(),
719 pic->cullRect().height(),
mtklein748ca3b2015-01-15 10:56:12 -0800720 &factory,
robertphillipse451c4d2014-12-09 10:28:00 -0800721 fUseMPDs[fCurrentUseMPD] ? kFlags : 0));
robertphillips5b693772014-11-21 06:19:36 -0800722 pic.reset(recorder.endRecording());
723 }
724 SkString name = SkOSPath::Basename(path.c_str());
725 fSourceType = "skp";
726 fBenchType = "playback";
halcanary385fe4d2015-08-26 13:07:48 -0700727 return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale],
728 fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP);
mtklein20840502014-08-21 15:51:22 -0700729 }
robertphillips5b693772014-11-21 06:19:36 -0800730 fCurrentUseMPD = 0;
731 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700732 }
733 fCurrentSKP = 0;
734 fCurrentScale++;
735 }
736
joshualitt261c3ad2015-04-27 09:16:57 -0700737 // Now loop over each skp again if we have an animation
cdalton63a82852015-06-29 14:06:10 -0700738 if (fZoomMax != 1.0f && fZoomPeriodMs > 0) {
joshualitt261c3ad2015-04-27 09:16:57 -0700739 while (fCurrentAnimSKP < fSKPs.count()) {
740 const SkString& path = fSKPs[fCurrentAnimSKP];
741 SkAutoTUnref<SkPicture> pic;
742 if (!ReadPicture(path.c_str(), &pic)) {
743 fCurrentAnimSKP++;
744 continue;
745 }
746
747 fCurrentAnimSKP++;
748 SkString name = SkOSPath::Basename(path.c_str());
cdalton63a82852015-06-29 14:06:10 -0700749 SkAutoTUnref<SKPAnimationBench::Animation> animation(
750 SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriodMs));
halcanary385fe4d2015-08-26 13:07:48 -0700751 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, animation,
752 FLAGS_loopSKP);
joshualitt261c3ad2015-04-27 09:16:57 -0700753 }
754 }
755
756
scroggo60869a42015-04-01 12:09:17 -0700757 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) {
758 const SkString& path = fImages[fCurrentCodec];
759 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
760 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
scroggo60869a42015-04-01 12:09:17 -0700761 if (!codec) {
762 // Nothing to time.
msarett9d9725c2015-04-24 11:41:55 -0700763 SkDebugf("Cannot find codec for %s\n", path.c_str());
scroggo60869a42015-04-01 12:09:17 -0700764 continue;
765 }
scroggo21027992015-04-02 13:22:38 -0700766
scroggo60869a42015-04-01 12:09:17 -0700767 while (fCurrentColorType < fColorTypes.count()) {
scroggo21027992015-04-02 13:22:38 -0700768 const SkColorType colorType = fColorTypes[fCurrentColorType];
scroggo60869a42015-04-01 12:09:17 -0700769 fCurrentColorType++;
scroggo21027992015-04-02 13:22:38 -0700770
scroggo60869a42015-04-01 12:09:17 -0700771 // Make sure we can decode to this color type.
scroggo60869a42015-04-01 12:09:17 -0700772 SkImageInfo info = codec->getInfo().makeColorType(colorType);
scroggo21027992015-04-02 13:22:38 -0700773 SkAlphaType alphaType;
774 if (!SkColorTypeValidateAlphaType(colorType, info.alphaType(),
775 &alphaType)) {
776 continue;
777 }
778 if (alphaType != info.alphaType()) {
779 info = info.makeAlphaType(alphaType);
780 }
781
782 const size_t rowBytes = info.minRowBytes();
783 SkAutoMalloc storage(info.getSafeSize(rowBytes));
784
785 // Used if fCurrentColorType is kIndex_8_SkColorType
786 int colorCount = 256;
787 SkPMColor colors[256];
788
scroggoeb602a52015-07-09 08:16:03 -0700789 const SkCodec::Result result = codec->getPixels(
halcanary96fcdcc2015-08-27 07:41:13 -0700790 info, storage.get(), rowBytes, nullptr, colors,
scroggo21027992015-04-02 13:22:38 -0700791 &colorCount);
scroggo60869a42015-04-01 12:09:17 -0700792 switch (result) {
scroggoeb602a52015-07-09 08:16:03 -0700793 case SkCodec::kSuccess:
794 case SkCodec::kIncompleteInput:
scroggo60869a42015-04-01 12:09:17 -0700795 return new CodecBench(SkOSPath::Basename(path.c_str()),
796 encoded, colorType);
scroggoeb602a52015-07-09 08:16:03 -0700797 case SkCodec::kInvalidConversion:
scroggo60869a42015-04-01 12:09:17 -0700798 // This is okay. Not all conversions are valid.
799 break;
scroggo60869a42015-04-01 12:09:17 -0700800 default:
801 // This represents some sort of failure.
802 SkASSERT(false);
803 break;
804 }
805 }
806 fCurrentColorType = 0;
807 }
808
msarett95f192d2015-02-13 09:05:41 -0800809 // Run the DecodingBenches
810 while (fCurrentImage < fImages.count()) {
811 while (fCurrentColorType < fColorTypes.count()) {
812 const SkString& path = fImages[fCurrentImage];
813 SkColorType colorType = fColorTypes[fCurrentColorType];
814 fCurrentColorType++;
scroggo60869a42015-04-01 12:09:17 -0700815 // Check if the image decodes to the right color type
816 // before creating the benchmark
msarett95f192d2015-02-13 09:05:41 -0800817 SkBitmap bitmap;
818 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap,
scroggo60869a42015-04-01 12:09:17 -0700819 colorType, SkImageDecoder::kDecodePixels_Mode)
820 && bitmap.colorType() == colorType) {
msarett95f192d2015-02-13 09:05:41 -0800821 return new DecodingBench(path, colorType);
822 }
823 }
824 fCurrentColorType = 0;
825 fCurrentImage++;
826 }
827
msarettb23e6aa2015-06-09 13:56:10 -0700828 // Run the SubsetBenches
829 bool useCodecOpts[] = { true, false };
830 while (fUseCodec < 2) {
831 bool useCodec = useCodecOpts[fUseCodec];
832 while (fCurrentSubsetImage < fImages.count()) {
833 while (fCurrentColorType < fColorTypes.count()) {
834 const SkString& path = fImages[fCurrentSubsetImage];
835 SkColorType colorType = fColorTypes[fCurrentColorType];
836 while (fCurrentSubsetType <= kLast_SubsetType) {
837 int width = 0;
838 int height = 0;
839 int currentSubsetType = fCurrentSubsetType++;
840 if (valid_subset_bench(path, colorType, useCodec, &width, &height)) {
841 switch (currentSubsetType) {
842 case kTopLeft_SubsetType:
msarettab80e352015-06-17 10:28:22 -0700843 return new SubsetSingleBench(path, colorType, width/3,
844 height/3, 0, 0, useCodec);
msarettb23e6aa2015-06-09 13:56:10 -0700845 case kTopRight_SubsetType:
msarettab80e352015-06-17 10:28:22 -0700846 return new SubsetSingleBench(path, colorType, width/3,
847 height/3, 2*width/3, 0, useCodec);
848 case kMiddle_SubsetType:
849 return new SubsetSingleBench(path, colorType, width/3,
850 height/3, width/3, height/3, useCodec);
msarettb23e6aa2015-06-09 13:56:10 -0700851 case kBottomLeft_SubsetType:
msarettab80e352015-06-17 10:28:22 -0700852 return new SubsetSingleBench(path, colorType, width/3,
853 height/3, 0, 2*height/3, useCodec);
msarettb23e6aa2015-06-09 13:56:10 -0700854 case kBottomRight_SubsetType:
msarettab80e352015-06-17 10:28:22 -0700855 return new SubsetSingleBench(path, colorType, width/3,
856 height/3, 2*width/3, 2*height/3, useCodec);
msarettb23e6aa2015-06-09 13:56:10 -0700857 case kTranslate_SubsetType:
858 return new SubsetTranslateBench(path, colorType, 512, 512,
859 useCodec);
860 case kZoom_SubsetType:
861 return new SubsetZoomBench(path, colorType, 512, 512,
862 useCodec);
msarett95f192d2015-02-13 09:05:41 -0800863 }
msarettb23e6aa2015-06-09 13:56:10 -0700864 } else {
865 break;
msarett95f192d2015-02-13 09:05:41 -0800866 }
867 }
msarettb23e6aa2015-06-09 13:56:10 -0700868 fCurrentSubsetType = 0;
869 fCurrentColorType++;
msarett95f192d2015-02-13 09:05:41 -0800870 }
msarettb23e6aa2015-06-09 13:56:10 -0700871 fCurrentColorType = 0;
872 fCurrentSubsetImage++;
msarett95f192d2015-02-13 09:05:41 -0800873 }
msarettb23e6aa2015-06-09 13:56:10 -0700874 fCurrentSubsetImage = 0;
875 fUseCodec++;
msarett95f192d2015-02-13 09:05:41 -0800876 }
877
halcanary96fcdcc2015-08-27 07:41:13 -0700878 return nullptr;
mtkleine714e752014-07-31 12:13:48 -0700879 }
mtklein92007582014-08-01 07:46:52 -0700880
881 void fillCurrentOptions(ResultsWriter* log) const {
882 log->configOption("source_type", fSourceType);
mtkleinfd731ce2014-09-10 12:19:30 -0700883 log->configOption("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -0700884 if (0 == strcmp(fSourceType, "skp")) {
885 log->configOption("clip",
886 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
887 fClip.fRight, fClip.fBottom).c_str());
888 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
robertphillips5b693772014-11-21 06:19:36 -0800889 if (fCurrentUseMPD > 0) {
890 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
891 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
892 }
mtklein92007582014-08-01 07:46:52 -0700893 }
mtklein051e56d2014-12-04 08:46:51 -0800894 if (0 == strcmp(fBenchType, "recording")) {
895 log->metric("bytes", fSKPBytes);
896 log->metric("ops", fSKPOps);
897 }
mtklein92007582014-08-01 07:46:52 -0700898 }
899
mtkleine714e752014-07-31 12:13:48 -0700900private:
msarettb23e6aa2015-06-09 13:56:10 -0700901 enum SubsetType {
902 kTopLeft_SubsetType = 0,
903 kTopRight_SubsetType = 1,
msarettab80e352015-06-17 10:28:22 -0700904 kMiddle_SubsetType = 2,
905 kBottomLeft_SubsetType = 3,
906 kBottomRight_SubsetType = 4,
907 kTranslate_SubsetType = 5,
908 kZoom_SubsetType = 6,
msarettb23e6aa2015-06-09 13:56:10 -0700909 kLast_SubsetType = kZoom_SubsetType
910 };
911
mtkleine714e752014-07-31 12:13:48 -0700912 const BenchRegistry* fBenches;
913 const skiagm::GMRegistry* fGMs;
mtklein92007582014-08-01 07:46:52 -0700914 SkIRect fClip;
915 SkTArray<SkScalar> fScales;
916 SkTArray<SkString> fSKPs;
robertphillips5b693772014-11-21 06:19:36 -0800917 SkTArray<bool> fUseMPDs;
msarett95f192d2015-02-13 09:05:41 -0800918 SkTArray<SkString> fImages;
919 SkTArray<SkColorType> fColorTypes;
cdalton63a82852015-06-29 14:06:10 -0700920 SkScalar fZoomMax;
921 double fZoomPeriodMs;
mtklein92007582014-08-01 07:46:52 -0700922
mtklein051e56d2014-12-04 08:46:51 -0800923 double fSKPBytes, fSKPOps;
924
mtkleinfd731ce2014-09-10 12:19:30 -0700925 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
926 const char* fBenchType; // How we bench it: micro, recording, playback, ...
927 int fCurrentRecording;
mtklein92007582014-08-01 07:46:52 -0700928 int fCurrentScale;
929 int fCurrentSKP;
robertphillips5b693772014-11-21 06:19:36 -0800930 int fCurrentUseMPD;
scroggo60869a42015-04-01 12:09:17 -0700931 int fCurrentCodec;
msarett95f192d2015-02-13 09:05:41 -0800932 int fCurrentImage;
933 int fCurrentSubsetImage;
934 int fCurrentColorType;
msarettb23e6aa2015-06-09 13:56:10 -0700935 int fCurrentSubsetType;
936 int fUseCodec;
joshualitt261c3ad2015-04-27 09:16:57 -0700937 int fCurrentAnimSKP;
mtkleine714e752014-07-31 12:13:48 -0700938};
939
jcgregorio3b27ade2014-11-13 08:06:40 -0800940int nanobench_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700941int nanobench_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800942 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -0700943 SkAutoGraphics ag;
mtkleincc29d262015-07-09 10:04:56 -0700944 SkTaskGroup::Enabler enabled(FLAGS_threads);
mtkleinf3723212014-06-25 14:08:00 -0700945
krajcevski69a55602014-08-13 10:46:31 -0700946#if SK_SUPPORT_GPU
bsalomon682c2692015-05-22 14:01:46 -0700947 GrContextOptions grContextOpts;
krajcevski12b35442014-08-13 12:06:26 -0700948 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
halcanary385fe4d2015-08-26 13:07:48 -0700949 gGrFactory.reset(new GrContextFactory(grContextOpts));
krajcevski69a55602014-08-13 10:46:31 -0700950#endif
951
bsalomon06cddec2014-10-24 10:40:50 -0700952 if (FLAGS_veryVerbose) {
953 FLAGS_verbose = true;
954 }
955
cdaltone1b89582015-06-25 19:17:08 -0700956 double samplingTimeMs = 0;
957 if (0 != strcmp("0", FLAGS_samplingTime[0])) {
958 SkSTArray<8, char> timeUnit;
959 timeUnit.push_back_n(static_cast<int>(strlen(FLAGS_samplingTime[0])) + 1);
960 if (2 != sscanf(FLAGS_samplingTime[0], "%lf%s", &samplingTimeMs, timeUnit.begin()) ||
961 (0 != strcmp("s", timeUnit.begin()) && 0 != strcmp("ms", timeUnit.begin()))) {
962 SkDebugf("Invalid --samplingTime \"%s\". Must be \"0\", \"%%lfs\", or \"%%lfms\"\n",
963 FLAGS_samplingTime[0]);
964 exit(0);
965 }
966 if (0 == strcmp("s", timeUnit.begin())) {
967 samplingTimeMs *= 1000;
968 }
969 if (samplingTimeMs) {
970 FLAGS_samples = kTimedSampling;
971 }
972 }
973
bsalomon6eb03cc2014-08-07 14:28:50 -0700974 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700975 FLAGS_samples = 1;
976 FLAGS_gpuFrameLag = 0;
977 }
978
bsalomon6eb03cc2014-08-07 14:28:50 -0700979 if (!FLAGS_writePath.isEmpty()) {
980 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
981 if (!sk_mkdir(FLAGS_writePath[0])) {
982 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
halcanary96fcdcc2015-08-27 07:41:13 -0700983 FLAGS_writePath.set(0, nullptr);
bsalomon6eb03cc2014-08-07 14:28:50 -0700984 }
985 }
986
halcanary385fe4d2015-08-26 13:07:48 -0700987 SkAutoTDelete<ResultsWriter> log(new ResultsWriter);
mtklein60317d0f2014-07-14 11:30:37 -0700988 if (!FLAGS_outResultsFile.isEmpty()) {
halcanary385fe4d2015-08-26 13:07:48 -0700989 log.reset(new NanoJSONResultsWriter(FLAGS_outResultsFile[0]));
mtklein60317d0f2014-07-14 11:30:37 -0700990 }
mtklein1915b622014-08-20 11:45:00 -0700991
992 if (1 == FLAGS_properties.count() % 2) {
993 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
994 return 1;
995 }
996 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
997 log->property(FLAGS_properties[i-1], FLAGS_properties[i]);
998 }
jcgregoriobf5e5232014-07-17 13:14:16 -0700999
1000 if (1 == FLAGS_key.count() % 2) {
1001 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
1002 return 1;
1003 }
1004 for (int i = 1; i < FLAGS_key.count(); i += 2) {
mtklein1915b622014-08-20 11:45:00 -07001005 log->key(FLAGS_key[i-1], FLAGS_key[i]);
mtklein94e51562014-08-19 12:41:53 -07001006 }
mtklein60317d0f2014-07-14 11:30:37 -07001007
mtkleinf3723212014-06-25 14:08:00 -07001008 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -07001009 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -04001010
cdaltone1b89582015-06-25 19:17:08 -07001011 SkTArray<double> samples;
mtkleinbb6a0282014-07-01 08:43:42 -07001012
bsalomon6eb03cc2014-08-07 14:28:50 -07001013 if (kAutoTuneLoops != FLAGS_loops) {
1014 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleinf3723212014-06-25 14:08:00 -07001015 } else if (FLAGS_quiet) {
mtklein40b32be2014-07-09 08:46:49 -07001016 SkDebugf("median\tbench\tconfig\n");
cdaltone1b89582015-06-25 19:17:08 -07001017 } else if (kTimedSampling == FLAGS_samples) {
1018 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n");
mtkleinf3723212014-06-25 14:08:00 -07001019 } else {
mtkleind75c4662015-04-30 07:11:22 -07001020 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
qiankun.miao8247ec32014-09-09 19:24:36 -07001021 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -07001022 }
1023
bsalomonc2553372014-07-22 13:09:05 -07001024 SkTDArray<Config> configs;
1025 create_configs(&configs);
1026
mtkleine070c2b2014-10-14 08:40:43 -07001027 int runs = 0;
mtklein92007582014-08-01 07:46:52 -07001028 BenchmarkStream benchStream;
1029 while (Benchmark* b = benchStream.next()) {
mtkleine714e752014-07-31 12:13:48 -07001030 SkAutoTDelete<Benchmark> bench(b);
mtklein96289052014-09-10 12:05:59 -07001031 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -07001032 continue;
1033 }
1034
egdaniel3bf92062015-06-26 08:12:46 -07001035 if (!configs.isEmpty()) {
mtklein96289052014-09-10 12:05:59 -07001036 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
jcgregoriobf5e5232014-07-17 13:14:16 -07001037 bench->preDraw();
1038 }
egdaniel3bf92062015-06-26 08:12:46 -07001039 for (int i = 0; i < configs.count(); ++i) {
1040 Target* target = is_enabled(b, configs[i]);
1041 if (!target) {
1042 continue;
1043 }
mtkleinf3723212014-06-25 14:08:00 -07001044
halcanary96fcdcc2015-08-27 07:41:13 -07001045 // During HWUI output this canvas may be nullptr.
egdaniel3bf92062015-06-26 08:12:46 -07001046 SkCanvas* canvas = target->getCanvas();
1047 const char* config = target->config.name;
1048
1049 target->setup();
robertphillips5b693772014-11-21 06:19:36 -08001050 bench->perCanvasPreDraw(canvas);
1051
cdaltone1b89582015-06-25 19:17:08 -07001052 int maxFrameLag;
egdaniel3bf92062015-06-26 08:12:46 -07001053 const int loops = target->needsFrameTiming(&maxFrameLag)
1054 ? setup_gpu_bench(target, bench.get(), maxFrameLag)
1055 : setup_cpu_bench(overhead, target, bench.get());
cdaltone1b89582015-06-25 19:17:08 -07001056
1057 if (kTimedSampling != FLAGS_samples) {
1058 samples.reset(FLAGS_samples);
1059 for (int s = 0; s < FLAGS_samples; s++) {
egdaniel3bf92062015-06-26 08:12:46 -07001060 samples[s] = time(loops, bench, target) / loops;
cdaltone1b89582015-06-25 19:17:08 -07001061 }
1062 } else if (samplingTimeMs) {
1063 samples.reset();
1064 if (FLAGS_verbose) {
1065 SkDebugf("Begin sampling %s for %ims\n",
1066 bench->getUniqueName(), static_cast<int>(samplingTimeMs));
1067 }
1068 WallTimer timer;
1069 timer.start();
1070 do {
egdaniel3bf92062015-06-26 08:12:46 -07001071 samples.push_back(time(loops, bench, target) / loops);
cdaltone1b89582015-06-25 19:17:08 -07001072 timer.end();
1073 } while (timer.fWall < samplingTimeMs);
1074 }
mtkleinf3723212014-06-25 14:08:00 -07001075
robertphillips5b693772014-11-21 06:19:36 -08001076 bench->perCanvasPostDraw(canvas);
1077
egdaniel3bf92062015-06-26 08:12:46 -07001078 if (Benchmark::kNonRendering_Backend != target->config.backend &&
tomhudsond968a6f2015-03-26 11:28:06 -07001079 !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -07001080 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -07001081 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -07001082 pngFilename.append(".png");
egdaniel3bf92062015-06-26 08:12:46 -07001083 write_canvas_png(target, pngFilename);
bsalomon6eb03cc2014-08-07 14:28:50 -07001084 }
1085
1086 if (kFailedLoops == loops) {
mtklein2069e222014-08-04 13:57:39 -07001087 // Can't be timed. A warning note has already been printed.
egdaniel3bf92062015-06-26 08:12:46 -07001088 cleanup_run(target);
Mike Kleine3631362014-07-15 17:56:37 -04001089 continue;
1090 }
1091
cdaltone1b89582015-06-25 19:17:08 -07001092 Stats stats(samples);
mtklein1915b622014-08-20 11:45:00 -07001093 log->config(config);
mtklein96289052014-09-10 12:05:59 -07001094 log->configOption("name", bench->getName());
mtklein1915b622014-08-20 11:45:00 -07001095 benchStream.fillCurrentOptions(log.get());
egdaniel3bf92062015-06-26 08:12:46 -07001096 target->fillOptions(log.get());
mtklein051e56d2014-12-04 08:46:51 -08001097 log->metric("min_ms", stats.min);
mtkleine070c2b2014-10-14 08:40:43 -07001098 if (runs++ % FLAGS_flushEvery == 0) {
1099 log->flush();
1100 }
mtklein60317d0f2014-07-14 11:30:37 -07001101
bsalomon6eb03cc2014-08-07 14:28:50 -07001102 if (kAutoTuneLoops != FLAGS_loops) {
egdaniel3bf92062015-06-26 08:12:46 -07001103 if (configs.count() == 1) {
mtkleina189ccd2014-07-14 12:28:47 -07001104 config = ""; // Only print the config if we run the same bench on more than one.
1105 }
mtkleind75c4662015-04-30 07:11:22 -07001106 SkDebugf("%4d/%-4dMB\t%s\t%s\n"
1107 , sk_tools::getCurrResidentSetSizeMB()
1108 , sk_tools::getMaxResidentSetSizeMB()
mtklein53d25622014-09-18 07:39:42 -07001109 , bench->getUniqueName()
1110 , config);
mtkleinf3723212014-06-25 14:08:00 -07001111 } else if (FLAGS_quiet) {
egdaniel3bf92062015-06-26 08:12:46 -07001112 if (configs.count() == 1) {
mtkleinf3723212014-06-25 14:08:00 -07001113 config = ""; // Only print the config if we run the same bench on more than one.
1114 }
mtklein96289052014-09-10 12:05:59 -07001115 SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getUniqueName(), config);
mtkleinf3723212014-06-25 14:08:00 -07001116 } else {
1117 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
mtkleind75c4662015-04-30 07:11:22 -07001118 SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n"
1119 , sk_tools::getCurrResidentSetSizeMB()
1120 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -07001121 , loops
mtklein55b0ffc2014-07-17 08:38:23 -07001122 , HUMANIZE(stats.min)
1123 , HUMANIZE(stats.median)
1124 , HUMANIZE(stats.mean)
1125 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -07001126 , stddev_percent
cdaltone1b89582015-06-25 19:17:08 -07001127 , kTimedSampling != FLAGS_samples ? stats.plot.c_str()
1128 : to_string(samples.count()).c_str()
mtkleinf3723212014-06-25 14:08:00 -07001129 , config
mtklein96289052014-09-10 12:05:59 -07001130 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -07001131 );
1132 }
bsalomonb12ea412015-02-02 21:19:50 -08001133#if SK_SUPPORT_GPU
1134 if (FLAGS_gpuStats &&
egdaniel3bf92062015-06-26 08:12:46 -07001135 Benchmark::kGPU_Backend == configs[i].backend) {
1136 gGrFactory->get(configs[i].ctxType)->printCacheStats();
1137 gGrFactory->get(configs[i].ctxType)->printGpuStats();
bsalomon06cddec2014-10-24 10:40:50 -07001138 }
1139#endif
cdalton2c56ba52015-06-26 13:32:53 -07001140 if (FLAGS_verbose) {
1141 SkDebugf("Samples: ");
1142 for (int i = 0; i < samples.count(); i++) {
1143 SkDebugf("%s ", HUMANIZE(samples[i]));
1144 }
1145 SkDebugf("%s\n", bench->getUniqueName());
1146 }
egdaniel3bf92062015-06-26 08:12:46 -07001147 cleanup_run(target);
mtkleinf3723212014-06-25 14:08:00 -07001148 }
mtkleinf3723212014-06-25 14:08:00 -07001149 }
1150
mtkleine1091452014-12-04 10:47:02 -08001151 log->bench("memory_usage", 0,0);
1152 log->config("meta");
1153 log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
1154
joshualitte0b19d42015-03-26 10:41:02 -07001155#if SK_SUPPORT_GPU
1156 // Make sure we clean up the global GrContextFactory here, otherwise we might race with the
1157 // SkEventTracer destructor
halcanary96fcdcc2015-08-27 07:41:13 -07001158 gGrFactory.reset(nullptr);
joshualitte0b19d42015-03-26 10:41:02 -07001159#endif
1160
mtkleinf3723212014-06-25 14:08:00 -07001161 return 0;
1162}
1163
jcgregorio3b27ade2014-11-13 08:06:40 -08001164#if !defined SK_BUILD_FOR_IOS
1165int main(int argc, char** argv) {
1166 SkCommandLineFlags::Parse(argc, argv);
1167 return nanobench_main();
1168}
1169#endif