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