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