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 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 10 | #include "Benchmark.h" |
| 11 | #include "CrashHandler.h" |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 12 | #include "GMBench.h" |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 13 | #include "ResultsWriter.h" |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 14 | #include "SKPBench.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 15 | #include "Stats.h" |
| 16 | #include "Timer.h" |
| 17 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 18 | #include "SkOSFile.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 19 | #include "SkCanvas.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 20 | #include "SkCommonFlags.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 21 | #include "SkForceLinking.h" |
| 22 | #include "SkGraphics.h" |
| 23 | #include "SkString.h" |
| 24 | #include "SkSurface.h" |
| 25 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 26 | #if SK_SUPPORT_GPU |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 27 | #include "gl/GrGLDefines.h" |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 28 | #include "GrContextFactory.h" |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 29 | SkAutoTDelete<GrContextFactory> gGrFactory; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 30 | #endif |
| 31 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 32 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 33 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 34 | static const int kAutoTuneLoops = -1; |
| 35 | |
mtklein | b511042 | 2014-08-07 15:20:02 -0700 | [diff] [blame] | 36 | static const int kDefaultLoops = |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 37 | #ifdef SK_DEBUG |
| 38 | 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 39 | #else |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 40 | kAutoTuneLoops; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 41 | #endif |
| 42 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 43 | static SkString loops_help_txt() { |
| 44 | SkString help; |
| 45 | help.printf("Number of times to run each bench. Set this to %d to auto-" |
| 46 | "tune for each bench. Timings are only reported when auto-tuning.", |
| 47 | kAutoTuneLoops); |
| 48 | return help; |
| 49 | } |
| 50 | |
| 51 | DEFINE_int32(loops, kDefaultLoops, loops_help_txt().c_str()); |
| 52 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 53 | DEFINE_int32(samples, 10, "Number of samples to measure for each bench."); |
| 54 | DEFINE_int32(overheadLoops, 100000, "Loops to estimate timer overhead."); |
| 55 | DEFINE_double(overheadGoal, 0.0001, |
| 56 | "Loop until timer overhead is at most this fraction of our measurments."); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 57 | DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
| 58 | 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] | 59 | DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to " |
| 60 | "software path rendering."); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 61 | |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 62 | DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 63 | DEFINE_int32(maxCalibrationAttempts, 3, |
| 64 | "Try up to this many times to guess loops for a bench, or skip the bench."); |
| 65 | DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); |
mtklein | 94e5156 | 2014-08-19 12:41:53 -0700 | [diff] [blame^] | 66 | DEFINE_string(key, "", |
| 67 | "Space-separated key/value pairs to add to JSON identifying this bench config."); |
| 68 | DEFINE_string(options, "", |
| 69 | "Space-separated option/value pairs to add to JSON, logging extra info."); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 70 | DEFINE_string(gitHash, "", "Git hash to add to JSON."); |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 71 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 72 | DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); |
| 73 | DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); |
| 74 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 75 | static SkString humanize(double ms) { |
| 76 | if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); |
| 77 | if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); |
mtklein | 6238688 | 2014-07-15 10:30:31 -0700 | [diff] [blame] | 78 | #ifdef SK_BUILD_FOR_WIN |
| 79 | if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); |
| 80 | #else |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 81 | if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); |
mtklein | 6238688 | 2014-07-15 10:30:31 -0700 | [diff] [blame] | 82 | #endif |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 83 | return SkStringPrintf("%.3gms", ms); |
| 84 | } |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 85 | #define HUMANIZE(ms) humanize(ms).c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 86 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 87 | static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContextHelper* gl) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 88 | if (canvas) { |
| 89 | canvas->clear(SK_ColorWHITE); |
| 90 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 91 | WallTimer timer; |
| 92 | timer.start(); |
| 93 | if (bench) { |
| 94 | bench->draw(loops, canvas); |
| 95 | } |
| 96 | if (canvas) { |
| 97 | canvas->flush(); |
| 98 | } |
| 99 | #if SK_SUPPORT_GPU |
| 100 | if (gl) { |
| 101 | SK_GL(*gl, Flush()); |
| 102 | gl->swapBuffers(); |
| 103 | } |
| 104 | #endif |
| 105 | timer.end(); |
| 106 | return timer.fWall; |
| 107 | } |
| 108 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 109 | static double estimate_timer_overhead() { |
| 110 | double overhead = 0; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 111 | for (int i = 0; i < FLAGS_overheadLoops; i++) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 112 | overhead += time(1, NULL, NULL, NULL); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 113 | } |
| 114 | return overhead / FLAGS_overheadLoops; |
| 115 | } |
| 116 | |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 117 | static int clamp_loops(int loops) { |
| 118 | if (loops < 1) { |
| 119 | SkDebugf("ERROR: clamping loops from %d to 1.\n", loops); |
| 120 | return 1; |
| 121 | } |
| 122 | if (loops > FLAGS_maxLoops) { |
| 123 | SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops); |
| 124 | return FLAGS_maxLoops; |
| 125 | } |
| 126 | return loops; |
| 127 | } |
| 128 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 129 | static bool write_canvas_png(SkCanvas* canvas, const SkString& filename) { |
| 130 | if (filename.isEmpty()) { |
| 131 | return false; |
| 132 | } |
| 133 | if (kUnknown_SkColorType == canvas->imageInfo().fColorType) { |
| 134 | return false; |
| 135 | } |
| 136 | SkBitmap bmp; |
| 137 | bmp.setInfo(canvas->imageInfo()); |
| 138 | if (!canvas->readPixels(&bmp, 0, 0)) { |
| 139 | SkDebugf("Can't read canvas pixels.\n"); |
| 140 | return false; |
| 141 | } |
| 142 | SkString dir = SkOSPath::Dirname(filename.c_str()); |
| 143 | if (!sk_mkdir(dir.c_str())) { |
| 144 | SkDebugf("Can't make dir %s.\n", dir.c_str()); |
| 145 | return false; |
| 146 | } |
| 147 | SkFILEWStream stream(filename.c_str()); |
| 148 | if (!stream.isValid()) { |
| 149 | SkDebugf("Can't write %s.\n", filename.c_str()); |
| 150 | return false; |
| 151 | } |
| 152 | if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) { |
| 153 | SkDebugf("Can't encode a PNG.\n"); |
| 154 | return false; |
| 155 | } |
| 156 | return true; |
| 157 | } |
| 158 | |
| 159 | static int kFailedLoops = -2; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 160 | static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas, double* samples) { |
| 161 | // 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] | 162 | double bench_plus_overhead = 0.0; |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 163 | int round = 0; |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 164 | if (kAutoTuneLoops == FLAGS_loops) { |
| 165 | while (bench_plus_overhead < overhead) { |
| 166 | if (round++ == FLAGS_maxCalibrationAttempts) { |
| 167 | SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n", |
| 168 | bench->getName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead)); |
| 169 | return kFailedLoops; |
| 170 | } |
| 171 | bench_plus_overhead = time(1, bench, canvas, NULL); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 172 | } |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 173 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 174 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 175 | // 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] | 176 | // We'll pick N to make timer overhead negligible: |
| 177 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 178 | // overhead |
| 179 | // ------------------------- < FLAGS_overheadGoal |
| 180 | // overhead + N * Bench Time |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 181 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 182 | // where bench_plus_overhead ≈ overhead + Bench Time. |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 183 | // |
| 184 | // Doing some math, we get: |
| 185 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 186 | // (overhead / FLAGS_overheadGoal) - overhead |
| 187 | // ------------------------------------------ < N |
| 188 | // bench_plus_overhead - overhead) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 189 | // |
| 190 | // Luckily, this also works well in practice. :) |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 191 | int loops = FLAGS_loops; |
| 192 | if (kAutoTuneLoops == loops) { |
| 193 | const double numer = overhead / FLAGS_overheadGoal - overhead; |
| 194 | const double denom = bench_plus_overhead - overhead; |
| 195 | loops = (int)ceil(numer / denom); |
| 196 | } |
| 197 | loops = clamp_loops(loops); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 198 | |
| 199 | for (int i = 0; i < FLAGS_samples; i++) { |
| 200 | samples[i] = time(loops, bench, canvas, NULL) / loops; |
| 201 | } |
| 202 | return loops; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 203 | } |
| 204 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 205 | #if SK_SUPPORT_GPU |
| 206 | static int gpu_bench(SkGLContextHelper* gl, |
| 207 | Benchmark* bench, |
| 208 | SkCanvas* canvas, |
| 209 | double* samples) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 210 | gl->makeCurrent(); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 211 | // Make sure we're done with whatever came before. |
mtklein | 9bc86ed | 2014-07-01 10:02:42 -0700 | [diff] [blame] | 212 | SK_GL(*gl, Finish()); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 213 | |
| 214 | // 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] | 215 | int loops = FLAGS_loops; |
| 216 | if (kAutoTuneLoops == loops) { |
| 217 | loops = 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 218 | double elapsed = 0; |
| 219 | do { |
| 220 | loops *= 2; |
| 221 | // If the GPU lets frames lag at all, we need to make sure we're timing |
| 222 | // _this_ round, not still timing last round. We force this by looping |
| 223 | // more times than any reasonable GPU will allow frames to lag. |
| 224 | for (int i = 0; i < FLAGS_gpuFrameLag; i++) { |
| 225 | elapsed = time(loops, bench, canvas, gl); |
| 226 | } |
| 227 | } while (elapsed < FLAGS_gpuMs); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 228 | |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 229 | // We've overshot at least a little. Scale back linearly. |
| 230 | loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 231 | |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 232 | // Might as well make sure we're not still timing our calibration. |
| 233 | SK_GL(*gl, Finish()); |
| 234 | } |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 235 | loops = clamp_loops(loops); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 236 | |
| 237 | // Pretty much the same deal as the calibration: do some warmup to make |
| 238 | // sure we're timing steady-state pipelined frames. |
| 239 | for (int i = 0; i < FLAGS_gpuFrameLag; i++) { |
| 240 | time(loops, bench, canvas, gl); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 241 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 242 | |
| 243 | // Now, actually do the timing! |
| 244 | for (int i = 0; i < FLAGS_samples; i++) { |
| 245 | samples[i] = time(loops, bench, canvas, gl) / loops; |
| 246 | } |
| 247 | return loops; |
| 248 | } |
| 249 | #endif |
| 250 | |
| 251 | static SkString to_lower(const char* str) { |
| 252 | SkString lower(str); |
| 253 | for (size_t i = 0; i < lower.size(); i++) { |
| 254 | lower[i] = tolower(lower[i]); |
| 255 | } |
| 256 | return lower; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 257 | } |
| 258 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 259 | struct Config { |
| 260 | const char* name; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 261 | Benchmark::Backend backend; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 262 | SkColorType color; |
| 263 | SkAlphaType alpha; |
| 264 | int samples; |
| 265 | #if SK_SUPPORT_GPU |
| 266 | GrContextFactory::GLContextType ctxType; |
| 267 | #else |
| 268 | int bogusInt; |
| 269 | #endif |
| 270 | }; |
| 271 | |
| 272 | struct Target { |
| 273 | explicit Target(const Config& c) : config(c) {} |
| 274 | const Config config; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 275 | SkAutoTDelete<SkSurface> surface; |
| 276 | #if SK_SUPPORT_GPU |
| 277 | SkGLContextHelper* gl; |
| 278 | #endif |
| 279 | }; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 280 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 281 | static bool is_cpu_config_allowed(const char* name) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 282 | for (int i = 0; i < FLAGS_config.count(); i++) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 283 | if (to_lower(FLAGS_config[i]).equals(name)) { |
| 284 | return true; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 287 | return false; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 288 | } |
| 289 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 290 | #if SK_SUPPORT_GPU |
| 291 | static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextType ctxType, |
| 292 | int sampleCnt) { |
| 293 | if (!is_cpu_config_allowed(name)) { |
| 294 | return false; |
| 295 | } |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 296 | if (const GrContext* ctx = gGrFactory->get(ctxType)) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 297 | return sampleCnt <= ctx->getMaxSampleCount(); |
| 298 | } |
| 299 | return false; |
| 300 | } |
| 301 | #endif |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 302 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 303 | #if SK_SUPPORT_GPU |
| 304 | #define kBogusGLContextType GrContextFactory::kNative_GLContextType |
| 305 | #else |
| 306 | #define kBogusGLContextType 0 |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 307 | #endif |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 308 | |
| 309 | // Append all configs that are enabled and supported. |
| 310 | static void create_configs(SkTDArray<Config>* configs) { |
| 311 | #define CPU_CONFIG(name, backend, color, alpha) \ |
| 312 | if (is_cpu_config_allowed(#name)) { \ |
| 313 | Config config = { #name, Benchmark::backend, color, alpha, 0, kBogusGLContextType }; \ |
| 314 | configs->push(config); \ |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 315 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 316 | |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 317 | if (FLAGS_cpu) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 318 | CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kUnpremul_SkAlphaType) |
| 319 | CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType) |
| 320 | CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType) |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 321 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 322 | |
| 323 | #if SK_SUPPORT_GPU |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 324 | #define GPU_CONFIG(name, ctxType, samples) \ |
| 325 | if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \ |
| 326 | Config config = { \ |
| 327 | #name, \ |
| 328 | Benchmark::kGPU_Backend, \ |
| 329 | kN32_SkColorType, \ |
| 330 | kPremul_SkAlphaType, \ |
| 331 | samples, \ |
| 332 | GrContextFactory::ctxType }; \ |
| 333 | configs->push(config); \ |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 334 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 335 | |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 336 | if (FLAGS_gpu) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 337 | GPU_CONFIG(gpu, kNative_GLContextType, 0) |
| 338 | GPU_CONFIG(msaa4, kNative_GLContextType, 4) |
| 339 | GPU_CONFIG(msaa16, kNative_GLContextType, 16) |
| 340 | GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4) |
| 341 | GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16) |
| 342 | GPU_CONFIG(debug, kDebug_GLContextType, 0) |
| 343 | GPU_CONFIG(nullgpu, kNull_GLContextType, 0) |
bsalomon | 3b4d077 | 2014-08-06 10:52:33 -0700 | [diff] [blame] | 344 | #ifdef SK_ANGLE |
| 345 | GPU_CONFIG(angle, kANGLE_GLContextType, 0) |
| 346 | #endif |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 347 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 348 | #endif |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 349 | } |
| 350 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 351 | // If bench is enabled for config, returns a Target* for it, otherwise NULL. |
| 352 | static Target* is_enabled(Benchmark* bench, const Config& config) { |
| 353 | if (!bench->isSuitableFor(config.backend)) { |
| 354 | return NULL; |
| 355 | } |
| 356 | |
| 357 | SkImageInfo info; |
| 358 | info.fAlphaType = config.alpha; |
| 359 | info.fColorType = config.color; |
| 360 | info.fWidth = bench->getSize().fX; |
| 361 | info.fHeight = bench->getSize().fY; |
| 362 | |
| 363 | Target* target = new Target(config); |
| 364 | |
| 365 | if (Benchmark::kRaster_Backend == config.backend) { |
| 366 | target->surface.reset(SkSurface::NewRaster(info)); |
| 367 | } |
| 368 | #if SK_SUPPORT_GPU |
| 369 | else if (Benchmark::kGPU_Backend == config.backend) { |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 370 | target->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(config.ctxType), info, |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 371 | config.samples)); |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 372 | target->gl = gGrFactory->getGLContext(config.ctxType); |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 373 | } |
| 374 | #endif |
| 375 | |
| 376 | if (Benchmark::kNonRendering_Backend != config.backend && !target->surface.get()) { |
| 377 | delete target; |
| 378 | return NULL; |
| 379 | } |
| 380 | return target; |
| 381 | } |
| 382 | |
| 383 | // Creates targets for a benchmark and a set of configs. |
| 384 | static void create_targets(SkTDArray<Target*>* targets, Benchmark* b, |
| 385 | const SkTDArray<Config>& configs) { |
| 386 | for (int i = 0; i < configs.count(); ++i) { |
| 387 | if (Target* t = is_enabled(b, configs[i])) { |
| 388 | targets->push(t); |
| 389 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 390 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 394 | static void fill_static_options(ResultsWriter* log) { |
| 395 | #if defined(SK_BUILD_FOR_WIN32) |
| 396 | log->option("system", "WIN32"); |
| 397 | #elif defined(SK_BUILD_FOR_MAC) |
| 398 | log->option("system", "MAC"); |
| 399 | #elif defined(SK_BUILD_FOR_ANDROID) |
| 400 | log->option("system", "ANDROID"); |
| 401 | #elif defined(SK_BUILD_FOR_UNIX) |
| 402 | log->option("system", "UNIX"); |
| 403 | #else |
| 404 | log->option("system", "other"); |
| 405 | #endif |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 406 | } |
| 407 | |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 408 | #if SK_SUPPORT_GPU |
| 409 | static void fill_gpu_options(ResultsWriter* log, SkGLContextHelper* ctx) { |
jcgregorio | 05c4560 | 2014-07-17 13:54:36 -0700 | [diff] [blame] | 410 | const GrGLubyte* version; |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 411 | SK_GL_RET(*ctx, version, GetString(GR_GL_VERSION)); |
| 412 | log->configOption("GL_VERSION", (const char*)(version)); |
| 413 | |
| 414 | SK_GL_RET(*ctx, version, GetString(GR_GL_RENDERER)); |
| 415 | log->configOption("GL_RENDERER", (const char*) version); |
| 416 | |
| 417 | SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR)); |
| 418 | log->configOption("GL_VENDOR", (const char*) version); |
| 419 | |
| 420 | SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
| 421 | log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); |
| 422 | } |
| 423 | #endif |
| 424 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 425 | class BenchmarkStream { |
| 426 | public: |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 427 | BenchmarkStream() : fBenches(BenchRegistry::Head()) |
| 428 | , fGMs(skiagm::GMRegistry::Head()) |
| 429 | , fCurrentScale(0) |
| 430 | , fCurrentSKP(0) { |
| 431 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 432 | if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
| 433 | fSKPs.push_back() = FLAGS_skps[i]; |
| 434 | } else { |
| 435 | SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
| 436 | SkString path; |
| 437 | while (it.next(&path)) { |
| 438 | fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); |
| 439 | } |
| 440 | } |
| 441 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 442 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 443 | if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
| 444 | &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) { |
| 445 | SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]); |
| 446 | exit(1); |
| 447 | } |
| 448 | |
| 449 | for (int i = 0; i < FLAGS_scales.count(); i++) { |
| 450 | if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { |
| 451 | SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]); |
| 452 | exit(1); |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | Benchmark* next() { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 458 | if (fBenches) { |
| 459 | Benchmark* bench = fBenches->factory()(NULL); |
| 460 | fBenches = fBenches->next(); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 461 | fSourceType = "bench"; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 462 | return bench; |
| 463 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 464 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 465 | while (fGMs) { |
| 466 | SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); |
| 467 | fGMs = fGMs->next(); |
| 468 | if (gm->getFlags() & skiagm::GM::kAsBench_Flag) { |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 469 | fSourceType = "gm"; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 470 | return SkNEW_ARGS(GMBench, (gm.detach())); |
| 471 | } |
| 472 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 473 | |
| 474 | while (fCurrentScale < fScales.count()) { |
| 475 | while (fCurrentSKP < fSKPs.count()) { |
| 476 | const SkString& path = fSKPs[fCurrentSKP++]; |
| 477 | |
| 478 | // Not strictly necessary, as it will be checked again later, |
| 479 | // but helps to avoid a lot of pointless work if we're going to skip it. |
| 480 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
| 481 | continue; |
| 482 | } |
| 483 | |
| 484 | SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); |
| 485 | if (stream.get() == NULL) { |
| 486 | SkDebugf("Could not read %s.\n", path.c_str()); |
| 487 | exit(1); |
| 488 | } |
| 489 | |
| 490 | SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get())); |
| 491 | if (pic.get() == NULL) { |
| 492 | SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); |
| 493 | exit(1); |
| 494 | } |
| 495 | |
| 496 | SkString name = SkOSPath::Basename(path.c_str()); |
| 497 | |
| 498 | fSourceType = "skp"; |
| 499 | return SkNEW_ARGS(SKPBench, |
| 500 | (name.c_str(), pic.get(), fClip, fScales[fCurrentScale])); |
| 501 | } |
| 502 | fCurrentSKP = 0; |
| 503 | fCurrentScale++; |
| 504 | } |
| 505 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 506 | return NULL; |
| 507 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 508 | |
| 509 | void fillCurrentOptions(ResultsWriter* log) const { |
| 510 | log->configOption("source_type", fSourceType); |
| 511 | if (0 == strcmp(fSourceType, "skp")) { |
| 512 | log->configOption("clip", |
| 513 | SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
| 514 | fClip.fRight, fClip.fBottom).c_str()); |
| 515 | log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str()); |
| 516 | } |
| 517 | } |
| 518 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 519 | private: |
| 520 | const BenchRegistry* fBenches; |
| 521 | const skiagm::GMRegistry* fGMs; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 522 | SkIRect fClip; |
| 523 | SkTArray<SkScalar> fScales; |
| 524 | SkTArray<SkString> fSKPs; |
| 525 | |
| 526 | const char* fSourceType; |
| 527 | int fCurrentScale; |
| 528 | int fCurrentSKP; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 529 | }; |
| 530 | |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 531 | int nanobench_main(); |
| 532 | int nanobench_main() { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 533 | SetupCrashHandler(); |
| 534 | SkAutoGraphics ag; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 535 | |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 536 | #if SK_SUPPORT_GPU |
krajcevski | 12b3544 | 2014-08-13 12:06:26 -0700 | [diff] [blame] | 537 | GrContext::Options grContextOpts; |
| 538 | grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; |
| 539 | gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts))); |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 540 | #endif |
| 541 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 542 | if (kAutoTuneLoops != FLAGS_loops) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 543 | FLAGS_samples = 1; |
| 544 | FLAGS_gpuFrameLag = 0; |
| 545 | } |
| 546 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 547 | if (!FLAGS_writePath.isEmpty()) { |
| 548 | SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]); |
| 549 | if (!sk_mkdir(FLAGS_writePath[0])) { |
| 550 | SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]); |
| 551 | FLAGS_writePath.set(0, NULL); |
| 552 | } |
| 553 | } |
| 554 | |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 555 | MultiResultsWriter log; |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 556 | SkAutoTDelete<NanoJSONResultsWriter> json; |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 557 | if (!FLAGS_outResultsFile.isEmpty()) { |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 558 | const char* gitHash = FLAGS_gitHash.isEmpty() ? "unknown-revision" : FLAGS_gitHash[0]; |
| 559 | json.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0], gitHash))); |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 560 | log.add(json.get()); |
| 561 | } |
| 562 | CallEnd<MultiResultsWriter> ender(log); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 563 | |
| 564 | if (1 == FLAGS_key.count() % 2) { |
| 565 | SkDebugf("ERROR: --key must be passed with an even number of arguments.\n"); |
| 566 | return 1; |
| 567 | } |
| 568 | for (int i = 1; i < FLAGS_key.count(); i += 2) { |
| 569 | log.key(FLAGS_key[i-1], FLAGS_key[i]); |
| 570 | } |
mtklein | 94e5156 | 2014-08-19 12:41:53 -0700 | [diff] [blame^] | 571 | |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 572 | fill_static_options(&log); |
mtklein | 94e5156 | 2014-08-19 12:41:53 -0700 | [diff] [blame^] | 573 | if (1 == FLAGS_options.count() % 2) { |
| 574 | SkDebugf("ERROR: --options must be passed with an even number of arguments.\n"); |
| 575 | return 1; |
| 576 | } |
| 577 | for (int i = 1; i < FLAGS_options.count(); i += 2) { |
| 578 | log.option(FLAGS_options[i-1], FLAGS_options[i]); |
| 579 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 580 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 581 | const double overhead = estimate_timer_overhead(); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 582 | SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead)); |
Mike Klein | 9129477 | 2014-07-16 19:59:32 -0400 | [diff] [blame] | 583 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 584 | SkAutoTMalloc<double> samples(FLAGS_samples); |
| 585 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 586 | if (kAutoTuneLoops != FLAGS_loops) { |
| 587 | 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] | 588 | } else if (FLAGS_verbose) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 589 | // No header. |
| 590 | } else if (FLAGS_quiet) { |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 591 | SkDebugf("median\tbench\tconfig\n"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 592 | } else { |
mtklein | 5d9d10e | 2014-07-11 11:57:07 -0700 | [diff] [blame] | 593 | SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 594 | } |
| 595 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 596 | SkTDArray<Config> configs; |
| 597 | create_configs(&configs); |
| 598 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 599 | BenchmarkStream benchStream; |
| 600 | while (Benchmark* b = benchStream.next()) { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 601 | SkAutoTDelete<Benchmark> bench(b); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 602 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { |
| 603 | continue; |
| 604 | } |
| 605 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 606 | SkTDArray<Target*> targets; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 607 | create_targets(&targets, bench.get(), configs); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 608 | |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 609 | if (!targets.isEmpty()) { |
| 610 | log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY); |
| 611 | bench->preDraw(); |
| 612 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 613 | for (int j = 0; j < targets.count(); j++) { |
| 614 | SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->getCanvas() : NULL; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 615 | const char* config = targets[j]->config.name; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 616 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 617 | #if SK_DEBUG |
| 618 | // skia:2797 Some SKPs SkASSERT in debug mode. Skip them for now. |
mtklein | 6e33e23 | 2014-08-01 08:23:39 -0700 | [diff] [blame] | 619 | if (0 == strcmp("565", config) && SkStrContains(bench->getName(), ".skp")) { |
| 620 | SkDebugf("Skipping 565 %s. See skia:2797\n", bench->getName()); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 621 | continue; |
| 622 | } |
| 623 | #endif |
| 624 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 625 | const int loops = |
| 626 | #if SK_SUPPORT_GPU |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 627 | Benchmark::kGPU_Backend == targets[j]->config.backend |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 628 | ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) |
| 629 | : |
| 630 | #endif |
| 631 | cpu_bench( overhead, bench.get(), canvas, samples.get()); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 632 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 633 | if (canvas && !FLAGS_writePath.isEmpty() && NULL != FLAGS_writePath[0]) { |
| 634 | SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config); |
| 635 | pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getName()); |
| 636 | pngFilename.append(".png"); |
| 637 | write_canvas_png(canvas, pngFilename); |
| 638 | } |
| 639 | |
| 640 | if (kFailedLoops == loops) { |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 641 | // Can't be timed. A warning note has already been printed. |
Mike Klein | e363136 | 2014-07-15 17:56:37 -0400 | [diff] [blame] | 642 | continue; |
| 643 | } |
| 644 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 645 | Stats stats(samples.get(), FLAGS_samples); |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 646 | log.config(config); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 647 | benchStream.fillCurrentOptions(&log); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 648 | #if SK_SUPPORT_GPU |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 649 | if (Benchmark::kGPU_Backend == targets[j]->config.backend) { |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 650 | fill_gpu_options(&log, targets[j]->gl); |
| 651 | } |
| 652 | #endif |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 653 | log.timer("min_ms", stats.min); |
| 654 | log.timer("median_ms", stats.median); |
| 655 | log.timer("mean_ms", stats.mean); |
| 656 | log.timer("max_ms", stats.max); |
| 657 | log.timer("stddev_ms", sqrt(stats.var)); |
| 658 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 659 | if (kAutoTuneLoops != FLAGS_loops) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 660 | if (targets.count() == 1) { |
| 661 | config = ""; // Only print the config if we run the same bench on more than one. |
| 662 | } |
| 663 | SkDebugf("%s\t%s\n", bench->getName(), config); |
| 664 | } else if (FLAGS_verbose) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 665 | for (int i = 0; i < FLAGS_samples; i++) { |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 666 | SkDebugf("%s ", HUMANIZE(samples[i])); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 667 | } |
| 668 | SkDebugf("%s\n", bench->getName()); |
| 669 | } else if (FLAGS_quiet) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 670 | if (targets.count() == 1) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 671 | config = ""; // Only print the config if we run the same bench on more than one. |
| 672 | } |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 673 | SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getName(), config); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 674 | } else { |
| 675 | const double stddev_percent = 100 * sqrt(stats.var) / stats.mean; |
mtklein | 5d9d10e | 2014-07-11 11:57:07 -0700 | [diff] [blame] | 676 | SkDebugf("%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 677 | , loops |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 678 | , HUMANIZE(stats.min) |
| 679 | , HUMANIZE(stats.median) |
| 680 | , HUMANIZE(stats.mean) |
| 681 | , HUMANIZE(stats.max) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 682 | , stddev_percent |
mtklein | 5d9d10e | 2014-07-11 11:57:07 -0700 | [diff] [blame] | 683 | , stats.plot.c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 684 | , config |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 685 | , bench->getName() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 686 | ); |
| 687 | } |
| 688 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 689 | targets.deleteAll(); |
Mike Klein | 3944a1d | 2014-07-15 13:40:19 -0400 | [diff] [blame] | 690 | |
| 691 | #if SK_SUPPORT_GPU |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 692 | if (FLAGS_abandonGpuContext) { |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 693 | gGrFactory->abandonContexts(); |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 694 | } |
| 695 | if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 696 | gGrFactory->destroyContexts(); |
Mike Klein | 3944a1d | 2014-07-15 13:40:19 -0400 | [diff] [blame] | 697 | } |
| 698 | #endif |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | #if !defined SK_BUILD_FOR_IOS |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 705 | int main(int argc, char** argv) { |
| 706 | SkCommandLineFlags::Parse(argc, argv); |
| 707 | return nanobench_main(); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 708 | } |
| 709 | #endif |