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