keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 8 | #include "SkBenchLogger.h" |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 9 | #include "BenchTimer.h" |
| 10 | #include "PictureBenchmark.h" |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkPicture.h" |
| 13 | #include "SkString.h" |
| 14 | #include "picture_utils.h" |
| 15 | |
| 16 | namespace sk_tools { |
| 17 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 18 | PictureBenchmark::PictureBenchmark() |
| 19 | : fRepeats(1) |
| 20 | , fLogger(NULL) |
| 21 | , fRenderer(NULL) |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 22 | , fTimerResult(TimerData::kAvg_Result) |
| 23 | , fTimerTypes(0) |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 24 | , fTimeIndividualTiles(false) |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 25 | , fPurgeDecodedTex(false) |
commit-bot@chromium.org | c873329 | 2014-04-11 15:54:14 +0000 | [diff] [blame] | 26 | , fPreprocess(false) |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 27 | {} |
| 28 | |
| 29 | PictureBenchmark::~PictureBenchmark() { |
| 30 | SkSafeUnref(fRenderer); |
| 31 | } |
| 32 | |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 33 | void PictureBenchmark::setTimersToShow(bool wall, |
| 34 | bool truncatedWall, |
| 35 | bool cpu, |
| 36 | bool truncatedCpu, |
| 37 | bool gpu) { |
| 38 | fTimerTypes = 0; |
| 39 | fTimerTypes |= wall ? TimerData::kWall_Flag : 0; |
| 40 | fTimerTypes |= truncatedWall ? TimerData::kTruncatedWall_Flag : 0; |
| 41 | fTimerTypes |= cpu ? TimerData::kCpu_Flag : 0; |
| 42 | fTimerTypes |= truncatedCpu ? TimerData::kTruncatedCpu_Flag : 0; |
| 43 | fTimerTypes |= gpu ? TimerData::kGpu_Flag : 0; |
| 44 | } |
| 45 | |
robertphillips@google.com | f9d0c95 | 2013-02-07 16:21:22 +0000 | [diff] [blame] | 46 | BenchTimer* PictureBenchmark::setupTimer(bool useGLTimer) { |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 47 | #if SK_SUPPORT_GPU |
robertphillips@google.com | f9d0c95 | 2013-02-07 16:21:22 +0000 | [diff] [blame] | 48 | if (useGLTimer && fRenderer != NULL && fRenderer->isUsingGpuDevice()) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 49 | return SkNEW_ARGS(BenchTimer, (fRenderer->getGLContext())); |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 50 | } |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 51 | #endif |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 52 | return SkNEW_ARGS(BenchTimer, (NULL)); |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 53 | } |
| 54 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 55 | void PictureBenchmark::logProgress(const char msg[]) { |
| 56 | if (fLogger != NULL) { |
| 57 | fLogger->logProgress(msg); |
| 58 | } |
| 59 | } |
| 60 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 61 | PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* renderer) { |
| 62 | SkRefCnt_SafeAssign(fRenderer, renderer); |
| 63 | return renderer; |
| 64 | } |
| 65 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 66 | void PictureBenchmark::run(SkPicture* pict) { |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 67 | SkASSERT(pict); |
keyar@chromium.org | 78a35c5 | 2012-08-20 15:03:44 +0000 | [diff] [blame] | 68 | if (NULL == pict) { |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 69 | return; |
| 70 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 71 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 72 | SkASSERT(fRenderer != NULL); |
| 73 | if (NULL == fRenderer) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 74 | return; |
| 75 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 76 | |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 77 | fRenderer->init(pict, NULL, NULL, NULL, false); |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 78 | |
| 79 | // We throw this away to remove first time effects (such as paging in this program) |
| 80 | fRenderer->setup(); |
commit-bot@chromium.org | c873329 | 2014-04-11 15:54:14 +0000 | [diff] [blame] | 81 | |
| 82 | if (fPreprocess) { |
| 83 | if (NULL != fRenderer->getCanvas()) { |
| 84 | fRenderer->getCanvas()->EXPERIMENTAL_optimize(pict); |
| 85 | } |
| 86 | } |
| 87 | |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 88 | fRenderer->render(NULL); |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 89 | fRenderer->resetState(true); // flush, swapBuffers and Finish |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 90 | |
commit-bot@chromium.org | c873329 | 2014-04-11 15:54:14 +0000 | [diff] [blame] | 91 | if (fPreprocess) { |
| 92 | if (NULL != fRenderer->getCanvas()) { |
| 93 | fRenderer->getCanvas()->EXPERIMENTAL_purge(pict); |
| 94 | } |
| 95 | } |
| 96 | |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 97 | if (fPurgeDecodedTex) { |
| 98 | fRenderer->purgeTextures(); |
| 99 | } |
| 100 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 101 | bool usingGpu = false; |
keyar@chromium.org | f8a513f | 2012-08-20 15:03:52 +0000 | [diff] [blame] | 102 | #if SK_SUPPORT_GPU |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 103 | usingGpu = fRenderer->isUsingGpuDevice(); |
keyar@chromium.org | f8a513f | 2012-08-20 15:03:52 +0000 | [diff] [blame] | 104 | #endif |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 105 | |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 106 | uint32_t timerTypes = fTimerTypes; |
| 107 | if (!usingGpu) { |
| 108 | timerTypes &= ~TimerData::kGpu_Flag; |
| 109 | } |
| 110 | |
| 111 | SkString timeFormat; |
| 112 | if (TimerData::kPerIter_Result == fTimerResult) { |
| 113 | timeFormat = fRenderer->getPerIterTimeFormat(); |
| 114 | } else { |
| 115 | timeFormat = fRenderer->getNormalTimeFormat(); |
| 116 | } |
| 117 | |
commit-bot@chromium.org | 359e4f0 | 2014-04-30 00:46:29 +0000 | [diff] [blame] | 118 | static const int kNumInnerLoops = 10; |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 119 | int numOuterLoops = 1; |
| 120 | int numInnerLoops = fRepeats; |
| 121 | |
| 122 | if (TimerData::kPerIter_Result == fTimerResult && fRepeats > 1) { |
| 123 | // interpret this flag combination to mean: generate 'fRepeats' |
| 124 | // numbers by averaging each rendering 'kNumInnerLoops' times |
| 125 | numOuterLoops = fRepeats; |
| 126 | numInnerLoops = kNumInnerLoops; |
| 127 | } |
| 128 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 129 | if (fTimeIndividualTiles) { |
| 130 | TiledPictureRenderer* tiledRenderer = fRenderer->getTiledRenderer(); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 131 | SkASSERT(tiledRenderer && tiledRenderer->supportsTimingIndividualTiles()); |
| 132 | if (NULL == tiledRenderer || !tiledRenderer->supportsTimingIndividualTiles()) { |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 133 | return; |
| 134 | } |
| 135 | int xTiles, yTiles; |
| 136 | if (!tiledRenderer->tileDimensions(xTiles, yTiles)) { |
| 137 | return; |
| 138 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 139 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 140 | // Insert a newline so that each tile is reported on its own line (separate from the line |
| 141 | // that describes the skp being run). |
| 142 | this->logProgress("\n"); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 143 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 144 | int x, y; |
| 145 | while (tiledRenderer->nextTile(x, y)) { |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 146 | // There are two timers, which will behave slightly differently: |
| 147 | // 1) longRunningTimer, along with perTileTimerData, will time how long it takes to draw |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 148 | // one tile fRepeats times, and take the average. As such, it will not respect the |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 149 | // logPerIter or printMin options, since it does not know the time per iteration. It |
| 150 | // 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 not precise enough to |
| 152 | // measure the small amount of time it takes to draw one tile once. |
| 153 | // |
| 154 | // 2) perTileTimer, along with perTileTimerData, will record each run separately, and |
| 155 | // then take the average. As such, it supports logPerIter and printMin options. |
robertphillips@google.com | 9b63c50 | 2013-02-07 20:20:27 +0000 | [diff] [blame] | 156 | // |
| 157 | // Although "legal", having two gpu timers running at the same time |
skia.committer@gmail.com | ee235f9 | 2013-02-08 07:16:45 +0000 | [diff] [blame] | 158 | // seems to cause problems (i.e., INVALID_OPERATIONs) on several |
| 159 | // platforms. To work around this, we disable the gpu timer on the |
robertphillips@google.com | 9b63c50 | 2013-02-07 20:20:27 +0000 | [diff] [blame] | 160 | // long running timer. |
borenet@google.com | b15e606 | 2013-02-11 18:42:43 +0000 | [diff] [blame] | 161 | SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer()); |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 162 | TimerData longRunningTimerData(numOuterLoops); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 163 | |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 164 | for (int outer = 0; outer < numOuterLoops; ++outer) { |
| 165 | SkAutoTDelete<BenchTimer> perTileTimer(this->setupTimer(false)); |
| 166 | TimerData perTileTimerData(numInnerLoops); |
| 167 | |
| 168 | longRunningTimer->start(); |
| 169 | for (int inner = 0; inner < numInnerLoops; ++inner) { |
| 170 | perTileTimer->start(); |
| 171 | tiledRenderer->drawCurrentTile(); |
| 172 | perTileTimer->truncatedEnd(); |
| 173 | tiledRenderer->resetState(false); // flush & swapBuffers, but don't Finish |
| 174 | perTileTimer->end(); |
| 175 | SkAssertResult(perTileTimerData.appendTimes(perTileTimer.get())); |
| 176 | |
| 177 | if (fPurgeDecodedTex) { |
| 178 | fRenderer->purgeTextures(); |
| 179 | } |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 180 | } |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 181 | longRunningTimer->truncatedEnd(); |
| 182 | tiledRenderer->resetState(true); // flush, swapBuffers and Finish |
| 183 | longRunningTimer->end(); |
| 184 | SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer.get())); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 185 | } |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 186 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 187 | SkString configName = tiledRenderer->getConfigName(); |
| 188 | configName.appendf(": tile [%i,%i] out of [%i,%i]", x, y, xTiles, yTiles); |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 189 | |
skia.committer@gmail.com | 0b70816 | 2014-03-12 03:02:18 +0000 | [diff] [blame] | 190 | // TODO(borenet): Turn off per-iteration tile time reporting for now. |
| 191 | // Avoiding logging the time for every iteration for each tile cuts |
| 192 | // down on data file size by a significant amount. Re-enable this once |
| 193 | // we're loading the bench data directly into a data store and are no |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 194 | // longer generating SVG graphs. |
| 195 | #if 0 |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 196 | SkString result = perTileTimerData.getResult(timeFormat.c_str(), fTimerResult, |
| 197 | configName.c_str(), timerTypes); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 198 | result.append("\n"); |
| 199 | this->logProgress(result.c_str()); |
borenet@google.com | b15e606 | 2013-02-11 18:42:43 +0000 | [diff] [blame] | 200 | #endif |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 201 | |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 202 | if (fPurgeDecodedTex) { |
| 203 | configName.append(" <withPurging>"); |
| 204 | } |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 205 | configName.append(" <averaged>"); |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 206 | SkString longRunningResult = longRunningTimerData.getResult( |
| 207 | tiledRenderer->getNormalTimeFormat().c_str(), |
| 208 | TimerData::kAvg_Result, |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 209 | configName.c_str(), timerTypes, numInnerLoops); |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 210 | longRunningResult.append("\n"); |
| 211 | this->logProgress(longRunningResult.c_str()); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 212 | } |
| 213 | } else { |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 214 | SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer()); |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 215 | TimerData longRunningTimerData(numOuterLoops); |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 216 | |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 217 | for (int outer = 0; outer < numOuterLoops; ++outer) { |
| 218 | SkAutoTDelete<BenchTimer> perRunTimer(this->setupTimer(false)); |
| 219 | TimerData perRunTimerData(numInnerLoops); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 220 | |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 221 | longRunningTimer->start(); |
| 222 | for (int inner = 0; inner < numInnerLoops; ++inner) { |
| 223 | fRenderer->setup(); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 224 | |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 225 | perRunTimer->start(); |
| 226 | fRenderer->render(NULL); |
| 227 | perRunTimer->truncatedEnd(); |
| 228 | fRenderer->resetState(false); // flush & swapBuffers, but don't Finish |
| 229 | perRunTimer->end(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 230 | |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 231 | SkAssertResult(perRunTimerData.appendTimes(perRunTimer.get())); |
| 232 | |
commit-bot@chromium.org | c873329 | 2014-04-11 15:54:14 +0000 | [diff] [blame] | 233 | if (fPreprocess) { |
| 234 | if (NULL != fRenderer->getCanvas()) { |
| 235 | fRenderer->getCanvas()->EXPERIMENTAL_purge(pict); |
| 236 | } |
| 237 | } |
| 238 | |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 239 | if (fPurgeDecodedTex) { |
| 240 | fRenderer->purgeTextures(); |
| 241 | } |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 242 | } |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 243 | longRunningTimer->truncatedEnd(); |
| 244 | fRenderer->resetState(true); // flush, swapBuffers and Finish |
| 245 | longRunningTimer->end(); |
| 246 | SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer.get())); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | SkString configName = fRenderer->getConfigName(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 250 | if (fPurgeDecodedTex) { |
| 251 | configName.append(" <withPurging>"); |
| 252 | } |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 253 | |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 254 | // Beware - since the per-run-timer doesn't ever include a glFinish it can |
| 255 | // report a lower time then the long-running-timer |
| 256 | #if 0 |
| 257 | SkString result = perRunTimerData.getResult(timeFormat.c_str(), |
| 258 | fTimerResult, |
| 259 | configName.c_str(), |
| 260 | timerTypes); |
| 261 | result.append("\n"); |
| 262 | |
| 263 | this->logProgress(result.c_str()); |
| 264 | #else |
skia.committer@gmail.com | 3b85deb | 2013-12-18 07:01:56 +0000 | [diff] [blame] | 265 | SkString result = longRunningTimerData.getResult(timeFormat.c_str(), |
commit-bot@chromium.org | 51c040e | 2014-03-11 22:58:00 +0000 | [diff] [blame] | 266 | fTimerResult, |
| 267 | configName.c_str(), |
| 268 | timerTypes, |
| 269 | numInnerLoops); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 270 | result.append("\n"); |
| 271 | this->logProgress(result.c_str()); |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 272 | #endif |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 273 | } |
| 274 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 275 | fRenderer->end(); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | } |