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