blob: 36a9177e576e38e2a47ba702e42644b86f6f6213 [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";
bsalomon0aa5cea2014-12-15 09:13:35 -0800528 fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic));
mtklein051e56d2014-12-04 08:46:51 -0800529 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(),
robertphillipse451c4d2014-12-09 10:28:00 -0800551 &factory,
552 fUseMPDs[fCurrentUseMPD] ? kFlags : 0));
robertphillips5b693772014-11-21 06:19:36 -0800553 pic.reset(recorder.endRecording());
554 }
555 SkString name = SkOSPath::Basename(path.c_str());
556 fSourceType = "skp";
557 fBenchType = "playback";
558 return SkNEW_ARGS(SKPBench,
559 (name.c_str(), pic.get(), fClip,
560 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]));
mtklein20840502014-08-21 15:51:22 -0700561 }
robertphillips5b693772014-11-21 06:19:36 -0800562 fCurrentUseMPD = 0;
563 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700564 }
565 fCurrentSKP = 0;
566 fCurrentScale++;
567 }
568
mtkleine714e752014-07-31 12:13:48 -0700569 return NULL;
570 }
mtklein92007582014-08-01 07:46:52 -0700571
572 void fillCurrentOptions(ResultsWriter* log) const {
573 log->configOption("source_type", fSourceType);
mtkleinfd731ce2014-09-10 12:19:30 -0700574 log->configOption("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -0700575 if (0 == strcmp(fSourceType, "skp")) {
576 log->configOption("clip",
577 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
578 fClip.fRight, fClip.fBottom).c_str());
579 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
robertphillips5b693772014-11-21 06:19:36 -0800580 if (fCurrentUseMPD > 0) {
581 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
582 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
583 }
mtklein92007582014-08-01 07:46:52 -0700584 }
mtklein051e56d2014-12-04 08:46:51 -0800585 if (0 == strcmp(fBenchType, "recording")) {
586 log->metric("bytes", fSKPBytes);
587 log->metric("ops", fSKPOps);
588 }
mtklein92007582014-08-01 07:46:52 -0700589 }
590
mtkleine714e752014-07-31 12:13:48 -0700591private:
592 const BenchRegistry* fBenches;
593 const skiagm::GMRegistry* fGMs;
mtklein92007582014-08-01 07:46:52 -0700594 SkIRect fClip;
595 SkTArray<SkScalar> fScales;
596 SkTArray<SkString> fSKPs;
robertphillips5b693772014-11-21 06:19:36 -0800597 SkTArray<bool> fUseMPDs;
mtklein92007582014-08-01 07:46:52 -0700598
mtklein051e56d2014-12-04 08:46:51 -0800599 double fSKPBytes, fSKPOps;
600
mtkleinfd731ce2014-09-10 12:19:30 -0700601 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
602 const char* fBenchType; // How we bench it: micro, recording, playback, ...
603 int fCurrentRecording;
mtklein92007582014-08-01 07:46:52 -0700604 int fCurrentScale;
605 int fCurrentSKP;
robertphillips5b693772014-11-21 06:19:36 -0800606 int fCurrentUseMPD;
mtkleine714e752014-07-31 12:13:48 -0700607};
608
jcgregorio3b27ade2014-11-13 08:06:40 -0800609int nanobench_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700610int nanobench_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800611 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -0700612 SkAutoGraphics ag;
mtklein4f108442014-12-03 13:07:39 -0800613 SkTaskGroup::Enabler enabled;
mtkleinf3723212014-06-25 14:08:00 -0700614
krajcevski69a55602014-08-13 10:46:31 -0700615#if SK_SUPPORT_GPU
krajcevski12b35442014-08-13 12:06:26 -0700616 GrContext::Options grContextOpts;
617 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
618 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts)));
krajcevski69a55602014-08-13 10:46:31 -0700619#endif
620
bsalomon06cddec2014-10-24 10:40:50 -0700621 if (FLAGS_veryVerbose) {
622 FLAGS_verbose = true;
623 }
624
bsalomon6eb03cc2014-08-07 14:28:50 -0700625 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700626 FLAGS_samples = 1;
627 FLAGS_gpuFrameLag = 0;
628 }
629
bsalomon6eb03cc2014-08-07 14:28:50 -0700630 if (!FLAGS_writePath.isEmpty()) {
631 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
632 if (!sk_mkdir(FLAGS_writePath[0])) {
633 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
634 FLAGS_writePath.set(0, NULL);
635 }
636 }
637
mtklein1915b622014-08-20 11:45:00 -0700638 SkAutoTDelete<ResultsWriter> log(SkNEW(ResultsWriter));
mtklein60317d0f2014-07-14 11:30:37 -0700639 if (!FLAGS_outResultsFile.isEmpty()) {
mtklein1915b622014-08-20 11:45:00 -0700640 log.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0])));
mtklein60317d0f2014-07-14 11:30:37 -0700641 }
mtklein1915b622014-08-20 11:45:00 -0700642
643 if (1 == FLAGS_properties.count() % 2) {
644 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
645 return 1;
646 }
647 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
648 log->property(FLAGS_properties[i-1], FLAGS_properties[i]);
649 }
jcgregoriobf5e5232014-07-17 13:14:16 -0700650
651 if (1 == FLAGS_key.count() % 2) {
652 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
653 return 1;
654 }
655 for (int i = 1; i < FLAGS_key.count(); i += 2) {
mtklein1915b622014-08-20 11:45:00 -0700656 log->key(FLAGS_key[i-1], FLAGS_key[i]);
mtklein94e51562014-08-19 12:41:53 -0700657 }
mtklein60317d0f2014-07-14 11:30:37 -0700658
mtkleinf3723212014-06-25 14:08:00 -0700659 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -0700660 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -0400661
mtkleinbb6a0282014-07-01 08:43:42 -0700662 SkAutoTMalloc<double> samples(FLAGS_samples);
663
bsalomon6eb03cc2014-08-07 14:28:50 -0700664 if (kAutoTuneLoops != FLAGS_loops) {
665 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleina189ccd2014-07-14 12:28:47 -0700666 } else if (FLAGS_verbose) {
mtkleinf3723212014-06-25 14:08:00 -0700667 // No header.
668 } else if (FLAGS_quiet) {
mtklein40b32be2014-07-09 08:46:49 -0700669 SkDebugf("median\tbench\tconfig\n");
mtkleinf3723212014-06-25 14:08:00 -0700670 } else {
qiankun.miao8247ec32014-09-09 19:24:36 -0700671 SkDebugf("maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
672 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -0700673 }
674
bsalomonc2553372014-07-22 13:09:05 -0700675 SkTDArray<Config> configs;
676 create_configs(&configs);
677
mtkleine070c2b2014-10-14 08:40:43 -0700678 int runs = 0;
mtklein92007582014-08-01 07:46:52 -0700679 BenchmarkStream benchStream;
680 while (Benchmark* b = benchStream.next()) {
mtkleine714e752014-07-31 12:13:48 -0700681 SkAutoTDelete<Benchmark> bench(b);
mtklein96289052014-09-10 12:05:59 -0700682 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -0700683 continue;
684 }
685
mtkleinbb6a0282014-07-01 08:43:42 -0700686 SkTDArray<Target*> targets;
bsalomonc2553372014-07-22 13:09:05 -0700687 create_targets(&targets, bench.get(), configs);
mtkleinf3723212014-06-25 14:08:00 -0700688
jcgregoriobf5e5232014-07-17 13:14:16 -0700689 if (!targets.isEmpty()) {
mtklein96289052014-09-10 12:05:59 -0700690 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
jcgregoriobf5e5232014-07-17 13:14:16 -0700691 bench->preDraw();
692 }
mtkleinbb6a0282014-07-01 08:43:42 -0700693 for (int j = 0; j < targets.count(); j++) {
694 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->getCanvas() : NULL;
bsalomonc2553372014-07-22 13:09:05 -0700695 const char* config = targets[j]->config.name;
mtkleinf3723212014-06-25 14:08:00 -0700696
robertphillips5b693772014-11-21 06:19:36 -0800697#if SK_SUPPORT_GPU
698 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
699 setup_gl(targets[j]->gl);
700 }
701#endif
702
703 bench->perCanvasPreDraw(canvas);
704
mtkleinbb6a0282014-07-01 08:43:42 -0700705 const int loops =
706#if SK_SUPPORT_GPU
bsalomonc2553372014-07-22 13:09:05 -0700707 Benchmark::kGPU_Backend == targets[j]->config.backend
mtkleinbb6a0282014-07-01 08:43:42 -0700708 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
709 :
710#endif
711 cpu_bench( overhead, bench.get(), canvas, samples.get());
mtkleinf3723212014-06-25 14:08:00 -0700712
robertphillips5b693772014-11-21 06:19:36 -0800713 bench->perCanvasPostDraw(canvas);
714
bsalomon49f085d2014-09-05 13:34:00 -0700715 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700716 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -0700717 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -0700718 pngFilename.append(".png");
719 write_canvas_png(canvas, pngFilename);
720 }
721
722 if (kFailedLoops == loops) {
mtklein2069e222014-08-04 13:57:39 -0700723 // Can't be timed. A warning note has already been printed.
Mike Kleine3631362014-07-15 17:56:37 -0400724 continue;
725 }
726
mtkleinf3723212014-06-25 14:08:00 -0700727 Stats stats(samples.get(), FLAGS_samples);
mtklein1915b622014-08-20 11:45:00 -0700728 log->config(config);
mtklein96289052014-09-10 12:05:59 -0700729 log->configOption("name", bench->getName());
mtklein1915b622014-08-20 11:45:00 -0700730 benchStream.fillCurrentOptions(log.get());
jcgregoriobf5e5232014-07-17 13:14:16 -0700731#if SK_SUPPORT_GPU
bsalomonc2553372014-07-22 13:09:05 -0700732 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
mtklein1915b622014-08-20 11:45:00 -0700733 fill_gpu_options(log.get(), targets[j]->gl);
jcgregoriobf5e5232014-07-17 13:14:16 -0700734 }
735#endif
mtklein051e56d2014-12-04 08:46:51 -0800736 log->metric("min_ms", stats.min);
mtkleine070c2b2014-10-14 08:40:43 -0700737 if (runs++ % FLAGS_flushEvery == 0) {
738 log->flush();
739 }
mtklein60317d0f2014-07-14 11:30:37 -0700740
bsalomon6eb03cc2014-08-07 14:28:50 -0700741 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700742 if (targets.count() == 1) {
743 config = ""; // Only print the config if we run the same bench on more than one.
744 }
mtklein53d25622014-09-18 07:39:42 -0700745 SkDebugf("%4dM\t%s\t%s\n"
746 , sk_tools::getMaxResidentSetSizeMB()
747 , bench->getUniqueName()
748 , config);
mtkleina189ccd2014-07-14 12:28:47 -0700749 } else if (FLAGS_verbose) {
mtkleinf3723212014-06-25 14:08:00 -0700750 for (int i = 0; i < FLAGS_samples; i++) {
mtklein55b0ffc2014-07-17 08:38:23 -0700751 SkDebugf("%s ", HUMANIZE(samples[i]));
mtkleinf3723212014-06-25 14:08:00 -0700752 }
mtklein96289052014-09-10 12:05:59 -0700753 SkDebugf("%s\n", bench->getUniqueName());
mtkleinf3723212014-06-25 14:08:00 -0700754 } else if (FLAGS_quiet) {
mtkleinbb6a0282014-07-01 08:43:42 -0700755 if (targets.count() == 1) {
mtkleinf3723212014-06-25 14:08:00 -0700756 config = ""; // Only print the config if we run the same bench on more than one.
757 }
mtklein96289052014-09-10 12:05:59 -0700758 SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getUniqueName(), config);
mtkleinf3723212014-06-25 14:08:00 -0700759 } else {
760 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
mtkleinafb43792014-08-19 15:55:55 -0700761 SkDebugf("%4dM\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n"
762 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -0700763 , loops
mtklein55b0ffc2014-07-17 08:38:23 -0700764 , HUMANIZE(stats.min)
765 , HUMANIZE(stats.median)
766 , HUMANIZE(stats.mean)
767 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -0700768 , stddev_percent
mtklein5d9d10e2014-07-11 11:57:07 -0700769 , stats.plot.c_str()
mtkleinf3723212014-06-25 14:08:00 -0700770 , config
mtklein96289052014-09-10 12:05:59 -0700771 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -0700772 );
773 }
bsalomon06cddec2014-10-24 10:40:50 -0700774#if SK_SUPPORT_GPU && GR_CACHE_STATS
775 if (FLAGS_veryVerbose &&
776 Benchmark::kGPU_Backend == targets[j]->config.backend) {
mtklein6838d852014-10-29 14:15:10 -0700777 gGrFactory->get(targets[j]->config.ctxType)->printCacheStats();
bsalomon06cddec2014-10-24 10:40:50 -0700778 }
779#endif
mtkleinf3723212014-06-25 14:08:00 -0700780 }
mtkleinbb6a0282014-07-01 08:43:42 -0700781 targets.deleteAll();
Mike Klein3944a1d2014-07-15 13:40:19 -0400782
bsalomon06cddec2014-10-24 10:40:50 -0700783#if SK_SUPPORT_GPU
bsalomon2354f842014-07-28 13:48:36 -0700784 if (FLAGS_abandonGpuContext) {
krajcevski69a55602014-08-13 10:46:31 -0700785 gGrFactory->abandonContexts();
bsalomon2354f842014-07-28 13:48:36 -0700786 }
787 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) {
krajcevski69a55602014-08-13 10:46:31 -0700788 gGrFactory->destroyContexts();
Mike Klein3944a1d2014-07-15 13:40:19 -0400789 }
bsalomon06cddec2014-10-24 10:40:50 -0700790#endif
mtkleinf3723212014-06-25 14:08:00 -0700791 }
792
mtkleine1091452014-12-04 10:47:02 -0800793 log->bench("memory_usage", 0,0);
794 log->config("meta");
795 log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
796
mtkleinf3723212014-06-25 14:08:00 -0700797 return 0;
798}
799
jcgregorio3b27ade2014-11-13 08:06:40 -0800800#if !defined SK_BUILD_FOR_IOS
801int main(int argc, char** argv) {
802 SkCommandLineFlags::Parse(argc, argv);
803 return nanobench_main();
804}
805#endif