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