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