blob: b734b8a44ae79b42996a7dba39ac0c183d0e26c5 [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "include/codec/SkAndroidCodec.h"
23#include "include/codec/SkCodec.h"
24#include "include/core/SkCanvas.h"
25#include "include/core/SkData.h"
26#include "include/core/SkGraphics.h"
27#include "include/core/SkPictureRecorder.h"
28#include "include/core/SkString.h"
29#include "include/core/SkSurface.h"
Ben Wagneracf98df2019-07-12 12:51:44 -040030#include "include/core/SkTime.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050031#include "src/core/SkAutoMalloc.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050032#include "src/core/SkColorSpacePriv.h"
Ben Wagnerab6eefe2019-05-20 11:02:49 -040033#include "src/core/SkLeanWindows.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050034#include "src/core/SkOSFile.h"
35#include "src/core/SkTaskGroup.h"
36#include "src/core/SkTraceEvent.h"
37#include "src/utils/SkJSONWriter.h"
38#include "src/utils/SkOSPath.h"
Jim Van Verth8a9a3712019-05-31 10:49:12 -040039#include "tools/AutoreleasePool.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050040#include "tools/CrashHandler.h"
41#include "tools/ProcStats.h"
42#include "tools/Stats.h"
43#include "tools/flags/CommonFlags.h"
44#include "tools/flags/CommonFlagsConfig.h"
45#include "tools/ios_utils.h"
46#include "tools/trace/EventTracingPriv.h"
47#include "tools/trace/SkDebugfTracer.h"
mtkleinf3723212014-06-25 14:08:00 -070048
Hal Canary0f666812018-03-22 15:21:12 -040049#ifdef SK_XML
Mike Kleinc0bd9f92019-04-23 12:05:21 -050050#include "experimental/svg/model/SkSVGDOM.h"
Hal Canary0f666812018-03-22 15:21:12 -040051#endif // SK_XML
52
Leon Scroggins III87caae62020-05-04 10:02:45 -040053#ifdef SK_ENABLE_ANDROID_UTILS
54#include "bench/BitmapRegionDecoderBench.h"
55#include "client_utils/android/BitmapRegionDecoder.h"
56#endif
57
Adlai Holler684838f2020-05-12 10:41:04 -040058#include <cinttypes>
bungeman60e0fee2015-08-26 05:15:46 -070059#include <stdlib.h>
Mike Klein03141d22017-10-30 11:57:15 -040060#include <thread>
bungeman60e0fee2015-08-26 05:15:46 -070061
Mike Reedc928fe22017-06-05 10:20:31 -040062extern bool gSkForceRasterPipelineBlitter;
Mike Klein2a57e792020-01-14 12:47:52 -060063extern bool gUseSkVMBlitter;
Mike Kleinea4459d2020-01-16 13:05:04 -060064extern bool gSkVMJITViaDylib;
Mike Reedc928fe22017-06-05 10:20:31 -040065
Mike Klein8f11d4d2018-01-24 12:42:55 -050066#ifndef SK_BUILD_FOR_WIN
scroggo38ce0a72016-01-07 07:28:47 -080067 #include <unistd.h>
Brian Salomon032aaae2018-03-23 16:10:36 -040068
scroggo38ce0a72016-01-07 07:28:47 -080069#endif
70
Mike Kleinc0bd9f92019-04-23 12:05:21 -050071#include "src/gpu/GrCaps.h"
72#include "src/gpu/GrContextPriv.h"
73#include "src/gpu/SkGr.h"
74#include "src/gpu/gl/GrGLDefines.h"
75#include "src/gpu/gl/GrGLGpu.h"
76#include "src/gpu/gl/GrGLUtil.h"
77#include "tools/gpu/GrContextFactory.h"
Brian Salomon032aaae2018-03-23 16:10:36 -040078
Brian Osmanc7ad40f2018-05-31 14:27:17 -040079using sk_gpu_test::ContextInfo;
80using sk_gpu_test::GrContextFactory;
81using sk_gpu_test::TestContext;
Brian Salomon032aaae2018-03-23 16:10:36 -040082
Brian Osmanc7ad40f2018-05-31 14:27:17 -040083GrContextOptions grContextOpts;
bsalomon682c2692015-05-22 14:01:46 -070084
reed53249782014-10-10 09:09:52 -070085static const int kAutoTuneLoops = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -070086
bsalomon6eb03cc2014-08-07 14:28:50 -070087static SkString loops_help_txt() {
88 SkString help;
89 help.printf("Number of times to run each bench. Set this to %d to auto-"
90 "tune for each bench. Timings are only reported when auto-tuning.",
91 kAutoTuneLoops);
92 return help;
93}
94
cdaltone1b89582015-06-25 19:17:08 -070095static SkString to_string(int n) {
96 SkString str;
97 str.appendS32(n);
98 return str;
99}
100
Mike Kleinac8f4432019-07-01 10:15:32 -0500101static DEFINE_int(loops, kAutoTuneLoops, loops_help_txt().c_str());
bsalomon6eb03cc2014-08-07 14:28:50 -0700102
Mike Klein5b3f3432019-03-21 11:42:21 -0500103static DEFINE_int(samples, 10, "Number of samples to measure for each bench.");
104static DEFINE_int(ms, 0, "If >0, run each bench for this many ms instead of obeying --samples.");
105static DEFINE_int(overheadLoops, 100000, "Loops to estimate timer overhead.");
Mike Klein84836b72019-03-21 11:31:36 -0500106static DEFINE_double(overheadGoal, 0.0001,
mtkleinf3723212014-06-25 14:08:00 -0700107 "Loop until timer overhead is at most this fraction of our measurments.");
Mike Klein84836b72019-03-21 11:31:36 -0500108static DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500109static DEFINE_int(gpuFrameLag, 5,
Mike Klein84836b72019-03-21 11:31:36 -0500110 "If unknown, estimated maximum number of frames GPU allows to lag.");
mtkleinf3723212014-06-25 14:08:00 -0700111
Mike Klein84836b72019-03-21 11:31:36 -0500112static DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500113static DEFINE_int(maxCalibrationAttempts, 3,
mtklein55b0ffc2014-07-17 08:38:23 -0700114 "Try up to this many times to guess loops for a bench, or skip the bench.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500115static DEFINE_int(maxLoops, 1000000, "Never run a bench more times than this.");
Mike Klein84836b72019-03-21 11:31:36 -0500116static DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
117static DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
118static DEFINE_string(zoom, "1.0,0",
119 "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom "
120 "function that ping-pongs between 1.0 and zoomMax.");
121static DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
Mike Klein84836b72019-03-21 11:31:36 -0500122static DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
123static DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?");
Mike Klein5b3f3432019-03-21 11:42:21 -0500124static DEFINE_int(flushEvery, 10, "Flush --outResultsFile every Nth run.");
Mike Klein84836b72019-03-21 11:31:36 -0500125static DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
126static DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json");
127static DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out");
128static DEFINE_bool(csv, false, "Print status in CSV format");
129static DEFINE_string(sourceType, "",
mtklein65dfd2f2016-02-03 10:40:54 -0800130 "Apply usual --match rules to source type: bench, gm, skp, image, etc.");
Mike Klein84836b72019-03-21 11:31:36 -0500131static DEFINE_string(benchType, "",
132 "Apply usual --match rules to bench type: micro, recording, "
133 "piping, playback, skcodec, etc.");
mtklein65dfd2f2016-02-03 10:40:54 -0800134
Mike Klein84836b72019-03-21 11:31:36 -0500135static DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
Mike Kleinea4459d2020-01-16 13:05:04 -0600136static DEFINE_bool(skvm, false, "sets gUseSkVMBlitter and gSkVMJITViaDylib");
Mike Reedc928fe22017-06-05 10:20:31 -0400137
Mike Klein19fb3972019-03-21 13:08:08 -0500138static DEFINE_bool2(pre_log, p, false,
139 "Log before running each test. May be incomprehensible when threading");
140
Mike Klein629f5fc2019-03-22 14:55:19 -0500141static DEFINE_bool(cpu, true, "master switch for running CPU-bound work.");
142static DEFINE_bool(gpu, true, "master switch for running GPU-bound work.");
143static DEFINE_bool(dryRun, false,
144 "just print the tests that would be run, without actually running them.");
145static DEFINE_string(images, "",
146 "List of images and/or directories to decode. A directory with no images"
147 " is treated as a fatal error.");
148static DEFINE_bool(simpleCodec, false,
149 "Runs of a subset of the codec tests, always N32, Premul or Opaque");
150
Mike Kleinc6142d82019-03-25 10:54:59 -0500151static DEFINE_string2(match, m, nullptr,
152 "[~][^]substring[$] [...] of name to run.\n"
153 "Multiple matches may be separated by spaces.\n"
154 "~ causes a matching name to always be skipped\n"
155 "^ requires the start of the name to match\n"
156 "$ requires the end of the name to match\n"
157 "^ and $ requires an exact match\n"
158 "If a name does not match any list entry,\n"
159 "it is skipped unless some list entry starts with ~");
160
161static DEFINE_bool2(quiet, q, false, "if true, don't print status updates.");
162static DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
163
164
165static DEFINE_string(skps, "skps", "Directory to read skps from.");
166static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file.");
Hal Canary5dfefa22019-10-24 13:52:17 -0400167static DEFINE_string(texttraces, "", "Directory to read TextBlobTrace files from.");
Mike Kleinc6142d82019-03-25 10:54:59 -0500168
169static DEFINE_int_2(threads, j, -1,
170 "Run threadsafe tests on a threadpool with this many extra threads, "
171 "defaulting to one extra thread per core.");
172
173static DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs.");
174
175static DEFINE_string(key, "",
176 "Space-separated key/value pairs to add to JSON identifying this builder.");
177static DEFINE_string(properties, "",
178 "Space-separated key/value pairs to add to JSON identifying this run.");
179
Mike Kleinee254232019-03-28 08:32:14 -0500180static DEFINE_bool(purgeBetweenBenches, false,
181 "Call SkGraphics::PurgeAllCaches() between each benchmark?");
182
mtkleinbbba1682015-10-28 11:36:30 -0700183static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
184
mtkleinf3723212014-06-25 14:08:00 -0700185static SkString humanize(double ms) {
Adlai Holler684838f2020-05-12 10:41:04 -0400186 if (FLAGS_verbose) return SkStringPrintf("%" PRIu64, (uint64_t)(ms*1e6));
mtklein748ca3b2015-01-15 10:56:12 -0800187 return HumanizeMs(ms);
mtkleinf3723212014-06-25 14:08:00 -0700188}
mtklein55b0ffc2014-07-17 08:38:23 -0700189#define HUMANIZE(ms) humanize(ms).c_str()
mtkleinf3723212014-06-25 14:08:00 -0700190
tomhudsond968a6f2015-03-26 11:28:06 -0700191bool Target::init(SkImageInfo info, Benchmark* bench) {
192 if (Benchmark::kRaster_Backend == config.backend) {
reede8f30622016-03-23 18:59:25 -0700193 this->surface = SkSurface::MakeRaster(info);
194 if (!this->surface) {
tomhudsond968a6f2015-03-26 11:28:06 -0700195 return false;
196 }
197 }
198 return true;
199}
200bool Target::capturePixels(SkBitmap* bmp) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700201 SkCanvas* canvas = this->getCanvas();
tomhudsond968a6f2015-03-26 11:28:06 -0700202 if (!canvas) {
203 return false;
204 }
Mike Reed12e946b2017-04-17 10:53:29 -0400205 bmp->allocPixels(canvas->imageInfo());
206 if (!canvas->readPixels(*bmp, 0, 0)) {
tomhudsond968a6f2015-03-26 11:28:06 -0700207 SkDebugf("Can't read canvas pixels.\n");
208 return false;
209 }
210 return true;
211}
212
tomhudsond968a6f2015-03-26 11:28:06 -0700213struct GPUTarget : public Target {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400214 explicit GPUTarget(const Config& c) : Target(c) {}
215 ContextInfo contextInfo;
216 std::unique_ptr<GrContextFactory> factory;
tomhudsond968a6f2015-03-26 11:28:06 -0700217
218 void setup() override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400219 this->contextInfo.testContext()->makeCurrent();
tomhudsond968a6f2015-03-26 11:28:06 -0700220 // Make sure we're done with whatever came before.
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400221 this->contextInfo.testContext()->finish();
tomhudsond968a6f2015-03-26 11:28:06 -0700222 }
223 void endTiming() override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400224 if (this->contextInfo.testContext()) {
Greg Daniel02497d42020-02-21 15:46:27 -0500225 this->contextInfo.testContext()->flushAndWaitOnSync(contextInfo.grContext());
tomhudsond968a6f2015-03-26 11:28:06 -0700226 }
227 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400228 void fence() override { this->contextInfo.testContext()->finish(); }
mtkleind75c4662015-04-30 07:11:22 -0700229
cdaltond416a5b2015-06-23 13:23:44 -0700230 bool needsFrameTiming(int* maxFrameLag) const override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400231 if (!this->contextInfo.testContext()->getMaxGpuFrameLag(maxFrameLag)) {
cdaltond416a5b2015-06-23 13:23:44 -0700232 // Frame lag is unknown.
233 *maxFrameLag = FLAGS_gpuFrameLag;
234 }
235 return true;
236 }
tomhudsond968a6f2015-03-26 11:28:06 -0700237 bool init(SkImageInfo info, Benchmark* bench) override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400238 GrContextOptions options = grContextOpts;
239 bench->modifyGrContextOptions(&options);
240 this->factory.reset(new GrContextFactory(options));
bsalomonafcd7cd2015-08-31 12:39:41 -0700241 uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag :
242 0;
tomhudsond968a6f2015-03-26 11:28:06 -0700243 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400244 this->surface = SkSurface::MakeRenderTarget(
245 this->factory->get(this->config.ctxType, this->config.ctxOverrides),
246 SkBudgeted::kNo, info, this->config.samples, &props);
247 this->contextInfo =
248 this->factory->getContextInfo(this->config.ctxType, this->config.ctxOverrides);
tomhudsond968a6f2015-03-26 11:28:06 -0700249 if (!this->surface.get()) {
250 return false;
251 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400252 if (!this->contextInfo.testContext()->fenceSyncSupport()) {
cdaltond416a5b2015-06-23 13:23:44 -0700253 SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. "
svaisanenc47635e2016-01-28 06:05:43 -0800254 "Timings might not be accurate.\n", this->config.name.c_str());
cdaltond416a5b2015-06-23 13:23:44 -0700255 }
tomhudsond968a6f2015-03-26 11:28:06 -0700256 return true;
257 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500258 void fillOptions(NanoJSONResultsWriter& log) override {
Brian Salomonf4ba4ec2020-03-19 15:54:28 -0400259#ifdef SK_GL
tomhudsond968a6f2015-03-26 11:28:06 -0700260 const GrGLubyte* version;
Greg Danielbdf12ad2018-10-12 09:31:11 -0400261 if (this->contextInfo.backend() == GrBackendApi::kOpenGL) {
Brian Salomon032aaae2018-03-23 16:10:36 -0400262 const GrGLInterface* gl =
Robert Phillips9da87e02019-02-04 13:26:26 -0500263 static_cast<GrGLGpu*>(this->contextInfo.grContext()->priv().getGpu())
Brian Salomon032aaae2018-03-23 16:10:36 -0400264 ->glInterface();
bsalomonc8699322016-05-11 11:55:36 -0700265 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VERSION));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500266 log.appendString("GL_VERSION", (const char*)(version));
tomhudsond968a6f2015-03-26 11:28:06 -0700267
bsalomonc8699322016-05-11 11:55:36 -0700268 GR_GL_CALL_RET(gl, version, GetString(GR_GL_RENDERER));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500269 log.appendString("GL_RENDERER", (const char*) version);
tomhudsond968a6f2015-03-26 11:28:06 -0700270
bsalomonc8699322016-05-11 11:55:36 -0700271 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VENDOR));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500272 log.appendString("GL_VENDOR", (const char*) version);
tomhudsond968a6f2015-03-26 11:28:06 -0700273
bsalomonc8699322016-05-11 11:55:36 -0700274 GR_GL_CALL_RET(gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500275 log.appendString("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
bsalomonc8699322016-05-11 11:55:36 -0700276 }
Brian Salomonf4ba4ec2020-03-19 15:54:28 -0400277#endif
tomhudsond968a6f2015-03-26 11:28:06 -0700278 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400279
280 void dumpStats() override {
Robert Phillips9da87e02019-02-04 13:26:26 -0500281 this->contextInfo.grContext()->priv().printCacheStats();
282 this->contextInfo.grContext()->priv().printGpuStats();
Robert Phillips273f1072020-05-05 13:03:07 -0400283 this->contextInfo.grContext()->priv().printContextStats();
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400284 }
tomhudsond968a6f2015-03-26 11:28:06 -0700285};
mtkleind75c4662015-04-30 07:11:22 -0700286
tomhudson75a0ebb2015-03-27 12:11:44 -0700287static double time(int loops, Benchmark* bench, Target* target) {
288 SkCanvas* canvas = target->getCanvas();
bsalomon6eb03cc2014-08-07 14:28:50 -0700289 if (canvas) {
290 canvas->clear(SK_ColorWHITE);
291 }
joshualitt8a6697a2015-09-30 12:11:07 -0700292 bench->preDraw(canvas);
mtkleinbbba1682015-10-28 11:36:30 -0700293 double start = now_ms();
tomhudson75a0ebb2015-03-27 12:11:44 -0700294 canvas = target->beginTiming(canvas);
295 bench->draw(loops, canvas);
tomhudson75a0ebb2015-03-27 12:11:44 -0700296 target->endTiming();
mtkleinbbba1682015-10-28 11:36:30 -0700297 double elapsed = now_ms() - start;
joshualitt8a6697a2015-09-30 12:11:07 -0700298 bench->postDraw(canvas);
mtkleinbbba1682015-10-28 11:36:30 -0700299 return elapsed;
mtkleinbb6a0282014-07-01 08:43:42 -0700300}
301
mtkleinf3723212014-06-25 14:08:00 -0700302static double estimate_timer_overhead() {
303 double overhead = 0;
mtkleinf3723212014-06-25 14:08:00 -0700304 for (int i = 0; i < FLAGS_overheadLoops; i++) {
mtkleinbbba1682015-10-28 11:36:30 -0700305 double start = now_ms();
306 overhead += now_ms() - start;
mtkleinf3723212014-06-25 14:08:00 -0700307 }
308 return overhead / FLAGS_overheadLoops;
309}
310
reed53249782014-10-10 09:09:52 -0700311static int detect_forever_loops(int loops) {
312 // look for a magic run-forever value
313 if (loops < 0) {
314 loops = SK_MaxS32;
315 }
316 return loops;
317}
318
mtklein55b0ffc2014-07-17 08:38:23 -0700319static int clamp_loops(int loops) {
320 if (loops < 1) {
mtklein527930f2014-11-06 08:04:34 -0800321 SkDebugf("ERROR: clamping loops from %d to 1. "
322 "There's probably something wrong with the bench.\n", loops);
mtklein55b0ffc2014-07-17 08:38:23 -0700323 return 1;
324 }
325 if (loops > FLAGS_maxLoops) {
326 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
327 return FLAGS_maxLoops;
328 }
329 return loops;
330}
331
tomhudsond968a6f2015-03-26 11:28:06 -0700332static bool write_canvas_png(Target* target, const SkString& filename) {
333
bsalomon6eb03cc2014-08-07 14:28:50 -0700334 if (filename.isEmpty()) {
335 return false;
336 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700337 if (target->getCanvas() &&
338 kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700339 return false;
340 }
tomhudsond968a6f2015-03-26 11:28:06 -0700341
bsalomon6eb03cc2014-08-07 14:28:50 -0700342 SkBitmap bmp;
tomhudsond968a6f2015-03-26 11:28:06 -0700343
344 if (!target->capturePixels(&bmp)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700345 return false;
346 }
tomhudsond968a6f2015-03-26 11:28:06 -0700347
bsalomon6eb03cc2014-08-07 14:28:50 -0700348 SkString dir = SkOSPath::Dirname(filename.c_str());
349 if (!sk_mkdir(dir.c_str())) {
350 SkDebugf("Can't make dir %s.\n", dir.c_str());
351 return false;
352 }
353 SkFILEWStream stream(filename.c_str());
354 if (!stream.isValid()) {
355 SkDebugf("Can't write %s.\n", filename.c_str());
356 return false;
357 }
Hal Canarydb683012016-11-23 08:55:18 -0700358 if (!SkEncodeImage(&stream, bmp, SkEncodedImageFormat::kPNG, 100)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700359 SkDebugf("Can't encode a PNG.\n");
360 return false;
361 }
362 return true;
363}
364
365static int kFailedLoops = -2;
cdaltone1b89582015-06-25 19:17:08 -0700366static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) {
mtkleinbb6a0282014-07-01 08:43:42 -0700367 // First figure out approximately how many loops of bench it takes to make overhead negligible.
mtklein2069e222014-08-04 13:57:39 -0700368 double bench_plus_overhead = 0.0;
mtklein55b0ffc2014-07-17 08:38:23 -0700369 int round = 0;
cdaltonb4022962015-06-25 10:51:56 -0700370 int loops = bench->calculateLoops(FLAGS_loops);
371 if (kAutoTuneLoops == loops) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700372 while (bench_plus_overhead < overhead) {
373 if (round++ == FLAGS_maxCalibrationAttempts) {
374 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
mtklein96289052014-09-10 12:05:59 -0700375 bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
bsalomon6eb03cc2014-08-07 14:28:50 -0700376 return kFailedLoops;
377 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700378 bench_plus_overhead = time(1, bench, target);
mtklein55b0ffc2014-07-17 08:38:23 -0700379 }
mtklein2069e222014-08-04 13:57:39 -0700380 }
mtkleinf3723212014-06-25 14:08:00 -0700381
mtkleinbb6a0282014-07-01 08:43:42 -0700382 // Later we'll just start and stop the timer once but loop N times.
mtkleinf3723212014-06-25 14:08:00 -0700383 // We'll pick N to make timer overhead negligible:
384 //
mtkleinbb6a0282014-07-01 08:43:42 -0700385 // overhead
386 // ------------------------- < FLAGS_overheadGoal
387 // overhead + N * Bench Time
mtkleinf3723212014-06-25 14:08:00 -0700388 //
Hal Canary55325b72017-01-03 10:36:17 -0500389 // where bench_plus_overhead ~=~ overhead + Bench Time.
mtkleinf3723212014-06-25 14:08:00 -0700390 //
391 // Doing some math, we get:
392 //
mtkleinbb6a0282014-07-01 08:43:42 -0700393 // (overhead / FLAGS_overheadGoal) - overhead
394 // ------------------------------------------ < N
395 // bench_plus_overhead - overhead)
mtkleinf3723212014-06-25 14:08:00 -0700396 //
397 // Luckily, this also works well in practice. :)
bsalomon6eb03cc2014-08-07 14:28:50 -0700398 if (kAutoTuneLoops == loops) {
399 const double numer = overhead / FLAGS_overheadGoal - overhead;
400 const double denom = bench_plus_overhead - overhead;
401 loops = (int)ceil(numer / denom);
reed53249782014-10-10 09:09:52 -0700402 loops = clamp_loops(loops);
403 } else {
404 loops = detect_forever_loops(loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700405 }
mtkleinbb6a0282014-07-01 08:43:42 -0700406
mtkleinbb6a0282014-07-01 08:43:42 -0700407 return loops;
mtkleinf3723212014-06-25 14:08:00 -0700408}
409
cdaltone1b89582015-06-25 19:17:08 -0700410static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) {
mtkleinbb6a0282014-07-01 08:43:42 -0700411 // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
cdaltonb4022962015-06-25 10:51:56 -0700412 int loops = bench->calculateLoops(FLAGS_loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700413 if (kAutoTuneLoops == loops) {
414 loops = 1;
mtkleina189ccd2014-07-14 12:28:47 -0700415 double elapsed = 0;
416 do {
mtklein527930f2014-11-06 08:04:34 -0800417 if (1<<30 == loops) {
418 // We're about to wrap. Something's wrong with the bench.
419 loops = 0;
420 break;
421 }
mtkleina189ccd2014-07-14 12:28:47 -0700422 loops *= 2;
423 // If the GPU lets frames lag at all, we need to make sure we're timing
cdaltond416a5b2015-06-23 13:23:44 -0700424 // _this_ round, not still timing last round.
425 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700426 elapsed = time(loops, bench, target);
mtkleina189ccd2014-07-14 12:28:47 -0700427 }
428 } while (elapsed < FLAGS_gpuMs);
mtkleinbb6a0282014-07-01 08:43:42 -0700429
mtkleina189ccd2014-07-14 12:28:47 -0700430 // We've overshot at least a little. Scale back linearly.
431 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
reed53249782014-10-10 09:09:52 -0700432 loops = clamp_loops(loops);
mtkleinbb6a0282014-07-01 08:43:42 -0700433
tomhudsond968a6f2015-03-26 11:28:06 -0700434 // Make sure we're not still timing our calibration.
435 target->fence();
reed53249782014-10-10 09:09:52 -0700436 } else {
437 loops = detect_forever_loops(loops);
mtkleina189ccd2014-07-14 12:28:47 -0700438 }
mtkleinbb6a0282014-07-01 08:43:42 -0700439 // Pretty much the same deal as the calibration: do some warmup to make
440 // sure we're timing steady-state pipelined frames.
Brian Osman01776982017-10-10 15:41:03 -0400441 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700442 time(loops, bench, target);
mtkleinf3723212014-06-25 14:08:00 -0700443 }
mtkleinbb6a0282014-07-01 08:43:42 -0700444
mtkleinbb6a0282014-07-01 08:43:42 -0700445 return loops;
446}
mtkleinbb6a0282014-07-01 08:43:42 -0700447
Brian Salomon6405e712017-03-20 08:54:16 -0400448#define kBogusContextType GrContextFactory::kGL_ContextType
csmartdaltone812d492017-02-21 12:36:05 -0700449#define kBogusContextOverrides GrContextFactory::ContextOverrides::kNone
bsalomonc2553372014-07-22 13:09:05 -0700450
svaisanenc47635e2016-01-28 06:05:43 -0800451static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) {
svaisanenc47635e2016-01-28 06:05:43 -0800452 if (const auto* gpuConfig = config->asConfigGpu()) {
Ben Wagner32fa5102017-08-10 21:25:55 -0400453 if (!FLAGS_gpu) {
454 SkDebugf("Skipping config '%s' as requested.\n", config->getTag().c_str());
svaisanenc47635e2016-01-28 06:05:43 -0800455 return;
Ben Wagner32fa5102017-08-10 21:25:55 -0400456 }
svaisanenc47635e2016-01-28 06:05:43 -0800457
svaisanenc47635e2016-01-28 06:05:43 -0800458 const auto ctxType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700459 const auto ctxOverrides = gpuConfig->getContextOverrides();
svaisanenc47635e2016-01-28 06:05:43 -0800460 const auto sampleCount = gpuConfig->getSamples();
Greg Daniel81e7bf82017-07-19 14:47:42 -0400461 const auto colorType = gpuConfig->getColorType();
462 auto colorSpace = gpuConfig->getColorSpace();
Brian Salomonf865b052018-03-09 09:01:53 -0500463 if (gpuConfig->getSurfType() != SkCommandLineConfigGpu::SurfType::kDefault) {
464 SkDebugf("This tool only supports the default surface type.");
465 return;
466 }
svaisanenc47635e2016-01-28 06:05:43 -0800467
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400468 GrContextFactory factory(grContextOpts);
469 if (const GrContext* ctx = factory.get(ctxType, ctxOverrides)) {
Greg Daniel6fa62e22019-08-07 15:52:37 -0400470 GrBackendFormat format = ctx->defaultBackendFormat(colorType, GrRenderable::kYes);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500471 int supportedSampleCount =
Greg Daniel6fa62e22019-08-07 15:52:37 -0400472 ctx->priv().caps()->getRenderTargetSampleCount(sampleCount, format);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400473 if (sampleCount != supportedSampleCount) {
Ben Wagner32fa5102017-08-10 21:25:55 -0400474 SkDebugf("Configuration '%s' sample count %d is not a supported sample count.\n",
475 config->getTag().c_str(), sampleCount);
svaisanenc47635e2016-01-28 06:05:43 -0800476 return;
477 }
478 } else {
Ben Wagner32fa5102017-08-10 21:25:55 -0400479 SkDebugf("No context was available matching config '%s'.\n",
480 config->getTag().c_str());
svaisanenc47635e2016-01-28 06:05:43 -0800481 return;
482 }
483
484 Config target = {
kkinnunend4e1c352016-03-01 23:41:26 -0800485 gpuConfig->getTag(),
svaisanenc47635e2016-01-28 06:05:43 -0800486 Benchmark::kGPU_Backend,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400487 colorType,
svaisanenc47635e2016-01-28 06:05:43 -0800488 kPremul_SkAlphaType,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400489 sk_ref_sp(colorSpace),
svaisanenc47635e2016-01-28 06:05:43 -0800490 sampleCount,
491 ctxType,
csmartdaltone812d492017-02-21 12:36:05 -0700492 ctxOverrides,
kkinnunend4e1c352016-03-01 23:41:26 -0800493 gpuConfig->getUseDIText()
494 };
svaisanenc47635e2016-01-28 06:05:43 -0800495
496 configs->push_back(target);
497 return;
498 }
svaisanenc47635e2016-01-28 06:05:43 -0800499
brianosmanb109b8c2016-06-16 13:03:24 -0700500 #define CPU_CONFIG(name, backend, color, alpha, colorSpace) \
501 if (config->getTag().equals(#name)) { \
Ben Wagner32fa5102017-08-10 21:25:55 -0400502 if (!FLAGS_cpu) { \
503 SkDebugf("Skipping config '%s' as requested.\n", \
504 config->getTag().c_str()); \
505 return; \
506 } \
brianosmanb109b8c2016-06-16 13:03:24 -0700507 Config config = { \
508 SkString(#name), Benchmark::backend, color, alpha, colorSpace, \
csmartdaltone812d492017-02-21 12:36:05 -0700509 0, kBogusContextType, kBogusContextOverrides, false \
brianosmanb109b8c2016-06-16 13:03:24 -0700510 }; \
511 configs->push_back(config); \
512 return; \
mtkleinbb6a0282014-07-01 08:43:42 -0700513 }
mtkleine714e752014-07-31 12:13:48 -0700514
Ben Wagner32fa5102017-08-10 21:25:55 -0400515 CPU_CONFIG(nonrendering, kNonRendering_Backend,
516 kUnknown_SkColorType, kUnpremul_SkAlphaType, nullptr)
mtkleinbb6c41b2016-03-08 11:31:11 -0800517
Mike Klein0e4041f2018-06-19 16:00:40 -0400518 CPU_CONFIG(a8, kRaster_Backend, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr)
519 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType, nullptr)
520 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType, nullptr)
521
522 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
Brian Osman82ebe042019-01-04 17:03:00 -0500523 auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50),
Mike Klein0e4041f2018-06-19 16:00:40 -0400524 srgb = SkColorSpace::MakeSRGB(),
525 srgbLinear = SkColorSpace::MakeSRGBLinear();
526
527 CPU_CONFIG( f16, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgbLinear)
528 CPU_CONFIG( srgb, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, srgb )
529 CPU_CONFIG( esrgb, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgb )
530 CPU_CONFIG( narrow, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, narrow )
531 CPU_CONFIG(enarrow, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, narrow )
mtkleinbb6a0282014-07-01 08:43:42 -0700532
svaisanenc47635e2016-01-28 06:05:43 -0800533 #undef CPU_CONFIG
Ben Wagner32fa5102017-08-10 21:25:55 -0400534
535 SkDebugf("Unknown config '%s'.\n", config->getTag().c_str());
mtkleinf3723212014-06-25 14:08:00 -0700536}
537
svaisanenc47635e2016-01-28 06:05:43 -0800538// Append all configs that are enabled and supported.
539void create_configs(SkTArray<Config>* configs) {
540 SkCommandLineConfigArray array;
541 ParseConfigs(FLAGS_config, &array);
542 for (int i = 0; i < array.count(); ++i) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400543 create_config(array[i].get(), configs);
svaisanenc47635e2016-01-28 06:05:43 -0800544 }
Ben Wagner32fa5102017-08-10 21:25:55 -0400545
546 // If no just default configs were requested, then we're okay.
547 if (array.count() == 0 || FLAGS_config.count() == 0 ||
Ben Wagner32fa5102017-08-10 21:25:55 -0400548 // Otherwise, make sure that all specified configs have been created.
549 array.count() == configs->count()) {
550 return;
551 }
Ben Wagner32fa5102017-08-10 21:25:55 -0400552 exit(1);
svaisanenc47635e2016-01-28 06:05:43 -0800553}
554
brianosman9f1f6e22016-09-15 08:33:02 -0700555// disable warning : switch statement contains default but no 'case' labels
556#if defined _WIN32
557#pragma warning ( push )
558#pragma warning ( disable : 4065 )
559#endif
560
halcanary96fcdcc2015-08-27 07:41:13 -0700561// If bench is enabled for config, returns a Target* for it, otherwise nullptr.
bsalomonc2553372014-07-22 13:09:05 -0700562static Target* is_enabled(Benchmark* bench, const Config& config) {
563 if (!bench->isSuitableFor(config.backend)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700564 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700565 }
566
reede5ea5002014-09-03 11:54:58 -0700567 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
brianosmanb109b8c2016-06-16 13:03:24 -0700568 config.color, config.alpha, config.colorSpace);
bsalomonc2553372014-07-22 13:09:05 -0700569
halcanary96fcdcc2015-08-27 07:41:13 -0700570 Target* target = nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700571
tomhudsond968a6f2015-03-26 11:28:06 -0700572 switch (config.backend) {
tomhudsond968a6f2015-03-26 11:28:06 -0700573 case Benchmark::kGPU_Backend:
574 target = new GPUTarget(config);
575 break;
tomhudsond968a6f2015-03-26 11:28:06 -0700576 default:
577 target = new Target(config);
578 break;
579 }
bsalomonc2553372014-07-22 13:09:05 -0700580
tomhudsond968a6f2015-03-26 11:28:06 -0700581 if (!target->init(info, bench)) {
bsalomonc2553372014-07-22 13:09:05 -0700582 delete target;
halcanary96fcdcc2015-08-27 07:41:13 -0700583 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700584 }
585 return target;
586}
587
brianosman9f1f6e22016-09-15 08:33:02 -0700588#if defined _WIN32
589#pragma warning ( pop )
590#endif
591
Leon Scroggins III87caae62020-05-04 10:02:45 -0400592#ifdef SK_ENABLE_ANDROID_UTILS
reed42943c82016-09-12 12:01:44 -0700593static bool valid_brd_bench(sk_sp<SkData> encoded, SkColorType colorType, uint32_t sampleSize,
msarettd1227a72016-05-18 06:23:57 -0700594 uint32_t minOutputSize, int* width, int* height) {
Leon Scroggins III87caae62020-05-04 10:02:45 -0400595 auto brd = android::skia::BitmapRegionDecoder::Make(encoded);
msarett7f691442015-09-22 11:56:16 -0700596 if (nullptr == brd.get()) {
597 // This is indicates that subset decoding is not supported for a particular image format.
598 return false;
599 }
600
msarett7f691442015-09-22 11:56:16 -0700601 if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize >
602 (uint32_t) brd->height()) {
603 // This indicates that the image is not large enough to decode a
604 // minOutputSize x minOutputSize subset at the given sampleSize.
605 return false;
606 }
607
608 // Set the image width and height. The calling code will use this to choose subsets to decode.
609 *width = brd->width();
610 *height = brd->height();
611 return true;
612}
Leon Scroggins III87caae62020-05-04 10:02:45 -0400613#endif
msarett7f691442015-09-22 11:56:16 -0700614
egdaniel3bf92062015-06-26 08:12:46 -0700615static void cleanup_run(Target* target) {
halcanary385fe4d2015-08-26 13:07:48 -0700616 delete target;
egdaniel3bf92062015-06-26 08:12:46 -0700617}
618
Mike Klein88544fb2019-03-20 10:50:33 -0500619static void collect_files(const CommandLineFlags::StringArray& paths,
620 const char* ext,
621 SkTArray<SkString>* list) {
fmalita6519c212016-09-14 08:05:17 -0700622 for (int i = 0; i < paths.count(); ++i) {
623 if (SkStrEndsWith(paths[i], ext)) {
624 list->push_back(SkString(paths[i]));
625 } else {
626 SkOSFile::Iter it(paths[i], ext);
627 SkString path;
628 while (it.next(&path)) {
629 list->push_back(SkOSPath::Join(paths[i], path.c_str()));
630 }
631 }
632 }
633}
634
mtkleine714e752014-07-31 12:13:48 -0700635class BenchmarkStream {
636public:
mtklein92007582014-08-01 07:46:52 -0700637 BenchmarkStream() : fBenches(BenchRegistry::Head())
Hal Canary2362ae72019-10-24 13:40:40 -0400638 , fGMs(skiagm::GMRegistry::Head()) {
fmalita6519c212016-09-14 08:05:17 -0700639 collect_files(FLAGS_skps, ".skp", &fSKPs);
640 collect_files(FLAGS_svgs, ".svg", &fSVGs);
Hal Canary5dfefa22019-10-24 13:52:17 -0400641 collect_files(FLAGS_texttraces, ".trace", &fTextBlobTraces);
mtkleine714e752014-07-31 12:13:48 -0700642
mtklein92007582014-08-01 07:46:52 -0700643 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
644 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
645 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
646 exit(1);
647 }
648
649 for (int i = 0; i < FLAGS_scales.count(); i++) {
650 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
651 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
652 exit(1);
653 }
654 }
robertphillips5b693772014-11-21 06:19:36 -0800655
cdalton63a82852015-06-29 14:06:10 -0700656 if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) {
657 SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]);
joshualitt261c3ad2015-04-27 09:16:57 -0700658 exit(1);
659 }
660
robertphillips5b693772014-11-21 06:19:36 -0800661 if (FLAGS_mpd) {
662 fUseMPDs.push_back() = true;
663 }
mtkleinc751ecb2015-06-15 08:56:38 -0700664 fUseMPDs.push_back() = false;
mtklein95553d92015-03-12 08:24:21 -0700665
msarett95f192d2015-02-13 09:05:41 -0800666 // Prepare the images for decoding
msarett69deca82016-04-29 09:38:40 -0700667 if (!CollectImages(FLAGS_images, &fImages)) {
scroggo86737142016-02-03 12:19:11 -0800668 exit(1);
msarett95f192d2015-02-13 09:05:41 -0800669 }
mtklein95553d92015-03-12 08:24:21 -0700670
msarett95f192d2015-02-13 09:05:41 -0800671 // Choose the candidate color types for image decoding
msarett67cb6662016-06-21 08:49:26 -0700672 fColorTypes.push_back(kN32_SkColorType);
673 if (!FLAGS_simpleCodec) {
674 fColorTypes.push_back(kRGB_565_SkColorType);
675 fColorTypes.push_back(kAlpha_8_SkColorType);
msarett67cb6662016-06-21 08:49:26 -0700676 fColorTypes.push_back(kGray_8_SkColorType);
677 }
mtklein92007582014-08-01 07:46:52 -0700678 }
679
reedca2622b2016-03-18 07:25:55 -0700680 static sk_sp<SkPicture> ReadPicture(const char* path) {
mtkleinfd731ce2014-09-10 12:19:30 -0700681 // Not strictly necessary, as it will be checked again later,
682 // but helps to avoid a lot of pointless work if we're going to skip it.
Mike Klein88544fb2019-03-20 10:50:33 -0500683 if (CommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) {
reedca2622b2016-03-18 07:25:55 -0700684 return nullptr;
mtkleinfd731ce2014-09-10 12:19:30 -0700685 }
686
bungemanf93d7112016-09-16 06:24:20 -0700687 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
688 if (!stream) {
mtkleinfd731ce2014-09-10 12:19:30 -0700689 SkDebugf("Could not read %s.\n", path);
reedca2622b2016-03-18 07:25:55 -0700690 return nullptr;
mtkleinfd731ce2014-09-10 12:19:30 -0700691 }
692
reedca2622b2016-03-18 07:25:55 -0700693 return SkPicture::MakeFromStream(stream.get());
mtkleinfd731ce2014-09-10 12:19:30 -0700694 }
695
fmalita6519c212016-09-14 08:05:17 -0700696 static sk_sp<SkPicture> ReadSVGPicture(const char* path) {
Brian Osman133823d2018-09-19 14:14:15 -0400697 sk_sp<SkData> data(SkData::MakeFromFileName(path));
698 if (!data) {
fmalita6519c212016-09-14 08:05:17 -0700699 SkDebugf("Could not read %s.\n", path);
700 return nullptr;
701 }
702
Hal Canary0f666812018-03-22 15:21:12 -0400703#ifdef SK_XML
Brian Osman133823d2018-09-19 14:14:15 -0400704 SkMemoryStream stream(std::move(data));
fmalitae1baa7c2016-09-14 12:04:30 -0700705 sk_sp<SkSVGDOM> svgDom = SkSVGDOM::MakeFromStream(stream);
fmalita6519c212016-09-14 08:05:17 -0700706 if (!svgDom) {
707 SkDebugf("Could not parse %s.\n", path);
708 return nullptr;
709 }
710
fmalitae1baa7c2016-09-14 12:04:30 -0700711 // Use the intrinsic SVG size if available, otherwise fall back to a default value.
712 static const SkSize kDefaultContainerSize = SkSize::Make(128, 128);
713 if (svgDom->containerSize().isEmpty()) {
714 svgDom->setContainerSize(kDefaultContainerSize);
715 }
716
fmalita6519c212016-09-14 08:05:17 -0700717 SkPictureRecorder recorder;
fmalitae1baa7c2016-09-14 12:04:30 -0700718 svgDom->render(recorder.beginRecording(svgDom->containerSize().width(),
719 svgDom->containerSize().height()));
fmalita6519c212016-09-14 08:05:17 -0700720 return recorder.finishRecordingAsPicture();
Hal Canary0f666812018-03-22 15:21:12 -0400721#else
722 return nullptr;
723#endif // SK_XML
fmalita6519c212016-09-14 08:05:17 -0700724 }
725
mtklein92007582014-08-01 07:46:52 -0700726 Benchmark* next() {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400727 std::unique_ptr<Benchmark> bench;
mtklein65dfd2f2016-02-03 10:40:54 -0800728 do {
729 bench.reset(this->rawNext());
730 if (!bench) {
731 return nullptr;
732 }
Mike Klein88544fb2019-03-20 10:50:33 -0500733 } while (CommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) ||
734 CommandLineFlags::ShouldSkip(FLAGS_benchType, fBenchType));
mtklein18300a32016-03-16 13:53:35 -0700735 return bench.release();
mtklein65dfd2f2016-02-03 10:40:54 -0800736 }
737
738 Benchmark* rawNext() {
mtkleine714e752014-07-31 12:13:48 -0700739 if (fBenches) {
Hal Canary972eba32018-07-30 17:07:07 -0400740 Benchmark* bench = fBenches->get()(nullptr);
mtkleine714e752014-07-31 12:13:48 -0700741 fBenches = fBenches->next();
mtklein92007582014-08-01 07:46:52 -0700742 fSourceType = "bench";
mtkleinfd731ce2014-09-10 12:19:30 -0700743 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700744 return bench;
745 }
mtklein92007582014-08-01 07:46:52 -0700746
mtkleine714e752014-07-31 12:13:48 -0700747 while (fGMs) {
Ben Wagner406ff502019-08-12 16:39:24 -0400748 std::unique_ptr<skiagm::GM> gm = fGMs->get()();
mtkleine714e752014-07-31 12:13:48 -0700749 fGMs = fGMs->next();
mtkleincf5d9c92015-01-23 10:31:45 -0800750 if (gm->runAsBench()) {
mtklein92007582014-08-01 07:46:52 -0700751 fSourceType = "gm";
mtkleinfd731ce2014-09-10 12:19:30 -0700752 fBenchType = "micro";
Ben Wagner406ff502019-08-12 16:39:24 -0400753 return new GMBench(std::move(gm));
mtkleine714e752014-07-31 12:13:48 -0700754 }
755 }
mtklein92007582014-08-01 07:46:52 -0700756
Hal Canary5dfefa22019-10-24 13:52:17 -0400757 while (fCurrentTextBlobTrace < fTextBlobTraces.count()) {
758 SkString path = fTextBlobTraces[fCurrentTextBlobTrace++];
759 SkString basename = SkOSPath::Basename(path.c_str());
760 static constexpr char kEnding[] = ".trace";
761 if (basename.endsWith(kEnding)) {
762 basename.remove(basename.size() - strlen(kEnding), strlen(kEnding));
763 }
764 fSourceType = "texttrace";
765 fBenchType = "micro";
766 return CreateDiffCanvasBench(
767 SkStringPrintf("SkDiffBench-%s", basename.c_str()),
768 [path](){ return SkStream::MakeFromFile(path.c_str()); });
769 }
770
mtkleinfd731ce2014-09-10 12:19:30 -0700771 // First add all .skps as RecordingBenches.
772 while (fCurrentRecording < fSKPs.count()) {
773 const SkString& path = fSKPs[fCurrentRecording++];
reedca2622b2016-03-18 07:25:55 -0700774 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
775 if (!pic) {
mtkleinfd731ce2014-09-10 12:19:30 -0700776 continue;
777 }
778 SkString name = SkOSPath::Basename(path.c_str());
779 fSourceType = "skp";
780 fBenchType = "recording";
Mike Klein88d90712018-01-27 17:30:04 +0000781 fSKPBytes = static_cast<double>(pic->approximateBytesUsed());
782 fSKPOps = pic->approximateOpCount();
Mike Kleina705cb92019-05-14 12:33:40 -0500783 return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh);
mtkleinfd731ce2014-09-10 12:19:30 -0700784 }
785
Mike Reede45ff462017-12-06 10:47:03 -0500786 // Add all .skps as DeserializePictureBenchs.
787 while (fCurrentDeserialPicture < fSKPs.count()) {
788 const SkString& path = fSKPs[fCurrentDeserialPicture++];
789 sk_sp<SkData> data = SkData::MakeFromFileName(path.c_str());
790 if (!data) {
791 continue;
792 }
793 SkString name = SkOSPath::Basename(path.c_str());
794 fSourceType = "skp";
795 fBenchType = "deserial";
Mike Reed7557bbb2017-12-24 19:50:57 -0500796 fSKPBytes = static_cast<double>(data->size());
Mike Klein88d90712018-01-27 17:30:04 +0000797 fSKPOps = 0;
Mike Reede45ff462017-12-06 10:47:03 -0500798 return new DeserializePictureBench(name.c_str(), std::move(data));
799 }
800
mtkleinfd731ce2014-09-10 12:19:30 -0700801 // Then once each for each scale as SKPBenches (playback).
mtklein92007582014-08-01 07:46:52 -0700802 while (fCurrentScale < fScales.count()) {
803 while (fCurrentSKP < fSKPs.count()) {
robertphillips5b693772014-11-21 06:19:36 -0800804 const SkString& path = fSKPs[fCurrentSKP];
reedca2622b2016-03-18 07:25:55 -0700805 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
806 if (!pic) {
robertphillips5b693772014-11-21 06:19:36 -0800807 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700808 continue;
809 }
robertphillips5b693772014-11-21 06:19:36 -0800810
811 while (fCurrentUseMPD < fUseMPDs.count()) {
812 if (FLAGS_bbh) {
813 // The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
814 SkRTreeFactory factory;
815 SkPictureRecorder recorder;
robertphillips5b693772014-11-21 06:19:36 -0800816 pic->playback(recorder.beginRecording(pic->cullRect().width(),
817 pic->cullRect().height(),
mtklein748ca3b2015-01-15 10:56:12 -0800818 &factory,
robertphillipsdda54452016-07-13 13:27:16 -0700819 0));
reedca2622b2016-03-18 07:25:55 -0700820 pic = recorder.finishRecordingAsPicture();
robertphillips5b693772014-11-21 06:19:36 -0800821 }
822 SkString name = SkOSPath::Basename(path.c_str());
823 fSourceType = "skp";
824 fBenchType = "playback";
halcanary385fe4d2015-08-26 13:07:48 -0700825 return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale],
826 fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP);
mtklein20840502014-08-21 15:51:22 -0700827 }
robertphillips5b693772014-11-21 06:19:36 -0800828 fCurrentUseMPD = 0;
829 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700830 }
fmalita6519c212016-09-14 08:05:17 -0700831
832 while (fCurrentSVG++ < fSVGs.count()) {
833 const char* path = fSVGs[fCurrentSVG - 1].c_str();
834 if (sk_sp<SkPicture> pic = ReadSVGPicture(path)) {
835 fSourceType = "svg";
836 fBenchType = "playback";
837 return new SKPBench(SkOSPath::Basename(path).c_str(), pic.get(), fClip,
838 fScales[fCurrentScale], false, FLAGS_loopSKP);
839 }
840 }
841
mtklein92007582014-08-01 07:46:52 -0700842 fCurrentSKP = 0;
fmalita6519c212016-09-14 08:05:17 -0700843 fCurrentSVG = 0;
mtklein92007582014-08-01 07:46:52 -0700844 fCurrentScale++;
845 }
846
joshualitt261c3ad2015-04-27 09:16:57 -0700847 // Now loop over each skp again if we have an animation
cdalton63a82852015-06-29 14:06:10 -0700848 if (fZoomMax != 1.0f && fZoomPeriodMs > 0) {
joshualitt261c3ad2015-04-27 09:16:57 -0700849 while (fCurrentAnimSKP < fSKPs.count()) {
850 const SkString& path = fSKPs[fCurrentAnimSKP];
reedca2622b2016-03-18 07:25:55 -0700851 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
852 if (!pic) {
joshualitt261c3ad2015-04-27 09:16:57 -0700853 fCurrentAnimSKP++;
854 continue;
855 }
856
857 fCurrentAnimSKP++;
858 SkString name = SkOSPath::Basename(path.c_str());
Ben Wagneracf98df2019-07-12 12:51:44 -0400859 sk_sp<SKPAnimationBench::Animation> animation =
860 SKPAnimationBench::MakeZoomAnimation(fZoomMax, fZoomPeriodMs);
861 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, std::move(animation),
halcanary385fe4d2015-08-26 13:07:48 -0700862 FLAGS_loopSKP);
joshualitt261c3ad2015-04-27 09:16:57 -0700863 }
864 }
865
scroggo60869a42015-04-01 12:09:17 -0700866 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) {
scroggo303fa352015-10-05 11:03:34 -0700867 fSourceType = "image";
868 fBenchType = "skcodec";
scroggo60869a42015-04-01 12:09:17 -0700869 const SkString& path = fImages[fCurrentCodec];
Mike Klein88544fb2019-03-20 10:50:33 -0500870 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
mtklein6f0ff912016-01-11 09:04:21 -0800871 continue;
872 }
bungeman38d909e2016-08-02 14:40:46 -0700873 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400874 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
scroggo60869a42015-04-01 12:09:17 -0700875 if (!codec) {
876 // Nothing to time.
msarett9d9725c2015-04-24 11:41:55 -0700877 SkDebugf("Cannot find codec for %s\n", path.c_str());
scroggo60869a42015-04-01 12:09:17 -0700878 continue;
879 }
scroggo21027992015-04-02 13:22:38 -0700880
scroggo60869a42015-04-01 12:09:17 -0700881 while (fCurrentColorType < fColorTypes.count()) {
scroggo21027992015-04-02 13:22:38 -0700882 const SkColorType colorType = fColorTypes[fCurrentColorType];
scroggo21027992015-04-02 13:22:38 -0700883
msarettc7796b92016-01-07 14:20:20 -0800884 SkAlphaType alphaType = codec->getInfo().alphaType();
msarett67cb6662016-06-21 08:49:26 -0700885 if (FLAGS_simpleCodec) {
886 if (kUnpremul_SkAlphaType == alphaType) {
887 alphaType = kPremul_SkAlphaType;
888 }
889
890 fCurrentColorType++;
891 } else {
892 switch (alphaType) {
893 case kOpaque_SkAlphaType:
894 // We only need to test one alpha type (opaque).
msarettc7796b92016-01-07 14:20:20 -0800895 fCurrentColorType++;
msarett67cb6662016-06-21 08:49:26 -0700896 break;
897 case kUnpremul_SkAlphaType:
898 case kPremul_SkAlphaType:
899 if (0 == fCurrentAlphaType) {
900 // Test unpremul first.
901 alphaType = kUnpremul_SkAlphaType;
902 fCurrentAlphaType++;
903 } else {
904 // Test premul.
905 alphaType = kPremul_SkAlphaType;
906 fCurrentAlphaType = 0;
907 fCurrentColorType++;
908 }
909 break;
910 default:
911 SkASSERT(false);
912 fCurrentColorType++;
913 break;
914 }
scroggo21027992015-04-02 13:22:38 -0700915 }
916
msarettc7796b92016-01-07 14:20:20 -0800917 // Make sure we can decode to this color type and alpha type.
918 SkImageInfo info =
919 codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType);
scroggo21027992015-04-02 13:22:38 -0700920 const size_t rowBytes = info.minRowBytes();
Mike Reedf0ffb892017-10-03 14:47:21 -0400921 SkAutoMalloc storage(info.computeByteSize(rowBytes));
scroggo21027992015-04-02 13:22:38 -0700922
scroggoeb602a52015-07-09 08:16:03 -0700923 const SkCodec::Result result = codec->getPixels(
Leon Scroggins571b30f2017-07-11 17:35:31 +0000924 info, storage.get(), rowBytes);
scroggo60869a42015-04-01 12:09:17 -0700925 switch (result) {
scroggoeb602a52015-07-09 08:16:03 -0700926 case SkCodec::kSuccess:
927 case SkCodec::kIncompleteInput:
scroggo60869a42015-04-01 12:09:17 -0700928 return new CodecBench(SkOSPath::Basename(path.c_str()),
bungeman38d909e2016-08-02 14:40:46 -0700929 encoded.get(), colorType, alphaType);
scroggoeb602a52015-07-09 08:16:03 -0700930 case SkCodec::kInvalidConversion:
scroggo60869a42015-04-01 12:09:17 -0700931 // This is okay. Not all conversions are valid.
932 break;
scroggo60869a42015-04-01 12:09:17 -0700933 default:
934 // This represents some sort of failure.
935 SkASSERT(false);
936 break;
937 }
938 }
939 fCurrentColorType = 0;
940 }
941
msarett84451022016-02-11 06:45:51 -0800942 // Run AndroidCodecBenches
943 const int sampleSizes[] = { 2, 4, 8 };
944 for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) {
945 fSourceType = "image";
946 fBenchType = "skandroidcodec";
947
948 const SkString& path = fImages[fCurrentAndroidCodec];
Mike Klein88544fb2019-03-20 10:50:33 -0500949 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
msarett84451022016-02-11 06:45:51 -0800950 continue;
951 }
bungeman38d909e2016-08-02 14:40:46 -0700952 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400953 std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
msarett84451022016-02-11 06:45:51 -0800954 if (!codec) {
955 // Nothing to time.
956 SkDebugf("Cannot find codec for %s\n", path.c_str());
957 continue;
958 }
959
960 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) {
961 int sampleSize = sampleSizes[fCurrentSampleSize];
962 fCurrentSampleSize++;
Brian Osman788b9162020-02-07 10:36:46 -0500963 if (10 * sampleSize > std::min(codec->getInfo().width(), codec->getInfo().height())) {
msarett84451022016-02-11 06:45:51 -0800964 // Avoid benchmarking scaled decodes of already small images.
965 break;
966 }
967
bungeman38d909e2016-08-02 14:40:46 -0700968 return new AndroidCodecBench(SkOSPath::Basename(path.c_str()),
969 encoded.get(), sampleSize);
msarett84451022016-02-11 06:45:51 -0800970 }
971 fCurrentSampleSize = 0;
972 }
973
Leon Scroggins III87caae62020-05-04 10:02:45 -0400974#ifdef SK_ENABLE_ANDROID_UTILS
msarett7f691442015-09-22 11:56:16 -0700975 // Run the BRDBenches
msarett7f691442015-09-22 11:56:16 -0700976 // We intend to create benchmarks that model the use cases in
977 // android/libraries/social/tiledimage. In this library, an image is decoded in 512x512
978 // tiles. The image can be translated freely, so the location of a tile may be anywhere in
979 // the image. For that reason, we will benchmark decodes in five representative locations
980 // in the image. Additionally, this use case utilizes power of two scaling, so we will
981 // test on power of two sample sizes. The output tile is always 512x512, so, when a
982 // sampleSize is used, the size of the subset that is decoded is always
983 // (sampleSize*512)x(sampleSize*512).
984 // There are a few good reasons to only test on power of two sample sizes at this time:
msarett7f691442015-09-22 11:56:16 -0700985 // All use cases we are aware of only scale by powers of two.
986 // PNG decodes use the indicated sampling strategy regardless of the sample size, so
987 // these tests are sufficient to provide good coverage of our scaling options.
msarett84451022016-02-11 06:45:51 -0800988 const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 };
msarett7f691442015-09-22 11:56:16 -0700989 const uint32_t minOutputSize = 512;
mtklein6f0ff912016-01-11 09:04:21 -0800990 for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) {
msarettd1227a72016-05-18 06:23:57 -0700991 fSourceType = "image";
992 fBenchType = "BRD";
993
mtklein6f0ff912016-01-11 09:04:21 -0800994 const SkString& path = fImages[fCurrentBRDImage];
Mike Klein88544fb2019-03-20 10:50:33 -0500995 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
mtklein6f0ff912016-01-11 09:04:21 -0800996 continue;
997 }
scroggo860e8a62015-10-15 07:51:28 -0700998
msarettd1227a72016-05-18 06:23:57 -0700999 while (fCurrentColorType < fColorTypes.count()) {
1000 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) {
1001 while (fCurrentSubsetType <= kLastSingle_SubsetType) {
scroggo860e8a62015-10-15 07:51:28 -07001002
bungeman38d909e2016-08-02 14:40:46 -07001003 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarettd1227a72016-05-18 06:23:57 -07001004 const SkColorType colorType = fColorTypes[fCurrentColorType];
1005 uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize];
1006 int currentSubsetType = fCurrentSubsetType++;
scroggo860e8a62015-10-15 07:51:28 -07001007
msarettd1227a72016-05-18 06:23:57 -07001008 int width = 0;
1009 int height = 0;
reed42943c82016-09-12 12:01:44 -07001010 if (!valid_brd_bench(encoded, colorType, sampleSize, minOutputSize,
msarettd1227a72016-05-18 06:23:57 -07001011 &width, &height)) {
1012 break;
msarett7f691442015-09-22 11:56:16 -07001013 }
msarettd1227a72016-05-18 06:23:57 -07001014
1015 SkString basename = SkOSPath::Basename(path.c_str());
1016 SkIRect subset;
1017 const uint32_t subsetSize = sampleSize * minOutputSize;
1018 switch (currentSubsetType) {
1019 case kTopLeft_SubsetType:
1020 basename.append("_TopLeft");
1021 subset = SkIRect::MakeXYWH(0, 0, subsetSize, subsetSize);
1022 break;
1023 case kTopRight_SubsetType:
1024 basename.append("_TopRight");
1025 subset = SkIRect::MakeXYWH(width - subsetSize, 0, subsetSize,
1026 subsetSize);
1027 break;
1028 case kMiddle_SubsetType:
1029 basename.append("_Middle");
1030 subset = SkIRect::MakeXYWH((width - subsetSize) / 2,
1031 (height - subsetSize) / 2, subsetSize, subsetSize);
1032 break;
1033 case kBottomLeft_SubsetType:
1034 basename.append("_BottomLeft");
1035 subset = SkIRect::MakeXYWH(0, height - subsetSize, subsetSize,
1036 subsetSize);
1037 break;
1038 case kBottomRight_SubsetType:
1039 basename.append("_BottomRight");
1040 subset = SkIRect::MakeXYWH(width - subsetSize,
1041 height - subsetSize, subsetSize, subsetSize);
1042 break;
1043 default:
1044 SkASSERT(false);
1045 }
1046
1047 return new BitmapRegionDecoderBench(basename.c_str(), encoded.get(),
1048 colorType, sampleSize, subset);
msarett7f691442015-09-22 11:56:16 -07001049 }
msarettd1227a72016-05-18 06:23:57 -07001050 fCurrentSubsetType = 0;
1051 fCurrentSampleSize++;
msarett7f691442015-09-22 11:56:16 -07001052 }
msarettd1227a72016-05-18 06:23:57 -07001053 fCurrentSampleSize = 0;
1054 fCurrentColorType++;
msarett7f691442015-09-22 11:56:16 -07001055 }
msarettd1227a72016-05-18 06:23:57 -07001056 fCurrentColorType = 0;
msarett7f691442015-09-22 11:56:16 -07001057 }
Leon Scroggins III87caae62020-05-04 10:02:45 -04001058#endif // SK_ENABLE_ANDROID_UTILS
msarett7f691442015-09-22 11:56:16 -07001059
halcanary96fcdcc2015-08-27 07:41:13 -07001060 return nullptr;
mtkleine714e752014-07-31 12:13:48 -07001061 }
mtklein92007582014-08-01 07:46:52 -07001062
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001063 void fillCurrentOptions(NanoJSONResultsWriter& log) const {
1064 log.appendString("source_type", fSourceType);
1065 log.appendString("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -07001066 if (0 == strcmp(fSourceType, "skp")) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001067 log.appendString("clip",
mtklein92007582014-08-01 07:46:52 -07001068 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
1069 fClip.fRight, fClip.fBottom).c_str());
djsollenf2b340f2016-01-29 08:51:04 -08001070 SkASSERT_RELEASE(fCurrentScale < fScales.count()); // debugging paranoia
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001071 log.appendString("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
robertphillips5b693772014-11-21 06:19:36 -08001072 if (fCurrentUseMPD > 0) {
1073 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001074 log.appendString("multi_picture_draw",
1075 fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
robertphillips5b693772014-11-21 06:19:36 -08001076 }
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;
robertphillips5b693772014-11-21 06:19:36 -08001109 SkTArray<bool> fUseMPDs;
msarett95f192d2015-02-13 09:05:41 -08001110 SkTArray<SkString> fImages;
msarett74deb982015-10-20 16:45:56 -07001111 SkTArray<SkColorType, true> fColorTypes;
cdalton63a82852015-06-29 14:06:10 -07001112 SkScalar fZoomMax;
1113 double fZoomPeriodMs;
mtklein92007582014-08-01 07:46:52 -07001114
Mike Klein88d90712018-01-27 17:30:04 +00001115 double fSKPBytes, fSKPOps;
mtklein051e56d2014-12-04 08:46:51 -08001116
mtkleinfd731ce2014-09-10 12:19:30 -07001117 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
1118 const char* fBenchType; // How we bench it: micro, recording, playback, ...
Hal Canary2362ae72019-10-24 13:40:40 -04001119 int fCurrentRecording = 0;
1120 int fCurrentDeserialPicture = 0;
1121 int fCurrentScale = 0;
1122 int fCurrentSKP = 0;
1123 int fCurrentSVG = 0;
Hal Canary5dfefa22019-10-24 13:52:17 -04001124 int fCurrentTextBlobTrace = 0;
Hal Canary2362ae72019-10-24 13:40:40 -04001125 int fCurrentUseMPD = 0;
1126 int fCurrentCodec = 0;
1127 int fCurrentAndroidCodec = 0;
Leon Scroggins III87caae62020-05-04 10:02:45 -04001128#ifdef SK_ENABLE_ANDROID_UTILS
Hal Canary2362ae72019-10-24 13:40:40 -04001129 int fCurrentBRDImage = 0;
Leon Scroggins III87caae62020-05-04 10:02:45 -04001130 int fCurrentSubsetType = 0;
1131#endif
Hal Canary2362ae72019-10-24 13:40:40 -04001132 int fCurrentColorType = 0;
1133 int fCurrentAlphaType = 0;
Hal Canary2362ae72019-10-24 13:40:40 -04001134 int fCurrentSampleSize = 0;
1135 int fCurrentAnimSKP = 0;
mtkleine714e752014-07-31 12:13:48 -07001136};
1137
msarettc149f0e2016-01-04 11:35:43 -08001138// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1139// This prints something every once in a while so that it knows we're still working.
1140static void start_keepalive() {
Mike Klein03141d22017-10-30 11:57:15 -04001141 static std::thread* intentionallyLeaked = new std::thread([]{
1142 for (;;) {
1143 static const int kSec = 1200;
1144 #if defined(SK_BUILD_FOR_WIN)
1145 Sleep(kSec * 1000);
1146 #else
1147 sleep(kSec);
1148 #endif
1149 SkDebugf("\nBenchmarks still running...\n");
msarettc149f0e2016-01-04 11:35:43 -08001150 }
Mike Klein03141d22017-10-30 11:57:15 -04001151 });
1152 (void)intentionallyLeaked;
msarettc149f0e2016-01-04 11:35:43 -08001153}
1154
Mike Kleinbe28ee22017-02-06 12:46:20 -05001155int main(int argc, char** argv) {
Mike Klein88544fb2019-03-20 10:50:33 -05001156 CommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001157
Brian Osmanbc8150f2017-07-24 11:38:01 -04001158 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001159
Mike Kleinadacaef2017-02-06 09:26:14 -05001160#if defined(SK_BUILD_FOR_IOS)
1161 cd_Documents();
1162#endif
jcgregorio3b27ade2014-11-13 08:06:40 -08001163 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -07001164 SkAutoGraphics ag;
mtkleincc29d262015-07-09 10:04:56 -07001165 SkTaskGroup::Enabler enabled(FLAGS_threads);
mtkleinf3723212014-06-25 14:08:00 -07001166
Chris Dalton040238b2017-12-18 14:22:34 -07001167 SetCtxOptionsFromCommonFlags(&grContextOpts);
krajcevski69a55602014-08-13 10:46:31 -07001168
bsalomon6eb03cc2014-08-07 14:28:50 -07001169 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -07001170 FLAGS_samples = 1;
1171 FLAGS_gpuFrameLag = 0;
1172 }
1173
bsalomon6eb03cc2014-08-07 14:28:50 -07001174 if (!FLAGS_writePath.isEmpty()) {
1175 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
1176 if (!sk_mkdir(FLAGS_writePath[0])) {
1177 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
halcanary96fcdcc2015-08-27 07:41:13 -07001178 FLAGS_writePath.set(0, nullptr);
bsalomon6eb03cc2014-08-07 14:28:50 -07001179 }
1180 }
1181
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001182 std::unique_ptr<SkWStream> logStream(new SkNullWStream);
mtklein60317d0f2014-07-14 11:30:37 -07001183 if (!FLAGS_outResultsFile.isEmpty()) {
mtklein53520152016-01-20 09:53:59 -08001184#if defined(SK_RELEASE)
Chris Dalton2e1381e2019-10-23 14:35:19 -06001185 // SkJSONWriter uses a 32k in-memory cache, so it only flushes occasionally and is well
1186 // equipped for a stream that re-opens, appends, and closes the file on every write.
1187 logStream.reset(new NanoFILEAppendAndCloseStream(FLAGS_outResultsFile[0]));
mtklein53520152016-01-20 09:53:59 -08001188#else
1189 SkDebugf("I'm ignoring --outResultsFile because this is a Debug build.");
1190 return 1;
1191#endif
mtklein60317d0f2014-07-14 11:30:37 -07001192 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001193 NanoJSONResultsWriter log(logStream.get(), SkJSONWriter::Mode::kPretty);
1194 log.beginObject(); // root
mtklein1915b622014-08-20 11:45:00 -07001195
1196 if (1 == FLAGS_properties.count() % 2) {
1197 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
1198 return 1;
1199 }
1200 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001201 log.appendString(FLAGS_properties[i-1], FLAGS_properties[i]);
mtklein1915b622014-08-20 11:45:00 -07001202 }
jcgregoriobf5e5232014-07-17 13:14:16 -07001203
1204 if (1 == FLAGS_key.count() % 2) {
1205 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
1206 return 1;
1207 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001208 if (FLAGS_key.count()) {
1209 log.beginObject("key");
1210 for (int i = 1; i < FLAGS_key.count(); i += 2) {
1211 log.appendString(FLAGS_key[i - 1], FLAGS_key[i]);
1212 }
1213 log.endObject(); // key
mtklein94e51562014-08-19 12:41:53 -07001214 }
mtklein60317d0f2014-07-14 11:30:37 -07001215
mtkleinf3723212014-06-25 14:08:00 -07001216 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -07001217 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -04001218
cdaltone1b89582015-06-25 19:17:08 -07001219 SkTArray<double> samples;
mtkleinbb6a0282014-07-01 08:43:42 -07001220
bsalomon6eb03cc2014-08-07 14:28:50 -07001221 if (kAutoTuneLoops != FLAGS_loops) {
1222 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleinf3723212014-06-25 14:08:00 -07001223 } else if (FLAGS_quiet) {
mtklein66cfcff2015-12-04 06:35:30 -08001224 SkDebugf("! -> high variance, ? -> moderate variance\n");
1225 SkDebugf(" micros \tbench\n");
mtkleinbbba1682015-10-28 11:36:30 -07001226 } else if (FLAGS_ms) {
cdaltone1b89582015-06-25 19:17:08 -07001227 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n");
mtkleinf3723212014-06-25 14:08:00 -07001228 } else {
mtkleind75c4662015-04-30 07:11:22 -07001229 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
qiankun.miao8247ec32014-09-09 19:24:36 -07001230 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -07001231 }
1232
svaisanenc47635e2016-01-28 06:05:43 -08001233 SkTArray<Config> configs;
bsalomonc2553372014-07-22 13:09:05 -07001234 create_configs(&configs);
1235
msarettc149f0e2016-01-04 11:35:43 -08001236 if (FLAGS_keepAlive) {
1237 start_keepalive();
1238 }
1239
Mike Klein03fa5d42019-03-22 11:39:09 -05001240 SetAnalyticAAFromCommonFlags();
liyuqian38911a72016-10-04 11:23:22 -07001241
Mike Klein2a57e792020-01-14 12:47:52 -06001242 if (FLAGS_forceRasterPipeline) { gSkForceRasterPipelineBlitter = true; }
Mike Kleinea4459d2020-01-16 13:05:04 -06001243 if (FLAGS_skvm) { gUseSkVMBlitter = gSkVMJITViaDylib = true; }
Yuqian Li550148b2017-01-13 10:13:13 -05001244
mtkleine070c2b2014-10-14 08:40:43 -07001245 int runs = 0;
mtklein92007582014-08-01 07:46:52 -07001246 BenchmarkStream benchStream;
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001247 log.beginObject("results");
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001248 AutoreleasePool pool;
mtklein92007582014-08-01 07:46:52 -07001249 while (Benchmark* b = benchStream.next()) {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001250 std::unique_ptr<Benchmark> bench(b);
Mike Klein88544fb2019-03-20 10:50:33 -05001251 if (CommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -07001252 continue;
1253 }
1254
svaisanenc47635e2016-01-28 06:05:43 -08001255 if (!configs.empty()) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001256 log.beginBench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
joshualitt8a6697a2015-09-30 12:11:07 -07001257 bench->delayedSetup();
jcgregoriobf5e5232014-07-17 13:14:16 -07001258 }
egdaniel3bf92062015-06-26 08:12:46 -07001259 for (int i = 0; i < configs.count(); ++i) {
1260 Target* target = is_enabled(b, configs[i]);
1261 if (!target) {
1262 continue;
1263 }
mtkleinf3723212014-06-25 14:08:00 -07001264
halcanary96fcdcc2015-08-27 07:41:13 -07001265 // During HWUI output this canvas may be nullptr.
egdaniel3bf92062015-06-26 08:12:46 -07001266 SkCanvas* canvas = target->getCanvas();
svaisanenc47635e2016-01-28 06:05:43 -08001267 const char* config = target->config.name.c_str();
egdaniel3bf92062015-06-26 08:12:46 -07001268
brianosman7a5ada82016-02-08 13:49:12 -08001269 if (FLAGS_pre_log || FLAGS_dryRun) {
benjaminwagner8d61f0d2016-01-25 13:02:40 -08001270 SkDebugf("Running %s\t%s\n"
1271 , bench->getUniqueName()
1272 , config);
brianosman7a5ada82016-02-08 13:49:12 -08001273 if (FLAGS_dryRun) {
1274 continue;
1275 }
benjaminwagner8d61f0d2016-01-25 13:02:40 -08001276 }
1277
Mike Kleinee254232019-03-28 08:32:14 -05001278 if (FLAGS_purgeBetweenBenches) {
1279 SkGraphics::PurgeAllCaches();
1280 }
1281
Brian Osman5ad87aa2017-09-08 16:05:23 -04001282 TRACE_EVENT2("skia", "Benchmark", "name", TRACE_STR_COPY(bench->getUniqueName()),
1283 "config", TRACE_STR_COPY(config));
Brian Osmanc3cdef52017-08-31 14:09:22 -04001284
egdaniel3bf92062015-06-26 08:12:46 -07001285 target->setup();
robertphillips5b693772014-11-21 06:19:36 -08001286 bench->perCanvasPreDraw(canvas);
1287
cdaltone1b89582015-06-25 19:17:08 -07001288 int maxFrameLag;
mtkleina1ebeb22015-10-01 09:43:39 -07001289 int loops = target->needsFrameTiming(&maxFrameLag)
egdaniel3bf92062015-06-26 08:12:46 -07001290 ? setup_gpu_bench(target, bench.get(), maxFrameLag)
1291 : setup_cpu_bench(overhead, target, bench.get());
cdaltone1b89582015-06-25 19:17:08 -07001292
Leon Scroggins IIIb30d1132017-10-02 09:48:15 -04001293 if (kFailedLoops == loops) {
1294 // Can't be timed. A warning note has already been printed.
1295 cleanup_run(target);
1296 continue;
1297 }
1298
Yuqian Li3528eb32017-09-21 13:23:49 -04001299 if (runs == 0 && FLAGS_ms < 1000) {
1300 // Run the first bench for 1000ms to warm up the nanobench if FLAGS_ms < 1000.
1301 // Otherwise, the first few benches' measurements will be inaccurate.
1302 auto stop = now_ms() + 1000;
1303 do {
1304 time(loops, bench.get(), target);
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001305 pool.drain();
Yuqian Li3528eb32017-09-21 13:23:49 -04001306 } while (now_ms() < stop);
1307 }
1308
mtkleinbbba1682015-10-28 11:36:30 -07001309 if (FLAGS_ms) {
1310 samples.reset();
1311 auto stop = now_ms() + FLAGS_ms;
1312 do {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001313 samples.push_back(time(loops, bench.get(), target) / loops);
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001314 pool.drain();
mtkleinbbba1682015-10-28 11:36:30 -07001315 } while (now_ms() < stop);
1316 } else {
cdaltone1b89582015-06-25 19:17:08 -07001317 samples.reset(FLAGS_samples);
1318 for (int s = 0; s < FLAGS_samples; s++) {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001319 samples[s] = time(loops, bench.get(), target) / loops;
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001320 pool.drain();
cdaltone1b89582015-06-25 19:17:08 -07001321 }
cdaltone1b89582015-06-25 19:17:08 -07001322 }
mtkleinf3723212014-06-25 14:08:00 -07001323
Mike Kleinfec9b902019-05-31 10:03:07 -05001324 // Scale each result to the benchmark's own units, time/unit.
1325 for (double& sample : samples) {
1326 sample *= (1.0 / bench->getUnits());
1327 }
1328
joshualitte45c81c2015-12-02 09:05:37 -08001329 SkTArray<SkString> keys;
1330 SkTArray<double> values;
1331 bool gpuStatsDump = FLAGS_gpuStatsDump && Benchmark::kGPU_Backend == configs[i].backend;
1332 if (gpuStatsDump) {
1333 // TODO cache stats
1334 bench->getGpuStats(canvas, &keys, &values);
1335 }
joshualitte45c81c2015-12-02 09:05:37 -08001336
robertphillips5b693772014-11-21 06:19:36 -08001337 bench->perCanvasPostDraw(canvas);
1338
egdaniel3bf92062015-06-26 08:12:46 -07001339 if (Benchmark::kNonRendering_Backend != target->config.backend &&
tomhudsond968a6f2015-03-26 11:28:06 -07001340 !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -07001341 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -07001342 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -07001343 pngFilename.append(".png");
egdaniel3bf92062015-06-26 08:12:46 -07001344 write_canvas_png(target, pngFilename);
bsalomon6eb03cc2014-08-07 14:28:50 -07001345 }
1346
Mike Klein512a2442018-09-27 10:44:56 -04001347 // Building stats.plot often shows up in profiles,
1348 // so skip building it when we're not going to print it anyway.
1349 const bool want_plot = !FLAGS_quiet;
1350
1351 Stats stats(samples, want_plot);
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001352 log.beginObject(config);
1353
1354 log.beginObject("options");
1355 log.appendString("name", bench->getName());
1356 benchStream.fillCurrentOptions(log);
1357 target->fillOptions(log);
1358 log.endObject(); // options
1359
1360 // Metrics
1361 log.appendMetric("min_ms", stats.min);
1362 log.beginArray("samples");
1363 for (double sample : samples) {
1364 log.appendDoubleDigits(sample, 16);
1365 }
1366 log.endArray(); // samples
1367 benchStream.fillCurrentMetrics(log);
joshualitte45c81c2015-12-02 09:05:37 -08001368 if (gpuStatsDump) {
1369 // dump to json, only SKPBench currently returns valid keys / values
1370 SkASSERT(keys.count() == values.count());
1371 for (int i = 0; i < keys.count(); i++) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001372 log.appendMetric(keys[i].c_str(), values[i]);
joshualitte45c81c2015-12-02 09:05:37 -08001373 }
1374 }
joshualitte45c81c2015-12-02 09:05:37 -08001375
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001376 log.endObject(); // config
1377
mtkleine070c2b2014-10-14 08:40:43 -07001378 if (runs++ % FLAGS_flushEvery == 0) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001379 log.flush();
mtkleine070c2b2014-10-14 08:40:43 -07001380 }
mtklein60317d0f2014-07-14 11:30:37 -07001381
bsalomon6eb03cc2014-08-07 14:28:50 -07001382 if (kAutoTuneLoops != FLAGS_loops) {
egdaniel3bf92062015-06-26 08:12:46 -07001383 if (configs.count() == 1) {
mtkleina189ccd2014-07-14 12:28:47 -07001384 config = ""; // Only print the config if we run the same bench on more than one.
1385 }
mtkleind75c4662015-04-30 07:11:22 -07001386 SkDebugf("%4d/%-4dMB\t%s\t%s\n"
1387 , sk_tools::getCurrResidentSetSizeMB()
1388 , sk_tools::getMaxResidentSetSizeMB()
mtklein53d25622014-09-18 07:39:42 -07001389 , bench->getUniqueName()
1390 , config);
mtkleinf3723212014-06-25 14:08:00 -07001391 } else if (FLAGS_quiet) {
mtklein66cfcff2015-12-04 06:35:30 -08001392 const char* mark = " ";
Hal Canarye99e8da2019-01-14 16:34:50 -05001393 const double stddev_percent =
1394 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
mtklein66cfcff2015-12-04 06:35:30 -08001395 if (stddev_percent > 5) mark = "?";
1396 if (stddev_percent > 10) mark = "!";
1397
1398 SkDebugf("%10.2f %s\t%s\t%s\n",
1399 stats.median*1e3, mark, bench->getUniqueName(), config);
Mike Reedc665e5b2017-07-04 22:56:06 -04001400 } else if (FLAGS_csv) {
Hal Canarye99e8da2019-01-14 16:34:50 -05001401 const double stddev_percent =
1402 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
Mike Reedc665e5b2017-07-04 22:56:06 -04001403 SkDebugf("%g,%g,%g,%g,%g,%s,%s\n"
1404 , stats.min
1405 , stats.median
1406 , stats.mean
1407 , stats.max
1408 , stddev_percent
1409 , config
1410 , bench->getUniqueName()
1411 );
1412 } else {
1413 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 -05001414 const double stddev_percent =
1415 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
Mike Reedc665e5b2017-07-04 22:56:06 -04001416 SkDebugf(format
mtkleind75c4662015-04-30 07:11:22 -07001417 , sk_tools::getCurrResidentSetSizeMB()
1418 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -07001419 , loops
mtklein55b0ffc2014-07-17 08:38:23 -07001420 , HUMANIZE(stats.min)
1421 , HUMANIZE(stats.median)
1422 , HUMANIZE(stats.mean)
1423 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -07001424 , stddev_percent
mtkleinbbba1682015-10-28 11:36:30 -07001425 , FLAGS_ms ? to_string(samples.count()).c_str() : stats.plot.c_str()
mtkleinf3723212014-06-25 14:08:00 -07001426 , config
mtklein96289052014-09-10 12:05:59 -07001427 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -07001428 );
1429 }
joshualitte45c81c2015-12-02 09:05:37 -08001430
joshualitte45c81c2015-12-02 09:05:37 -08001431 if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -04001432 target->dumpStats();
bsalomon06cddec2014-10-24 10:40:50 -07001433 }
joshualitte45c81c2015-12-02 09:05:37 -08001434
cdalton2c56ba52015-06-26 13:32:53 -07001435 if (FLAGS_verbose) {
1436 SkDebugf("Samples: ");
1437 for (int i = 0; i < samples.count(); i++) {
1438 SkDebugf("%s ", HUMANIZE(samples[i]));
1439 }
1440 SkDebugf("%s\n", bench->getUniqueName());
1441 }
egdaniel3bf92062015-06-26 08:12:46 -07001442 cleanup_run(target);
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001443 pool.drain();
mtkleinf3723212014-06-25 14:08:00 -07001444 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001445 if (!configs.empty()) {
1446 log.endBench();
1447 }
mtkleinf3723212014-06-25 14:08:00 -07001448 }
1449
Herb Derby5a523fe2017-01-26 16:48:28 -05001450 SkGraphics::PurgeAllCaches();
1451
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001452 log.beginBench("memory_usage", 0, 0);
1453 log.beginObject("meta"); // config
1454 log.appendS32("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
1455 log.endObject(); // config
1456 log.endBench();
1457
1458 log.endObject(); // results
1459 log.endObject(); // root
1460 log.flush();
mtkleine1091452014-12-04 10:47:02 -08001461
mtkleinf3723212014-06-25 14:08:00 -07001462 return 0;
1463}