Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: bench/nanobench.cpp

Issue 401663002: nanobench: --veryVerbose for more Win7 debugging (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.");
57 58
58 static SkString humanize(double ms) { 59 static SkString humanize(double ms) {
59 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); 60 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3);
60 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); 61 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6);
61 #ifdef SK_BUILD_FOR_WIN 62 #ifdef SK_BUILD_FOR_WIN
62 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); 63 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3);
63 #else 64 #else
64 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); 65 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3);
65 #endif 66 #endif
66 return SkStringPrintf("%.3gms", ms); 67 return SkStringPrintf("%.3gms", ms);
67 } 68 }
68 #define HUMANIZE(ms) humanize(ms).c_str() 69 #define HUMANIZE(ms) humanize(ms).c_str()
69 70
70 static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContextHel per* gl) { 71 static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContextHel per* gl) {
71 WallTimer timer; 72 WallTimer timer;
72 timer.start(); 73 timer.start();
73 if (bench) { 74 if (bench) {
75 if (FLAGS_veryVerbose) { SkDebugf("Timing %s for %d loops.\n", bench->ge tName(), loops); }
74 bench->draw(loops, canvas); 76 bench->draw(loops, canvas);
75 } 77 }
76 if (canvas) { 78 if (canvas) {
77 canvas->flush(); 79 canvas->flush();
78 } 80 }
79 #if SK_SUPPORT_GPU 81 #if SK_SUPPORT_GPU
80 if (gl) { 82 if (gl) {
81 SK_GL(*gl, Flush()); 83 SK_GL(*gl, Flush());
82 gl->swapBuffers(); 84 gl->swapBuffers();
83 } 85 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // ------------------------------------------ < N 136 // ------------------------------------------ < N
135 // bench_plus_overhead - overhead) 137 // bench_plus_overhead - overhead)
136 // 138 //
137 // Luckily, this also works well in practice. :) 139 // Luckily, this also works well in practice. :)
138 const double numer = overhead / FLAGS_overheadGoal - overhead; 140 const double numer = overhead / FLAGS_overheadGoal - overhead;
139 const double denom = bench_plus_overhead - overhead; 141 const double denom = bench_plus_overhead - overhead;
140 const int loops = clamp_loops(FLAGS_runOnce ? 1 : (int)ceil(numer / denom)); 142 const int loops = clamp_loops(FLAGS_runOnce ? 1 : (int)ceil(numer / denom));
141 143
142 for (int i = 0; i < FLAGS_samples; i++) { 144 for (int i = 0; i < FLAGS_samples; i++) {
143 samples[i] = time(loops, bench, canvas, NULL) / loops; 145 samples[i] = time(loops, bench, canvas, NULL) / loops;
146 if (FLAGS_veryVerbose) { SkDebugf(" %s\n", HUMANIZE(samples[i])); }
144 } 147 }
145 return loops; 148 return loops;
146 } 149 }
147 150
148 #if SK_SUPPORT_GPU 151 #if SK_SUPPORT_GPU
149 static int gpu_bench(SkGLContextHelper* gl, 152 static int gpu_bench(SkGLContextHelper* gl,
150 Benchmark* bench, 153 Benchmark* bench,
151 SkCanvas* canvas, 154 SkCanvas* canvas,
152 double* samples) { 155 double* samples) {
153 // Make sure we're done with whatever came before. 156 // Make sure we're done with whatever came before.
154 SK_GL(*gl, Finish()); 157 SK_GL(*gl, Finish());
155 158
156 // First, figure out how many loops it'll take to get a frame up to FLAGS_gp uMs. 159 // First, figure out how many loops it'll take to get a frame up to FLAGS_gp uMs.
157 int loops = 1; 160 int loops = 1;
158 if (!FLAGS_runOnce) { 161 if (!FLAGS_runOnce) {
159 double elapsed = 0; 162 double elapsed = 0;
160 do { 163 do {
161 loops *= 2; 164 loops *= 2;
162 // If the GPU lets frames lag at all, we need to make sure we're tim ing 165 // If the GPU lets frames lag at all, we need to make sure we're tim ing
163 // _this_ round, not still timing last round. We force this by loop ing 166 // _this_ round, not still timing last round. We force this by loop ing
164 // more times than any reasonable GPU will allow frames to lag. 167 // more times than any reasonable GPU will allow frames to lag.
165 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { 168 for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
166 elapsed = time(loops, bench, canvas, gl); 169 elapsed = time(loops, bench, canvas, gl);
167 } 170 }
168 } while (elapsed < FLAGS_gpuMs); 171 } while (elapsed < FLAGS_gpuMs);
169 172
170 // We've overshot at least a little. Scale back linearly. 173 // We've overshot at least a little. Scale back linearly.
171 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); 174 loops = (int)ceil(loops * FLAGS_gpuMs / elapsed);
172 175
176 if (FLAGS_veryVerbose) { SkDebugf("elapsed %s, loops %d\n", HUMANIZE(ela psed), loops); }
177
173 // Might as well make sure we're not still timing our calibration. 178 // Might as well make sure we're not still timing our calibration.
174 SK_GL(*gl, Finish()); 179 SK_GL(*gl, Finish());
175 } 180 }
176 loops = clamp_loops(loops); 181 loops = clamp_loops(loops);
177 182
178 // Pretty much the same deal as the calibration: do some warmup to make 183 // Pretty much the same deal as the calibration: do some warmup to make
179 // sure we're timing steady-state pipelined frames. 184 // sure we're timing steady-state pipelined frames.
180 for (int i = 0; i < FLAGS_gpuFrameLag; i++) { 185 for (int i = 0; i < FLAGS_gpuFrameLag; i++) {
181 time(loops, bench, canvas, gl); 186 time(loops, bench, canvas, gl);
182 } 187 }
183 188
184 // Now, actually do the timing! 189 // Now, actually do the timing!
185 for (int i = 0; i < FLAGS_samples; i++) { 190 for (int i = 0; i < FLAGS_samples; i++) {
186 samples[i] = time(loops, bench, canvas, gl) / loops; 191 samples[i] = time(loops, bench, canvas, gl) / loops;
192 if (FLAGS_veryVerbose) { SkDebugf(" %s\n", HUMANIZE(samples[i])); }
187 } 193 }
188 return loops; 194 return loops;
189 } 195 }
190 #endif 196 #endif
191 197
192 static SkString to_lower(const char* str) { 198 static SkString to_lower(const char* str) {
193 SkString lower(str); 199 SkString lower(str);
194 for (size_t i = 0; i < lower.size(); i++) { 200 for (size_t i = 0; i < lower.size(); i++) {
195 lower[i] = tolower(lower[i]); 201 lower[i] = tolower(lower[i]);
196 } 202 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 341
336 const int loops = 342 const int loops =
337 #if SK_SUPPORT_GPU 343 #if SK_SUPPORT_GPU
338 Benchmark::kGPU_Backend == targets[j]->backend 344 Benchmark::kGPU_Backend == targets[j]->backend
339 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) 345 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
340 : 346 :
341 #endif 347 #endif
342 cpu_bench( overhead, bench.get(), canvas, samples.get()); 348 cpu_bench( overhead, bench.get(), canvas, samples.get());
343 349
344 if (loops == 0) { 350 if (loops == 0) {
345 SkDebugf("Unable to time %s\t%s (overhead %s)\n",
346 bench->getName(), config, HUMANIZE(overhead));
347 continue; 351 continue;
348 } 352 }
349 353
350 Stats stats(samples.get(), FLAGS_samples); 354 Stats stats(samples.get(), FLAGS_samples);
351 log.config(config); 355 log.config(config);
352 log.timer("min_ms", stats.min); 356 log.timer("min_ms", stats.min);
353 log.timer("median_ms", stats.median); 357 log.timer("median_ms", stats.median);
354 log.timer("mean_ms", stats.mean); 358 log.timer("mean_ms", stats.mean);
355 log.timer("max_ms", stats.max); 359 log.timer("max_ms", stats.max);
356 log.timer("stddev_ms", sqrt(stats.var)); 360 log.timer("stddev_ms", sqrt(stats.var));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 399 }
396 400
397 return 0; 401 return 0;
398 } 402 }
399 403
400 #if !defined SK_BUILD_FOR_IOS 404 #if !defined SK_BUILD_FOR_IOS
401 int main(int argc, char * const argv[]) { 405 int main(int argc, char * const argv[]) {
402 return tool_main(argc, (char**) argv); 406 return tool_main(argc, (char**) argv);
403 } 407 }
404 #endif 408 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698