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 | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 20 | #include "ResultsWriter.h" |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 21 | #include "RecordingBench.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" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 24 | #include "Stats.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 25 | |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 26 | #include "SkAndroidCodec.h" |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 27 | #include "SkBitmapRegionDecoder.h" |
mtklein | 6838d85 | 2014-10-29 14:15:10 -0700 | [diff] [blame] | 28 | #include "SkBBoxHierarchy.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 29 | #include "SkCanvas.h" |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 30 | #include "SkCodec.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" |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 33 | #include "SkData.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 34 | #include "SkForceLinking.h" |
| 35 | #include "SkGraphics.h" |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 36 | #include "SkOSFile.h" |
| 37 | #include "SkPictureRecorder.h" |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 38 | #include "SkPictureUtils.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 39 | #include "SkString.h" |
| 40 | #include "SkSurface.h" |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 41 | #include "SkTaskGroup.h" |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 42 | #include "SkThreadUtils.h" |
joshualitt | 3ebd050 | 2016-02-09 07:18:08 -0800 | [diff] [blame] | 43 | #include "ThermalManager.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 44 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 45 | #include <stdlib.h> |
| 46 | |
scroggo | 38ce0a7 | 2016-01-07 07:28:47 -0800 | [diff] [blame] | 47 | #ifndef SK_BUILD_FOR_WIN32 |
| 48 | #include <unistd.h> |
| 49 | #endif |
| 50 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 51 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 52 | #include "nanobenchAndroid.h" |
| 53 | #endif |
| 54 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 55 | #if SK_SUPPORT_GPU |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 56 | #include "gl/GrGLDefines.h" |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 57 | #include "GrCaps.h" |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 58 | #include "GrContextFactory.h" |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 59 | SkAutoTDelete<GrContextFactory> gGrFactory; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 60 | #endif |
| 61 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 62 | struct GrContextOptions; |
| 63 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 64 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 65 | |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 66 | static const int kAutoTuneLoops = 0; |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 67 | |
mtklein | b511042 | 2014-08-07 15:20:02 -0700 | [diff] [blame] | 68 | static const int kDefaultLoops = |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 69 | #ifdef SK_DEBUG |
| 70 | 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 71 | #else |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 72 | kAutoTuneLoops; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 73 | #endif |
| 74 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 75 | static SkString loops_help_txt() { |
| 76 | SkString help; |
| 77 | help.printf("Number of times to run each bench. Set this to %d to auto-" |
| 78 | "tune for each bench. Timings are only reported when auto-tuning.", |
| 79 | kAutoTuneLoops); |
| 80 | return help; |
| 81 | } |
| 82 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 83 | static SkString to_string(int n) { |
| 84 | SkString str; |
| 85 | str.appendS32(n); |
| 86 | return str; |
| 87 | } |
| 88 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 89 | DEFINE_int32(loops, kDefaultLoops, loops_help_txt().c_str()); |
| 90 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 91 | DEFINE_int32(samples, 10, "Number of samples to measure for each bench."); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 92 | 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] | 93 | DEFINE_int32(overheadLoops, 100000, "Loops to estimate timer overhead."); |
| 94 | DEFINE_double(overheadGoal, 0.0001, |
| 95 | "Loop until timer overhead is at most this fraction of our measurments."); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 96 | DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 97 | DEFINE_int32(gpuFrameLag, 5, "If unknown, estimated maximum number of frames GPU allows to lag."); |
krajcevski | 12b3544 | 2014-08-13 12:06:26 -0700 | [diff] [blame] | 98 | DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to " |
| 99 | "software path rendering."); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 100 | |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 101 | DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 102 | DEFINE_int32(maxCalibrationAttempts, 3, |
| 103 | "Try up to this many times to guess loops for a bench, or skip the bench."); |
| 104 | DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 105 | DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); |
| 106 | DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 107 | DEFINE_string(zoom, "1.0,0", "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom " |
| 108 | "function that ping-pongs between 1.0 and zoomMax."); |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 109 | DEFINE_bool(bbh, true, "Build a BBH for SKPs?"); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 110 | DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?"); |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 111 | DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?"); |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 112 | DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run."); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 113 | DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test."); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 114 | DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?"); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 115 | DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json"); |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 116 | DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out"); |
joshualitt | 3ebd050 | 2016-02-09 07:18:08 -0800 | [diff] [blame] | 117 | DEFINE_string(useThermalManager, "0,1,10,1000", "enabled,threshold,sleepTimeMs,TimeoutMs for " |
| 118 | "thermalManager\n"); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 119 | |
mtklein | 65dfd2f | 2016-02-03 10:40:54 -0800 | [diff] [blame] | 120 | DEFINE_string(sourceType, "", |
| 121 | "Apply usual --match rules to source type: bench, gm, skp, image, etc."); |
| 122 | DEFINE_string(benchType, "", |
| 123 | "Apply usual --match rules to bench type: micro, recording, playback, skcodec, etc."); |
| 124 | |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 125 | static double now_ms() { return SkTime::GetNSecs() * 1e-6; } |
| 126 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 127 | static SkString humanize(double ms) { |
mtklein | dc5bbab | 2014-09-24 06:34:09 -0700 | [diff] [blame] | 128 | if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 129 | return HumanizeMs(ms); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 130 | } |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 131 | #define HUMANIZE(ms) humanize(ms).c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 132 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 133 | bool Target::init(SkImageInfo info, Benchmark* bench) { |
| 134 | if (Benchmark::kRaster_Backend == config.backend) { |
| 135 | this->surface.reset(SkSurface::NewRaster(info)); |
| 136 | if (!this->surface.get()) { |
| 137 | return false; |
| 138 | } |
| 139 | } |
| 140 | return true; |
| 141 | } |
| 142 | bool Target::capturePixels(SkBitmap* bmp) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 143 | SkCanvas* canvas = this->getCanvas(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 144 | if (!canvas) { |
| 145 | return false; |
| 146 | } |
| 147 | bmp->setInfo(canvas->imageInfo()); |
| 148 | if (!canvas->readPixels(bmp, 0, 0)) { |
| 149 | SkDebugf("Can't read canvas pixels.\n"); |
| 150 | return false; |
| 151 | } |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | #if SK_SUPPORT_GPU |
| 156 | struct GPUTarget : public Target { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 157 | explicit GPUTarget(const Config& c) : Target(c), gl(nullptr) { } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 158 | SkGLContext* gl; |
| 159 | |
| 160 | void setup() override { |
| 161 | this->gl->makeCurrent(); |
| 162 | // Make sure we're done with whatever came before. |
| 163 | SK_GL(*this->gl, Finish()); |
| 164 | } |
| 165 | void endTiming() override { |
| 166 | if (this->gl) { |
| 167 | SK_GL(*this->gl, Flush()); |
joshualitt | 01836ad | 2016-01-20 13:09:12 -0800 | [diff] [blame] | 168 | this->gl->waitOnSyncOrSwap(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | void fence() override { |
| 172 | SK_GL(*this->gl, Finish()); |
| 173 | } |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 174 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 175 | bool needsFrameTiming(int* maxFrameLag) const override { |
| 176 | if (!this->gl->getMaxGpuFrameLag(maxFrameLag)) { |
| 177 | // Frame lag is unknown. |
| 178 | *maxFrameLag = FLAGS_gpuFrameLag; |
| 179 | } |
| 180 | return true; |
| 181 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 182 | bool init(SkImageInfo info, Benchmark* bench) override { |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 183 | uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : |
| 184 | 0; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 185 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 186 | this->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(this->config.ctxType, |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 187 | this->config.ctxOptions), |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 188 | SkSurface::kNo_Budgeted, info, |
| 189 | this->config.samples, &props)); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 190 | this->gl = gGrFactory->getContextInfo(this->config.ctxType, |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 191 | this->config.ctxOptions).fGLContext; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 192 | if (!this->surface.get()) { |
| 193 | return false; |
| 194 | } |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 195 | if (!this->gl->fenceSyncSupport()) { |
| 196 | SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. " |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 197 | "Timings might not be accurate.\n", this->config.name.c_str()); |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 198 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 199 | return true; |
| 200 | } |
| 201 | void fillOptions(ResultsWriter* log) override { |
| 202 | const GrGLubyte* version; |
| 203 | SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION)); |
| 204 | log->configOption("GL_VERSION", (const char*)(version)); |
| 205 | |
| 206 | SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER)); |
| 207 | log->configOption("GL_RENDERER", (const char*) version); |
| 208 | |
| 209 | SK_GL_RET(*this->gl, version, GetString(GR_GL_VENDOR)); |
| 210 | log->configOption("GL_VENDOR", (const char*) version); |
| 211 | |
| 212 | SK_GL_RET(*this->gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
| 213 | log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); |
| 214 | } |
| 215 | }; |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 216 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 217 | #endif |
| 218 | |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 219 | static double time(int loops, Benchmark* bench, Target* target) { |
| 220 | SkCanvas* canvas = target->getCanvas(); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 221 | if (canvas) { |
| 222 | canvas->clear(SK_ColorWHITE); |
| 223 | } |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 224 | bench->preDraw(canvas); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 225 | double start = now_ms(); |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 226 | canvas = target->beginTiming(canvas); |
| 227 | bench->draw(loops, canvas); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 228 | if (canvas) { |
| 229 | canvas->flush(); |
| 230 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 231 | target->endTiming(); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 232 | double elapsed = now_ms() - start; |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 233 | bench->postDraw(canvas); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 234 | return elapsed; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 235 | } |
| 236 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 237 | static double estimate_timer_overhead() { |
| 238 | double overhead = 0; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 239 | for (int i = 0; i < FLAGS_overheadLoops; i++) { |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 240 | double start = now_ms(); |
| 241 | overhead += now_ms() - start; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 242 | } |
| 243 | return overhead / FLAGS_overheadLoops; |
| 244 | } |
| 245 | |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 246 | static int detect_forever_loops(int loops) { |
| 247 | // look for a magic run-forever value |
| 248 | if (loops < 0) { |
| 249 | loops = SK_MaxS32; |
| 250 | } |
| 251 | return loops; |
| 252 | } |
| 253 | |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 254 | static int clamp_loops(int loops) { |
| 255 | if (loops < 1) { |
mtklein | 527930f | 2014-11-06 08:04:34 -0800 | [diff] [blame] | 256 | SkDebugf("ERROR: clamping loops from %d to 1. " |
| 257 | "There's probably something wrong with the bench.\n", loops); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 258 | return 1; |
| 259 | } |
| 260 | if (loops > FLAGS_maxLoops) { |
| 261 | SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops); |
| 262 | return FLAGS_maxLoops; |
| 263 | } |
| 264 | return loops; |
| 265 | } |
| 266 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 267 | static bool write_canvas_png(Target* target, const SkString& filename) { |
| 268 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 269 | if (filename.isEmpty()) { |
| 270 | return false; |
| 271 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 272 | if (target->getCanvas() && |
| 273 | kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 274 | return false; |
| 275 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 276 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 277 | SkBitmap bmp; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 278 | |
| 279 | if (!target->capturePixels(&bmp)) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 280 | return false; |
| 281 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 282 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 283 | SkString dir = SkOSPath::Dirname(filename.c_str()); |
| 284 | if (!sk_mkdir(dir.c_str())) { |
| 285 | SkDebugf("Can't make dir %s.\n", dir.c_str()); |
| 286 | return false; |
| 287 | } |
| 288 | SkFILEWStream stream(filename.c_str()); |
| 289 | if (!stream.isValid()) { |
| 290 | SkDebugf("Can't write %s.\n", filename.c_str()); |
| 291 | return false; |
| 292 | } |
| 293 | if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) { |
| 294 | SkDebugf("Can't encode a PNG.\n"); |
| 295 | return false; |
| 296 | } |
| 297 | return true; |
| 298 | } |
| 299 | |
| 300 | static int kFailedLoops = -2; |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 301 | static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 302 | // 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] | 303 | double bench_plus_overhead = 0.0; |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 304 | int round = 0; |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 305 | int loops = bench->calculateLoops(FLAGS_loops); |
| 306 | if (kAutoTuneLoops == loops) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 307 | while (bench_plus_overhead < overhead) { |
| 308 | if (round++ == FLAGS_maxCalibrationAttempts) { |
| 309 | SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n", |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 310 | bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead)); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 311 | return kFailedLoops; |
| 312 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 313 | bench_plus_overhead = time(1, bench, target); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 314 | } |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 315 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 316 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 317 | // 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] | 318 | // We'll pick N to make timer overhead negligible: |
| 319 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 320 | // overhead |
| 321 | // ------------------------- < FLAGS_overheadGoal |
| 322 | // overhead + N * Bench Time |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 323 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 324 | // where bench_plus_overhead ≈ overhead + Bench Time. |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 325 | // |
| 326 | // Doing some math, we get: |
| 327 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 328 | // (overhead / FLAGS_overheadGoal) - overhead |
| 329 | // ------------------------------------------ < N |
| 330 | // bench_plus_overhead - overhead) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 331 | // |
| 332 | // Luckily, this also works well in practice. :) |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 333 | if (kAutoTuneLoops == loops) { |
| 334 | const double numer = overhead / FLAGS_overheadGoal - overhead; |
| 335 | const double denom = bench_plus_overhead - overhead; |
| 336 | loops = (int)ceil(numer / denom); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 337 | loops = clamp_loops(loops); |
| 338 | } else { |
| 339 | loops = detect_forever_loops(loops); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 340 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 341 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 342 | return loops; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 343 | } |
| 344 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 345 | static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 346 | // 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] | 347 | int loops = bench->calculateLoops(FLAGS_loops); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 348 | if (kAutoTuneLoops == loops) { |
| 349 | loops = 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 350 | double elapsed = 0; |
| 351 | do { |
mtklein | 527930f | 2014-11-06 08:04:34 -0800 | [diff] [blame] | 352 | if (1<<30 == loops) { |
| 353 | // We're about to wrap. Something's wrong with the bench. |
| 354 | loops = 0; |
| 355 | break; |
| 356 | } |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 357 | loops *= 2; |
| 358 | // 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] | 359 | // _this_ round, not still timing last round. |
| 360 | for (int i = 0; i < maxGpuFrameLag; i++) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 361 | elapsed = time(loops, bench, target); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 362 | } |
| 363 | } while (elapsed < FLAGS_gpuMs); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 364 | |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 365 | // We've overshot at least a little. Scale back linearly. |
| 366 | loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 367 | loops = clamp_loops(loops); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 368 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 369 | // Make sure we're not still timing our calibration. |
| 370 | target->fence(); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 371 | } else { |
| 372 | loops = detect_forever_loops(loops); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 373 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 374 | |
| 375 | // Pretty much the same deal as the calibration: do some warmup to make |
| 376 | // sure we're timing steady-state pipelined frames. |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 377 | for (int i = 0; i < maxGpuFrameLag - 1; i++) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 378 | time(loops, bench, target); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 379 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 380 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 381 | return loops; |
| 382 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 383 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 384 | #if SK_SUPPORT_GPU |
| 385 | #define kBogusGLContextType GrContextFactory::kNative_GLContextType |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 386 | #define kBogusGLContextOptions GrContextFactory::kNone_GLContextOptions |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 387 | #else |
| 388 | #define kBogusGLContextType 0 |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 389 | #define kBogusGLContextOptions 0 |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 390 | #endif |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 391 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 392 | static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) { |
| 393 | |
| 394 | #if SK_SUPPORT_GPU |
| 395 | if (const auto* gpuConfig = config->asConfigGpu()) { |
| 396 | if (!FLAGS_gpu) |
| 397 | return; |
| 398 | |
| 399 | const auto ctxOptions = gpuConfig->getUseNVPR() ? GrContextFactory::kEnableNVPR_GLContextOptions |
| 400 | : GrContextFactory::kNone_GLContextOptions; |
| 401 | const auto ctxType = gpuConfig->getContextType(); |
| 402 | const auto sampleCount = gpuConfig->getSamples(); |
| 403 | |
| 404 | if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOptions)) { |
| 405 | const auto maxSampleCount = ctx->caps()->maxSampleCount(); |
| 406 | if (sampleCount > ctx->caps()->maxSampleCount()) { |
| 407 | SkDebugf("Configuration sample count %d exceeds maximum %d.\n", |
| 408 | sampleCount, maxSampleCount); |
| 409 | return; |
| 410 | } |
| 411 | } else { |
| 412 | SkDebugf("No context was available matching config type and options.\n"); |
| 413 | return; |
| 414 | } |
| 415 | |
| 416 | Config target = { |
| 417 | config->getTag(), |
| 418 | Benchmark::kGPU_Backend, |
| 419 | kN32_SkColorType, |
| 420 | kPremul_SkAlphaType, |
| 421 | sampleCount, |
| 422 | ctxType, |
| 423 | ctxOptions, |
| 424 | false }; |
| 425 | |
| 426 | configs->push_back(target); |
| 427 | return; |
| 428 | } |
| 429 | #endif |
| 430 | |
| 431 | #define CPU_CONFIG(name, backend, color, alpha) \ |
| 432 | if (config->getTag().equals(#name)) { \ |
| 433 | Config config = { SkString(#name), Benchmark::backend, color, alpha, 0, \ |
| 434 | kBogusGLContextType, kBogusGLContextOptions, \ |
| 435 | false }; \ |
| 436 | configs->push_back(config); \ |
| 437 | return; \ |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 438 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 439 | |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 440 | if (FLAGS_cpu) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 441 | CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kUnpremul_SkAlphaType) |
| 442 | CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType) |
| 443 | CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType) |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 444 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 445 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 446 | #undef CPU_CONFIG |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 447 | |
| 448 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
djsollen | 817c72a | 2016-01-28 13:57:02 -0800 | [diff] [blame] | 449 | if (config->getTag().equals("hwui")) { |
| 450 | Config config = { SkString("hwui"), Benchmark::kHWUI_Backend, kRGBA_8888_SkColorType, |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 451 | kPremul_SkAlphaType, 0, kBogusGLContextType, kBogusGLContextOptions, |
| 452 | false }; |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 453 | configs->push_back(config); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 454 | } |
| 455 | #endif |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 456 | } |
| 457 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 458 | // Append all configs that are enabled and supported. |
| 459 | void create_configs(SkTArray<Config>* configs) { |
| 460 | SkCommandLineConfigArray array; |
| 461 | ParseConfigs(FLAGS_config, &array); |
| 462 | for (int i = 0; i < array.count(); ++i) { |
| 463 | create_config(array[i], configs); |
| 464 | } |
| 465 | } |
| 466 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 467 | // If bench is enabled for config, returns a Target* for it, otherwise nullptr. |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 468 | static Target* is_enabled(Benchmark* bench, const Config& config) { |
| 469 | if (!bench->isSuitableFor(config.backend)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 470 | return nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 471 | } |
| 472 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 473 | SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY, |
| 474 | config.color, config.alpha); |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 475 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 476 | Target* target = nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 477 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 478 | switch (config.backend) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 479 | #if SK_SUPPORT_GPU |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 480 | case Benchmark::kGPU_Backend: |
| 481 | target = new GPUTarget(config); |
| 482 | break; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 483 | #endif |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 484 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 485 | case Benchmark::kHWUI_Backend: |
| 486 | target = new HWUITarget(config, bench); |
| 487 | break; |
| 488 | #endif |
| 489 | default: |
| 490 | target = new Target(config); |
| 491 | break; |
| 492 | } |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 493 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 494 | if (!target->init(info, bench)) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 495 | delete target; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 496 | return nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 497 | } |
| 498 | return target; |
| 499 | } |
| 500 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 501 | static bool valid_brd_bench(SkData* encoded, SkBitmapRegionDecoder::Strategy strategy, |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 502 | SkColorType colorType, uint32_t sampleSize, uint32_t minOutputSize, int* width, |
| 503 | int* height) { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 504 | SkAutoTDelete<SkBitmapRegionDecoder> brd( |
| 505 | SkBitmapRegionDecoder::Create(encoded, strategy)); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 506 | if (nullptr == brd.get()) { |
| 507 | // This is indicates that subset decoding is not supported for a particular image format. |
| 508 | return false; |
| 509 | } |
| 510 | |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 511 | SkBitmap bitmap; |
| 512 | if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, brd->width(), brd->height()), |
| 513 | 1, colorType, false)) { |
| 514 | return false; |
| 515 | } |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 516 | |
| 517 | if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize > |
| 518 | (uint32_t) brd->height()) { |
| 519 | // This indicates that the image is not large enough to decode a |
| 520 | // minOutputSize x minOutputSize subset at the given sampleSize. |
| 521 | return false; |
| 522 | } |
| 523 | |
| 524 | // Set the image width and height. The calling code will use this to choose subsets to decode. |
| 525 | *width = brd->width(); |
| 526 | *height = brd->height(); |
| 527 | return true; |
| 528 | } |
| 529 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 530 | static void cleanup_run(Target* target) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 531 | delete target; |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 532 | #if SK_SUPPORT_GPU |
| 533 | if (FLAGS_abandonGpuContext) { |
| 534 | gGrFactory->abandonContexts(); |
| 535 | } |
| 536 | if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { |
| 537 | gGrFactory->destroyContexts(); |
| 538 | } |
| 539 | #endif |
| 540 | } |
| 541 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 542 | class BenchmarkStream { |
| 543 | public: |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 544 | BenchmarkStream() : fBenches(BenchRegistry::Head()) |
| 545 | , fGMs(skiagm::GMRegistry::Head()) |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 546 | , fCurrentRecording(0) |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 547 | , fCurrentScale(0) |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 548 | , fCurrentSKP(0) |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 549 | , fCurrentUseMPD(0) |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 550 | , fCurrentCodec(0) |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 551 | , fCurrentAndroidCodec(0) |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 552 | , fCurrentBRDImage(0) |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 553 | , fCurrentColorType(0) |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 554 | , fCurrentAlphaType(0) |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 555 | , fCurrentSubsetType(0) |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 556 | , fCurrentBRDStrategy(0) |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 557 | , fCurrentSampleSize(0) |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 558 | , fCurrentAnimSKP(0) { |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 559 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 560 | if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
| 561 | fSKPs.push_back() = FLAGS_skps[i]; |
| 562 | } else { |
| 563 | SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
| 564 | SkString path; |
| 565 | while (it.next(&path)) { |
| 566 | fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); |
| 567 | } |
| 568 | } |
| 569 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 570 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 571 | if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
| 572 | &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) { |
| 573 | SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]); |
| 574 | exit(1); |
| 575 | } |
| 576 | |
| 577 | for (int i = 0; i < FLAGS_scales.count(); i++) { |
| 578 | if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { |
| 579 | SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]); |
| 580 | exit(1); |
| 581 | } |
| 582 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 583 | |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 584 | if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) { |
| 585 | 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] | 586 | exit(1); |
| 587 | } |
| 588 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 589 | if (FLAGS_mpd) { |
| 590 | fUseMPDs.push_back() = true; |
| 591 | } |
mtklein | c751ecb | 2015-06-15 08:56:38 -0700 | [diff] [blame] | 592 | fUseMPDs.push_back() = false; |
mtklein | 95553d9 | 2015-03-12 08:24:21 -0700 | [diff] [blame] | 593 | |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 594 | // Prepare the images for decoding |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 595 | if (!CollectImages(&fImages)) { |
| 596 | exit(1); |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 597 | } |
mtklein | 95553d9 | 2015-03-12 08:24:21 -0700 | [diff] [blame] | 598 | |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 599 | // Choose the candidate color types for image decoding |
| 600 | const SkColorType colorTypes[] = |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 601 | { kN32_SkColorType, |
| 602 | kRGB_565_SkColorType, |
| 603 | kAlpha_8_SkColorType, |
| 604 | kIndex_8_SkColorType, |
| 605 | kGray_8_SkColorType }; |
msarett | 74deb98 | 2015-10-20 16:45:56 -0700 | [diff] [blame] | 606 | fColorTypes.reset(colorTypes, SK_ARRAY_COUNT(colorTypes)); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 607 | } |
| 608 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 609 | static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { |
| 610 | // Not strictly necessary, as it will be checked again later, |
| 611 | // 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] | 612 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 613 | return false; |
| 614 | } |
| 615 | |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 616 | SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 617 | if (stream.get() == nullptr) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 618 | SkDebugf("Could not read %s.\n", path); |
| 619 | return false; |
| 620 | } |
| 621 | |
mtklein | 57f27bd | 2015-02-09 11:58:41 -0800 | [diff] [blame] | 622 | pic->reset(SkPicture::CreateFromStream(stream.get())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 623 | if (pic->get() == nullptr) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 624 | SkDebugf("Could not read %s as an SkPicture.\n", path); |
| 625 | return false; |
| 626 | } |
| 627 | return true; |
| 628 | } |
| 629 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 630 | Benchmark* next() { |
mtklein | 65dfd2f | 2016-02-03 10:40:54 -0800 | [diff] [blame] | 631 | SkAutoTDelete<Benchmark> bench; |
| 632 | do { |
| 633 | bench.reset(this->rawNext()); |
| 634 | if (!bench) { |
| 635 | return nullptr; |
| 636 | } |
| 637 | } while(SkCommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) || |
| 638 | SkCommandLineFlags::ShouldSkip(FLAGS_benchType, fBenchType)); |
| 639 | return bench.detach(); |
| 640 | } |
| 641 | |
| 642 | Benchmark* rawNext() { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 643 | if (fBenches) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 644 | Benchmark* bench = fBenches->factory()(nullptr); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 645 | fBenches = fBenches->next(); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 646 | fSourceType = "bench"; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 647 | fBenchType = "micro"; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 648 | return bench; |
| 649 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 650 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 651 | while (fGMs) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 652 | SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 653 | fGMs = fGMs->next(); |
mtklein | cf5d9c9 | 2015-01-23 10:31:45 -0800 | [diff] [blame] | 654 | if (gm->runAsBench()) { |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 655 | fSourceType = "gm"; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 656 | fBenchType = "micro"; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 657 | return new GMBench(gm.detach()); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 660 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 661 | // First add all .skps as RecordingBenches. |
| 662 | while (fCurrentRecording < fSKPs.count()) { |
| 663 | const SkString& path = fSKPs[fCurrentRecording++]; |
| 664 | SkAutoTUnref<SkPicture> pic; |
| 665 | if (!ReadPicture(path.c_str(), &pic)) { |
| 666 | continue; |
| 667 | } |
| 668 | SkString name = SkOSPath::Basename(path.c_str()); |
| 669 | fSourceType = "skp"; |
| 670 | fBenchType = "recording"; |
bsalomon | 0aa5cea | 2014-12-15 09:13:35 -0800 | [diff] [blame] | 671 | fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic)); |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 672 | fSKPOps = pic->approximateOpCount(); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 673 | return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | // Then once each for each scale as SKPBenches (playback). |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 677 | while (fCurrentScale < fScales.count()) { |
| 678 | while (fCurrentSKP < fSKPs.count()) { |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 679 | const SkString& path = fSKPs[fCurrentSKP]; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 680 | SkAutoTUnref<SkPicture> pic; |
| 681 | if (!ReadPicture(path.c_str(), &pic)) { |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 682 | fCurrentSKP++; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 683 | continue; |
| 684 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 685 | |
| 686 | while (fCurrentUseMPD < fUseMPDs.count()) { |
| 687 | if (FLAGS_bbh) { |
| 688 | // The SKP we read off disk doesn't have a BBH. Re-record so it grows one. |
| 689 | SkRTreeFactory factory; |
| 690 | SkPictureRecorder recorder; |
| 691 | static const int kFlags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; |
| 692 | pic->playback(recorder.beginRecording(pic->cullRect().width(), |
| 693 | pic->cullRect().height(), |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 694 | &factory, |
robertphillips | e451c4d | 2014-12-09 10:28:00 -0800 | [diff] [blame] | 695 | fUseMPDs[fCurrentUseMPD] ? kFlags : 0)); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 696 | pic.reset(recorder.endRecording()); |
| 697 | } |
| 698 | SkString name = SkOSPath::Basename(path.c_str()); |
| 699 | fSourceType = "skp"; |
| 700 | fBenchType = "playback"; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 701 | return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale], |
| 702 | fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP); |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 703 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 704 | fCurrentUseMPD = 0; |
| 705 | fCurrentSKP++; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 706 | } |
| 707 | fCurrentSKP = 0; |
| 708 | fCurrentScale++; |
| 709 | } |
| 710 | |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 711 | // Now loop over each skp again if we have an animation |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 712 | if (fZoomMax != 1.0f && fZoomPeriodMs > 0) { |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 713 | while (fCurrentAnimSKP < fSKPs.count()) { |
| 714 | const SkString& path = fSKPs[fCurrentAnimSKP]; |
| 715 | SkAutoTUnref<SkPicture> pic; |
| 716 | if (!ReadPicture(path.c_str(), &pic)) { |
| 717 | fCurrentAnimSKP++; |
| 718 | continue; |
| 719 | } |
| 720 | |
| 721 | fCurrentAnimSKP++; |
| 722 | SkString name = SkOSPath::Basename(path.c_str()); |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 723 | SkAutoTUnref<SKPAnimationBench::Animation> animation( |
| 724 | SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriodMs)); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 725 | return new SKPAnimationBench(name.c_str(), pic.get(), fClip, animation, |
| 726 | FLAGS_loopSKP); |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 730 | for (; fCurrentCodec < fImages.count(); fCurrentCodec++) { |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 731 | fSourceType = "image"; |
| 732 | fBenchType = "skcodec"; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 733 | const SkString& path = fImages[fCurrentCodec]; |
mtklein | 6f0ff91 | 2016-01-11 09:04:21 -0800 | [diff] [blame] | 734 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
| 735 | continue; |
| 736 | } |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 737 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 738 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 739 | if (!codec) { |
| 740 | // Nothing to time. |
msarett | 9d9725c | 2015-04-24 11:41:55 -0700 | [diff] [blame] | 741 | SkDebugf("Cannot find codec for %s\n", path.c_str()); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 742 | continue; |
| 743 | } |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 744 | |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 745 | while (fCurrentColorType < fColorTypes.count()) { |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 746 | const SkColorType colorType = fColorTypes[fCurrentColorType]; |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 747 | |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 748 | SkAlphaType alphaType = codec->getInfo().alphaType(); |
| 749 | switch (alphaType) { |
| 750 | case kOpaque_SkAlphaType: |
| 751 | // We only need to test one alpha type (opaque). |
| 752 | fCurrentColorType++; |
| 753 | break; |
| 754 | case kUnpremul_SkAlphaType: |
| 755 | case kPremul_SkAlphaType: |
| 756 | if (0 == fCurrentAlphaType) { |
| 757 | // Test unpremul first. |
| 758 | alphaType = kUnpremul_SkAlphaType; |
| 759 | fCurrentAlphaType++; |
| 760 | } else { |
| 761 | // Test premul. |
| 762 | alphaType = kPremul_SkAlphaType; |
| 763 | fCurrentAlphaType = 0; |
| 764 | fCurrentColorType++; |
| 765 | } |
| 766 | break; |
| 767 | default: |
| 768 | SkASSERT(false); |
| 769 | fCurrentColorType++; |
| 770 | break; |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 771 | } |
| 772 | |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 773 | // Make sure we can decode to this color type and alpha type. |
| 774 | SkImageInfo info = |
| 775 | codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType); |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 776 | const size_t rowBytes = info.minRowBytes(); |
| 777 | SkAutoMalloc storage(info.getSafeSize(rowBytes)); |
| 778 | |
| 779 | // Used if fCurrentColorType is kIndex_8_SkColorType |
| 780 | int colorCount = 256; |
| 781 | SkPMColor colors[256]; |
| 782 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 783 | const SkCodec::Result result = codec->getPixels( |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 784 | info, storage.get(), rowBytes, nullptr, colors, |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 785 | &colorCount); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 786 | switch (result) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 787 | case SkCodec::kSuccess: |
| 788 | case SkCodec::kIncompleteInput: |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 789 | return new CodecBench(SkOSPath::Basename(path.c_str()), |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 790 | encoded, colorType, alphaType); |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 791 | case SkCodec::kInvalidConversion: |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 792 | // This is okay. Not all conversions are valid. |
| 793 | break; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 794 | default: |
| 795 | // This represents some sort of failure. |
| 796 | SkASSERT(false); |
| 797 | break; |
| 798 | } |
| 799 | } |
| 800 | fCurrentColorType = 0; |
| 801 | } |
| 802 | |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 803 | // Run AndroidCodecBenches |
| 804 | const int sampleSizes[] = { 2, 4, 8 }; |
| 805 | for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) { |
| 806 | fSourceType = "image"; |
| 807 | fBenchType = "skandroidcodec"; |
| 808 | |
| 809 | const SkString& path = fImages[fCurrentAndroidCodec]; |
| 810 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
| 811 | continue; |
| 812 | } |
| 813 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 814 | SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); |
| 815 | if (!codec) { |
| 816 | // Nothing to time. |
| 817 | SkDebugf("Cannot find codec for %s\n", path.c_str()); |
| 818 | continue; |
| 819 | } |
| 820 | |
| 821 | while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) { |
| 822 | int sampleSize = sampleSizes[fCurrentSampleSize]; |
| 823 | fCurrentSampleSize++; |
| 824 | if (10 * sampleSize > SkTMin(codec->getInfo().width(), codec->getInfo().height())) { |
| 825 | // Avoid benchmarking scaled decodes of already small images. |
| 826 | break; |
| 827 | } |
| 828 | |
| 829 | return new AndroidCodecBench(SkOSPath::Basename(path.c_str()), encoded, sampleSize); |
| 830 | } |
| 831 | fCurrentSampleSize = 0; |
| 832 | } |
| 833 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 834 | // Run the BRDBenches |
| 835 | // We will benchmark multiple BRD strategies. |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 836 | static const struct { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 837 | SkBitmapRegionDecoder::Strategy fStrategy; |
msarett | 0459c94 | 2015-11-10 14:52:13 -0800 | [diff] [blame] | 838 | const char* fName; |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 839 | } strategies[] = { |
msarett | 0459c94 | 2015-11-10 14:52:13 -0800 | [diff] [blame] | 840 | { SkBitmapRegionDecoder::kCanvas_Strategy, "BRD_canvas" }, |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 841 | { SkBitmapRegionDecoder::kAndroidCodec_Strategy, "BRD_android_codec" }, |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 842 | }; |
| 843 | |
| 844 | // We intend to create benchmarks that model the use cases in |
| 845 | // android/libraries/social/tiledimage. In this library, an image is decoded in 512x512 |
| 846 | // tiles. The image can be translated freely, so the location of a tile may be anywhere in |
| 847 | // the image. For that reason, we will benchmark decodes in five representative locations |
| 848 | // in the image. Additionally, this use case utilizes power of two scaling, so we will |
| 849 | // test on power of two sample sizes. The output tile is always 512x512, so, when a |
| 850 | // sampleSize is used, the size of the subset that is decoded is always |
| 851 | // (sampleSize*512)x(sampleSize*512). |
| 852 | // 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] | 853 | // All use cases we are aware of only scale by powers of two. |
| 854 | // PNG decodes use the indicated sampling strategy regardless of the sample size, so |
| 855 | // these tests are sufficient to provide good coverage of our scaling options. |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 856 | const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 }; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 857 | const uint32_t minOutputSize = 512; |
mtklein | 6f0ff91 | 2016-01-11 09:04:21 -0800 | [diff] [blame] | 858 | for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) { |
| 859 | const SkString& path = fImages[fCurrentBRDImage]; |
| 860 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
| 861 | continue; |
| 862 | } |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 863 | while (fCurrentBRDStrategy < (int) SK_ARRAY_COUNT(strategies)) { |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 864 | fSourceType = "image"; |
| 865 | fBenchType = strategies[fCurrentBRDStrategy].fName; |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 866 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 867 | const SkBitmapRegionDecoder::Strategy strategy = |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 868 | strategies[fCurrentBRDStrategy].fStrategy; |
| 869 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 870 | while (fCurrentColorType < fColorTypes.count()) { |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 871 | while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) { |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 872 | while (fCurrentSubsetType <= kLastSingle_SubsetType) { |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 873 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 874 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 875 | const SkColorType colorType = fColorTypes[fCurrentColorType]; |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 876 | uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize]; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 877 | int currentSubsetType = fCurrentSubsetType++; |
| 878 | |
| 879 | int width = 0; |
| 880 | int height = 0; |
| 881 | if (!valid_brd_bench(encoded.get(), strategy, colorType, sampleSize, |
| 882 | minOutputSize, &width, &height)) { |
| 883 | break; |
| 884 | } |
| 885 | |
| 886 | SkString basename = SkOSPath::Basename(path.c_str()); |
| 887 | SkIRect subset; |
| 888 | const uint32_t subsetSize = sampleSize * minOutputSize; |
| 889 | switch (currentSubsetType) { |
| 890 | case kTopLeft_SubsetType: |
| 891 | basename.append("_TopLeft"); |
| 892 | subset = SkIRect::MakeXYWH(0, 0, subsetSize, subsetSize); |
| 893 | break; |
| 894 | case kTopRight_SubsetType: |
| 895 | basename.append("_TopRight"); |
| 896 | subset = SkIRect::MakeXYWH(width - subsetSize, 0, subsetSize, |
| 897 | subsetSize); |
| 898 | break; |
| 899 | case kMiddle_SubsetType: |
| 900 | basename.append("_Middle"); |
| 901 | subset = SkIRect::MakeXYWH((width - subsetSize) / 2, |
| 902 | (height - subsetSize) / 2, subsetSize, subsetSize); |
| 903 | break; |
| 904 | case kBottomLeft_SubsetType: |
| 905 | basename.append("_BottomLeft"); |
| 906 | subset = SkIRect::MakeXYWH(0, height - subsetSize, subsetSize, |
| 907 | subsetSize); |
| 908 | break; |
| 909 | case kBottomRight_SubsetType: |
| 910 | basename.append("_BottomRight"); |
| 911 | subset = SkIRect::MakeXYWH(width - subsetSize, |
| 912 | height - subsetSize, subsetSize, subsetSize); |
| 913 | break; |
| 914 | default: |
| 915 | SkASSERT(false); |
| 916 | } |
| 917 | |
| 918 | return new BitmapRegionDecoderBench(basename.c_str(), encoded.get(), |
| 919 | strategy, colorType, sampleSize, subset); |
| 920 | } |
| 921 | fCurrentSubsetType = 0; |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 922 | fCurrentSampleSize++; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 923 | } |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 924 | fCurrentSampleSize = 0; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 925 | fCurrentColorType++; |
| 926 | } |
| 927 | fCurrentColorType = 0; |
| 928 | fCurrentBRDStrategy++; |
| 929 | } |
| 930 | fCurrentBRDStrategy = 0; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 931 | } |
| 932 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 933 | return nullptr; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 934 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 935 | |
| 936 | void fillCurrentOptions(ResultsWriter* log) const { |
| 937 | log->configOption("source_type", fSourceType); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 938 | log->configOption("bench_type", fBenchType); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 939 | if (0 == strcmp(fSourceType, "skp")) { |
| 940 | log->configOption("clip", |
| 941 | SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
| 942 | fClip.fRight, fClip.fBottom).c_str()); |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 943 | SkASSERT_RELEASE(fCurrentScale < fScales.count()); // debugging paranoia |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 944 | log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str()); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 945 | if (fCurrentUseMPD > 0) { |
| 946 | SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
| 947 | log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false"); |
| 948 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 949 | } |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 950 | if (0 == strcmp(fBenchType, "recording")) { |
| 951 | log->metric("bytes", fSKPBytes); |
| 952 | log->metric("ops", fSKPOps); |
| 953 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 954 | } |
| 955 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 956 | private: |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 957 | enum SubsetType { |
| 958 | kTopLeft_SubsetType = 0, |
| 959 | kTopRight_SubsetType = 1, |
msarett | ab80e35 | 2015-06-17 10:28:22 -0700 | [diff] [blame] | 960 | kMiddle_SubsetType = 2, |
| 961 | kBottomLeft_SubsetType = 3, |
| 962 | kBottomRight_SubsetType = 4, |
| 963 | kTranslate_SubsetType = 5, |
| 964 | kZoom_SubsetType = 6, |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 965 | kLast_SubsetType = kZoom_SubsetType, |
| 966 | kLastSingle_SubsetType = kBottomRight_SubsetType, |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 967 | }; |
| 968 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 969 | const BenchRegistry* fBenches; |
| 970 | const skiagm::GMRegistry* fGMs; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 971 | SkIRect fClip; |
| 972 | SkTArray<SkScalar> fScales; |
| 973 | SkTArray<SkString> fSKPs; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 974 | SkTArray<bool> fUseMPDs; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 975 | SkTArray<SkString> fImages; |
msarett | 74deb98 | 2015-10-20 16:45:56 -0700 | [diff] [blame] | 976 | SkTArray<SkColorType, true> fColorTypes; |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 977 | SkScalar fZoomMax; |
| 978 | double fZoomPeriodMs; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 979 | |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 980 | double fSKPBytes, fSKPOps; |
| 981 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 982 | const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
| 983 | const char* fBenchType; // How we bench it: micro, recording, playback, ... |
| 984 | int fCurrentRecording; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 985 | int fCurrentScale; |
| 986 | int fCurrentSKP; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 987 | int fCurrentUseMPD; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 988 | int fCurrentCodec; |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 989 | int fCurrentAndroidCodec; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 990 | int fCurrentBRDImage; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 991 | int fCurrentColorType; |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 992 | int fCurrentAlphaType; |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 993 | int fCurrentSubsetType; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 994 | int fCurrentBRDStrategy; |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 995 | int fCurrentSampleSize; |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 996 | int fCurrentAnimSKP; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 997 | }; |
| 998 | |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 999 | // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung. |
| 1000 | // This prints something every once in a while so that it knows we're still working. |
| 1001 | static void start_keepalive() { |
| 1002 | struct Loop { |
| 1003 | static void forever(void*) { |
| 1004 | for (;;) { |
| 1005 | static const int kSec = 1200; |
| 1006 | #if defined(SK_BUILD_FOR_WIN) |
| 1007 | Sleep(kSec * 1000); |
| 1008 | #else |
| 1009 | sleep(kSec); |
| 1010 | #endif |
| 1011 | SkDebugf("\nBenchmarks still running...\n"); |
| 1012 | } |
| 1013 | } |
| 1014 | }; |
| 1015 | static SkThread* intentionallyLeaked = new SkThread(Loop::forever); |
| 1016 | intentionallyLeaked->start(); |
| 1017 | } |
| 1018 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1019 | int nanobench_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1020 | int nanobench_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1021 | SetupCrashHandler(); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1022 | SkAutoGraphics ag; |
mtklein | cc29d26 | 2015-07-09 10:04:56 -0700 | [diff] [blame] | 1023 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1024 | |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 1025 | #if SK_SUPPORT_GPU |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 1026 | GrContextOptions grContextOpts; |
krajcevski | 12b3544 | 2014-08-13 12:06:26 -0700 | [diff] [blame] | 1027 | grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1028 | gGrFactory.reset(new GrContextFactory(grContextOpts)); |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 1029 | #endif |
| 1030 | |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 1031 | if (FLAGS_veryVerbose) { |
| 1032 | FLAGS_verbose = true; |
| 1033 | } |
| 1034 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1035 | if (kAutoTuneLoops != FLAGS_loops) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 1036 | FLAGS_samples = 1; |
| 1037 | FLAGS_gpuFrameLag = 0; |
| 1038 | } |
| 1039 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1040 | if (!FLAGS_writePath.isEmpty()) { |
| 1041 | SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]); |
| 1042 | if (!sk_mkdir(FLAGS_writePath[0])) { |
| 1043 | 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] | 1044 | FLAGS_writePath.set(0, nullptr); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1048 | SkAutoTDelete<ResultsWriter> log(new ResultsWriter); |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1049 | if (!FLAGS_outResultsFile.isEmpty()) { |
mtklein | 5352015 | 2016-01-20 09:53:59 -0800 | [diff] [blame] | 1050 | #if defined(SK_RELEASE) |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1051 | log.reset(new NanoJSONResultsWriter(FLAGS_outResultsFile[0])); |
mtklein | 5352015 | 2016-01-20 09:53:59 -0800 | [diff] [blame] | 1052 | #else |
| 1053 | SkDebugf("I'm ignoring --outResultsFile because this is a Debug build."); |
| 1054 | return 1; |
| 1055 | #endif |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1056 | } |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1057 | |
| 1058 | if (1 == FLAGS_properties.count() % 2) { |
| 1059 | SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n"); |
| 1060 | return 1; |
| 1061 | } |
| 1062 | for (int i = 1; i < FLAGS_properties.count(); i += 2) { |
| 1063 | log->property(FLAGS_properties[i-1], FLAGS_properties[i]); |
| 1064 | } |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 1065 | |
| 1066 | if (1 == FLAGS_key.count() % 2) { |
| 1067 | SkDebugf("ERROR: --key must be passed with an even number of arguments.\n"); |
| 1068 | return 1; |
| 1069 | } |
| 1070 | for (int i = 1; i < FLAGS_key.count(); i += 2) { |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1071 | log->key(FLAGS_key[i-1], FLAGS_key[i]); |
mtklein | 94e5156 | 2014-08-19 12:41:53 -0700 | [diff] [blame] | 1072 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1073 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1074 | const double overhead = estimate_timer_overhead(); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 1075 | SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead)); |
Mike Klein | 9129477 | 2014-07-16 19:59:32 -0400 | [diff] [blame] | 1076 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1077 | SkTArray<double> samples; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 1078 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1079 | if (kAutoTuneLoops != FLAGS_loops) { |
| 1080 | 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] | 1081 | } else if (FLAGS_quiet) { |
mtklein | 66cfcff | 2015-12-04 06:35:30 -0800 | [diff] [blame] | 1082 | SkDebugf("! -> high variance, ? -> moderate variance\n"); |
| 1083 | SkDebugf(" micros \tbench\n"); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1084 | } else if (FLAGS_ms) { |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1085 | SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1086 | } else { |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1087 | 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] | 1088 | FLAGS_samples, "samples"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 1091 | SkTArray<Config> configs; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 1092 | create_configs(&configs); |
| 1093 | |
joshualitt | 3ebd050 | 2016-02-09 07:18:08 -0800 | [diff] [blame] | 1094 | #ifdef THERMAL_MANAGER_SUPPORTED |
| 1095 | int tmEnabled, tmThreshold, tmSleepTimeMs, tmTimeoutMs; |
| 1096 | if (4 != sscanf(FLAGS_useThermalManager[0], "%d,%d,%d,%d", |
| 1097 | &tmEnabled, &tmThreshold, &tmSleepTimeMs, &tmTimeoutMs)) { |
| 1098 | SkDebugf("Can't parse %s from --useThermalManager.\n", FLAGS_useThermalManager[0]); |
| 1099 | exit(1); |
| 1100 | } |
| 1101 | ThermalManager tm(tmThreshold, tmSleepTimeMs, tmTimeoutMs); |
| 1102 | #endif |
| 1103 | |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 1104 | if (FLAGS_keepAlive) { |
| 1105 | start_keepalive(); |
| 1106 | } |
| 1107 | |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 1108 | int runs = 0; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1109 | BenchmarkStream benchStream; |
| 1110 | while (Benchmark* b = benchStream.next()) { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1111 | SkAutoTDelete<Benchmark> bench(b); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1112 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1113 | continue; |
| 1114 | } |
| 1115 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 1116 | if (!configs.empty()) { |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1117 | log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY); |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 1118 | bench->delayedSetup(); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 1119 | } |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1120 | for (int i = 0; i < configs.count(); ++i) { |
joshualitt | 3ebd050 | 2016-02-09 07:18:08 -0800 | [diff] [blame] | 1121 | #ifdef THERMAL_MANAGER_SUPPORTED |
| 1122 | if (tmEnabled && !tm.coolOffIfNecessary()) { |
| 1123 | SkDebugf("Could not cool off, timings will be throttled\n"); |
| 1124 | } |
| 1125 | #endif |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1126 | Target* target = is_enabled(b, configs[i]); |
| 1127 | if (!target) { |
| 1128 | continue; |
| 1129 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1130 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1131 | // During HWUI output this canvas may be nullptr. |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1132 | SkCanvas* canvas = target->getCanvas(); |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 1133 | const char* config = target->config.name.c_str(); |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1134 | |
brianosman | 7a5ada8 | 2016-02-08 13:49:12 -0800 | [diff] [blame] | 1135 | if (FLAGS_pre_log || FLAGS_dryRun) { |
benjaminwagner | 8d61f0d | 2016-01-25 13:02:40 -0800 | [diff] [blame] | 1136 | SkDebugf("Running %s\t%s\n" |
| 1137 | , bench->getUniqueName() |
| 1138 | , config); |
brianosman | 7a5ada8 | 2016-02-08 13:49:12 -0800 | [diff] [blame] | 1139 | if (FLAGS_dryRun) { |
| 1140 | continue; |
| 1141 | } |
benjaminwagner | 8d61f0d | 2016-01-25 13:02:40 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1144 | target->setup(); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1145 | bench->perCanvasPreDraw(canvas); |
| 1146 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1147 | int maxFrameLag; |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 1148 | int loops = target->needsFrameTiming(&maxFrameLag) |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1149 | ? setup_gpu_bench(target, bench.get(), maxFrameLag) |
| 1150 | : setup_cpu_bench(overhead, target, bench.get()); |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1151 | |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1152 | if (FLAGS_ms) { |
| 1153 | samples.reset(); |
| 1154 | auto stop = now_ms() + FLAGS_ms; |
| 1155 | do { |
| 1156 | samples.push_back(time(loops, bench, target) / loops); |
| 1157 | } while (now_ms() < stop); |
| 1158 | } else { |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1159 | samples.reset(FLAGS_samples); |
| 1160 | for (int s = 0; s < FLAGS_samples; s++) { |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1161 | samples[s] = time(loops, bench, target) / loops; |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1162 | } |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1163 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1164 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1165 | #if SK_SUPPORT_GPU |
| 1166 | SkTArray<SkString> keys; |
| 1167 | SkTArray<double> values; |
| 1168 | bool gpuStatsDump = FLAGS_gpuStatsDump && Benchmark::kGPU_Backend == configs[i].backend; |
| 1169 | if (gpuStatsDump) { |
| 1170 | // TODO cache stats |
| 1171 | bench->getGpuStats(canvas, &keys, &values); |
| 1172 | } |
| 1173 | #endif |
| 1174 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1175 | bench->perCanvasPostDraw(canvas); |
| 1176 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1177 | if (Benchmark::kNonRendering_Backend != target->config.backend && |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 1178 | !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1179 | SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1180 | pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName()); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1181 | pngFilename.append(".png"); |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1182 | write_canvas_png(target, pngFilename); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | if (kFailedLoops == loops) { |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 1186 | // Can't be timed. A warning note has already been printed. |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1187 | cleanup_run(target); |
Mike Klein | e363136 | 2014-07-15 17:56:37 -0400 | [diff] [blame] | 1188 | continue; |
| 1189 | } |
| 1190 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1191 | Stats stats(samples); |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1192 | log->config(config); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1193 | log->configOption("name", bench->getName()); |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1194 | benchStream.fillCurrentOptions(log.get()); |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1195 | target->fillOptions(log.get()); |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 1196 | log->metric("min_ms", stats.min); |
mtklein | e5cf2c6 | 2016-01-11 11:28:26 -0800 | [diff] [blame] | 1197 | log->metric("median_ms", stats.median); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1198 | #if SK_SUPPORT_GPU |
| 1199 | if (gpuStatsDump) { |
| 1200 | // dump to json, only SKPBench currently returns valid keys / values |
| 1201 | SkASSERT(keys.count() == values.count()); |
| 1202 | for (int i = 0; i < keys.count(); i++) { |
| 1203 | log->metric(keys[i].c_str(), values[i]); |
| 1204 | } |
| 1205 | } |
| 1206 | #endif |
| 1207 | |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 1208 | if (runs++ % FLAGS_flushEvery == 0) { |
| 1209 | log->flush(); |
| 1210 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1211 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1212 | if (kAutoTuneLoops != FLAGS_loops) { |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1213 | if (configs.count() == 1) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 1214 | config = ""; // Only print the config if we run the same bench on more than one. |
| 1215 | } |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1216 | SkDebugf("%4d/%-4dMB\t%s\t%s\n" |
| 1217 | , sk_tools::getCurrResidentSetSizeMB() |
| 1218 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | 53d2562 | 2014-09-18 07:39:42 -0700 | [diff] [blame] | 1219 | , bench->getUniqueName() |
| 1220 | , config); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1221 | } else if (FLAGS_quiet) { |
mtklein | 66cfcff | 2015-12-04 06:35:30 -0800 | [diff] [blame] | 1222 | const char* mark = " "; |
| 1223 | const double stddev_percent = 100 * sqrt(stats.var) / stats.mean; |
| 1224 | if (stddev_percent > 5) mark = "?"; |
| 1225 | if (stddev_percent > 10) mark = "!"; |
| 1226 | |
| 1227 | SkDebugf("%10.2f %s\t%s\t%s\n", |
| 1228 | stats.median*1e3, mark, bench->getUniqueName(), config); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1229 | } else { |
| 1230 | const double stddev_percent = 100 * sqrt(stats.var) / stats.mean; |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1231 | SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n" |
| 1232 | , sk_tools::getCurrResidentSetSizeMB() |
| 1233 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1234 | , loops |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 1235 | , HUMANIZE(stats.min) |
| 1236 | , HUMANIZE(stats.median) |
| 1237 | , HUMANIZE(stats.mean) |
| 1238 | , HUMANIZE(stats.max) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1239 | , stddev_percent |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1240 | , FLAGS_ms ? to_string(samples.count()).c_str() : stats.plot.c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1241 | , config |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1242 | , bench->getUniqueName() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1243 | ); |
| 1244 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1245 | |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 1246 | #if SK_SUPPORT_GPU |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1247 | if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) { |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 1248 | GrContext* context = gGrFactory->get(configs[i].ctxType, |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1249 | configs[i].ctxOptions); |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 1250 | context->printCacheStats(); |
| 1251 | context->printGpuStats(); |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 1252 | } |
| 1253 | #endif |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1254 | |
cdalton | 2c56ba5 | 2015-06-26 13:32:53 -0700 | [diff] [blame] | 1255 | if (FLAGS_verbose) { |
| 1256 | SkDebugf("Samples: "); |
| 1257 | for (int i = 0; i < samples.count(); i++) { |
| 1258 | SkDebugf("%s ", HUMANIZE(samples[i])); |
| 1259 | } |
| 1260 | SkDebugf("%s\n", bench->getUniqueName()); |
| 1261 | } |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1262 | cleanup_run(target); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1263 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
mtklein | e109145 | 2014-12-04 10:47:02 -0800 | [diff] [blame] | 1266 | log->bench("memory_usage", 0,0); |
| 1267 | log->config("meta"); |
| 1268 | log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB()); |
| 1269 | |
joshualitt | e0b19d4 | 2015-03-26 10:41:02 -0700 | [diff] [blame] | 1270 | #if SK_SUPPORT_GPU |
| 1271 | // Make sure we clean up the global GrContextFactory here, otherwise we might race with the |
| 1272 | // SkEventTracer destructor |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1273 | gGrFactory.reset(nullptr); |
joshualitt | e0b19d4 | 2015-03-26 10:41:02 -0700 | [diff] [blame] | 1274 | #endif |
| 1275 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1276 | return 0; |
| 1277 | } |
| 1278 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1279 | #if !defined SK_BUILD_FOR_IOS |
| 1280 | int main(int argc, char** argv) { |
| 1281 | SkCommandLineFlags::Parse(argc, argv); |
| 1282 | return nanobench_main(); |
| 1283 | } |
| 1284 | #endif |