blob: 78b556d3c28722909eef5d0f6765c574fb284928 [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "bench/CodecBench.h"
15#include "bench/CodecBenchPriv.h"
16#include "bench/GMBench.h"
17#include "bench/RecordingBench.h"
18#include "bench/ResultsWriter.h"
19#include "bench/SKPAnimationBench.h"
20#include "bench/SKPBench.h"
Hal Canary5dfefa22019-10-24 13:52:17 -040021#include "bench/SkGlyphCacheBench.h"
Brian Osman68870aa2020-07-08 14:12:43 -040022#include "bench/SkSLBench.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "include/codec/SkAndroidCodec.h"
24#include "include/codec/SkCodec.h"
25#include "include/core/SkCanvas.h"
26#include "include/core/SkData.h"
27#include "include/core/SkGraphics.h"
28#include "include/core/SkPictureRecorder.h"
29#include "include/core/SkString.h"
30#include "include/core/SkSurface.h"
Ben Wagneracf98df2019-07-12 12:51:44 -040031#include "include/core/SkTime.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050032#include "src/core/SkAutoMalloc.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050033#include "src/core/SkColorSpacePriv.h"
Ben Wagnerab6eefe2019-05-20 11:02:49 -040034#include "src/core/SkLeanWindows.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050035#include "src/core/SkOSFile.h"
36#include "src/core/SkTaskGroup.h"
37#include "src/core/SkTraceEvent.h"
38#include "src/utils/SkJSONWriter.h"
39#include "src/utils/SkOSPath.h"
Jim Van Verth8a9a3712019-05-31 10:49:12 -040040#include "tools/AutoreleasePool.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050041#include "tools/CrashHandler.h"
42#include "tools/ProcStats.h"
43#include "tools/Stats.h"
44#include "tools/flags/CommonFlags.h"
45#include "tools/flags/CommonFlagsConfig.h"
46#include "tools/ios_utils.h"
47#include "tools/trace/EventTracingPriv.h"
48#include "tools/trace/SkDebugfTracer.h"
mtkleinf3723212014-06-25 14:08:00 -070049
Hal Canary0f666812018-03-22 15:21:12 -040050#ifdef SK_XML
Florin Malitab3418102020-10-15 18:10:29 -040051#include "modules/svg/include/SkSVGDOM.h"
Hal Canary0f666812018-03-22 15:21:12 -040052#endif // SK_XML
53
Leon Scroggins III87caae62020-05-04 10:02:45 -040054#ifdef SK_ENABLE_ANDROID_UTILS
55#include "bench/BitmapRegionDecoderBench.h"
56#include "client_utils/android/BitmapRegionDecoder.h"
57#endif
58
Adlai Holler684838f2020-05-12 10:41:04 -040059#include <cinttypes>
bungeman60e0fee2015-08-26 05:15:46 -070060#include <stdlib.h>
John Stilesfbd050b2020-08-03 13:21:46 -040061#include <memory>
Mike Klein03141d22017-10-30 11:57:15 -040062#include <thread>
bungeman60e0fee2015-08-26 05:15:46 -070063
Mike Reedc928fe22017-06-05 10:20:31 -040064extern bool gSkForceRasterPipelineBlitter;
Mike Klein2a57e792020-01-14 12:47:52 -060065extern bool gUseSkVMBlitter;
Mike Klein813e8cc2020-08-05 09:33:38 -050066extern bool gSkVMAllowJIT;
Mike Kleinea4459d2020-01-16 13:05:04 -060067extern bool gSkVMJITViaDylib;
Mike Reedc928fe22017-06-05 10:20:31 -040068
Mike Klein8f11d4d2018-01-24 12:42:55 -050069#ifndef SK_BUILD_FOR_WIN
scroggo38ce0a72016-01-07 07:28:47 -080070 #include <unistd.h>
Brian Salomon032aaae2018-03-23 16:10:36 -040071
scroggo38ce0a72016-01-07 07:28:47 -080072#endif
73
Robert Phillips00f78de2020-07-01 16:09:43 -040074#include "include/gpu/GrDirectContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050075#include "src/gpu/GrCaps.h"
Adlai Hollera0693042020-10-14 11:23:11 -040076#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050077#include "src/gpu/SkGr.h"
78#include "src/gpu/gl/GrGLDefines.h"
79#include "src/gpu/gl/GrGLGpu.h"
80#include "src/gpu/gl/GrGLUtil.h"
81#include "tools/gpu/GrContextFactory.h"
Brian Salomon032aaae2018-03-23 16:10:36 -040082
Brian Osmanc7ad40f2018-05-31 14:27:17 -040083using sk_gpu_test::ContextInfo;
84using sk_gpu_test::GrContextFactory;
85using sk_gpu_test::TestContext;
Brian Salomon032aaae2018-03-23 16:10:36 -040086
Brian Osmanc7ad40f2018-05-31 14:27:17 -040087GrContextOptions grContextOpts;
bsalomon682c2692015-05-22 14:01:46 -070088
reed53249782014-10-10 09:09:52 -070089static const int kAutoTuneLoops = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -070090
bsalomon6eb03cc2014-08-07 14:28:50 -070091static SkString loops_help_txt() {
92 SkString help;
93 help.printf("Number of times to run each bench. Set this to %d to auto-"
94 "tune for each bench. Timings are only reported when auto-tuning.",
95 kAutoTuneLoops);
96 return help;
97}
98
cdaltone1b89582015-06-25 19:17:08 -070099static SkString to_string(int n) {
100 SkString str;
101 str.appendS32(n);
102 return str;
103}
104
Mike Kleinac8f4432019-07-01 10:15:32 -0500105static DEFINE_int(loops, kAutoTuneLoops, loops_help_txt().c_str());
bsalomon6eb03cc2014-08-07 14:28:50 -0700106
Mike Klein5b3f3432019-03-21 11:42:21 -0500107static DEFINE_int(samples, 10, "Number of samples to measure for each bench.");
108static DEFINE_int(ms, 0, "If >0, run each bench for this many ms instead of obeying --samples.");
109static DEFINE_int(overheadLoops, 100000, "Loops to estimate timer overhead.");
Mike Klein84836b72019-03-21 11:31:36 -0500110static DEFINE_double(overheadGoal, 0.0001,
mtkleinf3723212014-06-25 14:08:00 -0700111 "Loop until timer overhead is at most this fraction of our measurments.");
Mike Klein84836b72019-03-21 11:31:36 -0500112static DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500113static DEFINE_int(gpuFrameLag, 5,
Mike Klein84836b72019-03-21 11:31:36 -0500114 "If unknown, estimated maximum number of frames GPU allows to lag.");
mtkleinf3723212014-06-25 14:08:00 -0700115
Mike Klein84836b72019-03-21 11:31:36 -0500116static DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500117static DEFINE_int(maxCalibrationAttempts, 3,
mtklein55b0ffc2014-07-17 08:38:23 -0700118 "Try up to this many times to guess loops for a bench, or skip the bench.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500119static DEFINE_int(maxLoops, 1000000, "Never run a bench more times than this.");
Mike Klein84836b72019-03-21 11:31:36 -0500120static DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
121static DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
122static DEFINE_string(zoom, "1.0,0",
123 "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom "
124 "function that ping-pongs between 1.0 and zoomMax.");
125static DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
Mike Klein84836b72019-03-21 11:31:36 -0500126static DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?");
Mike Klein5b3f3432019-03-21 11:42:21 -0500127static DEFINE_int(flushEvery, 10, "Flush --outResultsFile every Nth run.");
Mike Klein84836b72019-03-21 11:31:36 -0500128static DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
129static DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json");
130static DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out");
131static DEFINE_bool(csv, false, "Print status in CSV format");
132static DEFINE_string(sourceType, "",
mtklein65dfd2f2016-02-03 10:40:54 -0800133 "Apply usual --match rules to source type: bench, gm, skp, image, etc.");
Mike Klein84836b72019-03-21 11:31:36 -0500134static DEFINE_string(benchType, "",
135 "Apply usual --match rules to bench type: micro, recording, "
136 "piping, playback, skcodec, etc.");
mtklein65dfd2f2016-02-03 10:40:54 -0800137
Mike Klein84836b72019-03-21 11:31:36 -0500138static DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
Mike Klein813e8cc2020-08-05 09:33:38 -0500139static DEFINE_bool(skvm, false, "sets gUseSkVMBlitter");
140static DEFINE_bool(jit, true, "sets gSkVMAllowJIT and gSkVMJITViaDylib");
Mike Reedc928fe22017-06-05 10:20:31 -0400141
Mike Klein19fb3972019-03-21 13:08:08 -0500142static DEFINE_bool2(pre_log, p, false,
143 "Log before running each test. May be incomprehensible when threading");
144
Leon Scroggins III1ff07062020-07-27 14:52:19 -0400145static DEFINE_bool(cpu, true, "Run CPU-bound work?");
146static DEFINE_bool(gpu, true, "Run GPU-bound work?");
Mike Klein629f5fc2019-03-22 14:55:19 -0500147static DEFINE_bool(dryRun, false,
148 "just print the tests that would be run, without actually running them.");
149static DEFINE_string(images, "",
150 "List of images and/or directories to decode. A directory with no images"
151 " is treated as a fatal error.");
152static DEFINE_bool(simpleCodec, false,
153 "Runs of a subset of the codec tests, always N32, Premul or Opaque");
154
Mike Kleinc6142d82019-03-25 10:54:59 -0500155static DEFINE_string2(match, m, nullptr,
156 "[~][^]substring[$] [...] of name to run.\n"
157 "Multiple matches may be separated by spaces.\n"
158 "~ causes a matching name to always be skipped\n"
159 "^ requires the start of the name to match\n"
160 "$ requires the end of the name to match\n"
161 "^ and $ requires an exact match\n"
162 "If a name does not match any list entry,\n"
163 "it is skipped unless some list entry starts with ~");
164
165static DEFINE_bool2(quiet, q, false, "if true, don't print status updates.");
166static DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
167
168
169static DEFINE_string(skps, "skps", "Directory to read skps from.");
170static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file.");
Hal Canary5dfefa22019-10-24 13:52:17 -0400171static DEFINE_string(texttraces, "", "Directory to read TextBlobTrace files from.");
Mike Kleinc6142d82019-03-25 10:54:59 -0500172
173static DEFINE_int_2(threads, j, -1,
174 "Run threadsafe tests on a threadpool with this many extra threads, "
175 "defaulting to one extra thread per core.");
176
177static DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs.");
178
179static DEFINE_string(key, "",
180 "Space-separated key/value pairs to add to JSON identifying this builder.");
181static DEFINE_string(properties, "",
182 "Space-separated key/value pairs to add to JSON identifying this run.");
183
Mike Kleinee254232019-03-28 08:32:14 -0500184static DEFINE_bool(purgeBetweenBenches, false,
185 "Call SkGraphics::PurgeAllCaches() between each benchmark?");
186
mtkleinbbba1682015-10-28 11:36:30 -0700187static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
188
mtkleinf3723212014-06-25 14:08:00 -0700189static SkString humanize(double ms) {
Adlai Holler684838f2020-05-12 10:41:04 -0400190 if (FLAGS_verbose) return SkStringPrintf("%" PRIu64, (uint64_t)(ms*1e6));
mtklein748ca3b2015-01-15 10:56:12 -0800191 return HumanizeMs(ms);
mtkleinf3723212014-06-25 14:08:00 -0700192}
mtklein55b0ffc2014-07-17 08:38:23 -0700193#define HUMANIZE(ms) humanize(ms).c_str()
mtkleinf3723212014-06-25 14:08:00 -0700194
tomhudsond968a6f2015-03-26 11:28:06 -0700195bool Target::init(SkImageInfo info, Benchmark* bench) {
196 if (Benchmark::kRaster_Backend == config.backend) {
reede8f30622016-03-23 18:59:25 -0700197 this->surface = SkSurface::MakeRaster(info);
198 if (!this->surface) {
tomhudsond968a6f2015-03-26 11:28:06 -0700199 return false;
200 }
201 }
202 return true;
203}
204bool Target::capturePixels(SkBitmap* bmp) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700205 SkCanvas* canvas = this->getCanvas();
tomhudsond968a6f2015-03-26 11:28:06 -0700206 if (!canvas) {
207 return false;
208 }
Mike Reed12e946b2017-04-17 10:53:29 -0400209 bmp->allocPixels(canvas->imageInfo());
210 if (!canvas->readPixels(*bmp, 0, 0)) {
tomhudsond968a6f2015-03-26 11:28:06 -0700211 SkDebugf("Can't read canvas pixels.\n");
212 return false;
213 }
214 return true;
215}
216
tomhudsond968a6f2015-03-26 11:28:06 -0700217struct GPUTarget : public Target {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400218 explicit GPUTarget(const Config& c) : Target(c) {}
219 ContextInfo contextInfo;
220 std::unique_ptr<GrContextFactory> factory;
tomhudsond968a6f2015-03-26 11:28:06 -0700221
Greg Daniel5ed3c112020-06-18 15:59:17 -0400222 ~GPUTarget() override {
223 // For Vulkan we need to release all our refs to the GrContext before destroy the vulkan
224 // context which happens at the end of this destructor. Thus we need to release the surface
225 // here which holds a ref to the GrContext.
226 surface.reset();
227 }
228
tomhudsond968a6f2015-03-26 11:28:06 -0700229 void setup() override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400230 this->contextInfo.testContext()->makeCurrent();
tomhudsond968a6f2015-03-26 11:28:06 -0700231 // Make sure we're done with whatever came before.
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400232 this->contextInfo.testContext()->finish();
tomhudsond968a6f2015-03-26 11:28:06 -0700233 }
234 void endTiming() override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400235 if (this->contextInfo.testContext()) {
Robert Phillips00f78de2020-07-01 16:09:43 -0400236 this->contextInfo.testContext()->flushAndWaitOnSync(contextInfo.directContext());
tomhudsond968a6f2015-03-26 11:28:06 -0700237 }
238 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400239 void fence() override { this->contextInfo.testContext()->finish(); }
mtkleind75c4662015-04-30 07:11:22 -0700240
cdaltond416a5b2015-06-23 13:23:44 -0700241 bool needsFrameTiming(int* maxFrameLag) const override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400242 if (!this->contextInfo.testContext()->getMaxGpuFrameLag(maxFrameLag)) {
cdaltond416a5b2015-06-23 13:23:44 -0700243 // Frame lag is unknown.
244 *maxFrameLag = FLAGS_gpuFrameLag;
245 }
246 return true;
247 }
tomhudsond968a6f2015-03-26 11:28:06 -0700248 bool init(SkImageInfo info, Benchmark* bench) override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400249 GrContextOptions options = grContextOpts;
250 bench->modifyGrContextOptions(&options);
John Stilesfbd050b2020-08-03 13:21:46 -0400251 this->factory = std::make_unique<GrContextFactory>(options);
bsalomonafcd7cd2015-08-31 12:39:41 -0700252 uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag :
253 0;
Ben Wagnerae4bb982020-09-24 14:49:00 -0400254 SkSurfaceProps props(flags, kRGB_H_SkPixelGeometry);
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400255 this->surface = SkSurface::MakeRenderTarget(
256 this->factory->get(this->config.ctxType, this->config.ctxOverrides),
257 SkBudgeted::kNo, info, this->config.samples, &props);
258 this->contextInfo =
259 this->factory->getContextInfo(this->config.ctxType, this->config.ctxOverrides);
John Stilesa008b0f2020-08-16 08:48:02 -0400260 if (!this->surface) {
tomhudsond968a6f2015-03-26 11:28:06 -0700261 return false;
262 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400263 if (!this->contextInfo.testContext()->fenceSyncSupport()) {
cdaltond416a5b2015-06-23 13:23:44 -0700264 SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. "
svaisanenc47635e2016-01-28 06:05:43 -0800265 "Timings might not be accurate.\n", this->config.name.c_str());
cdaltond416a5b2015-06-23 13:23:44 -0700266 }
tomhudsond968a6f2015-03-26 11:28:06 -0700267 return true;
268 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500269 void fillOptions(NanoJSONResultsWriter& log) override {
Brian Salomonf4ba4ec2020-03-19 15:54:28 -0400270#ifdef SK_GL
tomhudsond968a6f2015-03-26 11:28:06 -0700271 const GrGLubyte* version;
Greg Danielbdf12ad2018-10-12 09:31:11 -0400272 if (this->contextInfo.backend() == GrBackendApi::kOpenGL) {
Brian Salomon032aaae2018-03-23 16:10:36 -0400273 const GrGLInterface* gl =
Robert Phillips00f78de2020-07-01 16:09:43 -0400274 static_cast<GrGLGpu*>(this->contextInfo.directContext()->priv().getGpu())
Brian Salomon032aaae2018-03-23 16:10:36 -0400275 ->glInterface();
bsalomonc8699322016-05-11 11:55:36 -0700276 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VERSION));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500277 log.appendString("GL_VERSION", (const char*)(version));
tomhudsond968a6f2015-03-26 11:28:06 -0700278
bsalomonc8699322016-05-11 11:55:36 -0700279 GR_GL_CALL_RET(gl, version, GetString(GR_GL_RENDERER));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500280 log.appendString("GL_RENDERER", (const char*) version);
tomhudsond968a6f2015-03-26 11:28:06 -0700281
bsalomonc8699322016-05-11 11:55:36 -0700282 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VENDOR));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500283 log.appendString("GL_VENDOR", (const char*) version);
tomhudsond968a6f2015-03-26 11:28:06 -0700284
bsalomonc8699322016-05-11 11:55:36 -0700285 GR_GL_CALL_RET(gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500286 log.appendString("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
bsalomonc8699322016-05-11 11:55:36 -0700287 }
Brian Salomonf4ba4ec2020-03-19 15:54:28 -0400288#endif
tomhudsond968a6f2015-03-26 11:28:06 -0700289 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400290
291 void dumpStats() override {
Robert Phillips00f78de2020-07-01 16:09:43 -0400292 auto context = this->contextInfo.directContext();
293
294 context->priv().printCacheStats();
295 context->priv().printGpuStats();
296 context->priv().printContextStats();
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400297 }
tomhudsond968a6f2015-03-26 11:28:06 -0700298};
mtkleind75c4662015-04-30 07:11:22 -0700299
tomhudson75a0ebb2015-03-27 12:11:44 -0700300static double time(int loops, Benchmark* bench, Target* target) {
301 SkCanvas* canvas = target->getCanvas();
bsalomon6eb03cc2014-08-07 14:28:50 -0700302 if (canvas) {
303 canvas->clear(SK_ColorWHITE);
304 }
joshualitt8a6697a2015-09-30 12:11:07 -0700305 bench->preDraw(canvas);
mtkleinbbba1682015-10-28 11:36:30 -0700306 double start = now_ms();
tomhudson75a0ebb2015-03-27 12:11:44 -0700307 canvas = target->beginTiming(canvas);
308 bench->draw(loops, canvas);
tomhudson75a0ebb2015-03-27 12:11:44 -0700309 target->endTiming();
mtkleinbbba1682015-10-28 11:36:30 -0700310 double elapsed = now_ms() - start;
joshualitt8a6697a2015-09-30 12:11:07 -0700311 bench->postDraw(canvas);
mtkleinbbba1682015-10-28 11:36:30 -0700312 return elapsed;
mtkleinbb6a0282014-07-01 08:43:42 -0700313}
314
mtkleinf3723212014-06-25 14:08:00 -0700315static double estimate_timer_overhead() {
316 double overhead = 0;
mtkleinf3723212014-06-25 14:08:00 -0700317 for (int i = 0; i < FLAGS_overheadLoops; i++) {
mtkleinbbba1682015-10-28 11:36:30 -0700318 double start = now_ms();
319 overhead += now_ms() - start;
mtkleinf3723212014-06-25 14:08:00 -0700320 }
321 return overhead / FLAGS_overheadLoops;
322}
323
reed53249782014-10-10 09:09:52 -0700324static int detect_forever_loops(int loops) {
325 // look for a magic run-forever value
326 if (loops < 0) {
327 loops = SK_MaxS32;
328 }
329 return loops;
330}
331
mtklein55b0ffc2014-07-17 08:38:23 -0700332static int clamp_loops(int loops) {
333 if (loops < 1) {
mtklein527930f2014-11-06 08:04:34 -0800334 SkDebugf("ERROR: clamping loops from %d to 1. "
335 "There's probably something wrong with the bench.\n", loops);
mtklein55b0ffc2014-07-17 08:38:23 -0700336 return 1;
337 }
338 if (loops > FLAGS_maxLoops) {
339 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
340 return FLAGS_maxLoops;
341 }
342 return loops;
343}
344
tomhudsond968a6f2015-03-26 11:28:06 -0700345static bool write_canvas_png(Target* target, const SkString& filename) {
346
bsalomon6eb03cc2014-08-07 14:28:50 -0700347 if (filename.isEmpty()) {
348 return false;
349 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700350 if (target->getCanvas() &&
351 kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700352 return false;
353 }
tomhudsond968a6f2015-03-26 11:28:06 -0700354
bsalomon6eb03cc2014-08-07 14:28:50 -0700355 SkBitmap bmp;
tomhudsond968a6f2015-03-26 11:28:06 -0700356
357 if (!target->capturePixels(&bmp)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700358 return false;
359 }
tomhudsond968a6f2015-03-26 11:28:06 -0700360
bsalomon6eb03cc2014-08-07 14:28:50 -0700361 SkString dir = SkOSPath::Dirname(filename.c_str());
362 if (!sk_mkdir(dir.c_str())) {
363 SkDebugf("Can't make dir %s.\n", dir.c_str());
364 return false;
365 }
366 SkFILEWStream stream(filename.c_str());
367 if (!stream.isValid()) {
368 SkDebugf("Can't write %s.\n", filename.c_str());
369 return false;
370 }
Hal Canarydb683012016-11-23 08:55:18 -0700371 if (!SkEncodeImage(&stream, bmp, SkEncodedImageFormat::kPNG, 100)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700372 SkDebugf("Can't encode a PNG.\n");
373 return false;
374 }
375 return true;
376}
377
378static int kFailedLoops = -2;
cdaltone1b89582015-06-25 19:17:08 -0700379static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) {
mtkleinbb6a0282014-07-01 08:43:42 -0700380 // First figure out approximately how many loops of bench it takes to make overhead negligible.
mtklein2069e222014-08-04 13:57:39 -0700381 double bench_plus_overhead = 0.0;
mtklein55b0ffc2014-07-17 08:38:23 -0700382 int round = 0;
cdaltonb4022962015-06-25 10:51:56 -0700383 int loops = bench->calculateLoops(FLAGS_loops);
384 if (kAutoTuneLoops == loops) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700385 while (bench_plus_overhead < overhead) {
386 if (round++ == FLAGS_maxCalibrationAttempts) {
387 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
mtklein96289052014-09-10 12:05:59 -0700388 bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
bsalomon6eb03cc2014-08-07 14:28:50 -0700389 return kFailedLoops;
390 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700391 bench_plus_overhead = time(1, bench, target);
mtklein55b0ffc2014-07-17 08:38:23 -0700392 }
mtklein2069e222014-08-04 13:57:39 -0700393 }
mtkleinf3723212014-06-25 14:08:00 -0700394
mtkleinbb6a0282014-07-01 08:43:42 -0700395 // Later we'll just start and stop the timer once but loop N times.
mtkleinf3723212014-06-25 14:08:00 -0700396 // We'll pick N to make timer overhead negligible:
397 //
mtkleinbb6a0282014-07-01 08:43:42 -0700398 // overhead
399 // ------------------------- < FLAGS_overheadGoal
400 // overhead + N * Bench Time
mtkleinf3723212014-06-25 14:08:00 -0700401 //
Hal Canary55325b72017-01-03 10:36:17 -0500402 // where bench_plus_overhead ~=~ overhead + Bench Time.
mtkleinf3723212014-06-25 14:08:00 -0700403 //
404 // Doing some math, we get:
405 //
mtkleinbb6a0282014-07-01 08:43:42 -0700406 // (overhead / FLAGS_overheadGoal) - overhead
407 // ------------------------------------------ < N
408 // bench_plus_overhead - overhead)
mtkleinf3723212014-06-25 14:08:00 -0700409 //
410 // Luckily, this also works well in practice. :)
bsalomon6eb03cc2014-08-07 14:28:50 -0700411 if (kAutoTuneLoops == loops) {
412 const double numer = overhead / FLAGS_overheadGoal - overhead;
413 const double denom = bench_plus_overhead - overhead;
414 loops = (int)ceil(numer / denom);
reed53249782014-10-10 09:09:52 -0700415 loops = clamp_loops(loops);
416 } else {
417 loops = detect_forever_loops(loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700418 }
mtkleinbb6a0282014-07-01 08:43:42 -0700419
mtkleinbb6a0282014-07-01 08:43:42 -0700420 return loops;
mtkleinf3723212014-06-25 14:08:00 -0700421}
422
cdaltone1b89582015-06-25 19:17:08 -0700423static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) {
mtkleinbb6a0282014-07-01 08:43:42 -0700424 // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
cdaltonb4022962015-06-25 10:51:56 -0700425 int loops = bench->calculateLoops(FLAGS_loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700426 if (kAutoTuneLoops == loops) {
427 loops = 1;
mtkleina189ccd2014-07-14 12:28:47 -0700428 double elapsed = 0;
429 do {
mtklein527930f2014-11-06 08:04:34 -0800430 if (1<<30 == loops) {
431 // We're about to wrap. Something's wrong with the bench.
432 loops = 0;
433 break;
434 }
mtkleina189ccd2014-07-14 12:28:47 -0700435 loops *= 2;
436 // If the GPU lets frames lag at all, we need to make sure we're timing
cdaltond416a5b2015-06-23 13:23:44 -0700437 // _this_ round, not still timing last round.
438 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700439 elapsed = time(loops, bench, target);
mtkleina189ccd2014-07-14 12:28:47 -0700440 }
441 } while (elapsed < FLAGS_gpuMs);
mtkleinbb6a0282014-07-01 08:43:42 -0700442
mtkleina189ccd2014-07-14 12:28:47 -0700443 // We've overshot at least a little. Scale back linearly.
444 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
reed53249782014-10-10 09:09:52 -0700445 loops = clamp_loops(loops);
mtkleinbb6a0282014-07-01 08:43:42 -0700446
tomhudsond968a6f2015-03-26 11:28:06 -0700447 // Make sure we're not still timing our calibration.
448 target->fence();
reed53249782014-10-10 09:09:52 -0700449 } else {
450 loops = detect_forever_loops(loops);
mtkleina189ccd2014-07-14 12:28:47 -0700451 }
mtkleinbb6a0282014-07-01 08:43:42 -0700452 // Pretty much the same deal as the calibration: do some warmup to make
453 // sure we're timing steady-state pipelined frames.
Brian Osman01776982017-10-10 15:41:03 -0400454 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700455 time(loops, bench, target);
mtkleinf3723212014-06-25 14:08:00 -0700456 }
mtkleinbb6a0282014-07-01 08:43:42 -0700457
mtkleinbb6a0282014-07-01 08:43:42 -0700458 return loops;
459}
mtkleinbb6a0282014-07-01 08:43:42 -0700460
Brian Salomon6405e712017-03-20 08:54:16 -0400461#define kBogusContextType GrContextFactory::kGL_ContextType
csmartdaltone812d492017-02-21 12:36:05 -0700462#define kBogusContextOverrides GrContextFactory::ContextOverrides::kNone
bsalomonc2553372014-07-22 13:09:05 -0700463
svaisanenc47635e2016-01-28 06:05:43 -0800464static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) {
svaisanenc47635e2016-01-28 06:05:43 -0800465 if (const auto* gpuConfig = config->asConfigGpu()) {
Ben Wagner32fa5102017-08-10 21:25:55 -0400466 if (!FLAGS_gpu) {
467 SkDebugf("Skipping config '%s' as requested.\n", config->getTag().c_str());
svaisanenc47635e2016-01-28 06:05:43 -0800468 return;
Ben Wagner32fa5102017-08-10 21:25:55 -0400469 }
svaisanenc47635e2016-01-28 06:05:43 -0800470
svaisanenc47635e2016-01-28 06:05:43 -0800471 const auto ctxType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700472 const auto ctxOverrides = gpuConfig->getContextOverrides();
svaisanenc47635e2016-01-28 06:05:43 -0800473 const auto sampleCount = gpuConfig->getSamples();
Greg Daniel81e7bf82017-07-19 14:47:42 -0400474 const auto colorType = gpuConfig->getColorType();
475 auto colorSpace = gpuConfig->getColorSpace();
Brian Salomonf865b052018-03-09 09:01:53 -0500476 if (gpuConfig->getSurfType() != SkCommandLineConfigGpu::SurfType::kDefault) {
477 SkDebugf("This tool only supports the default surface type.");
478 return;
479 }
svaisanenc47635e2016-01-28 06:05:43 -0800480
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400481 GrContextFactory factory(grContextOpts);
Robert Phillipsf0288102020-07-06 13:45:34 -0400482 if (const auto ctx = factory.get(ctxType, ctxOverrides)) {
Greg Daniel6fa62e22019-08-07 15:52:37 -0400483 GrBackendFormat format = ctx->defaultBackendFormat(colorType, GrRenderable::kYes);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500484 int supportedSampleCount =
Greg Daniel6fa62e22019-08-07 15:52:37 -0400485 ctx->priv().caps()->getRenderTargetSampleCount(sampleCount, format);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400486 if (sampleCount != supportedSampleCount) {
Ben Wagner32fa5102017-08-10 21:25:55 -0400487 SkDebugf("Configuration '%s' sample count %d is not a supported sample count.\n",
488 config->getTag().c_str(), sampleCount);
svaisanenc47635e2016-01-28 06:05:43 -0800489 return;
490 }
491 } else {
Ben Wagner32fa5102017-08-10 21:25:55 -0400492 SkDebugf("No context was available matching config '%s'.\n",
493 config->getTag().c_str());
svaisanenc47635e2016-01-28 06:05:43 -0800494 return;
495 }
496
497 Config target = {
kkinnunend4e1c352016-03-01 23:41:26 -0800498 gpuConfig->getTag(),
svaisanenc47635e2016-01-28 06:05:43 -0800499 Benchmark::kGPU_Backend,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400500 colorType,
svaisanenc47635e2016-01-28 06:05:43 -0800501 kPremul_SkAlphaType,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400502 sk_ref_sp(colorSpace),
svaisanenc47635e2016-01-28 06:05:43 -0800503 sampleCount,
504 ctxType,
csmartdaltone812d492017-02-21 12:36:05 -0700505 ctxOverrides,
kkinnunend4e1c352016-03-01 23:41:26 -0800506 gpuConfig->getUseDIText()
507 };
svaisanenc47635e2016-01-28 06:05:43 -0800508
509 configs->push_back(target);
510 return;
511 }
svaisanenc47635e2016-01-28 06:05:43 -0800512
brianosmanb109b8c2016-06-16 13:03:24 -0700513 #define CPU_CONFIG(name, backend, color, alpha, colorSpace) \
514 if (config->getTag().equals(#name)) { \
Ben Wagner32fa5102017-08-10 21:25:55 -0400515 if (!FLAGS_cpu) { \
516 SkDebugf("Skipping config '%s' as requested.\n", \
517 config->getTag().c_str()); \
518 return; \
519 } \
brianosmanb109b8c2016-06-16 13:03:24 -0700520 Config config = { \
521 SkString(#name), Benchmark::backend, color, alpha, colorSpace, \
csmartdaltone812d492017-02-21 12:36:05 -0700522 0, kBogusContextType, kBogusContextOverrides, false \
brianosmanb109b8c2016-06-16 13:03:24 -0700523 }; \
524 configs->push_back(config); \
525 return; \
mtkleinbb6a0282014-07-01 08:43:42 -0700526 }
mtkleine714e752014-07-31 12:13:48 -0700527
Ben Wagner32fa5102017-08-10 21:25:55 -0400528 CPU_CONFIG(nonrendering, kNonRendering_Backend,
529 kUnknown_SkColorType, kUnpremul_SkAlphaType, nullptr)
mtkleinbb6c41b2016-03-08 11:31:11 -0800530
Mike Klein0e4041f2018-06-19 16:00:40 -0400531 CPU_CONFIG(a8, kRaster_Backend, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr)
532 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType, nullptr)
533 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType, nullptr)
534
535 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
Brian Osman82ebe042019-01-04 17:03:00 -0500536 auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50),
Mike Klein0e4041f2018-06-19 16:00:40 -0400537 srgb = SkColorSpace::MakeSRGB(),
538 srgbLinear = SkColorSpace::MakeSRGBLinear();
539
540 CPU_CONFIG( f16, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgbLinear)
541 CPU_CONFIG( srgb, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, srgb )
542 CPU_CONFIG( esrgb, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgb )
543 CPU_CONFIG( narrow, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, narrow )
544 CPU_CONFIG(enarrow, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, narrow )
mtkleinbb6a0282014-07-01 08:43:42 -0700545
svaisanenc47635e2016-01-28 06:05:43 -0800546 #undef CPU_CONFIG
Ben Wagner32fa5102017-08-10 21:25:55 -0400547
548 SkDebugf("Unknown config '%s'.\n", config->getTag().c_str());
mtkleinf3723212014-06-25 14:08:00 -0700549}
550
svaisanenc47635e2016-01-28 06:05:43 -0800551// Append all configs that are enabled and supported.
552void create_configs(SkTArray<Config>* configs) {
553 SkCommandLineConfigArray array;
554 ParseConfigs(FLAGS_config, &array);
555 for (int i = 0; i < array.count(); ++i) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400556 create_config(array[i].get(), configs);
svaisanenc47635e2016-01-28 06:05:43 -0800557 }
Ben Wagner32fa5102017-08-10 21:25:55 -0400558
559 // If no just default configs were requested, then we're okay.
560 if (array.count() == 0 || FLAGS_config.count() == 0 ||
Ben Wagner32fa5102017-08-10 21:25:55 -0400561 // Otherwise, make sure that all specified configs have been created.
562 array.count() == configs->count()) {
563 return;
564 }
Ben Wagner32fa5102017-08-10 21:25:55 -0400565 exit(1);
svaisanenc47635e2016-01-28 06:05:43 -0800566}
567
brianosman9f1f6e22016-09-15 08:33:02 -0700568// disable warning : switch statement contains default but no 'case' labels
569#if defined _WIN32
570#pragma warning ( push )
571#pragma warning ( disable : 4065 )
572#endif
573
halcanary96fcdcc2015-08-27 07:41:13 -0700574// If bench is enabled for config, returns a Target* for it, otherwise nullptr.
bsalomonc2553372014-07-22 13:09:05 -0700575static Target* is_enabled(Benchmark* bench, const Config& config) {
576 if (!bench->isSuitableFor(config.backend)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700577 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700578 }
579
reede5ea5002014-09-03 11:54:58 -0700580 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
brianosmanb109b8c2016-06-16 13:03:24 -0700581 config.color, config.alpha, config.colorSpace);
bsalomonc2553372014-07-22 13:09:05 -0700582
halcanary96fcdcc2015-08-27 07:41:13 -0700583 Target* target = nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700584
tomhudsond968a6f2015-03-26 11:28:06 -0700585 switch (config.backend) {
tomhudsond968a6f2015-03-26 11:28:06 -0700586 case Benchmark::kGPU_Backend:
587 target = new GPUTarget(config);
588 break;
tomhudsond968a6f2015-03-26 11:28:06 -0700589 default:
590 target = new Target(config);
591 break;
592 }
bsalomonc2553372014-07-22 13:09:05 -0700593
tomhudsond968a6f2015-03-26 11:28:06 -0700594 if (!target->init(info, bench)) {
bsalomonc2553372014-07-22 13:09:05 -0700595 delete target;
halcanary96fcdcc2015-08-27 07:41:13 -0700596 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700597 }
598 return target;
599}
600
brianosman9f1f6e22016-09-15 08:33:02 -0700601#if defined _WIN32
602#pragma warning ( pop )
603#endif
604
Leon Scroggins III87caae62020-05-04 10:02:45 -0400605#ifdef SK_ENABLE_ANDROID_UTILS
reed42943c82016-09-12 12:01:44 -0700606static bool valid_brd_bench(sk_sp<SkData> encoded, SkColorType colorType, uint32_t sampleSize,
msarettd1227a72016-05-18 06:23:57 -0700607 uint32_t minOutputSize, int* width, int* height) {
Leon Scroggins III87caae62020-05-04 10:02:45 -0400608 auto brd = android::skia::BitmapRegionDecoder::Make(encoded);
John Stilesa008b0f2020-08-16 08:48:02 -0400609 if (nullptr == brd) {
msarett7f691442015-09-22 11:56:16 -0700610 // This is indicates that subset decoding is not supported for a particular image format.
611 return false;
612 }
613
msarett7f691442015-09-22 11:56:16 -0700614 if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize >
615 (uint32_t) brd->height()) {
616 // This indicates that the image is not large enough to decode a
617 // minOutputSize x minOutputSize subset at the given sampleSize.
618 return false;
619 }
620
621 // Set the image width and height. The calling code will use this to choose subsets to decode.
622 *width = brd->width();
623 *height = brd->height();
624 return true;
625}
Leon Scroggins III87caae62020-05-04 10:02:45 -0400626#endif
msarett7f691442015-09-22 11:56:16 -0700627
egdaniel3bf92062015-06-26 08:12:46 -0700628static void cleanup_run(Target* target) {
halcanary385fe4d2015-08-26 13:07:48 -0700629 delete target;
egdaniel3bf92062015-06-26 08:12:46 -0700630}
631
Mike Klein88544fb2019-03-20 10:50:33 -0500632static void collect_files(const CommandLineFlags::StringArray& paths,
633 const char* ext,
634 SkTArray<SkString>* list) {
fmalita6519c212016-09-14 08:05:17 -0700635 for (int i = 0; i < paths.count(); ++i) {
636 if (SkStrEndsWith(paths[i], ext)) {
637 list->push_back(SkString(paths[i]));
638 } else {
639 SkOSFile::Iter it(paths[i], ext);
640 SkString path;
641 while (it.next(&path)) {
642 list->push_back(SkOSPath::Join(paths[i], path.c_str()));
643 }
644 }
645 }
646}
647
mtkleine714e752014-07-31 12:13:48 -0700648class BenchmarkStream {
649public:
mtklein92007582014-08-01 07:46:52 -0700650 BenchmarkStream() : fBenches(BenchRegistry::Head())
Hal Canary2362ae72019-10-24 13:40:40 -0400651 , fGMs(skiagm::GMRegistry::Head()) {
fmalita6519c212016-09-14 08:05:17 -0700652 collect_files(FLAGS_skps, ".skp", &fSKPs);
653 collect_files(FLAGS_svgs, ".svg", &fSVGs);
Hal Canary5dfefa22019-10-24 13:52:17 -0400654 collect_files(FLAGS_texttraces, ".trace", &fTextBlobTraces);
mtkleine714e752014-07-31 12:13:48 -0700655
mtklein92007582014-08-01 07:46:52 -0700656 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
657 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
658 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
659 exit(1);
660 }
661
662 for (int i = 0; i < FLAGS_scales.count(); i++) {
663 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
664 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
665 exit(1);
666 }
667 }
robertphillips5b693772014-11-21 06:19:36 -0800668
cdalton63a82852015-06-29 14:06:10 -0700669 if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) {
670 SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]);
joshualitt261c3ad2015-04-27 09:16:57 -0700671 exit(1);
672 }
673
msarett95f192d2015-02-13 09:05:41 -0800674 // Prepare the images for decoding
msarett69deca82016-04-29 09:38:40 -0700675 if (!CollectImages(FLAGS_images, &fImages)) {
scroggo86737142016-02-03 12:19:11 -0800676 exit(1);
msarett95f192d2015-02-13 09:05:41 -0800677 }
mtklein95553d92015-03-12 08:24:21 -0700678
msarett95f192d2015-02-13 09:05:41 -0800679 // Choose the candidate color types for image decoding
msarett67cb6662016-06-21 08:49:26 -0700680 fColorTypes.push_back(kN32_SkColorType);
681 if (!FLAGS_simpleCodec) {
682 fColorTypes.push_back(kRGB_565_SkColorType);
683 fColorTypes.push_back(kAlpha_8_SkColorType);
msarett67cb6662016-06-21 08:49:26 -0700684 fColorTypes.push_back(kGray_8_SkColorType);
685 }
mtklein92007582014-08-01 07:46:52 -0700686 }
687
reedca2622b2016-03-18 07:25:55 -0700688 static sk_sp<SkPicture> ReadPicture(const char* path) {
mtkleinfd731ce2014-09-10 12:19:30 -0700689 // Not strictly necessary, as it will be checked again later,
690 // but helps to avoid a lot of pointless work if we're going to skip it.
Mike Klein88544fb2019-03-20 10:50:33 -0500691 if (CommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) {
reedca2622b2016-03-18 07:25:55 -0700692 return nullptr;
mtkleinfd731ce2014-09-10 12:19:30 -0700693 }
694
bungemanf93d7112016-09-16 06:24:20 -0700695 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
696 if (!stream) {
mtkleinfd731ce2014-09-10 12:19:30 -0700697 SkDebugf("Could not read %s.\n", path);
reedca2622b2016-03-18 07:25:55 -0700698 return nullptr;
mtkleinfd731ce2014-09-10 12:19:30 -0700699 }
700
reedca2622b2016-03-18 07:25:55 -0700701 return SkPicture::MakeFromStream(stream.get());
mtkleinfd731ce2014-09-10 12:19:30 -0700702 }
703
fmalita6519c212016-09-14 08:05:17 -0700704 static sk_sp<SkPicture> ReadSVGPicture(const char* path) {
Mike Klein8ab65bf2020-12-04 09:20:32 -0600705 if (CommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) {
706 return nullptr;
707 }
Brian Osman133823d2018-09-19 14:14:15 -0400708 sk_sp<SkData> data(SkData::MakeFromFileName(path));
709 if (!data) {
fmalita6519c212016-09-14 08:05:17 -0700710 SkDebugf("Could not read %s.\n", path);
711 return nullptr;
712 }
713
Hal Canary0f666812018-03-22 15:21:12 -0400714#ifdef SK_XML
Brian Osman133823d2018-09-19 14:14:15 -0400715 SkMemoryStream stream(std::move(data));
fmalitae1baa7c2016-09-14 12:04:30 -0700716 sk_sp<SkSVGDOM> svgDom = SkSVGDOM::MakeFromStream(stream);
fmalita6519c212016-09-14 08:05:17 -0700717 if (!svgDom) {
718 SkDebugf("Could not parse %s.\n", path);
719 return nullptr;
720 }
721
fmalitae1baa7c2016-09-14 12:04:30 -0700722 // Use the intrinsic SVG size if available, otherwise fall back to a default value.
723 static const SkSize kDefaultContainerSize = SkSize::Make(128, 128);
724 if (svgDom->containerSize().isEmpty()) {
725 svgDom->setContainerSize(kDefaultContainerSize);
726 }
727
fmalita6519c212016-09-14 08:05:17 -0700728 SkPictureRecorder recorder;
fmalitae1baa7c2016-09-14 12:04:30 -0700729 svgDom->render(recorder.beginRecording(svgDom->containerSize().width(),
730 svgDom->containerSize().height()));
fmalita6519c212016-09-14 08:05:17 -0700731 return recorder.finishRecordingAsPicture();
Hal Canary0f666812018-03-22 15:21:12 -0400732#else
733 return nullptr;
734#endif // SK_XML
fmalita6519c212016-09-14 08:05:17 -0700735 }
736
mtklein92007582014-08-01 07:46:52 -0700737 Benchmark* next() {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400738 std::unique_ptr<Benchmark> bench;
mtklein65dfd2f2016-02-03 10:40:54 -0800739 do {
740 bench.reset(this->rawNext());
741 if (!bench) {
742 return nullptr;
743 }
Mike Klein88544fb2019-03-20 10:50:33 -0500744 } while (CommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) ||
745 CommandLineFlags::ShouldSkip(FLAGS_benchType, fBenchType));
mtklein18300a32016-03-16 13:53:35 -0700746 return bench.release();
mtklein65dfd2f2016-02-03 10:40:54 -0800747 }
748
749 Benchmark* rawNext() {
mtkleine714e752014-07-31 12:13:48 -0700750 if (fBenches) {
Hal Canary972eba32018-07-30 17:07:07 -0400751 Benchmark* bench = fBenches->get()(nullptr);
mtkleine714e752014-07-31 12:13:48 -0700752 fBenches = fBenches->next();
mtklein92007582014-08-01 07:46:52 -0700753 fSourceType = "bench";
mtkleinfd731ce2014-09-10 12:19:30 -0700754 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700755 return bench;
756 }
mtklein92007582014-08-01 07:46:52 -0700757
mtkleine714e752014-07-31 12:13:48 -0700758 while (fGMs) {
Ben Wagner406ff502019-08-12 16:39:24 -0400759 std::unique_ptr<skiagm::GM> gm = fGMs->get()();
mtkleine714e752014-07-31 12:13:48 -0700760 fGMs = fGMs->next();
mtkleincf5d9c92015-01-23 10:31:45 -0800761 if (gm->runAsBench()) {
mtklein92007582014-08-01 07:46:52 -0700762 fSourceType = "gm";
mtkleinfd731ce2014-09-10 12:19:30 -0700763 fBenchType = "micro";
Ben Wagner406ff502019-08-12 16:39:24 -0400764 return new GMBench(std::move(gm));
mtkleine714e752014-07-31 12:13:48 -0700765 }
766 }
mtklein92007582014-08-01 07:46:52 -0700767
Hal Canary5dfefa22019-10-24 13:52:17 -0400768 while (fCurrentTextBlobTrace < fTextBlobTraces.count()) {
769 SkString path = fTextBlobTraces[fCurrentTextBlobTrace++];
770 SkString basename = SkOSPath::Basename(path.c_str());
771 static constexpr char kEnding[] = ".trace";
772 if (basename.endsWith(kEnding)) {
773 basename.remove(basename.size() - strlen(kEnding), strlen(kEnding));
774 }
775 fSourceType = "texttrace";
776 fBenchType = "micro";
777 return CreateDiffCanvasBench(
778 SkStringPrintf("SkDiffBench-%s", basename.c_str()),
779 [path](){ return SkStream::MakeFromFile(path.c_str()); });
780 }
781
mtkleinfd731ce2014-09-10 12:19:30 -0700782 // First add all .skps as RecordingBenches.
783 while (fCurrentRecording < fSKPs.count()) {
784 const SkString& path = fSKPs[fCurrentRecording++];
reedca2622b2016-03-18 07:25:55 -0700785 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
786 if (!pic) {
mtkleinfd731ce2014-09-10 12:19:30 -0700787 continue;
788 }
789 SkString name = SkOSPath::Basename(path.c_str());
790 fSourceType = "skp";
791 fBenchType = "recording";
Mike Klein88d90712018-01-27 17:30:04 +0000792 fSKPBytes = static_cast<double>(pic->approximateBytesUsed());
793 fSKPOps = pic->approximateOpCount();
Mike Kleina705cb92019-05-14 12:33:40 -0500794 return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh);
mtkleinfd731ce2014-09-10 12:19:30 -0700795 }
796
Mike Reede45ff462017-12-06 10:47:03 -0500797 // Add all .skps as DeserializePictureBenchs.
798 while (fCurrentDeserialPicture < fSKPs.count()) {
799 const SkString& path = fSKPs[fCurrentDeserialPicture++];
800 sk_sp<SkData> data = SkData::MakeFromFileName(path.c_str());
801 if (!data) {
802 continue;
803 }
804 SkString name = SkOSPath::Basename(path.c_str());
805 fSourceType = "skp";
806 fBenchType = "deserial";
Mike Reed7557bbb2017-12-24 19:50:57 -0500807 fSKPBytes = static_cast<double>(data->size());
Mike Klein88d90712018-01-27 17:30:04 +0000808 fSKPOps = 0;
Mike Reede45ff462017-12-06 10:47:03 -0500809 return new DeserializePictureBench(name.c_str(), std::move(data));
810 }
811
mtkleinfd731ce2014-09-10 12:19:30 -0700812 // Then once each for each scale as SKPBenches (playback).
mtklein92007582014-08-01 07:46:52 -0700813 while (fCurrentScale < fScales.count()) {
814 while (fCurrentSKP < fSKPs.count()) {
Brian Salomon626349b2020-08-27 10:54:36 -0400815 const SkString& path = fSKPs[fCurrentSKP++];
reedca2622b2016-03-18 07:25:55 -0700816 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
817 if (!pic) {
mtklein92007582014-08-01 07:46:52 -0700818 continue;
819 }
robertphillips5b693772014-11-21 06:19:36 -0800820
Brian Salomon626349b2020-08-27 10:54:36 -0400821 if (FLAGS_bbh) {
822 // The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
823 SkRTreeFactory factory;
824 SkPictureRecorder recorder;
825 pic->playback(recorder.beginRecording(pic->cullRect().width(),
826 pic->cullRect().height(),
827 &factory));
828 pic = recorder.finishRecordingAsPicture();
mtklein20840502014-08-21 15:51:22 -0700829 }
Brian Salomon626349b2020-08-27 10:54:36 -0400830 SkString name = SkOSPath::Basename(path.c_str());
831 fSourceType = "skp";
832 fBenchType = "playback";
833 return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale],
834 FLAGS_loopSKP);
mtklein92007582014-08-01 07:46:52 -0700835 }
fmalita6519c212016-09-14 08:05:17 -0700836
Brian Salomon626349b2020-08-27 10:54:36 -0400837 while (fCurrentSVG < fSVGs.count()) {
838 const char* path = fSVGs[fCurrentSVG++].c_str();
fmalita6519c212016-09-14 08:05:17 -0700839 if (sk_sp<SkPicture> pic = ReadSVGPicture(path)) {
840 fSourceType = "svg";
841 fBenchType = "playback";
842 return new SKPBench(SkOSPath::Basename(path).c_str(), pic.get(), fClip,
Brian Salomon626349b2020-08-27 10:54:36 -0400843 fScales[fCurrentScale], FLAGS_loopSKP);
fmalita6519c212016-09-14 08:05:17 -0700844 }
845 }
846
mtklein92007582014-08-01 07:46:52 -0700847 fCurrentSKP = 0;
fmalita6519c212016-09-14 08:05:17 -0700848 fCurrentSVG = 0;
mtklein92007582014-08-01 07:46:52 -0700849 fCurrentScale++;
850 }
851
joshualitt261c3ad2015-04-27 09:16:57 -0700852 // Now loop over each skp again if we have an animation
cdalton63a82852015-06-29 14:06:10 -0700853 if (fZoomMax != 1.0f && fZoomPeriodMs > 0) {
joshualitt261c3ad2015-04-27 09:16:57 -0700854 while (fCurrentAnimSKP < fSKPs.count()) {
855 const SkString& path = fSKPs[fCurrentAnimSKP];
reedca2622b2016-03-18 07:25:55 -0700856 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
857 if (!pic) {
joshualitt261c3ad2015-04-27 09:16:57 -0700858 fCurrentAnimSKP++;
859 continue;
860 }
861
862 fCurrentAnimSKP++;
863 SkString name = SkOSPath::Basename(path.c_str());
Ben Wagneracf98df2019-07-12 12:51:44 -0400864 sk_sp<SKPAnimationBench::Animation> animation =
865 SKPAnimationBench::MakeZoomAnimation(fZoomMax, fZoomPeriodMs);
866 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, std::move(animation),
halcanary385fe4d2015-08-26 13:07:48 -0700867 FLAGS_loopSKP);
joshualitt261c3ad2015-04-27 09:16:57 -0700868 }
869 }
870
scroggo60869a42015-04-01 12:09:17 -0700871 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) {
scroggo303fa352015-10-05 11:03:34 -0700872 fSourceType = "image";
873 fBenchType = "skcodec";
scroggo60869a42015-04-01 12:09:17 -0700874 const SkString& path = fImages[fCurrentCodec];
Mike Klein88544fb2019-03-20 10:50:33 -0500875 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
mtklein6f0ff912016-01-11 09:04:21 -0800876 continue;
877 }
bungeman38d909e2016-08-02 14:40:46 -0700878 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400879 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
scroggo60869a42015-04-01 12:09:17 -0700880 if (!codec) {
881 // Nothing to time.
msarett9d9725c2015-04-24 11:41:55 -0700882 SkDebugf("Cannot find codec for %s\n", path.c_str());
scroggo60869a42015-04-01 12:09:17 -0700883 continue;
884 }
scroggo21027992015-04-02 13:22:38 -0700885
scroggo60869a42015-04-01 12:09:17 -0700886 while (fCurrentColorType < fColorTypes.count()) {
scroggo21027992015-04-02 13:22:38 -0700887 const SkColorType colorType = fColorTypes[fCurrentColorType];
scroggo21027992015-04-02 13:22:38 -0700888
msarettc7796b92016-01-07 14:20:20 -0800889 SkAlphaType alphaType = codec->getInfo().alphaType();
msarett67cb6662016-06-21 08:49:26 -0700890 if (FLAGS_simpleCodec) {
891 if (kUnpremul_SkAlphaType == alphaType) {
892 alphaType = kPremul_SkAlphaType;
893 }
894
895 fCurrentColorType++;
896 } else {
897 switch (alphaType) {
898 case kOpaque_SkAlphaType:
899 // We only need to test one alpha type (opaque).
msarettc7796b92016-01-07 14:20:20 -0800900 fCurrentColorType++;
msarett67cb6662016-06-21 08:49:26 -0700901 break;
902 case kUnpremul_SkAlphaType:
903 case kPremul_SkAlphaType:
904 if (0 == fCurrentAlphaType) {
905 // Test unpremul first.
906 alphaType = kUnpremul_SkAlphaType;
907 fCurrentAlphaType++;
908 } else {
909 // Test premul.
910 alphaType = kPremul_SkAlphaType;
911 fCurrentAlphaType = 0;
912 fCurrentColorType++;
913 }
914 break;
915 default:
916 SkASSERT(false);
917 fCurrentColorType++;
918 break;
919 }
scroggo21027992015-04-02 13:22:38 -0700920 }
921
msarettc7796b92016-01-07 14:20:20 -0800922 // Make sure we can decode to this color type and alpha type.
923 SkImageInfo info =
924 codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType);
scroggo21027992015-04-02 13:22:38 -0700925 const size_t rowBytes = info.minRowBytes();
Mike Reedf0ffb892017-10-03 14:47:21 -0400926 SkAutoMalloc storage(info.computeByteSize(rowBytes));
scroggo21027992015-04-02 13:22:38 -0700927
scroggoeb602a52015-07-09 08:16:03 -0700928 const SkCodec::Result result = codec->getPixels(
Leon Scroggins571b30f2017-07-11 17:35:31 +0000929 info, storage.get(), rowBytes);
scroggo60869a42015-04-01 12:09:17 -0700930 switch (result) {
scroggoeb602a52015-07-09 08:16:03 -0700931 case SkCodec::kSuccess:
932 case SkCodec::kIncompleteInput:
scroggo60869a42015-04-01 12:09:17 -0700933 return new CodecBench(SkOSPath::Basename(path.c_str()),
bungeman38d909e2016-08-02 14:40:46 -0700934 encoded.get(), colorType, alphaType);
scroggoeb602a52015-07-09 08:16:03 -0700935 case SkCodec::kInvalidConversion:
scroggo60869a42015-04-01 12:09:17 -0700936 // This is okay. Not all conversions are valid.
937 break;
scroggo60869a42015-04-01 12:09:17 -0700938 default:
939 // This represents some sort of failure.
940 SkASSERT(false);
941 break;
942 }
943 }
944 fCurrentColorType = 0;
945 }
946
msarett84451022016-02-11 06:45:51 -0800947 // Run AndroidCodecBenches
948 const int sampleSizes[] = { 2, 4, 8 };
949 for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) {
950 fSourceType = "image";
951 fBenchType = "skandroidcodec";
952
953 const SkString& path = fImages[fCurrentAndroidCodec];
Mike Klein88544fb2019-03-20 10:50:33 -0500954 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
msarett84451022016-02-11 06:45:51 -0800955 continue;
956 }
bungeman38d909e2016-08-02 14:40:46 -0700957 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400958 std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
msarett84451022016-02-11 06:45:51 -0800959 if (!codec) {
960 // Nothing to time.
961 SkDebugf("Cannot find codec for %s\n", path.c_str());
962 continue;
963 }
964
965 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) {
966 int sampleSize = sampleSizes[fCurrentSampleSize];
967 fCurrentSampleSize++;
Brian Osman788b9162020-02-07 10:36:46 -0500968 if (10 * sampleSize > std::min(codec->getInfo().width(), codec->getInfo().height())) {
msarett84451022016-02-11 06:45:51 -0800969 // Avoid benchmarking scaled decodes of already small images.
970 break;
971 }
972
bungeman38d909e2016-08-02 14:40:46 -0700973 return new AndroidCodecBench(SkOSPath::Basename(path.c_str()),
974 encoded.get(), sampleSize);
msarett84451022016-02-11 06:45:51 -0800975 }
976 fCurrentSampleSize = 0;
977 }
978
Leon Scroggins III87caae62020-05-04 10:02:45 -0400979#ifdef SK_ENABLE_ANDROID_UTILS
msarett7f691442015-09-22 11:56:16 -0700980 // Run the BRDBenches
msarett7f691442015-09-22 11:56:16 -0700981 // We intend to create benchmarks that model the use cases in
982 // android/libraries/social/tiledimage. In this library, an image is decoded in 512x512
983 // tiles. The image can be translated freely, so the location of a tile may be anywhere in
984 // the image. For that reason, we will benchmark decodes in five representative locations
985 // in the image. Additionally, this use case utilizes power of two scaling, so we will
986 // test on power of two sample sizes. The output tile is always 512x512, so, when a
987 // sampleSize is used, the size of the subset that is decoded is always
988 // (sampleSize*512)x(sampleSize*512).
989 // There are a few good reasons to only test on power of two sample sizes at this time:
msarett7f691442015-09-22 11:56:16 -0700990 // All use cases we are aware of only scale by powers of two.
991 // PNG decodes use the indicated sampling strategy regardless of the sample size, so
992 // these tests are sufficient to provide good coverage of our scaling options.
msarett84451022016-02-11 06:45:51 -0800993 const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 };
msarett7f691442015-09-22 11:56:16 -0700994 const uint32_t minOutputSize = 512;
mtklein6f0ff912016-01-11 09:04:21 -0800995 for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) {
msarettd1227a72016-05-18 06:23:57 -0700996 fSourceType = "image";
997 fBenchType = "BRD";
998
mtklein6f0ff912016-01-11 09:04:21 -0800999 const SkString& path = fImages[fCurrentBRDImage];
Mike Klein88544fb2019-03-20 10:50:33 -05001000 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
mtklein6f0ff912016-01-11 09:04:21 -08001001 continue;
1002 }
scroggo860e8a62015-10-15 07:51:28 -07001003
msarettd1227a72016-05-18 06:23:57 -07001004 while (fCurrentColorType < fColorTypes.count()) {
1005 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) {
1006 while (fCurrentSubsetType <= kLastSingle_SubsetType) {
scroggo860e8a62015-10-15 07:51:28 -07001007
bungeman38d909e2016-08-02 14:40:46 -07001008 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarettd1227a72016-05-18 06:23:57 -07001009 const SkColorType colorType = fColorTypes[fCurrentColorType];
1010 uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize];
1011 int currentSubsetType = fCurrentSubsetType++;
scroggo860e8a62015-10-15 07:51:28 -07001012
msarettd1227a72016-05-18 06:23:57 -07001013 int width = 0;
1014 int height = 0;
reed42943c82016-09-12 12:01:44 -07001015 if (!valid_brd_bench(encoded, colorType, sampleSize, minOutputSize,
msarettd1227a72016-05-18 06:23:57 -07001016 &width, &height)) {
1017 break;
msarett7f691442015-09-22 11:56:16 -07001018 }
msarettd1227a72016-05-18 06:23:57 -07001019
1020 SkString basename = SkOSPath::Basename(path.c_str());
1021 SkIRect subset;
1022 const uint32_t subsetSize = sampleSize * minOutputSize;
1023 switch (currentSubsetType) {
1024 case kTopLeft_SubsetType:
1025 basename.append("_TopLeft");
1026 subset = SkIRect::MakeXYWH(0, 0, subsetSize, subsetSize);
1027 break;
1028 case kTopRight_SubsetType:
1029 basename.append("_TopRight");
1030 subset = SkIRect::MakeXYWH(width - subsetSize, 0, subsetSize,
1031 subsetSize);
1032 break;
1033 case kMiddle_SubsetType:
1034 basename.append("_Middle");
1035 subset = SkIRect::MakeXYWH((width - subsetSize) / 2,
1036 (height - subsetSize) / 2, subsetSize, subsetSize);
1037 break;
1038 case kBottomLeft_SubsetType:
1039 basename.append("_BottomLeft");
1040 subset = SkIRect::MakeXYWH(0, height - subsetSize, subsetSize,
1041 subsetSize);
1042 break;
1043 case kBottomRight_SubsetType:
1044 basename.append("_BottomRight");
1045 subset = SkIRect::MakeXYWH(width - subsetSize,
1046 height - subsetSize, subsetSize, subsetSize);
1047 break;
1048 default:
1049 SkASSERT(false);
1050 }
1051
1052 return new BitmapRegionDecoderBench(basename.c_str(), encoded.get(),
1053 colorType, sampleSize, subset);
msarett7f691442015-09-22 11:56:16 -07001054 }
msarettd1227a72016-05-18 06:23:57 -07001055 fCurrentSubsetType = 0;
1056 fCurrentSampleSize++;
msarett7f691442015-09-22 11:56:16 -07001057 }
msarettd1227a72016-05-18 06:23:57 -07001058 fCurrentSampleSize = 0;
1059 fCurrentColorType++;
msarett7f691442015-09-22 11:56:16 -07001060 }
msarettd1227a72016-05-18 06:23:57 -07001061 fCurrentColorType = 0;
msarett7f691442015-09-22 11:56:16 -07001062 }
Leon Scroggins III87caae62020-05-04 10:02:45 -04001063#endif // SK_ENABLE_ANDROID_UTILS
msarett7f691442015-09-22 11:56:16 -07001064
halcanary96fcdcc2015-08-27 07:41:13 -07001065 return nullptr;
mtkleine714e752014-07-31 12:13:48 -07001066 }
mtklein92007582014-08-01 07:46:52 -07001067
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001068 void fillCurrentOptions(NanoJSONResultsWriter& log) const {
1069 log.appendString("source_type", fSourceType);
1070 log.appendString("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -07001071 if (0 == strcmp(fSourceType, "skp")) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001072 log.appendString("clip",
mtklein92007582014-08-01 07:46:52 -07001073 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
1074 fClip.fRight, fClip.fBottom).c_str());
djsollenf2b340f2016-01-29 08:51:04 -08001075 SkASSERT_RELEASE(fCurrentScale < fScales.count()); // debugging paranoia
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001076 log.appendString("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
mtklein92007582014-08-01 07:46:52 -07001077 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001078 }
1079
1080 void fillCurrentMetrics(NanoJSONResultsWriter& log) const {
mtklein051e56d2014-12-04 08:46:51 -08001081 if (0 == strcmp(fBenchType, "recording")) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001082 log.appendMetric("bytes", fSKPBytes);
1083 log.appendMetric("ops", fSKPOps);
mtklein051e56d2014-12-04 08:46:51 -08001084 }
mtklein92007582014-08-01 07:46:52 -07001085 }
1086
mtkleine714e752014-07-31 12:13:48 -07001087private:
Leon Scroggins III87caae62020-05-04 10:02:45 -04001088#ifdef SK_ENABLE_ANDROID_UTILS
msarettb23e6aa2015-06-09 13:56:10 -07001089 enum SubsetType {
1090 kTopLeft_SubsetType = 0,
1091 kTopRight_SubsetType = 1,
msarettab80e352015-06-17 10:28:22 -07001092 kMiddle_SubsetType = 2,
1093 kBottomLeft_SubsetType = 3,
1094 kBottomRight_SubsetType = 4,
1095 kTranslate_SubsetType = 5,
1096 kZoom_SubsetType = 6,
msarett7f691442015-09-22 11:56:16 -07001097 kLast_SubsetType = kZoom_SubsetType,
1098 kLastSingle_SubsetType = kBottomRight_SubsetType,
msarettb23e6aa2015-06-09 13:56:10 -07001099 };
Leon Scroggins III87caae62020-05-04 10:02:45 -04001100#endif
msarettb23e6aa2015-06-09 13:56:10 -07001101
mtkleine714e752014-07-31 12:13:48 -07001102 const BenchRegistry* fBenches;
1103 const skiagm::GMRegistry* fGMs;
mtklein92007582014-08-01 07:46:52 -07001104 SkIRect fClip;
1105 SkTArray<SkScalar> fScales;
1106 SkTArray<SkString> fSKPs;
fmalita6519c212016-09-14 08:05:17 -07001107 SkTArray<SkString> fSVGs;
Hal Canary5dfefa22019-10-24 13:52:17 -04001108 SkTArray<SkString> fTextBlobTraces;
msarett95f192d2015-02-13 09:05:41 -08001109 SkTArray<SkString> fImages;
msarett74deb982015-10-20 16:45:56 -07001110 SkTArray<SkColorType, true> fColorTypes;
cdalton63a82852015-06-29 14:06:10 -07001111 SkScalar fZoomMax;
1112 double fZoomPeriodMs;
mtklein92007582014-08-01 07:46:52 -07001113
Mike Klein88d90712018-01-27 17:30:04 +00001114 double fSKPBytes, fSKPOps;
mtklein051e56d2014-12-04 08:46:51 -08001115
mtkleinfd731ce2014-09-10 12:19:30 -07001116 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
1117 const char* fBenchType; // How we bench it: micro, recording, playback, ...
Hal Canary2362ae72019-10-24 13:40:40 -04001118 int fCurrentRecording = 0;
1119 int fCurrentDeserialPicture = 0;
1120 int fCurrentScale = 0;
1121 int fCurrentSKP = 0;
1122 int fCurrentSVG = 0;
Hal Canary5dfefa22019-10-24 13:52:17 -04001123 int fCurrentTextBlobTrace = 0;
Hal Canary2362ae72019-10-24 13:40:40 -04001124 int fCurrentCodec = 0;
1125 int fCurrentAndroidCodec = 0;
Leon Scroggins III87caae62020-05-04 10:02:45 -04001126#ifdef SK_ENABLE_ANDROID_UTILS
Hal Canary2362ae72019-10-24 13:40:40 -04001127 int fCurrentBRDImage = 0;
Leon Scroggins III87caae62020-05-04 10:02:45 -04001128 int fCurrentSubsetType = 0;
1129#endif
Hal Canary2362ae72019-10-24 13:40:40 -04001130 int fCurrentColorType = 0;
1131 int fCurrentAlphaType = 0;
Hal Canary2362ae72019-10-24 13:40:40 -04001132 int fCurrentSampleSize = 0;
1133 int fCurrentAnimSKP = 0;
mtkleine714e752014-07-31 12:13:48 -07001134};
1135
msarettc149f0e2016-01-04 11:35:43 -08001136// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1137// This prints something every once in a while so that it knows we're still working.
1138static void start_keepalive() {
Mike Klein03141d22017-10-30 11:57:15 -04001139 static std::thread* intentionallyLeaked = new std::thread([]{
1140 for (;;) {
1141 static const int kSec = 1200;
1142 #if defined(SK_BUILD_FOR_WIN)
1143 Sleep(kSec * 1000);
1144 #else
1145 sleep(kSec);
1146 #endif
1147 SkDebugf("\nBenchmarks still running...\n");
msarettc149f0e2016-01-04 11:35:43 -08001148 }
Mike Klein03141d22017-10-30 11:57:15 -04001149 });
1150 (void)intentionallyLeaked;
msarettc149f0e2016-01-04 11:35:43 -08001151}
1152
Mike Kleinbe28ee22017-02-06 12:46:20 -05001153int main(int argc, char** argv) {
Mike Klein88544fb2019-03-20 10:50:33 -05001154 CommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001155
Brian Osmanbc8150f2017-07-24 11:38:01 -04001156 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001157
Mike Kleinadacaef2017-02-06 09:26:14 -05001158#if defined(SK_BUILD_FOR_IOS)
1159 cd_Documents();
1160#endif
jcgregorio3b27ade2014-11-13 08:06:40 -08001161 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -07001162 SkAutoGraphics ag;
mtkleincc29d262015-07-09 10:04:56 -07001163 SkTaskGroup::Enabler enabled(FLAGS_threads);
mtkleinf3723212014-06-25 14:08:00 -07001164
Chris Dalton040238b2017-12-18 14:22:34 -07001165 SetCtxOptionsFromCommonFlags(&grContextOpts);
krajcevski69a55602014-08-13 10:46:31 -07001166
bsalomon6eb03cc2014-08-07 14:28:50 -07001167 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -07001168 FLAGS_samples = 1;
1169 FLAGS_gpuFrameLag = 0;
1170 }
1171
bsalomon6eb03cc2014-08-07 14:28:50 -07001172 if (!FLAGS_writePath.isEmpty()) {
1173 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
1174 if (!sk_mkdir(FLAGS_writePath[0])) {
1175 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
halcanary96fcdcc2015-08-27 07:41:13 -07001176 FLAGS_writePath.set(0, nullptr);
bsalomon6eb03cc2014-08-07 14:28:50 -07001177 }
1178 }
1179
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001180 std::unique_ptr<SkWStream> logStream(new SkNullWStream);
mtklein60317d0f2014-07-14 11:30:37 -07001181 if (!FLAGS_outResultsFile.isEmpty()) {
mtklein53520152016-01-20 09:53:59 -08001182#if defined(SK_RELEASE)
Chris Dalton2e1381e2019-10-23 14:35:19 -06001183 // SkJSONWriter uses a 32k in-memory cache, so it only flushes occasionally and is well
1184 // equipped for a stream that re-opens, appends, and closes the file on every write.
1185 logStream.reset(new NanoFILEAppendAndCloseStream(FLAGS_outResultsFile[0]));
mtklein53520152016-01-20 09:53:59 -08001186#else
1187 SkDebugf("I'm ignoring --outResultsFile because this is a Debug build.");
1188 return 1;
1189#endif
mtklein60317d0f2014-07-14 11:30:37 -07001190 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001191 NanoJSONResultsWriter log(logStream.get(), SkJSONWriter::Mode::kPretty);
1192 log.beginObject(); // root
mtklein1915b622014-08-20 11:45:00 -07001193
1194 if (1 == FLAGS_properties.count() % 2) {
1195 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
1196 return 1;
1197 }
1198 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001199 log.appendString(FLAGS_properties[i-1], FLAGS_properties[i]);
mtklein1915b622014-08-20 11:45:00 -07001200 }
jcgregoriobf5e5232014-07-17 13:14:16 -07001201
1202 if (1 == FLAGS_key.count() % 2) {
1203 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
1204 return 1;
1205 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001206 if (FLAGS_key.count()) {
1207 log.beginObject("key");
1208 for (int i = 1; i < FLAGS_key.count(); i += 2) {
1209 log.appendString(FLAGS_key[i - 1], FLAGS_key[i]);
1210 }
1211 log.endObject(); // key
mtklein94e51562014-08-19 12:41:53 -07001212 }
mtklein60317d0f2014-07-14 11:30:37 -07001213
mtkleinf3723212014-06-25 14:08:00 -07001214 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -07001215 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -04001216
cdaltone1b89582015-06-25 19:17:08 -07001217 SkTArray<double> samples;
mtkleinbb6a0282014-07-01 08:43:42 -07001218
bsalomon6eb03cc2014-08-07 14:28:50 -07001219 if (kAutoTuneLoops != FLAGS_loops) {
1220 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleinf3723212014-06-25 14:08:00 -07001221 } else if (FLAGS_quiet) {
mtklein66cfcff2015-12-04 06:35:30 -08001222 SkDebugf("! -> high variance, ? -> moderate variance\n");
1223 SkDebugf(" micros \tbench\n");
mtkleinbbba1682015-10-28 11:36:30 -07001224 } else if (FLAGS_ms) {
cdaltone1b89582015-06-25 19:17:08 -07001225 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n");
mtkleinf3723212014-06-25 14:08:00 -07001226 } else {
mtkleind75c4662015-04-30 07:11:22 -07001227 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
qiankun.miao8247ec32014-09-09 19:24:36 -07001228 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -07001229 }
1230
svaisanenc47635e2016-01-28 06:05:43 -08001231 SkTArray<Config> configs;
bsalomonc2553372014-07-22 13:09:05 -07001232 create_configs(&configs);
1233
msarettc149f0e2016-01-04 11:35:43 -08001234 if (FLAGS_keepAlive) {
1235 start_keepalive();
1236 }
1237
Mike Klein03fa5d42019-03-22 11:39:09 -05001238 SetAnalyticAAFromCommonFlags();
liyuqian38911a72016-10-04 11:23:22 -07001239
Mike Klein813e8cc2020-08-05 09:33:38 -05001240 gSkForceRasterPipelineBlitter = FLAGS_forceRasterPipeline;
1241 gUseSkVMBlitter = FLAGS_skvm;
1242 gSkVMAllowJIT = gSkVMJITViaDylib = FLAGS_jit;
Yuqian Li550148b2017-01-13 10:13:13 -05001243
mtkleine070c2b2014-10-14 08:40:43 -07001244 int runs = 0;
mtklein92007582014-08-01 07:46:52 -07001245 BenchmarkStream benchStream;
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001246 log.beginObject("results");
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001247 AutoreleasePool pool;
mtklein92007582014-08-01 07:46:52 -07001248 while (Benchmark* b = benchStream.next()) {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001249 std::unique_ptr<Benchmark> bench(b);
Mike Klein88544fb2019-03-20 10:50:33 -05001250 if (CommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -07001251 continue;
1252 }
1253
svaisanenc47635e2016-01-28 06:05:43 -08001254 if (!configs.empty()) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001255 log.beginBench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
joshualitt8a6697a2015-09-30 12:11:07 -07001256 bench->delayedSetup();
jcgregoriobf5e5232014-07-17 13:14:16 -07001257 }
egdaniel3bf92062015-06-26 08:12:46 -07001258 for (int i = 0; i < configs.count(); ++i) {
1259 Target* target = is_enabled(b, configs[i]);
1260 if (!target) {
1261 continue;
1262 }
mtkleinf3723212014-06-25 14:08:00 -07001263
halcanary96fcdcc2015-08-27 07:41:13 -07001264 // During HWUI output this canvas may be nullptr.
egdaniel3bf92062015-06-26 08:12:46 -07001265 SkCanvas* canvas = target->getCanvas();
svaisanenc47635e2016-01-28 06:05:43 -08001266 const char* config = target->config.name.c_str();
egdaniel3bf92062015-06-26 08:12:46 -07001267
brianosman7a5ada82016-02-08 13:49:12 -08001268 if (FLAGS_pre_log || FLAGS_dryRun) {
benjaminwagner8d61f0d2016-01-25 13:02:40 -08001269 SkDebugf("Running %s\t%s\n"
1270 , bench->getUniqueName()
1271 , config);
brianosman7a5ada82016-02-08 13:49:12 -08001272 if (FLAGS_dryRun) {
1273 continue;
1274 }
benjaminwagner8d61f0d2016-01-25 13:02:40 -08001275 }
1276
Mike Kleinee254232019-03-28 08:32:14 -05001277 if (FLAGS_purgeBetweenBenches) {
1278 SkGraphics::PurgeAllCaches();
1279 }
1280
Brian Osman5ad87aa2017-09-08 16:05:23 -04001281 TRACE_EVENT2("skia", "Benchmark", "name", TRACE_STR_COPY(bench->getUniqueName()),
1282 "config", TRACE_STR_COPY(config));
Brian Osmanc3cdef52017-08-31 14:09:22 -04001283
egdaniel3bf92062015-06-26 08:12:46 -07001284 target->setup();
robertphillips5b693772014-11-21 06:19:36 -08001285 bench->perCanvasPreDraw(canvas);
1286
cdaltone1b89582015-06-25 19:17:08 -07001287 int maxFrameLag;
mtkleina1ebeb22015-10-01 09:43:39 -07001288 int loops = target->needsFrameTiming(&maxFrameLag)
egdaniel3bf92062015-06-26 08:12:46 -07001289 ? setup_gpu_bench(target, bench.get(), maxFrameLag)
1290 : setup_cpu_bench(overhead, target, bench.get());
cdaltone1b89582015-06-25 19:17:08 -07001291
Leon Scroggins IIIb30d1132017-10-02 09:48:15 -04001292 if (kFailedLoops == loops) {
1293 // Can't be timed. A warning note has already been printed.
1294 cleanup_run(target);
1295 continue;
1296 }
1297
Yuqian Li3528eb32017-09-21 13:23:49 -04001298 if (runs == 0 && FLAGS_ms < 1000) {
1299 // Run the first bench for 1000ms to warm up the nanobench if FLAGS_ms < 1000.
1300 // Otherwise, the first few benches' measurements will be inaccurate.
1301 auto stop = now_ms() + 1000;
1302 do {
1303 time(loops, bench.get(), target);
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001304 pool.drain();
Yuqian Li3528eb32017-09-21 13:23:49 -04001305 } while (now_ms() < stop);
1306 }
1307
mtkleinbbba1682015-10-28 11:36:30 -07001308 if (FLAGS_ms) {
1309 samples.reset();
1310 auto stop = now_ms() + FLAGS_ms;
1311 do {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001312 samples.push_back(time(loops, bench.get(), target) / loops);
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001313 pool.drain();
mtkleinbbba1682015-10-28 11:36:30 -07001314 } while (now_ms() < stop);
1315 } else {
cdaltone1b89582015-06-25 19:17:08 -07001316 samples.reset(FLAGS_samples);
1317 for (int s = 0; s < FLAGS_samples; s++) {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001318 samples[s] = time(loops, bench.get(), target) / loops;
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001319 pool.drain();
cdaltone1b89582015-06-25 19:17:08 -07001320 }
cdaltone1b89582015-06-25 19:17:08 -07001321 }
mtkleinf3723212014-06-25 14:08:00 -07001322
Mike Kleinfec9b902019-05-31 10:03:07 -05001323 // Scale each result to the benchmark's own units, time/unit.
1324 for (double& sample : samples) {
1325 sample *= (1.0 / bench->getUnits());
1326 }
1327
joshualitte45c81c2015-12-02 09:05:37 -08001328 SkTArray<SkString> keys;
1329 SkTArray<double> values;
1330 bool gpuStatsDump = FLAGS_gpuStatsDump && Benchmark::kGPU_Backend == configs[i].backend;
1331 if (gpuStatsDump) {
1332 // TODO cache stats
1333 bench->getGpuStats(canvas, &keys, &values);
1334 }
joshualitte45c81c2015-12-02 09:05:37 -08001335
robertphillips5b693772014-11-21 06:19:36 -08001336 bench->perCanvasPostDraw(canvas);
1337
egdaniel3bf92062015-06-26 08:12:46 -07001338 if (Benchmark::kNonRendering_Backend != target->config.backend &&
tomhudsond968a6f2015-03-26 11:28:06 -07001339 !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -07001340 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -07001341 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -07001342 pngFilename.append(".png");
egdaniel3bf92062015-06-26 08:12:46 -07001343 write_canvas_png(target, pngFilename);
bsalomon6eb03cc2014-08-07 14:28:50 -07001344 }
1345
Mike Klein512a2442018-09-27 10:44:56 -04001346 // Building stats.plot often shows up in profiles,
1347 // so skip building it when we're not going to print it anyway.
1348 const bool want_plot = !FLAGS_quiet;
1349
1350 Stats stats(samples, want_plot);
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001351 log.beginObject(config);
1352
1353 log.beginObject("options");
1354 log.appendString("name", bench->getName());
1355 benchStream.fillCurrentOptions(log);
1356 target->fillOptions(log);
1357 log.endObject(); // options
1358
1359 // Metrics
1360 log.appendMetric("min_ms", stats.min);
1361 log.beginArray("samples");
1362 for (double sample : samples) {
1363 log.appendDoubleDigits(sample, 16);
1364 }
1365 log.endArray(); // samples
1366 benchStream.fillCurrentMetrics(log);
joshualitte45c81c2015-12-02 09:05:37 -08001367 if (gpuStatsDump) {
1368 // dump to json, only SKPBench currently returns valid keys / values
1369 SkASSERT(keys.count() == values.count());
1370 for (int i = 0; i < keys.count(); i++) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001371 log.appendMetric(keys[i].c_str(), values[i]);
joshualitte45c81c2015-12-02 09:05:37 -08001372 }
1373 }
joshualitte45c81c2015-12-02 09:05:37 -08001374
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001375 log.endObject(); // config
1376
mtkleine070c2b2014-10-14 08:40:43 -07001377 if (runs++ % FLAGS_flushEvery == 0) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001378 log.flush();
mtkleine070c2b2014-10-14 08:40:43 -07001379 }
mtklein60317d0f2014-07-14 11:30:37 -07001380
bsalomon6eb03cc2014-08-07 14:28:50 -07001381 if (kAutoTuneLoops != FLAGS_loops) {
egdaniel3bf92062015-06-26 08:12:46 -07001382 if (configs.count() == 1) {
mtkleina189ccd2014-07-14 12:28:47 -07001383 config = ""; // Only print the config if we run the same bench on more than one.
1384 }
mtkleind75c4662015-04-30 07:11:22 -07001385 SkDebugf("%4d/%-4dMB\t%s\t%s\n"
1386 , sk_tools::getCurrResidentSetSizeMB()
1387 , sk_tools::getMaxResidentSetSizeMB()
mtklein53d25622014-09-18 07:39:42 -07001388 , bench->getUniqueName()
1389 , config);
mtkleinf3723212014-06-25 14:08:00 -07001390 } else if (FLAGS_quiet) {
mtklein66cfcff2015-12-04 06:35:30 -08001391 const char* mark = " ";
Hal Canarye99e8da2019-01-14 16:34:50 -05001392 const double stddev_percent =
1393 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
mtklein66cfcff2015-12-04 06:35:30 -08001394 if (stddev_percent > 5) mark = "?";
1395 if (stddev_percent > 10) mark = "!";
1396
1397 SkDebugf("%10.2f %s\t%s\t%s\n",
1398 stats.median*1e3, mark, bench->getUniqueName(), config);
Mike Reedc665e5b2017-07-04 22:56:06 -04001399 } else if (FLAGS_csv) {
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("%g,%g,%g,%g,%g,%s,%s\n"
1403 , stats.min
1404 , stats.median
1405 , stats.mean
1406 , stats.max
1407 , stddev_percent
1408 , config
1409 , bench->getUniqueName()
1410 );
1411 } else {
1412 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 -05001413 const double stddev_percent =
1414 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
Mike Reedc665e5b2017-07-04 22:56:06 -04001415 SkDebugf(format
mtkleind75c4662015-04-30 07:11:22 -07001416 , sk_tools::getCurrResidentSetSizeMB()
1417 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -07001418 , loops
mtklein55b0ffc2014-07-17 08:38:23 -07001419 , HUMANIZE(stats.min)
1420 , HUMANIZE(stats.median)
1421 , HUMANIZE(stats.mean)
1422 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -07001423 , stddev_percent
mtkleinbbba1682015-10-28 11:36:30 -07001424 , FLAGS_ms ? to_string(samples.count()).c_str() : stats.plot.c_str()
mtkleinf3723212014-06-25 14:08:00 -07001425 , config
mtklein96289052014-09-10 12:05:59 -07001426 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -07001427 );
1428 }
joshualitte45c81c2015-12-02 09:05:37 -08001429
joshualitte45c81c2015-12-02 09:05:37 -08001430 if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -04001431 target->dumpStats();
bsalomon06cddec2014-10-24 10:40:50 -07001432 }
joshualitte45c81c2015-12-02 09:05:37 -08001433
cdalton2c56ba52015-06-26 13:32:53 -07001434 if (FLAGS_verbose) {
1435 SkDebugf("Samples: ");
1436 for (int i = 0; i < samples.count(); i++) {
1437 SkDebugf("%s ", HUMANIZE(samples[i]));
1438 }
1439 SkDebugf("%s\n", bench->getUniqueName());
1440 }
egdaniel3bf92062015-06-26 08:12:46 -07001441 cleanup_run(target);
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001442 pool.drain();
mtkleinf3723212014-06-25 14:08:00 -07001443 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001444 if (!configs.empty()) {
1445 log.endBench();
1446 }
mtkleinf3723212014-06-25 14:08:00 -07001447 }
1448
Herb Derby5a523fe2017-01-26 16:48:28 -05001449 SkGraphics::PurgeAllCaches();
1450
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001451 log.beginBench("memory_usage", 0, 0);
1452 log.beginObject("meta"); // config
1453 log.appendS32("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
1454 log.endObject(); // config
1455 log.endBench();
1456
Brian Osman68870aa2020-07-08 14:12:43 -04001457 RunSkSLMemoryBenchmarks(&log);
1458
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001459 log.endObject(); // results
1460 log.endObject(); // root
1461 log.flush();
mtkleine1091452014-12-04 10:47:02 -08001462
mtkleinf3723212014-06-25 14:08:00 -07001463 return 0;
1464}