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); |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 81 | fRenderer->resetState(true); |
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 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 104 | if (fTimeIndividualTiles) { |
| 105 | TiledPictureRenderer* tiledRenderer = fRenderer->getTiledRenderer(); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 106 | SkASSERT(tiledRenderer && tiledRenderer->supportsTimingIndividualTiles()); |
| 107 | if (NULL == tiledRenderer || !tiledRenderer->supportsTimingIndividualTiles()) { |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 108 | return; |
| 109 | } |
| 110 | int xTiles, yTiles; |
| 111 | if (!tiledRenderer->tileDimensions(xTiles, yTiles)) { |
| 112 | return; |
| 113 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 114 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 115 | // Insert a newline so that each tile is reported on its own line (separate from the line |
| 116 | // that describes the skp being run). |
| 117 | this->logProgress("\n"); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 118 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 119 | int x, y; |
| 120 | while (tiledRenderer->nextTile(x, y)) { |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 121 | // There are two timers, which will behave slightly differently: |
| 122 | // 1) longRunningTimer, along with perTileTimerData, will time how long it takes to draw |
robertphillips@google.com | fe1b536 | 2013-02-07 19:45:46 +0000 | [diff] [blame] | 123 | // one tile fRepeats times, and take the average. As such, it will not respect thea |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 124 | // logPerIter or printMin options, since it does not know the time per iteration. It |
| 125 | // will also be unable to call flush() for each tile. |
| 126 | // The goal of this timer is to make up for a system timer that is not precise enough to |
| 127 | // measure the small amount of time it takes to draw one tile once. |
| 128 | // |
| 129 | // 2) perTileTimer, along with perTileTimerData, will record each run separately, and |
| 130 | // 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] | 131 | // |
| 132 | // 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] | 133 | // seems to cause problems (i.e., INVALID_OPERATIONs) on several |
| 134 | // 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] | 135 | // long running timer. |
borenet@google.com | b15e606 | 2013-02-11 18:42:43 +0000 | [diff] [blame] | 136 | SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer()); |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 137 | TimerData longRunningTimerData(1); |
borenet@google.com | b15e606 | 2013-02-11 18:42:43 +0000 | [diff] [blame] | 138 | SkAutoTDelete<BenchTimer> perTileTimer(this->setupTimer(false)); |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 139 | TimerData perTileTimerData(fRepeats); |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 140 | longRunningTimer->start(); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 141 | for (int i = 0; i < fRepeats; ++i) { |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 142 | perTileTimer->start(); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 143 | tiledRenderer->drawCurrentTile(); |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 144 | perTileTimer->truncatedEnd(); |
| 145 | tiledRenderer->resetState(false); |
| 146 | perTileTimer->end(); |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 147 | SkAssertResult(perTileTimerData.appendTimes(perTileTimer.get())); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 148 | |
| 149 | if (fPurgeDecodedTex) { |
| 150 | fRenderer->purgeTextures(); |
| 151 | } |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 152 | } |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 153 | longRunningTimer->truncatedEnd(); |
| 154 | tiledRenderer->resetState(true); |
| 155 | longRunningTimer->end(); |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 156 | SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer.get())); |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 157 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 158 | SkString configName = tiledRenderer->getConfigName(); |
| 159 | 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] | 160 | |
| 161 | SkString result = perTileTimerData.getResult(timeFormat.c_str(), fTimerResult, |
| 162 | configName.c_str(), timerTypes); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 163 | result.append("\n"); |
borenet@google.com | b15e606 | 2013-02-11 18:42:43 +0000 | [diff] [blame] | 164 | |
| 165 | // TODO(borenet): Turn off per-iteration tile time reporting for now. Avoiding logging the time |
| 166 | // for every iteration for each tile cuts down on data file size by a significant amount. Re-enable |
| 167 | // this once we're loading the bench data directly into a data store and are no longer generating |
| 168 | // SVG graphs. |
| 169 | #if 0 |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 170 | this->logProgress(result.c_str()); |
borenet@google.com | b15e606 | 2013-02-11 18:42:43 +0000 | [diff] [blame] | 171 | #endif |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 172 | if (fPurgeDecodedTex) { |
| 173 | configName.append(" <withPurging>"); |
| 174 | } |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 175 | configName.append(" <averaged>"); |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 176 | SkString longRunningResult = longRunningTimerData.getResult( |
| 177 | tiledRenderer->getNormalTimeFormat().c_str(), |
| 178 | TimerData::kAvg_Result, |
| 179 | configName.c_str(), timerTypes, fRepeats); |
scroggo@google.com | 08085f8 | 2013-01-28 20:40:24 +0000 | [diff] [blame] | 180 | longRunningResult.append("\n"); |
| 181 | this->logProgress(longRunningResult.c_str()); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 182 | } |
| 183 | } else { |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 184 | SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer()); |
| 185 | TimerData longRunningTimerData(1); |
| 186 | SkAutoTDelete<BenchTimer> perRunTimer(this->setupTimer(false)); |
| 187 | TimerData perRunTimerData(fRepeats); |
| 188 | |
| 189 | longRunningTimer->start(); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 190 | for (int i = 0; i < fRepeats; ++i) { |
| 191 | fRenderer->setup(); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 192 | |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 193 | perRunTimer->start(); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 194 | fRenderer->render(NULL); |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 195 | perRunTimer->truncatedEnd(); |
| 196 | fRenderer->resetState(false); |
| 197 | perRunTimer->end(); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 198 | |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 199 | SkAssertResult(perRunTimerData.appendTimes(perRunTimer.get())); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 200 | |
| 201 | if (fPurgeDecodedTex) { |
| 202 | fRenderer->purgeTextures(); |
| 203 | } |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 204 | } |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 205 | longRunningTimer->truncatedEnd(); |
| 206 | fRenderer->resetState(true); |
| 207 | longRunningTimer->end(); |
| 208 | SkAssertResult(longRunningTimerData.appendTimes(longRunningTimer.get())); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 209 | |
| 210 | SkString configName = fRenderer->getConfigName(); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 211 | if (fPurgeDecodedTex) { |
| 212 | configName.append(" <withPurging>"); |
| 213 | } |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 214 | |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 215 | // Beware - since the per-run-timer doesn't ever include a glFinish it can |
| 216 | // report a lower time then the long-running-timer |
| 217 | #if 0 |
| 218 | SkString result = perRunTimerData.getResult(timeFormat.c_str(), |
| 219 | fTimerResult, |
| 220 | configName.c_str(), |
| 221 | timerTypes); |
| 222 | result.append("\n"); |
| 223 | |
| 224 | this->logProgress(result.c_str()); |
| 225 | #else |
skia.committer@gmail.com | 3b85deb | 2013-12-18 07:01:56 +0000 | [diff] [blame] | 226 | SkString result = longRunningTimerData.getResult(timeFormat.c_str(), |
| 227 | fTimerResult, |
| 228 | configName.c_str(), |
| 229 | timerTypes, |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 230 | fRepeats); |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 231 | result.append("\n"); |
| 232 | this->logProgress(result.c_str()); |
robertphillips@google.com | 090601c | 2013-12-17 13:40:20 +0000 | [diff] [blame] | 233 | #endif |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 234 | } |
| 235 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 236 | fRenderer->end(); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | } |