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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 DEFINE_bool(cpu, true, "Master switch for CPU-bound work."); | 48 DEFINE_bool(cpu, true, "Master switch for CPU-bound work."); |
49 DEFINE_bool(gpu, true, "Master switch for GPU-bound work."); | 49 DEFINE_bool(gpu, true, "Master switch for GPU-bound work."); |
50 | 50 |
51 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); | 51 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
52 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc
h."); | 52 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc
h."); |
53 DEFINE_int32(maxCalibrationAttempts, 3, | 53 DEFINE_int32(maxCalibrationAttempts, 3, |
54 "Try up to this many times to guess loops for a bench, or skip the
bench."); | 54 "Try up to this many times to guess loops for a bench, or skip the
bench."); |
55 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); | 55 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); |
56 | 56 |
57 DEFINE_bool2(veryVerbose, V, false, "Print lots for debugging bots."); | |
58 | 57 |
59 static SkString humanize(double ms) { | 58 static SkString humanize(double ms) { |
60 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); | 59 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); |
61 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); | 60 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); |
62 #ifdef SK_BUILD_FOR_WIN | 61 #ifdef SK_BUILD_FOR_WIN |
63 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); | 62 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); |
64 #else | 63 #else |
65 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); | 64 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); |
66 #endif | 65 #endif |
67 return SkStringPrintf("%.3gms", ms); | 66 return SkStringPrintf("%.3gms", ms); |
68 } | 67 } |
69 #define HUMANIZE(ms) humanize(ms).c_str() | 68 #define HUMANIZE(ms) humanize(ms).c_str() |
70 | 69 |
71 static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContextHel
per* gl) { | 70 static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContextHel
per* gl) { |
72 WallTimer timer; | 71 WallTimer timer; |
73 timer.start(); | 72 timer.start(); |
74 if (bench) { | 73 if (bench) { |
75 if (FLAGS_veryVerbose) { SkDebugf("Timing %s for %d loops.\n", bench->ge
tName(), loops); } | |
76 bench->draw(loops, canvas); | 74 bench->draw(loops, canvas); |
77 } | 75 } |
78 if (canvas) { | 76 if (canvas) { |
79 canvas->flush(); | 77 canvas->flush(); |
80 } | 78 } |
81 #if SK_SUPPORT_GPU | 79 #if SK_SUPPORT_GPU |
82 if (gl) { | 80 if (gl) { |
83 SK_GL(*gl, Flush()); | 81 SK_GL(*gl, Flush()); |
84 gl->swapBuffers(); | 82 gl->swapBuffers(); |
85 } | 83 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // ------------------------------------------ < N | 134 // ------------------------------------------ < N |
137 // bench_plus_overhead - overhead) | 135 // bench_plus_overhead - overhead) |
138 // | 136 // |
139 // Luckily, this also works well in practice. :) | 137 // Luckily, this also works well in practice. :) |
140 const double numer = overhead / FLAGS_overheadGoal - overhead; | 138 const double numer = overhead / FLAGS_overheadGoal - overhead; |
141 const double denom = bench_plus_overhead - overhead; | 139 const double denom = bench_plus_overhead - overhead; |
142 const int loops = clamp_loops(FLAGS_runOnce ? 1 : (int)ceil(numer / denom)); | 140 const int loops = clamp_loops(FLAGS_runOnce ? 1 : (int)ceil(numer / denom)); |
143 | 141 |
144 for (int i = 0; i < FLAGS_samples; i++) { | 142 for (int i = 0; i < FLAGS_samples; i++) { |
145 samples[i] = time(loops, bench, canvas, NULL) / loops; | 143 samples[i] = time(loops, bench, canvas, NULL) / loops; |
146 if (FLAGS_veryVerbose) { SkDebugf(" %s\n", HUMANIZE(samples[i])); } | |
147 } | 144 } |
148 return loops; | 145 return loops; |
149 } | 146 } |
150 | 147 |
151 #if SK_SUPPORT_GPU | 148 #if SK_SUPPORT_GPU |
152 static int gpu_bench(SkGLContextHelper* gl, | 149 static int gpu_bench(SkGLContextHelper* gl, |
153 Benchmark* bench, | 150 Benchmark* bench, |
154 SkCanvas* canvas, | 151 SkCanvas* canvas, |
155 double* samples) { | 152 double* samples) { |
156 // Make sure we're done with whatever came before. | 153 // Make sure we're done with whatever came before. |
157 SK_GL(*gl, Finish()); | 154 SK_GL(*gl, Finish()); |
158 | 155 |
159 // First, figure out how many loops it'll take to get a frame up to FLAGS_gp
uMs. | 156 // First, figure out how many loops it'll take to get a frame up to FLAGS_gp
uMs. |
160 int loops = 1; | 157 int loops = 1; |
161 if (!FLAGS_runOnce) { | 158 if (!FLAGS_runOnce) { |
162 double elapsed = 0; | 159 double elapsed = 0; |
163 do { | 160 do { |
164 loops *= 2; | 161 loops *= 2; |
165 // If the GPU lets frames lag at all, we need to make sure we're tim
ing | 162 // If the GPU lets frames lag at all, we need to make sure we're tim
ing |
166 // _this_ round, not still timing last round. We force this by loop
ing | 163 // _this_ round, not still timing last round. We force this by loop
ing |
167 // more times than any reasonable GPU will allow frames to lag. | 164 // more times than any reasonable GPU will allow frames to lag. |
168 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { | 165 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { |
169 elapsed = time(loops, bench, canvas, gl); | 166 elapsed = time(loops, bench, canvas, gl); |
170 } | 167 } |
171 } while (elapsed < FLAGS_gpuMs); | 168 } while (elapsed < FLAGS_gpuMs); |
172 | 169 |
173 // We've overshot at least a little. Scale back linearly. | 170 // We've overshot at least a little. Scale back linearly. |
174 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); | 171 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); |
175 | 172 |
176 if (FLAGS_veryVerbose) { SkDebugf("elapsed %s, loops %d\n", HUMANIZE(ela
psed), loops); } | |
177 | |
178 // Might as well make sure we're not still timing our calibration. | 173 // Might as well make sure we're not still timing our calibration. |
179 SK_GL(*gl, Finish()); | 174 SK_GL(*gl, Finish()); |
180 } | 175 } |
181 loops = clamp_loops(loops); | 176 loops = clamp_loops(loops); |
182 | 177 |
183 // Pretty much the same deal as the calibration: do some warmup to make | 178 // Pretty much the same deal as the calibration: do some warmup to make |
184 // sure we're timing steady-state pipelined frames. | 179 // sure we're timing steady-state pipelined frames. |
185 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { | 180 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { |
186 time(loops, bench, canvas, gl); | 181 time(loops, bench, canvas, gl); |
187 } | 182 } |
188 | 183 |
189 // Now, actually do the timing! | 184 // Now, actually do the timing! |
190 for (int i = 0; i < FLAGS_samples; i++) { | 185 for (int i = 0; i < FLAGS_samples; i++) { |
191 samples[i] = time(loops, bench, canvas, gl) / loops; | 186 samples[i] = time(loops, bench, canvas, gl) / loops; |
192 if (FLAGS_veryVerbose) { SkDebugf(" %s\n", HUMANIZE(samples[i])); } | |
193 } | 187 } |
194 return loops; | 188 return loops; |
195 } | 189 } |
196 #endif | 190 #endif |
197 | 191 |
198 static SkString to_lower(const char* str) { | 192 static SkString to_lower(const char* str) { |
199 SkString lower(str); | 193 SkString lower(str); |
200 for (size_t i = 0; i < lower.size(); i++) { | 194 for (size_t i = 0; i < lower.size(); i++) { |
201 lower[i] = tolower(lower[i]); | 195 lower[i] = tolower(lower[i]); |
202 } | 196 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 335 |
342 const int loops = | 336 const int loops = |
343 #if SK_SUPPORT_GPU | 337 #if SK_SUPPORT_GPU |
344 Benchmark::kGPU_Backend == targets[j]->backend | 338 Benchmark::kGPU_Backend == targets[j]->backend |
345 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) | 339 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) |
346 : | 340 : |
347 #endif | 341 #endif |
348 cpu_bench( overhead, bench.get(), canvas, samples.get()); | 342 cpu_bench( overhead, bench.get(), canvas, samples.get()); |
349 | 343 |
350 if (loops == 0) { | 344 if (loops == 0) { |
| 345 SkDebugf("Unable to time %s\t%s (overhead %s)\n", |
| 346 bench->getName(), config, HUMANIZE(overhead)); |
351 continue; | 347 continue; |
352 } | 348 } |
353 | 349 |
354 Stats stats(samples.get(), FLAGS_samples); | 350 Stats stats(samples.get(), FLAGS_samples); |
355 log.config(config); | 351 log.config(config); |
356 log.timer("min_ms", stats.min); | 352 log.timer("min_ms", stats.min); |
357 log.timer("median_ms", stats.median); | 353 log.timer("median_ms", stats.median); |
358 log.timer("mean_ms", stats.mean); | 354 log.timer("mean_ms", stats.mean); |
359 log.timer("max_ms", stats.max); | 355 log.timer("max_ms", stats.max); |
360 log.timer("stddev_ms", sqrt(stats.var)); | 356 log.timer("stddev_ms", sqrt(stats.var)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 395 } |
400 | 396 |
401 return 0; | 397 return 0; |
402 } | 398 } |
403 | 399 |
404 #if !defined SK_BUILD_FOR_IOS | 400 #if !defined SK_BUILD_FOR_IOS |
405 int main(int argc, char * const argv[]) { | 401 int main(int argc, char * const argv[]) { |
406 return tool_main(argc, (char**) argv); | 402 return tool_main(argc, (char**) argv); |
407 } | 403 } |
408 #endif | 404 #endif |
OLD | NEW |