mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 8 | #include <ctype.h> |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "bench/nanobench.h" |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "bench/AndroidCodecBench.h" |
| 13 | #include "bench/Benchmark.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #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 Canary | 5dfefa2 | 2019-10-24 13:52:17 -0400 | [diff] [blame] | 21 | #include "bench/SkGlyphCacheBench.h" |
Brian Osman | 68870aa | 2020-07-08 14:12:43 -0400 | [diff] [blame] | 22 | #include "bench/SkSLBench.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "include/codec/SkAndroidCodec.h" |
| 24 | #include "include/codec/SkCodec.h" |
| 25 | #include "include/core/SkCanvas.h" |
| 26 | #include "include/core/SkData.h" |
| 27 | #include "include/core/SkGraphics.h" |
| 28 | #include "include/core/SkPictureRecorder.h" |
| 29 | #include "include/core/SkString.h" |
| 30 | #include "include/core/SkSurface.h" |
Ben Wagner | acf98df | 2019-07-12 12:51:44 -0400 | [diff] [blame] | 31 | #include "include/core/SkTime.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 32 | #include "src/core/SkAutoMalloc.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 33 | #include "src/core/SkColorSpacePriv.h" |
Ben Wagner | ab6eefe | 2019-05-20 11:02:49 -0400 | [diff] [blame] | 34 | #include "src/core/SkLeanWindows.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 35 | #include "src/core/SkOSFile.h" |
| 36 | #include "src/core/SkTaskGroup.h" |
| 37 | #include "src/core/SkTraceEvent.h" |
| 38 | #include "src/utils/SkJSONWriter.h" |
| 39 | #include "src/utils/SkOSPath.h" |
Jim Van Verth | 8a9a371 | 2019-05-31 10:49:12 -0400 | [diff] [blame] | 40 | #include "tools/AutoreleasePool.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 41 | #include "tools/CrashHandler.h" |
| 42 | #include "tools/ProcStats.h" |
| 43 | #include "tools/Stats.h" |
| 44 | #include "tools/flags/CommonFlags.h" |
| 45 | #include "tools/flags/CommonFlagsConfig.h" |
| 46 | #include "tools/ios_utils.h" |
| 47 | #include "tools/trace/EventTracingPriv.h" |
| 48 | #include "tools/trace/SkDebugfTracer.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 49 | |
Hal Canary | 0f66681 | 2018-03-22 15:21:12 -0400 | [diff] [blame] | 50 | #ifdef SK_XML |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 51 | #include "experimental/svg/model/SkSVGDOM.h" |
Hal Canary | 0f66681 | 2018-03-22 15:21:12 -0400 | [diff] [blame] | 52 | #endif // SK_XML |
| 53 | |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 54 | #ifdef SK_ENABLE_ANDROID_UTILS |
| 55 | #include "bench/BitmapRegionDecoderBench.h" |
| 56 | #include "client_utils/android/BitmapRegionDecoder.h" |
| 57 | #endif |
| 58 | |
Adlai Holler | 684838f | 2020-05-12 10:41:04 -0400 | [diff] [blame] | 59 | #include <cinttypes> |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 60 | #include <stdlib.h> |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 61 | #include <memory> |
Mike Klein | 03141d2 | 2017-10-30 11:57:15 -0400 | [diff] [blame] | 62 | #include <thread> |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 63 | |
Mike Reed | c928fe2 | 2017-06-05 10:20:31 -0400 | [diff] [blame] | 64 | extern bool gSkForceRasterPipelineBlitter; |
Mike Klein | 2a57e79 | 2020-01-14 12:47:52 -0600 | [diff] [blame] | 65 | extern bool gUseSkVMBlitter; |
Mike Klein | 813e8cc | 2020-08-05 09:33:38 -0500 | [diff] [blame^] | 66 | extern bool gSkVMAllowJIT; |
Mike Klein | ea4459d | 2020-01-16 13:05:04 -0600 | [diff] [blame] | 67 | extern bool gSkVMJITViaDylib; |
Mike Reed | c928fe2 | 2017-06-05 10:20:31 -0400 | [diff] [blame] | 68 | |
Mike Klein | 8f11d4d | 2018-01-24 12:42:55 -0500 | [diff] [blame] | 69 | #ifndef SK_BUILD_FOR_WIN |
scroggo | 38ce0a7 | 2016-01-07 07:28:47 -0800 | [diff] [blame] | 70 | #include <unistd.h> |
Brian Salomon | 032aaae | 2018-03-23 16:10:36 -0400 | [diff] [blame] | 71 | |
scroggo | 38ce0a7 | 2016-01-07 07:28:47 -0800 | [diff] [blame] | 72 | #endif |
| 73 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 74 | #include "include/gpu/GrDirectContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 75 | #include "src/gpu/GrCaps.h" |
| 76 | #include "src/gpu/GrContextPriv.h" |
| 77 | #include "src/gpu/SkGr.h" |
| 78 | #include "src/gpu/gl/GrGLDefines.h" |
| 79 | #include "src/gpu/gl/GrGLGpu.h" |
| 80 | #include "src/gpu/gl/GrGLUtil.h" |
| 81 | #include "tools/gpu/GrContextFactory.h" |
Brian Salomon | 032aaae | 2018-03-23 16:10:36 -0400 | [diff] [blame] | 82 | |
Brian Osman | c7ad40f | 2018-05-31 14:27:17 -0400 | [diff] [blame] | 83 | using sk_gpu_test::ContextInfo; |
| 84 | using sk_gpu_test::GrContextFactory; |
| 85 | using sk_gpu_test::TestContext; |
Brian Salomon | 032aaae | 2018-03-23 16:10:36 -0400 | [diff] [blame] | 86 | |
Brian Osman | c7ad40f | 2018-05-31 14:27:17 -0400 | [diff] [blame] | 87 | GrContextOptions grContextOpts; |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 88 | |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 89 | static const int kAutoTuneLoops = 0; |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 90 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 91 | static SkString loops_help_txt() { |
| 92 | SkString help; |
| 93 | help.printf("Number of times to run each bench. Set this to %d to auto-" |
| 94 | "tune for each bench. Timings are only reported when auto-tuning.", |
| 95 | kAutoTuneLoops); |
| 96 | return help; |
| 97 | } |
| 98 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 99 | static SkString to_string(int n) { |
| 100 | SkString str; |
| 101 | str.appendS32(n); |
| 102 | return str; |
| 103 | } |
| 104 | |
Mike Klein | ac8f443 | 2019-07-01 10:15:32 -0500 | [diff] [blame] | 105 | static DEFINE_int(loops, kAutoTuneLoops, loops_help_txt().c_str()); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 106 | |
Mike Klein | 5b3f343 | 2019-03-21 11:42:21 -0500 | [diff] [blame] | 107 | static DEFINE_int(samples, 10, "Number of samples to measure for each bench."); |
| 108 | static DEFINE_int(ms, 0, "If >0, run each bench for this many ms instead of obeying --samples."); |
| 109 | static DEFINE_int(overheadLoops, 100000, "Loops to estimate timer overhead."); |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 110 | static DEFINE_double(overheadGoal, 0.0001, |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 111 | "Loop until timer overhead is at most this fraction of our measurments."); |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 112 | static DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
Mike Klein | 5b3f343 | 2019-03-21 11:42:21 -0500 | [diff] [blame] | 113 | static DEFINE_int(gpuFrameLag, 5, |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 114 | "If unknown, estimated maximum number of frames GPU allows to lag."); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 115 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 116 | static DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
Mike Klein | 5b3f343 | 2019-03-21 11:42:21 -0500 | [diff] [blame] | 117 | static DEFINE_int(maxCalibrationAttempts, 3, |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 118 | "Try up to this many times to guess loops for a bench, or skip the bench."); |
Mike Klein | 5b3f343 | 2019-03-21 11:42:21 -0500 | [diff] [blame] | 119 | static DEFINE_int(maxLoops, 1000000, "Never run a bench more times than this."); |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 120 | static DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); |
| 121 | static DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); |
| 122 | static DEFINE_string(zoom, "1.0,0", |
| 123 | "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom " |
| 124 | "function that ping-pongs between 1.0 and zoomMax."); |
| 125 | static DEFINE_bool(bbh, true, "Build a BBH for SKPs?"); |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 126 | static DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?"); |
| 127 | static DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?"); |
Mike Klein | 5b3f343 | 2019-03-21 11:42:21 -0500 | [diff] [blame] | 128 | static DEFINE_int(flushEvery, 10, "Flush --outResultsFile every Nth run."); |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 129 | static DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?"); |
| 130 | static DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json"); |
| 131 | static DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out"); |
| 132 | static DEFINE_bool(csv, false, "Print status in CSV format"); |
| 133 | static DEFINE_string(sourceType, "", |
mtklein | 65dfd2f | 2016-02-03 10:40:54 -0800 | [diff] [blame] | 134 | "Apply usual --match rules to source type: bench, gm, skp, image, etc."); |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 135 | static DEFINE_string(benchType, "", |
| 136 | "Apply usual --match rules to bench type: micro, recording, " |
| 137 | "piping, playback, skcodec, etc."); |
mtklein | 65dfd2f | 2016-02-03 10:40:54 -0800 | [diff] [blame] | 138 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 139 | static DEFINE_bool(forceRasterPipeline, false, "sets gSkForceRasterPipelineBlitter"); |
Mike Klein | 813e8cc | 2020-08-05 09:33:38 -0500 | [diff] [blame^] | 140 | static DEFINE_bool(skvm, false, "sets gUseSkVMBlitter"); |
| 141 | static DEFINE_bool(jit, true, "sets gSkVMAllowJIT and gSkVMJITViaDylib"); |
Mike Reed | c928fe2 | 2017-06-05 10:20:31 -0400 | [diff] [blame] | 142 | |
Mike Klein | 19fb397 | 2019-03-21 13:08:08 -0500 | [diff] [blame] | 143 | static DEFINE_bool2(pre_log, p, false, |
| 144 | "Log before running each test. May be incomprehensible when threading"); |
| 145 | |
Leon Scroggins III | 1ff0706 | 2020-07-27 14:52:19 -0400 | [diff] [blame] | 146 | static DEFINE_bool(cpu, true, "Run CPU-bound work?"); |
| 147 | static DEFINE_bool(gpu, true, "Run GPU-bound work?"); |
Mike Klein | 629f5fc | 2019-03-22 14:55:19 -0500 | [diff] [blame] | 148 | static DEFINE_bool(dryRun, false, |
| 149 | "just print the tests that would be run, without actually running them."); |
| 150 | static DEFINE_string(images, "", |
| 151 | "List of images and/or directories to decode. A directory with no images" |
| 152 | " is treated as a fatal error."); |
| 153 | static DEFINE_bool(simpleCodec, false, |
| 154 | "Runs of a subset of the codec tests, always N32, Premul or Opaque"); |
| 155 | |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 156 | static DEFINE_string2(match, m, nullptr, |
| 157 | "[~][^]substring[$] [...] of name to run.\n" |
| 158 | "Multiple matches may be separated by spaces.\n" |
| 159 | "~ causes a matching name to always be skipped\n" |
| 160 | "^ requires the start of the name to match\n" |
| 161 | "$ requires the end of the name to match\n" |
| 162 | "^ and $ requires an exact match\n" |
| 163 | "If a name does not match any list entry,\n" |
| 164 | "it is skipped unless some list entry starts with ~"); |
| 165 | |
| 166 | static DEFINE_bool2(quiet, q, false, "if true, don't print status updates."); |
| 167 | static DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver."); |
| 168 | |
| 169 | |
| 170 | static DEFINE_string(skps, "skps", "Directory to read skps from."); |
| 171 | static DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file."); |
Hal Canary | 5dfefa2 | 2019-10-24 13:52:17 -0400 | [diff] [blame] | 172 | static DEFINE_string(texttraces, "", "Directory to read TextBlobTrace files from."); |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 173 | |
| 174 | static DEFINE_int_2(threads, j, -1, |
| 175 | "Run threadsafe tests on a threadpool with this many extra threads, " |
| 176 | "defaulting to one extra thread per core."); |
| 177 | |
| 178 | static DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs."); |
| 179 | |
| 180 | static DEFINE_string(key, "", |
| 181 | "Space-separated key/value pairs to add to JSON identifying this builder."); |
| 182 | static DEFINE_string(properties, "", |
| 183 | "Space-separated key/value pairs to add to JSON identifying this run."); |
| 184 | |
Mike Klein | ee25423 | 2019-03-28 08:32:14 -0500 | [diff] [blame] | 185 | static DEFINE_bool(purgeBetweenBenches, false, |
| 186 | "Call SkGraphics::PurgeAllCaches() between each benchmark?"); |
| 187 | |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 188 | static double now_ms() { return SkTime::GetNSecs() * 1e-6; } |
| 189 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 190 | static SkString humanize(double ms) { |
Adlai Holler | 684838f | 2020-05-12 10:41:04 -0400 | [diff] [blame] | 191 | if (FLAGS_verbose) return SkStringPrintf("%" PRIu64, (uint64_t)(ms*1e6)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 192 | return HumanizeMs(ms); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 193 | } |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 194 | #define HUMANIZE(ms) humanize(ms).c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 195 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 196 | bool Target::init(SkImageInfo info, Benchmark* bench) { |
| 197 | if (Benchmark::kRaster_Backend == config.backend) { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 198 | this->surface = SkSurface::MakeRaster(info); |
| 199 | if (!this->surface) { |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 200 | return false; |
| 201 | } |
| 202 | } |
| 203 | return true; |
| 204 | } |
| 205 | bool Target::capturePixels(SkBitmap* bmp) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 206 | SkCanvas* canvas = this->getCanvas(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 207 | if (!canvas) { |
| 208 | return false; |
| 209 | } |
Mike Reed | 12e946b | 2017-04-17 10:53:29 -0400 | [diff] [blame] | 210 | bmp->allocPixels(canvas->imageInfo()); |
| 211 | if (!canvas->readPixels(*bmp, 0, 0)) { |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 212 | SkDebugf("Can't read canvas pixels.\n"); |
| 213 | return false; |
| 214 | } |
| 215 | return true; |
| 216 | } |
| 217 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 218 | struct GPUTarget : public Target { |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 219 | explicit GPUTarget(const Config& c) : Target(c) {} |
| 220 | ContextInfo contextInfo; |
| 221 | std::unique_ptr<GrContextFactory> factory; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 222 | |
Greg Daniel | 5ed3c11 | 2020-06-18 15:59:17 -0400 | [diff] [blame] | 223 | ~GPUTarget() override { |
| 224 | // For Vulkan we need to release all our refs to the GrContext before destroy the vulkan |
| 225 | // context which happens at the end of this destructor. Thus we need to release the surface |
| 226 | // here which holds a ref to the GrContext. |
| 227 | surface.reset(); |
| 228 | } |
| 229 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 230 | void setup() override { |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 231 | this->contextInfo.testContext()->makeCurrent(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 232 | // Make sure we're done with whatever came before. |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 233 | this->contextInfo.testContext()->finish(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 234 | } |
| 235 | void endTiming() override { |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 236 | if (this->contextInfo.testContext()) { |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 237 | this->contextInfo.testContext()->flushAndWaitOnSync(contextInfo.directContext()); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 238 | } |
| 239 | } |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 240 | void fence() override { this->contextInfo.testContext()->finish(); } |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 241 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 242 | bool needsFrameTiming(int* maxFrameLag) const override { |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 243 | if (!this->contextInfo.testContext()->getMaxGpuFrameLag(maxFrameLag)) { |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 244 | // Frame lag is unknown. |
| 245 | *maxFrameLag = FLAGS_gpuFrameLag; |
| 246 | } |
| 247 | return true; |
| 248 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 249 | bool init(SkImageInfo info, Benchmark* bench) override { |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 250 | GrContextOptions options = grContextOpts; |
| 251 | bench->modifyGrContextOptions(&options); |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 252 | this->factory = std::make_unique<GrContextFactory>(options); |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 253 | uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : |
| 254 | 0; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 255 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 256 | this->surface = SkSurface::MakeRenderTarget( |
| 257 | this->factory->get(this->config.ctxType, this->config.ctxOverrides), |
| 258 | SkBudgeted::kNo, info, this->config.samples, &props); |
| 259 | this->contextInfo = |
| 260 | this->factory->getContextInfo(this->config.ctxType, this->config.ctxOverrides); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 261 | if (!this->surface.get()) { |
| 262 | return false; |
| 263 | } |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 264 | if (!this->contextInfo.testContext()->fenceSyncSupport()) { |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 265 | SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. " |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 266 | "Timings might not be accurate.\n", this->config.name.c_str()); |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 267 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 268 | return true; |
| 269 | } |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 270 | void fillOptions(NanoJSONResultsWriter& log) override { |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 271 | #ifdef SK_GL |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 272 | const GrGLubyte* version; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 273 | if (this->contextInfo.backend() == GrBackendApi::kOpenGL) { |
Brian Salomon | 032aaae | 2018-03-23 16:10:36 -0400 | [diff] [blame] | 274 | const GrGLInterface* gl = |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 275 | static_cast<GrGLGpu*>(this->contextInfo.directContext()->priv().getGpu()) |
Brian Salomon | 032aaae | 2018-03-23 16:10:36 -0400 | [diff] [blame] | 276 | ->glInterface(); |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 277 | GR_GL_CALL_RET(gl, version, GetString(GR_GL_VERSION)); |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 278 | log.appendString("GL_VERSION", (const char*)(version)); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 279 | |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 280 | GR_GL_CALL_RET(gl, version, GetString(GR_GL_RENDERER)); |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 281 | log.appendString("GL_RENDERER", (const char*) version); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 282 | |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 283 | GR_GL_CALL_RET(gl, version, GetString(GR_GL_VENDOR)); |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 284 | log.appendString("GL_VENDOR", (const char*) version); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 285 | |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 286 | GR_GL_CALL_RET(gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 287 | log.appendString("GL_SHADING_LANGUAGE_VERSION", (const char*) version); |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 288 | } |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 289 | #endif |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 290 | } |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 291 | |
| 292 | void dumpStats() override { |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 293 | auto context = this->contextInfo.directContext(); |
| 294 | |
| 295 | context->priv().printCacheStats(); |
| 296 | context->priv().printGpuStats(); |
| 297 | context->priv().printContextStats(); |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 298 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 299 | }; |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 300 | |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 301 | static double time(int loops, Benchmark* bench, Target* target) { |
| 302 | SkCanvas* canvas = target->getCanvas(); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 303 | if (canvas) { |
| 304 | canvas->clear(SK_ColorWHITE); |
| 305 | } |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 306 | bench->preDraw(canvas); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 307 | double start = now_ms(); |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 308 | canvas = target->beginTiming(canvas); |
| 309 | bench->draw(loops, canvas); |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 310 | target->endTiming(); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 311 | double elapsed = now_ms() - start; |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 312 | bench->postDraw(canvas); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 313 | return elapsed; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 314 | } |
| 315 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 316 | static double estimate_timer_overhead() { |
| 317 | double overhead = 0; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 318 | for (int i = 0; i < FLAGS_overheadLoops; i++) { |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 319 | double start = now_ms(); |
| 320 | overhead += now_ms() - start; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 321 | } |
| 322 | return overhead / FLAGS_overheadLoops; |
| 323 | } |
| 324 | |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 325 | static int detect_forever_loops(int loops) { |
| 326 | // look for a magic run-forever value |
| 327 | if (loops < 0) { |
| 328 | loops = SK_MaxS32; |
| 329 | } |
| 330 | return loops; |
| 331 | } |
| 332 | |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 333 | static int clamp_loops(int loops) { |
| 334 | if (loops < 1) { |
mtklein | 527930f | 2014-11-06 08:04:34 -0800 | [diff] [blame] | 335 | SkDebugf("ERROR: clamping loops from %d to 1. " |
| 336 | "There's probably something wrong with the bench.\n", loops); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 337 | return 1; |
| 338 | } |
| 339 | if (loops > FLAGS_maxLoops) { |
| 340 | SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops); |
| 341 | return FLAGS_maxLoops; |
| 342 | } |
| 343 | return loops; |
| 344 | } |
| 345 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 346 | static bool write_canvas_png(Target* target, const SkString& filename) { |
| 347 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 348 | if (filename.isEmpty()) { |
| 349 | return false; |
| 350 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 351 | if (target->getCanvas() && |
| 352 | kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 353 | return false; |
| 354 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 355 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 356 | SkBitmap bmp; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 357 | |
| 358 | if (!target->capturePixels(&bmp)) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 359 | return false; |
| 360 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 361 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 362 | SkString dir = SkOSPath::Dirname(filename.c_str()); |
| 363 | if (!sk_mkdir(dir.c_str())) { |
| 364 | SkDebugf("Can't make dir %s.\n", dir.c_str()); |
| 365 | return false; |
| 366 | } |
| 367 | SkFILEWStream stream(filename.c_str()); |
| 368 | if (!stream.isValid()) { |
| 369 | SkDebugf("Can't write %s.\n", filename.c_str()); |
| 370 | return false; |
| 371 | } |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 372 | if (!SkEncodeImage(&stream, bmp, SkEncodedImageFormat::kPNG, 100)) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 373 | SkDebugf("Can't encode a PNG.\n"); |
| 374 | return false; |
| 375 | } |
| 376 | return true; |
| 377 | } |
| 378 | |
| 379 | static int kFailedLoops = -2; |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 380 | static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 381 | // First figure out approximately how many loops of bench it takes to make overhead negligible. |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 382 | double bench_plus_overhead = 0.0; |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 383 | int round = 0; |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 384 | int loops = bench->calculateLoops(FLAGS_loops); |
| 385 | if (kAutoTuneLoops == loops) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 386 | while (bench_plus_overhead < overhead) { |
| 387 | if (round++ == FLAGS_maxCalibrationAttempts) { |
| 388 | SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n", |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 389 | bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead)); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 390 | return kFailedLoops; |
| 391 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 392 | bench_plus_overhead = time(1, bench, target); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 393 | } |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 394 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 395 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 396 | // Later we'll just start and stop the timer once but loop N times. |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 397 | // We'll pick N to make timer overhead negligible: |
| 398 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 399 | // overhead |
| 400 | // ------------------------- < FLAGS_overheadGoal |
| 401 | // overhead + N * Bench Time |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 402 | // |
Hal Canary | 55325b7 | 2017-01-03 10:36:17 -0500 | [diff] [blame] | 403 | // where bench_plus_overhead ~=~ overhead + Bench Time. |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 404 | // |
| 405 | // Doing some math, we get: |
| 406 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 407 | // (overhead / FLAGS_overheadGoal) - overhead |
| 408 | // ------------------------------------------ < N |
| 409 | // bench_plus_overhead - overhead) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 410 | // |
| 411 | // Luckily, this also works well in practice. :) |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 412 | if (kAutoTuneLoops == loops) { |
| 413 | const double numer = overhead / FLAGS_overheadGoal - overhead; |
| 414 | const double denom = bench_plus_overhead - overhead; |
| 415 | loops = (int)ceil(numer / denom); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 416 | loops = clamp_loops(loops); |
| 417 | } else { |
| 418 | loops = detect_forever_loops(loops); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 419 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 420 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 421 | return loops; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 422 | } |
| 423 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 424 | static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 425 | // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs. |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 426 | int loops = bench->calculateLoops(FLAGS_loops); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 427 | if (kAutoTuneLoops == loops) { |
| 428 | loops = 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 429 | double elapsed = 0; |
| 430 | do { |
mtklein | 527930f | 2014-11-06 08:04:34 -0800 | [diff] [blame] | 431 | if (1<<30 == loops) { |
| 432 | // We're about to wrap. Something's wrong with the bench. |
| 433 | loops = 0; |
| 434 | break; |
| 435 | } |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 436 | loops *= 2; |
| 437 | // If the GPU lets frames lag at all, we need to make sure we're timing |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 438 | // _this_ round, not still timing last round. |
| 439 | for (int i = 0; i < maxGpuFrameLag; i++) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 440 | elapsed = time(loops, bench, target); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 441 | } |
| 442 | } while (elapsed < FLAGS_gpuMs); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 443 | |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 444 | // We've overshot at least a little. Scale back linearly. |
| 445 | loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 446 | loops = clamp_loops(loops); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 447 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 448 | // Make sure we're not still timing our calibration. |
| 449 | target->fence(); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 450 | } else { |
| 451 | loops = detect_forever_loops(loops); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 452 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 453 | // Pretty much the same deal as the calibration: do some warmup to make |
| 454 | // sure we're timing steady-state pipelined frames. |
Brian Osman | 0177698 | 2017-10-10 15:41:03 -0400 | [diff] [blame] | 455 | for (int i = 0; i < maxGpuFrameLag; i++) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 456 | time(loops, bench, target); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 457 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 458 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 459 | return loops; |
| 460 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 461 | |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 462 | #define kBogusContextType GrContextFactory::kGL_ContextType |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 463 | #define kBogusContextOverrides GrContextFactory::ContextOverrides::kNone |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 464 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 465 | static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) { |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 466 | if (const auto* gpuConfig = config->asConfigGpu()) { |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 467 | if (!FLAGS_gpu) { |
| 468 | SkDebugf("Skipping config '%s' as requested.\n", config->getTag().c_str()); |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 469 | return; |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 470 | } |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 471 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 472 | const auto ctxType = gpuConfig->getContextType(); |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 473 | const auto ctxOverrides = gpuConfig->getContextOverrides(); |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 474 | const auto sampleCount = gpuConfig->getSamples(); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 475 | const auto colorType = gpuConfig->getColorType(); |
| 476 | auto colorSpace = gpuConfig->getColorSpace(); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 477 | if (gpuConfig->getSurfType() != SkCommandLineConfigGpu::SurfType::kDefault) { |
| 478 | SkDebugf("This tool only supports the default surface type."); |
| 479 | return; |
| 480 | } |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 481 | |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 482 | GrContextFactory factory(grContextOpts); |
Robert Phillips | f028810 | 2020-07-06 13:45:34 -0400 | [diff] [blame] | 483 | if (const auto ctx = factory.get(ctxType, ctxOverrides)) { |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 484 | GrBackendFormat format = ctx->defaultBackendFormat(colorType, GrRenderable::kYes); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 485 | int supportedSampleCount = |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 486 | ctx->priv().caps()->getRenderTargetSampleCount(sampleCount, format); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 487 | if (sampleCount != supportedSampleCount) { |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 488 | SkDebugf("Configuration '%s' sample count %d is not a supported sample count.\n", |
| 489 | config->getTag().c_str(), sampleCount); |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 490 | return; |
| 491 | } |
| 492 | } else { |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 493 | SkDebugf("No context was available matching config '%s'.\n", |
| 494 | config->getTag().c_str()); |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 495 | return; |
| 496 | } |
| 497 | |
| 498 | Config target = { |
kkinnunen | d4e1c35 | 2016-03-01 23:41:26 -0800 | [diff] [blame] | 499 | gpuConfig->getTag(), |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 500 | Benchmark::kGPU_Backend, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 501 | colorType, |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 502 | kPremul_SkAlphaType, |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 503 | sk_ref_sp(colorSpace), |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 504 | sampleCount, |
| 505 | ctxType, |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 506 | ctxOverrides, |
kkinnunen | d4e1c35 | 2016-03-01 23:41:26 -0800 | [diff] [blame] | 507 | gpuConfig->getUseDIText() |
| 508 | }; |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 509 | |
| 510 | configs->push_back(target); |
| 511 | return; |
| 512 | } |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 513 | |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 514 | #define CPU_CONFIG(name, backend, color, alpha, colorSpace) \ |
| 515 | if (config->getTag().equals(#name)) { \ |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 516 | if (!FLAGS_cpu) { \ |
| 517 | SkDebugf("Skipping config '%s' as requested.\n", \ |
| 518 | config->getTag().c_str()); \ |
| 519 | return; \ |
| 520 | } \ |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 521 | Config config = { \ |
| 522 | SkString(#name), Benchmark::backend, color, alpha, colorSpace, \ |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 523 | 0, kBogusContextType, kBogusContextOverrides, false \ |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 524 | }; \ |
| 525 | configs->push_back(config); \ |
| 526 | return; \ |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 527 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 528 | |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 529 | CPU_CONFIG(nonrendering, kNonRendering_Backend, |
| 530 | kUnknown_SkColorType, kUnpremul_SkAlphaType, nullptr) |
mtklein | bb6c41b | 2016-03-08 11:31:11 -0800 | [diff] [blame] | 531 | |
Mike Klein | 0e4041f | 2018-06-19 16:00:40 -0400 | [diff] [blame] | 532 | CPU_CONFIG(a8, kRaster_Backend, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr) |
| 533 | CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType, nullptr) |
| 534 | CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType, nullptr) |
| 535 | |
| 536 | // 'narrow' has a gamut narrower than sRGB, and different transfer function. |
Brian Osman | 82ebe04 | 2019-01-04 17:03:00 -0500 | [diff] [blame] | 537 | auto narrow = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50), |
Mike Klein | 0e4041f | 2018-06-19 16:00:40 -0400 | [diff] [blame] | 538 | srgb = SkColorSpace::MakeSRGB(), |
| 539 | srgbLinear = SkColorSpace::MakeSRGBLinear(); |
| 540 | |
| 541 | CPU_CONFIG( f16, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgbLinear) |
| 542 | CPU_CONFIG( srgb, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, srgb ) |
| 543 | CPU_CONFIG( esrgb, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgb ) |
| 544 | CPU_CONFIG( narrow, kRaster_Backend, kRGBA_8888_SkColorType, kPremul_SkAlphaType, narrow ) |
| 545 | CPU_CONFIG(enarrow, kRaster_Backend, kRGBA_F16_SkColorType, kPremul_SkAlphaType, narrow ) |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 546 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 547 | #undef CPU_CONFIG |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 548 | |
| 549 | SkDebugf("Unknown config '%s'.\n", config->getTag().c_str()); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 550 | } |
| 551 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 552 | // Append all configs that are enabled and supported. |
| 553 | void create_configs(SkTArray<Config>* configs) { |
| 554 | SkCommandLineConfigArray array; |
| 555 | ParseConfigs(FLAGS_config, &array); |
| 556 | for (int i = 0; i < array.count(); ++i) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 557 | create_config(array[i].get(), configs); |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 558 | } |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 559 | |
| 560 | // If no just default configs were requested, then we're okay. |
| 561 | if (array.count() == 0 || FLAGS_config.count() == 0 || |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 562 | // Otherwise, make sure that all specified configs have been created. |
| 563 | array.count() == configs->count()) { |
| 564 | return; |
| 565 | } |
Ben Wagner | 32fa510 | 2017-08-10 21:25:55 -0400 | [diff] [blame] | 566 | exit(1); |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 567 | } |
| 568 | |
brianosman | 9f1f6e2 | 2016-09-15 08:33:02 -0700 | [diff] [blame] | 569 | // disable warning : switch statement contains default but no 'case' labels |
| 570 | #if defined _WIN32 |
| 571 | #pragma warning ( push ) |
| 572 | #pragma warning ( disable : 4065 ) |
| 573 | #endif |
| 574 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 575 | // If bench is enabled for config, returns a Target* for it, otherwise nullptr. |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 576 | static Target* is_enabled(Benchmark* bench, const Config& config) { |
| 577 | if (!bench->isSuitableFor(config.backend)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 578 | return nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 579 | } |
| 580 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 581 | SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 582 | config.color, config.alpha, config.colorSpace); |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 583 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 584 | Target* target = nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 585 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 586 | switch (config.backend) { |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 587 | case Benchmark::kGPU_Backend: |
| 588 | target = new GPUTarget(config); |
| 589 | break; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 590 | default: |
| 591 | target = new Target(config); |
| 592 | break; |
| 593 | } |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 594 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 595 | if (!target->init(info, bench)) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 596 | delete target; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 597 | return nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 598 | } |
| 599 | return target; |
| 600 | } |
| 601 | |
brianosman | 9f1f6e2 | 2016-09-15 08:33:02 -0700 | [diff] [blame] | 602 | #if defined _WIN32 |
| 603 | #pragma warning ( pop ) |
| 604 | #endif |
| 605 | |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 606 | #ifdef SK_ENABLE_ANDROID_UTILS |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 607 | static bool valid_brd_bench(sk_sp<SkData> encoded, SkColorType colorType, uint32_t sampleSize, |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 608 | uint32_t minOutputSize, int* width, int* height) { |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 609 | auto brd = android::skia::BitmapRegionDecoder::Make(encoded); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 610 | if (nullptr == brd.get()) { |
| 611 | // This is indicates that subset decoding is not supported for a particular image format. |
| 612 | return false; |
| 613 | } |
| 614 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 615 | if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize > |
| 616 | (uint32_t) brd->height()) { |
| 617 | // This indicates that the image is not large enough to decode a |
| 618 | // minOutputSize x minOutputSize subset at the given sampleSize. |
| 619 | return false; |
| 620 | } |
| 621 | |
| 622 | // Set the image width and height. The calling code will use this to choose subsets to decode. |
| 623 | *width = brd->width(); |
| 624 | *height = brd->height(); |
| 625 | return true; |
| 626 | } |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 627 | #endif |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 628 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 629 | static void cleanup_run(Target* target) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 630 | delete target; |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 633 | static void collect_files(const CommandLineFlags::StringArray& paths, |
| 634 | const char* ext, |
| 635 | SkTArray<SkString>* list) { |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 636 | for (int i = 0; i < paths.count(); ++i) { |
| 637 | if (SkStrEndsWith(paths[i], ext)) { |
| 638 | list->push_back(SkString(paths[i])); |
| 639 | } else { |
| 640 | SkOSFile::Iter it(paths[i], ext); |
| 641 | SkString path; |
| 642 | while (it.next(&path)) { |
| 643 | list->push_back(SkOSPath::Join(paths[i], path.c_str())); |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 649 | class BenchmarkStream { |
| 650 | public: |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 651 | BenchmarkStream() : fBenches(BenchRegistry::Head()) |
Hal Canary | 2362ae7 | 2019-10-24 13:40:40 -0400 | [diff] [blame] | 652 | , fGMs(skiagm::GMRegistry::Head()) { |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 653 | collect_files(FLAGS_skps, ".skp", &fSKPs); |
| 654 | collect_files(FLAGS_svgs, ".svg", &fSVGs); |
Hal Canary | 5dfefa2 | 2019-10-24 13:52:17 -0400 | [diff] [blame] | 655 | collect_files(FLAGS_texttraces, ".trace", &fTextBlobTraces); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 656 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 657 | if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
| 658 | &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) { |
| 659 | SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]); |
| 660 | exit(1); |
| 661 | } |
| 662 | |
| 663 | for (int i = 0; i < FLAGS_scales.count(); i++) { |
| 664 | if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { |
| 665 | SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]); |
| 666 | exit(1); |
| 667 | } |
| 668 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 669 | |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 670 | if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) { |
| 671 | SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]); |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 672 | exit(1); |
| 673 | } |
| 674 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 675 | if (FLAGS_mpd) { |
| 676 | fUseMPDs.push_back() = true; |
| 677 | } |
mtklein | c751ecb | 2015-06-15 08:56:38 -0700 | [diff] [blame] | 678 | fUseMPDs.push_back() = false; |
mtklein | 95553d9 | 2015-03-12 08:24:21 -0700 | [diff] [blame] | 679 | |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 680 | // Prepare the images for decoding |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 681 | if (!CollectImages(FLAGS_images, &fImages)) { |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 682 | exit(1); |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 683 | } |
mtklein | 95553d9 | 2015-03-12 08:24:21 -0700 | [diff] [blame] | 684 | |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 685 | // Choose the candidate color types for image decoding |
msarett | 67cb666 | 2016-06-21 08:49:26 -0700 | [diff] [blame] | 686 | fColorTypes.push_back(kN32_SkColorType); |
| 687 | if (!FLAGS_simpleCodec) { |
| 688 | fColorTypes.push_back(kRGB_565_SkColorType); |
| 689 | fColorTypes.push_back(kAlpha_8_SkColorType); |
msarett | 67cb666 | 2016-06-21 08:49:26 -0700 | [diff] [blame] | 690 | fColorTypes.push_back(kGray_8_SkColorType); |
| 691 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 692 | } |
| 693 | |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 694 | static sk_sp<SkPicture> ReadPicture(const char* path) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 695 | // Not strictly necessary, as it will be checked again later, |
| 696 | // but helps to avoid a lot of pointless work if we're going to skip it. |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 697 | if (CommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 698 | return nullptr; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 699 | } |
| 700 | |
bungeman | f93d711 | 2016-09-16 06:24:20 -0700 | [diff] [blame] | 701 | std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path); |
| 702 | if (!stream) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 703 | SkDebugf("Could not read %s.\n", path); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 704 | return nullptr; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 705 | } |
| 706 | |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 707 | return SkPicture::MakeFromStream(stream.get()); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 708 | } |
| 709 | |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 710 | static sk_sp<SkPicture> ReadSVGPicture(const char* path) { |
Brian Osman | 133823d | 2018-09-19 14:14:15 -0400 | [diff] [blame] | 711 | sk_sp<SkData> data(SkData::MakeFromFileName(path)); |
| 712 | if (!data) { |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 713 | SkDebugf("Could not read %s.\n", path); |
| 714 | return nullptr; |
| 715 | } |
| 716 | |
Hal Canary | 0f66681 | 2018-03-22 15:21:12 -0400 | [diff] [blame] | 717 | #ifdef SK_XML |
Brian Osman | 133823d | 2018-09-19 14:14:15 -0400 | [diff] [blame] | 718 | SkMemoryStream stream(std::move(data)); |
fmalita | e1baa7c | 2016-09-14 12:04:30 -0700 | [diff] [blame] | 719 | sk_sp<SkSVGDOM> svgDom = SkSVGDOM::MakeFromStream(stream); |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 720 | if (!svgDom) { |
| 721 | SkDebugf("Could not parse %s.\n", path); |
| 722 | return nullptr; |
| 723 | } |
| 724 | |
fmalita | e1baa7c | 2016-09-14 12:04:30 -0700 | [diff] [blame] | 725 | // Use the intrinsic SVG size if available, otherwise fall back to a default value. |
| 726 | static const SkSize kDefaultContainerSize = SkSize::Make(128, 128); |
| 727 | if (svgDom->containerSize().isEmpty()) { |
| 728 | svgDom->setContainerSize(kDefaultContainerSize); |
| 729 | } |
| 730 | |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 731 | SkPictureRecorder recorder; |
fmalita | e1baa7c | 2016-09-14 12:04:30 -0700 | [diff] [blame] | 732 | svgDom->render(recorder.beginRecording(svgDom->containerSize().width(), |
| 733 | svgDom->containerSize().height())); |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 734 | return recorder.finishRecordingAsPicture(); |
Hal Canary | 0f66681 | 2018-03-22 15:21:12 -0400 | [diff] [blame] | 735 | #else |
| 736 | return nullptr; |
| 737 | #endif // SK_XML |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 738 | } |
| 739 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 740 | Benchmark* next() { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 741 | std::unique_ptr<Benchmark> bench; |
mtklein | 65dfd2f | 2016-02-03 10:40:54 -0800 | [diff] [blame] | 742 | do { |
| 743 | bench.reset(this->rawNext()); |
| 744 | if (!bench) { |
| 745 | return nullptr; |
| 746 | } |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 747 | } while (CommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) || |
| 748 | CommandLineFlags::ShouldSkip(FLAGS_benchType, fBenchType)); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 749 | return bench.release(); |
mtklein | 65dfd2f | 2016-02-03 10:40:54 -0800 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | Benchmark* rawNext() { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 753 | if (fBenches) { |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 754 | Benchmark* bench = fBenches->get()(nullptr); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 755 | fBenches = fBenches->next(); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 756 | fSourceType = "bench"; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 757 | fBenchType = "micro"; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 758 | return bench; |
| 759 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 760 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 761 | while (fGMs) { |
Ben Wagner | 406ff50 | 2019-08-12 16:39:24 -0400 | [diff] [blame] | 762 | std::unique_ptr<skiagm::GM> gm = fGMs->get()(); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 763 | fGMs = fGMs->next(); |
mtklein | cf5d9c9 | 2015-01-23 10:31:45 -0800 | [diff] [blame] | 764 | if (gm->runAsBench()) { |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 765 | fSourceType = "gm"; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 766 | fBenchType = "micro"; |
Ben Wagner | 406ff50 | 2019-08-12 16:39:24 -0400 | [diff] [blame] | 767 | return new GMBench(std::move(gm)); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 768 | } |
| 769 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 770 | |
Hal Canary | 5dfefa2 | 2019-10-24 13:52:17 -0400 | [diff] [blame] | 771 | while (fCurrentTextBlobTrace < fTextBlobTraces.count()) { |
| 772 | SkString path = fTextBlobTraces[fCurrentTextBlobTrace++]; |
| 773 | SkString basename = SkOSPath::Basename(path.c_str()); |
| 774 | static constexpr char kEnding[] = ".trace"; |
| 775 | if (basename.endsWith(kEnding)) { |
| 776 | basename.remove(basename.size() - strlen(kEnding), strlen(kEnding)); |
| 777 | } |
| 778 | fSourceType = "texttrace"; |
| 779 | fBenchType = "micro"; |
| 780 | return CreateDiffCanvasBench( |
| 781 | SkStringPrintf("SkDiffBench-%s", basename.c_str()), |
| 782 | [path](){ return SkStream::MakeFromFile(path.c_str()); }); |
| 783 | } |
| 784 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 785 | // First add all .skps as RecordingBenches. |
| 786 | while (fCurrentRecording < fSKPs.count()) { |
| 787 | const SkString& path = fSKPs[fCurrentRecording++]; |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 788 | sk_sp<SkPicture> pic = ReadPicture(path.c_str()); |
| 789 | if (!pic) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 790 | continue; |
| 791 | } |
| 792 | SkString name = SkOSPath::Basename(path.c_str()); |
| 793 | fSourceType = "skp"; |
| 794 | fBenchType = "recording"; |
Mike Klein | 88d9071 | 2018-01-27 17:30:04 +0000 | [diff] [blame] | 795 | fSKPBytes = static_cast<double>(pic->approximateBytesUsed()); |
| 796 | fSKPOps = pic->approximateOpCount(); |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 797 | return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 800 | // Add all .skps as DeserializePictureBenchs. |
| 801 | while (fCurrentDeserialPicture < fSKPs.count()) { |
| 802 | const SkString& path = fSKPs[fCurrentDeserialPicture++]; |
| 803 | sk_sp<SkData> data = SkData::MakeFromFileName(path.c_str()); |
| 804 | if (!data) { |
| 805 | continue; |
| 806 | } |
| 807 | SkString name = SkOSPath::Basename(path.c_str()); |
| 808 | fSourceType = "skp"; |
| 809 | fBenchType = "deserial"; |
Mike Reed | 7557bbb | 2017-12-24 19:50:57 -0500 | [diff] [blame] | 810 | fSKPBytes = static_cast<double>(data->size()); |
Mike Klein | 88d9071 | 2018-01-27 17:30:04 +0000 | [diff] [blame] | 811 | fSKPOps = 0; |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 812 | return new DeserializePictureBench(name.c_str(), std::move(data)); |
| 813 | } |
| 814 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 815 | // Then once each for each scale as SKPBenches (playback). |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 816 | while (fCurrentScale < fScales.count()) { |
| 817 | while (fCurrentSKP < fSKPs.count()) { |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 818 | const SkString& path = fSKPs[fCurrentSKP]; |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 819 | sk_sp<SkPicture> pic = ReadPicture(path.c_str()); |
| 820 | if (!pic) { |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 821 | fCurrentSKP++; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 822 | continue; |
| 823 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 824 | |
| 825 | while (fCurrentUseMPD < fUseMPDs.count()) { |
| 826 | if (FLAGS_bbh) { |
| 827 | // The SKP we read off disk doesn't have a BBH. Re-record so it grows one. |
| 828 | SkRTreeFactory factory; |
| 829 | SkPictureRecorder recorder; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 830 | pic->playback(recorder.beginRecording(pic->cullRect().width(), |
| 831 | pic->cullRect().height(), |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 832 | &factory, |
robertphillips | dda5445 | 2016-07-13 13:27:16 -0700 | [diff] [blame] | 833 | 0)); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 834 | pic = recorder.finishRecordingAsPicture(); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 835 | } |
| 836 | SkString name = SkOSPath::Basename(path.c_str()); |
| 837 | fSourceType = "skp"; |
| 838 | fBenchType = "playback"; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 839 | return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale], |
| 840 | fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP); |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 841 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 842 | fCurrentUseMPD = 0; |
| 843 | fCurrentSKP++; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 844 | } |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 845 | |
| 846 | while (fCurrentSVG++ < fSVGs.count()) { |
| 847 | const char* path = fSVGs[fCurrentSVG - 1].c_str(); |
| 848 | if (sk_sp<SkPicture> pic = ReadSVGPicture(path)) { |
| 849 | fSourceType = "svg"; |
| 850 | fBenchType = "playback"; |
| 851 | return new SKPBench(SkOSPath::Basename(path).c_str(), pic.get(), fClip, |
| 852 | fScales[fCurrentScale], false, FLAGS_loopSKP); |
| 853 | } |
| 854 | } |
| 855 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 856 | fCurrentSKP = 0; |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 857 | fCurrentSVG = 0; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 858 | fCurrentScale++; |
| 859 | } |
| 860 | |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 861 | // Now loop over each skp again if we have an animation |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 862 | if (fZoomMax != 1.0f && fZoomPeriodMs > 0) { |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 863 | while (fCurrentAnimSKP < fSKPs.count()) { |
| 864 | const SkString& path = fSKPs[fCurrentAnimSKP]; |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 865 | sk_sp<SkPicture> pic = ReadPicture(path.c_str()); |
| 866 | if (!pic) { |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 867 | fCurrentAnimSKP++; |
| 868 | continue; |
| 869 | } |
| 870 | |
| 871 | fCurrentAnimSKP++; |
| 872 | SkString name = SkOSPath::Basename(path.c_str()); |
Ben Wagner | acf98df | 2019-07-12 12:51:44 -0400 | [diff] [blame] | 873 | sk_sp<SKPAnimationBench::Animation> animation = |
| 874 | SKPAnimationBench::MakeZoomAnimation(fZoomMax, fZoomPeriodMs); |
| 875 | return new SKPAnimationBench(name.c_str(), pic.get(), fClip, std::move(animation), |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 876 | FLAGS_loopSKP); |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 880 | for (; fCurrentCodec < fImages.count(); fCurrentCodec++) { |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 881 | fSourceType = "image"; |
| 882 | fBenchType = "skcodec"; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 883 | const SkString& path = fImages[fCurrentCodec]; |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 884 | if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
mtklein | 6f0ff91 | 2016-01-11 09:04:21 -0800 | [diff] [blame] | 885 | continue; |
| 886 | } |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 887 | sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str())); |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 888 | std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded)); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 889 | if (!codec) { |
| 890 | // Nothing to time. |
msarett | 9d9725c | 2015-04-24 11:41:55 -0700 | [diff] [blame] | 891 | SkDebugf("Cannot find codec for %s\n", path.c_str()); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 892 | continue; |
| 893 | } |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 894 | |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 895 | while (fCurrentColorType < fColorTypes.count()) { |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 896 | const SkColorType colorType = fColorTypes[fCurrentColorType]; |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 897 | |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 898 | SkAlphaType alphaType = codec->getInfo().alphaType(); |
msarett | 67cb666 | 2016-06-21 08:49:26 -0700 | [diff] [blame] | 899 | if (FLAGS_simpleCodec) { |
| 900 | if (kUnpremul_SkAlphaType == alphaType) { |
| 901 | alphaType = kPremul_SkAlphaType; |
| 902 | } |
| 903 | |
| 904 | fCurrentColorType++; |
| 905 | } else { |
| 906 | switch (alphaType) { |
| 907 | case kOpaque_SkAlphaType: |
| 908 | // We only need to test one alpha type (opaque). |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 909 | fCurrentColorType++; |
msarett | 67cb666 | 2016-06-21 08:49:26 -0700 | [diff] [blame] | 910 | break; |
| 911 | case kUnpremul_SkAlphaType: |
| 912 | case kPremul_SkAlphaType: |
| 913 | if (0 == fCurrentAlphaType) { |
| 914 | // Test unpremul first. |
| 915 | alphaType = kUnpremul_SkAlphaType; |
| 916 | fCurrentAlphaType++; |
| 917 | } else { |
| 918 | // Test premul. |
| 919 | alphaType = kPremul_SkAlphaType; |
| 920 | fCurrentAlphaType = 0; |
| 921 | fCurrentColorType++; |
| 922 | } |
| 923 | break; |
| 924 | default: |
| 925 | SkASSERT(false); |
| 926 | fCurrentColorType++; |
| 927 | break; |
| 928 | } |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 929 | } |
| 930 | |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 931 | // Make sure we can decode to this color type and alpha type. |
| 932 | SkImageInfo info = |
| 933 | codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType); |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 934 | const size_t rowBytes = info.minRowBytes(); |
Mike Reed | f0ffb89 | 2017-10-03 14:47:21 -0400 | [diff] [blame] | 935 | SkAutoMalloc storage(info.computeByteSize(rowBytes)); |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 936 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 937 | const SkCodec::Result result = codec->getPixels( |
Leon Scroggins | 571b30f | 2017-07-11 17:35:31 +0000 | [diff] [blame] | 938 | info, storage.get(), rowBytes); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 939 | switch (result) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 940 | case SkCodec::kSuccess: |
| 941 | case SkCodec::kIncompleteInput: |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 942 | return new CodecBench(SkOSPath::Basename(path.c_str()), |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 943 | encoded.get(), colorType, alphaType); |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 944 | case SkCodec::kInvalidConversion: |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 945 | // This is okay. Not all conversions are valid. |
| 946 | break; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 947 | default: |
| 948 | // This represents some sort of failure. |
| 949 | SkASSERT(false); |
| 950 | break; |
| 951 | } |
| 952 | } |
| 953 | fCurrentColorType = 0; |
| 954 | } |
| 955 | |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 956 | // Run AndroidCodecBenches |
| 957 | const int sampleSizes[] = { 2, 4, 8 }; |
| 958 | for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) { |
| 959 | fSourceType = "image"; |
| 960 | fBenchType = "skandroidcodec"; |
| 961 | |
| 962 | const SkString& path = fImages[fCurrentAndroidCodec]; |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 963 | if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 964 | continue; |
| 965 | } |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 966 | sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str())); |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 967 | std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded)); |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 968 | if (!codec) { |
| 969 | // Nothing to time. |
| 970 | SkDebugf("Cannot find codec for %s\n", path.c_str()); |
| 971 | continue; |
| 972 | } |
| 973 | |
| 974 | while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) { |
| 975 | int sampleSize = sampleSizes[fCurrentSampleSize]; |
| 976 | fCurrentSampleSize++; |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 977 | if (10 * sampleSize > std::min(codec->getInfo().width(), codec->getInfo().height())) { |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 978 | // Avoid benchmarking scaled decodes of already small images. |
| 979 | break; |
| 980 | } |
| 981 | |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 982 | return new AndroidCodecBench(SkOSPath::Basename(path.c_str()), |
| 983 | encoded.get(), sampleSize); |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 984 | } |
| 985 | fCurrentSampleSize = 0; |
| 986 | } |
| 987 | |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 988 | #ifdef SK_ENABLE_ANDROID_UTILS |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 989 | // Run the BRDBenches |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 990 | // We intend to create benchmarks that model the use cases in |
| 991 | // android/libraries/social/tiledimage. In this library, an image is decoded in 512x512 |
| 992 | // tiles. The image can be translated freely, so the location of a tile may be anywhere in |
| 993 | // the image. For that reason, we will benchmark decodes in five representative locations |
| 994 | // in the image. Additionally, this use case utilizes power of two scaling, so we will |
| 995 | // test on power of two sample sizes. The output tile is always 512x512, so, when a |
| 996 | // sampleSize is used, the size of the subset that is decoded is always |
| 997 | // (sampleSize*512)x(sampleSize*512). |
| 998 | // There are a few good reasons to only test on power of two sample sizes at this time: |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 999 | // All use cases we are aware of only scale by powers of two. |
| 1000 | // PNG decodes use the indicated sampling strategy regardless of the sample size, so |
| 1001 | // these tests are sufficient to provide good coverage of our scaling options. |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 1002 | const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 }; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1003 | const uint32_t minOutputSize = 512; |
mtklein | 6f0ff91 | 2016-01-11 09:04:21 -0800 | [diff] [blame] | 1004 | for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) { |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 1005 | fSourceType = "image"; |
| 1006 | fBenchType = "BRD"; |
| 1007 | |
mtklein | 6f0ff91 | 2016-01-11 09:04:21 -0800 | [diff] [blame] | 1008 | const SkString& path = fImages[fCurrentBRDImage]; |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 1009 | if (CommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
mtklein | 6f0ff91 | 2016-01-11 09:04:21 -0800 | [diff] [blame] | 1010 | continue; |
| 1011 | } |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 1012 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 1013 | while (fCurrentColorType < fColorTypes.count()) { |
| 1014 | while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) { |
| 1015 | while (fCurrentSubsetType <= kLastSingle_SubsetType) { |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 1016 | |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 1017 | sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str())); |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 1018 | const SkColorType colorType = fColorTypes[fCurrentColorType]; |
| 1019 | uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize]; |
| 1020 | int currentSubsetType = fCurrentSubsetType++; |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 1021 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 1022 | int width = 0; |
| 1023 | int height = 0; |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 1024 | if (!valid_brd_bench(encoded, colorType, sampleSize, minOutputSize, |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 1025 | &width, &height)) { |
| 1026 | break; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1027 | } |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 1028 | |
| 1029 | SkString basename = SkOSPath::Basename(path.c_str()); |
| 1030 | SkIRect subset; |
| 1031 | const uint32_t subsetSize = sampleSize * minOutputSize; |
| 1032 | switch (currentSubsetType) { |
| 1033 | case kTopLeft_SubsetType: |
| 1034 | basename.append("_TopLeft"); |
| 1035 | subset = SkIRect::MakeXYWH(0, 0, subsetSize, subsetSize); |
| 1036 | break; |
| 1037 | case kTopRight_SubsetType: |
| 1038 | basename.append("_TopRight"); |
| 1039 | subset = SkIRect::MakeXYWH(width - subsetSize, 0, subsetSize, |
| 1040 | subsetSize); |
| 1041 | break; |
| 1042 | case kMiddle_SubsetType: |
| 1043 | basename.append("_Middle"); |
| 1044 | subset = SkIRect::MakeXYWH((width - subsetSize) / 2, |
| 1045 | (height - subsetSize) / 2, subsetSize, subsetSize); |
| 1046 | break; |
| 1047 | case kBottomLeft_SubsetType: |
| 1048 | basename.append("_BottomLeft"); |
| 1049 | subset = SkIRect::MakeXYWH(0, height - subsetSize, subsetSize, |
| 1050 | subsetSize); |
| 1051 | break; |
| 1052 | case kBottomRight_SubsetType: |
| 1053 | basename.append("_BottomRight"); |
| 1054 | subset = SkIRect::MakeXYWH(width - subsetSize, |
| 1055 | height - subsetSize, subsetSize, subsetSize); |
| 1056 | break; |
| 1057 | default: |
| 1058 | SkASSERT(false); |
| 1059 | } |
| 1060 | |
| 1061 | return new BitmapRegionDecoderBench(basename.c_str(), encoded.get(), |
| 1062 | colorType, sampleSize, subset); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1063 | } |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 1064 | fCurrentSubsetType = 0; |
| 1065 | fCurrentSampleSize++; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1066 | } |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 1067 | fCurrentSampleSize = 0; |
| 1068 | fCurrentColorType++; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1069 | } |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 1070 | fCurrentColorType = 0; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1071 | } |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 1072 | #endif // SK_ENABLE_ANDROID_UTILS |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1073 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1074 | return nullptr; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1075 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1076 | |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1077 | void fillCurrentOptions(NanoJSONResultsWriter& log) const { |
| 1078 | log.appendString("source_type", fSourceType); |
| 1079 | log.appendString("bench_type", fBenchType); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1080 | if (0 == strcmp(fSourceType, "skp")) { |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1081 | log.appendString("clip", |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1082 | SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
| 1083 | fClip.fRight, fClip.fBottom).c_str()); |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 1084 | SkASSERT_RELEASE(fCurrentScale < fScales.count()); // debugging paranoia |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1085 | log.appendString("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str()); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1086 | if (fCurrentUseMPD > 0) { |
| 1087 | SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1088 | log.appendString("multi_picture_draw", |
| 1089 | fUseMPDs[fCurrentUseMPD-1] ? "true" : "false"); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1090 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1091 | } |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | void fillCurrentMetrics(NanoJSONResultsWriter& log) const { |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 1095 | if (0 == strcmp(fBenchType, "recording")) { |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1096 | log.appendMetric("bytes", fSKPBytes); |
| 1097 | log.appendMetric("ops", fSKPOps); |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 1098 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1101 | private: |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 1102 | #ifdef SK_ENABLE_ANDROID_UTILS |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 1103 | enum SubsetType { |
| 1104 | kTopLeft_SubsetType = 0, |
| 1105 | kTopRight_SubsetType = 1, |
msarett | ab80e35 | 2015-06-17 10:28:22 -0700 | [diff] [blame] | 1106 | kMiddle_SubsetType = 2, |
| 1107 | kBottomLeft_SubsetType = 3, |
| 1108 | kBottomRight_SubsetType = 4, |
| 1109 | kTranslate_SubsetType = 5, |
| 1110 | kZoom_SubsetType = 6, |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1111 | kLast_SubsetType = kZoom_SubsetType, |
| 1112 | kLastSingle_SubsetType = kBottomRight_SubsetType, |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 1113 | }; |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 1114 | #endif |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 1115 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1116 | const BenchRegistry* fBenches; |
| 1117 | const skiagm::GMRegistry* fGMs; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1118 | SkIRect fClip; |
| 1119 | SkTArray<SkScalar> fScales; |
| 1120 | SkTArray<SkString> fSKPs; |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 1121 | SkTArray<SkString> fSVGs; |
Hal Canary | 5dfefa2 | 2019-10-24 13:52:17 -0400 | [diff] [blame] | 1122 | SkTArray<SkString> fTextBlobTraces; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1123 | SkTArray<bool> fUseMPDs; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 1124 | SkTArray<SkString> fImages; |
msarett | 74deb98 | 2015-10-20 16:45:56 -0700 | [diff] [blame] | 1125 | SkTArray<SkColorType, true> fColorTypes; |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 1126 | SkScalar fZoomMax; |
| 1127 | double fZoomPeriodMs; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1128 | |
Mike Klein | 88d9071 | 2018-01-27 17:30:04 +0000 | [diff] [blame] | 1129 | double fSKPBytes, fSKPOps; |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 1130 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 1131 | const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
| 1132 | const char* fBenchType; // How we bench it: micro, recording, playback, ... |
Hal Canary | 2362ae7 | 2019-10-24 13:40:40 -0400 | [diff] [blame] | 1133 | int fCurrentRecording = 0; |
| 1134 | int fCurrentDeserialPicture = 0; |
| 1135 | int fCurrentScale = 0; |
| 1136 | int fCurrentSKP = 0; |
| 1137 | int fCurrentSVG = 0; |
Hal Canary | 5dfefa2 | 2019-10-24 13:52:17 -0400 | [diff] [blame] | 1138 | int fCurrentTextBlobTrace = 0; |
Hal Canary | 2362ae7 | 2019-10-24 13:40:40 -0400 | [diff] [blame] | 1139 | int fCurrentUseMPD = 0; |
| 1140 | int fCurrentCodec = 0; |
| 1141 | int fCurrentAndroidCodec = 0; |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 1142 | #ifdef SK_ENABLE_ANDROID_UTILS |
Hal Canary | 2362ae7 | 2019-10-24 13:40:40 -0400 | [diff] [blame] | 1143 | int fCurrentBRDImage = 0; |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 1144 | int fCurrentSubsetType = 0; |
| 1145 | #endif |
Hal Canary | 2362ae7 | 2019-10-24 13:40:40 -0400 | [diff] [blame] | 1146 | int fCurrentColorType = 0; |
| 1147 | int fCurrentAlphaType = 0; |
Hal Canary | 2362ae7 | 2019-10-24 13:40:40 -0400 | [diff] [blame] | 1148 | int fCurrentSampleSize = 0; |
| 1149 | int fCurrentAnimSKP = 0; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1150 | }; |
| 1151 | |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 1152 | // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung. |
| 1153 | // This prints something every once in a while so that it knows we're still working. |
| 1154 | static void start_keepalive() { |
Mike Klein | 03141d2 | 2017-10-30 11:57:15 -0400 | [diff] [blame] | 1155 | static std::thread* intentionallyLeaked = new std::thread([]{ |
| 1156 | for (;;) { |
| 1157 | static const int kSec = 1200; |
| 1158 | #if defined(SK_BUILD_FOR_WIN) |
| 1159 | Sleep(kSec * 1000); |
| 1160 | #else |
| 1161 | sleep(kSec); |
| 1162 | #endif |
| 1163 | SkDebugf("\nBenchmarks still running...\n"); |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 1164 | } |
Mike Klein | 03141d2 | 2017-10-30 11:57:15 -0400 | [diff] [blame] | 1165 | }); |
| 1166 | (void)intentionallyLeaked; |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 1167 | } |
| 1168 | |
Mike Klein | be28ee2 | 2017-02-06 12:46:20 -0500 | [diff] [blame] | 1169 | int main(int argc, char** argv) { |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 1170 | CommandLineFlags::Parse(argc, argv); |
Brian Osman | 53136aa | 2017-07-20 15:43:35 -0400 | [diff] [blame] | 1171 | |
Brian Osman | bc8150f | 2017-07-24 11:38:01 -0400 | [diff] [blame] | 1172 | initializeEventTracingForTools(); |
Brian Osman | 53136aa | 2017-07-20 15:43:35 -0400 | [diff] [blame] | 1173 | |
Mike Klein | adacaef | 2017-02-06 09:26:14 -0500 | [diff] [blame] | 1174 | #if defined(SK_BUILD_FOR_IOS) |
| 1175 | cd_Documents(); |
| 1176 | #endif |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1177 | SetupCrashHandler(); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1178 | SkAutoGraphics ag; |
mtklein | cc29d26 | 2015-07-09 10:04:56 -0700 | [diff] [blame] | 1179 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1180 | |
Chris Dalton | 040238b | 2017-12-18 14:22:34 -0700 | [diff] [blame] | 1181 | SetCtxOptionsFromCommonFlags(&grContextOpts); |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 1182 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1183 | if (kAutoTuneLoops != FLAGS_loops) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 1184 | FLAGS_samples = 1; |
| 1185 | FLAGS_gpuFrameLag = 0; |
| 1186 | } |
| 1187 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1188 | if (!FLAGS_writePath.isEmpty()) { |
| 1189 | SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]); |
| 1190 | if (!sk_mkdir(FLAGS_writePath[0])) { |
| 1191 | SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1192 | FLAGS_writePath.set(0, nullptr); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1196 | std::unique_ptr<SkWStream> logStream(new SkNullWStream); |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1197 | if (!FLAGS_outResultsFile.isEmpty()) { |
mtklein | 5352015 | 2016-01-20 09:53:59 -0800 | [diff] [blame] | 1198 | #if defined(SK_RELEASE) |
Chris Dalton | 2e1381e | 2019-10-23 14:35:19 -0600 | [diff] [blame] | 1199 | // SkJSONWriter uses a 32k in-memory cache, so it only flushes occasionally and is well |
| 1200 | // equipped for a stream that re-opens, appends, and closes the file on every write. |
| 1201 | logStream.reset(new NanoFILEAppendAndCloseStream(FLAGS_outResultsFile[0])); |
mtklein | 5352015 | 2016-01-20 09:53:59 -0800 | [diff] [blame] | 1202 | #else |
| 1203 | SkDebugf("I'm ignoring --outResultsFile because this is a Debug build."); |
| 1204 | return 1; |
| 1205 | #endif |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1206 | } |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1207 | NanoJSONResultsWriter log(logStream.get(), SkJSONWriter::Mode::kPretty); |
| 1208 | log.beginObject(); // root |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1209 | |
| 1210 | if (1 == FLAGS_properties.count() % 2) { |
| 1211 | SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n"); |
| 1212 | return 1; |
| 1213 | } |
| 1214 | for (int i = 1; i < FLAGS_properties.count(); i += 2) { |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1215 | log.appendString(FLAGS_properties[i-1], FLAGS_properties[i]); |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1216 | } |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 1217 | |
| 1218 | if (1 == FLAGS_key.count() % 2) { |
| 1219 | SkDebugf("ERROR: --key must be passed with an even number of arguments.\n"); |
| 1220 | return 1; |
| 1221 | } |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1222 | if (FLAGS_key.count()) { |
| 1223 | log.beginObject("key"); |
| 1224 | for (int i = 1; i < FLAGS_key.count(); i += 2) { |
| 1225 | log.appendString(FLAGS_key[i - 1], FLAGS_key[i]); |
| 1226 | } |
| 1227 | log.endObject(); // key |
mtklein | 94e5156 | 2014-08-19 12:41:53 -0700 | [diff] [blame] | 1228 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1229 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1230 | const double overhead = estimate_timer_overhead(); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 1231 | SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead)); |
Mike Klein | 9129477 | 2014-07-16 19:59:32 -0400 | [diff] [blame] | 1232 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1233 | SkTArray<double> samples; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 1234 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1235 | if (kAutoTuneLoops != FLAGS_loops) { |
| 1236 | SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1237 | } else if (FLAGS_quiet) { |
mtklein | 66cfcff | 2015-12-04 06:35:30 -0800 | [diff] [blame] | 1238 | SkDebugf("! -> high variance, ? -> moderate variance\n"); |
| 1239 | SkDebugf(" micros \tbench\n"); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1240 | } else if (FLAGS_ms) { |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1241 | SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1242 | } else { |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1243 | SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n", |
qiankun.miao | 8247ec3 | 2014-09-09 19:24:36 -0700 | [diff] [blame] | 1244 | FLAGS_samples, "samples"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 1247 | SkTArray<Config> configs; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 1248 | create_configs(&configs); |
| 1249 | |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 1250 | if (FLAGS_keepAlive) { |
| 1251 | start_keepalive(); |
| 1252 | } |
| 1253 | |
Mike Klein | 03fa5d4 | 2019-03-22 11:39:09 -0500 | [diff] [blame] | 1254 | SetAnalyticAAFromCommonFlags(); |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame] | 1255 | |
Mike Klein | 813e8cc | 2020-08-05 09:33:38 -0500 | [diff] [blame^] | 1256 | gSkForceRasterPipelineBlitter = FLAGS_forceRasterPipeline; |
| 1257 | gUseSkVMBlitter = FLAGS_skvm; |
| 1258 | gSkVMAllowJIT = gSkVMJITViaDylib = FLAGS_jit; |
Yuqian Li | 550148b | 2017-01-13 10:13:13 -0500 | [diff] [blame] | 1259 | |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 1260 | int runs = 0; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1261 | BenchmarkStream benchStream; |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1262 | log.beginObject("results"); |
Jim Van Verth | 8a9a371 | 2019-05-31 10:49:12 -0400 | [diff] [blame] | 1263 | AutoreleasePool pool; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1264 | while (Benchmark* b = benchStream.next()) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 1265 | std::unique_ptr<Benchmark> bench(b); |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 1266 | if (CommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1267 | continue; |
| 1268 | } |
| 1269 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 1270 | if (!configs.empty()) { |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1271 | log.beginBench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY); |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 1272 | bench->delayedSetup(); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 1273 | } |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1274 | for (int i = 0; i < configs.count(); ++i) { |
| 1275 | Target* target = is_enabled(b, configs[i]); |
| 1276 | if (!target) { |
| 1277 | continue; |
| 1278 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1279 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1280 | // During HWUI output this canvas may be nullptr. |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1281 | SkCanvas* canvas = target->getCanvas(); |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 1282 | const char* config = target->config.name.c_str(); |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1283 | |
brianosman | 7a5ada8 | 2016-02-08 13:49:12 -0800 | [diff] [blame] | 1284 | if (FLAGS_pre_log || FLAGS_dryRun) { |
benjaminwagner | 8d61f0d | 2016-01-25 13:02:40 -0800 | [diff] [blame] | 1285 | SkDebugf("Running %s\t%s\n" |
| 1286 | , bench->getUniqueName() |
| 1287 | , config); |
brianosman | 7a5ada8 | 2016-02-08 13:49:12 -0800 | [diff] [blame] | 1288 | if (FLAGS_dryRun) { |
| 1289 | continue; |
| 1290 | } |
benjaminwagner | 8d61f0d | 2016-01-25 13:02:40 -0800 | [diff] [blame] | 1291 | } |
| 1292 | |
Mike Klein | ee25423 | 2019-03-28 08:32:14 -0500 | [diff] [blame] | 1293 | if (FLAGS_purgeBetweenBenches) { |
| 1294 | SkGraphics::PurgeAllCaches(); |
| 1295 | } |
| 1296 | |
Brian Osman | 5ad87aa | 2017-09-08 16:05:23 -0400 | [diff] [blame] | 1297 | TRACE_EVENT2("skia", "Benchmark", "name", TRACE_STR_COPY(bench->getUniqueName()), |
| 1298 | "config", TRACE_STR_COPY(config)); |
Brian Osman | c3cdef5 | 2017-08-31 14:09:22 -0400 | [diff] [blame] | 1299 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1300 | target->setup(); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1301 | bench->perCanvasPreDraw(canvas); |
| 1302 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1303 | int maxFrameLag; |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 1304 | int loops = target->needsFrameTiming(&maxFrameLag) |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1305 | ? setup_gpu_bench(target, bench.get(), maxFrameLag) |
| 1306 | : setup_cpu_bench(overhead, target, bench.get()); |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1307 | |
Leon Scroggins III | b30d113 | 2017-10-02 09:48:15 -0400 | [diff] [blame] | 1308 | if (kFailedLoops == loops) { |
| 1309 | // Can't be timed. A warning note has already been printed. |
| 1310 | cleanup_run(target); |
| 1311 | continue; |
| 1312 | } |
| 1313 | |
Yuqian Li | 3528eb3 | 2017-09-21 13:23:49 -0400 | [diff] [blame] | 1314 | if (runs == 0 && FLAGS_ms < 1000) { |
| 1315 | // Run the first bench for 1000ms to warm up the nanobench if FLAGS_ms < 1000. |
| 1316 | // Otherwise, the first few benches' measurements will be inaccurate. |
| 1317 | auto stop = now_ms() + 1000; |
| 1318 | do { |
| 1319 | time(loops, bench.get(), target); |
Jim Van Verth | 49d6bca | 2020-02-28 11:05:44 -0500 | [diff] [blame] | 1320 | pool.drain(); |
Yuqian Li | 3528eb3 | 2017-09-21 13:23:49 -0400 | [diff] [blame] | 1321 | } while (now_ms() < stop); |
| 1322 | } |
| 1323 | |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1324 | if (FLAGS_ms) { |
| 1325 | samples.reset(); |
| 1326 | auto stop = now_ms() + FLAGS_ms; |
| 1327 | do { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 1328 | samples.push_back(time(loops, bench.get(), target) / loops); |
Jim Van Verth | 49d6bca | 2020-02-28 11:05:44 -0500 | [diff] [blame] | 1329 | pool.drain(); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1330 | } while (now_ms() < stop); |
| 1331 | } else { |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1332 | samples.reset(FLAGS_samples); |
| 1333 | for (int s = 0; s < FLAGS_samples; s++) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 1334 | samples[s] = time(loops, bench.get(), target) / loops; |
Jim Van Verth | 49d6bca | 2020-02-28 11:05:44 -0500 | [diff] [blame] | 1335 | pool.drain(); |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1336 | } |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1337 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1338 | |
Mike Klein | fec9b90 | 2019-05-31 10:03:07 -0500 | [diff] [blame] | 1339 | // Scale each result to the benchmark's own units, time/unit. |
| 1340 | for (double& sample : samples) { |
| 1341 | sample *= (1.0 / bench->getUnits()); |
| 1342 | } |
| 1343 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1344 | SkTArray<SkString> keys; |
| 1345 | SkTArray<double> values; |
| 1346 | bool gpuStatsDump = FLAGS_gpuStatsDump && Benchmark::kGPU_Backend == configs[i].backend; |
| 1347 | if (gpuStatsDump) { |
| 1348 | // TODO cache stats |
| 1349 | bench->getGpuStats(canvas, &keys, &values); |
| 1350 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1351 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1352 | bench->perCanvasPostDraw(canvas); |
| 1353 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1354 | if (Benchmark::kNonRendering_Backend != target->config.backend && |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 1355 | !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1356 | SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1357 | pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName()); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1358 | pngFilename.append(".png"); |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1359 | write_canvas_png(target, pngFilename); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
Mike Klein | 512a244 | 2018-09-27 10:44:56 -0400 | [diff] [blame] | 1362 | // Building stats.plot often shows up in profiles, |
| 1363 | // so skip building it when we're not going to print it anyway. |
| 1364 | const bool want_plot = !FLAGS_quiet; |
| 1365 | |
| 1366 | Stats stats(samples, want_plot); |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1367 | log.beginObject(config); |
| 1368 | |
| 1369 | log.beginObject("options"); |
| 1370 | log.appendString("name", bench->getName()); |
| 1371 | benchStream.fillCurrentOptions(log); |
| 1372 | target->fillOptions(log); |
| 1373 | log.endObject(); // options |
| 1374 | |
| 1375 | // Metrics |
| 1376 | log.appendMetric("min_ms", stats.min); |
| 1377 | log.beginArray("samples"); |
| 1378 | for (double sample : samples) { |
| 1379 | log.appendDoubleDigits(sample, 16); |
| 1380 | } |
| 1381 | log.endArray(); // samples |
| 1382 | benchStream.fillCurrentMetrics(log); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1383 | if (gpuStatsDump) { |
| 1384 | // dump to json, only SKPBench currently returns valid keys / values |
| 1385 | SkASSERT(keys.count() == values.count()); |
| 1386 | for (int i = 0; i < keys.count(); i++) { |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1387 | log.appendMetric(keys[i].c_str(), values[i]); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1388 | } |
| 1389 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1390 | |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1391 | log.endObject(); // config |
| 1392 | |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 1393 | if (runs++ % FLAGS_flushEvery == 0) { |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1394 | log.flush(); |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 1395 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1396 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1397 | if (kAutoTuneLoops != FLAGS_loops) { |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1398 | if (configs.count() == 1) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 1399 | config = ""; // Only print the config if we run the same bench on more than one. |
| 1400 | } |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1401 | SkDebugf("%4d/%-4dMB\t%s\t%s\n" |
| 1402 | , sk_tools::getCurrResidentSetSizeMB() |
| 1403 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | 53d2562 | 2014-09-18 07:39:42 -0700 | [diff] [blame] | 1404 | , bench->getUniqueName() |
| 1405 | , config); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1406 | } else if (FLAGS_quiet) { |
mtklein | 66cfcff | 2015-12-04 06:35:30 -0800 | [diff] [blame] | 1407 | const char* mark = " "; |
Hal Canary | e99e8da | 2019-01-14 16:34:50 -0500 | [diff] [blame] | 1408 | const double stddev_percent = |
| 1409 | sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean); |
mtklein | 66cfcff | 2015-12-04 06:35:30 -0800 | [diff] [blame] | 1410 | if (stddev_percent > 5) mark = "?"; |
| 1411 | if (stddev_percent > 10) mark = "!"; |
| 1412 | |
| 1413 | SkDebugf("%10.2f %s\t%s\t%s\n", |
| 1414 | stats.median*1e3, mark, bench->getUniqueName(), config); |
Mike Reed | c665e5b | 2017-07-04 22:56:06 -0400 | [diff] [blame] | 1415 | } else if (FLAGS_csv) { |
Hal Canary | e99e8da | 2019-01-14 16:34:50 -0500 | [diff] [blame] | 1416 | const double stddev_percent = |
| 1417 | sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean); |
Mike Reed | c665e5b | 2017-07-04 22:56:06 -0400 | [diff] [blame] | 1418 | SkDebugf("%g,%g,%g,%g,%g,%s,%s\n" |
| 1419 | , stats.min |
| 1420 | , stats.median |
| 1421 | , stats.mean |
| 1422 | , stats.max |
| 1423 | , stddev_percent |
| 1424 | , config |
| 1425 | , bench->getUniqueName() |
| 1426 | ); |
| 1427 | } else { |
| 1428 | 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 Canary | e99e8da | 2019-01-14 16:34:50 -0500 | [diff] [blame] | 1429 | const double stddev_percent = |
| 1430 | sk_ieee_double_divide(100 * sqrt(stats.var), stats.mean); |
Mike Reed | c665e5b | 2017-07-04 22:56:06 -0400 | [diff] [blame] | 1431 | SkDebugf(format |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1432 | , sk_tools::getCurrResidentSetSizeMB() |
| 1433 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1434 | , loops |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 1435 | , HUMANIZE(stats.min) |
| 1436 | , HUMANIZE(stats.median) |
| 1437 | , HUMANIZE(stats.mean) |
| 1438 | , HUMANIZE(stats.max) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1439 | , stddev_percent |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1440 | , FLAGS_ms ? to_string(samples.count()).c_str() : stats.plot.c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1441 | , config |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1442 | , bench->getUniqueName() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1443 | ); |
| 1444 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1445 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1446 | if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) { |
Brian Salomon | 0b4d8aa | 2017-10-11 15:34:27 -0400 | [diff] [blame] | 1447 | target->dumpStats(); |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 1448 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1449 | |
cdalton | 2c56ba5 | 2015-06-26 13:32:53 -0700 | [diff] [blame] | 1450 | if (FLAGS_verbose) { |
| 1451 | SkDebugf("Samples: "); |
| 1452 | for (int i = 0; i < samples.count(); i++) { |
| 1453 | SkDebugf("%s ", HUMANIZE(samples[i])); |
| 1454 | } |
| 1455 | SkDebugf("%s\n", bench->getUniqueName()); |
| 1456 | } |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1457 | cleanup_run(target); |
Jim Van Verth | 8a9a371 | 2019-05-31 10:49:12 -0400 | [diff] [blame] | 1458 | pool.drain(); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1459 | } |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1460 | if (!configs.empty()) { |
| 1461 | log.endBench(); |
| 1462 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
Herb Derby | 5a523fe | 2017-01-26 16:48:28 -0500 | [diff] [blame] | 1465 | SkGraphics::PurgeAllCaches(); |
| 1466 | |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1467 | log.beginBench("memory_usage", 0, 0); |
| 1468 | log.beginObject("meta"); // config |
| 1469 | log.appendS32("max_rss_mb", sk_tools::getMaxResidentSetSizeMB()); |
| 1470 | log.endObject(); // config |
| 1471 | log.endBench(); |
| 1472 | |
Brian Osman | 68870aa | 2020-07-08 14:12:43 -0400 | [diff] [blame] | 1473 | RunSkSLMemoryBenchmarks(&log); |
| 1474 | |
Brian Osman | 8c0a1ca | 2019-01-28 14:24:29 -0500 | [diff] [blame] | 1475 | log.endObject(); // results |
| 1476 | log.endObject(); // root |
| 1477 | log.flush(); |
mtklein | e109145 | 2014-12-04 10:47:02 -0800 | [diff] [blame] | 1478 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1479 | return 0; |
| 1480 | } |