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 "GMBench.h" | 12 #include "GMBench.h" |
13 #include "ResultsWriter.h" | 13 #include "ResultsWriter.h" |
| 14 #include "SKPBench.h" |
14 #include "Stats.h" | 15 #include "Stats.h" |
15 #include "Timer.h" | 16 #include "Timer.h" |
16 | 17 |
| 18 #include "SkOSFile.h" |
17 #include "SkCanvas.h" | 19 #include "SkCanvas.h" |
18 #include "SkCommonFlags.h" | 20 #include "SkCommonFlags.h" |
19 #include "SkForceLinking.h" | 21 #include "SkForceLinking.h" |
20 #include "SkGraphics.h" | 22 #include "SkGraphics.h" |
21 #include "SkString.h" | 23 #include "SkString.h" |
22 #include "SkSurface.h" | 24 #include "SkSurface.h" |
23 | 25 |
24 #if SK_SUPPORT_GPU | 26 #if SK_SUPPORT_GPU |
25 #include "gl/GrGLDefines.h" | 27 #include "gl/GrGLDefines.h" |
26 #include "GrContextFactory.h" | 28 #include "GrContextFactory.h" |
(...skipping 15 matching lines...) Expand all Loading... |
42 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); | 44 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
43 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow
s to lag."); | 45 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow
s to lag."); |
44 | 46 |
45 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); | 47 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
46 DEFINE_int32(maxCalibrationAttempts, 3, | 48 DEFINE_int32(maxCalibrationAttempts, 3, |
47 "Try up to this many times to guess loops for a bench, or skip the
bench."); | 49 "Try up to this many times to guess loops for a bench, or skip the
bench."); |
48 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); | 50 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); |
49 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON."); | 51 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON."); |
50 DEFINE_string(gitHash, "", "Git hash to add to JSON."); | 52 DEFINE_string(gitHash, "", "Git hash to add to JSON."); |
51 | 53 |
| 54 DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); |
| 55 DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); |
| 56 |
52 static SkString humanize(double ms) { | 57 static SkString humanize(double ms) { |
53 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); | 58 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); |
54 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); | 59 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); |
55 #ifdef SK_BUILD_FOR_WIN | 60 #ifdef SK_BUILD_FOR_WIN |
56 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); | 61 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); |
57 #else | 62 #else |
58 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); | 63 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); |
59 #endif | 64 #endif |
60 return SkStringPrintf("%.3gms", ms); | 65 return SkStringPrintf("%.3gms", ms); |
61 } | 66 } |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR)); | 355 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR)); |
351 log->configOption("GL_VENDOR", (const char*) version); | 356 log->configOption("GL_VENDOR", (const char*) version); |
352 | 357 |
353 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); | 358 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
354 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); | 359 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); |
355 } | 360 } |
356 #endif | 361 #endif |
357 | 362 |
358 class BenchmarkStream { | 363 class BenchmarkStream { |
359 public: | 364 public: |
360 BenchmarkStream() : fBenches(BenchRegistry::Head()) , fGMs(skiagm::GMRegistr
y::Head()) {} | 365 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
| 366 , fGMs(skiagm::GMRegistry::Head()) |
| 367 , fCurrentScale(0) |
| 368 , fCurrentSKP(0) { |
| 369 for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 370 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
| 371 fSKPs.push_back() = FLAGS_skps[i]; |
| 372 } else { |
| 373 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
| 374 SkString path; |
| 375 while (it.next(&path)) { |
| 376 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str
()); |
| 377 } |
| 378 } |
| 379 } |
361 | 380 |
362 Benchmark* next(const char** sourceType) { | 381 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
| 382 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom
)) { |
| 383 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0
]); |
| 384 exit(1); |
| 385 } |
| 386 |
| 387 for (int i = 0; i < FLAGS_scales.count(); i++) { |
| 388 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { |
| 389 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS
_scales[i]); |
| 390 exit(1); |
| 391 } |
| 392 } |
| 393 } |
| 394 |
| 395 Benchmark* next() { |
363 if (fBenches) { | 396 if (fBenches) { |
364 Benchmark* bench = fBenches->factory()(NULL); | 397 Benchmark* bench = fBenches->factory()(NULL); |
365 fBenches = fBenches->next(); | 398 fBenches = fBenches->next(); |
366 *sourceType = "bench"; | 399 fSourceType = "bench"; |
367 return bench; | 400 return bench; |
368 } | 401 } |
| 402 |
369 while (fGMs) { | 403 while (fGMs) { |
370 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); | 404 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); |
371 fGMs = fGMs->next(); | 405 fGMs = fGMs->next(); |
372 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) { | 406 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) { |
373 *sourceType = "gm"; | 407 fSourceType = "gm"; |
374 return SkNEW_ARGS(GMBench, (gm.detach())); | 408 return SkNEW_ARGS(GMBench, (gm.detach())); |
375 } | 409 } |
376 } | 410 } |
| 411 |
| 412 while (fCurrentScale < fScales.count()) { |
| 413 while (fCurrentSKP < fSKPs.count()) { |
| 414 const SkString& path = fSKPs[fCurrentSKP++]; |
| 415 |
| 416 // Not strictly necessary, as it will be checked again later, |
| 417 // but helps to avoid a lot of pointless work if we're going to
skip it. |
| 418 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
| 419 continue; |
| 420 } |
| 421 |
| 422 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str()
)); |
| 423 if (stream.get() == NULL) { |
| 424 SkDebugf("Could not read %s.\n", path.c_str()); |
| 425 exit(1); |
| 426 } |
| 427 |
| 428 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.g
et())); |
| 429 if (pic.get() == NULL) { |
| 430 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str(
)); |
| 431 exit(1); |
| 432 } |
| 433 |
| 434 SkString name = SkOSPath::Basename(path.c_str()); |
| 435 |
| 436 fSourceType = "skp"; |
| 437 return SkNEW_ARGS(SKPBench, |
| 438 (name.c_str(), pic.get(), fClip, fScales[fCurrentScale])
); |
| 439 } |
| 440 fCurrentSKP = 0; |
| 441 fCurrentScale++; |
| 442 } |
| 443 |
377 return NULL; | 444 return NULL; |
378 } | 445 } |
| 446 |
| 447 void fillCurrentOptions(ResultsWriter* log) const { |
| 448 log->configOption("source_type", fSourceType); |
| 449 if (0 == strcmp(fSourceType, "skp")) { |
| 450 log->configOption("clip", |
| 451 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
| 452 fClip.fRight, fClip.fBottom).c
_str()); |
| 453 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc
ale]).c_str()); |
| 454 } |
| 455 } |
| 456 |
379 private: | 457 private: |
380 const BenchRegistry* fBenches; | 458 const BenchRegistry* fBenches; |
381 const skiagm::GMRegistry* fGMs; | 459 const skiagm::GMRegistry* fGMs; |
| 460 SkIRect fClip; |
| 461 SkTArray<SkScalar> fScales; |
| 462 SkTArray<SkString> fSKPs; |
| 463 |
| 464 const char* fSourceType; |
| 465 int fCurrentScale; |
| 466 int fCurrentSKP; |
382 }; | 467 }; |
383 | 468 |
384 int nanobench_main(); | 469 int nanobench_main(); |
385 int nanobench_main() { | 470 int nanobench_main() { |
386 SetupCrashHandler(); | 471 SetupCrashHandler(); |
387 SkAutoGraphics ag; | 472 SkAutoGraphics ag; |
388 | 473 |
389 if (FLAGS_runOnce) { | 474 if (FLAGS_runOnce) { |
390 FLAGS_samples = 1; | 475 FLAGS_samples = 1; |
391 FLAGS_gpuFrameLag = 0; | 476 FLAGS_gpuFrameLag = 0; |
(...skipping 28 matching lines...) Expand all Loading... |
420 // No header. | 505 // No header. |
421 } else if (FLAGS_quiet) { | 506 } else if (FLAGS_quiet) { |
422 SkDebugf("median\tbench\tconfig\n"); | 507 SkDebugf("median\tbench\tconfig\n"); |
423 } else { | 508 } else { |
424 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\
n"); | 509 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\
n"); |
425 } | 510 } |
426 | 511 |
427 SkTDArray<Config> configs; | 512 SkTDArray<Config> configs; |
428 create_configs(&configs); | 513 create_configs(&configs); |
429 | 514 |
430 BenchmarkStream benches; | 515 BenchmarkStream benchStream; |
431 const char* sourceType; | 516 while (Benchmark* b = benchStream.next()) { |
432 while (Benchmark* b = benches.next(&sourceType)) { | |
433 SkAutoTDelete<Benchmark> bench(b); | 517 SkAutoTDelete<Benchmark> bench(b); |
434 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { | 518 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { |
435 continue; | 519 continue; |
436 } | 520 } |
437 | 521 |
438 SkTDArray<Target*> targets; | 522 SkTDArray<Target*> targets; |
439 create_targets(&targets, bench.get(), configs); | 523 create_targets(&targets, bench.get(), configs); |
440 | 524 |
441 if (!targets.isEmpty()) { | 525 if (!targets.isEmpty()) { |
442 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY
); | 526 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY
); |
443 bench->preDraw(); | 527 bench->preDraw(); |
444 } | 528 } |
445 for (int j = 0; j < targets.count(); j++) { | 529 for (int j = 0; j < targets.count(); j++) { |
446 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->
getCanvas() : NULL; | 530 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->
getCanvas() : NULL; |
447 const char* config = targets[j]->config.name; | 531 const char* config = targets[j]->config.name; |
448 | 532 |
| 533 #if SK_DEBUG |
| 534 // skia:2797 Some SKPs SkASSERT in debug mode. Skip them for now. |
| 535 if (0 == strcmp("565", config) |
| 536 && ( SkStrStartsWith(bench->getName(), "desk_carsvg.skp") |
| 537 || SkStrStartsWith(bench->getName(), "desk_forecastio.skp
") |
| 538 || SkStrStartsWith(bench->getName(), "tabl_cnet.skp") |
| 539 || SkStrStartsWith(bench->getName(), "tabl_googlecalendar
.skp"))) { |
| 540 SkDebugf("Skipping 565 %s. It'd assert.\n", bench->getName()); |
| 541 continue; |
| 542 } |
| 543 #endif |
| 544 |
449 const int loops = | 545 const int loops = |
450 #if SK_SUPPORT_GPU | 546 #if SK_SUPPORT_GPU |
451 Benchmark::kGPU_Backend == targets[j]->config.backend | 547 Benchmark::kGPU_Backend == targets[j]->config.backend |
452 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) | 548 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) |
453 : | 549 : |
454 #endif | 550 #endif |
455 cpu_bench( overhead, bench.get(), canvas, samples.get()); | 551 cpu_bench( overhead, bench.get(), canvas, samples.get()); |
456 | 552 |
457 if (loops == 0) { | 553 if (loops == 0) { |
458 SkDebugf("Unable to time %s\t%s (overhead %s)\n", | 554 SkDebugf("Unable to time %s\t%s (overhead %s)\n", |
459 bench->getName(), config, HUMANIZE(overhead)); | 555 bench->getName(), config, HUMANIZE(overhead)); |
460 continue; | 556 continue; |
461 } | 557 } |
462 | 558 |
463 Stats stats(samples.get(), FLAGS_samples); | 559 Stats stats(samples.get(), FLAGS_samples); |
464 log.config(config); | 560 log.config(config); |
465 log.configOption("source_type", sourceType); | 561 benchStream.fillCurrentOptions(&log); |
466 #if SK_SUPPORT_GPU | 562 #if SK_SUPPORT_GPU |
467 if (Benchmark::kGPU_Backend == targets[j]->config.backend) { | 563 if (Benchmark::kGPU_Backend == targets[j]->config.backend) { |
468 fill_gpu_options(&log, targets[j]->gl); | 564 fill_gpu_options(&log, targets[j]->gl); |
469 } | 565 } |
470 #endif | 566 #endif |
471 log.timer("min_ms", stats.min); | 567 log.timer("min_ms", stats.min); |
472 log.timer("median_ms", stats.median); | 568 log.timer("median_ms", stats.median); |
473 log.timer("mean_ms", stats.mean); | 569 log.timer("mean_ms", stats.mean); |
474 log.timer("max_ms", stats.max); | 570 log.timer("max_ms", stats.max); |
475 log.timer("stddev_ms", sqrt(stats.var)); | 571 log.timer("stddev_ms", sqrt(stats.var)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 614 |
519 return 0; | 615 return 0; |
520 } | 616 } |
521 | 617 |
522 #if !defined SK_BUILD_FOR_IOS | 618 #if !defined SK_BUILD_FOR_IOS |
523 int main(int argc, char** argv) { | 619 int main(int argc, char** argv) { |
524 SkCommandLineFlags::Parse(argc, argv); | 620 SkCommandLineFlags::Parse(argc, argv); |
525 return nanobench_main(); | 621 return nanobench_main(); |
526 } | 622 } |
527 #endif | 623 #endif |
OLD | NEW |