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