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