blob: eb48ec228d6b35886d6c8a87cd5e1c344f9479e3 [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.");
bsalomonb12ea412015-02-02 21:19:50 -080078DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
mtklein92007582014-08-01 07:46:52 -070079
mtkleinf3723212014-06-25 14:08:00 -070080static SkString humanize(double ms) {
mtkleindc5bbab2014-09-24 06:34:09 -070081 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
mtklein748ca3b2015-01-15 10:56:12 -080082 return HumanizeMs(ms);
mtkleinf3723212014-06-25 14:08:00 -070083}
mtklein55b0ffc2014-07-17 08:38:23 -070084#define HUMANIZE(ms) humanize(ms).c_str()
mtkleinf3723212014-06-25 14:08:00 -070085
kkinnunen9e61bb72014-10-09 05:24:15 -070086static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContext* gl) {
bsalomon6eb03cc2014-08-07 14:28:50 -070087 if (canvas) {
88 canvas->clear(SK_ColorWHITE);
89 }
mtkleinbb6a0282014-07-01 08:43:42 -070090 WallTimer timer;
91 timer.start();
92 if (bench) {
93 bench->draw(loops, canvas);
94 }
95 if (canvas) {
96 canvas->flush();
97 }
98#if SK_SUPPORT_GPU
99 if (gl) {
100 SK_GL(*gl, Flush());
101 gl->swapBuffers();
102 }
103#endif
104 timer.end();
105 return timer.fWall;
106}
107
mtkleinf3723212014-06-25 14:08:00 -0700108static double estimate_timer_overhead() {
109 double overhead = 0;
mtkleinf3723212014-06-25 14:08:00 -0700110 for (int i = 0; i < FLAGS_overheadLoops; i++) {
mtkleinbb6a0282014-07-01 08:43:42 -0700111 overhead += time(1, NULL, NULL, NULL);
mtkleinf3723212014-06-25 14:08:00 -0700112 }
113 return overhead / FLAGS_overheadLoops;
114}
115
reed53249782014-10-10 09:09:52 -0700116static int detect_forever_loops(int loops) {
117 // look for a magic run-forever value
118 if (loops < 0) {
119 loops = SK_MaxS32;
120 }
121 return loops;
122}
123
mtklein55b0ffc2014-07-17 08:38:23 -0700124static int clamp_loops(int loops) {
125 if (loops < 1) {
mtklein527930f2014-11-06 08:04:34 -0800126 SkDebugf("ERROR: clamping loops from %d to 1. "
127 "There's probably something wrong with the bench.\n", loops);
mtklein55b0ffc2014-07-17 08:38:23 -0700128 return 1;
129 }
130 if (loops > FLAGS_maxLoops) {
131 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
132 return FLAGS_maxLoops;
133 }
134 return loops;
135}
136
bsalomon6eb03cc2014-08-07 14:28:50 -0700137static bool write_canvas_png(SkCanvas* canvas, const SkString& filename) {
138 if (filename.isEmpty()) {
139 return false;
140 }
reede5ea5002014-09-03 11:54:58 -0700141 if (kUnknown_SkColorType == canvas->imageInfo().colorType()) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700142 return false;
143 }
144 SkBitmap bmp;
145 bmp.setInfo(canvas->imageInfo());
146 if (!canvas->readPixels(&bmp, 0, 0)) {
147 SkDebugf("Can't read canvas pixels.\n");
148 return false;
149 }
150 SkString dir = SkOSPath::Dirname(filename.c_str());
151 if (!sk_mkdir(dir.c_str())) {
152 SkDebugf("Can't make dir %s.\n", dir.c_str());
153 return false;
154 }
155 SkFILEWStream stream(filename.c_str());
156 if (!stream.isValid()) {
157 SkDebugf("Can't write %s.\n", filename.c_str());
158 return false;
159 }
160 if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) {
161 SkDebugf("Can't encode a PNG.\n");
162 return false;
163 }
164 return true;
165}
166
167static int kFailedLoops = -2;
mtkleinbb6a0282014-07-01 08:43:42 -0700168static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas, double* samples) {
169 // First figure out approximately how many loops of bench it takes to make overhead negligible.
mtklein2069e222014-08-04 13:57:39 -0700170 double bench_plus_overhead = 0.0;
mtklein55b0ffc2014-07-17 08:38:23 -0700171 int round = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -0700172 if (kAutoTuneLoops == FLAGS_loops) {
173 while (bench_plus_overhead < overhead) {
174 if (round++ == FLAGS_maxCalibrationAttempts) {
175 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
mtklein96289052014-09-10 12:05:59 -0700176 bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
bsalomon6eb03cc2014-08-07 14:28:50 -0700177 return kFailedLoops;
178 }
179 bench_plus_overhead = time(1, bench, canvas, NULL);
mtklein55b0ffc2014-07-17 08:38:23 -0700180 }
mtklein2069e222014-08-04 13:57:39 -0700181 }
mtkleinf3723212014-06-25 14:08:00 -0700182
mtkleinbb6a0282014-07-01 08:43:42 -0700183 // Later we'll just start and stop the timer once but loop N times.
mtkleinf3723212014-06-25 14:08:00 -0700184 // We'll pick N to make timer overhead negligible:
185 //
mtkleinbb6a0282014-07-01 08:43:42 -0700186 // overhead
187 // ------------------------- < FLAGS_overheadGoal
188 // overhead + N * Bench Time
mtkleinf3723212014-06-25 14:08:00 -0700189 //
mtkleinbb6a0282014-07-01 08:43:42 -0700190 // where bench_plus_overhead ≈ overhead + Bench Time.
mtkleinf3723212014-06-25 14:08:00 -0700191 //
192 // Doing some math, we get:
193 //
mtkleinbb6a0282014-07-01 08:43:42 -0700194 // (overhead / FLAGS_overheadGoal) - overhead
195 // ------------------------------------------ < N
196 // bench_plus_overhead - overhead)
mtkleinf3723212014-06-25 14:08:00 -0700197 //
198 // Luckily, this also works well in practice. :)
bsalomon6eb03cc2014-08-07 14:28:50 -0700199 int loops = FLAGS_loops;
200 if (kAutoTuneLoops == loops) {
201 const double numer = overhead / FLAGS_overheadGoal - overhead;
202 const double denom = bench_plus_overhead - overhead;
203 loops = (int)ceil(numer / denom);
reed53249782014-10-10 09:09:52 -0700204 loops = clamp_loops(loops);
205 } else {
206 loops = detect_forever_loops(loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700207 }
mtkleinbb6a0282014-07-01 08:43:42 -0700208
209 for (int i = 0; i < FLAGS_samples; i++) {
210 samples[i] = time(loops, bench, canvas, NULL) / loops;
211 }
212 return loops;
mtkleinf3723212014-06-25 14:08:00 -0700213}
214
mtkleinbb6a0282014-07-01 08:43:42 -0700215#if SK_SUPPORT_GPU
robertphillips5b693772014-11-21 06:19:36 -0800216static void setup_gl(SkGLContext* gl) {
217 gl->makeCurrent();
218 // Make sure we're done with whatever came before.
219 SK_GL(*gl, Finish());
220}
221
kkinnunen9e61bb72014-10-09 05:24:15 -0700222static int gpu_bench(SkGLContext* gl,
mtkleinbb6a0282014-07-01 08:43:42 -0700223 Benchmark* bench,
224 SkCanvas* canvas,
225 double* samples) {
mtkleinbb6a0282014-07-01 08:43:42 -0700226 // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
bsalomon6eb03cc2014-08-07 14:28:50 -0700227 int loops = FLAGS_loops;
228 if (kAutoTuneLoops == loops) {
229 loops = 1;
mtkleina189ccd2014-07-14 12:28:47 -0700230 double elapsed = 0;
231 do {
mtklein527930f2014-11-06 08:04:34 -0800232 if (1<<30 == loops) {
233 // We're about to wrap. Something's wrong with the bench.
234 loops = 0;
235 break;
236 }
mtkleina189ccd2014-07-14 12:28:47 -0700237 loops *= 2;
238 // If the GPU lets frames lag at all, we need to make sure we're timing
239 // _this_ round, not still timing last round. We force this by looping
240 // more times than any reasonable GPU will allow frames to lag.
241 for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
242 elapsed = time(loops, bench, canvas, gl);
243 }
244 } while (elapsed < FLAGS_gpuMs);
mtkleinbb6a0282014-07-01 08:43:42 -0700245
mtkleina189ccd2014-07-14 12:28:47 -0700246 // We've overshot at least a little. Scale back linearly.
247 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
reed53249782014-10-10 09:09:52 -0700248 loops = clamp_loops(loops);
mtkleinbb6a0282014-07-01 08:43:42 -0700249
mtkleina189ccd2014-07-14 12:28:47 -0700250 // Might as well make sure we're not still timing our calibration.
251 SK_GL(*gl, Finish());
reed53249782014-10-10 09:09:52 -0700252 } else {
253 loops = detect_forever_loops(loops);
mtkleina189ccd2014-07-14 12:28:47 -0700254 }
mtkleinbb6a0282014-07-01 08:43:42 -0700255
256 // Pretty much the same deal as the calibration: do some warmup to make
257 // sure we're timing steady-state pipelined frames.
258 for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
259 time(loops, bench, canvas, gl);
mtkleinf3723212014-06-25 14:08:00 -0700260 }
mtkleinbb6a0282014-07-01 08:43:42 -0700261
262 // Now, actually do the timing!
263 for (int i = 0; i < FLAGS_samples; i++) {
264 samples[i] = time(loops, bench, canvas, gl) / loops;
265 }
266 return loops;
267}
268#endif
269
270static SkString to_lower(const char* str) {
271 SkString lower(str);
272 for (size_t i = 0; i < lower.size(); i++) {
273 lower[i] = tolower(lower[i]);
274 }
275 return lower;
mtkleinf3723212014-06-25 14:08:00 -0700276}
277
bsalomonc2553372014-07-22 13:09:05 -0700278struct Config {
279 const char* name;
mtkleinbb6a0282014-07-01 08:43:42 -0700280 Benchmark::Backend backend;
bsalomonc2553372014-07-22 13:09:05 -0700281 SkColorType color;
282 SkAlphaType alpha;
283 int samples;
284#if SK_SUPPORT_GPU
285 GrContextFactory::GLContextType ctxType;
jvanverth4736e142014-11-07 07:12:46 -0800286 bool useDFText;
bsalomonc2553372014-07-22 13:09:05 -0700287#else
288 int bogusInt;
jvanverth4736e142014-11-07 07:12:46 -0800289 bool bogusBool;
bsalomonc2553372014-07-22 13:09:05 -0700290#endif
291};
292
293struct Target {
294 explicit Target(const Config& c) : config(c) {}
295 const Config config;
mtkleinbb6a0282014-07-01 08:43:42 -0700296 SkAutoTDelete<SkSurface> surface;
297#if SK_SUPPORT_GPU
kkinnunen9e61bb72014-10-09 05:24:15 -0700298 SkGLContext* gl;
mtkleinbb6a0282014-07-01 08:43:42 -0700299#endif
300};
mtkleinf3723212014-06-25 14:08:00 -0700301
bsalomonc2553372014-07-22 13:09:05 -0700302static bool is_cpu_config_allowed(const char* name) {
mtkleinbb6a0282014-07-01 08:43:42 -0700303 for (int i = 0; i < FLAGS_config.count(); i++) {
bsalomonc2553372014-07-22 13:09:05 -0700304 if (to_lower(FLAGS_config[i]).equals(name)) {
305 return true;
mtkleinf3723212014-06-25 14:08:00 -0700306 }
307 }
bsalomonc2553372014-07-22 13:09:05 -0700308 return false;
mtkleinbb6a0282014-07-01 08:43:42 -0700309}
310
bsalomonc2553372014-07-22 13:09:05 -0700311#if SK_SUPPORT_GPU
312static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextType ctxType,
313 int sampleCnt) {
314 if (!is_cpu_config_allowed(name)) {
315 return false;
316 }
krajcevski69a55602014-08-13 10:46:31 -0700317 if (const GrContext* ctx = gGrFactory->get(ctxType)) {
bsalomonc2553372014-07-22 13:09:05 -0700318 return sampleCnt <= ctx->getMaxSampleCount();
319 }
320 return false;
321}
322#endif
mtkleinbb6a0282014-07-01 08:43:42 -0700323
bsalomonc2553372014-07-22 13:09:05 -0700324#if SK_SUPPORT_GPU
325#define kBogusGLContextType GrContextFactory::kNative_GLContextType
326#else
327#define kBogusGLContextType 0
mtkleine714e752014-07-31 12:13:48 -0700328#endif
bsalomonc2553372014-07-22 13:09:05 -0700329
330// Append all configs that are enabled and supported.
331static void create_configs(SkTDArray<Config>* configs) {
jvanverth4736e142014-11-07 07:12:46 -0800332 #define CPU_CONFIG(name, backend, color, alpha) \
333 if (is_cpu_config_allowed(#name)) { \
334 Config config = { #name, Benchmark::backend, color, alpha, 0, \
335 kBogusGLContextType, false }; \
336 configs->push(config); \
mtkleinbb6a0282014-07-01 08:43:42 -0700337 }
mtkleine714e752014-07-31 12:13:48 -0700338
mtklein40b32be2014-07-09 08:46:49 -0700339 if (FLAGS_cpu) {
bsalomonc2553372014-07-22 13:09:05 -0700340 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kUnpremul_SkAlphaType)
341 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType)
342 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType)
mtklein40b32be2014-07-09 08:46:49 -0700343 }
mtkleinbb6a0282014-07-01 08:43:42 -0700344
345#if SK_SUPPORT_GPU
jvanverth4736e142014-11-07 07:12:46 -0800346 #define GPU_CONFIG(name, ctxType, samples, useDFText) \
bsalomonc2553372014-07-22 13:09:05 -0700347 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \
348 Config config = { \
349 #name, \
350 Benchmark::kGPU_Backend, \
351 kN32_SkColorType, \
352 kPremul_SkAlphaType, \
353 samples, \
jvanverth4736e142014-11-07 07:12:46 -0800354 GrContextFactory::ctxType, \
355 useDFText }; \
bsalomonc2553372014-07-22 13:09:05 -0700356 configs->push(config); \
mtkleinbb6a0282014-07-01 08:43:42 -0700357 }
mtkleine714e752014-07-31 12:13:48 -0700358
mtklein40b32be2014-07-09 08:46:49 -0700359 if (FLAGS_gpu) {
jvanverth4736e142014-11-07 07:12:46 -0800360 GPU_CONFIG(gpu, kNative_GLContextType, 0, false)
361 GPU_CONFIG(msaa4, kNative_GLContextType, 4, false)
362 GPU_CONFIG(msaa16, kNative_GLContextType, 16, false)
363 GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4, false)
364 GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16, false)
365 GPU_CONFIG(gpudft, kNative_GLContextType, 0, true)
366 GPU_CONFIG(debug, kDebug_GLContextType, 0, false)
367 GPU_CONFIG(nullgpu, kNull_GLContextType, 0, false)
bsalomon3b4d0772014-08-06 10:52:33 -0700368#ifdef SK_ANGLE
jvanverth4736e142014-11-07 07:12:46 -0800369 GPU_CONFIG(angle, kANGLE_GLContextType, 0, false)
bsalomon3b4d0772014-08-06 10:52:33 -0700370#endif
mtklein40b32be2014-07-09 08:46:49 -0700371 }
mtkleinbb6a0282014-07-01 08:43:42 -0700372#endif
mtkleinf3723212014-06-25 14:08:00 -0700373}
374
bsalomonc2553372014-07-22 13:09:05 -0700375// If bench is enabled for config, returns a Target* for it, otherwise NULL.
376static Target* is_enabled(Benchmark* bench, const Config& config) {
377 if (!bench->isSuitableFor(config.backend)) {
378 return NULL;
379 }
380
reede5ea5002014-09-03 11:54:58 -0700381 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
382 config.color, config.alpha);
bsalomonc2553372014-07-22 13:09:05 -0700383
384 Target* target = new Target(config);
385
386 if (Benchmark::kRaster_Backend == config.backend) {
387 target->surface.reset(SkSurface::NewRaster(info));
388 }
389#if SK_SUPPORT_GPU
390 else if (Benchmark::kGPU_Backend == config.backend) {
jvanverth4736e142014-11-07 07:12:46 -0800391 uint32_t flags = config.useDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
392 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
bsalomonafe30052015-01-16 07:32:33 -0800393 target->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(config.ctxType),
394 SkSurface::kNo_Budgeted, info,
jvanverth4736e142014-11-07 07:12:46 -0800395 config.samples, &props));
krajcevski69a55602014-08-13 10:46:31 -0700396 target->gl = gGrFactory->getGLContext(config.ctxType);
bsalomonc2553372014-07-22 13:09:05 -0700397 }
398#endif
399
400 if (Benchmark::kNonRendering_Backend != config.backend && !target->surface.get()) {
401 delete target;
402 return NULL;
403 }
404 return target;
405}
406
407// Creates targets for a benchmark and a set of configs.
408static void create_targets(SkTDArray<Target*>* targets, Benchmark* b,
409 const SkTDArray<Config>& configs) {
410 for (int i = 0; i < configs.count(); ++i) {
411 if (Target* t = is_enabled(b, configs[i])) {
412 targets->push(t);
413 }
mtkleine714e752014-07-31 12:13:48 -0700414
bsalomonc2553372014-07-22 13:09:05 -0700415 }
416}
417
jcgregoriobf5e5232014-07-17 13:14:16 -0700418#if SK_SUPPORT_GPU
kkinnunen9e61bb72014-10-09 05:24:15 -0700419static void fill_gpu_options(ResultsWriter* log, SkGLContext* ctx) {
jcgregorio05c45602014-07-17 13:54:36 -0700420 const GrGLubyte* version;
jcgregoriobf5e5232014-07-17 13:14:16 -0700421 SK_GL_RET(*ctx, version, GetString(GR_GL_VERSION));
422 log->configOption("GL_VERSION", (const char*)(version));
423
424 SK_GL_RET(*ctx, version, GetString(GR_GL_RENDERER));
425 log->configOption("GL_RENDERER", (const char*) version);
426
427 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR));
428 log->configOption("GL_VENDOR", (const char*) version);
429
430 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
431 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
432}
433#endif
434
mtkleine714e752014-07-31 12:13:48 -0700435class BenchmarkStream {
436public:
mtklein92007582014-08-01 07:46:52 -0700437 BenchmarkStream() : fBenches(BenchRegistry::Head())
438 , fGMs(skiagm::GMRegistry::Head())
mtkleinfd731ce2014-09-10 12:19:30 -0700439 , fCurrentRecording(0)
mtklein92007582014-08-01 07:46:52 -0700440 , fCurrentScale(0)
robertphillips5b693772014-11-21 06:19:36 -0800441 , fCurrentSKP(0)
442 , fCurrentUseMPD(0) {
mtklein92007582014-08-01 07:46:52 -0700443 for (int i = 0; i < FLAGS_skps.count(); i++) {
444 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
445 fSKPs.push_back() = FLAGS_skps[i];
446 } else {
447 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
448 SkString path;
449 while (it.next(&path)) {
450 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
451 }
452 }
453 }
mtkleine714e752014-07-31 12:13:48 -0700454
mtklein92007582014-08-01 07:46:52 -0700455 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
456 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
457 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
458 exit(1);
459 }
460
461 for (int i = 0; i < FLAGS_scales.count(); i++) {
462 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
463 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
464 exit(1);
465 }
466 }
robertphillips5b693772014-11-21 06:19:36 -0800467
468 fUseMPDs.push_back() = false;
469 if (FLAGS_mpd) {
470 fUseMPDs.push_back() = true;
471 }
mtklein92007582014-08-01 07:46:52 -0700472 }
473
mtkleinfd731ce2014-09-10 12:19:30 -0700474 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
475 // Not strictly necessary, as it will be checked again later,
476 // but helps to avoid a lot of pointless work if we're going to skip it.
477 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
478 return false;
479 }
480
scroggoa1193e42015-01-21 12:09:53 -0800481 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
mtkleinfd731ce2014-09-10 12:19:30 -0700482 if (stream.get() == NULL) {
483 SkDebugf("Could not read %s.\n", path);
484 return false;
485 }
486
mtklein535776e2014-11-25 14:57:26 -0800487 pic->reset(SkPicture::CreateFromStream(stream.get()));
mtkleinfd731ce2014-09-10 12:19:30 -0700488 if (pic->get() == NULL) {
489 SkDebugf("Could not read %s as an SkPicture.\n", path);
490 return false;
491 }
492 return true;
493 }
494
mtklein92007582014-08-01 07:46:52 -0700495 Benchmark* next() {
mtkleine714e752014-07-31 12:13:48 -0700496 if (fBenches) {
497 Benchmark* bench = fBenches->factory()(NULL);
498 fBenches = fBenches->next();
mtklein92007582014-08-01 07:46:52 -0700499 fSourceType = "bench";
mtkleinfd731ce2014-09-10 12:19:30 -0700500 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700501 return bench;
502 }
mtklein92007582014-08-01 07:46:52 -0700503
mtkleine714e752014-07-31 12:13:48 -0700504 while (fGMs) {
505 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL));
506 fGMs = fGMs->next();
mtkleincf5d9c92015-01-23 10:31:45 -0800507 if (gm->runAsBench()) {
mtklein92007582014-08-01 07:46:52 -0700508 fSourceType = "gm";
mtkleinfd731ce2014-09-10 12:19:30 -0700509 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700510 return SkNEW_ARGS(GMBench, (gm.detach()));
511 }
512 }
mtklein92007582014-08-01 07:46:52 -0700513
mtkleinfd731ce2014-09-10 12:19:30 -0700514 // First add all .skps as RecordingBenches.
515 while (fCurrentRecording < fSKPs.count()) {
516 const SkString& path = fSKPs[fCurrentRecording++];
517 SkAutoTUnref<SkPicture> pic;
518 if (!ReadPicture(path.c_str(), &pic)) {
519 continue;
520 }
521 SkString name = SkOSPath::Basename(path.c_str());
522 fSourceType = "skp";
523 fBenchType = "recording";
bsalomon0aa5cea2014-12-15 09:13:35 -0800524 fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic));
mtklein051e56d2014-12-04 08:46:51 -0800525 fSKPOps = pic->approximateOpCount();
mtkleinfd731ce2014-09-10 12:19:30 -0700526 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bbh));
527 }
528
529 // Then once each for each scale as SKPBenches (playback).
mtklein92007582014-08-01 07:46:52 -0700530 while (fCurrentScale < fScales.count()) {
531 while (fCurrentSKP < fSKPs.count()) {
robertphillips5b693772014-11-21 06:19:36 -0800532 const SkString& path = fSKPs[fCurrentSKP];
mtkleinfd731ce2014-09-10 12:19:30 -0700533 SkAutoTUnref<SkPicture> pic;
534 if (!ReadPicture(path.c_str(), &pic)) {
robertphillips5b693772014-11-21 06:19:36 -0800535 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700536 continue;
537 }
robertphillips5b693772014-11-21 06:19:36 -0800538
539 while (fCurrentUseMPD < fUseMPDs.count()) {
540 if (FLAGS_bbh) {
541 // The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
542 SkRTreeFactory factory;
543 SkPictureRecorder recorder;
544 static const int kFlags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
545 pic->playback(recorder.beginRecording(pic->cullRect().width(),
546 pic->cullRect().height(),
mtklein748ca3b2015-01-15 10:56:12 -0800547 &factory,
robertphillipse451c4d2014-12-09 10:28:00 -0800548 fUseMPDs[fCurrentUseMPD] ? kFlags : 0));
robertphillips5b693772014-11-21 06:19:36 -0800549 pic.reset(recorder.endRecording());
550 }
551 SkString name = SkOSPath::Basename(path.c_str());
552 fSourceType = "skp";
553 fBenchType = "playback";
554 return SkNEW_ARGS(SKPBench,
555 (name.c_str(), pic.get(), fClip,
556 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]));
mtklein20840502014-08-21 15:51:22 -0700557 }
robertphillips5b693772014-11-21 06:19:36 -0800558 fCurrentUseMPD = 0;
559 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700560 }
561 fCurrentSKP = 0;
562 fCurrentScale++;
563 }
564
mtkleine714e752014-07-31 12:13:48 -0700565 return NULL;
566 }
mtklein92007582014-08-01 07:46:52 -0700567
568 void fillCurrentOptions(ResultsWriter* log) const {
569 log->configOption("source_type", fSourceType);
mtkleinfd731ce2014-09-10 12:19:30 -0700570 log->configOption("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -0700571 if (0 == strcmp(fSourceType, "skp")) {
572 log->configOption("clip",
573 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
574 fClip.fRight, fClip.fBottom).c_str());
575 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
robertphillips5b693772014-11-21 06:19:36 -0800576 if (fCurrentUseMPD > 0) {
577 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
578 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
579 }
mtklein92007582014-08-01 07:46:52 -0700580 }
mtklein051e56d2014-12-04 08:46:51 -0800581 if (0 == strcmp(fBenchType, "recording")) {
582 log->metric("bytes", fSKPBytes);
583 log->metric("ops", fSKPOps);
584 }
mtklein92007582014-08-01 07:46:52 -0700585 }
586
mtkleine714e752014-07-31 12:13:48 -0700587private:
588 const BenchRegistry* fBenches;
589 const skiagm::GMRegistry* fGMs;
mtklein92007582014-08-01 07:46:52 -0700590 SkIRect fClip;
591 SkTArray<SkScalar> fScales;
592 SkTArray<SkString> fSKPs;
robertphillips5b693772014-11-21 06:19:36 -0800593 SkTArray<bool> fUseMPDs;
mtklein92007582014-08-01 07:46:52 -0700594
mtklein051e56d2014-12-04 08:46:51 -0800595 double fSKPBytes, fSKPOps;
596
mtkleinfd731ce2014-09-10 12:19:30 -0700597 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
598 const char* fBenchType; // How we bench it: micro, recording, playback, ...
599 int fCurrentRecording;
mtklein92007582014-08-01 07:46:52 -0700600 int fCurrentScale;
601 int fCurrentSKP;
robertphillips5b693772014-11-21 06:19:36 -0800602 int fCurrentUseMPD;
mtkleine714e752014-07-31 12:13:48 -0700603};
604
jcgregorio3b27ade2014-11-13 08:06:40 -0800605int nanobench_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700606int nanobench_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800607 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -0700608 SkAutoGraphics ag;
mtklein4f108442014-12-03 13:07:39 -0800609 SkTaskGroup::Enabler enabled;
mtkleinf3723212014-06-25 14:08:00 -0700610
krajcevski69a55602014-08-13 10:46:31 -0700611#if SK_SUPPORT_GPU
krajcevski12b35442014-08-13 12:06:26 -0700612 GrContext::Options grContextOpts;
613 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
614 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts)));
krajcevski69a55602014-08-13 10:46:31 -0700615#endif
616
bsalomon06cddec2014-10-24 10:40:50 -0700617 if (FLAGS_veryVerbose) {
618 FLAGS_verbose = true;
619 }
620
bsalomon6eb03cc2014-08-07 14:28:50 -0700621 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700622 FLAGS_samples = 1;
623 FLAGS_gpuFrameLag = 0;
624 }
625
bsalomon6eb03cc2014-08-07 14:28:50 -0700626 if (!FLAGS_writePath.isEmpty()) {
627 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
628 if (!sk_mkdir(FLAGS_writePath[0])) {
629 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
630 FLAGS_writePath.set(0, NULL);
631 }
632 }
633
mtklein1915b622014-08-20 11:45:00 -0700634 SkAutoTDelete<ResultsWriter> log(SkNEW(ResultsWriter));
mtklein60317d0f2014-07-14 11:30:37 -0700635 if (!FLAGS_outResultsFile.isEmpty()) {
mtklein1915b622014-08-20 11:45:00 -0700636 log.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0])));
mtklein60317d0f2014-07-14 11:30:37 -0700637 }
mtklein1915b622014-08-20 11:45:00 -0700638
639 if (1 == FLAGS_properties.count() % 2) {
640 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
641 return 1;
642 }
643 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
644 log->property(FLAGS_properties[i-1], FLAGS_properties[i]);
645 }
jcgregoriobf5e5232014-07-17 13:14:16 -0700646
647 if (1 == FLAGS_key.count() % 2) {
648 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
649 return 1;
650 }
651 for (int i = 1; i < FLAGS_key.count(); i += 2) {
mtklein1915b622014-08-20 11:45:00 -0700652 log->key(FLAGS_key[i-1], FLAGS_key[i]);
mtklein94e51562014-08-19 12:41:53 -0700653 }
mtklein60317d0f2014-07-14 11:30:37 -0700654
mtkleinf3723212014-06-25 14:08:00 -0700655 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -0700656 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -0400657
mtkleinbb6a0282014-07-01 08:43:42 -0700658 SkAutoTMalloc<double> samples(FLAGS_samples);
659
bsalomon6eb03cc2014-08-07 14:28:50 -0700660 if (kAutoTuneLoops != FLAGS_loops) {
661 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleina189ccd2014-07-14 12:28:47 -0700662 } else if (FLAGS_verbose) {
mtkleinf3723212014-06-25 14:08:00 -0700663 // No header.
664 } else if (FLAGS_quiet) {
mtklein40b32be2014-07-09 08:46:49 -0700665 SkDebugf("median\tbench\tconfig\n");
mtkleinf3723212014-06-25 14:08:00 -0700666 } else {
qiankun.miao8247ec32014-09-09 19:24:36 -0700667 SkDebugf("maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
668 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -0700669 }
670
bsalomonc2553372014-07-22 13:09:05 -0700671 SkTDArray<Config> configs;
672 create_configs(&configs);
673
mtkleine070c2b2014-10-14 08:40:43 -0700674 int runs = 0;
mtklein92007582014-08-01 07:46:52 -0700675 BenchmarkStream benchStream;
676 while (Benchmark* b = benchStream.next()) {
mtkleine714e752014-07-31 12:13:48 -0700677 SkAutoTDelete<Benchmark> bench(b);
mtklein96289052014-09-10 12:05:59 -0700678 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -0700679 continue;
680 }
681
mtkleinbb6a0282014-07-01 08:43:42 -0700682 SkTDArray<Target*> targets;
bsalomonc2553372014-07-22 13:09:05 -0700683 create_targets(&targets, bench.get(), configs);
mtkleinf3723212014-06-25 14:08:00 -0700684
jcgregoriobf5e5232014-07-17 13:14:16 -0700685 if (!targets.isEmpty()) {
mtklein96289052014-09-10 12:05:59 -0700686 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
jcgregoriobf5e5232014-07-17 13:14:16 -0700687 bench->preDraw();
688 }
mtkleinbb6a0282014-07-01 08:43:42 -0700689 for (int j = 0; j < targets.count(); j++) {
690 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->getCanvas() : NULL;
bsalomonc2553372014-07-22 13:09:05 -0700691 const char* config = targets[j]->config.name;
mtkleinf3723212014-06-25 14:08:00 -0700692
robertphillips5b693772014-11-21 06:19:36 -0800693#if SK_SUPPORT_GPU
694 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
695 setup_gl(targets[j]->gl);
696 }
697#endif
698
699 bench->perCanvasPreDraw(canvas);
700
mtkleinbb6a0282014-07-01 08:43:42 -0700701 const int loops =
702#if SK_SUPPORT_GPU
bsalomonc2553372014-07-22 13:09:05 -0700703 Benchmark::kGPU_Backend == targets[j]->config.backend
mtkleinbb6a0282014-07-01 08:43:42 -0700704 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
705 :
706#endif
707 cpu_bench( overhead, bench.get(), canvas, samples.get());
mtkleinf3723212014-06-25 14:08:00 -0700708
robertphillips5b693772014-11-21 06:19:36 -0800709 bench->perCanvasPostDraw(canvas);
710
bsalomon49f085d2014-09-05 13:34:00 -0700711 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700712 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -0700713 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -0700714 pngFilename.append(".png");
715 write_canvas_png(canvas, pngFilename);
716 }
717
718 if (kFailedLoops == loops) {
mtklein2069e222014-08-04 13:57:39 -0700719 // Can't be timed. A warning note has already been printed.
Mike Kleine3631362014-07-15 17:56:37 -0400720 continue;
721 }
722
mtkleinf3723212014-06-25 14:08:00 -0700723 Stats stats(samples.get(), FLAGS_samples);
mtklein1915b622014-08-20 11:45:00 -0700724 log->config(config);
mtklein96289052014-09-10 12:05:59 -0700725 log->configOption("name", bench->getName());
mtklein1915b622014-08-20 11:45:00 -0700726 benchStream.fillCurrentOptions(log.get());
jcgregoriobf5e5232014-07-17 13:14:16 -0700727#if SK_SUPPORT_GPU
bsalomonc2553372014-07-22 13:09:05 -0700728 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
mtklein1915b622014-08-20 11:45:00 -0700729 fill_gpu_options(log.get(), targets[j]->gl);
jcgregoriobf5e5232014-07-17 13:14:16 -0700730 }
731#endif
mtklein051e56d2014-12-04 08:46:51 -0800732 log->metric("min_ms", stats.min);
mtkleine070c2b2014-10-14 08:40:43 -0700733 if (runs++ % FLAGS_flushEvery == 0) {
734 log->flush();
735 }
mtklein60317d0f2014-07-14 11:30:37 -0700736
bsalomon6eb03cc2014-08-07 14:28:50 -0700737 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700738 if (targets.count() == 1) {
739 config = ""; // Only print the config if we run the same bench on more than one.
740 }
mtklein53d25622014-09-18 07:39:42 -0700741 SkDebugf("%4dM\t%s\t%s\n"
742 , sk_tools::getMaxResidentSetSizeMB()
743 , bench->getUniqueName()
744 , config);
mtkleina189ccd2014-07-14 12:28:47 -0700745 } else if (FLAGS_verbose) {
mtkleinf3723212014-06-25 14:08:00 -0700746 for (int i = 0; i < FLAGS_samples; i++) {
mtklein55b0ffc2014-07-17 08:38:23 -0700747 SkDebugf("%s ", HUMANIZE(samples[i]));
mtkleinf3723212014-06-25 14:08:00 -0700748 }
mtklein96289052014-09-10 12:05:59 -0700749 SkDebugf("%s\n", bench->getUniqueName());
mtkleinf3723212014-06-25 14:08:00 -0700750 } else if (FLAGS_quiet) {
mtkleinbb6a0282014-07-01 08:43:42 -0700751 if (targets.count() == 1) {
mtkleinf3723212014-06-25 14:08:00 -0700752 config = ""; // Only print the config if we run the same bench on more than one.
753 }
mtklein96289052014-09-10 12:05:59 -0700754 SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getUniqueName(), config);
mtkleinf3723212014-06-25 14:08:00 -0700755 } else {
756 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
mtkleinafb43792014-08-19 15:55:55 -0700757 SkDebugf("%4dM\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n"
758 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -0700759 , loops
mtklein55b0ffc2014-07-17 08:38:23 -0700760 , HUMANIZE(stats.min)
761 , HUMANIZE(stats.median)
762 , HUMANIZE(stats.mean)
763 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -0700764 , stddev_percent
mtklein5d9d10e2014-07-11 11:57:07 -0700765 , stats.plot.c_str()
mtkleinf3723212014-06-25 14:08:00 -0700766 , config
mtklein96289052014-09-10 12:05:59 -0700767 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -0700768 );
769 }
bsalomonb12ea412015-02-02 21:19:50 -0800770#if SK_SUPPORT_GPU
771 if (FLAGS_gpuStats &&
bsalomon06cddec2014-10-24 10:40:50 -0700772 Benchmark::kGPU_Backend == targets[j]->config.backend) {
mtklein6838d852014-10-29 14:15:10 -0700773 gGrFactory->get(targets[j]->config.ctxType)->printCacheStats();
bsalomonb12ea412015-02-02 21:19:50 -0800774 gGrFactory->get(targets[j]->config.ctxType)->printGpuStats();
bsalomon06cddec2014-10-24 10:40:50 -0700775 }
776#endif
mtkleinf3723212014-06-25 14:08:00 -0700777 }
mtkleinbb6a0282014-07-01 08:43:42 -0700778 targets.deleteAll();
Mike Klein3944a1d2014-07-15 13:40:19 -0400779
bsalomon06cddec2014-10-24 10:40:50 -0700780#if SK_SUPPORT_GPU
bsalomon2354f842014-07-28 13:48:36 -0700781 if (FLAGS_abandonGpuContext) {
krajcevski69a55602014-08-13 10:46:31 -0700782 gGrFactory->abandonContexts();
bsalomon2354f842014-07-28 13:48:36 -0700783 }
784 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) {
krajcevski69a55602014-08-13 10:46:31 -0700785 gGrFactory->destroyContexts();
Mike Klein3944a1d2014-07-15 13:40:19 -0400786 }
bsalomon06cddec2014-10-24 10:40:50 -0700787#endif
mtkleinf3723212014-06-25 14:08:00 -0700788 }
789
mtkleine1091452014-12-04 10:47:02 -0800790 log->bench("memory_usage", 0,0);
791 log->config("meta");
792 log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
793
mtkleinf3723212014-06-25 14:08:00 -0700794 return 0;
795}
796
jcgregorio3b27ade2014-11-13 08:06:40 -0800797#if !defined SK_BUILD_FOR_IOS
798int main(int argc, char** argv) {
799 SkCommandLineFlags::Parse(argc, argv);
800 return nanobench_main();
801}
802#endif