blob: 1e21065cb5f819818056b4ca6570dfdd2c7f826a [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
Robert Phillips00f78de2020-07-01 16:09:43 -040071#include "include/gpu/GrDirectContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050072#include "src/gpu/GrCaps.h"
73#include "src/gpu/GrContextPriv.h"
74#include "src/gpu/SkGr.h"
75#include "src/gpu/gl/GrGLDefines.h"
76#include "src/gpu/gl/GrGLGpu.h"
77#include "src/gpu/gl/GrGLUtil.h"
78#include "tools/gpu/GrContextFactory.h"
Brian Salomon032aaae2018-03-23 16:10:36 -040079
Brian Osmanc7ad40f2018-05-31 14:27:17 -040080using sk_gpu_test::ContextInfo;
81using sk_gpu_test::GrContextFactory;
82using sk_gpu_test::TestContext;
Brian Salomon032aaae2018-03-23 16:10:36 -040083
Brian Osmanc7ad40f2018-05-31 14:27:17 -040084GrContextOptions grContextOpts;
bsalomon682c2692015-05-22 14:01:46 -070085
reed53249782014-10-10 09:09:52 -070086static const int kAutoTuneLoops = 0;
bsalomon6eb03cc2014-08-07 14:28:50 -070087
bsalomon6eb03cc2014-08-07 14:28:50 -070088static SkString loops_help_txt() {
89 SkString help;
90 help.printf("Number of times to run each bench. Set this to %d to auto-"
91 "tune for each bench. Timings are only reported when auto-tuning.",
92 kAutoTuneLoops);
93 return help;
94}
95
cdaltone1b89582015-06-25 19:17:08 -070096static SkString to_string(int n) {
97 SkString str;
98 str.appendS32(n);
99 return str;
100}
101
Mike Kleinac8f4432019-07-01 10:15:32 -0500102static DEFINE_int(loops, kAutoTuneLoops, loops_help_txt().c_str());
bsalomon6eb03cc2014-08-07 14:28:50 -0700103
Mike Klein5b3f3432019-03-21 11:42:21 -0500104static DEFINE_int(samples, 10, "Number of samples to measure for each bench.");
105static DEFINE_int(ms, 0, "If >0, run each bench for this many ms instead of obeying --samples.");
106static DEFINE_int(overheadLoops, 100000, "Loops to estimate timer overhead.");
Mike Klein84836b72019-03-21 11:31:36 -0500107static DEFINE_double(overheadGoal, 0.0001,
mtkleinf3723212014-06-25 14:08:00 -0700108 "Loop until timer overhead is at most this fraction of our measurments.");
Mike Klein84836b72019-03-21 11:31:36 -0500109static DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500110static DEFINE_int(gpuFrameLag, 5,
Mike Klein84836b72019-03-21 11:31:36 -0500111 "If unknown, estimated maximum number of frames GPU allows to lag.");
mtkleinf3723212014-06-25 14:08:00 -0700112
Mike Klein84836b72019-03-21 11:31:36 -0500113static DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500114static DEFINE_int(maxCalibrationAttempts, 3,
mtklein55b0ffc2014-07-17 08:38:23 -0700115 "Try up to this many times to guess loops for a bench, or skip the bench.");
Mike Klein5b3f3432019-03-21 11:42:21 -0500116static DEFINE_int(maxLoops, 1000000, "Never run a bench more times than this.");
Mike Klein84836b72019-03-21 11:31:36 -0500117static DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
118static DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
119static DEFINE_string(zoom, "1.0,0",
120 "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom "
121 "function that ping-pongs between 1.0 and zoomMax.");
122static DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
Mike Klein84836b72019-03-21 11:31:36 -0500123static DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
124static DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?");
Mike Klein5b3f3432019-03-21 11:42:21 -0500125static DEFINE_int(flushEvery, 10, "Flush --outResultsFile every Nth run.");
Mike Klein84836b72019-03-21 11:31:36 -0500126static DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
127static DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json");
128static DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out");
129static DEFINE_bool(csv, false, "Print status in CSV format");
130static DEFINE_string(sourceType, "",
mtklein65dfd2f2016-02-03 10:40:54 -0800131 "Apply usual --match rules to source type: bench, gm, skp, image, etc.");
Mike Klein84836b72019-03-21 11:31:36 -0500132static DEFINE_string(benchType, "",
133 "Apply usual --match rules to bench type: micro, recording, "
134 "piping, playback, skcodec, etc.");
mtklein65dfd2f2016-02-03 10:40:54 -0800135
Mike Klein84836b72019-03-21 11:31:36 -0500136static DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter");
Mike Kleinea4459d2020-01-16 13:05:04 -0600137static DEFINE_bool(skvm, false, "sets gUseSkVMBlitter and gSkVMJITViaDylib");
Mike Reedc928fe22017-06-05 10:20:31 -0400138
Mike Klein19fb3972019-03-21 13:08:08 -0500139static DEFINE_bool2(pre_log, p, false,
140 "Log before running each test. May be incomprehensible when threading");
141
Mike Klein629f5fc2019-03-22 14:55:19 -0500142static DEFINE_bool(cpu, true, "master switch for running CPU-bound work.");
143static DEFINE_bool(gpu, true, "master switch for running GPU-bound work.");
144static DEFINE_bool(dryRun, false,
145 "just print the tests that would be run, without actually running them.");
146static DEFINE_string(images, "",
147 "List of images and/or directories to decode. A directory with no images"
148 " is treated as a fatal error.");
149static DEFINE_bool(simpleCodec, false,
150 "Runs of a subset of the codec tests, always N32, Premul or Opaque");
151
Mike Kleinc6142d82019-03-25 10:54:59 -0500152static DEFINE_string2(match, m, nullptr,
153 "[~][^]substring[$] [...] of name to run.\n"
154 "Multiple matches may be separated by spaces.\n"
155 "~ causes a matching name to always be skipped\n"
156 "^ requires the start of the name to match\n"
157 "$ requires the end of the name to match\n"
158 "^ and $ requires an exact match\n"
159 "If a name does not match any list entry,\n"
160 "it is skipped unless some list entry starts with ~");
161
162static DEFINE_bool2(quiet, q, false, "if true, don't print status updates.");
163static DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
164
165
166static DEFINE_string(skps, "skps", "Directory to read skps from.");
167static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file.");
Hal Canary5dfefa22019-10-24 13:52:17 -0400168static DEFINE_string(texttraces, "", "Directory to read TextBlobTrace files from.");
Mike Kleinc6142d82019-03-25 10:54:59 -0500169
170static DEFINE_int_2(threads, j, -1,
171 "Run threadsafe tests on a threadpool with this many extra threads, "
172 "defaulting to one extra thread per core.");
173
174static DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs.");
175
176static DEFINE_string(key, "",
177 "Space-separated key/value pairs to add to JSON identifying this builder.");
178static DEFINE_string(properties, "",
179 "Space-separated key/value pairs to add to JSON identifying this run.");
180
Mike Kleinee254232019-03-28 08:32:14 -0500181static DEFINE_bool(purgeBetweenBenches, false,
182 "Call SkGraphics::PurgeAllCaches() between each benchmark?");
183
mtkleinbbba1682015-10-28 11:36:30 -0700184static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
185
mtkleinf3723212014-06-25 14:08:00 -0700186static SkString humanize(double ms) {
Adlai Holler684838f2020-05-12 10:41:04 -0400187 if (FLAGS_verbose) return SkStringPrintf("%" PRIu64, (uint64_t)(ms*1e6));
mtklein748ca3b2015-01-15 10:56:12 -0800188 return HumanizeMs(ms);
mtkleinf3723212014-06-25 14:08:00 -0700189}
mtklein55b0ffc2014-07-17 08:38:23 -0700190#define HUMANIZE(ms) humanize(ms).c_str()
mtkleinf3723212014-06-25 14:08:00 -0700191
tomhudsond968a6f2015-03-26 11:28:06 -0700192bool Target::init(SkImageInfo info, Benchmark* bench) {
193 if (Benchmark::kRaster_Backend == config.backend) {
reede8f30622016-03-23 18:59:25 -0700194 this->surface = SkSurface::MakeRaster(info);
195 if (!this->surface) {
tomhudsond968a6f2015-03-26 11:28:06 -0700196 return false;
197 }
198 }
199 return true;
200}
201bool Target::capturePixels(SkBitmap* bmp) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700202 SkCanvas* canvas = this->getCanvas();
tomhudsond968a6f2015-03-26 11:28:06 -0700203 if (!canvas) {
204 return false;
205 }
Mike Reed12e946b2017-04-17 10:53:29 -0400206 bmp->allocPixels(canvas->imageInfo());
207 if (!canvas->readPixels(*bmp, 0, 0)) {
tomhudsond968a6f2015-03-26 11:28:06 -0700208 SkDebugf("Can't read canvas pixels.\n");
209 return false;
210 }
211 return true;
212}
213
tomhudsond968a6f2015-03-26 11:28:06 -0700214struct GPUTarget : public Target {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400215 explicit GPUTarget(const Config& c) : Target(c) {}
216 ContextInfo contextInfo;
217 std::unique_ptr<GrContextFactory> factory;
tomhudsond968a6f2015-03-26 11:28:06 -0700218
Greg Daniel5ed3c112020-06-18 15:59:17 -0400219 ~GPUTarget() override {
220 // For Vulkan we need to release all our refs to the GrContext before destroy the vulkan
221 // context which happens at the end of this destructor. Thus we need to release the surface
222 // here which holds a ref to the GrContext.
223 surface.reset();
224 }
225
tomhudsond968a6f2015-03-26 11:28:06 -0700226 void setup() override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400227 this->contextInfo.testContext()->makeCurrent();
tomhudsond968a6f2015-03-26 11:28:06 -0700228 // Make sure we're done with whatever came before.
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400229 this->contextInfo.testContext()->finish();
tomhudsond968a6f2015-03-26 11:28:06 -0700230 }
231 void endTiming() override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400232 if (this->contextInfo.testContext()) {
Robert Phillips00f78de2020-07-01 16:09:43 -0400233 this->contextInfo.testContext()->flushAndWaitOnSync(contextInfo.directContext());
tomhudsond968a6f2015-03-26 11:28:06 -0700234 }
235 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400236 void fence() override { this->contextInfo.testContext()->finish(); }
mtkleind75c4662015-04-30 07:11:22 -0700237
cdaltond416a5b2015-06-23 13:23:44 -0700238 bool needsFrameTiming(int* maxFrameLag) const override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400239 if (!this->contextInfo.testContext()->getMaxGpuFrameLag(maxFrameLag)) {
cdaltond416a5b2015-06-23 13:23:44 -0700240 // Frame lag is unknown.
241 *maxFrameLag = FLAGS_gpuFrameLag;
242 }
243 return true;
244 }
tomhudsond968a6f2015-03-26 11:28:06 -0700245 bool init(SkImageInfo info, Benchmark* bench) override {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400246 GrContextOptions options = grContextOpts;
247 bench->modifyGrContextOptions(&options);
248 this->factory.reset(new GrContextFactory(options));
bsalomonafcd7cd2015-08-31 12:39:41 -0700249 uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag :
250 0;
tomhudsond968a6f2015-03-26 11:28:06 -0700251 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400252 this->surface = SkSurface::MakeRenderTarget(
253 this->factory->get(this->config.ctxType, this->config.ctxOverrides),
254 SkBudgeted::kNo, info, this->config.samples, &props);
255 this->contextInfo =
256 this->factory->getContextInfo(this->config.ctxType, this->config.ctxOverrides);
tomhudsond968a6f2015-03-26 11:28:06 -0700257 if (!this->surface.get()) {
258 return false;
259 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400260 if (!this->contextInfo.testContext()->fenceSyncSupport()) {
cdaltond416a5b2015-06-23 13:23:44 -0700261 SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. "
svaisanenc47635e2016-01-28 06:05:43 -0800262 "Timings might not be accurate.\n", this->config.name.c_str());
cdaltond416a5b2015-06-23 13:23:44 -0700263 }
tomhudsond968a6f2015-03-26 11:28:06 -0700264 return true;
265 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500266 void fillOptions(NanoJSONResultsWriter& log) override {
Brian Salomonf4ba4ec2020-03-19 15:54:28 -0400267#ifdef SK_GL
tomhudsond968a6f2015-03-26 11:28:06 -0700268 const GrGLubyte* version;
Greg Danielbdf12ad2018-10-12 09:31:11 -0400269 if (this->contextInfo.backend() == GrBackendApi::kOpenGL) {
Brian Salomon032aaae2018-03-23 16:10:36 -0400270 const GrGLInterface* gl =
Robert Phillips00f78de2020-07-01 16:09:43 -0400271 static_cast<GrGLGpu*>(this->contextInfo.directContext()->priv().getGpu())
Brian Salomon032aaae2018-03-23 16:10:36 -0400272 ->glInterface();
bsalomonc8699322016-05-11 11:55:36 -0700273 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VERSION));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500274 log.appendString("GL_VERSION", (const char*)(version));
tomhudsond968a6f2015-03-26 11:28:06 -0700275
bsalomonc8699322016-05-11 11:55:36 -0700276 GR_GL_CALL_RET(gl, version, GetString(GR_GL_RENDERER));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500277 log.appendString("GL_RENDERER", (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_VENDOR));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500280 log.appendString("GL_VENDOR", (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_SHADING_LANGUAGE_VERSION));
Brian Osman8c0a1ca2019-01-28 14:24:29 -0500283 log.appendString("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
bsalomonc8699322016-05-11 11:55:36 -0700284 }
Brian Salomonf4ba4ec2020-03-19 15:54:28 -0400285#endif
tomhudsond968a6f2015-03-26 11:28:06 -0700286 }
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400287
288 void dumpStats() override {
Robert Phillips00f78de2020-07-01 16:09:43 -0400289 auto context = this->contextInfo.directContext();
290
291 context->priv().printCacheStats();
292 context->priv().printGpuStats();
293 context->priv().printContextStats();
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400294 }
tomhudsond968a6f2015-03-26 11:28:06 -0700295};
mtkleind75c4662015-04-30 07:11:22 -0700296
tomhudson75a0ebb2015-03-27 12:11:44 -0700297static double time(int loops, Benchmark* bench, Target* target) {
298 SkCanvas* canvas = target->getCanvas();
bsalomon6eb03cc2014-08-07 14:28:50 -0700299 if (canvas) {
300 canvas->clear(SK_ColorWHITE);
301 }
joshualitt8a6697a2015-09-30 12:11:07 -0700302 bench->preDraw(canvas);
mtkleinbbba1682015-10-28 11:36:30 -0700303 double start = now_ms();
tomhudson75a0ebb2015-03-27 12:11:44 -0700304 canvas = target->beginTiming(canvas);
305 bench->draw(loops, canvas);
tomhudson75a0ebb2015-03-27 12:11:44 -0700306 target->endTiming();
mtkleinbbba1682015-10-28 11:36:30 -0700307 double elapsed = now_ms() - start;
joshualitt8a6697a2015-09-30 12:11:07 -0700308 bench->postDraw(canvas);
mtkleinbbba1682015-10-28 11:36:30 -0700309 return elapsed;
mtkleinbb6a0282014-07-01 08:43:42 -0700310}
311
mtkleinf3723212014-06-25 14:08:00 -0700312static double estimate_timer_overhead() {
313 double overhead = 0;
mtkleinf3723212014-06-25 14:08:00 -0700314 for (int i = 0; i < FLAGS_overheadLoops; i++) {
mtkleinbbba1682015-10-28 11:36:30 -0700315 double start = now_ms();
316 overhead += now_ms() - start;
mtkleinf3723212014-06-25 14:08:00 -0700317 }
318 return overhead / FLAGS_overheadLoops;
319}
320
reed53249782014-10-10 09:09:52 -0700321static int detect_forever_loops(int loops) {
322 // look for a magic run-forever value
323 if (loops < 0) {
324 loops = SK_MaxS32;
325 }
326 return loops;
327}
328
mtklein55b0ffc2014-07-17 08:38:23 -0700329static int clamp_loops(int loops) {
330 if (loops < 1) {
mtklein527930f2014-11-06 08:04:34 -0800331 SkDebugf("ERROR: clamping loops from %d to 1. "
332 "There's probably something wrong with the bench.\n", loops);
mtklein55b0ffc2014-07-17 08:38:23 -0700333 return 1;
334 }
335 if (loops > FLAGS_maxLoops) {
336 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops);
337 return FLAGS_maxLoops;
338 }
339 return loops;
340}
341
tomhudsond968a6f2015-03-26 11:28:06 -0700342static bool write_canvas_png(Target* target, const SkString& filename) {
343
bsalomon6eb03cc2014-08-07 14:28:50 -0700344 if (filename.isEmpty()) {
345 return false;
346 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700347 if (target->getCanvas() &&
348 kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700349 return false;
350 }
tomhudsond968a6f2015-03-26 11:28:06 -0700351
bsalomon6eb03cc2014-08-07 14:28:50 -0700352 SkBitmap bmp;
tomhudsond968a6f2015-03-26 11:28:06 -0700353
354 if (!target->capturePixels(&bmp)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700355 return false;
356 }
tomhudsond968a6f2015-03-26 11:28:06 -0700357
bsalomon6eb03cc2014-08-07 14:28:50 -0700358 SkString dir = SkOSPath::Dirname(filename.c_str());
359 if (!sk_mkdir(dir.c_str())) {
360 SkDebugf("Can't make dir %s.\n", dir.c_str());
361 return false;
362 }
363 SkFILEWStream stream(filename.c_str());
364 if (!stream.isValid()) {
365 SkDebugf("Can't write %s.\n", filename.c_str());
366 return false;
367 }
Hal Canarydb683012016-11-23 08:55:18 -0700368 if (!SkEncodeImage(&stream, bmp, SkEncodedImageFormat::kPNG, 100)) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700369 SkDebugf("Can't encode a PNG.\n");
370 return false;
371 }
372 return true;
373}
374
375static int kFailedLoops = -2;
cdaltone1b89582015-06-25 19:17:08 -0700376static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) {
mtkleinbb6a0282014-07-01 08:43:42 -0700377 // First figure out approximately how many loops of bench it takes to make overhead negligible.
mtklein2069e222014-08-04 13:57:39 -0700378 double bench_plus_overhead = 0.0;
mtklein55b0ffc2014-07-17 08:38:23 -0700379 int round = 0;
cdaltonb4022962015-06-25 10:51:56 -0700380 int loops = bench->calculateLoops(FLAGS_loops);
381 if (kAutoTuneLoops == loops) {
bsalomon6eb03cc2014-08-07 14:28:50 -0700382 while (bench_plus_overhead < overhead) {
383 if (round++ == FLAGS_maxCalibrationAttempts) {
384 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
mtklein96289052014-09-10 12:05:59 -0700385 bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead));
bsalomon6eb03cc2014-08-07 14:28:50 -0700386 return kFailedLoops;
387 }
tomhudson75a0ebb2015-03-27 12:11:44 -0700388 bench_plus_overhead = time(1, bench, target);
mtklein55b0ffc2014-07-17 08:38:23 -0700389 }
mtklein2069e222014-08-04 13:57:39 -0700390 }
mtkleinf3723212014-06-25 14:08:00 -0700391
mtkleinbb6a0282014-07-01 08:43:42 -0700392 // Later we'll just start and stop the timer once but loop N times.
mtkleinf3723212014-06-25 14:08:00 -0700393 // We'll pick N to make timer overhead negligible:
394 //
mtkleinbb6a0282014-07-01 08:43:42 -0700395 // overhead
396 // ------------------------- < FLAGS_overheadGoal
397 // overhead + N * Bench Time
mtkleinf3723212014-06-25 14:08:00 -0700398 //
Hal Canary55325b72017-01-03 10:36:17 -0500399 // where bench_plus_overhead ~=~ overhead + Bench Time.
mtkleinf3723212014-06-25 14:08:00 -0700400 //
401 // Doing some math, we get:
402 //
mtkleinbb6a0282014-07-01 08:43:42 -0700403 // (overhead / FLAGS_overheadGoal) - overhead
404 // ------------------------------------------ < N
405 // bench_plus_overhead - overhead)
mtkleinf3723212014-06-25 14:08:00 -0700406 //
407 // Luckily, this also works well in practice. :)
bsalomon6eb03cc2014-08-07 14:28:50 -0700408 if (kAutoTuneLoops == loops) {
409 const double numer = overhead / FLAGS_overheadGoal - overhead;
410 const double denom = bench_plus_overhead - overhead;
411 loops = (int)ceil(numer / denom);
reed53249782014-10-10 09:09:52 -0700412 loops = clamp_loops(loops);
413 } else {
414 loops = detect_forever_loops(loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700415 }
mtkleinbb6a0282014-07-01 08:43:42 -0700416
mtkleinbb6a0282014-07-01 08:43:42 -0700417 return loops;
mtkleinf3723212014-06-25 14:08:00 -0700418}
419
cdaltone1b89582015-06-25 19:17:08 -0700420static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) {
mtkleinbb6a0282014-07-01 08:43:42 -0700421 // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
cdaltonb4022962015-06-25 10:51:56 -0700422 int loops = bench->calculateLoops(FLAGS_loops);
bsalomon6eb03cc2014-08-07 14:28:50 -0700423 if (kAutoTuneLoops == loops) {
424 loops = 1;
mtkleina189ccd2014-07-14 12:28:47 -0700425 double elapsed = 0;
426 do {
mtklein527930f2014-11-06 08:04:34 -0800427 if (1<<30 == loops) {
428 // We're about to wrap. Something's wrong with the bench.
429 loops = 0;
430 break;
431 }
mtkleina189ccd2014-07-14 12:28:47 -0700432 loops *= 2;
433 // If the GPU lets frames lag at all, we need to make sure we're timing
cdaltond416a5b2015-06-23 13:23:44 -0700434 // _this_ round, not still timing last round.
435 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700436 elapsed = time(loops, bench, target);
mtkleina189ccd2014-07-14 12:28:47 -0700437 }
438 } while (elapsed < FLAGS_gpuMs);
mtkleinbb6a0282014-07-01 08:43:42 -0700439
mtkleina189ccd2014-07-14 12:28:47 -0700440 // We've overshot at least a little. Scale back linearly.
441 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
reed53249782014-10-10 09:09:52 -0700442 loops = clamp_loops(loops);
mtkleinbb6a0282014-07-01 08:43:42 -0700443
tomhudsond968a6f2015-03-26 11:28:06 -0700444 // Make sure we're not still timing our calibration.
445 target->fence();
reed53249782014-10-10 09:09:52 -0700446 } else {
447 loops = detect_forever_loops(loops);
mtkleina189ccd2014-07-14 12:28:47 -0700448 }
mtkleinbb6a0282014-07-01 08:43:42 -0700449 // Pretty much the same deal as the calibration: do some warmup to make
450 // sure we're timing steady-state pipelined frames.
Brian Osman01776982017-10-10 15:41:03 -0400451 for (int i = 0; i < maxGpuFrameLag; i++) {
tomhudson75a0ebb2015-03-27 12:11:44 -0700452 time(loops, bench, target);
mtkleinf3723212014-06-25 14:08:00 -0700453 }
mtkleinbb6a0282014-07-01 08:43:42 -0700454
mtkleinbb6a0282014-07-01 08:43:42 -0700455 return loops;
456}
mtkleinbb6a0282014-07-01 08:43:42 -0700457
Brian Salomon6405e712017-03-20 08:54:16 -0400458#define kBogusContextType GrContextFactory::kGL_ContextType
csmartdaltone812d492017-02-21 12:36:05 -0700459#define kBogusContextOverrides GrContextFactory::ContextOverrides::kNone
bsalomonc2553372014-07-22 13:09:05 -0700460
svaisanenc47635e2016-01-28 06:05:43 -0800461static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) {
svaisanenc47635e2016-01-28 06:05:43 -0800462 if (const auto* gpuConfig = config->asConfigGpu()) {
Ben Wagner32fa5102017-08-10 21:25:55 -0400463 if (!FLAGS_gpu) {
464 SkDebugf("Skipping config '%s' as requested.\n", config->getTag().c_str());
svaisanenc47635e2016-01-28 06:05:43 -0800465 return;
Ben Wagner32fa5102017-08-10 21:25:55 -0400466 }
svaisanenc47635e2016-01-28 06:05:43 -0800467
svaisanenc47635e2016-01-28 06:05:43 -0800468 const auto ctxType = gpuConfig->getContextType();
csmartdaltone812d492017-02-21 12:36:05 -0700469 const auto ctxOverrides = gpuConfig->getContextOverrides();
svaisanenc47635e2016-01-28 06:05:43 -0800470 const auto sampleCount = gpuConfig->getSamples();
Greg Daniel81e7bf82017-07-19 14:47:42 -0400471 const auto colorType = gpuConfig->getColorType();
472 auto colorSpace = gpuConfig->getColorSpace();
Brian Salomonf865b052018-03-09 09:01:53 -0500473 if (gpuConfig->getSurfType() != SkCommandLineConfigGpu::SurfType::kDefault) {
474 SkDebugf("This tool only supports the default surface type.");
475 return;
476 }
svaisanenc47635e2016-01-28 06:05:43 -0800477
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400478 GrContextFactory factory(grContextOpts);
479 if (const GrContext* ctx = factory.get(ctxType, ctxOverrides)) {
Greg Daniel6fa62e22019-08-07 15:52:37 -0400480 GrBackendFormat format = ctx->defaultBackendFormat(colorType, GrRenderable::kYes);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500481 int supportedSampleCount =
Greg Daniel6fa62e22019-08-07 15:52:37 -0400482 ctx->priv().caps()->getRenderTargetSampleCount(sampleCount, format);
Greg Daniel81e7bf82017-07-19 14:47:42 -0400483 if (sampleCount != supportedSampleCount) {
Ben Wagner32fa5102017-08-10 21:25:55 -0400484 SkDebugf("Configuration '%s' sample count %d is not a supported sample count.\n",
485 config->getTag().c_str(), sampleCount);
svaisanenc47635e2016-01-28 06:05:43 -0800486 return;
487 }
488 } else {
Ben Wagner32fa5102017-08-10 21:25:55 -0400489 SkDebugf("No context was available matching config '%s'.\n",
490 config->getTag().c_str());
svaisanenc47635e2016-01-28 06:05:43 -0800491 return;
492 }
493
494 Config target = {
kkinnunend4e1c352016-03-01 23:41:26 -0800495 gpuConfig->getTag(),
svaisanenc47635e2016-01-28 06:05:43 -0800496 Benchmark::kGPU_Backend,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400497 colorType,
svaisanenc47635e2016-01-28 06:05:43 -0800498 kPremul_SkAlphaType,
Greg Daniel81e7bf82017-07-19 14:47:42 -0400499 sk_ref_sp(colorSpace),
svaisanenc47635e2016-01-28 06:05:43 -0800500 sampleCount,
501 ctxType,
csmartdaltone812d492017-02-21 12:36:05 -0700502 ctxOverrides,
kkinnunend4e1c352016-03-01 23:41:26 -0800503 gpuConfig->getUseDIText()
504 };
svaisanenc47635e2016-01-28 06:05:43 -0800505
506 configs->push_back(target);
507 return;
508 }
svaisanenc47635e2016-01-28 06:05:43 -0800509
brianosmanb109b8c2016-06-16 13:03:24 -0700510 #define CPU_CONFIG(name, backend, color, alpha, colorSpace) \
511 if (config->getTag().equals(#name)) { \
Ben Wagner32fa5102017-08-10 21:25:55 -0400512 if (!FLAGS_cpu) { \
513 SkDebugf("Skipping config '%s' as requested.\n", \
514 config->getTag().c_str()); \
515 return; \
516 } \
brianosmanb109b8c2016-06-16 13:03:24 -0700517 Config config = { \
518 SkString(#name), Benchmark::backend, color, alpha, colorSpace, \
csmartdaltone812d492017-02-21 12:36:05 -0700519 0, kBogusContextType, kBogusContextOverrides, false \
brianosmanb109b8c2016-06-16 13:03:24 -0700520 }; \
521 configs->push_back(config); \
522 return; \
mtkleinbb6a0282014-07-01 08:43:42 -0700523 }
mtkleine714e752014-07-31 12:13:48 -0700524
Ben Wagner32fa5102017-08-10 21:25:55 -0400525 CPU_CONFIG(nonrendering, kNonRendering_Backend,
526 kUnknown_SkColorType, kUnpremul_SkAlphaType, nullptr)
mtkleinbb6c41b2016-03-08 11:31:11 -0800527
Mike Klein0e4041f2018-06-19 16:00:40 -0400528 CPU_CONFIG(a8, kRaster_Backend, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr)
529 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType, nullptr)
530 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType, nullptr)
531
532 // 'narrow' has a gamut narrower than sRGB, and different transfer function.
Brian Osman82ebe042019-01-04 17:03:00 -0500533 auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50),
Mike Klein0e4041f2018-06-19 16:00:40 -0400534 srgb = SkColorSpace::MakeSRGB(),
535 srgbLinear = SkColorSpace::MakeSRGBLinear();
536
537 CPU_CONFIG( f16, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgbLinear)
538 CPU_CONFIG( srgb, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, srgb )
539 CPU_CONFIG( esrgb, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgb )
540 CPU_CONFIG( narrow, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, narrow )
541 CPU_CONFIG(enarrow, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, narrow )
mtkleinbb6a0282014-07-01 08:43:42 -0700542
svaisanenc47635e2016-01-28 06:05:43 -0800543 #undef CPU_CONFIG
Ben Wagner32fa5102017-08-10 21:25:55 -0400544
545 SkDebugf("Unknown config '%s'.\n", config->getTag().c_str());
mtkleinf3723212014-06-25 14:08:00 -0700546}
547
svaisanenc47635e2016-01-28 06:05:43 -0800548// Append all configs that are enabled and supported.
549void create_configs(SkTArray<Config>* configs) {
550 SkCommandLineConfigArray array;
551 ParseConfigs(FLAGS_config, &array);
552 for (int i = 0; i < array.count(); ++i) {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400553 create_config(array[i].get(), configs);
svaisanenc47635e2016-01-28 06:05:43 -0800554 }
Ben Wagner32fa5102017-08-10 21:25:55 -0400555
556 // If no just default configs were requested, then we're okay.
557 if (array.count() == 0 || FLAGS_config.count() == 0 ||
Ben Wagner32fa5102017-08-10 21:25:55 -0400558 // Otherwise, make sure that all specified configs have been created.
559 array.count() == configs->count()) {
560 return;
561 }
Ben Wagner32fa5102017-08-10 21:25:55 -0400562 exit(1);
svaisanenc47635e2016-01-28 06:05:43 -0800563}
564
brianosman9f1f6e22016-09-15 08:33:02 -0700565// disable warning : switch statement contains default but no 'case' labels
566#if defined _WIN32
567#pragma warning ( push )
568#pragma warning ( disable : 4065 )
569#endif
570
halcanary96fcdcc2015-08-27 07:41:13 -0700571// If bench is enabled for config, returns a Target* for it, otherwise nullptr.
bsalomonc2553372014-07-22 13:09:05 -0700572static Target* is_enabled(Benchmark* bench, const Config& config) {
573 if (!bench->isSuitableFor(config.backend)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700574 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700575 }
576
reede5ea5002014-09-03 11:54:58 -0700577 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY,
brianosmanb109b8c2016-06-16 13:03:24 -0700578 config.color, config.alpha, config.colorSpace);
bsalomonc2553372014-07-22 13:09:05 -0700579
halcanary96fcdcc2015-08-27 07:41:13 -0700580 Target* target = nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700581
tomhudsond968a6f2015-03-26 11:28:06 -0700582 switch (config.backend) {
tomhudsond968a6f2015-03-26 11:28:06 -0700583 case Benchmark::kGPU_Backend:
584 target = new GPUTarget(config);
585 break;
tomhudsond968a6f2015-03-26 11:28:06 -0700586 default:
587 target = new Target(config);
588 break;
589 }
bsalomonc2553372014-07-22 13:09:05 -0700590
tomhudsond968a6f2015-03-26 11:28:06 -0700591 if (!target->init(info, bench)) {
bsalomonc2553372014-07-22 13:09:05 -0700592 delete target;
halcanary96fcdcc2015-08-27 07:41:13 -0700593 return nullptr;
bsalomonc2553372014-07-22 13:09:05 -0700594 }
595 return target;
596}
597
brianosman9f1f6e22016-09-15 08:33:02 -0700598#if defined _WIN32
599#pragma warning ( pop )
600#endif
601
Leon Scroggins III87caae62020-05-04 10:02:45 -0400602#ifdef SK_ENABLE_ANDROID_UTILS
reed42943c82016-09-12 12:01:44 -0700603static bool valid_brd_bench(sk_sp<SkData> encoded, SkColorType colorType, uint32_t sampleSize,
msarettd1227a72016-05-18 06:23:57 -0700604 uint32_t minOutputSize, int* width, int* height) {
Leon Scroggins III87caae62020-05-04 10:02:45 -0400605 auto brd = android::skia::BitmapRegionDecoder::Make(encoded);
msarett7f691442015-09-22 11:56:16 -0700606 if (nullptr == brd.get()) {
607 // This is indicates that subset decoding is not supported for a particular image format.
608 return false;
609 }
610
msarett7f691442015-09-22 11:56:16 -0700611 if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize >
612 (uint32_t) brd->height()) {
613 // This indicates that the image is not large enough to decode a
614 // minOutputSize x minOutputSize subset at the given sampleSize.
615 return false;
616 }
617
618 // Set the image width and height. The calling code will use this to choose subsets to decode.
619 *width = brd->width();
620 *height = brd->height();
621 return true;
622}
Leon Scroggins III87caae62020-05-04 10:02:45 -0400623#endif
msarett7f691442015-09-22 11:56:16 -0700624
egdaniel3bf92062015-06-26 08:12:46 -0700625static void cleanup_run(Target* target) {
halcanary385fe4d2015-08-26 13:07:48 -0700626 delete target;
egdaniel3bf92062015-06-26 08:12:46 -0700627}
628
Mike Klein88544fb2019-03-20 10:50:33 -0500629static void collect_files(const CommandLineFlags::StringArray& paths,
630 const char* ext,
631 SkTArray<SkString>* list) {
fmalita6519c212016-09-14 08:05:17 -0700632 for (int i = 0; i < paths.count(); ++i) {
633 if (SkStrEndsWith(paths[i], ext)) {
634 list->push_back(SkString(paths[i]));
635 } else {
636 SkOSFile::Iter it(paths[i], ext);
637 SkString path;
638 while (it.next(&path)) {
639 list->push_back(SkOSPath::Join(paths[i], path.c_str()));
640 }
641 }
642 }
643}
644
mtkleine714e752014-07-31 12:13:48 -0700645class BenchmarkStream {
646public:
mtklein92007582014-08-01 07:46:52 -0700647 BenchmarkStream() : fBenches(BenchRegistry::Head())
Hal Canary2362ae72019-10-24 13:40:40 -0400648 , fGMs(skiagm::GMRegistry::Head()) {
fmalita6519c212016-09-14 08:05:17 -0700649 collect_files(FLAGS_skps, ".skp", &fSKPs);
650 collect_files(FLAGS_svgs, ".svg", &fSVGs);
Hal Canary5dfefa22019-10-24 13:52:17 -0400651 collect_files(FLAGS_texttraces, ".trace", &fTextBlobTraces);
mtkleine714e752014-07-31 12:13:48 -0700652
mtklein92007582014-08-01 07:46:52 -0700653 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
654 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) {
655 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]);
656 exit(1);
657 }
658
659 for (int i = 0; i < FLAGS_scales.count(); i++) {
660 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
661 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]);
662 exit(1);
663 }
664 }
robertphillips5b693772014-11-21 06:19:36 -0800665
cdalton63a82852015-06-29 14:06:10 -0700666 if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) {
667 SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]);
joshualitt261c3ad2015-04-27 09:16:57 -0700668 exit(1);
669 }
670
robertphillips5b693772014-11-21 06:19:36 -0800671 if (FLAGS_mpd) {
672 fUseMPDs.push_back() = true;
673 }
mtkleinc751ecb2015-06-15 08:56:38 -0700674 fUseMPDs.push_back() = false;
mtklein95553d92015-03-12 08:24:21 -0700675
msarett95f192d2015-02-13 09:05:41 -0800676 // Prepare the images for decoding
msarett69deca82016-04-29 09:38:40 -0700677 if (!CollectImages(FLAGS_images, &fImages)) {
scroggo86737142016-02-03 12:19:11 -0800678 exit(1);
msarett95f192d2015-02-13 09:05:41 -0800679 }
mtklein95553d92015-03-12 08:24:21 -0700680
msarett95f192d2015-02-13 09:05:41 -0800681 // Choose the candidate color types for image decoding
msarett67cb6662016-06-21 08:49:26 -0700682 fColorTypes.push_back(kN32_SkColorType);
683 if (!FLAGS_simpleCodec) {
684 fColorTypes.push_back(kRGB_565_SkColorType);
685 fColorTypes.push_back(kAlpha_8_SkColorType);
msarett67cb6662016-06-21 08:49:26 -0700686 fColorTypes.push_back(kGray_8_SkColorType);
687 }
mtklein92007582014-08-01 07:46:52 -0700688 }
689
reedca2622b2016-03-18 07:25:55 -0700690 static sk_sp<SkPicture> ReadPicture(const char* path) {
mtkleinfd731ce2014-09-10 12:19:30 -0700691 // Not strictly necessary, as it will be checked again later,
692 // but helps to avoid a lot of pointless work if we're going to skip it.
Mike Klein88544fb2019-03-20 10:50:33 -0500693 if (CommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) {
reedca2622b2016-03-18 07:25:55 -0700694 return nullptr;
mtkleinfd731ce2014-09-10 12:19:30 -0700695 }
696
bungemanf93d7112016-09-16 06:24:20 -0700697 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
698 if (!stream) {
mtkleinfd731ce2014-09-10 12:19:30 -0700699 SkDebugf("Could not read %s.\n", path);
reedca2622b2016-03-18 07:25:55 -0700700 return nullptr;
mtkleinfd731ce2014-09-10 12:19:30 -0700701 }
702
reedca2622b2016-03-18 07:25:55 -0700703 return SkPicture::MakeFromStream(stream.get());
mtkleinfd731ce2014-09-10 12:19:30 -0700704 }
705
fmalita6519c212016-09-14 08:05:17 -0700706 static sk_sp<SkPicture> ReadSVGPicture(const char* path) {
Brian Osman133823d2018-09-19 14:14:15 -0400707 sk_sp<SkData> data(SkData::MakeFromFileName(path));
708 if (!data) {
fmalita6519c212016-09-14 08:05:17 -0700709 SkDebugf("Could not read %s.\n", path);
710 return nullptr;
711 }
712
Hal Canary0f666812018-03-22 15:21:12 -0400713#ifdef SK_XML
Brian Osman133823d2018-09-19 14:14:15 -0400714 SkMemoryStream stream(std::move(data));
fmalitae1baa7c2016-09-14 12:04:30 -0700715 sk_sp<SkSVGDOM> svgDom = SkSVGDOM::MakeFromStream(stream);
fmalita6519c212016-09-14 08:05:17 -0700716 if (!svgDom) {
717 SkDebugf("Could not parse %s.\n", path);
718 return nullptr;
719 }
720
fmalitae1baa7c2016-09-14 12:04:30 -0700721 // Use the intrinsic SVG size if available, otherwise fall back to a default value.
722 static const SkSize kDefaultContainerSize = SkSize::Make(128, 128);
723 if (svgDom->containerSize().isEmpty()) {
724 svgDom->setContainerSize(kDefaultContainerSize);
725 }
726
fmalita6519c212016-09-14 08:05:17 -0700727 SkPictureRecorder recorder;
fmalitae1baa7c2016-09-14 12:04:30 -0700728 svgDom->render(recorder.beginRecording(svgDom->containerSize().width(),
729 svgDom->containerSize().height()));
fmalita6519c212016-09-14 08:05:17 -0700730 return recorder.finishRecordingAsPicture();
Hal Canary0f666812018-03-22 15:21:12 -0400731#else
732 return nullptr;
733#endif // SK_XML
fmalita6519c212016-09-14 08:05:17 -0700734 }
735
mtklein92007582014-08-01 07:46:52 -0700736 Benchmark* next() {
Ben Wagner145dbcd2016-11-03 14:40:50 -0400737 std::unique_ptr<Benchmark> bench;
mtklein65dfd2f2016-02-03 10:40:54 -0800738 do {
739 bench.reset(this->rawNext());
740 if (!bench) {
741 return nullptr;
742 }
Mike Klein88544fb2019-03-20 10:50:33 -0500743 } while (CommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) ||
744 CommandLineFlags::ShouldSkip(FLAGS_benchType, fBenchType));
mtklein18300a32016-03-16 13:53:35 -0700745 return bench.release();
mtklein65dfd2f2016-02-03 10:40:54 -0800746 }
747
748 Benchmark* rawNext() {
mtkleine714e752014-07-31 12:13:48 -0700749 if (fBenches) {
Hal Canary972eba32018-07-30 17:07:07 -0400750 Benchmark* bench = fBenches->get()(nullptr);
mtkleine714e752014-07-31 12:13:48 -0700751 fBenches = fBenches->next();
mtklein92007582014-08-01 07:46:52 -0700752 fSourceType = "bench";
mtkleinfd731ce2014-09-10 12:19:30 -0700753 fBenchType = "micro";
mtkleine714e752014-07-31 12:13:48 -0700754 return bench;
755 }
mtklein92007582014-08-01 07:46:52 -0700756
mtkleine714e752014-07-31 12:13:48 -0700757 while (fGMs) {
Ben Wagner406ff502019-08-12 16:39:24 -0400758 std::unique_ptr<skiagm::GM> gm = fGMs->get()();
mtkleine714e752014-07-31 12:13:48 -0700759 fGMs = fGMs->next();
mtkleincf5d9c92015-01-23 10:31:45 -0800760 if (gm->runAsBench()) {
mtklein92007582014-08-01 07:46:52 -0700761 fSourceType = "gm";
mtkleinfd731ce2014-09-10 12:19:30 -0700762 fBenchType = "micro";
Ben Wagner406ff502019-08-12 16:39:24 -0400763 return new GMBench(std::move(gm));
mtkleine714e752014-07-31 12:13:48 -0700764 }
765 }
mtklein92007582014-08-01 07:46:52 -0700766
Hal Canary5dfefa22019-10-24 13:52:17 -0400767 while (fCurrentTextBlobTrace < fTextBlobTraces.count()) {
768 SkString path = fTextBlobTraces[fCurrentTextBlobTrace++];
769 SkString basename = SkOSPath::Basename(path.c_str());
770 static constexpr char kEnding[] = ".trace";
771 if (basename.endsWith(kEnding)) {
772 basename.remove(basename.size() - strlen(kEnding), strlen(kEnding));
773 }
774 fSourceType = "texttrace";
775 fBenchType = "micro";
776 return CreateDiffCanvasBench(
777 SkStringPrintf("SkDiffBench-%s", basename.c_str()),
778 [path](){ return SkStream::MakeFromFile(path.c_str()); });
779 }
780
mtkleinfd731ce2014-09-10 12:19:30 -0700781 // First add all .skps as RecordingBenches.
782 while (fCurrentRecording < fSKPs.count()) {
783 const SkString& path = fSKPs[fCurrentRecording++];
reedca2622b2016-03-18 07:25:55 -0700784 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
785 if (!pic) {
mtkleinfd731ce2014-09-10 12:19:30 -0700786 continue;
787 }
788 SkString name = SkOSPath::Basename(path.c_str());
789 fSourceType = "skp";
790 fBenchType = "recording";
Mike Klein88d90712018-01-27 17:30:04 +0000791 fSKPBytes = static_cast<double>(pic->approximateBytesUsed());
792 fSKPOps = pic->approximateOpCount();
Mike Kleina705cb92019-05-14 12:33:40 -0500793 return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh);
mtkleinfd731ce2014-09-10 12:19:30 -0700794 }
795
Mike Reede45ff462017-12-06 10:47:03 -0500796 // Add all .skps as DeserializePictureBenchs.
797 while (fCurrentDeserialPicture < fSKPs.count()) {
798 const SkString& path = fSKPs[fCurrentDeserialPicture++];
799 sk_sp<SkData> data = SkData::MakeFromFileName(path.c_str());
800 if (!data) {
801 continue;
802 }
803 SkString name = SkOSPath::Basename(path.c_str());
804 fSourceType = "skp";
805 fBenchType = "deserial";
Mike Reed7557bbb2017-12-24 19:50:57 -0500806 fSKPBytes = static_cast<double>(data->size());
Mike Klein88d90712018-01-27 17:30:04 +0000807 fSKPOps = 0;
Mike Reede45ff462017-12-06 10:47:03 -0500808 return new DeserializePictureBench(name.c_str(), std::move(data));
809 }
810
mtkleinfd731ce2014-09-10 12:19:30 -0700811 // Then once each for each scale as SKPBenches (playback).
mtklein92007582014-08-01 07:46:52 -0700812 while (fCurrentScale < fScales.count()) {
813 while (fCurrentSKP < fSKPs.count()) {
robertphillips5b693772014-11-21 06:19:36 -0800814 const SkString& path = fSKPs[fCurrentSKP];
reedca2622b2016-03-18 07:25:55 -0700815 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
816 if (!pic) {
robertphillips5b693772014-11-21 06:19:36 -0800817 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700818 continue;
819 }
robertphillips5b693772014-11-21 06:19:36 -0800820
821 while (fCurrentUseMPD < fUseMPDs.count()) {
822 if (FLAGS_bbh) {
823 // The SKP we read off disk doesn't have a BBH. Re-record so it grows one.
824 SkRTreeFactory factory;
825 SkPictureRecorder recorder;
robertphillips5b693772014-11-21 06:19:36 -0800826 pic->playback(recorder.beginRecording(pic->cullRect().width(),
827 pic->cullRect().height(),
mtklein748ca3b2015-01-15 10:56:12 -0800828 &factory,
robertphillipsdda54452016-07-13 13:27:16 -0700829 0));
reedca2622b2016-03-18 07:25:55 -0700830 pic = recorder.finishRecordingAsPicture();
robertphillips5b693772014-11-21 06:19:36 -0800831 }
832 SkString name = SkOSPath::Basename(path.c_str());
833 fSourceType = "skp";
834 fBenchType = "playback";
halcanary385fe4d2015-08-26 13:07:48 -0700835 return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale],
836 fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP);
mtklein20840502014-08-21 15:51:22 -0700837 }
robertphillips5b693772014-11-21 06:19:36 -0800838 fCurrentUseMPD = 0;
839 fCurrentSKP++;
mtklein92007582014-08-01 07:46:52 -0700840 }
fmalita6519c212016-09-14 08:05:17 -0700841
842 while (fCurrentSVG++ < fSVGs.count()) {
843 const char* path = fSVGs[fCurrentSVG - 1].c_str();
844 if (sk_sp<SkPicture> pic = ReadSVGPicture(path)) {
845 fSourceType = "svg";
846 fBenchType = "playback";
847 return new SKPBench(SkOSPath::Basename(path).c_str(), pic.get(), fClip,
848 fScales[fCurrentScale], false, FLAGS_loopSKP);
849 }
850 }
851
mtklein92007582014-08-01 07:46:52 -0700852 fCurrentSKP = 0;
fmalita6519c212016-09-14 08:05:17 -0700853 fCurrentSVG = 0;
mtklein92007582014-08-01 07:46:52 -0700854 fCurrentScale++;
855 }
856
joshualitt261c3ad2015-04-27 09:16:57 -0700857 // Now loop over each skp again if we have an animation
cdalton63a82852015-06-29 14:06:10 -0700858 if (fZoomMax != 1.0f && fZoomPeriodMs > 0) {
joshualitt261c3ad2015-04-27 09:16:57 -0700859 while (fCurrentAnimSKP < fSKPs.count()) {
860 const SkString& path = fSKPs[fCurrentAnimSKP];
reedca2622b2016-03-18 07:25:55 -0700861 sk_sp<SkPicture> pic = ReadPicture(path.c_str());
862 if (!pic) {
joshualitt261c3ad2015-04-27 09:16:57 -0700863 fCurrentAnimSKP++;
864 continue;
865 }
866
867 fCurrentAnimSKP++;
868 SkString name = SkOSPath::Basename(path.c_str());
Ben Wagneracf98df2019-07-12 12:51:44 -0400869 sk_sp<SKPAnimationBench::Animation> animation =
870 SKPAnimationBench::MakeZoomAnimation(fZoomMax, fZoomPeriodMs);
871 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, std::move(animation),
halcanary385fe4d2015-08-26 13:07:48 -0700872 FLAGS_loopSKP);
joshualitt261c3ad2015-04-27 09:16:57 -0700873 }
874 }
875
scroggo60869a42015-04-01 12:09:17 -0700876 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) {
scroggo303fa352015-10-05 11:03:34 -0700877 fSourceType = "image";
878 fBenchType = "skcodec";
scroggo60869a42015-04-01 12:09:17 -0700879 const SkString& path = fImages[fCurrentCodec];
Mike Klein88544fb2019-03-20 10:50:33 -0500880 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
mtklein6f0ff912016-01-11 09:04:21 -0800881 continue;
882 }
bungeman38d909e2016-08-02 14:40:46 -0700883 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400884 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
scroggo60869a42015-04-01 12:09:17 -0700885 if (!codec) {
886 // Nothing to time.
msarett9d9725c2015-04-24 11:41:55 -0700887 SkDebugf("Cannot find codec for %s\n", path.c_str());
scroggo60869a42015-04-01 12:09:17 -0700888 continue;
889 }
scroggo21027992015-04-02 13:22:38 -0700890
scroggo60869a42015-04-01 12:09:17 -0700891 while (fCurrentColorType < fColorTypes.count()) {
scroggo21027992015-04-02 13:22:38 -0700892 const SkColorType colorType = fColorTypes[fCurrentColorType];
scroggo21027992015-04-02 13:22:38 -0700893
msarettc7796b92016-01-07 14:20:20 -0800894 SkAlphaType alphaType = codec->getInfo().alphaType();
msarett67cb6662016-06-21 08:49:26 -0700895 if (FLAGS_simpleCodec) {
896 if (kUnpremul_SkAlphaType == alphaType) {
897 alphaType = kPremul_SkAlphaType;
898 }
899
900 fCurrentColorType++;
901 } else {
902 switch (alphaType) {
903 case kOpaque_SkAlphaType:
904 // We only need to test one alpha type (opaque).
msarettc7796b92016-01-07 14:20:20 -0800905 fCurrentColorType++;
msarett67cb6662016-06-21 08:49:26 -0700906 break;
907 case kUnpremul_SkAlphaType:
908 case kPremul_SkAlphaType:
909 if (0 == fCurrentAlphaType) {
910 // Test unpremul first.
911 alphaType = kUnpremul_SkAlphaType;
912 fCurrentAlphaType++;
913 } else {
914 // Test premul.
915 alphaType = kPremul_SkAlphaType;
916 fCurrentAlphaType = 0;
917 fCurrentColorType++;
918 }
919 break;
920 default:
921 SkASSERT(false);
922 fCurrentColorType++;
923 break;
924 }
scroggo21027992015-04-02 13:22:38 -0700925 }
926
msarettc7796b92016-01-07 14:20:20 -0800927 // Make sure we can decode to this color type and alpha type.
928 SkImageInfo info =
929 codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType);
scroggo21027992015-04-02 13:22:38 -0700930 const size_t rowBytes = info.minRowBytes();
Mike Reedf0ffb892017-10-03 14:47:21 -0400931 SkAutoMalloc storage(info.computeByteSize(rowBytes));
scroggo21027992015-04-02 13:22:38 -0700932
scroggoeb602a52015-07-09 08:16:03 -0700933 const SkCodec::Result result = codec->getPixels(
Leon Scroggins571b30f2017-07-11 17:35:31 +0000934 info, storage.get(), rowBytes);
scroggo60869a42015-04-01 12:09:17 -0700935 switch (result) {
scroggoeb602a52015-07-09 08:16:03 -0700936 case SkCodec::kSuccess:
937 case SkCodec::kIncompleteInput:
scroggo60869a42015-04-01 12:09:17 -0700938 return new CodecBench(SkOSPath::Basename(path.c_str()),
bungeman38d909e2016-08-02 14:40:46 -0700939 encoded.get(), colorType, alphaType);
scroggoeb602a52015-07-09 08:16:03 -0700940 case SkCodec::kInvalidConversion:
scroggo60869a42015-04-01 12:09:17 -0700941 // This is okay. Not all conversions are valid.
942 break;
scroggo60869a42015-04-01 12:09:17 -0700943 default:
944 // This represents some sort of failure.
945 SkASSERT(false);
946 break;
947 }
948 }
949 fCurrentColorType = 0;
950 }
951
msarett84451022016-02-11 06:45:51 -0800952 // Run AndroidCodecBenches
953 const int sampleSizes[] = { 2, 4, 8 };
954 for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) {
955 fSourceType = "image";
956 fBenchType = "skandroidcodec";
957
958 const SkString& path = fImages[fCurrentAndroidCodec];
Mike Klein88544fb2019-03-20 10:50:33 -0500959 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
msarett84451022016-02-11 06:45:51 -0800960 continue;
961 }
bungeman38d909e2016-08-02 14:40:46 -0700962 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -0400963 std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
msarett84451022016-02-11 06:45:51 -0800964 if (!codec) {
965 // Nothing to time.
966 SkDebugf("Cannot find codec for %s\n", path.c_str());
967 continue;
968 }
969
970 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) {
971 int sampleSize = sampleSizes[fCurrentSampleSize];
972 fCurrentSampleSize++;
Brian Osman788b9162020-02-07 10:36:46 -0500973 if (10 * sampleSize > std::min(codec->getInfo().width(), codec->getInfo().height())) {
msarett84451022016-02-11 06:45:51 -0800974 // Avoid benchmarking scaled decodes of already small images.
975 break;
976 }
977
bungeman38d909e2016-08-02 14:40:46 -0700978 return new AndroidCodecBench(SkOSPath::Basename(path.c_str()),
979 encoded.get(), sampleSize);
msarett84451022016-02-11 06:45:51 -0800980 }
981 fCurrentSampleSize = 0;
982 }
983
Leon Scroggins III87caae62020-05-04 10:02:45 -0400984#ifdef SK_ENABLE_ANDROID_UTILS
msarett7f691442015-09-22 11:56:16 -0700985 // Run the BRDBenches
msarett7f691442015-09-22 11:56:16 -0700986 // We intend to create benchmarks that model the use cases in
987 // android/libraries/social/tiledimage. In this library, an image is decoded in 512x512
988 // tiles. The image can be translated freely, so the location of a tile may be anywhere in
989 // the image. For that reason, we will benchmark decodes in five representative locations
990 // in the image. Additionally, this use case utilizes power of two scaling, so we will
991 // test on power of two sample sizes. The output tile is always 512x512, so, when a
992 // sampleSize is used, the size of the subset that is decoded is always
993 // (sampleSize*512)x(sampleSize*512).
994 // There are a few good reasons to only test on power of two sample sizes at this time:
msarett7f691442015-09-22 11:56:16 -0700995 // All use cases we are aware of only scale by powers of two.
996 // PNG decodes use the indicated sampling strategy regardless of the sample size, so
997 // these tests are sufficient to provide good coverage of our scaling options.
msarett84451022016-02-11 06:45:51 -0800998 const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 };
msarett7f691442015-09-22 11:56:16 -0700999 const uint32_t minOutputSize = 512;
mtklein6f0ff912016-01-11 09:04:21 -08001000 for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) {
msarettd1227a72016-05-18 06:23:57 -07001001 fSourceType = "image";
1002 fBenchType = "BRD";
1003
mtklein6f0ff912016-01-11 09:04:21 -08001004 const SkString& path = fImages[fCurrentBRDImage];
Mike Klein88544fb2019-03-20 10:50:33 -05001005 if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) {
mtklein6f0ff912016-01-11 09:04:21 -08001006 continue;
1007 }
scroggo860e8a62015-10-15 07:51:28 -07001008
msarettd1227a72016-05-18 06:23:57 -07001009 while (fCurrentColorType < fColorTypes.count()) {
1010 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) {
1011 while (fCurrentSubsetType <= kLastSingle_SubsetType) {
scroggo860e8a62015-10-15 07:51:28 -07001012
bungeman38d909e2016-08-02 14:40:46 -07001013 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
msarettd1227a72016-05-18 06:23:57 -07001014 const SkColorType colorType = fColorTypes[fCurrentColorType];
1015 uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize];
1016 int currentSubsetType = fCurrentSubsetType++;
scroggo860e8a62015-10-15 07:51:28 -07001017
msarettd1227a72016-05-18 06:23:57 -07001018 int width = 0;
1019 int height = 0;
reed42943c82016-09-12 12:01:44 -07001020 if (!valid_brd_bench(encoded, colorType, sampleSize, minOutputSize,
msarettd1227a72016-05-18 06:23:57 -07001021 &width, &height)) {
1022 break;
msarett7f691442015-09-22 11:56:16 -07001023 }
msarettd1227a72016-05-18 06:23:57 -07001024
1025 SkString basename = SkOSPath::Basename(path.c_str());
1026 SkIRect subset;
1027 const uint32_t subsetSize = sampleSize * minOutputSize;
1028 switch (currentSubsetType) {
1029 case kTopLeft_SubsetType:
1030 basename.append("_TopLeft");
1031 subset = SkIRect::MakeXYWH(0, 0, subsetSize, subsetSize);
1032 break;
1033 case kTopRight_SubsetType:
1034 basename.append("_TopRight");
1035 subset = SkIRect::MakeXYWH(width - subsetSize, 0, subsetSize,
1036 subsetSize);
1037 break;
1038 case kMiddle_SubsetType:
1039 basename.append("_Middle");
1040 subset = SkIRect::MakeXYWH((width - subsetSize) / 2,
1041 (height - subsetSize) / 2, subsetSize, subsetSize);
1042 break;
1043 case kBottomLeft_SubsetType:
1044 basename.append("_BottomLeft");
1045 subset = SkIRect::MakeXYWH(0, height - subsetSize, subsetSize,
1046 subsetSize);
1047 break;
1048 case kBottomRight_SubsetType:
1049 basename.append("_BottomRight");
1050 subset = SkIRect::MakeXYWH(width - subsetSize,
1051 height - subsetSize, subsetSize, subsetSize);
1052 break;
1053 default:
1054 SkASSERT(false);
1055 }
1056
1057 return new BitmapRegionDecoderBench(basename.c_str(), encoded.get(),
1058 colorType, sampleSize, subset);
msarett7f691442015-09-22 11:56:16 -07001059 }
msarettd1227a72016-05-18 06:23:57 -07001060 fCurrentSubsetType = 0;
1061 fCurrentSampleSize++;
msarett7f691442015-09-22 11:56:16 -07001062 }
msarettd1227a72016-05-18 06:23:57 -07001063 fCurrentSampleSize = 0;
1064 fCurrentColorType++;
msarett7f691442015-09-22 11:56:16 -07001065 }
msarettd1227a72016-05-18 06:23:57 -07001066 fCurrentColorType = 0;
msarett7f691442015-09-22 11:56:16 -07001067 }
Leon Scroggins III87caae62020-05-04 10:02:45 -04001068#endif // SK_ENABLE_ANDROID_UTILS
msarett7f691442015-09-22 11:56:16 -07001069
halcanary96fcdcc2015-08-27 07:41:13 -07001070 return nullptr;
mtkleine714e752014-07-31 12:13:48 -07001071 }
mtklein92007582014-08-01 07:46:52 -07001072
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001073 void fillCurrentOptions(NanoJSONResultsWriter& log) const {
1074 log.appendString("source_type", fSourceType);
1075 log.appendString("bench_type", fBenchType);
mtklein92007582014-08-01 07:46:52 -07001076 if (0 == strcmp(fSourceType, "skp")) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001077 log.appendString("clip",
mtklein92007582014-08-01 07:46:52 -07001078 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
1079 fClip.fRight, fClip.fBottom).c_str());
djsollenf2b340f2016-01-29 08:51:04 -08001080 SkASSERT_RELEASE(fCurrentScale < fScales.count()); // debugging paranoia
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001081 log.appendString("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
robertphillips5b693772014-11-21 06:19:36 -08001082 if (fCurrentUseMPD > 0) {
1083 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001084 log.appendString("multi_picture_draw",
1085 fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
robertphillips5b693772014-11-21 06:19:36 -08001086 }
mtklein92007582014-08-01 07:46:52 -07001087 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001088 }
1089
1090 void fillCurrentMetrics(NanoJSONResultsWriter& log) const {
mtklein051e56d2014-12-04 08:46:51 -08001091 if (0 == strcmp(fBenchType, "recording")) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001092 log.appendMetric("bytes", fSKPBytes);
1093 log.appendMetric("ops", fSKPOps);
mtklein051e56d2014-12-04 08:46:51 -08001094 }
mtklein92007582014-08-01 07:46:52 -07001095 }
1096
mtkleine714e752014-07-31 12:13:48 -07001097private:
Leon Scroggins III87caae62020-05-04 10:02:45 -04001098#ifdef SK_ENABLE_ANDROID_UTILS
msarettb23e6aa2015-06-09 13:56:10 -07001099 enum SubsetType {
1100 kTopLeft_SubsetType = 0,
1101 kTopRight_SubsetType = 1,
msarettab80e352015-06-17 10:28:22 -07001102 kMiddle_SubsetType = 2,
1103 kBottomLeft_SubsetType = 3,
1104 kBottomRight_SubsetType = 4,
1105 kTranslate_SubsetType = 5,
1106 kZoom_SubsetType = 6,
msarett7f691442015-09-22 11:56:16 -07001107 kLast_SubsetType = kZoom_SubsetType,
1108 kLastSingle_SubsetType = kBottomRight_SubsetType,
msarettb23e6aa2015-06-09 13:56:10 -07001109 };
Leon Scroggins III87caae62020-05-04 10:02:45 -04001110#endif
msarettb23e6aa2015-06-09 13:56:10 -07001111
mtkleine714e752014-07-31 12:13:48 -07001112 const BenchRegistry* fBenches;
1113 const skiagm::GMRegistry* fGMs;
mtklein92007582014-08-01 07:46:52 -07001114 SkIRect fClip;
1115 SkTArray<SkScalar> fScales;
1116 SkTArray<SkString> fSKPs;
fmalita6519c212016-09-14 08:05:17 -07001117 SkTArray<SkString> fSVGs;
Hal Canary5dfefa22019-10-24 13:52:17 -04001118 SkTArray<SkString> fTextBlobTraces;
robertphillips5b693772014-11-21 06:19:36 -08001119 SkTArray<bool> fUseMPDs;
msarett95f192d2015-02-13 09:05:41 -08001120 SkTArray<SkString> fImages;
msarett74deb982015-10-20 16:45:56 -07001121 SkTArray<SkColorType, true> fColorTypes;
cdalton63a82852015-06-29 14:06:10 -07001122 SkScalar fZoomMax;
1123 double fZoomPeriodMs;
mtklein92007582014-08-01 07:46:52 -07001124
Mike Klein88d90712018-01-27 17:30:04 +00001125 double fSKPBytes, fSKPOps;
mtklein051e56d2014-12-04 08:46:51 -08001126
mtkleinfd731ce2014-09-10 12:19:30 -07001127 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
1128 const char* fBenchType; // How we bench it: micro, recording, playback, ...
Hal Canary2362ae72019-10-24 13:40:40 -04001129 int fCurrentRecording = 0;
1130 int fCurrentDeserialPicture = 0;
1131 int fCurrentScale = 0;
1132 int fCurrentSKP = 0;
1133 int fCurrentSVG = 0;
Hal Canary5dfefa22019-10-24 13:52:17 -04001134 int fCurrentTextBlobTrace = 0;
Hal Canary2362ae72019-10-24 13:40:40 -04001135 int fCurrentUseMPD = 0;
1136 int fCurrentCodec = 0;
1137 int fCurrentAndroidCodec = 0;
Leon Scroggins III87caae62020-05-04 10:02:45 -04001138#ifdef SK_ENABLE_ANDROID_UTILS
Hal Canary2362ae72019-10-24 13:40:40 -04001139 int fCurrentBRDImage = 0;
Leon Scroggins III87caae62020-05-04 10:02:45 -04001140 int fCurrentSubsetType = 0;
1141#endif
Hal Canary2362ae72019-10-24 13:40:40 -04001142 int fCurrentColorType = 0;
1143 int fCurrentAlphaType = 0;
Hal Canary2362ae72019-10-24 13:40:40 -04001144 int fCurrentSampleSize = 0;
1145 int fCurrentAnimSKP = 0;
mtkleine714e752014-07-31 12:13:48 -07001146};
1147
msarettc149f0e2016-01-04 11:35:43 -08001148// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1149// This prints something every once in a while so that it knows we're still working.
1150static void start_keepalive() {
Mike Klein03141d22017-10-30 11:57:15 -04001151 static std::thread* intentionallyLeaked = new std::thread([]{
1152 for (;;) {
1153 static const int kSec = 1200;
1154 #if defined(SK_BUILD_FOR_WIN)
1155 Sleep(kSec * 1000);
1156 #else
1157 sleep(kSec);
1158 #endif
1159 SkDebugf("\nBenchmarks still running...\n");
msarettc149f0e2016-01-04 11:35:43 -08001160 }
Mike Klein03141d22017-10-30 11:57:15 -04001161 });
1162 (void)intentionallyLeaked;
msarettc149f0e2016-01-04 11:35:43 -08001163}
1164
Mike Kleinbe28ee22017-02-06 12:46:20 -05001165int main(int argc, char** argv) {
Mike Klein88544fb2019-03-20 10:50:33 -05001166 CommandLineFlags::Parse(argc, argv);
Brian Osman53136aa2017-07-20 15:43:35 -04001167
Brian Osmanbc8150f2017-07-24 11:38:01 -04001168 initializeEventTracingForTools();
Brian Osman53136aa2017-07-20 15:43:35 -04001169
Mike Kleinadacaef2017-02-06 09:26:14 -05001170#if defined(SK_BUILD_FOR_IOS)
1171 cd_Documents();
1172#endif
jcgregorio3b27ade2014-11-13 08:06:40 -08001173 SetupCrashHandler();
mtkleinf3723212014-06-25 14:08:00 -07001174 SkAutoGraphics ag;
mtkleincc29d262015-07-09 10:04:56 -07001175 SkTaskGroup::Enabler enabled(FLAGS_threads);
mtkleinf3723212014-06-25 14:08:00 -07001176
Chris Dalton040238b2017-12-18 14:22:34 -07001177 SetCtxOptionsFromCommonFlags(&grContextOpts);
krajcevski69a55602014-08-13 10:46:31 -07001178
bsalomon6eb03cc2014-08-07 14:28:50 -07001179 if (kAutoTuneLoops != FLAGS_loops) {
mtkleina189ccd2014-07-14 12:28:47 -07001180 FLAGS_samples = 1;
1181 FLAGS_gpuFrameLag = 0;
1182 }
1183
bsalomon6eb03cc2014-08-07 14:28:50 -07001184 if (!FLAGS_writePath.isEmpty()) {
1185 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]);
1186 if (!sk_mkdir(FLAGS_writePath[0])) {
1187 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]);
halcanary96fcdcc2015-08-27 07:41:13 -07001188 FLAGS_writePath.set(0, nullptr);
bsalomon6eb03cc2014-08-07 14:28:50 -07001189 }
1190 }
1191
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001192 std::unique_ptr<SkWStream> logStream(new SkNullWStream);
mtklein60317d0f2014-07-14 11:30:37 -07001193 if (!FLAGS_outResultsFile.isEmpty()) {
mtklein53520152016-01-20 09:53:59 -08001194#if defined(SK_RELEASE)
Chris Dalton2e1381e2019-10-23 14:35:19 -06001195 // SkJSONWriter uses a 32k in-memory cache, so it only flushes occasionally and is well
1196 // equipped for a stream that re-opens, appends, and closes the file on every write.
1197 logStream.reset(new NanoFILEAppendAndCloseStream(FLAGS_outResultsFile[0]));
mtklein53520152016-01-20 09:53:59 -08001198#else
1199 SkDebugf("I'm ignoring --outResultsFile because this is a Debug build.");
1200 return 1;
1201#endif
mtklein60317d0f2014-07-14 11:30:37 -07001202 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001203 NanoJSONResultsWriter log(logStream.get(), SkJSONWriter::Mode::kPretty);
1204 log.beginObject(); // root
mtklein1915b622014-08-20 11:45:00 -07001205
1206 if (1 == FLAGS_properties.count() % 2) {
1207 SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n");
1208 return 1;
1209 }
1210 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001211 log.appendString(FLAGS_properties[i-1], FLAGS_properties[i]);
mtklein1915b622014-08-20 11:45:00 -07001212 }
jcgregoriobf5e5232014-07-17 13:14:16 -07001213
1214 if (1 == FLAGS_key.count() % 2) {
1215 SkDebugf("ERROR: --key must be passed with an even number of arguments.\n");
1216 return 1;
1217 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001218 if (FLAGS_key.count()) {
1219 log.beginObject("key");
1220 for (int i = 1; i < FLAGS_key.count(); i += 2) {
1221 log.appendString(FLAGS_key[i - 1], FLAGS_key[i]);
1222 }
1223 log.endObject(); // key
mtklein94e51562014-08-19 12:41:53 -07001224 }
mtklein60317d0f2014-07-14 11:30:37 -07001225
mtkleinf3723212014-06-25 14:08:00 -07001226 const double overhead = estimate_timer_overhead();
mtklein55b0ffc2014-07-17 08:38:23 -07001227 SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead));
Mike Klein91294772014-07-16 19:59:32 -04001228
cdaltone1b89582015-06-25 19:17:08 -07001229 SkTArray<double> samples;
mtkleinbb6a0282014-07-01 08:43:42 -07001230
bsalomon6eb03cc2014-08-07 14:28:50 -07001231 if (kAutoTuneLoops != FLAGS_loops) {
1232 SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n");
mtkleinf3723212014-06-25 14:08:00 -07001233 } else if (FLAGS_quiet) {
mtklein66cfcff2015-12-04 06:35:30 -08001234 SkDebugf("! -> high variance, ? -> moderate variance\n");
1235 SkDebugf(" micros \tbench\n");
mtkleinbbba1682015-10-28 11:36:30 -07001236 } else if (FLAGS_ms) {
cdaltone1b89582015-06-25 19:17:08 -07001237 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n");
mtkleinf3723212014-06-25 14:08:00 -07001238 } else {
mtkleind75c4662015-04-30 07:11:22 -07001239 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n",
qiankun.miao8247ec32014-09-09 19:24:36 -07001240 FLAGS_samples, "samples");
mtkleinf3723212014-06-25 14:08:00 -07001241 }
1242
svaisanenc47635e2016-01-28 06:05:43 -08001243 SkTArray<Config> configs;
bsalomonc2553372014-07-22 13:09:05 -07001244 create_configs(&configs);
1245
msarettc149f0e2016-01-04 11:35:43 -08001246 if (FLAGS_keepAlive) {
1247 start_keepalive();
1248 }
1249
Mike Klein03fa5d42019-03-22 11:39:09 -05001250 SetAnalyticAAFromCommonFlags();
liyuqian38911a72016-10-04 11:23:22 -07001251
Mike Klein2a57e792020-01-14 12:47:52 -06001252 if (FLAGS_forceRasterPipeline) { gSkForceRasterPipelineBlitter = true; }
Mike Kleinea4459d2020-01-16 13:05:04 -06001253 if (FLAGS_skvm) { gUseSkVMBlitter = gSkVMJITViaDylib = true; }
Yuqian Li550148b2017-01-13 10:13:13 -05001254
mtkleine070c2b2014-10-14 08:40:43 -07001255 int runs = 0;
mtklein92007582014-08-01 07:46:52 -07001256 BenchmarkStream benchStream;
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001257 log.beginObject("results");
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001258 AutoreleasePool pool;
mtklein92007582014-08-01 07:46:52 -07001259 while (Benchmark* b = benchStream.next()) {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001260 std::unique_ptr<Benchmark> bench(b);
Mike Klein88544fb2019-03-20 10:50:33 -05001261 if (CommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
mtkleinf3723212014-06-25 14:08:00 -07001262 continue;
1263 }
1264
svaisanenc47635e2016-01-28 06:05:43 -08001265 if (!configs.empty()) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001266 log.beginBench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY);
joshualitt8a6697a2015-09-30 12:11:07 -07001267 bench->delayedSetup();
jcgregoriobf5e5232014-07-17 13:14:16 -07001268 }
egdaniel3bf92062015-06-26 08:12:46 -07001269 for (int i = 0; i < configs.count(); ++i) {
1270 Target* target = is_enabled(b, configs[i]);
1271 if (!target) {
1272 continue;
1273 }
mtkleinf3723212014-06-25 14:08:00 -07001274
halcanary96fcdcc2015-08-27 07:41:13 -07001275 // During HWUI output this canvas may be nullptr.
egdaniel3bf92062015-06-26 08:12:46 -07001276 SkCanvas* canvas = target->getCanvas();
svaisanenc47635e2016-01-28 06:05:43 -08001277 const char* config = target->config.name.c_str();
egdaniel3bf92062015-06-26 08:12:46 -07001278
brianosman7a5ada82016-02-08 13:49:12 -08001279 if (FLAGS_pre_log || FLAGS_dryRun) {
benjaminwagner8d61f0d2016-01-25 13:02:40 -08001280 SkDebugf("Running %s\t%s\n"
1281 , bench->getUniqueName()
1282 , config);
brianosman7a5ada82016-02-08 13:49:12 -08001283 if (FLAGS_dryRun) {
1284 continue;
1285 }
benjaminwagner8d61f0d2016-01-25 13:02:40 -08001286 }
1287
Mike Kleinee254232019-03-28 08:32:14 -05001288 if (FLAGS_purgeBetweenBenches) {
1289 SkGraphics::PurgeAllCaches();
1290 }
1291
Brian Osman5ad87aa2017-09-08 16:05:23 -04001292 TRACE_EVENT2("skia", "Benchmark", "name", TRACE_STR_COPY(bench->getUniqueName()),
1293 "config", TRACE_STR_COPY(config));
Brian Osmanc3cdef52017-08-31 14:09:22 -04001294
egdaniel3bf92062015-06-26 08:12:46 -07001295 target->setup();
robertphillips5b693772014-11-21 06:19:36 -08001296 bench->perCanvasPreDraw(canvas);
1297
cdaltone1b89582015-06-25 19:17:08 -07001298 int maxFrameLag;
mtkleina1ebeb22015-10-01 09:43:39 -07001299 int loops = target->needsFrameTiming(&maxFrameLag)
egdaniel3bf92062015-06-26 08:12:46 -07001300 ? setup_gpu_bench(target, bench.get(), maxFrameLag)
1301 : setup_cpu_bench(overhead, target, bench.get());
cdaltone1b89582015-06-25 19:17:08 -07001302
Leon Scroggins IIIb30d1132017-10-02 09:48:15 -04001303 if (kFailedLoops == loops) {
1304 // Can't be timed. A warning note has already been printed.
1305 cleanup_run(target);
1306 continue;
1307 }
1308
Yuqian Li3528eb32017-09-21 13:23:49 -04001309 if (runs == 0 && FLAGS_ms < 1000) {
1310 // Run the first bench for 1000ms to warm up the nanobench if FLAGS_ms < 1000.
1311 // Otherwise, the first few benches' measurements will be inaccurate.
1312 auto stop = now_ms() + 1000;
1313 do {
1314 time(loops, bench.get(), target);
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001315 pool.drain();
Yuqian Li3528eb32017-09-21 13:23:49 -04001316 } while (now_ms() < stop);
1317 }
1318
mtkleinbbba1682015-10-28 11:36:30 -07001319 if (FLAGS_ms) {
1320 samples.reset();
1321 auto stop = now_ms() + FLAGS_ms;
1322 do {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001323 samples.push_back(time(loops, bench.get(), target) / loops);
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001324 pool.drain();
mtkleinbbba1682015-10-28 11:36:30 -07001325 } while (now_ms() < stop);
1326 } else {
cdaltone1b89582015-06-25 19:17:08 -07001327 samples.reset(FLAGS_samples);
1328 for (int s = 0; s < FLAGS_samples; s++) {
Ben Wagner145dbcd2016-11-03 14:40:50 -04001329 samples[s] = time(loops, bench.get(), target) / loops;
Jim Van Verth49d6bca2020-02-28 11:05:44 -05001330 pool.drain();
cdaltone1b89582015-06-25 19:17:08 -07001331 }
cdaltone1b89582015-06-25 19:17:08 -07001332 }
mtkleinf3723212014-06-25 14:08:00 -07001333
Mike Kleinfec9b902019-05-31 10:03:07 -05001334 // Scale each result to the benchmark's own units, time/unit.
1335 for (double& sample : samples) {
1336 sample *= (1.0 / bench->getUnits());
1337 }
1338
joshualitte45c81c2015-12-02 09:05:37 -08001339 SkTArray<SkString> keys;
1340 SkTArray<double> values;
1341 bool gpuStatsDump = FLAGS_gpuStatsDump && Benchmark::kGPU_Backend == configs[i].backend;
1342 if (gpuStatsDump) {
1343 // TODO cache stats
1344 bench->getGpuStats(canvas, &keys, &values);
1345 }
joshualitte45c81c2015-12-02 09:05:37 -08001346
robertphillips5b693772014-11-21 06:19:36 -08001347 bench->perCanvasPostDraw(canvas);
1348
egdaniel3bf92062015-06-26 08:12:46 -07001349 if (Benchmark::kNonRendering_Backend != target->config.backend &&
tomhudsond968a6f2015-03-26 11:28:06 -07001350 !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
bsalomon6eb03cc2014-08-07 14:28:50 -07001351 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config);
mtklein96289052014-09-10 12:05:59 -07001352 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName());
bsalomon6eb03cc2014-08-07 14:28:50 -07001353 pngFilename.append(".png");
egdaniel3bf92062015-06-26 08:12:46 -07001354 write_canvas_png(target, pngFilename);
bsalomon6eb03cc2014-08-07 14:28:50 -07001355 }
1356
Mike Klein512a2442018-09-27 10:44:56 -04001357 // Building stats.plot often shows up in profiles,
1358 // so skip building it when we're not going to print it anyway.
1359 const bool want_plot = !FLAGS_quiet;
1360
1361 Stats stats(samples, want_plot);
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001362 log.beginObject(config);
1363
1364 log.beginObject("options");
1365 log.appendString("name", bench->getName());
1366 benchStream.fillCurrentOptions(log);
1367 target->fillOptions(log);
1368 log.endObject(); // options
1369
1370 // Metrics
1371 log.appendMetric("min_ms", stats.min);
1372 log.beginArray("samples");
1373 for (double sample : samples) {
1374 log.appendDoubleDigits(sample, 16);
1375 }
1376 log.endArray(); // samples
1377 benchStream.fillCurrentMetrics(log);
joshualitte45c81c2015-12-02 09:05:37 -08001378 if (gpuStatsDump) {
1379 // dump to json, only SKPBench currently returns valid keys / values
1380 SkASSERT(keys.count() == values.count());
1381 for (int i = 0; i < keys.count(); i++) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001382 log.appendMetric(keys[i].c_str(), values[i]);
joshualitte45c81c2015-12-02 09:05:37 -08001383 }
1384 }
joshualitte45c81c2015-12-02 09:05:37 -08001385
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001386 log.endObject(); // config
1387
mtkleine070c2b2014-10-14 08:40:43 -07001388 if (runs++ % FLAGS_flushEvery == 0) {
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001389 log.flush();
mtkleine070c2b2014-10-14 08:40:43 -07001390 }
mtklein60317d0f2014-07-14 11:30:37 -07001391
bsalomon6eb03cc2014-08-07 14:28:50 -07001392 if (kAutoTuneLoops != FLAGS_loops) {
egdaniel3bf92062015-06-26 08:12:46 -07001393 if (configs.count() == 1) {
mtkleina189ccd2014-07-14 12:28:47 -07001394 config = ""; // Only print the config if we run the same bench on more than one.
1395 }
mtkleind75c4662015-04-30 07:11:22 -07001396 SkDebugf("%4d/%-4dMB\t%s\t%s\n"
1397 , sk_tools::getCurrResidentSetSizeMB()
1398 , sk_tools::getMaxResidentSetSizeMB()
mtklein53d25622014-09-18 07:39:42 -07001399 , bench->getUniqueName()
1400 , config);
mtkleinf3723212014-06-25 14:08:00 -07001401 } else if (FLAGS_quiet) {
mtklein66cfcff2015-12-04 06:35:30 -08001402 const char* mark = " ";
Hal Canarye99e8da2019-01-14 16:34:50 -05001403 const double stddev_percent =
1404 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
mtklein66cfcff2015-12-04 06:35:30 -08001405 if (stddev_percent > 5) mark = "?";
1406 if (stddev_percent > 10) mark = "!";
1407
1408 SkDebugf("%10.2f %s\t%s\t%s\n",
1409 stats.median*1e3, mark, bench->getUniqueName(), config);
Mike Reedc665e5b2017-07-04 22:56:06 -04001410 } else if (FLAGS_csv) {
Hal Canarye99e8da2019-01-14 16:34:50 -05001411 const double stddev_percent =
1412 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
Mike Reedc665e5b2017-07-04 22:56:06 -04001413 SkDebugf("%g,%g,%g,%g,%g,%s,%s\n"
1414 , stats.min
1415 , stats.median
1416 , stats.mean
1417 , stats.max
1418 , stddev_percent
1419 , config
1420 , bench->getUniqueName()
1421 );
1422 } else {
1423 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 -05001424 const double stddev_percent =
1425 sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean);
Mike Reedc665e5b2017-07-04 22:56:06 -04001426 SkDebugf(format
mtkleind75c4662015-04-30 07:11:22 -07001427 , sk_tools::getCurrResidentSetSizeMB()
1428 , sk_tools::getMaxResidentSetSizeMB()
mtkleinf3723212014-06-25 14:08:00 -07001429 , loops
mtklein55b0ffc2014-07-17 08:38:23 -07001430 , HUMANIZE(stats.min)
1431 , HUMANIZE(stats.median)
1432 , HUMANIZE(stats.mean)
1433 , HUMANIZE(stats.max)
mtkleinf3723212014-06-25 14:08:00 -07001434 , stddev_percent
mtkleinbbba1682015-10-28 11:36:30 -07001435 , FLAGS_ms ? to_string(samples.count()).c_str() : stats.plot.c_str()
mtkleinf3723212014-06-25 14:08:00 -07001436 , config
mtklein96289052014-09-10 12:05:59 -07001437 , bench->getUniqueName()
mtkleinf3723212014-06-25 14:08:00 -07001438 );
1439 }
joshualitte45c81c2015-12-02 09:05:37 -08001440
joshualitte45c81c2015-12-02 09:05:37 -08001441 if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) {
Brian Salomon0b4d8aa2017-10-11 15:34:27 -04001442 target->dumpStats();
bsalomon06cddec2014-10-24 10:40:50 -07001443 }
joshualitte45c81c2015-12-02 09:05:37 -08001444
cdalton2c56ba52015-06-26 13:32:53 -07001445 if (FLAGS_verbose) {
1446 SkDebugf("Samples: ");
1447 for (int i = 0; i < samples.count(); i++) {
1448 SkDebugf("%s ", HUMANIZE(samples[i]));
1449 }
1450 SkDebugf("%s\n", bench->getUniqueName());
1451 }
egdaniel3bf92062015-06-26 08:12:46 -07001452 cleanup_run(target);
Jim Van Verth8a9a3712019-05-31 10:49:12 -04001453 pool.drain();
mtkleinf3723212014-06-25 14:08:00 -07001454 }
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001455 if (!configs.empty()) {
1456 log.endBench();
1457 }
mtkleinf3723212014-06-25 14:08:00 -07001458 }
1459
Herb Derby5a523fe2017-01-26 16:48:28 -05001460 SkGraphics::PurgeAllCaches();
1461
Brian Osman8c0a1ca2019-01-28 14:24:29 -05001462 log.beginBench("memory_usage", 0, 0);
1463 log.beginObject("meta"); // config
1464 log.appendS32("max_rss_mb", sk_tools::getMaxResidentSetSizeMB());
1465 log.endObject(); // config
1466 log.endBench();
1467
1468 log.endObject(); // results
1469 log.endObject(); // root
1470 log.flush();
mtkleine1091452014-12-04 10:47:02 -08001471
mtkleinf3723212014-06-25 14:08:00 -07001472 return 0;
1473}