OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 | 8 |
9 #include <VisualBench/VisualBenchmarkStream.h> | 9 #include <VisualBench/VisualBenchmarkStream.h> |
10 #include <VisualBench/WrappedBenchmark.h> | 10 #include <VisualBench/WrappedBenchmark.h> |
11 #include "GMBench.h" | 11 #include "GMBench.h" |
12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
13 #include "SkPath.h" | 13 #include "SkPath.h" |
14 #include "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
15 #include "SkStream.h" | 15 #include "SkStream.h" |
16 #include "sk_tool_utils.h" | 16 #include "sk_tool_utils.h" |
17 #include "VisualFlags.h" | |
18 #include "VisualSKPBench.h" | 17 #include "VisualSKPBench.h" |
19 | 18 |
20 DEFINE_bool(cpu, false, "Run in CPU mode?"); | |
21 DEFINE_string2(match, m, nullptr, | 19 DEFINE_string2(match, m, nullptr, |
22 "[~][^]substring[$] [...] of bench name to run.\n" | 20 "[~][^]substring[$] [...] of bench name to run.\n" |
23 "Multiple matches may be separated by spaces.\n" | 21 "Multiple matches may be separated by spaces.\n" |
24 "~ causes a matching bench to always be skipped\n" | 22 "~ causes a matching bench to always be skipped\n" |
25 "^ requires the start of the bench to match\n" | 23 "^ requires the start of the bench to match\n" |
26 "$ requires the end of the bench to match\n" | 24 "$ requires the end of the bench to match\n" |
27 "^ and $ requires an exact match\n" | 25 "^ and $ requires an exact match\n" |
28 "If a bench does not match any list entry,\n" | 26 "If a bench does not match any list entry,\n" |
29 "it is skipped unless some list entry starts with ~"); | 27 "it is skipped unless some list entry starts with ~"); |
30 DEFINE_string(skps, "skps", "Directory to read skps from."); | 28 DEFINE_string(skps, "skps", "Directory to read skps from."); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 66 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
69 fSKPs.push_back() = FLAGS_skps[i]; | 67 fSKPs.push_back() = FLAGS_skps[i]; |
70 } else { | 68 } else { |
71 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 69 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
72 SkString path; | 70 SkString path; |
73 while (it.next(&path)) { | 71 while (it.next(&path)) { |
74 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); | 72 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); |
75 } | 73 } |
76 } | 74 } |
77 } | 75 } |
78 | |
79 // seed with an initial benchmark | |
80 // NOTE the initial benchmark will not have preTimingHooks called, but that
is okay because | |
81 // it is the warmupbench | |
82 this->next(); | |
83 } | 76 } |
84 | 77 |
85 bool VisualBenchmarkStream::ReadPicture(const char* path, SkAutoTUnref<SkPicture
>* pic) { | 78 bool VisualBenchmarkStream::ReadPicture(const char* path, SkAutoTUnref<SkPicture
>* pic) { |
86 // Not strictly necessary, as it will be checked again later, | 79 // Not strictly necessary, as it will be checked again later, |
87 // but helps to avoid a lot of pointless work if we're going to skip it. | 80 // but helps to avoid a lot of pointless work if we're going to skip it. |
88 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { | 81 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { |
89 return false; | 82 return false; |
90 } | 83 } |
91 | 84 |
92 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); | 85 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); |
93 if (stream.get() == nullptr) { | 86 if (stream.get() == nullptr) { |
94 SkDebugf("Could not read %s.\n", path); | 87 SkDebugf("Could not read %s.\n", path); |
95 return false; | 88 return false; |
96 } | 89 } |
97 | 90 |
98 pic->reset(SkPicture::CreateFromStream(stream.get())); | 91 pic->reset(SkPicture::CreateFromStream(stream.get())); |
99 if (pic->get() == nullptr) { | 92 if (pic->get() == nullptr) { |
100 SkDebugf("Could not read %s as an SkPicture.\n", path); | 93 SkDebugf("Could not read %s as an SkPicture.\n", path); |
101 return false; | 94 return false; |
102 } | 95 } |
103 return true; | 96 return true; |
104 } | 97 } |
105 | 98 |
106 Benchmark* VisualBenchmarkStream::next() { | 99 Benchmark* VisualBenchmarkStream::next(Configs::Config config) { |
107 Benchmark* bench; | 100 Benchmark* bench; |
108 if (!fIsWarmedUp) { | 101 if (!fIsWarmedUp) { |
109 fIsWarmedUp = true; | 102 fIsWarmedUp = true; |
110 bench = new WarmupBench; | 103 bench = new WarmupBench; |
111 } else { | 104 } else { |
112 // skips non matching benches | 105 // skips non matching benches |
113 while ((bench = this->innerNext()) && | 106 while ((bench = this->innerNext()) && |
114 (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName
()) || | 107 (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName
()) || |
115 !bench->isSuitableFor(Benchmark::kGPU_Backend))) { | 108 !bench->isSuitableFor(Benchmark::kGPU_Backend))) { |
116 bench->unref(); | 109 bench->unref(); |
117 } | 110 } |
118 } | 111 } |
119 | 112 |
120 // TODO move this all to --config | 113 if (bench) { |
121 if (bench && FLAGS_cpu) { | 114 switch (config.fType) { |
122 bench = new CpuWrappedBenchmark(bench); | 115 case Configs::Config::kCpu_Type: |
123 } else if (bench && FLAGS_nvpr) { | 116 bench = new CpuWrappedBenchmark(bench); |
124 bench = new NvprWrappedBenchmark(bench, 4); | 117 break; |
| 118 case Configs::Config::kNvpr_Type: |
| 119 bench = new NvprWrappedBenchmark(bench, config.fNumSamples); |
| 120 break; |
| 121 default: |
| 122 // These are the only two configs we need to wrap right now |
| 123 break; |
| 124 } |
125 } | 125 } |
126 | 126 |
127 fBenchmark.reset(bench); | 127 fBenchmark.reset(bench); |
128 return fBenchmark; | 128 return fBenchmark; |
129 } | 129 } |
130 | 130 |
131 Benchmark* VisualBenchmarkStream::innerNext() { | 131 Benchmark* VisualBenchmarkStream::innerNext() { |
132 while (fBenches) { | 132 while (fBenches) { |
133 Benchmark* bench = fBenches->factory()(nullptr); | 133 Benchmark* bench = fBenches->factory()(nullptr); |
134 fBenches = fBenches->next(); | 134 fBenches = fBenches->next(); |
(...skipping 24 matching lines...) Expand all Loading... |
159 } | 159 } |
160 | 160 |
161 SkString name = SkOSPath::Basename(path.c_str()); | 161 SkString name = SkOSPath::Basename(path.c_str()); |
162 fSourceType = "skp"; | 162 fSourceType = "skp"; |
163 fBenchType = "playback"; | 163 fBenchType = "playback"; |
164 return new VisualSKPBench(name.c_str(), pic.get()); | 164 return new VisualSKPBench(name.c_str(), pic.get()); |
165 } | 165 } |
166 | 166 |
167 return nullptr; | 167 return nullptr; |
168 } | 168 } |
OLD | NEW |