blob: a64cbcaf1f7ea75e230f56ff257319460e0c4cd8 [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.");
mtklein92007582014-08-01 07:46:52 -070077
mtkleinf3723212014-06-25 14:08:00 -070078static SkString humanize(double ms) {
mtkleindc5bbab2014-09-24 06:34:09 -070079 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
80 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3);
81 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6);
mtklein62386882014-07-15 10:30:31 -070082#ifdef SK_BUILD_FOR_WIN
mtkleindc5bbab2014-09-24 06:34:09 -070083 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3);
mtklein62386882014-07-15 10:30:31 -070084#else
mtkleindc5bbab2014-09-24 06:34:09 -070085 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3);
mtklein62386882014-07-15 10:30:31 -070086#endif
mtkleinf3723212014-06-25 14:08:00 -070087 return SkStringPrintf("%.3gms", ms);
88}
mtklein55b0ffc2014-07-17 08:38:23 -070089#define HUMANIZE(ms) humanize(ms).c_str()
mtkleinf3723212014-06-25 14:08:00 -070090
kkinnunen9e61bb72014-10-09 05:24:15 -070091static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContext* gl) {
bsalomon6eb03cc2014-08-07 14:28:50 -070092 if (canvas) {
93 canvas->clear(SK_ColorWHITE);
94 }
mtkleinbb6a0282014-07-01 08:43:42 -070095 WallTimer timer;
96 timer.start();
97 if (bench) {
98 bench->draw(loops, canvas);
99 }
100 if (canvas) {
101 canvas->flush();
102 }
103#if SK_SUPPORT_GPU
104 if (gl) {
105 SK_GL(*gl, Flush());
106 gl->swapBuffers();
107 }
108#endif
109 timer.end();
110 return timer.fWall;
111}
112
mtkleinf3723212014-06-25 14:08:00 -0700113static double estimate_timer_overhead() {
114 double overhead = 0;
mtkleinf3723212014-06-25 14:08:00 -0700115 for (int i = 0; i < FLAGS_overheadLoops; i++) {
mtkleinbb6a0282014-07-01 08:43:42 -0700116 overhead += time(1, NULL, NULL, NULL);
mtkleinf3723212014-06-25 14:08:00 -0700117 }
118 return overhead / FLAGS_overheadLoops;
119}
120
reed53249782014-10-10 09:09:52 -0700121static int detect_forever_loops(int loops) {
122 // look for a magic run-forever value
123 if (loops < 0) {
124 loops = SK_MaxS32;
125 }
126 return loops;
127}
128
mtklein55b0ffc2014-07-17 08:38:23 -0700129static int clamp_loops(int loops) {
130 if (loops < 1) {
mtklein527930f2014-11-06 08:04:34 -0800131 SkDebugf("ERROR: clamping loops from %d to 1. "
132 "There's probably something wrong with the bench.\n", loops);
mtklein55b0ffc2014-07-17 08:38:23 -0700133 return 1;
134 }
135 if (loops > FLAGS_maxLoops) {
136 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
137 return FLAGS_maxLoops;
138 }
139 return loops;
140}
141
bsalomon6eb03cc2014-08-07 14:28:50 -0700142static bool write_canvas_png(SkCanvas* canvas, const SkString& filename) {
143 if (filename.isEmpty()) {
144 return false;
145 }
reede5ea5002014-09-03 11:54:58 -0700146 if (kUnknown_SkColorType == canvas->imageInfo().colorType()) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700147 return false;
148 }
149 SkBitmap bmp;
150 bmp.setInfo(canvas->imageInfo());
151 if (!canvas->readPixels(&bmp, 0, 0)) {
152 SkDebugf("Can't read canvas pixels.\n");
153 return false;
154 }
155 SkString dir = SkOSPath::Dirname(filename.c_str());
156 if (!sk_mkdir(dir.c_str())) {
157 SkDebugf("Can't make dir %s.\n", dir.c_str());
158 return false;
159 }
160 SkFILEWStream stream(filename.c_str());
161 if (!stream.isValid()) {
162 SkDebugf("Can't write %s.\n", filename.c_str());
163 return false;
164 }
165 if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) {
166 SkDebugf("Can't encode a PNG.\n");
167 return false;
168 }
169 return true;
170}
171
172static int kFailedLoops = -2;
mtkleinbb6a0282014-07-01 08:43:42 -0700173static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas, double* samples) {
174 // First figure out approximately how many loops of bench it takes to make overhead negligible.
mtklein2069e222014-08-04 13:57:39 -0700175 double bench_plus_overhead = 0.0;
mtklein55b0ffc2014-07-17 08:38:23 -0700176 int round = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -0700177 if (kAutoTuneLoops == FLAGS_loops) {
178 while (bench_plus_overhead < overhead) {
179 if (round++ == FLAGS_maxCalibrationAttempts) {
180 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
mtklein96289052014-09-10 12:05:59 -0700181 bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
bsalomon6eb03cc2014-08-07 14:28:50 -0700182 return kFailedLoops;
183 }
184 bench_plus_overhead = time(1, bench, canvas, NULL);
mtklein55b0ffc2014-07-17 08:38:23 -0700185 }
mtklein2069e222014-08-04 13:57:39 -0700186 }
mtkleinf3723212014-06-25 14:08:00 -0700187
mtkleinbb6a0282014-07-01 08:43:42 -0700188 // Later we'll just start and stop the timer once but loop N times.
mtkleinf3723212014-06-25 14:08:00 -0700189 // We'll pick N to make timer overhead negligible:
190 //
mtkleinbb6a0282014-07-01 08:43:42 -0700191 // overhead
192 // ------------------------- < FLAGS_overheadGoal
193 // overhead + N * Bench Time
mtkleinf3723212014-06-25 14:08:00 -0700194 //
mtkleinbb6a0282014-07-01 08:43:42 -0700195 // where bench_plus_overhead ≈ overhead + Bench Time.
mtkleinf3723212014-06-25 14:08:00 -0700196 //
197 // Doing some math, we get:
198 //
mtkleinbb6a0282014-07-01 08:43:42 -0700199 // (overhead / FLAGS_overheadGoal) - overhead
200 // ------------------------------------------ < N
201 // bench_plus_overhead - overhead)
mtkleinf3723212014-06-25 14:08:00 -0700202 //
203 // Luckily, this also works well in practice. :)
bsalomon6eb03cc2014-08-07 14:28:50 -0700204 int loops = FLAGS_loops;
205 if (kAutoTuneLoops == loops) {
206 const double numer = overhead / FLAGS_overheadGoal - overhead;
207 const double denom = bench_plus_overhead - overhead;
208 loops = (int)ceil(numer / denom);
reed53249782014-10-10 09:09:52 -0700209 loops = clamp_loops(loops);
210 } else {
211 loops = detect_forever_loops(loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700212 }
mtkleinbb6a0282014-07-01 08:43:42 -0700213
214 for (int i = 0; i < FLAGS_samples; i++) {
215 samples[i] = time(loops, bench, canvas, NULL) / loops;
216 }
217 return loops;
mtkleinf3723212014-06-25 14:08:00 -0700218}
219
mtkleinbb6a0282014-07-01 08:43:42 -0700220#if SK_SUPPORT_GPU
robertphillips5b693772014-11-21 06:19:36 -0800221static void setup_gl(SkGLContext* gl) {
222 gl->makeCurrent();
223 // Make sure we're done with whatever came before.
224 SK_GL(*gl, Finish());
225}
226
kkinnunen9e61bb72014-10-09 05:24:15 -0700227static int gpu_bench(SkGLContext* gl,
mtkleinbb6a0282014-07-01 08:43:42 -0700228 Benchmark* bench,
229 SkCanvas* canvas,
230 double* samples) {
mtkleinbb6a0282014-07-01 08:43:42 -0700231 // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
bsalomon6eb03cc2014-08-07 14:28:50 -0700232 int loops = FLAGS_loops;
233 if (kAutoTuneLoops == loops) {
234 loops = 1;
mtkleina189ccd2014-07-14 12:28:47 -0700235 double elapsed = 0;
236 do {
mtklein527930f2014-11-06 08:04:34 -0800237 if (1<<30 == loops) {
238 // We're about to wrap. Something's wrong with the bench.
239 loops = 0;
240 break;
241 }
mtkleina189ccd2014-07-14 12:28:47 -0700242 loops *= 2;
243 // If the GPU lets frames lag at all, we need to make sure we're timing
244 // _this_ round, not still timing last round. We force this by looping
245 // more times than any reasonable GPU will allow frames to lag.
246 for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
247 elapsed = time(loops, bench, canvas, gl);
248 }
249 } while (elapsed < FLAGS_gpuMs);
mtkleinbb6a0282014-07-01 08:43:42 -0700250
mtkleina189ccd2014-07-14 12:28:47 -0700251 // We've overshot at least a little. Scale back linearly.
252 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
reed53249782014-10-10 09:09:52 -0700253 loops = clamp_loops(loops);
mtkleinbb6a0282014-07-01 08:43:42 -0700254
mtkleina189ccd2014-07-14 12:28:47 -0700255 // Might as well make sure we're not still timing our calibration.
256 SK_GL(*gl, Finish());
reed53249782014-10-10 09:09:52 -0700257 } else {
258 loops = detect_forever_loops(loops);
mtkleina189ccd2014-07-14 12:28:47 -0700259 }
mtkleinbb6a0282014-07-01 08:43:42 -0700260
261 // Pretty much the same deal as the calibration: do some warmup to make
262 // sure we're timing steady-state pipelined frames.
263 for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
264 time(loops, bench, canvas, gl);
mtkleinf3723212014-06-25 14:08:00 -0700265 }
mtkleinbb6a0282014-07-01 08:43:42 -0700266
267 // Now, actually do the timing!
268 for (int i = 0; i < FLAGS_samples; i++) {
269 samples[i] = time(loops, bench, canvas, gl) / loops;
270 }
271 return loops;
272}
273#endif
274
275static SkString to_lower(const char* str) {
276 SkString lower(str);
277 for (size_t i = 0; i < lower.size(); i++) {
278 lower[i] = tolower(lower[i]);
279 }
280 return lower;
mtkleinf3723212014-06-25 14:08:00 -0700281}
282
bsalomonc2553372014-07-22 13:09:05 -0700283struct Config {
284 const char* name;
mtkleinbb6a0282014-07-01 08:43:42 -0700285 Benchmark::Backend backend;
bsalomonc2553372014-07-22 13:09:05 -0700286 SkColorType color;
287 SkAlphaType alpha;
288 int samples;
289#if SK_SUPPORT_GPU
290 GrContextFactory::GLContextType ctxType;
jvanverth4736e142014-11-07 07:12:46 -0800291 bool useDFText;
bsalomonc2553372014-07-22 13:09:05 -0700292#else
293 int bogusInt;
jvanverth4736e142014-11-07 07:12:46 -0800294 bool bogusBool;
bsalomonc2553372014-07-22 13:09:05 -0700295#endif
296};
297
298struct Target {
299 explicit Target(const Config& c) : config(c) {}
300 const Config config;
mtkleinbb6a0282014-07-01 08:43:42 -0700301 SkAutoTDelete<SkSurface> surface;
302#if SK_SUPPORT_GPU
kkinnunen9e61bb72014-10-09 05:24:15 -0700303 SkGLContext* gl;
mtkleinbb6a0282014-07-01 08:43:42 -0700304#endif
305};
mtkleinf3723212014-06-25 14:08:00 -0700306
bsalomonc2553372014-07-22 13:09:05 -0700307static bool is_cpu_config_allowed(const char* name) {
mtkleinbb6a0282014-07-01 08:43:42 -0700308 for (int i = 0; i < FLAGS_config.count(); i++) {
bsalomonc2553372014-07-22 13:09:05 -0700309 if (to_lower(FLAGS_config[i]).equals(name)) {
310 return true;
mtkleinf3723212014-06-25 14:08:00 -0700311 }
312 }
bsalomonc2553372014-07-22 13:09:05 -0700313 return false;
mtkleinbb6a0282014-07-01 08:43:42 -0700314}
315
bsalomonc2553372014-07-22 13:09:05 -0700316#if SK_SUPPORT_GPU
317static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextType ctxType,
318 int sampleCnt) {
319 if (!is_cpu_config_allowed(name)) {
320 return false;
321 }
krajcevski69a55602014-08-13 10:46:31 -0700322 if (const GrContext* ctx = gGrFactory->get(ctxType)) {
bsalomonc2553372014-07-22 13:09:05 -0700323 return sampleCnt <= ctx->getMaxSampleCount();
324 }
325 return false;
326}
327#endif
mtkleinbb6a0282014-07-01 08:43:42 -0700328
bsalomonc2553372014-07-22 13:09:05 -0700329#if SK_SUPPORT_GPU
330#define kBogusGLContextType GrContextFactory::kNative_GLContextType
331#else
332#define kBogusGLContextType 0
mtkleine714e752014-07-31 12:13:48 -0700333#endif
bsalomonc2553372014-07-22 13:09:05 -0700334
335// Append all configs that are enabled and supported.
336static void create_configs(SkTDArray<Config>* configs) {
jvanverth4736e142014-11-07 07:12:46 -0800337 #define CPU_CONFIG(name, backend, color, alpha) \
338 if (is_cpu_config_allowed(#name)) { \
339 Config config = { #name, Benchmark::backend, color, alpha, 0, \
340 kBogusGLContextType, false }; \
341 configs->push(config); \
mtkleinbb6a0282014-07-01 08:43:42 -0700342 }
mtkleine714e752014-07-31 12:13:48 -0700343
mtklein40b32be2014-07-09 08:46:49 -0700344 if (FLAGS_cpu) {
bsalomonc2553372014-07-22 13:09:05 -0700345 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kUnpremul_SkAlphaType)
346 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType)
347 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType)
mtklein40b32be2014-07-09 08:46:49 -0700348 }
mtkleinbb6a0282014-07-01 08:43:42 -0700349
350#if SK_SUPPORT_GPU
jvanverth4736e142014-11-07 07:12:46 -0800351 #define GPU_CONFIG(name, ctxType, samples, useDFText) \
bsalomonc2553372014-07-22 13:09:05 -0700352 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \
353 Config config = { \
354 #name, \
355 Benchmark::kGPU_Backend, \
356 kN32_SkColorType, \
357 kPremul_SkAlphaType, \
358 samples, \
jvanverth4736e142014-11-07 07:12:46 -0800359 GrContextFactory::ctxType, \
360 useDFText }; \
bsalomonc2553372014-07-22 13:09:05 -0700361 configs->push(config); \
mtkleinbb6a0282014-07-01 08:43:42 -0700362 }
mtkleine714e752014-07-31 12:13:48 -0700363
mtklein40b32be2014-07-09 08:46:49 -0700364 if (FLAGS_gpu) {
jvanverth4736e142014-11-07 07:12:46 -0800365 GPU_CONFIG(gpu, kNative_GLContextType, 0, false)
366 GPU_CONFIG(msaa4, kNative_GLContextType, 4, false)
367 GPU_CONFIG(msaa16, kNative_GLContextType, 16, false)
368 GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4, false)
369 GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16, false)
370 GPU_CONFIG(gpudft, kNative_GLContextType, 0, true)
371 GPU_CONFIG(debug, kDebug_GLContextType, 0, false)
372 GPU_CONFIG(nullgpu, kNull_GLContextType, 0, false)
bsalomon3b4d0772014-08-06 10:52:33 -0700373#ifdef SK_ANGLE
jvanverth4736e142014-11-07 07:12:46 -0800374 GPU_CONFIG(angle, kANGLE_GLContextType, 0, false)
bsalomon3b4d0772014-08-06 10:52:33 -0700375#endif
mtklein40b32be2014-07-09 08:46:49 -0700376 }
mtkleinbb6a0282014-07-01 08:43:42 -0700377#endif
mtkleinf3723212014-06-25 14:08:00 -0700378}
379
bsalomonc2553372014-07-22 13:09:05 -0700380// If bench is enabled for config, returns a Target* for it, otherwise NULL.
381static Target* is_enabled(Benchmark* bench, const Config& config) {
382 if (!bench->isSuitableFor(config.backend)) {
383 return NULL;
384 }
385
reede5ea5002014-09-03 11:54:58 -0700386 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
387 config.color, config.alpha);
bsalomonc2553372014-07-22 13:09:05 -0700388
389 Target* target = new Target(config);
390
391 if (Benchmark::kRaster_Backend == config.backend) {
392 target->surface.reset(SkSurface::NewRaster(info));
393 }
394#if SK_SUPPORT_GPU
395 else if (Benchmark::kGPU_Backend == config.backend) {
jvanverth4736e142014-11-07 07:12:46 -0800396 uint32_t flags = config.useDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
397 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
krajcevski69a55602014-08-13 10:46:31 -0700398 target->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(config.ctxType), info,
jvanverth4736e142014-11-07 07:12:46 -0800399 config.samples, &props));
krajcevski69a55602014-08-13 10:46:31 -0700400 target->gl = gGrFactory->getGLContext(config.ctxType);
bsalomonc2553372014-07-22 13:09:05 -0700401 }
402#endif
403
404 if (Benchmark::kNonRendering_Backend != config.backend && !target->surface.get()) {
405 delete target;
406 return NULL;
407 }
408 return target;
409}
410
411// Creates targets for a benchmark and a set of configs.
412static void create_targets(SkTDArray<Target*>* targets, Benchmark* b,
413 const SkTDArray<Config>& configs) {
414 for (int i = 0; i < configs.count(); ++i) {
415 if (Target* t = is_enabled(b, configs[i])) {
416 targets->push(t);
417 }
mtkleine714e752014-07-31 12:13:48 -0700418
bsalomonc2553372014-07-22 13:09:05 -0700419 }
420}
421
jcgregoriobf5e5232014-07-17 13:14:16 -0700422#if SK_SUPPORT_GPU
kkinnunen9e61bb72014-10-09 05:24:15 -0700423static void fill_gpu_options(ResultsWriter* log, SkGLContext* ctx) {
jcgregorio05c45602014-07-17 13:54:36 -0700424 const GrGLubyte* version;
jcgregoriobf5e5232014-07-17 13:14:16 -0700425 SK_GL_RET(*ctx, version, GetString(GR_GL_VERSION));
426 log->configOption("GL_VERSION", (const char*)(version));
427
428 SK_GL_RET(*ctx, version, GetString(GR_GL_RENDERER));
429 log->configOption("GL_RENDERER", (const char*) version);
430
431 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR));
432 log->configOption("GL_VENDOR", (const char*) version);
433
434 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
435 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
436}
437#endif
438
mtkleine714e752014-07-31 12:13:48 -0700439class BenchmarkStream {
440public:
mtklein92007582014-08-01 07:46:52 -0700441 BenchmarkStream() : fBenches(BenchRegistry::Head())
442 , fGMs(skiagm::GMRegistry::Head())
mtkleinfd731ce2014-09-10 12:19:30 -0700443 , fCurrentRecording(0)
mtklein92007582014-08-01 07:46:52 -0700444 , fCurrentScale(0)
robertphillips5b693772014-11-21 06:19:36 -0800445 , fCurrentSKP(0)
446 , fCurrentUseMPD(0) {
mtklein92007582014-08-01 07:46:52 -0700447 for (int i = 0; i < FLAGS_skps.count(); i++) {
448 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
449 fSKPs.push_back() = FLAGS_skps[i];
450 } else {
451 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
452 SkString path;
453 while (it.next(&path)) {
454 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
455 }
456 }
457 }
mtkleine714e752014-07-31 12:13:48 -0700458
mtklein92007582014-08-01 07:46:52 -0700459 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
460 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
461 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
462 exit(1);
463 }
464
465 for (int i = 0; i < FLAGS_scales.count(); i++) {
466 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
467 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
468 exit(1);
469 }
470 }
robertphillips5b693772014-11-21 06:19:36 -0800471
472 fUseMPDs.push_back() = false;
473 if (FLAGS_mpd) {
474 fUseMPDs.push_back() = true;
475 }
mtklein92007582014-08-01 07:46:52 -0700476 }
477
mtkleinfd731ce2014-09-10 12:19:30 -0700478 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
479 // Not strictly necessary, as it will be checked again later,
480 // but helps to avoid a lot of pointless work if we're going to skip it.
481 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
482 return false;
483 }
484
485 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
486 if (stream.get() == NULL) {
487 SkDebugf("Could not read %s.\n", path);
488 return false;
489 }
490
mtklein535776e2014-11-25 14:57:26 -0800491 pic->reset(SkPicture::CreateFromStream(stream.get()));
mtkleinfd731ce2014-09-10 12:19:30 -0700492 if (pic->get() == NULL) {
493 SkDebugf("Could not read %s as an SkPicture.\n", path);
494 return false;
495 }
496 return true;
497 }
498
mtklein92007582014-08-01 07:46:52 -0700499 Benchmark* next() {
mtkleine714e752014-07-31 12:13:48 -0700500 if (fBenches) {
501 Benchmark* bench = fBenches->factory()(NULL);
502 fBenches = fBenches->next();
mtklein92007582014-08-01 07:46:52 -0700503 fSourceType = "bench";
mtkleinfd731ce2014-09-10 12:19:30 -0700504 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700505 return bench;
506 }
mtklein92007582014-08-01 07:46:52 -0700507
mtkleine714e752014-07-31 12:13:48 -0700508 while (fGMs) {
509 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL));
510 fGMs = fGMs->next();
511 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) {
mtklein92007582014-08-01 07:46:52 -0700512 fSourceType = "gm";
mtkleinfd731ce2014-09-10 12:19:30 -0700513 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700514 return SkNEW_ARGS(GMBench, (gm.detach()));
515 }
516 }
mtklein92007582014-08-01 07:46:52 -0700517
mtkleinfd731ce2014-09-10 12:19:30 -0700518 // First add all .skps as RecordingBenches.
519 while (fCurrentRecording < fSKPs.count()) {
520 const SkString& path = fSKPs[fCurrentRecording++];
521 SkAutoTUnref<SkPicture> pic;
522 if (!ReadPicture(path.c_str(), &pic)) {
523 continue;
524 }
525 SkString name = SkOSPath::Basename(path.c_str());
526 fSourceType = "skp";
527 fBenchType = "recording";
mtklein051e56d2014-12-04 08:46:51 -0800528 fSKPBytes = SkPictureUtils::ApproximateBytesUsed(pic);
529 fSKPOps = pic->approximateOpCount();
mtkleinfd731ce2014-09-10 12:19:30 -0700530 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bbh));
531 }
532
533 // Then once each for each scale as SKPBenches (playback).
mtklein92007582014-08-01 07:46:52 -0700534 while (fCurrentScale < fScales.count()) {
535 while (fCurrentSKP < fSKPs.count()) {
robertphillips5b693772014-11-21 06:19:36 -0800536 const SkString& path = fSKPs[fCurrentSKP];
mtkleinfd731ce2014-09-10 12:19:30 -0700537 SkAutoTUnref<SkPicture> pic;
538 if (!ReadPicture(path.c_str(), &pic)) {
robertphillips5b693772014-11-21 06:19:36 -0800539 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700540 continue;
541 }
robertphillips5b693772014-11-21 06:19:36 -0800542
543 while (fCurrentUseMPD < fUseMPDs.count()) {
544 if (FLAGS_bbh) {
545 // The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
546 SkRTreeFactory factory;
547 SkPictureRecorder recorder;
548 static const int kFlags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
549 pic->playback(recorder.beginRecording(pic->cullRect().width(),
550 pic->cullRect().height(),
551 &factory, kFlags));
552 pic.reset(recorder.endRecording());
553 }
554 SkString name = SkOSPath::Basename(path.c_str());
555 fSourceType = "skp";
556 fBenchType = "playback";
557 return SkNEW_ARGS(SKPBench,
558 (name.c_str(), pic.get(), fClip,
559 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]));
mtklein20840502014-08-21 15:51:22 -0700560 }
robertphillips5b693772014-11-21 06:19:36 -0800561 fCurrentUseMPD = 0;
562 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700563 }
564 fCurrentSKP = 0;
565 fCurrentScale++;
566 }
567
mtkleine714e752014-07-31 12:13:48 -0700568 return NULL;
569 }
mtklein92007582014-08-01 07:46:52 -0700570
571 void fillCurrentOptions(ResultsWriter* log) const {
572 log->configOption("source_type", fSourceType);
mtkleinfd731ce2014-09-10 12:19:30 -0700573 log->configOption("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -0700574 if (0 == strcmp(fSourceType, "skp")) {
575 log->configOption("clip",
576 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
577 fClip.fRight, fClip.fBottom).c_str());
578 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
robertphillips5b693772014-11-21 06:19:36 -0800579 if (fCurrentUseMPD > 0) {
580 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
581 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
582 }
mtklein92007582014-08-01 07:46:52 -0700583 }
mtklein051e56d2014-12-04 08:46:51 -0800584 if (0 == strcmp(fBenchType, "recording")) {
585 log->metric("bytes", fSKPBytes);
586 log->metric("ops", fSKPOps);
587 }
mtklein92007582014-08-01 07:46:52 -0700588 }
589
mtkleine714e752014-07-31 12:13:48 -0700590private:
591 const BenchRegistry* fBenches;
592 const skiagm::GMRegistry* fGMs;
mtklein92007582014-08-01 07:46:52 -0700593 SkIRect fClip;
594 SkTArray<SkScalar> fScales;
595 SkTArray<SkString> fSKPs;
robertphillips5b693772014-11-21 06:19:36 -0800596 SkTArray<bool> fUseMPDs;
mtklein92007582014-08-01 07:46:52 -0700597
mtklein051e56d2014-12-04 08:46:51 -0800598 double fSKPBytes, fSKPOps;
599
mtkleinfd731ce2014-09-10 12:19:30 -0700600 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
601 const char* fBenchType; // How we bench it: micro, recording, playback, ...
602 int fCurrentRecording;
mtklein92007582014-08-01 07:46:52 -0700603 int fCurrentScale;
604 int fCurrentSKP;
robertphillips5b693772014-11-21 06:19:36 -0800605 int fCurrentUseMPD;
mtkleine714e752014-07-31 12:13:48 -0700606};
607
jcgregorio3b27ade2014-11-13 08:06:40 -0800608int nanobench_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700609int nanobench_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800610 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -0700611 SkAutoGraphics ag;
mtklein4f108442014-12-03 13:07:39 -0800612 SkTaskGroup::Enabler enabled;
mtkleinf3723212014-06-25 14:08:00 -0700613
krajcevski69a55602014-08-13 10:46:31 -0700614#if SK_SUPPORT_GPU
krajcevski12b35442014-08-13 12:06:26 -0700615 GrContext::Options grContextOpts;
616 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
617 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts)));
krajcevski69a55602014-08-13 10:46:31 -0700618#endif
619
bsalomon06cddec2014-10-24 10:40:50 -0700620 if (FLAGS_veryVerbose) {
621 FLAGS_verbose = true;
622 }
623
bsalomon6eb03cc2014-08-07 14:28:50 -0700624 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700625 FLAGS_samples = 1;
626 FLAGS_gpuFrameLag = 0;
627 }
628
bsalomon6eb03cc2014-08-07 14:28:50 -0700629 if (!FLAGS_writePath.isEmpty()) {
630 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
631 if (!sk_mkdir(FLAGS_writePath[0])) {
632 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
633 FLAGS_writePath.set(0, NULL);
634 }
635 }
636
mtklein1915b622014-08-20 11:45:00 -0700637 SkAutoTDelete<ResultsWriter> log(SkNEW(ResultsWriter));
mtklein60317d0f2014-07-14 11:30:37 -0700638 if (!FLAGS_outResultsFile.isEmpty()) {
mtklein1915b622014-08-20 11:45:00 -0700639 log.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0])));
mtklein60317d0f2014-07-14 11:30:37 -0700640 }
mtklein1915b622014-08-20 11:45:00 -0700641
642 if (1 == FLAGS_properties.count() % 2) {
643 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
644 return 1;
645 }
646 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
647 log->property(FLAGS_properties[i-1], FLAGS_properties[i]);
648 }
jcgregoriobf5e5232014-07-17 13:14:16 -0700649
650 if (1 == FLAGS_key.count() % 2) {
651 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
652 return 1;
653 }
654 for (int i = 1; i < FLAGS_key.count(); i += 2) {
mtklein1915b622014-08-20 11:45:00 -0700655 log->key(FLAGS_key[i-1], FLAGS_key[i]);
mtklein94e51562014-08-19 12:41:53 -0700656 }
mtklein60317d0f2014-07-14 11:30:37 -0700657
mtkleinf3723212014-06-25 14:08:00 -0700658 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -0700659 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -0400660
mtkleinbb6a0282014-07-01 08:43:42 -0700661 SkAutoTMalloc<double> samples(FLAGS_samples);
662
bsalomon6eb03cc2014-08-07 14:28:50 -0700663 if (kAutoTuneLoops != FLAGS_loops) {
664 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleina189ccd2014-07-14 12:28:47 -0700665 } else if (FLAGS_verbose) {
mtkleinf3723212014-06-25 14:08:00 -0700666 // No header.
667 } else if (FLAGS_quiet) {
mtklein40b32be2014-07-09 08:46:49 -0700668 SkDebugf("median\tbench\tconfig\n");
mtkleinf3723212014-06-25 14:08:00 -0700669 } else {
qiankun.miao8247ec32014-09-09 19:24:36 -0700670 SkDebugf("maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
671 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -0700672 }
673
bsalomonc2553372014-07-22 13:09:05 -0700674 SkTDArray<Config> configs;
675 create_configs(&configs);
676
mtkleine070c2b2014-10-14 08:40:43 -0700677 int runs = 0;
mtklein92007582014-08-01 07:46:52 -0700678 BenchmarkStream benchStream;
679 while (Benchmark* b = benchStream.next()) {
mtkleine714e752014-07-31 12:13:48 -0700680 SkAutoTDelete<Benchmark> bench(b);
mtklein96289052014-09-10 12:05:59 -0700681 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -0700682 continue;
683 }
684
mtkleinbb6a0282014-07-01 08:43:42 -0700685 SkTDArray<Target*> targets;
bsalomonc2553372014-07-22 13:09:05 -0700686 create_targets(&targets, bench.get(), configs);
mtkleinf3723212014-06-25 14:08:00 -0700687
jcgregoriobf5e5232014-07-17 13:14:16 -0700688 if (!targets.isEmpty()) {
mtklein96289052014-09-10 12:05:59 -0700689 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
jcgregoriobf5e5232014-07-17 13:14:16 -0700690 bench->preDraw();
691 }
mtkleinbb6a0282014-07-01 08:43:42 -0700692 for (int j = 0; j < targets.count(); j++) {
693 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->getCanvas() : NULL;
bsalomonc2553372014-07-22 13:09:05 -0700694 const char* config = targets[j]->config.name;
mtkleinf3723212014-06-25 14:08:00 -0700695
robertphillips5b693772014-11-21 06:19:36 -0800696#if SK_SUPPORT_GPU
697 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
698 setup_gl(targets[j]->gl);
699 }
700#endif
701
702 bench->perCanvasPreDraw(canvas);
703
mtkleinbb6a0282014-07-01 08:43:42 -0700704 const int loops =
705#if SK_SUPPORT_GPU
bsalomonc2553372014-07-22 13:09:05 -0700706 Benchmark::kGPU_Backend == targets[j]->config.backend
mtkleinbb6a0282014-07-01 08:43:42 -0700707 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
708 :
709#endif
710 cpu_bench( overhead, bench.get(), canvas, samples.get());
mtkleinf3723212014-06-25 14:08:00 -0700711
robertphillips5b693772014-11-21 06:19:36 -0800712 bench->perCanvasPostDraw(canvas);
713
bsalomon49f085d2014-09-05 13:34:00 -0700714 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700715 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -0700716 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -0700717 pngFilename.append(".png");
718 write_canvas_png(canvas, pngFilename);
719 }
720
721 if (kFailedLoops == loops) {
mtklein2069e222014-08-04 13:57:39 -0700722 // Can't be timed. A warning note has already been printed.
Mike Kleine3631362014-07-15 17:56:37 -0400723 continue;
724 }
725
mtkleinf3723212014-06-25 14:08:00 -0700726 Stats stats(samples.get(), FLAGS_samples);
mtklein1915b622014-08-20 11:45:00 -0700727 log->config(config);
mtklein96289052014-09-10 12:05:59 -0700728 log->configOption("name", bench->getName());
mtklein1915b622014-08-20 11:45:00 -0700729 benchStream.fillCurrentOptions(log.get());
jcgregoriobf5e5232014-07-17 13:14:16 -0700730#if SK_SUPPORT_GPU
bsalomonc2553372014-07-22 13:09:05 -0700731 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
mtklein1915b622014-08-20 11:45:00 -0700732 fill_gpu_options(log.get(), targets[j]->gl);
jcgregoriobf5e5232014-07-17 13:14:16 -0700733 }
734#endif
mtklein051e56d2014-12-04 08:46:51 -0800735 log->metric("min_ms", stats.min);
736 log->metric("median_ms", stats.median);
737 log->metric("mean_ms", stats.mean);
738 log->metric("max_ms", stats.max);
739 log->metric("stddev_ms", sqrt(stats.var));
mtkleine070c2b2014-10-14 08:40:43 -0700740 if (runs++ % FLAGS_flushEvery == 0) {
741 log->flush();
742 }
mtklein60317d0f2014-07-14 11:30:37 -0700743
bsalomon6eb03cc2014-08-07 14:28:50 -0700744 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700745 if (targets.count() == 1) {
746 config = ""; // Only print the config if we run the same bench on more than one.
747 }
mtklein53d25622014-09-18 07:39:42 -0700748 SkDebugf("%4dM\t%s\t%s\n"
749 , sk_tools::getMaxResidentSetSizeMB()
750 , bench->getUniqueName()
751 , config);
mtkleina189ccd2014-07-14 12:28:47 -0700752 } else if (FLAGS_verbose) {
mtkleinf3723212014-06-25 14:08:00 -0700753 for (int i = 0; i < FLAGS_samples; i++) {
mtklein55b0ffc2014-07-17 08:38:23 -0700754 SkDebugf("%s ", HUMANIZE(samples[i]));
mtkleinf3723212014-06-25 14:08:00 -0700755 }
mtklein96289052014-09-10 12:05:59 -0700756 SkDebugf("%s\n", bench->getUniqueName());
mtkleinf3723212014-06-25 14:08:00 -0700757 } else if (FLAGS_quiet) {
mtkleinbb6a0282014-07-01 08:43:42 -0700758 if (targets.count() == 1) {
mtkleinf3723212014-06-25 14:08:00 -0700759 config = ""; // Only print the config if we run the same bench on more than one.
760 }
mtklein96289052014-09-10 12:05:59 -0700761 SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getUniqueName(), config);
mtkleinf3723212014-06-25 14:08:00 -0700762 } else {
763 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
mtkleinafb43792014-08-19 15:55:55 -0700764 SkDebugf("%4dM\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n"
765 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -0700766 , loops
mtklein55b0ffc2014-07-17 08:38:23 -0700767 , HUMANIZE(stats.min)
768 , HUMANIZE(stats.median)
769 , HUMANIZE(stats.mean)
770 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -0700771 , stddev_percent
mtklein5d9d10e2014-07-11 11:57:07 -0700772 , stats.plot.c_str()
mtkleinf3723212014-06-25 14:08:00 -0700773 , config
mtklein96289052014-09-10 12:05:59 -0700774 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -0700775 );
776 }
bsalomon06cddec2014-10-24 10:40:50 -0700777#if SK_SUPPORT_GPU && GR_CACHE_STATS
778 if (FLAGS_veryVerbose &&
779 Benchmark::kGPU_Backend == targets[j]->config.backend) {
mtklein6838d852014-10-29 14:15:10 -0700780 gGrFactory->get(targets[j]->config.ctxType)->printCacheStats();
bsalomon06cddec2014-10-24 10:40:50 -0700781 }
782#endif
mtkleinf3723212014-06-25 14:08:00 -0700783 }
mtkleinbb6a0282014-07-01 08:43:42 -0700784 targets.deleteAll();
Mike Klein3944a1d2014-07-15 13:40:19 -0400785
bsalomon06cddec2014-10-24 10:40:50 -0700786#if SK_SUPPORT_GPU
bsalomon2354f842014-07-28 13:48:36 -0700787 if (FLAGS_abandonGpuContext) {
krajcevski69a55602014-08-13 10:46:31 -0700788 gGrFactory->abandonContexts();
bsalomon2354f842014-07-28 13:48:36 -0700789 }
790 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) {
krajcevski69a55602014-08-13 10:46:31 -0700791 gGrFactory->destroyContexts();
Mike Klein3944a1d2014-07-15 13:40:19 -0400792 }
bsalomon06cddec2014-10-24 10:40:50 -0700793#endif
mtkleinf3723212014-06-25 14:08:00 -0700794 }
795
mtkleine1091452014-12-04 10:47:02 -0800796 log->bench("memory_usage", 0,0);
797 log->config("meta");
798 log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
799
mtkleinf3723212014-06-25 14:08:00 -0700800 return 0;
801}
802
jcgregorio3b27ade2014-11-13 08:06:40 -0800803#if !defined SK_BUILD_FOR_IOS
804int main(int argc, char** argv) {
805 SkCommandLineFlags::Parse(argc, argv);
806 return nanobench_main();
807}
808#endif