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" |
11 #include "CrashHandler.h" | 11 #include "CrashHandler.h" |
12 #include "ResultsWriter.h" | 12 #include "ResultsWriter.h" |
13 #include "Stats.h" | 13 #include "Stats.h" |
14 #include "Timer.h" | 14 #include "Timer.h" |
15 | 15 |
16 #include "SkCanvas.h" | 16 #include "SkCanvas.h" |
17 #include "SkCommandLineFlags.h" | 17 #include "SkCommandLineFlags.h" |
18 #include "SkForceLinking.h" | 18 #include "SkForceLinking.h" |
19 #include "SkGraphics.h" | 19 #include "SkGraphics.h" |
20 #include "SkString.h" | 20 #include "SkString.h" |
21 #include "SkSurface.h" | 21 #include "SkSurface.h" |
22 | 22 |
23 #if SK_SUPPORT_GPU | 23 #if SK_SUPPORT_GPU |
24 #include "gl/GrGLDefines.h" | |
24 #include "GrContextFactory.h" | 25 #include "GrContextFactory.h" |
25 GrContextFactory gGrFactory; | 26 GrContextFactory gGrFactory; |
26 #endif | 27 #endif |
27 | 28 |
28 __SK_FORCE_IMAGE_DECODER_LINKING; | 29 __SK_FORCE_IMAGE_DECODER_LINKING; |
29 | 30 |
30 #if SK_DEBUG | 31 #if SK_DEBUG |
31 DEFINE_bool(runOnce, true, "Run each benchmark just once?"); | 32 DEFINE_bool(runOnce, true, "Run each benchmark just once?"); |
32 #else | 33 #else |
33 DEFINE_bool(runOnce, false, "Run each benchmark just once?"); | 34 DEFINE_bool(runOnce, false, "Run each benchmark just once?"); |
(...skipping 11 matching lines...) Expand all Loading... | |
45 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); | 46 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
46 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); | 47 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); |
47 | 48 |
48 DEFINE_bool(cpu, true, "Master switch for CPU-bound work."); | 49 DEFINE_bool(cpu, true, "Master switch for CPU-bound work."); |
49 DEFINE_bool(gpu, true, "Master switch for GPU-bound work."); | 50 DEFINE_bool(gpu, true, "Master switch for GPU-bound work."); |
50 | 51 |
51 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); | 52 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
52 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc h."); | 53 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc h."); |
53 DEFINE_int32(maxCalibrationAttempts, 3, | 54 DEFINE_int32(maxCalibrationAttempts, 3, |
54 "Try up to this many times to guess loops for a bench, or skip the bench."); | 55 "Try up to this many times to guess loops for a bench, or skip the bench."); |
56 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON."); | |
57 DEFINE_string(gitHash, "", "Git hash to add to JSON."); | |
55 | 58 |
56 | 59 |
57 static SkString humanize(double ms) { | 60 static SkString humanize(double ms) { |
58 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); | 61 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); |
59 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); | 62 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); |
60 #ifdef SK_BUILD_FOR_WIN | 63 #ifdef SK_BUILD_FOR_WIN |
61 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); | 64 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); |
62 #else | 65 #else |
63 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); | 66 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); |
64 #endif | 67 #endif |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 GPU_TARGET(nvprmsaa16, GrContextFactory::kNVPR_GLContextType, _8888, 16) | 244 GPU_TARGET(nvprmsaa16, GrContextFactory::kNVPR_GLContextType, _8888, 16) |
242 GPU_TARGET(debug, GrContextFactory::kDebug_GLContextType, _8888, 0) | 245 GPU_TARGET(debug, GrContextFactory::kDebug_GLContextType, _8888, 0) |
243 GPU_TARGET(nullgpu, GrContextFactory::kNull_GLContextType, _8888, 0) | 246 GPU_TARGET(nullgpu, GrContextFactory::kNull_GLContextType, _8888, 0) |
244 #if SK_ANGLE | 247 #if SK_ANGLE |
245 GPU_TARGET(angle, GrContextFactory::kANGLE_GLContextType, _8888, 0) | 248 GPU_TARGET(angle, GrContextFactory::kANGLE_GLContextType, _8888, 0) |
246 #endif | 249 #endif |
247 } | 250 } |
248 #endif | 251 #endif |
249 } | 252 } |
250 | 253 |
251 static void fill_static_options(ResultsWriter* log) { | 254 static void fill_static_options(ResultsWriter* log) { |
mtklein
2014/07/17 13:41:16
Let's merge fill_static_options and fill_gpu_optio
jcgregorio
2014/07/17 19:13:22
Actually had to keep fill_gpu_options separate bec
| |
252 #if defined(SK_BUILD_FOR_WIN32) | 255 #if defined(SK_BUILD_FOR_WIN32) |
jcgregorio
2014/07/17 13:11:51
Are there any other values locked up in #defines t
mtklein
2014/07/17 13:41:16
We could probably also provide the CPU architectur
jcgregorio
2014/07/17 19:13:22
Those should come in via --key from the buildbot i
mtklein
2014/07/17 19:21:36
We could go arbitrarily fine... e.g., dump /proc/c
jcgregorio
2014/07/17 19:32:46
It does come from there, but it's not clean, it's
| |
253 log->option("system", "WIN32"); | 256 log->option("system", "WIN32"); |
254 #elif defined(SK_BUILD_FOR_MAC) | 257 #elif defined(SK_BUILD_FOR_MAC) |
255 log->option("system", "MAC"); | 258 log->option("system", "MAC"); |
256 #elif defined(SK_BUILD_FOR_ANDROID) | 259 #elif defined(SK_BUILD_FOR_ANDROID) |
257 log->option("system", "ANDROID"); | 260 log->option("system", "ANDROID"); |
258 #elif defined(SK_BUILD_FOR_UNIX) | 261 #elif defined(SK_BUILD_FOR_UNIX) |
259 log->option("system", "UNIX"); | 262 log->option("system", "UNIX"); |
260 #else | 263 #else |
261 log->option("system", "other"); | 264 log->option("system", "other"); |
262 #endif | 265 #endif |
263 #if defined(SK_DEBUG) | 266 } |
264 log->option("build", "DEBUG"); | 267 |
265 #else | 268 #if SK_SUPPORT_GPU |
266 log->option("build", "RELEASE"); | 269 static void fill_gpu_options(ResultsWriter* log) { |
270 if (!FLAGS_gpu) { | |
271 return; | |
272 } | |
273 | |
274 // Can't get a SkGLContextHelper until we've created a context of that type. | |
275 gGrFactory.get(GrContextFactory::kNative_GLContextType); | |
bsalomon
2014/07/17 13:35:04
We don't always want to use the kNative context. W
jcgregorio
2014/07/17 19:13:22
OK, changed it so that these are recorded per conf
| |
276 SkGLContextHelper* ctx = gGrFactory.getGLContext(GrContextFactory::kNative_G LContextType); | |
277 if (NULL != ctx) { | |
278 const GLubyte* version; | |
279 SK_GL_RET(*ctx, version, GetString(GR_GL_VERSION)); | |
280 log->option("GL_VERSION", (const char*)(version)); | |
281 | |
282 SK_GL_RET(*ctx, version, GetString(GR_GL_RENDERER)); | |
283 log->option("GL_RENDERER", (const char*) version); | |
284 | |
285 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR)); | |
286 log->option("GL_VENDOR", (const char*) version); | |
287 | |
288 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); | |
289 log->option("GL_SHADING_LANGUAGE_VERSION", (const char*) version); | |
290 } | |
291 gGrFactory.destroyContexts(); | |
292 } | |
267 #endif | 293 #endif |
268 } | |
269 | 294 |
270 int tool_main(int argc, char** argv); | 295 int tool_main(int argc, char** argv); |
271 int tool_main(int argc, char** argv) { | 296 int tool_main(int argc, char** argv) { |
272 SetupCrashHandler(); | 297 SetupCrashHandler(); |
273 SkAutoGraphics ag; | 298 SkAutoGraphics ag; |
274 SkCommandLineFlags::Parse(argc, argv); | 299 SkCommandLineFlags::Parse(argc, argv); |
275 | 300 |
276 if (FLAGS_runOnce) { | 301 if (FLAGS_runOnce) { |
277 FLAGS_samples = 1; | 302 FLAGS_samples = 1; |
278 FLAGS_gpuFrameLag = 0; | 303 FLAGS_gpuFrameLag = 0; |
279 } | 304 } |
280 | 305 |
281 MultiResultsWriter log; | 306 MultiResultsWriter log; |
282 SkAutoTDelete<JSONResultsWriter> json; | 307 SkAutoTDelete<NanoJSONResultsWriter> json; |
283 if (!FLAGS_outResultsFile.isEmpty()) { | 308 if (!FLAGS_outResultsFile.isEmpty()) { |
284 json.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0]))); | 309 const char* gitHash = FLAGS_gitHash.isEmpty() ? "" : FLAGS_gitHash[0]; |
mtklein
2014/07/17 13:41:16
"" -> "unknown-revision" perhaps?
jcgregorio
2014/07/17 19:13:22
Done.
| |
310 json.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0], gitHash) )); | |
285 log.add(json.get()); | 311 log.add(json.get()); |
286 } | 312 } |
287 CallEnd<MultiResultsWriter> ender(log); | 313 CallEnd<MultiResultsWriter> ender(log); |
mtklein
2014/07/17 13:41:16
One of log.end() or this line can go away right?
jcgregorio
2014/07/17 19:13:22
Done.
| |
314 | |
315 if (1 == FLAGS_key.count() % 2) { | |
316 SkDebugf("ERROR: --key must be passed with an even number of arguments.\ n"); | |
mtklein
2014/07/17 13:41:16
To be fair, you've written this in a way that we c
jcgregorio
2014/07/17 19:13:22
Acknowledged.
| |
317 return 1; | |
318 } | |
319 for (int i = 1; i < FLAGS_key.count(); i += 2) { | |
320 log.key(FLAGS_key[i-1], FLAGS_key[i]); | |
321 } | |
288 fill_static_options(&log); | 322 fill_static_options(&log); |
289 | 323 |
324 #if SK_SUPPORT_GPU | |
325 fill_gpu_options(&log); | |
326 #endif | |
327 | |
290 const double overhead = estimate_timer_overhead(); | 328 const double overhead = estimate_timer_overhead(); |
291 SkAutoTMalloc<double> samples(FLAGS_samples); | 329 SkAutoTMalloc<double> samples(FLAGS_samples); |
292 | 330 |
293 if (FLAGS_runOnce) { | 331 if (FLAGS_runOnce) { |
294 SkDebugf("--runOnce is true; times would only be misleading so we won't print them.\n"); | 332 SkDebugf("--runOnce is true; times would only be misleading so we won't print them.\n"); |
295 } else if (FLAGS_verbose) { | 333 } else if (FLAGS_verbose) { |
296 // No header. | 334 // No header. |
297 } else if (FLAGS_quiet) { | 335 } else if (FLAGS_quiet) { |
298 SkDebugf("median\tbench\tconfig\n"); | 336 SkDebugf("median\tbench\tconfig\n"); |
299 } else { | 337 } else { |
300 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n"); | 338 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n"); |
301 } | 339 } |
302 | 340 |
303 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next( )) { | 341 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next( )) { |
304 SkAutoTDelete<Benchmark> bench(r->factory()(NULL)); | 342 SkAutoTDelete<Benchmark> bench(r->factory()(NULL)); |
305 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { | 343 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { |
306 continue; | 344 continue; |
307 } | 345 } |
308 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY); | 346 bool loggedBench = false; |
309 | 347 |
310 SkTDArray<Target*> targets; | 348 SkTDArray<Target*> targets; |
311 create_targets(bench.get(), &targets); | 349 create_targets(bench.get(), &targets); |
mtklein
2014/07/17 13:41:16
Ah, gotcha. Let's do it here as
if (!targets.isE
jcgregorio
2014/07/17 19:13:23
Done.
| |
312 | 350 |
313 bench->preDraw(); | 351 bench->preDraw(); |
314 for (int j = 0; j < targets.count(); j++) { | 352 for (int j = 0; j < targets.count(); j++) { |
315 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL; | 353 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL; |
316 const char* config = targets[j]->config; | 354 const char* config = targets[j]->config; |
317 | 355 |
318 const int loops = | 356 const int loops = |
319 #if SK_SUPPORT_GPU | 357 #if SK_SUPPORT_GPU |
320 Benchmark::kGPU_Backend == targets[j]->backend | 358 Benchmark::kGPU_Backend == targets[j]->backend |
321 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) | 359 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) |
322 : | 360 : |
323 #endif | 361 #endif |
324 cpu_bench( overhead, bench.get(), canvas, samples.get()); | 362 cpu_bench( overhead, bench.get(), canvas, samples.get()); |
325 | 363 |
326 if (loops == 0) { | 364 if (loops == 0) { |
327 SkDebugf("Unable to time %s\t%s (overhead %s)\n", | 365 SkDebugf("Unable to time %s\t%s (overhead %s)\n", |
328 bench->getName(), config, humanize(overhead).c_str()); | 366 bench->getName(), config, humanize(overhead).c_str()); |
329 continue; | 367 continue; |
330 } | 368 } |
369 if (!loggedBench) { | |
370 log.bench(bench->getName(), bench->getSize().fX, bench->getSize( ).fY); | |
371 loggedBench = true; | |
372 } | |
331 | 373 |
332 Stats stats(samples.get(), FLAGS_samples); | 374 Stats stats(samples.get(), FLAGS_samples); |
333 log.config(config); | 375 log.config(config); |
334 log.timer("min_ms", stats.min); | 376 log.timer("min_ms", stats.min); |
335 log.timer("median_ms", stats.median); | 377 log.timer("median_ms", stats.median); |
336 log.timer("mean_ms", stats.mean); | 378 log.timer("mean_ms", stats.mean); |
337 log.timer("max_ms", stats.max); | 379 log.timer("max_ms", stats.max); |
338 log.timer("stddev_ms", sqrt(stats.var)); | 380 log.timer("stddev_ms", sqrt(stats.var)); |
339 | 381 |
340 if (FLAGS_runOnce) { | 382 if (FLAGS_runOnce) { |
(...skipping 27 matching lines...) Expand all Loading... | |
368 } | 410 } |
369 } | 411 } |
370 targets.deleteAll(); | 412 targets.deleteAll(); |
371 | 413 |
372 #if SK_SUPPORT_GPU | 414 #if SK_SUPPORT_GPU |
373 if (FLAGS_resetGpuContext) { | 415 if (FLAGS_resetGpuContext) { |
374 gGrFactory.destroyContexts(); | 416 gGrFactory.destroyContexts(); |
375 } | 417 } |
376 #endif | 418 #endif |
377 } | 419 } |
420 log.end(); | |
378 | 421 |
379 return 0; | 422 return 0; |
380 } | 423 } |
381 | 424 |
382 #if !defined SK_BUILD_FOR_IOS | 425 #if !defined SK_BUILD_FOR_IOS |
383 int main(int argc, char * const argv[]) { | 426 int main(int argc, char * const argv[]) { |
384 return tool_main(argc, (char**) argv); | 427 return tool_main(argc, (char**) argv); |
385 } | 428 } |
386 #endif | 429 #endif |
OLD | NEW |