OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBenchLogger.h" | |
9 #include "BenchTimer.h" | 8 #include "BenchTimer.h" |
10 #include "PictureBenchmark.h" | 9 #include "PictureBenchmark.h" |
11 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
12 #include "SkPicture.h" | 11 #include "SkPicture.h" |
13 #include "SkString.h" | 12 #include "SkString.h" |
14 #include "picture_utils.h" | 13 #include "picture_utils.h" |
15 | 14 |
16 namespace sk_tools { | 15 namespace sk_tools { |
17 | 16 |
18 PictureBenchmark::PictureBenchmark() | 17 PictureBenchmark::PictureBenchmark() |
19 : fRepeats(1) | 18 : fRepeats(1) |
20 , fLogger(NULL) | |
21 , fRenderer(NULL) | 19 , fRenderer(NULL) |
22 , fTimerResult(TimerData::kAvg_Result) | 20 , fTimerResult(TimerData::kAvg_Result) |
23 , fTimerTypes(0) | 21 , fTimerTypes(0) |
24 , fTimeIndividualTiles(false) | 22 , fTimeIndividualTiles(false) |
25 , fPurgeDecodedTex(false) | 23 , fPurgeDecodedTex(false) |
26 , fPreprocess(false) | 24 , fPreprocess(false) |
| 25 , fWriter(NULL) |
27 {} | 26 {} |
28 | 27 |
29 PictureBenchmark::~PictureBenchmark() { | 28 PictureBenchmark::~PictureBenchmark() { |
30 SkSafeUnref(fRenderer); | 29 SkSafeUnref(fRenderer); |
31 } | 30 } |
32 | 31 |
33 void PictureBenchmark::setTimersToShow(bool wall, | 32 void PictureBenchmark::setTimersToShow(bool wall, |
34 bool truncatedWall, | 33 bool truncatedWall, |
35 bool cpu, | 34 bool cpu, |
36 bool truncatedCpu, | 35 bool truncatedCpu, |
37 bool gpu) { | 36 bool gpu) { |
38 fTimerTypes = 0; | 37 fTimerTypes = 0; |
39 fTimerTypes |= wall ? TimerData::kWall_Flag : 0; | 38 fTimerTypes |= wall ? TimerData::kWall_Flag : 0; |
40 fTimerTypes |= truncatedWall ? TimerData::kTruncatedWall_Flag : 0; | 39 fTimerTypes |= truncatedWall ? TimerData::kTruncatedWall_Flag : 0; |
41 fTimerTypes |= cpu ? TimerData::kCpu_Flag : 0; | 40 fTimerTypes |= cpu ? TimerData::kCpu_Flag : 0; |
42 fTimerTypes |= truncatedCpu ? TimerData::kTruncatedCpu_Flag : 0; | 41 fTimerTypes |= truncatedCpu ? TimerData::kTruncatedCpu_Flag : 0; |
43 fTimerTypes |= gpu ? TimerData::kGpu_Flag : 0; | 42 fTimerTypes |= gpu ? TimerData::kGpu_Flag : 0; |
44 } | 43 } |
45 | 44 |
46 BenchTimer* PictureBenchmark::setupTimer(bool useGLTimer) { | 45 BenchTimer* PictureBenchmark::setupTimer(bool useGLTimer) { |
47 #if SK_SUPPORT_GPU | 46 #if SK_SUPPORT_GPU |
48 if (useGLTimer && fRenderer != NULL && fRenderer->isUsingGpuDevice()) { | 47 if (useGLTimer && fRenderer != NULL && fRenderer->isUsingGpuDevice()) { |
49 return SkNEW_ARGS(BenchTimer, (fRenderer->getGLContext())); | 48 return SkNEW_ARGS(BenchTimer, (fRenderer->getGLContext())); |
50 } | 49 } |
51 #endif | 50 #endif |
52 return SkNEW_ARGS(BenchTimer, (NULL)); | 51 return SkNEW_ARGS(BenchTimer, (NULL)); |
53 } | 52 } |
54 | 53 |
55 void PictureBenchmark::logProgress(const char msg[]) { | |
56 if (fLogger != NULL) { | |
57 fLogger->logProgress(msg); | |
58 } | |
59 } | |
60 | |
61 PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* render
er) { | 54 PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* render
er) { |
62 SkRefCnt_SafeAssign(fRenderer, renderer); | 55 SkRefCnt_SafeAssign(fRenderer, renderer); |
63 return renderer; | 56 return renderer; |
64 } | 57 } |
65 | 58 |
66 void PictureBenchmark::run(SkPicture* pict) { | 59 void PictureBenchmark::run(SkPicture* pict) { |
67 SkASSERT(pict); | 60 SkASSERT(pict); |
68 if (NULL == pict) { | 61 if (NULL == pict) { |
69 return; | 62 return; |
70 } | 63 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 TiledPictureRenderer* tiledRenderer = fRenderer->getTiledRenderer(); | 123 TiledPictureRenderer* tiledRenderer = fRenderer->getTiledRenderer(); |
131 SkASSERT(tiledRenderer && tiledRenderer->supportsTimingIndividualTiles()
); | 124 SkASSERT(tiledRenderer && tiledRenderer->supportsTimingIndividualTiles()
); |
132 if (NULL == tiledRenderer || !tiledRenderer->supportsTimingIndividualTil
es()) { | 125 if (NULL == tiledRenderer || !tiledRenderer->supportsTimingIndividualTil
es()) { |
133 return; | 126 return; |
134 } | 127 } |
135 int xTiles, yTiles; | 128 int xTiles, yTiles; |
136 if (!tiledRenderer->tileDimensions(xTiles, yTiles)) { | 129 if (!tiledRenderer->tileDimensions(xTiles, yTiles)) { |
137 return; | 130 return; |
138 } | 131 } |
139 | 132 |
140 // Insert a newline so that each tile is reported on its own line (separ
ate from the line | |
141 // that describes the skp being run). | |
142 this->logProgress("\n"); | |
143 | |
144 int x, y; | 133 int x, y; |
145 while (tiledRenderer->nextTile(x, y)) { | 134 while (tiledRenderer->nextTile(x, y)) { |
146 // There are two timers, which will behave slightly differently: | 135 // There are two timers, which will behave slightly differently: |
147 // 1) longRunningTimer, along with perTileTimerData, will time how l
ong it takes to draw | 136 // 1) longRunningTimer, along with perTileTimerData, will time how l
ong it takes to draw |
148 // one tile fRepeats times, and take the average. As such, it will n
ot respect the | 137 // one tile fRepeats times, and take the average. As such, it will n
ot respect the |
149 // logPerIter or printMin options, since it does not know the time p
er iteration. It | 138 // logPerIter or printMin options, since it does not know the time p
er iteration. It |
150 // will also be unable to call flush() for each tile. | 139 // will also be unable to call flush() for each tile. |
151 // The goal of this timer is to make up for a system timer that is n
ot precise enough to | 140 // The goal of this timer is to make up for a system timer that is n
ot precise enough to |
152 // measure the small amount of time it takes to draw one tile once. | 141 // measure the small amount of time it takes to draw one tile once. |
153 // | 142 // |
(...skipping 23 matching lines...) Expand all Loading... |
177 if (fPurgeDecodedTex) { | 166 if (fPurgeDecodedTex) { |
178 fRenderer->purgeTextures(); | 167 fRenderer->purgeTextures(); |
179 } | 168 } |
180 } | 169 } |
181 longRunningTimer->truncatedEnd(); | 170 longRunningTimer->truncatedEnd(); |
182 tiledRenderer->resetState(true); // flush, swapBuffers and
Finish | 171 tiledRenderer->resetState(true); // flush, swapBuffers and
Finish |
183 longRunningTimer->end(); | 172 longRunningTimer->end(); |
184 SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer
.get())); | 173 SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer
.get())); |
185 } | 174 } |
186 | 175 |
187 SkString configName = tiledRenderer->getConfigName(); | 176 fWriter->tileConfig(tiledRenderer->getConfigName()); |
188 configName.appendf(": tile [%i,%i] out of [%i,%i]", x, y, xTiles, yT
iles); | 177 fWriter->tileMeta(x, y, xTiles, yTiles); |
189 | 178 |
190 // TODO(borenet): Turn off per-iteration tile time reporting for now
. | 179 // TODO(borenet): Turn off per-iteration tile time reporting for now
. |
191 // Avoiding logging the time for every iteration for each tile cuts | 180 // Avoiding logging the time for every iteration for each tile cuts |
192 // down on data file size by a significant amount. Re-enable this on
ce | 181 // down on data file size by a significant amount. Re-enable this on
ce |
193 // we're loading the bench data directly into a data store and are n
o | 182 // we're loading the bench data directly into a data store and are n
o |
194 // longer generating SVG graphs. | 183 // longer generating SVG graphs. |
195 #if 0 | 184 #if 0 |
196 SkString result = perTileTimerData.getResult(timeFormat.c_str(), fTi
merResult, | 185 fWriter->tileData( |
197 configName.c_str(), tim
erTypes); | 186 &perTileTimerData, |
198 result.append("\n"); | 187 timeFormat.c_str(), |
199 this->logProgress(result.c_str()); | 188 fTimerResult, |
| 189 timerTypes); |
200 #endif | 190 #endif |
201 | 191 |
202 if (fPurgeDecodedTex) { | 192 if (fPurgeDecodedTex) { |
203 configName.append(" <withPurging>"); | 193 fWriter->addTileFlag(PictureResultsWriter::kPurging); |
204 } | 194 } |
205 configName.append(" <averaged>"); | 195 fWriter->addTileFlag(PictureResultsWriter::kAvg); |
206 SkString longRunningResult = longRunningTimerData.getResult( | 196 fWriter->tileData( |
| 197 &longRunningTimerData, |
207 tiledRenderer->getNormalTimeFormat().c_str(), | 198 tiledRenderer->getNormalTimeFormat().c_str(), |
208 TimerData::kAvg_Result, | 199 TimerData::kAvg_Result, |
209 configName.c_str(), timerTypes, numInnerLoops); | 200 timerTypes, |
210 longRunningResult.append("\n"); | 201 numInnerLoops); |
211 this->logProgress(longRunningResult.c_str()); | |
212 } | 202 } |
213 } else { | 203 } else { |
214 SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer()); | 204 SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer()); |
215 TimerData longRunningTimerData(numOuterLoops); | 205 TimerData longRunningTimerData(numOuterLoops); |
216 | 206 |
217 for (int outer = 0; outer < numOuterLoops; ++outer) { | 207 for (int outer = 0; outer < numOuterLoops; ++outer) { |
218 SkAutoTDelete<BenchTimer> perRunTimer(this->setupTimer(false)); | 208 SkAutoTDelete<BenchTimer> perRunTimer(this->setupTimer(false)); |
219 TimerData perRunTimerData(numInnerLoops); | 209 TimerData perRunTimerData(numInnerLoops); |
220 | 210 |
221 longRunningTimer->start(); | 211 longRunningTimer->start(); |
(...skipping 17 matching lines...) Expand all Loading... |
239 if (fPurgeDecodedTex) { | 229 if (fPurgeDecodedTex) { |
240 fRenderer->purgeTextures(); | 230 fRenderer->purgeTextures(); |
241 } | 231 } |
242 } | 232 } |
243 longRunningTimer->truncatedEnd(); | 233 longRunningTimer->truncatedEnd(); |
244 fRenderer->resetState(true); // flush, swapBuffers and Finish | 234 fRenderer->resetState(true); // flush, swapBuffers and Finish |
245 longRunningTimer->end(); | 235 longRunningTimer->end(); |
246 SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer.get
())); | 236 SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer.get
())); |
247 } | 237 } |
248 | 238 |
249 SkString configName = fRenderer->getConfigName(); | 239 fWriter->tileConfig(fRenderer->getConfigName()); |
250 if (fPurgeDecodedTex) { | 240 if (fPurgeDecodedTex) { |
251 configName.append(" <withPurging>"); | 241 fWriter->addTileFlag(PictureResultsWriter::kPurging); |
252 } | 242 } |
253 | 243 |
254 // Beware - since the per-run-timer doesn't ever include a glFinish it c
an | 244 // Beware - since the per-run-timer doesn't ever include a glFinish it c
an |
255 // report a lower time then the long-running-timer | 245 // report a lower time then the long-running-timer |
256 #if 0 | 246 #if 0 |
257 SkString result = perRunTimerData.getResult(timeFormat.c_str(), | 247 fWriter->tileData( |
258 fTimerResult, | 248 &perRunTimerData, |
259 configName.c_str(), | 249 timeFormat.c_str(), |
260 timerTypes); | 250 fTimerResult, |
261 result.append("\n"); | 251 timerTypes); |
262 | |
263 this->logProgress(result.c_str()); | |
264 #else | 252 #else |
265 SkString result = longRunningTimerData.getResult(timeFormat.c_str(), | 253 fWriter->tileData( |
266 fTimerResult, | 254 &longRunningTimerData, |
267 configName.c_str(), | 255 timeFormat.c_str(), |
268 timerTypes, | 256 fTimerResult, |
269 numInnerLoops); | 257 timerTypes, |
270 result.append("\n"); | 258 numInnerLoops); |
271 this->logProgress(result.c_str()); | |
272 #endif | 259 #endif |
273 } | 260 } |
274 | 261 |
275 fRenderer->end(); | 262 fRenderer->end(); |
276 } | 263 } |
277 | 264 |
278 } | 265 } |
OLD | NEW |