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