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