| 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 "nanobench.h" | 10 #include "nanobench.h" |
| 11 | 11 |
| 12 #include "AndroidCodecBench.h" |
| 12 #include "Benchmark.h" | 13 #include "Benchmark.h" |
| 13 #include "BitmapRegionDecoderBench.h" | 14 #include "BitmapRegionDecoderBench.h" |
| 14 #include "CodecBench.h" | 15 #include "CodecBench.h" |
| 15 #include "CodecBenchPriv.h" | 16 #include "CodecBenchPriv.h" |
| 16 #include "CrashHandler.h" | 17 #include "CrashHandler.h" |
| 17 #include "GMBench.h" | 18 #include "GMBench.h" |
| 18 #include "ProcStats.h" | 19 #include "ProcStats.h" |
| 19 #include "ResultsWriter.h" | 20 #include "ResultsWriter.h" |
| 20 #include "RecordingBench.h" | 21 #include "RecordingBench.h" |
| 21 #include "SKPAnimationBench.h" | 22 #include "SKPAnimationBench.h" |
| 22 #include "SKPBench.h" | 23 #include "SKPBench.h" |
| 23 #include "Stats.h" | 24 #include "Stats.h" |
| 24 | 25 |
| 26 #include "SkAndroidCodec.h" |
| 25 #include "SkBitmapRegionDecoder.h" | 27 #include "SkBitmapRegionDecoder.h" |
| 26 #include "SkBBoxHierarchy.h" | 28 #include "SkBBoxHierarchy.h" |
| 27 #include "SkCanvas.h" | 29 #include "SkCanvas.h" |
| 28 #include "SkCodec.h" | 30 #include "SkCodec.h" |
| 29 #include "SkCommonFlags.h" | 31 #include "SkCommonFlags.h" |
| 30 #include "SkCommonFlagsConfig.h" | 32 #include "SkCommonFlagsConfig.h" |
| 31 #include "SkData.h" | 33 #include "SkData.h" |
| 32 #include "SkForceLinking.h" | 34 #include "SkForceLinking.h" |
| 33 #include "SkGraphics.h" | 35 #include "SkGraphics.h" |
| 34 #include "SkOSFile.h" | 36 #include "SkOSFile.h" |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 541 |
| 540 class BenchmarkStream { | 542 class BenchmarkStream { |
| 541 public: | 543 public: |
| 542 BenchmarkStream() : fBenches(BenchRegistry::Head()) | 544 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
| 543 , fGMs(skiagm::GMRegistry::Head()) | 545 , fGMs(skiagm::GMRegistry::Head()) |
| 544 , fCurrentRecording(0) | 546 , fCurrentRecording(0) |
| 545 , fCurrentScale(0) | 547 , fCurrentScale(0) |
| 546 , fCurrentSKP(0) | 548 , fCurrentSKP(0) |
| 547 , fCurrentUseMPD(0) | 549 , fCurrentUseMPD(0) |
| 548 , fCurrentCodec(0) | 550 , fCurrentCodec(0) |
| 551 , fCurrentAndroidCodec(0) |
| 549 , fCurrentBRDImage(0) | 552 , fCurrentBRDImage(0) |
| 550 , fCurrentColorType(0) | 553 , fCurrentColorType(0) |
| 551 , fCurrentAlphaType(0) | 554 , fCurrentAlphaType(0) |
| 552 , fCurrentSubsetType(0) | 555 , fCurrentSubsetType(0) |
| 553 , fCurrentBRDStrategy(0) | 556 , fCurrentBRDStrategy(0) |
| 554 , fCurrentBRDSampleSize(0) | 557 , fCurrentSampleSize(0) |
| 555 , fCurrentAnimSKP(0) { | 558 , fCurrentAnimSKP(0) { |
| 556 for (int i = 0; i < FLAGS_skps.count(); i++) { | 559 for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 557 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 560 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
| 558 fSKPs.push_back() = FLAGS_skps[i]; | 561 fSKPs.push_back() = FLAGS_skps[i]; |
| 559 } else { | 562 } else { |
| 560 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 563 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
| 561 SkString path; | 564 SkString path; |
| 562 while (it.next(&path)) { | 565 while (it.next(&path)) { |
| 563 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str
()); | 566 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str
()); |
| 564 } | 567 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 break; | 793 break; |
| 791 default: | 794 default: |
| 792 // This represents some sort of failure. | 795 // This represents some sort of failure. |
| 793 SkASSERT(false); | 796 SkASSERT(false); |
| 794 break; | 797 break; |
| 795 } | 798 } |
| 796 } | 799 } |
| 797 fCurrentColorType = 0; | 800 fCurrentColorType = 0; |
| 798 } | 801 } |
| 799 | 802 |
| 803 // Run AndroidCodecBenches |
| 804 const int sampleSizes[] = { 2, 4, 8 }; |
| 805 for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) { |
| 806 fSourceType = "image"; |
| 807 fBenchType = "skandroidcodec"; |
| 808 |
| 809 const SkString& path = fImages[fCurrentAndroidCodec]; |
| 810 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
| 811 continue; |
| 812 } |
| 813 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 814 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(enco
ded)); |
| 815 if (!codec) { |
| 816 // Nothing to time. |
| 817 SkDebugf("Cannot find codec for %s\n", path.c_str()); |
| 818 continue; |
| 819 } |
| 820 |
| 821 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) { |
| 822 int sampleSize = sampleSizes[fCurrentSampleSize]; |
| 823 fCurrentSampleSize++; |
| 824 if (10 * sampleSize > SkTMin(codec->getInfo().width(), codec->ge
tInfo().height())) { |
| 825 // Avoid benchmarking scaled decodes of already small images
. |
| 826 break; |
| 827 } |
| 828 |
| 829 return new AndroidCodecBench(SkOSPath::Basename(path.c_str()), e
ncoded, sampleSize); |
| 830 } |
| 831 fCurrentSampleSize = 0; |
| 832 } |
| 833 |
| 800 // Run the BRDBenches | 834 // Run the BRDBenches |
| 801 // We will benchmark multiple BRD strategies. | 835 // We will benchmark multiple BRD strategies. |
| 802 static const struct { | 836 static const struct { |
| 803 SkBitmapRegionDecoder::Strategy fStrategy; | 837 SkBitmapRegionDecoder::Strategy fStrategy; |
| 804 const char* fName; | 838 const char* fName; |
| 805 } strategies[] = { | 839 } strategies[] = { |
| 806 { SkBitmapRegionDecoder::kCanvas_Strategy, "BRD_canvas" }, | 840 { SkBitmapRegionDecoder::kCanvas_Strategy, "BRD_canvas" }, |
| 807 { SkBitmapRegionDecoder::kAndroidCodec_Strategy, "BRD_android_codec"
}, | 841 { SkBitmapRegionDecoder::kAndroidCodec_Strategy, "BRD_android_codec"
}, |
| 808 }; | 842 }; |
| 809 | 843 |
| 810 // We intend to create benchmarks that model the use cases in | 844 // We intend to create benchmarks that model the use cases in |
| 811 // android/libraries/social/tiledimage. In this library, an image is de
coded in 512x512 | 845 // android/libraries/social/tiledimage. In this library, an image is de
coded in 512x512 |
| 812 // tiles. The image can be translated freely, so the location of a tile
may be anywhere in | 846 // tiles. The image can be translated freely, so the location of a tile
may be anywhere in |
| 813 // the image. For that reason, we will benchmark decodes in five repres
entative locations | 847 // the image. For that reason, we will benchmark decodes in five repres
entative locations |
| 814 // in the image. Additionally, this use case utilizes power of two scal
ing, so we will | 848 // in the image. Additionally, this use case utilizes power of two scal
ing, so we will |
| 815 // test on power of two sample sizes. The output tile is always 512x512
, so, when a | 849 // test on power of two sample sizes. The output tile is always 512x512
, so, when a |
| 816 // sampleSize is used, the size of the subset that is decoded is always | 850 // sampleSize is used, the size of the subset that is decoded is always |
| 817 // (sampleSize*512)x(sampleSize*512). | 851 // (sampleSize*512)x(sampleSize*512). |
| 818 // There are a few good reasons to only test on power of two sample size
s at this time: | 852 // There are a few good reasons to only test on power of two sample size
s at this time: |
| 819 // JPEG decodes using kOriginal_Strategy are broken for non-powers o
f two. | |
| 820 // https://bug.skia.org/4319 | |
| 821 // All use cases we are aware of only scale by powers of two. | 853 // All use cases we are aware of only scale by powers of two. |
| 822 // PNG decodes use the indicated sampling strategy regardless of the
sample size, so | 854 // PNG decodes use the indicated sampling strategy regardless of the
sample size, so |
| 823 // these tests are sufficient to provide good coverage of our sc
aling options. | 855 // these tests are sufficient to provide good coverage of our sc
aling options. |
| 824 const uint32_t sampleSizes[] = { 1, 2, 4, 8, 16, 32, 64 }; | 856 const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 }; |
| 825 const uint32_t minOutputSize = 512; | 857 const uint32_t minOutputSize = 512; |
| 826 for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) { | 858 for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) { |
| 827 const SkString& path = fImages[fCurrentBRDImage]; | 859 const SkString& path = fImages[fCurrentBRDImage]; |
| 828 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { | 860 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
| 829 continue; | 861 continue; |
| 830 } | 862 } |
| 831 while (fCurrentBRDStrategy < (int) SK_ARRAY_COUNT(strategies)) { | 863 while (fCurrentBRDStrategy < (int) SK_ARRAY_COUNT(strategies)) { |
| 832 fSourceType = "image"; | 864 fSourceType = "image"; |
| 833 fBenchType = strategies[fCurrentBRDStrategy].fName; | 865 fBenchType = strategies[fCurrentBRDStrategy].fName; |
| 834 | 866 |
| 835 const SkBitmapRegionDecoder::Strategy strategy = | 867 const SkBitmapRegionDecoder::Strategy strategy = |
| 836 strategies[fCurrentBRDStrategy].fStrategy; | 868 strategies[fCurrentBRDStrategy].fStrategy; |
| 837 | 869 |
| 838 while (fCurrentColorType < fColorTypes.count()) { | 870 while (fCurrentColorType < fColorTypes.count()) { |
| 839 while (fCurrentBRDSampleSize < (int) SK_ARRAY_COUNT(sampleSi
zes)) { | 871 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSi
zes)) { |
| 840 while (fCurrentSubsetType <= kLastSingle_SubsetType) { | 872 while (fCurrentSubsetType <= kLastSingle_SubsetType) { |
| 841 | 873 |
| 842 | |
| 843 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName
(path.c_str())); | 874 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName
(path.c_str())); |
| 844 const SkColorType colorType = fColorTypes[fCurrentCo
lorType]; | 875 const SkColorType colorType = fColorTypes[fCurrentCo
lorType]; |
| 845 uint32_t sampleSize = sampleSizes[fCurrentBRDSampleS
ize]; | 876 uint32_t sampleSize = brdSampleSizes[fCurrentSampleS
ize]; |
| 846 int currentSubsetType = fCurrentSubsetType++; | 877 int currentSubsetType = fCurrentSubsetType++; |
| 847 | 878 |
| 848 int width = 0; | 879 int width = 0; |
| 849 int height = 0; | 880 int height = 0; |
| 850 if (!valid_brd_bench(encoded.get(), strategy, colorT
ype, sampleSize, | 881 if (!valid_brd_bench(encoded.get(), strategy, colorT
ype, sampleSize, |
| 851 minOutputSize, &width, &height)) { | 882 minOutputSize, &width, &height)) { |
| 852 break; | 883 break; |
| 853 } | 884 } |
| 854 | 885 |
| 855 SkString basename = SkOSPath::Basename(path.c_str())
; | 886 SkString basename = SkOSPath::Basename(path.c_str())
; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 881 height - subsetSize, subsetSize, sub
setSize); | 912 height - subsetSize, subsetSize, sub
setSize); |
| 882 break; | 913 break; |
| 883 default: | 914 default: |
| 884 SkASSERT(false); | 915 SkASSERT(false); |
| 885 } | 916 } |
| 886 | 917 |
| 887 return new BitmapRegionDecoderBench(basename.c_str()
, encoded.get(), | 918 return new BitmapRegionDecoderBench(basename.c_str()
, encoded.get(), |
| 888 strategy, colorType, sampleSize, subset); | 919 strategy, colorType, sampleSize, subset); |
| 889 } | 920 } |
| 890 fCurrentSubsetType = 0; | 921 fCurrentSubsetType = 0; |
| 891 fCurrentBRDSampleSize++; | 922 fCurrentSampleSize++; |
| 892 } | 923 } |
| 893 fCurrentBRDSampleSize = 0; | 924 fCurrentSampleSize = 0; |
| 894 fCurrentColorType++; | 925 fCurrentColorType++; |
| 895 } | 926 } |
| 896 fCurrentColorType = 0; | 927 fCurrentColorType = 0; |
| 897 fCurrentBRDStrategy++; | 928 fCurrentBRDStrategy++; |
| 898 } | 929 } |
| 899 fCurrentBRDStrategy = 0; | 930 fCurrentBRDStrategy = 0; |
| 900 } | 931 } |
| 901 | 932 |
| 902 return nullptr; | 933 return nullptr; |
| 903 } | 934 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 | 979 |
| 949 double fSKPBytes, fSKPOps; | 980 double fSKPBytes, fSKPOps; |
| 950 | 981 |
| 951 const char* fSourceType; // What we're benching: bench, GM, SKP, ... | 982 const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
| 952 const char* fBenchType; // How we bench it: micro, recording, playback, ..
. | 983 const char* fBenchType; // How we bench it: micro, recording, playback, ..
. |
| 953 int fCurrentRecording; | 984 int fCurrentRecording; |
| 954 int fCurrentScale; | 985 int fCurrentScale; |
| 955 int fCurrentSKP; | 986 int fCurrentSKP; |
| 956 int fCurrentUseMPD; | 987 int fCurrentUseMPD; |
| 957 int fCurrentCodec; | 988 int fCurrentCodec; |
| 989 int fCurrentAndroidCodec; |
| 958 int fCurrentBRDImage; | 990 int fCurrentBRDImage; |
| 959 int fCurrentColorType; | 991 int fCurrentColorType; |
| 960 int fCurrentAlphaType; | 992 int fCurrentAlphaType; |
| 961 int fCurrentSubsetType; | 993 int fCurrentSubsetType; |
| 962 int fCurrentBRDStrategy; | 994 int fCurrentBRDStrategy; |
| 963 int fCurrentBRDSampleSize; | 995 int fCurrentSampleSize; |
| 964 int fCurrentAnimSKP; | 996 int fCurrentAnimSKP; |
| 965 }; | 997 }; |
| 966 | 998 |
| 967 // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've
hung. | 999 // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've
hung. |
| 968 // This prints something every once in a while so that it knows we're still work
ing. | 1000 // This prints something every once in a while so that it knows we're still work
ing. |
| 969 static void start_keepalive() { | 1001 static void start_keepalive() { |
| 970 struct Loop { | 1002 struct Loop { |
| 971 static void forever(void*) { | 1003 static void forever(void*) { |
| 972 for (;;) { | 1004 for (;;) { |
| 973 static const int kSec = 1200; | 1005 static const int kSec = 1200; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 | 1275 |
| 1244 return 0; | 1276 return 0; |
| 1245 } | 1277 } |
| 1246 | 1278 |
| 1247 #if !defined SK_BUILD_FOR_IOS | 1279 #if !defined SK_BUILD_FOR_IOS |
| 1248 int main(int argc, char** argv) { | 1280 int main(int argc, char** argv) { |
| 1249 SkCommandLineFlags::Parse(argc, argv); | 1281 SkCommandLineFlags::Parse(argc, argv); |
| 1250 return nanobench_main(); | 1282 return nanobench_main(); |
| 1251 } | 1283 } |
| 1252 #endif | 1284 #endif |
| OLD | NEW |