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