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