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