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