Chromium Code Reviews| 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 "DecodingBench.h" | |
| 13 #include "DecodingSubsetBench.h" | |
| 12 #include "GMBench.h" | 14 #include "GMBench.h" |
| 13 #include "ProcStats.h" | 15 #include "ProcStats.h" |
| 14 #include "ResultsWriter.h" | 16 #include "ResultsWriter.h" |
| 15 #include "RecordingBench.h" | 17 #include "RecordingBench.h" |
| 18 #include "Resources.h" | |
| 16 #include "SKPBench.h" | 19 #include "SKPBench.h" |
| 17 #include "Stats.h" | 20 #include "Stats.h" |
| 18 #include "Timer.h" | 21 #include "Timer.h" |
| 19 | 22 |
| 20 #include "SkBBoxHierarchy.h" | 23 #include "SkBBoxHierarchy.h" |
| 21 #include "SkCanvas.h" | 24 #include "SkCanvas.h" |
| 22 #include "SkCommonFlags.h" | 25 #include "SkCommonFlags.h" |
| 23 #include "SkForceLinking.h" | 26 #include "SkForceLinking.h" |
| 24 #include "SkGraphics.h" | 27 #include "SkGraphics.h" |
| 25 #include "SkOSFile.h" | 28 #include "SkOSFile.h" |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 } | 435 } |
| 433 #endif | 436 #endif |
| 434 | 437 |
| 435 class BenchmarkStream { | 438 class BenchmarkStream { |
| 436 public: | 439 public: |
| 437 BenchmarkStream() : fBenches(BenchRegistry::Head()) | 440 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
| 438 , fGMs(skiagm::GMRegistry::Head()) | 441 , fGMs(skiagm::GMRegistry::Head()) |
| 439 , fCurrentRecording(0) | 442 , fCurrentRecording(0) |
| 440 , fCurrentScale(0) | 443 , fCurrentScale(0) |
| 441 , fCurrentSKP(0) | 444 , fCurrentSKP(0) |
| 442 , fCurrentUseMPD(0) { | 445 , fCurrentUseMPD(0) |
| 446 , fCurrentImage(0) | |
| 447 , fCurrentSubsetImage(0) | |
| 448 , fCurrentColorType(0) | |
| 449 , fDivisor(2) | |
| 450 , fSubsetFailSilent(false) { | |
| 443 for (int i = 0; i < FLAGS_skps.count(); i++) { | 451 for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 444 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 452 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
| 445 fSKPs.push_back() = FLAGS_skps[i]; | 453 fSKPs.push_back() = FLAGS_skps[i]; |
| 446 } else { | 454 } else { |
| 447 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 455 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
| 448 SkString path; | 456 SkString path; |
| 449 while (it.next(&path)) { | 457 while (it.next(&path)) { |
| 450 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); | 458 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); |
| 451 } | 459 } |
| 452 } | 460 } |
| 453 } | 461 } |
| 454 | 462 |
| 455 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", | 463 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
| 456 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) { | 464 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) { |
| 457 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]); | 465 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]); |
| 458 exit(1); | 466 exit(1); |
| 459 } | 467 } |
| 460 | 468 |
| 461 for (int i = 0; i < FLAGS_scales.count(); i++) { | 469 for (int i = 0; i < FLAGS_scales.count(); i++) { |
| 462 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { | 470 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { |
| 463 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]); | 471 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]); |
| 464 exit(1); | 472 exit(1); |
| 465 } | 473 } |
| 466 } | 474 } |
| 467 | 475 |
| 468 fUseMPDs.push_back() = false; | 476 fUseMPDs.push_back() = false; |
| 469 if (FLAGS_mpd) { | 477 if (FLAGS_mpd) { |
| 470 fUseMPDs.push_back() = true; | 478 fUseMPDs.push_back() = true; |
| 471 } | 479 } |
| 480 | |
| 481 // Prepare the images for decoding | |
| 482 for (int i = 0; i < FLAGS_images.count(); i++) { | |
| 483 const char* flag = FLAGS_images[i]; | |
| 484 if (sk_isdir(flag)) { | |
| 485 // If the value passed in is a directory, add all the images | |
| 486 SkOSFile::Iter it(flag); | |
| 487 SkString file; | |
| 488 while (it.next(&file)) { | |
| 489 fImages.push_back() = SkOSPath::Join(flag, file.c_str()); | |
| 490 } | |
| 491 } else if (sk_exists(flag)) { | |
| 492 // Also add the value if it is a single image | |
| 493 fImages.push_back() = flag; | |
| 494 } | |
| 495 } | |
| 496 | |
| 497 // Choose the candidate color types for image decoding | |
| 498 const SkColorType colorTypes[] = | |
| 499 { kN32_SkColorType, kRGB_565_SkColorType, kAlpha_8_SkColorType }; | |
| 500 fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes); | |
| 472 } | 501 } |
| 473 | 502 |
| 474 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { | 503 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { |
| 475 // Not strictly necessary, as it will be checked again later, | 504 // Not strictly necessary, as it will be checked again later, |
| 476 // but helps to avoid a lot of pointless work if we're going to skip it. | 505 // but helps to avoid a lot of pointless work if we're going to skip it. |
| 477 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { | 506 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { |
| 478 return false; | 507 return false; |
| 479 } | 508 } |
| 480 | 509 |
| 481 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); | 510 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 (name.c_str(), pic.get(), fClip, | 584 (name.c_str(), pic.get(), fClip, |
| 556 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]) ); | 585 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]) ); |
| 557 } | 586 } |
| 558 fCurrentUseMPD = 0; | 587 fCurrentUseMPD = 0; |
| 559 fCurrentSKP++; | 588 fCurrentSKP++; |
| 560 } | 589 } |
| 561 fCurrentSKP = 0; | 590 fCurrentSKP = 0; |
| 562 fCurrentScale++; | 591 fCurrentScale++; |
| 563 } | 592 } |
| 564 | 593 |
| 594 // Run the DecodingBenches | |
| 595 SkString file; | |
| 596 while (fCurrentImage < fImages.count()) { | |
| 597 while (fCurrentColorType < fColorTypes.count()) { | |
| 598 const SkString& path = fImages[fCurrentImage]; | |
| 599 SkColorType colorType = fColorTypes[fCurrentColorType]; | |
| 600 fCurrentColorType++; | |
| 601 // Check if the image decodes before creating the benchmark | |
| 602 SkBitmap bitmap; | |
| 603 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, | |
| 604 colorType, SkImageDecoder::kDecodePixels_Mode)) { | |
| 605 return SkNEW_ARGS(DecodingBench, (path, colorType)); | |
| 606 } | |
| 607 } | |
| 608 fCurrentColorType = 0; | |
| 609 fCurrentImage++; | |
| 610 } | |
| 611 | |
| 612 // Run the DecodingSubsetBenches | |
| 613 while (fCurrentSubsetImage < fImages.count()) { | |
| 614 while (fCurrentColorType < fColorTypes.count()) { | |
| 615 const SkString& path = fImages[fCurrentSubsetImage]; | |
| 616 SkColorType colorType = fColorTypes[fCurrentColorType]; | |
| 617 fCurrentColorType++; | |
| 618 // Check if the image decodes before creating the benchmark | |
| 619 SkAutoTUnref<SkData> encoded( | |
| 620 SkData::NewFromFileName(path.c_str())); | |
| 621 SkAutoTDelete<SkMemoryStream> stream( | |
| 622 new SkMemoryStream(encoded)); | |
| 623 SkAutoTDelete<SkImageDecoder> | |
| 624 decoder(SkImageDecoder::Factory(stream.get())); | |
| 625 if (!decoder) { | |
| 626 SkDebugf("Cannot find decoder for %s\n", path.c_str()); | |
| 627 } else { | |
| 628 stream->rewind(); | |
| 629 int w, h; | |
| 630 bool success; | |
| 631 if (!decoder->buildTileIndex(stream.detach(), &w, &h) | |
| 632 || w*h == 1) { | |
| 633 if (!fSubsetFailSilent) { | |
| 634 SkDebugf("Subset decode is not supported for %s\n", | |
| 635 path.c_str()); | |
| 636 fSubsetFailSilent = true; | |
|
scroggo
2015/02/12 19:53:29
I think this should likely just be silent all the
msarett
2015/02/12 22:05:46
Sounds good.
| |
| 637 } | |
| 638 success = false; | |
| 639 } else if (fDivisor > w || fDivisor > h) { | |
| 640 SkDebugf("Divisor %d is too big for %s %dx%d\n", | |
| 641 fDivisor, path.c_str(), w, h); | |
| 642 success = false; | |
| 643 } else { | |
| 644 const int sW = w / fDivisor; | |
| 645 const int sH = h / fDivisor; | |
| 646 SkBitmap bitmap; | |
| 647 success = true; | |
| 648 for (int y = 0; y < h; y += sH) { | |
| 649 for (int x = 0; x < w; x += sW) { | |
| 650 SkIRect rect = SkIRect::MakeXYWH(x, y, sW, sH); | |
| 651 success &= decoder->decodeSubset(&bitmap, rect, | |
| 652 colorType); | |
| 653 } | |
| 654 } | |
| 655 } | |
| 656 // Create the benchmark if successful | |
| 657 if (success) { | |
| 658 return SkNEW_ARGS(DecodingSubsetBench, | |
| 659 (path, colorType, fDivisor)); | |
| 660 } | |
| 661 } | |
| 662 } | |
| 663 fCurrentColorType = 0; | |
| 664 fCurrentSubsetImage++; | |
| 665 } | |
| 666 | |
| 565 return NULL; | 667 return NULL; |
| 566 } | 668 } |
| 567 | 669 |
| 568 void fillCurrentOptions(ResultsWriter* log) const { | 670 void fillCurrentOptions(ResultsWriter* log) const { |
| 569 log->configOption("source_type", fSourceType); | 671 log->configOption("source_type", fSourceType); |
| 570 log->configOption("bench_type", fBenchType); | 672 log->configOption("bench_type", fBenchType); |
| 571 if (0 == strcmp(fSourceType, "skp")) { | 673 if (0 == strcmp(fSourceType, "skp")) { |
| 572 log->configOption("clip", | 674 log->configOption("clip", |
| 573 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, | 675 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
| 574 fClip.fRight, fClip.fBottom).c _str()); | 676 fClip.fRight, fClip.fBottom).c _str()); |
| 575 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); | 677 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); |
| 576 if (fCurrentUseMPD > 0) { | 678 if (fCurrentUseMPD > 0) { |
| 577 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); | 679 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
| 578 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); | 680 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); |
| 579 } | 681 } |
| 580 } | 682 } |
| 581 if (0 == strcmp(fBenchType, "recording")) { | 683 if (0 == strcmp(fBenchType, "recording")) { |
| 582 log->metric("bytes", fSKPBytes); | 684 log->metric("bytes", fSKPBytes); |
| 583 log->metric("ops", fSKPOps); | 685 log->metric("ops", fSKPOps); |
| 584 } | 686 } |
| 585 } | 687 } |
| 586 | 688 |
| 587 private: | 689 private: |
| 588 const BenchRegistry* fBenches; | 690 const BenchRegistry* fBenches; |
| 589 const skiagm::GMRegistry* fGMs; | 691 const skiagm::GMRegistry* fGMs; |
| 590 SkIRect fClip; | 692 SkIRect fClip; |
| 591 SkTArray<SkScalar> fScales; | 693 SkTArray<SkScalar> fScales; |
| 592 SkTArray<SkString> fSKPs; | 694 SkTArray<SkString> fSKPs; |
| 593 SkTArray<bool> fUseMPDs; | 695 SkTArray<bool> fUseMPDs; |
| 696 SkTArray<SkString> fImages; | |
| 697 SkTArray<SkColorType> fColorTypes; | |
| 594 | 698 |
| 595 double fSKPBytes, fSKPOps; | 699 double fSKPBytes, fSKPOps; |
| 596 | 700 |
| 597 const char* fSourceType; // What we're benching: bench, GM, SKP, ... | 701 const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
| 598 const char* fBenchType; // How we bench it: micro, recording, playback, .. . | 702 const char* fBenchType; // How we bench it: micro, recording, playback, .. . |
| 599 int fCurrentRecording; | 703 int fCurrentRecording; |
| 600 int fCurrentScale; | 704 int fCurrentScale; |
| 601 int fCurrentSKP; | 705 int fCurrentSKP; |
| 602 int fCurrentUseMPD; | 706 int fCurrentUseMPD; |
| 707 int fCurrentImage; | |
| 708 int fCurrentSubsetImage; | |
| 709 int fCurrentColorType; | |
| 710 const int fDivisor; | |
| 711 bool fSubsetFailSilent; | |
| 603 }; | 712 }; |
| 604 | 713 |
| 605 int nanobench_main(); | 714 int nanobench_main(); |
| 606 int nanobench_main() { | 715 int nanobench_main() { |
| 607 SetupCrashHandler(); | 716 SetupCrashHandler(); |
| 608 SkAutoGraphics ag; | 717 SkAutoGraphics ag; |
| 609 SkTaskGroup::Enabler enabled; | 718 SkTaskGroup::Enabler enabled; |
| 610 | 719 |
| 611 #if SK_SUPPORT_GPU | 720 #if SK_SUPPORT_GPU |
| 612 GrContext::Options grContextOpts; | 721 GrContext::Options grContextOpts; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 | 902 |
| 794 return 0; | 903 return 0; |
| 795 } | 904 } |
| 796 | 905 |
| 797 #if !defined SK_BUILD_FOR_IOS | 906 #if !defined SK_BUILD_FOR_IOS |
| 798 int main(int argc, char** argv) { | 907 int main(int argc, char** argv) { |
| 799 SkCommandLineFlags::Parse(argc, argv); | 908 SkCommandLineFlags::Parse(argc, argv); |
| 800 return nanobench_main(); | 909 return nanobench_main(); |
| 801 } | 910 } |
| 802 #endif | 911 #endif |
| OLD | NEW |