blob: 6fe2d626f49aef2de884ef38d8a25741db31d451 [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
mtkleinf3723212014-06-25 14:08:00 -070010#include "Benchmark.h"
11#include "CrashHandler.h"
mtkleine714e752014-07-31 12:13:48 -070012#include "GMBench.h"
mtkleinafb43792014-08-19 15:55:55 -070013#include "ProcStats.h"
mtklein60317d0f2014-07-14 11:30:37 -070014#include "ResultsWriter.h"
mtkleinfd731ce2014-09-10 12:19:30 -070015#include "RecordingBench.h"
mtklein92007582014-08-01 07:46:52 -070016#include "SKPBench.h"
mtkleinf3723212014-06-25 14:08:00 -070017#include "Stats.h"
18#include "Timer.h"
19
mtklein6838d852014-10-29 14:15:10 -070020#include "SkBBoxHierarchy.h"
mtkleinf3723212014-06-25 14:08:00 -070021#include "SkCanvas.h"
caryclark17f0b6d2014-07-22 10:15:34 -070022#include "SkCommonFlags.h"
mtkleinf3723212014-06-25 14:08:00 -070023#include "SkForceLinking.h"
24#include "SkGraphics.h"
mtklein20840502014-08-21 15:51:22 -070025#include "SkOSFile.h"
26#include "SkPictureRecorder.h"
mtklein051e56d2014-12-04 08:46:51 -080027#include "SkPictureUtils.h"
mtkleinf3723212014-06-25 14:08:00 -070028#include "SkString.h"
29#include "SkSurface.h"
robertphillips5b693772014-11-21 06:19:36 -080030#include "SkTaskGroup.h"
mtkleinf3723212014-06-25 14:08:00 -070031
mtkleinbb6a0282014-07-01 08:43:42 -070032#if SK_SUPPORT_GPU
jcgregoriobf5e5232014-07-17 13:14:16 -070033 #include "gl/GrGLDefines.h"
mtkleinbb6a0282014-07-01 08:43:42 -070034 #include "GrContextFactory.h"
krajcevski69a55602014-08-13 10:46:31 -070035 SkAutoTDelete<GrContextFactory> gGrFactory;
mtkleinbb6a0282014-07-01 08:43:42 -070036#endif
37
mtkleinf3723212014-06-25 14:08:00 -070038__SK_FORCE_IMAGE_DECODER_LINKING;
39
reed53249782014-10-10 09:09:52 -070040static const int kAutoTuneLoops = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -070041
mtkleinb5110422014-08-07 15:20:02 -070042static const int kDefaultLoops =
bsalomon6eb03cc2014-08-07 14:28:50 -070043#ifdef SK_DEBUG
44 1;
mtkleina189ccd2014-07-14 12:28:47 -070045#else
bsalomon6eb03cc2014-08-07 14:28:50 -070046 kAutoTuneLoops;
mtkleina189ccd2014-07-14 12:28:47 -070047#endif
48
bsalomon6eb03cc2014-08-07 14:28:50 -070049static SkString loops_help_txt() {
50 SkString help;
51 help.printf("Number of times to run each bench. Set this to %d to auto-"
52 "tune for each bench. Timings are only reported when auto-tuning.",
53 kAutoTuneLoops);
54 return help;
55}
56
57DEFINE_int32(loops, kDefaultLoops, loops_help_txt().c_str());
58
mtkleinf3723212014-06-25 14:08:00 -070059DEFINE_int32(samples, 10, "Number of samples to measure for each bench.");
60DEFINE_int32(overheadLoops, 100000, "Loops to estimate timer overhead.");
61DEFINE_double(overheadGoal, 0.0001,
62 "Loop until timer overhead is at most this fraction of our measurments.");
mtkleinbb6a0282014-07-01 08:43:42 -070063DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
64DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allows to lag.");
krajcevski12b35442014-08-13 12:06:26 -070065DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to "
66 "software path rendering.");
mtkleinf3723212014-06-25 14:08:00 -070067
mtklein60317d0f2014-07-14 11:30:37 -070068DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
mtklein55b0ffc2014-07-17 08:38:23 -070069DEFINE_int32(maxCalibrationAttempts, 3,
70 "Try up to this many times to guess loops for a bench, or skip the bench.");
71DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this.");
mtklein92007582014-08-01 07:46:52 -070072DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
73DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
mtklein20840502014-08-21 15:51:22 -070074DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
robertphillips5b693772014-11-21 06:19:36 -080075DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
mtkleine070c2b2014-10-14 08:40:43 -070076DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run.");
mtklein55e88b22015-01-21 15:50:13 -080077DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test.");
mtklein92007582014-08-01 07:46:52 -070078
mtkleinf3723212014-06-25 14:08:00 -070079static SkString humanize(double ms) {
mtkleindc5bbab2014-09-24 06:34:09 -070080 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
mtklein748ca3b2015-01-15 10:56:12 -080081 return HumanizeMs(ms);
mtkleinf3723212014-06-25 14:08:00 -070082}
mtklein55b0ffc2014-07-17 08:38:23 -070083#define HUMANIZE(ms) humanize(ms).c_str()
mtkleinf3723212014-06-25 14:08:00 -070084
kkinnunen9e61bb72014-10-09 05:24:15 -070085static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContext* gl) {
bsalomon6eb03cc2014-08-07 14:28:50 -070086 if (canvas) {
87 canvas->clear(SK_ColorWHITE);
88 }
mtkleinbb6a0282014-07-01 08:43:42 -070089 WallTimer timer;
90 timer.start();
91 if (bench) {
92 bench->draw(loops, canvas);
93 }
94 if (canvas) {
95 canvas->flush();
96 }
97#if SK_SUPPORT_GPU
98 if (gl) {
99 SK_GL(*gl, Flush());
100 gl->swapBuffers();
101 }
102#endif
103 timer.end();
104 return timer.fWall;
105}
106
mtkleinf3723212014-06-25 14:08:00 -0700107static double estimate_timer_overhead() {
108 double overhead = 0;
mtkleinf3723212014-06-25 14:08:00 -0700109 for (int i = 0; i < FLAGS_overheadLoops; i++) {
mtkleinbb6a0282014-07-01 08:43:42 -0700110 overhead += time(1, NULL, NULL, NULL);
mtkleinf3723212014-06-25 14:08:00 -0700111 }
112 return overhead / FLAGS_overheadLoops;
113}
114
reed53249782014-10-10 09:09:52 -0700115static int detect_forever_loops(int loops) {
116 // look for a magic run-forever value
117 if (loops < 0) {
118 loops = SK_MaxS32;
119 }
120 return loops;
121}
122
mtklein55b0ffc2014-07-17 08:38:23 -0700123static int clamp_loops(int loops) {
124 if (loops < 1) {
mtklein527930f2014-11-06 08:04:34 -0800125 SkDebugf("ERROR: clamping loops from %d to 1. "
126 "There's probably something wrong with the bench.\n", loops);
mtklein55b0ffc2014-07-17 08:38:23 -0700127 return 1;
128 }
129 if (loops > FLAGS_maxLoops) {
130 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
131 return FLAGS_maxLoops;
132 }
133 return loops;
134}
135
bsalomon6eb03cc2014-08-07 14:28:50 -0700136static bool write_canvas_png(SkCanvas* canvas, const SkString& filename) {
137 if (filename.isEmpty()) {
138 return false;
139 }
reede5ea5002014-09-03 11:54:58 -0700140 if (kUnknown_SkColorType == canvas->imageInfo().colorType()) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700141 return false;
142 }
143 SkBitmap bmp;
144 bmp.setInfo(canvas->imageInfo());
145 if (!canvas->readPixels(&bmp, 0, 0)) {
146 SkDebugf("Can't read canvas pixels.\n");
147 return false;
148 }
149 SkString dir = SkOSPath::Dirname(filename.c_str());
150 if (!sk_mkdir(dir.c_str())) {
151 SkDebugf("Can't make dir %s.\n", dir.c_str());
152 return false;
153 }
154 SkFILEWStream stream(filename.c_str());
155 if (!stream.isValid()) {
156 SkDebugf("Can't write %s.\n", filename.c_str());
157 return false;
158 }
159 if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) {
160 SkDebugf("Can't encode a PNG.\n");
161 return false;
162 }
163 return true;
164}
165
166static int kFailedLoops = -2;
mtkleinbb6a0282014-07-01 08:43:42 -0700167static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas, double* samples) {
168 // First figure out approximately how many loops of bench it takes to make overhead negligible.
mtklein2069e222014-08-04 13:57:39 -0700169 double bench_plus_overhead = 0.0;
mtklein55b0ffc2014-07-17 08:38:23 -0700170 int round = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -0700171 if (kAutoTuneLoops == FLAGS_loops) {
172 while (bench_plus_overhead < overhead) {
173 if (round++ == FLAGS_maxCalibrationAttempts) {
174 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
mtklein96289052014-09-10 12:05:59 -0700175 bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
bsalomon6eb03cc2014-08-07 14:28:50 -0700176 return kFailedLoops;
177 }
178 bench_plus_overhead = time(1, bench, canvas, NULL);
mtklein55b0ffc2014-07-17 08:38:23 -0700179 }
mtklein2069e222014-08-04 13:57:39 -0700180 }
mtkleinf3723212014-06-25 14:08:00 -0700181
mtkleinbb6a0282014-07-01 08:43:42 -0700182 // Later we'll just start and stop the timer once but loop N times.
mtkleinf3723212014-06-25 14:08:00 -0700183 // We'll pick N to make timer overhead negligible:
184 //
mtkleinbb6a0282014-07-01 08:43:42 -0700185 // overhead
186 // ------------------------- < FLAGS_overheadGoal
187 // overhead + N * Bench Time
mtkleinf3723212014-06-25 14:08:00 -0700188 //
mtkleinbb6a0282014-07-01 08:43:42 -0700189 // where bench_plus_overhead ≈ overhead + Bench Time.
mtkleinf3723212014-06-25 14:08:00 -0700190 //
191 // Doing some math, we get:
192 //
mtkleinbb6a0282014-07-01 08:43:42 -0700193 // (overhead / FLAGS_overheadGoal) - overhead
194 // ------------------------------------------ < N
195 // bench_plus_overhead - overhead)
mtkleinf3723212014-06-25 14:08:00 -0700196 //
197 // Luckily, this also works well in practice. :)
bsalomon6eb03cc2014-08-07 14:28:50 -0700198 int loops = FLAGS_loops;
199 if (kAutoTuneLoops == loops) {
200 const double numer = overhead / FLAGS_overheadGoal - overhead;
201 const double denom = bench_plus_overhead - overhead;
202 loops = (int)ceil(numer / denom);
reed53249782014-10-10 09:09:52 -0700203 loops = clamp_loops(loops);
204 } else {
205 loops = detect_forever_loops(loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700206 }
mtkleinbb6a0282014-07-01 08:43:42 -0700207
208 for (int i = 0; i < FLAGS_samples; i++) {
209 samples[i] = time(loops, bench, canvas, NULL) / loops;
210 }
211 return loops;
mtkleinf3723212014-06-25 14:08:00 -0700212}
213
mtkleinbb6a0282014-07-01 08:43:42 -0700214#if SK_SUPPORT_GPU
robertphillips5b693772014-11-21 06:19:36 -0800215static void setup_gl(SkGLContext* gl) {
216 gl->makeCurrent();
217 // Make sure we're done with whatever came before.
218 SK_GL(*gl, Finish());
219}
220
kkinnunen9e61bb72014-10-09 05:24:15 -0700221static int gpu_bench(SkGLContext* gl,
mtkleinbb6a0282014-07-01 08:43:42 -0700222 Benchmark* bench,
223 SkCanvas* canvas,
224 double* samples) {
mtkleinbb6a0282014-07-01 08:43:42 -0700225 // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
bsalomon6eb03cc2014-08-07 14:28:50 -0700226 int loops = FLAGS_loops;
227 if (kAutoTuneLoops == loops) {
228 loops = 1;
mtkleina189ccd2014-07-14 12:28:47 -0700229 double elapsed = 0;
230 do {
mtklein527930f2014-11-06 08:04:34 -0800231 if (1<<30 == loops) {
232 // We're about to wrap. Something's wrong with the bench.
233 loops = 0;
234 break;
235 }
mtkleina189ccd2014-07-14 12:28:47 -0700236 loops *= 2;
237 // If the GPU lets frames lag at all, we need to make sure we're timing
238 // _this_ round, not still timing last round. We force this by looping
239 // more times than any reasonable GPU will allow frames to lag.
240 for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
241 elapsed = time(loops, bench, canvas, gl);
242 }
243 } while (elapsed < FLAGS_gpuMs);
mtkleinbb6a0282014-07-01 08:43:42 -0700244
mtkleina189ccd2014-07-14 12:28:47 -0700245 // We've overshot at least a little. Scale back linearly.
246 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
reed53249782014-10-10 09:09:52 -0700247 loops = clamp_loops(loops);
mtkleinbb6a0282014-07-01 08:43:42 -0700248
mtkleina189ccd2014-07-14 12:28:47 -0700249 // Might as well make sure we're not still timing our calibration.
250 SK_GL(*gl, Finish());
reed53249782014-10-10 09:09:52 -0700251 } else {
252 loops = detect_forever_loops(loops);
mtkleina189ccd2014-07-14 12:28:47 -0700253 }
mtkleinbb6a0282014-07-01 08:43:42 -0700254
255 // Pretty much the same deal as the calibration: do some warmup to make
256 // sure we're timing steady-state pipelined frames.
257 for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
258 time(loops, bench, canvas, gl);
mtkleinf3723212014-06-25 14:08:00 -0700259 }
mtkleinbb6a0282014-07-01 08:43:42 -0700260
261 // Now, actually do the timing!
262 for (int i = 0; i < FLAGS_samples; i++) {
263 samples[i] = time(loops, bench, canvas, gl) / loops;
264 }
265 return loops;
266}
267#endif
268
269static SkString to_lower(const char* str) {
270 SkString lower(str);
271 for (size_t i = 0; i < lower.size(); i++) {
272 lower[i] = tolower(lower[i]);
273 }
274 return lower;
mtkleinf3723212014-06-25 14:08:00 -0700275}
276
bsalomonc2553372014-07-22 13:09:05 -0700277struct Config {
278 const char* name;
mtkleinbb6a0282014-07-01 08:43:42 -0700279 Benchmark::Backend backend;
bsalomonc2553372014-07-22 13:09:05 -0700280 SkColorType color;
281 SkAlphaType alpha;
282 int samples;
283#if SK_SUPPORT_GPU
284 GrContextFactory::GLContextType ctxType;
jvanverth4736e142014-11-07 07:12:46 -0800285 bool useDFText;
bsalomonc2553372014-07-22 13:09:05 -0700286#else
287 int bogusInt;
jvanverth4736e142014-11-07 07:12:46 -0800288 bool bogusBool;
bsalomonc2553372014-07-22 13:09:05 -0700289#endif
290};
291
292struct Target {
293 explicit Target(const Config& c) : config(c) {}
294 const Config config;
mtkleinbb6a0282014-07-01 08:43:42 -0700295 SkAutoTDelete<SkSurface> surface;
296#if SK_SUPPORT_GPU
kkinnunen9e61bb72014-10-09 05:24:15 -0700297 SkGLContext* gl;
mtkleinbb6a0282014-07-01 08:43:42 -0700298#endif
299};
mtkleinf3723212014-06-25 14:08:00 -0700300
bsalomonc2553372014-07-22 13:09:05 -0700301static bool is_cpu_config_allowed(const char* name) {
mtkleinbb6a0282014-07-01 08:43:42 -0700302 for (int i = 0; i < FLAGS_config.count(); i++) {
bsalomonc2553372014-07-22 13:09:05 -0700303 if (to_lower(FLAGS_config[i]).equals(name)) {
304 return true;
mtkleinf3723212014-06-25 14:08:00 -0700305 }
306 }
bsalomonc2553372014-07-22 13:09:05 -0700307 return false;
mtkleinbb6a0282014-07-01 08:43:42 -0700308}
309
bsalomonc2553372014-07-22 13:09:05 -0700310#if SK_SUPPORT_GPU
311static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextType ctxType,
312 int sampleCnt) {
313 if (!is_cpu_config_allowed(name)) {
314 return false;
315 }
krajcevski69a55602014-08-13 10:46:31 -0700316 if (const GrContext* ctx = gGrFactory->get(ctxType)) {
bsalomonc2553372014-07-22 13:09:05 -0700317 return sampleCnt <= ctx->getMaxSampleCount();
318 }
319 return false;
320}
321#endif
mtkleinbb6a0282014-07-01 08:43:42 -0700322
bsalomonc2553372014-07-22 13:09:05 -0700323#if SK_SUPPORT_GPU
324#define kBogusGLContextType GrContextFactory::kNative_GLContextType
325#else
326#define kBogusGLContextType 0
mtkleine714e752014-07-31 12:13:48 -0700327#endif
bsalomonc2553372014-07-22 13:09:05 -0700328
329// Append all configs that are enabled and supported.
330static void create_configs(SkTDArray<Config>* configs) {
jvanverth4736e142014-11-07 07:12:46 -0800331 #define CPU_CONFIG(name, backend, color, alpha) \
332 if (is_cpu_config_allowed(#name)) { \
333 Config config = { #name, Benchmark::backend, color, alpha, 0, \
334 kBogusGLContextType, false }; \
335 configs->push(config); \
mtkleinbb6a0282014-07-01 08:43:42 -0700336 }
mtkleine714e752014-07-31 12:13:48 -0700337
mtklein40b32be2014-07-09 08:46:49 -0700338 if (FLAGS_cpu) {
bsalomonc2553372014-07-22 13:09:05 -0700339 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kUnpremul_SkAlphaType)
340 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType)
341 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType)
mtklein40b32be2014-07-09 08:46:49 -0700342 }
mtkleinbb6a0282014-07-01 08:43:42 -0700343
344#if SK_SUPPORT_GPU
jvanverth4736e142014-11-07 07:12:46 -0800345 #define GPU_CONFIG(name, ctxType, samples, useDFText) \
bsalomonc2553372014-07-22 13:09:05 -0700346 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \
347 Config config = { \
348 #name, \
349 Benchmark::kGPU_Backend, \
350 kN32_SkColorType, \
351 kPremul_SkAlphaType, \
352 samples, \
jvanverth4736e142014-11-07 07:12:46 -0800353 GrContextFactory::ctxType, \
354 useDFText }; \
bsalomonc2553372014-07-22 13:09:05 -0700355 configs->push(config); \
mtkleinbb6a0282014-07-01 08:43:42 -0700356 }
mtkleine714e752014-07-31 12:13:48 -0700357
mtklein40b32be2014-07-09 08:46:49 -0700358 if (FLAGS_gpu) {
jvanverth4736e142014-11-07 07:12:46 -0800359 GPU_CONFIG(gpu, kNative_GLContextType, 0, false)
360 GPU_CONFIG(msaa4, kNative_GLContextType, 4, false)
361 GPU_CONFIG(msaa16, kNative_GLContextType, 16, false)
362 GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4, false)
363 GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16, false)
364 GPU_CONFIG(gpudft, kNative_GLContextType, 0, true)
365 GPU_CONFIG(debug, kDebug_GLContextType, 0, false)
366 GPU_CONFIG(nullgpu, kNull_GLContextType, 0, false)
bsalomon3b4d0772014-08-06 10:52:33 -0700367#ifdef SK_ANGLE
jvanverth4736e142014-11-07 07:12:46 -0800368 GPU_CONFIG(angle, kANGLE_GLContextType, 0, false)
bsalomon3b4d0772014-08-06 10:52:33 -0700369#endif
mtklein40b32be2014-07-09 08:46:49 -0700370 }
mtkleinbb6a0282014-07-01 08:43:42 -0700371#endif
mtkleinf3723212014-06-25 14:08:00 -0700372}
373
bsalomonc2553372014-07-22 13:09:05 -0700374// If bench is enabled for config, returns a Target* for it, otherwise NULL.
375static Target* is_enabled(Benchmark* bench, const Config& config) {
376 if (!bench->isSuitableFor(config.backend)) {
377 return NULL;
378 }
379
reede5ea5002014-09-03 11:54:58 -0700380 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
381 config.color, config.alpha);
bsalomonc2553372014-07-22 13:09:05 -0700382
383 Target* target = new Target(config);
384
385 if (Benchmark::kRaster_Backend == config.backend) {
386 target->surface.reset(SkSurface::NewRaster(info));
387 }
388#if SK_SUPPORT_GPU
389 else if (Benchmark::kGPU_Backend == config.backend) {
jvanverth4736e142014-11-07 07:12:46 -0800390 uint32_t flags = config.useDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
391 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
bsalomonafe30052015-01-16 07:32:33 -0800392 target->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(config.ctxType),
393 SkSurface::kNo_Budgeted, info,
jvanverth4736e142014-11-07 07:12:46 -0800394 config.samples, &props));
krajcevski69a55602014-08-13 10:46:31 -0700395 target->gl = gGrFactory->getGLContext(config.ctxType);
bsalomonc2553372014-07-22 13:09:05 -0700396 }
397#endif
398
399 if (Benchmark::kNonRendering_Backend != config.backend && !target->surface.get()) {
400 delete target;
401 return NULL;
402 }
403 return target;
404}
405
406// Creates targets for a benchmark and a set of configs.
407static void create_targets(SkTDArray<Target*>* targets, Benchmark* b,
408 const SkTDArray<Config>& configs) {
409 for (int i = 0; i < configs.count(); ++i) {
410 if (Target* t = is_enabled(b, configs[i])) {
411 targets->push(t);
412 }
mtkleine714e752014-07-31 12:13:48 -0700413
bsalomonc2553372014-07-22 13:09:05 -0700414 }
415}
416
jcgregoriobf5e5232014-07-17 13:14:16 -0700417#if SK_SUPPORT_GPU
kkinnunen9e61bb72014-10-09 05:24:15 -0700418static void fill_gpu_options(ResultsWriter* log, SkGLContext* ctx) {
jcgregorio05c45602014-07-17 13:54:36 -0700419 const GrGLubyte* version;
jcgregoriobf5e5232014-07-17 13:14:16 -0700420 SK_GL_RET(*ctx, version, GetString(GR_GL_VERSION));
421 log->configOption("GL_VERSION", (const char*)(version));
422
423 SK_GL_RET(*ctx, version, GetString(GR_GL_RENDERER));
424 log->configOption("GL_RENDERER", (const char*) version);
425
426 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR));
427 log->configOption("GL_VENDOR", (const char*) version);
428
429 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
430 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
431}
432#endif
433
mtkleine714e752014-07-31 12:13:48 -0700434class BenchmarkStream {
435public:
mtklein92007582014-08-01 07:46:52 -0700436 BenchmarkStream() : fBenches(BenchRegistry::Head())
437 , fGMs(skiagm::GMRegistry::Head())
mtkleinfd731ce2014-09-10 12:19:30 -0700438 , fCurrentRecording(0)
mtklein92007582014-08-01 07:46:52 -0700439 , fCurrentScale(0)
robertphillips5b693772014-11-21 06:19:36 -0800440 , fCurrentSKP(0)
441 , fCurrentUseMPD(0) {
mtklein92007582014-08-01 07:46:52 -0700442 for (int i = 0; i < FLAGS_skps.count(); i++) {
443 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
444 fSKPs.push_back() = FLAGS_skps[i];
445 } else {
446 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
447 SkString path;
448 while (it.next(&path)) {
449 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
450 }
451 }
452 }
mtkleine714e752014-07-31 12:13:48 -0700453
mtklein92007582014-08-01 07:46:52 -0700454 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
455 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
456 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
457 exit(1);
458 }
459
460 for (int i = 0; i < FLAGS_scales.count(); i++) {
461 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
462 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
463 exit(1);
464 }
465 }
robertphillips5b693772014-11-21 06:19:36 -0800466
467 fUseMPDs.push_back() = false;
468 if (FLAGS_mpd) {
469 fUseMPDs.push_back() = true;
470 }
mtklein92007582014-08-01 07:46:52 -0700471 }
472
mtkleinfd731ce2014-09-10 12:19:30 -0700473 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
474 // Not strictly necessary, as it will be checked again later,
475 // but helps to avoid a lot of pointless work if we're going to skip it.
476 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
477 return false;
478 }
479
scroggoa1193e42015-01-21 12:09:53 -0800480 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
mtkleinfd731ce2014-09-10 12:19:30 -0700481 if (stream.get() == NULL) {
482 SkDebugf("Could not read %s.\n", path);
483 return false;
484 }
485
mtklein535776e2014-11-25 14:57:26 -0800486 pic->reset(SkPicture::CreateFromStream(stream.get()));
mtkleinfd731ce2014-09-10 12:19:30 -0700487 if (pic->get() == NULL) {
488 SkDebugf("Could not read %s as an SkPicture.\n", path);
489 return false;
490 }
491 return true;
492 }
493
mtklein92007582014-08-01 07:46:52 -0700494 Benchmark* next() {
mtkleine714e752014-07-31 12:13:48 -0700495 if (fBenches) {
496 Benchmark* bench = fBenches->factory()(NULL);
497 fBenches = fBenches->next();
mtklein92007582014-08-01 07:46:52 -0700498 fSourceType = "bench";
mtkleinfd731ce2014-09-10 12:19:30 -0700499 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700500 return bench;
501 }
mtklein92007582014-08-01 07:46:52 -0700502
mtkleine714e752014-07-31 12:13:48 -0700503 while (fGMs) {
504 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL));
505 fGMs = fGMs->next();
506 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) {
mtklein92007582014-08-01 07:46:52 -0700507 fSourceType = "gm";
mtkleinfd731ce2014-09-10 12:19:30 -0700508 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700509 return SkNEW_ARGS(GMBench, (gm.detach()));
510 }
511 }
mtklein92007582014-08-01 07:46:52 -0700512
mtkleinfd731ce2014-09-10 12:19:30 -0700513 // First add all .skps as RecordingBenches.
514 while (fCurrentRecording < fSKPs.count()) {
515 const SkString& path = fSKPs[fCurrentRecording++];
516 SkAutoTUnref<SkPicture> pic;
517 if (!ReadPicture(path.c_str(), &pic)) {
518 continue;
519 }
520 SkString name = SkOSPath::Basename(path.c_str());
521 fSourceType = "skp";
522 fBenchType = "recording";
bsalomon0aa5cea2014-12-15 09:13:35 -0800523 fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic));
mtklein051e56d2014-12-04 08:46:51 -0800524 fSKPOps = pic->approximateOpCount();
mtkleinfd731ce2014-09-10 12:19:30 -0700525 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bbh));
526 }
527
528 // Then once each for each scale as SKPBenches (playback).
mtklein92007582014-08-01 07:46:52 -0700529 while (fCurrentScale < fScales.count()) {
530 while (fCurrentSKP < fSKPs.count()) {
robertphillips5b693772014-11-21 06:19:36 -0800531 const SkString& path = fSKPs[fCurrentSKP];
mtkleinfd731ce2014-09-10 12:19:30 -0700532 SkAutoTUnref<SkPicture> pic;
533 if (!ReadPicture(path.c_str(), &pic)) {
robertphillips5b693772014-11-21 06:19:36 -0800534 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700535 continue;
536 }
robertphillips5b693772014-11-21 06:19:36 -0800537
538 while (fCurrentUseMPD < fUseMPDs.count()) {
539 if (FLAGS_bbh) {
540 // The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
541 SkRTreeFactory factory;
542 SkPictureRecorder recorder;
543 static const int kFlags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
544 pic->playback(recorder.beginRecording(pic->cullRect().width(),
545 pic->cullRect().height(),
mtklein748ca3b2015-01-15 10:56:12 -0800546 &factory,
robertphillipse451c4d2014-12-09 10:28:00 -0800547 fUseMPDs[fCurrentUseMPD] ? kFlags : 0));
robertphillips5b693772014-11-21 06:19:36 -0800548 pic.reset(recorder.endRecording());
549 }
550 SkString name = SkOSPath::Basename(path.c_str());
551 fSourceType = "skp";
552 fBenchType = "playback";
553 return SkNEW_ARGS(SKPBench,
554 (name.c_str(), pic.get(), fClip,
555 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]));
mtklein20840502014-08-21 15:51:22 -0700556 }
robertphillips5b693772014-11-21 06:19:36 -0800557 fCurrentUseMPD = 0;
558 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700559 }
560 fCurrentSKP = 0;
561 fCurrentScale++;
562 }
563
mtkleine714e752014-07-31 12:13:48 -0700564 return NULL;
565 }
mtklein92007582014-08-01 07:46:52 -0700566
567 void fillCurrentOptions(ResultsWriter* log) const {
568 log->configOption("source_type", fSourceType);
mtkleinfd731ce2014-09-10 12:19:30 -0700569 log->configOption("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -0700570 if (0 == strcmp(fSourceType, "skp")) {
571 log->configOption("clip",
572 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
573 fClip.fRight, fClip.fBottom).c_str());
574 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
robertphillips5b693772014-11-21 06:19:36 -0800575 if (fCurrentUseMPD > 0) {
576 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
577 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
578 }
mtklein92007582014-08-01 07:46:52 -0700579 }
mtklein051e56d2014-12-04 08:46:51 -0800580 if (0 == strcmp(fBenchType, "recording")) {
581 log->metric("bytes", fSKPBytes);
582 log->metric("ops", fSKPOps);
583 }
mtklein92007582014-08-01 07:46:52 -0700584 }
585
mtkleine714e752014-07-31 12:13:48 -0700586private:
587 const BenchRegistry* fBenches;
588 const skiagm::GMRegistry* fGMs;
mtklein92007582014-08-01 07:46:52 -0700589 SkIRect fClip;
590 SkTArray<SkScalar> fScales;
591 SkTArray<SkString> fSKPs;
robertphillips5b693772014-11-21 06:19:36 -0800592 SkTArray<bool> fUseMPDs;
mtklein92007582014-08-01 07:46:52 -0700593
mtklein051e56d2014-12-04 08:46:51 -0800594 double fSKPBytes, fSKPOps;
595
mtkleinfd731ce2014-09-10 12:19:30 -0700596 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
597 const char* fBenchType; // How we bench it: micro, recording, playback, ...
598 int fCurrentRecording;
mtklein92007582014-08-01 07:46:52 -0700599 int fCurrentScale;
600 int fCurrentSKP;
robertphillips5b693772014-11-21 06:19:36 -0800601 int fCurrentUseMPD;
mtkleine714e752014-07-31 12:13:48 -0700602};
603
jcgregorio3b27ade2014-11-13 08:06:40 -0800604int nanobench_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700605int nanobench_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800606 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -0700607 SkAutoGraphics ag;
mtklein4f108442014-12-03 13:07:39 -0800608 SkTaskGroup::Enabler enabled;
mtkleinf3723212014-06-25 14:08:00 -0700609
krajcevski69a55602014-08-13 10:46:31 -0700610#if SK_SUPPORT_GPU
krajcevski12b35442014-08-13 12:06:26 -0700611 GrContext::Options grContextOpts;
612 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
613 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts)));
krajcevski69a55602014-08-13 10:46:31 -0700614#endif
615
bsalomon06cddec2014-10-24 10:40:50 -0700616 if (FLAGS_veryVerbose) {
617 FLAGS_verbose = true;
618 }
619
bsalomon6eb03cc2014-08-07 14:28:50 -0700620 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700621 FLAGS_samples = 1;
622 FLAGS_gpuFrameLag = 0;
623 }
624
bsalomon6eb03cc2014-08-07 14:28:50 -0700625 if (!FLAGS_writePath.isEmpty()) {
626 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
627 if (!sk_mkdir(FLAGS_writePath[0])) {
628 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
629 FLAGS_writePath.set(0, NULL);
630 }
631 }
632
mtklein1915b622014-08-20 11:45:00 -0700633 SkAutoTDelete<ResultsWriter> log(SkNEW(ResultsWriter));
mtklein60317d0f2014-07-14 11:30:37 -0700634 if (!FLAGS_outResultsFile.isEmpty()) {
mtklein1915b622014-08-20 11:45:00 -0700635 log.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0])));
mtklein60317d0f2014-07-14 11:30:37 -0700636 }
mtklein1915b622014-08-20 11:45:00 -0700637
638 if (1 == FLAGS_properties.count() % 2) {
639 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
640 return 1;
641 }
642 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
643 log->property(FLAGS_properties[i-1], FLAGS_properties[i]);
644 }
jcgregoriobf5e5232014-07-17 13:14:16 -0700645
646 if (1 == FLAGS_key.count() % 2) {
647 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
648 return 1;
649 }
650 for (int i = 1; i < FLAGS_key.count(); i += 2) {
mtklein1915b622014-08-20 11:45:00 -0700651 log->key(FLAGS_key[i-1], FLAGS_key[i]);
mtklein94e51562014-08-19 12:41:53 -0700652 }
mtklein60317d0f2014-07-14 11:30:37 -0700653
mtkleinf3723212014-06-25 14:08:00 -0700654 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -0700655 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -0400656
mtkleinbb6a0282014-07-01 08:43:42 -0700657 SkAutoTMalloc<double> samples(FLAGS_samples);
658
bsalomon6eb03cc2014-08-07 14:28:50 -0700659 if (kAutoTuneLoops != FLAGS_loops) {
660 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleina189ccd2014-07-14 12:28:47 -0700661 } else if (FLAGS_verbose) {
mtkleinf3723212014-06-25 14:08:00 -0700662 // No header.
663 } else if (FLAGS_quiet) {
mtklein40b32be2014-07-09 08:46:49 -0700664 SkDebugf("median\tbench\tconfig\n");
mtkleinf3723212014-06-25 14:08:00 -0700665 } else {
qiankun.miao8247ec32014-09-09 19:24:36 -0700666 SkDebugf("maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
667 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -0700668 }
669
bsalomonc2553372014-07-22 13:09:05 -0700670 SkTDArray<Config> configs;
671 create_configs(&configs);
672
mtkleine070c2b2014-10-14 08:40:43 -0700673 int runs = 0;
mtklein92007582014-08-01 07:46:52 -0700674 BenchmarkStream benchStream;
675 while (Benchmark* b = benchStream.next()) {
mtkleine714e752014-07-31 12:13:48 -0700676 SkAutoTDelete<Benchmark> bench(b);
mtklein96289052014-09-10 12:05:59 -0700677 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -0700678 continue;
679 }
680
mtkleinbb6a0282014-07-01 08:43:42 -0700681 SkTDArray<Target*> targets;
bsalomonc2553372014-07-22 13:09:05 -0700682 create_targets(&targets, bench.get(), configs);
mtkleinf3723212014-06-25 14:08:00 -0700683
jcgregoriobf5e5232014-07-17 13:14:16 -0700684 if (!targets.isEmpty()) {
mtklein96289052014-09-10 12:05:59 -0700685 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
jcgregoriobf5e5232014-07-17 13:14:16 -0700686 bench->preDraw();
687 }
mtkleinbb6a0282014-07-01 08:43:42 -0700688 for (int j = 0; j < targets.count(); j++) {
689 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->getCanvas() : NULL;
bsalomonc2553372014-07-22 13:09:05 -0700690 const char* config = targets[j]->config.name;
mtkleinf3723212014-06-25 14:08:00 -0700691
robertphillips5b693772014-11-21 06:19:36 -0800692#if SK_SUPPORT_GPU
693 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
694 setup_gl(targets[j]->gl);
695 }
696#endif
697
698 bench->perCanvasPreDraw(canvas);
699
mtkleinbb6a0282014-07-01 08:43:42 -0700700 const int loops =
701#if SK_SUPPORT_GPU
bsalomonc2553372014-07-22 13:09:05 -0700702 Benchmark::kGPU_Backend == targets[j]->config.backend
mtkleinbb6a0282014-07-01 08:43:42 -0700703 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
704 :
705#endif
706 cpu_bench( overhead, bench.get(), canvas, samples.get());
mtkleinf3723212014-06-25 14:08:00 -0700707
robertphillips5b693772014-11-21 06:19:36 -0800708 bench->perCanvasPostDraw(canvas);
709
bsalomon49f085d2014-09-05 13:34:00 -0700710 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700711 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -0700712 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -0700713 pngFilename.append(".png");
714 write_canvas_png(canvas, pngFilename);
715 }
716
717 if (kFailedLoops == loops) {
mtklein2069e222014-08-04 13:57:39 -0700718 // Can't be timed. A warning note has already been printed.
Mike Kleine3631362014-07-15 17:56:37 -0400719 continue;
720 }
721
mtkleinf3723212014-06-25 14:08:00 -0700722 Stats stats(samples.get(), FLAGS_samples);
mtklein1915b622014-08-20 11:45:00 -0700723 log->config(config);
mtklein96289052014-09-10 12:05:59 -0700724 log->configOption("name", bench->getName());
mtklein1915b622014-08-20 11:45:00 -0700725 benchStream.fillCurrentOptions(log.get());
jcgregoriobf5e5232014-07-17 13:14:16 -0700726#if SK_SUPPORT_GPU
bsalomonc2553372014-07-22 13:09:05 -0700727 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
mtklein1915b622014-08-20 11:45:00 -0700728 fill_gpu_options(log.get(), targets[j]->gl);
jcgregoriobf5e5232014-07-17 13:14:16 -0700729 }
730#endif
mtklein051e56d2014-12-04 08:46:51 -0800731 log->metric("min_ms", stats.min);
mtkleine070c2b2014-10-14 08:40:43 -0700732 if (runs++ % FLAGS_flushEvery == 0) {
733 log->flush();
734 }
mtklein60317d0f2014-07-14 11:30:37 -0700735
bsalomon6eb03cc2014-08-07 14:28:50 -0700736 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700737 if (targets.count() == 1) {
738 config = ""; // Only print the config if we run the same bench on more than one.
739 }
mtklein53d25622014-09-18 07:39:42 -0700740 SkDebugf("%4dM\t%s\t%s\n"
741 , sk_tools::getMaxResidentSetSizeMB()
742 , bench->getUniqueName()
743 , config);
mtkleina189ccd2014-07-14 12:28:47 -0700744 } else if (FLAGS_verbose) {
mtkleinf3723212014-06-25 14:08:00 -0700745 for (int i = 0; i < FLAGS_samples; i++) {
mtklein55b0ffc2014-07-17 08:38:23 -0700746 SkDebugf("%s ", HUMANIZE(samples[i]));
mtkleinf3723212014-06-25 14:08:00 -0700747 }
mtklein96289052014-09-10 12:05:59 -0700748 SkDebugf("%s\n", bench->getUniqueName());
mtkleinf3723212014-06-25 14:08:00 -0700749 } else if (FLAGS_quiet) {
mtkleinbb6a0282014-07-01 08:43:42 -0700750 if (targets.count() == 1) {
mtkleinf3723212014-06-25 14:08:00 -0700751 config = ""; // Only print the config if we run the same bench on more than one.
752 }
mtklein96289052014-09-10 12:05:59 -0700753 SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getUniqueName(), config);
mtkleinf3723212014-06-25 14:08:00 -0700754 } else {
755 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
mtkleinafb43792014-08-19 15:55:55 -0700756 SkDebugf("%4dM\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n"
757 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -0700758 , loops
mtklein55b0ffc2014-07-17 08:38:23 -0700759 , HUMANIZE(stats.min)
760 , HUMANIZE(stats.median)
761 , HUMANIZE(stats.mean)
762 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -0700763 , stddev_percent
mtklein5d9d10e2014-07-11 11:57:07 -0700764 , stats.plot.c_str()
mtkleinf3723212014-06-25 14:08:00 -0700765 , config
mtklein96289052014-09-10 12:05:59 -0700766 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -0700767 );
768 }
bsalomon06cddec2014-10-24 10:40:50 -0700769#if SK_SUPPORT_GPU && GR_CACHE_STATS
770 if (FLAGS_veryVerbose &&
771 Benchmark::kGPU_Backend == targets[j]->config.backend) {
mtklein6838d852014-10-29 14:15:10 -0700772 gGrFactory->get(targets[j]->config.ctxType)->printCacheStats();
bsalomon06cddec2014-10-24 10:40:50 -0700773 }
774#endif
mtkleinf3723212014-06-25 14:08:00 -0700775 }
mtkleinbb6a0282014-07-01 08:43:42 -0700776 targets.deleteAll();
Mike Klein3944a1d2014-07-15 13:40:19 -0400777
bsalomon06cddec2014-10-24 10:40:50 -0700778#if SK_SUPPORT_GPU
bsalomon2354f842014-07-28 13:48:36 -0700779 if (FLAGS_abandonGpuContext) {
krajcevski69a55602014-08-13 10:46:31 -0700780 gGrFactory->abandonContexts();
bsalomon2354f842014-07-28 13:48:36 -0700781 }
782 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) {
krajcevski69a55602014-08-13 10:46:31 -0700783 gGrFactory->destroyContexts();
Mike Klein3944a1d2014-07-15 13:40:19 -0400784 }
bsalomon06cddec2014-10-24 10:40:50 -0700785#endif
mtkleinf3723212014-06-25 14:08:00 -0700786 }
787
mtkleine1091452014-12-04 10:47:02 -0800788 log->bench("memory_usage", 0,0);
789 log->config("meta");
790 log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
791
mtkleinf3723212014-06-25 14:08:00 -0700792 return 0;
793}
794
jcgregorio3b27ade2014-11-13 08:06:40 -0800795#if !defined SK_BUILD_FOR_IOS
796int main(int argc, char** argv) {
797 SkCommandLineFlags::Parse(argc, argv);
798 return nanobench_main();
799}
800#endif