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