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