blob: f96cceaf3e445d1c01fa81d6b1d0225fcfae1a0a [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "bench/nanobench.h"
tomhudsond968a6f2015-03-26 11:28:06 -070011
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "bench/AndroidCodecBench.h"
13#include "bench/Benchmark.h"
14#include "bench/BitmapRegionDecoderBench.h"
15#include "bench/CodecBench.h"
16#include "bench/CodecBenchPriv.h"
17#include "bench/GMBench.h"
18#include "bench/RecordingBench.h"
19#include "bench/ResultsWriter.h"
20#include "bench/SKPAnimationBench.h"
21#include "bench/SKPBench.h"
Hal Canary5dfefa22019-10-24 13:52:17 -040022#include "bench/SkGlyphCacheBench.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "include/android/SkBitmapRegionDecoder.h"
24#include "include/codec/SkAndroidCodec.h"
25#include "include/codec/SkCodec.h"
26#include "include/core/SkCanvas.h"
27#include "include/core/SkData.h"
28#include "include/core/SkGraphics.h"
29#include "include/core/SkPictureRecorder.h"
30#include "include/core/SkString.h"
31#include "include/core/SkSurface.h"
Ben Wagneracf98df2019-07-12 12:51:44 -040032#include "include/core/SkTime.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050033#include "src/core/SkAutoMalloc.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050034#include "src/core/SkColorSpacePriv.h"
Ben Wagnerab6eefe2019-05-20 11:02:49 -040035#include "src/core/SkLeanWindows.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050036#include "src/core/SkOSFile.h"
37#include "src/core/SkTaskGroup.h"
38#include "src/core/SkTraceEvent.h"
39#include "src/utils/SkJSONWriter.h"
40#include "src/utils/SkOSPath.h"
Jim Van Verth8a9a3712019-05-31 10:49:12 -040041#include "tools/AutoreleasePool.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050042#include "tools/CrashHandler.h"
43#include "tools/ProcStats.h"
44#include "tools/Stats.h"
45#include "tools/flags/CommonFlags.h"
46#include "tools/flags/CommonFlagsConfig.h"
47#include "tools/ios_utils.h"
48#include "tools/trace/EventTracingPriv.h"
49#include "tools/trace/SkDebugfTracer.h"
mtkleinf3723212014-06-25 14:08:00 -070050
Hal Canary0f666812018-03-22 15:21:12 -040051#ifdef SK_XML
Mike Kleinc0bd9f92019-04-23 12:05:21 -050052#include "experimental/svg/model/SkSVGDOM.h"
Hal Canary0f666812018-03-22 15:21:12 -040053#endif // SK_XML
54
bungeman60e0fee2015-08-26 05:15:46 -070055#include <stdlib.h>
Mike Klein03141d22017-10-30 11:57:15 -040056#include <thread>
bungeman60e0fee2015-08-26 05:15:46 -070057
Mike Reedc928fe22017-06-05 10:20:31 -040058extern bool gSkForceRasterPipelineBlitter;
Mike Klein2a57e792020-01-14 12:47:52 -060059extern bool gUseSkVMBlitter;
Mike Kleinea4459d2020-01-16 13:05:04 -060060extern bool gSkVMJITViaDylib;
Mike Reedc928fe22017-06-05 10:20:31 -040061
Mike Klein8f11d4d2018-01-24 12:42:55 -050062#ifndef SK_BUILD_FOR_WIN
scroggo38ce0a72016-01-07 07:28:47 -080063 #include <unistd.h>
Brian Salomon032aaae2018-03-23 16:10:36 -040064
scroggo38ce0a72016-01-07 07:28:47 -080065#endif
66
Mike Kleinc0bd9f92019-04-23 12:05:21 -050067#include "src/gpu/GrCaps.h"
68#include "src/gpu/GrContextPriv.h"
69#include "src/gpu/SkGr.h"
70#include "src/gpu/gl/GrGLDefines.h"
71#include "src/gpu/gl/GrGLGpu.h"
72#include "src/gpu/gl/GrGLUtil.h"
73#include "tools/gpu/GrContextFactory.h"
Brian Salomon032aaae2018-03-23 16:10:36 -040074
Brian Osmanc7ad40f2018-05-31 14:27:17 -040075using sk_gpu_test::ContextInfo;
76using sk_gpu_test::GrContextFactory;
77using sk_gpu_test::TestContext;
Brian Salomon032aaae2018-03-23 16:10:36 -040078
Brian Osmanc7ad40f2018-05-31 14:27:17 -040079GrContextOptions grContextOpts;
bsalomon682c2692015-05-22 14:01:46 -070080
reed53249782014-10-10 09:09:52 -070081static const int kAutoTuneLoops = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -070082
bsalomon6eb03cc2014-08-07 14:28:50 -070083static SkString loops_help_txt() {
84 SkString help;
85 help.printf("Number of times to run each bench. Set this to %d to auto-"
86 "tune for each bench. Timings are only reported when auto-tuning.",
87 kAutoTuneLoops);
88 return help;
89}
90
cdaltone1b89582015-06-25 19:17:08 -070091static SkString to_string(int n) {
92 SkString str;
93 str.appendS32(n);
94 return str;
95}
96
Mike Kleinac8f4432019-07-01 10:15:32 -050097static DEFINE_int(loops, kAutoTuneLoops, loops_help_txt().c_str());
bsalomon6eb03cc2014-08-07 14:28:50 -070098
Mike Klein5b3f3432019-03-21 11:42:21 -050099static DEFINE_int(samples, 10, "Number of samples to measure for each bench.");
100static DEFINE_int(ms, 0, "If >0, run each bench for this many ms instead of obeying --samples.");
101static DEFINE_int(overheadLoops, 100000, "Loops to estimate timer overhead.");
Mike Klein84836b72019-03-21 11:31:36 -0500102static DEFINE_double(overheadGoal, 0.0001,
mtkleinf3723212014-06-25 14:08:00 -0700103 "Loop until timer overhead is at most this fraction of our measurments.");
Mike Klein84836b72019-03-21 11:31:36 -0500104static DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500105static DEFINE_int(gpuFrameLag, 5,
Mike Klein84836b72019-03-21 11:31:36 -0500106 "If unknown, estimated maximum number of frames GPU allows to lag.");
mtkleinf3723212014-06-25 14:08:00 -0700107
Mike Klein84836b72019-03-21 11:31:36 -0500108static DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500109static DEFINE_int(maxCalibrationAttempts, 3,
mtklein55b0ffc2014-07-17 08:38:23 -0700110 "Try up to this many times to guess loops for a bench, or skip the bench.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500111static DEFINE_int(maxLoops, 1000000, "Never run a bench more times than this.");
Mike Klein84836b72019-03-21 11:31:36 -0500112static DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
113static DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
114static DEFINE_string(zoom, "1.0,0",
115 "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom "
116 "function that ping-pongs between 1.0 and zoomMax.");
117static DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
Mike Klein84836b72019-03-21 11:31:36 -0500118static DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
119static DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?");
Mike Klein5b3f3432019-03-21 11:42:21 -0500120static DEFINE_int(flushEvery, 10, "Flush --outResultsFile every Nth run.");
Mike Klein84836b72019-03-21 11:31:36 -0500121static DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
122static DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json");
123static DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out");
124static DEFINE_bool(csv, false, "Print status in CSV format");
125static DEFINE_string(sourceType, "",
mtklein65dfd2f2016-02-03 10:40:54 -0800126 "Apply usual --match rules to source type: bench, gm, skp, image, etc.");
Mike Klein84836b72019-03-21 11:31:36 -0500127static DEFINE_string(benchType, "",
128 "Apply usual --match rules to bench type: micro, recording, "
129 "piping, playback, skcodec, etc.");
mtklein65dfd2f2016-02-03 10:40:54 -0800130
Mike Klein84836b72019-03-21 11:31:36 -0500131static DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
Mike Kleinea4459d2020-01-16 13:05:04 -0600132static DEFINE_bool(skvm, false, "sets gUseSkVMBlitter and gSkVMJITViaDylib");
Mike Reedc928fe22017-06-05 10:20:31 -0400133
Mike Klein19fb3972019-03-21 13:08:08 -0500134static DEFINE_bool2(pre_log, p, false,
135 "Log before running each test. May be incomprehensible when threading");
136
Mike Klein629f5fc2019-03-22 14:55:19 -0500137static DEFINE_bool(cpu, true, "master switch for running CPU-bound work.");
138static DEFINE_bool(gpu, true, "master switch for running GPU-bound work.");
139static DEFINE_bool(dryRun, false,
140 "just print the tests that would be run, without actually running them.");
141static DEFINE_string(images, "",
142 "List of images and/or directories to decode. A directory with no images"
143 " is treated as a fatal error.");
144static DEFINE_bool(simpleCodec, false,
145 "Runs of a subset of the codec tests, always N32, Premul or Opaque");
146
Mike Kleinc6142d82019-03-25 10:54:59 -0500147static DEFINE_string2(match, m, nullptr,
148 "[~][^]substring[$] [...] of name to run.\n"
149 "Multiple matches may be separated by spaces.\n"
150 "~ causes a matching name to always be skipped\n"
151 "^ requires the start of the name to match\n"
152 "$ requires the end of the name to match\n"
153 "^ and $ requires an exact match\n"
154 "If a name does not match any list entry,\n"
155 "it is skipped unless some list entry starts with ~");
156
157static DEFINE_bool2(quiet, q, false, "if true, don't print status updates.");
158static DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
159
160
161static DEFINE_string(skps, "skps", "Directory to read skps from.");
162static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file.");
Hal Canary5dfefa22019-10-24 13:52:17 -0400163static DEFINE_string(texttraces, "", "Directory to read TextBlobTrace files from.");
Mike Kleinc6142d82019-03-25 10:54:59 -0500164
165static DEFINE_int_2(threads, j, -1,
166 "Run threadsafe tests on a threadpool with this many extra threads, "
167 "defaulting to one extra thread per core.");
168
169static DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs.");
170
171static DEFINE_string(key, "",
172 "Space-separated key/value pairs to add to JSON identifying this builder.");
173static DEFINE_string(properties, "",
174 "Space-separated key/value pairs to add to JSON identifying this run.");
175
Mike Kleinee254232019-03-28 08:32:14 -0500176static DEFINE_bool(purgeBetweenBenches, false,
177 "Call SkGraphics::PurgeAllCaches() between each benchmark?");
178
mtkleinbbba1682015-10-28 11:36:30 -0700179static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
180
mtkleinf3723212014-06-25 14:08:00 -0700181static SkString humanize(double ms) {
mtkleindc5bbab2014-09-24 06:34:09 -0700182 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
mtklein748ca3b2015-01-15 10:56:12 -0800183 return HumanizeMs(ms);
mtkleinf3723212014-06-25 14:08:00 -0700184}
mtklein55b0ffc2014-07-17 08:38:23 -0700185#define HUMANIZE(ms) humanize(ms).c_str()
mtkleinf3723212014-06-25 14:08:00 -0700186
tomhudsond968a6f2015-03-26 11:28:06 -0700187bool Target::init(SkImageInfo info, Benchmark* bench) {
188 if (Benchmark::kRaster_Backend == config.backend) {
reede8f30622016-03-23 18:59:25 -0700189 this->surface = SkSurface::MakeRaster(info);
190 if (!this->surface) {
tomhudsond968a6f2015-03-26 11:28:06 -0700191 return false;
192 }
193 }
194 return true;
195}
196bool Target::capturePixels(SkBitmap* bmp) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700197 SkCanvas* canvas = this->getCanvas();
tomhudsond968a6f2015-03-26 11:28:06 -0700198 if (!canvas) {
199 return false;
200 }
Mike Reed12e946b2017-04-17 10:53:29 -0400201 bmp->allocPixels(canvas->imageInfo());
202 if (!canvas->readPixels(*bmp, 0, 0)) {
tomhudsond968a6f2015-03-26 11:28:06 -0700203 SkDebugf("Can't read canvas pixels.\n");
204 return false;
205 }
206 return true;
207}
208
tomhudsond968a6f2015-03-26 11:28:06 -0700209struct GPUTarget : public Target {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400210 explicit GPUTarget(const Config& c) : Target(c) {}
211 ContextInfo contextInfo;
212 std::unique_ptr<GrContextFactory> factory;
tomhudsond968a6f2015-03-26 11:28:06 -0700213
214 void setup() override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400215 this->contextInfo.testContext()->makeCurrent();
tomhudsond968a6f2015-03-26 11:28:06 -0700216 // Make sure we're done with whatever came before.
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400217 this->contextInfo.testContext()->finish();
tomhudsond968a6f2015-03-26 11:28:06 -0700218 }
219 void endTiming() override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400220 if (this->contextInfo.testContext()) {
Greg Daniel02497d42020-02-21 15:46:27 -0500221 this->contextInfo.testContext()->flushAndWaitOnSync(contextInfo.grContext());
tomhudsond968a6f2015-03-26 11:28:06 -0700222 }
223 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400224 void fence() override { this->contextInfo.testContext()->finish(); }
mtkleind75c4662015-04-30 07:11:22 -0700225
cdaltond416a5b2015-06-23 13:23:44 -0700226 bool needsFrameTiming(int* maxFrameLag) const override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400227 if (!this->contextInfo.testContext()->getMaxGpuFrameLag(maxFrameLag)) {
cdaltond416a5b2015-06-23 13:23:44 -0700228 // Frame lag is unknown.
229 *maxFrameLag = FLAGS_gpuFrameLag;
230 }
231 return true;
232 }
tomhudsond968a6f2015-03-26 11:28:06 -0700233 bool init(SkImageInfo info, Benchmark* bench) override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400234 GrContextOptions options = grContextOpts;
235 bench->modifyGrContextOptions(&options);
236 this->factory.reset(new GrContextFactory(options));
bsalomonafcd7cd2015-08-31 12:39:41 -0700237 uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag :
238 0;
tomhudsond968a6f2015-03-26 11:28:06 -0700239 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400240 this->surface = SkSurface::MakeRenderTarget(
241 this->factory->get(this->config.ctxType, this->config.ctxOverrides),
242 SkBudgeted::kNo, info, this->config.samples, &props);
243 this->contextInfo =
244 this->factory->getContextInfo(this->config.ctxType, this->config.ctxOverrides);
tomhudsond968a6f2015-03-26 11:28:06 -0700245 if (!this->surface.get()) {
246 return false;
247 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400248 if (!this->contextInfo.testContext()->fenceSyncSupport()) {
cdaltond416a5b2015-06-23 13:23:44 -0700249 SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. "
svaisanenc47635e2016-01-28 06:05:43 -0800250 "Timings might not be accurate.\n", this->config.name.c_str());
cdaltond416a5b2015-06-23 13:23:44 -0700251 }
tomhudsond968a6f2015-03-26 11:28:06 -0700252 return true;
253 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500254 void fillOptions(NanoJSONResultsWriter& log) override {
tomhudsond968a6f2015-03-26 11:28:06 -0700255 const GrGLubyte* version;
Greg Danielbdf12ad2018-10-12 09:31:11 -0400256 if (this->contextInfo.backend() == GrBackendApi::kOpenGL) {
Brian Salomon032aaae2018-03-23 16:10:36 -0400257 const GrGLInterface* gl =
Robert Phillips9da87e02019-02-04 13:26:26 -0500258 static_cast<GrGLGpu*>(this->contextInfo.grContext()->priv().getGpu())
Brian Salomon032aaae2018-03-23 16:10:36 -0400259 ->glInterface();
bsalomonc8699322016-05-11 11:55:36 -0700260 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VERSION));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500261 log.appendString("GL_VERSION", (const char*)(version));
tomhudsond968a6f2015-03-26 11:28:06 -0700262
bsalomonc8699322016-05-11 11:55:36 -0700263 GR_GL_CALL_RET(gl, version, GetString(GR_GL_RENDERER));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500264 log.appendString("GL_RENDERER", (const char*) version);
tomhudsond968a6f2015-03-26 11:28:06 -0700265
bsalomonc8699322016-05-11 11:55:36 -0700266 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VENDOR));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500267 log.appendString("GL_VENDOR", (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_SHADING_LANGUAGE_VERSION));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500270 log.appendString("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
bsalomonc8699322016-05-11 11:55:36 -0700271 }
tomhudsond968a6f2015-03-26 11:28:06 -0700272 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400273
274 void dumpStats() override {
Robert Phillips9da87e02019-02-04 13:26:26 -0500275 this->contextInfo.grContext()->priv().printCacheStats();
276 this->contextInfo.grContext()->priv().printGpuStats();
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400277 }
tomhudsond968a6f2015-03-26 11:28:06 -0700278};
mtkleind75c4662015-04-30 07:11:22 -0700279
tomhudson75a0ebb2015-03-27 12:11:44 -0700280static double time(int loops, Benchmark* bench, Target* target) {
281 SkCanvas* canvas = target->getCanvas();
bsalomon6eb03cc2014-08-07 14:28:50 -0700282 if (canvas) {
283 canvas->clear(SK_ColorWHITE);
284 }
joshualitt8a6697a2015-09-30 12:11:07 -0700285 bench->preDraw(canvas);
mtkleinbbba1682015-10-28 11:36:30 -0700286 double start = now_ms();
tomhudson75a0ebb2015-03-27 12:11:44 -0700287 canvas = target->beginTiming(canvas);
288 bench->draw(loops, canvas);
tomhudson75a0ebb2015-03-27 12:11:44 -0700289 target->endTiming();
mtkleinbbba1682015-10-28 11:36:30 -0700290 double elapsed = now_ms() - start;
joshualitt8a6697a2015-09-30 12:11:07 -0700291 bench->postDraw(canvas);
mtkleinbbba1682015-10-28 11:36:30 -0700292 return elapsed;
mtkleinbb6a0282014-07-01 08:43:42 -0700293}
294
mtkleinf3723212014-06-25 14:08:00 -0700295static double estimate_timer_overhead() {
296 double overhead = 0;
mtkleinf3723212014-06-25 14:08:00 -0700297 for (int i = 0; i < FLAGS_overheadLoops; i++) {
mtkleinbbba1682015-10-28 11:36:30 -0700298 double start = now_ms();
299 overhead += now_ms() - start;
mtkleinf3723212014-06-25 14:08:00 -0700300 }
301 return overhead / FLAGS_overheadLoops;
302}
303
reed53249782014-10-10 09:09:52 -0700304static int detect_forever_loops(int loops) {
305 // look for a magic run-forever value
306 if (loops < 0) {
307 loops = SK_MaxS32;
308 }
309 return loops;
310}
311
mtklein55b0ffc2014-07-17 08:38:23 -0700312static int clamp_loops(int loops) {
313 if (loops < 1) {
mtklein527930f2014-11-06 08:04:34 -0800314 SkDebugf("ERROR: clamping loops from %d to 1. "
315 "There's probably something wrong with the bench.\n", loops);
mtklein55b0ffc2014-07-17 08:38:23 -0700316 return 1;
317 }
318 if (loops > FLAGS_maxLoops) {
319 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
320 return FLAGS_maxLoops;
321 }
322 return loops;
323}
324
tomhudsond968a6f2015-03-26 11:28:06 -0700325static bool write_canvas_png(Target* target, const SkString& filename) {
326
bsalomon6eb03cc2014-08-07 14:28:50 -0700327 if (filename.isEmpty()) {
328 return false;
329 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700330 if (target->getCanvas() &&
331 kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700332 return false;
333 }
tomhudsond968a6f2015-03-26 11:28:06 -0700334
bsalomon6eb03cc2014-08-07 14:28:50 -0700335 SkBitmap bmp;
tomhudsond968a6f2015-03-26 11:28:06 -0700336
337 if (!target->capturePixels(&bmp)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700338 return false;
339 }
tomhudsond968a6f2015-03-26 11:28:06 -0700340
bsalomon6eb03cc2014-08-07 14:28:50 -0700341 SkString dir = SkOSPath::Dirname(filename.c_str());
342 if (!sk_mkdir(dir.c_str())) {
343 SkDebugf("Can't make dir %s.\n", dir.c_str());
344 return false;
345 }
346 SkFILEWStream stream(filename.c_str());
347 if (!stream.isValid()) {
348 SkDebugf("Can't write %s.\n", filename.c_str());
349 return false;
350 }
Hal Canarydb683012016-11-23 08:55:18 -0700351 if (!SkEncodeImage(&stream, bmp, SkEncodedImageFormat::kPNG, 100)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700352 SkDebugf("Can't encode a PNG.\n");
353 return false;
354 }
355 return true;
356}
357
358static int kFailedLoops = -2;
cdaltone1b89582015-06-25 19:17:08 -0700359static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) {
mtkleinbb6a0282014-07-01 08:43:42 -0700360 // First figure out approximately how many loops of bench it takes to make overhead negligible.
mtklein2069e222014-08-04 13:57:39 -0700361 double bench_plus_overhead = 0.0;
mtklein55b0ffc2014-07-17 08:38:23 -0700362 int round = 0;
cdaltonb4022962015-06-25 10:51:56 -0700363 int loops = bench->calculateLoops(FLAGS_loops);
364 if (kAutoTuneLoops == loops) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700365 while (bench_plus_overhead < overhead) {
366 if (round++ == FLAGS_maxCalibrationAttempts) {
367 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
mtklein96289052014-09-10 12:05:59 -0700368 bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
bsalomon6eb03cc2014-08-07 14:28:50 -0700369 return kFailedLoops;
370 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700371 bench_plus_overhead = time(1, bench, target);
mtklein55b0ffc2014-07-17 08:38:23 -0700372 }
mtklein2069e222014-08-04 13:57:39 -0700373 }
mtkleinf3723212014-06-25 14:08:00 -0700374
mtkleinbb6a0282014-07-01 08:43:42 -0700375 // Later we'll just start and stop the timer once but loop N times.
mtkleinf3723212014-06-25 14:08:00 -0700376 // We'll pick N to make timer overhead negligible:
377 //
mtkleinbb6a0282014-07-01 08:43:42 -0700378 // overhead
379 // ------------------------- < FLAGS_overheadGoal
380 // overhead + N * Bench Time
mtkleinf3723212014-06-25 14:08:00 -0700381 //
Hal Canary55325b72017-01-03 10:36:17 -0500382 // where bench_plus_overhead ~=~ overhead + Bench Time.
mtkleinf3723212014-06-25 14:08:00 -0700383 //
384 // Doing some math, we get:
385 //
mtkleinbb6a0282014-07-01 08:43:42 -0700386 // (overhead / FLAGS_overheadGoal) - overhead
387 // ------------------------------------------ < N
388 // bench_plus_overhead - overhead)
mtkleinf3723212014-06-25 14:08:00 -0700389 //
390 // Luckily, this also works well in practice. :)
bsalomon6eb03cc2014-08-07 14:28:50 -0700391 if (kAutoTuneLoops == loops) {
392 const double numer = overhead / FLAGS_overheadGoal - overhead;
393 const double denom = bench_plus_overhead - overhead;
394 loops = (int)ceil(numer / denom);
reed53249782014-10-10 09:09:52 -0700395 loops = clamp_loops(loops);
396 } else {
397 loops = detect_forever_loops(loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700398 }
mtkleinbb6a0282014-07-01 08:43:42 -0700399
mtkleinbb6a0282014-07-01 08:43:42 -0700400 return loops;
mtkleinf3723212014-06-25 14:08:00 -0700401}
402
cdaltone1b89582015-06-25 19:17:08 -0700403static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) {
mtkleinbb6a0282014-07-01 08:43:42 -0700404 // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
cdaltonb4022962015-06-25 10:51:56 -0700405 int loops = bench->calculateLoops(FLAGS_loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700406 if (kAutoTuneLoops == loops) {
407 loops = 1;
mtkleina189ccd2014-07-14 12:28:47 -0700408 double elapsed = 0;
409 do {
mtklein527930f2014-11-06 08:04:34 -0800410 if (1<<30 == loops) {
411 // We're about to wrap. Something's wrong with the bench.
412 loops = 0;
413 break;
414 }
mtkleina189ccd2014-07-14 12:28:47 -0700415 loops *= 2;
416 // If the GPU lets frames lag at all, we need to make sure we're timing
cdaltond416a5b2015-06-23 13:23:44 -0700417 // _this_ round, not still timing last round.
418 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700419 elapsed = time(loops, bench, target);
mtkleina189ccd2014-07-14 12:28:47 -0700420 }
421 } while (elapsed < FLAGS_gpuMs);
mtkleinbb6a0282014-07-01 08:43:42 -0700422
mtkleina189ccd2014-07-14 12:28:47 -0700423 // We've overshot at least a little. Scale back linearly.
424 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
reed53249782014-10-10 09:09:52 -0700425 loops = clamp_loops(loops);
mtkleinbb6a0282014-07-01 08:43:42 -0700426
tomhudsond968a6f2015-03-26 11:28:06 -0700427 // Make sure we're not still timing our calibration.
428 target->fence();
reed53249782014-10-10 09:09:52 -0700429 } else {
430 loops = detect_forever_loops(loops);
mtkleina189ccd2014-07-14 12:28:47 -0700431 }
mtkleinbb6a0282014-07-01 08:43:42 -0700432 // Pretty much the same deal as the calibration: do some warmup to make
433 // sure we're timing steady-state pipelined frames.
Brian Osman01776982017-10-10 15:41:03 -0400434 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700435 time(loops, bench, target);
mtkleinf3723212014-06-25 14:08:00 -0700436 }
mtkleinbb6a0282014-07-01 08:43:42 -0700437
mtkleinbb6a0282014-07-01 08:43:42 -0700438 return loops;
439}
mtkleinbb6a0282014-07-01 08:43:42 -0700440
Brian Salomon6405e712017-03-20 08:54:16 -0400441#define kBogusContextType GrContextFactory::kGL_ContextType
csmartdaltone812d492017-02-21 12:36:05 -0700442#define kBogusContextOverrides GrContextFactory::ContextOverrides::kNone
bsalomonc2553372014-07-22 13:09:05 -0700443
svaisanenc47635e2016-01-28 06:05:43 -0800444static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) {
svaisanenc47635e2016-01-28 06:05:43 -0800445 if (const auto* gpuConfig = config->asConfigGpu()) {
Ben Wagner32fa5102017-08-10 21:25:55 -0400446 if (!FLAGS_gpu) {
447 SkDebugf("Skipping config '%s' as requested.\n", config->getTag().c_str());
svaisanenc47635e2016-01-28 06:05:43 -0800448 return;
Ben Wagner32fa5102017-08-10 21:25:55 -0400449 }
svaisanenc47635e2016-01-28 06:05:43 -0800450
svaisanenc47635e2016-01-28 06:05:43 -0800451 const auto ctxType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700452 const auto ctxOverrides = gpuConfig->getContextOverrides();
svaisanenc47635e2016-01-28 06:05:43 -0800453 const auto sampleCount = gpuConfig->getSamples();
Greg Daniel81e7bf82017-07-19 14:47:42 -0400454 const auto colorType = gpuConfig->getColorType();
455 auto colorSpace = gpuConfig->getColorSpace();
Brian Salomonf865b052018-03-09 09:01:53 -0500456 if (gpuConfig->getSurfType() != SkCommandLineConfigGpu::SurfType::kDefault) {
457 SkDebugf("This tool only supports the default surface type.");
458 return;
459 }
svaisanenc47635e2016-01-28 06:05:43 -0800460
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400461 GrContextFactory factory(grContextOpts);
462 if (const GrContext* ctx = factory.get(ctxType, ctxOverrides)) {
Greg Daniel6fa62e22019-08-07 15:52:37 -0400463 GrBackendFormat format = ctx->defaultBackendFormat(colorType, GrRenderable::kYes);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500464 int supportedSampleCount =
Greg Daniel6fa62e22019-08-07 15:52:37 -0400465 ctx->priv().caps()->getRenderTargetSampleCount(sampleCount, format);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400466 if (sampleCount != supportedSampleCount) {
Ben Wagner32fa5102017-08-10 21:25:55 -0400467 SkDebugf("Configuration '%s' sample count %d is not a supported sample count.\n",
468 config->getTag().c_str(), sampleCount);
svaisanenc47635e2016-01-28 06:05:43 -0800469 return;
470 }
471 } else {
Ben Wagner32fa5102017-08-10 21:25:55 -0400472 SkDebugf("No context was available matching config '%s'.\n",
473 config->getTag().c_str());
svaisanenc47635e2016-01-28 06:05:43 -0800474 return;
475 }
476
477 Config target = {
kkinnunend4e1c352016-03-01 23:41:26 -0800478 gpuConfig->getTag(),
svaisanenc47635e2016-01-28 06:05:43 -0800479 Benchmark::kGPU_Backend,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400480 colorType,
svaisanenc47635e2016-01-28 06:05:43 -0800481 kPremul_SkAlphaType,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400482 sk_ref_sp(colorSpace),
svaisanenc47635e2016-01-28 06:05:43 -0800483 sampleCount,
484 ctxType,
csmartdaltone812d492017-02-21 12:36:05 -0700485 ctxOverrides,
kkinnunend4e1c352016-03-01 23:41:26 -0800486 gpuConfig->getUseDIText()
487 };
svaisanenc47635e2016-01-28 06:05:43 -0800488
489 configs->push_back(target);
490 return;
491 }
svaisanenc47635e2016-01-28 06:05:43 -0800492
brianosmanb109b8c2016-06-16 13:03:24 -0700493 #define CPU_CONFIG(name, backend, color, alpha, colorSpace) \
494 if (config->getTag().equals(#name)) { \
Ben Wagner32fa5102017-08-10 21:25:55 -0400495 if (!FLAGS_cpu) { \
496 SkDebugf("Skipping config '%s' as requested.\n", \
497 config->getTag().c_str()); \
498 return; \
499 } \
brianosmanb109b8c2016-06-16 13:03:24 -0700500 Config config = { \
501 SkString(#name), Benchmark::backend, color, alpha, colorSpace, \
csmartdaltone812d492017-02-21 12:36:05 -0700502 0, kBogusContextType, kBogusContextOverrides, false \
brianosmanb109b8c2016-06-16 13:03:24 -0700503 }; \
504 configs->push_back(config); \
505 return; \
mtkleinbb6a0282014-07-01 08:43:42 -0700506 }
mtkleine714e752014-07-31 12:13:48 -0700507
Ben Wagner32fa5102017-08-10 21:25:55 -0400508 CPU_CONFIG(nonrendering, kNonRendering_Backend,
509 kUnknown_SkColorType, kUnpremul_SkAlphaType, nullptr)
mtkleinbb6c41b2016-03-08 11:31:11 -0800510
Mike Klein0e4041f2018-06-19 16:00:40 -0400511 CPU_CONFIG(a8, kRaster_Backend, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr)
512 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType, nullptr)
513 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType, nullptr)
514
515 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
Brian Osman82ebe042019-01-04 17:03:00 -0500516 auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50),
Mike Klein0e4041f2018-06-19 16:00:40 -0400517 srgb = SkColorSpace::MakeSRGB(),
518 srgbLinear = SkColorSpace::MakeSRGBLinear();
519
520 CPU_CONFIG( f16, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgbLinear)
521 CPU_CONFIG( srgb, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, srgb )
522 CPU_CONFIG( esrgb, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgb )
523 CPU_CONFIG( narrow, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, narrow )
524 CPU_CONFIG(enarrow, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, narrow )
mtkleinbb6a0282014-07-01 08:43:42 -0700525
svaisanenc47635e2016-01-28 06:05:43 -0800526 #undef CPU_CONFIG
Ben Wagner32fa5102017-08-10 21:25:55 -0400527
528 SkDebugf("Unknown config '%s'.\n", config->getTag().c_str());
mtkleinf3723212014-06-25 14:08:00 -0700529}
530
svaisanenc47635e2016-01-28 06:05:43 -0800531// Append all configs that are enabled and supported.
532void create_configs(SkTArray<Config>* configs) {
533 SkCommandLineConfigArray array;
534 ParseConfigs(FLAGS_config, &array);
535 for (int i = 0; i < array.count(); ++i) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400536 create_config(array[i].get(), configs);
svaisanenc47635e2016-01-28 06:05:43 -0800537 }
Ben Wagner32fa5102017-08-10 21:25:55 -0400538
539 // If no just default configs were requested, then we're okay.
540 if (array.count() == 0 || FLAGS_config.count() == 0 ||
Ben Wagner32fa5102017-08-10 21:25:55 -0400541 // Otherwise, make sure that all specified configs have been created.
542 array.count() == configs->count()) {
543 return;
544 }
Ben Wagner32fa5102017-08-10 21:25:55 -0400545 exit(1);
svaisanenc47635e2016-01-28 06:05:43 -0800546}
547
brianosman9f1f6e22016-09-15 08:33:02 -0700548// disable warning : switch statement contains default but no 'case' labels
549#if defined _WIN32
550#pragma warning ( push )
551#pragma warning ( disable : 4065 )
552#endif
553
halcanary96fcdcc2015-08-27 07:41:13 -0700554// If bench is enabled for config, returns a Target* for it, otherwise nullptr.
bsalomonc2553372014-07-22 13:09:05 -0700555static Target* is_enabled(Benchmark* bench, const Config& config) {
556 if (!bench->isSuitableFor(config.backend)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700557 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700558 }
559
reede5ea5002014-09-03 11:54:58 -0700560 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
brianosmanb109b8c2016-06-16 13:03:24 -0700561 config.color, config.alpha, config.colorSpace);
bsalomonc2553372014-07-22 13:09:05 -0700562
halcanary96fcdcc2015-08-27 07:41:13 -0700563 Target* target = nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700564
tomhudsond968a6f2015-03-26 11:28:06 -0700565 switch (config.backend) {
tomhudsond968a6f2015-03-26 11:28:06 -0700566 case Benchmark::kGPU_Backend:
567 target = new GPUTarget(config);
568 break;
tomhudsond968a6f2015-03-26 11:28:06 -0700569 default:
570 target = new Target(config);
571 break;
572 }
bsalomonc2553372014-07-22 13:09:05 -0700573
tomhudsond968a6f2015-03-26 11:28:06 -0700574 if (!target->init(info, bench)) {
bsalomonc2553372014-07-22 13:09:05 -0700575 delete target;
halcanary96fcdcc2015-08-27 07:41:13 -0700576 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700577 }
578 return target;
579}
580
brianosman9f1f6e22016-09-15 08:33:02 -0700581#if defined _WIN32
582#pragma warning ( pop )
583#endif
584
reed42943c82016-09-12 12:01:44 -0700585static bool valid_brd_bench(sk_sp<SkData> encoded, SkColorType colorType, uint32_t sampleSize,
msarettd1227a72016-05-18 06:23:57 -0700586 uint32_t minOutputSize, int* width, int* height) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400587 std::unique_ptr<SkBitmapRegionDecoder> brd(
msarettd1227a72016-05-18 06:23:57 -0700588 SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroidCodec_Strategy));
msarett7f691442015-09-22 11:56:16 -0700589 if (nullptr == brd.get()) {
590 // This is indicates that subset decoding is not supported for a particular image format.
591 return false;
592 }
593
msarett7f691442015-09-22 11:56:16 -0700594 if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize >
595 (uint32_t) brd->height()) {
596 // This indicates that the image is not large enough to decode a
597 // minOutputSize x minOutputSize subset at the given sampleSize.
598 return false;
599 }
600
601 // Set the image width and height. The calling code will use this to choose subsets to decode.
602 *width = brd->width();
603 *height = brd->height();
604 return true;
605}
606
egdaniel3bf92062015-06-26 08:12:46 -0700607static void cleanup_run(Target* target) {
halcanary385fe4d2015-08-26 13:07:48 -0700608 delete target;
egdaniel3bf92062015-06-26 08:12:46 -0700609}
610
Mike Klein88544fb2019-03-20 10:50:33 -0500611static void collect_files(const CommandLineFlags::StringArray& paths,
612 const char* ext,
613 SkTArray<SkString>* list) {
fmalita6519c212016-09-14 08:05:17 -0700614 for (int i = 0; i < paths.count(); ++i) {
615 if (SkStrEndsWith(paths[i], ext)) {
616 list->push_back(SkString(paths[i]));
617 } else {
618 SkOSFile::Iter it(paths[i], ext);
619 SkString path;
620 while (it.next(&path)) {
621 list->push_back(SkOSPath::Join(paths[i], path.c_str()));
622 }
623 }
624 }
625}
626
mtkleine714e752014-07-31 12:13:48 -0700627class BenchmarkStream {
628public:
mtklein92007582014-08-01 07:46:52 -0700629 BenchmarkStream() : fBenches(BenchRegistry::Head())
Hal Canary2362ae72019-10-24 13:40:40 -0400630 , fGMs(skiagm::GMRegistry::Head()) {
fmalita6519c212016-09-14 08:05:17 -0700631 collect_files(FLAGS_skps, ".skp", &fSKPs);
632 collect_files(FLAGS_svgs, ".svg", &fSVGs);
Hal Canary5dfefa22019-10-24 13:52:17 -0400633 collect_files(FLAGS_texttraces, ".trace", &fTextBlobTraces);
mtkleine714e752014-07-31 12:13:48 -0700634
mtklein92007582014-08-01 07:46:52 -0700635 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
636 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
637 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
638 exit(1);
639 }
640
641 for (int i = 0; i < FLAGS_scales.count(); i++) {
642 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
643 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
644 exit(1);
645 }
646 }
robertphillips5b693772014-11-21 06:19:36 -0800647
cdalton63a82852015-06-29 14:06:10 -0700648 if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) {
649 SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]);
joshualitt261c3ad2015-04-27 09:16:57 -0700650 exit(1);
651 }
652
robertphillips5b693772014-11-21 06:19:36 -0800653 if (FLAGS_mpd) {
654 fUseMPDs.push_back() = true;
655 }
mtkleinc751ecb2015-06-15 08:56:38 -0700656 fUseMPDs.push_back() = false;
mtklein95553d92015-03-12 08:24:21 -0700657
msarett95f192d2015-02-13 09:05:41 -0800658 // Prepare the images for decoding
msarett69deca82016-04-29 09:38:40 -0700659 if (!CollectImages(FLAGS_images, &fImages)) {
scroggo86737142016-02-03 12:19:11 -0800660 exit(1);
msarett95f192d2015-02-13 09:05:41 -0800661 }
mtklein95553d92015-03-12 08:24:21 -0700662
msarett95f192d2015-02-13 09:05:41 -0800663 // Choose the candidate color types for image decoding
msarett67cb6662016-06-21 08:49:26 -0700664 fColorTypes.push_back(kN32_SkColorType);
665 if (!FLAGS_simpleCodec) {
666 fColorTypes.push_back(kRGB_565_SkColorType);
667 fColorTypes.push_back(kAlpha_8_SkColorType);
msarett67cb6662016-06-21 08:49:26 -0700668 fColorTypes.push_back(kGray_8_SkColorType);
669 }
mtklein92007582014-08-01 07:46:52 -0700670 }
671
reedca2622b2016-03-18 07:25:55 -0700672 static sk_sp<SkPicture> ReadPicture(const char* path) {
mtkleinfd731ce2014-09-10 12:19:30 -0700673 // Not strictly necessary, as it will be checked again later,
674 // but helps to avoid a lot of pointless work if we're going to skip it.
Mike Klein88544fb2019-03-20 10:50:33 -0500675 if (CommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) {
reedca2622b2016-03-18 07:25:55 -0700676 return nullptr;
mtkleinfd731ce2014-09-10 12:19:30 -0700677 }
678
bungemanf93d7112016-09-16 06:24:20 -0700679 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
680 if (!stream) {
mtkleinfd731ce2014-09-10 12:19:30 -0700681 SkDebugf("Could not read %s.\n", path);
reedca2622b2016-03-18 07:25:55 -0700682 return nullptr;
mtkleinfd731ce2014-09-10 12:19:30 -0700683 }
684
reedca2622b2016-03-18 07:25:55 -0700685 return SkPicture::MakeFromStream(stream.get());
mtkleinfd731ce2014-09-10 12:19:30 -0700686 }
687
fmalita6519c212016-09-14 08:05:17 -0700688 static sk_sp<SkPicture> ReadSVGPicture(const char* path) {
Brian Osman133823d2018-09-19 14:14:15 -0400689 sk_sp<SkData> data(SkData::MakeFromFileName(path));
690 if (!data) {
fmalita6519c212016-09-14 08:05:17 -0700691 SkDebugf("Could not read %s.\n", path);
692 return nullptr;
693 }
694
Hal Canary0f666812018-03-22 15:21:12 -0400695#ifdef SK_XML
Brian Osman133823d2018-09-19 14:14:15 -0400696 SkMemoryStream stream(std::move(data));
fmalitae1baa7c2016-09-14 12:04:30 -0700697 sk_sp<SkSVGDOM> svgDom = SkSVGDOM::MakeFromStream(stream);
fmalita6519c212016-09-14 08:05:17 -0700698 if (!svgDom) {
699 SkDebugf("Could not parse %s.\n", path);
700 return nullptr;
701 }
702
fmalitae1baa7c2016-09-14 12:04:30 -0700703 // Use the intrinsic SVG size if available, otherwise fall back to a default value.
704 static const SkSize kDefaultContainerSize = SkSize::Make(128, 128);
705 if (svgDom->containerSize().isEmpty()) {
706 svgDom->setContainerSize(kDefaultContainerSize);
707 }
708
fmalita6519c212016-09-14 08:05:17 -0700709 SkPictureRecorder recorder;
fmalitae1baa7c2016-09-14 12:04:30 -0700710 svgDom->render(recorder.beginRecording(svgDom->containerSize().width(),
711 svgDom->containerSize().height()));
fmalita6519c212016-09-14 08:05:17 -0700712 return recorder.finishRecordingAsPicture();
Hal Canary0f666812018-03-22 15:21:12 -0400713#else
714 return nullptr;
715#endif // SK_XML
fmalita6519c212016-09-14 08:05:17 -0700716 }
717
mtklein92007582014-08-01 07:46:52 -0700718 Benchmark* next() {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400719 std::unique_ptr<Benchmark> bench;
mtklein65dfd2f2016-02-03 10:40:54 -0800720 do {
721 bench.reset(this->rawNext());
722 if (!bench) {
723 return nullptr;
724 }
Mike Klein88544fb2019-03-20 10:50:33 -0500725 } while (CommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) ||
726 CommandLineFlags::ShouldSkip(FLAGS_benchType, fBenchType));
mtklein18300a32016-03-16 13:53:35 -0700727 return bench.release();
mtklein65dfd2f2016-02-03 10:40:54 -0800728 }
729
730 Benchmark* rawNext() {
mtkleine714e752014-07-31 12:13:48 -0700731 if (fBenches) {
Hal Canary972eba32018-07-30 17:07:07 -0400732 Benchmark* bench = fBenches->get()(nullptr);
mtkleine714e752014-07-31 12:13:48 -0700733 fBenches = fBenches->next();
mtklein92007582014-08-01 07:46:52 -0700734 fSourceType = "bench";
mtkleinfd731ce2014-09-10 12:19:30 -0700735 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700736 return bench;
737 }
mtklein92007582014-08-01 07:46:52 -0700738
mtkleine714e752014-07-31 12:13:48 -0700739 while (fGMs) {
Ben Wagner406ff502019-08-12 16:39:24 -0400740 std::unique_ptr<skiagm::GM> gm = fGMs->get()();
mtkleine714e752014-07-31 12:13:48 -0700741 fGMs = fGMs->next();
mtkleincf5d9c92015-01-23 10:31:45 -0800742 if (gm->runAsBench()) {
mtklein92007582014-08-01 07:46:52 -0700743 fSourceType = "gm";
mtkleinfd731ce2014-09-10 12:19:30 -0700744 fBenchType = "micro";
Ben Wagner406ff502019-08-12 16:39:24 -0400745 return new GMBench(std::move(gm));
mtkleine714e752014-07-31 12:13:48 -0700746 }
747 }
mtklein92007582014-08-01 07:46:52 -0700748
Hal Canary5dfefa22019-10-24 13:52:17 -0400749 while (fCurrentTextBlobTrace < fTextBlobTraces.count()) {
750 SkString path = fTextBlobTraces[fCurrentTextBlobTrace++];
751 SkString basename = SkOSPath::Basename(path.c_str());
752 static constexpr char kEnding[] = ".trace";
753 if (basename.endsWith(kEnding)) {
754 basename.remove(basename.size() - strlen(kEnding), strlen(kEnding));
755 }
756 fSourceType = "texttrace";
757 fBenchType = "micro";
758 return CreateDiffCanvasBench(
759 SkStringPrintf("SkDiffBench-%s", basename.c_str()),
760 [path](){ return SkStream::MakeFromFile(path.c_str()); });
761 }
762
mtkleinfd731ce2014-09-10 12:19:30 -0700763 // First add all .skps as RecordingBenches.
764 while (fCurrentRecording < fSKPs.count()) {
765 const SkString& path = fSKPs[fCurrentRecording++];
reedca2622b2016-03-18 07:25:55 -0700766 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
767 if (!pic) {
mtkleinfd731ce2014-09-10 12:19:30 -0700768 continue;
769 }
770 SkString name = SkOSPath::Basename(path.c_str());
771 fSourceType = "skp";
772 fBenchType = "recording";
Mike Klein88d90712018-01-27 17:30:04 +0000773 fSKPBytes = static_cast<double>(pic->approximateBytesUsed());
774 fSKPOps = pic->approximateOpCount();
Mike Kleina705cb92019-05-14 12:33:40 -0500775 return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh);
mtkleinfd731ce2014-09-10 12:19:30 -0700776 }
777
Mike Reede45ff462017-12-06 10:47:03 -0500778 // Add all .skps as DeserializePictureBenchs.
779 while (fCurrentDeserialPicture < fSKPs.count()) {
780 const SkString& path = fSKPs[fCurrentDeserialPicture++];
781 sk_sp<SkData> data = SkData::MakeFromFileName(path.c_str());
782 if (!data) {
783 continue;
784 }
785 SkString name = SkOSPath::Basename(path.c_str());
786 fSourceType = "skp";
787 fBenchType = "deserial";
Mike Reed7557bbb2017-12-24 19:50:57 -0500788 fSKPBytes = static_cast<double>(data->size());
Mike Klein88d90712018-01-27 17:30:04 +0000789 fSKPOps = 0;
Mike Reede45ff462017-12-06 10:47:03 -0500790 return new DeserializePictureBench(name.c_str(), std::move(data));
791 }
792
mtkleinfd731ce2014-09-10 12:19:30 -0700793 // Then once each for each scale as SKPBenches (playback).
mtklein92007582014-08-01 07:46:52 -0700794 while (fCurrentScale < fScales.count()) {
795 while (fCurrentSKP < fSKPs.count()) {
robertphillips5b693772014-11-21 06:19:36 -0800796 const SkString& path = fSKPs[fCurrentSKP];
reedca2622b2016-03-18 07:25:55 -0700797 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
798 if (!pic) {
robertphillips5b693772014-11-21 06:19:36 -0800799 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700800 continue;
801 }
robertphillips5b693772014-11-21 06:19:36 -0800802
803 while (fCurrentUseMPD < fUseMPDs.count()) {
804 if (FLAGS_bbh) {
805 // The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
806 SkRTreeFactory factory;
807 SkPictureRecorder recorder;
robertphillips5b693772014-11-21 06:19:36 -0800808 pic->playback(recorder.beginRecording(pic->cullRect().width(),
809 pic->cullRect().height(),
mtklein748ca3b2015-01-15 10:56:12 -0800810 &factory,
robertphillipsdda54452016-07-13 13:27:16 -0700811 0));
reedca2622b2016-03-18 07:25:55 -0700812 pic = recorder.finishRecordingAsPicture();
robertphillips5b693772014-11-21 06:19:36 -0800813 }
814 SkString name = SkOSPath::Basename(path.c_str());
815 fSourceType = "skp";
816 fBenchType = "playback";
halcanary385fe4d2015-08-26 13:07:48 -0700817 return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale],
818 fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP);
mtklein20840502014-08-21 15:51:22 -0700819 }
robertphillips5b693772014-11-21 06:19:36 -0800820 fCurrentUseMPD = 0;
821 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700822 }
fmalita6519c212016-09-14 08:05:17 -0700823
824 while (fCurrentSVG++ < fSVGs.count()) {
825 const char* path = fSVGs[fCurrentSVG - 1].c_str();
826 if (sk_sp<SkPicture> pic = ReadSVGPicture(path)) {
827 fSourceType = "svg";
828 fBenchType = "playback";
829 return new SKPBench(SkOSPath::Basename(path).c_str(), pic.get(), fClip,
830 fScales[fCurrentScale], false, FLAGS_loopSKP);
831 }
832 }
833
mtklein92007582014-08-01 07:46:52 -0700834 fCurrentSKP = 0;
fmalita6519c212016-09-14 08:05:17 -0700835 fCurrentSVG = 0;
mtklein92007582014-08-01 07:46:52 -0700836 fCurrentScale++;
837 }
838
joshualitt261c3ad2015-04-27 09:16:57 -0700839 // Now loop over each skp again if we have an animation
cdalton63a82852015-06-29 14:06:10 -0700840 if (fZoomMax != 1.0f && fZoomPeriodMs > 0) {
joshualitt261c3ad2015-04-27 09:16:57 -0700841 while (fCurrentAnimSKP < fSKPs.count()) {
842 const SkString& path = fSKPs[fCurrentAnimSKP];
reedca2622b2016-03-18 07:25:55 -0700843 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
844 if (!pic) {
joshualitt261c3ad2015-04-27 09:16:57 -0700845 fCurrentAnimSKP++;
846 continue;
847 }
848
849 fCurrentAnimSKP++;
850 SkString name = SkOSPath::Basename(path.c_str());
Ben Wagneracf98df2019-07-12 12:51:44 -0400851 sk_sp<SKPAnimationBench::Animation> animation =
852 SKPAnimationBench::MakeZoomAnimation(fZoomMax, fZoomPeriodMs);
853 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, std::move(animation),
halcanary385fe4d2015-08-26 13:07:48 -0700854 FLAGS_loopSKP);
joshualitt261c3ad2015-04-27 09:16:57 -0700855 }
856 }
857
scroggo60869a42015-04-01 12:09:17 -0700858 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) {
scroggo303fa352015-10-05 11:03:34 -0700859 fSourceType = "image";
860 fBenchType = "skcodec";
scroggo60869a42015-04-01 12:09:17 -0700861 const SkString& path = fImages[fCurrentCodec];
Mike Klein88544fb2019-03-20 10:50:33 -0500862 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
mtklein6f0ff912016-01-11 09:04:21 -0800863 continue;
864 }
bungeman38d909e2016-08-02 14:40:46 -0700865 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400866 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
scroggo60869a42015-04-01 12:09:17 -0700867 if (!codec) {
868 // Nothing to time.
msarett9d9725c2015-04-24 11:41:55 -0700869 SkDebugf("Cannot find codec for %s\n", path.c_str());
scroggo60869a42015-04-01 12:09:17 -0700870 continue;
871 }
scroggo21027992015-04-02 13:22:38 -0700872
scroggo60869a42015-04-01 12:09:17 -0700873 while (fCurrentColorType < fColorTypes.count()) {
scroggo21027992015-04-02 13:22:38 -0700874 const SkColorType colorType = fColorTypes[fCurrentColorType];
scroggo21027992015-04-02 13:22:38 -0700875
msarettc7796b92016-01-07 14:20:20 -0800876 SkAlphaType alphaType = codec->getInfo().alphaType();
msarett67cb6662016-06-21 08:49:26 -0700877 if (FLAGS_simpleCodec) {
878 if (kUnpremul_SkAlphaType == alphaType) {
879 alphaType = kPremul_SkAlphaType;
880 }
881
882 fCurrentColorType++;
883 } else {
884 switch (alphaType) {
885 case kOpaque_SkAlphaType:
886 // We only need to test one alpha type (opaque).
msarettc7796b92016-01-07 14:20:20 -0800887 fCurrentColorType++;
msarett67cb6662016-06-21 08:49:26 -0700888 break;
889 case kUnpremul_SkAlphaType:
890 case kPremul_SkAlphaType:
891 if (0 == fCurrentAlphaType) {
892 // Test unpremul first.
893 alphaType = kUnpremul_SkAlphaType;
894 fCurrentAlphaType++;
895 } else {
896 // Test premul.
897 alphaType = kPremul_SkAlphaType;
898 fCurrentAlphaType = 0;
899 fCurrentColorType++;
900 }
901 break;
902 default:
903 SkASSERT(false);
904 fCurrentColorType++;
905 break;
906 }
scroggo21027992015-04-02 13:22:38 -0700907 }
908
msarettc7796b92016-01-07 14:20:20 -0800909 // Make sure we can decode to this color type and alpha type.
910 SkImageInfo info =
911 codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType);
scroggo21027992015-04-02 13:22:38 -0700912 const size_t rowBytes = info.minRowBytes();
Mike Reedf0ffb892017-10-03 14:47:21 -0400913 SkAutoMalloc storage(info.computeByteSize(rowBytes));
scroggo21027992015-04-02 13:22:38 -0700914
scroggoeb602a52015-07-09 08:16:03 -0700915 const SkCodec::Result result = codec->getPixels(
Leon Scroggins571b30f2017-07-11 17:35:31 +0000916 info, storage.get(), rowBytes);
scroggo60869a42015-04-01 12:09:17 -0700917 switch (result) {
scroggoeb602a52015-07-09 08:16:03 -0700918 case SkCodec::kSuccess:
919 case SkCodec::kIncompleteInput:
scroggo60869a42015-04-01 12:09:17 -0700920 return new CodecBench(SkOSPath::Basename(path.c_str()),
bungeman38d909e2016-08-02 14:40:46 -0700921 encoded.get(), colorType, alphaType);
scroggoeb602a52015-07-09 08:16:03 -0700922 case SkCodec::kInvalidConversion:
scroggo60869a42015-04-01 12:09:17 -0700923 // This is okay. Not all conversions are valid.
924 break;
scroggo60869a42015-04-01 12:09:17 -0700925 default:
926 // This represents some sort of failure.
927 SkASSERT(false);
928 break;
929 }
930 }
931 fCurrentColorType = 0;
932 }
933
msarett84451022016-02-11 06:45:51 -0800934 // Run AndroidCodecBenches
935 const int sampleSizes[] = { 2, 4, 8 };
936 for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) {
937 fSourceType = "image";
938 fBenchType = "skandroidcodec";
939
940 const SkString& path = fImages[fCurrentAndroidCodec];
Mike Klein88544fb2019-03-20 10:50:33 -0500941 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
msarett84451022016-02-11 06:45:51 -0800942 continue;
943 }
bungeman38d909e2016-08-02 14:40:46 -0700944 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400945 std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
msarett84451022016-02-11 06:45:51 -0800946 if (!codec) {
947 // Nothing to time.
948 SkDebugf("Cannot find codec for %s\n", path.c_str());
949 continue;
950 }
951
952 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) {
953 int sampleSize = sampleSizes[fCurrentSampleSize];
954 fCurrentSampleSize++;
Brian Osman788b9162020-02-07 10:36:46 -0500955 if (10 * sampleSize > std::min(codec->getInfo().width(), codec->getInfo().height())) {
msarett84451022016-02-11 06:45:51 -0800956 // Avoid benchmarking scaled decodes of already small images.
957 break;
958 }
959
bungeman38d909e2016-08-02 14:40:46 -0700960 return new AndroidCodecBench(SkOSPath::Basename(path.c_str()),
961 encoded.get(), sampleSize);
msarett84451022016-02-11 06:45:51 -0800962 }
963 fCurrentSampleSize = 0;
964 }
965
msarett7f691442015-09-22 11:56:16 -0700966 // Run the BRDBenches
msarett7f691442015-09-22 11:56:16 -0700967 // We intend to create benchmarks that model the use cases in
968 // android/libraries/social/tiledimage. In this library, an image is decoded in 512x512
969 // tiles. The image can be translated freely, so the location of a tile may be anywhere in
970 // the image. For that reason, we will benchmark decodes in five representative locations
971 // in the image. Additionally, this use case utilizes power of two scaling, so we will
972 // test on power of two sample sizes. The output tile is always 512x512, so, when a
973 // sampleSize is used, the size of the subset that is decoded is always
974 // (sampleSize*512)x(sampleSize*512).
975 // There are a few good reasons to only test on power of two sample sizes at this time:
msarett7f691442015-09-22 11:56:16 -0700976 // All use cases we are aware of only scale by powers of two.
977 // PNG decodes use the indicated sampling strategy regardless of the sample size, so
978 // these tests are sufficient to provide good coverage of our scaling options.
msarett84451022016-02-11 06:45:51 -0800979 const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 };
msarett7f691442015-09-22 11:56:16 -0700980 const uint32_t minOutputSize = 512;
mtklein6f0ff912016-01-11 09:04:21 -0800981 for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) {
msarettd1227a72016-05-18 06:23:57 -0700982 fSourceType = "image";
983 fBenchType = "BRD";
984
mtklein6f0ff912016-01-11 09:04:21 -0800985 const SkString& path = fImages[fCurrentBRDImage];
Mike Klein88544fb2019-03-20 10:50:33 -0500986 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
mtklein6f0ff912016-01-11 09:04:21 -0800987 continue;
988 }
scroggo860e8a62015-10-15 07:51:28 -0700989
msarettd1227a72016-05-18 06:23:57 -0700990 while (fCurrentColorType < fColorTypes.count()) {
991 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) {
992 while (fCurrentSubsetType <= kLastSingle_SubsetType) {
scroggo860e8a62015-10-15 07:51:28 -0700993
bungeman38d909e2016-08-02 14:40:46 -0700994 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarettd1227a72016-05-18 06:23:57 -0700995 const SkColorType colorType = fColorTypes[fCurrentColorType];
996 uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize];
997 int currentSubsetType = fCurrentSubsetType++;
scroggo860e8a62015-10-15 07:51:28 -0700998
msarettd1227a72016-05-18 06:23:57 -0700999 int width = 0;
1000 int height = 0;
reed42943c82016-09-12 12:01:44 -07001001 if (!valid_brd_bench(encoded, colorType, sampleSize, minOutputSize,
msarettd1227a72016-05-18 06:23:57 -07001002 &width, &height)) {
1003 break;
msarett7f691442015-09-22 11:56:16 -07001004 }
msarettd1227a72016-05-18 06:23:57 -07001005
1006 SkString basename = SkOSPath::Basename(path.c_str());
1007 SkIRect subset;
1008 const uint32_t subsetSize = sampleSize * minOutputSize;
1009 switch (currentSubsetType) {
1010 case kTopLeft_SubsetType:
1011 basename.append("_TopLeft");
1012 subset = SkIRect::MakeXYWH(0, 0, subsetSize, subsetSize);
1013 break;
1014 case kTopRight_SubsetType:
1015 basename.append("_TopRight");
1016 subset = SkIRect::MakeXYWH(width - subsetSize, 0, subsetSize,
1017 subsetSize);
1018 break;
1019 case kMiddle_SubsetType:
1020 basename.append("_Middle");
1021 subset = SkIRect::MakeXYWH((width - subsetSize) / 2,
1022 (height - subsetSize) / 2, subsetSize, subsetSize);
1023 break;
1024 case kBottomLeft_SubsetType:
1025 basename.append("_BottomLeft");
1026 subset = SkIRect::MakeXYWH(0, height - subsetSize, subsetSize,
1027 subsetSize);
1028 break;
1029 case kBottomRight_SubsetType:
1030 basename.append("_BottomRight");
1031 subset = SkIRect::MakeXYWH(width - subsetSize,
1032 height - subsetSize, subsetSize, subsetSize);
1033 break;
1034 default:
1035 SkASSERT(false);
1036 }
1037
1038 return new BitmapRegionDecoderBench(basename.c_str(), encoded.get(),
1039 colorType, sampleSize, subset);
msarett7f691442015-09-22 11:56:16 -07001040 }
msarettd1227a72016-05-18 06:23:57 -07001041 fCurrentSubsetType = 0;
1042 fCurrentSampleSize++;
msarett7f691442015-09-22 11:56:16 -07001043 }
msarettd1227a72016-05-18 06:23:57 -07001044 fCurrentSampleSize = 0;
1045 fCurrentColorType++;
msarett7f691442015-09-22 11:56:16 -07001046 }
msarettd1227a72016-05-18 06:23:57 -07001047 fCurrentColorType = 0;
msarett7f691442015-09-22 11:56:16 -07001048 }
1049
halcanary96fcdcc2015-08-27 07:41:13 -07001050 return nullptr;
mtkleine714e752014-07-31 12:13:48 -07001051 }
mtklein92007582014-08-01 07:46:52 -07001052
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001053 void fillCurrentOptions(NanoJSONResultsWriter& log) const {
1054 log.appendString("source_type", fSourceType);
1055 log.appendString("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -07001056 if (0 == strcmp(fSourceType, "skp")) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001057 log.appendString("clip",
mtklein92007582014-08-01 07:46:52 -07001058 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
1059 fClip.fRight, fClip.fBottom).c_str());
djsollenf2b340f2016-01-29 08:51:04 -08001060 SkASSERT_RELEASE(fCurrentScale < fScales.count()); // debugging paranoia
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001061 log.appendString("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
robertphillips5b693772014-11-21 06:19:36 -08001062 if (fCurrentUseMPD > 0) {
1063 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001064 log.appendString("multi_picture_draw",
1065 fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
robertphillips5b693772014-11-21 06:19:36 -08001066 }
mtklein92007582014-08-01 07:46:52 -07001067 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001068 }
1069
1070 void fillCurrentMetrics(NanoJSONResultsWriter& log) const {
mtklein051e56d2014-12-04 08:46:51 -08001071 if (0 == strcmp(fBenchType, "recording")) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001072 log.appendMetric("bytes", fSKPBytes);
1073 log.appendMetric("ops", fSKPOps);
mtklein051e56d2014-12-04 08:46:51 -08001074 }
mtklein92007582014-08-01 07:46:52 -07001075 }
1076
mtkleine714e752014-07-31 12:13:48 -07001077private:
msarettb23e6aa2015-06-09 13:56:10 -07001078 enum SubsetType {
1079 kTopLeft_SubsetType = 0,
1080 kTopRight_SubsetType = 1,
msarettab80e352015-06-17 10:28:22 -07001081 kMiddle_SubsetType = 2,
1082 kBottomLeft_SubsetType = 3,
1083 kBottomRight_SubsetType = 4,
1084 kTranslate_SubsetType = 5,
1085 kZoom_SubsetType = 6,
msarett7f691442015-09-22 11:56:16 -07001086 kLast_SubsetType = kZoom_SubsetType,
1087 kLastSingle_SubsetType = kBottomRight_SubsetType,
msarettb23e6aa2015-06-09 13:56:10 -07001088 };
1089
mtkleine714e752014-07-31 12:13:48 -07001090 const BenchRegistry* fBenches;
1091 const skiagm::GMRegistry* fGMs;
mtklein92007582014-08-01 07:46:52 -07001092 SkIRect fClip;
1093 SkTArray<SkScalar> fScales;
1094 SkTArray<SkString> fSKPs;
fmalita6519c212016-09-14 08:05:17 -07001095 SkTArray<SkString> fSVGs;
Hal Canary5dfefa22019-10-24 13:52:17 -04001096 SkTArray<SkString> fTextBlobTraces;
robertphillips5b693772014-11-21 06:19:36 -08001097 SkTArray<bool> fUseMPDs;
msarett95f192d2015-02-13 09:05:41 -08001098 SkTArray<SkString> fImages;
msarett74deb982015-10-20 16:45:56 -07001099 SkTArray<SkColorType, true> fColorTypes;
cdalton63a82852015-06-29 14:06:10 -07001100 SkScalar fZoomMax;
1101 double fZoomPeriodMs;
mtklein92007582014-08-01 07:46:52 -07001102
Mike Klein88d90712018-01-27 17:30:04 +00001103 double fSKPBytes, fSKPOps;
mtklein051e56d2014-12-04 08:46:51 -08001104
mtkleinfd731ce2014-09-10 12:19:30 -07001105 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
1106 const char* fBenchType; // How we bench it: micro, recording, playback, ...
Hal Canary2362ae72019-10-24 13:40:40 -04001107 int fCurrentRecording = 0;
1108 int fCurrentDeserialPicture = 0;
1109 int fCurrentScale = 0;
1110 int fCurrentSKP = 0;
1111 int fCurrentSVG = 0;
Hal Canary5dfefa22019-10-24 13:52:17 -04001112 int fCurrentTextBlobTrace = 0;
Hal Canary2362ae72019-10-24 13:40:40 -04001113 int fCurrentUseMPD = 0;
1114 int fCurrentCodec = 0;
1115 int fCurrentAndroidCodec = 0;
1116 int fCurrentBRDImage = 0;
1117 int fCurrentColorType = 0;
1118 int fCurrentAlphaType = 0;
1119 int fCurrentSubsetType = 0;
1120 int fCurrentSampleSize = 0;
1121 int fCurrentAnimSKP = 0;
mtkleine714e752014-07-31 12:13:48 -07001122};
1123
msarettc149f0e2016-01-04 11:35:43 -08001124// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1125// This prints something every once in a while so that it knows we're still working.
1126static void start_keepalive() {
Mike Klein03141d22017-10-30 11:57:15 -04001127 static std::thread* intentionallyLeaked = new std::thread([]{
1128 for (;;) {
1129 static const int kSec = 1200;
1130 #if defined(SK_BUILD_FOR_WIN)
1131 Sleep(kSec * 1000);
1132 #else
1133 sleep(kSec);
1134 #endif
1135 SkDebugf("\nBenchmarks still running...\n");
msarettc149f0e2016-01-04 11:35:43 -08001136 }
Mike Klein03141d22017-10-30 11:57:15 -04001137 });
1138 (void)intentionallyLeaked;
msarettc149f0e2016-01-04 11:35:43 -08001139}
1140
Mike Kleinbe28ee22017-02-06 12:46:20 -05001141int main(int argc, char** argv) {
Mike Klein88544fb2019-03-20 10:50:33 -05001142 CommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001143
Brian Osmanbc8150f2017-07-24 11:38:01 -04001144 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001145
Mike Kleinadacaef2017-02-06 09:26:14 -05001146#if defined(SK_BUILD_FOR_IOS)
1147 cd_Documents();
1148#endif
jcgregorio3b27ade2014-11-13 08:06:40 -08001149 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -07001150 SkAutoGraphics ag;
mtkleincc29d262015-07-09 10:04:56 -07001151 SkTaskGroup::Enabler enabled(FLAGS_threads);
mtkleinf3723212014-06-25 14:08:00 -07001152
Chris Dalton040238b2017-12-18 14:22:34 -07001153 SetCtxOptionsFromCommonFlags(&grContextOpts);
krajcevski69a55602014-08-13 10:46:31 -07001154
bsalomon6eb03cc2014-08-07 14:28:50 -07001155 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -07001156 FLAGS_samples = 1;
1157 FLAGS_gpuFrameLag = 0;
1158 }
1159
bsalomon6eb03cc2014-08-07 14:28:50 -07001160 if (!FLAGS_writePath.isEmpty()) {
1161 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
1162 if (!sk_mkdir(FLAGS_writePath[0])) {
1163 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
halcanary96fcdcc2015-08-27 07:41:13 -07001164 FLAGS_writePath.set(0, nullptr);
bsalomon6eb03cc2014-08-07 14:28:50 -07001165 }
1166 }
1167
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001168 std::unique_ptr<SkWStream> logStream(new SkNullWStream);
mtklein60317d0f2014-07-14 11:30:37 -07001169 if (!FLAGS_outResultsFile.isEmpty()) {
mtklein53520152016-01-20 09:53:59 -08001170#if defined(SK_RELEASE)
Chris Dalton2e1381e2019-10-23 14:35:19 -06001171 // SkJSONWriter uses a 32k in-memory cache, so it only flushes occasionally and is well
1172 // equipped for a stream that re-opens, appends, and closes the file on every write.
1173 logStream.reset(new NanoFILEAppendAndCloseStream(FLAGS_outResultsFile[0]));
mtklein53520152016-01-20 09:53:59 -08001174#else
1175 SkDebugf("I'm ignoring --outResultsFile because this is a Debug build.");
1176 return 1;
1177#endif
mtklein60317d0f2014-07-14 11:30:37 -07001178 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001179 NanoJSONResultsWriter log(logStream.get(), SkJSONWriter::Mode::kPretty);
1180 log.beginObject(); // root
mtklein1915b622014-08-20 11:45:00 -07001181
1182 if (1 == FLAGS_properties.count() % 2) {
1183 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
1184 return 1;
1185 }
1186 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001187 log.appendString(FLAGS_properties[i-1], FLAGS_properties[i]);
mtklein1915b622014-08-20 11:45:00 -07001188 }
jcgregoriobf5e5232014-07-17 13:14:16 -07001189
1190 if (1 == FLAGS_key.count() % 2) {
1191 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
1192 return 1;
1193 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001194 if (FLAGS_key.count()) {
1195 log.beginObject("key");
1196 for (int i = 1; i < FLAGS_key.count(); i += 2) {
1197 log.appendString(FLAGS_key[i - 1], FLAGS_key[i]);
1198 }
1199 log.endObject(); // key
mtklein94e51562014-08-19 12:41:53 -07001200 }
mtklein60317d0f2014-07-14 11:30:37 -07001201
mtkleinf3723212014-06-25 14:08:00 -07001202 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -07001203 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -04001204
cdaltone1b89582015-06-25 19:17:08 -07001205 SkTArray<double> samples;
mtkleinbb6a0282014-07-01 08:43:42 -07001206
bsalomon6eb03cc2014-08-07 14:28:50 -07001207 if (kAutoTuneLoops != FLAGS_loops) {
1208 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleinf3723212014-06-25 14:08:00 -07001209 } else if (FLAGS_quiet) {
mtklein66cfcff2015-12-04 06:35:30 -08001210 SkDebugf("! -> high variance, ? -> moderate variance\n");
1211 SkDebugf(" micros \tbench\n");
mtkleinbbba1682015-10-28 11:36:30 -07001212 } else if (FLAGS_ms) {
cdaltone1b89582015-06-25 19:17:08 -07001213 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n");
mtkleinf3723212014-06-25 14:08:00 -07001214 } else {
mtkleind75c4662015-04-30 07:11:22 -07001215 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
qiankun.miao8247ec32014-09-09 19:24:36 -07001216 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -07001217 }
1218
svaisanenc47635e2016-01-28 06:05:43 -08001219 SkTArray<Config> configs;
bsalomonc2553372014-07-22 13:09:05 -07001220 create_configs(&configs);
1221
msarettc149f0e2016-01-04 11:35:43 -08001222 if (FLAGS_keepAlive) {
1223 start_keepalive();
1224 }
1225
Mike Klein03fa5d42019-03-22 11:39:09 -05001226 SetAnalyticAAFromCommonFlags();
liyuqian38911a72016-10-04 11:23:22 -07001227
Mike Klein2a57e792020-01-14 12:47:52 -06001228 if (FLAGS_forceRasterPipeline) { gSkForceRasterPipelineBlitter = true; }
Mike Kleinea4459d2020-01-16 13:05:04 -06001229 if (FLAGS_skvm) { gUseSkVMBlitter = gSkVMJITViaDylib = true; }
Yuqian Li550148b2017-01-13 10:13:13 -05001230
mtkleine070c2b2014-10-14 08:40:43 -07001231 int runs = 0;
mtklein92007582014-08-01 07:46:52 -07001232 BenchmarkStream benchStream;
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001233 log.beginObject("results");
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001234 AutoreleasePool pool;
mtklein92007582014-08-01 07:46:52 -07001235 while (Benchmark* b = benchStream.next()) {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001236 std::unique_ptr<Benchmark> bench(b);
Mike Klein88544fb2019-03-20 10:50:33 -05001237 if (CommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -07001238 continue;
1239 }
1240
svaisanenc47635e2016-01-28 06:05:43 -08001241 if (!configs.empty()) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001242 log.beginBench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
joshualitt8a6697a2015-09-30 12:11:07 -07001243 bench->delayedSetup();
jcgregoriobf5e5232014-07-17 13:14:16 -07001244 }
egdaniel3bf92062015-06-26 08:12:46 -07001245 for (int i = 0; i < configs.count(); ++i) {
1246 Target* target = is_enabled(b, configs[i]);
1247 if (!target) {
1248 continue;
1249 }
mtkleinf3723212014-06-25 14:08:00 -07001250
halcanary96fcdcc2015-08-27 07:41:13 -07001251 // During HWUI output this canvas may be nullptr.
egdaniel3bf92062015-06-26 08:12:46 -07001252 SkCanvas* canvas = target->getCanvas();
svaisanenc47635e2016-01-28 06:05:43 -08001253 const char* config = target->config.name.c_str();
egdaniel3bf92062015-06-26 08:12:46 -07001254
brianosman7a5ada82016-02-08 13:49:12 -08001255 if (FLAGS_pre_log || FLAGS_dryRun) {
benjaminwagner8d61f0d2016-01-25 13:02:40 -08001256 SkDebugf("Running %s\t%s\n"
1257 , bench->getUniqueName()
1258 , config);
brianosman7a5ada82016-02-08 13:49:12 -08001259 if (FLAGS_dryRun) {
1260 continue;
1261 }
benjaminwagner8d61f0d2016-01-25 13:02:40 -08001262 }
1263
Mike Kleinee254232019-03-28 08:32:14 -05001264 if (FLAGS_purgeBetweenBenches) {
1265 SkGraphics::PurgeAllCaches();
1266 }
1267
Brian Osman5ad87aa2017-09-08 16:05:23 -04001268 TRACE_EVENT2("skia", "Benchmark", "name", TRACE_STR_COPY(bench->getUniqueName()),
1269 "config", TRACE_STR_COPY(config));
Brian Osmanc3cdef52017-08-31 14:09:22 -04001270
egdaniel3bf92062015-06-26 08:12:46 -07001271 target->setup();
robertphillips5b693772014-11-21 06:19:36 -08001272 bench->perCanvasPreDraw(canvas);
1273
cdaltone1b89582015-06-25 19:17:08 -07001274 int maxFrameLag;
mtkleina1ebeb22015-10-01 09:43:39 -07001275 int loops = target->needsFrameTiming(&maxFrameLag)
egdaniel3bf92062015-06-26 08:12:46 -07001276 ? setup_gpu_bench(target, bench.get(), maxFrameLag)
1277 : setup_cpu_bench(overhead, target, bench.get());
cdaltone1b89582015-06-25 19:17:08 -07001278
Leon Scroggins IIIb30d1132017-10-02 09:48:15 -04001279 if (kFailedLoops == loops) {
1280 // Can't be timed. A warning note has already been printed.
1281 cleanup_run(target);
1282 continue;
1283 }
1284
Yuqian Li3528eb32017-09-21 13:23:49 -04001285 if (runs == 0 && FLAGS_ms < 1000) {
1286 // Run the first bench for 1000ms to warm up the nanobench if FLAGS_ms < 1000.
1287 // Otherwise, the first few benches' measurements will be inaccurate.
1288 auto stop = now_ms() + 1000;
1289 do {
1290 time(loops, bench.get(), target);
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001291 pool.drain();
Yuqian Li3528eb32017-09-21 13:23:49 -04001292 } while (now_ms() < stop);
1293 }
1294
mtkleinbbba1682015-10-28 11:36:30 -07001295 if (FLAGS_ms) {
1296 samples.reset();
1297 auto stop = now_ms() + FLAGS_ms;
1298 do {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001299 samples.push_back(time(loops, bench.get(), target) / loops);
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001300 pool.drain();
mtkleinbbba1682015-10-28 11:36:30 -07001301 } while (now_ms() < stop);
1302 } else {
cdaltone1b89582015-06-25 19:17:08 -07001303 samples.reset(FLAGS_samples);
1304 for (int s = 0; s < FLAGS_samples; s++) {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001305 samples[s] = time(loops, bench.get(), target) / loops;
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001306 pool.drain();
cdaltone1b89582015-06-25 19:17:08 -07001307 }
cdaltone1b89582015-06-25 19:17:08 -07001308 }
mtkleinf3723212014-06-25 14:08:00 -07001309
Mike Kleinfec9b902019-05-31 10:03:07 -05001310 // Scale each result to the benchmark's own units, time/unit.
1311 for (double& sample : samples) {
1312 sample *= (1.0 / bench->getUnits());
1313 }
1314
joshualitte45c81c2015-12-02 09:05:37 -08001315 SkTArray<SkString> keys;
1316 SkTArray<double> values;
1317 bool gpuStatsDump = FLAGS_gpuStatsDump && Benchmark::kGPU_Backend == configs[i].backend;
1318 if (gpuStatsDump) {
1319 // TODO cache stats
1320 bench->getGpuStats(canvas, &keys, &values);
1321 }
joshualitte45c81c2015-12-02 09:05:37 -08001322
robertphillips5b693772014-11-21 06:19:36 -08001323 bench->perCanvasPostDraw(canvas);
1324
egdaniel3bf92062015-06-26 08:12:46 -07001325 if (Benchmark::kNonRendering_Backend != target->config.backend &&
tomhudsond968a6f2015-03-26 11:28:06 -07001326 !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -07001327 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -07001328 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -07001329 pngFilename.append(".png");
egdaniel3bf92062015-06-26 08:12:46 -07001330 write_canvas_png(target, pngFilename);
bsalomon6eb03cc2014-08-07 14:28:50 -07001331 }
1332
Mike Klein512a2442018-09-27 10:44:56 -04001333 // Building stats.plot often shows up in profiles,
1334 // so skip building it when we're not going to print it anyway.
1335 const bool want_plot = !FLAGS_quiet;
1336
1337 Stats stats(samples, want_plot);
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001338 log.beginObject(config);
1339
1340 log.beginObject("options");
1341 log.appendString("name", bench->getName());
1342 benchStream.fillCurrentOptions(log);
1343 target->fillOptions(log);
1344 log.endObject(); // options
1345
1346 // Metrics
1347 log.appendMetric("min_ms", stats.min);
1348 log.beginArray("samples");
1349 for (double sample : samples) {
1350 log.appendDoubleDigits(sample, 16);
1351 }
1352 log.endArray(); // samples
1353 benchStream.fillCurrentMetrics(log);
joshualitte45c81c2015-12-02 09:05:37 -08001354 if (gpuStatsDump) {
1355 // dump to json, only SKPBench currently returns valid keys / values
1356 SkASSERT(keys.count() == values.count());
1357 for (int i = 0; i < keys.count(); i++) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001358 log.appendMetric(keys[i].c_str(), values[i]);
joshualitte45c81c2015-12-02 09:05:37 -08001359 }
1360 }
joshualitte45c81c2015-12-02 09:05:37 -08001361
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001362 log.endObject(); // config
1363
mtkleine070c2b2014-10-14 08:40:43 -07001364 if (runs++ % FLAGS_flushEvery == 0) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001365 log.flush();
mtkleine070c2b2014-10-14 08:40:43 -07001366 }
mtklein60317d0f2014-07-14 11:30:37 -07001367
bsalomon6eb03cc2014-08-07 14:28:50 -07001368 if (kAutoTuneLoops != FLAGS_loops) {
egdaniel3bf92062015-06-26 08:12:46 -07001369 if (configs.count() == 1) {
mtkleina189ccd2014-07-14 12:28:47 -07001370 config = ""; // Only print the config if we run the same bench on more than one.
1371 }
mtkleind75c4662015-04-30 07:11:22 -07001372 SkDebugf("%4d/%-4dMB\t%s\t%s\n"
1373 , sk_tools::getCurrResidentSetSizeMB()
1374 , sk_tools::getMaxResidentSetSizeMB()
mtklein53d25622014-09-18 07:39:42 -07001375 , bench->getUniqueName()
1376 , config);
mtkleinf3723212014-06-25 14:08:00 -07001377 } else if (FLAGS_quiet) {
mtklein66cfcff2015-12-04 06:35:30 -08001378 const char* mark = " ";
Hal Canarye99e8da2019-01-14 16:34:50 -05001379 const double stddev_percent =
1380 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
mtklein66cfcff2015-12-04 06:35:30 -08001381 if (stddev_percent > 5) mark = "?";
1382 if (stddev_percent > 10) mark = "!";
1383
1384 SkDebugf("%10.2f %s\t%s\t%s\n",
1385 stats.median*1e3, mark, bench->getUniqueName(), config);
Mike Reedc665e5b2017-07-04 22:56:06 -04001386 } else if (FLAGS_csv) {
Hal Canarye99e8da2019-01-14 16:34:50 -05001387 const double stddev_percent =
1388 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
Mike Reedc665e5b2017-07-04 22:56:06 -04001389 SkDebugf("%g,%g,%g,%g,%g,%s,%s\n"
1390 , stats.min
1391 , stats.median
1392 , stats.mean
1393 , stats.max
1394 , stddev_percent
1395 , config
1396 , bench->getUniqueName()
1397 );
1398 } else {
1399 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 -05001400 const double stddev_percent =
1401 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
Mike Reedc665e5b2017-07-04 22:56:06 -04001402 SkDebugf(format
mtkleind75c4662015-04-30 07:11:22 -07001403 , sk_tools::getCurrResidentSetSizeMB()
1404 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -07001405 , loops
mtklein55b0ffc2014-07-17 08:38:23 -07001406 , HUMANIZE(stats.min)
1407 , HUMANIZE(stats.median)
1408 , HUMANIZE(stats.mean)
1409 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -07001410 , stddev_percent
mtkleinbbba1682015-10-28 11:36:30 -07001411 , FLAGS_ms ? to_string(samples.count()).c_str() : stats.plot.c_str()
mtkleinf3723212014-06-25 14:08:00 -07001412 , config
mtklein96289052014-09-10 12:05:59 -07001413 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -07001414 );
1415 }
joshualitte45c81c2015-12-02 09:05:37 -08001416
joshualitte45c81c2015-12-02 09:05:37 -08001417 if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -04001418 target->dumpStats();
bsalomon06cddec2014-10-24 10:40:50 -07001419 }
joshualitte45c81c2015-12-02 09:05:37 -08001420
cdalton2c56ba52015-06-26 13:32:53 -07001421 if (FLAGS_verbose) {
1422 SkDebugf("Samples: ");
1423 for (int i = 0; i < samples.count(); i++) {
1424 SkDebugf("%s ", HUMANIZE(samples[i]));
1425 }
1426 SkDebugf("%s\n", bench->getUniqueName());
1427 }
egdaniel3bf92062015-06-26 08:12:46 -07001428 cleanup_run(target);
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001429 pool.drain();
mtkleinf3723212014-06-25 14:08:00 -07001430 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001431 if (!configs.empty()) {
1432 log.endBench();
1433 }
mtkleinf3723212014-06-25 14:08:00 -07001434 }
1435
Herb Derby5a523fe2017-01-26 16:48:28 -05001436 SkGraphics::PurgeAllCaches();
1437
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001438 log.beginBench("memory_usage", 0, 0);
1439 log.beginObject("meta"); // config
1440 log.appendS32("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
1441 log.endObject(); // config
1442 log.endBench();
1443
1444 log.endObject(); // results
1445 log.endObject(); // root
1446 log.flush();
mtkleine1091452014-12-04 10:47:02 -08001447
mtkleinf3723212014-06-25 14:08:00 -07001448 return 0;
1449}