OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "Benchmark.h" | |
9 #include "SkCommandLineFlags.h" | |
10 #include "SkOSFile.h" | |
11 #include "SkStream.h" | |
12 #include "VisualSKPBench.h" | |
13 | |
14 /* | |
15 * This is an experimental GPU only benchmarking program. The initial implement ation will only | |
16 * support SKPs. | |
17 */ | |
18 | |
19 // To get image decoders linked in we have to do the below magic | |
20 #include "SkForceLinking.h" | |
21 #include "SkImageDecoder.h" | |
22 __SK_FORCE_IMAGE_DECODER_LINKING; | |
23 | |
24 DEFINE_string(skps, "skps", "Directory to read skps from."); | |
25 | |
26 DEFINE_string2(match, m, nullptr, | |
27 "[~][^]substring[$] [...] of GM name to run.\n" | |
28 "Multiple matches may be separated by spaces.\n" | |
29 "~ causes a matching bench to always be skipped\n" | |
30 "^ requires the start of the bench to match\n" | |
31 "$ requires the end of the bench to match\n" | |
32 "^ and $ requires an exact match\n" | |
33 "If a bench does not match any list entry,\n" | |
34 "it is skipped unless some list entry starts with ~"); | |
35 | |
36 namespace kilobench { | |
37 class BenchmarkStream { | |
38 public: | |
39 BenchmarkStream() : fCurrentSKP(0) { | |
40 for (int i = 0; i < FLAGS_skps.count(); i++) { | |
41 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | |
42 fSKPs.push_back() = FLAGS_skps[i]; | |
43 } else { | |
44 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | |
45 SkString path; | |
46 while (it.next(&path)) { | |
47 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); | |
48 } | |
49 } | |
50 } | |
51 } | |
52 | |
53 Benchmark* next() { | |
54 Benchmark* bench = nullptr; | |
55 // skips non matching benches | |
56 while ((bench = this->innerNext()) && | |
57 (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName ()) || | |
58 !bench->isSuitableFor(Benchmark::kGPU_Backend))) { | |
59 bench->unref(); | |
mtklein
2016/01/14 16:49:43
Might want to `delete bench;` here for consistency
| |
60 } | |
61 return bench; | |
62 } | |
63 | |
64 private: | |
65 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { | |
66 // Not strictly necessary, as it will be checked again later, | |
67 // but helps to avoid a lot of pointless work if we're going to skip it. | |
68 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { | |
69 return false; | |
70 } | |
71 | |
72 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); | |
73 if (stream.get() == nullptr) { | |
74 SkDebugf("Could not read %s.\n", path); | |
75 return false; | |
76 } | |
77 | |
78 pic->reset(SkPicture::CreateFromStream(stream.get())); | |
79 if (pic->get() == nullptr) { | |
80 SkDebugf("Could not read %s as an SkPicture.\n", path); | |
81 return false; | |
82 } | |
83 return true; | |
84 } | |
85 | |
86 Benchmark* innerNext() { | |
87 // Render skps | |
88 while (fCurrentSKP < fSKPs.count()) { | |
89 const SkString& path = fSKPs[fCurrentSKP++]; | |
90 SkAutoTUnref<SkPicture> pic; | |
91 if (!ReadPicture(path.c_str(), &pic)) { | |
92 continue; | |
93 } | |
94 | |
95 SkString name = SkOSPath::Basename(path.c_str()); | |
96 return new VisualSKPBench(name.c_str(), pic.get()); | |
97 } | |
98 | |
99 return nullptr; | |
100 } | |
101 | |
102 SkTArray<SkString> fSKPs; | |
103 int fCurrentSKP; | |
104 }; | |
105 | |
106 } // namespace kilobench | |
107 | |
108 int kilobench_main() { | |
109 kilobench::BenchmarkStream benchStream; | |
110 while (Benchmark* b = benchStream.next()) { | |
111 SkAutoTDelete<Benchmark> bench(b); | |
bsalomon
2016/01/14 16:45:05
Does this work?
while (SkAutoTDelete<Benchmark> b
| |
112 // TODO actual stuff | |
113 } | |
114 return 0; | |
115 } | |
116 | |
117 #if !defined SK_BUILD_FOR_IOS | |
118 int main(int argc, char** argv) { | |
119 SkCommandLineFlags::Parse(argc, argv); | |
120 return kilobench_main(); | |
121 } | |
122 #endif | |
OLD | NEW |