blob: 12686e3a8476f53123ebaff725f35a3dc5ba0c7d [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));
mtklein748ca3b2015-01-15 10:56:12 -080080 return HumanizeMs(ms);
mtkleinf3723212014-06-25 14:08:00 -070081}
mtklein55b0ffc2014-07-17 08:38:23 -070082#define HUMANIZE(ms) humanize(ms).c_str()
mtkleinf3723212014-06-25 14:08:00 -070083
kkinnunen9e61bb72014-10-09 05:24:15 -070084static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContext* gl) {
bsalomon6eb03cc2014-08-07 14:28:50 -070085 if (canvas) {
86 canvas->clear(SK_ColorWHITE);
87 }
mtkleinbb6a0282014-07-01 08:43:42 -070088 WallTimer timer;
89 timer.start();
90 if (bench) {
91 bench->draw(loops, canvas);
92 }
93 if (canvas) {
94 canvas->flush();
95 }
96#if SK_SUPPORT_GPU
97 if (gl) {
98 SK_GL(*gl, Flush());
99 gl->swapBuffers();
100 }
101#endif
102 timer.end();
103 return timer.fWall;
104}
105
mtkleinf3723212014-06-25 14:08:00 -0700106static double estimate_timer_overhead() {
107 double overhead = 0;
mtkleinf3723212014-06-25 14:08:00 -0700108 for (int i = 0; i < FLAGS_overheadLoops; i++) {
mtkleinbb6a0282014-07-01 08:43:42 -0700109 overhead += time(1, NULL, NULL, NULL);
mtkleinf3723212014-06-25 14:08:00 -0700110 }
111 return overhead / FLAGS_overheadLoops;
112}
113
reed53249782014-10-10 09:09:52 -0700114static int detect_forever_loops(int loops) {
115 // look for a magic run-forever value
116 if (loops < 0) {
117 loops = SK_MaxS32;
118 }
119 return loops;
120}
121
mtklein55b0ffc2014-07-17 08:38:23 -0700122static int clamp_loops(int loops) {
123 if (loops < 1) {
mtklein527930f2014-11-06 08:04:34 -0800124 SkDebugf("ERROR: clamping loops from %d to 1. "
125 "There's probably something wrong with the bench.\n", loops);
mtklein55b0ffc2014-07-17 08:38:23 -0700126 return 1;
127 }
128 if (loops > FLAGS_maxLoops) {
129 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
130 return FLAGS_maxLoops;
131 }
132 return loops;
133}
134
bsalomon6eb03cc2014-08-07 14:28:50 -0700135static bool write_canvas_png(SkCanvas* canvas, const SkString& filename) {
136 if (filename.isEmpty()) {
137 return false;
138 }
reede5ea5002014-09-03 11:54:58 -0700139 if (kUnknown_SkColorType == canvas->imageInfo().colorType()) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700140 return false;
141 }
142 SkBitmap bmp;
143 bmp.setInfo(canvas->imageInfo());
144 if (!canvas->readPixels(&bmp, 0, 0)) {
145 SkDebugf("Can't read canvas pixels.\n");
146 return false;
147 }
148 SkString dir = SkOSPath::Dirname(filename.c_str());
149 if (!sk_mkdir(dir.c_str())) {
150 SkDebugf("Can't make dir %s.\n", dir.c_str());
151 return false;
152 }
153 SkFILEWStream stream(filename.c_str());
154 if (!stream.isValid()) {
155 SkDebugf("Can't write %s.\n", filename.c_str());
156 return false;
157 }
158 if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) {
159 SkDebugf("Can't encode a PNG.\n");
160 return false;
161 }
162 return true;
163}
164
165static int kFailedLoops = -2;
mtkleinbb6a0282014-07-01 08:43:42 -0700166static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas, double* samples) {
167 // First figure out approximately how many loops of bench it takes to make overhead negligible.
mtklein2069e222014-08-04 13:57:39 -0700168 double bench_plus_overhead = 0.0;
mtklein55b0ffc2014-07-17 08:38:23 -0700169 int round = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -0700170 if (kAutoTuneLoops == FLAGS_loops) {
171 while (bench_plus_overhead < overhead) {
172 if (round++ == FLAGS_maxCalibrationAttempts) {
173 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
mtklein96289052014-09-10 12:05:59 -0700174 bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
bsalomon6eb03cc2014-08-07 14:28:50 -0700175 return kFailedLoops;
176 }
177 bench_plus_overhead = time(1, bench, canvas, NULL);
mtklein55b0ffc2014-07-17 08:38:23 -0700178 }
mtklein2069e222014-08-04 13:57:39 -0700179 }
mtkleinf3723212014-06-25 14:08:00 -0700180
mtkleinbb6a0282014-07-01 08:43:42 -0700181 // Later we'll just start and stop the timer once but loop N times.
mtkleinf3723212014-06-25 14:08:00 -0700182 // We'll pick N to make timer overhead negligible:
183 //
mtkleinbb6a0282014-07-01 08:43:42 -0700184 // overhead
185 // ------------------------- < FLAGS_overheadGoal
186 // overhead + N * Bench Time
mtkleinf3723212014-06-25 14:08:00 -0700187 //
mtkleinbb6a0282014-07-01 08:43:42 -0700188 // where bench_plus_overhead ≈ overhead + Bench Time.
mtkleinf3723212014-06-25 14:08:00 -0700189 //
190 // Doing some math, we get:
191 //
mtkleinbb6a0282014-07-01 08:43:42 -0700192 // (overhead / FLAGS_overheadGoal) - overhead
193 // ------------------------------------------ < N
194 // bench_plus_overhead - overhead)
mtkleinf3723212014-06-25 14:08:00 -0700195 //
196 // Luckily, this also works well in practice. :)
bsalomon6eb03cc2014-08-07 14:28:50 -0700197 int loops = FLAGS_loops;
198 if (kAutoTuneLoops == loops) {
199 const double numer = overhead / FLAGS_overheadGoal - overhead;
200 const double denom = bench_plus_overhead - overhead;
201 loops = (int)ceil(numer / denom);
reed53249782014-10-10 09:09:52 -0700202 loops = clamp_loops(loops);
203 } else {
204 loops = detect_forever_loops(loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700205 }
mtkleinbb6a0282014-07-01 08:43:42 -0700206
207 for (int i = 0; i < FLAGS_samples; i++) {
208 samples[i] = time(loops, bench, canvas, NULL) / loops;
209 }
210 return loops;
mtkleinf3723212014-06-25 14:08:00 -0700211}
212
mtkleinbb6a0282014-07-01 08:43:42 -0700213#if SK_SUPPORT_GPU
robertphillips5b693772014-11-21 06:19:36 -0800214static void setup_gl(SkGLContext* gl) {
215 gl->makeCurrent();
216 // Make sure we're done with whatever came before.
217 SK_GL(*gl, Finish());
218}
219
kkinnunen9e61bb72014-10-09 05:24:15 -0700220static int gpu_bench(SkGLContext* gl,
mtkleinbb6a0282014-07-01 08:43:42 -0700221 Benchmark* bench,
222 SkCanvas* canvas,
223 double* samples) {
mtkleinbb6a0282014-07-01 08:43:42 -0700224 // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
bsalomon6eb03cc2014-08-07 14:28:50 -0700225 int loops = FLAGS_loops;
226 if (kAutoTuneLoops == loops) {
227 loops = 1;
mtkleina189ccd2014-07-14 12:28:47 -0700228 double elapsed = 0;
229 do {
mtklein527930f2014-11-06 08:04:34 -0800230 if (1<<30 == loops) {
231 // We're about to wrap. Something's wrong with the bench.
232 loops = 0;
233 break;
234 }
mtkleina189ccd2014-07-14 12:28:47 -0700235 loops *= 2;
236 // If the GPU lets frames lag at all, we need to make sure we're timing
237 // _this_ round, not still timing last round. We force this by looping
238 // more times than any reasonable GPU will allow frames to lag.
239 for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
240 elapsed = time(loops, bench, canvas, gl);
241 }
242 } while (elapsed < FLAGS_gpuMs);
mtkleinbb6a0282014-07-01 08:43:42 -0700243
mtkleina189ccd2014-07-14 12:28:47 -0700244 // We've overshot at least a little. Scale back linearly.
245 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
reed53249782014-10-10 09:09:52 -0700246 loops = clamp_loops(loops);
mtkleinbb6a0282014-07-01 08:43:42 -0700247
mtkleina189ccd2014-07-14 12:28:47 -0700248 // Might as well make sure we're not still timing our calibration.
249 SK_GL(*gl, Finish());
reed53249782014-10-10 09:09:52 -0700250 } else {
251 loops = detect_forever_loops(loops);
mtkleina189ccd2014-07-14 12:28:47 -0700252 }
mtkleinbb6a0282014-07-01 08:43:42 -0700253
254 // Pretty much the same deal as the calibration: do some warmup to make
255 // sure we're timing steady-state pipelined frames.
256 for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
257 time(loops, bench, canvas, gl);
mtkleinf3723212014-06-25 14:08:00 -0700258 }
mtkleinbb6a0282014-07-01 08:43:42 -0700259
260 // Now, actually do the timing!
261 for (int i = 0; i < FLAGS_samples; i++) {
262 samples[i] = time(loops, bench, canvas, gl) / loops;
263 }
264 return loops;
265}
266#endif
267
268static SkString to_lower(const char* str) {
269 SkString lower(str);
270 for (size_t i = 0; i < lower.size(); i++) {
271 lower[i] = tolower(lower[i]);
272 }
273 return lower;
mtkleinf3723212014-06-25 14:08:00 -0700274}
275
bsalomonc2553372014-07-22 13:09:05 -0700276struct Config {
277 const char* name;
mtkleinbb6a0282014-07-01 08:43:42 -0700278 Benchmark::Backend backend;
bsalomonc2553372014-07-22 13:09:05 -0700279 SkColorType color;
280 SkAlphaType alpha;
281 int samples;
282#if SK_SUPPORT_GPU
283 GrContextFactory::GLContextType ctxType;
jvanverth4736e142014-11-07 07:12:46 -0800284 bool useDFText;
bsalomonc2553372014-07-22 13:09:05 -0700285#else
286 int bogusInt;
jvanverth4736e142014-11-07 07:12:46 -0800287 bool bogusBool;
bsalomonc2553372014-07-22 13:09:05 -0700288#endif
289};
290
291struct Target {
292 explicit Target(const Config& c) : config(c) {}
293 const Config config;
mtkleinbb6a0282014-07-01 08:43:42 -0700294 SkAutoTDelete<SkSurface> surface;
295#if SK_SUPPORT_GPU
kkinnunen9e61bb72014-10-09 05:24:15 -0700296 SkGLContext* gl;
mtkleinbb6a0282014-07-01 08:43:42 -0700297#endif
298};
mtkleinf3723212014-06-25 14:08:00 -0700299
bsalomonc2553372014-07-22 13:09:05 -0700300static bool is_cpu_config_allowed(const char* name) {
mtkleinbb6a0282014-07-01 08:43:42 -0700301 for (int i = 0; i < FLAGS_config.count(); i++) {
bsalomonc2553372014-07-22 13:09:05 -0700302 if (to_lower(FLAGS_config[i]).equals(name)) {
303 return true;
mtkleinf3723212014-06-25 14:08:00 -0700304 }
305 }
bsalomonc2553372014-07-22 13:09:05 -0700306 return false;
mtkleinbb6a0282014-07-01 08:43:42 -0700307}
308
bsalomonc2553372014-07-22 13:09:05 -0700309#if SK_SUPPORT_GPU
310static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextType ctxType,
311 int sampleCnt) {
312 if (!is_cpu_config_allowed(name)) {
313 return false;
314 }
krajcevski69a55602014-08-13 10:46:31 -0700315 if (const GrContext* ctx = gGrFactory->get(ctxType)) {
bsalomonc2553372014-07-22 13:09:05 -0700316 return sampleCnt <= ctx->getMaxSampleCount();
317 }
318 return false;
319}
320#endif
mtkleinbb6a0282014-07-01 08:43:42 -0700321
bsalomonc2553372014-07-22 13:09:05 -0700322#if SK_SUPPORT_GPU
323#define kBogusGLContextType GrContextFactory::kNative_GLContextType
324#else
325#define kBogusGLContextType 0
mtkleine714e752014-07-31 12:13:48 -0700326#endif
bsalomonc2553372014-07-22 13:09:05 -0700327
328// Append all configs that are enabled and supported.
329static void create_configs(SkTDArray<Config>* configs) {
jvanverth4736e142014-11-07 07:12:46 -0800330 #define CPU_CONFIG(name, backend, color, alpha) \
331 if (is_cpu_config_allowed(#name)) { \
332 Config config = { #name, Benchmark::backend, color, alpha, 0, \
333 kBogusGLContextType, false }; \
334 configs->push(config); \
mtkleinbb6a0282014-07-01 08:43:42 -0700335 }
mtkleine714e752014-07-31 12:13:48 -0700336
mtklein40b32be2014-07-09 08:46:49 -0700337 if (FLAGS_cpu) {
bsalomonc2553372014-07-22 13:09:05 -0700338 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kUnpremul_SkAlphaType)
339 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType)
340 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType)
mtklein40b32be2014-07-09 08:46:49 -0700341 }
mtkleinbb6a0282014-07-01 08:43:42 -0700342
343#if SK_SUPPORT_GPU
jvanverth4736e142014-11-07 07:12:46 -0800344 #define GPU_CONFIG(name, ctxType, samples, useDFText) \
bsalomonc2553372014-07-22 13:09:05 -0700345 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \
346 Config config = { \
347 #name, \
348 Benchmark::kGPU_Backend, \
349 kN32_SkColorType, \
350 kPremul_SkAlphaType, \
351 samples, \
jvanverth4736e142014-11-07 07:12:46 -0800352 GrContextFactory::ctxType, \
353 useDFText }; \
bsalomonc2553372014-07-22 13:09:05 -0700354 configs->push(config); \
mtkleinbb6a0282014-07-01 08:43:42 -0700355 }
mtkleine714e752014-07-31 12:13:48 -0700356
mtklein40b32be2014-07-09 08:46:49 -0700357 if (FLAGS_gpu) {
jvanverth4736e142014-11-07 07:12:46 -0800358 GPU_CONFIG(gpu, kNative_GLContextType, 0, false)
359 GPU_CONFIG(msaa4, kNative_GLContextType, 4, false)
360 GPU_CONFIG(msaa16, kNative_GLContextType, 16, false)
361 GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4, false)
362 GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16, false)
363 GPU_CONFIG(gpudft, kNative_GLContextType, 0, true)
364 GPU_CONFIG(debug, kDebug_GLContextType, 0, false)
365 GPU_CONFIG(nullgpu, kNull_GLContextType, 0, false)
bsalomon3b4d0772014-08-06 10:52:33 -0700366#ifdef SK_ANGLE
jvanverth4736e142014-11-07 07:12:46 -0800367 GPU_CONFIG(angle, kANGLE_GLContextType, 0, false)
bsalomon3b4d0772014-08-06 10:52:33 -0700368#endif
mtklein40b32be2014-07-09 08:46:49 -0700369 }
mtkleinbb6a0282014-07-01 08:43:42 -0700370#endif
mtkleinf3723212014-06-25 14:08:00 -0700371}
372
bsalomonc2553372014-07-22 13:09:05 -0700373// If bench is enabled for config, returns a Target* for it, otherwise NULL.
374static Target* is_enabled(Benchmark* bench, const Config& config) {
375 if (!bench->isSuitableFor(config.backend)) {
376 return NULL;
377 }
378
reede5ea5002014-09-03 11:54:58 -0700379 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
380 config.color, config.alpha);
bsalomonc2553372014-07-22 13:09:05 -0700381
382 Target* target = new Target(config);
383
384 if (Benchmark::kRaster_Backend == config.backend) {
385 target->surface.reset(SkSurface::NewRaster(info));
386 }
387#if SK_SUPPORT_GPU
388 else if (Benchmark::kGPU_Backend == config.backend) {
jvanverth4736e142014-11-07 07:12:46 -0800389 uint32_t flags = config.useDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
390 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
krajcevski69a55602014-08-13 10:46:31 -0700391 target->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(config.ctxType), info,
jvanverth4736e142014-11-07 07:12:46 -0800392 config.samples, &props));
krajcevski69a55602014-08-13 10:46:31 -0700393 target->gl = gGrFactory->getGLContext(config.ctxType);
bsalomonc2553372014-07-22 13:09:05 -0700394 }
395#endif
396
397 if (Benchmark::kNonRendering_Backend != config.backend && !target->surface.get()) {
398 delete target;
399 return NULL;
400 }
401 return target;
402}
403
404// Creates targets for a benchmark and a set of configs.
405static void create_targets(SkTDArray<Target*>* targets, Benchmark* b,
406 const SkTDArray<Config>& configs) {
407 for (int i = 0; i < configs.count(); ++i) {
408 if (Target* t = is_enabled(b, configs[i])) {
409 targets->push(t);
410 }
mtkleine714e752014-07-31 12:13:48 -0700411
bsalomonc2553372014-07-22 13:09:05 -0700412 }
413}
414
jcgregoriobf5e5232014-07-17 13:14:16 -0700415#if SK_SUPPORT_GPU
kkinnunen9e61bb72014-10-09 05:24:15 -0700416static void fill_gpu_options(ResultsWriter* log, SkGLContext* ctx) {
jcgregorio05c45602014-07-17 13:54:36 -0700417 const GrGLubyte* version;
jcgregoriobf5e5232014-07-17 13:14:16 -0700418 SK_GL_RET(*ctx, version, GetString(GR_GL_VERSION));
419 log->configOption("GL_VERSION", (const char*)(version));
420
421 SK_GL_RET(*ctx, version, GetString(GR_GL_RENDERER));
422 log->configOption("GL_RENDERER", (const char*) version);
423
424 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR));
425 log->configOption("GL_VENDOR", (const char*) version);
426
427 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
428 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
429}
430#endif
431
mtkleine714e752014-07-31 12:13:48 -0700432class BenchmarkStream {
433public:
mtklein92007582014-08-01 07:46:52 -0700434 BenchmarkStream() : fBenches(BenchRegistry::Head())
435 , fGMs(skiagm::GMRegistry::Head())
mtkleinfd731ce2014-09-10 12:19:30 -0700436 , fCurrentRecording(0)
mtklein92007582014-08-01 07:46:52 -0700437 , fCurrentScale(0)
robertphillips5b693772014-11-21 06:19:36 -0800438 , fCurrentSKP(0)
439 , fCurrentUseMPD(0) {
mtklein92007582014-08-01 07:46:52 -0700440 for (int i = 0; i < FLAGS_skps.count(); i++) {
441 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
442 fSKPs.push_back() = FLAGS_skps[i];
443 } else {
444 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
445 SkString path;
446 while (it.next(&path)) {
447 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
448 }
449 }
450 }
mtkleine714e752014-07-31 12:13:48 -0700451
mtklein92007582014-08-01 07:46:52 -0700452 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
453 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
454 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
455 exit(1);
456 }
457
458 for (int i = 0; i < FLAGS_scales.count(); i++) {
459 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
460 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
461 exit(1);
462 }
463 }
robertphillips5b693772014-11-21 06:19:36 -0800464
465 fUseMPDs.push_back() = false;
466 if (FLAGS_mpd) {
467 fUseMPDs.push_back() = true;
468 }
mtklein92007582014-08-01 07:46:52 -0700469 }
470
mtkleinfd731ce2014-09-10 12:19:30 -0700471 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
472 // Not strictly necessary, as it will be checked again later,
473 // but helps to avoid a lot of pointless work if we're going to skip it.
474 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
475 return false;
476 }
477
478 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
479 if (stream.get() == NULL) {
480 SkDebugf("Could not read %s.\n", path);
481 return false;
482 }
483
mtklein535776e2014-11-25 14:57:26 -0800484 pic->reset(SkPicture::CreateFromStream(stream.get()));
mtkleinfd731ce2014-09-10 12:19:30 -0700485 if (pic->get() == NULL) {
486 SkDebugf("Could not read %s as an SkPicture.\n", path);
487 return false;
488 }
489 return true;
490 }
491
mtklein92007582014-08-01 07:46:52 -0700492 Benchmark* next() {
mtkleine714e752014-07-31 12:13:48 -0700493 if (fBenches) {
494 Benchmark* bench = fBenches->factory()(NULL);
495 fBenches = fBenches->next();
mtklein92007582014-08-01 07:46:52 -0700496 fSourceType = "bench";
mtkleinfd731ce2014-09-10 12:19:30 -0700497 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700498 return bench;
499 }
mtklein92007582014-08-01 07:46:52 -0700500
mtkleine714e752014-07-31 12:13:48 -0700501 while (fGMs) {
502 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL));
503 fGMs = fGMs->next();
504 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) {
mtklein92007582014-08-01 07:46:52 -0700505 fSourceType = "gm";
mtkleinfd731ce2014-09-10 12:19:30 -0700506 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700507 return SkNEW_ARGS(GMBench, (gm.detach()));
508 }
509 }
mtklein92007582014-08-01 07:46:52 -0700510
mtkleinfd731ce2014-09-10 12:19:30 -0700511 // First add all .skps as RecordingBenches.
512 while (fCurrentRecording < fSKPs.count()) {
513 const SkString& path = fSKPs[fCurrentRecording++];
514 SkAutoTUnref<SkPicture> pic;
515 if (!ReadPicture(path.c_str(), &pic)) {
516 continue;
517 }
518 SkString name = SkOSPath::Basename(path.c_str());
519 fSourceType = "skp";
520 fBenchType = "recording";
bsalomon0aa5cea2014-12-15 09:13:35 -0800521 fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic));
mtklein051e56d2014-12-04 08:46:51 -0800522 fSKPOps = pic->approximateOpCount();
mtkleinfd731ce2014-09-10 12:19:30 -0700523 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bbh));
524 }
525
526 // Then once each for each scale as SKPBenches (playback).
mtklein92007582014-08-01 07:46:52 -0700527 while (fCurrentScale < fScales.count()) {
528 while (fCurrentSKP < fSKPs.count()) {
robertphillips5b693772014-11-21 06:19:36 -0800529 const SkString& path = fSKPs[fCurrentSKP];
mtkleinfd731ce2014-09-10 12:19:30 -0700530 SkAutoTUnref<SkPicture> pic;
531 if (!ReadPicture(path.c_str(), &pic)) {
robertphillips5b693772014-11-21 06:19:36 -0800532 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700533 continue;
534 }
robertphillips5b693772014-11-21 06:19:36 -0800535
536 while (fCurrentUseMPD < fUseMPDs.count()) {
537 if (FLAGS_bbh) {
538 // The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
539 SkRTreeFactory factory;
540 SkPictureRecorder recorder;
541 static const int kFlags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
542 pic->playback(recorder.beginRecording(pic->cullRect().width(),
543 pic->cullRect().height(),
mtklein748ca3b2015-01-15 10:56:12 -0800544 &factory,
robertphillipse451c4d2014-12-09 10:28:00 -0800545 fUseMPDs[fCurrentUseMPD] ? kFlags : 0));
robertphillips5b693772014-11-21 06:19:36 -0800546 pic.reset(recorder.endRecording());
547 }
548 SkString name = SkOSPath::Basename(path.c_str());
549 fSourceType = "skp";
550 fBenchType = "playback";
551 return SkNEW_ARGS(SKPBench,
552 (name.c_str(), pic.get(), fClip,
553 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]));
mtklein20840502014-08-21 15:51:22 -0700554 }
robertphillips5b693772014-11-21 06:19:36 -0800555 fCurrentUseMPD = 0;
556 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700557 }
558 fCurrentSKP = 0;
559 fCurrentScale++;
560 }
561
mtkleine714e752014-07-31 12:13:48 -0700562 return NULL;
563 }
mtklein92007582014-08-01 07:46:52 -0700564
565 void fillCurrentOptions(ResultsWriter* log) const {
566 log->configOption("source_type", fSourceType);
mtkleinfd731ce2014-09-10 12:19:30 -0700567 log->configOption("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -0700568 if (0 == strcmp(fSourceType, "skp")) {
569 log->configOption("clip",
570 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
571 fClip.fRight, fClip.fBottom).c_str());
572 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
robertphillips5b693772014-11-21 06:19:36 -0800573 if (fCurrentUseMPD > 0) {
574 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
575 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
576 }
mtklein92007582014-08-01 07:46:52 -0700577 }
mtklein051e56d2014-12-04 08:46:51 -0800578 if (0 == strcmp(fBenchType, "recording")) {
579 log->metric("bytes", fSKPBytes);
580 log->metric("ops", fSKPOps);
581 }
mtklein92007582014-08-01 07:46:52 -0700582 }
583
mtkleine714e752014-07-31 12:13:48 -0700584private:
585 const BenchRegistry* fBenches;
586 const skiagm::GMRegistry* fGMs;
mtklein92007582014-08-01 07:46:52 -0700587 SkIRect fClip;
588 SkTArray<SkScalar> fScales;
589 SkTArray<SkString> fSKPs;
robertphillips5b693772014-11-21 06:19:36 -0800590 SkTArray<bool> fUseMPDs;
mtklein92007582014-08-01 07:46:52 -0700591
mtklein051e56d2014-12-04 08:46:51 -0800592 double fSKPBytes, fSKPOps;
593
mtkleinfd731ce2014-09-10 12:19:30 -0700594 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
595 const char* fBenchType; // How we bench it: micro, recording, playback, ...
596 int fCurrentRecording;
mtklein92007582014-08-01 07:46:52 -0700597 int fCurrentScale;
598 int fCurrentSKP;
robertphillips5b693772014-11-21 06:19:36 -0800599 int fCurrentUseMPD;
mtkleine714e752014-07-31 12:13:48 -0700600};
601
jcgregorio3b27ade2014-11-13 08:06:40 -0800602int nanobench_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700603int nanobench_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800604 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -0700605 SkAutoGraphics ag;
mtklein4f108442014-12-03 13:07:39 -0800606 SkTaskGroup::Enabler enabled;
mtkleinf3723212014-06-25 14:08:00 -0700607
krajcevski69a55602014-08-13 10:46:31 -0700608#if SK_SUPPORT_GPU
krajcevski12b35442014-08-13 12:06:26 -0700609 GrContext::Options grContextOpts;
610 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
611 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts)));
krajcevski69a55602014-08-13 10:46:31 -0700612#endif
613
bsalomon06cddec2014-10-24 10:40:50 -0700614 if (FLAGS_veryVerbose) {
615 FLAGS_verbose = true;
616 }
617
bsalomon6eb03cc2014-08-07 14:28:50 -0700618 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700619 FLAGS_samples = 1;
620 FLAGS_gpuFrameLag = 0;
621 }
622
bsalomon6eb03cc2014-08-07 14:28:50 -0700623 if (!FLAGS_writePath.isEmpty()) {
624 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
625 if (!sk_mkdir(FLAGS_writePath[0])) {
626 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
627 FLAGS_writePath.set(0, NULL);
628 }
629 }
630
mtklein1915b622014-08-20 11:45:00 -0700631 SkAutoTDelete<ResultsWriter> log(SkNEW(ResultsWriter));
mtklein60317d0f2014-07-14 11:30:37 -0700632 if (!FLAGS_outResultsFile.isEmpty()) {
mtklein1915b622014-08-20 11:45:00 -0700633 log.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0])));
mtklein60317d0f2014-07-14 11:30:37 -0700634 }
mtklein1915b622014-08-20 11:45:00 -0700635
636 if (1 == FLAGS_properties.count() % 2) {
637 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
638 return 1;
639 }
640 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
641 log->property(FLAGS_properties[i-1], FLAGS_properties[i]);
642 }
jcgregoriobf5e5232014-07-17 13:14:16 -0700643
644 if (1 == FLAGS_key.count() % 2) {
645 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
646 return 1;
647 }
648 for (int i = 1; i < FLAGS_key.count(); i += 2) {
mtklein1915b622014-08-20 11:45:00 -0700649 log->key(FLAGS_key[i-1], FLAGS_key[i]);
mtklein94e51562014-08-19 12:41:53 -0700650 }
mtklein60317d0f2014-07-14 11:30:37 -0700651
mtkleinf3723212014-06-25 14:08:00 -0700652 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -0700653 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -0400654
mtkleinbb6a0282014-07-01 08:43:42 -0700655 SkAutoTMalloc<double> samples(FLAGS_samples);
656
bsalomon6eb03cc2014-08-07 14:28:50 -0700657 if (kAutoTuneLoops != FLAGS_loops) {
658 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleina189ccd2014-07-14 12:28:47 -0700659 } else if (FLAGS_verbose) {
mtkleinf3723212014-06-25 14:08:00 -0700660 // No header.
661 } else if (FLAGS_quiet) {
mtklein40b32be2014-07-09 08:46:49 -0700662 SkDebugf("median\tbench\tconfig\n");
mtkleinf3723212014-06-25 14:08:00 -0700663 } else {
qiankun.miao8247ec32014-09-09 19:24:36 -0700664 SkDebugf("maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
665 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -0700666 }
667
bsalomonc2553372014-07-22 13:09:05 -0700668 SkTDArray<Config> configs;
669 create_configs(&configs);
670
mtkleine070c2b2014-10-14 08:40:43 -0700671 int runs = 0;
mtklein92007582014-08-01 07:46:52 -0700672 BenchmarkStream benchStream;
673 while (Benchmark* b = benchStream.next()) {
mtkleine714e752014-07-31 12:13:48 -0700674 SkAutoTDelete<Benchmark> bench(b);
mtklein96289052014-09-10 12:05:59 -0700675 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -0700676 continue;
677 }
678
mtkleinbb6a0282014-07-01 08:43:42 -0700679 SkTDArray<Target*> targets;
bsalomonc2553372014-07-22 13:09:05 -0700680 create_targets(&targets, bench.get(), configs);
mtkleinf3723212014-06-25 14:08:00 -0700681
jcgregoriobf5e5232014-07-17 13:14:16 -0700682 if (!targets.isEmpty()) {
mtklein96289052014-09-10 12:05:59 -0700683 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
jcgregoriobf5e5232014-07-17 13:14:16 -0700684 bench->preDraw();
685 }
mtkleinbb6a0282014-07-01 08:43:42 -0700686 for (int j = 0; j < targets.count(); j++) {
687 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->getCanvas() : NULL;
bsalomonc2553372014-07-22 13:09:05 -0700688 const char* config = targets[j]->config.name;
mtkleinf3723212014-06-25 14:08:00 -0700689
robertphillips5b693772014-11-21 06:19:36 -0800690#if SK_SUPPORT_GPU
691 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
692 setup_gl(targets[j]->gl);
693 }
694#endif
695
696 bench->perCanvasPreDraw(canvas);
697
mtkleinbb6a0282014-07-01 08:43:42 -0700698 const int loops =
699#if SK_SUPPORT_GPU
bsalomonc2553372014-07-22 13:09:05 -0700700 Benchmark::kGPU_Backend == targets[j]->config.backend
mtkleinbb6a0282014-07-01 08:43:42 -0700701 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
702 :
703#endif
704 cpu_bench( overhead, bench.get(), canvas, samples.get());
mtkleinf3723212014-06-25 14:08:00 -0700705
robertphillips5b693772014-11-21 06:19:36 -0800706 bench->perCanvasPostDraw(canvas);
707
bsalomon49f085d2014-09-05 13:34:00 -0700708 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700709 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -0700710 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -0700711 pngFilename.append(".png");
712 write_canvas_png(canvas, pngFilename);
713 }
714
715 if (kFailedLoops == loops) {
mtklein2069e222014-08-04 13:57:39 -0700716 // Can't be timed. A warning note has already been printed.
Mike Kleine3631362014-07-15 17:56:37 -0400717 continue;
718 }
719
mtkleinf3723212014-06-25 14:08:00 -0700720 Stats stats(samples.get(), FLAGS_samples);
mtklein1915b622014-08-20 11:45:00 -0700721 log->config(config);
mtklein96289052014-09-10 12:05:59 -0700722 log->configOption("name", bench->getName());
mtklein1915b622014-08-20 11:45:00 -0700723 benchStream.fillCurrentOptions(log.get());
jcgregoriobf5e5232014-07-17 13:14:16 -0700724#if SK_SUPPORT_GPU
bsalomonc2553372014-07-22 13:09:05 -0700725 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
mtklein1915b622014-08-20 11:45:00 -0700726 fill_gpu_options(log.get(), targets[j]->gl);
jcgregoriobf5e5232014-07-17 13:14:16 -0700727 }
728#endif
mtklein051e56d2014-12-04 08:46:51 -0800729 log->metric("min_ms", stats.min);
mtkleine070c2b2014-10-14 08:40:43 -0700730 if (runs++ % FLAGS_flushEvery == 0) {
731 log->flush();
732 }
mtklein60317d0f2014-07-14 11:30:37 -0700733
bsalomon6eb03cc2014-08-07 14:28:50 -0700734 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -0700735 if (targets.count() == 1) {
736 config = ""; // Only print the config if we run the same bench on more than one.
737 }
mtklein53d25622014-09-18 07:39:42 -0700738 SkDebugf("%4dM\t%s\t%s\n"
739 , sk_tools::getMaxResidentSetSizeMB()
740 , bench->getUniqueName()
741 , config);
mtkleina189ccd2014-07-14 12:28:47 -0700742 } else if (FLAGS_verbose) {
mtkleinf3723212014-06-25 14:08:00 -0700743 for (int i = 0; i < FLAGS_samples; i++) {
mtklein55b0ffc2014-07-17 08:38:23 -0700744 SkDebugf("%s ", HUMANIZE(samples[i]));
mtkleinf3723212014-06-25 14:08:00 -0700745 }
mtklein96289052014-09-10 12:05:59 -0700746 SkDebugf("%s\n", bench->getUniqueName());
mtkleinf3723212014-06-25 14:08:00 -0700747 } else if (FLAGS_quiet) {
mtkleinbb6a0282014-07-01 08:43:42 -0700748 if (targets.count() == 1) {
mtkleinf3723212014-06-25 14:08:00 -0700749 config = ""; // Only print the config if we run the same bench on more than one.
750 }
mtklein96289052014-09-10 12:05:59 -0700751 SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getUniqueName(), config);
mtkleinf3723212014-06-25 14:08:00 -0700752 } else {
753 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
mtkleinafb43792014-08-19 15:55:55 -0700754 SkDebugf("%4dM\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n"
755 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -0700756 , loops
mtklein55b0ffc2014-07-17 08:38:23 -0700757 , HUMANIZE(stats.min)
758 , HUMANIZE(stats.median)
759 , HUMANIZE(stats.mean)
760 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -0700761 , stddev_percent
mtklein5d9d10e2014-07-11 11:57:07 -0700762 , stats.plot.c_str()
mtkleinf3723212014-06-25 14:08:00 -0700763 , config
mtklein96289052014-09-10 12:05:59 -0700764 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -0700765 );
766 }
bsalomon06cddec2014-10-24 10:40:50 -0700767#if SK_SUPPORT_GPU && GR_CACHE_STATS
768 if (FLAGS_veryVerbose &&
769 Benchmark::kGPU_Backend == targets[j]->config.backend) {
mtklein6838d852014-10-29 14:15:10 -0700770 gGrFactory->get(targets[j]->config.ctxType)->printCacheStats();
bsalomon06cddec2014-10-24 10:40:50 -0700771 }
772#endif
mtkleinf3723212014-06-25 14:08:00 -0700773 }
mtkleinbb6a0282014-07-01 08:43:42 -0700774 targets.deleteAll();
Mike Klein3944a1d2014-07-15 13:40:19 -0400775
bsalomon06cddec2014-10-24 10:40:50 -0700776#if SK_SUPPORT_GPU
bsalomon2354f842014-07-28 13:48:36 -0700777 if (FLAGS_abandonGpuContext) {
krajcevski69a55602014-08-13 10:46:31 -0700778 gGrFactory->abandonContexts();
bsalomon2354f842014-07-28 13:48:36 -0700779 }
780 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) {
krajcevski69a55602014-08-13 10:46:31 -0700781 gGrFactory->destroyContexts();
Mike Klein3944a1d2014-07-15 13:40:19 -0400782 }
bsalomon06cddec2014-10-24 10:40:50 -0700783#endif
mtkleinf3723212014-06-25 14:08:00 -0700784 }
785
mtkleine1091452014-12-04 10:47:02 -0800786 log->bench("memory_usage", 0,0);
787 log->config("meta");
788 log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
789
mtkleinf3723212014-06-25 14:08:00 -0700790 return 0;
791}
792
jcgregorio3b27ade2014-11-13 08:06:40 -0800793#if !defined SK_BUILD_FOR_IOS
794int main(int argc, char** argv) {
795 SkCommandLineFlags::Parse(argc, argv);
796 return nanobench_main();
797}
798#endif