blob: bd61d34bdc439b92f444010d2a843625c74325a6 [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
tomhudsond968a6f2015-03-26 11:28:06 -070010#include "nanobench.h"
11
msarett84451022016-02-11 06:45:51 -080012#include "AndroidCodecBench.h"
mtkleinf3723212014-06-25 14:08:00 -070013#include "Benchmark.h"
msarett7f691442015-09-22 11:56:16 -070014#include "BitmapRegionDecoderBench.h"
scroggo60869a42015-04-01 12:09:17 -070015#include "CodecBench.h"
msarett7f691442015-09-22 11:56:16 -070016#include "CodecBenchPriv.h"
Mike Klein88544fb2019-03-20 10:50:33 -050017#include "CommonFlags.h"
18#include "CommonFlagsConfig.h"
mtkleinf3723212014-06-25 14:08:00 -070019#include "CrashHandler.h"
Mike Kleineb678fc2019-03-20 12:01:47 -050020#include "EventTracingPriv.h"
mtkleine714e752014-07-31 12:13:48 -070021#include "GMBench.h"
mtkleinafb43792014-08-19 15:55:55 -070022#include "ProcStats.h"
mtkleinfd731ce2014-09-10 12:19:30 -070023#include "RecordingBench.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040024#include "ResultsWriter.h"
joshualitt261c3ad2015-04-27 09:16:57 -070025#include "SKPAnimationBench.h"
mtklein92007582014-08-01 07:46:52 -070026#include "SKPBench.h"
msarett84451022016-02-11 06:45:51 -080027#include "SkAndroidCodec.h"
Hal Canary95e3c052017-01-11 12:44:43 -050028#include "SkAutoMalloc.h"
Kevin Lubickc456b732017-01-11 17:21:57 +000029#include "SkBBoxHierarchy.h"
Hal Canary95e3c052017-01-11 12:44:43 -050030#include "SkBitmapRegionDecoder.h"
mtkleinf3723212014-06-25 14:08:00 -070031#include "SkCanvas.h"
scroggo60869a42015-04-01 12:09:17 -070032#include "SkCodec.h"
Mike Klein0e4041f2018-06-19 16:00:40 -040033#include "SkColorSpacePriv.h"
msarett95f192d2015-02-13 09:05:41 -080034#include "SkData.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040035#include "SkDebugfTracer.h"
mtkleinf3723212014-06-25 14:08:00 -070036#include "SkGraphics.h"
Brian Osman8c0a1ca2019-01-28 14:24:29 -050037#include "SkJSONWriter.h"
halcanary4dbbd042016-06-07 17:21:10 -070038#include "SkLeanWindows.h"
mtklein20840502014-08-21 15:51:22 -070039#include "SkOSFile.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050040#include "SkOSPath.h"
mtklein20840502014-08-21 15:51:22 -070041#include "SkPictureRecorder.h"
mtkleinf3723212014-06-25 14:08:00 -070042#include "SkString.h"
43#include "SkSurface.h"
robertphillips5b693772014-11-21 06:19:36 -080044#include "SkTaskGroup.h"
Brian Osmanc3cdef52017-08-31 14:09:22 -040045#include "SkTraceEvent.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040046#include "Stats.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040047#include "ios_utils.h"
mtkleinf3723212014-06-25 14:08:00 -070048
Hal Canary0f666812018-03-22 15:21:12 -040049#ifdef SK_XML
50#include "SkSVGDOM.h"
51#endif // SK_XML
52
bungeman60e0fee2015-08-26 05:15:46 -070053#include <stdlib.h>
Mike Klein03141d22017-10-30 11:57:15 -040054#include <thread>
bungeman60e0fee2015-08-26 05:15:46 -070055
Mike Reedc928fe22017-06-05 10:20:31 -040056extern bool gSkForceRasterPipelineBlitter;
57
Mike Klein8f11d4d2018-01-24 12:42:55 -050058#ifndef SK_BUILD_FOR_WIN
scroggo38ce0a72016-01-07 07:28:47 -080059 #include <unistd.h>
Brian Salomon032aaae2018-03-23 16:10:36 -040060
scroggo38ce0a72016-01-07 07:28:47 -080061#endif
62
Brian Osmanc7ad40f2018-05-31 14:27:17 -040063#include "GrCaps.h"
64#include "GrContextFactory.h"
65#include "GrContextPriv.h"
66#include "SkGr.h"
67#include "gl/GrGLDefines.h"
68#include "gl/GrGLGpu.h"
69#include "gl/GrGLUtil.h"
Brian Salomon032aaae2018-03-23 16:10:36 -040070
Brian Osmanc7ad40f2018-05-31 14:27:17 -040071using sk_gpu_test::ContextInfo;
72using sk_gpu_test::GrContextFactory;
73using sk_gpu_test::TestContext;
Brian Salomon032aaae2018-03-23 16:10:36 -040074
Brian Osmanc7ad40f2018-05-31 14:27:17 -040075GrContextOptions grContextOpts;
bsalomon682c2692015-05-22 14:01:46 -070076
reed53249782014-10-10 09:09:52 -070077static const int kAutoTuneLoops = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -070078
Mike Kleind8ee67c2017-01-19 12:14:50 -050079#if !defined(__has_feature)
80 #define __has_feature(x) 0
81#endif
82
mtkleinb5110422014-08-07 15:20:02 -070083static const int kDefaultLoops =
Mike Klein7a002c32018-03-30 16:22:13 +000084#if defined(SK_DEBUG) || __has_feature(address_sanitizer)
bsalomon6eb03cc2014-08-07 14:28:50 -070085 1;
mtkleina189ccd2014-07-14 12:28:47 -070086#else
bsalomon6eb03cc2014-08-07 14:28:50 -070087 kAutoTuneLoops;
mtkleina189ccd2014-07-14 12:28:47 -070088#endif
89
bsalomon6eb03cc2014-08-07 14:28:50 -070090static SkString loops_help_txt() {
91 SkString help;
92 help.printf("Number of times to run each bench. Set this to %d to auto-"
93 "tune for each bench. Timings are only reported when auto-tuning.",
94 kAutoTuneLoops);
95 return help;
96}
97
cdaltone1b89582015-06-25 19:17:08 -070098static SkString to_string(int n) {
99 SkString str;
100 str.appendS32(n);
101 return str;
102}
103
Mike Klein5b3f3432019-03-21 11:42:21 -0500104static DEFINE_int(loops, kDefaultLoops, loops_help_txt().c_str());
bsalomon6eb03cc2014-08-07 14:28:50 -0700105
Mike Klein5b3f3432019-03-21 11:42:21 -0500106static DEFINE_int(samples, 10, "Number of samples to measure for each bench.");
107static DEFINE_int(ms, 0, "If >0, run each bench for this many ms instead of obeying --samples.");
108static DEFINE_int(overheadLoops, 100000, "Loops to estimate timer overhead.");
Mike Klein84836b72019-03-21 11:31:36 -0500109static DEFINE_double(overheadGoal, 0.0001,
mtkleinf3723212014-06-25 14:08:00 -0700110 "Loop until timer overhead is at most this fraction of our measurments.");
Mike Klein84836b72019-03-21 11:31:36 -0500111static DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500112static DEFINE_int(gpuFrameLag, 5,
Mike Klein84836b72019-03-21 11:31:36 -0500113 "If unknown, estimated maximum number of frames GPU allows to lag.");
mtkleinf3723212014-06-25 14:08:00 -0700114
Mike Klein84836b72019-03-21 11:31:36 -0500115static DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500116static DEFINE_int(maxCalibrationAttempts, 3,
mtklein55b0ffc2014-07-17 08:38:23 -0700117 "Try up to this many times to guess loops for a bench, or skip the bench.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500118static DEFINE_int(maxLoops, 1000000, "Never run a bench more times than this.");
Mike Klein84836b72019-03-21 11:31:36 -0500119static DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
120static DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
121static DEFINE_string(zoom, "1.0,0",
122 "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom "
123 "function that ping-pongs between 1.0 and zoomMax.");
124static DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
125static DEFINE_bool(lite, false, "Use SkLiteRecorder in recording benchmarks?");
126static DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
127static DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?");
Mike Klein5b3f3432019-03-21 11:42:21 -0500128static DEFINE_int(flushEvery, 10, "Flush --outResultsFile every Nth run.");
Mike Klein84836b72019-03-21 11:31:36 -0500129static DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
130static DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json");
131static DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out");
132static DEFINE_bool(csv, false, "Print status in CSV format");
133static DEFINE_string(sourceType, "",
mtklein65dfd2f2016-02-03 10:40:54 -0800134 "Apply usual --match rules to source type: bench, gm, skp, image, etc.");
Mike Klein84836b72019-03-21 11:31:36 -0500135static DEFINE_string(benchType, "",
136 "Apply usual --match rules to bench type: micro, recording, "
137 "piping, playback, skcodec, etc.");
mtklein65dfd2f2016-02-03 10:40:54 -0800138
Mike Klein84836b72019-03-21 11:31:36 -0500139static DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
Mike Reedc928fe22017-06-05 10:20:31 -0400140
Mike Klein19fb3972019-03-21 13:08:08 -0500141static DEFINE_bool2(pre_log, p, false,
142 "Log before running each test. May be incomprehensible when threading");
143
Mike Klein629f5fc2019-03-22 14:55:19 -0500144static DEFINE_bool(cpu, true, "master switch for running CPU-bound work.");
145static DEFINE_bool(gpu, true, "master switch for running GPU-bound work.");
146static DEFINE_bool(dryRun, false,
147 "just print the tests that would be run, without actually running them.");
148static DEFINE_string(images, "",
149 "List of images and/or directories to decode. A directory with no images"
150 " is treated as a fatal error.");
151static DEFINE_bool(simpleCodec, false,
152 "Runs of a subset of the codec tests, always N32, Premul or Opaque");
153
Mike Kleinc6142d82019-03-25 10:54:59 -0500154static DEFINE_string2(match, m, nullptr,
155 "[~][^]substring[$] [...] of name to run.\n"
156 "Multiple matches may be separated by spaces.\n"
157 "~ causes a matching name to always be skipped\n"
158 "^ requires the start of the name to match\n"
159 "$ requires the end of the name to match\n"
160 "^ and $ requires an exact match\n"
161 "If a name does not match any list entry,\n"
162 "it is skipped unless some list entry starts with ~");
163
164static DEFINE_bool2(quiet, q, false, "if true, don't print status updates.");
165static DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
166
167
168static DEFINE_string(skps, "skps", "Directory to read skps from.");
169static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file.");
170
171static DEFINE_int_2(threads, j, -1,
172 "Run threadsafe tests on a threadpool with this many extra threads, "
173 "defaulting to one extra thread per core.");
174
175static DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs.");
176
177static DEFINE_string(key, "",
178 "Space-separated key/value pairs to add to JSON identifying this builder.");
179static DEFINE_string(properties, "",
180 "Space-separated key/value pairs to add to JSON identifying this run.");
181
Mike Kleinee254232019-03-28 08:32:14 -0500182static DEFINE_bool(purgeBetweenBenches, false,
183 "Call SkGraphics::PurgeAllCaches() between each benchmark?");
184
mtkleinbbba1682015-10-28 11:36:30 -0700185static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
186
mtkleinf3723212014-06-25 14:08:00 -0700187static SkString humanize(double ms) {
mtkleindc5bbab2014-09-24 06:34:09 -0700188 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
mtklein748ca3b2015-01-15 10:56:12 -0800189 return HumanizeMs(ms);
mtkleinf3723212014-06-25 14:08:00 -0700190}
mtklein55b0ffc2014-07-17 08:38:23 -0700191#define HUMANIZE(ms) humanize(ms).c_str()
mtkleinf3723212014-06-25 14:08:00 -0700192
tomhudsond968a6f2015-03-26 11:28:06 -0700193bool Target::init(SkImageInfo info, Benchmark* bench) {
194 if (Benchmark::kRaster_Backend == config.backend) {
reede8f30622016-03-23 18:59:25 -0700195 this->surface = SkSurface::MakeRaster(info);
196 if (!this->surface) {
tomhudsond968a6f2015-03-26 11:28:06 -0700197 return false;
198 }
199 }
200 return true;
201}
202bool Target::capturePixels(SkBitmap* bmp) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700203 SkCanvas* canvas = this->getCanvas();
tomhudsond968a6f2015-03-26 11:28:06 -0700204 if (!canvas) {
205 return false;
206 }
Mike Reed12e946b2017-04-17 10:53:29 -0400207 bmp->allocPixels(canvas->imageInfo());
208 if (!canvas->readPixels(*bmp, 0, 0)) {
tomhudsond968a6f2015-03-26 11:28:06 -0700209 SkDebugf("Can't read canvas pixels.\n");
210 return false;
211 }
212 return true;
213}
214
tomhudsond968a6f2015-03-26 11:28:06 -0700215struct GPUTarget : public Target {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400216 explicit GPUTarget(const Config& c) : Target(c) {}
217 ContextInfo contextInfo;
218 std::unique_ptr<GrContextFactory> factory;
tomhudsond968a6f2015-03-26 11:28:06 -0700219
220 void setup() override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400221 this->contextInfo.testContext()->makeCurrent();
tomhudsond968a6f2015-03-26 11:28:06 -0700222 // Make sure we're done with whatever came before.
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400223 this->contextInfo.testContext()->finish();
tomhudsond968a6f2015-03-26 11:28:06 -0700224 }
225 void endTiming() override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400226 if (this->contextInfo.testContext()) {
227 this->contextInfo.testContext()->waitOnSyncOrSwap();
tomhudsond968a6f2015-03-26 11:28:06 -0700228 }
229 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400230 void fence() override { this->contextInfo.testContext()->finish(); }
mtkleind75c4662015-04-30 07:11:22 -0700231
cdaltond416a5b2015-06-23 13:23:44 -0700232 bool needsFrameTiming(int* maxFrameLag) const override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400233 if (!this->contextInfo.testContext()->getMaxGpuFrameLag(maxFrameLag)) {
cdaltond416a5b2015-06-23 13:23:44 -0700234 // Frame lag is unknown.
235 *maxFrameLag = FLAGS_gpuFrameLag;
236 }
237 return true;
238 }
tomhudsond968a6f2015-03-26 11:28:06 -0700239 bool init(SkImageInfo info, Benchmark* bench) override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400240 GrContextOptions options = grContextOpts;
241 bench->modifyGrContextOptions(&options);
242 this->factory.reset(new GrContextFactory(options));
bsalomonafcd7cd2015-08-31 12:39:41 -0700243 uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag :
244 0;
tomhudsond968a6f2015-03-26 11:28:06 -0700245 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400246 this->surface = SkSurface::MakeRenderTarget(
247 this->factory->get(this->config.ctxType, this->config.ctxOverrides),
248 SkBudgeted::kNo, info, this->config.samples, &props);
249 this->contextInfo =
250 this->factory->getContextInfo(this->config.ctxType, this->config.ctxOverrides);
tomhudsond968a6f2015-03-26 11:28:06 -0700251 if (!this->surface.get()) {
252 return false;
253 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400254 if (!this->contextInfo.testContext()->fenceSyncSupport()) {
cdaltond416a5b2015-06-23 13:23:44 -0700255 SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. "
svaisanenc47635e2016-01-28 06:05:43 -0800256 "Timings might not be accurate.\n", this->config.name.c_str());
cdaltond416a5b2015-06-23 13:23:44 -0700257 }
tomhudsond968a6f2015-03-26 11:28:06 -0700258 return true;
259 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500260 void fillOptions(NanoJSONResultsWriter& log) override {
tomhudsond968a6f2015-03-26 11:28:06 -0700261 const GrGLubyte* version;
Greg Danielbdf12ad2018-10-12 09:31:11 -0400262 if (this->contextInfo.backend() == GrBackendApi::kOpenGL) {
Brian Salomon032aaae2018-03-23 16:10:36 -0400263 const GrGLInterface* gl =
Robert Phillips9da87e02019-02-04 13:26:26 -0500264 static_cast<GrGLGpu*>(this->contextInfo.grContext()->priv().getGpu())
Brian Salomon032aaae2018-03-23 16:10:36 -0400265 ->glInterface();
bsalomonc8699322016-05-11 11:55:36 -0700266 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VERSION));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500267 log.appendString("GL_VERSION", (const char*)(version));
tomhudsond968a6f2015-03-26 11:28:06 -0700268
bsalomonc8699322016-05-11 11:55:36 -0700269 GR_GL_CALL_RET(gl, version, GetString(GR_GL_RENDERER));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500270 log.appendString("GL_RENDERER", (const char*) version);
tomhudsond968a6f2015-03-26 11:28:06 -0700271
bsalomonc8699322016-05-11 11:55:36 -0700272 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VENDOR));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500273 log.appendString("GL_VENDOR", (const char*) version);
tomhudsond968a6f2015-03-26 11:28:06 -0700274
bsalomonc8699322016-05-11 11:55:36 -0700275 GR_GL_CALL_RET(gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500276 log.appendString("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
bsalomonc8699322016-05-11 11:55:36 -0700277 }
tomhudsond968a6f2015-03-26 11:28:06 -0700278 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400279
280 void dumpStats() override {
Robert Phillips9da87e02019-02-04 13:26:26 -0500281 this->contextInfo.grContext()->priv().printCacheStats();
282 this->contextInfo.grContext()->priv().printGpuStats();
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400283 }
tomhudsond968a6f2015-03-26 11:28:06 -0700284};
mtkleind75c4662015-04-30 07:11:22 -0700285
tomhudson75a0ebb2015-03-27 12:11:44 -0700286static double time(int loops, Benchmark* bench, Target* target) {
287 SkCanvas* canvas = target->getCanvas();
bsalomon6eb03cc2014-08-07 14:28:50 -0700288 if (canvas) {
289 canvas->clear(SK_ColorWHITE);
290 }
joshualitt8a6697a2015-09-30 12:11:07 -0700291 bench->preDraw(canvas);
mtkleinbbba1682015-10-28 11:36:30 -0700292 double start = now_ms();
tomhudson75a0ebb2015-03-27 12:11:44 -0700293 canvas = target->beginTiming(canvas);
294 bench->draw(loops, canvas);
mtkleinbb6a0282014-07-01 08:43:42 -0700295 if (canvas) {
296 canvas->flush();
297 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700298 target->endTiming();
mtkleinbbba1682015-10-28 11:36:30 -0700299 double elapsed = now_ms() - start;
joshualitt8a6697a2015-09-30 12:11:07 -0700300 bench->postDraw(canvas);
mtkleinbbba1682015-10-28 11:36:30 -0700301 return elapsed;
mtkleinbb6a0282014-07-01 08:43:42 -0700302}
303
mtkleinf3723212014-06-25 14:08:00 -0700304static double estimate_timer_overhead() {
305 double overhead = 0;
mtkleinf3723212014-06-25 14:08:00 -0700306 for (int i = 0; i < FLAGS_overheadLoops; i++) {
mtkleinbbba1682015-10-28 11:36:30 -0700307 double start = now_ms();
308 overhead += now_ms() - start;
mtkleinf3723212014-06-25 14:08:00 -0700309 }
310 return overhead / FLAGS_overheadLoops;
311}
312
reed53249782014-10-10 09:09:52 -0700313static int detect_forever_loops(int loops) {
314 // look for a magic run-forever value
315 if (loops < 0) {
316 loops = SK_MaxS32;
317 }
318 return loops;
319}
320
mtklein55b0ffc2014-07-17 08:38:23 -0700321static int clamp_loops(int loops) {
322 if (loops < 1) {
mtklein527930f2014-11-06 08:04:34 -0800323 SkDebugf("ERROR: clamping loops from %d to 1. "
324 "There's probably something wrong with the bench.\n", loops);
mtklein55b0ffc2014-07-17 08:38:23 -0700325 return 1;
326 }
327 if (loops > FLAGS_maxLoops) {
328 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
329 return FLAGS_maxLoops;
330 }
331 return loops;
332}
333
tomhudsond968a6f2015-03-26 11:28:06 -0700334static bool write_canvas_png(Target* target, const SkString& filename) {
335
bsalomon6eb03cc2014-08-07 14:28:50 -0700336 if (filename.isEmpty()) {
337 return false;
338 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700339 if (target->getCanvas() &&
340 kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700341 return false;
342 }
tomhudsond968a6f2015-03-26 11:28:06 -0700343
bsalomon6eb03cc2014-08-07 14:28:50 -0700344 SkBitmap bmp;
tomhudsond968a6f2015-03-26 11:28:06 -0700345
346 if (!target->capturePixels(&bmp)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700347 return false;
348 }
tomhudsond968a6f2015-03-26 11:28:06 -0700349
bsalomon6eb03cc2014-08-07 14:28:50 -0700350 SkString dir = SkOSPath::Dirname(filename.c_str());
351 if (!sk_mkdir(dir.c_str())) {
352 SkDebugf("Can't make dir %s.\n", dir.c_str());
353 return false;
354 }
355 SkFILEWStream stream(filename.c_str());
356 if (!stream.isValid()) {
357 SkDebugf("Can't write %s.\n", filename.c_str());
358 return false;
359 }
Hal Canarydb683012016-11-23 08:55:18 -0700360 if (!SkEncodeImage(&stream, bmp, SkEncodedImageFormat::kPNG, 100)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700361 SkDebugf("Can't encode a PNG.\n");
362 return false;
363 }
364 return true;
365}
366
367static int kFailedLoops = -2;
cdaltone1b89582015-06-25 19:17:08 -0700368static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) {
mtkleinbb6a0282014-07-01 08:43:42 -0700369 // First figure out approximately how many loops of bench it takes to make overhead negligible.
mtklein2069e222014-08-04 13:57:39 -0700370 double bench_plus_overhead = 0.0;
mtklein55b0ffc2014-07-17 08:38:23 -0700371 int round = 0;
cdaltonb4022962015-06-25 10:51:56 -0700372 int loops = bench->calculateLoops(FLAGS_loops);
373 if (kAutoTuneLoops == loops) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700374 while (bench_plus_overhead < overhead) {
375 if (round++ == FLAGS_maxCalibrationAttempts) {
376 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
mtklein96289052014-09-10 12:05:59 -0700377 bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
bsalomon6eb03cc2014-08-07 14:28:50 -0700378 return kFailedLoops;
379 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700380 bench_plus_overhead = time(1, bench, target);
mtklein55b0ffc2014-07-17 08:38:23 -0700381 }
mtklein2069e222014-08-04 13:57:39 -0700382 }
mtkleinf3723212014-06-25 14:08:00 -0700383
mtkleinbb6a0282014-07-01 08:43:42 -0700384 // Later we'll just start and stop the timer once but loop N times.
mtkleinf3723212014-06-25 14:08:00 -0700385 // We'll pick N to make timer overhead negligible:
386 //
mtkleinbb6a0282014-07-01 08:43:42 -0700387 // overhead
388 // ------------------------- < FLAGS_overheadGoal
389 // overhead + N * Bench Time
mtkleinf3723212014-06-25 14:08:00 -0700390 //
Hal Canary55325b72017-01-03 10:36:17 -0500391 // where bench_plus_overhead ~=~ overhead + Bench Time.
mtkleinf3723212014-06-25 14:08:00 -0700392 //
393 // Doing some math, we get:
394 //
mtkleinbb6a0282014-07-01 08:43:42 -0700395 // (overhead / FLAGS_overheadGoal) - overhead
396 // ------------------------------------------ < N
397 // bench_plus_overhead - overhead)
mtkleinf3723212014-06-25 14:08:00 -0700398 //
399 // Luckily, this also works well in practice. :)
bsalomon6eb03cc2014-08-07 14:28:50 -0700400 if (kAutoTuneLoops == loops) {
401 const double numer = overhead / FLAGS_overheadGoal - overhead;
402 const double denom = bench_plus_overhead - overhead;
403 loops = (int)ceil(numer / denom);
reed53249782014-10-10 09:09:52 -0700404 loops = clamp_loops(loops);
405 } else {
406 loops = detect_forever_loops(loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700407 }
mtkleinbb6a0282014-07-01 08:43:42 -0700408
mtkleinbb6a0282014-07-01 08:43:42 -0700409 return loops;
mtkleinf3723212014-06-25 14:08:00 -0700410}
411
cdaltone1b89582015-06-25 19:17:08 -0700412static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) {
mtkleinbb6a0282014-07-01 08:43:42 -0700413 // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
cdaltonb4022962015-06-25 10:51:56 -0700414 int loops = bench->calculateLoops(FLAGS_loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700415 if (kAutoTuneLoops == loops) {
416 loops = 1;
mtkleina189ccd2014-07-14 12:28:47 -0700417 double elapsed = 0;
418 do {
mtklein527930f2014-11-06 08:04:34 -0800419 if (1<<30 == loops) {
420 // We're about to wrap. Something's wrong with the bench.
421 loops = 0;
422 break;
423 }
mtkleina189ccd2014-07-14 12:28:47 -0700424 loops *= 2;
425 // If the GPU lets frames lag at all, we need to make sure we're timing
cdaltond416a5b2015-06-23 13:23:44 -0700426 // _this_ round, not still timing last round.
427 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700428 elapsed = time(loops, bench, target);
mtkleina189ccd2014-07-14 12:28:47 -0700429 }
430 } while (elapsed < FLAGS_gpuMs);
mtkleinbb6a0282014-07-01 08:43:42 -0700431
mtkleina189ccd2014-07-14 12:28:47 -0700432 // We've overshot at least a little. Scale back linearly.
433 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
reed53249782014-10-10 09:09:52 -0700434 loops = clamp_loops(loops);
mtkleinbb6a0282014-07-01 08:43:42 -0700435
tomhudsond968a6f2015-03-26 11:28:06 -0700436 // Make sure we're not still timing our calibration.
437 target->fence();
reed53249782014-10-10 09:09:52 -0700438 } else {
439 loops = detect_forever_loops(loops);
mtkleina189ccd2014-07-14 12:28:47 -0700440 }
mtkleinbb6a0282014-07-01 08:43:42 -0700441 // Pretty much the same deal as the calibration: do some warmup to make
442 // sure we're timing steady-state pipelined frames.
Brian Osman01776982017-10-10 15:41:03 -0400443 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700444 time(loops, bench, target);
mtkleinf3723212014-06-25 14:08:00 -0700445 }
mtkleinbb6a0282014-07-01 08:43:42 -0700446
mtkleinbb6a0282014-07-01 08:43:42 -0700447 return loops;
448}
mtkleinbb6a0282014-07-01 08:43:42 -0700449
Brian Salomon6405e712017-03-20 08:54:16 -0400450#define kBogusContextType GrContextFactory::kGL_ContextType
csmartdaltone812d492017-02-21 12:36:05 -0700451#define kBogusContextOverrides GrContextFactory::ContextOverrides::kNone
bsalomonc2553372014-07-22 13:09:05 -0700452
svaisanenc47635e2016-01-28 06:05:43 -0800453static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) {
svaisanenc47635e2016-01-28 06:05:43 -0800454 if (const auto* gpuConfig = config->asConfigGpu()) {
Ben Wagner32fa5102017-08-10 21:25:55 -0400455 if (!FLAGS_gpu) {
456 SkDebugf("Skipping config '%s' as requested.\n", config->getTag().c_str());
svaisanenc47635e2016-01-28 06:05:43 -0800457 return;
Ben Wagner32fa5102017-08-10 21:25:55 -0400458 }
svaisanenc47635e2016-01-28 06:05:43 -0800459
svaisanenc47635e2016-01-28 06:05:43 -0800460 const auto ctxType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700461 const auto ctxOverrides = gpuConfig->getContextOverrides();
svaisanenc47635e2016-01-28 06:05:43 -0800462 const auto sampleCount = gpuConfig->getSamples();
Greg Daniel81e7bf82017-07-19 14:47:42 -0400463 const auto colorType = gpuConfig->getColorType();
464 auto colorSpace = gpuConfig->getColorSpace();
Brian Salomonf865b052018-03-09 09:01:53 -0500465 if (gpuConfig->getSurfType() != SkCommandLineConfigGpu::SurfType::kDefault) {
466 SkDebugf("This tool only supports the default surface type.");
467 return;
468 }
svaisanenc47635e2016-01-28 06:05:43 -0800469
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400470 GrContextFactory factory(grContextOpts);
471 if (const GrContext* ctx = factory.get(ctxType, ctxOverrides)) {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400472 GrPixelConfig grPixConfig = SkColorType2GrPixelConfig(colorType);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500473 int supportedSampleCount =
Robert Phillips9da87e02019-02-04 13:26:26 -0500474 ctx->priv().caps()->getRenderTargetSampleCount(sampleCount, grPixConfig);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400475 if (sampleCount != supportedSampleCount) {
Ben Wagner32fa5102017-08-10 21:25:55 -0400476 SkDebugf("Configuration '%s' sample count %d is not a supported sample count.\n",
477 config->getTag().c_str(), sampleCount);
svaisanenc47635e2016-01-28 06:05:43 -0800478 return;
479 }
480 } else {
Ben Wagner32fa5102017-08-10 21:25:55 -0400481 SkDebugf("No context was available matching config '%s'.\n",
482 config->getTag().c_str());
svaisanenc47635e2016-01-28 06:05:43 -0800483 return;
484 }
485
486 Config target = {
kkinnunend4e1c352016-03-01 23:41:26 -0800487 gpuConfig->getTag(),
svaisanenc47635e2016-01-28 06:05:43 -0800488 Benchmark::kGPU_Backend,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400489 colorType,
svaisanenc47635e2016-01-28 06:05:43 -0800490 kPremul_SkAlphaType,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400491 sk_ref_sp(colorSpace),
svaisanenc47635e2016-01-28 06:05:43 -0800492 sampleCount,
493 ctxType,
csmartdaltone812d492017-02-21 12:36:05 -0700494 ctxOverrides,
kkinnunend4e1c352016-03-01 23:41:26 -0800495 gpuConfig->getUseDIText()
496 };
svaisanenc47635e2016-01-28 06:05:43 -0800497
498 configs->push_back(target);
499 return;
500 }
svaisanenc47635e2016-01-28 06:05:43 -0800501
brianosmanb109b8c2016-06-16 13:03:24 -0700502 #define CPU_CONFIG(name, backend, color, alpha, colorSpace) \
503 if (config->getTag().equals(#name)) { \
Ben Wagner32fa5102017-08-10 21:25:55 -0400504 if (!FLAGS_cpu) { \
505 SkDebugf("Skipping config '%s' as requested.\n", \
506 config->getTag().c_str()); \
507 return; \
508 } \
brianosmanb109b8c2016-06-16 13:03:24 -0700509 Config config = { \
510 SkString(#name), Benchmark::backend, color, alpha, colorSpace, \
csmartdaltone812d492017-02-21 12:36:05 -0700511 0, kBogusContextType, kBogusContextOverrides, false \
brianosmanb109b8c2016-06-16 13:03:24 -0700512 }; \
513 configs->push_back(config); \
514 return; \
mtkleinbb6a0282014-07-01 08:43:42 -0700515 }
mtkleine714e752014-07-31 12:13:48 -0700516
Ben Wagner32fa5102017-08-10 21:25:55 -0400517 CPU_CONFIG(nonrendering, kNonRendering_Backend,
518 kUnknown_SkColorType, kUnpremul_SkAlphaType, nullptr)
mtkleinbb6c41b2016-03-08 11:31:11 -0800519
Mike Klein0e4041f2018-06-19 16:00:40 -0400520 CPU_CONFIG(a8, kRaster_Backend, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr)
521 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType, nullptr)
522 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType, nullptr)
523
524 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
Brian Osman82ebe042019-01-04 17:03:00 -0500525 auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50),
Mike Klein0e4041f2018-06-19 16:00:40 -0400526 srgb = SkColorSpace::MakeSRGB(),
527 srgbLinear = SkColorSpace::MakeSRGBLinear();
528
529 CPU_CONFIG( f16, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgbLinear)
530 CPU_CONFIG( srgb, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, srgb )
531 CPU_CONFIG( esrgb, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgb )
532 CPU_CONFIG( narrow, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, narrow )
533 CPU_CONFIG(enarrow, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, narrow )
mtkleinbb6a0282014-07-01 08:43:42 -0700534
svaisanenc47635e2016-01-28 06:05:43 -0800535 #undef CPU_CONFIG
Ben Wagner32fa5102017-08-10 21:25:55 -0400536
537 SkDebugf("Unknown config '%s'.\n", config->getTag().c_str());
mtkleinf3723212014-06-25 14:08:00 -0700538}
539
svaisanenc47635e2016-01-28 06:05:43 -0800540// Append all configs that are enabled and supported.
541void create_configs(SkTArray<Config>* configs) {
542 SkCommandLineConfigArray array;
543 ParseConfigs(FLAGS_config, &array);
544 for (int i = 0; i < array.count(); ++i) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400545 create_config(array[i].get(), configs);
svaisanenc47635e2016-01-28 06:05:43 -0800546 }
Ben Wagner32fa5102017-08-10 21:25:55 -0400547
548 // If no just default configs were requested, then we're okay.
549 if (array.count() == 0 || FLAGS_config.count() == 0 ||
Ben Wagner32fa5102017-08-10 21:25:55 -0400550 // Otherwise, make sure that all specified configs have been created.
551 array.count() == configs->count()) {
552 return;
553 }
Ben Wagner32fa5102017-08-10 21:25:55 -0400554 exit(1);
svaisanenc47635e2016-01-28 06:05:43 -0800555}
556
brianosman9f1f6e22016-09-15 08:33:02 -0700557// disable warning : switch statement contains default but no 'case' labels
558#if defined _WIN32
559#pragma warning ( push )
560#pragma warning ( disable : 4065 )
561#endif
562
halcanary96fcdcc2015-08-27 07:41:13 -0700563// If bench is enabled for config, returns a Target* for it, otherwise nullptr.
bsalomonc2553372014-07-22 13:09:05 -0700564static Target* is_enabled(Benchmark* bench, const Config& config) {
565 if (!bench->isSuitableFor(config.backend)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700566 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700567 }
568
reede5ea5002014-09-03 11:54:58 -0700569 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
brianosmanb109b8c2016-06-16 13:03:24 -0700570 config.color, config.alpha, config.colorSpace);
bsalomonc2553372014-07-22 13:09:05 -0700571
halcanary96fcdcc2015-08-27 07:41:13 -0700572 Target* target = nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700573
tomhudsond968a6f2015-03-26 11:28:06 -0700574 switch (config.backend) {
tomhudsond968a6f2015-03-26 11:28:06 -0700575 case Benchmark::kGPU_Backend:
576 target = new GPUTarget(config);
577 break;
tomhudsond968a6f2015-03-26 11:28:06 -0700578 default:
579 target = new Target(config);
580 break;
581 }
bsalomonc2553372014-07-22 13:09:05 -0700582
tomhudsond968a6f2015-03-26 11:28:06 -0700583 if (!target->init(info, bench)) {
bsalomonc2553372014-07-22 13:09:05 -0700584 delete target;
halcanary96fcdcc2015-08-27 07:41:13 -0700585 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700586 }
587 return target;
588}
589
brianosman9f1f6e22016-09-15 08:33:02 -0700590#if defined _WIN32
591#pragma warning ( pop )
592#endif
593
reed42943c82016-09-12 12:01:44 -0700594static bool valid_brd_bench(sk_sp<SkData> encoded, SkColorType colorType, uint32_t sampleSize,
msarettd1227a72016-05-18 06:23:57 -0700595 uint32_t minOutputSize, int* width, int* height) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400596 std::unique_ptr<SkBitmapRegionDecoder> brd(
msarettd1227a72016-05-18 06:23:57 -0700597 SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroidCodec_Strategy));
msarett7f691442015-09-22 11:56:16 -0700598 if (nullptr == brd.get()) {
599 // This is indicates that subset decoding is not supported for a particular image format.
600 return false;
601 }
602
msarett7f691442015-09-22 11:56:16 -0700603 if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize >
604 (uint32_t) brd->height()) {
605 // This indicates that the image is not large enough to decode a
606 // minOutputSize x minOutputSize subset at the given sampleSize.
607 return false;
608 }
609
610 // Set the image width and height. The calling code will use this to choose subsets to decode.
611 *width = brd->width();
612 *height = brd->height();
613 return true;
614}
615
egdaniel3bf92062015-06-26 08:12:46 -0700616static void cleanup_run(Target* target) {
halcanary385fe4d2015-08-26 13:07:48 -0700617 delete target;
egdaniel3bf92062015-06-26 08:12:46 -0700618}
619
Mike Klein88544fb2019-03-20 10:50:33 -0500620static void collect_files(const CommandLineFlags::StringArray& paths,
621 const char* ext,
622 SkTArray<SkString>* list) {
fmalita6519c212016-09-14 08:05:17 -0700623 for (int i = 0; i < paths.count(); ++i) {
624 if (SkStrEndsWith(paths[i], ext)) {
625 list->push_back(SkString(paths[i]));
626 } else {
627 SkOSFile::Iter it(paths[i], ext);
628 SkString path;
629 while (it.next(&path)) {
630 list->push_back(SkOSPath::Join(paths[i], path.c_str()));
631 }
632 }
633 }
634}
635
mtkleine714e752014-07-31 12:13:48 -0700636class BenchmarkStream {
637public:
mtklein92007582014-08-01 07:46:52 -0700638 BenchmarkStream() : fBenches(BenchRegistry::Head())
639 , fGMs(skiagm::GMRegistry::Head())
mtkleinfd731ce2014-09-10 12:19:30 -0700640 , fCurrentRecording(0)
Mike Reede45ff462017-12-06 10:47:03 -0500641 , fCurrentDeserialPicture(0)
mtklein92007582014-08-01 07:46:52 -0700642 , fCurrentScale(0)
robertphillips5b693772014-11-21 06:19:36 -0800643 , fCurrentSKP(0)
fmalita6519c212016-09-14 08:05:17 -0700644 , fCurrentSVG(0)
msarett95f192d2015-02-13 09:05:41 -0800645 , fCurrentUseMPD(0)
scroggo60869a42015-04-01 12:09:17 -0700646 , fCurrentCodec(0)
msarett84451022016-02-11 06:45:51 -0800647 , fCurrentAndroidCodec(0)
msarett7f691442015-09-22 11:56:16 -0700648 , fCurrentBRDImage(0)
msarett95f192d2015-02-13 09:05:41 -0800649 , fCurrentColorType(0)
msarettc7796b92016-01-07 14:20:20 -0800650 , fCurrentAlphaType(0)
msarettb23e6aa2015-06-09 13:56:10 -0700651 , fCurrentSubsetType(0)
msarett84451022016-02-11 06:45:51 -0800652 , fCurrentSampleSize(0)
msarettb23e6aa2015-06-09 13:56:10 -0700653 , fCurrentAnimSKP(0) {
fmalita6519c212016-09-14 08:05:17 -0700654 collect_files(FLAGS_skps, ".skp", &fSKPs);
655 collect_files(FLAGS_svgs, ".svg", &fSVGs);
mtkleine714e752014-07-31 12:13:48 -0700656
mtklein92007582014-08-01 07:46:52 -0700657 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
658 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
659 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
660 exit(1);
661 }
662
663 for (int i = 0; i < FLAGS_scales.count(); i++) {
664 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
665 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
666 exit(1);
667 }
668 }
robertphillips5b693772014-11-21 06:19:36 -0800669
cdalton63a82852015-06-29 14:06:10 -0700670 if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) {
671 SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]);
joshualitt261c3ad2015-04-27 09:16:57 -0700672 exit(1);
673 }
674
robertphillips5b693772014-11-21 06:19:36 -0800675 if (FLAGS_mpd) {
676 fUseMPDs.push_back() = true;
677 }
mtkleinc751ecb2015-06-15 08:56:38 -0700678 fUseMPDs.push_back() = false;
mtklein95553d92015-03-12 08:24:21 -0700679
msarett95f192d2015-02-13 09:05:41 -0800680 // Prepare the images for decoding
msarett69deca82016-04-29 09:38:40 -0700681 if (!CollectImages(FLAGS_images, &fImages)) {
scroggo86737142016-02-03 12:19:11 -0800682 exit(1);
msarett95f192d2015-02-13 09:05:41 -0800683 }
mtklein95553d92015-03-12 08:24:21 -0700684
msarett95f192d2015-02-13 09:05:41 -0800685 // Choose the candidate color types for image decoding
msarett67cb6662016-06-21 08:49:26 -0700686 fColorTypes.push_back(kN32_SkColorType);
687 if (!FLAGS_simpleCodec) {
688 fColorTypes.push_back(kRGB_565_SkColorType);
689 fColorTypes.push_back(kAlpha_8_SkColorType);
msarett67cb6662016-06-21 08:49:26 -0700690 fColorTypes.push_back(kGray_8_SkColorType);
691 }
mtklein92007582014-08-01 07:46:52 -0700692 }
693
reedca2622b2016-03-18 07:25:55 -0700694 static sk_sp<SkPicture> ReadPicture(const char* path) {
mtkleinfd731ce2014-09-10 12:19:30 -0700695 // Not strictly necessary, as it will be checked again later,
696 // but helps to avoid a lot of pointless work if we're going to skip it.
Mike Klein88544fb2019-03-20 10:50:33 -0500697 if (CommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) {
reedca2622b2016-03-18 07:25:55 -0700698 return nullptr;
mtkleinfd731ce2014-09-10 12:19:30 -0700699 }
700
bungemanf93d7112016-09-16 06:24:20 -0700701 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
702 if (!stream) {
mtkleinfd731ce2014-09-10 12:19:30 -0700703 SkDebugf("Could not read %s.\n", path);
reedca2622b2016-03-18 07:25:55 -0700704 return nullptr;
mtkleinfd731ce2014-09-10 12:19:30 -0700705 }
706
reedca2622b2016-03-18 07:25:55 -0700707 return SkPicture::MakeFromStream(stream.get());
mtkleinfd731ce2014-09-10 12:19:30 -0700708 }
709
fmalita6519c212016-09-14 08:05:17 -0700710 static sk_sp<SkPicture> ReadSVGPicture(const char* path) {
Brian Osman133823d2018-09-19 14:14:15 -0400711 sk_sp<SkData> data(SkData::MakeFromFileName(path));
712 if (!data) {
fmalita6519c212016-09-14 08:05:17 -0700713 SkDebugf("Could not read %s.\n", path);
714 return nullptr;
715 }
716
Hal Canary0f666812018-03-22 15:21:12 -0400717#ifdef SK_XML
Brian Osman133823d2018-09-19 14:14:15 -0400718 SkMemoryStream stream(std::move(data));
fmalitae1baa7c2016-09-14 12:04:30 -0700719 sk_sp<SkSVGDOM> svgDom = SkSVGDOM::MakeFromStream(stream);
fmalita6519c212016-09-14 08:05:17 -0700720 if (!svgDom) {
721 SkDebugf("Could not parse %s.\n", path);
722 return nullptr;
723 }
724
fmalitae1baa7c2016-09-14 12:04:30 -0700725 // Use the intrinsic SVG size if available, otherwise fall back to a default value.
726 static const SkSize kDefaultContainerSize = SkSize::Make(128, 128);
727 if (svgDom->containerSize().isEmpty()) {
728 svgDom->setContainerSize(kDefaultContainerSize);
729 }
730
fmalita6519c212016-09-14 08:05:17 -0700731 SkPictureRecorder recorder;
fmalitae1baa7c2016-09-14 12:04:30 -0700732 svgDom->render(recorder.beginRecording(svgDom->containerSize().width(),
733 svgDom->containerSize().height()));
fmalita6519c212016-09-14 08:05:17 -0700734 return recorder.finishRecordingAsPicture();
Hal Canary0f666812018-03-22 15:21:12 -0400735#else
736 return nullptr;
737#endif // SK_XML
fmalita6519c212016-09-14 08:05:17 -0700738 }
739
mtklein92007582014-08-01 07:46:52 -0700740 Benchmark* next() {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400741 std::unique_ptr<Benchmark> bench;
mtklein65dfd2f2016-02-03 10:40:54 -0800742 do {
743 bench.reset(this->rawNext());
744 if (!bench) {
745 return nullptr;
746 }
Mike Klein88544fb2019-03-20 10:50:33 -0500747 } while (CommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) ||
748 CommandLineFlags::ShouldSkip(FLAGS_benchType, fBenchType));
mtklein18300a32016-03-16 13:53:35 -0700749 return bench.release();
mtklein65dfd2f2016-02-03 10:40:54 -0800750 }
751
752 Benchmark* rawNext() {
mtkleine714e752014-07-31 12:13:48 -0700753 if (fBenches) {
Hal Canary972eba32018-07-30 17:07:07 -0400754 Benchmark* bench = fBenches->get()(nullptr);
mtkleine714e752014-07-31 12:13:48 -0700755 fBenches = fBenches->next();
mtklein92007582014-08-01 07:46:52 -0700756 fSourceType = "bench";
mtkleinfd731ce2014-09-10 12:19:30 -0700757 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700758 return bench;
759 }
mtklein92007582014-08-01 07:46:52 -0700760
mtkleine714e752014-07-31 12:13:48 -0700761 while (fGMs) {
Hal Canary972eba32018-07-30 17:07:07 -0400762 std::unique_ptr<skiagm::GM> gm(fGMs->get()(nullptr));
mtkleine714e752014-07-31 12:13:48 -0700763 fGMs = fGMs->next();
mtkleincf5d9c92015-01-23 10:31:45 -0800764 if (gm->runAsBench()) {
mtklein92007582014-08-01 07:46:52 -0700765 fSourceType = "gm";
mtkleinfd731ce2014-09-10 12:19:30 -0700766 fBenchType = "micro";
mtklein18300a32016-03-16 13:53:35 -0700767 return new GMBench(gm.release());
mtkleine714e752014-07-31 12:13:48 -0700768 }
769 }
mtklein92007582014-08-01 07:46:52 -0700770
mtkleinfd731ce2014-09-10 12:19:30 -0700771 // First add all .skps as RecordingBenches.
772 while (fCurrentRecording < fSKPs.count()) {
773 const SkString& path = fSKPs[fCurrentRecording++];
reedca2622b2016-03-18 07:25:55 -0700774 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
775 if (!pic) {
mtkleinfd731ce2014-09-10 12:19:30 -0700776 continue;
777 }
778 SkString name = SkOSPath::Basename(path.c_str());
779 fSourceType = "skp";
780 fBenchType = "recording";
Mike Klein88d90712018-01-27 17:30:04 +0000781 fSKPBytes = static_cast<double>(pic->approximateBytesUsed());
782 fSKPOps = pic->approximateOpCount();
mtklein8c1a4f82016-08-08 06:56:22 -0700783 return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh, FLAGS_lite);
mtkleinfd731ce2014-09-10 12:19:30 -0700784 }
785
Mike Reede45ff462017-12-06 10:47:03 -0500786 // Add all .skps as DeserializePictureBenchs.
787 while (fCurrentDeserialPicture < fSKPs.count()) {
788 const SkString& path = fSKPs[fCurrentDeserialPicture++];
789 sk_sp<SkData> data = SkData::MakeFromFileName(path.c_str());
790 if (!data) {
791 continue;
792 }
793 SkString name = SkOSPath::Basename(path.c_str());
794 fSourceType = "skp";
795 fBenchType = "deserial";
Mike Reed7557bbb2017-12-24 19:50:57 -0500796 fSKPBytes = static_cast<double>(data->size());
Mike Klein88d90712018-01-27 17:30:04 +0000797 fSKPOps = 0;
Mike Reede45ff462017-12-06 10:47:03 -0500798 return new DeserializePictureBench(name.c_str(), std::move(data));
799 }
800
mtkleinfd731ce2014-09-10 12:19:30 -0700801 // Then once each for each scale as SKPBenches (playback).
mtklein92007582014-08-01 07:46:52 -0700802 while (fCurrentScale < fScales.count()) {
803 while (fCurrentSKP < fSKPs.count()) {
robertphillips5b693772014-11-21 06:19:36 -0800804 const SkString& path = fSKPs[fCurrentSKP];
reedca2622b2016-03-18 07:25:55 -0700805 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
806 if (!pic) {
robertphillips5b693772014-11-21 06:19:36 -0800807 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700808 continue;
809 }
robertphillips5b693772014-11-21 06:19:36 -0800810
811 while (fCurrentUseMPD < fUseMPDs.count()) {
812 if (FLAGS_bbh) {
813 // The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
814 SkRTreeFactory factory;
815 SkPictureRecorder recorder;
robertphillips5b693772014-11-21 06:19:36 -0800816 pic->playback(recorder.beginRecording(pic->cullRect().width(),
817 pic->cullRect().height(),
mtklein748ca3b2015-01-15 10:56:12 -0800818 &factory,
robertphillipsdda54452016-07-13 13:27:16 -0700819 0));
reedca2622b2016-03-18 07:25:55 -0700820 pic = recorder.finishRecordingAsPicture();
robertphillips5b693772014-11-21 06:19:36 -0800821 }
822 SkString name = SkOSPath::Basename(path.c_str());
823 fSourceType = "skp";
824 fBenchType = "playback";
halcanary385fe4d2015-08-26 13:07:48 -0700825 return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale],
826 fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP);
mtklein20840502014-08-21 15:51:22 -0700827 }
robertphillips5b693772014-11-21 06:19:36 -0800828 fCurrentUseMPD = 0;
829 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700830 }
fmalita6519c212016-09-14 08:05:17 -0700831
832 while (fCurrentSVG++ < fSVGs.count()) {
833 const char* path = fSVGs[fCurrentSVG - 1].c_str();
834 if (sk_sp<SkPicture> pic = ReadSVGPicture(path)) {
835 fSourceType = "svg";
836 fBenchType = "playback";
837 return new SKPBench(SkOSPath::Basename(path).c_str(), pic.get(), fClip,
838 fScales[fCurrentScale], false, FLAGS_loopSKP);
839 }
840 }
841
mtklein92007582014-08-01 07:46:52 -0700842 fCurrentSKP = 0;
fmalita6519c212016-09-14 08:05:17 -0700843 fCurrentSVG = 0;
mtklein92007582014-08-01 07:46:52 -0700844 fCurrentScale++;
845 }
846
joshualitt261c3ad2015-04-27 09:16:57 -0700847 // Now loop over each skp again if we have an animation
cdalton63a82852015-06-29 14:06:10 -0700848 if (fZoomMax != 1.0f && fZoomPeriodMs > 0) {
joshualitt261c3ad2015-04-27 09:16:57 -0700849 while (fCurrentAnimSKP < fSKPs.count()) {
850 const SkString& path = fSKPs[fCurrentAnimSKP];
reedca2622b2016-03-18 07:25:55 -0700851 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
852 if (!pic) {
joshualitt261c3ad2015-04-27 09:16:57 -0700853 fCurrentAnimSKP++;
854 continue;
855 }
856
857 fCurrentAnimSKP++;
858 SkString name = SkOSPath::Basename(path.c_str());
Hal Canary2db83612016-11-04 13:02:54 -0400859 sk_sp<SKPAnimationBench::Animation> animation(
cdalton63a82852015-06-29 14:06:10 -0700860 SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriodMs));
Hal Canary2db83612016-11-04 13:02:54 -0400861 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, animation.get(),
halcanary385fe4d2015-08-26 13:07:48 -0700862 FLAGS_loopSKP);
joshualitt261c3ad2015-04-27 09:16:57 -0700863 }
864 }
865
scroggo60869a42015-04-01 12:09:17 -0700866 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) {
scroggo303fa352015-10-05 11:03:34 -0700867 fSourceType = "image";
868 fBenchType = "skcodec";
scroggo60869a42015-04-01 12:09:17 -0700869 const SkString& path = fImages[fCurrentCodec];
Mike Klein88544fb2019-03-20 10:50:33 -0500870 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
mtklein6f0ff912016-01-11 09:04:21 -0800871 continue;
872 }
bungeman38d909e2016-08-02 14:40:46 -0700873 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400874 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
scroggo60869a42015-04-01 12:09:17 -0700875 if (!codec) {
876 // Nothing to time.
msarett9d9725c2015-04-24 11:41:55 -0700877 SkDebugf("Cannot find codec for %s\n", path.c_str());
scroggo60869a42015-04-01 12:09:17 -0700878 continue;
879 }
scroggo21027992015-04-02 13:22:38 -0700880
scroggo60869a42015-04-01 12:09:17 -0700881 while (fCurrentColorType < fColorTypes.count()) {
scroggo21027992015-04-02 13:22:38 -0700882 const SkColorType colorType = fColorTypes[fCurrentColorType];
scroggo21027992015-04-02 13:22:38 -0700883
msarettc7796b92016-01-07 14:20:20 -0800884 SkAlphaType alphaType = codec->getInfo().alphaType();
msarett67cb6662016-06-21 08:49:26 -0700885 if (FLAGS_simpleCodec) {
886 if (kUnpremul_SkAlphaType == alphaType) {
887 alphaType = kPremul_SkAlphaType;
888 }
889
890 fCurrentColorType++;
891 } else {
892 switch (alphaType) {
893 case kOpaque_SkAlphaType:
894 // We only need to test one alpha type (opaque).
msarettc7796b92016-01-07 14:20:20 -0800895 fCurrentColorType++;
msarett67cb6662016-06-21 08:49:26 -0700896 break;
897 case kUnpremul_SkAlphaType:
898 case kPremul_SkAlphaType:
899 if (0 == fCurrentAlphaType) {
900 // Test unpremul first.
901 alphaType = kUnpremul_SkAlphaType;
902 fCurrentAlphaType++;
903 } else {
904 // Test premul.
905 alphaType = kPremul_SkAlphaType;
906 fCurrentAlphaType = 0;
907 fCurrentColorType++;
908 }
909 break;
910 default:
911 SkASSERT(false);
912 fCurrentColorType++;
913 break;
914 }
scroggo21027992015-04-02 13:22:38 -0700915 }
916
msarettc7796b92016-01-07 14:20:20 -0800917 // Make sure we can decode to this color type and alpha type.
918 SkImageInfo info =
919 codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType);
scroggo21027992015-04-02 13:22:38 -0700920 const size_t rowBytes = info.minRowBytes();
Mike Reedf0ffb892017-10-03 14:47:21 -0400921 SkAutoMalloc storage(info.computeByteSize(rowBytes));
scroggo21027992015-04-02 13:22:38 -0700922
scroggoeb602a52015-07-09 08:16:03 -0700923 const SkCodec::Result result = codec->getPixels(
Leon Scroggins571b30f2017-07-11 17:35:31 +0000924 info, storage.get(), rowBytes);
scroggo60869a42015-04-01 12:09:17 -0700925 switch (result) {
scroggoeb602a52015-07-09 08:16:03 -0700926 case SkCodec::kSuccess:
927 case SkCodec::kIncompleteInput:
scroggo60869a42015-04-01 12:09:17 -0700928 return new CodecBench(SkOSPath::Basename(path.c_str()),
bungeman38d909e2016-08-02 14:40:46 -0700929 encoded.get(), colorType, alphaType);
scroggoeb602a52015-07-09 08:16:03 -0700930 case SkCodec::kInvalidConversion:
scroggo60869a42015-04-01 12:09:17 -0700931 // This is okay. Not all conversions are valid.
932 break;
scroggo60869a42015-04-01 12:09:17 -0700933 default:
934 // This represents some sort of failure.
935 SkASSERT(false);
936 break;
937 }
938 }
939 fCurrentColorType = 0;
940 }
941
msarett84451022016-02-11 06:45:51 -0800942 // Run AndroidCodecBenches
943 const int sampleSizes[] = { 2, 4, 8 };
944 for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) {
945 fSourceType = "image";
946 fBenchType = "skandroidcodec";
947
948 const SkString& path = fImages[fCurrentAndroidCodec];
Mike Klein88544fb2019-03-20 10:50:33 -0500949 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
msarett84451022016-02-11 06:45:51 -0800950 continue;
951 }
bungeman38d909e2016-08-02 14:40:46 -0700952 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400953 std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
msarett84451022016-02-11 06:45:51 -0800954 if (!codec) {
955 // Nothing to time.
956 SkDebugf("Cannot find codec for %s\n", path.c_str());
957 continue;
958 }
959
960 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) {
961 int sampleSize = sampleSizes[fCurrentSampleSize];
962 fCurrentSampleSize++;
963 if (10 * sampleSize > SkTMin(codec->getInfo().width(), codec->getInfo().height())) {
964 // Avoid benchmarking scaled decodes of already small images.
965 break;
966 }
967
bungeman38d909e2016-08-02 14:40:46 -0700968 return new AndroidCodecBench(SkOSPath::Basename(path.c_str()),
969 encoded.get(), sampleSize);
msarett84451022016-02-11 06:45:51 -0800970 }
971 fCurrentSampleSize = 0;
972 }
973
msarett7f691442015-09-22 11:56:16 -0700974 // Run the BRDBenches
msarett7f691442015-09-22 11:56:16 -0700975 // We intend to create benchmarks that model the use cases in
976 // android/libraries/social/tiledimage. In this library, an image is decoded in 512x512
977 // tiles. The image can be translated freely, so the location of a tile may be anywhere in
978 // the image. For that reason, we will benchmark decodes in five representative locations
979 // in the image. Additionally, this use case utilizes power of two scaling, so we will
980 // test on power of two sample sizes. The output tile is always 512x512, so, when a
981 // sampleSize is used, the size of the subset that is decoded is always
982 // (sampleSize*512)x(sampleSize*512).
983 // There are a few good reasons to only test on power of two sample sizes at this time:
msarett7f691442015-09-22 11:56:16 -0700984 // All use cases we are aware of only scale by powers of two.
985 // PNG decodes use the indicated sampling strategy regardless of the sample size, so
986 // these tests are sufficient to provide good coverage of our scaling options.
msarett84451022016-02-11 06:45:51 -0800987 const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 };
msarett7f691442015-09-22 11:56:16 -0700988 const uint32_t minOutputSize = 512;
mtklein6f0ff912016-01-11 09:04:21 -0800989 for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) {
msarettd1227a72016-05-18 06:23:57 -0700990 fSourceType = "image";
991 fBenchType = "BRD";
992
mtklein6f0ff912016-01-11 09:04:21 -0800993 const SkString& path = fImages[fCurrentBRDImage];
Mike Klein88544fb2019-03-20 10:50:33 -0500994 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
mtklein6f0ff912016-01-11 09:04:21 -0800995 continue;
996 }
scroggo860e8a62015-10-15 07:51:28 -0700997
msarettd1227a72016-05-18 06:23:57 -0700998 while (fCurrentColorType < fColorTypes.count()) {
999 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) {
1000 while (fCurrentSubsetType <= kLastSingle_SubsetType) {
scroggo860e8a62015-10-15 07:51:28 -07001001
bungeman38d909e2016-08-02 14:40:46 -07001002 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarettd1227a72016-05-18 06:23:57 -07001003 const SkColorType colorType = fColorTypes[fCurrentColorType];
1004 uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize];
1005 int currentSubsetType = fCurrentSubsetType++;
scroggo860e8a62015-10-15 07:51:28 -07001006
msarettd1227a72016-05-18 06:23:57 -07001007 int width = 0;
1008 int height = 0;
reed42943c82016-09-12 12:01:44 -07001009 if (!valid_brd_bench(encoded, colorType, sampleSize, minOutputSize,
msarettd1227a72016-05-18 06:23:57 -07001010 &width, &height)) {
1011 break;
msarett7f691442015-09-22 11:56:16 -07001012 }
msarettd1227a72016-05-18 06:23:57 -07001013
1014 SkString basename = SkOSPath::Basename(path.c_str());
1015 SkIRect subset;
1016 const uint32_t subsetSize = sampleSize * minOutputSize;
1017 switch (currentSubsetType) {
1018 case kTopLeft_SubsetType:
1019 basename.append("_TopLeft");
1020 subset = SkIRect::MakeXYWH(0, 0, subsetSize, subsetSize);
1021 break;
1022 case kTopRight_SubsetType:
1023 basename.append("_TopRight");
1024 subset = SkIRect::MakeXYWH(width - subsetSize, 0, subsetSize,
1025 subsetSize);
1026 break;
1027 case kMiddle_SubsetType:
1028 basename.append("_Middle");
1029 subset = SkIRect::MakeXYWH((width - subsetSize) / 2,
1030 (height - subsetSize) / 2, subsetSize, subsetSize);
1031 break;
1032 case kBottomLeft_SubsetType:
1033 basename.append("_BottomLeft");
1034 subset = SkIRect::MakeXYWH(0, height - subsetSize, subsetSize,
1035 subsetSize);
1036 break;
1037 case kBottomRight_SubsetType:
1038 basename.append("_BottomRight");
1039 subset = SkIRect::MakeXYWH(width - subsetSize,
1040 height - subsetSize, subsetSize, subsetSize);
1041 break;
1042 default:
1043 SkASSERT(false);
1044 }
1045
1046 return new BitmapRegionDecoderBench(basename.c_str(), encoded.get(),
1047 colorType, sampleSize, subset);
msarett7f691442015-09-22 11:56:16 -07001048 }
msarettd1227a72016-05-18 06:23:57 -07001049 fCurrentSubsetType = 0;
1050 fCurrentSampleSize++;
msarett7f691442015-09-22 11:56:16 -07001051 }
msarettd1227a72016-05-18 06:23:57 -07001052 fCurrentSampleSize = 0;
1053 fCurrentColorType++;
msarett7f691442015-09-22 11:56:16 -07001054 }
msarettd1227a72016-05-18 06:23:57 -07001055 fCurrentColorType = 0;
msarett7f691442015-09-22 11:56:16 -07001056 }
1057
halcanary96fcdcc2015-08-27 07:41:13 -07001058 return nullptr;
mtkleine714e752014-07-31 12:13:48 -07001059 }
mtklein92007582014-08-01 07:46:52 -07001060
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001061 void fillCurrentOptions(NanoJSONResultsWriter& log) const {
1062 log.appendString("source_type", fSourceType);
1063 log.appendString("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -07001064 if (0 == strcmp(fSourceType, "skp")) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001065 log.appendString("clip",
mtklein92007582014-08-01 07:46:52 -07001066 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
1067 fClip.fRight, fClip.fBottom).c_str());
djsollenf2b340f2016-01-29 08:51:04 -08001068 SkASSERT_RELEASE(fCurrentScale < fScales.count()); // debugging paranoia
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001069 log.appendString("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
robertphillips5b693772014-11-21 06:19:36 -08001070 if (fCurrentUseMPD > 0) {
1071 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001072 log.appendString("multi_picture_draw",
1073 fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
robertphillips5b693772014-11-21 06:19:36 -08001074 }
mtklein92007582014-08-01 07:46:52 -07001075 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001076 }
1077
1078 void fillCurrentMetrics(NanoJSONResultsWriter& log) const {
mtklein051e56d2014-12-04 08:46:51 -08001079 if (0 == strcmp(fBenchType, "recording")) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001080 log.appendMetric("bytes", fSKPBytes);
1081 log.appendMetric("ops", fSKPOps);
mtklein051e56d2014-12-04 08:46:51 -08001082 }
mtklein92007582014-08-01 07:46:52 -07001083 }
1084
mtkleine714e752014-07-31 12:13:48 -07001085private:
msarettb23e6aa2015-06-09 13:56:10 -07001086 enum SubsetType {
1087 kTopLeft_SubsetType = 0,
1088 kTopRight_SubsetType = 1,
msarettab80e352015-06-17 10:28:22 -07001089 kMiddle_SubsetType = 2,
1090 kBottomLeft_SubsetType = 3,
1091 kBottomRight_SubsetType = 4,
1092 kTranslate_SubsetType = 5,
1093 kZoom_SubsetType = 6,
msarett7f691442015-09-22 11:56:16 -07001094 kLast_SubsetType = kZoom_SubsetType,
1095 kLastSingle_SubsetType = kBottomRight_SubsetType,
msarettb23e6aa2015-06-09 13:56:10 -07001096 };
1097
mtkleine714e752014-07-31 12:13:48 -07001098 const BenchRegistry* fBenches;
1099 const skiagm::GMRegistry* fGMs;
mtklein92007582014-08-01 07:46:52 -07001100 SkIRect fClip;
1101 SkTArray<SkScalar> fScales;
1102 SkTArray<SkString> fSKPs;
fmalita6519c212016-09-14 08:05:17 -07001103 SkTArray<SkString> fSVGs;
robertphillips5b693772014-11-21 06:19:36 -08001104 SkTArray<bool> fUseMPDs;
msarett95f192d2015-02-13 09:05:41 -08001105 SkTArray<SkString> fImages;
msarett74deb982015-10-20 16:45:56 -07001106 SkTArray<SkColorType, true> fColorTypes;
cdalton63a82852015-06-29 14:06:10 -07001107 SkScalar fZoomMax;
1108 double fZoomPeriodMs;
mtklein92007582014-08-01 07:46:52 -07001109
Mike Klein88d90712018-01-27 17:30:04 +00001110 double fSKPBytes, fSKPOps;
mtklein051e56d2014-12-04 08:46:51 -08001111
mtkleinfd731ce2014-09-10 12:19:30 -07001112 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
1113 const char* fBenchType; // How we bench it: micro, recording, playback, ...
1114 int fCurrentRecording;
Mike Reede45ff462017-12-06 10:47:03 -05001115 int fCurrentDeserialPicture;
mtklein92007582014-08-01 07:46:52 -07001116 int fCurrentScale;
1117 int fCurrentSKP;
fmalita6519c212016-09-14 08:05:17 -07001118 int fCurrentSVG;
robertphillips5b693772014-11-21 06:19:36 -08001119 int fCurrentUseMPD;
scroggo60869a42015-04-01 12:09:17 -07001120 int fCurrentCodec;
msarett84451022016-02-11 06:45:51 -08001121 int fCurrentAndroidCodec;
msarett7f691442015-09-22 11:56:16 -07001122 int fCurrentBRDImage;
msarett95f192d2015-02-13 09:05:41 -08001123 int fCurrentColorType;
msarettc7796b92016-01-07 14:20:20 -08001124 int fCurrentAlphaType;
msarettb23e6aa2015-06-09 13:56:10 -07001125 int fCurrentSubsetType;
msarett84451022016-02-11 06:45:51 -08001126 int fCurrentSampleSize;
joshualitt261c3ad2015-04-27 09:16:57 -07001127 int fCurrentAnimSKP;
mtkleine714e752014-07-31 12:13:48 -07001128};
1129
msarettc149f0e2016-01-04 11:35:43 -08001130// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1131// This prints something every once in a while so that it knows we're still working.
1132static void start_keepalive() {
Mike Klein03141d22017-10-30 11:57:15 -04001133 static std::thread* intentionallyLeaked = new std::thread([]{
1134 for (;;) {
1135 static const int kSec = 1200;
1136 #if defined(SK_BUILD_FOR_WIN)
1137 Sleep(kSec * 1000);
1138 #else
1139 sleep(kSec);
1140 #endif
1141 SkDebugf("\nBenchmarks still running...\n");
msarettc149f0e2016-01-04 11:35:43 -08001142 }
Mike Klein03141d22017-10-30 11:57:15 -04001143 });
1144 (void)intentionallyLeaked;
msarettc149f0e2016-01-04 11:35:43 -08001145}
1146
Mike Kleinbe28ee22017-02-06 12:46:20 -05001147int main(int argc, char** argv) {
Mike Klein88544fb2019-03-20 10:50:33 -05001148 CommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001149
Brian Osmanbc8150f2017-07-24 11:38:01 -04001150 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001151
Mike Kleinadacaef2017-02-06 09:26:14 -05001152#if defined(SK_BUILD_FOR_IOS)
1153 cd_Documents();
1154#endif
jcgregorio3b27ade2014-11-13 08:06:40 -08001155 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -07001156 SkAutoGraphics ag;
mtkleincc29d262015-07-09 10:04:56 -07001157 SkTaskGroup::Enabler enabled(FLAGS_threads);
mtkleinf3723212014-06-25 14:08:00 -07001158
Chris Dalton040238b2017-12-18 14:22:34 -07001159 SetCtxOptionsFromCommonFlags(&grContextOpts);
krajcevski69a55602014-08-13 10:46:31 -07001160
bsalomon6eb03cc2014-08-07 14:28:50 -07001161 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -07001162 FLAGS_samples = 1;
1163 FLAGS_gpuFrameLag = 0;
1164 }
1165
bsalomon6eb03cc2014-08-07 14:28:50 -07001166 if (!FLAGS_writePath.isEmpty()) {
1167 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
1168 if (!sk_mkdir(FLAGS_writePath[0])) {
1169 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
halcanary96fcdcc2015-08-27 07:41:13 -07001170 FLAGS_writePath.set(0, nullptr);
bsalomon6eb03cc2014-08-07 14:28:50 -07001171 }
1172 }
1173
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001174 std::unique_ptr<SkWStream> logStream(new SkNullWStream);
mtklein60317d0f2014-07-14 11:30:37 -07001175 if (!FLAGS_outResultsFile.isEmpty()) {
mtklein53520152016-01-20 09:53:59 -08001176#if defined(SK_RELEASE)
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001177 logStream.reset(new SkFILEWStream(FLAGS_outResultsFile[0]));
mtklein53520152016-01-20 09:53:59 -08001178#else
1179 SkDebugf("I'm ignoring --outResultsFile because this is a Debug build.");
1180 return 1;
1181#endif
mtklein60317d0f2014-07-14 11:30:37 -07001182 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001183 NanoJSONResultsWriter log(logStream.get(), SkJSONWriter::Mode::kPretty);
1184 log.beginObject(); // root
mtklein1915b622014-08-20 11:45:00 -07001185
1186 if (1 == FLAGS_properties.count() % 2) {
1187 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
1188 return 1;
1189 }
1190 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001191 log.appendString(FLAGS_properties[i-1], FLAGS_properties[i]);
mtklein1915b622014-08-20 11:45:00 -07001192 }
jcgregoriobf5e5232014-07-17 13:14:16 -07001193
1194 if (1 == FLAGS_key.count() % 2) {
1195 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
1196 return 1;
1197 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001198 if (FLAGS_key.count()) {
1199 log.beginObject("key");
1200 for (int i = 1; i < FLAGS_key.count(); i += 2) {
1201 log.appendString(FLAGS_key[i - 1], FLAGS_key[i]);
1202 }
1203 log.endObject(); // key
mtklein94e51562014-08-19 12:41:53 -07001204 }
mtklein60317d0f2014-07-14 11:30:37 -07001205
mtkleinf3723212014-06-25 14:08:00 -07001206 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -07001207 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -04001208
cdaltone1b89582015-06-25 19:17:08 -07001209 SkTArray<double> samples;
mtkleinbb6a0282014-07-01 08:43:42 -07001210
bsalomon6eb03cc2014-08-07 14:28:50 -07001211 if (kAutoTuneLoops != FLAGS_loops) {
1212 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleinf3723212014-06-25 14:08:00 -07001213 } else if (FLAGS_quiet) {
mtklein66cfcff2015-12-04 06:35:30 -08001214 SkDebugf("! -> high variance, ? -> moderate variance\n");
1215 SkDebugf(" micros \tbench\n");
mtkleinbbba1682015-10-28 11:36:30 -07001216 } else if (FLAGS_ms) {
cdaltone1b89582015-06-25 19:17:08 -07001217 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n");
mtkleinf3723212014-06-25 14:08:00 -07001218 } else {
mtkleind75c4662015-04-30 07:11:22 -07001219 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
qiankun.miao8247ec32014-09-09 19:24:36 -07001220 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -07001221 }
1222
svaisanenc47635e2016-01-28 06:05:43 -08001223 SkTArray<Config> configs;
bsalomonc2553372014-07-22 13:09:05 -07001224 create_configs(&configs);
1225
msarettc149f0e2016-01-04 11:35:43 -08001226 if (FLAGS_keepAlive) {
1227 start_keepalive();
1228 }
1229
Mike Klein03fa5d42019-03-22 11:39:09 -05001230 SetAnalyticAAFromCommonFlags();
liyuqian38911a72016-10-04 11:23:22 -07001231
Mike Reedc928fe22017-06-05 10:20:31 -04001232 if (FLAGS_forceRasterPipeline) {
1233 gSkForceRasterPipelineBlitter = true;
1234 }
Yuqian Li550148b2017-01-13 10:13:13 -05001235
mtkleine070c2b2014-10-14 08:40:43 -07001236 int runs = 0;
mtklein92007582014-08-01 07:46:52 -07001237 BenchmarkStream benchStream;
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001238 log.beginObject("results");
mtklein92007582014-08-01 07:46:52 -07001239 while (Benchmark* b = benchStream.next()) {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001240 std::unique_ptr<Benchmark> bench(b);
Mike Klein88544fb2019-03-20 10:50:33 -05001241 if (CommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -07001242 continue;
1243 }
1244
svaisanenc47635e2016-01-28 06:05:43 -08001245 if (!configs.empty()) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001246 log.beginBench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
joshualitt8a6697a2015-09-30 12:11:07 -07001247 bench->delayedSetup();
jcgregoriobf5e5232014-07-17 13:14:16 -07001248 }
egdaniel3bf92062015-06-26 08:12:46 -07001249 for (int i = 0; i < configs.count(); ++i) {
1250 Target* target = is_enabled(b, configs[i]);
1251 if (!target) {
1252 continue;
1253 }
mtkleinf3723212014-06-25 14:08:00 -07001254
halcanary96fcdcc2015-08-27 07:41:13 -07001255 // During HWUI output this canvas may be nullptr.
egdaniel3bf92062015-06-26 08:12:46 -07001256 SkCanvas* canvas = target->getCanvas();
svaisanenc47635e2016-01-28 06:05:43 -08001257 const char* config = target->config.name.c_str();
egdaniel3bf92062015-06-26 08:12:46 -07001258
brianosman7a5ada82016-02-08 13:49:12 -08001259 if (FLAGS_pre_log || FLAGS_dryRun) {
benjaminwagner8d61f0d2016-01-25 13:02:40 -08001260 SkDebugf("Running %s\t%s\n"
1261 , bench->getUniqueName()
1262 , config);
brianosman7a5ada82016-02-08 13:49:12 -08001263 if (FLAGS_dryRun) {
1264 continue;
1265 }
benjaminwagner8d61f0d2016-01-25 13:02:40 -08001266 }
1267
Mike Kleinee254232019-03-28 08:32:14 -05001268 if (FLAGS_purgeBetweenBenches) {
1269 SkGraphics::PurgeAllCaches();
1270 }
1271
Brian Osman5ad87aa2017-09-08 16:05:23 -04001272 TRACE_EVENT2("skia", "Benchmark", "name", TRACE_STR_COPY(bench->getUniqueName()),
1273 "config", TRACE_STR_COPY(config));
Brian Osmanc3cdef52017-08-31 14:09:22 -04001274
egdaniel3bf92062015-06-26 08:12:46 -07001275 target->setup();
robertphillips5b693772014-11-21 06:19:36 -08001276 bench->perCanvasPreDraw(canvas);
1277
cdaltone1b89582015-06-25 19:17:08 -07001278 int maxFrameLag;
mtkleina1ebeb22015-10-01 09:43:39 -07001279 int loops = target->needsFrameTiming(&maxFrameLag)
egdaniel3bf92062015-06-26 08:12:46 -07001280 ? setup_gpu_bench(target, bench.get(), maxFrameLag)
1281 : setup_cpu_bench(overhead, target, bench.get());
cdaltone1b89582015-06-25 19:17:08 -07001282
Leon Scroggins IIIb30d1132017-10-02 09:48:15 -04001283 if (kFailedLoops == loops) {
1284 // Can't be timed. A warning note has already been printed.
1285 cleanup_run(target);
1286 continue;
1287 }
1288
Yuqian Li3528eb32017-09-21 13:23:49 -04001289 if (runs == 0 && FLAGS_ms < 1000) {
1290 // Run the first bench for 1000ms to warm up the nanobench if FLAGS_ms < 1000.
1291 // Otherwise, the first few benches' measurements will be inaccurate.
1292 auto stop = now_ms() + 1000;
1293 do {
1294 time(loops, bench.get(), target);
1295 } while (now_ms() < stop);
1296 }
1297
mtkleinbbba1682015-10-28 11:36:30 -07001298 if (FLAGS_ms) {
1299 samples.reset();
1300 auto stop = now_ms() + FLAGS_ms;
1301 do {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001302 samples.push_back(time(loops, bench.get(), target) / loops);
mtkleinbbba1682015-10-28 11:36:30 -07001303 } while (now_ms() < stop);
1304 } else {
cdaltone1b89582015-06-25 19:17:08 -07001305 samples.reset(FLAGS_samples);
1306 for (int s = 0; s < FLAGS_samples; s++) {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001307 samples[s] = time(loops, bench.get(), target) / loops;
cdaltone1b89582015-06-25 19:17:08 -07001308 }
cdaltone1b89582015-06-25 19:17:08 -07001309 }
mtkleinf3723212014-06-25 14:08:00 -07001310
joshualitte45c81c2015-12-02 09:05:37 -08001311 SkTArray<SkString> keys;
1312 SkTArray<double> values;
1313 bool gpuStatsDump = FLAGS_gpuStatsDump && Benchmark::kGPU_Backend == configs[i].backend;
1314 if (gpuStatsDump) {
1315 // TODO cache stats
1316 bench->getGpuStats(canvas, &keys, &values);
1317 }
joshualitte45c81c2015-12-02 09:05:37 -08001318
robertphillips5b693772014-11-21 06:19:36 -08001319 bench->perCanvasPostDraw(canvas);
1320
egdaniel3bf92062015-06-26 08:12:46 -07001321 if (Benchmark::kNonRendering_Backend != target->config.backend &&
tomhudsond968a6f2015-03-26 11:28:06 -07001322 !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -07001323 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -07001324 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -07001325 pngFilename.append(".png");
egdaniel3bf92062015-06-26 08:12:46 -07001326 write_canvas_png(target, pngFilename);
bsalomon6eb03cc2014-08-07 14:28:50 -07001327 }
1328
Mike Klein512a2442018-09-27 10:44:56 -04001329 // Building stats.plot often shows up in profiles,
1330 // so skip building it when we're not going to print it anyway.
1331 const bool want_plot = !FLAGS_quiet;
1332
1333 Stats stats(samples, want_plot);
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001334 log.beginObject(config);
1335
1336 log.beginObject("options");
1337 log.appendString("name", bench->getName());
1338 benchStream.fillCurrentOptions(log);
1339 target->fillOptions(log);
1340 log.endObject(); // options
1341
1342 // Metrics
1343 log.appendMetric("min_ms", stats.min);
1344 log.beginArray("samples");
1345 for (double sample : samples) {
1346 log.appendDoubleDigits(sample, 16);
1347 }
1348 log.endArray(); // samples
1349 benchStream.fillCurrentMetrics(log);
joshualitte45c81c2015-12-02 09:05:37 -08001350 if (gpuStatsDump) {
1351 // dump to json, only SKPBench currently returns valid keys / values
1352 SkASSERT(keys.count() == values.count());
1353 for (int i = 0; i < keys.count(); i++) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001354 log.appendMetric(keys[i].c_str(), values[i]);
joshualitte45c81c2015-12-02 09:05:37 -08001355 }
1356 }
joshualitte45c81c2015-12-02 09:05:37 -08001357
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001358 log.endObject(); // config
1359
mtkleine070c2b2014-10-14 08:40:43 -07001360 if (runs++ % FLAGS_flushEvery == 0) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001361 log.flush();
mtkleine070c2b2014-10-14 08:40:43 -07001362 }
mtklein60317d0f2014-07-14 11:30:37 -07001363
bsalomon6eb03cc2014-08-07 14:28:50 -07001364 if (kAutoTuneLoops != FLAGS_loops) {
egdaniel3bf92062015-06-26 08:12:46 -07001365 if (configs.count() == 1) {
mtkleina189ccd2014-07-14 12:28:47 -07001366 config = ""; // Only print the config if we run the same bench on more than one.
1367 }
mtkleind75c4662015-04-30 07:11:22 -07001368 SkDebugf("%4d/%-4dMB\t%s\t%s\n"
1369 , sk_tools::getCurrResidentSetSizeMB()
1370 , sk_tools::getMaxResidentSetSizeMB()
mtklein53d25622014-09-18 07:39:42 -07001371 , bench->getUniqueName()
1372 , config);
mtkleinf3723212014-06-25 14:08:00 -07001373 } else if (FLAGS_quiet) {
mtklein66cfcff2015-12-04 06:35:30 -08001374 const char* mark = " ";
Hal Canarye99e8da2019-01-14 16:34:50 -05001375 const double stddev_percent =
1376 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
mtklein66cfcff2015-12-04 06:35:30 -08001377 if (stddev_percent > 5) mark = "?";
1378 if (stddev_percent > 10) mark = "!";
1379
1380 SkDebugf("%10.2f %s\t%s\t%s\n",
1381 stats.median*1e3, mark, bench->getUniqueName(), config);
Mike Reedc665e5b2017-07-04 22:56:06 -04001382 } else if (FLAGS_csv) {
Hal Canarye99e8da2019-01-14 16:34:50 -05001383 const double stddev_percent =
1384 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
Mike Reedc665e5b2017-07-04 22:56:06 -04001385 SkDebugf("%g,%g,%g,%g,%g,%s,%s\n"
1386 , stats.min
1387 , stats.median
1388 , stats.mean
1389 , stats.max
1390 , stddev_percent
1391 , config
1392 , bench->getUniqueName()
1393 );
1394 } else {
1395 const char* format = "%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n";
Hal Canarye99e8da2019-01-14 16:34:50 -05001396 const double stddev_percent =
1397 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
Mike Reedc665e5b2017-07-04 22:56:06 -04001398 SkDebugf(format
mtkleind75c4662015-04-30 07:11:22 -07001399 , sk_tools::getCurrResidentSetSizeMB()
1400 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -07001401 , loops
mtklein55b0ffc2014-07-17 08:38:23 -07001402 , HUMANIZE(stats.min)
1403 , HUMANIZE(stats.median)
1404 , HUMANIZE(stats.mean)
1405 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -07001406 , stddev_percent
mtkleinbbba1682015-10-28 11:36:30 -07001407 , FLAGS_ms ? to_string(samples.count()).c_str() : stats.plot.c_str()
mtkleinf3723212014-06-25 14:08:00 -07001408 , config
mtklein96289052014-09-10 12:05:59 -07001409 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -07001410 );
1411 }
joshualitte45c81c2015-12-02 09:05:37 -08001412
joshualitte45c81c2015-12-02 09:05:37 -08001413 if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -04001414 target->dumpStats();
bsalomon06cddec2014-10-24 10:40:50 -07001415 }
joshualitte45c81c2015-12-02 09:05:37 -08001416
cdalton2c56ba52015-06-26 13:32:53 -07001417 if (FLAGS_verbose) {
1418 SkDebugf("Samples: ");
1419 for (int i = 0; i < samples.count(); i++) {
1420 SkDebugf("%s ", HUMANIZE(samples[i]));
1421 }
1422 SkDebugf("%s\n", bench->getUniqueName());
1423 }
egdaniel3bf92062015-06-26 08:12:46 -07001424 cleanup_run(target);
mtkleinf3723212014-06-25 14:08:00 -07001425 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001426 if (!configs.empty()) {
1427 log.endBench();
1428 }
mtkleinf3723212014-06-25 14:08:00 -07001429 }
1430
Herb Derby5a523fe2017-01-26 16:48:28 -05001431 SkGraphics::PurgeAllCaches();
1432
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001433 log.beginBench("memory_usage", 0, 0);
1434 log.beginObject("meta"); // config
1435 log.appendS32("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
1436 log.endObject(); // config
1437 log.endBench();
1438
1439 log.endObject(); // results
1440 log.endObject(); // root
1441 log.flush();
mtkleine1091452014-12-04 10:47:02 -08001442
mtkleinf3723212014-06-25 14:08:00 -07001443 return 0;
1444}