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