| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <ctype.h> | 8 #include <ctype.h> |
| 9 | 9 |
| 10 #include "Benchmark.h" | 10 #include "Benchmark.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "SkSurface.h" | 28 #include "SkSurface.h" |
| 29 | 29 |
| 30 #if SK_SUPPORT_GPU | 30 #if SK_SUPPORT_GPU |
| 31 #include "gl/GrGLDefines.h" | 31 #include "gl/GrGLDefines.h" |
| 32 #include "GrContextFactory.h" | 32 #include "GrContextFactory.h" |
| 33 SkAutoTDelete<GrContextFactory> gGrFactory; | 33 SkAutoTDelete<GrContextFactory> gGrFactory; |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 __SK_FORCE_IMAGE_DECODER_LINKING; | 36 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 37 | 37 |
| 38 static const int kAutoTuneLoops = -1; | 38 static const int kAutoTuneLoops = 0; |
| 39 | 39 |
| 40 static const int kDefaultLoops = | 40 static const int kDefaultLoops = |
| 41 #ifdef SK_DEBUG | 41 #ifdef SK_DEBUG |
| 42 1; | 42 1; |
| 43 #else | 43 #else |
| 44 kAutoTuneLoops; | 44 kAutoTuneLoops; |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 static SkString loops_help_txt() { | 47 static SkString loops_help_txt() { |
| 48 SkString help; | 48 SkString help; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 | 108 |
| 109 static double estimate_timer_overhead() { | 109 static double estimate_timer_overhead() { |
| 110 double overhead = 0; | 110 double overhead = 0; |
| 111 for (int i = 0; i < FLAGS_overheadLoops; i++) { | 111 for (int i = 0; i < FLAGS_overheadLoops; i++) { |
| 112 overhead += time(1, NULL, NULL, NULL); | 112 overhead += time(1, NULL, NULL, NULL); |
| 113 } | 113 } |
| 114 return overhead / FLAGS_overheadLoops; | 114 return overhead / FLAGS_overheadLoops; |
| 115 } | 115 } |
| 116 | 116 |
| 117 static int detect_forever_loops(int loops) { |
| 118 // look for a magic run-forever value |
| 119 if (loops < 0) { |
| 120 loops = SK_MaxS32; |
| 121 } |
| 122 return loops; |
| 123 } |
| 124 |
| 117 static int clamp_loops(int loops) { | 125 static int clamp_loops(int loops) { |
| 118 if (loops < 1) { | 126 if (loops < 1) { |
| 119 SkDebugf("ERROR: clamping loops from %d to 1.\n", loops); | 127 SkDebugf("ERROR: clamping loops from %d to 1.\n", loops); |
| 120 return 1; | 128 return 1; |
| 121 } | 129 } |
| 122 if (loops > FLAGS_maxLoops) { | 130 if (loops > FLAGS_maxLoops) { |
| 123 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loo
ps, FLAGS_maxLoops); | 131 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loo
ps, FLAGS_maxLoops); |
| 124 return FLAGS_maxLoops; | 132 return FLAGS_maxLoops; |
| 125 } | 133 } |
| 126 return loops; | 134 return loops; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // (overhead / FLAGS_overheadGoal) - overhead | 194 // (overhead / FLAGS_overheadGoal) - overhead |
| 187 // ------------------------------------------ < N | 195 // ------------------------------------------ < N |
| 188 // bench_plus_overhead - overhead) | 196 // bench_plus_overhead - overhead) |
| 189 // | 197 // |
| 190 // Luckily, this also works well in practice. :) | 198 // Luckily, this also works well in practice. :) |
| 191 int loops = FLAGS_loops; | 199 int loops = FLAGS_loops; |
| 192 if (kAutoTuneLoops == loops) { | 200 if (kAutoTuneLoops == loops) { |
| 193 const double numer = overhead / FLAGS_overheadGoal - overhead; | 201 const double numer = overhead / FLAGS_overheadGoal - overhead; |
| 194 const double denom = bench_plus_overhead - overhead; | 202 const double denom = bench_plus_overhead - overhead; |
| 195 loops = (int)ceil(numer / denom); | 203 loops = (int)ceil(numer / denom); |
| 204 loops = clamp_loops(loops); |
| 205 } else { |
| 206 loops = detect_forever_loops(loops); |
| 196 } | 207 } |
| 197 loops = clamp_loops(loops); | |
| 198 | 208 |
| 199 for (int i = 0; i < FLAGS_samples; i++) { | 209 for (int i = 0; i < FLAGS_samples; i++) { |
| 200 samples[i] = time(loops, bench, canvas, NULL) / loops; | 210 samples[i] = time(loops, bench, canvas, NULL) / loops; |
| 201 } | 211 } |
| 202 return loops; | 212 return loops; |
| 203 } | 213 } |
| 204 | 214 |
| 205 #if SK_SUPPORT_GPU | 215 #if SK_SUPPORT_GPU |
| 206 static int gpu_bench(SkGLContext* gl, | 216 static int gpu_bench(SkGLContext* gl, |
| 207 Benchmark* bench, | 217 Benchmark* bench, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 221 // If the GPU lets frames lag at all, we need to make sure we're tim
ing | 231 // If the GPU lets frames lag at all, we need to make sure we're tim
ing |
| 222 // _this_ round, not still timing last round. We force this by loop
ing | 232 // _this_ round, not still timing last round. We force this by loop
ing |
| 223 // more times than any reasonable GPU will allow frames to lag. | 233 // more times than any reasonable GPU will allow frames to lag. |
| 224 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { | 234 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { |
| 225 elapsed = time(loops, bench, canvas, gl); | 235 elapsed = time(loops, bench, canvas, gl); |
| 226 } | 236 } |
| 227 } while (elapsed < FLAGS_gpuMs); | 237 } while (elapsed < FLAGS_gpuMs); |
| 228 | 238 |
| 229 // We've overshot at least a little. Scale back linearly. | 239 // We've overshot at least a little. Scale back linearly. |
| 230 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); | 240 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); |
| 241 loops = clamp_loops(loops); |
| 231 | 242 |
| 232 // Might as well make sure we're not still timing our calibration. | 243 // Might as well make sure we're not still timing our calibration. |
| 233 SK_GL(*gl, Finish()); | 244 SK_GL(*gl, Finish()); |
| 245 } else { |
| 246 loops = detect_forever_loops(loops); |
| 234 } | 247 } |
| 235 loops = clamp_loops(loops); | |
| 236 | 248 |
| 237 // Pretty much the same deal as the calibration: do some warmup to make | 249 // Pretty much the same deal as the calibration: do some warmup to make |
| 238 // sure we're timing steady-state pipelined frames. | 250 // sure we're timing steady-state pipelined frames. |
| 239 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { | 251 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { |
| 240 time(loops, bench, canvas, gl); | 252 time(loops, bench, canvas, gl); |
| 241 } | 253 } |
| 242 | 254 |
| 243 // Now, actually do the timing! | 255 // Now, actually do the timing! |
| 244 for (int i = 0; i < FLAGS_samples; i++) { | 256 for (int i = 0; i < FLAGS_samples; i++) { |
| 245 samples[i] = time(loops, bench, canvas, gl) / loops; | 257 samples[i] = time(loops, bench, canvas, gl) / loops; |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 | 729 |
| 718 return 0; | 730 return 0; |
| 719 } | 731 } |
| 720 | 732 |
| 721 #if !defined SK_BUILD_FOR_IOS | 733 #if !defined SK_BUILD_FOR_IOS |
| 722 int main(int argc, char** argv) { | 734 int main(int argc, char** argv) { |
| 723 SkCommandLineFlags::Parse(argc, argv); | 735 SkCommandLineFlags::Parse(argc, argv); |
| 724 return nanobench_main(); | 736 return nanobench_main(); |
| 725 } | 737 } |
| 726 #endif | 738 #endif |
| OLD | NEW |