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 20 matching lines...) Expand all Loading... |
31 DEFINE_double(overheadGoal, 0.0001, | 31 DEFINE_double(overheadGoal, 0.0001, |
32 "Loop until timer overhead is at most this fraction of our measurm
ents."); | 32 "Loop until timer overhead is at most this fraction of our measurm
ents."); |
33 DEFINE_string(match, "", "The usual filters on file names of benchmarks to measu
re."); | 33 DEFINE_string(match, "", "The usual filters on file names of benchmarks to measu
re."); |
34 DEFINE_bool2(quiet, q, false, "Print only bench name and minimum sample."); | 34 DEFINE_bool2(quiet, q, false, "Print only bench name and minimum sample."); |
35 DEFINE_bool2(verbose, v, false, "Print all samples."); | 35 DEFINE_bool2(verbose, v, false, "Print all samples."); |
36 DEFINE_string(config, "nonrendering 8888 gpu", "Configs to measure. Options: " | 36 DEFINE_string(config, "nonrendering 8888 gpu", "Configs to measure. Options: " |
37 "565 8888 gpu nonrendering debug nullgpu msaa4 msaa16 nvprmsaa4 nv
prmsaa16 angle"); | 37 "565 8888 gpu nonrendering debug nullgpu msaa4 msaa16 nvprmsaa4 nv
prmsaa16 angle"); |
38 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); | 38 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
39 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow
s to lag."); | 39 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow
s to lag."); |
40 | 40 |
| 41 DEFINE_bool(cpu, true, "Master switch for CPU-bound work."); |
| 42 DEFINE_bool(gpu, true, "Master switch for GPU-bound work."); |
| 43 |
41 | 44 |
42 static SkString humanize(double ms) { | 45 static SkString humanize(double ms) { |
43 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); | 46 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); |
44 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); | 47 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); |
45 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); | 48 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); |
46 return SkStringPrintf("%.3gms", ms); | 49 return SkStringPrintf("%.3gms", ms); |
47 } | 50 } |
48 | 51 |
49 static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContextHel
per* gl) { | 52 static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContextHel
per* gl) { |
50 WallTimer timer; | 53 WallTimer timer; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 const int w = bench->getSize().fX, | 189 const int w = bench->getSize().fX, |
187 h = bench->getSize().fY; | 190 h = bench->getSize().fY; |
188 const SkImageInfo _8888 = { w, h, kN32_SkColorType, kPremul_SkAlphaType
}, | 191 const SkImageInfo _8888 = { w, h, kN32_SkColorType, kPremul_SkAlphaType
}, |
189 _565 = { w, h, kRGB_565_SkColorType, kOpaque_SkAlphaType
}; | 192 _565 = { w, h, kRGB_565_SkColorType, kOpaque_SkAlphaType
}; |
190 | 193 |
191 #define CPU_TARGET(config, backend, code) \ | 194 #define CPU_TARGET(config, backend, code) \ |
192 if (Target* t = is_enabled(bench, Benchmark::backend, #config)) { \ | 195 if (Target* t = is_enabled(bench, Benchmark::backend, #config)) { \ |
193 t->surface.reset(code); \ | 196 t->surface.reset(code); \ |
194 targets->push(t); \ | 197 targets->push(t); \ |
195 } | 198 } |
196 CPU_TARGET(nonrendering, kNonRendering_Backend, NULL) | 199 if (FLAGS_cpu) { |
197 CPU_TARGET(8888, kRaster_Backend, SkSurface::NewRaster(_8888)) | 200 CPU_TARGET(nonrendering, kNonRendering_Backend, NULL) |
198 CPU_TARGET(565, kRaster_Backend, SkSurface::NewRaster(_565)) | 201 CPU_TARGET(8888, kRaster_Backend, SkSurface::NewRaster(_8888)) |
| 202 CPU_TARGET(565, kRaster_Backend, SkSurface::NewRaster(_565)) |
| 203 } |
199 | 204 |
200 #if SK_SUPPORT_GPU | 205 #if SK_SUPPORT_GPU |
201 #define GPU_TARGET(config, ctxType, info, samples)
\ | 206 #define GPU_TARGET(config, ctxType, info, samples)
\ |
202 if (Target* t = is_enabled(bench, Benchmark::kGPU_Backend, #config)) {
\ | 207 if (Target* t = is_enabled(bench, Benchmark::kGPU_Backend, #config)) {
\ |
203 t->surface.reset(SkSurface::NewRenderTarget(gGrFactory.get(ctxType),
info, samples)); \ | 208 t->surface.reset(SkSurface::NewRenderTarget(gGrFactory.get(ctxType),
info, samples)); \ |
204 t->gl = gGrFactory.getGLContext(ctxType);
\ | 209 t->gl = gGrFactory.getGLContext(ctxType);
\ |
205 targets->push(t);
\ | 210 targets->push(t);
\ |
206 } | 211 } |
207 GPU_TARGET(gpu, GrContextFactory::kNative_GLContextType, _8888, 0) | 212 if (FLAGS_gpu) { |
208 GPU_TARGET(msaa4, GrContextFactory::kNative_GLContextType, _8888, 4) | 213 GPU_TARGET(gpu, GrContextFactory::kNative_GLContextType, _8888, 0) |
209 GPU_TARGET(msaa16, GrContextFactory::kNative_GLContextType, _8888, 16) | 214 GPU_TARGET(msaa4, GrContextFactory::kNative_GLContextType, _8888, 4) |
210 GPU_TARGET(nvprmsaa4, GrContextFactory::kNVPR_GLContextType, _8888, 4) | 215 GPU_TARGET(msaa16, GrContextFactory::kNative_GLContextType, _8888, 16) |
211 GPU_TARGET(nvprmsaa16, GrContextFactory::kNVPR_GLContextType, _8888, 16) | 216 GPU_TARGET(nvprmsaa4, GrContextFactory::kNVPR_GLContextType, _8888, 4) |
212 GPU_TARGET(debug, GrContextFactory::kDebug_GLContextType, _8888, 0) | 217 GPU_TARGET(nvprmsaa16, GrContextFactory::kNVPR_GLContextType, _8888, 16) |
213 GPU_TARGET(nullgpu, GrContextFactory::kNull_GLContextType, _8888, 0) | 218 GPU_TARGET(debug, GrContextFactory::kDebug_GLContextType, _8888, 0) |
214 #if SK_ANGLE | 219 GPU_TARGET(nullgpu, GrContextFactory::kNull_GLContextType, _8888, 0) |
215 GPU_TARGET(angle, GrContextFactory::kANGLE_GLContextType, _8888, 0) | 220 #if SK_ANGLE |
216 #endif | 221 GPU_TARGET(angle, GrContextFactory::kANGLE_GLContextType, _8888, 0) |
| 222 #endif |
| 223 } |
217 #endif | 224 #endif |
218 } | 225 } |
219 | 226 |
220 int tool_main(int argc, char** argv); | 227 int tool_main(int argc, char** argv); |
221 int tool_main(int argc, char** argv) { | 228 int tool_main(int argc, char** argv) { |
222 SetupCrashHandler(); | 229 SetupCrashHandler(); |
223 SkAutoGraphics ag; | 230 SkAutoGraphics ag; |
224 SkCommandLineFlags::Parse(argc, argv); | 231 SkCommandLineFlags::Parse(argc, argv); |
225 | 232 |
226 const double overhead = estimate_timer_overhead(); | 233 const double overhead = estimate_timer_overhead(); |
227 SkAutoTMalloc<double> samples(FLAGS_samples); | 234 SkAutoTMalloc<double> samples(FLAGS_samples); |
228 | 235 |
229 // TODO: display add median, use it in --quiet mode | |
230 | |
231 if (FLAGS_verbose) { | 236 if (FLAGS_verbose) { |
232 // No header. | 237 // No header. |
233 } else if (FLAGS_quiet) { | 238 } else if (FLAGS_quiet) { |
234 SkDebugf("min\tbench\tconfig\n"); | 239 SkDebugf("median\tbench\tconfig\n"); |
235 } else { | 240 } else { |
236 SkDebugf("loops\tmin\tmean\tmax\tstddev\tconfig\tbench\n"); | 241 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tconfig\tbench\n"); |
237 } | 242 } |
238 | 243 |
239 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next(
)) { | 244 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next(
)) { |
240 SkAutoTDelete<Benchmark> bench(r->factory()(NULL)); | 245 SkAutoTDelete<Benchmark> bench(r->factory()(NULL)); |
241 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { | 246 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { |
242 continue; | 247 continue; |
243 } | 248 } |
244 | 249 |
245 SkTDArray<Target*> targets; | 250 SkTDArray<Target*> targets; |
246 create_targets(bench.get(), &targets); | 251 create_targets(bench.get(), &targets); |
(...skipping 15 matching lines...) Expand all Loading... |
262 const char* config = targets[j]->config; | 267 const char* config = targets[j]->config; |
263 if (FLAGS_verbose) { | 268 if (FLAGS_verbose) { |
264 for (int i = 0; i < FLAGS_samples; i++) { | 269 for (int i = 0; i < FLAGS_samples; i++) { |
265 SkDebugf("%s ", humanize(samples[i]).c_str()); | 270 SkDebugf("%s ", humanize(samples[i]).c_str()); |
266 } | 271 } |
267 SkDebugf("%s\n", bench->getName()); | 272 SkDebugf("%s\n", bench->getName()); |
268 } else if (FLAGS_quiet) { | 273 } else if (FLAGS_quiet) { |
269 if (targets.count() == 1) { | 274 if (targets.count() == 1) { |
270 config = ""; // Only print the config if we run the same ben
ch on more than one. | 275 config = ""; // Only print the config if we run the same ben
ch on more than one. |
271 } | 276 } |
272 SkDebugf("%s\t%s\t%s\n", humanize(stats.min).c_str(), bench->get
Name(), config); | 277 SkDebugf("%s\t%s\t%s\n", humanize(stats.median).c_str(), bench->
getName(), config); |
273 } else { | 278 } else { |
274 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean
; | 279 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean
; |
275 SkDebugf("%d\t%s\t%s\t%s\t%.0f%%\t%s\t%s\n" | 280 SkDebugf("%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\n" |
276 , loops | 281 , loops |
277 , humanize(stats.min).c_str() | 282 , humanize(stats.min).c_str() |
| 283 , humanize(stats.median).c_str() |
278 , humanize(stats.mean).c_str() | 284 , humanize(stats.mean).c_str() |
279 , humanize(stats.max).c_str() | 285 , humanize(stats.max).c_str() |
280 , stddev_percent | 286 , stddev_percent |
281 , config | 287 , config |
282 , bench->getName() | 288 , bench->getName() |
283 ); | 289 ); |
284 } | 290 } |
285 } | 291 } |
286 targets.deleteAll(); | 292 targets.deleteAll(); |
287 } | 293 } |
288 | 294 |
289 return 0; | 295 return 0; |
290 } | 296 } |
291 | 297 |
292 #if !defined SK_BUILD_FOR_IOS | 298 #if !defined SK_BUILD_FOR_IOS |
293 int main(int argc, char * const argv[]) { | 299 int main(int argc, char * const argv[]) { |
294 return tool_main(argc, (char**) argv); | 300 return tool_main(argc, (char**) argv); |
295 } | 301 } |
296 #endif | 302 #endif |
OLD | NEW |